Skip to content

Commit

Permalink
Define platform-agnostic types for common structures
Browse files Browse the repository at this point in the history
Resolves twhl-community#56

(cherry picked from commit 4b7226e)
  • Loading branch information
SamVanheer authored and LogicAndTrick committed Dec 24, 2021
1 parent a9348bf commit aa65943
Show file tree
Hide file tree
Showing 21 changed files with 80 additions and 80 deletions.
16 changes: 8 additions & 8 deletions cl_dll/ammo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ void WeaponsResource :: LoadWeaponSprites( WEAPON *pWeapon )
if ( !pWeapon )
return;

memset( &pWeapon->rcActive, 0, sizeof(wrect_t) );
memset( &pWeapon->rcInactive, 0, sizeof(wrect_t) );
memset( &pWeapon->rcAmmo, 0, sizeof(wrect_t) );
memset( &pWeapon->rcAmmo2, 0, sizeof(wrect_t) );
memset( &pWeapon->rcActive, 0, sizeof(Rect) );
memset( &pWeapon->rcInactive, 0, sizeof(Rect) );
memset( &pWeapon->rcAmmo, 0, sizeof(Rect) );
memset( &pWeapon->rcAmmo2, 0, sizeof(Rect) );
pWeapon->hInactive = 0;
pWeapon->hActive = 0;
pWeapon->hAmmo = 0;
Expand Down Expand Up @@ -391,7 +391,7 @@ void CHudAmmo::Think()
// Helper function to return a Ammo pointer from id
//

HSPRITE* WeaponsResource :: GetAmmoPicFromWeapon( int iAmmoId, wrect_t& rect )
HSPRITE* WeaponsResource :: GetAmmoPicFromWeapon( int iAmmoId, Rect& rect )
{
for ( int i = 0; i < MAX_WEAPONS; i++ )
{
Expand Down Expand Up @@ -549,7 +549,7 @@ int CHudAmmo::MsgFunc_HideWeapon( const char *pszName, int iSize, void *pbuf )
}
else if ( (m_pWeapon == NULL) || (gHUD.m_iHideHUDDisplay & ( HIDEHUD_WEAPONS | HIDEHUD_ALL )) )
{
static wrect_t nullrc;
static Rect nullrc;
gpActiveSel = NULL;
SetCrosshair( 0, nullrc, 0, 0, 0 );
// CONPRINT("Blanking crosshair\n");
Expand All @@ -571,7 +571,7 @@ int CHudAmmo::MsgFunc_HideWeapon( const char *pszName, int iSize, void *pbuf )
//
int CHudAmmo::MsgFunc_CurWeapon(const char *pszName, int iSize, void *pbuf )
{
static wrect_t nullrc;
static Rect nullrc;
int fOnTarget = FALSE;

BEGIN_READ( pbuf, iSize );
Expand Down Expand Up @@ -910,7 +910,7 @@ int CHudAmmo::Draw(float flTime)
x = ScreenWidth - (8 * AmmoWidth) - iIconWidth;
x = gHUD.DrawHudNumber(x, y, iFlags | DHN_3DIGITS, pw->iClip, r, g, b);

wrect_t rc;
Rect rc;
rc.top = 0;
rc.left = 0;
rc.right = AmmoWidth;
Expand Down
16 changes: 8 additions & 8 deletions cl_dll/ammo.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,21 @@ struct WEAPON
int iCount; // # of itesm in plist

HSPRITE hActive;
wrect_t rcActive;
Rect rcActive;
HSPRITE hInactive;
wrect_t rcInactive;
Rect rcInactive;
HSPRITE hAmmo;
wrect_t rcAmmo;
Rect rcAmmo;
HSPRITE hAmmo2;
wrect_t rcAmmo2;
Rect rcAmmo2;
HSPRITE hCrosshair;
wrect_t rcCrosshair;
Rect rcCrosshair;
HSPRITE hAutoaim;
wrect_t rcAutoaim;
Rect rcAutoaim;
HSPRITE hZoomedCrosshair;
wrect_t rcZoomedCrosshair;
Rect rcZoomedCrosshair;
HSPRITE hZoomedAutoaim;
wrect_t rcZoomedAutoaim;
Rect rcZoomedAutoaim;
};

typedef int AMMO;
Expand Down
6 changes: 3 additions & 3 deletions cl_dll/ammohistory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct ITEM_INFO
{
char szName[MAX_ITEM_NAME];
HSPRITE spr;
wrect_t rect;
Rect rect;
};

void HistoryResource :: AddToHistory( int iType, int iId, int iCount )
Expand Down Expand Up @@ -120,7 +120,7 @@ int HistoryResource :: DrawAmmoHistory( float flTime )
}
else if ( rgAmmoHistory[i].type == HISTSLOT_AMMO )
{
wrect_t rcPic;
Rect rcPic;
HSPRITE *spr = gWR.GetAmmoPicFromWeapon( rgAmmoHistory[i].iId, rcPic );

int r, g, b;
Expand Down Expand Up @@ -168,7 +168,7 @@ int HistoryResource :: DrawAmmoHistory( float flTime )
if ( !rgAmmoHistory[i].iId )
continue; // sprite not loaded

wrect_t rect = gHUD.GetSpriteRect( rgAmmoHistory[i].iId );
Rect rect = gHUD.GetSpriteRect( rgAmmoHistory[i].iId );

UnpackRGB(r,g,b, gHUD.m_iHUDColor);
float scale = (rgAmmoHistory[i].DisplayTime - flTime) * 80;
Expand Down
2 changes: 1 addition & 1 deletion cl_dll/ammohistory.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class WeaponsResource

int CountAmmo( int iId );

HSPRITE* GetAmmoPicFromWeapon( int iAmmoId, wrect_t& rect );
HSPRITE* GetAmmoPicFromWeapon( int iAmmoId, Rect& rect );
};

extern WeaponsResource gWR;
Expand Down
2 changes: 1 addition & 1 deletion cl_dll/battery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ int CHudBattery::Draw(float flTime)
return 1;

int r, g, b, x, y, a;
wrect_t rc;
Rect rc;

rc = *m_prc2;

Expand Down
2 changes: 1 addition & 1 deletion cl_dll/flashlight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ int CHudFlashlight::Draw(float flTime)
return 1;

int r, g, b, x, y, a;
wrect_t rc;
Rect rc;

if (!(gHUD.m_iWeaponBits & (1<<(WEAPON_SUIT)) ))
return 1;
Expand Down
2 changes: 1 addition & 1 deletion cl_dll/hud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ void CHud :: VidInit()

// allocated memory for sprite handle arrays
m_rghSprites = new HSPRITE[m_iSpriteCount];
m_rgrcRects = new wrect_t[m_iSpriteCount];
m_rgrcRects = new Rect[m_iSpriteCount];
m_rgszSpriteNames = new char[m_iSpriteCount * MAX_SPRITE_NAME_LENGTH];

p = m_pSpriteList;
Expand Down
18 changes: 9 additions & 9 deletions cl_dll/hud.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#define _cdecl
#endif

#include "wrect.h"
#include "common_types.h"
#include "cl_dll.h"
#include "ammo.h"

Expand Down Expand Up @@ -334,8 +334,8 @@ class CHudBattery: public CHudBase
private:
HSPRITE m_hSprite1;
HSPRITE m_hSprite2;
wrect_t *m_prc1;
wrect_t *m_prc2;
Rect *m_prc1;
Rect *m_prc2;
int m_iBat;
int m_iBatMax;
float m_fFade;
Expand All @@ -360,9 +360,9 @@ class CHudFlashlight: public CHudBase
HSPRITE m_hSprite1;
HSPRITE m_hSprite2;
HSPRITE m_hBeam;
wrect_t *m_prc1;
wrect_t *m_prc2;
wrect_t *m_prcBeam;
Rect *m_prc1;
Rect *m_prc2;
Rect *m_prcBeam;
float m_flBat;
int m_iBat;
int m_fOn;
Expand Down Expand Up @@ -472,7 +472,7 @@ class CHudStatusIcons: public CHudBase
{
char szSpriteName[MAX_ICONSPRITENAME_LENGTH];
HSPRITE spr;
wrect_t rc;
Rect rc;
unsigned char r, g, b;
} icon_sprite_t;

Expand Down Expand Up @@ -529,7 +529,7 @@ class CHud
// the memory for these arrays are allocated in the first call to CHud::VidInit(), when the hud.txt and associated sprites are loaded.
// freed in ~CHud()
HSPRITE *m_rghSprites; /*[HUD_SPRITE_COUNT]*/ // the sprites loaded from hud.txt
wrect_t *m_rgrcRects; /*[HUD_SPRITE_COUNT]*/
Rect *m_rgrcRects; /*[HUD_SPRITE_COUNT]*/
char *m_rgszSpriteNames; /*[HUD_SPRITE_COUNT][MAX_SPRITE_NAME_LENGTH]*/

struct cvar_s *default_fov;
Expand All @@ -539,7 +539,7 @@ class CHud
return (index < 0) ? 0 : m_rghSprites[index];
}

wrect_t& GetSpriteRect( int index )
Rect& GetSpriteRect( int index )
{
return m_rgrcRects[index];
}
Expand Down
2 changes: 1 addition & 1 deletion cl_dll/hud_spectator.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class CHudSpectator : public CHudBase
HSPRITE m_hsprBeam;
HSPRITE m_hCrosshair;

wrect_t m_crosshairRect;
Rect m_crosshairRect;

struct model_s * m_MapSprite; // each layer image is saved in one sprite, where each tile is a sprite frame
float m_flNextObserverInput;
Expand Down
8 changes: 4 additions & 4 deletions cl_dll/in_camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ int iMouseInUse=0;
int cam_distancemove;
extern int mouse_x, mouse_y; //used to determine what the current x and y values are
int cam_old_mouse_x, cam_old_mouse_y; //holds the last ticks mouse movement
POINT cam_mouse;
Point cam_mouse;
//-------------------------------------------------- Local Variables

static kbutton_t cam_pitchup, cam_pitchdown, cam_yawleft, cam_yawright;
Expand All @@ -83,10 +83,10 @@ void CAM_ToFirstPerson();
void CAM_StartDistance();
void CAM_EndDistance();

void SDL_GetCursorPos( POINT *p )
void SDL_GetCursorPos( Point *p )
{
gEngfuncs.GetMousePosition( (int *)&p->x, (int *)&p->y );
// SDL_GetMouseState( (int *)&p->x, (int *)&p->y );
gEngfuncs.GetMousePosition( &p->x, &p->y );
// SDL_GetMouseState( &p->x, &p->y );
}

void SDL_SetCursorPos( const int x, const int y )
Expand Down
2 changes: 1 addition & 1 deletion cl_dll/inputw32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ static cvar_t *m_mousethread_sleep;

int mouse_buttons;
int mouse_oldbuttonstate;
POINT current_pos;
int old_mouse_x, old_mouse_y, mx_accum, my_accum;
float mouse_x, mouse_y;

Expand Down Expand Up @@ -179,6 +178,7 @@ void Force_CenterView_f ()
#ifdef _WIN32
long s_mouseDeltaX = 0;
long s_mouseDeltaY = 0;
POINT current_pos;
POINT old_mouse_pos;

long ThreadInterlockedExchange( long *pDest, long value )
Expand Down
1 change: 1 addition & 0 deletions common/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#pragma warning(disable : 4100) // unreferenced formal parameter

#include "archtypes.h" // DAL
#include "common_types.h"

// Misc C-runtime library headers
#include <cmath>
Expand Down
24 changes: 18 additions & 6 deletions cl_dll/wrect.h → common/common_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,24 @@
// $NoKeywords: $
//=============================================================================

#if !defined( WRECTH )
#define WRECTH
#pragma once

typedef struct rect_s
/**
* @file
*
* Common data types
*/

struct Point
{
int left, right, top, bottom;
} wrect_t;
int x = 0;
int y = 0;
};

#endif
struct Rect
{
int left = 0;
int right = 0;
int top = 0;
int bottom = 0;
};
13 changes: 0 additions & 13 deletions common/port.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,10 @@ typedef char * LPSTR;
#define MAX_PATH PATH_MAX

#ifdef LINUX
typedef struct POINT_s
{
int x;
int y;
} POINT;
typedef void *HINSTANCE;
typedef void *HWND;
typedef void *HDC;
typedef void *HGLRC;

typedef struct RECT_s
{
int left;
int right;
int top;
int bottom;
} RECT;
#endif


Expand Down
25 changes: 13 additions & 12 deletions engine/APIProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "archtypes.h" // DAL
#include "netadr.h"
#include "Sequence.h"
#include "common_types.h"

#ifndef _WIN32
#include "enums.h"
Expand Down Expand Up @@ -223,15 +224,15 @@ typedef int (*pfnEngSrc_pfnSPR_Frames_t ) ( HSPRITE hPic );
typedef int (*pfnEngSrc_pfnSPR_Height_t ) ( HSPRITE hPic, int frame );
typedef int (*pfnEngSrc_pfnSPR_Width_t ) ( HSPRITE hPic, int frame );
typedef void (*pfnEngSrc_pfnSPR_Set_t ) ( HSPRITE hPic, int r, int g, int b );
typedef void (*pfnEngSrc_pfnSPR_Draw_t ) ( int frame, int x, int y, const struct rect_s *prc );
typedef void (*pfnEngSrc_pfnSPR_DrawHoles_t ) ( int frame, int x, int y, const struct rect_s *prc );
typedef void (*pfnEngSrc_pfnSPR_DrawAdditive_t ) ( int frame, int x, int y, const struct rect_s *prc );
typedef void (*pfnEngSrc_pfnSPR_Draw_t ) ( int frame, int x, int y, const Rect *prc );
typedef void (*pfnEngSrc_pfnSPR_DrawHoles_t ) ( int frame, int x, int y, const Rect *prc );
typedef void (*pfnEngSrc_pfnSPR_DrawAdditive_t ) ( int frame, int x, int y, const Rect *prc );
typedef void (*pfnEngSrc_pfnSPR_EnableScissor_t ) ( int x, int y, int width, int height );
typedef void (*pfnEngSrc_pfnSPR_DisableScissor_t ) ( void );
typedef struct client_sprite_s * (*pfnEngSrc_pfnSPR_GetList_t ) (const char *psz, int *piCount );
typedef void (*pfnEngSrc_pfnFillRGBA_t ) ( int x, int y, int width, int height, int r, int g, int b, int a );
typedef int (*pfnEngSrc_pfnGetScreenInfo_t ) ( struct SCREENINFO_s *pscrinfo );
typedef void (*pfnEngSrc_pfnSetCrosshair_t ) ( HSPRITE hspr, wrect_t rc, int r, int g, int b );
typedef void (*pfnEngSrc_pfnSetCrosshair_t ) ( HSPRITE hspr, Rect rc, int r, int g, int b );
typedef struct cvar_s * (*pfnEngSrc_pfnRegisterVariable_t ) ( const char *szName, const char *szValue, int flags );
typedef float (*pfnEngSrc_pfnGetCvarFloat_t ) ( const char *szName );
typedef const char* (*pfnEngSrc_pfnGetCvarString_t ) ( const char *szName );
Expand Down Expand Up @@ -319,7 +320,7 @@ typedef qboolean (*pfnEngSrc_GetPlayerUniqueID_t)(int iPlayer, char playerID
typedef int (*pfnEngSrc_GetTrackerIDForPlayer_t)(int playerSlot);
typedef int (*pfnEngSrc_GetPlayerForTrackerID_t)(int trackerID);
typedef int (*pfnEngSrc_pfnServerCmdUnreliable_t )( char *szCmdString );
typedef void (*pfnEngSrc_GetMousePos_t )(struct tagPOINT *ppt);
typedef void (*pfnEngSrc_GetMousePos_t )(Point *ppt);
typedef void (*pfnEngSrc_SetMousePos_t )(int x, int y);
typedef void (*pfnEngSrc_SetMouseEnable_t)(qboolean fEnable);
typedef struct cvar_s * (*pfnEngSrc_GetFirstCVarPtr_t)();
Expand All @@ -333,7 +334,7 @@ typedef void (*pfnEngSrc_pfnSetFilterMode_t )( int mode );
typedef void (*pfnEngSrc_pfnSetFilterColor_t )( float r, float g, float b );
typedef void (*pfnEngSrc_pfnSetFilterBrightness_t )( float brightness );
typedef sequenceEntry_s* (*pfnEngSrc_pfnSequenceGet_t )( const char *fileName, const char* entryName );
typedef void (*pfnEngSrc_pfnSPR_DrawGeneric_t )( int frame, int x, int y, const struct rect_s *prc, int src, int dest, int w, int h );
typedef void (*pfnEngSrc_pfnSPR_DrawGeneric_t )( int frame, int x, int y, const Rect *prc, int src, int dest, int w, int h );
typedef sentenceEntry_s* (*pfnEngSrc_pfnSequencePickSentence_t )( const char *sentenceName, int pickMethod, int* entryPicked );
// draw a complete string
typedef int (*pfnEngSrc_pfnDrawString_t ) ( int x, int y, const char *str, int r, int g, int b );
Expand Down Expand Up @@ -501,15 +502,15 @@ typedef void (*pfnEngDst_pfnSPR_Frames_t ) ( HSPRITE * );
typedef void (*pfnEngDst_pfnSPR_Height_t ) ( HSPRITE *, int * );
typedef void (*pfnEngDst_pfnSPR_Width_t ) ( HSPRITE *, int * );
typedef void (*pfnEngDst_pfnSPR_Set_t ) ( HSPRITE *, int *, int *, int * );
typedef void (*pfnEngDst_pfnSPR_Draw_t ) ( int *, int *, int *, const struct rect_s ** );
typedef void (*pfnEngDst_pfnSPR_DrawHoles_t ) ( int *, int *, int *, const struct rect_s ** );
typedef void (*pfnEngDst_pfnSPR_DrawAdditive_t ) ( int *, int *, int *, const struct rect_s ** );
typedef void (*pfnEngDst_pfnSPR_Draw_t ) ( int *, int *, int *, const Rect ** );
typedef void (*pfnEngDst_pfnSPR_DrawHoles_t ) ( int *, int *, int *, const Rect ** );
typedef void (*pfnEngDst_pfnSPR_DrawAdditive_t ) ( int *, int *, int *, const Rect ** );
typedef void (*pfnEngDst_pfnSPR_EnableScissor_t ) ( int *, int *, int *, int * );
typedef void (*pfnEngDst_pfnSPR_DisableScissor_t ) ( void );
typedef void (*pfnEngDst_pfnSPR_GetList_t ) ( char **, int ** );
typedef void (*pfnEngDst_pfnFillRGBA_t ) ( int *, int *, int *, int *, int *, int *, int *, int * );
typedef void (*pfnEngDst_pfnGetScreenInfo_t ) ( struct SCREENINFO_s ** );
typedef void (*pfnEngDst_pfnSetCrosshair_t ) ( HSPRITE *, struct rect_s *, int *, int *, int * );
typedef void (*pfnEngDst_pfnSetCrosshair_t ) ( HSPRITE *, Rect *, int *, int *, int * );
typedef void (*pfnEngDst_pfnRegisterVariable_t ) ( char **, char **, int * );
typedef void (*pfnEngDst_pfnGetCvarFloat_t ) ( char ** );
typedef void (*pfnEngDst_pfnGetCvarString_t ) ( char ** );
Expand Down Expand Up @@ -591,14 +592,14 @@ typedef void (*pfnEngDst_GetPlayerUniqueID_t) (int *, char **);
typedef void (*pfnEngDst_GetTrackerIDForPlayer_t) (int *);
typedef void (*pfnEngDst_GetPlayerForTrackerID_t) (int *);
typedef void (*pfnEngDst_pfnServerCmdUnreliable_t ) ( char ** );
typedef void (*pfnEngDst_GetMousePos_t ) (struct tagPOINT **);
typedef void (*pfnEngDst_GetMousePos_t ) (Point **);
typedef void (*pfnEngDst_SetMousePos_t ) (int *, int *);
typedef void (*pfnEngDst_SetMouseEnable_t ) (qboolean *);
typedef void (*pfnEngDst_pfnSetFilterMode_t) ( int * );
typedef void (*pfnEngDst_pfnSetFilterColor_t) ( float *, float *, float * );
typedef void (*pfnEngDst_pfnSetFilterBrightness_t) ( float * );
typedef void (*pfnEngDst_pfnSequenceGet_t ) ( const char**, const char** );
typedef void (*pfnEngDst_pfnSPR_DrawGeneric_t ) ( int *, int *, int *, const struct rect_s **, int *, int *, int *, int * );
typedef void (*pfnEngDst_pfnSPR_DrawGeneric_t ) ( int *, int *, int *, const Rect **, int *, int *, int *, int * );
typedef void (*pfnEngDst_pfnSequencePickSentence_t ) ( const char**, int *, int ** );
typedef void (*pfnEngDst_pfnDrawString_t ) ( int *, int *, const char *, int *, int *, int * );
typedef void (*pfnEngDst_pfnDrawStringReverse_t ) ( int *, int *, const char *, int *, int *, int * );
Expand Down
Loading

0 comments on commit aa65943

Please sign in to comment.