Skip to content

Commit 00dba6a

Browse files
authored
Integrate bgf. (#46)
* Upgrade `Scene`. * Upgrade bave to v0.5.5, use `EventSink`. * Add `GameDriver`, separate screen layout from game layout. * Rename `ILayout` to `IDisplay`. * Integrate bgf. * Start using RGBA keys in styles. * Replace font.
1 parent 1450f40 commit 00dba6a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+277
-2047
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ compile_commands.json
1414
imgui.ini
1515
bave*.log
1616
/spaced
17+
/notes.txt

CMakeLists.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ set(CMAKE_CXX_EXTENSIONS OFF)
99
include(FetchContent)
1010

1111
FetchContent_Declare(
12-
bave
13-
GIT_REPOSITORY https://github.com/karnkaul/bave
14-
GIT_TAG v0.5.4
15-
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ext/bave"
12+
bgf
13+
GIT_REPOSITORY https://github.com/karnkaul/bgf
14+
GIT_TAG v0.1.0
15+
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ext/bgf"
1616
)
1717

18-
FetchContent_MakeAvailable(bave)
18+
FetchContent_MakeAvailable(bgf)
1919

2020
add_subdirectory(src)

assets/fonts/CuteDino.otf

29.3 KB
Binary file not shown.

assets/fonts/hesitation.regular.ttf

-20.8 KB
Binary file not shown.

assets/styles.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
"padding": 10
3838
},
3939
"enemy": {
40-
"background": "#f75c03ff",
41-
"fill": "#ffffffff",
40+
"background": "orange",
41+
"fill": "milk",
4242
"corner_ratio": 0.5,
4343
"padding": 5
4444
}
@@ -50,9 +50,9 @@
5050
10.000000
5151
],
5252
"corner_ratio": 0.25,
53-
"background_tint": "#e5cdaeff",
54-
"outline_tint": "#231d2aff",
55-
"content_text_tint": "#231d2aff"
53+
"background_tint": "milk",
54+
"outline_tint": "black",
55+
"content_text_tint": "black"
5656
}
5757
},
5858
"sliders": {
@@ -63,7 +63,7 @@
6363
}
6464
},
6565
"loading_screen": {
66-
"background_tint": "#231d2aff",
66+
"background_tint": "black",
6767
"spinner": {
6868
"size": [
6969
100.000000,

src/spaced/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ add_library(${PROJECT_NAME})
77
add_library(spaced::lib ALIAS ${PROJECT_NAME})
88

99
target_link_libraries(${PROJECT_NAME} PUBLIC
10-
bave::bave
10+
bave::bgf
1111
bave::bave-compile-options
1212
)
1313

@@ -19,3 +19,5 @@ target_include_directories(${PROJECT_NAME} PUBLIC
1919
file(GLOB_RECURSE sources LIST_DIRECTORIES false CONFIGURE_DEPENDS "spaced/*.?pp")
2020

2121
target_sources(${PROJECT_NAME} PRIVATE ${sources})
22+
23+
target_precompile_headers(${PROJECT_NAME} REUSE_FROM bave)

src/spaced/spaced/assets/asset_list.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
#include <bave/services/resources.hpp>
12
#include <spaced/assets/asset_list.hpp>
23
#include <spaced/assets/asset_loader.hpp>
3-
#include <spaced/services/resources.hpp>
44

55
namespace spaced {
6+
using bave::AsyncExec;
67
using bave::Loader;
8+
using bave::Resources;
9+
using bave::Services;
710

811
AssetList::AssetList(Loader loader, Services const& services) : m_loader(std::move(loader)), m_resources(&services.get<Resources>()) {}
912

src/spaced/spaced/assets/asset_list.hpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
#pragma once
2+
#include <bave/async_exec.hpp>
23
#include <bave/loader.hpp>
4+
#include <bave/services/resources.hpp>
5+
#include <bave/services/services.hpp>
36
#include <spaced/assets/asset_manifest.hpp>
4-
#include <spaced/async_exec.hpp>
5-
#include <spaced/services/services.hpp>
67
#include <set>
78

8-
namespace spaced {
9+
namespace bave {
910
struct Resources;
11+
}
12+
13+
namespace spaced {
1014
class AssetLoader;
1115

1216
class AssetList {
1317
public:
14-
explicit AssetList(bave::Loader loader, Services const& services);
18+
explicit AssetList(bave::Loader loader, bave::Services const& services);
1519

1620
auto add_texture(std::string uri, bool mip_map = false) -> AssetList&;
1721
auto add_font(std::string uri) -> AssetList&;
@@ -20,7 +24,7 @@ class AssetList {
2024

2125
void add_manifest(AssetManifest manifest);
2226

23-
[[nodiscard]] auto build_task_stages() const -> std::vector<AsyncExec::Stage>;
27+
[[nodiscard]] auto build_task_stages() const -> std::vector<bave::AsyncExec::Stage>;
2428

2529
private:
2630
struct Tex {
@@ -32,11 +36,11 @@ class AssetList {
3236
auto operator<(Tex const& rhs) const -> bool { return uri < rhs.uri; }
3337
};
3438

35-
auto build_stage_0(AssetLoader& asset_loader) const -> AsyncExec::Stage;
36-
auto build_stage_1(AssetLoader& asset_loader) const -> AsyncExec::Stage;
39+
auto build_stage_0(AssetLoader& asset_loader) const -> bave::AsyncExec::Stage;
40+
auto build_stage_1(AssetLoader& asset_loader) const -> bave::AsyncExec::Stage;
3741

3842
bave::Loader m_loader;
39-
bave::NotNull<Resources*> m_resources;
43+
bave::NotNull<bave::Resources*> m_resources;
4044

4145
std::set<Tex> m_textures{};
4246
std::set<std::string> m_fonts{};

src/spaced/spaced/assets/asset_loader.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ using bave::Loader;
99
using bave::Logger;
1010
using bave::NotNull;
1111
using bave::ParticleEmitter;
12+
using bave::Resources;
1213
using bave::Texture;
1314

1415
struct AssetLoader::Impl {

src/spaced/spaced/assets/asset_loader.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/core/ptr.hpp>
33
#include <bave/loader.hpp>
4-
#include <spaced/services/resources.hpp>
4+
#include <bave/services/resources.hpp>
55
#include <functional>
66
#include <memory>
77

@@ -10,7 +10,7 @@ class AssetLoader {
1010
public:
1111
using LoadTask = std::function<void()>;
1212

13-
explicit AssetLoader(bave::Loader loader, bave::NotNull<Resources*> resources);
13+
explicit AssetLoader(bave::Loader loader, bave::NotNull<bave::Resources*> resources);
1414

1515
[[nodiscard]] auto make_load_font(std::string uri, bool reload = false) -> LoadTask;
1616
[[nodiscard]] auto make_load_texture(std::string uri, bool mip_map = false, bool reload = false) -> LoadTask;

src/spaced/spaced/async_exec.cpp

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

src/spaced/spaced/async_exec.hpp

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

src/spaced/spaced/game/arsenal.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
namespace spaced {
55
using bave::Seconds;
6+
using bave::Services;
67
using bave::Shader;
78

89
Arsenal::Arsenal(Services const& services) : m_primary(services), m_stats(&services.get<Stats>()) {}

src/spaced/spaced/game/arsenal.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ struct Stats;
88
// Weapons only switch when they are idle.
99
class Arsenal {
1010
public:
11-
explicit Arsenal(Services const& services);
11+
explicit Arsenal(bave::Services const& services);
1212

1313
[[nodiscard]] auto get_weapon() const -> Weapon const&;
1414
[[nodiscard]] auto get_weapon() -> Weapon&;

src/spaced/spaced/game/controllers/auto_controller.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#pragma once
22
#include <bave/core/ptr.hpp>
33
#include <bave/input/gamepad.hpp>
4+
#include <bave/services/services.hpp>
45
#include <spaced/game/controllers/follow_controller.hpp>
56
#include <spaced/game/spring_arm.hpp>
67
#include <spaced/game/target_provider.hpp>
78
#include <spaced/services/gamepad_provider.hpp>
89
#include <spaced/services/layout.hpp>
9-
#include <spaced/services/services.hpp>
1010

1111
namespace spaced {
1212
class AutoController : public FollowController {

src/spaced/spaced/game/controllers/player_controller.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,20 @@ using bave::Action;
99
using bave::EnumArray;
1010
using bave::GamepadAxis;
1111
using bave::GamepadButton;
12+
using bave::IDisplay;
1213
using bave::im_text;
1314
using bave::PointerMove;
1415
using bave::PointerTap;
1516
using bave::Seconds;
17+
using bave::Services;
1618

17-
PlayerController::PlayerController(Services const& services) : m_layout(&services.get<ILayout>()), m_gamepad_provider(&services.get<IGamepadProvider>()) {
18-
max_y = 0.5f * m_layout->get_world_space().y;
19+
PlayerController::PlayerController(Services const& services) : m_display(&services.get<IDisplay>()), m_gamepad_provider(&services.get<IGamepadProvider>()) {
20+
max_y = 0.5f * m_display->get_world_space().y;
1921
min_y = -max_y; // NOLINT(cppcoreguidelines-prefer-member-initializer)
2022
}
2123

2224
void PlayerController::on_move(PointerMove const& pointer_move) {
23-
auto const world_pos = m_layout->project_to_world(pointer_move.pointer.position);
25+
auto const world_pos = m_display->project_to_world(pointer_move.pointer.position);
2426

2527
if (m_type == Type::eTouch) {
2628
if (!is_in_move_area(world_pos)) {
@@ -39,7 +41,7 @@ void PlayerController::on_move(PointerMove const& pointer_move) {
3941
}
4042

4143
void PlayerController::on_tap(PointerTap const& pointer_tap) {
42-
auto const world_pos = m_layout->project_to_world(pointer_tap.pointer.position);
44+
auto const world_pos = m_display->project_to_world(pointer_tap.pointer.position);
4345
if (m_type == Type::eTouch && is_in_move_area(world_pos)) {
4446
// pointer tap in move area is ingored
4547
return;
@@ -66,7 +68,7 @@ void PlayerController::stop_firing() {
6668
}
6769

6870
auto PlayerController::is_in_move_area(glm::vec2 const position) const -> bool {
69-
auto const n_pos = position.x / m_layout->get_world_space().x;
71+
auto const n_pos = position.x / m_display->get_world_space().x;
7072
return n_pos <= -n_move_area;
7173
}
7274

src/spaced/spaced/game/controllers/player_controller.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#pragma once
22
#include <bave/core/ptr.hpp>
33
#include <bave/input/gamepad.hpp>
4+
#include <bave/services/display.hpp>
5+
#include <bave/services/services.hpp>
46
#include <spaced/game/controllers/follow_controller.hpp>
57
#include <spaced/game/spring_arm.hpp>
68
#include <spaced/services/gamepad_provider.hpp>
7-
#include <spaced/services/layout.hpp>
8-
#include <spaced/services/services.hpp>
99

1010
namespace spaced {
1111
class PlayerController : public FollowController {
@@ -18,7 +18,7 @@ class PlayerController : public FollowController {
1818

1919
[[nodiscard]] auto get_type_name() const -> std::string_view final { return type_name_v; };
2020

21-
explicit PlayerController(Services const& services);
21+
explicit PlayerController(bave::Services const& services);
2222

2323
void on_move(bave::PointerMove const& pointer_move) final;
2424
void on_tap(bave::PointerTap const& pointer_tap) final;
@@ -45,7 +45,7 @@ class PlayerController : public FollowController {
4545
auto tick_y(bave::Seconds dt) -> float final;
4646
void do_inspect() final;
4747

48-
bave::Ptr<ILayout const> m_layout{};
48+
bave::Ptr<bave::IDisplay const> m_display{};
4949
bave::Ptr<IGamepadProvider const> m_gamepad_provider{};
5050

5151
Type m_type{};

src/spaced/spaced/game/enemies/creep.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ void Creep::tick(Seconds const dt, bool const in_play) {
88
if (!in_play) { return; }
99

1010
shape.transform.position.x -= x_speed * dt.count();
11-
if (shape.transform.position.x < -0.5f * (get_layout().get_world_space().x + shape.get_shape().size.x)) { set_destroyed(); }
11+
if (shape.transform.position.x < -0.5f * (get_layout().world_space.x + shape.get_shape().size.x)) { set_destroyed(); }
1212
}
1313
} // namespace spaced

src/spaced/spaced/game/enemies/creep.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
namespace spaced {
55
class Creep : public Enemy {
66
public:
7-
explicit Creep(Services const& services) : Enemy(services, "Creep") {}
7+
explicit Creep(bave::Services const& services) : Enemy(services, "Creep") {}
88

99
void tick(bave::Seconds dt, bool in_play) override;
1010

0 commit comments

Comments
 (0)