lua binding updated, maincomponent binding added

This commit is contained in:
turanszkij
2015-08-06 18:28:08 +02:00
parent 305cb8e3dd
commit 82452ad93c
11 changed files with 149 additions and 19 deletions
+8 -2
View File
@@ -6,7 +6,7 @@
#include "wiCpuInfo.h"
#include "wiInputManager.h"
#include "wiBackLog.h"
#include "MainComponent_BindLua.h"
MainComponent::MainComponent()
{
@@ -18,6 +18,8 @@ MainComponent::MainComponent()
setFrameSkip(true);
setTargetFrameRate(60);
setApplicationControlLostThreshold(10);
MainComponent_BindLua::Bind();
}
@@ -26,6 +28,11 @@ MainComponent::~MainComponent()
activeComponent->Unload();
}
void MainComponent::Initialize()
{
wiLua::GetGlobal()->RegisterObject(MainComponent_BindLua::className, "main", new MainComponent_BindLua(this));
}
void MainComponent::activateComponent(RenderableComponent* component)
{
if (component == nullptr)
@@ -41,7 +48,6 @@ void MainComponent::activateComponent(RenderableComponent* component)
void MainComponent::run()
{
static wiTimer timer = wiTimer();
static double accumulator = 0.0;
+1 -1
View File
@@ -33,7 +33,7 @@ public:
int getTargetFrameRate(){ return targetFrameRate; }
void setApplicationControlLostThreshold(int value){ applicationControlLostThreshold = value; }
virtual void Initialize(){};
virtual void Initialize();
virtual void Update();
virtual void Render();
virtual void Compose();
+75
View File
@@ -0,0 +1,75 @@
#include "MainComponent_BindLua.h"
#include "Renderable3DComponent_BindLua.h"
const char MainComponent_BindLua::className[] = "MainComponent";
Luna<MainComponent_BindLua>::FunctionType MainComponent_BindLua::methods[] = {
lunamethod(MainComponent_BindLua, GetActiveComponent),
lunamethod(MainComponent_BindLua, SetActiveComponent),
lunamethod(MainComponent_BindLua, SetFrameSkip),
{ NULL, NULL }
};
Luna<MainComponent_BindLua>::PropertyType MainComponent_BindLua::properties[] = {
{ NULL, NULL }
};
MainComponent_BindLua::MainComponent_BindLua(MainComponent* component) :component(component)
{
}
MainComponent_BindLua::MainComponent_BindLua(lua_State *L)
{
component = nullptr;
}
MainComponent_BindLua::~MainComponent_BindLua()
{
}
int MainComponent_BindLua::GetActiveComponent(lua_State *L)
{
Renderable3DComponent* comp = dynamic_cast<Renderable3DComponent*>(component->getActiveComponent());
if (comp != nullptr)
{
Luna<Renderable3DComponent_BindLua>::push(L, new Renderable3DComponent_BindLua(comp));
return 1;
}
wiLua::SError(L, "GetActiveComponent() Warning: type of active component not registered with lua!");
return 0;
}
int MainComponent_BindLua::SetActiveComponent(lua_State *L)
{
int argc = wiLua::SGetArgCount(L);
if (argc > 1)
{
//TODO
}
else
{
wiLua::SError(L, "SetActiveComponent(Renderable3DComponent component) not enought arguments!");
return 0;
}
return 0;
}
int MainComponent_BindLua::SetFrameSkip(lua_State *L)
{
int argc = wiLua::SGetArgCount(L);
if (argc > 1)
{
component->setFrameSkip(wiLua::SGetBool(L, 2));
}
else
wiLua::SError(L, "SetFrameSkip(bool enabled) not enought arguments!");
return 0;
}
void MainComponent_BindLua::Bind()
{
static bool initialized = false;
if (!initialized)
{
initialized = true;
Luna<MainComponent_BindLua>::Register(wiLua::GetGlobal()->GetLuaState());
}
}
+25
View File
@@ -0,0 +1,25 @@
#pragma once
#include "wiLua.h"
#include "wiLuna.h"
#include "MainComponent.h"
class MainComponent_BindLua
{
private:
MainComponent *component;
public:
static const char className[];
static Luna<MainComponent_BindLua>::FunctionType methods[];
static Luna<MainComponent_BindLua>::PropertyType properties[];
MainComponent_BindLua(MainComponent* component = nullptr);
MainComponent_BindLua(lua_State *L);
~MainComponent_BindLua();
int GetActiveComponent(lua_State *L);
int SetActiveComponent(lua_State *L);
int SetFrameSkip(lua_State *L);
static void Bind();
};
@@ -1,8 +1,10 @@
#include "Renderable3DComponent_BindLua.h"
#include "wiResourceManager_BindLua.h"
const char Renderable3DComponent_BindLua::className[] = "Renderable3DComponent";
Luna<Renderable3DComponent_BindLua>::FunctionType Renderable3DComponent_BindLua::methods[] = {
lunamethod(Renderable3DComponent_BindLua,GetContent),
{ NULL, NULL }
};
Luna<Renderable3DComponent_BindLua>::PropertyType Renderable3DComponent_BindLua::properties[] = {
@@ -22,6 +24,12 @@ Renderable3DComponent_BindLua::~Renderable3DComponent_BindLua()
{
}
int Renderable3DComponent_BindLua::GetContent(lua_State *L)
{
Luna<wiResourceManager_BindLua>::push(L, new wiResourceManager_BindLua(&component->Content));
return 1;
}
void Renderable3DComponent_BindLua::Bind()
{
static bool initialized = false;
@@ -16,6 +16,8 @@ public:
Renderable3DComponent_BindLua(lua_State* L);
~Renderable3DComponent_BindLua();
int GetContent(lua_State *L);
static void Bind();
};
+2
View File
@@ -210,6 +210,7 @@
<ClCompile Include="LUA\lzio.c" />
<ClCompile Include="MainComponent.cpp" />
<ClCompile Include="LoadingScreenComponent.cpp" />
<ClCompile Include="MainComponent_BindLua.cpp" />
<ClCompile Include="Renderable2DComponent.cpp" />
<ClCompile Include="Renderable3DComponent_BindLua.cpp" />
<ClCompile Include="wiBackLog.cpp" />
@@ -409,6 +410,7 @@
<ClCompile Include="wiXInput.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="MainComponent_BindLua.h" />
<ClInclude Include="Renderable3DComponent_BindLua.h" />
<ClInclude Include="wiLuna.h" />
<ClInclude Include="wiRenderer_BindLua.h" />
@@ -749,6 +749,9 @@
<ClCompile Include="Renderable3DComponent_BindLua.cpp">
<Filter>ScriptBinders</Filter>
</ClCompile>
<ClCompile Include="MainComponent_BindLua.cpp">
<Filter>ScriptBinders</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="typelib.h">
@@ -1669,6 +1672,9 @@
<ClInclude Include="Renderable3DComponent_BindLua.h">
<Filter>ScriptBinders</Filter>
</ClInclude>
<ClInclude Include="MainComponent_BindLua.h">
<Filter>ScriptBinders</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\io_export_wicked_wi_bin.py" />
+4 -3
View File
@@ -19,7 +19,6 @@ public:
COMPUTESHADER,
};
protected:
struct Resource
{
void* data;
@@ -27,13 +26,15 @@ protected:
Resource(void* newData, Data_Type newType) :data(newData), type(newType){};
};
typedef unordered_map<string, Resource*> container;
container resources;
protected:
typedef map<string,Data_Type> filetypes;
static filetypes types;
static wiResourceManager* globalResources;
static void SetUp();
typedef unordered_map<string,Resource*> container;
container resources;
public:
wiResourceManager();
+14 -12
View File
@@ -1,6 +1,5 @@
#include "wiResourceManager_BindLua.h"
#include "wiSound_BindLua.h"
#include "wiHelper.h"
@@ -17,9 +16,12 @@ Luna<wiResourceManager_BindLua>::PropertyType wiResourceManager_BindLua::propert
{ NULL, NULL }
};
wiResourceManager_BindLua::wiResourceManager_BindLua(wiResourceManager* resources) :resources(resources)
{
}
wiResourceManager_BindLua::wiResourceManager_BindLua(lua_State *L)
{
wiResourceManager::wiResourceManager();
resources = nullptr;
}
wiResourceManager_BindLua::~wiResourceManager_BindLua()
{
@@ -31,13 +33,13 @@ int wiResourceManager_BindLua::Get(lua_State *L)
if (argc > 1)
{
string name = wiLua::SGetString(L, 2);
const Resource* data = get(name);
const wiResourceManager::Resource* data = resources->get(name);
if (data != nullptr)
{
switch (data->type)
{
case Data_Type::MUSIC:
case Data_Type::SOUND:
case wiResourceManager::Data_Type::MUSIC:
case wiResourceManager::Data_Type::SOUND:
Luna<wiSound_BindLua>::push(L, new wiSound_BindLua((wiSound*)data->data));
return 1;
break;
@@ -64,16 +66,16 @@ int wiResourceManager_BindLua::Add(lua_State *L)
if (argc > 1)
{
string name = wiLua::SGetString(L, 2);
Data_Type type = Data_Type::DYNAMIC;
wiResourceManager::Data_Type type = wiResourceManager::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;
type = wiResourceManager::Data_Type::SOUND;
else if (!typeStr.compare("MUSIC"))
type = Data_Type::MUSIC;
type = wiResourceManager::Data_Type::MUSIC;
}
void* data = add(name, type);
void* data = resources->add(name, type);
wiLua::SSetString(L, (data != nullptr ? "ok" : "not found"));
return 1;
}
@@ -89,7 +91,7 @@ int wiResourceManager_BindLua::Del(lua_State *L)
if (argc > 1)
{
string name = wiLua::SGetString(L, 2);
wiLua::SSetString(L, (del(name) ? "ok" : "not found"));
wiLua::SSetString(L, (resources->del(name) ? "ok" : "not found"));
return 1;
}
else
@@ -102,7 +104,7 @@ int wiResourceManager_BindLua::List(lua_State *L)
{
stringstream ss("");
ss << "Resources of: " << wiLua::SGetString(L, 1) << endl;
for (auto& x : resources)
for (auto& x : resources->resources)
{
ss << x.first << endl;
}
@@ -116,7 +118,7 @@ void wiResourceManager_BindLua::Bind()
if (!initialized)
{
Luna<wiResourceManager_BindLua>::Register(wiLua::GetGlobal()->GetLuaState());
wiLua::GetGlobal()->RegisterObject(className, "globalResources", wiResourceManager::GetGlobal());
wiLua::GetGlobal()->RegisterObject(className, "globalResources", new wiResourceManager_BindLua(wiResourceManager::GetGlobal()));
initialized = true;
}
}
+4 -1
View File
@@ -5,13 +5,16 @@
//extends the resourcemanager to be accessed by lua scripts using the Luna wrapper
class wiResourceManager_BindLua:public wiResourceManager
class wiResourceManager_BindLua : public wiResourceManager
{
private:
wiResourceManager* resources;
public:
static const char className[];
static Luna<wiResourceManager_BindLua>::FunctionType methods[];
static Luna<wiResourceManager_BindLua>::PropertyType properties[];
wiResourceManager_BindLua(wiResourceManager* resources = nullptr);
wiResourceManager_BindLua(lua_State *L);
~wiResourceManager_BindLua();