GIGA REFACTOR

This commit is contained in:
2022-03-02 18:51:42 +01:00
parent 553b2f6aad
commit 6df59b1487
92 changed files with 1807 additions and 1785 deletions

View File

@@ -1,12 +1,4 @@
/*
* Renderer.h
*
* Created on: 4 nov. 2020
* Author: simon
*/
#ifndef RENDER_RENDERER_H_
#define RENDER_RENDERER_H_
#pragma once
#include <glm/glm.hpp>
#include <memory>
@@ -26,8 +18,8 @@ public:
glm::vec2 positon;
};
private:
std::unique_ptr<WorldShader> m_WorldShader;
std::unique_ptr<EntityShader> m_EntityShader;
std::unique_ptr<shader::WorldShader> m_WorldShader;
std::unique_ptr<shader::EntityShader> m_EntityShader;
glm::vec3 m_BackgroundColor;
@@ -38,29 +30,27 @@ public:
Renderer();
~Renderer();
bool init();
bool Init();
void prepare();
void resize(const int width, const int height);
void Prepare();
void Resize(const int width, const int height);
void renderVAO(const GL::VertexArray& vao);
void renderModel(const Model& model);
void RenderVAO(const GL::VertexArray& vao);
void RenderModel(const Model& model);
void setZoom(float zoom);
void setCamMovement(const glm::vec2& mov);
void setCamPos(const glm::vec2& newPos);
void setIsometricView(bool isometric); // false = 2D true = Isometric
void SetZoom(float zoom);
void SetCamMovement(const glm::vec2& mov);
void SetCamPos(const glm::vec2& newPos);
void SetIsometricView(bool isometric); // false = 2D true = Isometric
void setBackgroundColor(const glm::vec3& color) { m_BackgroundColor = color; }
void SetBackgroundColor(const glm::vec3& color) { m_BackgroundColor = color; }
glm::vec2 getCursorWorldPos(const glm::vec2& cursorPos, float aspectRatio, float zoom, float windowWidth, float windowHeight);
glm::vec2 GetCursorWorldPos(const glm::vec2& cursorPos, float aspectRatio, float zoom, float windowWidth, float windowHeight);
private:
void updateIsometricView();
void updateIsometricFade();
void initShader();
void UpdateIsometricView();
void UpdateIsometricFade();
void InitShaders();
};
} // namespace render
} // namespace td
#endif /* RENDER_RENDERER_H_ */

View File

@@ -25,13 +25,13 @@ private:
public:
VertexCache() : m_VertexCount(0) {}
void addData(std::uint64_t index, std::vector<float> positions, std::vector<float> colors);
void removeData(std::uint64_t index);
void clear();
void updateVertexArray();
void AddData(std::uint64_t index, std::vector<float> positions, std::vector<float> colors);
void RemoveData(std::uint64_t index);
void Clear();
void UpdateVertexArray();
const GL::VertexArray& getVertexArray() const { return *m_VertexArray; }
bool isEmpty() const { return m_VertexArray == nullptr; }
const GL::VertexArray& GetVertexArray() const { return *m_VertexArray; }
bool IsEmpty() const { return m_VertexArray == nullptr; }
};
} // namespace render

View File

@@ -46,41 +46,41 @@ public:
WorldRenderer(game::World* world, client::ClientGame* client);
~WorldRenderer();
void loadModels();
void LoadModels();
static ImVec4 getImGuiTeamColor(game::TeamColor color);
static ImVec4 GetImGuiTeamColor(game::TeamColor color);
void update();
void render();
void Update();
void Render();
void setCamPos(float camX, float camY);
void SetCamPos(float camX, float camY);
void moveCam(float relativeX, float relativeY, float aspectRatio);
void changeZoom(float zoom);
void MoveCam(float relativeX, float relativeY, float aspectRatio);
void ChangeZoom(float zoom);
// WorldListener
virtual void OnTowerAdd(game::TowerPtr tower);
virtual void OnTowerRemove(game::TowerPtr tower);
private:
void click();
void renderWorld() const;
void renderTowers() const;
void renderMobs() const;
void renderTileSelect() const;
void renderPopups();
void renderTowerUpgradePopup();
void renderMobTooltip() const;
void renderCastleTooltip() const;
void detectClick();
void detectMobHovering() const;
void detectCastleHovering() const;
void renderTooltips() const;
void removeTower();
glm::vec2 getCursorWorldPos() const;
glm::vec2 getClickWorldPos() const;
void Click();
void RenderWorld() const;
void RenderTowers() const;
void RenderMobs() const;
void RenderTileSelect() const;
void RenderPopups();
void RenderTowerUpgradePopup();
void RenderMobTooltip() const;
void RenderCastleTooltip() const;
void DetectClick();
void DetectMobHovering() const;
void DetectCastleHovering() const;
void RenderTooltips() const;
void RemoveTower();
glm::vec2 GetCursorWorldPos() const;
glm::vec2 GetClickWorldPos() const;
void updateCursorPos();
void UpdateCursorPos();
};
} // namespace render

View File

@@ -18,10 +18,10 @@ private:
public:
CastleTooltip(client::Client* client);
virtual void render();
virtual void Render();
void setCastle(const game::TeamCastle* castle) { m_Castle = castle; }
bool isShown() { return m_Castle != nullptr; }
void SetCastle(const game::TeamCastle* castle) { m_Castle = castle; }
bool IsShown() { return m_Castle != nullptr; }
};
} // namespace gui

View File

@@ -13,7 +13,7 @@ private:
public:
FrameMenu(client::Client* client);
virtual void render();
virtual void Render();
};
} // namespace gui

View File

@@ -11,13 +11,13 @@ private:
public:
GameMenu(client::Client* client);
virtual void render();
virtual void Render();
private:
void showTPS();
void showStats();
void showPlayers();
void showLobbyProgress();
void showTeamSelection();
void ShowTPS();
void ShowStats();
void ShowPlayers();
void ShowLobbyProgress();
void ShowTeamSelection();
};
} // namespace gui

View File

@@ -12,15 +12,15 @@ class GuiManager {
private:
std::vector<std::unique_ptr<GuiWidget>> m_Widgets;
public:
GuiManager(){}
GuiManager() {}
void renderWidgets() {
void RenderWidgets() {
for (auto& widget : m_Widgets) {
widget->render();
widget->Render();
}
}
void addWidget(std::unique_ptr<GuiWidget>&& widget) {
void AddWidget(std::unique_ptr<GuiWidget>&& widget) {
m_Widgets.push_back(std::move(widget));
}
};

View File

@@ -14,9 +14,9 @@ protected:
public:
GuiWidget(client::Client* client) : m_Client(client) {}
client::Client* getClient() { return m_Client; }
client::Client* GetClient() { return m_Client; }
virtual void render() = 0;
virtual void Render() = 0;
};
} // namespace gui

View File

@@ -26,11 +26,11 @@ public:
MainMenu(client::Client* client);
~MainMenu();
virtual void render();
virtual void Render();
const server::Server* getServer() const { return m_Server.get(); }
const server::Server* GetServer() const { return m_Server.get(); }
private:
bool startServer();
bool StartServer();
};
} // namespace gui

View File

@@ -18,10 +18,10 @@ private:
public:
MobTooltip(client::Client* client);
virtual void render();
virtual void Render();
void setMob(const game::Mob* mob) { m_Mob = mob; }
bool isShown() { return m_Mob != nullptr; }
void SetMob(const game::Mob* mob) { m_Mob = mob; }
bool IsShown() { return m_Mob != nullptr; }
};
} // namespace gui

View File

@@ -17,9 +17,9 @@ private:
public:
SummonMenu(client::Client* client);
virtual void render();
virtual void Render();
private:
void setSummonMax(int valueIndex);
void SetSummonMax(int valueIndex);
};
} // namespace gui

View File

@@ -37,12 +37,12 @@ public:
TowerGui(SDL_Window* wndow, SDL_GLContext glContext, td::render::Renderer* renderer);
~TowerGui();
void render();
void Render();
private:
void initWidgets();
void tick();
void beginFrame();
void endFrame();
void InitWidgets();
void Tick();
void BeginFrame();
void EndFrame();
};
} // namespace render

View File

@@ -13,9 +13,9 @@ private:
public:
TowerPlacePopup(client::Client* client);
virtual void render();
virtual void Render();
void setClickPos(const glm::vec2& worldPos);
void SetClickPos(const glm::vec2& worldPos);
private:
static constexpr float m_TowerPopupTileWidth = 200.0f;
static constexpr float m_TowerPopupTileHeight = 200.0f;

View File

@@ -18,11 +18,11 @@ private:
public:
UpdateMenu(client::Client* client);
virtual void render();
virtual void Render();
private:
void checkUpdates();
bool isUpdateChecked();
void renderErrorPopup();
void CheckUpdates();
bool IsUpdateChecked();
void RenderErrorPopup();
};
} // namespace gui

View File

@@ -28,6 +28,7 @@ private:
std::vector<VertexAttribPointer> m_VertexAttribs;
public:
REMOVE_COPY(VertexBuffer);
VertexBuffer(VertexBuffer&& other) {
m_VertexAttribs = std::move(other.m_VertexAttribs);
m_ID = other.m_ID;
@@ -35,12 +36,14 @@ public:
other.m_ID = 0;
other.m_DataStride = 0;
}
VertexBuffer(const std::vector<float>& data, unsigned int stride);
~VertexBuffer();
void bind() const;
void unbind() const;
void addVertexAttribPointer(unsigned int index, unsigned int coordinateSize, unsigned int offset);
void bindVertexAttribs() const;
void Bind() const;
void Unbind() const;
void AddVertexAttribPointer(unsigned int index, unsigned int coordinateSize, unsigned int offset);
void BindVertexAttribs() const;
};
class VertexArray {
@@ -49,6 +52,7 @@ private:
std::vector<VertexBuffer> m_VertexBuffers; //use to destroy vbos when become unused
public:
REMOVE_COPY(VertexArray);
VertexArray(VertexArray&& other) {
m_ID = other.m_ID;
m_VertexCount = other.m_VertexCount;
@@ -56,12 +60,14 @@ public:
other.m_VertexCount = 0;
other.m_ID = 0;
}
VertexArray(unsigned int vertexCount);
~VertexArray();
unsigned int getVertexCount() const { return m_VertexCount; }
void bindVertexBuffer(VertexBuffer& vbo);
void bind() const;
void unbind() const;
unsigned int GetVertexCount() const { return m_VertexCount; }
void BindVertexBuffer(VertexBuffer& vbo);
void Bind() const;
void Unbind() const;
};
}

View File

@@ -10,7 +10,7 @@
namespace TextureLoader {
unsigned int loadGLTexture(const char* fileName);
unsigned int LoadGLTexture(const char* fileName);
}

View File

@@ -13,10 +13,10 @@ struct RenderData {
std::vector<float> colors;
};
GL::VertexArray loadMobModel();
GL::VertexArray loadWorldModel(const td::game::World* world);
GL::VertexArray loadTileSelectModel();
RenderData loadTowerModel(game::TowerPtr tower);
GL::VertexArray LoadMobModel();
GL::VertexArray LoadWorldModel(const td::game::World* world);
GL::VertexArray LoadTileSelectModel();
RenderData LoadTowerModel(game::TowerPtr tower);
} // namespace WorldLoader

View File

@@ -2,17 +2,29 @@
#include "ShaderProgram.h"
namespace td {
namespace shader {
class EntityShader : public ShaderProgram {
private:
unsigned int location_cam = 0, location_zoom = 0, location_aspect_ratio = 0, location_translation = 0, location_viewtype = 0;
unsigned int m_LocationCam = 0;
unsigned int m_LocationZoom = 0;
unsigned int m_LocationAspectRatio = 0;
unsigned int m_LocationTranslation = 0;
unsigned int m_LocationViewtype = 0;
protected:
void getAllUniformLocation();
virtual void GetAllUniformLocation();
public:
EntityShader();
void loadShader();
void setCamPos(const glm::vec2& camPos);
void setZoom(float zoom);
void setAspectRatio(float aspectRatio);
void setModelPos(const glm::vec2& modelPos);
void setIsometricView(float isometric);
void LoadShader();
void SetCamPos(const glm::vec2& camPos);
void SetZoom(float zoom);
void SetAspectRatio(float aspectRatio);
void SetModelPos(const glm::vec2& modelPos);
void SetIsometricView(float isometric);
};
} // namespace shader
} // namespace td

View File

@@ -1,46 +1,44 @@
/*
* ShaderProgram.h
*
* Created on: 31 janv. 2020
* Author: simon
*/
#ifndef RENDER_SHADERS_SHADERPROGRAM_H_
#define RENDER_SHADERS_SHADERPROGRAM_H_
#pragma once
#include <string>
#include <glm/glm.hpp>
#include "render/GL.h"
namespace td {
namespace shader {
class ShaderProgram {
public:
ShaderProgram();
virtual ~ShaderProgram();
void start() const;
void stop() const;
void loadProgramFile(const std::string& vertexFile, const std::string& fragmentFile);
void loadProgram(const std::string& vertexSource, const std::string& fragmentSource);
void Start() const;
void Stop() const;
void LoadProgramFile(const std::string& vertexFile, const std::string& fragmentFile);
void LoadProgram(const std::string& vertexSource, const std::string& fragmentSource);
protected:
virtual void getAllUniformLocation() = 0;
int getUniformLocation(const std::string& uniformName) const;
virtual void GetAllUniformLocation() = 0;
int GetUniformLocation(const std::string& uniformName) const;
void loadFloat(unsigned int location, float value) const;
void loadInt(unsigned int location, int value) const;
void loadVector(unsigned int location, const glm::vec2& vector) const;
void loadVector(unsigned int location, const glm::vec3& vector) const;
void loadVector(unsigned int location, const glm::vec4& vector) const;
void loadBoolean(unsigned int location, bool value) const;
void loadMatrix(unsigned int location, const glm::mat4& matrix) const;
void cleanUp() const;
void LoadFloat(unsigned int location, float value) const;
void LoadInt(unsigned int location, int value) const;
void LoadVector(unsigned int location, const glm::vec2& vector) const;
void LoadVector(unsigned int location, const glm::vec3& vector) const;
void LoadVector(unsigned int location, const glm::vec4& vector) const;
void LoadBoolean(unsigned int location, bool value) const;
void LoadMatrix(unsigned int location, const glm::mat4& matrix) const;
void CleanUp() const;
private:
unsigned int m_ProgramID;
unsigned int m_VertexShaderID;
unsigned int m_FragmentShaderID;
unsigned int loadShaderFromFile(const std::string& file, GLenum type);
unsigned int loadShader(const std::string& source, GLenum type);
unsigned int LoadShaderFromFile(const std::string& file, GLenum type);
unsigned int LoadShader(const std::string& source, GLenum type);
};
#endif /* RENDER_SHADERS_SHADERPROGRAM_H_ */
} // namespace shader
} // namespace td

View File

@@ -1,27 +1,23 @@
/*
* GameShader.h
*
* Created on: 4 nov. 2020
* Author: simon
*/
#ifndef RENDER_SHADERS_GAMESHADER_H_
#define RENDER_SHADERS_GAMESHADER_H_
#pragma once
#include "ShaderProgram.h"
namespace td {
namespace shader {
class WorldShader : public ShaderProgram {
private:
unsigned int location_cam = 0, location_zoom = 0, location_aspect_ratio = 0, location_viewtype = 0;
unsigned int m_LocationCam = 0, m_LocationZoom = 0, m_LocationAspectRatio = 0, m_LocationViewtype = 0;
protected:
void getAllUniformLocation();
void GetAllUniformLocation();
public:
WorldShader();
void loadShader();
void setCamPos(const glm::vec2& camPos);
void setZoom(float zoom);
void setAspectRatio(float aspectRatio);
void setIsometricView(float isometric);
void LoadShader();
void SetCamPos(const glm::vec2& camPos);
void SetZoom(float zoom);
void SetAspectRatio(float aspectRatio);
void SetIsometricView(float isometric);
};
#endif /* RENDER_SHADERS_GAMESHADER_H_ */
} // namespace shader
} // namespace td