diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 207649f8..7b758b8e 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -31,7 +31,7 @@ jobs:
run: |
sudo apt update
sudo apt upgrade -y
- sudo apt install -y build-essential wget cmake libvpx-dev gcc-11 libgl1-mesa-glx libgl1-mesa-dev libglew-dev ninja-build python3-pip libx11-dev libx11-xcb-dev libfontenc-dev libice-dev libsm-dev libxau-dev libxaw7-dev libxcomposite-dev libxcursor-dev libxdamage-dev libxdmcp-dev libxext-dev libxfixes-dev libxft-dev libxi-dev libxinerama-dev libxkbfile-dev libxmu-dev libxmuu-dev libxpm-dev libxrandr-dev libxrender-dev libxres-dev libxss-dev libxt-dev libxtst-dev libxv-dev libxvmc-dev libxxf86vm-dev xtrans-dev libxcb-render0-dev libxcb-render-util0-dev libxcb-xkb-dev libxcb-icccm4-dev libxcb-image0-dev libxcb-keysyms1-dev libxcb-randr0-dev libxcb-shape0-dev libxcb-sync-dev libxcb-xfixes0-dev libxcb-xinerama0-dev xkb-data libxcb-dri3-dev uuid-dev libxcb-util-dev
+ sudo apt install -y build-essential wget cmake libssl-dev libvpx-dev gcc-11 libgl1-mesa-glx libgl1-mesa-dev libglew-dev ninja-build python3-pip libx11-dev libx11-xcb-dev libfontenc-dev libice-dev libsm-dev libxau-dev libxaw7-dev libxcomposite-dev libxcursor-dev libxdamage-dev libxdmcp-dev libxext-dev libxfixes-dev libxft-dev libxi-dev libxinerama-dev libxkbfile-dev libxmu-dev libxmuu-dev libxpm-dev libxrandr-dev libxrender-dev libxres-dev libxss-dev libxt-dev libxtst-dev libxv-dev libxvmc-dev libxxf86vm-dev xtrans-dev libxcb-render0-dev libxcb-render-util0-dev libxcb-xkb-dev libxcb-icccm4-dev libxcb-image0-dev libxcb-keysyms1-dev libxcb-randr0-dev libxcb-shape0-dev libxcb-sync-dev libxcb-xfixes0-dev libxcb-xinerama0-dev xkb-data libxcb-dri3-dev uuid-dev libxcb-util-dev
- name: Restore cache
id: cache
@@ -40,7 +40,7 @@ jobs:
path: |
./build
~/cpm-cache
- key: host-${{ runner.os }}-${{ hashFiles('./CMakeLists.txt', './bass/CMakeLists.txt', './engine/CMakeLists.txt', './math/CMakeLists.txt', './render/CMakeLists.txt', './resources/CMakeLists.txt', './ui/CMakeLists.txt', './utils/CMakeLists.txt', './physics_3d/CMakeLists.txt', './physics_2d/CMakeLists.txt', './webm/CMakeLists.txt', './assimp/CMakeLists.txt') }}
+ key: host-${{ runner.os }}-${{ hashFiles('./CMakeLists.txt', './bass/CMakeLists.txt', './engine/CMakeLists.txt', './math/CMakeLists.txt', './render/CMakeLists.txt', './resources/CMakeLists.txt', './ui/CMakeLists.txt', './utils/CMakeLists.txt', './physics_3d/CMakeLists.txt', './physics_2d/CMakeLists.txt', './webm/CMakeLists.txt', './assimp/CMakeLists.txt', './scripting/CMakeLists.txt') }}
- name: Build
id: build
@@ -58,7 +58,7 @@ jobs:
path: |
./build
~/cpm-cache
- key: host-${{ runner.os }}-${{ hashFiles('./CMakeLists.txt', './bass/CMakeLists.txt', './engine/CMakeLists.txt', './math/CMakeLists.txt', './render/CMakeLists.txt', './resources/CMakeLists.txt', './ui/CMakeLists.txt', './utils/CMakeLists.txt', './physics_3d/CMakeLists.txt', './physics_2d/CMakeLists.txt', './webm/CMakeLists.txt', './assimp/CMakeLists.txt') }}
+ key: host-${{ runner.os }}-${{ hashFiles('./CMakeLists.txt', './bass/CMakeLists.txt', './engine/CMakeLists.txt', './math/CMakeLists.txt', './render/CMakeLists.txt', './resources/CMakeLists.txt', './ui/CMakeLists.txt', './utils/CMakeLists.txt', './physics_3d/CMakeLists.txt', './physics_2d/CMakeLists.txt', './webm/CMakeLists.txt', './assimp/CMakeLists.txt', './scripting/CMakeLists.txt') }}
- name: Run tests
run: |
diff --git a/.vscode/settings.json b/.vscode/settings.json
index e6c4c723..2076808f 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -11,6 +11,12 @@
"isTable",
"isString",
"json",
- "fmt"
+ "fmt",
+ "printTable",
+ "scripting",
+ "stencil",
+ "http",
+ "curtime",
+ "BGFX_FRAME"
]
}
diff --git a/.vscode/tasks.json b/.vscode/tasks.json
index ff67011a..97c39237 100644
--- a/.vscode/tasks.json
+++ b/.vscode/tasks.json
@@ -55,7 +55,7 @@
{
"label": "Clean project",
"type": "shell",
- "command": "rm -rf build bin .cache",
+ "command": "rm -rf build bin .cache bass/deps webm/deps",
"group": "build",
"options": {
"cwd": "${workspaceFolder}"
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2ca5cd62..aa7984af 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -24,7 +24,7 @@ list(PREPEND CONAN_GENERATORS_FOLDER ${CMAKE_BINARY_DIR})
# ---
# OPTIONS ---
-option(BUILD_TESTING "Build tests" ON)
+option(RAWRBOX_BUILD_TESTING "Build tests" ON)
option(RAWRBOX_USE_WAYLAND "Use Wayland for linux" OFF)
option(RAWRBOX_BUILD_SAMPLES "Build samples" ON)
@@ -52,6 +52,7 @@ if(RAWRBOX_BUILD_RAWRBOX_3D_PHYSICS)
endif()
option(RAWRBOX_ENABLE_QHULL "Include QHull on utils" ON)
+option(RAWRBOX_ENABLE_HTTP_REQUEST "Include HTTP requests on utils" ON)
# -----
# OTHER SETTINGS ----
@@ -97,11 +98,7 @@ set(CMAKE_SKIP_RPATH TRUE)
set(CMAKE_SKIP_BUILD_RPATH TRUE)
# ---------------------------------
-# SETUP CCACHE ---
-CPMAddPackage("gh:TheLartians/Ccache.cmake@1.2.4")
-# --------------
-
-# PACKAGES ------
+# GLOBAL PACKAGES ------
CPMAddPackage("gh:fmtlib/fmt#10.0.0")
if(fmt_ADDED)
set_lib_runtime_mt(fmt)
@@ -115,6 +112,22 @@ endif()
if(NOT WIN32 AND RAWRBOX_USE_WAYLAND)
CPMAddPackage("gl:wayland/weston@12.0.1")
endif()
+
+CPMAddPackage(
+ NAME
+ nlohmann_json
+ VERSION
+ 3.11.2
+ # the git repo is incredibly large, so we download the archived include directory
+ URL
+ https://github.com/nlohmann/json/releases/download/v3.11.2/include.zip
+ URL_HASH
+ SHA256=e5c7a9f49a16814be27e4ed0ee900ecd0092bfb7dbfca65b5a421b774dccaaed)
+
+if(nlohmann_json_ADDED)
+ add_library(nlohmann_json INTERFACE IMPORTED)
+ target_include_directories(nlohmann_json INTERFACE ${nlohmann_json_SOURCE_DIR}/include)
+endif()
# --------------------
add_subdirectory("math")
@@ -164,6 +177,10 @@ if(RAWRBOX_BUILD_RAWRBOX_2D_PHYSICS)
endif()
if(RAWRBOX_BUILD_SAMPLES)
- message(STATUS "Enabled SAMPLES building")
- add_subdirectory("samples")
+ if(NOT RAWRBOX_BUILD_RAWRBOX_RESOURCES)
+ message(WARNING "Samples require RAWRBOX.RESOURCES to be enabled")
+ else()
+ message(STATUS "Enabled SAMPLES building")
+ add_subdirectory("samples")
+ endif()
endif()
diff --git a/README.md b/README.md
index c410333f..73ce73d9 100644
--- a/README.md
+++ b/README.md
@@ -25,24 +25,26 @@
# FEATURES (so far)
-- Model loading (animations, light, texture import) using assimp
+- Model loading (animations, light, texture import) using [assimp](https://github.com/assimp/assimp)
- Light support (point, spot, directional)
-- Clustered rendering
+- Clustered rendering & support for other type of rendering
- 3D text
- 2D stencil drawing
-- Fonts
-- Images (png, jpeg, tga, bitmap)
-- Video (webm)
-- Sounds (using BASS lib)
+- Fonts (ttf) using [stb](https://github.com/nothings/stb)
+- JSON loading using [nlohmann json](https://github.com/nlohmann/json)
+- Images (png, jpeg, tga, bitmap, gif) using [stb](https://github.com/nothings/stb)
+- Video ([webm](https://github.com/webmproject/libwebm))
+- Sounds (using [BASS](https://www.un4seen.com/) lib)
- Custom UI
- Material system (similar to unity)
-- GIF loading & animation
-- Vulkan / DirectX / OpenGL support
+- Vulkan / DirectX / OpenGL support using [BGFX](https://github.com/bkaradzic/bgfx)
- Linux Wayland support + steam deck support
- 3D Physics system using [JoltPhysics](https://github.com/jrouwe/JoltPhysics)
- 2D Physics system using [Muli](https://github.com/Sopiro/Muli)
- Decal system
-- Scripting / modding support with LUA
+- Scripting / modding support with LUA using [sol2](https://github.com/ThePhD/sol2) and [luajit2](https://github.com/openresty/luajit2)
+- Post-processing effects support
+- HTTP / HTTPS requests using curl + [libcpr](https://github.com/libcpr/cpr)
# TODO LIST
@@ -79,7 +81,7 @@
| OPTION NAME | NOTE |
| :------------------------------------------- | :------------------------------------------------------------------------------------------------- |
-| `BUILD_TESTING` | Builds & enables project tests |
+| `RAWRBOX_BUILD_TESTING` | Builds & enables project tests |
| -- | -- |
| `RAWRBOX_OUTPUT_BIN` | The output build folder. Default is `bin` |
| `RAWRBOX_CONTENT_FOLDER` | The content folder to output resources. Default is `content` |
@@ -87,6 +89,7 @@
| `RAWRBOX_USE_WAYLAND` | Enables WAYLAND compiling on LINUX |
| -- | -- |
| `RAWRBOX_ENABLE_QHULL` | Enables QHull util |
+| `RAWRBOX_ENABLE_HTTP_REQUEST` | Enables HTTP / HTTPS requests util |
| -- | -- |
| `RAWRBOX_BUILD_SAMPLES` | Builds the project sample |
| `RAWRBOX_BUILD_RAWRBOX_UI` | Builds and includes ui |
@@ -124,6 +127,7 @@
| muli | ✖️ | Used for managing 2D physics |
| webmlib & vpx | ✖️ | Used for loading webm |
| lua & sol2 & luajit | ✖️ | Used for loading & managing lua scripting |
+| curl + libcpr | ✖️ | Used for HTTP / HTTPS requests |
# BUILDING
@@ -160,7 +164,7 @@
### 001-stencil
-
+
### 002-generated-models
@@ -192,7 +196,7 @@
### 009-physics
-
+
### 010-instancing
diff --git a/assimp/CMakeLists.txt b/assimp/CMakeLists.txt
index ecf937e1..d0f8dd55 100644
--- a/assimp/CMakeLists.txt
+++ b/assimp/CMakeLists.txt
@@ -3,39 +3,48 @@ project("RAWRBOX.ASSIMP" VERSION ${RAWRBOX_VERSION} DESCRIPTION "RawrBox - ASSIM
set(output_target RAWRBOX.ASSIMP)
# LIBS ---
+find_package(ZLIB QUIET)
+if(ZLIB_FOUND)
+ message(STATUS "Found zlib, turning off build zlib on assimp")
+ set(BUILD_ZLIB 0)
+ set(ZLIB_FOUND 0) # Because assimp will then try to install invalid targets
+else()
+ set(BUILD_ZLIB 1)
+endif()
+
CPMAddPackage(
NAME
assimp
- VERSION
- 5.2.5
+ GIT_TAG
+ master
GITHUB_REPOSITORY
assimp/assimp
OPTIONS
- "BUILD_SHARED_LIBS OFF"
- "ASSIMP_NO_EXPORT ON"
- "ASSIMP_BUILD_ALL_EXPORTERS_BY_DEFAULT OFF"
- "ASSIMP_INSTALL ON"
- "ASSIMP_BUILD_ASSIMP_TOOLS OFF"
- "ASSIMP_BUILD_TESTS OFF"
- "ASSIMP_BUILD_SAMPLES OFF"
- "ASSIMP_BUILD_DOCS OFF"
- "USE_STATIC_CRT ON"
- "ASSIMP_BUILD_ASSIMP_VIEW OFF"
- "ASSIMP_BUILD_ZLIB TRUE"
- "ASSIMP_WARNINGS_AS_ERRORS OFF"
- "ASSIMP_INSTALL_PDB OFF"
- "ASSIMP_BUILD_DRACO OFF"
- "ASSIMP_BUILD_ALL_IMPORTERS_BY_DEFAULT OFF"
- "ASSIMP_BUILD_ALL_EXPORTERS_BY_DEFAULT OFF"
+ "BUILD_SHARED_LIBS 0"
+ "ASSIMP_NO_EXPORT 1"
+ "ASSIMP_BUILD_ALL_EXPORTERS_BY_DEFAULT 0"
+ "ASSIMP_INSTALL 1"
+ "ASSIMP_BUILD_ASSIMP_TOOLS 0"
+ "ASSIMP_BUILD_TESTS 0"
+ "ASSIMP_BUILD_SAMPLES 0"
+ "ASSIMP_BUILD_DOCS 0"
+ "USE_STATIC_CRT 1"
+ "ASSIMP_BUILD_ASSIMP_VIEW 0"
+ "ASSIMP_BUILD_ZLIB ${BUILD_ZLIB}"
+ "ASSIMP_WARNINGS_AS_ERRORS 0"
+ "ASSIMP_INSTALL_PDB 0"
+ "ASSIMP_BUILD_DRACO 0"
+ "ASSIMP_BUILD_ALL_IMPORTERS_BY_DEFAULT 0"
+ "ASSIMP_BUILD_ALL_EXPORTERS_BY_DEFAULT 0"
# IMPORT SUPPORTS
- "ASSIMP_BUILD_OBJ_IMPORTER ON"
- "ASSIMP_BUILD_FBX_IMPORTER ON"
- "ASSIMP_BUILD_DAE_IMPORTER ON"
- "ASSIMP_BUILD_STL_IMPORTER ON"
- "ASSIMP_BUILD_GLTF_IMPORTER ON"
- "ASSIMP_BUILD_3DS_IMPORTER ON"
- # "ASSIMP_BUILD_MDL_IMPORTER ON"
- "ASSIMP_BUILD_MD5_IMPORTER ON")
+ "ASSIMP_BUILD_OBJ_IMPORTER 1"
+ "ASSIMP_BUILD_FBX_IMPORTER 1"
+ "ASSIMP_BUILD_DAE_IMPORTER 1"
+ "ASSIMP_BUILD_STL_IMPORTER 1"
+ "ASSIMP_BUILD_GLTF_IMPORTER 1"
+ "ASSIMP_BUILD_3DS_IMPORTER 1"
+ # "ASSIMP_BUILD_MDL_IMPORTER 1"
+ "ASSIMP_BUILD_MD5_IMPORTER 1")
# ----
# Grab source files
@@ -44,14 +53,8 @@ file(GLOB_RECURSE RAWRBOX_ASSIMP_IMPORTS "src/*.cpp" "include/*.hpp")
if(RAWRBOX_BUILD_RAWRBOX_RESOURCES)
set(RAWRBOX_EXTRA_LIBS RAWRBOX.RESOURCES)
else()
- if(NOT RAWRBOX_BUILD_RAWRBOX_RESOURCES)
- foreach(TMP_PATH ${RAWRBOX_ASSIMP_IMPORTS})
- string(FIND ${TMP_PATH} "/resources/" EXCLUDE_DIR_FOUND)
- if(NOT ${EXCLUDE_DIR_FOUND} EQUAL -1)
- list(REMOVE_ITEM RAWRBOX_ASSIMP_IMPORTS ${TMP_PATH})
- endif()
- endforeach(TMP_PATH)
- endif()
+ remove_folder("${RAWRBOX_ASSIMP_IMPORTS}" "/resources/")
+ set(RAWRBOX_ASSIMP_IMPORTS "${CLEAN_SOURCES}")
endif()
# ----
diff --git a/assimp/include/rawrbox/assimp/importer.hpp b/assimp/include/rawrbox/assimp/importer.hpp
index 7e8e9aa1..0e261e59 100644
--- a/assimp/include/rawrbox/assimp/importer.hpp
+++ b/assimp/include/rawrbox/assimp/importer.hpp
@@ -46,15 +46,15 @@ namespace rawrbox {
uint64_t blending = BGFX_STATE_BLEND_NORMAL;
OptionalTexture diffuse = std::nullopt;
- rawrbox::Colorf diffuseColor = rawrbox::Colors::White;
+ rawrbox::Colorf diffuseColor = rawrbox::Colors::White();
std::unique_ptr normal = nullptr;
std::unique_ptr specular = nullptr;
- rawrbox::Colorf specularColor = rawrbox::Colors::White;
+ rawrbox::Colorf specularColor = rawrbox::Colors::White();
float shininess = 25.F;
std::unique_ptr emissive = nullptr;
- rawrbox::Colorf emissionColor = rawrbox::Colors::White;
+ rawrbox::Colorf emissionColor = rawrbox::Colors::White();
float intensity = 1.F;
explicit AssimpMaterial(std::string _name) : name(std::move(_name)){};
@@ -65,9 +65,9 @@ namespace rawrbox {
std::string name = "light";
std::string parentID = "";
- rawrbox::Colorf diffuse = rawrbox::Colors::White;
- rawrbox::Colorf specular = rawrbox::Colors::White;
- rawrbox::Colorf ambient = rawrbox::Colors::Black;
+ rawrbox::Colorf diffuse = rawrbox::Colors::White();
+ rawrbox::Colorf specular = rawrbox::Colors::White();
+ rawrbox::Colorf ambient = rawrbox::Colors::Black();
rawrbox::Vector3f pos = {};
rawrbox::Vector3f direction = {};
diff --git a/bass/CMakeLists.txt b/bass/CMakeLists.txt
index 70d01a39..6db7e0c4 100644
--- a/bass/CMakeLists.txt
+++ b/bass/CMakeLists.txt
@@ -18,14 +18,17 @@ file(GLOB_RECURSE RAWRBOX_BASS_SOURCES "src/*.cpp" "include/*.hpp")
if(RAWRBOX_BUILD_RAWRBOX_RESOURCES)
set(RAWRBOX_EXTRA_LIBS RAWRBOX.RESOURCES)
else()
- if(NOT RAWRBOX_BUILD_RAWRBOX_RESOURCES)
- foreach(TMP_PATH ${RAWRBOX_BASS_SOURCES})
- string(FIND ${TMP_PATH} "/resources/" EXCLUDE_DIR_FOUND)
- if(NOT ${EXCLUDE_DIR_FOUND} EQUAL -1)
- list(REMOVE_ITEM RAWRBOX_BASS_SOURCES ${TMP_PATH})
- endif()
- endforeach(TMP_PATH)
+ remove_folder("${RAWRBOX_BASS_SOURCES}" "/resources/")
+ set(RAWRBOX_BASS_SOURCES "${CLEAN_SOURCES}")
+endif()
+
+if(RAWRBOX_BUILD_RAWRBOX_SCRIPTING)
+ if(NOT RAWRBOX_BUILD_RAWRBOX_RESOURCES) # RAWRBOX.RESOURCES already includes scripting if RAWRBOX_BUILD_RAWRBOX_SCRIPTING is enabled
+ list(APPEND RAWRBOX_EXTRA_LIBS RAWRBOX.SCRIPTING)
endif()
+else()
+ remove_folder("${RAWRBOX_BASS_SOURCES}" "/scripting/")
+ set(RAWRBOX_BASS_SOURCES "${CLEAN_SOURCES}")
endif()
# ----
@@ -56,6 +59,6 @@ target_compile_definitions(${output_target} PRIVATE _CRT_SECURE_NO_WARNINGS NOMI
target_compile_definitions(${output_target} PUBLIC RAWRBOX_BASS)
target_include_directories(${output_target} PUBLIC "include")
target_compile_features(${output_target} PUBLIC cxx_std_${CMAKE_CXX_STANDARD})
-target_link_libraries(${output_target} PUBLIC RAWRBOX.ENGINE RAWRBOX.MATH ${RAWRBOX_EXTRA_LIBS} fmt::fmt BASS::BASS BASS::FX)
+target_link_libraries(${output_target} PUBLIC RAWRBOX.ENGINE RAWRBOX.MATH ${RAWRBOX_EXTRA_LIBS} BASS::BASS BASS::FX)
set_lib_runtime_mt(${output_target})
diff --git a/bass/include/rawrbox/bass/scripting/plugin.hpp b/bass/include/rawrbox/bass/scripting/plugin.hpp
new file mode 100644
index 00000000..aac673a2
--- /dev/null
+++ b/bass/include/rawrbox/bass/scripting/plugin.hpp
@@ -0,0 +1,18 @@
+#pragma once
+#include
+
+namespace rawrbox {
+ class BASSPlugin : public rawrbox::Plugin {
+ public:
+ void registerTypes(sol::state& lua) override {
+ }
+
+ void registerGlobal(rawrbox::Mod* mod) override {
+ if (mod == nullptr) throw std::runtime_error("[RawrBox-BASSPlugin] Tried to register plugin on invalid mod!");
+ }
+
+ void loadLuaExtensions(rawrbox::Mod* mod) override {
+ if (mod == nullptr) throw std::runtime_error("[RawrBox-BASSPlugin] Tried to register plugin on invalid mod!");
+ }
+ };
+} // namespace rawrbox
diff --git a/bass/include/rawrbox/bass/scripting/wrapper/instance_wrapper.hpp b/bass/include/rawrbox/bass/scripting/wrapper/instance_wrapper.hpp
new file mode 100644
index 00000000..1e3c546e
--- /dev/null
+++ b/bass/include/rawrbox/bass/scripting/wrapper/instance_wrapper.hpp
@@ -0,0 +1,44 @@
+#pragma once
+
+#include
+
+#include
+
+namespace rawrbox {
+ class SoundInstanceWrapper {
+ std::shared_ptr ref;
+
+ public:
+ SoundInstanceWrapper(const std::shared_ptr& instance);
+
+ /*bool getLooping() const;
+ void setLooping(bool loop);
+
+ float getVolume() const;
+ void setVolume(float val);
+
+ float getPitch() const;
+ void setPitch(float val);
+
+ const mainframe::math::Vector2& getPosition() const;
+ void setPosition(const mainframe::math::Vector2& location);
+
+ void set3D(float maxDistance);
+ void setBeatSettings(float bandwidth, float center_freq, float release_time);
+
+ bool isValid();
+ bool isPlaying();
+ bool isHTTP();
+ uint32_t id();
+
+ sol::table getFFT(int fft_length, sol::this_state lua);
+
+ void stop();
+ void play();
+
+ void onBEAT(sol::function callback);
+ void onEnd(sol::function callback);*/
+
+ static void registerLua(sol::state& lua);
+ };
+} // namespace rawrbox
diff --git a/bass/include/rawrbox/bass/sound/instance.hpp b/bass/include/rawrbox/bass/sound/instance.hpp
index f875935c..5fc4b36b 100644
--- a/bass/include/rawrbox/bass/sound/instance.hpp
+++ b/bass/include/rawrbox/bass/sound/instance.hpp
@@ -1,5 +1,9 @@
#pragma once
+#ifdef RAWRBOX_SCRIPTING
+ #include
+#endif
+
#include
#include
#include
@@ -8,8 +12,12 @@
#include
namespace rawrbox {
- class SoundInstance {
+#ifdef RAWRBOX_SCRIPTING
+ class SoundInstance : public std::enable_shared_from_this {
+#else
+ class SoundInstance {
+#endif
protected:
uint32_t _sample = 0;
uint32_t _channel = 0;
@@ -28,7 +36,11 @@ namespace rawrbox {
bool _looping = false;
bool _stream = false;
- protected:
+#ifdef RAWRBOX_SCRIPTING
+ sol::object _luaWrapper;
+ virtual void initializeLua();
+#endif
+
[[nodiscard]] uint32_t getNextAvailableChannel() const;
public:
@@ -36,44 +48,46 @@ namespace rawrbox {
rawrbox::Event onBPM;
rawrbox::Event<> onEnd;
- SoundInstance() = default;
SoundInstance(uint32_t audioSample, bool isStream, uint32_t flags);
-
- virtual ~SoundInstance();
SoundInstance(SoundInstance&&) = delete;
SoundInstance& operator=(SoundInstance&&) = delete;
SoundInstance(const SoundInstance&) = delete;
SoundInstance& operator=(const SoundInstance&) = delete;
+ virtual ~SoundInstance();
- void play();
- void stop();
+ virtual void play();
+ virtual void stop();
// UTILS ----
- [[nodiscard]] uint32_t id() const;
- [[nodiscard]] bool isValid() const;
- [[nodiscard]] bool isCreated() const;
- [[nodiscard]] bool is3D() const;
+ [[nodiscard]] virtual uint32_t id() const;
+ [[nodiscard]] virtual bool isValid() const;
+ [[nodiscard]] virtual bool isCreated() const;
+ [[nodiscard]] virtual bool is3D() const;
- [[nodiscard]] float getTempo() const;
- [[nodiscard]] float getVolume() const;
- [[nodiscard]] double getSeek() const;
+ [[nodiscard]] virtual float getTempo() const;
+ [[nodiscard]] virtual float getVolume() const;
+ [[nodiscard]] virtual double getSeek() const;
- [[nodiscard]] bool isLooping() const;
- [[nodiscard]] bool isPlaying() const;
- [[nodiscard]] bool isPaused() const;
- [[nodiscard]] bool isHTTPStream() const;
+ [[nodiscard]] virtual bool isLooping() const;
+ [[nodiscard]] virtual bool isPlaying() const;
+ [[nodiscard]] virtual bool isPaused() const;
+ [[nodiscard]] virtual bool isHTTPStream() const;
- [[nodiscard]] const std::vector getFFT(int bass_length) const;
+ [[nodiscard]] virtual const std::vector getFFT(int bass_length) const;
- [[nodiscard]] const rawrbox::Vector3f& getPosition() const;
+ [[nodiscard]] virtual const rawrbox::Vector3f& getPosition() const;
// ------------------
- void setBeatSettings(float bandwidth, float center_freq, float release_time);
- void setVolume(float volume);
- void setTempo(float tempo);
- void seek(double seek);
- void setLooping(bool loop);
- void setPosition(const rawrbox::Vector3f& location);
- void set3D(float maxDistance, float minDistance = 0.F);
+ virtual void setBeatSettings(float bandwidth, float center_freq, float release_time);
+ virtual void setVolume(float volume);
+ virtual void setTempo(float tempo);
+ virtual void seek(double seek);
+ virtual void setLooping(bool loop);
+ virtual void setPosition(const rawrbox::Vector3f& location);
+ virtual void set3D(float maxDistance, float minDistance = 0.F);
+
+#ifdef RAWRBOX_SCRIPTING
+ virtual sol::object& getScriptingWrapper();
+#endif
};
} // namespace rawrbox
diff --git a/bass/src/scripting/wrapper/instance_wrapper.cpp b/bass/src/scripting/wrapper/instance_wrapper.cpp
new file mode 100644
index 00000000..b2b6bdf9
--- /dev/null
+++ b/bass/src/scripting/wrapper/instance_wrapper.cpp
@@ -0,0 +1,3 @@
+namespace rawrbox {
+
+}
diff --git a/bass/src/sound/instance.cpp b/bass/src/sound/instance.cpp
index 19c0b8f0..531de268 100644
--- a/bass/src/sound/instance.cpp
+++ b/bass/src/sound/instance.cpp
@@ -7,6 +7,10 @@
#include
#include
+#ifdef RAWRBOX_SCRIPTING
+ #include
+#endif
+
namespace rawrbox {
SoundInstance::SoundInstance(uint32_t audioSample, bool isStream, uint32_t flags) : _sample(audioSample), _flags(flags), _stream(isStream) {
rawrbox::BASS::onBEAT.add(std::to_string(this->_sample), [this](std::pair data) {
@@ -34,7 +38,23 @@ namespace rawrbox {
// CLEANUP CALLBACKS
rawrbox::BASS::onBEAT.remove(std::to_string(this->_sample));
rawrbox::BASS::onSoundEnd.remove(std::to_string(this->_sample));
+
+#ifdef RAWRBOX_SCRIPTING
+ if (this->_luaWrapper.valid()) this->_luaWrapper.abandon();
+#endif
+ }
+
+#ifdef RAWRBOX_SCRIPTING
+ void SoundInstance::initializeLua() {
+ if (!SCRIPTING::initialized) return;
+ // this->_luaWrapper = sol::make_object(rawrbox::SCRIPTING::getLUA(), rawrbox::LightBaseWrapper(this));
+ }
+
+ sol::object& SoundInstance::getScriptingWrapper() {
+ if (!this->_luaWrapper.valid()) this->initializeLua();
+ return this->_luaWrapper;
}
+#endif
uint32_t SoundInstance::getNextAvailableChannel() const {
if (!isValid()) return 0;
@@ -106,7 +126,7 @@ namespace rawrbox {
if (!this->isCreated()) return 0.;
QWORD pos = BASS_ChannelGetPosition(this->_channel, BASS_POS_BYTE);
- return pos != -1 ? BASS_ChannelBytes2Seconds(this->_channel, pos) : 0.;
+ return pos != -1. ? BASS_ChannelBytes2Seconds(this->_channel, pos) : 0.;
}
bool SoundInstance::isLooping() const {
diff --git a/cmake/FindVPX.cmake b/cmake/FindVPX.cmake
index cffa668a..5fb455ec 100644
--- a/cmake/FindVPX.cmake
+++ b/cmake/FindVPX.cmake
@@ -2,13 +2,13 @@
include(FindPackageHandleStandardArgs)
-if(VPX_VERSION EQUAL 0)
+if(NOT DEFINED VPX_VERSION)
message(FATAL_ERROR "No VPX version selected, set `VPX_VERSION`")
else()
message("Selected VPX Version: ${VPX_VERSION}")
endif()
-if(VPX_MSC_VERSION EQUAL 0)
+if(NOT DEFINED VPX_MSC_VERSION)
message(STATUS "No MSC version selected, set `VPX_MSC_VERSION` to 17")
set(VPX_MSC_VERSION 17)
else()
diff --git a/cmake/catch2.cmake b/cmake/catch2.cmake
index 0a68eb39..542829d1 100644
--- a/cmake/catch2.cmake
+++ b/cmake/catch2.cmake
@@ -1,5 +1,5 @@
# Packages ----
-if(BUILD_TESTING)
+if(RAWRBOX_BUILD_TESTING)
message(STATUS "Enabled testing for ${output_target}")
enable_testing()
@@ -26,7 +26,7 @@ endif()
# --------------
# TESTING ----
-if(BUILD_TESTING)
+if(RAWRBOX_BUILD_TESTING)
file(GLOB_RECURSE RAWRBOX_TESTS_IMPORTS "tests/*.spec.cpp")
add_executable(${output_target}-TESTS ${RAWRBOX_TESTS_IMPORTS})
diff --git a/cmake/rawrbox_utils.cmake b/cmake/rawrbox_utils.cmake
index c60a0483..89a340f4 100644
--- a/cmake/rawrbox_utils.cmake
+++ b/cmake/rawrbox_utils.cmake
@@ -7,3 +7,16 @@ function(set_lib_runtime_mt target)
endif()
endif()
endfunction()
+
+# From : https://stackoverflow.com/questions/24491129/excluding-directory-somewhere-in-file-structure-from-cmake-sourcefile-list
+function(remove_folder glob_sources folderName)
+ message(STATUS "Removing ${folderName} from sources")
+
+ foreach(ITR ${glob_sources})
+ if("${ITR}" MATCHES "(.*)${folderName}(.*)")
+ list(REMOVE_ITEM glob_sources ${ITR})
+ endif("${ITR}" MATCHES "(.*)${folderName}(.*)")
+ endforeach(ITR)
+
+ set(CLEAN_SOURCES "${glob_sources}" PARENT_SCOPE)
+endfunction()
diff --git a/engine/CMakeLists.txt b/engine/CMakeLists.txt
index 49648cb6..8394b6af 100644
--- a/engine/CMakeLists.txt
+++ b/engine/CMakeLists.txt
@@ -1,9 +1,5 @@
# Project setup
-project(
- "RAWRBOX.ENGINE"
- VERSION ${RAWRBOX_VERSION}
- DESCRIPTION "RawrBox - Engine lib"
- LANGUAGES CXX)
+project("RAWRBOX.ENGINE" VERSION ${RAWRBOX_VERSION} DESCRIPTION "RawrBox - Engine lib" LANGUAGES CXX)
set(output_target RAWRBOX.ENGINE)
# LIB ----
@@ -13,7 +9,7 @@ target_include_directories(${output_target} PUBLIC "include")
target_compile_definitions(${output_target} PRIVATE _CRT_SECURE_NO_WARNINGS NOMINMAX)
target_compile_definitions(${output_target} PUBLIC RAWRBOX_ENGINE)
target_compile_features(${output_target} PUBLIC cxx_std_${CMAKE_CXX_STANDARD})
-target_link_libraries(${output_target} PUBLIC RAWRBOX.UTILS fmt::fmt)
+target_link_libraries(${output_target} PUBLIC RAWRBOX.UTILS)
set_lib_runtime_mt(${output_target})
# --------------
diff --git a/math/include/rawrbox/math/color.hpp b/math/include/rawrbox/math/color.hpp
index 3c901c2d..4d5f6b8c 100644
--- a/math/include/rawrbox/math/color.hpp
+++ b/math/include/rawrbox/math/color.hpp
@@ -245,20 +245,89 @@ namespace rawrbox {
using ColorType = Color_t;
public:
- inline const static ColorType Black = ColorType(0, 0, 0, 1);
- inline const static ColorType White = ColorType(1, 1, 1, 1);
+ [[nodiscard]] static inline ColorType Black() {
+ if constexpr (std::is_same_v) {
+ return ColorType(0, 0, 0, 255);
+ } else {
+ return ColorType(0, 0, 0, 1);
+ }
+ }
+
+ [[nodiscard]] static inline ColorType White() {
+ if constexpr (std::is_same_v) {
+ return ColorType(255, 255, 255, 255);
+ } else {
+ return ColorType(1, 1, 1, 1);
+ }
+ }
+
+ [[nodiscard]] static inline ColorType Gray() {
+ if constexpr (std::is_same_v) {
+ return ColorType(206, 204, 191, 255);
+ } else {
+ return ColorType(0.81F, 0.8F, 0.75F, 1);
+ }
+ }
+
+ [[nodiscard]] static inline ColorType DarkGray() {
+ if constexpr (std::is_same_v) {
+ return ColorType(130, 127, 119, 255);
+ } else {
+ return ColorType(0.51F, 0.50F, 0.47F, 1);
+ }
+ }
+
+ [[nodiscard]] static inline ColorType Red() {
+ if constexpr (std::is_same_v) {
+ return ColorType(255, 82, 82, 255);
+ } else {
+ return ColorType(1, 0.32F, 0.32F, 1);
+ }
+ }
- inline const static ColorType Gray = ColorType(0.81F, 0.8F, 0.75F, 1);
- inline const static ColorType DarkGray = ColorType(0.51F, 0.50F, 0.47F, 1);
+ [[nodiscard]] static inline ColorType Green() {
+ if constexpr (std::is_same_v) {
+ return ColorType(36, 222, 128, 255);
+ } else {
+ return ColorType(0.14F, 0.87F, 0.50F, 1);
+ }
+ }
+
+ [[nodiscard]] static inline ColorType Blue() {
+ if constexpr (std::is_same_v) {
+ return ColorType(51, 171, 222, 255);
+ } else {
+ return ColorType(0.2F, 0.67F, 0.87F, 1);
+ }
+ }
+
+ [[nodiscard]] static inline ColorType Orange() {
+ if constexpr (std::is_same_v) {
+ return ColorType(255, 120, 61, 255);
+ } else {
+ return ColorType(1, 0.47F, 0.24F, 1);
+ }
+ }
+
+ [[nodiscard]] static inline ColorType Yellow() {
+ if constexpr (std::is_same_v) {
+ return ColorType(255, 230, 64, 255);
+ } else {
+ return ColorType(1, 0.9F, 0.25F, 1);
+ }
+ }
- inline const static ColorType Red = ColorType(1, 0.32F, 0.32F, 1);
- inline const static ColorType Green = ColorType(0.14F, 0.87F, 0.50F, 1);
- inline const static ColorType Blue = ColorType(0.2F, 0.67F, 0.87F, 1);
- inline const static ColorType Orange = ColorType(1, 0.47F, 0.24F, 1);
- inline const static ColorType Yellow = ColorType(1, 0.69F, 0.25F, 1);
- inline const static ColorType Purple = ColorType(1.F, 0.F, 1.F, 1);
+ [[nodiscard]] static inline ColorType Purple() {
+ if constexpr (std::is_same_v) {
+ return ColorType(255, 0, 255, 255);
+ } else {
+ return ColorType(1.F, 0.F, 1.F, 1);
+ }
+ }
- inline const static ColorType Transparent = ColorType(0, 0, 0, 0);
+ [[nodiscard]] static inline ColorType Transparent() {
+ return ColorType(0, 0, 0, 0);
+ }
};
using Colorsf = Colors_t;
diff --git a/math/tests/color.spec.cpp b/math/tests/color.spec.cpp
index 03372df9..d612d18d 100644
--- a/math/tests/color.spec.cpp
+++ b/math/tests/color.spec.cpp
@@ -16,7 +16,7 @@ TEST_CASE("Color should behave as expected", "[rawrbox::Color]") {
}
SECTION("rawrbox::Colors") {
- auto red = rawrbox::Colors::Red;
+ auto red = rawrbox::Colors::Red();
REQUIRE(red.r == 1.F);
REQUIRE(red.g == 0.32F);
@@ -25,7 +25,7 @@ TEST_CASE("Color should behave as expected", "[rawrbox::Color]") {
}
SECTION("rawrbox::Color::cast") {
- auto red = rawrbox::Colors::Red.cast();
+ auto red = rawrbox::Colors::Red().cast();
rawrbox::Colori col = rawrbox::Colori{255, 255, 0, 255};
auto clCast = col.cast();
diff --git a/rawrbox.code-workspace b/rawrbox.code-workspace
index 9bef2f41..2cd2b6bd 100644
--- a/rawrbox.code-workspace
+++ b/rawrbox.code-workspace
@@ -48,8 +48,6 @@
"cmake.generator": "Ninja",
"cmake.configureArgs": ["-Wno-dev"],
"cmake.configureSettings": {
- "DUSE_CCACHE": "YES",
- "DCCACHE_OPTIONS": "CCACHE_CPP2=true;CCACHE_SLOPPINESS=clang_index_store",
"DCMAKE_EXPORT_COMPILE_COMMANDS": "ON",
"DRAWRBOX_OUTPUT_BIN": "bin"
//"DCMAKE_CXX_INCLUDE_WHAT_YOU_USE": "../include-what-you-use.exe"
diff --git a/render/CMakeLists.txt b/render/CMakeLists.txt
index 59c0ec03..3b7c6fe9 100644
--- a/render/CMakeLists.txt
+++ b/render/CMakeLists.txt
@@ -58,12 +58,17 @@ file(GLOB_RECURSE RAWRBOX_RENDER_SOURCES "src/*.cpp" "src/*.c" "include/*.h" "in
if(RAWRBOX_BUILD_RAWRBOX_RESOURCES)
list(APPEND RAWRBOX_EXTRA_LIBS RAWRBOX.RESOURCES)
else()
- foreach(TMP_PATH ${RAWRBOX_RENDER_SOURCES})
- string(FIND ${TMP_PATH} "/resources/" EXCLUDE_DIR_FOUND)
- if(NOT ${EXCLUDE_DIR_FOUND} EQUAL -1)
- list(REMOVE_ITEM RAWRBOX_RENDER_SOURCES ${TMP_PATH})
- endif()
- endforeach(TMP_PATH)
+ remove_folder("${RAWRBOX_RENDER_SOURCES}" "/resources/")
+ set(RAWRBOX_RENDER_SOURCES "${CLEAN_SOURCES}")
+endif()
+
+if(RAWRBOX_BUILD_RAWRBOX_SCRIPTING)
+ if(NOT RAWRBOX_BUILD_RAWRBOX_RESOURCES) # RAWRBOX.RESOURCES already includes scripting if RAWRBOX_BUILD_RAWRBOX_SCRIPTING is enabled
+ list(APPEND RAWRBOX_EXTRA_LIBS RAWRBOX.SCRIPTING)
+ endif()
+else()
+ remove_folder("${RAWRBOX_RENDER_SOURCES}" "/scripting/")
+ set(RAWRBOX_RENDER_SOURCES "${CLEAN_SOURCES}")
endif()
# -----------------
@@ -87,9 +92,13 @@ add_custom_target(
COMMENT "Copying RENDERER resources into binary directory")
# ------------------
+if(RAWRBOX_BUILD_RAWRBOX_SCRIPTING)
+ set(RAWRBOX_RENDER_DEPS copy_resources_lua)
+endif()
+
# Project setup
add_library(${output_target} ${RAWRBOX_LIBRARY_TYPE} ${RAWRBOX_RENDER_SOURCES})
-add_dependencies(${output_target} copy_resources_render)
+add_dependencies(${output_target} copy_resources_render ${RAWRBOX_RENDER_DEPS})
target_compile_definitions(${output_target} PRIVATE _CRT_SECURE_NO_WARNINGS NOMINMAX)
target_compile_definitions(${output_target} PUBLIC RAWRBOX_RENDER)
target_include_directories(${output_target} PUBLIC "include")
@@ -100,7 +109,6 @@ target_link_libraries(
RAWRBOX.MATH
RAWRBOX.ENGINE
${RAWRBOX_EXTRA_LIBS}
- fmt::fmt
magic_enum::magic_enum
utf8cpp
bgfx
diff --git a/render/include/rawrbox/render/decals/manager.hpp b/render/include/rawrbox/render/decals/manager.hpp
index cee02ab1..4f50a60b 100644
--- a/render/include/rawrbox/render/decals/manager.hpp
+++ b/render/include/rawrbox/render/decals/manager.hpp
@@ -14,8 +14,8 @@ namespace rawrbox {
static void setAtlasTexture(rawrbox::TextureBase* atlas);
// UTILS -----
- static void add(const rawrbox::Vector3f& pos, const rawrbox::Vector3f& scale = {1, 1, 1}, float direction = 0, const rawrbox::Colorf& color = rawrbox::Colors::White, uint16_t atlasId = 0);
- static void remove(size_t i);
+ static bool add(const rawrbox::Vector3f& pos, const rawrbox::Vector3f& scale = {1, 1, 1}, float direction = 0, const rawrbox::Colorf& color = rawrbox::Colors::White(), uint16_t atlasId = 0);
+ static bool remove(size_t i);
static const rawrbox::Instance& get(size_t i);
static const rawrbox::Mesh& getTemplate();
static size_t count();
diff --git a/render/include/rawrbox/render/light/base.hpp b/render/include/rawrbox/render/light/base.hpp
index e14c0e11..c945f67a 100644
--- a/render/include/rawrbox/render/light/base.hpp
+++ b/render/include/rawrbox/render/light/base.hpp
@@ -4,13 +4,16 @@
#include
#include
#include
-#include
#include
namespace rawrbox {
+#ifdef RAWRBOX_SCRIPTING
+ class LightBase : public std::enable_shared_from_this {
+#else
class LightBase {
+#endif
protected:
bool _isOn = true;
size_t _id = 0;
@@ -19,15 +22,15 @@ namespace rawrbox {
rawrbox::Vector3f _offset = {};
rawrbox::Vector3f _direction = {};
- rawrbox::Colorf _color = rawrbox::Colors::White;
+ rawrbox::Colorf _color = rawrbox::Colors::White();
float _radius = 5.F;
public:
LightBase(const rawrbox::Vector3f& pos, const rawrbox::Colorf& color, float radius);
- LightBase(const LightBase&) = default;
- LightBase(LightBase&&) = default;
- LightBase& operator=(const LightBase&) = default;
+ LightBase(const LightBase&) = delete;
+ LightBase(LightBase&&) = delete;
+ LightBase& operator=(const LightBase&) = delete;
LightBase& operator=(LightBase&&) = delete;
virtual ~LightBase() = default;
diff --git a/render/include/rawrbox/render/light/manager.hpp b/render/include/rawrbox/render/light/manager.hpp
index 3bfb8a27..7d0c8bc1 100644
--- a/render/include/rawrbox/render/light/manager.hpp
+++ b/render/include/rawrbox/render/light/manager.hpp
@@ -36,7 +36,7 @@ namespace rawrbox {
class LIGHTS {
protected:
- static std::vector> _lights;
+ static std::vector> _lights;
static bgfx::DynamicVertexBufferHandle _buffer;
static bgfx::UniformHandle _u_lightSettings;
@@ -79,7 +79,7 @@ namespace rawrbox {
// ----
// FOG
- static void setFog(rawrbox::FOG_TYPE type, float end, float density, const rawrbox::Colorf& col = rawrbox::Colors::Black);
+ static void setFog(rawrbox::FOG_TYPE type, float end, float density, const rawrbox::Colorf& col = rawrbox::Colors::Black());
static rawrbox::FOG_TYPE getFogType();
static const rawrbox::Colorf& getFogColor();
@@ -95,12 +95,7 @@ namespace rawrbox {
// Light ----
template
static rawrbox::LightBase* addLight(CallbackArgs&&... args) {
- if (_lights.size() >= rawrbox::MAX_LIGHTS) {
- fmt::print("[RawrBox-LIGHTS] Could not add light, max lights limit hit!\n");
- return nullptr;
- }
-
- auto light = _lights.emplace_back(std::make_unique(std::forward(args)...)).get();
+ auto light = _lights.emplace_back(std::make_shared(std::forward(args)...)).get();
light->setId(++rawrbox::LIGHT_ID);
rawrbox::__LIGHT_DIRTY__ = true;
diff --git a/render/include/rawrbox/render/light/point.hpp b/render/include/rawrbox/render/light/point.hpp
index a1bb61ac..de2ce6a2 100644
--- a/render/include/rawrbox/render/light/point.hpp
+++ b/render/include/rawrbox/render/light/point.hpp
@@ -7,9 +7,9 @@ namespace rawrbox {
public:
using rawrbox::LightBase::LightBase;
- PointLight(const PointLight&) = default;
+ PointLight(const PointLight&) = delete;
PointLight(PointLight&&) = delete;
- PointLight& operator=(const PointLight&) = default;
+ PointLight& operator=(const PointLight&) = delete;
PointLight& operator=(PointLight&&) = delete;
~PointLight() override = default;
diff --git a/render/include/rawrbox/render/light/spot.hpp b/render/include/rawrbox/render/light/spot.hpp
index fdb6968b..4e7a64a0 100644
--- a/render/include/rawrbox/render/light/spot.hpp
+++ b/render/include/rawrbox/render/light/spot.hpp
@@ -12,9 +12,9 @@ namespace rawrbox {
this->_direction = direction.normalized();
};
- SpotLight(const SpotLight&) = default;
+ SpotLight(const SpotLight&) = delete;
SpotLight(SpotLight&&) = delete;
- SpotLight& operator=(const SpotLight&) = default;
+ SpotLight& operator=(const SpotLight&) = delete;
SpotLight& operator=(SpotLight&&) = delete;
~SpotLight() override = default;
diff --git a/render/include/rawrbox/render/model/base.hpp b/render/include/rawrbox/render/model/base.hpp
index ffadc663..66c2eb5e 100644
--- a/render/include/rawrbox/render/model/base.hpp
+++ b/render/include/rawrbox/render/model/base.hpp
@@ -2,10 +2,20 @@
#include
+#ifdef RAWRBOX_SCRIPTING
+ #include
+ #include
+ #include
+#endif
+
namespace rawrbox {
template
+#ifdef RAWRBOX_SCRIPTING
+ class ModelBase : public std::enable_shared_from_this> {
+#else
class ModelBase {
+#endif
protected:
bgfx::DynamicVertexBufferHandle _vbdh = BGFX_INVALID_HANDLE; // Vertices - Dynamic
@@ -21,8 +31,19 @@ namespace rawrbox {
bool _isDynamic = false;
// ----
+#ifdef RAWRBOX_SCRIPTING
+ sol::object _luaWrapper;
+
+ virtual void initializeLua() {
+ if (!SCRIPTING::initialized) return;
+
+ auto ptr = std::dynamic_pointer_cast>(this->shared_from_this());
+ this->_luaWrapper = sol::make_object(rawrbox::SCRIPTING::getLUA(), rawrbox::ModelBaseWrapper(ptr));
+ }
+#endif
+
virtual void updateBuffers() {
- if (!this->isDynamicBuffer() || !this->isUploaded()) return;
+ if (!this->isDynamic() || !this->isUploaded()) return;
const bgfx::Memory* vertMem = bgfx::makeRef(this->_mesh->vertices.data(), static_cast(this->_mesh->vertices.size()) * M::vLayout().getStride());
const bgfx::Memory* indexMem = bgfx::makeRef(this->_mesh->indices.data(), static_cast(this->_mesh->indices.size()) * sizeof(uint16_t));
@@ -45,6 +66,10 @@ namespace rawrbox {
RAWRBOX_DESTROY(this->_ibdh);
this->_mesh.reset();
+
+#ifdef RAWRBOX_SCRIPTING
+ if (this->_luaWrapper.valid()) this->_luaWrapper.abandon();
+#endif
}
// UTIL ---
@@ -71,12 +96,12 @@ namespace rawrbox {
return this->_mesh->matrix;
}
- [[nodiscard]] virtual bool isDynamicBuffer() const {
+ [[nodiscard]] virtual bool isDynamic() const {
return this->_isDynamic;
}
[[nodiscard]] virtual bool isUploaded() const {
- if (this->isDynamicBuffer()) return bgfx::isValid(this->_ibdh) && bgfx::isValid(this->_vbdh);
+ if (this->isDynamic()) return bgfx::isValid(this->_ibdh) && bgfx::isValid(this->_vbdh);
return bgfx::isValid(this->_ibh) && bgfx::isValid(this->_vbh);
}
@@ -114,5 +139,12 @@ namespace rawrbox {
virtual void draw() {
if (!this->isUploaded()) throw std::runtime_error("[RawrBox-Model] Failed to render model, vertex / index buffer is not uploaded");
}
+
+#ifdef RAWRBOX_SCRIPTING
+ virtual sol::object& getScriptingWrapper() {
+ if (!this->_luaWrapper.valid()) this->initializeLua();
+ return this->_luaWrapper;
+ }
+#endif
};
} // namespace rawrbox
diff --git a/render/include/rawrbox/render/model/defs.hpp b/render/include/rawrbox/render/model/defs.hpp
index db45e977..5ae55e41 100644
--- a/render/include/rawrbox/render/model/defs.hpp
+++ b/render/include/rawrbox/render/model/defs.hpp
@@ -24,18 +24,18 @@ namespace rawrbox {
VertexData() = default;
explicit VertexData(const rawrbox::Vector3f& _pos,
- const rawrbox::Vector4f& _uv = {}, const rawrbox::Color cl = rawrbox::Colors::White) : position(_pos), uv(_uv), abgr(cl.pack()) {}
+ const rawrbox::Vector4f& _uv = {}, const rawrbox::Color cl = rawrbox::Colors::White()) : position(_pos), uv(_uv), abgr(cl.pack()) {}
explicit VertexData(const rawrbox::Vector3f& _pos,
- const rawrbox::Vector2f& _uv = {}, const rawrbox::Color cl = rawrbox::Colors::White) : position(_pos), uv(_uv), abgr(cl.pack()) {}
+ const rawrbox::Vector2f& _uv = {}, const rawrbox::Color cl = rawrbox::Colors::White()) : position(_pos), uv(_uv), abgr(cl.pack()) {}
explicit VertexData(const rawrbox::Vector3f& _pos,
const rawrbox::Vector2f& _uv = {},
- const std::array& _normal = {}, const rawrbox::Color cl = rawrbox::Colors::White) : position(_pos), uv(_uv), abgr(cl.pack()), normal(_normal) {}
+ const std::array& _normal = {}, const rawrbox::Color cl = rawrbox::Colors::White()) : position(_pos), uv(_uv), abgr(cl.pack()), normal(_normal) {}
explicit VertexData(const rawrbox::Vector3f& _pos,
const rawrbox::Vector4f& _uv = {},
- const std::array& _normal = {}, const rawrbox::Color cl = rawrbox::Colors::White) : position(_pos), uv(_uv), abgr(cl.pack()), normal(_normal) {}
+ const std::array& _normal = {}, const rawrbox::Color cl = rawrbox::Colors::White()) : position(_pos), uv(_uv), abgr(cl.pack()), normal(_normal) {}
static bgfx::VertexLayout vLayout(bool normals = false, bool bones = false) {
bgfx::VertexLayout l;
diff --git a/render/include/rawrbox/render/model/instanced.hpp b/render/include/rawrbox/render/model/instanced.hpp
index 9143c20f..828aef71 100644
--- a/render/include/rawrbox/render/model/instanced.hpp
+++ b/render/include/rawrbox/render/model/instanced.hpp
@@ -7,10 +7,10 @@ namespace rawrbox {
struct Instance {
rawrbox::Matrix4x4 matrix = {};
- rawrbox::Colorf color = rawrbox::Colors::White;
+ rawrbox::Colorf color = rawrbox::Colors::White();
rawrbox::Vector4f extraData = {}; // AtlasID, etc..
- Instance(const rawrbox::Matrix4x4& mat, const rawrbox::Colorf& col = rawrbox::Colors::White, rawrbox::Vector4f data = {}) : matrix(mat), color(col), extraData(data) {}
+ Instance(const rawrbox::Matrix4x4& mat, const rawrbox::Colorf& col = rawrbox::Colors::White(), rawrbox::Vector4f data = {}) : matrix(mat), color(col), extraData(data) {}
static bgfx::VertexLayout vLayout() {
static bgfx::VertexLayout l;
@@ -54,7 +54,7 @@ namespace rawrbox {
if (mesh.empty()) throw std::runtime_error("[RawrBox-InstancedModel] Invalid mesh! Missing vertices / indices!");
this->_mesh = std::make_unique(mesh);
- if (this->isUploaded() && this->isDynamicBuffer()) {
+ if (this->isUploaded() && this->isDynamic()) {
this->updateBuffers();
}
}
@@ -108,7 +108,7 @@ namespace rawrbox {
ModelBase::draw();
this->_material->process(*this->_mesh); // Set atlas
- if (this->isDynamicBuffer()) {
+ if (this->isDynamic()) {
bgfx::setVertexBuffer(0, this->_vbdh);
bgfx::setIndexBuffer(this->_ibdh);
} else {
diff --git a/render/include/rawrbox/render/model/mesh.hpp b/render/include/rawrbox/render/model/mesh.hpp
index 1b5ca66a..02d500ef 100644
--- a/render/include/rawrbox/render/model/mesh.hpp
+++ b/render/include/rawrbox/render/model/mesh.hpp
@@ -21,7 +21,7 @@ namespace rawrbox {
class LightBase;
class Mesh {
- private:
+ protected:
bool _canOptimize = true;
rawrbox::Vector3f _scale = {1, 1, 1};
@@ -65,7 +65,7 @@ namespace rawrbox {
// RENDERING ---
rawrbox::Matrix4x4 matrix = {};
- rawrbox::Color color = rawrbox::Colors::White;
+ rawrbox::Color color = rawrbox::Colors::White();
bool wireframe = false;
bool lineMode = false;
diff --git a/render/include/rawrbox/render/model/model.hpp b/render/include/rawrbox/render/model/model.hpp
index f9d47611..aa2bd254 100644
--- a/render/include/rawrbox/render/model/model.hpp
+++ b/render/include/rawrbox/render/model/model.hpp
@@ -10,6 +10,11 @@
#define BGFX_STATE_DEFAULT_3D (0 | BGFX_STATE_WRITE_RGB | BGFX_STATE_WRITE_A)
+#ifdef RAWRBOX_SCRIPTING
+ #include
+ #include
+#endif
+
namespace rawrbox {
template
@@ -206,6 +211,15 @@ namespace rawrbox {
}
}
+#ifdef RAWRBOX_SCRIPTING
+ void initializeLua() override {
+ if (this->_luaWrapper.valid()) this->_luaWrapper.abandon();
+
+ auto ptr = std::dynamic_pointer_cast>(this->shared_from_this());
+ this->_luaWrapper = sol::make_object(rawrbox::SCRIPTING::getLUA(), rawrbox::ModelWrapper(ptr));
+ }
+#endif
+
public:
Model() = default;
Model(const Model&) = delete;
@@ -350,14 +364,14 @@ namespace rawrbox {
++it2;
}
- if (this->isUploaded() && this->isDynamicBuffer()) this->flattenMeshes(); // Already uploaded? And dynamic? Then update vertices
+ if (this->isUploaded() && this->isDynamic()) this->flattenMeshes(); // Already uploaded? And dynamic? Then update vertices
}
virtual void removeMesh(size_t index) {
if (index >= this->_meshes.size()) return;
this->_meshes.erase(this->_meshes.begin() + index);
- if (this->isUploaded() && this->isDynamicBuffer()) this->flattenMeshes(); // Already uploaded? And dynamic? Then update vertices
+ if (this->isUploaded() && this->isDynamic()) this->flattenMeshes(); // Already uploaded? And dynamic? Then update vertices
}
virtual rawrbox::Mesh* addMesh(rawrbox::Mesh mesh) {
@@ -365,7 +379,7 @@ namespace rawrbox {
mesh.owner = this;
auto& a = this->_meshes.emplace_back(std::make_unique(mesh));
- if (this->isUploaded() && this->isDynamicBuffer()) {
+ if (this->isUploaded() && this->isDynamic()) {
this->flattenMeshes(); // Already uploaded? And dynamic? Then update vertices
}
@@ -451,7 +465,7 @@ namespace rawrbox {
this->animate(*mesh);
// ---
- if (this->isDynamicBuffer()) {
+ if (this->isDynamic()) {
bgfx::setVertexBuffer(0, this->_vbdh, mesh->baseVertex, mesh->totalVertex);
bgfx::setIndexBuffer(this->_ibdh, mesh->baseIndex, mesh->totalIndex);
} else {
diff --git a/render/include/rawrbox/render/model/spline.hpp b/render/include/rawrbox/render/model/spline.hpp
index 5a07f5c5..157ea811 100644
--- a/render/include/rawrbox/render/model/spline.hpp
+++ b/render/include/rawrbox/render/model/spline.hpp
@@ -108,7 +108,7 @@ namespace rawrbox {
auto norm = rawrbox::Vector3f(this->_shape->normal[j].x, this->_shape->normal[j].y, 0.F);
auto uv = rawrbox::Vector2f(this->_shape->u[j], path[i].vCoordinate);
- buff[id] = rawrbox::VertexData(path[i].LocalToWorld(pos), uv, {rawrbox::PackUtils::packNormal(norm.x, norm.y, norm.z), 0}, rawrbox::Colors::White);
+ buff[id] = rawrbox::VertexData(path[i].LocalToWorld(pos), uv, {rawrbox::PackUtils::packNormal(norm.x, norm.y, norm.z), 0}, rawrbox::Colors::White());
}
}
@@ -144,7 +144,7 @@ namespace rawrbox {
ModelBase::draw();
this->_material->process(*this->_mesh);
- if (this->isDynamicBuffer()) {
+ if (this->isDynamic()) {
bgfx::setVertexBuffer(0, this->_vbdh);
bgfx::setIndexBuffer(this->_ibdh);
} else {
diff --git a/render/include/rawrbox/render/model/sprite.hpp b/render/include/rawrbox/render/model/sprite.hpp
index d3a963a8..e24102df 100644
--- a/render/include/rawrbox/render/model/sprite.hpp
+++ b/render/include/rawrbox/render/model/sprite.hpp
@@ -43,7 +43,7 @@ namespace rawrbox {
this->_material->process(*mesh);
- if (this->isDynamicBuffer()) {
+ if (this->isDynamic()) {
bgfx::setVertexBuffer(0, this->_vbdh, mesh->baseVertex, mesh->totalVertex);
bgfx::setIndexBuffer(this->_ibdh, mesh->baseIndex, mesh->totalIndex);
} else {
diff --git a/render/include/rawrbox/render/model/text3D.hpp b/render/include/rawrbox/render/model/text3D.hpp
index d44698e6..d8cc9ba3 100644
--- a/render/include/rawrbox/render/model/text3D.hpp
+++ b/render/include/rawrbox/render/model/text3D.hpp
@@ -23,7 +23,7 @@ namespace rawrbox {
void setScaleMul(float mul);
[[nodiscard]] float getScaleMul() const;
- uint32_t addText(const rawrbox::Font& font, const std::string& text, const rawrbox::Vector3f& pos, const rawrbox::Colorf& cl = rawrbox::Colors::White, rawrbox::Alignment alignX = rawrbox::Alignment::Center, rawrbox::Alignment alignY = rawrbox::Alignment::Center, bool billboard = false);
+ uint32_t addText(const rawrbox::Font& font, const std::string& text, const rawrbox::Vector3f& pos, const rawrbox::Colorf& cl = rawrbox::Colors::White(), rawrbox::Alignment alignX = rawrbox::Alignment::Center, rawrbox::Alignment alignY = rawrbox::Alignment::Center, bool billboard = false);
void removeText(uint32_t indx);
// ----------
diff --git a/render/include/rawrbox/render/model/utils/mesh.hpp b/render/include/rawrbox/render/model/utils/mesh.hpp
index 0790c65d..83c5ff84 100644
--- a/render/include/rawrbox/render/model/utils/mesh.hpp
+++ b/render/include/rawrbox/render/model/utils/mesh.hpp
@@ -84,7 +84,7 @@ namespace rawrbox {
return mesh;
}
- static inline rawrbox::Mesh generatePlane(const rawrbox::Vector3f& pos, const rawrbox::Vector2f& size, const rawrbox::Colorf& cl = rawrbox::Colors::White) {
+ static inline rawrbox::Mesh generatePlane(const rawrbox::Vector3f& pos, const rawrbox::Vector2f& size, const rawrbox::Colorf& cl = rawrbox::Colors::White()) {
rawrbox::Mesh mesh;
mesh.setPos(pos);
@@ -117,7 +117,7 @@ namespace rawrbox {
return mesh;
}
- static inline rawrbox::Mesh generateCube(const rawrbox::Vector3f& pos, const rawrbox::Vector3f& size, const rawrbox::Colorf& cl = rawrbox::Colors::White) {
+ static inline rawrbox::Mesh generateCube(const rawrbox::Vector3f& pos, const rawrbox::Vector3f& size, const rawrbox::Colorf& cl = rawrbox::Colors::White()) {
rawrbox::Mesh mesh;
mesh.setPos(pos);
@@ -208,9 +208,9 @@ namespace rawrbox {
mesh.setPos(pos);
float hSize = size / 2.F;
- mesh.merge(generateCube(pos, {hSize * 2, 0.01F, 0.01F}, Colors::Red)); // x
- mesh.merge(generateCube(pos, {0.01F, hSize * 2, 0.01F}, Colors::Green)); // y
- mesh.merge(generateCube(pos, {0.01F, 0.01F, hSize * 2}, Colors::Blue)); // z
+ mesh.merge(generateCube(pos, {hSize * 2, 0.01F, 0.01F}, rawrbox::Colors::Red())); // x
+ mesh.merge(generateCube(pos, {0.01F, hSize * 2, 0.01F}, rawrbox::Colors::Green())); // y
+ mesh.merge(generateCube(pos, {0.01F, 0.01F, hSize * 2}, rawrbox::Colors::Blue())); // z
// AABB ---
mesh.bbox.m_min = {-hSize, -hSize, -hSize};
@@ -226,7 +226,7 @@ namespace rawrbox {
// Adapted from https://github.com/bkaradzic/bgfx/blob/master/examples/common/debugdraw/debugdraw.cpp#L687
// Does not support UV :( / normals
- static inline rawrbox::Mesh generateCone(const rawrbox::Vector3f& pos, const rawrbox::Vector3f& size, uint32_t ratio = 12, const rawrbox::Colorf& cl = rawrbox::Colors::White) {
+ static inline rawrbox::Mesh generateCone(const rawrbox::Vector3f& pos, const rawrbox::Vector3f& size, uint32_t ratio = 12, const rawrbox::Colorf& cl = rawrbox::Colors::White()) {
rawrbox::Mesh mesh;
mesh.setPos(pos);
@@ -289,7 +289,7 @@ namespace rawrbox {
// Adapted from https://github.com/bkaradzic/bgfx/blob/master/examples/common/debugdraw/debugdraw.cpp#L750
// Does not support UV :( / normals
- static inline rawrbox::Mesh generateCylinder(const rawrbox::Vector3f& pos, const rawrbox::Vector3f& size, uint32_t ratio = 12, const rawrbox::Colorf& cl = rawrbox::Colors::White) {
+ static inline rawrbox::Mesh generateCylinder(const rawrbox::Vector3f& pos, const rawrbox::Vector3f& size, uint32_t ratio = 12, const rawrbox::Colorf& cl = rawrbox::Colors::White()) {
rawrbox::Mesh mesh;
mesh.setPos(pos);
@@ -357,7 +357,7 @@ namespace rawrbox {
// Adapted from https://github.com/bkaradzic/bgfx/blob/master/examples/common/debugdraw/debugdraw.cpp#L640
// Does not support UV :( / normals
- static inline rawrbox::Mesh generateSphere(const rawrbox::Vector3f& pos, float size, uint32_t ratio = 1, const rawrbox::Colorf& cl = rawrbox::Colors::White) {
+ static inline rawrbox::Mesh generateSphere(const rawrbox::Vector3f& pos, float size, uint32_t ratio = 1, const rawrbox::Colorf& cl = rawrbox::Colors::White()) {
rawrbox::Mesh mesh;
mesh.setPos(pos);
@@ -465,7 +465,7 @@ namespace rawrbox {
return mesh;
}
- static inline rawrbox::Mesh generateMesh(const rawrbox::Vector3f& pos, uint32_t subDivs = 1, const rawrbox::Colorf& cl = rawrbox::Colors::White) {
+ static inline rawrbox::Mesh generateMesh(const rawrbox::Vector3f& pos, uint32_t subDivs = 1, const rawrbox::Colorf& cl = rawrbox::Colors::White()) {
rawrbox::Mesh mesh;
mesh.setPos(pos);
@@ -508,7 +508,7 @@ namespace rawrbox {
}
// Adapted from : https://stackoverflow.com/questions/58494179/how-to-create-a-grid-in-opengl-and-drawing-it-with-lines
- static inline rawrbox::Mesh generateGrid(uint16_t size, const rawrbox::Vector3f& pos, const rawrbox::Colorf& cl = rawrbox::Colors::DarkGray, const rawrbox::Colorf& borderCl = rawrbox::Colors::Transparent) {
+ static inline rawrbox::Mesh generateGrid(uint16_t size, const rawrbox::Vector3f& pos, const rawrbox::Colorf& cl = rawrbox::Colors::DarkGray(), const rawrbox::Colorf& borderCl = rawrbox::Colors::Transparent()) {
rawrbox::Mesh mesh;
mesh.setPos(pos);
diff --git a/render/include/rawrbox/render/scripting/plugin.hpp b/render/include/rawrbox/render/scripting/plugin.hpp
new file mode 100644
index 00000000..08d72463
--- /dev/null
+++ b/render/include/rawrbox/render/scripting/plugin.hpp
@@ -0,0 +1,97 @@
+#pragma once
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#ifdef RAWRBOX_RESOURCES
+ #include
+ #include
+#endif
+#include
+#include
+#include
+#include
+#include
+#include
+
+namespace rawrbox {
+ class RenderPlugin : public rawrbox::Plugin {
+ protected:
+ rawrbox::Window* _window = nullptr;
+
+ public:
+ RenderPlugin(rawrbox::Window* window) : rawrbox::Plugin(), _window(window){};
+
+ void registerTypes(sol::state& lua) override {
+ // GAME
+ rawrbox::WindowWrapper::registerLua(lua);
+ rawrbox::CameraWrapper::registerLua(lua);
+ rawrbox::StencilWrapper::registerLua(lua);
+ rawrbox::DecalsWrapper::registerLua(lua);
+ // ----
+
+ // MODEL --
+ rawrbox::ModelBaseWrapper::registerLua(lua);
+ rawrbox::ModelWrapper::registerLua(lua);
+ rawrbox::MeshWrapper::registerLua(lua);
+ // ----
+
+ // TEXTURES ----
+ rawrbox::TextureWrapper::registerLua(lua);
+ // ------
+
+ // LIGHT ----
+ rawrbox::LightBaseWrapper::registerLua(lua);
+ rawrbox::LightsWrapper::registerLua(lua);
+ // ------
+
+ // FONT ----
+ rawrbox::FontWrapper::registerLua(lua);
+ // ------
+
+#ifdef RAWRBOX_RESOURCES
+ // RESOURCES ---
+ rawrbox::TextureLoaderWrapper::registerLua(lua);
+ rawrbox::FontLoaderWrapper::registerLua(lua);
+// ------
+#endif
+ }
+
+ void registerGlobal(rawrbox::Mod* mod) override {
+ if (mod == nullptr) throw std::runtime_error("[RawrBox-RenderPlugin] Tried to register plugin on invalid mod!");
+ if (this->_window == nullptr) throw std::runtime_error("[RawrBox-RenderPlugin] Window not set!");
+
+ auto& env = mod->getEnvironment();
+
+ // Game singletons
+ env["camera"] = rawrbox::CameraWrapper();
+ env["window"] = rawrbox::WindowWrapper(this->_window);
+ env["stencil"] = rawrbox::StencilWrapper(&this->_window->getStencil());
+
+ env["decals"] = rawrbox::DecalsWrapper();
+ env["lights"] = rawrbox::LightsWrapper();
+
+#ifdef RAWRBOX_RESOURCES
+ // Loaders ----
+ env["texture"] = rawrbox::TextureLoaderWrapper(mod);
+ env["font"] = rawrbox::FontLoaderWrapper(mod);
+ //-----
+#endif
+
+ // Renderer statics ---
+ env["MAX_BONES_PER_VERTEX"] = rawrbox::MAX_BONES_PER_VERTEX;
+ env["MAX_BONES_PER_MODEL"] = rawrbox::MAX_BONES_PER_MODEL;
+ env["CURRENT_VIEW_ID"] = []() { return rawrbox::CURRENT_VIEW_ID; };
+ env["BGFX_FRAME"] = []() { return rawrbox::BGFX_FRAME; };
+ // -----
+ }
+
+ void loadLuaExtensions(rawrbox::Mod* mod) override {
+ if (mod == nullptr) throw std::runtime_error("[RawrBox-RenderPlugin] Tried to register plugin on invalid mod!");
+ rawrbox::SCRIPTING::loadLuaFile("./lua/render_enums.lua", mod->getEnvironment());
+ }
+ };
+} // namespace rawrbox
diff --git a/render/include/rawrbox/render/scripting/wrappers/camera_wrapper.hpp b/render/include/rawrbox/render/scripting/wrappers/camera_wrapper.hpp
new file mode 100644
index 00000000..61096aca
--- /dev/null
+++ b/render/include/rawrbox/render/scripting/wrappers/camera_wrapper.hpp
@@ -0,0 +1,41 @@
+#pragma once
+
+#include
+
+#include
+
+namespace rawrbox {
+ class CameraWrapper {
+ public:
+ CameraWrapper() = default;
+ CameraWrapper(const CameraWrapper&) = default;
+ CameraWrapper(CameraWrapper&&) = default;
+ CameraWrapper& operator=(const CameraWrapper&) = default;
+ CameraWrapper& operator=(CameraWrapper&&) = default;
+ virtual ~CameraWrapper() = default;
+
+ // UTILS -----
+ virtual void setPos(const rawrbox::Vector3f& pos);
+ [[nodiscard]] virtual const rawrbox::Vector3f getPos() const;
+
+ virtual void setAngle(const rawrbox::Vector4f& ang);
+ [[nodiscard]] virtual const rawrbox::Vector4f getAngle() const;
+
+ [[nodiscard]] virtual rawrbox::Vector3f getForward() const;
+ [[nodiscard]] virtual rawrbox::Vector3f getRight() const;
+ [[nodiscard]] virtual rawrbox::Vector3f getUp() const;
+
+ [[nodiscard]] virtual float getZFar() const;
+ [[nodiscard]] virtual float getZNear() const;
+
+ [[nodiscard]] virtual const rawrbox::Matrix4x4 getViewMtx() const;
+ [[nodiscard]] virtual const rawrbox::Matrix4x4 getProjMtx() const;
+ [[nodiscard]] virtual const rawrbox::Matrix4x4 getProjViewMtx() const;
+
+ [[nodiscard]] virtual const rawrbox::Vector3f worldToScreen(const rawrbox::Vector3f& pos) const;
+ [[nodiscard]] virtual const rawrbox::Vector3f screenToWorld(const rawrbox::Vector2f& screen_pos) const;
+ // ----------------
+
+ static void registerLua(sol::state& lua);
+ };
+} // namespace rawrbox
diff --git a/render/include/rawrbox/render/scripting/wrappers/decals_wrapper.hpp b/render/include/rawrbox/render/scripting/wrappers/decals_wrapper.hpp
new file mode 100644
index 00000000..cd6e6581
--- /dev/null
+++ b/render/include/rawrbox/render/scripting/wrappers/decals_wrapper.hpp
@@ -0,0 +1,26 @@
+#pragma once
+
+#include
+
+#include
+
+namespace rawrbox {
+ class DecalsWrapper {
+ public:
+ DecalsWrapper() = default;
+ DecalsWrapper(const DecalsWrapper&) = default;
+ DecalsWrapper(DecalsWrapper&&) = default;
+ DecalsWrapper& operator=(const DecalsWrapper&) = default;
+ DecalsWrapper& operator=(DecalsWrapper&&) = default;
+ virtual ~DecalsWrapper() = default;
+
+ // UTILS -----
+ virtual bool add(const rawrbox::Vector3f& pos, const sol::optional scale, const sol::optional direction, const sol::optional color, const sol::optional atlasId);
+ virtual bool remove(size_t i);
+ virtual const rawrbox::Instance& get(size_t i);
+ virtual size_t count();
+ // -----
+
+ static void registerLua(sol::state& lua);
+ };
+} // namespace rawrbox
diff --git a/render/include/rawrbox/render/scripting/wrappers/light/base_wrapper.hpp b/render/include/rawrbox/render/scripting/wrappers/light/base_wrapper.hpp
new file mode 100644
index 00000000..39fac81d
--- /dev/null
+++ b/render/include/rawrbox/render/scripting/wrappers/light/base_wrapper.hpp
@@ -0,0 +1,52 @@
+#pragma once
+
+#include
+
+#include
+
+namespace rawrbox {
+ class LightBaseWrapper {
+ protected:
+ std::weak_ptr _ref;
+
+ public:
+ LightBaseWrapper(const std::shared_ptr& ref);
+ LightBaseWrapper(const LightBaseWrapper&) = default;
+ LightBaseWrapper(LightBaseWrapper&&) = default;
+ LightBaseWrapper& operator=(const LightBaseWrapper&) = default;
+ LightBaseWrapper& operator=(LightBaseWrapper&&) = default;
+ virtual ~LightBaseWrapper();
+
+ // UTILS ----
+ [[nodiscard]] virtual const rawrbox::Colori getColor() const;
+ virtual void setColor(const rawrbox::Colori& col);
+
+ [[nodiscard]] virtual const rawrbox::Vector4f getData() const;
+
+ virtual void setRadius(float radius);
+ [[nodiscard]] virtual float getRadius() const;
+
+ [[nodiscard]] virtual size_t id() const;
+
+ [[nodiscard]] virtual bool isOn() const;
+ virtual void setStatus(bool on);
+
+ [[nodiscard]] virtual const rawrbox::Vector3f& getPos() const;
+ virtual void setPos(const rawrbox::Vector3f& pos);
+
+ [[nodiscard]] virtual const rawrbox::Vector3f& getOffsetPos() const;
+ virtual void setOffsetPos(const rawrbox::Vector3f& pos);
+
+ [[nodiscard]] virtual const rawrbox::Vector3f getWorldPos() const;
+ [[nodiscard]] virtual rawrbox::LightType getType() const;
+
+ [[nodiscard]] virtual const rawrbox::Vector3f& getDirection() const;
+ virtual void setDirection(const rawrbox::Vector3f& dir);
+ // ------
+
+ [[nodiscard]] virtual bool isValid() const;
+ [[nodiscard]] virtual rawrbox::LightBase* getRef() const;
+
+ static void registerLua(sol::state& lua);
+ };
+} // namespace rawrbox
diff --git a/render/include/rawrbox/render/scripting/wrappers/light/manager_wrapper.hpp b/render/include/rawrbox/render/scripting/wrappers/light/manager_wrapper.hpp
new file mode 100644
index 00000000..2866a2e9
--- /dev/null
+++ b/render/include/rawrbox/render/scripting/wrappers/light/manager_wrapper.hpp
@@ -0,0 +1,55 @@
+#pragma once
+
+#include
+#include
+
+#include
+
+namespace rawrbox {
+ class LightsWrapper {
+ public:
+ LightsWrapper() = default;
+ LightsWrapper(const LightsWrapper&) = default;
+ LightsWrapper(LightsWrapper&&) = default;
+ LightsWrapper& operator=(const LightsWrapper&) = default;
+ LightsWrapper& operator=(LightsWrapper&&) = default;
+ virtual ~LightsWrapper() = default;
+
+ // UTILS ----
+ virtual void setEnabled(bool fb);
+
+ // SUN
+ virtual void setSun(const rawrbox::Vector3f& dir, const rawrbox::Colori& col);
+ virtual const rawrbox::Colori getSunColor();
+ virtual const rawrbox::Vector3f& getSunDir();
+ // ----
+
+ // FOG
+ virtual void setFog(rawrbox::FOG_TYPE type, float end, float density, const sol::optional col);
+
+ virtual rawrbox::FOG_TYPE getFogType();
+ virtual const rawrbox::Colori getFogColor();
+ virtual float getFogEnd();
+ virtual float getFogDensity();
+ // ----
+
+ // AMBIENT
+ virtual void setAmbient(const rawrbox::Colori& col);
+ virtual const rawrbox::Colori getAmbient();
+ // -------
+
+ // Light ----
+ void addPoint(const rawrbox::Vector3f& pos, const rawrbox::Colori& color, float radius);
+ void addSpot(const rawrbox::Vector3f& posMatrix, const rawrbox::Vector3f& direction, const rawrbox::Colori& color, float innerCone, float outerCone, float power);
+
+ void removeLight(rawrbox::LightBaseWrapper& light);
+ // ---------
+
+ // Light utils ----
+ virtual rawrbox::LightBaseWrapper getLight(size_t indx);
+ virtual size_t count();
+ // ---------
+
+ static void registerLua(sol::state& lua);
+ };
+} // namespace rawrbox
diff --git a/render/include/rawrbox/render/scripting/wrappers/model/base_wrapper.hpp b/render/include/rawrbox/render/scripting/wrappers/model/base_wrapper.hpp
new file mode 100644
index 00000000..d0f58ba5
--- /dev/null
+++ b/render/include/rawrbox/render/scripting/wrappers/model/base_wrapper.hpp
@@ -0,0 +1,49 @@
+#pragma once
+
+#include
+#include
+#include
+#include
+
+#include
+
+namespace rawrbox {
+ template
+ class ModelBase;
+
+ class ModelBaseWrapper {
+ protected:
+ std::weak_ptr> _ref;
+
+ public:
+ ModelBaseWrapper(const std::shared_ptr>& ref);
+ ModelBaseWrapper(const ModelBaseWrapper&) = default;
+ ModelBaseWrapper(ModelBaseWrapper&&) = default;
+ ModelBaseWrapper& operator=(const ModelBaseWrapper&) = default;
+ ModelBaseWrapper& operator=(ModelBaseWrapper&&) = default;
+ virtual ~ModelBaseWrapper();
+
+ // UTILS ----
+ [[nodiscard]] virtual const rawrbox::Vector3f getPos() const;
+ virtual void setPos(const rawrbox::Vector3f& pos);
+
+ [[nodiscard]] virtual const rawrbox::Vector3f getScale() const;
+ virtual void setScale(const rawrbox::Vector3f& scale);
+
+ [[nodiscard]] virtual const rawrbox::Vector4f getAngle() const;
+ virtual void setAngle(const rawrbox::Vector4f& ang);
+
+ virtual void setEulerAngle(const rawrbox::Vector3f& ang);
+
+ [[nodiscard]] virtual const rawrbox::Matrix4x4 getMatrix() const;
+
+ [[nodiscard]] virtual bool isDynamic() const;
+
+ [[nodiscard]] virtual bool isUploaded() const;
+ // ------
+
+ [[nodiscard]] bool isValid() const;
+
+ static void registerLua(sol::state& lua);
+ };
+} // namespace rawrbox
diff --git a/render/include/rawrbox/render/scripting/wrappers/model/mesh_wrapper.hpp b/render/include/rawrbox/render/scripting/wrappers/model/mesh_wrapper.hpp
new file mode 100644
index 00000000..a7b40dff
--- /dev/null
+++ b/render/include/rawrbox/render/scripting/wrappers/model/mesh_wrapper.hpp
@@ -0,0 +1,12 @@
+#pragma once
+
+#include
+
+#include
+
+namespace rawrbox {
+ class MeshWrapper {
+ public:
+ static void registerLua(sol::state& lua);
+ };
+} // namespace rawrbox
diff --git a/render/include/rawrbox/render/scripting/wrappers/model/model_wrapper.hpp b/render/include/rawrbox/render/scripting/wrappers/model/model_wrapper.hpp
new file mode 100644
index 00000000..a6cb4438
--- /dev/null
+++ b/render/include/rawrbox/render/scripting/wrappers/model/model_wrapper.hpp
@@ -0,0 +1,49 @@
+#pragma once
+
+#include
+#include
+#include
+#include
+#include
+
+#include
+
+namespace rawrbox {
+ class ModelWrapper : public rawrbox::ModelBaseWrapper {
+
+ public:
+ ModelWrapper(const std::shared_ptr>& ref);
+ ModelWrapper(const ModelWrapper&) = default;
+ ModelWrapper(ModelWrapper&&) = default;
+ ModelWrapper& operator=(const ModelWrapper&) = default;
+ ModelWrapper& operator=(ModelWrapper&&) = default;
+ ~ModelWrapper() override = default;
+
+ // ANIMS ---
+ virtual void playAnimation(const std::string& name, sol::optional loop, sol::optional speed);
+ virtual void stopAnimation(const std::string& name);
+ // ---
+
+ // UTILS ---
+ virtual void setOptimizable(bool optimize);
+ virtual void optimize();
+
+ void setPos(const rawrbox::Vector3f& pos) override;
+ void setAngle(const rawrbox::Vector4f& angle) override;
+ void setEulerAngle(const rawrbox::Vector3f& angle) override;
+ void setScale(const rawrbox::Vector3f& size) override;
+
+ [[nodiscard]] virtual const rawrbox::BBOX getBBOX() const;
+ [[nodiscard]] virtual size_t totalMeshes() const;
+ [[nodiscard]] virtual bool empty() const;
+
+ virtual void removeMeshByName(const std::string& id);
+ virtual void removeMesh(size_t index);
+
+ virtual rawrbox::Mesh* getMeshByName(const std::string& id);
+ virtual rawrbox::Mesh* getMesh(sol::optional id);
+ // ---
+
+ static void registerLua(sol::state& lua);
+ };
+} // namespace rawrbox
diff --git a/render/include/rawrbox/render/scripting/wrappers/resources/font_loader_wrapper.hpp b/render/include/rawrbox/render/scripting/wrappers/resources/font_loader_wrapper.hpp
new file mode 100644
index 00000000..eb49e742
--- /dev/null
+++ b/render/include/rawrbox/render/scripting/wrappers/resources/font_loader_wrapper.hpp
@@ -0,0 +1,24 @@
+#pragma once
+
+#include
+#include
+
+#include
+
+namespace rawrbox {
+ class FontLoaderWrapper {
+ rawrbox::Mod* _mod;
+
+ public:
+ FontLoaderWrapper(rawrbox::Mod* mod_);
+ FontLoaderWrapper(const FontLoaderWrapper&) = default;
+ FontLoaderWrapper(FontLoaderWrapper&&) = default;
+ FontLoaderWrapper& operator=(const FontLoaderWrapper&) = default;
+ FontLoaderWrapper& operator=(FontLoaderWrapper&&) = default;
+ virtual ~FontLoaderWrapper() = default;
+
+ virtual rawrbox::FontWrapper get(const std::string& path, sol::optional size);
+
+ static void registerLua(sol::state& lua);
+ };
+} // namespace rawrbox
diff --git a/render/include/rawrbox/render/scripting/wrappers/resources/texture_loader_wrapper.hpp b/render/include/rawrbox/render/scripting/wrappers/resources/texture_loader_wrapper.hpp
new file mode 100644
index 00000000..d7679834
--- /dev/null
+++ b/render/include/rawrbox/render/scripting/wrappers/resources/texture_loader_wrapper.hpp
@@ -0,0 +1,24 @@
+#pragma once
+
+#include
+#include
+
+#include
+
+namespace rawrbox {
+ class TextureLoaderWrapper {
+ rawrbox::Mod* _mod;
+
+ public:
+ TextureLoaderWrapper(rawrbox::Mod* mod_);
+ TextureLoaderWrapper(const TextureLoaderWrapper&) = default;
+ TextureLoaderWrapper(TextureLoaderWrapper&&) = default;
+ TextureLoaderWrapper& operator=(const TextureLoaderWrapper&) = default;
+ TextureLoaderWrapper& operator=(TextureLoaderWrapper&&) = default;
+ virtual ~TextureLoaderWrapper() = default;
+
+ virtual rawrbox::TextureWrapper get(const std::string& path, sol::optional loadFlags);
+
+ static void registerLua(sol::state& lua);
+ };
+} // namespace rawrbox
diff --git a/render/include/rawrbox/render/scripting/wrappers/stencil_wrapper.hpp b/render/include/rawrbox/render/scripting/wrappers/stencil_wrapper.hpp
new file mode 100644
index 00000000..f0c95c94
--- /dev/null
+++ b/render/include/rawrbox/render/scripting/wrappers/stencil_wrapper.hpp
@@ -0,0 +1,57 @@
+#pragma once
+
+#include
+#include
+#include
+
+#include
+
+namespace rawrbox {
+ class StencilWrapper {
+ protected:
+ rawrbox::Stencil* _stencil = nullptr;
+
+ public:
+ StencilWrapper(rawrbox::Stencil* stencil);
+ StencilWrapper(const StencilWrapper&) = default;
+ StencilWrapper(StencilWrapper&&) = default;
+ StencilWrapper& operator=(const StencilWrapper&) = default;
+ StencilWrapper& operator=(StencilWrapper&&) = default;
+ virtual ~StencilWrapper() = default;
+
+ // Draw ----
+ // virtual void drawPolygon(rawrbox::Polygon poly);
+ virtual void drawTriangle(const rawrbox::Vector2f& a, const rawrbox::Vector2f& aUV, const rawrbox::Colori& colA, const rawrbox::Vector2f& b, const rawrbox::Vector2f& bUV, const rawrbox::Colori& colB, const rawrbox::Vector2f& c, const rawrbox::Vector2f& cUV, const rawrbox::Colori& colC);
+ virtual void drawBox(const rawrbox::Vector2f& pos, const rawrbox::Vector2f& size, const sol::optional col);
+ virtual void drawTexture(const rawrbox::Vector2f& pos, const rawrbox::Vector2f& size, const rawrbox::TextureWrapper& tex, const sol::optional col, const sol::optional uvStart, const sol::optional uvEnd);
+ virtual void drawCircle(const rawrbox::Vector2f& pos, const rawrbox::Vector2f& size, const sol::optional col, const sol::optional roundness, const sol::optional angleStart, const sol::optional angleEnd);
+ virtual void drawLine(const rawrbox::Vector2& from, const rawrbox::Vector2& to, const sol::optional col);
+ virtual void drawText(const rawrbox::FontWrapper& font, const std::string& text, const rawrbox::Vector2f& pos, const sol::optional& col, const sol::optional alignX, const sol::optional alignY);
+ // ------
+
+ // Pop & Push ----
+ virtual void pushOffset(const rawrbox::Vector2f& offset);
+ virtual void popOffset();
+
+ virtual void pushLocalOffset();
+ virtual void popLocalOffset();
+
+ virtual void pushRotation(float _rotation, const rawrbox::Vector2f& _origin);
+ virtual void popRotation();
+
+ virtual void pushOutline(float thickness, float stipple = 0.F);
+ virtual void popOutline();
+
+ virtual void pushClipping(const rawrbox::AABB& rect);
+ virtual void popClipping();
+
+ virtual void pushScale(const rawrbox::Vector2f& scale);
+ virtual void popScale();
+
+ virtual void pushDisableCulling();
+ virtual void popDisableCulling();
+ // ------
+
+ static void registerLua(sol::state& lua);
+ };
+} // namespace rawrbox
diff --git a/render/include/rawrbox/render/scripting/wrappers/text/font_wrapper.hpp b/render/include/rawrbox/render/scripting/wrappers/text/font_wrapper.hpp
new file mode 100644
index 00000000..0af0d294
--- /dev/null
+++ b/render/include/rawrbox/render/scripting/wrappers/text/font_wrapper.hpp
@@ -0,0 +1,33 @@
+#pragma once
+
+#include
+
+#include
+
+namespace rawrbox {
+ class FontWrapper {
+ rawrbox::Font* _ref = nullptr;
+
+ public:
+ FontWrapper(rawrbox::Font* instance);
+ FontWrapper(const FontWrapper&) = default;
+ FontWrapper(FontWrapper&&) = default;
+ FontWrapper& operator=(const FontWrapper&) = default;
+ FontWrapper& operator=(FontWrapper&&) = default;
+ virtual ~FontWrapper() = default;
+
+ [[nodiscard]] virtual rawrbox::Font* getRef() const;
+
+ // UTILS -----
+ [[nodiscard]] virtual bool isValid() const;
+ [[nodiscard]] virtual float getSize() const;
+ [[nodiscard]] virtual float getScale() const;
+ [[nodiscard]] virtual float getLineHeight() const;
+
+ [[nodiscard]] virtual rawrbox::Vector2f getStringSize(const std::string& text) const;
+ [[nodiscard]] virtual bool hasGlyph(uint32_t codepoint) const;
+ // ------
+
+ static void registerLua(sol::state& lua);
+ };
+} // namespace rawrbox
diff --git a/render/include/rawrbox/render/scripting/wrappers/textures/base_wrapper.hpp b/render/include/rawrbox/render/scripting/wrappers/textures/base_wrapper.hpp
new file mode 100644
index 00000000..5eaed380
--- /dev/null
+++ b/render/include/rawrbox/render/scripting/wrappers/textures/base_wrapper.hpp
@@ -0,0 +1,32 @@
+#pragma once
+
+#include
+
+#include
+
+namespace rawrbox {
+ class TextureWrapper {
+ protected:
+ rawrbox::TextureBase* _texture = nullptr;
+
+ public:
+ TextureWrapper(rawrbox::TextureBase* texture);
+ TextureWrapper(const TextureWrapper&) = default;
+ TextureWrapper(TextureWrapper&&) = default;
+ TextureWrapper& operator=(const TextureWrapper&) = default;
+ TextureWrapper& operator=(TextureWrapper&&) = default;
+ virtual ~TextureWrapper() = default;
+
+ [[nodiscard]] virtual rawrbox::TextureBase* getRef() const;
+
+ // UTILS----
+ [[nodiscard]] virtual bool hasTransparency() const;
+ [[nodiscard]] virtual const rawrbox::Vector2i getSize() const;
+ [[nodiscard]] virtual bool isValid() const;
+
+ [[nodiscard]] virtual std::array getData() const;
+ // -----
+
+ static void registerLua(sol::state& lua);
+ };
+} // namespace rawrbox
diff --git a/render/include/rawrbox/render/scripting/wrappers/window_wrapper.hpp b/render/include/rawrbox/render/scripting/wrappers/window_wrapper.hpp
new file mode 100644
index 00000000..58649e7f
--- /dev/null
+++ b/render/include/rawrbox/render/scripting/wrappers/window_wrapper.hpp
@@ -0,0 +1,39 @@
+#pragma once
+
+#include
+
+#include
+
+namespace rawrbox {
+ class WindowWrapper {
+ protected:
+ rawrbox::Window* _window = nullptr;
+
+ public:
+ WindowWrapper(rawrbox::Window* window);
+ WindowWrapper(const WindowWrapper&) = default;
+ WindowWrapper(WindowWrapper&&) = default;
+ WindowWrapper& operator=(const WindowWrapper&) = default;
+ WindowWrapper& operator=(WindowWrapper&&) = default;
+ virtual ~WindowWrapper() = default;
+
+ // Utils ----
+ virtual void setTitle(const std::string& title);
+
+ virtual void hideCursor(bool hidden);
+ virtual void setCursor(uint32_t cursor);
+
+ virtual void close();
+
+ [[nodiscard]] virtual rawrbox::Vector2i getSize() const;
+ [[nodiscard]] virtual float getAspectRatio() const;
+
+ [[nodiscard]] virtual rawrbox::Vector2i getMousePos() const;
+
+ [[nodiscard]] virtual bool isKeyDown(int key) const;
+ [[nodiscard]] virtual bool isMouseDown(int key) const;
+ // -------
+
+ static void registerLua(sol::state& lua);
+ };
+} // namespace rawrbox
diff --git a/render/include/rawrbox/render/static.hpp b/render/include/rawrbox/render/static.hpp
index a81bb823..2561f55d 100644
--- a/render/include/rawrbox/render/static.hpp
+++ b/render/include/rawrbox/render/static.hpp
@@ -28,7 +28,6 @@ namespace rawrbox {
constexpr auto MAX_BONES_PER_VERTEX = 4;
constexpr auto MAX_BONES_PER_MODEL = 200;
- constexpr auto MAX_LIGHTS = 1000;
extern bool BGFX_INITIALIZED;
diff --git a/render/include/rawrbox/render/stencil.hpp b/render/include/rawrbox/render/stencil.hpp
index d8efa9b6..184a9a41 100644
--- a/render/include/rawrbox/render/stencil.hpp
+++ b/render/include/rawrbox/render/stencil.hpp
@@ -33,11 +33,11 @@ namespace rawrbox {
struct PolygonVertice {
rawrbox::Vector2f pos = {};
rawrbox::Vector2f uv = {};
- rawrbox::Color col = rawrbox::Colors::White;
+ rawrbox::Color col = rawrbox::Colors::White();
};
struct Polygon {
- std::vector verts = {};
+ std::vector verts = {};
std::vector indices = {};
};
@@ -45,7 +45,7 @@ namespace rawrbox {
bgfx::ProgramHandle stencilProgram = BGFX_INVALID_HANDLE;
bgfx::TextureHandle textureHandle = BGFX_INVALID_HANDLE;
- std::vector vertices = {};
+ std::vector vertices = {};
std::vector indices = {};
uint64_t drawMode = 0;
@@ -216,13 +216,13 @@ namespace rawrbox {
virtual void resize(const rawrbox::Vector2i& size);
// ------ UTILS
- virtual void drawPolygon(rawrbox::Polygon poly);
+ virtual void drawPolygon(const rawrbox::Polygon& poly);
virtual void drawTriangle(const rawrbox::Vector2f& a, const rawrbox::Vector2f& aUV, const rawrbox::Color& colA, const rawrbox::Vector2f& b, const rawrbox::Vector2f& bUV, const rawrbox::Color& colB, const rawrbox::Vector2f& c, const rawrbox::Vector2f& cUV, const rawrbox::Color& colC);
- virtual void drawBox(const rawrbox::Vector2f& pos, const rawrbox::Vector2f& size, const rawrbox::Color& col = rawrbox::Colors::White);
- virtual void drawTexture(const rawrbox::Vector2f& pos, const rawrbox::Vector2f& size, const rawrbox::TextureBase& tex, const rawrbox::Color& col = rawrbox::Colors::White, const rawrbox::Vector2f& uvStart = {0, 0}, const rawrbox::Vector2f& uvEnd = {1, 1});
- virtual void drawCircle(const rawrbox::Vector2f& pos, const rawrbox::Vector2f& size, const rawrbox::Color& col = rawrbox::Colors::White, size_t roundness = 32, float angleStart = 0.F, float angleEnd = 360.F);
- virtual void drawLine(const rawrbox::Vector2& from, const rawrbox::Vector2& to, const rawrbox::Color& col = rawrbox::Colors::White);
- virtual void drawText(const rawrbox::Font& font, const std::string& text, const rawrbox::Vector2f& pos, const rawrbox::Color& col = rawrbox::Colors::White, rawrbox::Alignment alignX = rawrbox::Alignment::Left, rawrbox::Alignment alignY = rawrbox::Alignment::Left);
+ virtual void drawBox(const rawrbox::Vector2f& pos, const rawrbox::Vector2f& size, const rawrbox::Color& col = rawrbox::Colors::White());
+ virtual void drawTexture(const rawrbox::Vector2f& pos, const rawrbox::Vector2f& size, const rawrbox::TextureBase& tex, const rawrbox::Color& col = rawrbox::Colors::White(), const rawrbox::Vector2f& uvStart = {0, 0}, const rawrbox::Vector2f& uvEnd = {1, 1});
+ virtual void drawCircle(const rawrbox::Vector2f& pos, const rawrbox::Vector2f& size, const rawrbox::Color& col = rawrbox::Colors::White(), size_t roundness = 32, float angleStart = 0.F, float angleEnd = 360.F);
+ virtual void drawLine(const rawrbox::Vector2& from, const rawrbox::Vector2& to, const rawrbox::Color& col = rawrbox::Colors::White());
+ virtual void drawText(const rawrbox::Font& font, const std::string& text, const rawrbox::Vector2f& pos, const rawrbox::Color& col = rawrbox::Colors::White(), rawrbox::Alignment alignX = rawrbox::Alignment::Left, rawrbox::Alignment alignY = rawrbox::Alignment::Left);
// --------------------
// ------ RENDERING
diff --git a/render/include/rawrbox/render/text/font.hpp b/render/include/rawrbox/render/text/font.hpp
index 6cf8880c..14fd379a 100644
--- a/render/include/rawrbox/render/text/font.hpp
+++ b/render/include/rawrbox/render/text/font.hpp
@@ -102,14 +102,14 @@ namespace rawrbox {
rawrbox::FontInfo _info = {};
// INTERNAL ---
- void loadFontInfo();
+ virtual void loadFontInfo();
std::unique_ptr bakeGlyphAlpha(uint32_t codePoint);
- void generateGlyph(uint32_t codePoint);
+ virtual void generateGlyph(uint32_t codePoint);
// ----
public:
- ~Font();
+ virtual ~Font();
Font(const std::vector& buffer, uint32_t pixelHeight, int32_t fontIndex = 0, int16_t widthPadding = 6, int16_t heightPadding = 6);
Font(Font&&) = delete;
@@ -118,24 +118,24 @@ namespace rawrbox {
Font& operator=(const Font&) = delete;
// LOADING ---
- void addChars(const std::string& chars);
+ virtual void addChars(const std::string& chars);
// ----
// UTILS ---
- [[nodiscard]] const rawrbox::FontInfo getFontInfo() const;
+ [[nodiscard]] virtual const rawrbox::FontInfo getFontInfo() const;
- [[nodiscard]] bool hasGlyph(uint32_t codepoint) const;
- [[nodiscard]] rawrbox::Glyph* getGlyph(uint32_t codepoint) const;
+ [[nodiscard]] virtual bool hasGlyph(uint32_t codepoint) const;
+ [[nodiscard]] virtual rawrbox::Glyph* getGlyph(uint32_t codepoint) const;
- [[nodiscard]] float getSize() const;
- [[nodiscard]] float getScale() const;
- [[nodiscard]] float getLineHeight() const;
- [[nodiscard]] float getKerning(uint32_t prevCodePoint, uint32_t nextCodePoint) const;
+ [[nodiscard]] virtual float getSize() const;
+ [[nodiscard]] virtual float getScale() const;
+ [[nodiscard]] virtual float getLineHeight() const;
+ [[nodiscard]] virtual float getKerning(uint32_t prevCodePoint, uint32_t nextCodePoint) const;
- [[nodiscard]] rawrbox::Vector2f getStringSize(const std::string& text) const;
- [[nodiscard]] rawrbox::TexturePack* getPackTexture(rawrbox::Glyph* g) const;
+ [[nodiscard]] virtual rawrbox::Vector2f getStringSize(const std::string& text) const;
+ [[nodiscard]] virtual rawrbox::TexturePack* getPackTexture(rawrbox::Glyph* g) const;
- void render(const std::string& text, const rawrbox::Vector2f& pos, bool yIsUp, std::function render) const;
+ virtual void render(const std::string& text, const rawrbox::Vector2f& pos, bool yIsUp, std::function render) const;
// ----
// GLOBAL UTILS ---
diff --git a/render/include/rawrbox/render/texture/base.hpp b/render/include/rawrbox/render/texture/base.hpp
index df0744b0..e5fae9aa 100644
--- a/render/include/rawrbox/render/texture/base.hpp
+++ b/render/include/rawrbox/render/texture/base.hpp
@@ -36,15 +36,15 @@ namespace rawrbox {
// UTILS----
[[nodiscard]] virtual bool hasTransparency() const;
- [[nodiscard]] const virtual rawrbox::Vector2i& getSize() const;
- [[nodiscard]] virtual bool valid() const;
- [[nodiscard]] const virtual bgfx::TextureHandle& getHandle() const;
+ [[nodiscard]] virtual const rawrbox::Vector2i& getSize() const;
+ [[nodiscard]] virtual bool isValid() const;
+ [[nodiscard]] virtual const bgfx::TextureHandle& getHandle() const;
+ [[nodiscard]] virtual std::array getData() const;
// -----
virtual void setFlags(uint64_t flags);
virtual void upload(bgfx::TextureFormat::Enum format = bgfx::TextureFormat::Count) = 0;
virtual void update();
- virtual std::array getData();
};
} // namespace rawrbox
diff --git a/render/include/rawrbox/render/texture/pack.hpp b/render/include/rawrbox/render/texture/pack.hpp
index 0ba4d66a..206f1e20 100644
--- a/render/include/rawrbox/render/texture/pack.hpp
+++ b/render/include/rawrbox/render/texture/pack.hpp
@@ -20,7 +20,7 @@ namespace rawrbox {
std::unique_ptr right = nullptr;
bool canInsertNode(int insertedWidth, int insertedHeight);
- std::optional> InsertNode(int width, int height);
+ std::optional> InsertNode(int width, int height);
PackNode() = default;
PackNode(int _x, int _y, int _w, int _h) : x(_x), y(_y), width(_w), height(_h){};
diff --git a/render/include/rawrbox/render/window.hpp b/render/include/rawrbox/render/window.hpp
index 7bcd52f0..f9b57093 100644
--- a/render/include/rawrbox/render/window.hpp
+++ b/render/include/rawrbox/render/window.hpp
@@ -191,8 +191,6 @@ namespace rawrbox {
// UTILS ---------------
void close();
- [[nodiscard]] virtual bool getShouldClose() const;
- virtual void setShouldClose(bool close) const;
[[nodiscard]] virtual rawrbox::Vector2i getSize() const;
[[nodiscard]] virtual float getAspectRatio() const;
diff --git a/render/lua/render_enums.lua b/render/lua/render_enums.lua
new file mode 100644
index 00000000..f9dbf3d0
--- /dev/null
+++ b/render/lua/render_enums.lua
@@ -0,0 +1,12 @@
+LightType = {
+ UNKNOWN = 0,
+
+ POINT = 1,
+ SPOT = 2,
+ DIR = 3,
+}
+
+FogType = {
+ FOG_LINEAR = 0,
+ FOG_EXP = 1
+}
diff --git a/render/src/decals/manager.cpp b/render/src/decals/manager.cpp
index d30a5e9c..56d930c1 100644
--- a/render/src/decals/manager.cpp
+++ b/render/src/decals/manager.cpp
@@ -15,18 +15,20 @@ namespace rawrbox {
_model->getTemplate().setTexture(atlas);
}
- void DECALS::add(const rawrbox::Vector3f& pos, const rawrbox::Vector3f& scale, float direction, const rawrbox::Colorf& color, uint16_t atlasId) {
- if (_model == nullptr) return;
+ bool DECALS::add(const rawrbox::Vector3f& pos, const rawrbox::Vector3f& scale, float direction, const rawrbox::Colorf& color, uint16_t atlasId) {
+ if (_model == nullptr) return false;
rawrbox::Matrix4x4 m;
m.mtxSRT(scale, rawrbox::Vector4f::toQuat({bx::toRad(direction), 0, 0}), pos);
_model->addInstance({m, color, {static_cast(atlasId), 0, 0, 0}});
+ return true;
}
- void DECALS::remove(size_t i) {
- if (_model == nullptr) return;
+ bool DECALS::remove(size_t i) {
+ if (_model == nullptr) return false;
_model->removeInstance(i);
+ return true;
}
const rawrbox::Instance& DECALS::get(size_t i) {
diff --git a/render/src/light/manager.cpp b/render/src/light/manager.cpp
index 8f5b9966..e3f43987 100644
--- a/render/src/light/manager.cpp
+++ b/render/src/light/manager.cpp
@@ -5,7 +5,7 @@
namespace rawrbox {
// PRIVATE ----
- std::vector> LIGHTS::_lights = {};
+ std::vector> LIGHTS::_lights = {};
bgfx::DynamicVertexBufferHandle LIGHTS::_buffer = BGFX_INVALID_HANDLE;
bgfx::UniformHandle LIGHTS::_u_lightSettings = BGFX_INVALID_HANDLE;
@@ -21,7 +21,7 @@ namespace rawrbox {
rawrbox::Colorf LIGHTS::_ambient = {0.01F, 0.01F, 0.01F, 1.F};
// Sun --
- rawrbox::Colorf LIGHTS::_sun_color = rawrbox::Colors::Transparent; // No sun by default
+ rawrbox::Colorf LIGHTS::_sun_color = rawrbox::Colors::Transparent(); // No sun by default
rawrbox::Vector3f LIGHTS::_sun_direction = {0, 0, 0};
// Fog --
diff --git a/render/src/materials/base.cpp b/render/src/materials/base.cpp
index 3a53a061..11d94f30 100644
--- a/render/src/materials/base.cpp
+++ b/render/src/materials/base.cpp
@@ -36,7 +36,7 @@ namespace rawrbox {
}
void MaterialBase::process(const rawrbox::Mesh& mesh) {
- if (mesh.texture != nullptr && mesh.texture->valid() && !mesh.lineMode && !mesh.wireframe) {
+ if (mesh.texture != nullptr && mesh.texture->isValid() && !mesh.lineMode && !mesh.wireframe) {
mesh.texture->update(); // Update texture
bgfx::setUniform(this->_u_tex_flags, mesh.texture->getData().data());
@@ -45,7 +45,7 @@ namespace rawrbox {
bgfx::setTexture(rawrbox::SAMPLE_MAT_ALBEDO, this->_s_albedo, rawrbox::WHITE_TEXTURE->getHandle());
}
- if (mesh.displacementTexture != nullptr && mesh.displacementTexture->valid()) {
+ if (mesh.displacementTexture != nullptr && mesh.displacementTexture->isValid()) {
bgfx::setTexture(rawrbox::SAMPLE_MAT_DISPLACEMENT, this->_s_displacement, mesh.displacementTexture->getHandle());
} else {
bgfx::setTexture(rawrbox::SAMPLE_MAT_DISPLACEMENT, this->_s_displacement, rawrbox::BLACK_TEXTURE->getHandle());
diff --git a/render/src/materials/lit.cpp b/render/src/materials/lit.cpp
index a224ce08..c9578387 100644
--- a/render/src/materials/lit.cpp
+++ b/render/src/materials/lit.cpp
@@ -48,19 +48,19 @@ namespace rawrbox {
}
void MaterialLit::process(const rawrbox::Mesh& mesh) {
- if (mesh.normalTexture != nullptr && mesh.normalTexture->valid() && !mesh.lineMode && !mesh.wireframe) {
+ if (mesh.normalTexture != nullptr && mesh.normalTexture->isValid() && !mesh.lineMode && !mesh.wireframe) {
bgfx::setTexture(rawrbox::SAMPLE_MAT_NORMAL, this->_s_normal, mesh.normalTexture->getHandle());
} else {
bgfx::setTexture(rawrbox::SAMPLE_MAT_NORMAL, this->_s_normal, rawrbox::NORMAL_TEXTURE->getHandle());
}
- if (mesh.specularTexture != nullptr && mesh.specularTexture->valid() && !mesh.lineMode && !mesh.wireframe) {
+ if (mesh.specularTexture != nullptr && mesh.specularTexture->isValid() && !mesh.lineMode && !mesh.wireframe) {
bgfx::setTexture(rawrbox::SAMPLE_MAT_SPECULAR, this->_s_specular, mesh.specularTexture->getHandle());
} else {
bgfx::setTexture(rawrbox::SAMPLE_MAT_SPECULAR, this->_s_specular, rawrbox::BLACK_TEXTURE->getHandle());
}
- if (mesh.emissionTexture != nullptr && mesh.emissionTexture->valid() && !mesh.lineMode && !mesh.wireframe) {
+ if (mesh.emissionTexture != nullptr && mesh.emissionTexture->isValid() && !mesh.lineMode && !mesh.wireframe) {
bgfx::setTexture(rawrbox::SAMPLE_MAT_EMISSION, this->_s_emission, mesh.emissionTexture->getHandle());
} else {
bgfx::setTexture(rawrbox::SAMPLE_MAT_EMISSION, this->_s_emission, rawrbox::BLACK_TEXTURE->getHandle());
diff --git a/render/src/model/text3D.cpp b/render/src/model/text3D.cpp
index c8230757..5a765ca4 100644
--- a/render/src/model/text3D.cpp
+++ b/render/src/model/text3D.cpp
@@ -94,7 +94,7 @@ namespace rawrbox {
bgfx::setTransform((this->getMatrix() * mesh->matrix).data());
- if (this->isDynamicBuffer()) {
+ if (this->isDynamic()) {
bgfx::setVertexBuffer(0, this->_vbdh, mesh->baseVertex, mesh->totalVertex);
bgfx::setIndexBuffer(this->_ibdh, mesh->baseIndex, mesh->totalIndex);
} else {
diff --git a/render/src/scripting/wrappers/camera_wrapper.cpp b/render/src/scripting/wrappers/camera_wrapper.cpp
new file mode 100644
index 00000000..3d6ee82e
--- /dev/null
+++ b/render/src/scripting/wrappers/camera_wrapper.cpp
@@ -0,0 +1,101 @@
+#include
+#include
+
+namespace rawrbox {
+
+ // UTILS -----
+ void CameraWrapper::setPos(const rawrbox::Vector3f& pos) {
+ if (rawrbox::MAIN_CAMERA == nullptr) return;
+ rawrbox::MAIN_CAMERA->setPos(pos);
+ }
+
+ const rawrbox::Vector3f CameraWrapper::getPos() const {
+ if (rawrbox::MAIN_CAMERA == nullptr) return {};
+ return rawrbox::MAIN_CAMERA->getPos();
+ }
+
+ void CameraWrapper::setAngle(const rawrbox::Vector4f& ang) {
+ if (rawrbox::MAIN_CAMERA == nullptr) return;
+ rawrbox::MAIN_CAMERA->setAngle(ang);
+ }
+
+ const rawrbox::Vector4f CameraWrapper::getAngle() const {
+ if (rawrbox::MAIN_CAMERA == nullptr) return {};
+ return rawrbox::MAIN_CAMERA->getAngle();
+ }
+
+ rawrbox::Vector3f CameraWrapper::getForward() const {
+ if (rawrbox::MAIN_CAMERA == nullptr) return {};
+ return rawrbox::MAIN_CAMERA->getForward();
+ }
+
+ rawrbox::Vector3f CameraWrapper::getRight() const {
+ if (rawrbox::MAIN_CAMERA == nullptr) return {};
+ return rawrbox::MAIN_CAMERA->getRight();
+ }
+
+ rawrbox::Vector3f CameraWrapper::getUp() const {
+ if (rawrbox::MAIN_CAMERA == nullptr) return {};
+ return rawrbox::MAIN_CAMERA->getUp();
+ }
+
+ float CameraWrapper::getZFar() const {
+ if (rawrbox::MAIN_CAMERA == nullptr) return 0;
+ return rawrbox::MAIN_CAMERA->getZFar();
+ }
+
+ float CameraWrapper::getZNear() const {
+ if (rawrbox::MAIN_CAMERA == nullptr) return 0;
+ return rawrbox::MAIN_CAMERA->getZNear();
+ }
+
+ const rawrbox::Matrix4x4 CameraWrapper::getViewMtx() const {
+ if (rawrbox::MAIN_CAMERA == nullptr) return {};
+ return rawrbox::MAIN_CAMERA->getViewMtx();
+ }
+
+ const rawrbox::Matrix4x4 CameraWrapper::getProjMtx() const {
+ if (rawrbox::MAIN_CAMERA == nullptr) return {};
+ return rawrbox::MAIN_CAMERA->getProjMtx();
+ }
+
+ const rawrbox::Matrix4x4 CameraWrapper::getProjViewMtx() const {
+ if (rawrbox::MAIN_CAMERA == nullptr) return {};
+ return rawrbox::MAIN_CAMERA->getProjViewMtx();
+ }
+
+ const rawrbox::Vector3f CameraWrapper::worldToScreen(const rawrbox::Vector3f& pos) const {
+ if (rawrbox::MAIN_CAMERA == nullptr) return {};
+ return rawrbox::MAIN_CAMERA->worldToScreen(pos);
+ }
+
+ const rawrbox::Vector3f CameraWrapper::screenToWorld(const rawrbox::Vector2f& screen_pos) const {
+ if (rawrbox::MAIN_CAMERA == nullptr) return {};
+ return rawrbox::MAIN_CAMERA->screenToWorld(screen_pos);
+ }
+ // ----------------
+
+ void CameraWrapper::registerLua(sol::state& lua) {
+ lua.new_usertype("Camera",
+ sol::no_constructor,
+
+ "setPos", &CameraWrapper::setPos,
+ "getPos", &CameraWrapper::getPos,
+ "setAngle", &CameraWrapper::setAngle,
+ "getAngle", &CameraWrapper::getAngle,
+
+ // UTILS ----
+ "getForward", &CameraWrapper::getForward,
+ "getRight", &CameraWrapper::getRight,
+ "getUp", &CameraWrapper::getUp,
+ "getZFar", &CameraWrapper::getZFar,
+ "getZNear", &CameraWrapper::getZNear,
+ "getViewMtx", &CameraWrapper::getViewMtx,
+ "getProjMtx", &CameraWrapper::getProjMtx,
+ "getProjViewMtx", &CameraWrapper::getProjViewMtx,
+ "worldToScreen", &CameraWrapper::worldToScreen,
+ "screenToWorld", &CameraWrapper::screenToWorld
+ // ---------
+ );
+ }
+} // namespace rawrbox
diff --git a/render/src/scripting/wrappers/decals_wrapper.cpp b/render/src/scripting/wrappers/decals_wrapper.cpp
new file mode 100644
index 00000000..34ee0959
--- /dev/null
+++ b/render/src/scripting/wrappers/decals_wrapper.cpp
@@ -0,0 +1,35 @@
+#include
+
+namespace rawrbox {
+
+ // UTILS -----
+ bool DecalsWrapper::add(const rawrbox::Vector3f& pos, const sol::optional scale, const sol::optional direction, const sol::optional color, const sol::optional atlasId) {
+ return rawrbox::DECALS::add(pos, scale.value_or(rawrbox::Vector3f::one()), direction.value_or(0.F), color.value_or(rawrbox::Colorsi::White()).cast(), atlasId.value_or(0));
+ }
+
+ bool DecalsWrapper::remove(size_t i) {
+ return rawrbox::DECALS::remove(i);
+ }
+
+ const rawrbox::Instance& DecalsWrapper::get(size_t i) {
+ return rawrbox::DECALS::get(i);
+ }
+
+ size_t DecalsWrapper::count() {
+ return rawrbox::DECALS::count();
+ }
+ // ----------------
+
+ void DecalsWrapper::registerLua(sol::state& lua) {
+ lua.new_usertype("Decals",
+ sol::no_constructor,
+
+ // UTILS ----
+ "add", &DecalsWrapper::add,
+ "remove", &DecalsWrapper::remove,
+ "get", &DecalsWrapper::get,
+ "count", &DecalsWrapper::count
+ // ---------
+ );
+ }
+} // namespace rawrbox
diff --git a/render/src/scripting/wrappers/light/base_wrapper.cpp b/render/src/scripting/wrappers/light/base_wrapper.cpp
new file mode 100644
index 00000000..c8217835
--- /dev/null
+++ b/render/src/scripting/wrappers/light/base_wrapper.cpp
@@ -0,0 +1,132 @@
+
+#include
+
+namespace rawrbox {
+ LightBaseWrapper::LightBaseWrapper(const std::shared_ptr& ref) : _ref(ref) {}
+ LightBaseWrapper::~LightBaseWrapper() { this->_ref.reset(); }
+
+ // UTILS ----
+ const rawrbox::Colori LightBaseWrapper::getColor() const {
+ if (this->isValid()) throw std::runtime_error("[RawrBox-LightBase] Light reference not set!");
+ return this->_ref.lock()->getColor().cast();
+ }
+
+ void LightBaseWrapper::setColor(const rawrbox::Colori& col) {
+ if (this->isValid()) throw std::runtime_error("[RawrBox-LightBase] Light reference not set!");
+ this->_ref.lock()->setColor(col.cast());
+ }
+
+ const rawrbox::Vector4f LightBaseWrapper::getData() const {
+ if (this->isValid()) throw std::runtime_error("[RawrBox-LightBase] Light reference not set!");
+ return this->_ref.lock()->getData();
+ }
+
+ void LightBaseWrapper::setRadius(float radius) {
+ if (this->isValid()) throw std::runtime_error("[RawrBox-LightBase] Light reference not set!");
+ this->_ref.lock()->setRadius(radius);
+ }
+
+ float LightBaseWrapper::getRadius() const {
+ if (this->isValid()) throw std::runtime_error("[RawrBox-LightBase] Light reference not set!");
+ return this->_ref.lock()->getRadius();
+ }
+
+ size_t LightBaseWrapper::id() const {
+ if (this->isValid()) throw std::runtime_error("[RawrBox-LightBase] Light reference not set!");
+ return this->_ref.lock()->id();
+ }
+
+ bool LightBaseWrapper::isOn() const {
+ if (this->isValid()) throw std::runtime_error("[RawrBox-LightBase] Light reference not set!");
+ return this->_ref.lock()->isOn();
+ }
+
+ void LightBaseWrapper::setStatus(bool on) {
+ if (this->isValid()) throw std::runtime_error("[RawrBox-LightBase] Light reference not set!");
+ this->_ref.lock()->setStatus(on);
+ }
+
+ const rawrbox::Vector3f& LightBaseWrapper::getPos() const {
+ if (this->isValid()) throw std::runtime_error("[RawrBox-LightBase] Light reference not set!");
+ return this->_ref.lock()->getPos();
+ }
+
+ void LightBaseWrapper::setPos(const rawrbox::Vector3f& pos) {
+ if (this->isValid()) throw std::runtime_error("[RawrBox-LightBase] Light reference not set!");
+ this->_ref.lock()->setPos(pos);
+ }
+
+ const rawrbox::Vector3f& LightBaseWrapper::getOffsetPos() const {
+ if (this->isValid()) throw std::runtime_error("[RawrBox-LightBase] Light reference not set!");
+ return this->_ref.lock()->getOffsetPos();
+ }
+
+ void LightBaseWrapper::setOffsetPos(const rawrbox::Vector3f& pos) {
+ if (this->isValid()) throw std::runtime_error("[RawrBox-LightBase] Light reference not set!");
+ this->_ref.lock()->setOffsetPos(pos);
+ }
+
+ const rawrbox::Vector3f LightBaseWrapper::getWorldPos() const {
+ if (this->isValid()) throw std::runtime_error("[RawrBox-LightBase] Light reference not set!");
+ return this->_ref.lock()->getWorldPos();
+ }
+
+ rawrbox::LightType LightBaseWrapper::getType() const {
+ if (this->isValid()) throw std::runtime_error("[RawrBox-LightBase] Light reference not set!");
+ return this->_ref.lock()->getType();
+ }
+
+ const rawrbox::Vector3f& LightBaseWrapper::getDirection() const {
+ if (this->isValid()) throw std::runtime_error("[RawrBox-LightBase] Light reference not set!");
+ return this->_ref.lock()->getDirection();
+ }
+
+ void LightBaseWrapper::setDirection(const rawrbox::Vector3f& dir) {
+ if (this->isValid()) throw std::runtime_error("[RawrBox-LightBase] Light reference not set!");
+ this->_ref.lock()->setDirection(dir);
+ }
+ // ------
+
+ bool LightBaseWrapper::isValid() const {
+ return !this->_ref.expired();
+ }
+
+ rawrbox::LightBase* LightBaseWrapper::getRef() const {
+ return nullptr;
+ // return &_ref.lock();
+ }
+
+ void LightBaseWrapper::registerLua(sol::state& lua) {
+ lua.new_usertype("LightBase",
+ sol::no_constructor,
+
+ // UTILS ----
+ "getColor", &LightBaseWrapper::getColor,
+ "setColor", &LightBaseWrapper::setPos,
+
+ "getData", &LightBaseWrapper::getData,
+
+ "setRadius", &LightBaseWrapper::setRadius,
+ "getRadius", &LightBaseWrapper::getRadius,
+
+ "id", &LightBaseWrapper::id,
+
+ "isOn", &LightBaseWrapper::isOn,
+ "setStatus", &LightBaseWrapper::setStatus,
+
+ "getPos", &LightBaseWrapper::getPos,
+ "setPos", &LightBaseWrapper::setPos,
+
+ "getOffsetPos", &LightBaseWrapper::getOffsetPos,
+ "setOffsetPos", &LightBaseWrapper::setOffsetPos,
+
+ "getWorldPos", &LightBaseWrapper::getWorldPos,
+ "getType", &LightBaseWrapper::getType,
+
+ "getDirection", &LightBaseWrapper::getDirection,
+ "setDirection", &LightBaseWrapper::setDirection,
+ // --------------
+
+ "isValid", &LightBaseWrapper::isValid);
+ }
+} // namespace rawrbox
diff --git a/render/src/scripting/wrappers/light/manager_wrapper.cpp b/render/src/scripting/wrappers/light/manager_wrapper.cpp
new file mode 100644
index 00000000..6cebd4b0
--- /dev/null
+++ b/render/src/scripting/wrappers/light/manager_wrapper.cpp
@@ -0,0 +1,122 @@
+#include
+#include
+#include
+
+namespace rawrbox {
+ // UTILS ----
+ void LightsWrapper::setEnabled(bool fb) {
+ rawrbox::LIGHTS::setEnabled(fb);
+ }
+
+ // SUN
+ void LightsWrapper::setSun(const rawrbox::Vector3f& dir, const rawrbox::Colori& col) {
+ rawrbox::LIGHTS::setSun(dir, col.cast());
+ }
+
+ const rawrbox::Colori LightsWrapper::getSunColor() {
+ return rawrbox::LIGHTS::getSunColor().cast();
+ }
+
+ const rawrbox::Vector3f& LightsWrapper::getSunDir() {
+ return rawrbox::LIGHTS::getSunDir();
+ }
+ // ----
+
+ // FOG
+ void LightsWrapper::setFog(rawrbox::FOG_TYPE type, float end, float density, const sol::optional col) {
+ rawrbox::LIGHTS::setFog(type, end, density, col.value_or(rawrbox::Colorsi::White()).cast());
+ }
+
+ rawrbox::FOG_TYPE LightsWrapper::getFogType() {
+ return rawrbox::LIGHTS::getFogType();
+ }
+
+ const rawrbox::Colori LightsWrapper::getFogColor() {
+ return rawrbox::LIGHTS::getFogColor().cast();
+ }
+
+ float LightsWrapper::getFogEnd() {
+ return rawrbox::LIGHTS::getFogEnd();
+ }
+
+ float LightsWrapper::getFogDensity() {
+ return rawrbox::LIGHTS::getFogDensity();
+ }
+ // ----
+
+ // AMBIENT
+ void LightsWrapper::setAmbient(const rawrbox::Colori& col) {
+ rawrbox::LIGHTS::setAmbient(col.cast());
+ }
+
+ const rawrbox::Colori LightsWrapper::getAmbient() {
+ return rawrbox::LIGHTS::getAmbient().cast();
+ }
+ // -------
+
+ // Light ----
+
+ void LightsWrapper::addPoint(const rawrbox::Vector3f& pos, const rawrbox::Colori& color, float radius) {
+ rawrbox::LIGHTS::addLight(pos, color.cast(), radius);
+ }
+
+ void LightsWrapper::addSpot(const rawrbox::Vector3f& posMatrix, const rawrbox::Vector3f& direction, const rawrbox::Colori& color, float innerCone, float outerCone, float power) {
+ rawrbox::LIGHTS::addLight(posMatrix, direction, color.cast(), innerCone, outerCone, power);
+ }
+
+ void LightsWrapper::removeLight(rawrbox::LightBaseWrapper& light) {
+ if (!light.isValid()) return;
+ rawrbox::LIGHTS::removeLight(light.getRef());
+ }
+ // ---------
+
+ // Light utils ----
+ rawrbox::LightBaseWrapper LightsWrapper::getLight(size_t indx) {
+ // auto light = rawrbox::LIGHTS::getLight(indx);
+ // return {light};
+ throw std::runtime_error("AAAAAAAAAAA");
+ }
+
+ size_t LightsWrapper::count() {
+ return rawrbox::LIGHTS::count();
+ }
+ // ---------
+
+ void LightsWrapper::registerLua(sol::state& lua) {
+ lua.new_usertype("Lights",
+ sol::no_constructor,
+
+ // UTILS ----
+ "setEnabled", &LightsWrapper::setEnabled,
+ // ---------
+
+ // SUN
+ "setSun", &LightsWrapper::setFog,
+ "getSunColor", &LightsWrapper::getSunColor,
+ "getSunDir", &LightsWrapper::getSunDir,
+ // ---------
+
+ // FOG
+ "setFog", &LightsWrapper::setFog,
+ "getFogType", &LightsWrapper::getFogType,
+ "getFogColor", &LightsWrapper::getFogColor,
+ "getFogEnd", &LightsWrapper::getFogEnd,
+ "getFogDensity", &LightsWrapper::getFogDensity,
+ // ---------
+
+ // AMBIENT
+ "setAmbient", &LightsWrapper::setAmbient,
+ "getAmbient", &LightsWrapper::getAmbient,
+ // ---------
+
+ // Light
+ "removeLight", &LightsWrapper::removeLight,
+ // ---------
+
+ // Light utils
+ "getLight", &LightsWrapper::getLight,
+ "count", &LightsWrapper::count
+ // ---------
+ );
+ }
+} // namespace rawrbox
diff --git a/render/src/scripting/wrappers/model/base_wrapper.cpp b/render/src/scripting/wrappers/model/base_wrapper.cpp
new file mode 100644
index 00000000..c3a4fe40
--- /dev/null
+++ b/render/src/scripting/wrappers/model/base_wrapper.cpp
@@ -0,0 +1,87 @@
+
+#include
+#include
+
+namespace rawrbox {
+ ModelBaseWrapper::ModelBaseWrapper(const std::shared_ptr>& ref) : _ref(ref) {}
+ ModelBaseWrapper::~ModelBaseWrapper() { this->_ref.reset(); }
+
+ // UTILS ----
+ const rawrbox::Vector3f ModelBaseWrapper::getPos() const {
+ if (!this->isValid()) return {};
+ return this->_ref.lock()->getPos();
+ }
+
+ void ModelBaseWrapper::setPos(const rawrbox::Vector3f& pos) {
+ if (!this->isValid()) return;
+ this->_ref.lock()->setPos(pos);
+ }
+
+ const rawrbox::Vector3f ModelBaseWrapper::getScale() const {
+ if (!this->isValid()) return {};
+ return this->_ref.lock()->getScale();
+ }
+
+ void ModelBaseWrapper::setScale(const rawrbox::Vector3f& scale) {
+ if (!this->isValid()) return;
+ this->_ref.lock()->setScale(scale);
+ }
+
+ const rawrbox::Vector4f ModelBaseWrapper::getAngle() const {
+ if (!this->isValid()) return {};
+ return this->_ref.lock()->getAngle();
+ }
+
+ void ModelBaseWrapper::setAngle(const rawrbox::Vector4f& ang) {
+ if (!this->isValid()) return;
+ this->_ref.lock()->setAngle(ang);
+ }
+
+ void ModelBaseWrapper::setEulerAngle(const rawrbox::Vector3f& ang) {
+ if (!this->isValid()) return;
+ this->_ref.lock()->setEulerAngle(ang);
+ }
+
+ const rawrbox::Matrix4x4 ModelBaseWrapper::getMatrix() const {
+ if (!this->isValid()) return {};
+ return this->_ref.lock()->getMatrix();
+ }
+
+ bool ModelBaseWrapper::isDynamic() const {
+ if (!this->isValid()) return false;
+ return this->_ref.lock()->isDynamic();
+ }
+
+ bool ModelBaseWrapper::isUploaded() const {
+ if (!this->isValid()) return false;
+ return this->_ref.lock()->isUploaded();
+ }
+ // ------
+
+ bool ModelBaseWrapper::isValid() const {
+ return !this->_ref.expired();
+ }
+
+ void ModelBaseWrapper::registerLua(sol::state& lua) {
+ lua.new_usertype("ModelBase<>",
+ sol::no_constructor,
+
+ // UTILS ----
+ "getPos", &ModelBaseWrapper::getPos,
+ "setPos", &ModelBaseWrapper::setPos,
+
+ "getScale", &ModelBaseWrapper::getScale,
+ "setScale", &ModelBaseWrapper::setScale,
+
+ "getAngle", &ModelBaseWrapper::getAngle,
+ "setAngle", &ModelBaseWrapper::setAngle,
+ "setEulerAngle", &ModelBaseWrapper::setEulerAngle,
+
+ "getMatrix", &ModelBaseWrapper::getMatrix,
+ "isDynamic", &ModelBaseWrapper::isDynamic,
+ "isUploaded", &ModelBaseWrapper::isUploaded,
+ // --------------
+
+ "isValid", &ModelBaseWrapper::isValid);
+ }
+} // namespace rawrbox
diff --git a/render/src/scripting/wrappers/model/mesh_wrapper.cpp b/render/src/scripting/wrappers/model/mesh_wrapper.cpp
new file mode 100644
index 00000000..f3be2396
--- /dev/null
+++ b/render/src/scripting/wrappers/model/mesh_wrapper.cpp
@@ -0,0 +1,67 @@
+
+#include
+#include
+
+namespace rawrbox {
+ void MeshWrapper::registerLua(sol::state& lua) {
+ lua.new_usertype("Mesh",
+ sol::constructors(),
+
+ "getName", &Mesh::getName,
+ "setName", &Mesh::setName,
+
+ // "getVertices", &Mesh::getVertices,
+ "getIndices", &Mesh::getIndices,
+ "getBBOX", &Mesh::getBBOX,
+
+ "empty", &Mesh::empty,
+
+ "getMatrix", &Mesh::getMatrix,
+
+ "getPos", &Mesh::getPos,
+ "setPos", &Mesh::setPos,
+
+ "getAngle", &Mesh::getAngle,
+ "setAngle", &Mesh::setAngle,
+ "setEulerAngle", &Mesh::setEulerAngle,
+
+ "getScale", &Mesh::getScale,
+ "setScale", &Mesh::setScale,
+
+ /* "getTexture", &Mesh::getTexture,
+ "setTexture", &Mesh::setTexture,*/
+
+ "getAtlasID", &Mesh::getAtlasID,
+ "setAtlasID", &Mesh::setAtlasID,
+
+ /*"getNormalTexture", &Mesh::getNormalTexture,
+ "setNormalTexture", &Mesh::setNormalTexture,
+ "getDisplacementTexture", &Mesh::getDisplacementTexture,
+ "setDisplacementTexture", &Mesh::setDisplacementTexture,
+ "getEmissionTexture", &Mesh::getEmissionTexture,
+ "setEmissionTexture", &Mesh::setEmissionTexture,
+ "getSpecularTexture", &Mesh::getSpecularTexture,
+ "setSpecularTexture", &Mesh::setSpecularTexture,*/
+
+ "setVertexSnap", &Mesh::setVertexSnap,
+ "setWireframe", &Mesh::setWireframe,
+ "setCulling", &Mesh::setCulling,
+ "setDepthTest", &Mesh::setDepthTest,
+ "setBlend", &Mesh::setBlend,
+ "setRecieveDecals", &Mesh::setRecieveDecals,
+ "setColor", &Mesh::setColor,
+
+ "addData", &Mesh::addData,
+ "getData", &Mesh::getData,
+ "hasData", &Mesh::hasData,
+
+ //"getSkeleton", &Mesh::getSkeleton,
+
+ "clear", &Mesh::clear,
+
+ "merge", &Mesh::merge,
+
+ "setOptimizable", &Mesh::setOptimizable,
+ "canOptimize", &Mesh::canOptimize);
+ }
+} // namespace rawrbox
diff --git a/render/src/scripting/wrappers/model/model_wrapper.cpp b/render/src/scripting/wrappers/model/model_wrapper.cpp
new file mode 100644
index 00000000..5273578c
--- /dev/null
+++ b/render/src/scripting/wrappers/model/model_wrapper.cpp
@@ -0,0 +1,137 @@
+
+#include
+#include
+
+namespace rawrbox {
+ ModelWrapper::ModelWrapper(const std::shared_ptr>& ref) : rawrbox::ModelBaseWrapper(ref) {}
+
+ // ANIMS ---
+ void ModelWrapper::playAnimation(const std::string& name, sol::optional loop, sol::optional speed) {
+ if (!this->isValid()) return;
+ std::weak_ptr> ptr = std::dynamic_pointer_cast>(this->_ref.lock());
+ ptr.lock()->playAnimation(name, loop.value_or(true), speed.value_or(1.F));
+ }
+
+ void ModelWrapper::stopAnimation(const std::string& name) {
+ if (!this->isValid()) return;
+ std::weak_ptr> ptr = std::dynamic_pointer_cast>(this->_ref.lock());
+ ptr.lock()->stopAnimation(name);
+ }
+ // ---
+
+ // UTILS ----
+ void ModelWrapper::setOptimizable(bool optimize) {
+ if (!this->isValid()) return;
+ std::weak_ptr> ptr = std::dynamic_pointer_cast>(this->_ref.lock());
+ ptr.lock()->setOptimizable(optimize);
+ }
+
+ void ModelWrapper::optimize() {
+ if (!this->isValid()) return;
+ std::weak_ptr> ptr = std::dynamic_pointer_cast>(this->_ref.lock());
+ ptr.lock()->optimize();
+ }
+
+ void ModelWrapper::setPos(const rawrbox::Vector3f& pos) {
+ if (!this->isValid()) return;
+ std::weak_ptr> ptr = std::dynamic_pointer_cast>(this->_ref.lock());
+ ptr.lock()->setPos(pos);
+ }
+
+ void ModelWrapper::setAngle(const rawrbox::Vector4f& angle) {
+ if (!this->isValid()) return;
+ std::weak_ptr> ptr = std::dynamic_pointer_cast>(this->_ref.lock());
+ ptr.lock()->setAngle(angle);
+ }
+
+ void ModelWrapper::setEulerAngle(const rawrbox::Vector3f& angle) {
+ if (!this->isValid()) return;
+ std::weak_ptr> ptr = std::dynamic_pointer_cast>(this->_ref.lock());
+ ptr.lock()->setEulerAngle(angle);
+ }
+
+ void ModelWrapper::setScale(const rawrbox::Vector3f& size) {
+ if (!this->isValid()) return;
+ std::weak_ptr> ptr = std::dynamic_pointer_cast>(this->_ref.lock());
+ ptr.lock()->setScale(size);
+ }
+
+ const rawrbox::BBOX ModelWrapper::getBBOX() const {
+ if (!this->isValid()) return {};
+ std::weak_ptr> ptr = std::dynamic_pointer_cast>(this->_ref.lock());
+ return ptr.lock()->getBBOX();
+ }
+
+ size_t ModelWrapper::totalMeshes() const {
+ if (!this->isValid()) return 0;
+ std::weak_ptr> ptr = std::dynamic_pointer_cast>(this->_ref.lock());
+ return ptr.lock()->totalMeshes();
+ }
+
+ bool ModelWrapper::empty() const {
+ if (!this->isValid()) return true;
+ std::weak_ptr> ptr = std::dynamic_pointer_cast>(this->_ref.lock());
+ return ptr.lock()->empty();
+ }
+
+ void ModelWrapper::removeMeshByName(const std::string& id) {
+ if (!this->isValid()) return;
+ std::weak_ptr> ptr = std::dynamic_pointer_cast>(this->_ref.lock());
+ return ptr.lock()->removeMeshByName(id);
+ }
+
+ void ModelWrapper::removeMesh(size_t index) {
+ if (!this->isValid()) return;
+ std::weak_ptr> ptr = std::dynamic_pointer_cast>(this->_ref.lock());
+ return ptr.lock()->removeMesh(index);
+ }
+
+ rawrbox::Mesh* ModelWrapper::getMeshByName(const std::string& id) {
+ if (!this->isValid()) return nullptr;
+
+ std::weak_ptr> ptr = std::dynamic_pointer_cast>(this->_ref.lock());
+ auto mesh = ptr.lock()->getMeshByName(id);
+ if (mesh == nullptr) return nullptr;
+
+ return mesh;
+ }
+
+ rawrbox::Mesh* ModelWrapper::getMesh(sol::optional id) {
+ if (!this->isValid()) return nullptr;
+
+ std::weak_ptr> ptr = std::dynamic_pointer_cast>(this->_ref.lock());
+ auto mesh = ptr.lock()->getMesh(id.value_or(0));
+ if (mesh == nullptr) return nullptr;
+
+ return mesh;
+ }
+ // ------
+
+ void ModelWrapper::registerLua(sol::state& lua) {
+ lua.new_usertype("Model<>",
+ sol::no_constructor,
+
+ // UTILS ----
+ "setOptimizable", &ModelWrapper::setOptimizable,
+ "optimize", &ModelWrapper::optimize,
+
+ "getBBOX", &ModelWrapper::getBBOX,
+
+ "totalMeshes", &ModelWrapper::totalMeshes,
+ "empty", &ModelWrapper::empty,
+
+ "removeMeshByName", &ModelWrapper::removeMeshByName,
+ "removeMesh", &ModelWrapper::removeMesh,
+ // ----
+
+ "getMeshByName", &ModelWrapper::getMeshByName,
+ "getMesh", &ModelWrapper::getMesh,
+
+ // ANIMS ---
+ "playAnimation", &ModelWrapper::playAnimation,
+ "stopAnimation", &ModelWrapper::stopAnimation,
+ // ----
+
+ sol::base_classes, sol::bases());
+ }
+} // namespace rawrbox
diff --git a/render/src/scripting/wrappers/resources/font_loader_wrapper.cpp b/render/src/scripting/wrappers/resources/font_loader_wrapper.cpp
new file mode 100644
index 00000000..971cac39
--- /dev/null
+++ b/render/src/scripting/wrappers/resources/font_loader_wrapper.cpp
@@ -0,0 +1,35 @@
+
+#include
+#include
+#include
+#include
+
+namespace rawrbox {
+ FontLoaderWrapper::FontLoaderWrapper(rawrbox::Mod* mod) : _mod(mod) {}
+
+ rawrbox::FontWrapper FontLoaderWrapper::get(const std::string& path, sol::optional size) {
+ if (this->_mod == nullptr) throw std::runtime_error("[RawrBox-FontLoader] MOD not set!");
+ auto fixedPath = rawrbox::LuaUtils::getContent(path, this->_mod->getFolder().generic_string());
+
+ if (!rawrbox::RESOURCES::isLoaded(fixedPath)) {
+ fmt::print("[Resources] Loading '{}' RUNTIME! You should load content on the 'MOD:onLoad' stage instead!", fixedPath);
+
+ auto ptr = rawrbox::RESOURCES::loadFile(fixedPath, 0);
+ if (ptr == nullptr) throw std::runtime_error(fmt::format("[Resources] '{}' not found!", fixedPath));
+
+ return {ptr->getSize(size.value_or(12))};
+ } else {
+ auto ptr = rawrbox::RESOURCES::getFile(fixedPath);
+ if (ptr == nullptr) throw std::runtime_error(fmt::format("[Resources] '{}' not found!", fixedPath));
+
+ return {ptr->getSize(size.value_or(12))};
+ }
+ }
+
+ void FontLoaderWrapper::registerLua(sol::state& lua) {
+ lua.new_usertype("fontLoader",
+ sol::no_constructor,
+ "get", &FontLoaderWrapper::get);
+ }
+
+} // namespace rawrbox
diff --git a/render/src/scripting/wrappers/resources/texture_loader_wrapper.cpp b/render/src/scripting/wrappers/resources/texture_loader_wrapper.cpp
new file mode 100644
index 00000000..531bc062
--- /dev/null
+++ b/render/src/scripting/wrappers/resources/texture_loader_wrapper.cpp
@@ -0,0 +1,35 @@
+
+#include