2 Commits

Author SHA1 Message Date
550ff3aeec add basic camera controls 2026-01-01 20:58:28 +01:00
127fa1fcb8 add vec operations 2026-01-01 20:57:57 +01:00
11 changed files with 69 additions and 9827 deletions

View File

@@ -183,6 +183,51 @@ T Lerp(T v0, T v1, T t) {
} // namespace maths
template<typename T>
Vec2<T> operator+(const Vec2<T>& vect, const Vec2<T>& other) {
return {vect.x + other.x, vect.y + other.y};
}
template<typename T>
Vec2<T> operator- (const Vec2<T>& vect) {
return { -vect.x, -vect.y };
}
template<typename T>
Vec2<T> operator- (const Vec2<T>& vect, const Vec2<T>& other) {
return vect + (-other);
}
template<typename T>
Vec3<T> operator- (const Vec3<T>& vect) {
return { -vect.x, -vect.y, -vect.z };
}
template<typename T>
Vec3<T> operator+ (const Vec3<T>& vect, const Vec3<T>& other) {
return { vect.x + other.x, vect.y + other.y, vect.z + other.z };
}
template<typename T>
Vec3<T> operator- (const Vec3<T>& vect, const Vec3<T>& other) {
return vect + (-other);
}
template<typename T>
Vec4<T> operator- (const Vec4<T>& vect) {
return { -vect.x, -vect.y, -vect.z, -vect.w };
}
template<typename T>
Vec4<T> operator+ (const Vec4<T>& vect, const Vec4<T>& other) {
return { vect.x + other.x, vect.y + other.y, vect.z + other.z, vect.w + other.w };
}
template<typename T>
Vec4<T> operator- (const Vec4<T>& vect, const Vec4<T>& other) {
return vect + (-other);
}
template <typename T>
sp::DataBuffer& operator<<(sp::DataBuffer& a_Buffer, const Vec2<T>& a_Vec) {
return a_Buffer << a_Vec.x << a_Vec.y;

View File

@@ -1,127 +0,0 @@
#pragma once
#include <td/display/DisplayState.h>
#include <imgui_node_editor.h>
namespace ed = ax::NodeEditor;
namespace td {
class NodeEditorState : public DisplayState {
public:
enum class PinType {
Flow,
Bool,
Int,
Float,
String,
Object,
Function,
Delegate,
};
enum class PinKind { Output, Input };
enum class NodeType { Blueprint, Simple, Tree, Comment, Houdini };
struct Pin;
struct Node {
ed::NodeId ID;
std::string Name;
std::vector<Pin> Inputs;
std::vector<Pin> Outputs;
ImColor Color;
NodeType Type;
ImVec2 Size;
std::string State;
std::string SavedState;
Node(int id, const char* name, ImColor color = ImColor(255, 255, 255)) :
ID(id), Name(name), Color(color), Type(NodeType::Blueprint), Size(0, 0) {}
};
struct Pin {
ed::PinId ID;
::td::NodeEditorState::Node* Node;
std::string Name;
PinType Type;
PinKind Kind;
Pin(int id, const char* name, PinType type) : ID(id), Node(nullptr), Name(name), Type(type), Kind(PinKind::Input) {}
};
struct Link {
ed::LinkId ID;
ed::PinId StartPinID;
ed::PinId EndPinID;
ImColor Color;
Link(ed::LinkId id, ed::PinId startPinId, ed::PinId endPinId) :
ID(id), StartPinID(startPinId), EndPinID(endPinId), Color(255, 255, 255) {}
};
struct NodeIdLess {
bool operator()(const ed::NodeId& lhs, const ed::NodeId& rhs) const {
return lhs.AsPointer() < rhs.AsPointer();
}
};
int m_NextId = 1;
const int m_PinIconSize = 24;
std::vector<Node> m_Nodes;
std::vector<Link> m_Links;
ImTextureID m_HeaderBackground = 0;
ImTextureID m_SaveIcon = 0;
ImTextureID m_RestoreIcon = 0;
const float m_TouchTime = 1.0f;
std::map<ed::NodeId, float, NodeIdLess> m_NodeTouchTime;
bool m_ShowOrdinals = false;
public:
NodeEditorState(Display& a_Display);
~NodeEditorState();
virtual void Update(float a_Delta) override;
private:
int GetNextId();
ed::LinkId GetNextLinkId();
void TouchNode(ed::NodeId id);
float GetTouchProgress(ed::NodeId id);
void UpdateTouch();
Node* FindNode(ed::NodeId id);
Link* FindLink(ed::LinkId id);
Pin* FindPin(ed::PinId id);
bool IsPinLinked(ed::PinId id);
bool CanCreateLink(Pin* a, Pin* b);
void BuildNode(Node* node);
Node* SpawnInputActionNode();
Node* SpawnBranchNode();
Node* SpawnDoNNode();
Node* SpawnOutputActionNode();
Node* SpawnPrintStringNode();
Node* SpawnMessageNode();
Node* SpawnSetTimerNode();
Node* SpawnLessNode();
Node* SpawnWeirdNode();
Node* SpawnTraceByChannelNode();
Node* SpawnTreeSequenceNode();
Node* SpawnTreeTaskNode();
Node* SpawnTreeTask2Node();
Node* SpawnComment();
Node* SpawnHoudiniTransformNode();
Node* SpawnHoudiniGroupNode();
void BuildNodes();
ImColor GetIconColor(PinType type);
void DrawPinIcon(const Pin& pin, bool connected, int alpha);
void ShowStyleEditor(bool* show = nullptr);
void ShowLeftPane(float paneWidth);
};
} // namespace td

View File

@@ -35,6 +35,7 @@ class Camera {
void UpdatePerspective(float a_AspectRatio);
void SetCamPos(const Vec3f& a_NewPos);
const Vec3f& GetCamPos() const;
};
} // namespace render

View File

@@ -17,6 +17,9 @@ class WorldRenderer : public Renderer<shader::WorldShader> {
virtual ~WorldRenderer();
virtual void Render(float a_Lerp) override;
private:
void UpdateControls();
};
} // namespace render

View File

@@ -1,6 +0,0 @@
target("imgui-node-editor")
set_kind("static")
add_files("imgui-node-editor/**.cpp")
add_includedirs("imgui-node-editor", {public = true})
add_packages("imgui")

View File

@@ -1,12 +1,12 @@
#include <chrono>
#include <td/display/state/NodeEditorState.h>
#include <td/display/state/MainMenuState.h>
#include <td/misc/Time.h>
int main(int argc, char** argv) {
// init GL context
td::Display display(1920, 1080, "Tower-Defense 2");
display.ChangeState<td::NodeEditorState>();
display.ChangeState<td::MainMenuState>();
td::Timer timer;
while (!display.IsCloseRequested()) {

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,3 +1,4 @@
#include "td/Maths.h"
#include <td/render/Camera.h>
#include <cmath>
@@ -24,5 +25,9 @@ void Camera::SetCamPos(const Vec3f& a_NewPos) {
OnViewChange();
}
const Vec3f& Camera::GetCamPos() const {
return m_CamPos;
}
} // namespace render
} // namespace td

View File

@@ -1,3 +1,4 @@
#include <td/Maths.h>
#include <td/render/renderer/WorldRenderer.h>
#include <td/render/loader/WorldLoader.h>
@@ -13,7 +14,17 @@ WorldRenderer::WorldRenderer(Camera& a_Camera, const game::WorldPtr& a_World) :
WorldRenderer::~WorldRenderer() {}
void WorldRenderer::UpdateControls() {
if (ImGui::IsMouseDown(ImGuiMouseButton_Left)) {
constexpr float sensitivity = 1.0f;
float delta = ImGui::GetIO().DeltaTime;
auto mouseDelta = ImGui::GetIO().MouseDelta;
m_Camera.SetCamPos(m_Camera.GetCamPos() + Vec3f{-mouseDelta.x * delta * sensitivity, 0, -mouseDelta.y * delta * sensitivity});
}
}
void WorldRenderer::Render(float a_Lerp) {
UpdateControls();
m_Shader->Start();
Renderer::Render(*m_WorldVao);
}

View File

@@ -2,7 +2,8 @@ add_rules("mode.debug", "mode.release")
add_repositories("persson-repo https://git.ale-pri.com/Persson-dev/xmake-repo.git")
add_requires("imgui[sdl3,opengl3] 1.92.1", "splib 2.3.2", "zlib", "glew", "fpm", "enet6")
add_requires("imgui 1.92.0", {configs = {sdl3 = true, opengl3 = true}})
add_requires("libsdl3 3.2.16", "splib 2.3.2", "zlib", "glew", "fpm", "enet6")
set_languages("c++20")
@@ -16,8 +17,6 @@ else
set_policy("build.sanitizer.undefined", true)
end
includes("lib/*.lua")
target("Tower-Defense2")
add_includedirs("include", {public = true})
set_kind("binary")
@@ -25,7 +24,6 @@ target("Tower-Defense2")
add_packages("libsdl3", "imgui", "glew", "splib", "zlib", "fpm", "enet6", {public = true})
set_rundir(".")
add_defines("TD_GL_LOADER_GLEW")
add_deps("imgui-node-editor")
-- Tests