aboutsummaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
authorAlexander Pickering <alexandermpickering@gmail.com>2018-03-09 23:55:49 -0500
committerAlexander Pickering <alexandermpickering@gmail.com>2018-03-09 23:55:49 -0500
commit2831e232b886c5e3b0791ea5192f9e5194e6abf3 (patch)
tree4fb9309d18f388673b7a21b8f0e927727006f585 /src/client
parent35b7c646fd7f80b64c1ef49b6d81f9df9bc1b940 (diff)
downloadbrokengine-2831e232b886c5e3b0791ea5192f9e5194e6abf3.tar.gz
brokengine-2831e232b886c5e3b0791ea5192f9e5194e6abf3.tar.bz2
brokengine-2831e232b886c5e3b0791ea5192f9e5194e6abf3.zip
Added IGUIImages
Added the ability to display itextures on the gui
Diffstat (limited to 'src/client')
-rw-r--r--src/client/callbackhandeler.cpp13
-rw-r--r--src/client/lua_api/gui/iguiimage.cpp100
-rw-r--r--src/client/lua_api/gui/iguiimage.hpp12
-rw-r--r--src/client/lua_api/gui/simple.cpp55
-rw-r--r--src/client/lua_api/gui/simple.hpp0
-rw-r--r--src/client/lua_api/load_gui.cpp2
-rw-r--r--src/client/lua_api/load_video.cpp21
-rw-r--r--src/client/lua_api/load_video.hpp14
-rw-r--r--src/client/lua_api/phys/cbphysbox.cpp54
-rw-r--r--src/client/lua_api/scene/icamera.cpp65
-rw-r--r--src/client/lua_api/scene/igeneric.cpp2
-rw-r--r--src/client/lua_api/scene/imesh.cpp2
-rw-r--r--src/client/lua_api/video/iimage.cpp81
-rw-r--r--src/client/lua_api/video/iimage.hpp8
-rw-r--r--src/client/lua_api/video/itexture.cpp41
-rw-r--r--src/client/lua_api/video/itexture.hpp8
-rw-r--r--src/client/lua_api/video/smaterial.cpp51
-rw-r--r--src/client/lua_api/video/smaterial.hpp8
-rw-r--r--src/client/main.cpp31
19 files changed, 495 insertions, 73 deletions
diff --git a/src/client/callbackhandeler.cpp b/src/client/callbackhandeler.cpp
index c548624..cf24cd2 100644
--- a/src/client/callbackhandeler.cpp
+++ b/src/client/callbackhandeler.cpp
@@ -31,6 +31,7 @@ GlobalEventReceiver::GlobalEventReceiver(IrrlichtDevice* d){
}
bool GlobalEventReceiver::OnEvent(const SEvent& e){
EEVENT_TYPE type = e.EventType;
+ //printf("Onevent called:%d\n",(int)type);
switch (type){
case EET_GUI_EVENT:{
IGUIElement* caller = e.GUIEvent.Caller;
@@ -48,12 +49,15 @@ 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");
+ 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;
}
@@ -68,11 +72,14 @@ bool GlobalEventReceiver::OnEvent(const SEvent& e){
lua_pushboolean(L,se.Control);
lua_pushboolean(L,se.Shift);
lua_call(L,4,0);
+ lua_pop(L,1);
+ }else{
+ lua_pop(L,2);
}
break;
}
default:
- //printf("Called an unknown event\n");
+ printf("Called an unknown event\n");
return false;
}
}
diff --git a/src/client/lua_api/gui/iguiimage.cpp b/src/client/lua_api/gui/iguiimage.cpp
new file mode 100644
index 0000000..c349c3e
--- /dev/null
+++ b/src/client/lua_api/gui/iguiimage.cpp
@@ -0,0 +1,100 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <vector>
+#include <memory>
+#include <map>
+#include <functional>
+extern "C" {
+ #include <lua.h>
+ #include <lauxlib.h>
+ #include <lualib.h>
+}
+#include <irrlicht.h>
+#include "../guiparts.hpp"
+#include "iguielement.hpp"
+#include "iguiwindow.hpp"
+#include "iguiutil.hpp"
+#include "../../callbackhandeler.hpp"
+#include "../../../shared/lua_api/common.h"
+
+using namespace irr;
+using namespace gui;
+
+extern IrrlichtDevice* device;
+extern IGUIEnvironment* env;
+//IrrlichtDevice* guidevice;
+
+
+//static bool iguiimageevent(irr::SEvent e){
+ //IGUIElement* caller = (IGUIElement*)e.GUIEvent.Caller;
+ //int ref = iguielements[caller];
+ //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;
+ //}
+ //}
+ //printf("Oh no! an iguiimage generated an event!");
+ //return false;
+//}
+
+//new({startx,starty},alpha,itexture)
+static int newiguiimage(lua_State* L){
+ printf("Creating iguiimage\n");
+
+ video::ITexture* tex = (video::ITexture*)lua_touserdata(L,-1);
+ lua_pop(L,1);
+
+ bool usealpha = lua_toboolean(L,-1);
+ lua_pop(L,1);
+
+ long sx,sy;
+ popvector2i(L,&sx,&sy);
+
+ IGUIEnvironment* env = device->getGUIEnvironment();
+ IGUIImage* img = env->addImage(tex,core::position2d<s32>(sx,sy),usealpha,0,-1,L"");
+ img->setImage(tex);
+
+ lua_pushlightuserdata(L,img);//ud_iguiimg
+ luaL_getmetatable(L,"iguiimage");//ud_iguiimg,{m_iguiimg}
+ lua_setmetatable(L,-1);//ud_iguiimg
+
+ return 1;
+}
+
+static const luaL_reg iguiimage_m[] = {
+ //{"move", moveiguielement},
+ //{"settext", setiguitext},
+ //{"remove", removeiguielement},
+ {0, 0},
+};
+
+void iguiimage_register(lua_State* L){
+ printf("Loading iguiimage\n");
+ luaL_newmetatable(L,"iguiimage");//{m_iguiimg}
+ lua_newtable(L);//{m_iguiimg},{}
+ luaL_register(L,NULL,iguiimage_m);//{m_iguiimg},{iguiimg_m}
+ printf("About to set field\n");
+ lua_setfield(L,-2,"__index");//{m_iguiimg}
+ lua_pop(L,1);//
+ 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");
+}
diff --git a/src/client/lua_api/gui/iguiimage.hpp b/src/client/lua_api/gui/iguiimage.hpp
new file mode 100644
index 0000000..7210ff0
--- /dev/null
+++ b/src/client/lua_api/gui/iguiimage.hpp
@@ -0,0 +1,12 @@
+
+
+#include <stdio.h>
+#include <stdlib.h>
+extern "C" {
+ #include <lua.h>
+ #include <lauxlib.h>
+ #include <lualib.h>
+}
+#include <irrlicht.h>
+
+int iguiimage_register(lua_State* L);
diff --git a/src/client/lua_api/gui/simple.cpp b/src/client/lua_api/gui/simple.cpp
new file mode 100644
index 0000000..8790069
--- /dev/null
+++ b/src/client/lua_api/gui/simple.cpp
@@ -0,0 +1,55 @@
+#include <irrlicht.h>
+extern "C" {
+ #include <lua.h>
+ #include <lauxlib.h>
+ #include <lualib.h>
+}
+
+// {{startx, starty},{endx,endy}}
+lua_torecti(lua_State* L, int number, int* sx, int* sy, int* ex, int* ey){
+ lua_pushnumber(L,1);// ...,{},...,1
+ lua_gettable(L,number);// ...,{{sx,sy},{ex,ey}},...,{sx,sy}
+
+ lua_pushnumber(L,1);// ...,{{sx,sy},{ex,ey}},...,{sx,sy},1
+ lua_gettable(L,-2);// ...,{{sx,sy},{ex,ey}},...,{sx,sy},sx
+ *sx = lua_tonumber(L,-1);// ...,{{sx,sy},{ex,ey}},...,{sx,sy},sx
+
+ lua_pop(1);// ...,{{sx,sy},{ex,ey}},...,{sx,sy}
+
+ lua_pushnumber(L,2);// ...,{{sx,sy},{ex,ey}},...,{sx,sy},2
+ lua_gettable(L,-2);// ...,{{sx,sy},{ex,ey}},...,{sx,sy},sy
+ *sy = lua_tonumber(L,-1);
+
+ lua_pop(2);// ...,{{sx,sy},{ex,ey}},...
+
+
+ lua_pushnumber(L,2);// ...,{{sx,sy},{ex,ey}},...,2
+ lua_gettable(L,number);// ...,{{sx,sy},{ex,ey}},...,{ex,ey}
+ lua_pushnumber(L,1);// ...,{{sx,sy},{ex,ey}},...,{ex,ey},1
+
+ lua_gettable(L,-2);// ...,{{sx,sy},{ex,ey}},...,{ex,ey},ex
+ *ex = lua_tonumber(L,-1);// ...,{{sx,sy},{ex,ey}},...,{ex,ey},ex
+ lua_pop(L,1);// ...,{{sx,sy},{ex,ey}},...,{ex,ey}
+
+ lua_pushnumber(L,2);// ...,{{sx,sy},{ex,ey}},...,{ex,ey},2
+ lua_gettable(L,-2);// ...,{{sx,sy},{ex,ey}},...,{ex,ey},ey
+ *ey = lua_tonumber(L,-1);// ...,{{sx,sy},{ex,ey}},...,{ex,ey},ey
+
+ lua_pop(L,2);// ...,{{sx,sy},{ex,ey}},...
+}
+
+int addIGUIButton(lua_State* L){
+ IGUIEnvironment env = lua_touserdata(L,1);
+ IGUIElement parent = lua_touserdata(L,2);
+ s32 id = lua_tonumber(L,3);
+ s32 sx,sy,ex,ey;
+ lua_torecti(L,4,&sx,&sy,&ex,&ey);
+ core::rect<s32> rect = core::rect<s32>(sx,sy,ex,ey);
+ IGUIElement* button = env->addButton(rect,parent,id,
+
+}
+
+void add_gui(lua_State* L){
+
+}
+
diff --git a/src/client/lua_api/gui/simple.hpp b/src/client/lua_api/gui/simple.hpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/client/lua_api/gui/simple.hpp
diff --git a/src/client/lua_api/load_gui.cpp b/src/client/lua_api/load_gui.cpp
index f8e8dc0..86c95cc 100644
--- a/src/client/lua_api/load_gui.cpp
+++ b/src/client/lua_api/load_gui.cpp
@@ -15,6 +15,7 @@ extern "C" {
#include "gui/iguiwindow.hpp"
#include "gui/iguiskin.hpp"
#include "gui/iguicheckbox.hpp"
+#include "gui/iguiimage.hpp"
#include "../callbackhandeler.hpp"
#include "guiparts.hpp"
@@ -52,6 +53,7 @@ void load_guifuncs(lua_State* L){
lua_setglobal(L,"gui");
iguicheckbox_register(L);
iguiwindow_register(L,device);
+ iguiimage_register(L);
lua_pushcfunction(L,screenwidth);
lua_setglobal(L,"scrw");
diff --git a/src/client/lua_api/load_video.cpp b/src/client/lua_api/load_video.cpp
new file mode 100644
index 0000000..8662aa0
--- /dev/null
+++ b/src/client/lua_api/load_video.cpp
@@ -0,0 +1,21 @@
+
+extern "C" {
+ #include <lua.h>
+ #include <lauxlib.h>
+ #include <lualib.h>
+}
+#include <irrlicht.h>
+#include "video/smaterial.hpp"
+#include "video/itexture.hpp"
+#include "video/iimage.hpp"
+
+void load_videofuncs(lua_State* L){
+ printf("Loading video libraries...\n");
+ lua_newtable(L);//{}
+ lua_setglobal(L,"video");//
+
+ smaterial_register(L);
+ itexture_register(L);
+ iimage_register(L);
+
+}
diff --git a/src/client/lua_api/load_video.hpp b/src/client/lua_api/load_video.hpp
new file mode 100644
index 0000000..c80129e
--- /dev/null
+++ b/src/client/lua_api/load_video.hpp
@@ -0,0 +1,14 @@
+#ifndef __H_loadvideo
+#define __H_loadvideo
+#include <stdio.h>
+#include <stdlib.h>
+#include <vector>
+extern "C" {
+ #include <lua.h>
+ #include <lauxlib.h>
+ #include <lualib.h>
+}
+#include <irrlicht.h>
+
+void load_videofuncs(lua_State* L);
+#endif
diff --git a/src/client/lua_api/phys/cbphysbox.cpp b/src/client/lua_api/phys/cbphysbox.cpp
index 029e6ab..6cbd749 100644
--- a/src/client/lua_api/phys/cbphysbox.cpp
+++ b/src/client/lua_api/phys/cbphysbox.cpp
@@ -61,6 +61,8 @@ static int newcbphysbox(lua_State* L){//
ISceneNode* n = (ISceneNode*)lua_touserdata(L,-1);//ud_iscenenode
lua_pop(L,1);
+ r->setUserPointer(n);
+
lua_newtable(L);//{}
lua_pushlightuserdata(L,r);//{},ud_rigidbody
lua_setfield(L,-2,"rigidbody");//{}
@@ -75,36 +77,68 @@ static int newcbphysbox(lua_State* L){//
//bphysbox:setpos({v3 pos})
int cbphyssetpos(lua_State* L){//{rigidbody=ud_btRigidbody,node=ud_iscenenode},{v3 pos}
- printf("calling cbphysbox setpos\n");
+ //printf("calling cbphysbox setpos\n");
double x,y,z;
popvector3d(L,&x,&y,&z);//{rigidbody=ud_btRigidbody,node=ud_iscenenode}
- printf("Getting rigidbody\n");
+ //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);
+ //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);
+ //printf("Got node, it was %p\n",i);
lua_pop(L,2);//
- btTransform bt;
+ btTransform bt = btTransform(btQuaternion(0,0,0,1), btVector3(x,y,z));
btMotionState* ms = r->getMotionState();
- ms->getWorldTransform(bt);
- bt.setOrigin(btVector3(x,y,z));
ms->setWorldTransform(bt);
- r->activate();
+ r->setWorldTransform(bt);
+
+ r->activate(true);
- i->setPosition(vector3df(x,y,z));
- i->updateAbsolutePosition();
+ //i->setPosition(vector3df(x,y,z));
+ //i->updateAbsolutePosition();
return 0;
}
+//bphysbox:getpos()
+int cbphysgetpos(lua_State* L){//{rigidbody=ud_btRigidbody,node=ud_iscenenode}
+ //printf("cphysgetpos called, stack size is %d\n",lua_gettop(L));
+ lua_getfield(L,-1,"rigidbody");//{rigidbody=ud_btRigidbody,node=ud_iscenenode}, ud_rigidbody
+ btRigidBody* r = (btRigidBody*) lua_touserdata(L,-1);
+ lua_pop(L,2);
+ btTransform bt = r->getCenterOfMassTransform();
+ btVector3 p = bt.getOrigin();
+ pushvector3d(L,p.x(),p.y(),p.z());
+ return 1;
+}
+
+int cbphysgetgravity(lua_State* L){
+ lua_getfield(L,-1,"rigidbody");//{rigidbody=ud_btRigidbody,node=ud_iscenenode}, ud_rigidbody
+ btRigidBody* r = (btRigidBody*) lua_touserdata(L,-1);
+ lua_pop(L,2);
+ btVector3 p = r->getGravity();
+ pushvector3d(L,p.x(),p.y(),p.z());
+ return 1;
+}
+
+int cbphysapplygravity(lua_State* L){
+ lua_getfield(L,-1,"rigidbody");//{rigidbody=ud_btRigidbody,node=ud_iscenenode}, ud_rigidbody
+ btRigidBody* r = (btRigidBody*) lua_touserdata(L,-1);
+ lua_pop(L,2);
+ r->applyGravity();
+ return 0;
+}
+
static const luaL_reg cbphysbox_m[] = {
{"setcpos", cbphyssetpos},//overload
+ {"getcpos", cbphysgetpos},
+ {"getgravity", cbphysgetgravity},
+ {"applygravity",cbphysapplygravity},
// {"delete", delbphysbox},//client side delete needs to delete the visual representation
{0, 0},
};
diff --git a/src/client/lua_api/scene/icamera.cpp b/src/client/lua_api/scene/icamera.cpp
index 3c5e2b0..ec9469d 100644
--- a/src/client/lua_api/scene/icamera.cpp
+++ b/src/client/lua_api/scene/icamera.cpp
@@ -14,6 +14,7 @@ extern "C" {
#include "../gameparts.hpp"
#include "icamera.hpp"
#include "igeneric.hpp"
+#include "../../../shared/lua_api/common.h"
using namespace irr;
using namespace scene;
@@ -97,60 +98,33 @@ static int newiscenefpscamera(lua_State* L){//
static int newiscenecamera(lua_State* L){
printf("Createing camera!\n");
int nargs = lua_gettop(L);
+ double px,py,pz;
+ double lx,ly,lz;
+
+ int parent = lua_tonumber(L,-1);
+ lua_pop(L,1);
//The position of the camera
- int startx = luaL_optint(L,1,0);
- int starty = luaL_optint(L,2,0);
- int startz = luaL_optint(L,3,0);
- int endx = luaL_optint(L,4,startx+100);
- int endy = luaL_optint(L,5,starty+100);
- int endz = luaL_optint(L,6,startz+100);
-
- //Label and tooltip
- wchar_t* label;
- const char* labelopt = luaL_optstring(L,5,"Label");
- int bls = strlen(labelopt);
- label = (wchar_t*)malloc(sizeof(wchar_t)*(bls));
- mbstowcs(label,labelopt,bls);
- printf("Got the string option\n");
-
+ popvector3d(L,&px,&py,&pz);
+ printf("position of camera was %f,%f,%f\n",px,py,pz);
+ popvector3d(L,&lx,&ly,&lz);
+ printf("lookat of camera was %f,%f,%f\n",lx,ly,lz);
+
//If the element has a parrent
- if(nargs >= 6){
- printf("got the parrent\n");
+ if(nargs >= 3){
+ printf("got the parrent\n");
}
//Create the camera
ISceneManager* smgr = device->getSceneManager();
- //IGUIEnvironment* env = device->getGUIEnvironment();
- //printf("Createing button with data %d %d %d %d, %p, %d, %s, %s\n", startx,starty,endx,endy,guielements[parent],gui_elenum,button_label,button_tooltip);
- //Create the label
- //IGUIStaticText* llabel = (IGUIStaticText*) env->addStaticText(label,core::rect<s32>(startx,starty,endx,endy),false,false, guielements[parent], gui_elenum++, false);
- ICameraSceneNode* cam = smgr->addCameraSceneNode(0, vector3df(startx,starty,startz), vector3df(endx,endy,endz));
+ ICameraSceneNode* cam = smgr->addCameraSceneNode(0, vector3df(px,py,pz), vector3df(lx,ly,lz));
printf("Registered the camera!\n");
+ lua_newtable(L);
+ lua_pushlightuserdata(L,cam);
+ lua_setfield(L,-2,"node");
+ luaL_getmetatable(L,"scene.icamera");
+ lua_setmetatable(L,-2);
- //Register it's callback
- //registerguicallback(llabel,EGET_ELEMENT_HOVERED,iguilabelevent);
-
- //Create it's lua representation
- LISceneNode* lcam = (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.iscenecamera");
- lua_setmetatable(L, -2);
-
- //Create the struct
- lcam->n = cam;
- lcam->funcmap = hashmap_new();
- lcam->type = "iscenecamera";
-
- //Free up anything made in this function
- //free(label);
-
- //Put it on top and return it
- lua_rawgeti(L,LUA_REGISTRYINDEX,tref);
return 1;
}
@@ -167,6 +141,7 @@ static const luaL_reg imayacamera_m[] = {
};
static const luaL_reg ifpscamera_m[] = {
+ {"getpos", iscenegetpos},
{0,0},
};
diff --git a/src/client/lua_api/scene/igeneric.cpp b/src/client/lua_api/scene/igeneric.cpp
index 0d061d2..8280008 100644
--- a/src/client/lua_api/scene/igeneric.cpp
+++ b/src/client/lua_api/scene/igeneric.cpp
@@ -43,7 +43,7 @@ int iscenesetpos(lua_State* L){//{node=ud_IMeshSceneNode},{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);
+ //printf("After setting pos, new pos is %f %f %f",pos.X,pos.Y,pos.Z);
lua_pop(L,2);//
return 0;
}
diff --git a/src/client/lua_api/scene/imesh.cpp b/src/client/lua_api/scene/imesh.cpp
index 3f3ae24..f391431 100644
--- a/src/client/lua_api/scene/imesh.cpp
+++ b/src/client/lua_api/scene/imesh.cpp
@@ -71,7 +71,7 @@ void makenewiscenecube(lua_State* L){
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));
+ IMeshSceneNode* n = device->getSceneManager()->addCubeSceneNode(1,0,-1,core::vector3df(x,y,z),core::vector3df(0,0,0),core::vector3df(sx,sy,sz));
lua_pushlightuserdata(L,n);
}
diff --git a/src/client/lua_api/video/iimage.cpp b/src/client/lua_api/video/iimage.cpp
new file mode 100644
index 0000000..b832783
--- /dev/null
+++ b/src/client/lua_api/video/iimage.cpp
@@ -0,0 +1,81 @@
+
+#include "iimage.hpp"
+#include <irrlicht.h>
+
+#include "../../../shared/lua_api/common.h"
+
+using namespace irr;
+using namespace video;
+
+extern IrrlichtDevice* device;
+extern IVideoDriver* driver;
+
+//newiimage(ECOLOR_FORMAT,{width,height})
+int newiimage(lua_State* L){
+ 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");
+ IImage* img = driver->createImage((irr::video::ECOLOR_FORMAT)format,irr::core::dimension2d<u32>(w,h));
+ lua_pushlightuserdata(L,img);
+ luaL_getmetatable(L,"iimage");
+ lua_setmetatable(L,-2);
+ printf("Everything sets up, returning\n");
+ return 1;
+}
+
+//setPixel({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}
+ long x,y;
+ popvector2i(L,&x,&y);//{ud_iimage}
+ IImage* img = (IImage*)lua_touserdata(L,-1);//{ud_iimage}
+ img->setPixel(x,y,SColor(a,r,g,b),sb);
+ lua_pop(L,1);
+ return 0;
+}
+
+static const luaL_reg iimage_m[] = {
+ {"setPixel", setiimagepixel},
+ {0,0},
+};
+
+#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");//{}
+
+ set_const(L,ECF_A1R5G5B5);
+ set_const(L,ECF_R5G6B5);
+ set_const(L,ECF_A8R8G8B8);
+ set_const(L,ECF_R16F);
+ set_const(L,ECF_G16R16F);
+ set_const(L,ECF_A16B16G16R16F);
+ set_const(L,ECF_R32F);
+ set_const(L,ECF_G32R32F);
+ set_const(L,ECF_A32B32G32R32F);
+ set_const(L,ECF_UNKNOWN);
+
+ lua_pushcfunction(L,newiimage);//{},newiimage()
+ lua_setfield(L,-2,"newiimage");//{}
+ lua_pop(L,1);//
+
+ luaL_newmetatable(L,"iimage");//{m_iimage}
+
+ lua_newtable(L);//{m_iimage},{}
+ luaL_register(L,NULL,iimage_m);//{m_iimage},{iimage}
+
+ lua_setfield(L,-2,"__index");//{m_iimage}
+
+ lua_pop(L,1);//
+
+ printf("registered iimage!\n");
+}
diff --git a/src/client/lua_api/video/iimage.hpp b/src/client/lua_api/video/iimage.hpp
new file mode 100644
index 0000000..d5890e4
--- /dev/null
+++ b/src/client/lua_api/video/iimage.hpp
@@ -0,0 +1,8 @@
+
+extern "C" {
+ #include <lua.h>
+ #include <lauxlib.h>
+ #include <lualib.h>
+}
+
+void iimage_register(lua_State* L);
diff --git a/src/client/lua_api/video/itexture.cpp b/src/client/lua_api/video/itexture.cpp
new file mode 100644
index 0000000..a7f4652
--- /dev/null
+++ b/src/client/lua_api/video/itexture.cpp
@@ -0,0 +1,41 @@
+
+extern "C" {
+ #include <lua.h>
+ #include <lauxlib.h>
+ #include <lualib.h>
+}
+#include <irrlicht.h>
+#include "itexture.hpp"
+#include "iimage.hpp"
+#include "../../../shared/lua_api/common.h"
+
+using namespace irr;
+using namespace video;
+
+extern IrrlichtDevice* device;
+extern IVideoDriver* driver;
+//newtexture(string name,IImage* image)
+int newitexture(lua_State* L){
+ IImage* im = (IImage*) lua_touserdata(L,-1);
+ lua_pop(L,1);
+ const char* name = lua_tostring(L,-1);
+ lua_pop(L,1);
+
+ ITexture* tex = driver->addTexture(name,im);
+ if(!tex){
+ lua_pushstring(L,"Failed to create texture!");
+ lua_error(L);
+ }
+
+ lua_pushlightuserdata(L,tex);
+
+ return 1;
+}
+
+
+
+void itexture_register(lua_State* L){
+ lua_getglobal(L,"video");
+ lua_pushcfunction(L,newitexture);
+ lua_setfield(L,-2,"newtexture");
+}
diff --git a/src/client/lua_api/video/itexture.hpp b/src/client/lua_api/video/itexture.hpp
new file mode 100644
index 0000000..35d7174
--- /dev/null
+++ b/src/client/lua_api/video/itexture.hpp
@@ -0,0 +1,8 @@
+
+extern "C" {
+ #include <lua.h>
+ #include <lauxlib.h>
+ #include <lualib.h>
+}
+
+void itexture_register(lua_State* L);
diff --git a/src/client/lua_api/video/smaterial.cpp b/src/client/lua_api/video/smaterial.cpp
new file mode 100644
index 0000000..e5b9eff
--- /dev/null
+++ b/src/client/lua_api/video/smaterial.cpp
@@ -0,0 +1,51 @@
+
+extern "C" {
+ #include <lua.h>
+ #include <lauxlib.h>
+ #include <lualib.h>
+}
+#include <irrlicht.h>
+#include "smaterial.hpp"
+
+using namespace irr::video;
+
+/*This probably needs a _gc metamethod*/
+int newsmaterial(lua_State* L){
+ SMaterial* mat = new SMaterial();
+ lua_pushlightuserdata(L,mat);
+
+ return 0;
+}
+
+#define set_const(l,x) lua_pushstring(l,#x);lua_pushinteger(l,x);lua_settable(l,-3);
+
+void smaterial_register(lua_State* L){
+ //Add globals dealing with material flags
+
+ lua_getglobal(L,"video");//{}
+
+ set_const(L,EMF_WIREFRAME);
+ set_const(L,EMF_POINTCLOUD);
+ set_const(L,EMF_GOURAUD_SHADING);
+ set_const(L,EMF_LIGHTING);
+ set_const(L,EMF_ZBUFFER);
+ set_const(L,EMF_ZWRITE_ENABLE);
+ set_const(L,EMF_BACK_FACE_CULLING);
+ set_const(L,EMF_FRONT_FACE_CULLING);
+ set_const(L,EMF_BILINEAR_FILTER);
+ set_const(L,EMF_TRILINEAR_FILTER);
+ set_const(L,EMF_ANISOTROPIC_FILTER);
+ set_const(L,EMF_FOG_ENABLE);
+ set_const(L,EMF_NORMALIZE_NORMALS);
+ set_const(L,EMF_TEXTURE_WRAP);
+ set_const(L,EMF_ANTI_ALIASING);
+ set_const(L,EMF_COLOR_MASK);
+ set_const(L,EMF_COLOR_MATERIAL);
+ set_const(L,EMF_USE_MIP_MAPS);
+ set_const(L,EMF_BLEND_OPERATION);
+ set_const(L,EMF_POLYGON_OFFSET);
+
+ lua_pushcfunction(L,newsmaterial);//{},newsmaterial
+ lua_setfield(L,-2,"newsmaterial");
+
+}
diff --git a/src/client/lua_api/video/smaterial.hpp b/src/client/lua_api/video/smaterial.hpp
new file mode 100644
index 0000000..7457d69
--- /dev/null
+++ b/src/client/lua_api/video/smaterial.hpp
@@ -0,0 +1,8 @@
+
+extern "C" {
+ #include <lua.h>
+ #include <lauxlib.h>
+ #include <lualib.h>
+}
+
+void smaterial_register(lua_State* L);
diff --git a/src/client/main.cpp b/src/client/main.cpp
index 2d30c70..54aafc0 100644
--- a/src/client/main.cpp
+++ b/src/client/main.cpp
@@ -18,6 +18,7 @@ extern "C" {
#include "lua_api/load_game.hpp"
#include "lua_api/load_scene.hpp"
#include "lua_api/load_phys.hpp"
+#include "lua_api/load_video.hpp"
#include "callbackhandeler.hpp"
#include "../shared/lua_api/common.h"
@@ -37,13 +38,23 @@ using namespace std::chrono;
lua_State* L;
IrrlichtDevice* device;
-
+IVideoDriver* driver;
void loadIrrLibs(lua_State* L, IrrlichtDevice* device){
- printf("Loading guifuncs...\n");
+ printf("Loading guifuncs...");
load_guifuncs(L);
+ printf("[OK]\n");
+ printf("Loading gamefuncs...");
load_gamefuncs(L);
+ printf("[OK]\n");
+ printf("Loading scenefuncs...");
load_scenefuncs(L);
+ printf("[OK]\n");
+ printf("Loading physfuncs...");
load_physfuncs(L);
+ printf("[OK]\n");
+ printf("Loading videofuncs...");
+ load_videofuncs(L);
+ printf("[OK]\n");
}
void RemoveISceneNode(btRigidBody* rb){
@@ -70,6 +81,7 @@ 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());
@@ -83,6 +95,7 @@ void UpdateElement(btRigidBody* TObject){
QuaternionToEuler(TObject->getOrientation(), EulerRotation);
Node->setRotation(core::vector3df(EulerRotation[0], EulerRotation[1], EulerRotation[2]));
}
+
}
int main(int argc, char *argv[]){
@@ -117,20 +130,18 @@ int main(int argc, char *argv[]){
//Load some menu
loadMenu("Some menu",device);
- IVideoDriver* driver = device->getVideoDriver();
+ driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
IGUIEnvironment* guienv = device->getGUIEnvironment();
- device->setWindowCaption(L"Bork[en]gine Client");
+ device->setWindowCaption(L"Brok[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();
@@ -138,35 +149,29 @@ int main(int argc, char *argv[]){
//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);
}
+ //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;
}