aboutsummaryrefslogtreecommitdiff
path: root/src/client/lua_api
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/lua_api')
-rw-r--r--src/client/lua_api/gameparts.hpp1
-rw-r--r--src/client/lua_api/gui/iguigeneric.cpp27
-rw-r--r--src/client/lua_api/gui/iguigeneric.hpp11
-rw-r--r--src/client/lua_api/gui/iguilabel.cpp3
-rw-r--r--src/client/lua_api/load_core.cpp31
-rw-r--r--src/client/lua_api/load_core.hpp4
-rw-r--r--src/client/lua_api/load_gui.cpp4
-rw-r--r--src/client/lua_api/scene/icamera.cpp72
-rw-r--r--src/client/lua_api/scene/igeneric.cpp70
-rw-r--r--src/client/lua_api/scene/igeneric.hpp15
-rw-r--r--src/client/lua_api/scene/imesh.cpp131
-rw-r--r--src/client/lua_api/scene/imesh.hpp11
12 files changed, 324 insertions, 56 deletions
diff --git a/src/client/lua_api/gameparts.hpp b/src/client/lua_api/gameparts.hpp
index e6f02a1..2938ee2 100644
--- a/src/client/lua_api/gameparts.hpp
+++ b/src/client/lua_api/gameparts.hpp
@@ -1,3 +1,4 @@
+#include "../util/hashmap.h"
extern "C" {
#include <lua.h>
#include <lauxlib.h>
diff --git a/src/client/lua_api/gui/iguigeneric.cpp b/src/client/lua_api/gui/iguigeneric.cpp
new file mode 100644
index 0000000..7f39fdc
--- /dev/null
+++ b/src/client/lua_api/gui/iguigeneric.cpp
@@ -0,0 +1,27 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <vector>
+#include <memory>
+#include <map>
+#include <string>
+#include <functional>
+extern "C" {
+ #include <lua.h>
+ #include <lauxlib.h>
+ #include <lualib.h>
+}
+#include <irrlicht.h>
+#include "../guiparts.hpp"
+#include "iguielement.hpp"
+#include "../../callbackhandeler.hpp"
+#include "../../util/hashmap.h"
+
+using namespace irr;
+using namespace gui;
+
+extern IrrlichtDevice* device;
+
+int iguigeneric_register(lua_State* L, IrrlichtDevice* d){
+
+ return 0;
+}
diff --git a/src/client/lua_api/gui/iguigeneric.hpp b/src/client/lua_api/gui/iguigeneric.hpp
new file mode 100644
index 0000000..287fb4e
--- /dev/null
+++ b/src/client/lua_api/gui/iguigeneric.hpp
@@ -0,0 +1,11 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <vector>
+extern "C" {
+ #include <lua.h>
+ #include <lauxlib.h>
+ #include <lualib.h>
+}
+#include <irrlicht.h>
+
+int iguigeneric_register(lua_State* L, irr::IrrlichtDevice* d);
diff --git a/src/client/lua_api/gui/iguilabel.cpp b/src/client/lua_api/gui/iguilabel.cpp
index da720f9..3754ac6 100644
--- a/src/client/lua_api/gui/iguilabel.cpp
+++ b/src/client/lua_api/gui/iguilabel.cpp
@@ -61,11 +61,10 @@ static int newiguilabel(lua_State* L){
//Create the button
IGUIEnvironment* env = guidevice->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);
printf("Created the button\n");
-
+
//Register it's callback
registerguicallback(llabel,EGET_ELEMENT_HOVERED,iguilabelevent);
diff --git a/src/client/lua_api/load_core.cpp b/src/client/lua_api/load_core.cpp
index 910115f..2109fd5 100644
--- a/src/client/lua_api/load_core.cpp
+++ b/src/client/lua_api/load_core.cpp
@@ -3,30 +3,21 @@
#include <vector>
#include <map>
extern "C" {
- #include <lua.h>
- #include <lauxlib.h>
- #include <lualib.h>
+ #include <lua.h>
+ #include <lauxlib.h>
+ #include <lualib.h>
}
#include <irrlicht.h>
+#include "scene/icamera.hpp"
+#include "scene/imesh.hpp"
-int makevector(lua_State* L){
- lua_newtable(L);
-
- lua_pushstring("x");
- lua_optint(L,1,0);
- lua_settable(L,-2);
-
- lua_pushstring("y");
- lua_optint(L,2,0);
- lua_settable(L,-2);
-
- lua_pushstring("z");
- lua_optint(L,3,0);
- lua_settable(L,-2);
-
-}
+using namespace irr;
void load_corefuncs(lua_State* L, IrrlichtDevice* d){
+ icamera_register(L,d);
+ imesh_register(L,d);
+ lua_pop(L, 1);
+
lua_newtable(L);
- lua_setglobal(L,"GAME");
+ lua_setglobal(L,"scene");
}
diff --git a/src/client/lua_api/load_core.hpp b/src/client/lua_api/load_core.hpp
index 641ca08..6280484 100644
--- a/src/client/lua_api/load_core.hpp
+++ b/src/client/lua_api/load_core.hpp
@@ -1,5 +1,5 @@
-#ifndef __H_loadgame
-#define __H_loadgame
+#ifndef __H_loadcore
+#define __H_loadcore
#include <stdio.h>
#include <stdlib.h>
#include <vector>
diff --git a/src/client/lua_api/load_gui.cpp b/src/client/lua_api/load_gui.cpp
index ed7faac..49c40e4 100644
--- a/src/client/lua_api/load_gui.cpp
+++ b/src/client/lua_api/load_gui.cpp
@@ -11,6 +11,7 @@ extern "C" {
#include "gui/iguibutton.hpp"
#include "gui/iguilabel.hpp"
+#include "gui/iguigeneric.hpp"
#include "../callbackhandeler.hpp"
#include "guiparts.hpp"
@@ -33,11 +34,10 @@ void load_guifuncs(lua_State* L, IrrlichtDevice* d){
guidevice = d;
gui_elenum = 0;
guielements[0] = NULL;
- printf("About to initalize guielements vector\n");
- printf("Done initalizeing guilements vector\n");
iguibutton_register(L,d);
iguilabel_register(L,d);
+ iguigeneric_register(L,d);
lua_pop(L, 1);
lua_newtable(L);
diff --git a/src/client/lua_api/scene/icamera.cpp b/src/client/lua_api/scene/icamera.cpp
index 2dd5a67..ce54ef2 100644
--- a/src/client/lua_api/scene/icamera.cpp
+++ b/src/client/lua_api/scene/icamera.cpp
@@ -13,11 +13,13 @@ extern "C" {
#include <irrlicht.h>
#include "../gameparts.hpp"
#include "icamera.hpp"
+#include "igeneric.hpp"
using namespace irr;
using namespace scene;
+using namespace core;
-//IrrlichtDevice* guidevice;
+extern IrrlichtDevice* device;
static LISceneNode* checkiscenecamera(lua_State* L, int index){
void* ud = luaL_checkudata(L,index,"scene.icamera");
@@ -36,8 +38,10 @@ static int newiscenecamera(lua_State* L){
//The position of the camera
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);
+ 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;
@@ -48,65 +52,73 @@ static int newiscenecamera(lua_State* L){
printf("Got the string option\n");
//If the element has a parrent
- int parent = 0;
+ int parent = -1;
if(nargs >= 6){
- parent = luaL_optint(L,6,0);
+ parent = luaL_optint(L,7,0);
printf("got the parrent\n");
}
- //Create the button
- IGUIEnvironment* env = guidevice->getGUIEnvironment();
+ //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);
- printf("Created the button\n");
+ //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));
+ printf("Registered the camera!\n");
//Register it's callback
- registerguicallback(llabel,EGET_ELEMENT_HOVERED,iguilabelevent);
+ //registerguicallback(llabel,EGET_ELEMENT_HOVERED,iguilabelevent);
//Create it's lua representation
- LIGUIElement* ltext = (LIGUIElement*)lua_newuserdata(L, sizeof(LIGUIElement));
+ LISceneNode* lcam = (LISceneNode*)lua_newuserdata(L, sizeof(LISceneNode));
int tref = luaL_ref(L,LUA_REGISTRYINDEX);
- iguielements[llabel] = tref;
- lua_rawgeti(L,LUA_REGISTRYINDEX,tref);//Put it back on the stack since luaL_ref pops the object.
+ //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, "gui.iguilabel");
+ luaL_getmetatable(L, "scene.iscenecamera");
lua_setmetatable(L, -2);
//Create the struct
- ltext->e = llabel;
- ltext->funcmap = hashmap_new();
- ltext->type = "iguilabel";
+ lcam->n = cam;
+ lcam->funcmap = hashmap_new();
+ lcam->type = "iscenecamera";
//Free up anything made in this function
- free(label);
+ //free(label);
//Put it on top and return it
lua_rawgeti(L,LUA_REGISTRYINDEX,tref);
return 1;
}
-static const luaL_reg iguilabel_f[] = {
- {"new", newiguilabel},
- {"gethandeler", guigethandeler},
- {"sethandeler", guisethandeler},
+static const luaL_reg icamera_f[] = {
+ {"new", newiscenecamera},
+// {"gethandeler", guigethandeler},
+// {"sethandeler", guisethandeler},
{0,0},
};
-static const luaL_reg iguilabel_m[] = {
- {"move", moveiguielement},
- {"settext", setiguitext},
- {"remove", removeiguielement},
+static const luaL_reg icamera_m[] = {
+ {"getpos", iscenegetpos},
+ {"setpos", iscenesetpos},
+// {"move", moveiguielement},
+// {"settext", setiguitext},
+// {"remove", removeiguielement},
{0, 0},
};
-int iguilabel_register(lua_State* L, IrrlichtDevice* d){
+int icamera_register(lua_State* L, IrrlichtDevice* d){
- luaL_newmetatable(L, "gui.iguilabel");
+ device = d;
- luaL_register(L,"iguilabel",iguilabel_f);
+ printf("icamera registered\n");
+
+ luaL_newmetatable(L, "scene.icamera");
+
+ luaL_register(L,"icamera",icamera_f);
lua_pushstring(L,"__index");
lua_pushstring(L,"gethandeler");
@@ -118,7 +130,7 @@ int iguilabel_register(lua_State* L, IrrlichtDevice* d){
lua_gettable(L,-3);
lua_settable(L,-4);
- luaL_register(L, NULL, iguilabel_m);
+ luaL_register(L, NULL, icamera_m);
return 1;
}
diff --git a/src/client/lua_api/scene/igeneric.cpp b/src/client/lua_api/scene/igeneric.cpp
new file mode 100644
index 0000000..51aaf66
--- /dev/null
+++ b/src/client/lua_api/scene/igeneric.cpp
@@ -0,0 +1,70 @@
+/*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 "igeneric.hpp"
+#include "../gameparts.hpp"
+
+using namespace irr;
+using namespace core;
+using namespace scene;
+
+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;
+ vector3df pos = i->getAbsolutePosition();
+
+ 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);
+
+ lua_pushnumber(L,3);
+ lua_pushnumber(L,pos.Z);
+ lua_settable(L,-3);
+
+ 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;
+}
diff --git a/src/client/lua_api/scene/igeneric.hpp b/src/client/lua_api/scene/igeneric.hpp
new file mode 100644
index 0000000..848709b
--- /dev/null
+++ b/src/client/lua_api/scene/igeneric.hpp
@@ -0,0 +1,15 @@
+#ifndef __H_iscenegeneric
+#define __H_iscenegeneric
+#include <stdio.h>
+#include <stdlib.h>
+extern "C" {
+ #include <lua.h>
+ #include <lauxlib.h>
+ #include <lualib.h>
+}
+#include <irrlicht.h>
+
+int iscenegetpos(lua_State* L);
+int iscenesetpos(lua_State* L);
+
+#endif
diff --git a/src/client/lua_api/scene/imesh.cpp b/src/client/lua_api/scene/imesh.cpp
new file mode 100644
index 0000000..c2b6510
--- /dev/null
+++ b/src/client/lua_api/scene/imesh.cpp
@@ -0,0 +1,131 @@
+
+#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 "../gameparts.hpp"
+#include "imesh.hpp"
+#include "igeneric.hpp"
+
+using namespace irr;
+using namespace scene;
+using namespace core;
+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");
+ return (LISceneNode*) ud;
+}
+
+/*
+static LISceneNode* checkismesh(lua_State* L){
+ return checkismesh(L,1);
+}
+*/
+
+//iscenecamera.new(Vector position, Vector lookat, parrent)
+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 );
+ 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;
+}
+
+/*mesh:setmaterial("string",layernum=0)*/
+static int setmaterial(lua_State* L){
+ LISceneNode* n = checkismesh(L,1);
+ u32 layernum = luaL_optint(L,3,0);
+ const char* matfile = luaL_optstring(L,2,"error.png");
+ printf("Setting material on a %s",n->type);
+ IVideoDriver* driver = device->getVideoDriver();
+ n->n->setMaterialTexture( 0, driver->getTexture(matfile) );
+ return 0;
+}
+
+static const luaL_reg imesh_f[] = {
+ {"new", newiscenemesh},
+// {"gethandeler", guigethandeler},
+// {"sethandeler", guisethandeler},
+ {0,0},
+};
+
+static const luaL_reg imesh_m[] = {
+ {"setMaterial", setmaterial},
+ {"getpos", iscenegetpos},
+ {"setpos", iscenesetpos},
+// {"settext", setiguitext},
+// {"remove", removeiguielement},
+ {0, 0},
+};
+
+int imesh_register(lua_State* L, IrrlichtDevice* d){
+
+ device = d;
+
+ printf("imesh registered\n");
+
+ luaL_newmetatable(L, "scene.imesh");
+
+ luaL_register(L,"imesh",imesh_f);
+
+ 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);
+
+ luaL_register(L, NULL, imesh_m);
+
+ return 1;
+}
diff --git a/src/client/lua_api/scene/imesh.hpp b/src/client/lua_api/scene/imesh.hpp
new file mode 100644
index 0000000..bd33c07
--- /dev/null
+++ b/src/client/lua_api/scene/imesh.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>
+
+int imesh_register(lua_State* L, irr::IrrlichtDevice* d);