code refactoring, still testing
some fixes all over the place fixed all warnings from clang
This commit is contained in:
parent
5ff6b9ecde
commit
bc2e57a7a8
22 changed files with 984 additions and 1051 deletions
116
include/core.h
116
include/core.h
|
|
@ -398,32 +398,6 @@ enum GameStartMessage
|
|||
GSM_SAY_TEAM = 10001
|
||||
};
|
||||
|
||||
// netmessage functions
|
||||
enum NetworkMessage
|
||||
{
|
||||
NETMSG_UNDEFINED = 0,
|
||||
NETMSG_VGUI = 1,
|
||||
NETMSG_SHOWMENU = 2,
|
||||
NETMSG_WEAPONLIST = 3,
|
||||
NETMSG_CURWEAPON = 4,
|
||||
NETMSG_AMMOX = 5,
|
||||
NETMSG_AMMOPICKUP = 6,
|
||||
NETMSG_DAMAGE = 7,
|
||||
NETMSG_MONEY = 8,
|
||||
NETMSG_STATUSICON = 9,
|
||||
NETMSG_DEATH = 10,
|
||||
NETMSG_SCREENFADE = 11,
|
||||
NETMSG_HLTV = 12,
|
||||
NETMSG_TEXTMSG = 13,
|
||||
NETMSG_SCOREINFO = 14,
|
||||
NETMSG_BARTIME = 15,
|
||||
NETMSG_SENDAUDIO = 17,
|
||||
NETMSG_SAYTEXT = 18,
|
||||
NETMSG_BOTVOICE = 19,
|
||||
NETMSG_RESETHUD = 20,
|
||||
NETMSG_NUM = 21
|
||||
};
|
||||
|
||||
// sensing states
|
||||
enum SensingState
|
||||
{
|
||||
|
|
@ -553,6 +527,7 @@ const int MAX_WEAPONS = 32;
|
|||
const int NUM_WEAPONS = 26;
|
||||
const int MAX_COLLIDE_MOVES = 3;
|
||||
const int MAX_ENGINE_PLAYERS = 32; // we can have 64 players with xash
|
||||
const int MAX_PRINT_BUFFER = 1024;
|
||||
|
||||
// weapon masks
|
||||
const int WEAPON_PRIMARY = ((1 << WEAPON_XM1014) | (1 <<WEAPON_M3) | (1 << WEAPON_MAC10) | (1 << WEAPON_UMP45) | (1 << WEAPON_MP5) | (1 << WEAPON_TMP) | (1 << WEAPON_P90) | (1 << WEAPON_AUG) | (1 << WEAPON_M4A1) | (1 << WEAPON_SG552) | (1 << WEAPON_AK47) | (1 << WEAPON_SCOUT) | (1 << WEAPON_SG550) | (1 << WEAPON_AWP) | (1 << WEAPON_G3SG1) | (1 << WEAPON_M249) | (1 << WEAPON_FAMAS) | (1 << WEAPON_GALIL));
|
||||
|
|
@ -598,13 +573,6 @@ struct ChatterItem
|
|||
float repeatTime;
|
||||
};
|
||||
|
||||
// language config structure definition
|
||||
struct LanguageItem
|
||||
{
|
||||
const char *original; // original string
|
||||
const char *translated; // string to replace for
|
||||
};
|
||||
|
||||
struct WeaponSelect
|
||||
{
|
||||
int id; // the weapon id value
|
||||
|
|
@ -766,7 +734,7 @@ private:
|
|||
float m_blindRecognizeTime; // time to recognize enemy
|
||||
float m_itemCheckTime; // time next search for items needs to be done
|
||||
PickupType m_pickupType; // type of entity which needs to be used/picked up
|
||||
Vector m_breakable; // origin of breakable
|
||||
Vector m_breakableOrigin; // origin of breakable
|
||||
|
||||
edict_t *m_pickupItem; // pointer to entity of item to use/pickup
|
||||
edict_t *m_itemIgnore; // pointer to entity to ignore for pickup
|
||||
|
|
@ -824,7 +792,7 @@ private:
|
|||
bool m_wantsToFire; // bot needs consider firing
|
||||
float m_shootAtDeadTime; // time to shoot at dying players
|
||||
edict_t *m_avoidGrenade; // pointer to grenade entity to avoid
|
||||
char m_needAvoidGrenade; // which direction to strafe away
|
||||
int m_needAvoidGrenade; // which direction to strafe away
|
||||
|
||||
float m_followWaitTime; // wait to follow time
|
||||
edict_t *m_targetEntity; // the entity that the bot is trying to reach
|
||||
|
|
@ -1194,7 +1162,7 @@ public:
|
|||
void Think (void);
|
||||
|
||||
/// the things that can be executed while skipping frames
|
||||
void ThinkDelayed (void);
|
||||
void ThinkFrame (void);
|
||||
|
||||
void DisplayDebugOverlay (void);
|
||||
void NewRound (void);
|
||||
|
|
@ -1218,7 +1186,7 @@ public:
|
|||
inline TaskID GetTaskId (void) { return GetTask ()->id; };
|
||||
|
||||
void TakeDamage (edict_t *inflictor, int damage, int armor, int bits);
|
||||
void TakeBlinded (const Vector &fade, int alpha);
|
||||
void TakeBlinded (int r, int g, int b, int alpha);
|
||||
|
||||
void DiscardWeaponForUser (edict_t *user, bool discardC4);
|
||||
|
||||
|
|
@ -1254,7 +1222,7 @@ public:
|
|||
};
|
||||
|
||||
// manager class
|
||||
class BotManager
|
||||
class BotManager : public Singleton <BotManager>
|
||||
{
|
||||
private:
|
||||
Array <CreateQueue> m_creationTab; // bot creation tab
|
||||
|
|
@ -1349,46 +1317,9 @@ public:
|
|||
void SendDeathMsgFix (void);
|
||||
};
|
||||
|
||||
// texts localizer
|
||||
class Localizer
|
||||
{
|
||||
public:
|
||||
Array <LanguageItem> m_langTab;
|
||||
|
||||
public:
|
||||
Localizer (void) { m_langTab.RemoveAll (); }
|
||||
~Localizer (void) { m_langTab.RemoveAll (); }
|
||||
|
||||
char *TranslateInput (const char *input);
|
||||
void Destroy (void);
|
||||
};
|
||||
|
||||
// netmessage handler class
|
||||
class NetworkMsg
|
||||
{
|
||||
private:
|
||||
Bot *m_bot;
|
||||
int m_state;
|
||||
int m_message;
|
||||
int m_registerdMessages[NETMSG_NUM];
|
||||
|
||||
public:
|
||||
NetworkMsg (void);
|
||||
~NetworkMsg (void) { };
|
||||
|
||||
void Execute (void *p);
|
||||
inline void Reset (void) { m_message = NETMSG_UNDEFINED; m_state = 0; m_bot = NULL; };
|
||||
void HandleMessageIfRequired (int messageType, int requiredType);
|
||||
|
||||
inline void SetMessage (int message) { m_message = message; }
|
||||
inline void SetBot (Bot *bot) { m_bot = bot; }
|
||||
|
||||
inline int GetId (int messageType) { return m_registerdMessages[messageType]; }
|
||||
inline void SetId (int messageType, int messsageIdentifier) { m_registerdMessages[messageType] = messsageIdentifier; }
|
||||
};
|
||||
|
||||
// waypoint operation class
|
||||
class Waypoint
|
||||
class Waypoint : public Singleton <Waypoint>
|
||||
{
|
||||
friend class Bot;
|
||||
|
||||
|
|
@ -1409,7 +1340,7 @@ private:
|
|||
int m_lastJumpWaypoint;
|
||||
int m_visibilityIndex;
|
||||
Vector m_lastWaypoint;
|
||||
byte m_visLUT[MAX_WAYPOINTS][MAX_WAYPOINTS / 4];
|
||||
unsigned char m_visLUT[MAX_WAYPOINTS][MAX_WAYPOINTS / 4];
|
||||
|
||||
float m_pathDisplayTime;
|
||||
float m_arrowDisplayTime;
|
||||
|
|
@ -1440,12 +1371,12 @@ public:
|
|||
void InitVisibilityTab (void);
|
||||
|
||||
void InitTypes (void);
|
||||
void AddPath (short int addIndex, short int pathIndex, float distance);
|
||||
void AddPath (int addIndex, int pathIndex, float distance);
|
||||
|
||||
int GetFacingIndex (void);
|
||||
int FindFarest (const Vector &origin, float maxDistance = 32.0);
|
||||
int FindNearest (const Vector &origin, float minDistance = 9999.0f, int flags = -1);
|
||||
void FindInRadius (Array <int> &radiusHolder, float radius, const Vector &origin, int maxCount = -1);
|
||||
void FindInRadius (Array <int> &holder, float radius, const Vector &origin, int maxCount = -1);
|
||||
|
||||
void Add (int flags, const Vector &waypointOrigin = Vector::GetZero ());
|
||||
void Delete (void);
|
||||
|
|
@ -1466,6 +1397,7 @@ public:
|
|||
|
||||
bool Load (void);
|
||||
void Save (void);
|
||||
void CleanupPathMemory (void);
|
||||
|
||||
bool Reachable (Bot *bot, int index);
|
||||
bool IsNodeReachable (const Vector &src, const Vector &destination);
|
||||
|
|
@ -1492,25 +1424,11 @@ public:
|
|||
void SetGoalVisited (int index);
|
||||
void ClearVisitedGoals (void);
|
||||
|
||||
inline const Vector &GetBombPosition (void)
|
||||
{
|
||||
return m_foundBombOrigin;
|
||||
}
|
||||
const char *GetDataDir (void);
|
||||
|
||||
void SetBombPosition (bool shouldReset = false);
|
||||
String CheckSubfolderFile (void);
|
||||
|
||||
// quick access
|
||||
inline Path *operator [] (int index)
|
||||
{
|
||||
extern int g_numWaypoints;
|
||||
|
||||
if (index < 0 || index >= g_numWaypoints)
|
||||
assert (0);
|
||||
|
||||
return GetPath (index);
|
||||
}
|
||||
void SetBombPosition (bool shouldReset = false);
|
||||
inline const Vector &GetBombPosition (void) { return m_foundBombOrigin; }
|
||||
|
||||
// free's socket handle
|
||||
void CloseSocketHandle (int sock);
|
||||
|
|
@ -1522,11 +1440,9 @@ public:
|
|||
#include <engine.h>
|
||||
|
||||
// expose bot super-globals
|
||||
extern NetworkMsg netmsg;
|
||||
extern Localizer locale;
|
||||
extern Waypoint waypoints;
|
||||
extern BotManager bots;
|
||||
extern Engine engine;
|
||||
#define waypoints Waypoint::GetReference ()
|
||||
#define engine Engine::GetReference ()
|
||||
#define bots BotManager::GetReference ()
|
||||
|
||||
// prototypes of bot functions...
|
||||
extern int GetWeaponReturn (bool isString, const char *weaponAlias, int weaponIndex = -1);
|
||||
|
|
|
|||
|
|
@ -2303,7 +2303,7 @@ public:
|
|||
char buffer[1024];
|
||||
|
||||
va_start (ap, fmt);
|
||||
vsprintf (buffer, fmt, ap);
|
||||
vsnprintf (buffer, sizeof (buffer) - 1, fmt, ap);
|
||||
va_end (ap);
|
||||
|
||||
Append (buffer);
|
||||
|
|
@ -2374,7 +2374,7 @@ public:
|
|||
char buffer[1024];
|
||||
|
||||
va_start (ap, fmt);
|
||||
vsprintf (buffer, fmt, ap);
|
||||
vsnprintf (buffer, sizeof (buffer) - 1, fmt, ap);
|
||||
va_end (ap);
|
||||
|
||||
Assign (buffer);
|
||||
|
|
@ -3311,46 +3311,23 @@ public:
|
|||
// Returns:
|
||||
// None
|
||||
//
|
||||
static inline void TrimExternalBuffer (char *string)
|
||||
static inline void TrimExternalBuffer (char *str)
|
||||
{
|
||||
char *ptr = string;
|
||||
int pos = 0;
|
||||
char *dest = str;
|
||||
|
||||
int length = 0, toggleFlag = 0, increment = 0;
|
||||
int i = 0;
|
||||
while (str[pos] <= ' ' && str[pos] > 0)
|
||||
pos++;
|
||||
|
||||
while (*ptr++)
|
||||
length++;
|
||||
|
||||
for (i = length - 1; i >= 0; i--)
|
||||
while (str[pos])
|
||||
{
|
||||
if (!isspace (string[i]))
|
||||
break;
|
||||
else
|
||||
{
|
||||
string[i] = 0;
|
||||
length--;
|
||||
}
|
||||
*(dest++) = str[pos];
|
||||
pos++;
|
||||
}
|
||||
*(dest--) = '\0';
|
||||
|
||||
for (i = 0; i < length; i++)
|
||||
{
|
||||
if (isspace (string[i]) && !toggleFlag)
|
||||
{
|
||||
increment++;
|
||||
|
||||
if (increment + i < length)
|
||||
string[i] = string[increment + i];
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!toggleFlag)
|
||||
toggleFlag = 1;
|
||||
|
||||
if (increment)
|
||||
string[i] = string[increment + i];
|
||||
}
|
||||
}
|
||||
string[length] = 0;
|
||||
while (dest >= str && *dest <= ' ' && *dest > 0)
|
||||
*(dest--) = '\0';
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -3694,10 +3671,9 @@ public:
|
|||
static MF_Unloader Unloader;
|
||||
|
||||
protected:
|
||||
String m_fileName;
|
||||
int m_fileSize;
|
||||
int m_filePos;
|
||||
unsigned char *m_fileBuffer;
|
||||
int m_size;
|
||||
int m_pos;
|
||||
unsigned char *m_buffer;
|
||||
|
||||
//
|
||||
// Group: (Con/De)structors
|
||||
|
|
@ -3710,11 +3686,10 @@ public:
|
|||
//
|
||||
MemoryFile (void)
|
||||
{
|
||||
m_fileSize = 0;
|
||||
m_filePos = 0;
|
||||
m_size = 0;
|
||||
m_pos = 0;
|
||||
|
||||
m_fileBuffer = NULL;
|
||||
m_fileName.Empty ();
|
||||
m_buffer = NULL;
|
||||
}
|
||||
|
||||
//
|
||||
|
|
@ -3723,11 +3698,10 @@ public:
|
|||
//
|
||||
MemoryFile (const String &fileName)
|
||||
{
|
||||
m_fileSize = 0;
|
||||
m_filePos = 0;
|
||||
m_size = 0;
|
||||
m_pos = 0;
|
||||
|
||||
m_fileBuffer = NULL;
|
||||
m_fileName.Empty ();
|
||||
m_buffer = NULL;
|
||||
|
||||
Open (fileName);
|
||||
}
|
||||
|
|
@ -3751,18 +3725,17 @@ public:
|
|||
// Returns:
|
||||
// True if operation succeeded, false otherwise.
|
||||
//
|
||||
bool Open (const String &fileName)
|
||||
bool Open (const char *fileName)
|
||||
{
|
||||
if (fileName.IsEmpty () || Loader == NULL)
|
||||
if (!Loader)
|
||||
return false;
|
||||
|
||||
m_fileSize = 0;
|
||||
m_filePos = 0;
|
||||
m_fileName = fileName;
|
||||
m_size = 0;
|
||||
m_pos = 0;
|
||||
|
||||
m_fileBuffer = Loader (fileName.GetBuffer (), &m_fileSize);
|
||||
m_buffer = Loader (fileName, &m_size);
|
||||
|
||||
if (m_fileBuffer == NULL || m_fileSize < 0)
|
||||
if (m_buffer == NULL || m_size < 0)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
@ -3775,13 +3748,12 @@ public:
|
|||
void Close (void)
|
||||
{
|
||||
if (Unloader != NULL)
|
||||
Unloader (m_fileBuffer);
|
||||
Unloader (m_buffer);
|
||||
|
||||
m_fileSize = 0;
|
||||
m_filePos = 0;
|
||||
m_size = 0;
|
||||
m_pos = 0;
|
||||
|
||||
m_fileBuffer = NULL;
|
||||
m_fileName.Empty ();
|
||||
m_buffer = NULL;
|
||||
}
|
||||
|
||||
//
|
||||
|
|
@ -3793,11 +3765,11 @@ public:
|
|||
//
|
||||
int GetChar (void)
|
||||
{
|
||||
if (m_fileBuffer == NULL || m_filePos >= m_fileSize)
|
||||
if (m_buffer == NULL || m_pos >= m_size)
|
||||
return -1;
|
||||
|
||||
int readCh = m_fileBuffer[m_filePos];
|
||||
m_filePos++;
|
||||
int readCh = m_buffer[m_pos];
|
||||
m_pos++;
|
||||
|
||||
return readCh;
|
||||
}
|
||||
|
|
@ -3815,41 +3787,41 @@ public:
|
|||
//
|
||||
char *GetBuffer (char *buffer, int count)
|
||||
{
|
||||
if (m_fileBuffer == NULL || m_filePos >= m_fileSize)
|
||||
if (m_buffer == NULL || m_pos >= m_size)
|
||||
return NULL;
|
||||
|
||||
int lineStartOffset = m_filePos;
|
||||
int lineEndOffset = m_fileSize - 1;
|
||||
int start = m_pos;
|
||||
int end = m_size - 1;
|
||||
|
||||
if (m_fileSize - m_filePos > count - 1)
|
||||
lineEndOffset = m_filePos + count - 1;
|
||||
if (m_size - m_pos > count - 1)
|
||||
end = m_pos + count - 1;
|
||||
|
||||
while (m_filePos < lineEndOffset)
|
||||
while (m_pos < end)
|
||||
{
|
||||
if (m_fileBuffer[m_filePos] == 0x0a)
|
||||
lineEndOffset = m_filePos;
|
||||
if (m_buffer[m_pos] == 0x0a)
|
||||
end = m_pos;
|
||||
|
||||
m_filePos++;
|
||||
m_pos++;
|
||||
}
|
||||
|
||||
if (m_filePos == lineStartOffset)
|
||||
if (m_pos == start)
|
||||
return NULL;
|
||||
|
||||
int pos = lineStartOffset;
|
||||
int pos = start;
|
||||
|
||||
for (; pos <= lineEndOffset; pos++)
|
||||
buffer[pos - lineStartOffset] = m_fileBuffer[pos];
|
||||
for (; pos <= end; pos++)
|
||||
buffer[pos - start] = m_buffer[pos];
|
||||
|
||||
if (buffer[pos - lineStartOffset - 2] == 0x0d)
|
||||
if (buffer[pos - start - 2] == 0x0d)
|
||||
{
|
||||
buffer[pos - lineStartOffset - 2] = '\n';
|
||||
buffer[pos - start - 2] = '\n';
|
||||
pos--;
|
||||
}
|
||||
|
||||
if (buffer[pos - lineStartOffset - 1] == 0x0d || buffer[pos - lineStartOffset - 1] == 0x0a)
|
||||
buffer[pos - lineStartOffset - 1] = '\n';
|
||||
if (buffer[pos - start - 1] == 0x0d || buffer[pos - start - 1] == 0x0a)
|
||||
buffer[pos - start - 1] = '\n';
|
||||
|
||||
buffer[pos - lineStartOffset] = 0;
|
||||
buffer[pos - start] = 0;
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
|
@ -3868,16 +3840,13 @@ public:
|
|||
//
|
||||
int Read (void *buffer, int size, int count = 1)
|
||||
{
|
||||
if (m_fileBuffer == NULL || m_filePos >= m_fileSize)
|
||||
if (!m_buffer|| m_pos >= m_size || buffer == NULL || !size || !count)
|
||||
return 0;
|
||||
|
||||
if (buffer == NULL || size == 0 || count == 0 || m_fileBuffer == NULL)
|
||||
return 0;
|
||||
int blocksRead = min ((m_size - m_pos) / size, count) * size;
|
||||
|
||||
int blocksRead = min ((m_fileSize - m_filePos) / size, count);
|
||||
|
||||
memcpy (buffer, &m_fileBuffer[m_filePos], blocksRead * size);
|
||||
m_filePos += blocksRead * size;
|
||||
memcpy (buffer, &m_buffer[m_pos], blocksRead);
|
||||
m_pos += blocksRead;
|
||||
|
||||
return blocksRead;
|
||||
}
|
||||
|
|
@ -3895,29 +3864,29 @@ public:
|
|||
//
|
||||
bool Seek (long offset, int origin)
|
||||
{
|
||||
if (m_fileBuffer == NULL || m_filePos >= m_fileSize)
|
||||
if (m_buffer == NULL || m_pos >= m_size)
|
||||
return false;
|
||||
|
||||
if (origin == SEEK_SET)
|
||||
{
|
||||
if (offset >= m_fileSize)
|
||||
if (offset >= m_size)
|
||||
return false;
|
||||
|
||||
m_filePos = offset;
|
||||
m_pos = offset;
|
||||
}
|
||||
else if (origin == SEEK_END)
|
||||
{
|
||||
if (offset >= m_fileSize)
|
||||
if (offset >= m_size)
|
||||
return false;
|
||||
|
||||
m_filePos = m_fileSize - offset;
|
||||
m_pos = m_size - offset;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_filePos + offset >= m_fileSize)
|
||||
if (m_pos + offset >= m_size)
|
||||
return false;
|
||||
|
||||
m_filePos += offset;
|
||||
m_pos += offset;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
@ -3931,7 +3900,7 @@ public:
|
|||
//
|
||||
int GetSize (void)
|
||||
{
|
||||
return m_fileSize;
|
||||
return m_size;
|
||||
}
|
||||
|
||||
//
|
||||
|
|
@ -3943,7 +3912,7 @@ public:
|
|||
//
|
||||
bool IsValid (void)
|
||||
{
|
||||
return m_fileBuffer != NULL && m_fileSize > 0;
|
||||
return m_buffer != NULL && m_size > 0;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -3953,63 +3922,9 @@ public:
|
|||
//
|
||||
typedef Array <const String &> StrVec;
|
||||
|
||||
//
|
||||
// Class: Exception
|
||||
// Simple exception raiser.
|
||||
//
|
||||
class Exception
|
||||
{
|
||||
private:
|
||||
String m_exceptionText;
|
||||
String m_fileName;
|
||||
int m_line;
|
||||
|
||||
//
|
||||
// Group: (Con/De)structors
|
||||
//
|
||||
public:
|
||||
|
||||
//
|
||||
// Function: Exception
|
||||
// Default exception constructor.
|
||||
//
|
||||
// Parameters:
|
||||
// exceptionText - Text to throw.
|
||||
// fileName - Debug file name.
|
||||
// line - Debug line number.
|
||||
//
|
||||
Exception (String exceptionText, String fileName = "(no)", int line = -1) : m_exceptionText (exceptionText), m_fileName (fileName), m_line (line) { }
|
||||
|
||||
//
|
||||
// Function: ~Exception
|
||||
// Default exception destructor.
|
||||
//
|
||||
virtual ~Exception (void) { };
|
||||
|
||||
//
|
||||
// Group: Functions
|
||||
//
|
||||
public:
|
||||
|
||||
//
|
||||
// Function: GetDescription
|
||||
// Gets the description from throw object.
|
||||
//
|
||||
// Returns:
|
||||
// Exception text.
|
||||
//
|
||||
inline const String &GetDescription (void)
|
||||
{
|
||||
static String result;
|
||||
|
||||
if (m_fileName != "(no)" && m_line != -1)
|
||||
result.AssignFormat ("Exception: %s at %s:%i", m_exceptionText.GetBuffer (), m_fileName.GetBuffer (), m_line);
|
||||
else
|
||||
result = m_exceptionText;
|
||||
|
||||
return result;
|
||||
}
|
||||
};
|
||||
#ifndef FORCEINLINE
|
||||
#define FORCEINLINE inline
|
||||
#endif
|
||||
|
||||
//
|
||||
// Class: Singleton
|
||||
|
|
@ -4034,6 +3949,10 @@ protected:
|
|||
//
|
||||
virtual ~Singleton (void) { }
|
||||
|
||||
private:
|
||||
Singleton (Singleton const &);
|
||||
void operator = (Singleton const &);
|
||||
|
||||
public:
|
||||
|
||||
//
|
||||
|
|
@ -4044,7 +3963,7 @@ public:
|
|||
// Object pointer.
|
||||
//
|
||||
//
|
||||
static inline T *GetObject (void)
|
||||
static FORCEINLINE T *GetObject (void)
|
||||
{
|
||||
static T reference;
|
||||
return &reference;
|
||||
|
|
@ -4058,7 +3977,7 @@ public:
|
|||
// Object reference.
|
||||
//
|
||||
//
|
||||
static inline T &GetReference (void)
|
||||
static FORCEINLINE T &GetReference (void)
|
||||
{
|
||||
static T reference;
|
||||
return reference;
|
||||
|
|
|
|||
129
include/engine.h
129
include/engine.h
|
|
@ -38,10 +38,36 @@ enum VarType
|
|||
VT_NOREGISTER
|
||||
};
|
||||
|
||||
// need since we don't want to use Singleton on engine class
|
||||
class ConVarWrapper : public Singleton <ConVarWrapper>
|
||||
// netmessage functions
|
||||
enum NetMsgId
|
||||
{
|
||||
private:
|
||||
NETMSG_UNDEFINED = -1,
|
||||
NETMSG_VGUI = 1,
|
||||
NETMSG_SHOWMENU = 2,
|
||||
NETMSG_WEAPONLIST = 3,
|
||||
NETMSG_CURWEAPON = 4,
|
||||
NETMSG_AMMOX = 5,
|
||||
NETMSG_AMMOPICKUP = 6,
|
||||
NETMSG_DAMAGE = 7,
|
||||
NETMSG_MONEY = 8,
|
||||
NETMSG_STATUSICON = 9,
|
||||
NETMSG_DEATH = 10,
|
||||
NETMSG_SCREENFADE = 11,
|
||||
NETMSG_HLTV = 12,
|
||||
NETMSG_TEXTMSG = 13,
|
||||
NETMSG_SCOREINFO = 14,
|
||||
NETMSG_BARTIME = 15,
|
||||
NETMSG_SENDAUDIO = 17,
|
||||
NETMSG_SAYTEXT = 18,
|
||||
NETMSG_BOTVOICE = 19,
|
||||
NETMSG_NUM = 21
|
||||
};
|
||||
|
||||
// provides utility functions to not call original engine (less call-cost)
|
||||
class Engine : public Singleton <Engine>
|
||||
{
|
||||
public:
|
||||
// variable reg pair
|
||||
struct VarPair
|
||||
{
|
||||
VarType type;
|
||||
|
|
@ -49,16 +75,23 @@ private:
|
|||
bool regMissing;
|
||||
class ConVar *self;
|
||||
};
|
||||
Array <VarPair> m_regs;
|
||||
|
||||
public:
|
||||
void RegisterVariable (const char *variable, const char *value, VarType varType, bool regMissing, ConVar *self);
|
||||
void PushRegisteredConVarsToEngine (bool gameVars = false);
|
||||
};
|
||||
// translation pair
|
||||
struct TranslatorPair
|
||||
{
|
||||
const char *original;
|
||||
const char *translated;
|
||||
};
|
||||
|
||||
// network message block
|
||||
struct MessageBlock
|
||||
{
|
||||
int bot;
|
||||
int state;
|
||||
int msg;
|
||||
int regMsgs[NETMSG_NUM];
|
||||
};
|
||||
|
||||
// provides utility functions to not call original engine (less call-cost)
|
||||
class Engine
|
||||
{
|
||||
private:
|
||||
short m_drawModels[DRAW_NUM];
|
||||
|
||||
|
|
@ -70,6 +103,16 @@ private:
|
|||
edict_t *m_startEntity;
|
||||
edict_t *m_localEntity;
|
||||
|
||||
Array <VarPair> m_cvars;
|
||||
Array <TranslatorPair> m_language;
|
||||
|
||||
MessageBlock m_msgBlock;
|
||||
|
||||
public:
|
||||
Engine (void);
|
||||
|
||||
~Engine (void);
|
||||
|
||||
// public functions
|
||||
public:
|
||||
|
||||
|
|
@ -124,6 +167,21 @@ public:
|
|||
// sends bot command
|
||||
void IssueBotCommand (edict_t *ent, const char *fmt, ...);
|
||||
|
||||
// adds cvar to registration stack
|
||||
void PushVariableToStack (const char *variable, const char *value, VarType varType, bool regMissing, ConVar *self);
|
||||
|
||||
// sends local registration stack for engine registration
|
||||
void PushRegisteredConVarsToEngine (bool gameVars = false);
|
||||
|
||||
// translates bot message into needed language
|
||||
char *TraslateMessage (const char *input);
|
||||
|
||||
// cleanup translator resources
|
||||
void TerminateTranslator (void);
|
||||
|
||||
// do actual network message processing
|
||||
void ProcessMesageCapture (void *ptr);
|
||||
|
||||
// public inlines
|
||||
public:
|
||||
|
||||
|
|
@ -168,21 +226,25 @@ public:
|
|||
return m_argumentCount;
|
||||
}
|
||||
|
||||
// gets edict pointer out of entity index
|
||||
inline edict_t *EntityOfIndex (const int index)
|
||||
{
|
||||
return static_cast <edict_t *> (m_startEntity + index);
|
||||
};
|
||||
|
||||
// gets edict index out of it's pointer
|
||||
inline int IndexOfEntity (const edict_t *ent)
|
||||
{
|
||||
return static_cast <int> (ent - m_startEntity);
|
||||
};
|
||||
|
||||
// verify entity isn't null
|
||||
inline bool IsNullEntity (const edict_t *ent)
|
||||
{
|
||||
return !ent || !IndexOfEntity (ent);
|
||||
}
|
||||
|
||||
// gets the player team
|
||||
inline int GetTeam (edict_t *ent)
|
||||
{
|
||||
extern Client g_clients[MAX_ENGINE_PLAYERS];
|
||||
|
|
@ -194,6 +256,51 @@ public:
|
|||
#endif
|
||||
}
|
||||
|
||||
// adds translation pair from config
|
||||
inline void PushTranslationPair (const TranslatorPair &lang)
|
||||
{
|
||||
m_language.Push (lang);
|
||||
}
|
||||
|
||||
// resets the message capture mechanism
|
||||
inline void ResetMessageCapture (void)
|
||||
{
|
||||
m_msgBlock.msg = NETMSG_UNDEFINED;
|
||||
m_msgBlock.state = 0;
|
||||
m_msgBlock.bot = 0;
|
||||
};
|
||||
|
||||
// sets the currently executed message
|
||||
inline void SetOngoingMessageId (int message)
|
||||
{
|
||||
m_msgBlock.msg = message;
|
||||
}
|
||||
|
||||
// set the bot entity that receive this message
|
||||
inline void SetOngoingMessageReceiver (int id)
|
||||
{
|
||||
m_msgBlock.bot = id;
|
||||
}
|
||||
|
||||
// find registered message id
|
||||
inline int FindMessageId (int type)
|
||||
{
|
||||
return m_msgBlock.regMsgs[type];
|
||||
}
|
||||
|
||||
// assigns message id for message type
|
||||
inline void AssignMessageId (int type, int id)
|
||||
{
|
||||
m_msgBlock.regMsgs[type] = id;
|
||||
}
|
||||
|
||||
// tries to set needed message id
|
||||
void TryCaptureMessage (int type, int msgId)
|
||||
{
|
||||
if (type == m_msgBlock.regMsgs[msgId])
|
||||
SetOngoingMessageId (msgId);
|
||||
}
|
||||
|
||||
// static utility functions
|
||||
public:
|
||||
static const char *ExtractSingleField (const char *string, int id, bool terminate);
|
||||
|
|
|
|||
|
|
@ -149,7 +149,7 @@ typedef struct enginefuncs_s
|
|||
void (*pfnGetAimVector) (edict_t *ent, float speed, float *rgflReturn);
|
||||
void (*pfnServerCommand) (char *str);
|
||||
void (*pfnServerExecute) (void);
|
||||
void (*pfnClientCommand) (edict_t *ent, char *szFmt, ...);
|
||||
void (*pfnClientCommand) (edict_t *ent, char const *szFmt, ...);
|
||||
void (*pfnParticleEffect) (const float *org, const float *dir, float color, float count);
|
||||
void (*pfnLightStyle) (int style, char *val);
|
||||
int (*pfnDecalIndex) (const char *name);
|
||||
|
|
@ -203,7 +203,7 @@ typedef struct enginefuncs_s
|
|||
void (*pfnSetView) (const edict_t *client, const edict_t *pViewent);
|
||||
float (*pfnTime) (void);
|
||||
void (*pfnCrosshairAngle) (const edict_t *client, float pitch, float yaw);
|
||||
byte *(*pfnLoadFileForMe) (char *szFilename, int *pLength);
|
||||
byte *(*pfnLoadFileForMe) (char const *szFilename, int *pLength);
|
||||
void (*pfnFreeFile) (void *buffer);
|
||||
void (*pfnEndSection) (const char *pszSectionName); // trigger_endsection
|
||||
int (*pfnCompareFileTime) (char *filename1, char *filename2, int *compare);
|
||||
|
|
@ -215,9 +215,9 @@ typedef struct enginefuncs_s
|
|||
void (*pfnRunPlayerMove) (edict_t *fakeclient, const float *viewangles, float forwardmove, float sidemove, float upmove, unsigned short buttons, byte impulse, byte msec);
|
||||
int (*pfnNumberOfEntities) (void);
|
||||
char *(*pfnGetInfoKeyBuffer) (edict_t *e); // passing in NULL gets the serverinfo
|
||||
char *(*pfnInfoKeyValue) (char *infobuffer, char *key);
|
||||
char *(*pfnInfoKeyValue) (char *infobuffer, char const *key);
|
||||
void (*pfnSetKeyValue) (char *infobuffer, char *key, char *value);
|
||||
void (*pfnSetClientKeyValue) (int clientIndex, char *infobuffer, char *key, char *value);
|
||||
void (*pfnSetClientKeyValue) (int clientIndex, char *infobuffer, char const *key, char const *value);
|
||||
int (*pfnIsMapValid) (char *szFilename);
|
||||
void (*pfnStaticDecal) (const float *origin, int decalIndex, int entityIndex, int modelIndex);
|
||||
int (*pfnPrecacheGeneric) (char *s);
|
||||
|
|
@ -280,7 +280,7 @@ typedef struct enginefuncs_s
|
|||
typedef struct KeyValueData_s
|
||||
{
|
||||
char *szClassName; // in: entity classname
|
||||
char *szKeyName; // in: name of key
|
||||
char const *szKeyName; // in: name of key
|
||||
char *szValue; // in: value of key
|
||||
int32 fHandled; // out: DLL sets to true if key-value pair was understood
|
||||
} KeyValueData;
|
||||
|
|
|
|||
|
|
@ -37,13 +37,13 @@ typedef enum
|
|||
|
||||
typedef struct
|
||||
{
|
||||
char *ifvers;
|
||||
char *name;
|
||||
char *version;
|
||||
char *date;
|
||||
char *author;
|
||||
char *url;
|
||||
char *logtag;
|
||||
char const *ifvers;
|
||||
char const *name;
|
||||
char const *version;
|
||||
char const *date;
|
||||
char const *author;
|
||||
char const *url;
|
||||
char const *logtag;
|
||||
PLUG_LOADTIME loadable;
|
||||
PLUG_LOADTIME unloadable;
|
||||
} plugin_info_t;
|
||||
|
|
|
|||
|
|
@ -53,12 +53,6 @@ static inline edict_t *FIND_ENTITY_BY_TARGET (edict_t *entStart, const char *psz
|
|||
#define ClearBits(flBitVector, bits) ((flBitVector) = (int)(flBitVector) & ~(bits))
|
||||
#define FBitSet(flBitVector, bit) ((int)(flBitVector) & (bit))
|
||||
|
||||
// Pointer operators
|
||||
#define PTR_TO_BYTE(in) *(byte *) (in)
|
||||
#define PTR_TO_FLT(in) *(float *) (in)
|
||||
#define PTR_TO_INT(in) *(int *) (in)
|
||||
#define PTR_TO_STR(in) (char *) (in)
|
||||
|
||||
// Makes these more explicit, and easier to find
|
||||
#define FILE_GLOBAL static
|
||||
|
||||
|
|
@ -82,6 +76,7 @@ typedef int BOOL;
|
|||
//
|
||||
// Conversion among the three types of "entity", including identity-conversions.
|
||||
//
|
||||
#if 0
|
||||
static inline edict_t *ENT (const entvars_t *pev)
|
||||
{
|
||||
return pev->pContainingEntity;
|
||||
|
|
@ -131,12 +126,14 @@ static inline entvars_t *VARS (EOFFSET eoffset)
|
|||
{
|
||||
return VARS (ENT (eoffset));
|
||||
}
|
||||
#endif
|
||||
|
||||
static inline void MESSAGE_BEGIN (int msg_dest, int msg_type, const float *pOrigin, entvars_t *ent)
|
||||
{
|
||||
(*g_engfuncs.pfnMessageBegin) (msg_dest, msg_type, pOrigin, ENT (ent));
|
||||
(*g_engfuncs.pfnMessageBegin) (msg_dest, msg_type, pOrigin, ent->pContainingEntity);
|
||||
}
|
||||
|
||||
#if 0
|
||||
// Testing the three types of "entity" for nullity
|
||||
#define eoNullEntity 0
|
||||
static inline BOOL FNullEnt (EOFFSET eoffset)
|
||||
|
|
@ -162,6 +159,7 @@ static inline BOOL FStringNull (int stingPtr)
|
|||
#define cchMapNameMost 32
|
||||
|
||||
#define SAFE_FUNCTION_CALL(pfn,args) try { pfn args; } catch (...) { }
|
||||
#endif
|
||||
|
||||
// Dot products for view cone checking
|
||||
#define VIEW_FIELD_FULL (float)-1.0 // +-180 degrees
|
||||
|
|
@ -176,7 +174,7 @@ static inline BOOL FStrEq (const char *sz1, const char *sz2)
|
|||
}
|
||||
static inline BOOL FClassnameIs (edict_t *pent, const char *szClassname)
|
||||
{
|
||||
return FStrEq (STRING (VARS (pent)->classname), szClassname);
|
||||
return FStrEq (STRING (pent->v.classname), szClassname);
|
||||
}
|
||||
static inline BOOL FClassnameIs (entvars_t *pev, const char *szClassname)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -21,15 +21,15 @@
|
|||
// detects the compiler
|
||||
#if defined (_MSC_VER)
|
||||
#define COMPILER_VISUALC _MSC_VER
|
||||
#elif defined (__MINGW32__)
|
||||
#define COMPILER_MINGW32 __MINGW32__
|
||||
#elif defined (__MINGW32_MAJOR_VERSION)
|
||||
#define COMPILER_MINGW32 __MINGW32_MAJOR_VERSION
|
||||
#endif
|
||||
|
||||
// configure export macros
|
||||
#if defined (COMPILER_VISUALC) || defined (COMPILER_MINGW32)
|
||||
#define export extern "C" __declspec (dllexport)
|
||||
#define SHARED_LIBRARAY_EXPORT extern "C" __declspec (dllexport)
|
||||
#elif defined (PLATFORM_LINUX) || defined (PLATFORM_OSX)
|
||||
#define export extern "C" __attribute__((visibility("default")))
|
||||
#define SHARED_LIBRARAY_EXPORT extern "C" __attribute__((visibility("default")))
|
||||
#else
|
||||
#error "Can't configure export macros. Compiler unrecognized."
|
||||
#endif
|
||||
|
|
@ -38,6 +38,7 @@
|
|||
#ifdef PLATFORM_WIN32
|
||||
|
||||
#include <direct.h>
|
||||
#include <string.h>
|
||||
|
||||
#define DLL_ENTRYPOINT int STDCALL DllMain (HINSTANCE, DWORD dwReason, LPVOID)
|
||||
#define DLL_DETACHING (dwReason == DLL_PROCESS_DETACH)
|
||||
|
|
@ -46,7 +47,7 @@
|
|||
#if defined (COMPILER_VISUALC)
|
||||
#define DLL_GIVEFNPTRSTODLL extern "C" void STDCALL
|
||||
#elif defined (COMPILER_MINGW32)
|
||||
#define DLL_GIVEFNPTRSTODLL export void STDCALL
|
||||
#define DLL_GIVEFNPTRSTODLL SHARED_LIBRARAY_EXPORT void STDCALL
|
||||
#endif
|
||||
|
||||
// specify export parameter
|
||||
|
|
@ -138,11 +139,8 @@ public:
|
|||
|
||||
template <typename R> R GetFuncAddr (const char *function)
|
||||
{
|
||||
if (!IsLoaded ())
|
||||
return NULL;
|
||||
|
||||
#ifdef PLATFORM_WIN32
|
||||
return reinterpret_cast <R> (GetProcAddress (static_cast <HMODULE> (m_ptr), function));
|
||||
return reinterpret_cast <R> (GetProcAddress (GetHandle <HMODULE> (), function));
|
||||
#else
|
||||
return reinterpret_cast <R> (dlsym (m_ptr, function));
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue