mirror of
https://github.com/1dot13/source.git
synced 2026-07-22 13:40:22 +02:00
Merge pull request #236 from 1dot13/container
Remove use of Container.cpp in vsurface, dialogue and event systems
This commit is contained in:
@@ -1514,12 +1514,6 @@ UINT32 InitializeJA2(void)
|
||||
// INit intensity tables
|
||||
BuildIntensityTable( );
|
||||
|
||||
// Init Event Manager
|
||||
if ( !InitializeEventManager( ) )
|
||||
{
|
||||
return( ERROR_SCREEN );
|
||||
}
|
||||
|
||||
// Initailize World
|
||||
if ( !InitializeWorld( ) )
|
||||
{
|
||||
@@ -1698,8 +1692,6 @@ void ShutdownJA2(void)
|
||||
|
||||
ShutdownJA2Sound( );
|
||||
|
||||
ShutdownEventManager( );
|
||||
|
||||
ShutdownBaseDirtyRectQueue( );
|
||||
|
||||
// Unload any text box images!
|
||||
|
||||
@@ -51,7 +51,6 @@
|
||||
|
||||
|
||||
|
||||
HLIST ghVideoObjects = NULL;
|
||||
BOOLEAN gfVideoObjectsInit=FALSE;
|
||||
|
||||
#ifndef SGP_VIDEO_DEBUGGING
|
||||
|
||||
@@ -225,7 +225,6 @@ BOOLEAN GetETRLEPixelValue( UINT8 * pDest, HVOBJECT hVObject, UINT16 usETLREInde
|
||||
// Globals
|
||||
//
|
||||
// ****************************************************************************
|
||||
extern HLIST ghVideoObjects;
|
||||
|
||||
// ****************************************************************************
|
||||
//
|
||||
|
||||
@@ -98,18 +98,13 @@ void CheckValidVSurfaceIndex( UINT32 uiIndex );
|
||||
|
||||
INT32 giMemUsedInSurfaces;
|
||||
|
||||
|
||||
//OBSOLETE!!!!!!!!!
|
||||
HLIST ghVideoSurfaces = NULL;
|
||||
//OBSOLETE!!!!!!!!!
|
||||
|
||||
|
||||
HVSURFACE ghPrimary = NULL;
|
||||
HVSURFACE ghBackBuffer = NULL;
|
||||
HVSURFACE ghFrameBuffer = NULL;
|
||||
HVSURFACE ghMouseBuffer = NULL;
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
extern std::map<UINT32,ClipRectangle> g_SurfaceRectangle;
|
||||
|
||||
@@ -1161,11 +1156,7 @@ HVSURFACE CreateVideoSurface( VSURFACE_DESC *VSurfaceDesc )
|
||||
//
|
||||
// Allocate memory for Video Surface data and initialize
|
||||
//
|
||||
|
||||
hVSurface = (HVSURFACE) MemAlloc( sizeof( SGPVSurface ) );
|
||||
memset( hVSurface, 0, sizeof( SGPVSurface ) );
|
||||
CHECKF( hVSurface != NULL );
|
||||
|
||||
hVSurface = new SGPVSurface{};
|
||||
hVSurface->usHeight = usHeight;
|
||||
hVSurface->usWidth = usWidth;
|
||||
// BF : since we use a 16bpp framebuffer and images are converted to that format,
|
||||
@@ -1178,7 +1169,6 @@ HVSURFACE CreateVideoSurface( VSURFACE_DESC *VSurfaceDesc )
|
||||
hVSurface->pPalette = NULL;
|
||||
hVSurface->p16BPPPalette = NULL;
|
||||
hVSurface->TransparentColor = FROMRGB( 0, 0, 0 );
|
||||
hVSurface->RegionList = CreateList( DEFAULT_NUM_REGIONS, sizeof( VSURFACE_REGION ) );
|
||||
hVSurface->fFlags = 0;
|
||||
hVSurface->pClipper = NULL;
|
||||
|
||||
@@ -1647,12 +1637,6 @@ BOOLEAN DeleteVideoSurface( HVSURFACE hVSurface )
|
||||
hVSurface->pPalette = NULL;
|
||||
}
|
||||
|
||||
//if ( hVSurface->pClipper != NULL )
|
||||
//{
|
||||
// Release Clipper
|
||||
// DDReleaseClipper( (LPDIRECTDRAWCLIPPER)hVSurface->pClipper );
|
||||
//}
|
||||
|
||||
// Get surface pointer
|
||||
lpDDSurface = (LPDIRECTDRAWSURFACE2)hVSurface->pSurfaceData;
|
||||
|
||||
@@ -1670,7 +1654,7 @@ BOOLEAN DeleteVideoSurface( HVSURFACE hVSurface )
|
||||
}
|
||||
|
||||
// Release region data
|
||||
DeleteList( hVSurface->RegionList );
|
||||
hVSurface->RegionList.clear();
|
||||
|
||||
//If there is a 16bpp palette, free it
|
||||
if( hVSurface->p16BPPPalette != NULL )
|
||||
@@ -1682,8 +1666,7 @@ BOOLEAN DeleteVideoSurface( HVSURFACE hVSurface )
|
||||
giMemUsedInSurfaces -= ( hVSurface->usHeight * hVSurface->usWidth * ( hVSurface->ubBitDepth / 8 ) );
|
||||
|
||||
// Release object
|
||||
MemFree( hVSurface );
|
||||
|
||||
delete hVSurface;
|
||||
return( TRUE );
|
||||
}
|
||||
|
||||
@@ -1768,7 +1751,7 @@ BOOLEAN GetNumRegions( HVSURFACE hVSurface , UINT32 *puiNumRegions )
|
||||
{
|
||||
Assert( hVSurface );
|
||||
|
||||
*puiNumRegions = ListSize( hVSurface->RegionList );
|
||||
*puiNumRegions = hVSurface->RegionList.size();
|
||||
|
||||
return( TRUE );
|
||||
|
||||
@@ -1780,7 +1763,7 @@ BOOLEAN AddVSurfaceRegion( HVSURFACE hVSurface, VSURFACE_REGION *pNewRegion )
|
||||
Assert( pNewRegion != NULL );
|
||||
|
||||
// Add new region to list
|
||||
hVSurface->RegionList = AddtoList( hVSurface->RegionList, pNewRegion, ListSize( hVSurface->RegionList ) );
|
||||
hVSurface->RegionList.push_back(*pNewRegion);
|
||||
|
||||
return( TRUE );
|
||||
}
|
||||
@@ -1801,29 +1784,10 @@ BOOLEAN AddVSurfaceRegions( HVSURFACE hVSurface, VSURFACE_REGION **ppNewRegions,
|
||||
return( TRUE );
|
||||
}
|
||||
|
||||
BOOLEAN RemoveVSurfaceRegion( HVSURFACE hVSurface, UINT16 usIndex )
|
||||
{
|
||||
VSURFACE_REGION aRegion;
|
||||
|
||||
Assert( hVSurface != NULL );
|
||||
|
||||
return( RemfromList( hVSurface->RegionList, &aRegion, usIndex ) );
|
||||
|
||||
}
|
||||
|
||||
BOOLEAN ClearAllVSurfaceRegions( HVSURFACE hVSurface )
|
||||
{
|
||||
UINT32 uiListSize;
|
||||
|
||||
Assert( hVSurface != NULL );
|
||||
|
||||
uiListSize = ListSize( hVSurface->RegionList );
|
||||
|
||||
for ( INT32 cnt = uiListSize - 1; cnt >= 0; cnt-- )
|
||||
{
|
||||
RemoveVSurfaceRegion( hVSurface, (UINT16)cnt );
|
||||
}
|
||||
|
||||
hVSurface->RegionList.clear();
|
||||
return( TRUE );
|
||||
}
|
||||
|
||||
@@ -1831,11 +1795,12 @@ BOOLEAN GetVSurfaceRegion( HVSURFACE hVSurface, UINT16 usIndex, VSURFACE_REGION
|
||||
{
|
||||
Assert( hVSurface != NULL );
|
||||
|
||||
if ( !PeekList( hVSurface->RegionList, aRegion, usIndex ) )
|
||||
if (usIndex >= hVSurface->RegionList.size())
|
||||
{
|
||||
return( FALSE );
|
||||
}
|
||||
|
||||
*aRegion = hVSurface->RegionList[usIndex];
|
||||
return( TRUE );
|
||||
}
|
||||
|
||||
@@ -1858,15 +1823,12 @@ BOOLEAN ReplaceVSurfaceRegion( HVSURFACE hVSurface , UINT16 usIndex, VSURFACE_RE
|
||||
|
||||
Assert( hVSurface != NULL );
|
||||
|
||||
// Validate index given
|
||||
if ( !PeekList( hVSurface->RegionList, &OldRegion, usIndex ) )
|
||||
if (usIndex >= hVSurface->RegionList.size())
|
||||
{
|
||||
return( FALSE );
|
||||
}
|
||||
|
||||
// Replace information
|
||||
hVSurface->RegionList = AddtoList( hVSurface->RegionList, aRegion, usIndex );
|
||||
|
||||
hVSurface->RegionList[usIndex] = *aRegion;
|
||||
return( TRUE );
|
||||
}
|
||||
|
||||
@@ -1875,11 +1837,14 @@ BOOLEAN AddVSurfaceRegionAtIndex( HVSURFACE hVSurface, UINT16 usIndex, VSURFACE_
|
||||
Assert( hVSurface != NULL );
|
||||
Assert( pNewRegion != NULL );
|
||||
|
||||
// Add new region to list
|
||||
hVSurface->RegionList = AddtoList( hVSurface->RegionList, pNewRegion, usIndex );
|
||||
|
||||
return( TRUE );
|
||||
if (usIndex >= hVSurface->RegionList.size())
|
||||
{
|
||||
return(FALSE);
|
||||
}
|
||||
|
||||
auto pos = hVSurface->RegionList.begin() + usIndex;
|
||||
hVSurface->RegionList.insert(pos, *pNewRegion);
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
// *******************************************************************
|
||||
@@ -2161,7 +2126,7 @@ HVSURFACE CreateVideoSurfaceFromDDSurface( LPDIRECTDRAWSURFACE2 lpDDSurface )
|
||||
|
||||
|
||||
// Allocate Video Surface struct
|
||||
hVSurface = (HVSURFACE) MemAlloc( sizeof( SGPVSurface ) );
|
||||
hVSurface = new SGPVSurface{};
|
||||
|
||||
// Set values based on DD Surface given
|
||||
DDGetSurfaceDescription ( lpDDSurface, &DDSurfaceDesc );
|
||||
@@ -2173,7 +2138,6 @@ HVSURFACE CreateVideoSurfaceFromDDSurface( LPDIRECTDRAWSURFACE2 lpDDSurface )
|
||||
hVSurface->pSurfaceData = (PTR)lpDDSurface;
|
||||
hVSurface->pSurfaceData1 = NULL;
|
||||
hVSurface->pSavedSurfaceData = NULL;
|
||||
hVSurface->RegionList = CreateList( DEFAULT_NUM_REGIONS, sizeof( VSURFACE_REGION ) );
|
||||
hVSurface->fFlags = 0;
|
||||
|
||||
// Get and Set palette, if attached, allow to fail
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "container.h"
|
||||
#include "himage.h"
|
||||
#include "vobject.h"
|
||||
#include <vector>
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
@@ -105,7 +106,7 @@ typedef struct
|
||||
UINT16 *p16BPPPalette; // A 16BPP palette used for 8->16 blits
|
||||
COLORVAL TransparentColor; // Defaults to 0,0,0
|
||||
PTR pClipper; // A void pointer encapsolated as a clipper Surface
|
||||
HLIST RegionList; // A List of regions within the video Surface
|
||||
std::vector<VSURFACE_REGION> RegionList; // A List of regions within the video Surface
|
||||
|
||||
} SGPVSurface, *HVSURFACE;
|
||||
|
||||
@@ -240,7 +241,6 @@ BOOLEAN DeleteVideoSurfaceFromIndex( UINT32 uiIndex );
|
||||
BOOLEAN AddVSurfaceRegion( HVSURFACE hVSurface, VSURFACE_REGION *pNewRegion );
|
||||
BOOLEAN AddVSurfaceRegionAtIndex( HVSURFACE hVSurface, UINT16 usIndex, VSURFACE_REGION *pNewRegion );
|
||||
BOOLEAN AddVSurfaceRegions( HVSURFACE hVSurface, VSURFACE_REGION **ppNewRegions, UINT16 uiNumRegions );
|
||||
BOOLEAN RemoveVSurfaceRegion( HVSURFACE hVSurface, UINT16 usIndex );
|
||||
BOOLEAN ClearAllVSurfaceRegions( HVSURFACE hVSurface );
|
||||
BOOLEAN GetVSurfaceRegion( HVSURFACE hVSurface, UINT16 usIndex, VSURFACE_REGION *aRegion );
|
||||
BOOLEAN GetNumRegions( HVSURFACE hVSurface , UINT32 *puiNumRegions );
|
||||
@@ -286,4 +286,4 @@ BOOLEAN ShadowVideoSurfaceRectUsingLowPercentTable( UINT32 uiDestVSurface, INT32
|
||||
#endif
|
||||
*/
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
+238
-317
File diff suppressed because it is too large
Load Diff
@@ -6,7 +6,6 @@ set(UtilsSrc
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/Debug Control.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/dsutil.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}/ExportStrings.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
|
||||
|
||||
+255
-115
@@ -1,21 +1,26 @@
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include "sgp.h"
|
||||
#include "container.h"
|
||||
#include "wcheck.h"
|
||||
#include "Event Pump.h"
|
||||
#include "Timer.h"
|
||||
#include "Sound Control.h"
|
||||
#include "Overhead.h"
|
||||
#include "weapons.h"
|
||||
#include "Animation Control.h"
|
||||
#include "opplist.h"
|
||||
#include "Tactical Save.h"
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include "sgp.h"
|
||||
#include "container.h"
|
||||
#include "wcheck.h"
|
||||
#include "Event Pump.h"
|
||||
#include "Timer.h"
|
||||
#include "Sound Control.h"
|
||||
#include "Overhead.h"
|
||||
#include "weapons.h"
|
||||
#include "Animation Control.h"
|
||||
#include "opplist.h"
|
||||
#include "Tactical Save.h"
|
||||
#include <vector>
|
||||
#include <queue>
|
||||
|
||||
#ifdef NETWORKED
|
||||
#include "Networking.h"
|
||||
#include "NetworkEvent.h"
|
||||
#endif
|
||||
#include "MemMan.h"
|
||||
#include "Timer Control.h"
|
||||
#include "DEBUG.H"
|
||||
|
||||
UINT8 gubEncryptionArray4[ BASE_NUMBER_OF_ROTATION_ARRAYS * 3 ][ NEW_ROTATION_ARRAY_SIZE ] =
|
||||
{
|
||||
@@ -590,6 +595,44 @@ UINT8 gubEncryptionArray4[ BASE_NUMBER_OF_ROTATION_ARRAYS * 3 ][ NEW_ROTATION_AR
|
||||
},
|
||||
};
|
||||
|
||||
struct EVENT
|
||||
{
|
||||
TIMER TimeStamp;
|
||||
UINT32 uiFlags;
|
||||
UINT16 usDelay;
|
||||
UINT32 uiEvent;
|
||||
UINT32 uiDataSize;
|
||||
BYTE* pData;
|
||||
|
||||
EVENT(UINT16 delay, UINT32 event, UINT32 dataSize, BYTE* eventData) :
|
||||
TimeStamp(GetJA2Clock()),
|
||||
uiFlags(0),
|
||||
usDelay(delay),
|
||||
uiEvent(event),
|
||||
uiDataSize(dataSize),
|
||||
pData{ eventData }
|
||||
{
|
||||
}
|
||||
|
||||
EVENT() :
|
||||
TimeStamp(GetJA2Clock()),
|
||||
uiFlags(0),
|
||||
usDelay(0),
|
||||
uiEvent(0),
|
||||
uiDataSize(0),
|
||||
pData{ nullptr }
|
||||
{}
|
||||
};
|
||||
|
||||
#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,
|
||||
// Used as globals for stack reasons
|
||||
EV_E_PLAYSOUND EPlaySound;
|
||||
@@ -601,68 +644,144 @@ EV_S_GETNEWPATH SGetNewPath;
|
||||
EV_S_BEGINTURN SBeginTurn;
|
||||
EV_S_CHANGESTANCE SChangeStance;
|
||||
EV_S_SETDIRECTION SSetDirection;
|
||||
EV_S_SETDESIREDDIRECTION SSetDesiredDirection;
|
||||
EV_S_BEGINFIREWEAPON SBeginFireWeapon;
|
||||
EV_S_SETDESIREDDIRECTION SSetDesiredDirection;
|
||||
EV_S_BEGINFIREWEAPON SBeginFireWeapon;
|
||||
EV_S_FIREWEAPON SFireWeapon;
|
||||
EV_S_WEAPONHIT SWeaponHit;
|
||||
EV_S_STRUCTUREHIT SStructureHit;
|
||||
EV_S_WINDOWHIT SWindowHit;
|
||||
EV_S_MISS SMiss;
|
||||
EV_S_NOISE SNoise;
|
||||
EV_S_MISS SMiss;
|
||||
EV_S_NOISE SNoise;
|
||||
EV_S_STOP_MERC SStopMerc;
|
||||
EV_S_SENDPATHTONETWORK SUpdateNetworkSoldier;
|
||||
EV_S_SENDPATHTONETWORK SUpdateNetworkSoldier;
|
||||
|
||||
extern BOOLEAN gfAmINetworked;
|
||||
|
||||
BOOLEAN AddGameEventToQueue( UINT32 uiEvent, UINT16 usDelay, PTR pEventData, UINT8 ubQueueID );
|
||||
|
||||
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));
|
||||
#ifdef NETWORKED
|
||||
if(gfAmINetworked)
|
||||
SendEventToNetwork(uiEvent, usDelay, pEventData);
|
||||
#endif
|
||||
return( AddGameEventToQueue( uiEvent, 0, pEventData, DEMAND_EVENT_QUEUE ) );
|
||||
case PRIMARY_EVENT_QUEUE:
|
||||
hEventQueue.emplace(usDelay, uiEvent, uiDataSize, pData);
|
||||
break;
|
||||
|
||||
case SECONDARY_EVENT_QUEUE:
|
||||
hDelayEventQueue.emplace_back(usDelay, uiEvent, uiDataSize, pData);
|
||||
break;
|
||||
|
||||
case DEMAND_EVENT_QUEUE:
|
||||
hDemandEventQueue.emplace(usDelay, uiEvent, uiDataSize, pData);
|
||||
break;
|
||||
|
||||
default:
|
||||
Assert(FALSE);
|
||||
break;
|
||||
}
|
||||
else if( uiEvent < EVENTS_LOCAL_AND_NETWORK)
|
||||
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
|
||||
static BOOLEAN RemoveEventFromSecondaryEventQueue(EVENT* ppEvent, UINT32 uiIndex)
|
||||
{
|
||||
if (uiIndex >= hDelayEventQueue.size())
|
||||
{
|
||||
//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);
|
||||
}
|
||||
|
||||
*ppEvent = hDelayEventQueue[uiIndex];
|
||||
hDelayEventQueue.erase(hDelayEventQueue.begin() + uiIndex);
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
BOOLEAN AddGameEventFromNetwork( UINT32 uiEvent, UINT16 usDelay, PTR pEventData )
|
||||
|
||||
static BOOLEAN PopEvent(EVENT* ppEvent, UINT8 ubQueueID)
|
||||
{
|
||||
return( AddGameEventToQueue( uiEvent, usDelay, pEventData, PRIMARY_EVENT_QUEUE ) );
|
||||
// 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 AddGameEventToQueue( UINT32 uiEvent, UINT16 usDelay, PTR pEventData, UINT8 ubQueueID )
|
||||
|
||||
static BOOLEAN FreeEventData(EVENT* pEvent)
|
||||
{
|
||||
CHECKF(pEvent != NULL);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static BOOLEAN AddGameEventToQueue( UINT32 uiEvent, UINT16 usDelay, PTR pEventData, UINT8 ubQueueID )
|
||||
{
|
||||
UINT32 uiDataSize;
|
||||
|
||||
@@ -783,18 +902,65 @@ BOOLEAN AddGameEventToQueue( UINT32 uiEvent, UINT16 usDelay, PTR pEventData, UIN
|
||||
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 )
|
||||
{
|
||||
EVENT *pEvent;
|
||||
UINT32 uiQueueSize, cnt;
|
||||
BOOLEAN fCompleteLoop = FALSE;
|
||||
EVENT pEvent;
|
||||
UINT32 uiQueueSize, i;
|
||||
BOOLEAN fCompleteLoop = FALSE;
|
||||
|
||||
|
||||
// First dequeue all primary events
|
||||
|
||||
|
||||
while( EventQueueSize( PRIMARY_EVENT_QUEUE ) > 0 )
|
||||
{
|
||||
// Get Event
|
||||
if ( RemoveEvent( &pEvent, 0, PRIMARY_EVENT_QUEUE) == FALSE )
|
||||
if (PopEvent( &pEvent, PRIMARY_EVENT_QUEUE) == FALSE )
|
||||
{
|
||||
return( FALSE );
|
||||
}
|
||||
@@ -802,90 +968,66 @@ BOOLEAN DequeAllGameEvents( BOOLEAN fExecute )
|
||||
if ( fExecute )
|
||||
{
|
||||
// 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
|
||||
{
|
||||
ExecuteGameEvent( pEvent );
|
||||
ExecuteGameEvent( &pEvent );
|
||||
}
|
||||
}
|
||||
|
||||
// Delete event
|
||||
FreeEvent( pEvent );
|
||||
|
||||
FreeEventData( &pEvent );
|
||||
};
|
||||
|
||||
// NOW CHECK SECONDARY QUEUE FOR ANY EXPRIED EVENTS
|
||||
// Get size of queue
|
||||
|
||||
// NOW CHECK SECONDARY QUEUE FOR EVENTS
|
||||
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 )
|
||||
{
|
||||
return( FALSE );
|
||||
}
|
||||
|
||||
EVENT& pEventRef = hDelayEventQueue[i];
|
||||
// Check time
|
||||
if ( ( GetJA2Clock() - pEvent->TimeStamp ) > pEvent->usDelay )
|
||||
if ( ( GetJA2Clock() - pEventRef.TimeStamp ) > pEventRef.usDelay )
|
||||
{
|
||||
if ( fExecute )
|
||||
{
|
||||
ExecuteGameEvent( pEvent );
|
||||
ExecuteGameEvent( &pEventRef );
|
||||
}
|
||||
|
||||
// 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 );
|
||||
|
||||
for ( cnt = 0; cnt < uiQueueSize; cnt++ )
|
||||
EVENT& pEventRef = hDelayEventQueue[i];
|
||||
if (pEventRef.uiFlags & EVENT_EXPIRED)
|
||||
{
|
||||
if ( PeekEvent( &pEvent, cnt, SECONDARY_EVENT_QUEUE) == FALSE )
|
||||
{
|
||||
return( FALSE );
|
||||
}
|
||||
|
||||
// Check time
|
||||
if ( pEvent->uiFlags & EVENT_EXPIRED )
|
||||
{
|
||||
RemoveEvent( &pEvent, cnt, SECONDARY_EVENT_QUEUE );
|
||||
FreeEvent( pEvent );
|
||||
// Restart loop
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
RemoveEventFromSecondaryEventQueue(&pEventRef, i);
|
||||
FreeEventData(&pEventRef);
|
||||
}
|
||||
|
||||
if ( cnt == uiQueueSize )
|
||||
{
|
||||
fCompleteLoop = TRUE;
|
||||
}
|
||||
|
||||
} while( fCompleteLoop == FALSE );
|
||||
}
|
||||
|
||||
return( TRUE );
|
||||
}
|
||||
|
||||
|
||||
BOOLEAN DequeueAllDemandGameEvents( BOOLEAN fExecute )
|
||||
{
|
||||
EVENT *pEvent;
|
||||
EVENT pEvent;
|
||||
|
||||
// Dequeue all events on the demand queue (only)
|
||||
|
||||
while( EventQueueSize( DEMAND_EVENT_QUEUE ) > 0 )
|
||||
{
|
||||
// Get Event
|
||||
if ( RemoveEvent( &pEvent, 0, DEMAND_EVENT_QUEUE) == FALSE )
|
||||
if ( PopEvent( &pEvent, DEMAND_EVENT_QUEUE) == FALSE )
|
||||
{
|
||||
return( FALSE );
|
||||
}
|
||||
@@ -893,18 +1035,18 @@ BOOLEAN DequeueAllDemandGameEvents( BOOLEAN fExecute )
|
||||
if ( fExecute )
|
||||
{
|
||||
// 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
|
||||
{
|
||||
ExecuteGameEvent( pEvent );
|
||||
ExecuteGameEvent( &pEvent );
|
||||
}
|
||||
}
|
||||
|
||||
// Delete event
|
||||
FreeEvent( pEvent );
|
||||
FreeEventData( &pEvent );
|
||||
|
||||
};
|
||||
|
||||
@@ -912,7 +1054,6 @@ BOOLEAN DequeueAllDemandGameEvents( BOOLEAN fExecute )
|
||||
}
|
||||
|
||||
|
||||
|
||||
BOOLEAN ExecuteGameEvent( EVENT *pEvent )
|
||||
{
|
||||
SOLDIERTYPE *pSoldier;
|
||||
@@ -1237,17 +1378,16 @@ BOOLEAN ExecuteGameEvent( EVENT *pEvent )
|
||||
BOOLEAN ClearEventQueue( void )
|
||||
{
|
||||
// clear out the event queue
|
||||
EVENT *pEvent;
|
||||
EVENT pEvent;
|
||||
while( EventQueueSize( PRIMARY_EVENT_QUEUE ) > 0 )
|
||||
{
|
||||
// Get Event
|
||||
if ( RemoveEvent( &pEvent, 0, PRIMARY_EVENT_QUEUE) == FALSE )
|
||||
if (PopEvent( &pEvent, PRIMARY_EVENT_QUEUE) == FALSE )
|
||||
{
|
||||
return( FALSE );
|
||||
}
|
||||
FreeEventData(&pEvent);
|
||||
}
|
||||
|
||||
return( TRUE );
|
||||
}
|
||||
|
||||
|
||||
|
||||
+2
-5
@@ -1,7 +1,6 @@
|
||||
#ifndef EVENT_PROCESSOR_H
|
||||
#define EVENT_PROCESSOR_H
|
||||
|
||||
#include "Event Manager.h"
|
||||
#include "Overhead Types.h"
|
||||
|
||||
|
||||
@@ -271,8 +270,6 @@ BOOLEAN AddGameEventFromNetwork( UINT32 uiEvent, UINT16 usDelay, PTR pEventData
|
||||
BOOLEAN DequeAllGameEvents( BOOLEAN fExecute );
|
||||
BOOLEAN DequeueAllDemandGameEvents( BOOLEAN fExecute );
|
||||
|
||||
// clean out the evetn queue
|
||||
// clean out the event queue
|
||||
BOOLEAN ClearEventQueue( void );
|
||||
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user