From 95ca0e469ef856c0182bb0da411e4417391e3780 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Tue, 5 Feb 2008 00:10:02 +0000 Subject: renamed client and server application objects cleaned up namespaces --- src/client/Makefile.am | 8 +-- src/client/application.cc | 101 ------------------------------------- src/client/application.h | 37 -------------- src/client/camera.cc | 3 ++ src/client/camera.h | 38 ++++---------- src/client/client.cc | 125 +++++++++++++++++++++++++++++++++++++++++++--- src/client/client.h | 26 ++-------- src/client/console.cc | 117 +++++++++++++++++++++++++++++++++---------- src/client/console.h | 56 ++++++++------------- src/client/input.cc | 23 ++++++--- src/client/input.h | 12 ++--- src/client/video.cc | 5 +- src/client/video.h | 24 +++++---- src/client/view.cc | 40 ++++++++++----- src/osirion.cc | 7 ++- src/osiriond.cc | 7 ++- src/server/Makefile.am | 4 +- src/server/application.cc | 66 ------------------------ src/server/application.h | 32 ------------ src/server/console.cc | 61 +++++++++++++++++++++- src/server/console.h | 23 +++------ src/server/server.cc | 97 +++++++++++++++++++++++++++++++++-- src/server/server.h | 11 ++-- 23 files changed, 490 insertions(+), 433 deletions(-) delete mode 100644 src/client/application.cc delete mode 100644 src/client/application.h delete mode 100644 src/server/application.cc delete mode 100644 src/server/application.h diff --git a/src/client/Makefile.am b/src/client/Makefile.am index 4c20c54..a7ca17e 100644 --- a/src/client/Makefile.am +++ b/src/client/Makefile.am @@ -1,13 +1,13 @@ METASOURCES = AUTO INCLUDES = -I$(top_srcdir)/src -libclient_la_SOURCES = application.cc camera.cc client.cc console.cc hud.cc input.cc \ - shipdrawer.cc stardrawer.cc video.cc view.cc +libclient_la_SOURCES = camera.cc client.cc console.cc hud.cc input.cc \ + shipdrawer.cc stardrawer.cc video.cc view.cc libclient_la_CFLAGS = $(LIBSDL_CFLAGS) $(GL_CFLAGS) libclient_la_LDFLAGS = -avoid-version -no-undefined $(GL_LIBS) $(LIBSDL_LIBS) noinst_LTLIBRARIES = libclient.la -noinst_HEADERS = application.h camera.h client.h console.h input.h shipdrawer.h stardrawer.h \ - video.h view.h +noinst_HEADERS = camera.h client.h console.h input.h shipdrawer.h stardrawer.h \ + video.h view.h libclient_la_LIBADD = $(top_builddir)/src/render/librender.la \ $(top_builddir)/src/core/libcore.la $(top_builddir)/src/filesystem/libfilesystem.la \ $(top_builddir)/src/game/libgame.la $(top_builddir)/src/math/libmath.la $(top_builddir)/src/sys/libsys.la diff --git a/src/client/application.cc b/src/client/application.cc deleted file mode 100644 index c8eaab4..0000000 --- a/src/client/application.cc +++ /dev/null @@ -1,101 +0,0 @@ -/* - client/application.cc - This file is part of the Osirion project and is distributed under - the terms and conditions of the GNU General Public License version 2 -*/ - -// project headers -#include "client/client.h" -#include "client/application.h" -#include "core/core.h" - -// SDL headers -#include - -// C++ headers -#include - -namespace client -{ - -extern "C" void func_con_toggle(std::stringstream &args) -{ - console.toggle(); -} - -void Application::quit(int status) -{ - SDL_Quit(); - core::ApplicationInterface::quit(status); -} - -void Application::init() -{ - con_print << "Initializing client..." << std::endl; - // initialize core - core::ApplicationInterface::init(); - - // Initialize the video subsystem - if (!client::video::init()) - quit(1); - - // initialize input - input::init(); - - // register our engine functions - core::func::add("con_toggle", func_con_toggle); -} - -void Application::run() -{ - con_print << "Running client..." << std::endl; - - Uint32 chrono = SDL_GetTicks(); - - while (true) { - Uint32 current = SDL_GetTicks(); - - // overflow protection ~49 days - if (current < chrono) { - chrono = current; - } - - // run a core frame - float seconds = ((float)(current - chrono)) / 1000.0f; - frame(seconds); - - // run a video frame - video::frame(seconds); - if (seconds > 0) - current_fps = floorf(1/seconds); - else - current_fps = 9999; - - // process input - input::frame(seconds); - - // update the main loop chronometer - chrono = current; - } - -} - -void Application::shutdown() -{ - con_print << "Shutting down client..." << std::endl; - console.flush(); - - input::shutdown(); - console.flush(); - - video::shutdown(); - console.flush(); - - core::ApplicationInterface::shutdown(); - console.flush(); - - quit(0); -} - -} // namespace client - diff --git a/src/client/application.h b/src/client/application.h deleted file mode 100644 index 150b24e..0000000 --- a/src/client/application.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - client/application.h - This file is part of the Osirion project and is distributed under - the terms and conditions of the GNU General Public License version 2 -*/ - -#ifndef __INCLUDED_CLIENT_APPLICATION_H__ -#define __INCLUDED_CLIENT_APPLICATION_H__ - -#include "core/applicationinterface.h" - -namespace client -{ - -/// client Application implementation -class Application : public core::ApplicationInterface -{ -public: - /// initialize the client Application - virtual void init(); - - /// run the client Application - virtual void run(); - - /// shutdown the client Application - virtual void shutdown(); - - /// quit the client Application - virtual void quit(int status); - - /// current fps - float current_fps; -}; - -} -#endif // __INCLUDED_CLIENT_APPLICATION_H__ - diff --git a/src/client/camera.cc b/src/client/camera.cc index a0d3ea0..c1ceaa9 100644 --- a/src/client/camera.cc +++ b/src/client/camera.cc @@ -5,6 +5,8 @@ */ #include "client/client.h" +#include "client/camera.h" +#include "render/render.h" #include "math/mathlib.h" using math::degrees360f; @@ -67,6 +69,7 @@ void shutdown() void draw(float elapsed) { + // TODO camera needs to get this from selected core entity if (mode == Track) { yaw_target = game.ship.yaw(); } diff --git a/src/client/camera.h b/src/client/camera.h index dd1ecc3..b1245c8 100644 --- a/src/client/camera.h +++ b/src/client/camera.h @@ -7,56 +7,40 @@ #ifndef __INCLUDED_CLIENT_CAMERA_H__ #define __INCLUDED_CLIENT_CAMERA_H__ -#include "render/render.h" - namespace client { /// camera functions -/** The functions in the camera namespace perform the transformations - * for the camera eye location. The camera always looks at (0,0,0) - */ namespace camera { /// enum indicating the camera mode enum Mode {Free, Track, Overview}; /// initialize the camera - extern void init(); + void init(); /// shutdown the camera - extern void shutdown(); + void shutdown(); /// draw the OpenGL camera transformation - extern void draw(float elapsed); + void draw(float elapsed); /// rotate the camera left - extern void rotate_left(); + void rotate_left(); + /// rotate the camera right - extern void rotate_right(); + void rotate_right(); + /// rotate the camera up - extern void rotate_up(); + void rotate_up(); + /// rotate the camera down - extern void rotate_down(); + void rotate_down(); /// switch to next camera mode - extern void nextmode(); - - /// camera target - /** The location the camera is looking at */ - extern math::Vector3f target; - - /// target yaw, angle in XZ plane, positive is looking left - extern float yaw_target; - /// target pitch, angle in XZ plane, positive is looking left - extern float pitch_target; - /// distance from the camera to the target - extern float distance; - /// current camera mode - extern Mode mode; + void nextmode(); } // namespace camera } // namespace client #endif // __INCLUDED_CLIENT_CAMERA_H__ - diff --git a/src/client/client.cc b/src/client/client.cc index 1d29c23..556e2a7 100644 --- a/src/client/client.cc +++ b/src/client/client.cc @@ -4,22 +4,135 @@ the terms and conditions of the GNU General Public License version 2 */ -#include "client/application.h" +// project headers +#include "client/client.h" +#include "client/video.h" #include "client/camera.h" #include "client/console.h" #include "client/input.h" -#include "client/video.h" #include "client/view.h" - +#include "core/core.h" #include "game/game.h" +// SDL headers +#include + +// C++ headers +#include +#include + namespace client { -// public instances -Application application; -Console console; +//--- private definition ------------------------------------------ +/// client application implementation +class Client : public core::ApplicationInterface +{ +public: + /// initialize the client Client + virtual void init(); + + /// run the client Client + virtual void run(); + + /// shutdown the client Client + virtual void shutdown(); + + /// quit the client Client + virtual void quit(int status); +}; + +Client app; + +//--- public ------------------------------------------------------ game::Game game; +void main(int count, char **arguments) +{ + std::cout << "The Osirion Project " << VERSION << std::endl; + for (int i =0; i < count; i++) + std::cout << arguments[i] << " "; + std::cout << std::endl; + + app.init(); + app.run(); + app.shutdown(); +} + +//--- private ----------------------------------------------------- + +void Client::quit(int status) +{ + SDL_Quit(); + core::ApplicationInterface::quit(status); +} + +void Client::init() +{ + con_print << "Initializing client..." << std::endl; + // initialize core + core::ApplicationInterface::init(); + + // Initialize the video subsystem + if (!client::video::init()) + quit(1); + + // initialize console + console::init(); + + // initialize input + input::init(); +} + +void Client::run() +{ + con_print << "Running client..." << std::endl; + + Uint32 chrono = SDL_GetTicks(); + + while (true) { + Uint32 current = SDL_GetTicks(); + + // overflow protection ~49 days + if (current < chrono) { + chrono = current; + } + + // run a core frame + float seconds = ((float)(current - chrono)) / 1000.0f; + core::ApplicationInterface::frame(seconds); + + // run a video frame + video::frame(seconds); + + // process input + input::frame(seconds); + + // update the main loop chronometer + chrono = current; + } + +} + +void Client::shutdown() +{ + con_print << "Shutting down client..." << std::endl; + console::flush(); + + console::shutdown(); + console::flush(); + + input::shutdown(); + console::flush(); + + video::shutdown(); + console::flush(); + + core::ApplicationInterface::shutdown(); + console::flush(); + + quit(0); +} + } // namespace client diff --git a/src/client/client.h b/src/client/client.h index 3b8b78e..7c0b74d 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -7,37 +7,17 @@ #ifndef __INCLUDED_CLIENT_H__ #define __INCLUDED_CLIENT_H__ -// project headers -#include "client/application.h" -#include "client/camera.h" -#include "client/console.h" -#include "client/input.h" -#include "client/video.h" -#include "client/view.h" - -#include "core/core.h" #include "game/game.h" -#include - -/// client-side functions to render and control the gameworld -/** The client namespace contains the necessary functions to - * accept input, send it to the game and renders the result - */ +/// client part of the engine namespace client { -/// global client Application instance; -extern Application application; - -/// global client Console instance -extern Console console; +/// the client main loop +void main(int count, char **arguments); /// global client Game instance extern game::Game game; -/// current fps -inline float fps() { return (application.current_fps); } - } // namespace client #endif // __INCLUDED_CLIENT_H__ diff --git a/src/client/console.cc b/src/client/console.cc index f435e9a..127481a 100644 --- a/src/client/console.cc +++ b/src/client/console.cc @@ -4,44 +4,83 @@ the terms and conditions of the GNU General Public License version 2 */ -#include "client/client.h" #include "client/console.h" +#include "client/video.h" #include "core/core.h" #include "render/render.h" #include +#include namespace client { -Console::Console() { - console_visible = true; -} +namespace console { -std::ostream & Console::messagestream() -{ - return (buffer << ". "); -} +//--- private definition ------------------------------------------ -std::ostream & Console::warningstream() +/// private client console implementation +class Console : public sys::ConsoleInterface { +public: + /// stream to send normal messages too + virtual std::ostream & messagestream(); + + /// stream to send warning messages too + virtual std::ostream & warningstream(); + + /// stream to send error messages too + virtual std::ostream & errorstream(); + + /// stream to send debug messages too + virtual std::ostream & debugstream(); + + /// console text buffer + std::stringstream buffer; +}; + +// private client console object +Console console; + +// client console input +std::string input; + +// console text data +std::deque text; + +// console visibility +bool console_visible; + +//--- engine functions -------------------------------------------- + +extern "C" void func_con_toggle(std::stringstream &args) { - return (buffer << "* "); + console_visible = !console_visible; } -std::ostream & Console::errorstream() +//--- public ------------------------------------------------------ + +void init() { - return (buffer << "! "); + con_print << "Initializing console..." << std::endl; + + console_visible = false; + + // register our engine functions + core::func::add("con_toggle", func_con_toggle); } -std::ostream & Console::debugstream() +void shutdown() { - return (buffer << "? "); + con_print << "Shutting down console..." << std::endl; + + // unregister our engine functions + core::func::remove("con_toggle"); } -void Console::draw() +void draw() { using namespace render; - console.flush(); + flush(); if(!console_visible) return; @@ -69,9 +108,9 @@ void Console::draw() // draw the console text gl::enable(GL_TEXTURE_2D); - std::deque::reverse_iterator rit = console.text.rbegin(); + std::deque::reverse_iterator rit = text.rbegin(); float y = video::height*con_height-2*CHARHEIGHT-8; - while (y > 0 && rit < console.text.rend()) { + while (y > 0 && rit < text.rend()) { std::string line(*rit); if (line[0] == '?') @@ -94,18 +133,17 @@ void Console::draw() draw_text(CHARWIDTH, video::height*con_height - CHARHEIGHT - 4, input); // draw cursor - if ((core::time() - floorf(core::time())) < 0.5f) { + if ((core::time() - ::floorf(core::time())) < 0.5f) { std::string cursor("_"); draw_text(CHARWIDTH*(input.size()+1), video::height*con_height - CHARHEIGHT - 4 , cursor); } gl::disable(GL_TEXTURE_2D); } -void Console::flush() +void flush() { char line[MAXCMDSIZE]; - while(this->buffer.getline(line, MAXCMDSIZE-1)) { - + while(console.buffer.getline(line, MAXCMDSIZE-1)) { while (text.size() >= MAXCONLINES) { text.pop_front(); } @@ -113,15 +151,15 @@ void Console::flush() std::cout << line << std::endl; } - buffer.clear(); + console.buffer.clear(); } -void Console::toggle() +void toggle() { console_visible = !console_visible; } -void Console::handle_keyreleased(SDL_keysym* keysym) +void handle_keyreleased(SDL_keysym* keysym) { switch( keysym->sym ) { case SDLK_RETURN: @@ -144,4 +182,33 @@ void Console::handle_keyreleased(SDL_keysym* keysym) } } +bool visible() +{ + return console_visible; +} + +//--- private ----------------------------------------------------- + +std::ostream & Console::messagestream() +{ + return (buffer << ". "); +} + +std::ostream & Console::warningstream() +{ + return (buffer << "* "); +} + +std::ostream & Console::errorstream() +{ + return (buffer << "! "); +} + +std::ostream & Console::debugstream() +{ + return (buffer << "? "); +} + +} // namespace console + } // namespace client diff --git a/src/client/console.h b/src/client/console.h index c0d485f..9eeb57e 100644 --- a/src/client/console.h +++ b/src/client/console.h @@ -18,49 +18,35 @@ namespace client { -/// client console implementation -class Console : public sys::ConsoleInterface { -public: - Console(); +/// the client console +namespace console { - /// stream to send normal messages too - virtual std::ostream & messagestream(); +/// initialize client console +/** Adds the engine functions for the client console + */ +void init(); - /// stream to send warning messages too - virtual std::ostream & warningstream(); +/// shutdown the client console +/** Removes the engine functions for the client console + */ +void shutdown(); - /// stream to send error messages too - virtual std::ostream & errorstream(); +/// flush buffer messages and print to stdout +void flush(); - /// stream to send debug messages too - virtual std::ostream & debugstream(); +/// draw the console +void draw(); - /// flush buffer - void flush(); - - /// draw the console - void draw(); +/// toggle the console on or off +void toggle(); - /// toggle the console on or off - void toggle(); - - /// true of the console is visible - inline bool visible() { return console_visible; } +/// handle keyboard input +void handle_keyreleased(SDL_keysym* keysym); - /// toggle handle keyboard input - void handle_keyreleased(SDL_keysym* keysym); - -protected: - /// console text buffer - std::stringstream buffer; - - /// console text data - std::deque text; +/// true of the console is visible +bool visible(); -private: - std::string input; - bool console_visible; -}; +} } diff --git a/src/client/input.cc b/src/client/input.cc index 08fa9ca..91f462c 100644 --- a/src/client/input.cc +++ b/src/client/input.cc @@ -1,11 +1,16 @@ /* - input.cc + client/input.h This file is part of the Osirion project and is distributed under the terms and conditions of the GNU General Public License version 2 */ -//project headers + #include "client/client.h" +#include "client/input.h" +#include "client/console.h" +#include "client/camera.h" + +#include "SDL/SDL.h" namespace client { @@ -60,15 +65,19 @@ void handle_keypressed(SDL_keysym* keysym) camera::rotate_down(); break; case SDLK_KP_PLUS: + // TODO set core entity params game.ship.set_thrust(game.ship.thrust() + 0.08f); break; case SDLK_KP_MINUS: + // TODO set core entity params game.ship.set_thrust(game.ship.thrust() - 0.1f); break; case SDLK_KP4: + // TODO set core entity params game.ship.set_yaw(game.ship.yaw() + 10); break; case SDLK_KP6: + // TODO set core entity params game.ship.set_yaw(game.ship.yaw() - 10); break; default: @@ -90,7 +99,7 @@ void frame(float seconds) client::application.shutdown(); } */ - if (core::connected() && !console.visible()) { + if (core::connected() && !console::visible()) { // send key events to the game world handle_keypressed( &event.key.keysym ); } @@ -98,10 +107,10 @@ void frame(float seconds) case SDL_KEYUP: if (event.key.keysym.sym == '`' || event.key.keysym.sym == '~') { - console.toggle(); - } else if (console.visible()) { + console::toggle(); + } else if (console::visible()) { // send key events to the console - console.handle_keyreleased( &event.key.keysym ); + console::handle_keyreleased( &event.key.keysym ); } else if (core::connected()) { // send key events to the game world handle_keyreleased( &event.key.keysym ); @@ -109,7 +118,7 @@ void frame(float seconds) break; case SDL_QUIT: - client::application.shutdown(); + core::application()->shutdown(); break; } diff --git a/src/client/input.h b/src/client/input.h index 2fc3580..7b5f61a 100644 --- a/src/client/input.h +++ b/src/client/input.h @@ -1,4 +1,4 @@ -/* input.h +/* client/input.h This file is part of the Osirion project and is distributed under the terms and conditions of the GNU General Public License version 2 */ @@ -6,18 +6,18 @@ #ifndef __INCLUDED_INPUT_H__ #define __INCLUDED_INPUT_H__ -#include - namespace client { namespace input { /// initialize the input subsystem -extern void init(); +void init(); + /// shutdown the input subsystem -extern void shutdown(); +void shutdown(); + /// handle one frame of input events -extern void frame(float seconds); +void frame(float seconds); } // namespace input diff --git a/src/client/video.cc b/src/client/video.cc index 47e9dde..bb748d0 100644 --- a/src/client/video.cc +++ b/src/client/video.cc @@ -1,10 +1,11 @@ /* - video.cc + client/video.cc This file is part of the Osirion project and is distributed under the terms and conditions of the GNU General Public License version 2 */ -#include "client/client.h" +#include "client/video.h" +#include "client/view.h" #include "render/render.h" #include "sys/sys.h" diff --git a/src/client/video.h b/src/client/video.h index 314bdbe..2b3fc41 100644 --- a/src/client/video.h +++ b/src/client/video.h @@ -1,5 +1,7 @@ -/* video.h - This file is part of the Osirion project +/* + client/video.h + This file is part of the Osirion project and is distributed under + the terms and conditions of the GNU General Public License version 2 */ #ifndef __INCLUDED_CLIENT_VIDEO_H__ @@ -11,18 +13,23 @@ namespace client { namespace video { /// initialize the client video subsystem - extern bool init(); + bool init(); + /// shutdown the client video subsystem - extern void shutdown(); + void shutdown(); + /// draw the next client video frame - extern void frame(float seconds); + void frame(float seconds); + /// reset and clear the viewport - extern void reset(); + void reset(); - /// width of the SDL window in pixels + /// width of the window in pixels extern int width; - /// height of the SDL window in pixels + + /// height of the window in pixels extern int height; + /// width/height ratio extern float aspect; @@ -31,4 +38,3 @@ namespace video } // namespace client #endif // __INCLUDED_CLIENT_VIDEO_H__ - diff --git a/src/client/view.cc b/src/client/view.cc index 87afd38..07e7cff 100644 --- a/src/client/view.cc +++ b/src/client/view.cc @@ -5,8 +5,11 @@ */ #include "client/client.h" +#include "client/camera.h" +#include "client/console.h" #include "client/shipdrawer.h" #include "client/stardrawer.h" +#include "client/video.h" #include "render/render.h" #include "game/game.h" #include "sys/sys.h" @@ -17,8 +20,6 @@ #include #include -using namespace render; - namespace client { @@ -27,9 +28,10 @@ namespace view ShipDrawer *shipdrawer = 0; StarDrawer *stardrawer = 0; - game::Ship *target = 0; // the view's target +float fps = 0; + void init() { if (!shipdrawer) { @@ -53,6 +55,8 @@ void shutdown() void reset() { + using namespace render; + // set clear color gl::clearcolor(0.0f, 0.0f, 0.0f, 1.0f); @@ -76,6 +80,8 @@ void reset() void draw_world(float elapsed) { + using namespace render; + // draw the world gl::push(); @@ -93,7 +99,7 @@ void draw_world(float elapsed) void draw_background(float elapsed) { - using namespace gl; + using namespace render::gl; // galactic axis begin(Lines); @@ -139,6 +145,8 @@ void draw_background(float elapsed) void draw_loader() { + using namespace render; + gl::enable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, render::textures[0]); // bitmaps/loader.tga gl::color(1.0f, 1.0f, 1.0f, 1.0f); @@ -163,9 +171,9 @@ void draw_loader() void draw_status() { - using namespace std; + using namespace render; - if (console.visible()) + if (console::visible()) return; glBindTexture(GL_TEXTURE_2D, render::textures[1]); // bitmaps/conchars.tga @@ -178,15 +186,15 @@ void draw_status() int hours = (int) sys::time() / 3600; int minutes = (int)(sys::time() - 3600*hours) / 60; int seconds = (int)(sys::time() - 3600*hours - 60 *minutes); - status << " clock " << setfill('0') << setw(2) << hours << ":" - << setfill('0') << setw(2) << minutes << ":" - << setfill('0') << setw(2) << seconds; + status << " clock " << std::setfill('0') << std::setw(2) << hours << ":" + << std::setfill('0') << std::setw(2) << minutes << ":" + << std::setfill('0') << std::setw(2) << seconds; minutes = (int) floorf(core::time() / 60.0f); seconds = (int) floorf(core::time() - (float) minutes* 60.0f); - status << " time " << setfill('0') << setw(2) << minutes << ":" << setfill('0') << setw(2) << seconds; - status << " fps " << setw(4) << client::fps(); + status << " time " << std::setfill('0') << std::setw(2) << minutes << ":" << std::setfill('0') << std::setw(2) << seconds; + status << " fps " << std::setw(4) << fps; draw_text(0, 4, status); // print the version number in the upper right corner @@ -200,6 +208,14 @@ void draw_status() void frame(float seconds) { + using namespace render; + + // calculate frames per second + if (seconds > 0.0f) + fps = floorf(1.0f / seconds); + else + fps = 9999; + // Clear the color and depth buffers. gl::clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -247,7 +263,7 @@ void frame(float seconds) } // draw the console - console.draw(); + console::draw(); // draw the status line draw_status(); diff --git a/src/osirion.cc b/src/osirion.cc index 6955042..058fe25 100644 --- a/src/osirion.cc +++ b/src/osirion.cc @@ -5,10 +5,9 @@ #include "client/client.h" -int main( int argc, char *argv[] ) +int main(int count, char **arguments) { - client::application.init(); - client::application.run(); - client::application.shutdown(); + client::main(count, arguments); + return 0; } diff --git a/src/osiriond.cc b/src/osiriond.cc index 052c68d..ea08f47 100644 --- a/src/osiriond.cc +++ b/src/osiriond.cc @@ -6,9 +6,8 @@ #include "server/server.h" -int main( int argc, char *argv[] ) +int main(int count, char **arguments) { - server::application.init(); - server::application.run(); - server::application.shutdown(); + server::main(count, arguments); + return 0; } diff --git a/src/server/Makefile.am b/src/server/Makefile.am index 6875dbf..0b9ba48 100644 --- a/src/server/Makefile.am +++ b/src/server/Makefile.am @@ -1,6 +1,6 @@ METASOURCES = AUTO -libserver_la_SOURCES = application.cc console.cc server.cc timer.cc -noinst_HEADERS = application.h console.h server.h timer.h +libserver_la_SOURCES = console.cc server.cc timer.cc +noinst_HEADERS = console.h server.h timer.h noinst_LTLIBRARIES = libserver.la INCLUDES = -I$(top_srcdir)/src libserver_la_LDFLAGS = -avoid-version -no-undefined diff --git a/src/server/application.cc b/src/server/application.cc deleted file mode 100644 index 8ea0808..0000000 --- a/src/server/application.cc +++ /dev/null @@ -1,66 +0,0 @@ -/* - server/application.cc - This file is part of the Osirion project and is distributed under - the terms and conditions of the GNU General Public License version 2 -*/ - -// project headers -#include "server/server.h" -#include "server/application.h" -#include "server/timer.h" -#include "core/core.h" -#include "game/game.h" - -namespace server { - -void Application::init() -{ - // FIXME core should be able to load game.so - // force initialization of the game object - server::game = new game::Game(); - - con_print << "Initializing server..." << std::endl; - - // initialize core - core::ApplicationInterface::init(); - - // connect to the game module - core::ApplicationInterface::connect(); -} - -void Application::run() -{ - const float server_framerate = 1.0f / 20.0f; - server::Timer timer; - - timer.mark(); - - while(true) { - float elapsed = timer.elapsed(); - - frame(elapsed); - - sys::sleep(server_framerate - elapsed); - timer.mark(); - } - -} - -void Application::shutdown() -{ - con_debug << "Shutting down server..." << std::endl; - - core::ApplicationInterface::shutdown(); - - quit(0); -} - -void Application::quit(int status) -{ - // FIXME core should be able to unload game.so - delete server::game; - - core::ApplicationInterface::quit(status); -} - -} diff --git a/src/server/application.h b/src/server/application.h deleted file mode 100644 index b081726..0000000 --- a/src/server/application.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - server/application.h - This file is part of the Osirion project and is distributed under - the terms and conditions of the GNU General Public License version 2 -*/ - -#ifndef __INCLUDED_SERVER_APPLICATION_H__ -#define __INCLUDED_SERVER_APPLICATION_H__ - -#include "core/applicationinterface.h" - -namespace server { - -/// server Application implementation -class Application : public core::ApplicationInterface { -public: - /// initialize the server Application - virtual void init(); - - /// run the server Application - virtual void run(); - - /// shutdown the server Application - virtual void shutdown(); - - /// quit the server Application - virtual void quit(int status); -}; - -} -#endif // __INCLUDED_SERVER_APPLICATION_H__ - diff --git a/src/server/console.cc b/src/server/console.cc index a2e8503..a8cc02e 100644 --- a/src/server/console.cc +++ b/src/server/console.cc @@ -5,10 +5,66 @@ */ #include "server/console.h" +#include "core/core.h" + #include -namespace server +namespace server { + +namespace console { + +//--- private definition ------------------------------------------ + +/// server console implementation +class Console : public sys::ConsoleInterface { +public: + /// stream to send normal messages too + virtual std::ostream & messagestream(); + + /// stream to send warning messages too + virtual std::ostream & warningstream(); + + /// stream to send warning messages too + virtual std::ostream & errorstream(); + + /// stream to send debug messages too + virtual std::ostream & debugstream(); + + unsigned long ping; + +}; + +// private console object +Console console; + +//--- engine functions -------------------------------------------- + +extern "C" void func_con_ping(std::stringstream &args) +{ + con_print << "Ping!" << std::endl; + console.ping++; +} + +//--- public ------------------------------------------------------ + +void init() +{ + con_print << "Initializing console..." << std::endl; + + // register our engine functions + core::func::add("con_ping", func_con_ping); +} + +void shutdown() { + con_print << "Shutting down console..." << std::endl; + + // unregister our engine functions + core::func::remove("con_ping"); +} + +//--- private ----------------------------------------------------- + std::ostream & Console::messagestream() { return std::cout; @@ -28,5 +84,6 @@ std::ostream & Console::debugstream() return std::cout; } -} // namespace server +} // namespace console +} // namespace server diff --git a/src/server/console.h b/src/server/console.h index a5f45c3..1d94ba6 100644 --- a/src/server/console.h +++ b/src/server/console.h @@ -11,22 +11,13 @@ namespace server { -/// server console implementation -class Console : public sys::ConsoleInterface { -public: - /// stream to send normal messages too - virtual std::ostream & messagestream(); - - /// stream to send warning messages too - virtual std::ostream & warningstream(); - - /// stream to send warning messages too - virtual std::ostream & errorstream(); - - /// stream to send debug messages too - virtual std::ostream & debugstream(); - -}; +namespace console { + +void init(); + +void shutdown(); + +} // namespace console } // namespace server diff --git a/src/server/server.cc b/src/server/server.cc index fc37aa6..b6b6515 100644 --- a/src/server/server.cc +++ b/src/server/server.cc @@ -4,17 +4,104 @@ the terms and conditions of the GNU General Public License version 2 */ -// project headers - -#include "server/application.h" #include "server/console.h" +#include "server/server.h" +#include "server/timer.h" +#include "core/core.h" #include "game/game.h" namespace server { -Application application; -Console console; +//--- private definition ------------------------------------------ + +/// server Application implementation +class Server : public core::ApplicationInterface { +public: + /// initialize the server Application + virtual void init(); + + /// run the server Application + virtual void run(); + + /// shutdown the server Application + virtual void shutdown(); + + /// quit the server Application + virtual void quit(int status); +}; + +Server app; game::Game *game; +//--- public ------------------------------------------------------ + +/// the server main loop +void main(int count, char **arguments) +{ + std::cout << "The Osirion Project " << VERSION << std::endl; + for (int i =0; i < count; i++) + std::cout << arguments[i] << " "; + std::cout << std::endl; + + app.init(); + app.run(); + app.shutdown(); +} + +//--- private ----------------------------------------------------- + +void Server::init() +{ + // FIXME core should be able to load game.so - + // force initialization of the game object + server::game = new game::Game(); + + con_print << "Initializing server..." << std::endl; + + core::ApplicationInterface::init(); + + console::init(); + + core::ApplicationInterface::connect(); } +void Server::run() +{ + const float server_framerate = 1.0f / 20.0f; + server::Timer timer; + + timer.mark(); + + while(true) { + float elapsed = timer.elapsed(); + + frame(elapsed); + + sys::sleep(server_framerate - elapsed); + timer.mark(); + } + +} + +void Server::shutdown() +{ + con_debug << "Shutting down server..." << std::endl; + + console::shutdown(); + + core::ApplicationInterface::shutdown(); + + quit(0); +} + +void Server::quit(int status) +{ + // FIXME core should be able to unload game.so + delete server::game; + + core::ApplicationInterface::quit(status); +} + + +} // namespace server + diff --git a/src/server/server.h b/src/server/server.h index 7871c5f..29656bd 100644 --- a/src/server/server.h +++ b/src/server/server.h @@ -7,18 +7,13 @@ #ifndef __INCLUDED_SERVER_H__ #define __INCLUDED_SERVER_H__ -#include "server/application.h" -#include "server/console.h" #include "game/game.h" /// contains classes and functions to run a dedicated server namespace server { - -/// global server application instance -extern Application application; - -/// global server console instance -extern Console console; + +/// the server main loop +void main(int count, char **arguments); /// global Game instance extern game::Game *game; -- cgit v1.2.3