polyadvent

A game engine from scratch in C
git clone git://jb55.com/polyadvent
Log | Files | Refs | README

game.h (2262B)


      1 
      2 #ifndef PA_GAME_H
      3 #define PA_GAME_H
      4 
      5 #include "vbo.h"
      6 #include "entity.h"
      7 #include "fbo.h"
      8 #include "input.h"
      9 #include "model.h"
     10 #include "node.h"
     11 #include "orbit.h"
     12 #include "shader.h"
     13 #include "skybox.h"
     14 #include "terrain.h"
     15 #include "texture.h"
     16 #include "ui.h"
     17 
     18 #define PLAYER_HEIGHT 1.73
     19 
     20 #define MAX_PROGRAMS 12
     21 
     22 enum program_type {
     23   DEFAULT_PROGRAM,
     24   TERRAIN_PROGRAM,
     25   UI_PROGRAM,
     26   SKYBOX_PROGRAM,
     27   NUM_PROGRAMS,
     28 };
     29 
     30 /*
     31  * Global data used by our render callback:
     32  * NOTE: just for testing right now
     33  */
     34 struct resources {
     35 	struct vbo vertex_buffer, element_buffer, normal_buffer;
     36     struct fbo shadow_buffer;
     37 
     38     struct gpu_program programs[NUM_PROGRAMS];
     39 
     40 	struct uniforms {
     41 		GLint ambient_str;
     42 		GLint camera_position;
     43 		GLint depth_mvp;
     44 		GLint depth_vp;
     45 		GLint diffuse_on;
     46 		GLint fog_on;
     47 		GLint light_dir;
     48 		GLint light_intensity;
     49 		GLint model;
     50 		GLint model_view;
     51 		GLint mvp;
     52 		GLint normal_matrix;
     53 		GLint sky_intensity;
     54 		GLint sun_color;
     55 		GLint time;
     56 		GLint view_proj;
     57 	} uniforms;
     58 
     59 	gpu_addr vertex_attrs[n_vertex_attrs];
     60 
     61 	node_id root_id;
     62 	entity_id player_id;
     63     struct geometry qh_test;
     64 	struct orbit orbit_camera;
     65 	node_id free_camera_id;
     66     node_id camera_node_id;
     67 	node_id sun_camera_id;
     68 
     69     u32 test_cubemap;
     70     float time;
     71 	bool fog_on, diffuse_on;
     72 
     73     struct skybox skybox;
     74 	float sun_color[3];
     75 	float test_mvp[MAT4_ELEMS];
     76 	float light_dir[3];
     77 	float light_intensity;
     78 	float proj_persp[MAT4_ELEMS];
     79 	float proj_ortho[MAT4_ELEMS];
     80 };
     81 
     82 struct user_settings {
     83     float mouse_sens;
     84 };
     85 
     86 struct game {
     87     SDL_Window *window;
     88     int counter;
     89     int seed;
     90     int quit;
     91     int wireframe;
     92     float dt;
     93     u64 frame;
     94     struct user_settings user_settings;
     95     struct ui ui;
     96     struct resources test_resources;
     97     struct input input;
     98     struct terrain terrain;
     99 };
    100 
    101 struct entity *get_player(struct resources *);
    102 struct entity *get_terrain_entity(struct terrain *);
    103 void game_init(struct game *game, int width, int height);
    104 void quit_game(struct game *game);
    105 void should_update(struct game *game);
    106 bool was_key_pressed_this_frame(struct game *game, int scancode);
    107 bool was_button_pressed_this_frame(struct game *game, SDL_GameControllerButton button);
    108 int is_free_camera(struct game *game);
    109 
    110 #endif /* PA_GAME_H */