aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libjin/Core/Game.cpp11
-rw-r--r--libjin/Input/Event.h36
-rw-r--r--libjin/Math/Math.h10
-rw-r--r--test/01HelloWorld/main.cpp8
4 files changed, 35 insertions, 30 deletions
diff --git a/libjin/Core/Game.cpp b/libjin/Core/Game.cpp
index 4296c21..06537c7 100644
--- a/libjin/Core/Game.cpp
+++ b/libjin/Core/Game.cpp
@@ -25,7 +25,6 @@ namespace core
_running = true;
Event e;
int previous = getMilliSecond();
- int lag = 0;
while (_running)
{
while (jin::input::pollEvent(&e))
@@ -35,18 +34,14 @@ namespace core
}
SAFECALL(_onUpdate);
SAFECALL(_onDraw);
+ wnd->swapBuffers();
const int current = getMilliSecond();
const int wait = MS_PER_UPDATE - (current - previous);
previous += MS_PER_UPDATE;
- if (wait >= 0 && lag == 0)
+ if (wait > 0)
sleep(wait);
- else if(wait >= 0 && lag > 0) // catch, dont sleep
- lag = lowerBound(lag - MS_PER_UPDATE, 0);
- else if(wait < 0)
- {
- lag += abs(wait);
+ else
previous = current;
- }
}
stoploop:;
}
diff --git a/libjin/Input/Event.h b/libjin/Input/Event.h
index 91d8593..9feb3a5 100644
--- a/libjin/Input/Event.h
+++ b/libjin/Input/Event.h
@@ -16,12 +16,32 @@ namespace input
enum EventType {
QUIT = SDL_QUIT,
- KEYDOWN = SDL_KEYDOWN,
- KEYUP = SDL_KEYUP,
- MOUSEMOTION = SDL_MOUSEMOTION,
- MOUSEBUTTONDOWN = SDL_MOUSEBUTTONDOWN,
- MOUSEBUTTONUP = SDL_MOUSEBUTTONUP,
- MOUSEWHEEL = SDL_MOUSEWHEEL
+ KEY_DOWN = SDL_KEYDOWN,
+ KEY_UP = SDL_KEYUP,
+ MOUSE_MOTION = SDL_MOUSEMOTION,
+ MOUSE_BUTTON_DOWN = SDL_MOUSEBUTTONDOWN,
+ MOUSE_BUTTON_UP = SDL_MOUSEBUTTONUP,
+ MOUSE_WHEEL = SDL_MOUSEWHEEL,
+ WINDOW_EVENT = SDL_WINDOWEVENT,
+ };
+
+ enum WindowEvent {
+ WINDOW_SHOWN = SDL_WINDOWEVENT_SHOWN ,
+ WINDOW_HIDDEN = SDL_WINDOWEVENT_HIDDEN ,
+ WINDOW_EXPOSED = SDL_WINDOWEVENT_EXPOSED ,
+ WINDOW_MOVED = SDL_WINDOWEVENT_MOVED ,
+ WINDOW_RESIZED = SDL_WINDOWEVENT_RESIZED ,
+ WINDOW_SIZE_CAHNGE = SDL_WINDOWEVENT_SIZE_CHANGED ,
+ WINDOW_MINIMIZED = SDL_WINDOWEVENT_MINIMIZED ,
+ WINDOW_MAXIMIZED = SDL_WINDOWEVENT_MAXIMIZED ,
+ WINDOW_RESTORED = SDL_WINDOWEVENT_RESTORED ,
+ WINDOW_ENTER = SDL_WINDOWEVENT_ENTER ,
+ WINDOW_LEAVE = SDL_WINDOWEVENT_LEAVE ,
+ WINDOW_FOCUS_GAINED = SDL_WINDOWEVENT_FOCUS_GAINED,
+ WINDOW_FOCUS_LOST = SDL_WINDOWEVENT_FOCUS_LOST ,
+ WINDOW_CLOSE = SDL_WINDOWEVENT_CLOSE ,
+ WINDOW_TAKE_FOCUS = SDL_WINDOWEVENT_TAKE_FOCUS ,
+ WINDOW_HIT_TEST = SDL_WINDOWEVENT_HIT_TEST ,
};
inline int pollEvent(Event* e)
@@ -64,8 +84,8 @@ namespace input
*/
#endif // JIN_INPUT_SDL
-}
-}
+} // input
+} // jin
#endif // JIN_MODULES_INPUT
#endif \ No newline at end of file
diff --git a/libjin/Math/Math.h b/libjin/Math/Math.h
index 76f9da7..5b34f4c 100644
--- a/libjin/Math/Math.h
+++ b/libjin/Math/Math.h
@@ -4,18 +4,12 @@
#include "constant.h"
#include "matrix.h"
#include "quad.h"
-//
-//#define min(a,b) (a < b ? a : b)
-//#define max(a,b) (a > b ? a : b)
-//#define clamp(a, mi,ma) (min(max(a,mi),ma))
-//#define within(a,min,max) (a >= min && a <= max)
-//#define without(a,min,max) (a < min || a > max)
-//#define abs(n) (a > 0 ? a : -a)
-//
+
namespace jin
{
namespace math
{
+
#ifdef min
#undef min
#endif // min
diff --git a/test/01HelloWorld/main.cpp b/test/01HelloWorld/main.cpp
index d187849..fa81918 100644
--- a/test/01HelloWorld/main.cpp
+++ b/test/01HelloWorld/main.cpp
@@ -11,7 +11,7 @@ void onEvent(jin::input::Event* e)
if (e->type == EventType::QUIT)
game->stop();
}
-static float dt = 0;
+
void onUpdate()
{
@@ -19,11 +19,7 @@ void onUpdate()
void onDraw()
{
- dt += 16;
- if (dt > 1000)
- {
- dt = 0;
- }
+
}
int main(int argc, char* argv[])