A 3D game engine from scratch.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

change type names

+928 -944
+24 -24
src/anim.cpp
··· 10 10 anim::State *anim::state = nullptr; 11 11 12 12 13 - bool32 13 + bool 14 14 anim::is_animation_component_valid(anim::Component *animation_component) 15 15 { 16 16 return animation_component->n_bones > 0 && ··· 18 18 } 19 19 20 20 21 - uint32 21 + u32 22 22 anim::push_to_bone_matrix_pool() 23 23 { 24 24 return anim::state->bone_matrix_pool.n_bone_matrix_sets++; ··· 26 26 27 27 28 28 m4 * 29 - anim::get_bone_matrix(uint32 idx, uint32 idx_bone, uint32 idx_anim_key) 29 + anim::get_bone_matrix(u32 idx, u32 idx_bone, u32 idx_anim_key) 30 30 { 31 31 return anim::state->bone_matrix_pool.bone_matrices[ 32 32 idx * MAX_N_ANIM_KEYS * MAX_N_BONES + ··· 62 62 63 63 // If we have multiple anim keys, find the right ones and interpolate. 64 64 } else { 65 - real64 animation_timepoint = fmod(engine::get_t(), animation->duration); 65 + f64 animation_timepoint = fmod(engine::get_t(), animation->duration); 66 66 67 - uint32 idx_anim_key = get_bone_matrix_anim_key_for_timepoint( 67 + u32 idx_anim_key = get_bone_matrix_anim_key_for_timepoint( 68 68 animation_component, 69 69 animation_timepoint, animation->idx_bone_matrix_set, 70 70 idx_bone); 71 71 72 - real64 t0 = *get_bone_matrix_time( 72 + f64 t0 = *get_bone_matrix_time( 73 73 animation->idx_bone_matrix_set, idx_bone, idx_anim_key); 74 74 m4 transform_t0 = *get_bone_matrix( 75 75 animation->idx_bone_matrix_set, idx_bone, idx_anim_key); 76 76 77 - real64 t1 = *get_bone_matrix_time( 77 + f64 t1 = *get_bone_matrix_time( 78 78 animation->idx_bone_matrix_set, idx_bone, idx_anim_key + 1); 79 79 m4 transform_t1 = *get_bone_matrix( 80 80 animation->idx_bone_matrix_set, idx_bone, idx_anim_key + 1); 81 81 82 - real32 lerp_factor = (real32)((animation_timepoint - t0) / (t1 - t0)); 82 + f32 lerp_factor = (f32)((animation_timepoint - t0) / (t1 - t0)); 83 83 84 84 // NOTE: This is probably bad if we have scaling in our transform? 85 85 m4 interpolated_matrix = ··· 96 96 anim::make_bone_matrices_for_animation_bone( 97 97 anim::Component *animation_component, 98 98 aiNodeAnim *ai_channel, 99 - uint32 idx_animation, 100 - uint32 idx_bone 99 + u32 idx_animation, 100 + u32 idx_bone 101 101 ) { 102 102 assert(ai_channel->mNumPositionKeys == ai_channel->mNumRotationKeys); 103 103 assert(ai_channel->mNumPositionKeys == ai_channel->mNumScalingKeys); ··· 110 110 ai_channel->mRotationKeys[idx_anim_key].mTime); 111 111 assert(ai_channel->mPositionKeys[idx_anim_key].mTime == 112 112 ai_channel->mScalingKeys[idx_anim_key].mTime); 113 - real64 anim_key_time = ai_channel->mPositionKeys[idx_anim_key].mTime; 113 + f64 anim_key_time = ai_channel->mPositionKeys[idx_anim_key].mTime; 114 114 115 115 m4 *bone_matrix = get_bone_matrix( 116 116 animation_component->animations[idx_animation].idx_bone_matrix_set, 117 117 idx_bone, idx_anim_key); 118 118 119 - real64 *time = get_bone_matrix_time( 119 + f64 *time = get_bone_matrix_time( 120 120 animation_component->animations[idx_animation].idx_bone_matrix_set, 121 121 idx_bone, idx_anim_key); 122 122 ··· 170 170 anim::state->bone_matrix_pool.bone_matrices = Array<m4>(pool, 171 171 MAX_N_ANIMATED_MODELS * MAX_N_BONES * MAX_N_ANIMATIONS * MAX_N_ANIM_KEYS, 172 172 "bone_matrices", true); 173 - anim::state->bone_matrix_pool.times = Array<real64>(pool, 173 + anim::state->bone_matrix_pool.times = Array<f64>(pool, 174 174 MAX_N_ANIMATED_MODELS * MAX_N_BONES * MAX_N_ANIMATIONS * MAX_N_ANIM_KEYS, 175 175 "bone_matrix_times", true); 176 176 } 177 177 178 178 179 - real64 * 179 + f64 * 180 180 anim::get_bone_matrix_time( 181 - uint32 idx, 182 - uint32 idx_bone, 183 - uint32 idx_anim_key 181 + u32 idx, 182 + u32 idx_bone, 183 + u32 idx_anim_key 184 184 ) { 185 185 return anim::state->bone_matrix_pool.times[ 186 186 idx * MAX_N_ANIM_KEYS * MAX_N_BONES + ··· 190 190 } 191 191 192 192 193 - uint32 193 + u32 194 194 anim::get_bone_matrix_anim_key_for_timepoint( 195 195 anim::Component *animation_component, 196 - real64 animation_timepoint, 197 - uint32 idx_bone_matrix_set, 198 - uint32 idx_bone 196 + f64 animation_timepoint, 197 + u32 idx_bone_matrix_set, 198 + u32 idx_bone 199 199 ) { 200 200 Bone *bone = &animation_component->bones[idx_bone]; 201 201 assert(bone->n_anim_keys > 1); 202 - uint32 idx_anim_key = bone->last_anim_key; 202 + u32 idx_anim_key = bone->last_anim_key; 203 203 do { 204 - real64 t0 = *get_bone_matrix_time(idx_bone_matrix_set, idx_bone, idx_anim_key); 205 - real64 t1 = *get_bone_matrix_time(idx_bone_matrix_set, idx_bone, idx_anim_key + 1); 204 + f64 t0 = *get_bone_matrix_time(idx_bone_matrix_set, idx_bone, idx_anim_key); 205 + f64 t1 = *get_bone_matrix_time(idx_bone_matrix_set, idx_bone, idx_anim_key + 1); 206 206 if (animation_timepoint > t0 && animation_timepoint < t1) { 207 207 bone->last_anim_key = idx_anim_key; 208 208 return idx_anim_key;
+24 -24
src/anim.hpp
··· 13 13 public: 14 14 struct BoneMatrixPool { 15 15 Array<m4> bone_matrices; 16 - Array<real64> times; 17 - uint32 n_bone_matrix_sets; 16 + Array<f64> times; 17 + u32 n_bone_matrix_sets; 18 18 }; 19 19 20 20 struct Bone { 21 21 char name[MAX_NODE_NAME_LENGTH]; 22 - uint32 idx_parent; 23 - uint32 n_anim_keys; 24 - uint32 last_anim_key; 22 + u32 idx_parent; 23 + u32 n_anim_keys; 24 + u32 last_anim_key; 25 25 m4 offset; 26 26 }; 27 27 28 28 struct Animation { 29 29 char name[MAX_NODE_NAME_LENGTH]; 30 - real64 duration; 30 + f64 duration; 31 31 // NOTE: Index into the BoneMatrixPool 32 - uint32 idx_bone_matrix_set; 32 + u32 idx_bone_matrix_set; 33 33 }; 34 34 35 35 struct Component { 36 36 entities::Handle entity_handle; 37 37 Bone bones[MAX_N_BONES]; 38 38 m4 bone_matrices[MAX_N_BONES]; 39 - uint32 n_bones; 39 + u32 n_bones; 40 40 Animation animations[MAX_N_ANIMATIONS]; 41 - uint32 n_animations; 41 + u32 n_animations; 42 42 }; 43 43 44 44 struct ComponentSet { ··· 49 49 BoneMatrixPool bone_matrix_pool; 50 50 }; 51 51 52 - static bool32 is_animation_component_valid(Component *animation_component); 53 - static uint32 push_to_bone_matrix_pool(); 52 + static bool is_animation_component_valid(Component *animation_component); 53 + static u32 push_to_bone_matrix_pool(); 54 54 static m4 * get_bone_matrix( 55 - uint32 idx, 56 - uint32 idx_bone, 57 - uint32 idx_anim_key 55 + u32 idx, 56 + u32 idx_bone, 57 + u32 idx_anim_key 58 58 ); 59 59 static void update_animation_components( 60 60 ComponentSet *animation_component_set, ··· 63 63 static void make_bone_matrices_for_animation_bone( 64 64 Component *animation_component, 65 65 aiNodeAnim *ai_channel, 66 - uint32 idx_animation, 67 - uint32 idx_bone 66 + u32 idx_animation, 67 + u32 idx_bone 68 68 ); 69 69 static Component * find_animation_component(spatial::Component *spatial_component); 70 70 static void init(anim::State *anim_state, memory::Pool *pool); 71 71 72 72 private: 73 - static real64 * get_bone_matrix_time( 74 - uint32 idx, 75 - uint32 idx_bone, 76 - uint32 idx_anim_key 73 + static f64 * get_bone_matrix_time( 74 + u32 idx, 75 + u32 idx_bone, 76 + u32 idx_anim_key 77 77 ); 78 - static uint32 get_bone_matrix_anim_key_for_timepoint( 78 + static u32 get_bone_matrix_anim_key_for_timepoint( 79 79 Component *animation_component, 80 - real64 animation_timepoint, 81 - uint32 idx_bone_matrix_set, 82 - uint32 idx_bone 80 + f64 animation_timepoint, 81 + u32 idx_bone_matrix_set, 82 + u32 idx_bone 83 83 ); 84 84 85 85 static anim::State *state;
+11 -11
src/array.hpp
··· 9 9 public: 10 10 memory::Pool *memory_pool = nullptr; 11 11 const char *debug_name = nullptr; 12 - uint32 length = 0; 13 - uint32 capacity = 0; 14 - bool32 is_sparse = false; 15 - uint32 starting_idx = 0; 12 + u32 length = 0; 13 + u32 capacity = 0; 14 + bool is_sparse = false; 15 + u32 starting_idx = 0; 16 16 T *items = nullptr; 17 17 18 18 void alloc() { ··· 24 24 alloc(); 25 25 } 26 26 assert(this->length < this->capacity); 27 - uint32 new_idx = this->length; 27 + u32 new_idx = this->length; 28 28 this->length++; 29 29 T* new_slot = &this->items[new_idx]; 30 30 return new_slot; ··· 36 36 return new_slot; 37 37 } 38 38 39 - T* get(uint32 idx) { 39 + T* get(u32 idx) { 40 40 if (!this->items) { 41 41 alloc(); 42 42 } ··· 48 48 return &this->items[idx]; 49 49 } 50 50 51 - T* operator[](uint32 idx) { 51 + T* operator[](u32 idx) { 52 52 return get(idx); 53 53 } 54 54 ··· 75 75 this->length = 0; 76 76 } 77 77 78 - void delete_elements_after_index(uint32 idx) { 78 + void delete_elements_after_index(u32 idx) { 79 79 memset(&this->items[idx], 0, sizeof(T) * (this->length - idx)); 80 80 this->length = idx; 81 81 } 82 82 83 83 Array( 84 84 memory::Pool *memory_pool, 85 - uint32 capacity, 85 + u32 capacity, 86 86 const char *debug_name, 87 - bool32 is_sparse = false, 88 - uint32 starting_idx = 0 87 + bool is_sparse = false, 88 + u32 starting_idx = 0 89 89 ) : 90 90 memory_pool(memory_pool), 91 91 debug_name(debug_name),
+3 -3
src/behavior.cpp
··· 10 10 behavior::State *behavior::state = nullptr; 11 11 12 12 13 - behavior::Function behavior::function_map[(uint32)Behavior::length] = { 13 + behavior::Function behavior::function_map[(u32)Behavior::length] = { 14 14 (behavior::Function)nullptr, 15 15 (behavior::Function)behavior_functions::test, 16 16 (behavior::Function)behavior_functions::char_movement_test, ··· 49 49 } 50 50 51 51 52 - bool32 52 + bool 53 53 behavior::is_behavior_component_valid(behavior::Component *behavior_component) 54 54 { 55 55 return behavior_component->behavior != Behavior::none; ··· 67 67 68 68 entities::Handle entity_handle = behavior_component->entity_handle; 69 69 70 - auto handler = function_map[(uint32)behavior_component->behavior]; 70 + auto handler = function_map[(u32)behavior_component->behavior]; 71 71 if (handler) { 72 72 handler(entity_handle); 73 73 }
+2 -2
src/behavior.hpp
··· 34 34 35 35 typedef void (*Function) (entities::Handle entity_handle); 36 36 37 - static Function function_map[(uint32)Behavior::length]; 37 + static Function function_map[(u32)Behavior::length]; 38 38 39 39 static char const * behavior_to_string(Behavior behavior); 40 40 static Behavior behavior_from_string(const char *str); 41 - static bool32 is_behavior_component_valid(Component *behavior_component); 41 + static bool is_behavior_component_valid(Component *behavior_component); 42 42 static void update_behavior_components(ComponentSet *component_set); 43 43 static void init( 44 44 behavior::State *behavior_state,
+14 -14
src/behavior_functions.cpp
··· 16 16 } 17 17 18 18 spatial_component->rotation = 19 - glm::angleAxis((real32)sin(1.0f - (engine::get_t())), v3(0.0f, 1.0f, 0.0f)) * 20 - glm::angleAxis((real32)cos(1.0f - (engine::get_t())), v3(1.0f, 0.0f, 0.0f)); 19 + glm::angleAxis((f32)sin(1.0f - (engine::get_t())), v3(0.0f, 1.0f, 0.0f)) * 20 + glm::angleAxis((f32)cos(1.0f - (engine::get_t())), v3(1.0f, 0.0f, 0.0f)); 21 21 } 22 22 23 23 ··· 41 41 42 42 // Update position 43 43 spatial_component->position.x = 44 - (real32)sin((engine::get_t()) * 1.0f) * 4.0f + 45 - (real32)sin((engine::get_t()) * 2.0f) * 0.1f + 46 - (real32)cos((engine::get_t()) * 3.0f) * 0.3f; 44 + (f32)sin((engine::get_t()) * 1.0f) * 4.0f + 45 + (f32)sin((engine::get_t()) * 2.0f) * 0.1f + 46 + (f32)cos((engine::get_t()) * 3.0f) * 0.3f; 47 47 spatial_component->position.z = 48 - (real32)cos((engine::get_t()) * 1.0f) * 4.0f + 49 - (real32)cos((engine::get_t()) * 2.0f) * 0.3f + 50 - (real32)sin((engine::get_t()) * 3.0f) * 0.1f; 48 + (f32)cos((engine::get_t()) * 1.0f) * 4.0f + 49 + (f32)cos((engine::get_t()) * 2.0f) * 0.3f + 50 + (f32)sin((engine::get_t()) * 3.0f) * 0.1f; 51 51 spatial_component->rotation = 52 52 glm::angleAxis( 53 - (real32)sin((engine::get_t()) * 3.0f) + radians(70.0f), v3(0.0f, 1.0f, 0.0f) 53 + (f32)sin((engine::get_t()) * 3.0f) + radians(70.0f), v3(0.0f, 1.0f, 0.0f) 54 54 ) * 55 55 glm::angleAxis( 56 - (real32)cos((engine::get_t()) * 2.0f) / 3.0f, v3(0.0f, 1.0f, 0.0f) 56 + (f32)cos((engine::get_t()) * 2.0f) / 3.0f, v3(0.0f, 1.0f, 0.0f) 57 57 ) * 58 - glm::angleAxis((real32)cos((engine::get_t()) * 2.0f), v3(1.0f, 0.0f, 0.0f)) * 59 - glm::angleAxis((real32)sin((engine::get_t()) * 1.5f) / 2.0f, v3(1.0f, 0.0f, 0.0f)) * 60 - glm::angleAxis((real32)sin((engine::get_t()) * 2.5f) / 1.5f, v3(0.5f, 0.5f, 0.2f)); 58 + glm::angleAxis((f32)cos((engine::get_t()) * 2.0f), v3(1.0f, 0.0f, 0.0f)) * 59 + glm::angleAxis((f32)sin((engine::get_t()) * 1.5f) / 2.0f, v3(1.0f, 0.0f, 0.0f)) * 60 + glm::angleAxis((f32)sin((engine::get_t()) * 2.5f) / 1.5f, v3(0.5f, 0.5f, 0.2f)); 61 61 #if 0 62 62 spatial_component->position.x = -5.0f; 63 63 spatial_component->position.z = -5.0f; 64 64 spatial_component->rotation = 65 - glm::angleAxis((real32)sin((engine::get_t())) + radians(70.0f), v3(0.0f, 1.0f, 0.0f)) * 65 + glm::angleAxis((f32)sin((engine::get_t())) + radians(70.0f), v3(0.0f, 1.0f, 0.0f)) * 66 66 glm::angleAxis(radians(90.0f), v3(1.0f, 0.0f, 0.0f)); 67 67 #endif 68 68
+16 -16
src/cameras.cpp
··· 16 16 17 17 void 18 18 cameras::update_matrices( 19 - Camera *camera, uint32 window_width, uint32 window_height 19 + Camera *camera, u32 window_width, u32 window_height 20 20 ) { 21 21 if (window_width == 0 || window_height == 0) { 22 22 return; ··· 32 32 33 33 void 34 34 cameras::update_ui_matrices( 35 - Camera *camera, uint32 window_width, uint32 window_height 35 + Camera *camera, u32 window_width, u32 window_height 36 36 ) { 37 - camera->ui_projection = glm::ortho(0.0f, (real32)window_width, 38 - 0.0f, (real32)window_height); 37 + camera->ui_projection = glm::ortho(0.0f, (f32)window_width, 38 + 0.0f, (f32)window_height); 39 39 } 40 40 41 41 42 42 void 43 - cameras::move_front_back(Camera *camera, real32 sign, real64 dt) 43 + cameras::move_front_back(Camera *camera, f32 sign, f64 dt) 44 44 { 45 - camera->position += (sign * camera->speed * (real32)dt) * camera->front; 45 + camera->position += (sign * camera->speed * (f32)dt) * camera->front; 46 46 } 47 47 48 48 49 49 void 50 - cameras::move_left_right(Camera *camera, real32 sign, real64 dt) 50 + cameras::move_left_right(Camera *camera, f32 sign, f64 dt) 51 51 { 52 52 v3 direction = normalize(cross( 53 53 camera->front, camera->up 54 54 )); 55 - camera->position += (sign * camera->speed * (real32)dt) * direction; 55 + camera->position += (sign * camera->speed * (f32)dt) * direction; 56 56 } 57 57 58 58 59 59 void 60 - cameras::move_up_down(Camera *camera, real32 sign, real64 dt) 60 + cameras::move_up_down(Camera *camera, f32 sign, f64 dt) 61 61 { 62 - camera->position += (sign * camera->speed * (real32)dt) * camera->up; 62 + camera->position += (sign * camera->speed * (f32)dt) * camera->up; 63 63 } 64 64 65 65 ··· 80 80 void 81 81 cameras::init( 82 82 cameras::State *cameras_state, 83 - uint32 window_width, 84 - uint32 window_height 83 + u32 window_width, 84 + u32 window_height 85 85 ) { 86 86 cameras::state = cameras_state; 87 87 cameras::state->camera_main.type = CameraType::perspective; ··· 104 104 105 105 void 106 106 cameras::update_matrices_ortho( 107 - Camera *camera, uint32 window_width, uint32 window_height 107 + Camera *camera, u32 window_width, u32 window_height 108 108 ) { 109 109 if (window_width == 0 || window_height == 0) { 110 110 return; ··· 119 119 120 120 void 121 121 cameras::update_matrices_perspective( 122 - Camera *camera, uint32 window_width, uint32 window_height 122 + Camera *camera, u32 window_width, u32 window_height 123 123 ) { 124 124 if (window_width == 0 || window_height == 0) { 125 125 return; ··· 134 134 camera->position + camera->front, camera->up); 135 135 136 136 camera->projection = glm::perspective(radians(camera->horizontal_fov), 137 - (real32)window_width / (real32)window_height, 137 + (f32)window_width / (f32)window_height, 138 138 camera->near_clip_dist, camera->far_clip_dist); 139 139 // https://en.wikipedia.org/wiki/Field_of_view_in_video_games#Field_of_view_calculations 140 - camera->vertical_fov = (real32)degrees(2 * 140 + camera->vertical_fov = (f32)degrees(2 * 141 141 atan(tan(radians(camera->horizontal_fov) / 2) * window_height / window_width)); 142 142 }
+17 -17
src/cameras.hpp
··· 11 11 struct Camera { 12 12 m4 view; 13 13 v3 position; 14 - real64 pitch; 14 + f64 pitch; 15 15 m4 projection; 16 16 m4 ui_projection; 17 - real32 exposure; 18 - real32 horizontal_fov; 19 - real32 vertical_fov; 20 - real32 near_clip_dist; 21 - real32 far_clip_dist; 17 + f32 exposure; 18 + f32 horizontal_fov; 19 + f32 vertical_fov; 20 + f32 near_clip_dist; 21 + f32 far_clip_dist; 22 22 CameraType type; 23 - real64 yaw; 23 + f64 yaw; 24 24 v3 front; 25 25 v3 up; 26 - real32 speed; 26 + f32 speed; 27 27 }; 28 28 29 29 struct State { ··· 32 32 33 33 static Camera * get_main(); 34 34 static void update_matrices( 35 - Camera *camera, uint32 window_width, uint32 window_height 35 + Camera *camera, u32 window_width, u32 window_height 36 36 ); 37 37 static void update_ui_matrices( 38 - Camera *camera, uint32 window_width, uint32 window_height 38 + Camera *camera, u32 window_width, u32 window_height 39 39 ); 40 - static void move_front_back(Camera *camera, real32 sign, real64 dt); 41 - static void move_left_right(Camera *camera, real32 sign, real64 dt); 42 - static void move_up_down(Camera *camera, real32 sign, real64 dt); 40 + static void move_front_back(Camera *camera, f32 sign, f64 dt); 41 + static void move_left_right(Camera *camera, f32 sign, f64 dt); 42 + static void move_up_down(Camera *camera, f32 sign, f64 dt); 43 43 static void update_mouse(Camera *camera, v2 mouse_offset); 44 44 static void init( 45 45 cameras::State *cameras_state, 46 - uint32 window_width, 47 - uint32 window_height 46 + u32 window_width, 47 + u32 window_height 48 48 ); 49 49 50 50 private: 51 51 static void update_matrices_ortho( 52 - Camera *camera, uint32 window_width, uint32 window_height 52 + Camera *camera, u32 window_width, u32 window_height 53 53 ); 54 54 static void update_matrices_perspective( 55 - Camera *camera, uint32 window_width, uint32 window_height 55 + Camera *camera, u32 window_width, u32 window_height 56 56 ); 57 57 58 58 static cameras::State *state;
+4 -4
src/common.hpp
··· 3 3 #pragma once 4 4 5 5 struct WindowSize { 6 - int32 width; // in pixels (size of framebuffer) 7 - int32 height; // in pixels (size of framebuffer) 8 - uint32 screencoord_width; // in screen coordinates 9 - uint32 screencoord_height; // in screen coordinates 6 + i32 width; // in pixels (size of framebuffer) 7 + i32 height; // in pixels (size of framebuffer) 8 + u32 screencoord_width; // in screen coordinates 9 + u32 screencoord_height; // in screen coordinates 10 10 }; 11 11
+24 -24
src/constants.hpp
··· 5 5 #include "types.hpp" 6 6 7 7 // Math things 8 - constexpr real32 PI32 = 3.14159265359f; 9 - constexpr real64 PI = 3.14159265358979323846; 8 + constexpr f32 PI32 = 3.14159265359f; 9 + constexpr f64 PI = 3.14159265358979323846; 10 10 11 11 // Platform things 12 12 #if !defined(MAX_PATH) ··· 72 72 constexpr char DEFAULT_SCENE[] = "terraintest"; 73 73 constexpr char SCENE_EXTENSION[] = ".peony_scene"; 74 74 constexpr char MATERIAL_FILE_EXTENSION[] = ".peony_materials"; 75 - constexpr uint32 N_LOADING_THREADS = 5; 76 - constexpr uint32 MAX_N_ENTITIES = 256; 77 - constexpr uint32 MAX_N_MODELS = 128; 78 - constexpr uint32 MAX_N_ANIMATED_MODELS = 128; 79 - constexpr uint32 MAX_DEBUG_NAME_LENGTH = 256; 80 - constexpr uint32 MAX_GENEROUS_STRING_LENGTH = 512; 81 - constexpr uint32 MAX_N_MESHES = 128; 82 - constexpr uint32 MAX_N_MATERIALS = 256; 83 - constexpr uint32 MAX_N_MATERIALS_PER_MODEL = 16; 84 - constexpr uint32 MAX_UNIFORM_LENGTH = 256; 85 - constexpr uint32 MAX_N_TEXTURE_POOL_SIZES = 6; 86 - constexpr uint32 MAX_N_TEXTURES_PER_MATERIAL = 16; 87 - constexpr uint8 MAX_N_UNIFORMS = 64; 88 - constexpr uint8 MAX_UNIFORM_NAME_LENGTH = 64; 89 - constexpr uint8 MAX_N_TEXTURE_UNITS = 80; 90 - constexpr uint32 MAX_COMMON_NAME_LENGTH = 128; 91 - constexpr uint32 MAX_N_BONES = 128; 92 - constexpr uint32 MAX_N_BONES_PER_VERTEX = 4; 93 - constexpr uint32 MAX_NODE_NAME_LENGTH = 32; 94 - constexpr uint32 MAX_N_ANIMATIONS = 2; 95 - constexpr uint32 MAX_N_ANIM_KEYS = 256; 96 - constexpr uint16 MAX_N_LIGHTS = 8; 75 + constexpr u32 N_LOADING_THREADS = 5; 76 + constexpr u32 MAX_N_ENTITIES = 256; 77 + constexpr u32 MAX_N_MODELS = 128; 78 + constexpr u32 MAX_N_ANIMATED_MODELS = 128; 79 + constexpr u32 MAX_DEBUG_NAME_LENGTH = 256; 80 + constexpr u32 MAX_GENEROUS_STRING_LENGTH = 512; 81 + constexpr u32 MAX_N_MESHES = 128; 82 + constexpr u32 MAX_N_MATERIALS = 256; 83 + constexpr u32 MAX_N_MATERIALS_PER_MODEL = 16; 84 + constexpr u32 MAX_UNIFORM_LENGTH = 256; 85 + constexpr u32 MAX_N_TEXTURE_POOL_SIZES = 6; 86 + constexpr u32 MAX_N_TEXTURES_PER_MATERIAL = 16; 87 + constexpr u8 MAX_N_UNIFORMS = 64; 88 + constexpr u8 MAX_UNIFORM_NAME_LENGTH = 64; 89 + constexpr u8 MAX_N_TEXTURE_UNITS = 80; 90 + constexpr u32 MAX_COMMON_NAME_LENGTH = 128; 91 + constexpr u32 MAX_N_BONES = 128; 92 + constexpr u32 MAX_N_BONES_PER_VERTEX = 4; 93 + constexpr u32 MAX_NODE_NAME_LENGTH = 32; 94 + constexpr u32 MAX_N_ANIMATIONS = 2; 95 + constexpr u32 MAX_N_ANIM_KEYS = 256; 96 + constexpr u16 MAX_N_LIGHTS = 8;
+2 -2
src/core.cpp
··· 97 97 98 98 99 99 void 100 - core::mouse_callback(GLFWwindow *window, real64 x, real64 y) 100 + core::mouse_callback(GLFWwindow *window, f64 x, f64 y) 101 101 { 102 102 v2 mouse_pos = v2(x, y); 103 103 input::update_mouse(mouse_pos); ··· 119 119 120 120 121 121 void 122 - core::char_callback(GLFWwindow* window, uint32 codepoint) { 122 + core::char_callback(GLFWwindow* window, u32 codepoint) { 123 123 input::update_text_input(codepoint); 124 124 } 125 125
+2 -2
src/core.hpp
··· 13 13 static int run(); 14 14 static void framebuffer_size_callback(GLFWwindow* window, int width, int height); 15 15 static void mouse_button_callback(GLFWwindow *window, int button, int action, int mods); 16 - static void mouse_callback(GLFWwindow *window, real64 x, real64 y); 16 + static void mouse_callback(GLFWwindow *window, f64 x, f64 y); 17 17 static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods); 18 - static void char_callback(GLFWwindow* window, uint32 codepoint); 18 + static void char_callback(GLFWwindow* window, u32 codepoint); 19 19 20 20 private: 21 21 static bool init_state(State *state, memory::Pool *asset_memory_pool);
+2 -2
src/debug.cpp
··· 8 8 } 9 9 10 10 11 - real64 debug_end_timer(chrono::steady_clock::time_point t0) { 12 - return ((chrono::duration<real64, std::milli>)(chrono::steady_clock::now() - t0)).count(); 11 + f64 debug_end_timer(chrono::steady_clock::time_point t0) { 12 + return ((chrono::duration<f64, std::milli>)(chrono::steady_clock::now() - t0)).count(); 13 13 }
+2 -2
src/debug.hpp
··· 8 8 #include "types.hpp" 9 9 10 10 chrono::steady_clock::time_point debug_start_timer(); 11 - real64 debug_end_timer(chrono::steady_clock::time_point t0); 11 + f64 debug_end_timer(chrono::steady_clock::time_point t0); 12 12 13 13 #if USE_TIMERS 14 14 #define START_TIMER(name) \ ··· 16 16 17 17 #define END_TIMER_MIN(name, min_duration_ms) \ 18 18 { \ 19 - real64 duration = debug_end_timer(debug_timerstart_##name); \ 19 + f64 duration = debug_end_timer(debug_timerstart_##name); \ 20 20 if (duration >= min_duration_ms) { \ 21 21 logs::info("Timer %s took %0.fms", #name, duration); \ 22 22 } \
+12 -12
src/debug_ui.cpp
··· 125 125 126 126 127 127 void 128 - debug_ui::get_entity_text_representation(char *text, entities::Entity *entity, uint8 depth) 128 + debug_ui::get_entity_text_representation(char *text, entities::Entity *entity, u8 depth) 129 129 { 130 130 // TODO: fixme 131 131 engine::State *engine_state = engine::todo_fixme_get_engine_state(); ··· 142 142 return; 143 143 } 144 144 145 - bool32 has_spatial_component = spatial::is_spatial_component_valid(spatial_component); 146 - bool32 has_drawable_component = drawable::is_component_valid( 145 + bool has_spatial_component = spatial::is_spatial_component_valid(spatial_component); 146 + bool has_drawable_component = drawable::is_component_valid( 147 147 engine_state->drawable_component_set.components[handle]); 148 - bool32 has_light_component = lights::is_light_component_valid( 148 + bool has_light_component = lights::is_light_component_valid( 149 149 engine_state->light_component_set.components[handle]); 150 - bool32 has_behavior_component = behavior::is_behavior_component_valid( 150 + bool has_behavior_component = behavior::is_behavior_component_valid( 151 151 engine_state->behavior_component_set.components[handle]); 152 - bool32 has_animation_component = anim::is_animation_component_valid( 152 + bool has_animation_component = anim::is_animation_component_valid( 153 153 engine_state->animation_component_set.components[handle]); 154 154 155 - for (uint8 level = 0; level < depth; level++) { 155 + for (u8 level = 0; level < depth; level++) { 156 156 strcat(text, " "); 157 157 } 158 158 ··· 190 190 191 191 if (spatial::is_spatial_component_valid(spatial_component)) { 192 192 // NOTE: This is super slow lol. 193 - uint32 n_children_found = 0; 193 + u32 n_children_found = 0; 194 194 each (child_spatial_component, engine_state->spatial_component_set.components) { 195 195 if ( 196 196 child_spatial_component->parent_entity_handle == ··· 210 210 } 211 211 } 212 212 if (n_children_found > 5) { 213 - for (uint8 level = 0; level < (depth + 1); level++) { 213 + for (u8 level = 0; level < (depth + 1); level++) { 214 214 strcat(text, " "); 215 215 } 216 216 strcat(text, "(and "); ··· 233 233 234 234 text[0] = '\0'; 235 235 236 - constexpr uint32 const MAX_N_SHOWN_ENTITIES = 35; 237 - uint32 idx_entity = 0; 236 + constexpr u32 const MAX_N_SHOWN_ENTITIES = 35; 237 + u32 idx_entity = 0; 238 238 each (entity, engine_state->entity_set.entities) { 239 239 if (idx_entity > MAX_N_SHOWN_ENTITIES) { 240 240 sprintf(text + strlen(text), ··· 261 261 262 262 bool have_seen_non_internal = false; 263 263 264 - uint32 idx = 0; 264 + u32 idx = 0; 265 265 each (material, *mats::get_materials()) { 266 266 strcat(text, "- "); 267 267 strcat(text, material->name);
+1 -1
src/debug_ui.hpp
··· 13 13 static void render_debug_ui(WindowSize *window_size); 14 14 15 15 private: 16 - static void get_entity_text_representation(char *text, entities::Entity *entity, uint8 depth); 16 + static void get_entity_text_representation(char *text, entities::Entity *entity, u8 depth); 17 17 static void get_scene_text_representation(char *text); 18 18 static void get_materials_text_representation(char *text); 19 19 };
+6 -6
src/debugdraw.cpp
··· 22 22 23 23 24 24 void 25 - debugdraw::draw_ray(spatial::Ray *ray, real32 length, v4 color) 25 + debugdraw::draw_ray(spatial::Ray *ray, f32 length, v4 color) 26 26 { 27 27 v3 end_pos = ray->origin + ray->direction * length; 28 28 v3 x_axis = util::get_orthogonal_vector(&ray->direction); 29 29 v3 z_axis = cross(ray->direction, x_axis); 30 - real32 chevron_size = 0.2f; 30 + f32 chevron_size = 0.2f; 31 31 v3 chevron_1_pos = end_pos + ((-ray->direction + x_axis) * chevron_size); 32 32 v3 chevron_2_pos = end_pos + ((-ray->direction - x_axis) * chevron_size); 33 33 v3 chevron_3_pos = end_pos + ((-ray->direction + z_axis) * chevron_size); ··· 101 101 102 102 103 103 void 104 - debugdraw::draw_point(v3 position, real32 size, v4 color) 104 + debugdraw::draw_point(v3 position, f32 size, v4 color) 105 105 { 106 106 spatial::Obb obb = { 107 107 .center=position, ··· 158 158 glBindBuffer(GL_ARRAY_BUFFER, debugdraw::state->vbo); 159 159 glBufferData(GL_ARRAY_BUFFER, VERTEX_SIZE * MAX_N_VERTICES, NULL, GL_DYNAMIC_DRAW); 160 160 161 - uint32 location; 161 + u32 location; 162 162 163 163 // position (vec3) 164 164 location = 0; ··· 170 170 location = 1; 171 171 glEnableVertexAttribArray(location); 172 172 glVertexAttribPointer(location, 4, GL_FLOAT, GL_FALSE, VERTEX_SIZE, 173 - (void*)(3 * sizeof(real32))); 173 + (void*)(3 * sizeof(f32))); 174 174 } 175 175 176 176 memory::destroy_memory_pool(&temp_memory_pool); ··· 178 178 179 179 180 180 void 181 - debugdraw::push_vertices(DebugDrawVertex vertices[], uint32 n_vertices) 181 + debugdraw::push_vertices(DebugDrawVertex vertices[], u32 n_vertices) 182 182 { 183 183 if (debugdraw::state->n_vertices_pushed + n_vertices > MAX_N_VERTICES) { 184 184 logs::error("Pushed too many DebugDraw vertices, did you forget to call debugdraw::clear()?");
+9 -9
src/debugdraw.hpp
··· 8 8 9 9 class debugdraw { 10 10 public: 11 - static constexpr uint32 MAX_N_VERTICES = 2048; 12 - static constexpr uint32 VERTEX_LENGTH = 7; 13 - static constexpr size_t VERTEX_SIZE = sizeof(real32) * VERTEX_LENGTH; 11 + static constexpr u32 MAX_N_VERTICES = 2048; 12 + static constexpr u32 VERTEX_LENGTH = 7; 13 + static constexpr size_t VERTEX_SIZE = sizeof(f32) * VERTEX_LENGTH; 14 14 15 15 struct DebugDrawVertex { 16 16 v3 position; ··· 19 19 20 20 struct State { 21 21 shaders::Asset shader_asset; 22 - uint32 vao; 23 - uint32 vbo; 22 + u32 vao; 23 + u32 vbo; 24 24 DebugDrawVertex vertices[MAX_N_VERTICES]; 25 - uint32 n_vertices_pushed; 25 + u32 n_vertices_pushed; 26 26 }; 27 27 28 28 static void draw_line(v3 start_pos, v3 end_pos, v4 color); 29 - static void draw_ray(spatial::Ray *ray, real32 length, v4 color); 29 + static void draw_ray(spatial::Ray *ray, f32 length, v4 color); 30 30 static void draw_quad( 31 31 v3 p1, // clockwise: top left 32 32 v3 p2, // top right ··· 46 46 v4 color 47 47 ); 48 48 static void draw_obb(spatial::Obb *obb, v4 color); 49 - static void draw_point(v3 position, real32 size, v4 color); 49 + static void draw_point(v3 position, f32 size, v4 color); 50 50 static void clear(); 51 51 static void render(); 52 52 static void init(debugdraw::State *debug_draw_state, memory::Pool *memory_pool); 53 53 54 54 private: 55 - static void push_vertices(DebugDrawVertex vertices[], uint32 n_vertices); 55 + static void push_vertices(DebugDrawVertex vertices[], u32 n_vertices); 56 56 57 57 static debugdraw::State *state; 58 58 };
+1 -1
src/drawable.cpp
··· 74 74 } 75 75 76 76 77 - bool32 77 + bool 78 78 drawable::is_component_valid(drawable::Component *drawable_component) 79 79 { 80 80 return geom::is_mesh_valid(&drawable_component->mesh);
+3 -3
src/drawable.hpp
··· 9 9 public: 10 10 enum class Mode { regular, depth }; 11 11 12 - enum class Pass : uint32 { 12 + enum class Pass : u32 { 13 13 none = 0, 14 14 shadowcaster = (1 << 0), 15 15 deferred = (1 << 1), ··· 32 32 33 33 struct ComponentSet { 34 34 Array<drawable::Component> components; 35 - uint32 last_drawn_shader_program; 35 + u32 last_drawn_shader_program; 36 36 }; 37 37 38 38 static char const * render_pass_to_string(drawable::Pass render_pass); 39 39 static drawable::Pass render_pass_from_string(const char* str); 40 - static bool32 is_component_valid(drawable::Component *drawable_component); 40 + static bool is_component_valid(drawable::Component *drawable_component); 41 41 static void destroy_component(drawable::Component *drawable_component); 42 42 };
+1 -1
src/drawinfo.hpp
··· 6 6 public: 7 7 enum class Mode { regular, depth }; 8 8 9 - enum class Pass : uint32 { 9 + enum class Pass : u32 { 10 10 none = 0, 11 11 shadowcaster = (1 << 0), 12 12 deferred = (1 << 1),
+19 -19
src/engine.cpp
··· 168 168 } 169 169 170 170 171 - real64 171 + f64 172 172 engine::get_t() 173 173 { 174 174 return engine::state->t; 175 175 } 176 176 177 177 178 - real64 178 + f64 179 179 engine::get_dt() 180 180 { 181 181 return engine::state->dt; ··· 288 288 engine::destroy_non_internal_entities() 289 289 { 290 290 for ( 291 - uint32 idx = engine::state->entity_set.first_non_internal_handle; 291 + u32 idx = engine::state->entity_set.first_non_internal_handle; 292 292 idx < engine::state->entity_set.entities.length; 293 293 idx++ 294 294 ) { ··· 333 333 } 334 334 335 335 336 - bool32 336 + bool 337 337 engine::load_scene(const char *scene_name) 338 338 { 339 339 // If the current scene has not finished loading, we can neither ··· 403 403 // already encountered this model in a previous entry. If two entities 404 404 // have the same `model_path`, we just make one model and use it in both. 405 405 models::ModelLoader *found_model_loader = engine::state->model_loaders.find( 406 - [model_path](models::ModelLoader *candidate_model_loader) -> bool32 { 406 + [model_path](models::ModelLoader *candidate_model_loader) -> bool { 407 407 return pstr_eq(model_path, candidate_model_loader->model_path); 408 408 } 409 409 ); ··· 461 461 462 462 463 463 void 464 - engine::update_light_position(real32 amount) 464 + engine::update_light_position(f32 amount) 465 465 { 466 466 each (light_component, engine::state->light_component_set.components) { 467 467 if (light_component->type == lights::LightType::directional) { ··· 520 520 } 521 521 522 522 if (input::is_key_down(GLFW_KEY_Z)) { 523 - update_light_position(0.10f * (real32)(engine::get_dt())); 523 + update_light_position(0.10f * (f32)(engine::get_dt())); 524 524 } 525 525 526 526 if (input::is_key_down(GLFW_KEY_X)) { 527 - update_light_position(-0.10f * (real32)(engine::get_dt())); 527 + update_light_position(-0.10f * (f32)(engine::get_dt())); 528 528 } 529 529 530 530 if (input::is_key_down(GLFW_KEY_SPACE)) { ··· 575 575 } 576 576 577 577 578 - bool32 578 + bool 579 579 engine::check_all_entities_loaded() 580 580 { 581 581 bool are_all_done_loading = true; ··· 587 587 } 588 588 } 589 589 590 - uint32 new_n_valid_model_loaders = 0; 590 + u32 new_n_valid_model_loaders = 0; 591 591 each (model_loader, engine::state->model_loaders) { 592 592 if (!models::is_model_loader_valid(model_loader)) { 593 593 continue; ··· 600 600 } 601 601 engine::state->n_valid_model_loaders = new_n_valid_model_loaders; 602 602 603 - uint32 new_n_valid_entity_loaders = 0; 603 + u32 new_n_valid_entity_loaders = 0; 604 604 each (entity_loader, engine::state->entity_loader_set.loaders) { 605 605 if (!models::is_entity_loader_valid(entity_loader)) { 606 606 continue; ··· 608 608 new_n_valid_entity_loaders++; 609 609 610 610 models::ModelLoader *model_loader = engine::state->model_loaders.find( 611 - [entity_loader](models::ModelLoader *candidate_model_loader) -> bool32 { 611 + [entity_loader](models::ModelLoader *candidate_model_loader) -> bool { 612 612 return pstr_eq(entity_loader->model_path, candidate_model_loader->model_path); 613 613 } 614 614 ); ··· 670 670 671 671 672 672 engine::TimingInfo 673 - engine::init_timing_info(uint32 target_fps) 673 + engine::init_timing_info(u32 target_fps) 674 674 { 675 675 TimingInfo timing_info = {}; 676 676 timing_info.second_start = chrono::steady_clock::now(); 677 677 timing_info.frame_start = chrono::steady_clock::now(); 678 678 timing_info.last_frame_start = chrono::steady_clock::now(); 679 679 timing_info.frame_duration = chrono::nanoseconds( 680 - (uint32)((real64)1.0f / (real64)target_fps) 680 + (u32)((f64)1.0f / (f64)target_fps) 681 681 ); 682 682 return timing_info; 683 683 } 684 684 685 685 686 686 void 687 - engine::update_timing_info(TimingInfo *timing, uint32 *last_fps) 687 + engine::update_timing_info(TimingInfo *timing, u32 *last_fps) 688 688 { 689 689 timing->n_frames_since_start++; 690 690 timing->last_frame_start = timing->frame_start; ··· 692 692 timing->time_frame_should_end = timing->frame_start + timing->frame_duration; 693 693 694 694 timing->n_frames_this_second++; 695 - chrono::duration<real64> time_since_second_start = 695 + chrono::duration<f64> time_since_second_start = 696 696 timing->frame_start - timing->second_start; 697 697 if (time_since_second_start >= chrono::seconds(1)) { 698 698 timing->second_start = timing->frame_start; ··· 708 708 engine::state->dt = util::get_us_from_duration( 709 709 timing->frame_start - timing->last_frame_start); 710 710 if (engine::state->timescale_diff != 0.0f) { 711 - engine::state->dt *= max(1.0f + engine::state->timescale_diff, (real64)0.01f); 711 + engine::state->dt *= max(1.0f + engine::state->timescale_diff, (f64)0.01f); 712 712 } 713 713 714 714 engine::state->perf_counters.dt_hist[engine::state->perf_counters.dt_hist_idx] = ··· 717 717 if (engine::state->perf_counters.dt_hist_idx >= DT_HIST_LENGTH) { 718 718 engine::state->perf_counters.dt_hist_idx = 0; 719 719 } 720 - real64 dt_hist_sum = 0.0f; 721 - for (uint32 idx = 0; idx < DT_HIST_LENGTH; idx++) { 720 + f64 dt_hist_sum = 0.0f; 721 + for (u32 idx = 0; idx < DT_HIST_LENGTH; idx++) { 722 722 dt_hist_sum += engine::state->perf_counters.dt_hist[idx]; 723 723 } 724 724 engine::state->perf_counters.dt_average = dt_hist_sum / DT_HIST_LENGTH;
+26 -26
src/engine.hpp
··· 17 17 #include "cameras.hpp" 18 18 19 19 20 - static constexpr uint32 DT_HIST_LENGTH = 512; 20 + static constexpr u32 DT_HIST_LENGTH = 512; 21 21 22 22 23 23 class engine { ··· 29 29 chrono::steady_clock::time_point time_frame_should_end; 30 30 31 31 chrono::steady_clock::time_point second_start; 32 - uint32 n_frames_this_second; 33 - uint32 n_frames_since_start; 32 + u32 n_frames_this_second; 33 + u32 n_frames_since_start; 34 34 }; 35 35 36 36 struct PerfCounters { 37 - real64 dt_average; 38 - real64 dt_hist[DT_HIST_LENGTH]; 39 - uint32 dt_hist_idx; 40 - uint32 last_fps; 37 + f64 dt_average; 38 + f64 dt_hist[DT_HIST_LENGTH]; 39 + u32 dt_hist_idx; 40 + u32 last_fps; 41 41 }; 42 42 43 43 struct State { 44 - bool32 is_manual_frame_advance_enabled; 45 - bool32 should_manually_advance_to_next_frame; 46 - bool32 should_stop; 47 - bool32 should_pause; 48 - bool32 should_limit_fps; 44 + bool is_manual_frame_advance_enabled; 45 + bool should_manually_advance_to_next_frame; 46 + bool should_stop; 47 + bool should_pause; 48 + bool should_limit_fps; 49 49 char current_scene_name[MAX_COMMON_NAME_LENGTH]; 50 50 // NOTE: `t` and `dt` will not change when gameplay is paused. 51 - real64 t; // us 52 - real64 dt; // us 53 - real64 timescale_diff; 51 + f64 t; // us 52 + f64 dt; // us 53 + f64 timescale_diff; 54 54 PerfCounters perf_counters; 55 - uint32 n_valid_model_loaders; 56 - uint32 n_valid_entity_loaders; 57 - bool32 is_world_loaded; 58 - bool32 was_world_ever_loaded; 55 + u32 n_valid_model_loaders; 56 + u32 n_valid_entity_loaders; 57 + bool is_world_loaded; 58 + bool was_world_ever_loaded; 59 59 Array<models::ModelLoader> model_loaders; 60 60 models::EntityLoaderSet entity_loader_set; 61 61 entities::Set entity_set; ··· 88 88 static behavior::Component * get_behavior_component(entities::Handle entity_handle); 89 89 static anim::Component * get_animation_component(entities::Handle entity_handle); 90 90 static physics::Component * get_physics_component(entities::Handle entity_handle); 91 - static real64 get_t(); 92 - static real64 get_dt(); 91 + static f64 get_t(); 92 + static f64 get_dt(); 93 93 static void run_main_loop(GLFWwindow *window, WindowSize *window_size); 94 94 static void init(engine::State *engine_state, memory::Pool *asset_memory_pool); 95 95 ··· 98 98 static void destroy_model_loaders(); 99 99 static void destroy_non_internal_entities(); 100 100 static void destroy_scene(); 101 - static bool32 load_scene(const char *scene_name); 101 + static bool load_scene(const char *scene_name); 102 102 static void handle_console_command(); 103 - static void update_light_position(real32 amount); 103 + static void update_light_position(f32 amount); 104 104 static void process_input(GLFWwindow *window); 105 - static bool32 check_all_entities_loaded(); 105 + static bool check_all_entities_loaded(); 106 106 static void update(WindowSize *window_size); 107 - static TimingInfo init_timing_info(uint32 target_fps); 108 - static void update_timing_info(TimingInfo *timing, uint32 *last_fps); 107 + static TimingInfo init_timing_info(u32 target_fps); 108 + static void update_timing_info(TimingInfo *timing, u32 *last_fps); 109 109 static void update_dt_and_perf_counters(TimingInfo *timing); 110 110 };
+1 -1
src/entities.hpp
··· 9 9 class entities { 10 10 public: 11 11 // NOTE: 0 is an invalid handle. 12 - typedef uint32 Handle; 12 + typedef u32 Handle; 13 13 14 14 struct Entity { 15 15 Handle handle;
+10 -10
src/files.cpp
··· 9 9 unsigned char * 10 10 files::load_image( 11 11 const char *path, 12 - int32 *width, 13 - int32 *height, 14 - int32 *n_channels, 12 + i32 *width, 13 + i32 *height, 14 + i32 *n_channels, 15 15 bool should_flip 16 16 ) { 17 17 stbi_set_flip_vertically_on_load(should_flip); ··· 26 26 unsigned char * 27 27 files::load_image( 28 28 const char *path, 29 - int32 *width, 30 - int32 *height, 31 - int32 *n_channels 29 + i32 *width, 30 + i32 *height, 31 + i32 *n_channels 32 32 ) { 33 33 return load_image(path, width, height, n_channels, true); 34 34 } ··· 41 41 } 42 42 43 43 44 - uint32 44 + u32 45 45 files::get_file_size(char const *path) 46 46 { 47 47 FILE *f = fopen(path, "rb"); ··· 50 50 return 0; 51 51 } 52 52 fseek(f, 0, SEEK_END); 53 - uint32 size = ftell(f); 53 + u32 size = ftell(f); 54 54 fclose(f); 55 55 return size; 56 56 } ··· 65 65 return nullptr; 66 66 } 67 67 fseek(f, 0, SEEK_END); 68 - uint32 file_size = ftell(f); 68 + u32 file_size = ftell(f); 69 69 fseek(f, 0, SEEK_SET); 70 70 71 71 char *string = (char*)memory::push(memory_pool, file_size + 1, path); ··· 90 90 return nullptr; 91 91 } 92 92 fseek(f, 0, SEEK_END); 93 - uint32 file_size = ftell(f); 93 + u32 file_size = ftell(f); 94 94 fseek(f, 0, SEEK_SET); 95 95 96 96 size_t result = fread(string, file_size, 1, f);
+3 -3
src/files.hpp
··· 7 7 class files { 8 8 public: 9 9 static unsigned char * load_image( 10 - char const *path, int32 *width, int32 *height, int32 *n_channels, bool should_flip 10 + char const *path, i32 *width, i32 *height, i32 *n_channels, bool should_flip 11 11 ); 12 12 static unsigned char * load_image( 13 - char const *path, int32 *width, int32 *height, int32 *n_channels 13 + char const *path, i32 *width, i32 *height, i32 *n_channels 14 14 ); 15 15 static void free_image(unsigned char *image_data); 16 - static uint32 get_file_size(char const *path); 16 + static u32 get_file_size(char const *path); 17 17 static char const * load_file(memory::Pool *memory_pool, char const *path); 18 18 static char const * load_file(char *string, char const *path); 19 19 };
+9 -9
src/fonts.cpp
··· 9 9 #include "intrinsics.hpp" 10 10 11 11 12 - real32 13 - fonts::frac_px_to_px(uint32 n) 12 + f32 13 + fonts::frac_px_to_px(u32 n) 14 14 { 15 - return (real32)(n >> 6); 15 + return (f32)(n >> 6); 16 16 } 17 17 18 18 19 - real32 20 - fonts::font_unit_to_px(uint32 n) 19 + f32 20 + fonts::font_unit_to_px(u32 n) 21 21 { 22 22 // NOTE: We should be dividing by units_per_em here...probably? 23 23 // This is because we expect height etc. to be in "font units". 24 24 // But treating these metrics as "fractional pixels" seems to work, 25 25 // whereas division by units_per_em doesn't. 26 26 // Check this in more detail. 27 - return (real32)(n >> 6); 27 + return (f32)(n >> 6); 28 28 } 29 29 30 30 ··· 49 49 FT_Library *ft_library, 50 50 const char *name, 51 51 const char *filename, 52 - uint16 font_size 52 + u16 font_size 53 53 ) { 54 54 font_asset->name = name; 55 55 font_asset->font_size = font_size; ··· 90 90 FT_GlyphSlot glyph = face->glyph; 91 91 92 92 // TODO: Can we avoid loading all characters twice here? 93 - for (uint32 c = 0; c < CHAR_MAX_CODEPOINT_TO_LOAD; c++) { 93 + for (u32 c = 0; c < CHAR_MAX_CODEPOINT_TO_LOAD; c++) { 94 94 Character *character = font_asset->characters.push(); 95 95 96 96 if (FT_Load_Char(face, c, FT_LOAD_RENDER)) { ··· 105 105 106 106 mats::activate_font_texture(texture_atlas->texture_name); 107 107 108 - for (uint32 c = 0; c < CHAR_MAX_CODEPOINT_TO_LOAD; c++) { 108 + for (u32 c = 0; c < CHAR_MAX_CODEPOINT_TO_LOAD; c++) { 109 109 if ( 110 110 // Unicode C0 controls 111 111 (c <= 0x1F) ||
+10 -10
src/fonts.hpp
··· 12 12 public: 13 13 // NOTE: Unicode is only the same as ASCII until 0x7F. 14 14 // We can change this to 0xFF when we add Unicode support. 15 - static constexpr uint32 CHAR_MAX_CODEPOINT_TO_LOAD = 0x7F; 15 + static constexpr u32 CHAR_MAX_CODEPOINT_TO_LOAD = 0x7F; 16 16 17 17 struct Character { 18 18 iv2 size; ··· 24 24 struct FontAsset { 25 25 const char *name; 26 26 Array<Character> characters; 27 - uint32 texture; 28 - uint32 font_size; 29 - uint32 units_per_em; 30 - uint32 ascender; 31 - uint32 descender; 32 - uint32 height; 27 + u32 texture; 28 + u32 font_size; 29 + u32 units_per_em; 30 + u32 ascender; 31 + u32 descender; 32 + u32 height; 33 33 }; 34 34 35 - static real32 frac_px_to_px(uint32 n); 36 - static real32 font_unit_to_px(uint32 n); 35 + static f32 frac_px_to_px(u32 n); 36 + static f32 font_unit_to_px(u32 n); 37 37 static FontAsset * get_by_name(Array<FontAsset> *assets, const char *name); 38 38 static FontAsset * init_font_asset( 39 39 FontAsset *font_asset, ··· 42 42 FT_Library *ft_library, 43 43 const char *name, 44 44 const char *filename, 45 - uint16 font_size 45 + u16 font_size 46 46 ); 47 47 48 48 private:
+38 -38
src/geom.cpp
··· 6 6 void 7 7 geom::setup_mesh_vertex_buffers( 8 8 Mesh *mesh, 9 - Vertex *vertex_data, uint32 n_vertices, 10 - uint32 *index_data, uint32 n_indices 9 + Vertex *vertex_data, u32 n_vertices, 10 + u32 *index_data, u32 n_indices 11 11 ) { 12 12 assert(vertex_data && n_vertices > 0); 13 13 14 - uint32 vertex_size = sizeof(Vertex); 15 - uint32 index_size = sizeof(uint32); 14 + u32 vertex_size = sizeof(Vertex); 15 + u32 index_size = sizeof(u32); 16 16 17 17 glGenVertexArrays(1, &mesh->vao); 18 18 glGenBuffers(1, &mesh->vbo); ··· 26 26 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mesh->ebo); 27 27 glBufferData(GL_ELEMENT_ARRAY_BUFFER, index_size * n_indices, index_data, GL_STATIC_DRAW); 28 28 29 - uint32 location; 29 + u32 location; 30 30 31 31 location = 0; 32 32 glEnableVertexAttribArray(location); ··· 51 51 } 52 52 53 53 54 - bool32 54 + bool 55 55 geom::is_mesh_valid(geom::Mesh *mesh) 56 56 { 57 57 return mesh->vao > 0; ··· 70 70 void 71 71 geom::make_plane( 72 72 memory::Pool *memory_pool, 73 - uint32 x_size, uint32 z_size, 74 - uint32 n_x_segments, uint32 n_z_segments, 75 - uint32 *n_vertices, uint32 *n_indices, 76 - geom::Vertex **vertex_data, uint32 **index_data 73 + u32 x_size, u32 z_size, 74 + u32 n_x_segments, u32 n_z_segments, 75 + u32 *n_vertices, u32 *n_indices, 76 + geom::Vertex **vertex_data, u32 **index_data 77 77 ) { 78 78 *n_vertices = 0; 79 79 *n_indices = 0; 80 80 81 - uint32 n_total_vertices = (n_x_segments + 1) * (n_z_segments + 1); 82 - uint32 index_data_length = (n_x_segments) * (n_z_segments) * 6; 81 + u32 n_total_vertices = (n_x_segments + 1) * (n_z_segments + 1); 82 + u32 index_data_length = (n_x_segments) * (n_z_segments) * 6; 83 83 84 84 *vertex_data = (geom::Vertex*)memory::push(memory_pool, sizeof(geom::Vertex) * n_total_vertices, "plane_vertex_data"); 85 - *index_data = (uint32*)memory::push(memory_pool, sizeof(uint32) * index_data_length, "plane_index_data"); 85 + *index_data = (u32*)memory::push(memory_pool, sizeof(u32) * index_data_length, "plane_index_data"); 86 86 87 - for (uint32 idx_x = 0; idx_x <= n_x_segments; idx_x++) { 88 - for (uint32 idx_z = 0; idx_z <= n_z_segments; idx_z++) { 89 - real32 x_segment = (real32)idx_x / (real32)n_x_segments; 90 - real32 z_segment = (real32)idx_z / (real32)n_z_segments; 91 - real32 x_pos = x_segment * x_size - (x_size / 2); 92 - real32 y_pos = 0; 93 - real32 z_pos = z_segment * z_size - (z_size / 2); 87 + for (u32 idx_x = 0; idx_x <= n_x_segments; idx_x++) { 88 + for (u32 idx_z = 0; idx_z <= n_z_segments; idx_z++) { 89 + f32 x_segment = (f32)idx_x / (f32)n_x_segments; 90 + f32 z_segment = (f32)idx_z / (f32)n_z_segments; 91 + f32 x_pos = x_segment * x_size - (x_size / 2); 92 + f32 y_pos = 0; 93 + f32 z_pos = z_segment * z_size - (z_size / 2); 94 94 95 95 (*vertex_data)[(*n_vertices)++] = { 96 96 .position = { x_pos, y_pos, z_pos }, ··· 102 102 103 103 // NOTE: Counterclockwise winding order. I could swear this code is CW 104 104 // order though. Not sure where the confusion happens. 105 - for (uint32 idx_x = 0; idx_x < n_x_segments; idx_x++) { 106 - for (uint32 idx_z = 0; idx_z < n_z_segments; idx_z++) { 105 + for (u32 idx_x = 0; idx_x < n_x_segments; idx_x++) { 106 + for (u32 idx_z = 0; idx_z < n_z_segments; idx_z++) { 107 107 // This current vertex. 108 108 (*index_data)[(*n_indices)++] = (idx_x * (n_z_segments + 1)) + idx_z; 109 109 // Next row, right of this one. ··· 125 125 void 126 126 geom::make_sphere( 127 127 memory::Pool *memory_pool, 128 - uint32 n_x_segments, uint32 n_y_segments, 129 - uint32 *n_vertices, uint32 *n_indices, 130 - geom::Vertex **vertex_data, uint32 **index_data 128 + u32 n_x_segments, u32 n_y_segments, 129 + u32 *n_vertices, u32 *n_indices, 130 + geom::Vertex **vertex_data, u32 **index_data 131 131 ) { 132 132 *n_vertices = 0; 133 133 *n_indices = 0; 134 134 135 - uint32 total_n_vertices = (n_x_segments + 1) * (n_y_segments + 1); 136 - uint32 index_data_length = (n_x_segments + 1) * (n_y_segments) * 2; 135 + u32 total_n_vertices = (n_x_segments + 1) * (n_y_segments + 1); 136 + u32 index_data_length = (n_x_segments + 1) * (n_y_segments) * 2; 137 137 138 138 *vertex_data = (geom::Vertex*)memory::push(memory_pool, sizeof(geom::Vertex) * total_n_vertices, "sphere_vertex_data"); 139 - *index_data = (uint32*)memory::push(memory_pool, sizeof(uint32) * index_data_length, "sphere_index_data"); 139 + *index_data = (u32*)memory::push(memory_pool, sizeof(u32) * index_data_length, "sphere_index_data"); 140 140 141 - for (uint32 y = 0; y <= n_y_segments; y++) { 142 - for (uint32 x = 0; x <= n_x_segments; x++) { 143 - real32 x_segment = (real32)x / (real32)n_x_segments; 144 - real32 y_segment = (real32)y / (real32)n_y_segments; 145 - real32 x_pos = cos(x_segment * 2.0f * PI32) * sin(y_segment * PI32); 146 - real32 y_pos = cos(y_segment * PI32); 147 - real32 z_pos = sin(x_segment * 2.0f * PI32) * sin(y_segment * PI32); 141 + for (u32 y = 0; y <= n_y_segments; y++) { 142 + for (u32 x = 0; x <= n_x_segments; x++) { 143 + f32 x_segment = (f32)x / (f32)n_x_segments; 144 + f32 y_segment = (f32)y / (f32)n_y_segments; 145 + f32 x_pos = cos(x_segment * 2.0f * PI32) * sin(y_segment * PI32); 146 + f32 y_pos = cos(y_segment * PI32); 147 + f32 z_pos = sin(x_segment * 2.0f * PI32) * sin(y_segment * PI32); 148 148 149 149 (*vertex_data)[(*n_vertices)++] = { 150 150 .position = {x_pos, y_pos, z_pos}, ··· 154 154 } 155 155 } 156 156 157 - for (uint32 y = 0; y < n_y_segments; y++) { 157 + for (u32 y = 0; y < n_y_segments; y++) { 158 158 if (y % 2 == 0) { 159 - for (uint32 x = 0; x <= n_x_segments; x++) { 159 + for (u32 x = 0; x <= n_x_segments; x++) { 160 160 (*index_data)[(*n_indices)++] = (y + 1) * (n_x_segments + 1) + x; 161 161 (*index_data)[(*n_indices)++] = y * (n_x_segments + 1) + x; 162 162 } 163 163 } else { 164 - for (int32 x = n_x_segments; x >= 0; x--) { 164 + for (i32 x = n_x_segments; x >= 0; x--) { 165 165 (*index_data)[(*n_indices)++] = y * (n_x_segments + 1) + x; 166 166 (*index_data)[(*n_indices)++] = (y + 1) * (n_x_segments + 1) + x; 167 167 }
+18 -18
src/geom.hpp
··· 12 12 v3 position; 13 13 v3 normal; 14 14 v2 tex_coords; 15 - uint32 bone_idxs[MAX_N_BONES_PER_VERTEX]; 16 - real32 bone_weights[MAX_N_BONES_PER_VERTEX]; 15 + u32 bone_idxs[MAX_N_BONES_PER_VERTEX]; 16 + f32 bone_weights[MAX_N_BONES_PER_VERTEX]; 17 17 }; 18 18 19 19 struct Mesh { ··· 21 21 m4 transform; 22 22 char material_name[MAX_COMMON_NAME_LENGTH]; 23 23 pack::Pack indices_pack; 24 - uint32 vao; 25 - uint32 vbo; 26 - uint32 ebo; 24 + u32 vao; 25 + u32 vbo; 26 + u32 ebo; 27 27 GLenum mode; 28 28 Vertex *vertices; 29 - uint32 *indices; 30 - uint32 n_vertices; 31 - uint32 n_indices; 29 + u32 *indices; 30 + u32 n_vertices; 31 + u32 n_indices; 32 32 }; 33 33 34 34 static void setup_mesh_vertex_buffers( 35 35 Mesh *mesh, 36 - Vertex *vertex_data, uint32 n_vertices, 37 - uint32 *index_data, uint32 n_indices 36 + Vertex *vertex_data, u32 n_vertices, 37 + u32 *index_data, u32 n_indices 38 38 ); 39 - static bool32 is_mesh_valid(Mesh *mesh); 39 + static bool is_mesh_valid(Mesh *mesh); 40 40 static void destroy_mesh(Mesh *mesh); 41 41 static void make_plane( 42 42 memory::Pool *memory_pool, 43 - uint32 x_size, uint32 z_size, 44 - uint32 n_x_segments, uint32 n_z_segments, 45 - uint32 *n_vertices, uint32 *n_indices, 46 - Vertex **vertex_data, uint32 **index_data 43 + u32 x_size, u32 z_size, 44 + u32 n_x_segments, u32 n_z_segments, 45 + u32 *n_vertices, u32 *n_indices, 46 + Vertex **vertex_data, u32 **index_data 47 47 ); 48 48 static void make_sphere( 49 49 memory::Pool *memory_pool, 50 - uint32 n_x_segments, uint32 n_y_segments, 51 - uint32 *n_vertices, uint32 *n_indices, 52 - Vertex **vertex_data, uint32 **index_data 50 + u32 n_x_segments, u32 n_y_segments, 51 + u32 *n_vertices, u32 *n_indices, 52 + Vertex **vertex_data, u32 **index_data 53 53 ); 54 54 };
+65 -65
src/gui.cpp
··· 12 12 13 13 14 14 void 15 - gui::update_screen_dimensions(uint32 new_window_width, uint32 new_window_height) 15 + gui::update_screen_dimensions(u32 new_window_width, u32 new_window_height) 16 16 { 17 17 gui::state->window_dimensions = v2(new_window_width, new_window_height); 18 18 } ··· 110 110 draw_heading(gui::state->heading_text, 111 111 v4(0.0f, 0.33f, 0.93f, gui::state->heading_opacity)); 112 112 if (gui::state->heading_fadeout_delay > 0.0f) { 113 - gui::state->heading_fadeout_delay -= (real32)(engine::get_dt()); 113 + gui::state->heading_fadeout_delay -= (f32)(engine::get_dt()); 114 114 } else { 115 115 gui::state->heading_opacity -= 116 - gui::state->heading_fadeout_duration * (real32)(engine::get_dt()); 116 + gui::state->heading_fadeout_duration * (f32)(engine::get_dt()); 117 117 } 118 118 } 119 119 } 120 120 121 121 122 - bool32 123 - gui::draw_toggle(Container *container, const char *text, bool32 toggle_state) 122 + bool 123 + gui::draw_toggle(Container *container, const char *text, bool toggle_state) 124 124 { 125 - bool32 is_pressed = false; 125 + bool is_pressed = false; 126 126 127 127 v2 text_dimensions = get_text_dimensions(fonts::get_by_name(gui::state->font_assets, "body"), text); 128 128 v2 button_dimensions = TOGGLE_BUTTON_SIZE + BUTTON_DEFAULT_BORDER * 2.0f; ··· 206 206 } 207 207 208 208 209 - bool32 209 + bool 210 210 gui::draw_button(Container *container, const char *text) 211 211 { 212 - bool32 is_pressed = false; 212 + bool is_pressed = false; 213 213 214 214 v2 text_dimensions = get_text_dimensions(fonts::get_by_name(gui::state->font_assets, "body"), text); 215 215 v2 button_dimensions = text_dimensions + BUTTON_AUTOSIZE_PADDING + BUTTON_DEFAULT_BORDER * 2.0f; ··· 251 251 } 252 252 253 253 fonts::FontAsset *font_asset = fonts::get_by_name(gui::state->font_assets, "body"); 254 - real32 line_height = fonts::font_unit_to_px(font_asset->height); 255 - real32 line_spacing = floor(line_height * CONSOLE_LINE_SPACING_FACTOR); 254 + f32 line_height = fonts::font_unit_to_px(font_asset->height); 255 + f32 line_spacing = floor(line_height * CONSOLE_LINE_SPACING_FACTOR); 256 256 257 257 // Draw console log 258 258 { ··· 262 262 v2(gui::state->window_dimensions.x, MAX_CONSOLE_LOG_HEIGHT), 263 263 CONSOLE_BG_COLOR); 264 264 265 - uint32 idx_line = gui::state->console.idx_log_start; 265 + u32 idx_line = gui::state->console.idx_log_start; 266 266 while (idx_line != gui::state->console.idx_log_end) { 267 267 v2 text_dimensions = get_text_dimensions(font_asset, gui::state->console.log[idx_line]); 268 268 next_element_position.y -= text_dimensions.y + line_spacing; ··· 277 277 278 278 // Draw console input 279 279 { 280 - real32 console_input_height = line_height + (2.0f * CONSOLE_PADDING.y); 280 + f32 console_input_height = line_height + (2.0f * CONSOLE_PADDING.y); 281 281 v2 console_input_position = v2(0.0f, MAX_CONSOLE_LOG_HEIGHT); 282 282 283 283 draw_rect(console_input_position, ··· 332 332 333 333 void 334 334 gui::set_heading( 335 - const char *text, real32 opacity, 336 - real32 fadeout_duration, real32 fadeout_delay 335 + const char *text, f32 opacity, 336 + f32 fadeout_duration, f32 fadeout_delay 337 337 ) { 338 338 gui::state->heading_text = text; 339 339 gui::state->heading_opacity = opacity; ··· 348 348 gui::State* gui_state, 349 349 iv2 texture_atlas_size, 350 350 Array<fonts::FontAsset> *font_assets, 351 - uint32 window_width, uint32 window_height 351 + u32 window_width, u32 window_height 352 352 ) { 353 353 gui::state = gui_state; 354 354 ··· 376 376 377 377 378 378 void 379 - gui::push_vertices(real32 *vertices, uint32 n_vertices) 379 + gui::push_vertices(f32 *vertices, u32 n_vertices) 380 380 { 381 381 renderer::push_gui_vertices(vertices, n_vertices); 382 382 } ··· 387 387 { 388 388 // NOTE: This returns the dimensions around the main body of the text. 389 389 // This does not include descenders. 390 - real32 line_height = fonts::font_unit_to_px(font_asset->height); 391 - real32 line_spacing = line_height * LINE_SPACING_FACTOR; 392 - real32 ascender = fonts::font_unit_to_px(font_asset->ascender); 390 + f32 line_height = fonts::font_unit_to_px(font_asset->height); 391 + f32 line_spacing = line_height * LINE_SPACING_FACTOR; 392 + f32 ascender = fonts::font_unit_to_px(font_asset->ascender); 393 393 394 - real32 start_x = 0.0f; 395 - real32 start_y = 0.0f - (line_height - ascender); 396 - real32 max_x = 0.0f; 397 - real32 curr_x = start_x; 398 - real32 curr_y = start_y; 394 + f32 start_x = 0.0f; 395 + f32 start_y = 0.0f - (line_height - ascender); 396 + f32 max_x = 0.0f; 397 + f32 curr_x = start_x; 398 + f32 curr_y = start_y; 399 399 size_t str_length = strlen(str); 400 400 401 - for (uint32 idx = 0; idx < str_length; idx++) { 401 + for (u32 idx = 0; idx < str_length; idx++) { 402 402 char c = str[idx]; 403 403 404 404 if (c < 32) { ··· 483 483 { 484 484 // NOTE: We use top-left as our origin, but OpenGL uses bottom-left. 485 485 // Flip the y axis before drawing. 486 - real32 x0 = position.x; 487 - real32 x1 = x0 + dimensions.x; 488 - real32 y0 = (real32)gui::state->window_dimensions.y - position.y; 489 - real32 y1 = y0 - dimensions.y; 486 + f32 x0 = position.x; 487 + f32 x1 = x0 + dimensions.x; 488 + f32 y0 = (f32)gui::state->window_dimensions.y - position.y; 489 + f32 y1 = y0 - dimensions.y; 490 490 491 - real32 vertices[VERTEX_LENGTH * 6] = { 491 + f32 vertices[VERTEX_LENGTH * 6] = { 492 492 x0, y0, -1.0f, -1.0f, color.r, color.g, color.b, color.a, 493 493 x0, y1, -1.0f, -1.0f, color.r, color.g, color.b, color.a, 494 494 x1, y1, -1.0f, -1.0f, color.r, color.g, color.b, color.a, ··· 508 508 ) { 509 509 fonts::FontAsset *font_asset = fonts::get_by_name(gui::state->font_assets, font_name); 510 510 511 - real32 line_height = fonts::font_unit_to_px(font_asset->height); 512 - real32 line_spacing = line_height * LINE_SPACING_FACTOR; 513 - real32 ascender = fonts::font_unit_to_px(font_asset->ascender); 511 + f32 line_height = fonts::font_unit_to_px(font_asset->height); 512 + f32 line_spacing = line_height * LINE_SPACING_FACTOR; 513 + f32 ascender = fonts::font_unit_to_px(font_asset->ascender); 514 514 515 515 // NOTE: When changing this code, remember that the text positioning logic 516 516 // needs to be replicated in `get_text_dimensions()`! 517 - real32 start_x = position.x; 518 - real32 start_y = position.y - (line_height - ascender); 519 - real32 curr_x = start_x; 520 - real32 curr_y = start_y; 517 + f32 start_x = position.x; 518 + f32 start_y = position.y - (line_height - ascender); 519 + f32 curr_x = start_x; 520 + f32 curr_y = start_y; 521 521 size_t str_length = strlen(str); 522 522 523 - for (uint32 idx = 0; idx < str_length; idx++) { 523 + for (u32 idx = 0; idx < str_length; idx++) { 524 524 char c = str[idx]; 525 525 526 526 if (c < 32) { ··· 538 538 continue; 539 539 } 540 540 541 - real32 char_x = curr_x + character->bearing.x; 542 - real32 char_y = curr_y + fonts::font_unit_to_px(font_asset->height) - character->bearing.y; 541 + f32 char_x = curr_x + character->bearing.x; 542 + f32 char_y = curr_y + fonts::font_unit_to_px(font_asset->height) - character->bearing.y; 543 543 544 - real32 tex_x = (real32)character->tex_coords.x / gui::state->texture_atlas_size.x; 545 - real32 tex_y = (real32)character->tex_coords.y / gui::state->texture_atlas_size.y; 546 - real32 tex_w = (real32)character->size.x / gui::state->texture_atlas_size.x; 547 - real32 tex_h = (real32)character->size.y / gui::state->texture_atlas_size.y; 544 + f32 tex_x = (f32)character->tex_coords.x / gui::state->texture_atlas_size.x; 545 + f32 tex_y = (f32)character->tex_coords.y / gui::state->texture_atlas_size.y; 546 + f32 tex_w = (f32)character->size.x / gui::state->texture_atlas_size.x; 547 + f32 tex_h = (f32)character->size.y / gui::state->texture_atlas_size.y; 548 548 549 - real32 w = (real32)character->size.x; 550 - real32 h = (real32)character->size.y; 549 + f32 w = (f32)character->size.x; 550 + f32 h = (f32)character->size.y; 551 551 552 552 curr_x += fonts::frac_px_to_px(character->advance.x); 553 553 curr_y += fonts::frac_px_to_px(character->advance.y); ··· 559 559 560 560 // NOTE: We use top-left as our origin, but OpenGL uses bottom-left. 561 561 // Flip the y axis before drawing. 562 - real32 x0 = char_x; 563 - real32 x1 = x0 + w; 564 - real32 y0 = (real32)gui::state->window_dimensions.y - char_y; 565 - real32 y1 = y0 - h; 562 + f32 x0 = char_x; 563 + f32 x1 = x0 + w; 564 + f32 y0 = (f32)gui::state->window_dimensions.y - char_y; 565 + f32 y1 = y0 - h; 566 566 567 - real32 tex_x0 = tex_x; 568 - real32 tex_x1 = tex_x0 + tex_w; 569 - real32 tex_y0 = tex_y; 570 - real32 tex_y1 = tex_y0 + tex_h; 567 + f32 tex_x0 = tex_x; 568 + f32 tex_x1 = tex_x0 + tex_w; 569 + f32 tex_y0 = tex_y; 570 + f32 tex_y1 = tex_y0 + tex_h; 571 571 572 - real32 vertices[VERTEX_LENGTH * 6] = { 572 + f32 vertices[VERTEX_LENGTH * 6] = { 573 573 x0, y0, tex_x0, tex_y0, color.r, color.g, color.b, color.a, 574 574 x0, y1, tex_x0, tex_y1, color.r, color.g, color.b, color.a, 575 575 x1, y1, tex_x1, tex_y1, color.r, color.g, color.b, color.a, ··· 616 616 617 617 618 618 void 619 - gui::draw_line(v2 start, v2 end, real32 thickness, v4 color) 619 + gui::draw_line(v2 start, v2 end, f32 thickness, v4 color) 620 620 { 621 621 // NOTE: We use top-left as our origin, but OpenGL uses bottom-left. 622 622 // Flip the y axis before drawing. ··· 626 626 // 0------------------3 627 627 // | | 628 628 // 1------------------2 629 - real32 x0 = start.x + delta.y; 630 - real32 y0 = gui::state->window_dimensions.y - start.y; 631 - real32 x1 = start.x; 632 - real32 y1 = gui::state->window_dimensions.y - start.y - delta.x; 633 - real32 x2 = end.x; 634 - real32 y2 = gui::state->window_dimensions.y - end.y - delta.x; 635 - real32 x3 = end.x + delta.y; 636 - real32 y3 = gui::state->window_dimensions.y - end.y; 629 + f32 x0 = start.x + delta.y; 630 + f32 y0 = gui::state->window_dimensions.y - start.y; 631 + f32 x1 = start.x; 632 + f32 y1 = gui::state->window_dimensions.y - start.y - delta.x; 633 + f32 x2 = end.x; 634 + f32 y2 = gui::state->window_dimensions.y - end.y - delta.x; 635 + f32 x3 = end.x + delta.y; 636 + f32 y3 = gui::state->window_dimensions.y - end.y; 637 637 638 - real32 vertices[VERTEX_LENGTH * 6] = { 638 + f32 vertices[VERTEX_LENGTH * 6] = { 639 639 x0, y0, -1.0f, -1.0f, color.r, color.g, color.b, color.a, 640 640 x1, y1, -1.0f, -1.0f, color.r, color.g, color.b, color.a, 641 641 x2, y2, -1.0f, -1.0f, color.r, color.g, color.b, color.a,
+26 -26
src/gui.hpp
··· 9 9 10 10 class gui { 11 11 public: 12 - static constexpr uint32 MAX_CONSOLE_LINE_LENGTH = 200; 13 - static constexpr uint32 MAX_N_CONSOLE_LINES = 30; 12 + static constexpr u32 MAX_CONSOLE_LINE_LENGTH = 200; 13 + static constexpr u32 MAX_N_CONSOLE_LINES = 30; 14 14 static constexpr char CONSOLE_SYMBOL[] = "> "; 15 15 static constexpr size_t CONSOLE_SYMBOL_LENGTH = 2; 16 16 17 17 static constexpr const char *MAIN_FONT_REGULAR = "SofiaProRegular.otf"; 18 18 static constexpr const char *MAIN_FONT_BOLD = "SofiaProBold.otf"; 19 - static constexpr real32 LINE_SPACING_FACTOR = 1.8f; 20 - static constexpr real32 CONSOLE_LINE_SPACING_FACTOR = 1.2f; 19 + static constexpr f32 LINE_SPACING_FACTOR = 1.8f; 20 + static constexpr f32 CONSOLE_LINE_SPACING_FACTOR = 1.2f; 21 21 22 - static constexpr uint32 VERTEX_LENGTH = 8; 22 + static constexpr u32 VERTEX_LENGTH = 8; 23 23 24 24 static constexpr v2 TEXT_SHADOW_OFFSET = v2(1.0f); 25 25 ··· 38 38 static constexpr v2 BUTTON_AUTOSIZE_PADDING = v2(20.0f, 20.0f); 39 39 static constexpr v2 BUTTON_DEFAULT_BORDER = v2(0.0f); 40 40 41 - static constexpr real32 NAMED_VALUE_NAME_WIDTH = 250.0f; 42 - static constexpr real32 TOGGLE_SPACING = 20.0f; 41 + static constexpr f32 NAMED_VALUE_NAME_WIDTH = 250.0f; 42 + static constexpr f32 TOGGLE_SPACING = 20.0f; 43 43 static constexpr v2 TOGGLE_BUTTON_SIZE = v2(20.0f); 44 44 static constexpr v2 TOGGLE_BUTTON_DEFAULT_BORDER = v2(0.0f); 45 45 46 - static constexpr real32 MAX_CONSOLE_LOG_HEIGHT = 350.0f; 46 + static constexpr f32 MAX_CONSOLE_LOG_HEIGHT = 350.0f; 47 47 static constexpr v2 CONSOLE_PADDING = v2(10.0f); 48 48 49 49 struct Container { ··· 58 58 // The main axis has a 1.0f, while the orthogonal axis has a 0.0f. 59 59 v2 direction; 60 60 v2 padding; 61 - real32 title_bar_height; 62 - uint32 n_elements; 63 - real32 element_margin; 61 + f32 title_bar_height; 62 + u32 n_elements; 63 + f32 element_margin; 64 64 }; 65 65 66 66 struct GameConsole { 67 - bool32 is_enabled; 67 + bool is_enabled; 68 68 char log[gui::MAX_N_CONSOLE_LINES][gui::MAX_CONSOLE_LINE_LENGTH]; 69 - uint32 idx_log_start; 70 - uint32 idx_log_end; 69 + u32 idx_log_start; 70 + u32 idx_log_end; 71 71 }; 72 72 73 73 struct State { ··· 83 83 Container *container_being_moved; 84 84 85 85 // Heading 86 - real32 heading_opacity; 86 + f32 heading_opacity; 87 87 const char *heading_text; 88 - real32 heading_fadeout_duration; 89 - real32 heading_fadeout_delay; 88 + f32 heading_fadeout_duration; 89 + f32 heading_fadeout_delay; 90 90 }; 91 91 92 92 static void update_screen_dimensions( 93 - uint32 new_window_width, uint32 new_window_height 93 + u32 new_window_width, u32 new_window_height 94 94 ); 95 95 static void update_mouse_button(); 96 96 static void update_mouse(); ··· 99 99 static Container * make_container(const char *title, v2 position); 100 100 static void draw_heading(const char *str, v4 color); 101 101 static void tick_heading(); 102 - static bool32 draw_toggle( 102 + static bool draw_toggle( 103 103 Container *container, 104 104 const char *text, 105 - bool32 toggle_state 105 + bool toggle_state 106 106 ); 107 107 static void draw_named_value( 108 108 Container *container, ··· 110 110 const char *value_text 111 111 ); 112 112 static void draw_body_text(Container *container, const char *text); 113 - static bool32 draw_button(Container *container, const char *text); 113 + static bool draw_button(Container *container, const char *text); 114 114 static void draw_console(char *console_input_text); 115 115 static bool is_console_enabled(); 116 116 static void set_console_enabled(bool val); 117 117 static void log(const char *format, ...); 118 118 static void set_heading( 119 - const char *text, real32 opacity, 120 - real32 fadeout_duration, real32 fadeout_delay 119 + const char *text, f32 opacity, 120 + f32 fadeout_duration, f32 fadeout_delay 121 121 ); 122 122 static void init( 123 123 memory::Pool *memory_pool, 124 124 gui::State* gui_state, 125 125 iv2 texture_atlas_size, 126 126 Array<fonts::FontAsset> *font_assets, 127 - uint32 window_width, uint32 window_height 127 + u32 window_width, u32 window_height 128 128 ); 129 129 130 130 private: 131 131 static void request_cursor(input::CursorType cursor); 132 132 static void set_cursor(); 133 - static void push_vertices(real32 *vertices, uint32 n_vertices); 133 + static void push_vertices(f32 *vertices, u32 n_vertices); 134 134 static v2 get_text_dimensions(fonts::FontAsset *font_asset, char const *str); 135 135 static v2 center_bb(v2 container_position, v2 container_dimensions, v2 element_dimensions); 136 136 static v2 add_element_to_container(Container *container, v2 element_dimensions); ··· 146 146 v4 color 147 147 ); 148 148 static void draw_container(Container *container); 149 - static void draw_line(v2 start, v2 end, real32 thickness, v4 color); 149 + static void draw_line(v2 start, v2 end, f32 thickness, v4 color); 150 150 static void draw_frame(v2 position, v2 bottomright, v2 thickness, v4 color); 151 151 152 152 static gui::State *state;
+13 -13
src/input.cpp
··· 53 53 void 54 54 input::update_mouse_button(int button, int action, int mods) 55 55 { 56 - bool32 new_state = (action == GLFW_PRESS); 56 + bool new_state = (action == GLFW_PRESS); 57 57 if (new_state != input::state->mouse_button_states[button]) { 58 58 input::state->mouse_button_states[button] = new_state; 59 59 input::state->n_mouse_button_state_changes_this_frame[button]++; ··· 61 61 } 62 62 63 63 64 - bool32 64 + bool 65 65 input::is_mouse_button_down(int button) 66 66 { 67 67 return input::state->mouse_button_states[button]; 68 68 } 69 69 70 70 71 - bool32 71 + bool 72 72 input::is_mouse_button_up(int button) 73 73 { 74 74 return !is_mouse_button_down(button); 75 75 } 76 76 77 77 78 - bool32 78 + bool 79 79 input::is_mouse_button_now_down(int button) 80 80 { 81 81 return is_mouse_button_down(button) && ··· 83 83 } 84 84 85 85 86 - bool32 86 + bool 87 87 input::is_mouse_button_now_up(int button) 88 88 { 89 89 return is_mouse_button_up(button) && ··· 101 101 102 102 input::state->mouse_offset = new_mouse_pos - input::state->mouse_pos; 103 103 input::state->mouse_3d_offset = 104 - input::state->mouse_offset * (real32)input::state->mouse_3d_sensitivity; 104 + input::state->mouse_offset * (f32)input::state->mouse_3d_sensitivity; 105 105 input::state->mouse_pos = new_mouse_pos; 106 106 } 107 107 ··· 141 141 142 142 143 143 void 144 - input::update_text_input(uint32 codepoint) 144 + input::update_text_input(u32 codepoint) 145 145 { 146 146 if (!input::state->is_text_input_enabled) { 147 147 return; ··· 162 162 void 163 163 input::update_keys(int key, int scancode, int action, int mods) 164 164 { 165 - bool32 new_state = (action == GLFW_PRESS || action == GLFW_REPEAT); 165 + bool new_state = (action == GLFW_PRESS || action == GLFW_REPEAT); 166 166 if (new_state != input::state->key_states[key]) { 167 167 input::state->key_states[key] = new_state; 168 168 input::state->n_key_state_changes_this_frame[key]++; ··· 170 170 } 171 171 172 172 173 - bool32 173 + bool 174 174 input::is_key_down(int key) 175 175 { 176 176 return input::state->key_states[key]; 177 177 } 178 178 179 179 180 - bool32 180 + bool 181 181 input::is_key_up(int key) 182 182 { 183 183 return !is_key_down(key); 184 184 } 185 185 186 186 187 - bool32 187 + bool 188 188 input::is_key_now_down(int key) 189 189 { 190 190 return is_key_down(key) && input::state->n_key_state_changes_this_frame[key] > 0; 191 191 } 192 192 193 193 194 - bool32 194 + bool 195 195 input::is_key_now_up(int key) 196 196 { 197 197 return is_key_up(key) && input::state->n_key_state_changes_this_frame[key] > 0; 198 198 } 199 199 200 200 201 - bool32 201 + bool 202 202 input::is_mouse_in_bb(v2 topleft, v2 bottomright) 203 203 { 204 204 return input::state->mouse_pos.x > topleft.x &&
+20 -20
src/input.hpp
··· 7 7 8 8 class input { 9 9 public: 10 - static constexpr uint32 MAX_TEXT_INPUT_LENGTH = 512; 11 - static constexpr uint32 MAX_TEXT_INPUT_COMMAND_LENGTH = 50; 12 - static constexpr uint32 MAX_TEXT_INPUT_ARGUMENTS_LENGTH = 10 + static constexpr u32 MAX_TEXT_INPUT_LENGTH = 512; 11 + static constexpr u32 MAX_TEXT_INPUT_COMMAND_LENGTH = 50; 12 + static constexpr u32 MAX_TEXT_INPUT_ARGUMENTS_LENGTH = 13 13 MAX_TEXT_INPUT_LENGTH - MAX_TEXT_INPUT_COMMAND_LENGTH; 14 14 15 15 enum class CursorType { ··· 28 28 v2 mouse_pos; 29 29 v2 mouse_offset; 30 30 v2 mouse_3d_offset; 31 - real64 mouse_3d_sensitivity; 32 - bool32 mouse_button_states[GLFW_MOUSE_BUTTON_LAST]; 33 - uint32 n_mouse_button_state_changes_this_frame[GLFW_MOUSE_BUTTON_LAST]; 34 - bool32 key_states[GLFW_KEY_LAST]; 35 - uint32 n_key_state_changes_this_frame[GLFW_KEY_LAST]; 31 + f64 mouse_3d_sensitivity; 32 + bool mouse_button_states[GLFW_MOUSE_BUTTON_LAST]; 33 + u32 n_mouse_button_state_changes_this_frame[GLFW_MOUSE_BUTTON_LAST]; 34 + bool key_states[GLFW_KEY_LAST]; 35 + u32 n_key_state_changes_this_frame[GLFW_KEY_LAST]; 36 36 GLFWcursor *current_cursor; 37 37 GLFWcursor *arrow_cursor; 38 38 GLFWcursor *ibeam_cursor; ··· 40 40 GLFWcursor *hand_cursor; 41 41 GLFWcursor *hresize_cursor; 42 42 GLFWcursor *vresize_cursor; 43 - bool32 have_ever_gotten_mouse_pos; 44 - bool32 is_text_input_enabled; 43 + bool have_ever_gotten_mouse_pos; 44 + bool is_text_input_enabled; 45 45 char text_input[MAX_TEXT_INPUT_LENGTH]; 46 46 }; 47 47 ··· 52 52 static v2 get_mouse_offset(); 53 53 static v2 get_mouse_3d_offset(); 54 54 static void update_mouse_button(int button, int action, int mods); 55 - static bool32 is_mouse_button_down(int button); 56 - static bool32 is_mouse_button_up(int button); 57 - static bool32 is_mouse_button_now_down(int button); 58 - static bool32 is_mouse_button_now_up(int button); 55 + static bool is_mouse_button_down(int button); 56 + static bool is_mouse_button_up(int button); 57 + static bool is_mouse_button_now_down(int button); 58 + static bool is_mouse_button_now_up(int button); 59 59 static void update_mouse(v2 new_mouse_pos); 60 60 static void clear_text_input(); 61 61 static void enable_text_input(); 62 62 static void disable_text_input(); 63 63 static void do_text_input_backspace(); 64 - static void update_text_input(uint32 codepoint); 64 + static void update_text_input(u32 codepoint); 65 65 static void update_keys(int key, int scancode, int action, int mods); 66 - static bool32 is_key_down(int key); 67 - static bool32 is_key_up(int key); 68 - static bool32 is_key_now_down(int key); 69 - static bool32 is_key_now_up(int key); 70 - static bool32 is_mouse_in_bb(v2 topleft, v2 bottomright); 66 + static bool is_key_down(int key); 67 + static bool is_key_up(int key); 68 + static bool is_key_now_down(int key); 69 + static bool is_key_now_up(int key); 70 + static bool is_mouse_in_bb(v2 topleft, v2 bottomright); 71 71 static void set_cursor(GLFWcursor *new_cursor); 72 72 static void set_cursor(CursorType type); 73 73 static void reset_n_mouse_button_state_changes_this_frame();
+1 -1
src/intrinsics.hpp
··· 16 16 // Loops 17 17 #define range_named(idx, start, end) \ 18 18 for ( \ 19 - uint32 idx = (start); \ 19 + u32 idx = (start); \ 20 20 idx < (end); \ 21 21 idx++ \ 22 22 )
+3 -3
src/lights.cpp
··· 48 48 } 49 49 50 50 51 - uint32 51 + u32 52 52 lights::light_type_to_int(LightType light_type) 53 53 { 54 54 if (light_type == LightType::point) { ··· 60 60 } 61 61 62 62 63 - bool32 63 + bool 64 64 lights::is_light_component_valid(lights::Component *light_component) 65 65 { 66 66 return light_component->type != LightType::none; ··· 89 89 } 90 90 91 91 if (light_component->type == LightType::point) { 92 - light_component->color.b = ((real32)sin(engine::get_t()) + 1.0f) / 2.0f * 50.0f; 92 + light_component->color.b = ((f32)sin(engine::get_t()) + 1.0f) / 2.0f * 50.0f; 93 93 } 94 94 95 95 // For the sun! :)
+3 -3
src/lights.hpp
··· 29 29 }; 30 30 31 31 struct State { 32 - real32 dir_light_angle; 32 + f32 dir_light_angle; 33 33 }; 34 34 35 35 static void adjust_dir_light_angle(f32 amount); 36 36 static const char* light_type_to_string(LightType light_type); 37 37 static LightType light_type_from_string(const char *str); 38 - static uint32 light_type_to_int(LightType light_type); 39 - static bool32 is_light_component_valid(Component *light_component); 38 + static u32 light_type_to_int(LightType light_type); 39 + static bool is_light_component_valid(Component *light_component); 40 40 static void update_light_components( 41 41 ComponentSet *light_component_set, 42 42 spatial::ComponentSet *spatial_component_set,
+1 -1
src/main.cpp
··· 11 11 main() 12 12 { 13 13 // Seed RNG 14 - srand((uint32)time(NULL)); 14 + srand((u32)time(NULL)); 15 15 16 16 // 17 17 // ___
+31 -31
src/mats.cpp
··· 45 45 mats::destroy_non_internal_materials() 46 46 { 47 47 for ( 48 - uint32 idx = mats::state->first_non_internal_material_idx; 48 + u32 idx = mats::state->first_non_internal_material_idx; 49 49 idx < mats::state->materials.length; 50 50 idx++ 51 51 ) { ··· 192 192 Texture *texture, 193 193 GLenum target, 194 194 TextureType type, 195 - uint32 texture_name, 196 - int32 width, 197 - int32 height, 198 - int32 n_components 195 + u32 texture_name, 196 + i32 width, 197 + i32 height, 198 + i32 n_components 199 199 ) { 200 200 texture->target = target; 201 201 texture->type = type; ··· 291 291 shaders::destroy_shader_asset(&material->depth_shader_asset); 292 292 } 293 293 294 - for (uint32 idx = 0; idx < material->n_textures; idx++) { 294 + for (u32 idx = 0; idx < material->n_textures; idx++) { 295 295 Texture *texture = &material->textures[idx]; 296 296 if (!texture->is_builtin) { 297 297 destroy_texture(texture); ··· 335 335 glUseProgram(shader_asset->program); 336 336 337 337 for ( 338 - uint32 uniform_idx = 0; 338 + u32 uniform_idx = 0; 339 339 uniform_idx < shader_asset->n_intrinsic_uniforms; 340 340 uniform_idx++ 341 341 ) { ··· 355 355 356 356 shaders::reset_texture_units(shader_asset); 357 357 358 - for (uint32 idx = 0; idx < material->n_textures; idx++) { 358 + for (u32 idx = 0; idx < material->n_textures; idx++) { 359 359 Texture *texture = &material->textures[idx]; 360 360 const char *uniform_name = material->texture_uniform_names[idx]; 361 361 #if USE_SHADER_DEBUG ··· 392 392 } 393 393 394 394 395 - bool32 395 + bool 396 396 mats::prepare_material_and_check_if_done(Material *material) 397 397 { 398 398 if (material->state == MaterialState::empty) { ··· 403 403 if (material->state == MaterialState::initialized) { 404 404 // NOTE: We only have to copy stuff if we have one or more textures that 405 405 // don't have names yet. 406 - bool32 should_try_to_copy_textures = false; 407 - for (uint32 idx = 0; idx < material->n_textures; idx++) { 406 + bool should_try_to_copy_textures = false; 407 + for (u32 idx = 0; idx < material->n_textures; idx++) { 408 408 Texture *texture = &material->textures[idx]; 409 409 if (!texture->texture_name) { 410 410 should_try_to_copy_textures = true; ··· 464 464 } 465 465 466 466 467 - bool32 467 + bool 468 468 mats::is_texture_type_screensize_dependent(TextureType type) 469 469 { 470 470 return ( ··· 481 481 } 482 482 483 483 484 - uint16 484 + u16 485 485 mats::get_new_persistent_pbo_idx() 486 486 { 487 487 auto *ppbo = &mats::state->persistent_pbo; 488 - uint16 current_idx = ppbo->next_idx; 488 + u16 current_idx = ppbo->next_idx; 489 489 ppbo->next_idx++; 490 490 if (ppbo->next_idx >= ppbo->texture_count) { 491 491 ppbo->next_idx = 0; ··· 495 495 496 496 497 497 void * 498 - mats::get_memory_for_persistent_pbo_idx(uint16 idx) 498 + mats::get_memory_for_persistent_pbo_idx(u16 idx) 499 499 { 500 500 auto *ppbo = &mats::state->persistent_pbo; 501 - return (char*)ppbo->memory + ((uint64)idx * ppbo->texture_size); 501 + return (char*)ppbo->memory + ((u64)idx * ppbo->texture_size); 502 502 } 503 503 504 504 505 505 void 506 506 mats::copy_textures_to_pbo(Material *material) 507 507 { 508 - for (uint32 idx = 0; idx < material->n_textures; idx++) { 508 + for (u32 idx = 0; idx < material->n_textures; idx++) { 509 509 Texture *texture = &material->textures[idx]; 510 510 if (texture->texture_name) { 511 511 continue; ··· 521 521 } 522 522 523 523 524 - uint32 525 - mats::get_new_texture_name(uint32 target_size) 524 + u32 525 + mats::get_new_texture_name(u32 target_size) 526 526 { 527 527 auto *pool = &mats::state->texture_name_pool; 528 - for (uint32 idx_size = 0; idx_size < pool->n_sizes; idx_size++) { 528 + for (u32 idx_size = 0; idx_size < pool->n_sizes; idx_size++) { 529 529 if (pool->sizes[idx_size] == target_size) { 530 530 assert(pool->idx_next[idx_size] < pool->n_textures); 531 - uint32 idx_name = (idx_size * pool->n_textures) + pool->idx_next[idx_size]; 532 - uint32 texture_name = pool->texture_names[idx_name]; 531 + u32 idx_name = (idx_size * pool->n_textures) + pool->idx_next[idx_size]; 532 + u32 texture_name = pool->texture_names[idx_name]; 533 533 pool->idx_next[idx_size]++; 534 534 return texture_name; 535 535 } ··· 540 540 541 541 542 542 void * 543 - mats::get_offset_for_persistent_pbo_idx(uint16 idx) 543 + mats::get_offset_for_persistent_pbo_idx(u16 idx) 544 544 { 545 - return (void*)((uint64)idx * mats::state->persistent_pbo.texture_size); 545 + return (void*)((u64)idx * mats::state->persistent_pbo.texture_size); 546 546 } 547 547 548 548 ··· 554 554 } 555 555 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, mats::state->persistent_pbo.pbo); 556 556 557 - for (uint32 idx = 0; idx < material->n_textures; idx++) { 557 + for (u32 idx = 0; idx < material->n_textures; idx++) { 558 558 Texture *texture = &material->textures[idx]; 559 559 if (texture->texture_name != 0) { 560 560 continue; ··· 598 598 599 599 mats::PersistentPbo * 600 600 mats::init_persistent_pbo( 601 - uint16 texture_count, int32 width, int32 height, int32 n_components 601 + u16 texture_count, i32 width, i32 height, i32 n_components 602 602 ) { 603 603 auto *ppbo = &mats::state->persistent_pbo; 604 604 ppbo->texture_count = texture_count; ··· 637 637 mats::TextureNamePool * 638 638 mats::init_texture_name_pool( 639 639 memory::Pool *memory_pool, 640 - uint32 n_textures, 641 - uint32 mipmap_max_level 640 + u32 n_textures, 641 + u32 mipmap_max_level 642 642 ) { 643 643 auto *pool = &mats::state->texture_name_pool; 644 644 pool->n_textures = n_textures; ··· 648 648 pool->sizes[pool->n_sizes++] = 512; 649 649 pool->sizes[pool->n_sizes++] = 2048; 650 650 651 - pool->texture_names = (uint32*)memory::push(memory_pool, 652 - sizeof(uint32) * pool->n_textures * pool->n_sizes, "texture_names"); 651 + pool->texture_names = (u32*)memory::push(memory_pool, 652 + sizeof(u32) * pool->n_textures * pool->n_sizes, "texture_names"); 653 653 654 654 glGenTextures(pool->n_textures * pool->n_sizes, pool->texture_names); 655 655 656 656 range_named (idx_size, 0, pool->n_sizes) { 657 657 range_named (idx_texture, 0, pool->n_textures) { 658 - uint32 idx_name = (idx_size * pool->n_textures) + idx_texture; 658 + u32 idx_name = (idx_size * pool->n_textures) + idx_texture; 659 659 glBindTexture(GL_TEXTURE_2D, pool->texture_names[idx_name]); 660 660 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 661 661 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+44 -44
src/mats.hpp
··· 14 14 class mats { 15 15 public: 16 16 struct TextureNamePool { 17 - uint32 mipmap_max_level; 18 - uint32 n_textures; 19 - uint32 n_sizes; 20 - uint32 sizes[MAX_N_TEXTURE_POOL_SIZES]; 21 - uint32 idx_next[MAX_N_TEXTURE_POOL_SIZES]; 22 - uint32 *texture_names; 17 + u32 mipmap_max_level; 18 + u32 n_textures; 19 + u32 n_sizes; 20 + u32 sizes[MAX_N_TEXTURE_POOL_SIZES]; 21 + u32 idx_next[MAX_N_TEXTURE_POOL_SIZES]; 22 + u32 *texture_names; 23 23 }; 24 24 25 25 struct PersistentPbo { 26 - uint32 pbo; 26 + u32 pbo; 27 27 void *memory; 28 - int32 width; 29 - int32 height; 30 - int32 n_components; 31 - uint16 texture_count; 32 - uint32 texture_size; 33 - uint32 total_size; 34 - uint16 next_idx; 28 + i32 width; 29 + i32 height; 30 + i32 n_components; 31 + u16 texture_count; 32 + u32 texture_size; 33 + u32 total_size; 34 + u16 next_idx; 35 35 }; 36 36 37 37 struct TextureAtlas { 38 38 iv2 size; 39 39 iv2 next_position; 40 40 iv2 max_allocated_position_per_axis; 41 - uint32 texture_name; 41 + u32 texture_name; 42 42 }; 43 43 44 44 enum class TextureType { ··· 68 68 GLenum target; 69 69 TextureType type; 70 70 char path[MAX_PATH]; 71 - uint32 texture_name; 72 - int32 width; 73 - int32 height; 74 - int32 n_components; 75 - uint16 pbo_idx_for_copy; 76 - bool32 is_screensize_dependent; 71 + u32 texture_name; 72 + i32 width; 73 + i32 height; 74 + i32 n_components; 75 + u16 pbo_idx_for_copy; 76 + bool is_screensize_dependent; 77 77 // NOTE: We assume a builtin texture can belong to multiple materials, 78 78 // but a non-builtin texture can belong to only one material. 79 79 // If we delete a material, we delete all its non-builtin textures. 80 - bool32 is_builtin; 80 + bool is_builtin; 81 81 }; 82 82 83 83 enum class MaterialState { ··· 91 91 struct Material { 92 92 char name[MAX_COMMON_NAME_LENGTH]; 93 93 MaterialState state; 94 - bool32 have_textures_been_generated; 95 - bool32 is_screensize_dependent; 94 + bool have_textures_been_generated; 95 + bool is_screensize_dependent; 96 96 shaders::Asset shader_asset; 97 97 shaders::Asset depth_shader_asset; 98 - uint32 n_textures; 98 + u32 n_textures; 99 99 Texture textures[MAX_N_TEXTURES_PER_MATERIAL]; 100 100 char texture_uniform_names[MAX_N_UNIFORMS][MAX_UNIFORM_LENGTH]; 101 - uint32 idx_texture_uniform_names; 101 + u32 idx_texture_uniform_names; 102 102 103 103 v4 albedo_static; 104 - real32 metallic_static; 105 - real32 roughness_static; 106 - real32 ao_static; 107 - bool32 should_use_normal_map; 104 + f32 metallic_static; 105 + f32 roughness_static; 106 + f32 ao_static; 107 + bool should_use_normal_map; 108 108 }; 109 109 110 110 struct State { 111 111 PersistentPbo persistent_pbo; 112 112 TextureNamePool texture_name_pool; 113 113 Array<Material> materials; 114 - uint32 first_non_internal_material_idx; 114 + u32 first_non_internal_material_idx; 115 115 }; 116 116 117 117 static Array<Material> * get_materials(); ··· 133 133 Texture *texture, 134 134 GLenum target, 135 135 TextureType type, 136 - uint32 texture_name, 137 - int32 width, 138 - int32 height, 139 - int32 n_components 136 + u32 texture_name, 137 + i32 width, 138 + i32 height, 139 + i32 n_components 140 140 ); 141 141 static void destroy_texture(Texture *texture); 142 142 static TextureAtlas * init_texture_atlas( ··· 162 162 mats::State *materials_state, 163 163 memory::Pool *memory_pool 164 164 ); 165 - static bool32 prepare_material_and_check_if_done(Material *material); 165 + static bool prepare_material_and_check_if_done(Material *material); 166 166 static void reload_shaders(); 167 167 168 168 private: 169 - static bool32 is_texture_type_screensize_dependent(TextureType type); 170 - static uint16 get_new_persistent_pbo_idx(); 171 - static void * get_memory_for_persistent_pbo_idx(uint16 idx); 169 + static bool is_texture_type_screensize_dependent(TextureType type); 170 + static u16 get_new_persistent_pbo_idx(); 171 + static void * get_memory_for_persistent_pbo_idx(u16 idx); 172 172 static void copy_textures_to_pbo(Material *material); 173 - static uint32 get_new_texture_name(uint32 target_size); 174 - static void * get_offset_for_persistent_pbo_idx(uint16 idx); 173 + static u32 get_new_texture_name(u32 target_size); 174 + static void * get_offset_for_persistent_pbo_idx(u16 idx); 175 175 static void generate_textures_from_pbo(Material *material); 176 176 static char const * material_state_to_string(MaterialState material_state); 177 177 static PersistentPbo * init_persistent_pbo( 178 - uint16 texture_count, int32 width, int32 height, int32 n_components 178 + u16 texture_count, i32 width, i32 height, i32 n_components 179 179 ); 180 180 static TextureNamePool * init_texture_name_pool( 181 181 memory::Pool *memory_pool, 182 - uint32 n_textures, 183 - uint32 mipmap_max_level 182 + u32 n_textures, 183 + u32 mipmap_max_level 184 184 ); 185 185 186 186 static mats::State *state;
+8 -8
src/memory.cpp
··· 22 22 if (pool->memory == nullptr) { 23 23 #if USE_MEMORY_DEBUG_LOGS 24 24 logs::info("Allocating memory pool: %.2fMB (%dB)", 25 - util::b_to_mb((real64)pool->size), pool->size); 25 + util::b_to_mb((f64)pool->size), pool->size); 26 26 #endif 27 27 28 - pool->memory = (uint8*)calloc(1, pool->size); 28 + pool->memory = (u8*)calloc(1, pool->size); 29 29 if (!pool->memory) { 30 30 logs::fatal("Could not allocate memory. Buy more RAM!"); 31 31 assert(false); // A little hint for the compiler ··· 47 47 48 48 #if USE_MEMORY_DEBUG_LOGS 49 49 logs::info("Pusing to memory pool: %.2fMB (%dB) for %s, now at %.2fMB (%dB)", 50 - util::b_to_mb((real64)item_size), 50 + util::b_to_mb((f64)item_size), 51 51 item_size, item_debug_name, 52 - util::b_to_mb((real64)pool->used), 52 + util::b_to_mb((f64)pool->used), 53 53 pool->used); 54 54 #endif 55 55 ··· 61 61 memory::print_memory_pool(Pool *pool) 62 62 { 63 63 logs::info("memory::Pool:"); 64 - logs::info(" Used: %.2fMB (%dB)", util::b_to_mb((uint32)pool->used), pool->used); 65 - logs::info(" Size: %.2fMB (%dB)", util::b_to_mb((uint32)pool->size), pool->size); 64 + logs::info(" Used: %.2fMB (%dB)", util::b_to_mb((u32)pool->used), pool->used); 65 + logs::info(" Size: %.2fMB (%dB)", util::b_to_mb((u32)pool->size), pool->size); 66 66 logs::info(" Items:"); 67 67 if (pool->n_items == 0) { 68 68 logs::info(" (none)"); 69 69 } 70 70 #if USE_MEMORYPOOL_ITEM_DEBUG 71 - for (uint32 idx = 0; idx < pool->n_items; idx++) { 71 + for (u32 idx = 0; idx < pool->n_items; idx++) { 72 72 logs::info(" %02d. %s, %.2fMB (%dB)", 73 73 idx, 74 74 pool->item_debug_names[idx], 75 - util::b_to_mb((real64)pool->item_debug_sizes[idx]), 75 + util::b_to_mb((f64)pool->item_debug_sizes[idx]), 76 76 pool->item_debug_sizes[idx]); 77 77 } 78 78 #endif
+3 -3
src/memory.hpp
··· 10 10 class memory { 11 11 public: 12 12 #if USE_MEMORYPOOL_ITEM_DEBUG 13 - constexpr uint32 MAX_N_MEMORYPOOL_ITEMS = 1024; 13 + constexpr u32 MAX_N_MEMORYPOOL_ITEMS = 1024; 14 14 #endif 15 15 16 16 struct Pool { 17 - uint8 *memory; 17 + u8 *memory; 18 18 size_t size; 19 19 size_t used; 20 - uint32 n_items; 20 + u32 n_items; 21 21 #if USE_MEMORYPOOL_ITEM_DEBUG 22 22 const char *item_debug_names[MAX_N_MEMORYPOOL_ITEMS]; 23 23 size_t item_debug_sizes[MAX_N_MEMORYPOOL_ITEMS];
+30 -30
src/models.cpp
··· 12 12 #include "intrinsics.hpp" 13 13 14 14 15 - bool32 15 + bool 16 16 models::prepare_model_loader_and_check_if_done(ModelLoader *model_loader) { 17 17 if (model_loader->state == ModelLoaderState::initialized) { 18 18 if (pstr_starts_with(model_loader->model_path, "builtin:")) { ··· 31 31 } 32 32 33 33 if (model_loader->state == ModelLoaderState::mesh_data_loaded) { 34 - for (uint32 idx = 0; idx < model_loader->n_meshes; idx++) { 34 + for (u32 idx = 0; idx < model_loader->n_meshes; idx++) { 35 35 geom::Mesh *mesh = &model_loader->meshes[idx]; 36 36 geom::setup_mesh_vertex_buffers(mesh, mesh->vertices, mesh->n_vertices, mesh->indices, mesh->n_indices); 37 37 memory::destroy_memory_pool(&mesh->temp_memory_pool); ··· 44 44 range_named (idx_material, 0, model_loader->n_material_names) { 45 45 range_named (idx_mesh, 0, model_loader->n_meshes) { 46 46 geom::Mesh *mesh = &model_loader->meshes[idx_mesh]; 47 - uint8 mesh_number = pack::get(&mesh->indices_pack, 0); 47 + u8 mesh_number = pack::get(&mesh->indices_pack, 0); 48 48 // For our model's mesh number `mesh_number`, we want to choose 49 49 // material `idx_mesh` such that `mesh_number == idx_mesh`, i.e. 50 50 // we choose the 4th material for mesh number 4. ··· 70 70 } 71 71 72 72 73 - bool32 73 + bool 74 74 models::prepare_entity_loader_and_check_if_done( 75 75 EntityLoader *entity_loader, 76 76 ModelLoader *model_loader ··· 112 112 .target_render_pass = entity_loader->render_pass, 113 113 }; 114 114 } else if (model_loader->n_meshes > 1) { 115 - for (uint32 idx = 0; idx < model_loader->n_meshes; idx++) { 115 + for (u32 idx = 0; idx < model_loader->n_meshes; idx++) { 116 116 geom::Mesh *mesh = &model_loader->meshes[idx]; 117 117 118 118 entities::Entity *child_entity = entities::add_entity_to_set(entity_loader->name); ··· 150 150 } 151 151 152 152 153 - bool32 153 + bool 154 154 models::is_model_loader_valid(ModelLoader *model_loader) 155 155 { 156 156 return model_loader->state != ModelLoaderState::empty; 157 157 } 158 158 159 159 160 - bool32 160 + bool 161 161 models::is_entity_loader_valid(EntityLoader *entity_loader) 162 162 { 163 163 return entity_loader->state != EntityLoaderState::empty; ··· 215 215 } 216 216 217 217 218 - bool32 218 + bool 219 219 models::is_bone_only_node(aiNode *node) 220 220 { 221 221 if (node->mNumMeshes > 0) { 222 222 return false; 223 223 } 224 - bool32 have_we_found_it = true; 224 + bool have_we_found_it = true; 225 225 range (0, node->mNumChildren) { 226 226 if (!is_bone_only_node(node->mChildren[idx])) { 227 227 have_we_found_it = false; ··· 255 255 models::add_bone_tree_to_animation_component( 256 256 anim::Component *animation_component, 257 257 aiNode *node, 258 - uint32 idx_parent 258 + u32 idx_parent 259 259 ) { 260 - uint32 idx_new_bone = animation_component->n_bones; 260 + u32 idx_new_bone = animation_component->n_bones; 261 261 animation_component->bones[idx_new_bone] = { 262 262 .idx_parent = idx_parent, 263 263 // NOTE: offset is added later, since we don't have the aiBone at this stage. ··· 315 315 range_named(idx_bone, 0, animation_component->n_bones) { 316 316 anim::Bone *bone = &animation_component->bones[idx_bone]; 317 317 318 - uint32 found_channel_idx = 0; 319 - bool32 did_find_channel = false; 318 + u32 found_channel_idx = 0; 319 + bool did_find_channel = false; 320 320 321 321 range_named (idx_channel, 0, ai_animation->mNumChannels) { 322 322 aiNodeAnim *ai_channel = ai_animation->mChannels[idx_channel]; ··· 383 383 mesh->vertices = (geom::Vertex*)memory::push(&mesh->temp_memory_pool, 384 384 mesh->n_vertices * sizeof(geom::Vertex), "mesh_vertices"); 385 385 386 - for (uint32 idx = 0; idx < ai_mesh->mNumVertices; idx++) { 386 + for (u32 idx = 0; idx < ai_mesh->mNumVertices; idx++) { 387 387 geom::Vertex *vertex = &mesh->vertices[idx]; 388 388 *vertex = {}; 389 389 ··· 406 406 } 407 407 408 408 // Indices 409 - uint32 n_indices = 0; 410 - for (uint32 idx_face = 0; idx_face < ai_mesh->mNumFaces; idx_face++) { 409 + u32 n_indices = 0; 410 + for (u32 idx_face = 0; idx_face < ai_mesh->mNumFaces; idx_face++) { 411 411 aiFace face = ai_mesh->mFaces[idx_face]; 412 412 n_indices += face.mNumIndices; 413 413 } 414 414 415 415 mesh->n_indices = n_indices; 416 - mesh->indices = (uint32*)memory::push(&mesh->temp_memory_pool, 417 - mesh->n_indices * sizeof(uint32), "mesh_indices"); 418 - uint32 idx_index = 0; 416 + mesh->indices = (u32*)memory::push(&mesh->temp_memory_pool, 417 + mesh->n_indices * sizeof(u32), "mesh_indices"); 418 + u32 idx_index = 0; 419 419 420 - for (uint32 idx_face = 0; idx_face < ai_mesh->mNumFaces; idx_face++) { 420 + for (u32 idx_face = 0; idx_face < ai_mesh->mNumFaces; idx_face++) { 421 421 aiFace face = ai_mesh->mFaces[idx_face]; 422 422 for ( 423 - uint32 idx_face_index = 0; 423 + u32 idx_face_index = 0; 424 424 idx_face_index < face.mNumIndices; 425 425 idx_face_index++ 426 426 ) { ··· 433 433 anim::Component *animation_component = &model_loader->animation_component; 434 434 range_named (idx_bone, 0, ai_mesh->mNumBones) { 435 435 aiBone *ai_bone = ai_mesh->mBones[idx_bone]; 436 - uint32 idx_found_bone = 0; 437 - bool32 did_find_bone = false; 436 + u32 idx_found_bone = 0; 437 + bool did_find_bone = false; 438 438 439 439 range_named (idx_animcomp_bone, 0, animation_component->n_bones) { 440 440 if (pstr_eq( ··· 456 456 util::aimatrix4x4_to_glm(&ai_bone->mOffsetMatrix); 457 457 458 458 range_named (idx_weight, 0, ai_bone->mNumWeights) { 459 - uint32 vertex_idx = ai_bone->mWeights[idx_weight].mVertexId; 460 - real32 weight = ai_bone->mWeights[idx_weight].mWeight; 459 + u32 vertex_idx = ai_bone->mWeights[idx_weight].mVertexId; 460 + f32 weight = ai_bone->mWeights[idx_weight].mWeight; 461 461 assert(vertex_idx < mesh->n_vertices); 462 462 range_named (idx_vertex_weight, 0, MAX_N_BONES_PER_VERTEX) { 463 463 // Put it in the next free space, if there is any. ··· 492 492 pack::Pack new_indices_pack = indices_pack; 493 493 // NOTE: We can only store 4 bits per pack element. Our indices can be way 494 494 // bigger than that, but that's fine. We don't need that much precision. 495 - // Just smash the number down to a uint8. 496 - pack::push(&new_indices_pack, (uint8)idx); 495 + // Just smash the number down to a u8. 496 + pack::push(&new_indices_pack, (u8)idx); 497 497 load_node(model_loader, node->mChildren[idx], scene, transform, new_indices_pack); 498 498 } 499 499 } ··· 546 546 memory::Pool temp_memory_pool = {}; 547 547 548 548 geom::Vertex *vertex_data = nullptr; 549 - uint32 n_vertices = 0; 550 - uint32 *index_data = nullptr; 551 - uint32 n_indices = 0; 549 + u32 n_vertices = 0; 550 + u32 *index_data = nullptr; 551 + u32 n_indices = 0; 552 552 GLenum mode = 0; 553 553 554 554 if (pstr_eq(model_loader->model_path, "builtin:axes")) {
+9 -9
src/models.hpp
··· 20 20 class models { 21 21 public: 22 22 // NOTE: Should be at least peony_parser::MAX_N_ARRAY_VALUES 23 - static constexpr uint32 const MAX_N_COMMON_ARRAY_VALUES = 8; 23 + static constexpr u32 const MAX_N_COMMON_ARRAY_VALUES = 8; 24 24 25 25 enum class ModelLoaderState { 26 26 empty, ··· 35 35 // These from from the file 36 36 char model_path[MAX_PATH]; 37 37 char material_names[MAX_COMMON_NAME_LENGTH][MAX_N_COMMON_ARRAY_VALUES]; 38 - uint32 n_material_names; 38 + u32 n_material_names; 39 39 40 40 // These are created later 41 41 geom::Mesh meshes[MAX_N_MESHES]; 42 - uint32 n_meshes; 42 + u32 n_meshes; 43 43 anim::Component animation_component; 44 44 ModelLoaderState state; 45 45 }; ··· 69 69 70 70 #include "models_data.hpp" 71 71 72 - static bool32 prepare_model_loader_and_check_if_done(ModelLoader *model_loader); 73 - static bool32 prepare_entity_loader_and_check_if_done( 72 + static bool prepare_model_loader_and_check_if_done(ModelLoader *model_loader); 73 + static bool prepare_entity_loader_and_check_if_done( 74 74 EntityLoader *entity_loader, 75 75 ModelLoader *model_loader 76 76 ); 77 - static bool32 is_model_loader_valid(ModelLoader *model_loader); 78 - static bool32 is_entity_loader_valid(EntityLoader *entity_loader); 77 + static bool is_model_loader_valid(ModelLoader *model_loader); 78 + static bool is_entity_loader_valid(EntityLoader *entity_loader); 79 79 static void add_material_to_model_loader( 80 80 ModelLoader *model_loader, 81 81 char const *material_name ··· 93 93 ); 94 94 95 95 private: 96 - static bool32 is_bone_only_node(aiNode *node); 96 + static bool is_bone_only_node(aiNode *node); 97 97 static aiNode * find_root_bone(const aiScene *scene); 98 98 static void add_bone_tree_to_animation_component( 99 99 anim::Component *animation_component, 100 100 aiNode *node, 101 - uint32 idx_parent 101 + u32 idx_parent 102 102 ); 103 103 static void load_bones( 104 104 anim::Component *animation_component,
+7 -7
src/pack.cpp
··· 11 11 12 12 13 13 void 14 - pack::set(Pack *pack, uint8 value, uint8 idx) 14 + pack::set(Pack *pack, u8 value, u8 idx) 15 15 { 16 16 assert(idx < MAX_LENGTH); 17 17 Pack mask = 0b1111ULL << (idx * ELEMENT_SIZE); ··· 19 19 } 20 20 21 21 22 - uint8 23 - pack::get(Pack *pack, uint8 idx) 22 + u8 23 + pack::get(Pack *pack, u8 idx) 24 24 { 25 25 Pack mask = 0b1111ULL << (idx * ELEMENT_SIZE); 26 - return (uint8)((*pack & mask) >> (idx * ELEMENT_SIZE)); 26 + return (u8)((*pack & mask) >> (idx * ELEMENT_SIZE)); 27 27 } 28 28 29 29 30 - uint8 30 + u8 31 31 pack::get_count(Pack *pack) 32 32 { 33 33 return get(pack, COUNTER_IDX); ··· 35 35 36 36 37 37 void 38 - pack::push(Pack *pack, uint8 value) 38 + pack::push(Pack *pack, u8 value) 39 39 { 40 - uint8 count = get_count(pack); 40 + u8 count = get_count(pack); 41 41 // Last element is reserved for count; 42 42 assert(count < COUNTER_IDX); 43 43 set(pack, value, count);
+8 -8
src/pack.hpp
··· 6 6 7 7 class pack { 8 8 public: 9 - static constexpr uint16 ELEMENT_SIZE = 4; 10 - static constexpr uint16 MAX_LENGTH = (64 / ELEMENT_SIZE); 11 - static constexpr uint16 COUNTER_IDX = (MAX_LENGTH - 1); 9 + static constexpr u16 ELEMENT_SIZE = 4; 10 + static constexpr u16 MAX_LENGTH = (64 / ELEMENT_SIZE); 11 + static constexpr u16 COUNTER_IDX = (MAX_LENGTH - 1); 12 12 13 - typedef uint64 Pack; 13 + typedef u64 Pack; 14 14 15 15 static void init(Pack *pack); 16 - static void set(Pack *pack, uint8 value, uint8 idx); 17 - static uint8 get(Pack *pack, uint8 idx); 18 - static uint8 get_count(Pack *pack); 19 - static void push(Pack *pack, uint8 value); 16 + static void set(Pack *pack, u8 value, u8 idx); 17 + static u8 get(Pack *pack, u8 idx); 18 + static u8 get_count(Pack *pack); 19 + static void push(Pack *pack, u8 value); 20 20 };
+22 -22
src/peony_parser.cpp
··· 6 6 #include "intrinsics.hpp" 7 7 8 8 9 - bool32 9 + bool 10 10 peony_parser::parse_file(PeonyFile *pf, char const *path) 11 11 { 12 - int32 idx_entry = -1; 12 + i32 idx_entry = -1; 13 13 Entry *entry = nullptr; 14 14 15 15 FILE *f = fopen(path, "r"); ··· 71 71 } 72 72 73 73 74 - bool32 74 + bool 75 75 peony_parser::is_char_whitespace(const char target) 76 76 { 77 77 return target == TOKEN_NEWLINE || target == TOKEN_SPACE; 78 78 } 79 79 80 80 81 - bool32 81 + bool 82 82 peony_parser::is_token_whitespace(const char *token) 83 83 { 84 84 return is_char_whitespace(token[0]); 85 85 } 86 86 87 87 88 - bool32 88 + bool 89 89 peony_parser::is_char_allowed_in_name(const char target) 90 90 { 91 91 return isalpha(target) || isdigit(target) || target == '_' || target == '-' || ··· 93 93 } 94 94 95 95 96 - bool32 96 + bool 97 97 peony_parser::is_token_name(const char *token) 98 98 { 99 99 range (0, pstr_len(token)) { ··· 105 105 } 106 106 107 107 108 - bool32 108 + bool 109 109 peony_parser::is_char_token_boundary(char target) 110 110 { 111 111 return is_char_whitespace(target) || ··· 120 120 } 121 121 122 122 123 - bool32 123 + bool 124 124 peony_parser::get_token(char *token, FILE *f) 125 125 { 126 - uint32 idx_token = 0; 127 - bool32 could_get_token = true; 126 + u32 idx_token = 0; 127 + bool could_get_token = true; 128 128 129 129 while (true) { 130 130 char new_char = (char)fgetc(f); ··· 160 160 } 161 161 162 162 163 - bool32 163 + bool 164 164 peony_parser::get_non_trivial_token(char *token, FILE *f) 165 165 { 166 - bool32 could_get_token; 166 + bool could_get_token; 167 167 do { 168 168 could_get_token = get_token(token, f); 169 169 if (token[0] == TOKEN_COMMENT_START) { ··· 184 184 get_non_trivial_token(token, f); 185 185 assert(token[0] == TOKEN_TUPLE_START); 186 186 get_non_trivial_token(token, f); 187 - (*parsed_vector).x = (real32)strtod(token, nullptr); 187 + (*parsed_vector).x = (f32)strtod(token, nullptr); 188 188 get_non_trivial_token(token, f); 189 - (*parsed_vector).y = (real32)strtod(token, nullptr); 189 + (*parsed_vector).y = (f32)strtod(token, nullptr); 190 190 get_non_trivial_token(token, f); 191 191 assert(token[0] == TOKEN_TUPLE_END); 192 192 } ··· 198 198 get_non_trivial_token(token, f); 199 199 assert(token[0] == TOKEN_TUPLE_START); 200 200 get_non_trivial_token(token, f); 201 - (*parsed_vector).x = (real32)strtod(token, nullptr); 201 + (*parsed_vector).x = (f32)strtod(token, nullptr); 202 202 get_non_trivial_token(token, f); 203 - (*parsed_vector).y = (real32)strtod(token, nullptr); 203 + (*parsed_vector).y = (f32)strtod(token, nullptr); 204 204 get_non_trivial_token(token, f); 205 - (*parsed_vector).z = (real32)strtod(token, nullptr); 205 + (*parsed_vector).z = (f32)strtod(token, nullptr); 206 206 get_non_trivial_token(token, f); 207 207 assert(token[0] == TOKEN_TUPLE_END); 208 208 } ··· 214 214 get_non_trivial_token(token, f); 215 215 assert(token[0] == TOKEN_TUPLE_START); 216 216 get_non_trivial_token(token, f); 217 - (*parsed_vector).x = (real32)strtod(token, nullptr); 217 + (*parsed_vector).x = (f32)strtod(token, nullptr); 218 218 get_non_trivial_token(token, f); 219 - (*parsed_vector).y = (real32)strtod(token, nullptr); 219 + (*parsed_vector).y = (f32)strtod(token, nullptr); 220 220 get_non_trivial_token(token, f); 221 - (*parsed_vector).z = (real32)strtod(token, nullptr); 221 + (*parsed_vector).z = (f32)strtod(token, nullptr); 222 222 get_non_trivial_token(token, f); 223 - (*parsed_vector).w = (real32)strtod(token, nullptr); 223 + (*parsed_vector).w = (f32)strtod(token, nullptr); 224 224 get_non_trivial_token(token, f); 225 225 assert(token[0] == TOKEN_TUPLE_END); 226 226 } ··· 249 249 // NOTE: `strtod()` returns 0.0 if parsing fails, so we need to check 250 250 // if our value actually was 0.0; 251 251 prop_value->type = PropValueType::number; 252 - prop_value->number_value = (real32)strtod(token, nullptr); 252 + prop_value->number_value = (f32)strtod(token, nullptr); 253 253 } else { 254 254 prop_value->type = PropValueType::string; 255 255 pstr_copy(prop_value->string_value, MAX_TOKEN_LENGTH, token);
+17 -17
src/peony_parser.hpp
··· 6 6 7 7 class peony_parser { 8 8 public: 9 - static constexpr uint32 MAX_N_FILE_ENTRIES = 128; 10 - static constexpr uint32 MAX_N_ENTRY_PROPS = 32; 11 - static constexpr uint32 MAX_N_ARRAY_VALUES = 8; 12 - static constexpr uint32 MAX_TOKEN_LENGTH = 128; 9 + static constexpr u32 MAX_N_FILE_ENTRIES = 128; 10 + static constexpr u32 MAX_N_ENTRY_PROPS = 32; 11 + static constexpr u32 MAX_N_ARRAY_VALUES = 8; 12 + static constexpr u32 MAX_TOKEN_LENGTH = 128; 13 13 14 14 static constexpr const char TOKEN_SPACE = ' '; 15 15 static constexpr const char TOKEN_NEWLINE = '\n'; ··· 32 32 PropValueType type; 33 33 union { 34 34 char string_value[MAX_TOKEN_LENGTH]; 35 - bool32 boolean_value; 36 - real32 number_value; 35 + bool boolean_value; 36 + f32 number_value; 37 37 v2 vec2_value; 38 38 v3 vec3_value; 39 39 v4 vec4_value; ··· 43 43 struct Prop { 44 44 char name[MAX_TOKEN_LENGTH]; 45 45 PropValue values[MAX_N_ARRAY_VALUES]; 46 - uint32 n_values; 46 + u32 n_values; 47 47 }; 48 48 49 49 struct Entry { 50 50 char name[MAX_TOKEN_LENGTH]; 51 51 Prop props[MAX_N_ENTRY_PROPS]; 52 - uint32 n_props; 52 + u32 n_props; 53 53 }; 54 54 55 55 struct PeonyFile { 56 56 Entry entries[MAX_N_FILE_ENTRIES]; 57 - uint32 n_entries; 57 + u32 n_entries; 58 58 }; 59 59 60 - static bool32 parse_file(PeonyFile *pf, char const *path); 60 + static bool parse_file(PeonyFile *pf, char const *path); 61 61 62 62 private: 63 63 static void print_value(PropValue *value); 64 - static bool32 is_char_whitespace(const char target); 65 - static bool32 is_token_whitespace(const char *token); 66 - static bool32 is_char_allowed_in_name(const char target); 67 - static bool32 is_token_name(const char *token); 68 - static bool32 is_char_token_boundary(char target); 69 - static bool32 get_token(char *token, FILE *f); 70 - static bool32 get_non_trivial_token(char *token, FILE *f); 64 + static bool is_char_whitespace(const char target); 65 + static bool is_token_whitespace(const char *token); 66 + static bool is_char_allowed_in_name(const char target); 67 + static bool is_token_name(const char *token); 68 + static bool is_char_token_boundary(char target); 69 + static bool get_token(char *token, FILE *f); 70 + static bool get_non_trivial_token(char *token, FILE *f); 71 71 static void parse_vec2(char *token, FILE *f, v2 *parsed_vector); 72 72 static void parse_vec3(char *token, FILE *f, v3 *parsed_vector); 73 73 static void parse_vec4(char *token, FILE *f, v4 *parsed_vector);
+5 -5
src/peony_parser_utils.cpp
··· 16 16 } 17 17 18 18 19 - bool32 * 19 + bool * 20 20 peony_parser_utils::get_boolean(peony_parser::Prop *prop) 21 21 { 22 22 if (!prop) { return nullptr; } ··· 24 24 } 25 25 26 26 27 - real32 * 27 + f32 * 28 28 peony_parser_utils::get_number(peony_parser::Prop *prop) 29 29 { 30 30 if (!prop) { return nullptr; } ··· 83 83 } 84 84 range_named (idx_value, 0, prop->n_values) { 85 85 peony_parser::PropValue *value = &prop->values[idx_value]; 86 - bool32 does_material_already_exist = false; 86 + bool does_material_already_exist = false; 87 87 each (unique_value, *unique_values) { 88 88 if (pstr_eq(value->string_value, *unique_value)) { 89 89 does_material_already_exist = true; ··· 228 228 if (render_passes_prop) { 229 229 range (0, render_passes_prop->n_values) { 230 230 render_pass = (drawable::Pass)( 231 - (uint32)render_pass | 232 - (uint32)drawable::render_pass_from_string( 231 + (u32)render_pass | 232 + (u32)drawable::render_pass_from_string( 233 233 render_passes_prop->values[idx].string_value)); 234 234 } 235 235 } else {
+2 -2
src/peony_parser_utils.hpp
··· 15 15 static constexpr size_t BUILTIN_TEXTURE_PREFIX_LENGTH = 17; 16 16 17 17 static char * get_string(peony_parser::Prop *prop); 18 - static bool32 * get_boolean(peony_parser::Prop *prop); 19 - static real32 * get_number(peony_parser::Prop *prop); 18 + static bool * get_boolean(peony_parser::Prop *prop); 19 + static f32 * get_number(peony_parser::Prop *prop); 20 20 static v2 * get_vec2(peony_parser::Prop *prop); 21 21 static v3 * get_vec3(peony_parser::Prop *prop); 22 22 static v4 * get_vec4(peony_parser::Prop *prop);
+42 -42
src/physics.cpp
··· 125 125 // Calculate slab intersection points for ray 126 126 // `t is the distance along the ray (or “time” along the ray, as Szauer 127 127 // calls it) that the intersection happens at. 128 - real32 t[6] = {}; 128 + f32 t[6] = {}; 129 129 range_named (i, 0, 3) { 130 130 if (f[i] == 0) { 131 131 if (-e[i] - obb->extents[i] > 0 || -e[i] + obb->extents[i] < 0) { ··· 141 141 142 142 // After the above loop, we've hit all three slabs. We now need to find the 143 143 // largest minimum `t^{min}` and smallest maximum `t^{max}`. 144 - real32 tmin = max( 144 + f32 tmin = max( 145 145 max(min(t[0], t[1]), min(t[2], t[3])), 146 146 min(t[4], t[5])); 147 - real32 tmax = min( 147 + f32 tmax = min( 148 148 min(max(t[0], t[1]), max(t[2], t[3])), 149 149 max(t[4], t[5])); 150 150 ··· 203 203 physics::get_edge_contact_point( 204 204 v3 a_edge_point, 205 205 v3 a_axis, 206 - real32 a_axis_length, 206 + f32 a_axis_length, 207 207 v3 b_edge_point, 208 208 v3 b_axis, 209 - real32 b_axis_length, 210 - bool32 should_use_a_midpoint 209 + f32 b_axis_length, 210 + bool should_use_a_midpoint 211 211 ) { 212 - real32 a_axis_sqlen = length2(a_axis); 213 - real32 b_axis_sqlen = length2(b_axis); 214 - real32 a_b_axes_dotprod = dot(b_axis, a_axis); 212 + f32 a_axis_sqlen = length2(a_axis); 213 + f32 b_axis_sqlen = length2(b_axis); 214 + f32 a_b_axes_dotprod = dot(b_axis, a_axis); 215 215 216 216 v3 a_ep_to_b_ep = a_edge_point - b_edge_point; 217 - real32 a_ep_projection = dot(a_axis, a_ep_to_b_ep); 218 - real32 b_ep_projection = dot(b_axis, a_ep_to_b_ep); 217 + f32 a_ep_projection = dot(a_axis, a_ep_to_b_ep); 218 + f32 b_ep_projection = dot(b_axis, a_ep_to_b_ep); 219 219 220 - real32 denom = a_axis_sqlen * b_axis_sqlen - a_b_axes_dotprod * a_b_axes_dotprod; 220 + f32 denom = a_axis_sqlen * b_axis_sqlen - a_b_axes_dotprod * a_b_axes_dotprod; 221 221 222 222 // Zero denominator indicates parallel lines 223 223 if (abs(denom) < 0.0001f) { 224 224 return should_use_a_midpoint ? a_edge_point : b_edge_point; 225 225 } 226 226 227 - real32 mua = (a_b_axes_dotprod * b_ep_projection - b_axis_sqlen * a_ep_projection) / denom; 228 - real32 mub = (a_axis_sqlen * b_ep_projection - a_b_axes_dotprod * a_ep_projection) / denom; 227 + f32 mua = (a_b_axes_dotprod * b_ep_projection - b_axis_sqlen * a_ep_projection) / denom; 228 + f32 mub = (a_axis_sqlen * b_ep_projection - a_b_axes_dotprod * a_ep_projection) / denom; 229 229 230 230 // If either of the edges has the nearest point out of bounds, then the edges 231 231 // aren't crossed, we have an edge-face contact. Our point is on the edge, ··· 328 328 v3 e, // object extents 329 329 v3 c, // object center 330 330 v3 n, // collision normal 331 - uint32 axis, // axis of separation 332 - uint32 clip_edges[4], // the indices of the reference face edges 331 + u32 axis, // axis of separation 332 + u32 clip_edges[4], // the indices of the reference face edges 333 333 m3 *reference_face_cob, // the change of basis of the reference face 334 334 v3 *reference_face_e // the extents of the reference face 335 335 ) { ··· 403 403 } 404 404 405 405 406 - uint32 406 + u32 407 407 physics::clip_faces( 408 408 v3 reference_center, v3 reference_face_extents, 409 - uint32 clip_edges[4], m3 reference_face_cob, 409 + u32 clip_edges[4], m3 reference_face_cob, 410 410 spatial::Face incident_face, 411 - v3 clip_vertices[8], real32 clip_depths[8] 411 + v3 clip_vertices[8], f32 clip_depths[8] 412 412 ) { 413 413 return 0; 414 414 } ··· 416 416 417 417 void 418 418 physics::update_best_for_face_axis( 419 - real32 *best_sep, uint32 *best_axis, v3 *best_normal, 420 - real32 sep, uint32 axis, v3 normal 419 + f32 *best_sep, u32 *best_axis, v3 *best_normal, 420 + f32 sep, u32 axis, v3 normal 421 421 ) { 422 422 if (sep > *best_sep) { 423 423 *best_sep = sep; ··· 429 429 430 430 void 431 431 physics::update_best_for_edge_axis( 432 - real32 *best_sep, uint32 *best_axis, v3 *best_normal, 433 - real32 sep, uint32 axis, v3 normal 432 + f32 *best_sep, u32 *best_axis, v3 *best_normal, 433 + f32 sep, u32 axis, v3 normal 434 434 ) { 435 - real32 normal_len = length(normal); 435 + f32 normal_len = length(normal); 436 436 sep /= normal_len; 437 437 if (sep > *best_sep) { 438 438 *best_sep = sep; ··· 478 478 spatial::Component *spatial_b 479 479 ) { 480 480 // The radius from a/b's center to its outer vertex 481 - real32 a_radius, b_radius; 481 + f32 a_radius, b_radius; 482 482 // The distance between a and b 483 - real32 a_to_b; 483 + f32 a_to_b; 484 484 // The separation between a and b 485 - real32 sep; 485 + f32 sep; 486 486 // The rotation matrix expression b in a's coordinate frame 487 487 m3 r; 488 488 // abs(r) is used in a lot of calculations so we precompute it ··· 529 529 // their cross product will give us something we can't use. I'm not sure why 530 530 // we're not skipping the specific axes specifically, and we're skipping 531 531 // everything instead. 532 - bool32 do_obbs_share_one_axis = false; 532 + bool do_obbs_share_one_axis = false; 533 533 534 534 // Compute common subexpressions. Add in an epsilon term to counteract 535 535 // arithmetic errors when two edges are parallel and their cross product ··· 543 543 } 544 544 } 545 545 546 - real32 a_face_max_sep = -FLT_MAX; 547 - uint32 a_face_best_axis = 0; 546 + f32 a_face_max_sep = -FLT_MAX; 547 + u32 a_face_best_axis = 0; 548 548 v3 a_face_best_normal = v3(0.0f); 549 - real32 b_face_max_sep = -FLT_MAX; 550 - uint32 b_face_best_axis = 0; 549 + f32 b_face_max_sep = -FLT_MAX; 550 + u32 b_face_best_axis = 0; 551 551 v3 b_face_best_normal = v3(0.0f); 552 - real32 edge_max_sep = -FLT_MAX; 553 - uint32 edge_best_axis = 0; 552 + f32 edge_max_sep = -FLT_MAX; 553 + u32 edge_best_axis = 0; 554 554 v3 edge_best_normal = v3(0.0f); 555 555 556 556 // Test a's face axes (a.x, a.y, a.z) ··· 606 606 } 607 607 608 608 // Find the best option for the face cases 609 - real32 face_max_sep; 610 - uint32 face_best_axis; 609 + f32 face_max_sep; 610 + u32 face_best_axis; 611 611 if (a_face_max_sep > b_face_max_sep) { 612 612 face_max_sep = a_face_max_sep; 613 613 face_best_axis = a_face_best_axis; ··· 689 689 690 690 spatial::Face incident_face = get_incident_face(&incident_cob, incident_extents, incident_center, manifold.normal); 691 691 692 - uint32 clip_edges[4]; 692 + u32 clip_edges[4]; 693 693 m3 reference_face_cob; 694 694 v3 reference_face_extents; 695 695 get_reference_face_edges_and_basis( 696 696 &reference_cob, reference_extents, reference_center, manifold.normal, 697 697 manifold.axis, clip_edges, &reference_face_cob, &reference_face_extents); 698 698 699 - uint32 n_clip_vertices; 699 + u32 n_clip_vertices; 700 700 v3 clip_vertices[8]; 701 - real32 clip_depths[8]; 701 + f32 clip_depths[8]; 702 702 n_clip_vertices = clip_faces( 703 703 reference_center, reference_face_extents, 704 704 clip_edges, reference_face_cob, ··· 729 729 v4(0.0f, 1.0f, 0.0f, 1.0f)); 730 730 } else { 731 731 // Edge-edge collision 732 - uint32 edge_axis = manifold.axis - 6; 733 - uint32 a_axis = edge_axis / 3; 734 - uint32 b_axis = edge_axis % 3; 732 + u32 edge_axis = manifold.axis - 6; 733 + u32 a_axis = edge_axis / 3; 734 + u32 b_axis = edge_axis % 3; 735 735 736 736 v3 a_edge_point = a->extents; 737 737 v3 b_edge_point = b->extents;
+22 -22
src/physics.hpp
··· 8 8 9 9 class physics { 10 10 public: 11 - static constexpr real32 PARALLEL_FACE_TOLERANCE = 1.0e-2; 12 - static constexpr real32 RELATIVE_TOLERANCE = 1.00f; 13 - static constexpr real32 ABSOLUTE_TOLERANCE = 0.10f; 11 + static constexpr f32 PARALLEL_FACE_TOLERANCE = 1.0e-2; 12 + static constexpr f32 RELATIVE_TOLERANCE = 1.00f; 13 + static constexpr f32 ABSOLUTE_TOLERANCE = 0.10f; 14 14 15 15 struct Component { 16 16 entities::Handle entity_handle; ··· 23 23 }; 24 24 25 25 struct CollisionManifold { 26 - bool32 did_collide; 26 + bool did_collide; 27 27 Component *collidee; 28 - real32 sep_max; 29 - uint32 axis; 28 + f32 sep_max; 29 + u32 axis; 30 30 v3 normal; 31 31 }; 32 32 33 33 struct RaycastResult { 34 - bool32 did_intersect; 35 - real32 distance; 34 + bool did_intersect; 35 + f32 distance; 36 36 }; 37 37 38 38 struct RayCollisionResult { 39 - bool32 did_intersect; 40 - real32 distance; 39 + bool did_intersect; 40 + f32 distance; 41 41 Component *collidee; 42 42 }; 43 43 ··· 58 58 static v3 get_edge_contact_point( 59 59 v3 a_edge_point, 60 60 v3 a_axis, 61 - real32 a_axis_length, 61 + f32 a_axis_length, 62 62 v3 b_edge_point, 63 63 v3 b_axis, 64 - real32 b_axis_length, 65 - bool32 should_use_a_midpoint 64 + f32 b_axis_length, 65 + bool should_use_a_midpoint 66 66 ); 67 67 static spatial::Face get_incident_face(m3 *cob, v3 e, v3 c, v3 n); 68 68 static void get_reference_face_edges_and_basis( ··· 70 70 v3 e, 71 71 v3 c, 72 72 v3 n, 73 - uint32 axis, 74 - uint32 clip_edges[4], 73 + u32 axis, 74 + u32 clip_edges[4], 75 75 m3 *reference_face_cob, 76 76 v3 *reference_face_e 77 77 ); 78 - static uint32 clip_faces( 78 + static u32 clip_faces( 79 79 v3 reference_center, v3 reference_face_extents, 80 - uint32 clip_edges[4], m3 reference_face_cob, 80 + u32 clip_edges[4], m3 reference_face_cob, 81 81 spatial::Face incident_face, 82 - v3 clip_vertices[8], real32 clip_depths[8] 82 + v3 clip_vertices[8], f32 clip_depths[8] 83 83 ); 84 84 static void update_best_for_face_axis( 85 - real32 *best_sep, uint32 *best_axis, v3 *best_normal, 86 - real32 sep, uint32 axis, v3 normal 85 + f32 *best_sep, u32 *best_axis, v3 *best_normal, 86 + f32 sep, u32 axis, v3 normal 87 87 ); 88 88 static void update_best_for_edge_axis( 89 - real32 *best_sep, uint32 *best_axis, v3 *best_normal, 90 - real32 sep, uint32 axis, v3 normal 89 + f32 *best_sep, u32 *best_axis, v3 *best_normal, 90 + f32 sep, u32 axis, v3 normal 91 91 ); 92 92 static CollisionManifold intersect_obb_obb( 93 93 spatial::Obb *a,
+6 -6
src/queue.hpp
··· 7 7 template <typename T> 8 8 class Queue { 9 9 public: 10 - uint32 size = 0; 11 - uint32 max_size = 0; 10 + u32 size = 0; 11 + u32 max_size = 0; 12 12 T *items = nullptr; 13 - uint32 head = 0; 14 - uint32 tail = 0; 13 + u32 head = 0; 14 + u32 tail = 0; 15 15 16 16 T* push() { 17 17 assert(this->size < this->max_size); ··· 43 43 return item; 44 44 } 45 45 46 - Queue(memory::Pool *memory_pool, uint32 new_max_size, const char *debug_name) { 46 + Queue(memory::Pool *memory_pool, u32 new_max_size, const char *debug_name) { 47 47 this->max_size = new_max_size; 48 48 this->items = (T*)memory::push(memory_pool, sizeof(T) * this->max_size, debug_name); 49 49 } 50 50 51 - Queue(memory::Pool *memory_pool, uint32 new_size, uint32 new_max_size, T *new_items) { 51 + Queue(memory::Pool *memory_pool, u32 new_size, u32 new_max_size, T *new_items) { 52 52 this->size = new_size; 53 53 this->head = 0; 54 54 this->tail = new_size;
+63 -63
src/renderer.cpp
··· 47 47 // not pixels! 48 48 49 49 #if USE_FULLSCREEN 50 - int32 n_monitors; 50 + i32 n_monitors; 51 51 GLFWmonitor **monitors = glfwGetMonitors(&n_monitors); 52 52 GLFWmonitor *target_monitor = monitors[TARGET_MONITOR]; 53 53 const GLFWvidmode *video_mode = glfwGetVideoMode(target_monitor); ··· 159 159 renderer::resize_renderer_buffers( 160 160 memory::Pool *memory_pool, 161 161 BuiltinTextures *builtin_textures, 162 - uint32 width, 163 - uint32 height 162 + u32 width, 163 + u32 height 164 164 ) { 165 165 // TODO: Only regenerate once we're done resizing, not for every little bit 166 166 // of the resize. ··· 189 189 190 190 each (material, *mats::get_materials()) { 191 191 if (material->n_textures > 0 && material->is_screensize_dependent) { 192 - for (uint32 idx_texture = 0; idx_texture < material->n_textures; idx_texture++) { 192 + for (u32 idx_texture = 0; idx_texture < material->n_textures; idx_texture++) { 193 193 mats::Texture *texture = &material->textures[idx_texture]; 194 194 if (texture->type == mats::TextureType::g_position) { 195 195 material->textures[idx_texture] = *builtin_textures->g_position_texture; ··· 277 277 { 278 278 // Point lights 279 279 { 280 - real32 ratio = (real32)renderer::state->builtin_textures.shadowmap_3d_width / 281 - (real32)renderer::state->builtin_textures.shadowmap_3d_height; 280 + f32 ratio = (f32)renderer::state->builtin_textures.shadowmap_3d_width / 281 + (f32)renderer::state->builtin_textures.shadowmap_3d_height; 282 282 m4 perspective_projection = glm::perspective( 283 283 radians(90.0f), ratio, 284 284 renderer::state->builtin_textures.shadowmap_near_clip_dist, 285 285 renderer::state->builtin_textures.shadowmap_far_clip_dist); 286 286 287 - uint32 idx_light = 0; 287 + u32 idx_light = 0; 288 288 289 289 each (light_component, *engine::get_light_components()) { 290 290 if (light_component->entity_handle == entities::NO_ENTITY_HANDLE) { ··· 304 304 305 305 v3 position = spatial_component->position; 306 306 307 - for (uint32 idx_face = 0; idx_face < 6; idx_face++) { 307 + for (u32 idx_face = 0; idx_face < 6; idx_face++) { 308 308 renderer::state->shadowmap_3d_transforms[(idx_light * 6) + idx_face] = 309 309 perspective_projection * glm::lookAt( 310 310 position, ··· 330 330 331 331 // Directional lights 332 332 { 333 - real32 ortho_ratio = ( 334 - (real32)renderer::state->builtin_textures.shadowmap_2d_width / 335 - (real32)renderer::state->builtin_textures.shadowmap_2d_height); 336 - real32 ortho_width = 100.0f; 337 - real32 ortho_height = ortho_width / ortho_ratio; 333 + f32 ortho_ratio = ( 334 + (f32)renderer::state->builtin_textures.shadowmap_2d_width / 335 + (f32)renderer::state->builtin_textures.shadowmap_2d_height); 336 + f32 ortho_width = 100.0f; 337 + f32 ortho_height = ortho_width / ortho_ratio; 338 338 m4 ortho_projection = glm::ortho( 339 339 -ortho_width, ortho_width, -ortho_height, ortho_height, 340 340 renderer::state->builtin_textures.shadowmap_near_clip_dist, 341 341 renderer::state->builtin_textures.shadowmap_far_clip_dist); 342 342 343 - uint32 idx_light = 0; 343 + u32 idx_light = 0; 344 344 345 345 each (light_component, *engine::get_light_components()) { 346 346 if (light_component->entity_handle == entities::NO_ENTITY_HANDLE) { ··· 465 465 copy_scene_data_to_ubo(window_size, 0, 0, false); 466 466 render_scene(drawable::Pass::blur2, drawable::Mode::regular); 467 467 468 - for (uint32 idx = 0; idx < 3; idx++) { 468 + for (u32 idx = 0; idx < 3; idx++) { 469 469 glBindFramebuffer(GL_FRAMEBUFFER, renderer::state->builtin_textures.blur1_buffer); 470 470 copy_scene_data_to_ubo(window_size, 0, 0, true); 471 471 render_scene(drawable::Pass::blur1, drawable::Mode::regular); ··· 514 514 renderer::init( 515 515 renderer::State *renderer_state, 516 516 memory::Pool *memory_pool, 517 - uint32 width, 518 - uint32 height, 517 + u32 width, 518 + u32 height, 519 519 GLFWwindow *window 520 520 ) { 521 521 renderer::state = renderer_state; ··· 527 527 .shadowmap_2d_width = 800, 528 528 .shadowmap_2d_height = 600, 529 529 #elif defined(GRAPHICS_HIGH) 530 - .shadowmap_3d_width = min((uint32)width, (uint32)2000), 531 - .shadowmap_3d_height = min((uint32)width, (uint32)2000), 530 + .shadowmap_3d_width = min((u32)width, (u32)2000), 531 + .shadowmap_3d_height = min((u32)width, (u32)2000), 532 532 .shadowmap_2d_width = 2560 * 2, 533 533 .shadowmap_2d_height = 1440 * 2, 534 534 #endif ··· 686 686 void 687 687 renderer::init_g_buffer( 688 688 memory::Pool *memory_pool, 689 - uint32 *g_buffer, 689 + u32 *g_buffer, 690 690 mats::Texture **g_position_texture, 691 691 mats::Texture **g_normal_texture, 692 692 mats::Texture **g_albedo_texture, 693 693 mats::Texture **g_pbr_texture, 694 - uint32 width, 695 - uint32 height 694 + u32 width, 695 + u32 height 696 696 ) { 697 697 glGenFramebuffers(1, g_buffer); 698 698 glBindFramebuffer(GL_FRAMEBUFFER, *g_buffer); 699 699 700 - uint32 g_position_texture_name; 701 - uint32 g_normal_texture_name; 702 - uint32 g_albedo_texture_name; 703 - uint32 g_pbr_texture_name; 700 + u32 g_position_texture_name; 701 + u32 g_normal_texture_name; 702 + u32 g_albedo_texture_name; 703 + u32 g_pbr_texture_name; 704 704 705 705 glGenTextures(1, &g_position_texture_name); 706 706 glGenTextures(1, &g_normal_texture_name); ··· 763 763 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT3, GL_TEXTURE_2D, 764 764 (*g_pbr_texture)->texture_name, 0); 765 765 766 - uint32 attachments[4] = { 766 + u32 attachments[4] = { 767 767 GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, 768 768 GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3 769 769 }; 770 770 glDrawBuffers(4, attachments); 771 771 772 - uint32 rbo_depth; 772 + u32 rbo_depth; 773 773 glGenRenderbuffers(1, &rbo_depth); 774 774 glBindRenderbuffer(GL_RENDERBUFFER, rbo_depth); 775 775 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, width, height); ··· 785 785 void 786 786 renderer::init_l_buffer( 787 787 memory::Pool *memory_pool, 788 - uint32 *l_buffer, 788 + u32 *l_buffer, 789 789 mats::Texture **l_color_texture, 790 790 mats::Texture **l_bright_color_texture, 791 791 mats::Texture **l_depth_texture, 792 - uint32 width, 793 - uint32 height 792 + u32 width, 793 + u32 height 794 794 ) { 795 795 glGenFramebuffers(1, l_buffer); 796 796 glBindFramebuffer(GL_FRAMEBUFFER, *l_buffer); 797 797 798 798 // l_color_texture 799 799 { 800 - uint32 l_color_texture_name; 800 + u32 l_color_texture_name; 801 801 glGenTextures(1, &l_color_texture_name); 802 802 803 803 *l_color_texture = mats::init_texture( ··· 820 820 821 821 // l_bright_color_texture 822 822 { 823 - uint32 l_bright_color_texture_name; 823 + u32 l_bright_color_texture_name; 824 824 glGenTextures(1, &l_bright_color_texture_name); 825 825 826 826 *l_bright_color_texture = mats::init_texture( ··· 844 844 845 845 // Attach textures 846 846 { 847 - uint32 attachments[2] = {GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1}; 847 + u32 attachments[2] = {GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1}; 848 848 glDrawBuffers(2, attachments); 849 849 } 850 850 ··· 860 860 // way, we know we can copy the depth from one to the other without issues. For the 861 861 // moment, we're not using fog, so this is just commented out. 862 862 { 863 - uint32 l_depth_texture_name; 863 + u32 l_depth_texture_name; 864 864 glGenTextures(1, &l_depth_texture_name); 865 865 866 866 *l_depth_texture = mats::init_texture( ··· 884 884 // Depth buffer 885 885 // NOTE: Either this or the l_depth_texure should be enabled, not both 886 886 { 887 - uint32 rbo_depth; 887 + u32 rbo_depth; 888 888 glGenRenderbuffers(1, &rbo_depth); 889 889 glBindRenderbuffer(GL_RENDERBUFFER, rbo_depth); 890 890 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, width, height); ··· 902 902 void 903 903 renderer::init_blur_buffers( 904 904 memory::Pool *memory_pool, 905 - uint32 *blur1_buffer, 906 - uint32 *blur2_buffer, 905 + u32 *blur1_buffer, 906 + u32 *blur2_buffer, 907 907 mats::Texture **blur1_texture, 908 908 mats::Texture **blur2_texture, 909 - uint32 width, 910 - uint32 height 909 + u32 width, 910 + u32 height 911 911 ) { 912 912 #if !USE_BLOOM 913 913 return; 914 914 #endif 915 915 glGenFramebuffers(1, blur1_buffer); 916 916 glBindFramebuffer(GL_FRAMEBUFFER, *blur1_buffer); 917 - uint32 blur1_texture_name; 917 + u32 blur1_texture_name; 918 918 glGenTextures(1, &blur1_texture_name); 919 919 920 920 *blur1_texture = mats::init_texture( ··· 940 940 941 941 glGenFramebuffers(1, blur2_buffer); 942 942 glBindFramebuffer(GL_FRAMEBUFFER, *blur2_buffer); 943 - uint32 blur2_texture_name; 943 + u32 blur2_texture_name; 944 944 glGenTextures(1, &blur2_texture_name); 945 945 946 946 *blur2_texture = mats::init_texture( ··· 967 967 968 968 969 969 void 970 - renderer::init_ubo(uint32 *ubo_shader_common) 970 + renderer::init_ubo(u32 *ubo_shader_common) 971 971 { 972 972 glGenBuffers(1, ubo_shader_common); 973 973 glBindBuffer(GL_UNIFORM_BUFFER, *ubo_shader_common); ··· 980 980 void 981 981 renderer::init_3d_shadowmaps( 982 982 memory::Pool *memory_pool, 983 - uint32 *shadowmaps_3d_framebuffer, 984 - uint32 *shadowmaps_3d, 983 + u32 *shadowmaps_3d_framebuffer, 984 + u32 *shadowmaps_3d, 985 985 mats::Texture **shadowmaps_3d_texture, 986 - uint32 shadowmap_3d_width, 987 - uint32 shadowmap_3d_height 986 + u32 shadowmap_3d_width, 987 + u32 shadowmap_3d_height 988 988 ) { 989 989 glGenFramebuffers(1, shadowmaps_3d_framebuffer); 990 990 glGenTextures(1, shadowmaps_3d); ··· 1019 1019 void 1020 1020 renderer::init_2d_shadowmaps( 1021 1021 memory::Pool *memory_pool, 1022 - uint32 *shadowmaps_2d_framebuffer, 1023 - uint32 *shadowmaps_2d, 1022 + u32 *shadowmaps_2d_framebuffer, 1023 + u32 *shadowmaps_2d, 1024 1024 mats::Texture **shadowmaps_2d_texture, 1025 - uint32 shadowmap_2d_width, 1026 - uint32 shadowmap_2d_height 1025 + u32 shadowmap_2d_width, 1026 + u32 shadowmap_2d_height 1027 1027 ) { 1028 1028 glGenFramebuffers(1, shadowmaps_2d_framebuffer); 1029 1029 glGenTextures(1, shadowmaps_2d); ··· 1036 1036 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 1037 1037 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); 1038 1038 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); 1039 - real32 border_color[] = { 1.0f, 1.0f, 1.0f, 1.0f }; 1039 + f32 border_color[] = { 1.0f, 1.0f, 1.0f, 1.0f }; 1040 1040 glTexParameterfv(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BORDER_COLOR, border_color); 1041 1041 glBindFramebuffer(GL_FRAMEBUFFER, *shadowmaps_2d_framebuffer); 1042 1042 glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, *shadowmaps_2d, 0); ··· 1068 1068 glBindVertexArray(renderer::state->gui_vao); 1069 1069 glBindBuffer(GL_ARRAY_BUFFER, renderer::state->gui_vbo); 1070 1070 glBufferData(GL_ARRAY_BUFFER, GUI_VERTEX_SIZE * GUI_MAX_N_VERTICES, NULL, GL_DYNAMIC_DRAW); 1071 - uint32 location; 1071 + u32 location; 1072 1072 1073 1073 // position (vec2) 1074 1074 location = 0; ··· 1080 1080 location = 1; 1081 1081 glEnableVertexAttribArray(location); 1082 1082 glVertexAttribPointer(location, 2, GL_FLOAT, GL_FALSE, GUI_VERTEX_SIZE, 1083 - (void*)(2 * sizeof(real32))); 1083 + (void*)(2 * sizeof(f32))); 1084 1084 1085 1085 // color (vec4) 1086 1086 location = 2; 1087 1087 glEnableVertexAttribArray(location); 1088 1088 glVertexAttribPointer(location, 4, GL_FLOAT, GL_FALSE, GUI_VERTEX_SIZE, 1089 - (void*)(4 * sizeof(real32))); 1089 + (void*)(4 * sizeof(f32))); 1090 1090 } 1091 1091 1092 1092 // Shaders ··· 1126 1126 void 1127 1127 renderer::copy_scene_data_to_ubo( 1128 1128 WindowSize *window_size, 1129 - uint32 current_shadow_light_idx, 1130 - uint32 current_shadow_light_type, 1131 - bool32 is_blur_horizontal 1129 + u32 current_shadow_light_idx, 1130 + u32 current_shadow_light_type, 1131 + bool is_blur_horizontal 1132 1132 ) { 1133 1133 ShaderCommon *shader_common = &renderer::state->shader_common; 1134 1134 cameras::Camera *camera = cameras::get_main(); ··· 1166 1166 shader_common->window_width = window_size->width; 1167 1167 shader_common->window_height = window_size->height; 1168 1168 1169 - uint32 n_point_lights = 0; 1170 - uint32 n_directional_lights = 0; 1169 + u32 n_point_lights = 0; 1170 + u32 n_directional_lights = 0; 1171 1171 1172 1172 each (light_component, *engine::get_light_components()) { 1173 1173 if (light_component->entity_handle == entities::NO_ENTITY_HANDLE) { ··· 1244 1244 1245 1245 if (render_mode == drawable::Mode::regular) { 1246 1246 for ( 1247 - uint32 texture_idx = 1; 1247 + u32 texture_idx = 1; 1248 1248 texture_idx < shader_asset->n_texture_units + 1; texture_idx++ 1249 1249 ) { 1250 1250 if (shader_asset->texture_units[texture_idx] != 0) { ··· 1257 1257 } 1258 1258 1259 1259 for ( 1260 - uint32 uniform_idx = 0; 1260 + u32 uniform_idx = 0; 1261 1261 uniform_idx < shader_asset->n_intrinsic_uniforms; 1262 1262 uniform_idx++ 1263 1263 ) { ··· 1295 1295 continue; 1296 1296 } 1297 1297 1298 - if (!((uint32)render_pass & (uint32)drawable_component->target_render_pass)) { 1298 + if (!((u32)render_pass & (u32)drawable_component->target_render_pass)) { 1299 1299 continue; 1300 1300 } 1301 1301
+49 -49
src/renderer.hpp
··· 15 15 16 16 class renderer { 17 17 public: 18 - static constexpr uint32 GUI_MAX_N_VERTICES = 65536; 19 - static constexpr size_t GUI_VERTEX_SIZE = sizeof(real32) * gui::VERTEX_LENGTH; 18 + static constexpr u32 GUI_MAX_N_VERTICES = 65536; 19 + static constexpr size_t GUI_VERTEX_SIZE = sizeof(f32) * gui::VERTEX_LENGTH; 20 20 21 21 struct ShaderCommon { 22 22 m4 view; ··· 59 59 }; 60 60 61 61 struct BuiltinTextures { 62 - uint32 g_buffer; 62 + u32 g_buffer; 63 63 mats::Texture *g_position_texture; 64 64 mats::Texture *g_normal_texture; 65 65 mats::Texture *g_albedo_texture; 66 66 mats::Texture *g_pbr_texture; 67 67 68 - uint32 l_buffer; 68 + u32 l_buffer; 69 69 mats::Texture *l_color_texture; 70 70 mats::Texture *l_bright_color_texture; 71 71 mats::Texture *l_depth_texture; 72 72 73 - uint32 blur1_buffer; 74 - uint32 blur2_buffer; 73 + u32 blur1_buffer; 74 + u32 blur2_buffer; 75 75 mats::Texture *blur1_texture; 76 76 mats::Texture *blur2_texture; 77 77 78 - uint32 shadowmaps_3d_framebuffer; 79 - uint32 shadowmaps_3d; 78 + u32 shadowmaps_3d_framebuffer; 79 + u32 shadowmaps_3d; 80 80 mats::Texture *shadowmaps_3d_texture; 81 - uint32 shadowmap_3d_width; 82 - uint32 shadowmap_3d_height; 81 + u32 shadowmap_3d_width; 82 + u32 shadowmap_3d_height; 83 83 84 - uint32 shadowmaps_2d_framebuffer; 85 - uint32 shadowmaps_2d; 84 + u32 shadowmaps_2d_framebuffer; 85 + u32 shadowmaps_2d; 86 86 mats::Texture *shadowmaps_2d_texture; 87 - uint32 shadowmap_2d_width; 88 - uint32 shadowmap_2d_height; 87 + u32 shadowmap_2d_width; 88 + u32 shadowmap_2d_height; 89 89 90 - real32 shadowmap_near_clip_dist; 91 - real32 shadowmap_far_clip_dist; 90 + f32 shadowmap_near_clip_dist; 91 + f32 shadowmap_far_clip_dist; 92 92 }; 93 93 94 94 struct State { 95 - bool32 should_hide_ui; 96 - bool32 should_use_wireframe; 95 + bool should_hide_ui; 96 + bool should_use_wireframe; 97 97 mats::TextureType renderdebug_displayed_texture_type; 98 98 shaders::Asset standard_depth_shader_asset; 99 - uint32 ubo_shader_common; 99 + u32 ubo_shader_common; 100 100 ShaderCommon shader_common; 101 101 m4 shadowmap_3d_transforms[6 * MAX_N_LIGHTS]; 102 102 m4 shadowmap_2d_transforms[MAX_N_LIGHTS]; 103 103 BuiltinTextures builtin_textures; 104 - uint32 gui_vao; 105 - uint32 gui_vbo; 104 + u32 gui_vao; 105 + u32 gui_vbo; 106 106 mats::TextureAtlas gui_texture_atlas; 107 107 shaders::Asset gui_shader_asset; 108 108 Array<fonts::FontAsset> gui_font_assets; 109 - uint32 gui_n_vertices_pushed; 109 + u32 gui_n_vertices_pushed; 110 110 }; 111 111 112 112 static GLFWwindow * init_window(WindowSize *window_size); 113 - bool32 is_drawable_component_valid(drawable::Component *drawable_component); 113 + bool is_drawable_component_valid(drawable::Component *drawable_component); 114 114 void destroy_drawable_component(drawable::Component *drawable_component); 115 115 static void resize_renderer_buffers( 116 116 memory::Pool *memory_pool, 117 117 BuiltinTextures *builtin_textures, 118 - uint32 width, 119 - uint32 height 118 + u32 width, 119 + u32 height 120 120 ); 121 121 static void update_drawing_options(GLFWwindow *window); 122 122 static void render(GLFWwindow *window, WindowSize *window_size); 123 123 static void init( 124 124 renderer::State *renderer_state, 125 125 memory::Pool *memory_pool, 126 - uint32 width, 127 - uint32 height, 126 + u32 width, 127 + u32 height, 128 128 GLFWwindow *window 129 129 ); 130 130 static void start_drawing_gui(); ··· 144 144 private: 145 145 static void init_g_buffer( 146 146 memory::Pool *memory_pool, 147 - uint32 *g_buffer, 147 + u32 *g_buffer, 148 148 mats::Texture **g_position_texture, 149 149 mats::Texture **g_normal_texture, 150 150 mats::Texture **g_albedo_texture, 151 151 mats::Texture **g_pbr_texture, 152 - uint32 width, 153 - uint32 height 152 + u32 width, 153 + u32 height 154 154 ); 155 155 static void init_l_buffer( 156 156 memory::Pool *memory_pool, 157 - uint32 *l_buffer, 157 + u32 *l_buffer, 158 158 mats::Texture **l_color_texture, 159 159 mats::Texture **l_bright_color_texture, 160 160 mats::Texture **l_depth_texture, 161 - uint32 width, 162 - uint32 height 161 + u32 width, 162 + u32 height 163 163 ); 164 164 static void init_blur_buffers( 165 165 memory::Pool *memory_pool, 166 - uint32 *blur1_buffer, 167 - uint32 *blur2_buffer, 166 + u32 *blur1_buffer, 167 + u32 *blur2_buffer, 168 168 mats::Texture **blur1_texture, 169 169 mats::Texture **blur2_texture, 170 - uint32 width, 171 - uint32 height 170 + u32 width, 171 + u32 height 172 172 ); 173 - static void init_ubo(uint32 *ubo_shader_common); 173 + static void init_ubo(u32 *ubo_shader_common); 174 174 static void init_3d_shadowmaps( 175 175 memory::Pool *memory_pool, 176 - uint32 *shadowmaps_3d_framebuffer, 177 - uint32 *shadowmaps_3d, 176 + u32 *shadowmaps_3d_framebuffer, 177 + u32 *shadowmaps_3d, 178 178 mats::Texture **shadowmaps_3d_texture, 179 - uint32 shadowmap_3d_width, 180 - uint32 shadowmap_3d_height 179 + u32 shadowmap_3d_width, 180 + u32 shadowmap_3d_height 181 181 ); 182 182 static void init_2d_shadowmaps( 183 183 memory::Pool *memory_pool, 184 - uint32 *shadowmaps_2d_framebuffer, 185 - uint32 *shadowmaps_2d, 184 + u32 *shadowmaps_2d_framebuffer, 185 + u32 *shadowmaps_2d, 186 186 mats::Texture **shadowmaps_2d_texture, 187 - uint32 shadowmap_2d_width, 188 - uint32 shadowmap_2d_height 187 + u32 shadowmap_2d_width, 188 + u32 shadowmap_2d_height 189 189 ); 190 190 static void init_gui(memory::Pool *memory_pool); 191 191 static void copy_scene_data_to_ubo( 192 192 WindowSize *window_size, 193 - uint32 current_shadow_light_idx, 194 - uint32 current_shadow_light_type, 195 - bool32 is_blur_horizontal 193 + u32 current_shadow_light_idx, 194 + u32 current_shadow_light_type, 195 + bool is_blur_horizontal 196 196 ); 197 197 static void draw( 198 198 drawable::Mode render_mode,
+37 -37
src/shaders.cpp
··· 49 49 50 50 void 51 51 shaders::set_int( 52 - shaders::Asset *shader_asset, const char *uniform_name, uint32 value 52 + shaders::Asset *shader_asset, const char *uniform_name, u32 value 53 53 ) { 54 - int32 location = get_uniform_location(shader_asset, uniform_name); 54 + i32 location = get_uniform_location(shader_asset, uniform_name); 55 55 if (location >= 0) { 56 56 glUniform1i(location, value); 57 57 } ··· 62 62 shaders::set_bool( 63 63 shaders::Asset *shader_asset, const char *uniform_name, bool value 64 64 ) { 65 - set_int(shader_asset, uniform_name, (uint32)value); 65 + set_int(shader_asset, uniform_name, (u32)value); 66 66 } 67 67 68 68 ··· 70 70 shaders::set_float( 71 71 shaders::Asset *shader_asset, const char *uniform_name, float value 72 72 ) { 73 - int32 location = get_uniform_location(shader_asset, uniform_name); 73 + i32 location = get_uniform_location(shader_asset, uniform_name); 74 74 if (location >= 0) { 75 75 glUniform1f(location, value); 76 76 } ··· 80 80 void 81 81 shaders::set_vec2(shaders::Asset *shader_asset, const char *uniform_name, v2 *value) 82 82 { 83 - int32 location = get_uniform_location(shader_asset, uniform_name); 83 + i32 location = get_uniform_location(shader_asset, uniform_name); 84 84 if (location >= 0) { 85 85 glUniform2fv(location, 1, glm::value_ptr(*value)); 86 86 } ··· 90 90 void 91 91 shaders::set_vec3(shaders::Asset *shader_asset, const char *uniform_name, v3 *value) 92 92 { 93 - int32 location = get_uniform_location(shader_asset, uniform_name); 93 + i32 location = get_uniform_location(shader_asset, uniform_name); 94 94 if (location >= 0) { 95 95 glUniform3fv(location, 1, glm::value_ptr(*value)); 96 96 } ··· 100 100 void 101 101 shaders::set_vec4(shaders::Asset *shader_asset, const char *uniform_name, v4 *value) 102 102 { 103 - int32 location = get_uniform_location(shader_asset, uniform_name); 103 + i32 location = get_uniform_location(shader_asset, uniform_name); 104 104 if (location >= 0) { 105 105 glUniform4fv(location, 1, glm::value_ptr(*value)); 106 106 } ··· 110 110 void 111 111 shaders::set_mat2(shaders::Asset *shader_asset, const char *uniform_name, m2 *mat) 112 112 { 113 - int32 location = get_uniform_location(shader_asset, uniform_name); 113 + i32 location = get_uniform_location(shader_asset, uniform_name); 114 114 if (location >= 0) { 115 115 glUniformMatrix2fv(location, 1, GL_FALSE, glm::value_ptr(*mat)); 116 116 } ··· 120 120 void 121 121 shaders::set_mat3(shaders::Asset *shader_asset, const char *uniform_name, m3 *mat) 122 122 { 123 - int32 location = get_uniform_location(shader_asset, uniform_name); 123 + i32 location = get_uniform_location(shader_asset, uniform_name); 124 124 if (location >= 0) { 125 125 glUniformMatrix3fv(location, 1, GL_FALSE, glm::value_ptr(*mat)); 126 126 } ··· 129 129 130 130 void 131 131 shaders::set_mat4_multiple( 132 - shaders::Asset *shader_asset, uint32 n, const char *uniform_name, m4 *mat 132 + shaders::Asset *shader_asset, u32 n, const char *uniform_name, m4 *mat 133 133 ) { 134 - int32 location = get_uniform_location(shader_asset, uniform_name); 134 + i32 location = get_uniform_location(shader_asset, uniform_name); 135 135 if (location >= 0) { 136 136 glUniformMatrix4fv(location, n, GL_FALSE, glm::value_ptr(*mat)); 137 137 } ··· 141 141 void 142 142 shaders::set_mat4(shaders::Asset *shader_asset, const char *uniform_name, m4 *mat) 143 143 { 144 - int32 location = get_uniform_location(shader_asset, uniform_name); 144 + i32 location = get_uniform_location(shader_asset, uniform_name); 145 145 if (location >= 0) { 146 146 glUniformMatrix4fv(location, 1, GL_FALSE, glm::value_ptr(*mat)); 147 147 } ··· 155 155 } 156 156 157 157 158 - uint32 158 + u32 159 159 shaders::add_texture_unit( 160 160 shaders::Asset *shader_asset, 161 - uint32 new_texture_unit, 161 + u32 new_texture_unit, 162 162 GLenum new_texture_unit_type 163 163 ) { 164 - uint32 idx = ++shader_asset->n_texture_units; 164 + u32 idx = ++shader_asset->n_texture_units; 165 165 shader_asset->texture_units[idx] = new_texture_unit; 166 166 shader_asset->texture_unit_types[idx] = new_texture_unit_type; 167 167 return idx; ··· 235 235 236 236 237 237 void 238 - shaders::assert_shader_status_ok(uint32 new_shader, const char *path) 238 + shaders::assert_shader_status_ok(u32 new_shader, const char *path) 239 239 { 240 - int32 status; 240 + i32 status; 241 241 glGetShaderiv(new_shader, GL_COMPILE_STATUS, &status); 242 242 243 243 if (status != 1) { ··· 251 251 252 252 253 253 void 254 - shaders::assert_program_status_ok(uint32 new_program) 254 + shaders::assert_program_status_ok(u32 new_program) 255 255 { 256 - int32 status; 256 + i32 status; 257 257 glGetProgramiv(new_program, GL_LINK_STATUS, &status); 258 258 259 259 if (status != 1) { ··· 266 266 } 267 267 268 268 269 - uint32 269 + u32 270 270 shaders::make_shader(const char *path, const char *source, GLenum shader_type) 271 271 { 272 - uint32 shader = glCreateShader(shader_type); 272 + u32 shader = glCreateShader(shader_type); 273 273 glShaderSource(shader, 1, &source, NULL); 274 274 glCompileShader(shader); 275 275 assert_shader_status_ok(shader, path); ··· 277 277 } 278 278 279 279 280 - uint32 281 - shaders::make_program(uint32 vertex_shader, uint32 fragment_shader) 280 + u32 281 + shaders::make_program(u32 vertex_shader, u32 fragment_shader) 282 282 { 283 - uint32 new_program = glCreateProgram(); 283 + u32 new_program = glCreateProgram(); 284 284 glAttachShader(new_program, vertex_shader); 285 285 glAttachShader(new_program, fragment_shader); 286 286 glLinkProgram(new_program); ··· 291 291 } 292 292 293 293 294 - uint32 294 + u32 295 295 shaders::make_program( 296 - uint32 vertex_shader, uint32 fragment_shader, uint32 geometry_shader 296 + u32 vertex_shader, u32 fragment_shader, u32 geometry_shader 297 297 ) { 298 - uint32 new_program = glCreateProgram(); 298 + u32 new_program = glCreateProgram(); 299 299 glAttachShader(new_program, vertex_shader); 300 300 glAttachShader(new_program, fragment_shader); 301 301 glAttachShader(new_program, geometry_shader); ··· 314 314 char full_path[MAX_PATH]; 315 315 strcpy(full_path, SHADER_DIR); // TODO: Fix unsafe strings? 316 316 strcat(full_path, path); 317 - uint32 f1_size = files::get_file_size(SHADER_COMMON_PATH); 318 - uint32 f2_size = files::get_file_size(full_path); 317 + u32 f1_size = files::get_file_size(SHADER_COMMON_PATH); 318 + u32 f2_size = files::get_file_size(full_path); 319 319 char *file_memory = (char*)memory::push(memory_pool, f1_size + f2_size + 1, full_path); 320 320 files::load_file(file_memory, SHADER_COMMON_PATH); 321 321 files::load_file(file_memory + f1_size, full_path); ··· 329 329 char full_path[MAX_PATH]; 330 330 strcpy(full_path, SHADER_DIR); // TODO: Fix unsafe strings? 331 331 strcat(full_path, path); 332 - uint32 f1_size = files::get_file_size(SHADER_COMMON_PATH); 333 - uint32 f2_size = files::get_file_size(SHADER_COMMON_FRAGMENT_PATH); 334 - uint32 f3_size = files::get_file_size(full_path); 332 + u32 f1_size = files::get_file_size(SHADER_COMMON_PATH); 333 + u32 f2_size = files::get_file_size(SHADER_COMMON_FRAGMENT_PATH); 334 + u32 f3_size = files::get_file_size(full_path); 335 335 char *file_memory = (char*)memory::push(memory_pool, f1_size + f2_size + f3_size + 1, full_path); 336 336 files::load_file(file_memory, SHADER_COMMON_PATH); 337 337 files::load_file(file_memory + f1_size, SHADER_COMMON_FRAGMENT_PATH); ··· 340 340 } 341 341 342 342 343 - int32 343 + i32 344 344 shaders::get_uniform_location( 345 345 shaders::Asset *shader_asset, 346 346 const char *uniform_name 347 347 ) { 348 348 // Look up in cache. 349 - for (uint32 idx = 0; idx < shader_asset->n_intrinsic_uniforms; idx++) { 349 + for (u32 idx = 0; idx < shader_asset->n_intrinsic_uniforms; idx++) { 350 350 if (strcmp(shader_asset->intrinsic_uniform_names[idx], uniform_name) == 0) { 351 351 return shader_asset->intrinsic_uniform_locations[idx]; 352 352 } ··· 368 368 void 369 369 shaders::load_uniforms(shaders::Asset *shader_asset) 370 370 { 371 - for (uint16 idx = 0; idx < MAX_N_UNIFORMS; idx++) { 371 + for (u16 idx = 0; idx < MAX_N_UNIFORMS; idx++) { 372 372 shader_asset->intrinsic_uniform_locations[idx] = -1; 373 373 } 374 374 375 375 // Bind uniform block 376 - uint32 uniform_block_index = glGetUniformBlockIndex(shader_asset->program, "shader_common"); 376 + u32 uniform_block_index = glGetUniformBlockIndex(shader_asset->program, "shader_common"); 377 377 glUniformBlockBinding(shader_asset->program, uniform_block_index, 0); 378 378 379 379 // Load uniforms 380 380 // NOTE: We may want to skip all shader_asset stuff, because fallback on loading the locations 381 381 // in `shader::set_*` anyway. But, it's kind of cool to know we're loading everything we can 382 382 // up front in shader_asset function. 383 - uint32 new_n_intrinsic_uniforms = 0; 383 + u32 new_n_intrinsic_uniforms = 0; 384 384 GLint n_active_uniforms; 385 385 char uniform_name[MAX_UNIFORM_NAME_LENGTH]; 386 386 GLint uniform_name_length;
+16 -16
src/shaders.hpp
··· 16 16 char vert_path[MAX_PATH]; 17 17 char frag_path[MAX_PATH]; 18 18 char geom_path[MAX_PATH]; 19 - uint32 program; 19 + u32 program; 20 20 Type type; 21 - uint32 n_texture_units; 22 - uint32 texture_units[MAX_N_TEXTURE_UNITS]; 21 + u32 n_texture_units; 22 + u32 texture_units[MAX_N_TEXTURE_UNITS]; 23 23 GLenum texture_unit_types[MAX_N_TEXTURE_UNITS]; 24 24 bool did_set_texture_uniforms; 25 25 ··· 32 32 uniform buffer object. 33 33 */ 34 34 35 - uint32 n_intrinsic_uniforms; 36 - int32 intrinsic_uniform_locations[MAX_N_UNIFORMS]; 35 + u32 n_intrinsic_uniforms; 36 + i32 intrinsic_uniform_locations[MAX_N_UNIFORMS]; 37 37 char intrinsic_uniform_names[MAX_UNIFORM_NAME_LENGTH][MAX_N_UNIFORMS]; 38 38 }; 39 39 40 40 static const char* shader_type_to_string(Type shader_type); 41 41 static Type shader_type_from_string(const char* str); 42 42 static bool is_shader_asset_valid(Asset *shader_asset); 43 - static void set_int(Asset *shader_asset, const char *uniform_name, uint32 value); 43 + static void set_int(Asset *shader_asset, const char *uniform_name, u32 value); 44 44 static void set_bool(Asset *shader_asset, const char *uniform_name, bool value); 45 45 static void set_float(Asset *shader_asset, const char *uniform_name, float value); 46 46 static void set_vec2(Asset *shader_asset, const char *uniform_name, v2 *value); ··· 49 49 static void set_mat2(Asset *shader_asset, const char *uniform_name, m2 *mat); 50 50 static void set_mat3(Asset *shader_asset, const char *uniform_name, m3 *mat); 51 51 static void set_mat4_multiple( 52 - Asset *shader_asset, uint32 n, const char *uniform_name, m4 *mat 52 + Asset *shader_asset, u32 n, const char *uniform_name, m4 *mat 53 53 ); 54 54 static void set_mat4(Asset *shader_asset, const char *uniform_name, m4 *mat); 55 55 static void reset_texture_units(Asset *shader_asset); 56 - static uint32 add_texture_unit( 56 + static u32 add_texture_unit( 57 57 Asset *shader_asset, 58 - uint32 new_texture_unit, 58 + u32 new_texture_unit, 59 59 GLenum new_texture_unit_type 60 60 ); 61 61 static void load_shader_asset(Asset *shader_asset, memory::Pool *memory_pool); ··· 68 68 static void destroy_shader_asset(Asset *shader_asset); 69 69 70 70 private: 71 - static void assert_shader_status_ok(uint32 new_shader, const char *path); 72 - static void assert_program_status_ok(uint32 new_program); 73 - static uint32 make_shader(const char *path, const char *source, GLenum shader_type); 74 - static uint32 make_program(uint32 vertex_shader, uint32 fragment_shader); 75 - static uint32 make_program( 76 - uint32 vertex_shader, uint32 fragment_shader, uint32 geometry_shader 71 + static void assert_shader_status_ok(u32 new_shader, const char *path); 72 + static void assert_program_status_ok(u32 new_program); 73 + static u32 make_shader(const char *path, const char *source, GLenum shader_type); 74 + static u32 make_program(u32 vertex_shader, u32 fragment_shader); 75 + static u32 make_program( 76 + u32 vertex_shader, u32 fragment_shader, u32 geometry_shader 77 77 ); 78 78 static const char* load_file(memory::Pool *memory_pool, const char *path); 79 79 static const char* load_frag_file(memory::Pool *memory_pool, const char *path); 80 - static int32 get_uniform_location( 80 + static i32 get_uniform_location( 81 81 Asset *shader_asset, 82 82 const char *uniform_name 83 83 );
+2 -2
src/spatial.cpp
··· 21 21 } 22 22 23 23 24 - bool32 24 + bool 25 25 spatial::does_spatial_component_have_dimensions(spatial::Component *spatial_component) 26 26 { 27 27 return ( ··· 32 32 } 33 33 34 34 35 - bool32 35 + bool 36 36 spatial::is_spatial_component_valid(spatial::Component *spatial_component) 37 37 { 38 38 return does_spatial_component_have_dimensions(spatial_component) ||
+2 -2
src/spatial.hpp
··· 44 44 45 45 46 46 static void print_spatial_component(Component *spatial_component); 47 - static bool32 does_spatial_component_have_dimensions(Component *spatial_component); 48 - static bool32 is_spatial_component_valid(Component *spatial_component); 47 + static bool does_spatial_component_have_dimensions(Component *spatial_component); 48 + static bool is_spatial_component_valid(Component *spatial_component); 49 49 static m4 make_model_matrix( 50 50 Component *spatial_component, 51 51 ModelMatrixCache *cache
+8 -8
src/stackarray.hpp
··· 4 4 5 5 #include "memory.hpp" 6 6 7 - template <typename T, uint32 capacity> 7 + template <typename T, u32 capacity> 8 8 class StackArray { 9 9 public: 10 10 T items[capacity] = {{}}; 11 - uint32 length = 0; 12 - bool32 is_sparse = false; 13 - uint32 starting_idx = 0; 11 + u32 length = 0; 12 + bool is_sparse = false; 13 + u32 starting_idx = 0; 14 14 15 15 T* push() { 16 16 assert(this->length < capacity); 17 - uint32 new_idx = this->length; 17 + u32 new_idx = this->length; 18 18 this->length++; 19 19 T* new_slot = &this->items[new_idx]; 20 20 return new_slot; ··· 26 26 return new_slot; 27 27 } 28 28 29 - T* get(uint32 idx) { 29 + T* get(u32 idx) { 30 30 assert(idx >= this->starting_idx && idx < capacity); 31 31 if (idx >= this->length) { 32 32 assert(this->is_sparse); ··· 35 35 return &this->items[idx]; 36 36 } 37 37 38 - T* operator[](uint32 idx) { 38 + T* operator[](u32 idx) { 39 39 return get(idx); 40 40 } 41 41 ··· 62 62 this->length = 0; 63 63 } 64 64 65 - void delete_elements_after_index(uint32 idx) { 65 + void delete_elements_after_index(u32 idx) { 66 66 memset(&this->items[idx], 0, sizeof(T) * (this->length - idx)); 67 67 this->length = idx; 68 68 }
+3 -3
src/tasks.cpp
··· 21 21 void 22 22 tasks::run_loading_loop( 23 23 std::mutex *mutex, 24 - bool32 *should_stop, 25 - uint32 idx_thread 24 + bool *should_stop, 25 + u32 idx_thread 26 26 ) { 27 27 while (!*should_stop) { 28 28 Task *task = nullptr; ··· 55 55 { 56 56 auto t0 = debug_start_timer(); 57 57 task->fn(task->argument_1); 58 - real64 duration = debug_end_timer(t0); 58 + f64 duration = debug_end_timer(t0); 59 59 logs::info("Task took %.0fms", duration); 60 60 }
+2 -2
src/tasks.hpp
··· 20 20 static void push(Task task); 21 21 static void run_loading_loop( 22 22 std::mutex *mutex, 23 - bool32 *should_stop, 24 - uint32 idx_thread 23 + bool *should_stop, 24 + u32 idx_thread 25 25 ); 26 26 static void init(tasks::State *tasks_state, memory::Pool *pool); 27 27
+14 -30
src/types.hpp
··· 5 5 #include <stdint.h> 6 6 #include "glm.hpp" 7 7 8 - typedef int8_t int8; 9 - typedef int16_t int16; 10 - typedef int32_t int32; 11 - typedef int64_t int64; 12 - typedef int8 s8; 13 - typedef int16 s16; 14 - typedef int32 s32; 15 - typedef int64 s64; 8 + typedef int8_t i8; 9 + typedef int16_t i16; 10 + typedef int32_t i32; 11 + typedef int64_t i64; 16 12 17 - typedef int8 bool8; 18 - typedef int16 bool16; 19 - typedef int32 bool32; 20 - typedef int64 bool64; 21 - typedef bool8 b8; 22 - typedef bool16 b16; 23 - typedef bool32 b32; 24 - typedef bool64 b64; 13 + typedef int8_t b8; 14 + typedef int16_t b16; 15 + typedef int32_t b32; 16 + typedef int64_t b64; 25 17 26 - typedef uint8_t uint8; 27 - typedef uint16_t uint16; 28 - typedef uint32_t uint32; 29 - typedef uint64_t uint64; 30 - typedef uint8 u8; 31 - typedef uint16 u16; 32 - typedef uint32 u32; 33 - typedef uint64 u64; 18 + typedef uint8_t u8; 19 + typedef uint16_t u16; 20 + typedef uint32_t u32; 21 + typedef uint64_t u64; 34 22 35 - typedef float real32; 36 - typedef double real64; 37 - typedef real32 r32; 38 - typedef real64 r64; 39 - typedef real32 f32; 40 - typedef real64 f64; 23 + typedef float f32; 24 + typedef double f64; 41 25 42 26 typedef glm::vec2 v2; 43 27 typedef glm::vec3 v3;
+18 -18
src/util.cpp
··· 56 56 57 57 58 58 GLenum 59 - util::get_texture_format_from_n_components(int32 n_components) 59 + util::get_texture_format_from_n_components(i32 n_components) 60 60 { 61 61 if (n_components == 1) { 62 62 return GL_RED; ··· 71 71 } 72 72 73 73 74 - real64 75 - util::random(real64 min, real64 max) 74 + f64 75 + util::random(f64 min, f64 max) 76 76 { 77 - uint32 r = rand(); 78 - real64 r_normalized = (real64)r / (real64)RAND_MAX; 77 + u32 r = rand(); 78 + f64 r_normalized = (f64)r / (f64)RAND_MAX; 79 79 return min + ((r_normalized) * (max - min)); 80 80 } 81 81 ··· 256 256 } 257 257 258 258 259 - real32 260 - util::round_to_nearest_multiple(real32 n, real32 multiple_of) 259 + f32 260 + util::round_to_nearest_multiple(f32 n, f32 multiple_of) 261 261 { 262 262 return (floor((n) / multiple_of) * multiple_of) + multiple_of; 263 263 } 264 264 265 265 266 - real64 267 - util::get_us_from_duration(chrono::duration<real64> duration) 266 + f64 267 + util::get_us_from_duration(chrono::duration<f64> duration) 268 268 { 269 - return chrono::duration_cast<chrono::duration<real64>>(duration).count(); 269 + return chrono::duration_cast<chrono::duration<f64>>(duration).count(); 270 270 } 271 271 272 272 ··· 281 281 } 282 282 283 283 284 - uint32 util::kb_to_b(uint32 value) { return value * 1024; } 285 - uint32 util::mb_to_b(uint32 value) { return kb_to_b(value) * 1024; } 286 - uint32 util::gb_to_b(uint32 value) { return mb_to_b(value) * 1024; } 287 - uint32 util::tb_to_b(uint32 value) { return gb_to_b(value) * 1024; } 288 - real32 util::b_to_kb(uint32 value) { return value / 1024.0f; } 289 - real32 util::b_to_mb(uint32 value) { return b_to_kb(value) / 1024.0f; } 290 - real32 util::b_to_gb(uint32 value) { return b_to_mb(value) / 1024.0f; } 291 - real32 util::b_to_tb(uint32 value) { return b_to_gb(value) / 1024.0f; } 284 + u32 util::kb_to_b(u32 value) { return value * 1024; } 285 + u32 util::mb_to_b(u32 value) { return kb_to_b(value) * 1024; } 286 + u32 util::gb_to_b(u32 value) { return mb_to_b(value) * 1024; } 287 + u32 util::tb_to_b(u32 value) { return gb_to_b(value) * 1024; } 288 + f32 util::b_to_kb(u32 value) { return value / 1024.0f; } 289 + f32 util::b_to_mb(u32 value) { return b_to_kb(value) / 1024.0f; } 290 + f32 util::b_to_gb(u32 value) { return b_to_mb(value) / 1024.0f; } 291 + f32 util::b_to_tb(u32 value) { return b_to_gb(value) / 1024.0f; }
+12 -12
src/util.hpp
··· 11 11 class util { 12 12 public: 13 13 static char const * stringify_glenum(GLenum thing); 14 - static GLenum get_texture_format_from_n_components(int32 n_components); 15 - static real64 random(real64 min, real64 max); 14 + static GLenum get_texture_format_from_n_components(i32 n_components); 15 + static f64 random(f64 min, f64 max); 16 16 static v3 aiVector3D_to_glm(aiVector3D *vec); 17 17 static quat aiQuaternion_to_glm(aiQuaternion *rotation); 18 18 static m4 aimatrix4x4_to_glm(aiMatrix4x4 *from); ··· 21 21 GLenum source, GLenum type, unsigned int id, GLenum severity, GLsizei length, 22 22 char const *message, const void *userParam 23 23 ); 24 - static real32 round_to_nearest_multiple(real32 n, real32 multiple_of); 25 - static real64 get_us_from_duration(chrono::duration<real64> duration); 24 + static f32 round_to_nearest_multiple(f32 n, f32 multiple_of); 25 + static f64 get_us_from_duration(chrono::duration<f64> duration); 26 26 static v3 get_orthogonal_vector(v3 *v); 27 - static uint32 kb_to_b(uint32 value); 28 - static uint32 mb_to_b(uint32 value); 29 - static uint32 gb_to_b(uint32 value); 30 - static uint32 tb_to_b(uint32 value); 31 - static real32 b_to_kb(uint32 value); 32 - static real32 b_to_mb(uint32 value); 33 - static real32 b_to_gb(uint32 value); 34 - static real32 b_to_tb(uint32 value); 27 + static u32 kb_to_b(u32 value); 28 + static u32 mb_to_b(u32 value); 29 + static u32 gb_to_b(u32 value); 30 + static u32 tb_to_b(u32 value); 31 + static f32 b_to_kb(u32 value); 32 + static f32 b_to_mb(u32 value); 33 + static f32 b_to_gb(u32 value); 34 + static f32 b_to_tb(u32 value); 35 35 };