1
0
forked from 0ad/0ad

committing the current status of dacian's new network code on matei's request

also includes sound support.

GameSetup: ensure all ScriptingInit are called; moved simulation
ScriptingInits and init/shutdown to SimulationScriptInit.cpp (reduces
#includes)

This was SVN commit r6028.
This commit is contained in:
janwas 2008-06-16 18:19:35 +00:00
parent ab2f86ff75
commit b0a6d6dca8
25 changed files with 1930 additions and 521 deletions

View File

@ -166,9 +166,9 @@ void CMiniMap::FireWorldClickEvent(int button, int clicks)
g_JSGameEvents.FireWorldClick(
button,
clicks,
NMT_Goto,
NMT_GOTO,
-1,
NMT_Run,
NMT_RUN,
-1,
NULL,
(int)Destination.x,

View File

@ -31,13 +31,15 @@ that of Atlas depending on commandline parameters.
#include "ps/Hotkey.h"
#include "ps/Globals.h"
#include "ps/Interact.h"
#include "network/Client.h"
#include "network/Server.h"
#include "network/SessionManager.h"
#include "network/NetClient.h"
#include "network/NetServer.h"
//#include "network/SessionManager.h"
#include "network/NetSession.h"
#include "graphics/Camera.h"
#include "graphics/GameView.h"
#include "simulation/Scheduler.h"
#include "sound/CMusicPlayer.h"
#include "sound/SoundGroupMgr.h"
#include "gui/GUI.h"
#define LOG_CATEGORY "main"
@ -204,6 +206,10 @@ static void Frame()
music_player.Update();
PROFILE_END( "update music" );
PROFILE_START( "update sound groups" );
g_soundGroupMgr->UpdateSoundGroups(TimeSinceLastFrame);
PROFILE_END( "update sound groups" );
bool is_building_archive; // must come before PROFILE_START's {
PROFILE_START("build archive");
MICROLOG(L"build archive");
@ -231,7 +237,9 @@ static void Frame()
PROFILE_START("input");
MICROLOG(L"input");
PumpEvents();
g_SessionManager.Poll();
//g_SessionManager.Poll();
if ( CNetHost::IsInitialised() )
CNetHost::GetSingleton().Poll();
PROFILE_END("input");
ogl_WarnIfError();

View File

@ -49,23 +49,19 @@ CNetMessage *Deserialize##_nm(const u8 *, size_t); \
class _nm: public _base \
{ \
protected: \
_nm(ENetMessageType type): _base(type) {}\
_nm(NetMessageType type): _base(type) {}\
\
/* This one is for subclasses that want to use the base class' string */ \
/* converters to get SubMessage { <parent fields>, ... } */ \
CStr GetStringRaw() const;\
CStr ToStringRaw() const;\
public: \
_nm(): _base(_tp) {} \
virtual size_t GetSerializedLength() const; \
virtual u8 *Serialize(u8 *buffer) const; \
virtual const u8 *Deserialize(const u8 *pos, const u8 *end); \
virtual CStr GetString() const; \
virtual CNetMessage *Copy() const \
{ \
return new _nm(*this); \
} \
virtual CStr ToString() const; \
inline operator CStr () const \
{ return GetString(); }
{ return ToString(); }
/**
* Add an integer field to the message type.
@ -251,13 +247,18 @@ const u8 *_nm::Deserialize(const u8 *pos, const u8 *end) \
#define NMT_CREATOR_PASS_REGISTRATION
#define START_NMTS() SNetMessageDeserializerRegistration g_DeserializerRegistrations[] = {
#define END_NMTS() { NMT_NONE, NULL } };
//#define START_NMTS() SNetMessageDeserializerRegistration g_DeserializerRegistrations[] = {
//#define END_NMTS() { NMT_INVALID, NULL } };
#define START_NMTS()
#define END_NMTS()
#define START_NMT_CLASS(_nm, _tp) \
START_NMT_CLASS_DERIVED(CNetMessage, _nm, _tp)
#define START_NMT_CLASS_DERIVED(_base, _nm, _tp) \
{ _tp, Deserialize##_nm },
//#define START_NMT_CLASS_DERIVED(_base, _nm, _tp) \
// { _tp, Deserialize##_nm },
#define START_NMT_CLASS_DERIVED(_base, _nm, _tp)
#define NMT_START_ARRAY(_nm)
@ -285,26 +286,26 @@ const u8 *_nm::Deserialize(const u8 *pos, const u8 *end) \
#define END_NMTS()
#define START_NMT_CLASS(_nm, _tp) \
CStr _nm::GetString() const \
CStr _nm::ToString() const \
{ \
CStr ret=#_nm _T(" { "); \
return ret + GetStringRaw() + _T(" }"); \
return ret + ToStringRaw() + _T(" }"); \
} \
CStr _nm::GetStringRaw() const \
CStr _nm::ToStringRaw() const \
{ \
CStr ret; \
const _nm *thiz=this;\
UNUSED2(thiz); // preempt any "unused" warning
#define START_NMT_CLASS_DERIVED(_base, _nm, _tp) \
CStr _nm::GetString() const \
CStr _nm::ToString() const \
{ \
CStr ret=#_nm _T(" { "); \
return ret + GetStringRaw() + _T(" }"); \
return ret + ToStringRaw() + _T(" }"); \
} \
CStr _nm::GetStringRaw() const \
CStr _nm::ToStringRaw() const \
{ \
CStr ret=_base::GetStringRaw() + _T(", "); \
CStr ret=_base::ToStringRaw() + _T(", "); \
const _nm *thiz=this;\
UNUSED2(thiz); // preempt any "unused" warning

File diff suppressed because it is too large Load Diff

View File

@ -1,97 +1,237 @@
#ifndef INCLUDED_NETWORK_NETMESSAGE
#define INCLUDED_NETWORK_NETMESSAGE
/**
*-----------------------------------------------------------------------------
* FILE : NetMessage.h
* PROJECT : 0 A.D.
* DESCRIPTION : Defines the basic interface for network messages
*-----------------------------------------------------------------------------
*/
#ifndef NETMESSAGE_H
#define NETMESSAGE_H
// INCLUDES
#include "Serialization.h"
#include "SocketBase.h"
#include "ps/Vector2D.h"
#include <map>
// We need the enum from AllNetMessages.h, but we can't create any classes in
// AllNetMessages, since they in turn require CNetMessage to be defined
#define ALLNETMSGS_DONT_CREATE_NMTS
#include "AllNetMessages.h"
#include "NetMessages.h"
#undef ALLNETMSGS_DONT_CREATE_NMTS
class CNetCommand;
class CVector2D;
struct CEntityList;
/**
* The base class for network messages
/*
CLASS : CNetMessage
DESCRIPTION : CNetMessage is the base class for all network messages
exchanged within the game.
NOTES :
*/
class CNetMessage : public ISerializable
{
ENetMessageType m_Type;
protected:
inline CNetMessage(ENetMessageType type):
m_Type(type)
{}
friend class CNetSession;
public:
virtual ~CNetMessage();
inline ENetMessageType GetType() const
{ return m_Type; }
CNetMessage( void );
CNetMessage( NetMessageType type );
virtual ~CNetMessage( void );
/**
* @returns The length of the message when serialized.
*/
virtual size_t GetSerializedLength() const;
/**
* Serialize the message into the buffer. The buffer will have the size
* returned from the last call to GetSerializedLength()
*/
virtual u8 *Serialize(u8 *buffer) const;
virtual const u8 *Deserialize(const u8 *pos, const u8 *end);
/**
* Make a string representation of the message. The default implementation
* returns the empty string
*/
virtual CStr GetString() const;
inline operator CStr() const
{ return GetString(); }
/**
* Copy the message
*/
virtual CNetMessage *Copy() const;
/**
* Deserialize a net message, using the globally registered deserializers.
* Retrieves the message header. If changes are made on header,SetDirty
* must be called on the header's message
*
* @param type The NetMessageType of the message
* @param buffer A pointer to the buffer holding the message data
* @param length The length of the message data
*
* @returns a pointer to a newly created CNetMessage subclass, or NULL if
* there was an error in data format.
* @return Message header
*/
static CNetMessage *DeserializeMessage(ENetMessageType type, u8 *buffer, size_t length);
//const CNetMessageHeader& GetHeader( void ) const { return m_Header; }
NetMessageType GetType( void ) const { return m_Type; }
/**
* Returns whether the message has changed since its last use
*
* @return true if it changed or false otherwise
*/
bool GetDirty( void ) const { return m_Dirty; }
/**
* Specify the message has changed since its last use
*
*/
void SetDirty( void ) { m_Dirty = true; }
/**
* Serialize the message into the specified buffer parameter. The size
* required by the buffer parameter can be found by a call to
* GetSerializedLength method. The information contained within the message
* must be serialized before the message is sent. By default only the
* message type and its size are serialized in the buffer parameter.
*
* @param pBuffer Buffer where to serialize the message
* @return The position in the buffer right after the
* serialized message
*/
virtual u8* Serialize( u8* pBuffer ) const;
/**
* Deserializes the message from the specified buffer.
*
* @param pStart Message start within the serialized buffer
* @param pEnd Message end within the serialized buffer
* @return The position in the buffer right after the
* message or NULL if an error occured
*/
virtual const u8* Deserialize( const u8* pStart, const u8* pEnd );
/**
* Deserializes the specified message from the specified buffer using
* registered deserializers.
*
* @param messageType Message type
* @param pBuffer Buffer from which to deserialize
* @param bufferSize The size in bytes of the buffer
* @return A pointer to a newly created
* CNetMessage, or NULL if the message was
* not correctly deserialized.
*/
static CNetMessage* Deserialize(
NetMessageType type,
const u8* pBuffer,
uint bufferSize );
//static CNetMessage* Deserialize(ENetMessageType type, u8 *buffer, uint length);
/**
* Retrieves the size in bytes of the serialized message. Before calling
* Serialize,the memory size for the buffer where to serialize the message
* object can be found by calling this method.
*
* @return The size of serialized message
*/
virtual uint GetSerializedLength() const;
/**
* Returns a string representation for the message
*
* @return The message as a string
*/
virtual CStr ToString( void ) const;
// virtual CStr GetString( void ) const;
// operator CStr() const { return GetString(); }
/**
* Makes a copy of the message
*
* @return A copy of the message
*/
virtual CNetMessage* Clone( void ) const;
// virtual CNetMessage* Copy( void ) const;
protected:
/**
* Copies the content of this message into the message specified parameter
*
* @param Message destination
*/
virtual void Copy( CNetMessage* pMessage ) const;
private:
// Not implemented
CNetMessage( const CNetMessage& );
CNetMessage& operator=( const CNetMessage& );
bool m_Dirty; // Message has been modified
NetMessageType m_Type; // Message type
//u16 m_SerializeSize; // Serialized message size in bytes
public:
/**
* Register a selection of message types as JS constants.
* The constant's names will be the same as those of the enums
*/
static void ScriptingInit();
static void ScriptingInit( void );
static CNetCommand *CommandFromJSArgs(const CEntityList &entities, JSContext* cx, uintN argc, jsval* argv, bool isQueued);
/*static CCommandMessage* CommandFromJSArgs(
const CEntityList &entities,
JSContext* cx,
uintN argc,
jsval* argv,
bool isQueued );*/
//These can create a net message without JS args
static CNetMessage *CreatePositionMessage( const CEntityList& entities, const int type, CVector2D pos );
static CNetMessage *CreateEntityIntMessage( const CEntityList& entities, const int type, HEntity& target, int action );
static CNetMessage *CreateProduceMessage( const CEntityList& entities, const int type, int proType, const CStrW& name );
static CNetMessage* CommandFromJSArgs(
const CEntityList &entities,
JSContext* cx,
uintN argc,
jsval* argv,
bool isQueued );
static CNetMessage* CreatePositionMessage(
const CEntityList& entities,
const int type,
CVector2D pos );
static CNetMessage* CreateEntityIntMessage(
const CEntityList& entities,
const int type,
HEntity& target,
int action );
static CNetMessage* CreateProduceMessage(
const CEntityList& entities,
const int type,
int proType,
const CStrW& name );
};
typedef CNetMessage * (*NetMessageDeserializer) (const u8 *buffer, size_t length);
#include "simulation/EntityHandles.h"
struct SNetMessageDeserializerRegistration
/*
CLASS : CNetMessageFactory
DESCRIPTION : Creates messages from data received through the network
NOTES : It follows the factory method pattern implementation
*/
class CNetMessageFactory
{
ENetMessageType m_Type;
NetMessageDeserializer m_pDeserializer;
public:
/**
* Factory method which creates a message object based on the given data
*
* @param pData Data buffer
* @param dataSize Size of data buffer
* @return The new message created
*/
static CNetMessage* CreateMessage( const void* pData, size_t dataSize );
/**
* Factory methods which creates a message object from JavaScript arguments
*
* @param entities
* @param pContext
* @param argc
* @param argv
* @param isQueued
* @return The new message created
*/
static CNetMessage* CreateMessage(
const CEntityList &entities,
JSContext *pContext,
uintN argc,
jsval *argv,
bool queued );
protected:
private:
// Not implemented
CNetMessageFactory( void );
~CNetMessageFactory( void );
CNetMessageFactory( const CNetMessageFactory& );
CNetMessageFactory& operator=( const CNetMessageFactory& );
};
// This time, the classes are created
#include "AllNetMessages.h"
#include "NetMessages.h"
#endif // #ifndef INCLUDED_NETWORK_NETMESSAGE
#endif // NETMESSAGE_H

View File

@ -1,5 +1,5 @@
#include "precompiled.h"
#include "precompiled.h"
#include "Network.h"
#include "Serialization.h"
#include "ps/CLogger.h"
@ -8,10 +8,6 @@
DEFINE_ERROR(CONFLICTING_OP_IN_PROGRESS, "A conflicting operation is already in progress");
#define ALIGN_UP(_n, _block) (_n+_block-(_n%_block))
#define BUFFER_BLOCK 4096
#define BUFFER_SIZE(_n) ALIGN_UP(_n, BUFFER_BLOCK)
#define LOG_CAT_NET "net"
/**
@ -77,7 +73,7 @@ CNetMessage *CMessagePipe::End::TryPop()
}
}*/
CStr CNetErrorMessage::GetString() const
/*CStr CErrorMessage::GetString() const
{
static const char* const states[]={
"SS_UNCONNECTED",
@ -96,13 +92,37 @@ CStr CConnectCompleteMessage::GetString() const
}
CStr CCloseRequestMessage::GetString() const
{
return CStr("CloseRequestMessage");
}*/
CStr CErrorMessage::ToString( void ) const
{
static const char* const states[]=
{
"SS_UNCONNECTED",
"SS_CONNECT_STARTED",
"SS_CONNECTED",
"SS_CLOSED_LOCALLY"
};
return CStr("NetErrorMessage: ")+
m_Error+", Socket State "+states[m_State];
}
CStr CConnectCompleteMessage::ToString( void ) const
{
return CStr( "ConnectCompleteMessage" );
}
CStr CCloseRequestMessage::ToString( void ) const
{
return CStr( "CloseRequestMessage" );
}
void CMessageSocket::Push(CNetMessage *msg)
{
NET_LOG2( "CMessageSocket::Push(): %s", msg->GetString().c_str() );
NET_LOG2( "CMessageSocket::Push(): %s", msg->ToString().c_str() );
m_OutQ.Lock();
m_OutQ.push_back(msg);
@ -164,7 +184,8 @@ void CMessageSocket::StartWriteNextMessage()
// Allocate buffer space
if ((size_t)(hdr.m_MsgLength+HEADER_LENGTH) > m_WrBufferSize)
{
m_WrBufferSize = BUFFER_SIZE(hdr.m_MsgLength+HEADER_LENGTH);
//m_WrBufferSize = BUFFER_SIZE(hdr.m_MsgLength+HEADER_LENGTH);
m_WrBufferSize = ALIGN_BLOCK(hdr.m_MsgLength+HEADER_LENGTH);
if (m_pWrBuffer)
m_pWrBuffer=(u8 *)realloc(m_pWrBuffer, m_WrBufferSize);
else
@ -188,7 +209,7 @@ void CMessageSocket::StartWriteNextMessage()
// Queue Error Message
m_InQ.Lock();
m_InQ.push_back(new CNetErrorMessage(res, GetState()));
m_InQ.push_back(new CErrorMessage(res, GetState()));
m_InQ.Unlock();
}
}
@ -227,7 +248,7 @@ void CMessageSocket::WriteComplete(PS_RESULT ec)
else
{
// Push an error message
m_InQ.push_back(new CNetErrorMessage(ec, GetState()));
m_InQ.push_back(new CErrorMessage(ec, GetState()));
}
}
@ -235,13 +256,15 @@ void CMessageSocket::StartReadHeader()
{
if (m_RdBufferSize < HEADER_LENGTH)
{
m_RdBufferSize=BUFFER_SIZE(HEADER_LENGTH);
//m_RdBufferSize=BUFFER_SIZE(HEADER_LENGTH);
m_RdBufferSize=ALIGN_BLOCK(HEADER_LENGTH);
if (m_pRdBuffer)
m_pRdBuffer=(u8 *)realloc(m_pRdBuffer, m_RdBufferSize);
else
m_pRdBuffer=(u8 *)malloc(m_RdBufferSize);
}
m_ReadingData=false;
printf("CMessageSocket::StartReadHeader(): Trying to read %u\n", HEADER_LENGTH);
PS_RESULT res=Read(m_pRdBuffer, HEADER_LENGTH);
if (res != PS_OK)
{
@ -249,7 +272,7 @@ void CMessageSocket::StartReadHeader()
// Push an error message
CScopeLock scopeLock(m_InQ.m_Mutex);
m_InQ.push_back(new CNetErrorMessage(res, GetState()));
m_InQ.push_back(new CErrorMessage(res, GetState()));
}
}
@ -261,7 +284,8 @@ void CMessageSocket::StartReadMessage()
size_t reqBufSize=HEADER_LENGTH+hdr.m_MsgLength;
if (m_RdBufferSize < reqBufSize)
{
m_RdBufferSize=BUFFER_SIZE(reqBufSize);
//m_RdBufferSize=BUFFER_SIZE(reqBufSize);
m_RdBufferSize=ALIGN_BLOCK(reqBufSize);
if (m_pRdBuffer)
m_pRdBuffer=(u8 *)realloc(m_pRdBuffer, m_RdBufferSize);
else
@ -282,7 +306,7 @@ void CMessageSocket::StartReadMessage()
// Queue an error message
CScopeLock scopeLock(m_InQ);
m_InQ.push_back(new CNetErrorMessage(res, GetState()));
m_InQ.push_back(new CErrorMessage(res, GetState()));
}
}
}
@ -302,7 +326,8 @@ void CMessageSocket::ReadComplete(PS_RESULT ec)
{
SNetHeader hdr;
hdr.Deserialize(m_pRdBuffer);
CNetMessage *pMsg=CNetMessage::DeserializeMessage((ENetMessageType)hdr.m_MsgType, m_pRdBuffer+HEADER_LENGTH, hdr.m_MsgLength);
//CNetMessage *pMsg=CNetMessage::DeserializeMessage((ENetMessageType)hdr.m_MsgType, m_pRdBuffer+HEADER_LENGTH, hdr.m_MsgLength);
CNetMessage *pMsg = CNetMessageFactory::CreateMessage( m_pRdBuffer+HEADER_LENGTH, hdr.m_MsgLength);
if (pMsg)
{
OnMessage(pMsg);
@ -326,7 +351,7 @@ void CMessageSocket::OnMessage(CNetMessage *pMsg)
{
m_InQ.Lock();
m_InQ.push_back(pMsg);
NET_LOG2( "CMessageSocket::OnMessage(): %s", pMsg->GetString().c_str() );
NET_LOG2( "CMessageSocket::OnMessage(): %s", pMsg->ToString().c_str() );
NET_LOG2( "CMessageSocket::OnMessage(): Queue size now %u", m_InQ.size() );
m_InQ.Unlock();
}
@ -342,14 +367,14 @@ void CMessageSocket::ConnectComplete(PS_RESULT ec)
else
{
CScopeLock scopeLock(m_InQ);
m_InQ.push_back(new CNetErrorMessage(ec, GetState()));
m_InQ.push_back(new CErrorMessage(ec, GetState()));
}
}
void CMessageSocket::OnClose(PS_RESULT errorCode)
{
CScopeLock scopeLock(m_InQ.m_Mutex);
m_InQ.push_back(new CNetErrorMessage(errorCode, GetState()));
m_InQ.push_back(new CErrorMessage(errorCode, GetState()));
}
CMessageSocket::CMessageSocket(CSocketInternal *pInt):

View File

@ -56,6 +56,9 @@ MORE INFO
//-------------------------------------------------
// Typedefs and Macros
//-------------------------------------------------
#define BLOCK_SIZE 4096
#define ALIGN_UP( _n, _block ) ( _n + _block - (_n % _block ) )
#define ALIGN_BLOCK( _n ) ALIGN_UP( _n, BLOCK_SIZE )
#define LOG_CAT_NET "net"
@ -190,23 +193,23 @@ public:
virtual void OnAccept(const CSocketAddress &)=0;
};
class CNetErrorMessage: public CNetMessage
class CErrorMessage: public CNetMessage
{
public:
PS_RESULT m_Error;
ESocketState m_State;
inline CNetErrorMessage():
inline CErrorMessage():
CNetMessage(NMT_ERROR)
{}
inline CNetErrorMessage(PS_RESULT error, ESocketState state):
inline CErrorMessage(PS_RESULT error, ESocketState state):
CNetMessage(NMT_ERROR),
m_Error(error),
m_State(state)
{}
virtual CStr GetString() const;
virtual CStr ToString() const;
};
struct CCloseRequestMessage: public CNetMessage
@ -214,7 +217,7 @@ struct CCloseRequestMessage: public CNetMessage
inline CCloseRequestMessage(): CNetMessage(NMT_CLOSE_REQUEST)
{}
virtual CStr GetString() const;
virtual CStr ToString() const;
};
struct CConnectCompleteMessage: public CNetMessage
@ -222,7 +225,7 @@ struct CConnectCompleteMessage: public CNetMessage
inline CConnectCompleteMessage(): CNetMessage(NMT_CONNECT_COMPLETE)
{}
virtual CStr GetString() const;
virtual CStr ToString() const;
};
/**

View File

@ -15,8 +15,8 @@
#include "lib/res/graphics/unifont.h"
#include "lib/sysdep/clipboard.h"
#include "maths/MathUtil.h"
#include "network/Client.h"
#include "network/Server.h"
#include "network/NetClient.h"
#include "network/NetServer.h"
#include "ps/CLogger.h"
#include "ps/Filesystem.h"
#include "ps/Globals.h"
@ -753,21 +753,25 @@ void CConsole::SaveHistory()
g_VFS->CreateFile(m_sHistoryFile, buffer.Data(), buffer.Size());
}
void CConsole::SendChatMessage(const wchar_t *szMessage)
void CConsole::SendChatMessage(const wchar_t *pText)
{
if (g_NetClient || g_NetServer)
CNetHost *pHost = NULL;
if ( pHost )
{
CChatMessage *msg=new CChatMessage();
msg->m_Recipient = PS_CHAT_RCP_ALL;
msg->m_Message = szMessage;
if (g_NetClient)
g_NetClient->Push(msg);
else
CChatMessage chat;
chat.m_Recipient = CHAT_RECIPIENT_ALL;
chat.m_Message = pText;
if ( pHost->IsServer() )
{
msg->m_Sender=0;
ReceivedChatMessage(g_NetServer->GetServerPlayerName(), msg->m_Message.c_str());
g_NetServer->Broadcast(msg);
CNetServer* pServer = ( CNetServer* )pHost;
chat.m_Sender = 0;
ReceivedChatMessage( pServer->GetPlayerName(), chat.m_Message.c_str() );
}
pHost->Broadcast( &chat );
}
}

View File

@ -81,8 +81,10 @@ CLogger::~CLogger ()
time_t t = time(NULL);
struct tm* now = localtime(&t);
const char* months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
CStr currentDate = CStr(months[now->tm_mon]) + " " + CStr(now->tm_mday) + " " + CStr(1900+now->tm_year);
//const char* months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
//CStr currentDate = CStr(months[now->tm_mon]) + " " + CStr(now->tm_mday) + " " + CStr(1900+now->tm_year);
char currentDate[11];
sprintf(currentDate, "%02d %02d %04d", now->tm_mon, now->tm_mday, (1900+now->tm_year));
char currentTime[10];
sprintf(currentTime, "%02d:%02d:%02d", now->tm_hour, now->tm_min, now->tm_sec);

View File

@ -11,7 +11,7 @@
#include "graphics/GameView.h"
#include "graphics/UnitManager.h"
#include "lib/timer.h"
#include "network/Client.h"
#include "network/NetClient.h"
#include "ps/CConsole.h"
#include "ps/CLogger.h"
#include "ps/CStr.h"

View File

@ -5,7 +5,7 @@
#include "GameAttributes.h"
#include "Game.h"
#include "ConfigDB.h"
#include "network/ServerSession.h"
#include "network/NetSession.h"
#include "CLogger.h"
#include "ps/XML/Xeromyces.h"
#include "simulation/LOSManager.h"
@ -80,7 +80,7 @@ bool CPlayerSlot::JSI_AssignToSession(JSContext* UNUSED(cx), uintN argc, jsval*
{
if (argc != 1)
return false;
CNetServerSession *pSession=ToNative<CNetServerSession>(argv[0]);
CNetSession* pSession = ToNative<CNetSession>(argv[0]);
if (pSession)
{
AssignToSession(pSession);
@ -103,7 +103,7 @@ void CPlayerSlot::CallCallback()
}
void CPlayerSlot::SetAssignment(EPlayerSlotAssignment assignment,
CNetServerSession *pSession, int sessionID)
CNetSession *pSession, int sessionID)
{
m_Assignment=assignment;
m_pSession=pSession;
@ -122,7 +122,7 @@ void CPlayerSlot::AssignOpen()
SetAssignment(SLOT_OPEN, NULL, -1);
}
void CPlayerSlot::AssignToSession(CNetServerSession *pSession)
void CPlayerSlot::AssignToSession(CNetSession *pSession)
{
SetAssignment(SLOT_SESSION, pSession, pSession->GetID());
m_pPlayer->SetName(pSession->GetName());

View File

@ -6,7 +6,8 @@
#include "scripting/SynchedJSObject.h"
#include "simulation/LOSManager.h"
class CNetServerSession;
//class CNetServerSession;
class CNetSession;
class CGameAttributes;
class CPlayerSlot;
@ -25,7 +26,8 @@ class CPlayerSlot: public CJSObject<CPlayerSlot>
size_t m_SlotID;
EPlayerSlotAssignment m_Assignment;
CNetServerSession *m_pSession;
//CNetServerSession *m_pSession;
CNetSession *m_pSession;
int m_SessionID;
CPlayer *m_pPlayer;
@ -48,7 +50,8 @@ class CPlayerSlot: public CJSObject<CPlayerSlot>
jsval JSI_GetAssignment(JSContext* cx);
void CallCallback();
void SetAssignment(EPlayerSlotAssignment, CNetServerSession *pSession, int sessionID);
//void SetAssignment(EPlayerSlotAssignment, CNetServerSession *pSession, int sessionID);
void SetAssignment(EPlayerSlotAssignment, CNetSession *pSession, int sessionID);
protected:
friend class CGameAttributes;
@ -68,7 +71,9 @@ public:
// Only applicable on the server host, and may return NULL if the slot
// is not assigned to a server session.
inline CNetServerSession *GetSession()
//inline CNetServerSession *GetSession()
//{ return m_pSession; }
inline CNetSession *GetSession()
{ return m_pSession; }
@ -86,7 +91,8 @@ public:
void AssignClosed();
// [Server] Assign the slot to a connected session
void AssignToSession(CNetServerSession *pSession);
//void AssignToSession(CNetServerSession *pSession);
void AssignToSession(CNetSession *pSession);
// [Client] The slot has been assigned by the server to a session ID, mirror
// the assignment

View File

@ -43,43 +43,32 @@
#include "maths/MathUtil.h"
#include "simulation/scripting/SimulationScriptInit.h"
#include "simulation/Entity.h"
#include "simulation/FormationManager.h"
#include "simulation/TriggerManager.h"
#include "simulation/FormationCollection.h"
#include "simulation/TechnologyCollection.h"
#include "simulation/EntityManager.h"
#include "simulation/EntityTemplateCollection.h"
#include "simulation/Scheduler.h"
#include "simulation/EventHandlers.h"
#include "simulation/PathfindEngine.h"
#include "scripting/ScriptableComplex.inl"
#include "scripting/ScriptingHost.h"
#include "scripting/DOMEvent.h"
#include "scripting/GameEvents.h"
#include "scripting/ScriptableComplex.h"
#include "maths/scripting/JSInterface_Vector3D.h"
#include "graphics/scripting/JSInterface_Camera.h"
#include "graphics/scripting/JSInterface_LightEnv.h"
#include "ps/scripting/JSInterface_Selection.h"
#include "ps/scripting/JSInterface_Console.h"
#include "graphics/scripting/JSInterface_LightEnv.h"
#include "ps/scripting/JSCollection.h"
#include "scripting/DOMEvent.h"
#include "simulation/scripting/SimulationScriptInit.h"
#ifndef NO_GUI
# include "gui/scripting/JSInterface_IGUIObject.h"
# include "gui/scripting/JSInterface_GUITypes.h"
# include "gui/GUI.h"
#endif
#include "network/ServerSession.h"
#include "sound/CMusicPlayer.h"
#include "sound/JSI_Sound.h"
#include "network/Client.h"
#include "network/NetLog.h"
#include "network/Server.h"
#include "network/SessionManager.h"
#include "network/NetServer.h"
#include "network/NetClient.h"
#include "ps/GameSetup/Atlas.h"
#include "ps/GameSetup/GameSetup.h"
@ -496,7 +485,8 @@ static void RegisterJavascriptInterfaces()
CNetMessage::ScriptingInit();
CNetClient::ScriptingInit();
CNetServer::ScriptingInit();
CNetServerSession::ScriptingInit();
CNetSession::ScriptingInit();
CServerPlayer::ScriptingInit();
// simulation
SimulationScriptInit();
@ -522,33 +512,6 @@ static void InitScripting()
RegisterJavascriptInterfaces();
g_ScriptingHost.DefineConstant( "FORMATION_ENTER", CFormationEvent::FORMATION_ENTER );
g_ScriptingHost.DefineConstant( "FORMATION_LEAVE", CFormationEvent::FORMATION_LEAVE );
g_ScriptingHost.DefineConstant( "FORMATION_DAMAGE", CFormationEvent::FORMATION_DAMAGE );
g_ScriptingHost.DefineConstant( "FORMATION_ATTACK", CFormationEvent::FORMATION_ATTACK );
g_ScriptingHost.DefineConstant( "NOTIFY_NONE", CEntityListener::NOTIFY_NONE );
g_ScriptingHost.DefineConstant( "NOTIFY_GOTO", CEntityListener::NOTIFY_GOTO );
g_ScriptingHost.DefineConstant( "NOTIFY_RUN", CEntityListener::NOTIFY_RUN );
g_ScriptingHost.DefineConstant( "NOTIFY_FOLLOW", CEntityListener::NOTIFY_FOLLOW );
g_ScriptingHost.DefineConstant( "NOTIFY_ATTACK", CEntityListener::NOTIFY_ATTACK );
g_ScriptingHost.DefineConstant( "NOTIFY_DAMAGE", CEntityListener::NOTIFY_DAMAGE );
g_ScriptingHost.DefineConstant( "NOTIFY_COMBAT", CEntityListener::NOTIFY_COMBAT );
g_ScriptingHost.DefineConstant( "NOTIFY_ESCORT", CEntityListener::NOTIFY_ESCORT );
g_ScriptingHost.DefineConstant( "NOTIFY_HEAL", CEntityListener::NOTIFY_HEAL );
g_ScriptingHost.DefineConstant( "NOTIFY_GATHER", CEntityListener::NOTIFY_GATHER );
g_ScriptingHost.DefineConstant( "NOTIFY_IDLE", CEntityListener::NOTIFY_IDLE );
g_ScriptingHost.DefineConstant( "NOTIFY_ORDER_CHANGE", CEntityListener::NOTIFY_ORDER_CHANGE );
g_ScriptingHost.DefineConstant( "NOTIFY_ALL", CEntityListener::NOTIFY_ALL );
g_ScriptingHost.DefineConstant( "ORDER_NONE", -1 );
g_ScriptingHost.DefineConstant( "ORDER_GOTO", CEntityOrder::ORDER_GOTO );
g_ScriptingHost.DefineConstant( "ORDER_RUN", CEntityOrder::ORDER_RUN );
g_ScriptingHost.DefineConstant( "ORDER_PATROL", CEntityOrder::ORDER_PATROL );
g_ScriptingHost.DefineConstant( "ORDER_GENERIC", CEntityOrder::ORDER_GENERIC );
g_ScriptingHost.DefineConstant( "ORDER_PRODUCE", CEntityOrder::ORDER_PRODUCE );
g_ScriptingHost.DefineConstant( "ORDER_START_CONSTRUCTION", CEntityOrder::ORDER_START_CONSTRUCTION );
#define REG_JS_CONSTANT(_name) g_ScriptingHost.DefineConstant(#_name, _name)
REG_JS_CONSTANT(SDL_BUTTON_LEFT);
REG_JS_CONSTANT(SDL_BUTTON_MIDDLE);
@ -793,31 +756,15 @@ void Shutdown(int flags)
if (! (flags & INIT_NO_SIM))
{
TIMER_BEGIN("shutdown SessionManager");
delete &g_SessionManager;
TIMER_END("shutdown SessionManager");
TIMER_BEGIN("shutdown mouse stuff");
delete &g_Mouseover;
delete &g_Selection;
delete &g_BuildingPlacer;
TIMER_END("shutdown mouse stuff");
TIMER_BEGIN("shutdown Pathfinder");
delete &g_Pathfinder;
TIMER_END("shutdown Pathfinder");
// Managed by CWorld
// delete &g_EntityManager;
TIMER_BEGIN("shutdown game scripting stuff");
delete &g_GameAttributes;
delete &g_TriggerManager;
delete &g_FormationManager;
delete &g_TechnologyCollection;
delete &g_EntityFormationCollection;
delete &g_EntityTemplateCollection;
SimulationShutdown();
TIMER_END("shutdown game scripting stuff");
}
@ -1056,30 +1003,14 @@ void Init(const CmdLineArgs& args, int flags)
if (! (flags & INIT_NO_SIM))
{
{
TIMER("Init_entitiessection");
// This needs to be done after the renderer has loaded all its actors...
new CEntityTemplateCollection;
new CFormationCollection;
new CTechnologyCollection;
g_EntityFormationCollection.LoadTemplates();
g_TechnologyCollection.LoadTechnologies();
new CFormationManager;
new CTriggerManager;
g_TriggerManager.LoadXml(CStr("scripts/TriggerSpecs.xml"));
g_ScriptingHost.RunScript("scripts/trigger_functions.js");
// CEntityManager is managed by CWorld
//new CEntityManager;
new CSelectedEntities;
new CMouseoverEntities;
}
SimulationInit();
{
TIMER("Init_miscgamesection");
new CPathfindEngine;
new CSelectedEntities;
new CMouseoverEntities;
new CBuildingPlacer;
new CSessionManager;
new CGameAttributes;
}

View File

@ -568,7 +568,7 @@ void CSelectedEntities::Update()
}
// Don't count GOTO as a majority action unless everything else has 0 votes.
defaultPoll[NMT_Goto - NMT_COMMAND_FIRST] = 0;
defaultPoll[NMT_GOTO - NMT_COMMAND_FIRST] = 0;
vote = -1;
secvote = -1;
@ -1412,7 +1412,7 @@ void CBuildingPlacer::MouseReleased()
if( m_valid )
{
// issue a place object command accross the network
CPlaceObject *msg = new CPlaceObject();
CPlaceObjectMessage *msg = new CPlaceObjectMessage();
msg->m_IsQueued = hotkeys[HOTKEY_ORDER_QUEUE];
msg->m_Entities = g_Selection.m_selected;
msg->m_Template = m_templateName;

View File

@ -21,8 +21,8 @@
#include "lib/timer.h"
#include "lib/frequency_filter.h"
#include "maths/scripting/JSInterface_Vector3D.h"
#include "network/Client.h"
#include "network/Server.h"
#include "network/NetClient.h"
#include "network/NetServer.h"
#include "ps/CConsole.h"
#include "ps/CLogger.h"
#include "ps/CStr.h"
@ -196,23 +196,23 @@ void CreateFormationMessage( std::vector<CNetMessage*>& msgList, CNetMessage* ms
CNetMessage* retMsg;
const int type = msg->GetType();
if ( type == NMT_Goto )
if ( type == NMT_GOTO )
{
//formationEnt->GetFormation()->BaseToMovement();
CGoto* tmp = static_cast<CGoto*>(msg);
retMsg = CNetMessage::CreatePositionMessage( formation, NMT_FormationGoto,
CGotoMessage* tmp = static_cast<CGotoMessage*>(msg);
retMsg = CNetMessage::CreatePositionMessage( formation, NMT_FORMATION_GOTO,
CVector2D(tmp->m_TargetX, tmp->m_TargetY) );
}
else if( type == NMT_Run )
else if( type == NMT_RUN )
{
CGoto* tmp = static_cast<CGoto*>(msg);
retMsg = CNetMessage::CreatePositionMessage( formation, NMT_FormationGoto,
CGotoMessage* tmp = static_cast<CGotoMessage*>(msg);
retMsg = CNetMessage::CreatePositionMessage( formation, NMT_FORMATION_GOTO,
CVector2D(tmp->m_TargetX, tmp->m_TargetY) );
}
else if ( type == NMT_Generic )
else if ( type == NMT_GENERIC )
{
CGeneric* tmp = static_cast<CGeneric*>(msg);
retMsg = CNetMessage::CreateEntityIntMessage(formation, NMT_FormationGeneric,
CGenericMessage* tmp = static_cast<CGenericMessage*>(msg);
retMsg = CNetMessage::CreateEntityIntMessage(formation, NMT_FORMATION_GENERIC,
tmp->m_Target, tmp->m_Action);
}
else
@ -285,8 +285,8 @@ JSBool IssueCommand( JSContext* cx, JSObject*, uintN argc, jsval* argv, jsval* r
for ( std::vector<CNetMessage*>::iterator it=messages.begin(); it != messages.end(); it++ )
{
g_Console->InsertMessage(L"IssueCommand: %hs", (*it)->GetString().c_str());
*rval = g_ScriptingHost.UCStringToValue((*it)->GetString());
g_Console->InsertMessage(L"IssueCommand: %hs", (*it)->ToString().c_str());
*rval = g_ScriptingHost.UCStringToValue((*it)->ToString());
g_Game->GetSimulation()->QueueLocalCommand(*it);
}

View File

@ -169,7 +169,7 @@ void CEntityFormation::UpdateFormation()
}
}
CEntityList entities = GetEntityList();
CNetMessage* msg = CNetMessage::CreatePositionMessage( entities, NMT_FormationGoto, m_position );
CNetMessage* msg = CNetMessage::CreatePositionMessage( entities, NMT_FORMATION_GOTO, m_position );
g_Game->GetSimulation()->QueueLocalCommand(msg);
}

View File

@ -17,6 +17,7 @@
#include "LOSManager.h"
#include "graphics/Terrain.h"
#include "Stance.h"
#include "sound/SoundGroupMgr.h"
#include "ps/Game.h"
#include "ps/World.h"
@ -437,8 +438,8 @@ bool CEntity::ProcessContactActionNoPathing( CEntityOrder* current, int timestep
if( ( m_fsm_cyclepos <= action->m_Speed ) && ( nextpos > action->m_Speed ) )
{
// TODO: Play a sound here. Use m_base->m_SoundGroupTable[animation] to get the
// name of the soundgroup XML file to play.
const size_t soundGroupIndex = m_base->m_SoundGroupTable[animation];
g_soundGroupMgr->PlayNext(soundGroupIndex);
if(!DispatchEvent( contactEvent ))
{

View File

@ -7,6 +7,7 @@
#include "ps/Player.h"
#include "scripting/ScriptableComplex.inl"
#include "ps/XML/Xeromyces.h"
#include "sound/SoundGroupMgr.h"
#include "ps/CLogger.h"
#define LOG_CATEGORY "entity"
@ -319,8 +320,9 @@ bool CEntityTemplate::LoadXml( const CStr& filename )
{
XMBElement child = children.Item(j);
CStr8 name = toCamelCase( XeroFile.GetElementString( child.GetNodeName() ) );
CStr8 value = child.GetText();
m_SoundGroupTable[name] = value;
CStr8 soundGroupFilename = child.GetText();
const size_t soundGroupIndex = g_soundGroupMgr->AddGroup(soundGroupFilename);
m_SoundGroupTable[name] = soundGroupIndex;
}
}
else

View File

@ -61,7 +61,8 @@ public:
CBoundingObject::EBoundingType m_bound_type;
// Sound properties
typedef STL_HASH_MAP<CStr, CStr, CStr_hash_compare> SoundGroupTable;
// map animation name to soundGroup index returned by SoundGroupMgr
typedef STL_HASH_MAP<CStr, size_t, CStr_hash_compare> SoundGroupTable;
SoundGroupTable m_SoundGroupTable;
//SP properties

View File

@ -97,7 +97,7 @@ bool CSimulation::Update(double frameTime)
// cutting down on Interpolate and rendering, and call us a few times
// with frameTime == 0 to give us a chance to catch up.
ok = false;
LOG(CLogger::Warning, "simulation", "Missing a simulation turn due to low FPS");
debug_printf("WARNING: missing a simulation turn due to low FPS\n");
}
}
else
@ -151,14 +151,13 @@ void CSimulation::Simulate()
int time = m_pTurnManager->GetTurnLength();
m_Time += time / 1000.0f;
#ifdef DEBUG_SYNCHRONIZATION
#if defined(DEBUG_SYNCHRONIZATION)
debug_printf("Simulation turn: %.3lf\n", m_Time);
#endif
PROFILE_START( "scheduler tick" );
g_Scheduler.Update(time);
PROFILE_END( "scheduler tick" );
PROFILE_START( "entity updates" );
g_EntityManager.UpdateAll(time);
PROFILE_END( "entity updates" );
@ -180,7 +179,7 @@ void CSimulation::Simulate()
m_pTurnManager->IterateBatch(0, TranslateMessage, this);
PROFILE_END( "turn manager update" );
#ifdef DEBUG_SYNCHRONIZATION
#if defined(DEBUG_SYNCHRONIZATION)
debug_printf("End turn\n", m_Time);
#endif
}
@ -319,9 +318,9 @@ size_t CSimulation::TranslateMessage(CNetMessage* pMsg, size_t clientMask, void*
switch (pMsg->GetType())
{
case NMT_AddWaypoint:
case NMT_ADD_WAYPOINT:
{
CAddWaypoint *msg=(CAddWaypoint *)pMsg;
CAddWaypointMessage *msg=(CAddWaypointMessage *)pMsg;
isQueued = msg->m_IsQueued != 0;
order.m_type=CEntityOrder::ORDER_LAST;
order.m_target_location.x=(float)msg->m_TargetX;
@ -353,35 +352,35 @@ size_t CSimulation::TranslateMessage(CNetMessage* pMsg, size_t clientMask, void*
}
break;
}
case NMT_Goto:
ENTITY_POSITION(CGoto, ORDER_GOTO);
case NMT_GOTO:
ENTITY_POSITION(CGotoMessage, ORDER_GOTO);
break;
case NMT_Run:
ENTITY_POSITION(CRun, ORDER_RUN);
case NMT_RUN:
ENTITY_POSITION(CRunMessage, ORDER_RUN);
break;
case NMT_Patrol:
ENTITY_POSITION(CPatrol, ORDER_PATROL);
case NMT_PATROL:
ENTITY_POSITION(CPatrolMessage, ORDER_PATROL);
break;
case NMT_FormationGoto:
ENTITY_POSITION_FORM(CFormationGoto, ORDER_GOTO);
case NMT_FORMATION_GOTO:
ENTITY_POSITION_FORM(CFormationGotoMessage, ORDER_GOTO);
break;
//TODO: make formation move to within range of target and then attack normally
case NMT_Generic:
ENTITY_ENTITY_INT(CGeneric, ORDER_GENERIC);
case NMT_GENERIC:
ENTITY_ENTITY_INT(CGenericMessage, ORDER_GENERIC);
break;
case NMT_FormationGeneric:
ENTITY_ENTITY_INT(CFormationGeneric, ORDER_GENERIC);
case NMT_FORMATION_GENERIC:
ENTITY_ENTITY_INT(CFormationGenericMessage, ORDER_GENERIC);
break;
case NMT_NotifyRequest:
ENTITY_ENTITY_INT(CNotifyRequest, ORDER_NOTIFY_REQUEST);
case NMT_NOTIFY_REQUEST:
ENTITY_ENTITY_INT(CNotifyRequestMessage, ORDER_NOTIFY_REQUEST);
break;
case NMT_Produce:
ENTITY_INT_STRING(CProduce, ORDER_PRODUCE);
case NMT_PRODUCE:
ENTITY_INT_STRING(CProduceMessage, ORDER_PRODUCE);
break;
case NMT_PlaceObject:
case NMT_PLACE_OBJECT:
{
CPlaceObject *msg = (CPlaceObject *) pMsg;
CPlaceObjectMessage *msg = (CPlaceObjectMessage *) pMsg;
isQueued = msg->m_IsQueued != 0;
// Figure out the player

View File

@ -70,7 +70,7 @@ void CTurnManager::SendBatch(uintptr_t batch)
SendMessage(it->m_pMessage, it->m_ClientMask);
++it;
}
CEndCommandBatch *pMsg=new CEndCommandBatch();
CEndCommandBatchMessage *pMsg=new CEndCommandBatchMessage();
pMsg->m_TurnLength=m_Batches[batch].m_TurnLength;
SendMessage(pMsg, (size_t)-1);
}
@ -82,7 +82,7 @@ void CTurnManager::SendMessage(CNetMessage *pMsg, size_t clientMask)
if (clientMask & (1<<i))
{
if (m_Clients[i].m_Pipe)
m_Clients[i].m_Pipe->Push(pMsg->Copy());
m_Clients[i].m_Pipe->Push(pMsg->Clone());
}
}
}
@ -116,7 +116,7 @@ void CTurnManager::Initialize(size_t numClients)
void CTurnManager::RecordBatch(uintptr_t batch)
{
IterateBatch(batch, RecordIterator, m_pRecord);
CEndCommandBatch msg;
CEndCommandBatchMessage msg;
m_pRecord->WriteMessage(&msg);
}

View File

@ -1,10 +1,12 @@
#include "precompiled.h"
#include "lib/timer.h"
#include "simulation/Scheduler.h"
#include "simulation/EntityTemplate.h"
#include "simulation/Entity.h"
#include "simulation/Projectile.h"
#include "simulation/TriggerManager.h"
#include "simulation/FormationManager.h"
#include "simulation/ProductionQueue.h"
#include "simulation/Technology.h"
@ -20,4 +22,68 @@ void SimulationScriptInit()
CTechnology::ScriptingInit();
EntityCollection::Init( "EntityCollection" );
g_ScriptingHost.DefineConstant( "FORMATION_ENTER", CFormationEvent::FORMATION_ENTER );
g_ScriptingHost.DefineConstant( "FORMATION_LEAVE", CFormationEvent::FORMATION_LEAVE );
g_ScriptingHost.DefineConstant( "FORMATION_DAMAGE", CFormationEvent::FORMATION_DAMAGE );
g_ScriptingHost.DefineConstant( "FORMATION_ATTACK", CFormationEvent::FORMATION_ATTACK );
g_ScriptingHost.DefineConstant( "NOTIFY_NONE", CEntityListener::NOTIFY_NONE );
g_ScriptingHost.DefineConstant( "NOTIFY_GOTO", CEntityListener::NOTIFY_GOTO );
g_ScriptingHost.DefineConstant( "NOTIFY_RUN", CEntityListener::NOTIFY_RUN );
g_ScriptingHost.DefineConstant( "NOTIFY_FOLLOW", CEntityListener::NOTIFY_FOLLOW );
g_ScriptingHost.DefineConstant( "NOTIFY_ATTACK", CEntityListener::NOTIFY_ATTACK );
g_ScriptingHost.DefineConstant( "NOTIFY_DAMAGE", CEntityListener::NOTIFY_DAMAGE );
g_ScriptingHost.DefineConstant( "NOTIFY_COMBAT", CEntityListener::NOTIFY_COMBAT );
g_ScriptingHost.DefineConstant( "NOTIFY_ESCORT", CEntityListener::NOTIFY_ESCORT );
g_ScriptingHost.DefineConstant( "NOTIFY_HEAL", CEntityListener::NOTIFY_HEAL );
g_ScriptingHost.DefineConstant( "NOTIFY_GATHER", CEntityListener::NOTIFY_GATHER );
g_ScriptingHost.DefineConstant( "NOTIFY_IDLE", CEntityListener::NOTIFY_IDLE );
g_ScriptingHost.DefineConstant( "NOTIFY_ORDER_CHANGE", CEntityListener::NOTIFY_ORDER_CHANGE );
g_ScriptingHost.DefineConstant( "NOTIFY_ALL", CEntityListener::NOTIFY_ALL );
g_ScriptingHost.DefineConstant( "ORDER_NONE", -1 );
g_ScriptingHost.DefineConstant( "ORDER_GOTO", CEntityOrder::ORDER_GOTO );
g_ScriptingHost.DefineConstant( "ORDER_RUN", CEntityOrder::ORDER_RUN );
g_ScriptingHost.DefineConstant( "ORDER_PATROL", CEntityOrder::ORDER_PATROL );
g_ScriptingHost.DefineConstant( "ORDER_GENERIC", CEntityOrder::ORDER_GENERIC );
g_ScriptingHost.DefineConstant( "ORDER_PRODUCE", CEntityOrder::ORDER_PRODUCE );
g_ScriptingHost.DefineConstant( "ORDER_START_CONSTRUCTION", CEntityOrder::ORDER_START_CONSTRUCTION );
}
void SimulationInit()
{
TIMER("SimulationInit");
new CEntityTemplateCollection;
new CFormationCollection;
new CTechnologyCollection;
g_EntityFormationCollection.LoadTemplates();
g_TechnologyCollection.LoadTechnologies();
new CFormationManager;
new CTriggerManager;
g_TriggerManager.LoadXml(CStr("scripts/TriggerSpecs.xml"));
g_ScriptingHost.RunScript("scripts/trigger_functions.js");
// CEntityManager is managed by CWorld
//new CEntityManager;
new CPathfindEngine;
}
void SimulationShutdown()
{
TIMER_BEGIN("shutdown Pathfinder");
delete &g_Pathfinder;
TIMER_END("shutdown Pathfinder");
// Managed by CWorld
// delete &g_EntityManager;
delete &g_TriggerManager;
delete &g_FormationManager;
delete &g_TechnologyCollection;
delete &g_EntityFormationCollection;
delete &g_EntityTemplateCollection;
}

View File

@ -1 +1,4 @@
extern void SimulationScriptInit();
extern void SimulationInit();
extern void SimulationShutdown();

View File

@ -71,6 +71,10 @@ void CSoundGroup::PlayNext()
}
else
{
// if no sounds, return
if (filenames.size() == 0)
return;
// try loading on the fly only when we need the sound to see if that fixes release problems...
if(TestFlag(eRandOrder))
m_index = (size_t)rand(0, (size_t)filenames.size());

View File

@ -64,3 +64,5 @@ private:
CSoundGroupMgr &operator=(const CSoundGroupMgr &ref);
};
#define g_soundGroupMgr CSoundGroupMgr::GetInstance()