aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlexander Pickering <alexandermpickering@gmail.com>2017-12-26 00:57:52 -0500
committerAlexander Pickering <alexandermpickering@gmail.com>2017-12-26 00:57:52 -0500
commit35b7c646fd7f80b64c1ef49b6d81f9df9bc1b940 (patch)
treed345f620b51ae1ad1d7923e572a6b07ed8731ee5 /src
parentcc12503339004bae2f945e7f7339fc845b2a194f (diff)
downloadbrokengine-35b7c646fd7f80b64c1ef49b6d81f9df9bc1b940.tar.gz
brokengine-35b7c646fd7f80b64c1ef49b6d81f9df9bc1b940.tar.bz2
brokengine-35b7c646fd7f80b64c1ef49b6d81f9df9bc1b940.zip
Major update
Diffstat (limited to 'src')
-rw-r--r--src/client/callbackhandeler.cpp61
-rw-r--r--src/client/lua_api/gui/iguicheckbox.cpp55
-rw-r--r--src/client/lua_api/gui/iguicheckbox.hpp10
-rw-r--r--src/client/lua_api/gui/iguiwindow.cpp133
-rw-r--r--src/client/lua_api/guiparts.hpp1
-rw-r--r--src/client/lua_api/load_gui.cpp6
-rw-r--r--src/client/lua_api/load_scene.cpp16
-rw-r--r--src/client/lua_api/phys/bphysbox.cpp49
-rw-r--r--src/client/lua_api/phys/cbphysbox.cpp93
-rw-r--r--src/client/lua_api/scene/icamera.cpp76
-rw-r--r--src/client/lua_api/scene/icamera.hpp2
-rw-r--r--src/client/lua_api/scene/icube.cpp68
-rw-r--r--src/client/lua_api/scene/icube.hpp11
-rw-r--r--src/client/lua_api/scene/igeneric.cpp80
-rw-r--r--src/client/lua_api/scene/igeneric.hpp3
-rw-r--r--src/client/lua_api/scene/ilight.cpp96
-rw-r--r--src/client/lua_api/scene/ilight.hpp2
-rw-r--r--src/client/lua_api/scene/imesh.cpp162
-rw-r--r--src/client/lua_api/scene/imesh.hpp5
-rw-r--r--src/client/main.cpp162
-rw-r--r--src/shared/lua_api/common.c47
-rw-r--r--src/shared/lua_api/common.h3
-rw-r--r--src/shared/lua_api/irr/cubenode.cpp6
-rw-r--r--src/shared/lua_api/irr/cubenode.hpp6
-rw-r--r--src/shared/lua_api/load_scene.cpp11
-rw-r--r--src/shared/lua_api/load_scene.hpp8
-rw-r--r--src/shared/lua_api/phys/bphysbox.cpp30
-rw-r--r--src/shared/lua_api/phys/bphysbox.hpp2
28 files changed, 712 insertions, 492 deletions
diff --git a/src/client/callbackhandeler.cpp b/src/client/callbackhandeler.cpp
index 59b5bee..c548624 100644
--- a/src/client/callbackhandeler.cpp
+++ b/src/client/callbackhandeler.cpp
@@ -30,32 +30,47 @@ GlobalEventReceiver::GlobalEventReceiver(IrrlichtDevice* d){
//device = d;
}
bool GlobalEventReceiver::OnEvent(const SEvent& e){
- EEVENT_TYPE type = e.EventType;
+ EEVENT_TYPE type = e.EventType;
switch (type){
case EET_GUI_EVENT:{
- IGUIElement* caller = e.GUIEvent.Caller;
- EGUI_EVENT_TYPE get = e.GUIEvent.EventType;
- printf("detected gui event: %d\n",get);
- bool callerregistered = guifuncs.find(caller) != guifuncs.end();
- bool callerhasfunc = guifuncs[caller].find(get) != guifuncs[caller].end();
- if (callerregistered && callerhasfunc){
- return guifuncs[caller][get](e);
- }
- return false;
- break;
+ IGUIElement* caller = e.GUIEvent.Caller;
+ EGUI_EVENT_TYPE get = e.GUIEvent.EventType;
+ printf("detected gui event: %d\n",get);
+ bool callerregistered = guifuncs.find(caller) != guifuncs.end();
+ bool callerhasfunc = guifuncs[caller].find(get) != guifuncs[caller].end();
+ if (callerregistered && callerhasfunc){
+ return guifuncs[caller][get](e);
+ }
+ return false;
+ break;
+ }
+ case EET_MOUSE_INPUT_EVENT:{
+ SEvent::SMouseInput se = e.MouseInput;
+ //printf("X: %d Y: %d\n",se.X, se.Y);
+
+ lua_getglobal(L,"GAME");
+ lua_getfield(L,-1,"onMouseMove");
+ if(!lua_isnil(L,-1)){
+ lua_pushnumber(L,se.X);
+ lua_pushnumber(L,se.Y);
+ lua_call(L,2,0);
+ }
+ break;
+ }
+ case EET_KEY_INPUT_EVENT:{
+ printf("Got input event\n");
+ SEvent::SKeyInput se = e.KeyInput;
+ lua_getglobal(L,"GAME");//{}
+ lua_getfield(L,-1,"onKeyDown");//{},()|nil
+ if(!lua_isnil(L,-1)){
+ lua_pushnumber(L,se.Key);
+ lua_pushboolean(L,se.PressedDown);
+ lua_pushboolean(L,se.Control);
+ lua_pushboolean(L,se.Shift);
+ lua_call(L,4,0);
+ }
+ break;
}
- case EET_MOUSE_INPUT_EVENT:{
- SEvent::SMouseInput se = e.MouseInput;
- //printf("X: %d Y: %d\n",se.X, se.Y);
-
- lua_getglobal(L,"GAME");
- lua_getfield(L,-1,"onMouseMove");
- if(!lua_isnil(L,-1)){
- lua_pushnumber(L,se.X);
- lua_pushnumber(L,se.Y);
- lua_call(L,2,0);
- }
- }
default:
//printf("Called an unknown event\n");
return false;
diff --git a/src/client/lua_api/gui/iguicheckbox.cpp b/src/client/lua_api/gui/iguicheckbox.cpp
new file mode 100644
index 0000000..c6e5955
--- /dev/null
+++ b/src/client/lua_api/gui/iguicheckbox.cpp
@@ -0,0 +1,55 @@
+/*This file defines some things that all igui stuff can do*/
+extern "C" {
+ #include <lua.h>
+ #include <lauxlib.h>
+ #include <lualib.h>
+}
+#include <irrlicht.h>
+#include "../guiparts.hpp"
+#include "iguielement.hpp"
+#include "../../../shared/lua_api/common.h"
+
+using namespace irr;
+using namespace core;
+
+extern IrrlichtDevice* device;
+
+//new({startx,starty},{endx,endy},"checkbox_name",parent)
+int newiguicheckbox(lua_State* L){
+ int parentid = lua_tointeger(L,-1);
+ lua_pop(L,1);//{startx,starty},{endx,endy},"checkbox_name"
+ const char* text = lua_tostring(L,-1);
+ int tlen = strlen(text);
+ lua_pop(L,1);//{startx,starty},{endx,endy}
+ long startx,starty,endx,endy;
+ popvector2i(L,&endx,&endy);//{startx,starty}
+ popvector2i(L,&startx, &starty);//
+ irr::gui::IGUICheckBox* cb = device->getGUIEnvironment()->addCheckBox(false,core::rect<int>(startx,starty,endx,endy),0,-1,stringw(text).c_str());
+ lua_pushlightuserdata(L,cb);//*checkbox
+ luaL_getmetatable(L,"gui.checkbox");//*checkbox,m{gui.checkbox}
+ lua_setmetatable(L,-2);//*checkbox
+
+ return 1;
+}
+
+static const luaL_reg iguicheckbox_m[] = {
+ {"move", moveiguielement},
+ {"setText", setiguitext},
+ {"remove", guisethandeler},
+ {0,0},
+};
+
+int iguicheckbox_register(lua_State* L){//
+
+ luaL_newmetatable(L,"gui.checkbox");//m{gui.checkbox}
+ luaL_register(L,NULL,iguicheckbox_m);
+ lua_pop(L,1);//
+
+ lua_getglobal(L,"gui");//{gui}
+ lua_pushstring(L,"newcheckbox");//{gui},new(),"newcheckbox"
+ lua_pushcfunction(L,newiguicheckbox);//{gui},new()
+ printf("I have registered the newcheckbox function\n");
+ lua_settable(L,-3);//{gui}
+ lua_pop(L,1);
+ return 0;
+}
diff --git a/src/client/lua_api/gui/iguicheckbox.hpp b/src/client/lua_api/gui/iguicheckbox.hpp
new file mode 100644
index 0000000..ee2f2bc
--- /dev/null
+++ b/src/client/lua_api/gui/iguicheckbox.hpp
@@ -0,0 +1,10 @@
+#include <stdio.h>
+#include <stdlib.h>
+extern "C" {
+ #include <lua.h>
+ #include <lauxlib.h>
+ #include <lualib.h>
+}
+#include <irrlicht.h>
+
+int iguicheckbox_register(lua_State* L);
diff --git a/src/client/lua_api/gui/iguiwindow.cpp b/src/client/lua_api/gui/iguiwindow.cpp
index 34b6cfa..038c9f7 100644
--- a/src/client/lua_api/gui/iguiwindow.cpp
+++ b/src/client/lua_api/gui/iguiwindow.cpp
@@ -15,6 +15,7 @@ extern "C" {
#include "iguiwindow.hpp"
#include "iguiutil.hpp"
#include "../../callbackhandeler.hpp"
+#include "../../../shared/lua_api/common.h"
using namespace irr;
using namespace gui;
@@ -58,110 +59,84 @@ static bool iguiwindowevent(irr::SEvent e){
return false;
}
+//new({posx,posy},{width,height}[,"title"][,parent])
static int newiguiwindow(lua_State* L){
- printf("Createing label!\n");
- int nargs = lua_gettop(L);
- //The position of the text
+ printf("Creating window\n");
- //Frame position
- int x,y;
- lua_popvector2i(L,1,&x,&y);
-
- printf("got xy\n");
+ int parentid = lua_tointeger(L,-1);
+ lua_pop(L,1);
+ const char* title_c = lua_tostring(L,-1);
+ const wchar_t* title_w = irr::core::stringw(title_c).c_str();
+ lua_pop(L,1);
- //Frame size
- int w,h;
- lua_popvector2i(L,2,&w,&h);
+ //Frame position
+ long x,y,w,h;
+ popvector2i(L,&x,&y);
+ popvector2i(L,&w,&h);
printf("I want to make a frame at (%d,%d) size (%d,%d)\n",x,y,w,h);
-
- // int startx = luaL_optint(L,1,0);
- // int starty = luaL_optint(L,2,0);
- // int endx = luaL_optint(L,3,startx+100);
- // int endy = luaL_optint(L,4,starty+100);
-
- //Label
- wchar_t* label;
- const char* labelopt = luaL_optstring(L,3,"Label");
- int bls = strlen(labelopt);
- label = (wchar_t*)calloc(sizeof(wchar_t),(bls));
- mbstowcs(label,labelopt,bls);
- printf("Got the string option\n");
- //
- //If the element has a parrent
- int parent = luaL_optint(L,4,0);
- //
- //
- // //Create the button
+
+ //Create the window
IGUIEnvironment* env = guidevice->getGUIEnvironment();
IGUIWindow* wi = env->addWindow(
core::rect<s32>(x,y,x+w,y+h),
false,
- label,
- guielements[parent],
+ title_w,
+ guielements[parentid],
-1
);
- // /Create the label
- // IGUIStaticText* llabel = (IGUIStaticText*) env->addStaticText(label,core::rect<s32>(startx,starty,endx,endy),false,false, guielements[parent], gui_elenum++, false);
- // printf("Created the button\n");
- //
- // /Register it's callback
+
+ lua_newtable(L);//{}
+ lua_pushlightuserdata(L,wi);
+ lua_setfield(L,-2,"element");
+
+ luaL_getmetatable(L,"gui.window");
+ lua_setmetatable(L,-2);
+
registerguicallback(wi,EGET_ELEMENT_CLOSED,iguiwindowevent);
- //
- //Create it's lua representation
- LIGUIElement* lwindow = (LIGUIElement*)lua_newuserdata(L, sizeof(LIGUIElement));
- int tref = luaL_ref(L,LUA_REGISTRYINDEX);
- iguielements[wi] = tref;
- lua_rawgeti(L,LUA_REGISTRYINDEX,tref);//Put it back on the stack since luaL_ref pops the object.
- //
- //Set it's metatable
- luaL_getmetatable(L, "gui.iguiwindow");
- lua_setmetatable(L, -2);
- //
- //Create the struct
- lwindow->e = wi;
- lwindow->funcmap = hashmap_new();
- lwindow->type = "iguiwindow";
- //
- // /Free up anything made in this function
- free(label);
- //
- // /Put it on top and return it
- lua_rawgeti(L,LUA_REGISTRYINDEX,tref);
- return 1;
+ return 1;
}
static const luaL_reg iguiwindow_f[] = {
- {"new", newiguiwindow},
- {"gethandeler", guigethandeler},
- {"sethandeler", guisethandeler},
- {0,0},
+ {"new", newiguiwindow},
+ {0,0},
};
static const luaL_reg iguiwindow_m[] = {
- {"move", moveiguielement},
- {"settext", setiguitext},
- {"remove", removeiguielement},
- {0, 0},
+ {"move", moveiguielement},
+ {"settext", setiguitext},
+ {"remove", removeiguielement},
+ {0, 0},
};
int iguiwindow_register(lua_State* L, IrrlichtDevice* d){
+ printf("Loading window\n");
+ luaL_newmetatable(L,"gui.window");//m{gui.checkbox}
+ luaL_register(L,NULL,iguiwindow_m);
+ lua_pop(L,1);//
+
+ lua_getglobal(L,"gui");
+ lua_pushstring(L,"newwindow");
+ lua_pushcfunction(L,newiguiwindow);
+ lua_settable(L,-3);
+ lua_pop(L,1);
- luaL_newmetatable(L, "gui.iguiwindow");
+ return 0;
+ //luaL_newmetatable(L, "gui.iguiwindow");
- luaL_register(L,"iguiwindow",iguiwindow_f);
+ //luaL_register(L,"iguiwindow",iguiwindow_f);
- lua_pushstring(L,"__index");
- lua_pushstring(L,"gethandeler");
- lua_gettable(L,-3);
- lua_settable(L,-4);
+ //lua_pushstring(L,"__index");
+ //lua_pushstring(L,"gethandeler");
+ //lua_gettable(L,-3);
+ //lua_settable(L,-4);
- lua_pushstring(L,"__newindex");
- lua_pushstring(L,"sethandeler");
- lua_gettable(L,-3);
- lua_settable(L,-4);
+ //lua_pushstring(L,"__newindex");
+ //lua_pushstring(L,"sethandeler");
+ //lua_gettable(L,-3);
+ //lua_settable(L,-4);
- luaL_register(L, NULL, iguiwindow_m);
+ //luaL_register(L, NULL, iguiwindow_m);
- return 1;
+ //return 1;
}
diff --git a/src/client/lua_api/guiparts.hpp b/src/client/lua_api/guiparts.hpp
index fba3862..ea369b7 100644
--- a/src/client/lua_api/guiparts.hpp
+++ b/src/client/lua_api/guiparts.hpp
@@ -20,7 +20,6 @@ typedef struct LIGUIElement {
const char* type;
} LIGUIElement;
-
extern lua_State* tL;
extern irr::IrrlichtDevice* guidevice;
extern long gui_elenum;
diff --git a/src/client/lua_api/load_gui.cpp b/src/client/lua_api/load_gui.cpp
index a282d34..f8e8dc0 100644
--- a/src/client/lua_api/load_gui.cpp
+++ b/src/client/lua_api/load_gui.cpp
@@ -14,6 +14,7 @@ extern "C" {
#include "gui/iguigeneric.hpp"
#include "gui/iguiwindow.hpp"
#include "gui/iguiskin.hpp"
+#include "gui/iguicheckbox.hpp"
#include "../callbackhandeler.hpp"
#include "guiparts.hpp"
@@ -42,7 +43,6 @@ void load_guifuncs(lua_State* L){
iguibutton_register(L,device);
iguilabel_register(L,device);
iguigeneric_register(L,device);
- iguiwindow_register(L,device);
lua_pop(L, 1);
//Various enums
@@ -50,7 +50,9 @@ void load_guifuncs(lua_State* L){
lua_newtable(L);
lua_setglobal(L,"gui");
-
+ iguicheckbox_register(L);
+ iguiwindow_register(L,device);
+
lua_pushcfunction(L,screenwidth);
lua_setglobal(L,"scrw");
diff --git a/src/client/lua_api/load_scene.cpp b/src/client/lua_api/load_scene.cpp
index 6d02a2d..342bc9a 100644
--- a/src/client/lua_api/load_scene.cpp
+++ b/src/client/lua_api/load_scene.cpp
@@ -21,13 +21,17 @@ extern IrrlichtDevice* device;
void load_scenefuncs(lua_State* L){
lua_newtable(L);//{}
lua_setglobal(L,"scene");//
- icamera_register(L,device);
-
- imesh_register(L,device);
- ilight_register(L,device);
- lua_newtable(L);
- lua_setglobal(L,"phys");
+
+ //scene things
+ icamera_register(L);
+ imesh_register(L);
+ ilight_register(L);
+
+ lua_newtable(L);//{}
+ lua_setglobal(L,"phys");//
+ //phys things
cbphysbox_register(L);
+
bphysmodel_register(L,device);
//lua_pop(L, 1);
diff --git a/src/client/lua_api/phys/bphysbox.cpp b/src/client/lua_api/phys/bphysbox.cpp
deleted file mode 100644
index c15646f..0000000
--- a/src/client/lua_api/phys/bphysbox.cpp
+++ /dev/null
@@ -1,49 +0,0 @@
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <list>
-extern "C" {
- #include <lua.h>
- #include <lauxlib.h>
- #include <lualib.h>
-}
-
-#include <btBulletDynamicsCommon.h>
-#include <irrlicht.h>
-#include "bphysbox.hpp"
-#include "../../../shared/lua_api/phys/bphysbox.hpp"
-
-using namespace irr;
-using namespace scene;
-using namespace core;
-using namespace video;
-
-extern IrrlichtDevice* device;
-
-extern btDiscreteDynamicsWorld* World;
-extern std::list<btRigidBody*> Objects;
-/*
-static LBPhysNode* checkisbphysbox(lua_State* L, int index){
- void* ud = luaL_checkudata(L,index,"phys.physbox");
- luaL_argcheck(L,ud != NULL, index, "'phys.physbox' expected");
- return (LBPhysNode*) ud;
-}
-*/
-
-/*
-static LISceneNode* checkismesh(lua_State* L){
- return checkismesh(L,1);
-}
-*/
-
-//phys.newphysbox({vector3 size},{vector3 origin},mass)
-/*
-static int newcbphysbox(lua_State* L){//
- newbphysbox(L);//{phys.physbox}
- LBPhysNode
-}
-*/
-
-void cbphysbox_register(lua_State* L){
- bphysbox_register(L);
-}
diff --git a/src/client/lua_api/phys/cbphysbox.cpp b/src/client/lua_api/phys/cbphysbox.cpp
index 0da9939..029e6ab 100644
--- a/src/client/lua_api/phys/cbphysbox.cpp
+++ b/src/client/lua_api/phys/cbphysbox.cpp
@@ -11,6 +11,7 @@ extern "C" {
#include <btBulletDynamicsCommon.h>
#include <irrlicht.h>
#include "cbphysbox.hpp"
+#include "../scene/imesh.hpp"
#include "../../../shared/lua_api/phys/bphysbox.hpp"
using namespace irr;
@@ -22,6 +23,7 @@ extern IrrlichtDevice* device;
extern btDiscreteDynamicsWorld* World;
extern std::list<btRigidBody*> Objects;
+
/*
static LBPhysNode* checkisbphysbox(lua_State* L, int index){
void* ud = luaL_checkudata(L,index,"phys.physbox");
@@ -37,13 +39,94 @@ static LISceneNode* checkismesh(lua_State* L){
*/
//phys.newphysbox({vector3 size},{vector3 origin},mass)
-/*
static int newcbphysbox(lua_State* L){//
- newbphysbox(L);//{phys.physbox}
- LBPhysNode
+ printf("Createing new cbphysbox\n");
+ double sx,sy,sz,x,y,z,mass;
+ //Get the data
+ mass = lua_tonumber(L,-1);//{v3 size}, {v3 origin}, mass
+ lua_pop(L,1);//{v3 size}, {v3 origin}
+ popvector3d(L,&x,&y,&z);//{v3 size}
+ popvector3d(L,&sx,&sy,&sz);//
+
+ pushvector3d(L,sx,sy,sz);//{v3 size}
+ pushvector3d(L,x,y,z);//{v3 size},{v3 origin}
+ lua_pushnumber(L,mass);//{v3 size}, {v3 origin}, mass
+ makenewbphysbox(L);//ud_btRigidbody
+ btRigidBody* r = (btRigidBody*)lua_touserdata(L,-1);//ud_btRigidbody
+ lua_pop(L,1);
+
+ pushvector3d(L,sx,sy,sz);//{v3 size}
+ pushvector3d(L,x,y,z);//{v3 size},{v3 origin}
+ makenewiscenecube(L);//ud_iscenenode
+ ISceneNode* n = (ISceneNode*)lua_touserdata(L,-1);//ud_iscenenode
+ lua_pop(L,1);
+
+ lua_newtable(L);//{}
+ lua_pushlightuserdata(L,r);//{},ud_rigidbody
+ lua_setfield(L,-2,"rigidbody");//{}
+ lua_pushlightuserdata(L,n);//{},ud_iscenenode
+ lua_setfield(L,-2,"node");//{}
+
+ luaL_getmetatable(L,"phys.physbox");//{},{phys.physbox}
+ lua_setmetatable(L,-2);//{}
+
+ return 1;
}
-*/
+
+//bphysbox:setpos({v3 pos})
+int cbphyssetpos(lua_State* L){//{rigidbody=ud_btRigidbody,node=ud_iscenenode},{v3 pos}
+ printf("calling cbphysbox setpos\n");
+ double x,y,z;
+ popvector3d(L,&x,&y,&z);//{rigidbody=ud_btRigidbody,node=ud_iscenenode}
+
+ printf("Getting rigidbody\n");
+ lua_getfield(L,-1,"rigidbody");//{rigidbody=ud_btRigidbody,node=ud_iscenenode},ud_btRigidbody
+ btRigidBody* r = (btRigidBody*)lua_touserdata(L,-1);//{rigidbody=ud_btRigidbody,node=ud_iscenenode},ud_btRigidbody
+ printf("Got rigidbody, it was %p\n",r);
+ lua_pop(L,1);//{rigidbody=ud_btRigidbody,node=ud_iscenenode}
+ lua_getfield(L,-1,"node");//{rigidbody=ud_btRigidbody,node=ud_iscenenode},ud_iscenenode
+ ISceneNode* i = (ISceneNode*)lua_touserdata(L,-1);//{btRigidBody=ud_btRigidbody,node=ud_iscenenode},ud_iscenenode
+ printf("Got node, it was %p\n",i);
+ lua_pop(L,2);//
+
+ btTransform bt;
+ btMotionState* ms = r->getMotionState();
+ ms->getWorldTransform(bt);
+ bt.setOrigin(btVector3(x,y,z));
+ ms->setWorldTransform(bt);
+ r->activate();
+
+ i->setPosition(vector3df(x,y,z));
+ i->updateAbsolutePosition();
+
+ return 0;
+
+}
+
+static const luaL_reg cbphysbox_m[] = {
+ {"setcpos", cbphyssetpos},//overload
+// {"delete", delbphysbox},//client side delete needs to delete the visual representation
+ {0, 0},
+};
void cbphysbox_register(lua_State* L){
- bphysbox_register(L);
+ bphysbox_register(L);//
+ lua_getglobal(L,"phys");//{}
+ lua_pushcfunction(L,newcbphysbox);//{},newcbphysbox()
+ lua_setfield(L,-2,"newcphysbox");//{}
+
+ lua_pop(L,1);//
+
+ luaL_getmetatable(L,"phys.physbox");//phys.physbox
+ lua_newtable(L);//phys.physbox,{}
+ luaL_register(L,NULL,cbphysbox_m);//phys.physbox,{}
+ lua_setfield(L,-2,"__index");//phys.physbox
+
+ lua_pop(L,1);
+
+ printf("When registering physbox, new() is %p\n",newcbphysbox);
+ printf("setpos is %p\n",cbphyssetpos);
+
+ lua_pop(L,1);
+
}
diff --git a/src/client/lua_api/scene/icamera.cpp b/src/client/lua_api/scene/icamera.cpp
index 14f9283..3c5e2b0 100644
--- a/src/client/lua_api/scene/icamera.cpp
+++ b/src/client/lua_api/scene/icamera.cpp
@@ -21,7 +21,6 @@ using namespace core;
extern IrrlichtDevice* device;
-
static LISceneNode* checkiscenecamera(lua_State* L, int index){
void* ud = luaL_checkudata(L,index,"scene.iscenecamera");
luaL_argcheck(L,ud != NULL, index, "'scene.iscenecamera' expected");
@@ -46,49 +45,51 @@ static LISceneNode* checkismayacamera(lua_State* L){
*/
static int newiscenemayacamera(lua_State* L){
- printf("createing maya camera!\n");
- ISceneManager* smgr = device->getSceneManager();
- ICameraSceneNode* cam = smgr->addCameraSceneNodeMaya();
- printf("cam is %p",cam);
- LISceneNode* lcam = (LISceneNode*)lua_newuserdata(L, sizeof(LISceneNode));
- int tref = luaL_ref(L,LUA_REGISTRYINDEX);
-
- //Set it's metatable
- luaL_getmetatable(L, "scene.iscenemayacamera");
- lua_setmetatable(L, -2);
-
- //Create the struct
- lcam->n = cam;
- lcam->funcmap = hashmap_new();
- lcam->type = "iscenemayacamera";
-
- //Free up anything made in this function
- //free(label);
-
- //Put it on top and return it
- lua_rawgeti(L,LUA_REGISTRYINDEX,tref);
- return 1;
+ printf("createing maya camera!\n");
+ ISceneManager* smgr = device->getSceneManager();
+ ICameraSceneNode* cam = smgr->addCameraSceneNodeMaya();
+ printf("cam is %p",cam);
+ lua_newtable(L);//{}
+ lua_pushlightuserdata(L,cam);
+ lua_setfield(L,-2,"node");
+ //LISceneNode* lcam = (LISceneNode*)lua_newuserdata(L, sizeof(LISceneNode));
+ //int tref = luaL_ref(L,LUA_REGISTRYINDEX);
+
+ //Set it's metatable
+ luaL_getmetatable(L, "scene.iscenemayacamera");
+ lua_setmetatable(L, -2);
+
+ //Create the struct
+ //lcam->n = cam;
+ //lcam->funcmap = hashmap_new();
+ //lcam->type = "iscenemayacamera";
+
+ //Free up anything made in this function
+ //free(label);
+
+ //Put it on top and return it
+ //lua_rawgeti(L,LUA_REGISTRYINDEX,tref);
+ return 1;
}
// ifpscamera.new()
static int newiscenefpscamera(lua_State* L){//
ISceneManager* smgr = device->getSceneManager();
ICameraSceneNode* cam = smgr->addCameraSceneNodeFPS();
- LISceneNode* lcam = (LISceneNode*)lua_newuserdata(L, sizeof(LISceneNode));//userdata_scenenode
- int tref = luaL_ref(L,LUA_REGISTRYINDEX);//
- lua_rawgeti(L,LUA_REGISTRYINDEX,tref);//userdata_scenenode
+ lua_newtable(L);//{}
+ lua_pushlightuserdata(L,cam);//{},ud_cam
+ lua_setfield(L,-2,"node");
+ //LISceneNode* lcam = (LISceneNode*)lua_newuserdata(L, sizeof(LISceneNode));//userdata_scenenode
//Set it's metatable
luaL_getmetatable(L, "scene.ifpscamera");//userdata_scenenode,scene.ifpscamera
lua_setmetatable(L, -2);//userdata_scenenode
//Create the struct
- lcam->n = cam;
- lcam->funcmap = hashmap_new();
- lcam->type = "iscenefpscamera";
+ //lcam->n = cam;
+ //lcam->funcmap = hashmap_new();
+ //lcam->type = "iscenefpscamera";
- //Put it on top and return it
- //lua_rawgeti(L,LUA_REGISTRYINDEX,tref);
return 1;
}
@@ -154,9 +155,10 @@ static int newiscenecamera(lua_State* L){
}
static const luaL_reg icamera_m[] = {
- {"getpos", iscenegetpos},
- {"setpos", iscenesetpos},
-// {"remove", removeiguielement},
+ {"getpos", iscenegetpos},
+ {"setpos", iscenesetpos},
+ {"getangle", iscenegetangle},
+ {"setangle", iscenesetangle},
{0, 0},
};
@@ -168,8 +170,7 @@ static const luaL_reg ifpscamera_m[] = {
{0,0},
};
-void icamera_register(lua_State* L, IrrlichtDevice* d){
- device = d;
+void icamera_register(lua_State* L){
luaL_newmetatable(L, "scene.icamera");//scene.icamera
lua_newtable(L);//scene.icamera, {}
@@ -180,6 +181,7 @@ void icamera_register(lua_State* L, IrrlichtDevice* d){
luaL_newmetatable(L, "scene.imayacamera");//scene.imayacamera
lua_newtable(L);//scene.imayascamera,{}
luaL_register(L,NULL,imayacamera_m);//scene.imayascamera,{}
+ luaL_register(L,NULL,icamera_m);//scene.imayascamera,{}
lua_setfield(L,-2,"__index");//scene.imayascamera
lua_pop(L,1);//
@@ -198,5 +200,5 @@ void icamera_register(lua_State* L, IrrlichtDevice* d){
lua_pushcfunction(L,newiscenemayacamera);//{},newiscenemayacamera()
lua_setfield(L,-2,"newmayacamera");//{}
printf("\"scene\" was set!\n");
- //lua_pop(L,1);
+ lua_pop(L,1);//
}
diff --git a/src/client/lua_api/scene/icamera.hpp b/src/client/lua_api/scene/icamera.hpp
index 38874e3..ada1e98 100644
--- a/src/client/lua_api/scene/icamera.hpp
+++ b/src/client/lua_api/scene/icamera.hpp
@@ -8,4 +8,4 @@ extern "C" {
}
#include <irrlicht.h>
-void icamera_register(lua_State* L, irr::IrrlichtDevice* d);
+void icamera_register(lua_State* L);
diff --git a/src/client/lua_api/scene/icube.cpp b/src/client/lua_api/scene/icube.cpp
new file mode 100644
index 0000000..d18db2a
--- /dev/null
+++ b/src/client/lua_api/scene/icube.cpp
@@ -0,0 +1,68 @@
+
+extern "C" {
+ #include <lua.h>
+ #include <lauxlib.h>
+ #include <lualib.h>
+}
+#include <irrlicht.h>
+
+extern IrrlichtDevice* device;
+
+using namespace irr;
+
+// {} :: scene.newcube(num_size, {v3 pos})
+int newiscenecube(lua_StatE* L){//num_size, {v3 pos}
+ double x,y,z;
+ popvector3d(L,&x, &y, &z);//num_size
+ double size = lua_tonumber(L,-1);//num_size
+ lua_pop(L,1);//
+ IMeshSceneNode* n = device->getSceneManager()->addCubeSceneNode(size,0,-1,core::vector3df(x,y,z));
+
+ lua_newtable(L);//{}
+ lua_pushlightuserdata(L,n);//{},ud_node
+ lua_setfield(L,-2,"node");//{}
+
+ luaL_getmetatable(L,"scene.inode");//{},sene.inode
+ lua_setmetatable(L,-2);
+
+ return 1;
+}
+
+static const luaL_reg iscenenode_m[] = {
+ {"getpos", iscenegetpos},
+ {"setpos", iscenesetpos},
+// {"remove", removeiguielement},
+ {0, 0},
+};
+
+void icube_register(lua_State* L){
+
+ luaL_newmetatable(L, "scene.icamera");//scene.icamera
+ lua_newtable(L);//scene.icamera, {}
+ luaL_register(L,NULL,icamera_m);//scene.icamera, {}
+ lua_setfield(L,-2,"__index");//scene.icamera
+ lua_pop(L,1);//
+
+ luaL_newmetatable(L, "scene.imayacamera");//scene.imayacamera
+ lua_newtable(L);//scene.imayascamera,{}
+ luaL_register(L,NULL,imayacamera_m);//scene.imayascamera,{}
+ lua_setfield(L,-2,"__index");//scene.imayascamera
+ lua_pop(L,1);//
+
+ luaL_newmetatable(L,"scene.ifpscamera");//scene.ifpscamera
+ lua_newtable(L);//scene.ifpscamera, {}
+ luaL_register(L,NULL,ifpscamera_m);//scene.ifpscamera,{}
+ luaL_register(L,NULL,icamera_m);//scene.ifpscamera,{}
+ lua_setfield(L,-2,"__index");//scene.ifpscamera
+ lua_pop(L,1);//
+
+ lua_getglobal(L,"scene");//{}
+ lua_pushcfunction(L,newiscenecamera);//{},newiscenecamera()
+ lua_setfield(L,-2,"newcamera");//{}
+ lua_pushcfunction(L,newiscenefpscamera);//{},newiscenefpscamera()
+ lua_setfield(L,-2,"newfpscamera");//{}
+ lua_pushcfunction(L,newiscenemayacamera);//{},newiscenemayacamera()
+ lua_setfield(L,-2,"newmayacamera");//{}
+ printf("\"scene\" was set!\n");
+ //lua_pop(L,1);
+}
diff --git a/src/client/lua_api/scene/icube.hpp b/src/client/lua_api/scene/icube.hpp
new file mode 100644
index 0000000..ffb4d3b
--- /dev/null
+++ b/src/client/lua_api/scene/icube.hpp
@@ -0,0 +1,11 @@
+
+#include <stdio.h>
+#include <stdlib.h>
+extern "C" {
+ #include <lua.h>
+ #include <lauxlib.h>
+ #include <lualib.h>
+}
+#include <irrlicht.h>
+
+void icube_register(lua_State* L);
diff --git a/src/client/lua_api/scene/igeneric.cpp b/src/client/lua_api/scene/igeneric.cpp
index fc32e83..0d061d2 100644
--- a/src/client/lua_api/scene/igeneric.cpp
+++ b/src/client/lua_api/scene/igeneric.cpp
@@ -7,6 +7,7 @@ extern "C" {
#include <irrlicht.h>
#include "igeneric.hpp"
#include "../gameparts.hpp"
+#include "../../../shared/lua_api/common.h"
using namespace irr;
using namespace core;
@@ -15,63 +16,57 @@ using namespace video;
extern IrrlichtDevice* device;
+/*
static LISceneNode* toiscenenode(lua_State* L, int index){
LISceneNode* ret = (LISceneNode*)lua_touserdata(L,index);
if(ret == NULL)
luaL_typerror(L,index,"LISceneNode");
return ret;
}
+*/
-int iscenegetpos(lua_State* L){
- ISceneNode* i = toiscenenode(L,1)->n;
+int iscenegetpos(lua_State* L){//{node=ud_IMeshSceneNode}
+ lua_getfield(L,-1,"node");//{node=ud_IMeshSceneNode},ud_IMeshSceneNode
+ ISceneNode* i = (ISceneNode*)lua_touserdata(L,-1);//{node=ud_IMeshSceneNode},ud_IMeshSceneNode
vector3df pos = i->getAbsolutePosition();
+ lua_pop(L,2);
+ pushvector3d(L,pos.X,pos.Y,pos.Z);
- lua_createtable(L,3,0);
-
- lua_pushnumber(L,1);
- lua_pushnumber(L,pos.X);
- lua_settable(L,-3);
-
- lua_pushnumber(L,2);
- lua_pushnumber(L,pos.Y);
- lua_settable(L,-3);
+ return 1;
+}
- lua_pushnumber(L,3);
- lua_pushnumber(L,pos.Z);
- lua_settable(L,-3);
-
+int iscenesetpos(lua_State* L){//{node=ud_IMeshSceneNode},{x,y,z}
+ double x,y,z;
+ popvector3d(L,&x,&y,&z);//{node=ud_IMeshSceneNode}
+ lua_getfield(L,-1,"node");//{node=ud_IMeshSceneNode},ud_IMeshSceneNode
+ ISceneNode* i = (ISceneNode*)lua_touserdata(L,-1);//{node=ud_IMeshSceneNode},ud_IMeshSceneNode
+ i->setPosition(vector3df(x,y,z));
+ i->updateAbsolutePosition();
+ vector3df pos = i->getAbsolutePosition();
+ printf("After setting pos, new pos is %f %f %f",pos.X,pos.Y,pos.Z);
+ lua_pop(L,2);//
+ return 0;
+}
+
+int iscenegetangle(lua_State* L){//{node=ud-IMeshSceneNode}
+ lua_getfield(L,-1,"node");
+ ISceneNode* i = (ISceneNode*)lua_touserdata(L,-1);
+ irr::core::vector3df ang = i->getRotation();
+ pushvector3d(L,ang.X, ang.Y, ang.Z);
return 1;
}
-int iscenesetpos(lua_State* L){
-
- ISceneNode* i = toiscenenode(L,1)->n;
-
- lua_pushnumber(L,1);
- lua_gettable(L,-2);
- f32 x = (f32)lua_tonumber(L,-1);
- lua_pop(L,1);
-
- lua_pushnumber(L,2);
- lua_gettable(L,-2);
- f32 y = (f32)lua_tonumber(L,-1);
- lua_pop(L,1);
-
- lua_pushnumber(L,3);
- lua_gettable(L,-2);
- f32 z = (f32)lua_tonumber(L,-1);
- lua_pop(L,1);
-
- printf("Trying to set pos of %p to %f %f %f",i,x,y,z);
-
- i->setPosition(vector3df(x,y,z));
- i->updateAbsolutePosition();
- vector3df pos = i->getAbsolutePosition();
- printf("After setting pos, new pos is %f %f %f",pos.X,pos.Y,pos.Z);
-
- return 0;
+int iscenesetangle(lua_State* L){//{node=ud_ISceneNode},{x,y,z}
+ double x,y,z;
+ popvector3d(L,&x,&y,&z);
+ lua_getfield(L,-1,"node");
+ ISceneNode* i = (ISceneNode*)lua_touserdata(L,-1);
+ irr::core::vector3df ang = irr::core::vector3df(x,y,z);
+ i->setRotation(ang);
+ return 0;
}
+/*
int iscenesetmaterial(lua_State* L){
ISceneNode* i = toiscenenode(L,1)->n;
const char* s = luaL_optstring(L,2,"error.png");
@@ -81,3 +76,4 @@ int iscenesetmaterial(lua_State* L){
return 0;
}
+*/
diff --git a/src/client/lua_api/scene/igeneric.hpp b/src/client/lua_api/scene/igeneric.hpp
index 85a9d3e..c60b169 100644
--- a/src/client/lua_api/scene/igeneric.hpp
+++ b/src/client/lua_api/scene/igeneric.hpp
@@ -11,6 +11,9 @@ extern "C" {
int iscenegetpos(lua_State* L);
int iscenesetpos(lua_State* L);
+int iscenegetangle(lua_State* L);
+int iscenesetangle(lua_State* L);
+
int iscenesetmaterial(lua_State* L);
diff --git a/src/client/lua_api/scene/ilight.cpp b/src/client/lua_api/scene/ilight.cpp
index 2511999..451280a 100644
--- a/src/client/lua_api/scene/ilight.cpp
+++ b/src/client/lua_api/scene/ilight.cpp
@@ -14,6 +14,7 @@ extern "C" {
#include "../gameparts.hpp"
#include "ilight.hpp"
#include "igeneric.hpp"
+#include "../../../shared/lua_api/common.h"
using namespace irr;
using namespace scene;
@@ -31,100 +32,49 @@ static LISceneNode* checkilight(lua_State* L){
return checkiscenelight(L,1);
}
-//iscenelight.new(Vector position, parrent = nil)
+//{} :: scene.newlight(radius, {v3 position})
static int newiscenelight(lua_State* L){
printf("Createing light!\n");
- int nargs = lua_gettop(L);
- //lua_pop(L,1);
- // float radius = 100;
- // if(nargs == 2){
- // radius = luaL_optnumber(L,2,100);
- // }
- float radius = lua_tonumber(L,-1);
- printf("radius was %f\n" ,radius);
- lua_pop(L,1);
+ double x,y,z;
+ popvector3d(L,&x,&y,&z);//radius
+ double radius = lua_tonumber(L,-1);
+ lua_pop(L,1);//
- //The position of the light
- lua_pushnumber(L,1);
- lua_gettable(L,-2);
- float x = lua_tonumber(L,-1);
- printf("got x: %f\n",x);
- lua_pop(L,1);
- lua_pushnumber(L,2);
- lua_gettable(L,-2);
- float y = lua_tonumber(L,-1);
- lua_pop(L,1);
- lua_pushnumber(L,3);
- lua_gettable(L,-2);
- float z = lua_tonumber(L,-1);
- lua_pop(L,1);
- printf("Found position for light: %f %f %f\n",x,y,z);
-
//Create the mesh
ISceneManager* smgr = device->getSceneManager();
ILightSceneNode* light = smgr->addLightSceneNode(0,vector3df(x,y,z),video::SColor(1.0f,1.0f,1.0f,1.0f),(f32)radius,(s32)-1);
- printf("Registered the light!\n");
-
- //Register it's callback
- //registerguicallback(llabel,EGET_ELEMENT_HOVERED,iguilabelevent);
//Create it's lua representation
- LISceneNode* lnode = (LISceneNode*)lua_newuserdata(L, sizeof(LISceneNode));
- int tref = luaL_ref(L,LUA_REGISTRYINDEX);
- //iguielements[lcam] = tref;
- lua_rawgeti(L,LUA_REGISTRYINDEX,tref);//Put it back on the stack since luaL_ref pops the object.
+ lua_newtable(L);//{}
+ lua_pushlightuserdata(L,light);
+ lua_setfield(L,-2,"node");
//Set it's metatable
luaL_getmetatable(L, "scene.imesh");
lua_setmetatable(L, -2);
- lnode->n = light;
- lnode->funcmap = hashmap_new();
- lnode->type = "ilight";
-
- //Put it on top and return it
- lua_rawgeti(L,LUA_REGISTRYINDEX,tref);
return 1;
}
-static const luaL_reg icamera_f[] = {
- {"new", newiscenelight},
-// {"gethandeler", guigethandeler},
-// {"sethandeler", guisethandeler},
- {0,0},
-};
-
-static const luaL_reg icamera_m[] = {
- {"getpos", iscenegetpos},
- {"setpos", iscenesetpos},
-// {"move", moveiguielement},
-// {"settext", setiguitext},
-// {"remove", removeiguielement},
- {0, 0},
+static const luaL_reg ilight_m[] = {
+ {"getpos", iscenegetpos},
+ {"setpos", iscenesetpos},
+ {0, 0},
};
-int ilight_register(lua_State* L, IrrlichtDevice* d){
-
- device = d;
-
- printf("ilight registered\n");
+void ilight_register(lua_State* L){
- luaL_newmetatable(L, "scene.ilight");
+ lua_getglobal(L,"scene");//{scene}
+ lua_pushcfunction(L,newiscenelight);//{scene},newiscenelight()
+ lua_setfield(L,-2,"newlight");//{scene}
- luaL_register(L,"ilight",icamera_f);
+ lua_pop(L,1);//
- lua_pushstring(L,"__index");
- lua_pushstring(L,"gethandeler");
- lua_gettable(L,-3);
- lua_settable(L,-4);
+ luaL_newmetatable(L,"scene.ilight");//scene.ilight
+ lua_newtable(L);//scene.ilight,{}
+ luaL_register(L, NULL, ilight_m);//scene.ilight,{}
+ lua_setfield(L,-2,"__index");//scene.ilight
- lua_pushstring(L,"__newindex");
- lua_pushstring(L,"sethandeler");
- lua_gettable(L,-3);
- lua_settable(L,-4);
-
- luaL_register(L, NULL, icamera_m);
-
- return 1;
+ lua_pop(L,1);
}
diff --git a/src/client/lua_api/scene/ilight.hpp b/src/client/lua_api/scene/ilight.hpp
index 87d2841..af9c084 100644
--- a/src/client/lua_api/scene/ilight.hpp
+++ b/src/client/lua_api/scene/ilight.hpp
@@ -8,4 +8,4 @@ extern "C" {
}
#include <irrlicht.h>
-int ilight_register(lua_State* L, irr::IrrlichtDevice* d);
+void ilight_register(lua_State* L);
diff --git a/src/client/lua_api/scene/imesh.cpp b/src/client/lua_api/scene/imesh.cpp
index 1a1c28b..3f3ae24 100644
--- a/src/client/lua_api/scene/imesh.cpp
+++ b/src/client/lua_api/scene/imesh.cpp
@@ -14,6 +14,7 @@ extern "C" {
#include "../gameparts.hpp"
#include "imesh.hpp"
#include "igeneric.hpp"
+#include "../../../shared/lua_api/common.h"
using namespace irr;
using namespace scene;
@@ -22,7 +23,6 @@ using namespace video;
extern IrrlichtDevice* device;
-
static LISceneNode* checkismesh(lua_State* L, int index){
void* ud = luaL_checkudata(L,index,"scene.imesh");
luaL_argcheck(L,ud != NULL, index, "'scene.imesh' expected");
@@ -35,83 +35,107 @@ static LISceneNode* checkismesh(lua_State* L){
}
*/
-static int newiscenemesh(lua_State* L){
- printf("Createing mesh!\n");
- int nargs = lua_gettop(L);
- if(nargs != 1){
- printf("Incorrect # of args to create a mesh!");
- }
- //The model for the mesh
- const char* modelpath = luaL_optstring(L,1,"error");
-
- //Create the mesh
- ISceneManager* smgr = device->getSceneManager();
- IAnimatedMesh* amesh = smgr->getMesh(modelpath);
- IAnimatedMeshSceneNode* mesh = smgr->addAnimatedMeshSceneNode( amesh );
- mesh->setMaterialFlag(EMF_GOURAUD_SHADING,true);
- printf("Registered the mesh!\n");
-
- //Register it's callback
- //registerguicallback(llabel,EGET_ELEMENT_HOVERED,iguilabelevent);
-
- //Create it's lua representation
- LISceneNode* lmesh = (LISceneNode*)lua_newuserdata(L, sizeof(LISceneNode));
- int tref = luaL_ref(L,LUA_REGISTRYINDEX);
- //iguielements[lcam] = tref;
- lua_rawgeti(L,LUA_REGISTRYINDEX,tref);//Put it back on the stack since luaL_ref pops the object.
-
- //Set it's metatable
- luaL_getmetatable(L, "scene.imesh");
- lua_setmetatable(L, -2);
-
- //Create the struct
- lmesh->n = mesh;
- lmesh->funcmap = hashmap_new();
- lmesh->type = "imesh";
-
- //Free up anything made in this function
- //free(label);
-
- //Put it on top and return it
- lua_rawgeti(L,LUA_REGISTRYINDEX,tref);
- return 1;
+//{} :: scene.newmesh("/path/to/model")
+static int newiscenemesh(lua_State* L){//"path/to"
+
+ printf("Createing mesh!\n");
+ int nargs = lua_gettop(L);
+ if(nargs != 1){
+ lua_pushfstring(L,"scene.newmesh got %d arguments, expecting 1",nargs);
+ lua_error(L);
+ }
+ //The model for the mesh
+ const char* modelpath = luaL_optstring(L,1,"error");//"path/to"
+ lua_pop(L,1);//
+
+ //Create the mesh
+ ISceneManager* smgr = device->getSceneManager();
+ IAnimatedMesh* amesh = smgr->getMesh(modelpath);
+ IAnimatedMeshSceneNode* mesh = smgr->addAnimatedMeshSceneNode( amesh );
+ mesh->setMaterialFlag(EMF_GOURAUD_SHADING,true);
+ printf("Registered the mesh!\n");
+
+ lua_newtable(L);//{}
+ luaL_getmetatable(L,"scene.imesh");//{},scene.imesh
+ lua_setmetatable(L,-2);//{}
+
+ lua_pushlightuserdata(L,mesh);//{},ud_mesh
+ lua_setfield(L,-2,"node");//{}
+
+ return 1;
}
-static const luaL_reg imesh_f[] = {
- {"new", newiscenemesh},
-// {"gethandeler", guigethandeler},
-// {"sethandeler", guisethandeler},
- {0,0},
-};
+// ud_node :: ({v3 size}, {v3 origin})
+void makenewiscenecube(lua_State* L){
+ double x,y,z;
+ popvector3d(L,&x,&y,&z);//{v3 size}
+ double sx,sy,sz;
+ popvector3d(L,&sx,&sy,&sz);//{}
+ IMeshSceneNode* n = device->getSceneManager()->addCubeSceneNode(10,0,-1,core::vector3df(x,y,z),core::vector3df(0,0,0),core::vector3df(sx,sy,sz));
+ lua_pushlightuserdata(L,n);
+}
-static const luaL_reg imesh_m[] = {
- {"setMaterial", iscenesetmaterial},
- {"getpos", iscenegetpos},
- {"setpos", iscenesetpos},
-// {"settext", setiguitext},
-// {"remove", removeiguielement},
- {0, 0},
-};
+// {} :: scene.newcube({v3 size}, {v3 origin})
+int newiscenecube(lua_State* L){//{v3 size}, {v3 origin}
+ makenewiscenecube(L);//ud_node
+ ISceneNode* n = (ISceneNode*)lua_touserdata(L,-1);//ud_node
+ lua_pop(L,1);//
+ lua_newtable(L);//{}
+ luaL_getmetatable(L,"scene.icube");//{},scene.icube
+ lua_setmetatable(L,-2);//{}
-int imesh_register(lua_State* L, IrrlichtDevice* d){
+ lua_pushlightuserdata(L,n);//{},ud_mesh
+ lua_setfield(L,-2,"node");//{}
- device = d;
+ return 1;
+}
- luaL_newmetatable(L, "scene.imesh");
+// self:setMaterial("path/to/material")
+int iscenesetmaterial(lua_State* L){//self,"path/to"
+ ISceneNode* node = (IMeshSceneNode*)lua_touserdata(L,-2);
+ const char* s = lua_tostring(L,-1);
+ //ISceneNode* i = toiscenenode(L,1)->n;
+ //const char* s = luaL_optstring(L,2,"error.png");
+ //printf("Setting material to %s",s);
- luaL_register(L,"imesh",imesh_f);
+ IVideoDriver* driver = device->getVideoDriver();
+ node->setMaterialTexture(0, driver->getTexture(s));
- lua_pushstring(L,"__index");
- lua_pushstring(L,"gethandeler");
- lua_gettable(L,-3);
- lua_settable(L,-4);
+ lua_pop(L,2);
+ return 0;
+}
- lua_pushstring(L,"__newindex");
- lua_pushstring(L,"sethandeler");
- lua_gettable(L,-3);
- lua_settable(L,-4);
+static const luaL_reg imesh_m[] = {
+ {"setMaterial", iscenesetmaterial},
+ {"getpos", iscenegetpos},
+ {"setpos", iscenesetpos},
+ // {"remove", removeiguielement},
+ {0, 0},
+};
+
+static const luaL_reg icube_m[] = {
+ {0,0},
+};
- luaL_register(L, NULL, imesh_m);
+void imesh_register(lua_State* L){
+
+ luaL_newmetatable(L, "scene.imesh");//scene.icamera
+ lua_newtable(L);//scene.icamera,{}
+ luaL_register(L,NULL,imesh_m);//scene.icamera,{}
+ lua_setfield(L,-2,"__index");//scene.icamera
+ lua_pop(L,1);//
+
+ luaL_newmetatable(L,"scene.icube");//scene.icube
+ lua_newtable(L);//scene.icube, {}
+ luaL_register(L,NULL,imesh_m);//scene.icube,{}
+ luaL_register(L,NULL,icube_m);//scene.icube,{}
+ lua_setfield(L,-2,"__index");//scene.icube
+ lua_pop(L,1);//
+
+ lua_getglobal(L,"scene");
+ lua_pushcfunction(L,newiscenemesh);
+ lua_setfield(L,-2,"newmesh");
+ lua_pushcfunction(L,newiscenecube);
+ lua_setfield(L,-2,"newcube");
- return 1;
}
diff --git a/src/client/lua_api/scene/imesh.hpp b/src/client/lua_api/scene/imesh.hpp
index bd33c07..925f12e 100644
--- a/src/client/lua_api/scene/imesh.hpp
+++ b/src/client/lua_api/scene/imesh.hpp
@@ -8,4 +8,7 @@ extern "C" {
}
#include <irrlicht.h>
-int imesh_register(lua_State* L, irr::IrrlichtDevice* d);
+
+void makenewiscenecube(lua_State* L);
+int newiscenecube(lua_State* L);//{v3 size}, {v3 origin}, mass
+void imesh_register(lua_State* L);
diff --git a/src/client/main.cpp b/src/client/main.cpp
index 13a52e4..2d30c70 100644
--- a/src/client/main.cpp
+++ b/src/client/main.cpp
@@ -70,7 +70,6 @@ void QuaternionToEuler(const btQuaternion &TQuat, btVector3 &TEuler) {
}
void UpdateElement(btRigidBody* TObject){
-
if(TObject->getUserPointer() != NULL){
//UpdateRender(*Iterator);
scene::ISceneNode *Node = static_cast<scene::ISceneNode *>((TObject)->getUserPointer());
@@ -87,82 +86,87 @@ void UpdateElement(btRigidBody* TObject){
}
int main(int argc, char *argv[]){
- printf("Brok[en]gine Client");
- // Initialize bullet
- phys_genesis();
-
- //Create a new lua state, this gets shared everywhere
- lua_State *state = luaL_newstate();
- L = state;
- //Load the lua libraries
- loadLLibs(state);
- //Defined in initdevice.cpp, creates the irrlicht device
- device = spawnIrrDevice(state);
- if (!device)
- return 1;
- //Loads libraries for interfaceing with irrlicht
- loadIrrLibs(state,device);
- loadNetLibs(state);
- printf("Loadded irr libs...\n");
- //Sets the global event handeler
- GlobalEventReceiver ger = GlobalEventReceiver(device);
- device->setEventReceiver(&ger);
- int iErr = luaL_dofile(state,"../data/init.lua");
- if(iErr != 0){
- lua_error(state);
- printf("Failed to open lua file:../data/guitest.lua\n");
- }
-
- //Load some bullet physics stuff
-
- //Load some menu
- loadMenu("Some menu",device);
-
- IVideoDriver* driver = device->getVideoDriver();
- ISceneManager* smgr = device->getSceneManager();
- IGUIEnvironment* guienv = device->getGUIEnvironment();
-
- device->setWindowCaption(L"Bork[en]gine Client");
-
- printf("Everything registered, about to start running device!\n");
-
- //u32 TimeStamp = irrTimer->getTime(), DeltaTime = 0;
- //high_resolution_clock::time_point t1 = high_resolution_clock::now();
- while(device->run()){
- gameloop_net(L);
- gameloop_phys(UpdateElement);
- if(device->isWindowActive()){
- //high_resolution_clock::time_point now = high_resolution_clock::now();
- //duration<double> delta = now-t1;
- //double steps = delta.count() * 100;
- //UpdatePhysics(steps,UpdateElement);
- //t1 = now;
- driver->beginScene(true, true, SColor(255,100,101,140));
-
- smgr->drawAll();
- guienv->drawAll();
-
- driver->endScene();
- }else{
- device->yield();
- }
- lua_getglobal(state,"GAME");//{}
- lua_getfield(state,-1,"tick");//{},function_tick()
- if(!lua_isnil(state,-1)){
- lua_call(state,0,0);
- lua_pop(state,1);
- }else{
- lua_pop(state,2);
- }
- }
- printf("Closeing lua state...\n");
- //lua_close(state);
- //printf("clearing objects...\n");
- //ClearObjects(World,Objects,RemoveISceneNode); //Clearing objects must be done after we droped the device.
- phys_shutdown(RemoveISceneNode);
-
- device->drop();
- printf("droped device\n");
-
- return 0;
+ printf("Brok[en]gine Client");
+ // Initialize bullet
+ phys_genesis();
+
+ //Create a new lua state, this gets shared everywhere
+ lua_State *state = luaL_newstate();
+ L = state;
+ //Load the lua libraries
+ loadLLibs(state);
+ //Defined in initdevice.cpp, creates the irrlicht device
+ device = spawnIrrDevice(state);
+ if (!device)
+ return 1;
+ //Loads libraries for interfaceing with irrlicht
+ loadIrrLibs(state,device);
+ loadNetLibs(state);
+ printf("Loadded irr libs...\n");
+ //Sets the global event handeler
+ GlobalEventReceiver ger = GlobalEventReceiver(device);
+ device->setEventReceiver(&ger);
+ int iErr = luaL_dofile(state,"../data/init.lua");
+ if(iErr != 0){
+ lua_error(state);
+ printf("Failed to open lua file:../data/guitest.lua\n");
+ }
+
+ //Load some bullet physics stuff
+
+ //Load some menu
+ loadMenu("Some menu",device);
+
+ IVideoDriver* driver = device->getVideoDriver();
+ ISceneManager* smgr = device->getSceneManager();
+ IGUIEnvironment* guienv = device->getGUIEnvironment();
+
+ device->setWindowCaption(L"Bork[en]gine Client");
+
+ printf("Everything registered, about to start running device!\n");
+
+ //u32 TimeStamp = irrTimer->getTime(), DeltaTime = 0;
+ //high_resolution_clock::time_point t1 = high_resolution_clock::now();
+ while(device->run()){
+ printf("Game loop:\n");
+ gameloop_net(L);
+ printf("Update phys:\n");
+ gameloop_phys(UpdateElement);
+ if(device->isWindowActive()){
+ //high_resolution_clock::time_point now = high_resolution_clock::now();
+ //duration<double> delta = now-t1;
+ //double steps = delta.count() * 100;
+ //UpdatePhysics(steps,UpdateElement);
+ //t1 = now;
+ printf("beginscene\n");
+ driver->beginScene(true, true, SColor(255,100,101,140));
+ printf("scene drawAll\n");
+ smgr->drawAll();
+ printf("gui drawAll\n");
+ guienv->drawAll();
+ printf("scene end\n");
+ driver->endScene();
+ }else{
+ device->yield();
+ }
+ lua_getglobal(state,"GAME");//{}
+ lua_getfield(state,-1,"tick");//{},function_tick()
+ printf("Tick\n");
+ if(!lua_isnil(state,-1)){
+ lua_call(state,0,0);
+ lua_pop(state,1);
+ }else{
+ lua_pop(state,2);
+ }
+ }
+ printf("Closeing lua state...\n");
+ //lua_close(state);
+ //printf("clearing objects...\n");
+ //ClearObjects(World,Objects,RemoveISceneNode); //Clearing objects must be done after we droped the device.
+ phys_shutdown(RemoveISceneNode);
+
+ device->drop();
+ printf("droped device\n");
+
+ return 0;
}
diff --git a/src/shared/lua_api/common.c b/src/shared/lua_api/common.c
index 140ece1..50eb850 100644
--- a/src/shared/lua_api/common.c
+++ b/src/shared/lua_api/common.c
@@ -39,19 +39,19 @@ void loadLLibs(lua_State* L){
int pushvector3i(lua_State* L,long a,long b,long c){
- lua_newtable(L);
+ lua_newtable(L);//{}
- lua_pushinteger(L,1);
- lua_pushinteger(L,a);
- lua_settable(L,-3);
+ lua_pushinteger(L,1);//{},1
+ lua_pushinteger(L,a);//{},1,a
+ lua_settable(L,-3);//{}
- lua_pushinteger(L,2);
- lua_pushinteger(L,b);
- lua_settable(L,-3);
+ lua_pushinteger(L,2);//{},2
+ lua_pushinteger(L,b);//{},2,b
+ lua_settable(L,-3);//{}
- lua_pushinteger(L,3);
- lua_pushinteger(L,c);
- lua_settable(L,-3);
+ lua_pushinteger(L,3);//{},3
+ lua_pushinteger(L,c);//{},3,c
+ lua_settable(L,-3);//{}
return 1;
}
@@ -72,6 +72,19 @@ int pushvector3d(lua_State* L,double a,double b,double c){
return 1;
}
+int pushvector2i(lua_State* L, long a, long b){
+ lua_newtable(L);
+
+ lua_pushinteger(L,1);
+ lua_pushinteger(L,a);
+ lua_settable(L,-3);
+
+ lua_pushinteger(L,2);
+ lua_pushinteger(L,b);
+ lua_settable(L,-3);
+
+ return 1;
+}
int popvector3i(lua_State* L,long* a,long* b,long* c){//{v3}
lua_pushinteger(L,1);//{v3},1
@@ -114,3 +127,17 @@ int popvector3d(lua_State* L,double* a,double* b,double* c){
lua_pop(L,1);
return 0;
}
+
+int popvector2i(lua_State* L, long* a, long* b){
+ lua_pushinteger(L,1);
+ lua_gettable(L,-2);
+ *a = lua_tonumber(L,-1);
+ lua_pop(L,1);
+
+ lua_pushinteger(L,2);
+ lua_gettable(L,-2);
+ *b = lua_tonumber(L,-1);
+ lua_pop(L,2);
+
+ return 0;
+}
diff --git a/src/shared/lua_api/common.h b/src/shared/lua_api/common.h
index 81dc3a4..9260706 100644
--- a/src/shared/lua_api/common.h
+++ b/src/shared/lua_api/common.h
@@ -9,5 +9,8 @@ void loadLLibs(lua_State*);
int pushvector3i(lua_State*,long,long,long);
int pushvector3d(lua_State*,double,double,double);
+int pushvector2i(lua_State*,long,long);
+
int popvector3i(lua_State*,long*,long*,long*);
int popvector3d(lua_State*,double*,double*,double*);
+int popvector2i(lua_State*,long*,long*);
diff --git a/src/shared/lua_api/irr/cubenode.cpp b/src/shared/lua_api/irr/cubenode.cpp
new file mode 100644
index 0000000..d7e87bb
--- /dev/null
+++ b/src/shared/lua_api/irr/cubenode.cpp
@@ -0,0 +1,6 @@
+
+extern "C" {
+ #include <lua.h>
+ #include <lauxlib.h>
+ #include <lualib.h>
+}
diff --git a/src/shared/lua_api/irr/cubenode.hpp b/src/shared/lua_api/irr/cubenode.hpp
new file mode 100644
index 0000000..d7e87bb
--- /dev/null
+++ b/src/shared/lua_api/irr/cubenode.hpp
@@ -0,0 +1,6 @@
+
+extern "C" {
+ #include <lua.h>
+ #include <lauxlib.h>
+ #include <lualib.h>
+}
diff --git a/src/shared/lua_api/load_scene.cpp b/src/shared/lua_api/load_scene.cpp
new file mode 100644
index 0000000..633fcb1
--- /dev/null
+++ b/src/shared/lua_api/load_scene.cpp
@@ -0,0 +1,11 @@
+
+extern "C" {
+ #include <lua.h>
+ #include <lauxlib.h>
+ #include <lualib.h>
+}
+
+
+void register_scene(lua_State* L){
+
+}
diff --git a/src/shared/lua_api/load_scene.hpp b/src/shared/lua_api/load_scene.hpp
new file mode 100644
index 0000000..c83a224
--- /dev/null
+++ b/src/shared/lua_api/load_scene.hpp
@@ -0,0 +1,8 @@
+
+extern "C" {
+ #include <lua.h>
+ #include <lauxlib.h>
+ #include <lualib.h>
+}
+
+void register_scene(lua_State* L);
diff --git a/src/shared/lua_api/phys/bphysbox.cpp b/src/shared/lua_api/phys/bphysbox.cpp
index be9db07..3036cf9 100644
--- a/src/shared/lua_api/phys/bphysbox.cpp
+++ b/src/shared/lua_api/phys/bphysbox.cpp
@@ -26,22 +26,15 @@ static LISceneNode* checkismesh(lua_State* L){
return checkismesh(L,1);
}
*/
-
-// phys.newphysbox(vector3 size, vector3 origin, double mass)
-int newbphysbox(lua_State* L){
- printf("Createing bphysbox!\n");
- int nargs = lua_gettop(L);
- if(nargs != 3){
- lua_pushfstring(L,"Expected 3 arguments, got %d",nargs);
- lua_error(L);
- }
+// ud_btRigidBody :: ({v3 size}, {v3 origin}, double mass)
+void makenewbphysbox(lua_State* L){
double px,py,pz; //position
double sx,sy,sz; //size
double mass;
mass = lua_tonumber(L,-1);//{v3_size},{v3_origin},mass
lua_pop(L,1);//{v3_size},{v3_origin}
- printf("Got mass: %d\n",mass);
+ printf("Got mass: %f\n",mass);
popvector3d(L,&px,&py,&pz);//{v3_size}
printf("Got position: (%f,%f,%f)\n",px,py,pz);
@@ -73,9 +66,18 @@ int newbphysbox(lua_State* L){
World->addRigidBody(rigidbody);
Objects.push_back(rigidbody);
+ lua_pushlightuserdata(L,rigidbody);//ud_rigidbody
+}
+
+// phys.newphysbox(vector3 size, vector3 origin, double mass)
+int newbphysbox(lua_State* L){
+ printf("Createing bphysbox!\n");
//Create it's lua representation
+ makenewbphysbox(L);//ud_btRigidBody
+ btRigidBody* r = (btRigidBody*)lua_touserdata(L,-1);
+ lua_pop(L,1);
lua_newtable(L);//{}
- lua_pushlightuserdata(L,rigidbody);//{},ud_rigidbody
+ lua_pushlightuserdata(L,r);//ud_btRigidBody
lua_setfield(L,-2,"rigidbody");//{}
//Set it's metatable
@@ -118,6 +120,7 @@ static int bphyssetpos(lua_State *L){//self,{v3 pos}
// {v3 pos} :: physbox:getpos()
static int bphysgetpos(lua_State *L){//self
+ printf("Physics box set pos called\n");
lua_getfield(L,-1,"rigidbody");//self,ud_rigidbody
btRigidBody* i = (btRigidBody*)lua_touserdata(L,-1);//self,ud_rigidbody
btTransform bt = i->getWorldTransform();
@@ -145,7 +148,8 @@ void bphysbox_register(lua_State* L){//
lua_pop(L,1);//
lua_getglobal(L,"phys");//{}
- lua_pushcfunction(L,newbphysbox);
- lua_setfield(L,-2,"newphysbox");
+ lua_pushcfunction(L,newbphysbox);//{},newbphysbox()
+ lua_setfield(L,-2,"newphysbox");//{}
+ lua_pop(L,1);
}
diff --git a/src/shared/lua_api/phys/bphysbox.hpp b/src/shared/lua_api/phys/bphysbox.hpp
index c031037..96b58a7 100644
--- a/src/shared/lua_api/phys/bphysbox.hpp
+++ b/src/shared/lua_api/phys/bphysbox.hpp
@@ -11,4 +11,4 @@ extern "C" {
#include "../common.h"
void bphysbox_register(lua_State* L);
-int newbphysbox(lua_State* L);
+void makenewbphysbox(lua_State* L);