diff --git a/source/ps/Entity.cpp b/source/ps/Entity.cpp index 8d8317d608..b8ca7aa234 100755 --- a/source/ps/Entity.cpp +++ b/source/ps/Entity.cpp @@ -1,6 +1,6 @@ // Last modified: 19 January 2004 (Mark Thompson) -#include "entity.h" +#include "Entity.h" //-------------------------------------------------------- // CEntity: Entity class @@ -260,15 +260,6 @@ HEntityWeak::HEntityWeak( unsigned short _index ) index = _index; } -//-------------------------------------------------------- -// HEntityWeak::operator=( const HEntityWeak& copy ) -//-------------------------------------------------------- - -void HEntityWeak::operator=( const HEntityWeak& copy ) -{ - index = copy.index; -} - //-------------------------------------------------------- // HEntityWeak::operator*() //-------------------------------------------------------- @@ -288,7 +279,7 @@ CEntity* HEntityWeak::operator->() { assert( index != BAD_HANDLE ); assert( g_HandlePool.Pool[index].ptr ); - return( *g_HandlePool.Pool[index].ptr ); + return( g_HandlePool.Pool[index].ptr ); } //-------------------------------------------------------- @@ -297,5 +288,5 @@ CEntity* HEntityWeak::operator->() HEntityWeak::operator HEntity() { - return *( new HEntity( index ) ); + return HEntity( index ); } diff --git a/source/ps/Entity.h b/source/ps/Entity.h index f23ae021d8..23296f5b3f 100755 --- a/source/ps/Entity.h +++ b/source/ps/Entity.h @@ -29,7 +29,8 @@ TDD at http://forums.wildfiregames.com/0ad #include "assert.h" #include "stdio.h" -#include "ps/singleton.h" +#include "singleton.h" +#include "Event.h" // Handle defines @@ -45,6 +46,22 @@ class CEntity; class HEntity; class HEntityWeak; +// HEntityWeak: Weak (non-refcounted) smart pointer + +class HEntityWeak +{ + friend CHandlePool; + friend HEntity; +private: + unsigned short index; + HEntityWeak( unsigned short index ); +public: + HEntityWeak(); + CEntity& operator*(); + CEntity* operator->(); + operator HEntity(); +}; + // CEntity: Entity class class CEntity @@ -58,13 +75,15 @@ public: CEntity(); ~CEntity(); void Dispatch( CEvent* ev ); -} +}; // CHandle: Entity handles, used by manager class class CHandle { friend CHandlePool; + friend HEntity; + friend HEntityWeak; private: CEntity* ptr; unsigned short refcount; @@ -73,29 +92,12 @@ private: ~CHandle(); }; -// CHandlePool: Tracks entity handles - -#define g_HandlePool CHandlePool::GetSingleton() - -class CHandlePool : public Singleton -{ - friend HEntity; -private: - unsigned short FreeHandle; - CHandle Pool[MAX_HANDLES]; -public: - CHandlePool(); - ~CHandlePool(); - HEntity Assign( CEntity* ptr ); - HEntity Create() { return Assign( new CEntity ); }; - void Destroy( unsigned short index ); -}; - // HEntity: Entity smart pointer class HEntity { friend CHandlePool; + friend HEntityWeak; private: unsigned short index; HEntity( unsigned short index ); @@ -112,17 +114,23 @@ public: ~HEntity(); }; -// HEntityWeak: Weak (non-refcounted) smart pointer +// CHandlePool: Tracks entity handles -class HEntityWeak +#define g_HandlePool CHandlePool::GetSingleton() + +class CHandlePool : public Singleton { - friend CHandlePool; + friend HEntity; + friend HEntityWeak; private: - unsigned short index; - HEntityWeak( unsigned short index ); + unsigned short FreeHandle; + CHandle Pool[MAX_HANDLES]; public: - CEntity& operator*(); - CEntity* operator->(); + CHandlePool(); + ~CHandlePool(); + HEntity Assign( CEntity* ptr ); + HEntity Create() { return Assign( new CEntity ); }; + void Destroy( unsigned short index ); }; #endif // !defined( ENTITY_INCLUDED ) diff --git a/source/ps/Event.cpp b/source/ps/Event.cpp new file mode 100755 index 0000000000..e69de29bb2 diff --git a/source/ps/Event.h b/source/ps/Event.h new file mode 100755 index 0000000000..f6187771a2 --- /dev/null +++ b/source/ps/Event.h @@ -0,0 +1,46 @@ +/* +Event.h + +Game event (scheduled messages) definitions + +Mark Thompson (markt@0ad.wildfiregames.com) + +Last modified: 19 January 2004 (Mark Thompson) + +--Overview-- + +Contains the class definitions for serializable event messages. +--Usage-- + +TODO + +--Examples-- + +TODO + +--More info-- + +TDD at http://forums.wildfiregames.com/0ad + +*/ + +#ifndef EVENT_INCLUDED +#define EVENT_INCLUDED + +#include "assert.h" +#include "stdio.h" +#include "Network/Serialization.h" +#include "Entity.h" +#include "Network/NetMessage.h" + +class CEvent : public CNetMessage +{ +public: + virtual uint GetSerializedLength() = 0; + virtual u8* Serialize( u8* buffer ) = 0; +}; + + +#endif // EVENT_INCLUDED + + diff --git a/source/ps/EventTypes.h b/source/ps/EventTypes.h new file mode 100755 index 0000000000..d7efb4df4f --- /dev/null +++ b/source/ps/EventTypes.h @@ -0,0 +1,59 @@ +/* + + Net Message Creator registration + +*/ + + #ifdef CREATING_NMT + + //HACKA HACKA HACKA HACKA HACKA HACK... + + #ifdef NMT_CREATOR_PASS_CLASSDEF + +/* + + The Event classes; + + Adding an event currently requires four steps. + + One, create the event class within the NMT_CREATOR_PASS_CLASSDEF + ifdef. The classEvent macro will help. + + Two, assign an message type in NetMessage.h. + + Three, provide a deserializer function mapping in the + NMT_CREATOR_PASS_REGISTRATION ifdef, below. + + Four, implement the interface ISerializable for the new class in + Event.cpp. + +*/ + + #define classEvent( _ev ) \ + struct CEvent##_ev : public CEvent \ + { \ + public: \ + uint GetSerializedLength(); \ + u8* Serialize( u8* buffer ); \ + static CNetMessage* Deserialize( const u8* buffer, \ + uint length ); + + + +/* + classEvent( TestOnly ) + int16 TheIntegerIveGot; + }; +*/ + + #endif + + #ifdef NMT_CREATOR_PASS_REGISTRATION + +/* + { NMT_Event_IveGotAnInteger, CEventTestOnly::Deserialize }, +*/ + + #endif + + #endif \ No newline at end of file diff --git a/source/ps/Network/AllNetMessages.h b/source/ps/Network/AllNetMessages.h index 7cf5a63083..7c57ec5136 100755 --- a/source/ps/Network/AllNetMessages.h +++ b/source/ps/Network/AllNetMessages.h @@ -22,9 +22,14 @@ enum NetMessageType */ NMT_NONE=0, + /* Game event messages */ + + NMT_Event_IveGotAnInteger, + /* Beware, the list will contain bogus messages when under development ;-) */ NMT_Aloha, NMT_Sayonara, + /** * One higher than the highest value of any message type @@ -50,6 +55,8 @@ START_NMT_CLASS(SayonaraMessage, NMT_Sayonara) NMT_FIELD(CStr, m_SayonaraCode) END_NMT_CLASS() +#include "../EventTypes.h" + END_NMTS() #else diff --git a/source/ps/Network/NMTCreator.h b/source/ps/Network/NMTCreator.h index 0544cd59b4..f291768660 100755 --- a/source/ps/Network/NMTCreator.h +++ b/source/ps/Network/NMTCreator.h @@ -21,6 +21,7 @@ /*************************************************************************/ // Pass 1, class definition +#define NMT_CREATOR_PASS_CLASSDEF #define START_NMTS() #define END_NMTS() @@ -66,11 +67,13 @@ struct _nm: public CNetMessage \ #define END_NMT_CLASS() }; #include "NMTCreator.h" +#undef NMT_CREATOR_PASS_CLASSDEF #ifdef NMT_CREATOR_IMPLEMENT /*************************************************************************/ // Pass 2, GetSerializedLength +#define NMT_CREATOR_PASS_GETLENGTH #define START_NMTS() #define END_NMTS() @@ -90,9 +93,13 @@ uint _nm::GetSerializedLength() const \ }; #include "NMTCreator.h" +#undef NMT_CREATOR_PASS_GETLENGTH /*************************************************************************/ // Pass 3, Serialize + +#define NMT_CREATOR_PASS_SERIALIZE + #define START_NMTS() #define END_NMTS() @@ -112,8 +119,13 @@ void _nm::Serialize(u8 *buffer) const \ #include "NMTCreator.h" +#undef NMT_CREATOR_PASS_SERIALIZE + /*************************************************************************/ // Pass 4, Deserialize + +#define NMT_CREATOR_PASS_DESERIALIZE + #define START_NMTS() #define END_NMTS() @@ -143,8 +155,13 @@ CNetMessage *Deserialize##_nm(const u8 *buffer, uint length) \ #undef BAIL_DESERIALIZER +#undef NMT_CREATOR_PASS_DESERIALIZE + /*************************************************************************/ // Pass 5, Deserializer Registration + +#define NMT_CREATOR_PASS_REGISTRATION + #define START_NMTS() SNetMessageDeserializerRegistration g_DeserializerRegistrations[] = { #define END_NMTS() { NMT_NONE, NULL } }; @@ -159,6 +176,8 @@ CNetMessage *Deserialize##_nm(const u8 *buffer, uint length) \ #include "NMTCreator.h" +#undef NMT_CREATOR_PASS_REGISTRATION + #endif // #ifdef NMT_CREATOR_IMPLEMENT /*************************************************************************/ diff --git a/source/ps/Network/NetMessage.h b/source/ps/Network/NetMessage.h index 37802164b0..df6fc1eaf7 100755 --- a/source/ps/Network/NetMessage.h +++ b/source/ps/Network/NetMessage.h @@ -7,6 +7,7 @@ #include "AllNetMessages.h" #undef ALLNETMSGS_DONT_CREATE_NMTS + class CNetMessage { NetMessageType m_Type; @@ -45,6 +46,8 @@ public: class CNetMessage; typedef CNetMessage * (*NetMessageDeserializer) (const u8 *buffer, uint length); +#include "Entity.h" + struct SNetMessageDeserializerRegistration { NetMessageType m_Type; diff --git a/source/vc6/ps.dsp b/source/vc6/ps.dsp index 6cd6fc1085..d61fcfc7a8 100755 --- a/source/vc6/ps.dsp +++ b/source/vc6/ps.dsp @@ -583,7 +583,7 @@ SOURCE=..\ps\Encryption.h # End Source File # Begin Source File -SOURCE=.\Entity.cpp +SOURCE=..\ps\Entity.cpp # End Source File # Begin Source File