Skip to content

Commit 0913308

Browse files
committed
YAGNI: Simplify asset workflow, remove reflected factories, etc. (#33)
* [WIP] Simplify Enemy spawn flow, fix race in `Resources`. * Remove `EnemySpawner`, `EnemyFactoryBuilder`. * Remove `WorldSpec`, add `AssetManifest`. Hard-code manifest in game.cpp. * Refactor asset loading into a dedicated scene. * Remove `setup()`, can be done in constructors now. * Misc cleanup.
1 parent 4557121 commit 0913308

36 files changed

+280
-488
lines changed

assets/worlds/playground.json

Lines changed: 0 additions & 24 deletions
This file was deleted.

src/spaced/spaced/game/asset_list.cpp renamed to src/spaced/spaced/assets/asset_list.cpp

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#include <spaced/game/asset_list.hpp>
2-
#include <spaced/game/asset_loader.hpp>
1+
#include <spaced/assets/asset_list.hpp>
2+
#include <spaced/assets/asset_loader.hpp>
33
#include <spaced/services/resources.hpp>
44

55
namespace spaced {
@@ -37,31 +37,12 @@ auto AssetList::add_audio_clip(std::string uri) -> AssetList& {
3737
return *this;
3838
}
3939

40-
auto AssetList::read_world_spec(std::string_view const uri) -> WorldSpec {
41-
if (uri.empty()) { return {}; }
42-
43-
auto const json = m_loader.load_json(uri);
44-
if (!json) { return {}; }
45-
46-
auto ret = WorldSpec{};
47-
ret.name = json["name"].as_string();
48-
ret.background_tint = json["background_tint"].as_string();
49-
50-
if (auto const& player = json["player"]) {
51-
ret.player.tint = player["tint"].as_string();
52-
ret.player.exhaust_emitter = player["exhaust_emitter"].as_string();
53-
ret.player.death_emitter = player["death_emitter"].as_string();
54-
add_particle_emitter(ret.player.exhaust_emitter);
55-
add_particle_emitter(ret.player.death_emitter);
56-
}
57-
58-
for (auto const& enemy_factory : json["enemy_factories"].array_view()) {
59-
add_particle_emitter(enemy_factory["death_emitter"].as<std::string>());
60-
for (auto const& death_sfx : enemy_factory["death_sfx"].array_view()) { add_audio_clip(death_sfx.as<std::string>()); }
61-
ret.enemy_factories.push_back(enemy_factory);
62-
}
63-
64-
return ret;
40+
void AssetList::add_manifest(AssetManifest manifest) {
41+
for (auto& uri : manifest.textures) { add_texture(std::move(uri), false); }
42+
for (auto& uri : manifest.mip_mapped_textures) { add_texture(std::move(uri), true); }
43+
for (auto& uri : manifest.fonts) { add_font(std::move(uri)); }
44+
for (auto& uri : manifest.audio_clips) { add_audio_clip(std::move(uri)); }
45+
for (auto& uri : manifest.particle_emitters) { add_particle_emitter(std::move(uri)); }
6546
}
6647

6748
auto AssetList::build_task_stages() const -> std::vector<AsyncExec::Stage> {

src/spaced/spaced/game/asset_list.hpp renamed to src/spaced/spaced/assets/asset_list.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#pragma once
22
#include <bave/loader.hpp>
3+
#include <spaced/assets/asset_manifest.hpp>
34
#include <spaced/async_exec.hpp>
4-
#include <spaced/game/world_spec.hpp>
55
#include <spaced/services/services.hpp>
66
#include <set>
77

@@ -18,7 +18,7 @@ class AssetList {
1818
auto add_particle_emitter(std::string uri) -> AssetList&;
1919
auto add_audio_clip(std::string uri) -> AssetList&;
2020

21-
auto read_world_spec(std::string_view uri) -> WorldSpec;
21+
void add_manifest(AssetManifest manifest);
2222

2323
[[nodiscard]] auto build_task_stages() const -> std::vector<AsyncExec::Stage>;
2424

src/spaced/spaced/game/asset_loader.cpp renamed to src/spaced/spaced/assets/asset_loader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <bave/graphics/particle_system.hpp>
22
#include <bave/json_io.hpp>
33
#include <bave/logger.hpp>
4-
#include <spaced/game/asset_loader.hpp>
4+
#include <spaced/assets/asset_loader.hpp>
55
#include <mutex>
66

77
namespace spaced {
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#pragma once
2+
#include <string>
3+
#include <vector>
4+
5+
namespace spaced {
6+
struct AssetManifest {
7+
std::vector<std::string> textures{};
8+
std::vector<std::string> mip_mapped_textures{};
9+
std::vector<std::string> fonts{};
10+
std::vector<std::string> audio_clips{};
11+
std::vector<std::string> particle_emitters{};
12+
};
13+
} // namespace spaced

src/spaced/spaced/async_exec.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
namespace spaced {
77
using namespace std::chrono_literals;
88

9-
AsyncExec::AsyncExec(std::span<Task const> tasks) {
9+
AsyncExec::AsyncExec(std::vector<Task> tasks) {
1010
if (tasks.empty()) { return; }
1111

1212
m_total = static_cast<int>(tasks.size());
1313
enqueue(tasks);
1414
}
1515

16-
AsyncExec::AsyncExec(std::span<Stage> stages) {
16+
AsyncExec::AsyncExec(std::vector<Stage> stages) {
1717
if (stages.empty()) { return; }
1818
std::move(stages.begin(), stages.end(), std::back_inserter(m_stages));
1919
m_total = std::accumulate(m_stages.begin(), m_stages.end(), 0, [](int count, auto const& tasks) { return static_cast<int>(tasks.size()) + count; });

src/spaced/spaced/async_exec.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ class AsyncExec {
1414

1515
struct Status;
1616

17-
explicit AsyncExec(std::span<Task const> tasks);
18-
explicit AsyncExec(std::span<Stage> stages);
17+
explicit AsyncExec(std::vector<Task> tasks);
18+
explicit AsyncExec(std::vector<Stage> stages);
1919

2020
auto update() -> Status;
2121

src/spaced/spaced/game/enemies/basic_creep_factory.cpp

Lines changed: 0 additions & 54 deletions
This file was deleted.

src/spaced/spaced/game/enemies/basic_creep_factory.hpp

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)