Index: configure.ac =================================================================== --- configure.ac (revision 14) +++ configure.ac (working copy) @@ -14,6 +14,9 @@ AC_PROG_INSTALL # Checks for libraries. +AC_CHECK_LIB([Xxf86vm], [main], [], [echo "ERROR: Xxf86vm library not found." && exit 1]) +AC_CHECK_LIB([GL], [main], [], [echo "ERROR: GL library not found." && exit 1]) +AC_CHECK_LIB([GLU], [main], [], [echo "ERROR: GLU library not found." && exit 1]) AC_CHECK_LIB([Irrlicht], [main], [], [echo "ERROR: Irrlicht library not found." && exit 1]) AC_CHECK_LIB([ssl], [main], [], [echo "ERROR: ssl library not found." && exit 1]) AC_CHECK_LIB([crypto], [main], [], [echo "ERROR: ssl crypto library not found." && exit 1]) Index: src/client/Client.cpp =================================================================== --- src/client/Client.cpp (revision 0) +++ src/client/Client.cpp (revision 0) @@ -0,0 +1,144 @@ +#include "common.h" + +#include "Client.h" +#include "ClientNetwork.h" +#include "ClientSession.h" +#include "GUI.h" +#include + +volatile uint8 Client::_clientState = CS_INIT; + + +Client::Client() +{ + sLog.outDebug("Client Master object created"); +} + +Client::~Client() +{ + sLog.outDebug("Client Master object destroyed"); +} + +void Client::SetConfigFile(char *c) +{ + _confFileName = c; +} + + +void Client::HookSignals(void) +{ + signal(SIGINT, _OnSignal); + signal(SIGQUIT, _OnSignal); + signal(SIGTERM, _OnSignal); + signal(SIGABRT, _OnSignal); +#ifdef _WIN32 + signal(SIGBREAK, _OnSignal); +#endif +} + +void Client::UnhookSignals(void) +{ + signal(SIGINT, 0); + signal(SIGQUIT, 0); + signal(SIGTERM, 0); + signal(SIGABRT, 0); +#ifdef _WIN32 + signal(SIGBREAK, 0); +#endif +} + +void Client::Terminate(void) +{ + sLog.outString("Terminating client NOW."); + _clientState = CS_KILL; +} + +void Client::Shutdown(void) +{ + sLog.outString("Client shutdown started..."); + _clientState = CS_SHUTDOWN; +} + + +void Client::_OnSignal(int s) +{ + switch(s) + { + case SIGINT: + case SIGQUIT: + case SIGTERM: + Shutdown(); + break; + + case SIGABRT: +#ifdef _WIN32 + case SIGBREAK: +#endif + Terminate(); + break; + } +} + + + +bool Client::Initialize() +{ + _clientState = CS_INIT; + sLog.outString("Reading config file %s",_confFileName.c_str()); + if(!_ReadConfig()) + { + sLog.outError("Could not read config file. Aborting"); + return false; + } + _ApplyConfig(); + sLog.outString("Starting GUI"); + if(!sGUI.Initialize()) + { + sLog.outError("Could not Initialize GUI. Aborting"); + } + return true; +} + +bool Client::_ReadConfig() +{ + std::string line, vv, vn; + const char *fn = _confFileName.c_str(); + + std::ifstream ifs(fn); + while(getline(ifs,line)) + { + if(line.empty() || (line.at(0)=='/' && line.at(0)=='/') || line.at(0)=='#' ) + { + line.clear(); + continue; + } + while(line.at(0)== ' ' || line.at(0)=='\t') + line.erase(0,1); + vn.clear(); + vv.clear(); + unsigned int pos = line.find("="); + if(pos!=std::string::npos) + { + vn = line.substr(0,pos); + vv = line.substr(pos+1,line.length()-1); + _confvars[vn] = vv; + DEBUG_LOG("Var import [%s] = '%s'",vn.c_str(),vv.c_str()); + } + line.clear(); + } + ifs.close(); +} + +void Client::_ApplyConfig() +{ + _config.LoginserverAdress=(_confvars["Login.Server.IP"].size()>0)?_confvars["Login.Server.IP"]:"127.0.0.1"; + _config.LoginserverPort=(_confvars["Login.Server.Port"].size()>0)?atoi(_confvars["Login.Server.Port"].c_str()):9066; + _config.GUIwidth=(_confvars["GUI.width"].size()>0)?atoi(_confvars["GUI.width"].c_str()):800; + _config.GUIheight=(_confvars["GUI.height"].size()>0)?atoi(_confvars["GUI.height"].c_str()):600; + _config.GUIbitdepth=(_confvars["GUI.bitdepth"].size()>0)?atoi(_confvars["GUI.bitdepth"].c_str()):16; +} + +Client& Client::Instance() +{ + return *ACE_Singleton::instance(); +} \ No newline at end of file Index: src/client/Client.h =================================================================== --- src/client/Client.h (revision 0) +++ src/client/Client.h (revision 0) @@ -0,0 +1,64 @@ +#ifndef CLIENT_H +#define CLIENT_H + +#include +#include +#include + + +#include "common.h" + +/* This is the main Client class */ +/* It should handle: + - client settings + - client states + - connection to the server + +*/ +enum ClientStates +{ + CS_INIT = 0, //Initial State, not connected to login server + CS_LOGINSCREEN = 1, //connected to loginserver + CS_INGAME = 2, //logged in + CS_SHUTDOWN = 3, //shutting down + CS_KILL = 4, //go down in flames + CS_COUNT = 5 +}; + +struct ClientConfig +{ + std::string LoginserverAdress; + uint16 LoginserverPort; + uint16 GUIwidth, GUIheight; + uint8 GUIbitdepth; +}; + +class Client +{ +public: + Client(); + ~Client(); + static Client& Instance(); + + bool Initialize(void); + void SetConfigFile(char*); + inline const ClientConfig *GetConfig(void) { return &_config; } + static void HookSignals(void); + static void UnhookSignals(void); + static void Shutdown(void); + static void Terminate(void); + + static volatile uint8 _clientState; + +private: + static void _OnSignal(int); + std::string _confFileName; + ClientConfig _config; + std::map _confvars; // plaintext config variables + bool _ReadConfig(void); + void _ApplyConfig(void); + +}; +#define sClient Client::Instance() + +#endif \ No newline at end of file Index: src/client/main.cpp =================================================================== --- src/client/main.cpp (revision 14) +++ src/client/main.cpp (working copy) @@ -164,26 +164,56 @@ #include #include */ +#include "Client.h" +#include "GUI.h" #include "ClientNetwork.h" #include "ClientSession.h" #include "GamePacket.h" #include "mycrc32.h" #include "BigNumber.h" +#ifndef _DEBUG +#define CLIENT_VERSION "Die Zwerge - Game Client V 0.0.001" +#else +#define CLIENT_VERSION "Die Zwerge - Game Client V 0.0.001-debug" +#endif + + + int main(int argc, char **argv) { + sLog.outString("Platform: %s",PLATFORM_NAME); + sLog.outString("Compiler: %s ("COMPILER_VERSION_OUT")",COMPILER_NAME,COMPILER_VERSION); + sLog.outString("Compiled: %s %s",__DATE__,__TIME__); + sLog.outString(""); + sLog.outString("Client: "CLIENT_VERSION" starting up..."); + sLog.outString(""); + + sClient.SetConfigFile("client.conf"); + + if(sClient.Initialize()) + { + sLog.outString("Init completed."); + } + else + { + sLog.outString("Init failed for some reason, exiting..."); + return 0; + } + sClient.HookSignals(); + + network.SetCompression(9); network.SetCompressionMinsize(70); network.SetEncrypt(false); network.SetStreamBuildInterval(50); - if(!network.Connect("127.0.0.1", 9066)) + if(!network.Connect(sClient.GetConfig()->LoginserverAdress.c_str(), sClient.GetConfig()->LoginserverPort)) { sLog.outError("Unable to connect!"); ACE_OS::sleep(1); return 1; } - - session.SetLoginData("test", "test"); + session.SetLoginData("test", "test"); GamePacket pkt(OPCODE_HELLO, 15); pkt << "DZWC"; @@ -196,7 +226,7 @@ sLog.outDebug("Sending NOW"); session.SendPacket(pkt); - while(network.IsConnected()) + while(network.IsConnected() && sClient._clientState::instance(); +} + +GUI::GUI() +{ + sLog.outDebug("GUI object created"); +} + +GUI::~GUI() +{ + _guithread->wait(); + delete _guithread; + _guithread = NULL; + _device->drop(); + _device=NULL; + + sLog.outDebug("GUI object destroyed"); +} + +bool GUI::Initialize() +{ + _device = createDevice(video::EDT_OPENGL, core::dimension2d(sClient.GetConfig()->GUIwidth, sClient.GetConfig()->GUIheight), sClient.GetConfig()->GUIbitdepth, false, false, false, 0); + _driver = _device->getVideoDriver(); + _guienv = _device->getGUIEnvironment(); + _smgr = _device->getSceneManager(); + ACE_OS::sleep(2); + + ACE_Based::Runnable *r = new GUIRunnable();//Probably an evil hackish way to do it. + _guithread = new ACE_Based::Thread(*r); + + +return true; +} + + + + +uint32 GUI::Run() +{ + sLog.outDebug("Starting GUI Run"); + while(sClient._clientStatebeginScene(true, true, video::SColor(255,100,101,140)))sClient._clientState=CS_SHUTDOWN; + _smgr->drawAll(); + _guienv->drawAll(); + _driver->endScene(); + core::stringw str = L"Irrlicht Engine ["; + str += _driver->getName(); + str += L"] FPS: "; + str += (s32)_driver->getFPS(); + + _device->setWindowCaption(str.c_str()); + + } +} +/* + + + MyEventReceiver receiver; + + device->setEventReceiver(&receiver); + + ITimer* timer = device->getTimer(); + + // set atributes of terrain + s32 terrainWidth = 500; + s32 terrainHeight = 500; + s32 meshSize = 100; + f32 tileSize = 1; + core::vector3df terrainPos(0.0f, 0.0f, 0.0f); + + // setup camera + MCameraFPS camera(smgr); + camera.setNearValue(0.1f); + camera.setFarValue(600); + camera.setPosition(core::vector3df(terrainWidth*tileSize/2, 0, terrainHeight*tileSize/2) + terrainPos); + + // create terrain scene node + ShTlTerrainSceneNode* terrain = new ShTlTerrainSceneNode(smgr, terrainWidth, terrainHeight, tileSize, meshSize); + terrain->drop(); + + terrain->setPosition(terrainPos); + + terrain->getMaterial(0).setTexture(1,driver->getTexture("cdata/dirt.bmp")); + terrain->getMaterial(0).setFlag(video::EMF_LIGHTING, true); + terrain->getMaterial(0).setFlag(video::EMF_FOG_ENABLE, true); + + // set terrain to render around camera + terrain->follow(camera.getNode()); + + // randomize terrain + makeRandomHills(terrain, 2000, 20); + makeRandomHills(terrain, 10000, 5); + + terrain->smoothNormals(); + + randomizeColor(terrain); + + randomizeUV(terrain); + + gui::IGUIFont* font = guienv->getFont("cdata/cityblueprint.bmp"); + guienv->getSkin()->setFont(font); + + // movement speed per second + f32 speed = 15.0f * tileSize; + + // time + f32 time = 0; + f32 oldtime; + // time between frames + f32 deltaT; + + IMouse& mouse = receiver.mouse; + IKeys& key = receiver.key; + + bool debugmode = false; + + vector3df cpos = camera.getPosition(); + vector3df lpos = cpos; + ISceneNode *node; + + + //smgr->addLightSceneNode(0, vector3df(40,-40,40),SColorf(1.0f,0.5f,0.5f), 100.0f); + + scene::ILightSceneNode* light = smgr->addLightSceneNode(0, core::vector3df(0,0,0), video::SColorf(1, 1, 1, 1), 1000.0f); + video::SLight& ldata = light->getLightData(); + ldata.AmbientColor = video::SColorf(0.2f,0.2f,0.2f); + ldata.DiffuseColor = video::SColorf(1.f,1.f,1.f); + ldata.SpecularColor = video::SColorf(0.5f,0.5f,0.5f); + ldata.Type = video::ELT_POINT; + ldata.Position = lpos + vector3df(0,15,0); + node = smgr->addCubeSceneNode(1); + if (node->getMaterialCount()) + { + node->getMaterial(0).setFlag(video::EMF_LIGHTING, true); + node->getMaterial(0).setFlag(video::EMF_FOG_ENABLE, true); + node->getMaterial(0).AmbientColor = SColor(255,255,255,255); + node->getMaterial(0).EmissiveColor = SColor(255,0,0,100); + node->getMaterial(0).SpecularColor = SColor(255,255,255,255); + node->getMaterial(0).Shininess = 20; + } + node->setPosition(light->getLightData().Position); + + terrain->getMaterial(0); + terrain->getMaterial(0).Shininess = 20; + terrain->getMaterial(0).SpecularColor = SColor(100,100,100,100); + + + + IGUIStaticText *text = guienv->addStaticText(L"Text",rect(0,0,500,50),true,true); + + + while(device->run()) + { + driver->beginScene(true, true, video::SColor(255,100,101,140)); + + // calculate time between frames + oldtime = time; + time = (f32)timer->getTime() / 1000.0f; + deltaT = time - oldtime; + + // camera movement control + if(key.pressed(KEY_KEY_W)) camera.moveForward(speed * deltaT); + if(key.pressed(KEY_KEY_S)) camera.moveBack(speed * deltaT); + if(key.pressed(KEY_KEY_D)) camera.moveRight(speed * deltaT); + if(key.pressed(KEY_KEY_A)) camera.moveLeft(speed * deltaT); + if(key.pressed_once(KEY_BACK)) + { + debugmode = !debugmode; + terrain->setDebugDataVisible(debugmode ? EDS_FULL : EDS_OFF); + } + + cpos = camera.getPosition(); + + // mouse directional control + camera.turnRight(50 * (device->getCursorControl()->getRelativePosition().X - 0.5f)); + camera.turnUp(50 * (device->getCursorControl()->getRelativePosition().Y - 0.5f)); + device->getCursorControl()->setPosition(0.5f, 0.5f); + + // camera height control + if (mouse.wheel < 10) mouse.wheel = 10; + //camera.setHeight( mouse.wheel/10 + terrain->getHeight(camera.getPosition()) ); + camera.setHeight( 5 + terrain->getHeight(camera.getPosition()) ); + + char t[300]; + sprintf(t,"CAM: X=%.3f Y=%.3f Z=%.3f",cpos.X, cpos.Y, cpos.Z); + stringw tw = t; + text->setText(tw.c_str()); + + + + smgr->drawAll(); + guienv->drawAll(); + + driver->endScene(); + + } + + device->drop(); + + + return 0; +*/ \ No newline at end of file Index: src/client/ClientNetwork.cpp =================================================================== --- src/client/ClientNetwork.cpp (revision 14) +++ src/client/ClientNetwork.cpp (working copy) @@ -283,7 +283,7 @@ DEBUG_LOG("Network workers initialized."); } -bool ClientNetwork::Connect(char *addr, uint32 port) +bool ClientNetwork::Connect(const char *addr, uint32 port) { sLog.outDebug("Connecting..."); ACE_INET_Addr server_addr(port, addr); Index: src/client/Makefile.am =================================================================== --- src/client/Makefile.am (revision 14) +++ src/client/Makefile.am (working copy) @@ -6,7 +6,9 @@ main.cpp\ ClientNetwork.cpp\ ClientSession.cpp\ - ShTlTerrainSceneNode.cpp + ShTlTerrainSceneNode.cpp\ + Client.cpp\ + GUI.cpp client_LDADD = $(top_builddir)/src/shared/libshared.a\ $(top_builddir)/src/ace/libACE.la\ Index: src/client/GUI.h =================================================================== --- src/client/GUI.h (revision 0) +++ src/client/GUI.h (revision 0) @@ -0,0 +1,34 @@ +#ifndef GUI_H +#define GUI_H + +#include + + +#include "common.h" +using namespace irr; + +class GUIRunnable : public ACE_Based::Runnable +{ +public: + GUIRunnable(); + void run(void); +}; + +class GUI +{ +public: + GUI(); + ~GUI(); + static GUI& Instance(); + uint32 Run(); + bool Initialize(void); +private: +IrrlichtDevice* _device; +video::IVideoDriver* _driver; +gui::IGUIEnvironment* _guienv; +scene::ISceneManager* _smgr; +ACE_Based::Thread *_guithread; +}; +#define sGUI GUI::Instance() + +#endif \ No newline at end of file Index: src/client/ClientNetwork.h =================================================================== --- src/client/ClientNetwork.h (revision 14) +++ src/client/ClientNetwork.h (working copy) @@ -44,7 +44,7 @@ ~ClientNetwork(); static ClientNetwork& instance(void); - bool Connect(char *addr, uint32 port); + bool Connect(const char *addr, uint32 port); void Send(GamePacket *packet); // Hint: Send NULL to shutdown outgoing network void SetStreamBuildInterval(uint32 ms); void SetCrypt(PktCrypt *crypt); Index: bin/misc/client.conf =================================================================== --- bin/misc/client.conf (revision 0) +++ bin/misc/client.conf (revision 0) @@ -0,0 +1,10 @@ +###################################### +# Client configuration settings # +###################################### + +Server.Login.IP=127.0.0.1 +Server.Login.Port=9066 + +GUI.width=800 +GUI.height=600 +GUI.bitdepth=16 \ No newline at end of file