diff --git a/WickedEngine/DeferredRenderableComponent.cpp b/WickedEngine/DeferredRenderableComponent.cpp index cadb3dc33..451bd11f3 100644 --- a/WickedEngine/DeferredRenderableComponent.cpp +++ b/WickedEngine/DeferredRenderableComponent.cpp @@ -6,7 +6,6 @@ #include "wiStencilRef.h" #include "wiHelper.h" #include "wiTextureHelper.h" -#include "DeferredRenderableComponent_BindLua.h" DeferredRenderableComponent::DeferredRenderableComponent(){ Renderable3DComponent::setProperties(); @@ -15,8 +14,6 @@ DeferredRenderableComponent::DeferredRenderableComponent(){ setSSAOEnabled(true); setPreferredThreadingCount(0); - - DeferredRenderableComponent_BindLua::Bind(); } DeferredRenderableComponent::~DeferredRenderableComponent(){ } diff --git a/WickedEngine/ForwardRenderableComponent.cpp b/WickedEngine/ForwardRenderableComponent.cpp index b05288475..383ea60f2 100644 --- a/WickedEngine/ForwardRenderableComponent.cpp +++ b/WickedEngine/ForwardRenderableComponent.cpp @@ -5,7 +5,6 @@ #include "wiCamera.h" #include "wiStencilRef.h" #include "wiHelper.h" -#include "ForwardRenderableComponent_BindLua.h" ForwardRenderableComponent::ForwardRenderableComponent(){ Renderable3DComponent::setProperties(); @@ -15,8 +14,6 @@ ForwardRenderableComponent::ForwardRenderableComponent(){ setShadowsEnabled(false); setPreferredThreadingCount(0); - - ForwardRenderableComponent_BindLua::Bind(); } ForwardRenderableComponent::~ForwardRenderableComponent(){ } diff --git a/WickedEngine/LoadingScreenComponent.cpp b/WickedEngine/LoadingScreenComponent.cpp index adb51115a..0933fa106 100644 --- a/WickedEngine/LoadingScreenComponent.cpp +++ b/WickedEngine/LoadingScreenComponent.cpp @@ -1,5 +1,4 @@ #include "LoadingScreenComponent.h" -#include "LoadingScreenComponent_BindLua.h" LoadingScreenComponent::LoadingScreenComponent() @@ -7,7 +6,6 @@ LoadingScreenComponent::LoadingScreenComponent() Renderable2DComponent::Renderable2DComponent(); loaders.clear(); finish = nullptr; - LoadingScreenComponent_BindLua::Bind(); } diff --git a/WickedEngine/MainComponent.cpp b/WickedEngine/MainComponent.cpp index 5bdee2c27..0ce45bf0a 100644 --- a/WickedEngine/MainComponent.cpp +++ b/WickedEngine/MainComponent.cpp @@ -18,8 +18,6 @@ MainComponent::MainComponent() setFrameSkip(true); setTargetFrameRate(60); setApplicationControlLostThreshold(10); - - MainComponent_BindLua::Bind(); } diff --git a/WickedEngine/MainComponent_BindLua.cpp b/WickedEngine/MainComponent_BindLua.cpp index 08463fe43..f0e3664a7 100644 --- a/WickedEngine/MainComponent_BindLua.cpp +++ b/WickedEngine/MainComponent_BindLua.cpp @@ -1,6 +1,8 @@ #include "MainComponent_BindLua.h" #include "Renderable3DComponent_BindLua.h" #include "Renderable2DComponent_BindLua.h" +#include "DeferredRenderableComponent_BindLua.h" +#include "ForwardRenderableComponent_BindLua.h" #include "wiResourceManager_BindLua.h" const char MainComponent_BindLua::className[] = "MainComponent"; @@ -41,6 +43,22 @@ int MainComponent_BindLua::GetContent(lua_State *L) } int MainComponent_BindLua::GetActiveComponent(lua_State *L) { + //return deferred 3d component if the active one is of that type + DeferredRenderableComponent* compDef3D = dynamic_cast(component->getActiveComponent()); + if (compDef3D != nullptr) + { + Luna::push(L, new DeferredRenderableComponent_BindLua(compDef3D)); + return 1; + } + + //return forward 3d component if the active one is of that type + ForwardRenderableComponent* compFwd3D = dynamic_cast(component->getActiveComponent()); + if (compFwd3D != nullptr) + { + Luna::push(L, new ForwardRenderableComponent_BindLua(compFwd3D)); + return 1; + } + //return 3d component if the active one is of that type Renderable3DComponent* comp3D = dynamic_cast(component->getActiveComponent()); if (comp3D != nullptr) diff --git a/WickedEngine/Renderable2DComponent.cpp b/WickedEngine/Renderable2DComponent.cpp index 4627ff159..164ddfbc3 100644 --- a/WickedEngine/Renderable2DComponent.cpp +++ b/WickedEngine/Renderable2DComponent.cpp @@ -1,14 +1,11 @@ #include "Renderable2DComponent.h" #include "wiResourceManager.h" #include "wiSprite.h" -#include "Renderable2DComponent_BindLua.h" Renderable2DComponent::Renderable2DComponent() { setSpriteSpeed(1.f); m_sprites.clear(); - - Renderable2DComponent_BindLua::Bind(); } diff --git a/WickedEngine/Renderable2DComponent_BindLua.cpp b/WickedEngine/Renderable2DComponent_BindLua.cpp index e6a9d0d7e..6db3a0287 100644 --- a/WickedEngine/Renderable2DComponent_BindLua.cpp +++ b/WickedEngine/Renderable2DComponent_BindLua.cpp @@ -1,5 +1,6 @@ #include "Renderable2DComponent_BindLua.h" #include "wiResourceManager_BindLua.h" +#include "wiSprite.h" const char Renderable2DComponent_BindLua::className[] = "Renderable2DComponent"; @@ -39,10 +40,28 @@ int Renderable2DComponent_BindLua::GetContent(lua_State *L) int Renderable2DComponent_BindLua::AddSprite(lua_State *L) { + if (component == nullptr) + { + wiLua::SError(L, "GetContent() component is empty!"); + return 0; + } int argc = wiLua::SGetArgCount(L); if (argc > 1) { - //TODO + string tex = wiLua::SGetString(L, 2); + string mask = ""; + string nor = ""; + if (argc > 2) + { + mask = wiLua::SGetString(L, 3); + if (argc > 3) + { + nor = wiLua::SGetString(L, 4); + } + } + wiSprite* sprite = new wiSprite(tex,mask,nor,&component->Content); + sprite->effects = wiImageEffects(100, 100); + component->addSprite(sprite); } else { diff --git a/WickedEngine/Renderable3DComponent.cpp b/WickedEngine/Renderable3DComponent.cpp index 348daea1e..1f749e012 100644 --- a/WickedEngine/Renderable3DComponent.cpp +++ b/WickedEngine/Renderable3DComponent.cpp @@ -6,11 +6,9 @@ #include "wiStencilRef.h" #include "wiHelper.h" #include "wiTextureHelper.h" -#include "Renderable3DComponent_BindLua.h" Renderable3DComponent::Renderable3DComponent() { - Renderable3DComponent_BindLua::Bind(); } Renderable3DComponent::~Renderable3DComponent() { diff --git a/WickedEngine/Texture_BindLua.cpp b/WickedEngine/Texture_BindLua.cpp new file mode 100644 index 000000000..9d677b072 --- /dev/null +++ b/WickedEngine/Texture_BindLua.cpp @@ -0,0 +1,31 @@ +#include "Texture_BindLua.h" + +const char Texture_BindLua::className[] = "Texture"; + +Luna::FunctionType Texture_BindLua::methods[] = { + { NULL, NULL } +}; +Luna::PropertyType Texture_BindLua::properties[] = { + { NULL, NULL } +}; + +Texture_BindLua::Texture_BindLua(wiRenderer::TextureView texture) :texture(texture) +{ +} +Texture_BindLua::Texture_BindLua(lua_State *L) +{ + texture = nullptr; +} +Texture_BindLua::~Texture_BindLua() +{ +} + +void Texture_BindLua::Bind() +{ + static bool initialized = false; + if (!initialized) + { + Luna::Register(wiLua::GetGlobal()->GetLuaState()); + initialized = true; + } +} \ No newline at end of file diff --git a/WickedEngine/Texture_BindLua.h b/WickedEngine/Texture_BindLua.h new file mode 100644 index 000000000..44e6bb5b5 --- /dev/null +++ b/WickedEngine/Texture_BindLua.h @@ -0,0 +1,21 @@ +#pragma once +#include "wiLua.h" +#include "wiLuna.h" +#include "wiRenderer.h" + +class Texture_BindLua +{ +private: + wiRenderer::TextureView texture; +public: + static const char className[]; + static Luna::FunctionType methods[]; + static Luna::PropertyType properties[]; + + Texture_BindLua(wiRenderer::TextureView texture = nullptr); + Texture_BindLua(lua_State *L); + ~Texture_BindLua(); + + static void Bind(); +}; + diff --git a/WickedEngine/WickedEngine.vcxproj b/WickedEngine/WickedEngine.vcxproj index 95b1b8832..7e55f2c00 100644 --- a/WickedEngine/WickedEngine.vcxproj +++ b/WickedEngine/WickedEngine.vcxproj @@ -217,6 +217,7 @@ + @@ -397,6 +398,7 @@ + @@ -420,6 +422,7 @@ + @@ -678,6 +681,7 @@ + diff --git a/WickedEngine/WickedEngine.vcxproj.filters b/WickedEngine/WickedEngine.vcxproj.filters index 024741fcb..3613d115d 100644 --- a/WickedEngine/WickedEngine.vcxproj.filters +++ b/WickedEngine/WickedEngine.vcxproj.filters @@ -764,6 +764,12 @@ ScriptBinders + + ScriptBinders + + + ScriptBinders + @@ -1699,6 +1705,12 @@ ScriptBinders + + ScriptBinders + + + ScriptBinders + diff --git a/WickedEngine/wiLua.cpp b/WickedEngine/wiLua.cpp index eea7991b0..1529accf2 100644 --- a/WickedEngine/wiLua.cpp +++ b/WickedEngine/wiLua.cpp @@ -1,5 +1,15 @@ #include "wiLua.h" #include "wiBackLog.h" +#include "MainComponent_BindLua.h" +#include "Renderable2DComponent_BindLua.h" +#include "LoadingScreenComponent_BindLua.h" +#include "Renderable3DComponent_BindLua.h" +#include "DeferredRenderableComponent_BindLua.h" +#include "ForwardRenderableComponent_BindLua.h" +#include "Texture_BindLua.h" +#include "wiRenderer_BindLua.h" +#include "wiSound_BindLua.h" +#include "wiSprite_BindLua.h" wiLua *wiLua::globalLua = nullptr; @@ -23,6 +33,17 @@ wiLua* wiLua::GetGlobal() if (globalLua == nullptr) { globalLua = new wiLua(); + + MainComponent_BindLua::Bind(); + Renderable2DComponent_BindLua::Bind(); + LoadingScreenComponent_BindLua::Bind(); + Renderable3DComponent_BindLua::Bind(); + DeferredRenderableComponent_BindLua::Bind(); + ForwardRenderableComponent_BindLua::Bind(); + Texture_BindLua::Bind(); + wiRenderer_BindLua::Bind(); + wiSound_BindLua::Bind(); + wiSprite_BindLua::Bind(); } return globalLua; } diff --git a/WickedEngine/wiRenderer.cpp b/WickedEngine/wiRenderer.cpp index 95891e669..eaf743669 100644 --- a/WickedEngine/wiRenderer.cpp +++ b/WickedEngine/wiRenderer.cpp @@ -20,7 +20,6 @@ #include "wiWaterPlane.h" #include "wiGraphicsThreads.h" #include "wiRandom.h" -#include "wiRenderer_BindLua.h" #pragma region STATICS D3D_DRIVER_TYPE wiRenderer::driverType; @@ -468,8 +467,6 @@ void wiRenderer::SetUpStaticComponents() ,1,false ); - - wiRenderer_BindLua::Bind(); } void wiRenderer::CleanUpStatic() { diff --git a/WickedEngine/wiResourceManager.cpp b/WickedEngine/wiResourceManager.cpp index 5474aa429..dcf9d344e 100644 --- a/WickedEngine/wiResourceManager.cpp +++ b/WickedEngine/wiResourceManager.cpp @@ -4,7 +4,6 @@ #include "wiHelper.h" #include "Utility/WicTextureLoader.h" #include "Utility/DDSTextureLoader.h" -#include "wiResourceManager_BindLua.h" wiResourceManager::filetypes wiResourceManager::types; wiResourceManager* wiResourceManager::globalResources = nullptr; @@ -25,7 +24,6 @@ wiResourceManager* wiResourceManager::GetGlobal() if (globalResources == nullptr) { globalResources = new wiResourceManager(); - wiResourceManager_BindLua::Bind(); } STATICMUTEX.unlock(); } diff --git a/WickedEngine/wiResourceManager_BindLua.cpp b/WickedEngine/wiResourceManager_BindLua.cpp index 5f299ca9e..bb2f1c1f0 100644 --- a/WickedEngine/wiResourceManager_BindLua.cpp +++ b/WickedEngine/wiResourceManager_BindLua.cpp @@ -1,6 +1,8 @@ #include "wiResourceManager_BindLua.h" #include "wiSound_BindLua.h" #include "wiHelper.h" +#include "Texture_BindLua.h" +#include "wiRenderer.h" const char wiResourceManager_BindLua::className[] = "Resource"; @@ -29,6 +31,11 @@ wiResourceManager_BindLua::~wiResourceManager_BindLua() int wiResourceManager_BindLua::Get(lua_State *L) { + if (resources == nullptr) + { + wiLua::SError(L, "Get(string name) resources is empty!"); + return 0; + } int argc = wiLua::SGetArgCount(L); if (argc > 1) { @@ -38,6 +45,10 @@ int wiResourceManager_BindLua::Get(lua_State *L) { switch (data->type) { + case wiResourceManager::Data_Type::IMAGE: + Luna::push(L, new Texture_BindLua((wiRenderer::TextureView)data->data)); + return 1; + break; case wiResourceManager::Data_Type::MUSIC: case wiResourceManager::Data_Type::SOUND: Luna::push(L, new wiSound_BindLua((wiSound*)data->data)); @@ -62,6 +73,11 @@ int wiResourceManager_BindLua::Get(lua_State *L) } int wiResourceManager_BindLua::Add(lua_State *L) { + if (resources == nullptr) + { + wiLua::SError(L, "Get(string name) resources is empty!"); + return 0; + } int argc = wiLua::SGetArgCount(L); if (argc > 1) { @@ -87,6 +103,11 @@ int wiResourceManager_BindLua::Add(lua_State *L) } int wiResourceManager_BindLua::Del(lua_State *L) { + if (resources == nullptr) + { + wiLua::SError(L, "Get(string name) resources is empty!"); + return 0; + } int argc = wiLua::SGetArgCount(L); if (argc > 1) { @@ -102,6 +123,11 @@ int wiResourceManager_BindLua::Del(lua_State *L) } int wiResourceManager_BindLua::List(lua_State *L) { + if (resources == nullptr) + { + wiLua::SError(L, "Get(string name) resources is empty!"); + return 0; + } stringstream ss(""); for (auto& x : resources->resources) { @@ -116,6 +142,7 @@ void wiResourceManager_BindLua::Bind() static bool initialized = false; if (!initialized) { + Texture_BindLua::Bind(); Luna::Register(wiLua::GetGlobal()->GetLuaState()); wiLua::GetGlobal()->RegisterObject(className, "globalResources", new wiResourceManager_BindLua(wiResourceManager::GetGlobal())); initialized = true; diff --git a/WickedEngine/wiSound.cpp b/WickedEngine/wiSound.cpp index 4308124b6..57def510e 100644 --- a/WickedEngine/wiSound.cpp +++ b/WickedEngine/wiSound.cpp @@ -1,5 +1,4 @@ #include "wiSound.h" -#include "wiSound_BindLua.h" IXAudio2* wiSoundEffect::pXAudio2; IXAudio2MasteringVoice* wiSoundEffect::pMasterVoice; @@ -214,8 +213,6 @@ float wiSoundEffect::GetVolume(){ } HRESULT wiSoundEffect::Initialize() { - wiSound_BindLua::Bind(); - HRESULT hr; pXAudio2 = nullptr; if(FAILED( hr = XAudio2Create( &pXAudio2, 0, XAUDIO2_DEFAULT_PROCESSOR ) )) @@ -290,8 +287,6 @@ float wiMusic::GetVolume(){ } HRESULT wiMusic::Initialize() { - wiSound_BindLua::Bind(); - HRESULT hr; pXAudio2 = nullptr; if(FAILED( hr = XAudio2Create( &pXAudio2, 0, XAUDIO2_DEFAULT_PROCESSOR ) )) diff --git a/WickedEngine/wiSprite_BindLua.cpp b/WickedEngine/wiSprite_BindLua.cpp new file mode 100644 index 000000000..e8c3d8896 --- /dev/null +++ b/WickedEngine/wiSprite_BindLua.cpp @@ -0,0 +1,49 @@ +#include "wiSprite_BindLua.h" + +const char wiSprite_BindLua::className[] = "Sprite"; + +Luna::FunctionType wiSprite_BindLua::methods[] = { + { NULL, NULL } +}; +Luna::PropertyType wiSprite_BindLua::properties[] = { + { NULL, NULL } +}; + +wiSprite_BindLua::wiSprite_BindLua(wiSprite* sprite) :sprite(sprite) +{ +} + +wiSprite_BindLua::wiSprite_BindLua(lua_State *L) +{ + string name = "", mask = "", normal = ""; + int argc = wiLua::SGetArgCount(L); + if (argc > 0) + { + name = wiLua::SGetString(L, 1); + if (argc > 1) + { + mask = wiLua::SGetString(L, 2); + if (argc > 2) + { + normal = wiLua::SGetString(L, 3); + } + } + } + sprite = new wiSprite(name, mask, normal); +} + + +wiSprite_BindLua::~wiSprite_BindLua() +{ +} + +void wiSprite_BindLua::Bind() +{ + static bool initialized = false; + if (!initialized) + { + initialized = true; + Luna::Register(wiLua::GetGlobal()->GetLuaState()); + } +} + diff --git a/WickedEngine/wiSprite_BindLua.h b/WickedEngine/wiSprite_BindLua.h new file mode 100644 index 000000000..53430d7f4 --- /dev/null +++ b/WickedEngine/wiSprite_BindLua.h @@ -0,0 +1,21 @@ +#pragma once +#include "wiLua.h" +#include "wiLuna.h" +#include "wiSprite.h" + +class wiSprite_BindLua +{ +private: + wiSprite* sprite; +public: + static const char className[]; + static Luna::FunctionType methods[]; + static Luna::PropertyType properties[]; + + wiSprite_BindLua(wiSprite* sprite = nullptr); + wiSprite_BindLua(lua_State *L); + ~wiSprite_BindLua(); + + static void Bind(); +}; +