Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/client')
-rw-r--r--src/client/Makefile.am4
-rw-r--r--src/client/application.cc84
-rw-r--r--src/client/application.h33
-rw-r--r--src/client/client.cc96
-rw-r--r--src/client/client.h49
-rw-r--r--src/client/console.h6
-rw-r--r--src/client/input.cc7
-rw-r--r--src/client/main.cc9
8 files changed, 177 insertions, 111 deletions
diff --git a/src/client/Makefile.am b/src/client/Makefile.am
index f8542e2..e191f5f 100644
--- a/src/client/Makefile.am
+++ b/src/client/Makefile.am
@@ -8,12 +8,12 @@ osirion_LDADD = $(top_builddir)/src/math/libmath.la \
$(top_builddir)/src/core/libcore.la \
$(top_builddir)/src/game/libgame.la \
$(top_builddir)/src/gl/libgl.la
-osirion_SOURCES = camera.cc client.cc console.cc hud.cc input.cc main.cc \
+osirion_SOURCES = application.cc camera.cc client.cc console.cc hud.cc input.cc main.cc \
shipdrawer.cc stardrawer.cc video.cc view.cc
INCLUDES = -I$(top_srcdir)/src
osirion_CFLAGS = $(LIBSDL_CFLAGS) $(GL_CFLAGS)
osirion_LDFLAGS = $(LIBSDL_LIBS) $(GL_LIBS)
-noinst_HEADERS = camera.h client.h console.h input.h shipdrawer.h stardrawer.h \
+noinst_HEADERS = application.h camera.h client.h console.h input.h shipdrawer.h stardrawer.h \
video.h view.h
diff --git a/src/client/application.cc b/src/client/application.cc
new file mode 100644
index 0000000..03dda2f
--- /dev/null
+++ b/src/client/application.cc
@@ -0,0 +1,84 @@
+/*
+ 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 <SDL/SDL.h>
+
+// C++ headers
+#include <cmath>
+
+namespace client {
+
+void Application::quit(int status)
+{
+ SDL_Quit();
+ exit(status);
+}
+
+void Application::init()
+{
+ // initialize core
+ core::ApplicationInterface::init();
+
+ con_debug << "Initializing client..." << std::endl;
+
+ // Initialize the video subsystem
+ video.init();
+ if (!video.initialized) {
+ quit(1);
+ }
+
+ // initialize input
+ input.init();
+}
+
+void Application::run()
+{
+ Uint32 chrono = SDL_GetTicks();
+
+ while(true) {
+ Uint32 current = SDL_GetTicks();
+
+ // overflow protection ~49 days
+ if (current < chrono) {
+ chrono = current;
+ }
+
+ // update the game chronometers
+ float elapsed = (float) ( current - chrono) / 1000.0f;
+ chrono = current;
+
+ frame(elapsed);
+
+ // update the video chronometers and draw
+ video.draw(elapsed);
+
+ // process input
+ input.process();
+ }
+
+}
+
+void Application::shutdown()
+{
+ con_debug << "Shutting down client..." << std::endl;
+
+ input.shutdown();
+
+ video.shutdown();
+
+ core::ApplicationInterface::shutdown();
+
+ quit(0);
+
+}
+
+}
diff --git a/src/client/application.h b/src/client/application.h
new file mode 100644
index 0000000..571e5af
--- /dev/null
+++ b/src/client/application.h
@@ -0,0 +1,33 @@
+/*
+ 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();
+
+protected:
+ /// quit the client Application
+ void quit(int result);
+};
+
+}
+#endif // __INCLUDED_CLIENT_APPLICATION_H__
+
diff --git a/src/client/client.cc b/src/client/client.cc
index 7a718a3..e78f73d 100644
--- a/src/client/client.cc
+++ b/src/client/client.cc
@@ -4,91 +4,25 @@
the terms and conditions of the GNU General Public License version 2
*/
-// project headers
-#include "client/client.h"
-#include "game/game.h"
-#include "core/core.h"
-#include "common/common.h"
-
-// SDL headers
-#include <SDL/SDL.h>
+#include "client/application.h"
+#include "client/camera.h"
+#include "client/console.h"
+#include "client/input.h"
+#include "client/video.h"
+#include "client/view.h"
-// C++ headers
-#include <cmath>
+#include "game/game.h"
namespace client {
// public instances
-Camera camera;
-View view;
-Video video;
-Input input;
-
-// private instance of the client console object
-Console console_instance;
-// private instance of the game object
-game::Game game_instance;
-
-void quit(int status)
-{
- SDL_Quit();
- exit(status);
-}
-
-void init()
-{
- // core initializes all the modules
- core::init();
-
- con_debug << "Initializing client..." << std::endl;
-
- // Initialize the video subsystem
- video.init();
- if (!video.initialized) {
- quit(1);
- }
-
- // initialize input
- input.init();
-}
-
-void run()
-{
- Uint32 chrono = SDL_GetTicks();
-
- while(true) {
- Uint32 current = SDL_GetTicks();
-
- // overflow protection ~49 days
- if (current < chrono) {
- chrono = current;
- }
-
- // update the game chronometers
- float elapsed = (float) ( current - chrono) / 1000.0f;
- chrono = current;
-
- core::frame(elapsed);
-
- // update the video chronometers and draw
- video.draw(elapsed);
-
- // process input
- input.process();
- }
-}
-
-void shutdown()
-{
- con_debug << "Shutting down client..." << std::endl;
-
- input.shutdown();
-
- video.shutdown();
-
- core::shutdown();
-
- quit(0);
-}
+Application application;
+Camera camera;
+View view;
+Video video;
+Input input;
+Console console;
+game::Game game;
} // namespace client
+
diff --git a/src/client/client.h b/src/client/client.h
index a25643c..af3e53b 100644
--- a/src/client/client.h
+++ b/src/client/client.h
@@ -7,32 +7,45 @@
#ifndef __INCLUDED_CLIENT_H__
#define __INCLUDED_CLIENT_H__
-#include "client/console.h"
+// project headers
+#include "client/application.h"
#include "client/camera.h"
-#include "client/view.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"
/// 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
*/
namespace client {
- /// initialize the client
- extern void init();
- /// run the client
- extern void run();
- /// shutdown the client
- extern void shutdown();
-
- /// global Video object
- extern Video video;
- /// global Input object
- extern Input input;
- /// global View object
- extern View view;
- /// global Camera object
- extern Camera camera;
-}
+
+/// global Application instance;
+extern Application application;
+
+/// global Video instance
+extern Video video;
+
+/// global Input instance
+extern Input input;
+
+/// global View instance
+extern View view;
+
+/// global Camera instance
+extern Camera camera;
+
+/// global server Console instance
+extern Console console;
+
+/// global Game instance
+extern game::Game game;
+
+} // namespace client
#endif // __INCLUDED_CLIENT_H__
+
diff --git a/src/client/console.h b/src/client/console.h
index 21d5df9..8e8ab02 100644
--- a/src/client/console.h
+++ b/src/client/console.h
@@ -7,12 +7,12 @@
#ifndef __INCLUDED_CLIENT_CONSOLE_H__
#define __INCLUDED_CLIENT_CONSOLE_H__
-#include "common/console.h"
+#include "common/consoleinterface.h"
namespace client {
-/// Interface for a console object that writes messages on the screen
-class Console : public common::Console {
+/// client console implementation
+class Console : public common::ConsoleInterface {
public:
/// stream to send normal messages too
virtual std::ostream & messagestream();
diff --git a/src/client/input.cc b/src/client/input.cc
index b18339e..5f38d35 100644
--- a/src/client/input.cc
+++ b/src/client/input.cc
@@ -12,6 +12,8 @@ namespace client {
void Input::init()
{
+ con_debug << "Initializing input..." << std::endl;
+
//condebug << "SDL_DEFAULT_REPEAT_DELAY " << SDL_DEFAULT_REPEAT_DELAY << std::endl;
//SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
SDL_EnableKeyRepeat(10, SDL_DEFAULT_REPEAT_INTERVAL);
@@ -19,6 +21,7 @@ void Input::init()
void Input::shutdown()
{
+ con_debug << "Shutting down input..." << std::endl;
}
/*
@@ -43,7 +46,7 @@ void Input::handle_keypressed(SDL_keysym* keysym)
{
switch( keysym->sym ) {
case SDLK_ESCAPE:
- client::shutdown();
+ client::application.shutdown();
break;
case SDLK_LEFT:
camera.rotate_left();
@@ -88,7 +91,7 @@ void Input::process()
handle_keyreleased( &event.key.keysym );
break;
case SDL_QUIT:
- client::shutdown();
+ client::application.shutdown();
break;
}
diff --git a/src/client/main.cc b/src/client/main.cc
index 7c5f7b7..6955042 100644
--- a/src/client/main.cc
+++ b/src/client/main.cc
@@ -7,9 +7,8 @@
int main( int argc, char *argv[] )
{
- client::init();
-
- client::run();
-
- client::shutdown();
+ client::application.init();
+ client::application.run();
+ client::application.shutdown();
}
+