Skip to content

Commit 59e3a3c

Browse files
authored
Merge pull request #43 from antkeeper/gh-29-reenter-play-state
GH-29: Fix re-entering of play state.
2 parents 7885417 + 2ca158d commit 59e3a3c

File tree

93 files changed

+1634
-3005
lines changed

Some content is hidden

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

93 files changed

+1634
-3005
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ FetchContent_Declare(dr_libs
6666
)
6767
FetchContent_Declare(entt
6868
GIT_REPOSITORY https://github.com/skypjack/entt.git
69-
GIT_TAG e4ccb878f47245a319704912435d3c89f34ad6be # v3.10.3
69+
GIT_TAG 4a2d1a8541228a90e02a873dba6a980506c42c03 # v3.14.0
7070
GIT_PROGRESS TRUE
7171
)
7272
FetchContent_Declare(freetype

src/engine/animation/skeletal-animation.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include <engine/math/euler-angles.hpp>
88
#include <engine/debug/log.hpp>
99
#include <engine/scene/skeletal-mesh.hpp>
10-
#include "game/components/scene-component.hpp"
10+
#include "game/components/scene-object-component.hpp"
1111
#include <filesystem>
1212
#include <format>
1313
#include <stdexcept>
@@ -48,7 +48,7 @@ void bind_skeletal_animation([[maybe_unused]] animation_sequence& sequence, [[ma
4848
{
4949
track.output() = [bone_index](auto samples, auto& context)
5050
{
51-
auto& scene_object = *(context.handle.template get<scene_component>().object);
51+
auto& scene_object = *(context.handle.template get<scene_object_component>().object);
5252
auto& skeletal_mesh = static_cast<scene::skeletal_mesh&>(scene_object);
5353

5454
const auto translation = math::fvec3{samples[0], samples[1], samples[2]};
@@ -60,7 +60,7 @@ void bind_skeletal_animation([[maybe_unused]] animation_sequence& sequence, [[ma
6060
{
6161
track.output() = [bone_index](auto samples, auto& context)
6262
{
63-
auto& scene_object = *(context.handle.template get<scene_component>().object);
63+
auto& scene_object = *(context.handle.template get<scene_object_component>().object);
6464
auto& skeletal_mesh = static_cast<scene::skeletal_mesh&>(scene_object);
6565

6666
const auto rotation = math::normalize(math::fquat{samples[0], samples[1], samples[2], samples[3]});
@@ -72,7 +72,7 @@ void bind_skeletal_animation([[maybe_unused]] animation_sequence& sequence, [[ma
7272
{
7373
track.output() = [bone_index](auto samples, auto& context)
7474
{
75-
auto& scene_object = *(context.handle.template get<scene_component>().object);
75+
auto& scene_object = *(context.handle.template get<scene_object_component>().object);
7676
auto& skeletal_mesh = static_cast<scene::skeletal_mesh&>(scene_object);
7777

7878
const auto rotation = math::euler_xyz_to_quat(math::fvec3{samples[0], samples[1], samples[2]});
@@ -84,7 +84,7 @@ void bind_skeletal_animation([[maybe_unused]] animation_sequence& sequence, [[ma
8484
{
8585
track.output() = [bone_index](auto samples, auto& context)
8686
{
87-
auto& scene_object = *(context.handle.template get<scene_component>().object);
87+
auto& scene_object = *(context.handle.template get<scene_object_component>().object);
8888
auto& skeletal_mesh = static_cast<scene::skeletal_mesh&>(scene_object);
8989

9090
const auto scale = math::fvec3{samples[0], samples[1], samples[2]};

src/engine/config.hpp.in

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
#ifndef ANTKEEPER_CONFIG_HPP
55
#define ANTKEEPER_CONFIG_HPP
66

7-
#include <cstddef>
8-
#include <engine/math/vector.hpp>
9-
107
/// Global configuration constants.
118
namespace config {
129

@@ -52,7 +49,7 @@ inline constexpr const char* application_url = "@PROJECT_HOMEPAGE_URL@";
5249
/// @{
5350

5451
/// Maximum number of debug logs to archive.
55-
inline constexpr std::size_t debug_log_archive_capacity = 5;
52+
inline constexpr unsigned int debug_log_archive_capacity = 5;
5653

5754
/// @}
5855

@@ -85,34 +82,6 @@ inline constexpr int opengl_min_stencil_size = 0;
8582

8683
/// @}
8784

88-
inline constexpr math::vector<float, 3> global_forward = {0.0f, 0.0f, -1.0f};
89-
inline constexpr math::vector<float, 3> global_up = {0.0f, 1.0f, 0.0f};
90-
inline constexpr math::vector<float, 3> global_right = {1.0f, 0.0f, 0.0f};
91-
92-
/// Duration of the menu fade in animation, in seconds.
93-
inline constexpr float menu_fade_in_duration = 0.25f;
94-
95-
/// Duration of the menu fade out animation, in seconds.
96-
inline constexpr float menu_fade_out_duration = 0.125f;
97-
98-
/// Padding of the a menu item mouseover bounds, as a percentage of the font size.
99-
inline constexpr float menu_mouseover_padding = 0.1f;
100-
101-
/// Opacity of the menu background.
102-
inline constexpr float menu_bg_opacity = 3.0f / 4.0f;
103-
104-
/// Duration of the title screen fade in, in seconds.
105-
inline constexpr float title_fade_in_duration = 1.0f;
106-
107-
/// Duration of the fade out when quitting the game or returning to the main menu, in seconds.
108-
inline constexpr float quit_fade_out_duration = 0.5f;
109-
110-
/// Duration of the fade out when a new colony is started, in seconds.
111-
inline constexpr float new_colony_fade_out_duration = 1.0f;
112-
113-
/// Duration of the nuptial flight fade in, in seconds.
114-
inline constexpr float nuptial_flight_fade_in_duration = 5.0f;
115-
11685
} // namespace config
11786

11887
#endif // ANTKEEPER_CONFIG_HPP

src/engine/entity/clone.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ void clone(entity::registry& registry, entity::id source, entity::id destination
1111
{
1212
if (auto& storage = it.second; storage.contains(source))
1313
{
14-
storage.emplace(destination, storage.get(source));
14+
storage.push(destination, storage.value(source));
1515
}
1616
}
1717
}

src/engine/hash/fnv.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
namespace hash {
1919

2020
/// 32-bit FNV hash value.
21-
enum class fnv32_t : std::uint32_t {};
21+
enum class fnv32_t: std::uint32_t{};
2222

2323
/// 64-bit FNV hash value.
24-
enum class fnv64_t : std::uint64_t {};
24+
enum class fnv64_t: std::uint64_t{};
2525

2626
namespace types
2727
{

src/engine/render/stages/light-probe-stage.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <engine/scene/light-probe.hpp>
77
#include <engine/scene/collection.hpp>
88
#include <engine/hash/fnv.hpp>
9+
#include <engine/debug/contract.hpp>
910
#include <stdexcept>
1011

1112
using namespace hash::literals;
@@ -105,6 +106,27 @@ light_probe_stage::light_probe_stage(gl::pipeline& pipeline, ::resource_manager&
105106
// Load cubemap filter shader template and build shader program
106107
m_cubemap_filter_shader_template = resource_manager.load<gl::shader_template>("cubemap-filter.glsl");
107108
rebuild_cubemap_filter_shader_program();
109+
110+
debug::postcondition(m_vertex_array != nullptr);
111+
112+
debug::postcondition(m_cubemap_to_sh_shader_program != nullptr);
113+
debug::postcondition(m_cubemap_to_sh_cubemap_var != nullptr);
114+
115+
debug::postcondition(m_cubemap_downsample_shader_program != nullptr);
116+
debug::postcondition(m_cubemap_downsample_cubemap_var != nullptr);
117+
118+
debug::postcondition(m_cubemap_filter_lut_texture != nullptr);
119+
debug::postcondition(m_cubemap_filter_lut_framebuffer != nullptr);
120+
debug::postcondition(m_cubemap_filter_lut_shader_program != nullptr);
121+
debug::postcondition(m_cubemap_filter_lut_resolution_var != nullptr);
122+
debug::postcondition(m_cubemap_filter_lut_face_size_var != nullptr);
123+
debug::postcondition(m_cubemap_filter_lut_mip_bias_var != nullptr);
124+
125+
debug::postcondition(m_cubemap_filter_shader_program != nullptr);
126+
debug::postcondition(m_cubemap_filter_cubemap_var != nullptr);
127+
debug::postcondition(m_cubemap_filter_filter_lut_var != nullptr);
128+
debug::postcondition(m_cubemap_filter_mip_level_var != nullptr);
129+
108130
}
109131

110132
void light_probe_stage::execute(render::context& ctx)
@@ -131,6 +153,8 @@ void light_probe_stage::update_light_probes_luminance(const std::vector<scene::o
131153
{
132154
continue;
133155
}
156+
157+
debug::invariant(light_probe.get_luminance_texture() != nullptr);
134158

135159
// Store light probe luminance sampler
136160
auto light_probe_luminance_sampler = light_probe.get_luminance_texture()->get_sampler();
@@ -233,6 +257,9 @@ void light_probe_stage::update_light_probes_illuminance(const std::vector<scene:
233257
{
234258
continue;
235259
}
260+
261+
debug::invariant(light_probe.get_luminance_texture() != nullptr);
262+
debug::invariant(light_probe.get_illuminance_framebuffer() != nullptr);
236263

237264
// Setup viewport and bind cubemap to spherical harmonics shader program
238265
if (!state_bound)

src/engine/render/stages/light-probe-stage.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,8 @@ class light_probe_stage: public stage
9595

9696
std::shared_ptr<gl::shader_template> m_cubemap_downsample_shader_template;
9797
std::unique_ptr<gl::shader_program> m_cubemap_downsample_shader_program;
98-
9998
const gl::shader_variable* m_cubemap_downsample_cubemap_var{};
10099
std::vector<std::unique_ptr<gl::framebuffer>> m_cubemap_downsample_framebuffers;
101-
std::unique_ptr<gl::texture_cube> m_cubemap_downsample_texture;
102100

103101
std::shared_ptr<gl::texture_2d> m_cubemap_filter_lut_texture;
104102
std::unique_ptr<gl::framebuffer> m_cubemap_filter_lut_framebuffer;

src/engine/scene/directional-light.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,9 @@ class directional_light: public light
210210
float m_shadow_max_distance{100.0f};
211211
float m_shadow_fade_range{0.0f};
212212
float m_shadow_cascade_distribution{0.8f};
213-
math::fvec4 m_shadow_cascade_distances;
214-
math::fmat4 m_shadow_cascade_matrices[4];
215-
math::fmat4 m_shadow_scale_bias_matrices[4];
213+
math::fvec4 m_shadow_cascade_distances{};
214+
math::fmat4 m_shadow_cascade_matrices[4]{};
215+
math::fmat4 m_shadow_scale_bias_matrices[4]{};
216216
};
217217

218218
} // namespace scene

src/engine/scene/light-probe.cpp

Lines changed: 83 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,55 @@
22
// SPDX-License-Identifier: GPL-3.0-or-later
33

44
#include <engine/scene/light-probe.hpp>
5+
#include <engine/debug/contract.hpp>
56

67
namespace scene {
78

9+
namespace
10+
{
11+
// 4 floats per pixel to encode the 3 4x4 spherical harmonics illuminance matrices in a 12 pixel 1D image.
12+
inline constexpr gl::format light_probe_illuminance_image_format = gl::format::r32g32b32a32_sfloat;
13+
14+
// 12 pixels, corresponding to the column vectors of three spherical harmonics illuminance matrices (R0, R1, R2, R3, G0, G1, G2, G3, B0, B1, B2, B3).
15+
inline constexpr std::uint32_t light_probe_illuminance_image_width = 12;
16+
}
17+
18+
light_probe::light_probe(gl::format format, std::uint32_t face_size):
19+
light_probe()
20+
{
21+
const auto mip_levels = static_cast<std::uint32_t>(std::bit_width(face_size));
22+
23+
set_luminance_texture
24+
(
25+
std::make_shared<gl::texture_cube>
26+
(
27+
// Luminance texture image view
28+
std::make_shared<gl::image_view_cube>
29+
(
30+
std::make_shared<gl::image_cube>
31+
(
32+
format,
33+
face_size,
34+
mip_levels
35+
),
36+
gl::format::undefined,
37+
0,
38+
mip_levels
39+
),
40+
41+
// Lumiance texture sampler
42+
std::make_shared<gl::sampler>
43+
(
44+
gl::sampler_filter::linear,
45+
gl::sampler_filter::linear,
46+
gl::sampler_mipmap_mode::linear,
47+
gl::sampler_address_mode::clamp_to_edge,
48+
gl::sampler_address_mode::clamp_to_edge
49+
)
50+
)
51+
);
52+
}
53+
854
light_probe::light_probe()
955
{
1056
// Allocate illuminance texture
@@ -14,8 +60,8 @@ light_probe::light_probe()
1460
(
1561
std::make_shared<gl::image_1d>
1662
(
17-
gl::format::r32g32b32a32_sfloat,
18-
12
63+
light_probe_illuminance_image_format,
64+
light_probe_illuminance_image_width
1965
)
2066
),
2167
std::make_shared<gl::sampler>
@@ -36,7 +82,7 @@ light_probe::light_probe()
3682
0
3783
}
3884
};
39-
m_illuminance_framebuffer = std::make_shared<gl::framebuffer>(attachments, 12, 1);
85+
m_illuminance_framebuffer = std::make_shared<gl::framebuffer>(attachments, light_probe_illuminance_image_width, 1);
4086

4187
// Init illuminance matrices
4288
m_illuminance_matrices[0] = {};
@@ -46,55 +92,62 @@ light_probe::light_probe()
4692

4793
void light_probe::update_illuminance_matrices()
4894
{
95+
debug::precondition(m_illuminance_texture != nullptr);
96+
4997
m_illuminance_texture->get_image_view()->get_image()->read
5098
(
5199
0,
52100
0,
53101
0,
54102
0,
55-
12,
103+
light_probe_illuminance_image_width,
56104
1,
57105
1,
58-
gl::format::r32g32b32a32_sfloat,
106+
light_probe_illuminance_image_format,
59107
std::as_writable_bytes(std::span{m_illuminance_matrices})
60108
);
61109
}
62110

63111
void light_probe::set_luminance_texture(std::shared_ptr<gl::texture_cube> texture)
64112
{
65-
if (m_luminance_texture != texture)
113+
if (m_luminance_texture == texture)
66114
{
67-
m_luminance_texture = texture;
115+
return;
116+
}
117+
118+
m_luminance_texture = texture;
68119

69-
// Update luminance framebuffers
70-
if (m_luminance_texture)
71-
{
72-
const auto face_size = texture->get_image_view()->get_image()->get_dimensions()[0];
73-
const auto mip_count = static_cast<std::uint32_t>(std::bit_width(face_size));
120+
// Update luminance framebuffers
121+
if (m_luminance_texture)
122+
{
123+
debug::invariant(m_luminance_texture->get_image_view() != nullptr);
124+
debug::invariant(m_luminance_texture->get_image_view()->get_image() != nullptr);
125+
126+
const auto face_size = m_luminance_texture->get_image_view()->get_image()->get_dimensions()[0];
127+
const auto mip_count = static_cast<std::uint32_t>(std::bit_width(face_size));
74128

75-
m_luminance_framebuffers.resize(mip_count);
129+
m_luminance_framebuffers.resize(mip_count);
76130

77-
for (std::uint32_t i = 0; i < mip_count; ++i)
131+
for (std::uint32_t i = 0; i < mip_count; ++i)
132+
{
133+
const gl::framebuffer_attachment attachments[1] =
78134
{
79-
const gl::framebuffer_attachment attachments[1] =
80135
{
81-
{
82-
gl::color_attachment_bit,
83-
m_luminance_texture->get_image_view(),
84-
i
85-
}
86-
};
87-
m_luminance_framebuffers[i] = std::make_shared<gl::framebuffer>(attachments, face_size >> i, face_size >> i);
88-
}
89-
}
90-
else
91-
{
92-
m_luminance_framebuffers.clear();
136+
gl::color_attachment_bit,
137+
m_luminance_texture->get_image_view(),
138+
i
139+
}
140+
};
141+
m_luminance_framebuffers[i] = std::make_shared<gl::framebuffer>(attachments, face_size >> i, face_size >> i);
93142
}
94-
95-
set_luminance_outdated(true);
96-
set_illuminance_outdated(true);
97143
}
144+
else
145+
{
146+
m_luminance_framebuffers.clear();
147+
}
148+
149+
set_luminance_outdated(true);
150+
set_illuminance_outdated(true);
98151
}
99152

100153
void light_probe::set_luminance_outdated(bool outdated)

0 commit comments

Comments
 (0)