begin raylib
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
|
||||
namespace td {
|
||||
|
||||
static constexpr float PI = 3.141592653f;
|
||||
// static constexpr float PI = 3.141592653f;
|
||||
|
||||
template <typename T>
|
||||
struct Vec2 {
|
||||
|
||||
37
include/td/common/Event.h
Normal file
37
include/td/common/Event.h
Normal file
@@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
|
||||
namespace td {
|
||||
|
||||
class EventDispatcher;
|
||||
|
||||
class Event {
|
||||
|
||||
};
|
||||
|
||||
struct WindowResizeEvent {
|
||||
int m_Width;
|
||||
int m_Height;
|
||||
};
|
||||
|
||||
class EventDispatcher {
|
||||
public:
|
||||
EventDispatcher(const Event& event);
|
||||
|
||||
template<typename E>
|
||||
void Dispatch();
|
||||
};
|
||||
|
||||
// template<typename Event>
|
||||
// class ConcreteEvent : public Event {
|
||||
// public:
|
||||
// void Accept(EventDispatcher& a_Dispatcher) {
|
||||
// a_Dispatcher.Handle(*this);
|
||||
// }
|
||||
// };
|
||||
|
||||
void OnEvent(const Event& event) {
|
||||
EventDispatcher dispatcher(event);
|
||||
dispatcher.Dispatch<WindowResizeEvent>();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,8 +2,6 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <SDL3/SDL_keycode.h>
|
||||
#include <SDL3/SDL_video.h>
|
||||
#include <td/common/StateMachine.h>
|
||||
#include <td/misc/Signal.h>
|
||||
|
||||
@@ -11,17 +9,15 @@ namespace td {
|
||||
|
||||
class Display : public StateMachine<Display, void, float> {
|
||||
private:
|
||||
SDL_Window* m_Window;
|
||||
SDL_GLContext m_GLContext;
|
||||
|
||||
int m_LastWidth, m_LastHeight;
|
||||
int m_LastWidth;
|
||||
int m_LastHeight;
|
||||
float m_AspectRatio;
|
||||
|
||||
bool m_ShouldClose;
|
||||
|
||||
public:
|
||||
utils::Signal<float> OnAspectRatioChange;
|
||||
utils::Signal<SDL_Keycode> OnKeyDown;
|
||||
utils::Signal<int> OnKeyDown;
|
||||
|
||||
Display(int a_Width, int a_Height, const std::string& a_Title);
|
||||
~Display();
|
||||
|
||||
@@ -13,7 +13,7 @@ class DisplayState : public Display::State, private utils::SlotGuard {
|
||||
|
||||
protected:
|
||||
virtual void OnAspectRatioChange(float a_Ratio) {}
|
||||
virtual void OnKeyDown(SDL_Keycode a_Key) {}
|
||||
virtual void OnKeyDown(int a_Key) {}
|
||||
};
|
||||
|
||||
} // namespace td
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace td {
|
||||
class DebugWorldState : public DisplayState {
|
||||
private:
|
||||
render::RenderPipeline m_Renderer;
|
||||
render::Camera m_Camera;
|
||||
Camera m_Camera;
|
||||
std::unique_ptr<server::Server> m_Server;
|
||||
std::unique_ptr<client::Client> m_Client;
|
||||
client::GameState* m_ClientState;
|
||||
@@ -31,7 +31,7 @@ class DebugWorldState : public DisplayState {
|
||||
|
||||
protected:
|
||||
virtual void OnAspectRatioChange(float a_Ratio) override;
|
||||
virtual void OnKeyDown(SDL_Keycode a_Key) override;
|
||||
virtual void OnKeyDown(int a_Key) override;
|
||||
};
|
||||
|
||||
} // namespace td
|
||||
|
||||
@@ -21,7 +21,7 @@ class MainMenuState : public DisplayState, public MainMenuStateStack {
|
||||
void RenderBackButton();
|
||||
|
||||
protected:
|
||||
virtual void OnKeyDown(SDL_Keycode a_Key) override;
|
||||
virtual void OnKeyDown(int a_Key) override;
|
||||
};
|
||||
|
||||
} // namespace td
|
||||
|
||||
@@ -79,9 +79,10 @@ class Mob : public sp::MessageBase<MobType, MobHandler> {
|
||||
Vec2fp m_Position;
|
||||
Direction m_Direction;
|
||||
std::vector<EffectDuration> m_Effects;
|
||||
const Tower* m_LastDamage; // the last tower that damaged the mob
|
||||
std::shared_ptr<Tower> m_LastDamage; // the last tower that damaged the mob
|
||||
float m_HitCooldown;
|
||||
TeamCastle* m_CastleTarget;
|
||||
std::shared_ptr<TeamCastle> m_CastleTarget;
|
||||
bool m_HasReachedCastle = false;
|
||||
// utils::CooldownTimer m_AttackTimer;
|
||||
|
||||
MobPtr m_Next;
|
||||
|
||||
@@ -25,12 +25,12 @@ enum class TileType : std::uint8_t {
|
||||
Ice,*/
|
||||
};
|
||||
|
||||
static constexpr Color BLACK{0, 0, 0};
|
||||
static constexpr Color WHITE{255, 255, 255};
|
||||
// static constexpr Color BLACK(0, 0, 0);
|
||||
// static constexpr Color WHITE(255, 255, 255);
|
||||
|
||||
static constexpr Color RED{255, 0, 0};
|
||||
static constexpr Color GREEN{0, 255, 0};
|
||||
static constexpr Color BLUE{0, 0, 255};
|
||||
// static constexpr Color RED(255, 0, 0);
|
||||
// static constexpr Color GREEN(0, 255, 0);
|
||||
// static constexpr Color BLUE(0, 0, 255);
|
||||
|
||||
class TileHandler;
|
||||
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <td/Maths.h>
|
||||
#include <td/misc/Signal.h>
|
||||
|
||||
namespace td {
|
||||
namespace render {
|
||||
|
||||
class Camera {
|
||||
private:
|
||||
Mat4f m_ViewMatrix;
|
||||
Mat4f m_ProjectionMatrix;
|
||||
Mat4f m_InvViewMatrix;
|
||||
Mat4f m_InvProjectionMatrix;
|
||||
|
||||
float m_CamDistance = 25.0f;
|
||||
Vec3f m_CamPos{0, m_CamDistance, 0};
|
||||
Vec2f m_CamLook{};
|
||||
|
||||
float m_Yaw = -PI / 2.0f;
|
||||
float m_Pitch = -PI / 2.0f + 0.0000001f;
|
||||
|
||||
public:
|
||||
utils::Signal<> OnPerspectiveChange;
|
||||
utils::Signal<> OnViewChange;
|
||||
|
||||
const Mat4f& GetViewMatrix() const {
|
||||
return m_ViewMatrix;
|
||||
}
|
||||
|
||||
const Mat4f& GetProjectionMatrix() const {
|
||||
return m_ProjectionMatrix;
|
||||
}
|
||||
|
||||
void UpdatePerspective(float a_AspectRatio);
|
||||
|
||||
void SetCamPos(const Vec3f& a_NewPos);
|
||||
const Vec3f& GetCamPos() const;
|
||||
};
|
||||
|
||||
} // namespace render
|
||||
} // namespace td
|
||||
@@ -1,8 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef TD_GL_LOADER_GLEW
|
||||
#include <GL/glew.h>
|
||||
#else
|
||||
#include <glbinding/gl/gl.h>
|
||||
using namespace gl;
|
||||
#endif
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <td/render/Camera.h>
|
||||
#include <raylib.h>
|
||||
#include <td/render/loader/GLLoader.h>
|
||||
#include <td/render/shader/CameraShaderProgram.h>
|
||||
#include <td/misc/SlotGuard.h>
|
||||
@@ -66,15 +66,15 @@ class RenderPipeline {
|
||||
|
||||
template <typename TShader>
|
||||
Renderer<TShader>::Renderer(Camera& a_Camera) : m_Shader(std::make_unique<TShader>()), m_Camera(a_Camera) {
|
||||
Connect(a_Camera.OnPerspectiveChange, [this](){
|
||||
m_Shader->Start();
|
||||
m_Shader->SetProjectionMatrix(m_Camera.GetProjectionMatrix());
|
||||
});
|
||||
// Connect(a_Camera.OnPerspectiveChange, [this](){
|
||||
// // m_Shader->Start();
|
||||
// m_Shader->SetProjectionMatrix(m_Camera.GetProjectionMatrix());
|
||||
// });
|
||||
|
||||
Connect(a_Camera.OnViewChange, [this]() {
|
||||
m_Shader->Start();
|
||||
m_Shader->SetViewMatrix(m_Camera.GetViewMatrix());
|
||||
});
|
||||
// Connect(a_Camera.OnViewChange, [this]() {
|
||||
// // m_Shader->Start();
|
||||
// m_Shader->SetViewMatrix(m_Camera.GetViewMatrix());
|
||||
// });
|
||||
}
|
||||
|
||||
} // namespace render
|
||||
|
||||
@@ -1,22 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <td/game/World.h>
|
||||
#include <td/render/loader/GLLoader.h>
|
||||
#include <raylib.h>
|
||||
|
||||
namespace td {
|
||||
namespace render {
|
||||
|
||||
namespace WorldLoader {
|
||||
|
||||
struct RenderData {
|
||||
std::vector<float> positions;
|
||||
std::vector<float> colors;
|
||||
};
|
||||
|
||||
GL::VertexArray LoadMobModel();
|
||||
GL::VertexArray LoadWorldModel(const td::game::World* world);
|
||||
GL::VertexArray LoadTileSelectModel();
|
||||
RenderData LoadTowerModel(const game::TowerPtr& tower);
|
||||
Mesh LoadWorldModel(const td::game::World* world);
|
||||
|
||||
} // namespace WorldLoader
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <raylib.h>
|
||||
#include <td/render/Renderer.h>
|
||||
#include <td/render/shader/EntityShader.h>
|
||||
#include <td/game/World.h>
|
||||
@@ -10,7 +11,8 @@ namespace render {
|
||||
class EntityRenderer : public Renderer<shader::EntityShader> {
|
||||
private:
|
||||
game::WorldPtr m_World;
|
||||
std::unique_ptr<GL::VertexArray> m_EntityVao;
|
||||
Model m_ZombieModel;
|
||||
Texture2D m_ZombieTexture;
|
||||
|
||||
public:
|
||||
EntityRenderer(Camera& a_Camera, const game::WorldPtr& a_World);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <raylib.h>
|
||||
#include <td/render/Renderer.h>
|
||||
#include <td/render/shader/EntityShader.h>
|
||||
#include <td/game/World.h>
|
||||
@@ -10,7 +11,8 @@ namespace render {
|
||||
class TowerRenderer : public Renderer<shader::EntityShader> {
|
||||
private:
|
||||
game::WorldPtr m_World;
|
||||
std::unique_ptr<GL::VertexArray> m_EntityVao;
|
||||
Model m_TowerModel;
|
||||
Texture2D m_TowerTexture;
|
||||
|
||||
public:
|
||||
TowerRenderer(Camera& a_Camera, const game::WorldPtr& a_World);
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace render {
|
||||
|
||||
class WorldRenderer : public Renderer<shader::WorldShader> {
|
||||
private:
|
||||
std::unique_ptr<GL::VertexArray> m_WorldVao;
|
||||
Model m_WorldModel;
|
||||
|
||||
public:
|
||||
WorldRenderer(Camera& a_Camera, const game::WorldPtr& a_World);
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include <td/render/shader/ShaderProgram.h>
|
||||
#include <raylib.h>
|
||||
#include <td/Maths.h>
|
||||
|
||||
namespace td {
|
||||
namespace shader {
|
||||
|
||||
class CameraShaderProgram : public ShaderProgram {
|
||||
class CameraShaderProgram {
|
||||
private:
|
||||
unsigned int m_LocationProjection = 0, m_LocationView = 0;
|
||||
|
||||
public:
|
||||
CameraShaderProgram() {}
|
||||
CameraShaderProgram() {
|
||||
}
|
||||
|
||||
void SetProjectionMatrix(const Mat4f& proj) const;
|
||||
void SetViewMatrix(const Mat4f& view) const;
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <td/Maths.h>
|
||||
#include <td/render/OpenGL.h>
|
||||
|
||||
namespace td {
|
||||
namespace shader {
|
||||
|
||||
class ShaderProgram {
|
||||
public:
|
||||
ShaderProgram();
|
||||
virtual ~ShaderProgram();
|
||||
|
||||
void Start() const;
|
||||
void Stop() const;
|
||||
|
||||
protected:
|
||||
void LoadProgramFile(const std::string& vertexFile, const std::string& fragmentFile);
|
||||
void LoadProgram(const std::string& vertexSource, const std::string& fragmentSource);
|
||||
|
||||
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 Vec2f& vector) const;
|
||||
void LoadVector(unsigned int location, const Vec3f& vector) const;
|
||||
void LoadBoolean(unsigned int location, bool value) const;
|
||||
void LoadMat4(unsigned int location, const Mat4f& mat) 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);
|
||||
};
|
||||
|
||||
} // namespace shader
|
||||
} // namespace td
|
||||
Reference in New Issue
Block a user