Fixed camera angle resetting when right-click is held. Improved README

to conform to markdown syntax.
dev
shariq shah 8 years ago
parent c60930e739
commit d9f135a087
  1. 463
      README.md
  2. 20
      src/game.c
  3. 3
      src/gui.c
  4. 9
      src/utils.c
  5. 5
      src/utils.h

@ -1,42 +1,47 @@
=================== # Project Symmetry
Project Symmetry
===================
** What? - ## What?
A topdown 2D shooter exploring symmetry. A topdown 2D shooter exploring symmetry.
** License - ## License
All the code in this repository is under GPLv3, see LICENSE for more information All the code in this repository is under GPLv3, see LICENSE for more information
** File format specifications - ## File format specifications
*** Entity
# Comment, Sample entity definition in file, paremeters left out are set to defaults
# Empty line at the end specifies end of entity definition
entity: "Something"
position: 0 0 0
scale: 1 1 1
rotation: 0 0 0 1
model: "suzanne.pamesh"
material: "blinn_phong"
diffuse_color: 1 0 0 1
diffuse_texture: "checkered.tga"
specular: 0.55
- ### Entity
```.conf
:::conf
# Comment, Sample entity definition in file, paremeters left out are set to defaults
# Empty line at the end specifies end of entity definition
entity: "Something"
position: 0 0 0
scale: 1 1 1
rotation: 0 0 0 1
model: "suzanne.pamesh"
material: "blinn_phong"
diffuse_color: 1 0 0 1
diffuse_texture: "checkered.tga"
specular: 0.55
```
- Add to_string functions for major structs like transform, model etc to ease in conversion? - Add to_string functions for major structs like transform, model etc to ease in conversion?
*** Configuration Variables a.k.a cfg-vars - ### Configuration Variables a.k.a cfg-vars
# Comment ```.conf
render_width: 1024 # Comment
render_height: 1024 render_width: 1024
debug_draw_enabled: true render_height: 1024
fog_color: 0.5 0.2 0.2 1 debug_draw_enabled: true
# There can be comments or empty newlines in between unlike entity definitions fog_color: 0.5 0.2 0.2 1
# There can be comments or empty newlines in between unlike entity definitions
ambient_light: 0.1 0.1 0.1 1 ambient_light: 0.1 0.1 0.1 1
msaa: true msaa: true
msaa_levels: 8 msaa_levels: 8
*** Keybindings ```
- ### Keybindings
```.conf
# All keys are parsed by comparing the output of SDL_GetKeyname # All keys are parsed by comparing the output of SDL_GetKeyname
# Each line represents a keybinding # Each line represents a keybinding
Move_Forward: W Move_Forward: W
@ -53,210 +58,218 @@ All the code in this repository is under GPLv3, see LICENSE for more information
# Single modifier keys are allowed but multiple modifier keys without corresponding # Single modifier keys are allowed but multiple modifier keys without corresponding
# non-modifier key are not allowed # non-modifier key are not allowed
Sprint: Left Shift Sprint: Left Shift
```
- ### Level/Scene
- Binary format with header attached at the top
- Save child entities first
- Copy paste all entites in the file one by one. Since the entites all look
the same in memory and are made up of tagged unions, a simple memcpy approach
should suffice. The problem is entity heirarchies. There are multiple approaches to
solve this problem.
- Save a sorted list of entites to file i.e. before saving create a new list that does
not have the empty array slots in the entity list and then just copy and paste. This
is the simplest way to solve the problem as we don't have to worry about indexes of
parent/child entites in heirarchy. We can take the whole array and paste it to the
file but creating a copy of entity list for this purpose only would be slow and consume a lot of memory.
- Instead of creating a copy of the entity list for sorting and saving, sort the actual entity list
and update all references as necessary then save the array to file.
- Just write the name of the parent entity as parent. Make sure that all entity names are unique.
- ### Materials
- ### Mesh/Geometry
*** Level/Scene - ### Notes on entity Systems
- Binary format with header attached at the top
- Save child entities first
- Copy paste all entites in the file one by one. Since the entites all look
the same in memory and are made up of tagged unions, a simple memcpy approach
should suffice. The problem is entity heirarchies. There are multiple approaches to
solve this problem.
-- Save a sorted list of entites to file i.e. before saving create a new list that does
not have the empty array slots in the entity list and then just copy and paste. This
is the simplest way to solve the problem as we don't have to worry about indexes of
parent/child entites in heirarchy. We can take the whole array and paste it to the
file but creating a copy of entity list for this purpose only would be slow and consume a lot of memory.
-- Instead of creating a copy of the entity list for sorting and saving, sort the actual entity list
and update all references as necessary then save the array to file.
-- Just write the name of the parent entity as parent. Make sure that all entity names are unique.
*** Materials
*** Mesh/Geometry
** Notes on entity Systems
- Fat entites with all related properties, i.e. position, mesh etc in them. Easy to serialize, memory friendly, simple to implement
but would require significant changes to the current codebase. e.g.
struct Entity
{
int type;
char* name;
struct Transform {....};
struct Camera {....};
// Separate properties unique to entity types by using unions - Fat entites with all related properties, i.e. position, mesh etc in them. Easy to serialize, memory friendly, simple to implement but would require significant changes to the current codebase, for example:
struct Renderable ```.C
{ struct Entity
struct Model {....}; {
union int type;
{ char* name;
struct Player struct Transform {....};
{ struct Camera {....};
int score;
int bullets;
};
struct Enemy // Separate properties unique to entity types by using unions
{ struct Renderable
int target; {
}; struct Model {....};
} union
} {
}; struct Player
{
int score;
int bullets;
};
struct Enemy
{
int target;
};
}
}
};
```
- Change component implementation by using anonymous unions to simulate interfaces. e.g - Change component implementation by using anonymous unions to simulate interfaces. e.g
```.C
struct Component struct Component
{ {
int type; int type;
union union
{ {
struct Transform {....}; struct Transform {....};
struct Model {....}; struct Model {....};
struct Camera {....}; struct Camera {....};
} }
} }
```
- Use handles for assets - Use handles for assets
- Use something similar to Variant to use as entity, not sure what or how - Use something similar to Variant to use as entity, not sure what or how
- Don't forget to think of the actual use-case and usage when coming up with a solution, don't build castles in the air! - Don't forget to think of the actual use-case and usage when coming up with a solution, don't build castles in the air!
- ## TODO
- Finish entity loading from file then move on to 2D rendering
- First class 2d rendering
- Sprite batching (XNA like)
- Font rendering(2d/3d) with stb_ttf or freetype
? Minimal custom UI for in-game usage that can be rendered to a texture or modify nuklear for that?
- Bounding Boxes
? Recalculated bounding boxes for rotated meshes
- File extension checking for asset loading
- Only allocate hashmap bucket when required
- Mapping actions to keybindings, for example map action "Jump" to Space key etc
- Ability to mark meshes for debug rendering with possibility of different color for each?
- Switch to completely static allocation of entites i.e. have a static array of MAX_ENTITIES size. This way we can store pointers to entites and they'll still be in an array and fast to process.
- Add marking or queuing up custom meshes for debug render with particular transform and color for rendering bounding spheres for example
- Interleaved vbos for meshes and changes to blender exporter accordingly
- Enumerate and save all the uniform and attribute positions in shader when it is added and cache them in shader object?
- Physics/Collision detection in 2d
- Complete gui integration
- Decoupled event handling of gui and input if possible
- Custom rendering for gui
- Allow passsing base path as commandline argument?
- Remove components and switch to "Fat Entities" i.e. one entity struct contains all combinations
- Use variants for material params
- Improve Material Parameters/Pipeline Uniforms/Instance Uniforms are handled
- Fix light rotation/direction bugs
- Better handling incase assets folder is not found?
- Write entity to/from file
- Ogg format loading and playback
- Stick with OpenAL or switch to SoLoud + SDL for sound?
- Sound streaming
- Implment missing sound source properties (inner/outer cone, getting sound source data)
- Ingame console and console commands etc
- Allow binding/unbinding input maps to functions at runtime, for example if input map "Recompute" is triggered, it would call some function that can recompute bounding spheres.
- Better handling of wav format checking at load time
- Sprite sheet animations
- Ray picking
- Shadow maps
- Print processor stats and machine capabilites RAM etc on every run to log.
- Milestone: Pong!
- In order to put things into perspective and get a feel for what really needs to be prioritized, a very small but actual game release is necessary.
- Release platforms: Windows and Linux
- Makefile additions. Try to compile game as a dynamically loaded library with ability to reload on recompile
- Separation between game and engine base
? Game .so with init, update and cleanup functions
x Configuration files and "cvars" load/reload
x Keybindings in config
x Log output on every run.
- Implement entity load/save to file
? Prefab load/save to file
- Do input maps really need to be queried by their string names?
- Reloading all the things! (textures/shaders/models/settings/entities etc)
- Separate Debug/Editor camera from the active camera in the scene that can be switched to at any time
- Make logging to file and console toggleable at complie-time or run-time
- Add default keybindings
- Write default config/keybindings etc to file if none are found in preferences dir
- Wrap malloc and free calls in custom functions to track usage
- Flatpak packaging for linux releases
- Use hashmap for debugvar slots in editor
- Use hashmap to store input maps
- Multisampled textures and framebuffers
- Validate necessary assets at game launch
- Gamma correctness
- Log and debug/stats output in gui
- Editor automatic window layout adjusting to the current window resolution
- Event Subsystem
- Keybindings for gui?
- Textual/Binary format for data serialization and persistance
- Better logging
- Hatching/Ink rendering style
- Array based string type comptible with cstring(char*)
- Separate game, engine and assets into different repositories. Combine as sub-repositories
? Positive and negative values for input_maps and returning corresponding values when they are true
? CANCELED Image based lighting?
? CANCELED Deferred rendering?
- ???
- Profit!
================ - ## Completed
Things TODO
================
x Input * Input
x Shaders * Shaders
x Geometry * Geometry
x change struct usage * change struct usage
x change Array implementation * change Array implementation
x resolve vec-types sizes * resolve vec-types sizes
x Transform * Transform
x Deltatime * Deltatime
x Investigate about Exit() and at_exit() functions and whether to use them or not. * Investigate about Exit() and at_exit() functions and whether to use them or not.
x Fix readme markdown * Fix readme markdown
x Framebuffer and resolution independent rendering * Framebuffer and resolution independent rendering
x A simpler build system without dependencies * A simpler build system without dependencies
x Remove dependencies * Remove dependencies
x Remove Kazmath dependency * Remove Kazmath dependency
x Entity * Entity
x Find a permanent solution for build system * Find a permanent solution for build system
? Positive and negative values for input_maps and returning corresponding values when they are true * Textures
x Textures * Camera
x Camera * Test render
x Test render * Fix input lag and other framerate related issues
x Fix input lag and other framerate related issues * Materials
x Materials * Mesh/Model
x Mesh/Model * Add modifiers to input maps to enable combinations for example, c-x, m-k etc
x Add modifiers to input maps to enable combinations for example, c-x, m-k etc * Heirarchical Transforms
x Heirarchical Transforms * Materials with textures
x Materials with textures * Lights!
x Lights! * Fix problems with texture units
x Fix problems with texture units * Fix problems with frustrum culling
x Fix problems with frustrum culling * Gui
x Gui * Fix mouse bugs on windows
x Fix mouse bugs on windows * Configuration/Settings load/save handling
x Configuration/Settings load/save handling * Fix mousewheel bugs and gui not responding to mousewheel input
x Fix mousewheel bugs and gui not responding to mousewheel input * Setup cross compilation with mingw or stick to msvc?
x Setup cross compilation with mingw or stick to msvc? * Toggleable debug drawing for meshes
x Toggleable debug drawing for meshes * Font selection
x Font selection * Font atlas proper cleanup
x Font atlas proper cleanup * In second refactor pass, use entities everywhere, no need to pass in transform and model separately for example since they're both part of the same entity anyway
x In second refactor pass, use entities everywhere, no need to pass in transform and model separately for example since they're both part of the same entity anyway * Show SDL dialogbox if we cannot launch at all?
x Show SDL dialogbox if we cannot launch at all? * Writing back to config file
x Writing back to config file * Reading from config file
x Reading from config file * Variant -> String conversion procedure. Use in editor for debug var slots
x Variant -> String conversion procedure. Use in editor for debug var slots * Add strings and booleans to variant types
x Add strings and booleans to variant types * Fix Key release not being reported
x Fix Key release not being reported * OpenAL not working in releasebuilds
x OpenAL not working in releasebuilds * 3d sound using OpenAL
x 3d sound using OpenAL * Fix frustum culling bugs
x Fix frustum culling bugs * Array-based Hashmaps
x Array-based Hashmaps * Fix bugs with heirarchical transformations
x Fix bugs with heirarchical transformations * Remove reduntant "settings" structures and move all configuration stuff to config variables
x Remove reduntant "settings" structures and move all configuration stuff to config variables * Log output to file on every run
x Log output to file on every run * Add option to specify where to read/write files from instead of being hard-coded assets dir
x Add option to specify where to read/write files from instead of being hard-coded assets dir * Fix input map bugs
x Fix input map bugs * Live data views in editor
x Live data views in editor * Camera resize on window reisze
x Camera resize on window reisze * Resizable framebuffers and textures
x Resizable framebuffers and textures * Support for multiple color attachments in framebuffers?
x Support for multiple color attachments in framebuffers? * Better way to store and manage textures attached to framebuffers
x Better way to store and manage textures attached to framebuffers * Variant type
x Variant type * Editor
x Editor * Fix frustum culling sometimes not working
x Fix frustum culling sometimes not working * Compile and test on windows
x Compile and test on windows * Fix mouse bugs
x Fix mouse bugs * Fix
x Fix * issues with opengl context showing 2.1 only
x issues with opengl context showing 2.1 only * Improve this readme
x Improve this readme * Replace orgfile with simple text readme and reduce duplication
x Replace orgfile with simple text readme and reduce duplication? * Fix camera acting all weird when right click is held
- Bounding Boxes * Fix README to conform with markdown syntax
? Recalculated bounding boxes for rotated meshes?
- File extension checking for asset loading
- Only allocate hashmap bucket when required
- Mapping actions to keybindings, for example map action "Jump" to Space key etc
- Ability to mark meshes for debug rendering with possibility of different color for each?
- Switch to completely static allocation of entites i.e. have a static array of MAX_ENTITIES size. This way we can store pointers to entites and they'll still be in an array and fast to process.
? CANCELED Image based lighting?
? CANCELED Deferred rendering?
- Add marking or queuing up custom meshes for debug render with particular transform and color for rendering bounding spheres for example
- Interleaved vbos for meshes and changes to blender exporter accordingly
- Enumerate and save all the uniform and attribute positions in shader when it is added and cache them in shader object?
- Physics/Collision detection in 2d
- Complete gui integration
- Decoupled event handling of gui and input if possible
- Custom rendering for gui
- Allow passsing base path as commandline argument?
- Remove components and switch to "Fat Entities" i.e. one entity struct contains all combinations
- Use variants for material params
- Improve Material Parameters/Pipeline Uniforms/Instance Uniforms are handled
- Fix light rotation/direction bugs
- Better handling incase assets folder is not found?
- Write entity to/from file
- Ogg format loading and playback
- Stick with OpenAL or switch to SoLoud + SDL for sound?
- Sound streaming
- Implment missing sound source properties (inner/outer cone, getting sound source data)
- Ingame console and console commands etc
- Allow binding/unbinding input maps to functions at runtime, for example if input map "Recompute" is triggered, it would call some function that can recompute bounding spheres.
- Better handling of wav format checking at load time
- Sprite sheet animations
- First class 2d rendering
- Sprite batching (XNA like)
- Font rendering(2d/3d) with stb_ttf or freetype
? Minimal custom UI for in-game usage that can be rendered to a texture or modify nuklear for that?
- Ray picking
- Shadow maps
- Print processor stats and machine capabilites RAM etc on every run to log.
- Milestone: Pong!
- In order to put things into perspective and get a feel for what really needs to be prioritized, a very small but actual game release is necessary.
- Release platforms: Windows and Linux
- Makefile additions. Try to compile game as a dynamically loaded library with ability to reload on recompile
- Separation between game and engine base
? Game .so with init, update and cleanup functions
x Configuration files and "cvars" load/reload
x Keybindings in config
x Log output on every run.
- Implement entity load/save to file
? Prefab load/save to file
- Do input maps really need to be queried by their string names?
- Reloading all the things! (textures/shaders/models/settings/entities etc)
- Separate Debug/Editor camera from the active camera in the scene that can be switched to at any time
- Make logging to file and console toggleable at complie-time or run-time
- Add default keybindings
- Write default config/keybindings etc to file if none are found in preferences dir
- Wrap malloc and free calls in custom functions to track usage
- Flatpak packaging for linux releases
- Use hashmap for debugvar slots in editor
- Use hashmap to store input maps
- Multisampled textures and framebuffers
- Validate necessary assets at game launch
- Gamma correctness
- Log and debug/stats output in gui
- Editor automatic window layout adjusting to the current window resolution
- Event Subsystem
- Keybindings for gui?
- Textual/Binary format for data serialization and persistance
- Better logging
- Hatching/Ink rendering style
- Array based string type comptible with cstring(char*)
- Separate game, engine and assets into different repositories. Combine as sub-repositories
- ???
- Profit!

@ -119,7 +119,7 @@ void scene_setup(void)
sound_source_play(sound_ent); sound_source_play(sound_ent);
int parent_node = new_ent->id; int parent_node = new_ent->id;
int num_suz = 2; int num_suz = 50;
srand(time(NULL)); srand(time(NULL));
for(int i = 0; i < num_suz; i++) for(int i = 0; i < num_suz; i++)
{ {
@ -166,7 +166,7 @@ void scene_setup(void)
/* model_set_material_param(screen_model, "diffuse_color", &color); */ /* model_set_material_param(screen_model, "diffuse_color", &color); */
/* model_set_material_param(screen_model, "diffuse_texture", &cam->render_tex); */ /* model_set_material_param(screen_model, "diffuse_texture", &cam->render_tex); */
const int MAX_LIGHTS = 6; const int MAX_LIGHTS = 3;
for(int i = 0; i < MAX_LIGHTS; i++) for(int i = 0; i < MAX_LIGHTS; i++)
{ {
int x = rand() % MAX_LIGHTS; int x = rand() % MAX_LIGHTS;
@ -209,17 +209,23 @@ void debug(float dt)
if(input_mousebutton_state_get(MSB_RIGHT, KS_PRESSED)) if(input_mousebutton_state_get(MSB_RIGHT, KS_PRESSED))
{ {
if(input_mouse_mode_get() != MM_RELATIVE) input_mouse_mode_set(MM_RELATIVE); const float scale = 0.1f;
const double scale = 0.25; int cursor_lr, cursor_ud;
int cursor_lr, cursor_ud; input_mouse_delta_get(&cursor_lr, &cursor_ud);
input_mouse_delta_get(&cursor_lr, &cursor_ud); if(input_mouse_mode_get() != MM_RELATIVE)
{
input_mouse_mode_set(MM_RELATIVE);
cursor_lr = cursor_ud = 0;
}
turn_up_down = -cursor_ud * turn_speed * dt * scale; turn_up_down = -cursor_ud * turn_speed * dt * scale;
turn_left_right = cursor_lr * turn_speed * dt * scale; turn_left_right = cursor_lr * turn_speed * dt * scale;
input_mouse_pos_set(0.0, 0.0); log_message("ud : %d, lr : %d", cursor_ud, cursor_lr);
} }
else else
{ {
input_mouse_mode_set(MM_NORMAL); input_mouse_mode_set(MM_NORMAL);
log_message("ud : %.3f, lr : %.3f", turn_up_down, turn_left_right);
turn_up_down *= dt; turn_up_down *= dt;
turn_left_right *= dt; turn_left_right *= dt;
} }

@ -93,7 +93,8 @@ bool gui_init(void)
//gui_font_set("Ubuntu-R.ttf", 14); //gui_font_set("Ubuntu-R.ttf", 14);
//gui_font_set("FiraSans-Regular.ttf", 14); //gui_font_set("FiraSans-Regular.ttf", 14);
gui_font_set("RobotoCondensed-Regular.ttf", 18); gui_font_set("RobotoCondensed-Regular.ttf", 18);
gui_theme_set(GT_RED); // gui_theme_set(GT_RED);
gui_theme_set(GT_DEFAULT);
success = true; success = true;
return success; return success;
} }

@ -1,6 +1,7 @@
#include "utils.h" #include "utils.h"
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <math.h>
#define BUFF_SIZE 128 #define BUFF_SIZE 128
static char str_buff[BUFF_SIZE]; static char str_buff[BUFF_SIZE];
@ -25,3 +26,11 @@ const char* tostr_quat(quat* q)
snprintf(str_buff, BUFF_SIZE, "(%.3f, %.3f, %.3f, %.3f)", q->x, q->y, q->z, q->w); snprintf(str_buff, BUFF_SIZE, "(%.3f, %.3f, %.3f, %.3f)", q->x, q->y, q->z, q->w);
return str_buff; return str_buff;
} }
int min(int a, int b) { return a < b ? a : b; }
int max(int a, int b) { return a > b ? a : b; }
int clamp(int num, int upper, int lower)
{
return min(upper, max(num, lower));
}

@ -7,4 +7,9 @@ const char* tostr_vec3(vec3* v);
const char* tostr_vec4(vec4* v); const char* tostr_vec4(vec4* v);
const char* tostr_quat(quat* q); const char* tostr_quat(quat* q);
// Math related functions
int min(int a, int b);
int max(int a, int b);
int clamp(int num, int min, int max);
#endif #endif

Loading…
Cancel
Save