Add skeleton for particle system
parent
b7a6c11b77
commit
7b2c48524d
|
@ -9,6 +9,9 @@
|
|||
#define MAX_NAME_LEN 32
|
||||
#define MAX_LEVEL_PACK 4
|
||||
#define N_SFX 18
|
||||
#define MAX_PARTICLE_CONF 8
|
||||
#define MAX_PARTICLE_EMITTER 16
|
||||
#define MAX_PARTICLES 10
|
||||
|
||||
#define MAX_TILE_TYPES 16
|
||||
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
#include "particle_sys.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
void init_particle_system(ParticleSystem_t* system)
|
||||
{
|
||||
memset(system, 0, sizeof(ParticleSystem_t));
|
||||
sc_queue_init(&system->free_list);
|
||||
for ( uint32_t i = 0; i < MAX_PARTICLE_EMITTER; ++i)
|
||||
{
|
||||
sc_queue_add_last(&system->free_list, i);
|
||||
}
|
||||
}
|
||||
void add_particle_emitter(ParticleSystem_t* system, ParticleEmitter_t* emitter)
|
||||
{
|
||||
if (sc_queue_empty(&system->free_list)) return;
|
||||
uint32_t idx = sc_queue_del_first(&system->free_list);
|
||||
system->emitter_list[system->tail_idx].next = idx;
|
||||
system->tail_idx = idx;
|
||||
system->emitter_list[idx].next = 0;
|
||||
system->emitters[idx] = *emitter;
|
||||
}
|
||||
void update_particle_system(ParticleSystem_t* system)
|
||||
{
|
||||
}
|
||||
void draw_particle_system(ParticleSystem_t* system)
|
||||
{
|
||||
}
|
||||
void deinit_particle_system(ParticleSystem_t* system)
|
||||
{
|
||||
sc_queue_term(&system->free_list);
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
#ifndef _PARTICLE_SYSTEM_H
|
||||
#define _PARTICLE_SYSTEM_H
|
||||
#include "raylib.h"
|
||||
#include "engine_conf.h"
|
||||
#include "sc_queue.h"
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef enum PartEmitterType
|
||||
{
|
||||
EMITTER_BURST = 0,
|
||||
} PartEmitterType_t;
|
||||
|
||||
typedef struct Particle
|
||||
{
|
||||
Texture2D* tex;
|
||||
Vector2 position;
|
||||
Vector2 velocity;
|
||||
Vector2 accleration;
|
||||
float rotation;
|
||||
bool alive;
|
||||
uint32_t timer;
|
||||
}Particle_t;
|
||||
|
||||
typedef struct EmitterConfig
|
||||
{
|
||||
Vector2 launch_range;
|
||||
Vector2 speed_range;
|
||||
Vector2 position;
|
||||
uint32_t particle_lifetime;
|
||||
Vector2 gravity;
|
||||
Vector2 friction_coeff;
|
||||
PartEmitterType_t type;
|
||||
}EmitterConfig_t;
|
||||
|
||||
typedef struct ParticleEmitter
|
||||
{
|
||||
EmitterConfig_t* config;
|
||||
Particle_t particles[MAX_PARTICLES];
|
||||
uint32_t n_particles;
|
||||
uint32_t timer;
|
||||
bool one_shot;
|
||||
bool finished;
|
||||
bool active;
|
||||
}ParticleEmitter_t;
|
||||
|
||||
typedef struct IndexList
|
||||
{
|
||||
uint32_t next;
|
||||
}IndexList_t;
|
||||
|
||||
typedef struct ParticleSystem
|
||||
{
|
||||
EmitterConfig_t emitter_configs[MAX_PARTICLE_CONF];
|
||||
ParticleEmitter_t emitters[MAX_PARTICLE_EMITTER];
|
||||
IndexList_t emitter_list[MAX_PARTICLE_EMITTER + 1];
|
||||
struct sc_queue_64 free_list;
|
||||
uint32_t tail_idx;
|
||||
uint32_t n_configs;
|
||||
uint32_t n_emitters;
|
||||
}ParticleSystem_t;
|
||||
|
||||
void init_particle_system(ParticleSystem_t* system);
|
||||
void add_particle_emitter(ParticleSystem_t* system, ParticleEmitter_t* emitter);
|
||||
void update_particle_system(ParticleSystem_t* system);
|
||||
void draw_particle_system(ParticleSystem_t* system);
|
||||
void deinit_particle_system(ParticleSystem_t* system);
|
||||
#endif // _PARTICLE_SYSTEM_H
|
|
@ -0,0 +1,23 @@
|
|||
#include "particle_sys.h"
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include "raylib.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
InitWindow(1280, 640, "raylib");
|
||||
SetTargetFPS(60);
|
||||
static ParticleSystem_t part_sys = {0
|
||||
};
|
||||
|
||||
while(!WindowShouldClose())
|
||||
{
|
||||
update_particle_system(&part_sys);
|
||||
|
||||
BeginDrawing();
|
||||
ClearBackground(RAYWHITE);
|
||||
draw_particle_system(&part_sys);
|
||||
EndDrawing();
|
||||
}
|
||||
CloseWindow();
|
||||
}
|
Loading…
Reference in New Issue