Skip to content

Commit

Permalink
New Lua bindings and library (Revolutionary-Games#511)
Browse files Browse the repository at this point in the history
* Updated setup script

* Removed lua and luabind. Replaced with luajit and sol. Didn't change the code to use it yet

* Added luajit to cmake

* Moved individual script_bindings files' contents to script_initializer

* Changed luabind forward declarations to sol forward declarations

* Now ignoring a bunch of warnings so that sol.hpp can be included

* Started fixing things to use sol, again this time not moving binding methods to a single file

* System wrapper for lua. First few bindings done

* More bindings

* Collision filter fixed. .collisions now returns a table and works a bit differently

* More wrapper updates

* Tried to made wrappers more ready to use default values

* Moving component stuff to use the new lua wrapper

* Fixed some more wrappers

* Hooked up engine to new lua stuff. More basic wrappers

* Possibly not-optimal Component bindings

* Created new compound registry bindings

* Working on final script bindings

Only some Ogre classes haven't been updated yet

* Finished the largest file with new bindings, perhaps could be split

* Thrive main library now compiles. tests still need fixing

* Updated ogre tests, everything now compiles

* Played around a bit with error reporting from lua

* Fixed the first few classes for the new bindings

* Added SystemWrapper bindings

* Added system class creation helper

* Fixing lua scripts for new things

* Engine now more carefully casts things to Systems

* Added a new Bullet physics wrapper

* Started adding Lua replacements of C++ GameState and Engine

* Lua fixes

* Added luabindings for Game

* Removed stuff that is now in lua from the C++ side

* Started moving stuff from C++ to Lua and creating wrappers for C++ code to use

Fixing lua scripts and creating wrappers for C++ to use

* Renamed GameState to GameStateData

* Moved stuff from engine.cpp to lua engine

Also fixed compiling entity.cpp

* Updated to new GameStateData

* C++ now compiles. Lua files are still a mess

* Finished reimplementing the removed c++ stuff in lua

Switched lua classes to use "create" method as a constructor so now
"init" can be used like before

* First Lua systems can now be created without errors

There are still bunch of lua scripts that need fixing

* Updated sol library

* Exposed ComponentWrapper to Lua

* Fixed engine binding things as sol::var when they should have been sol::property

* Fixed Component registering from Lua

* Rewrote microbe ai classes for new sol bindings

* Added notes about changed things

Fixed species_system.lua. There was an improperly formatted function
call in this file, I added an explanation to the notes on how to fix
this

* Lua stacktraces now don't include the top most entry

the entry was always [C]:-1 so it wasn't very helpful

* Fixed Component::TYPE_ID access from Lua

* Removed some old systems code

* Fixed indentation

* Updated examples

* Updated more Lua files to use new classes

* Added missing call to .new on EntityFilter

* Added missing call to ScriptEntityFilter bindings

* The engine now stops loading Lua scripts after the first failed file

* Exposed correct constructor for PowerupSystem

* More fixes to Lua files

* Added cmake argument LUA_CHECKS which enables more lua debug checks

Also the linuxrelease refuses to build if LUA_CHECKS is on

* Updated Entity documentation

* Exposed EntityManager to Lua

* Updated systems to have a proper init method and added base classes to some systems

* Added some lua class checks and some notes about usage

* Rewrote some more Lua scripts to use new classes

* Some random formatting change

* Added get method for current GameState to Engine

* Fixed C++ systems that relied on broken Entity constructors

* Added table call constructors for some Ogre types

* Changed the lua error functions slightly

* Fixed some lua bindings being wrong

* Still fixing lua scripts

* Removed old system that doesn't even work with Ogre 2.0

* Added missing Touchable bases to RigidBodyComponent

* shutdown is now called even if an error occurs

* cleanup

* Replaced entity addComponent luabindings

* C++ components now expose a factory to lua. Also updated entity to accept the factory constructed c++ stuff

* Renamed factory functions to be just 'new'

* Lua fixed class calls

* Added an unwrap function to lua

* Collision shapes now properly use factories to create shared_ptrs

* Components now share a macro for binding common things.

+ Added the component "castFrom" function

* Fixed Microbe not casting accessed Components to their subclasses

* All setup code now runs. But the game crashes just after entering the main loop

* Fixed moving temporary prevents copy elision

* Fixed engine shutdown causing a crash

CEGUIWIndow is now a factory, because probably CEGUI will delete the
window with its parent

GameStateData owning the SceneManager checks is ogre still valid before
destructing

* Formatting change. Main loop now starts

* Fixed reading thrive version when the file was one folder up

* Fixed startup message thrive version

* Exposed rootGuiWindow again

* Added processRemovals to EntityManager Lua bindings

* Exposed paused Engine property to Lua

* Thrive now starts and shows the menu correctly!

* Made FPS counter actually accurate

* Made Game time utilities take things by reference

* Added frame time counting to FPS counter

* Added a convenience getComponent lua function

* Switched fixes to use the new convenience getComponent

* Made Components use cheaper casts when accessed from Lua

* Various lua binding fixes and lua updates to use new classes

* setup now attempts to set LUAJIT_ENABLE_LUA52COMPAT on in luajit makefile

* Fixed microbe spawn function not correctly attempting to spawn a cell

Also removed slightly confusing call constructor that isn't actually
used all that often

* Microbe editor can now be entered

* Added a workaround for crash after loading save

* Fixed container bindings to accept "get" without default value

* Exposed EntityManager methods required for saving/loading

* Restored intro video

* Systems no longer have an enabled property, GameState already manages which ones to run

Fixed saving and loading

* Changed to use the new class syntax

* Everything now mostly work

There's just 3 cells just after splitting

and all the compounds drain out of cells immediately

(and there's a workaround to a crash in restoring sounds after loading
game)

* Fixed bug venting everything

Current bugs:
3 cells spawn after dividing when tutorial is completed and after that
(but not when tutorial is skipped)

If tutorial is complete and the game is started again from the main menu
and the tutorial is skipped the game crashes. Also other way around
works: if you first play normally and then play the tutorial the game
crashes when exiting the editor.

* Fixed including sol directly

* Removed unneeded lua link creation

* Fixed packaging script and included librtmp in releases

* Updated SOL

CEGUIWindow is now a basic usertype, which can be used as an example if
others need to be converted

* Updated CEGUI version

* Added a few more libraries Narotiza mentioned being missing

* Windows support for luajit

* Fixed setup system not being configured to pull updates

* Updated sol to fix compile errors

* Updated CEGUI version

also some cleanup on CEGUIVideoPlayer

* Added option to profile Lua memory usage

* Split some really long lines

* Lua now automatically sets the version number in the GUI

* Removed Cg program manager from CMakeLists and added a better error for missing Ogre plugins

* Removed more references to CgProgramManager plugin

* Added a cscope indexing script

* Added a commented out debugging line

* Fixed Lua errors caused by the earlier merge

also removed some process speed things from bio_process_registry.cpp

* Workaround for compile errors due to disagreement regarding cegui version
  • Loading branch information
hhyyrylainen authored May 5, 2017
1 parent b92c626 commit 8055e85
Show file tree
Hide file tree
Showing 272 changed files with 21,793 additions and 39,215 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,8 @@ nbproject/
!thriveversion.ver
# Temporary/backup files
*~


# Cscope files
/cscope.files
/RunCodeIndexing.rb
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[submodule "contrib/googletest"]
path = contrib/googletest
url = git://github.com/liquid-mirror/googletest.git
[submodule "contrib/luabind"]
path = contrib/luabind
url = git://github.com/rpavlik/luabind.git
[submodule "contrib/lua/luajit"]
path = contrib/lua/luajit
url = http://luajit.org/git/luajit-2.0.git
104 changes: 59 additions & 45 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ set(OGRE_PLUGINS
# Plugin_OctreeSceneManager
# Plugin_OctreeZone
Plugin_ParticleFX
Plugin_CgProgramManager
# Plugin_CgProgramManager
# Plugin_PCZSceneManager
RenderSystem_GL
)
Expand Down Expand Up @@ -137,21 +137,36 @@ find_package(Bullet REQUIRED QUIET)

include_directories(SYSTEM ${BULLET_INCLUDE_DIRS})

##########
# TinyXML #
##########

find_package(TinyXML REQUIRED QUIET)

#######
# Lua #
#######

option(LUA_CHECKS "when ON enables additional Lua safety
checks. Lowers performance so only use while debugging"
OFF)

if(LUA_CHECKS)

add_definitions(-DSOL_CHECK_ARGUMENTS)

endif()

include_directories(
SYSTEM
"${CMAKE_CURRENT_SOURCE_DIR}/contrib/lua/lua/src"
"${CMAKE_CURRENT_SOURCE_DIR}/contrib/luabind/"
)
"${CMAKE_CURRENT_SOURCE_DIR}/contrib/lua"
)

link_directories(
"${CMAKE_CURRENT_SOURCE_DIR}/contrib/lua/luajit/src"
)

set(LUA_FOUND TRUE)

if(WIN32)
set(LUA_LIBRARIES lua51.dll)
else()
set(LUA_LIBRARIES luajit.a dl)
endif()


#######
# CEGUI #
Expand All @@ -177,26 +192,6 @@ find_package(TinyXML REQUIRED QUIET)

include_directories(SYSTEM ${TINYXML_INCLUDE_DIR})

if(WIN32)
add_definitions(-DLUA_BUILD_AS_DLL)
endif()

add_subdirectory(
"${CMAKE_CURRENT_SOURCE_DIR}/contrib/lua/"
)

set(LUA_FOUND TRUE)
set(LUA_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/contrib/lua/lua/src")
set(LUA_LIBRARIES lua)
#set(BUILD_SHARED_LUABIND ON)
#set(INSTALL_LUABIND ON)
set(LIB_DIR bin)
add_definitions(-DLUABIND_CPLUSPLUS_LUA)

add_subdirectory(
"${CMAKE_CURRENT_SOURCE_DIR}/contrib/luabind/"
)

################
# cAudio #
################
Expand Down Expand Up @@ -230,7 +225,10 @@ include_directories(

# Compile using c++11 and using sse2
#no-unused-variable is necessary to supress werror while compiling cAudio
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1y -msse2 -Wno-unused-function")
# SOL uses a bunch of recursive templates so unless all lua bindings are written to be
# less efficient runtime dynamic bindings we need to have bigger template depth.
# though this may kill compile times
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1y -msse2 -Wno-unused-function -Wno-error=redundant-decls -ftemplate-depth=1500" )


find_package(Threads)
Expand Down Expand Up @@ -265,7 +263,7 @@ target_link_libraries(ThriveLib
${CEGUI_LIBRARY}
${TINYXML_LIBRARIES}
${OpenAL_LIBRARIES}
luabind
${LUA_LIBRARIES}
)

target_link_libraries(ThriveLib
Expand Down Expand Up @@ -331,7 +329,7 @@ set_source_files_properties(
)

add_executable(RunTests ${TEST_SOURCE_FILES})
target_link_libraries(RunTests ThriveLib gtest_main)
target_link_libraries(RunTests ThriveLib gtest_main ${LUA_LIBRARIES})

#################
# Documentation #
Expand Down Expand Up @@ -367,10 +365,6 @@ install(TARGETS Thrive
LIBRARY DESTINATION bin
)

install(EXPORT lua
DESTINATION bin
)

# Version file

install(FILES
Expand Down Expand Up @@ -581,6 +575,8 @@ if(WIN32)
"${MINGW_ENV}/install/bin/avutil-55.dll"
"${MINGW_ENV}/install/bin/swscale-4.dll"
"${MINGW_ENV}/install/bin/swresample-2.dll"
"${CMAKE_SOURCE_DIR}/contrib/lua/luajit/src/lua51.dll"
"${CMAKE_SOURCE_DIR}/contrib/lua/luajit/src/luajit.exe"
DESTINATION bin
CONFIGURATIONS Debug
)
Expand Down Expand Up @@ -640,6 +636,12 @@ elseif(UNIX)
OGRE_PLUGIN_LIB_DBG
OGRE_PLUGIN_LIB_REL
)

if(NOT EXISTS "${OGRE_PLUGIN_LIB_REL}" OR NOT EXISTS "${OGRE_PLUGIN_LIB_DBG}")
message(SEND_ERROR "Ogre plugin file doesn't exist: ${OGRE_PLUGIN} . Did you build "
"all the required Ogre plugins?")
endif()

# Release
InstallFollowingSymlink(
${OGRE_PLUGIN_LIB_REL}
Expand Down Expand Up @@ -688,12 +690,24 @@ if(UNIX)
"${CMAKE_CURRENT_BINARY_DIR}/CMakeLibraryList.xml" @ONLY
)

add_custom_target(linuxrelease
COMMAND "${CMAKE_SOURCE_DIR}/cpack/PackageProject.rb" "${CMAKE_CURRENT_BINARY_DIR}"
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/cpack"
DEPENDS ThriveLib doc
)
# The name of the Thrive target somehow breaks in the above command
add_dependencies(linuxrelease Thrive)
if(LUA_CHECKS)

# creating debug releases is bad
add_custom_target(linuxrelease
# Please don't touch this really complex command output format
COMMAND "ruby" "-e" \"puts \\\"\\033[31m\\\"\; puts 'ERROR: LUA_CHECKS is on. release build is disabled. Please run \\'cmake .. -DLUA_CHECKS=OFF\\' and try again'\; puts \\\"\\033[0m\\\"\; exit(3) \"
)

else()

add_custom_target(linuxrelease
COMMAND "${CMAKE_SOURCE_DIR}/cpack/PackageProject.rb" "${CMAKE_CURRENT_BINARY_DIR}"
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/cpack"
DEPENDS ThriveLib doc
)
# The name of the Thrive target somehow breaks in the above command
add_dependencies(linuxrelease Thrive)

endif()

endif()
54 changes: 41 additions & 13 deletions SetupThrive.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ def checkRunFolder(suggestedfolder)
end
end

def projectFolder(baseDir)

return File.join baseDir, "thrive"

end

ThriveBranch = "master"
#ThriveBranch = "ruby_setup"
SkipPackageManager = false
Expand All @@ -46,7 +52,7 @@ def checkRunFolder(suggestedfolder)

PackagesToInstall = "bullet-devel boost gcc-c++ libXaw-devel freetype-devel " +
"freeimage-devel zziplib-devel boost-devel ois-devel tinyxml-devel " +
"glm-devel ffmpeg-devel ffmpeg-libs openal-soft-devel libatomic Cg"
"glm-devel ffmpeg-devel ffmpeg-libs openal-soft-devel libatomic"

elsif LinuxOS.casecmp("Ubuntu") == 0

Expand Down Expand Up @@ -124,12 +130,22 @@ def checkRunFolder(suggestedfolder)

Dir.chdir(File.join(CurrentDir, "thrive")) do

systemChecked "git checkout #{ThriveBranch}"
systemChecked "git pull --recurse-submodules origin #{ThriveBranch}"
system "git checkout #{ThriveBranch}"

if $?.exitstatus > 0

warning "Failed to checkout target thrive branch"

else

systemChecked "git pull --recurse-submodules origin #{ThriveBranch}"

end

systemChecked "git submodule update --recursive"

# submodule init check
if not File.exists? File.join(CurrentDir, "thrive", "contrib/luabind/luabind", "object.hpp")
if not File.exists? File.join(CurrentDir, "thrive", "contrib/lua/luajit/src", "lua.hpp")

warning "Submodules haven't been initialized, initializing now"

Expand Down Expand Up @@ -162,14 +178,34 @@ def checkRunFolder(suggestedfolder)
end

success "Assets are good to go"

info "Building luajit"

Dir.chdir(File.join(CurrentDir, "thrive", "contrib/lua/luajit/src")) do

# Make sure XCFLAGS+= -DLUAJIT_ENABLE_LUA52COMPAT is uncommented
outdata = File.read("Makefile").gsub(/#XCFLAGS\+= -DLUAJIT_ENABLE_LUA52COMPAT/,
"XCFLAGS+= -DLUAJIT_ENABLE_LUA52COMPAT")

File.open("Makefile", 'w') do |out|
out << outdata
end

runCompiler CompileThreads

onError "Failed to compile luajit" if $?.exitstatus > 0

end

success "luajit is ok"

FileUtils.mkdir_p "build"
FileUtils.mkdir_p "build/dist"
FileUtils.mkdir_p "build/dist/bin"

info "Making links"

# It seems that if the link is created when it already exists a llink is created into
# It seems that if the link is created when it already exists a link is created into
# the target folder for some reason
createLinkIfDoesntExist "assets/cegui_examples", "cegui_examples"
createLinkIfDoesntExist "assets/fonts", "fonts"
Expand Down Expand Up @@ -216,14 +252,6 @@ def checkRunFolder(suggestedfolder)

success "Done compiling thrive"

# Create a link from liblua.so to fix undefined symbol: _Z13luaL_newstatev
Dir.chdir(File.join(CurrentDir, "thrive", "build")) do

FileUtils.ln_sf "contrib/lua/liblua.so", "liblua.so"

end


info "run the game with '#{CurrentDir}/thrive/build/Thrive'"

success "Done"
Expand Down
86 changes: 0 additions & 86 deletions contrib/lua/CMakeLists.txt

This file was deleted.

6 changes: 6 additions & 0 deletions contrib/lua/building.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
LuaJIT has a really complex makefile so go into the luajit/src folder
and run make

Unfortunately there are some lua 5.2 features that need to be
explicitly enabled. So before running make uncomment this line in
`luajit/src/Makefile`: `#XCFLAGS+= -DLUAJIT_ENABLE_LUA52COMPAT`
6 changes: 0 additions & 6 deletions contrib/lua/lua/README

This file was deleted.

Loading

0 comments on commit 8055e85

Please sign in to comment.