summaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
authorVegard Storheil Eriksen <zyp@jvnv.net>2010-06-25 23:05:47 +0200
committerVegard Storheil Eriksen <zyp@jvnv.net>2010-06-25 23:05:47 +0200
commitb50d18f3f882865a94458c7113aedd7a0cccce80 (patch)
treedcaacd6f02b0622a6c8979a49373d64179524b61 /engine
parent445d92dbb16d443e201f3a7ac73d4fa5ba6c2697 (diff)
Moved Application to wriggle.
Diffstat (limited to 'engine')
-rw-r--r--engine/application.h42
-rw-r--r--engine/engine.cpp (renamed from engine/application.cpp)104
-rw-r--r--engine/engine.h32
3 files changed, 47 insertions, 131 deletions
diff --git a/engine/application.h b/engine/application.h
deleted file mode 100644
index b7fc36a..0000000
--- a/engine/application.h
+++ /dev/null
@@ -1,42 +0,0 @@
-#ifndef APPLICATION_H
-#define APPLICATION_H
-
-#include <SDL/SDL.h>
-#include <FTGL/ftgl.h>
-#include <vector>
-
-#include "stage.h"
-
-#include "bulletpattern.h"
-#include <wriggle/shader.h>
-#include <wriggle/texture.h>
-
-class Application {
- private:
- SDL_Surface *surface;
- bool please_quit;
-
- bool paused;
- unsigned int lasttick;
- unsigned int frames;
- unsigned int lastframes;
- float fps;
-
- FTFont* font;
- Texture* background;
-
- public:
- Stage* stage;
-
- Application();
- ~Application();
- void run();
- void quit();
-
- protected:
- virtual void event_keypress(SDLKey key);
-
- void main_loop(unsigned int tick);
-};
-
-#endif
diff --git a/engine/application.cpp b/engine/engine.cpp
index ab66bf4..4c7d426 100644
--- a/engine/application.cpp
+++ b/engine/engine.cpp
@@ -1,4 +1,4 @@
-#include "application.h"
+#include "engine.h"
#include "config.h"
@@ -7,49 +7,24 @@
#include <SDL/SDL_opengl.h>
#include <iostream>
-#include <stdexcept>
#include <cmath>
#include <boost/format.hpp>
-Application::Application() {
- // Initialize SDL
- if(SDL_Init(SDL_INIT_VIDEO)) {
- throw(std::runtime_error("SDL initialization failed"));
- }
- // Fetch the video info
- const SDL_VideoInfo *info = SDL_GetVideoInfo();
- if(!info) {
- throw(std::runtime_error("SDL info query failed"));
- }
- // The SDL mode-flags
- int flags = SDL_OPENGL; // OpenGL in SDL
- flags |= SDL_GL_DOUBLEBUFFER; // Double buffering
- flags |= SDL_HWPALETTE; // Hardware palette
- // Check for hardware surface aviability
- if(info->hw_available) {
- flags |= SDL_HWSURFACE;
- } else {
- flags |= SDL_SWSURFACE;
- }
- // Check for hardware blit ability
- if(info->blit_hw) {
- flags |= SDL_HWACCEL;
- }
- // Setup double buffering
- SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
-
- SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
-
- SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1);
-
- // Get our surface
- surface = SDL_SetVideoMode(Config::window_w, Config::window_h, 32, flags);
- if(!surface) {
- throw(std::runtime_error("Video mode set failed"));
+void Engine::event_keypress(SDLKey key) {
+ switch(key) {
+ case SDLK_SPACE:
+ paused = !paused;
+ break;
+ default:
+ Application::event_keypress(key);
}
+}
+Engine::Engine() {
+ init_window(Config::window_w, Config::window_h);
+
// Texturing
glEnable(GL_TEXTURE_2D);
// Blending
@@ -69,46 +44,14 @@ Application::Application() {
glClearColor(0, 0, 0, 0);
glClearDepth(1);
- please_quit = false;
-}
-
-Application::~Application() {
-
-}
-
-void Application::run() {
- paused = false;
-
font = new FTTextureFont("fonts/VeraMono.ttf");
font->FaceSize(20);
background = new TextureSDL("textures/background.png");
- lasttick = SDL_GetTicks();
-
- while(1) {
- SDL_Event event;
- while(SDL_PollEvent(&event)) {
- if(event.type == SDL_QUIT) {
- break;
- } else if(event.type == SDL_KEYDOWN) {
- event_keypress(event.key.keysym.sym);
- }
- }
-
- if(please_quit) {
- return;
- }
-
- unsigned int tick = SDL_GetTicks();
- lasttick = tick;
-
- main_loop(tick);
-
- //SDL_Delay(10);
- }
+ paused = false;
}
-void Application::main_loop(unsigned int tick) {
+void Engine::update() {
if(!paused) {
stage->update();
}
@@ -141,6 +84,7 @@ void Application::main_loop(unsigned int tick) {
glDisable(GL_TEXTURE_2D);
glColor4f(1, 1, 0, 1);
+ unsigned int tick = SDL_GetTicks();
if(tick - lastframes >= 1000) {
fps = (float)frames * ((float)(tick - lastframes) / 1000.0f);
frames = 1;
@@ -213,21 +157,3 @@ void Application::main_loop(unsigned int tick) {
SDL_GL_SwapBuffers();
}
-
-void Application::quit() {
- please_quit = true;
-}
-
-void Application::event_keypress(SDLKey key) {
- switch(key) {
- case SDLK_ESCAPE:
- quit();
- break;
- case SDLK_SPACE:
- paused = !paused;
- lasttick = SDL_GetTicks();
- break;
- default:
- break;
- }
-}
diff --git a/engine/engine.h b/engine/engine.h
new file mode 100644
index 0000000..894143e
--- /dev/null
+++ b/engine/engine.h
@@ -0,0 +1,32 @@
+#ifndef ENGINE_H
+#define ENGINE_H
+
+#include <wriggle/application.h>
+
+#include <FTGL/ftgl.h>
+
+#include "stage.h"
+
+class Engine : public Application {
+ private:
+ FTFont* font;
+ Texture* background;
+
+ bool paused;
+
+ unsigned int frames;
+ unsigned int lastframes;
+ float fps;
+
+ protected:
+ virtual void event_keypress(SDLKey key);
+
+ virtual void update();
+
+ public:
+ Stage* stage;
+
+ Engine();
+};
+
+#endif