Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kind Alien Swarm #294

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
87 changes: 59 additions & 28 deletions engine/GameEventManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ static ConVar net_showevents( "net_showevents", "0", FCVAR_CHEAT, "Dump game eve

EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CGameEventManager, IGameEventManager2, INTERFACEVERSION_GAMEEVENTSMANAGER2, s_GameEventManager );

CGameEvent::CGameEvent( CGameEventDescriptor *descriptor )
CGameEvent::CGameEvent( CGameEventDescriptor *descriptor, const char *name )
{
Assert( descriptor );
m_pDescriptor = descriptor;
m_pDataKeys = new KeyValues( descriptor->name );
m_pDataKeys = new KeyValues( name );
}

CGameEvent::~CGameEvent()
Expand All @@ -63,6 +63,11 @@ int CGameEvent::GetInt( const char *keyName, int defaultValue)
return m_pDataKeys->GetInt( keyName, defaultValue );
}

uint64 CGameEvent::GetUint64( const char *keyName, uint64 defaultValue)
{
return m_pDataKeys->GetUint64( keyName, defaultValue );
}

float CGameEvent::GetFloat( const char *keyName, float defaultValue )
{
return m_pDataKeys->GetFloat( keyName, defaultValue );
Expand All @@ -83,6 +88,11 @@ void CGameEvent::SetInt( const char *keyName, int value )
m_pDataKeys->SetInt( keyName, value );
}

void CGameEvent::SetUint64( const char *keyName, uint64 value )
{
m_pDataKeys->SetUint64( keyName, value );
}

void CGameEvent::SetFloat( const char *keyName, float value )
{
m_pDataKeys->SetFloat( keyName, value );
Expand Down Expand Up @@ -158,8 +168,8 @@ void CGameEventManager::Reset()
m_Listeners.PurgeAndDeleteElements();
m_EventFiles.RemoveAll();
m_EventFileNames.RemoveAll();
m_EventMap.Purge();
m_bClientListenersChanged = true;

Assert( m_GameEvents.Count() == 0 );
}

Expand Down Expand Up @@ -189,10 +199,12 @@ void CGameEventManager::WriteEventList(SVC_GameEventList *msg)

Assert( descriptor.eventid >= 0 && descriptor.eventid < MAX_EVENT_NUMBER );

const char *pName = m_EventMap.GetElementName( descriptor.elementIndex );

msg->m_DataOut.WriteUBitLong( descriptor.eventid, MAX_EVENT_BITS );
msg->m_DataOut.WriteString( descriptor.name );
KeyValues *key = descriptor.keys->GetFirstSubKey();
msg->m_DataOut.WriteString( pName );

KeyValues *key = descriptor.keys->GetFirstSubKey();

while ( key )
{
Expand All @@ -208,7 +220,6 @@ void CGameEventManager::WriteEventList(SVC_GameEventList *msg)
}

msg->m_DataOut.WriteUBitLong( TYPE_LOCAL, 3 ); // end marker

msg->m_nNumEvents++;
}
}
Expand Down Expand Up @@ -296,25 +307,26 @@ void CGameEventManager::WriteListenEventList(CLC_ListenEvents *msg)

if ( descriptor.eventid == -1 )
{
DevMsg("Warning! Client listens to event '%s' unknown by server.\n", descriptor.name );
const char *pName = m_EventMap.GetElementName(descriptor.elementIndex);
DevMsg("Warning! Client listens to event '%s' unknown by server.\n", pName );
continue;
}

msg->m_EventArray.Set( descriptor.eventid );
}
}

IGameEvent *CGameEventManager::CreateEvent( CGameEventDescriptor *descriptor )
IGameEvent *CGameEventManager::CreateEvent( CGameEventDescriptor *descriptor, const char *name )
{
return new CGameEvent ( descriptor );
return new CGameEvent ( descriptor, name );
}

IGameEvent *CGameEventManager::CreateEvent( const char *name, bool bForce )
IGameEvent *CGameEventManager::CreateEvent( const char *name, bool bForce, int *pCookie )
{
if ( !name || !name[0] )
return NULL;

CGameEventDescriptor *descriptor = GetEventDescriptor( name );
CGameEventDescriptor *descriptor = GetEventDescriptor( name, pCookie );

// check if this event name is known
if ( !descriptor )
Expand All @@ -330,7 +342,7 @@ IGameEvent *CGameEventManager::CreateEvent( const char *name, bool bForce )
}

// create & return the new event
return new CGameEvent ( descriptor );
return new CGameEvent ( descriptor, name );
}

bool CGameEventManager::FireEvent( IGameEvent *event, bool bServerOnly )
Expand All @@ -351,7 +363,8 @@ IGameEvent *CGameEventManager::DuplicateEvent( IGameEvent *event )
return NULL;

// create new instance
CGameEvent *newEvent = new CGameEvent ( gameEvent->m_pDescriptor );
const char *pName = m_EventMap.GetElementName(gameEvent->m_pDescriptor->elementIndex );
CGameEvent *newEvent = new CGameEvent ( gameEvent->m_pDescriptor, pName );

// free keys
newEvent->m_pDataKeys->deleteThis();
Expand Down Expand Up @@ -414,12 +427,16 @@ bool CGameEventManager::FireEventIntern( IGameEvent *event, bool bServerOnly, bo
{
if ( bClientOnly )
{
ConMsg( "Game event \"%s\", Tick %i:\n", descriptor->name, cl.GetClientTickCount() );
#ifndef DEDICATED
const char *pName = m_EventMap.GetElementName(descriptor->elementIndex);
ConMsg( "Game event \"%s\", Tick %i:\n", pName, cl.GetClientTickCount() );
ConPrintEvent( event );
#endif
}
else if ( net_showevents.GetInt() > 1 )
{
ConMsg( "Server event \"%s\", Tick %i:\n", descriptor->name, sv.GetTick() );
const char *pName = m_EventMap.GetElementName(descriptor->elementIndex);
ConMsg( "Server event \"%s\", Tick %i:\n", pName, sv.GetTick() );
ConPrintEvent( event );
}
}
Expand Down Expand Up @@ -491,7 +508,8 @@ bool CGameEventManager::SerializeEvent( IGameEvent *event, bf_write* buf )

if ( net_showevents.GetInt() > 2 )
{
DevMsg("Serializing event '%s' (%i):\n", descriptor->name, descriptor->eventid );
const char *pName = m_EventMap.GetElementName(descriptor->elementIndex);
DevMsg("Serializing event '%s' (%i):\n", pName, descriptor->eventid );
}

while ( key )
Expand Down Expand Up @@ -545,11 +563,12 @@ IGameEvent *CGameEventManager::UnserializeEvent( bf_read *buf)
}

// create new event
IGameEvent *event = CreateEvent( descriptor );
const char *pName = m_EventMap.GetElementName(descriptor->elementIndex);
IGameEvent *event = CreateEvent( descriptor, pName );

if ( !event )
{
DevMsg( "CGameEventManager::UnserializeEvent:: failed to create event %s.\n", descriptor->name );
DevMsg( "CGameEventManager::UnserializeEvent:: failed to create event %i.\n", descriptor->eventid );
return NULL;
}

Expand Down Expand Up @@ -766,9 +785,7 @@ bool CGameEventManager::RegisterEvent( KeyValues * event)
int index = m_GameEvents.AddToTail();
descriptor = &m_GameEvents.Element(index);

AssertMsg2( V_strlen( event->GetName() ) <= MAX_EVENT_NAME_LENGTH, "Event named '%s' exceeds maximum name length %d", event->GetName(), MAX_EVENT_NAME_LENGTH );

Q_strncpy( descriptor->name, event->GetName(), MAX_EVENT_NAME_LENGTH );
descriptor->elementIndex = m_EventMap.Insert( event->GetName(), index );
}
else
{
Expand Down Expand Up @@ -859,20 +876,34 @@ void CGameEventManager::FreeEvent( IGameEvent *event )
delete event;
}

CGameEventDescriptor *CGameEventManager::GetEventDescriptor(const char * name)
CGameEventDescriptor *CGameEventManager::GetEventDescriptor(const char * name, int *pCookie)
{
const uint32 cookieBit = 0x80000000;
const uint32 cookieMask = ~cookieBit;

if ( !name || !name[0] )
return NULL;

for (int i=0; i < m_GameEvents.Count(); i++ )
if ( pCookie && *pCookie )
{
CGameEventDescriptor *descriptor = &m_GameEvents[i];
int gameEventIndex = uint32(*pCookie) & cookieMask;
CGameEventDescriptor *pDescriptor = &m_GameEvents[gameEventIndex];
if ( !V_stricmp( m_EventMap.GetElementName(pDescriptor->elementIndex), name ) )
{
return pDescriptor;
}
}
int eventMapIndex = m_EventMap.Find( name );
if ( eventMapIndex == m_EventMap.InvalidIndex() )
return NULL;

if ( Q_strcmp( descriptor->name, name ) == 0 )
return descriptor;
int gameEventIndex = m_EventMap[eventMapIndex];
if ( pCookie )
{
*pCookie = cookieBit | gameEventIndex;
}

return NULL;
return &m_GameEvents[gameEventIndex];
}

bool CGameEventManager::AddListenerAll( void *listener, int nListenerType )
Expand Down
21 changes: 13 additions & 8 deletions engine/GameEventManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#pragma once
#endif

#include "utldict.h"
#include <igameevents.h>
#include <utlvector.h>
#include <KeyValues.h>
Expand All @@ -34,16 +35,16 @@ class CGameEventDescriptor
public:
CGameEventDescriptor()
{
name[0] = 0;
eventid = -1;
keys = NULL;
local = false;
reliable = true;
elementIndex = -1;
}

public:
char name[MAX_EVENT_NAME_LENGTH]; // name of this event
int eventid; // network index number, -1 = not networked
int eventid; // network index number, -1 = not networked
int elementIndex;
KeyValues *keys; // KeyValue describing data types, if NULL only name
bool local; // local event, never tell clients about that
bool reliable; // send this event as reliable message
Expand All @@ -54,7 +55,7 @@ class CGameEvent : public IGameEvent
{
public:

CGameEvent( CGameEventDescriptor *descriptor );
CGameEvent( CGameEventDescriptor *descriptor, const char *name );
virtual ~CGameEvent();

const char *GetName() const;
Expand All @@ -64,11 +65,13 @@ class CGameEvent : public IGameEvent

bool GetBool( const char *keyName = NULL, bool defaultValue = false );
int GetInt( const char *keyName = NULL, int defaultValue = 0 );
uint64 GetUint64( const char *keyName = NULL, uint64 defaultValue = 0 );
float GetFloat( const char *keyName = NULL, float defaultValue = 0.0f );
const char *GetString( const char *keyName = NULL, const char *defaultValue = "" );

void SetBool( const char *keyName, bool value );
void SetInt( const char *keyName, int value );
void SetUint64( const char *keyName, uint64 value );
void SetFloat( const char *keyName, float value );
void SetString( const char *keyName, const char *value );

Expand Down Expand Up @@ -111,8 +114,9 @@ class CGameEventManager : public IGameEventManager2
bool AddListener( IGameEventListener2 *listener, const char *name, bool bServerSide );
bool FindListener( IGameEventListener2 *listener, const char *name );
void RemoveListener( IGameEventListener2 *listener);

IGameEvent *CreateEvent( const char *name, bool bForce = false );

IGameEvent *CreateEvent( const char *name, bool bForce = false, int *pCookie = NULL );

IGameEvent *DuplicateEvent( IGameEvent *event);
bool FireEvent( IGameEvent *event, bool bDontBroadcast = false );
bool FireEventClientSide( IGameEvent *event );
Expand All @@ -127,7 +131,7 @@ class CGameEventManager : public IGameEventManager2
void ReloadEventDefinitions(); // called by server on new map
bool AddListener( void *listener, CGameEventDescriptor *descriptor, int nListenerType );

CGameEventDescriptor *GetEventDescriptor( const char *name );
CGameEventDescriptor *GetEventDescriptor( const char *name, int *pCookie = NULL );
CGameEventDescriptor *GetEventDescriptor( IGameEvent *event );
CGameEventDescriptor *GetEventDescriptor( int eventid );

Expand All @@ -145,13 +149,14 @@ class CGameEventManager : public IGameEventManager2

protected:

IGameEvent *CreateEvent( CGameEventDescriptor *descriptor );
IGameEvent *CreateEvent( CGameEventDescriptor *descriptor, const char *name );
bool RegisterEvent( KeyValues * keys );
void UnregisterEvent(int index);
bool FireEventIntern( IGameEvent *event, bool bServerSide, bool bClientOnly );
CGameEventCallback* FindEventListener( void* listener );

CUtlVector<CGameEventDescriptor> m_GameEvents; // list of all known events
CUtlDict<int, int> m_EventMap;
CUtlVector<CGameEventCallback*> m_Listeners; // list of all registered listeners
CUtlSymbolTable m_EventFiles; // list of all loaded event files
CUtlVector<CUtlSymbol> m_EventFileNames;
Expand Down
8 changes: 8 additions & 0 deletions engine/baseclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,13 @@ CBaseClient::CBaseClient()
m_bReportFakeClient = true;
m_iTracing = 0;
m_bPlayerNameLocked = false;

m_nDebugID = EVENT_DEBUG_ID_INIT;
}

CBaseClient::~CBaseClient()
{
m_nDebugID = EVENT_DEBUG_ID_SHUTDOWN;
}


Expand Down Expand Up @@ -670,6 +673,11 @@ void CBaseClient::FireGameEvent( IGameEvent *event )
}
}

int CBaseClient::GetEventDebugID( void )
{
return m_nDebugID;
}

bool CBaseClient::SendServerInfo( void )
{
COM_TimestampedLog( " CBaseClient::SendServerInfo" );
Expand Down
2 changes: 2 additions & 0 deletions engine/baseclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ class CBaseClient : public IGameEventListener2, public IClient, public IClientMe

public: // IGameEventListener
virtual void FireGameEvent( IGameEvent *event );
int m_nDebugID;
virtual int GetEventDebugID( void );

public:

Expand Down
9 changes: 9 additions & 0 deletions engine/cdll_engine_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,8 @@ class CEngineClient : public IVEngineClient
virtual bool REMOVED_SteamRefreshLogin( const char *password, bool isSecure ) { return false; }
virtual bool REMOVED_SteamProcessCall( bool & finished ) { return false; }

virtual ISPSharedMemory *GetSinglePlayerSharedMemorySpace( const char *handle, int ent_num = MAX_EDICTS );

virtual void SetGamestatsData( CGamestatsData *pGamestatsData );
virtual CGamestatsData *GetGamestatsData();

Expand Down Expand Up @@ -1568,6 +1570,13 @@ void CEngineClient::OnStorageDeviceDetached( void )
g_pXboxSystem->CloseContainers();
}


ISPSharedMemory *CEngineClient::GetSinglePlayerSharedMemorySpace( const char *szName, int ent_num )
{
// TODO(nillerusr): it this necessary? Implement later if so
return NULL; //g_pSinglePlayerSharedMemoryManager->GetSharedMemory( szName, ent_num );
}

void CEngineClient::ResetDemoInterpolation( void )
{
if( demorecorder->IsRecording() )
Expand Down
Loading
Loading