Complete implementation
Intermediate Tutorial 1 - source (complete)
Welcome to the new Ogre Wiki!
If you haven't done so already, be sure to visit the Wiki Portal to read about how the wiki works. Especially the Ogre Wiki Overview page.
If you haven't done so already, be sure to visit the Wiki Portal to read about how the wiki works. Especially the Ogre Wiki Overview page.
Here is a working example of Intermediate Tutorial 1, complete with multiple robots that can be animated, along with factory classes for generating objects, with a complete Singleton implementation that was obtained from this post http://www.gamedev.net/community/forums/topic.asp?topic_id=301651
by cuzman in the GameDev.net forums.
All the classes are one big mess I know.
singleton.h
//------------------------------------------------------ // file: singleton.h // description: this is the template singleton class //------------------------------------------------------ #ifndef IM_TUTORIAL1_SINGLETON_H__ #define IM_TUTORIAL1_SINGLETON_H__ namespace IntermediateTutorial1 { // This class was found in a post in GameDev.net. I assume // it is public domain, since it was posted in a public forum // for the purpose of being improved upon and being // utilized // // I modified it to create itself automatically in the // getSingleton method instead of having a seperate // initSingleton static method. Also added was the ability // to get a ptr or a reference to the Singleton // // The original author's name is cozman // // Original Post: // http://www.gamedev.net/community/forums/topic.asp?topic_id=301651 // // Singleton solution w/ auto_ptr? // // cozman GDNet+ Member since: 8/7/2001 From: Cary, United States // // Posted - 2/17/2005 11:12:04 PM // I was toying around with creating a generic Singleton class. // I was wondering if any of you could comment on this idea: // // #include <cassert> // #include <memory> // #include <iostream> // // template<class T> // class Singleton // { // public: // static void initSingleton() // { // assert(instance_.get() == 0); // // instance_ = std::auto_ptr<T>(new T); // } // // static T& getSingleton() // { // assert(instance_.get() != 0); // // return *instance_; // } // // static void destroySingleton() // { // assert(instance_.get() != 0); // // instance_.reset(); // } // // virtual ~Singleton()=0; // // private: // // static std::auto_ptr<T> instance_; // }; // // template<class T> // std::auto_ptr<T> Singleton<T>::instance_(0); // // template<class T> // Singleton<T>::~Singleton() { } // // class Something : public Singleton<Something> // { // friend class Singleton<Something>; // friend class std::auto_ptr<Something>; // private: // Something() { std::cout << "created" << std::endl; } // ~Something() { std::cout << "destroyed" << std::endl; } // }; // // // From basic testing it works fine, you can't leak memory, // but you can also control the order of destruction if it // is important. // // Does anyone have any suggestions? /** Template class for creating single-instance global classes. */ template<class T> class Singleton { public: // static void initSingleton() // { // assert(instance_.get() == 0); // // instance_ = std::auto_ptr<T>(new T); // } static T& getSingleton() { if(instance_.get() == 0) instance_ = std::auto_ptr<T>(new T); return *(instance_.get()); } static T* getSingletonPtr() { return &(getSingleton()); } static void destroySingleton() { assert(instance_.get() != 0); instance_.reset(); } virtual ~Singleton()=0; private: static std::auto_ptr<T> instance_; }; template<class T> std::auto_ptr<T> Singleton<T>::instance_(0); template<class T> Singleton<T>::~Singleton() { } // implementation details //class Something : public Singleton<Something> //{ // friend class Singleton<Something>; // friend class std::auto_ptr<Something>; //private: // Something() { std::cout << "created" << std::endl; } // ~Something() { std::cout << "destroyed" << std::endl; } //}; } #endif
im_tutorial1.h
#ifndef IM_TUTORIAL2_H__ # define IM_TURORIAL2_H__ # define CREATOR_CLASS(x) friend class x #endif
Go on to im_tutorial1.cpp source code
Contributors to this page: jacmoe
and
OgreWikiBot
.
Page last modified on Monday 04 of January, 2010 05:25:27 GMT by jacmoe
.
The content on this page is licensed under the terms of the Creative Commons Attribution-ShareAlike License.
As an exception, any source code contributed within the content is released into the Public Domain.
Sidebar
Search box
Online users
51
online users

