aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander <alex@cogarr.net>2019-01-09 16:09:39 -0500
committerAlexander <alex@cogarr.net>2019-01-09 16:09:39 -0500
commitbb9f6d43a4e574506e3049bd56c890c242d35e8b (patch)
tree5935b51197a2f571593a01d972559b85ca485773
parent2009501214f3c2e3f8d8b1a06432afdf39276bd5 (diff)
downloadbrokengine-bb9f6d43a4e574506e3049bd56c890c242d35e8b.tar.gz
brokengine-bb9f6d43a4e574506e3049bd56c890c242d35e8b.tar.bz2
brokengine-bb9f6d43a4e574506e3049bd56c890c242d35e8b.zip
Moved the define constant definition into common/shared header
-rw-r--r--src/client/lua_api/gui/iguielement.cpp4
-rw-r--r--src/client/lua_api/video/iimage.cpp15
-rw-r--r--src/shared/lua_api/common.hpp1
-rw-r--r--src/shared/lua_api/load_net.cpp2
-rw-r--r--src/shared/lua_api/load_phys.cpp6
-rw-r--r--src/shared/lua_api/phys/bphysgeneric.cpp41
6 files changed, 65 insertions, 4 deletions
diff --git a/src/client/lua_api/gui/iguielement.cpp b/src/client/lua_api/gui/iguielement.cpp
index 4ef5026..f1a83b8 100644
--- a/src/client/lua_api/gui/iguielement.cpp
+++ b/src/client/lua_api/gui/iguielement.cpp
@@ -17,7 +17,7 @@ extern "C" {
#include <lualib.h>
}
-
+#include <stdio.h>
#include <shared/lua_api/common.hpp>
#include <irrlicht.h>
#include "../guiparts.hpp"
@@ -177,7 +177,7 @@ int getiguitext(lua_State* L){
lua_pop(L,2);//
const wchar_t *t = el->getText();
size_t cstrlen = wcslen(t);
- __mingw_printf("In gui get text, cstrlen is %zu\n",cstrlen);
+ printf("In gui get text, cstrlen is %zu\n",cstrlen);
char output[cstrlen + 1];//+1 for \0
wcstombs(output,t,cstrlen);
output[cstrlen] = '\0';
diff --git a/src/client/lua_api/video/iimage.cpp b/src/client/lua_api/video/iimage.cpp
index 6fbf6c5..4c7795d 100644
--- a/src/client/lua_api/video/iimage.cpp
+++ b/src/client/lua_api/video/iimage.cpp
@@ -135,9 +135,24 @@ int getiimagepixel(lua_State* L){
return 1;
}
+/***
+Returns the dimensions of the image
+@function iimage:getDimensions()
+@treturn vec2i dimensions The dimensions of the image
+*/
+//getdimensions({self})
+int getiimagedimensions(lua_State *L){
+ lua_getfield(L,-1,"image");
+ IImage *img = (IImage*)lua_touserdata(L,-1);
+ core::dimension2d<u32> dims = img->getDimension();
+ pushvector2i(L,dims.Height, dims.Width);
+ return 1;
+}
+
static const luaL_reg iimage_m[] = {
{"setpixel", setiimagepixel},
{"getpixel", getiimagepixel},
+ {"getdimensions", getiimagedimensions},
{0,0},
};
diff --git a/src/shared/lua_api/common.hpp b/src/shared/lua_api/common.hpp
index 0b7abd6..583ab1e 100644
--- a/src/shared/lua_api/common.hpp
+++ b/src/shared/lua_api/common.hpp
@@ -1,6 +1,7 @@
#ifndef __broken_shared_lua_common
#define __broken_shared_lua_common
+#define set_const(l,x) lua_pushstring(l,#x);lua_pushinteger(l,x);lua_settable(l,-3);
extern "C" {
#include <lua.h>
#include <lauxlib.h>
diff --git a/src/shared/lua_api/load_net.cpp b/src/shared/lua_api/load_net.cpp
index 4baf952..677f1d1 100644
--- a/src/shared/lua_api/load_net.cpp
+++ b/src/shared/lua_api/load_net.cpp
@@ -313,7 +313,7 @@ void gameloop_net(lua_State* L){
luaL_getmetatable(L,"net.stream");//func,{data=stream}
lua_setmetatable(L,-2);//func,{stream}
lua_call(L,1,0);//
- __mingw_printf("Finished calling gameloop, buf is %p, size is %zu\n",buf,size);
+ printf("Finished calling gameloop, buf is %p, size is %zu\n",buf,size);
nng_msg_free(msgp);
printf("called nn_freemsg\n");
free(stream);//We manually set stream->data so free_stream would crash here
diff --git a/src/shared/lua_api/load_phys.cpp b/src/shared/lua_api/load_phys.cpp
index 6875970..7580e99 100644
--- a/src/shared/lua_api/load_phys.cpp
+++ b/src/shared/lua_api/load_phys.cpp
@@ -1,10 +1,16 @@
#include "load_phys.hpp"
#include "phys/bphysbox.hpp"
#include "phys/bhingeconstraint.hpp"
+#include <btBulletDynamicsCommon.h>
+#include <shared/lua_api/common.hpp>
void load_physfuncs(lua_State* L){
lua_newtable(L);//{}
lua_setglobal(L,"phys");
+ set_const(L,BT_DISABLE_WORLD_GRAVITY);
+ set_const(L,BT_ENABLE_GYROSCOPIC_FORCE_EXPLICIT);
+ set_const(L,BT_ENABLE_GYROSCOPIC_FORCE_IMPLICIT_WORLD);
+ set_const(L,BT_ENABLE_GYROSCOPIC_FORCE_IMPLICIT_BODY);
bphysbox_register(L);
bhingeconstraint_register(L);
}
diff --git a/src/shared/lua_api/phys/bphysgeneric.cpp b/src/shared/lua_api/phys/bphysgeneric.cpp
index 44c789d..5faef2d 100644
--- a/src/shared/lua_api/phys/bphysgeneric.cpp
+++ b/src/shared/lua_api/phys/bphysgeneric.cpp
@@ -18,7 +18,12 @@ extern "C" {
node = ISceneNode,
}
*/
-
+btRigidBody* popRigidBody(lua_State *L){
+ lua_getfield(L,-1,"rigidbody");
+ btRigidBody *r = (btRigidBody*)lua_touserdata(L,-1);
+ lua_pop(L,2);
+ return r;
+}
/***
Sets the direction of gravity on this object.
@function rigidbody:setgravity({x,y,z})
@@ -215,9 +220,42 @@ int setdamping(lua_State *L){
return 0;
}
+/***
+Sets flags on this rigidbody
+@function rigidbody:setflags(flags)
+@tparam number flags
+*/
+int setflags(lua_State *L){
+ int flags = lua_tonumber(L,-1);
+ lua_pop(L,1);
+
+ lua_getfield(L,-1,"rigidbody");
+ btRigidBody *r = (btRigidBody*)lua_touserdata(L,-1);
+ lua_pop(L,2);
+
+ r->setFlags(flags);
+
+ return 0;
+}
+
+/***
+Apply an impulse to the rigidboy
+@function rigidbody:centralimpulse(vec3 impulse)
+@tparam vector3 impulse The direction to apply the impulse in
+*/
+int applyimpulse(lua_State *L){
+ double x,y,z,ox,oy,oz;
+ 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;
+}
+
extern const luaL_reg brigidbody_m[] = {
{"setgravity", setgravity},
{"applyforce", applyforce},
+ {"applyimpulse", applyimpulse},
{"getldamping", getlineardamping},
{"getadamping", getangulardamping},
{"setdamping", setdamping},
@@ -225,5 +263,6 @@ extern const luaL_reg brigidbody_m[] = {
{"getvelocity", getvelocity},
{"setvelocity", setvelocity},
{"setangfactor", setangfactor},
+ {"setflags", setflags},
{NULL, NULL}
};