temp tower rendering

This commit is contained in:
2025-07-28 18:11:17 +02:00
parent da1586baed
commit 4c2ac7e3f0
4 changed files with 68 additions and 1 deletions

View File

@@ -83,4 +83,16 @@ sp::DataBuffer& operator<<(sp::DataBuffer& a_Buffer, const FpFloat& a_Float);
sp::DataBuffer& operator>>(sp::DataBuffer& a_Buffer, EntityCoords& a_Coords); sp::DataBuffer& operator>>(sp::DataBuffer& a_Buffer, EntityCoords& a_Coords);
sp::DataBuffer& operator>>(sp::DataBuffer& a_Buffer, FpFloat& a_Float); sp::DataBuffer& operator>>(sp::DataBuffer& a_Buffer, FpFloat& a_Float);
inline TowerType& operator>>=(TowerType& a_Type, std::size_t a_Offset) {
return a_Type;
}
inline TowerType operator&(const TowerType& a_Type, std::size_t a_Offset) {
return a_Type;
}
inline TowerType& operator&=(TowerType& a_Type, std::size_t a_Offset) {
return a_Type;
}
} // namespace td } // namespace td

View File

@@ -0,0 +1,23 @@
#pragma once
#include <td/render/Renderer.h>
#include <td/render/shader/EntityShader.h>
#include <td/game/World.h>
namespace td {
namespace render {
class TowerRenderer : public Renderer<shader::EntityShader> {
private:
const game::World& m_World;
std::unique_ptr<GL::VertexArray> m_EntityVao;
public:
TowerRenderer(Camera& a_Camera, const game::World& a_World);
virtual ~TowerRenderer();
virtual void Render(float a_Lerp) override;
};
} // namespace render
} // namespace td

View File

@@ -10,6 +10,7 @@
#include <td/render/renderer/EntityRenderer.h> #include <td/render/renderer/EntityRenderer.h>
#include <td/render/renderer/WorldRenderer.h> #include <td/render/renderer/WorldRenderer.h>
#include <td/render/renderer/TowerRenderer.h>
#include <td/simulation/RealTimeSimulation.h> #include <td/simulation/RealTimeSimulation.h>
@@ -74,6 +75,9 @@ td::sim::GameHistory GetCustomHistory() {
auto spawn = std::make_shared<td::protocol::commands::SpawnTroopCommand>(0, 0, td::Vec2fp{td::FpFloat(77), td::FpFloat(13)}, 0); auto spawn = std::make_shared<td::protocol::commands::SpawnTroopCommand>(0, 0, td::Vec2fp{td::FpFloat(77), td::FpFloat(13)}, 0);
gh[0].push_back(spawn); gh[0].push_back(spawn);
auto tower = std::make_shared<td::protocol::commands::PlaceTowerCommand>(td::TowerType::Archer, 0, td::TowerCoords{77, 13});
gh[0].push_back(tower);
return gh; return gh;
} }
@@ -94,11 +98,12 @@ int main(int argc, char** argv) {
td::render::RenderPipeline renderer; td::render::RenderPipeline renderer;
renderer.AddRenderer<td::render::WorldRenderer>(cam, w); renderer.AddRenderer<td::render::WorldRenderer>(cam, w);
renderer.AddRenderer<td::render::EntityRenderer>(cam, w); renderer.AddRenderer<td::render::EntityRenderer>(cam, w);
renderer.AddRenderer<td::render::TowerRenderer>(cam, w);
cam.SetCamPos({77, 5, 13}); cam.SetCamPos({77, 5, 13});
cam.UpdatePerspective(display.GetAspectRatio()); cam.UpdatePerspective(display.GetAspectRatio());
td::sim::RealTimeSimulation simulation(w, std::move(gh), 2000); td::sim::RealTimeSimulation simulation(w, std::move(gh), 500);
while (!display.IsCloseRequested()) { while (!display.IsCloseRequested()) {
display.PollEvents(); display.PollEvents();

View File

@@ -0,0 +1,27 @@
#include <td/render/renderer/TowerRenderer.h>
#include <td/render/loader/WorldLoader.h>
namespace td {
namespace render {
TowerRenderer::TowerRenderer(Camera& a_Camera, const game::World& a_World) : Renderer(a_Camera), m_World(a_World) {
m_EntityVao = std::make_unique<GL::VertexArray>(WorldLoader::LoadMobModel());
m_Shader->Start();
m_Shader->SetColorEffect({0, 0, 1});
}
TowerRenderer::~TowerRenderer() {}
void TowerRenderer::Render(float a_Lerp) {
m_Shader->Start();
for (const auto& tower : m_World.GetTowers()) {
m_Shader->SetModelPos({tower->GetCenterX(), 1, tower->GetCenterY()});
Renderer::Render(*m_EntityVao);
}
}
} // namespace render
} // namespace td