diff --git a/WickedEngine/WickedEngine.vcxproj b/WickedEngine/WickedEngine.vcxproj
index 4f251ca00..f6625078b 100644
--- a/WickedEngine/WickedEngine.vcxproj
+++ b/WickedEngine/WickedEngine.vcxproj
@@ -383,6 +383,7 @@
+
@@ -664,6 +665,7 @@
+
diff --git a/WickedEngine/WickedEngine.vcxproj.filters b/WickedEngine/WickedEngine.vcxproj.filters
index bf2ef3e71..2b08b0a37 100644
--- a/WickedEngine/WickedEngine.vcxproj.filters
+++ b/WickedEngine/WickedEngine.vcxproj.filters
@@ -740,6 +740,9 @@
ScriptBinders
+
+ ScriptBinders
+
@@ -1654,6 +1657,9 @@
Header Files
+
+ ScriptBinders
+
diff --git a/WickedEngine/wiRenderer_BindLua.cpp b/WickedEngine/wiRenderer_BindLua.cpp
index 34b7edde8..5b1b5ecb4 100644
--- a/WickedEngine/wiRenderer_BindLua.cpp
+++ b/WickedEngine/wiRenderer_BindLua.cpp
@@ -8,17 +8,22 @@ namespace wiRenderer_BindLua
void Bind()
{
- wiLua::GetGlobal()->RegisterFunc("GetArmatures", GetArmatures);
- wiLua::GetGlobal()->RegisterFunc("GetObjects", GetObjects);
- wiLua::GetGlobal()->RegisterFunc("GetObjectProp", GetObjectProp);
- wiLua::GetGlobal()->RegisterFunc("GetMeshes", GetMeshes);
- wiLua::GetGlobal()->RegisterFunc("GetLights", GetLights);
- wiLua::GetGlobal()->RegisterFunc("GetMaterials", GetMaterials);
- wiLua::GetGlobal()->RegisterFunc("GetGameSpeed", GetGameSpeed);
- wiLua::GetGlobal()->RegisterFunc("GetMaterials", GetMaterials);
+ static bool initialized = false;
+ if (!initialized)
+ {
+ initialized = true;
+ wiLua::GetGlobal()->RegisterFunc("GetArmatures", GetArmatures);
+ wiLua::GetGlobal()->RegisterFunc("GetObjects", GetObjects);
+ wiLua::GetGlobal()->RegisterFunc("GetObjectProp", GetObjectProp);
+ wiLua::GetGlobal()->RegisterFunc("GetMeshes", GetMeshes);
+ wiLua::GetGlobal()->RegisterFunc("GetLights", GetLights);
+ wiLua::GetGlobal()->RegisterFunc("GetMaterials", GetMaterials);
+ wiLua::GetGlobal()->RegisterFunc("GetGameSpeed", GetGameSpeed);
+ wiLua::GetGlobal()->RegisterFunc("GetMaterials", GetMaterials);
- wiLua::GetGlobal()->RegisterFunc("SetObjectProp", SetObjectProp);
- wiLua::GetGlobal()->RegisterFunc("SetGameSpeed", SetGameSpeed);
+ wiLua::GetGlobal()->RegisterFunc("SetObjectProp", SetObjectProp);
+ wiLua::GetGlobal()->RegisterFunc("SetGameSpeed", SetGameSpeed);
+ }
}
int GetArmatures(lua_State* L)
diff --git a/WickedEngine/wiResourceManager_BindLua.cpp b/WickedEngine/wiResourceManager_BindLua.cpp
index aca883854..5a981d477 100644
--- a/WickedEngine/wiResourceManager_BindLua.cpp
+++ b/WickedEngine/wiResourceManager_BindLua.cpp
@@ -1,4 +1,7 @@
#include "wiResourceManager_BindLua.h"
+#include "wiSound_BindLua.h"
+
+#include "wiHelper.h"
const char wiResourceManager_BindLua::className[] = "Resource";
@@ -28,9 +31,26 @@ int wiResourceManager_BindLua::Get(lua_State *L)
if (argc > 1)
{
string name = wiLua::SGetString(L, 2);
- void* data = add(name);
- wiLua::SSetString(L, (data != nullptr ? "ok" : "not found"));
- return 1;
+ const Resource* data = get(name);
+ if (data != nullptr)
+ {
+ switch (data->type)
+ {
+ case Data_Type::MUSIC:
+ case Data_Type::SOUND:
+ Luna::push(L, new wiSound_BindLua((wiSound*)data->data));
+ return 1;
+ break;
+ default:
+ wiLua::SError(L, "Resource:Get(string name) resource type not supported!");
+ break;
+ }
+ }
+ else
+ {
+ wiLua::SError(L, "Resource:Get(string name) resource not found!");
+ }
+ return 0;
}
else
{
@@ -44,13 +64,22 @@ int wiResourceManager_BindLua::Add(lua_State *L)
if (argc > 1)
{
string name = wiLua::SGetString(L, 2);
- void* data = add(name);
+ Data_Type type = Data_Type::DYNAMIC;
+ if (argc > 2) //type info also provided in this case
+ {
+ string typeStr = wiHelper::toUpper( wiLua::SGetString(L, 3) );
+ if (!typeStr.compare("SOUND"))
+ type = Data_Type::SOUND;
+ else if (!typeStr.compare("MUSIC"))
+ type = Data_Type::MUSIC;
+ }
+ void* data = add(name, type);
wiLua::SSetString(L, (data != nullptr ? "ok" : "not found"));
return 1;
}
else
{
- wiLua::SError(L, "Resource:Add(string name) not enough arguments!");
+ wiLua::SError(L, "Resource:Add(string name, (opt) string type) not enough arguments!");
}
return 0;
}
@@ -83,7 +112,12 @@ int wiResourceManager_BindLua::List(lua_State *L)
void wiResourceManager_BindLua::Bind()
{
- Luna::Register(wiLua::GetGlobal()->GetLuaState());
- wiLua::GetGlobal()->RegisterObject(className, "globalResources", wiResourceManager::GetGlobal());
+ static bool initialized = false;
+ if (!initialized)
+ {
+ Luna::Register(wiLua::GetGlobal()->GetLuaState());
+ wiLua::GetGlobal()->RegisterObject(className, "globalResources", wiResourceManager::GetGlobal());
+ initialized = true;
+ }
}
diff --git a/WickedEngine/wiSound.cpp b/WickedEngine/wiSound.cpp
index 57def510e..4308124b6 100644
--- a/WickedEngine/wiSound.cpp
+++ b/WickedEngine/wiSound.cpp
@@ -1,4 +1,5 @@
#include "wiSound.h"
+#include "wiSound_BindLua.h"
IXAudio2* wiSoundEffect::pXAudio2;
IXAudio2MasteringVoice* wiSoundEffect::pMasterVoice;
@@ -213,6 +214,8 @@ float wiSoundEffect::GetVolume(){
}
HRESULT wiSoundEffect::Initialize()
{
+ wiSound_BindLua::Bind();
+
HRESULT hr;
pXAudio2 = nullptr;
if(FAILED( hr = XAudio2Create( &pXAudio2, 0, XAUDIO2_DEFAULT_PROCESSOR ) ))
@@ -287,6 +290,8 @@ 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/wiSound_BindLua.cpp b/WickedEngine/wiSound_BindLua.cpp
new file mode 100644
index 000000000..089b8c38d
--- /dev/null
+++ b/WickedEngine/wiSound_BindLua.cpp
@@ -0,0 +1,89 @@
+#include "wiSound_BindLua.h"
+
+
+const char wiSound_BindLua::className[] = "Sound";
+
+Luna::FunctionType wiSound_BindLua::methods[] = {
+ lunamethod(wiSound_BindLua, Play),
+ lunamethod(wiSound_BindLua, Stop),
+ { NULL, NULL }
+};
+Luna::PropertyType wiSound_BindLua::properties[] = {
+ { NULL, NULL }
+};
+
+wiSound_BindLua::wiSound_BindLua(wiSound* sound) :sound(sound)
+{
+}
+wiSound_BindLua::wiSound_BindLua(lua_State *L)
+{
+ sound = nullptr;
+}
+
+
+wiSound_BindLua::~wiSound_BindLua()
+{
+}
+
+int wiSound_BindLua::Play(lua_State* L)
+{
+ if (sound == nullptr)
+ {
+ wiLua::SError(L, "Play(int delay) sound resource not loaded!");
+ return 0;
+ }
+
+ int argc = wiLua::SGetArgCount(L);
+ if (argc > 0)
+ sound->Play((DWORD)wiLua::SGetInt(L, 2));
+ else
+ sound->Play();
+ return 0;
+}
+
+int wiSound_BindLua::Stop(lua_State *L)
+{
+ if (sound == nullptr)
+ {
+ wiLua::SError(L, "Stop() sound resource not loaded!");
+ return 0;
+ }
+
+ sound->Stop();
+ return 0;
+}
+
+void wiSound_BindLua::Bind()
+{
+ static bool initialized = false;
+ if (!initialized)
+ {
+ initialized = true;
+ Luna::Register(wiLua::GetGlobal()->GetLuaState());
+
+ wiLua::GetGlobal()->RegisterFunc("SoundVolume", SoundVolume);
+ wiLua::GetGlobal()->RegisterFunc("MusicVolume", MusicVolume);
+ }
+}
+
+int wiSound_BindLua::SoundVolume(lua_State *L)
+{
+ int argc = wiLua::SGetArgCount(L);
+ if (argc > 0)
+ {
+ wiSoundEffect::SetVolume(wiLua::SGetFloat(L, 1));
+ }
+ wiLua::SSetFloat(L, wiSoundEffect::GetVolume());
+ return 1;
+}
+int wiSound_BindLua::MusicVolume(lua_State *L)
+{
+ int argc = wiLua::SGetArgCount(L);
+ if (argc > 0)
+ {
+ wiMusic::SetVolume(wiLua::SGetFloat(L, 1));
+ }
+ wiLua::SSetFloat(L, wiMusic::GetVolume());
+ return 1;
+}
+
diff --git a/WickedEngine/wiSound_BindLua.h b/WickedEngine/wiSound_BindLua.h
new file mode 100644
index 000000000..e17d971c7
--- /dev/null
+++ b/WickedEngine/wiSound_BindLua.h
@@ -0,0 +1,27 @@
+#pragma once
+#include "wiLua.h"
+#include "wiLuna.h"
+#include "wiSound.h"
+
+class wiSound_BindLua
+{
+private:
+ wiSound* sound;
+public:
+ static const char className[];
+ static Luna::FunctionType methods[];
+ static Luna::PropertyType properties[];
+
+ wiSound_BindLua(wiSound* sound = nullptr);
+ wiSound_BindLua(lua_State *L);
+ ~wiSound_BindLua();
+
+ int Play(lua_State *L);
+ int Stop(lua_State *L);
+
+ static void Bind();
+
+ static int SoundVolume(lua_State *L);
+ static int MusicVolume(lua_State *L);
+};
+
diff --git a/features.txt b/features.txt
index bdab932e6..b28976c78 100644
--- a/features.txt
+++ b/features.txt
@@ -52,4 +52,5 @@ Screen Space Ambient Occlusion
Skin shader (Subsurface scattering approximation)
Stencil layering
Deferred decals
-Color Grading
\ No newline at end of file
+Color Grading
+Lua Scripting
\ No newline at end of file