diff --git a/WickedEngine/wiApplication.cpp b/WickedEngine/wiApplication.cpp index f50e9672f..e4b3d5101 100644 --- a/WickedEngine/wiApplication.cpp +++ b/WickedEngine/wiApplication.cpp @@ -25,8 +25,12 @@ #include #include +//#define WICKED_ENGINE_HEAP_ALLOCATION_COUNTER + +#ifdef WICKED_ENGINE_HEAP_ALLOCATION_COUNTER static std::atomic number_of_heap_allocations{ 0 }; static std::atomic size_of_heap_allocations{ 0 }; +#endif // WICKED_ENGINE_HEAP_ALLOCATION_COUNTER using namespace wi::graphics; @@ -113,7 +117,7 @@ namespace wi graphicsDevice->SubmitCommandLists(); } } - #endif + #endif // WICKEDENGINE_BUILD_DX12 static bool startup_script = false; if (!startup_script) @@ -391,12 +395,16 @@ namespace wi if (infoDisplay.heap_allocation_counter) { infodisplay_str += "Heap allocations per frame: "; +#ifdef WICKED_ENGINE_HEAP_ALLOCATION_COUNTER infodisplay_str += std::to_string(number_of_heap_allocations.load()); infodisplay_str += " ("; infodisplay_str += std::to_string(size_of_heap_allocations.load()); infodisplay_str += " bytes)\n"; number_of_heap_allocations.store(0); size_of_heap_allocations.store(0); +#else + infodisplay_str += "[disabled]\n"; +#endif // WICKED_ENGINE_HEAP_ALLOCATION_COUNTER } if (infoDisplay.pipeline_count) { @@ -592,6 +600,7 @@ namespace wi } +#ifdef WICKED_ENGINE_HEAP_ALLOCATION_COUNTER // Heap alloc replacements are used to count heap allocations: // It is good practice to reduce the amount of heap allocations that happen during the frame, // so keep an eye on the info display of the engine while Application::InfoDisplayer::heap_allocation_counter is enabled @@ -624,3 +633,4 @@ void operator delete(void* ptr) throw() { free(ptr); } void operator delete (void* ptr, const std::nothrow_t&) throw() { free(ptr); } void operator delete[](void* ptr) throw() { free(ptr); } void operator delete[](void* ptr, const std::nothrow_t&) throw() { free(ptr); } +#endif // WICKED_ENGINE_HEAP_ALLOCATION_COUNTER diff --git a/WickedEngine/wiAudio_BindLua.cpp b/WickedEngine/wiAudio_BindLua.cpp index 1c241c1f7..d93399f20 100644 --- a/WickedEngine/wiAudio_BindLua.cpp +++ b/WickedEngine/wiAudio_BindLua.cpp @@ -371,7 +371,7 @@ namespace wi::lua Vector_BindLua* vec = Luna::lightcheck(L, 1); if (vec != nullptr) { - XMStoreFloat3(&soundinstance3D.listenerPos, XMLoadFloat4(vec)); + XMStoreFloat3(&soundinstance3D.listenerPos, XMLoadFloat4(&vec->data)); } } else @@ -386,7 +386,7 @@ namespace wi::lua Vector_BindLua* vec = Luna::lightcheck(L, 1); if (vec != nullptr) { - XMStoreFloat3(&soundinstance3D.listenerUp, XMLoadFloat4(vec)); + XMStoreFloat3(&soundinstance3D.listenerUp, XMLoadFloat4(&vec->data)); } } else @@ -401,7 +401,7 @@ namespace wi::lua Vector_BindLua* vec = Luna::lightcheck(L, 1); if (vec != nullptr) { - XMStoreFloat3(&soundinstance3D.listenerFront, XMLoadFloat4(vec)); + XMStoreFloat3(&soundinstance3D.listenerFront, XMLoadFloat4(&vec->data)); } } else @@ -416,7 +416,7 @@ namespace wi::lua Vector_BindLua* vec = Luna::lightcheck(L, 1); if (vec != nullptr) { - XMStoreFloat3(&soundinstance3D.listenerVelocity, XMLoadFloat4(vec)); + XMStoreFloat3(&soundinstance3D.listenerVelocity, XMLoadFloat4(&vec->data)); } } else @@ -432,7 +432,7 @@ namespace wi::lua Vector_BindLua* vec = Luna::lightcheck(L, 1); if (vec != nullptr) { - XMStoreFloat3(&soundinstance3D.emitterPos, XMLoadFloat4(vec)); + XMStoreFloat3(&soundinstance3D.emitterPos, XMLoadFloat4(&vec->data)); } } else @@ -447,7 +447,7 @@ namespace wi::lua Vector_BindLua* vec = Luna::lightcheck(L, 1); if (vec != nullptr) { - XMStoreFloat3(&soundinstance3D.emitterUp, XMLoadFloat4(vec)); + XMStoreFloat3(&soundinstance3D.emitterUp, XMLoadFloat4(&vec->data)); } } else @@ -462,7 +462,7 @@ namespace wi::lua Vector_BindLua* vec = Luna::lightcheck(L, 1); if (vec != nullptr) { - XMStoreFloat3(&soundinstance3D.emitterFront, XMLoadFloat4(vec)); + XMStoreFloat3(&soundinstance3D.emitterFront, XMLoadFloat4(&vec->data)); } } else @@ -477,7 +477,7 @@ namespace wi::lua Vector_BindLua* vec = Luna::lightcheck(L, 1); if (vec != nullptr) { - XMStoreFloat3(&soundinstance3D.emitterVelocity, XMLoadFloat4(vec)); + XMStoreFloat3(&soundinstance3D.emitterVelocity, XMLoadFloat4(&vec->data)); } } else diff --git a/WickedEngine/wiCanvas.h b/WickedEngine/wiCanvas.h index 4c56e3764..b73fdd550 100644 --- a/WickedEngine/wiCanvas.h +++ b/WickedEngine/wiCanvas.h @@ -8,6 +8,8 @@ namespace wi // The canvas specifies a DPI-aware drawing area struct Canvas { + virtual ~Canvas() = default; + uint32_t width = 0; uint32_t height = 0; float dpi = 96; diff --git a/WickedEngine/wiConfig.h b/WickedEngine/wiConfig.h index 50565a0dc..103bd7316 100644 --- a/WickedEngine/wiConfig.h +++ b/WickedEngine/wiConfig.h @@ -10,6 +10,8 @@ namespace wi::config struct File; struct Section { + virtual ~Section() = default; + friend struct File; // Check whether the key exists: diff --git a/WickedEngine/wiECS.h b/WickedEngine/wiECS.h index 75306cf58..8c5bbcd41 100644 --- a/WickedEngine/wiECS.h +++ b/WickedEngine/wiECS.h @@ -94,6 +94,7 @@ namespace wi::ecs class ComponentManager_Interface { public: + virtual ~ComponentManager_Interface() = default; virtual void Copy(const ComponentManager_Interface& other) = 0; virtual void Merge(ComponentManager_Interface& other) = 0; virtual void Clear() = 0; diff --git a/WickedEngine/wiGraphics.h b/WickedEngine/wiGraphics.h index a0668c24f..f8faf6888 100644 --- a/WickedEngine/wiGraphics.h +++ b/WickedEngine/wiGraphics.h @@ -683,6 +683,8 @@ namespace wi::graphics { std::shared_ptr internal_state; inline bool IsValid() const { return internal_state.get() != nullptr; } + + virtual ~GraphicsDeviceChild() = default; }; struct Sampler : public GraphicsDeviceChild diff --git a/WickedEngine/wiImageParams_BindLua.cpp b/WickedEngine/wiImageParams_BindLua.cpp index aa6691ab0..b291e25da 100644 --- a/WickedEngine/wiImageParams_BindLua.cpp +++ b/WickedEngine/wiImageParams_BindLua.cpp @@ -156,7 +156,7 @@ namespace wi::lua Vector_BindLua* vector = Luna::lightcheck(L, 1); if (vector != nullptr) { - XMStoreFloat3(¶ms.pos, XMLoadFloat4(vector)); + XMStoreFloat3(¶ms.pos, XMLoadFloat4(&vector->data)); } } else @@ -173,7 +173,7 @@ namespace wi::lua Vector_BindLua* vector = Luna::lightcheck(L, 1); if (vector != nullptr) { - XMStoreFloat2(¶ms.siz, XMLoadFloat4(vector)); + XMStoreFloat2(¶ms.siz, XMLoadFloat4(&vector->data)); } } else @@ -190,7 +190,7 @@ namespace wi::lua Vector_BindLua* vector = Luna::lightcheck(L, 1); if (vector != nullptr) { - XMStoreFloat2(¶ms.pivot, XMLoadFloat4(vector)); + XMStoreFloat2(¶ms.pivot, XMLoadFloat4(&vector->data)); } } else @@ -207,7 +207,7 @@ namespace wi::lua Vector_BindLua* param = Luna::lightcheck(L, 1); if (param != nullptr) { - XMStoreFloat4(¶ms.color, XMLoadFloat4(param)); + XMStoreFloat4(¶ms.color, XMLoadFloat4(¶m->data)); } } else @@ -329,7 +329,7 @@ namespace wi::lua Vector_BindLua* vector = Luna::lightcheck(L, 1); if (vector != nullptr) { - XMStoreFloat2(¶ms.texOffset, XMLoadFloat4(vector)); + XMStoreFloat2(¶ms.texOffset, XMLoadFloat4(&vector->data)); } } else @@ -346,7 +346,7 @@ namespace wi::lua Vector_BindLua* vector = Luna::lightcheck(L, 1); if (vector != nullptr) { - XMStoreFloat2(¶ms.texOffset2, XMLoadFloat4(vector)); + XMStoreFloat2(¶ms.texOffset2, XMLoadFloat4(&vector->data)); } } else @@ -364,7 +364,7 @@ namespace wi::lua if (vector != nullptr) { XMFLOAT4 drawrect; - XMStoreFloat4(&drawrect, XMLoadFloat4(vector)); + XMStoreFloat4(&drawrect, XMLoadFloat4(&vector->data)); params.enableDrawRect(drawrect); } } @@ -383,7 +383,7 @@ namespace wi::lua if (vector != nullptr) { XMFLOAT4 drawrect2; - XMStoreFloat4(&drawrect2, XMLoadFloat4(vector)); + XMStoreFloat4(&drawrect2, XMLoadFloat4(&vector->data)); params.enableDrawRect2(drawrect2); } } diff --git a/WickedEngine/wiInitializer.cpp b/WickedEngine/wiInitializer.cpp index 690933464..a3bd34a61 100644 --- a/WickedEngine/wiInitializer.cpp +++ b/WickedEngine/wiInitializer.cpp @@ -7,9 +7,9 @@ namespace wi::initializer { - bool initializationStarted = false; - wi::jobsystem::context ctx; - wi::Timer timer; + static bool initializationStarted = false; + static wi::jobsystem::context ctx; + static wi::Timer timer; static std::atomic_bool systems[INITIALIZED_SYSTEM_COUNT]{}; void InitializeComponentsImmediate() diff --git a/WickedEngine/wiInput_BindLua.cpp b/WickedEngine/wiInput_BindLua.cpp index d94ebd7ac..1ab89a89c 100644 --- a/WickedEngine/wiInput_BindLua.cpp +++ b/WickedEngine/wiInput_BindLua.cpp @@ -101,7 +101,7 @@ namespace wi::lua Vector_BindLua* vec = Luna::lightcheck(L, 1); if (vec != nullptr) { - wi::input::SetPointer(*vec); + wi::input::SetPointer(vec->data); } else wi::lua::SError(L, "SetPointer(Vector props) argument is not a Vector!"); @@ -348,7 +348,7 @@ namespace wi::lua Vector_BindLua* vec = Luna::lightcheck(L, 1); if (vec != nullptr) { - feedback.led_color = wi::Color::fromFloat4(*vec); + feedback.led_color = wi::Color::fromFloat4(vec->data); } else { diff --git a/WickedEngine/wiLua.cpp b/WickedEngine/wiLua.cpp index 4fcf52d7d..2b07e3cad 100644 --- a/WickedEngine/wiLua.cpp +++ b/WickedEngine/wiLua.cpp @@ -145,6 +145,8 @@ namespace wi::lua RegisterFunc("dofile", Internal_DoFile); RunText(wiLua_Globals); + Vector_BindLua::Bind(); + Matrix_BindLua::Bind(); Application_BindLua::Bind(); Canvas_BindLua::Bind(); RenderPath_BindLua::Bind(); @@ -158,8 +160,6 @@ namespace wi::lua ImageParams_BindLua::Bind(); SpriteAnim_BindLua::Bind(); scene::Bind(); - Vector_BindLua::Bind(); - Matrix_BindLua::Bind(); Input_BindLua::Bind(); SpriteFont_BindLua::Bind(); backlog::Bind(); diff --git a/WickedEngine/wiLua.h b/WickedEngine/wiLua.h index 9bb484009..661763a37 100644 --- a/WickedEngine/wiLua.h +++ b/WickedEngine/wiLua.h @@ -124,17 +124,9 @@ namespace wi::lua //push null to lua stack void SSetNull(lua_State* L); - //get-setters template for custom types - class LuaProperty - { - public: - virtual int Get(lua_State*L) = 0; - virtual int Set(lua_State*L) = 0; - }; //get-setters for int type - class IntProperty final : public LuaProperty + struct IntProperty { - public: int *data = nullptr; IntProperty(){} IntProperty(int* data): data(data) {} @@ -142,9 +134,8 @@ namespace wi::lua int Set(lua_State* L); }; //get-setters for long type - class LongProperty final : public LuaProperty + struct LongProperty { - public: long* data = nullptr; LongProperty(){} LongProperty(long* data): data(data) {} @@ -152,9 +143,8 @@ namespace wi::lua int Set(lua_State* L); }; //get-setters for long long type - class LongLongProperty final : public LuaProperty + struct LongLongProperty { - public: long long* data = nullptr; LongLongProperty(){} LongLongProperty(long long* data): data(data) {} @@ -162,9 +152,8 @@ namespace wi::lua int Set(lua_State* L); }; //get-setters for int type - class FloatProperty final : public LuaProperty + struct FloatProperty { - public: float* data = nullptr; FloatProperty(){} FloatProperty(float* data): data(data) {} @@ -172,9 +161,8 @@ namespace wi::lua int Set(lua_State* L); }; //get-setters for double type - class DoubleProperty final : public LuaProperty + struct DoubleProperty { - public: double* data = nullptr; DoubleProperty(){} DoubleProperty(double* data): data(data) {} @@ -182,9 +170,8 @@ namespace wi::lua int Set(lua_State* L); }; //get-setters for string type - class StringProperty final : public LuaProperty + struct StringProperty { - public: std::string* data = nullptr; StringProperty(){} StringProperty(std::string* data): data(data) {} @@ -192,9 +179,8 @@ namespace wi::lua int Set(lua_State* L); }; //get-setters for bool type - class BoolProperty final : public LuaProperty + struct BoolProperty { - public: bool* data = nullptr; BoolProperty(){} BoolProperty(bool* data): data(data) {} diff --git a/WickedEngine/wiMath_BindLua.cpp b/WickedEngine/wiMath_BindLua.cpp index 3ce8e018b..753ad37e9 100644 --- a/WickedEngine/wiMath_BindLua.cpp +++ b/WickedEngine/wiMath_BindLua.cpp @@ -43,50 +43,50 @@ namespace wi::lua Vector_BindLua::Vector_BindLua() { - x = 0; - y = 0; - z = 0; - w = 0; + data.x = 0; + data.y = 0; + data.z = 0; + data.w = 0; } Vector_BindLua::Vector_BindLua(const XMFLOAT3& vector) { - x = vector.x; - y = vector.y; - z = vector.z; - w = 1; + data.x = vector.x; + data.y = vector.y; + data.z = vector.z; + data.w = 1; } Vector_BindLua::Vector_BindLua(const XMFLOAT4& vector) { - x = vector.x; - y = vector.y; - z = vector.z; - w = vector.w; + data.x = vector.x; + data.y = vector.y; + data.z = vector.z; + data.w = vector.w; } Vector_BindLua::Vector_BindLua(const XMVECTOR& vector) { - XMStoreFloat4(this, vector); + XMStoreFloat4(&data, vector); } Vector_BindLua::Vector_BindLua(lua_State* L) { - x = 0; - y = 0; - z = 0; - w = 0; + data.x = 0; + data.y = 0; + data.z = 0; + data.w = 0; int argc = wi::lua::SGetArgCount(L); if (argc > 0) { - x = wi::lua::SGetFloat(L, 1); + data.x = wi::lua::SGetFloat(L, 1); if (argc > 1) { - y = wi::lua::SGetFloat(L, 2); + data.y = wi::lua::SGetFloat(L, 2); if (argc > 2) { - z = wi::lua::SGetFloat(L, 3); + data.z = wi::lua::SGetFloat(L, 3); if (argc > 3) { - w = wi::lua::SGetFloat(L, 4); + data.w = wi::lua::SGetFloat(L, 4); } } } @@ -97,22 +97,22 @@ namespace wi::lua int Vector_BindLua::GetX(lua_State* L) { - wi::lua::SSetFloat(L, x); + wi::lua::SSetFloat(L, data.x); return 1; } int Vector_BindLua::GetY(lua_State* L) { - wi::lua::SSetFloat(L, y); + wi::lua::SSetFloat(L, data.y); return 1; } int Vector_BindLua::GetZ(lua_State* L) { - wi::lua::SSetFloat(L, z); + wi::lua::SSetFloat(L, data.z); return 1; } int Vector_BindLua::GetW(lua_State* L) { - wi::lua::SSetFloat(L, w); + wi::lua::SSetFloat(L, data.w); return 1; } @@ -121,7 +121,7 @@ namespace wi::lua int argc = wi::lua::SGetArgCount(L); if (argc > 0) { - x = wi::lua::SGetFloat(L, 1); + data.x = wi::lua::SGetFloat(L, 1); } else wi::lua::SError(L, "SetX(float value) not enough arguments!"); @@ -132,7 +132,7 @@ namespace wi::lua int argc = wi::lua::SGetArgCount(L); if (argc > 0) { - y = wi::lua::SGetFloat(L, 1); + data.y = wi::lua::SGetFloat(L, 1); } else wi::lua::SError(L, "SetY(float value) not enough arguments!"); @@ -143,7 +143,7 @@ namespace wi::lua int argc = wi::lua::SGetArgCount(L); if (argc > 0) { - z = wi::lua::SGetFloat(L, 1); + data.z = wi::lua::SGetFloat(L, 1); } else wi::lua::SError(L, "SetZ(float value) not enough arguments!"); @@ -154,7 +154,7 @@ namespace wi::lua int argc = wi::lua::SGetArgCount(L); if (argc > 0) { - w = wi::lua::SGetFloat(L, 1); + data.w = wi::lua::SGetFloat(L, 1); } else wi::lua::SError(L, "SetW(float value) not enough arguments!"); @@ -170,7 +170,7 @@ namespace wi::lua Matrix_BindLua* mat = Luna::lightcheck(L, 2); if (vec && mat) { - Luna::push(L, new Vector_BindLua(XMVector4Transform(XMLoadFloat4(vec), XMLoadFloat4x4(mat)))); + Luna::push(L, new Vector_BindLua(XMVector4Transform(XMLoadFloat4(&vec->data), XMLoadFloat4x4(&mat->data)))); return 1; } else @@ -189,7 +189,7 @@ namespace wi::lua Matrix_BindLua* mat = Luna::lightcheck(L, 2); if (vec && mat) { - Luna::push(L, new Vector_BindLua(XMVector3TransformNormal(XMLoadFloat4(vec), XMLoadFloat4x4(mat)))); + Luna::push(L, new Vector_BindLua(XMVector3TransformNormal(XMLoadFloat4(&vec->data), XMLoadFloat4x4(&mat->data)))); return 1; } else @@ -208,7 +208,7 @@ namespace wi::lua Matrix_BindLua* mat = Luna::lightcheck(L, 2); if (vec && mat) { - Luna::push(L, new Vector_BindLua(XMVector3TransformCoord(XMLoadFloat4(vec), XMLoadFloat4x4(mat)))); + Luna::push(L, new Vector_BindLua(XMVector3TransformCoord(XMLoadFloat4(&vec->data), XMLoadFloat4x4(&mat->data)))); return 1; } else @@ -220,17 +220,17 @@ namespace wi::lua } int Vector_BindLua::Length(lua_State* L) { - wi::lua::SSetFloat(L, XMVectorGetX(XMVector3Length(XMLoadFloat4(this)))); + wi::lua::SSetFloat(L, XMVectorGetX(XMVector3Length(XMLoadFloat4(&data)))); return 1; } int Vector_BindLua::Normalize(lua_State* L) { - Luna::push(L, new Vector_BindLua(XMVector3Normalize(XMLoadFloat4(this)))); + Luna::push(L, new Vector_BindLua(XMVector3Normalize(XMLoadFloat4(&data)))); return 1; } int Vector_BindLua::QuaternionNormalize(lua_State* L) { - Luna::push(L, new Vector_BindLua(XMQuaternionNormalize(XMLoadFloat4(this)))); + Luna::push(L, new Vector_BindLua(XMQuaternionNormalize(XMLoadFloat4(&data)))); return 1; } int Vector_BindLua::Clamp(lua_State* L) @@ -240,7 +240,7 @@ namespace wi::lua { float a = wi::lua::SGetFloat(L, 1); float b = wi::lua::SGetFloat(L, 2); - Luna::push(L, new Vector_BindLua(XMVectorClamp(XMLoadFloat4(this), XMVectorSet(a, a, a, a), XMVectorSet(b, b, b, b)))); + Luna::push(L, new Vector_BindLua(XMVectorClamp(XMLoadFloat4(&data), XMVectorReplicate(a), XMVectorReplicate(b)))); return 1; } else @@ -249,7 +249,7 @@ namespace wi::lua } int Vector_BindLua::Saturate(lua_State* L) { - Luna::push(L, new Vector_BindLua(XMVectorSaturate(XMLoadFloat4(this)))); + Luna::push(L, new Vector_BindLua(XMVectorSaturate(XMLoadFloat4(&data)))); return 1; } @@ -264,7 +264,7 @@ namespace wi::lua Vector_BindLua* v2 = Luna::lightcheck(L, 2); if (v1 && v2) { - wi::lua::SSetFloat(L, XMVectorGetX(XMVector3Dot(XMLoadFloat4(v1), XMLoadFloat4(v2)))); + wi::lua::SSetFloat(L, XMVectorGetX(XMVector3Dot(XMLoadFloat4(&v1->data), XMLoadFloat4(&v2->data)))); return 1; } } @@ -280,7 +280,7 @@ namespace wi::lua Vector_BindLua* v2 = Luna::lightcheck(L, 2); if (v1 && v2) { - Luna::push(L, new Vector_BindLua(XMVector3Cross(XMLoadFloat4(v1), XMLoadFloat4(v2)))); + Luna::push(L, new Vector_BindLua(XMVector3Cross(XMLoadFloat4(&v1->data), XMLoadFloat4(&v2->data)))); return 1; } } @@ -296,17 +296,17 @@ namespace wi::lua Vector_BindLua* v2 = Luna::lightcheck(L, 2); if (v1 && v2) { - Luna::push(L, new Vector_BindLua(XMVectorMultiply(XMLoadFloat4(v1), XMLoadFloat4(v2)))); + Luna::push(L, new Vector_BindLua(XMVectorMultiply(XMLoadFloat4(&v1->data), XMLoadFloat4(&v2->data)))); return 1; } else if (v1) { - Luna::push(L, new Vector_BindLua(XMLoadFloat4(v1) * wi::lua::SGetFloat(L, 2))); + Luna::push(L, new Vector_BindLua(XMLoadFloat4(&v1->data) * wi::lua::SGetFloat(L, 2))); return 1; } else if (v2) { - Luna::push(L, new Vector_BindLua(wi::lua::SGetFloat(L, 1) * XMLoadFloat4(v2))); + Luna::push(L, new Vector_BindLua(wi::lua::SGetFloat(L, 1) * XMLoadFloat4(&v2->data))); return 1; } } @@ -322,7 +322,7 @@ namespace wi::lua Vector_BindLua* v2 = Luna::lightcheck(L, 2); if (v1 && v2) { - Luna::push(L, new Vector_BindLua(XMVectorAdd(XMLoadFloat4(v1), XMLoadFloat4(v2)))); + Luna::push(L, new Vector_BindLua(XMVectorAdd(XMLoadFloat4(&v1->data), XMLoadFloat4(&v2->data)))); return 1; } } @@ -338,7 +338,7 @@ namespace wi::lua Vector_BindLua* v2 = Luna::lightcheck(L, 2); if (v1 && v2) { - Luna::push(L, new Vector_BindLua(XMVectorSubtract(XMLoadFloat4(v1), XMLoadFloat4(v2)))); + Luna::push(L, new Vector_BindLua(XMVectorSubtract(XMLoadFloat4(&v1->data), XMLoadFloat4(&v2->data)))); return 1; } } @@ -355,7 +355,7 @@ namespace wi::lua float t = wi::lua::SGetFloat(L, 3); if (v1 && v2) { - Luna::push(L, new Vector_BindLua(XMVectorLerp(XMLoadFloat4(v1), XMLoadFloat4(v2), t))); + Luna::push(L, new Vector_BindLua(XMVectorLerp(XMLoadFloat4(&v1->data), XMLoadFloat4(&v2->data), t))); return 1; } } @@ -373,7 +373,7 @@ namespace wi::lua Vector_BindLua* v2 = Luna::lightcheck(L, 2); if (v1 && v2) { - Luna::push(L, new Vector_BindLua(XMQuaternionMultiply(XMLoadFloat4(v1), XMLoadFloat4(v2)))); + Luna::push(L, new Vector_BindLua(XMQuaternionMultiply(XMLoadFloat4(&v1->data), XMLoadFloat4(&v2->data)))); return 1; } } @@ -388,7 +388,7 @@ namespace wi::lua Vector_BindLua* v1 = Luna::lightcheck(L, 1); if (v1) { - Luna::push(L, new Vector_BindLua(XMQuaternionRotationRollPitchYawFromVector(XMLoadFloat4(v1)))); + Luna::push(L, new Vector_BindLua(XMQuaternionRotationRollPitchYawFromVector(XMLoadFloat4(&v1->data)))); return 1; } } @@ -403,7 +403,7 @@ namespace wi::lua Vector_BindLua* v1 = Luna::lightcheck(L, 1); if (v1) { - XMFLOAT3 xyz = wi::math::QuaternionToRollPitchYaw(*v1); + XMFLOAT3 xyz = wi::math::QuaternionToRollPitchYaw(v1->data); Luna::push(L, new Vector_BindLua(XMFLOAT4(xyz.x, xyz.y, xyz.z, 0))); return 1; } @@ -421,7 +421,7 @@ namespace wi::lua float t = wi::lua::SGetFloat(L, 3); if (v1 && v2) { - Luna::push(L, new Vector_BindLua(XMQuaternionSlerp(XMLoadFloat4(v1), XMLoadFloat4(v2), t))); + Luna::push(L, new Vector_BindLua(XMQuaternionSlerp(XMLoadFloat4(&v1->data), XMLoadFloat4(&v2->data), t))); return 1; } } @@ -458,10 +458,6 @@ namespace wi::lua { Luna::push(L, new Vector_BindLua(XMLoadFloat4(data_f4))); } - if(data_v) - { - Luna::push(L, new Vector_BindLua(*data_v)); - } return 1; } int VectorProperty::Set(lua_State* L) @@ -471,19 +467,15 @@ namespace wi::lua { if(data_f2) { - XMStoreFloat2(data_f2, XMLoadFloat4(get)); + XMStoreFloat2(data_f2, XMLoadFloat4(&get->data)); } if(data_f3) { - XMStoreFloat3(data_f3, XMLoadFloat4(get)); + XMStoreFloat3(data_f3, XMLoadFloat4(&get->data)); } if(data_f4) { - *data_f4 = *get; - } - if(data_v) - { - *data_v = XMLoadFloat4(get); + *data_f4 = get->data; } } return 0; @@ -519,15 +511,14 @@ namespace wi::lua Matrix_BindLua::Matrix_BindLua() { - std::memcpy(this, &wi::math::IDENTITY_MATRIX, sizeof(wi::math::IDENTITY_MATRIX)); } Matrix_BindLua::Matrix_BindLua(const XMFLOAT4X4& matrix) { - std::memcpy(this, &matrix, sizeof(matrix)); + data = matrix; } Matrix_BindLua::Matrix_BindLua(const XMMATRIX& matrix) { - XMStoreFloat4x4(this, matrix); + XMStoreFloat4x4(&data, matrix); } Matrix_BindLua::Matrix_BindLua(lua_State* L) { @@ -555,10 +546,10 @@ namespace wi::lua } } } - this->m[i][0] = x; - this->m[i][1] = x; - this->m[i][2] = x; - this->m[i][3] = x; + data.m[i][0] = x; + data.m[i][1] = x; + data.m[i][2] = x; + data.m[i][3] = x; } } @@ -573,7 +564,7 @@ namespace wi::lua if (row < 0 || row > 3) row = 0; } - XMFLOAT4 r = XMFLOAT4(m[row][0], m[row][1], m[row][2], m[row][3]); + XMFLOAT4 r = XMFLOAT4(data.m[row][0], data.m[row][1], data.m[row][2], data.m[row][3]); Luna::push(L, new Vector_BindLua(r)); return 1; } @@ -589,7 +580,7 @@ namespace wi::lua Vector_BindLua* vector = Luna::lightcheck(L, 1); if (vector != nullptr) { - mat = XMMatrixTranslationFromVector(XMLoadFloat4(vector)); + mat = XMMatrixTranslationFromVector(XMLoadFloat4(&vector->data)); } } Luna::push(L, new Matrix_BindLua(mat)); @@ -605,7 +596,7 @@ namespace wi::lua Vector_BindLua* vector = Luna::lightcheck(L, 1); if (vector != nullptr) { - mat = XMMatrixRotationRollPitchYawFromVector(XMLoadFloat4(vector)); + mat = XMMatrixRotationRollPitchYawFromVector(XMLoadFloat4(&vector->data)); } } Luna::push(L, new Matrix_BindLua(mat)); @@ -657,7 +648,7 @@ namespace wi::lua Vector_BindLua* vector = Luna::lightcheck(L, 1); if (vector != nullptr) { - mat = XMMatrixRotationQuaternion(XMLoadFloat4(vector)); + mat = XMMatrixRotationQuaternion(XMLoadFloat4(&vector->data)); } } Luna::push(L, new Matrix_BindLua(mat)); @@ -673,7 +664,7 @@ namespace wi::lua Vector_BindLua* vector = Luna::lightcheck(L, 1); if (vector != nullptr) { - mat = XMMatrixScalingFromVector(XMLoadFloat4(vector)); + mat = XMMatrixScalingFromVector(XMLoadFloat4(&vector->data)); } } Luna::push(L, new Matrix_BindLua(mat)); @@ -693,11 +684,11 @@ namespace wi::lua if (argc > 3) { Vector_BindLua* up = Luna::lightcheck(L, 3); - Up = XMLoadFloat4(up); + Up = XMLoadFloat4(&up->data); } else Up = XMVectorSet(0, 1, 0, 0); - Luna::push(L, new Matrix_BindLua(XMMatrixLookToLH(XMLoadFloat4(pos), XMLoadFloat4(dir), Up))); + Luna::push(L, new Matrix_BindLua(XMMatrixLookToLH(XMLoadFloat4(&pos->data), XMLoadFloat4(&dir->data), Up))); } else wi::lua::SError(L, "LookTo(Vector eye, Vector direction, opt Vector up) argument is not a Vector!"); @@ -720,11 +711,11 @@ namespace wi::lua if (argc > 3) { Vector_BindLua* up = Luna::lightcheck(L, 3); - Up = XMLoadFloat4(up); + Up = XMLoadFloat4(&up->data); } else Up = XMVectorSet(0, 1, 0, 0); - Luna::push(L, new Matrix_BindLua(XMMatrixLookAtLH(XMLoadFloat4(pos), XMLoadFloat4(dir), Up))); + Luna::push(L, new Matrix_BindLua(XMMatrixLookAtLH(XMLoadFloat4(&pos->data), XMLoadFloat4(&dir->data), Up))); } else wi::lua::SError(L, "LookAt(Vector eye, Vector focusPos, opt Vector up) argument is not a Vector!"); @@ -743,7 +734,7 @@ namespace wi::lua Matrix_BindLua* m2 = Luna::lightcheck(L, 2); if (m1 && m2) { - Luna::push(L, new Matrix_BindLua(XMMatrixMultiply(XMLoadFloat4x4(m1), XMLoadFloat4x4(m2)))); + Luna::push(L, new Matrix_BindLua(XMMatrixMultiply(XMLoadFloat4x4(&m1->data), XMLoadFloat4x4(&m2->data)))); return 1; } } @@ -759,7 +750,7 @@ namespace wi::lua Matrix_BindLua* m2 = Luna::lightcheck(L, 2); if (m1 && m2) { - Luna::push(L, new Matrix_BindLua(XMLoadFloat4x4(m1) + XMLoadFloat4x4(m2))); + Luna::push(L, new Matrix_BindLua(XMLoadFloat4x4(&m1->data) + XMLoadFloat4x4(&m2->data))); return 1; } } @@ -774,7 +765,7 @@ namespace wi::lua Matrix_BindLua* m1 = Luna::lightcheck(L, 1); if (m1) { - Luna::push(L, new Matrix_BindLua(XMMatrixTranspose(XMLoadFloat4x4(m1)))); + Luna::push(L, new Matrix_BindLua(XMMatrixTranspose(XMLoadFloat4x4(&m1->data)))); return 1; } } @@ -790,7 +781,7 @@ namespace wi::lua if (m1) { XMVECTOR det; - Luna::push(L, new Matrix_BindLua(XMMatrixInverse(&det, XMLoadFloat4x4(m1)))); + Luna::push(L, new Matrix_BindLua(XMMatrixInverse(&det, XMLoadFloat4x4(&m1->data)))); wi::lua::SSetFloat(L, XMVectorGetX(det)); return 2; } @@ -819,10 +810,6 @@ namespace wi::lua { Luna::push(L, new Matrix_BindLua(*data_f4x4)); } - if(data_m) - { - Luna::push(L, new Matrix_BindLua(*data_m)); - } return 1; } int MatrixProperty::Set(lua_State *L) @@ -832,11 +819,7 @@ namespace wi::lua { if(data_f4x4) { - *data_f4x4 = *get; - } - if(data_m) - { - *data_m = XMLoadFloat4x4(get); + *data_f4x4 = get->data; } } return 0; diff --git a/WickedEngine/wiMath_BindLua.h b/WickedEngine/wiMath_BindLua.h index b26da6732..863e97fdc 100644 --- a/WickedEngine/wiMath_BindLua.h +++ b/WickedEngine/wiMath_BindLua.h @@ -7,9 +7,10 @@ namespace wi::lua { - class Vector_BindLua : public XMFLOAT4 + class Vector_BindLua { public: + XMFLOAT4 data = {}; static const char className[]; static Luna::FunctionType methods[]; static Luna::PropertyType properties[]; @@ -54,14 +55,13 @@ namespace wi::lua static void Bind(); }; - class VectorProperty final : public LuaProperty + struct VectorProperty { public: VectorProperty(){} VectorProperty(XMFLOAT2* data): data_f2(data) {} VectorProperty(XMFLOAT3* data): data_f3(data) {} VectorProperty(XMFLOAT4* data): data_f4(data) {} - VectorProperty(XMVECTOR* data): data_v(data) {} int Get(lua_State*L); int Set(lua_State*L); @@ -69,12 +69,12 @@ namespace wi::lua XMFLOAT2* data_f2 = nullptr; XMFLOAT3* data_f3 = nullptr; XMFLOAT4* data_f4 = nullptr; - XMVECTOR* data_v = nullptr; }; - class Matrix_BindLua : public XMFLOAT4X4 + class Matrix_BindLua { public: + XMFLOAT4X4 data = wi::math::IDENTITY_MATRIX; static const char className[]; static Luna::FunctionType methods[]; static Luna::PropertyType properties[]; @@ -103,17 +103,15 @@ namespace wi::lua static void Bind(); }; - class MatrixProperty final : public LuaProperty + struct MatrixProperty { public: MatrixProperty(){} MatrixProperty(XMFLOAT4X4* data): data_f4x4(data) {} - MatrixProperty(XMMATRIX* data): data_m(data) {} int Get(lua_State*L); int Set(lua_State*L); private: - XMFLOAT4X4* data_f4x4; - XMMATRIX* data_m; + XMFLOAT4X4* data_f4x4 = nullptr; }; } diff --git a/WickedEngine/wiPrimitive_BindLua.cpp b/WickedEngine/wiPrimitive_BindLua.cpp index 205d0e113..82279da2a 100644 --- a/WickedEngine/wiPrimitive_BindLua.cpp +++ b/WickedEngine/wiPrimitive_BindLua.cpp @@ -49,7 +49,7 @@ namespace wi::lua::primitive Vector_BindLua* d = Luna::lightcheck(L, 2); if (o && d) { - ray = Ray(XMLoadFloat4(o), XMLoadFloat4(d)); + ray = Ray(XMLoadFloat4(&o->data), XMLoadFloat4(&d->data)); if (argc > 2) { ray.TMin = wi::lua::SGetFloat(L, 3); @@ -116,7 +116,7 @@ namespace wi::lua::primitive Vector_BindLua* v = Luna::lightcheck(L, 1); if (v != nullptr) { - XMStoreFloat3(&ray.origin, XMLoadFloat4(v)); + XMStoreFloat3(&ray.origin, XMLoadFloat4(&v->data)); } else { @@ -142,7 +142,7 @@ namespace wi::lua::primitive Vector_BindLua* v = Luna::lightcheck(L, 1); if (v != nullptr) { - XMStoreFloat3(&ray.direction, XMLoadFloat4(v)); + XMStoreFloat3(&ray.direction, XMLoadFloat4(&v->data)); } else { @@ -189,15 +189,15 @@ namespace wi::lua::primitive if (_minV && _maxV) { XMFLOAT3 _min, _max; - XMStoreFloat3(&_min, XMLoadFloat4(_minV)); - XMStoreFloat3(&_max, XMLoadFloat4(_maxV)); + XMStoreFloat3(&_min, XMLoadFloat4(&_minV->data)); + XMStoreFloat3(&_max, XMLoadFloat4(&_maxV->data)); aabb = AABB(_min, _max); } else if (_minV) { XMFLOAT3 _min; - XMStoreFloat3(&_min, XMLoadFloat4(_minV)); + XMStoreFloat3(&_min, XMLoadFloat4(&_minV->data)); aabb = AABB(_min); } @@ -278,7 +278,7 @@ namespace wi::lua::primitive Vector_BindLua* v = Luna::lightcheck(L, 1); if (v != nullptr) { - XMStoreFloat3(&aabb._min, XMLoadFloat4(v)); + XMStoreFloat3(&aabb._min, XMLoadFloat4(&v->data)); } else { @@ -305,7 +305,7 @@ namespace wi::lua::primitive Vector_BindLua* v = Luna::lightcheck(L, 1); if (v != nullptr) { - XMStoreFloat3(&aabb._max, XMLoadFloat4(v)); + XMStoreFloat3(&aabb._max, XMLoadFloat4(&v->data)); } else { @@ -338,7 +338,7 @@ namespace wi::lua::primitive Matrix_BindLua* _matrix = Luna::lightcheck(L, 1); if (_matrix) { - Luna::push(L, new AABB_BindLua(aabb.transform(*_matrix))); + Luna::push(L, new AABB_BindLua(aabb.transform(_matrix->data))); return 1; } else @@ -382,7 +382,7 @@ namespace wi::lua::primitive if (cV) { XMFLOAT3 c; - XMStoreFloat3(&c, XMLoadFloat4(cV)); + XMStoreFloat3(&c, XMLoadFloat4(&cV->data)); float r = wi::lua::SGetFloat(L, 2); @@ -450,7 +450,7 @@ namespace wi::lua::primitive Vector_BindLua* cV = Luna::lightcheck(L, 1); if (cV) { - XMStoreFloat3(&sphere.center, XMLoadFloat4(cV)); + XMStoreFloat3(&sphere.center, XMLoadFloat4(&cV->data)); } else { @@ -509,9 +509,9 @@ namespace wi::lua::primitive if (bV && tV) { XMFLOAT3 b; - XMStoreFloat3(&b, XMLoadFloat4(bV)); + XMStoreFloat3(&b, XMLoadFloat4(&bV->data)); XMFLOAT3 t; - XMStoreFloat3(&t, XMLoadFloat4(tV)); + XMStoreFloat3(&t, XMLoadFloat4(&tV->data)); float r = wi::lua::SGetFloat(L, 3); @@ -585,7 +585,7 @@ namespace wi::lua::primitive Vector_BindLua* cV = Luna::lightcheck(L, 1); if (cV) { - XMStoreFloat3(&capsule.base, XMLoadFloat4(cV)); + XMStoreFloat3(&capsule.base, XMLoadFloat4(&cV->data)); } else { @@ -606,7 +606,7 @@ namespace wi::lua::primitive Vector_BindLua* cV = Luna::lightcheck(L, 1); if (cV) { - XMStoreFloat3(&capsule.tip, XMLoadFloat4(cV)); + XMStoreFloat3(&capsule.tip, XMLoadFloat4(&cV->data)); } else { diff --git a/WickedEngine/wiRenderPath2D_BindLua.h b/WickedEngine/wiRenderPath2D_BindLua.h index 9e461478e..306f1e2a2 100644 --- a/WickedEngine/wiRenderPath2D_BindLua.h +++ b/WickedEngine/wiRenderPath2D_BindLua.h @@ -26,6 +26,7 @@ namespace wi::lua { this->component = &renderpath; } + virtual ~RenderPath2D_BindLua() = default; int AddSprite(lua_State* L); int AddFont(lua_State* L); diff --git a/WickedEngine/wiRenderer_BindLua.cpp b/WickedEngine/wiRenderer_BindLua.cpp index b663edf26..f18a07969 100644 --- a/WickedEngine/wiRenderer_BindLua.cpp +++ b/WickedEngine/wiRenderer_BindLua.cpp @@ -164,15 +164,15 @@ namespace wi::lua::renderer if (a && b) { wi::renderer::RenderableLine line; - XMStoreFloat3(&line.start, XMLoadFloat4(a)); - XMStoreFloat3(&line.end, XMLoadFloat4(b)); + XMStoreFloat3(&line.start, XMLoadFloat4(&a->data)); + XMStoreFloat3(&line.end, XMLoadFloat4(&b->data)); if (argc > 2) { Vector_BindLua* c = Luna::lightcheck(L, 3); if (c) { - XMStoreFloat4(&line.color_start, XMLoadFloat4(c)); - XMStoreFloat4(&line.color_end, XMLoadFloat4(c)); + XMStoreFloat4(&line.color_start, XMLoadFloat4(&c->data)); + XMStoreFloat4(&line.color_end, XMLoadFloat4(&c->data)); } else wi::lua::SError(L, "DrawLine(Vector origin,end, opt Vector color) one or more arguments are not vectors!"); @@ -196,7 +196,7 @@ namespace wi::lua::renderer if (a) { wi::renderer::RenderablePoint point; - XMStoreFloat3(&point.position, XMLoadFloat4(a)); + XMStoreFloat3(&point.position, XMLoadFloat4(&a->data)); if (argc > 1) { point.size = wi::lua::SGetFloat(L, 2); @@ -204,7 +204,10 @@ namespace wi::lua::renderer if (argc > 2) { Vector_BindLua* color = Luna::lightcheck(L, 3); - point.color = *color; + if (color) + { + point.color = color->data; + } } } wi::renderer::DrawPoint(point); @@ -230,12 +233,12 @@ namespace wi::lua::renderer Vector_BindLua* color = Luna::lightcheck(L, 2); if (color) { - wi::renderer::DrawBox(*m, *color); + wi::renderer::DrawBox(m->data, color->data); return 0; } } - wi::renderer::DrawBox(*m); + wi::renderer::DrawBox(m->data); } else wi::lua::SError(L, "DrawBox(Matrix boxMatrix, opt Vector color) first argument must be a Matrix type!"); @@ -258,7 +261,7 @@ namespace wi::lua::renderer Vector_BindLua* color = Luna::lightcheck(L, 2); if (color) { - wi::renderer::DrawSphere(sphere->sphere, *color); + wi::renderer::DrawSphere(sphere->sphere, color->data); return 0; } } @@ -286,7 +289,7 @@ namespace wi::lua::renderer Vector_BindLua* color = Luna::lightcheck(L, 2); if (color) { - wi::renderer::DrawCapsule(capsule->capsule, *color); + wi::renderer::DrawCapsule(capsule->capsule, color->data); return 0; } } @@ -313,16 +316,16 @@ namespace wi::lua::renderer Vector_BindLua* position = Luna::lightcheck(L, 2); if (position != nullptr) { - params.position.x = position->x; - params.position.y = position->y; - params.position.z = position->z; + params.position.x = position->data.x; + params.position.y = position->data.y; + params.position.z = position->data.z; if (argc > 2) { Vector_BindLua* color = Luna::lightcheck(L, 3); if (color != nullptr) { - params.color = *color; + params.color = color->data; if (argc > 3) { @@ -359,7 +362,7 @@ namespace wi::lua::renderer if (v) { XMFLOAT3 pos; - XMStoreFloat3(&pos, XMLoadFloat4(v)); + XMStoreFloat3(&pos, XMLoadFloat4(&v->data)); GetGlobalScene()->PutWaterRipple(name, pos); } else diff --git a/WickedEngine/wiScene_BindLua.cpp b/WickedEngine/wiScene_BindLua.cpp index 52e17c1aa..89cc6e978 100644 --- a/WickedEngine/wiScene_BindLua.cpp +++ b/WickedEngine/wiScene_BindLua.cpp @@ -72,7 +72,7 @@ int LoadModel(lua_State* L) Matrix_BindLua* matrix = Luna::lightcheck(L, 3); if (matrix != nullptr) { - transform = XMLoadFloat4x4(matrix); + transform = XMLoadFloat4x4(&matrix->data); } else { @@ -99,7 +99,7 @@ int LoadModel(lua_State* L) Matrix_BindLua* matrix = Luna::lightcheck(L, 2); if (matrix != nullptr) { - transform = XMLoadFloat4x4(matrix); + transform = XMLoadFloat4x4(&matrix->data); } else { @@ -2260,19 +2260,6 @@ Luna::PropertyType NameComponent_BindLua::properties[] = { NULL, NULL } }; -NameComponent_BindLua::NameComponent_BindLua(lua_State *L) -{ - owning = true; - component = new NameComponent; -} -NameComponent_BindLua::~NameComponent_BindLua() -{ - if (owning) - { - delete component; - } -} - int NameComponent_BindLua::SetName(lua_State* L) { int argc = wi::lua::SGetArgCount(L); @@ -2309,19 +2296,6 @@ Luna::PropertyType LayerComponent_BindLua::properties[] { NULL, NULL } }; -LayerComponent_BindLua::LayerComponent_BindLua(lua_State *L) -{ - owning = true; - component = new LayerComponent; -} -LayerComponent_BindLua::~LayerComponent_BindLua() -{ - if (owning) - { - delete component; - } -} - int LayerComponent_BindLua::SetLayerMask(lua_State* L) { int argc = wi::lua::SGetArgCount(L); @@ -2373,20 +2347,6 @@ Luna::PropertyType TransformComponent_BindLua::prope { NULL, NULL } }; -TransformComponent_BindLua::TransformComponent_BindLua(lua_State *L) -{ - owning = true; - component = new TransformComponent; - BuildBindings(); -} -TransformComponent_BindLua::~TransformComponent_BindLua() -{ - if (owning) - { - delete component; - } -} - int TransformComponent_BindLua::Scale(lua_State* L) { int argc = wi::lua::SGetArgCount(L); @@ -2396,7 +2356,7 @@ int TransformComponent_BindLua::Scale(lua_State* L) if (v != nullptr) { XMFLOAT3 value; - XMStoreFloat3(&value, XMLoadFloat4(v)); + XMStoreFloat3(&value, XMLoadFloat4(&v->data)); component->Scale(value); } @@ -2420,7 +2380,7 @@ int TransformComponent_BindLua::Rotate(lua_State* L) if (v != nullptr) { XMFLOAT3 rollPitchYaw; - XMStoreFloat3(&rollPitchYaw, XMLoadFloat4(v)); + XMStoreFloat3(&rollPitchYaw, XMLoadFloat4(&v->data)); component->RotateRollPitchYaw(rollPitchYaw); } @@ -2444,7 +2404,7 @@ int TransformComponent_BindLua::Translate(lua_State* L) if (v != nullptr) { XMFLOAT3 value; - XMStoreFloat3(&value, XMLoadFloat4(v)); + XMStoreFloat3(&value, XMLoadFloat4(&v->data)); component->Translate(value); } @@ -2549,7 +2509,7 @@ int TransformComponent_BindLua::MatrixTransform(lua_State* L) Matrix_BindLua* m = Luna::lightcheck(L, 1); if (m != nullptr) { - component->MatrixTransform(XMLoadFloat4x4(m)); + component->MatrixTransform(XMLoadFloat4x4(&m->data)); } else { @@ -2660,19 +2620,6 @@ Luna::PropertyType CameraComponent_BindLua::properties[ { NULL, NULL } }; -CameraComponent_BindLua::CameraComponent_BindLua(lua_State *L) -{ - owning = true; - component = new CameraComponent; -} -CameraComponent_BindLua::~CameraComponent_BindLua() -{ - if (owning) - { - delete component; - } -} - int CameraComponent_BindLua::UpdateCamera(lua_State* L) { component->UpdateCamera(); @@ -2803,7 +2750,7 @@ int CameraComponent_BindLua::SetApertureShape(lua_State* L) Vector_BindLua* param = Luna::lightcheck(L, 1); if (param != nullptr) { - XMStoreFloat2(&component->aperture_shape, XMLoadFloat4(param)); + XMStoreFloat2(&component->aperture_shape, XMLoadFloat4(¶m->data)); } } else @@ -2889,19 +2836,6 @@ Luna::PropertyType AnimationComponent_BindLua::prope { NULL, NULL } }; -AnimationComponent_BindLua::AnimationComponent_BindLua(lua_State *L) -{ - owning = true; - component = new AnimationComponent; -} -AnimationComponent_BindLua::~AnimationComponent_BindLua() -{ - if (owning) - { - delete component; - } -} - int AnimationComponent_BindLua::Play(lua_State* L) { component->Play(); @@ -3043,20 +2977,6 @@ Luna::PropertyType MaterialComponent_BindLua::propert { NULL, NULL } }; -MaterialComponent_BindLua::MaterialComponent_BindLua(lua_State *L) -{ - owning = true; - component = new MaterialComponent; - BuildBindings(); -} -MaterialComponent_BindLua::~MaterialComponent_BindLua() -{ - if (owning) - { - delete component; - } -} - int MaterialComponent_BindLua::GetBaseColor(lua_State* L) { Luna::push(L, new Vector_BindLua(component->baseColor)); @@ -3071,7 +2991,7 @@ int MaterialComponent_BindLua::SetBaseColor(lua_State* L) if (_color) { XMFLOAT4 color; - XMStoreFloat4(&color, XMLoadFloat4(_color)); + XMStoreFloat4(&color, XMLoadFloat4(&_color->data)); component->SetBaseColor(color); } else @@ -3100,7 +3020,7 @@ int MaterialComponent_BindLua::SetEmissiveColor(lua_State* L) if (_color) { XMFLOAT4 color; - XMStoreFloat4(&color, XMLoadFloat4(_color)); + XMStoreFloat4(&color, XMLoadFloat4(&_color->data)); component->SetEmissiveColor(color); } else @@ -3285,20 +3205,6 @@ Luna::PropertyType MeshComponent_BindLua::properties[] = { NULL, NULL } }; -MeshComponent_BindLua::MeshComponent_BindLua(lua_State *L) -{ - owning = true; - component = new MeshComponent; - BuildBindings(); -} -MeshComponent_BindLua::~MeshComponent_BindLua() -{ - if (owning) - { - delete component; - } -} - int MeshComponent_BindLua::SetMeshSubsetMaterialID(lua_State* L) { int argc = wi::lua::SGetArgCount(L); @@ -3408,20 +3314,6 @@ Luna::PropertyType EmitterComponent_BindLua::propertie { NULL, NULL } }; -EmitterComponent_BindLua::EmitterComponent_BindLua(lua_State *L) -{ - owning = true; - component = new wi::EmittedParticleSystem; - BuildBindings(); -} -EmitterComponent_BindLua::~EmitterComponent_BindLua() -{ - if (owning) - { - delete component; - } -} - int EmitterComponent_BindLua::Burst(lua_State* L) { int argc = wi::lua::SGetArgCount(L); @@ -3659,20 +3551,6 @@ Luna::PropertyType HairParticleSystem_BindLua::prope { NULL, NULL } }; -HairParticleSystem_BindLua::HairParticleSystem_BindLua(lua_State *L) -{ - owning = true; - component = new wi::HairParticleSystem; - BuildBindings(); -} -HairParticleSystem_BindLua::~HairParticleSystem_BindLua() -{ - if (owning) - { - delete component; - } -} - @@ -3712,19 +3590,6 @@ Luna::PropertyType LightComponent_BindLua::properties[] { NULL, NULL } }; -LightComponent_BindLua::LightComponent_BindLua(lua_State *L) -{ - owning = true; - component = new LightComponent; -} -LightComponent_BindLua::~LightComponent_BindLua() -{ - if (owning) - { - delete component; - } -} - int LightComponent_BindLua::GetType(lua_State* L) { wi::lua::SSetInt(L, (int)component->type); @@ -3813,7 +3678,7 @@ int LightComponent_BindLua::SetColor(lua_State* L) Vector_BindLua* value = Luna::lightcheck(L, 1); if (value) { - XMStoreFloat3(&component->color, XMLoadFloat4(value)); + XMStoreFloat3(&component->color, XMLoadFloat4(&value->data)); } else { @@ -3961,19 +3826,6 @@ Luna::PropertyType ObjectComponent_BindLua::properties[ { NULL, NULL } }; -ObjectComponent_BindLua::ObjectComponent_BindLua(lua_State* L) -{ - owning = true; - component = new ObjectComponent; -} -ObjectComponent_BindLua::~ObjectComponent_BindLua() -{ - if (owning) - { - delete component; - } -} - int ObjectComponent_BindLua::GetMeshID(lua_State* L) { @@ -4064,7 +3916,7 @@ int ObjectComponent_BindLua::SetColor(lua_State* L) Vector_BindLua* value = Luna::lightcheck(L, 1); if (value) { - XMStoreFloat4(&component->color, XMLoadFloat4(value)); + XMStoreFloat4(&component->color, XMLoadFloat4(&value->data)); } else { @@ -4086,7 +3938,7 @@ int ObjectComponent_BindLua::SetEmissiveColor(lua_State* L) Vector_BindLua* value = Luna::lightcheck(L, 1); if (value) { - XMStoreFloat4(&component->emissiveColor, XMLoadFloat4(value)); + XMStoreFloat4(&component->emissiveColor, XMLoadFloat4(&value->data)); } else { @@ -4171,19 +4023,6 @@ Luna::PropertyType InverseKinematicsComponen { NULL, NULL } }; -InverseKinematicsComponent_BindLua::InverseKinematicsComponent_BindLua(lua_State* L) -{ - owning = true; - component = new InverseKinematicsComponent; -} -InverseKinematicsComponent_BindLua::~InverseKinematicsComponent_BindLua() -{ - if (owning) - { - delete component; - } -} - int InverseKinematicsComponent_BindLua::SetTarget(lua_State* L) { int argc = wi::lua::SGetArgCount(L); @@ -4285,20 +4124,6 @@ Luna::PropertyType SpringComponent_BindLua::properties[ { NULL, NULL } }; -SpringComponent_BindLua::SpringComponent_BindLua(lua_State* L) -{ - owning = true; - component = new SpringComponent; - BuildBindings(); -} -SpringComponent_BindLua::~SpringComponent_BindLua() -{ - if (owning) - { - delete component; - } -} - int SpringComponent_BindLua::GetStiffness(lua_State *L) { wi::lua::SSetFloat(L, component->stiffnessForce); @@ -4377,19 +4202,6 @@ Luna::PropertyType ScriptComponent_BindLua::properties[ { NULL, NULL } }; -ScriptComponent_BindLua::ScriptComponent_BindLua(lua_State* L) -{ - owning = true; - component = new ScriptComponent; -} -ScriptComponent_BindLua::~ScriptComponent_BindLua() -{ - if (owning) - { - delete component; - } -} - int ScriptComponent_BindLua::CreateFromFile(lua_State* L) { int argc = wi::lua::SGetArgCount(L); @@ -4460,20 +4272,6 @@ Luna::PropertyType RigidBodyPhysicsComponent_ { NULL, NULL } }; -RigidBodyPhysicsComponent_BindLua::RigidBodyPhysicsComponent_BindLua(lua_State* L) -{ - owning = true; - component = new RigidBodyPhysicsComponent; - BuildBindings(); -} -RigidBodyPhysicsComponent_BindLua::~RigidBodyPhysicsComponent_BindLua() -{ - if (owning) - { - delete component; - } -} - int RigidBodyPhysicsComponent_BindLua::IsDisableDeactivation(lua_State* L) { wi::lua::SSetBool(L, component->IsDisableDeactivation()); @@ -4534,20 +4332,6 @@ Luna::PropertyType SoftBodyPhysicsComponent_Bi { NULL, NULL } }; -SoftBodyPhysicsComponent_BindLua::SoftBodyPhysicsComponent_BindLua(lua_State* L) -{ - owning = true; - component = new SoftBodyPhysicsComponent; - BuildBindings(); -} -SoftBodyPhysicsComponent_BindLua::~SoftBodyPhysicsComponent_BindLua() -{ - if (owning) - { - delete component; - } -} - int SoftBodyPhysicsComponent_BindLua::SetDisableDeactivation(lua_State *L) { bool value = wi::lua::SGetBool(L, 1); @@ -4584,20 +4368,6 @@ Luna::PropertyType ForceFieldComponent_BindLua::pro { NULL, NULL } }; -ForceFieldComponent_BindLua::ForceFieldComponent_BindLua(lua_State* L) -{ - owning = true; - component = new ForceFieldComponent; - BuildBindings(); -} -ForceFieldComponent_BindLua::~ForceFieldComponent_BindLua() -{ - if (owning) - { - delete component; - } -} - @@ -4625,20 +4395,6 @@ Luna::PropertyType Weather_OceanParams_BindLua::pro { NULL, NULL } }; -Weather_OceanParams_BindLua::Weather_OceanParams_BindLua(lua_State* L) -{ - owning = true; - parameter = new wi::Ocean::OceanParameters; - BuildBindings(); -} -Weather_OceanParams_BindLua::~Weather_OceanParams_BindLua() -{ - if (owning) - { - delete parameter; - } -} - int Weather_OceanParams_Property::Get(lua_State *L) { Luna::push(L, new Weather_OceanParams_BindLua(data)); @@ -4688,20 +4444,6 @@ Luna::PropertyType Weather_AtmosphereParams_Bi { NULL, NULL } }; -Weather_AtmosphereParams_BindLua::Weather_AtmosphereParams_BindLua(lua_State* L) -{ - owning = true; - parameter = new AtmosphereParameters; - BuildBindings(); -} -Weather_AtmosphereParams_BindLua::~Weather_AtmosphereParams_BindLua() -{ - if (owning) - { - delete parameter; - } -} - int Weather_AtmosphereParams_Property::Get(lua_State *L) { Luna::push(L, new Weather_AtmosphereParams_BindLua(data)); @@ -4759,20 +4501,6 @@ Luna::PropertyType Weather_VolumetricClou { NULL, NULL } }; -Weather_VolumetricCloudParams_BindLua::Weather_VolumetricCloudParams_BindLua(lua_State* L) -{ - owning = true; - parameter = new VolumetricCloudParameters; - BuildBindings(); -} -Weather_VolumetricCloudParams_BindLua::~Weather_VolumetricCloudParams_BindLua() -{ - if (owning) - { - delete parameter; - } -} - int Weather_VolumetricCloudParams_Property::Get(lua_State *L) { Luna::push(L, new Weather_VolumetricCloudParams_BindLua(data)); @@ -4843,20 +4571,6 @@ Luna::PropertyType WeatherComponent_BindLua::propertie { NULL, NULL } }; -WeatherComponent_BindLua::WeatherComponent_BindLua(lua_State* L) -{ - owning = true; - component = new WeatherComponent; - BuildBindings(); -} -WeatherComponent_BindLua::~WeatherComponent_BindLua() -{ - if (owning) - { - delete component; - } -} - int WeatherComponent_BindLua::IsOceanEnabled(lua_State* L) { wi::lua::SSetBool(L, component->IsOceanEnabled()); @@ -5017,20 +4731,6 @@ Luna::PropertyType SoundComponent_BindLua::properties[] { NULL, NULL } }; -SoundComponent_BindLua::SoundComponent_BindLua(lua_State* L) -{ - owning = true; - component = new SoundComponent; - BuildBindings(); -} -SoundComponent_BindLua::~SoundComponent_BindLua() -{ - if (owning) - { - delete component; - } -} - int SoundComponent_BindLua::IsPlaying(lua_State* L) { wi::lua::SSetBool(L, component->IsPlaying()); @@ -5109,20 +4809,6 @@ Luna::PropertyType ColliderComponent_BindLua::propert { NULL, NULL } }; -ColliderComponent_BindLua::ColliderComponent_BindLua(lua_State* L) -{ - owning = true; - component = new ColliderComponent; - BuildBindings(); -} -ColliderComponent_BindLua::~ColliderComponent_BindLua() -{ - if (owning) - { - delete component; - } -} - int ColliderComponent_BindLua::SetCPUEnabled(lua_State* L) { int argc = wi::lua::SGetArgCount(L); diff --git a/WickedEngine/wiScene_BindLua.h b/WickedEngine/wiScene_BindLua.h index bfc5a584b..31a5abd6f 100644 --- a/WickedEngine/wiScene_BindLua.h +++ b/WickedEngine/wiScene_BindLua.h @@ -21,7 +21,7 @@ namespace wi::lua::scene class Scene_BindLua { private: - wi::scene::Scene customScene; + std::unique_ptr owning; public: wi::scene::Scene* scene = nullptr; @@ -32,7 +32,8 @@ namespace wi::lua::scene Scene_BindLua(wi::scene::Scene* scene) :scene(scene) {} Scene_BindLua(lua_State* L) { - this->scene = &customScene; + owning = std::make_unique(); + this->scene = owning.get(); } int Update(lua_State* L); @@ -159,8 +160,9 @@ namespace wi::lua::scene class NameComponent_BindLua { + private: + std::unique_ptr owning; public: - bool owning = false; wi::scene::NameComponent* component = nullptr; static const char className[]; @@ -168,8 +170,11 @@ namespace wi::lua::scene static Luna::PropertyType properties[]; NameComponent_BindLua(wi::scene::NameComponent* component) :component(component) {} - NameComponent_BindLua(lua_State *L); - ~NameComponent_BindLua(); + NameComponent_BindLua(lua_State* L) + { + owning = std::make_unique(); + component = owning.get(); + } int SetName(lua_State* L); int GetName(lua_State* L); @@ -177,8 +182,9 @@ namespace wi::lua::scene class LayerComponent_BindLua { + private: + std::unique_ptr owning; public: - bool owning = false; wi::scene::LayerComponent* component = nullptr; static const char className[]; @@ -186,8 +192,11 @@ namespace wi::lua::scene static Luna::PropertyType properties[]; LayerComponent_BindLua(wi::scene::LayerComponent* component) :component(component) {} - LayerComponent_BindLua(lua_State *L); - ~LayerComponent_BindLua(); + LayerComponent_BindLua(lua_State* L) + { + owning = std::make_unique(); + component = owning.get(); + } int SetLayerMask(lua_State* L); int GetLayerMask(lua_State* L); @@ -195,8 +204,9 @@ namespace wi::lua::scene class TransformComponent_BindLua { + private: + std::unique_ptr owning; public: - bool owning = false; wi::scene::TransformComponent* component = nullptr; static const char className[]; @@ -210,9 +220,16 @@ namespace wi::lua::scene Scale_local = VectorProperty(&component->scale_local); } - TransformComponent_BindLua(wi::scene::TransformComponent* component) :component(component) { BuildBindings(); } - TransformComponent_BindLua(lua_State *L); - ~TransformComponent_BindLua(); + TransformComponent_BindLua(wi::scene::TransformComponent* component) :component(component) + { + BuildBindings(); + } + TransformComponent_BindLua(lua_State* L) + { + owning = std::make_unique(); + component = owning.get(); + BuildBindings(); + } VectorProperty Translation_local; VectorProperty Rotation_local; @@ -240,8 +257,9 @@ namespace wi::lua::scene class CameraComponent_BindLua { + private: + std::unique_ptr owning; public: - bool owning = false; wi::scene::CameraComponent* component = nullptr; static const char className[]; @@ -249,8 +267,11 @@ namespace wi::lua::scene static Luna::PropertyType properties[]; CameraComponent_BindLua(wi::scene::CameraComponent* component) :component(component) {} - CameraComponent_BindLua(lua_State *L); - ~CameraComponent_BindLua(); + CameraComponent_BindLua(lua_State* L) + { + owning = std::make_unique(); + component = owning.get(); + } int UpdateCamera(lua_State* L); int TransformCamera(lua_State* L); @@ -279,8 +300,9 @@ namespace wi::lua::scene class AnimationComponent_BindLua { + private: + std::unique_ptr owning; public: - bool owning = false; wi::scene::AnimationComponent* component = nullptr; static const char className[]; @@ -288,8 +310,11 @@ namespace wi::lua::scene static Luna::PropertyType properties[]; AnimationComponent_BindLua(wi::scene::AnimationComponent* component) :component(component) {} - AnimationComponent_BindLua(lua_State *L); - ~AnimationComponent_BindLua(); + AnimationComponent_BindLua(lua_State* L) + { + owning = std::make_unique(); + component = owning.get(); + } int Play(lua_State* L); int Pause(lua_State* L); @@ -306,8 +331,9 @@ namespace wi::lua::scene class MaterialComponent_BindLua { + private: + std::unique_ptr owning; public: - bool owning = false; wi::scene::MaterialComponent* component = nullptr; static const char className[]; @@ -342,9 +368,16 @@ namespace wi::lua::scene customShaderID = IntProperty(&component->customShaderID); } - MaterialComponent_BindLua(wi::scene::MaterialComponent* component) :component(component) { BuildBindings(); } - MaterialComponent_BindLua(lua_State *L); - ~MaterialComponent_BindLua(); + MaterialComponent_BindLua(wi::scene::MaterialComponent* component) :component(component) + { + BuildBindings(); + } + MaterialComponent_BindLua(lua_State* L) + { + owning = std::make_unique(); + component = owning.get(); + BuildBindings(); + } LongLongProperty _flags; IntProperty ShaderType; @@ -414,8 +447,9 @@ namespace wi::lua::scene class MeshComponent_BindLua { + private: + std::unique_ptr owning; public: - bool owning = false; wi::scene::MeshComponent* component = nullptr; static const char className[]; @@ -430,9 +464,16 @@ namespace wi::lua::scene SubsetsPerLOD = LongLongProperty(reinterpret_cast(&component->subsets_per_lod)); } - MeshComponent_BindLua(wi::scene::MeshComponent* component) :component(component) { BuildBindings(); } - MeshComponent_BindLua(lua_State *L); - ~MeshComponent_BindLua(); + MeshComponent_BindLua(wi::scene::MeshComponent* component) :component(component) + { + BuildBindings(); + } + MeshComponent_BindLua(lua_State* L) + { + owning = std::make_unique(); + component = owning.get(); + BuildBindings(); + } LongLongProperty _flags; FloatProperty TessellationFactor; @@ -450,8 +491,9 @@ namespace wi::lua::scene class EmitterComponent_BindLua { + private: + std::unique_ptr owning; public: - bool owning = false; wi::EmittedParticleSystem* component = nullptr; static const char className[]; @@ -482,9 +524,16 @@ namespace wi::lua::scene SpriteSheet_Framerate = FloatProperty(&component->frameRate); } - EmitterComponent_BindLua(wi::EmittedParticleSystem* component) :component(component) { BuildBindings(); } - EmitterComponent_BindLua(lua_State *L); - ~EmitterComponent_BindLua(); + EmitterComponent_BindLua(wi::EmittedParticleSystem* component) :component(component) + { + BuildBindings(); + } + EmitterComponent_BindLua(lua_State* L) + { + owning = std::make_unique(); + component = owning.get(); + BuildBindings(); + } LongLongProperty _flags; @@ -554,9 +603,10 @@ namespace wi::lua::scene class HairParticleSystem_BindLua { + private: + std::unique_ptr owning; public: - bool owning = false; - HairParticleSystem* component = nullptr; + wi::HairParticleSystem* component = nullptr; static const char className[]; static Luna::FunctionType methods[]; @@ -580,9 +630,16 @@ namespace wi::lua::scene SpriteSheet_Frame_Start = LongLongProperty(reinterpret_cast(&component->frameStart)); } - HairParticleSystem_BindLua(HairParticleSystem* component) :component(component) { BuildBindings(); } - HairParticleSystem_BindLua(lua_State *L); - ~HairParticleSystem_BindLua(); + HairParticleSystem_BindLua(HairParticleSystem* component) :component(component) + { + BuildBindings(); + } + HairParticleSystem_BindLua(lua_State* L) + { + owning = std::make_unique(); + component = owning.get(); + BuildBindings(); + } LongLongProperty _flags; @@ -617,8 +674,9 @@ namespace wi::lua::scene class LightComponent_BindLua { + private: + std::unique_ptr owning; public: - bool owning = false; wi::scene::LightComponent* component = nullptr; static const char className[]; @@ -626,8 +684,11 @@ namespace wi::lua::scene static Luna::PropertyType properties[]; LightComponent_BindLua(wi::scene::LightComponent* component) :component(component) {} - LightComponent_BindLua(lua_State *L); - ~LightComponent_BindLua(); + LightComponent_BindLua(lua_State* L) + { + owning = std::make_unique(); + component = owning.get(); + } int SetType(lua_State* L); int SetRange(lua_State* L); @@ -656,8 +717,9 @@ namespace wi::lua::scene class ObjectComponent_BindLua { + private: + std::unique_ptr owning; public: - bool owning = false; wi::scene::ObjectComponent* component = nullptr; static const char className[]; @@ -665,8 +727,11 @@ namespace wi::lua::scene static Luna::PropertyType properties[]; ObjectComponent_BindLua(wi::scene::ObjectComponent* component) :component(component) {} - ObjectComponent_BindLua(lua_State* L); - ~ObjectComponent_BindLua(); + ObjectComponent_BindLua(lua_State* L) + { + owning = std::make_unique(); + component = owning.get(); + } int GetMeshID(lua_State* L); int GetCascadeMask(lua_State* L); @@ -689,8 +754,9 @@ namespace wi::lua::scene class InverseKinematicsComponent_BindLua { + private: + std::unique_ptr owning; public: - bool owning = false; wi::scene::InverseKinematicsComponent* component = nullptr; static const char className[]; @@ -698,8 +764,11 @@ namespace wi::lua::scene static Luna::PropertyType properties[]; InverseKinematicsComponent_BindLua(wi::scene::InverseKinematicsComponent* component) :component(component) {} - InverseKinematicsComponent_BindLua(lua_State* L); - ~InverseKinematicsComponent_BindLua(); + InverseKinematicsComponent_BindLua(lua_State* L) + { + owning = std::make_unique(); + component = owning.get(); + } int SetTarget(lua_State* L); int SetChainLength(lua_State* L); @@ -713,8 +782,9 @@ namespace wi::lua::scene class SpringComponent_BindLua { + private: + std::unique_ptr owning; public: - bool owning = false; wi::scene::SpringComponent* component = nullptr; static const char className[]; @@ -729,9 +799,16 @@ namespace wi::lua::scene GravityDirection = VectorProperty(&component->gravityDir); } - SpringComponent_BindLua(wi::scene::SpringComponent* component) :component(component) { BuildBindings(); } - SpringComponent_BindLua(lua_State* L); - ~SpringComponent_BindLua(); + SpringComponent_BindLua(wi::scene::SpringComponent* component) :component(component) + { + BuildBindings(); + } + SpringComponent_BindLua(lua_State* L) + { + owning = std::make_unique(); + component = owning.get(); + BuildBindings(); + } FloatProperty DragForce; FloatProperty HitRadius; @@ -753,8 +830,9 @@ namespace wi::lua::scene class ScriptComponent_BindLua { + private: + std::unique_ptr owning; public: - bool owning = false; wi::scene::ScriptComponent* component = nullptr; static const char className[]; @@ -762,8 +840,11 @@ namespace wi::lua::scene static Luna::PropertyType properties[]; ScriptComponent_BindLua(wi::scene::ScriptComponent* component) :component(component) {} - ScriptComponent_BindLua(lua_State* L); - ~ScriptComponent_BindLua(); + ScriptComponent_BindLua(lua_State* L) + { + owning = std::make_unique(); + component = owning.get(); + } int CreateFromFile(lua_State* L); int Play(lua_State* L); @@ -774,8 +855,9 @@ namespace wi::lua::scene class RigidBodyPhysicsComponent_BindLua { + private: + std::unique_ptr owning; public: - bool owning = false; wi::scene::RigidBodyPhysicsComponent* component = nullptr; static const char className[]; @@ -797,9 +879,16 @@ namespace wi::lua::scene TargetMeshLOD = LongLongProperty(reinterpret_cast(&component->mesh_lod)); } - RigidBodyPhysicsComponent_BindLua(wi::scene::RigidBodyPhysicsComponent* component) :component(component) { BuildBindings(); } - RigidBodyPhysicsComponent_BindLua(lua_State* L); - ~RigidBodyPhysicsComponent_BindLua(); + RigidBodyPhysicsComponent_BindLua(wi::scene::RigidBodyPhysicsComponent* component) :component(component) + { + BuildBindings(); + } + RigidBodyPhysicsComponent_BindLua(lua_State* L) + { + owning = std::make_unique(); + component = owning.get(); + BuildBindings(); + } IntProperty Shape; FloatProperty Mass; @@ -834,8 +923,9 @@ namespace wi::lua::scene class SoftBodyPhysicsComponent_BindLua { + private: + std::unique_ptr owning; public: - bool owning = false; wi::scene::SoftBodyPhysicsComponent* component = nullptr; static const char className[]; @@ -849,9 +939,16 @@ namespace wi::lua::scene Restitution = wi::lua::FloatProperty(&component->restitution); } - SoftBodyPhysicsComponent_BindLua(wi::scene::SoftBodyPhysicsComponent* component) :component(component) { BuildBindings(); } - SoftBodyPhysicsComponent_BindLua(lua_State* L); - ~SoftBodyPhysicsComponent_BindLua(); + SoftBodyPhysicsComponent_BindLua(wi::scene::SoftBodyPhysicsComponent* component) :component(component) + { + BuildBindings(); + } + SoftBodyPhysicsComponent_BindLua(lua_State* L) + { + owning = std::make_unique(); + component = owning.get(); + BuildBindings(); + } wi::lua::FloatProperty Mass; wi::lua::FloatProperty Friction; @@ -868,8 +965,9 @@ namespace wi::lua::scene class ForceFieldComponent_BindLua { + private: + std::unique_ptr owning; public: - bool owning = false; wi::scene::ForceFieldComponent* component = nullptr; static const char className[]; @@ -883,9 +981,16 @@ namespace wi::lua::scene Range = FloatProperty(&component->range); } - ForceFieldComponent_BindLua(wi::scene::ForceFieldComponent* component) :component(component) { BuildBindings(); } - ForceFieldComponent_BindLua(lua_State* L); - ~ForceFieldComponent_BindLua(); + ForceFieldComponent_BindLua(wi::scene::ForceFieldComponent* component) :component(component) + { + BuildBindings(); + } + ForceFieldComponent_BindLua(lua_State* L) + { + owning = std::make_unique(); + component = owning.get(); + BuildBindings(); + } IntProperty Type; FloatProperty Gravity; @@ -898,8 +1003,9 @@ namespace wi::lua::scene class Weather_OceanParams_BindLua { + private: + std::unique_ptr owning; public: - bool owning = false; wi::Ocean::OceanParameters* parameter = nullptr; static const char className[]; @@ -918,9 +1024,16 @@ namespace wi::lua::scene choppy_scale = FloatProperty(¶meter->choppy_scale); } - Weather_OceanParams_BindLua(wi::Ocean::OceanParameters* parameter) :parameter(parameter) { BuildBindings(); } - Weather_OceanParams_BindLua(lua_State* L); - ~Weather_OceanParams_BindLua(); + Weather_OceanParams_BindLua(wi::Ocean::OceanParameters* parameter) :parameter(parameter) + { + BuildBindings(); + } + Weather_OceanParams_BindLua(lua_State* L) + { + owning = std::make_unique(); + parameter = owning.get(); + BuildBindings(); + } IntProperty dmap_dim; FloatProperty patch_length; @@ -948,10 +1061,9 @@ namespace wi::lua::scene PropertyFunction(surfaceDetail) PropertyFunction(surfaceDisplacement) }; - class Weather_OceanParams_Property final : public LuaProperty + struct Weather_OceanParams_Property { - public: - wi::Ocean::OceanParameters* data; + wi::Ocean::OceanParameters* data = nullptr; Weather_OceanParams_Property(){} Weather_OceanParams_Property(wi::Ocean::OceanParameters* data) :data(data){} int Get(lua_State* L); @@ -960,8 +1072,9 @@ namespace wi::lua::scene class Weather_AtmosphereParams_BindLua { + private: + std::unique_ptr owning; public: - bool owning = false; AtmosphereParameters* parameter = nullptr; static const char className[]; @@ -991,9 +1104,16 @@ namespace wi::lua::scene groundAlbedo = VectorProperty(¶meter->groundAlbedo); } - Weather_AtmosphereParams_BindLua(AtmosphereParameters* parameter) :parameter(parameter) { BuildBindings(); } - Weather_AtmosphereParams_BindLua(lua_State* L); - ~Weather_AtmosphereParams_BindLua(); + Weather_AtmosphereParams_BindLua(AtmosphereParameters* parameter) :parameter(parameter) + { + BuildBindings(); + } + Weather_AtmosphereParams_BindLua(lua_State* L) + { + owning = std::make_unique(); + parameter = owning.get(); + BuildBindings(); + } FloatProperty bottomRadius; FloatProperty topRadius; @@ -1036,10 +1156,9 @@ namespace wi::lua::scene PropertyFunction(absorptionExtinction) PropertyFunction(groundAlbedo) }; - class Weather_AtmosphereParams_Property final : public LuaProperty + struct Weather_AtmosphereParams_Property { - public: - AtmosphereParameters* data; + AtmosphereParameters* data = nullptr; Weather_AtmosphereParams_Property(){} Weather_AtmosphereParams_Property(AtmosphereParameters* data) :data(data){} int Get(lua_State* L); @@ -1048,8 +1167,9 @@ namespace wi::lua::scene class Weather_VolumetricCloudParams_BindLua { + private: + std::unique_ptr owning; public: - bool owning = false; VolumetricCloudParameters* parameter = nullptr; static const char className[]; @@ -1095,9 +1215,16 @@ namespace wi::lua::scene } - Weather_VolumetricCloudParams_BindLua(VolumetricCloudParameters* parameter) :parameter(parameter) { BuildBindings(); } - Weather_VolumetricCloudParams_BindLua(lua_State* L); - ~Weather_VolumetricCloudParams_BindLua(); + Weather_VolumetricCloudParams_BindLua(VolumetricCloudParameters* parameter) : parameter(parameter) + { + BuildBindings(); + } + Weather_VolumetricCloudParams_BindLua(lua_State* L) + { + owning = std::make_unique(); + parameter = owning.get(); + BuildBindings(); + } VectorProperty Albedo; FloatProperty CloudAmbientGroundMultiplier; @@ -1170,10 +1297,9 @@ namespace wi::lua::scene PropertyFunction(CloudGradientLarge) }; - class Weather_VolumetricCloudParams_Property final : public LuaProperty + struct Weather_VolumetricCloudParams_Property { - public: - VolumetricCloudParameters* data; + VolumetricCloudParameters* data = nullptr; Weather_VolumetricCloudParams_Property(){} Weather_VolumetricCloudParams_Property(VolumetricCloudParameters* data) :data(data){} int Get(lua_State* L); @@ -1182,8 +1308,9 @@ namespace wi::lua::scene class WeatherComponent_BindLua { + private: + std::unique_ptr owning; public: - bool owning = false; wi::scene::WeatherComponent* component = nullptr; static const char className[]; @@ -1218,9 +1345,16 @@ namespace wi::lua::scene volumetricCloudsWeatherMapName = StringProperty(&component->volumetricCloudsWeatherMapName); } - WeatherComponent_BindLua(wi::scene::WeatherComponent* component) :component(component) { BuildBindings(); } - WeatherComponent_BindLua(lua_State* L); - ~WeatherComponent_BindLua(); + WeatherComponent_BindLua(wi::scene::WeatherComponent* component) :component(component) + { + BuildBindings(); + } + WeatherComponent_BindLua(lua_State* L) + { + owning = std::make_unique(); + component = owning.get(); + BuildBindings(); + } VectorProperty sunColor; VectorProperty sunDirection; @@ -1307,8 +1441,9 @@ namespace wi::lua::scene class SoundComponent_BindLua { + private: + std::unique_ptr owning; public: - bool owning = false; wi::scene::SoundComponent* component = nullptr; static const char className[]; @@ -1321,9 +1456,16 @@ namespace wi::lua::scene Volume = FloatProperty(&component->volume); } - SoundComponent_BindLua(wi::scene::SoundComponent* component) :component(component) { BuildBindings(); } - SoundComponent_BindLua(lua_State* L); - ~SoundComponent_BindLua(); + SoundComponent_BindLua(wi::scene::SoundComponent* component) :component(component) + { + BuildBindings(); + } + SoundComponent_BindLua(lua_State* L) + { + owning = std::make_unique(); + component = owning.get(); + BuildBindings(); + } StringProperty Filename; FloatProperty Volume; @@ -1343,8 +1485,9 @@ namespace wi::lua::scene class ColliderComponent_BindLua { + private: + std::unique_ptr owning; public: - bool owning = false; wi::scene::ColliderComponent* component = nullptr; static const char className[]; @@ -1359,9 +1502,16 @@ namespace wi::lua::scene Tail = VectorProperty(&component->tail); } - ColliderComponent_BindLua(wi::scene::ColliderComponent* component) :component(component) { BuildBindings(); } - ColliderComponent_BindLua(lua_State* L); - ~ColliderComponent_BindLua(); + ColliderComponent_BindLua(wi::scene::ColliderComponent* component) :component(component) + { + BuildBindings(); + } + ColliderComponent_BindLua(lua_State* L) + { + owning = std::make_unique(); + component = owning.get(); + BuildBindings(); + } IntProperty Shape; FloatProperty Radius; diff --git a/WickedEngine/wiSpriteAnim_BindLua.cpp b/WickedEngine/wiSpriteAnim_BindLua.cpp index 08f8c1f0a..aaa232ea3 100644 --- a/WickedEngine/wiSpriteAnim_BindLua.cpp +++ b/WickedEngine/wiSpriteAnim_BindLua.cpp @@ -119,7 +119,7 @@ namespace wi::lua Vector_BindLua* vec = Luna::lightcheck(L, 1); if (vec != nullptr) { - XMStoreFloat3(&anim.vel, XMLoadFloat4(vec)); + XMStoreFloat3(&anim.vel, XMLoadFloat4(&vec->data)); } else { diff --git a/WickedEngine/wiSpriteFont_BindLua.cpp b/WickedEngine/wiSpriteFont_BindLua.cpp index 29844b069..82e4953a8 100644 --- a/WickedEngine/wiSpriteFont_BindLua.cpp +++ b/WickedEngine/wiSpriteFont_BindLua.cpp @@ -109,8 +109,8 @@ namespace wi::lua Vector_BindLua* param = Luna::lightcheck(L, 1); if (param != nullptr) { - font.params.posX = param->x; - font.params.posY = param->y; + font.params.posX = param->data.x; + font.params.posY = param->data.y; } else wi::lua::SError(L, "SetPos(Vector pos) argument is not a vector!"); @@ -127,8 +127,8 @@ namespace wi::lua Vector_BindLua* param = Luna::lightcheck(L, 1); if (param != nullptr) { - font.params.spacingX = param->x; - font.params.spacingY = param->y; + font.params.spacingX = param->data.x; + font.params.spacingY = param->data.y; } else wi::lua::SError(L, "SetSpacing(Vector spacing) argument is not a vector!"); @@ -160,7 +160,7 @@ namespace wi::lua Vector_BindLua* param = Luna::lightcheck(L, 1); if (param != nullptr) { - font.params.color = wi::Color::fromFloat4(*param); + font.params.color = wi::Color::fromFloat4(param->data); } else { @@ -180,7 +180,7 @@ namespace wi::lua Vector_BindLua* param = Luna::lightcheck(L, 1); if (param != nullptr) { - font.params.shadowColor = wi::Color::fromFloat4(*param); + font.params.shadowColor = wi::Color::fromFloat4(param->data); } else { @@ -248,8 +248,8 @@ namespace wi::lua Vector_BindLua* param = Luna::lightcheck(L, 1); if (param != nullptr) { - font.params.shadow_offset_x = param->x; - font.params.shadow_offset_y = param->y; + font.params.shadow_offset_x = param->data.x; + font.params.shadow_offset_y = param->data.y; } else wi::lua::SError(L, "SetShadowOffset(Vector pos) argument is not a vector!"); diff --git a/WickedEngine/wiTerrain.cpp b/WickedEngine/wiTerrain.cpp index 1030da837..8f692bb7a 100644 --- a/WickedEngine/wiTerrain.cpp +++ b/WickedEngine/wiTerrain.cpp @@ -1202,7 +1202,7 @@ namespace wi::terrain archive << chunks.size(); for (auto& it : chunks) { - Chunk& chunk = it.first; + const Chunk& chunk = it.first; archive << chunk.x; archive << chunk.z; ChunkData& chunk_data = it.second; diff --git a/WickedEngine/wiTerrain.h b/WickedEngine/wiTerrain.h index 94ff73ed1..9bf96a626 100644 --- a/WickedEngine/wiTerrain.h +++ b/WickedEngine/wiTerrain.h @@ -171,6 +171,8 @@ namespace wi::terrain struct Modifier { + virtual ~Modifier() = default; + enum class Type { Perlin, diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index 7c9c68aa3..4ce57d99e 100644 --- a/WickedEngine/wiVersion.cpp +++ b/WickedEngine/wiVersion.cpp @@ -9,7 +9,7 @@ namespace wi::version // minor features, major updates, breaking compatibility changes const int minor = 71; // minor bug fixes, alterations, refactors, updates - const int revision = 43; + const int revision = 44; const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);