Skip to content

Commit

Permalink
renderer: Refactor variable names of the subrenderers.
Browse files Browse the repository at this point in the history
  • Loading branch information
heinezen committed Apr 14, 2023
1 parent aa1fe26 commit e66c57a
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 38 deletions.
12 changes: 9 additions & 3 deletions libopenage/renderer/stages/terrain/terrain_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void TerrainRenderModel::set_camera(const std::shared_ptr<renderer::camera::Came
this->camera = camera;
}

void TerrainRenderModel::update() {
void TerrainRenderModel::update(const curve::time_t &time) {
// Check render entity for updates
if (this->render_entity->is_changed()) {
// TODO: Multiple meshes
Expand All @@ -38,9 +38,15 @@ void TerrainRenderModel::update() {

// Indicate to the render entity that its updates have been processed.
this->render_entity->clear_changed_flag();

// Return to let the renderer create a new renderable
return;
}

// update uniforms
this->update_uniforms(time);
}

void TerrainRenderModel::update_uniforms(const curve::time_t &time) {
for (auto mesh : this->meshes) {
auto unifs = mesh->get_uniforms();
if (unifs != nullptr) [[likely]] {
Expand Down Expand Up @@ -126,7 +132,7 @@ std::shared_ptr<TerrainRenderMesh> TerrainRenderModel::create_mesh() {

// Update textures
auto tex_manager = this->asset_manager->get_texture_manager();
auto terrain_info = this->asset_manager->request_terrain(this->render_entity->get_texture_path());
auto terrain_info = this->asset_manager->request_terrain(this->render_entity->get_terrain_path());
auto texture = tex_manager.request(terrain_info->get_texture(0)->get_image_path().value());
// TODO: Support multiple textures per terrain

Expand Down
30 changes: 24 additions & 6 deletions libopenage/renderer/stages/terrain/terrain_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

#pragma once

#include <eigen3/Eigen/Dense>
#include <memory>

#include <eigen3/Eigen/Dense>

#include "curve/curve.h"

namespace openage::renderer {
class Renderer;

namespace camera {
class Camera;
Expand Down Expand Up @@ -43,8 +45,26 @@ class TerrainRenderModel {
*/
void set_camera(const std::shared_ptr<renderer::camera::Camera> &camera);

void update();
/**
* Recalculate the vertex positions for this mesh with information
* from the currently set render entity.
*
* @param time Current simulation time.
*/
void update(const curve::time_t &time = 0.0);

/**
* Update the uniforms of the renderable associated with this object.
*
* @param time Current simulation time.
*/
void update_uniforms(const curve::time_t &time = 0.0);

/**
* Get the meshes composing the terrain.
*
* @return Vector of terrain meshes.
*/
const std::vector<std::shared_ptr<TerrainRenderMesh>> &get_meshes() const;

private:
Expand All @@ -67,9 +87,7 @@ class TerrainRenderModel {
std::shared_ptr<renderer::camera::Camera> camera;

/**
* Texture manager for central accessing and loading textures.
*
* TODO: Replace with asset manager
* Asset manager for central accessing and loading textures.
*/
std::shared_ptr<renderer::resources::AssetManager> asset_manager;

Expand Down
12 changes: 3 additions & 9 deletions libopenage/renderer/stages/terrain/terrain_render_entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,11 @@

namespace openage::renderer::terrain {

TerrainRenderEntity::TerrainRenderEntity(
// const std::shared_ptr<renderer::Renderer> &renderer,
// const util::Path &assetdir
) :
TerrainRenderEntity::TerrainRenderEntity() :
changed{false},
size{0, 0},
vertices{},
terrain_path{}
// renderer{renderer},
// assetdir{assetdir}
{
terrain_path{} {
}

void TerrainRenderEntity::update(util::Vector2s size,
Expand Down Expand Up @@ -74,7 +68,7 @@ const std::vector<coord::scene3> &TerrainRenderEntity::get_vertices() {
return this->vertices;
}

const util::Path &TerrainRenderEntity::get_texture_path() {
const util::Path &TerrainRenderEntity::get_terrain_path() {
std::shared_lock lock{this->mutex};

return this->terrain_path;
Expand Down
6 changes: 2 additions & 4 deletions libopenage/renderer/stages/terrain/terrain_render_entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class TerrainRenderEntity {
*
* @return Texture mapping of textures to vertex area.
*/
const util::Path &get_texture_path();
const util::Path &get_terrain_path();

/**
* Get the number of vertices on each side of the terrain.
Expand Down Expand Up @@ -82,13 +82,11 @@ class TerrainRenderEntity {

/**
* Terrain vertices (ingame coordinates).
*
* TODO: Use coordinate system.
*/
std::vector<coord::scene3> vertices;

/**
* Terrain texture-
* Path to the terrain definition file.
*
* TODO: Use texture mapping.
*/
Expand Down
2 changes: 1 addition & 1 deletion libopenage/renderer/stages/terrain/terrain_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ void TerrainRenderer::update() {
// TODO: Remove old renderable instead of clearing everything
this->render_pass->clear_renderables();
this->render_pass->add_renderables(display_obj);
mesh->clear_requires_renderable();

mesh->set_uniforms(transform_unifs);
mesh->clear_requires_renderable();
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions libopenage/renderer/stages/world/world_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void WorldObject::update(const curve::time_t &time) {
this->require_renderable = true;

// Update textures
auto anim_info = this->asset_manager->request_animation(this->render_entity->get_texture_path());
auto anim_info = this->asset_manager->request_animation(this->render_entity->get_animation_path());
auto tex_manager = this->asset_manager->get_texture_manager();
this->texture = tex_manager.request(anim_info->get_texture(0)->get_image_path().value());
// TODO: Support multiple textures per animation
Expand All @@ -71,7 +71,7 @@ void WorldObject::update(const curve::time_t &time) {
void WorldObject::update_uniforms(const curve::time_t &time) {
if (this->uniforms != nullptr) [[likely]] {
/* Frame subtexture */
auto anim_info = this->asset_manager->request_animation(this->render_entity->get_texture_path());
auto anim_info = this->asset_manager->request_animation(this->render_entity->get_animation_path());
auto layer = anim_info->get_layer(0); // TODO: Support multiple layers
auto angle = layer.get_angle(0); // TODO: Support multiple angles

Expand Down
10 changes: 5 additions & 5 deletions libopenage/renderer/stages/world/world_render_entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ namespace openage::renderer::world {
WorldRenderEntity::WorldRenderEntity() :
changed{false},
position{0.0f, 0.0f, 0.0f},
sprite_path{},
animation_path{},
last_update{0.0} {
}

void WorldRenderEntity::update(const uint32_t ref_id,
const coord::phys3 position,
const util::Path sprite_path,
const util::Path animation_path,
const curve::time_t time) {
std::unique_lock lock{this->mutex};

this->ref_id = ref_id;
this->position = position.to_scene3();
this->sprite_path = sprite_path;
this->animation_path = animation_path;
this->changed = true;
this->last_update = time;
}
Expand All @@ -36,10 +36,10 @@ const coord::scene3 WorldRenderEntity::get_position() {
return this->position;
}

const util::Path &WorldRenderEntity::get_texture_path() {
const util::Path &WorldRenderEntity::get_animation_path() {
std::shared_lock lock{this->mutex};

return this->sprite_path;
return this->animation_path;
}

curve::time_t WorldRenderEntity::get_update_time() {
Expand Down
14 changes: 6 additions & 8 deletions libopenage/renderer/stages/world/world_render_entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ class WorldRenderEntity {
*
* @param ref_id Game entity ID.
* @param position Position of the game entity inside the game world.
* @param sprite_path Path to the animation definition.
* @param animation_path Path to the animation definition.
* @param time Simulation time of the update.
*/
void update(const uint32_t ref_id,
const coord::phys3 position,
const util::Path sprite_path,
const util::Path animation_path,
const curve::time_t time = 0.0);

/**
Expand All @@ -45,13 +45,11 @@ class WorldRenderEntity {
const coord::scene3 get_position();

/**
* Get the texture path.
* Get the animation definition path.
*
* TODO: Return the animation.
*
* @return Path to the texture.
* @return Path to the animation definition file.
*/
const util::Path &get_texture_path();
const util::Path &get_animation_path();

/**
* Get the time of the last update.
Expand Down Expand Up @@ -94,7 +92,7 @@ class WorldRenderEntity {
/**
* Path to the texture.
*/
util::Path sprite_path;
util::Path animation_path;

/**
* Time of the last texture update.
Expand Down

0 comments on commit e66c57a

Please sign in to comment.