aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client/callbackhandeler.cpp76
-rw-r--r--src/client/initdevice.cpp4
-rw-r--r--src/client/lua_api/gui/iguibutton.cpp136
-rw-r--r--src/client/lua_api/gui/iguibutton.hpp2
-rw-r--r--src/client/lua_api/gui/iguicheckbox.cpp14
-rw-r--r--src/client/lua_api/gui/iguielement.cpp50
-rw-r--r--src/client/lua_api/gui/iguielement.hpp1
-rw-r--r--src/client/lua_api/gui/iguiimage.cpp72
-rw-r--r--src/client/lua_api/gui/iguiwindow.cpp80
-rw-r--r--src/client/lua_api/load_gui.cpp6
-rw-r--r--src/client/lua_api/load_phys.cpp11
-rw-r--r--src/client/lua_api/load_scene.cpp8
-rw-r--r--src/client/lua_api/load_video.cpp63
-rw-r--r--src/client/lua_api/phys/bphysbuffer.cpp2
-rw-r--r--src/client/lua_api/phys/bphysmodel.cpp2
-rw-r--r--src/client/lua_api/phys/cbphysbox.cpp4
-rw-r--r--src/client/lua_api/scene/icamera.cpp1
-rw-r--r--src/client/lua_api/scene/icube.cpp2
-rw-r--r--src/client/lua_api/video/iimage.cpp59
-rw-r--r--src/client/lua_api/video/itexture.cpp37
-rw-r--r--src/client/main.cpp20
-rw-r--r--src/shared/lua_api/common.c37
-rw-r--r--src/shared/lua_api/common.h3
-rw-r--r--src/shared/lua_api/phys/bphysbox.cpp22
-rw-r--r--src/shared/phys/physcommon.cpp12
25 files changed, 481 insertions, 243 deletions
diff --git a/src/client/callbackhandeler.cpp b/src/client/callbackhandeler.cpp
index cf24cd2..76fe693 100644
--- a/src/client/callbackhandeler.cpp
+++ b/src/client/callbackhandeler.cpp
@@ -36,10 +36,11 @@ bool GlobalEventReceiver::OnEvent(const SEvent& e){
case EET_GUI_EVENT:{
IGUIElement* caller = e.GUIEvent.Caller;
EGUI_EVENT_TYPE get = e.GUIEvent.EventType;
- printf("detected gui event: %d\n",get);
+ //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){
+ //printf("Found a callback for this event\n");
return guifuncs[caller][get](e);
}
return false;
@@ -49,20 +50,71 @@ bool GlobalEventReceiver::OnEvent(const SEvent& e){
SEvent::SMouseInput se = e.MouseInput;
//printf("X: %d Y: %d\n",se.X, se.Y);
- lua_getglobal(L,"GAME");//{}
- lua_getfield(L,-1,"onMouseMove");//{},onMouseMove()
- if(!lua_isnil(L,-1)){
- lua_pushnumber(L,se.X);
- lua_pushnumber(L,se.Y);
- lua_call(L,2,0);
- lua_pop(L,1);
- }else{
- lua_pop(L,2);
+ switch(se.Event){
+ case EMIE_MOUSE_MOVED:{
+ lua_getglobal(L,"GAME");//{}
+ lua_getfield(L,-1,"onMouseMove");//{},onMouseMove()
+ if(!lua_isnil(L,-1)){
+ lua_pushnumber(L,se.X);
+ lua_pushnumber(L,se.Y);
+ lua_call(L,2,0);
+ lua_pop(L,1);
+ }else{
+ lua_pop(L,2);
+ }
+ break;
}
+ case EMIE_LMOUSE_PRESSED_DOWN:
+ case EMIE_RMOUSE_PRESSED_DOWN:
+ case EMIE_MMOUSE_PRESSED_DOWN:{
+ lua_getglobal(L,"GAME");
+ lua_getfield(L,-1,"onMouseDown");
+ if(!lua_isnil(L,-1)){
+ lua_pushnumber(L,se.X);
+ lua_pushnumber(L,se.Y);
+ lua_pushnumber(L,se.Event);
+ lua_call(L,3,0);
+ lua_pop(L,1);
+ }else{
+ lua_pop(L,2);
+ }
+ break;
+ }
+ case EMIE_LMOUSE_LEFT_UP:
+ case EMIE_RMOUSE_LEFT_UP:
+ case EMIE_MMOUSE_LEFT_UP:{
+ lua_getglobal(L,"GAME");
+ lua_getfield(L,-1,"onMouseUp");
+ if(!lua_isnil(L,-1)){
+ lua_pushnumber(L,se.X);
+ lua_pushnumber(L,se.Y);
+ lua_pushnumber(L,se.Event);
+ lua_call(L,3,0);
+ lua_pop(L,1);
+ }else{
+ lua_pop(L,2);
+ }
+ break;
+ }
+ case EMIE_MOUSE_WHEEL:{
+ lua_getglobal(L,"GAME");
+ lua_getfield(L,-1,"onMouseWheel");
+ if(!lua_isnil(L,-1)){
+ lua_pushnumber(L,se.X);
+ lua_pushnumber(L,se.Y);
+ lua_pushnumber(L,se.Wheel);
+ lua_call(L,3,0);
+ lua_pop(L,1);
+ }else{
+ lua_pop(L,2);
+ }
+ }
+ }
+
break;
}
case EET_KEY_INPUT_EVENT:{
- printf("Got input event\n");
+ //printf("Got input event\n");
SEvent::SKeyInput se = e.KeyInput;
lua_getglobal(L,"GAME");//{}
lua_getfield(L,-1,"onKeyDown");//{},()|nil
@@ -79,7 +131,7 @@ bool GlobalEventReceiver::OnEvent(const SEvent& e){
break;
}
default:
- printf("Called an unknown event\n");
+ //printf("Called an unknown event\n");
return false;
}
}
diff --git a/src/client/initdevice.cpp b/src/client/initdevice.cpp
index e3af44c..79b6706 100644
--- a/src/client/initdevice.cpp
+++ b/src/client/initdevice.cpp
@@ -148,7 +148,7 @@ void parseSetting(const char* settingname, lua_State* L, settings* set){
void settingsFromTable(lua_State *L, SIrrlichtCreationParameters* p){
lua_pushnil(L);
settings* set = (settings*)malloc(sizeof(settings));
- printf("Loading settings:");
+ printf("Loading settings...");
while(lua_next(L,-2) != 0){
if(lua_isstring(L,-2)){
const char* setstr = lua_tostring(L,-2);
@@ -174,7 +174,7 @@ void settingsFromTable(lua_State *L, SIrrlichtCreationParameters* p){
}
IrrlichtDevice* spawnIrrDevice(lua_State* L){
- printf("Attempting to load settings...\n");
+ //printf("Attempting to load settings...\n");
int iErr = luaL_dofile(L,"../data/deviceinit.lua");
SIrrlichtCreationParameters p = SIrrlichtCreationParameters();
settingsFromTable(L,&p);
diff --git a/src/client/lua_api/gui/iguibutton.cpp b/src/client/lua_api/gui/iguibutton.cpp
index 494e9f9..8732bd6 100644
--- a/src/client/lua_api/gui/iguibutton.cpp
+++ b/src/client/lua_api/gui/iguibutton.cpp
@@ -13,10 +13,12 @@ extern "C" {
#include <irrlicht.h>
#include "../guiparts.hpp"
#include "iguielement.hpp"
-#include "../../callbackhandeler.hpp"
-#include "../../util/hashmap.h"
+#include "client/callbackhandeler.hpp"
+#include "client/util/hashmap.h"
+#include "shared/lua_api/common.h"
using namespace irr;
+using namespace core;
using namespace gui;
extern IrrlichtDevice* device;
@@ -68,97 +70,67 @@ static bool iguibuttonevent(irr::SEvent e){
return false;
}
+//gui.newbutton({x,y},{width,height},text[,parent])
static int newiguibutton(lua_State* L){
- printf("Createing gui button!\n");
- //The position of the button
- 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 and tooltip
- wchar_t* button_label;
- wchar_t* button_tooltip;
- const char* labelopt = luaL_optstring(L,5,"Button");
- const char* tooltipopt = luaL_optstring(L,6,"Tooltip");
- int bls = strlen(labelopt);
- int bts = strlen(tooltipopt);
- button_label = (wchar_t*)malloc(sizeof(wchar_t)*(bls));
- button_tooltip = (wchar_t*)malloc(sizeof(wchar_t)*(bts));
- mbstowcs(button_label,labelopt,bls+1);
- mbstowcs(button_tooltip,tooltipopt,bts+1);
- printf("Got the string options\n");
-
- //If the element has a parrent
- int parent = luaL_optint(L,7,0);
-
- //Create the button
- IGUIEnvironment* env = device->getGUIEnvironment();
- IGUIButton* nbut = (IGUIButton*) env->addButton(core::rect<s32>(startx,starty,endx,endy), guielements[parent], gui_elenum++, button_label, button_tooltip);
-
- //Register it's callback
- registerguicallback(nbut,EGET_BUTTON_CLICKED,iguibuttonevent);
- printf("Finished registering callback\n");
-
- //Create the lua representation of the button
- LIGUIElement* lbut = (LIGUIElement*)lua_newuserdata(L, sizeof(LIGUIElement));
-
- //Make it callbackable
- int tref = luaL_ref(L,LUA_REGISTRYINDEX);
- iguielements[nbut] = 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.iguibutton");
- lua_setmetatable(L, -2);
-
- //Create the struct
- lbut->e = nbut;
- lbut->funcmap = hashmap_new();
- lbut->type = "iguibutton";
-
- //Free up anything made in the function
- free(button_label);
- free(button_tooltip);
-
- //Put it on top and return it
- lua_rawgeti(L,LUA_REGISTRYINDEX,tref);
- return 1;
+ printf("Createing gui button!\n");
+
+ int nargs = lua_gettop(L);
+ IGUIElement* parent = NULL;
+ if(nargs == 4){
+ parent = (IGUIElement*)lua_touserdata(L,-1);
+ lua_pop(L,1);
+ }
+
+
+ const char* label_c = lua_tostring(L,-1);
+ const wchar_t* label_w = irr::core::stringw(label_c).c_str();
+ lua_pop(L,1);
+
+ long x,y,w,h;
+ popvector2i(L,&w,&h);
+ popvector2i(L,&x,&y);
+
+ rect<s32> dim = rect<s32>(x,y,x+w,y+h);
+ IGUIEnvironment* env = device->getGUIEnvironment();
+ IGUIButton* but = env->addButton(dim,parent,-2,label_w,L"");
+
+ lua_pushlightuserdata(L,but);//
+ luaL_getmetatable(L,"gui.iguibutton");
+ lua_setmetatable(L,-2);
+
+ registerguicallback(but,EGET_BUTTON_CLICKED,iguibuttonevent);
+ printf("Finished registering callback\n");
+
+ return 1;
}
static const luaL_reg iguibutton_f[] = {
- {"new", newiguibutton},
- {"gethandeler", guigethandeler},
- {"sethandeler", guisethandeler},
- {0,0},
+ {"new", newiguibutton},
+ {"gethandeler", guigethandeler},
+ {"sethandeler", guisethandeler},
+ {0,0},
};
static const luaL_reg iguibutton_m[] = {
- {"move", moveiguielement},
- {"settext", setiguitext},
- {"remove", removeiguielement},
- {0,0},
+ {"move", moveiguielement},
+ {"settext", setiguitext},
+ {"remove", removeiguielement},
+ {0,0},
};
-int iguibutton_register(lua_State* L, IrrlichtDevice* d){
- //device = d;
- tL = L;
+int iguibutton_register(lua_State* L){
+ tL = L;
- luaL_newmetatable(L, "gui.iguibutton");
+ luaL_newmetatable(L, "gui.iguibutton");//{m_iguibutton}
+ lua_newtable(L);//{m_iguibutton},{}
+ luaL_register(L,NULL,iguibutton_m);//{m_iguibutton},{}
+ lua_setfield(L,-2,"__index");//{m_iguibutton}
- luaL_register(L,"iguibutton",iguibutton_f);
+ lua_pop(L,1);
- lua_pushstring(L,"__index");
- lua_pushstring(L,"gethandeler");
- lua_gettable(L,-3);
- lua_settable(L,-4);
+ lua_getglobal(L,"gui");
+ lua_pushcfunction(L,newiguibutton);
+ lua_setfield(L,-2,"newbutton");
- lua_pushstring(L,"__newindex");
- lua_pushstring(L,"sethandeler");
- lua_gettable(L,-3);
- lua_settable(L,-4);
-
- luaL_register(L, NULL, iguibutton_m);
-
- return 1;
+ lua_pop(L,1);
}
diff --git a/src/client/lua_api/gui/iguibutton.hpp b/src/client/lua_api/gui/iguibutton.hpp
index 4059767..abccbf0 100644
--- a/src/client/lua_api/gui/iguibutton.hpp
+++ b/src/client/lua_api/gui/iguibutton.hpp
@@ -8,4 +8,4 @@ extern "C" {
}
#include <irrlicht.h>
-int iguibutton_register(lua_State* L, irr::IrrlichtDevice* d);
+int iguibutton_register(lua_State* L);
diff --git a/src/client/lua_api/gui/iguicheckbox.cpp b/src/client/lua_api/gui/iguicheckbox.cpp
index c6e5955..74dd12e 100644
--- a/src/client/lua_api/gui/iguicheckbox.cpp
+++ b/src/client/lua_api/gui/iguicheckbox.cpp
@@ -10,21 +10,26 @@ extern "C" {
#include "../../../shared/lua_api/common.h"
using namespace irr;
+using namespace gui;
using namespace core;
extern IrrlichtDevice* device;
-//new({startx,starty},{endx,endy},"checkbox_name",parent)
+//new({startx,starty},{endx,endy},"checkbox_name"[,ud_parent])
int newiguicheckbox(lua_State* L){
- int parentid = lua_tointeger(L,-1);
- lua_pop(L,1);//{startx,starty},{endx,endy},"checkbox_name"
+ IGUIElement* par = 0;
+ if(lua_gettop(L) > 3){
+ par = (IGUIElement*)lua_touserdata(L,-1);//{startx,starty},{endx,endy},"checkbox_name",ud_parent
+ printf("Checkbox's parent was %s\n",par);
+ 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());
+ irr::gui::IGUICheckBox* cb = device->getGUIEnvironment()->addCheckBox(false,core::rect<int>(startx,starty,endx,endy),par,-1,stringw(text).c_str());
lua_pushlightuserdata(L,cb);//*checkbox
luaL_getmetatable(L,"gui.checkbox");//*checkbox,m{gui.checkbox}
lua_setmetatable(L,-2);//*checkbox
@@ -48,7 +53,6 @@ int iguicheckbox_register(lua_State* L){//
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/iguielement.cpp b/src/client/lua_api/gui/iguielement.cpp
index c01fa70..436bf93 100644
--- a/src/client/lua_api/gui/iguielement.cpp
+++ b/src/client/lua_api/gui/iguielement.cpp
@@ -4,6 +4,9 @@ extern "C" {
#include <lauxlib.h>
#include <lualib.h>
}
+
+
+#include "../../../shared/lua_api/common.h"
#include <irrlicht.h>
#include "../guiparts.hpp"
@@ -22,6 +25,41 @@ static LIGUIElement* toiguielement(lua_State* L){
return toiguielement(L,1);
}
+//move({element},{x,y}) -> nil
+int moveiguielement(lua_State* L){
+ //printf("Got call to move element\n");
+ long x,y;
+ popvector2i(L,&x,&y); //{element}
+ //printf("I want to move to %d %d\n",x,y);
+ lua_getfield(L,-1,"guielement");//{element},*element
+ IGUIElement *el = (IGUIElement*)lua_touserdata(L,-1);
+ //printf("Found element to move: %p\n",el);
+ lua_pop(L,2);//
+
+ el->move(position2d<s32>(x,y));
+ el->updateAbsolutePosition();
+ return 0;
+}
+
+//getabsrect({element})-> {{sx,sy},{ex,ey}}
+int getiguiclippingrect(lua_State* L){
+ printf("Getting iguiclipping elemnt\n");
+ lua_getfield(L,-1,"guielement");
+ IGUIElement *el = (IGUIElement*)lua_touserdata(L,-1);
+ core::rect<s32> rect = el->getAbsoluteClippingRect();
+ position2d<s32> ul = rect.UpperLeftCorner;
+ position2d<s32> lr = rect.LowerRightCorner;
+ lua_newtable(L);
+ lua_pushnumber(L,1);
+ double sx,sy,ex,ey;
+ pushvector2i(L,ul.X,ul.Y);
+ lua_settable(L,-3);
+ lua_pushnumber(L,2);
+ pushvector2i(L,lr.X,lr.Y);
+ lua_settable(L,-3);
+ return 1;
+}
+/*
int moveiguielement(lua_State* L){
LIGUIElement* ele = toiguielement(L,1);
int x = luaL_optint(L,2,0);
@@ -29,6 +67,7 @@ int moveiguielement(lua_State* L){
ele->e->move(position2d<s32>(x,y));
return 0;
}
+*/
int setiguitext(lua_State* L){
LIGUIElement* ele = toiguielement(L,1);
@@ -41,12 +80,13 @@ int setiguitext(lua_State* L){
return 0;
}
+//remove({self})
int removeiguielement(lua_State* L){
- LIGUIElement* ele = toiguielement(L,1);
- ele->e->remove();
- hashmap_free(ele->funcmap);
- free(ele);
- return 0;
+ lua_getfield(L,-1,"guielement");
+ IGUIElement *ele = (IGUIElement*)lua_touserdata(L,-1);
+ ele->remove();
+ lua_pop(L,2);
+ return 0;
}
int guigethandeler(lua_State* L){
diff --git a/src/client/lua_api/gui/iguielement.hpp b/src/client/lua_api/gui/iguielement.hpp
index a036fd5..84fc2c9 100644
--- a/src/client/lua_api/gui/iguielement.hpp
+++ b/src/client/lua_api/gui/iguielement.hpp
@@ -9,6 +9,7 @@ extern "C" {
#include <irrlicht.h>
int moveiguielement(lua_State* L);
+int getiguiclippingrect(lua_State* L);
int setiguitext(lua_State* L);
int removeiguielement(lua_State* L);
int guigethandeler(lua_State* L);
diff --git a/src/client/lua_api/gui/iguiimage.cpp b/src/client/lua_api/gui/iguiimage.cpp
index fea283b..370da68 100644
--- a/src/client/lua_api/gui/iguiimage.cpp
+++ b/src/client/lua_api/gui/iguiimage.cpp
@@ -31,33 +31,34 @@ extern IGUIEnvironment* env;
//EGUI_EVENT_TYPE etype = e.GUIEvent.EventType;
//printf("Detected image event\n");
//if(etype == EGET_ELEMENT_CLOSED){
- //lua_rawgeti(tL,LUA_REGISTRYINDEX,ref);
- //printf("getting raw, the thing on the top of stack is a %s\n",luaL_typename(tL,-1));
- //LIGUIElement* tbut = checkiguiwindow(tL,-1);
- //int hashmapresponse;
- //char* hashkey = (char*)"onclose";
- //int terror = hashmap_get(tbut->funcmap,hashkey,(void**)&hashmapresponse);
- //if(terror == MAP_OK){ //Only call if we actually have that function.
- //printf("Looks like we have an onclose function, calling!\n");
- //lua_rawgeti(tL,LUA_REGISTRYINDEX,hashmapresponse); //push the function
- //lua_rawgeti(tL,LUA_REGISTRYINDEX,ref); //push the referance to iguielement
- //lua_call(tL,1,1);
- ////int b = lua_isnoneornil(tL,1);
- //int a = lua_toboolean(tL,-1);
- //printf("a:%d\n",a);
- //return a;
- //}
+ //lua_rawgeti(tL,LUA_REGISTRYINDEX,ref);
+ //printf("getting raw, the thing on the top of stack is a %s\n",luaL_typename(tL,-1));
+ //LIGUIElement* tbut = checkiguiwindow(tL,-1);
+ //int hashmapresponse;
+ //char* hashkey = (char*)"onclose";
+ //int terror = hashmap_get(tbut->funcmap,hashkey,(void**)&hashmapresponse);
+ //if(terror == MAP_OK){ //Only call if we actually have that function.
+ //printf("Looks like we have an onclose function, calling!\n");
+ //lua_rawgeti(tL,LUA_REGISTRYINDEX,hashmapresponse); //push the function
+ //lua_rawgeti(tL,LUA_REGISTRYINDEX,ref); //push the referance to iguielement
+ //lua_call(tL,1,1);
+ ////int b = lua_isnoneornil(tL,1);
+ //int a = lua_toboolean(tL,-1);
+ //printf("a:%d\n",a);
+ //return a;
+ //}
//}
//printf("Oh no! an iguiimage generated an event!");
//return false;
//}
-//new({startx,starty},alpha,itexture)
+//new({startx,starty},alpha,{itexture}) -> {guielement}
static int newiguiimage(lua_State* L){
- printf("Creating iguiimage\n");
+ //printf("Creating iguiimage\n");
+ lua_getfield(L,-1,"texture");//{startx,starty},alpha,{itexture},*itexture
video::ITexture* tex = (video::ITexture*)lua_touserdata(L,-1);
- lua_pop(L,1);
+ lua_pop(L,2);//{startx,starty},alpha,
bool usealpha = lua_toboolean(L,-1);
lua_pop(L,1);
@@ -68,34 +69,49 @@ static int newiguiimage(lua_State* L){
IGUIEnvironment* env = device->getGUIEnvironment();
IGUIImage* img = env->addImage(tex,core::position2d<s32>(sx,sy),usealpha,0,-1,L"");
img->setImage(tex);
-
+
+ lua_newtable(L);
lua_pushlightuserdata(L,img);//ud_iguiimg
+ lua_setfield(L,-2,"guielement");
luaL_getmetatable(L,"iguiimage");//ud_iguiimg,{m_iguiimg}
- lua_setmetatable(L,-1);//ud_iguiimg
+ lua_setmetatable(L,-2);//ud_iguiimg
return 1;
}
+//setcolor(self,{r,g,b,a})
+int setcolor(lua_State* L){
+ long r,g,b,a;
+ popvector4i(L,&r,&g,&b,&a);
+ lua_getfield(L,-1,"guielement");
+ IGUIImage *img = (IGUIImage*)lua_touserdata(L,-1);
+ img->setColor(video::SColor(a,r,g,b));
+ lua_pop(L,2);
+ return 0;
+}
+
static const luaL_reg iguiimage_m[] = {
- //{"move", moveiguielement},
+ {"move", moveiguielement},
+ {"getabsrect", getiguiclippingrect},
+ {"setcolor", setcolor},
//{"settext", setiguitext},
- //{"remove", removeiguielement},
+ {"remove", removeiguielement},
{0, 0},
};
void iguiimage_register(lua_State* L){
- printf("Loading iguiimage\n");
+ //printf("Loading iguiimage\n");
luaL_newmetatable(L,"iguiimage");//{m_iguiimg}
- printf("made meta table\n");
+ //printf("made meta table\n");
lua_newtable(L);//{m_iguiimg},{}
luaL_register(L,NULL,iguiimage_m);//{m_iguiimg},{iguiimg_m}
- printf("About to set field\n");
+ //printf("About to set field\n");
lua_setfield(L,-2,"__index");//{m_iguiimg}
lua_pop(L,1);//
- printf("Got half way\n");
+ //printf("Got half way\n");
lua_getglobal(L,"gui");//{gui}
lua_pushcfunction(L,newiguiimage);//{gui},newimg()
lua_setfield(L,-2,"newiguiimage");//{gui}
lua_pop(L,1);//
- printf("Finished loading iguiimage\n");
+ //printf("Finished loading iguiimage\n");
}
diff --git a/src/client/lua_api/gui/iguiwindow.cpp b/src/client/lua_api/gui/iguiwindow.cpp
index 9a42dff..150ba68 100644
--- a/src/client/lua_api/gui/iguiwindow.cpp
+++ b/src/client/lua_api/gui/iguiwindow.cpp
@@ -20,82 +20,59 @@ extern "C" {
using namespace irr;
using namespace gui;
-//IrrlichtDevice* guidevice;
-
-static LIGUIElement* checkiguiwindow(lua_State* L, int index){
- void* ud = luaL_checkudata(L,index,"gui.iguiwindow");
- luaL_argcheck(L,ud != NULL, index, "'gui.iguiwindow' expected");
- return (LIGUIElement*) ud;
-}
+static bool iguiwindowevent(irr::SEvent e){
+ int ref = iguielements[e.GUIEvent.Caller];
+ lua_rawgeti(tL,LUA_REGISTRYINDEX,ref);
+ lua_getfield(tL,-1,"close");
-static LIGUIElement* checkiguiwindow(lua_State* L){
- return checkiguiwindow(L,1);
-}
+ lua_rawgeti(tL,LUA_REGISTRYINDEX,ref);
+ lua_call(tL,1,1);
-static bool iguiwindowevent(irr::SEvent e){
- IGUIElement* caller = (IGUIElement*)e.GUIEvent.Caller;
- int ref = iguielements[caller];
- EGUI_EVENT_TYPE etype = e.GUIEvent.EventType;
- printf("Detected window event\n");
- if(etype == EGET_ELEMENT_CLOSED){
- lua_rawgeti(tL,LUA_REGISTRYINDEX,ref);
- printf("getting raw, the thing on the top of stack is a %s\n",luaL_typename(tL,-1));
- LIGUIElement* tbut = checkiguiwindow(tL,-1);
- int hashmapresponse;
- char* hashkey = (char*)"onclose";
- int terror = hashmap_get(tbut->funcmap,hashkey,(void**)&hashmapresponse);
- if(terror == MAP_OK){ //Only call if we actually have that function.
- printf("Looks like we have an onclose function, calling!\n");
- lua_rawgeti(tL,LUA_REGISTRYINDEX,hashmapresponse); //push the function
- lua_rawgeti(tL,LUA_REGISTRYINDEX,ref); //push the referance to iguielement
- lua_call(tL,1,1);
- //int b = lua_isnoneornil(tL,1);
- int a = lua_toboolean(tL,-1);
- printf("a:%d\n",a);
- return a;
- }
- }
- printf("Oh no! an iguiwindow generated an event!");
- return false;
+ int shouldclose = lua_toboolean(tL,-1);
+ return shouldclose == 1;
}
-//new({width,height},{posx,posy},"title"[,parent])
+//new({posx,posy},{width,height},"title"[,parent])
static int newiguiwindow(lua_State* L){
- printf("Creating window\n");
-
+ IGUIElement* parent = NULL;
int numargs = lua_gettop(L);
-
- int parentid = lua_tointeger(L,-1);
- lua_pop(L,1);
+ if(numargs == 4){
+ parent = (IGUIElement*)lua_touserdata(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 position
long x,y,w,h;
- popvector2i(L,&x,&y);
popvector2i(L,&w,&h);
+ popvector2i(L,&x,&y);
- printf("I want to make a frame at (%d,%d) size (%d,%d)\n",x,y,w,h);
-
//Create the window
IGUIEnvironment* env = guidevice->getGUIEnvironment();
IGUIWindow* wi = env->addWindow(
core::rect<s32>(x,y,x+w,y+h),
false,
title_w,
- guielements[parentid],
+ parent,
-1
);
- lua_newtable(L);//{}
lua_pushlightuserdata(L,wi);
- lua_setfield(L,-2,"element");
-
- luaL_getmetatable(L,"gui.window");
- lua_setmetatable(L,-2);
+ lua_newtable(L);//{}
+ lua_pushlightuserdata(L,wi);//{},{ud_window}
+ lua_setfield(L,-2,"element");//{element=ud_window}
+
+ luaL_getmetatable(L,"gui.window");//{element=ud_window},{m_gui.window}
+ lua_setmetatable(L,-2);//{element=ud_window, __meta=gui.window}
+
+ int ref = luaL_ref(L,LUA_REGISTRYINDEX);//ref
+ lua_rawgeti(L,LUA_REGISTRYINDEX,ref);//ref,{element=ud_window, __meta=gui.window}
+ iguielements[wi] = ref;
+
registerguicallback(wi,EGET_ELEMENT_CLOSED,iguiwindowevent);
return 1;
}
@@ -105,11 +82,12 @@ static const luaL_reg iguiwindow_m[] = {
{"settext", setiguitext},
{"remove", removeiguielement},
{"getid", guigetid},
+// bool :: iguiwindow:close() -- Called when window is closed, returning
+// -- Anything but false or nil prevents close
{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);//
diff --git a/src/client/lua_api/load_gui.cpp b/src/client/lua_api/load_gui.cpp
index b2e941b..c90c8f5 100644
--- a/src/client/lua_api/load_gui.cpp
+++ b/src/client/lua_api/load_gui.cpp
@@ -40,7 +40,6 @@ void load_guifuncs(lua_State* L){
gui_elenum = 0;
guielements[0] = NULL;
- iguibutton_register(L,device);
iguilabel_register(L,device);
lua_pop(L, 1);
@@ -52,6 +51,7 @@ void load_guifuncs(lua_State* L){
iguicheckbox_register(L);
iguiwindow_register(L,device);
iguiimage_register(L);
+ iguibutton_register(L);
lua_pushcfunction(L,screenwidth);
lua_setglobal(L,"scrw");
@@ -65,13 +65,13 @@ void load_guifuncs(lua_State* L){
int screenheight(lua_State* L){
core::rect<s32> dim = guidevice->getGUIEnvironment()->getRootGUIElement()->getAbsoluteClippingRect();
lua_pushnumber(L,dim.getHeight());
- printf("Got screen height:%d\n",dim.getWidth());
+ //printf("Got screen height:%d\n",dim.getWidth());
return 1;
}
int screenwidth(lua_State* L){
core::rect<s32> dim = guidevice->getGUIEnvironment()->getRootGUIElement()->getAbsoluteClippingRect();
lua_pushnumber(L,dim.getWidth());
- printf("Got screen width:%d\n",dim.getWidth());
+ //printf("Got screen width:%d\n",dim.getWidth());
return 1;
}
diff --git a/src/client/lua_api/load_phys.cpp b/src/client/lua_api/load_phys.cpp
index 846d34c..23bb22a 100644
--- a/src/client/lua_api/load_phys.cpp
+++ b/src/client/lua_api/load_phys.cpp
@@ -10,13 +10,20 @@ extern "C" {
#include <irrlicht.h>
#include "../callbackhandeler.hpp"
+#include "phys/cbphysbox.hpp"
+#include "phys/bphysmodel.hpp"
using namespace irr;
using namespace gui;
using namespace core;
-extern IrrlichtDevice* d;
+extern IrrlichtDevice* device;
void load_physfuncs(lua_State* L){
- printf("Called load physfuncs...");
+ lua_newtable(L);//{}
+ lua_setglobal(L,"phys");//
+ //phys things
+ cbphysbox_register(L);
+
+ bphysmodel_register(L,device);
}
diff --git a/src/client/lua_api/load_scene.cpp b/src/client/lua_api/load_scene.cpp
index 342bc9a..c605581 100644
--- a/src/client/lua_api/load_scene.cpp
+++ b/src/client/lua_api/load_scene.cpp
@@ -11,8 +11,6 @@ extern "C" {
#include "scene/icamera.hpp"
#include "scene/imesh.hpp"
#include "scene/ilight.hpp"
-#include "phys/cbphysbox.hpp"
-#include "phys/bphysmodel.hpp"
using namespace irr;
@@ -27,12 +25,6 @@ void load_scenefuncs(lua_State* 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/load_video.cpp b/src/client/lua_api/load_video.cpp
index 8662aa0..df3a9aa 100644
--- a/src/client/lua_api/load_video.cpp
+++ b/src/client/lua_api/load_video.cpp
@@ -9,11 +9,72 @@ extern "C" {
#include "video/itexture.hpp"
#include "video/iimage.hpp"
+#include "shared/lua_api/common.h"
+
+using namespace irr;
+using namespace video;
+using namespace core;
+
+extern IrrlichtDevice* device;
+extern IVideoDriver* driver;
+
+//{texture},{x,y}
+//{texture},{x,y},{sourcerect},,{color},use_alpha
+int draw2dimage(lua_State* L){
+ int nargs = lua_gettop(L);
+ //printf("Drawing a 2d image\n");
+ if(nargs == 2){
+ //printf("2-argument version\n");
+ long x,y;
+ popvector2i(L,&x,&y);
+ lua_getfield(L,-1,"texture");
+ ITexture *tex = (ITexture*)lua_touserdata(L,-1);
+ lua_pop(L,2);
+ driver->draw2DImage(tex,position2d<s32>(x,y));
+ }else if(nargs == 5){
+ //printf("5-argument version\n");
+ int usealpha = lua_toboolean(L,-1);
+ lua_pop(L,1);
+ //printf("Got usealpha: %d\n",usealpha);
+ long r,g,b,a;
+ popvector4i(L,&r,&g,&b,&a);
+ long ssx,ssy,sex,sey;
+ poprecti(L,&ssx,&ssy,&sex,&sey);
+ long x,y;
+ popvector2i(L,&x,&y);
+ lua_getfield(L,-1,"texture");
+ ITexture *tex = (ITexture*)lua_touserdata(L,-1);
+ if(tex == NULL){
+ lua_pushstring(L,"Tried to draw a NULL texture");
+ lua_error(L);
+ }
+ lua_pop(L,2);
+ rect<s32> clipedto;
+ driver->draw2DImage(
+ tex,
+ position2d<s32>(x,y),
+ rect<s32>(ssx,ssy,sex,sey),
+ NULL,
+ SColor(a,r,g,b),
+ usealpha == 1
+ );
+ }else{
+ lua_pushstring(L,"Incorrect number of arguments to video.drawtexture() (expected 2 or 6)");
+ lua_error(L);
+ }
+ return 0;
+}
+
void load_videofuncs(lua_State* L){
- printf("Loading video libraries...\n");
+ //printf("Loading video libraries...\n");
lua_newtable(L);//{}
lua_setglobal(L,"video");//
+ lua_getglobal(L,"video");//{}
+ lua_pushcfunction(L,draw2dimage);//{},draw2dimage()
+ lua_setfield(L,-2,"drawtexture");//{}
+ lua_pop(L,1);//
+
smaterial_register(L);
itexture_register(L);
iimage_register(L);
diff --git a/src/client/lua_api/phys/bphysbuffer.cpp b/src/client/lua_api/phys/bphysbuffer.cpp
index 367aa37..aa2833a 100644
--- a/src/client/lua_api/phys/bphysbuffer.cpp
+++ b/src/client/lua_api/phys/bphysbuffer.cpp
@@ -280,7 +280,7 @@ int bphysmodel_register(lua_State* L, IrrlichtDevice* d){
device = d;
- printf("bphysmodel registered\n");
+ //printf("bphysmodel registered\n");
luaL_newmetatable(L, "phys.physmodel");
diff --git a/src/client/lua_api/phys/bphysmodel.cpp b/src/client/lua_api/phys/bphysmodel.cpp
index 424fdf8..95458b1 100644
--- a/src/client/lua_api/phys/bphysmodel.cpp
+++ b/src/client/lua_api/phys/bphysmodel.cpp
@@ -294,7 +294,7 @@ int bphysmodel_register(lua_State* L, IrrlichtDevice* d){
device = d;
- printf("bphysmodel registered\n");
+ //printf("bphysmodel registered\n");
luaL_newmetatable(L, "phys.physmodel");
diff --git a/src/client/lua_api/phys/cbphysbox.cpp b/src/client/lua_api/phys/cbphysbox.cpp
index 3e72672..6a3d64e 100644
--- a/src/client/lua_api/phys/cbphysbox.cpp
+++ b/src/client/lua_api/phys/cbphysbox.cpp
@@ -180,8 +180,8 @@ void cbphysbox_register(lua_State* L){
lua_pop(L,1);
- printf("When registering physbox, new() is %p\n",newcbphysbox);
- printf("setpos is %p\n",cbphyssetpos);
+ //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 ec9469d..dcdec2d 100644
--- a/src/client/lua_api/scene/icamera.cpp
+++ b/src/client/lua_api/scene/icamera.cpp
@@ -174,6 +174,5 @@ void icamera_register(lua_State* L){
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.cpp b/src/client/lua_api/scene/icube.cpp
index d18db2a..8f4c9d8 100644
--- a/src/client/lua_api/scene/icube.cpp
+++ b/src/client/lua_api/scene/icube.cpp
@@ -63,6 +63,6 @@ void icube_register(lua_State* L){
lua_setfield(L,-2,"newfpscamera");//{}
lua_pushcfunction(L,newiscenemayacamera);//{},newiscenemayacamera()
lua_setfield(L,-2,"newmayacamera");//{}
- printf("\"scene\" was set!\n");
+ //printf("\"scene\" was set!\n");
//lua_pop(L,1);
}
diff --git a/src/client/lua_api/video/iimage.cpp b/src/client/lua_api/video/iimage.cpp
index b832783..3090057 100644
--- a/src/client/lua_api/video/iimage.cpp
+++ b/src/client/lua_api/video/iimage.cpp
@@ -10,34 +10,71 @@ using namespace video;
extern IrrlichtDevice* device;
extern IVideoDriver* driver;
-//newiimage(ECOLOR_FORMAT,{width,height})
+//newiimage(ECOLOR_FORMAT,{width,height}) -> {image}
int newiimage(lua_State* L){
- printf("Attempting to create new iimage\n");
+ //printf("Attempting to create new iimage\n");
long w,h;
popvector2i(L,&w,&h);
int format = lua_tonumber(L,-1);
lua_pop(L,1);
- printf("All data collected, creating...\n");
+ //printf("All data collected, creating...\n");
IImage* img = driver->createImage((irr::video::ECOLOR_FORMAT)format,irr::core::dimension2d<u32>(w,h));
+ lua_newtable(L);
lua_pushlightuserdata(L,img);
+ lua_setfield(L,-2,"image");
luaL_getmetatable(L,"iimage");
lua_setmetatable(L,-2);
- printf("Everything sets up, returning\n");
+ //printf("Everything sets up, returning\n");
return 1;
}
-//setPixel({x,y},{r,g,b,a},bool_shouldblend)
+//newiimagefromfile("/path/to/file") -> {image}
+int newiimagefromfile(lua_State* L){
+ //printf("Creating new iimage from file");
+ const char* strpath = lua_tostring(L,-1);
+ lua_pop(L,1);
+ int numloaders = driver->getImageLoaderCount();
+ bool hasloaded = false;
+ IImage* img;
+ for(int j = 0; j < numloaders; j++){
+ IImageLoader* loader = driver->getImageLoader(j);
+ io::IReadFile* f = device->getFileSystem()->createAndOpenFile(strpath);
+ if(!loader->isALoadableFileExtension(strpath))
+ continue;
+ if(!loader->isALoadableFileFormat(f))
+ continue;
+ hasloaded = true;
+ img = loader->loadImage(f);
+ }
+ if(!hasloaded){
+ lua_pushstring(L,"Failed to load file");
+ lua_error(L);
+ }
+ if(!img){
+ lua_pushstring(L,"Failed to load image");
+ lua_error(L);
+ }
+ lua_newtable(L);
+ lua_pushlightuserdata(L,img);
+ lua_setfield(L,-2,"image");
+ luaL_getmetatable(L,"iimage");
+ lua_setmetatable(L,-2);
+ //printf("IImage made, returning!");
+ return 1;
+}
+
+//setPixel({self},{x,y},{r,g,b,a},bool_shouldblend)
int setiimagepixel(lua_State* L){
- printf("Setpixel called\n");
bool sb = lua_toboolean(L,-1);//{ud_iimage},{x,y},{r,g,b,a},bool_shouldblend
lua_pop(L,1);//{ud_iimage},{x,y},{r,g,b,a}
- long r,g,b,a;
- popvector4i(L,&r,&g,&b,&a);//{ud_iimage},{x,y}
+ double r,g,b,a;
+ popvector4d(L,&r,&g,&b,&a);//{ud_iimage},{x,y}
long x,y;
popvector2i(L,&x,&y);//{ud_iimage}
+ lua_getfield(L,-1,"image");
IImage* img = (IImage*)lua_touserdata(L,-1);//{ud_iimage}
img->setPixel(x,y,SColor(a,r,g,b),sb);
- lua_pop(L,1);
+ lua_pop(L,2);
return 0;
}
@@ -49,7 +86,6 @@ static const luaL_reg iimage_m[] = {
#define set_const(l,x) lua_pushstring(l,#x);lua_pushinteger(l,x);lua_settable(l,-3);
void iimage_register(lua_State* L){
- printf("Registering iimage...\n");
driver = device->getVideoDriver();
lua_getglobal(L,"video");//{}
@@ -66,6 +102,8 @@ void iimage_register(lua_State* L){
lua_pushcfunction(L,newiimage);//{},newiimage()
lua_setfield(L,-2,"newiimage");//{}
+ lua_pushcfunction(L,newiimagefromfile);//{},newiimagefromfile()
+ lua_setfield(L,-2,"newiimagefromfile");//{}
lua_pop(L,1);//
luaL_newmetatable(L,"iimage");//{m_iimage}
@@ -77,5 +115,4 @@ void iimage_register(lua_State* L){
lua_pop(L,1);//
- printf("registered iimage!\n");
}
diff --git a/src/client/lua_api/video/itexture.cpp b/src/client/lua_api/video/itexture.cpp
index a7f4652..42de1bd 100644
--- a/src/client/lua_api/video/itexture.cpp
+++ b/src/client/lua_api/video/itexture.cpp
@@ -14,20 +14,42 @@ using namespace video;
extern IrrlichtDevice* device;
extern IVideoDriver* driver;
-//newtexture(string name,IImage* image)
+//newtexture(string name,{image}) -> {texture}
int newitexture(lua_State* L){
+ //printf("About to create new texture\n");
+ lua_getfield(L,-1,"image");//"name",{image},image*
IImage* im = (IImage*) lua_touserdata(L,-1);
- lua_pop(L,1);
+ lua_pop(L,2);//"name"
const char* name = lua_tostring(L,-1);
- lua_pop(L,1);
+ lua_pop(L,1);//
+ //printf("About to create texture\n");
ITexture* tex = driver->addTexture(name,im);
if(!tex){
lua_pushstring(L,"Failed to create texture!");
lua_error(L);
}
+ lua_newtable(L);
+ lua_pushlightuserdata(L,tex);
+ lua_setfield(L,-2,"texture");
+
+ return 1;
+}
+
+//newtexturefromfile(string file_name) -> {texture}
+int newitexturefromfile(lua_State* L){
+ const char* strpath = lua_tostring(L,-1);
+ lua_pop(L,1);
+ ITexture* tex = driver->getTexture(strpath);
+ if(!tex){
+ lua_pushstring(L,"Failed to create texture!");
+ lua_error(L);
+ }
+
+ lua_newtable(L);
lua_pushlightuserdata(L,tex);
+ lua_setfield(L,-2,"texture");
return 1;
}
@@ -35,7 +57,10 @@ int newitexture(lua_State* L){
void itexture_register(lua_State* L){
- lua_getglobal(L,"video");
- lua_pushcfunction(L,newitexture);
- lua_setfield(L,-2,"newtexture");
+ lua_getglobal(L,"video");//{}
+ lua_pushcfunction(L,newitexture);//{},newitexture
+ lua_setfield(L,-2,"newtexture");//{}
+ lua_pushcfunction(L,newitexturefromfile);
+ lua_setfield(L,-2,"newtexturefromfile");
+ lua_pop(L,1);
}
diff --git a/src/client/main.cpp b/src/client/main.cpp
index fbe707b..9c22567 100644
--- a/src/client/main.cpp
+++ b/src/client/main.cpp
@@ -5,6 +5,7 @@ extern "C" {
#include <lauxlib.h>
#include <lualib.h>
}
+#define _IRR_STATIC_LIB_
#include <irrlicht.h>
#include <chrono>
@@ -109,7 +110,7 @@ int setbackgroundcolor(lua_State* L){
}
int main(int argc, char *argv[]){
- printf("Brok[en]gine Client");
+ printf("Brok[en]gine Client\n");
// Initialize bullet
phys_genesis();
@@ -120,11 +121,14 @@ int main(int argc, char *argv[]){
loadLLibs(state);
//Defined in initdevice.cpp, creates the irrlicht device
device = spawnIrrDevice(state);
+ ILogger* log = device->getLogger();
+ log->setLogLevel(ELL_NONE);
if (!device)
return 1;
//Loads libraries for interfaceing with irrlicht
loadIrrLibs(state,device);
loadNetLibs(state);
+ luaL_openlibs(state);
printf("Loadded irr libs...\n");
//Sets the global event handeler
GlobalEventReceiver ger = GlobalEventReceiver(device);
@@ -138,13 +142,13 @@ int main(int argc, char *argv[]){
//Load some bullet physics stuff
//Load some menu
- loadMenu("Some menu",device);
+ //loadMenu("Some menu",device);
driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
IGUIEnvironment* guienv = device->getGUIEnvironment();
- device->setWindowCaption(L"Brok[en]gine Client");
+ device->setWindowCaption(L"Brok[en]gine Client v0.1\n");
printf("Everything registered, about to start running device!\n");
@@ -164,6 +168,16 @@ int main(int argc, char *argv[]){
//UpdatePhysics(steps,UpdateElement);
//t1 = now;
driver->beginScene(true, true, background);
+
+ lua_getglobal(state,"GAME");
+ lua_getfield(state,-1,"draw");
+ if(!lua_isnil(state,-1)){
+ lua_call(state,0,0);
+ lua_pop(state,1);
+ }else{
+ lua_pop(state,2);
+ }
+
smgr->drawAll();
guienv->drawAll();
driver->endScene();
diff --git a/src/shared/lua_api/common.c b/src/shared/lua_api/common.c
index 9a8baca..2eeee11 100644
--- a/src/shared/lua_api/common.c
+++ b/src/shared/lua_api/common.c
@@ -153,6 +153,43 @@ int popvector3d(lua_State* L,double* a,double* b,double* c){
return 0;
}
+int popvector4d(lua_State* L, double *a, double *b, double *c, double *d){
+ lua_pushinteger(L,1);//{a,b,c,d},1
+ lua_gettable(L,-2);//{a,b,c,d},a
+ *a = lua_tonumber(L,-1);//{a,b,c,d},a
+ lua_pop(L,1);//{a,b,c,d}
+
+ lua_pushinteger(L,2);
+ lua_gettable(L,-2);
+ *b = lua_tonumber(L,-1);
+ lua_pop(L,1);
+
+ lua_pushinteger(L,3);
+ lua_gettable(L,-2);
+ *c = lua_tonumber(L,-1);
+ lua_pop(L,1);
+
+ lua_pushinteger(L,4);
+ lua_gettable(L,-2);
+ *d = lua_tonumber(L,-1);
+ lua_pop(L,1);
+
+ lua_pop(L,1);
+ return 0;
+}
+
+//{{sx,sy},{ex,ey}}
+int poprecti(lua_State* L, long *sx, long *sy, long *ex, long *ey){
+ lua_pushnumber(L,1);
+ lua_gettable(L,-2);
+ popvector2i(L,sx,sy);
+ lua_pushnumber(L,2);
+ lua_gettable(L,-2);
+ popvector2i(L,ex,ey);
+ lua_pop(L,1);
+ return 0;
+}
+
int popvector2i(lua_State* L, long* a, long* b){
lua_pushinteger(L,1);
lua_gettable(L,-2);
diff --git a/src/shared/lua_api/common.h b/src/shared/lua_api/common.h
index c2e067d..6086065 100644
--- a/src/shared/lua_api/common.h
+++ b/src/shared/lua_api/common.h
@@ -12,6 +12,9 @@ int pushvector3d(lua_State*,double,double,double);
int pushvector2i(lua_State*,long,long);
int popvector4i(lua_State*,long*,long*,long*,long*);
+int popvector4d(lua_State*,double*,double*,double*,double*);
int popvector3i(lua_State*,long*,long*,long*);
int popvector3d(lua_State*,double*,double*,double*);
int popvector2i(lua_State*,long*,long*);
+
+int poprecti(lua_State* L,long*,long*,long*,long*);
diff --git a/src/shared/lua_api/phys/bphysbox.cpp b/src/shared/lua_api/phys/bphysbox.cpp
index 78f1c45..0fe9f72 100644
--- a/src/shared/lua_api/phys/bphysbox.cpp
+++ b/src/shared/lua_api/phys/bphysbox.cpp
@@ -34,14 +34,14 @@ void makenewbphysbox(lua_State* L){
mass = lua_tonumber(L,-1);//{v3_size},{v3_origin},mass
lua_pop(L,1);//{v3_size},{v3_origin}
- printf("Got mass: %f\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);
+ //printf("Got position: (%f,%f,%f)\n",px,py,pz);
popvector3d(L,&sx,&sy,&sz);//
btVector3 vshape = btVector3(sx * 0.5f, sy * 0.5f, sz * 0.5f);
- printf("Got size: (%f,%f,%f)\n",sx,sy,sz);
+ //printf("Got size: (%f,%f,%f)\n",sx,sy,sz);
btVector3 pos = btVector3(px,py,pz);
// Set the initial position of the object
@@ -52,12 +52,12 @@ void makenewbphysbox(lua_State* L){
// Give it a default MotionState
btDefaultMotionState* motionstate = new btDefaultMotionState(transform);
if(!motionstate){
- printf("No motionstate\n");
+ //printf("No motionstate\n");
}
// Create the shape
btCollisionShape* shape = new btBoxShape(vshape);
if(!shape){
- printf("no shape\n");
+ //printf("no shape\n");
}
// Add mass
@@ -67,12 +67,12 @@ void makenewbphysbox(lua_State* L){
// Create the rigid body object
btRigidBody* rigidbody = new btRigidBody(mass, motionstate, shape, localinertia);
if(!rigidbody){
- printf("No rigidbody\n");
+ //printf("No rigidbody\n");
}
// Add it to the world
World->addRigidBody(rigidbody);
- printf("Added rigid body to world: %p\n",World);
+ //printf("Added rigid body to world: %p\n",World);
Objects.push_back(rigidbody);
lua_pushlightuserdata(L,rigidbody);//ud_rigidbody
@@ -80,7 +80,7 @@ void makenewbphysbox(lua_State* L){
// phys.newphysbox(vector3 size, vector3 origin, double mass)
int newbphysbox(lua_State* L){
- printf("Createing bphysbox!\n");
+ //printf("Createing bphysbox!\n");
//Create it's lua representation
makenewbphysbox(L);//ud_btRigidBody
btRigidBody* r = (btRigidBody*)lua_touserdata(L,-1);
@@ -98,7 +98,7 @@ int newbphysbox(lua_State* L){
//{phys.physbox}:delete()
static int delbphysbox(lua_State* L){//self
- printf("Attempting to delete physbox\n");
+ //printf("Attempting to delete physbox\n");
lua_getfield(L,-1,"rigidbody");//self,ud_rigidbody
btRigidBody* r = (btRigidBody*)lua_touserdata(L,-1);//self,ud_rigidbody
delete r->getCollisionShape();
@@ -130,7 +130,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");
+ //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();
@@ -149,7 +149,7 @@ static const luaL_reg bphysbox_m[] = {
};
void bphysbox_register(lua_State* L){//
- printf("Registered bphysbox\n");
+ //printf("Registered bphysbox\n");
luaL_newmetatable(L, "phys.physbox");//{phys.physbox}
lua_newtable(L);//{phys.physbox},{}
diff --git a/src/shared/phys/physcommon.cpp b/src/shared/phys/physcommon.cpp
index 4f506bb..b1c4c67 100644
--- a/src/shared/phys/physcommon.cpp
+++ b/src/shared/phys/physcommon.cpp
@@ -33,17 +33,17 @@ btSequentialImpulseConstraintSolver* Solver;
void phys_genesis(){
BroadPhase = new btAxisSweep3(btVector3(-1000,-1000,-1000),btVector3(1000,1000,1000));
- printf("Broadphase\n");
+ //printf("Broadphase\n");
CollisionConfiguration = new btDefaultCollisionConfiguration();
- printf("Collision config\n");
+ //printf("Collision config\n");
Dispatcher = new btCollisionDispatcher(CollisionConfiguration);
- printf("Dispatcher\n");
+ //printf("Dispatcher\n");
Solver = new btSequentialImpulseConstraintSolver();
- printf("Solver\n");
+ //printf("Solver\n");
World = new btDiscreteDynamicsWorld(Dispatcher, BroadPhase, Solver, CollisionConfiguration);
- printf("Physics world init ok.\n");
+ //printf("Physics world init ok.\n");
World->setGravity(btVector3(0,-10,0));
- printf("Created physics world: %p\n",World);
+ //printf("Created physics world: %p\n",World);
}
void phys_shutdown(void(*f)(btRigidBody*)){