Skip to content

Commit 74e16dc

Browse files
committed
Update le2d to v0.2.0
1 parent b5afa4e commit 74e16dc

File tree

9 files changed

+25
-31
lines changed

9 files changed

+25
-31
lines changed

ext/src.zip

9.66 KB
Binary file not shown.

src/app.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ constexpr auto context_ci = le::Context::CreateInfo{
1414
};
1515
} // namespace
1616

17-
App::App() : m_context(context_ci), m_data_loader(le::FileDataLoader::upfind("assets")) { bind_services(); }
17+
App::App() : m_context(context_ci), m_data_loader(le::FileDataLoader::upfind("assets")), m_asset_loader(m_context.create_asset_loader(&m_data_loader)) {
18+
bind_services();
19+
}
1820

1921
void App::run() {
2022
auto game = Game{&m_services};
@@ -40,5 +42,7 @@ void App::bind_services() {
4042
// m_data_loader is bound to both the interface and the concrete class for use through either type.
4143
m_services.bind<le::IDataLoader>(&m_data_loader);
4244
m_services.bind<le::FileDataLoader>(&m_data_loader);
45+
46+
m_services.bind(&m_asset_loader);
4347
}
4448
} // namespace miracle

src/app.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class App {
1515

1616
le::Context m_context;
1717
le::FileDataLoader m_data_loader{};
18+
le::AssetLoader m_asset_loader{};
1819

1920
le::ServiceLocator m_services{};
2021
};

src/enemy.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77
#include <le2d/renderer.hpp>
88
#include <le2d/service_locator.hpp>
99
#include <cstddef>
10-
#include <optional>
11-
#include "glm/vec2.hpp"
12-
#include "le2d/texture.hpp"
10+
#include <memory>
11+
#include "le2d/resource/texture.hpp"
1312

1413
namespace miracle {
1514
class Enemy {
@@ -35,7 +34,7 @@ class Enemy {
3534

3635
private:
3736
gsl::not_null<le::ServiceLocator const*> m_services;
38-
std::optional<le::Texture> m_texture;
37+
std::unique_ptr<le::ITexture> m_texture;
3938
le::drawable::Circle m_sprite{};
4039
glm::vec2 m_target_pos{};
4140
float m_move_speed{};

src/game.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,23 @@
11
#include <game.hpp>
22
#include <glm/gtx/norm.hpp>
33
#include <le2d/context.hpp>
4-
#include <algorithm>
54
#include <cstddef>
65
#include <format>
76
#include <iterator>
87
#include <string>
98
#include <vector>
109
#include "enemy.hpp"
1110
#include "kvf/time.hpp"
12-
#include "le2d/asset_loader.hpp"
13-
#include "le2d/data_loader.hpp"
1411
#include "le2d/drawable/text.hpp"
1512
#include "lighthouse.hpp"
1613
#include "util/random.hpp"
1714

1815
namespace miracle {
1916
Game::Game(gsl::not_null<le::ServiceLocator const*> services) : m_services(services), m_lighthouse(services), m_light(services) {
2017
spawn_wave();
21-
auto const& data_loader = services->get<le::IDataLoader>();
22-
auto const& context = services->get<le::Context>();
23-
auto const asset_loader = le::AssetLoader{&data_loader, &context};
24-
m_font = asset_loader.load_font("fonts/specialElite.ttf");
18+
auto const& asset_loader = services->get<le::AssetLoader>();
19+
m_font = asset_loader.load<le::IFont>("fonts/specialElite.ttf");
20+
if (!m_font) { throw std::runtime_error{"Failed to load font"}; }
2521
}
2622

2723
void Game::on_cursor_pos(le::event::CursorPos const& cursor_pos) {
@@ -79,7 +75,7 @@ void Game::update_score(int points) {
7975
m_score += points;
8076
m_score_str.clear();
8177
std::format_to(std::back_inserter(m_score_str), "Score: {}", m_score);
82-
m_score_text.set_string(m_font, m_score_str);
78+
m_score_text.set_string(*m_font, m_score_str);
8379
}
8480

8581
void Game::update_health_text() {
@@ -95,7 +91,7 @@ void Game::update_health_text() {
9591
std::format_to(std::back_inserter(m_health_str), "Health: {:.1f}", m_lighthouse.get_health());
9692
}
9793

98-
m_health_text.set_string(m_font, m_health_str);
94+
m_health_text.set_string(*m_font, m_health_str);
9995
}
10096

10197
} // namespace miracle

src/game.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
#include <le2d/event.hpp>
55
#include <le2d/renderer.hpp>
66
#include <le2d/service_locator.hpp>
7-
#include <cstddef>
7+
#include <memory>
88
#include "enemy.hpp"
99
#include "le2d/drawable/text.hpp"
10-
#include "le2d/font.hpp"
10+
#include "le2d/resource/font.hpp"
1111
#include "light.hpp"
1212
#include "lighthouse.hpp"
1313

@@ -29,7 +29,7 @@ class Game {
2929
Lighthouse m_lighthouse;
3030
Light m_light;
3131

32-
le::Font m_font{};
32+
std::unique_ptr<le::IFont> m_font{};
3333
le::drawable::Text m_score_text{};
3434
le::drawable::Text m_health_text{};
3535
int m_score{};

src/light.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
#pragma once
22

33
#include "enemy.hpp"
4-
#include "glm/vec2.hpp"
54
#include "gsl/pointers"
65
#include "le2d/drawable/shape.hpp"
76
#include "le2d/renderer.hpp"
7+
#include "le2d/resource/texture.hpp"
88
#include "le2d/service_locator.hpp"
9-
#include "le2d/texture.hpp"
109

1110
namespace miracle {
1211
class Light {
@@ -19,7 +18,7 @@ class Light {
1918

2019
private:
2120
gsl::not_null<le::ServiceLocator const*> m_services;
22-
std::optional<le::Texture> m_texture;
21+
std::unique_ptr<le::ITexture> m_texture;
2322
le::drawable::Circle m_sprite{};
2423
float m_diameter{};
2524
};

src/lighthouse.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
#include <glm/gtc/matrix_transform.hpp>
22
#include <lighthouse.hpp>
33
#include "glm/gtx/norm.hpp"
4-
#include "le2d/asset_loader.hpp"
5-
#include "le2d/data_loader.hpp"
64

75
namespace miracle {
86
Lighthouse::Lighthouse(gsl::not_null<le::ServiceLocator const*> services) : m_services(services) {
97
m_sprite.create(m_hitbox_diameter);
10-
auto const& data_loader = services->get<le::IDataLoader>();
11-
auto const& context = services->get<le::Context>();
12-
auto const asset_loader = le::AssetLoader{&data_loader, &context};
13-
m_texture = asset_loader.load_texture("images/lighthouse.png");
14-
m_sprite.texture = &m_texture.value();
8+
auto const& asset_loader = services->get<le::AssetLoader>();
9+
m_texture = asset_loader.load<le::ITexture>("images/lighthouse.png");
10+
m_sprite.texture = m_texture.get();
1511
}
1612

1713
void Lighthouse::rotate_towards_cursor(glm::vec2 cursor_pos) {

src/lighthouse.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66
#include <le2d/event.hpp>
77
#include <le2d/renderer.hpp>
88
#include <le2d/service_locator.hpp>
9-
#include <cstddef>
10-
#include <optional>
9+
#include <memory>
1110
#include "enemy.hpp"
12-
#include "le2d/texture.hpp"
11+
#include "le2d/resource/texture.hpp"
1312

1413
namespace miracle {
1514
class Lighthouse {
@@ -27,7 +26,7 @@ class Lighthouse {
2726
gsl::not_null<le::ServiceLocator const*> m_services;
2827
float m_hitbox_diameter{150.0f};
2928
float m_visibility_diameter{250.0f};
30-
std::optional<le::Texture> m_texture;
29+
std::unique_ptr<le::ITexture> m_texture;
3130
le::drawable::Circle m_sprite{};
3231
float m_health{100};
3332
};

0 commit comments

Comments
 (0)