Compare commits

..

No commits in common. "911663b51f6eb67218efcb226c8fbe219b9a6930" and "8ae999ccc8869df424dd8d7c7afef18f1def6988" have entirely different histories.

13 changed files with 32 additions and 195 deletions

View File

@ -26,7 +26,6 @@ typedef enum ComponentEnum {
CLIFETIMER_T,
CWATERRUNNER_T,
CAIRTIMER_T,
CEMITTER_T,
} ComponentEnum_t;
typedef enum MovementMode {
@ -216,13 +215,6 @@ typedef struct _CMoveable_t {
bool gridmove;
} CMoveable_t;
typedef uint16_t EmitterHandle;
typedef struct _CEmitter_t
{
EmitterHandle handle;
Vector2 offset;
} CEmitter_t;
static inline void set_bbox(CBBox_t* p_bbox, unsigned int x, unsigned int y)
{
p_bbox->size.x = x;

View File

@ -17,6 +17,6 @@
#define MAX_TILE_TYPES 16
#define N_TAGS 10
#define N_COMPONENTS 15
#define N_COMPONENTS 14
#define MAX_COMP_POOL_SIZE 1024
#endif // _ENGINE_CONF_H

View File

@ -77,7 +77,6 @@ static CMoveable_t cmoveable_buffer[MAX_COMP_POOL_SIZE];
static CLifeTimer_t clifetimer_buffer[MAX_COMP_POOL_SIZE];
static CWaterRunner_t cwaterrunner_buffer[32];
static CAirTimer_t cairtimer_buffer[8]; // Only player is expected to have this
static CEmitter_t cemitter_buffer[MAX_COMP_POOL_SIZE]; // Only player is expected to have this
// Static allocate mempools
static MemPool_t comp_mempools[N_COMPONENTS] = {
@ -95,7 +94,6 @@ static MemPool_t comp_mempools[N_COMPONENTS] = {
{clifetimer_buffer, MAX_COMP_POOL_SIZE, sizeof(CLifeTimer_t), NULL, {0}},
{cwaterrunner_buffer, 32, sizeof(CWaterRunner_t), NULL, {0}},
{cairtimer_buffer, 8, sizeof(CAirTimer_t), NULL, {0}},
{cemitter_buffer, MAX_COMP_POOL_SIZE, sizeof(CEmitter_t), NULL, {0}},
};
static MemPool_t ent_mempool = {
.buffer = entity_buffer,

View File

@ -103,7 +103,7 @@ void play_emitter_handle(ParticleSystem_t* system, uint16_t handle)
// An emitter cannot be unloaded or paused mid-way when particles to still
// emitting, so defer into update function to do so
void stop_emitter_handle(ParticleSystem_t* system, EmitterHandle handle)
void pause_emitter_handle(ParticleSystem_t* system, uint16_t handle)
{
if (handle == 0) return;
//if (!system->emitter_list[handle].playing) return;
@ -118,7 +118,7 @@ void update_emitter_handle_position(ParticleSystem_t* system, EmitterHandle hand
system->emitters[handle].position = pos;
}
void unload_emitter_handle(ParticleSystem_t* system, EmitterHandle handle)
void unload_emitter_handle(ParticleSystem_t* system, uint16_t handle)
{
if (handle == 0) return;
@ -126,20 +126,12 @@ void unload_emitter_handle(ParticleSystem_t* system, EmitterHandle handle)
system->emitters[handle].finished = true;
}
bool is_emitter_handle_alive(ParticleSystem_t* system, EmitterHandle handle)
void play_particle_emitter(ParticleSystem_t* system, const ParticleEmitter_t* in_emitter)
{
if (handle == 0) return false;
return system->emitters[handle].active;
}
EmitterHandle play_particle_emitter(ParticleSystem_t* system, const ParticleEmitter_t* in_emitter)
{
EmitterHandle idx = load_in_particle_emitter(system, in_emitter);
if (idx == 0) return 0 ;
uint16_t idx = load_in_particle_emitter(system, in_emitter);
if (idx == 0) return;
play_emitter_handle(system, idx);
return idx;
}
void update_particle_system(ParticleSystem_t* system)
@ -151,12 +143,6 @@ void update_particle_system(ParticleSystem_t* system)
{
ParticleEmitter_t* emitter = system->emitters + emitter_idx;
uint32_t inactive_count = 0;
if (emitter->emitter_update_func != NULL && emitter->active)
{
emitter->active = emitter->emitter_update_func(emitter);
}
for (uint32_t i = 0; i < emitter->n_particles; ++i)
{
// TODO: If a particle is not spawned, run its timer. Spawn on zero
@ -201,11 +187,10 @@ void update_particle_system(ParticleSystem_t* system)
}
}
}
if (inactive_count == emitter->n_particles)
{
// Stop playing only if all particles is inactive
if (!emitter->finished)
if (!emitter->finished && emitter->config->one_shot)
{
emitter->finished = true;
}
@ -228,7 +213,6 @@ void update_particle_system(ParticleSystem_t* system)
emitter_idx = system->emitter_list[emitter_idx].next;
}
}
void draw_particle_system(ParticleSystem_t* system)
{
uint32_t emitter_idx = system->emitter_list[0].next;

View File

@ -7,6 +7,8 @@
#include <stdint.h>
#include <stdbool.h>
typedef uint16_t EmitterHandle;
typedef enum PartEmitterType
{
EMITTER_UNKNOWN = 0,
@ -27,10 +29,7 @@ typedef struct Particle
bool spawned;
}Particle_t;
typedef struct ParticleEmitter ParticleEmitter_t;
typedef void (*particle_update_func_t)(Particle_t* part, void* user_data);
typedef bool (*emitter_check_func_t)(const ParticleEmitter_t* emitter);
typedef struct EmitterConfig
{
@ -42,7 +41,7 @@ typedef struct EmitterConfig
bool one_shot;
}EmitterConfig_t;
struct ParticleEmitter
typedef struct ParticleEmitter
{
const EmitterConfig_t* config;
Sprite_t* spr;
@ -54,8 +53,7 @@ struct ParticleEmitter
bool active;
void* user_data;
particle_update_func_t update_func;
emitter_check_func_t emitter_update_func;
};
}ParticleEmitter_t;
typedef struct IndexList
{
@ -77,14 +75,13 @@ void init_particle_system(ParticleSystem_t* system);
uint16_t get_number_of_free_emitter(ParticleSystem_t* system);
// For one-shots
EmitterHandle play_particle_emitter(ParticleSystem_t* system, const ParticleEmitter_t* in_emitter);
void play_particle_emitter(ParticleSystem_t* system, const ParticleEmitter_t* in_emitter);
EmitterHandle load_in_particle_emitter(ParticleSystem_t* system, const ParticleEmitter_t* in_emitter);
void play_emitter_handle(ParticleSystem_t* system, EmitterHandle handle);
void stop_emitter_handle(ParticleSystem_t* system, EmitterHandle handle);
void pause_emitter_handle(ParticleSystem_t* system, EmitterHandle handle);
void update_emitter_handle_position(ParticleSystem_t* system, EmitterHandle handle, Vector2 pos);
void unload_emitter_handle(ParticleSystem_t* system, EmitterHandle handle);
bool is_emitter_handle_alive(ParticleSystem_t* system, EmitterHandle handle);
void update_particle_system(ParticleSystem_t* system);
void draw_particle_system(ParticleSystem_t* system);

View File

@ -45,12 +45,6 @@ void simple_particle_system_update(Particle_t* part, void* user_data)
}
}
}
static bool check_mouse_click(const ParticleEmitter_t* emitter)
{
return IsMouseButtonDown(MOUSE_RIGHT_BUTTON);
}
int main(void)
{
InitWindow(1280, 640, "raylib");
@ -82,14 +76,12 @@ int main(void)
.config = &conf,
.n_particles = MAX_PARTICLES,
.update_func = &simple_particle_system_update,
.emitter_update_func = NULL,
.spr = (tex.width == 0) ? NULL : &spr,
};
EmitterConfig_t conf2 ={
.one_shot = false,
.launch_range = {45, 135},
//.launch_range = {0, 360},
.speed_range = {300, 800},
.particle_lifetime = {15, 30},
.initial_spawn_delay = 5,
@ -100,14 +92,15 @@ int main(void)
.config = &conf2,
.n_particles = MAX_PARTICLES,
.update_func = &simple_particle_system_update,
.emitter_update_func = &check_mouse_click,
.spr = (tex.width == 0) ? NULL : &spr,
};
EmitterHandle han = load_in_particle_emitter(&part_sys, &emitter2);
assert(han != 0);
bool key_press = false;
uint8_t key2_press = 0;
char text_buffer[32];
EmitterHandle han = 0;
while(!WindowShouldClose())
{
Vector2 mouse_pos = GetMousePosition();
@ -128,8 +121,8 @@ int main(void)
if (key2_press == 0b01)
{
emitter2.position = mouse_pos;
han = play_particle_emitter(&part_sys, &emitter2);
update_emitter_handle_position(&part_sys, han, mouse_pos);
play_emitter_handle(&part_sys, han);
}
else if(key2_press == 0b11)
{
@ -137,8 +130,7 @@ int main(void)
}
else if (key2_press == 0b10)
{
stop_emitter_handle(&part_sys, han);
han = 0;
pause_emitter_handle(&part_sys, han);
}
update_particle_system(&part_sys);

View File

@ -41,28 +41,20 @@ static bool parse_emitter_info(char* emitter_info_str, EmitterConfig_t* conf)
char emitter_type;
uint8_t one_shot;
int data_count = sscanf(
emitter_info_str, "%c,%f-%f,%f-%f,%u-%u,%u,%c",
emitter_info_str, "%c,%f-%f,%f-%f,%u-%u,%c",
&emitter_type,
conf->launch_range, conf->launch_range + 1,
conf->speed_range, conf->speed_range + 1,
conf->particle_lifetime, conf->particle_lifetime + 1,
&conf->initial_spawn_delay, &one_shot
&one_shot
);
if (data_count == 9)
if (data_count == 8)
{
conf->type = EMITTER_UNKNOWN;
if (emitter_type == 'b')
{
conf->type = EMITTER_BURST;
}
else if (emitter_type == 's')
{
conf->type = EMITTER_STREAM;
}
conf->type = (emitter_type == 'b') ? EMITTER_BURST : EMITTER_UNKNOWN;
conf->one_shot = (one_shot == '1');
}
return data_count == 9;
return data_count == 8;
}
static inline AssetInfoType_t get_asset_type(const char* str)

View File

@ -171,10 +171,6 @@ static void level_scene_render_func(Scene_t* scene)
sprintf(buffer, "FPS: %u", GetFPS());
DrawText(buffer, gui_x, gui_y, 12, BLACK);
gui_y += 30;
sprintf(buffer, "part sys free: %u", get_number_of_free_emitter(&scene->part_sys));
DrawText(buffer, gui_x, gui_y, 12, BLACK);
gui_y += 30;
print_mempool_stats(buffer);
DrawText(buffer, gui_x, gui_y, 12, BLACK);
@ -1026,7 +1022,6 @@ void init_sandbox_scene(LevelScene_t* scene)
sc_array_add(&scene->scene.systems, &spike_collision_system);
sc_array_add(&scene->scene.systems, &edge_velocity_check_system);
sc_array_add(&scene->scene.systems, &state_transition_update_system);
sc_array_add(&scene->scene.systems, &update_entity_emitter_system);
sc_array_add(&scene->scene.systems, &player_ground_air_transition_system);
sc_array_add(&scene->scene.systems, &lifetimer_update_system);
sc_array_add(&scene->scene.systems, &airtimer_update_system);

View File

@ -378,7 +378,6 @@ void init_game_scene(LevelScene_t* scene)
sc_array_add(&scene->scene.systems, &spike_collision_system);
sc_array_add(&scene->scene.systems, &edge_velocity_check_system);
sc_array_add(&scene->scene.systems, &state_transition_update_system);
sc_array_add(&scene->scene.systems, &update_entity_emitter_system);
sc_array_add(&scene->scene.systems, &player_ground_air_transition_system);
sc_array_add(&scene->scene.systems, &lifetimer_update_system);
sc_array_add(&scene->scene.systems, &airtimer_update_system);

View File

@ -7,8 +7,6 @@
#include <stdio.h>
void simple_particle_system_update(Particle_t* part, void* user_data);
void floating_particle_system_update(Particle_t* part, void* user_data);
bool check_in_water(const ParticleEmitter_t* emitter);
static const Vector2 GRAVITY = {0, GRAV_ACCEL};
static const Vector2 UPTHRUST = {0, -GRAV_ACCEL * 1.1};
@ -1471,47 +1469,8 @@ void state_transition_update_system(Scene_t* scene)
.n_particles = 5,
.user_data = &(CONTAINER_OF(scene, LevelScene_t, scene)->data),
.update_func = &simple_particle_system_update,
.emitter_update_func = NULL,
};
play_particle_emitter(&scene->part_sys, &emitter);
}
if (p_mstate->water_state & 1)
{
CEmitter_t* p_emitter = get_component(p_ent, CEMITTER_T);
if (p_emitter != NULL)
{
if (!is_emitter_handle_alive(&scene->part_sys, p_emitter->handle))
{
ParticleEmitter_t emitter = {
.spr = get_sprite(&scene->engine->assets, "p_water"),
.config = get_emitter_conf(&scene->engine->assets, "pe_bubbling"),
.position = p_ctransform->position,
.n_particles = 5,
.user_data = &(CONTAINER_OF(scene, LevelScene_t, scene)->data),
.update_func = &floating_particle_system_update,
.emitter_update_func = &check_in_water,
};
p_emitter->handle = play_particle_emitter(&scene->part_sys, &emitter);
}
}
}
}
}
void update_entity_emitter_system(Scene_t* scene)
{
CEmitter_t* p_emitter;
unsigned long ent_idx;
sc_map_foreach(&scene->ent_manager.component_map[CEMITTER_T], ent_idx, p_emitter)
{
Entity_t* p_ent = get_entity(&scene->ent_manager, ent_idx);
CTransform_t* p_ctransform = get_component(p_ent, CTRANSFORM_COMP_T);
CBBox_t* p_bbox = get_component(p_ent, CBBOX_COMP_T);
if (is_emitter_handle_alive(&scene->part_sys, p_emitter->handle))
{
update_emitter_handle_position(&scene->part_sys, p_emitter->handle, p_ctransform->position);
}
}
}
@ -2108,30 +2067,6 @@ void level_end_detection_system(Scene_t* scene)
}
}
static inline bool is_point_in_water(Vector2 pos, TileGrid_t tilemap)
{
unsigned int tile_idx = get_tile_idx(
pos.x,
pos.y,
tilemap.width
);
int tile_x = tile_idx % tilemap.width;
int tile_y = tile_idx / tilemap.width;
uint32_t water_height = tilemap.tiles[tile_idx].water_level * WATER_BBOX_STEP;
Vector2 tl = {tile_x * tilemap.tile_size, (tile_y + 1) * tilemap.tile_size - water_height};
return point_in_AABB(
pos,
(Rectangle){tl.x, tl.y, tilemap.tile_size, water_height}
);
}
bool check_in_water(const ParticleEmitter_t* emitter)
{
LevelSceneData_t* lvl_data = (LevelSceneData_t*)emitter->user_data;
TileGrid_t tilemap = lvl_data->tilemap;
return is_point_in_water(emitter->position, tilemap);
}
void simple_particle_system_update(Particle_t* part, void* user_data)
{
LevelSceneData_t* lvl_data = (LevelSceneData_t*)user_data;
@ -2158,53 +2093,18 @@ void simple_particle_system_update(Particle_t* part, void* user_data)
Vector2Scale(part->velocity, delta_time)
);
Vector2 center = Vector2AddValue(
part->position,
part->size / 2
);
// Level boundary collision
unsigned int level_width = tilemap.width * TILE_SIZE;
unsigned int level_height = tilemap.height * TILE_SIZE;
{
if(
center.x < 0 || center.x + part->size > level_width
|| center.y < 0 || center.y + part->size > level_height
part->position.x < 0 || part->position.x + part->size > level_width
|| part->position.y < 0 || part->position.y + part->size > level_height
)
{
part->timer = 0;
}
}
void floating_particle_system_update(Particle_t* part, void* user_data)
{
LevelSceneData_t* lvl_data = (LevelSceneData_t*)user_data;
TileGrid_t tilemap = lvl_data->tilemap;
float delta_time = DELTA_T; // TODO: Will need to think about delta time handling
part->position = Vector2Add(
part->position,
Vector2Scale(part->velocity, delta_time)
);
Vector2 center = Vector2AddValue(
part->position,
part->size / 2
);
// Level boundary collision
unsigned int level_width = tilemap.width * TILE_SIZE;
unsigned int level_height = tilemap.height * TILE_SIZE;
if(
center.x < 0 || center.x + part->size > level_width
|| center.y < 0 || center.y + part->size > level_height
)
{
part->timer = 0;
}
center.y = part->position.y;
if (!is_point_in_water(center, tilemap))
{
part->timer = 0;
}
}

View File

@ -13,7 +13,6 @@ void global_external_forces_system(Scene_t* scene);
void movement_update_system(Scene_t* scene);
void player_ground_air_transition_system(Scene_t* scene);
void state_transition_update_system(Scene_t* scene);
void update_entity_emitter_system(Scene_t* scene);
void update_tilemap_system(Scene_t* scene);
void hitbox_update_system(Scene_t* scene);
void edge_velocity_check_system(Scene_t* scene);

View File

@ -183,15 +183,6 @@ Entity_t* create_bomb(EntityManager_t* ent_manager, Vector2 launch_dir)
p_ctransform->position.y += (TILE_SIZE - 25) / 2;
p_ctransform->velocity = Vector2Scale(Vector2Normalize(launch_dir), 500);
if (launch_dir.x > 0)
{
p_ctransform->position.x += TILE_SIZE/ 2;
}
else if (launch_dir.x < 0)
{
p_ctransform->position.x -= TILE_SIZE / 2;
}
return p_bomb;
}

View File

@ -105,8 +105,6 @@ Entity_t* create_player(EntityManager_t* ent_manager)
p_cspr->sprites = player_sprite_map;
p_cspr->transition_func = &player_sprite_transition_func;
add_component(p_ent, CEMITTER_T);
return p_ent;
}