4 changed files with 71 additions and 56 deletions
@ -0,0 +1,35 @@ |
|||||||
|
|
||||||
|
#include "game.h" |
||||||
|
|
||||||
|
|
||||||
|
GameOrbit* |
||||||
|
getFreeOrbit(GameState* gs) |
||||||
|
{ |
||||||
|
GameOrbit* orbit = nullptr; |
||||||
|
|
||||||
|
// NOTE: first check if we have a freed orbit to use
|
||||||
|
for (u32 i = 0; i < gs->num_orbits; i++) { |
||||||
|
if (!gs->orbits[i].in_use) |
||||||
|
orbit = &gs->orbits[i]; |
||||||
|
} |
||||||
|
|
||||||
|
// NOTE: if we can't re-use a freed orbit, initialize a new one
|
||||||
|
if (!orbit) { |
||||||
|
assert(gs->num_orbits < gs->max_orbits); |
||||||
|
orbit = &gs->orbits[gs->num_orbits++]; |
||||||
|
} |
||||||
|
|
||||||
|
orbit->in_use = true; |
||||||
|
return orbit; |
||||||
|
} |
||||||
|
|
||||||
|
void |
||||||
|
disableGameOrbit(GameOrbit* orbit) |
||||||
|
{ |
||||||
|
orbit->in_use = false; |
||||||
|
orbit->selected = false; |
||||||
|
orbit->system = {0}; |
||||||
|
orbit->grav_body = nullptr; |
||||||
|
orbit->ellipse_entity = nullptr; |
||||||
|
orbit->satellite_entity = nullptr; |
||||||
|
} |
||||||
@ -0,0 +1,34 @@ |
|||||||
|
#pragma once |
||||||
|
|
||||||
|
#include "tangerine.h" |
||||||
|
#include "orbits.h" |
||||||
|
|
||||||
|
|
||||||
|
struct GameOrbit |
||||||
|
{ |
||||||
|
TwoBodySystem system; |
||||||
|
|
||||||
|
Entity* grav_body; |
||||||
|
Entity* ellipse_entity; |
||||||
|
Entity* satellite_entity; |
||||||
|
bool in_use; |
||||||
|
bool selected; |
||||||
|
}; |
||||||
|
|
||||||
|
struct GameState |
||||||
|
{ |
||||||
|
bool running; |
||||||
|
MemoryArena* arena; |
||||||
|
|
||||||
|
u64 game_time_ms; |
||||||
|
u64 sim_time_ms; |
||||||
|
float sim_speed; |
||||||
|
|
||||||
|
GameOrbit* orbits; |
||||||
|
u32 num_orbits; |
||||||
|
u32 max_orbits; |
||||||
|
}; |
||||||
|
|
||||||
|
GameOrbit* getFreeOrbit(GameState* gs); |
||||||
|
|
||||||
|
void disableGameOrbit(GameOrbit* orbit); |
||||||
Loading…
Reference in new issue