aboutsummaryrefslogtreecommitdiffstats
path: root/src/engine
diff options
context:
space:
mode:
Diffstat (limited to 'src/engine')
-rw-r--r--src/engine/app.cpp32
-rw-r--r--src/engine/renderer.cpp8
-rw-r--r--src/engine/renderer.hpp7
3 files changed, 37 insertions, 10 deletions
diff --git a/src/engine/app.cpp b/src/engine/app.cpp
index 64b9f01..d5001c1 100644
--- a/src/engine/app.cpp
+++ b/src/engine/app.cpp
@@ -89,12 +89,14 @@ void App::run() {
// above is sky. Anything that falls into the ground is destroyed.
graph.ground_level = 1.0f;
- // Resolve each material's texture once (nullptr = draw flat colour).
+ // Resolve each material's texture once: prefer BYO Forts art, fall back to
+ // the CC0 placeholder, then to a flat colour (nullptr).
std::vector<SDL_Texture*> mat_tex(graph.materials.size(), nullptr);
for (size_t i = 0; i < graph.materials.size(); i++)
- if (!graph.materials[i].texture.empty())
- mat_tex[i] = renderer.load_texture(graph.materials[i].texture);
- SDL_Texture* ground_tex = renderer.load_texture("data/textures/ground.png");
+ mat_tex[i] = renderer.load_texture_or(graph.materials[i].texture_forts,
+ graph.materials[i].texture);
+ SDL_Texture* ground_tex = renderer.load_texture_or(
+ "forts:environment/midwest/ground/ground1.tga", "data/textures/ground.png");
// Short-lived explosion puffs spawned when debris hits the ground.
struct Explosion { float x, y, life; };
@@ -108,8 +110,16 @@ void App::run() {
if (weapons[i].name == "cannon") cannon_type = (int)i;
if (weapons[i].name == "laser") laser_type = (int)i;
}
- SDL_Texture* turret_tex = renderer.load_texture("data/textures/weapon_turret.png");
- SDL_Texture* shell_tex = renderer.load_texture("data/textures/projectile_laser.png");
+ // Per-weapon turret sprite (BYO Forts art, else CC0 placeholder).
+ std::vector<SDL_Texture*> weapon_tex(weapons.size(), nullptr);
+ for (size_t i = 0; i < weapons.size(); i++)
+ weapon_tex[i] = renderer.load_texture_or(weapons[i].texture_forts,
+ weapons[i].texture);
+ SDL_Texture* shell_tex = nullptr;
+ if (!weapons.empty())
+ shell_tex = renderer.load_texture_or(
+ weapons[cannon_type].projectile_texture_forts,
+ weapons[cannon_type].projectile_texture);
struct Cannon { float x, y, mount, aim, cooldown; int type; };
std::vector<Cannon> cannons;
@@ -127,8 +137,8 @@ void App::run() {
MapData map = load_map(script, "data");
std::vector<SDL_Texture*> dev_tex(device_defs.size(), nullptr);
for (size_t i = 0; i < device_defs.size(); i++)
- if (!device_defs[i].texture.empty())
- dev_tex[i] = renderer.load_texture(device_defs[i].texture);
+ dev_tex[i] = renderer.load_texture_or(device_defs[i].texture_forts,
+ device_defs[i].texture);
SDL_Texture* deposit_tex = renderer.load_texture("data/textures/deposit.png");
struct Device { int def, team; float x, y, hp, max_hp; bool on_deposit; };
@@ -673,8 +683,10 @@ void App::run() {
float bx = c.x + std::cos(c.aim) * bl * 0.5f;
float by = c.y + std::sin(c.aim) * bl * 0.5f;
renderer.draw_box(bx, by, bl * 0.5f, 0.12f, c.aim, 0.30f, 0.30f, 0.34f, 1.0f);
- if (turret_tex) renderer.draw_sprite(c.x, c.y, 0.5f, 0.5f, 0.0f, turret_tex);
- else renderer.draw_box(c.x, c.y, 0.5f, 0.5f, 0.0f, 0.4f, 0.4f, 0.45f, 1.0f);
+ SDL_Texture* wt = (c.type >= 0 && c.type < (int)weapon_tex.size())
+ ? weapon_tex[c.type] : nullptr;
+ if (wt) renderer.draw_sprite(c.x, c.y, 0.5f, 0.5f, 0.0f, wt);
+ else renderer.draw_box(c.x, c.y, 0.5f, 0.5f, 0.0f, 0.4f, 0.4f, 0.45f, 1.0f);
}
// Firing arc of the selected cannon (the cone of allowed directions).
diff --git a/src/engine/renderer.cpp b/src/engine/renderer.cpp
index 0ec6371..bc9bbf7 100644
--- a/src/engine/renderer.cpp
+++ b/src/engine/renderer.cpp
@@ -192,6 +192,14 @@ SDL_Texture* Renderer::load_texture(const std::string& path) {
return tex;
}
+SDL_Texture* Renderer::load_texture_or(const std::string& primary,
+ const std::string& fallback) {
+ if (!primary.empty()) {
+ if (SDL_Texture* t = load_texture(primary)) return t;
+ }
+ return fallback.empty() ? nullptr : load_texture(fallback);
+}
+
void Renderer::draw_sprite(float cx, float cy, float half_w, float half_h,
float angle, SDL_Texture* tex,
float r, float g, float b, float a) {
diff --git a/src/engine/renderer.hpp b/src/engine/renderer.hpp
index ddc8055..f5a087f 100644
--- a/src/engine/renderer.hpp
+++ b/src/engine/renderer.hpp
@@ -25,6 +25,13 @@ public:
// Load a texture (cached by path). Returns nullptr on failure.
SDL_Texture* load_texture(const std::string& path);
+ // Load `primary` if set, falling back to `fallback` if it is empty or fails
+ // to load. Used for BYO Forts art ("forts:...") that degrades to the CC0
+ // placeholder when the game is not installed. Returns nullptr if neither
+ // loads.
+ SDL_Texture* load_texture_or(const std::string& primary,
+ const std::string& fallback);
+
// Draw a textured quad in world coordinates, colour-modulated by (r,g,b,a).
void draw_sprite(float cx, float cy, float half_w, float half_h,
float angle, SDL_Texture* tex,