Skip to content

Commit 61d409b

Browse files
committed
Merge branch 'fix/render_entity_threadsafe' into feature/apply_effect
2 parents b1dfe87 + d41cec3 commit 61d409b

Some content is hidden

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

44 files changed

+502
-413
lines changed

Diff for: copying.md

+1
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ _the openage authors_ are:
154154
| Haoyang Bi | AyiStar | ayistar à outlook dawt com |
155155
| Michael Seibt | RoboSchmied | github à roboschmie dawt de |
156156
| Nikhil Ghosh | NikhilGhosh75 | nghosh606 à gmail dawt com |
157+
| Edvin Lindholm | EdvinLndh | edvinlndh à gmail dawt com |
157158

158159
If you're a first-time committer, add yourself to the above list. This is not
159160
just for legal reasons, but also to keep an overview of all those nicknames.

Diff for: libopenage/gamestate/game_entity.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2022-2023 the openage authors. See copying.md for legal info.
1+
// Copyright 2022-2024 the openage authors. See copying.md for legal info.
22

33
#include "game_entity.h"
44

@@ -30,7 +30,7 @@ entity_id_t GameEntity::get_id() const {
3030
return this->id;
3131
}
3232

33-
void GameEntity::set_render_entity(const std::shared_ptr<renderer::world::WorldRenderEntity> &entity) {
33+
void GameEntity::set_render_entity(const std::shared_ptr<renderer::world::RenderEntity> &entity) {
3434
// TODO: Transfer state from old render entity to new one?
3535

3636
this->render_entity = entity;

Diff for: libopenage/gamestate/game_entity.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
namespace openage {
1515

1616
namespace renderer::world {
17-
class WorldRenderEntity;
17+
class RenderEntity;
1818
}
1919

2020
namespace gamestate {
@@ -62,7 +62,7 @@ class GameEntity {
6262
*
6363
* @param entity New render entity.
6464
*/
65-
void set_render_entity(const std::shared_ptr<renderer::world::WorldRenderEntity> &entity);
65+
void set_render_entity(const std::shared_ptr<renderer::world::RenderEntity> &entity);
6666

6767
/**
6868
* Set the event manager of this entity.
@@ -142,7 +142,7 @@ class GameEntity {
142142
/**
143143
* Render entity for pushing updates to the renderer. Can be \p nullptr.
144144
*/
145-
std::shared_ptr<renderer::world::WorldRenderEntity> render_entity;
145+
std::shared_ptr<renderer::world::RenderEntity> render_entity;
146146

147147
/**
148148
* Event manager.

Diff for: libopenage/gamestate/terrain_chunk.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ TerrainChunk::TerrainChunk(const util::Vector2s size,
1818
}
1919
}
2020

21-
void TerrainChunk::set_render_entity(const std::shared_ptr<renderer::terrain::TerrainRenderEntity> &entity) {
21+
void TerrainChunk::set_render_entity(const std::shared_ptr<renderer::terrain::RenderEntity> &entity) {
2222
this->render_entity = entity;
2323
}
2424

Diff for: libopenage/gamestate/terrain_chunk.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class TerrainChunk {
3232
*
3333
* @param entity New render entity.
3434
*/
35-
void set_render_entity(const std::shared_ptr<renderer::terrain::TerrainRenderEntity> &entity);
35+
void set_render_entity(const std::shared_ptr<renderer::terrain::RenderEntity> &entity);
3636

3737
/**
3838
* Get the size of this terrain chunk.
@@ -103,7 +103,7 @@ class TerrainChunk {
103103
/**
104104
* Render entity for pushing updates to the renderer. Can be \p nullptr.
105105
*/
106-
std::shared_ptr<renderer::terrain::TerrainRenderEntity> render_entity;
106+
std::shared_ptr<renderer::terrain::RenderEntity> render_entity;
107107
};
108108

109109
} // namespace openage::gamestate

Diff for: libopenage/input/controller/hud/controller.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2023-2023 the openage authors. See copying.md for legal info.
1+
// Copyright 2023-2024 the openage authors. See copying.md for legal info.
22

33
#include "controller.h"
44

@@ -27,19 +27,19 @@ bool Controller::process(const event_arguments &ev_args,
2727
return true;
2828
}
2929

30-
void Controller::set_drag_entity(const std::shared_ptr<renderer::hud::HudDragRenderEntity> &entity) {
30+
void Controller::set_drag_entity(const std::shared_ptr<renderer::hud::DragRenderEntity> &entity) {
3131
this->drag_entity = entity;
3232
}
3333

34-
const std::shared_ptr<renderer::hud::HudDragRenderEntity> &Controller::get_drag_entity() const {
34+
const std::shared_ptr<renderer::hud::DragRenderEntity> &Controller::get_drag_entity() const {
3535
return this->drag_entity;
3636
}
3737

3838
void setup_defaults(const std::shared_ptr<BindingContext> &ctx,
3939
const std::shared_ptr<renderer::hud::HudRenderStage> &hud_renderer) {
4040
binding_func_t drag_selection_init{[&](const event_arguments &args,
4141
const std::shared_ptr<Controller> controller) {
42-
auto render_entity = std::make_shared<renderer::hud::HudDragRenderEntity>(args.mouse);
42+
auto render_entity = std::make_shared<renderer::hud::DragRenderEntity>(args.mouse);
4343
hud_renderer->add_drag_entity(render_entity);
4444
controller->set_drag_entity(render_entity);
4545
}};

Diff for: libopenage/input/controller/hud/controller.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
namespace openage {
1111

1212
namespace renderer::hud {
13-
class HudDragRenderEntity;
13+
class DragRenderEntity;
1414
class HudRenderStage;
1515
} // namespace renderer::hud
1616

@@ -42,20 +42,20 @@ class Controller : public std::enable_shared_from_this<Controller> {
4242
*
4343
* @param entity New render entity.
4444
*/
45-
void set_drag_entity(const std::shared_ptr<renderer::hud::HudDragRenderEntity> &entity);
45+
void set_drag_entity(const std::shared_ptr<renderer::hud::DragRenderEntity> &entity);
4646

4747
/**
4848
* Get the render entity for the selection box.
4949
*
5050
* @return Render entity for the selection box.
5151
*/
52-
const std::shared_ptr<renderer::hud::HudDragRenderEntity> &get_drag_entity() const;
52+
const std::shared_ptr<renderer::hud::DragRenderEntity> &get_drag_entity() const;
5353

5454
private:
5555
/**
5656
* Render entity for the selection box.
5757
*/
58-
std::shared_ptr<renderer::hud::HudDragRenderEntity> drag_entity;
58+
std::shared_ptr<renderer::hud::DragRenderEntity> drag_entity;
5959
};
6060

6161
/**

Diff for: libopenage/renderer/demo/demo_3.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ void renderer_demo_3(const util::Path &path) {
123123

124124
// Fill a 10x10 terrain grid with height values
125125
auto terrain_size = util::Vector2s{10, 10};
126-
std::vector<std::pair<terrain::TerrainRenderEntity::terrain_elevation_t, std::string>> tiles{};
126+
std::vector<std::pair<terrain::RenderEntity::terrain_elevation_t, std::string>> tiles{};
127127
tiles.reserve(terrain_size[0] * terrain_size[1]);
128128
for (size_t i = 0; i < terrain_size[0] * terrain_size[1]; ++i) {
129129
tiles.emplace_back(0.0f, "./textures/test_terrain.terrain");

Diff for: libopenage/renderer/demo/stresstest_0.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ void renderer_stresstest_0(const util::Path &path) {
133133

134134
// Fill a 10x10 terrain grid with height values
135135
auto terrain_size = util::Vector2s{10, 10};
136-
std::vector<std::pair<terrain::TerrainRenderEntity::terrain_elevation_t, std::string>> tiles{};
136+
std::vector<std::pair<terrain::RenderEntity::terrain_elevation_t, std::string>> tiles{};
137137
tiles.reserve(terrain_size[0] * terrain_size[1]);
138138
for (size_t i = 0; i < terrain_size[0] * terrain_size[1]; ++i) {
139139
tiles.emplace_back(0.0f, "./textures/test_terrain.terrain");
@@ -147,7 +147,7 @@ void renderer_stresstest_0(const util::Path &path) {
147147
terrain0->update(terrain_size, tiles);
148148

149149
// World entities
150-
std::vector<std::shared_ptr<renderer::world::WorldRenderEntity>> render_entities{};
150+
std::vector<std::shared_ptr<renderer::world::RenderEntity>> render_entities{};
151151
auto add_world_entity = [&](const coord::phys3 initial_pos,
152152
const time::time_t time) {
153153
const auto animation_path = "./textures/test_tank_mirrored.sprite";

Diff for: libopenage/renderer/demo/stresstest_1.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ void renderer_stresstest_1(const util::Path &path) {
138138

139139
// Fill a 10x10 terrain grid with height values
140140
auto terrain_size = util::Vector2s{10, 10};
141-
std::vector<std::pair<terrain::TerrainRenderEntity::terrain_elevation_t, std::string>> tiles{};
141+
std::vector<std::pair<terrain::RenderEntity::terrain_elevation_t, std::string>> tiles{};
142142
tiles.reserve(terrain_size[0] * terrain_size[1]);
143143
for (size_t i = 0; i < terrain_size[0] * terrain_size[1]; ++i) {
144144
tiles.emplace_back(0.0f, "./textures/test_terrain.terrain");
@@ -151,7 +151,7 @@ void renderer_stresstest_1(const util::Path &path) {
151151
// send the terrain data to the terrain renderer
152152
terrain0->update(terrain_size, tiles);
153153

154-
std::vector<std::shared_ptr<renderer::world::WorldRenderEntity>> render_entities{};
154+
std::vector<std::shared_ptr<renderer::world::RenderEntity>> render_entities{};
155155
auto add_world_entity = [&](const coord::phys3 initial_pos,
156156
const time::time_t time) {
157157
const auto animation_path = "./textures/test_tank_mirrored.sprite";

Diff for: libopenage/renderer/opengl/renderer.cpp

+8-9
Original file line numberDiff line numberDiff line change
@@ -86,22 +86,21 @@ std::shared_ptr<RenderTarget> GlRenderer::get_display_target() {
8686

8787
std::shared_ptr<UniformBuffer> GlRenderer::add_uniform_buffer(resources::UniformBufferInfo const &info) {
8888
auto inputs = info.get_inputs();
89-
std::unordered_map<std::string, GlInBlockUniform> uniforms{};
89+
std::vector<GlInBlockUniform> uniforms{};
9090
size_t offset = 0;
9191
for (auto const &input : inputs) {
9292
auto type = GL_UBO_INPUT_TYPE.get(input.type);
9393
auto size = resources::UniformBufferInfo::get_size(input, info.get_layout());
9494

9595
// align offset to the size of the type
9696
offset += offset % size;
97-
98-
uniforms.emplace(
99-
std::make_pair(input.name,
100-
GlInBlockUniform{type,
101-
offset,
102-
resources::UniformBufferInfo::get_size(input, info.get_layout()),
103-
resources::UniformBufferInfo::get_stride_size(input.type, info.get_layout()),
104-
input.count}));
97+
uniforms.push_back(
98+
GlInBlockUniform{type,
99+
offset,
100+
resources::UniformBufferInfo::get_size(input, info.get_layout()),
101+
resources::UniformBufferInfo::get_stride_size(input.type, info.get_layout()),
102+
input.count,
103+
input.name});
105104

106105
offset += size;
107106
}

Diff for: libopenage/renderer/opengl/shader_data.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <optional>
66
#include <string>
77
#include <unordered_map>
8+
#include <vector>
89

910
#include <epoxy/gl.h>
1011

@@ -61,6 +62,11 @@ struct GlInBlockUniform {
6162
* Only relevant for arrays. The number of elements in the array.
6263
*/
6364
size_t count;
65+
66+
/**
67+
* Name of the block uniform.
68+
*/
69+
std::string name;
6470
};
6571

6672
/**
@@ -78,7 +84,7 @@ struct GlUniformBlock {
7884
/**
7985
* Maps uniform names within this block to their descriptions.
8086
*/
81-
std::unordered_map<std::string, GlInBlockUniform> uniforms;
87+
std::vector<GlInBlockUniform> uniforms;
8288

8389
/**
8490
* The binding point assigned to this block.

Diff for: libopenage/renderer/opengl/shader_program.cpp

+11-11
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ GlShaderProgram::GlShaderProgram(const std::shared_ptr<GlContext> &context,
125125
std::vector<GLint> uniform_indices(val);
126126
glGetActiveUniformBlockiv(handle, i_unif_block, GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES, uniform_indices.data());
127127

128-
std::unordered_map<std::string, GlInBlockUniform> uniforms;
128+
std::vector<GlInBlockUniform> uniforms;
129129
for (GLuint const i_unif : uniform_indices) {
130130
in_block_unifs.insert(i_unif);
131131

@@ -152,14 +152,14 @@ GlShaderProgram::GlShaderProgram(const std::shared_ptr<GlContext> &context,
152152
// We do not need to handle sampler types here like in the uniform loop below,
153153
// because named blocks cannot contain samplers.
154154

155-
uniforms.insert(std::make_pair(
156-
name.data(),
155+
uniforms.push_back(
157156
GlInBlockUniform{
158157
type,
159158
size_t(offset),
160159
size_t(count) * GL_UNIFORM_TYPE_SIZE.get(type),
161160
size_t(stride),
162-
size_t(count)}));
161+
size_t(count),
162+
std::string(name.data())});
163163
}
164164

165165
// ENSURE(block_binding < caps.max_uniform_buffer_bindings,
@@ -257,10 +257,10 @@ GlShaderProgram::GlShaderProgram(const std::shared_ptr<GlContext> &context,
257257
for (auto const &pair : this->uniform_blocks) {
258258
log::log(MSG(dbg) << "(" << pair.second.index << ") " << pair.first
259259
<< " (size: " << pair.second.data_size << ") {");
260-
for (auto const &unif_pair : pair.second.uniforms) {
261-
log::log(MSG(dbg) << "\t+" << unif_pair.second.offset
262-
<< " " << unif_pair.first << ": "
263-
<< GLSL_TYPE_NAME.get(unif_pair.second.type));
260+
for (auto const &unif : pair.second.uniforms) {
261+
log::log(MSG(dbg) << "\t+" << unif.offset
262+
<< " " << unif.name << ": "
263+
<< GLSL_TYPE_NAME.get(unif.type));
264264
}
265265
log::log(MSG(dbg) << "}");
266266
}
@@ -478,9 +478,9 @@ void GlShaderProgram::bind_uniform_buffer(const char *block_name, std::shared_pt
478478
auto &block = this->uniform_blocks[block_name];
479479

480480
// Check if the uniform buffer matches the block definition
481-
for (auto const &pair : block.uniforms) {
482-
ENSURE(gl_buffer->has_uniform(pair.first.c_str()),
483-
"Uniform buffer does not contain uniform '" << pair.first << "' required by block " << block_name);
481+
for (auto const &unif : block.uniforms) {
482+
ENSURE(gl_buffer->has_uniform(unif.name.c_str()),
483+
"Uniform buffer does not contain uniform '" << unif.name << "' required by block " << block_name);
484484
}
485485

486486
block.binding_point = gl_buffer->get_binding_point();

0 commit comments

Comments
 (0)