Browse Source

break out GameOrbit and GameState to game.h

main
cinnaboot 4 years ago
parent
commit
3a8be29148
  1. 2
      Makefile
  2. 35
      src/game.cpp
  3. 34
      src/game.h
  4. 56
      src/main.cpp

2
Makefile

@ -29,7 +29,7 @@ IMGUI_SOURCES := $(filter-out $(IMGUI_DIR)/imgui_demo.cpp, $(wildcard $(IMGUI_DI
IMGUI_OBJECTS := $(patsubst $(IMGUI_DIR)/%.cpp, $(OBJDIR)/%.o, $(IMGUI_SOURCES)) IMGUI_OBJECTS := $(patsubst $(IMGUI_DIR)/%.cpp, $(OBJDIR)/%.o, $(IMGUI_SOURCES))
IMGUI_IMP_OBJECTS += $(patsubst $(IMGUI_IMPL_DIR)/%.cpp, $(OBJDIR)/%.o, $(IMGUI_IMPL_SOURCES)) IMGUI_IMP_OBJECTS += $(patsubst $(IMGUI_IMPL_DIR)/%.cpp, $(OBJDIR)/%.o, $(IMGUI_IMPL_SOURCES))
SOURCES := $(SRCDIR)/main.cpp $(SRCDIR)/gooey.cpp SOURCES := $(SRCDIR)/main.cpp $(SRCDIR)/gooey.cpp $(SRCDIR)/game.cpp
OBJECTS := $(patsubst $(SRCDIR)/%.cpp, $(OBJDIR)/%.o, $(SOURCES)) OBJECTS := $(patsubst $(SRCDIR)/%.cpp, $(OBJDIR)/%.o, $(SOURCES))
BIN := $(BINDIR)/orbital_shipping BIN := $(BINDIR)/orbital_shipping

35
src/game.cpp

@ -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;
}

34
src/game.h

@ -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);

56
src/main.cpp

@ -22,6 +22,7 @@
#include "input.h" #include "input.h"
#include "tangerine.h" #include "tangerine.h"
#include "game.h"
#include "gooey.h" #include "gooey.h"
#include "orbits.h" #include "orbits.h"
@ -32,61 +33,6 @@ const vec4 g_light_color = vec4(0.5, 0.5, 0.5, 1);
const uvec4 g_light_intensities = uvec4(1, 0, 0, 0); const uvec4 g_light_intensities = uvec4(1, 0, 0, 0);
struct GameOrbit
{
TwoBodySystem system;
Entity* grav_body;
Entity* ellipse_entity;
Entity* satellite_entity;
bool in_use;
};
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)
{
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->system = {0};
orbit->grav_body = nullptr;
orbit->ellipse_entity = nullptr;
orbit->satellite_entity = nullptr;
}
void void
initCamera(RenderState* rs, vec3 cam_pos, vec3 cam_focus, vec3 cam_up) initCamera(RenderState* rs, vec3 cam_pos, vec3 cam_focus, vec3 cam_up)
{ {

Loading…
Cancel
Save