Renamed some functions, replaced bool with int and added function to close main window and stop game

dev
Shariq Shah 10 years ago
parent e6a04a1577
commit f7e1887028
  1. 6
      src/entity.c
  2. 5
      src/entity.h
  3. 2
      src/file_io.c
  4. 3
      src/file_io.h
  5. 11
      src/game.c
  6. 19
      src/geometry.c
  7. 2
      src/geometry.h
  8. 30
      src/input.c
  9. 13
      src/input.h
  10. 6
      src/main.c
  11. 2
      src/shader.c
  12. 2
      src/shader.h
  13. 15
      src/window_system.c
  14. 7
      src/window_system.h

@ -11,7 +11,7 @@ static struct Entity* entity_list;
static int* empty_indices;
void entity_initialize(void)
void entity_init(void)
{
entity_list = array_new(struct Entity);
empty_indices = array_new(int);
@ -106,9 +106,9 @@ struct Entity* entity_find(const char* name)
return entity;
}
bool entity_component_remove(struct Entity* entity, enum Component component)
int entity_component_remove(struct Entity* entity, enum Component component)
{
bool success = true;
int success = 1;
assert(entity);
switch(component)
{

@ -3,7 +3,6 @@
#include "components.h"
#include "num_types.h"
#include <stdbool.h>
typedef int32 Node;
@ -15,13 +14,13 @@ struct Entity
int components[MAX_COMPONENTS];
};
void entity_initialize(void);
void entity_init(void);
void entity_cleanup(void);
void entity_remove(int index);
struct Entity* entity_create(const char* name, const char* tag);
struct Entity* entity_get(int index);
struct Entity* entity_find(const char* name);
bool entity_component_remove(struct Entity* entity, enum Component component);
int entity_component_remove(struct Entity* entity, enum Component component);
void* entity_component_get(struct Entity* entity, enum Component component);
void* entity_component_add(struct Entity* entity, enum Component component);

@ -7,7 +7,7 @@
static char* base_assets_path;
void io_file_initialize(const char* assets_path)
void io_file_init(const char* assets_path)
{
base_assets_path = str_new(assets_path);
}

@ -1,10 +1,9 @@
#ifndef file_io_H
#define file_io_H
#include <stdbool.h>
#include <stdio.h>
void io_file_initialize(const char* assets_path);
void io_file_init(const char* assets_path);
char* io_file_read(const char* path);
FILE* io_file_open(const char* path, const char* mode);
void io_file_cleanup(void);

@ -11,6 +11,7 @@
#include "file_io.h"
#include "shader.h"
#include "entity.h"
#include "geometry.h"
#include "array.h"
void run(void);
@ -23,9 +24,10 @@ void game_init(void)
/* Init systems */
input_init(window);
renderer_init(window);
io_file_initialize("/mnt/Dev/Projects/Symmetry/assets/");/* TODO: Implement proper way of getting binary directory */
shader_initialize();
entity_initialize();
io_file_init("/mnt/Dev/Projects/Symmetry/assets/");/* TODO: Implement proper way of getting binary directory */
shader_init();
entity_init();
geom_init();
int keys[2] = {'W', GLFW_KEY_UP};
@ -55,6 +57,8 @@ void run(void)
void update(void)
{
input_update();
if(input_key_state_get(GLFW_KEY_ESCAPE, GLFW_PRESS))
window_set_should_close(1);
}
void render(void)
@ -65,6 +69,7 @@ void render(void)
void game_cleanup(void)
{
entity_cleanup();
geom_cleanup();
input_cleanup();
renderer_cleanup();
io_file_cleanup();

@ -18,7 +18,7 @@
struct Geometry
{
char* filename;
bool draw_indexed;
int draw_indexed;
uint vao;
uint vertex_vbo;
uint uv_vbo;
@ -41,10 +41,10 @@ static struct Geometry* geometry_list;
static int* empty_indices;
/* Function definitions */
bool load_from_file(struct Geometry* geometry, const char* filename);
int load_from_file(struct Geometry* geometry, const char* filename);
void create_vao(struct Geometry* geometry);
void geom_initialize(void)
void geom_init(void)
{
geometry_list = array_new(struct Geometry);
empty_indices = array_new(int);
@ -131,10 +131,10 @@ void geom_cleanup(void)
array_free(empty_indices);
}
bool load_from_file(struct Geometry* geometry, const char* filename)
int load_from_file(struct Geometry* geometry, const char* filename)
{
assert(filename);
bool success = true;
int success = 1;
char* full_path = str_new("models/");
full_path = str_concat(full_path, filename);
@ -150,7 +150,7 @@ bool load_from_file(struct Geometry* geometry, const char* filename)
if((bytes_read = fread(header, INDEX_SIZE, 4, file)) <= 0)
{
log_error("geometry:load_from_file", "Read failed");
success = false;
success = 0;
}
else
{
@ -173,14 +173,13 @@ bool load_from_file(struct Geometry* geometry, const char* filename)
}
fclose(file);
geometry->filename = str_new(filename);
geometry->draw_indexed = true;
geometry->draw_indexed = 1;
geometry->ref_count++;
}
else
{
success = false;
success = 0;
}
return success;
}
@ -248,7 +247,7 @@ void create_vao(struct Geometry* geometry)
array_len(geometry->indices) * sizeof(GLuint),
geometry->indices,
GL_STATIC_DRAW);
geometry->draw_indexed = true;
geometry->draw_indexed = 1;
}
glBindVertexArray(0);
}

@ -1,7 +1,7 @@
#ifndef geometry_H
#define geometry_H
void geom_initialize(void);
void geom_init(void);
int geom_ceate(const char* name);
int geom_find(const char* filename);
void geom_remove(int index);

@ -91,7 +91,7 @@ void input_cursor_mode_set(enum Cursor_Mode mode)
glfwSetInputMode(window, GLFW_CURSOR, cursor_mode);
}
bool input_map_state_get(const char* map_name, int state)
int input_map_state_get(const char* map_name, int state)
{
int current_state = KS_INACTIVE;
for(int i = 0; i < array_len(input_map_list); i++)
@ -103,21 +103,21 @@ bool input_map_state_get(const char* map_name, int state)
break;
}
}
return state == current_state ? true : false;
return state == current_state ? 1 : 0;
}
bool input_key_state_get(int key, int state_type)
int input_key_state_get(int key, int state_type)
{
GLFWwindow* window = window_get_active();
int current_state = glfwGetKey(window, key);
return current_state == state_type ? true : false;
return current_state == state_type ? 1 : 0;
}
bool input_mousebutton_state_get(int button, int state_type)
int input_mousebutton_state_get(int button, int state_type)
{
GLFWwindow* window = window_get_active();
int current_state = glfwGetMouseButton(window, button);
return current_state == state_type ? true : false;
return current_state == state_type ? 1 : 0;
}
void input_map_create(const char* name, int* keys, size_t num_keys)
@ -144,25 +144,25 @@ void input_update(void)
}
}
bool input_map_remove(const char* name)
int input_map_remove(const char* name)
{
assert(name);
bool success = false;
int success = 0;
int index = map_find(name);
if(index > -1)
{
array_remove_at(input_map_list, (int)index);
success = true;
success = 1;
}
if(!success) log_error("input:map_remove", "Map %s not found", name);
return success;
}
bool input_map_keys_set(const char* name, int* keys, int num_keys)
int input_map_keys_set(const char* name, int* keys, int num_keys)
{
assert(name && keys && num_keys > 0);
bool success = false;
int success = 0;
int index = map_find(name);
if(index > -1)
{
@ -170,23 +170,23 @@ bool input_map_keys_set(const char* name, int* keys, int num_keys)
array_reset(map->keys, num_keys);
for(int i = 0; i < num_keys; i++)
map->keys[i] = keys[i];
success = true;
success = 1;
}
if(!success)
log_error("input:map_keys_set", "Map %s not found", name);
return success;
}
bool input_map_name_set(const char* name, const char* new_name)
int input_map_name_set(const char* name, const char* new_name)
{
assert(name && new_name);
bool success = false;
int success = 0;
int index = map_find(name);
if(index > -1)
{
struct Input_Map* map = &input_map_list[index];
map->name = new_name;
success = true;
success = 1;
}
if(!success) log_error("input:map_name_set", "Map %s not found", name);
return success;

@ -1,7 +1,6 @@
#ifndef input_H
#define input_H
#include <stdbool.h>
#include <stdlib.h>
typedef struct GLFWwindow GLFWwindow;
@ -16,15 +15,15 @@ enum Cursor_Mode
void input_init(GLFWwindow* window);
void input_cleanup(void);
bool input_mousebutton_state_get(int button, int state_type);
bool input_key_state_get(int key, int state_type);
int input_mousebutton_state_get(int button, int state_type);
int input_key_state_get(int key, int state_type);
void input_cursor_pos_get(double* xpos, double* ypos);
void input_cursor_mode_set(enum Cursor_Mode mode);
void input_update(void);
bool input_map_state_get(const char* map_name, int state);
int input_map_state_get(const char* map_name, int state);
void input_map_create(const char* name, int* keys, size_t num_keys);
bool input_map_remove(const char* name);
bool input_map_keys_set(const char* name, int* keys, int num_keys);
bool input_map_name_set(const char* name, const char* new_name);
int input_map_remove(const char* name);
int input_map_keys_set(const char* name, int* keys, int num_keys);
int input_map_name_set(const char* name, const char* new_name);
#endif

@ -28,7 +28,7 @@ int main(int argc, char** args)
int init(void)
{
bool success = true;
int success = 1;
if(window_init("Symmetry", WIN_WIDTH, WIN_HEIGHT))
{
//Initialize GLEW
@ -37,12 +37,12 @@ int init(void)
if(glewError != GLEW_OK)
{
log_error("Main:init", "GLEW : %s", glewGetErrorString(glewError));
success = false;
success = 0;
}
}
else
{
success = false;
success = 0;
}
return success;
}

@ -89,7 +89,7 @@ char* run_preprocessor(char* shader_text)
return shader_text;
}
void shader_initialize(void)
void shader_init(void)
{
shader_list = array_new(Shader_Object);
empty_indices = array_new(int);

@ -4,7 +4,7 @@
#include "linmath.h"
int shader_create(const char* vert_shader_name, const char* frag_shader_name);
void shader_initialize(void);
void shader_init(void);
void shader_bind(const int shader_index);
void shader_remove(const int shader_index);
void shader_unbind(void);

@ -11,14 +11,14 @@ void window_error_callback(int error, const char* description);
void window_resize(GLFWwindow* window, int width, int height);
void window_close_callback(GLFWwindow* window);
bool window_init(const char* title, int width, int height)
int window_init(const char* title, int width, int height)
{
bool success = true;
int success = 1;
glfwSetErrorCallback(window_error_callback);
if(!glfwInit())
{
log_error("window_create", "Initializing glfw failed");
success = false;
success = 0;
}
else
{
@ -32,7 +32,7 @@ bool window_init(const char* title, int width, int height)
if(!active_window)
{
log_error("window_create", "Failed to create window");
success = false;
success = 0;
}
else
{
@ -90,7 +90,12 @@ GLFWwindow* window_get_active(void)
return active_window;
}
bool window_should_close(void)
int window_should_close(void)
{
return glfwWindowShouldClose(active_window);
}
void window_set_should_close(int should_close)
{
glfwSetWindowShouldClose(active_window, should_close ? GL_TRUE : GL_FALSE);
}

@ -1,8 +1,6 @@
#ifndef window_system_H
#define window_system_H
#include <stdbool.h>
struct GLFWwindow;
typedef struct GLFWwindow GLFWwindow;
@ -11,12 +9,13 @@ typedef void (*on_window_resize) (int, int); // Callback that recieves window
typedef void (*on_key) (int, int , int, int); // Callback for keyboard events
typedef void (*on_mouse_pos) (double, double); // Callback for mouse position
bool window_init(const char* title, int width, int height);
int window_init(const char* title, int width, int height);
void window_cleanup(void);
void window_set_size(int width, int height);
void window_poll_events(void);
void window_swap_buffers(void);
bool window_should_close(void);
int window_should_close(void);
void window_set_should_close(int should_close);
GLFWwindow* window_get_active(void);
#endif

Loading…
Cancel
Save