power_play/src/sim_step.h
2025-02-22 23:20:42 -06:00

83 lines
2.1 KiB
C

#ifndef SIM_STEP_H
#define SIM_STEP_H
struct space;
struct sim_snapshot;
struct sim_snapshot_list;
struct sim_lookup;
/* ========================== *
* Sim lookup
* ========================== */
/* Structure used to accelerate up entity lookup (rebuilt every step) */
/* TODO: Remove this and do something better. Just a hack to de-couple old sim ctx from step. */
struct sim_lookup_key {
u64 hash;
};
struct sim_lookup_entry {
struct sim_lookup_key key;
struct sim_ent_handle ent;
struct sim_lookup_entry *next;
struct sim_lookup_entry *prev;
};
struct sim_lookup_bucket {
struct sim_lookup_entry *first;
struct sim_lookup_entry *last;
};
struct sim_lookup {
struct arena arena;
struct sim_lookup_bucket *buckets;
u64 num_buckets;
struct sim_lookup_entry *first_free_entry;
};
struct sim_lookup sim_lookup_alloc(u64 num_buckets);
void sim_lookup_release(struct sim_lookup *l);
void sim_lookup_reset(struct sim_lookup *l);
struct sim_lookup_entry *sim_lookup_get(struct sim_lookup *l, struct sim_lookup_key key);
void sim_lookup_set(struct sim_lookup *l, struct sim_lookup_key key, struct sim_ent_handle handle);
void sim_lookup_remove(struct sim_lookup *l, struct sim_lookup_entry *entry);
struct sim_lookup_key sim_lookup_key_from_two_handles(struct sim_ent_handle h0, struct sim_ent_handle h1);
/* ========================== *
* Sim accel
* ========================== */
/* Structure used to accelerate up entity lookup (rebuilt every step) */
/* TODO: Remove this and do something better. Just a hack to de-couple old sim ctx from step. */
struct sim_accel {
struct space *space;
struct sim_lookup contact_lookup;
#if COLLIDER_DEBUG
struct sim_lookup collision_debug_lookup;
#endif
};
struct sim_accel sim_accel_alloc(void);
void sim_accel_release(struct sim_accel *accel);
void sim_accel_rebuild(struct sim_snapshot *ss, struct sim_accel *accel);
/* ========================== *
* Sim step
* ========================== */
struct sim_step_ctx {
b32 is_master;
struct sim_accel *accel;
struct sim_snapshot *world;
i64 sim_dt_ns;
};
void sim_step(struct sim_step_ctx *ctx);
#endif