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

[WIP] abi2 prototype #468

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions cl_dll/hl/hl_weapons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ bool bIsMultiplayer( void )
//Just loads a v_ model.
void LoadVModel( const char *szViewModel, CBasePlayer *m_pPlayer )
{
gEngfuncs.CL_LoadModel( szViewModel, &m_pPlayer->pev->viewmodel );
int index = m_pPlayer->pev->viewmodel.ExplicitInt();
gEngfuncs.CL_LoadModel( szViewModel, &index );
m_pPlayer->pev->viewmodel = index;
}

/*
Expand Down Expand Up @@ -213,7 +215,9 @@ BOOL CBasePlayerWeapon::DefaultDeploy( const char *szViewModel, const char *szWe
if( !CanDeploy() )
return FALSE;

gEngfuncs.CL_LoadModel( szViewModel, &m_pPlayer->pev->viewmodel );
int index = m_pPlayer->pev->viewmodel.ExplicitInt();
gEngfuncs.CL_LoadModel( szViewModel, &index );
m_pPlayer->pev->viewmodel = index;

SendWeaponAnim( iAnim, skiplocal, body );

Expand Down Expand Up @@ -878,7 +882,7 @@ void HUD_WeaponsPostThink( local_state_s *from, local_state_s *to, usercmd_t *cm
}

// Copy in results of prediction code
to->client.viewmodel = player.pev->viewmodel;
to->client.viewmodel = player.pev->viewmodel.ExplicitInt();
to->client.fov = player.pev->fov;
to->client.weaponanim = player.pev->weaponanim;
to->client.m_flNextAttack = player.m_flNextAttack;
Expand Down
2 changes: 1 addition & 1 deletion cl_dll/util_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
#else
#include <math.h>
#endif

// Header file containing definition of globalvars_t and entvars_t
typedef unsigned int func_t; //
typedef int string_t; // from engine's pr_comp.h;
typedef float vec_t; // needed before including progdefs.h

//=========================================================
Expand Down
4 changes: 4 additions & 0 deletions cmake/LibraryNaming.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ else()
set(POSTFIX "")
endif()

if(CMAKE_SIZEOF_VOID_P AND NOT XASH_ARCH_ONLY_USES_ABI2)
set(POSTFIX "${POSTFIX}_st64")
endif()

message(STATUS "Library postfix: " ${POSTFIX})

set(CMAKE_RELEASE_POSTFIX ${POSTFIX})
Expand Down
36 changes: 35 additions & 1 deletion common/const.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
#pragma once
#if !defined(CONST_H)
#define CONST_H

#include <stddef.h> // ptrdiff_t

//
// Constants shared by the engine and dlls
// This header file included by engine files and DLL files.
Expand Down Expand Up @@ -735,7 +738,38 @@ enum
};

typedef unsigned int func_t;
typedef int string_t;

#if __cplusplus
class string_t
{
ptrdiff_t offset;
public:
// only construct from ptrdiff_t
string_t( ptrdiff_t offset ) : offset( offset ) {}
string_t() : offset( 0 ) {}

// as string_t sometimes used as a storage, we allow explicit conversion to an int
// as a method
int ExplicitInt()
{
return (int) offset;
}

// for null checks
operator bool() const { return offset != 0; }

// only convert to ptrdiff_t
operator ptrdiff_t() const
{
return offset;
}
#if XASH_64BIT
operator int() const = delete;
#endif
};
#else // ! __cplusplus
typedef ptrdiff_t string_t;
#endif

typedef unsigned char byte;
typedef unsigned short word;
Expand Down
20 changes: 10 additions & 10 deletions dlls/bigmomma.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ class CBigMomma : public CBaseMonster
Schedule_t *GetScheduleOfType( int Type );
void TraceAttack( entvars_t *pevAttacker, float flDamage, Vector vecDir, TraceResult *ptr, int bitsDamageType );

void NodeStart( int iszNextNode );
void NodeStart( string_t iszNextNode );
void NodeReach( void );
BOOL ShouldGoToNode( void );

Expand All @@ -191,7 +191,7 @@ class CBigMomma : public CBaseMonster
void HandleAnimEvent( MonsterEvent_t *pEvent );
void LayHeadcrab( void );

int GetNodeSequence( void )
string_t GetNodeSequence( void )
{
CBaseEntity *pTarget = m_hTargetEnt;
if( pTarget )
Expand All @@ -201,7 +201,7 @@ class CBigMomma : public CBaseMonster
return 0;
}

int GetNodePresequence( void )
string_t GetNodePresequence( void )
{
CInfoBM *pTarget = (CInfoBM *)(CBaseEntity *)m_hTargetEnt;
if( pTarget )
Expand Down Expand Up @@ -682,7 +682,7 @@ void CBigMomma::Activate( void )
Remember( bits_MEMORY_ADVANCE_NODE ); // Start 'er up
}

void CBigMomma::NodeStart( int iszNextNode )
void CBigMomma::NodeStart( string_t iszNextNode )
{
pev->netname = iszNextNode;

Expand Down Expand Up @@ -904,16 +904,16 @@ void CBigMomma::StartTask( Task_t *pTask )
case TASK_PLAY_NODE_PRESEQUENCE:
case TASK_PLAY_NODE_SEQUENCE:
{
int sequence;
string_t sequence_string;
if( pTask->iTask == TASK_PLAY_NODE_SEQUENCE )
sequence = GetNodeSequence();
sequence_string = GetNodeSequence();
else
sequence = GetNodePresequence();
sequence_string = GetNodePresequence();

ALERT( at_aiconsole, "BM: Playing node sequence %s\n", STRING( sequence ) );
if( sequence )
ALERT( at_aiconsole, "BM: Playing node sequence %s\n", STRING( sequence_string ) );
if( sequence_string )
{
sequence = LookupSequence( STRING( sequence ) );
int sequence = LookupSequence( STRING( sequence_string ) );
if( sequence != -1 )
{
pev->sequence = sequence;
Expand Down
2 changes: 1 addition & 1 deletion dlls/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ void ClientCommand( edict_t *pEntity )
{
if( g_enable_cheats->value != 0 )
{
int iszItem = ALLOC_STRING( CMD_ARGV( 1 ) ); // Make a copy of the classname
string_t iszItem = ALLOC_STRING( CMD_ARGV( 1 ) ); // Make a copy of the classname
GetClassPtr( (CBasePlayer *)pev )->GiveNamedItem( STRING( iszItem ) );
}
}
Expand Down
1 change: 0 additions & 1 deletion dlls/extdll.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ typedef int BOOL;

// Header file containing definition of globalvars_t and entvars_t
typedef unsigned int func_t;
typedef int string_t; // from engine's pr_comp.h;
typedef float vec_t; // needed before including progdefs.h

// Vector class
Expand Down
2 changes: 1 addition & 1 deletion dlls/h_cycler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ class CWeaponCycler : public CBasePlayerWeapon
void SecondaryAttack( void );
BOOL Deploy( void );
void Holster( int skiplocal = 0 );
int m_iszModel;
string_t m_iszModel;
int m_iModel;
};

Expand Down
2 changes: 1 addition & 1 deletion dlls/maprules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class CRuleEntity : public CBaseEntity
virtual int Restore( CRestore &restore );
static TYPEDESCRIPTION m_SaveData[];

void SetMaster( int iszMaster ) { m_iszMaster = iszMaster; }
void SetMaster( string_t iszMaster ) { m_iszMaster = iszMaster; }

protected:
BOOL CanFireForActivator( CBaseEntity *pActivator );
Expand Down
2 changes: 1 addition & 1 deletion dlls/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3353,7 +3353,7 @@ void CBasePlayer::GiveNamedItem( const char *pszName )
{
edict_t *pent;

int istr = MAKE_STRING( pszName );
string_t istr = MAKE_STRING( pszName );

pent = CREATE_NAMED_ENTITY( istr );
if( FNullEnt( pent ) )
Expand Down
2 changes: 1 addition & 1 deletion dlls/rpg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ void CRpg::UpdateSpot( void )
#if !CLIENT_DLL
if( m_fSpotActive )
{
if (m_pPlayer->pev->viewmodel == 0)
if( FStringNull( m_pPlayer->pev->viewmodel ))
return;

if( !m_pSpot )
Expand Down
2 changes: 1 addition & 1 deletion dlls/saverestore.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class CSave : public CSaveRestoreBuffer
void WriteTime( const char *pname, const float *value, int count ); // Save a float (timevalue)
void WriteData( const char *pname, int size, const char *pdata ); // Save a binary data block
void WriteString( const char *pname, const char *pstring ); // Save a null-terminated string
void WriteString( const char *pname, const int *stringId, int count ); // Save a null-terminated string (engine string)
void WriteString( const char *pname, const string_t *stringId, int count ); // Save a null-terminated string (engine string)
void WriteVector( const char *pname, const Vector &value ); // Save a vector
void WriteVector( const char *pname, const float *value, int count ); // Save a vector
void WritePositionVector( const char *pname, const Vector &value ); // Offset for landmark if necessary
Expand Down
8 changes: 4 additions & 4 deletions dlls/scripted.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -471,9 +471,9 @@ void CCineMonster::CineThink( void )
}

// lookup a sequence name and setup the target monster to play it
BOOL CCineMonster::StartSequence( CBaseMonster *pTarget, int iszSeq, BOOL completeOnEmpty )
BOOL CCineMonster::StartSequence( CBaseMonster *pTarget, string_t iszSeq, BOOL completeOnEmpty )
{
if( !iszSeq && completeOnEmpty )
if( FStringNull( iszSeq ) && completeOnEmpty )
{
SequenceDone( pTarget );
return FALSE;
Expand Down Expand Up @@ -503,9 +503,9 @@ BOOL CCineMonster::StartSequence( CBaseMonster *pTarget, int iszSeq, BOOL comple
// lookup a sequence name and setup the target monster to play it
// overridden for CCineAI because it's ok for them to not have an animation sequence
// for the monster to play. For a regular Scripted Sequence, that situation is an error.
BOOL CCineAI::StartSequence( CBaseMonster *pTarget, int iszSeq, BOOL completeOnEmpty )
BOOL CCineAI::StartSequence( CBaseMonster *pTarget, string_t iszSeq, BOOL completeOnEmpty )
{
if( iszSeq == 0 && completeOnEmpty )
if( FStringNull( iszSeq ) && completeOnEmpty )
{
// no sequence was provided. Just let the monster proceed, however, we still have to fire any Sequence target
// and remove any non-repeatable CineAI entities here ( because there is code elsewhere that handles those tasks, but
Expand Down
4 changes: 2 additions & 2 deletions dlls/scripted.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class CCineMonster : public CBaseMonster

void ReleaseEntity( CBaseMonster *pEntity );
void CancelScript( void );
virtual BOOL StartSequence( CBaseMonster *pTarget, int iszSeq, BOOL completeOnEmpty );
virtual BOOL StartSequence( CBaseMonster *pTarget, string_t iszSeq, BOOL completeOnEmpty );
virtual BOOL FCanOverrideState ( void );
void SequenceDone ( CBaseMonster *pMonster );
virtual void FixScriptMonsterSchedule( CBaseMonster *pMonster );
Expand Down Expand Up @@ -98,7 +98,7 @@ class CCineMonster : public CBaseMonster

class CCineAI : public CCineMonster
{
BOOL StartSequence( CBaseMonster *pTarget, int iszSeq, BOOL completeOnEmpty );
BOOL StartSequence( CBaseMonster *pTarget, string_t iszSeq, BOOL completeOnEmpty );
void PossessEntity( void );
BOOL FCanOverrideState ( void );
virtual void FixScriptMonsterSchedule( CBaseMonster *pMonster );
Expand Down
2 changes: 1 addition & 1 deletion dlls/triggers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ void CMultiManager::Spawn( void )
if( m_flTargetDelay[i] < m_flTargetDelay[i - 1] )
{
// Swap out of order elements
int name = m_iTargetName[i];
string_t name = m_iTargetName[i];
float delay = m_flTargetDelay[i];
m_iTargetName[i] = m_iTargetName[i - 1];
m_flTargetDelay[i] = m_flTargetDelay[i - 1];
Expand Down
2 changes: 1 addition & 1 deletion dlls/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1827,7 +1827,7 @@ void CSave::WriteString( const char *pname, const char *pdata )
#endif
}

void CSave::WriteString( const char *pname, const int *stringId, int count )
void CSave::WriteString( const char *pname, const string_t *stringId, int count )
{
int i, size;
#if TOKENIZE
Expand Down
20 changes: 8 additions & 12 deletions dlls/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,16 @@ inline void MESSAGE_BEGIN( int msg_dest, int msg_type, const float *pOrigin, ent
extern globalvars_t *gpGlobals;

// Use this instead of ALLOC_STRING on constant strings
#define STRING(offset) (const char *)(gpGlobals->pStringBase + (int)offset)
inline const char *STRING( string_t offset )
{
return gpGlobals->pStringBase + (ptrdiff_t)offset;
}

#if !XASH_64BIT || CLIENT_DLL
#define MAKE_STRING(str) ((int)(long int)str - (int)(long int)STRING(0))
#else
static inline int MAKE_STRING(const char *szValue)
inline string_t MAKE_STRING( const char *szValue )
{
long long ptrdiff = szValue - STRING(0);
if( ptrdiff > INT_MAX || ptrdiff < INT_MIN )
return ALLOC_STRING( szValue );
else
return (int)ptrdiff;
ptrdiff_t ptrdiff = szValue - STRING( 0 );
return string_t( ptrdiff );
}
#endif

inline edict_t *FIND_ENTITY_BY_CLASSNAME(edict_t *entStart, const char *pszName)
{
Expand Down Expand Up @@ -166,7 +162,7 @@ inline BOOL FNullEnt(entvars_t* pev) { return pev == NULL || FNullEnt(OFFSET(

// Testing strings for nullity
#define iStringNull 0
inline BOOL FStringNull(int iString) { return iString == iStringNull; }
inline BOOL FStringNull(string_t iString) { return (ptrdiff_t)iString == iStringNull; }

#define cchMapNameMost 32

Expand Down
4 changes: 2 additions & 2 deletions dlls/weapons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ MULTIDAMAGE gMultiDamage;
// you the maximum amount of that type of ammunition that a
// player can carry.
//=========================================================
int MaxAmmoCarry( int iszName )
int MaxAmmoCarry( string_t iszName )
{
for( int i = 0; i < MAX_WEAPONS; i++ )
{
Expand Down Expand Up @@ -1465,7 +1465,7 @@ BOOL CWeaponBox::PackWeapon( CBasePlayerItem *pWeapon )
//=========================================================
// CWeaponBox - PackAmmo
//=========================================================
BOOL CWeaponBox::PackAmmo( int iszName, int iCount )
BOOL CWeaponBox::PackAmmo( string_t iszName, int iCount )
{
int iMaxCarry;

Expand Down
2 changes: 1 addition & 1 deletion dlls/weapons.h
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ class CWeaponBox : public CBaseEntity

BOOL HasWeapon( CBasePlayerItem *pCheckItem );
BOOL PackWeapon( CBasePlayerItem *pWeapon );
BOOL PackAmmo( int iszName, int iCount );
BOOL PackAmmo( string_t iszName, int iCount );

CBasePlayerItem *m_rgpPlayerItems[MAX_ITEM_TYPES];// one slot for each

Expand Down
6 changes: 3 additions & 3 deletions engine/eiface.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ typedef struct enginefuncs_s
void (*pfnAngleVectors)( const float *rgflVector, float *forward, float *right, float *up );
edict_t* (*pfnCreateEntity)( void );
void (*pfnRemoveEntity)( edict_t* e );
edict_t* (*pfnCreateNamedEntity)( int className );
edict_t* (*pfnCreateNamedEntity)( string_t className );
void (*pfnMakeStatic)( edict_t *ent );
int (*pfnEntIsOnFloor)( edict_t *e );
int (*pfnDropToFloor)( edict_t* e );
Expand Down Expand Up @@ -160,8 +160,8 @@ typedef struct enginefuncs_s
void* (*pfnPvAllocEntPrivateData)( edict_t *pEdict, int cb );
void* (*pfnPvEntPrivateData)( edict_t *pEdict );
void (*pfnFreeEntPrivateData)( edict_t *pEdict );
const char *(*pfnSzFromIndex)( int iString );
int (*pfnAllocString)( const char *szValue );
const char *(*pfnSzFromIndex)( string_t iString );
string_t (*pfnAllocString)( const char *szValue );
struct entvars_s *(*pfnGetVarsOfEnt)( edict_t *pEdict );
edict_t* (*pfnPEntityOfEntOffset)( int iEntOffset );
int (*pfnEntOffsetOfPEntity)( const edict_t *pEdict );
Expand Down
6 changes: 3 additions & 3 deletions engine/progdefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ typedef struct entvars_s
int modelindex;

string_t model;
int viewmodel; // player's viewmodel
int weaponmodel; // what other players see
string_t viewmodel; // player's viewmodel
string_t weaponmodel; // what other players see

vec3_t absmin; // BB max translated to world coord
vec3_t absmax; // BB max translated to world coord
Expand Down Expand Up @@ -144,7 +144,7 @@ typedef struct entvars_s
int flags;

int colormap; // lowbyte topcolor, highbyte bottomcolor
int team;
string_t team;

float max_health;
float teleport_time;
Expand Down
3 changes: 3 additions & 0 deletions scripts/waifulib/library_naming.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,7 @@ def configure(conf):
else:
conf.env.POSTFIX = ''

if conf.env.DEST_SIZEOF_VOID_P == 8 and not conf.env.XASH_ARCH_USES_ONLY_ABI2:
conf.env.POSTFIX += '_st64'

conf.end_msg(conf.env.POSTFIX)