Skip to content

Commit

Permalink
mac os x support
Browse files Browse the repository at this point in the history
  • Loading branch information
weimzh committed May 18, 2014
1 parent d0c0df0 commit 05a1bd1
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 83 deletions.
38 changes: 25 additions & 13 deletions src/Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#CPP=g++
#CC=gcc
#DLLWRAP=dllwrap
#WINDRES=windres
CPP=g++
CC=gcc
DLLWRAP=dllwrap
WINDRES=windres

CPP=i586-mingw32msvc-g++
CC=i586-mingw32msvc-gcc
DLLWRAP=i586-mingw32msvc-dllwrap
WINDRES=i586-mingw32msvc-windres
#CPP=i586-mingw32msvc-g++
#CC=i586-mingw32msvc-gcc
#DLLWRAP=i586-mingw32msvc-dllwrap
#WINDRES=i586-mingw32msvc-windres

OS=windows
#OS=windows
#OS=linux
OS=mac

OBJ=bot.o bot_ai.o bot_chat.o bot_client.o bot_combat.o bot_globals.o bot_navigate.o bot_sounds.o compress.o cstrike.o dllapi.o engine_api.o h_export.o intl.o linkgame.o meta_api.o namefunc.o util.o waypoint.o

Expand All @@ -24,10 +25,20 @@ ifeq "$(OS)" "linux"
BASEFLAGS=-Dstricmp=strcasecmp -Dstrcmpi=strcasecmp -w
CPPFLAGS=${BASEFLAGS} ${CFLAGS}

all: podbot_i386.so
all: podbot.so

podbot_i386.so: ${OBJ}
${CPP} ${CFLAGS} -fPIC -shared -static -o $@ ${OBJ} -ldl -lm
podbot.so: ${OBJ}
${CPP} ${CFLAGS} -fPIC -shared -o $@ ${OBJ} -ldl -lm

else ifeq "$(OS)" "mac"

BASEFLAGS=-Dstricmp=strcasecmp -Dstrcmpi=strcasecmp -w -m32
CPPFLAGS=${BASEFLAGS} ${CFLAGS}

all: podbot.dylib

podbot.dylib: ${OBJ}
${CPP} -m32 -fPIC -shared -o $@ ${OBJ} -ldl -lm

else

Expand All @@ -47,7 +58,8 @@ endif
clean:
-rm -f *.o
-rm -f PODBot.dll
-rm -f podbot_i386.so
-rm -f podbot.so
-rm -f podbot.dylib

%.o: %.cpp
${CPP} ${CPPFLAGS} -c $< -o $@
Expand Down
4 changes: 2 additions & 2 deletions src/bot.h
Original file line number Diff line number Diff line change
Expand Up @@ -817,13 +817,13 @@ void UTIL_DrawArrow(edict_t *pEntity, Vector start, Vector end, int width,
Vector VecCheckToss( entvars_t *pev, const Vector &vecSpot1, Vector vecSpot2, float flGravityAdj = 1.0 );
Vector VecCheckThrow( entvars_t *pev, const Vector &vecSpot1, Vector vecSpot2, float flSpeed, float flGravityAdj = 1.0 );

inline bool IsNullString(const char *str) {
static inline bool IsNullString(const char *str) {
if (str == NULL)
return TRUE;
return (*str == '\0');
}

inline bool ParamIsValid(const char *str) {
static inline bool ParamIsValid(const char *str) {
if (IsNullString(str))
return FALSE;
return (*str != '*' || *(str + 1) != '\0');
Expand Down
1 change: 0 additions & 1 deletion src/compress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <malloc.h>

#ifdef _MSC_VER
#pragma warning (disable: 4244) /* convert 'int' to 'unsigned char' */
Expand Down
9 changes: 6 additions & 3 deletions src/h_export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void WINAPI GiveFnptrsToDll( enginefuncs_t* pengfuncsFromEngine, globalvars_t *p
GetGameDirectory(szGameDLLName);

// load the actual Counter-Strike Game DLL
#ifdef _WIN32
#if defined (_WIN32)
strcat(szGameDLLName, "\\dlls");
mkdir(szGameDLLName);
strcat(szGameDLLName, "\\mp.dll");
Expand All @@ -100,8 +100,11 @@ void WINAPI GiveFnptrsToDll( enginefuncs_t* pengfuncsFromEngine, globalvars_t *p

h_Library = LoadLibrary(szGameDLLName);
}
#else
strcat(szGameDLLName, "/dlls/cs_i386.so");
#elif defined (__linux__)
strcat(szGameDLLName, "/dlls/cs.so");
h_Library = dlopen(szGameDLLName, RTLD_NOW);
#elif defined (__APPLE__)
strcat(szGameDLLName, "/dlls/cs.dylib");
h_Library = dlopen(szGameDLLName, RTLD_NOW);
#endif

Expand Down
54 changes: 27 additions & 27 deletions src/hlsdk/dlls/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,26 @@
#ifndef ENGINECALLBACK_H
#include "enginecallback.h"
#endif
inline void MESSAGE_BEGIN( int msg_dest, int msg_type, const float *pOrigin, entvars_t *ent ); // implementation later in this file
static inline void MESSAGE_BEGIN( int msg_dest, int msg_type, const float *pOrigin, entvars_t *ent ); // implementation later in this file

extern globalvars_t *gpGlobals;

// Use this instead of ALLOC_STRING on constant strings
#define STRING(offset) (const char *)(gpGlobals->pStringBase + (int)offset)
#define MAKE_STRING(str) ((int)str - (int)STRING(0))

inline edict_t *FIND_ENTITY_BY_CLASSNAME(edict_t *entStart, const char *pszName)
static inline edict_t *FIND_ENTITY_BY_CLASSNAME(edict_t *entStart, const char *pszName)
{
return FIND_ENTITY_BY_STRING(entStart, "classname", pszName);
}

inline edict_t *FIND_ENTITY_BY_TARGETNAME(edict_t *entStart, const char *pszName)
static inline edict_t *FIND_ENTITY_BY_TARGETNAME(edict_t *entStart, const char *pszName)
{
return FIND_ENTITY_BY_STRING(entStart, "targetname", pszName);
}

// for doing a reverse lookup. Say you have a door, and want to find its button.
inline edict_t *FIND_ENTITY_BY_TARGET(edict_t *entStart, const char *pszName)
static inline edict_t *FIND_ENTITY_BY_TARGET(edict_t *entStart, const char *pszName)
{
return FIND_ENTITY_BY_STRING(entStart, "target", pszName);
}
Expand Down Expand Up @@ -99,55 +99,55 @@ typedef int BOOL;
//
#ifdef DEBUG
extern edict_t *DBG_EntOfVars(const entvars_t *pev);
inline edict_t *ENT(const entvars_t *pev) { return DBG_EntOfVars(pev); }
static inline edict_t *ENT(const entvars_t *pev) { return DBG_EntOfVars(pev); }
#else
inline edict_t *ENT(const entvars_t *pev) { return pev->pContainingEntity; }
static inline edict_t *ENT(const entvars_t *pev) { return pev->pContainingEntity; }
#endif
inline edict_t *ENT(edict_t *pent) { return pent; }
inline edict_t *ENT(EOFFSET eoffset) { return (*g_engfuncs.pfnPEntityOfEntOffset)(eoffset); }
inline EOFFSET OFFSET(EOFFSET eoffset) { return eoffset; }
inline EOFFSET OFFSET(const edict_t *pent)
static inline edict_t *ENT(edict_t *pent) { return pent; }
static inline edict_t *ENT(EOFFSET eoffset) { return (*g_engfuncs.pfnPEntityOfEntOffset)(eoffset); }
static inline EOFFSET OFFSET(EOFFSET eoffset) { return eoffset; }
static inline EOFFSET OFFSET(const edict_t *pent)
{
#ifdef _DEBUG
if ( !pent )
ALERT( at_error, "Bad ent in OFFSET()\n" );
#endif
return (*g_engfuncs.pfnEntOffsetOfPEntity)(pent);
}
inline EOFFSET OFFSET(entvars_t *pev)
static inline EOFFSET OFFSET(entvars_t *pev)
{
#ifdef _DEBUG
if ( !pev )
ALERT( at_error, "Bad pev in OFFSET()\n" );
#endif
return OFFSET(ENT(pev));
}
inline entvars_t *VARS(entvars_t *pev) { return pev; }
static inline entvars_t *VARS(entvars_t *pev) { return pev; }

inline entvars_t *VARS(edict_t *pent)
static inline entvars_t *VARS(edict_t *pent)
{
if ( !pent )
return NULL;

return &pent->v;
}

inline entvars_t* VARS(EOFFSET eoffset) { return VARS(ENT(eoffset)); }
inline int ENTINDEX(edict_t *pEdict) { return (*g_engfuncs.pfnIndexOfEdict)(pEdict); }
inline edict_t* INDEXENT( int iEdictNum ) { return (*g_engfuncs.pfnPEntityOfEntIndex)(iEdictNum); }
static inline entvars_t* VARS(EOFFSET eoffset) { return VARS(ENT(eoffset)); }
static inline int ENTINDEX(edict_t *pEdict) { return (*g_engfuncs.pfnIndexOfEdict)(pEdict); }
static inline edict_t* INDEXENT( int iEdictNum ) { return (*g_engfuncs.pfnPEntityOfEntIndex)(iEdictNum); }
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));
}

// Testing the three types of "entity" for nullity
#define eoNullEntity 0
inline BOOL FNullEnt(EOFFSET eoffset) { return eoffset == 0; }
inline BOOL FNullEnt(const edict_t* pent) { return pent == NULL || FNullEnt(OFFSET(pent)); }
inline BOOL FNullEnt(entvars_t* pev) { return pev == NULL || FNullEnt(OFFSET(pev)); }
static inline BOOL FNullEnt(EOFFSET eoffset) { return eoffset == 0; }
static inline BOOL FNullEnt(const edict_t* pent) { return pent == NULL || FNullEnt(OFFSET(pent)); }
static inline BOOL FNullEnt(entvars_t* pev) { return pev == NULL || FNullEnt(OFFSET(pev)); }

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

#define cchMapNameMost 32

Expand Down Expand Up @@ -190,11 +190,11 @@ typedef enum
} TOGGLE_STATE;

// Misc useful
inline BOOL FStrEq(const char*sz1, const char*sz2)
static inline BOOL FStrEq(const char*sz1, const char*sz2)
{ return (strcmp(sz1, sz2) == 0); }
inline BOOL FClassnameIs(edict_t* pent, const char* szClassname)
static inline BOOL FClassnameIs(edict_t* pent, const char* szClassname)
{ return FStrEq(STRING(VARS(pent)->classname), szClassname); }
inline BOOL FClassnameIs(entvars_t* pev, const char* szClassname)
static inline BOOL FClassnameIs(entvars_t* pev, const char* szClassname)
{ return FStrEq(STRING(pev->classname), szClassname); }

class CBaseEntity;
Expand Down Expand Up @@ -224,7 +224,7 @@ extern void UTIL_MakeVectors (const Vector &vecAngles);
extern int UTIL_MonstersInSphere( CBaseEntity **pList, int listMax, const Vector &center, float radius );
extern int UTIL_EntitiesInBox( CBaseEntity **pList, int listMax, const Vector &mins, const Vector &maxs, int flagMask );

inline void UTIL_MakeVectorsPrivate( const Vector &vecAngles, float *p_vForward, float *p_vRight, float *p_vUp )
static inline void UTIL_MakeVectorsPrivate( const Vector &vecAngles, float *p_vForward, float *p_vRight, float *p_vUp )
{
g_engfuncs.pfnAngleVectors( vecAngles, p_vForward, p_vRight, p_vUp );
}
Expand Down Expand Up @@ -289,7 +289,7 @@ extern void UTIL_PrecacheOther( const char *szClassname );

// prints a message to each client
extern void UTIL_ClientPrintAll( int msg_dest, const char *msg_name, const char *param1 = NULL, const char *param2 = NULL, const char *param3 = NULL, const char *param4 = NULL );
inline void UTIL_CenterPrintAll( const char *msg_name, const char *param1 = NULL, const char *param2 = NULL, const char *param3 = NULL, const char *param4 = NULL )
static inline void UTIL_CenterPrintAll( const char *msg_name, const char *param1 = NULL, const char *param2 = NULL, const char *param3 = NULL, const char *param4 = NULL )
{
UTIL_ClientPrintAll( HUD_PRINTCENTER, msg_name, param1, param2, param3, param4 );
}
Expand Down Expand Up @@ -491,12 +491,12 @@ void EMIT_SOUND_DYN(edict_t *entity, int channel, const char *sample, float volu
int flags, int pitch);


inline void EMIT_SOUND(edict_t *entity, int channel, const char *sample, float volume, float attenuation)
static inline void EMIT_SOUND(edict_t *entity, int channel, const char *sample, float volume, float attenuation)
{
EMIT_SOUND_DYN(entity, channel, sample, volume, attenuation, 0, PITCH_NORM);
}

inline void STOP_SOUND(edict_t *entity, int channel, const char *sample)
static inline void STOP_SOUND(edict_t *entity, int channel, const char *sample)
{
EMIT_SOUND_DYN(entity, channel, sample, 0, 0, SND_STOP, PITCH_NORM);
}
Expand Down
62 changes: 31 additions & 31 deletions src/hlsdk/dlls/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@
class Vector2D
{
public:
inline Vector2D(void): x(0.0), y(0.0) { }
inline Vector2D(float X, float Y): x(0.0), y(0.0) { x = X; y = Y; }
inline Vector2D operator+(const Vector2D& v) const { return Vector2D(x+v.x, y+v.y); }
inline Vector2D operator-(const Vector2D& v) const { return Vector2D(x-v.x, y-v.y); }
inline Vector2D operator*(float fl) const { return Vector2D(x*fl, y*fl); }
inline Vector2D operator/(float fl) const { return Vector2D(x/fl, y/fl); }
Vector2D(void): x(0.0), y(0.0) { }
Vector2D(float X, float Y) { x = X; y = Y; }
Vector2D operator+(const Vector2D& v) const { return Vector2D(x+v.x, y+v.y); }
Vector2D operator-(const Vector2D& v) const { return Vector2D(x-v.x, y-v.y); }
Vector2D operator*(float fl) const { return Vector2D(x*fl, y*fl); }
Vector2D operator/(float fl) const { return Vector2D(x/fl, y/fl); }

inline float Length(void) const { return sqrt(x*x + y*y ); }
float Length(void) const { return sqrt(x*x + y*y ); }

inline Vector2D Normalize ( void ) const
Vector2D Normalize ( void ) const
{
// Vector2D vec2;

Expand All @@ -50,8 +50,8 @@ class Vector2D
vec_t x, y;
};

inline float DotProduct(const Vector2D& a, const Vector2D& b) { return( a.x*b.x + a.y*b.y ); }
inline Vector2D operator*(float fl, const Vector2D& v) { return v * fl; }
static inline float DotProduct(const Vector2D& a, const Vector2D& b) { return( a.x*b.x + a.y*b.y ); }
static inline Vector2D operator*(float fl, const Vector2D& v) { return v * fl; }

//=========================================================
// 3D Vector
Expand All @@ -60,36 +60,36 @@ class Vector // same data-layout as engine's vec3_t,
{ // which is a vec_t[3]
public:
// Construction/destruction
inline Vector(void): x(0.0), y(0.0), z(0.0) { }
inline Vector(float X, float Y, float Z): x(0.0), y(0.0), z(0.0) { x = X; y = Y; z = Z; }
//inline Vector(double X, double Y, double Z) { x = (float)X; y = (float)Y; z = (float)Z; }
//inline Vector(int X, int Y, int Z) { x = (float)X; y = (float)Y; z = (float)Z; }
inline Vector(const Vector& v): x(0.0), y(0.0), z(0.0) { x = v.x; y = v.y; z = v.z; }
inline Vector(float rgfl[3]): x(0.0), y(0.0), z(0.0) { x = rgfl[0]; y = rgfl[1]; z = rgfl[2]; }
Vector(void): x(0.0), y(0.0), z(0.0) { }
Vector(float X, float Y, float Z) { x = X; y = Y; z = Z; }
//Vector(double X, double Y, double Z) { x = (float)X; y = (float)Y; z = (float)Z; }
//Vector(int X, int Y, int Z) { x = (float)X; y = (float)Y; z = (float)Z; }
Vector(const Vector& v): x(0.0), y(0.0), z(0.0) { x = v.x; y = v.y; z = v.z; }
Vector(float rgfl[3]): x(0.0), y(0.0), z(0.0) { x = rgfl[0]; y = rgfl[1]; z = rgfl[2]; }

// Operators
inline Vector operator-(void) const { return Vector(-x,-y,-z); }
inline int operator==(const Vector& v) const { return x==v.x && y==v.y && z==v.z; }
inline int operator!=(const Vector& v) const { return !(*this==v); }
inline Vector operator+(const Vector& v) const { return Vector(x+v.x, y+v.y, z+v.z); }
inline Vector operator-(const Vector& v) const { return Vector(x-v.x, y-v.y, z-v.z); }
inline Vector operator*(float fl) const { return Vector(x*fl, y*fl, z*fl); }
inline Vector operator/(float fl) const { return Vector(x/fl, y/fl, z/fl); }
Vector operator-(void) const { return Vector(-x,-y,-z); }
int operator==(const Vector& v) const { return x==v.x && y==v.y && z==v.z; }
int operator!=(const Vector& v) const { return !(*this==v); }
Vector operator+(const Vector& v) const { return Vector(x+v.x, y+v.y, z+v.z); }
Vector operator-(const Vector& v) const { return Vector(x-v.x, y-v.y, z-v.z); }
Vector operator*(float fl) const { return Vector(x*fl, y*fl, z*fl); }
Vector operator/(float fl) const { return Vector(x/fl, y/fl, z/fl); }

// Methods
inline void CopyToArray(float* rgfl) const { rgfl[0] = x, rgfl[1] = y, rgfl[2] = z; }
inline float Length(void) const { return sqrt(x*x + y*y + z*z); }
void CopyToArray(float* rgfl) const { rgfl[0] = x, rgfl[1] = y, rgfl[2] = z; }
float Length(void) const { return sqrt(x*x + y*y + z*z); }
operator float *() { return &x; } // Vectors will now automatically convert to float * when needed
operator const float *() const { return &x; } // Vectors will now automatically convert to float * when needed
inline Vector Normalize(void) const
Vector Normalize(void) const
{
float flLen = Length();
if (flLen == 0) return Vector(0,0,1); // ????
flLen = 1 / flLen;
return Vector(x * flLen, y * flLen, z * flLen);
}

inline Vector2D Make2D ( void ) const
Vector2D Make2D ( void ) const
{
Vector2D Vec2;

Expand All @@ -98,14 +98,14 @@ class Vector // same data-layout as engine's vec3_t,

return Vec2;
}
inline float Length2D(void) const { return sqrt(x*x + y*y); }
float Length2D(void) const { return sqrt(x*x + y*y); }

// Members
vec_t x, y, z;
};
inline Vector operator*(float fl, const Vector& v) { return v * fl; }
inline float DotProduct(const Vector& a, const Vector& b) { return(a.x*b.x+a.y*b.y+a.z*b.z); }
inline Vector CrossProduct(const Vector& a, const Vector& b) { return Vector( a.y*b.z - a.z*b.y, a.z*b.x - a.x*b.z, a.x*b.y - a.y*b.x ); }
static inline Vector operator*(float fl, const Vector& v) { return v * fl; }
static inline float DotProduct(const Vector& a, const Vector& b) { return(a.x*b.x+a.y*b.y+a.z*b.z); }
static inline Vector CrossProduct(const Vector& a, const Vector& b) { return Vector( a.y*b.z - a.z*b.y, a.z*b.x - a.x*b.z, a.x*b.y - a.y*b.x ); }



Expand Down
6 changes: 3 additions & 3 deletions src/linkgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@

#include "bot.h"

#ifndef __linux__
#ifdef _WIN32
#ifdef __BORLANDC__
#define h_Library _h_Library
#endif // __BORLANDC__
typedef void (FAR *LINK_ENTITY_GAME)(entvars_t *);
extern HINSTANCE h_Library;
#else // __linux__
#else // _WIN32
typedef void (*LINK_ENTITY_GAME)(entvars_t *);
extern void *h_Library;
#endif // __linux__
#endif // _WIN32

#define LINK_ENTITY_TO_GAME(mapClassName) \
extern "C" EXPORT void mapClassName(entvars_t *pev) \
Expand Down
2 changes: 1 addition & 1 deletion src/metamod/mplugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#define MPLUGIN_H

#include <time.h> // time_t, etc
#include <malloc.h> // malloc, etc
#include <string.h> // malloc, etc

#include <eiface.h> // DLL_FUNCTIONS, etc

Expand Down
Loading

0 comments on commit 05a1bd1

Please sign in to comment.