Skip to content

Commit

Permalink
First attempt to hand-merge Ryan's Linux and Mac OS X port.
Browse files Browse the repository at this point in the history
This was a _ton_ of changes, made 15 years ago, so there are probably some
problems to work out still.

Among others: Engine/Base/Stream.* was mostly abandoned and will need to be
re-ported.

Still, this is a pretty good start, and probably holds a world record for
lines of changes or something.  :)
  • Loading branch information
icculus committed Mar 29, 2016
1 parent a7af6eb commit 24cb244
Show file tree
Hide file tree
Showing 497 changed files with 29,841 additions and 6,608 deletions.
4 changes: 2 additions & 2 deletions Sources/DecodeReport/DecodeReport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void SubMain( int argc, char *argv[])
}

// initialize engine
SE_InitEngine("");
SE_InitEngine(argv[0], "");
_fnmApplicationPath = CTString("");


Expand All @@ -103,7 +103,7 @@ void SubMain( int argc, char *argv[])
strmSrc.GetLine_t(strLine);

// try to find address marker in it
const char *strAdr = strstr(strLine, "$adr:");
char *strAdr = strstr(strLine, "$adr:");
// if there is no marker
if (strAdr==NULL) {
// just copy the line
Expand Down
168 changes: 107 additions & 61 deletions Sources/DedicatedServer/DedicatedServer.cpp
Original file line number Diff line number Diff line change
@@ -1,58 +1,64 @@
/* Copyright (c) 2002-2012 Croteam Ltd. All rights reserved. */

#ifdef PLATFORM_UNIX /* rcg10072001 */
#include <signal.h>
#endif

#include "StdAfx.h"
#include <GameMP/Game.h>
#define DECL_DLL

#if 0 /* rcg10042001 Doesn't seem to exist. */
#include <Entities/Global.h>
#endif

// application state variables
extern BOOL _bRunning = TRUE;
BOOL _bRunning = TRUE;
static BOOL _bForceRestart = FALSE;
static BOOL _bForceNextMap = FALSE;

extern CTString _strSamVersion = "no version information";
extern INDEX ded_iMaxFPS = 100;
extern CTString ded_strConfig = "";
extern CTString ded_strLevel = "";
extern INDEX ded_bRestartWhenEmpty = TRUE;
extern FLOAT ded_tmTimeout = -1;
extern CGame *_pGame = NULL;
extern CTString sam_strFirstLevel = "Levels\\KarnakDemo.wld";
extern CTString sam_strIntroLevel = "Levels\\Intro.wld";
extern CTString sam_strGameName = "serioussam";
CTString _strSamVersion = "no version information";
INDEX ded_iMaxFPS = 100;
CTString ded_strConfig = "";
CTString ded_strLevel = "";
INDEX ded_bRestartWhenEmpty = TRUE;
FLOAT ded_tmTimeout = -1;
CGame *_pGame = NULL;
CTString sam_strFirstLevel = "Levels\\KarnakDemo.wld";
CTString sam_strIntroLevel = "Levels\\Intro.wld";
CTString sam_strGameName = "serioussam";

CTimerValue _tvLastLevelEnd(-1i64);
CTimerValue _tvLastLevelEnd((__int64) -1);

void InitializeGame(void)
{
try {
#ifndef NDEBUG
#define GAMEDLL _fnmApplicationExe.FileDir()+"Game"+_strModExt+"D.dll"
#ifdef STATICALLY_LINKED
#define fnmExpanded NULL
CPrintF(TRANS("Loading game library '%s'...\n"), "(statically linked)");
#else
CTFileName fnmDLL;
#ifndef NDEBUG
fnmDLL = "Bin\\Debug\\Game"+_strModExt+"D.dll";
#else
#define GAMEDLL _fnmApplicationExe.FileDir()+"Game"+_strModExt+".dll"
fnmDLL = "Bin\\Game"+_strModExt+".dll";
#endif
CTFileName fnmExpanded;
ExpandFilePath(EFP_READ, CTString(GAMEDLL), fnmExpanded);

fnmDLL = CDynamicLoader::ConvertLibNameToPlatform(fnmDLL);
CTFileName fnmExpanded;
ExpandFilePath(EFP_READ | EFP_NOZIPS,fnmDLL,fnmExpanded);
CPrintF(TRANS("Loading game library '%s'...\n"), (const char *)fnmExpanded);
HMODULE hGame = LoadLibraryA(fnmExpanded);
if (hGame==NULL) {
ThrowF_t("%s", GetWindowsError(GetLastError()));
}
CGame* (*GAME_Create)(void) = (CGame* (*)(void))GetProcAddress(hGame, "GAME_Create");
if (GAME_Create==NULL) {
ThrowF_t("%s", GetWindowsError(GetLastError()));
}
_pGame = GAME_Create();
#endif

} catch (char *strError) {
FatalError("%s", strError);
CDynamicLoader *loader = CDynamicLoader::GetInstance(fnmExpanded);
CGame *(*GAME_Create)(void) = NULL;

if (loader->GetError() == NULL) {
GAME_Create = (CGame* (*)(void)) loader->FindSymbol("GAME_Create");
}

if (GAME_Create == NULL) {
FatalError("%s", loader->GetError());
} else {
_pGame = GAME_Create();
// init game - this will load persistent symbols
_pGame->Initialize(CTString("Data\\DedicatedServer.gms"));
}
// init game - this will load persistent symbols
_pGame->Initialize(CTString("Data\\DedicatedServer.gms"));
}

static void QuitGame(void)
Expand Down Expand Up @@ -84,12 +90,16 @@ void LimitFrameRate(void)
// limit maximum frame rate
ded_iMaxFPS = ClampDn( ded_iMaxFPS, 1L);
TIME tmWantedDelta = 1.0f / ded_iMaxFPS;
if( tmCurrentDelta<tmWantedDelta) Sleep( (tmWantedDelta-tmCurrentDelta)*1000.0f);
if( tmCurrentDelta<tmWantedDelta)
_pTimer->Sleep( (DWORD) ((tmWantedDelta-tmCurrentDelta)*1000.0f) );

// remember new time
tvLast = _pTimer->GetHighPrecisionTimer();
}


/* rcg10072001 win32ism. */
#ifdef PLATFORM_WIN32
// break/close handler
BOOL WINAPI HandlerRoutine(
DWORD dwCtrlType // control signal type
Expand All @@ -104,13 +114,22 @@ BOOL WINAPI HandlerRoutine(
}
return TRUE;
}
#endif

#ifdef PLATFORM_UNIX
void unix_signal_catcher(int signum)
{
_bRunning = FALSE;
}
#endif


#define REFRESHTIME (0.1f)

static void LoadingHook_t(CProgressHookInfo *pphi)
{
// measure time since last call
static CTimerValue tvLast(0I64);
static CTimerValue tvLast((__int64) 0);
CTimerValue tvNow = _pTimer->GetHighPrecisionTimer();

if (!_bRunning) {
Expand All @@ -126,8 +145,13 @@ static void LoadingHook_t(CProgressHookInfo *pphi)

// print status text
CTString strRes;
#ifdef PLATFORM_WIN32
printf("\r ");
printf("\r%s : %3.0f%%\r", pphi->phi_strDescription, pphi->phi_fCompleted*100);
printf("\r%s : %3.0f%%\r", (const char *) pphi->phi_strDescription, pphi->phi_fCompleted*100);
#else
// !!! FIXME: This isn't right, either...
printf("%s : %3.0f%%\n", (const char *) pphi->phi_strDescription, pphi->phi_fCompleted*100);
#endif
}

// loading hook functions
Expand Down Expand Up @@ -158,14 +182,21 @@ BOOL StartGame(CTString &strLevel)
return _pGame->NewGame( _pGame->gam_strSessionName, strLevel, sp);
}

void ExecScript(const CTString &str)
void ExecScript(const CTFileName &fnmScript)
{
CPrintF("Executing: '%s'\n", str);
CPrintF("Executing: '%s'\n", (const char *) fnmScript);
CTString strCmd;
strCmd.PrintF("include \"%s\"", str);
strCmd.PrintF("include \"%s\"", (const char *) fnmScript);
_pShell->Execute(strCmd);
}


#ifdef PLATFORM_WIN32
#define DelayBeforeExit() fgetc(stdin);
#else
#define DelayBeforeExit()
#endif

BOOL Init(int argc, char* argv[])
{
_bDedicatedServer = TRUE;
Expand All @@ -174,11 +205,14 @@ BOOL Init(int argc, char* argv[])
// NOTE: this cannot be translated - translations are not loaded yet
printf("Usage: DedicatedServer <configname> [<modname>]\n"
"This starts a server reading configs from directory 'Scripts\\Dedicated\\<configname>\\'\n");
getch();

DelayBeforeExit();
exit(0);
}

SetConsoleTitleA(argv[1]);
#ifdef PLATFORM_WIN32
SetConsoleTitle(argv[1]);
#endif

ded_strConfig = CTString("Scripts\\Dedicated\\")+argv[1]+"\\";

Expand All @@ -190,7 +224,7 @@ BOOL Init(int argc, char* argv[])
_strLogFile = CTString("Dedicated_")+argv[1];

// initialize engine
SE_InitEngine(sam_strGameName);
SE_InitEngine(argv[0], sam_strGameName);

// ParseCommandLine(strCmdLine);

Expand All @@ -211,32 +245,40 @@ BOOL Init(int argc, char* argv[])

FinishTranslationTable();
} catch (char *strError) {
FatalError("%s %s", CTString(fnmTransTable), strError);
CTString str(fnmTransTable);
FatalError("%s %s", (const char *) str, strError);
}

// always disable all warnings when in serious sam
_pShell->Execute( "con_bNoWarnings=1;");

// declare shell symbols
_pShell->DeclareSymbol("persistent user INDEX ded_iMaxFPS;", &ded_iMaxFPS);
_pShell->DeclareSymbol("user void Quit(void);", &QuitGame);
_pShell->DeclareSymbol("user CTString ded_strLevel;", &ded_strLevel);
_pShell->DeclareSymbol("user FLOAT ded_tmTimeout;", &ded_tmTimeout);
_pShell->DeclareSymbol("user INDEX ded_bRestartWhenEmpty;", &ded_bRestartWhenEmpty);
_pShell->DeclareSymbol("user void Restart(void);", &RestartGame);
_pShell->DeclareSymbol("user void NextMap(void);", &NextMap);
_pShell->DeclareSymbol("persistent user CTString sam_strIntroLevel;", &sam_strIntroLevel);
_pShell->DeclareSymbol("persistent user CTString sam_strGameName;", &sam_strGameName);
_pShell->DeclareSymbol("user CTString sam_strFirstLevel;", &sam_strFirstLevel);
_pShell->DeclareSymbol("persistent user INDEX ded_iMaxFPS;", (void *) &ded_iMaxFPS);
_pShell->DeclareSymbol("user void Quit(void);", (void *) &QuitGame);
_pShell->DeclareSymbol("user CTString ded_strLevel;", (void *) &ded_strLevel);
_pShell->DeclareSymbol("user FLOAT ded_tmTimeout;", (void *) &ded_tmTimeout);
_pShell->DeclareSymbol("user INDEX ded_bRestartWhenEmpty;", (void *) &ded_bRestartWhenEmpty);
_pShell->DeclareSymbol("user void Restart(void);", (void *) &RestartGame);
_pShell->DeclareSymbol("user void NextMap(void);", (void *) &NextMap);
_pShell->DeclareSymbol("persistent user CTString sam_strIntroLevel;", (void *) &sam_strIntroLevel);
_pShell->DeclareSymbol("persistent user CTString sam_strGameName;", (void *) &sam_strGameName);
_pShell->DeclareSymbol("user CTString sam_strFirstLevel;", (void *) &sam_strFirstLevel);

// init game - this will load persistent symbols
InitializeGame();
_pNetwork->md_strGameID = sam_strGameName;

LoadStringVar(CTString("Data\\Var\\Sam_Version.var"), _strSamVersion);
CPrintF(TRANS("Serious Sam version: %s\n"), _strSamVersion);
CPrintF(TRANS("Serious Sam version: %s\n"), (const char *) _strSamVersion);

SetConsoleCtrlHandler(HandlerRoutine, TRUE);
#if (defined PLATFORM_WIN32)
SetConsoleCtrlHandler(HandlerRoutine, TRUE);
#elif (defined PLATFORM_UNIX)
signal(SIGINT, unix_signal_catcher);
signal(SIGHUP, unix_signal_catcher);
signal(SIGQUIT, unix_signal_catcher);
signal(SIGTERM, unix_signal_catcher);
#endif

// if there is a mod
if (_fnmMod!="") {
Expand Down Expand Up @@ -269,8 +311,8 @@ void RoundBegin(void)
{
// repeat generate script names
FOREVER {
strBegScript.PrintF("%s%d_begin.ini", ded_strConfig, iRound);
strEndScript.PrintF("%s%d_end.ini", ded_strConfig, iRound);
strBegScript.PrintF("%s%d_begin.ini", (const char *) ded_strConfig, iRound);
strEndScript.PrintF("%s%d_end.ini", (const char *) ded_strConfig, iRound);
// if start script exists
if (FileExists(strBegScript)) {
// stop searching
Expand Down Expand Up @@ -303,7 +345,7 @@ void RoundBegin(void)
_bHadPlayers = 0;
_bRestart = 0;
DisableLoadingHook();
_tvLastLevelEnd = CTimerValue(-1i64);
_tvLastLevelEnd = CTimerValue((__int64) -1);
CPrintF(TRANS("\nALL OK: Dedicated server is now running!\n"));
CPrintF(TRANS("Use Ctrl+C to shutdown the server.\n"));
CPrintF(TRANS("DO NOT use the 'Close' button, it might leave the port hanging!\n\n"));
Expand All @@ -317,7 +359,7 @@ void ForceNextMap(void)
_bHadPlayers = 0;
_bRestart = 0;
DisableLoadingHook();
_tvLastLevelEnd = CTimerValue(-1i64);
_tvLastLevelEnd = CTimerValue((__int64) -1);
}

void RoundEnd(void)
Expand All @@ -331,6 +373,10 @@ void RoundEnd(void)
// do the main game loop and render screen
void DoGame(void)
{
#ifdef SINGLE_THREADED
_pTimer->HandleTimerHandlers();
#endif

// do the main game loop
if( _pGame->gm_bGameOn) {
_pGame->GameMainLoop();
Expand Down
4 changes: 3 additions & 1 deletion Sources/DedicatedServer/StdAfx.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <Engine/Templates/Stock_CModelData.h>
#include <GameMP/Game.h>

/* rcg10042001 protect against Visual C-isms. */
// rcg10042001 protect against Visual C-isms.
#ifdef _MSC_VER
#define DECL_DLL _declspec(dllimport)
#endif
Expand All @@ -18,6 +18,8 @@
#include <EntitiesMP/Global.h>
#include <EntitiesMP/Common/Common.h>
#include <EntitiesMP/Common/GameInterface.h>
#include <EntitiesMP/WorldLink.h> // rcg10072001 needed enum definition.
#include <EntitiesMP/Player.h>

#undef DECL_DLL
11 changes: 7 additions & 4 deletions Sources/Depend/Dependency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,18 +427,21 @@ void CDependencyList::ExtractTranslations_t( const CTFileName &fnTranslations)
// for each byte in file
for(INDEX iByte=0; iByte<slSize-4; iByte++) {
UBYTE *pub = pubFile+iByte;
ULONG *pul = (ULONG*)pub;
ULONG ul = *((ULONG*)pub);

BYTESWAP(ul);

// if exe translatable string is here
if (*pul=='SRTE') {
if (ul=='SRTE') {
// get it
CTString str = (char*)(pub+4);
// add it
AddStringForTranslation(str);
// if data translatable string is here
} else if (*pul=='SRTD') {
} else if (ul=='SRTD') {
char achr[ 256];
INDEX iStrLen = *(INDEX *)(pub + 4);
BYTESWAP(iStrLen);
if( iStrLen > 254 || iStrLen<0) {
continue;
}
Expand All @@ -449,7 +452,7 @@ void CDependencyList::ExtractTranslations_t( const CTFileName &fnTranslations)
// add it
AddStringForTranslation(str);
// if text translatable string is here
} else if (*pul=='SRTT') {
} else if (ul=='SRTT') {

// after describing long and one space we will find file name
char *pchrStart = (char*)pub + 4 + 1;
Expand Down
2 changes: 1 addition & 1 deletion Sources/Depend/UtilityDepend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void SubMain( int argc, char *argv[])
}

// initialize engine
SE_InitEngine("");
SE_InitEngine(argv[0], "");
// get application path from cmd line
_fnmApplicationPath = CTString(ACHR_APP_DIR);
// if not ending with backslash
Expand Down
Loading

0 comments on commit 24cb244

Please sign in to comment.