Skip to content

Commit e999cca

Browse files
committed
Revert "Premakify publicsdk and build additional shared library on Linux (#120)"
This reverts commit 486f46c.
1 parent 402e199 commit e999cca

File tree

11 files changed

+630
-100
lines changed

11 files changed

+630
-100
lines changed

.gitignore

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,3 @@ _Pvt_Extensions
307307
Bin/
308308
Build/
309309
InstallFiles/
310-
311-
# publicsdk ignores
312-
Shared/publicsdk/include/lauxlib.h
313-
Shared/publicsdk/include/lua.h
314-
Shared/publicsdk/include/luaconf.h
315-
Shared/publicsdk/include/lualib.h
316-
Shared/publicsdk/lib/

Server/mods/deathmatch/premake5.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ project "Deathmatch"
3131
}
3232

3333
links {
34-
"pthread", "sqlite", "ehs", "cryptopp", "pme", "pcre", "json-c", "zip", "zlib"
34+
"Lua_Server", "pthread", "sqlite", "ehs", "cryptopp", "pme", "pcre", "json-c", "zip", "zlib"
3535
}
3636

3737
vpaths {
@@ -58,14 +58,14 @@ project "Deathmatch"
5858
filter "system:windows"
5959
includedirs { "../../../vendor/pthreads/include" }
6060
buildoptions { "-Zm130" }
61-
links { "ws2_32", "Lua_Server" }
61+
links { "ws2_32" }
6262

6363
filter {"system:windows", "toolset:*120*"}
6464
links { "Psapi.lib" }
6565

6666
filter "system:not windows"
6767
buildoptions { "-Wno-narrowing" } -- We should fix the warnings at some point
68-
links { "rt", "Lua_Server_Static" }
68+
links { "rt" }
6969

7070
filter "platforms:x64"
7171
targetdir(buildpath("server/x64"))

Shared/publicsdk/CThread.cpp

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
/*********************************************************
2+
*
3+
* Multi Theft Auto: San Andreas - Deathmatch
4+
*
5+
* ml_base, External lua add-on module
6+
*
7+
* Copyright © 2003-2008 MTA. All Rights Reserved.
8+
*
9+
* Grand Theft Auto is © 2002-2003 Rockstar North
10+
*
11+
* THE FOLLOWING SOURCES ARE PART OF THE MULTI THEFT
12+
* AUTO SOFTWARE DEVELOPMENT KIT AND ARE RELEASED AS
13+
* OPEN SOURCE FILES. THESE FILES MAY BE USED AS LONG
14+
* AS THE DEVELOPER AGREES TO THE LICENSE THAT IS
15+
* PROVIDED WITH THIS PACKAGE.
16+
*
17+
*********************************************************/
18+
19+
#include "CThread.h"
20+
21+
CThread::CThread ( void )
22+
{
23+
m_pThreadData = NULL;
24+
m_pArg = NULL;
25+
#ifdef WIN32 // Win32 threads
26+
m_hThread = NULL;
27+
#endif
28+
}
29+
30+
31+
CThread::~CThread ( void )
32+
{
33+
Stop ();
34+
}
35+
36+
37+
bool CThread::Start ( CThreadData *pData )
38+
{
39+
if ( pData == NULL ) // pData HAS to be valid
40+
return false;
41+
42+
Stop ();
43+
Arg ( pData );
44+
45+
#ifdef WIN32 // Win32 threads
46+
m_hThread = CreateThread ( NULL, 0, &CThread::EntryPoint, this, 0, NULL );
47+
return m_hThread != NULL;
48+
#else // POSIX threads
49+
if ( pthread_create ( &m_hThread, NULL, CThread::EntryPoint, this ) )
50+
{
51+
// something bad happened
52+
return false;
53+
}
54+
#endif
55+
return true;
56+
}
57+
58+
59+
void CThread::Stop ( void )
60+
{
61+
if ( m_hThread )
62+
{
63+
// TerminateThread ( m_hThread, 0 );
64+
if ( m_pThreadData != NULL )
65+
m_pThreadData->bAbortThread = true;
66+
}
67+
}
68+
69+
70+
bool CThread::TryLock ( ThreadMutex * Mutex )
71+
{
72+
#ifdef WIN32
73+
if ( TryEnterCriticalSection ( Mutex ) != 0 )
74+
return true;
75+
#else
76+
if ( pthread_mutex_trylock ( Mutex ) == 0 )
77+
return true;
78+
#endif
79+
return false;
80+
}
81+
82+
83+
void CThread::Lock ( ThreadMutex * Mutex )
84+
{
85+
#ifdef WIN32 // Win32 threads
86+
EnterCriticalSection ( Mutex );
87+
#else // POSIX threads
88+
pthread_mutex_lock ( Mutex );
89+
#endif
90+
}
91+
92+
93+
void CThread::Unlock ( ThreadMutex * Mutex )
94+
{
95+
#ifdef WIN32 // Win32 threads
96+
LeaveCriticalSection ( Mutex );
97+
#else // POSIX threads
98+
pthread_mutex_unlock ( Mutex );
99+
#endif
100+
}
101+
102+
103+
int CThread::Run ( CThreadData* arg )
104+
{
105+
return Execute ( arg );
106+
}
107+
108+
109+
#ifdef WIN32 // Win32 threads
110+
DWORD CThread::EntryPoint ( void* pThis )
111+
{
112+
CThread* pt = (CThread*)pThis;
113+
return pt->Run ( pt->Arg () );
114+
}
115+
#else // POSIX threads
116+
void* CThread::EntryPoint ( void* pThis )
117+
{
118+
CThread* pt = (CThread*)pThis;
119+
pt->Run ( pt->Arg () );
120+
return NULL;
121+
}
122+
#endif
123+
124+
125+
CThreadData* CThread::Arg ( void ) const
126+
{
127+
return m_pThreadData;
128+
}
129+
130+
131+
void CThread::Arg ( CThreadData* pData )
132+
{
133+
m_pThreadData = pData;
134+
}

Shared/publicsdk/CThread.h

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*********************************************************
2+
*
3+
* Multi Theft Auto: San Andreas - Deathmatch
4+
*
5+
* ml_base, External lua add-on module
6+
*
7+
* Copyright © 2003-2008 MTA. All Rights Reserved.
8+
*
9+
* Grand Theft Auto is © 2002-2003 Rockstar North
10+
*
11+
* THE FOLLOWING SOURCES ARE PART OF THE MULTI THEFT
12+
* AUTO SOFTWARE DEVELOPMENT KIT AND ARE RELEASED AS
13+
* OPEN SOURCE FILES. THESE FILES MAY BE USED AS LONG
14+
* AS THE DEVELOPER AGREES TO THE LICENSE THAT IS
15+
* PROVIDED WITH THIS PACKAGE.
16+
*
17+
*********************************************************/
18+
19+
/** And remember.. threads on Win32 and POSIX are not similar at all. **/
20+
21+
#ifndef __CTHREAD_H
22+
#define __CTHREAD_H
23+
24+
#ifdef WIN32 // Win32 threads
25+
#define _WIN32_WINNT 0x400
26+
#define WIN32_LEAN_AND_MEAN
27+
#include <windows.h>
28+
29+
typedef HANDLE ThreadHandle;
30+
typedef CRITICAL_SECTION ThreadMutex;
31+
#else // POSIX threads
32+
#include <stdio.h>
33+
#include <pthread.h>
34+
35+
typedef pthread_t ThreadHandle;
36+
typedef pthread_mutex_t ThreadMutex;
37+
#endif
38+
39+
#include "CThreadData.h"
40+
41+
// Base thread class
42+
class CThread
43+
{
44+
public:
45+
CThread ( void );
46+
virtual ~CThread ( void );
47+
48+
bool Start ( CThreadData *pData );
49+
void Stop ( void );
50+
51+
static bool TryLock ( ThreadMutex * Mutex );
52+
static void Lock ( ThreadMutex * Mutex );
53+
static void Unlock ( ThreadMutex * Mutex );
54+
55+
protected:
56+
int Run ( CThreadData* arg );
57+
58+
virtual int Execute ( CThreadData* pData ) = 0;
59+
60+
CThreadData* Arg ( void ) const;
61+
void Arg ( CThreadData* pData );
62+
63+
#ifdef WIN32 // Win32 threads
64+
static DWORD WINAPI EntryPoint ( void* );
65+
#else // POSIX threads
66+
static void* EntryPoint ( void* );
67+
#endif
68+
69+
private:
70+
void* m_pArg;
71+
CThreadData* m_pThreadData;
72+
ThreadHandle m_hThread;
73+
};
74+
75+
#endif

Shared/publicsdk/CThreadData.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*********************************************************
2+
*
3+
* Multi Theft Auto: San Andreas - Deathmatch
4+
*
5+
* ml_base, External lua add-on module
6+
*
7+
* Copyright © 2003-2008 MTA. All Rights Reserved.
8+
*
9+
* Grand Theft Auto is © 2002-2003 Rockstar North
10+
*
11+
* THE FOLLOWING SOURCES ARE PART OF THE MULTI THEFT
12+
* AUTO SOFTWARE DEVELOPMENT KIT AND ARE RELEASED AS
13+
* OPEN SOURCE FILES. THESE FILES MAY BE USED AS LONG
14+
* AS THE DEVELOPER AGREES TO THE LICENSE THAT IS
15+
* PROVIDED WITH THIS PACKAGE.
16+
*
17+
*********************************************************/
18+
19+
#include "CThreadData.h"
20+
21+
CThreadData::CThreadData ( void )
22+
{
23+
bAbortThread = false;
24+
25+
// Initialize the mutexes
26+
#ifdef WIN32 // Win32 threads
27+
InitializeCriticalSection ( &MutexPrimary );
28+
InitializeCriticalSection ( &MutexLogical );
29+
#else // POSIX threads
30+
pthread_mutex_init ( &MutexPrimary, NULL );
31+
pthread_mutex_init ( &MutexLogical, NULL );
32+
#endif
33+
}
34+
35+
CThreadData::~CThreadData ( void )
36+
{
37+
#ifdef WIN32
38+
DeleteCriticalSection ( &MutexPrimary );
39+
DeleteCriticalSection ( &MutexLogical );
40+
#else
41+
#endif
42+
}

Shared/publicsdk/CThreadData.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*********************************************************
2+
*
3+
* Multi Theft Auto: San Andreas - Deathmatch
4+
*
5+
* ml_base, External lua add-on module
6+
*
7+
* Copyright © 2003-2008 MTA. All Rights Reserved.
8+
*
9+
* Grand Theft Auto is © 2002-2003 Rockstar North
10+
*
11+
* THE FOLLOWING SOURCES ARE PART OF THE MULTI THEFT
12+
* AUTO SOFTWARE DEVELOPMENT KIT AND ARE RELEASED AS
13+
* OPEN SOURCE FILES. THESE FILES MAY BE USED AS LONG
14+
* AS THE DEVELOPER AGREES TO THE LICENSE THAT IS
15+
* PROVIDED WITH THIS PACKAGE.
16+
*
17+
*********************************************************/
18+
19+
class CThreadData;
20+
21+
#ifndef __CTHREADDATA_H
22+
#define __CTHREADDATA_H
23+
24+
#include "CThread.h"
25+
26+
class CThreadData
27+
{
28+
public:
29+
CThreadData ( void );
30+
~CThreadData ( void );
31+
32+
bool bAbortThread;
33+
ThreadMutex MutexPrimary; // primary mutex for suspend/resume operations
34+
ThreadMutex MutexLogical; // logical mutex for proper CThreadData sync
35+
};
36+
37+
#endif

Shared/publicsdk/Makefile.am

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
noinst_LTLIBRARIES = libml_base.la
2+
3+
libml_base_la_SOURCES = \
4+
CFunctions.cpp \
5+
CThread.cpp \
6+
CThreadData.cpp \
7+
ml_base.cpp \
8+
extra/CLuaArgument.cpp \
9+
extra/CLuaArguments.cpp
10+
11+
#TODO:
12+
# the windows project uses the internal LUA, why?
13+
14+
libml_base_la_CXXFLAGS = \
15+
-I$(top_srcdir)/vendor/lua/src/ \
16+
-I$(top_builddir)/vendor/lua/src/
17+
18+
libml_base_la_LIBADD = \
19+
$(top_builddir)/vendor/lua/src/liblua.la

Shared/publicsdk/ml_base.sln

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Microsoft Visual Studio Solution File, Format Version 10.00
2+
# Visual Studio 2008
3+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ml_base", "ml_base.vcproj", "{132A627F-058D-46F8-BCBB-63B6C8D2CC1A}"
4+
EndProject
5+
Global
6+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
7+
Debug|Win32 = Debug|Win32
8+
Release|Win32 = Release|Win32
9+
EndGlobalSection
10+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
11+
{132A627F-058D-46F8-BCBB-63B6C8D2CC1A}.Debug|Win32.ActiveCfg = Debug|Win32
12+
{132A627F-058D-46F8-BCBB-63B6C8D2CC1A}.Debug|Win32.Build.0 = Debug|Win32
13+
{132A627F-058D-46F8-BCBB-63B6C8D2CC1A}.Release|Win32.ActiveCfg = Release|Win32
14+
{132A627F-058D-46F8-BCBB-63B6C8D2CC1A}.Release|Win32.Build.0 = Release|Win32
15+
EndGlobalSection
16+
GlobalSection(SolutionProperties) = preSolution
17+
HideSolutionNode = FALSE
18+
EndGlobalSection
19+
EndGlobal

0 commit comments

Comments
 (0)