├── .gitattributes ├── .gitignore ├── .travis.yml ├── CMakeLists.txt ├── LICENSE.md ├── README.md ├── TODO.txt ├── cmake └── Modules │ ├── FindBox2D.cmake │ ├── FindFMOD.cmake │ ├── FindSDL2.cmake │ └── Findglm.cmake ├── dep ├── CMakeLists.txt ├── glmx.h ├── imgui │ ├── CMakeLists.txt │ ├── imconfig.h │ ├── imgui.cpp │ ├── imgui.h │ ├── imgui_demo.cpp │ ├── imgui_draw.cpp │ ├── imgui_internal.h │ ├── imgui_user.inl │ ├── stb_rect_pack.h │ ├── stb_textedit.h │ └── stb_truetype.h ├── lua │ ├── CMakeLists.txt │ ├── Makefile │ ├── Makefile.mac │ ├── lapi.c │ ├── lapi.h │ ├── lauxlib.c │ ├── lauxlib.h │ ├── lbaselib.c │ ├── lbitlib.c │ ├── lcode.c │ ├── lcode.h │ ├── lcorolib.c │ ├── lctype.c │ ├── lctype.h │ ├── ldblib.c │ ├── ldebug.c │ ├── ldebug.h │ ├── ldo.c │ ├── ldo.h │ ├── ldump.c │ ├── lfunc.c │ ├── lfunc.h │ ├── lgc.c │ ├── lgc.h │ ├── liblua.a │ ├── linit.c │ ├── liolib.c │ ├── llex.c │ ├── llex.h │ ├── llimits.h │ ├── lmathlib.c │ ├── lmem.c │ ├── lmem.h │ ├── loadlib.c │ ├── lobject.c │ ├── lobject.h │ ├── lopcodes.c │ ├── lopcodes.h │ ├── loslib.c │ ├── lparser.c │ ├── lparser.h │ ├── lprefix.h │ ├── lstate.c │ ├── lstate.h │ ├── lstring.c │ ├── lstring.h │ ├── lstrlib.c │ ├── ltable.c │ ├── ltable.h │ ├── ltablib.c │ ├── ltm.c │ ├── ltm.h │ ├── lua.c │ ├── lua.h │ ├── lua.hpp │ ├── luac.c │ ├── luaconf.h │ ├── lualib.h │ ├── lundump.c │ ├── lundump.h │ ├── lutf8lib.c │ ├── lvm.c │ ├── lvm.h │ ├── lzio.c │ └── lzio.h ├── squish │ ├── CMakeLists.txt │ ├── README │ ├── alpha.cpp │ ├── alpha.h │ ├── clusterfit.cpp │ ├── clusterfit.h │ ├── colourblock.cpp │ ├── colourblock.h │ ├── colourfit.cpp │ ├── colourfit.h │ ├── colourset.cpp │ ├── colourset.h │ ├── config.h │ ├── maths.cpp │ ├── maths.h │ ├── rangefit.cpp │ ├── rangefit.h │ ├── simd.h │ ├── simd_float.h │ ├── simd_sse.h │ ├── simd_ve.h │ ├── singlecolourfit.cpp │ ├── singlecolourfit.h │ ├── singlecolourlookup.inl │ ├── squish.cpp │ ├── squish.h │ └── texture_compression_s3tc.txt ├── stb_image.h └── stb_image_write.h ├── engine ├── Arc.cpp ├── Arc.h ├── BezierInterpolation.cpp ├── BezierInterpolation.h ├── CMakeLists.txt ├── Color.cpp ├── Color.h ├── DebugDraw.cpp ├── DebugDraw.h ├── Engine.cpp ├── Engine.h ├── EngineContactListener.cpp ├── EngineContactListener.h ├── Engine_GL.cpp ├── Engine_Window.cpp ├── Gradient.cpp ├── Gradient.h ├── HeadTracker.cpp ├── HeadTracker.h ├── ImgFont.cpp ├── ImgFont.h ├── InputDevice.cpp ├── InputDevice.h ├── Interpolation.h ├── LinearInterpolation.cpp ├── LinearInterpolation.h ├── LuaDefines.h ├── LuaFuncs.h ├── LuaInterface.cpp ├── LuaInterface.h ├── Node.cpp ├── Node.h ├── ObjSegment.cpp ├── ObjSegment.h ├── Object.cpp ├── Object.h ├── Object3D.cpp ├── Object3D.h ├── OpenGLShader.cpp ├── OpenGLShader.h ├── ParticleSystem.cpp ├── ParticleSystem.h ├── PointQueryCallback.h ├── Quad.cpp ├── Quad.h ├── Random.cpp ├── Random.h ├── Rect.cpp ├── Rect.h ├── RenderState.cpp ├── RenderState.h ├── ResourceCache.cpp ├── ResourceCache.h ├── ResourceLoader.cpp ├── ResourceLoader.h ├── SoundVol.cpp ├── SoundVol.h ├── SystemUtils.cpp ├── SystemUtils.h ├── Text.cpp ├── Text.h ├── actions │ ├── Action.h │ ├── ActionBind.h │ ├── AxisAction.cpp │ ├── AxisAction.h │ ├── CombinedAction.cpp │ ├── CombinedAction.h │ ├── DpadMovement.cpp │ ├── DpadMovement.h │ ├── JoyButtonAction.cpp │ ├── JoyButtonAction.h │ ├── JoystickMovement.cpp │ ├── JoystickMovement.h │ ├── KeyboardAction.cpp │ ├── KeyboardAction.h │ ├── KeyboardMovement.cpp │ ├── KeyboardMovement.h │ ├── MouseButtonAction.cpp │ ├── MouseButtonAction.h │ ├── Movement.h │ ├── MovementBind.h │ ├── NoAction.h │ └── NoMovement.h ├── events │ ├── Observer.h │ ├── Subject.cpp │ └── Subject.h ├── imgui_impl_opengl3.cpp ├── imgui_impl_sdl.cpp ├── imgui_impl_sdl.h ├── managers │ ├── EntityManager.cpp │ ├── EntityManager.h │ ├── InputManager.cpp │ ├── InputManager.h │ ├── InterpolationManager.cpp │ ├── InterpolationManager.h │ ├── NodeManager.cpp │ ├── NodeManager.h │ ├── ObjectManager.cpp │ ├── ObjectManager.h │ ├── ParticleSystemManager.cpp │ ├── ParticleSystemManager.h │ ├── SceneryManager.cpp │ ├── SceneryManager.h │ ├── SoundManager.cpp │ ├── SoundManager.h │ ├── Stringbank.cpp │ └── Stringbank.h ├── mtrand.cpp ├── mtrand.h ├── opengl-api.cpp ├── opengl-api.h └── opengl-stubs.h ├── fixdylibs_mac.sh ├── game ├── CMakeLists.txt ├── DebugUI.cpp ├── DebugUI.h ├── GameEngine.cpp ├── GameEngine.h ├── GameEngine.rc ├── GameEngine_color.cpp ├── GameEngine_events.cpp ├── GameEngine_xmlparse.cpp ├── LevelEditor.cpp ├── LevelEditor.h ├── LuaFuncs.cpp ├── MemoryEditor.cpp ├── MemoryEditor.h ├── ParticleEditor.cpp ├── ParticleEditor.h ├── SteelSeriesEditor.cpp ├── SteelSeriesEditor.h └── main.cpp ├── io ├── CMakeLists.txt ├── FileOperations.cpp ├── FileOperations.h ├── Hash.cpp ├── Hash.h ├── Logger.cpp ├── Logger.h ├── PakLoader.cpp ├── PakLoader.h ├── ResourceTypes.h ├── StringUtils.cpp ├── StringUtils.h ├── rapidjson │ ├── allocators.h │ ├── document.h │ ├── encodedstream.h │ ├── encodings.h │ ├── error │ │ ├── en.h │ │ └── error.h │ ├── filereadstream.h │ ├── filewritestream.h │ ├── fwd.h │ ├── internal │ │ ├── biginteger.h │ │ ├── diyfp.h │ │ ├── dtoa.h │ │ ├── ieee754.h │ │ ├── itoa.h │ │ ├── meta.h │ │ ├── pow10.h │ │ ├── regex.h │ │ ├── stack.h │ │ ├── strfunc.h │ │ ├── strtod.h │ │ └── swap.h │ ├── istreamwrapper.h │ ├── memorybuffer.h │ ├── memorystream.h │ ├── msinttypes │ │ ├── inttypes.h │ │ └── stdint.h │ ├── ostreamwrapper.h │ ├── pointer.h │ ├── prettywriter.h │ ├── rapidjson.h │ ├── reader.h │ ├── schema.h │ ├── stream.h │ ├── stringbuffer.h │ └── writer.h ├── stb_image.h ├── stb_image_write.h ├── tinydir.h ├── tinyxml2.cpp ├── tinyxml2.h ├── wfLZ.c └── wfLZ.h ├── net ├── CMakeLists.txt ├── MutexLock.cpp ├── MutexLock.h ├── NetworkThread.cpp ├── NetworkThread.h ├── SteelSeriesClient.cpp ├── SteelSeriesClient.h ├── SteelSeriesEvents.h ├── SteelSeriesHaptic.cpp ├── SteelSeriesHaptic.h ├── ThreadsafeQueue.h ├── minihttp.cpp └── minihttp.h ├── res ├── lua │ ├── init.lua │ ├── math.lua │ ├── node │ │ ├── burgermakingcontroller.lua │ │ ├── gravwell.lua │ │ ├── heartbeat.lua │ │ ├── linearforcefield.lua │ │ ├── loadmap.lua │ │ ├── notereceiver.lua │ │ ├── radialforcefield.lua │ │ ├── tammousecontroller.lua │ │ ├── template.lua │ │ └── test.lua │ └── obj │ │ ├── bounce.lua │ │ ├── marble.lua │ │ ├── notereceiver.lua │ │ ├── soundband.lua │ │ ├── spaceship.lua │ │ ├── templateobj.lua │ │ └── testblob.lua └── shaders │ ├── debugdraw.frag │ ├── debugdraw.vert │ ├── default.frag │ └── default.vert └── tools ├── CMakeLists.txt └── compressor ├── CMakeLists.txt ├── LuaMinify ├── CommandLineMinify.lua ├── FormatMini.lua ├── LICENSE.md ├── ParseLua.lua ├── Scope.lua ├── Util.lua └── strict.lua ├── images.cpp ├── lua.cpp ├── main.cpp ├── main.h ├── mesh.cpp └── stb_rect_pack.h /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build/* 2 | 3 | *.d 4 | *.o 5 | *.res 6 | *.exe 7 | *.log 8 | _downloaded/* 9 | _gfxbase/* 10 | *.dll 11 | *.directory 12 | *.mp3 13 | *.flac 14 | *.ogg 15 | *.wav 16 | *.kate-swp 17 | *.blend 18 | *.blend1 19 | *.blend2 20 | gmon.out 21 | *.png 22 | *.jpg 23 | *.jpeg 24 | *.tif 25 | *.tiff 26 | *.obj 27 | *.tiny3d 28 | *.mtl 29 | *.font 30 | *.wflz 31 | *.ico 32 | *.pak 33 | Planet.cpp 34 | Planet.h 35 | res/**/*.xml 36 | res/**/*.txt 37 | res/json/* 38 | res/mus/* 39 | res/pak/* 40 | res/3d/* 41 | res/icons/* 42 | res/cursor/* 43 | dev/* 44 | workspace.np 45 | gamecontrollerdb.txt 46 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # http://docs.travis-ci.com/user/build-configuration/ 2 | language: cpp 3 | 4 | sudo: false 5 | 6 | compiler: 7 | - gcc 8 | - clang 9 | 10 | os: 11 | - linux 12 | 13 | addons: 14 | apt: 15 | packages: 16 | # - libbox2d-dev #This is backported on the travis-ci servers for some reason. We'll use our own 17 | - libglm-dev 18 | - libsdl2-dev 19 | 20 | before_install: 21 | - wget https://www.dropbox.com/s/61h7ziwo4fdk8xc/fmodstudioapi11002linux.tar.gz 22 | - tar -xzf fmodstudioapi11002linux.tar.gz 23 | - wget https://www.dropbox.com/s/vku4vicddawbwem/Box2D.tar.gz 24 | - tar -xzf Box2D.tar.gz 25 | 26 | script: 27 | - cd Box2D 28 | - mkdir cmake-build 29 | - cd cmake-build 30 | - cmake .. -DBOX2D_BUILD_EXAMPLES=OFF 31 | - make -j 2 32 | - cd ../.. 33 | - export CMAKE_PREFIX_PATH="$CMAKE_PREFIX_PATH;/usr/lib/x86_64-linux-gnu/" 34 | - CMAKE_OPTIONS='-DCMAKE_PREFIX_PATH='"$CMAKE_PREFIX_PATH"' -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBOX2D_LIBRARY='"../Box2D/cmake-build/Box2D/libBox2D.a"' -DBOX2D_INCLUDE_DIRS='"../Box2D/Box2D"' -DFMOD_INCLUDE_DIRS='"../fmodstudioapi11002linux/api/lowlevel/inc"' -DFMOD_INCLUDE_SEARCH_DIRS='"../fmodstudioapi11002linux/api/lowlevel/inc"' -DFMOD_LIBRARY='"../fmodstudioapi11002linux/api/lowlevel/lib/x86_64/libfmod.so"'' 35 | - rm -rf cmake-build 36 | - mkdir cmake-build 37 | - cd cmake-build 38 | - cmake $CMAKE_OPTIONS .. 39 | - make -j 2 40 | 41 | notifications: 42 | email: false 43 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.6) 2 | project(retsphinx) 3 | 4 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/") 5 | 6 | set(PROJ_ROOT "${CMAKE_CURRENT_SOURCE_DIR}") 7 | 8 | # HACK: Apparently not set automatically either 9 | set(BOX2D_INCLUDE_DIRS CACHE PATH "") 10 | find_package(Box2D REQUIRED) 11 | find_package(glm REQUIRED) 12 | find_package(SDL2 REQUIRED) 13 | find_package(FMOD REQUIRED) 14 | 15 | if(MSVC) 16 | add_definitions(-D_CRT_SECURE_NO_DEPRECATE) 17 | add_definitions(-D_CRT_SECURE_NO_WARNINGS) 18 | endif() 19 | 20 | # HACK: Apparently not set automatically? 21 | set(glm_INCLUDE_DIRS "${glm_DIR}/../" CACHE STRING "Path to glm includes") 22 | 23 | include_directories(dep) 24 | add_subdirectory(dep) 25 | 26 | include_directories("${CMAKE_CURRENT_SOURCE_DIR}") 27 | 28 | include_directories(io) 29 | add_subdirectory(io) 30 | 31 | include_directories("${glm_INCLUDE_DIRS}") 32 | include_directories("${BOX2D_INCLUDE_DIRS}/..") 33 | include_directories("${SDL2_INCLUDE_DIR}") 34 | include_directories("${FMOD_INCLUDE_DIRS}") 35 | include_directories(dep/lua) 36 | include_directories(dep/imgui) 37 | 38 | add_subdirectory(net) 39 | 40 | include_directories(net) 41 | add_subdirectory(engine) 42 | 43 | include_directories(engine) 44 | include_directories(engine/events) 45 | include_directories(engine/managers) 46 | include_directories(engine/actions) 47 | add_subdirectory(game) 48 | 49 | include_directories(dep/squish) 50 | add_subdirectory(tools) 51 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014 Mark Hutcheson 2 | 3 | This software is provided 'as-is', without any express or implied 4 | warranty. In no event will the authors be held liable for any damages 5 | arising from the use of this software. 6 | 7 | Permission is granted to anyone to use this software for any purpose, 8 | including commercial applications, and to alter it and redistribute it 9 | freely, subject to the following restrictions: 10 | 11 | 1. The origin of this software must not be misrepresented; you must not 12 | claim that you wrote the original software. If you use this software 13 | in a product, an acknowledgment in the product documentation would be 14 | appreciated but is not required. 15 | 16 | 2. Altered source versions must be plainly marked as such, and must not be 17 | misrepresented as being the original software. 18 | 19 | 3. This notice may not be removed or altered from any source 20 | distribution. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://travis-ci.org/meh2481/RetSphinxEngine.svg?branch=develop)](https://travis-ci.org/meh2481/RetSphinxEngine) 2 | 3 | GameEngine 4 | ============== 5 | 6 | (Working title) 7 | 8 | I was inspired by Itay Keren's work on Mushroom 11, particularly with vertex mapped bodies for simplified soft body physics here http://itaykeren.tumblr.com/post/64889060446/vertex-mapped-bodies . This is an attempt to get my engine up to snuff so I can do cool stuff like this. 9 | -------------------------------------------------------------------------------- /cmake/Modules/FindBox2D.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find Box2D 2 | # Once done this will define 3 | # BOX2D_FOUND - System has Box2D 4 | # BOX2D_INCLUDE_DIRS - The Box2D include directories 5 | # BOX2D_LIBRARIES - The libraries needed to use Box2D 6 | # BOX2D_DEFINITIONS - Compiler switches required for using Box2D 7 | 8 | find_package(PkgConfig) 9 | pkg_check_modules(PC_BOX2D QUIET Box2D) 10 | set(BOX2D_INCLUDE_DIRS ${PC_BOX2D_INCLUDE_DIRS}) 11 | set(BOX2D_DEFINITIONS ${PC_BOX2D_CFLAGS_OTHER}) 12 | 13 | find_library(BOX2D_LIBRARY NAMES Box2D 14 | HINTS ${PC_BOX2D_LIBDIR} ${PC_BOX2D_LIBRARY_DIRS}) 15 | set(BOX2D_LIBRARIES ${BOX2D_LIBRARY}) 16 | 17 | include(FindPackageHandleStandardArgs) 18 | find_package_handle_standard_args(Box2D DEFAULT_MSG BOX2D_LIBRARY BOX2D_INCLUDE_DIRS) 19 | 20 | mark_as_advanced(BOX2D_INCLUDE_DIRS BOX2D_LIBRARY) 21 | -------------------------------------------------------------------------------- /cmake/Modules/Findglm.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Find GLM 3 | # 4 | # Try to find GLM : OpenGL Mathematics. 5 | # This module defines 6 | # - GLM_INCLUDE_DIRS 7 | # - GLM_FOUND 8 | # 9 | # The following variables can be set as arguments for the module. 10 | # - GLM_ROOT_DIR : Root library directory of GLM 11 | # 12 | # References: 13 | # - https://github.com/Groovounet/glm/blob/master/util/FindGLM.cmake 14 | # - https://bitbucket.org/alfonse/gltut/src/28636298c1c0/glm-0.9.0.7/FindGLM.cmake 15 | # 16 | 17 | # Additional modules 18 | include(FindPackageHandleStandardArgs) 19 | 20 | if (WIN32) 21 | # Find include files 22 | find_path( 23 | GLM_INCLUDE_DIR 24 | NAMES glm/glm.hpp 25 | PATHS 26 | $ENV{PROGRAMFILES}/include 27 | ${GLM_ROOT_DIR}/include 28 | DOC "The directory where glm/glm.hpp resides") 29 | else() 30 | # Find include files 31 | find_path( 32 | GLM_INCLUDE_DIR 33 | NAMES glm/glm.hpp 34 | PATHS 35 | /usr/include 36 | /usr/local/include 37 | /sw/include 38 | /opt/local/include 39 | ${GLM_ROOT_DIR}/include 40 | DOC "The directory where glm/glm.hpp resides") 41 | endif() 42 | 43 | # Handle REQUIRD argument, define *_FOUND variable 44 | find_package_handle_standard_args(GLM DEFAULT_MSG GLM_INCLUDE_DIR) 45 | 46 | # Define GLM_INCLUDE_DIRS 47 | if (GLM_FOUND) 48 | set(GLM_INCLUDE_DIRS ${GLM_INCLUDE_DIR}) 49 | endif() 50 | 51 | # Hide some variables 52 | mark_as_advanced(GLM_INCLUDE_DIR) 53 | -------------------------------------------------------------------------------- /dep/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(lua) 2 | add_subdirectory(imgui) 3 | add_subdirectory(squish) 4 | -------------------------------------------------------------------------------- /dep/glmx.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define GLM_META_PROG_HELPERS 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | namespace glmx { 10 | 11 | inline glm::vec3 orthogonalize(const glm::vec3 ref, const glm::vec3 toOrtho, glm::vec3 *third) 12 | { 13 | *third = glm::normalize(glm::cross(ref, toOrtho)); 14 | return glm::cross(*third, ref); 15 | } 16 | 17 | template 18 | inline T to(const T self, const T other) 19 | { 20 | return other - self; 21 | } 22 | 23 | template 24 | inline float lensqr(const T v) 25 | { 26 | return glm::dot(v, v); 27 | } 28 | 29 | 30 | 31 | } // end namespace glmx 32 | 33 | -------------------------------------------------------------------------------- /dep/imgui/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # for automatic ImVec<->glm::vec conversion 2 | include_directories("${glm_INCLUDE_DIRS}") 3 | 4 | 5 | set(imgui_src 6 | imconfig.h 7 | imgui.cpp 8 | imgui.h 9 | imgui_demo.cpp 10 | imgui_draw.cpp 11 | imgui_internal.h 12 | stb_rect_pack.h 13 | stb_textedit.h 14 | stb_truetype.h 15 | imgui_user.inl 16 | ) 17 | 18 | 19 | add_library(imgui ${imgui_src}) 20 | #target_link_libraries(imgui) 21 | 22 | -------------------------------------------------------------------------------- /dep/lua/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(lua_src 2 | lapi.c 3 | lapi.h 4 | lauxlib.c 5 | lauxlib.h 6 | lbaselib.c 7 | lbitlib.c 8 | lcode.c 9 | lcode.h 10 | lcorolib.c 11 | lctype.c 12 | lctype.h 13 | ldblib.c 14 | ldebug.c 15 | ldebug.h 16 | ldo.c 17 | ldo.h 18 | ldump.c 19 | lfunc.c 20 | lfunc.h 21 | lgc.c 22 | lgc.h 23 | linit.c 24 | liolib.c 25 | llex.c 26 | llex.h 27 | llimits.h 28 | lmathlib.c 29 | lmem.c 30 | lmem.h 31 | loadlib.c 32 | lobject.c 33 | lobject.h 34 | lopcodes.c 35 | lopcodes.h 36 | loslib.c 37 | lparser.c 38 | lparser.h 39 | lprefix.h 40 | lstate.c 41 | lstate.h 42 | lstring.c 43 | lstring.h 44 | lstrlib.c 45 | ltable.c 46 | ltable.h 47 | ltablib.c 48 | ltm.c 49 | ltm.h 50 | lua.h 51 | luaconf.h 52 | lualib.h 53 | lundump.c 54 | lundump.h 55 | lutf8lib.c 56 | lvm.c 57 | lvm.h 58 | lzio.c 59 | lzio.h 60 | ) 61 | 62 | add_library(lua53 ${lua_src}) 63 | -------------------------------------------------------------------------------- /dep/lua/Makefile: -------------------------------------------------------------------------------- 1 | # Simple makefile for building lua as static lib 2 | OBJECTS = $(shell ls -1 *.c | sed 's/\.c/\.o/') 3 | TARGET = liblua.a 4 | CFLAGS = 5 | CC = gcc 6 | 7 | all: $(TARGET) 8 | 9 | %.o: %.c 10 | $(CC) -g -c -o $@ $< $(CFLAGS) 11 | 12 | clean: clean-obj clean-lib 13 | 14 | clean-obj: 15 | rm -rf *.o 16 | 17 | clean-lib: 18 | rm -rf $(TARGET) 19 | 20 | $(TARGET): $(OBJECTS) 21 | ar rcs $(TARGET) $(OBJECTS) -------------------------------------------------------------------------------- /dep/lua/Makefile.mac: -------------------------------------------------------------------------------- 1 | # Simple makefile for building lua as static lib 2 | OBJECTS = $(shell ls -1 *.c | sed 's/\.c/\.o/') 3 | TARGET = liblua.a 4 | CFLAGS = -arch i386 -arch x86_64 -arch ppc 5 | CC = cc 6 | 7 | all: $(TARGET) 8 | 9 | %.o: %.c 10 | $(CC) -g -c -o $@ $< $(CFLAGS) 11 | 12 | clean: clean-obj clean-lib 13 | 14 | clean-obj: 15 | rm -rf *.o 16 | 17 | clean-lib: 18 | rm -rf $(TARGET) 19 | 20 | $(TARGET): $(OBJECTS) 21 | ar rcs $(TARGET) $(OBJECTS) -------------------------------------------------------------------------------- /dep/lua/lapi.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lapi.h,v 2.9 2015/03/06 19:49:50 roberto Exp $ 3 | ** Auxiliary functions from Lua API 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lapi_h 8 | #define lapi_h 9 | 10 | 11 | #include "llimits.h" 12 | #include "lstate.h" 13 | 14 | #define api_incr_top(L) {L->top++; api_check(L, L->top <= L->ci->top, \ 15 | "stack overflow");} 16 | 17 | #define adjustresults(L,nres) \ 18 | { if ((nres) == LUA_MULTRET && L->ci->top < L->top) L->ci->top = L->top; } 19 | 20 | #define api_checknelems(L,n) api_check(L, (n) < (L->top - L->ci->func), \ 21 | "not enough elements in the stack") 22 | 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /dep/lua/lctype.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lctype.c,v 1.12 2014/11/02 19:19:04 roberto Exp $ 3 | ** 'ctype' functions for Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lctype_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include "lctype.h" 14 | 15 | #if !LUA_USE_CTYPE /* { */ 16 | 17 | #include 18 | 19 | LUAI_DDEF const lu_byte luai_ctype_[UCHAR_MAX + 2] = { 20 | 0x00, /* EOZ */ 21 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0. */ 22 | 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 23 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 1. */ 24 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 25 | 0x0c, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, /* 2. */ 26 | 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 27 | 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, /* 3. */ 28 | 0x16, 0x16, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 29 | 0x04, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x05, /* 4. */ 30 | 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 31 | 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, /* 5. */ 32 | 0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x05, 33 | 0x04, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x05, /* 6. */ 34 | 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 35 | 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, /* 7. */ 36 | 0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x00, 37 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 8. */ 38 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 39 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 9. */ 40 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 41 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* a. */ 42 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 43 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* b. */ 44 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 45 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* c. */ 46 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 47 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* d. */ 48 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 49 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* e. */ 50 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 51 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* f. */ 52 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 53 | }; 54 | 55 | #endif /* } */ 56 | -------------------------------------------------------------------------------- /dep/lua/lctype.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lctype.h,v 1.12 2011/07/15 12:50:29 roberto Exp $ 3 | ** 'ctype' functions for Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lctype_h 8 | #define lctype_h 9 | 10 | #include "lua.h" 11 | 12 | 13 | /* 14 | ** WARNING: the functions defined here do not necessarily correspond 15 | ** to the similar functions in the standard C ctype.h. They are 16 | ** optimized for the specific needs of Lua 17 | */ 18 | 19 | #if !defined(LUA_USE_CTYPE) 20 | 21 | #if 'A' == 65 && '0' == 48 22 | /* ASCII case: can use its own tables; faster and fixed */ 23 | #define LUA_USE_CTYPE 0 24 | #else 25 | /* must use standard C ctype */ 26 | #define LUA_USE_CTYPE 1 27 | #endif 28 | 29 | #endif 30 | 31 | 32 | #if !LUA_USE_CTYPE /* { */ 33 | 34 | #include 35 | 36 | #include "llimits.h" 37 | 38 | 39 | #define ALPHABIT 0 40 | #define DIGITBIT 1 41 | #define PRINTBIT 2 42 | #define SPACEBIT 3 43 | #define XDIGITBIT 4 44 | 45 | 46 | #define MASK(B) (1 << (B)) 47 | 48 | 49 | /* 50 | ** add 1 to char to allow index -1 (EOZ) 51 | */ 52 | #define testprop(c,p) (luai_ctype_[(c)+1] & (p)) 53 | 54 | /* 55 | ** 'lalpha' (Lua alphabetic) and 'lalnum' (Lua alphanumeric) both include '_' 56 | */ 57 | #define lislalpha(c) testprop(c, MASK(ALPHABIT)) 58 | #define lislalnum(c) testprop(c, (MASK(ALPHABIT) | MASK(DIGITBIT))) 59 | #define lisdigit(c) testprop(c, MASK(DIGITBIT)) 60 | #define lisspace(c) testprop(c, MASK(SPACEBIT)) 61 | #define lisprint(c) testprop(c, MASK(PRINTBIT)) 62 | #define lisxdigit(c) testprop(c, MASK(XDIGITBIT)) 63 | 64 | /* 65 | ** this 'ltolower' only works for alphabetic characters 66 | */ 67 | #define ltolower(c) ((c) | ('A' ^ 'a')) 68 | 69 | 70 | /* two more entries for 0 and -1 (EOZ) */ 71 | LUAI_DDEC const lu_byte luai_ctype_[UCHAR_MAX + 2]; 72 | 73 | 74 | #else /* }{ */ 75 | 76 | /* 77 | ** use standard C ctypes 78 | */ 79 | 80 | #include 81 | 82 | 83 | #define lislalpha(c) (isalpha(c) || (c) == '_') 84 | #define lislalnum(c) (isalnum(c) || (c) == '_') 85 | #define lisdigit(c) (isdigit(c)) 86 | #define lisspace(c) (isspace(c)) 87 | #define lisprint(c) (isprint(c)) 88 | #define lisxdigit(c) (isxdigit(c)) 89 | 90 | #define ltolower(c) (tolower(c)) 91 | 92 | #endif /* } */ 93 | 94 | #endif 95 | 96 | -------------------------------------------------------------------------------- /dep/lua/ldebug.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldebug.h,v 2.14 2015/05/22 17:45:56 roberto Exp $ 3 | ** Auxiliary functions from Debug Interface module 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ldebug_h 8 | #define ldebug_h 9 | 10 | 11 | #include "lstate.h" 12 | 13 | 14 | #define pcRel(pc, p) (cast(int, (pc) - (p)->code) - 1) 15 | 16 | #define getfuncline(f,pc) (((f)->lineinfo) ? (f)->lineinfo[pc] : -1) 17 | 18 | #define resethookcount(L) (L->hookcount = L->basehookcount) 19 | 20 | 21 | LUAI_FUNC l_noret luaG_typeerror (lua_State *L, const TValue *o, 22 | const char *opname); 23 | LUAI_FUNC l_noret luaG_concaterror (lua_State *L, const TValue *p1, 24 | const TValue *p2); 25 | LUAI_FUNC l_noret luaG_opinterror (lua_State *L, const TValue *p1, 26 | const TValue *p2, 27 | const char *msg); 28 | LUAI_FUNC l_noret luaG_tointerror (lua_State *L, const TValue *p1, 29 | const TValue *p2); 30 | LUAI_FUNC l_noret luaG_ordererror (lua_State *L, const TValue *p1, 31 | const TValue *p2); 32 | LUAI_FUNC l_noret luaG_runerror (lua_State *L, const char *fmt, ...); 33 | LUAI_FUNC const char *luaG_addinfo (lua_State *L, const char *msg, 34 | TString *src, int line); 35 | LUAI_FUNC l_noret luaG_errormsg (lua_State *L); 36 | LUAI_FUNC void luaG_traceexec (lua_State *L); 37 | 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /dep/lua/ldo.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldo.h,v 2.28 2015/11/23 11:29:43 roberto Exp $ 3 | ** Stack and Call structure of Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ldo_h 8 | #define ldo_h 9 | 10 | 11 | #include "lobject.h" 12 | #include "lstate.h" 13 | #include "lzio.h" 14 | 15 | 16 | /* 17 | ** Macro to check stack size and grow stack if needed. Parameters 18 | ** 'pre'/'pos' allow the macro to preserve a pointer into the 19 | ** stack across reallocations, doing the work only when needed. 20 | ** 'condmovestack' is used in heavy tests to force a stack reallocation 21 | ** at every check. 22 | */ 23 | #define luaD_checkstackaux(L,n,pre,pos) \ 24 | if (L->stack_last - L->top <= (n)) \ 25 | { pre; luaD_growstack(L, n); pos; } else { condmovestack(L,pre,pos); } 26 | 27 | /* In general, 'pre'/'pos' are empty (nothing to save) */ 28 | #define luaD_checkstack(L,n) luaD_checkstackaux(L,n,,) 29 | 30 | 31 | 32 | #define savestack(L,p) ((char *)(p) - (char *)L->stack) 33 | #define restorestack(L,n) ((TValue *)((char *)L->stack + (n))) 34 | 35 | 36 | /* type of protected functions, to be ran by 'runprotected' */ 37 | typedef void (*Pfunc) (lua_State *L, void *ud); 38 | 39 | LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name, 40 | const char *mode); 41 | LUAI_FUNC void luaD_hook (lua_State *L, int event, int line); 42 | LUAI_FUNC int luaD_precall (lua_State *L, StkId func, int nresults); 43 | LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults); 44 | LUAI_FUNC void luaD_callnoyield (lua_State *L, StkId func, int nResults); 45 | LUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u, 46 | ptrdiff_t oldtop, ptrdiff_t ef); 47 | LUAI_FUNC int luaD_poscall (lua_State *L, CallInfo *ci, StkId firstResult, 48 | int nres); 49 | LUAI_FUNC void luaD_reallocstack (lua_State *L, int newsize); 50 | LUAI_FUNC void luaD_growstack (lua_State *L, int n); 51 | LUAI_FUNC void luaD_shrinkstack (lua_State *L); 52 | LUAI_FUNC void luaD_inctop (lua_State *L); 53 | 54 | LUAI_FUNC l_noret luaD_throw (lua_State *L, int errcode); 55 | LUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud); 56 | 57 | #endif 58 | 59 | -------------------------------------------------------------------------------- /dep/lua/lfunc.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lfunc.h,v 2.15 2015/01/13 15:49:11 roberto Exp $ 3 | ** Auxiliary functions to manipulate prototypes and closures 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lfunc_h 8 | #define lfunc_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | #define sizeCclosure(n) (cast(int, sizeof(CClosure)) + \ 15 | cast(int, sizeof(TValue)*((n)-1))) 16 | 17 | #define sizeLclosure(n) (cast(int, sizeof(LClosure)) + \ 18 | cast(int, sizeof(TValue *)*((n)-1))) 19 | 20 | 21 | /* test whether thread is in 'twups' list */ 22 | #define isintwups(L) (L->twups != L) 23 | 24 | 25 | /* 26 | ** maximum number of upvalues in a closure (both C and Lua). (Value 27 | ** must fit in a VM register.) 28 | */ 29 | #define MAXUPVAL 255 30 | 31 | 32 | /* 33 | ** Upvalues for Lua closures 34 | */ 35 | struct UpVal { 36 | TValue *v; /* points to stack or to its own value */ 37 | lu_mem refcount; /* reference counter */ 38 | union { 39 | struct { /* (when open) */ 40 | UpVal *next; /* linked list */ 41 | int touched; /* mark to avoid cycles with dead threads */ 42 | } open; 43 | TValue value; /* the value (when closed) */ 44 | } u; 45 | }; 46 | 47 | #define upisopen(up) ((up)->v != &(up)->u.value) 48 | 49 | 50 | LUAI_FUNC Proto *luaF_newproto (lua_State *L); 51 | LUAI_FUNC CClosure *luaF_newCclosure (lua_State *L, int nelems); 52 | LUAI_FUNC LClosure *luaF_newLclosure (lua_State *L, int nelems); 53 | LUAI_FUNC void luaF_initupvals (lua_State *L, LClosure *cl); 54 | LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level); 55 | LUAI_FUNC void luaF_close (lua_State *L, StkId level); 56 | LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f); 57 | LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number, 58 | int pc); 59 | 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /dep/lua/liblua.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/meh2481/RetSphinxEngine/cbf61bcb6d7affd5831f975263d98c79c8e8ce79/dep/lua/liblua.a -------------------------------------------------------------------------------- /dep/lua/linit.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: linit.c,v 1.38 2015/01/05 13:48:33 roberto Exp $ 3 | ** Initialization of libraries for lua.c and other clients 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #define linit_c 9 | #define LUA_LIB 10 | 11 | /* 12 | ** If you embed Lua in your program and need to open the standard 13 | ** libraries, call luaL_openlibs in your program. If you need a 14 | ** different set of libraries, copy this file to your project and edit 15 | ** it to suit your needs. 16 | ** 17 | ** You can also *preload* libraries, so that a later 'require' can 18 | ** open the library, which is already linked to the application. 19 | ** For that, do the following code: 20 | ** 21 | ** luaL_getsubtable(L, LUA_REGISTRYINDEX, "_PRELOAD"); 22 | ** lua_pushcfunction(L, luaopen_modname); 23 | ** lua_setfield(L, -2, modname); 24 | ** lua_pop(L, 1); // remove _PRELOAD table 25 | */ 26 | 27 | #include "lprefix.h" 28 | 29 | 30 | #include 31 | 32 | #include "lua.h" 33 | 34 | #include "lualib.h" 35 | #include "lauxlib.h" 36 | 37 | 38 | /* 39 | ** these libs are loaded by lua.c and are readily available to any Lua 40 | ** program 41 | */ 42 | static const luaL_Reg loadedlibs[] = { 43 | {"_G", luaopen_base}, 44 | {LUA_LOADLIBNAME, luaopen_package}, 45 | {LUA_COLIBNAME, luaopen_coroutine}, 46 | {LUA_TABLIBNAME, luaopen_table}, 47 | {LUA_IOLIBNAME, luaopen_io}, 48 | {LUA_OSLIBNAME, luaopen_os}, 49 | {LUA_STRLIBNAME, luaopen_string}, 50 | {LUA_MATHLIBNAME, luaopen_math}, 51 | {LUA_UTF8LIBNAME, luaopen_utf8}, 52 | {LUA_DBLIBNAME, luaopen_debug}, 53 | #if defined(LUA_COMPAT_BITLIB) 54 | {LUA_BITLIBNAME, luaopen_bit32}, 55 | #endif 56 | {NULL, NULL} 57 | }; 58 | 59 | 60 | LUALIB_API void luaL_openlibs (lua_State *L) { 61 | const luaL_Reg *lib; 62 | /* "require" functions from 'loadedlibs' and set results to global table */ 63 | for (lib = loadedlibs; lib->func; lib++) { 64 | luaL_requiref(L, lib->name, lib->func, 1); 65 | lua_pop(L, 1); /* remove lib */ 66 | } 67 | } 68 | 69 | -------------------------------------------------------------------------------- /dep/lua/llex.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: llex.h,v 1.78 2014/10/29 15:38:24 roberto Exp $ 3 | ** Lexical Analyzer 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef llex_h 8 | #define llex_h 9 | 10 | #include "lobject.h" 11 | #include "lzio.h" 12 | 13 | 14 | #define FIRST_RESERVED 257 15 | 16 | 17 | #if !defined(LUA_ENV) 18 | #define LUA_ENV "_ENV" 19 | #endif 20 | 21 | 22 | /* 23 | * WARNING: if you change the order of this enumeration, 24 | * grep "ORDER RESERVED" 25 | */ 26 | enum RESERVED { 27 | /* terminal symbols denoted by reserved words */ 28 | TK_AND = FIRST_RESERVED, TK_BREAK, 29 | TK_DO, TK_ELSE, TK_ELSEIF, TK_END, TK_FALSE, TK_FOR, TK_FUNCTION, 30 | TK_GOTO, TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT, 31 | TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE, 32 | /* other terminal symbols */ 33 | TK_IDIV, TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, 34 | TK_SHL, TK_SHR, 35 | TK_DBCOLON, TK_EOS, 36 | TK_FLT, TK_INT, TK_NAME, TK_STRING 37 | }; 38 | 39 | /* number of reserved words */ 40 | #define NUM_RESERVED (cast(int, TK_WHILE-FIRST_RESERVED+1)) 41 | 42 | 43 | typedef union { 44 | lua_Number r; 45 | lua_Integer i; 46 | TString *ts; 47 | } SemInfo; /* semantics information */ 48 | 49 | 50 | typedef struct Token { 51 | int token; 52 | SemInfo seminfo; 53 | } Token; 54 | 55 | 56 | /* state of the lexer plus state of the parser when shared by all 57 | functions */ 58 | typedef struct LexState { 59 | int current; /* current character (charint) */ 60 | int linenumber; /* input line counter */ 61 | int lastline; /* line of last token 'consumed' */ 62 | Token t; /* current token */ 63 | Token lookahead; /* look ahead token */ 64 | struct FuncState *fs; /* current function (parser) */ 65 | struct lua_State *L; 66 | ZIO *z; /* input stream */ 67 | Mbuffer *buff; /* buffer for tokens */ 68 | Table *h; /* to avoid collection/reuse strings */ 69 | struct Dyndata *dyd; /* dynamic structures used by the parser */ 70 | TString *source; /* current source name */ 71 | TString *envn; /* environment variable name */ 72 | char decpoint; /* locale decimal point */ 73 | } LexState; 74 | 75 | 76 | LUAI_FUNC void luaX_init (lua_State *L); 77 | LUAI_FUNC void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, 78 | TString *source, int firstchar); 79 | LUAI_FUNC TString *luaX_newstring (LexState *ls, const char *str, size_t l); 80 | LUAI_FUNC void luaX_next (LexState *ls); 81 | LUAI_FUNC int luaX_lookahead (LexState *ls); 82 | LUAI_FUNC l_noret luaX_syntaxerror (LexState *ls, const char *s); 83 | LUAI_FUNC const char *luaX_token2str (LexState *ls, int token); 84 | 85 | 86 | #endif 87 | -------------------------------------------------------------------------------- /dep/lua/lmem.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lmem.h,v 1.43 2014/12/19 17:26:14 roberto Exp $ 3 | ** Interface to Memory Manager 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lmem_h 8 | #define lmem_h 9 | 10 | 11 | #include 12 | 13 | #include "llimits.h" 14 | #include "lua.h" 15 | 16 | 17 | /* 18 | ** This macro reallocs a vector 'b' from 'on' to 'n' elements, where 19 | ** each element has size 'e'. In case of arithmetic overflow of the 20 | ** product 'n'*'e', it raises an error (calling 'luaM_toobig'). Because 21 | ** 'e' is always constant, it avoids the runtime division MAX_SIZET/(e). 22 | ** 23 | ** (The macro is somewhat complex to avoid warnings: The 'sizeof' 24 | ** comparison avoids a runtime comparison when overflow cannot occur. 25 | ** The compiler should be able to optimize the real test by itself, but 26 | ** when it does it, it may give a warning about "comparison is always 27 | ** false due to limited range of data type"; the +1 tricks the compiler, 28 | ** avoiding this warning but also this optimization.) 29 | */ 30 | #define luaM_reallocv(L,b,on,n,e) \ 31 | (((sizeof(n) >= sizeof(size_t) && cast(size_t, (n)) + 1 > MAX_SIZET/(e)) \ 32 | ? luaM_toobig(L) : cast_void(0)) , \ 33 | luaM_realloc_(L, (b), (on)*(e), (n)*(e))) 34 | 35 | /* 36 | ** Arrays of chars do not need any test 37 | */ 38 | #define luaM_reallocvchar(L,b,on,n) \ 39 | cast(char *, luaM_realloc_(L, (b), (on)*sizeof(char), (n)*sizeof(char))) 40 | 41 | #define luaM_freemem(L, b, s) luaM_realloc_(L, (b), (s), 0) 42 | #define luaM_free(L, b) luaM_realloc_(L, (b), sizeof(*(b)), 0) 43 | #define luaM_freearray(L, b, n) luaM_realloc_(L, (b), (n)*sizeof(*(b)), 0) 44 | 45 | #define luaM_malloc(L,s) luaM_realloc_(L, NULL, 0, (s)) 46 | #define luaM_new(L,t) cast(t *, luaM_malloc(L, sizeof(t))) 47 | #define luaM_newvector(L,n,t) \ 48 | cast(t *, luaM_reallocv(L, NULL, 0, n, sizeof(t))) 49 | 50 | #define luaM_newobject(L,tag,s) luaM_realloc_(L, NULL, tag, (s)) 51 | 52 | #define luaM_growvector(L,v,nelems,size,t,limit,e) \ 53 | if ((nelems)+1 > (size)) \ 54 | ((v)=cast(t *, luaM_growaux_(L,v,&(size),sizeof(t),limit,e))) 55 | 56 | #define luaM_reallocvector(L, v,oldn,n,t) \ 57 | ((v)=cast(t *, luaM_reallocv(L, v, oldn, n, sizeof(t)))) 58 | 59 | LUAI_FUNC l_noret luaM_toobig (lua_State *L); 60 | 61 | /* not to be called directly */ 62 | LUAI_FUNC void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize, 63 | size_t size); 64 | LUAI_FUNC void *luaM_growaux_ (lua_State *L, void *block, int *size, 65 | size_t size_elem, int limit, 66 | const char *what); 67 | 68 | #endif 69 | 70 | -------------------------------------------------------------------------------- /dep/lua/lprefix.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lprefix.h,v 1.2 2014/12/29 16:54:13 roberto Exp $ 3 | ** Definitions for Lua code that must come before any other header file 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lprefix_h 8 | #define lprefix_h 9 | 10 | 11 | /* 12 | ** Allows POSIX/XSI stuff 13 | */ 14 | #if !defined(LUA_USE_C89) /* { */ 15 | 16 | #if !defined(_XOPEN_SOURCE) 17 | #define _XOPEN_SOURCE 600 18 | #elif _XOPEN_SOURCE == 0 19 | #undef _XOPEN_SOURCE /* use -D_XOPEN_SOURCE=0 to undefine it */ 20 | #endif 21 | 22 | /* 23 | ** Allows manipulation of large files in gcc and some other compilers 24 | */ 25 | #if !defined(LUA_32BITS) && !defined(_FILE_OFFSET_BITS) 26 | #define _LARGEFILE_SOURCE 1 27 | #define _FILE_OFFSET_BITS 64 28 | #endif 29 | 30 | #endif /* } */ 31 | 32 | 33 | /* 34 | ** Windows stuff 35 | */ 36 | #if defined(_WIN32) /* { */ 37 | 38 | #if !defined(_CRT_SECURE_NO_WARNINGS) 39 | #define _CRT_SECURE_NO_WARNINGS /* avoid warnings about ISO C functions */ 40 | #endif 41 | 42 | #endif /* } */ 43 | 44 | #endif 45 | 46 | -------------------------------------------------------------------------------- /dep/lua/lstring.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lstring.h,v 1.61 2015/11/03 15:36:01 roberto Exp $ 3 | ** String table (keep all strings handled by Lua) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lstring_h 8 | #define lstring_h 9 | 10 | #include "lgc.h" 11 | #include "lobject.h" 12 | #include "lstate.h" 13 | 14 | 15 | #define sizelstring(l) (sizeof(union UTString) + ((l) + 1) * sizeof(char)) 16 | 17 | #define sizeludata(l) (sizeof(union UUdata) + (l)) 18 | #define sizeudata(u) sizeludata((u)->len) 19 | 20 | #define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \ 21 | (sizeof(s)/sizeof(char))-1)) 22 | 23 | 24 | /* 25 | ** test whether a string is a reserved word 26 | */ 27 | #define isreserved(s) ((s)->tt == LUA_TSHRSTR && (s)->extra > 0) 28 | 29 | 30 | /* 31 | ** equality for short strings, which are always internalized 32 | */ 33 | #define eqshrstr(a,b) check_exp((a)->tt == LUA_TSHRSTR, (a) == (b)) 34 | 35 | 36 | LUAI_FUNC unsigned int luaS_hash (const char *str, size_t l, unsigned int seed); 37 | LUAI_FUNC unsigned int luaS_hashlongstr (TString *ts); 38 | LUAI_FUNC int luaS_eqlngstr (TString *a, TString *b); 39 | LUAI_FUNC void luaS_resize (lua_State *L, int newsize); 40 | LUAI_FUNC void luaS_clearcache (global_State *g); 41 | LUAI_FUNC void luaS_init (lua_State *L); 42 | LUAI_FUNC void luaS_remove (lua_State *L, TString *ts); 43 | LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s); 44 | LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l); 45 | LUAI_FUNC TString *luaS_new (lua_State *L, const char *str); 46 | LUAI_FUNC TString *luaS_createlngstrobj (lua_State *L, size_t l); 47 | 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /dep/lua/ltable.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltable.h,v 2.21 2015/11/03 15:47:30 roberto Exp $ 3 | ** Lua tables (hash) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ltable_h 8 | #define ltable_h 9 | 10 | #include "lobject.h" 11 | 12 | 13 | #define gnode(t,i) (&(t)->node[i]) 14 | #define gval(n) (&(n)->i_val) 15 | #define gnext(n) ((n)->i_key.nk.next) 16 | 17 | 18 | /* 'const' to avoid wrong writings that can mess up field 'next' */ 19 | #define gkey(n) cast(const TValue*, (&(n)->i_key.tvk)) 20 | 21 | /* 22 | ** writable version of 'gkey'; allows updates to individual fields, 23 | ** but not to the whole (which has incompatible type) 24 | */ 25 | #define wgkey(n) (&(n)->i_key.nk) 26 | 27 | #define invalidateTMcache(t) ((t)->flags = 0) 28 | 29 | 30 | /* returns the key, given the value of a table entry */ 31 | #define keyfromval(v) \ 32 | (gkey(cast(Node *, cast(char *, (v)) - offsetof(Node, i_val)))) 33 | 34 | 35 | LUAI_FUNC const TValue *luaH_getint (Table *t, lua_Integer key); 36 | LUAI_FUNC void luaH_setint (lua_State *L, Table *t, lua_Integer key, 37 | TValue *value); 38 | LUAI_FUNC const TValue *luaH_getshortstr (Table *t, TString *key); 39 | LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key); 40 | LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key); 41 | LUAI_FUNC TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key); 42 | LUAI_FUNC TValue *luaH_set (lua_State *L, Table *t, const TValue *key); 43 | LUAI_FUNC Table *luaH_new (lua_State *L); 44 | LUAI_FUNC void luaH_resize (lua_State *L, Table *t, unsigned int nasize, 45 | unsigned int nhsize); 46 | LUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, unsigned int nasize); 47 | LUAI_FUNC void luaH_free (lua_State *L, Table *t); 48 | LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key); 49 | LUAI_FUNC int luaH_getn (Table *t); 50 | 51 | 52 | #if defined(LUA_DEBUG) 53 | LUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key); 54 | LUAI_FUNC int luaH_isdummy (Node *n); 55 | #endif 56 | 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /dep/lua/ltm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltm.h,v 2.21 2014/10/25 11:50:46 roberto Exp $ 3 | ** Tag methods 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ltm_h 8 | #define ltm_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | /* 15 | * WARNING: if you change the order of this enumeration, 16 | * grep "ORDER TM" and "ORDER OP" 17 | */ 18 | typedef enum { 19 | TM_INDEX, 20 | TM_NEWINDEX, 21 | TM_GC, 22 | TM_MODE, 23 | TM_LEN, 24 | TM_EQ, /* last tag method with fast access */ 25 | TM_ADD, 26 | TM_SUB, 27 | TM_MUL, 28 | TM_MOD, 29 | TM_POW, 30 | TM_DIV, 31 | TM_IDIV, 32 | TM_BAND, 33 | TM_BOR, 34 | TM_BXOR, 35 | TM_SHL, 36 | TM_SHR, 37 | TM_UNM, 38 | TM_BNOT, 39 | TM_LT, 40 | TM_LE, 41 | TM_CONCAT, 42 | TM_CALL, 43 | TM_N /* number of elements in the enum */ 44 | } TMS; 45 | 46 | 47 | 48 | #define gfasttm(g,et,e) ((et) == NULL ? NULL : \ 49 | ((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e])) 50 | 51 | #define fasttm(l,et,e) gfasttm(G(l), et, e) 52 | 53 | #define ttypename(x) luaT_typenames_[(x) + 1] 54 | #define objtypename(x) ttypename(ttnov(x)) 55 | 56 | LUAI_DDEC const char *const luaT_typenames_[LUA_TOTALTAGS]; 57 | 58 | 59 | LUAI_FUNC const TValue *luaT_gettm (Table *events, TMS event, TString *ename); 60 | LUAI_FUNC const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, 61 | TMS event); 62 | LUAI_FUNC void luaT_init (lua_State *L); 63 | 64 | LUAI_FUNC void luaT_callTM (lua_State *L, const TValue *f, const TValue *p1, 65 | const TValue *p2, TValue *p3, int hasres); 66 | LUAI_FUNC int luaT_callbinTM (lua_State *L, const TValue *p1, const TValue *p2, 67 | StkId res, TMS event); 68 | LUAI_FUNC void luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2, 69 | StkId res, TMS event); 70 | LUAI_FUNC int luaT_callorderTM (lua_State *L, const TValue *p1, 71 | const TValue *p2, TMS event); 72 | 73 | 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /dep/lua/lua.hpp: -------------------------------------------------------------------------------- 1 | // lua.hpp 2 | // Lua header files for C++ 3 | // <> not supplied automatically because Lua also compiles as C++ 4 | 5 | extern "C" { 6 | #include "lua.h" 7 | #include "lualib.h" 8 | #include "lauxlib.h" 9 | } 10 | -------------------------------------------------------------------------------- /dep/lua/lualib.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lualib.h,v 1.44 2014/02/06 17:32:33 roberto Exp $ 3 | ** Lua standard libraries 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lualib_h 9 | #define lualib_h 10 | 11 | #include "lua.h" 12 | 13 | 14 | 15 | LUAMOD_API int (luaopen_base) (lua_State *L); 16 | 17 | #define LUA_COLIBNAME "coroutine" 18 | LUAMOD_API int (luaopen_coroutine) (lua_State *L); 19 | 20 | #define LUA_TABLIBNAME "table" 21 | LUAMOD_API int (luaopen_table) (lua_State *L); 22 | 23 | #define LUA_IOLIBNAME "io" 24 | LUAMOD_API int (luaopen_io) (lua_State *L); 25 | 26 | #define LUA_OSLIBNAME "os" 27 | LUAMOD_API int (luaopen_os) (lua_State *L); 28 | 29 | #define LUA_STRLIBNAME "string" 30 | LUAMOD_API int (luaopen_string) (lua_State *L); 31 | 32 | #define LUA_UTF8LIBNAME "utf8" 33 | LUAMOD_API int (luaopen_utf8) (lua_State *L); 34 | 35 | #define LUA_BITLIBNAME "bit32" 36 | LUAMOD_API int (luaopen_bit32) (lua_State *L); 37 | 38 | #define LUA_MATHLIBNAME "math" 39 | LUAMOD_API int (luaopen_math) (lua_State *L); 40 | 41 | #define LUA_DBLIBNAME "debug" 42 | LUAMOD_API int (luaopen_debug) (lua_State *L); 43 | 44 | #define LUA_LOADLIBNAME "package" 45 | LUAMOD_API int (luaopen_package) (lua_State *L); 46 | 47 | 48 | /* open all previous libraries */ 49 | LUALIB_API void (luaL_openlibs) (lua_State *L); 50 | 51 | 52 | 53 | #if !defined(lua_assert) 54 | #define lua_assert(x) ((void)0) 55 | #endif 56 | 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /dep/lua/lundump.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lundump.h,v 1.45 2015/09/08 15:41:05 roberto Exp $ 3 | ** load precompiled Lua chunks 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lundump_h 8 | #define lundump_h 9 | 10 | #include "llimits.h" 11 | #include "lobject.h" 12 | #include "lzio.h" 13 | 14 | 15 | /* data to catch conversion errors */ 16 | #define LUAC_DATA "\x19\x93\r\n\x1a\n" 17 | 18 | #define LUAC_INT 0x5678 19 | #define LUAC_NUM cast_num(370.5) 20 | 21 | #define MYINT(s) (s[0]-'0') 22 | #define LUAC_VERSION (MYINT(LUA_VERSION_MAJOR)*16+MYINT(LUA_VERSION_MINOR)) 23 | #define LUAC_FORMAT 0 /* this is the official format */ 24 | 25 | /* load one chunk; from lundump.c */ 26 | LUAI_FUNC LClosure* luaU_undump (lua_State* L, ZIO* Z, const char* name); 27 | 28 | /* dump one chunk; from ldump.c */ 29 | LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, 30 | void* data, int strip); 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /dep/lua/lzio.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.c,v 1.37 2015/09/08 15:41:05 roberto Exp $ 3 | ** Buffered streams 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lzio_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include 14 | 15 | #include "lua.h" 16 | 17 | #include "llimits.h" 18 | #include "lmem.h" 19 | #include "lstate.h" 20 | #include "lzio.h" 21 | 22 | 23 | int luaZ_fill (ZIO *z) { 24 | size_t size; 25 | lua_State *L = z->L; 26 | const char *buff; 27 | lua_unlock(L); 28 | buff = z->reader(L, z->data, &size); 29 | lua_lock(L); 30 | if (buff == NULL || size == 0) 31 | return EOZ; 32 | z->n = size - 1; /* discount char being returned */ 33 | z->p = buff; 34 | return cast_uchar(*(z->p++)); 35 | } 36 | 37 | 38 | void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) { 39 | z->L = L; 40 | z->reader = reader; 41 | z->data = data; 42 | z->n = 0; 43 | z->p = NULL; 44 | } 45 | 46 | 47 | /* --------------------------------------------------------------- read --- */ 48 | size_t luaZ_read (ZIO *z, void *b, size_t n) { 49 | while (n) { 50 | size_t m; 51 | if (z->n == 0) { /* no bytes in buffer? */ 52 | if (luaZ_fill(z) == EOZ) /* try to read more */ 53 | return n; /* no more input; return number of missing bytes */ 54 | else { 55 | z->n++; /* luaZ_fill consumed first byte; put it back */ 56 | z->p--; 57 | } 58 | } 59 | m = (n <= z->n) ? n : z->n; /* min. between n and z->n */ 60 | memcpy(b, z->p, m); 61 | z->n -= m; 62 | z->p += m; 63 | b = (char *)b + m; 64 | n -= m; 65 | } 66 | return 0; 67 | } 68 | 69 | -------------------------------------------------------------------------------- /dep/lua/lzio.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.h,v 1.31 2015/09/08 15:41:05 roberto Exp $ 3 | ** Buffered streams 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lzio_h 9 | #define lzio_h 10 | 11 | #include "lua.h" 12 | 13 | #include "lmem.h" 14 | 15 | 16 | #define EOZ (-1) /* end of stream */ 17 | 18 | typedef struct Zio ZIO; 19 | 20 | #define zgetc(z) (((z)->n--)>0 ? cast_uchar(*(z)->p++) : luaZ_fill(z)) 21 | 22 | 23 | typedef struct Mbuffer { 24 | char *buffer; 25 | size_t n; 26 | size_t buffsize; 27 | } Mbuffer; 28 | 29 | #define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0) 30 | 31 | #define luaZ_buffer(buff) ((buff)->buffer) 32 | #define luaZ_sizebuffer(buff) ((buff)->buffsize) 33 | #define luaZ_bufflen(buff) ((buff)->n) 34 | 35 | #define luaZ_buffremove(buff,i) ((buff)->n -= (i)) 36 | #define luaZ_resetbuffer(buff) ((buff)->n = 0) 37 | 38 | 39 | #define luaZ_resizebuffer(L, buff, size) \ 40 | ((buff)->buffer = luaM_reallocvchar(L, (buff)->buffer, \ 41 | (buff)->buffsize, size), \ 42 | (buff)->buffsize = size) 43 | 44 | #define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0) 45 | 46 | 47 | LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, 48 | void *data); 49 | LUAI_FUNC size_t luaZ_read (ZIO* z, void *b, size_t n); /* read next n bytes */ 50 | 51 | 52 | 53 | /* --------- Private Part ------------------ */ 54 | 55 | struct Zio { 56 | size_t n; /* bytes still unread */ 57 | const char *p; /* current position in buffer */ 58 | lua_Reader reader; /* reader function */ 59 | void *data; /* additional data */ 60 | lua_State *L; /* Lua state (for reader) */ 61 | }; 62 | 63 | 64 | LUAI_FUNC int luaZ_fill (ZIO *z); 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /dep/squish/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(squish_src 2 | alpha.cpp 3 | clusterfit.h 4 | colourblock.h 5 | colourset.cpp 6 | maths.cpp 7 | rangefit.h 8 | simd_float.h 9 | singlecolourfit.cpp 10 | squish.cpp 11 | alpha.h 12 | colourfit.cpp 13 | colourset.h 14 | maths.h 15 | simd_sse.h 16 | singlecolourfit.h 17 | squish.h 18 | clusterfit.cpp 19 | colourblock.cpp 20 | colourfit.h 21 | config.h 22 | rangefit.cpp 23 | simd.h 24 | simd_ve.h 25 | ) 26 | 27 | add_library(squish ${squish_src}) 28 | -------------------------------------------------------------------------------- /dep/squish/README: -------------------------------------------------------------------------------- 1 | LICENSE 2 | ------- 3 | 4 | The squish library is distributed under the terms and conditions of the MIT 5 | license. This license is specified at the top of each source file and must be 6 | preserved in its entirety. 7 | 8 | BUILDING AND INSTALLING THE LIBRARY 9 | ----------------------------------- 10 | 11 | If you are using Visual Studio 2003 or above under Windows then load the Visual 12 | Studio 2003 project in the vs7 folder. By default, the library is built using 13 | SSE2 optimisations. To change this either change or remove the SQUISH_USE_SSE=2 14 | from the preprocessor symbols. 15 | 16 | If you are using a Mac then load the Xcode 2.2 project in the distribution. By 17 | default, the library is built using Altivec optimisations. To change this 18 | either change or remove SQUISH_USE_ALTIVEC=1 from the preprocessor symbols. I 19 | guess I'll have to think about changing this for the new Intel Macs that are 20 | rolling out... 21 | 22 | If you are using unix then first edit the config file in the base directory of 23 | the distribution, enabling Altivec or SSE with the USE_ALTIVEC or USE_SSE 24 | variables, and editing the optimisation flags passed to the C++ compiler if 25 | necessary. Then make can be used to build the library, and make install (from 26 | the superuser account) can be used to install (into /usr/local by default). 27 | 28 | REPORTING BUGS OR FEATURE REQUESTS 29 | ---------------------------------- 30 | 31 | Feedback can be sent to Simon Brown (the developer) at si@sjbrown.co.uk 32 | 33 | New releases are announced on the squish library homepage at 34 | http://sjbrown.co.uk/?code=squish 35 | 36 | -------------------------------------------------------------------------------- /dep/squish/alpha.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------------- 2 | 3 | Copyright (c) 2006 Simon Brown si@sjbrown.co.uk 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included 14 | in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | -------------------------------------------------------------------------- */ 25 | 26 | #ifndef SQUISH_ALPHA_H 27 | #define SQUISH_ALPHA_H 28 | 29 | #include "squish.h" 30 | 31 | namespace squish { 32 | 33 | void CompressAlphaDxt3( u8 const* rgba, int mask, void* block ); 34 | void CompressAlphaDxt5( u8 const* rgba, int mask, void* block ); 35 | 36 | void DecompressAlphaDxt3( u8* rgba, void const* block ); 37 | void DecompressAlphaDxt5( u8* rgba, void const* block ); 38 | 39 | } // namespace squish 40 | 41 | #endif // ndef SQUISH_ALPHA_H 42 | -------------------------------------------------------------------------------- /dep/squish/clusterfit.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------------- 2 | 3 | Copyright (c) 2006 Simon Brown si@sjbrown.co.uk 4 | Copyright (c) 2007 Ignacio Castano icastano@nvidia.com 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining 7 | a copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included 15 | in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | -------------------------------------------------------------------------- */ 26 | 27 | #ifndef SQUISH_CLUSTERFIT_H 28 | #define SQUISH_CLUSTERFIT_H 29 | 30 | #include "squish.h" 31 | #include "maths.h" 32 | #include "simd.h" 33 | #include "colourfit.h" 34 | 35 | namespace squish { 36 | 37 | class ClusterFit : public ColourFit 38 | { 39 | public: 40 | ClusterFit( ColourSet const* colours, int flags ); 41 | 42 | private: 43 | bool ConstructOrdering( Vec3 const& axis, int iteration ); 44 | 45 | virtual void Compress3( void* block ); 46 | virtual void Compress4( void* block ); 47 | 48 | enum { kMaxIterations = 8 }; 49 | 50 | int m_iterationCount; 51 | Vec3 m_principle; 52 | u8 m_order[16*kMaxIterations]; 53 | Vec4 m_points_weights[16]; 54 | Vec4 m_xsum_wsum; 55 | Vec4 m_metric; 56 | Vec4 m_besterror; 57 | }; 58 | 59 | } // namespace squish 60 | 61 | #endif // ndef SQUISH_CLUSTERFIT_H 62 | -------------------------------------------------------------------------------- /dep/squish/colourblock.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------------- 2 | 3 | Copyright (c) 2006 Simon Brown si@sjbrown.co.uk 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included 14 | in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | -------------------------------------------------------------------------- */ 25 | 26 | #ifndef SQUISH_COLOURBLOCK_H 27 | #define SQUISH_COLOURBLOCK_H 28 | 29 | #include "squish.h" 30 | #include "maths.h" 31 | 32 | namespace squish { 33 | 34 | void WriteColourBlock3( Vec3::Arg start, Vec3::Arg end, u8 const* indices, void* block ); 35 | void WriteColourBlock4( Vec3::Arg start, Vec3::Arg end, u8 const* indices, void* block ); 36 | 37 | void DecompressColour( u8* rgba, void const* block, bool isDxt1 ); 38 | 39 | } // namespace squish 40 | 41 | #endif // ndef SQUISH_COLOURBLOCK_H 42 | -------------------------------------------------------------------------------- /dep/squish/colourfit.cpp: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------------- 2 | 3 | Copyright (c) 2006 Simon Brown si@sjbrown.co.uk 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included 14 | in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | -------------------------------------------------------------------------- */ 25 | 26 | #include "colourfit.h" 27 | #include "colourset.h" 28 | 29 | namespace squish { 30 | 31 | ColourFit::ColourFit( ColourSet const* colours, int flags ) 32 | : m_colours( colours ), 33 | m_flags( flags ) 34 | { 35 | } 36 | 37 | void ColourFit::Compress( void* block ) 38 | { 39 | bool isDxt1 = ( ( m_flags & kDxt1 ) != 0 ); 40 | if( isDxt1 ) 41 | { 42 | Compress3( block ); 43 | if( !m_colours->IsTransparent() ) 44 | Compress4( block ); 45 | } 46 | else 47 | Compress4( block ); 48 | } 49 | 50 | } // namespace squish 51 | -------------------------------------------------------------------------------- /dep/squish/colourfit.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------------- 2 | 3 | Copyright (c) 2006 Simon Brown si@sjbrown.co.uk 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included 14 | in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | -------------------------------------------------------------------------- */ 25 | 26 | #ifndef SQUISH_COLOURFIT_H 27 | #define SQUISH_COLOURFIT_H 28 | 29 | #include "squish.h" 30 | #include "maths.h" 31 | 32 | namespace squish { 33 | 34 | class ColourSet; 35 | 36 | class ColourFit 37 | { 38 | public: 39 | ColourFit( ColourSet const* colours, int flags ); 40 | 41 | void Compress( void* block ); 42 | 43 | protected: 44 | virtual void Compress3( void* block ) = 0; 45 | virtual void Compress4( void* block ) = 0; 46 | 47 | ColourSet const* m_colours; 48 | int m_flags; 49 | }; 50 | 51 | } // namespace squish 52 | 53 | #endif // ndef SQUISH_COLOURFIT_H 54 | -------------------------------------------------------------------------------- /dep/squish/colourset.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------------- 2 | 3 | Copyright (c) 2006 Simon Brown si@sjbrown.co.uk 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included 14 | in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | -------------------------------------------------------------------------- */ 25 | 26 | #ifndef SQUISH_COLOURSET_H 27 | #define SQUISH_COLOURSET_H 28 | 29 | #include "squish.h" 30 | #include "maths.h" 31 | 32 | namespace squish { 33 | 34 | /*! @brief Represents a set of block colours 35 | */ 36 | class ColourSet 37 | { 38 | public: 39 | ColourSet( u8 const* rgba, int mask, int flags ); 40 | 41 | int GetCount() const { return m_count; } 42 | Vec3 const* GetPoints() const { return m_points; } 43 | float const* GetWeights() const { return m_weights; } 44 | bool IsTransparent() const { return m_transparent; } 45 | 46 | void RemapIndices( u8 const* source, u8* target ) const; 47 | 48 | private: 49 | int m_count; 50 | Vec3 m_points[16]; 51 | float m_weights[16]; 52 | int m_remap[16]; 53 | bool m_transparent; 54 | }; 55 | 56 | } // namespace sqish 57 | 58 | #endif // ndef SQUISH_COLOURSET_H 59 | -------------------------------------------------------------------------------- /dep/squish/config.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------------- 2 | 3 | Copyright (c) 2006 Simon Brown si@sjbrown.co.uk 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included 14 | in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | -------------------------------------------------------------------------- */ 25 | 26 | #ifndef SQUISH_CONFIG_H 27 | #define SQUISH_CONFIG_H 28 | 29 | // Set to 1 when building squish to use Altivec instructions. 30 | #ifndef SQUISH_USE_ALTIVEC 31 | #define SQUISH_USE_ALTIVEC 0 32 | #endif 33 | 34 | // Set to 1 or 2 when building squish to use SSE or SSE2 instructions. 35 | #ifndef SQUISH_USE_SSE 36 | #define SQUISH_USE_SSE 0 37 | #endif 38 | 39 | // Internally et SQUISH_USE_SIMD when either Altivec or SSE is available. 40 | #if SQUISH_USE_ALTIVEC && SQUISH_USE_SSE 41 | #error "Cannot enable both Altivec and SSE!" 42 | #endif 43 | #if SQUISH_USE_ALTIVEC || SQUISH_USE_SSE 44 | #define SQUISH_USE_SIMD 1 45 | #else 46 | #define SQUISH_USE_SIMD 0 47 | #endif 48 | 49 | #endif // ndef SQUISH_CONFIG_H 50 | -------------------------------------------------------------------------------- /dep/squish/rangefit.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------------- 2 | 3 | Copyright (c) 2006 Simon Brown si@sjbrown.co.uk 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included 14 | in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | -------------------------------------------------------------------------- */ 25 | 26 | #ifndef SQUISH_RANGEFIT_H 27 | #define SQUISH_RANGEFIT_H 28 | 29 | #include "squish.h" 30 | #include "colourfit.h" 31 | #include "maths.h" 32 | 33 | namespace squish { 34 | 35 | class ColourSet; 36 | 37 | class RangeFit : public ColourFit 38 | { 39 | public: 40 | RangeFit( ColourSet const* colours, int flags ); 41 | 42 | private: 43 | virtual void Compress3( void* block ); 44 | virtual void Compress4( void* block ); 45 | 46 | Vec3 m_metric; 47 | Vec3 m_start; 48 | Vec3 m_end; 49 | float m_besterror; 50 | }; 51 | 52 | } // squish 53 | 54 | #endif // ndef SQUISH_RANGEFIT_H 55 | -------------------------------------------------------------------------------- /dep/squish/simd.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------------- 2 | 3 | Copyright (c) 2006 Simon Brown si@sjbrown.co.uk 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included 14 | in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | -------------------------------------------------------------------------- */ 25 | 26 | #ifndef SQUISH_SIMD_H 27 | #define SQUISH_SIMD_H 28 | 29 | #include "maths.h" 30 | 31 | #if SQUISH_USE_ALTIVEC 32 | #include "simd_ve.h" 33 | #elif SQUISH_USE_SSE 34 | #include "simd_sse.h" 35 | #else 36 | #include "simd_float.h" 37 | #endif 38 | 39 | 40 | #endif // ndef SQUISH_SIMD_H 41 | -------------------------------------------------------------------------------- /dep/squish/singlecolourfit.h: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------------- 2 | 3 | Copyright (c) 2006 Simon Brown si@sjbrown.co.uk 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included 14 | in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | -------------------------------------------------------------------------- */ 25 | 26 | #ifndef SQUISH_SINGLECOLOURFIT_H 27 | #define SQUISH_SINGLECOLOURFIT_H 28 | 29 | #include "squish.h" 30 | #include "colourfit.h" 31 | 32 | namespace squish { 33 | 34 | class ColourSet; 35 | struct SingleColourLookup; 36 | 37 | class SingleColourFit : public ColourFit 38 | { 39 | public: 40 | SingleColourFit( ColourSet const* colours, int flags ); 41 | 42 | private: 43 | virtual void Compress3( void* block ); 44 | virtual void Compress4( void* block ); 45 | 46 | void ComputeEndPoints( SingleColourLookup const* const* lookups ); 47 | 48 | u8 m_colour[3]; 49 | Vec3 m_start; 50 | Vec3 m_end; 51 | u8 m_index; 52 | int m_error; 53 | int m_besterror; 54 | }; 55 | 56 | } // namespace squish 57 | 58 | #endif // ndef SQUISH_SINGLECOLOURFIT_H 59 | -------------------------------------------------------------------------------- /engine/Arc.h: -------------------------------------------------------------------------------- 1 | /* 2 | GameEngine header - Arc.h 3 | Class for creating electric-looking arcs between two points 4 | Copyright (c) 2014 Mark Hutcheson 5 | */ 6 | #pragma once 7 | 8 | #include "Rect.h" 9 | #include "Color.h" 10 | #include 11 | 12 | class Arc 13 | { 14 | protected: 15 | float* segmentPos; 16 | //Image* arcSegImg; 17 | unsigned numSegments; 18 | 19 | Arc(){}; 20 | void average(); //Helper function to average the values for a less jittery arc 21 | 22 | public: 23 | Vec2 p1, p2; 24 | float add; 25 | float max; 26 | float height; 27 | unsigned avg; 28 | float depth; 29 | //Image* img; 30 | bool active; 31 | Color col; 32 | 33 | Arc(unsigned number); 34 | ~Arc(); 35 | 36 | void init(); 37 | void draw(glm::mat4 mat); 38 | void update(float dt); 39 | 40 | //Accessor methods 41 | unsigned getNumber() {return numSegments;}; 42 | 43 | 44 | }; 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /engine/BezierInterpolation.cpp: -------------------------------------------------------------------------------- 1 | #include "BezierInterpolation.h" 2 | 3 | BezierInterpolation::BezierInterpolation(float* v, float d, float t) : Interpolation(v, d, t) 4 | { 5 | } 6 | 7 | bool BezierInterpolation::update(float dt) 8 | { 9 | curTime += dt; 10 | 11 | //See if done 12 | if(curTime >= time) 13 | { 14 | *val = dest; 15 | return true; 16 | } 17 | 18 | //Formula: B(t) = (1-t)^3P0+3(1-t)^2tP1+3(1-t)t^2P2+t^3P3, 0 <= t <= 1 19 | 20 | float t = curTime / time; // range 0..1 for how far along we are (t) 21 | float negt = 1.0f - t; 22 | float p = (dest - start); //Value is y axis, control points on top/bottom of that 23 | 24 | //In our case, we only care about Y for 1D interpolation 25 | *val = start + 3 * negt*t*t*p + t*t*t*p; //Simplified a lot 26 | 27 | return false; 28 | } 29 | -------------------------------------------------------------------------------- /engine/BezierInterpolation.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Interpolation.h" 3 | #include "Rect.h" 4 | 5 | class BezierInterpolation : public Interpolation 6 | { 7 | BezierInterpolation() {}; 8 | public: 9 | BezierInterpolation(float* v, float d, float t); 10 | 11 | bool update(float dt); 12 | }; 13 | -------------------------------------------------------------------------------- /engine/Color.cpp: -------------------------------------------------------------------------------- 1 | #include "Color.h" 2 | #include 3 | #include "StringUtils.h" 4 | 5 | Color::Color() 6 | { 7 | clear(); 8 | } 9 | 10 | Color::Color(int ir, int ig, int ib) 11 | { 12 | from256(ir, ig, ib); 13 | } 14 | 15 | Color::Color(float fr, float fg, float fb, float fa) 16 | { 17 | set(fr, fg, fb, fa); 18 | } 19 | 20 | void Color::from256(int ir, int ig, int ib, int ia) 21 | { 22 | r = (float)ir / 255.0f; 23 | g = (float)ig / 255.0f; 24 | b = (float)ib / 255.0f; 25 | a = (float)ia / 255.0f; 26 | } 27 | 28 | void Color::fromString(const std::string& input) 29 | { 30 | std::string s = input; 31 | s = StringUtils::stripCommas(s); 32 | 33 | //Now, parse 34 | std::istringstream iss(s); 35 | int r, g, b, a; 36 | if(iss >> r >> g >> b) 37 | { 38 | if(!(iss >> a)) 39 | from256(r, g, b); 40 | else 41 | from256(r, g, b, a); 42 | } 43 | } 44 | 45 | std::string Color::toString() 46 | { 47 | std::ostringstream oss; 48 | int ir = (int)(r * 255); 49 | int ig = (int)(g * 255); 50 | int ib = (int)(b * 255); 51 | int ia = (int)(a * 255); 52 | oss << ir << ", " << ig << ", " << ib << ", " << ia; 53 | return oss.str(); 54 | } 55 | 56 | void Color::set(float fr, float fg, float fb, float fa) 57 | { 58 | r = fr; 59 | g = fg; 60 | b = fb; 61 | a = fa; 62 | } -------------------------------------------------------------------------------- /engine/Color.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | class Color 5 | { 6 | public: 7 | float r, g, b, a; 8 | Color(); 9 | Color(int ir, int ig, int ib); 10 | Color(float fr, float fg, float fb, float fa); 11 | 12 | void from256(int ir, int ig, int ib, int a = 255); 13 | void set(float fr, float fg, float fb, float fa = 1.0); 14 | void clear() { r = g = b = a = 1.0f; }; 15 | 16 | void fromString(const std::string& s); //Set values from comma-separated values in a string 17 | std::string toString(); 18 | }; -------------------------------------------------------------------------------- /engine/DebugDraw.h: -------------------------------------------------------------------------------- 1 | #ifndef DEBUG_DRAW_H 2 | #define DEBUG_DRAW_H 3 | 4 | #include "Box2D/Box2D.h" 5 | 6 | //Debug draw class for drawing Box2D stuff 7 | class DebugDraw : public b2Draw 8 | { 9 | public: 10 | void DrawPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color); 11 | void DrawSolidPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color); 12 | void DrawCircle(const b2Vec2& center, float32 radius, const b2Color& color); 13 | void DrawSolidCircle(const b2Vec2& center, float32 radius, const b2Vec2& axis, const b2Color& color); 14 | void DrawSegment(const b2Vec2& p1, const b2Vec2& p2, const b2Color& color); 15 | void DrawTransform(const b2Transform& xf); 16 | void DrawPoint(const b2Vec2& p, float32 size, const b2Color& color); 17 | void DrawString(int x, int y, const char* string, ...); 18 | void DrawString(const b2Vec2& p, const char* string, ...); 19 | void DrawAABB(b2AABB* aabb, const b2Color& color); 20 | 21 | unsigned int uniformId; 22 | float fillAlpha; 23 | float fillMul; 24 | float outlineAlpha; 25 | }; 26 | 27 | 28 | #endif //DEBUG_DRAW_H -------------------------------------------------------------------------------- /engine/EngineContactListener.cpp: -------------------------------------------------------------------------------- 1 | #include "EngineContactListener.h" 2 | #include "ObjSegment.h" 3 | #include 4 | 5 | void EngineContactListener::BeginContact(b2Contact *contact) 6 | { 7 | currentContacts.insert(contact); //Keep track of all contacts 8 | if(!contact->IsTouching()) return; //Don't keep track of temp contacts if they're not touching, however. Can we miss short contacts this way? I dunno, don't care 9 | 10 | m_tmpFrameContacts.insert(contact); //Keep track of all contacts that started this frame 11 | } 12 | 13 | void EngineContactListener::EndContact(b2Contact *contact) 14 | { 15 | currentContacts.erase(contact); //Don't track this contact anymore 16 | if(m_tmpFrameContacts.count(contact)) //If we've added this this frame, add this to our set that keeps track of short fast contacts (so they can still be registered in this frame) 17 | frameContacts.insert(contact); 18 | } 19 | 20 | void EngineContactListener::PreSolve(b2Contact *contact, const b2Manifold *oldManifold) 21 | { 22 | 23 | } 24 | 25 | void EngineContactListener::PostSolve(b2Contact *contact, const b2ContactImpulse *impulse) 26 | { 27 | 28 | } 29 | 30 | Object* EngineContactListener::getObj(b2Fixture* fix) 31 | { 32 | Object* result = NULL; 33 | if(fix) 34 | { 35 | b2Body* bod = fix->GetBody(); 36 | if(bod) 37 | { 38 | void* data = bod->GetUserData(); 39 | if(data) 40 | { 41 | ObjSegment* seg = (ObjSegment*)data; 42 | result = seg->parent; 43 | } 44 | } 45 | } 46 | return result; 47 | } 48 | 49 | Collision EngineContactListener::getCollision(b2Contact* c) 50 | { 51 | Collision cResult = {NULL, NULL, NULL, NULL, c->GetManifold()->points[0].normalImpulse}; 52 | if(!c->IsTouching()) return cResult; 53 | 54 | b2Fixture* fixA = c->GetFixtureA(); 55 | b2Fixture* fixB = c->GetFixtureB(); 56 | 57 | void* fixAUser = fixA->GetUserData(); 58 | void* fixBUser = fixB->GetUserData(); 59 | 60 | if(fixAUser) 61 | cResult.nodeA = (Node*)fixAUser; 62 | if(fixBUser) 63 | cResult.nodeB = (Node*)fixBUser; 64 | 65 | cResult.objA = getObj(fixA); 66 | cResult.objB = getObj(fixB); 67 | 68 | return cResult; 69 | } 70 | 71 | void EngineContactListener::clearFrameContacts() 72 | { 73 | frameContacts.clear(); 74 | m_tmpFrameContacts.clear(); 75 | } -------------------------------------------------------------------------------- /engine/EngineContactListener.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Box2D/Dynamics/b2WorldCallbacks.h" 4 | #include "Object.h" 5 | #include "Node.h" 6 | #include 7 | 8 | typedef struct { 9 | Object* objA; 10 | Object* objB; 11 | Node* nodeA; 12 | Node* nodeB; 13 | float impulse; 14 | } Collision; 15 | 16 | class EngineContactListener : public b2ContactListener 17 | { 18 | std::set m_tmpFrameContacts; 19 | public: 20 | std::set frameContacts; 21 | std::set currentContacts; 22 | 23 | //Implementations from Box2D 24 | virtual void BeginContact(b2Contact *contact); 25 | virtual void EndContact(b2Contact *contact); 26 | virtual void PreSolve(b2Contact *contact, const b2Manifold *oldManifold); 27 | virtual void PostSolve(b2Contact *contact, const b2ContactImpulse *impulse); 28 | 29 | //Helper functions for my use 30 | static Collision getCollision(b2Contact* c); //Get two objects that are colliding on this fixture (either one can be NULL) 31 | static Object* getObj(b2Fixture* fix); //Get the object (or NULL) this fixture is associated with 32 | void clearFrameContacts(); //Call every frame to wipe temporary (hit and leave) contacts for that frame 33 | }; 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /engine/Engine_Window.cpp: -------------------------------------------------------------------------------- 1 | #include "Engine.h" 2 | #include "Logger.h" 3 | 4 | void Engine::changeScreenResolution(int w, int h) 5 | { 6 | LOG(INFO) << "Changing screen resolution to " << w << ", " << h; 7 | 8 | m_iWidth = w; 9 | m_iHeight = h; 10 | 11 | if(m_bFullscreen) 12 | SDL_SetWindowFullscreen(m_Window, SDL_WINDOW_FULLSCREEN_DESKTOP); 13 | 14 | SDL_SetWindowSize(m_Window, m_iWidth, m_iHeight); 15 | 16 | //Set OpenGL back up 17 | setup_opengl(); 18 | } 19 | 20 | void Engine::setFullscreen(bool bFullscreen) 21 | { 22 | if(m_bFullscreen == bFullscreen) 23 | return; 24 | m_bFullscreen = !m_bFullscreen; 25 | //TODO: Restore previous window size/maximized when exiting from fullscreen 26 | SDL_SetWindowFullscreen(m_Window, (m_bFullscreen) ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0); 27 | } 28 | 29 | bool Engine::isMaximized() 30 | { 31 | return !!(SDL_GetWindowFlags(m_Window) & SDL_WINDOW_MAXIMIZED); 32 | } 33 | 34 | Vec2 Engine::getWindowPos() 35 | { 36 | Vec2 p; 37 | int x, y; 38 | SDL_GetWindowPosition(m_Window, &x, &y); 39 | p.x = (float)x; 40 | p.y = (float)y; 41 | return p; 42 | } 43 | 44 | //If we used to be fullscreen, and now we're not, we don't want to be in the upper-left corner. 45 | void Engine::setWindowPos(Vec2 pos) 46 | { 47 | if(pos.x > 0 && pos.y > 0) 48 | SDL_SetWindowPosition(m_Window, (int)pos.x, (int)pos.y); 49 | else 50 | SDL_SetWindowPosition(m_Window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED); //Center if we're upper-left corner or above or some such. 51 | } 52 | 53 | void Engine::maximizeWindow() 54 | { 55 | SDL_MaximizeWindow(m_Window); 56 | } 57 | 58 | -------------------------------------------------------------------------------- /engine/Gradient.cpp: -------------------------------------------------------------------------------- 1 | #include "Gradient.h" 2 | #include "tinyxml2.h" 3 | #include "Logger.h" 4 | 5 | Gradient::Gradient(const std::string& sXMLFilename) 6 | { 7 | load(sXMLFilename); 8 | } 9 | 10 | Gradient::Gradient() 11 | { 12 | } 13 | 14 | void Gradient::insert(float fVal, int32_t r, int32_t g, int32_t b, int32_t a) 15 | { 16 | Color c; 17 | c.from256(r, g, b, a); 18 | m_colorMap[fVal] = c; 19 | } 20 | 21 | Color Gradient::getVal(float fVal) 22 | { 23 | for(std::map::iterator i = m_colorMap.begin(); i != m_colorMap.end(); i++) 24 | { 25 | if(fVal <= i->first) 26 | return i->second; //Before beginning, or exactly on one point - return this color 27 | 28 | //Get next color point 29 | std::map::iterator next = i; 30 | next++; 31 | if(next == m_colorMap.end()) 32 | return i->second; //Past end - return last color in list 33 | 34 | if(fVal >= i->first && fVal <= next->first) //Between these two points 35 | { 36 | float rDiff = next->second.r - i->second.r; 37 | float gDiff = next->second.g - i->second.g; 38 | float bDiff = next->second.b - i->second.b; 39 | float aDiff = next->second.a - i->second.a; 40 | float diff = next->first - i->first; 41 | float diffFac = (fVal - i->first) / diff; 42 | 43 | Color c = i->second; 44 | c.r += rDiff * diffFac; 45 | c.g += gDiff * diffFac; 46 | c.b += bDiff * diffFac; 47 | c.a += aDiff * diffFac; 48 | return c; 49 | } 50 | } 51 | 52 | Color c; 53 | return c; //No points or something; return rgba(1,1,1,1) 54 | } 55 | 56 | bool Gradient::load(const std::string& sXMLFilename) 57 | { 58 | m_colorMap.clear(); 59 | 60 | tinyxml2::XMLDocument* doc = new tinyxml2::XMLDocument; 61 | int iErr = doc->LoadFile(sXMLFilename.c_str()); 62 | if(iErr != tinyxml2::XML_NO_ERROR) 63 | { 64 | LOG(ERR) << "Error opening gradient XML file: " << sXMLFilename << "- Error " << iErr; 65 | delete doc; 66 | return false; 67 | } 68 | 69 | tinyxml2::XMLElement* root = doc->RootElement(); 70 | if(root == NULL) 71 | { 72 | LOG(ERR) << "Error: Root element NULL in XML file " << sXMLFilename << ". Ignoring..."; 73 | delete doc; 74 | return false; 75 | } 76 | 77 | for(tinyxml2::XMLElement* val = root->FirstChildElement("val"); val != NULL; val = val->NextSiblingElement("val")) 78 | { 79 | float pos = 0.0f; 80 | 81 | val->QueryFloatAttribute("pos", &pos); 82 | const char* cCol = val->Attribute("col"); 83 | if(cCol != NULL) 84 | m_colorMap[pos].fromString(cCol); 85 | } 86 | 87 | delete doc; 88 | return true; 89 | } 90 | -------------------------------------------------------------------------------- /engine/Gradient.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Color.h" 4 | #include 5 | #include 6 | 7 | 8 | class Gradient 9 | { 10 | protected: 11 | 12 | 13 | std::map m_colorMap; 14 | 15 | 16 | public: 17 | Gradient(const std::string& sXMLFilename); 18 | Gradient(); 19 | ~Gradient() {}; 20 | 21 | void insert(float fVal, int32_t r, int32_t g, int32_t b, int32_t a); 22 | Color getVal(float fVal); 23 | bool load(const std::string& sXMLFilename); 24 | 25 | }; 26 | -------------------------------------------------------------------------------- /engine/HeadTracker.cpp: -------------------------------------------------------------------------------- 1 | #include "HeadTracker.h" 2 | #include "Logger.h" 3 | 4 | #define AXIS_MAX 32767.0f 5 | 6 | HeadTracker::HeadTracker(SDL_Joystick* joy) 7 | { 8 | LOG(INFO) << "Initializing headtracker from joystick " << SDL_JoystickName(joy); 9 | m_joy = joy; 10 | } 11 | 12 | HeadTracker::~HeadTracker() 13 | { 14 | SDL_JoystickClose(m_joy); 15 | } 16 | 17 | float HeadTracker::getX() //-x is left 18 | { 19 | return scale(SDL_JoystickGetAxis(m_joy, 0)); 20 | } 21 | 22 | float HeadTracker::getY() //-y is down 23 | { 24 | return scale(SDL_JoystickGetAxis(m_joy, 1)); 25 | } 26 | 27 | float HeadTracker::getZ() //-z is tilt clockwise as facing screen 28 | { 29 | return scale(SDL_JoystickGetAxis(m_joy, 2)); 30 | } 31 | 32 | float HeadTracker::scale(Sint16 val) 33 | { 34 | return (float)(val) / AXIS_MAX; 35 | } 36 | 37 | -------------------------------------------------------------------------------- /engine/HeadTracker.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "SDL_joystick.h" 3 | 4 | class HeadTracker 5 | { 6 | SDL_Joystick* m_joy; 7 | 8 | HeadTracker() {}; 9 | float scale(Sint16 val); 10 | public: 11 | HeadTracker(SDL_Joystick* joy); 12 | ~HeadTracker(); 13 | 14 | float getX(); //Get -1..1 range for X 15 | float getY(); //Get -1..1 range for Y 16 | float getZ(); //Get -1..1 range for Z 17 | }; -------------------------------------------------------------------------------- /engine/ImgFont.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "Rect.h" 4 | 5 | class Image; 6 | 7 | class ImgFont 8 | { 9 | unsigned int num; 10 | Image* img; 11 | uint32_t* codepoints; 12 | float* rects; 13 | 14 | ImgFont() {}; 15 | 16 | void renderChar(Vec2 drawSz, Vec2 offset, float* rect); 17 | uint32_t getIndex(uint32_t codepoint); 18 | uint32_t getNextCodepoint(const char** strpos); //Get the next codepoint from the given string & increment the pointer 19 | float* getNextRect(const char** str); //Get the next image rect for the given string position & increment the pointer 20 | 21 | public: 22 | ImgFont(Image* image, unsigned int count, uint32_t* codePoints, float* imgRects); //codepoint/imgrect mem will be freed on obj deletion NOTE MUST BE CREATED WITH MALLOC 23 | ~ImgFont(); 24 | 25 | void renderString(const char* str, float drawPt, Vec2 drawOffset); 26 | float stringWidth(const char* str, float drawPt); 27 | }; 28 | -------------------------------------------------------------------------------- /engine/InputDevice.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "SDL.h" 3 | #include "Action.h" 4 | #include "Movement.h" 5 | #include "Rect.h" 6 | #include 7 | 8 | class SteelSeriesHaptic; 9 | class SteelSeriesClient; 10 | class ActionBind; 11 | class MovementBind; 12 | 13 | #define KB_MOUSE_DEVICE_INDEX -1 14 | 15 | class InputDevice 16 | { 17 | private: 18 | SDL_Haptic* m_haptic; 19 | SDL_GameController* m_controller; 20 | bool rumbleLRSupported; 21 | int m_deviceIndex; 22 | int curEffect; //Current effect index for haptic 23 | std::string joystickName; 24 | std::string controllerName; 25 | SteelSeriesHaptic* ssHaptic; 26 | 27 | void rumbleControllerBasic(float strength, uint32_t duration, float curTime); 28 | SDL_Haptic* initHapticDevice(SDL_Haptic* newRumble); 29 | 30 | public: 31 | InputDevice(SteelSeriesClient* ssc); //Init from mouse and kb 32 | InputDevice(int deviceIndex); //Init from controller 33 | ~InputDevice(); 34 | 35 | void rumbleLR(uint32_t duration, uint16_t largeMotor, uint16_t smallMotor, float curTime); 36 | 37 | int getAxis(int axis); 38 | bool getButton(int button); 39 | 40 | bool hasHaptic(); 41 | int getDeviceIndex() { return m_deviceIndex; } 42 | std::string getJoystickName() { return joystickName; } 43 | std::string getControllerName() { return controllerName; } 44 | }; -------------------------------------------------------------------------------- /engine/Interpolation.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class Interpolation 4 | { 5 | protected: 6 | 7 | Interpolation() {}; 8 | public: 9 | float* val; 10 | float start; 11 | float dest; 12 | float time; 13 | float curTime; 14 | 15 | Interpolation(float* v, float d, float t) : val(v), dest(d), time(t), curTime(0), start(*v) {}; 16 | 17 | virtual bool update(float dt) = 0; 18 | }; -------------------------------------------------------------------------------- /engine/LinearInterpolation.cpp: -------------------------------------------------------------------------------- 1 | #include "LinearInterpolation.h" 2 | 3 | LinearInterpolation::LinearInterpolation(float* v, float d, float t) : Interpolation(v, d, t) 4 | { 5 | } 6 | 7 | bool LinearInterpolation::update(float dt) 8 | { 9 | curTime += dt; 10 | 11 | //See if done 12 | if(curTime >= time) 13 | { 14 | *val = dest; 15 | return true; 16 | } 17 | 18 | float timeFac = curTime / time; // range 0..1 for how far along we are 19 | float amtFac = dest - start; // total difference between start and target value 20 | 21 | *val = timeFac * amtFac + start; // Set to proper linearly-interpolated value 22 | 23 | return false; 24 | } 25 | -------------------------------------------------------------------------------- /engine/LinearInterpolation.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Interpolation.h" 3 | 4 | class LinearInterpolation : public Interpolation 5 | { 6 | 7 | LinearInterpolation() {}; 8 | public: 9 | LinearInterpolation(float* v, float d, float t); 10 | 11 | bool update(float dt); 12 | }; 13 | -------------------------------------------------------------------------------- /engine/LuaFuncs.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "LuaDefines.h" 3 | 4 | struct lua_State; 5 | 6 | enum ObjMainType 7 | { 8 | OT_IMAGE, 9 | OT_OBJECT, 10 | OT_B2BODY, 11 | OT_ARC, 12 | OT_BG, 13 | OT_CURSOR, 14 | OT_ENGINE, 15 | OT_GAMEENGINE, 16 | OT_LATTICE, 17 | OT_NODE, 18 | OT_PARTICLESYSTEM, 19 | OT_TEXT, 20 | OT_TINYXML2, 21 | OT_SEGMENT, 22 | //TODO: Figure out what we should have, and add moar / remove some 23 | }; 24 | 25 | struct LuaFunctions 26 | { 27 | const char *name; 28 | lua_CFunction func; 29 | }; 30 | 31 | void lua_register_all(lua_State *); 32 | 33 | 34 | -------------------------------------------------------------------------------- /engine/LuaInterface.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | struct lua_State; 4 | 5 | class LuaObjGlue; 6 | 7 | class LuaInterface 8 | { 9 | public: 10 | 11 | LuaInterface(const char *script); 12 | ~LuaInterface(); 13 | 14 | bool Init(); 15 | void Shutdown(); 16 | void GC(); 17 | unsigned int MemUsed(); 18 | 19 | LuaObjGlue *createObject(void *o, unsigned ty, const char *classname); 20 | void deleteObject(LuaObjGlue *glue); 21 | 22 | //Direct method calls 23 | bool call(const char *f); 24 | bool call(const char *f, const char *); 25 | bool call(const char *f, const char *a, const char *b); 26 | bool call(const char *f, float); 27 | bool call(const char *f, int, int); 28 | bool call(const char *func, int a, int b, bool c); 29 | bool call(const char *func, int a, int b, int c, int d); 30 | bool call(const char *func, int a, int b, int c, int d, int e); 31 | bool call(const char *func, const char *a, const char *b, const char *c, const char *d, const char *e); 32 | bool call(const char *func, const char *a, const char *b, const char *c, const char *d); 33 | 34 | //Method calls on classes 35 | bool callMethod(void *o, const char *func); 36 | bool callMethod(void *o, const char *func, float a); 37 | bool callMethod(void *o, const char *func, float a, float b); 38 | bool callMethod(void *o, const char *func, float a, float b, float c); 39 | bool callMethod(void *o, const char *func, void* other); 40 | bool callMethod(void *o, const char *func, void* other, float a); 41 | 42 | //FG TODO: Add functions that call luaL_newmetatable() and all that, rather than just getState() 43 | lua_State* getState() {return _lua;}; 44 | 45 | protected: 46 | 47 | void lookupFunc(const char *f); 48 | //void lookupObject(void *o); // push Lua representation of an object 49 | void lookupMethod(void *o, const char *func); // Push object and its method as function 50 | bool doCall(int nparams, int nrets = 0); 51 | 52 | const char *script; 53 | 54 | lua_State *_lua; 55 | }; 56 | 57 | class LuaObjGlue 58 | { 59 | friend class LuaInterface; 60 | public: 61 | LuaObjGlue(void *p, unsigned ty) : obj(p), type(ty) {} 62 | void *obj; // read-only 63 | const unsigned type; 64 | 65 | private: 66 | LuaObjGlue(const LuaObjGlue&); // non-copyable 67 | }; 68 | 69 | -------------------------------------------------------------------------------- /engine/Node.cpp: -------------------------------------------------------------------------------- 1 | #include "Node.h" 2 | #include "LuaInterface.h" 3 | 4 | Node::Node() 5 | { 6 | body = NULL; 7 | lua = NULL; 8 | } 9 | 10 | Node::~Node() 11 | { 12 | if(lua) 13 | lua->callMethod(this, "destroy"); 14 | } 15 | 16 | //Node creation 17 | void Node::init() 18 | { 19 | if(lua && luaClass.length()) 20 | { 21 | lua_State* L = lua->getState(); 22 | lua->call("loadclass", ("node" + luaClass).c_str(), luaDef.c_str()); 23 | glueObj = lua->createObject(this, TYPE, ("node" + luaClass).c_str()); 24 | lua->callMethod(this, "init"); 25 | } 26 | } 27 | 28 | //Update the node 29 | void Node::update(float dt) 30 | { 31 | if(lua) 32 | lua->callMethod(this, "update", dt); 33 | } 34 | 35 | //Collided with an object 36 | void Node::collided(Object* o) 37 | { 38 | if(lua) 39 | lua->callMethod(this, "collide", o); 40 | } 41 | -------------------------------------------------------------------------------- /engine/Node.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "LuaFuncs.h" 3 | #include "Rect.h" 4 | #include 5 | #include 6 | 7 | class Object; 8 | class b2Body; 9 | class LuaObjGlue; 10 | class LuaInterface; 11 | 12 | class Node { 13 | LuaObjGlue* glueObj; 14 | std::map propertyValues; //This can be populated by XML and called from Lua! For userdata and such 15 | public: 16 | enum { TYPE = OT_NODE }; 17 | std::string luaClass; 18 | std::string luaDef; 19 | LuaInterface* lua; 20 | Vec2 pos; 21 | std::string name; 22 | b2Body* body; 23 | 24 | Node(); 25 | ~Node(); 26 | 27 | void update(float dt); //Update the node 28 | void collided(Object* o); //Collided with an object 29 | void init(); //Create stuff in lua for this object 30 | 31 | void setProperty(const std::string& prop, const std::string& value) {propertyValues[prop] = value;}; 32 | void addProperty(const std::string& prop, const std::string& value) {setProperty(prop, value);}; 33 | std::string getProperty(const std::string prop) {if(propertyValues.count(prop)) return propertyValues[prop]; return "";}; 34 | }; 35 | 36 | -------------------------------------------------------------------------------- /engine/ObjSegment.h: -------------------------------------------------------------------------------- 1 | /* 2 | RetSphinxEngine header - ObjSegment.h 3 | Copyright (c) 2017 Mark Hutcheson 4 | */ 5 | #pragma once 6 | 7 | #include "Rect.h" 8 | #include "Color.h" 9 | #include "RenderState.h" 10 | #include "LuaFuncs.h" 11 | 12 | class Object; 13 | class b2Body; 14 | class Image; 15 | class Object3D; 16 | 17 | //Physical segments of objects - be they actual physics bodies or just images 18 | class ObjSegment 19 | { 20 | public: 21 | enum { TYPE = OT_SEGMENT }; 22 | 23 | b2Body* body; //Physics body associated with this segment 24 | Object* parent; //Parent object 25 | Object3D* obj3D; //3D object 26 | 27 | Vec2 pos; //Offset (after rotation) 28 | Vec2 tile; //tile image in x and y 29 | float rot; 30 | Vec2 size; //Actual texel size; not pixels 31 | float depth; 32 | Image* img; 33 | bool active; 34 | Color col; //TODO: Implement or remove 35 | 36 | ObjSegment(); 37 | ~ObjSegment(); 38 | 39 | void draw(RenderState renderState); 40 | }; 41 | -------------------------------------------------------------------------------- /engine/Object.h: -------------------------------------------------------------------------------- 1 | /* 2 | GameEngine header - Object.h 3 | Copyright (c) 2014 Mark Hutcheson 4 | */ 5 | #pragma once 6 | 7 | #include "Object3D.h" 8 | #include "LuaInterface.h" 9 | #include "LuaFuncs.h" 10 | #include "Rect.h" 11 | #include "Color.h" 12 | #include "RenderState.h" 13 | #include 14 | #include 15 | #include 16 | 17 | class ObjSegment; 18 | class b2Body; 19 | class Image; 20 | 21 | //Collections of the above all stuffed into one object for ease of use. 22 | class Object 23 | { 24 | LuaObjGlue* glueObj; 25 | std::map propertyValues; 26 | std::vector segments; 27 | 28 | public: 29 | enum { TYPE = OT_OBJECT }; 30 | 31 | Vec2 meshSize; 32 | LuaInterface* lua; 33 | std::string luaClass; 34 | std::string luaDef; 35 | float depth; 36 | Image* img; 37 | bool active; 38 | bool alive; 39 | Color col; 40 | 41 | Object(); 42 | ~Object(); 43 | 44 | void draw(RenderState renderState); 45 | void addSegment(ObjSegment* seg); 46 | ObjSegment* getSegment(unsigned int idx); 47 | void update(float dt); 48 | b2Body* getBody(); 49 | Vec2 getPos(); 50 | std::string getLuaClass() {return luaClass;} 51 | void collide(Object* other, float impulse); 52 | void collideWall(Vec2 ptNormal, float impulse); //ptNormal will be a normal vector from the wall to this object 53 | void initLua(); 54 | void setPosition(Vec2 p); //Best to call this not on object creation, but only when needed (makes box2d unhappy if done too much) 55 | 56 | void setProperty(const std::string& prop, const std::string& value) {propertyValues[prop] = value;}; 57 | std::string getProperty(const std::string& prop) {if(propertyValues.count(prop)) return propertyValues[prop]; return "";}; 58 | 59 | void setImage(Image* img, unsigned int seg = 0); //Sets the image of the given physSegment 60 | }; 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /engine/Object3D.h: -------------------------------------------------------------------------------- 1 | /* 2 | RetSphinxEngine source - Object3D.h 3 | Copyright (c) 2013 Mark Hutcheson 4 | */ 5 | #pragma once 6 | #include 7 | #include "RenderState.h" 8 | #include 9 | 10 | class Image; 11 | 12 | class Object3D 13 | { 14 | protected: 15 | uint32_t num; 16 | unsigned int m_tex; 17 | unsigned int vertBuf; 18 | unsigned int vertArray; 19 | 20 | void _fromData(unsigned char* data, Image* tex); 21 | 22 | Object3D() {}; 23 | 24 | public: 25 | Object3D(unsigned char* data, Image* tex); 26 | ~Object3D(); 27 | 28 | void render(RenderState renderState); 29 | }; 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /engine/OpenGLShader.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "SDL_opengl.h" 3 | 4 | namespace OpenGLShader 5 | { 6 | GLuint loadShaders(const char * vertex_file_path, const char * fragment_file_path); 7 | } -------------------------------------------------------------------------------- /engine/PointQueryCallback.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Box2D/Box2D.h" 4 | #include 5 | 6 | //----------------------------------------------------- 7 | // Callback helper class for finding objects 8 | //----------------------------------------------------- 9 | class PointQueryCallback : public b2QueryCallback 10 | { 11 | public: 12 | std::vector foundBodies; 13 | 14 | bool ReportFixture(b2Fixture* fixture) 15 | { 16 | foundBodies.push_back(fixture->GetBody()); 17 | return true; 18 | } 19 | }; 20 | -------------------------------------------------------------------------------- /engine/Quad.cpp: -------------------------------------------------------------------------------- 1 | #include "Quad.h" 2 | #include "SDL_opengl.h" 3 | 4 | namespace Draw 5 | { 6 | void drawQuad(Quad* q) 7 | { 8 | // tell opengl to use the generated texture 9 | glBindTexture(GL_TEXTURE_2D, q->tex.tex.tex); 10 | glVertexPointer(2, GL_FLOAT, 0, q->pos); 11 | glTexCoordPointer(2, GL_FLOAT, 0, q->tex.uv); 12 | glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); 13 | } 14 | } -------------------------------------------------------------------------------- /engine/Quad.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class Texture 4 | { 5 | public: 6 | unsigned int tex; 7 | unsigned int width; 8 | unsigned int height; 9 | }; 10 | 11 | class Image 12 | { 13 | public: 14 | Texture tex; 15 | float uv[8]; 16 | }; 17 | 18 | class Quad 19 | { 20 | public: 21 | Image tex; 22 | float pos[8]; 23 | }; 24 | 25 | namespace Draw 26 | { 27 | void drawQuad(Quad* q); //Yeeeeaaaaaaah 28 | } 29 | -------------------------------------------------------------------------------- /engine/Random.cpp: -------------------------------------------------------------------------------- 1 | #include "Random.h" 2 | #include "mtrand.h" 3 | 4 | static MTRand_int32 irand; 5 | static MTRand_closed drand; 6 | 7 | int Random::random() 8 | { 9 | return irand(); 10 | } 11 | 12 | int Random::random(int min, int max) 13 | { 14 | if(min == max) return min; 15 | if(min > max) 16 | { 17 | int temp = min; 18 | min = max; 19 | max = temp; 20 | } 21 | int diff = max - min + 1; 22 | return(irand() % diff + min); 23 | } 24 | 25 | int Random::random(int max) 26 | { 27 | return random(0, max); 28 | } 29 | 30 | float Random::randomFloat() 31 | { 32 | return (float)drand(); 33 | } 34 | 35 | float Random::randomFloat(float min, float max) 36 | { 37 | if(min == max) return min; 38 | if(min > max) 39 | { 40 | float temp = min; 41 | min = max; 42 | max = temp; 43 | } 44 | return (float)(drand() * (max - min) + min); 45 | } 46 | 47 | float Random::randomFloat(float max) 48 | { 49 | return randomFloat(0.0f, max); 50 | } 51 | 52 | void Random::seed(unsigned long seed) 53 | { 54 | irand.seed(seed); 55 | drand.seed(seed); 56 | } 57 | -------------------------------------------------------------------------------- /engine/Random.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | class Random 3 | { 4 | //Don't allow instantiations 5 | Random() {}; 6 | ~Random() {}; 7 | public: 8 | static int random(); 9 | static int random(int min, int max); 10 | static int random(int max); //Between 0 and max 11 | static float randomFloat(); //Between 0 and 1 12 | static float randomFloat(float min, float max); 13 | static float randomFloat(float max); //Between 0 and max 14 | static void seed(unsigned long seed); 15 | }; 16 | 17 | -------------------------------------------------------------------------------- /engine/Rect.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "glmx.h" 3 | #include 4 | 5 | //------------------------------------------------------ 6 | // Other helpful things 7 | //------------------------------------------------------ 8 | typedef glm::vec2 Vec2; 9 | typedef glm::vec3 Vec3; 10 | 11 | //TODO: move somewhere where it makes sense 12 | Vec2 pointFromString(const std::string& s); 13 | std::string pointToString(Vec2 pt); 14 | Vec3 vec3FromString(const std::string& s); 15 | std::string vec3ToString(Vec3 vec); 16 | 17 | //------------------------------------------------------ 18 | // Rect class 19 | //------------------------------------------------------ 20 | class Rect 21 | { 22 | public: 23 | float left, top, right, bottom; 24 | 25 | Rect(); 26 | Rect(float l, float t, float r, float b); 27 | 28 | //Helper accessor methods 29 | float width(); 30 | float height(); 31 | float area(); 32 | Vec2 center(); 33 | void center(float* x, float* y); 34 | 35 | //Transform methods 36 | void offset(float x, float y); 37 | void offset(Vec2 pt); 38 | void scale(float fScale); 39 | void scale(float fScalex, float fScaley); 40 | void centerOn(Vec2 p); 41 | 42 | //Test method 43 | bool inside(Vec2 p); 44 | 45 | //Setter methods 46 | void fromString(const std::string& s); //Get a rectangle from comma-separated values in a string 47 | std::string toString(); 48 | void set(float fleft, float ftop, float fright, float fbottom); 49 | }; 50 | -------------------------------------------------------------------------------- /engine/RenderState.cpp: -------------------------------------------------------------------------------- 1 | #include "RenderState.h" 2 | #include "opengl-api.h" 3 | 4 | void RenderState::apply() const 5 | { 6 | glUniformMatrix4fv(modelId, 1, false, &model[0][0]); 7 | glUniformMatrix4fv(viewId, 1, false, &view[0][0]); 8 | glUniformMatrix4fv(projectionId, 1, false, &projection[0][0]); 9 | } 10 | -------------------------------------------------------------------------------- /engine/RenderState.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "glmx.h" 3 | 4 | class RenderState 5 | { 6 | public: 7 | unsigned int programId; 8 | glm::mat4 model; 9 | glm::mat4 view; 10 | glm::mat4 projection; 11 | unsigned int modelId; 12 | unsigned int viewId; 13 | unsigned int projectionId; 14 | 15 | void apply() const; 16 | }; 17 | -------------------------------------------------------------------------------- /engine/ResourceCache.cpp: -------------------------------------------------------------------------------- 1 | #include "ResourceCache.h" 2 | #include "Object3D.h" 3 | #include "ImgFont.h" 4 | #include 5 | 6 | ResourceCache::~ResourceCache() 7 | { 8 | clear(); 9 | } 10 | 11 | void ResourceCache::add(uint64_t id, void* item) 12 | { 13 | map[id] = item; 14 | } 15 | 16 | void* ResourceCache::find(uint64_t id) 17 | { 18 | std::map::iterator i = map.find(id); 19 | if(i == map.end()) //This image isn't here 20 | return NULL; 21 | return i->second; 22 | } 23 | 24 | void ResourceCache::clear() 25 | { 26 | for(std::map::iterator i = map.begin(); i != map.end(); i++) 27 | free(i->second); 28 | map.clear(); 29 | } 30 | -------------------------------------------------------------------------------- /engine/ResourceCache.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | //TODO: Move this inside ResourceLoader or something, since this is just a map 7 | class ResourceCache 8 | { 9 | std::map map; 10 | 11 | public: 12 | ~ResourceCache(); 13 | 14 | void* find(uint64_t id); 15 | void add(uint64_t id, void* item); 16 | 17 | void clear(); 18 | }; 19 | -------------------------------------------------------------------------------- /engine/ResourceLoader.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include "tinyxml2.h" 6 | #include "Box2D/Box2D.h" 7 | #include "Rect.h" 8 | #include "SDL.h" 9 | #include "ResourceTypes.h" 10 | 11 | class Object; 12 | class ParticleSystem; 13 | class ObjSegment; 14 | class ResourceCache; 15 | class Object3D; 16 | class PakLoader; 17 | class ImgFont; 18 | class Stringbank; 19 | class Image; 20 | class Texture; 21 | class LuaInterface; 22 | 23 | class ResourceLoader 24 | { 25 | b2World* m_world; 26 | ResourceCache* m_cache; 27 | PakLoader* m_pakLoader; 28 | std::string m_sPakDir; 29 | 30 | std::string readTextFile(const std::string& filename); 31 | Image* loadImageFromFile(const std::string& filename); 32 | Image* loadImageFromData(unsigned char* data, unsigned int len); 33 | Texture* bindTexture(unsigned char* data, unsigned int width, unsigned int height, int mode, int len); 34 | Texture* getAtlas(uint64_t atlasId); 35 | 36 | ResourceLoader() {}; 37 | public: 38 | ResourceLoader(b2World* physicsWorld, const std::string& sPakDir); 39 | ~ResourceLoader(); 40 | 41 | //Utility 42 | void clearCache(); 43 | 44 | //Images 45 | Image* getImage(const std::string& sID); 46 | Image* getImage(uint64_t hashID); 47 | SDL_Surface* getSDLImage(const std::string& sID); 48 | 49 | //Meshes 50 | Object3D* get3dObject(const std::string& sID); 51 | 52 | //Particles 53 | ParticleSystem* getParticleSystem(const std::string& sID); 54 | 55 | //Mouse cursors 56 | SDL_Cursor* getCursor(const std::string& sID); 57 | 58 | //Fonts 59 | ImgFont* getFont(const std::string& sID); 60 | 61 | //Text 62 | Stringbank* getStringbank(const std::string& sID); 63 | std::string getTextFile(const std::string& sID); //Read a whole text file into one string 64 | 65 | //Objects 66 | Object* getObject(const std::string& sType, Vec2 ptOffset, Vec2 ptVel, LuaInterface* lua); 67 | ObjSegment* getObjectSegment(tinyxml2::XMLElement* layer); 68 | b2Fixture* getObjectFixture(tinyxml2::XMLElement* fixture, b2Body* bod); 69 | 70 | //Sounds 71 | unsigned char* getSound(const std::string& sID, unsigned int* length); // Raw data since we load with FMOD 72 | SoundLoop* getSoundLoop(const std::string& sID); 73 | }; 74 | -------------------------------------------------------------------------------- /engine/SoundVol.cpp: -------------------------------------------------------------------------------- 1 | #include "SoundVol.h" 2 | 3 | SoundVol::SoundVol(FMOD::Channel* s, float d) 4 | { 5 | cur = 1.0f; 6 | sfx = s; 7 | dest = d; 8 | sfx->getVolume(&cur); 9 | } 10 | 11 | bool SoundVol::update() 12 | { 13 | sfx->setVolume(cur); 14 | if(cur == dest) 15 | { 16 | if(dest == 0.0f) 17 | sfx->stop(); 18 | return true; 19 | } 20 | return false; 21 | } 22 | -------------------------------------------------------------------------------- /engine/SoundVol.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "fmod.hpp" 3 | 4 | class SoundVol 5 | { 6 | float dest; 7 | float cur; 8 | FMOD::Channel* sfx; 9 | 10 | SoundVol() {}; 11 | public: 12 | 13 | SoundVol(FMOD::Channel* s, float d); //Fade sound to d volume 14 | 15 | bool update(); 16 | 17 | float* getCur() { return &cur; } 18 | }; -------------------------------------------------------------------------------- /engine/SystemUtils.cpp: -------------------------------------------------------------------------------- 1 | #include "SystemUtils.h" 2 | #ifdef _WIN32 3 | #include 4 | #define BUFFER_SIZE 100 5 | #else 6 | #warning TODO Get locale in UNIX/POSIX using those functions 7 | #endif 8 | 9 | //See OSFunctions.cpp in Aquaria for inspiration 10 | 11 | namespace SystemUtils 12 | { 13 | std::string getCurLocale() 14 | { 15 | #ifdef _WIN32 16 | WCHAR wcBuffer[BUFFER_SIZE]; 17 | 18 | //NOTE: Breaks pre-Vista compat 19 | int iResult = GetLocaleInfoEx( 20 | LOCALE_NAME_USER_DEFAULT, 21 | LOCALE_SNAME, 22 | wcBuffer, 23 | BUFFER_SIZE 24 | ); 25 | 26 | if(iResult > 0) 27 | { 28 | char* cBuf = (char*)malloc(BUFFER_SIZE); 29 | //Wandows is stupid and wants wide strings, but locale strings should always be ASCII, so convert 30 | for(int i = 0; i <= lstrlenW(wcBuffer); i++) 31 | { 32 | cBuf[i] = (char)wcBuffer[i]; 33 | } 34 | 35 | char *firstDash = strchr(cBuf, '-'); 36 | if(firstDash != NULL) 37 | *firstDash = '\0'; 38 | 39 | std::string s(cBuf); 40 | free(cBuf); 41 | return s; 42 | } 43 | 44 | #endif 45 | return std::string(""); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /engine/SystemUtils.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace SystemUtils 5 | { 6 | std::string getCurLocale(); //Returns current system locale. 7 | } -------------------------------------------------------------------------------- /engine/Text.h: -------------------------------------------------------------------------------- 1 | /* 2 | GameEngine header - Text.h 3 | Class for ease of drawing bitmapped fonts 4 | Copyright (c) 2014 Mark Hutcheson 5 | */ 6 | #pragma once 7 | 8 | //#include "Image.h" 9 | #include "Color.h" 10 | #include "Rect.h" 11 | #include 12 | 13 | class Image; 14 | 15 | enum TextAlignment 16 | { 17 | ALIGN_LEFT = 1, 18 | ALIGN_RIGHT = 2, 19 | ALIGN_CENTER = 4, 20 | ALIGN_TOP = 8, 21 | ALIGN_MIDDLE = 16, 22 | ALIGN_BOTTOM = 32 23 | }; 24 | 25 | //class Image; 26 | 27 | class Text 28 | { 29 | private: 30 | Text(){}; //Default constructor cannot be called 31 | Image* m_imgFont; //Image for this bitmap font 32 | std::map m_mRectangles; //Rectangles for drawing each character 33 | std::map m_mKerning; //Kerning info for font glyphs 34 | std::string m_sName; 35 | 36 | public: 37 | Color col; 38 | 39 | Text(const std::string& sXMLFilename); //Create the font from this XML file 40 | ~Text(); 41 | 42 | //Render this text to the screen, centered on x and y 43 | void render(const std::string& sText, float x, float y, float pt); 44 | 45 | //Find the size of a given string of text 46 | float size(const std::string& sText, float pt); 47 | std::string getName() {return m_sName;}; 48 | void setName(const std::string& sName) {m_sName = sName;}; 49 | 50 | }; 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /engine/actions/Action.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | //Enum for different actions the player can perform 4 | typedef enum 5 | { 6 | JUMP, 7 | RUN, 8 | SHIP_THRUST, 9 | EXAMINE, 10 | ATTACK, 11 | NOTE_UP, 12 | NOTE_DOWN, 13 | NOTE_LEFT, 14 | NOTE_RIGHT, 15 | 16 | NUM_ACTIONS //Not an action, an array size 17 | } Action; 18 | -------------------------------------------------------------------------------- /engine/actions/ActionBind.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class InputDevice; 4 | 5 | class ActionBind 6 | { 7 | public: 8 | //Get an action true/false 9 | virtual bool getDigitalAction(InputDevice* d) = 0; 10 | 11 | //Get a normalized 0..1 for this action 12 | virtual float getAnalogAction(InputDevice* d) = 0; 13 | 14 | }; 15 | -------------------------------------------------------------------------------- /engine/actions/AxisAction.cpp: -------------------------------------------------------------------------------- 1 | #include "AxisAction.h" 2 | #include "InputDevice.h" 3 | #include // std::min 4 | 5 | //Defined by SDL 6 | #define JOY_AXIS_MAX 32767.0f //Technically 32768 on the negative axis but who's counting 7 | 8 | AxisAction::AxisAction(int axisToUse, int trip) 9 | { 10 | joyAxisTrip = trip; 11 | axis = axisToUse; 12 | } 13 | 14 | bool AxisAction::getDigitalAction(InputDevice* d) 15 | { 16 | return (abs(d->getAxis(axis)) > joyAxisTrip); 17 | } 18 | 19 | float AxisAction::getAnalogAction(InputDevice* d) 20 | { 21 | int val = d->getAxis(axis); 22 | if(abs(val) < joyAxisTrip) 23 | return 0.0f; 24 | return std::max(std::min(val / JOY_AXIS_MAX, 1.0f), -1.0f); 25 | } 26 | -------------------------------------------------------------------------------- /engine/actions/AxisAction.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ActionBind.h" 3 | 4 | class InputDevice; 5 | 6 | class AxisAction : public ActionBind 7 | { 8 | private: 9 | int joyAxisTrip; 10 | int axis; 11 | 12 | AxisAction() {}; 13 | public: 14 | AxisAction(int axisToUse, int trip); 15 | 16 | bool getDigitalAction(InputDevice* d); 17 | float getAnalogAction(InputDevice* d); 18 | }; -------------------------------------------------------------------------------- /engine/actions/CombinedAction.cpp: -------------------------------------------------------------------------------- 1 | #include "CombinedAction.h" 2 | 3 | CombinedAction::CombinedAction(ActionBind * a1, ActionBind * a2) 4 | { 5 | action1 = a1; 6 | action2 = a2; 7 | } 8 | 9 | CombinedAction::~CombinedAction() 10 | { 11 | delete action1; 12 | delete action2; 13 | } 14 | 15 | bool CombinedAction::getDigitalAction(InputDevice * d) 16 | { 17 | return (action1->getDigitalAction(d) || action2->getDigitalAction(d)); 18 | } 19 | 20 | float CombinedAction::getAnalogAction(InputDevice * d) 21 | { 22 | float res = action1->getAnalogAction(d); 23 | if(res == 0.0) 24 | return action2->getAnalogAction(d); 25 | return res; 26 | } 27 | -------------------------------------------------------------------------------- /engine/actions/CombinedAction.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ActionBind.h" 3 | 4 | //Class for unbound actions 5 | class CombinedAction : public ActionBind 6 | { 7 | private: 8 | ActionBind* action1; 9 | ActionBind* action2; 10 | CombinedAction() {}; 11 | 12 | public: 13 | CombinedAction(ActionBind* a1, ActionBind* a2); 14 | ~CombinedAction(); 15 | bool getDigitalAction(InputDevice* d); 16 | float getAnalogAction(InputDevice* d); 17 | }; 18 | -------------------------------------------------------------------------------- /engine/actions/DpadMovement.cpp: -------------------------------------------------------------------------------- 1 | #include "DpadMovement.h" 2 | #include "InputDevice.h" 3 | 4 | DpadMovement::DpadMovement(int l, int r, int u, int d) 5 | { 6 | up = u; 7 | down = d; 8 | left = l; 9 | right = r; 10 | } 11 | 12 | Vec2 DpadMovement::getMovement(InputDevice* d) 13 | { 14 | Vec2 v(0.0f, 0.0f); 15 | 16 | if(d->getButton(up)) 17 | v.y += 1.0f; 18 | if(d->getButton(down)) 19 | v.y -= 1.0f; 20 | if(d->getButton(right)) 21 | v.x += 1.0f; 22 | if(d->getButton(left)) 23 | v.x -= 1.0f; 24 | 25 | return v; 26 | } 27 | -------------------------------------------------------------------------------- /engine/actions/DpadMovement.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "MovementBind.h" 3 | 4 | class DpadMovement : public MovementBind 5 | { 6 | private: 7 | int up, down, left, right; 8 | 9 | DpadMovement() {}; 10 | 11 | public: 12 | DpadMovement(int left, int right, int up, int down); 13 | 14 | Vec2 getMovement(InputDevice* d); 15 | 16 | }; -------------------------------------------------------------------------------- /engine/actions/JoyButtonAction.cpp: -------------------------------------------------------------------------------- 1 | #include "JoyButtonAction.h" 2 | #include "InputDevice.h" 3 | 4 | JoyButtonAction::JoyButtonAction(int buttonIndex) 5 | { 6 | button = buttonIndex; 7 | } 8 | 9 | bool JoyButtonAction::getDigitalAction(InputDevice* d) 10 | { 11 | return d->getButton(button); 12 | } 13 | 14 | float JoyButtonAction::getAnalogAction(InputDevice* d) 15 | { 16 | if(getDigitalAction(d)) 17 | return 1.0f; 18 | return 0.0f; 19 | } 20 | -------------------------------------------------------------------------------- /engine/actions/JoyButtonAction.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ActionBind.h" 3 | #include "SDL_gamecontroller.h" 4 | 5 | class JoyButtonAction : public ActionBind 6 | { 7 | private: 8 | int button; 9 | 10 | JoyButtonAction() {}; 11 | 12 | public: 13 | JoyButtonAction(int buttonIndex); 14 | 15 | bool getDigitalAction(InputDevice* d); 16 | float getAnalogAction(InputDevice* d); 17 | }; -------------------------------------------------------------------------------- /engine/actions/JoystickMovement.cpp: -------------------------------------------------------------------------------- 1 | #include "JoystickMovement.h" 2 | #include "InputDevice.h" 3 | #include // std::min 4 | 5 | #define JOY_AXIS_MAX 32767.0f 6 | 7 | JoystickMovement::JoystickMovement(int x, int y, float trip) 8 | { 9 | xAxis = x; 10 | yAxis = y; 11 | joyAxisTrip = trip; 12 | } 13 | 14 | Vec2 JoystickMovement::getMovement(InputDevice* d) 15 | { 16 | int x = d->getAxis(xAxis); 17 | int y = -d->getAxis(yAxis); //Flip y so -y = down 18 | if(abs(x) < joyAxisTrip && abs(y) < joyAxisTrip) 19 | return Vec2(0.0f, 0.0f); 20 | 21 | //Slightly complex math here so that right outside of dead zone will be 0.0f, rather than stick center being 0.0f 22 | const float trip = joyAxisTrip / JOY_AXIS_MAX; //Dead zone size, in 0.0-1.0f range 23 | float xf = std::max(std::min(x / JOY_AXIS_MAX, 1.0f), -1.0f); //Current stick pos in 0.0-1.0f range 24 | float yf = std::max(std::min(y / JOY_AXIS_MAX, 1.0f), -1.0f); 25 | 26 | float angle = atan2(yf, xf); //Angle of stick movement 27 | Vec2 tripPt(cos(angle)*trip, sin(angle)*trip); //Point on trip circle 28 | 29 | Vec2 ret(xf, yf); //Actual joystick pos 30 | ret -= tripPt; //Distance from trip point 31 | ret /= 1.0f - trip; //Scale according to maximum 32 | 33 | return ret; 34 | } 35 | -------------------------------------------------------------------------------- /engine/actions/JoystickMovement.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "MovementBind.h" 3 | #include "SDL_gamecontroller.h" 4 | 5 | class JoystickMovement : public MovementBind 6 | { 7 | private: 8 | int xAxis, yAxis; 9 | float joyAxisTrip; 10 | 11 | JoystickMovement() {}; 12 | 13 | public: 14 | JoystickMovement(int xAxis, int yAxis, float trip); 15 | 16 | Vec2 getMovement(InputDevice* d); 17 | }; 18 | -------------------------------------------------------------------------------- /engine/actions/KeyboardAction.cpp: -------------------------------------------------------------------------------- 1 | #include "KeyboardAction.h" 2 | #include "SDL_keyboard.h" 3 | 4 | KeyboardAction::KeyboardAction(int keyToUse) 5 | { 6 | key = keyToUse; 7 | keystates = SDL_GetKeyboardState(NULL); 8 | } 9 | 10 | bool KeyboardAction::getDigitalAction(InputDevice* d) 11 | { 12 | return !!(keystates[key]); 13 | } 14 | 15 | float KeyboardAction::getAnalogAction(InputDevice* d) 16 | { 17 | if(getDigitalAction(d)) 18 | return 1.0f; 19 | return 0.0f; 20 | } 21 | -------------------------------------------------------------------------------- /engine/actions/KeyboardAction.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ActionBind.h" 3 | #include "SDL_scancode.h" 4 | 5 | class KeyboardAction : public ActionBind 6 | { 7 | private: 8 | int key; 9 | const Uint8* keystates; 10 | KeyboardAction() {}; 11 | 12 | public: 13 | KeyboardAction(int keyToUse); 14 | 15 | bool getDigitalAction(InputDevice* d); 16 | float getAnalogAction(InputDevice* d); 17 | }; -------------------------------------------------------------------------------- /engine/actions/KeyboardMovement.cpp: -------------------------------------------------------------------------------- 1 | #include "KeyboardMovement.h" 2 | #include "SDL_keyboard.h" 3 | 4 | KeyboardMovement::KeyboardMovement(int l, int r, int u, int d) 5 | { 6 | left = l; 7 | right = r; 8 | up = u; 9 | down = d; 10 | keystates = SDL_GetKeyboardState(NULL); 11 | } 12 | 13 | Vec2 KeyboardMovement::getMovement(InputDevice* d) 14 | { 15 | Vec2 v(0.0f, 0.0f); 16 | 17 | if(keystates[up]) 18 | v.y += 1.0f; 19 | if(keystates[down]) 20 | v.y -= 1.0f; 21 | if(keystates[right]) 22 | v.x += 1.0f; 23 | if(keystates[left]) 24 | v.x -= 1.0f; 25 | 26 | return v; 27 | } 28 | -------------------------------------------------------------------------------- /engine/actions/KeyboardMovement.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "MovementBind.h" 3 | #include "SDL_scancode.h" 4 | 5 | class KeyboardMovement : public MovementBind 6 | { 7 | private: 8 | int left, right, up, down; 9 | const Uint8* keystates; 10 | 11 | public: 12 | KeyboardMovement(int left, int right, int up, int down); 13 | 14 | Vec2 getMovement(InputDevice* d); 15 | }; 16 | -------------------------------------------------------------------------------- /engine/actions/MouseButtonAction.cpp: -------------------------------------------------------------------------------- 1 | #include "MouseButtonAction.h" 2 | #include "SDL_mouse.h" 3 | 4 | MouseButtonAction::MouseButtonAction(int b) 5 | { 6 | button = b; 7 | } 8 | 9 | bool MouseButtonAction::getDigitalAction(InputDevice* d) 10 | { 11 | return !!(SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(button)); 12 | } 13 | 14 | float MouseButtonAction::getAnalogAction(InputDevice* d) 15 | { 16 | if(getDigitalAction(d)) 17 | return 1.0f; 18 | return 0.0f; 19 | } 20 | -------------------------------------------------------------------------------- /engine/actions/MouseButtonAction.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ActionBind.h" 3 | 4 | class MouseButtonAction : public ActionBind 5 | { 6 | private: 7 | int button; 8 | MouseButtonAction() {}; 9 | 10 | public: 11 | MouseButtonAction(int button); 12 | 13 | bool getDigitalAction(InputDevice* d); 14 | float getAnalogAction(InputDevice* d); 15 | }; -------------------------------------------------------------------------------- /engine/actions/Movement.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | typedef enum 4 | { 5 | MOVE, 6 | AIM, 7 | PAN, 8 | NUM_MOVEMENTS 9 | } Movement; -------------------------------------------------------------------------------- /engine/actions/MovementBind.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Rect.h" 3 | 4 | class InputDevice; 5 | 6 | class MovementBind 7 | { 8 | public: 9 | virtual Vec2 getMovement(InputDevice* d) = 0; 10 | }; 11 | -------------------------------------------------------------------------------- /engine/actions/NoAction.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ActionBind.h" 3 | 4 | //Class for unbound actions 5 | class NoAction : public ActionBind 6 | { 7 | public: 8 | bool getDigitalAction(InputDevice* d) { return false; } 9 | float getAnalogAction(InputDevice* d) { return 0.0f; } 10 | }; 11 | -------------------------------------------------------------------------------- /engine/actions/NoMovement.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "MovementBind.h" 3 | 4 | //Class for unbound movements 5 | class NoMovement : public MovementBind 6 | { 7 | public: 8 | Vec2 getMovement(InputDevice* d) { return Vec2(); } 9 | }; 10 | -------------------------------------------------------------------------------- /engine/events/Observer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "Rect.h" 4 | 5 | 6 | class Observer 7 | { 8 | public: 9 | virtual void onNotify(const std::string& sMsg, Vec2 pos) = 0; 10 | }; -------------------------------------------------------------------------------- /engine/events/Subject.cpp: -------------------------------------------------------------------------------- 1 | #include "Subject.h" 2 | 3 | void Subject::addObserver(Observer * o) 4 | { 5 | observers.push_back(o); 6 | } 7 | 8 | void Subject::removeObserver(Observer * o) 9 | { 10 | for(std::vector::iterator i = observers.begin(); i != observers.end(); i++) 11 | { 12 | if(*i == o) 13 | { 14 | observers.erase(i); 15 | return; 16 | } 17 | } 18 | } 19 | 20 | void Subject::notify(const std::string& sMsg, Vec2 pos) 21 | { 22 | for(std::vector::iterator i = observers.begin(); i != observers.end(); i++) 23 | (*i)->onNotify(sMsg, pos); 24 | } 25 | -------------------------------------------------------------------------------- /engine/events/Subject.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Observer.h" 3 | #include 4 | 5 | class Subject 6 | { 7 | std::vector observers; 8 | int numObservers; 9 | 10 | public: 11 | 12 | void addObserver(Observer* o); 13 | void removeObserver(Observer* o); 14 | 15 | void notify(const std::string& sMsg, Vec2 pos); 16 | 17 | }; -------------------------------------------------------------------------------- /engine/imgui_impl_sdl.h: -------------------------------------------------------------------------------- 1 | // ImGui SDL2 binding with OpenGL 2 | // You can copy and use unmodified imgui_impl_* files in your project. 3 | // If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown(). 4 | // See main.cpp for an example of using this. 5 | // https://github.com/ocornut/imgui 6 | #pragma once 7 | 8 | struct SDL_Window; 9 | typedef union SDL_Event SDL_Event; 10 | 11 | IMGUI_API bool ImGui_ImplSdl_Init(SDL_Window *window, const char* cIniFile); 12 | IMGUI_API void ImGui_ImplSdl_NewFrame(SDL_Window *window); 13 | IMGUI_API bool ImGui_ImplSdl_ProcessEvent(SDL_Event* event); 14 | 15 | /*IMGUI_API void ImGui_Impl_GL2_Shutdown(); 16 | IMGUI_API void ImGui_Impl_GL2_InvalidateDeviceObjects(); 17 | IMGUI_API bool ImGui_Impl_GL2_CreateDeviceObjects(); 18 | IMGUI_API void ImGui_Impl_GL2_RenderDrawLists(ImDrawData*);*/ 19 | 20 | IMGUI_API void ImGui_Impl_GL3_Shutdown(); 21 | IMGUI_API void ImGui_Impl_GL3_InvalidateDeviceObjects(); 22 | IMGUI_API bool ImGui_Impl_GL3_CreateDeviceObjects(); 23 | IMGUI_API void ImGui_Impl_GL3_RenderDrawLists(ImDrawData*); 24 | 25 | IMGUI_API void ImGui_Impl_GL3_DeleteContext(const void *ctx); 26 | IMGUI_API void ImGui_Impl_GL3_SwitchContext(const void *ctx); 27 | 28 | 29 | extern unsigned g_imgui_FontTexture; 30 | -------------------------------------------------------------------------------- /engine/managers/EntityManager.cpp: -------------------------------------------------------------------------------- 1 | #include "EntityManager.h" 2 | #include "ParticleSystemManager.h" 3 | #include "ResourceLoader.h" 4 | #include "NodeManager.h" 5 | #include "Object.h" 6 | #include "ObjectManager.h" 7 | #include "SceneryManager.h" 8 | 9 | EntityManager::EntityManager(ResourceLoader* resourceLoader, b2World* world) 10 | { 11 | particleSystemManager = new ParticleSystemManager(resourceLoader); 12 | nodeManager = new NodeManager(world); 13 | objectManager = new ObjectManager(world); 14 | sceneryManager = new SceneryManager(); 15 | } 16 | 17 | EntityManager::~EntityManager() 18 | { 19 | delete particleSystemManager; 20 | delete nodeManager; 21 | delete objectManager; 22 | delete sceneryManager; 23 | } 24 | 25 | //General methods 26 | void EntityManager::update(float dt) 27 | { 28 | particleSystemManager->update(dt); 29 | nodeManager->update(dt); 30 | objectManager->update(dt); 31 | sceneryManager->update(dt); 32 | } 33 | 34 | void EntityManager::render(const RenderState& renderState) 35 | { 36 | sceneryManager->renderBackground(renderState); 37 | objectManager->render(renderState); 38 | particleSystemManager->render(renderState); 39 | sceneryManager->renderForeground(renderState); 40 | } 41 | 42 | void EntityManager::cleanup() 43 | { 44 | particleSystemManager->cleanup(); 45 | nodeManager->cleanup(); 46 | objectManager->cleanup(); 47 | sceneryManager->cleanup(); 48 | } 49 | 50 | //Particle systems 51 | void EntityManager::add(ParticleSystem * pSys) 52 | { 53 | particleSystemManager->add(pSys); 54 | } 55 | 56 | //Nodes 57 | void EntityManager::add(Node * n) 58 | { 59 | nodeManager->add(n); 60 | } 61 | 62 | Node* EntityManager::getNode(Vec2 pos) 63 | { 64 | return nodeManager->getNode(pos); 65 | } 66 | 67 | Node* EntityManager::getNodeUnder(Vec2 pos) 68 | { 69 | return nodeManager->getNodeUnder(pos); 70 | } 71 | 72 | Node* EntityManager::getNode(const std::string& sNodeName) 73 | { 74 | return nodeManager->getNode(sNodeName); 75 | } 76 | 77 | //Objects 78 | void EntityManager::add(Object * o) 79 | { 80 | objectManager->add(o); 81 | } 82 | 83 | Object* EntityManager::getObject(Vec2 p) 84 | { 85 | return objectManager->getAt(p); 86 | } 87 | 88 | Object* EntityManager::getClosestObject(Vec2 p) 89 | { 90 | return objectManager->getClosest(p); 91 | } 92 | 93 | //Scenery 94 | void EntityManager::add(ObjSegment * o) 95 | { 96 | sceneryManager->add(o); 97 | } 98 | 99 | -------------------------------------------------------------------------------- /engine/managers/EntityManager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "glmx.h" 3 | #include 4 | #include "Rect.h" 5 | #include "RenderState.h" 6 | 7 | class ParticleSystemManager; 8 | class ResourceLoader; 9 | class ParticleSystem; 10 | class NodeManager; 11 | class Node; 12 | class ObjectManager; 13 | class Object; 14 | class ObjSegment; 15 | class b2World; 16 | class SceneryManager; 17 | 18 | class EntityManager 19 | { 20 | ParticleSystemManager* particleSystemManager; 21 | NodeManager* nodeManager; 22 | ObjectManager* objectManager; 23 | SceneryManager* sceneryManager; 24 | 25 | public: 26 | EntityManager(ResourceLoader* resourceLoader, b2World* world); 27 | ~EntityManager(); 28 | 29 | void update(float dt); 30 | void render(const RenderState& renderState); 31 | 32 | void cleanup(); 33 | 34 | //Particle system functions 35 | void add(ParticleSystem* pSys); 36 | 37 | //Node functions 38 | void add(Node* n); 39 | Node* getNode(Vec2 pos); //Get closest node to a location TODO rename 40 | Node* getNodeUnder(Vec2 pos); //Get Node under a location, or NULL 41 | Node* getNode(const std::string& sNodeName); 42 | 43 | //Object funtions 44 | void add(Object* o); 45 | Object* getObject(Vec2 p); 46 | Object* getClosestObject(Vec2 p); 47 | 48 | //Scenery functions 49 | void add(ObjSegment* o); 50 | }; -------------------------------------------------------------------------------- /engine/managers/InputManager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "SDL_scancode.h" 4 | #include "Action.h" 5 | #include "Movement.h" 6 | #include "Rect.h" 7 | #include "SDL_joystick.h" 8 | 9 | //SDL codes that should be defined but aren't 10 | #define SDL_BUTTON_FORWARD SDL_BUTTON_X2 11 | #define SDL_BUTTON_BACK SDL_BUTTON_X1 12 | #define SDL_SCANCODE_CTRL (SDL_NUM_SCANCODES) 13 | #define SDL_SCANCODE_SHIFT (SDL_NUM_SCANCODES+1) 14 | #define SDL_SCANCODE_ALT (SDL_NUM_SCANCODES+2) 15 | #define SDL_SCANCODE_GUI (SDL_NUM_SCANCODES+3) 16 | 17 | //Class predeclarations 18 | class InputDevice; 19 | class ActionBind; 20 | class MovementBind; 21 | class HeadTracker; 22 | 23 | class InputManager 24 | { 25 | private: 26 | //TODO Better mouse/kb handling than separate arrays here 27 | ActionBind* actions[2][NUM_ACTIONS]; 28 | MovementBind* movements[2][NUM_MOVEMENTS]; 29 | std::vector m_controllers; 30 | HeadTracker* m_headTracker; //Only support one at a time for now 31 | int m_curActiveController; 32 | const Uint8 *m_iKeystates; //Keep track of keys that are pressed/released so we can poll as needed 33 | 34 | void bindMouseKbActions(); 35 | void bindControllerActions(); 36 | 37 | public: 38 | InputManager(); 39 | ~InputManager(); 40 | 41 | //Controller management 42 | InputDevice* getCurController(); 43 | void addController(int deviceIndex); 44 | void addController(InputDevice* device); 45 | void addHeadTracker(SDL_Joystick* joy); 46 | bool removeController(int deviceIndex); //Return true to signal this was the active one 47 | void activateController(int deviceIndex); 48 | std::vector getControllerList() { return m_controllers; } 49 | 50 | bool keyDown(int32_t keyCode); //Test and see if a key is currently pressed (for raw keyboard input) 51 | 52 | //Action (input) handling 53 | bool getDigitalAction(Action a); //Get a true/false for this action for the current input device 54 | float getAnalogAction(Action a); //Get a normalized 0..1 for this action (emulated if digital input) for the current input device 55 | Vec2 getMovement(Movement m); //Get the vector for movement 56 | Vec3 getHeadMovement(); //Get head tracker movement 57 | }; -------------------------------------------------------------------------------- /engine/managers/InterpolationManager.cpp: -------------------------------------------------------------------------------- 1 | #include "InterpolationManager.h" 2 | #include "Interpolation.h" 3 | #include "LinearInterpolation.h" 4 | #include "BezierInterpolation.h" 5 | 6 | InterpolationManager::InterpolationManager() 7 | { 8 | } 9 | 10 | InterpolationManager::~InterpolationManager() 11 | { 12 | clear(); 13 | } 14 | 15 | void InterpolationManager::update(float dt) 16 | { 17 | std::vector::iterator i = interpolations.begin(); 18 | while(i != interpolations.end()) 19 | { 20 | if(i->interp->update(dt)) //Interpolation is done 21 | { 22 | if(i->count == REPEAT_FOREVER || i->count-- > 0) //Repeat 23 | { 24 | if(i->repeat == REPEAT) //Start over 25 | { 26 | *i->interp->val = i->interp->start; 27 | i->interp->curTime = 0.0f; 28 | } 29 | else if(i->repeat == PINGPONG) //go back and forth 30 | { 31 | //Swap start and dest 32 | float tmp = i->interp->dest; 33 | i->interp->dest = i->interp->start; 34 | i->interp->start = tmp; 35 | i->interp->curTime = 0.0f; 36 | } 37 | i++; //Increment i here also 38 | } 39 | else 40 | { 41 | //Delete & remove if done updating 42 | delete i->interp; 43 | i = interpolations.erase(i); 44 | } 45 | } 46 | else 47 | i++; 48 | } 49 | } 50 | 51 | void InterpolationManager::interpolate(float * val, float end, float time, InterpType type, int count, InterpRepeat repeat) 52 | { 53 | Interpolation* interp = NULL; 54 | switch(type) 55 | { 56 | case LINEAR: 57 | interp = new LinearInterpolation(val, end, time); 58 | break; 59 | 60 | case BEZIER: 61 | interp = new BezierInterpolation(val, end, time); 62 | break; 63 | } 64 | 65 | if(interp != NULL) 66 | { 67 | InterpHolder holder; 68 | holder.count = count; 69 | holder.interp = interp; 70 | holder.repeat = repeat; 71 | interpolations.push_back(holder); 72 | } 73 | } 74 | 75 | bool InterpolationManager::contains(float * val) 76 | { 77 | for(std::vector::iterator i = interpolations.begin(); i != interpolations.end(); i++) 78 | { 79 | if(i->interp->val == val) 80 | return true; 81 | } 82 | return false; 83 | } 84 | 85 | void InterpolationManager::clear() 86 | { 87 | for(std::vector::iterator i = interpolations.begin(); i != interpolations.end(); i++) 88 | delete i->interp; 89 | interpolations.clear(); 90 | } 91 | -------------------------------------------------------------------------------- /engine/managers/InterpolationManager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | typedef enum 5 | { 6 | LINEAR, 7 | BEZIER 8 | } InterpType; 9 | 10 | typedef enum 11 | { 12 | REPEAT, 13 | PINGPONG 14 | } InterpRepeat; 15 | 16 | #define REPEAT_FOREVER -1 17 | 18 | class Interpolation; 19 | 20 | class InterpolationManager 21 | { 22 | typedef struct 23 | { 24 | Interpolation* interp; 25 | InterpRepeat repeat; 26 | int count; 27 | } InterpHolder; 28 | 29 | std::vector interpolations; 30 | 31 | public: 32 | InterpolationManager(); 33 | ~InterpolationManager(); 34 | 35 | void update(float dt); 36 | 37 | void interpolate(float* val, float end, float time, InterpType type = BEZIER, int repeatCount = 0, InterpRepeat repeatType = REPEAT); 38 | //TODO: O(n) 39 | bool contains(float* val); 40 | void clear(); 41 | }; 42 | -------------------------------------------------------------------------------- /engine/managers/NodeManager.cpp: -------------------------------------------------------------------------------- 1 | #include "NodeManager.h" 2 | #include "Node.h" 3 | #include "Box2D/Box2D.h" 4 | #include "PointQueryCallback.h" 5 | #include 6 | 7 | NodeManager::NodeManager(b2World * world) 8 | { 9 | physicsWorld = world; 10 | } 11 | 12 | NodeManager::~NodeManager() 13 | { 14 | cleanup(); 15 | } 16 | 17 | void NodeManager::add(Node* n) 18 | { 19 | if(n != NULL) 20 | { 21 | m_nodes[n->name] = n; 22 | n->init(); 23 | } 24 | } 25 | 26 | void NodeManager::update(float dt) 27 | { 28 | for(std::map::iterator i = m_nodes.begin(); i != m_nodes.end(); i++) 29 | i->second->update(dt); 30 | } 31 | 32 | void NodeManager::cleanup() 33 | { 34 | for(std::map::iterator it = m_nodes.begin(); it != m_nodes.end(); ++it) 35 | delete it->second; 36 | m_nodes.clear(); 37 | } 38 | 39 | Node* NodeManager::getNode(const std::string& sNodeName) 40 | { 41 | std::map::iterator i = m_nodes.find(sNodeName); 42 | if(i != m_nodes.end()) 43 | return i->second; 44 | return NULL; 45 | } 46 | 47 | 48 | Node* NodeManager::getNodeUnder(Vec2 p) 49 | { 50 | PointQueryCallback pqc; 51 | b2AABB aabb; 52 | aabb.lowerBound.Set(p.x, p.y); 53 | aabb.upperBound.Set(p.x, p.y); 54 | physicsWorld->QueryAABB(&pqc, aabb); 55 | 56 | //This returns a list of possible bodies; loop through and check for actual containment 57 | for(std::vector::iterator i = pqc.foundBodies.begin(); i != pqc.foundBodies.end(); i++) 58 | { 59 | for(b2Fixture* fix = (*i)->GetFixtureList(); fix != NULL; fix = fix->GetNext()) 60 | { 61 | if(fix->TestPoint(b2Vec2(p.x, p.y))) //we have a hit 62 | { 63 | void* data = fix->GetUserData(); 64 | if(data) 65 | return (Node*)(data); 66 | } 67 | } 68 | } 69 | 70 | return NULL; 71 | } 72 | 73 | Node* NodeManager::getNode(Vec2 p) 74 | { 75 | Node* closest = NULL; 76 | Vec2 closestPt; 77 | for(std::map::iterator i = m_nodes.begin(); i != m_nodes.end(); i++) 78 | { 79 | float distClosest = glm::length(p - closestPt); 80 | float distCur = glm::length(p - i->second->pos); 81 | if(!closest || distCur < distClosest) 82 | { 83 | closest = i->second; 84 | closestPt = closest->pos; 85 | } 86 | } 87 | return closest; 88 | } 89 | -------------------------------------------------------------------------------- /engine/managers/NodeManager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include "Rect.h" 6 | 7 | class Node; 8 | class b2World; 9 | 10 | class NodeManager 11 | { 12 | std::map m_nodes; 13 | b2World* physicsWorld; 14 | 15 | NodeManager() {}; 16 | 17 | public: 18 | NodeManager(b2World* world); 19 | ~NodeManager(); 20 | 21 | void add(Node* n); 22 | void update(float dt); 23 | void cleanup(); 24 | Node* getNode(const std::string& sNodeName); 25 | Node* getNode(Vec2 p); //TODO rename 26 | Node* getNodeUnder(Vec2 p); 27 | 28 | 29 | }; -------------------------------------------------------------------------------- /engine/managers/ObjectManager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Rect.h" 3 | #include "RenderState.h" 4 | #include 5 | 6 | class Object; 7 | class b2World; 8 | 9 | class ObjectManager 10 | { 11 | bool updating; 12 | std::vector m_lObjects; //Object list 13 | std::vector m_lUpdateObjects; //Temp holder for objects added while iterating over the object list 14 | b2World* m_physicsWorld; 15 | 16 | public: 17 | ObjectManager(b2World* world); 18 | ~ObjectManager(); 19 | 20 | void render(const RenderState& renderState); 21 | void add(Object* o); 22 | void cleanup(); 23 | void update(float dt); 24 | 25 | Object* getAt(Vec2 p); //Get first object at this point 26 | Object* getClosest(Vec2 p); //Get closest object to this point 27 | 28 | }; -------------------------------------------------------------------------------- /engine/managers/ParticleSystemManager.cpp: -------------------------------------------------------------------------------- 1 | #include "ParticleSystemManager.h" 2 | #include "ParticleSystem.h" 3 | 4 | ParticleSystemManager::ParticleSystemManager(ResourceLoader* loader) 5 | { 6 | updating = false; 7 | m_notifySubject = new Subject(); 8 | m_notifySubject->addObserver(this); 9 | m_loader = loader; 10 | } 11 | 12 | ParticleSystemManager::~ParticleSystemManager() 13 | { 14 | cleanup(); 15 | delete m_notifySubject; 16 | } 17 | 18 | void ParticleSystemManager::add(ParticleSystem * sys) 19 | { 20 | if(sys) 21 | { 22 | sys->setSubject(m_notifySubject); 23 | if(updating) 24 | m_updateParticles.push_back(sys); 25 | else 26 | m_particles.push_back(sys); 27 | } 28 | } 29 | 30 | void ParticleSystemManager::cleanup() 31 | { 32 | for(std::vector::iterator i = m_particles.begin(); i != m_particles.end(); i++) 33 | delete *i; 34 | for(std::vector::iterator i = m_updateParticles.begin(); i != m_updateParticles.end(); i++) 35 | delete *i; 36 | m_particles.clear(); 37 | m_updateParticles.clear(); 38 | } 39 | 40 | void ParticleSystemManager::render(const RenderState& renderState) 41 | { 42 | for(std::vector::iterator i = m_particles.begin(); i != m_particles.end(); i++) 43 | (*i)->draw(renderState); 44 | } 45 | 46 | void ParticleSystemManager::update(float dt) 47 | { 48 | updating = true; 49 | for(std::vector::iterator i = m_particles.begin(); i != m_particles.end(); i++) 50 | { 51 | (*i)->update(dt); 52 | if((*i)->done()) 53 | { 54 | delete *i; 55 | i = m_particles.erase(i); 56 | continue; 57 | } 58 | } 59 | updating = false; 60 | for(std::vector::iterator i = m_updateParticles.begin(); i != m_updateParticles.end(); i++) 61 | m_particles.push_back(*i); 62 | 63 | m_updateParticles.clear(); 64 | } 65 | 66 | void ParticleSystemManager::onNotify(const std::string& sParticleFilename, Vec2 pos) 67 | { 68 | ParticleSystem* pSys = m_loader->getParticleSystem(sParticleFilename); 69 | pSys->emitFrom.centerOn(pos); 70 | add(pSys); 71 | } 72 | -------------------------------------------------------------------------------- /engine/managers/ParticleSystemManager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "Observer.h" 4 | #include "Subject.h" 5 | #include "ResourceLoader.h" 6 | #include "RenderState.h" 7 | 8 | class ParticleSystem; 9 | 10 | class ParticleSystemManager : public Observer 11 | { 12 | ParticleSystemManager() {}; 13 | 14 | std::vector m_particles; 15 | std::vector m_updateParticles; 16 | Subject* m_notifySubject; 17 | ResourceLoader* m_loader; 18 | bool updating; 19 | 20 | public: 21 | ParticleSystemManager(ResourceLoader* loader); 22 | ~ParticleSystemManager(); 23 | 24 | void add(ParticleSystem* sys); 25 | void cleanup(); 26 | void render(const RenderState& renderState); 27 | void update(float dt); 28 | 29 | virtual void onNotify(const std::string& sParticleFilename, Vec2 pos); 30 | }; 31 | 32 | -------------------------------------------------------------------------------- /engine/managers/SceneryManager.cpp: -------------------------------------------------------------------------------- 1 | #include "SceneryManager.h" 2 | #include "ObjSegment.h" 3 | 4 | SceneryManager::~SceneryManager() 5 | { 6 | cleanup(); 7 | } 8 | 9 | void SceneryManager::update(float dt) 10 | { 11 | //for(std::multiset::iterator i = m_lSceneryFg.begin(); i != m_lSceneryFg.end(); i++) 12 | // (*i)->update(dt); 13 | //for(std::multiset::iterator i = m_lSceneryBg.begin(); i != m_lSceneryBg.end(); i++) 14 | // (*i)->update(dt); 15 | } 16 | 17 | void SceneryManager::renderForeground(const RenderState& renderState) 18 | { 19 | for(std::multiset::iterator i = m_lSceneryFg.begin(); i != m_lSceneryFg.end(); i++) 20 | (*i)->draw(renderState); 21 | } 22 | 23 | void SceneryManager::renderBackground(const RenderState& renderState) 24 | { 25 | for(std::multiset::iterator i = m_lSceneryBg.begin(); i != m_lSceneryBg.end(); i++) 26 | (*i)->draw(renderState); 27 | } 28 | 29 | void SceneryManager::add(ObjSegment * seg) 30 | { 31 | if(seg->depth > 0) 32 | m_lSceneryFg.insert(seg); 33 | else 34 | m_lSceneryBg.insert(seg); 35 | } 36 | 37 | void SceneryManager::cleanup() 38 | { 39 | for(std::multiset::iterator i = m_lSceneryFg.begin(); i != m_lSceneryFg.end(); i++) 40 | delete (*i); 41 | for(std::multiset::iterator i = m_lSceneryBg.begin(); i != m_lSceneryBg.end(); i++) 42 | delete (*i); 43 | 44 | m_lSceneryBg.clear(); 45 | m_lSceneryFg.clear(); 46 | } 47 | -------------------------------------------------------------------------------- /engine/managers/SceneryManager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "glmx.h" 4 | #include 5 | #include "RenderState.h" 6 | #include "ObjSegment.h" 7 | 8 | //TODO: Use SceneryLayer rather than ObjSegment 9 | class SceneryManager 10 | { 11 | class DepthComparator 12 | { 13 | public: 14 | bool operator()(const ObjSegment* s1, const ObjSegment* s2) 15 | { 16 | return s1->depth < s2->depth; 17 | } 18 | }; 19 | 20 | std::multiset m_lSceneryFg; 21 | std::multiset m_lSceneryBg; 22 | 23 | public: 24 | ~SceneryManager(); 25 | 26 | void update(float dt); 27 | void renderForeground(const RenderState& renderState); 28 | void renderBackground(const RenderState& renderState); 29 | void add(ObjSegment* seg); 30 | void cleanup(); 31 | }; 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /engine/managers/Stringbank.cpp: -------------------------------------------------------------------------------- 1 | #include "Stringbank.h" 2 | #include "Hash.h" 3 | #include 4 | #include 5 | 6 | Stringbank::Stringbank(uint8_t* fromData, uint64_t dataLen) 7 | { 8 | curLangOffset = 0; 9 | raw = fromData; 10 | load(fromData, dataLen); 11 | } 12 | 13 | Stringbank::~Stringbank() 14 | { 15 | free(raw); 16 | } 17 | 18 | const char* Stringbank::getString(const char* stringID) 19 | { 20 | return getString(Hash::hash(stringID)); 21 | } 22 | 23 | const char* Stringbank::getString(uint64_t stringHash) 24 | { 25 | //Binary search 26 | uint64_t first = 0; 27 | uint64_t last = header->numStrings - 1; 28 | uint64_t middle = (first + last) / 2; 29 | 30 | while(first <= last) 31 | { 32 | uint64_t mid = ids[middle]; 33 | if(mid < stringHash) 34 | first = middle + 1; 35 | else if(mid == stringHash) 36 | return getStringAt(middle); 37 | else 38 | last = middle - 1; 39 | 40 | middle = (first + last) / 2; 41 | } 42 | 43 | return NULL; 44 | } 45 | 46 | bool Stringbank::setLanguage(const char* langID) 47 | { 48 | LanguageOffset* offset = offsets; 49 | for(unsigned int i = 0; i < header->numLanguages; i++) 50 | { 51 | if(strcmp(offset->languageID, langID) == 0) 52 | { 53 | curLangOffset = offset->offset; 54 | return true; 55 | } 56 | offset++; 57 | } 58 | return false; 59 | } 60 | 61 | const char* Stringbank::getLanguage() 62 | { 63 | return offsets[curLangOffset].languageID; 64 | } 65 | 66 | const char* Stringbank::getStringAt(uint64_t offset) 67 | { 68 | return &stringData[stringPointers[(offset*header->numLanguages)+curLangOffset]]; 69 | } 70 | 71 | void Stringbank::load(uint8_t* fromData, uint64_t dataLen) 72 | { 73 | assert(dataLen > sizeof(StringBankHeader)); 74 | 75 | header = (StringBankHeader*)fromData; 76 | 77 | assert(dataLen > sizeof(StringBankHeader) + header->numLanguages * sizeof(LanguageOffset) + header->numStrings * sizeof(StringID) + header->numStrings*header->numLanguages * sizeof(StringDataPointer)); 78 | 79 | uint64_t offset = sizeof(StringBankHeader); 80 | 81 | offsets = (LanguageOffset*) &fromData[offset]; 82 | 83 | offset += header->numLanguages * sizeof(LanguageOffset); 84 | 85 | ids = (uint64_t*)&fromData[offset]; 86 | 87 | offset += header->numStrings * sizeof(StringID); 88 | 89 | stringPointers = (uint64_t*)&fromData[offset]; 90 | 91 | offset += header->numStrings*header->numLanguages * sizeof(StringDataPointer); 92 | 93 | stringData = (const char*)&fromData[offset]; 94 | } 95 | -------------------------------------------------------------------------------- /engine/managers/Stringbank.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ResourceTypes.h" 3 | 4 | class Stringbank 5 | { 6 | uint8_t* raw; 7 | 8 | uint32_t curLangOffset; 9 | 10 | StringBankHeader* header; 11 | LanguageOffset* offsets; 12 | uint64_t* ids; 13 | uint64_t* stringPointers; 14 | const char* stringData; 15 | 16 | const char* getStringAt(uint64_t offset); 17 | void load(uint8_t* fromData, uint64_t dataLen); 18 | 19 | Stringbank(){}; 20 | 21 | public: 22 | Stringbank(uint8_t* fromData, uint64_t dataLen); //Load from data (MUST BE ALLOCATED WITH MALLOC. FREED ON OBJECT DELETION) 23 | ~Stringbank(); 24 | 25 | const char* getString(const char* stringID); 26 | const char* getString(uint64_t stringHash); 27 | 28 | bool setLanguage(const char* langID); //Set to a particular language. Returns true on success, false on failure 29 | const char* getLanguage(); 30 | }; -------------------------------------------------------------------------------- /engine/mtrand.cpp: -------------------------------------------------------------------------------- 1 | // mtrand.cpp, see include file mtrand.h for information 2 | 3 | #include "mtrand.h" 4 | // non-inline function definitions and static member definitions cannot 5 | // reside in header file because of the risk of multiple declarations 6 | 7 | // initialization of static private members 8 | unsigned long MTRand_int32::state[n] = {0x0UL}; 9 | int MTRand_int32::p = 0; 10 | bool MTRand_int32::init = false; 11 | 12 | void MTRand_int32::gen_state() { // generate new state vector 13 | for (int i = 0; i < (n - m); ++i) 14 | state[i] = state[i + m] ^ twiddle(state[i], state[i + 1]); 15 | for (int i = n - m; i < (n - 1); ++i) 16 | state[i] = state[i + m - n] ^ twiddle(state[i], state[i + 1]); 17 | state[n - 1] = state[m - 1] ^ twiddle(state[n - 1], state[0]); 18 | p = 0; // reset position 19 | } 20 | 21 | void MTRand_int32::seed(unsigned long s) { // init by 32 bit seed 22 | state[0] = s & 0xFFFFFFFFUL; // for > 32 bit machines 23 | for (int i = 1; i < n; ++i) { 24 | state[i] = 1812433253UL * (state[i - 1] ^ (state[i - 1] >> 30)) + i; 25 | // see Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier 26 | // in the previous versions, MSBs of the seed affect only MSBs of the array state 27 | // 2002/01/09 modified by Makoto Matsumoto 28 | state[i] &= 0xFFFFFFFFUL; // for > 32 bit machines 29 | } 30 | p = n; // force gen_state() to be called for next random number 31 | } 32 | 33 | void MTRand_int32::seed(const unsigned long* array, int size) { // init by array 34 | seed(19650218UL); 35 | int i = 1, j = 0; 36 | for (int k = ((n > size) ? n : size); k; --k) { 37 | state[i] = (state[i] ^ ((state[i - 1] ^ (state[i - 1] >> 30)) * 1664525UL)) 38 | + array[j] + j; // non linear 39 | state[i] &= 0xFFFFFFFFUL; // for > 32 bit machines 40 | ++j; j %= size; 41 | if ((++i) == n) { state[0] = state[n - 1]; i = 1; } 42 | } 43 | for (int k = n - 1; k; --k) { 44 | state[i] = (state[i] ^ ((state[i - 1] ^ (state[i - 1] >> 30)) * 1566083941UL)) - i; 45 | state[i] &= 0xFFFFFFFFUL; // for > 32 bit machines 46 | if ((++i) == n) { state[0] = state[n - 1]; i = 1; } 47 | } 48 | state[0] = 0x80000000UL; // MSB is 1; assuring non-zero initial array 49 | p = n; // force gen_state() to be called for next random number 50 | } 51 | -------------------------------------------------------------------------------- /engine/opengl-api.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | #include 6 | #include "opengl-api.h" 7 | #include "Logger.h" 8 | 9 | 10 | // Populate global namespace with static function pointers pFUNC, 11 | // and function stubs FUNC that call their associated function pointer 12 | #define GL_FUNC(ret,fn,params,call,rt) \ 13 | extern "C" { \ 14 | static ret (GLAPIENTRY *p##fn) params = NULL; \ 15 | ret GLAPIENTRY fn params { rt p##fn call; } \ 16 | } 17 | #define GL_PTR(pty, fn) pty fn = NULL; 18 | 19 | #include "opengl-stubs.h" 20 | 21 | 22 | static bool lookup_glsym(const char *funcname, void **func) 23 | { 24 | *func = SDL_GL_GetProcAddress(funcname); 25 | if (*func == NULL) 26 | { 27 | LOG(ERR) << "Failed to find OpenGL symbol '" << funcname << "'"; 28 | return false; 29 | } 30 | return true; 31 | } 32 | 33 | static bool lookup_all_glsyms(void) 34 | { 35 | bool retval = true; 36 | #define GL_FUNC(ret,fn,params,call,rt) \ 37 | if (!lookup_glsym(#fn, (void **) &p##fn)) retval = false; 38 | #define GL_PTR(_, fn) \ 39 | if (!lookup_glsym(#fn, (void **) &fn)) retval = false; 40 | #include "opengl-stubs.h" 41 | return retval; 42 | } 43 | 44 | 45 | 46 | namespace OpenGLAPI { 47 | 48 | 49 | bool LoadSymbols() 50 | { 51 | return lookup_all_glsyms(); 52 | } 53 | 54 | void ClearSymbols() 55 | { 56 | // reset all the entry points to NULL, so we know exactly what happened 57 | // if we call a GL function after shutdown. 58 | #define GL_FUNC(ret,fn,params,call,rt) p##fn = NULL; 59 | #define GL_PTR(pty, fn) fn = NULL; 60 | #include "opengl-stubs.h" 61 | } 62 | 63 | 64 | }; // end namespace OpenGLAPI 65 | 66 | -------------------------------------------------------------------------------- /engine/opengl-api.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef _DLL 4 | #define WASDLL 5 | #undef _DLL // HACK: don't put any __declspec in front of the function definitions 6 | #endif 7 | 8 | #include 9 | 10 | #define GL_FUNC(ret,fn,params,call,rt) 11 | #define GL_PTR(pty, fn) extern pty fn; 12 | #include "opengl-stubs.h" 13 | 14 | 15 | #ifdef WASDLL 16 | #define _DLL 17 | #undef WASDLL 18 | #endif 19 | 20 | 21 | namespace OpenGLAPI 22 | { 23 | bool LoadSymbols(); 24 | void ClearSymbols(); 25 | void ResetCallCount(); 26 | unsigned int GetCallCount(); 27 | }; 28 | 29 | -------------------------------------------------------------------------------- /fixdylibs_mac.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # fixdylibs_mac.sh 4 | # 5 | # Fix dylib paths inside final executable 6 | # 7 | # Created by Mark H on 7/18/14. 8 | 9 | install_name_tool -change @executable_path/../Frameworks/SDL2.framework/Versions/A/SDL2 @executable_path/SDL2 ./Pony48_mac 10 | install_name_tool -change ./libfmodexL.dylib @executable_path/libfmodexL.dylib ./Pony48_mac 11 | -------------------------------------------------------------------------------- /game/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(game_src 2 | DebugUI.cpp 3 | DebugUI.h 4 | GameEngine.cpp 5 | GameEngine.h 6 | GameEngine.rc 7 | GameEngine_color.cpp 8 | GameEngine_events.cpp 9 | GameEngine_xmlparse.cpp 10 | LevelEditor.h 11 | LevelEditor.cpp 12 | LuaFuncs.cpp 13 | main.cpp 14 | MemoryEditor.cpp 15 | MemoryEditor.h 16 | ParticleEditor.cpp 17 | ParticleEditor.h 18 | SteelSeriesEditor.h 19 | SteelSeriesEditor.cpp 20 | ) 21 | 22 | add_executable(game ${game_src}) 23 | 24 | set(EXTRA_LIBS "") 25 | 26 | if(WIN32) 27 | set(EXTRA_LIBS ${EXTRA_LIBS} ws2_32) 28 | endif() 29 | 30 | target_link_libraries(game engine net ${EXTRA_LIBS}) 31 | -------------------------------------------------------------------------------- /game/DebugUI.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "MemoryEditor.h" 4 | #include "Color.h" 5 | 6 | class GameEngine; 7 | class ParticleSystem; 8 | class SteelSeriesEditor; 9 | class ParticleEditor; 10 | class LevelEditor; 11 | 12 | class DebugUI 13 | { 14 | public: 15 | DebugUI(GameEngine*); 16 | ~DebugUI(); 17 | void draw(); 18 | bool hasFocus(); 19 | 20 | bool visible; 21 | bool hadFocus; 22 | 23 | //Steel Series editor 24 | SteelSeriesEditor* steelSeriesEditor; 25 | 26 | //Particle system editor 27 | ParticleEditor* particleEditor; 28 | 29 | private: 30 | void _draw(); 31 | 32 | MemoryEditor memEdit; 33 | LevelEditor* levelEditor; 34 | GameEngine *_ge; 35 | 36 | bool rumbleMenu; 37 | int windowFlags; 38 | 39 | //Rumble testing helper vars 40 | int largeMotorStrength; 41 | int smallMotorStrength; 42 | int motorDuration; 43 | }; 44 | -------------------------------------------------------------------------------- /game/GameEngine.rc: -------------------------------------------------------------------------------- 1 | 42 ICON "res/icons/icon.ico" 2 | 1 VERSIONINFO 3 | FILEVERSION 1,0,0,0 4 | PRODUCTVERSION 1,0,0,0 5 | BEGIN 6 | BLOCK "StringFileInfo" 7 | BEGIN 8 | BLOCK "040904E4" 9 | BEGIN 10 | VALUE "CompanyName", "RetiredSphinx game design" 11 | VALUE "FileDescription", "Game Engine" 12 | VALUE "FileVersion", "1.0" 13 | VALUE "InternalName", "Game Engine" 14 | VALUE "LegalCopyright", "RetiredSphinx" 15 | VALUE "OriginalFilename", "GameEngine.exe" 16 | VALUE "ProductName", "Game Engine" 17 | VALUE "ProductVersion", "1.0" 18 | END 19 | END 20 | 21 | BLOCK "VarFileInfo" 22 | BEGIN 23 | VALUE "Translation", 0x409, 1252 24 | END 25 | END -------------------------------------------------------------------------------- /game/LevelEditor.cpp: -------------------------------------------------------------------------------- 1 | #include "LevelEditor.h" 2 | #include "GameEngine.h" 3 | #include "imgui/imgui.h" 4 | #include "Node.h" 5 | #include "EntityManager.h" 6 | #include "Box2D/Box2D.h" 7 | #include "LuaInterface.h" 8 | 9 | #define WINDOW_TITLE "Level Editor" 10 | 11 | LevelEditor::LevelEditor(GameEngine * _g) 12 | { 13 | open = false; 14 | ge = _g; 15 | } 16 | 17 | void LevelEditor::draw(int windowFlags, bool focus) 18 | { 19 | if(ImGui::Begin(WINDOW_TITLE, &open, windowFlags)) 20 | { 21 | ImGuiIO& io = ImGui::GetIO(); 22 | ge->cameraPos.z += io.MouseWheel * 4.0f; //+ = zoom in, - = zoom out 23 | 24 | Vec2 cursorPos = ge->worldPosFromCursor(Vec2(io.MousePos.x, io.MousePos.y), ge->cameraPos); 25 | Vec2 cursorMove = ge->worldMovement(Vec2(io.MouseDelta.x, -io.MouseDelta.y), ge->cameraPos); 26 | static Node* draggingNode = NULL; 27 | //Pan view with rmb+drag 28 | if(!focus && io.MouseDown[1]) 29 | { 30 | ge->cameraPos.x += cursorMove.x; 31 | ge->cameraPos.y += cursorMove.y; 32 | } 33 | else if(!focus && io.MouseDown[0]) //Move objects with LMB 34 | { 35 | Node* curOverNode = ge->getEntityManager()->getNodeUnder(cursorPos); 36 | if(draggingNode == NULL && curOverNode != NULL) 37 | draggingNode = curOverNode; 38 | } 39 | else if(!io.MouseDown[0]) 40 | { 41 | if(draggingNode) 42 | { 43 | draggingNode->lua->callMethod(draggingNode, "init"); //Re-init lua to recalc position 44 | draggingNode = NULL; 45 | } 46 | } 47 | 48 | if(draggingNode != NULL) 49 | { 50 | draggingNode->pos += cursorMove; 51 | draggingNode->body->SetTransform(b2Vec2(draggingNode->pos.x, draggingNode->pos.y), draggingNode->body->GetAngle()); 52 | } 53 | } 54 | #ifdef _DEBUG 55 | else 56 | ge->playPhysics(); 57 | #endif 58 | ImGui::End(); 59 | } 60 | 61 | -------------------------------------------------------------------------------- /game/LevelEditor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class GameEngine; 4 | 5 | class LevelEditor 6 | { 7 | GameEngine* ge; 8 | 9 | public: 10 | LevelEditor(GameEngine* _g); 11 | 12 | bool open; 13 | void draw(int windowFlags, bool focus); 14 | }; 15 | -------------------------------------------------------------------------------- /game/MemoryEditor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | class MemoryEditor 5 | { 6 | public: 7 | 8 | bool Open; 9 | bool AllowEdits; 10 | int Rows; 11 | int DataEditingAddr; 12 | bool DataEditingTakeFocus; 13 | char DataInput[32]; 14 | char AddrInput[32]; 15 | 16 | MemoryEditor(); 17 | 18 | void Draw(const char* title, unsigned char* mem_data, int mem_size, size_t base_display_addr = 0, int flags = 0); 19 | }; 20 | -------------------------------------------------------------------------------- /game/ParticleEditor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Color.h" 3 | #include 4 | 5 | #define SAVE_BUF_SZ 256 6 | 7 | class GameEngine; 8 | class ParticleSystem; 9 | 10 | class ParticleEditor 11 | { 12 | public: 13 | Color particleBgColor; 14 | ParticleSystem* particles; 15 | bool open; 16 | 17 | ParticleEditor(GameEngine* ge); 18 | ~ParticleEditor(); 19 | 20 | void draw(int windowFlags); 21 | 22 | private: 23 | GameEngine* _ge; 24 | ParticleEditor() {}; 25 | 26 | //Helper variables for particle-system editing 27 | float emitRect[4]; 28 | float emitVel[2]; 29 | float startSz[2]; 30 | float endSz[2]; 31 | float accel[2]; 32 | float accelVar[2]; 33 | float rotAxis[3]; 34 | float rotAxisVar[3]; 35 | float startCol[4]; 36 | float endCol[4]; 37 | float colVar[4]; 38 | float bgCol[3]; 39 | bool psysDecay; 40 | bool loadParticles; 41 | bool saveParticles; 42 | int curSelectedLoadSaveItem; 43 | char saveFilenameBuf[SAVE_BUF_SZ]; 44 | bool fireOnStart; 45 | int curSelectedSpawn; 46 | bool spawnParticleSelect; 47 | int curSelectedSpawnSystem; 48 | int curSelectedImgRect; 49 | bool loadParticleImage; 50 | int curSelectedLoadImage; 51 | 52 | std::string curImageFilename; 53 | 54 | //Helper functions 55 | void updateHelperVars(); //Keep the above up-to-date with the particle system 56 | void saveParticleSystemXML(std::string filename); //Save the current particle system to XML 57 | }; -------------------------------------------------------------------------------- /game/SteelSeriesEditor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | #define SS_BUF_SZ 33 5 | 6 | class GameEngine; 7 | 8 | class SteelSeriesEditor 9 | { 10 | public: 11 | bool open; 12 | 13 | void draw(int windowFlags); 14 | 15 | SteelSeriesEditor(GameEngine* ge); 16 | 17 | private: 18 | 19 | SteelSeriesEditor() {}; 20 | 21 | GameEngine* _ge; 22 | 23 | std::string appName; 24 | 25 | //Rumble testing helper vars 26 | int largeMotorStrength; 27 | int smallMotorStrength; 28 | int motorDuration; 29 | std::string eventType; 30 | int selectedSSMouseRumble; 31 | int rumbleCount; 32 | float rumbleFreq; 33 | int rumbleLen; 34 | 35 | //Mouse color testing helper vars 36 | std::string colorZone; 37 | int selectedSSMouseColorZone; 38 | int colorValue; 39 | float mouse0Color[3]; 40 | float mouse100Color[3]; 41 | bool colorFlash; 42 | float colorFlashFreq; 43 | int colorFlashCount; 44 | 45 | //Mouse screen testing helper vars 46 | int selectedEventIcon; 47 | int percentHealth; 48 | int screenMs; 49 | char prefixBuf[SS_BUF_SZ]; 50 | char suffixBuf[SS_BUF_SZ]; 51 | 52 | //Helper functions for dealing with SteelSeries mouse testing 53 | void bindTactileEvent(const std::string& eventId); 54 | void bindScreenEvent(const std::string& eventId); 55 | void bindColorEvent(const std::string& eventId); 56 | }; 57 | -------------------------------------------------------------------------------- /game/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | GameEngine source - main.cpp 3 | Copyright (c) 2014 Mark Hutcheson 4 | */ 5 | 6 | #include "GameEngine.h" 7 | #include "Logger.h" 8 | #include "LuaInterface.h" 9 | 10 | #ifdef _WIN32 11 | #define ICONNAME "res/icons/icon_32.img" //For some reason, Windoze (Or SDL2, or something) doesn't like large (256x256) icons for windows. Using a 32x32 icon instead. 12 | #else 13 | #define ICONNAME "res/icons/icon_256.img" 14 | #endif 15 | 16 | #ifdef _WIN32 17 | int SDL_main(int argc, char *argv[]) 18 | #else 19 | int main(int argc, char** argv) 20 | #endif 21 | { 22 | GameEngine* eng = new GameEngine(DEFAULT_WIDTH, DEFAULT_HEIGHT, "Game Engine", "RetiredSphinxGameDev", "GameEngine", ICONNAME, true); //Create our engine 23 | 24 | std::vector lCommandLine; 25 | 26 | for(int i = 1; i < argc; i++) 27 | lCommandLine.push_back(argv[i]); 28 | 29 | eng->commandline(lCommandLine); 30 | eng->start(); //Get the engine rolling 31 | 32 | //Done main loop; exit program 33 | LOG(INFO) << "Deleting engine"; 34 | delete eng; 35 | LOG(INFO) << "Ending program happily"; 36 | logger_quit(); 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /io/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(io_src 2 | Logger.h 3 | Logger.cpp 4 | FileOperations.h 5 | FileOperations.cpp 6 | Hash.cpp 7 | Hash.h 8 | PakLoader.h 9 | PakLoader.cpp 10 | StringUtils.cpp 11 | StringUtils.h 12 | ResourceTypes.h 13 | stb_image.h 14 | stb_image_write.h 15 | tinydir.h 16 | tinyxml2.cpp 17 | tinyxml2.h 18 | wfLZ.c 19 | wfLZ.h 20 | ) 21 | 22 | include_directories (.) 23 | include_directories (rapidjson) 24 | 25 | add_library(io ${io_src}) 26 | -------------------------------------------------------------------------------- /io/FileOperations.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #ifndef WIN32 7 | #include 8 | #else 9 | #define stat _stat 10 | #endif 11 | #include "FileOperations.h" 12 | #include "tinydir.h" 13 | 14 | namespace FileOperations 15 | { 16 | unsigned char* readFile(const std::string& filename, unsigned int* fileSize) 17 | { 18 | FILE *f = fopen(filename.c_str(), "rb"); 19 | if(f == NULL) 20 | return NULL; //File not here 21 | 22 | fseek(f, 0, SEEK_END); 23 | long size = ftell(f); 24 | fseek(f, 0, SEEK_SET); //same as rewind(f); 25 | 26 | unsigned char *buf = (unsigned char*)malloc(size); 27 | fread(buf, 1, size, f); 28 | fclose(f); 29 | 30 | if(fileSize) 31 | *fileSize = size; 32 | 33 | return buf; 34 | } 35 | 36 | std::set readFilesFromDir(const std::string& sDirPath, bool fullPath) 37 | { 38 | std::set returnedFiles; 39 | 40 | tinydir_dir dir; 41 | tinydir_open(&dir, sDirPath.c_str()); 42 | 43 | while(dir.has_next) 44 | { 45 | tinydir_file file; 46 | tinydir_readfile(&dir, &file); 47 | 48 | if(!file.is_dir) 49 | { 50 | if(fullPath) 51 | { 52 | std::ostringstream oss; 53 | oss << sDirPath << "/" << file.name; 54 | returnedFiles.insert(oss.str()); 55 | } 56 | else 57 | returnedFiles.insert(file.name); 58 | } 59 | 60 | tinydir_next(&dir); 61 | } 62 | 63 | tinydir_close(&dir); 64 | 65 | return returnedFiles; 66 | } 67 | 68 | time_t timeModified(const std::string& filename) 69 | { 70 | struct stat result; 71 | if(stat(filename.c_str(), &result) == 0) 72 | { 73 | return result.st_mtime; 74 | } 75 | return time(0); //Return current time if can't stat last modified time 76 | } 77 | 78 | bool fileExists(const std::string& filename) 79 | { 80 | struct stat buffer; 81 | return (stat(filename.c_str(), &buffer) == 0); 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /io/FileOperations.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | namespace FileOperations 7 | { 8 | //Read an entire file into memory and return the buffer, NULL on error. 9 | //The pointer returned from this function must be free()d. 10 | unsigned char* readFile(const std::string& filename, unsigned int* fileSize); 11 | 12 | std::set readFilesFromDir(const std::string& sDirPath, bool fullPath = true); //Return a list of all files in the given folder 13 | 14 | time_t timeModified(const std::string& filename); //Get the last modified time of the given file 15 | 16 | bool fileExists(const std::string& filename); //Return true if file exists, false if no 17 | } 18 | -------------------------------------------------------------------------------- /io/Hash.cpp: -------------------------------------------------------------------------------- 1 | #include "Hash.h" 2 | 3 | namespace Hash 4 | { 5 | uint64_t hash(const char* str) 6 | { 7 | uint64_t hash = 5381; 8 | int c; 9 | 10 | while(c = *str++) 11 | hash = ((hash << 5) + hash) + c; 12 | 13 | return hash; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /io/Hash.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace Hash 5 | { 6 | uint64_t hash(const char* string); 7 | } -------------------------------------------------------------------------------- /io/Logger.cpp: -------------------------------------------------------------------------------- 1 | #include "Logger.h" 2 | #include "StringUtils.h" 3 | #include 4 | #include 5 | 6 | #define BUF_SZ 32 7 | 8 | static logstream logfile; 9 | static LogLevel curLogLevel; 10 | static char buffer[BUF_SZ]; 11 | 12 | static const char* levelToString(LogLevel l) 13 | { 14 | switch(l) 15 | { 16 | case TRACE: 17 | return "TRACE"; 18 | case DBG: 19 | return "DEBUG"; 20 | case INFO: 21 | return "INFO"; 22 | case WARN: 23 | return "WARN"; 24 | case ERR: 25 | return "ERROR"; 26 | } 27 | return "UNK"; 28 | } 29 | 30 | static const char* curTime() 31 | { 32 | time_t t = time(0); 33 | struct tm* now = localtime(&t); 34 | strftime(buffer, BUF_SZ, "%D %T", now); 35 | return buffer; 36 | } 37 | 38 | #ifdef _DEBUG 39 | logstream& logg(LogLevel l, const char* file, int line) 40 | #else 41 | logstream& logg(LogLevel l) 42 | #endif 43 | { 44 | if(l >= curLogLevel) 45 | { 46 | logfile._on(); 47 | logfile << std::endl << curTime() << ' ' << levelToString(l); 48 | #ifdef _DEBUG 49 | logfile << ' ' << StringUtils::getFilename(file) << ':' << line; 50 | #endif 51 | logfile << " : "; 52 | } 53 | else 54 | logfile._off(); 55 | return logfile; 56 | } 57 | 58 | void logger_init(const char* filename, LogLevel l) 59 | { 60 | #ifdef _DEBUG 61 | //If in debug mode, overwrite existing log file 62 | #define MODE std::ofstream::out 63 | #else 64 | //If in release mode, append to existing file 65 | #define MODE std::ofstream::out | std::ofstream::app 66 | #endif 67 | curLogLevel = l; 68 | logfile.coss.open(filename, MODE); 69 | logfile << curTime() << " Logger init"; 70 | } 71 | 72 | void logger_quit() 73 | { 74 | logfile << std::endl << curTime() << " Logger close" << std::endl; 75 | logfile.coss.close(); 76 | } 77 | 78 | void logstream::_on() 79 | { 80 | coss.clear(); 81 | #ifdef _DEBUG 82 | std::cout.clear(); 83 | #endif 84 | } 85 | 86 | void logstream::_off() 87 | { 88 | coss.setstate(std::ios_base::badbit); 89 | #ifdef _DEBUG 90 | std::cout.setstate(std::ios_base::badbit); 91 | #endif 92 | } 93 | 94 | logstream& logstream::operator<< (std::ostream& (*pfun)(std::ostream&)) 95 | { 96 | pfun(coss); 97 | #ifdef _DEBUG 98 | pfun(std::cout); 99 | #endif 100 | return *this; 101 | } 102 | -------------------------------------------------------------------------------- /io/Logger.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | typedef enum loglevel 7 | { 8 | TRACE = 0, 9 | DBG = 1, 10 | INFO = 2, 11 | WARN = 3, 12 | ERR = 4 13 | } LogLevel; 14 | 15 | 16 | class logstream 17 | { 18 | public: 19 | std::ofstream coss; 20 | logstream& operator<< (std::ostream& (*pfun)(std::ostream&)); 21 | void _on(); 22 | void _off(); 23 | }; 24 | 25 | #ifdef _DEBUG 26 | logstream& logg(LogLevel l, const char* file, int line); 27 | #else 28 | logstream& logg(LogLevel l); 29 | #endif 30 | 31 | template 32 | inline logstream& operator<<(logstream & st, const T & val) 33 | { 34 | st.coss << val; 35 | #ifdef _DEBUG 36 | std::cout << val; 37 | #endif 38 | return st; 39 | } 40 | 41 | void logger_init(const char* filename, LogLevel l); 42 | void logger_quit(); 43 | 44 | #ifdef _DEBUG 45 | #define LOG(level) logg(level, __FILE__, __LINE__) 46 | #else 47 | #define LOG(level) logg(level) 48 | #endif 49 | -------------------------------------------------------------------------------- /io/PakLoader.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "ResourceTypes.h" 8 | 9 | #define PAK_FILE_TYPE "pak" 10 | 11 | class PakLoader 12 | { 13 | typedef struct 14 | { 15 | ResourcePtr ptr; 16 | FILE* fp; 17 | } PakPtr; 18 | 19 | std::map m_pakFiles; //Maps resource IDs to particular pak files 20 | std::vector openedFiles; //Keeps track of all opened file handles so we can close them easily 21 | 22 | void parseFile(const std::string& sFileName); 23 | 24 | PakLoader() {}; 25 | 26 | public: 27 | PakLoader(const std::string& sDirName); 28 | ~PakLoader(); 29 | 30 | void clear(); 31 | void loadFromDir(const std::string& sDirName); 32 | 33 | //Load a resource from the opened pak files. Returns NULL if it's not here or on error, 34 | // returns a pointer to the data otherwise. This pointer must be delete[]d. 35 | unsigned char* loadResource(uint64_t id, unsigned int* len = NULL); 36 | }; -------------------------------------------------------------------------------- /io/StringUtils.h: -------------------------------------------------------------------------------- 1 | /* 2 | GameEngine header - StringUtils.h 3 | Utility functions for parsing strings 4 | Copyright (c) 2014 Mark Hutcheson 5 | */ 6 | #pragma once 7 | 8 | #include "rapidjson/document.h" 9 | #include 10 | 11 | //-------------------------------------------------- 12 | // Parsing functions 13 | //-------------------------------------------------- 14 | namespace StringUtils 15 | { 16 | //Trim whitespace from beginning & end of string 17 | std::string trim(const std::string& s); 18 | 19 | //Strip all whitespace from s 20 | std::string removeWhitespace(const std::string& s); 21 | 22 | //Strip all of "from" from s, leaving "to" in their place 23 | std::string replaceWith(const std::string& s, char from, char to); 24 | 25 | //Shorthand for replaceWith(s, ',', ' ') 26 | std::string stripCommas(const std::string& s); 27 | 28 | //Get the file extension (not including the dot) from a filename, or empty string if there is none 29 | // For example: if filename is "image.png", then getExtension(filename) will be "png" 30 | std::string getExtension(const std::string& filename); 31 | 32 | std::string getFilename(const std::string& path); //Get the filename from the given path 33 | 34 | std::string normalize(const std::string& input); //Normalizes this string to all uppercase, no punctuation 35 | 36 | std::string stringify(const rapidjson::Document& doc); //Stringifies the passed-in JSON doc 37 | } 38 | 39 | -------------------------------------------------------------------------------- /io/rapidjson/internal/strfunc.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_INTERNAL_STRFUNC_H_ 16 | #define RAPIDJSON_INTERNAL_STRFUNC_H_ 17 | 18 | #include "../stream.h" 19 | 20 | RAPIDJSON_NAMESPACE_BEGIN 21 | namespace internal { 22 | 23 | //! Custom strlen() which works on different character types. 24 | /*! \tparam Ch Character type (e.g. char, wchar_t, short) 25 | \param s Null-terminated input string. 26 | \return Number of characters in the string. 27 | \note This has the same semantics as strlen(), the return value is not number of Unicode codepoints. 28 | */ 29 | template 30 | inline SizeType StrLen(const Ch* s) { 31 | const Ch* p = s; 32 | while (*p) ++p; 33 | return SizeType(p - s); 34 | } 35 | 36 | //! Returns number of code points in a encoded string. 37 | template 38 | bool CountStringCodePoint(const typename Encoding::Ch* s, SizeType length, SizeType* outCount) { 39 | GenericStringStream is(s); 40 | const typename Encoding::Ch* end = s + length; 41 | SizeType count = 0; 42 | while (is.src_ < end) { 43 | unsigned codepoint; 44 | if (!Encoding::Decode(is, &codepoint)) 45 | return false; 46 | count++; 47 | } 48 | *outCount = count; 49 | return true; 50 | } 51 | 52 | } // namespace internal 53 | RAPIDJSON_NAMESPACE_END 54 | 55 | #endif // RAPIDJSON_INTERNAL_STRFUNC_H_ 56 | -------------------------------------------------------------------------------- /io/rapidjson/internal/swap.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_INTERNAL_SWAP_H_ 16 | #define RAPIDJSON_INTERNAL_SWAP_H_ 17 | 18 | #include "../rapidjson.h" 19 | 20 | #if defined(__clang__) 21 | RAPIDJSON_DIAG_PUSH 22 | RAPIDJSON_DIAG_OFF(c++98-compat) 23 | #endif 24 | 25 | RAPIDJSON_NAMESPACE_BEGIN 26 | namespace internal { 27 | 28 | //! Custom swap() to avoid dependency on C++ header 29 | /*! \tparam T Type of the arguments to swap, should be instantiated with primitive C++ types only. 30 | \note This has the same semantics as std::swap(). 31 | */ 32 | template 33 | inline void Swap(T& a, T& b) RAPIDJSON_NOEXCEPT { 34 | T tmp = a; 35 | a = b; 36 | b = tmp; 37 | } 38 | 39 | } // namespace internal 40 | RAPIDJSON_NAMESPACE_END 41 | 42 | #if defined(__clang__) 43 | RAPIDJSON_DIAG_POP 44 | #endif 45 | 46 | #endif // RAPIDJSON_INTERNAL_SWAP_H_ 47 | -------------------------------------------------------------------------------- /io/rapidjson/memorybuffer.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_MEMORYBUFFER_H_ 16 | #define RAPIDJSON_MEMORYBUFFER_H_ 17 | 18 | #include "stream.h" 19 | #include "internal/stack.h" 20 | 21 | RAPIDJSON_NAMESPACE_BEGIN 22 | 23 | //! Represents an in-memory output byte stream. 24 | /*! 25 | This class is mainly for being wrapped by EncodedOutputStream or AutoUTFOutputStream. 26 | 27 | It is similar to FileWriteBuffer but the destination is an in-memory buffer instead of a file. 28 | 29 | Differences between MemoryBuffer and StringBuffer: 30 | 1. StringBuffer has Encoding but MemoryBuffer is only a byte buffer. 31 | 2. StringBuffer::GetString() returns a null-terminated string. MemoryBuffer::GetBuffer() returns a buffer without terminator. 32 | 33 | \tparam Allocator type for allocating memory buffer. 34 | \note implements Stream concept 35 | */ 36 | template 37 | struct GenericMemoryBuffer { 38 | typedef char Ch; // byte 39 | 40 | GenericMemoryBuffer(Allocator* allocator = 0, size_t capacity = kDefaultCapacity) : stack_(allocator, capacity) {} 41 | 42 | void Put(Ch c) { *stack_.template Push() = c; } 43 | void Flush() {} 44 | 45 | void Clear() { stack_.Clear(); } 46 | void ShrinkToFit() { stack_.ShrinkToFit(); } 47 | Ch* Push(size_t count) { return stack_.template Push(count); } 48 | void Pop(size_t count) { stack_.template Pop(count); } 49 | 50 | const Ch* GetBuffer() const { 51 | return stack_.template Bottom(); 52 | } 53 | 54 | size_t GetSize() const { return stack_.GetSize(); } 55 | 56 | static const size_t kDefaultCapacity = 256; 57 | mutable internal::Stack stack_; 58 | }; 59 | 60 | typedef GenericMemoryBuffer<> MemoryBuffer; 61 | 62 | //! Implement specialized version of PutN() with memset() for better performance. 63 | template<> 64 | inline void PutN(MemoryBuffer& memoryBuffer, char c, size_t n) { 65 | std::memset(memoryBuffer.stack_.Push(n), c, n * sizeof(c)); 66 | } 67 | 68 | RAPIDJSON_NAMESPACE_END 69 | 70 | #endif // RAPIDJSON_MEMORYBUFFER_H_ 71 | -------------------------------------------------------------------------------- /io/rapidjson/ostreamwrapper.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_OSTREAMWRAPPER_H_ 16 | #define RAPIDJSON_OSTREAMWRAPPER_H_ 17 | 18 | #include "stream.h" 19 | #include 20 | 21 | #ifdef __clang__ 22 | RAPIDJSON_DIAG_PUSH 23 | RAPIDJSON_DIAG_OFF(padded) 24 | #endif 25 | 26 | RAPIDJSON_NAMESPACE_BEGIN 27 | 28 | //! Wrapper of \c std::basic_ostream into RapidJSON's Stream concept. 29 | /*! 30 | The classes can be wrapped including but not limited to: 31 | 32 | - \c std::ostringstream 33 | - \c std::stringstream 34 | - \c std::wpstringstream 35 | - \c std::wstringstream 36 | - \c std::ifstream 37 | - \c std::fstream 38 | - \c std::wofstream 39 | - \c std::wfstream 40 | 41 | \tparam StreamType Class derived from \c std::basic_ostream. 42 | */ 43 | 44 | template 45 | class BasicOStreamWrapper { 46 | public: 47 | typedef typename StreamType::char_type Ch; 48 | BasicOStreamWrapper(StreamType& stream) : stream_(stream) {} 49 | 50 | void Put(Ch c) { 51 | stream_.put(c); 52 | } 53 | 54 | void Flush() { 55 | stream_.flush(); 56 | } 57 | 58 | // Not implemented 59 | char Peek() const { RAPIDJSON_ASSERT(false); return 0; } 60 | char Take() { RAPIDJSON_ASSERT(false); return 0; } 61 | size_t Tell() const { RAPIDJSON_ASSERT(false); return 0; } 62 | char* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } 63 | size_t PutEnd(char*) { RAPIDJSON_ASSERT(false); return 0; } 64 | 65 | private: 66 | BasicOStreamWrapper(const BasicOStreamWrapper&); 67 | BasicOStreamWrapper& operator=(const BasicOStreamWrapper&); 68 | 69 | StreamType& stream_; 70 | }; 71 | 72 | typedef BasicOStreamWrapper OStreamWrapper; 73 | typedef BasicOStreamWrapper WOStreamWrapper; 74 | 75 | #ifdef __clang__ 76 | RAPIDJSON_DIAG_POP 77 | #endif 78 | 79 | RAPIDJSON_NAMESPACE_END 80 | 81 | #endif // RAPIDJSON_OSTREAMWRAPPER_H_ 82 | -------------------------------------------------------------------------------- /net/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(net_src 2 | minihttp.cpp 3 | minihttp.h 4 | MutexLock.cpp 5 | MutexLock.h 6 | NetworkThread.cpp 7 | NetworkThread.h 8 | SteelSeriesClient.h 9 | SteelSeriesClient.cpp 10 | SteelSeriesEvents.h 11 | SteelSeriesHaptic.h 12 | SteelSeriesHaptic.cpp 13 | ThreadsafeQueue.h 14 | ) 15 | 16 | include_directories (.) 17 | 18 | add_library(net ${net_src}) 19 | #target_link_libraries(engine imgui lua53 io ${BOX2D_LIBRARY} ${SDL2_LIBRARY}) 20 | -------------------------------------------------------------------------------- /net/MutexLock.cpp: -------------------------------------------------------------------------------- 1 | #include "MutexLock.h" 2 | #include "MutexLock.h" 3 | #include 4 | 5 | MutexLock::MutexLock(SDL_mutex * m) 6 | { 7 | mutex = m; 8 | assert(!SDL_LockMutex(m)); 9 | } 10 | 11 | MutexLock::~MutexLock() 12 | { 13 | assert(!SDL_UnlockMutex(mutex)); 14 | } 15 | -------------------------------------------------------------------------------- /net/MutexLock.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "SDL_mutex.h" 3 | 4 | class MutexLock 5 | { 6 | SDL_mutex *mutex; 7 | 8 | MutexLock() {}; 9 | public: 10 | MutexLock(SDL_mutex *m); 11 | ~MutexLock(); 12 | }; -------------------------------------------------------------------------------- /net/NetworkThread.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace NetworkThread 5 | { 6 | typedef struct 7 | { 8 | std::string data; 9 | std::string url; 10 | } NetworkMessage; 11 | 12 | bool start(); //Start the networking thread 13 | bool stop(); //Stop the networking thread 14 | bool send(NetworkMessage message); //Send the specified data to the specified URL 15 | } -------------------------------------------------------------------------------- /net/SteelSeriesClient.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "rapidjson/document.h" 3 | #include 4 | 5 | class SteelSeriesClient 6 | { 7 | bool valid; 8 | float heartbeatTimer; 9 | std::string url; 10 | std::string appId; 11 | 12 | std::string getSSURL(); //Get the URL for communicating with SteelSeries devices 13 | bool registerApp(const std::string& ID, const std::string& displayName); //Registers the application 14 | bool sendJSON(const std::string& stringifiedJSON, const char* endpoint); //Sends this JSON to the specified endpoint 15 | void heartbeat(); //Call this every so often so that SteelSeries drivers don't drop us 16 | 17 | public: 18 | SteelSeriesClient(); 19 | ~SteelSeriesClient(); 20 | 21 | bool isValid() { return valid; }; //Call after constructor to determine if the SS engine exists or not 22 | 23 | bool init(const std::string& appName); //Register ourselves with SteelSeries with the given app name 24 | void update(float dt); //Update (Call every frame) 25 | 26 | void bindEvent(const std::string& eventJSON); //Create an event with this (stringified) JSON 27 | void sendEvent(const std::string& eventId, int value); //Send an update to this event 28 | 29 | std::string getAppId() { return appId; } 30 | }; 31 | -------------------------------------------------------------------------------- /net/SteelSeriesHaptic.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | class SteelSeriesClient; 6 | 7 | class SteelSeriesHaptic 8 | { 9 | private: 10 | SteelSeriesClient* ssClient; 11 | 12 | void bindEvent(const std::string& eventId, const std::string& eventType, uint32_t rumbleLen); 13 | 14 | public: 15 | SteelSeriesHaptic(SteelSeriesClient* client); 16 | ~SteelSeriesHaptic(); 17 | 18 | void init(); 19 | bool isValid(); 20 | 21 | //Strength in range 0-1, duration in msec, curTime current clock time in seconds 22 | void rumble(float strength, uint32_t duration, float curTime); 23 | }; -------------------------------------------------------------------------------- /net/ThreadsafeQueue.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include "MutexLock.h" 5 | #include "SDL_mutex.h" 6 | 7 | template 8 | class ThreadsafeQueue 9 | { 10 | std::queue q; 11 | SDL_mutex *mutex; 12 | 13 | public: 14 | ThreadsafeQueue(); 15 | ~ThreadsafeQueue(); 16 | 17 | 18 | bool pop(T& s); //returns true on success, false on failure 19 | void push(const T& x); 20 | }; 21 | 22 | 23 | template 24 | ThreadsafeQueue::ThreadsafeQueue() 25 | { 26 | mutex = SDL_CreateMutex(); 27 | assert(mutex); 28 | } 29 | 30 | template 31 | ThreadsafeQueue::~ThreadsafeQueue() 32 | { 33 | SDL_DestroyMutex(mutex); 34 | } 35 | 36 | template 37 | bool ThreadsafeQueue::pop(T& s) 38 | { 39 | MutexLock lock(mutex); 40 | if(q.empty()) 41 | return false; 42 | s = q.front(); 43 | q.pop(); 44 | return true; 45 | } 46 | 47 | template 48 | void ThreadsafeQueue::push(const T& x) 49 | { 50 | MutexLock lock(mutex); 51 | q.push(x); 52 | } 53 | -------------------------------------------------------------------------------- /res/lua/init.lua: -------------------------------------------------------------------------------- 1 | --Fix obvious exploits 2 | --NOTE: Does not mean that scripts are safe or sandboxed! 3 | os = nil 4 | io = nil 5 | 6 | 7 | --Set global variables in global var table 8 | local function setglobal(name, v) 9 | rawset(_G, name, v) 10 | end 11 | setglobal("setglobal", setglobal) 12 | 13 | local classes = {} --List of all loaded classes (so we know to reload them) 14 | 15 | --Load a class' lua definition from a string 16 | local function loadclass(s, def) 17 | if rawget(_G, s) == nil then 18 | local classFunc = load(def) 19 | local cls = classFunc() 20 | setglobal(s, cls) 21 | local reg = debug.getregistry() --HACK 22 | reg[s] = cls 23 | classes[s] = true 24 | end 25 | end 26 | setglobal("loadclass", loadclass) 27 | 28 | --Clear all loaded classes so we'll reload them when we call loadclass() again 29 | local function clearClasses() 30 | for k, v in pairs(classes) do 31 | rawset(_G, k, nil) 32 | classes[k] = nil 33 | end 34 | end 35 | setglobal("clearClasses", clearClasses) 36 | 37 | --Lua entry point after all game engine loading is done 38 | local function loadLua(map) 39 | if map == nil then 40 | mouse_setCursor("res/cursor/arrow.xml") 41 | map = "res/map/solarsystem.scene.xml" 42 | end 43 | map_load(map) 44 | end 45 | setglobal("loadLua", loadLua) 46 | 47 | --Load our math functions 48 | local mathfunc = load(resource_loadText("res/lua/math.lua")) 49 | mathfunc() 50 | -------------------------------------------------------------------------------- /res/lua/math.lua: -------------------------------------------------------------------------------- 1 | --Math functions yaaay 2 | 3 | --Find the length of a given vector 4 | local function vec2_length(x, y) 5 | local length = math.sqrt((x*x)+(y*y)) 6 | return length 7 | end 8 | setglobal("vec2_length", vec2_length) 9 | 10 | --Normalize a given vector (make the length = 1) 11 | local function vec2_normalize(x, y) 12 | local length = vec2_length(x,y) 13 | if length == 0 then 14 | return x, y 15 | end 16 | return x/length, y/length 17 | end 18 | setglobal("vec2_normalize", vec2_normalize) 19 | 20 | --Multiply a given vector by a scaling factor 21 | local function vec2_mul(x,y,fac) 22 | if fac then 23 | return x * fac, y * fac 24 | end 25 | return x, y 26 | end 27 | setglobal("vec2_mul", vec2_mul) 28 | 29 | --Get the angle a vector is pointing in 30 | local function vec2_angle(x,y) 31 | return math.atan(y,x) 32 | end 33 | setglobal("vec2_angle", vec2_angle) -------------------------------------------------------------------------------- /res/lua/node/gravwell.lua: -------------------------------------------------------------------------------- 1 | local gravwell = {} 2 | gravwell.__index = gravwell 3 | 4 | --Called when this node is created 5 | function gravwell:init() 6 | self.force = tonumber(node_getProperty(self, "force")) 7 | --self.rad = tonumber(node_getProperty(self, "radius")) 8 | self.posx, self.posy = node_getPos(self) 9 | end 10 | 11 | --Called when an object enters this node 12 | function gravwell:collide(object) 13 | local objx, objy = obj_getPos(object) 14 | 15 | --Get vector from object to me 16 | local x = objx - self.posx 17 | local y = objy - self.posy 18 | 19 | --Save distance between me and object 20 | local dist = vec2_length(x,y) 21 | 22 | --Don't divide by zero; if it's centered over us, just don't apply force this frame 23 | if dist == 0 then return end 24 | 25 | --Normalize the obj->me vector 26 | x,y = vec2_normalize(x,y) 27 | 28 | --Find force we need 29 | local force = self.force / (dist * dist) --Note: splodes physics when you get too close 30 | 31 | --Multiply the direction vector by this force 32 | x,y = vec2_mul(x, y, force) 33 | 34 | --Apply the force 35 | obj_applyForce(object, x, y) 36 | end 37 | 38 | --Called every timestep to update the node 39 | function gravwell:update(dt) 40 | end 41 | 42 | --Called when node is destroyed 43 | function gravwell:destroy() 44 | end 45 | 46 | return gravwell -------------------------------------------------------------------------------- /res/lua/node/heartbeat.lua: -------------------------------------------------------------------------------- 1 | local heartbeat = {} 2 | heartbeat.__index = heartbeat 3 | 4 | --Called when this node is created 5 | function heartbeat:init() 6 | self.curTime = 0 7 | self.last = 0 8 | self.dub = false 9 | self.offset = 0.85 10 | self.duboffset = 0.15 11 | 12 | self.amplitude = 1.0 13 | self.decay = 0.05 14 | --ss_bindEvent("res/json/heartbeat.json") 15 | self.eventName = "HEARTBEAT" 16 | self.val = 0 17 | end 18 | 19 | --Called when an object enters this node 20 | function heartbeat:collide(object) 21 | end 22 | 23 | --Called every timestep to update the node 24 | function heartbeat:update(dt) 25 | self.curTime = self.curTime + dt 26 | 27 | if self.curTime - self.last >= self.offset then 28 | controller_rumbleLR(95, self.amplitude, 0.0) 29 | --ss_sendEvent(self.eventName, self.val) 30 | self.val = self.val + 1 31 | if self.val > 100 then 32 | self.val = 0 33 | end 34 | self.last = self.curTime 35 | self.dub = false 36 | end 37 | 38 | if self.curTime - self.last >= self.duboffset and self.dub == false then 39 | controller_rumbleLR(30, 0.0, self.amplitude) 40 | self.dub = true 41 | --self.amplitude = self.amplitude - self.decay 42 | --if self.amplitude <= 0 then 43 | -- self.amplitude = 1.0 44 | --end 45 | end 46 | 47 | end 48 | 49 | --Called when node is destroyed 50 | function heartbeat:destroy() 51 | end 52 | 53 | return heartbeat -------------------------------------------------------------------------------- /res/lua/node/linearforcefield.lua: -------------------------------------------------------------------------------- 1 | local linearforcefield = {} 2 | linearforcefield.__index = linearforcefield 3 | 4 | --Called when this node is created 5 | function linearforcefield:init() 6 | self.forcex, self.forcey = node_getVec2Property(self, "force") 7 | 8 | --print('force: '..self.forcex..', '..self.forcey) 9 | end 10 | 11 | --Called when an object enters this node 12 | function linearforcefield:collide(object) 13 | obj_applyForce(object, self.forcex, self.forcey) 14 | end 15 | 16 | --Called every timestep to update the node 17 | function linearforcefield:update(dt) 18 | end 19 | 20 | --Called when node is destroyed 21 | function linearforcefield:destroy() 22 | end 23 | 24 | return linearforcefield -------------------------------------------------------------------------------- /res/lua/node/loadmap.lua: -------------------------------------------------------------------------------- 1 | local loadmap = {} 2 | loadmap.__index = loadmap 3 | 4 | --Called when this node is created 5 | function loadmap:init() 6 | self.mapfile = node_getProperty(self, "map") 7 | self.mapnode = node_getProperty(self, "node") 8 | --print('durr ' .. self.mapnode) 9 | end 10 | 11 | --Called when an object enters this node 12 | function loadmap:collide(object) 13 | --Load a new map when the player collides with this node 14 | if object == obj_getPlayer() then 15 | map_load(self.mapfile, self.mapnode) 16 | --print('durr ' .. self.mapnode) 17 | end 18 | end 19 | 20 | --Called every timestep to update the node 21 | function loadmap:update(dt) 22 | end 23 | 24 | --Called when node is destroyed 25 | function loadmap:destroy() 26 | end 27 | 28 | return loadmap -------------------------------------------------------------------------------- /res/lua/node/notereceiver.lua: -------------------------------------------------------------------------------- 1 | local notereceiver = {} 2 | notereceiver.__index = notereceiver 3 | 4 | --Called when this node is created 5 | function notereceiver:init() 6 | self.X, self.Y = node_getPos(self) 7 | self.DIRECTION = node_getProperty(self, "direction") 8 | self.RADIUS = tonumber(node_getProperty(self, "radius")) 9 | self.PRESS = false 10 | self.KEYDOWN = false 11 | 12 | if self.DIRECTION == "up" then 13 | self.ACTION_DIR = NOTE_UP 14 | elseif self.DIRECTION == "down" then 15 | self.ACTION_DIR = NOTE_DOWN 16 | elseif self.DIRECTION == "left" then 17 | self.ACTION_DIR = NOTE_LEFT 18 | elseif self.DIRECTION == "right" then 19 | self.ACTION_DIR = NOTE_RIGHT 20 | end 21 | end 22 | 23 | --Test to see if a point is inside this node 24 | function notereceiver:isInside(x, y) 25 | local distance = vec2_length(x - self.X, y - self.Y) 26 | if distance <= self.RADIUS then 27 | return true 28 | end 29 | return false 30 | end 31 | 32 | --Called when an object enters this node 33 | function notereceiver:collide(object) 34 | local objx, objy = obj_getPos(object) 35 | local inside = self:isInside(objx, objy) 36 | 37 | if inside and self.PRESS then 38 | obj_destroy(object) 39 | --print "hit" 40 | elseif not inside then 41 | if self.DIRECTION == "up" then 42 | if objy < self.Y then 43 | obj_destroy(object) 44 | --print "miss" 45 | end 46 | elseif self.DIRECTION == "down" then 47 | if objy > self.Y then 48 | obj_destroy(object) 49 | --print "miss" 50 | end 51 | elseif self.DIRECTION == "left" then 52 | if objx > self.X then 53 | obj_destroy(object) 54 | --print "miss" 55 | end 56 | elseif self.DIRECTION == "right" then 57 | if objx < self.X then 58 | obj_destroy(object) 59 | --print "miss" 60 | end 61 | end 62 | end 63 | end 64 | 65 | --Called every timestep to update the node 66 | function notereceiver:update(dt) 67 | 68 | --Update key-down state 69 | if action_digital(self.ACTION_DIR) then 70 | if self.KEYDOWN == false then 71 | self.PRESS = true 72 | sound_play('res/sfx/laser.wav') 73 | --print (self.DIRECTION.." pos: "..music_getPos()) 74 | else 75 | self.PRESS = false 76 | end 77 | self.KEYDOWN = true 78 | else 79 | self.KEYDOWN = false 80 | self.PRESS = false 81 | end 82 | 83 | end 84 | 85 | --Called when node is destroyed 86 | function notereceiver:destroy() 87 | end 88 | 89 | return notereceiver 90 | -------------------------------------------------------------------------------- /res/lua/node/radialforcefield.lua: -------------------------------------------------------------------------------- 1 | local radialforcefield = {} 2 | radialforcefield.__index = radialforcefield 3 | 4 | --Called when this node is created 5 | function radialforcefield:init() 6 | self.forcecenter = tonumber(node_getProperty(self, "forceatcenter")) 7 | self.forceedge = tonumber(node_getProperty(self, "forceatedge")) 8 | self.rad = tonumber(node_getProperty(self, "radius")) 9 | self.posx, self.posy = node_getPos(self) 10 | end 11 | 12 | --Called when an object enters this node 13 | function radialforcefield:collide(object) 14 | local objx, objy = obj_getPos(object) 15 | 16 | --Get vector from object to me 17 | local x = objx - self.posx 18 | local y = objy - self.posy 19 | 20 | --Save distance between me and object 21 | local dist = vec2_length(x,y) 22 | 23 | --Don't divide by zero; if it's centered over us, just don't apply force this frame 24 | --Also ignore if they're outside our radius (so we don't push away because math) 25 | if dist == 0 or dist > self.rad then return end 26 | 27 | --Normalize the obj->me vector 28 | x,y = vec2_normalize(x,y) 29 | 30 | --Find force we need 31 | local fac = dist / self.rad --Factor for how far away from me the object is 32 | 33 | --lerp force applied between forceatcenter and forceatedge 34 | local force = fac * (self.forceedge - self.forcecenter) + self.forcecenter 35 | 36 | --Multiply the direction vector by this force 37 | x,y = vec2_mul(x, y, force) 38 | 39 | --Apply the force 40 | obj_applyForce(object, x, y) 41 | end 42 | 43 | --Called every timestep to update the node 44 | function radialforcefield:update(dt) 45 | end 46 | 47 | --Called when node is destroyed 48 | function radialforcefield:destroy() 49 | end 50 | 51 | return radialforcefield -------------------------------------------------------------------------------- /res/lua/node/template.lua: -------------------------------------------------------------------------------- 1 | local template = {} 2 | template.__index = template 3 | 4 | --Called when this node is created 5 | function template:init() 6 | end 7 | 8 | --Called when an object enters this node 9 | function template:collide(object) 10 | end 11 | 12 | --Called every timestep to update the node 13 | function template:update(dt) 14 | end 15 | 16 | --Called when node is destroyed 17 | function template:destroy() 18 | end 19 | 20 | return template -------------------------------------------------------------------------------- /res/lua/node/test.lua: -------------------------------------------------------------------------------- 1 | local test = {} 2 | test.__index = test 3 | test.name = "test" 4 | 5 | --Called when this node is created 6 | function test:init() 7 | --TODO 8 | --local strength = node_getProperty(self, "strength") 9 | --print('node ' .. self.name .. ' created with strength = '..strength) 10 | --self.strength = strength 11 | end 12 | 13 | --Called when an object enters this node 14 | function test:collide(object) 15 | --TODO 16 | --local x,y = obj_getPos(object) 17 | 18 | --print(self.name .. ' colliding with object at '..x..', '..y..' '..self.strength) 19 | end 20 | 21 | --Called every timestep to update the node 22 | function test:update(dt) 23 | --TODO 24 | end 25 | 26 | --Called when node is destroyed 27 | function test:destroy() 28 | --TODO 29 | --print('node ' .. self.name .. ' destroyed!') 30 | end 31 | 32 | return test -------------------------------------------------------------------------------- /res/lua/obj/bounce.lua: -------------------------------------------------------------------------------- 1 | local bounce = {} 2 | bounce.__index = bounce 3 | 4 | function bounce:init() 5 | self.SEG = 0 6 | self.NUM = 6 7 | self.ADD_FAC = 1.25 8 | self.FALL_FAC = 0.15 9 | self.SIZE_X, self.SIZE_Y = seg_getSize(self, self.SEG) 10 | self.CUR_X = self.SIZE_X 11 | self.CUR_Y = self.SIZE_Y 12 | self.MAX_X = self.SIZE_X * 2.0 13 | self.MAX_Y = self.SIZE_Y * 2.0 14 | end 15 | 16 | function bounce:collide(other) 17 | end 18 | 19 | function bounce:collidewall(wallnormalX, wallnormalY) 20 | end 21 | 22 | function bounce:update(dt) 23 | local channel = music_getChannel() 24 | local spectrum = table.pack(music_spectrum(channel, self.NUM)) 25 | 26 | --Error check 27 | if spectrum[self.NUM] == nil then 28 | return 29 | end 30 | 31 | --print(self.CHANNEL, spectrum[1]) 32 | --for k, v in pairs(spectrum) do 33 | -- print(k, v) 34 | --end 35 | 36 | --print(self.SIZE_X, self.SIZE_Y) 37 | 38 | --Add fac 39 | self.CUR_X = self.CUR_X + self.ADD_FAC * spectrum[self.NUM] 40 | self.CUR_Y = self.CUR_Y + self.ADD_FAC * spectrum[self.NUM] 41 | 42 | --Bounds check 43 | if self.CUR_X > self.MAX_X then 44 | self.CUR_X = self.MAX_X 45 | end 46 | if self.CUR_Y > self.MAX_Y then 47 | self.CUR_Y = self.MAX_Y 48 | end 49 | 50 | --Set size for this frame 51 | seg_setSize(self, self.SEG, self.CUR_X, self.CUR_Y) 52 | 53 | --Fall back for next frame 54 | self.CUR_X = self.CUR_X - self.FALL_FAC 55 | self.CUR_Y = self.CUR_Y - self.FALL_FAC 56 | 57 | --Bounds check 58 | if self.CUR_X < self.SIZE_X then 59 | self.CUR_X = self.SIZE_X 60 | end 61 | if self.CUR_Y < self.SIZE_Y then 62 | self.CUR_Y = self.SIZE_Y 63 | end 64 | end 65 | 66 | function bounce:destroy() 67 | end 68 | 69 | return bounce 70 | -------------------------------------------------------------------------------- /res/lua/obj/marble.lua: -------------------------------------------------------------------------------- 1 | local marble = {} 2 | marble.__index = marble 3 | 4 | --Called when this node is created 5 | function marble:init() 6 | local id = obj_getProperty(self, "id") 7 | obj_setImage(self, "res/gfx/"..id..".png") 8 | end 9 | 10 | --Called when an object enters this node 11 | function marble:collide(object) 12 | end 13 | 14 | --Called when this object hits a wall 15 | function marble:collidewall(wallnormalX, wallnormalY) 16 | end 17 | 18 | --Called every timestep to update the node 19 | function marble:update(dt) 20 | end 21 | 22 | --Called when node is destroyed 23 | function marble:destroy() 24 | end 25 | 26 | return marble -------------------------------------------------------------------------------- /res/lua/obj/notereceiver.lua: -------------------------------------------------------------------------------- 1 | local notereceiver = {} 2 | notereceiver.__index = notereceiver 3 | 4 | function notereceiver:init() 5 | self.SEG = 0 6 | self.SIZE_X, self.SIZE_Y = seg_getSize(self, self.SEG) 7 | local posprop = obj_getProperty(self, "pos") 8 | local i = 1 9 | local posx = 0 10 | local posy = 0 11 | --TODO: We need to get the obj position from XML cause this is silly 12 | for str in string.gmatch(posprop, "([^,]+)") do 13 | str = str:gsub("^%s*(.-)%s*$", "%1") 14 | if i == 1 then 15 | posx = tonumber(str) 16 | elseif i == 2 then 17 | posy = tonumber(str) 18 | end 19 | i = i + 1 20 | end 21 | 22 | --Set segment position 23 | seg_setPos(self, self.SEG, posx, posy) 24 | 25 | --Set image 26 | local imgProp = obj_getProperty(self, "img") 27 | obj_setImage(self, imgProp, self.SEG) 28 | 29 | --Get direction 30 | local dir = obj_getProperty(self, "direction"); 31 | if dir == "up" then 32 | self.DIR = NOTE_UP 33 | elseif dir == "down" then 34 | self.DIR = NOTE_DOWN 35 | elseif dir == "left" then 36 | self.DIR = NOTE_LEFT 37 | else 38 | self.DIR = NOTE_RIGHT 39 | end 40 | end 41 | 42 | function notereceiver:collide(other) 43 | end 44 | 45 | function notereceiver:collidewall(wallnormalX, wallnormalY) 46 | end 47 | 48 | function notereceiver:update(dt) 49 | 50 | local cur_x = self.SIZE_X 51 | local cur_y = self.SIZE_Y 52 | 53 | if action_digital(self.DIR) then 54 | cur_x = cur_x / 1.1 55 | cur_y = cur_y / 1.1 56 | end 57 | 58 | --Set size for this frame 59 | seg_setSize(self, self.SEG, cur_x, cur_y) 60 | end 61 | 62 | function notereceiver:destroy() 63 | end 64 | 65 | return notereceiver 66 | -------------------------------------------------------------------------------- /res/lua/obj/soundband.lua: -------------------------------------------------------------------------------- 1 | local soundband = {} 2 | soundband.__index = soundband 3 | 4 | function soundband:init() 5 | self.NUM = 16 6 | self.HEIGHT = 2.5 7 | self.SIZE_X, self.SIZE_Y = seg_getSize(self, 0) 8 | self.POS_X, self.POS_Y = seg_getPos(self, 0) 9 | self.SIDE = obj_getProperty(self, 'side') 10 | end 11 | 12 | function soundband:collide(other) 13 | end 14 | 15 | function soundband:collidewall(wallnormalX, wallnormalY) 16 | end 17 | 18 | function soundband:update(dt) 19 | local channel = music_getChannel() 20 | local spectrum 21 | if self.SIDE == 'r' then 22 | spectrum = table.pack(music_spectrumR(channel, self.NUM)) 23 | elseif self.SIDE == 'l' then 24 | spectrum = table.pack(music_spectrumL(channel, self.NUM)) 25 | else 26 | spectrum = table.pack(music_spectrum(channel, self.NUM)) 27 | end 28 | 29 | --Error check 30 | if spectrum[1] == nil then 31 | return 32 | end 33 | 34 | local count = self.NUM - 1 35 | 36 | for i = 0, count do 37 | local fac = spectrum[i + 1] * self.HEIGHT 38 | --Set size for this frame 39 | seg_setSize(self, i, self.SIZE_X, fac) 40 | local x, y = seg_getPos(self, i) 41 | seg_setPos(self, i, x, self.POS_Y + fac / 2) --Center so that bottom stays still 42 | end 43 | end 44 | 45 | function soundband:destroy() 46 | end 47 | 48 | return soundband 49 | -------------------------------------------------------------------------------- /res/lua/obj/templateobj.lua: -------------------------------------------------------------------------------- 1 | local templateobj = {} 2 | templateobj.__index = templateobj 3 | 4 | function templateobj:init() 5 | end 6 | 7 | function templateobj:collide(other) 8 | end 9 | 10 | function templateobj:collidewall(wallnormalX, wallnormalY) 11 | end 12 | 13 | function templateobj:update(dt) 14 | end 15 | 16 | function templateobj:destroy() 17 | end 18 | 19 | return templateobj 20 | -------------------------------------------------------------------------------- /res/lua/obj/testblob.lua: -------------------------------------------------------------------------------- 1 | local testblob = {} 2 | testblob.__index = testblob 3 | 4 | function testblob:init() 5 | end 6 | 7 | function testblob:collide(other) 8 | end 9 | 10 | function testblob:collidewall(wallnormalX, wallnormalY) 11 | end 12 | 13 | function testblob:update(dt) 14 | --TEST 15 | if mouse_isDown() then 16 | obj_setPos(self, 0, 3) 17 | end 18 | end 19 | 20 | function testblob:destroy() 21 | end 22 | 23 | return testblob 24 | -------------------------------------------------------------------------------- /res/shaders/debugdraw.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | in vec4 incol; 4 | out vec4 outcol; 5 | 6 | void main() 7 | { 8 | outcol = incol; 9 | } 10 | 11 | -------------------------------------------------------------------------------- /res/shaders/debugdraw.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | layout(location = 0) in vec3 position; 4 | uniform mat4 model; 5 | uniform mat4 view; 6 | uniform mat4 projection; 7 | uniform vec4 col; 8 | out vec4 incol; 9 | 10 | void main() 11 | { 12 | incol = col; 13 | gl_Position = projection * view * model * vec4(position, 1.0); 14 | } 15 | -------------------------------------------------------------------------------- /res/shaders/default.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | uniform sampler2D tex; 3 | 4 | in vec2 uv; 5 | in vec4 incol; 6 | 7 | out vec4 outcol; 8 | 9 | void main() 10 | { 11 | outcol = incol * texture(tex, uv); 12 | } 13 | 14 | -------------------------------------------------------------------------------- /res/shaders/default.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | layout(location = 0) in vec3 position; 4 | uniform mat4 model; 5 | uniform mat4 view; 6 | uniform mat4 projection; 7 | out vec2 uv; 8 | out vec4 incol; 9 | 10 | void main() 11 | { 12 | incol = gl_Color; 13 | uv = gl_MultiTexCoord0.xy; 14 | gl_Position = projection * view * model * vec4(position, 1.0); 15 | } 16 | -------------------------------------------------------------------------------- /tools/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(compressor) -------------------------------------------------------------------------------- /tools/compressor/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(compressor_src 2 | images.cpp 3 | lua.cpp 4 | mesh.cpp 5 | main.cpp 6 | main.h 7 | ) 8 | 9 | add_executable(compressor ${compressor_src}) 10 | target_link_libraries(compressor lua53 io engine squish) 11 | -------------------------------------------------------------------------------- /tools/compressor/LuaMinify/CommandLineMinify.lua: -------------------------------------------------------------------------------- 1 | -- 2 | -- CommandlineMinify.lua 3 | -- 4 | -- A command line utility for minifying lua source code using the minifier. 5 | -- 6 | 7 | package.path = package.path .. ';' .. 'tools/compressor/LuaMinify/' .. '?.lua' 8 | 9 | local util = require'Util' 10 | local Parser = require'ParseLua' 11 | local Format_Mini = require'FormatMini' 12 | local ParseLua = Parser.ParseLua 13 | local PrintTable = util.PrintTable 14 | 15 | local function setglobal(name, v) 16 | rawset(_G, name, v) 17 | end 18 | setglobal("setglobal", setglobal) 19 | 20 | local function main_minify(filename) 21 | local inf = io.open(filename, 'r') 22 | if not inf then 23 | print("Failed to open `"..filename.."` for reading") 24 | return nil 25 | end 26 | -- 27 | local sourceText = inf:read('*all') 28 | inf:close() 29 | -- 30 | local st, ast = ParseLua(sourceText) 31 | if not st then 32 | --we failed to parse the file, show why 33 | print(ast) 34 | return nil 35 | end 36 | return Format_Mini(ast) 37 | end 38 | setglobal("main_minify", main_minify) 39 | -------------------------------------------------------------------------------- /tools/compressor/LuaMinify/LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2012-2013 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /tools/compressor/LuaMinify/Util.lua: -------------------------------------------------------------------------------- 1 | 2 | -- 3 | -- Util.lua 4 | -- 5 | -- Provides some common utilities shared throughout the project. 6 | -- 7 | 8 | local function lookupify(tb) 9 | for _, v in pairs(tb) do 10 | tb[v] = true 11 | end 12 | return tb 13 | end 14 | 15 | 16 | local function CountTable(tb) 17 | local c = 0 18 | for _ in pairs(tb) do c = c + 1 end 19 | return c 20 | end 21 | 22 | 23 | local function PrintTable(tb, atIndent) 24 | if tb.Print then 25 | return tb.Print() 26 | end 27 | atIndent = atIndent or 0 28 | local useNewlines = (CountTable(tb) > 1) 29 | local baseIndent = string.rep(' ', atIndent+1) 30 | local out = "{"..(useNewlines and '\n' or '') 31 | for k, v in pairs(tb) do 32 | if type(v) ~= 'function' then 33 | --do 34 | out = out..(useNewlines and baseIndent or '') 35 | if type(k) == 'number' then 36 | --nothing to do 37 | elseif type(k) == 'string' and k:match("^[A-Za-z_][A-Za-z0-9_]*$") then 38 | out = out..k.." = " 39 | elseif type(k) == 'string' then 40 | out = out.."[\""..k.."\"] = " 41 | else 42 | out = out.."["..tostring(k).."] = " 43 | end 44 | if type(v) == 'string' then 45 | out = out.."\""..v.."\"" 46 | elseif type(v) == 'number' then 47 | out = out..v 48 | elseif type(v) == 'table' then 49 | out = out..PrintTable(v, atIndent+(useNewlines and 1 or 0)) 50 | else 51 | out = out..tostring(v) 52 | end 53 | if next(tb, k) then 54 | out = out.."," 55 | end 56 | if useNewlines then 57 | out = out..'\n' 58 | end 59 | end 60 | end 61 | out = out..(useNewlines and string.rep(' ', atIndent) or '').."}" 62 | return out 63 | end 64 | 65 | 66 | local function splitLines(str) 67 | if str:match("\n") then 68 | local lines = {} 69 | for line in str:gmatch("[^\n]*") do 70 | table.insert(lines, line) 71 | end 72 | assert(#lines > 0) 73 | return lines 74 | else 75 | return { str } 76 | end 77 | end 78 | 79 | 80 | local function printf(fmt, ...) 81 | return print(string.format(fmt, ...)) 82 | end 83 | 84 | 85 | return { 86 | PrintTable = PrintTable, 87 | CountTable = CountTable, 88 | lookupify = lookupify, 89 | splitLines = splitLines, 90 | printf = printf, 91 | } 92 | -------------------------------------------------------------------------------- /tools/compressor/LuaMinify/strict.lua: -------------------------------------------------------------------------------- 1 | -- From http://metalua.luaforge.net/src/lib/strict.lua.html 2 | -- 3 | -- strict.lua 4 | -- checks uses of undeclared global variables 5 | -- All global variables must be 'declared' through a regular assignment 6 | -- (even assigning nil will do) in a main chunk before being used 7 | -- anywhere or assigned to inside a function. 8 | -- 9 | 10 | local mt = getmetatable(_G) 11 | if mt == nil then 12 | mt = {} 13 | setmetatable(_G, mt) 14 | end 15 | 16 | __STRICT = true 17 | mt.__declared = {} 18 | 19 | mt.__newindex = function (t, n, v) 20 | if __STRICT and not mt.__declared[n] then 21 | local w = debug.getinfo(2, "S").what 22 | if w ~= "main" and w ~= "C" then 23 | error("assign to undeclared variable '"..n.."'", 2) 24 | end 25 | mt.__declared[n] = true 26 | end 27 | rawset(t, n, v) 28 | end 29 | 30 | mt.__index = function (t, n) 31 | if not mt.__declared[n] and debug.getinfo(2, "S").what ~= "C" then 32 | error("variable '"..n.."' is not declared", 2) 33 | end 34 | return rawget(t, n) 35 | end 36 | 37 | function global(...) 38 | for _, v in ipairs{...} do mt.__declared[v] = true end 39 | end 40 | -------------------------------------------------------------------------------- /tools/compressor/lua.cpp: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include "LuaInterface.h" 3 | #include "Logger.h" 4 | #include "FileOperations.h" 5 | #include "lua.hpp" 6 | #include 7 | 8 | static LuaInterface* lua = NULL; 9 | 10 | unsigned char* extractLua(const std::string& luaFilename, unsigned int* size) 11 | { 12 | //Call main_minify in lua 13 | lua_State* L = lua->getState(); 14 | lua_getglobal(L, "main_minify"); 15 | lua_pushstring(L, luaFilename.c_str()); 16 | lua_call(L, 1, 1); 17 | const char* result = lua_tostring(L, -1); 18 | lua_pop(L, 1); 19 | 20 | if(result) 21 | { 22 | *size = strlen(result); 23 | unsigned char* ret = (unsigned char*)malloc(*size); 24 | memcpy(ret, result, *size); 25 | return ret; 26 | } 27 | else 28 | { 29 | std::cout << "not string" << std::endl; 30 | } 31 | return NULL; 32 | } 33 | 34 | void initLua() 35 | { 36 | logger_init("compressor_out.log", DBG); 37 | unsigned int size = 0; 38 | char* luaFile = (char*)FileOperations::readFile("tools/compressor/LuaMinify/CommandLineMinify.lua", &size); 39 | if(luaFile == NULL || size < 1) 40 | std::cout << "Unable to load lua file" << std::endl; 41 | char* nullpadded = (char*)malloc(size + 1); 42 | nullpadded[size] = '\0'; 43 | memcpy(nullpadded, luaFile, size); 44 | lua = new LuaInterface(nullpadded); 45 | free(luaFile); 46 | if(!lua->Init()) 47 | { 48 | std::cout << "Failed to init lua" << std::endl; 49 | std::cout << nullpadded << std::endl; 50 | } 51 | free(nullpadded); 52 | } 53 | 54 | void teardownLua() 55 | { 56 | delete lua; 57 | logger_quit(); 58 | } 59 | 60 | void lua_register_all(lua_State *) 61 | { 62 | //no-op to keep lua interface happy 63 | } 64 | -------------------------------------------------------------------------------- /tools/compressor/main.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "ResourceTypes.h" 4 | #include "Hash.h" 5 | 6 | //Helper struct for compression 7 | typedef struct 8 | { 9 | CompressionHeader header; 10 | uint8_t* data; 11 | unsigned int size; 12 | uint64_t id; 13 | uint32_t type; //One of the CompressionHeader types 14 | } CompressionHelper; 15 | 16 | //main.cpp 17 | void addHelper(const CompressionHelper& helper); 18 | void createCompressionHelper(CompressionHelper* helper, unsigned char* decompressed, unsigned int size); 19 | 20 | //images.cpp 21 | void addImage(const std::string& img); 22 | void packImages(const std::string& filename); 23 | unsigned char* extractImage(const std::string& filename, unsigned int* size); 24 | 25 | //mesh.cpp 26 | unsigned char* extractMesh(const std::string& objFilename, unsigned int* size); 27 | unsigned char* extract3dObject(const std::string& xmlFilename, unsigned int* size); 28 | 29 | //lua.cpp 30 | unsigned char* extractLua(const std::string& luaFilename, unsigned int* size); 31 | void initLua(); 32 | void teardownLua(); 33 | --------------------------------------------------------------------------------