diff options
author | Stijn Buys <ingar@osirion.org> | 2007-10-22 17:44:54 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2007-10-22 17:44:54 +0000 |
commit | 8a4aa60b830467d81f8029c194bec5b2e74ceb17 (patch) | |
tree | a32662287892a41ffa7fd55ab2d80f6040dedfb9 /src | |
parent | aa33bc22ec4cd14e200ba9e09c43e884a2101a74 (diff) |
basic system console (new files)
Diffstat (limited to 'src')
-rw-r--r-- | src/client/client.cc | 80 | ||||
-rw-r--r-- | src/client/client.h | 37 | ||||
-rw-r--r-- | src/client/console.cc | 28 | ||||
-rw-r--r-- | src/client/console.h | 31 | ||||
-rw-r--r-- | src/common/console.cc | 14 | ||||
-rw-r--r-- | src/common/console.h | 40 | ||||
-rw-r--r-- | src/server/console.cc | 27 | ||||
-rw-r--r-- | src/server/console.h | 31 |
8 files changed, 288 insertions, 0 deletions
diff --git a/src/client/client.cc b/src/client/client.cc new file mode 100644 index 0000000..14e6bb5 --- /dev/null +++ b/src/client/client.cc @@ -0,0 +1,80 @@ +/* + client/client.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 "camera.h" +#include "view.h" +#include "video.h" +#include "input.h" +#include "console.h" + +#include "game/game.h" +#include "osirion.h" + +#include <SDL/SDL.h> + +namespace client { + +Camera camera; +View view; +Video video; +Input input; + +void quit(int status) +{ + SDL_Quit(); + exit(status); +} + +void init() +{ + // initialize console + Console clientconsole; + common::Console::instance = &clientconsole; + + conmesg << "Project::OSiRiON " << OSIRION_VERSION << std::endl; + + // Initialize the video subsystem + video.init(); + if (!video.initialized) { + quit(1); + } + + // initialize input + input.init(); + + // initialize game + game::init(); +} + +void run() +{ + Uint32 startup = SDL_GetTicks(); + while(game::initialized) { + Uint32 chrono = SDL_GetTicks(); + + // overflow protection ~49 days + if (chrono < startup) { + startup = chrono; + } + + // update the game chronometers + float elapsed = (float) ( chrono - startup) / 1000.0f; + game::update(elapsed); + + // update the video chronometers and draw + video.draw(elapsed); + startup = chrono; + + // process input + input.process(); + } + + input.shutdown(); + video.shutdown(); + quit(0); +} + +} // namespace client diff --git a/src/client/client.h b/src/client/client.h new file mode 100644 index 0000000..613061a --- /dev/null +++ b/src/client/client.h @@ -0,0 +1,37 @@ +/* + client/client.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 +*/ + +#include "camera.h" +#include "view.h" +#include "input.h" +#include "video.h" +#include "console.h" + +#ifndef __INCLUDED_CLIENT_H__ +#define __INCLUDED_CLIENT_H__ + +/// 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 render the result + */ +namespace client { + /// initialize the client + extern void init(); + /// run the client(); + extern void run(); + + /// global Video object + extern Video video; + /// global Input object + extern Input input; + /// global View object + extern View view; + /// global Camera object + extern Camera camera; +} + +#endif // __INCLUDED_CLIENT_H__ diff --git a/src/client/console.cc b/src/client/console.cc new file mode 100644 index 0000000..21dde67 --- /dev/null +++ b/src/client/console.cc @@ -0,0 +1,28 @@ +/* + client/console.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 "console.h" +#include <iostream> + +namespace client { + +std::ostream & Console::message() +{ + return std::cout; +} + +std::ostream & Console::warning() +{ + return std::cerr; +} + +std::ostream & Console::debug() +{ + return std::cout; +} + +} // namespace client + diff --git a/src/client/console.h b/src/client/console.h new file mode 100644 index 0000000..1dc7109 --- /dev/null +++ b/src/client/console.h @@ -0,0 +1,31 @@ +/* + client/console.h + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 +*/ + +#ifndef __INCLUDED_CLIENTCONSOLE_H__ +#define __INCLUDED_CLIENTCONSOLE_H__ + +#include "common/console.h" + +namespace client { + +/// Interface for a console object that writes messages on the screen +class Console : public common::Console { +public: + /// stream to send normal messages too + virtual std::ostream & message(); + + /// stream to send warning messages too + virtual std::ostream & warning(); + + /// stream to send debug messages too + virtual std::ostream & debug(); + +}; // class Console + +} // namespace server + +#endif // __INCLUDED_CLIENTCONSOLE_H__ + diff --git a/src/common/console.cc b/src/common/console.cc new file mode 100644 index 0000000..7641865 --- /dev/null +++ b/src/common/console.cc @@ -0,0 +1,14 @@ +/* + common/console.cc + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 +*/ + +#include "console.h" + +namespace common { + + Console *Console::instance = 0; + +} // namespace common + diff --git a/src/common/console.h b/src/common/console.h new file mode 100644 index 0000000..609c99a --- /dev/null +++ b/src/common/console.h @@ -0,0 +1,40 @@ +/* + common/console.h + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 +*/ + +#ifndef __INCLUDED_CONSOLE_H__ +#define __INCLUDED_CONSOLE_H__ + +// C++ headers +#include <iostream> + +/// global define to send a message to the system console +#define conmesg common::Console::instance->message() +/// global define to send a warning message to the system console +#define conwarn common::Console::instance->warning() +/// global define to send a debug message to the system console +#define condebug common::Console::instance->debug() + +namespace common { + +/// Interface for a console object that writes messages on the screen +class Console { +public: + /// stream to send normal messages too + virtual std::ostream & message() = 0; + + /// stream to send warning messages too + virtual std::ostream & warning() = 0; + + /// stream to send debug messages too + virtual std::ostream & debug() = 0 ; + + static Console *instance; +}; // class Console + +} // namespace common + +#endif // __INCLUDED_CONSOLE_H__ + diff --git a/src/server/console.cc b/src/server/console.cc new file mode 100644 index 0000000..40b752d --- /dev/null +++ b/src/server/console.cc @@ -0,0 +1,27 @@ +/* + server/console.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 "console.h" +#include <iostream> + +namespace server { +std::ostream & Console::message() +{ + return std::cout; +} + +std::ostream & Console::warning() +{ + return std::cerr; +} + +std::ostream & Console::debug() +{ + return std::cout; +} + +} // namespace server + diff --git a/src/server/console.h b/src/server/console.h new file mode 100644 index 0000000..69f2ea8 --- /dev/null +++ b/src/server/console.h @@ -0,0 +1,31 @@ +/* + server/console.h + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 +*/ + +#ifndef __INCLUDED_SERVERCONSOLE_H__ +#define __INCLUDED_SERVERCONSOLE_H__ + +#include "common/console.h" + +namespace server { + +/// Interface for a console object that writes messages on the screen +class Console : public common::Console { +public: + /// stream to send normal messages too + virtual std::ostream & message(); + + /// stream to send warning messages too + virtual std::ostream & warning(); + + /// stream to send debug messages too + virtual std::ostream & debug(); + +}; // class Console + +} // namespace server + +#endif // __INCLUDED_SERVERCONSOLE_H__ + |