Skip to content

Commit

Permalink
Merge pull request #16 from jeefo/develop
Browse files Browse the repository at this point in the history
fixes to #9 #11 #13 dirty fixes to #14
  • Loading branch information
jeefo committed Jan 30, 2016
2 parents e9d826c + 9e5c154 commit 8448bb3
Show file tree
Hide file tree
Showing 15 changed files with 396 additions and 397 deletions.
157 changes: 5 additions & 152 deletions include/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,155 +18,7 @@

using namespace Math;

// detects the build platform
#if defined (__linux__) || defined (__debian__) || defined (__linux)
#define PLATFORM_LINUX 1
#elif defined (__APPLE__)
#define PLATFORM_OSX 1
#elif defined (_WIN32)
#define PLATFORM_WIN32 1
#endif

// detects the compiler
#if defined (_MSC_VER)
#define COMPILER_VISUALC _MSC_VER
#elif defined (__MINGW32__)
#define COMPILER_MINGW32 __MINGW32__
#endif

// configure export macros
#if defined (COMPILER_VISUALC) || defined (COMPILER_MINGW32)
#define export extern "C" __declspec (dllexport)
#elif defined (PLATFORM_LINUX) || defined (PLATFORM_OSX)
#define export extern "C" __attribute__((visibility("default")))
#else
#error "Can't configure export macros. Compiler unrecognized."
#endif

// operating system specific macros, functions and typedefs
#ifdef PLATFORM_WIN32

#include <direct.h>

#define DLL_ENTRYPOINT int STDCALL DllMain (HINSTANCE, DWORD dwReason, LPVOID)
#define DLL_DETACHING (dwReason == DLL_PROCESS_DETACH)
#define DLL_RETENTRY return TRUE

#if defined (COMPILER_VISUALC)
#define DLL_GIVEFNPTRSTODLL extern "C" void STDCALL
#elif defined (COMPILER_MINGW32)
#define DLL_GIVEFNPTRSTODLL export void STDCALL
#endif

// specify export parameter
#if defined (COMPILER_VISUALC) && (COMPILER_VISUALC > 1000)
#pragma comment (linker, "/EXPORT:GiveFnptrsToDll=_GiveFnptrsToDll@8,@1")
#pragma comment (linker, "/SECTION:.data,RW")
#endif

typedef int (FAR *EntityAPI_t) (gamefuncs_t *, int);
typedef int (FAR *NewEntityAPI_t) (newgamefuncs_t *, int *);
typedef int (FAR *BlendAPI_t) (int, void **, void *, float (*)[3][4], float (*)[128][3][4]);
typedef void (STDCALL *FuncPointers_t) (enginefuncs_t *, globalvars_t *);
typedef void (FAR *EntityPtr_t) (entvars_t *);

#elif defined (PLATFORM_LINUX) || defined (PLATFORM_OSX)

#include <unistd.h>
#include <dlfcn.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/stat.h>

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <arpa/inet.h>

#define DLL_ENTRYPOINT __attribute__((destructor)) void _fini (void)
#define DLL_DETACHING TRUE
#define DLL_RETENTRY return
#define DLL_GIVEFNPTRSTODLL extern "C" void __attribute__((visibility("default")))

#if defined (__ANDROID__)
#define PLATFORM_ANDROID 1
#endif

typedef int (*EntityAPI_t) (gamefuncs_t *, int);
typedef int (*NewEntityAPI_t) (newgamefuncs_t *, int *);
typedef int (*BlendAPI_t) (int, void **, void *, float (*)[3][4], float (*)[128][3][4]);
typedef void (*FuncPointers_t) (enginefuncs_t *, globalvars_t *);
typedef void (*EntityPtr_t) (entvars_t *);

#else
#error "Platform unrecognized."
#endif

// library wrapper
class Library
{
private:
void *m_ptr;

public:

Library (const char *fileName)
{
m_ptr = NULL;

if (fileName == NULL)
return;

LoadLib (fileName);
}

~Library (void)
{
if (!IsLoaded ())
return;

#ifdef PLATFORM_WIN32
FreeLibrary ((HMODULE) m_ptr);
#else
dlclose (m_ptr);
#endif
}

public:
inline void *LoadLib (const char *fileName)
{
#ifdef PLATFORM_WIN32
m_ptr = LoadLibrary (fileName);
#else
m_ptr = dlopen (fileName, RTLD_NOW);
#endif

return m_ptr;
}

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));
#else
return reinterpret_cast <R> (dlsym (m_ptr, function));
#endif
}

template <typename R> R GetHandle (void)
{
return (R) m_ptr;
}

inline bool IsLoaded (void) const
{
return m_ptr != NULL;
}
};
#include "platform.h"

#include <assert.h>
#include <ctype.h>
Expand Down Expand Up @@ -258,9 +110,9 @@ enum CollisionState
// counter-strike team id's
enum Team
{
TEAM_TF = 0,
TEAM_CF,
TEAM_SPEC
TERRORIST = 0,
CT,
SPECTATOR
};

// client flags
Expand Down Expand Up @@ -1362,6 +1214,7 @@ class BotManager : public Singleton <BotManager>
float m_maintainTime; // time to maintain bot creation
float m_quotaMaintainTime; // time to maintain bot quota
int m_lastWinner; // the team who won previous round
int m_balanceCount; // limit of bots to add

bool m_economicsGood[2]; // is team able to buy anything
bool m_deathMsgSent; // for fakeping
Expand Down
37 changes: 4 additions & 33 deletions include/corelib.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ namespace Math
//
static inline void SineCosine (float rad, float *sine, float *cosine)
{
#if defined (_WIN32) && defined (_MSC_VER)
#if defined (_WIN32) && defined (_MSC_VER) && !defined (__clang__)
__asm
{
fld dword ptr[rad]
Expand All @@ -223,7 +223,8 @@ namespace Math
*cosine = _cos;
*sine = _sin;
#else
#error "SineConsine not defined."
*sine = sinf (rad);
*cosine = cosf (rad);
#endif
}

Expand Down Expand Up @@ -616,7 +617,7 @@ class Vector
//
inline static const Vector &GetZero (void)
{
static const Vector &s_zero = Vector (0.0f, 0.0f, 0.0f);
static const Vector s_zero = Vector (0.0f, 0.0f, 0.0f);
return s_zero;
}

Expand Down Expand Up @@ -2754,21 +2755,6 @@ class String
return strcmp (m_bufferPtr, string.m_bufferPtr);
}

//
// Function: CompareI
// Compares string with other string without case check.
//
// Parameters:
// string - String t compare with.
//
// Returns:
// Zero if they are equal.
//
int CompareI (String &string) const
{
return strcmpi (m_bufferPtr, string.m_bufferPtr);
}

//
// Function: Compare
// Compares string with other string.
Expand All @@ -2784,21 +2770,6 @@ class String
return strcmp (m_bufferPtr, str);
}

//
// Function: CompareI
// Compares string with other string without case check.
//
// Parameters:
// str - String to compare with.
//
// Returns:
// Zero if they are equal.
//
int CompareI (const char *str) const
{
return stricmp (m_bufferPtr, str);
}

//
// Function: Collate
// Collate the string.
Expand Down
2 changes: 1 addition & 1 deletion include/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,6 @@ static inline int GetTeam (edict_t *ent)
#ifndef XASH_CSDM
return g_clients[IndexOfEntity (ent) - 1].team;
#else
return g_clients[IndexOfEntity (ent) - 1].team = ent->v.team == 1 ? TEAM_TF : TEAM_CF;
return g_clients[IndexOfEntity (ent) - 1].team = ent->v.team == 1 ? TERRORIST : CT;
#endif
}
Loading

0 comments on commit 8448bb3

Please sign in to comment.