Skip to content

Commit

Permalink
Merge branch 'fix/render_entity_threadsafe' into feature/apply_effect
Browse files Browse the repository at this point in the history
  • Loading branch information
heinezen committed Oct 5, 2024
2 parents b1dfe87 + d41cec3 commit 61d409b
Show file tree
Hide file tree
Showing 44 changed files with 502 additions and 413 deletions.
1 change: 1 addition & 0 deletions copying.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ _the openage authors_ are:
| Haoyang Bi | AyiStar | ayistar à outlook dawt com |
| Michael Seibt | RoboSchmied | github à roboschmie dawt de |
| Nikhil Ghosh | NikhilGhosh75 | nghosh606 à gmail dawt com |
| Edvin Lindholm | EdvinLndh | edvinlndh à gmail dawt com |

If you're a first-time committer, add yourself to the above list. This is not
just for legal reasons, but also to keep an overview of all those nicknames.
Expand Down
4 changes: 2 additions & 2 deletions libopenage/gamestate/game_entity.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022-2023 the openage authors. See copying.md for legal info.
// Copyright 2022-2024 the openage authors. See copying.md for legal info.

#include "game_entity.h"

Expand Down Expand Up @@ -30,7 +30,7 @@ entity_id_t GameEntity::get_id() const {
return this->id;
}

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

this->render_entity = entity;
Expand Down
6 changes: 3 additions & 3 deletions libopenage/gamestate/game_entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
namespace openage {

namespace renderer::world {
class WorldRenderEntity;
class RenderEntity;
}

namespace gamestate {
Expand Down Expand Up @@ -62,7 +62,7 @@ class GameEntity {
*
* @param entity New render entity.
*/
void set_render_entity(const std::shared_ptr<renderer::world::WorldRenderEntity> &entity);
void set_render_entity(const std::shared_ptr<renderer::world::RenderEntity> &entity);

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

/**
* Event manager.
Expand Down
2 changes: 1 addition & 1 deletion libopenage/gamestate/terrain_chunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ TerrainChunk::TerrainChunk(const util::Vector2s size,
}
}

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

Expand Down
4 changes: 2 additions & 2 deletions libopenage/gamestate/terrain_chunk.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class TerrainChunk {
*
* @param entity New render entity.
*/
void set_render_entity(const std::shared_ptr<renderer::terrain::TerrainRenderEntity> &entity);
void set_render_entity(const std::shared_ptr<renderer::terrain::RenderEntity> &entity);

/**
* Get the size of this terrain chunk.
Expand Down Expand Up @@ -103,7 +103,7 @@ class TerrainChunk {
/**
* Render entity for pushing updates to the renderer. Can be \p nullptr.
*/
std::shared_ptr<renderer::terrain::TerrainRenderEntity> render_entity;
std::shared_ptr<renderer::terrain::RenderEntity> render_entity;
};

} // namespace openage::gamestate
8 changes: 4 additions & 4 deletions libopenage/input/controller/hud/controller.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023-2023 the openage authors. See copying.md for legal info.
// Copyright 2023-2024 the openage authors. See copying.md for legal info.

#include "controller.h"

Expand Down Expand Up @@ -27,19 +27,19 @@ bool Controller::process(const event_arguments &ev_args,
return true;
}

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

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

void setup_defaults(const std::shared_ptr<BindingContext> &ctx,
const std::shared_ptr<renderer::hud::HudRenderStage> &hud_renderer) {
binding_func_t drag_selection_init{[&](const event_arguments &args,
const std::shared_ptr<Controller> controller) {
auto render_entity = std::make_shared<renderer::hud::HudDragRenderEntity>(args.mouse);
auto render_entity = std::make_shared<renderer::hud::DragRenderEntity>(args.mouse);
hud_renderer->add_drag_entity(render_entity);
controller->set_drag_entity(render_entity);
}};
Expand Down
8 changes: 4 additions & 4 deletions libopenage/input/controller/hud/controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace openage {

namespace renderer::hud {
class HudDragRenderEntity;
class DragRenderEntity;
class HudRenderStage;
} // namespace renderer::hud

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

/**
* Get the render entity for the selection box.
*
* @return Render entity for the selection box.
*/
const std::shared_ptr<renderer::hud::HudDragRenderEntity> &get_drag_entity() const;
const std::shared_ptr<renderer::hud::DragRenderEntity> &get_drag_entity() const;

private:
/**
* Render entity for the selection box.
*/
std::shared_ptr<renderer::hud::HudDragRenderEntity> drag_entity;
std::shared_ptr<renderer::hud::DragRenderEntity> drag_entity;
};

/**
Expand Down
2 changes: 1 addition & 1 deletion libopenage/renderer/demo/demo_3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void renderer_demo_3(const util::Path &path) {

// Fill a 10x10 terrain grid with height values
auto terrain_size = util::Vector2s{10, 10};
std::vector<std::pair<terrain::TerrainRenderEntity::terrain_elevation_t, std::string>> tiles{};
std::vector<std::pair<terrain::RenderEntity::terrain_elevation_t, std::string>> tiles{};
tiles.reserve(terrain_size[0] * terrain_size[1]);
for (size_t i = 0; i < terrain_size[0] * terrain_size[1]; ++i) {
tiles.emplace_back(0.0f, "./textures/test_terrain.terrain");
Expand Down
4 changes: 2 additions & 2 deletions libopenage/renderer/demo/stresstest_0.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ void renderer_stresstest_0(const util::Path &path) {

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

// World entities
std::vector<std::shared_ptr<renderer::world::WorldRenderEntity>> render_entities{};
std::vector<std::shared_ptr<renderer::world::RenderEntity>> render_entities{};
auto add_world_entity = [&](const coord::phys3 initial_pos,
const time::time_t time) {
const auto animation_path = "./textures/test_tank_mirrored.sprite";
Expand Down
4 changes: 2 additions & 2 deletions libopenage/renderer/demo/stresstest_1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ void renderer_stresstest_1(const util::Path &path) {

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

std::vector<std::shared_ptr<renderer::world::WorldRenderEntity>> render_entities{};
std::vector<std::shared_ptr<renderer::world::RenderEntity>> render_entities{};
auto add_world_entity = [&](const coord::phys3 initial_pos,
const time::time_t time) {
const auto animation_path = "./textures/test_tank_mirrored.sprite";
Expand Down
17 changes: 8 additions & 9 deletions libopenage/renderer/opengl/renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,22 +86,21 @@ std::shared_ptr<RenderTarget> GlRenderer::get_display_target() {

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

// align offset to the size of the type
offset += offset % size;

uniforms.emplace(
std::make_pair(input.name,
GlInBlockUniform{type,
offset,
resources::UniformBufferInfo::get_size(input, info.get_layout()),
resources::UniformBufferInfo::get_stride_size(input.type, info.get_layout()),
input.count}));
uniforms.push_back(
GlInBlockUniform{type,
offset,
resources::UniformBufferInfo::get_size(input, info.get_layout()),
resources::UniformBufferInfo::get_stride_size(input.type, info.get_layout()),
input.count,
input.name});

offset += size;
}
Expand Down
8 changes: 7 additions & 1 deletion libopenage/renderer/opengl/shader_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <optional>
#include <string>
#include <unordered_map>
#include <vector>

#include <epoxy/gl.h>

Expand Down Expand Up @@ -61,6 +62,11 @@ struct GlInBlockUniform {
* Only relevant for arrays. The number of elements in the array.
*/
size_t count;

/**
* Name of the block uniform.
*/
std::string name;
};

/**
Expand All @@ -78,7 +84,7 @@ struct GlUniformBlock {
/**
* Maps uniform names within this block to their descriptions.
*/
std::unordered_map<std::string, GlInBlockUniform> uniforms;
std::vector<GlInBlockUniform> uniforms;

/**
* The binding point assigned to this block.
Expand Down
22 changes: 11 additions & 11 deletions libopenage/renderer/opengl/shader_program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ GlShaderProgram::GlShaderProgram(const std::shared_ptr<GlContext> &context,
std::vector<GLint> uniform_indices(val);
glGetActiveUniformBlockiv(handle, i_unif_block, GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES, uniform_indices.data());

std::unordered_map<std::string, GlInBlockUniform> uniforms;
std::vector<GlInBlockUniform> uniforms;
for (GLuint const i_unif : uniform_indices) {
in_block_unifs.insert(i_unif);

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

uniforms.insert(std::make_pair(
name.data(),
uniforms.push_back(
GlInBlockUniform{
type,
size_t(offset),
size_t(count) * GL_UNIFORM_TYPE_SIZE.get(type),
size_t(stride),
size_t(count)}));
size_t(count),
std::string(name.data())});
}

// ENSURE(block_binding < caps.max_uniform_buffer_bindings,
Expand Down Expand Up @@ -257,10 +257,10 @@ GlShaderProgram::GlShaderProgram(const std::shared_ptr<GlContext> &context,
for (auto const &pair : this->uniform_blocks) {
log::log(MSG(dbg) << "(" << pair.second.index << ") " << pair.first
<< " (size: " << pair.second.data_size << ") {");
for (auto const &unif_pair : pair.second.uniforms) {
log::log(MSG(dbg) << "\t+" << unif_pair.second.offset
<< " " << unif_pair.first << ": "
<< GLSL_TYPE_NAME.get(unif_pair.second.type));
for (auto const &unif : pair.second.uniforms) {
log::log(MSG(dbg) << "\t+" << unif.offset
<< " " << unif.name << ": "
<< GLSL_TYPE_NAME.get(unif.type));
}
log::log(MSG(dbg) << "}");
}
Expand Down Expand Up @@ -478,9 +478,9 @@ void GlShaderProgram::bind_uniform_buffer(const char *block_name, std::shared_pt
auto &block = this->uniform_blocks[block_name];

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

block.binding_point = gl_buffer->get_binding_point();
Expand Down
Loading

0 comments on commit 61d409b

Please sign in to comment.