Modified cleanup to be called by atexit

dev
Shariq Shah 10 years ago
parent cfd810f020
commit 11b15a5248
  1. 18
      src/game.c
  2. 34
      src/main.c
  3. 1
      src/window_system.c

@ -16,9 +16,9 @@
#include "transform.h" #include "transform.h"
void run(void); void run(void);
void update(void); void update(float dt);
void render(void); void render(void);
void debug(void); void debug(float dt);
struct Entity* entity = NULL; struct Entity* entity = NULL;
@ -50,33 +50,39 @@ void game_init(void)
run(); run();
} }
void debug(void) void debug(float dt)
{ {
struct Transform* transform = entity_component_get(entity, C_TRANSFORM); struct Transform* transform = entity_component_get(entity, C_TRANSFORM);
vec3 offset = {0, 5, 0}; vec3 offset = {0, 5, 0};
vec3_scale(offset, offset, dt);
transform_translate(transform, offset, TS_WORLD); transform_translate(transform, offset, TS_WORLD);
log_message("Position : %.3f, %.3f, %.3f", transform->position[0], transform->position[1], transform->position[2]); log_message("Position : %.3f, %.3f, %.3f", transform->position[0], transform->position[1], transform->position[2]);
} }
void run(void) void run(void)
{ {
double last_time = glfwGetTime();
while(!window_should_close()) while(!window_should_close())
{ {
update(); double curr_time = glfwGetTime();
float delta_time = (float)(curr_time - last_time);
last_time = curr_time;
update(delta_time);
render(); render();
window_swap_buffers(); window_swap_buffers();
window_poll_events(); window_poll_events();
} }
} }
void update(void) void update(float dt)
{ {
input_update(); input_update();
if(input_key_state_get(GLFW_KEY_ESCAPE, GLFW_PRESS)) if(input_key_state_get(GLFW_KEY_ESCAPE, GLFW_PRESS))
window_set_should_close(1); window_set_should_close(1);
if(input_map_state_get("MoveUp", GLFW_PRESS)) if(input_map_state_get("MoveUp", GLFW_PRESS))
debug(); debug(dt);
} }
void render(void) void render(void)

@ -1,6 +1,7 @@
#define GLEW_STATIC #define GLEW_STATIC
#include <GL/glew.h> #include <GL/glew.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include "log.h" #include "log.h"
#include "window_system.h" #include "window_system.h"
@ -21,28 +22,34 @@ int main(int argc, char** args)
else else
game_init(); game_init();
cleanup(); exit(EXIT_SUCCESS);
log_message("Program exiting!");
return 0;
} }
int init(void) int init(void)
{ {
int success = 1; int success = 1;
if(window_init("Symmetry", WIN_WIDTH, WIN_HEIGHT)) if(atexit(cleanup) != 0)
{ {
//Initialize GLEW success = 0;
glewExperimental = GL_TRUE; log_error("Main:init", "Could not register cleanup func with atexit");
GLenum glewError = glewInit();
if(glewError != GLEW_OK)
{
log_error("Main:init", "GLEW : %s", glewGetErrorString(glewError));
success = 0;
}
} }
else else
{ {
success = 0; if(window_init("Symmetry", WIN_WIDTH, WIN_HEIGHT))
{
//Initialize GLEW
glewExperimental = GL_TRUE;
GLenum glewError = glewInit();
if(glewError != GLEW_OK)
{
log_error("Main:init", "GLEW : %s", glewGetErrorString(glewError));
success = 0;
}
}
else
{
success = 0;
}
} }
return success; return success;
} }
@ -51,4 +58,5 @@ void cleanup()
{ {
game_cleanup(); game_cleanup();
window_cleanup(); window_cleanup();
log_message("Program exiting!");
} }

@ -30,7 +30,6 @@ int window_init(const char* title, int width, int height)
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
glfwWindowHint(GLFW_FOCUSED, GL_TRUE); glfwWindowHint(GLFW_FOCUSED, GL_TRUE);
//glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE); //glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);
active_window = glfwCreateWindow(width, height, title, NULL, NULL); active_window = glfwCreateWindow(width, height, title, NULL, NULL);
if(!active_window) if(!active_window)
{ {

Loading…
Cancel
Save