├── tools ├── createDoc.sh ├── updateRepository.sh ├── metrics.sh ├── codeCheck.sh └── cppcheckToHtml.xsl ├── .coveralls.yml ├── include └── radix │ ├── core │ ├── math │ │ ├── Quaternion.hpp │ │ ├── Vector4i.hpp │ │ ├── Vector2i.hpp │ │ ├── Rectangle.hpp │ │ ├── Math.hpp │ │ ├── Matrix3f.hpp │ │ ├── Matrix4f.hpp │ │ └── Vector2ui.hpp │ ├── state │ │ ├── HandleGameFunction.hpp │ │ └── GameStateManager.hpp │ ├── gl │ │ ├── DebugOutput.hpp │ │ ├── OpenGL.hpp │ │ ├── TightDataPacker.hpp │ │ ├── VBO.hpp │ │ └── Framebuffer.hpp │ ├── file │ │ └── Path.hpp │ ├── diag │ │ ├── StdoutLogger.hpp │ │ ├── Throwables.hpp │ │ ├── AnsiConsoleLogger.hpp │ │ ├── Logger.hpp │ │ └── LogInput.hpp │ ├── event │ │ └── Event.hpp │ └── types │ │ └── TimeDelta.hpp │ ├── data │ ├── README.md │ ├── map │ │ ├── MapListLoader.hpp │ │ ├── BaseTrigger.hpp │ │ ├── Destination.hpp │ │ ├── MapLoader.hpp │ │ ├── WinTrigger.hpp │ │ ├── CustomTrigger.hpp │ │ ├── DeathTrigger.hpp │ │ ├── RadiationTrigger.hpp │ │ ├── TeleportTrigger.hpp │ │ ├── MapTrigger.hpp │ │ ├── ScriptTrigger.hpp │ │ ├── AudioTrigger.hpp │ │ ├── XmlMapLoader.hpp │ │ ├── XmlTriggerHelper.hpp │ │ └── XmlHelper.hpp │ ├── text │ │ ├── Glyph.hpp │ │ ├── FontLoader.hpp │ │ ├── Text.hpp │ │ └── Font.hpp │ ├── screen │ │ ├── Screen.hpp │ │ ├── Element.hpp │ │ ├── XmlScreenLoader.hpp │ │ └── Style.hpp │ ├── model │ │ └── Mesh.hpp │ ├── material │ │ ├── Material.hpp │ │ └── MaterialLoader.hpp │ ├── shader │ │ └── Shader.hpp │ └── texture │ │ ├── Texture.hpp │ │ └── TextureLoader.hpp │ ├── Console.hpp │ ├── Viewport.hpp │ ├── env │ ├── OperatingSystem.hpp │ ├── GameConsole.hpp │ ├── LegacyEnvironment.hpp │ ├── ArgumentsParser.hpp │ └── Util.hpp │ ├── util │ ├── sdl │ │ └── Fps.hpp │ ├── Hash.std.string.hpp │ ├── NullReference.hpp │ ├── XmlLoader.hpp │ ├── Profiling.hpp │ ├── BulletUserPtrInfo.hpp │ ├── BulletGhostPairCallbacks.hpp │ └── Hash.hpp │ ├── WindowConfigurator.hpp │ ├── input │ ├── GamePad.hpp │ ├── ChannelListener.hpp │ ├── NullInputSource.hpp │ ├── ChannelBase.hpp │ ├── Bind.hpp │ ├── InputManager.hpp │ └── Channel.hpp │ ├── entities │ ├── traits │ │ ├── SoundListenerTrait.hpp │ │ ├── SoundSourceTrait.hpp │ │ ├── SoundPhysicalMediumTrait.hpp │ │ ├── MeshDrawableTrait.hpp │ │ ├── HealthTrait.hpp │ │ ├── LightSourceTrait.hpp │ │ ├── Trait.hpp │ │ └── RigidBodyTrait.hpp │ ├── ReferencePoint.hpp │ ├── LightSource.hpp │ ├── ViewFrame.hpp │ ├── LiquidVolume.hpp │ ├── StaticModel.hpp │ ├── ContactPlayerCallback.hpp │ ├── Trigger.hpp │ └── Player.hpp │ ├── api │ ├── PlayerApi.hpp │ ├── RadixApi.hpp │ └── ScriptEngine.hpp │ ├── simulation │ ├── Player.hpp │ └── Simulation.hpp │ ├── Transform.hpp │ ├── physics │ ├── CollisionDispatcher.hpp │ ├── CollisionShapeManager.hpp │ ├── GhostPairCallback.hpp │ ├── PhysicsHelper.hpp │ ├── PhysicsDebugDraw.hpp │ └── Uncollider.hpp │ ├── renderer │ ├── PortalRenderer.hpp │ ├── SubRenderer.hpp │ ├── ScreenRenderer.hpp │ ├── TextRenderer.hpp │ └── RenderContext.hpp │ ├── GameWorld.hpp │ ├── SoundManager.hpp │ ├── Camera.hpp │ └── World.hpp ├── CTestCustom.cmake ├── source ├── util │ ├── NullReference.cpp │ ├── sdl │ │ └── Fps.cpp │ └── XmlLoader.cpp ├── data │ ├── map │ │ ├── MapLoader.cpp │ │ ├── WinTrigger.cpp │ │ ├── DeathTrigger.cpp │ │ ├── RadiationTrigger.cpp │ │ ├── MapListLoader.cpp │ │ ├── ScriptTrigger.cpp │ │ ├── AudioTrigger.cpp │ │ ├── MapTrigger.cpp │ │ └── TeleportTrigger.cpp │ ├── screen │ │ └── Element.cpp │ ├── shader │ │ └── Shader.cpp │ └── text │ │ └── FontLoader.cpp ├── core │ ├── diag │ │ ├── Logger.cpp │ │ ├── StdoutLogger.cpp │ │ └── LogInput.cpp │ ├── math │ │ ├── Vector2i.cpp │ │ ├── Vector2ui.cpp │ │ ├── Math.cpp │ │ ├── Vector2f.cpp │ │ └── Vector3f.cpp │ ├── state │ │ └── GameStateManager.cpp │ ├── gl │ │ ├── TightDataPacker.cpp │ │ ├── OpenGL.cpp │ │ └── VBO.cpp │ └── file │ │ └── Path.cpp ├── entities │ ├── traits │ │ ├── Trait.cpp │ │ ├── SoundSourceTrait.cpp │ │ ├── HealthTrait.cpp │ │ └── RigidBodyTrait.cpp │ └── StaticModel.cpp ├── env │ ├── OperatingSystem.cpp │ ├── LegacyEnvironment.cpp │ ├── GameConsole.cpp │ └── Util.cpp ├── WindowConfigurator.cpp ├── physics │ ├── CollisionDispatcher.cpp │ └── PhysicsHelper.cpp ├── simulation │ └── Player.cpp ├── renderer │ ├── PortalRenderer.cpp │ ├── SubRenderer.cpp │ ├── TextRenderer.cpp │ └── ScreenRenderer.cpp ├── Transform.cpp ├── api │ ├── RadixApi.cpp │ ├── PlayerApi.cpp │ └── ScriptEngine.cpp ├── GameWorld.cpp ├── input │ └── GamePad.cpp ├── Entity.cpp ├── World.cpp └── EntityManager.cpp ├── documentation ├── mainpage.dox └── resources │ ├── RadixEngine_icon_dark.svg │ └── style.css ├── cmake ├── FindCatch.cmake ├── FindLinenoise.cmake ├── Findjson11.cmake ├── FindVHACD.cmake ├── FindRadixEntity.cmake ├── Findeasy_profiler.cmake ├── FindAssimp.cmake ├── FindAngelScript.cmake ├── FindUnitTestPlusPlus.cmake ├── FindCXX14.cmake ├── FindTinyXML2.cmake └── FindFreeImage.cmake ├── .gitignore ├── tests ├── CMakeLists.txt ├── RotationTest.cpp └── XmlHelperTest.cpp ├── external └── json11 │ ├── CMakeLists.txt │ ├── LICENSE.txt │ └── README.md ├── .gitmodules ├── LICENSE.md ├── README.md ├── CONTRIBUTE.md └── .travis.yml /tools/createDoc.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | cd ..; 3 | doxygen; -------------------------------------------------------------------------------- /.coveralls.yml: -------------------------------------------------------------------------------- 1 | repo_token: XcgjR2KjUHOkdLygzBTf6fqDDy3neAMFA 2 | -------------------------------------------------------------------------------- /include/radix/core/math/Quaternion.hpp: -------------------------------------------------------------------------------- 1 | #include "Vector4f.hpp" 2 | -------------------------------------------------------------------------------- /include/radix/data/README.md: -------------------------------------------------------------------------------- 1 | Contains classes to represent and load data -------------------------------------------------------------------------------- /CTestCustom.cmake: -------------------------------------------------------------------------------- 1 | set(CTEST_CUSTOM_TESTS_IGNORE 2 | ${CTEST_CUSTOM_TESTS_IGNORE} 3 | ) 4 | -------------------------------------------------------------------------------- /tools/updateRepository.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | cd ..; 3 | git fetch --all 4 | git reset --hard origin/master 5 | -------------------------------------------------------------------------------- /tools/metrics.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | cd ..; 3 | find ./source -print0 | xargs -0 cccc 4 | cd .cccc; 5 | cp cccc.html index.html -------------------------------------------------------------------------------- /source/util/NullReference.cpp: -------------------------------------------------------------------------------- 1 | namespace radix { 2 | namespace util { 3 | 4 | void* getNullptr() { 5 | return nullptr; 6 | } 7 | 8 | } /* namespace util */ 9 | } /* namespace radix */ 10 | -------------------------------------------------------------------------------- /source/data/map/MapLoader.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace radix { 4 | 5 | MapLoader::MapLoader(World &w) : 6 | world(w) { 7 | } 8 | 9 | } /* namespace radix */ 10 | -------------------------------------------------------------------------------- /source/core/diag/Logger.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace radix { 4 | 5 | const char* Logger::getName() const { 6 | return "Empty logger"; 7 | } 8 | 9 | } /* namespace radix */ 10 | -------------------------------------------------------------------------------- /source/entities/traits/Trait.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace radix { 4 | namespace entities { 5 | 6 | Trait::Trait() { 7 | m_traits.emplace_back(this); 8 | } 9 | 10 | } /* namespace entities */ 11 | } /* namespace radix */ 12 | -------------------------------------------------------------------------------- /documentation/mainpage.dox: -------------------------------------------------------------------------------- 1 | /** @mainpage Main Page 2 | 3 | @anchor mainpage 4 | 5 | Welcome to the RadixEngine documentation. 6 | Check out the file World.cpp to get to a central point. 7 | 8 | For instructions on how to build the game refer to COMPILE.org in the document root. 9 | 10 | */ 11 | -------------------------------------------------------------------------------- /include/radix/Console.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_CONSOLE_HPP 2 | #define RADIX_CONSOLE_HPP 3 | 4 | #include 5 | 6 | namespace radix { 7 | 8 | class Console : public Logger { 9 | public: 10 | void render(); 11 | }; 12 | 13 | } /* namespace radix */ 14 | #endif /* RADIX_CONSOLE_HPP */ -------------------------------------------------------------------------------- /include/radix/Viewport.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_VIEWPORT_HPP 2 | #define RADIX_VIEWPORT_HPP 3 | 4 | namespace radix { 5 | 6 | struct Viewport { 7 | virtual ~Viewport() {} 8 | 9 | virtual void getSize(int *w, int *h) const = 0; 10 | }; 11 | 12 | } /* namespace radix */ 13 | 14 | #endif /* RADIX_VIEWPORT_HPP */ 15 | -------------------------------------------------------------------------------- /include/radix/env/OperatingSystem.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_OPERATING_SYSTEM_HPP 2 | #define RADIX_OPERATING_SYSTEM_HPP 3 | 4 | namespace radix { 5 | 6 | class OperatingSystem { 7 | 8 | public: 9 | static bool IsLinux(); 10 | }; 11 | 12 | } /* namespace radix */ 13 | 14 | #endif /* RADIX_OPERATING_SYSTEM_HPP */ 15 | -------------------------------------------------------------------------------- /tools/codeCheck.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -l 2 | cd ..; 3 | mkdir -p html/cppcheck/; 4 | 5 | if [ -z ${cppcheckpath+x} ]; then cppcheck --enable=all ./source --xml 2> /tmp/cppCheck.xml; else $cppcheckpath --enable=all ./source --xml 2> /tmp/cppCheck.xml; fi 6 | xsltproc -o html/cppcheck/index.html tools/cppcheckToHtml.xsl /tmp/cppCheck.xml; 7 | -------------------------------------------------------------------------------- /include/radix/env/GameConsole.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_GAME_CONSOLE_HPP 2 | #define RADIX_GAME_CONSOLE_HPP 3 | 4 | #include 5 | 6 | namespace radix { 7 | 8 | class GameConsole { 9 | public: 10 | static void run(BaseGame &game); 11 | }; 12 | 13 | } /* namespace radix */ 14 | 15 | #endif /* RADIX_GAME_CONSOLE_HPP */ 16 | -------------------------------------------------------------------------------- /source/env/OperatingSystem.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | namespace radix { 6 | 7 | bool OperatingSystem::IsLinux() { 8 | if (std::string("Linux") == SDL_GetPlatform()) { 9 | return true; 10 | } 11 | return false; 12 | } 13 | 14 | } /* namespace radix */ 15 | -------------------------------------------------------------------------------- /include/radix/core/state/HandleGameFunction.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_HANDLEGAMEFUNCTION_HPP 2 | #define RADIX_HANDLEGAMEFUNCTION_HPP 3 | 4 | #include 5 | 6 | namespace radix { 7 | 8 | class BaseGame; 9 | 10 | using HandleGameFunction = std::function; 11 | 12 | } /* namespace radix */ 13 | 14 | #endif /* RADIX_HANDLEGAMEFUNCTION_HPP */ 15 | -------------------------------------------------------------------------------- /include/radix/data/map/MapListLoader.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_MAPLISTLOADER_HPP 2 | #define RADIX_MAPLISTLOADER_HPP 3 | 4 | #include 5 | #include 6 | 7 | namespace radix { 8 | 9 | class MapListLoader { 10 | public: 11 | static std::vector getMapList(); 12 | }; 13 | 14 | } /* namespace radix */ 15 | 16 | #endif /* RADIX_MAPLISTLOADER_HPP */ 17 | -------------------------------------------------------------------------------- /source/entities/traits/SoundSourceTrait.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | namespace radix { 5 | namespace entities { 6 | 7 | void SoundSourceTrait::playSound(const std::string &path) { 8 | SoundManager::playSound(path, *this); 9 | } 10 | 11 | } /* namespace entities */ 12 | } /* namespace radix */ 13 | -------------------------------------------------------------------------------- /include/radix/data/map/BaseTrigger.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_BASE_TRIGGER_HPP 2 | #define RADIX_BASE_TRIGGER_HPP 3 | 4 | #include 5 | 6 | #include 7 | 8 | namespace radix { 9 | 10 | class BaseTrigger { 11 | public: 12 | virtual void addAction(Entity& trigger) {} 13 | }; 14 | 15 | } /* namespace radix */ 16 | 17 | #endif /* RADIX_BASE_TRIGGER_HPP */ 18 | -------------------------------------------------------------------------------- /include/radix/util/sdl/Fps.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_FPS_HPP 2 | #define RADIX_FPS_HPP 3 | 4 | namespace radix { 5 | 6 | class Fps { 7 | public: 8 | Fps(); 9 | int getFps(); 10 | void countCycle(); 11 | private: 12 | unsigned int lastFpsTime; 13 | int fps; 14 | int skipped; 15 | int rendered; 16 | }; 17 | 18 | } /* namespace radix */ 19 | 20 | #endif /* RADIX_FPS_HPP */ 21 | -------------------------------------------------------------------------------- /include/radix/core/gl/DebugOutput.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_CORE_GL_DEBUG_OUTPUT_HPP 2 | #define RADIX_CORE_GL_DEBUG_OUTPUT_HPP 3 | 4 | namespace radix { 5 | namespace gl { 6 | 7 | class DebugOutput { 8 | public: 9 | static void enable(); 10 | static void disable(); 11 | }; 12 | 13 | } /* namespace gl */ 14 | } /* namespace radix */ 15 | 16 | #endif /* RADIX_CORE_GL_DEBUG_OUTPUT_HPP */ 17 | -------------------------------------------------------------------------------- /source/WindowConfigurator.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace radix { 4 | void WindowConfigurator::configure(radix::Config &config, radix::Window &window){ 5 | if (config.isLoaded()){ 6 | window.setIgnoreGlVersion(config.getIgnoreGlVersion()); 7 | window.setAntialiasLevel(config.getAntialiasLevel()); 8 | } 9 | 10 | } 11 | } /* namespace radix */ 12 | 13 | -------------------------------------------------------------------------------- /source/core/math/Vector2i.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | namespace radix { 6 | 7 | const Vector2i Vector2i::ZERO(0, 0); 8 | const Vector2i Vector2i::UP(0, 1); 9 | 10 | std::string Vector2i::str() const { 11 | std::stringstream ss; 12 | ss << "(" << x << ", " << y << ")"; 13 | return ss.str(); 14 | } 15 | 16 | } /* namespace radix */ 17 | -------------------------------------------------------------------------------- /source/core/state/GameStateManager.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | 6 | namespace radix { 7 | 8 | void GameStateManager::handleInput(BaseGame &game) { 9 | HandleGameFunction stateFunction = game.getWorld()->stateFunctionStack.top(); 10 | stateFunction(game); 11 | } 12 | 13 | } /* namespace radix */ 14 | -------------------------------------------------------------------------------- /include/radix/data/map/Destination.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_DESTINATION_HPP 2 | #define RADIX_DESTINATION_HPP 3 | 4 | #include 5 | #include 6 | 7 | namespace radix { 8 | 9 | struct Destination { 10 | Vector3f position; 11 | Vector3f rotation; 12 | Quaternion orientation; 13 | }; 14 | 15 | } /* namespace radix */ 16 | 17 | #endif /* RADIX_DESTINATION_HPP */ 18 | -------------------------------------------------------------------------------- /include/radix/data/text/Glyph.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_GLYPH_HPP 2 | #define RADIX_GLYPH_HPP 3 | 4 | #include 5 | 6 | namespace radix { 7 | 8 | class Glyph { 9 | public: 10 | int x; 11 | int y; 12 | int width; 13 | int height; 14 | float xOffset; 15 | float yOffset; 16 | float advance; 17 | 18 | Mesh mesh; 19 | }; 20 | 21 | } /* namespace radix */ 22 | 23 | #endif /* RADIX_GLYPH_HPP */ 24 | -------------------------------------------------------------------------------- /include/radix/util/Hash.std.string.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_UTIL_HASH_STD_STRING_HPP 2 | #define RADIX_UTIL_HASH_STD_STRING_HPP 3 | 4 | #include 5 | 6 | #include 7 | 8 | namespace radix { 9 | 10 | constexpr uint32_t Hash32(const std::string &str) { 11 | return impl::MurmurHash2(str.data(), str.size(), 0); 12 | } 13 | 14 | } /* namespace radix */ 15 | 16 | #endif /* RADIX_UTIL_HASH_STD_STRING_HPP */ 17 | -------------------------------------------------------------------------------- /include/radix/WindowConfigurator.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_WINDOW_CONFIGURATOR_HPP 2 | #define RADIX_WINDOW_CONFIGURATOR_HPP 3 | 4 | #include 5 | #include 6 | 7 | namespace radix { 8 | 9 | class WindowConfigurator { 10 | public: 11 | static void configure(radix::Config &config, radix::Window &window); 12 | }; 13 | 14 | } /* namespace radix */ 15 | 16 | #endif /* RADIX_WINDOW_CONFIGURATOR_HPP */ 17 | -------------------------------------------------------------------------------- /include/radix/input/GamePad.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_GAME_PAD_HPP 2 | #define RADIX_GAME_PAD_HPP 3 | 4 | #include 5 | #include 6 | 7 | namespace radix { 8 | 9 | class GamePad { 10 | public: 11 | GamePad(); 12 | void create(); 13 | SDL_GameController& getController(); 14 | private: 15 | SDL_GameController *controller; 16 | SDL_Joystick *joystick; 17 | }; 18 | 19 | } 20 | 21 | #endif /* RADIX_GAME_PAD_HPP */ 22 | -------------------------------------------------------------------------------- /include/radix/data/map/MapLoader.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_MAPLOADER_HPP 2 | #define RADIX_MAPLOADER_HPP 3 | 4 | #include 5 | 6 | namespace radix { 7 | 8 | class Entity; 9 | class Mesh; 10 | class World; 11 | 12 | class MapLoader { 13 | protected: 14 | World &world; 15 | MapLoader(World&); 16 | 17 | public: 18 | virtual void load(const std::string &path) = 0; 19 | }; 20 | 21 | } /* namespace radix */ 22 | 23 | #endif /* RADIX_MAPLOADER_HPP */ 24 | -------------------------------------------------------------------------------- /source/physics/CollisionDispatcher.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace radix { 4 | 5 | #if 0 6 | bool CollisionDispatcher::needsCollision(const btCollisionObject *obj0, 7 | const btCollisionObject *obj1) { 8 | return false; 9 | } 10 | 11 | bool CollisionDispatcher::needsResponse(const btCollisionObject *obj0, 12 | const btCollisionObject *obj1) { 13 | return false; 14 | } 15 | #endif 16 | 17 | } /* namespace radix */ -------------------------------------------------------------------------------- /cmake/FindCatch.cmake: -------------------------------------------------------------------------------- 1 | set(CATCH_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/external/catch/single_include") 2 | set(CATCH_INCLUDE_DIRS ${CATCH_INCLUDE_DIR}) 3 | set(CATCH_LIBRARY "CATCH") 4 | set(CATCH_LIBRARIES ${CATCH_LIBRARY}) 5 | 6 | include(FindPackageHandleStandardArgs) 7 | find_package_handle_standard_args(CATCH DEFAULT_MSG CATCH_LIBRARIES CATCH_INCLUDE_DIR CATCH_INCLUDE_DIRS) 8 | 9 | mark_as_advanced(CATCH_LIBRARY CATCH_LIBRARIES CATCH_INCLUDE_DIR CATCH_INCLUDE_DIRS) 10 | -------------------------------------------------------------------------------- /include/radix/data/screen/Screen.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_SCREEN_HPP 2 | #define RADIX_SCREEN_HPP 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | namespace radix { 11 | 12 | struct Screen { 13 | Vector4f color; 14 | std::vector text; 15 | std::vector elements; 16 | }; 17 | 18 | } /* namespace radix */ 19 | 20 | #endif /* RADIX_SCREEN_HPP */ 21 | -------------------------------------------------------------------------------- /include/radix/core/file/Path.hpp: -------------------------------------------------------------------------------- 1 | #ifndef PATH_HPP 2 | #define PATH_HPP 3 | 4 | #include 5 | 6 | namespace radix { 7 | 8 | class Path { 9 | public: 10 | static std::string GetDirectorySeparator(); 11 | static bool DirectoryExist(std::string & directory); 12 | 13 | // convert path from unix paths used throughout the code 14 | static std::string FromUnixPath(const std::string & unixPath); 15 | }; 16 | 17 | } /* namespace radix */ 18 | 19 | #endif /* PATH_HPP */ 20 | -------------------------------------------------------------------------------- /include/radix/data/map/WinTrigger.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_WIN_TRIGGER_HPP 2 | #define RADIX_WIN_TRIGGER_HPP 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | namespace radix { 10 | 11 | class WinTrigger: public BaseTrigger { 12 | public: 13 | static const std::string TYPE; 14 | void addAction(Entity& trigger); 15 | }; 16 | 17 | } /* namespace radix */ 18 | 19 | #endif /* RADIX_WIN_TRIGGER_HPP */ 20 | -------------------------------------------------------------------------------- /source/simulation/Player.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | namespace radix { 6 | namespace simulation { 7 | 8 | Player::Player(World &world, BaseGame*) : 9 | Simulation(world) { 10 | } 11 | 12 | Player::~Player() { 13 | } 14 | 15 | const char* Player::getName() const { 16 | return "Player"; 17 | } 18 | 19 | void Player::update(TDelta dtime) { 20 | (void) dtime; 21 | } 22 | 23 | } /* namespace simulation */ 24 | } /* namespace radix */ 25 | -------------------------------------------------------------------------------- /include/radix/data/map/CustomTrigger.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_CUSTOM_TRIGGER_HPP 2 | #define RADIX_CUSTOM_TRIGGER_HPP 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | namespace radix { 12 | 13 | struct CustomTrigger { 14 | std::string TYPE; 15 | std::function loadFunction; 16 | }; 17 | 18 | } /* namespace radix */ 19 | 20 | #endif /* RADIX_CUSTOM_TRIGGER_HPP */ 21 | -------------------------------------------------------------------------------- /include/radix/input/ChannelListener.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_CHANNEL_LISTENER_HPP 2 | #define RADIX_CHANNEL_LISTENER_HPP 3 | 4 | namespace radix { 5 | 6 | template 7 | class ChannelListener { 8 | public: 9 | virtual void channelChanged(T newValue, const int &id) = 0; 10 | 11 | }; 12 | 13 | class Vector2f; 14 | 15 | typedef ChannelListener DigitalChannelListener; 16 | typedef ChannelListener VectorChannelListener; 17 | 18 | } 19 | 20 | #endif /* RADIX_INPUT_MANAGER_HPP */ 21 | -------------------------------------------------------------------------------- /source/data/screen/Element.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace radix { 4 | 5 | Element::Element():needsRecomputation(true) { 6 | } 7 | 8 | void Element::addStyle(Style& style) { 9 | needsRecomputation = true; 10 | styles.push_back(style); 11 | } 12 | 13 | void Element::computeStyle() { 14 | } 15 | 16 | Style Element::getStyle() { 17 | if (needsRecomputation) { 18 | computeStyle(); 19 | } 20 | 21 | return computedStyle; 22 | } 23 | 24 | } /* namespace radix */ 25 | -------------------------------------------------------------------------------- /include/radix/data/map/DeathTrigger.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_DEATH_TRIGGER_HPP 2 | #define RADIX_DEATH_TRIGGER_HPP 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | namespace radix { 11 | 12 | class DeathTrigger: public BaseTrigger { 13 | public: 14 | static const std::string TYPE; 15 | void addAction(Entity& trigger); 16 | }; 17 | 18 | } /* namespace radix */ 19 | 20 | #endif /* RADIX_DEATH_TRIGGER_HPP */ 21 | -------------------------------------------------------------------------------- /include/radix/data/map/RadiationTrigger.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_RADIATION_TRIGGER_HPP 2 | #define RADIX_RADIATION_TRIGGER_HPP 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | namespace radix { 10 | 11 | class RadiationTrigger: public BaseTrigger { 12 | public: 13 | static const std::string TYPE; 14 | void addAction(Entity& trigger); 15 | }; 16 | 17 | } /* namespace radix */ 18 | 19 | #endif /* RADIX_RADIATION_TRIGGER_HPP */ 20 | -------------------------------------------------------------------------------- /cmake/FindLinenoise.cmake: -------------------------------------------------------------------------------- 1 | set(LINENOISE_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/external/linenoise") 2 | set(LINENOISE_INCLUDE_DIRS ${LINENOISE_INCLUDE_DIR}) 3 | set(LINENOISE_LIBRARY "LINENOISE") 4 | set(LINENOISE_LIBRARIES ${LINENOISE_LIBRARY}) 5 | 6 | include(FindPackageHandleStandardArgs) 7 | find_package_handle_standard_args(LINENOISE DEFAULT_MSG LINENOISE_LIBRARIES LINENOISE_INCLUDE_DIR LINENOISE_INCLUDE_DIRS) 8 | 9 | mark_as_advanced(LINENOISE_LIBRARY LINENOISE_LIBRARIES LINENOISE_INCLUDE_DIR LINENOISE_INCLUDE_DIRS) 10 | -------------------------------------------------------------------------------- /cmake/Findjson11.cmake: -------------------------------------------------------------------------------- 1 | set(JSON11_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/external") 2 | set(JSON11_INCLUDE_DIRS ${JSON11_INCLUDE_DIR}) 3 | set(JSON11_LIBRARY "json11") 4 | set(JSON11_LIBRARIES ${JSON11_LIBRARY}) 5 | 6 | add_subdirectory("${JSON11_INCLUDE_DIR}/json11") 7 | 8 | include(FindPackageHandleStandardArgs) 9 | find_package_handle_standard_args(json11 DEFAULT_MSG JSON11_LIBRARIES JSON11_INCLUDE_DIR JSON11_INCLUDE_DIRS) 10 | 11 | mark_as_advanced(JSON11_LIBRARY JSON11_LIBRARIES JSON11_INCLUDE_DIR JSON11_INCLUDE_DIRS) 12 | -------------------------------------------------------------------------------- /source/core/diag/StdoutLogger.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | namespace radix { 6 | 7 | const char* StdoutLogger::getName() const { 8 | return "stdout logger"; 9 | } 10 | 11 | void StdoutLogger::log(const std::string &message, LogLevel lvl, const std::string &tag) { 12 | std::unique_lock lk(mtx); 13 | 14 | if (not tag.empty()) { 15 | std::cout << tag << ' '; 16 | } 17 | std::cout << message << std::endl; 18 | } 19 | 20 | } /* namespace radix */ 21 | -------------------------------------------------------------------------------- /source/core/gl/TightDataPacker.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace radix { 4 | 5 | TightDataPacker::TightDataPacker(unsigned int reserveBytes) { 6 | data.reserve(reserveBytes); 7 | } 8 | 9 | void TightDataPacker::reserve(unsigned int bytes) { 10 | data.reserve(bytes); 11 | } 12 | 13 | unsigned int TightDataPacker::getSize() const { 14 | return data.size(); 15 | } 16 | 17 | const uint8_t* TightDataPacker::getDataPtr() const { 18 | return data.data(); 19 | } 20 | 21 | } /* namespace radix */ 22 | -------------------------------------------------------------------------------- /source/util/sdl/Fps.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | namespace radix { 5 | 6 | Fps::Fps() { 7 | fps = 0; 8 | lastFpsTime = SDL_GetTicks(); 9 | skipped = 0; 10 | rendered = 0; 11 | } 12 | 13 | void Fps::countCycle() { 14 | rendered++; 15 | } 16 | 17 | int Fps::getFps() { 18 | if (SDL_GetTicks() - lastFpsTime > 1000) { 19 | lastFpsTime = SDL_GetTicks(); 20 | fps = rendered; 21 | rendered = 0; 22 | } 23 | return fps; 24 | } 25 | 26 | } /* namespace radix */ 27 | -------------------------------------------------------------------------------- /include/radix/data/map/TeleportTrigger.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_TELEPORT_TRIGGER_HPP 2 | #define RADIX_TELEPORT_TRIGGER_HPP 3 | 4 | #include 5 | 6 | #include 7 | 8 | namespace radix { 9 | 10 | class TeleportTrigger : public BaseTrigger { 11 | public: 12 | TeleportTrigger(std::string destination); 13 | static const std::string TYPE; 14 | std::string destination; 15 | void addAction(Entity& trigger); 16 | }; 17 | 18 | } /* namespace radix */ 19 | 20 | #endif /* RADIX_TELEPORT_TRIGGER_HPP */ 21 | -------------------------------------------------------------------------------- /include/radix/data/text/FontLoader.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_FONTLOADER_HPP 2 | #define RADIX_FONTLOADER_HPP 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | namespace radix { 10 | 11 | class FontLoader { 12 | public: 13 | static Font& getFont(const std::string &path); 14 | private: 15 | static Font loadFont(const std::string &path, const std::string &name); 16 | static std::map fontCache; 17 | }; 18 | 19 | } /* namespace radix */ 20 | 21 | #endif /* RADIX_FONTLOADER_HPP */ 22 | -------------------------------------------------------------------------------- /include/radix/entities/traits/SoundListenerTrait.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_ENTITIES_SOUNDLISTENER_TRAIT_HPP 2 | #define RADIX_ENTITIES_SOUNDLISTENER_TRAIT_HPP 3 | 4 | #include 5 | 6 | namespace radix { 7 | namespace entities { 8 | 9 | class SoundListenerTrait : public Trait { 10 | public: 11 | // TODO 12 | 13 | radix_trait_declare("radix/entities/traits/", "SoundListener") 14 | }; 15 | 16 | } /* namespace entities */ 17 | } /* namespace radix */ 18 | 19 | #endif /* RADIX_ENTITIES_SOUNDLISTENER_TRAIT_HPP */ 20 | -------------------------------------------------------------------------------- /source/core/math/Vector2ui.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | 6 | namespace radix { 7 | 8 | const Vector2ui Vector2ui::ZERO(0, 0); 9 | const Vector2ui Vector2ui::UP(0, 1); 10 | 11 | /* Core */ 12 | unsigned int Vector2ui::length() const { 13 | return sqrt(x * x + y * y); 14 | } 15 | 16 | std::string Vector2ui::str() const { 17 | std::stringstream ss; 18 | ss << "(" << x << ", " << y << ")"; 19 | return ss.str(); 20 | } 21 | 22 | } /* namespace radix */ 23 | -------------------------------------------------------------------------------- /include/radix/api/PlayerApi.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_PLAYER_API_HPP 2 | #define RADIX_PLAYER_API_HPP 3 | 4 | #include 5 | 6 | #include 7 | 8 | namespace radix { 9 | 10 | class PlayerApi { 11 | private: 12 | World &world; 13 | public: 14 | PlayerApi(World &world); 15 | void registerFunctions(asIScriptEngine *angelScript); 16 | void kill(); 17 | void moveY(float distance); 18 | void moveX(float distance); 19 | void jump(); 20 | }; 21 | 22 | } /* namespace radix */ 23 | 24 | #endif /* RADIX_PLAYER_API_HPP */ 25 | -------------------------------------------------------------------------------- /include/radix/api/RadixApi.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_ENGINE_API_HPP 2 | #define RADIX_ENGINE_API_HPP 3 | 4 | #include 5 | 6 | #include 7 | 8 | #include 9 | 10 | namespace radix { 11 | 12 | class RadixApi { 13 | private: 14 | World &world; 15 | public: 16 | RadixApi(World &world); 17 | void registerFunctions(asIScriptEngine *angelScript); 18 | void exit(); 19 | void logDebug(std::string category, std::string message); 20 | }; 21 | 22 | } /* namespace radix */ 23 | 24 | #endif /* RADIX_ENGINE_API_HPP */ 25 | -------------------------------------------------------------------------------- /include/radix/simulation/Player.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_SIMULATION_PLAYER_HPP 2 | #define RADIX_SIMULATION_PLAYER_HPP 3 | 4 | #include 5 | 6 | namespace radix { 7 | namespace simulation { 8 | 9 | class Player final : public Simulation { 10 | public: 11 | Player(World&, BaseGame *game); 12 | ~Player(); 13 | 14 | const char* getName() const override; 15 | void update(TDelta dtime) override; 16 | }; 17 | 18 | } /* namespace simulation */ 19 | } /* namespace radix */ 20 | 21 | #endif /* RADIX_SIMULATION_PLAYER_HPP */ 22 | -------------------------------------------------------------------------------- /include/radix/core/state/GameStateManager.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_GAME_STATE_MANAGER_HPP 2 | #define RADIX_GAME_STATE_MANAGER_HPP 3 | 4 | #include 5 | #include 6 | 7 | namespace radix { 8 | 9 | class GameStateManager { 10 | public: 11 | struct WinEvent : public Event { 12 | radix_event_declare("radix/GameState:Win") 13 | 14 | WinEvent() {} 15 | }; 16 | 17 | public: 18 | void handleInput(BaseGame &game); 19 | }; 20 | 21 | } /* namespace radix */ 22 | 23 | #endif /* RADIX_GAME_STATE_MANAGER_HPP */ 24 | -------------------------------------------------------------------------------- /include/radix/entities/traits/SoundSourceTrait.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_ENTITIES_SOUNDSOURCE_TRAIT_HPP 2 | #define RADIX_ENTITIES_SOUNDSOURCE_TRAIT_HPP 3 | 4 | #include 5 | 6 | namespace radix { 7 | namespace entities { 8 | 9 | class SoundSourceTrait : public Trait { 10 | public: 11 | radix_trait_declare("radix/entities/traits/", "SoundSource") 12 | 13 | void playSound(const std::string &path); 14 | }; 15 | 16 | } /* namespace entities */ 17 | } /* namespace radix */ 18 | 19 | #endif /* RADIX_ENTITIES_SOUNDSOURCE_TRAIT_HPP */ 20 | -------------------------------------------------------------------------------- /include/radix/core/math/Vector4i.hpp: -------------------------------------------------------------------------------- 1 | #ifndef VECTOR4I_HPP 2 | #define VECTOR4I_HPP 3 | struct Vector4i { 4 | union { 5 | int x, top, r; 6 | }; 7 | union { 8 | int y, bottom, g; 9 | }; 10 | union { 11 | int z, left, b; 12 | }; 13 | union { 14 | int w, right, a; 15 | }; 16 | 17 | constexpr Vector4i() 18 | : x(0), y(0), z(0), w(0) {} 19 | constexpr Vector4i(int x, int y, int z, int w) 20 | : x(x), y(y), z(z), w(w) {} 21 | constexpr Vector4i(int v) 22 | : x(v), y(v), z(v), w(v) {} 23 | 24 | }; 25 | #endif /* VECTOR4I_HPP */ 26 | -------------------------------------------------------------------------------- /include/radix/data/map/MapTrigger.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_MAP_TRIGGER_HPP 2 | #define RADIX_MAP_TRIGGER_HPP 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | namespace radix { 10 | 11 | class MapTrigger: public BaseTrigger { 12 | private: 13 | std::string filePath; 14 | bool loop; 15 | public: 16 | static const std::string TYPE; 17 | MapTrigger(const std::string &filePath); 18 | void addAction(Entity& trigger); 19 | }; 20 | 21 | } /* namespace radix */ 22 | 23 | #endif /* RADIX_MAP_TRIGGER_HPP */ 24 | -------------------------------------------------------------------------------- /source/renderer/PortalRenderer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | namespace radix { 11 | 12 | PortalRenderer::PortalRenderer(World &world, Renderer &renderer, GameWorld &gameWorld) : 13 | SubRenderer(world, renderer), 14 | gameWorld(gameWorld) { } 15 | 16 | void PortalRenderer::render() { 17 | } 18 | 19 | } /* namespace radix */ 20 | -------------------------------------------------------------------------------- /include/radix/data/map/ScriptTrigger.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_SCRIPT_TRIGGER_HPP 2 | #define RADIX_SCRIPT_TRIGGER_HPP 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | namespace radix { 10 | 11 | class ScriptTrigger: public BaseTrigger { 12 | private: 13 | std::string code; 14 | public: 15 | static const std::string TYPE; 16 | ScriptTrigger(const std::string &code); 17 | void addAction(Entity& trigger); 18 | }; 19 | 20 | } /* namespace radix */ 21 | 22 | #endif /* RADIX_SCRIPT_TRIGGER_HPP */ 23 | -------------------------------------------------------------------------------- /source/renderer/SubRenderer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace radix { 4 | 5 | SubRenderer::SubRenderer(World &w, Renderer &ren) : 6 | world(w), renderer(ren), 7 | camera(nullptr), 8 | viewportWidth(0), viewportHeight(0) { 9 | renderContext = std::make_unique(ren); 10 | } 11 | 12 | void SubRenderer::initCamera() { 13 | camera = std::make_unique(); 14 | camera->setOrthographic(); 15 | camera->setBounds(0, viewportWidth, 0, viewportHeight); 16 | renderContext->pushCamera(*camera.get()); 17 | } 18 | 19 | } /* namespace radix */ -------------------------------------------------------------------------------- /include/radix/Transform.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_TRANSFORM_HPP 2 | #define RADIX_TRANSFORM_HPP 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | class btTransform; 9 | 10 | namespace radix { 11 | 12 | class Transform { 13 | public: 14 | Vector3f position, scale{1}; 15 | Quaternion orientation; 16 | 17 | void applyModelMtx(Matrix4f&) const; 18 | void getModelMtx(Matrix4f&) const; 19 | 20 | operator btTransform() const; 21 | }; 22 | 23 | } /* namespace radix */ 24 | 25 | #endif /* RADIX_TRANSFORM_HPP */ 26 | -------------------------------------------------------------------------------- /cmake/FindVHACD.cmake: -------------------------------------------------------------------------------- 1 | set(VHACD_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/external/vhacd-lib") 2 | set(VHACD_INCLUDE_DIR "${VHACD_ROOT_DIR}/public") 3 | set(VHACD_INCLUDE_DIRS ${VHACD_INCLUDE_DIR}) 4 | set(VHACD_LIBRARY "VHACD_LIB") 5 | set(VHACD_LIBRARIES ${VHACD_LIBRARY}) 6 | 7 | set(NO_OPENCL ON) 8 | set(NO_OPENMP ON) 9 | add_subdirectory("${VHACD_ROOT_DIR}") 10 | 11 | include(FindPackageHandleStandardArgs) 12 | find_package_handle_standard_args(VHACD DEFAULT_MSG VHACD_LIBRARIES VHACD_INCLUDE_DIR VHACD_INCLUDE_DIRS) 13 | 14 | mark_as_advanced(VHACD_LIBRARY VHACD_LIBRARIES VHACD_INCLUDE_DIR VHACD_INCLUDE_DIRS) 15 | -------------------------------------------------------------------------------- /include/radix/data/model/Mesh.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_MESH_HPP 2 | #define RADIX_MESH_HPP 3 | 4 | #include 5 | 6 | #include 7 | 8 | namespace radix { 9 | 10 | class Mesh { 11 | public: 12 | int handle; 13 | int numFaces; 14 | std::vector vertices; 15 | 16 | Mesh() : 17 | handle(0), 18 | numFaces(0) { 19 | } 20 | Mesh(int handle, int numFaces, const std::vector &vertices) : 21 | handle(handle), 22 | numFaces(numFaces), 23 | vertices(vertices) { 24 | } 25 | }; 26 | 27 | } /* namespace radix */ 28 | 29 | #endif /* RADIX_MESH_HPP */ 30 | -------------------------------------------------------------------------------- /include/radix/entities/traits/SoundPhysicalMediumTrait.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_ENTITIES_SOUND_PHYSICAL_MEDIUM_TRAIT_HPP 2 | #define RADIX_ENTITIES_SOUND_PHYSICAL_MEDIUM_TRAIT_HPP 3 | 4 | #include 5 | 6 | namespace radix { 7 | namespace entities { 8 | 9 | class SoundPhysicalMediumTrait : public Trait { 10 | public: 11 | /* TODO 12 | double speedOfSound; 13 | */ 14 | 15 | radix_trait_declare("radix/entities/traits/", "SoundPhysicalMedium") 16 | }; 17 | 18 | } /* namespace entities */ 19 | } /* namespace radix */ 20 | 21 | #endif /* RADIX_ENTITIES_SOUND_PHYSICAL_MEDIUM_TRAIT_HPP */ 22 | -------------------------------------------------------------------------------- /source/data/map/WinTrigger.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | namespace radix { 10 | 11 | const std::string WinTrigger::TYPE = "win"; 12 | 13 | void WinTrigger::addAction(Entity &ent) { 14 | entities::Trigger &trigger = dynamic_cast(ent); 15 | trigger.setActionOnUpdate([] (entities::Trigger &trigger) { 16 | trigger.world.event.dispatch(GameStateManager::WinEvent()); 17 | }); 18 | } 19 | 20 | } /* namespace radix */ 21 | -------------------------------------------------------------------------------- /source/data/map/DeathTrigger.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | using namespace std; 9 | 10 | namespace radix { 11 | 12 | const std::string DeathTrigger::TYPE = "death"; 13 | 14 | void DeathTrigger::addAction(Entity &ent) { 15 | entities::Trigger &trigger = dynamic_cast(ent); 16 | trigger.setActionOnEnter([] (entities::Trigger &trigger) { 17 | trigger.world.getPlayer().kill(); 18 | }); 19 | } 20 | 21 | } /* namespace radix */ 22 | -------------------------------------------------------------------------------- /include/radix/physics/CollisionDispatcher.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_COLLISION_DISPATCHER_HPP 2 | #define RADIX_COLLISION_DISPATCHER_HPP 3 | 4 | #include 5 | 6 | namespace radix { 7 | 8 | class CollisionDispatcher : public btCollisionDispatcher { 9 | public: 10 | using btCollisionDispatcher::btCollisionDispatcher; 11 | 12 | //bool needsCollision(const btCollisionObject*, const btCollisionObject*) final override; 13 | //bool needsResponse(const btCollisionObject*, const btCollisionObject*) final override; 14 | }; 15 | 16 | } /* namespace radix */ 17 | 18 | #endif /* RADIX_COLLISION_DISPATCHER_HPP */ 19 | -------------------------------------------------------------------------------- /include/radix/util/NullReference.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_UTIL_NULL_REFERENCE_HPP 2 | #define RADIX_UTIL_NULL_REFERENCE_HPP 3 | 4 | namespace radix { 5 | namespace util { 6 | 7 | void* getNullptr(); 8 | 9 | /** 10 | * Shorthand to get a nullptr-targeting reference. 11 | * @warning This is undefined behaviour, and should only be used in other cases of *unreachable* 12 | * undefined behaviour to make the compiler happy. 13 | */ 14 | template 15 | T &NullReference = *reinterpret_cast(getNullptr()); 16 | 17 | } /* namespace util */ 18 | } /* namespace radix */ 19 | 20 | #endif /* RADIX_UTIL_NULL_REFERENCE_HPP */ 21 | -------------------------------------------------------------------------------- /include/radix/core/diag/StdoutLogger.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_STDOUT_LOGGER_HPP 2 | #define RADIX_STDOUT_LOGGER_HPP 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | namespace radix { 10 | 11 | /** \class StdoutLogger 12 | * @brief Logger that outputs to an ANSI/vt-100 console 13 | */ 14 | class StdoutLogger : public Logger { 15 | protected: 16 | std::mutex mtx; 17 | 18 | public: 19 | const char* getName() const; 20 | void log(const std::string &message, LogLevel lvl, const std::string &tag); 21 | }; 22 | 23 | } /* namespace radix */ 24 | 25 | #endif /* RADIX_STDOUT_LOGGER_HPP */ 26 | -------------------------------------------------------------------------------- /include/radix/core/gl/OpenGL.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_CORE_GL_OPENGL_HPP 2 | #define RADIX_CORE_GL_OPENGL_HPP 3 | 4 | #if defined(RADIX_GL_USE_LIBEPOXY) 5 | #include 6 | #include 7 | #elif defined(RADIX_GL_USE_GLAD) 8 | #include 9 | #else 10 | #error "No OpenGL loader selected" 11 | #endif 12 | 13 | namespace radix { 14 | namespace gl { 15 | 16 | class OpenGL { 17 | public: 18 | static void initialize(); 19 | static int version(); 20 | static bool hasExtension(const char*); 21 | }; 22 | 23 | } /* namespace gl */ 24 | } /* namespace radix */ 25 | 26 | #endif /* RADIX_CORE_GL_DEBUG_OUTPUT_HPP */ 27 | -------------------------------------------------------------------------------- /include/radix/data/map/AudioTrigger.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_AUDIO_TRIGGER_HPP 2 | #define RADIX_AUDIO_TRIGGER_HPP 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | namespace radix { 10 | 11 | class AudioTrigger: public BaseTrigger { 12 | private: 13 | std::string filePath; 14 | bool loop; 15 | public: 16 | static const std::string TYPE; 17 | AudioTrigger(std::string filePath); 18 | void setLoop(bool loop); 19 | void addAction(Entity& trigger); 20 | }; 21 | 22 | } /* namespace radix */ 23 | 24 | #endif /* RADIX_AUDIO_TRIGGER_HPP */ 25 | -------------------------------------------------------------------------------- /include/radix/util/XmlLoader.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_UTIL_XML_LOADER_HPP 2 | #define RADIX_UTIL_XML_LOADER_HPP 3 | 4 | #include 5 | 6 | #include 7 | 8 | #include 9 | 10 | namespace radix { 11 | 12 | class XmlLoader { 13 | public: 14 | static std::string errorName(tinyxml2::XMLError err); 15 | 16 | protected: 17 | static bool extractColor(tinyxml2::XMLElement* currElement, Vector4f* color); 18 | static void handleFailureForElement(std::string module, std::string element, std::string path); 19 | }; 20 | 21 | } /* namespace radix */ 22 | 23 | #endif /* RADIX_UTIL_XML_LOADER_HPP */ 24 | -------------------------------------------------------------------------------- /include/radix/renderer/PortalRenderer.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_PORTAL_RENDERER_HPP 2 | #define RADIX_PORTAL_RENDERER_HPP 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | namespace radix { 12 | 13 | class PortalRenderer : public SubRenderer{ 14 | public: 15 | PortalRenderer(World& world, Renderer& renderer, GameWorld& gameWorld); 16 | void render(); 17 | GameWorld &gameWorld; 18 | }; 19 | 20 | } /* namespace radix */ 21 | 22 | #endif /* RADIX_PORTAL_RENDERER_HPP */ 23 | -------------------------------------------------------------------------------- /include/radix/physics/CollisionShapeManager.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_COLLISION_SHAPE_MANAGER_HPP 2 | #define RADIX_COLLISION_SHAPE_MANAGER_HPP 3 | 4 | #include 5 | #include 6 | 7 | namespace radix { 8 | 9 | class CollisionShapeManager { 10 | public: 11 | BoxCollider(); 12 | BoxCollider(const Vector3f &position, const Vector3f &size); 13 | bool collidesWith(const BoxCollider &collider) const; 14 | static BoxCollider generateCage(const Entity &entity); 15 | 16 | Vector3f position; 17 | Vector3f size; 18 | }; 19 | 20 | } /* namespace radix */ 21 | 22 | #endif /* RADIX_COLLISION_SHAPE_MANAGER_HPP */ 23 | -------------------------------------------------------------------------------- /include/radix/data/material/Material.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_MATERIAL_HPP 2 | #define RADIX_MATERIAL_HPP 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | namespace radix { 10 | 11 | class Material { 12 | public: 13 | static const Material Empty; 14 | 15 | std::string name, fancyname; 16 | Texture diffuse, specular, normal, height; 17 | float shininess = 0; 18 | float scaleU = 1, scaleV = 1; 19 | 20 | bool portalable; 21 | std::string kind; 22 | std::vector tags; 23 | 24 | int tileScale; 25 | }; 26 | 27 | } /* namespace radix */ 28 | 29 | #endif /* RADIX_MATERIAL_HPP */ 30 | -------------------------------------------------------------------------------- /include/radix/entities/ReferencePoint.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_ENTITIES_REFERENCE_POINT_HPP 2 | #define RADIX_ENTITIES_REFERENCE_POINT_HPP 3 | 4 | #include 5 | 6 | namespace radix { 7 | namespace entities { 8 | 9 | class ReferencePoint : 10 | public virtual Entity { 11 | public: 12 | using Entity::Entity; 13 | 14 | std::string fullClassName() const override { 15 | return "radix/entities/ReferencePoint"; 16 | } 17 | std::string className() const override { 18 | return "ReferencePoint"; 19 | } 20 | }; 21 | 22 | } /* namespace entities */ 23 | } /* namespace radix */ 24 | 25 | #endif /* RADIX_ENTITIES_REFERENCE_POINT_HPP */ 26 | -------------------------------------------------------------------------------- /include/radix/api/ScriptEngine.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_SCRIPT_ENGINE_HPP 2 | #define RADIX_SCRIPT_ENGINE_HPP 3 | 4 | #include 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | namespace radix { 13 | 14 | class ScriptEngine { 15 | private: 16 | World &world; 17 | PlayerApi playerApi; 18 | RadixApi radixApi; 19 | asIScriptEngine *angelScript; 20 | 21 | public: 22 | ScriptEngine(World &world); 23 | ~ScriptEngine(); 24 | void runCode(const std::string &code); 25 | }; 26 | 27 | } /* namespace radix */ 28 | 29 | #endif /* RADIX_SCRIPT_ENGINE_HPP */ 30 | -------------------------------------------------------------------------------- /include/radix/data/text/Text.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_TEXT_HPP 2 | #define RADIX_TEXT_HPP 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | namespace radix { 10 | 11 | struct Text { 12 | enum Align { 13 | Left, 14 | Right, 15 | Center 16 | }; 17 | 18 | Vector4f color; 19 | Vector3f position; 20 | std::string id; //for styling and scripting 21 | std::string type; //for styling 22 | std::string font; 23 | std::string content; 24 | Align align; 25 | float z; 26 | float top; 27 | float size; 28 | }; 29 | 30 | } /* namespace radix */ 31 | 32 | #endif /* RADIX_TEXT_HPP */ 33 | -------------------------------------------------------------------------------- /source/data/map/RadiationTrigger.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | using namespace std; 9 | 10 | namespace radix { 11 | 12 | const std::string RadiationTrigger::TYPE = "radiation"; 13 | 14 | void RadiationTrigger::addAction(Entity &ent) { 15 | entities::Trigger &trigger = dynamic_cast(ent); 16 | trigger.setActionOnUpdate([] (entities::Trigger &trigger) { 17 | trigger.world.getPlayer().harm(0.1f); 18 | }); 19 | } 20 | 21 | } /* namespace radix */ 22 | -------------------------------------------------------------------------------- /include/radix/input/NullInputSource.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_NULL_INPUT_SOURCE_HPP 2 | #define RADIX_NULL_INPUT_SOURCE_HPP 3 | 4 | #include 5 | 6 | namespace radix { 7 | 8 | class NullInputSource : public InputSource { 9 | public: 10 | void processEvents() {} 11 | 12 | void keyPressed(int, int) {} 13 | void keyReleased(int, int) {} 14 | bool isKeyDown(int) { return false; } 15 | std::string getCharBuffer() { return ""; } 16 | void addToBuffer(const std::string&) {} 17 | void clearBuffer() {} 18 | void truncateCharBuffer() {} 19 | void clear() {} 20 | }; 21 | 22 | } /* namespace radix */ 23 | 24 | #endif /* RADIX_NULL_INPUT_SOURCE_HPP */ 25 | -------------------------------------------------------------------------------- /cmake/FindRadixEntity.cmake: -------------------------------------------------------------------------------- 1 | set(RADIXENTITY_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/external/RadixEntity") 2 | set(RADIXENTITY_INCLUDE_DIR "${RADIXENTITY_ROOT_DIR}/include/") 3 | set(RADIXENTITY_INCLUDE_DIRS ${RADIXENTITY_INCLUDE_DIR}) 4 | set(RADIXENTITY_LIBRARY "RadixEntity") 5 | set(RADIXENTITY_LIBRARIES ${RADIXENTITY_LIBRARY}) 6 | 7 | add_subdirectory("${RADIXENTITY_ROOT_DIR}") 8 | 9 | include(FindPackageHandleStandardArgs) 10 | find_package_handle_standard_args(${RADIXENTITY_LIBRARY} DEFAULT_MSG RADIXENTITY_LIBRARIES RADIXENTITY_INCLUDE_DIR RADIXENTITY_INCLUDE_DIRS) 11 | 12 | mark_as_advanced(RADIXENTITY_LIBRARY RADIXENTITY_LIBRARIES RADIXENTITY_INCLUDE_DIR RADIXENTITY_INCLUDE_DIRS) 13 | -------------------------------------------------------------------------------- /include/radix/entities/traits/MeshDrawableTrait.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_ENTITIES_MESHDRAWABLE_TRAIT_HPP 2 | #define RADIX_ENTITIES_MESHDRAWABLE_TRAIT_HPP 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | namespace radix { 10 | namespace entities { 11 | 12 | class MeshDrawableTrait : public Trait { 13 | public: 14 | radix_trait_declare("radix/entities/traits/", "MeshDrawable") 15 | 16 | Mesh mesh; 17 | // TODO: MaterialDrawable? 18 | Material material; 19 | }; 20 | 21 | } /* namespace entities */ 22 | } /* namespace radix */ 23 | 24 | #endif /* RADIX_ENTITIES_MESHDRAWABLE_TRAIT_HPP */ 25 | -------------------------------------------------------------------------------- /include/radix/entities/traits/HealthTrait.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_ENTITIES_HEALTH_TRAIT_HPP 2 | #define RADIX_ENTITIES_HEALTH_TRAIT_HPP 3 | 4 | #include 5 | 6 | namespace radix { 7 | namespace entities { 8 | 9 | class HealthTrait : public Trait { 10 | protected: 11 | HealthTrait(); 12 | 13 | public: 14 | radix_trait_declare("radix/entities/traits/", "Health") 15 | 16 | float maxHealth; 17 | float health; 18 | 19 | bool isAlive(); 20 | void heal(float amount); 21 | void harm(float amount); 22 | void kill(); 23 | void revive(); 24 | }; 25 | 26 | } /* namespace entities */ 27 | } /* namespace radix */ 28 | 29 | #endif /* RADIX_ENTITIES_TRAITS_HEALTH_HPP */ 30 | -------------------------------------------------------------------------------- /source/data/map/MapListLoader.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | namespace radix { 9 | 10 | vector MapListLoader::getMapList() { 11 | vector mapList; 12 | std::string path = LegacyEnvironment::getDataDir() + "/maps/maplist"; 13 | ifstream file(path); 14 | 15 | if (not file.is_open()) { 16 | throw runtime_error("Could not find file: " + path); 17 | } 18 | 19 | string line; 20 | 21 | while (std::getline(file, line)) { 22 | mapList.push_back(line); 23 | } 24 | 25 | return mapList; 26 | } 27 | 28 | } /* namespace radix */ 29 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | CMakeCache.txt 2 | CMakeFiles/ 3 | Makefile 4 | cmake_install.cmake 5 | portal 6 | docs/ 7 | *~ 8 | [#]*[#] 9 | .\#* 10 | /Default 11 | /.* 12 | !.travis.yml 13 | /glPortal.* 14 | /build 15 | Debug/ 16 | __pycache__/ 17 | CTestTestfile.cmake 18 | Testing/ 19 | source/glportal 20 | source/glportal_d 21 | /html 22 | documentation/html/ 23 | documentation/latex/ 24 | external/json11/libjson11.a 25 | analysis.txt 26 | source/gmon.out 27 | documentation/doxygen_sqlite3.db 28 | tests/quaternionTest 29 | tests/xmlReadingTest 30 | RadixEngine 31 | CPackConfig.cmake 32 | CPackSourceConfig.cmake 33 | libGLAD.a 34 | libRadixEngine.a 35 | libimgui.a 36 | tests/MathTest 37 | tests/QuaternionTest 38 | tests/XmlHelperTest 39 | -------------------------------------------------------------------------------- /include/radix/data/screen/Element.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_ELEMENT_HPP 2 | #define RADIX_ELEMENT_HPP 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace radix { 9 | /** 10 | * Represents a screen element in the DOM 11 | */ 12 | class Element { 13 | public: 14 | Element(); 15 | Style style; 16 | Style getStyle(); 17 | void addStyle(Style& style); 18 | std::vector getSubElements(); 19 | private: 20 | bool needsRecomputation; 21 | std::vector elements; 22 | std::vector> styles; 23 | void computeStyle(); 24 | Style computedStyle; 25 | }; 26 | } /* namespace radix */ 27 | 28 | #endif /* RADIX_ELEMENT_HPP */ 29 | -------------------------------------------------------------------------------- /include/radix/util/Profiling.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_UTIL_PROFILING_HPP 2 | #define RADIX_UTIL_PROFILING_HPP 3 | 4 | #include 5 | 6 | #define PROFILER_BLOCK(...) EASY_BLOCK(__VA_ARGS__) 7 | #define PROFILER_NONSCOPED_BLOCK(...) EASY_NONSCOPED_BLOCK(__VA_ARGS__) 8 | #define PROFILER_FUNCTION(...) EASY_FUNCTION(__VA_ARGS__) 9 | #define PROFILER_END_BLOCK EASY_END_BLOCK 10 | #define PROFILER_EVENT(...) EASY_EVENT(__VA_ARGS__) 11 | #define PROFILER_PROFILER_ENABLE EASY_PROFILER_ENABLE 12 | #define PROFILER_PROFILER_DISABLE EASY_PROFILER_DISABLE 13 | #define PROFILER_THREAD_SCOPE(...) EASY_THREAD_SCOPE(__VA_ARGS__) 14 | #define PROFILER_MAIN_THREAD EASY_MAIN_THREAD 15 | 16 | #endif /* RADIX_UTIL_PROFILING_HPP */ 17 | -------------------------------------------------------------------------------- /include/radix/data/shader/Shader.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_SHADER_HPP 2 | #define RADIX_SHADER_HPP 3 | 4 | #include 5 | #include 6 | 7 | namespace radix { 8 | 9 | class Shader { 10 | public: 11 | enum Type { 12 | Vertex, 13 | Fragment, 14 | Geometry 15 | }; 16 | 17 | Shader(unsigned int handle) : handle(handle) {} 18 | void bind() const; 19 | void release() const; 20 | 21 | unsigned int handle; 22 | 23 | int uni(const std::string&); 24 | int uni(const char*); 25 | int att(const std::string&); 26 | int att(const char*); 27 | 28 | private: 29 | std::unordered_map locationMap; 30 | }; 31 | 32 | } /* namespace radix */ 33 | 34 | #endif /* RADIX_SHADER_HPP */ 35 | -------------------------------------------------------------------------------- /include/radix/entities/LightSource.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_ENTITIES_LIGHT_SOURCE_HPP 2 | #define RADIX_ENTITIES_LIGHT_SOURCE_HPP 3 | 4 | #include 5 | #include 6 | 7 | namespace radix { 8 | namespace entities { 9 | 10 | class LightSource : 11 | public virtual Entity, 12 | public LightSourceTrait { 13 | public: 14 | using Entity::Entity; 15 | 16 | std::string fullClassName() const override { 17 | return "radix/entities/LightSource"; 18 | } 19 | std::string className() const override { 20 | return "LightSource"; 21 | } 22 | }; 23 | 24 | } /* namespace entities */ 25 | } /* namespace radix */ 26 | 27 | #endif /* RADIX_ENTITIES_LIGHT_SOURCE_HPP */ 28 | -------------------------------------------------------------------------------- /include/radix/entities/ViewFrame.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_ENTITIES_VIEW_FRAME_HPP 2 | #define RADIX_ENTITIES_VIEW_FRAME_HPP 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | namespace radix { 10 | namespace entities { 11 | 12 | class ViewFrame : public Entity { 13 | public: 14 | Mesh mesh; 15 | Camera view; 16 | 17 | using Entity::Entity; 18 | 19 | std::string fullClassName() const override { 20 | return "radix/entities/ViewFrame"; 21 | } 22 | std::string className() const override { 23 | return "ViewFrame"; 24 | } 25 | }; 26 | 27 | } /* namespace entities */ 28 | } /* namespace radix */ 29 | 30 | #endif /* RADIX_ENTITIES_VIEW_FRAME_HPP */ 31 | -------------------------------------------------------------------------------- /include/radix/entities/LiquidVolume.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_ENTITIES_LIQUID_VOLUME_HPP 2 | #define RADIX_ENTITIES_LIQUID_VOLUME_HPP 3 | 4 | #include 5 | #include 6 | 7 | namespace radix { 8 | namespace entities { 9 | 10 | class LiquidVolume : 11 | public virtual Entity, 12 | public MeshDrawableTrait { 13 | public: 14 | using Entity::Entity; 15 | 16 | std::string fullClassName() const override { 17 | return "radix/entities/LiquidVolume"; 18 | } 19 | std::string className() const override { 20 | return "LiquidVolume"; 21 | } 22 | }; 23 | 24 | } /* namespace entities */ 25 | } /* namespace radix */ 26 | 27 | #endif /* RADIX_ENTITIES_LIQUID_VOLUME_HPP */ 28 | -------------------------------------------------------------------------------- /include/radix/env/LegacyEnvironment.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_LEGACY_ENVIRONMENT_HPP 2 | #define RADIX_LEGACY_ENVIRONMENT_HPP 3 | 4 | #include 5 | 6 | #include 7 | 8 | namespace radix { 9 | 10 | /** @brief Manager for config 11 | * 12 | * Manages the configuration of the the game 13 | */ 14 | 15 | class LegacyEnvironment { 16 | private: 17 | static Config config; 18 | static std::string dataDir; 19 | 20 | public: 21 | static void Init(); 22 | static Config& getConfig(); 23 | static void InitializeConfig(); 24 | static std::string getDataDir(); 25 | static void setDataDir(const std::string &string); 26 | }; 27 | 28 | } /* namespace radix */ 29 | 30 | #endif /* RADIX_LEGACY_ENVIRONMENT_HPP */ 31 | -------------------------------------------------------------------------------- /include/radix/renderer/SubRenderer.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_SUB_RENDERER_HPP 2 | #define RADIX_SUB_RENDERER_HPP 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | namespace radix { 10 | 11 | class World; 12 | class Renderer; 13 | 14 | class SubRenderer { 15 | public: 16 | SubRenderer(World &w, Renderer& ren); 17 | 18 | virtual void render() = 0; 19 | protected: 20 | void initCamera(); 21 | 22 | World &world; 23 | Renderer &renderer; 24 | 25 | std::unique_ptr camera; 26 | std::unique_ptr renderContext; 27 | 28 | int viewportWidth, viewportHeight; 29 | }; 30 | 31 | } /* namespace radix */ 32 | 33 | #endif /* RADIX_SUB_RENDERER_HPP */ 34 | -------------------------------------------------------------------------------- /source/entities/StaticModel.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace radix { 4 | namespace entities { 5 | 6 | StaticModel::StaticModel(const CreationParams &cp) : 7 | Entity(cp) { 8 | 9 | } 10 | 11 | StaticModel::~StaticModel() { 12 | } 13 | 14 | int StaticModel::getCollisionFlags() const { 15 | return btCollisionObject::CF_STATIC_OBJECT; 16 | } 17 | 18 | int StaticModel::getCollisionGroup() const { 19 | return btBroadphaseProxy::StaticFilter; 20 | } 21 | 22 | int StaticModel::getCollisionMask() const { 23 | return btBroadphaseProxy::DefaultFilter | 24 | btBroadphaseProxy::CharacterFilter | 25 | btBroadphaseProxy::DebrisFilter; 26 | } 27 | 28 | } /* namespace entities */ 29 | } /* namespace radix */ 30 | -------------------------------------------------------------------------------- /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(TEST_LIBRARIES ${UnitTestPlusPlus_LIBRARY} ${RADIX_LIBRARIES}) 2 | include_directories(${RADIX_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}) 3 | 4 | add_custom_target(tests) 5 | 6 | function(test) 7 | set(TEST_NAME ${ARGV0}) 8 | set(TEST_SOURCES "") 9 | foreach(argn RANGE 1 ${ARGC}) 10 | list(APPEND TEST_SOURCES "${ARGV${argn}}") 11 | endforeach(argn) 12 | add_executable(${TEST_NAME} ${TEST_SOURCES}) 13 | target_link_libraries(${TEST_NAME} ${TEST_LIBRARIES}) 14 | add_dependencies(tests ${TEST_NAME}) 15 | add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME}) 16 | endfunction(test) 17 | 18 | test(XmlHelperTest XmlHelperTest.cpp) 19 | test(QuaternionTest ./core/math/QuaternionTest.cpp) 20 | test(MathTest ./core/math/MathTest.cpp) 21 | -------------------------------------------------------------------------------- /external/json11/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.6) 2 | 3 | if(CMAKE_VERSION VERSION_LESS "3") 4 | add_definitions(-std=c++11) 5 | else() 6 | set(CMAKE_CXX_STANDARD 11) 7 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 8 | endif() 9 | 10 | project(json11 CXX) 11 | add_library(json11 STATIC json11.cpp) 12 | target_compile_options(json11 PRIVATE -fno-rtti -fno-exceptions -Wall) 13 | 14 | # Set warning flags, which may vary per platform 15 | include(CheckCXXCompilerFlag) 16 | set(_possible_warnings_flags /W4 /WX -Wextra -Werror) 17 | foreach(_warning_flag in ${_possible_warnings_flags}) 18 | CHECK_CXX_COMPILER_FLAG(_warning_flag _flag_supported) 19 | if(${_flag_supported}) 20 | target_compile_options(json11 PRIVATE ${_warning_flag}) 21 | endif() 22 | endforeach() 23 | -------------------------------------------------------------------------------- /include/radix/GameWorld.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_GAME_WORLD_HPP 2 | #define RADIX_GAME_WORLD_HPP 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | namespace radix { 11 | 12 | class InputSource; 13 | struct Screen; 14 | 15 | class GameWorld { 16 | public: 17 | InputSource &input; 18 | radix::Screen &splashScreen; 19 | radix::Screen &pauseScreen; 20 | radix::Screen &gameOverScreen; 21 | GameWorld(InputSource &input); 22 | void addScreen(Screen& screen); 23 | void removeScreen(Screen& screen); 24 | std::list* getScreens(); 25 | private: 26 | std::list screens; 27 | }; 28 | 29 | } /* namespace radix */ 30 | 31 | #endif /* RADIX_GAME_WORLD_HPP */ 32 | -------------------------------------------------------------------------------- /cmake/Findeasy_profiler.cmake: -------------------------------------------------------------------------------- 1 | set(EASY_PROFILER_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/external/easy_profiler") 2 | set(EASY_PROFILER_INCLUDE_DIR "${EASY_PROFILER_ROOT_DIR}/easy_profiler_core/include") 3 | set(EASY_PROFILER_INCLUDE_DIRS "${EASY_PROFILER_INCLUDE_DIR}") 4 | set(EASY_PROFILER_LIBRARY "easy_profiler") 5 | set(EASY_PROFILER_LIBRARIES "${EASY_PROFILER_LIBRARY}") 6 | 7 | add_subdirectory("${EASY_PROFILER_ROOT_DIR}") 8 | 9 | set(BUILD_SHARED_LIBS OFF CACHE INTERNAL "") 10 | 11 | include(FindPackageHandleStandardArgs) 12 | find_package_handle_standard_args(easy_profiler DEFAULT_MSG 13 | EASY_PROFILER_LIBRARIES EASY_PROFILER_INCLUDE_DIRS) 14 | 15 | mark_as_advanced( 16 | EASY_PROFILER_LIBRARY EASY_PROFILER_LIBRARIES 17 | EASY_PROFILER_INCLUDE_DIR EASY_PROFILER_INCLUDE_DIRS) 18 | -------------------------------------------------------------------------------- /include/radix/core/gl/TightDataPacker.hpp: -------------------------------------------------------------------------------- 1 | #ifndef TIGHT_DATA_PACKER_HPP 2 | #define TIGHT_DATA_PACKER_HPP 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace radix { 9 | 10 | class TightDataPacker { 11 | protected: 12 | std::vector data; 13 | 14 | public: 15 | TightDataPacker() {} 16 | TightDataPacker(unsigned int reserveBytes); 17 | template TightDataPacker& operator<<(T k) { 18 | data.insert(data.end(), sizeof(k), 0); 19 | std::memcpy(&data[data.size()-sizeof(k)], &k, sizeof(k)); 20 | return *this; 21 | } 22 | void reserve(unsigned int bytes); 23 | unsigned int getSize() const; 24 | const uint8_t* getDataPtr() const; 25 | }; 26 | 27 | } /* namespace radix */ 28 | 29 | #endif /* TIGHT_DATA_PACKER_HPP */ 30 | -------------------------------------------------------------------------------- /include/radix/data/texture/Texture.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_TEXTURE_HPP 2 | #define RADIX_TEXTURE_HPP 3 | 4 | namespace radix { 5 | 6 | struct Texture { 7 | /** 8 | * @brief default constructor 9 | */ 10 | Texture() = default; 11 | 12 | /** 13 | * @brief Texture constructor 14 | * @param handle OpenGL Texture handler 15 | * @param width Texture width 16 | * @param height Texture height 17 | */ 18 | Texture(unsigned int handle, int width, int height) 19 | : handle(handle), width(width), height(height) {} 20 | 21 | unsigned int handle = 0; /** < OpenGL Texture handler */ 22 | int width; /** < Texture width */ 23 | int height; /** < Texture height */ 24 | }; 25 | 26 | } /* namespace radix */ 27 | 28 | #endif /* RADIX_TEXTURE_HPP */ 29 | -------------------------------------------------------------------------------- /source/Transform.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | namespace radix { 6 | 7 | /*void Transform::serialize(serine::Archiver &ar) { 8 | ar("pos", position); 9 | if (ar.isLoading() || (ar.isSaving() && (scale.x != 0 || scale.y != 0 || scale.z != 0))) { 10 | ar("scl", scale); 11 | } 12 | ar("orient", orientation); 13 | }*/ 14 | 15 | void Transform::applyModelMtx(Matrix4f &m) const { 16 | m.translate(position); 17 | m.rotate(orientation); 18 | m.scale(scale); 19 | } 20 | 21 | void Transform::getModelMtx(Matrix4f &m) const { 22 | m.setIdentity(); 23 | applyModelMtx(m); 24 | } 25 | 26 | Transform::operator btTransform() const { 27 | return btTransform(orientation, position); 28 | } 29 | 30 | } /* namespace radix */ 31 | -------------------------------------------------------------------------------- /source/api/RadixApi.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | 6 | namespace radix { 7 | 8 | RadixApi::RadixApi(World &world): world(world) { 9 | } 10 | 11 | void RadixApi::registerFunctions(asIScriptEngine *angelScript) { 12 | angelScript->RegisterGlobalFunction("void exit()", asMETHOD(RadixApi, exit), asCALL_THISCALL_ASGLOBAL, this); 13 | angelScript->RegisterGlobalFunction("void logDebug(const string &in category, const string &in message)", asMETHOD(RadixApi, logDebug), asCALL_THISCALL_ASGLOBAL, this); 14 | } 15 | 16 | void RadixApi::exit() { 17 | } 18 | 19 | void RadixApi::logDebug(std::string category, std::string message) { 20 | Util::Log(LogLevel::Debug, category) << message; 21 | } 22 | 23 | } /* namespace radix */ 24 | -------------------------------------------------------------------------------- /include/radix/renderer/ScreenRenderer.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_SCREENRENDERER_HPP 2 | #define RADIX_SCREENRENDERER_HPP 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | namespace radix { 13 | 14 | class ScreenRenderer : public SubRenderer{ 15 | public: 16 | ScreenRenderer(World& w, Renderer& ren, GameWorld& gw); 17 | 18 | void render(); 19 | 20 | private: 21 | void renderScreen(Screen* screen); 22 | int getHorizontalPositionByAlignment(Text::Align align, int viewportWidth, int textWidth); 23 | GameWorld &gameWorld; 24 | }; 25 | 26 | } /* namespace radix */ 27 | 28 | #endif /* RADIX_SCREENRENDERER_HPP */ 29 | -------------------------------------------------------------------------------- /include/radix/data/text/Font.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_FONT_HPP 2 | #define RADIX_FONT_HPP 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | namespace radix { 10 | 11 | class Font { 12 | public: 13 | int num_chars; 14 | float size; 15 | 16 | const Glyph& getGlyph(int index) const { 17 | return letters.at(index); 18 | } 19 | 20 | int getStringLength(const std::string &string) const { 21 | int length = 0; 22 | const char *array = string.c_str(); 23 | for (unsigned int i = 0; i < string.length(); i++) { 24 | const Glyph &letter = getGlyph(array[i]); 25 | length += letter.width * this->size; 26 | } 27 | return length; 28 | } 29 | 30 | std::map letters; 31 | }; 32 | 33 | } /* namespace radix */ 34 | 35 | #endif /* RADIX_FONT_HPP */ 36 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "external/vhacd-lib"] 2 | path = external/vhacd-lib 3 | url = https://github.com/GlPortal/vhacd-lib.git 4 | [submodule "external/serine"] 5 | path = external/serine 6 | url = https://github.com/GlPortal/serine.git 7 | [submodule "external/catch"] 8 | path = external/catch 9 | url = https://github.com/philsquared/Catch.git 10 | [submodule "external/linenoise"] 11 | path = external/linenoise 12 | url = https://github.com/GlPortal/cpp-linenoise.git 13 | [submodule "external/RadixEntity"] 14 | path = external/RadixEntity 15 | url = https://github.com/GlPortal/RadixEntity.git 16 | [submodule "external/easy_profiler"] 17 | path = external/easy_profiler 18 | url = https://github.com/yse/easy_profiler.git 19 | [submodule "external/AngelScript"] 20 | path = external/AngelScript 21 | url = https://github.com/GlPortal/script.git -------------------------------------------------------------------------------- /include/radix/env/ArgumentsParser.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_ARGUMENTS_PARSER_HPP 2 | #define RADIX_ARGUMENTS_PARSER_HPP 3 | 4 | #include 5 | #include 6 | 7 | namespace radix { 8 | 9 | class ArgumentsParser { 10 | private: 11 | static std::string mapName; 12 | static std::string mapPath; 13 | static bool showCursor; 14 | static bool ignoreGlVersion; 15 | static bool debugMode; 16 | static bool consoleEnabled; 17 | static bool profilerEnabled; 18 | static int screen; 19 | static const int NO_ARGUMENT; 20 | public: 21 | static void showUsage(char **argv); 22 | static void setEnvironmentFromArgs(const int argc, char **argv); 23 | static void populateConfig(radix::Config &config); 24 | static void showVersion(); 25 | }; 26 | 27 | } /* namespace radix */ 28 | 29 | #endif /* RADIX_ARGUMENTS_PARSER_HPP */ 30 | -------------------------------------------------------------------------------- /source/entities/traits/HealthTrait.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | #include 6 | 7 | namespace radix { 8 | namespace entities { 9 | 10 | HealthTrait::HealthTrait() : 11 | maxHealth(1.f), 12 | health(maxHealth) { 13 | } 14 | 15 | bool HealthTrait::isAlive() { 16 | return health > 0; 17 | } 18 | 19 | void HealthTrait::heal(float amount) { 20 | health = Math::clamp(health + amount, 0.f, maxHealth); 21 | } 22 | 23 | void HealthTrait::harm(float amount) { 24 | health = Math::clamp(health - amount, 0.f, maxHealth); 25 | } 26 | 27 | void HealthTrait::kill() { 28 | health = 0; 29 | } 30 | 31 | void HealthTrait::revive() { 32 | if (not isAlive()) { 33 | health = 1.f; 34 | } 35 | } 36 | 37 | } /* namespace entities */ 38 | } /* namespace radix */ 39 | -------------------------------------------------------------------------------- /documentation/resources/RadixEngine_icon_dark.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /include/radix/entities/traits/LightSourceTrait.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_ENTITIES_LIGHTSOURCE_TRAIT_HPP 2 | #define RADIX_ENTITIES_LIGHTSOURCE_TRAIT_HPP 3 | 4 | #include 5 | 6 | #include 7 | 8 | namespace radix { 9 | namespace entities { 10 | 11 | class LightSourceTrait : public Trait { 12 | public: 13 | bool enabled; 14 | Vector3f color; 15 | float distance; 16 | float energy; 17 | float specular; 18 | 19 | protected: 20 | LightSourceTrait() : 21 | enabled(true), 22 | color(1, 1, 1), 23 | distance(1), 24 | energy(10), 25 | specular(1) { 26 | } 27 | 28 | public: 29 | radix_trait_declare("radix/entities/traits/", "LightSource") 30 | }; 31 | 32 | } /* namespace entities */ 33 | } /* namespace radix */ 34 | 35 | #endif /* RADIX_ENTITIES_TRAITS_LIGHTSOURCE_TRAIT_HPP */ 36 | -------------------------------------------------------------------------------- /source/GameWorld.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace radix { 4 | GameWorld::GameWorld(InputSource &input) : 5 | input(input), 6 | splashScreen(radix::XmlScreenLoader::getScreen(radix::LegacyEnvironment::getDataDir() + "/screens/title.xml")), 7 | pauseScreen(radix::XmlScreenLoader::getScreen(radix::LegacyEnvironment::getDataDir() + "/screens/pause.xml")), 8 | gameOverScreen(radix::XmlScreenLoader::getScreen(radix::LegacyEnvironment::getDataDir() + "/screens/end.xml")) 9 | { 10 | } 11 | 12 | void GameWorld::addScreen(Screen &screen) { 13 | screens.push_back(&screen); 14 | } 15 | 16 | void GameWorld::removeScreen(Screen &screen) { 17 | screens.erase(std::remove(screens.begin(), screens.end(), &screen), screens.end()); 18 | } 19 | 20 | std::list* GameWorld::getScreens() { 21 | return &screens; 22 | } 23 | } /* namespace radix */ 24 | -------------------------------------------------------------------------------- /include/radix/data/screen/XmlScreenLoader.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_XML_SCREEN_LOADER_HPP 2 | #define RADIX_XML_SCREEN_LOADER_HPP 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | namespace radix { 14 | 15 | class XmlScreenLoader : public XmlLoader { 16 | public: 17 | static Screen& getScreen(const std::string& path); 18 | private: 19 | static std::map> screenCache; 20 | static std::shared_ptr loadScreen(const std::string& path); 21 | static const std::string MODULE_NAME; 22 | static bool loadText(tinyxml2::XMLHandle &rootHandle, std::vector* text); 23 | }; 24 | 25 | } /* namespace radix */ 26 | 27 | #endif /* RADIX_XML_SCREEN_LOADER_HPP */ 28 | -------------------------------------------------------------------------------- /include/radix/physics/GhostPairCallback.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_PHYSICS_GHOST_PAIR_CALLBACK_HPP 2 | #define RADIX_PHYSICS_GHOST_PAIR_CALLBACK_HPP 3 | 4 | #include 5 | 6 | namespace radix { 7 | 8 | class GhostPairCallback final: public btOverlappingPairCallback { 9 | public: 10 | GhostPairCallback() {} 11 | ~GhostPairCallback() override {} 12 | 13 | btBroadphasePair* addOverlappingPair( 14 | btBroadphaseProxy *proxy0, btBroadphaseProxy *proxy1) override; 15 | void* removeOverlappingPair( 16 | btBroadphaseProxy *proxy0, btBroadphaseProxy *proxy1, btDispatcher *dispatcher) override; 17 | void removeOverlappingPairsContainingProxy( 18 | btBroadphaseProxy *proxy, btDispatcher *dispatcher) override; 19 | }; 20 | 21 | } /* namespace radix */ 22 | 23 | #endif /* RADIX_PHYSICS_GHOST_PAIR_CALLBACK_HPP */ 24 | -------------------------------------------------------------------------------- /include/radix/core/diag/Throwables.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_THROWABLES_HPP 2 | #define RADIX_THROWABLES_HPP 3 | 4 | #include 5 | #include 6 | 7 | namespace radix { 8 | namespace Exception { 9 | 10 | class Error : public std::exception { 11 | protected: 12 | const std::string src, msg; 13 | 14 | public: 15 | Error(const std::string &s, const std::string &m) : src(s), msg(m) {} 16 | Error(const std::string &s, const char *m) : src(s), msg(m){} 17 | Error(const char *s, const std::string &m) : src(s), msg(m) {} 18 | Error(const char *s, const char *m) : src(s), msg(m) {} 19 | 20 | const char* source() const noexcept { 21 | return src.c_str(); 22 | } 23 | const char* what() const noexcept { 24 | return msg.c_str(); 25 | } 26 | }; 27 | 28 | 29 | } /* namespace Exception */ 30 | } /* namespace radix */ 31 | 32 | #endif /* RADIX_THROWABLES_HPP */ 33 | -------------------------------------------------------------------------------- /include/radix/core/diag/AnsiConsoleLogger.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_ANSI_CONSOLE_LOGGER_HPP 2 | #define RADIX_ANSI_CONSOLE_LOGGER_HPP 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | namespace radix { 10 | 11 | /** \class AnsiConsoleLogger 12 | * @brief Logger that outputs to an ANSI/vt-100 console 13 | */ 14 | class AnsiConsoleLogger : public Logger { 15 | protected: 16 | std::mutex mtx; 17 | 18 | public: 19 | /** 20 | * @brief Enables colored output 21 | */ 22 | bool enableColors; 23 | /** 24 | * @brief Enables colored backround on log tags 25 | */ 26 | bool enableBackground; 27 | 28 | AnsiConsoleLogger(); 29 | 30 | const char* getName() const; 31 | void log(const std::string &message, LogLevel lvl, const std::string &tag); 32 | }; 33 | } /* namespace radix */ 34 | 35 | #endif /* RADIX_ANSI_CONSOLE_LOGGER_HPP */ 36 | -------------------------------------------------------------------------------- /include/radix/core/diag/Logger.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_LOGGER_HPP 2 | #define RADIX_LOGGER_HPP 3 | 4 | #include 5 | 6 | namespace radix { 7 | 8 | enum LogLevel { 9 | Verbose, 10 | Debug, 11 | Info, 12 | Warning, 13 | Error, 14 | Failure 15 | }; 16 | 17 | /** \class Logger 18 | * @brief Base class to create log sinks 19 | */ 20 | class Logger { 21 | public: 22 | /** 23 | * @brief Returns the name of the Logger instance 24 | */ 25 | virtual const char* getName() const = 0; 26 | 27 | /** 28 | * @brief Log a message 29 | * 30 | * @param message Message to log 31 | * @param lvl Log level 32 | * @param tag Log tag, identifying the log category / class emitting the message 33 | */ 34 | virtual void log(const std::string &message, LogLevel lvl, const std::string &tag) = 0; 35 | }; 36 | 37 | } /* namespace radix */ 38 | 39 | #endif /* RADIX_LOGGER_HPP */ 40 | -------------------------------------------------------------------------------- /include/radix/core/math/Vector2i.hpp: -------------------------------------------------------------------------------- 1 | #ifndef VECTOR2I_HPP 2 | #define VECTOR2I_HPP 3 | 4 | #include 5 | 6 | namespace radix { 7 | 8 | struct Vector2i { 9 | union { 10 | int x, width; 11 | }; 12 | union { 13 | int y, height; 14 | }; 15 | 16 | static const Vector2i ZERO, UP; 17 | 18 | constexpr Vector2i() 19 | : x(0), y(0) {} 20 | constexpr Vector2i(int x, int y) 21 | : x(x), y(y) {} 22 | constexpr Vector2i(int v) 23 | : x(v), y(v) {} 24 | 25 | std::string str() const; 26 | 27 | constexpr bool operator==(const Vector2i &v) const { 28 | return x == v.x && y == v.y; 29 | } 30 | 31 | constexpr bool operator!=(const Vector2i &v) const { 32 | return x != v.x || y != v.y; 33 | } 34 | 35 | constexpr Vector2i operator-(const Vector2i& v) const { 36 | return Vector2i(x - v.x, y - v.y); 37 | } 38 | }; 39 | } /* namespace radix */ 40 | #endif /* VECTOR2I_HPP */ 41 | -------------------------------------------------------------------------------- /cmake/FindAssimp.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find Assimp 2 | # Once done, this will define 3 | # 4 | # ASSIMP_FOUND - system has Assimp 5 | # ASSIMP_INCLUDE_DIRS - the Assimp include directories 6 | # ASSIMP_LIBRARIES - link these to use Assimp 7 | 8 | FIND_PATH( ASSIMP_INCLUDE_DIR assimp/mesh.h 9 | /usr/include 10 | /usr/local/include 11 | /opt/local/include 12 | ) 13 | 14 | FIND_LIBRARY( ASSIMP_LIBRARY assimp 15 | /usr/lib64 16 | /usr/lib 17 | /usr/local/lib 18 | /opt/local/lib 19 | ) 20 | 21 | IF(ASSIMP_INCLUDE_DIR AND ASSIMP_LIBRARY) 22 | SET( ASSIMP_FOUND TRUE ) 23 | SET( ASSIMP_INCLUDE_DIRS ${ASSIMP_INCLUDE_DIR} ) 24 | SET( ASSIMP_LIBRARIES ${ASSIMP_LIBRARY} ) 25 | ENDIF(ASSIMP_INCLUDE_DIR AND ASSIMP_LIBRARY) 26 | 27 | # handle REQUIRED and QUIET options 28 | include ( FindPackageHandleStandardArgs ) 29 | 30 | find_package_handle_standard_args ( Assimp 31 | REQUIRED_VARS ASSIMP_LIBRARY ASSIMP_INCLUDE_DIR 32 | ) -------------------------------------------------------------------------------- /tools/cppcheckToHtml.xsl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | <!DOCTYPE html> 6 | 7 | 8 | GlPortal - static C/C++ code analysis 9 | 10 | 11 |

Static C/C++ code analysis of GlPortal

12 |

Based on the output of cppcheck.

13 |
    14 | 15 |
  • 16 | (): () 17 |
  • 18 |
    19 |
20 | 21 | 22 |
23 |
24 | -------------------------------------------------------------------------------- /source/core/file/Path.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | #ifndef _WIN32 6 | #include 7 | #endif 8 | 9 | 10 | namespace radix { 11 | 12 | std::string Path::GetDirectorySeparator() { 13 | #ifndef _WIN32 14 | return "/"; 15 | #else 16 | return "\\"; 17 | #endif 18 | } 19 | 20 | bool Path::DirectoryExist(std::string &directory) { 21 | #ifndef _WIN32 22 | struct stat sb; 23 | 24 | if (stat(directory.c_str(), &sb) == 0 and S_ISDIR(sb.st_mode)) { 25 | return true; 26 | } 27 | return false; 28 | #else 29 | return true; 30 | #endif 31 | } 32 | 33 | std::string Path::FromUnixPath(const std::string &unixPath) { 34 | std::string path(unixPath); 35 | #ifdef _WIN32 36 | for (unsigned int i = 0; i < path.size(); ++i) { 37 | if (path.at(i) == '/') { 38 | path.at(i) = '\\'; 39 | } 40 | } 41 | #endif 42 | return path; 43 | } 44 | 45 | } /* namespace radix */ 46 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # zlib License 2 | 3 | Copyright (c) 2016-2018 RadixEngine Team 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 18 | 2. Altered source versions must be plainly marked as such, and must not be 19 | misrepresented as being the original software. 20 | 21 | 3. This notice may not be removed or altered from any source 22 | distribution. 23 | -------------------------------------------------------------------------------- /include/radix/simulation/Simulation.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_SIMULATION_SIMULATION_HPP 2 | #define RADIX_SIMULATION_SIMULATION_HPP 3 | 4 | #include 5 | 6 | namespace radix { 7 | 8 | class BaseGame; 9 | class World; 10 | 11 | namespace simulation { 12 | 13 | class Simulation { 14 | protected: 15 | World &world; 16 | 17 | public: 18 | Simulation(World &w) : world(w) {} 19 | 20 | Simulation(const Simulation&) = delete; 21 | Simulation& operator=(const Simulation&) = delete; 22 | Simulation(Simulation&&) = delete; 23 | Simulation& operator=(Simulation&&) = delete; 24 | 25 | virtual const char* getName() const = 0; 26 | virtual bool runsBefore(const Simulation&) { return false; } 27 | virtual bool runsAfter(const Simulation&) { return false; } 28 | virtual void update(TDelta dtime) = 0; 29 | }; 30 | 31 | } /* namespace simulation */ 32 | } /* namespace radix */ 33 | 34 | #endif /* RADIX_SIMULATION_SIMULATION_HPP */ 35 | -------------------------------------------------------------------------------- /documentation/resources/style.css: -------------------------------------------------------------------------------- 1 | #top { 2 | background: #222; 3 | color: #fff; 4 | border-bottom: 1px solid hsl(40deg, 100%, 50%); 5 | } 6 | #projectname { 7 | font-size: 200%; 8 | font-family: "Liberation Sans", Tahoma, Arial, sans-serif; 9 | } 10 | #projectbrief { 11 | display: none; 12 | } 13 | #projectlogo { 14 | vertical-align: middle; 15 | } 16 | #titlearea { 17 | border-bottom: 1px solid hsl(40deg, 100%, 50%); 18 | } 19 | #titlearea table { 20 | padding-left: .5em; 21 | } 22 | #titlearea tr { 23 | height: auto !important; 24 | } 25 | .sm-dox { 26 | background: none; 27 | } 28 | .sm-dox a, .sm-dox a:focus, .sm-dox a:hover, .sm-dox a:active { 29 | line-height: normal; 30 | color: inherit; 31 | text-shadow: none; 32 | } 33 | #main-menu>li>ul { 34 | top: 2em !important; 35 | } 36 | #MSearchBox { 37 | margin-top: 0; 38 | height: auto; 39 | } 40 | #MSearchBox .left, #MSearchBox .right, #MSearchField { 41 | top: 0; 42 | background: #fff; 43 | } 44 | -------------------------------------------------------------------------------- /include/radix/SoundManager.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_SOUNDMANAGER_HPP 2 | #define RADIX_SOUNDMANAGER_HPP 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | #include 10 | 11 | namespace radix { 12 | 13 | class SoundManager { 14 | public: 15 | struct SoundInfo { 16 | Mix_Chunk *chunk; 17 | }; 18 | 19 | static void init(); 20 | static void reload(); 21 | static void destroy(); 22 | 23 | static void playMusic(const std::string &filename); 24 | static void playSound(const std::string &filename, const Entity &source); 25 | 26 | static bool isPlaying(const std::string &filename); 27 | 28 | static void update(const Entity &listener); 29 | 30 | private: 31 | static bool isInitialized, isDisabled; 32 | 33 | static std::string musicFilePlaying; 34 | static Mix_Music *music; 35 | static std::map sounds; 36 | }; 37 | 38 | } /* namespace radix */ 39 | 40 | #endif /* RADIX_SOUNDMANAGER_HPP */ 41 | -------------------------------------------------------------------------------- /include/radix/util/BulletUserPtrInfo.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_UTIL_BULLET_USER_PTR_INFO_HPP 2 | #define RADIX_UTIL_BULLET_USER_PTR_INFO_HPP 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | namespace radix { 10 | namespace util { 11 | 12 | struct BulletUserPtrInfo { 13 | Entity *entity; 14 | entities::Trait *trait; 15 | 16 | inline BulletUserPtrInfo(Entity *e = nullptr, entities::Trait *t = nullptr) : 17 | entity(e), 18 | trait(t) { 19 | } 20 | }; 21 | 22 | template 23 | inline T& getBtPtrAs(const btCollisionObject *o) { 24 | return *reinterpret_cast(o->getUserPointer()); 25 | } 26 | 27 | inline const BulletUserPtrInfo& getBtPtrInfo(const btCollisionObject *o) { 28 | return getBtPtrAs(o); 29 | } 30 | 31 | } /* namespace util */ 32 | } /* namespace radix */ 33 | 34 | #endif /* RADIX_UTIL_BULLET_USER_PTR_INFO_HPP */ 35 | -------------------------------------------------------------------------------- /include/radix/entities/StaticModel.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_ENTITIES_STATIC_MODEL_HPP 2 | #define RADIX_ENTITIES_STATIC_MODEL_HPP 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace radix { 9 | namespace entities { 10 | 11 | class StaticModel : 12 | public virtual Entity, 13 | public MeshDrawableTrait, 14 | public RigidBodyTrait { 15 | public: 16 | StaticModel(const CreationParams&); 17 | ~StaticModel(); 18 | 19 | int getCollisionFlags() const override; 20 | int getCollisionGroup() const override; 21 | int getCollisionMask() const override; 22 | 23 | std::string fullClassName() const override { 24 | return "radix/entities/StaticModel"; 25 | } 26 | std::string className() const override { 27 | return "StaticModel"; 28 | } 29 | }; 30 | 31 | } /* namespace entities */ 32 | } /* namespace radix */ 33 | 34 | #endif /* RADIX_ENTITIES_STATIC_MODEL_HPP */ 35 | -------------------------------------------------------------------------------- /source/input/GamePad.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace radix { 4 | GamePad::GamePad() :controller() { 5 | } 6 | 7 | void GamePad::create(){ 8 | int numJoysticks = SDL_NumJoysticks(); 9 | Util::Log(Verbose, "Window") << "Number of game pads " << std::to_string(numJoysticks); 10 | 11 | for (int i = 0; i < numJoysticks; ++i) { 12 | if (SDL_IsGameController(i)) { 13 | controller = SDL_GameControllerOpen(i); 14 | if (controller) { 15 | Util::Log(Warning, "Window") << "Game pad of index " << i << " loaded"; 16 | joystick = SDL_JoystickOpen(i); 17 | 18 | break; 19 | } else { 20 | Util::Log(Warning, "Window") << "Game pad of index " << i << " unable to load"; 21 | } 22 | } else { 23 | Util::Log(Warning, "Window") << "Game pad of index " << i << " not a controller"; 24 | } 25 | } 26 | } 27 | 28 | SDL_GameController &GamePad::getController() { 29 | return *(this->controller); 30 | } 31 | 32 | } /* namespace radix */ 33 | -------------------------------------------------------------------------------- /source/data/map/ScriptTrigger.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | using namespace std; 11 | 12 | namespace radix { 13 | 14 | const std::string ScriptTrigger::TYPE = "script"; 15 | 16 | ScriptTrigger::ScriptTrigger(const std::string &code) : 17 | code(code) { 18 | } 19 | 20 | void ScriptTrigger::addAction(Entity &entity) { 21 | entities::Trigger &trigger = dynamic_cast(entity); 22 | std::string sourceCode = code; 23 | trigger.setActionOnEnter([sourceCode] (entities::Trigger &trigger) { 24 | BaseGame &game = trigger.world.game; 25 | ScriptEngine* scriptEngine = game.getScriptEngine(); 26 | scriptEngine->runCode(sourceCode); 27 | }); 28 | } 29 | 30 | } /* namespace radix */ 31 | -------------------------------------------------------------------------------- /cmake/FindAngelScript.cmake: -------------------------------------------------------------------------------- 1 | set(ANGELSCRIPT_BASE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/external/AngelScript/sdk") 2 | set(ANGELSCRIPT_INCLUDE_DIRS 3 | "${ANGELSCRIPT_BASE_DIR}/angelscript/include" 4 | "${ANGELSCRIPT_BASE_DIR}/add_on") 5 | set(ANGELSCRIPT_LIBRARY "angelscript") 6 | set(ANGELSCRIPT_LIBRARIES ${ANGELSCRIPT_LIBRARY}) 7 | 8 | add_subdirectory("${ANGELSCRIPT_BASE_DIR}/angelscript/projects/cmake") 9 | 10 | target_sources("${ANGELSCRIPT_LIBRARY}" PUBLIC 11 | "${ANGELSCRIPT_BASE_DIR}/add_on/scriptarray/scriptarray.cpp" 12 | "${ANGELSCRIPT_BASE_DIR}/add_on/scripthandle/scripthandle.cpp" 13 | "${ANGELSCRIPT_BASE_DIR}/add_on/scriptstdstring/scriptstdstring.cpp" 14 | "${ANGELSCRIPT_BASE_DIR}/add_on/scriptstdstring/scriptstdstring_utils.cpp" 15 | "${ANGELSCRIPT_BASE_DIR}/add_on/weakref/weakref.cpp" 16 | ) 17 | 18 | include(FindPackageHandleStandardArgs) 19 | find_package_handle_standard_args(AngelScript DEFAULT_MSG ANGELSCRIPT_LIBRARY) 20 | 21 | mark_as_advanced(ANGELSCRIPT_BASE_DIR ANGELSCRIPT_INCLUDE_DIRS ANGELSCRIPT_LIBRARY ANGELSCRIPT_LIBRARIES) 22 | -------------------------------------------------------------------------------- /source/data/map/AudioTrigger.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | using namespace std; 9 | 10 | namespace radix { 11 | 12 | const std::string AudioTrigger::TYPE = "audio"; 13 | 14 | AudioTrigger::AudioTrigger(std::string filePath) { 15 | this->filePath = filePath; 16 | } 17 | 18 | void AudioTrigger::setLoop(bool loop) { 19 | this->loop = loop; 20 | } 21 | 22 | void AudioTrigger::addAction(Entity &ent) { 23 | entities::Trigger &trigger = dynamic_cast(ent); 24 | std::string datadir = LegacyEnvironment::getDataDir(); 25 | std::string fileName = datadir + "/audio/" + this->filePath; 26 | trigger.setActionOnEnter([fileName] (entities::Trigger &trigger) { 27 | if (!SoundManager::isPlaying(fileName)) { 28 | SoundManager::playMusic(fileName); 29 | } 30 | }); 31 | } 32 | 33 | } /* namespace radix */ 34 | -------------------------------------------------------------------------------- /source/core/math/Math.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | namespace radix { 10 | Vector3f Math::toDirection(const Quaternion &orientation) { 11 | return orientation * Vector3f::FORWARD; 12 | } 13 | 14 | Vector3f Math::toEuler(const Vector3f &direction) { 15 | Vector3f euler; 16 | 17 | // Pitch 18 | euler.x = asin(direction.y); 19 | 20 | // Yaw 21 | if (direction.x <= 0 && direction.z < 0) { 22 | euler.y = atan(fabs(direction.x) / fabs(direction.z)); 23 | } 24 | if (direction.x < 0 && direction.z >= 0) { 25 | euler.y = atan(fabs(direction.z) / fabs(direction.x)) + rad(90); 26 | } 27 | if (direction.x >= 0 && direction.z > 0) { 28 | euler.y = atan(fabs(direction.x) / fabs(direction.z)) + rad(180); 29 | } 30 | if (direction.x > 0 && direction.z <= 0) { 31 | euler.y = atan(fabs(direction.z) / fabs(direction.x)) + rad(270); 32 | } 33 | 34 | return euler; 35 | } 36 | 37 | } /* namespace radix */ 38 | -------------------------------------------------------------------------------- /external/json11/LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013 Dropbox, Inc. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /include/radix/core/event/Event.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_CORE_EVENT_EVENT_HPP 2 | #define RADIX_CORE_EVENT_EVENT_HPP 3 | 4 | #include 5 | 6 | #include 7 | 8 | #define radix_event_declare(TN) static constexpr StaticEventTypeName TypeName = TN; \ 9 | const EventTypeName getTypeName() const override { \ 10 | return TypeName; \ 11 | } \ 12 | static constexpr StaticEventType Type = TypeNameHash(TypeName); \ 13 | const EventType getType() const override { \ 14 | return Type; \ 15 | } 16 | 17 | namespace radix { 18 | 19 | using StaticEventType = const uint32_t; 20 | using EventType = uint32_t; 21 | using StaticEventTypeName = const char *const; 22 | using EventTypeName = std::string; 23 | 24 | struct Event { 25 | constexpr static EventType TypeNameHash(StaticEventTypeName etn) { 26 | return (EventType) Hash32(etn); 27 | } 28 | 29 | virtual const EventType getType() const = 0; 30 | virtual const EventTypeName getTypeName() const = 0; 31 | virtual std::string debugStringRepr() const { return ""; } 32 | }; 33 | 34 | } /* namespace radix */ 35 | 36 | #endif /* RADIX_CORE_EVENT_EVENT_HPP */ 37 | -------------------------------------------------------------------------------- /include/radix/core/math/Rectangle.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #ifndef RADIX_RECTANGLE_HPP 3 | #define RADIX_RECTANGLE_HPP 4 | 5 | namespace radix { 6 | 7 | /** \class Rectangle 8 | */ 9 | template 10 | struct Rectangle { 11 | T x, y, w, h; 12 | 13 | /* Core */ 14 | constexpr Rectangle() {} 15 | constexpr Rectangle(T x, T y, T w, T h) : 16 | x(x), y(y), w(w), h(h) {} 17 | 18 | constexpr void set(T x, T y, T w, T h) { 19 | this->x = x; 20 | this->y = y; 21 | this->w = w; 22 | this->h = h; 23 | } 24 | 25 | constexpr bool hasZeroArea() const { 26 | return w == 0 and h == 0; 27 | } 28 | 29 | /* Operator overloads */ 30 | constexpr bool operator==(const Rectangle &o) const { 31 | return x == o.x and 32 | y == o.y and 33 | w == o.w and 34 | h == o.h; 35 | } 36 | constexpr bool operator!=(const Rectangle &o) const { 37 | return !operator==(o); 38 | } 39 | }; 40 | 41 | using RectangleI = Rectangle; 42 | using RectangleF = Rectangle; 43 | using RectangleD = Rectangle; 44 | 45 | } /* namespace radix */ 46 | 47 | #endif /* RADIX_RECTANGLE_HPP */ 48 | -------------------------------------------------------------------------------- /source/api/PlayerApi.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | namespace radix { 6 | 7 | PlayerApi::PlayerApi(World &world): world(world) { 8 | } 9 | 10 | void PlayerApi::registerFunctions(asIScriptEngine *angelScript) { 11 | angelScript->RegisterGlobalFunction("void killPlayer()", asMETHOD(PlayerApi, kill), asCALL_THISCALL_ASGLOBAL, this); 12 | angelScript->RegisterGlobalFunction("void playerMoveY(float distance)", asMETHOD(PlayerApi, moveY), asCALL_THISCALL_ASGLOBAL, this); 13 | angelScript->RegisterGlobalFunction("void playerMoveX(float distance)", asMETHOD(PlayerApi, moveX), asCALL_THISCALL_ASGLOBAL, this); 14 | angelScript->RegisterGlobalFunction("void playerJump()", asMETHOD(PlayerApi, jump), asCALL_THISCALL_ASGLOBAL, this); 15 | } 16 | 17 | void PlayerApi::kill() { 18 | world.getPlayer().kill(); 19 | } 20 | 21 | void PlayerApi::moveY(float distance) { 22 | world.getPlayer().moveY(distance); 23 | } 24 | 25 | void PlayerApi::moveX(float distance) { 26 | world.getPlayer().moveX(distance); 27 | } 28 | 29 | void PlayerApi::jump() { 30 | world.getPlayer().jump(); 31 | } 32 | 33 | } /* namespace radix */ 34 | 35 | -------------------------------------------------------------------------------- /include/radix/data/map/XmlMapLoader.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_XMLMAPLOADER_HPP 2 | #define RADIX_XMLMAPLOADER_HPP 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | namespace radix { 13 | 14 | /** \class XmlMapLoader 15 | * Load a map in GlPortal XML format. 16 | * @ref map-format-spec 17 | */ 18 | class XmlMapLoader : public MapLoader { 19 | public: 20 | XmlMapLoader(World&, const std::list&); 21 | /** 22 | * Load data from XML into World. 23 | */ 24 | void load(const std::string &path); 25 | private: 26 | tinyxml2::XMLHandle rootHandle; 27 | std::list customTriggers; 28 | void extractMaterials(); 29 | /** 30 | * Extract a spawn element containing its rotation and position elements 31 | */ 32 | void extractSpawn(); 33 | void extractLights(); 34 | void extractDoor(); 35 | void extractWalls(); 36 | void extractAcids(); 37 | void extractDestinations(); 38 | void extractTriggers(); 39 | void extractModels(); 40 | }; 41 | 42 | } /* namespace radix */ 43 | 44 | #endif /* RADIX_XMLMAPLOADER_HPP */ 45 | -------------------------------------------------------------------------------- /include/radix/data/map/XmlTriggerHelper.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_XML_TRIGGER_HELPER_HPP 2 | #define RADIX_XML_TRIGGER_HELPER_HPP 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | namespace radix { 15 | 16 | class XmlTriggerHelper { 17 | public: 18 | static void extractTriggerActions(entities::Trigger &trigger, tinyxml2::XMLElement* xmlElement, const std::list& customTriggers); 19 | static void extractMapTriggerActions(entities::Trigger &trigger, tinyxml2::XMLElement *xmlElement); 20 | static void extractAudioTriggerActions(entities::Trigger &trigger, tinyxml2::XMLElement *xmlElement); 21 | static void extractDestinationTriggerActions(entities::Trigger &trigger, 22 | tinyxml2::XMLElement *xmlElement); 23 | static void extractScriptTriggerActions(entities::Trigger &trigger, tinyxml2::XMLElement *xmlElement); 24 | }; 25 | 26 | } /* namespace radix */ 27 | 28 | #endif /* RADIX_XML_TRIGGER_HELPER_HPP */ 29 | -------------------------------------------------------------------------------- /include/radix/env/Util.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_UTIL_HPP 2 | #define RADIX_UTIL_HPP 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | namespace radix { 12 | 13 | class Util { 14 | private: 15 | static std::unique_ptr logger; 16 | 17 | public: 18 | /*! \cond PRIVATE */ 19 | struct _Log { 20 | inline LogInput operator()(LogLevel lvl) { 21 | return LogInput(*Util::logger, lvl); 22 | } 23 | inline LogInput operator()(LogLevel lvl, const std::string &tag) { 24 | return LogInput(*Util::logger, lvl, tag); 25 | } 26 | inline LogInput operator()(LogLevel lvl, const char *tag) { 27 | return LogInput(*Util::logger, lvl, tag); 28 | } 29 | }; 30 | /*! \endcond */ 31 | static _Log Log; 32 | 33 | static std::random_device RandDev; 34 | static std::mt19937 Rand; 35 | 36 | static void Init(); 37 | 38 | static void SetCurrentThreadName(const char*); 39 | inline static void SetCurrentThreadName(const std::string &name) { 40 | SetCurrentThreadName(name.c_str()); 41 | } 42 | }; 43 | 44 | } /* namespace radix */ 45 | 46 | #endif /* RADIX_UTIL_HPP */ 47 | -------------------------------------------------------------------------------- /source/physics/PhysicsHelper.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | 6 | namespace radix { 7 | 8 | bool PhysicsHelper::pointInAABB(const btVector3 &p, const btVector3 &min, const btVector3 &max) { 9 | return p.x() >= min.x() && p.x() <= max.x() && 10 | p.y() >= min.y() && p.y() <= max.y() && 11 | p.z() >= min.z() && p.z() <= max.z(); 12 | } 13 | 14 | bool PhysicsHelper::pointInVolume(const btVector3 &p, const btCollisionObject &o) { 15 | btVector3 min, max; 16 | const btCollisionShape &s = *o.getCollisionShape(); 17 | const btTransform &t = o.getWorldTransform(); 18 | s.getAabb(t, min, max); 19 | // So far the following technique only works on collision shapes inheriting 20 | // from btPolyhedralConvexShape. Check for those. 21 | if (pointInAABB(p, min, max) && s.isPolyhedral() && s.isConvex()) { 22 | const btPolyhedralConvexShape &cs = (const btPolyhedralConvexShape&)s; 23 | return cs.isInside(t.inverse()(p), cs.getMargin()); 24 | } 25 | return false; 26 | } 27 | 28 | } /* namespace radix */ 29 | -------------------------------------------------------------------------------- /source/core/math/Vector2f.cpp: -------------------------------------------------------------------------------- 1 | /* --------------------------------------------------------------------------- 2 | ** This software is in the public domain, furnished "as is", without technical 3 | ** support, and with no warranty, express or implied, as to its usefulness for 4 | ** any purpose. 5 | ** 6 | ** Vector2f.cpp 7 | ** Implements a vector consisting of 2 float values and its helper functions 8 | ** 9 | ** Author: Nim 10 | ** -------------------------------------------------------------------------*/ 11 | 12 | #include 13 | 14 | #include 15 | #include 16 | 17 | namespace radix { 18 | 19 | const Vector2f Vector2f::ZERO(0, 0); 20 | const Vector2f Vector2f::UP(0, 1); 21 | 22 | /* Core */ 23 | float Vector2f::length() const { 24 | return sqrt(x * x + y * y); 25 | } 26 | 27 | std::string Vector2f::str() const { 28 | std::stringstream ss; 29 | ss << "(" << x << ", " << y << ")"; 30 | return ss.str(); 31 | } 32 | 33 | bool Vector2f::fuzzyEqual(const Vector2f &v, float threshold) const { 34 | return (x > v.x - threshold and x < v.x + threshold) and 35 | (y > v.y - threshold and y < v.y + threshold); 36 | } 37 | 38 | } /* namespace radix */ 39 | -------------------------------------------------------------------------------- /source/data/map/MapTrigger.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | using namespace std; 11 | 12 | namespace radix { 13 | 14 | const std::string MapTrigger::TYPE = "map"; 15 | 16 | MapTrigger::MapTrigger(const std::string &filePath) : 17 | filePath(filePath) { 18 | } 19 | 20 | void MapTrigger::addAction(Entity &ent) { 21 | entities::Trigger &trigger = dynamic_cast(ent); 22 | std::string fileName = filePath; 23 | trigger.setActionOnEnter([fileName] (entities::Trigger &trigger) { 24 | BaseGame &game = trigger.world.game; 25 | World &newWorld = game.createOtherWorld(fileName); 26 | game.deferPostCycle([fileName, &game, &newWorld] () { 27 | XmlMapLoader mapLoader(newWorld, game.getCustomTriggers()); 28 | mapLoader.load(LegacyEnvironment::getDataDir() + "/maps/" + fileName + ".xml"); 29 | game.switchToOtherWorld(fileName); 30 | }); 31 | }); 32 | } 33 | 34 | } /* namespace radix */ 35 | -------------------------------------------------------------------------------- /include/radix/data/material/MaterialLoader.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_MATERIAL_LOADER_HPP 2 | #define RADIX_MATERIAL_LOADER_HPP 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | namespace tinyxml2 { 10 | class XMLHandle; 11 | } 12 | 13 | namespace radix { 14 | 15 | class MaterialLoader { 16 | public: 17 | /** 18 | * @brief create material from xml file 19 | * 20 | * @param path xml file path 21 | * 22 | * @return material object 23 | */ 24 | static const Material loadFromXML(const std::string &path); 25 | 26 | /** 27 | * @brief get Material from XML file 28 | * 29 | * @param name XML file name 30 | * 31 | * @return Material Instance 32 | */ 33 | static const Material &getMaterial(const std::string &name); 34 | 35 | /** 36 | * @brief get Material from Texture 37 | * 38 | * @param name texture file name 39 | * 40 | * @return Material Instance 41 | */ 42 | static const Material &fromTexture(const std::string &name); 43 | 44 | private: 45 | /**< Cached map from created material*/ 46 | static std::map materialCache; 47 | }; 48 | 49 | } /* namespace radix */ 50 | 51 | #endif /* RADIX_MATERIAL_LOADER_HPP */ 52 | -------------------------------------------------------------------------------- /include/radix/util/BulletGhostPairCallbacks.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_UTIL_BULLET_GHOST_PAIR_CALLBACKS_HPP 2 | #define RADIX_UTIL_BULLET_GHOST_PAIR_CALLBACKS_HPP 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | namespace radix { 12 | namespace util { 13 | 14 | struct BulletGhostPairCallbacks : public BulletUserPtrInfo { 15 | struct CallbackParams { 16 | const BulletGhostPairCallbacks &gpCallbacks; 17 | btGhostObject *ghostObj; 18 | btCollisionObject *colObj; 19 | 20 | inline CallbackParams( 21 | const BulletGhostPairCallbacks &gpc, btGhostObject *go, btCollisionObject *co) : 22 | gpCallbacks(gpc), 23 | ghostObj(go), 24 | colObj(co) { 25 | } 26 | }; 27 | 28 | std::function onEnter, onExit; 29 | 30 | 31 | inline BulletGhostPairCallbacks(Entity *e = nullptr, entities::Trait *t = nullptr) : 32 | BulletUserPtrInfo(e, t) { 33 | } 34 | }; 35 | 36 | } /* namespace util */ 37 | } /* namespace radix */ 38 | 39 | #endif /* RADIX_UTIL_BULLET_GHOST_PAIR_CALLBACKS_HPP */ 40 | -------------------------------------------------------------------------------- /include/radix/renderer/TextRenderer.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_TEXT_RENDERER_HPP 2 | #define RADIX_TEXT_RENDERER_HPP 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | namespace radix { 13 | 14 | class TextRenderer { 15 | public: 16 | TextRenderer(World& w, Renderer& ren); 17 | void render(double dtime); 18 | 19 | /** 20 | * Renders a string to the screen using signed-distance field text rendering. 21 | * @param text The text to render 22 | */ 23 | void renderText(RenderContext &rc, Text text); 24 | 25 | /** 26 | * Meassures the width of text respecting the font 27 | * @param text 28 | * @param font 29 | * @return Width in pixels 30 | */ 31 | int getTextWidth(std::string text, Font font); 32 | static Matrix4f clipProjMat(const Entity &ent, const Matrix4f &view, const Matrix4f &proj); 33 | 34 | private: 35 | World &world; 36 | Renderer& renderer; 37 | 38 | std::unique_ptr renderContext; 39 | 40 | double time; 41 | }; 42 | 43 | } /* namespace radix */ 44 | 45 | #endif /* RADIX_TEXT_RENDERER_HPP */ 46 | -------------------------------------------------------------------------------- /include/radix/entities/traits/Trait.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_ENTITIES_TRAIT_HPP 2 | #define RADIX_ENTITIES_TRAIT_HPP 3 | 4 | #include 5 | 6 | #define radix_trait_declare(TNP, TN) virtual std::string fullTraitClassName() const override { \ 7 | return TNP TN; \ 8 | } \ 9 | virtual std::string traitClassName() const override { \ 10 | return TN; \ 11 | } 12 | 13 | namespace radix { 14 | 15 | class EntityManager; 16 | 17 | namespace entities { 18 | 19 | class Trait : protected virtual Entity { 20 | protected: 21 | friend EntityManager; 22 | friend Entity; 23 | 24 | Trait(); 25 | 26 | virtual void onRemoveTrait() {} 27 | 28 | public: 29 | inline Entity& entity() { 30 | return *this; 31 | } 32 | inline const Entity& entity() const { 33 | return *this; 34 | } 35 | 36 | /** 37 | * @brief Get the full virtual class path, without terminating "Trait" 38 | */ 39 | virtual std::string fullTraitClassName() const = 0; 40 | 41 | /** 42 | * @brief Get the virtual class name, without terminating "Trait" 43 | */ 44 | virtual std::string traitClassName() const = 0; 45 | }; 46 | 47 | } /* namespace entities */ 48 | } /* namespace radix */ 49 | 50 | #endif /* RADIX_ENTITIES_TRAIT_HPP */ 51 | -------------------------------------------------------------------------------- /include/radix/input/ChannelBase.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_CHANNEL_BASE_HPP 2 | #define RADIX_CHANNEL_BASE_HPP 3 | 4 | #include 5 | 6 | namespace radix { 7 | 8 | template 9 | class ChannelListener; 10 | 11 | template 12 | class ChannelBase { 13 | public: 14 | ChannelBase(); 15 | ChannelBase(ChannelListener *listener); 16 | 17 | void setId(const int &id) { this->id = id; } 18 | void addListener(ChannelListener *listener); 19 | void setDigital(const float &actPoint); 20 | void setAnalogue(const float &deadZone); 21 | void setBound(const float& bound); 22 | void setSensitivity(const float& sensitivity) { this->sensitivity = sensitivity; } 23 | void setAutoZero() { autoZero = true; } 24 | void setAlwaysNotifyListener() { alwaysNotifyListener = true; } 25 | void set(T newValue); 26 | int getId() const { return id; } 27 | T get() const { return value; } 28 | 29 | protected: 30 | void notifyListeners(); 31 | 32 | std::list*> listeners; 33 | int id; 34 | float bound, sensitivity; 35 | bool hasBound, isDigital, autoZero, alwaysNotifyListener; 36 | union { 37 | float deadZone, actPoint; 38 | }; 39 | T value; 40 | 41 | }; 42 | 43 | } 44 | 45 | #endif /* RADIX_INPUT_MANAGER_HPP */ 46 | -------------------------------------------------------------------------------- /source/Entity.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | static const char *Tag = "Entity"; 9 | 10 | namespace radix { 11 | 12 | Entity::Entity(const CreationParams &cp) : 13 | world(cp.world), id(cp.id) { 14 | } 15 | Entity::~Entity() { 16 | } 17 | 18 | void Entity::init() { 19 | Util::Log(Verbose, Tag) << "Create " << className() << '(' << id << ')'; 20 | } 21 | 22 | void Entity::setPosition(const Vector3f &val) { 23 | position = val; 24 | } 25 | 26 | void Entity::setScale(const Vector3f &val) { 27 | scale = val; 28 | } 29 | 30 | void Entity::setOrientation(const Quaternion &val) { 31 | orientation = val; 32 | } 33 | 34 | void Entity::setName(const std::string &newName) { 35 | onNameChange(newName); 36 | std::string oldName(std::move(m_name)); 37 | m_name = newName; 38 | world.entityManager.changeEntityName(*this, oldName, newName); 39 | world.event.dispatch(NameChangedEvent(*this, oldName)); 40 | } 41 | 42 | void Entity::remove() { 43 | for (auto trit = m_traits.rbegin(); trit != m_traits.rend(); ++trit) { 44 | (*trit)->onRemoveTrait(); 45 | } 46 | onRemove(); 47 | world.entityManager.queueDeleteEntity(this); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /include/radix/entities/ContactPlayerCallback.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_ENTITIES_CONTACT_PLAYER_CALLBACK_HPP 2 | #define RADIX_ENTITIES_CONTACT_PLAYER_CALLBACK_HPP 3 | 4 | namespace radix { 5 | namespace entities { 6 | 7 | class Player; 8 | 9 | class ContactPlayerCallback : public btCollisionWorld::ContactResultCallback { 10 | public: 11 | virtual btScalar addSingleResult(btManifoldPoint& cp, const btCollisionObjectWrapper* colObj0Wrap, 12 | int partId0, int index0,const btCollisionObjectWrapper* colObj1Wrap, int partId1, int index1) { 13 | Entity* playerEntity = util::getBtPtrInfo(colObj0Wrap->getCollisionObject()).entity; 14 | Entity* triggerEntity = util::getBtPtrInfo(colObj1Wrap->getCollisionObject()).entity; 15 | 16 | if (triggerEntity && playerEntity) { 17 | Trigger *trigger = dynamic_cast(triggerEntity); 18 | if (!trigger) { 19 | return 0; 20 | } 21 | trigger->onUpdate(); 22 | 23 | Player *player = dynamic_cast(playerEntity); 24 | if (player) { 25 | player->trigger = trigger; 26 | } 27 | } 28 | return 0; 29 | } 30 | }; 31 | 32 | } /* namespace entities */ 33 | } /* namespace radix */ 34 | 35 | #endif /* RADIX_ENTITIES_CONTACT_PLAYER_CALLBACK_HPP */ 36 | -------------------------------------------------------------------------------- /source/core/gl/OpenGL.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #if defined(RADIX_GL_USE_GLAD) 4 | #include 5 | #include 6 | #include 7 | #endif 8 | 9 | namespace radix { 10 | namespace gl { 11 | 12 | #if defined(RADIX_GL_USE_GLAD) 13 | static std::set extensions; 14 | #endif 15 | 16 | void OpenGL::initialize() { 17 | #if defined(RADIX_GL_USE_LIBEPOXY) 18 | // libepoxy initializes lazily 19 | #elif defined(RADIX_GL_USE_GLAD) 20 | if (!gladLoadGL()) { 21 | throw std::runtime_error("GLAD initialization failed"); 22 | } 23 | GLint n, i; 24 | glGetIntegerv(GL_NUM_EXTENSIONS, &n); 25 | for (i = 0; i < n; i++) { 26 | extensions.insert(reinterpret_cast(glGetStringi(GL_EXTENSIONS, i))); 27 | } 28 | #endif 29 | } 30 | 31 | int OpenGL::version() { 32 | #if defined(RADIX_GL_USE_LIBEPOXY) 33 | return epoxy_gl_version(); 34 | #elif defined(RADIX_GL_USE_GLAD) 35 | return GLVersion.major * 10 + GLVersion.minor; 36 | #endif 37 | } 38 | 39 | bool OpenGL::hasExtension(const char *ext) { 40 | #if defined(RADIX_GL_USE_LIBEPOXY) 41 | return epoxy_has_gl_extension(ext); 42 | #elif defined(RADIX_GL_USE_GLAD) 43 | return extensions.find(ext) != extensions.end(); 44 | #endif 45 | } 46 | 47 | } /* namespace gl */ 48 | } /* namespace radix */ 49 | -------------------------------------------------------------------------------- /source/data/map/TeleportTrigger.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace radix { 10 | 11 | const std::string TeleportTrigger::TYPE = "teleport"; 12 | 13 | TeleportTrigger::TeleportTrigger(std::string destination) : destination(destination) {} 14 | 15 | void TeleportTrigger::addAction(Entity &ent) { 16 | entities::Trigger &trigger = dynamic_cast(ent); 17 | 18 | std::string dest = destination; 19 | 20 | trigger.setActionOnUpdate([dest] (entities::Trigger &trigger) { 21 | entities::Player &player = trigger.world.getPlayer(); 22 | if (trigger.world.destinations.find(dest) 23 | != trigger.world.destinations.end()) { 24 | player.setPosition(trigger.world.destinations.at(dest).position); 25 | player.setOrientation(Quaternion().fromAero(trigger.world.destinations.at(dest) 26 | .rotation)); 27 | player.setHeadOrientation(Quaternion().fromAero(trigger.world.destinations.at(dest) 28 | .rotation)); 29 | } 30 | }); 31 | } 32 | 33 | } /* namespace radix */ 34 | -------------------------------------------------------------------------------- /include/radix/physics/PhysicsHelper.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_PHYSICS_HELPER_HPP 2 | #define RADIX_PHYSICS_HELPER_HPP 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace radix { 10 | 11 | class PhysicsHelper { 12 | private: 13 | PhysicsHelper(); 14 | 15 | public: 16 | class ContactResultHolder : public btCollisionWorld::ContactResultCallback { 17 | public: 18 | bool collides = false; 19 | btScalar addSingleResult(btManifoldPoint&, const btCollisionObjectWrapper*, int, int, 20 | const btCollisionObjectWrapper*, int, int) { 21 | collides = true; 22 | return 1; 23 | } 24 | }; 25 | 26 | static bool pointInAABB(const btVector3 &p, const btVector3 &min, const btVector3 &max); 27 | static inline bool pointInAABB(const btVector3 &p, const btAABB &aabb) { 28 | return pointInAABB(p, aabb.m_min, aabb.m_max); 29 | } 30 | 31 | static bool pointInVolume(const btVector3&, const btCollisionObject&); 32 | static inline bool pointInVolume(const btVector3 &v, const btCollisionObject *o) { 33 | return pointInVolume(v, *o); 34 | } 35 | }; 36 | 37 | } /* namespace radix */ 38 | 39 | #endif /* RADIX_PHYSICS_HELPER_HPP */ 40 | -------------------------------------------------------------------------------- /cmake/FindUnitTestPlusPlus.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # This CMake Module locates the UnitTest++ (http://unittest-cpp.sourceforge.net/) 3 | # C++ unit testing framework, enabling FIND_PACKAGE(UnitTestPlusPlus) to work. 4 | # 5 | 6 | FIND_PATH(UnitTestPlusPlus_INCLUDE_DIR UnitTest++.h /usr/include/unittest++) 7 | 8 | IF ("${UnitTestPlusPlus_INCLUDE_DIR}" MATCHES "NOTFOUND") 9 | FIND_PATH(UnitTestPlusPlus_INCLUDE_DIR UnitTest++.h /usr/include/UnitTest++) 10 | ENDIF ("${UnitTestPlusPlus_INCLUDE_DIR}" MATCHES "NOTFOUND") 11 | MARK_AS_ADVANCED(UnitTestPlusPlus_INCLUDE_DIR) 12 | 13 | FIND_LIBRARY(UnitTestPlusPlus_LIBRARY NAMES UnitTest++) 14 | MARK_AS_ADVANCED(UnitTestPlusPlus_LIBRARY) 15 | 16 | INCLUDE(FindPackageHandleStandardArgs) 17 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(UnitTestPlusPlus DEFAULT_MSG UnitTestPlusPlus_LIBRARY UnitTestPlusPlus_INCLUDE_DIR) 18 | 19 | IF ("${UnitTestPlusPlus_INCLUDE_DIR}" MATCHES "NOTFOUND") 20 | SET (UnitTestPlusPlus_LIBRARY) 21 | SET (UnitTestPlusPlus_INCLUDE_DIR) 22 | ELSEIF ("${UnitTestPlusPlus_LIBRARY}" MATCHES "NOTFOUND") 23 | SET (UnitTestPlusPlus_LIBRARY) 24 | SET (UnitTestPlusPLus_INCLUDE_DIR) 25 | ELSE ("${UnitTestPlusPlus_INCLUDE_DIR}" MATCHES "NOTFOUND") 26 | SET (UnitTestPlusPlus_FOUND 1) 27 | SET (UnitTestPlusPlus_LIBRARIES ${UnitTestPlusPlus_LIBRARY}) 28 | SET (UnitTestPlusPlus_INCLUDE_DIRS ${UnitTestPlusPlus_INCLUDE_DIR}) 29 | ENDIF ("${UnitTestPlusPlus_INCLUDE_DIR}" MATCHES "NOTFOUND") 30 | -------------------------------------------------------------------------------- /include/radix/physics/PhysicsDebugDraw.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_PHYSICS_DEBUG_DRAW_HPP 2 | #define RADIX_PHYSICS_DEBUG_DRAW_HPP 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | namespace radix { 15 | 16 | class PhysicsDebugDraw : public btIDebugDraw { 17 | private: 18 | int dbgMode; 19 | GLuint vao; 20 | std::unique_ptr vbo; 21 | struct PtData { 22 | float x, y, z, r, g, b; 23 | }; 24 | std::vector points; 25 | 26 | public: 27 | PhysicsDebugDraw(); 28 | ~PhysicsDebugDraw(); 29 | 30 | void drawLine(const btVector3 &from, const btVector3 &to, const btVector3 &color); 31 | void drawLine(const btVector3 &from, const btVector3 &to, const btVector3 &fromColor, 32 | const btVector3 &toColor); 33 | void reportErrorWarning(const char *warningString); 34 | void draw3dText(const btVector3 &location, const char *textString); 35 | void drawContactPoint(const btVector3 &PointOnB, const btVector3 &normalOnB, 36 | btScalar distance, int lifeTime, const btVector3 &color); 37 | void setDebugMode(int debugMode); 38 | int getDebugMode() const; 39 | 40 | void render(RenderContext &rc); 41 | }; 42 | 43 | } /* namespace radix */ 44 | 45 | #endif /* RADIX_PHYSICS_DEBUG_DRAW_HPP */ 46 | -------------------------------------------------------------------------------- /include/radix/data/map/XmlHelper.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_XML_HELPER_HPP 2 | #define RADIX_XML_HELPER_HPP 3 | 4 | #include 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | namespace radix { 12 | 13 | class XmlHelper { 14 | public: 15 | static void pushAttributeVertexToVector(tinyxml2::XMLElement *xmlElement, 16 | Vector3f &targetVector); 17 | static std::string mandatoryAttributeMessage; 18 | static std::string invalidElementMessage; 19 | static void throwMandatoryAttributeException(const std::string &message); 20 | static void extractPosition(tinyxml2::XMLElement *xmlElement, Vector3f &position); 21 | static void extractColor(tinyxml2::XMLElement *xmlElement, Vector3f &color); 22 | static void extractRotation(tinyxml2::XMLElement *xmlElement, Vector3f &rotation); 23 | static void extractScale(tinyxml2::XMLElement *xmlElement, Vector3f &scale); 24 | static void extractFileAttribute(tinyxml2::XMLElement *xmlElement, std::string &fileName); 25 | static bool extractBooleanAttribute(tinyxml2::XMLElement *xmlElement, std::string attribute, bool defaultValue); 26 | static std::string extractStringAttribute(tinyxml2::XMLElement *xmlElement, std::string attribute); 27 | static std::string extractStringMandatoryAttribute(tinyxml2::XMLElement *xmlElement, std::string attribute); 28 | }; 29 | 30 | } /* namespace radix */ 31 | 32 | #endif /* RADIX_XML_HELPER_HPP */ 33 | -------------------------------------------------------------------------------- /include/radix/entities/traits/RigidBodyTrait.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_ENTITIES_RIGID_BODY_TRAIT_HPP 2 | #define RADIX_ENTITIES_RIGID_BODY_TRAIT_HPP 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | namespace radix { 14 | namespace entities { 15 | 16 | class RigidBodyTrait : public Trait { 17 | protected: 18 | util::BulletUserPtrInfo m_btPtrInfo; 19 | 20 | RigidBodyTrait(); 21 | 22 | public: 23 | radix_trait_declare("radix/entities/traits/", "RigidBody") 24 | 25 | std::shared_ptr shape; 26 | btDefaultMotionState motionState; 27 | btRigidBody *body; 28 | 29 | virtual void onRemoveTrait() override; 30 | ~RigidBodyTrait(); 31 | 32 | virtual int getCollisionFlags() const; 33 | virtual int getCollisionGroup() const; 34 | virtual int getCollisionMask() const; 35 | void setRigidBody(float mass, 36 | const std::shared_ptr &collisionshape); 37 | 38 | virtual void setPosition(const Vector3f&) override; 39 | virtual void setScale(const Vector3f&) override; 40 | virtual void setOrientation(const Quaternion&) override; 41 | }; 42 | 43 | } /* namespace entities */ 44 | } /* namespace radix */ 45 | 46 | #endif /* RADIX_ENTITIES_TRAITS_RIGID_BODY_TRAIT_HPP */ 47 | -------------------------------------------------------------------------------- /include/radix/input/Bind.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_BIND_HPP 2 | #define RADIX_BIND_HPP 3 | 4 | namespace radix { 5 | 6 | struct Bind { 7 | short action; 8 | short inputType; 9 | short inputCode; 10 | float sensitivity; 11 | union { 12 | float deadZone, actPoint; 13 | }; 14 | enum InputType : int8_t { 15 | INPUT_TYPE_INVALID = -1, 16 | KEYBOARD = 0, 17 | MOUSE_BUTTON = 1, 18 | MOUSE_AXIS = 2, 19 | CONTROLLER_BUTTON = 3, 20 | CONTROLLER_AXIS = 4, 21 | CONTROLLER_TRIGGER = 5, 22 | INPUT_TYPE_MAX = 6 23 | }; 24 | static bool isInputTypeDigital(const int& input) { 25 | switch (input) { 26 | case MOUSE_AXIS: 27 | case CONTROLLER_AXIS: 28 | case CONTROLLER_TRIGGER: { 29 | return false; 30 | break; 31 | } 32 | case KEYBOARD: 33 | case MOUSE_BUTTON: 34 | case CONTROLLER_BUTTON: 35 | case INPUT_TYPE_INVALID: 36 | case INPUT_TYPE_MAX: 37 | default: { 38 | return true; 39 | break; 40 | } 41 | } 42 | } 43 | 44 | Bind() : 45 | action(-1), 46 | inputType(-1), 47 | inputCode(-1), 48 | sensitivity(1.0f), 49 | deadZone(0.0f) {} 50 | Bind(const int &action, const int &inputType, const int &inputCode, const float &sensitivity = 1.0f, const float &deadZone = 0.5) : 51 | action(action), 52 | inputType(inputType), 53 | inputCode(inputCode), 54 | sensitivity(sensitivity), 55 | deadZone(deadZone) {} 56 | }; 57 | 58 | } 59 | 60 | #endif /* RADIX_BIND_HPP */ 61 | -------------------------------------------------------------------------------- /include/radix/physics/Uncollider.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_UNCOLLIDER_HPP 2 | #define RADIX_UNCOLLIDER_HPP 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | namespace std { 11 | template 12 | struct hash> { 13 | std::size_t operator()(std::pair const &p) const { 14 | return (std::size_t)((p.second - p.first) * ((intptr_t)p.first ^ 0x412c765140f2fa32) + (intptr_t)p.second); 15 | } 16 | }; 17 | } 18 | 19 | namespace radix { 20 | 21 | class World; 22 | 23 | class Uncollider : public btOverlapFilterCallback { 24 | private: 25 | World &world; 26 | 27 | public: 28 | static std::list volumes; 29 | static std::unordered_set> 30 | collisonPairExclusions; 31 | static void addCollisonPairExclusion(btCollisionObject*, btCollisionObject*); 32 | static void removeCollisonPairExclusion(btCollisionObject*, btCollisionObject*); 33 | static bool isPointInUncollideVolume(const btVector3 &p); 34 | 35 | Uncollider(World&); 36 | void beforePhysicsStep(); 37 | bool needBroadphaseCollision(btBroadphaseProxy *proxy0, btBroadphaseProxy *proxy1) const; 38 | static void nearCallback(btBroadphasePair&, btCollisionDispatcher&, const btDispatcherInfo&); 39 | }; 40 | 41 | } /* namespace radix */ 42 | 43 | #endif /* RADIX_UNCOLLIDER_HPP */ 44 | -------------------------------------------------------------------------------- /source/World.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace radix { 10 | 11 | World::World(BaseGame &game) : 12 | gameTime(0), 13 | lastUpdateTime(0), 14 | game(game), 15 | simulations(*this), 16 | entityManager(*this) { 17 | event.debugLogLevel = EventDispatcher::DebugLogLevel::DispatchedEventsRepr; 18 | } 19 | 20 | World::~World() { 21 | } 22 | 23 | void World::setConfig(radix::Config &config) { 24 | this->config = &config; 25 | } 26 | 27 | radix::Config& World::getConfig() { 28 | return *(this->config); 29 | } 30 | 31 | void World::onCreate() { 32 | lastUpdateTime = SDL_GetTicks(); 33 | camera = std::make_unique(); 34 | } 35 | 36 | void World::onStart() { 37 | input = &game.getWindow(); 38 | input->addDispatcher(event); 39 | } 40 | 41 | void World::update(TDelta dtime) { 42 | gameTime += dtime; 43 | simulations.run(dtime); 44 | for (Entity &ent : entityManager) { 45 | ent.tick(dtime); 46 | } 47 | entityManager.doMaintenance(); 48 | } 49 | 50 | void World::onStop() { 51 | input->removeDispatcher(event); 52 | input = nullptr; 53 | } 54 | 55 | void World::onDestroy() { 56 | } 57 | 58 | entities::Player& World::getPlayer() { 59 | return *player; 60 | } 61 | 62 | void World::initPlayer() { 63 | player = &entityManager.create(); 64 | } 65 | 66 | } /* namespace radix */ 67 | -------------------------------------------------------------------------------- /include/radix/data/screen/Style.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_STYLE_HPP 2 | #define RADIX_STYLE_HPP 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | namespace radix { 11 | enum PositionMode { 12 | absolute, 13 | relative 14 | }; 15 | 16 | enum AlignMode { 17 | left, 18 | right, 19 | center 20 | }; 21 | 22 | /** 23 | * Represents element style 24 | */ 25 | class Style { 26 | public: 27 | Style(); 28 | Style operator+(Style& rightStyle); 29 | bool hasColor(); 30 | void setColor(Vector4i color); 31 | Vector4i getColor(); 32 | bool hasPosition(); 33 | void setPosition(Vector4i position); 34 | Vector4i getPosition(); 35 | bool hasMargin(); 36 | void setMargin(Vector4i margin); 37 | Vector4i getMargin(); 38 | bool hasPadding(); 39 | void setPadding(Vector4i padding); 40 | Vector4i getPadding(); 41 | bool hasAlignMode(); 42 | AlignMode getAlignMode(); 43 | void setAlignMode(AlignMode mode); 44 | bool hasPositionMode(); 45 | PositionMode getPositionMode(); 46 | void setPositionMode(PositionMode mode); 47 | private: 48 | std::pair color; 49 | std::pair position; 50 | std::pair margin; 51 | std::pair padding; 52 | std::pair alignMode; 53 | std::pair positionMode; 54 | }; 55 | } /* namespace radix */ 56 | 57 | #endif /* RADIX_STYLE_HPP */ 58 | -------------------------------------------------------------------------------- /include/radix/core/math/Math.hpp: -------------------------------------------------------------------------------- 1 | #ifndef MATH_HPP 2 | #define MATH_HPP 3 | 4 | #include 5 | #include 6 | 7 | namespace radix { 8 | 9 | /** \class Math 10 | * @brief Math helper class 11 | */ 12 | class Math { 13 | public: 14 | static constexpr float PI = 3.14159265358979323846f; 15 | static constexpr float DEG_TO_RAD = PI / 180; 16 | static constexpr float RAD_TO_DEG = 180 / PI; 17 | 18 | static Vector3f toDirection(const Quaternion &orientation); 19 | static Vector3f toEuler(const Vector3f &direction); 20 | 21 | /** Restricts a value to a range 22 | * @param v Value 23 | * @param low Low bound 24 | * @param high High bound 25 | */ 26 | template 27 | static constexpr inline T clamp(T v, T low, T high) { 28 | if (v < low) { 29 | return low; 30 | } else if (v > high) { 31 | return high; 32 | } 33 | return v; 34 | } 35 | 36 | /** Returns the sign of value 37 | * @param v value 38 | * @returns 1 if v is positive 39 | * -1 if v is negative 40 | * 0 if v is 0 41 | */ 42 | template 43 | static constexpr inline T sign(T v) { 44 | if (v > 0) { 45 | return 1; 46 | } 47 | if (v < 0) { 48 | return -1; 49 | } 50 | return 0; 51 | } 52 | }; 53 | 54 | constexpr inline float deg(float rad) { 55 | return rad * Math::RAD_TO_DEG; 56 | } 57 | 58 | constexpr inline float rad(float deg) { 59 | return deg * Math::DEG_TO_RAD; 60 | } 61 | 62 | } /* namespace radix */ 63 | 64 | #endif /* MATH_HPP */ 65 | -------------------------------------------------------------------------------- /include/radix/input/InputManager.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_INPUT_MANAGER_HPP 2 | #define RADIX_INPUT_MANAGER_HPP 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | namespace radix { 12 | 13 | class BaseGame; 14 | 15 | class InputManager : public DigitalChannelListener, VectorChannelListener { 16 | public: 17 | enum Action : int8_t { 18 | ACTION_INVALID = -1, 19 | PLAYER_MOVE_ANALOGUE = 0, 20 | PLAYER_LOOK_ANALOGUE, 21 | PLAYER_FORWARD, 22 | PLAYER_BACK, 23 | PLAYER_LEFT, 24 | PLAYER_RIGHT, 25 | PLAYER_JUMP, 26 | PLAYER_FIRE_PRIMARY, 27 | PLAYER_FIRE_SECONDARY, 28 | GAME_PAUSE, 29 | GAME_QUIT, 30 | GAME_START, 31 | ACTION_MAX 32 | }; 33 | 34 | InputManager() = delete; 35 | InputManager(BaseGame *baseGame); 36 | 37 | void init(); 38 | virtual void postInit() {} 39 | void reInit(); 40 | virtual void postReInit() {} 41 | 42 | virtual void channelChanged(bool newValue, const int &id) override; // DigitalChannelListener 43 | virtual void channelChanged(Vector2f newValue, const int &id) override; // VectorChannelListener 44 | 45 | Vector2f getPlayerMovementVector() const; 46 | 47 | static bool isActionDigital(const int &act); 48 | 49 | protected: 50 | bool initialised; 51 | BaseGame *game; 52 | std::unordered_map digitalChannels; 53 | std::unordered_map vectorChannels; 54 | 55 | }; 56 | 57 | } 58 | 59 | #endif /* RADIX_INPUT_MANAGER_HPP */ 60 | -------------------------------------------------------------------------------- /include/radix/core/types/TimeDelta.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_TIME_DELTA_HPP 2 | #define RADIX_TIME_DELTA_HPP 3 | 4 | #include 5 | 6 | namespace radix { 7 | 8 | class TimeDelta final { 9 | private: 10 | using Type = uint32_t; 11 | Type value; 12 | 13 | constexpr TimeDelta(Type microsecs) : value(microsecs) {} 14 | constexpr TimeDelta(double microsecs) : value(static_cast(microsecs)) {} 15 | constexpr TimeDelta(int microsecs) : value(static_cast(microsecs)) {} 16 | 17 | public: 18 | constexpr TimeDelta() : value(0) {} 19 | constexpr operator uint32_t() const { return value; } 20 | 21 | static constexpr TimeDelta sec(double t) { return TimeDelta(t*1000000); } 22 | static constexpr TimeDelta sec(int t) { return TimeDelta(t*1000000); } 23 | static constexpr TimeDelta sec(Type t) { return TimeDelta(t*1000000); } 24 | constexpr double sec() const { return value / 1000000.; } 25 | static constexpr TimeDelta msec(double t) { return TimeDelta(t*1000); } 26 | static constexpr TimeDelta msec(int t) { return TimeDelta(t*1000); } 27 | static constexpr TimeDelta msec(Type t) { return TimeDelta(t*1000); } 28 | constexpr double msec() const { return value / 1000.; } 29 | static constexpr TimeDelta usec(double t) { return TimeDelta(t); } 30 | static constexpr TimeDelta usec(int t) { return TimeDelta(t); } 31 | static constexpr TimeDelta usec(Type t) { return TimeDelta(t); } 32 | constexpr Type usec() const { return value; } 33 | constexpr double usec_d() const { return static_cast(value); } 34 | }; 35 | 36 | using TDelta = TimeDelta; 37 | 38 | } /* namespace radix */ 39 | 40 | #endif /* RADIX_TIME_DELTA_HPP */ 41 | -------------------------------------------------------------------------------- /external/json11/README.md: -------------------------------------------------------------------------------- 1 | json11 2 | ------ 3 | 4 | json11 is a tiny JSON library for C++11, providing JSON parsing and serialization. 5 | 6 | The core object provided by the library is json11::Json. A Json object represents any JSON 7 | value: null, bool, number (int or double), string (std::string), array (std::vector), or 8 | object (std::map). 9 | 10 | Json objects act like values. They can be assigned, copied, moved, compared for equality or 11 | order, and so on. There are also helper methods Json::dump, to serialize a Json to a string, and 12 | Json::parse (static) to parse a std::string as a Json object. 13 | 14 | It's easy to make a JSON object with C++11's new initializer syntax: 15 | 16 | Json my_json = Json::object { 17 | { "key1", "value1" }, 18 | { "key2", false }, 19 | { "key3", Json::array { 1, 2, 3 } }, 20 | }; 21 | std::string json_str = my_json.dump(); 22 | 23 | There are also implicit constructors that allow standard and user-defined types to be 24 | automatically converted to JSON. For example: 25 | 26 | class Point { 27 | public: 28 | int x; 29 | int y; 30 | Point (int x, int y) : x(x), y(y) {} 31 | Json to_json() const { return Json::array { x, y }; } 32 | }; 33 | 34 | std::vector points = { { 1, 2 }, { 10, 20 }, { 100, 200 } }; 35 | std::string points_json = Json(points).dump(); 36 | 37 | JSON values can have their values queried and inspected: 38 | 39 | Json json = Json::array { Json::object { { "k", "v" } } }; 40 | std::string str = json[0]["k"].string_value(); 41 | 42 | More documentation is still to come. For now, see json11.hpp. 43 | -------------------------------------------------------------------------------- /source/env/LegacyEnvironment.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | namespace radix { 10 | 11 | Config LegacyEnvironment::config; 12 | 13 | std::string LegacyEnvironment::dataDir = ""; 14 | 15 | void LegacyEnvironment::Init() { 16 | if (dataDir.empty()) { 17 | std::vector dataDirPaths = { 18 | "data" 19 | }; 20 | 21 | dataDirPaths.push_back("../data"); 22 | 23 | if(OperatingSystem::IsLinux()){ 24 | dataDirPaths.push_back("/usr/local/share/glportal/data"); 25 | dataDirPaths.push_back("/usr/share/glportal/data"); 26 | } 27 | 28 | for (auto & path : dataDirPaths) { 29 | Util::Log(Info, "DataDir") << "Searching data in " << path; 30 | if (Path::DirectoryExist(path)) { 31 | dataDir = path; 32 | Util::Log(Info, "DataDir") << "Found data in " << path; 33 | 34 | break; 35 | } 36 | } 37 | } 38 | InitializeConfig(); 39 | } 40 | 41 | Config& LegacyEnvironment::getConfig() { 42 | return config; 43 | } 44 | 45 | void LegacyEnvironment::InitializeConfig() { 46 | config.load(); 47 | } 48 | 49 | std::string LegacyEnvironment::getDataDir() { 50 | if (dataDir == "") { 51 | Util::Log(Info, "DataDir") << "No data dir set!"; 52 | exit(0); 53 | } 54 | 55 | return dataDir; 56 | } 57 | 58 | void LegacyEnvironment::setDataDir(const std::string &string) { 59 | Util::Log(Info, "DataDir") << "Setting data dir to " << string; 60 | dataDir = string; 61 | if (dataDir[dataDir.size() - 1] == '/') { 62 | dataDir = dataDir.substr(0, dataDir.length() - 1); 63 | } 64 | } 65 | 66 | } /* namespace radix */ 67 | -------------------------------------------------------------------------------- /source/util/XmlLoader.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace tinyxml2; 5 | 6 | namespace radix { 7 | 8 | bool XmlLoader::extractColor(XMLElement* currentElement, Vector4f* color) { 9 | if (currentElement) { 10 | currentElement->QueryFloatAttribute("r", &color->x); 11 | currentElement->QueryFloatAttribute("g", &color->y); 12 | currentElement->QueryFloatAttribute("b", &color->z); 13 | currentElement->QueryFloatAttribute("a", &color->w); 14 | return true; 15 | } 16 | return false; 17 | } 18 | 19 | void XmlLoader::handleFailureForElement(std::string module, std::string element, std::string path) { 20 | Util::Log(Error, module) << "Failed to load element " << element << " in " << path; 21 | } 22 | 23 | #if TINYXML2_MAJOR_VERSION < 5 24 | static const char *errorNames[] = { 25 | "XML_SUCCESS", 26 | "XML_NO_ATTRIBUTE", 27 | "XML_WRONG_ATTRIBUTE_TYPE", 28 | "XML_ERROR_FILE_NOT_FOUND", 29 | "XML_ERROR_FILE_COULD_NOT_BE_OPENED", 30 | "XML_ERROR_FILE_READ_ERROR", 31 | "XML_ERROR_ELEMENT_MISMATCH", 32 | "XML_ERROR_PARSING_ELEMENT", 33 | "XML_ERROR_PARSING_ATTRIBUTE", 34 | "XML_ERROR_IDENTIFYING_TAG", 35 | "XML_ERROR_PARSING_TEXT", 36 | "XML_ERROR_PARSING_CDATA", 37 | "XML_ERROR_PARSING_COMMENT", 38 | "XML_ERROR_PARSING_DECLARATION", 39 | "XML_ERROR_PARSING_UNKNOWN", 40 | "XML_ERROR_EMPTY_DOCUMENT", 41 | "XML_ERROR_MISMATCHED_ELEMENT", 42 | "XML_ERROR_PARSING", 43 | "XML_CAN_NOT_CONVERT_TEXT", 44 | "XML_NO_TEXT_NODE" 45 | }; 46 | #endif 47 | 48 | std::string XmlLoader::errorName(XMLError err) { 49 | #if TINYXML2_MAJOR_VERSION >= 5 50 | return tinyxml2::XMLDocument::ErrorIDToName(err); 51 | #else 52 | return errorNames[err]; 53 | #endif 54 | } 55 | 56 | } /* namespace radix */ 57 | -------------------------------------------------------------------------------- /include/radix/core/math/Matrix3f.hpp: -------------------------------------------------------------------------------- 1 | /* --------------------------------------------------------------------------- 2 | ** This software is in the public domain, furnished "as is", without technical 3 | ** support, and with no warranty, express or implied, as to its usefulness for 4 | ** any purpose. 5 | ** 6 | ** Matrix3f.hpp 7 | ** Declares a 3x3 matrix consisting of 9 float values and its helper functions 8 | ** 9 | ** Author: Nim 10 | ** -------------------------------------------------------------------------*/ 11 | 12 | #pragma once 13 | #ifndef MATRIX3F_HPP 14 | #define MATRIX3F_HPP 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | namespace radix { 21 | 22 | class Matrix4f; 23 | 24 | class Matrix3f { 25 | public: 26 | static const Matrix3f Identity; 27 | 28 | /* Core */ 29 | Matrix3f(); 30 | void setIdentity(); 31 | void translate(const Vector2f &v); 32 | void rotate(float angle); 33 | void scale(float scale); 34 | void scale(const Vector2f &scale); 35 | Vector3f transform(const Vector3f &v) const; 36 | 37 | float* toArray(); 38 | std::string str() const; 39 | 40 | /* Operator overloads */ 41 | inline float operator[](int i) const { 42 | return a[i]; 43 | } 44 | inline float& operator[](int i) { 45 | return a[i]; 46 | } 47 | bool operator==(const Matrix3f&) const; 48 | bool operator!=(const Matrix3f&) const; 49 | Matrix3f operator*(const Matrix3f&) const; 50 | private: 51 | float a[9]; 52 | }; 53 | 54 | /* Utility functions */ 55 | Matrix3f transpose(const Matrix3f& m); 56 | float determinant(const Matrix3f& m); 57 | Matrix3f inverse(const Matrix3f& m); 58 | Matrix4f toMatrix4f(const Matrix3f& m); 59 | 60 | } /* namespace radix */ 61 | 62 | #endif /* MATRIX3F_HPP */ 63 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://travis-ci.org/GlPortal/RadixEngine.svg?branch=master)](https://travis-ci.org/GlPortal/RadixEngine) 2 | [![Coverage Status](https://coveralls.io/repos/github/GlPortal/RadixEngine/badge.svg?branch=HEAD)](https://coveralls.io/github/GlPortal/RadixEngine?branch=HEAD) 3 | [![RadixEngine subreddit](https://img.shields.io/badge/reddit-/r/RadixEngine-brightgreen.svg)](https://www.reddit.com/r/RadixEngine/) 4 | [![Chat on Gitter](https://img.shields.io/gitter/room/GlPortal/glPortal.svg)](https://gitter.im/GlPortal/glPortal) 5 | [![Join Chat](https://img.shields.io/badge/discord-join_chat-brightgreen.svg)](https://discord.gg/c9VgpFqWfp) 6 | 7 | [![zlib License](https://img.shields.io/badge/license-zlib-blue.svg)](LICENSE.md) ![Language: C++14](https://img.shields.io/badge/language-C%2B%2B14-lightgrey.svg) [![Documentation Status](https://img.shields.io/badge/specification-latest-brightgreen.svg)](http://radix-spec.glportal.de/en/latest/) 8 | 9 | ![RadixEngine](https://raw.githubusercontent.com/GlPortal/glportal_raw_data/master/graphics/logo/radix/RadixEngine.png "RadixEngine") 10 | 11 | **Radix** is a modern, free and open-source 3D game engine, featuring, among other things, physics simulation. 12 | It runs on all modern operating systems including GNU/Linux, Mac and Windows. 13 | 14 | ## The Team 15 | Henry Hirsch, Julian Thijssen, Céleste Wouters, Geert Custers [all contributors](https://github.com/GlPortal/RadixEngine/graphs/contributors) 16 | 17 | ## Compile the source 18 | For instructions on how to compile the game engine please [read COMPILE.md](COMPILE.md). 19 | 20 | ## Issues 21 | Report Issues to [github](https://github.com/GlPortal/RadixEngine/issues). 22 | 23 | ## Donate 24 | Donate Bitcoin to 1JxrwJZgV9qBeEPH7BDF9qLJPSDcp6fqxz to help us pay for hosting and domain names. 25 | -------------------------------------------------------------------------------- /source/EntityManager.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | #include 6 | 7 | namespace radix { 8 | 9 | void EntityManager::entityAdded(Entity &ent) { 10 | idMap.emplace(std::piecewise_construct, 11 | std::forward_as_tuple(ent.id), 12 | std::forward_as_tuple(ent)); 13 | ent.init(); 14 | world.event.dispatch(EntityCreatedEvent(ent)); 15 | } 16 | 17 | void EntityManager::queueDeleteEntity(Entity *ent) { 18 | auto it = std::find_if(Base::begin(), Base::end(), [ent](const std::unique_ptr &p) { 19 | return p.get() == ent; 20 | }); 21 | if (it == Base::end()) { 22 | return; 23 | } 24 | m_queuedDeletions.emplace_back(std::move(*it)); 25 | Base::erase(it); 26 | } 27 | 28 | void EntityManager::changeEntityName(Entity &ent, const std::string &from, const std::string &to) { 29 | if (!from.empty()) { 30 | nameMap.erase(from); 31 | } 32 | if (!to.empty()) { 33 | nameMap.emplace(std::piecewise_construct, 34 | std::forward_as_tuple(to), 35 | std::forward_as_tuple(ent)); 36 | } 37 | } 38 | 39 | EntityManager::EntityManager(World &w) : 40 | m_lastAllocatedId(1), 41 | world(w) { 42 | } 43 | 44 | Entity& EntityManager::getById(EntityId id) { 45 | for (Entity &ent : *this) { 46 | if (ent.id == id) { 47 | return ent; 48 | } 49 | } 50 | throw std::out_of_range("No entity found by that ID"); 51 | } 52 | 53 | Entity& EntityManager::getByName(const std::string &name) { 54 | auto it = nameMap.find(name); 55 | if (it == nameMap.end()) { 56 | throw std::out_of_range("No entity found by that name"); 57 | } 58 | return it->second; 59 | } 60 | 61 | void EntityManager::doMaintenance() { 62 | if (m_queuedDeletions.size() > 0) { 63 | m_queuedDeletions.clear(); 64 | } 65 | } 66 | 67 | } /* namespace radix */ 68 | -------------------------------------------------------------------------------- /source/data/shader/Shader.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | namespace radix { 6 | 7 | void Shader::bind() const { 8 | glUseProgram(handle); 9 | } 10 | 11 | void Shader::release() const { 12 | glUseProgram(0); 13 | } 14 | 15 | int Shader::uni(const std::string &name) { 16 | // Check if the uniform name is already in our map 17 | auto it = locationMap.find(name); 18 | if (it != locationMap.end()) { 19 | return it->second; 20 | } 21 | 22 | // If its not, get the location and store it 23 | GLint loc = glGetUniformLocation(handle, name.c_str()); 24 | locationMap.insert({name, loc}); 25 | 26 | return loc; 27 | } 28 | 29 | int Shader::uni(const char *name) { 30 | // Check if the uniform name is already in our map 31 | auto it = locationMap.find(name); 32 | if (it != locationMap.end()) { 33 | return it->second; 34 | } 35 | 36 | // If its not, get the location and store it 37 | GLint loc = glGetUniformLocation(handle, name); 38 | locationMap.insert({name, loc}); 39 | 40 | return loc; 41 | } 42 | 43 | int Shader::att(const std::string &name) { 44 | // Check if the attribute name is already in our map 45 | auto it = locationMap.find(name); 46 | if (it != locationMap.end()) { 47 | return it->second; 48 | } 49 | 50 | // If its not, get the location and store it 51 | GLint loc = glGetAttribLocation(handle, name.c_str()); 52 | locationMap.insert({name, loc}); 53 | 54 | return loc; 55 | } 56 | 57 | int Shader::att(const char *name) { 58 | // Check if the attribute name is already in our map 59 | auto it = locationMap.find(name); 60 | if (it != locationMap.end()) { 61 | return it->second; 62 | } 63 | 64 | // If its not, get the location and store it 65 | GLint loc = glGetAttribLocation(handle, name); 66 | locationMap.insert({name, loc}); 67 | 68 | return loc; 69 | } 70 | 71 | } /* namespace radix */ 72 | -------------------------------------------------------------------------------- /CONTRIBUTE.md: -------------------------------------------------------------------------------- 1 | # GlPortal Contribution Guide 2 | 3 | ## All 4 | If you want to become part of the team or you need help, please say hi in [gitter](https://gitter.im/GlPortal/glPortal?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) or [irc](http://webchat.freenode.net/?channels=%23glportal&uio=d4). 5 | 6 | ## Developer 7 | - Follow the [compile guide](https://github.com/GlPortal/glPortal/blob/master/COMPILE.md) to compile the game. 8 | - Check the [bugtracker](https://bugs.glportal.de/) for tasks you want to do or add your own. 9 | - Send a pull request on github. 10 | 11 | ## Artist 12 | - Contact us through gitter or irc. 13 | 14 | ### Composers 15 | - Check our [music guidelines](https://github.com/GlPortal/specification/blob/master/music.md). 16 | - Optionaly add your note-sheets to our [repository](https://github.com/GlPortal/music). 17 | - Add your licence and tracks to [raw data repository](https://github.com/GlPortal/glportal_raw_data/tree/master/audio/music). 18 | 19 | ## Quality Control 20 | - If there is anything wrong with a commit do one of the following 21 | - Only if you can't fix it yourself comment objectively on the commit and tell the commiter exactly what the commit breaks. If you don't do this polite don't expect anyone to listen to you or aknowledge your existence. 22 | - Implement the change yourself and if you are not sure if everybody will agree then propose the change as a pull request (either way the chance to travel back in time is implied by git so mistakes are not to be treated as a catastrophy. If you want to do that you should work on center stage in a theater not on an open source project). 23 | 24 | ## Writers 25 | - Create a github account 26 | - Learn how to [use github in the browser](https://help.github.com/articles/github-flow-in-the-browser/) 27 | - Learn how to [edit files in other peoples repository](https://help.github.com/articles/editing-files-in-another-user-s-repository/) 28 | 29 | 30 | -------------------------------------------------------------------------------- /include/radix/input/Channel.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_CHANNEL_HPP 2 | #define RADIX_CHANNEL_HPP 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | namespace radix { 14 | 15 | template 16 | class SubChannel; 17 | 18 | class DigitalChannel: public ChannelBase, ChannelListener { 19 | public: 20 | DigitalChannel() = default; 21 | DigitalChannel(ChannelListener *listener) 22 | : ChannelBase(listener) {} 23 | void init(const int &id, EventDispatcher &event, const std::vector &binds); 24 | void reInit(EventDispatcher &event); 25 | 26 | void channelChanged(float newValue, const int &id) override; 27 | 28 | private: 29 | std::list> subChannels; 30 | 31 | }; 32 | 33 | class VectorChannel: public ChannelBase, ChannelListener { 34 | public: 35 | VectorChannel() = default; 36 | VectorChannel(ChannelListener *listener) 37 | : ChannelBase(listener) {} 38 | void init(const int &id, EventDispatcher &event, const std::vector &binds); 39 | void reInit(EventDispatcher &event); 40 | 41 | void channelChanged(Vector2f newValue, const int &id) override; 42 | 43 | private: 44 | std::list> subChannels; 45 | 46 | }; 47 | 48 | template 49 | class SubChannel: public ChannelBase { 50 | public: 51 | SubChannel() = default; 52 | SubChannel(ChannelListener *listener) 53 | : ChannelBase(listener) {} 54 | void init(const int &id, EventDispatcher &event, const Bind &bind); 55 | void reInit(EventDispatcher &event); 56 | 57 | private: 58 | void addObservers(EventDispatcher &event); 59 | 60 | Bind bind; 61 | 62 | }; 63 | 64 | } 65 | 66 | #endif /* RADIX_INPUT_MANAGER_HPP */ 67 | -------------------------------------------------------------------------------- /tests/RotationTest.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace radix; 7 | 8 | int main(int argc, char *argv[]) { 9 | Vector3f portalPos(4, 0, -2); 10 | Vector3f portalRot(0, -90, 0); 11 | Vector3f cameraPos(5, 0, -1); 12 | Vector3f cameraRot(-45, 90, 0); 13 | Vector3f oportalPos(-3, 0, 2); 14 | Vector3f oportalRot(0, 180, 0); 15 | 16 | //Set camera in other portal 17 | Vector3f camPos = Vector3f::sub(cameraPos, portalPos); 18 | Vector3f camDir = Math::toDirection(cameraRot); 19 | printf("The position relative to the portal:\n"); 20 | camPos.print(); 21 | 22 | //Invert the position and rotation to be behind the portal 23 | Vector3f icamPos = Vector3f::negate(camPos); 24 | Vector3f icamDir = Vector3f::negate(camDir); 25 | printf("The inverted position relative to the portal\n"); 26 | icamPos.print(); 27 | printf("The inverted direction relative to the portal\n"); 28 | icamDir.print(); 29 | 30 | //Calculate the position and rotation of the camera relative to the Z axis 31 | Matrix4f mAntiRot; 32 | mAntiRot.rotate(Vector3f::negate(portalRot)); 33 | 34 | Vector3f nrcamPos = mAntiRot.transform(icamPos); 35 | Vector3f nrcamDir = mAntiRot.transform(icamDir); 36 | printf("The position relative to the Z axis:\n"); 37 | nrcamPos.print(); 38 | printf("The direction relative to the Z axis:\n"); 39 | nrcamDir.print(); 40 | 41 | //Calculate the position and rotation of the camera relative to the other portal 42 | Matrix4f mRot; 43 | mRot.rotate(oportalRot); 44 | 45 | Vector3f rcamPos = mRot.transform(nrcamPos); 46 | Vector3f rcamDir = mRot.transform(nrcamDir); 47 | printf("The position relative to the other portal:\n"); 48 | rcamPos.print(); 49 | printf("The direction relative to the other portal:\n"); 50 | rcamDir.print(); 51 | 52 | Vector3f rcamRot = Math::toEuler(rcamDir); 53 | printf("The rotation relative to the other portal:\n"); 54 | rcamRot.print(); 55 | 56 | return 0; 57 | } 58 | -------------------------------------------------------------------------------- /include/radix/entities/Trigger.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_COMPONENT_TRIGGER_HPP 2 | #define RADIX_COMPONENT_TRIGGER_HPP 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | namespace radix { 16 | 17 | class BaseGame; 18 | 19 | namespace entities { 20 | 21 | class Trigger : public Entity { 22 | private: 23 | util::BulletGhostPairCallbacks bulletGhostPairCallbacks; 24 | std::unique_ptr ghostObject; 25 | std::unique_ptr shape; 26 | 27 | public: 28 | using Action = std::function; 29 | 30 | Action actionOnEnter; 31 | Action actionOnExit; 32 | Action actionOnMove; 33 | Action actionOnUpdate; 34 | 35 | Trigger(const CreationParams&); 36 | Trigger(const CreationParams&, const Transform&); 37 | ~Trigger(); 38 | 39 | void setActionOnExit(Action action); 40 | void setActionOnEnter(Action action); 41 | void setActionOnMove(Action action); 42 | void setActionOnUpdate(Action action); 43 | 44 | void serialize(serine::Archiver &ar) { 45 | } 46 | 47 | void onEnter() { actionOnEnter(*this); } 48 | void onExit() { actionOnExit(*this); } 49 | void onMove() { actionOnMove(*this); } 50 | void onUpdate() { actionOnUpdate(*this); } 51 | 52 | virtual void setPosition(const Vector3f&) override; 53 | virtual void setOrientation(const Quaternion&) override; 54 | virtual void setScale(const Vector3f&) override; 55 | 56 | btGhostObject* getBulletGhostObject() const; 57 | 58 | std::string fullClassName() const override { 59 | return "radix/entities/Trigger"; 60 | } 61 | std::string className() const override { 62 | return "Trigger"; 63 | } 64 | }; 65 | 66 | } /* namespace entities */ 67 | } /* namespace radix */ 68 | 69 | #endif /* RADIX_COMPONENT_TRIGGER_HPP */ 70 | -------------------------------------------------------------------------------- /cmake/FindCXX14.cmake: -------------------------------------------------------------------------------- 1 | # - Finds if the compiler has C++14 support 2 | # This module can be used to detect compiler flags for using C++14, and checks 3 | # a small subset of the language. 4 | # 5 | # The following variables are set: 6 | # CXX14_FLAGS - flags to add to the CXX compiler for C++14 support 7 | # CXX14_FOUND - true if the compiler supports C++14 8 | # 9 | # TODO: When compilers starts implementing the whole C++14, check the full set 10 | 11 | include(CheckCXXSourceCompiles) 12 | include(FindPackageHandleStandardArgs) 13 | 14 | set(CXX14_FLAG_CANDIDATES 15 | # GCC 6+ and everything that automatically accepts C++14 16 | " " 17 | # GCC < 6 and Intel Linux 18 | "-std=c++14" 19 | # Intel Windows 20 | "/Qstd=c++14" 21 | ) 22 | 23 | set(CXX14_TEST_SOURCE 24 | " 25 | [[deprecated]] void unused() {} 26 | 27 | template 28 | constexpr T pi = T(3.1415926535897932385); 29 | 30 | constexpr int numberwang(int n) { 31 | if (n < 0) { 32 | return 0b1'1001'0101; 33 | } 34 | return n - 1; 35 | } 36 | 37 | auto lambda = [v = 0](auto a, auto b) { return v + a * b; }; 38 | 39 | auto square(int n) { 40 | return lambda(n, n) * numberwang(2); 41 | } 42 | 43 | int main() { 44 | int s = square(3); 45 | double pie = pi; 46 | return 0; 47 | } 48 | ") 49 | 50 | set(SAVE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}") 51 | foreach(FLAG ${CXX14_FLAG_CANDIDATES}) 52 | set(CMAKE_REQUIRED_FLAGS "${FLAG}") 53 | unset(CXX14_FLAG_DETECTED CACHE) 54 | message(STATUS "Trying C++14 flag '${FLAG}'") 55 | check_cxx_source_compiles("${CXX14_TEST_SOURCE}" CXX14_FLAG_DETECTED) 56 | if(CXX14_FLAG_DETECTED) 57 | set(CXX14_FLAGS_INTERNAL "${FLAG}") 58 | break() 59 | endif(CXX14_FLAG_DETECTED) 60 | endforeach(FLAG ${CXX14_FLAG_CANDIDATES}) 61 | set(CMAKE_REQUIRED_FLAGS "${SAVE_CMAKE_REQUIRED_FLAGS}") 62 | unset(SAVE_CMAKE_REQUIRED_FLAGS) 63 | 64 | set(CXX14_FLAGS "${CXX14_FLAGS_INTERNAL}") 65 | 66 | find_package_handle_standard_args(CXX14 DEFAULT_MSG CXX14_FLAGS) 67 | mark_as_advanced(CXX14_FLAGS) 68 | -------------------------------------------------------------------------------- /include/radix/entities/Player.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_ENTITIES_PLAYER_HPP 2 | #define RADIX_ENTITIES_PLAYER_HPP 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | namespace radix { 17 | 18 | class Vector2f; 19 | 20 | namespace entities { 21 | 22 | class Player : 23 | public virtual Entity, 24 | public HealthTrait, 25 | public SoundSourceTrait { 26 | protected: 27 | util::BulletGhostPairCallbacks m_btGpCallbacks; 28 | 29 | public: 30 | std::shared_ptr shape; 31 | btPairCachingGhostObject *obj; 32 | KinematicCharacterController *controller; 33 | 34 | Vector3f velocity, headAngle; 35 | bool flying, noclip, frozen, attemptJump; 36 | float speed; 37 | float stepCounter; 38 | Vector3f newMovement, oldMovement, headingChange; 39 | 40 | Trigger *trigger; 41 | 42 | Player(const CreationParams&); 43 | ~Player(); 44 | 45 | void tick(TDelta) override; 46 | void jump(); 47 | void move(const Vector2f &move); 48 | void moveX(const float &move); 49 | void moveY(const float &move); 50 | void changeHeading(const Vector2f& lookVector); 51 | 52 | Quaternion getBaseHeadOrientation() const; 53 | Quaternion getHeadOrientation() const; 54 | inline void setHeadOrientation(Quaternion &quaternion) { 55 | headAngle = quaternion.toAero(); 56 | } 57 | 58 | virtual void setPosition(const Vector3f&) override; 59 | 60 | std::string fullClassName() const override { 61 | return "radix/entities/Player"; 62 | } 63 | std::string className() const override { 64 | return "Player"; 65 | } 66 | }; 67 | 68 | } /* namespace entities */ 69 | } /* namespace radix */ 70 | 71 | #endif /* RADIX_ENTITIES_PLAYER_HPP */ 72 | -------------------------------------------------------------------------------- /source/renderer/TextRenderer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | namespace radix { 14 | 15 | TextRenderer::TextRenderer(World &w, Renderer &ren) : 16 | world(w), 17 | renderer(ren) { 18 | renderContext = std::make_unique(ren); 19 | } 20 | 21 | int TextRenderer::getTextWidth(std::string text, Font font) { 22 | return font.getStringLength(text); 23 | } 24 | 25 | void TextRenderer::renderText(RenderContext &rc, Text text) { 26 | PROFILER_BLOCK("TextRenderer::renderText"); 27 | // FIXME This should be determined by the currently set font 28 | const Material &mat = MaterialLoader::fromTexture("Pacaya.png"); 29 | Shader &shader = ShaderLoader::getShader("text.frag"); 30 | shader.bind(); 31 | Vector4f color = text.color; 32 | glUniform4f(shader.uni("color"), color.x, color.y, color.z, color.w); 33 | Vector2f position(text.position.x, text.position.y); 34 | Matrix4f mtx; 35 | 36 | const char *array = text.content.c_str(); 37 | for (unsigned int i = 0; i < text.content.length(); i++) { 38 | char c = array[i]; 39 | 40 | Font font = FontLoader::getFont(text.font); 41 | font.size = text.size; 42 | const Glyph &letter = font.getGlyph(c); 43 | const Mesh &mesh = letter.mesh; 44 | 45 | mtx.setIdentity(); 46 | mtx.translate(Vector3f(position.x + letter.xOffset * font.size, 47 | position.y + letter.yOffset * font.size, 48 | text.position.z)); 49 | 50 | mtx.scale(Vector3f(letter.width * font.size, 51 | letter.height * font.size, 1)); 52 | 53 | renderer.renderMesh(rc, shader, mtx, mesh, mat); 54 | position.x += letter.advance * font.size; 55 | } 56 | shader.release(); 57 | } 58 | } /* namespace radix */ 59 | -------------------------------------------------------------------------------- /include/radix/core/math/Matrix4f.hpp: -------------------------------------------------------------------------------- 1 | /* --------------------------------------------------------------------------- 2 | ** This software is in the public domain, furnished "as is", without technical 3 | ** support, and with no warranty, express or implied, as to its usefulness for 4 | ** any purpose. 5 | ** 6 | ** Matrix4f.hpp 7 | ** Declares a 4x4 matrix consisting of 16 float values and its helper functions 8 | ** 9 | ** Author: Nim 10 | ** -------------------------------------------------------------------------*/ 11 | 12 | #pragma once 13 | #ifndef MATRIX4F_HPP 14 | #define MATRIX4F_HPP 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | namespace radix { 21 | 22 | class Matrix3f; 23 | 24 | class Matrix4f { 25 | public: 26 | static const Matrix4f Identity; 27 | 28 | /* Core */ 29 | Matrix4f(); 30 | Matrix4f(const Vector3f&, const Quaternion&); 31 | void setIdentity(); 32 | void translate(const Vector3f &v); 33 | void rotate(float angle, float x, float y, float z); 34 | void rotate(const Quaternion &quat); 35 | void scale(float scale); 36 | void scale(const Vector3f &scale); 37 | Vector3f transform(const Vector3f &v) const; 38 | 39 | float *toArray(); 40 | const float* toArray() const; 41 | std::string str() const; 42 | 43 | Quaternion getRotation() const; 44 | Vector3f getPosition() const; 45 | 46 | /* Operator overloads */ 47 | inline float operator[](int i) const { 48 | return a[i]; 49 | } 50 | inline float& operator[](int i) { 51 | return a[i]; 52 | } 53 | bool operator==(const Matrix4f&) const; 54 | bool operator!=(const Matrix4f&) const; 55 | Matrix4f operator*(const Matrix4f&) const; 56 | Vector4f operator*(const Vector4f&) const; 57 | Vector3f operator*(const Vector3f&) const; 58 | private: 59 | float a[16]; 60 | }; 61 | 62 | /* Utility functions */ 63 | Matrix4f transpose(const Matrix4f& m); 64 | float determinant(const Matrix4f& m); 65 | Matrix4f inverse(const Matrix4f& m); 66 | Matrix3f toMatrix3f(const Matrix4f& m); 67 | 68 | } /* namespace radix */ 69 | 70 | #endif /* MATRIX4F_HPP */ 71 | -------------------------------------------------------------------------------- /source/core/diag/LogInput.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | namespace radix { 12 | 13 | LogInput::LogInput(Logger &sink, LogLevel lvl, const char *tag) : 14 | sink(sink), lvl(lvl), tag(tag) { 15 | } 16 | 17 | LogInput::LogInput(Logger &sink, LogLevel lvl, const std::string &tag) : 18 | sink(sink), lvl(lvl), tag(tag) { 19 | } 20 | 21 | LogInput::~LogInput() { 22 | if (not buf.empty()) { 23 | sink.log(buf, lvl, tag); 24 | } 25 | } 26 | 27 | LogInput::LogInput(LogInput &&o) : 28 | sink(o.sink), lvl(o.lvl), buf(o.buf) { 29 | o.buf.clear(); 30 | } 31 | 32 | LogInput& LogInput::operator<<(const char *s) { 33 | buf.append(s); 34 | return *this; 35 | } 36 | 37 | LogInput& LogInput::operator<<(const std::string &s) { 38 | buf.append(s); 39 | return *this; 40 | } 41 | 42 | LogInput& LogInput::operator<<(const stx::string_view &s) { 43 | buf.append(s.cbegin(), s.cend()); 44 | return *this; 45 | } 46 | 47 | 48 | LogInput& LogInput::operator<<(bool b) { 49 | buf.append(b ? "true" : "false"); 50 | return *this; 51 | } 52 | 53 | LogInput& LogInput::operator<<(char c) { 54 | buf.push_back(c); 55 | return *this; 56 | } 57 | 58 | LogInput& LogInput::operator<<(const void *ptr) { 59 | std::stringbuf hbuf; 60 | std::ostream os(&hbuf); 61 | os << "0x" << std::setfill('0') << std::setw(sizeof(ptr) * 2) << std::hex << (uint64_t)ptr; 62 | buf.append(hbuf.str()); 63 | return *this; 64 | } 65 | 66 | 67 | LogInput& LogInput::operator<<(const Vector2f &v) { 68 | *this << '(' << v.x << ", " << v.y << ')'; 69 | return *this; 70 | } 71 | 72 | LogInput& LogInput::operator<<(const Vector3f &v) { 73 | *this << '(' << v.x << ", " << v.y << ", " << v.z << ')'; 74 | return *this; 75 | } 76 | 77 | LogInput& LogInput::operator<<(const Vector4f &v) { 78 | *this << '(' << v.x << ", " << v.y << ", " << v.z << ", " << v.w << ')'; 79 | return *this; 80 | } 81 | 82 | } /* namespace radix */ 83 | -------------------------------------------------------------------------------- /source/core/math/Vector3f.cpp: -------------------------------------------------------------------------------- 1 | /* --------------------------------------------------------------------------- 2 | ** This software is in the public domain, furnished "as is", without technical 3 | ** support, and with no warranty, express or implied, as to its usefulness for 4 | ** any purpose. 5 | ** 6 | ** Vector3f.cpp 7 | ** Implements a vector consisting of 3 float values and its helper functions 8 | ** 9 | ** Author: Nim 10 | ** -------------------------------------------------------------------------*/ 11 | 12 | #include 13 | 14 | #include 15 | #include 16 | 17 | #include 18 | 19 | #include 20 | 21 | namespace radix { 22 | 23 | const Vector3f Vector3f::ZERO(0, 0, 0); 24 | const Vector3f Vector3f::FORWARD(0, 0, -1); 25 | const Vector3f Vector3f::UP(0, 1, 0); 26 | 27 | /* Core */ 28 | float Vector3f::length() const { 29 | return sqrt(x * x + y * y + z * z); 30 | } 31 | 32 | std::string Vector3f::str() const { 33 | std::stringstream ss; 34 | ss << "(" << x << ", " << y << ", " << z << ")"; 35 | return ss.str(); 36 | } 37 | 38 | void Vector3f::serialize(serine::Archiver &ar) { 39 | ar("x", x); 40 | ar("y", y); 41 | ar("z", z); 42 | } 43 | 44 | /* Operator overloads */ 45 | bool Vector3f::fuzzyEqual(const Vector3f &v, float threshold) const { 46 | return (x > v.x - threshold and x < v.x + threshold) and 47 | (y > v.y - threshold and y < v.y + threshold) and 48 | (z > v.z - threshold and z < v.z + threshold); 49 | } 50 | 51 | /* Bullet interop */ 52 | 53 | Vector3f::Vector3f(const btVector3 &v) : 54 | Vector3f(v.x(), v.y(), v.z()) { 55 | } 56 | 57 | Vector3f::operator btVector3() const { 58 | return btVector3(x, y, z); 59 | } 60 | 61 | Vector3f& Vector3f::operator=(const btVector3 &v) { 62 | x = v.x(); y = v.y(); z = v.z(); 63 | return *this; 64 | } 65 | 66 | /* Utility functions */ 67 | Vector3f cross(const Vector3f& v1, const Vector3f& v2) { 68 | Vector3f v; 69 | v.x = v1.y * v2.z - v1.z * v2.y; 70 | v.y = v2.x * v1.z - v2.z * v1.x; 71 | v.z = v1.x * v2.y - v1.y * v2.x; 72 | return v; 73 | } 74 | 75 | } /* namespace radix */ 76 | -------------------------------------------------------------------------------- /source/env/GameConsole.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace radix { 8 | 9 | void GameConsole::run(BaseGame &game) { 10 | const auto path = "history.txt"; 11 | 12 | // Enable the multi-line mode 13 | linenoise::SetMultiLine(true); 14 | 15 | // Set max length of the history 16 | linenoise::SetHistoryMaxLen(4); 17 | 18 | linenoise::SetCompletionCallback([](const char* editBuffer, std::vector& completions) { 19 | if (editBuffer[0] == 'h') { 20 | completions.push_back("help"); 21 | } 22 | 23 | if (editBuffer[0] == 'r') { 24 | completions.push_back("run"); 25 | } 26 | 27 | if (editBuffer[0] == 'e') { 28 | completions.push_back("exit"); 29 | completions.push_back("echo"); 30 | } 31 | 32 | if (editBuffer[0] == 'q') { 33 | completions.push_back("quit"); 34 | } 35 | }); 36 | 37 | // Load history 38 | linenoise::LoadHistory(path); 39 | 40 | while (true) { 41 | std::string line; 42 | 43 | auto quit = linenoise::Readline("command > ", line); 44 | 45 | if (quit) { 46 | break; 47 | } 48 | 49 | if (line == "help") { 50 | std::cout << "Valid commands:" << std::endl; 51 | std::cout << "quit, run, exit, help" << std::endl; 52 | } 53 | 54 | if (line == "quit") { 55 | std::cout << "Closing console" << std::endl; 56 | break; 57 | } 58 | 59 | if (line == "run") { 60 | std::cout << "Starting game" << std::endl; 61 | break; 62 | } 63 | 64 | if (line == "exit") { 65 | std::cout << "Exiting game" << std::endl; 66 | exit(0); 67 | } 68 | 69 | if (line == "echo") { 70 | std::cout << line << std::endl; 71 | } 72 | 73 | // Add line to history 74 | linenoise::AddHistory(line.c_str()); 75 | 76 | // Save history 77 | linenoise::SaveHistory(path); 78 | } 79 | } 80 | 81 | } /* namespace radix */ 82 | -------------------------------------------------------------------------------- /include/radix/util/Hash.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_UTIL_HASH_HPP 2 | #define RADIX_UTIL_HASH_HPP 3 | 4 | #include 5 | 6 | namespace radix { 7 | 8 | namespace impl { 9 | 10 | // MurmurHash2, by Austin Appleby, https://sites.google.com/site/murmurhash/ 11 | #if 0 12 | constexpr unsigned int MurmurHash2(const void *key, int len, unsigned int seed) { 13 | static_assert(sizeof(int) == 4, "int type isn't 4 bytes long"); 14 | const unsigned int m = 0x5bd1e995; 15 | const int r = 24; 16 | unsigned int h = seed ^ len; 17 | const unsigned char *data = (const unsigned char*)key; 18 | while (len >= 4) { 19 | unsigned int k = *(unsigned int *)data; 20 | k *= m; 21 | k ^= k >> r; 22 | k *= m; 23 | h *= m; 24 | h ^= k; 25 | data += 4; 26 | len -= 4; 27 | } 28 | switch (len) { 29 | case 3: h ^= data[2] << 16; 30 | case 2: h ^= data[1] << 8; 31 | case 1: h ^= data[0]; 32 | h *= m; 33 | }; 34 | h ^= h >> 13; 35 | h *= m; 36 | h ^= h >> 15; 37 | return h; 38 | } 39 | #endif 40 | constexpr unsigned int MurmurHashNeutral2(const char *key, int len, unsigned int seed) { 41 | static_assert(sizeof(int) == 4, "int type isn't 4 bytes long"); 42 | const unsigned int m = 0x5bd1e995; 43 | const int r = 24; 44 | unsigned int h = seed ^ len; 45 | const char *data = key; 46 | while (len >= 4) { 47 | unsigned int k = data[0]; 48 | k |= data[1] << 8; 49 | k |= data[2] << 16; 50 | k |= data[3] << 24; 51 | k *= m; 52 | k ^= k >> r; 53 | k *= m; 54 | h *= m; 55 | h ^= k; 56 | data += 4; 57 | len -= 4; 58 | } 59 | switch (len) { 60 | case 3: h ^= data[2] << 16; 61 | case 2: h ^= data[1] << 8; 62 | case 1: h ^= data[0]; 63 | h *= m; 64 | }; 65 | h ^= h >> 13; 66 | h *= m; 67 | h ^= h >> 15; 68 | return h; 69 | } 70 | 71 | } 72 | 73 | /*constexpr uint32_t Hash32(const void *key, int len) { 74 | return impl::MurmurHashNeutral2(key, len, 0); 75 | }*/ 76 | 77 | constexpr int conststrlen(const char *str) { 78 | return *str ? 1 + conststrlen(str + 1) : 0; 79 | } 80 | 81 | constexpr uint32_t Hash32(const char *str) { 82 | return impl::MurmurHashNeutral2(str, conststrlen(str), 0); 83 | } 84 | 85 | } /* namespace radix */ 86 | 87 | #endif /* RADIX_UTIL_HASH_HPP */ 88 | -------------------------------------------------------------------------------- /include/radix/data/texture/TextureLoader.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_TEXTURELOADER_HPP 2 | #define RADIX_TEXTURELOADER_HPP 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | namespace radix { 10 | 11 | class TextureLoader { 12 | using CachedTexture = std::map; 13 | public: 14 | enum class PixelFormat : uint8_t { 15 | RGB8, 16 | BGR8, 17 | RGBA8, 18 | BGRA8 19 | }; 20 | 21 | /** 22 | * @brief getEmptyTexture get Empty texture 23 | * @param name Texture name for caching 24 | * @param pixel pointer to image 25 | * @return return Empty Texture 26 | */ 27 | static Texture getEmptyTexture(const std::string &name, 28 | const char *pixel = "\xFF\xFF\xFF"); 29 | 30 | /** 31 | * @brief getEmptyDiffuse get Empty Diffuse Texture 32 | * @return 33 | */ 34 | static Texture getEmptyDiffuse(); 35 | 36 | /** 37 | * @brief getEmptyNormal get Empty Normal Texture 38 | * @return 39 | */ 40 | static Texture getEmptyNormal(); 41 | 42 | /** 43 | * @brief getEmptySpecular get Empty Specular Texture 44 | * @return 45 | */ 46 | static Texture getEmptySpecular(); 47 | 48 | /** 49 | * @brief getTexture get Texture from image 50 | * @param path path to image 51 | * @return Texture object uploaded to GPU 52 | */ 53 | static Texture getTexture(const std::string &path); 54 | 55 | /** 56 | * @brief getTextureCache Get refrence to cached Texture 57 | * @return get Texture map 58 | */ 59 | static CachedTexture &getTextureCache() { 60 | return textureCache; 61 | } 62 | 63 | private: 64 | /** 65 | * @brief uploadTexture Upload texture from CPU to GPU memory. 66 | * @param data Pointer to CPU Texture. 67 | * @param width Texture width. 68 | * @param height Texture height. 69 | * @return get Texture Object 70 | */ 71 | static Texture uploadTexture(const unsigned char *data, PixelFormat, 72 | unsigned int width, unsigned int height); 73 | 74 | static CachedTexture textureCache; /**< Cached Texture Object*/ 75 | }; 76 | 77 | } /* namespace radix */ 78 | 79 | #endif /* RADIX_TEXTURELOADER_HPP */ 80 | -------------------------------------------------------------------------------- /include/radix/core/gl/VBO.hpp: -------------------------------------------------------------------------------- 1 | #ifndef VBO_HPP 2 | #define VBO_HPP 3 | 4 | #include 5 | #include 6 | 7 | namespace radix { 8 | 9 | class VBO { 10 | protected: 11 | std::size_t size; 12 | unsigned int id; 13 | 14 | public: 15 | enum Usage : uint8_t { 16 | Static = 0b0001, 17 | Dynamic = 0b0010, 18 | Stream = 0b0011, 19 | 20 | Draw = 0b0100, 21 | Read = 0b1000, 22 | Copy = 0b1100 23 | }; 24 | constexpr static Usage DefaultUsage = static_cast(Static | Draw); 25 | 26 | // Ctor / dtor 27 | VBO(); 28 | VBO(std::size_t size, Usage usage = DefaultUsage); 29 | ~VBO(); 30 | // No copy 31 | VBO(const VBO&) = delete; 32 | VBO& operator=(const VBO&) = delete; 33 | // Move 34 | VBO(VBO&&); 35 | VBO& operator=(VBO&&); 36 | 37 | operator unsigned int() const { return id; } 38 | void setSize(std::size_t size, Usage usage = DefaultUsage); 39 | std::size_t getSize() const { 40 | return size; 41 | } 42 | 43 | void setData(const void *data, std::size_t count, Usage usage = DefaultUsage); 44 | 45 | template 46 | void setData(const std::vector &data, Usage usage = DefaultUsage) { 47 | setData(reinterpret_cast(data.data()), data.size()*sizeof(T), usage); 48 | } 49 | template 50 | void setData(const T *data, std::size_t count, Usage usage = DefaultUsage) { 51 | setData(reinterpret_cast(data), count*sizeof(T), usage); 52 | } 53 | 54 | void update(const void *data, std::size_t count = 0, std::size_t offset = 0); 55 | 56 | template 57 | void update(const std::vector &data, std::size_t count = 0, std::size_t offset = 0) { 58 | if (count == 0) { 59 | count = data.size(); 60 | } 61 | update(reinterpret_cast(data.data()), count*sizeof(T), offset); 62 | } 63 | template 64 | void update(const T *data, std::size_t count, std::size_t offset = 0) { 65 | update(reinterpret_cast(data), count*sizeof(T), offset); 66 | } 67 | void bind() const; 68 | }; 69 | 70 | constexpr inline VBO::Usage operator|(const VBO::Usage a, const VBO::Usage b) { 71 | return static_cast(static_cast(a) | static_cast(b)); 72 | } 73 | 74 | } /* namespace radix */ 75 | 76 | #endif /* VBO_HPP */ 77 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: required 2 | 3 | language: cpp 4 | 5 | matrix: 6 | include: 7 | - os: linux 8 | services: docker 9 | before_install: 10 | - docker pull glportal/whale-gcc:coverall 11 | script: 12 | - docker run -it --rm -w /data -v $(pwd):/data glportal/whale-gcc:coverall bash -c "cmake -DCOVERAGE:BOOL=ON ./&& make && make tests&& ctest&& coveralls --dryrun -i include -i source -e tests --gcov-options \'-lp\' && cmake -DCOVERAGE:BOOL=ON ./&& make tests&& ctest&& coveralls -i include -i source -e tests --gcov-options \'-lp\' > /dev/null;" 13 | - os: osx 14 | osx_image: xcode8.3 15 | compiler: gcc 16 | git: 17 | submodules: false 18 | before_install: 19 | - brew update 20 | install: 21 | - brew install assimp 22 | - brew install libepoxy 23 | - brew install sdl2 24 | - brew install sdl2_mixer 25 | - brew install bullet 26 | - brew install tinyxml2 27 | - brew install unittest-cpp 28 | - brew install freeimage 29 | before_script: 30 | - git submodule update --init --recursive 31 | - mkdir build && cd build 32 | script: 33 | - cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$PWD/install .. 34 | - make -j4 35 | - os: osx 36 | osx_image: xcode8.3 37 | compiler: clang 38 | git: 39 | submodules: false 40 | before_install: 41 | - brew update 42 | install: 43 | - brew install assimp 44 | - brew install libepoxy 45 | - brew install sdl2 46 | - brew install sdl2_mixer 47 | - brew install bullet 48 | - brew install tinyxml2 49 | - brew install unittest-cpp 50 | - brew install freeimage 51 | before_script: 52 | - git submodule update --init --recursive 53 | - mkdir build && cd build 54 | script: 55 | - set -e 56 | - cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$PWD/install .. 57 | - make -j4 58 | 59 | notifications: 60 | irc: "chat.freenode.net#glportal" 61 | slack: glportal:6owD9V6VXhGmM7yyEd2hIZue 62 | webhooks: 63 | urls: 64 | - https://webhooks.gitter.im/e/ea210c016747790b4fa4 65 | on_success: always 66 | on_failure: always 67 | on_start: never 68 | -------------------------------------------------------------------------------- /source/data/text/FontLoader.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | namespace radix { 11 | 12 | std::map FontLoader::fontCache = {}; 13 | 14 | Font& FontLoader::getFont(const std::string &name) { 15 | auto it = fontCache.find(name); 16 | if (it != fontCache.end()) { 17 | return it->second; 18 | } 19 | std::string path = LegacyEnvironment::getDataDir() + "/fonts/" + name + ".txt"; 20 | Font font = loadFont(path, name); 21 | auto inserted = fontCache.insert(std::pair(name, font)); 22 | // Return reference to newly inserted Font 23 | return inserted.first->second; 24 | } 25 | 26 | Font FontLoader::loadFont(const std::string &path, const std::string &name) { 27 | Font font; 28 | std::ifstream input(path); 29 | for (std::string line; getline(input, line);) { 30 | std::stringstream stream(line); 31 | 32 | if (line.length() > 0) { 33 | std::string tokens[9]; 34 | 35 | for (int i = 0; i < 9; i++) { 36 | stream >> tokens[i]; 37 | } 38 | 39 | if (tokens[0] == "char") { 40 | //Delete all the letters from the tokens 41 | for (int i = 1; i < 9; ++i) { 42 | //Find the start of the digits 43 | int pos = tokens[i].find('=', 0) + 1; 44 | //Erase the rest 45 | tokens[i].erase(0, pos); 46 | } 47 | 48 | Glyph letter; 49 | int id = std::stoi(tokens[1]); 50 | letter.x = std::stoi(tokens[2]); 51 | letter.y = std::stoi(tokens[3]); 52 | letter.width = std::stoi(tokens[4]); 53 | letter.height = std::stoi(tokens[5]); 54 | letter.xOffset = std::stof(tokens[6]); 55 | letter.yOffset = std::stof(tokens[7]); 56 | letter.advance = std::stof(tokens[8]); 57 | 58 | //Load the mesh 59 | Texture texture = TextureLoader::getTexture(name + ".png"); 60 | letter.mesh = MeshLoader::getSubPlane(letter.x, letter.y, letter.width, letter.height, 61 | texture.width, texture.height); 62 | 63 | font.letters.insert(std::pair(id, letter)); 64 | } 65 | } 66 | } 67 | 68 | return font; 69 | } 70 | 71 | } /* namespace radix */ 72 | -------------------------------------------------------------------------------- /tests/XmlHelperTest.cpp: -------------------------------------------------------------------------------- 1 | #ifndef CATCH_CONFIG_MAIN 2 | #define CATCH_CONFIG_MAIN 3 | #endif 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | using namespace radix; 11 | using namespace std; 12 | 13 | struct XmlHelperFixtures 14 | { 15 | Vector3f sourceVector; 16 | Vector3f vector; 17 | tinyxml2::XMLDocument doc; 18 | tinyxml2::XMLElement * lightElement; 19 | tinyxml2::XMLElement * testElement; 20 | 21 | XmlHelperFixtures() { 22 | doc.NewDeclaration("1.0"); 23 | lightElement = doc.NewElement("light"); 24 | sourceVector = Vector3f(155, 266, 377); 25 | lightElement->SetAttribute("x", sourceVector.x); 26 | lightElement->SetAttribute("y", sourceVector.y); 27 | lightElement->SetAttribute("z", sourceVector.z); 28 | 29 | testElement = doc.NewElement("test"); 30 | testElement->SetAttribute("key", "value"); 31 | testElement->SetAttribute("emptyKey", ""); 32 | 33 | } 34 | 35 | ~XmlHelperFixtures() {} 36 | 37 | }; 38 | 39 | TEST_CASE_METHOD(XmlHelperFixtures, "Data can be extracted from xml", "[xml-helper]") { 40 | SECTION("Extracted vectors are valid") { 41 | XmlHelper::pushAttributeVertexToVector(lightElement, vector); 42 | 43 | bool vectorIsValid(false); 44 | Vector3f resultVector = sourceVector - vector; 45 | if((resultVector.x + resultVector.y + resultVector.z) == 0 ){ 46 | vectorIsValid = true; 47 | } 48 | REQUIRE(vectorIsValid); 49 | } 50 | 51 | SECTION("Extracting missing attribute throws error") { 52 | lightElement->DeleteAttribute("z"); 53 | REQUIRE_THROWS_AS(XmlHelper::pushAttributeVertexToVector(lightElement, vector), runtime_error); 54 | } 55 | } 56 | 57 | TEST_CASE_METHOD(XmlHelperFixtures, "String attributes can be extracted from xml", "[xml-string-attribute]") { 58 | SECTION("Non mandatory string can be extracted") { 59 | 60 | REQUIRE(XmlHelper::extractStringAttribute(testElement, "key") == "value"); 61 | } 62 | 63 | SECTION("Mandatory string can be extracted") { 64 | 65 | REQUIRE(XmlHelper::extractStringMandatoryAttribute(testElement, "key") == "value"); 66 | } 67 | 68 | SECTION("Error is thrown when Mandatory string does not exist") { 69 | 70 | REQUIRE_THROWS_AS(XmlHelper::extractStringMandatoryAttribute(testElement, "non-existant"), runtime_error); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /include/radix/Camera.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_CAMERA_HPP 2 | #define RADIX_CAMERA_HPP 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace radix { 10 | 11 | class Camera { 12 | public: 13 | static constexpr const float DEFAULT_FOVY = rad(60); 14 | static constexpr const float DEFAULT_ASPECT = 1; 15 | static constexpr const float DEFAULT_ZNEAR = 0.1f; 16 | static constexpr const float DEFAULT_ZFAR = 100; 17 | static constexpr const bool DEFAULT_PERSPECTIVE = true; 18 | static constexpr const float DEFAULT_TOP = 0.5f; 19 | static constexpr const float DEFAULT_BOTTOM = -0.5f; 20 | static constexpr const float DEFAULT_LEFT = -0.5f; 21 | static constexpr const float DEFAULT_RIGHT = 0.5f; 22 | 23 | Camera() = default; 24 | Camera(const float fovy, const float aspect, const float zNear, const float zFar); 25 | 26 | void getProjMatrix(Matrix4f &m) const; 27 | void setProjMatrix(const Matrix4f &m); 28 | void getViewMatrix(Matrix4f &m) const; 29 | void setViewMatrix(const Matrix4f &m); 30 | void getInvViewMatrix(Matrix4f &m) const; 31 | 32 | void setFovy(const float fovy); 33 | float getFovy() const; 34 | void setAspect(const float aspect); 35 | float getAspect() const; 36 | void setZNear(const float zNear); 37 | float getZNear() const; 38 | void setZFar(const float zFar); 39 | float getZFar() const; 40 | void setPerspective(); 41 | void setOrthographic(); 42 | void setBounds(const float left, const float right, const float bottom, const float top); 43 | 44 | Vector3f getPosition() const; 45 | void setPosition(const Vector3f&); 46 | Quaternion getOrientation() const; 47 | void setOrientation(const Quaternion&); 48 | 49 | private: 50 | Vector3f position; 51 | Quaternion orientation; 52 | 53 | void calcProj(); 54 | void calcView(); 55 | Matrix4f projMatrix; 56 | Matrix4f viewMatrix; 57 | Matrix4f invViewMatrix; 58 | 59 | bool perspective = DEFAULT_PERSPECTIVE; 60 | float fovy = DEFAULT_FOVY; 61 | float aspect = DEFAULT_ASPECT; 62 | float zNear = DEFAULT_ZNEAR; 63 | float zFar = DEFAULT_ZFAR; 64 | 65 | float top = DEFAULT_TOP; 66 | float bottom = DEFAULT_BOTTOM; 67 | float left = DEFAULT_LEFT; 68 | float right = DEFAULT_RIGHT; 69 | }; 70 | 71 | } /* namespace radix */ 72 | 73 | #endif /* RADIX_CAMERA_HPP */ 74 | -------------------------------------------------------------------------------- /source/entities/traits/RigidBodyTrait.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | 6 | static const char *Tag = "RigidBodyTrait"; 7 | 8 | namespace radix { 9 | namespace entities { 10 | 11 | RigidBodyTrait::RigidBodyTrait() : 12 | m_btPtrInfo(this, this), 13 | body(nullptr) { 14 | } 15 | 16 | int RigidBodyTrait::getCollisionFlags() const { 17 | return 0; 18 | } 19 | 20 | int RigidBodyTrait::getCollisionGroup() const { 21 | return 0; 22 | } 23 | 24 | int RigidBodyTrait::getCollisionMask() const { 25 | return 0; 26 | } 27 | 28 | void RigidBodyTrait::setRigidBody(float mass, 29 | const std::shared_ptr &collisionshape) { 30 | shape = collisionshape; 31 | motionState.setWorldTransform(*this); 32 | btVector3 localInertia; 33 | collisionshape->calculateLocalInertia(mass, localInertia); 34 | btRigidBody::btRigidBodyConstructionInfo ci(mass, &motionState, shape.get(), localInertia); 35 | body = new btRigidBody(ci); 36 | body->setCollisionFlags(getCollisionFlags() | btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK); 37 | body->setUserPointer(&m_btPtrInfo); 38 | body->setUserIndex(id); 39 | 40 | auto &phys = world.simulations.findFirstOfType(); 41 | Util::Log(Verbose, Tag) << "Adding body to phys world (" << id << ')'; 42 | phys.getPhysicsWorld().addRigidBody(body, getCollisionGroup(), getCollisionMask()); 43 | } 44 | 45 | void RigidBodyTrait::onRemoveTrait() { 46 | if (body) { 47 | auto &phys = world.simulations.findFirstOfType(); 48 | Util::Log(Verbose, Tag) << "Removing body from phys world (" << id << ')'; 49 | phys.getPhysicsWorld().removeRigidBody(body); 50 | } 51 | } 52 | 53 | RigidBodyTrait::~RigidBodyTrait() { 54 | delete body; 55 | } 56 | 57 | void RigidBodyTrait::setPosition(const Vector3f &val) { 58 | position = val; 59 | if (body) { 60 | btTransform t = body->getWorldTransform(); 61 | t.setOrigin(val); 62 | body->setWorldTransform(t); 63 | } 64 | } 65 | 66 | void RigidBodyTrait::setScale(const Vector3f &val) { 67 | scale = val; 68 | } 69 | 70 | void RigidBodyTrait::setOrientation(const Quaternion &val) { 71 | orientation = val; 72 | if (body) { 73 | btTransform t = body->getWorldTransform(); 74 | t.setRotation(val); 75 | body->setWorldTransform(t); 76 | } 77 | } 78 | 79 | } /* namespace entities */ 80 | } /* namespace radix */ 81 | -------------------------------------------------------------------------------- /include/radix/World.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_WORLD_HPP 2 | #define RADIX_WORLD_HPP 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | namespace radix { 20 | 21 | namespace entities { 22 | class Player; 23 | } 24 | class BaseGame; 25 | class InputSource; 26 | class Config; 27 | 28 | typedef std::pair EntityPair; 29 | 30 | class World { 31 | private: 32 | Config *config; 33 | double gameTime; 34 | uint32_t lastUpdateTime; 35 | 36 | protected: 37 | entities::Player *player; 38 | 39 | public: 40 | BaseGame &game; 41 | InputSource *input; 42 | 43 | World(BaseGame&); 44 | ~World(); 45 | 46 | void setConfig(radix::Config &config); 47 | radix::Config& getConfig(); 48 | void initPlayer(); 49 | 50 | inline double getTime() const { 51 | return gameTime; 52 | } 53 | 54 | void onCreate(); 55 | void onStart(); 56 | void update(TDelta dtime); 57 | void onStop(); 58 | void onDestroy(); 59 | 60 | entities::Player& getPlayer(); 61 | std::map materials; 62 | EventDispatcher event; 63 | SimulationManager simulations; 64 | EntityManager entityManager; 65 | std::unique_ptr camera; 66 | 67 | // Convenience 68 | std::map entityAliases; 69 | std::map> entityGroups; 70 | std::map> entityPairs; 71 | std::map destinations; 72 | 73 | // Game States 74 | std::stack stateFunctionStack; 75 | 76 | /** 77 | * Gets the reference to the entity with specified ID. 78 | * @throws std::out_of_range if no entity with this ID is found. 79 | */ 80 | inline Entity& getEntityById(EntityId id) { 81 | return entityManager.getById(id); 82 | } 83 | 84 | /** 85 | * Gets the reference to the entity with specified name. 86 | * @throws std::out_of_range if no entity with this name is found. 87 | */ 88 | inline Entity& getEntityByName(const std::string &name) { 89 | return entityManager.getByName(name); 90 | } 91 | }; 92 | 93 | } /* namespace glPortal */ 94 | 95 | #endif /* RADIX_WORLD_HPP */ 96 | -------------------------------------------------------------------------------- /include/radix/core/diag/LogInput.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_LOGINPUT_HPP 2 | #define RADIX_LOGINPUT_HPP 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | namespace radix { 15 | 16 | /** \class LogInput 17 | * @brief `std::cout`-like object that sends the data it aggregated to a Logger when it dies 18 | */ 19 | class LogInput { 20 | protected: 21 | Logger &sink; 22 | LogLevel lvl; 23 | std::string buf, tag; 24 | 25 | template 26 | inline LogInput& appendNumber(N number) { 27 | buf.append(std::to_string(number)); 28 | return *this; 29 | } 30 | 31 | public: 32 | LogInput(Logger &sink, LogLevel lvl, const char *tag = ""); 33 | LogInput(Logger &sink, LogLevel lvl, const std::string &tag); 34 | ~LogInput(); 35 | 36 | LogInput(const LogInput&) = delete; 37 | LogInput& operator=(const LogInput&) = delete; 38 | 39 | LogInput(LogInput&&); 40 | LogInput& operator=(LogInput&&) = delete; 41 | 42 | LogInput& operator<<(const char*); 43 | LogInput& operator<<(const std::string&); 44 | LogInput& operator<<(const stx::string_view&); 45 | 46 | LogInput& operator<<(bool); 47 | LogInput& operator<<(char); 48 | 49 | // std::to_string overloads 50 | LogInput& operator<<(int v) { return appendNumber(v); } 51 | LogInput& operator<<(long v) { return appendNumber(v); } 52 | LogInput& operator<<(long long v) { return appendNumber(v); } 53 | LogInput& operator<<(unsigned v) { return appendNumber(v); } 54 | LogInput& operator<<(unsigned long v) { return appendNumber(v); } 55 | LogInput& operator<<(unsigned long long v) { return appendNumber(v); } 56 | LogInput& operator<<(float v) { return appendNumber(v); } 57 | LogInput& operator<<(double v) { return appendNumber(v); } 58 | LogInput& operator<<(long double v) { return appendNumber(v); } 59 | 60 | // std::to_string-compatible upcasts 61 | LogInput& operator<<(unsigned char v) { return appendNumber(v); } 62 | LogInput& operator<<(short v) { return appendNumber(v); } 63 | LogInput& operator<<(unsigned short v) { return appendNumber(v); } 64 | 65 | LogInput& operator<<(const void*); 66 | 67 | LogInput& operator<<(const Vector2f&); 68 | LogInput& operator<<(const Vector3f&); 69 | LogInput& operator<<(const Vector4f&); 70 | }; 71 | 72 | } /* namespace radix */ 73 | 74 | #endif /* RADIX_LOGINPUT_HPP */ 75 | -------------------------------------------------------------------------------- /source/api/ScriptEngine.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | namespace radix { 12 | 13 | void MessageCallback(const asSMessageInfo *message, void *parameter) { 14 | LogLevel level; 15 | switch (message->type) { 16 | case asMSGTYPE_INFORMATION: level = LogLevel::Info; break; 17 | case asMSGTYPE_WARNING: level = LogLevel::Warning; break; 18 | case asMSGTYPE_ERROR: level = LogLevel::Error; break; 19 | } 20 | Util::Log(level, "AngelScript") << message->section << " (" << message->row << ", " << message->col << "): " 21 | << message->message; 22 | } 23 | 24 | ScriptEngine::ScriptEngine(World &world): world(world), playerApi(world), radixApi(world) { 25 | angelScript = asCreateScriptEngine(); 26 | if (angelScript == nullptr) { 27 | throw std::runtime_error("Failed to create AngelScript engine"); 28 | } 29 | angelScript->SetMessageCallback(asFUNCTION(MessageCallback), nullptr, asCALL_CDECL); 30 | RegisterStdString(angelScript); 31 | RegisterScriptHandle(angelScript); 32 | RegisterScriptWeakRef(angelScript); 33 | 34 | playerApi.registerFunctions(angelScript); 35 | radixApi.registerFunctions(angelScript); 36 | } 37 | 38 | ScriptEngine::~ScriptEngine() { 39 | angelScript->ShutDownAndRelease(); 40 | } 41 | 42 | void ScriptEngine::runCode(const std::string &code) { 43 | std::string actualcode = "void main() {\n" + code + "\n}"; 44 | asIScriptModule *module = angelScript->GetModule(0, asGM_ALWAYS_CREATE); 45 | int result = module->AddScriptSection("script", &actualcode[0], actualcode.size()); 46 | if (result < 0) { 47 | throw std::runtime_error("AddScriptSection() failed"); 48 | } 49 | result = module->Build(); 50 | if (result < 0) { 51 | throw std::runtime_error("Build() failed"); 52 | } 53 | asIScriptContext *context = angelScript->CreateContext(); 54 | if (context == nullptr) { 55 | throw std::runtime_error("Failed to create AngelScript context"); 56 | } 57 | asIScriptFunction *function = angelScript->GetModule(0)->GetFunctionByDecl("void main()"); 58 | if (function == nullptr) { 59 | throw std::runtime_error("No main() function"); 60 | } 61 | result = context->Prepare(function); 62 | if (result < 0) { 63 | throw std::runtime_error("Failed to prepare context"); 64 | } 65 | result = context->Execute(); 66 | context->Release(); 67 | } 68 | 69 | } /* namespace radix */ 70 | 71 | -------------------------------------------------------------------------------- /include/radix/core/gl/Framebuffer.hpp: -------------------------------------------------------------------------------- 1 | #ifndef FRAME_BUFFER_HPP 2 | #define FRAME_BUFFER_HPP 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace radix { 9 | enum FramebufferType { 10 | Texture = 1, 11 | Depth = 2, 12 | Stencil = 4 13 | }; 14 | 15 | struct FrameBuffer { 16 | ~FrameBuffer(); 17 | 18 | /** 19 | * @brief create uchar RGB texture 20 | * with Nearest filter and clamp to edge 21 | * 22 | * @param width texture width level 0 23 | * @param height texture height level 0 24 | * 25 | * @return OpenGL texture handler 26 | */ 27 | static GLuint createTexture(const int width, const int height); 28 | 29 | /** 30 | * @brief create renderbuffer 31 | * 32 | * @param width buffer width 33 | * @param height buffer height 34 | * @param type buffer type ex. GL_RGB 35 | * 36 | * @return OpenGL renderbuffer handler 37 | */ 38 | static GLuint createRenderBuffer(const int width, const int height, 39 | GLenum type); 40 | 41 | /** 42 | * @brief create Framebuffer and attachments 43 | * 44 | * @param viewportWidth Framebuffer width 45 | * @param viewportHeight Framebuffer height 46 | * @param types types of attachments 47 | */ 48 | void create(const int viewportWidth, const int viewportHeight, 49 | const FramebufferType types); 50 | 51 | /** 52 | * @brief bind framebuffer 53 | */ 54 | inline void bind() { 55 | glBindFramebuffer(GL_FRAMEBUFFER, frameBuffer); 56 | } 57 | 58 | /** 59 | * @brief unbind framebuffer 60 | */ 61 | inline static void unbind() { 62 | glBindFramebuffer(GL_FRAMEBUFFER, 0); 63 | } 64 | 65 | /** 66 | * @brief bind color Texture 67 | */ 68 | inline void bindTexture() { 69 | if(colorTexture != 0) { 70 | glBindTexture(GL_TEXTURE_2D, colorTexture); 71 | } 72 | } 73 | 74 | /** 75 | * @brief unbind color Texture 76 | */ 77 | inline static void unbindTexture() { 78 | glBindTexture(GL_TEXTURE_2D, 0); 79 | } 80 | 81 | /** 82 | * @brief Save all attachment to hard 83 | * 84 | * @param dir location to save images 85 | */ 86 | void save(std::string&& dir); 87 | 88 | protected: 89 | int width = 0; 90 | int height = 0; 91 | GLuint frameBuffer = 0; 92 | GLuint colorTexture = 0; 93 | GLuint depthTexture = 0; 94 | }; 95 | } 96 | #endif //!FRAME_BUFFER_HPP 97 | -------------------------------------------------------------------------------- /include/radix/renderer/RenderContext.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RADIX_RENDER_CONTEXT_HPP 2 | #define RADIX_RENDER_CONTEXT_HPP 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | namespace radix { 10 | 11 | class Renderer; 12 | class Mesh; 13 | class Transform; 14 | 15 | struct RenderContext { 16 | Renderer &renderer; 17 | RenderContext(Renderer &r) : renderer(r) {} 18 | 19 | std::vector projStack; 20 | bool projDirty; 21 | inline Matrix4f& getProj() { 22 | return projStack.back(); 23 | } 24 | inline const Matrix4f& getProj() const { 25 | return projStack.back(); 26 | } 27 | inline void pushProj(const Matrix4f &m) { 28 | projStack.push_back(m); 29 | projDirty = true; 30 | } 31 | inline void popProj() { 32 | projStack.pop_back(); 33 | projDirty = true; 34 | } 35 | 36 | std::vector viewStack, invViewStack; 37 | bool viewDirty; 38 | size_t viewStackMaxDepth; 39 | inline Matrix4f& getView() { 40 | return viewStack.back(); 41 | } 42 | inline const Matrix4f& getView() const { 43 | return viewStack.back(); 44 | } 45 | inline Matrix4f& getInvView() { 46 | return invViewStack.back(); 47 | } 48 | inline const Matrix4f& getInvView() const { 49 | return invViewStack.back(); 50 | } 51 | inline void pushView(const Matrix4f &m) { 52 | viewStack.push_back(m); 53 | invViewStack.push_back(inverse(m)); 54 | viewDirty = true; 55 | } 56 | inline void popView() { 57 | viewStack.pop_back(); 58 | invViewStack.pop_back(); 59 | viewDirty = true; 60 | } 61 | 62 | inline void pushCamera(const Camera &c) { 63 | projStack.push_back(Matrix4f::Identity); 64 | c.getProjMatrix(projStack.back()); 65 | viewStack.push_back(Matrix4f::Identity); 66 | c.getViewMatrix(viewStack.back()); 67 | invViewStack.push_back(Matrix4f::Identity); 68 | c.getInvViewMatrix(invViewStack.back()); 69 | projDirty = viewDirty = true; 70 | } 71 | inline void popCamera() { 72 | projStack.pop_back(); 73 | viewStack.pop_back(); 74 | invViewStack.pop_back(); 75 | projDirty = viewDirty = true; 76 | } 77 | 78 | using ViewFrameInfo = std::pair; 79 | std::vector viewFramesStack; 80 | inline const ViewFrameInfo getViewFrame() const { 81 | return viewFramesStack.back(); 82 | } 83 | inline void pushViewFrame(const ViewFrameInfo &frame) { 84 | viewFramesStack.push_back(frame); 85 | } 86 | inline void popViewFrame() { 87 | viewFramesStack.pop_back(); 88 | } 89 | }; 90 | 91 | } /* namespace radix */ 92 | 93 | #endif /* RADIX_RENDER_CONTEXT_HPP */ 94 | -------------------------------------------------------------------------------- /source/env/Util.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #ifdef _WIN32 11 | #include 12 | const DWORD MS_VC_EXCEPTION=0x406D1388; 13 | #pragma pack(push,8) 14 | typedef struct tagTHREADNAME_INFO 15 | { 16 | DWORD dwType; // Must be 0x1000. 17 | LPCSTR szName; // Pointer to name (in user addr space). 18 | DWORD dwThreadID; // Thread ID (-1=caller thread). 19 | DWORD dwFlags; // Reserved for future use, must be zero. 20 | } THREADNAME_INFO; 21 | #pragma pack(pop) 22 | #elif __APPLE__ 23 | #include // std::strlen 24 | #include 25 | #elif __linux__ 26 | #include // std::strlen 27 | #include // pthread_* 28 | #include 29 | #endif 30 | 31 | namespace radix { 32 | 33 | std::unique_ptr Util::logger; 34 | Util::_Log Util::Log; 35 | 36 | std::random_device Util::RandDev; 37 | std::mt19937 Util::Rand(Util::RandDev()); 38 | 39 | void Util::Init() { 40 | if (OperatingSystem::IsLinux()) { 41 | logger.reset(new AnsiConsoleLogger); 42 | } else { 43 | logger.reset(new StdoutLogger); 44 | } 45 | } 46 | 47 | #ifdef _WIN32 48 | static void WinSetThreadName(uint32_t dwThreadID, const char **threadName) { 49 | THREADNAME_INFO info; 50 | info.dwType = 0x1000; 51 | info.szName = *threadName; 52 | info.dwThreadID = dwThreadID; 53 | info.dwFlags = 0; 54 | __try 55 | { 56 | RaiseException( MS_VC_EXCEPTION, 0, sizeof(info)/sizeof(ULONG_PTR), (ULONG_PTR*)&info ); 57 | } 58 | __except(EXCEPTION_EXECUTE_HANDLER) 59 | { 60 | } 61 | } 62 | 63 | void Util::SetCurrentThreadName(const char *name) { 64 | DWORD threadId = ::GetThreadId((HANDLE)(GetCurrentThreadId())); 65 | WinSetThreadName(threadId, &name); 66 | } 67 | #elif __APPLE__ 68 | void Util::SetCurrentThreadName(const char *name) { 69 | if (std::strlen(name) > 15) { 70 | throw std::length_error("Name exceeds length of 15 characters"); 71 | } 72 | int ret = pthread_setname_np(name); 73 | if (ret != 0) { 74 | throw std::system_error(ret, std::system_category(), 75 | std::string("Setting thread name to \"") + name + '"'); 76 | } 77 | } 78 | #else 79 | void Util::SetCurrentThreadName(const char *name) { 80 | if (std::strlen(name) > 15) { 81 | throw std::length_error("Name exceeds length of 15 characters"); 82 | } 83 | int ret = pthread_setname_np(pthread_self(), name); 84 | if (ret != 0) { 85 | throw std::system_error(ret, std::system_category(), 86 | std::string("Setting thread name to \"") + name + '"'); 87 | } 88 | } 89 | #endif 90 | 91 | } /* namespace radix */ 92 | -------------------------------------------------------------------------------- /source/renderer/ScreenRenderer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | namespace radix { 12 | 13 | ScreenRenderer::ScreenRenderer(World &w, Renderer &ren, GameWorld &gw) : 14 | SubRenderer(w, ren), 15 | gameWorld(gw) { } 16 | 17 | void ScreenRenderer::render() { 18 | for (Screen *screen : *gameWorld.getScreens()) { 19 | renderScreen(screen); 20 | } 21 | } 22 | 23 | void ScreenRenderer::renderScreen(Screen *screen) { 24 | PROFILER_BLOCK("ScreenRenderer::renderScreen", profiler::colors::LightGreen100); 25 | glDepthMask(GL_FALSE); 26 | 27 | renderer.getViewport()->getSize(&viewportWidth, &viewportHeight); 28 | 29 | initCamera(); 30 | 31 | Matrix4f widget; 32 | int xAxisViewportCenter = viewportWidth / 2; 33 | int yAxisViewportCenter = viewportHeight / 2; 34 | widget.translate(Vector3f(xAxisViewportCenter, yAxisViewportCenter, -18)); 35 | widget.scale(Vector3f(viewportWidth, viewportHeight, 1)); 36 | 37 | const Mesh &mesh = MeshLoader::getMesh("GUIElement.obj"); 38 | Shader &shader = ShaderLoader::getShader("color.frag"); 39 | 40 | shader.bind(); 41 | glUniform4f(shader.uni("color"), screen->color.r, screen->color.g, screen->color.b, screen->color.a); 42 | renderer.renderMesh(*renderContext, shader, widget, mesh); 43 | 44 | shader.release(); 45 | 46 | for (unsigned int i = 0; i < screen->text.size(); i++) { 47 | screen->text[i].font = "Pacaya"; 48 | Font font = FontLoader::getFont(screen->text[i].font); 49 | font.size = screen->text[i].size; 50 | int textWidth = font.getStringLength(screen->text[i].content); 51 | Vector3f position(0, 0, screen->text[i].z); 52 | 53 | position.y = viewportHeight - screen->text[i].top; 54 | Text::Align textAlign = screen->text[i].align; 55 | position.x = getHorizontalPositionByAlignment(textAlign, viewportWidth, textWidth); 56 | 57 | screen->text[i].position = position; 58 | 59 | renderer.renderText(*renderContext, screen->text[i]); 60 | } 61 | 62 | glDepthMask(GL_TRUE); 63 | } 64 | 65 | int ScreenRenderer::getHorizontalPositionByAlignment(Text::Align align, int viewportWidth, int textWidth) { 66 | int xAxisViewportCenter = viewportWidth / 2; 67 | if (align == Text::Center) { 68 | return xAxisViewportCenter - (textWidth / 2); 69 | } else if (align == Text::Right) { 70 | return (xAxisViewportCenter + viewportWidth / 4) - (textWidth / 2); 71 | } 72 | 73 | // Default assumes left alignment 74 | return (xAxisViewportCenter - viewportWidth / 4) - (textWidth / 2); 75 | } 76 | 77 | } /* namespace radix */ 78 | -------------------------------------------------------------------------------- /cmake/FindTinyXML2.cmake: -------------------------------------------------------------------------------- 1 | # - Find TinyXML2 2 | # Find the native TinyXML2 includes and library 3 | # 4 | # TINYXML2_FOUND - True if TinyXML found. 5 | # TINYXML2_INCLUDE_DIR - where to find tinyxml.h, etc. 6 | # TINYXML2_LIBRARIES - List of libraries when using TinyXML. 7 | # 8 | 9 | IF( TINYXML2_INCLUDE_DIR ) 10 | # Already in cache, be silent 11 | SET( TinyXML2_FIND_QUIETLY TRUE ) 12 | ENDIF( TINYXML2_INCLUDE_DIR ) 13 | 14 | FIND_PATH( TINYXML2_INCLUDE_DIR "tinyxml2.h" 15 | PATHS /usr/include 16 | PATH_SUFFIXES "tinyxml2" ) 17 | set (TINYXML2_INCLUDE_DIRS ${TINYXML2_INCLUDE_DIR}) 18 | 19 | file(STRINGS "${TINYXML2_INCLUDE_DIR}/tinyxml2.h" TINYXML2_MAJOR_VERSION 20 | LENGTH_MINIMUM 39 LIMIT_COUNT 1 21 | REGEX "static const int TIXML2_MAJOR_VERSION = [0-9]+;") 22 | string(REGEX REPLACE "static const int TIXML2_MAJOR_VERSION = ([0-9]+)\\\\;" 23 | "\\1" TINYXML2_MAJOR_VERSION "${TINYXML2_MAJOR_VERSION}") 24 | file(STRINGS "${TINYXML2_INCLUDE_DIR}/tinyxml2.h" TINYXML2_MINOR_VERSION 25 | LENGTH_MINIMUM 39 LIMIT_COUNT 1 26 | REGEX "static const int TIXML2_MINOR_VERSION = [0-9]+;") 27 | string(REGEX REPLACE "static const int TIXML2_MINOR_VERSION = ([0-9]+)\\\\;" 28 | "\\1" TINYXML2_MINOR_VERSION "${TINYXML2_MINOR_VERSION}") 29 | file(STRINGS "${TINYXML2_INCLUDE_DIR}/tinyxml2.h" TINYXML2_PATCH_VERSION 30 | LENGTH_MINIMUM 39 LIMIT_COUNT 1 31 | REGEX "static const int TIXML2_PATCH_VERSION = [0-9]+;") 32 | string(REGEX REPLACE "static const int TIXML2_PATCH_VERSION = ([0-9]+)\\\\;" 33 | "\\1" TINYXML2_PATCH_VERSION "${TINYXML2_PATCH_VERSION}") 34 | set(TINYXML2_VERSION 35 | "${TINYXML2_MAJOR_VERSION}.${TINYXML2_MINOR_VERSION}.${TINYXML2_PATCH_VERSION}") 36 | math(EXPR TINYXML2_VERSION_CODE 37 | "${TINYXML2_MAJOR_VERSION}*100000+${TINYXML2_MINOR_VERSION}*100+${TINYXML2_PATCH_VERSION}") 38 | 39 | if(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION) 40 | set(PACKAGE_VERSION_COMPATIBLE FALSE) 41 | else() 42 | set(PACKAGE_VERSION_COMPATIBLE TRUE) 43 | if(PACKAGE_FIND_VERSION STREQUAL PACKAGE_VERSION) 44 | set(PACKAGE_VERSION_EXACT TRUE) 45 | endif() 46 | endif() 47 | 48 | FIND_LIBRARY( TINYXML2_LIBRARY 49 | NAMES "tinyxml2" 50 | PATH_SUFFIXES "tinyxml2" ) 51 | set (TINYXML2_LIBRARIES ${TINYXML2_LIBRARY}) 52 | 53 | # handle the QUIETLY and REQUIRED arguments and set TINYXML_FOUND to TRUE if 54 | # all listed variables are TRUE 55 | include("FindPackageHandleStandardArgs") 56 | find_package_handle_standard_args("TinyXML2" 57 | REQUIRED_VARS TINYXML2_LIBRARY TINYXML2_INCLUDE_DIR TINYXML2_VERSION 58 | VERSION_VAR TINYXML2_VERSION) 59 | 60 | MARK_AS_ADVANCED(TINYXML2_LIBRARY TINYXML2_INCLUDE_DIR TINYXML2_INCLUDE_DIRS TINYXML2_LIBRARIES 61 | TINYXML2_VERSION TINYXML2_MAJOR_VERSION TINYXML2_MINOR_VERSION TINYXML2_PATCH_VERSION) 62 | -------------------------------------------------------------------------------- /source/core/gl/VBO.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | namespace radix { 6 | 7 | constexpr static GLenum getGlUsage(const VBO::Usage usage) { 8 | switch (usage & 0b0011) { 9 | case VBO::Static: 10 | switch (usage & 0b1100) { 11 | case VBO::Draw: 12 | return GL_STATIC_DRAW; 13 | case VBO::Read: 14 | return GL_STATIC_READ; 15 | case VBO::Copy: 16 | return GL_STATIC_COPY; 17 | } 18 | break; 19 | case VBO::Dynamic: 20 | switch (usage & 0b1100) { 21 | case VBO::Draw: 22 | return GL_DYNAMIC_DRAW; 23 | case VBO::Read: 24 | return GL_DYNAMIC_READ; 25 | case VBO::Copy: 26 | return GL_DYNAMIC_COPY; 27 | } 28 | break; 29 | case VBO::Stream: 30 | switch (usage & 0b1100) { 31 | case VBO::Draw: 32 | return GL_STREAM_DRAW; 33 | case VBO::Read: 34 | return GL_STREAM_READ; 35 | case VBO::Copy: 36 | return GL_STREAM_COPY; 37 | } 38 | break; 39 | } 40 | return GL_INVALID_ENUM; 41 | // throw std::invalid_argument("Invalid VBO::Usage"); 42 | } 43 | 44 | VBO::VBO() : 45 | size(0) { 46 | glGenBuffers(1, &id); 47 | } 48 | 49 | VBO::VBO(std::size_t size, Usage usage) : 50 | size(0) { 51 | glGenBuffers(1, &id); 52 | setSize(size, usage); 53 | } 54 | 55 | VBO::VBO(VBO &&other) { 56 | glDeleteBuffers(1, &id); 57 | id = other.id; size = other.size; 58 | other.size = other.id = 0; 59 | } 60 | VBO& VBO::operator=(VBO &&other) { 61 | glDeleteBuffers(1, &id); 62 | id = other.id; size = other.size; 63 | other.size = other.id = 0; 64 | return *this; 65 | } 66 | 67 | VBO::~VBO() { 68 | glDeleteBuffers(1, &id); 69 | } 70 | 71 | void VBO::bind() const { 72 | glBindBuffer(GL_ARRAY_BUFFER, id); 73 | } 74 | 75 | void VBO::setSize(std::size_t size, Usage usage) { 76 | GLint currentBoundArray; glGetIntegerv(GL_ARRAY_BUFFER_BINDING, ¤tBoundArray); 77 | glBindBuffer(GL_ARRAY_BUFFER, id); 78 | this->size = size; 79 | glBufferData(GL_ARRAY_BUFFER, size, nullptr, getGlUsage(usage)); 80 | glBindBuffer(GL_ARRAY_BUFFER, currentBoundArray); 81 | } 82 | 83 | void VBO::setData(const void *data, std::size_t count, Usage usage) { 84 | GLint currentBoundArray; glGetIntegerv(GL_ARRAY_BUFFER_BINDING, ¤tBoundArray); 85 | glBindBuffer(GL_ARRAY_BUFFER, id); 86 | this->size = count; 87 | glBufferData(GL_ARRAY_BUFFER, count, data, getGlUsage(usage)); 88 | glBindBuffer(GL_ARRAY_BUFFER, currentBoundArray); 89 | } 90 | 91 | void VBO::update(const void *data, std::size_t count, std::size_t offset) { 92 | GLint currentBoundArray; glGetIntegerv(GL_ARRAY_BUFFER_BINDING, ¤tBoundArray); 93 | glBindBuffer(GL_ARRAY_BUFFER, id); 94 | glBufferSubData(GL_ARRAY_BUFFER, offset, count, data); 95 | glBindBuffer(GL_ARRAY_BUFFER, currentBoundArray); 96 | } 97 | 98 | } /* namespace radix */ 99 | -------------------------------------------------------------------------------- /cmake/FindFreeImage.cmake: -------------------------------------------------------------------------------- 1 | # Find the FreeImage library. 2 | # 3 | # This module defines 4 | # FREEIMAGE_FOUND - True if FREEIMAGE was found. 5 | # FREEIMAGE_INCLUDE_DIRS - Include directories for FREEIMAGE headers. 6 | # FREEIMAGE_LIBRARIES - Libraries for FREEIMAGE. 7 | # 8 | # To specify an additional directory to search, set FREEIMAGE_ROOT. 9 | # 10 | # Copyright (c) 2010, Ewen Cheslack-Postava 11 | # Based on FindSQLite3.cmake by: 12 | # Copyright (c) 2006, Jaroslaw Staniek, 13 | # Extended by Siddhartha Chaudhuri, 2008. 14 | # 15 | # Redistribution and use is allowed according to the terms of the BSD license. 16 | # 17 | 18 | SET(FREEIMAGE_FOUND FALSE) 19 | SET(FREEIMAGE_INCLUDE_DIRS) 20 | SET(FREEIMAGE_LIBRARIES) 21 | 22 | SET(SEARCH_PATHS 23 | $ENV{ProgramFiles}/freeimage/include 24 | $ENV{SystemDrive}/freeimage/include 25 | $ENV{ProgramFiles}/freeimage 26 | $ENV{SystemDrive}/freeimage 27 | ) 28 | IF(FREEIMAGE_ROOT) 29 | SET(SEARCH_PATHS 30 | ${FREEIMAGE_ROOT} 31 | ${FREEIMAGE_ROOT}/include 32 | ${SEARCH_PATHS} 33 | ) 34 | ENDIF() 35 | 36 | FIND_PATH(FREEIMAGE_INCLUDE_DIRS 37 | NAMES FreeImage.h 38 | PATHS ${SEARCH_PATHS} 39 | NO_DEFAULT_PATH) 40 | IF(NOT FREEIMAGE_INCLUDE_DIRS) # now look in system locations 41 | FIND_PATH(FREEIMAGE_INCLUDE_DIRS NAMES FreeImage.h) 42 | ENDIF(NOT FREEIMAGE_INCLUDE_DIRS) 43 | 44 | SET(FREEIMAGE_LIBRARY_DIRS) 45 | IF(FREEIMAGE_ROOT) 46 | SET(FREEIMAGE_LIBRARY_DIRS ${FREEIMAGE_ROOT}) 47 | IF(EXISTS "${FREEIMAGE_ROOT}/lib") 48 | SET(FREEIMAGE_LIBRARY_DIRS ${FREEIMAGE_LIBRARY_DIRS} ${FREEIMAGE_ROOT}/lib) 49 | ENDIF() 50 | IF(EXISTS "${FREEIMAGE_ROOT}/lib/static") 51 | SET(FREEIMAGE_LIBRARY_DIRS ${FREEIMAGE_LIBRARY_DIRS} ${FREEIMAGE_ROOT}/lib/static) 52 | ENDIF() 53 | ENDIF() 54 | 55 | # FREEIMAGE 56 | # Without system dirs 57 | FIND_LIBRARY(FREEIMAGE_LIBRARY 58 | NAMES freeimage 59 | PATHS ${FREEIMAGE_LIBRARY_DIRS} 60 | NO_DEFAULT_PATH 61 | ) 62 | IF(NOT FREEIMAGE_LIBRARY) # now look in system locations 63 | FIND_LIBRARY(FREEIMAGE_LIBRARY NAMES freeimage) 64 | ENDIF(NOT FREEIMAGE_LIBRARY) 65 | 66 | SET(FREEIMAGE_LIBRARIES) 67 | IF(FREEIMAGE_LIBRARY) 68 | SET(FREEIMAGE_LIBRARIES ${FREEIMAGE_LIBRARY}) 69 | ENDIF() 70 | 71 | IF(FREEIMAGE_INCLUDE_DIRS AND FREEIMAGE_LIBRARIES) 72 | SET(FREEIMAGE_FOUND TRUE) 73 | IF(NOT FREEIMAGE_FIND_QUIETLY) 74 | MESSAGE(STATUS "Found FreeImage: headers at ${FREEIMAGE_INCLUDE_DIRS}, libraries at ${FREEIMAGE_LIBRARY_DIRS} :: ${FREEIMAGE_LIBRARIES}") 75 | ENDIF(NOT FREEIMAGE_FIND_QUIETLY) 76 | ELSE(FREEIMAGE_INCLUDE_DIRS AND FREEIMAGE_LIBRARIES) 77 | SET(FREEIMAGE_FOUND FALSE) 78 | IF(FREEIMAGE_FIND_REQUIRED) 79 | MESSAGE(STATUS "FreeImage not found") 80 | ENDIF(FREEIMAGE_FIND_REQUIRED) 81 | ENDIF(FREEIMAGE_INCLUDE_DIRS AND FREEIMAGE_LIBRARIES) 82 | 83 | MARK_AS_ADVANCED(FREEIMAGE_INCLUDE_DIRS FREEIMAGE_LIBRARIES) 84 | -------------------------------------------------------------------------------- /include/radix/core/math/Vector2ui.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #ifndef VECTOR2UI_HPP 3 | #define VECTOR2UI_HPP 4 | 5 | #include 6 | 7 | namespace radix { 8 | 9 | /** \class Vector2ui 10 | * @brief 2-dimensional `unsigned int`-based storage and manipulation struct 11 | */ 12 | struct Vector2ui { 13 | union { 14 | unsigned int x, r, s, u; 15 | }; 16 | union { 17 | unsigned int y, g, t, v; 18 | }; 19 | 20 | static const Vector2ui ZERO, UP; 21 | 22 | /* Core */ 23 | constexpr Vector2ui() 24 | : x(0), y(0) {} 25 | constexpr Vector2ui(unsigned int x, unsigned int y) 26 | : x(x), y(y) {} 27 | constexpr Vector2ui(unsigned int v) 28 | : x(v), y(v) {} 29 | 30 | unsigned int length() const; 31 | std::string str() const; 32 | 33 | /* Operator overloads */ 34 | constexpr bool operator==(const Vector2ui &v) const { 35 | return x == v.x && y == v.y; 36 | } 37 | 38 | constexpr bool operator!=(const Vector2ui &v) const { 39 | return x != v.x || y != v.y; 40 | } 41 | 42 | constexpr Vector2ui operator+(const Vector2ui& v) const { 43 | return Vector2ui(x + v.x, y + v.y); 44 | } 45 | Vector2ui& operator+=(const Vector2ui &v) { 46 | x += v.x; 47 | y += v.y; 48 | return *this; 49 | } 50 | 51 | constexpr Vector2ui operator-(const Vector2ui& v) const { 52 | return Vector2ui(x - v.x, y - v.y); 53 | } 54 | Vector2ui& operator-=(const Vector2ui& v) { 55 | x -= v.x; 56 | y -= v.y; 57 | return *this; 58 | } 59 | 60 | constexpr Vector2ui operator*(const Vector2ui& v) const { 61 | return Vector2ui(x * v.x, y * v.y); 62 | } 63 | Vector2ui& operator*=(const Vector2ui& v) { 64 | x *= v.x; 65 | y *= v.y; 66 | return *this; 67 | } 68 | 69 | constexpr Vector2ui operator*(unsigned int scale) const { 70 | return Vector2ui(x * scale, y * scale); 71 | } 72 | Vector2ui& operator*=(unsigned int scale) { 73 | x *= scale; 74 | y *= scale; 75 | return *this; 76 | } 77 | 78 | constexpr Vector2ui operator/(unsigned int divisor) const { 79 | return Vector2ui(x / divisor, y / divisor); 80 | } 81 | Vector2ui& operator/=(unsigned int divisor) { 82 | x /= divisor; 83 | y /= divisor; 84 | return *this; 85 | } 86 | 87 | constexpr Vector2ui operator/=(const Vector2ui& v) const { 88 | return Vector2ui(x / v.x, y / v.y); 89 | } 90 | Vector2ui& operator/=(const Vector2ui& v) { 91 | x /= v.x; 92 | y /= v.y; 93 | return *this; 94 | } 95 | }; 96 | 97 | /* Utility functions */ 98 | constexpr inline unsigned int dot(const Vector2ui &v1, const Vector2ui &v2) { 99 | return v1.x * v2.x + v1.y * v2.y; 100 | } 101 | inline Vector2ui normalize(const Vector2ui &v) { 102 | return v / v.length(); 103 | } 104 | 105 | } /* namespace radix */ 106 | 107 | #endif /* VECTOR2F_HPP */ 108 | --------------------------------------------------------------------------------