summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--SConstruct2
-rw-r--r--engine/engine.cpp17
-rw-r--r--engine/engine.h6
-rw-r--r--engine/player.cpp16
m---------wriggle0
5 files changed, 16 insertions, 25 deletions
diff --git a/SConstruct b/SConstruct
index 3790557..9d19e09 100644
--- a/SConstruct
+++ b/SConstruct
@@ -15,7 +15,7 @@ if env['PLATFORM'] == 'darwin':
env.Append(CPPPATH = ['.', '/opt/local/include', '/opt/local/include/freetype2'])
env.Append(LIBS = ['ftgl'])
env.Append(LIBPATH = ['/opt/local/lib'])
- env.Append(FRAMEWORKS = ['SDL', 'SDL_image', 'Cocoa', 'OpenGL', 'AppKit'])
+ env.Append(FRAMEWORKS = ['sfml-system', 'sfml-window', 'SDL', 'SDL_image', 'OpenGL'])
else:
env.Append(CPPPATH = ['.'])
env.Append(LIBS = ['GL', 'GLU', 'SDL', 'SDL_image'])
diff --git a/engine/engine.cpp b/engine/engine.cpp
index eccf495..278007e 100644
--- a/engine/engine.cpp
+++ b/engine/engine.cpp
@@ -12,9 +12,9 @@
#include <boost/format.hpp>
-void Engine::event_keypress(SDLKey key) {
+void Engine::event_keypress(sf::Key::Code key) {
switch(key) {
- case SDLK_SPACE:
+ case sf::Key::Space:
paused = !paused;
break;
default:
@@ -84,13 +84,10 @@ void Engine::update() {
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;
- lastframes = tick;
- } else {
- frames++;
+ if(++fps_frames >= 60) {
+ fps = float(fps_frames) / fps_clock.GetElapsedTime();
+ fps_clock.Reset();
+ fps_frames = 0;
}
glScalef(0.0005, 0.0005, 0.0005);
@@ -108,6 +105,4 @@ void Engine::update() {
stage->draw();
glDisable(GL_SCISSOR_TEST);
-
- SDL_GL_SwapBuffers();
}
diff --git a/engine/engine.h b/engine/engine.h
index 894143e..754342d 100644
--- a/engine/engine.h
+++ b/engine/engine.h
@@ -14,12 +14,12 @@ class Engine : public Application {
bool paused;
- unsigned int frames;
- unsigned int lastframes;
float fps;
+ unsigned int fps_frames;
+ sf::Clock fps_clock;
protected:
- virtual void event_keypress(SDLKey key);
+ virtual void event_keypress(sf::Key::Code key);
virtual void update();
diff --git a/engine/player.cpp b/engine/player.cpp
index c9a4ee2..091f874 100644
--- a/engine/player.cpp
+++ b/engine/player.cpp
@@ -1,10 +1,5 @@
-#ifndef __APPLE__
-#include <GL/gl.h>
-#else
-#include <OpenGL/gl.h>
-#endif
+#include <SFML/Window.hpp>
#include <cmath>
-#include <SDL/SDL.h>
#include "player.h"
#include <wriggle/texturesdl.h>
@@ -33,11 +28,12 @@ void Player::draw() {
}
void Player::update() {
- Uint8 *keystate = SDL_GetKeyState(NULL);
- float factor = move_factor * (SDL_GetModState() & KMOD_SHIFT ? focus_factor : 1);
+ sf::Input input;
+
+ float factor = move_factor * (input.IsKeyDown(sf::Key::LShift) ? focus_factor : 1);
- float x_speed = factor * keystate[SDLK_RIGHT] - factor * keystate[SDLK_LEFT];
- float y_speed = factor * keystate[SDLK_UP] - factor * keystate[SDLK_DOWN];
+ float x_speed = factor * input.IsKeyDown(sf::Key::Right) - factor * input.IsKeyDown(sf::Key::Left);
+ float y_speed = factor * input.IsKeyDown(sf::Key::Up) - factor * input.IsKeyDown(sf::Key::Down);
if(x_speed && y_speed) {
x_speed /= sqrtf(2);
diff --git a/wriggle b/wriggle
-Subproject ab8c1e0eeffedb0e5979874fba64b305effdb2d
+Subproject bf4827f46f22b4df0fa2ddd6716fd59247f9e1b