aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile25
-rw-r--r--src/client/callbackhandeler.cpp2
-rw-r--r--src/client/initdevice.cpp2
-rw-r--r--src/client/lua_api/gui/iguielement.cpp27
-rw-r--r--src/client/lua_api/load_gui.cpp42
-rw-r--r--src/client/lua_api/load_video.cpp2
-rw-r--r--src/client/lua_api/phys/cbphysbox.cpp12
-rw-r--r--src/client/lua_api/phys/cbphysmodel.cpp281
-rw-r--r--src/client/lua_api/scene/imesh.cpp3
-rw-r--r--src/client/main.cpp3
-rw-r--r--src/shared/lua_api/common.cpp15
-rw-r--r--src/shared/lua_api/common.hpp3
-rw-r--r--src/shared/lua_api/load_common.cpp8
-rw-r--r--src/shared/lua_api/load_common.hpp11
-rw-r--r--src/shared/lua_api/load_net.cpp13
-rw-r--r--src/shared/lua_api/phys/bcollider.cpp47
-rw-r--r--src/shared/lua_api/phys/bghostobject.cpp12
-rw-r--r--src/shared/lua_api/phys/bhingeconstraint.cpp6
-rw-r--r--src/shared/lua_api/phys/bphysbox.cpp1
-rw-r--r--src/shared/lua_api/phys/bphysgeneric.cpp41
-rw-r--r--src/shared/lua_api/phys/bphysmodel.cpp32
-rw-r--r--src/shared/phys/physcommon.cpp1
22 files changed, 373 insertions, 216 deletions
diff --git a/Makefile b/Makefile
index 25dc478..63845f4 100644
--- a/Makefile
+++ b/Makefile
@@ -7,6 +7,11 @@ else
endif
CP=cp
+CXX?=g++
+MKDIR?=mkdir
+RM?=rm -f
+ECHO?=echo
+
ifeq ($(UNAME), Windows)
EXE_EXT=.exe
STA_LIB_EXT=.a
@@ -42,10 +47,6 @@ BINS+= $(foreach part,$(EX_PARTS),$(BIN_DIR)/$(part)/bin/$(EX_PRE)$(part)$(EXE_E
BUILDS = $(EX_PARTS:%=$(BUILD_DIR)/%)
SRC_DIRS = $(EX_PARTS:%=$(SRC_DIR)/%)
-CXX?=g++
-MKDIR?=mkdir
-RM?=rm -f
-ECHO?=echo
LLUADIR=$(LIB_DIR)/luajit
LIRRDIR=$(LIB_DIR)/irrlicht
@@ -151,7 +152,7 @@ all : $(BINS)
# The shared stuff
LAPI_S_PHYS = bhingeconstraint bphysbox bphysmodel bphysgeneric bcharactercontroller bghostobject bcollider
-LAPI_S_LOAD = load_phys load_net common stream
+LAPI_S_LOAD = load_phys load_net common stream load_common
LAPI_PATHS_T = $(LAPI_S_PHYS:%=lua_api/phys/%) $(LAPI_S_LOAD:%=lua_api/%)
SHARED_CLIENT_FILES = $(LAPI_PATHS_T) phys/physcommon util/hashmap util/tinyobj
SHARED_CLIENT_OBJS = $(SHARED_CLIENT_FILES:%=$(BUILD_DIR)/$(CLIENTNAME)/%.o)
@@ -179,7 +180,7 @@ $(BUILD_DIR)/$(CLIENTNAME)/main.o : $(SRC_DIR)/client/main.cpp
@$(CXX) $(CXXFLAGS) -c -o $@ $^
# does have the .hpp associated in src/client
-$(CLIENT_SRCS) : $(BUILD_DIR)/$(CLIENTNAME)/%.o : src/client/%.cpp $(SRC_DIR)/client/%.hpp
+$(CLIENT_SRCS) : $(BUILD_DIR)/$(CLIENTNAME)/%.o : src/client/%.cpp $(SRC_DIR)/client/%.hpp $(LIB_OBJS)
@echo "[CLIENT] CXX $<"
@$(CXX) $(CXXFLAGS) -c -o $@ $<
@@ -234,7 +235,7 @@ endif
ifeq ($(DEBUG),true)
else
- IRRMAKEFLAGS+=NDEBUG=1
+ IRRMAKEFLAGS+=NDEBUG=1
endif
# Library - Irrlicht
@@ -242,7 +243,7 @@ $(LIB_S_IRR) : $(IRRMADELIB)/libIrrlicht.a
$(CP) $^ $@
$(IRRMADELIB)/libIrrlicht.a : $(LIRRDIR)/source/Irrlicht/Makefile
- sed --in-place=OLD '107s/ -ld3dx9d//' lib/irrlicht/source/Irrlicht/Makefile
+ sed --in-place=OLD 's/ -ld3dx9d//' lib/irrlicht/source/Irrlicht/Makefile
cd $(LIRRDIR)/source/Irrlicht && $(MAKE) $(IRRMAKEFLAGS)
$(LIB_D_IRR) : $(IRRMADELIB)/Irrlicht$(DYN_LIB_EXT)
@@ -253,7 +254,7 @@ $(BIN_DIR)/$(CLIENTNAME)/bin/Irrlicht$(DYN_LIB_EXT) : $(IRRMADELIB)/Irrlicht$(DY
$(CP) $^ $@
$(IRRMADELIB)/Irrlicht$(DYN_LIB_EXT) : $(LIRRDIR)/source/Irrlicht/Makefile
- sed --in-place=OLD '107s/ -ld3dx9d//' lib/irrlicht/source/Irrlicht/Makefile
+ sed --in-place=OLD 's/ -ld3dx9d//' lib/irrlicht/source/Irrlicht/Makefile
cd $(LIRRDIR)/source/Irrlicht && $(MAKE) $(IRRMAKEFLAGS)
ifeq ($(UNAME),Windows)
@@ -317,16 +318,18 @@ $(LNNGDIR)/dynamic/Makefile : $(LNNGDIR)/CMakeLists.txt
cd $(LNNGDIR)/dynamic && cmake $(CMAKE_FLAGS) -DBUILD_SHARED_LIBS="TRUE" ../
$(LIB_S_NNG) : $(LNNGDIR)/static/libnng$(STA_LIB_EXT)
- cp $< $@
+ $(CP) $< $@
$(LIB_D_NNG) : $(LNNGDIR)/dynamic/libnng$(DYN_LIB_EXT)
- cp $< $@
+ $(CP) $< $@
$(LNNGDIR)/static/libnng$(STA_LIB_EXT) : $(LNNGDIR)/static/Makefile
cd $(LNNGDIR)/static && $(MAKE) nng
+ ln -s $(LNNGDIR)/src $(LNNGDIR)/include/nng
$(LNNGDIR)/dynamic/libnng$(DYN_LIB_EXT) : $(LNNGDIR)/dynamic/Makefile
cd $(LNNGDIR)/dynamic && $(MAKE) nng
+ ln -s $(LNNGDIR)/src $(LNNGDIR)/include/nng
$(LNNGDIR)/Makefile : $(LNNGDIR)/CMakeLists.txt
@echo "LIB_OBJS were $(LIB_OBJS)"
diff --git a/src/client/callbackhandeler.cpp b/src/client/callbackhandeler.cpp
index 3b069a4..0f1f87f 100644
--- a/src/client/callbackhandeler.cpp
+++ b/src/client/callbackhandeler.cpp
@@ -68,7 +68,7 @@ bool GlobalEventReceiver::OnEvent(const SEvent& e){
//lua_State* L = this->L;
EEVENT_TYPE type = e.EventType;
SEvent::SMouseInput se = e.MouseInput;
- printf("Onevent called:%d\n",(int)type);
+ //printf("Onevent called:%d\n",(int)type);
switch (type){
case EET_GUI_EVENT:{
//printf("Gui event\n");
diff --git a/src/client/initdevice.cpp b/src/client/initdevice.cpp
index c7535a0..3720d49 100644
--- a/src/client/initdevice.cpp
+++ b/src/client/initdevice.cpp
@@ -96,8 +96,6 @@ void parseSetting(const char* settingname, lua_State* L, settings* set){
set->driver = EDT_SOFTWARE;
}else if(strcmp(dts,"BURNINGS") == 0){
set->driver = EDT_BURNINGSVIDEO;
- }else if(strcmp(dts,"D3D8") == 0){
- set->driver = EDT_DIRECT3D8;
}else if(strcmp(dts,"D3D9") == 0){
set->driver = EDT_DIRECT3D9;
}else if(strcmp(dts,"OPENGL") == 0){
diff --git a/src/client/lua_api/gui/iguielement.cpp b/src/client/lua_api/gui/iguielement.cpp
index 9254ba0..db7669a 100644
--- a/src/client/lua_api/gui/iguielement.cpp
+++ b/src/client/lua_api/gui/iguielement.cpp
@@ -236,6 +236,31 @@ int getelementenabled(lua_State *L){
return 1;
}
+//{guielement},{guielement}
+int sendtofront(lua_State *L){
+ lua_getfield(L,-1,"guielement");
+ IGUIElement *ele = (IGUIElement*)lua_touserdata(L,-1);
+ lua_pop(L,2);//{guielement}
+
+ lua_getfield(L,-1,"guielement");
+ IGUIElement *ele2 = (IGUIElement*)lua_touserdata(L,-1);
+ lua_pop(L,2);//
+ ele->bringToFront(ele2);
+ return 0;
+}
+
+//{guielement},{guielement}
+int sendtoback(lua_State *L){
+ lua_getfield(L,-1,"guielement");
+ IGUIElement *ele = (IGUIElement*)lua_touserdata(L,-1);
+ lua_pop(L,2);//{guielement}
+
+ lua_getfield(L,-1,"guielement");
+ IGUIElement *ele2 = (IGUIElement*)lua_touserdata(L,-1);
+ lua_pop(L,2);//
+ ele->sendToBack(ele2);
+ return 0;
+}
class guicallback{
private:
@@ -291,5 +316,7 @@ extern const luaL_reg iguielement_m[] = {
{"remove", removeiguielement},
{"focus", focus},
{"enable", setelementenabled},
+ {"sendfront", sendtofront},
+ {"sendback", sendtoback},
{NULL, NULL}
};
diff --git a/src/client/lua_api/load_gui.cpp b/src/client/lua_api/load_gui.cpp
index 845661a..64b9711 100644
--- a/src/client/lua_api/load_gui.cpp
+++ b/src/client/lua_api/load_gui.cpp
@@ -25,6 +25,7 @@ extern "C" {
#include "gui/iguispinbox.hpp"
#include "gui/iguitreeview.hpp"
#include "gui/iguicombobox.hpp"
+#include "gui/iguielement.hpp"
#include "../callbackhandeler.hpp"
#include "guiparts.hpp"
@@ -43,6 +44,7 @@ lua_State* tL;
int screenwidth(lua_State* L);
int screenheight(lua_State* L);
+int getroot(lua_State *L);
/***
@function gui.scrw()
@@ -72,7 +74,12 @@ void load_guifuncs(lua_State* L){
//Various enums
lua_newtable(L);
+
+ lua_pushcfunction(L,getroot);
+ lua_setfield(L,-2,"getroot");
+
lua_setglobal(L,"gui");
+
iguilabel_register(L);
iguicheckbox_register(L);
iguiwindow_register(L,device);
@@ -90,19 +97,38 @@ void load_guifuncs(lua_State* L){
lua_pushcfunction(L,screenheight);
lua_setglobal(L,"scrh");
+
+ luaL_newmetatable(L, "gui.iguielement");//{m_iguielement}
+ lua_newtable(L);//{m_iguibutton},{}
+ luaL_register(L,NULL,iguielement_m);
+ lua_setfield(L,-2,"__index");//{m_iguielement}
+ lua_pop(L,1);
+
}
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());
- return 1;
+ core::rect<s32> dim = guidevice->getGUIEnvironment()->getRootGUIElement()->getAbsoluteClippingRect();
+ lua_pushnumber(L,dim.getHeight());
+ //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());
- return 1;
+ core::rect<s32> dim = guidevice->getGUIEnvironment()->getRootGUIElement()->getAbsoluteClippingRect();
+ lua_pushnumber(L,dim.getWidth());
+ //printf("Got screen width:%d\n",dim.getWidth());
+ return 1;
+}
+
+//Get the root gui element
+int getroot(lua_State* L){
+ IGUIElement *ele = device->getGUIEnvironment()->getRootGUIElement();
+ lua_newtable(L);//{}
+ lua_pushlightuserdata(L,ele);//{},ud_iguibutton
+ lua_setfield(L,-2,"guielement");//{guielement}
+ luaL_getmetatable(L,"gui.iguielement");//{guielement},{m_iguibutton}
+ lua_setmetatable(L,-2);//{guielement}
+
+ return 1;
}
diff --git a/src/client/lua_api/load_video.cpp b/src/client/lua_api/load_video.cpp
index e0c7557..f309180 100644
--- a/src/client/lua_api/load_video.cpp
+++ b/src/client/lua_api/load_video.cpp
@@ -74,7 +74,7 @@ int draw2dline(lua_State* L){
popvector2i(L,&ex,&ey);
popvector2i(L,&sx,&sy);
- driver->draw2DLine(position2d<s32>(sx,sy),position2d<s32>(ex,ey),SColor(r,g,b,a));
+ driver->draw2DLine(position2d<s32>(sx,sy),position2d<s32>(ex,ey),SColor(a,r,g,b));
return 0;
}
diff --git a/src/client/lua_api/phys/cbphysbox.cpp b/src/client/lua_api/phys/cbphysbox.cpp
index c5aacd8..3c0f97d 100644
--- a/src/client/lua_api/phys/cbphysbox.cpp
+++ b/src/client/lua_api/phys/cbphysbox.cpp
@@ -51,15 +51,25 @@ static int newcbphysbox(lua_State* L){//
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_pop(L,1);//
r->setUserPointer(n);
lua_newtable(L);//{}
+
lua_pushlightuserdata(L,r);//{},ud_rigidbody
lua_setfield(L,-2,"collider");//{}
+ lua_pushstring(L,"rigidbody");//{},"rigidbody"
+ lua_setfield(L,-2,"type");//{}
lua_pushlightuserdata(L,n);//{},ud_iscenenode
lua_setfield(L,-2,"node");//{}
+
+ lua_getglobal(L,"phys");//{rb},{phys}
+ lua_getfield(L,-1,"colliders");//{rb},{phys},{phys.colliders}
+ lua_pushlightuserdata(L,r);//{rb},{phys},{colliders},ud_rb
+ lua_pushvalue(L,-4);//{rb},{phys},{colliders},ud_rb,{rb}
+ lua_settable(L,-3);//{rb},{phys},{phys.colliders}
+ lua_pop(L,2);//{rb}
luaL_getmetatable(L,"phys.physbox");//{},{phys.physbox}
lua_setmetatable(L,-2);//{}
diff --git a/src/client/lua_api/phys/cbphysmodel.cpp b/src/client/lua_api/phys/cbphysmodel.cpp
index 4f4c106..ac27288 100644
--- a/src/client/lua_api/phys/cbphysmodel.cpp
+++ b/src/client/lua_api/phys/cbphysmodel.cpp
@@ -19,6 +19,7 @@ extern "C" {
#include <client/lua_api/scene/igeneric.hpp>
#include <shared/lua_api/phys/bphysmodel.hpp>
#include <shared/lua_api/phys/bcollider.hpp>
+#include <shared/lua_api/phys/bphysgeneric.hpp>
#include <shared/lua_api/common.hpp>
#include <shared/util/tinyobj.hpp>
@@ -65,141 +66,148 @@ static int newbphysmodel(lua_State* L){
//Create the scene node
//IMeshBuffer *buf = new CDynamicMeshBuffer(E_VERTEX_TYPE::EVT_STANDARD,E_INDEX_TYPE::EIT_16BIT);
- IMeshBuffer *buf = new SMeshBuffer();
- tinyobj_attrib_t attrib;
- printf("At the very beginning, attrib is %p\n",(void*)&attrib);
- tinyobj_shape_t *shapes = NULL;
- size_t meshcount;
- tinyobj_material_t *materials = NULL;
- size_t num_materials;
-
- //Read data from the graphics file
- size_t data_len = 0;
- FILE *objfile = fopen(gpath,"rb");
- fseek(objfile,0,SEEK_END);
- data_len = ftell(objfile);
- printf("model data is %d long\n",(int)data_len);
- fseek(objfile,0,SEEK_SET);
- char *objdata = (char*)malloc(sizeof(char)*data_len);
- fread(objdata, sizeof(char), data_len, objfile);
- fclose(objfile);
-
- //Parse the data into a tinyobj
- printf("About to tinyobj_parse_obj\n");
- int err = tinyobj_parse_obj(&attrib, &shapes, &meshcount, &materials, &num_materials, objdata, data_len, TINYOBJ_FLAG_TRIANGULATE);
- free(objdata);
-
- //int err = tinyobj_parse_obj(&attrib, &shapes, &meshcount, &materials, &num_materials, objdata, data_len, 0);
- if(err != TINYOBJ_SUCCESS){
- printf("Tinyobj failed to load model:%s\n",ppath);
- }
- printf("num_shapes: %d\n",(int)meshcount);
- for(size_t i = 0; i < meshcount; i++){
- tinyobj_shape_t shape = shapes[i];
- printf("Shape %d:\n\tname: %s\n\tface_offset: %d\n\tlength: %d\n",(int)i, shape.name, shape.face_offset, shape.length);
- }
- //u32 meshcount = pmesh->getMeshBufferCount();
- //size_t numverts = attrib.num_vertices;
- //size_t stride = 9; //9 = 3 position floats + 3 normal floats + 3 color floats
- //size_t face_offset = 0;
- printf("Obj attrib:\n\tnum_vertices:%d\n\tnum_normals:%d\n\tnum_texcoords:%d\n\tnum_faces:%d\n\tnum_face_num_verts:%d\n",
- attrib.num_vertices, attrib.num_normals, attrib.num_texcoords, attrib.num_faces, attrib.num_face_num_verts);
- //S3DVertex verts[attrib.num_faces];
- //for(size_t i = 0; i < attrib.num_face_num_verts; i++){
- //printf("verts %d starts at %p\n",(int)i,(void*)&(verts[i]));
+ //IMeshBuffer *buf = new SMeshBuffer();
+ //tinyobj_attrib_t attrib;
+ //printf("At the very beginning, attrib is %p\n",(void*)&attrib);
+ //tinyobj_shape_t *shapes = NULL;
+ //size_t meshcount;
+ //tinyobj_material_t *materials = NULL;
+ //size_t num_materials;
+
+ ////Read data from the graphics file
+ //size_t data_len = 0;
+ //FILE *objfile = fopen(gpath,"rb");
+ //fseek(objfile,0,SEEK_END);
+ //data_len = ftell(objfile);
+ //printf("model data is %d long\n",(int)data_len);
+ //fseek(objfile,0,SEEK_SET);
+ //char *objdata = (char*)malloc(sizeof(char)*data_len);
+ //fread(objdata, sizeof(char), data_len, objfile);
+ //fclose(objfile);
+
+ ////Parse the data into a tinyobj
+ //printf("About to tinyobj_parse_obj\n");
+ //int err = tinyobj_parse_obj(&attrib, &shapes, &meshcount, &materials, &num_materials, objdata, data_len, TINYOBJ_FLAG_TRIANGULATE);
+ //free(objdata);
+
+ ////int err = tinyobj_parse_obj(&attrib, &shapes, &meshcount, &materials, &num_materials, objdata, data_len, 0);
+ //if(err != TINYOBJ_SUCCESS){
+ //printf("Tinyobj failed to load model:%s\n",ppath);
//}
- //u16 indicies[attrib.num_faces];
- size_t index_c = 0;
- printf("Faces for %d verts:\n",attrib.num_face_num_verts);
- //int num_faces = attrib.num_faces;
- //for(int i = 0; i < num_faces; i+=3){
- ////printf("\t%u verts in face %u\n",attrib.face_num_verts[i],i);
- //tinyobj_vertex_index_t fac1 = attrib.faces[i + 0];
- //tinyobj_vertex_index_t fac2 = attrib.faces[i + 1];
- //tinyobj_vertex_index_t fac3 = attrib.faces[i + 2];
- ////printf("Verts:\n\tPosition, normal, texture\n\t(%8d %7d %7d)\n\t(%8d %7d %7d)\n\t(%8d %7d %7d)\n",fac1.v_idx,fac1.vn_idx,fac1.vt_idx,fac2.v_idx,fac2.vn_idx,fac2.vt_idx,fac3.v_idx,fac3.vn_idx,fac3.vt_idx);
-
- //float f1px, f1py, f1pz;
- //f1px = attrib.vertices[(3 * fac1.v_idx) + 0];
- //f1py = attrib.vertices[(3 * fac1.v_idx) + 1];
- //f1pz = attrib.vertices[(3 * fac1.v_idx) + 2];
- //float f1nx, f1ny, f1nz;
- //f1nx = attrib.normals[(3 * fac1.vn_idx) + 0];
- //f1ny = attrib.normals[(3 * fac1.vn_idx) + 1];
- //f1nz = attrib.normals[(3 * fac1.vn_idx) + 2];
-
- //float f2px, f2py, f2pz;
- //f2px = attrib.vertices[(3 * fac2.v_idx) + 0];
- //f2py = attrib.vertices[(3 * fac2.v_idx) + 1];
- //f2pz = attrib.vertices[(3 * fac2.v_idx) + 2];
- //float f2nx, f2ny, f2nz;
- //f2nx = attrib.normals[(3 * fac2.vn_idx) + 0];
- //f2ny = attrib.normals[(3 * fac2.vn_idx) + 1];
- //f2nz = attrib.normals[(3 * fac2.vn_idx) + 2];
-
- //float f3px, f3py, f3pz;
- //f3px = attrib.vertices[(3 * fac3.v_idx) + 0];
- //f3py = attrib.vertices[(3 * fac3.v_idx) + 1];
- //f3pz = attrib.vertices[(3 * fac3.v_idx) + 2];
- //float f3nx, f3ny, f3nz;
- //f3nx = attrib.normals[(3 * fac3.vn_idx) + 0];
- //f3ny = attrib.normals[(3 * fac3.vn_idx) + 1];
- //f3nz = attrib.normals[(3 * fac3.vn_idx) + 2];
-
- /*printf("Triangle %d:\n\t\
- //Positions:\n\t\t\
- //(%f %f %f)\n\t\t\
- //(%f %f %f)\n\t\t\
- //(%f %f %f)\n\t\
- //Normals:\n\t\t\
- //(%f %f %f)\n\t\t\
- //(%f %f %f)\n\t\t\
- //(%f %f %f)\n",((int)i)/3,f1px,f1py,f1pz,f2px,f2py,f2pz,f3px,f3py,f3pz,f1nx,f1ny,f1nz,f2nx,f2ny,f2nz,f3nx,f3ny,f3nz);
+ //printf("num_shapes: %d\n",(int)meshcount);
+ //for(size_t i = 0; i < meshcount-1; i++){// 0 - meshcount, so -1
+ //tinyobj_shape_t shape = shapes[i];
+ //printf("Shape %d:\n\tname: %s\n\tface_offset: %d\n\tlength: %d\n",(int)i, shape.name, shape.face_offset, shape.length);
+ //}
+ ////u32 meshcount = pmesh->getMeshBufferCount();
+ ////size_t numverts = attrib.num_vertices;
+ ////size_t stride = 9; //9 = 3 position floats + 3 normal floats + 3 color floats
+ ////size_t face_offset = 0;
+ //printf("Obj attrib:\n\tnum_vertices:%d\n\tnum_normals:%d\n\tnum_texcoords:%d\n\tnum_faces:%d\n\tnum_face_num_verts:%d\n",
+ //attrib.num_vertices, attrib.num_normals, attrib.num_texcoords, attrib.num_faces, attrib.num_face_num_verts);
+ ////S3DVertex verts[attrib.num_faces];
+ ////for(size_t i = 0; i < attrib.num_face_num_verts; i++){
+ ////printf("verts %d starts at %p\n",(int)i,(void*)&(verts[i]));
+ ////}
+ ////u16 indicies[attrib.num_faces];
+ //size_t index_c = 0;
+ //printf("Faces for %d verts:\n",attrib.num_face_num_verts);
+ ////int num_faces = attrib.num_faces;
+ ////for(int i = 0; i < num_faces; i+=3){
+ //////printf("\t%u verts in face %u\n",attrib.face_num_verts[i],i);
+ ////tinyobj_vertex_index_t fac1 = attrib.faces[i + 0];
+ ////tinyobj_vertex_index_t fac2 = attrib.faces[i + 1];
+ ////tinyobj_vertex_index_t fac3 = attrib.faces[i + 2];
+ //////printf("Verts:\n\tPosition, normal, texture\n\t(%8d %7d %7d)\n\t(%8d %7d %7d)\n\t(%8d %7d %7d)\n",fac1.v_idx,fac1.vn_idx,fac1.vt_idx,fac2.v_idx,fac2.vn_idx,fac2.vt_idx,fac3.v_idx,fac3.vn_idx,fac3.vt_idx);
+
+ ////float f1px, f1py, f1pz;
+ ////f1px = attrib.vertices[(3 * fac1.v_idx) + 0];
+ ////f1py = attrib.vertices[(3 * fac1.v_idx) + 1];
+ ////f1pz = attrib.vertices[(3 * fac1.v_idx) + 2];
+ ////float f1nx, f1ny, f1nz;
+ ////f1nx = attrib.normals[(3 * fac1.vn_idx) + 0];
+ ////f1ny = attrib.normals[(3 * fac1.vn_idx) + 1];
+ ////f1nz = attrib.normals[(3 * fac1.vn_idx) + 2];
+
+ ////float f2px, f2py, f2pz;
+ ////f2px = attrib.vertices[(3 * fac2.v_idx) + 0];
+ ////f2py = attrib.vertices[(3 * fac2.v_idx) + 1];
+ ////f2pz = attrib.vertices[(3 * fac2.v_idx) + 2];
+ ////float f2nx, f2ny, f2nz;
+ ////f2nx = attrib.normals[(3 * fac2.vn_idx) + 0];
+ ////f2ny = attrib.normals[(3 * fac2.vn_idx) + 1];
+ ////f2nz = attrib.normals[(3 * fac2.vn_idx) + 2];
+
+ ////float f3px, f3py, f3pz;
+ ////f3px = attrib.vertices[(3 * fac3.v_idx) + 0];
+ ////f3py = attrib.vertices[(3 * fac3.v_idx) + 1];
+ ////f3pz = attrib.vertices[(3 * fac3.v_idx) + 2];
+ ////float f3nx, f3ny, f3nz;
+ ////f3nx = attrib.normals[(3 * fac3.vn_idx) + 0];
+ ////f3ny = attrib.normals[(3 * fac3.vn_idx) + 1];
+ ////f3nz = attrib.normals[(3 * fac3.vn_idx) + 2];
+ /*
+ //printf("Triangle %d:\n\t\
+ ////Positions:\n\t\t\
+ ////(%f %f %f)\n\t\t\
+ ////(%f %f %f)\n\t\t\
+ ////(%f %f %f)\n\t\
+ ////Normals:\n\t\t\
+ ////(%f %f %f)\n\t\t\
+ ////(%f %f %f)\n\t\t\
+ ////(%f %f %f)\n",((int)i)/3,f1px,f1py,f1pz,f2px,f2py,f2pz,f3px,f3py,f3pz,f1nx,f1ny,f1nz,f2nx,f2ny,f2nz,f3nx,f3ny,f3nz);
*/
- ////float
-
- //verts[i + 0] = S3DVertex(f1px,f1py,f1pz,f1nx,f1ny,f1nz,SColor(255,255,255,255),0,0);
- //verts[i + 1] = S3DVertex(f2px,f2py,f2pz,f2nx,f2ny,f2nz,SColor(255,255,255,255),0,0);
- //verts[i + 2] = S3DVertex(f3px,f3py,f3pz,f3nx,f3ny,f3nz,SColor(255,255,255,255),0,0);
- //indicies[index_c] = i;
- //index_c++;
- //indicies[index_c] = i + 1;
- //index_c++;
- //indicies[index_c] = i + 2;
- //index_c++;
+ //////float
+
+ ////verts[i + 0] = S3DVertex(f1px,f1py,f1pz,f1nx,f1ny,f1nz,SColor(255,255,255,255),0,0);
+ ////verts[i + 1] = S3DVertex(f2px,f2py,f2pz,f2nx,f2ny,f2nz,SColor(255,255,255,255),0,0);
+ ////verts[i + 2] = S3DVertex(f3px,f3py,f3pz,f3nx,f3ny,f3nz,SColor(255,255,255,255),0,0);
+ ////indicies[index_c] = i;
+ ////index_c++;
+ ////indicies[index_c] = i + 1;
+ ////index_c++;
+ ////indicies[index_c] = i + 2;
+ ////index_c++;
+ ////}
+ //S3DVertex verts[attrib.num_vertices];
+ ////S3DVertex real_verts[attrib.num_faces];
+ //u16 indicies[attrib.num_faces];
+ //for(size_t i = 0; i < attrib.num_vertices - 1; i++){ //0 - num_vertices, so -1
+ //float x,y,z;
+ //x = attrib.vertices[(i * 3) + 0];
+ //y = attrib.vertices[(i * 3) + 1];
+ //z = attrib.vertices[(i * 3) + 2];
+ //__mingw_printf("Vertex number %llu: (%3f, %3f, %3f)\n",i,x,y,z);
+ //verts[i] = S3DVertex(x,y,z,0,0,0,SColor(255,255,255,255),0,0);
//}
- S3DVertex verts[attrib.num_vertices];
- u16 indicies[attrib.num_faces];
- for(size_t i = 0; i < attrib.num_vertices; i++){
- float x,y,z;
- x = attrib.vertices[i * 3];
- y = attrib.vertices[(i * 3) + 1];
- z = attrib.vertices[(i * 3) + 2];
- verts[i] = S3DVertex(x,y,z,0,0,0,SColor(255,255,255,255),0,0);
- }
- for(size_t i = 0; i < attrib.num_faces; i ++){
- indicies[i] = attrib.faces[i].v_idx;
- }
- printf("indicies:\n");
- for(size_t i = 0; i < index_c; i++){
- printf("%d ",indicies[i]);
- }
- printf("\n");
+ //for(size_t i = 0; i < attrib.num_face_vertices; i++){
- //for(size_t i = 0; i < attrib.num_faces; i++){
- //tinyobj_vertex_index_t tface = attrib.faces[i];
- //printf("Looking at face %d: %d %d %d\n", (int)i, (int)tface.v_idx, (int)tface.vt_idx, (int)tface.vn_idx);
- //indicies[index_c] = (u16)tface.v_idx;
- //index_c++;
//}
- buf->append(verts, attrib.num_vertices, indicies, (u32)attrib.num_faces);
- //buf->recalculateBoundingBox();
- SMesh *gmesh = new SMesh();
- gmesh->addMeshBuffer(buf);
- //gmesh->recalculateBoundingBox();
- //gmesh->setDirty();
-
- //IMesh *gmesh = smgr->getMesh(gpath);
+ //for(size_t i = 0; i < attrib.num_faces - 1; i ++){// 0 - num_faces, so -1
+ //__mingw_printf("Found index: %llu: %3d\n",i,attrib.faces[i].v_idx);
+ ////real_verts[i]
+ //indicies[i] = attrib.faces[i].v_idx;
+ //}
+ //printf("indicies:\n");
+ //for(size_t i = 0; i < index_c; i++){
+ //printf("%d ",indicies[i]);
+ //}
+ //printf("\n");
+
+ ////for(size_t i = 0; i < attrib.num_faces; i++){
+ ////tinyobj_vertex_index_t tface = attrib.faces[i];
+ ////printf("Looking at face %d: %d %d %d\n", (int)i, (int)tface.v_idx, (int)tface.vt_idx, (int)tface.vn_idx);
+ ////indicies[index_c] = (u16)tface.v_idx;
+ ////index_c++;
+ ////}
+ //buf->append(verts, attrib.num_vertices, indicies, (u32)attrib.num_faces);
+ ////buf->recalculateBoundingBox();
+ //SMesh *gmesh = new SMesh();
+ //gmesh->addMeshBuffer(buf);
+ ////gmesh->recalculateBoundingBox();
+ ////gmesh->setDirty();
+
+ IMesh *gmesh = smgr->getMesh(gpath);
printf("Creating client physbox at %f %f %f\n",x,y,z);
ISceneNode *node = smgr->addMeshSceneNode(gmesh,0,-1,vector3df(x,y,z));
@@ -253,14 +261,15 @@ static const luaL_reg bphysmodel_m[] = {
};
int cbphysmodel_register(lua_State* L){
- //printf("bphysmodel registered\n");
+ bphysmodel_register(L);
- luaL_newmetatable(L, "phys.physmodel");//{}
- lua_newtable(L);//{physmodel_m},{}
+ luaL_getmetatable(L,"phys.physmodel");//{physmodel_m}
+ lua_getfield(L,-1,"__index");//{physmodel_m},{}
luaL_register(L,NULL,igeneric_m); //Inherit all the things to do with scene nodes
- luaL_register(L,NULL,bcollider_m);
- luaL_register(L,NULL,bphysmodel_m);
- lua_setfield(L,-2,"__index");
+ luaL_register(L,NULL,bcollider_m);//Override things to do with physics
+ luaL_register(L,NULL,brigidbody_m);//Add rigidbody things
+ luaL_register(L,NULL,bphysmodel_m);//anything specific?
+ lua_pop(L,2);
lua_getglobal(L,"phys");
luaL_register(L,NULL,bphysmodel_f);
diff --git a/src/client/lua_api/scene/imesh.cpp b/src/client/lua_api/scene/imesh.cpp
index 7a72edf..8ed357c 100644
--- a/src/client/lua_api/scene/imesh.cpp
+++ b/src/client/lua_api/scene/imesh.cpp
@@ -62,7 +62,8 @@ 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(1,0,-1,core::vector3df(x,y,z),core::vector3df(0,0,0),core::vector3df(sx,sy,sz));
+ printf("Makeing new iscenecube, size %f %f %f, origin %f %f %f\n", sx,sy,sz,x,y,z);
+ ISceneNode* 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/main.cpp b/src/client/main.cpp
index 0a82e99..f08862c 100644
--- a/src/client/main.cpp
+++ b/src/client/main.cpp
@@ -27,6 +27,7 @@ extern "C" {
#include <shared/lua_api/common.hpp>
#include "../shared/lua_api/load_net.hpp"
#include "../shared/phys/physcommon.hpp"
+#include "../shared/lua_api/load_common.hpp"
using namespace irr;
using namespace core;
@@ -104,6 +105,7 @@ void UpdateElement(btCollisionObject* obj){
btTransform transform = obj->getWorldTransform();
btVector3 pos = transform.getOrigin();
node->setPosition(core::vector3df((f32)pos[0], (f32)pos[1], (f32)pos[2]));
+ //printf("Setting new position to %f %f %f\n", pos[0], pos[1], pos[2]);
//Set rotation
btQuaternion rot = transform.getRotation();
@@ -153,6 +155,7 @@ int main(int argc, char *argv[]){
luaL_openlibs(state);
loadIrrLibs(state,device);
loadNetLibs(state);
+ loadCommonLibs(state);
printf("Loadded irr libs...\n");
//Sets the global event handeler
printf("Creating event receiver\n");
diff --git a/src/shared/lua_api/common.cpp b/src/shared/lua_api/common.cpp
index 1ee4b72..9b833fe 100644
--- a/src/shared/lua_api/common.cpp
+++ b/src/shared/lua_api/common.cpp
@@ -5,6 +5,7 @@ extern "C" {
#include <lualib.h>
}
+#include <stdlib.h>
#include "common.hpp"
//Expose things to the lua state
@@ -236,6 +237,9 @@ int popvector2i(lua_State* L, long* a, long* b){
return 0;
}
+//When crashy is enabled, errors that usually get caught by errfunc crash instead
+//Useful for testing
+bool crashy = false;
//errfunc("mssg",false)
int errfunc(lua_State *L){
printf("Error function called\n");
@@ -268,9 +272,18 @@ int errfunc(lua_State *L){
printf("--------------------------\n");
lua_call(L,1,0);//error,{debug}
lua_pop(L,1);
- printf("Returning");
+ printf("Returning:");
+ printf("crashy is %d", crashy);
+ if(crashy){
+ exit(-1);
+ }
return 1;
}
void pusherrorfunc(lua_State *L){
lua_pushcfunction(L,errfunc);
}
+int make_crashy(lua_State *L){
+ crashy = true;
+ printf("Setting crashy to %d\n",crashy);
+ return 0;
+}
diff --git a/src/shared/lua_api/common.hpp b/src/shared/lua_api/common.hpp
index ba89521..ef8ae58 100644
--- a/src/shared/lua_api/common.hpp
+++ b/src/shared/lua_api/common.hpp
@@ -24,5 +24,6 @@ int popvector2i(lua_State*,long*,long*);
int poprecti(lua_State* L,long*,long*,long*,long*);
int pushrecti(lua_State* L,long,long,long,long);
-void pusherrorfunc(lua_State *L);
+void pusherrorfunc(lua_State* L);
+int make_crashy(lua_State* L);
#endif
diff --git a/src/shared/lua_api/load_common.cpp b/src/shared/lua_api/load_common.cpp
new file mode 100644
index 0000000..66afe67
--- /dev/null
+++ b/src/shared/lua_api/load_common.cpp
@@ -0,0 +1,8 @@
+extern "C" {
+ #include <lua.h>
+ #include <lauxlib.h>
+ #include <lualib.h>
+}
+
+void loadCommonLibs(lua_State* L);
+void gameloop_common(lua_State* L);
diff --git a/src/shared/lua_api/load_common.hpp b/src/shared/lua_api/load_common.hpp
new file mode 100644
index 0000000..5be5de1
--- /dev/null
+++ b/src/shared/lua_api/load_common.hpp
@@ -0,0 +1,11 @@
+#include <shared/lua_api/common.hpp>
+
+void loadCommonLibs(lua_State* L){
+ lua_getglobal(L,"GAME");
+ lua_pushcfunction(L,make_crashy);
+ lua_setfield(L,-2,"crashy");
+}
+
+void gameloop_common(lua_State* L){
+
+}
diff --git a/src/shared/lua_api/load_net.cpp b/src/shared/lua_api/load_net.cpp
index 04a9239..d8d321a 100644
--- a/src/shared/lua_api/load_net.cpp
+++ b/src/shared/lua_api/load_net.cpp
@@ -10,20 +10,20 @@ ect.
--Server
local s = net.newsocket(net.REP)
s:bind("tcp://127.0.0.1:8765")
- s:receive(function(stream)
+ function s:receive(stream)
local message = stream:readstring()
s:send("pong",function(stream)
stream:writestring(message .. " world!")
end)
- end)
+ end
@usage
--Client
local c = net.newsocket(net.REQ)
c:connect("tcp://127.0.0.1:8765")
- c:receive(function(stream)
+ c:receive(stream)
print(stream:readstring())
- end)
+ end
c:send(function(stream)
stream:writestring("Hello,")
end)
@@ -378,8 +378,8 @@ void gameloop_net(lua_State* L){
if(err){
switch(err){
case NNG_EAGAIN: break;
- case NNG_ESTATE:
- if(stype == REQ) break;
+ //case NNG_ESTATE:
+ //if(stype == REQ) break;
default:
printf("Net error: %s\n\tSocket type:%d\n",nng_strerror(err),stype);
lua_pushstring(L,"Error while receving message:");
@@ -535,7 +535,6 @@ int send(lua_State* L){
//lua_getfield(L,-1,"n");//{socket},type
//int sockettype = lua_tonumber(L,-1);
//lua_pop(L,2);//
- //switch(sockettype
//netfuncs[fd] = func;//
//nettypes[fd] = sockettype;
//return 0;
diff --git a/src/shared/lua_api/phys/bcollider.cpp b/src/shared/lua_api/phys/bcollider.cpp
index 356c504..0a87af3 100644
--- a/src/shared/lua_api/phys/bcollider.cpp
+++ b/src/shared/lua_api/phys/bcollider.cpp
@@ -33,12 +33,57 @@ to move.
int activate(lua_State *L){
btCollisionObject *r = popCollider(L);
- r->activate();
+ r->activate(true);
return 0;
}
+//collider:getfriction()
+int getfriction(lua_State *L){
+ btCollisionObject *r = popCollider(L);
+ double fric = r->getFriction();
+ lua_pushnumber(L, fric);
+ return 1;
+}
+
+//collider:setfriction(number)
+int setfriction(lua_State *L){
+ double friction = lua_tonumber(L,-1);
+ lua_pop(L,1);
+ btCollisionObject *r = popCollider(L);
+ r->setFriction(friction);
+ return 0;
+}
+
+//collider:setpos({x,y,z})
+int setpos(lua_State *L){
+ double x,y,z;
+ popvector3d(L,&x,&y,&z);
+ lua_getfield(L,-1,"collider");
+ btCollisionObject *c = (btCollisionObject*)lua_touserdata(L,-1);
+ lua_pop(L,1);
+ btTransform t = c->getWorldTransform();
+ t.setOrigin(btVector3(x,y,z));
+ c->setWorldTransform(t);
+ c->activate();
+ return 0;
+}
+
+//collider:getpos() :: {x,y,z}
+int getpos(lua_State *L){
+ lua_getfield(L,-1,"collider");
+ btCollisionObject *c = (btCollisionObject*)lua_touserdata(L,-1);
+ btTransform t = c->getWorldTransform();
+ btVector3 o = t.getOrigin();
+ pushvector3d(L,o.x(), o.y(), o.z());
+ return 1;
+}
+
extern const luaL_reg bcollider_m[] = {
{"activate", activate},
+ {"getpos", getpos},
+ {"setpos", setpos},
+ {"getfriction", getfriction},
+ {"setfriction", setfriction},
{NULL, NULL}
};
diff --git a/src/shared/lua_api/phys/bghostobject.cpp b/src/shared/lua_api/phys/bghostobject.cpp
index da9406d..8174b21 100644
--- a/src/shared/lua_api/phys/bghostobject.cpp
+++ b/src/shared/lua_api/phys/bghostobject.cpp
@@ -59,14 +59,14 @@ void makeghostobject(lua_State* L){
btGhostObject *ghost = new btGhostObject();
ghost->setCollisionShape(shape);
ghost->setWorldTransform(transform);
- ghost->setCollisionFlags(
- btCollisionObject::CollisionFlags::CF_NO_CONTACT_RESPONSE |
- btCollisionObject::CollisionFlags::CF_KINEMATIC_OBJECT
- );
+ //ghost->setCollisionFlags(
+ //btCollisionObject::CollisionFlags::CF_NO_CONTACT_RESPONSE |
+ //btCollisionObject::CollisionFlags::CF_KINEMATIC_OBJECT
+ //);
World->addCollisionObject(ghost, btBroadphaseProxy::SensorTrigger, btBroadphaseProxy::AllFilter & ~btBroadphaseProxy::SensorTrigger);
//printf("Added rigid body to world: %p\n",World);
- Objects.push_back(ghost);
+ //Objects.push_back(ghost);
lua_pushlightuserdata(L,ghost);//ud_ghost
}
@@ -148,7 +148,7 @@ int bghostoverlapping(lua_State *L){
lua_pushlightuserdata(L,co);//{},{phys},{phys.colliders},i,ud_co
lua_gettable(L,-3);//{},{phys},{phys.colliders},i,{collider=ud_co}
if(lua_isnil(L,-1)){
- printf("Failed to find collider, failing...\n");
+ printf("Failed to find object of collider %p\n", (void*)co);
lua_pushstring(L,"Failed to find collider we are overlapping");
lua_error(L);
}
diff --git a/src/shared/lua_api/phys/bhingeconstraint.cpp b/src/shared/lua_api/phys/bhingeconstraint.cpp
index ab6fb50..a8c6567 100644
--- a/src/shared/lua_api/phys/bhingeconstraint.cpp
+++ b/src/shared/lua_api/phys/bhingeconstraint.cpp
@@ -8,15 +8,9 @@ extern "C" {
#include <lualib.h>
}
#include <shared/lua_api/common.hpp>
-#include <Irrlicht.h>
#include <btBulletDynamicsCommon.h>
#include <shared/lua_api/phys/bhingeconstraint.hpp>
-using namespace irr;
-using namespace scene;
-using namespace core;
-using namespace video;
-
extern btDiscreteDynamicsWorld* World;
extern std::list<btRigidBody*> Objects;
diff --git a/src/shared/lua_api/phys/bphysbox.cpp b/src/shared/lua_api/phys/bphysbox.cpp
index a0ad15a..4564c6e 100644
--- a/src/shared/lua_api/phys/bphysbox.cpp
+++ b/src/shared/lua_api/phys/bphysbox.cpp
@@ -79,7 +79,6 @@ void makenewbphysbox(lua_State* L){
// Add it to the world
World->addRigidBody(rigidbody);
- //printf("Added rigid body to world: %p\n",World);
Objects.push_back(rigidbody);
lua_pushlightuserdata(L,rigidbody);//ud_rigidbody
diff --git a/src/shared/lua_api/phys/bphysgeneric.cpp b/src/shared/lua_api/phys/bphysgeneric.cpp
index 56320dd..718ffed 100644
--- a/src/shared/lua_api/phys/bphysgeneric.cpp
+++ b/src/shared/lua_api/phys/bphysgeneric.cpp
@@ -205,6 +205,7 @@ int setdamping(lua_State *L){
return 0;
}
+
/***
Sets flags on this rigidbody
@function rigidbody:setflags(flags)
@@ -223,41 +224,29 @@ int setflags(lua_State *L){
/***
Apply an impulse to the rigidboy
-@function rigidbody:centralimpulse(vec3 impulse)
+@function rigidbody:applyimpulse(vec3 impulse[, vec3 offset])
@tparam vector3 impulse The direction to apply the impulse in
+@tparam? vector3 offset The offset from the center to apply the impulse, default = {0, 0, 0}
*/
+//applyimpuse(self,{pos},{off})
int applyimpulse(lua_State *L){
+ printf("Apply impulse called...\n");
+ int nargs = lua_gettop(L);
double x,y,z,ox,oy,oz;
+ if(nargs > 2){
+ popvector3d(L,&ox,&oy,&oz);
+ }else{
+ ox = 0;
+ oy = 0;
+ oz = 0;
+ }
popvector3d(L,&x,&y,&z);
- popvector3d(L,&ox,&oy,&oz);
btRigidBody *r = popRigidBody(L);
r->applyImpulse(btVector3(x,y,z),btVector3(ox,oy,oz));
return 0;
}
-//collider:setpos({x,y,z})
-int setpos(lua_State *L){
- double x,y,z;
- popvector3d(L,&x,&y,&z);
- lua_getfield(L,-1,"collider");
- btCollisionObject *c = (btCollisionObject*)lua_touserdata(L,-1);
- lua_pop(L,1);
- btTransform t = c->getWorldTransform();
- t.setOrigin(btVector3(x,y,z));
- c->setWorldTransform(t);
- c->activate();
- return 0;
-}
-//collider:getpos() :: {x,y,z}
-int getpos(lua_State *L){
- lua_getfield(L,-1,"collider");
- btCollisionObject *c = (btCollisionObject*)lua_touserdata(L,-1);
- btTransform t = c->getWorldTransform();
- btVector3 o = t.getOrigin();
- pushvector3d(L,o.x(), o.y(), o.z());
- return 1;
-}
/*
A callback used to detect collisions
@@ -296,9 +285,7 @@ extern const luaL_reg brigidbody_m[] = {
{"getldamping", getlineardamping},
{"getadamping", getangulardamping},
{"setdamping", setdamping},
- {"getpos", getpos},
- {"setpos", setpos},
- //{"activate", activate},
+ //{"activate", activate}, --moved to bcollider_m
{"getvelocity", getvelocity},
{"setvelocity", setvelocity},
{"setangfactor", setangfactor},
diff --git a/src/shared/lua_api/phys/bphysmodel.cpp b/src/shared/lua_api/phys/bphysmodel.cpp
index 55039ba..a89a28f 100644
--- a/src/shared/lua_api/phys/bphysmodel.cpp
+++ b/src/shared/lua_api/phys/bphysmodel.cpp
@@ -16,9 +16,13 @@ extern "C" {
#include <shared/lua_api/common.hpp>
#include <shared/util/tinyobj.hpp>
+#include <shared/lua_api/phys/bcollider.hpp>
+#include <shared/lua_api/phys/bphysgeneric.hpp>
+
extern btDiscreteDynamicsWorld* World;
extern std::list<btRigidBody*> Objects;
+//TODO: This will break in the future, see github.com/syoyo/tinyobjloader-c/issues/16
//"physicfile",mass[,position][,lookat] :: ud_rigidbody
void makebphysmodel(lua_State *L){
printf("making bphysmodel\n");
@@ -57,25 +61,37 @@ void makebphysmodel(lua_State *L){
fclose(objfile);
printf("About to tinyobj_parse_obj\n");
int err = tinyobj_parse_obj(&attrib, &shapes, &meshcount, &materials, &num_materials, objdata, data_len, TINYOBJ_FLAG_TRIANGULATE);
+ printf("Finished parsing tinyobj\n");
if(err != TINYOBJ_SUCCESS){
printf("Tinyobj failed to load model:%s\n",ppath);
}
//u32 meshcount = pmesh->getMeshBufferCount();
+ __mingw_printf("attrib.num_vertices: %u\n",attrib.num_vertices);
+ __mingw_printf("attrib.num_faces: %u\n",attrib.num_faces);
btTriangleMesh* trimesh = new btTriangleMesh();
- for(size_t i = 0; i < attrib.num_vertices; i++){
- float *vs = attrib.vertices + (sizeof(float)*3*i);//3 floats per vertex
+ for(size_t i = 0; i < attrib.num_vertices; i++){ //0 - x, so num_vertices - 1
+ //__mingw_printf("Looking at vertice %llu/%u\n",i,attrib.num_vertices);
+ //DO NOT MULTIPLY THIS BY SIEZEOF(FLOAT)
+ float *vs = attrib.vertices + (3*i);//3 floats per vertex
+ //printf("Got start\n");
float v1 = vs[0];
+ //printf("Got 1\n");
float v2 = vs[1];
+ //printf("Got 2\n");
float v3 = vs[2];
+ //printf("Got all 3 vertexees\n");
+ //printf("Adding vertex: (%f %f %f)\n",v1, v2, v3);
trimesh->findOrAddVertex(btVector3(v1,v2,v3),true);
}
- for(size_t i = 0; i < attrib.num_faces; i+= 3){
+ printf("Finished finding or adding vertexes\n");
+ for(size_t i = 0; i < attrib.num_faces - 1; i+= 3){ //0 - y to num_faces - 1
tinyobj_vertex_index_t i1,i2,i3;
i1 = attrib.faces[i];
i2 = attrib.faces[i+1];
i3 = attrib.faces[i+2];
trimesh->addTriangleIndices(i1.v_idx,i2.v_idx,i3.v_idx);
}
+ printf("Finished adding triangle indicies\n");
//size_t numverts = attrib.num_face_num_verts;
////size_t stride = 9; //9 = 3 position floats + 3 normal floats + 3 color floats
//size_t face_offset = 0;
@@ -197,12 +213,18 @@ int bphysmodel_register(lua_State* L){
//printf("bphysmodel registered\n");
- luaL_newmetatable(L, "phys.physmodel");//{}
+ luaL_newmetatable(L, "phys.physmodel");//{m_physmodel}
+ lua_newtable(L);//{m_physmodel},{}
+ luaL_register(L,NULL,bcollider_m);
luaL_register(L,NULL,bphysmodel_m);
+ luaL_register(L,NULL,brigidbody_m);
+ lua_setfield(L,-2,"__index");//{m_physmodel}
+ lua_pop(L,1);//
//luaL_register(L,NULL,igeneric_m); //Inherit all the things to do with scene nodes
lua_getglobal(L,"phys");
luaL_register(L,NULL,bphysmodel_f);
+ lua_pop(L,1);
- return 1;
+ return 0;
}
diff --git a/src/shared/phys/physcommon.cpp b/src/shared/phys/physcommon.cpp
index b588b23..379ad55 100644
--- a/src/shared/phys/physcommon.cpp
+++ b/src/shared/phys/physcommon.cpp
@@ -85,6 +85,7 @@ void UpdatePhysics(double TDeltaTime, void(*f)(btCollisionObject *)) {
World->stepSimulation(TDeltaTime * 0.2f, 60);
//printf("Done step simulation\n");
if(f){
+ //printf("Updating the position of %llu objects\n", Objects.size());
// Relay the object's orientation to irrlicht
for(std::list<btCollisionObject *>::iterator it = Objects.begin(); it != Objects.end(); ++it) {
(*f)(*it);