sound bind to lua

This commit is contained in:
turanszkij
2015-08-06 11:55:20 +02:00
parent 7b22a7a790
commit ec77b3de7c
8 changed files with 187 additions and 18 deletions
+2
View File
@@ -383,6 +383,7 @@
<ClCompile Include="RenderableComponent.cpp" />
<ClCompile Include="wiRenderer_BindLua.cpp" />
<ClCompile Include="wiResourceManager_BindLua.cpp" />
<ClCompile Include="wiSound_BindLua.cpp" />
<ClCompile Include="wiSprite.cpp" />
<ClCompile Include="wiParticle.cpp" />
<ClCompile Include="wiRenderer.cpp" />
@@ -664,6 +665,7 @@
<ClInclude Include="wiInitializer.h" />
<ClInclude Include="wiLua.h" />
<ClInclude Include="wiResourceManager_BindLua.h" />
<ClInclude Include="wiSound_BindLua.h" />
<ClInclude Include="wiStencilRef.h" />
<ClInclude Include="wiTextureHelper.h" />
<ClInclude Include="WickedEngine.h" />
@@ -740,6 +740,9 @@
<ClCompile Include="wiResourceManager_BindLua.cpp">
<Filter>ScriptBinders</Filter>
</ClCompile>
<ClCompile Include="wiSound_BindLua.cpp">
<Filter>ScriptBinders</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="typelib.h">
@@ -1654,6 +1657,9 @@
<ClInclude Include="wiLuna.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="wiSound_BindLua.h">
<Filter>ScriptBinders</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\io_export_wicked_wi_bin.py" />
+15 -10
View File
@@ -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)
+41 -7
View File
@@ -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<wiSound_BindLua>::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<wiResourceManager_BindLua>::Register(wiLua::GetGlobal()->GetLuaState());
wiLua::GetGlobal()->RegisterObject(className, "globalResources", wiResourceManager::GetGlobal());
static bool initialized = false;
if (!initialized)
{
Luna<wiResourceManager_BindLua>::Register(wiLua::GetGlobal()->GetLuaState());
wiLua::GetGlobal()->RegisterObject(className, "globalResources", wiResourceManager::GetGlobal());
initialized = true;
}
}
+5
View File
@@ -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 ) ))
+89
View File
@@ -0,0 +1,89 @@
#include "wiSound_BindLua.h"
const char wiSound_BindLua::className[] = "Sound";
Luna<wiSound_BindLua>::FunctionType wiSound_BindLua::methods[] = {
lunamethod(wiSound_BindLua, Play),
lunamethod(wiSound_BindLua, Stop),
{ NULL, NULL }
};
Luna<wiSound_BindLua>::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<wiSound_BindLua>::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;
}
+27
View File
@@ -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<wiSound_BindLua>::FunctionType methods[];
static Luna<wiSound_BindLua>::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);
};
+2 -1
View File
@@ -52,4 +52,5 @@ Screen Space Ambient Occlusion
Skin shader (Subsurface scattering approximation)
Stencil layering
Deferred decals
Color Grading
Color Grading
Lua Scripting