From: <spo...@us...> - 2009-02-11 22:21:44
|
Revision: 1026 http://opengate.svn.sourceforge.net/opengate/?rev=1026&view=rev Author: spom_spom Date: 2009-02-11 22:20:22 +0000 (Wed, 11 Feb 2009) Log Message: ----------- some adjustments for the win32 build Modified Paths: -------------- trunk/src/AiManager.h trunk/src/AiObject.h trunk/src/KeyMap.h trunk/src/OpenALSoundManager.h trunk/src/Opengate.h trunk/src/SectorBaseObject.h trunk/src/SectorMeshObject.h trunk/src/common.h Modified: trunk/src/AiManager.h =================================================================== --- trunk/src/AiManager.h 2009-02-10 19:19:48 UTC (rev 1025) +++ trunk/src/AiManager.h 2009-02-11 22:20:22 UTC (rev 1026) @@ -20,6 +20,8 @@ #ifndef _OPENGATE_AIMANAGER__H #define _OPENGATE_AIMANAGER__H + +#include "Opengate.h" #include <string> #include <vector> @@ -30,26 +32,9 @@ #include <boost/thread.hpp> namespace OpenGate{ + +typedef SingularCallBack< AiManager, void, AiObject * > AiManagerCB; -class ResourceManager; -class SectorObjectVessel; -class AiManager; -class AiObject; - -template < class Class, typename ReturnType, typename Parameter > class SingularCallBack{ -public: - typedef ReturnType ( Class::*Method )( Parameter ); - SingularCallBack( Class * class_instance, Method method ) : class_instance_( class_instance ), method_( method ) { } - - ReturnType operator()( Parameter parameter ) { return ( class_instance_->*method_ )( parameter ); } - ReturnType execute( Parameter parameter ){ return operator()( parameter ); } -private: - Class * class_instance_; - Method method_; -}; - -typedef SingularCallBack< AiManager, void, AiObject * > AiManagerCB; - //! Manager for artificial intelligence (ai) objects. /*! Manager for artificial intelligence (ai) objects. Communication with ai i.e. bots with this manager. Each ai runs in his own thread. */ class AiManager{ @@ -59,45 +44,45 @@ ~AiManager( ); void cmd( const std::vector < std::string > & argv ); - + /*! Create new ai and put it to the set of active ai. The instance is taken from heap if available else create new. The object will start its work when startAiObject is called. The object will destoyed automaticaly either there work is done or stopAiObject is called.*/ AiObject * createAiObject( const std::string & name ); - - /*! Create new thread for the ai and start running */ + + /*! Create new thread for the ai and start running */ void startAiObject( AiObject * ai ); - - /*! Send kill signal to aiObject. The object will erased automaticaly */ + + /*! Send kill signal to aiObject. The object will erased automaticaly */ void stopAiObject( AiObject * ai ); - + /*! Check for any active ai's. */ inline bool hasActiveObjects() const { return ( aiObjects_.size() > 0 ); } - + /*!Send kill signal to all ai and join all threads. Mainly used for shutdown the manager.*/ void killall(); - + /*! ID of the last created ai */ uint aiID() const { return aiID_; } - + AiObject * spawnAi( ); - + protected: /*! The ai is dead and can be recycled. */ void recycle_( AiObject * ai ); - + /*! Erase ai from set of active ai's. The instance will not destroyd but put on a heap for the next usage*/ void eraseAiObject_( AiObject * ai ); - - + + ResourceManager * resources_; - + std::set< AiObject * > aiObjects_; std::deque< AiObject * > aiObjectHeap_; //! ID counter for the ai uint aiID_; - + boost::thread_group aiThreads_; AiManagerCB * eraseAiObjectCB_; boost::mutex eraseMutex_; Modified: trunk/src/AiObject.h =================================================================== --- trunk/src/AiObject.h 2009-02-10 19:19:48 UTC (rev 1025) +++ trunk/src/AiObject.h 2009-02-11 22:20:22 UTC (rev 1026) @@ -42,65 +42,65 @@ class AiObject{ public: AiObject( uint id ); - - ~AiObject( ); - + + virtual ~AiObject( ); + /*! Functor to the livecyle */ void operator()(){ return run( ); } - + /*! Main livecyle */ virtual void run(); - + /*! Set the instance which is controled by this ai */ void setVesselObject( SectorVesselObject * obj ); - + /*! Get the instance which is controled by this ai */ inline SectorVesselObject * vesselObject( ){ return vesselObject_; } - + bool isAlive() const { return isAlive_; } - + void kill(); - + void reset(); - + void setName ( const std::string & name ){ name_ = name; } - + std::string name() const { return name_; } - + uint id() const { return id_;} - + void dance( ); - + void test( ); void land( SectorStationObject * station ); - + /*! Idle and look every second for new orders */ //bool cmdIdle( ); /*! Wait and do nothing */ bool cmdWait( double time ){return true;} - + /*! Accelerate a given time with a given thrustRate */ bool cmdAccelerate( double time, double thrustRate ){ return true; } - + /*! Calculate maximum speed from a given thrustRate [0..1]*/ double maxSpeed( double thrustRate = 1.0 ) const; - + /*! Calculate speed from 0 with a given thrustRate [0..1] for a given time.*/ double speedAfterTime( double time, double thrustRate = 1.0 ) const; - + /*! Calculate linear way starting with speed 0 and a given thrustRate [0..1] for a given time.*/ double wayAfterTime( double time, double thrustRate ) const; - + /*! Calculate time until reach a speed from 0 with a given thrustRate [0..1].*/ double timeToSpeed( double speed, double thrustRate = 1.0 ) const; - + /*! Calculate the braking distance without turnaround.*/ double brakingDistance( double v ) const; - + /*! Calculate the braking time without turnaround.*/ double brakingTime( double v ) const; - + //! reference counting used for threading, prob. better using smart pointer uint referenceCounter() const { return refCounter_; } void incReferenceCounter() { refCounter_ ++; } @@ -109,31 +109,31 @@ AiObject( const AiObject & ai ); AiObject & operator = ( const AiObject & ai ); - + void copy_( const AiObject & ai ); - + //! unique id uint id_; - - //! the graphical representation + + //! the graphical representation SectorVesselObject * vesselObject_; - std::deque< AiCommand * > cmdQueue_; - + std::deque< AiCommand * > cmdQueue_; + AiCommand * activeCmd_; - + //! holds objects live status bool isAlive_; - + //! prepare object to die, called by kill() and evaluated in run loop bool die_; - + //! holds objects livetime Ogre::Timer * lifeTimer_; - + //! time from last livecyle in microseconds unsigned long lasttime_; - + //! objects name std::string name_; Modified: trunk/src/KeyMap.h =================================================================== --- trunk/src/KeyMap.h 2009-02-10 19:19:48 UTC (rev 1025) +++ trunk/src/KeyMap.h 2009-02-11 22:20:22 UTC (rev 1026) @@ -21,6 +21,8 @@ #ifndef _OPENGATE_KEYMAP__H #define _OPENGATE_KEYMAP__H +#include "Opengate.h" + #include <map> #include <sys/types.h> //#include "InputManager.h" @@ -31,20 +33,6 @@ namespace OpenGate{ -class UnDockedState; -class Console; - -template < class Object, typename returnT, typename Args > class memberBind { -public: - typedef returnT( Object::*F )( Args ); - memberBind( F function, Object * object) : function_( function ), object_( object ) {} - - returnT operator()( Args args ) const { return ( object_->*function_ )( args ); } -protected: - F function_; - Object object_; -}; - enum GlobalKeyModifier{KEY_NONE, KEY_CONTROL, KEY_SHIFT}; class KeyMap{ Modified: trunk/src/OpenALSoundManager.h =================================================================== --- trunk/src/OpenALSoundManager.h 2009-02-10 19:19:48 UTC (rev 1025) +++ trunk/src/OpenALSoundManager.h 2009-02-11 22:20:22 UTC (rev 1026) @@ -24,6 +24,8 @@ #include <string> #include <iostream> #include <map> + +#include "Opengate.h" #include <OgreVector3.h> #include <OgreSingleton.h> Modified: trunk/src/Opengate.h =================================================================== --- trunk/src/Opengate.h 2009-02-10 19:19:48 UTC (rev 1025) +++ trunk/src/Opengate.h 2009-02-11 22:20:22 UTC (rev 1026) @@ -32,7 +32,7 @@ namespace CEGUI{ class Window; } - + namespace OpenGate{ #define SECTOR_AVATAR_OBJECT_RTTI 1 @@ -50,7 +50,7 @@ #define SECTOR_STATION_OBJECT_RTTI 13 #define SECTOR_STATION_PAD_OBJECT_RTTI 14 #define SECTOR_VESSEL_OBJECT_RTTI 15 - + #define SECTOROBJECTENVIRONMENT_RTTI 1000010 #define PROJECTILE_RTTI 100001 #define SECTOROBJECT_RTTI 100002 @@ -68,8 +68,10 @@ class AiManager; class Avatar; -class BaseObject; -class DockedState; +class BaseObject; +class Console; +class DockedState; +class UnDockedState; class Gun; class Engine; @@ -86,7 +88,7 @@ class EngineObject; class ResourceManager; - + class Sector; class SectorAvatarObject; class SectorBaseObject; @@ -125,9 +127,32 @@ class Movable; class NetworkClient; -class UnDockedState; class Vessel; - + +template < class Class, typename ReturnType, typename Parameter > class SingularCallBack{ +public: + typedef ReturnType ( Class::*Method )( Parameter ); + SingularCallBack( Class * class_instance, Method method ) : class_instance_( class_instance ), method_( method ) { } + + ReturnType operator()( Parameter parameter ) { return ( class_instance_->*method_ )( parameter ); } + ReturnType execute( Parameter parameter ){ return operator()( parameter ); } +private: + Class * class_instance_; + Method method_; +}; + +template < class Object, typename returnT, typename Args > class memberBind { +public: + typedef returnT( Object::*F )( Args ); + memberBind( F function, Object * object) : function_( function ), object_( object ) {} + + returnT operator()( Args args ) const { return ( object_->*function_ )( args ); } +protected: + F function_; + Object object_; +}; + + } // namespace OpenGate #endif // _OPENGATE_OPENGATE__H Modified: trunk/src/SectorBaseObject.h =================================================================== --- trunk/src/SectorBaseObject.h 2009-02-10 19:19:48 UTC (rev 1025) +++ trunk/src/SectorBaseObject.h 2009-02-11 22:20:22 UTC (rev 1026) @@ -24,8 +24,8 @@ #include "Opengate.h" namespace OpenGate{ - -/*! Baseclass for SectorObjects. All visible and interaction stuff that belongs to a sector is a SectorObject. Each SectorObject has a OgreSceneNode and provide a update function */ + +/*! Baseclass for SectorObjects. All visible and interaction stuff that belongs to a sector is a SectorObject. Each SectorObject has a OgreSceneNode and provide a update function */ class SectorBaseObject { public: /*! Construct SectorBaseObject, each SectorObject must have an unique name, a sector (which can be understand as a runtime container for the object) @@ -34,55 +34,55 @@ /*! Default destructor */ virtual ~SectorBaseObject( ); - + /*! Abstract class for runtime identification */ virtual int rtti( ) const = 0; - + /*! Base update loop return fals either !update_() or destroyRequest */ virtual bool update( Ogre::Real elapsedTime ) = 0; - + //** Start GETer/SETer /*! Return the name of the object */ inline const std::string & name() const { return name_; } - + /*! Return a ptr to the corresponding sector */ inline Sector * sector() { return sector_; } - + /*! Return a ptr to main OgreSceneNode for this SectorObject. */ inline Ogre::SceneNode * mainNode() { return mainNode_; } - + inline bool isDestroyRequest() const { return destroyRequest_; } - + //** END GETer/SETer - + protected: - /*! Mark the object for destruction \n + /*! Mark the object for destruction \n To keep destruction thread safe, we just notify and let update return false, so the sector update cycle do the destruction job */ inline void setDestroyRequest_( bool dest = true ) { destroyRequest_ = dest; } - - + + std::string name_; Sector * sector_; Ogre::SceneNode * mainNode_; - + bool destroyRequest_; }; - + /*! Sectorobject that represent space environment without collision*/ class SectorEnvironmentObject : public SectorBaseObject { SectorEnvironmentObject( const Ogre::String & name, Sector * sector ); }; - - - - class SectorPlanetObject : public SectorEnvironmentObject{ + + + + /*class SectorPlanetObject : public SectorEnvironmentObject{ }; class SectorStarfieldObject : public SectorEnvironmentObject{ }; class SectorSpaceDustObject : public SectorEnvironmentObject{ }; class SectorSpaceDecorationObject : public SectorEnvironmentObject{ - }; + };*/ } //namespace OpenGate Modified: trunk/src/SectorMeshObject.h =================================================================== --- trunk/src/SectorMeshObject.h 2009-02-10 19:19:48 UTC (rev 1025) +++ trunk/src/SectorMeshObject.h 2009-02-11 22:20:22 UTC (rev 1026) @@ -25,8 +25,8 @@ #include "SectorCollisionObject.h" namespace OpenGate{ - -/*! Baseclass for SectorObjects with Ogre::Meshs. SectorMeshObject can by selected */ + +/*! Baseclass for SectorObjects with Ogre::Meshs. SectorMeshObject can by selected */ class SectorMeshObject : public SectorCollisionObject { public: /*! Construct SectorObjectBase, */ @@ -34,77 +34,77 @@ /*! Default destructor */ virtual ~SectorMeshObject( ); - + /*! Abstract method for runtime identification */ virtual int rtti( ) const { return SECTOR_MESH_OBJECT_RTTI; } - + /*! Update function */ virtual bool update( Ogre::Real elapsedTime ) { return true; } - + /*! Method for collision handling, called during a collision by opcodewrapper */ virtual void collide( SectorCollisionObject * object ); - + /*! Set the the mesh by a given meshname and initialize collision, the meshname must known to the global ogre::resourcemanager */ void setMesh( const std::string & meshname ); - + /*! Static scale the mesh to size */ void setBaseScale( const Ogre::Real & scale ); - + /*! Static scale the mesh to size */ void setBaseSize( const Ogre::Vector3 & size ); - + /*! Static rotation to the mesh */ void setBaseRot( const Ogre::Real & yaw, const Ogre::Real & pitch = 0, const Ogre::Real & roll = 0 ); - + /*! Returns a ptr to the base scale node */ inline Ogre::SceneNode * scaleNode() { return entityScaleNode_;} - + /*! Returns a ptr to the base rotation node */ inline Ogre::SceneNode * rotNode() { return entityRotNode_;} - - - - /*! Add an object to the set of observers e.g. selected as target + + + + /*! Add an object to the set of observers e.g. selected as target When this object dies the observers have to be informed. */ inline void addObserver( SectorMeshObject * obj ){ observers_.insert( obj ); } - + /*! Remove observer from, e.g. deselect as target */ inline void delObserver( SectorMeshObject * obj ){ observers_.erase( obj ); } - + /*! Set an object as target, used for missiles, avatar. This object becomes an observer for the target. */ virtual void setTarget( SectorMeshObject * target ); - + /*! Return the current target. */ virtual SectorMeshObject * target( ){ return target_; } - + /*! The target disapear and inform this object. */ virtual void looseTarget( ); - + /*! Unsubscribe this object from all objects that observe this object, Usually when this object disapears*/ void unsubscribeToObservers(); - + /*! Destroy the mesh object and emit explosion*/ virtual void explode(); - + /*! Destroy the object without explosion */ virtual void destroy(); - + /*! Reset the object, clear target_ pointer and list of observers_; */ virtual void reset( ); - + protected: Ogre::SceneNode * entityScaleNode_; // Main character node for base size Ogre::SceneNode * entityRotNode_; // Main character node for base rotation - std::set < SectorMeshObject * > observers_; + std::set < SectorMeshObject * > observers_; SectorMeshObject * target_; }; - class SectorAsteroidObject : public SectorMeshObject{ + /* class SectorAsteroidObject : public SectorMeshObject{ }; class SectorAnomalieObject : public SectorMeshObject{ - }; + };*/ } //namespace OpenGate Modified: trunk/src/common.h =================================================================== --- trunk/src/common.h 2009-02-10 19:19:48 UTC (rev 1025) +++ trunk/src/common.h 2009-02-11 22:20:22 UTC (rev 1026) @@ -48,17 +48,18 @@ #include <algorithm> #include <sys/timeb.h> #include <stdexcept> - - + typedef uint8_t Uint8; typedef uint16_t Uint16; typedef uint32_t Uint32; #ifdef WIN32 #define PATHSEPARATOR "\\" -typedef unsigned int uint; +typedef size_t uint; -#include <windows.h> +#include <windows.h> +#undef near +#undef far #else #define PATHSEPARATOR "/" #endif @@ -74,7 +75,7 @@ int a, b, c; }; inline bool operator == ( const Triangle & a, const Triangle & b ) { return ( a.a == b.a && a.b == b.b && a.c == b.c ); } - + inline Uint32 createGlobalID( Uint32 userId, Uint8 childId ) { return childId * MAXUSERID + userId; } //! In-place convert string to lower case \return ref to transformed string @@ -92,7 +93,7 @@ /*! Read one line from a file stream and return a vector of strings. */ std::vector < std::string > getRowSubstrings( std::fstream & file, char comment = '#' ); -inline std::string strReplaceBlankWithUnderscore( const std::string & str ) { +inline std::string strReplaceBlankWithUnderscore( const std::string & str ) { std::string res( str ); for ( uint i = 0; i < res.length(); i ++ ){ @@ -102,7 +103,7 @@ } -#define __D( str ) +#define __D( str ) //#define __D( str ) DebugBreakPoint __d( toStr( __ASSERT_FUNCTION ) + " " + str ); #define WHERE_AM_I toStr( __FILE__ ) + ": "+ toStr( __LINE__) + " " + toStr( __ASSERT_FUNCTION ) + " " #define __Dtmp( str ) DebugBreakPoint __dtmp( WHERE_AM_I + str ); @@ -135,7 +136,7 @@ // std::transform(wdata.begin(),wdata.end(),wdata.begin(),ToLower<wchar_t>(locE)); //** to test with unicode - + /*! * \brief This method compares two values and returns the smaller one * \param a One of the values to compare @@ -194,7 +195,7 @@ * \param str The string you want to convert */ inline float toFloat( const std::string & str ) { return to< float >( str ); } - + /*! * \brief This method converts a string to double * \param str The string you want to double @@ -238,27 +239,27 @@ class Stopwatch { public: Stopwatch() { state = undefined; } - void start(){ + void start(){ ftime( & starttime ); state = running; } - void stop( bool verbose = false ){ + void stop( bool verbose = false ){ ftime( & stoptime ); state = halted; if ( verbose ) std::cout << "time: " << duration() << "s" << std::endl; } /*! Restart the stopwatch.*/ - void restart(){ + void restart(){ stop(); start(); } /*! Reset the stopwatch, same like \ref restart.*/ void reset(){ restart(); } - double duration(){ + double duration(){ if ( state == undefined ) std::cerr << "Stopwatch not started!" << std::endl;; if ( state == running ) ftime( &stoptime ); - return double( stoptime.time - starttime.time ) + return double( stoptime.time - starttime.time ) + double( stoptime.millitm - starttime.millitm ) / 1000.0; } protected: @@ -266,17 +267,17 @@ enum watchstate {undefined,halted,running} state; }; -template < class Container > int split( const std::string & input, +template < class Container > int split( const std::string & input, const std::string & delimiter, Container & results ){ int pos = 0; int offset = 0; int lengthDelimiter = (int)delimiter.size(); int lengthInput = (int)input.size(); - + if ( ( lengthInput == 0 ) || ( lengthDelimiter == 0 ) ) { return 0; } - + while ( ( pos = input.find( delimiter, offset ) ) ) { results.push_back( input.substr( offset, pos-offset ) ); if ( pos == (int)std::string::npos ) { @@ -289,7 +290,7 @@ struct deletePtr{ template < typename T > void operator()( T * p ) { if ( p ) { delete p; p = NULL; } } }; -template < class ValueType > +template < class ValueType > bool readXMLAttribute( TiXmlElement * pElem, const std::string & name, ValueType & val ){ std::vector < std::string > names( getSubstrings( name ) ); for ( uint i = 0; i < names.size(); i ++ ) { @@ -301,13 +302,13 @@ return false; } -/*! Read a single xml-element with a given key and fill associated object properties. +/*! Read a single xml-element with a given key and fill associated object properties. If the mandatory flag is set, a std::invalid_argument exception is thrown when the node can not be found.*/ -template < class ValueType, class Class, class Method > +template < class ValueType, class Class, class Method > bool readXMLAttribute( TiXmlElement * pElem, const std::string & name, Class * obj, Method method, bool mandatory ){ // std::vector < std::string > names( getSubstrings( name ) ); -// +// // for ( uint i = 0; i < names.size(); i ++ ) { // if ( pElem->Attribute( names[ i ] ) ){ // (obj->*method)( to< ValueType >( *pElem->Attribute( names[ i ] ) ) ); @@ -321,19 +322,19 @@ (obj->*method)( val ); return true; } - + if ( mandatory ){ throw std::invalid_argument( "Missing mandatory xml node " + name + " for entity " + obj->name() ); } return false; } -/*! Read a single xml-node with a given key and fill associated object properties. +/*! Read a single xml-node with a given key and fill associated object properties. If the mandatory flag is set, a std::invalid_argument exception is thrown when the node can not be found.*/ -template < class ValueType, class Class, class Method > +template < class ValueType, class Class, class Method > bool readXMLNode( TiXmlHandle & hRoot, const std::string & key, Class * obj, Method method, bool mandatory ){ std::vector < std::string > keys( getSubstrings( key ) ); - + TiXmlElement * pElem; for ( uint i = 0; i < keys.size(); i ++ ) { pElem = hRoot.ChildElement( keys[ i ], 0 ).Element(); @@ -351,16 +352,15 @@ } /*! Read all xml-nodes with a given key and fill associated object properties.*/ -template < class ValueType, class Class, class Method > +template < class ValueType, class Class, class Method > bool readXMLNodes( TiXmlHandle & hRoot, const std::string & key, Class * obj, Method method ){ TiXmlElement * pElem; - + for ( pElem = hRoot.FirstChild( key ).Element(); pElem != 0; pElem = pElem->NextSiblingElement() ) { (obj->*method)( to< ValueType>( pElem->FirstChild()->Value() ) ); } return true; } - #endif // _OPENGATE_COMMON__H This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |