Compare commits
2 Commits
lua
...
550ff3aeec
| Author | SHA1 | Date | |
|---|---|---|---|
|
550ff3aeec
|
|||
|
127fa1fcb8
|
@@ -183,6 +183,51 @@ T Lerp(T v0, T v1, T t) {
|
|||||||
|
|
||||||
} // namespace maths
|
} // 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>
|
template <typename T>
|
||||||
sp::DataBuffer& operator<<(sp::DataBuffer& a_Buffer, const Vec2<T>& a_Vec) {
|
sp::DataBuffer& operator<<(sp::DataBuffer& a_Buffer, const Vec2<T>& a_Vec) {
|
||||||
return a_Buffer << a_Vec.x << a_Vec.y;
|
return a_Buffer << a_Vec.x << a_Vec.y;
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ class Camera {
|
|||||||
void UpdatePerspective(float a_AspectRatio);
|
void UpdatePerspective(float a_AspectRatio);
|
||||||
|
|
||||||
void SetCamPos(const Vec3f& a_NewPos);
|
void SetCamPos(const Vec3f& a_NewPos);
|
||||||
|
const Vec3f& GetCamPos() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace render
|
} // namespace render
|
||||||
|
|||||||
@@ -17,6 +17,9 @@ class WorldRenderer : public Renderer<shader::WorldShader> {
|
|||||||
virtual ~WorldRenderer();
|
virtual ~WorldRenderer();
|
||||||
|
|
||||||
virtual void Render(float a_Lerp) override;
|
virtual void Render(float a_Lerp) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void UpdateControls();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace render
|
} // namespace render
|
||||||
|
|||||||
70
src/main.cpp
70
src/main.cpp
@@ -1,68 +1,18 @@
|
|||||||
// #include <chrono>
|
#include <chrono>
|
||||||
// #include <td/display/state/MainMenuState.h>
|
#include <td/display/state/MainMenuState.h>
|
||||||
// #include <td/misc/Time.h>
|
#include <td/misc/Time.h>
|
||||||
|
|
||||||
#define SOL_ALL_SAFETIES_ON 1
|
|
||||||
#include <sol/sol.hpp>
|
|
||||||
|
|
||||||
void some_function() {
|
|
||||||
std::cout << "some function!" << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
void some_other_function() {
|
|
||||||
std::cout << "some other function!" << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct some_class {
|
|
||||||
int variable = 30;
|
|
||||||
|
|
||||||
double member_function() {
|
|
||||||
return 24.5;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
// init GL context
|
// init GL context
|
||||||
// td::Display display(1920, 1080, "Tower-Defense 2");
|
td::Display display(1920, 1080, "Tower-Defense 2");
|
||||||
|
|
||||||
// display.ChangeState<td::MainMenuState>();
|
display.ChangeState<td::MainMenuState>();
|
||||||
|
|
||||||
// td::Timer timer;
|
td::Timer timer;
|
||||||
// while (!display.IsCloseRequested()) {
|
while (!display.IsCloseRequested()) {
|
||||||
// display.PollEvents();
|
display.PollEvents();
|
||||||
// display.Update(timer.GetDelta());
|
display.Update(timer.GetDelta());
|
||||||
// }
|
}
|
||||||
|
|
||||||
std::cout << "=== functions (all) ===" << std::endl;
|
|
||||||
|
|
||||||
sol::state lua;
|
|
||||||
lua.open_libraries(sol::lib::base);
|
|
||||||
|
|
||||||
// put an instance of "some_class" into lua
|
|
||||||
// (we'll go into more detail about this later
|
|
||||||
// just know here that it works and is
|
|
||||||
// put into lua as a userdata
|
|
||||||
lua.set("sc", some_class());
|
|
||||||
|
|
||||||
// binds a plain function
|
|
||||||
lua["f1"] = some_function;
|
|
||||||
lua.set_function("f2", &some_other_function);
|
|
||||||
|
|
||||||
// binds just the member function
|
|
||||||
lua["m1"] = &some_class::member_function;
|
|
||||||
|
|
||||||
// binds the class to the type
|
|
||||||
lua.set_function("m2", &some_class::member_function, some_class{});
|
|
||||||
|
|
||||||
// binds just the member variable as a function
|
|
||||||
lua["v1"] = &some_class::variable;
|
|
||||||
|
|
||||||
// binds class with member variable as function
|
|
||||||
lua.set_function("v2", &some_class::variable, some_class{});
|
|
||||||
|
|
||||||
lua.script_file("test/main.lua");
|
|
||||||
|
|
||||||
std::cout << std::endl;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#include "td/Maths.h"
|
||||||
#include <td/render/Camera.h>
|
#include <td/render/Camera.h>
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
@@ -24,5 +25,9 @@ void Camera::SetCamPos(const Vec3f& a_NewPos) {
|
|||||||
OnViewChange();
|
OnViewChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const Vec3f& Camera::GetCamPos() const {
|
||||||
|
return m_CamPos;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace render
|
} // namespace render
|
||||||
} // namespace td
|
} // namespace td
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#include <td/Maths.h>
|
||||||
#include <td/render/renderer/WorldRenderer.h>
|
#include <td/render/renderer/WorldRenderer.h>
|
||||||
|
|
||||||
#include <td/render/loader/WorldLoader.h>
|
#include <td/render/loader/WorldLoader.h>
|
||||||
@@ -13,7 +14,17 @@ WorldRenderer::WorldRenderer(Camera& a_Camera, const game::WorldPtr& a_World) :
|
|||||||
|
|
||||||
WorldRenderer::~WorldRenderer() {}
|
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) {
|
void WorldRenderer::Render(float a_Lerp) {
|
||||||
|
UpdateControls();
|
||||||
m_Shader->Start();
|
m_Shader->Start();
|
||||||
Renderer::Render(*m_WorldVao);
|
Renderer::Render(*m_WorldVao);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,24 +0,0 @@
|
|||||||
f1() -- some function!
|
|
||||||
f2() -- some other function!
|
|
||||||
|
|
||||||
-- need class instance if you don't bind it with the function
|
|
||||||
print(m1(sc)) -- 24.5
|
|
||||||
-- does not need class instance: was bound to lua with one
|
|
||||||
print(m2()) -- 24.5
|
|
||||||
|
|
||||||
-- need class instance if you
|
|
||||||
-- don't bind it with the function
|
|
||||||
print(v1(sc)) -- 30
|
|
||||||
-- does not need class instance:
|
|
||||||
-- it was bound with one
|
|
||||||
print(v2()) -- 30
|
|
||||||
|
|
||||||
-- can set, still
|
|
||||||
-- requires instance
|
|
||||||
v1(sc, 212)
|
|
||||||
-- can set, does not need
|
|
||||||
-- class instance: was bound with one
|
|
||||||
v2(254)
|
|
||||||
|
|
||||||
print(v1(sc)) -- 212
|
|
||||||
print(v2()) -- 254
|
|
||||||
@@ -3,7 +3,7 @@ add_rules("mode.debug", "mode.release")
|
|||||||
add_repositories("persson-repo https://git.ale-pri.com/Persson-dev/xmake-repo.git")
|
add_repositories("persson-repo https://git.ale-pri.com/Persson-dev/xmake-repo.git")
|
||||||
|
|
||||||
add_requires("imgui 1.92.0", {configs = {sdl3 = true, opengl3 = true}})
|
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", "sol2")
|
add_requires("libsdl3 3.2.16", "splib 2.3.2", "zlib", "glew", "fpm", "enet6")
|
||||||
|
|
||||||
set_languages("c++20")
|
set_languages("c++20")
|
||||||
|
|
||||||
@@ -21,7 +21,7 @@ target("Tower-Defense2")
|
|||||||
add_includedirs("include", {public = true})
|
add_includedirs("include", {public = true})
|
||||||
set_kind("binary")
|
set_kind("binary")
|
||||||
add_files("src/**.cpp")
|
add_files("src/**.cpp")
|
||||||
add_packages("libsdl3", "imgui", "glew", "splib", "zlib", "fpm", "enet6", "sol2", {public = true})
|
add_packages("libsdl3", "imgui", "glew", "splib", "zlib", "fpm", "enet6", {public = true})
|
||||||
set_rundir(".")
|
set_rundir(".")
|
||||||
add_defines("TD_GL_LOADER_GLEW")
|
add_defines("TD_GL_LOADER_GLEW")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user