made engine an interface

This commit is contained in:
oy 2011-02-27 15:03:57 +01:00
parent 45eee0c8c2
commit d9ce720387
23 changed files with 164 additions and 212 deletions

View file

@ -6,29 +6,42 @@
#include <base/math.h> #include <base/math.h>
#include <base/system.h> #include <base/system.h>
#include <engine/shared/engine.h>
#include <engine/shared/protocol.h> #include <engine/client.h>
#include <engine/shared/snapshot.h> #include <engine/config.h>
#include <engine/shared/compression.h> #include <engine/console.h>
#include <engine/shared/network.h> #include <engine/editor.h>
#include <engine/engine.h>
#include <engine/graphics.h>
#include <engine/input.h>
#include <engine/keys.h>
#include <engine/map.h>
#include <engine/masterserver.h>
#include <engine/serverbrowser.h>
#include <engine/sound.h>
#include <engine/storage.h>
#include <engine/textrender.h>
#include <engine/shared/config.h> #include <engine/shared/config.h>
#include <engine/shared/packer.h> #include <engine/shared/compression.h>
#include <engine/shared/memheap.h>
#include <engine/shared/datafile.h> #include <engine/shared/datafile.h>
#include <engine/shared/ringbuffer.h>
#include <engine/shared/protocol.h>
#include <engine/shared/demo.h> #include <engine/shared/demo.h>
#include <engine/shared/memheap.h>
#include <engine/shared/network.h>
#include <engine/shared/packer.h>
#include <engine/shared/protocol.h>
#include <engine/shared/ringbuffer.h>
#include <engine/shared/snapshot.h>
#include <mastersrv/mastersrv.h> #include <mastersrv/mastersrv.h>
#include <versionsrv/versionsrv.h> #include <versionsrv/versionsrv.h>
#include "srvbrowse.h"
#include "client.h" #include "client.h"
#if defined(CONF_FAMILY_WINDOWS) #if defined(CONF_FAMILY_WINDOWS)
#define _WIN32_WINNT 0x0500 #define _WIN32_WINNT 0x0501
#define NOGDI #define WIN32_LEAN_AND_MEAN
#include <windows.h> #include <windows.h>
#endif #endif
@ -1748,7 +1761,7 @@ void CClient::VersionUpdate()
{ {
if(m_VersionInfo.m_State == 0) if(m_VersionInfo.m_State == 0)
{ {
m_Engine.HostLookup(&m_VersionInfo.m_VersionServeraddr, g_Config.m_ClVersionServer); Engine()->HostLookup(&m_VersionInfo.m_VersionServeraddr, g_Config.m_ClVersionServer);
m_VersionInfo.m_State++; m_VersionInfo.m_State++;
} }
else if(m_VersionInfo.m_State == 1) else if(m_VersionInfo.m_State == 1)
@ -1773,11 +1786,6 @@ void CClient::VersionUpdate()
} }
} }
void CClient::InitEngine(const char *pAppname)
{
m_Engine.Init(pAppname);
}
void CClient::RegisterInterfaces() void CClient::RegisterInterfaces()
{ {
Kernel()->RegisterInterface(static_cast<IDemoRecorder*>(&m_DemoRecorder)); Kernel()->RegisterInterface(static_cast<IDemoRecorder*>(&m_DemoRecorder));
@ -1788,6 +1796,7 @@ void CClient::RegisterInterfaces()
void CClient::InitInterfaces() void CClient::InitInterfaces()
{ {
// fetch interfaces // fetch interfaces
m_pEngine = Kernel()->RequestInterface<IEngine>();
m_pEditor = Kernel()->RequestInterface<IEditor>(); m_pEditor = Kernel()->RequestInterface<IEditor>();
m_pGraphics = Kernel()->RequestInterface<IEngineGraphics>(); m_pGraphics = Kernel()->RequestInterface<IEngineGraphics>();
m_pSound = Kernel()->RequestInterface<IEngineSound>(); m_pSound = Kernel()->RequestInterface<IEngineSound>();
@ -2280,15 +2289,12 @@ int main(int argc, const char **argv) // ignore_convention
} }
#endif #endif
// init the engine
dbg_msg("client", "starting...");
m_Client.InitEngine("Teeworlds");
IKernel *pKernel = IKernel::Create(); IKernel *pKernel = IKernel::Create();
pKernel->RegisterInterface(&m_Client); pKernel->RegisterInterface(&m_Client);
m_Client.RegisterInterfaces(); m_Client.RegisterInterfaces();
// create the components // create the components
IEngine *pEngine = CreateEngine("Teeworlds");
IConsole *pConsole = CreateConsole(CFGFLAG_CLIENT); IConsole *pConsole = CreateConsole(CFGFLAG_CLIENT);
IStorage *pStorage = CreateStorage("Teeworlds", argc, argv); // ignore_convention IStorage *pStorage = CreateStorage("Teeworlds", argc, argv); // ignore_convention
IConfig *pConfig = CreateConfig(); IConfig *pConfig = CreateConfig();
@ -2302,8 +2308,9 @@ int main(int argc, const char **argv) // ignore_convention
{ {
bool RegisterFail = false; bool RegisterFail = false;
RegisterFail = RegisterFail || !pKernel->RegisterInterface(static_cast<IConsole*>(pConsole)); RegisterFail = RegisterFail || !pKernel->RegisterInterface(pEngine);
RegisterFail = RegisterFail || !pKernel->RegisterInterface(static_cast<IConfig*>(pConfig)); RegisterFail = RegisterFail || !pKernel->RegisterInterface(pConsole);
RegisterFail = RegisterFail || !pKernel->RegisterInterface(pConfig);
RegisterFail = RegisterFail || !pKernel->RegisterInterface(static_cast<IEngineGraphics*>(pEngineGraphics)); // register graphics as both RegisterFail = RegisterFail || !pKernel->RegisterInterface(static_cast<IEngineGraphics*>(pEngineGraphics)); // register graphics as both
RegisterFail = RegisterFail || !pKernel->RegisterInterface(static_cast<IGraphics*>(pEngineGraphics)); RegisterFail = RegisterFail || !pKernel->RegisterInterface(static_cast<IGraphics*>(pEngineGraphics));
@ -2332,7 +2339,7 @@ int main(int argc, const char **argv) // ignore_convention
} }
pConfig->Init(); pConfig->Init();
pEngineMasterServer->Init(m_Client.Engine()); pEngineMasterServer->Init();
pEngineMasterServer->Load(); pEngineMasterServer->Load();
// register all console commands // register all console commands
@ -2359,6 +2366,7 @@ int main(int argc, const char **argv) // ignore_convention
m_Client.Engine()->InitLogfile(); m_Client.Engine()->InitLogfile();
// run the client // run the client
dbg_msg("client", "starting...");
m_Client.Run(); m_Client.Run();
// write down the config and quit // write down the config and quit

View file

@ -3,28 +3,6 @@
#ifndef ENGINE_CLIENT_CLIENT_H #ifndef ENGINE_CLIENT_CLIENT_H
#define ENGINE_CLIENT_CLIENT_H #define ENGINE_CLIENT_CLIENT_H
#include <engine/console.h>
#include <engine/editor.h>
#include <engine/graphics.h>
#include <engine/textrender.h>
#include <engine/client.h>
#include <engine/config.h>
#include <engine/serverbrowser.h>
#include <engine/sound.h>
#include <engine/input.h>
#include <engine/keys.h>
#include <engine/map.h>
#include <engine/masterserver.h>
#include <engine/storage.h>
#include <engine/shared/engine.h>
#include <engine/shared/protocol.h>
#include <engine/shared/demo.h>
#include <engine/shared/network.h>
#include "srvbrowse.h"
class CGraph class CGraph
{ {
public: public:
@ -106,6 +84,7 @@ public:
class CClient : public IClient, public CDemoPlayer::IListner class CClient : public IClient, public CDemoPlayer::IListner
{ {
// needed interfaces // needed interfaces
IEngine *m_pEngine;
IEditor *m_pEditor; IEditor *m_pEditor;
IEngineInput *m_pInput; IEngineInput *m_pInput;
IEngineGraphics *m_pGraphics; IEngineGraphics *m_pGraphics;
@ -122,11 +101,10 @@ class CClient : public IClient, public CDemoPlayer::IListner
PREDICTION_MARGIN=1000/50/2, // magic network prediction value PREDICTION_MARGIN=1000/50/2, // magic network prediction value
}; };
CNetClient m_NetClient; class CNetClient m_NetClient;
CDemoPlayer m_DemoPlayer; class CDemoPlayer m_DemoPlayer;
CDemoRecorder m_DemoRecorder; class CDemoRecorder m_DemoRecorder;
CEngine m_Engine; class CServerBrowser m_ServerBrowser;
CServerBrowser m_ServerBrowser;
char m_aServerAddressStr[256]; char m_aServerAddressStr[256];
@ -191,28 +169,30 @@ class CClient : public IClient, public CDemoPlayer::IListner
CGraph m_FpsGraph; CGraph m_FpsGraph;
// the game snapshots are modifiable by the game // the game snapshots are modifiable by the game
CSnapshotStorage m_SnapshotStorage; class CSnapshotStorage m_SnapshotStorage;
CSnapshotStorage::CHolder *m_aSnapshots[NUM_SNAPSHOT_TYPES]; CSnapshotStorage::CHolder *m_aSnapshots[NUM_SNAPSHOT_TYPES];
int m_RecivedSnapshots; int m_RecivedSnapshots;
char m_aSnapshotIncommingData[CSnapshot::MAX_SIZE]; char m_aSnapshotIncommingData[CSnapshot::MAX_SIZE];
CSnapshotStorage::CHolder m_aDemorecSnapshotHolders[NUM_SNAPSHOT_TYPES]; class CSnapshotStorage::CHolder m_aDemorecSnapshotHolders[NUM_SNAPSHOT_TYPES];
char *m_aDemorecSnapshotData[NUM_SNAPSHOT_TYPES][2][CSnapshot::MAX_SIZE]; char *m_aDemorecSnapshotData[NUM_SNAPSHOT_TYPES][2][CSnapshot::MAX_SIZE];
CSnapshotDelta m_SnapshotDelta; class CSnapshotDelta m_SnapshotDelta;
// //
CServerInfo m_CurrentServerInfo; class CServerInfo m_CurrentServerInfo;
int64 m_CurrentServerInfoRequestTime; // >= 0 should request, == -1 got info int64 m_CurrentServerInfoRequestTime; // >= 0 should request, == -1 got info
// version info // version info
struct struct
{ {
int m_State; int m_State;
CHostLookup m_VersionServeraddr; class CHostLookup m_VersionServeraddr;
} m_VersionInfo; } m_VersionInfo;
public: public:
IEngine *Engine() { return m_pEngine; }
IEngineGraphics *Graphics() { return m_pGraphics; } IEngineGraphics *Graphics() { return m_pGraphics; }
IEngineInput *Input() { return m_pInput; } IEngineInput *Input() { return m_pInput; }
IEngineSound *Sound() { return m_pSound; } IEngineSound *Sound() { return m_pSound; }
@ -298,7 +278,6 @@ public:
void Update(); void Update();
void InitEngine(const char *pAppname);
void RegisterInterfaces(); void RegisterInterfaces();
void InitInterfaces(); void InitInterfaces();
@ -327,7 +306,5 @@ public:
void AutoScreenshot_Start(); void AutoScreenshot_Start();
void AutoScreenshot_Cleanup(); void AutoScreenshot_Cleanup();
virtual class CEngine *Engine() { return &m_Engine; }
}; };
#endif #endif

View file

@ -21,14 +21,13 @@
#include <base/system.h> #include <base/system.h>
#include <engine/external/pnglite/pnglite.h> #include <engine/external/pnglite/pnglite.h>
#include <engine/shared/engine.h>
#include <engine/shared/config.h> #include <engine/shared/config.h>
#include <engine/graphics.h> #include <engine/graphics.h>
#include <engine/storage.h> #include <engine/storage.h>
#include <engine/keys.h> #include <engine/keys.h>
#include <engine/console.h> #include <engine/console.h>
#include <math.h> #include <math.h> // cosf, sinf
#include "graphics.h" #include "graphics.h"

View file

@ -1,6 +1,8 @@
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */ /* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
/* If you are missing that file, acquire a complete release at teeworlds.com. */ /* If you are missing that file, acquire a complete release at teeworlds.com. */
#include <base/system.h> #include <base/system.h>
#include <engine/graphics.h>
#include <engine/storage.h>
#include <engine/shared/config.h> #include <engine/shared/config.h>
#include "SDL.h" #include "SDL.h"

View file

@ -4,9 +4,6 @@
#define ENGINE_CLIENT_SOUND_H #define ENGINE_CLIENT_SOUND_H
#include <engine/sound.h> #include <engine/sound.h>
#include <engine/storage.h>
#include <engine/graphics.h>
#include <engine/shared/engine.h>
class CSound : public IEngineSound class CSound : public IEngineSound
{ {

View file

@ -8,7 +8,6 @@
#include <engine/shared/protocol.h> #include <engine/shared/protocol.h>
#include <engine/shared/config.h> #include <engine/shared/config.h>
#include <engine/shared/memheap.h> #include <engine/shared/memheap.h>
#include <engine/shared/engine.h>
#include <engine/masterserver.h> #include <engine/masterserver.h>
#include <engine/console.h> #include <engine/console.h>

31
src/engine/engine.h Normal file
View file

@ -0,0 +1,31 @@
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
/* If you are missing that file, acquire a complete release at teeworlds.com. */
#ifndef ENGINE_ENGINE_H
#define ENGINE_ENGINE_H
#include "kernel.h"
#include <engine/shared/jobs.h>
class CHostLookup
{
public:
CJob m_Job;
char m_aHostname[128];
NETADDR m_Addr;
};
class IEngine : public IInterface
{
MACRO_INTERFACE("engine", 0)
protected:
class CJobPool m_HostLookupPool;
public:
virtual void InitLogfile() = 0;
virtual void HostLookup(CHostLookup *pLookup, const char *pHostname) = 0;
};
extern IEngine *CreateEngine(const char *pAppname);
#endif

View file

@ -15,7 +15,7 @@ public:
MAX_MASTERSERVERS=4 MAX_MASTERSERVERS=4
}; };
virtual void Init(class CEngine *pEngine) = 0; virtual void Init() = 0;
virtual void SetDefault() = 0; virtual void SetDefault() = 0;
virtual int Load() = 0; virtual int Load() = 0;
virtual int Save() = 0; virtual int Save() = 0;

View file

@ -3,7 +3,6 @@
#include <base/system.h> #include <base/system.h>
#include <engine/shared/network.h> #include <engine/shared/network.h>
#include <engine/shared/config.h> #include <engine/shared/config.h>
#include <engine/shared/engine.h>
#include <engine/console.h> #include <engine/console.h>
#include <engine/masterserver.h> #include <engine/masterserver.h>

View file

@ -3,26 +3,22 @@
#include <base/system.h> #include <base/system.h>
#include <engine/shared/config.h> #include <engine/config.h>
#include <engine/shared/engine.h> #include <engine/console.h>
#include <engine/engine.h>
#include <engine/shared/protocol.h> #include <engine/map.h>
#include <engine/shared/snapshot.h> #include <engine/masterserver.h>
#include <engine/server.h>
#include <engine/storage.h>
#include <engine/shared/compression.h> #include <engine/shared/compression.h>
#include <engine/shared/network.h>
#include <engine/shared/config.h> #include <engine/shared/config.h>
#include <engine/shared/packer.h>
#include <engine/shared/datafile.h> #include <engine/shared/datafile.h>
#include <engine/shared/demo.h> #include <engine/shared/demo.h>
#include <engine/shared/network.h>
#include <engine/server.h> #include <engine/shared/packer.h>
#include <engine/map.h> #include <engine/shared/protocol.h>
#include <engine/console.h> #include <engine/shared/snapshot.h>
#include <engine/storage.h>
#include <engine/masterserver.h>
#include <engine/config.h>
#include <mastersrv/mastersrv.h> #include <mastersrv/mastersrv.h>
@ -30,8 +26,8 @@
#include "server.h" #include "server.h"
#if defined(CONF_FAMILY_WINDOWS) #if defined(CONF_FAMILY_WINDOWS)
#define _WIN32_WINNT 0x0500 #define _WIN32_WINNT 0x0501
#define NOGDI #define WIN32_LEAN_AND_MEAN
#include <windows.h> #include <windows.h>
#endif #endif
@ -1046,11 +1042,6 @@ int CServer::LoadMap(const char *pMapName)
return 1; return 1;
} }
void CServer::InitEngine(const char *pAppname)
{
m_Engine.Init(pAppname);
}
void CServer::InitRegister(CNetServer *pNetServer, IEngineMasterServer *pMasterServer, IConsole *pConsole) void CServer::InitRegister(CNetServer *pNetServer, IEngineMasterServer *pMasterServer, IConsole *pConsole)
{ {
m_Register.Init(pNetServer, pMasterServer, pConsole); m_Register.Init(pNetServer, pMasterServer, pConsole);
@ -1062,9 +1053,6 @@ int CServer::Run()
m_pMap = Kernel()->RequestInterface<IEngineMap>(); m_pMap = Kernel()->RequestInterface<IEngineMap>();
m_pStorage = Kernel()->RequestInterface<IStorage>(); m_pStorage = Kernel()->RequestInterface<IStorage>();
//snap_init_id();
net_init();
// //
Console()->RegisterPrintCallback(SendRconLineAuthed, this); Console()->RegisterPrintCallback(SendRconLineAuthed, this);
@ -1495,14 +1483,11 @@ int main(int argc, const char **argv) // ignore_convention
} }
#endif #endif
// init the engine
dbg_msg("server", "starting...");
CServer *pServer = CreateServer(); CServer *pServer = CreateServer();
pServer->InitEngine("Teeworlds");
IKernel *pKernel = IKernel::Create(); IKernel *pKernel = IKernel::Create();
// create the components // create the components
IEngine *pEngine = CreateEngine("Teeworlds");
IEngineMap *pEngineMap = CreateEngineMap(); IEngineMap *pEngineMap = CreateEngineMap();
IGameServer *pGameServer = CreateGameServer(); IGameServer *pGameServer = CreateGameServer();
IConsole *pConsole = CreateConsole(CFGFLAG_SERVER); IConsole *pConsole = CreateConsole(CFGFLAG_SERVER);
@ -1516,6 +1501,7 @@ int main(int argc, const char **argv) // ignore_convention
bool RegisterFail = false; bool RegisterFail = false;
RegisterFail = RegisterFail || !pKernel->RegisterInterface(pServer); // register as both RegisterFail = RegisterFail || !pKernel->RegisterInterface(pServer); // register as both
RegisterFail = RegisterFail || !pKernel->RegisterInterface(pEngine);
RegisterFail = RegisterFail || !pKernel->RegisterInterface(static_cast<IEngineMap*>(pEngineMap)); // register as both RegisterFail = RegisterFail || !pKernel->RegisterInterface(static_cast<IEngineMap*>(pEngineMap)); // register as both
RegisterFail = RegisterFail || !pKernel->RegisterInterface(static_cast<IMap*>(pEngineMap)); RegisterFail = RegisterFail || !pKernel->RegisterInterface(static_cast<IMap*>(pEngineMap));
RegisterFail = RegisterFail || !pKernel->RegisterInterface(pGameServer); RegisterFail = RegisterFail || !pKernel->RegisterInterface(pGameServer);
@ -1530,7 +1516,7 @@ int main(int argc, const char **argv) // ignore_convention
} }
pConfig->Init(); pConfig->Init();
pEngineMasterServer->Init(pServer->Engine()); pEngineMasterServer->Init();
pEngineMasterServer->Load(); pEngineMasterServer->Load();
// register all console commands // register all console commands
@ -1547,9 +1533,10 @@ int main(int argc, const char **argv) // ignore_convention
// restore empty config strings to their defaults // restore empty config strings to their defaults
pConfig->RestoreStrings(); pConfig->RestoreStrings();
pServer->Engine()->InitLogfile(); pEngine->InitLogfile();
// run the server // run the server
dbg_msg("server", "starting...");
pServer->Run(); pServer->Run();
// free // free

View file

@ -48,7 +48,6 @@ public:
class IGameServer *GameServer() { return m_pGameServer; } class IGameServer *GameServer() { return m_pGameServer; }
class IConsole *Console() { return m_pConsole; } class IConsole *Console() { return m_pConsole; }
class IStorage *Storage() { return m_pStorage; } class IStorage *Storage() { return m_pStorage; }
class CEngine *Engine() { return &m_Engine; }
class CClient class CClient
{ {
@ -120,7 +119,6 @@ public:
int m_CurrentMapSize; int m_CurrentMapSize;
CDemoRecorder m_DemoRecorder; CDemoRecorder m_DemoRecorder;
CEngine m_Engine;
CRegister m_Register; CRegister m_Register;
CServer(); CServer();
@ -172,7 +170,6 @@ public:
char *GetMapName(); char *GetMapName();
int LoadMap(const char *pMapName); int LoadMap(const char *pMapName);
void InitEngine(const char *pAppname);
void InitRegister(CNetServer *pNetServer, IEngineMasterServer *pMasterServer, IConsole *pConsole); void InitRegister(CNetServer *pNetServer, IEngineMasterServer *pMasterServer, IConsole *pConsole);
int Run(); int Run();

View file

@ -6,7 +6,6 @@
#include <engine/storage.h> #include <engine/storage.h>
#include "console.h" #include "console.h"
#include "config.h" #include "config.h"
#include "engine.h"
#include "linereader.h" #include "linereader.h"
const char *CConsole::CResult::GetString(unsigned Index) const char *CConsole::CResult::GetString(unsigned Index)

View file

@ -4,7 +4,6 @@
#include <base/system.h> #include <base/system.h>
#include <engine/storage.h> #include <engine/storage.h>
#include "datafile.h" #include "datafile.h"
#include "engine.h"
#include <zlib.h> #include <zlib.h>
static const int DEBUG=0; static const int DEBUG=0;

View file

@ -9,7 +9,6 @@
#include "snapshot.h" #include "snapshot.h"
#include "compression.h" #include "compression.h"
#include "network.h" #include "network.h"
#include "engine.h"
static const unsigned char gs_aHeaderMarker[7] = {'T', 'W', 'D', 'E', 'M', 'O', 0}; static const unsigned char gs_aHeaderMarker[7] = {'T', 'W', 'D', 'E', 'M', 'O', 0};
static const unsigned char gs_ActVersion = 2; static const unsigned char gs_ActVersion = 2;

View file

@ -3,71 +3,11 @@
#include <base/system.h> #include <base/system.h>
#include <engine/engine.h>
#include <engine/shared/config.h> #include <engine/shared/config.h>
#include <engine/shared/engine.h>
#include <engine/shared/network.h> #include <engine/shared/network.h>
#include <engine/console.h> #include <engine/console.h>
#include "linereader.h"
// compiled-in data-dir path
#define DATA_DIR "data"
//static int engine_find_datadir(char *argv0);
/*
static void con_dbg_dumpmem(IConsole::IResult *result, void *user_data)
{
mem_debug_dump();
}
static void con_dbg_lognetwork(IConsole::IResult *result, void *user_data)
{
CNetBase::OpenLog("network_sent.dat", "network_recv.dat");
}*/
/*
static char application_save_path[512] = {0};
static char datadir[512] = {0};
const char *engine_savepath(const char *filename, char *buffer, int max)
{
str_format(buffer, max, "%s/%s", application_save_path, filename);
return buffer;
}*/
void CEngine::Init(const char *pAppname)
{
dbg_logger_stdout();
dbg_logger_debugger();
//
dbg_msg("engine", "running on %s-%s-%s", CONF_FAMILY_STRING, CONF_PLATFORM_STRING, CONF_ARCH_STRING);
#ifdef CONF_ARCH_ENDIAN_LITTLE
dbg_msg("engine", "arch is little endian");
#elif defined(CONF_ARCH_ENDIAN_BIG)
dbg_msg("engine", "arch is big endian");
#else
dbg_msg("engine", "unknown endian");
#endif
// init the network
net_init();
CNetBase::Init();
m_HostLookupPool.Init(1);
//MACRO_REGISTER_COMMAND("dbg_dumpmem", "", CFGFLAG_SERVER|CFGFLAG_CLIENT, con_dbg_dumpmem, 0x0, "Dump the memory");
//MACRO_REGISTER_COMMAND("dbg_lognetwork", "", CFGFLAG_SERVER|CFGFLAG_CLIENT, con_dbg_lognetwork, 0x0, "Log the network");
// reset the config
//config_reset();
}
void CEngine::InitLogfile()
{
// open logfile if needed
if(g_Config.m_Logfile[0])
dbg_logger_file(g_Config.m_Logfile);
}
static int HostLookupThread(void *pUser) static int HostLookupThread(void *pUser)
{ {
@ -76,8 +16,57 @@ static int HostLookupThread(void *pUser)
return 0; return 0;
} }
void CEngine::HostLookup(CHostLookup *pLookup, const char *pHostname) class CEngine : public IEngine
{ {
str_copy(pLookup->m_aHostname, pHostname, sizeof(pLookup->m_aHostname)); public:
m_HostLookupPool.Add(&pLookup->m_Job, HostLookupThread, pLookup); /*
} static void con_dbg_dumpmem(IConsole::IResult *result, void *user_data)
{
mem_debug_dump();
}
static void con_dbg_lognetwork(IConsole::IResult *result, void *user_data)
{
CNetBase::OpenLog("network_sent.dat", "network_recv.dat");
}*/
CEngine(const char *pAppname)
{
dbg_logger_stdout();
dbg_logger_debugger();
//
dbg_msg("engine", "running on %s-%s-%s", CONF_FAMILY_STRING, CONF_PLATFORM_STRING, CONF_ARCH_STRING);
#ifdef CONF_ARCH_ENDIAN_LITTLE
dbg_msg("engine", "arch is little endian");
#elif defined(CONF_ARCH_ENDIAN_BIG)
dbg_msg("engine", "arch is big endian");
#else
dbg_msg("engine", "unknown endian");
#endif
// init the network
net_init();
CNetBase::Init();
m_HostLookupPool.Init(1);
//MACRO_REGISTER_COMMAND("dbg_dumpmem", "", CFGFLAG_SERVER|CFGFLAG_CLIENT, con_dbg_dumpmem, 0x0, "Dump the memory");
//MACRO_REGISTER_COMMAND("dbg_lognetwork", "", CFGFLAG_SERVER|CFGFLAG_CLIENT, con_dbg_lognetwork, 0x0, "Log the network");
}
void InitLogfile()
{
// open logfile if needed
if(g_Config.m_Logfile[0])
dbg_logger_file(g_Config.m_Logfile);
}
void HostLookup(CHostLookup *pLookup, const char *pHostname)
{
str_copy(pLookup->m_aHostname, pHostname, sizeof(pLookup->m_aHostname));
m_HostLookupPool.Add(&pLookup->m_Job, HostLookupThread, pLookup);
}
};
IEngine *CreateEngine(const char *pAppname) { return new CEngine(pAppname); }

View file

@ -1,26 +0,0 @@
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
/* If you are missing that file, acquire a complete release at teeworlds.com. */
#ifndef ENGINE_SHARED_E_ENGINE_H
#define ENGINE_SHARED_E_ENGINE_H
#include "jobs.h"
class CHostLookup
{
public:
CJob m_Job;
char m_aHostname[128];
NETADDR m_Addr;
};
class CEngine
{
class CJobPool m_HostLookupPool;
public:
void Init(const char *pAppname);
void InitLogfile();
void HostLookup(CHostLookup *pLookup, const char *pHostname);
};
#endif

View file

@ -3,9 +3,11 @@
#include <stdio.h> // sscanf #include <stdio.h> // sscanf
#include <base/system.h> #include <base/system.h>
#include <engine/engine.h>
#include <engine/masterserver.h> #include <engine/masterserver.h>
#include <engine/storage.h> #include <engine/storage.h>
#include "engine.h"
#include "linereader.h" #include "linereader.h"
class CMasterServer : public IEngineMasterServer class CMasterServer : public IEngineMasterServer
@ -22,7 +24,8 @@ public:
CMasterInfo m_aMasterServers[MAX_MASTERSERVERS]; CMasterInfo m_aMasterServers[MAX_MASTERSERVERS];
int m_NeedsUpdate; int m_NeedsUpdate;
CEngine *m_pEngine; IEngine *m_pEngine;
IStorage *m_pStorage;
CMasterServer() CMasterServer()
{ {
@ -98,9 +101,10 @@ public:
} }
} }
virtual void Init(class CEngine *pEngine) virtual void Init()
{ {
m_pEngine = pEngine; m_pEngine = Kernel()->RequestInterface<IEngine>();
m_pStorage = Kernel()->RequestInterface<IStorage>();
} }
virtual void SetDefault() virtual void SetDefault()
@ -115,12 +119,11 @@ public:
CLineReader LineReader; CLineReader LineReader;
IOHANDLE File; IOHANDLE File;
int Count = 0; int Count = 0;
IStorage *pStorage = Kernel()->RequestInterface<IStorage>(); if(!m_pStorage)
if(!pStorage)
return -1; return -1;
// try to open file // try to open file
File = pStorage->OpenFile("masters.cfg", IOFLAG_READ, IStorage::TYPE_SAVE); File = m_pStorage->OpenFile("masters.cfg", IOFLAG_READ, IStorage::TYPE_SAVE);
if(!File) if(!File)
return -1; return -1;
@ -161,12 +164,11 @@ public:
{ {
IOHANDLE File; IOHANDLE File;
IStorage *pStorage = Kernel()->RequestInterface<IStorage>(); if(!m_pStorage)
if(!pStorage)
return -1; return -1;
// try to open file // try to open file
File = pStorage->OpenFile("masters.cfg", IOFLAG_WRITE, IStorage::TYPE_SAVE); File = m_pStorage->OpenFile("masters.cfg", IOFLAG_WRITE, IStorage::TYPE_SAVE);
if(!File) if(!File)
return -1; return -1;

View file

@ -4,7 +4,6 @@
#include "config.h" #include "config.h"
#include "engine.h"
#include "network.h" #include "network.h"
#include "huffman.h" #include "huffman.h"

View file

@ -4,7 +4,6 @@
#include "packer.h" #include "packer.h"
#include "compression.h" #include "compression.h"
#include "engine.h"
#include "config.h" #include "config.h"
void CPacker::Reset() void CPacker::Reset()

View file

@ -1,7 +1,6 @@
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */ /* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
/* If you are missing that file, acquire a complete release at teeworlds.com. */ /* If you are missing that file, acquire a complete release at teeworlds.com. */
#include "snapshot.h" #include "snapshot.h"
#include "engine.h"
#include "compression.h" #include "compression.h"
// CSnapshot // CSnapshot

View file

@ -2,7 +2,6 @@
/* If you are missing that file, acquire a complete release at teeworlds.com. */ /* If you are missing that file, acquire a complete release at teeworlds.com. */
#include <base/system.h> #include <base/system.h>
#include <engine/storage.h> #include <engine/storage.h>
#include "engine.h"
#include "linereader.h" #include "linereader.h"
// compiled-in data-dir path // compiled-in data-dir path

View file

@ -7,7 +7,6 @@
#include <engine/graphics.h> #include <engine/graphics.h>
#include <engine/storage.h> #include <engine/storage.h>
#include <engine/shared/engine.h>
#include "skins.h" #include "skins.h"

View file

@ -5,7 +5,6 @@
#include <engine/shared/datafile.h> #include <engine/shared/datafile.h>
#include <engine/shared/config.h> #include <engine/shared/config.h>
#include <engine/shared/engine.h>
#include <engine/client.h> #include <engine/client.h>
#include <engine/console.h> #include <engine/console.h>
#include <engine/graphics.h> #include <engine/graphics.h>