Skip to content

Commit

Permalink
[MP] Clean up shared memory buffer between gamecode and engine
Browse files Browse the repository at this point in the history
  • Loading branch information
Razish committed Jan 20, 2014
1 parent 00d0abd commit 8de5cc6
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 100 deletions.
20 changes: 19 additions & 1 deletion codemp/cgame/cg_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,25 @@ Ghoul2 Insert Start
Ghoul2 Insert End
*/

char sharedBuffer[MAX_CG_SHARED_BUFFER_SIZE];
// used for communication with the engine
union {
char raw[MAX_CG_SHARED_BUFFER_SIZE];
TCGPointContents pointContents;
TCGVectorData vectorData;
TCGGetBoltData getBoltData;
TCGTrace trace;
TCGG2Mark g2Mark;
TCGImpactMark impactMark;
ragCallbackDebugBox_t rcbDebugBox;
ragCallbackDebugLine_t rcbDebugLine;
ragCallbackBoneSnap_t rcbBoneSnap;
ragCallbackBoneInSolid_t rcbBoneInSolid;
ragCallbackTraceLine_t rcbTraceLine;
TCGMiscEnt miscEnt;
TCGIncomingConsoleCommand icc;
autoMapInput_t autoMapInput;
TCGCameraShake cameraShake;
} sharedBuffer;

short radarEntityCount;
short radarEntities[MAX_CLIENTS+16];
Expand Down
139 changes: 60 additions & 79 deletions codemp/cgame/cg_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,95 +153,80 @@ qboolean CG_NoUseableForce(void)
return qtrue;
}

static int C_PointContents(void)
{
TCGPointContents *data = (TCGPointContents *)cg.sharedBuffer;

static int C_PointContents( void ) {
TCGPointContents *data = &cg.sharedBuffer.pointContents;
return CG_PointContents( data->mPoint, data->mPassEntityNum );
}

static void C_GetLerpOrigin(void)
{
TCGVectorData *data = (TCGVectorData *)cg.sharedBuffer;

VectorCopy(cg_entities[data->mEntityNum].lerpOrigin, data->mPoint);
static void C_GetLerpOrigin( void ) {
TCGVectorData *data = &cg.sharedBuffer.vectorData;
VectorCopy( cg_entities[data->mEntityNum].lerpOrigin, data->mPoint );
}

static void C_GetLerpData(void)
{//only used by FX system to pass to getboltmat
TCGGetBoltData *data = (TCGGetBoltData *)cg.sharedBuffer;
// only used by FX system to pass to getboltmat
static void C_GetLerpData( void ) {
TCGGetBoltData *data = &cg.sharedBuffer.getBoltData;

VectorCopy(cg_entities[data->mEntityNum].lerpOrigin, data->mOrigin);
VectorCopy(cg_entities[data->mEntityNum].modelScale, data->mScale);
VectorCopy(cg_entities[data->mEntityNum].lerpAngles, data->mAngles);
if (cg_entities[data->mEntityNum].currentState.eType == ET_PLAYER)
{ //normal player
VectorCopy( cg_entities[data->mEntityNum].lerpOrigin, data->mOrigin );
VectorCopy( cg_entities[data->mEntityNum].modelScale, data->mScale );
VectorCopy( cg_entities[data->mEntityNum].lerpAngles, data->mAngles );
if ( cg_entities[data->mEntityNum].currentState.eType == ET_PLAYER ) {
// normal player
data->mAngles[PITCH] = 0.0f;
data->mAngles[ROLL] = 0.0f;
}
else if (cg_entities[data->mEntityNum].currentState.eType == ET_NPC)
{ //an NPC
else if ( cg_entities[data->mEntityNum].currentState.eType == ET_NPC ) {
// an NPC
Vehicle_t *pVeh = cg_entities[data->mEntityNum].m_pVehicle;
if (!pVeh)
{ //for vehicles, we may or may not want to 0 out pitch and roll
if ( !pVeh ) {
// for vehicles, we may or may not want to 0 out pitch and roll
data->mAngles[PITCH] = 0.0f;
data->mAngles[ROLL] = 0.0f;
}
else if (pVeh->m_pVehicleInfo->type == VH_SPEEDER)
{ //speeder wants no pitch but a roll
else if ( pVeh->m_pVehicleInfo->type == VH_SPEEDER ) {
// speeder wants no pitch but a roll
data->mAngles[PITCH] = 0.0f;
}
else if (pVeh->m_pVehicleInfo->type != VH_FIGHTER)
{ //fighters want all angles
else if ( pVeh->m_pVehicleInfo->type != VH_FIGHTER ) {
// fighters want all angles
data->mAngles[PITCH] = 0.0f;
data->mAngles[ROLL] = 0.0f;
}
}
}

static void C_Trace(void)
{
TCGTrace *td = (TCGTrace *)cg.sharedBuffer;

CG_Trace(&td->mResult, td->mStart, td->mMins, td->mMaxs, td->mEnd, td->mSkipNumber, td->mMask);
static void C_Trace( void ) {
TCGTrace *td = &cg.sharedBuffer.trace;
CG_Trace( &td->mResult, td->mStart, td->mMins, td->mMaxs, td->mEnd, td->mSkipNumber, td->mMask );
}

static void C_G2Trace(void)
{
TCGTrace *td = (TCGTrace *)cg.sharedBuffer;

CG_G2Trace(&td->mResult, td->mStart, td->mMins, td->mMaxs, td->mEnd, td->mSkipNumber, td->mMask);
static void C_G2Trace( void ) {
TCGTrace *td = &cg.sharedBuffer.trace;
CG_G2Trace( &td->mResult, td->mStart, td->mMins, td->mMaxs, td->mEnd, td->mSkipNumber, td->mMask );
}

static void C_G2Mark(void)
{
TCGG2Mark *td = (TCGG2Mark *)cg.sharedBuffer;
trace_t tr;
vec3_t end;
static void C_G2Mark( void ) {
TCGG2Mark *td = &cg.sharedBuffer.g2Mark;
trace_t tr;
vec3_t end;

VectorMA(td->start, 64, td->dir, end);
CG_G2Trace(&tr, td->start, NULL, NULL, end, ENTITYNUM_NONE, MASK_PLAYERSOLID);
VectorMA( td->start, 64.0f, td->dir, end );
CG_G2Trace( &tr, td->start, NULL, NULL, end, ENTITYNUM_NONE, MASK_PLAYERSOLID );

if (tr.entityNum < ENTITYNUM_WORLD &&
cg_entities[tr.entityNum].ghoul2)
{ //hit someone with a ghoul2 instance, let's project the decal on them then.
if ( tr.entityNum < ENTITYNUM_WORLD && cg_entities[tr.entityNum].ghoul2 ) {
// hit someone with a ghoul2 instance, let's project the decal on them then.
centity_t *cent = &cg_entities[tr.entityNum];

//CG_TestLine(tr.endpos, end, 2000, 0x0000ff, 1);
// CG_TestLine( tr.endpos, end, 2000, 0x0000ff, 1 );

CG_AddGhoul2Mark(td->shader, td->size, tr.endpos, end, tr.entityNum,
cent->lerpOrigin, cent->lerpAngles[YAW], cent->ghoul2, cent->modelScale,
Q_irand(2000, 4000));
//I'm making fx system decals have a very short lifetime.
CG_AddGhoul2Mark( td->shader, td->size, tr.endpos, end, tr.entityNum, cent->lerpOrigin, cent->lerpAngles[YAW],
cent->ghoul2, cent->modelScale, Q_irand( 2000, 4000 ) );
// I'm making fx system decals have a very short lifetime.
}
}

static void CG_DebugBoxLines(vec3_t mins, vec3_t maxs, int duration)
{
vec3_t start;
vec3_t end;
vec3_t vert;

static void CG_DebugBoxLines( vec3_t mins, vec3_t maxs, int duration ) {
vec3_t start, end, vert;
float x = maxs[0] - mins[0];
float y = maxs[1] - mins[1];

Expand Down Expand Up @@ -305,21 +290,21 @@ static int CG_RagCallback(int callType)
{
case RAG_CALLBACK_DEBUGBOX:
{
ragCallbackDebugBox_t *callData = (ragCallbackDebugBox_t *)cg.sharedBuffer;
ragCallbackDebugBox_t *callData = &cg.sharedBuffer.rcbDebugBox;

CG_DebugBoxLines(callData->mins, callData->maxs, callData->duration);
}
break;
case RAG_CALLBACK_DEBUGLINE:
{
ragCallbackDebugLine_t *callData = (ragCallbackDebugLine_t *)cg.sharedBuffer;
ragCallbackDebugLine_t *callData = &cg.sharedBuffer.rcbDebugLine;

CG_TestLine(callData->start, callData->end, callData->time, callData->color, callData->radius);
}
break;
case RAG_CALLBACK_BONESNAP:
{
ragCallbackBoneSnap_t *callData = (ragCallbackBoneSnap_t *)cg.sharedBuffer;
ragCallbackBoneSnap_t *callData = &cg.sharedBuffer.rcbBoneSnap;
centity_t *cent = &cg_entities[callData->entNum];
int snapSound = trap->S_RegisterSound(va("sound/player/bodyfall_human%i.wav", Q_irand(1, 3)));

Expand All @@ -330,7 +315,7 @@ static int CG_RagCallback(int callType)
case RAG_CALLBACK_BONEINSOLID:
#if 0
{
ragCallbackBoneInSolid_t *callData = (ragCallbackBoneInSolid_t *)cg.sharedBuffer;
ragCallbackBoneInSolid_t *callData = &cg.sharedBuffer.rcbBoneInSolid;

if (callData->solidCount > 16)
{ //don't bother if we're just tapping into solidity, we'll probably recover on our own
Expand All @@ -347,7 +332,7 @@ static int CG_RagCallback(int callType)
break;
case RAG_CALLBACK_TRACELINE:
{
ragCallbackTraceLine_t *callData = (ragCallbackTraceLine_t *)cg.sharedBuffer;
ragCallbackTraceLine_t *callData = &cg.sharedBuffer.rcbTraceLine;

CG_Trace(&callData->tr, callData->start, callData->mins, callData->maxs,
callData->end, callData->ignore, callData->mask);
Expand All @@ -361,23 +346,19 @@ static int CG_RagCallback(int callType)
return 0;
}

static void C_ImpactMark(void)
{
TCGImpactMark *data = (TCGImpactMark *)cg.sharedBuffer;
static void C_ImpactMark( void ) {
TCGImpactMark *data = &cg.sharedBuffer.impactMark;

/*
CG_ImpactMark((int)arg0, (const float *)arg1, (const float *)arg2, (float)arg3,
(float)arg4, (float)arg5, (float)arg6, (float)arg7, qtrue, (float)arg8, qfalse);
*/
CG_ImpactMark(data->mHandle, data->mPoint, data->mAngle, data->mRotation,
data->mRed, data->mGreen, data->mBlue, data->mAlphaStart, qtrue, data->mSizeStart, qfalse);
// CG_ImpactMark( (int)arg0, (const float *)arg1, (const float *)arg2, (float)arg3, (float)arg4, (float)arg5, (float)arg6,
// (float)arg7, qtrue, (float)arg8, qfalse );

CG_ImpactMark( data->mHandle, data->mPoint, data->mAngle, data->mRotation, data->mRed, data->mGreen, data->mBlue,
data->mAlphaStart, qtrue, data->mSizeStart, qfalse );
}

void CG_MiscEnt(void)
{
int i;
int modelIndex;
TCGMiscEnt *data = (TCGMiscEnt *)cg.sharedBuffer;
void CG_MiscEnt( void ) {
int i, modelIndex;
TCGMiscEnt *data = &cg.sharedBuffer.miscEnt;
cg_staticmodel_t *staticmodel;

if( cgs.numMiscStaticModels >= MAX_STATIC_MODELS ) {
Expand Down Expand Up @@ -2590,7 +2571,7 @@ void CG_Init( int serverMessageNum, int serverCommandSequence, int clientNum )

BG_InitAnimsets(); //clear it out

trap->RegisterSharedMemory(cg.sharedBuffer);
trap->RegisterSharedMemory( cg.sharedBuffer.raw );

//Load external vehicle data
BG_VehicleLoadParms();
Expand Down Expand Up @@ -3059,7 +3040,7 @@ static qboolean CG_IncomingConsoleCommand( void ) {
//qfalse to not execute anything, or you can fill conCommand in with something valid and return 0
//in order to have that string executed in place. Some example code:
#if 0
TCGIncomingConsoleCommand *icc = (TCGIncomingConsoleCommand *)cg.sharedBuffer;
TCGIncomingConsoleCommand *icc = &cg.sharedBuffer.icc;
if ( strstr( icc->conCommand, "wait" ) )
{ //filter out commands contaning wait
Com_Printf( "You can't use commands containing the string wait with MyMod v1.0\n" );
Expand Down Expand Up @@ -3102,7 +3083,7 @@ static void CG_MapChange( void ) {
}

static void CG_AutomapInput( void ) {
autoMapInput_t *autoInput = (autoMapInput_t *)cg.sharedBuffer;
autoMapInput_t *autoInput = &cg.sharedBuffer.autoMapInput;

memcpy( &cg_autoMapInput, autoInput, sizeof( autoMapInput_t ) );

Expand All @@ -3120,7 +3101,7 @@ static void CG_AutomapInput( void ) {
}

static void CG_FX_CameraShake( void ) {
TCGCameraShake *data = (TCGCameraShake *)cg.sharedBuffer;
TCGCameraShake *data = &cg.sharedBuffer.cameraShake;
CG_DoCameraShake( data->mOrigin, data->mIntensity, data->mRadius, data->mTime );
}

Expand Down
23 changes: 22 additions & 1 deletion codemp/game/g_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,28 @@ extern vec3_t gPainPoint;
#define EC "\x19"

#define MAX_G_SHARED_BUFFER_SIZE 8192
extern char gSharedBuffer[MAX_G_SHARED_BUFFER_SIZE];
// used for communication with the engine
typedef union sharedBuffer_u {
char raw[MAX_G_SHARED_BUFFER_SIZE];
T_G_ICARUS_PLAYSOUND playSound;
T_G_ICARUS_SET set;
T_G_ICARUS_LERP2POS lerp2Pos;
T_G_ICARUS_LERP2ORIGIN lerp2Origin;
T_G_ICARUS_LERP2ANGLES lerp2Angles;
T_G_ICARUS_GETTAG getTag;
T_G_ICARUS_LERP2START lerp2Start;
T_G_ICARUS_LERP2END lerp2End;
T_G_ICARUS_USE use;
T_G_ICARUS_KILL kill;
T_G_ICARUS_REMOVE remove;
T_G_ICARUS_PLAY play;
T_G_ICARUS_GETFLOAT getFloat;
T_G_ICARUS_GETVECTOR getVector;
T_G_ICARUS_GETSTRING getString;
T_G_ICARUS_SOUNDINDEX soundIndex;
T_G_ICARUS_GETSETIDFORSTRING getSetIDForString;
} sharedBuffer_t;
extern sharedBuffer_t gSharedBuffer;

// movers are things like doors, plats, buttons, etc
typedef enum {
Expand Down
Loading

0 comments on commit 8de5cc6

Please sign in to comment.