diff options
Diffstat (limited to 'src/shared/lua_api')
| -rw-r--r-- | src/shared/lua_api/common.cpp | 2 | ||||
| -rw-r--r-- | src/shared/lua_api/load_common.cpp | 26 | ||||
| -rw-r--r-- | src/shared/lua_api/load_common.hpp | 11 | ||||
| -rw-r--r-- | src/shared/lua_api/load_net.cpp | 49 | ||||
| -rw-r--r-- | src/shared/lua_api/load_phys.cpp | 1 | ||||
| -rw-r--r-- | src/shared/lua_api/load_scene.cpp | 1 | ||||
| -rw-r--r-- | src/shared/lua_api/phys/bphysbuffer.cpp | 10 | ||||
| -rw-r--r-- | src/shared/lua_api/phys/bphysmodel.cpp | 19 |
8 files changed, 73 insertions, 46 deletions
diff --git a/src/shared/lua_api/common.cpp b/src/shared/lua_api/common.cpp index 9b833fe..b26c3cc 100644 --- a/src/shared/lua_api/common.cpp +++ b/src/shared/lua_api/common.cpp @@ -8,6 +8,8 @@ extern "C" { #include <stdlib.h> #include "common.hpp" +#define set_const(l,x) lua_pushstring(l,#x);lua_pushinteger(l,x);lua_settable(l,-3); + //Expose things to the lua state void loadLLibs(lua_State* L){ diff --git a/src/shared/lua_api/load_common.cpp b/src/shared/lua_api/load_common.cpp index 66afe67..dc61ef1 100644 --- a/src/shared/lua_api/load_common.cpp +++ b/src/shared/lua_api/load_common.cpp @@ -1,8 +1,30 @@ +#include <chrono> +#include <shared/lua_api/load_common.hpp> extern "C" { #include <lua.h> #include <lauxlib.h> #include <lualib.h> } +using namespace std::chrono; -void loadCommonLibs(lua_State* L); -void gameloop_common(lua_State* L); +//Gets the time +int get_time(lua_State* L){ + std::chrono::high_resolution_clock::time_point now = high_resolution_clock::now(); + std::chrono::high_resolution_clock::duration since_epoch = now.time_since_epoch(); + double dc = std::chrono::duration_cast<std::chrono::milliseconds>(since_epoch).count(); + lua_pushnumber(L,dc); + return 1; +} + +void loadCommonLibs(lua_State* L){ + lua_getglobal(L,"GAME"); + lua_pushcfunction(L,make_crashy); + lua_setfield(L,-2,"crashy"); + lua_pop(L,1); + lua_pushcfunction(L,get_time); + lua_setglobal(L,"get_time"); +} + +void gameloop_common(lua_State* L){ + +} diff --git a/src/shared/lua_api/load_common.hpp b/src/shared/lua_api/load_common.hpp index 5be5de1..759ba85 100644 --- a/src/shared/lua_api/load_common.hpp +++ b/src/shared/lua_api/load_common.hpp @@ -1,11 +1,4 @@ #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){ - -} +void loadCommonLibs(lua_State* L); +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 d8d321a..3452aa2 100644 --- a/src/shared/lua_api/load_net.cpp +++ b/src/shared/lua_api/load_net.cpp @@ -30,34 +30,35 @@ ect. */ extern "C" { - #include <lua.h> - #include <lauxlib.h> - #include <lualib.h> +# include <lua.h> +# include <lauxlib.h> +# include <lualib.h> } #include <string.h> - +#include <assert.h> #include <string> #include <map> -#include <nng/nng.h> - -#include <nng/transport/inproc/inproc.h> -#include <nng/transport/ipc/ipc.h> -#include <nng/transport/tcp/tcp.h> -#include <nng/transport/tls/tls.h> -#include <nng/transport/zerotier/zerotier.h> - -#include <nng/protocol/pair1/pair.h> -#include <nng/protocol/bus0/bus.h> -#include <nng/protocol/pubsub0/pub.h> -#include <nng/protocol/pubsub0/sub.h> -#include <nng/protocol/pipeline0/pull.h> -#include <nng/protocol/pipeline0/push.h> -#include <nng/protocol/reqrep0/req.h> -#include <nng/protocol/reqrep0/rep.h> -#include <nng/protocol/survey0/respond.h> -#include <nng/protocol/survey0/survey.h> - +extern "C" { +# include <nng/nng.h> + +# include <nng/transport/inproc/inproc.h> +# include <nng/transport/ipc/ipc.h> +# include <nng/transport/tcp/tcp.h> +# include <nng/transport/tls/tls.h> +# include <nng/transport/zerotier/zerotier.h> + +# include <nng/protocol/pair1/pair.h> +# include <nng/protocol/bus0/bus.h> +# include <nng/protocol/pubsub0/pub.h> +# include <nng/protocol/pubsub0/sub.h> +# include <nng/protocol/pipeline0/pull.h> +# include <nng/protocol/pipeline0/push.h> +# include <nng/protocol/reqrep0/req.h> +# include <nng/protocol/reqrep0/rep.h> +# include <nng/protocol/survey0/respond.h> +# include <nng/protocol/survey0/survey.h> +} #include "load_net.hpp" #include <shared/util/hashmap.hpp> @@ -336,6 +337,7 @@ int block_recv(lua_State *L){//{socket} } void gameloop_net(lua_State* L){ + assert(lua_gettop(L) == 0); //printf("Doing net of gameloop,starting with %d args\n",lua_gettop(L)); //printf("Got net\n"); lua_getglobal(L,"net");//{net} @@ -423,6 +425,7 @@ void gameloop_net(lua_State* L){ //printf("There are %d items left on the lua stack\n",lua_gettop(L)); lua_pop(L,2); //printf("Done with net game loop\n"); + assert(lua_gettop(L) == 0); } /*** diff --git a/src/shared/lua_api/load_phys.cpp b/src/shared/lua_api/load_phys.cpp index be5529c..7002a09 100644 --- a/src/shared/lua_api/load_phys.cpp +++ b/src/shared/lua_api/load_phys.cpp @@ -6,6 +6,7 @@ #include <shared/lua_api/common.hpp> void load_physfuncs(lua_State* L){ + printf("Loading phys things\n"); lua_newtable(L);//{} lua_setglobal(L,"phys");// lua_getglobal(L,"phys");//{phys} diff --git a/src/shared/lua_api/load_scene.cpp b/src/shared/lua_api/load_scene.cpp index 633fcb1..ef22653 100644 --- a/src/shared/lua_api/load_scene.cpp +++ b/src/shared/lua_api/load_scene.cpp @@ -7,5 +7,4 @@ extern "C" { void register_scene(lua_State* L){ - } diff --git a/src/shared/lua_api/phys/bphysbuffer.cpp b/src/shared/lua_api/phys/bphysbuffer.cpp index 111b159..074f506 100644 --- a/src/shared/lua_api/phys/bphysbuffer.cpp +++ b/src/shared/lua_api/phys/bphysbuffer.cpp @@ -27,11 +27,11 @@ using namespace video; extern btDiscreteDynamicsWorld* World; extern core::list<btRigidBody*> Objects; -static LBPhysNode* checkisbphysmodel(lua_State* L, int index){ - void* ud = luaL_checkudata(L,index,"phys.physmodel"); - luaL_argcheck(L,ud != NULL, index, "'phys.physmodel' expected"); - return (LBPhysNode*) ud; -} +//static LBPhysNode* checkisbphysmodel(lua_State* L, int index){ + //void* ud = luaL_checkudata(L,index,"phys.physmodel"); + //luaL_argcheck(L,ud != NULL, index, "'phys.physmodel' expected"); + //return (LBPhysNode*) ud; +//} //iscenecamera.new(Vector position, Vector lookat, parrent) // {} {} 0 1 diff --git a/src/shared/lua_api/phys/bphysmodel.cpp b/src/shared/lua_api/phys/bphysmodel.cpp index 0cff0ed..2c9a02d 100644 --- a/src/shared/lua_api/phys/bphysmodel.cpp +++ b/src/shared/lua_api/phys/bphysmodel.cpp @@ -12,6 +12,8 @@ extern "C" { #include <lualib.h> } #include <btBulletDynamicsCommon.h> +#include <btBulletCollisionCommon.h> +#include <BulletCollision/Gimpact/btGImpactShape.h> #include "bphysmodel.hpp" #include <shared/lua_api/common.hpp> #include <shared/util/tinyobj.hpp> @@ -69,19 +71,22 @@ void makebphysmodel(lua_State *L){ //__mingw_printf("attrib.num_vertices: %u\n",attrib.num_vertices); //__mingw_printf("attrib.num_faces: %u\n",attrib.num_faces); btTriangleMesh* trimesh = new btTriangleMesh(); + btVector3 vertexes[attrib.num_vertices]; 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]; + //For some reason irrlicht and bullet disagree with which direction +x is, + //negate the x in the physics engine so the graphical stuff lines up + //with the physics stuff + 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); + //trimesh->findOrAddVertex(btVector3(v1,v2,v3),true); + vertexes[i] = btVector3(v1,v2,v3); } 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 @@ -89,7 +94,8 @@ void makebphysmodel(lua_State *L){ 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); + trimesh->addTriangle(vertexes[i1.v_idx],vertexes[i2.v_idx],vertexes[i3.v_idx],true); + //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; @@ -120,7 +126,8 @@ void makebphysmodel(lua_State *L){ //face_offset += (size_t)attrib.face_num_verts[i]; //} printf("Done building trimesh\n"); - btCollisionShape *shape = new btBvhTriangleMeshShape(trimesh,true); + //btCollisionShape *shape = new btGImpactMeshShape(trimesh); + btCollisionShape *shape = new btConvexTriangleMeshShape(trimesh); btTransform tr; tr.setIdentity(); tr.setOrigin(btVector3(x,y,z)); |
