A 3D game engine from scratch.
0
fork

Configure Feed

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

refactor spatial

+69 -72
+3 -6
src/anim.cpp
··· 37 37 38 38 39 39 void 40 - anim::update_animation_components( 41 - anim::ComponentSet *animation_component_set, 42 - spatial::ComponentSet *spatial_component_set 43 - ) { 40 + anim::update_animation_components(anim::ComponentSet *animation_component_set) 41 + { 44 42 each (animation_component, animation_component_set->components) { 45 43 if (!is_animation_component_valid(animation_component)) { 46 44 continue; ··· 154 152 } 155 153 156 154 if (spatial_component->parent_entity_handle != entities::NO_ENTITY_HANDLE) { 157 - spatial::Component *parent = 158 - engine::get_spatial_component(spatial_component->parent_entity_handle); 155 + spatial::Component *parent = spatial::get_component(spatial_component->parent_entity_handle); 159 156 return find_animation_component(parent); 160 157 } 161 158
+1 -4
src/anim.hpp
··· 56 56 u32 idx_bone, 57 57 u32 idx_anim_key 58 58 ); 59 - static void update_animation_components( 60 - ComponentSet *animation_component_set, 61 - spatial::ComponentSet *spatial_component_set 62 - ); 59 + static void update_animation_components(ComponentSet *animation_component_set); 63 60 static void make_bone_matrices_for_animation_bone( 64 61 Component *animation_component, 65 62 aiNodeAnim *ai_channel,
+2 -4
src/behavior_functions.cpp
··· 8 8 void 9 9 behavior_functions::test(entities::Handle entity_handle) 10 10 { 11 - spatial::Component *spatial_component = 12 - engine::get_spatial_component(entity_handle); 11 + spatial::Component *spatial_component = spatial::get_component(entity_handle); 13 12 if (!spatial_component) { 14 13 logs::error("Could not get spatial::Component for behavior::Component"); 15 14 return; ··· 24 23 void 25 24 behavior_functions::char_movement_test(entities::Handle entity_handle) 26 25 { 27 - spatial::Component *spatial_component = 28 - engine::get_spatial_component(entity_handle); 26 + spatial::Component *spatial_component = spatial::get_component(entity_handle); 29 27 if (!spatial_component) { 30 28 logs::error("Could not get spatial::Component for behavior::Component"); 31 29 return;
+1
src/core.cpp
··· 130 130 131 131 state->asset_memory_pool = asset_memory_pool; 132 132 133 + spatial::init(&state->spatial_state, asset_memory_pool); 133 134 engine::init(&state->engine_state, asset_memory_pool); 134 135 mats::init(&state->materials_state, asset_memory_pool); 135 136 input::init(&state->input_state, state->window);
+2 -2
src/debug_ui.cpp
··· 131 131 engine::State *engine_state = engine::debug_get_engine_state(); 132 132 133 133 entities::Handle handle = entity->handle; 134 - spatial::Component *spatial_component = engine_state->spatial_component_set.components[handle]; 134 + spatial::Component *spatial_component = spatial::get_component(handle); 135 135 136 136 // Children will be drawn under their parents. 137 137 if ( ··· 191 191 if (spatial::is_spatial_component_valid(spatial_component)) { 192 192 // NOTE: This is super slow lol. 193 193 u32 n_children_found = 0; 194 - each (child_spatial_component, engine_state->spatial_component_set.components) { 194 + each (child_spatial_component, *spatial::get_components()) { 195 195 if ( 196 196 child_spatial_component->parent_entity_handle == 197 197 spatial_component->entity_handle
+10 -40
src/engine.cpp
··· 92 92 } 93 93 94 94 95 - Array<spatial::Component> * 96 - engine::get_spatial_components() 97 - { 98 - return &engine::state->spatial_component_set.components; 99 - } 100 - 101 - 102 95 Array<behavior::Component> * 103 96 engine::get_behavior_components() 104 97 { ··· 138 131 engine::get_light_component(entities::Handle entity_handle) 139 132 { 140 133 return engine::state->light_component_set.components[entity_handle]; 141 - } 142 - 143 - 144 - spatial::Component * 145 - engine::get_spatial_component(entities::Handle entity_handle) 146 - { 147 - return engine::state->spatial_component_set.components[entity_handle]; 148 134 } 149 135 150 136 ··· 233 219 void engine::init(engine::State *engine_state, memory::Pool *asset_memory_pool) { 234 220 engine::state = engine_state; 235 221 engine::state->model_loaders = Array<models::ModelLoader>( 236 - asset_memory_pool, MAX_N_MODELS, "model_loaders" 237 - ); 222 + asset_memory_pool, MAX_N_MODELS, "model_loaders"); 238 223 engine::state->entity_loader_set = { 239 224 .loaders = Array<models::EntityLoader>( 240 - asset_memory_pool, MAX_N_ENTITIES, "entity_loaders", true, 1 241 - ) 225 + asset_memory_pool, MAX_N_ENTITIES, "entity_loaders", true, 1) 242 226 }; 243 227 engine::state->entity_set = { 244 228 .entities = Array<entities::Entity>( 245 - asset_memory_pool, MAX_N_ENTITIES, "entities", true, 1 246 - ) 229 + asset_memory_pool, MAX_N_ENTITIES, "entities", true, 1) 247 230 }; 248 231 engine::state->drawable_component_set = { 249 232 .components = Array<drawable::Component>( 250 - asset_memory_pool, MAX_N_ENTITIES, "drawable_components", true, 1 251 - ) 233 + asset_memory_pool, MAX_N_ENTITIES, "drawable_components", true, 1) 252 234 }; 253 235 engine::state->light_component_set = { 254 236 .components = Array<lights::Component>( 255 - asset_memory_pool, MAX_N_ENTITIES, "light_components", true, 1 256 - ) 257 - }; 258 - engine::state->spatial_component_set = { 259 - .components = Array<spatial::Component>( 260 - asset_memory_pool, MAX_N_ENTITIES, "spatial_components", true, 1 261 - ) 237 + asset_memory_pool, MAX_N_ENTITIES, "light_components", true, 1) 262 238 }; 263 239 engine::state->behavior_component_set = { 264 240 .components = Array<behavior::Component>( 265 - asset_memory_pool, MAX_N_ENTITIES, "behavior_components", true, 1 266 - ) 241 + asset_memory_pool, MAX_N_ENTITIES, "behavior_components", true, 1) 267 242 }; 268 243 engine::state->animation_component_set = { 269 244 .components = Array<anim::Component>( 270 - asset_memory_pool, MAX_N_ENTITIES, "animation_components", true, 1 271 - ) 245 + asset_memory_pool, MAX_N_ENTITIES, "animation_components", true, 1) 272 246 }; 273 247 engine::state->physics_component_set = { 274 248 .components = Array<physics::Component>( 275 - asset_memory_pool, MAX_N_ENTITIES, "physics_components", true, 1 276 - ) 249 + asset_memory_pool, MAX_N_ENTITIES, "physics_components", true, 1) 277 250 }; 278 251 } 279 252 ··· 305 278 engine::state->entity_set.first_non_internal_handle); 306 279 engine::state->light_component_set.components.delete_elements_after_index( 307 280 engine::state->entity_set.first_non_internal_handle); 308 - engine::state->spatial_component_set.components.delete_elements_after_index( 281 + spatial::get_components()->delete_elements_after_index( 309 282 engine::state->entity_set.first_non_internal_handle); 310 283 engine::state->drawable_component_set.components.delete_elements_after_index( 311 284 engine::state->entity_set.first_non_internal_handle); ··· 656 629 657 630 lights::update_light_components( 658 631 &engine::state->light_component_set, 659 - &engine::state->spatial_component_set, 660 632 cameras::get_main()->position); 661 633 662 634 behavior::update_behavior_components(&engine::state->behavior_component_set); 663 635 664 - anim::update_animation_components( 665 - &engine::state->animation_component_set, 666 - &engine::state->spatial_component_set); 636 + anim::update_animation_components(&engine::state->animation_component_set); 667 637 668 638 physics::update_components(); 669 639 }
-1
src/engine.hpp
··· 61 61 entities::Set entity_set; 62 62 drawable::ComponentSet drawable_component_set; 63 63 lights::ComponentSet light_component_set; 64 - spatial::ComponentSet spatial_component_set; 65 64 behavior::ComponentSet behavior_component_set; 66 65 anim::ComponentSet animation_component_set; 67 66 physics::ComponentSet physics_component_set;
+1 -2
src/lights.cpp
··· 70 70 void 71 71 lights::update_light_components( 72 72 lights::ComponentSet *light_component_set, 73 - spatial::ComponentSet *spatial_component_set, 74 73 v3 camera_position 75 74 ) { 76 75 each (light_component, light_component_set->components) { ··· 79 78 } 80 79 81 80 spatial::Component *spatial_component = 82 - spatial_component_set->components[light_component->entity_handle]; 81 + spatial::get_component(light_component->entity_handle); 83 82 84 83 if (!( 85 84 is_light_component_valid(light_component) &&
-1
src/lights.hpp
··· 39 39 static bool is_light_component_valid(Component *light_component); 40 40 static void update_light_components( 41 41 ComponentSet *light_component_set, 42 - spatial::ComponentSet *spatial_component_set, 43 42 v3 camera_position 44 43 ); 45 44 static void init(lights::State *state);
+2 -2
src/models.cpp
··· 82 82 return false; 83 83 } 84 84 85 - spatial::Component *spatial_component = engine::get_spatial_component(entity_loader->entity_handle); 85 + spatial::Component *spatial_component = spatial::get_component(entity_loader->entity_handle); 86 86 *spatial_component = entity_loader->spatial_component; 87 87 spatial_component->entity_handle = entity_loader->entity_handle; 88 88 ··· 118 118 entities::Entity *child_entity = entities::add_entity_to_set(entity_loader->name); 119 119 120 120 if (spatial::is_spatial_component_valid(&entity_loader->spatial_component)) { 121 - spatial::Component *child_spatial_component = engine::get_spatial_component(child_entity->handle); 121 + spatial::Component *child_spatial_component = spatial::get_component(child_entity->handle); 122 122 assert(child_spatial_component); 123 123 *child_spatial_component = { 124 124 .entity_handle = child_entity->handle,
+2 -4
src/physics.cpp
··· 45 45 if (!is_component_valid(candidate_physics)) { 46 46 continue; 47 47 } 48 - spatial::Component *candidate_spatial = 49 - engine::get_spatial_component(candidate_physics->entity_handle); 48 + spatial::Component *candidate_spatial = spatial::get_component(candidate_physics->entity_handle); 50 49 if (!candidate_spatial) { 51 50 logs::error("Could not get spatial::Component for candidate"); 52 51 return physics::CollisionManifold {}; ··· 76 75 continue; 77 76 } 78 77 79 - spatial::Component *spatial_component = 80 - engine::get_spatial_component(physics_component->entity_handle); 78 + spatial::Component *spatial_component = spatial::get_component(physics_component->entity_handle); 81 79 82 80 if (!spatial::is_spatial_component_valid(spatial_component)) { 83 81 logs::warning("Tried to update physics component but it had no spatial component.");
+4 -5
src/renderer.cpp
··· 294 294 } 295 295 296 296 spatial::Component *spatial_component = 297 - engine::get_spatial_component(light_component->entity_handle); 297 + spatial::get_component(light_component->entity_handle); 298 298 299 299 if (!( 300 300 lights::is_light_component_valid(light_component) && ··· 350 350 } 351 351 352 352 spatial::Component *spatial_component = 353 - engine::get_spatial_component(light_component->entity_handle); 353 + spatial::get_component(light_component->entity_handle); 354 354 355 355 if (!( 356 356 lights::is_light_component_valid(light_component) && ··· 1177 1177 } 1178 1178 1179 1179 spatial::Component *spatial_component = 1180 - engine::get_spatial_component(light_component->entity_handle); 1180 + spatial::get_component(light_component->entity_handle); 1181 1181 1182 1182 if (!( 1183 1183 lights::is_light_component_valid(light_component) && ··· 1313 1313 material = mats::get_material_by_name("unknown"); 1314 1314 } 1315 1315 1316 - spatial::Component *spatial_component = 1317 - engine::get_spatial_component(drawable_component->entity_handle); 1316 + spatial::Component *spatial_component = spatial::get_component(drawable_component->entity_handle); 1318 1317 1319 1318 m4 model_matrix = m4(1.0f); 1320 1319 m3 model_normal_matrix = m3(1.0f);
+30 -1
src/spatial.cpp
··· 5 5 #include "engine.hpp" 6 6 7 7 8 + spatial::State *spatial::state = nullptr; 9 + 10 + 8 11 void 9 12 spatial::print_spatial_component(spatial::Component *spatial_component) 10 13 { ··· 48 51 m4 model_matrix = m4(1.0f); 49 52 50 53 if (spatial_component->parent_entity_handle != entities::NO_ENTITY_HANDLE) { 51 - spatial::Component *parent = engine::get_spatial_component( 54 + spatial::Component *parent = spatial::get_component( 52 55 spatial_component->parent_entity_handle); 53 56 model_matrix = make_model_matrix(parent, cache); 54 57 } ··· 72 75 73 76 return model_matrix; 74 77 } 78 + 79 + 80 + Array<spatial::Component> * 81 + spatial::get_components() 82 + { 83 + return &spatial::state->component_set.components; 84 + } 85 + 86 + 87 + spatial::Component * 88 + spatial::get_component(entities::Handle entity_handle) 89 + { 90 + return spatial::state->component_set.components[entity_handle]; 91 + } 92 + 93 + 94 + void 95 + spatial::init(spatial::State *spatial_state, memory::Pool *asset_memory_pool) 96 + { 97 + spatial::state = spatial_state; 98 + spatial::state->component_set = { 99 + .components = Array<spatial::Component>( 100 + asset_memory_pool, MAX_N_ENTITIES, "spatial_components", true, 1 101 + ) 102 + }; 103 + }
+10
src/spatial.hpp
··· 42 42 Array<Component> components; 43 43 }; 44 44 45 + struct State { 46 + ComponentSet component_set; 47 + }; 48 + 45 49 46 50 static void print_spatial_component(Component *spatial_component); 47 51 static bool does_spatial_component_have_dimensions(Component *spatial_component); ··· 50 54 Component *spatial_component, 51 55 ModelMatrixCache *cache 52 56 ); 57 + static Array<spatial::Component> * get_components(); 58 + static spatial::Component * get_component(entities::Handle entity_handle); 59 + static void init(spatial::State *spatial_state, memory::Pool *asset_memory_pool); 60 + 61 + private: 62 + static spatial::State *state; 53 63 };
+1
src/state.hpp
··· 22 22 struct State { 23 23 GLFWwindow *window; 24 24 WindowSize window_size; 25 + spatial::State spatial_state; 25 26 engine::State engine_state; 26 27 renderer::State renderer_state; 27 28 cameras::State cameras_state;