forked from mirrors/0ad
[Entities and Events] Still incomplete, but compiles cleanly. Replaces version accidentally commited that didn't.
This was SVN commit r152.
This commit is contained in:
+3
-12
@@ -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 );
|
||||
}
|
||||
|
||||
+35
-27
@@ -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<CHandlePool>
|
||||
{
|
||||
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<CHandlePool>
|
||||
{
|
||||
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 )
|
||||
|
||||
Executable
Executable
+46
@@ -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
|
||||
|
||||
|
||||
Executable
+59
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
@@ -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;
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user