~vladh/peony

a1736d238653d521aad4faeb27f9c53ee3b1855d — Vlad-Stefan Harbuz 1 year, 7 months ago 6f7df3f
refactor anim state
M src/anim.cpp => src/anim.cpp +22 -7
@@ 37,9 37,9 @@ anim::get_bone_matrix(u32 idx, u32 idx_bone, u32 idx_anim_key)


void
anim::update_animation_components(anim::ComponentSet *animation_component_set)
anim::update()
{
    each (animation_component, animation_component_set->components) {
    each (animation_component, *get_components()) {
        if (!is_animation_component_valid(animation_component)) {
            continue;
        }


@@ 144,8 144,7 @@ anim::make_bone_matrices_for_animation_bone(
anim::Component *
anim::find_animation_component(spatial::Component *spatial_component)
{
    anim::Component *animation_component =
        engine::get_animation_component(spatial_component->entity_handle);
    anim::Component *animation_component = get_component(spatial_component->entity_handle);

    if (is_animation_component_valid(animation_component)) {
        return animation_component;


@@ 160,16 159,32 @@ anim::find_animation_component(spatial::Component *spatial_component)
}


Array<anim::Component> *
anim::get_components()
{
    return &anim::state->components;
}


anim::Component *
anim::get_component(entities::Handle entity_handle)
{
    return anim::state->components[entity_handle];
}


void
anim::init(anim::State *anim_state, memory::Pool *pool)
anim::init(anim::State *anim_state, memory::Pool *asset_memory_pool)
{
    anim::state = anim_state;
    anim::state->bone_matrix_pool.bone_matrices = Array<m4>(pool,
    anim::state->bone_matrix_pool.bone_matrices = Array<m4>(asset_memory_pool,
        MAX_N_ANIMATED_MODELS * MAX_N_BONES * MAX_N_ANIMATIONS * MAX_N_ANIM_KEYS,
        "bone_matrices", true);
    anim::state->bone_matrix_pool.times = Array<f64>(pool,
    anim::state->bone_matrix_pool.times = Array<f64>(asset_memory_pool,
        MAX_N_ANIMATED_MODELS * MAX_N_BONES * MAX_N_ANIMATIONS * MAX_N_ANIM_KEYS,
        "bone_matrix_times", true);
    anim::state->components =  Array<anim::Component>(
        asset_memory_pool, MAX_N_ENTITIES, "animation_components", true, 1);
}



M src/anim.hpp => src/anim.hpp +4 -5
@@ 41,11 41,8 @@ public:
        u32 n_animations;
    };

    struct ComponentSet {
        Array<Component> components;
    };

    struct State {
        Array<Component> components;
        BoneMatrixPool bone_matrix_pool;
    };



@@ 56,7 53,7 @@ public:
        u32 idx_bone,
        u32 idx_anim_key
    );
    static void update_animation_components(ComponentSet *animation_component_set);
    static void update();
    static void make_bone_matrices_for_animation_bone(
        Component *animation_component,
        aiNodeAnim *ai_channel,


@@ 64,6 61,8 @@ public:
        u32 idx_bone
    );
    static Component * find_animation_component(spatial::Component *spatial_component);
    static Array<anim::Component> * get_components();
    static anim::Component * get_component(entities::Handle entity_handle);
    static void init(anim::State *anim_state, memory::Pool *pool);

private:

M src/behavior.cpp => src/behavior.cpp +1 -1
@@ 57,7 57,7 @@ behavior::is_behavior_component_valid(behavior::Component *behavior_component)


void
behavior::update_behavior_components()
behavior::update()
{
    each (behavior_component, *get_components()) {
        if (!is_behavior_component_valid(behavior_component)) {

M src/behavior.hpp => src/behavior.hpp +1 -1
@@ 36,7 36,7 @@ public:
    static char const * behavior_to_string(Behavior behavior);
    static Behavior behavior_from_string(const char *str);
    static bool is_behavior_component_valid(Component *behavior_component);
    static void update_behavior_components();
    static void update();
    static Array<behavior::Component> * get_components();
    static behavior::Component * get_component(entities::Handle entity_handle);
    static void init(

M src/core.cpp => src/core.cpp +1 -1
@@ 133,6 133,7 @@ core::init_state(State *state, memory::Pool *asset_memory_pool)
    spatial::init(&state->spatial_state, asset_memory_pool);
    drawable::init(&state->drawable_state, asset_memory_pool);
    lights::init(&state->lights_state, asset_memory_pool);
    anim::init(&state->anim_state, asset_memory_pool);
    behavior::init(
        &state->behavior_state,
        asset_memory_pool,


@@ 152,7 153,6 @@ core::init_state(State *state, memory::Pool *asset_memory_pool)
        state->window_size.width, state->window_size.height);
    debugdraw::init(&state->debug_draw_state, asset_memory_pool);
    tasks::init(&state->tasks_state, asset_memory_pool);
    anim::init(&state->anim_state, asset_memory_pool);
    cameras::init(&state->cameras_state, state->window_size.width, state->window_size.height);

    return true;

M src/debug_ui.cpp => src/debug_ui.cpp +1 -1
@@ 150,7 150,7 @@ debug_ui::get_entity_text_representation(char *text, entities::Entity *entity, u
    bool has_behavior_component = behavior::is_behavior_component_valid(
        behavior::get_component(handle));
    bool has_animation_component = anim::is_animation_component_valid(
        engine_state->animation_component_set.components[handle]);
        anim::get_component(handle));

    for (u8 level = 0; level < depth; level++) {
        strcat(text, "  ");

M src/engine.cpp => src/engine.cpp +5 -26
@@ 64,13 64,6 @@ engine::get_entities()
}


Array<anim::Component> *
engine::get_animation_components()
{
    return &engine::state->animation_component_set.components;
}


Array<physics::Component> *
engine::get_physics_components()
{


@@ 85,13 78,6 @@ engine::get_entity(entities::Handle entity_handle)
}


anim::Component *
engine::get_animation_component(entities::Handle entity_handle)
{
    return engine::state->animation_component_set.components[entity_handle];
}


physics::Component *
engine::get_physics_component(entities::Handle entity_handle)
{


@@ 172,10 158,6 @@ void engine::init(engine::State *engine_state, memory::Pool *asset_memory_pool) 
        .entities = Array<entities::Entity>(
            asset_memory_pool, MAX_N_ENTITIES, "entities", true, 1)
    };
    engine::state->animation_component_set = {
        .components = Array<anim::Component>(
            asset_memory_pool, MAX_N_ENTITIES, "animation_components", true, 1)
    };
    engine::state->physics_component_set = {
        .components = Array<physics::Component>(
            asset_memory_pool, MAX_N_ENTITIES, "physics_components", true, 1)


@@ 215,7 197,7 @@ engine::destroy_non_internal_entities()
        engine::state->entity_set.first_non_internal_handle);
    behavior::get_components()->delete_elements_after_index(
        engine::state->entity_set.first_non_internal_handle);
    engine::state->animation_component_set.components.delete_elements_after_index(
    anim::get_components()->delete_elements_after_index(
        engine::state->entity_set.first_non_internal_handle);
}



@@ 558,13 540,10 @@ engine::update()

    engine::state->is_world_loaded = check_all_entities_loaded();

    lights::update_light_components(cameras::get_main()->position);

    behavior::update_behavior_components();

    anim::update_animation_components(&engine::state->animation_component_set);

    physics::update_components();
    lights::update(cameras::get_main()->position);
    behavior::update();
    anim::update();
    physics::update();
}



M src/engine.hpp => src/engine.hpp +0 -3
@@ 58,7 58,6 @@ public:
        Array<models::ModelLoader> model_loaders;
        models::EntityLoaderSet entity_loader_set;
        entities::Set entity_set;
        anim::ComponentSet animation_component_set;
        physics::ComponentSet physics_component_set;
    };



@@ 68,10 67,8 @@ public:
    static void mark_first_non_internal_handle();
    static entities::Set * get_entity_set();
    static Array<entities::Entity> * get_entities();
    static Array<anim::Component> * get_animation_components();
    static Array<physics::Component> * get_physics_components();
    static entities::Entity * get_entity(entities::Handle entity_handle);
    static anim::Component * get_animation_component(entities::Handle entity_handle);
    static physics::Component * get_physics_component(entities::Handle entity_handle);
    static f64 get_t();
    static f64 get_dt();

M src/lights.cpp => src/lights.cpp +1 -1
@@ 68,7 68,7 @@ lights::is_light_component_valid(lights::Component *light_component)


void
lights::update_light_components(v3 camera_position)
lights::update(v3 camera_position)
{
    each (light_component, *get_components()) {
        if (light_component->entity_handle == entities::NO_ENTITY_HANDLE) {

M src/lights.hpp => src/lights.hpp +1 -1
@@ 34,7 34,7 @@ public:
    static LightType light_type_from_string(const char *str);
    static u32 light_type_to_int(LightType light_type);
    static bool is_light_component_valid(Component *light_component);
    static void update_light_components(v3 camera_position);
    static void update(v3 camera_position);
    static Array<lights::Component> * get_components();
    static lights::Component * get_component(entities::Handle entity_handle);
    static void init(lights::State *state, memory::Pool *asset_memory_pool);

M src/models.cpp => src/models.cpp +1 -1
@@ 94,7 94,7 @@ models::prepare_entity_loader_and_check_if_done(
        *behavior_component = entity_loader->behavior_component;
        behavior_component->entity_handle = entity_loader->entity_handle;

        anim::Component *animation_component = engine::get_animation_component(entity_loader->entity_handle);
        anim::Component *animation_component = anim::get_component(entity_loader->entity_handle);
        *animation_component = model_loader->animation_component;
        animation_component->entity_handle = entity_loader->entity_handle;


M src/physics.cpp => src/physics.cpp +1 -1
@@ 68,7 68,7 @@ physics::find_collision(


void
physics::update_components()
physics::update()
{
    each (physics_component, *engine::get_physics_components()) {
        if (!is_component_valid(physics_component)) {

M src/physics.hpp => src/physics.hpp +1 -1
@@ 49,7 49,7 @@ public:
        Component *self_physics,
        spatial::Component *self_spatial
    );
    static void update_components();
    static void update();

private:
    static spatial::Obb transform_obb(spatial::Obb obb, spatial::Component *spatial);