aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--Makefile.shared7
-rw-r--r--Makefile.win447
-rw-r--r--src/client/callbackhandeler.cpp24
-rw-r--r--src/client/initdevice.cpp35
-rw-r--r--src/client/lua_api/gui/iguibutton.cpp10
-rw-r--r--src/client/lua_api/gui/iguifiledialog.cpp16
-rw-r--r--src/client/lua_api/gui/iguiimage.cpp14
-rw-r--r--src/client/lua_api/load_cphys.cpp13
-rw-r--r--src/client/lua_api/load_video.cpp20
-rw-r--r--src/client/lua_api/phys/cbcharactercontroller.cpp2
-rw-r--r--src/client/lua_api/phys/cbphysbox.cpp13
-rw-r--r--src/client/lua_api/phys/cbphysmodel.cpp12
-rw-r--r--src/client/lua_api/phys/cbphysmodel.hpp2
-rw-r--r--src/client/lua_api/scene/igeneric.cpp18
-rw-r--r--src/client/lua_api/scene/ilight.cpp23
-rw-r--r--src/client/lua_api/video/draw.cpp29
-rw-r--r--src/client/lua_api/video/draw.hpp8
-rw-r--r--src/client/lua_api/video/smaterial.cpp14
-rw-r--r--src/client/main.cpp49
-rw-r--r--src/server/main.cpp21
-rw-r--r--src/shared/lua_api/common.cpp2
-rw-r--r--src/shared/lua_api/load_common.cpp26
-rw-r--r--src/shared/lua_api/load_common.hpp11
-rw-r--r--src/shared/lua_api/load_net.cpp49
-rw-r--r--src/shared/lua_api/load_phys.cpp1
-rw-r--r--src/shared/lua_api/load_scene.cpp1
-rw-r--r--src/shared/lua_api/phys/bphysbuffer.cpp10
-rw-r--r--src/shared/lua_api/phys/bphysmodel.cpp19
-rw-r--r--src/shared/phys/physcommon.cpp49
30 files changed, 449 insertions, 498 deletions
diff --git a/Makefile b/Makefile
index c3d7109..62137a4 100644
--- a/Makefile
+++ b/Makefile
@@ -5,7 +5,7 @@ ifeq ($(OS), Windows_NT)
else
UNAME:=$(shell uname -s)
endif
-
+Q=@
ifeq ($(UNAME), Windows)
include Makefile.win
endif
diff --git a/Makefile.shared b/Makefile.shared
index f2192b9..05466b5 100644
--- a/Makefile.shared
+++ b/Makefile.shared
@@ -51,7 +51,8 @@ CLIENT_SRC=\
src/client/lua_api/scene/imesh\
src/client/lua_api/video/iimage\
src/client/lua_api/video/itexture\
- src/client/lua_api/video/smaterial
+ src/client/lua_api/video/smaterial\
+ src/client/lua_api/video/draw
SERVER_SRC=\
src/server/main\
@@ -65,6 +66,6 @@ ifeq ($(DEBUG), true)
CFLAGS += -g -shared -Wall -Werror -fPIC
LDFLAGS += -shared
else
- CFLAGS += -static
- #LDFLAGS += -static
+ CFLAGS += -static -O3
+ LDFLAGS += -static
endif
diff --git a/Makefile.win b/Makefile.win
index b4e8162..cd983cb 100644
--- a/Makefile.win
+++ b/Makefile.win
@@ -1,10 +1,5 @@
-#Detect what kind of system we're on
-ifeq ($(OS), Windows_NT)
- UNAME:=Windows
-else
- UNAME:=$(shell uname -s)
-endif
+include Makefile.shared
CP=cp
CXX?=g++
@@ -12,383 +7,67 @@ MKDIR?=mkdir
RM?=rm -f
ECHO?=echo
-ifeq ($(UNAME), Windows)
- EXE_EXT=.exe
- STA_LIB_EXT=.a
- DYN_LIB_EXT=.dll
- CMAKE_TYPE="MinGW Makefiles"
- CMAKE_FLAGS=-G $(CMAKE_TYPE) -DCMAKE_SH="CMAKE_SH-NOTFOUND"
-endif
+shared_objs=$(SHARED_SRC:src/shared/%=build/shared/%.o)
+client_objs=$(CLIENT_SRC:src/client/%=build/client/%.o)
+server_objs=$(SERVER_SRC:src/server/%=build/server/%.o)
+client_dlls=Irrlicht
+client_bins=bin/client/bin/brokengine_client.exe $(client_dlls:%=bin/client/bin/%.dll)
+server_bins=bin/server/bin/brokengine_server.exe
+bins=$(client_bins) $(server_bins)
+
+CLIENT_LIB_DIRS=\
+ -Llib/bullet/lib\
+ -Llib/irrlicht/lib/Win32-gcc\
+ -Llib/luajit/src\
+ -Llib/nng/static
+
+CLIENT_LIBS=\
+ -lBulletDynamics\
+ -lBulletCollision\
+ -lLinearMath\
+ -lIrrlicht\
+ -lnng\
+ -lluajit\
+ -lOpenGL32\
+ -lws2_32\
+ -lmswsock\
+ -ladvapi32\
+ -lwinmm\
+ -lm\
+ #-lstdc++
+
+CFLAGS+=-DNNG_STATIC_LIB
+
+all : $(bins)
+ echo "Done"
+
+clean:
+ $(RM) $(client_objs)
+ $(RM) $(server_objs)
+ $(RM) $(shared_objs)
+ $(RM) $(bins)
+
+bin/client/bin/brokengine_client.exe : $(client_objs) $(shared_objs)
+ $(Q)echo "Linking $@"
+ $(Q)$(CXX) $(LDFLAGS) -o $@ $^ $(CLIENT_LIB_DIRS) $(CLIENT_LIBS) # -Wl,--verbose
+
+bin/server/bin/brokengine_server.exe : $(server_objs) $(shared_objs)
+ $(Q)echo "Linking $@"
+ $(Q)$(CXX) $(LDFLAGS) -o $@ $^ $(CLIENT_LIB_DIRS) $(CLIENT_LIBS) # -Wl,--verbose
+
+$(shared_objs) : build/shared/%.o : src/shared/%.cpp src/shared/%.hpp
+ $(Q)echo "CXX $@"
+ $(Q)$(CXX) $(CFLAGS) -c -o $@ $<
+
+$(client_objs) : build/client/%.o : src/client/%.cpp src/client/%.hpp
+ $(Q)echo "CXX $@"
+ $(Q)$(CXX) $(CFLAGS) -c -o $@ $<
+
+$(server_objs) : build/server/%.o : src/server/%.cpp src/server/%.hpp
+ $(Q)echo "CXX $@"
+ $(Q)$(CXX) $(CFLAGS) -c -o $@ $<
+
+bin/client/bin/Irrlicht.dll : lib/irrlicht/bin/Win32-gcc/Irrlicht.dll
+ cp $^ $@
-ifeq ($(UNAME), Linux)
- EXE_EXT=
- STA_LIB_EXT=.a
- DYN_LIB_EXT=.so
- CMAKE_TYPE="Unix Makefiles"
- CMAKE_FLAGS= -G $(CMAKE_TYPE)
-endif
-BIN_DIR=bin
-BUILD_DIR=build
-SRC_DIR=src
-LIB_DIR=lib
-DOC_DIR=doc
-
-CLIENTNAME=client
-SERVERNAME=server
-MASTERNAME=#masterserver
-BINS=
-
-EX_PRE = brokengine_
-EX_PARTS = $(CLIENTNAME) $(SERVERNAME) $(MASTERNAME)
-
-NAMES = $(EX_PARTS:%=$(EX_PRE)%)
-BINS+= $(foreach part,$(EX_PARTS),$(BIN_DIR)/$(part)/bin/$(EX_PRE)$(part)$(EXE_EXT))
-BUILDS = $(EX_PARTS:%=$(BUILD_DIR)/%)
-SRC_DIRS = $(EX_PARTS:%=$(SRC_DIR)/%)
-
-
-LLUADIR=$(LIB_DIR)/luajit
-LIRRDIR=$(LIB_DIR)/irrlicht
-LBULDIR=$(LIB_DIR)/bullet
-LNNGDIR=$(LIB_DIR)/nng
-LOBJDIR=$(LIB_DIR)/tinyobjloader-c
-
-#Include directories
-ILUADIR=$(LLUADIR)/src
-IIRRDIR=$(LIRRDIR)/include
-IBULDIR=$(LBULDIR)/src
-INNGDIR=$(LNNGDIR)/include
-IOBJDIR=$(LOBJDIR)/
-ISHADIR=src
-INCLUDE_PATHS=-I$(ILUADIR) -I$(IIRRDIR) -I$(IBULDIR) -I$(INNGDIR) -I$(ISHADIR) -I$(IOBJDIR)
-#library directories
-
-CXXFLAGS+=$(INCLUDE_PATHS)
-
-CXXFLAGS+=-Llib
-
-#Library binary names
-ifeq ($(UNAME),Windows)
- LIB_N_LUA=lua51
- LIB_N_IRR=Irrlicht$(DYN_LIB_EXT)
-endif
-ifeq ($(UNAME),Linux)
- LIB_N_LUA=libluajit
- LIB_N_IRR=libIrrlicht$(DYN_LIB_EXT).1.8.4 #TODO: Automatically detect version
-endif
-
-#Libraries
-#static libs
-LIB_S_LUA=$(LIB_DIR)/libluajit.a
-LIB_S_IRR=$(LIB_DIR)/libIrrlicht.a
-LIB_S_BCO=$(LIB_DIR)/libBulletCollision.a
-LIB_S_BDY=$(LIB_DIR)/libBulletDynamics.a
-LIB_S_BLM=$(LIB_DIR)/libLinearMath.a
-LIB_S_NNG=$(LIB_DIR)/libnng.a
-
-#dynamic libraries
-LIB_D_LUA=$(LIB_DIR)/$(LIB_N_LUA)$(DYN_LIB_EXT)
-LIB_D_IRR=lib/$(LIB_N_IRR)
-# Bullet cannot be built dynamically
-LIB_D_BCO=$(LIB_S_BCO)
-LIB_D_BDY=$(LIB_S_BDY)
-LIB_D_BLM=$(LIB_S_BLM)
-LIB_D_NNG=lib/libnng$(DYN_LIB_EXT)
-
-ifeq ($(UNAME),Windows)
- CLIENT_DLLS=Irrlicht libnng lua51
- SERVER_DLLS=libnng lua51
-endif
-ifeq ($(UNAME),Linux)
- CLIENT_DLLS=Irrlicht libnng luajit
- SERVER_DLLS=libnng luajit
-endif
-ifeq ($(DEBUG),true)
- LIB_OBJS = $(LIB_D_LUA) $(LIB_D_IRR) $(LIB_D_BCO) $(LIB_D_BDY) $(LIB_D_BLM) $(LIB_D_NNG)
- BINS+=$(CLIENT_DLLS:%=$(BIN_DIR)/$(CLIENTNAME)/bin/%$(DYN_LIB_EXT)) $(SERVER_DLLS:%=$(BIN_DIR)/$(SERVERNAME)/bin/%$(DYN_LIB_EXT))
-else
- LIB_OBJS = $(LIB_S_LUA) $(LIB_S_IRR) $(LIB_S_BCO) $(LIB_S_BDY) $(LIB_S_BLM) $(LIB_S_NNG)
-endif
-
-# Libraries
-#order matters!
-CLIENT_LIBS=-lBulletDynamics -lBulletCollision -lLinearMath -lIrrlicht -lnng
-SERVER_LIBS=-lBulletDynamics -lBulletCollision -lLinearMath -lnng
-#LIBS=-lBulletDynamics -lBulletCollision -lLinearMath -lIrrlicht -lnng
-ifeq ($(UNAME),Windows)
- CLIENT_LIBS+=-lOpenGL32
-else
- CLIENT_LIBS+=-lGL
-endif
-ifeq ($(DEBUG),true)
-ifeq ($(UNAME),Windows)
- CLIENT_LIBS+=-llua51
- SERVER_LIBS+=-llua51
-endif
-ifeq ($(UNAME),Linux)
- CLIENT_LIBS+=-lluajit
- SERVER_LIBS+=-lluajit
-endif
-else
- CLIENT_LIBS+=-lluajit
- SERVER_LIBS+=-lluajit
-endif
-
-#can't compile with -std=c++11 because irrlicht will complain
-#LDFLAGS+=$(LIBS)
-ifeq ($(DEBUG), true)
-
-else
- CXXFLAGS += -static $(INCLUDE_PATHS) -D_IRR_STATIC_LIB_ -DNNG_STATIC_LIB
-endif
-S_LDFLAGS= $(SERVER_LIBS)
-C_LDFLAGS= $(CLIENT_LIBS)
-ifeq ($(UNAME),Windows)
- C_LDFLAGS += -mwindows -lwinmm -lstdc++
- ifeq ($(DEBUG),true)
-
- else
- C_LDFLAGS += -lws2_32 -lmswsock -ladvapi32
- S_LDFLAGS += -lws2_32 -lmswsock -ladvapi32
- endif
-endif
-
-ifeq ($(DEBUG),true)
- ifeq ($(UNAME),Windows)
- C_LDFLAGS+=-Wl,-subsystem,console
- endif
-endif
-
-ifeq ($(DEBUG),true)
- CXXFLAGS+=-O0 -g -Wall -Werror
-else
- CXXFLAGS+=-O3
-endif
-
-FSYSTEM_FOLDERS = lua_api phys util lua_api/irr lua_api/phys lua_api/gui lua_api/scene lua_api/video
-CLIENT_BUILD_FOLDERS = $(FSYSTEM_FOLDERS:%=$(BUILD_DIR)/$(CLIENTNAME)/%)
-
-all : $(BINS)
- @echo "Done"
-
-# The shared stuff
-LAPI_S_PHYS = bhingeconstraint bphysbox bphysmodel bphysgeneric bcharactercontroller bghostobject bcollider
-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)
-
-# The client-side only stuff
-LAPI_C_GUI = iguibutton iguicheckbox iguielement iguiimage iguilabel iguiwindow iguieditbox iguicolorselector iguifiledialog iguispinbox iguitreeview iguicombobox
-LAPI_C_PHYS = cbphysbox cbphysmodel cbcharactercontroller
-LAPI_C_SCENE = icamera igeneric ilight imesh
-LAPI_C_VIDEO = iimage itexture smaterial
-LAPI_C_IO = ifilesystem
-LAPI_LOAD = load_gui load_scene load_game load_cphys load_video load_io
-LAPI_OBJS_T = $(LAPI_C_GUI:%=gui/%.o) $(LAPI_C_PHYS:%=phys/%.o) $(LAPI_C_SCENE:%=scene/%.o) $(LAPI_C_VIDEO:%=video/%.o) $(LAPI_C_IO:%=io/%.o)
-LAPI_OBJS = $(LAPI_OBJS_T:%=$(BUILD_DIR)/$(CLIENTNAME)/lua_api/%) $(LAPI_LOAD:%=$(BUILD_DIR)/$(CLIENTNAME)/lua_api/%.o)
-CLIENT_FILES = initdevice menuhandeler callbackhandeler
-CLIENT_SRCS = $(CLIENT_FILES:%=$(BUILD_DIR)/$(CLIENTNAME)/%.o) $(LAPI_OBJS)
-CLIENT_OBJS = $(BUILD_DIR)/$(CLIENTNAME)/main.o $(CLIENT_SRCS) $(SHARED_CLIENT_OBJS)
-
-#Compile the client
-$(BIN_DIR)/$(CLIENTNAME)/bin/$(EX_PRE)$(CLIENTNAME)$(EXE_EXT) : $(CLIENT_OBJS) $(LIB_OBJS)
- @echo "[CLIENT] Building binary $@"
- $(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) $(C_LDFLAGS) $(LIB_OBJS) # -Wl,--verbose
-
-# does not have .hpp associated
-$(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 $(LIB_OBJS)
- @echo "[CLIENT] CXX $<"
- @$(CXX) $(CXXFLAGS) -c -o $@ $<
-
-# does have the .hpp associated in src/shared
-$(SHARED_CLIENT_OBJS) : $(BUILD_DIR)/$(CLIENTNAME)/%.o : src/shared/%.cpp $(SRC_DIR)/shared/%.hpp
- @echo "[CLIENT] CXX $<"
- @$(CXX) $(CXXFLAGS) -c -o $@ $<
-
-#compile server
-SERVER_FILES = lua_api/load_game lua_api/load_io
-SERVER_OBJ=$(SERVER_FILES:%=$(BUILD_DIR)/$(SERVERNAME)/%.o)
-SHARED_SERVER_FILES= $(LAPI_PATHS_T) util/hashmap phys/physcommon util/tinyobj
-SHARED_SERVER_OBJS=$(SHARED_SERVER_FILES:%=$(BUILD_DIR)/$(SERVERNAME)/%.o)
-SERVER_OBJS = $(SERVER_OBJ) $(SHARED_SERVER_OBJS) $(BUILD_DIR)/$(SERVERNAME)/main.o
-
-$(BIN_DIR)/$(SERVERNAME)/bin/$(EX_PRE)$(SERVERNAME)$(EXE_EXT) : $(SERVER_OBJS) $(LIB_OBJS)
- @echo "[SERVER] Building binary $@"
- @$(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) $(S_LDFLAGS)
-
-# Special, main does not have a .hpp associated with it
-$(BUILD_DIR)/$(SERVERNAME)/main.o : $(SRC_DIR)/server/main.cpp
- @echo "[SERVER] CXX $<"
- @$(CXX) $(CXXFLAGS) -c -o $@ $^
-
-$(SHARED_SERVER_OBJS) : $(BUILD_DIR)/$(SERVERNAME)/%.o : $(SRC_DIR)/shared/%.cpp $(SRC_DIR)/shared/%.hpp
- @echo "[SERVER] CXX $<"
- @$(CXX) $(CXXFLAGS) -c -o $@ $<
-
-$(SERVER_OBJ) : $(BUILD_DIR)/$(SERVERNAME)/%.o : $(SRC_DIR)/server/%.cpp $(SRC_DIR)/server/%.hpp
- @echo "[SERVER] CXX $<"
- @$(CXX) $(CXXFLAGS) -c -o $@ $<
-
-#compile libraries
-$(LIBLUA) : $(ILUADIR)/Makefile
- @echo "Could not find $(LIBLUA), rebuilding"
- cd $(ILUADIR) && $(MAKE) "BUILDMODE= static"
- $(CP) $(ILUADIR)/libluajit.a lib
-
-IRRMAKEFLAGS=
-IRRMADELIB=
-ifeq ($(UNAME), Windows)
- ifeq ($(DEBUG),true)
- IRRMAKEFLAGS=sharedlib_win32
- IRRMADELIB=$(LIRRDIR)/bin/Win32-gcc
- else
- IRRMAKEFLAGS=staticlib_win32
- IRRMADELIB=$(LIRRDIR)/lib/Win32-gcc
- endif
-else
- IRRMADELIB=$(LIRRDIR)/lib/Linux
-endif
-
-ifeq ($(DEBUG),true)
-else
- IRRMAKEFLAGS+=NDEBUG=1
-endif
-
-# Library - Irrlicht
-$(LIB_S_IRR) : $(IRRMADELIB)/libIrrlicht.a
- $(CP) $^ $@
-
-$(IRRMADELIB)/libIrrlicht.a : $(LIRRDIR)/source/Irrlicht/Makefile
- sed --in-place=OLD 's/ -ld3dx9d//' lib/irrlicht/source/Irrlicht/Makefile
- cd $(LIRRDIR)/source/Irrlicht && $(MAKE) $(IRRMAKEFLAGS)
-
-$(LIB_D_IRR) : $(IRRMADELIB)/$(LIB_N_IRR)
- @echo "Could not find $@, remaking..."
- $(CP) $^ $@
-
-$(BIN_DIR)/$(CLIENTNAME)/bin/Irrlicht$(DYN_LIB_EXT) : $(IRRMADELIB)/$(LIB_N_IRR)
- $(CP) $^ $@*
-
-$(IRRMADELIB)/$(LIB_N_IRR) : $(LIRRDIR)/source/Irrlicht/Makefile
- sed --in-place=OLD 's/ -ld3dx9d//' lib/irrlicht/source/Irrlicht/Makefile
- cd $(LIRRDIR)/source/Irrlicht && $(MAKE) $(IRRMAKEFLAGS)
-
-ifeq ($(UNAME),Windows)
- LUAJIT_ARGS:= TARGET_SYS=Windows
-else
- #LUAJIT_ARGS=
-endif
-
-# Library - Lua
-$(BIN_DIR)/$(CLIENTNAME)/bin/$(LIB_N_LUA)$(DYN_LIB_EXT) : $(LIB_D_LUA)
- $(CP) $^ $@
-
-$(BIN_DIR)/$(SERVERNAME)/bin/$(LIB_N_LUA)$(DYN_LIB_EXT) : $(LIB_D_LUA)
- $(CP) $^ $@
-
-$(LLUADIR)/src/libluajit$(STA_LIB_EXT) : $(LLUADIR)/src/Makefile
- cd $(LLUADIR)/src && $(MAKE) $(LUAJIT_ARGS) "BUILDMODE= static"
-
-$(LIB_S_LUA) : $(LLUADIR)/src/libluajit$(STA_LIB_EXT)
- $(CP) $^ $@
-
-$(LLUADIR)/src/lua51$(DYN_LIB_EXT) : $(LLUADIR)/src/Makefile
- cd $(LLUADIR)/src && $(MAKE) $(LUAJIT_ARGS) "BUILDMODE= dynamic"
-
-$(LIB_D_LUA) : $(LLUADIR)/src/$(LIB_N_LUA)$(DYN_LIB_EXT)
- $(CP) $^ $@
-
-# Library - Bullet
-$(LBULDIR)/lib/libBulletCollision.a : $(LBULDIR)/Makefile
- cd $(LBULDIR) && $(MAKE) BulletCollision
-
-$(LBULDIR)/lib/libBulletDynamics.a : $(LBULDIR)/Makefile
- cd $(LBULDIR) && $(MAKE) BulletDynamics
-
-$(LBULDIR)/lib/libLinearMath.a : $(LBULDIR)/Makefile
- cd $(LBULDIR) && $(MAKE) LinearMath
-
-ifeq ($(UNAME),Windows)
-$(LIB_D_BCO) : $(LBULDIR)/lib/libBulletCollision.a
- $(CP) $^ $@
-
-$(LIB_D_BDY) : $(LBULDIR)/lib/libBulletDynamics.a
- $(CP) $^ $@
-
-$(LIB_D_BLM) : $(LBULDIR)/lib/libLinearMath.a
- $(CP) $^ $@
-endif
-ifeq ($(UNAME),Linux)
-$(LIB_D_BCO) : $(LBULDIR)/src/BulletCollision/libBulletCollision.a
- $(CP) $^ $@
-
-$(LIB_D_BDY) : $(LBULDIR)/src/BulletDynamics/libBulletDynamics.a
- $(CP) $^ $@
-
-$(LIB_D_BLM) : $(LBULDIR)/src/LinearMath/libLinearMath.a
- $(CP) $^ $@
-endif
-
-$(LBULDIR)/Makefile : $(LBULDIR)/CMakeLists.txt
- cd $(LBULDIR) && cmake $(CMAKE_FLAGS) -DBUILD_EXTRAS=off -DBUILD_DEMOS=off
-
-# Library - NNG
-NNGFLAGS=
-$(BIN_DIR)/$(CLIENTNAME)/bin/libnng$(DYN_LIB_EXT) : $(LIB_D_NNG)
- $(CP) $^ $@
-
-$(BIN_DIR)/$(SERVERNAME)/bin/libnng$(DYN_LIB_EXT) : $(LIB_D_NNG)
- $(CP) $^ $@
-
-$(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) $< $@
-
-$(LIB_D_NNG) : $(LNNGDIR)/dynamic/libnng$(DYN_LIB_EXT)
- $(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)"
- cd $(LNNGDIR) && cmake $(CMAKE_FLAGS) $(NNGCMAKEFLAGS)
-
-TEST_BIN_NAMES=brokengine_client.exe Irrlicht.dll libnanomsg.dll libnng.dll lua51.dll
-TEST_BINS=$(TEST_BIN_NAMES:%=test/bin/%)
-
-#compile & run tests
-test: $(TEST_BINS)
- @$(ECHO) "Running busted tests"
- @./busted busted.spec
-
-$(TEST_BINS) : test/bin/% : bin/client/bin/%
- $(CP) $^ $@
-
-$(TEST_PATH)test_stream : $(TEST_SRC)test_streams.cpp $(SHARED_SRC)/lua_api/stream.cpp $(SHARED_SRC)/lua_api/stream.hpp
- @$(CC) $(CFLAGS) -o $(TEST_PATH)test_stream $(TEST_SRC)test_streams.cpp $(SHARED_SRC)/lua_api/stream.cpp $(SHARED_SRC)/lua_api/stream.hpp
-
-$(TEST_PATH)test_phys : $(TEST_SRC)test_phys.cpp
- $(CC) $(CFLAGS) -o $(TEST_PATH)test_phys $(TEST_SRC)test_phys.cpp $(SLIBS)
-#end tests
-
-cleantest :
- echo $(BUILDS:%=%/*.o)
-
-clean :
- $(RM) $(CLIENT_OBJS)
- $(RM) $(SERVER_OBJS)
- $(RM) $(BINS)
diff --git a/src/client/callbackhandeler.cpp b/src/client/callbackhandeler.cpp
index 0f1f87f..d522e84 100644
--- a/src/client/callbackhandeler.cpp
+++ b/src/client/callbackhandeler.cpp
@@ -1,6 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <vector>
+#include <assert.h>
extern "C" {
#include <lua.h>
#include <lauxlib.h>
@@ -38,8 +39,10 @@ GlobalEventReceiver::GlobalEventReceiver(IrrlichtDevice* d){
//device = d;
}
+
int callMouse(lua_State* L, const char* funcname, double x, double y, double event){
int consume = 0;
+ assert(lua_gettop(L) == 0);
lua_getglobal(L,"GAME");//GAME
pusherrorfunc(L);//{GAME},errfun
lua_getfield(L,-2,funcname);//{GAME},errfunc,funcname?
@@ -53,18 +56,22 @@ int callMouse(lua_State* L, const char* funcname, double x, double y, double eve
}else{
if(!lua_isnil(L,-1)){
consume = lua_toboolean(L,-1);
- lua_pop(L,-1);
}
}
- lua_pop(L,2);
+ lua_pop(L,3);
+ assert(lua_gettop(L) == 0);
}else{
//{GAME},errfunc,nil
lua_pop(L,3);//
+ assert(lua_gettop(L) == 0);
}
+ assert(lua_gettop(L) == 0);
return consume;
}
bool GlobalEventReceiver::OnEvent(const SEvent& e){
+ //printf("Onevent triggered when top was %d\n", lua_gettop(L));
+ assert(lua_gettop(L) == 0);
//lua_State* L = this->L;
EEVENT_TYPE type = e.EventType;
SEvent::SMouseInput se = e.MouseInput;
@@ -95,7 +102,7 @@ bool GlobalEventReceiver::OnEvent(const SEvent& e){
case EGET_LISTBOX_SELECTED_AGAIN: fieldname = "onSame"; break;
case EGET_FILE_SELECTED: fieldname = "onFileSelect"; break;
case EGET_DIRECTORY_SELECTED: fieldname = "onDirectorySelect"; break;
- case EGET_FILE_CHOOSE_DIALOG_CANCELLED: fieldname = "onFileChooserCancel"; break;
+ case EGET_FILE_CHOOSE_DIALOG_CANCELLED: fieldname = "onCanceled"; break;
case EGET_MESSAGEBOX_YES: fieldname = "onYes"; break;
case EGET_MESSAGEBOX_NO: fieldname = "onNo"; break;
case EGET_MESSAGEBOX_OK: fieldname = "onOk"; break;
@@ -122,6 +129,7 @@ bool GlobalEventReceiver::OnEvent(const SEvent& e){
if(lua_isnil(L,-1)){
printf("Element did not have a function %s, returning\n",fieldname);
lua_pop(L,3);//
+ assert(lua_gettop(L) == 0);
return false;
}
lua_rawgeti(L,LUA_REGISTRYINDEX,ref);//{guielement},errfunc(),func(),{guielement}
@@ -130,9 +138,12 @@ bool GlobalEventReceiver::OnEvent(const SEvent& e){
if(!lua_isnil(L,-1)){
printf("Got an argument back!\n");
int ans = lua_toboolean(L,-1);
+ lua_pop(L,3);
+ assert(lua_gettop(L) == 0);
return ans;
}
lua_pop(L,3);//
+ assert(lua_gettop(L) == 0);
return false;
}
break;
@@ -199,6 +210,7 @@ Detects any key presses from the game.
case EET_KEY_INPUT_EVENT:{
//printf("Got input event\n");
SEvent::SKeyInput se = e.KeyInput;
+ assert(lua_gettop(L) == 0);
lua_getglobal(L,"GAME");//{}
lua_getfield(L,-1,"onKeyDown");//{},()|nil
if(!lua_isnil(L,-1)){
@@ -210,10 +222,9 @@ Detects any key presses from the game.
lua_pushboolean(L,se.Control);//{GAME},GAME.onKeyDown(),errfunc,onKeyDown(),key_number,is_down,is_ctrl
lua_pushboolean(L,se.Shift);//{GAME},GAME.onKeyDown(),errfunc,onKeyDown(),key_number,is_down,is_ctrl,is_shift
lua_pcall(L,4,0,-6);//GAME,GAME.onKeyDown()
- lua_pop(L,2);
- }else{
- lua_pop(L,2);
}
+ lua_pop(L,lua_gettop(L));
+ assert(lua_gettop(L) == 0);
return false;
break;
}
@@ -222,5 +233,6 @@ Detects any key presses from the game.
return false;
}
}
+ assert(lua_gettop(L) == 0);
return true;
}
diff --git a/src/client/initdevice.cpp b/src/client/initdevice.cpp
index 3720d49..40a1e30 100644
--- a/src/client/initdevice.cpp
+++ b/src/client/initdevice.cpp
@@ -144,7 +144,7 @@ void parseSetting(const char* settingname, lua_State* L, settings* set){
}
void settingsFromTable(lua_State *L, SIrrlichtCreationParameters* p){
- lua_pushnil(L);
+ lua_pushnil(L);//nil
settings* set = (settings*)malloc(sizeof(settings));
printf("Loading settings...");
while(lua_next(L,-2) != 0){
@@ -172,20 +172,21 @@ void settingsFromTable(lua_State *L, SIrrlichtCreationParameters* p){
}
IrrlichtDevice* spawnIrrDevice(lua_State* L, char *path){
- //printf("Attempting to load settings...\n");
- char initname[] = "deviceinit.lua";
- size_t pathlen = strlen(initname) + strlen(path);
- char filename[pathlen + 1];
- sprintf(filename,"%s/%s",path,initname);
- int iErr = luaL_dofile(L,filename);
- SIrrlichtCreationParameters p = SIrrlichtCreationParameters();
- if(iErr != 0){
- printf("Failed to open lua file:%s\n", filename);
- }
- settingsFromTable(L,&p);
- IrrlichtDevice* dev = createDeviceEx(p);
- if(!dev)
- exit(1);
- dev->setWindowCaption(L"Borkengin");
- return dev;
+ //printf("Attempting to load settings...\n");
+ char initname[] = "deviceinit.lua";
+ size_t pathlen = strlen(initname) + strlen(path);
+ char filename[pathlen + 1];
+ sprintf(filename,"%s/%s",path,initname);
+ int iErr = luaL_dofile(L,filename);//ret
+ SIrrlichtCreationParameters p = SIrrlichtCreationParameters();
+ if(iErr != 0){
+ printf("Failed to open lua file:%s\n", filename);
+ }
+ settingsFromTable(L,&p);
+ IrrlichtDevice* dev = createDeviceEx(p);
+ if(!dev)
+ exit(1);
+ dev->setWindowCaption(L"Brokengine");
+ lua_pop(L,1);
+ return dev;
}
diff --git a/src/client/lua_api/gui/iguibutton.cpp b/src/client/lua_api/gui/iguibutton.cpp
index 42d2846..b8ff517 100644
--- a/src/client/lua_api/gui/iguibutton.cpp
+++ b/src/client/lua_api/gui/iguibutton.cpp
@@ -30,11 +30,11 @@ char lhashkey[20];
/***
Creates a new button.
Buttons may have the following fields set for callbacks:
-`.onClick(self)`
-`.onFocus(self)`
-`.onUnfocus(self)`
-`.onHover(self)`
-`.onLeave(self)`
+ .onClick(self)
+ .onFocus(self)
+ .onUnfocus(self)
+ .onHover(self)
+ .onLeave(self)
@function newbutton()
@tparam rect dimensions The rectangle to place the button at. If the box has a parent,
it is offset from the upper-left of the parent element.
diff --git a/src/client/lua_api/gui/iguifiledialog.cpp b/src/client/lua_api/gui/iguifiledialog.cpp
index 6303230..d717673 100644
--- a/src/client/lua_api/gui/iguifiledialog.cpp
+++ b/src/client/lua_api/gui/iguifiledialog.cpp
@@ -28,7 +28,11 @@ extern IrrlichtDevice* device;
/***
@function newfileopendialog()
-Creates a new dialog to open a file
+Creates a new dialog to open a file.
+The file creation window may have the following fields set for callbacks:
+ .onDirectorySelect(self)
+ .onFileSelect(self)
+ .onCanceled(self)
@tparam ?string title The rectangle to place the button at. If the box has a parent,
it is offset from the upper-left of the parent element.
@tparam ?string path The path to open the file dialog to
@@ -66,10 +70,10 @@ static int newfileopendialog(lua_State* L){
mbstowcs(title,titlec,titlecslen);
title[titlecslen] = L'\0';
}
-
+ //printf("Got all arguments\n");
IGUIEnvironment *env = device->getGUIEnvironment();
IGUIFileOpenDialog *but = env->addFileOpenDialog(title,modal,parent,-1,false,path);
-
+ //printf("Created file open dialog\n");
//printf("Added file open dialog\n");
lua_newtable(L);//{}
lua_pushlightuserdata(L,but);//{},ud_iguibutton
@@ -78,13 +82,13 @@ static int newfileopendialog(lua_State* L){
lua_setmetatable(L,-2);//{guielement}
//printf("Created lua representation\n");
- setelementcallback(L,EGET_DIRECTORY_SELECTED,"onDirectory");//
- setelementcallback(L,EGET_FILE_SELECTED,"onFileSelected");
+ setelementcallback(L,EGET_DIRECTORY_SELECTED,"onDirectorySelect");//
+ setelementcallback(L,EGET_FILE_SELECTED,"onFileSelect");
setelementcallback(L,EGET_FILE_CHOOSE_DIALOG_CANCELLED,"onCanceled");
//printf("Finished registering callback\n");
free(title);
- free(path);
+ //printf("Freed everything\n");
return 1;
}
diff --git a/src/client/lua_api/gui/iguiimage.cpp b/src/client/lua_api/gui/iguiimage.cpp
index 1d0f4dc..267cbd2 100644
--- a/src/client/lua_api/gui/iguiimage.cpp
+++ b/src/client/lua_api/gui/iguiimage.cpp
@@ -21,6 +21,7 @@ extern "C" {
@module gui
*/
using namespace irr;
+using namespace video;
using namespace gui;
extern IrrlichtDevice* device;
@@ -80,8 +81,21 @@ int setcolor(lua_State* L){
return 0;
}
+//setimage(self,itexture)
+int setimage(lua_State *L){
+ lua_getfield(L,-1,"texture");//{iguiimg},{itex}
+ ITexture* img = (ITexture*)lua_touserdata(L,-1);//{iguiimg},{itex},ud_itexture
+ lua_pop(L,2);//{iguiimg}
+ lua_getfield(L,-1,"guielement");//{iguiimg},ud_guiimg
+ IGUIImage *gimg = (IGUIImage*)lua_touserdata(L,-1);//{iguiimg},ud_guiimg
+ lua_pop(L,2);//
+ gimg->setImage(img);
+ return 0;
+}
+
static const luaL_reg iguiimage_m[] = {
{"setcolor", setcolor},
+ {"setimage", setimage},
{0, 0},
};
diff --git a/src/client/lua_api/load_cphys.cpp b/src/client/lua_api/load_cphys.cpp
index 92eaff0..2e2d18a 100644
--- a/src/client/lua_api/load_cphys.cpp
+++ b/src/client/lua_api/load_cphys.cpp
@@ -2,6 +2,7 @@
#include <stdlib.h>
#include <vector>
#include <map>
+#include <assert.h>
extern "C" {
#include <lua.h>
#include <lauxlib.h>
@@ -31,8 +32,8 @@ extern btBroadphaseInterface *BroadPhase;
int raytest(lua_State *L){
double fx,fy,fz;
double tx,ty,tz;
- popvector3d(L, &fx, &fy, &fz);
popvector3d(L, &tx, &ty, &tz);
+ popvector3d(L, &fx, &fy, &fz);
btVector3 from(fx, fy, fz);
btVector3 to(tx, ty, tz);
@@ -44,15 +45,23 @@ int raytest(lua_State *L){
}
void load_cphysfuncs(lua_State* L){
-
+ assert(lua_gettop(L) == 0);
+ printf("Registering cphysbox\n");
//phys things
+ assert(lua_gettop(L) == 0);
cbphysbox_register(L);
+ assert(lua_gettop(L) == 0);
cbcharactercontroller_register(L);
+ assert(lua_gettop(L) == 0);
cbphysmodel_register(L);
+ assert(lua_gettop(L) == 0);
bghostobject_register(L);
+ assert(lua_gettop(L) == 0);
+ assert(lua_gettop(L) == 0);
lua_getglobal(L,"phys");//{}
lua_pushcfunction(L,raytest);//{},raytest()
lua_setfield(L,-2,"raytest");//{}
lua_pop(L,1);
+ assert(lua_gettop(L) == 0);
}
diff --git a/src/client/lua_api/load_video.cpp b/src/client/lua_api/load_video.cpp
index f309180..b3487ca 100644
--- a/src/client/lua_api/load_video.cpp
+++ b/src/client/lua_api/load_video.cpp
@@ -8,6 +8,7 @@ extern "C" {
#include "video/smaterial.hpp"
#include "video/itexture.hpp"
#include "video/iimage.hpp"
+#include "video/draw.hpp"
#include <shared/lua_api/common.hpp>
@@ -79,6 +80,20 @@ int draw2dline(lua_State* L){
return 0;
}
+//{sx,sy,sz},{ex,ey,ez},{color}
+int draw3dline(lua_State* L){
+ double sx,sy,sz;
+ double ex,ey,ez;
+ long r,g,b,a;
+ popvector4i(L,&r,&g,&b,&a);
+ popvector3d(L,&ex,&ey,&ez);
+ popvector3d(L,&sx,&sy,&sz);
+
+ driver->draw3DLine(vector3df(sx,sy,sz),vector3df(ex,ey,ez),SColor(a,r,g,b));
+
+ return 0;
+}
+
void load_videofuncs(lua_State* L){
//printf("Loading video libraries...\n");
lua_newtable(L);//{}
@@ -88,11 +103,14 @@ void load_videofuncs(lua_State* L){
lua_pushcfunction(L,draw2dimage);//{},draw2dimage()
lua_setfield(L,-2,"drawtexture");//{}
lua_pushcfunction(L,draw2dline);//{},draw2dline()
- lua_setfield(L,-2,"drawline");//{}
+ lua_setfield(L,-2,"draw2dline");//{}
+ lua_pushcfunction(L,draw3dline);
+ lua_setfield(L,-2,"draw3dline");
lua_pop(L,1);//
smaterial_register(L);
itexture_register(L);
iimage_register(L);
+ draw_register(L);
}
diff --git a/src/client/lua_api/phys/cbcharactercontroller.cpp b/src/client/lua_api/phys/cbcharactercontroller.cpp
index 6a6da96..16ad1ad 100644
--- a/src/client/lua_api/phys/cbcharactercontroller.cpp
+++ b/src/client/lua_api/phys/cbcharactercontroller.cpp
@@ -115,6 +115,4 @@ void cbcharactercontroller_register(lua_State* L){
//printf("When registering physbox, new() is %p\n",newcbphysbox);
//printf("setpos is %p\n",cbphyssetpos);
- lua_pop(L,1);
-
}
diff --git a/src/client/lua_api/phys/cbphysbox.cpp b/src/client/lua_api/phys/cbphysbox.cpp
index 3c0f97d..e675a04 100644
--- a/src/client/lua_api/phys/cbphysbox.cpp
+++ b/src/client/lua_api/phys/cbphysbox.cpp
@@ -2,6 +2,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <list>
+#include <assert.h>
extern "C" {
#include <lua.h>
#include <lauxlib.h>
@@ -163,12 +164,15 @@ static const luaL_reg cbphysbox_m[] = {
};
void cbphysbox_register(lua_State* L){
+ assert(lua_gettop(L) == 0);
bphysbox_register(L);//
+ assert(lua_gettop(L) == 0);
lua_getglobal(L,"phys");//{}
lua_pushcfunction(L,newcbphysbox);//{},newcbphysbox()
- lua_setfield(L,-2,"newcphysbox");//{}
+ lua_setfield(L,-2,"newphysbox");//{phys}
lua_pop(L,1);//
+ assert(lua_gettop(L) == 0);
luaL_getmetatable(L,"phys.physbox");//phys.physbox
lua_newtable(L);//phys.physbox,{}
@@ -176,15 +180,14 @@ void cbphysbox_register(lua_State* L){
luaL_register(L,NULL,brigidbody_m);
luaL_register(L,NULL,igeneric_m);
luaL_register(L,NULL,cbphysbox_m);//phys.physbox,{}
- lua_pushstring(L,"rigidbody");
- lua_setfield(L,-2,"type");
+ lua_pushstring(L,"rigidbody");//phys.physbox,{},"rigidbody"
+ lua_setfield(L,-2,"type");//phys.physbox,{}
lua_setfield(L,-2,"__index");//phys.physbox
lua_pop(L,1);
-
//printf("When registering physbox, new() is %p\n",newcbphysbox);
//printf("setpos is %p\n",cbphyssetpos);
- lua_pop(L,1);
+ assert(lua_gettop(L) == 0);
}
diff --git a/src/client/lua_api/phys/cbphysmodel.cpp b/src/client/lua_api/phys/cbphysmodel.cpp
index ac27288..ae2559e 100644
--- a/src/client/lua_api/phys/cbphysmodel.cpp
+++ b/src/client/lua_api/phys/cbphysmodel.cpp
@@ -6,6 +6,7 @@
#include <map>
#include <functional>
#include <list>
+#include <assert.h>
extern "C" {
#include <lua.h>
#include <lauxlib.h>
@@ -260,9 +261,12 @@ static const luaL_reg bphysmodel_m[] = {
{0, 0},
};
-int cbphysmodel_register(lua_State* L){
+void cbphysmodel_register(lua_State* L){
+ assert(lua_gettop(L) == 0);
bphysmodel_register(L);
+ assert(lua_gettop(L) == 0);
+ assert(lua_gettop(L) == 0);
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
@@ -270,9 +274,11 @@ int cbphysmodel_register(lua_State* L){
luaL_register(L,NULL,brigidbody_m);//Add rigidbody things
luaL_register(L,NULL,bphysmodel_m);//anything specific?
lua_pop(L,2);
+ assert(lua_gettop(L) == 0);
+ assert(lua_gettop(L) == 0);
lua_getglobal(L,"phys");
luaL_register(L,NULL,bphysmodel_f);
-
- return 1;
+ lua_pop(L,1);
+ assert(lua_gettop(L) == 0);
}
diff --git a/src/client/lua_api/phys/cbphysmodel.hpp b/src/client/lua_api/phys/cbphysmodel.hpp
index 5ea42a8..d8495d2 100644
--- a/src/client/lua_api/phys/cbphysmodel.hpp
+++ b/src/client/lua_api/phys/cbphysmodel.hpp
@@ -8,5 +8,5 @@ extern "C" {
}
#include <irrlicht.h>
-int cbphysmodel_register(lua_State* L);
+void cbphysmodel_register(lua_State* L);
#endif
diff --git a/src/client/lua_api/scene/igeneric.cpp b/src/client/lua_api/scene/igeneric.cpp
index 63bf4bc..dcac022 100644
--- a/src/client/lua_api/scene/igeneric.cpp
+++ b/src/client/lua_api/scene/igeneric.cpp
@@ -161,6 +161,23 @@ int iscenesetscale(lua_State *L){
}
/***
+Sets the visibility of this scene element
+@function iscenenode:setvisible(bool)
+@tparam boolean visible Sets the visibility for this element
+*/
+//setvisible(true|false)
+int iscenesetvisible(lua_State *L){
+ int visible = lua_toboolean(L,-1);
+ lua_pop(L,1);
+ lua_getfield(L, -1, "node");
+ ISceneNode *i = (ISceneNode*)lua_touserdata(L,-1);//{node=ud_ISceneNode}, ud_ISceneNode
+ lua_pop(L,2);
+
+ i->setVisible(visible == 1);
+ return 0;
+}
+
+/***
Get the scale of this scene element.
@function iscenenode:getscale()
@treturn vector3d The scale scale of this element.
@@ -208,5 +225,6 @@ extern const luaL_reg igeneric_m[] = {
{"setscale", iscenesetscale},
{"getscale", iscenegetscale},
{"remove", isceneremove},
+ {"setvisible", iscenesetvisible},
{0, 0},
};
diff --git a/src/client/lua_api/scene/ilight.cpp b/src/client/lua_api/scene/ilight.cpp
index 972de83..1e292ee 100644
--- a/src/client/lua_api/scene/ilight.cpp
+++ b/src/client/lua_api/scene/ilight.cpp
@@ -17,6 +17,7 @@ extern "C" {
#include <shared/lua_api/common.hpp>
using namespace irr;
+using namespace video;
using namespace scene;
using namespace core;
@@ -27,9 +28,9 @@ static int newiscenelight(lua_State* L){
printf("Createing light!\n");
double x,y,z;
popvector3d(L,&x,&y,&z);//radius
- double radius = lua_tonumber(L,-1);
+ double radius = lua_tonumber(L,-1);
lua_pop(L,1);//
-
+
//Create the mesh
ISceneManager* smgr = device->getSceneManager();
ILightSceneNode* light = smgr->addLightSceneNode(0,vector3df(x,y,z),video::SColor(1.0f,1.0f,1.0f,1.0f),(f32)radius,(s32)-1);
@@ -45,11 +46,23 @@ static int newiscenelight(lua_State* L){
return 1;
- }
+}
+
+//settype(self,const)
+int settype(lua_State *L){
+ video::E_LIGHT_TYPE type = (video::E_LIGHT_TYPE)lua_tonumber(L,-1);//self,type
+ lua_pop(L,1);//self
+ lua_getfield(L,-1,"node");//self,ud_ILightSceneNode
+ ILightSceneNode *light = (ILightSceneNode*)lua_touserdata(L,-1);
+ lua_pop(L,2);//
+ light->setLightType(type);
+ return 0;
+}
static const luaL_reg ilight_m[] = {
{"getpos", iscenegetpos},
{"setpos", iscenesetpos},
+ {"settype", settype},
{0, 0},
};
@@ -59,6 +72,10 @@ void ilight_register(lua_State* L){
lua_pushcfunction(L,newiscenelight);//{scene},newiscenelight()
lua_setfield(L,-2,"newlight");//{scene}
+ set_const(L,ELT_POINT);
+ set_const(L,ELT_SPOT);
+ set_const(L,ELT_DIRECTIONAL);
+
lua_pop(L,1);//
luaL_newmetatable(L,"scene.ilight");//scene.ilight
diff --git a/src/client/lua_api/video/draw.cpp b/src/client/lua_api/video/draw.cpp
new file mode 100644
index 0000000..1f38f34
--- /dev/null
+++ b/src/client/lua_api/video/draw.cpp
@@ -0,0 +1,29 @@
+
+#include <irrlicht.h>
+#include <shared/lua_api/common.hpp>
+#include "draw.hpp"
+
+using namespace irr;
+using namespace video;
+using namespace core;
+
+extern IrrlichtDevice* device;
+extern IVideoDriver* driver;
+//drawline2d {startx,starty},{endx,endy},{r,g,b,a}
+int drawline2d(lua_State *L){
+ long r,g,b,a;
+ popvector4i(L, &r, &g, &b, &a);
+ long endx, endy;
+ popvector2i(L, &endx, &endy);
+ long startx, starty;
+ popvector2i(L, &startx, &starty);
+ driver->draw2DLine(position2d<s32>(startx, starty), position2d<s32>(endx,endy), SColor(r,g,b,a));
+ return 0;
+}
+
+void draw_register(lua_State *L){
+ lua_getglobal(L,"video");//{video}
+ lua_pushcfunction(L,drawline2d);//{video},drawline2d()
+ lua_setfield(L,-2,"drawline2d");//{video}
+ lua_pop(L,1);//
+}
diff --git a/src/client/lua_api/video/draw.hpp b/src/client/lua_api/video/draw.hpp
new file mode 100644
index 0000000..eb5a9a7
--- /dev/null
+++ b/src/client/lua_api/video/draw.hpp
@@ -0,0 +1,8 @@
+
+extern "C" {
+ #include <lua.h>
+ #include <lauxlib.h>
+ #include <lualib.h>
+}
+
+void draw_register(lua_State* L);
diff --git a/src/client/lua_api/video/smaterial.cpp b/src/client/lua_api/video/smaterial.cpp
index 2ef7053..510748c 100644
--- a/src/client/lua_api/video/smaterial.cpp
+++ b/src/client/lua_api/video/smaterial.cpp
@@ -38,8 +38,22 @@ int setTexture(lua_State* L){
return 0;
}
+//{Material},flag,state
+int setFlag(lua_State* L){
+ int b = lua_toboolean(L,-1);//{material},flag,state
+ lua_pop(L,1);//{material},flag
+ int flag = lua_tonumber(L,-1);//{material},flag
+ lua_pop(L,1);//{material}
+ lua_getfield(L,-1,"smaterial");//{material},ud_material
+ SMaterial* mat = (SMaterial*)lua_touserdata(L,-1);
+ lua_pop(L,2);
+ mat->setFlag((E_MATERIAL_FLAG)flag,b == 1 ? true : false);
+ return 0;
+}
+
static const luaL_reg smaterial_m[] = {
{"setTexture", setTexture},
+ {"setFlag", setFlag},
{0,0},
};
diff --git a/src/client/main.cpp b/src/client/main.cpp
index f08862c..98b2f61 100644
--- a/src/client/main.cpp
+++ b/src/client/main.cpp
@@ -1,5 +1,6 @@
#include <stdio.h>
#include <stdlib.h>
+#include <assert.h>
extern "C" {
#include <lua.h>
#include <lauxlib.h>
@@ -134,7 +135,9 @@ int main(int argc, char *argv[]){
L = state;
printf("Created lua state at %p\n",L);
//Load the lua libraries
+ assert(lua_gettop(L) == 0);
loadLLibs(state);
+ assert(lua_gettop(L) == 0);
//Defined in initdevice.cpp, creates the irrlicht device
printf("Argc: %d\n",argc);
char *path;
@@ -143,7 +146,9 @@ int main(int argc, char *argv[]){
}else{
path = (char*)"../data";
}
+ assert(lua_gettop(L) == 0);
device = spawnIrrDevice(state,path);
+ assert(lua_gettop(L) == 0);
if (!device){
printf("Failed to initalize device\n");
return 1;
@@ -152,19 +157,24 @@ int main(int argc, char *argv[]){
//ILogger* log = device->getLogger();
//log->setLogLevel(ELL_NONE);
//Loads libraries for interfaceing with irrlicht
+ assert(lua_gettop(L) == 0);
luaL_openlibs(state);
+ assert(lua_gettop(L) == 0);
loadIrrLibs(state,device);
+ assert(lua_gettop(L) == 0);
loadNetLibs(state);
+ assert(lua_gettop(L) == 0);
loadCommonLibs(state);
+ assert(lua_gettop(L) == 0);
printf("Loadded irr libs...\n");
//Sets the global event handeler
printf("Creating event receiver\n");
GlobalEventReceiver ger = GlobalEventReceiver(device);
printf("Created event receiver\n");
device->setEventReceiver(&ger);
-
+ assert(lua_gettop(L) == 0);
pusherrorfunc(L);//errfunc
- int err = luaL_loadfile(state,"init.lua");
+ int err = luaL_loadfile(state,"init.lua");//errfunc,init()
printf("Error loading init.lua: %d\n",err);
switch(err){//errmsg or nothing
case 0:
@@ -181,8 +191,10 @@ int main(int argc, char *argv[]){
}
//errfunc,initfile()
printf("Loaded file\n");
- lua_pcall(state,0,0,-2);
+ lua_pcall(state,0,0,-2);//errfunc()
+ lua_pop(L,1);//
printf("Finished running init.lua");
+ assert(lua_gettop(L) == 0);
//int iErr = luaL_dofile(state,"init.lua");
//if(iErr != 0){
//printf("Failed to open lua file:%s/init.lua\n",path);
@@ -205,14 +217,21 @@ int main(int argc, char *argv[]){
printf("Device is %p\n",device);
while(device->run()){
//printf("Start gameloop net\n");
+ assert(lua_gettop(L) == 0);
gameloop_net(L);
+ assert(lua_gettop(L) == 0);
//printf("End gameloop net\n");
//printf("Start gameloop phys\n");
+ assert(lua_gettop(L) == 0);
gameloop_phys(UpdateElement);
+ assert(lua_gettop(L) == 0);
//printf("End gameloop phys\n");
if(device->isWindowActive()){
+ assert(lua_gettop(L) == 0);
driver->beginScene(true, true, background);
+ assert(lua_gettop(L) == 0);
//printf("Device active, began scene\n");
+ assert(lua_gettop(L) == 0);
pusherrorfunc(state);
lua_getglobal(state,"GAME");//err(),{GAME}
lua_getfield(state,-1,"draw");//err(),{GAME},GAME.draw()
@@ -222,10 +241,12 @@ int main(int argc, char *argv[]){
}else{
lua_pop(state,3);
}
+ assert(lua_gettop(L) == 0);
//printf("Finished calling GAME.draw()\n");
smgr->drawAll();
//printf("Scene manager drew all\n");
+ assert(lua_gettop(L) == 0);
lua_getglobal(state,"GAME");
lua_getfield(state,-1,"drawPostScene");
if(!lua_isnil(state,-1)){
@@ -234,9 +255,11 @@ int main(int argc, char *argv[]){
}else{
lua_pop(state,2);
}
+ assert(lua_gettop(L) == 0);
//printf("Post draw scene completed\n");
guienv->drawAll();
//printf("Gui draw all completed\n");
+ assert(lua_gettop(L) == 0);
lua_getglobal(state,"GAME");
lua_getfield(state,-1,"drawPostGui");
if(!lua_isnil(state,-1)){
@@ -245,23 +268,29 @@ int main(int argc, char *argv[]){
}else{
lua_pop(state,2);
}
+ assert(lua_gettop(L) == 0);
//printf("GAME.drawPostGui completed\n");
driver->endScene();
}else{
+ assert(lua_gettop(L) == 0);
device->yield();
+ assert(lua_gettop(L) == 0);
}
- lua_getglobal(state,"GAME");//{}
- lua_getfield(state,-1,"tick");//{},function_tick()
+ assert(lua_gettop(L) == 0);
+ pusherrorfunc(L);//errfunc()
+ lua_getglobal(state,"GAME");//errfunc(),{}
+ lua_getfield(state,-1,"tick");//errfunc(),{},function_tick()
if(!lua_isnil(state,-1)){
- lua_call(state,0,0);
- lua_pop(state,1);
- }else{
- lua_pop(state,2);
+ lua_pcall(state,0,0,-3);//errfunc(),{}
+ lua_pop(state,2);//
+ }else{//errfunc(),{},nil
+ lua_pop(state,3);//
}
+ assert(lua_gettop(L) == 0);
}
+ assert(lua_gettop(L) == 0);
//phys_shutdown(RemoveISceneNode);
phys_shutdown();
-
device->drop();
printf("Goodbye\n");
return 0;
diff --git a/src/server/main.cpp b/src/server/main.cpp
index c4c4d8e..8817329 100644
--- a/src/server/main.cpp
+++ b/src/server/main.cpp
@@ -1,6 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
+#include <assert.h>
extern "C" {
#include <lua.h>
#include <lauxlib.h>
@@ -66,24 +67,34 @@ int main (int argc, char *argv[]){
putenv(envstr);
//printf("Put lua path\n");
L = luaL_newstate();
+ assert(lua_gettop(L) == 0);
//printf("Created lua state\n");
//lua_newtable(L);//{}
//lua_setglobal(L,"GAME");//
+ assert(lua_gettop(L) == 0);
load_gamefuncs(L);
+ assert(lua_gettop(L) == 0);
printf("Created global table\n");
+ assert(lua_gettop(L) == 0);
phys_genesis();
printf("Started phys\n");
+ assert(lua_gettop(L) == 0);
luaL_openlibs(L);
printf("Opened standard libs\n");
+ assert(lua_gettop(L) == 0);
loadLLibs(L);
printf("Opened aux libs\n");
+ assert(lua_gettop(L) == 0);
loadNetLibs(L);
printf("Opened net libs\n");
+ assert(lua_gettop(L) == 0);
load_physfuncs(L);
printf("Opened phys libs\n");
+ assert(lua_gettop(L) == 0);
load_iofuncs(L);
printf("About to push error func\n");
+ assert(lua_gettop(L) == 0);
pusherrorfunc(L);//errfunc
printf("pushed error func\n");
size_t init_file_path_len = snprintf(NULL,0,"%s/init.lua",path);
@@ -104,14 +115,19 @@ int main (int argc, char *argv[]){
}
//errfunc,initfile()
printf("Loaded file\n");
- lua_pcall(L,0,0,-2);
+ lua_pcall(L,0,0,-2);//errfunc
+ lua_pop(L,1);
+ assert(lua_gettop(L) == 0);
do{
+ assert(lua_gettop(L) == 0);
//printf("Start of server gameloop\n");
gameloop();
+ assert(lua_gettop(L) == 0);
//printf("Gameloop\n");
//std::this_thread::yield();
std::this_thread::sleep_for(std::chrono::milliseconds(100));
//printf("Thread yeild\n");
+ assert(lua_gettop(L) == 0);
pusherrorfunc(L);//errfunc()
lua_getglobal(L,"GAME");//errfunc(),{}
lua_getfield(L,-1,"tick");//errfunc(),{},function_tick()?
@@ -123,9 +139,12 @@ int main (int argc, char *argv[]){
//printf("Did not find tick function\n");
lua_pop(L,3);
}
+ assert(lua_gettop(L) == 0);
//printf("End of server gameloop\n");
}while(game_active);
+ assert(lua_gettop(L) == 0);
phys_shutdown();
+ assert(lua_gettop(L) == 0);
printf("Goodbye\n");
return 0;
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));
diff --git a/src/shared/phys/physcommon.cpp b/src/shared/phys/physcommon.cpp
index 379ad55..45374d2 100644
--- a/src/shared/phys/physcommon.cpp
+++ b/src/shared/phys/physcommon.cpp
@@ -2,8 +2,14 @@
#define __shared_physcommon_h
#include <chrono>
#include <list>
+#include <assert.h>
#include <btBulletDynamicsCommon.h>
-
+extern "C" {
+ #include <lua.h>
+ #include <lauxlib.h>
+ #include <lualib.h>
+}
+#include <shared/lua_api/common.hpp>
#include "physcommon.hpp"
using namespace std::chrono;
@@ -11,6 +17,7 @@ using namespace std::chrono;
btDiscreteDynamicsWorld* World;
std::list<btCollisionObject*> Objects;
std::list<btKinematicCharacterController*> Chars;
+extern lua_State *L;
extern void dropCollisionObject(btCollisionObject* b);
@@ -45,7 +52,7 @@ btCollisionDispatcher* Dispatcher;
btSequentialImpulseConstraintSolver* Solver;
void phys_genesis(){
- broadphase = new btAxisSweep3(btVector3(-1000,-1000,-1000),btVector3(1000,1000,1000));
+ broadphase = new btAxisSweep3(btVector3(-100000,-100000,-100000),btVector3(100000,100000,100000));
broadphase ->getOverlappingPairCache()->setInternalGhostPairCallback(new btGhostPairCallback());
//printf("Broadphase\n");
CollisionConfiguration = new btDefaultCollisionConfiguration();
@@ -84,6 +91,7 @@ void UpdatePhysics(double TDeltaTime, void(*f)(btCollisionObject *)) {
//printf("Pre step simulation\n");
World->stepSimulation(TDeltaTime * 0.2f, 60);
//printf("Done step simulation\n");
+ assert(lua_gettop(L) == 0);
if(f){
//printf("Updating the position of %llu objects\n", Objects.size());
// Relay the object's orientation to irrlicht
@@ -91,15 +99,52 @@ void UpdatePhysics(double TDeltaTime, void(*f)(btCollisionObject *)) {
(*f)(*it);
}
}
+ assert(lua_gettop(L) == 0);
+
+ //Call phy.oncollide(obj1, obj2, point1, point2, normal2)
+ lua_getglobal(L,"phys");//phys
+ lua_getfield(L,-1,"colliders");//phys,colliders
+ int nummanifolds = World->getDispatcher()->getNumManifolds();
+ pusherrorfunc(L);//{phys},{colliders},errfunc()
+ for(int i = 0; i < nummanifolds; i++){
+ //printf("Looking at manifold %d, top is %d\n", i, lua_gettop(L));
+
+ lua_getfield(L,-3,"oncollide");//{phys},{colliders},errfunc(),oncollide()
+ if(lua_isnil(L,-1)){
+ lua_pop(L,4);
+ return;
+ }
+ btPersistentManifold *mf = World->getDispatcher()->getManifoldByIndexInternal(i);
+ btCollisionObject *oa = (btCollisionObject*)mf->getBody0();
+ btCollisionObject *ob = (btCollisionObject*)mf->getBody1();
+ btManifoldPoint mp = mf->getContactPoint(i);
+ btVector3 pa = mp.getPositionWorldOnA();
+ btVector3 pb = mp.getPositionWorldOnB();
+ btVector3 pn = mp.m_normalWorldOnB;
+ lua_pushlightuserdata(L,oa);//{phys},{colliders},errfunc(),oncollide(),ud_oa
+ lua_gettable(L,-4);//{phys},{colliders},errfun(),concollide(),{oa}
+ lua_pushlightuserdata(L,ob);//{phys},{colliders},errfunc(),oncollide(),{oa},ud_ob
+ lua_gettable(L,-5);//{phys},{colliders},errfunc(),oncollide(),{oa},{ob}
+ pushvector3d(L,pa.x(),pa.y(),pa.z());
+ pushvector3d(L,pb.x(),pb.y(),pb.z());
+ pushvector3d(L,pn.x(),pn.y(),pn.z());//{phys},{colliders},errfunc(),oncollide(),{oa},{ob},{pa},{pb},{normal}
+ int err = lua_pcall(L,5,0,-7);//{phys},{colliders},errfunc()
+ if(err)
+ printf("Failed to call oncollide\n");
+ }
+ lua_pop(L,3);
+ assert(lua_gettop(L) == 0);
}
high_resolution_clock::time_point t1 = high_resolution_clock::now();
void gameloop_phys(void(*f)(btCollisionObject *)){
+ assert(lua_gettop(L) == 0);
//printf("Doing phys gameloop\n");
high_resolution_clock::time_point now = high_resolution_clock::now();
duration<double> delta = now-t1;
double steps = delta.count() * 10;
UpdatePhysics(steps,f);
t1 = now;
+ assert(lua_gettop(L) == 0);
}
#endif