summaryrefslogtreecommitdiff
path: root/src/engine/M_game.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/engine/M_game.c')
-rw-r--r--src/engine/M_game.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/engine/M_game.c b/src/engine/M_game.c
index 3c76d96..6295f51 100644
--- a/src/engine/M_game.c
+++ b/src/engine/M_game.c
@@ -15,6 +15,8 @@ int M_initGame(M_Game *game, const char *window_title)
game->window_height,
SDL_WINDOW_OPENGL
);
+ SDL_SetWindowRelativeMouseMode(game->window, 1);
+
M_setupProjection(90.0f, ((float)game->window_width)/((float)game->window_height), &game->render_info);
game->block_atlas = M_createBlockAtlas();
@@ -33,7 +35,9 @@ int M_initGame(M_Game *game, const char *window_title)
return 1;
}
- game->event_handler = SDL_CreateThread(M_handleEvents, "eventHandler", (void*)game);
+ game->render_info.global_models = malloc(10*sizeof(M_ViewModel));
+
+ game->render_info.global_models[0] = M_createCube();
glClearColor(0.0f, 0.25f, 0.5f, 1.0f);
@@ -44,23 +48,27 @@ int M_initGame(M_Game *game, const char *window_title)
int M_killGame(M_Game *game)
{
- SDL_WaitThread(game->event_handler, NULL);
+ free(game->render_info.global_models);
SDL_Quit();
return 0;
}
-int SDLCALL M_handleEvents(void* arg)
+int M_handleEvents(M_Game *game)
{
- M_Game *game = arg;
SDL_Event event;
- while (game->running) {
- SDL_PollEvent(&event);
+ while(SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_EVENT_QUIT:
game->running = 0;
break;
+ case SDL_EVENT_KEY_DOWN:
+ SDL_SetWindowRelativeMouseMode(game->window, 0);
+ break;
+ case SDL_EVENT_MOUSE_MOTION:
+ game->player.camera.yaw += (float)event.motion.xrel/100;
+ game->player.camera.pitch += (float)event.motion.yrel/100;
+ break;
}
- SDL_Delay(1);
}
return 0;
}