mirror of
https://github.com/1dot13/source.git
synced 2026-09-09 14:46:05 +02:00
Use std::queue and std::vector in event system
instead of old custom code from container.cpp * Removed initialize and shutdown event manager calls from Init.cpp as they were only used to create and destroy the old HLIST globals * Moved code from Event Manager.cpp to Event Pump.cpp as the event queue system is only used in said file. * Removed now useless event manager.cpp and .h files
This commit is contained in:
@@ -1514,12 +1514,6 @@ UINT32 InitializeJA2(void)
|
|||||||
// INit intensity tables
|
// INit intensity tables
|
||||||
BuildIntensityTable( );
|
BuildIntensityTable( );
|
||||||
|
|
||||||
// Init Event Manager
|
|
||||||
if ( !InitializeEventManager( ) )
|
|
||||||
{
|
|
||||||
return( ERROR_SCREEN );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initailize World
|
// Initailize World
|
||||||
if ( !InitializeWorld( ) )
|
if ( !InitializeWorld( ) )
|
||||||
{
|
{
|
||||||
@@ -1698,8 +1692,6 @@ void ShutdownJA2(void)
|
|||||||
|
|
||||||
ShutdownJA2Sound( );
|
ShutdownJA2Sound( );
|
||||||
|
|
||||||
ShutdownEventManager( );
|
|
||||||
|
|
||||||
ShutdownBaseDirtyRectQueue( );
|
ShutdownBaseDirtyRectQueue( );
|
||||||
|
|
||||||
// Unload any text box images!
|
// Unload any text box images!
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ set(UtilsSrc
|
|||||||
"${CMAKE_CURRENT_SOURCE_DIR}/Debug Control.cpp"
|
"${CMAKE_CURRENT_SOURCE_DIR}/Debug Control.cpp"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/dsutil.cpp"
|
"${CMAKE_CURRENT_SOURCE_DIR}/dsutil.cpp"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/Encrypted File.cpp"
|
"${CMAKE_CURRENT_SOURCE_DIR}/Encrypted File.cpp"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/Event Manager.cpp"
|
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/Event Pump.cpp"
|
"${CMAKE_CURRENT_SOURCE_DIR}/Event Pump.cpp"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/ExportStrings.cpp"
|
"${CMAKE_CURRENT_SOURCE_DIR}/ExportStrings.cpp"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/Font Control.cpp"
|
"${CMAKE_CURRENT_SOURCE_DIR}/Font Control.cpp"
|
||||||
|
|||||||
@@ -1,234 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include <time.h>
|
|
||||||
#include "sgp.h"
|
|
||||||
#include "container.h"
|
|
||||||
#include "wcheck.h"
|
|
||||||
#include "Event Manager.h"
|
|
||||||
#include "Timer Control.h"
|
|
||||||
|
|
||||||
HLIST hEventQueue = NULL;
|
|
||||||
HLIST hDelayEventQueue = NULL;
|
|
||||||
HLIST hDemandEventQueue = NULL;
|
|
||||||
|
|
||||||
#define QUEUE_RESIZE 20
|
|
||||||
|
|
||||||
// LOCAL FUNCTIONS
|
|
||||||
HLIST GetQueue( UINT8 ubQueueID );
|
|
||||||
void SetQueue( UINT8 ubQueueID, HLIST hQueue );
|
|
||||||
|
|
||||||
|
|
||||||
BOOLEAN InitializeEventManager( )
|
|
||||||
{
|
|
||||||
// Create Queue
|
|
||||||
hEventQueue = CreateList( QUEUE_RESIZE, sizeof( PTR ) );
|
|
||||||
|
|
||||||
if ( hEventQueue == NULL )
|
|
||||||
{
|
|
||||||
return( FALSE );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create Delay Queue
|
|
||||||
hDelayEventQueue = CreateList( QUEUE_RESIZE, sizeof( PTR ) );
|
|
||||||
|
|
||||||
if ( hDelayEventQueue == NULL )
|
|
||||||
{
|
|
||||||
return( FALSE );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create Demand Queue (events on this queue are only processed when specifically
|
|
||||||
// called for by code)
|
|
||||||
hDemandEventQueue = CreateList( QUEUE_RESIZE, sizeof( PTR ) );
|
|
||||||
|
|
||||||
if ( hDemandEventQueue == NULL )
|
|
||||||
{
|
|
||||||
return( FALSE );
|
|
||||||
}
|
|
||||||
|
|
||||||
return( TRUE );
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOLEAN ShutdownEventManager( )
|
|
||||||
{
|
|
||||||
if ( hEventQueue != NULL )
|
|
||||||
{
|
|
||||||
DeleteList( hEventQueue );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( hDelayEventQueue != NULL )
|
|
||||||
{
|
|
||||||
DeleteList( hDelayEventQueue );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( hDemandEventQueue != NULL )
|
|
||||||
{
|
|
||||||
DeleteList( hDemandEventQueue );
|
|
||||||
}
|
|
||||||
|
|
||||||
return( TRUE );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
BOOLEAN AddEvent( UINT32 uiEvent, UINT16 usDelay, PTR pEventData, UINT32 uiDataSize, UINT8 ubQueueID )
|
|
||||||
{
|
|
||||||
EVENT *pEvent;
|
|
||||||
UINT32 uiEventSize = sizeof( EVENT );
|
|
||||||
HLIST hQueue;
|
|
||||||
|
|
||||||
// Allocate new event
|
|
||||||
pEvent = (EVENT *) MemAlloc( uiEventSize + uiDataSize );
|
|
||||||
|
|
||||||
CHECKF( pEvent != NULL );
|
|
||||||
|
|
||||||
// Set values
|
|
||||||
pEvent->TimeStamp = GetJA2Clock( );
|
|
||||||
pEvent->usDelay = usDelay;
|
|
||||||
pEvent->uiEvent = uiEvent;
|
|
||||||
pEvent->uiFlags = 0;
|
|
||||||
pEvent->uiDataSize = uiDataSize;
|
|
||||||
pEvent->pData = (BYTE*)pEvent;
|
|
||||||
pEvent->pData = pEvent->pData + uiEventSize;
|
|
||||||
|
|
||||||
memcpy( pEvent->pData, pEventData, uiDataSize );
|
|
||||||
|
|
||||||
// Add event to queue
|
|
||||||
hQueue = GetQueue( ubQueueID );
|
|
||||||
hQueue = AddtoList( hQueue, &pEvent, ListSize( hQueue ) );
|
|
||||||
SetQueue( ubQueueID, hQueue );
|
|
||||||
|
|
||||||
return( TRUE );
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
BOOLEAN RemoveEvent( EVENT **ppEvent, UINT32 uiIndex, UINT8 ubQueueID )
|
|
||||||
{
|
|
||||||
UINT32 uiQueueSize;
|
|
||||||
HLIST hQueue;
|
|
||||||
|
|
||||||
// Get an event from queue, if one exists
|
|
||||||
//
|
|
||||||
|
|
||||||
hQueue = GetQueue( ubQueueID );
|
|
||||||
|
|
||||||
|
|
||||||
// Get Size
|
|
||||||
uiQueueSize = ListSize( hQueue );
|
|
||||||
|
|
||||||
if ( uiQueueSize > 0 )
|
|
||||||
{
|
|
||||||
// Get
|
|
||||||
CHECKF( RemfromList( hQueue , ppEvent, uiIndex ) != FALSE );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return( FALSE );
|
|
||||||
}
|
|
||||||
|
|
||||||
return( TRUE );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
BOOLEAN PeekEvent( EVENT **ppEvent, UINT32 uiIndex , UINT8 ubQueueID )
|
|
||||||
{
|
|
||||||
UINT32 uiQueueSize;
|
|
||||||
HLIST hQueue;
|
|
||||||
|
|
||||||
// Get an event from queue, if one exists
|
|
||||||
//
|
|
||||||
|
|
||||||
hQueue = GetQueue( ubQueueID );
|
|
||||||
|
|
||||||
|
|
||||||
// Get Size
|
|
||||||
uiQueueSize = ListSize( hQueue );
|
|
||||||
|
|
||||||
if ( uiQueueSize > 0 )
|
|
||||||
{
|
|
||||||
// Get
|
|
||||||
CHECKF( PeekList( hQueue, ppEvent, uiIndex ) != FALSE );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return( FALSE );
|
|
||||||
}
|
|
||||||
|
|
||||||
return( TRUE );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
BOOLEAN FreeEvent( EVENT *pEvent )
|
|
||||||
{
|
|
||||||
CHECKF( pEvent != NULL );
|
|
||||||
|
|
||||||
// Delete event
|
|
||||||
MemFree( pEvent );
|
|
||||||
|
|
||||||
return( TRUE );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
UINT32 EventQueueSize( UINT8 ubQueueID )
|
|
||||||
{
|
|
||||||
UINT32 uiQueueSize;
|
|
||||||
HLIST hQueue;
|
|
||||||
|
|
||||||
// Get an event from queue, if one exists
|
|
||||||
//
|
|
||||||
|
|
||||||
hQueue = GetQueue( ubQueueID );
|
|
||||||
|
|
||||||
// Get Size
|
|
||||||
uiQueueSize = ListSize( hQueue );
|
|
||||||
|
|
||||||
return( uiQueueSize );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
HLIST GetQueue( UINT8 ubQueueID )
|
|
||||||
{
|
|
||||||
switch( ubQueueID )
|
|
||||||
{
|
|
||||||
case PRIMARY_EVENT_QUEUE:
|
|
||||||
return( hEventQueue );
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SECONDARY_EVENT_QUEUE:
|
|
||||||
return( hDelayEventQueue );
|
|
||||||
break;
|
|
||||||
|
|
||||||
case DEMAND_EVENT_QUEUE:
|
|
||||||
return( hDemandEventQueue );
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
Assert( FALSE );
|
|
||||||
return( 0 );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetQueue( UINT8 ubQueueID, HQUEUE hQueue )
|
|
||||||
{
|
|
||||||
switch( ubQueueID )
|
|
||||||
{
|
|
||||||
case PRIMARY_EVENT_QUEUE:
|
|
||||||
hEventQueue = hQueue;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SECONDARY_EVENT_QUEUE:
|
|
||||||
hDelayEventQueue = hQueue;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case DEMAND_EVENT_QUEUE:
|
|
||||||
hDemandEventQueue = hQueue;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
Assert( FALSE );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
#ifndef __EVENT_MANAGER_H
|
|
||||||
#define __EVENT_MANAGER_H
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
TIMER TimeStamp;
|
|
||||||
UINT32 uiFlags;
|
|
||||||
UINT16 usDelay;
|
|
||||||
UINT32 uiEvent;
|
|
||||||
UINT32 uiDataSize;
|
|
||||||
BYTE *pData;
|
|
||||||
|
|
||||||
} EVENT;
|
|
||||||
|
|
||||||
#define PRIMARY_EVENT_QUEUE 0
|
|
||||||
#define SECONDARY_EVENT_QUEUE 1
|
|
||||||
#define DEMAND_EVENT_QUEUE 2
|
|
||||||
|
|
||||||
#define EVENT_EXPIRED 0x00000002
|
|
||||||
|
|
||||||
// Management fucntions
|
|
||||||
BOOLEAN InitializeEventManager( );
|
|
||||||
BOOLEAN ShutdownEventManager( );
|
|
||||||
|
|
||||||
BOOLEAN AddEvent( UINT32 uiEvent, UINT16 usDelay, PTR pEventData, UINT32 uiDataSize, UINT8 ubQueueID );
|
|
||||||
BOOLEAN RemoveEvent( EVENT **ppEvent, UINT32 uiIndex , UINT8 ubQueueID );
|
|
||||||
BOOLEAN PeekEvent( EVENT **ppEvent, UINT32 uiIndex , UINT8 ubQueueID );
|
|
||||||
BOOLEAN FreeEvent( EVENT *pEvent );
|
|
||||||
UINT32 EventQueueSize( UINT8 ubQueueID );
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
+267
-116
@@ -1,21 +1,26 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include "sgp.h"
|
#include "sgp.h"
|
||||||
#include "container.h"
|
#include "container.h"
|
||||||
#include "wcheck.h"
|
#include "wcheck.h"
|
||||||
#include "Event Pump.h"
|
#include "Event Pump.h"
|
||||||
#include "Timer.h"
|
#include "Timer.h"
|
||||||
#include "Sound Control.h"
|
#include "Sound Control.h"
|
||||||
#include "Overhead.h"
|
#include "Overhead.h"
|
||||||
#include "weapons.h"
|
#include "weapons.h"
|
||||||
#include "Animation Control.h"
|
#include "Animation Control.h"
|
||||||
#include "opplist.h"
|
#include "opplist.h"
|
||||||
#include "Tactical Save.h"
|
#include "Tactical Save.h"
|
||||||
|
#include<vector>
|
||||||
|
#include<queue>
|
||||||
|
|
||||||
#ifdef NETWORKED
|
#ifdef NETWORKED
|
||||||
#include "Networking.h"
|
#include "Networking.h"
|
||||||
#include "NetworkEvent.h"
|
#include "NetworkEvent.h"
|
||||||
#endif
|
#endif
|
||||||
|
#include "MemMan.h"
|
||||||
|
#include "Timer Control.h"
|
||||||
|
#include "DEBUG.H"
|
||||||
|
|
||||||
UINT8 gubEncryptionArray4[ BASE_NUMBER_OF_ROTATION_ARRAYS * 3 ][ NEW_ROTATION_ARRAY_SIZE ] =
|
UINT8 gubEncryptionArray4[ BASE_NUMBER_OF_ROTATION_ARRAYS * 3 ][ NEW_ROTATION_ARRAY_SIZE ] =
|
||||||
{
|
{
|
||||||
@@ -590,6 +595,26 @@ UINT8 gubEncryptionArray4[ BASE_NUMBER_OF_ROTATION_ARRAYS * 3 ][ NEW_ROTATION_AR
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
TIMER TimeStamp;
|
||||||
|
UINT32 uiFlags;
|
||||||
|
UINT16 usDelay;
|
||||||
|
UINT32 uiEvent;
|
||||||
|
UINT32 uiDataSize;
|
||||||
|
BYTE* pData;
|
||||||
|
|
||||||
|
} EVENT;
|
||||||
|
|
||||||
|
#define PRIMARY_EVENT_QUEUE 0
|
||||||
|
#define SECONDARY_EVENT_QUEUE 1
|
||||||
|
#define DEMAND_EVENT_QUEUE 2
|
||||||
|
#define EVENT_EXPIRED 0x00000002
|
||||||
|
|
||||||
|
std::queue<EVENT> hEventQueue;
|
||||||
|
std::vector<EVENT> hDelayEventQueue;
|
||||||
|
std::queue<EVENT> hDemandEventQueue;
|
||||||
|
|
||||||
// GLobals used here, for each event structure used,
|
// GLobals used here, for each event structure used,
|
||||||
// Used as globals for stack reasons
|
// Used as globals for stack reasons
|
||||||
EV_E_PLAYSOUND EPlaySound;
|
EV_E_PLAYSOUND EPlaySound;
|
||||||
@@ -601,67 +626,172 @@ EV_S_GETNEWPATH SGetNewPath;
|
|||||||
EV_S_BEGINTURN SBeginTurn;
|
EV_S_BEGINTURN SBeginTurn;
|
||||||
EV_S_CHANGESTANCE SChangeStance;
|
EV_S_CHANGESTANCE SChangeStance;
|
||||||
EV_S_SETDIRECTION SSetDirection;
|
EV_S_SETDIRECTION SSetDirection;
|
||||||
EV_S_SETDESIREDDIRECTION SSetDesiredDirection;
|
EV_S_SETDESIREDDIRECTION SSetDesiredDirection;
|
||||||
EV_S_BEGINFIREWEAPON SBeginFireWeapon;
|
EV_S_BEGINFIREWEAPON SBeginFireWeapon;
|
||||||
EV_S_FIREWEAPON SFireWeapon;
|
EV_S_FIREWEAPON SFireWeapon;
|
||||||
EV_S_WEAPONHIT SWeaponHit;
|
EV_S_WEAPONHIT SWeaponHit;
|
||||||
EV_S_STRUCTUREHIT SStructureHit;
|
EV_S_STRUCTUREHIT SStructureHit;
|
||||||
EV_S_WINDOWHIT SWindowHit;
|
EV_S_WINDOWHIT SWindowHit;
|
||||||
EV_S_MISS SMiss;
|
EV_S_MISS SMiss;
|
||||||
EV_S_NOISE SNoise;
|
EV_S_NOISE SNoise;
|
||||||
EV_S_STOP_MERC SStopMerc;
|
EV_S_STOP_MERC SStopMerc;
|
||||||
EV_S_SENDPATHTONETWORK SUpdateNetworkSoldier;
|
EV_S_SENDPATHTONETWORK SUpdateNetworkSoldier;
|
||||||
|
|
||||||
extern BOOLEAN gfAmINetworked;
|
extern BOOLEAN gfAmINetworked;
|
||||||
|
|
||||||
BOOLEAN AddGameEventToQueue( UINT32 uiEvent, UINT16 usDelay, PTR pEventData, UINT8 ubQueueID );
|
|
||||||
BOOLEAN ExecuteGameEvent( EVENT *pEvent );
|
BOOLEAN ExecuteGameEvent( EVENT *pEvent );
|
||||||
|
|
||||||
|
|
||||||
BOOLEAN AddGameEvent( UINT32 uiEvent, UINT16 usDelay, PTR pEventData )
|
BOOLEAN AddEvent(UINT32 uiEvent, UINT16 usDelay, PTR pEventData, UINT32 uiDataSize, UINT8 ubQueueID)
|
||||||
{
|
{
|
||||||
if (usDelay == DEMAND_EVENT_DELAY)
|
BYTE* pData = (BYTE*)MemAlloc(uiDataSize);
|
||||||
|
Assert(pData);
|
||||||
|
memcpy(pData, pEventData, uiDataSize);
|
||||||
|
|
||||||
|
// Add event to queue
|
||||||
|
switch (ubQueueID)
|
||||||
{
|
{
|
||||||
//DebugMsg( TOPIC_JA2, DBG_LEVEL_3, String("AddGameEvent: Sending Local and network #%d", uiEvent));
|
case PRIMARY_EVENT_QUEUE:
|
||||||
#ifdef NETWORKED
|
//hEventQueue.push(*pEvent);
|
||||||
if(gfAmINetworked)
|
hEventQueue.emplace(
|
||||||
SendEventToNetwork(uiEvent, usDelay, pEventData);
|
EVENT{
|
||||||
#endif
|
GetJA2Clock(),
|
||||||
return( AddGameEventToQueue( uiEvent, 0, pEventData, DEMAND_EVENT_QUEUE ) );
|
0,
|
||||||
|
usDelay,
|
||||||
|
uiEvent,
|
||||||
|
uiDataSize,
|
||||||
|
pData
|
||||||
|
}
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SECONDARY_EVENT_QUEUE:
|
||||||
|
hDelayEventQueue.emplace_back(
|
||||||
|
EVENT{
|
||||||
|
GetJA2Clock(),
|
||||||
|
0,
|
||||||
|
usDelay,
|
||||||
|
uiEvent,
|
||||||
|
uiDataSize,
|
||||||
|
pData
|
||||||
|
}
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DEMAND_EVENT_QUEUE:
|
||||||
|
hDemandEventQueue.emplace(
|
||||||
|
EVENT{
|
||||||
|
GetJA2Clock(),
|
||||||
|
0,
|
||||||
|
usDelay,
|
||||||
|
uiEvent,
|
||||||
|
uiDataSize,
|
||||||
|
pData
|
||||||
|
}
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
Assert(FALSE);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
else if( uiEvent < EVENTS_LOCAL_AND_NETWORK)
|
|
||||||
{
|
return(TRUE);
|
||||||
//DebugMsg( TOPIC_JA2, DBG_LEVEL_3, String("AddGameEvent: Sending Local and network #%d", uiEvent));
|
|
||||||
#ifdef NETWORKED
|
|
||||||
if(gfAmINetworked)
|
|
||||||
SendEventToNetwork(uiEvent, usDelay, pEventData);
|
|
||||||
#endif
|
|
||||||
return( AddGameEventToQueue( uiEvent, usDelay, pEventData, PRIMARY_EVENT_QUEUE ) );
|
|
||||||
}
|
|
||||||
else if( uiEvent < EVENTS_ONLY_USED_LOCALLY)
|
|
||||||
{
|
|
||||||
//DebugMsg( TOPIC_JA2, DBG_LEVEL_3, String("AddGameEvent: Sending Local #%d", uiEvent));
|
|
||||||
return( AddGameEventToQueue( uiEvent, usDelay, pEventData, PRIMARY_EVENT_QUEUE ) );
|
|
||||||
}
|
|
||||||
else if( uiEvent < EVENTS_ONLY_SENT_OVER_NETWORK)
|
|
||||||
{
|
|
||||||
//DebugMsg( TOPIC_JA2, DBG_LEVEL_3, String("AddGameEvent: Sending network #%d", uiEvent));
|
|
||||||
#ifdef NETWORKED
|
|
||||||
if(gfAmINetworked)
|
|
||||||
SendEventToNetwork(uiEvent, usDelay, pEventData);
|
|
||||||
#endif
|
|
||||||
return(TRUE);
|
|
||||||
}
|
|
||||||
// There is an error with the event
|
|
||||||
else
|
|
||||||
return(FALSE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOLEAN AddGameEventFromNetwork( UINT32 uiEvent, UINT16 usDelay, PTR pEventData )
|
|
||||||
|
static BOOLEAN RemoveEventFromSecondaryEventQueue(EVENT* ppEvent, UINT32 uiIndex)
|
||||||
{
|
{
|
||||||
return( AddGameEventToQueue( uiEvent, usDelay, pEventData, PRIMARY_EVENT_QUEUE ) );
|
if (uiIndex < hDelayEventQueue.size())
|
||||||
|
{
|
||||||
|
*ppEvent = hDelayEventQueue[uiIndex];
|
||||||
|
hDelayEventQueue.erase(hDelayEventQueue.begin() + uiIndex);
|
||||||
|
return(TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
return(FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BOOLEAN PopEvent(EVENT* ppEvent, UINT8 ubQueueID)
|
||||||
|
{
|
||||||
|
// Get an event from queue, if one exists
|
||||||
|
//
|
||||||
|
switch (ubQueueID)
|
||||||
|
{
|
||||||
|
case PRIMARY_EVENT_QUEUE:
|
||||||
|
if (!hEventQueue.empty())
|
||||||
|
{
|
||||||
|
*ppEvent = hEventQueue.front();
|
||||||
|
hEventQueue.pop();
|
||||||
|
return(TRUE);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SECONDARY_EVENT_QUEUE:
|
||||||
|
if (!hDelayEventQueue.empty())
|
||||||
|
{
|
||||||
|
*ppEvent = hDelayEventQueue.front();
|
||||||
|
hDelayEventQueue.erase(hDelayEventQueue.begin());
|
||||||
|
return(TRUE);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DEMAND_EVENT_QUEUE:
|
||||||
|
if (!hDemandEventQueue.empty())
|
||||||
|
{
|
||||||
|
*ppEvent = hDemandEventQueue.front();
|
||||||
|
hDemandEventQueue.pop();
|
||||||
|
return(TRUE);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
Assert(FALSE);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return(FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BOOLEAN FreeEvent(EVENT* pEvent)
|
||||||
|
{
|
||||||
|
CHECKF(pEvent != NULL);
|
||||||
|
|
||||||
|
// Delete event
|
||||||
|
MemFree(pEvent->pData);
|
||||||
|
//MemFree(pEvent);
|
||||||
|
|
||||||
|
return(TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
UINT32 EventQueueSize(UINT8 ubQueueID)
|
||||||
|
{
|
||||||
|
switch (ubQueueID)
|
||||||
|
{
|
||||||
|
case PRIMARY_EVENT_QUEUE:
|
||||||
|
return(hEventQueue.size());
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SECONDARY_EVENT_QUEUE:
|
||||||
|
return(hDelayEventQueue.size());
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DEMAND_EVENT_QUEUE:
|
||||||
|
return(hDemandEventQueue.size());
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
Assert(FALSE);
|
||||||
|
return(-1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
BOOLEAN AddGameEventToQueue( UINT32 uiEvent, UINT16 usDelay, PTR pEventData, UINT8 ubQueueID )
|
BOOLEAN AddGameEventToQueue( UINT32 uiEvent, UINT16 usDelay, PTR pEventData, UINT8 ubQueueID )
|
||||||
{
|
{
|
||||||
UINT32 uiDataSize;
|
UINT32 uiDataSize;
|
||||||
@@ -783,18 +913,65 @@ BOOLEAN AddGameEventToQueue( UINT32 uiEvent, UINT16 usDelay, PTR pEventData, UIN
|
|||||||
return( TRUE );
|
return( TRUE );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BOOLEAN AddGameEvent(UINT32 uiEvent, UINT16 usDelay, PTR pEventData)
|
||||||
|
{
|
||||||
|
if (usDelay == DEMAND_EVENT_DELAY)
|
||||||
|
{
|
||||||
|
//DebugMsg( TOPIC_JA2, DBG_LEVEL_3, String("AddGameEvent: Sending Local and network #%d", uiEvent));
|
||||||
|
#ifdef NETWORKED
|
||||||
|
if (gfAmINetworked)
|
||||||
|
SendEventToNetwork(uiEvent, usDelay, pEventData);
|
||||||
|
#endif
|
||||||
|
return(AddGameEventToQueue(uiEvent, 0, pEventData, DEMAND_EVENT_QUEUE));
|
||||||
|
}
|
||||||
|
else if (uiEvent < EVENTS_LOCAL_AND_NETWORK)
|
||||||
|
{
|
||||||
|
//DebugMsg( TOPIC_JA2, DBG_LEVEL_3, String("AddGameEvent: Sending Local and network #%d", uiEvent));
|
||||||
|
#ifdef NETWORKED
|
||||||
|
if (gfAmINetworked)
|
||||||
|
SendEventToNetwork(uiEvent, usDelay, pEventData);
|
||||||
|
#endif
|
||||||
|
return(AddGameEventToQueue(uiEvent, usDelay, pEventData, PRIMARY_EVENT_QUEUE));
|
||||||
|
}
|
||||||
|
else if (uiEvent < EVENTS_ONLY_USED_LOCALLY)
|
||||||
|
{
|
||||||
|
//DebugMsg( TOPIC_JA2, DBG_LEVEL_3, String("AddGameEvent: Sending Local #%d", uiEvent));
|
||||||
|
return(AddGameEventToQueue(uiEvent, usDelay, pEventData, PRIMARY_EVENT_QUEUE));
|
||||||
|
}
|
||||||
|
else if (uiEvent < EVENTS_ONLY_SENT_OVER_NETWORK)
|
||||||
|
{
|
||||||
|
//DebugMsg( TOPIC_JA2, DBG_LEVEL_3, String("AddGameEvent: Sending network #%d", uiEvent));
|
||||||
|
#ifdef NETWORKED
|
||||||
|
if (gfAmINetworked)
|
||||||
|
SendEventToNetwork(uiEvent, usDelay, pEventData);
|
||||||
|
#endif
|
||||||
|
return(TRUE);
|
||||||
|
}
|
||||||
|
// There is an error with the event
|
||||||
|
else
|
||||||
|
return(FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BOOLEAN AddGameEventFromNetwork(UINT32 uiEvent, UINT16 usDelay, PTR pEventData)
|
||||||
|
{
|
||||||
|
return(AddGameEventToQueue(uiEvent, usDelay, pEventData, PRIMARY_EVENT_QUEUE));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
BOOLEAN DequeAllGameEvents( BOOLEAN fExecute )
|
BOOLEAN DequeAllGameEvents( BOOLEAN fExecute )
|
||||||
{
|
{
|
||||||
EVENT *pEvent;
|
EVENT pEvent;
|
||||||
UINT32 uiQueueSize, cnt;
|
UINT32 uiQueueSize, i;
|
||||||
BOOLEAN fCompleteLoop = FALSE;
|
BOOLEAN fCompleteLoop = FALSE;
|
||||||
|
|
||||||
|
|
||||||
// First dequeue all primary events
|
// First dequeue all primary events
|
||||||
|
|
||||||
|
|
||||||
while( EventQueueSize( PRIMARY_EVENT_QUEUE ) > 0 )
|
while( EventQueueSize( PRIMARY_EVENT_QUEUE ) > 0 )
|
||||||
{
|
{
|
||||||
// Get Event
|
// Get Event
|
||||||
if ( RemoveEvent( &pEvent, 0, PRIMARY_EVENT_QUEUE) == FALSE )
|
if (PopEvent( &pEvent, PRIMARY_EVENT_QUEUE) == FALSE )
|
||||||
{
|
{
|
||||||
return( FALSE );
|
return( FALSE );
|
||||||
}
|
}
|
||||||
@@ -802,90 +979,66 @@ BOOLEAN DequeAllGameEvents( BOOLEAN fExecute )
|
|||||||
if ( fExecute )
|
if ( fExecute )
|
||||||
{
|
{
|
||||||
// Check if event has a delay and add to secondary queue if so
|
// Check if event has a delay and add to secondary queue if so
|
||||||
if ( pEvent->usDelay > 0 )
|
if ( pEvent.usDelay > 0 )
|
||||||
{
|
{
|
||||||
AddGameEventToQueue( pEvent->uiEvent, pEvent->usDelay, pEvent->pData, SECONDARY_EVENT_QUEUE );
|
AddGameEventToQueue( pEvent.uiEvent, pEvent.usDelay, pEvent.pData, SECONDARY_EVENT_QUEUE );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ExecuteGameEvent( pEvent );
|
ExecuteGameEvent( &pEvent );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete event
|
// Delete event
|
||||||
FreeEvent( pEvent );
|
FreeEvent( &pEvent );
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// NOW CHECK SECONDARY QUEUE FOR ANY EXPRIED EVENTS
|
|
||||||
// Get size of queue
|
// NOW CHECK SECONDARY QUEUE FOR EVENTS
|
||||||
uiQueueSize = EventQueueSize( SECONDARY_EVENT_QUEUE );
|
uiQueueSize = EventQueueSize( SECONDARY_EVENT_QUEUE );
|
||||||
|
|
||||||
for ( cnt = 0; cnt < uiQueueSize; cnt++ )
|
for ( i = 0; i < uiQueueSize; i++ )
|
||||||
{
|
{
|
||||||
if ( PeekEvent( &pEvent, cnt, SECONDARY_EVENT_QUEUE) == FALSE )
|
EVENT& pEventRef = hDelayEventQueue[i];
|
||||||
{
|
|
||||||
return( FALSE );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check time
|
// Check time
|
||||||
if ( ( GetJA2Clock() - pEvent->TimeStamp ) > pEvent->usDelay )
|
if ( ( GetJA2Clock() - pEventRef.TimeStamp ) > pEventRef.usDelay )
|
||||||
{
|
{
|
||||||
if ( fExecute )
|
if ( fExecute )
|
||||||
{
|
{
|
||||||
ExecuteGameEvent( pEvent );
|
ExecuteGameEvent( &pEventRef );
|
||||||
}
|
}
|
||||||
|
|
||||||
// FLag as expired
|
// FLag as expired
|
||||||
pEvent->uiFlags = EVENT_EXPIRED;
|
pEventRef.uiFlags = EVENT_EXPIRED;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
do
|
// Remove expired events from secondary event queue
|
||||||
|
uiQueueSize = EventQueueSize(SECONDARY_EVENT_QUEUE);
|
||||||
|
for (INT32 i = uiQueueSize-1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
uiQueueSize = EventQueueSize( SECONDARY_EVENT_QUEUE );
|
EVENT& pEventRef = hDelayEventQueue[i];
|
||||||
|
if (pEventRef.uiFlags & EVENT_EXPIRED)
|
||||||
for ( cnt = 0; cnt < uiQueueSize; cnt++ )
|
|
||||||
{
|
{
|
||||||
if ( PeekEvent( &pEvent, cnt, SECONDARY_EVENT_QUEUE) == FALSE )
|
RemoveEventFromSecondaryEventQueue(&pEventRef, i);
|
||||||
{
|
FreeEvent(&pEventRef);
|
||||||
return( FALSE );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check time
|
|
||||||
if ( pEvent->uiFlags & EVENT_EXPIRED )
|
|
||||||
{
|
|
||||||
RemoveEvent( &pEvent, cnt, SECONDARY_EVENT_QUEUE );
|
|
||||||
FreeEvent( pEvent );
|
|
||||||
// Restart loop
|
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if ( cnt == uiQueueSize )
|
|
||||||
{
|
|
||||||
fCompleteLoop = TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
} while( fCompleteLoop == FALSE );
|
|
||||||
|
|
||||||
return( TRUE );
|
return( TRUE );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BOOLEAN DequeueAllDemandGameEvents( BOOLEAN fExecute )
|
BOOLEAN DequeueAllDemandGameEvents( BOOLEAN fExecute )
|
||||||
{
|
{
|
||||||
EVENT *pEvent;
|
EVENT pEvent;
|
||||||
|
|
||||||
// Dequeue all events on the demand queue (only)
|
// Dequeue all events on the demand queue (only)
|
||||||
|
|
||||||
while( EventQueueSize( DEMAND_EVENT_QUEUE ) > 0 )
|
while( EventQueueSize( DEMAND_EVENT_QUEUE ) > 0 )
|
||||||
{
|
{
|
||||||
// Get Event
|
// Get Event
|
||||||
if ( RemoveEvent( &pEvent, 0, DEMAND_EVENT_QUEUE) == FALSE )
|
if ( PopEvent( &pEvent, DEMAND_EVENT_QUEUE) == FALSE )
|
||||||
{
|
{
|
||||||
return( FALSE );
|
return( FALSE );
|
||||||
}
|
}
|
||||||
@@ -893,18 +1046,18 @@ BOOLEAN DequeueAllDemandGameEvents( BOOLEAN fExecute )
|
|||||||
if ( fExecute )
|
if ( fExecute )
|
||||||
{
|
{
|
||||||
// Check if event has a delay and add to secondary queue if so
|
// Check if event has a delay and add to secondary queue if so
|
||||||
if ( pEvent->usDelay > 0 )
|
if ( pEvent.usDelay > 0 )
|
||||||
{
|
{
|
||||||
AddGameEventToQueue( pEvent->uiEvent, pEvent->usDelay, pEvent->pData, SECONDARY_EVENT_QUEUE );
|
AddGameEventToQueue( pEvent.uiEvent, pEvent.usDelay, pEvent.pData, SECONDARY_EVENT_QUEUE );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ExecuteGameEvent( pEvent );
|
ExecuteGameEvent( &pEvent );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete event
|
// Delete event
|
||||||
FreeEvent( pEvent );
|
FreeEvent( &pEvent );
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -912,7 +1065,6 @@ BOOLEAN DequeueAllDemandGameEvents( BOOLEAN fExecute )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
BOOLEAN ExecuteGameEvent( EVENT *pEvent )
|
BOOLEAN ExecuteGameEvent( EVENT *pEvent )
|
||||||
{
|
{
|
||||||
SOLDIERTYPE *pSoldier;
|
SOLDIERTYPE *pSoldier;
|
||||||
@@ -1237,17 +1389,16 @@ BOOLEAN ExecuteGameEvent( EVENT *pEvent )
|
|||||||
BOOLEAN ClearEventQueue( void )
|
BOOLEAN ClearEventQueue( void )
|
||||||
{
|
{
|
||||||
// clear out the event queue
|
// clear out the event queue
|
||||||
EVENT *pEvent;
|
EVENT pEvent;
|
||||||
while( EventQueueSize( PRIMARY_EVENT_QUEUE ) > 0 )
|
while( EventQueueSize( PRIMARY_EVENT_QUEUE ) > 0 )
|
||||||
{
|
{
|
||||||
// Get Event
|
// Get Event
|
||||||
if ( RemoveEvent( &pEvent, 0, PRIMARY_EVENT_QUEUE) == FALSE )
|
if (PopEvent( &pEvent, PRIMARY_EVENT_QUEUE) == FALSE )
|
||||||
{
|
{
|
||||||
return( FALSE );
|
return( FALSE );
|
||||||
}
|
}
|
||||||
|
FreeEvent(&pEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
return( TRUE );
|
return( TRUE );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+2
-5
@@ -1,7 +1,6 @@
|
|||||||
#ifndef EVENT_PROCESSOR_H
|
#ifndef EVENT_PROCESSOR_H
|
||||||
#define EVENT_PROCESSOR_H
|
#define EVENT_PROCESSOR_H
|
||||||
|
|
||||||
#include "Event Manager.h"
|
|
||||||
#include "Overhead Types.h"
|
#include "Overhead Types.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -271,8 +270,6 @@ BOOLEAN AddGameEventFromNetwork( UINT32 uiEvent, UINT16 usDelay, PTR pEventData
|
|||||||
BOOLEAN DequeAllGameEvents( BOOLEAN fExecute );
|
BOOLEAN DequeAllGameEvents( BOOLEAN fExecute );
|
||||||
BOOLEAN DequeueAllDemandGameEvents( BOOLEAN fExecute );
|
BOOLEAN DequeueAllDemandGameEvents( BOOLEAN fExecute );
|
||||||
|
|
||||||
// clean out the evetn queue
|
// clean out the event queue
|
||||||
BOOLEAN ClearEventQueue( void );
|
BOOLEAN ClearEventQueue( void );
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|||||||
Reference in New Issue
Block a user