├── docs └── logo │ └── Recast logo v1a.png ├── libs ├── sqlite │ ├── .gitignore │ └── CMakeLists.txt ├── Box2D │ ├── UseBox2D.cmake │ ├── Box2D │ │ ├── UseBox2D.cmake │ │ ├── Common │ │ │ ├── b2Draw.cpp │ │ │ ├── b2Settings.cpp │ │ │ ├── b2Timer.h │ │ │ ├── b2StackAllocator.h │ │ │ ├── b2BlockAllocator.h │ │ │ ├── b2GrowableStack.h │ │ │ └── b2StackAllocator.cpp │ │ ├── Box2DConfig.cmake.in │ │ ├── Dynamics │ │ │ ├── Contacts │ │ │ │ ├── b2CircleContact.h │ │ │ │ ├── b2PolygonContact.h │ │ │ │ ├── b2EdgeAndCircleContact.h │ │ │ │ ├── b2EdgeAndPolygonContact.h │ │ │ │ ├── b2PolygonAndCircleContact.h │ │ │ │ ├── b2ChainAndCircleContact.h │ │ │ │ ├── b2ChainAndPolygonContact.h │ │ │ │ ├── b2EdgeAndCircleContact.cpp │ │ │ │ ├── b2EdgeAndPolygonContact.cpp │ │ │ │ ├── b2CircleContact.cpp │ │ │ │ ├── b2PolygonAndCircleContact.cpp │ │ │ │ └── b2PolygonContact.cpp │ │ │ ├── b2WorldCallbacks.cpp │ │ │ ├── b2ContactManager.h │ │ │ └── b2TimeStep.h │ │ └── Collision │ │ │ └── b2TimeOfImpact.h │ ├── Common │ │ ├── b2Draw.cpp │ │ ├── b2Settings.cpp │ │ ├── b2Timer.h │ │ ├── b2StackAllocator.h │ │ ├── b2BlockAllocator.h │ │ ├── b2GrowableStack.h │ │ └── b2StackAllocator.cpp │ ├── Box2DConfig.cmake.in │ ├── Dynamics │ │ ├── Contacts │ │ │ ├── b2CircleContact.h │ │ │ ├── b2PolygonContact.h │ │ │ ├── b2EdgeAndCircleContact.h │ │ │ ├── b2EdgeAndPolygonContact.h │ │ │ ├── b2PolygonAndCircleContact.h │ │ │ ├── b2ChainAndCircleContact.h │ │ │ ├── b2ChainAndPolygonContact.h │ │ │ ├── b2EdgeAndCircleContact.cpp │ │ │ ├── b2EdgeAndPolygonContact.cpp │ │ │ ├── b2PolygonAndCircleContact.cpp │ │ │ ├── b2CircleContact.cpp │ │ │ └── b2PolygonContact.cpp │ │ ├── b2WorldCallbacks.cpp │ │ ├── b2ContactManager.h │ │ └── b2TimeStep.h │ └── Collision │ │ └── b2TimeOfImpact.h ├── sqlite_orm │ └── CMakeLists.txt └── CMakeLists.txt ├── src ├── core │ ├── commands │ │ ├── ICommand.cpp │ │ ├── ICommandSender.cpp │ │ ├── StopCommand.cpp │ │ └── CreateEntityCommand.cpp │ ├── io │ │ ├── network │ │ │ ├── listeners │ │ │ │ ├── CastSpell.cpp │ │ │ │ └── GetEntitys.cpp │ │ │ ├── Socket.cpp │ │ │ └── NetworkUtils.cpp │ │ ├── SQLite.cpp │ │ └── configs │ │ │ └── Config.cpp │ └── utils │ │ ├── Utils.cpp │ │ └── Parcel.cpp ├── spell │ ├── events │ │ ├── SpellEventListener.cpp │ │ ├── HeatEvent.cpp │ │ └── MoveEvent.cpp │ ├── nodes │ │ ├── GeneratorNode.cpp │ │ ├── HeaterNode.cpp │ │ ├── AimNode.cpp │ │ └── EnergyNode.cpp │ └── Spell.cpp ├── headers │ ├── models │ │ ├── Point.hpp │ │ ├── User.hpp │ │ ├── Player.hpp │ │ └── collections │ │ │ └── PlayersOnline.hpp │ ├── utils │ │ ├── Utils.hpp │ │ ├── DelayedSpellCreate.h │ │ ├── DelayCommand.h │ │ └── Parcel.hpp │ ├── world │ │ ├── wrappers │ │ │ ├── EntityType.h │ │ │ ├── EntityData.h │ │ │ ├── SpellEntity.h │ │ │ └── Entity.h │ │ ├── utils │ │ │ └── CollectEntity.h │ │ └── Box2DWorld.h │ ├── spells │ │ ├── events │ │ │ ├── IEventListener.hpp │ │ │ ├── MoveEvent.h │ │ │ ├── IEvent.hpp │ │ │ ├── HeatEvent.hpp │ │ │ └── SpellEventListener.hpp │ │ ├── nodes │ │ │ ├── HeaterNode.hpp │ │ │ ├── GeneratorNode.h │ │ │ ├── AimNode.h │ │ │ ├── EnergyNode.hpp │ │ │ └── SpellNode.hpp │ │ └── Spell.hpp │ ├── temperature-world │ │ ├── types │ │ │ ├── Size.hpp │ │ │ ├── Temperature.hpp │ │ │ ├── Coord.hpp │ │ │ ├── Edge.hpp │ │ │ ├── GenericScalar.hpp │ │ │ ├── Point.hpp │ │ │ ├── IntScale.hpp │ │ │ └── IntScaleParallelepiped.hpp │ │ ├── interfaces │ │ │ ├── IUpdater.hpp │ │ │ ├── ITimer.hpp │ │ │ ├── ITimerBlockable.hpp │ │ │ ├── ITemperatureWorldScalable.hpp │ │ │ ├── ITemperatureWorldScalableMutable.hpp │ │ │ ├── ITemperatureWorldPointPrioritizable.hpp │ │ │ ├── ITemperatureWorldChunkableMutable.hpp │ │ │ ├── ITemperatureWorldChunkableObservable.hpp │ │ │ ├── IUpdaterTemperatureWorldSemiChunkUpdatable.hpp │ │ │ ├── ITemperatureWorldBoundable.hpp │ │ │ ├── ITemperatureWorldChunkableGeneratable.hpp │ │ │ └── ITemperatureWorldChunkable.hpp │ │ ├── implementation │ │ │ ├── BoundTemperatureWorld.inc.hpp │ │ │ ├── BasicTimer.hpp │ │ │ ├── typedefs │ │ │ │ └── GeneratableChunkedTemperatureWorldTypedefs.hpp │ │ │ ├── SynchronizedBlockingTimer.hpp │ │ │ ├── BoundTemperatureWorld.hpp │ │ │ ├── ChunkedTemperatureWorld.hpp │ │ │ ├── GeneratableChunkedTemperatureWorld.hpp │ │ │ └── ScalingGeneratableChunkedTemperatureWorld.hpp │ │ └── utils │ │ │ ├── FileUtils.hpp │ │ │ ├── TimeUtils.hpp │ │ │ ├── MathUtils.hpp │ │ │ └── TemperatureWorldUtils.hpp │ ├── io │ │ ├── network │ │ │ ├── listeners │ │ │ │ ├── CastSpell.h │ │ │ │ └── GetEntitys.h │ │ │ ├── Networking.hpp │ │ │ ├── NetworkUtils.hpp │ │ │ ├── Socket.hpp │ │ │ ├── SocketUDP.hpp │ │ │ ├── NetworkListener.hpp │ │ │ ├── SocketTCP.hpp │ │ │ └── NetworkServer.hpp │ │ └── configs │ │ │ └── Config.hpp │ ├── commands │ │ ├── StopCommand.hpp │ │ ├── ICommandSender.hpp │ │ ├── CreateEntityCommand.h │ │ ├── CommandManager.hpp │ │ └── ICommand.hpp │ ├── exceptions │ │ ├── ServerFullException.hpp │ │ └── InvalidLoginOrPassword.hpp │ └── threads │ │ └── InputThread.hpp ├── Main.cpp ├── world │ └── wrappers │ │ ├── SpellEntity.cpp │ │ └── Entity.cpp ├── temperature-world │ └── implementation │ │ ├── BasicTimer.cpp │ │ └── SynchronizedBlockingTimer.cpp └── threads │ └── InputThread.cpp ├── Dockerfile ├── test └── temperature-world │ ├── demo-web │ └── index.html │ ├── performance.cpp │ ├── performance-multichunk.cpp │ ├── unittest.cpp │ └── demo.cpp ├── .travis.yml └── README.md /docs/logo/Recast logo v1a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/glitchless/Recast/HEAD/docs/logo/Recast logo v1a.png -------------------------------------------------------------------------------- /libs/sqlite/.gitignore: -------------------------------------------------------------------------------- 1 | CMakeCache.txt 2 | CMakeFiles 3 | Makefile 4 | cmake_install.cmake 5 | install_manifest.txt 6 | -------------------------------------------------------------------------------- /src/core/commands/ICommand.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief ICommand some method 4 | * @author LionZXY 5 | * @project Recast-server 6 | * @date 08.06.17 7 | * 8 | * Now do nothing :3 9 | * 10 | **/ 11 | #include "commands/ICommand.hpp" 12 | -------------------------------------------------------------------------------- /src/core/commands/ICommandSender.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief ICommandSender file for other method. 4 | * @author LionZXY 5 | * @project Recast-server 6 | * @date 08.06.17 7 | * 8 | * Now do nothing :3 9 | * 10 | **/ 11 | #include "commands/ICommandSender.hpp" 12 | -------------------------------------------------------------------------------- /libs/Box2D/UseBox2D.cmake: -------------------------------------------------------------------------------- 1 | # -*- cmake -*- 2 | # 3 | # UseBox2d.cmake 4 | # 5 | 6 | add_definitions ( ${BOX2D_DEFINITIONS} ) 7 | include_directories ( ${BOX2D_INCLUDE_DIRS} ) 8 | link_directories ( ${BOX2D_LIBRARY_DIRS} ) 9 | 10 | -------------------------------------------------------------------------------- /libs/Box2D/Box2D/UseBox2D.cmake: -------------------------------------------------------------------------------- 1 | # -*- cmake -*- 2 | # 3 | # UseBox2d.cmake 4 | # 5 | 6 | add_definitions ( ${BOX2D_DEFINITIONS} ) 7 | include_directories ( ${BOX2D_INCLUDE_DIRS} ) 8 | link_directories ( ${BOX2D_LIBRARY_DIRS} ) 9 | 10 | -------------------------------------------------------------------------------- /src/spell/events/SpellEventListener.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file SpellEventListener.cpp 3 | * @author LionZXY 4 | * @project Recast-server 5 | * @date 24.06.17 6 | * @email nikita@kulikof.ru 7 | **/ 8 | #include "spells/events/SpellEventListener.hpp" 9 | 10 | void SpellEventListener::onEvent(IEvent &event) { 11 | event.commit(world, entity, tempWorld); 12 | } 13 | -------------------------------------------------------------------------------- /src/headers/models/Point.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RECAST_SERVER_POINT_H 2 | #define RECAST_SERVER_POINT_H 3 | 4 | /** 5 | * @brief Just point 6 | * 7 | * It't Point. James Point. 8 | */ 9 | struct Point { 10 | double x; 11 | double y; 12 | double z; 13 | 14 | Point(double x, double y, double z) : x(x), y(y), z(z) {} 15 | }; 16 | 17 | 18 | #endif //RECAST_SERVER_POINT_H 19 | -------------------------------------------------------------------------------- /src/Main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file Main.cpp 3 | * @brief Starting point 4 | * @author LionZXY 5 | * 6 | * Starting point for Recast server. Initializing @see Server and @see MainThread. 7 | * Init config class @see Config. 8 | **/ 9 | #include "Server.hpp" 10 | 11 | /** 12 | * @brief Main method :) 13 | **/ 14 | int main() { 15 | Server server; 16 | server.initServer(); 17 | return EXIT_SUCCESS; 18 | } 19 | -------------------------------------------------------------------------------- /src/headers/utils/Utils.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file Utils.h 3 | * @brief Utils file 4 | * @author LionZXY 5 | * @project Recast-server 6 | * @date 16.06.17 7 | * @email nikita@kulikof.ru 8 | * 9 | * Misc methods 10 | * 11 | **/ 12 | #ifndef RECAST_SERVER_UTILS_H 13 | #define RECAST_SERVER_UTILS_H 14 | 15 | #include 16 | 17 | std::string genRandomString(const size_t len); 18 | 19 | #endif //RECAST_SERVER_UTILS_H 20 | -------------------------------------------------------------------------------- /src/headers/world/wrappers/EntityType.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file EntityType.h 3 | * @author LionZXY 4 | * @project Recast-server 5 | * @date 28.06.17 6 | * @email nikita@kulikof.ru 7 | **/ 8 | #ifndef RECAST_SERVER_ENTITYTYPE_H 9 | #define RECAST_SERVER_ENTITYTYPE_H 10 | 11 | enum EntityType { 12 | UNKN = 3, 13 | MOB = 0, 14 | FIREBALL = 1, 15 | SPELL = 2 16 | }; 17 | 18 | #endif //RECAST_SERVER_ENTITYTYPE_H 19 | -------------------------------------------------------------------------------- /libs/sqlite_orm/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | PROJECT(sqlite_orm) 2 | cmake_minimum_required(VERSION 2.8) 3 | 4 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}) 5 | add_library(sqlite_orm STATIC sqlite_orm.h) 6 | 7 | SET_TARGET_PROPERTIES(sqlite_orm PROPERTIES LINKER_LANGUAGE CXX) 8 | 9 | target_link_libraries(sqlite_orm ${CMAKE_DL_LIBS}) 10 | install(FILES sqlite_orm.h DESTINATION include) 11 | install(TARGETS sqlite_orm LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) 12 | -------------------------------------------------------------------------------- /src/headers/spells/events/IEventListener.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file IEventListener.h 3 | * @author LionZXY 4 | * @project Recast-server 5 | * @date 21.06.17 6 | * @email nikita@kulikof.ru 7 | **/ 8 | #ifndef RECAST_SERVER_IEVENTLISTENER_H 9 | #define RECAST_SERVER_IEVENTLISTENER_H 10 | 11 | #include "IEvent.hpp" 12 | 13 | class IEventListener { 14 | public: 15 | virtual void onEvent(IEvent &event) {}; 16 | }; 17 | 18 | 19 | #endif //RECAST_SERVER_IEVENTLISTENER_H 20 | -------------------------------------------------------------------------------- /src/headers/temperature-world/types/Size.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Oleg Morozenkov on 31.05.17. 3 | // 4 | 5 | #ifndef RECAST_SIZE_H_H 6 | #define RECAST_SIZE_H_H 7 | 8 | 9 | #include "GenericScalar.hpp" 10 | 11 | /** 12 | * Type. 13 | * Represents world object or size of world by some axis. 14 | */ 15 | struct Size : public GenericScalar { 16 | public: 17 | Size(int value = 0) : GenericScalar(value) { 18 | } 19 | }; 20 | 21 | 22 | #endif //RECAST_SIZE_H_H 23 | -------------------------------------------------------------------------------- /src/headers/temperature-world/types/Temperature.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Oleg Morozenkov on 30.03.17. 3 | // 4 | 5 | #ifndef RECAST_TEMPERATURE_H 6 | #define RECAST_TEMPERATURE_H 7 | 8 | 9 | #include "GenericScalar.hpp" 10 | 11 | /** 12 | * Type. 13 | * Represents temperature of world object. 14 | */ 15 | struct Temperature : public GenericScalar { 16 | public: 17 | Temperature(int value = 0) : GenericScalar(value) { 18 | } 19 | }; 20 | 21 | 22 | #endif //RECAST_TEMPERATURE_H -------------------------------------------------------------------------------- /src/headers/temperature-world/interfaces/IUpdater.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Oleg Morozenkov on 30.03.17. 3 | // 4 | 5 | #ifndef RECAST_TEMPERATUREWORLDUPDATER_H 6 | #define RECAST_TEMPERATUREWORLDUPDATER_H 7 | 8 | 9 | /** 10 | * Interface. 11 | * Updates something. 12 | */ 13 | class IUpdater { 14 | public: 15 | virtual ~IUpdater() noexcept = default; 16 | 17 | /** 18 | * Updates. 19 | */ 20 | virtual void update() = 0; 21 | }; 22 | 23 | 24 | #endif //RECAST_TEMPERATUREWORLDUPDATER_H 25 | -------------------------------------------------------------------------------- /src/headers/temperature-world/types/Coord.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Oleg Morozenkov on 30.03.17. 3 | // 4 | 5 | #ifndef RECAST_COORD_H 6 | #define RECAST_COORD_H 7 | 8 | 9 | #include 10 | #include "GenericScalar.hpp" 11 | 12 | /** 13 | * Type. 14 | * Represents coordinate in a space. 15 | */ 16 | struct Coord : public GenericScalar { 17 | public: 18 | Coord(int value = 0) : GenericScalar(value) { 19 | } 20 | }; 21 | 22 | 23 | #endif //RECAST_COORD_H 24 | -------------------------------------------------------------------------------- /src/headers/io/network/listeners/CastSpell.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file CastSpell.h 3 | * @author LionZXY 4 | * @project Recast-server 5 | * @date 28.06.17 6 | * @email nikita@kulikof.ru 7 | **/ 8 | #ifndef RECAST_SERVER_CASTSPELL_H 9 | #define RECAST_SERVER_CASTSPELL_H 10 | 11 | 12 | #include 13 | 14 | class CastSpell : public NetworkListener { 15 | public: 16 | CastSpell(); 17 | 18 | char *onPacket(char *request, ICommandSender *sender); 19 | }; 20 | 21 | 22 | #endif //RECAST_SERVER_CASTSPELL_H 23 | -------------------------------------------------------------------------------- /src/headers/world/wrappers/EntityData.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file EntityData.h 3 | * @author LionZXY 4 | * @project Recast-server 5 | * @date 25.06.17 6 | * @email nikita@kulikof.ru 7 | **/ 8 | #ifndef RECAST_SERVER_ENTITYDATA_H 9 | #define RECAST_SERVER_ENTITYDATA_H 10 | 11 | #include "EntityType.h" 12 | 13 | class SpellEntity; 14 | 15 | class EntityData { 16 | public: 17 | int id = -1; 18 | SpellEntity *spellEntity = NULL; 19 | EntityType type = EntityType::UNKN; 20 | }; 21 | 22 | 23 | #endif //RECAST_SERVER_ENTITYDATA_H 24 | -------------------------------------------------------------------------------- /src/headers/io/network/listeners/GetEntitys.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file GetEntitys.h 3 | * @author LionZXY 4 | * @project Recast-server 5 | * @date 28.06.17 6 | * @email nikita@kulikof.ru 7 | **/ 8 | #ifndef RECAST_SERVER_GETENTITYS_H 9 | #define RECAST_SERVER_GETENTITYS_H 10 | 11 | #include 12 | 13 | class GetEntitys: public NetworkListener { 14 | public: 15 | 16 | GetEntitys(); 17 | 18 | char *onPacket(char *request, ICommandSender *sender); 19 | }; 20 | 21 | 22 | #endif //RECAST_SERVER_GETENTITYS_H 23 | -------------------------------------------------------------------------------- /src/headers/commands/StopCommand.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RECAST_SERVER_STOPCOMMAND_H 2 | #define RECAST_SERVER_STOPCOMMAND_H 3 | 4 | 5 | #include "ICommand.hpp" 6 | 7 | /** 8 | * @brief StopCommand 9 | * 10 | * @example 'stop' 11 | */ 12 | class StopCommand: public ICommand { 13 | public: 14 | bool isValid(const std::string &cmd, const std::vector &args) const; 15 | void onCommand(ICommandSender &sender, const std::string &cmd, const std::vector &args); 16 | 17 | }; 18 | 19 | 20 | #endif //RECAST_SERVER_STOPCOMMAND_H 21 | -------------------------------------------------------------------------------- /src/headers/io/network/Networking.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file Networking.hpp 3 | * @brief Networking quick-include header file 4 | * @author StealthTech 5 | * @project Recast-server 6 | * @date 27.06.17 7 | * @email st3althtech@mail.ru 8 | * 9 | **/ 10 | 11 | #ifndef RECAST_SERVER_NETWORKING_HPP 12 | #define RECAST_SERVER_NETWORKING_HPP 13 | 14 | #include "NetworkUtils.hpp" 15 | #include "NetworkListener.hpp" 16 | #include "Socket.hpp" 17 | #include "SocketTCP.hpp" 18 | #include "SocketUDP.hpp" 19 | 20 | #endif //RECAST_SERVER_NETWORKING_HPP 21 | -------------------------------------------------------------------------------- /src/headers/temperature-world/types/Edge.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Oleg Morozenkov on 24.06.17. 3 | // 4 | 5 | #ifndef RECAST_SERVER_EDGE_HPP 6 | #define RECAST_SERVER_EDGE_HPP 7 | 8 | 9 | /** 10 | * Represents edges of a cube. 11 | * When you see a cube from the side of XY plane, `left`, `right`, `up` and `down` are the edges of this plane. `Near` edge is this plane. `Far` is cube edge which is parallel to this plane. 12 | */ 13 | enum class Edge { 14 | LEFT, RIGHT, UP, DOWN, NEAR, FAR 15 | }; 16 | 17 | 18 | #endif //RECAST_SERVER_EDGE_HPP 19 | -------------------------------------------------------------------------------- /src/headers/commands/ICommandSender.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RECAST_SERVER_ICOMMANDSENDER_H 2 | #define RECAST_SERVER_ICOMMANDSENDER_H 3 | 4 | #include 5 | 6 | class Server; 7 | 8 | class Player; 9 | 10 | class Box2DWorld; 11 | 12 | class ICommandSender { 13 | public: 14 | virtual bool isOP() const = 0; 15 | 16 | virtual Server *getServer() = 0; 17 | 18 | virtual Box2DWorld *getWorld() = 0; 19 | 20 | virtual Player *getPlayer() = 0; 21 | 22 | virtual void onMessage(const std::string &msg) = 0; 23 | }; 24 | 25 | 26 | #endif //RECAST_SERVER_ICOMMANDSENDER_H 27 | -------------------------------------------------------------------------------- /src/headers/spells/nodes/HeaterNode.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file HeaterNode.h 3 | * @author LionZXY 4 | * @project Recast-server 5 | * @date 24.06.17 6 | * @email nikita@kulikof.ru 7 | **/ 8 | #ifndef RECAST_SERVER_HEATERNODE_H 9 | #define RECAST_SERVER_HEATERNODE_H 10 | 11 | 12 | #include "EnergyNode.hpp" 13 | 14 | class HeaterNode: public EnergyNode { 15 | public: 16 | HeaterNode(float x, float y, float z, float energy); 17 | 18 | private: 19 | virtual void onTick(IEventListener &listener, SpellNode *callable); 20 | }; 21 | 22 | 23 | #endif //RECAST_SERVER_HEATERNODE_H 24 | -------------------------------------------------------------------------------- /src/headers/temperature-world/implementation/BoundTemperatureWorld.inc.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Oleg Morozenkov on 15.06.17. 3 | // 4 | 5 | #ifndef RECAST_SYNCHRONIZEDVECTORBOUNDTEMPERATUREWORLD_INC_H 6 | #define RECAST_SYNCHRONIZEDVECTORBOUNDTEMPERATUREWORLD_INC_H 7 | 8 | 9 | #include "BoundTemperatureWorld.hpp" 10 | 11 | inline void swap(BoundTemperatureWorld& first, BoundTemperatureWorld& second) { 12 | std::swap(first._bounds, second._bounds); 13 | std::swap(first._data, second._data); 14 | } 15 | 16 | 17 | #endif //RECAST_SYNCHRONIZEDVECTORBOUNDTEMPERATUREWORLD_INC_H 18 | -------------------------------------------------------------------------------- /src/headers/spells/nodes/GeneratorNode.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file GeneratorNode.h 3 | * @author LionZXY 4 | * @project Recast-server 5 | * @date 27.06.17 6 | * @email nikita@kulikof.ru 7 | **/ 8 | #ifndef RECAST_SERVER_GENERATORNODE_H 9 | #define RECAST_SERVER_GENERATORNODE_H 10 | 11 | 12 | #include "EnergyNode.hpp" 13 | 14 | class GeneratorNode : public EnergyNode { 15 | public: 16 | GeneratorNode(float x, float y, float z, float energy); 17 | 18 | private: 19 | virtual void onTick(IEventListener &listener, SpellNode *callable); 20 | }; 21 | 22 | 23 | #endif //RECAST_SERVER_GENERATORNODE_H 24 | -------------------------------------------------------------------------------- /src/headers/spells/nodes/AimNode.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file AimNode.h 3 | * @author LionZXY 4 | * @project Recast-server 5 | * @date 25.06.17 6 | * @email nikita@kulikof.ru 7 | **/ 8 | #ifndef RECAST_SERVER_AIMNODE_H 9 | #define RECAST_SERVER_AIMNODE_H 10 | 11 | #include 12 | #include "EnergyNode.hpp" 13 | 14 | class AimNode: public EnergyNode { 15 | public: 16 | AimNode(float x, float y, float z, float energy, 17 | int entityId); 18 | 19 | private: 20 | int entityId; 21 | void onTick(IEventListener &listener, SpellNode *callable); 22 | }; 23 | 24 | 25 | #endif //RECAST_SERVER_AIMNODE_H 26 | -------------------------------------------------------------------------------- /src/spell/nodes/GeneratorNode.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file GeneratorNode.cpp 3 | * @author LionZXY 4 | * @project Recast-server 5 | * @date 27.06.17 6 | * @email nikita@kulikof.ru 7 | **/ 8 | #include "spells/nodes/GeneratorNode.h" 9 | 10 | GeneratorNode::GeneratorNode(float x, float y, float z, float energy) : EnergyNode(NodeType::GENERATOR, x, y, z, 11 | energy) { 12 | 13 | } 14 | 15 | void GeneratorNode::onTick(IEventListener &listener, SpellNode *callable) { 16 | energy += Config::g("spell.generator.per_tick", 10); 17 | EnergyNode::onTick(listener, callable); 18 | } 19 | -------------------------------------------------------------------------------- /src/headers/spells/events/MoveEvent.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file MoveEvent.h 3 | * @author LionZXY 4 | * @project Recast-server 5 | * @date 25.06.17 6 | * @email nikita@kulikof.ru 7 | **/ 8 | #ifndef RECAST_SERVER_MOVEEVENT_H 9 | #define RECAST_SERVER_MOVEEVENT_H 10 | 11 | 12 | #include "IEvent.hpp" 13 | 14 | class MoveEvent : public IEvent { 15 | public: 16 | MoveEvent(SpellNode *node, int entityId, float energy) : IEvent(node), entityId(entityId), energy(energy) {} 17 | void commit(Box2DWorld *world, SpellEntity * entity, std::shared_ptr tempWorld); 18 | private: 19 | float energy; 20 | int entityId; 21 | }; 22 | 23 | 24 | #endif //RECAST_SERVER_MOVEEVENT_H 25 | -------------------------------------------------------------------------------- /src/world/wrappers/SpellEntity.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file SpellEntity.cpp 3 | * @author LionZXY 4 | * @project Recast-server 5 | * @date 25.06.17 6 | * @email nikita@kulikof.ru 7 | **/ 8 | #include 9 | #include "world/wrappers/SpellEntity.h" 10 | #include "spells/Spell.hpp" 11 | 12 | SpellEntity::SpellEntity(b2Fixture *fixture1, Spell *spell, Box2DWorld *world, std::shared_ptr tempWorld) 13 | : Entity(fixture1), spell(spell), 14 | listener(spell, this, world, tempWorld) {} 15 | 16 | void SpellEntity::update(Box2DWorld *box2DWorld) { 17 | spell->tickSpell(listener); 18 | } 19 | 20 | SpellEntity::~SpellEntity() { 21 | delete spell; 22 | } 23 | -------------------------------------------------------------------------------- /src/headers/exceptions/ServerFullException.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file ServerFullException.h 3 | * @brief Exception - server is full 4 | * @author LionZXY 5 | * @project Recast-server 6 | * @date 16.06.17 7 | * @email nikita@kulikof.ru 8 | * 9 | * Exception thrown when server is full and user tries to connect 10 | * 11 | **/ 12 | #ifndef RECAST_SERVER_SERVERFULLEXCEPTION_H 13 | #define RECAST_SERVER_SERVERFULLEXCEPTION_H 14 | 15 | 16 | #include 17 | 18 | class ServerFullException : public std::exception { 19 | public: 20 | const char *what() const throw() { 21 | return "Server is full!"; 22 | } 23 | }; 24 | 25 | 26 | #endif //RECAST_SERVER_SERVERFULLEXCEPTION_H 27 | -------------------------------------------------------------------------------- /libs/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | if(UNIX) 3 | set(BOX2D_INSTALL_BY_DEFAULT ON) 4 | else(UNIX) 5 | set(BOX2D_INSTALL_BY_DEFAULT OFF) 6 | endif(UNIX) 7 | 8 | option(BOX2D_INSTALL "Install Box2D libs, includes, and CMake scripts" ${BOX2D_INSTALL_BY_DEFAULT}) 9 | option(BOX2D_INSTALL_DOC "Install Box2D documentation" OFF) 10 | option(BOX2D_BUILD_SHARED "Build Box2D shared libraries" OFF) 11 | option(BOX2D_BUILD_STATIC "Build Box2D static libraries" ON) 12 | option(BOX2D_BUILD_EXAMPLES "Build Box2D examples" OFF) 13 | 14 | set(BOX2D_VERSION 2.3.0) 15 | set(LIB_INSTALL_DIR lib${LIB_SUFFIX}) 16 | 17 | add_subdirectory(Box2D) # Box2D 18 | add_subdirectory(sqlite) # SqLite 19 | add_subdirectory(sqlite_orm) # SqLite ORM 20 | 21 | -------------------------------------------------------------------------------- /src/headers/exceptions/InvalidLoginOrPassword.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file InvalidLoginOrPassword.h 3 | * @brief Exception - auth failed 4 | * @author LionZXY 5 | * @project Recast-server 6 | * @date 17.06.17 7 | * @email nikita@kulikof.ru 8 | * 9 | * Exception throw when auth failed: incorrect login or password. 10 | * 11 | **/ 12 | #ifndef RECAST_SERVER_INVALIDLOGINORPASSWORD_H 13 | #define RECAST_SERVER_INVALIDLOGINORPASSWORD_H 14 | 15 | #include 16 | 17 | class InvalidLoginOrPassword : public std::exception { 18 | public: 19 | const char * what () const throw () { 20 | return "Invalid login or password. Try again!"; 21 | } 22 | }; 23 | 24 | 25 | #endif //RECAST_SERVER_INVALIDLOGINORPASSWORD_H 26 | -------------------------------------------------------------------------------- /src/core/io/network/listeners/CastSpell.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file CastSpell.cpp 3 | * @author LionZXY 4 | * @project Recast-server 5 | * @date 28.06.17 6 | * @email nikita@kulikof.ru 7 | **/ 8 | #include "io/network/listeners/CastSpell.h" 9 | #include "spells/Spell.hpp" 10 | 11 | CastSpell::CastSpell() : NetworkListener(2) {} 12 | 13 | using namespace std; 14 | 15 | char *CastSpell::onPacket(char *request, ICommandSender *sender) { 16 | Parcel parcel(vector(request + 1, request + sizeof(request) / sizeof(char))); 17 | b2Vec2 pos(parcel.readFloat(), parcel.readFloat()); 18 | Spell *spell = Spell::read(parcel); 19 | sender->getWorld()->asyncCreateSpellEntity(pos, spell); 20 | return (char *) "OK!"; 21 | } 22 | -------------------------------------------------------------------------------- /src/core/commands/StopCommand.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "commands/ICommandSender.hpp" 3 | #include "commands/StopCommand.hpp" 4 | #include "Server.hpp" 5 | 6 | using namespace std; 7 | 8 | bool StopCommand::isValid(const string &cmd, const vector &args) const { 9 | return cmd == "stop"; 10 | } 11 | 12 | void StopCommand::onCommand(ICommandSender &sender, const string &cmd, const vector &args) { 13 | if (!sender.isOP()) { 14 | sender.onMessage("Permission error"); 15 | } else if (sender.getServer() != NULL) { 16 | sender.getServer()->shutdown(); 17 | sender.onMessage("Server stopping..."); 18 | } else { 19 | sender.onMessage("Unavilable Server class. Contact to developers."); 20 | } 21 | } -------------------------------------------------------------------------------- /src/headers/commands/CreateEntityCommand.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file CreateEntityCommand.h 3 | * @author LionZXY 4 | * @project Recast-server 5 | * @date 27.06.17 6 | * @email nikita@kulikof.ru 7 | **/ 8 | #ifndef RECAST_SERVER_CREATEENTITYCOMMAND_H 9 | #define RECAST_SERVER_CREATEENTITYCOMMAND_H 10 | 11 | #include "commands/ICommand.hpp" 12 | 13 | class CreateEntityCommand : public ICommand { 14 | public: 15 | bool isOnlyUICommand() { return true; } 16 | 17 | bool isValid(const std::string &cmd, const std::vector &args) const; 18 | 19 | void onCommand(ICommandSender &sender, const std::string &cmd, const std::vector &args); 20 | 21 | 22 | }; 23 | 24 | 25 | #endif //RECAST_SERVER_CREATEENTITYCOMMAND_H 26 | -------------------------------------------------------------------------------- /src/headers/temperature-world/types/GenericScalar.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Oleg Morozenkov on 14.06.17. 3 | // 4 | 5 | #ifndef RECAST_GENERICSCALAR_H 6 | #define RECAST_GENERICSCALAR_H 7 | 8 | 9 | /** 10 | * Template for structs that wrap fundamental types. You can consider it as medium-strong typedef. 11 | * 12 | * @tparam T Underlying type. 13 | */ 14 | template 15 | struct GenericScalar { 16 | public: 17 | GenericScalar(T value) : _value(value) { 18 | } 19 | 20 | inline operator T() const noexcept { 21 | return _value; 22 | } 23 | 24 | inline operator T&() noexcept { 25 | return _value; 26 | } 27 | 28 | protected: 29 | T _value; 30 | }; 31 | 32 | 33 | #endif //RECAST_GENERICSCALAR_H 34 | -------------------------------------------------------------------------------- /src/headers/utils/DelayedSpellCreate.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file DelayedSpellCreate.h 3 | * @author LionZXY 4 | * @project Recast-server 5 | * @date 28.06.17 6 | * @email nikita@kulikof.ru 7 | **/ 8 | #ifndef RECAST_SERVER_DELAYEDSPELLCREATE_H 9 | #define RECAST_SERVER_DELAYEDSPELLCREATE_H 10 | 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | class DelayedSpellCreate { 17 | public: 18 | DelayedSpellCreate(b2Vec2 pos, Spell *spell) : pos(pos), spell(spell) {} 19 | 20 | b2Vec2 getPos() { return pos; } 21 | 22 | Spell *getSpell() { return spell; } 23 | 24 | private: 25 | b2Vec2 pos; 26 | Spell *spell; 27 | }; 28 | 29 | 30 | #endif //RECAST_SERVER_DELAYEDSPELLCREATE_H 31 | -------------------------------------------------------------------------------- /src/headers/world/wrappers/SpellEntity.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file SpellEntity.h 3 | * @author LionZXY 4 | * @project Recast-server 5 | * @date 25.06.17 6 | * @email nikita@kulikof.ru 7 | **/ 8 | #ifndef RECAST_SERVER_SPELLENTITY_H 9 | #define RECAST_SERVER_SPELLENTITY_H 10 | 11 | #include "spells/events/SpellEventListener.hpp" 12 | #include "Entity.h" 13 | 14 | class Spell; 15 | 16 | class SpellEntity : public Entity { 17 | public: 18 | SpellEntity(b2Fixture *fixture1, Spell *spell, Box2DWorld *world, std::shared_ptr tempWorld); 19 | 20 | ~SpellEntity(); 21 | 22 | void update(Box2DWorld *box2DWorld); 23 | 24 | private: 25 | Spell *spell; 26 | SpellEventListener listener; 27 | }; 28 | 29 | 30 | #endif //RECAST_SERVER_SPELLENTITY_H 31 | -------------------------------------------------------------------------------- /src/headers/spells/events/IEvent.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file IEvent.h 3 | * @author LionZXY 4 | * @project Recast-server 5 | * @date 21.06.17 6 | * @email nikita@kulikof.ru 7 | **/ 8 | #ifndef RECAST_SERVER_IEVENT_H 9 | #define RECAST_SERVER_IEVENT_H 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | class SpellNode; 16 | class SpellEntity; 17 | 18 | class IEvent { 19 | public: 20 | IEvent(SpellNode *node) : fromNode(node) {} 21 | 22 | SpellNode *getNode() const { return fromNode; } 23 | 24 | virtual void commit(Box2DWorld *world, SpellEntity * entity, std::shared_ptr tempWorld) = 0; 25 | 26 | protected: 27 | SpellNode *fromNode; 28 | }; 29 | 30 | 31 | #endif //RECAST_SERVER_IEVENT_H 32 | -------------------------------------------------------------------------------- /src/headers/temperature-world/implementation/BasicTimer.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Oleg Morozenkov on 11.06.17. 3 | // 4 | 5 | #ifndef RECAST_BASICTIMER_H 6 | #define RECAST_BASICTIMER_H 7 | 8 | 9 | #include "temperature-world/interfaces/ITimer.hpp" 10 | 11 | /** 12 | * Timer that measures time duration between two updates. 13 | */ 14 | class BasicTimer : public virtual ITimer { 15 | public: 16 | BasicTimer(); 17 | 18 | std::chrono::milliseconds delta() const override; 19 | double deltaFloatSeconds() const override; 20 | bool isFirstUpdate() const override; 21 | 22 | void update() override; 23 | 24 | protected: 25 | std::chrono::system_clock::time_point _lastUpdateTime; 26 | bool _isFirstUpdate; 27 | }; 28 | 29 | 30 | #endif //RECAST_BASICTIMER_H 31 | -------------------------------------------------------------------------------- /src/headers/models/User.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file PlayerAuth.h 3 | * @author LionZXY 4 | * @project Recast-server 5 | * @date 17.06.17 6 | * @email nikita@kulikof.ru 7 | **/ 8 | #ifndef RECAST_SERVER_PLAYERAUTH_H 9 | #define RECAST_SERVER_PLAYERAUTH_H 10 | 11 | #include 12 | #include 13 | #include "Player.hpp" 14 | 15 | /** 16 | * @brief User - technical data of a player (login, password and other) 17 | */ 18 | struct User { 19 | public: 20 | int id; 21 | int playerId; 22 | std::string login; 23 | std::string password; 24 | std::shared_ptr player; 25 | 26 | User() {} 27 | 28 | User(std::string login, std::string password) : login(login), password(password) {} 29 | 30 | }; 31 | 32 | 33 | #endif //RECAST_SERVER_PLAYERAUTH_H 34 | -------------------------------------------------------------------------------- /src/headers/temperature-world/utils/FileUtils.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Oleg Morozenkov on 02.06.17. 3 | // 4 | 5 | #ifndef RECAST_FILEUTILS_H 6 | #define RECAST_FILEUTILS_H 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | /** 13 | * Collection of functions which work with files. 14 | */ 15 | namespace FileUtils { 16 | 17 | /** 18 | * Reads all file contents to a string. 19 | * 20 | * @param fileName Path of file 21 | * @return File contents 22 | */ 23 | inline std::string readFile(const std::string& fileName) { 24 | std::ifstream file(fileName); 25 | std::ostringstream output; 26 | output << file.rdbuf(); 27 | return output.str(); 28 | } 29 | 30 | } 31 | 32 | #endif //RECAST_FILEUTILS_H 33 | -------------------------------------------------------------------------------- /libs/sqlite/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | PROJECT(sqlite3) 2 | cmake_minimum_required(VERSION 2.8) 3 | 4 | link_libraries(pthread) 5 | link_libraries(dl) 6 | 7 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}) 8 | add_library(sqlite3 STATIC src/sqlite3.c src/sqlite3.h src/sqlite3ext.h) 9 | add_executable(sqlite src/sqlite3.c src/shell.c src/sqlite3.h src/sqlite3ext.h) 10 | set_target_properties(sqlite PROPERTIES OUTPUT_NAME sqlite3) 11 | 12 | add_definitions(-DSQLITE_ENABLE_RTREE) 13 | add_definitions(-DSQLITE_ENABLE_FTS4) 14 | add_definitions(-DSQLITE_ENABLE_JSON1) 15 | 16 | target_link_libraries(sqlite3 ${CMAKE_DL_LIBS}) 17 | install(FILES src/sqlite3.h src/sqlite3ext.h DESTINATION include) 18 | install(TARGETS sqlite3 LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) 19 | install(TARGETS sqlite RUNTIME DESTINATION bin) 20 | -------------------------------------------------------------------------------- /src/headers/temperature-world/implementation/typedefs/GeneratableChunkedTemperatureWorldTypedefs.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Oleg Morozenkov on 19.06.17. 3 | // 4 | 5 | #ifndef RECAST_GENERATABLECHUNKEDTEMPERATUREWORLDTYPEDEFS_H 6 | #define RECAST_GENERATABLECHUNKEDTEMPERATUREWORLDTYPEDEFS_H 7 | 8 | #include 9 | #include 10 | #include "temperature-world/types/Coord.hpp" 11 | #include "temperature-world/interfaces/ITemperatureWorldBoundable.hpp" 12 | 13 | namespace GeneratableChunkedTemperatureWorldTypedefs { 14 | using NeedChunkFn = std::function; 15 | using MakeChunkFn = std::function>(Coord, Coord, Coord)>; 16 | }; 17 | 18 | 19 | #endif //RECAST_GENERATABLECHUNKEDTEMPERATUREWORLDTYPEDEFS_H 20 | -------------------------------------------------------------------------------- /src/temperature-world/implementation/BasicTimer.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Oleg Morozenkov on 11.06.17. 3 | // 4 | 5 | #include "temperature-world/implementation/BasicTimer.hpp" 6 | 7 | using namespace std; 8 | using namespace std::chrono; 9 | 10 | BasicTimer::BasicTimer() : _lastUpdateTime(system_clock::now()), _isFirstUpdate(true) { 11 | } 12 | 13 | chrono::milliseconds BasicTimer::delta() const { 14 | return duration_cast(system_clock::now() - _lastUpdateTime); 15 | } 16 | 17 | double BasicTimer::deltaFloatSeconds() const { 18 | return delta().count() / 1000.0; 19 | } 20 | 21 | void BasicTimer::update() { 22 | _lastUpdateTime = system_clock::now(); 23 | _isFirstUpdate = false; 24 | } 25 | 26 | bool BasicTimer::isFirstUpdate() const { 27 | return _isFirstUpdate; 28 | } 29 | -------------------------------------------------------------------------------- /src/headers/threads/InputThread.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file InputThread.h 3 | * @brief Thread for command file 4 | * @author LionZXY 5 | * @project Recast-server 6 | * @date 12.06.17 7 | * @email nikita@kulikof.ru 8 | * 9 | * Execute console commands in background. 10 | * 11 | **/ 12 | #ifndef RECAST_SERVER_INPUTTHREAD_H 13 | #define RECAST_SERVER_INPUTTHREAD_H 14 | 15 | #include "commands/CommandManager.hpp" 16 | 17 | class Server; 18 | 19 | class InputThread { 20 | public: 21 | InputThread(InputThread &&thr1) { server = thr1.server; } 22 | 23 | InputThread(Server *srv); 24 | 25 | void init(); 26 | 27 | CommandManager *getManager() { return &manager; } 28 | 29 | private: 30 | Server *server; 31 | CommandManager manager; 32 | }; 33 | 34 | 35 | #endif //RECAST_SERVER_INPUTTHREAD_H 36 | -------------------------------------------------------------------------------- /src/threads/InputThread.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file InputThread.cpp 3 | * @brief Input thread for execution of terminal command 4 | * @author LionZXY 5 | * @project Recast-server 6 | * @date 12.06.17 7 | * @email nikita@kulikof.ru 8 | * 9 | * Execute background command 10 | * 11 | **/ 12 | 13 | #include 14 | #include 15 | #include 16 | #include "threads/InputThread.hpp" 17 | #include "Server.hpp" 18 | 19 | using namespace std; 20 | 21 | InputThread::InputThread(Server *srv) { 22 | server = srv; 23 | BOOST_LOG_TRIVIAL(info) << "Input thread is running..."; 24 | } 25 | 26 | void InputThread::init() { 27 | while (server->isRunning()) { 28 | string cmd = ""; 29 | getline(cin, cmd); 30 | manager.onCommand(server, cmd); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/headers/spells/events/HeatEvent.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file HeatEvent.h 3 | * @author LionZXY 4 | * @project Recast-server 5 | * @date 21.06.17 6 | * @email nikita@kulikof.ru 7 | **/ 8 | #ifndef RECAST_SERVER_HEATEVENT_H 9 | #define RECAST_SERVER_HEATEVENT_H 10 | 11 | #include 12 | #include "IEvent.hpp" 13 | 14 | class HeatEvent : public IEvent { 15 | public: 16 | HeatEvent(SpellNode *node, float temp) : IEvent(node), temp(temp) {}; 17 | 18 | static float getTempFromEnergy(float energyEjection) { 19 | return Config::g("spell.heater.temp_per_energy", 1) * energyEjection; 20 | } 21 | 22 | void commit(Box2DWorld *world, SpellEntity *entity, std::shared_ptr tempWorld); 23 | 24 | private: 25 | float temp; 26 | 27 | }; 28 | 29 | 30 | #endif //RECAST_SERVER_HEATEVENT_H 31 | -------------------------------------------------------------------------------- /src/spell/nodes/HeaterNode.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file HeaterNode.cpp 3 | * @author LionZXY 4 | * @project Recast-server 5 | * @date 24.06.17 6 | * @email nikita@kulikof.ru 7 | **/ 8 | #include 9 | #include "spells/nodes/HeaterNode.hpp" 10 | 11 | HeaterNode::HeaterNode(float x, float y, float z, float energy) : EnergyNode(NodeType::HEATER, x, y, z, energy) {} 12 | 13 | void HeaterNode::onTick(IEventListener &listener, SpellNode *callable) { 14 | float energyPerTickHeater = Config::g("spell.heater.per_tick_consumer", 10); 15 | if (energy > energyPerTickHeater) { 16 | HeatEvent event = HeatEvent(this, HeatEvent::getTempFromEnergy(energyPerTickHeater)); 17 | listener.onEvent(event); 18 | energy -= energyPerTickHeater; 19 | } 20 | EnergyNode::onTick(listener, callable); 21 | } 22 | 23 | -------------------------------------------------------------------------------- /src/spell/nodes/AimNode.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file AimNode.cpp 3 | * @author LionZXY 4 | * @project Recast-server 5 | * @date 25.06.17 6 | * @email nikita@kulikof.ru 7 | **/ 8 | #include 9 | #include "spells/nodes/AimNode.h" 10 | 11 | 12 | void AimNode::onTick(IEventListener &listener, SpellNode *callable) { 13 | float energyPerTickHeater = Config::g("spell.aim.per_tick_consumer", 10); 14 | if (energy > energyPerTickHeater) { 15 | MoveEvent event(this, entityId, energyPerTickHeater); 16 | listener.onEvent(event); 17 | energy -= energyPerTickHeater; 18 | } 19 | EnergyNode::onTick(listener, callable); 20 | } 21 | 22 | AimNode::AimNode(float x, float y, float z, float energy, 23 | int entityId) : EnergyNode(NodeType::AIM, x, y, z, energy), entityId(entityId) { 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/headers/spells/Spell.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file Spell.h 3 | * @author LionZXY 4 | * @project Recast-server 5 | * @date 21.06.17 6 | * @email nikita@kulikof.ru 7 | **/ 8 | #ifndef RECAST_SERVER_SPELL_H 9 | #define RECAST_SERVER_SPELL_H 10 | 11 | 12 | #include "spells/nodes/SpellNode.hpp" 13 | #include "spells/events/SpellEventListener.hpp" 14 | 15 | class Spell { 16 | public: 17 | Spell() : rootNode(new SpellNode(NodeType::USUALLY, 0, 0, 0)) {}; 18 | 19 | Spell(SpellNode *rootNode) : rootNode(rootNode) {}; 20 | 21 | ~Spell(); 22 | 23 | SpellNode *getRootNode() { return rootNode; } 24 | 25 | void tickSpell(SpellEventListener &listener); 26 | 27 | static void write(Parcel &in, Spell * obj); 28 | static Spell *read(Parcel &out); 29 | private: 30 | SpellNode *rootNode; 31 | }; 32 | 33 | 34 | #endif //RECAST_SERVER_SPELL_H 35 | -------------------------------------------------------------------------------- /src/headers/world/utils/CollectEntity.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file CollectEntity.h 3 | * @author LionZXY 4 | * @project Recast-server 5 | * @date 25.06.17 6 | * @email nikita@kulikof.ru 7 | **/ 8 | #ifndef RECAST_SERVER_COLLECTENTITY_H 9 | #define RECAST_SERVER_COLLECTENTITY_H 10 | 11 | #include 12 | #include 13 | #include "world/wrappers/Entity.h" 14 | 15 | class CollectEntity : public b2QueryCallback { 16 | public: 17 | bool ReportFixture(b2Fixture *fixture) { 18 | b2Body *body = fixture->GetBody(); 19 | if (body->GetType() == b2_dynamicBody) 20 | entitys.push_back(Entity(fixture)); 21 | 22 | return true; 23 | } 24 | 25 | std::vector getEntitys() const { return entitys; } 26 | 27 | private: 28 | std::vector entitys; 29 | }; 30 | 31 | 32 | #endif //RECAST_SERVER_COLLECTENTITY_H 33 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM gcc:latest 2 | 3 | # If host is running squid-deb-proxy on port 8000, populate /etc/apt/apt.conf.d/30proxy 4 | # By default, squid-deb-proxy 403s unknown sources, so apt shouldn't proxy ppa.launchpad.net 5 | RUN route -n | awk '/^0.0.0.0/ {print $2}' > /tmp/host_ip.txt 6 | RUN echo "HEAD /" | nc `cat /tmp/host_ip.txt` 8000 | grep squid-deb-proxy \ 7 | && (echo "Acquire::http::Proxy \"http://$(cat /tmp/host_ip.txt):8000\";" > /etc/apt/apt.conf.d/30proxy) \ 8 | && (echo "Acquire::http::Proxy::ppa.launchpad.net DIRECT;" >> /etc/apt/apt.conf.d/30proxy) \ 9 | || echo "No squid-deb-proxy detected on docker host" 10 | 11 | RUN apt-get -qq update && apt-get -qq upgrade && apt-get -qqy install cmake libboost-all-dev sqlite3 12 | 13 | WORKDIR /tmp/recast 14 | RUN rm -rf /tmp/recast/* 15 | COPY . . 16 | 17 | RUN mkdir build && cd build && cmake .. && make -j$(nproc) -------------------------------------------------------------------------------- /src/core/utils/Utils.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file Utils.cpp 3 | * @brief Utils file 4 | * @author LionZXY 5 | * @project Recast-server 6 | * @date 16.06.17 7 | * @email nikita@kulikof.ru 8 | * 9 | * Misc methods 10 | * 11 | **/ 12 | #include "utils/Utils.hpp" 13 | #include 14 | 15 | using namespace std; 16 | 17 | static const char ALPHANUM[] = 18 | "0123456789" 19 | "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 20 | "abcdefghijklmnopqrstuvwxyz"; 21 | /** 22 | * Return random string that contains symbols [0-9A-Za-z] 23 | * 24 | * @param len of string 25 | * @return std::string 26 | */ 27 | string genRandomString(const size_t len) { 28 | string randStr; 29 | randStr.reserve(len); 30 | 31 | for (int i = 0; i < len; ++i) { 32 | randStr.push_back(ALPHANUM[rand() % (sizeof(ALPHANUM) - 1)]); 33 | } 34 | 35 | return randStr; 36 | } 37 | -------------------------------------------------------------------------------- /test/temperature-world/demo-web/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | world-with-temperature-demo 6 | 27 | 28 | 29 | 30 | 31 | 32 | 33 |
Info
34 | 35 | 36 | -------------------------------------------------------------------------------- /src/spell/events/HeatEvent.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file HeatEvent.cpp 3 | * @author LionZXY 4 | * @project Recast-server 5 | * @date 27.06.17 6 | * @email nikita@kulikof.ru 7 | **/ 8 | #include "spells/events/HeatEvent.hpp" 9 | #include "world/wrappers/SpellEntity.h" 10 | #include "spells/nodes/SpellNode.hpp" 11 | 12 | void HeatEvent::commit(Box2DWorld *world, SpellEntity *entity, std::shared_ptr tempWorld) { 13 | float per_real_metr = Config::g("spell.general.per_real", 0.001f); 14 | b2Vec2 loc = entity->getFixture()->GetBody()->GetPosition(); 15 | Coord newX((int) (loc.x + getNode()->getX() * per_real_metr)); 16 | Coord newY((int) (loc.y + getNode()->getY() * per_real_metr)); 17 | Coord newZ((int) (getNode()->getZ() * per_real_metr)); 18 | 19 | tempWorld->set(newX, newY, newZ, Temperature(tempWorld->get(newX, newY, newZ) + temp)); 20 | entity->setType(EntityType::FIREBALL); 21 | } 22 | -------------------------------------------------------------------------------- /src/headers/world/wrappers/Entity.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file Entity.h 3 | * @author LionZXY 4 | * @project Recast-server 5 | * @date 25.06.17 6 | * @email nikita@kulikof.ru 7 | **/ 8 | #ifndef RECAST_SERVER_ENTITY_H 9 | #define RECAST_SERVER_ENTITY_H 10 | 11 | #include 12 | #include "EntityData.h" 13 | #include "EntityType.h" 14 | 15 | class EntityData; 16 | 17 | class b2Fixture; 18 | 19 | class Box2DWorld; 20 | 21 | class Entity { 22 | public: 23 | Entity(b2Fixture *fixture1); 24 | 25 | int getId(); 26 | 27 | virtual void update(Box2DWorld *box2DWorld) {} 28 | 29 | b2Fixture *getFixture() const { return fixture; } 30 | 31 | static void write(Parcel &in, Entity *obj); 32 | 33 | EntityType getType() const; 34 | 35 | void setType(EntityType type); 36 | 37 | private: 38 | b2Fixture *fixture; 39 | EntityData *data; 40 | }; 41 | 42 | 43 | #endif //RECAST_SERVER_ENTITY_H 44 | -------------------------------------------------------------------------------- /src/headers/io/network/NetworkUtils.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file NetworkUtils.hpp 3 | * @brief Basic networking utils header file 4 | * @author StealthTech 5 | * @project Recast-server 6 | * @date 17.06.17 7 | * @email st3althtech@mail.ru 8 | * 9 | **/ 10 | 11 | #ifndef RECAST_NETWORK_UTILS_HPP 12 | #define RECAST_NETWORK_UTILS_HPP 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include // socket(), AF_INET/PF_INET 19 | #include // struct sockaddr_in 20 | #include // inet_aton() 21 | #include // gethostbyname 22 | #include 23 | #include 24 | 25 | using namespace std; 26 | 27 | const int DEFAULT_PORT_TCP = 1337; 28 | const int DEFAULT_PORT_UDP = 1338; 29 | 30 | string int2ipv4(uint32_t ip); 31 | struct sockaddr_in resolve(const char* host, int port); 32 | 33 | #endif //RECAST_NETWORK_UTILS_HPP 34 | -------------------------------------------------------------------------------- /src/headers/io/network/Socket.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file Socket.hpp 3 | * @brief Socket abstract utils header file 4 | * @author StealthTech 5 | * @project Recast-server 6 | * @date 27.06.17 7 | * @email st3althtech@mail.ru 8 | * 9 | **/ 10 | 11 | #ifndef RECAST_SERVER_SOCKET_HPP 12 | #define RECAST_SERVER_SOCKET_HPP 13 | 14 | #include "NetworkUtils.hpp" 15 | 16 | class Socket { 17 | public: 18 | Socket() : socketDescr(-1), socketBoundPort(0) {} 19 | Socket(int sd) : socketDescr(sd), socketBoundPort(0) {} 20 | ~Socket() { if (socketDescr > 0) ::close(socketDescr); } 21 | public: 22 | int getSocketDescr() const noexcept { return socketDescr; } 23 | void setNonBlocked(bool option); 24 | void close() { ::close(socketDescr); } 25 | virtual void createServerSocket() = 0; 26 | protected: 27 | void setReuseAddress(int sd); 28 | int socketDescr; 29 | uint32_t socketBoundPort; 30 | }; 31 | 32 | #endif //RECAST_SERVER_SOCKET_HPP 33 | -------------------------------------------------------------------------------- /src/headers/temperature-world/interfaces/ITimer.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Oleg Morozenkov on 31.05.17. 3 | // 4 | 5 | #ifndef RECAST_ITIMER_H 6 | #define RECAST_ITIMER_H 7 | 8 | 9 | #include 10 | 11 | /** 12 | * Interface. 13 | * Measures time. 14 | */ 15 | class ITimer { 16 | public: 17 | virtual ~ITimer() noexcept = default; 18 | 19 | /** 20 | * @return Time from last update in milliseconds. 21 | */ 22 | virtual std::chrono::milliseconds delta() const = 0; 23 | 24 | /** 25 | * @return Time from last update in float-number seconds. 26 | */ 27 | virtual double deltaFloatSeconds() const = 0; 28 | 29 | /** 30 | * @return True if timer was never updated. 31 | */ 32 | virtual bool isFirstUpdate() const = 0; 33 | 34 | /** 35 | * Saves update, saves the "tick". It will influence value of `delta`. 36 | */ 37 | virtual void update() = 0; 38 | }; 39 | 40 | 41 | #endif //RECAST_ITIMER_H 42 | -------------------------------------------------------------------------------- /src/headers/utils/DelayCommand.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file DelayCommand.h 3 | * @author LionZXY 4 | * @project Recast-server 5 | * @date 26.06.17 6 | * @email nikita@kulikof.ru 7 | **/ 8 | #ifndef RECAST_SERVER_DELAYCOMMAND_H 9 | #define RECAST_SERVER_DELAYCOMMAND_H 10 | 11 | #include 12 | #include 13 | 14 | class ICommandSender; 15 | 16 | class DelayCommand { 17 | public: 18 | DelayCommand() {} 19 | 20 | DelayCommand(ICommandSender *sender, std::shared_ptr command, std::string cmd, 21 | std::vector args) : sender( 22 | sender), command(command), cmd(cmd), args(args) {} 23 | 24 | void execute() { 25 | command->onCommand(*sender, cmd, args); 26 | } 27 | 28 | private: 29 | ICommandSender *sender; 30 | std::shared_ptr command; 31 | std::string cmd; 32 | std::vector args; 33 | }; 34 | 35 | 36 | #endif //RECAST_SERVER_DELAYCOMMAND_H 37 | -------------------------------------------------------------------------------- /src/headers/temperature-world/interfaces/ITimerBlockable.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Oleg Morozenkov on 31.05.17. 3 | // 4 | 5 | #ifndef RECAST_ILIMITINGTIMER_H 6 | #define RECAST_ILIMITINGTIMER_H 7 | 8 | 9 | #include "ITimer.hpp" 10 | 11 | /** 12 | * Should not be derived directly. Use `ITimerBlockable`. 13 | * This class is useful for `dynamic_cast`. 14 | */ 15 | class ITimerBlockableMixin { 16 | public: 17 | /** 18 | * @return Minimum possible value of `delta`. 19 | */ 20 | virtual std::chrono::milliseconds minDelta() const = 0; 21 | 22 | /** 23 | * Blocks until `delta` >= `minDelta`. 24 | */ 25 | virtual void wait() = 0; 26 | }; 27 | 28 | /** 29 | * Mixin to timer. 30 | * Makes timer to have method that block client, so the `delta` won't be less than `minDelta`. 31 | */ 32 | template 33 | class ITimerBlockable : public virtual T, public virtual ITimerBlockableMixin { 34 | }; 35 | 36 | 37 | #endif //RECAST_ILIMITINGTIMER_H 38 | -------------------------------------------------------------------------------- /src/headers/spells/events/SpellEventListener.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file SpellEventListener.h 3 | * @author LionZXY 4 | * @project Recast-server 5 | * @date 24.06.17 6 | * @email nikita@kulikof.ru 7 | **/ 8 | #ifndef RECAST_SERVER_SPELLEVENTLISTENER_H 9 | #define RECAST_SERVER_SPELLEVENTLISTENER_H 10 | 11 | #include 12 | #include "IEventListener.hpp" 13 | 14 | class Spell; 15 | 16 | class SpellEntity; 17 | 18 | class SpellEventListener : public IEventListener { 19 | public: 20 | SpellEventListener(Spell *spell, SpellEntity *entity, Box2DWorld *world, std::shared_ptr tempWorld) 21 | : spell(spell), 22 | entity(entity), 23 | world(world), 24 | tempWorld(tempWorld) {} 25 | 26 | void onEvent(IEvent &event); 27 | 28 | private: 29 | Spell *spell; 30 | SpellEntity *entity; 31 | Box2DWorld *world; 32 | std::shared_ptr tempWorld; 33 | }; 34 | 35 | 36 | #endif //RECAST_SERVER_SPELLEVENTLISTENER_H 37 | -------------------------------------------------------------------------------- /test/temperature-world/performance.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Oleg Morozenkov on 30.03.17. 3 | // 4 | 5 | #include "temperature-world/implementation/BasicTimer.hpp" 6 | #include "temperature-world/types/Parallelepiped.hpp" 7 | #include "temperature-world/injectors/BoundTemperatureWorldInjector.hpp" 8 | 9 | #include 10 | 11 | using namespace std; 12 | 13 | int main() { 14 | Size n = 99; 15 | Parallelepiped worldBounds(n, n, n); 16 | 17 | BoundTemperatureWorldInjector injector; 18 | injector.setWorldBounds(worldBounds); 19 | 20 | auto world = injector.world(); 21 | auto updater = injector.updater(); 22 | 23 | BasicTimer benchmarkTimer; 24 | cout << "Number of blocks: " << world->bounds().volume() << endl; 25 | for (size_t i = 0; i < 5; i++) { 26 | benchmarkTimer.update(); 27 | 28 | updater->update(); 29 | 30 | cout << "Update delta: " << benchmarkTimer.deltaFloatSeconds() << "s" << endl; 31 | } 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /src/headers/temperature-world/types/Point.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Oleg Morozenkov on 18.06.17. 3 | // 4 | 5 | #ifndef RECAST_POINT_H 6 | #define RECAST_POINT_H 7 | 8 | 9 | #include "Coord.hpp" 10 | 11 | /** 12 | * Type. 13 | * Represents point in three-dimensional space. 14 | */ 15 | struct Point { 16 | public: 17 | Point(Coord x, Coord y, Coord z) : _x(x), _y(y), _z(z) { 18 | } 19 | 20 | inline Coord x() const noexcept { 21 | return _x; 22 | } 23 | 24 | inline Coord y() const noexcept { 25 | return _y; 26 | } 27 | 28 | inline Coord z() const noexcept { 29 | return _z; 30 | } 31 | 32 | inline bool operator==(const Point& other) const noexcept { 33 | return _x == other._x && _y == other._y && _z == other._z; 34 | } 35 | 36 | inline bool operator!=(const Point& other) const noexcept { 37 | return !(*this == other); 38 | } 39 | 40 | protected: 41 | Coord _x, _y, _z; 42 | }; 43 | 44 | #endif //RECAST_POINT_H 45 | -------------------------------------------------------------------------------- /src/headers/spells/nodes/EnergyNode.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file EnergyNode.h 3 | * @author LionZXY 4 | * @project Recast-server 5 | * @date 20.06.17 6 | * @email nikita@kulikof.ru 7 | **/ 8 | #ifndef RECAST_SERVER_ENERGYNODE_H 9 | #define RECAST_SERVER_ENERGYNODE_H 10 | 11 | #include "io/configs/Config.hpp" 12 | #include "SpellNode.hpp" 13 | 14 | class EnergyNode : public SpellNode { 15 | public: 16 | EnergyNode(float x, float y, float z, float energy) : SpellNode(NodeType::ENERGY, x, y, z), energy(energy) {} 17 | 18 | EnergyNode(NodeType type, float x, float y, float z, float energy) : SpellNode(type, x, y, z), energy(energy) {} 19 | 20 | virtual bool isEnergyNode() { return true; } 21 | 22 | inline float getEnergy() const { return energy; } 23 | 24 | virtual float transferEnergy(SpellNode *from, float count); 25 | 26 | protected: 27 | float energy = 0; 28 | 29 | virtual void onTick(IEventListener &listener, SpellNode *callable); 30 | }; 31 | 32 | 33 | #endif //RECAST_SERVER_ENERGYNODE_H 34 | -------------------------------------------------------------------------------- /src/headers/temperature-world/interfaces/ITemperatureWorldScalable.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Oleg Morozenkov on 18.06.17. 3 | // 4 | 5 | #ifndef RECAST_ISCALABLETEMPERATUREWORLD_H 6 | #define RECAST_ISCALABLETEMPERATUREWORLD_H 7 | 8 | 9 | #include "../types/IntScaleParallelepiped.hpp" 10 | 11 | /** 12 | * Should not be derived directly. Use `ITemperatureWorldScalableScalable`. 13 | * This class is useful for `dynamic_cast`. 14 | */ 15 | class ITemperatureWorldScalableMixin { 16 | public: 17 | /** 18 | * @return Scale of each cell in three dimensions. 19 | */ 20 | virtual IntScaleParallelepiped cellScale() const noexcept = 0; 21 | }; 22 | 23 | /** 24 | * Mixin to temperature world. 25 | * Makes temperature world to have scale of cells. 26 | * 27 | * @tparam T Base temperature world class. 28 | */ 29 | template 30 | class ITemperatureWorldScalable : public virtual T, public virtual ITemperatureWorldScalableMixin { 31 | }; 32 | 33 | 34 | #endif //RECAST_ISCALABLETEMPERATUREWORLD_H 35 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: cpp 2 | 3 | sudo: true 4 | 5 | # Blacklist 6 | branches: 7 | only: 8 | - master 9 | except: 10 | - gh-pages 11 | 12 | # Environment variables 13 | env: 14 | global: 15 | - GH_REPO_NAME: Recast 16 | - DOXYFILE: $TRAVIS_BUILD_DIR/doxyfile 17 | - GH_REPO_REF: github.com/LionZXY/Recast.git 18 | 19 | # Install dependencies 20 | addons: 21 | apt: 22 | sources: 23 | - george-edison55-precise-backports # cmake 3.2.3 / doxygen 1.8.3 24 | packages: 25 | - doxygen 26 | - doxygen-doc 27 | - doxygen-latex 28 | - doxygen-gui 29 | - graphviz 30 | - cmake 31 | - cmake-data 32 | 33 | services: 34 | - docker 35 | script: 36 | - docker build -t lionzxy/recast . 37 | - docker run lionzxy/recast 38 | 39 | # Generate and deploy documentation 40 | after_success: 41 | - cd $TRAVIS_BUILD_DIR 42 | - chmod +x generateDocumentationAndDeploy.sh 43 | - 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then bash ./generateDocumentationAndDeploy.sh; fi' 44 | -------------------------------------------------------------------------------- /src/headers/models/Player.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief Player file 4 | * @author LionZXY 5 | * @project Recast-server 6 | * @date 08.06.17 7 | * 8 | * Player file 9 | * 10 | **/ 11 | #ifndef RECAST_SERVER_PLAYER_H 12 | #define RECAST_SERVER_PLAYER_H 13 | 14 | #include "Point.hpp" 15 | 16 | /** 17 | * @brief Player class. XP, Life points and other 18 | */ 19 | struct Player { 20 | public: 21 | Player() : location(Point(0, 0, 0)) {}; 22 | 23 | Player(Point location) : location(location) {}; 24 | 25 | int id; 26 | int userId; 27 | 28 | const double &getPosX() const { return location.x; } 29 | void setPosX(double x) { location.x = x; } 30 | const double &getPosY() const { return location.y; } 31 | void setPosY(double y) { location.y = y; } 32 | const double &getPosZ() const { return location.z; } 33 | void setPosZ(double z) { location.z = z; } 34 | const Point &getPoint() { return location; } 35 | private: 36 | Point location; 37 | }; 38 | 39 | 40 | #endif //RECAST_SERVER_PLAYER_H 41 | -------------------------------------------------------------------------------- /src/core/io/network/listeners/GetEntitys.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file GetEntitys.cpp 3 | * @author LionZXY 4 | * @project Recast-server 5 | * @date 28.06.17 6 | * @email nikita@kulikof.ru 7 | **/ 8 | #include 9 | #include "io/network/listeners/GetEntitys.h" 10 | #include "world/Box2DWorld.h" 11 | 12 | GetEntitys::GetEntitys() : NetworkListener(1) {} 13 | 14 | float readFloat(char *request, int &curPos) { 15 | float f; 16 | memcpy(&f, request + curPos, sizeof(f)); 17 | curPos += sizeof(f); 18 | return f; 19 | } 20 | 21 | using namespace std; 22 | 23 | char *GetEntitys::onPacket(char *request, ICommandSender *sender) { 24 | int curPos = 1; 25 | float start = readFloat(request, curPos); 26 | float end = readFloat(request, curPos); 27 | auto v = sender->getWorld()->getAllEntityInChunk(start, end); 28 | Parcel answer; 29 | answer.put((int) v.size()); 30 | for (Entity en : v) { 31 | Entity::write(answer, &en); 32 | } 33 | return (char *) answer.getVector()->data(); 34 | } 35 | -------------------------------------------------------------------------------- /src/world/wrappers/Entity.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file Entity.cpp 3 | * @author LionZXY 4 | * @project Recast-server 5 | * @date 25.06.17 6 | * @email nikita@kulikof.ru 7 | **/ 8 | #include 9 | #include 10 | #include "world/wrappers/Entity.h" 11 | 12 | int Entity::getId() { 13 | if (data != NULL) 14 | return data->id; 15 | else return -1; 16 | } 17 | 18 | Entity::Entity(b2Fixture *fixture1) : fixture(fixture1) { 19 | data = (EntityData *) fixture->GetBody()->GetUserData(); 20 | } 21 | 22 | void Entity::write(Parcel &in, Entity *obj) { 23 | in.put(obj->getType()); 24 | in.put(obj->getId()); 25 | b2Vec2 pos = obj->getFixture()->GetBody()->GetPosition(); 26 | in.put(pos.x); 27 | in.put(pos.y); 28 | } 29 | 30 | EntityType Entity::getType() const { 31 | if (data == NULL) 32 | return EntityType::UNKN; 33 | return data->type; 34 | } 35 | 36 | void Entity::setType(EntityType type) { 37 | if (data == NULL) 38 | return; 39 | else data->type = type; 40 | } 41 | -------------------------------------------------------------------------------- /src/headers/io/network/SocketUDP.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file SocketUDP.hpp 3 | * @brief Socket (UDP) utils header file 4 | * @author StealthTech 5 | * @project Recast-server 6 | * @date 27.06.17 7 | * @email st3althtech@mail.ru 8 | * 9 | **/ 10 | 11 | #ifndef RECAST_SERVER_SOCKET_UDP_HPP 12 | #define RECAST_SERVER_SOCKET_UDP_HPP 13 | 14 | #include "NetworkUtils.hpp" 15 | #include "Socket.hpp" 16 | 17 | class SocketUDP : public Socket { 18 | public: 19 | using Socket::Socket; 20 | SocketUDP(uint32_t port) : Socket::Socket() { 21 | socketBoundPort = port; 22 | createServerSocket(); 23 | } 24 | public: 25 | void createServerSocket() override; 26 | void createServerSocket(uint32_t port); 27 | void sendTo(struct sockaddr_in &sendToAddr, const string &str); 28 | string recvFrom(struct sockaddr_in &recvFromAddr); 29 | 30 | void sendBytesTo(struct sockaddr_in &sendToAddr, const char *data, size_t num); 31 | char* recvBytesFrom(struct sockaddr_in &recvFromAddr); 32 | }; 33 | 34 | #endif //RECAST_SERVER_SOCKET_UDP_HPP 35 | -------------------------------------------------------------------------------- /src/headers/temperature-world/utils/TimeUtils.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Oleg Morozenkov on 08.05.17. 3 | // 4 | 5 | #ifndef RECAST_TIMEUTILS_H 6 | #define RECAST_TIMEUTILS_H 7 | 8 | 9 | #include 10 | 11 | /** 12 | * Collection of functions which work with time. 13 | */ 14 | namespace TimeUtils { 15 | 16 | /** 17 | * Gets current time since Epoch in milliseconds. 18 | * 19 | * @return Milliseconds since Epoch. 20 | */ 21 | inline long long int currentTimeMillis() { 22 | const auto now = std::chrono::system_clock::now(); 23 | const auto duration = now.time_since_epoch(); 24 | const auto millis = std::chrono::duration_cast(duration).count(); 25 | return millis; 26 | } 27 | 28 | /** 29 | * Gets current time since Epoch in seconds. 30 | * 31 | * @return Seconds since Epoch. 32 | */ 33 | inline double currentTimeSeconds() { 34 | return (double) currentTimeMillis() / 1000; 35 | } 36 | 37 | }; 38 | 39 | #endif //RECAST_TIMEUTILS_H 40 | -------------------------------------------------------------------------------- /src/headers/temperature-world/utils/MathUtils.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Oleg Morozenkov on 03.04.17. 3 | // 4 | 5 | #ifndef RECAST_MATHUTILS_H 6 | #define RECAST_MATHUTILS_H 7 | 8 | 9 | #include 10 | #include 11 | 12 | /** 13 | * Collection of functions which work with numbers. 14 | */ 15 | namespace MathUtils { 16 | 17 | /** 18 | * Makes value `a` to be more "similar" to value `b` by factor `t`. 19 | * 20 | * @tparam T Any number, e.g. `double`. 21 | * @param a First value. 22 | * @param b Second Value. 23 | * @param t Factor. 24 | * @return Linear interpolated value. 25 | */ 26 | template 27 | inline T lerp(T a, T b, double t) { 28 | return T((1 - t) * a + t * b); 29 | } 30 | 31 | /** 32 | * Generates random value between 0.0 and 1.0. 33 | * 34 | * @return Random value between 0.0 and 1.0. 35 | */ 36 | inline double randomFloat() { 37 | return (double) rand() / RAND_MAX; 38 | } 39 | 40 | }; 41 | 42 | 43 | #endif //RECAST_MATHUTILS_H 44 | -------------------------------------------------------------------------------- /src/headers/temperature-world/implementation/SynchronizedBlockingTimer.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Oleg Morozenkov on 31.05.17. 3 | // 4 | 5 | #ifndef RECAST_BLOCKINGTIMER_H 6 | #define RECAST_BLOCKINGTIMER_H 7 | 8 | 9 | #include 10 | #include "temperature-world/interfaces/ITimerBlockable.hpp" 11 | 12 | /** 13 | * Implementation of blocking timer. 14 | */ 15 | class SynchronizedBlockingTimer : public virtual ITimerBlockable { 16 | public: 17 | SynchronizedBlockingTimer(std::chrono::milliseconds minDelta); 18 | 19 | std::chrono::milliseconds delta() const override; 20 | std::chrono::milliseconds minDelta() const override; 21 | double deltaFloatSeconds() const override; 22 | bool isFirstUpdate() const override; 23 | 24 | void update() override; 25 | void wait() override; 26 | 27 | protected: 28 | std::chrono::milliseconds _minDelta; 29 | 30 | std::chrono::system_clock::time_point _lastUpdateTime; 31 | mutable std::mutex _lastUpdateTimeMutex; 32 | 33 | bool _isFirstUpdate; 34 | }; 35 | 36 | 37 | #endif //RECAST_BLOCKINGTIMER_H 38 | -------------------------------------------------------------------------------- /src/headers/temperature-world/interfaces/ITemperatureWorldScalableMutable.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Oleg Morozenkov on 18.06.17. 3 | // 4 | 5 | #ifndef RECAST_ITEMPERATUREWORLDSCALABLEMUTABLE_H_H 6 | #define RECAST_ITEMPERATUREWORLDSCALABLEMUTABLE_H_H 7 | 8 | 9 | #include "../types/IntScale.hpp" 10 | 11 | /** 12 | * Should not be derived directly. Use `ITemperatureWorldScalableMutable`. 13 | * This class is useful for `dynamic_cast`. 14 | */ 15 | class ITemperatureWorldScalableMutableMixin { 16 | public: 17 | /** 18 | * Sets scale of each cell. 19 | * 20 | * @param scale Scale in three dimensions. 21 | */ 22 | virtual void setCellScale(IntScaleParallelepiped scale) = 0; 23 | }; 24 | 25 | /** 26 | * Mixin to temperature world. 27 | * Makes temperature world to set scale of cells. 28 | * 29 | * @tparam T Base temperature world class. 30 | */ 31 | template 32 | class ITemperatureWorldScalableMutable : public virtual T, public virtual ITemperatureWorldScalableMutableMixin { 33 | }; 34 | 35 | 36 | #endif //RECAST_ITEMPERATUREWORLDSCALABLEMUTABLE_H_H 37 | -------------------------------------------------------------------------------- /src/core/io/network/Socket.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file Socket.cpp 3 | * @brief Socket abstract utils header file 4 | * @author StealthTech 5 | * @project Recast-server 6 | * @date 27.06.17 7 | * @email st3althtech@mail.ru 8 | * 9 | **/ 10 | 11 | #include 12 | #include "io/network/Socket.hpp" 13 | using namespace std; 14 | 15 | void setNonBlockedImpl(int sd, bool option) noexcept (false) { 16 | int flags = fcntl(sd, F_GETFL, 0); 17 | int new_flags = (option)? (flags | O_NONBLOCK) : (flags & ~O_NONBLOCK); 18 | if (fcntl(sd, F_SETFL, new_flags) == -1) { 19 | throw runtime_error("An exception occurred (make non-blocked): " + string(strerror(errno))); 20 | } 21 | } 22 | 23 | void Socket::setNonBlocked(bool option) noexcept (false) { 24 | setNonBlockedImpl(socketDescr, option); 25 | } 26 | 27 | void Socket::setReuseAddress(int sd) noexcept (false) { 28 | int yes = 1; 29 | if (setsockopt(sd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) == -1) { 30 | ::close(sd); 31 | throw runtime_error("An exception occurred (setopt reuse): " + string(strerror(errno))); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /test/temperature-world/performance-multichunk.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Oleg Morozenkov on 30.03.17. 3 | // 4 | 5 | #include "temperature-world/implementation/BasicTimer.hpp" 6 | #include "temperature-world/types/Parallelepiped.hpp" 7 | #include "temperature-world/injectors/ScalingGeneratableChunkedTemperatureWorldInjector.hpp" 8 | 9 | #include 10 | 11 | using namespace std; 12 | 13 | int main() { 14 | ScalingGeneratableChunkedTemperatureWorldInjector injector; 15 | injector.setChunkBounds(Parallelepiped(32, 32, 8)); 16 | 17 | auto world = injector.world(); 18 | auto updater = injector.updater(); 19 | 20 | for (int ix = -4; ix < 4; ix++) { 21 | for (int iy = -4; iy < 4; iy++) { 22 | world->getOrGenerateChunk(ix * injector.chunkBounds().sizeX() + 1, iy * injector.chunkBounds().sizeY() + 1, 0); 23 | } 24 | } 25 | 26 | BasicTimer benchmarkTimer; 27 | for (size_t i = 0; i < 5; i++) { 28 | benchmarkTimer.update(); 29 | 30 | updater->update(); 31 | 32 | cout << "Update delta: " << benchmarkTimer.deltaFloatSeconds() << "s" << endl; 33 | } 34 | 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /src/headers/io/network/NetworkListener.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file networking.cpp 3 | * @brief Network Listener abstract utils header file 4 | * @author StealthTech 5 | * @project Recast-server 6 | * @date 27.06.17 7 | * @email st3althtech@mail.ru 8 | * 9 | **/ 10 | 11 | #ifndef RECAST_SERVER_NETWORKLISTENER_HPP 12 | #define RECAST_SERVER_NETWORKLISTENER_HPP 13 | 14 | #include 15 | #include "io/network/Networking.hpp" 16 | #include "commands/ICommandSender.hpp" 17 | 18 | class NetworkListener { 19 | public: 20 | NetworkListener(int id) : listenerId(id) {} 21 | 22 | public: 23 | int getId() { return listenerId; } 24 | 25 | virtual char *onPacket(char *request, ICommandSender *sender) = 0; 26 | 27 | protected: 28 | int listenerId; 29 | }; 30 | 31 | class DebugNetworkListener : public NetworkListener { 32 | public: 33 | using NetworkListener::NetworkListener; 34 | public: 35 | char *onPacket(char *request, ICommandSender *sender) { 36 | sender->onMessage(std::string("Listener [") + std::to_string(listenerId) + "] got request " + request); 37 | return request; 38 | }; 39 | }; 40 | 41 | #endif //RECAST_SERVER_NETWORKLISTENER_HPP 42 | -------------------------------------------------------------------------------- /src/headers/commands/CommandManager.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief CommandManager file 4 | * @author LionZXY 5 | * @project Recast-server 6 | * @date 08.06.17 7 | * 8 | * Command manager file 9 | * 10 | **/ 11 | #ifndef RECAST_SERVER_COMMANDMANAGER_H 12 | #define RECAST_SERVER_COMMANDMANAGER_H 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include "utils/DelayCommand.h" 20 | 21 | class ICommandSender; 22 | 23 | class ICommand; 24 | 25 | /** 26 | * @brief Send string-command through CommandManager 27 | * 28 | * This is a very important class. Through this you can execute console-like text commands. 29 | */ 30 | class CommandManager { 31 | public: 32 | CommandManager(); 33 | 34 | CommandManager(const CommandManager &other) = delete; 35 | 36 | void onCommand(ICommandSender *sender, const std::string &cmd); 37 | 38 | void executeDelayedCommandInUI(); 39 | 40 | private: 41 | std::vector> commands; 42 | boost::lockfree::queue> delayedCommand; 43 | }; 44 | 45 | 46 | #endif //RECAST_SERVER_COMMANDMANAGER_H 47 | -------------------------------------------------------------------------------- /src/headers/io/network/SocketTCP.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file networking.cpp 3 | * @brief Socket (TCP) utils header file 4 | * @author StealthTech 5 | * @project Recast-server 6 | * @date 27.06.17 7 | * @email st3althtech@mail.ru 8 | * 9 | **/ 10 | 11 | #ifndef RECAST_SERVER_SOCKET_TCP_HPP 12 | #define RECAST_SERVER_SOCKET_TCP_HPP 13 | 14 | #include "NetworkUtils.hpp" 15 | #include "Socket.hpp" 16 | 17 | using namespace std; 18 | 19 | class SocketTCP : public Socket { 20 | public: 21 | using Socket::Socket; 22 | SocketTCP(uint32_t port, uint32_t queueSize) : Socket::Socket() { 23 | socketBoundPort = port; 24 | socketQueueSize = queueSize; 25 | createServerSocket(); 26 | } 27 | public: 28 | void setRecvTimeout(int seconds, int microseconds); 29 | void createServerSocket() override; 30 | void createServerSocket(uint32_t port, uint32_t queueSize); 31 | 32 | void send(const string &str); 33 | void sendBytes(const char *data, size_t num); 34 | string recv(); 35 | string recv(size_t bytes); 36 | string recvTimed(int timeout); 37 | char* recvBytes(size_t num); 38 | bool hasData(); 39 | shared_ptr accept(); 40 | private: 41 | uint32_t socketQueueSize; 42 | }; 43 | 44 | #endif //RECAST_SERVER_SOCKET_TCP_HPP 45 | -------------------------------------------------------------------------------- /src/core/io/SQLite.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file SQLite.cpp 3 | * @brief Nice case for sqlite_orm 4 | * @author LionZXY 5 | * @project Recast-server 6 | * @date 17.06.17 7 | * @email nikita@kulikof.ru 8 | * 9 | **/ 10 | #include 11 | #include "exceptions/InvalidLoginOrPassword.hpp" 12 | #include "io/SQLite.hpp" 13 | 14 | using namespace sqlite_orm; 15 | using namespace std; 16 | 17 | User SQLite::registerUser(string login, string password) { 18 | User user(login, password); 19 | user.id = storage.insert(user); 20 | 21 | Player player(Point(0, 0, 0)); 22 | player.userId = user.id; 23 | player.id = storage.insert(player); 24 | 25 | user.player = make_shared(player); 26 | user.playerId = player.id; 27 | storage.update(user); 28 | 29 | return user; 30 | } 31 | 32 | User SQLite::authUser(string login, string password) { 33 | auto users = storage.get_all(where(eq(&User::login, login) and eq(&User::password, password))); 34 | for (auto &user : users) { 35 | if (auto player = storage.get_no_throw(user.playerId)) { 36 | user.player = player; 37 | } 38 | return user; 39 | } 40 | throw InvalidLoginOrPassword(); 41 | } 42 | 43 | void SQLite::update(Player player) { 44 | storage.update(player); 45 | } 46 | -------------------------------------------------------------------------------- /src/spell/events/MoveEvent.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file MoveEvent.cpp 3 | * @author LionZXY 4 | * @project Recast-server 5 | * @date 25.06.17 6 | * @email nikita@kulikof.ru 7 | **/ 8 | #include 9 | #include "spells/events/MoveEvent.h" 10 | #include "world/wrappers/SpellEntity.h" 11 | 12 | float pSq(float var) { // Возведение в квадрат 13 | return var * var; 14 | } 15 | 16 | void MoveEvent::commit(Box2DWorld *world, SpellEntity * entity, std::shared_ptr tempWorld) { 17 | double k = Config::g("spell.event.move.density_k", 0.001); // Коэфициент сжатия силовой пружины 18 | Entity *target = world->getEntityById(entityId); 19 | if(target == NULL) 20 | return; 21 | 22 | b2Vec2 pos1 = entity->getFixture()->GetBody()->GetPosition(); 23 | b2Vec2 pos2 = target->getFixture()->GetBody()->GetPosition(); 24 | 25 | float xInSquare = pSq(pos1.x - pos2.x) + pSq(pos1.y - pos2.y); 26 | float force = (float) (xInSquare * k * energy); // Формула F=kx^2 27 | 28 | float distance = sqrt(xInSquare); 29 | b2Vec2 forceVec; 30 | forceVec.x = (abs(pos1.x - pos2.x) / distance) /*cos*/ * force; 31 | forceVec.y = (abs(pos2.y - pos2.y) / distance) /*sin*/ * force; 32 | 33 | entity->getFixture()->GetBody()->ApplyForceToCenter(forceVec, true); 34 | } 35 | -------------------------------------------------------------------------------- /src/core/utils/Parcel.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file Parcel.cpp 3 | * @brief Serialization Parcel class source file 4 | * @author LionZXY 5 | * @project Recast 6 | * @email nikita@kulikof.ru 7 | * @date 08.06.17 8 | * 9 | * Serialization 10 | * 11 | **/ 12 | 13 | #include "utils/Parcel.hpp" 14 | 15 | template 16 | char inline getByte(T var, int number); 17 | 18 | template 19 | void inline setByte(char byte, int number, T *var); 20 | 21 | Parcel::Parcel() { 22 | curPos = sizeof(int); 23 | } 24 | 25 | int Parcel::readInt() { 26 | int var = 0; 27 | for (int i = 0; i < sizeof(int); i++, curPos++) { 28 | setByte(data[curPos], i, &var); 29 | } 30 | return var; 31 | } 32 | 33 | std::string Parcel::readString() { 34 | std::string str; 35 | char tmp; 36 | while ((tmp = data[curPos++]) != '\0') { 37 | str.push_back(tmp); 38 | } 39 | return str; 40 | } 41 | 42 | float Parcel::readFloat() { 43 | float var = 0; 44 | for (int i = 0; i < sizeof(float); i++, curPos++) { 45 | setByte(data[curPos], i, &var); 46 | } 47 | return var; 48 | } 49 | 50 | void Parcel::putString(std::string var) { 51 | for (size_t i = 0; i < var.length(); i++) 52 | data.push_back((char) var.at(i)); 53 | data.push_back('\0'); 54 | } 55 | 56 | -------------------------------------------------------------------------------- /src/core/commands/CreateEntityCommand.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file CreateEntityCommand.cpp 3 | * @author LionZXY 4 | * @project Recast-server 5 | * @date 27.06.17 6 | * @email nikita@kulikof.ru 7 | **/ 8 | #include 9 | #include "commands/CreateEntityCommand.h" 10 | #include "Box2D/Box2D.h" 11 | #include "world/Box2DWorld.h" 12 | 13 | using namespace std; 14 | 15 | bool CreateEntityCommand::isValid(const string &cmd, const vector &args) const { 16 | return args.size() > 0 && cmd == "create" && args[0] == "entity"; 17 | } 18 | 19 | void 20 | CreateEntityCommand::onCommand(ICommandSender &sender, const string &cmd, const vector &args) { 21 | if (args.size() != 3) { 22 | sender.onMessage("create entity [posX] [posY]"); 23 | return; 24 | } 25 | b2BodyDef bodyDef; 26 | bodyDef.position.Set((float32) atof(args[1].c_str()), (float32) atof(args[2].c_str())); 27 | 28 | b2PolygonShape dynamicBox; 29 | dynamicBox.SetAsBox(1.0f, 1.0f); 30 | 31 | b2FixtureDef fixtureDef; 32 | fixtureDef.shape = &dynamicBox; 33 | fixtureDef.density = 1.0f; 34 | fixtureDef.friction = 0.3f; 35 | 36 | Entity *entity = sender.getWorld()->createEntity(bodyDef, fixtureDef); 37 | sender.onMessage(string("Created entity. Id:") + to_string(entity->getId())); 38 | } 39 | -------------------------------------------------------------------------------- /src/headers/temperature-world/utils/TemperatureWorldUtils.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Oleg Morozenkov on 08.05.17. 3 | // 4 | 5 | #ifndef RECAST_TEMPERATUREWORLDUTILS_H 6 | #define RECAST_TEMPERATUREWORLDUTILS_H 7 | 8 | 9 | #include 10 | #include 11 | #include "temperature-world/interfaces/ITemperatureWorldBoundable.hpp" 12 | #include "MathUtils.hpp" 13 | 14 | /** 15 | * Collection of functions which work with temperature world. 16 | */ 17 | namespace TemperatureWorldUtils { 18 | 19 | /** 20 | * Initializes temperature world with random temperatures. Random temperatures are generated within the range. 21 | * 22 | * @param world World to initialize. 23 | * @param minTemperature Minimum possible temperature in the world. 24 | * @param maxTemperature Maximum possible temperature in the world. 25 | */ 26 | inline void randomize(ITemperatureWorldBoundable& world, Temperature minTemperature, Temperature maxTemperature) { 27 | assert(minTemperature < maxTemperature); 28 | const Temperature temperatureRange = maxTemperature - minTemperature; 29 | world.foreach([&](Coord x, Coord y, Coord z) { 30 | const Temperature t = minTemperature + Temperature(MathUtils::randomFloat() * temperatureRange); 31 | world.set(x, y, z, t); 32 | }); 33 | } 34 | 35 | } 36 | 37 | #endif //RECAST_TEMPERATUREWORLDUTILS_H 38 | -------------------------------------------------------------------------------- /libs/Box2D/Common/b2Draw.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Erin Catto http://box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #include 20 | 21 | b2Draw::b2Draw() 22 | { 23 | m_drawFlags = 0; 24 | } 25 | 26 | void b2Draw::SetFlags(uint32 flags) 27 | { 28 | m_drawFlags = flags; 29 | } 30 | 31 | uint32 b2Draw::GetFlags() const 32 | { 33 | return m_drawFlags; 34 | } 35 | 36 | void b2Draw::AppendFlags(uint32 flags) 37 | { 38 | m_drawFlags |= flags; 39 | } 40 | 41 | void b2Draw::ClearFlags(uint32 flags) 42 | { 43 | m_drawFlags &= ~flags; 44 | } 45 | -------------------------------------------------------------------------------- /libs/Box2D/Box2D/Common/b2Draw.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Erin Catto http://box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #include 20 | 21 | b2Draw::b2Draw() 22 | { 23 | m_drawFlags = 0; 24 | } 25 | 26 | void b2Draw::SetFlags(uint32 flags) 27 | { 28 | m_drawFlags = flags; 29 | } 30 | 31 | uint32 b2Draw::GetFlags() const 32 | { 33 | return m_drawFlags; 34 | } 35 | 36 | void b2Draw::AppendFlags(uint32 flags) 37 | { 38 | m_drawFlags |= flags; 39 | } 40 | 41 | void b2Draw::ClearFlags(uint32 flags) 42 | { 43 | m_drawFlags &= ~flags; 44 | } 45 | -------------------------------------------------------------------------------- /libs/Box2D/Box2DConfig.cmake.in: -------------------------------------------------------------------------------- 1 | # -*- cmake -*- 2 | # 3 | # Box2dConfig.cmake(.in) 4 | # 5 | 6 | # Use the following variables to compile and link against Box2d: 7 | # BOX2D_FOUND - True if Box2d was found on your system 8 | # BOX2D_USE_FILE - The file making Box2d usable 9 | # BOX2D_DEFINITIONS - Definitions needed to build with Box2d 10 | # BOX2D_INCLUDE_DIR - Box2d headers location 11 | # BOX2D_INCLUDE_DIRS - List of directories where Box2d header file are 12 | # BOX2D_LIBRARY - Library name 13 | # BOX2D_LIBRARIES - List of libraries to link against 14 | # BOX2D_LIBRARY_DIRS - List of directories containing Box2d libraries 15 | # BOX2D_ROOT_DIR - The base directory of Box2d 16 | # BOX2D_VERSION_STRING - A human-readable string containing the version 17 | 18 | set ( BOX2D_FOUND 1 ) 19 | set ( BOX2D_USE_FILE "@BOX2D_USE_FILE@" ) 20 | 21 | set ( BOX2D_DEFINITIONS "@BOX2D_DEFINITIONS@" ) 22 | set ( BOX2D_INCLUDE_DIR "@BOX2D_INCLUDE_DIR@" ) 23 | set ( Box2D_INCLUDE_DIRS "@BOX2D_INCLUDE_DIRS@" ) # deprecated 24 | set ( BOX2D_INCLUDE_DIRS "@BOX2D_INCLUDE_DIRS@" ) 25 | set ( BOX2D_LIBRARY "@BOX2D_LIBRARY@" ) 26 | set ( BOX2D_LIBRARIES "@BOX2D_LIBRARIES@" ) 27 | set ( BOX2D_LIBRARY_DIRS "@BOX2D_LIBRARY_DIRS@" ) 28 | set ( BOX2D_ROOT_DIR "@CMAKE_INSTALL_PREFIX@" ) 29 | 30 | set ( BOX2D_VERSION_STRING "@BOX2D_VERSION@" ) 31 | 32 | -------------------------------------------------------------------------------- /libs/Box2D/Box2D/Box2DConfig.cmake.in: -------------------------------------------------------------------------------- 1 | # -*- cmake -*- 2 | # 3 | # Box2dConfig.cmake(.in) 4 | # 5 | 6 | # Use the following variables to compile and link against Box2d: 7 | # BOX2D_FOUND - True if Box2d was found on your system 8 | # BOX2D_USE_FILE - The file making Box2d usable 9 | # BOX2D_DEFINITIONS - Definitions needed to build with Box2d 10 | # BOX2D_INCLUDE_DIR - Box2d headers location 11 | # BOX2D_INCLUDE_DIRS - List of directories where Box2d header file are 12 | # BOX2D_LIBRARY - Library name 13 | # BOX2D_LIBRARIES - List of libraries to link against 14 | # BOX2D_LIBRARY_DIRS - List of directories containing Box2d libraries 15 | # BOX2D_ROOT_DIR - The base directory of Box2d 16 | # BOX2D_VERSION_STRING - A human-readable string containing the version 17 | 18 | set ( BOX2D_FOUND 1 ) 19 | set ( BOX2D_USE_FILE "@BOX2D_USE_FILE@" ) 20 | 21 | set ( BOX2D_DEFINITIONS "@BOX2D_DEFINITIONS@" ) 22 | set ( BOX2D_INCLUDE_DIR "@BOX2D_INCLUDE_DIR@" ) 23 | set ( Box2D_INCLUDE_DIRS "@BOX2D_INCLUDE_DIRS@" ) # deprecated 24 | set ( BOX2D_INCLUDE_DIRS "@BOX2D_INCLUDE_DIRS@" ) 25 | set ( BOX2D_LIBRARY "@BOX2D_LIBRARY@" ) 26 | set ( BOX2D_LIBRARIES "@BOX2D_LIBRARIES@" ) 27 | set ( BOX2D_LIBRARY_DIRS "@BOX2D_LIBRARY_DIRS@" ) 28 | set ( BOX2D_ROOT_DIR "@CMAKE_INSTALL_PREFIX@" ) 29 | 30 | set ( BOX2D_VERSION_STRING "@BOX2D_VERSION@" ) 31 | 32 | -------------------------------------------------------------------------------- /src/headers/temperature-world/interfaces/ITemperatureWorldPointPrioritizable.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Oleg Morozenkov on 18.06.17. 3 | // 4 | 5 | #ifndef RECAST_ITEMPERATUREWORLDPOINTPRIORITIZABLE_H 6 | #define RECAST_ITEMPERATUREWORLDPOINTPRIORITIZABLE_H 7 | 8 | 9 | /** 10 | * Should not be derived directly. Use `ITemperatureWorldPointPrioritizable`. 11 | * This class is useful for `dynamic_cast`. 12 | */ 13 | class ITemperatureWorldPointPrioritizableMixin { 14 | public: 15 | /** 16 | * Marks point where there is something important. 17 | * 18 | * @param x X coordinate. 19 | * @param y Y coordinate. 20 | * @param z Z coordinate. 21 | */ 22 | virtual void addPriorityPoint(Coord x, Coord y, Coord z) = 0; 23 | 24 | /** 25 | * Unmarks point where there is something important. 26 | * 27 | * @param x X coordinate. 28 | * @param y Y coordinate. 29 | * @param z Z coordinate. 30 | */ 31 | virtual void removePriorityPoint(Coord x, Coord y, Coord z) = 0; 32 | }; 33 | 34 | /** 35 | * Mixin to temperature world. 36 | * Makes temperature world to know which points are more important. 37 | * 38 | * @tparam T Base temperature world class. 39 | */ 40 | template 41 | class ITemperatureWorldPointPrioritizable : public virtual T, public virtual ITemperatureWorldPointPrioritizableMixin { 42 | }; 43 | 44 | 45 | #endif //RECAST_ITEMPERATUREWORLDPOINTPRIORITIZABLE_H 46 | -------------------------------------------------------------------------------- /src/headers/temperature-world/interfaces/ITemperatureWorldChunkableMutable.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Oleg Morozenkov on 18.06.17. 3 | // 4 | 5 | #ifndef RECAST_ITEMPERATUREWORLDCHUNKABLEMUTABLE_H 6 | #define RECAST_ITEMPERATUREWORLDCHUNKABLEMUTABLE_H 7 | 8 | 9 | #include "../types/Coord.hpp" 10 | #include "ITemperatureWorldBoundable.hpp" 11 | 12 | /** 13 | * Should not be derived directly. Use `ITemperatureWorldChunkableMutable`. 14 | * This class is useful for `dynamic_cast`. 15 | */ 16 | class ITemperatureWorldChunkableMutableMixin { 17 | public: 18 | /** 19 | * Adds a chunk to this temperature world. 20 | * 21 | * @param chunk Chunk to add. 22 | */ 23 | virtual void addChunk(std::shared_ptr> chunk) = 0; 24 | 25 | /** 26 | * Removes chunk from this temperature world. 27 | * 28 | * @param chunk Chunk to remove. 29 | */ 30 | virtual void removeChunk(std::shared_ptr> chunk) = 0; 31 | }; 32 | 33 | /** 34 | * Mixin to temperature world which can be divided by chunks. 35 | * Makes temperature world to allow chunk collection modifications. 36 | * 37 | * @tparam T Base temperature world class. 38 | */ 39 | template 40 | class ITemperatureWorldChunkableMutable : public virtual T, public virtual ITemperatureWorldChunkableMutableMixin { 41 | }; 42 | 43 | 44 | #endif //RECAST_ITEMPERATUREWORLDCHUNKABLEMUTABLE_H 45 | -------------------------------------------------------------------------------- /src/headers/io/network/NetworkServer.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file NetworkServer.hpp 3 | * @brief Networking server header file 4 | * @author StealthTech 5 | * @project Recast-server 6 | * @date 19.06.17 7 | * @email st3althtech@mail.ru 8 | * 9 | **/ 10 | 11 | #ifndef RECAST_NETWORKING_SERVER_HPP 12 | #define RECAST_NETWORKING_SERVER_HPP 13 | 14 | #include 15 | #include 16 | #include "Networking.hpp" 17 | 18 | class ICommandSender; 19 | void setNonBlockedImpl(int sd, bool option) noexcept (false); 20 | 21 | class NetworkServer { 22 | public: 23 | NetworkServer(uint32_t port, ICommandSender *sender, bool isTCP = false); 24 | void run(); 25 | void shutdown(); 26 | bool running() { return isRunning; } 27 | bool registerListener(NetworkListener *listener); 28 | bool removeListener(NetworkListener *listener); 29 | private: 30 | ICommandSender *sender; 31 | uint32_t port; 32 | bool isTCP; 33 | volatile bool isRunning; 34 | std::unordered_map listeners; 35 | 36 | bool nofityListener(char *request); 37 | void listenFor(std::shared_ptr client); 38 | void listenForBytes(std::shared_ptr client); 39 | void listenFor(std::shared_ptr client); 40 | void listenForBytes(std::shared_ptr client); 41 | string exchange(const string request); 42 | char* exchange(char *request); 43 | }; 44 | 45 | #endif //RECAST_NETWORKING_SERVER_HPP 46 | -------------------------------------------------------------------------------- /src/headers/utils/Parcel.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file Parcel.hpp 3 | * @brief Serialization Parcel class header file 4 | * @author LionZXY 5 | * @project Recast 6 | * @email nikita@kulikof.ru 7 | * @date 08.06.17 8 | * 9 | * Serialization 10 | * 11 | **/ 12 | 13 | #ifndef RECAST_SERIALIZABLE_H 14 | #define RECAST_SERIALIZABLE_H 15 | 16 | 17 | #include 18 | #include 19 | 20 | template 21 | void inline setByte(char byte, int number, T *var) { 22 | *(char *) (((void *) var) + number) = byte; 23 | } 24 | 25 | template 26 | char inline getByte(T var, int number) { 27 | return (char) ((var >> ((sizeof(T) - number - 1) * 8)) & 255); 28 | } 29 | 30 | /** 31 | * @class Parcel 32 | * 33 | * Позволяет переводить удобно данные в массив. 34 | */ 35 | class Parcel { 36 | public: 37 | Parcel(); 38 | 39 | Parcel(std::vector vector) : data(vector) {} 40 | 41 | Parcel(Parcel &other) = delete; 42 | 43 | void putString(std::string var); 44 | 45 | template 46 | void put(T var) { 47 | unsigned char const *p = reinterpret_cast(&var); 48 | for (int i = 0; i < sizeof(T); i++) 49 | data.push_back((char &&) p[i]); 50 | } 51 | 52 | int readInt(); 53 | 54 | std::string readString(); 55 | 56 | float readFloat(); 57 | 58 | const std::vector *getVector() const { return &data; } 59 | 60 | private: 61 | int curPos; 62 | std::vector data; 63 | }; 64 | 65 | 66 | #endif //RECAST_SERIALIZABLE_H 67 | -------------------------------------------------------------------------------- /libs/Box2D/Common/b2Settings.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | b2Version b2_version = {2, 3, 1}; 25 | 26 | // Memory allocators. Modify these to use your own allocator. 27 | void* b2Alloc(int32 size) 28 | { 29 | return malloc(size); 30 | } 31 | 32 | void b2Free(void* mem) 33 | { 34 | free(mem); 35 | } 36 | 37 | // You can modify this to use your logging facility. 38 | void b2Log(const char* string, ...) 39 | { 40 | va_list args; 41 | va_start(args, string); 42 | vprintf(string, args); 43 | va_end(args); 44 | } 45 | -------------------------------------------------------------------------------- /libs/Box2D/Box2D/Common/b2Settings.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | b2Version b2_version = {2, 3, 1}; 25 | 26 | // Memory allocators. Modify these to use your own allocator. 27 | void* b2Alloc(int32 size) 28 | { 29 | return malloc(size); 30 | } 31 | 32 | void b2Free(void* mem) 33 | { 34 | free(mem); 35 | } 36 | 37 | // You can modify this to use your logging facility. 38 | void b2Log(const char* string, ...) 39 | { 40 | va_list args; 41 | va_start(args, string); 42 | vprintf(string, args); 43 | va_end(args); 44 | } 45 | -------------------------------------------------------------------------------- /src/headers/temperature-world/types/IntScale.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Oleg Morozenkov on 18.06.17. 3 | // 4 | 5 | #ifndef RECAST_INTSCALE_H 6 | #define RECAST_INTSCALE_H 7 | 8 | 9 | /** 10 | * Type. 11 | * Represents scale. It can be either upscale or downscale. 12 | */ 13 | struct IntScale { 14 | public: 15 | enum Mode { 16 | Upscale, Downscale 17 | }; 18 | 19 | IntScale(int scale, Mode mode) : _scale(scale), _mode(mode) { 20 | } 21 | 22 | inline int scale() const noexcept { 23 | return _scale; 24 | } 25 | 26 | inline Mode mode() const noexcept { 27 | return _mode; 28 | } 29 | 30 | inline bool isUpscale() const noexcept { 31 | return _mode == Upscale; 32 | } 33 | 34 | inline bool isDownscale() const noexcept { 35 | return _mode == Downscale; 36 | } 37 | 38 | template 39 | inline T apply(T value) const noexcept { 40 | return _mode == Upscale ? value * _scale : value / _scale; 41 | } 42 | 43 | template 44 | inline T invertApply(T value) const noexcept { 45 | return _mode == Upscale ? value / _scale : value * _scale; 46 | } 47 | 48 | inline bool operator==(const IntScale& other) const noexcept { 49 | return _scale == other._scale && _mode == other._mode; 50 | } 51 | 52 | inline bool operator!=(const IntScale& other) const noexcept { 53 | return !(*this == other); 54 | } 55 | 56 | protected: 57 | int _scale; 58 | Mode _mode; 59 | }; 60 | 61 | 62 | #endif //RECAST_INTSCALE_H 63 | -------------------------------------------------------------------------------- /test/temperature-world/unittest.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Oleg Morozenkov on 30.03.17. 3 | // 4 | 5 | #define CATCH_CONFIG_MAIN 6 | #include "lib/catch.hpp" 7 | #include "temperature-world/implementation/BoundTemperatureWorld.hpp" 8 | 9 | SCENARIO("BoundTemperatureWorld data can be accessed") { 10 | GIVEN("small BoundTemperatureWorld") { 11 | BoundTemperatureWorld world(Parallelepiped(101, 55, 4)); 12 | 13 | REQUIRE(world.bounds().minX() < 0); 14 | REQUIRE(world.bounds().minY() < 0); 15 | REQUIRE(world.bounds().minZ() < 0); 16 | REQUIRE(world.bounds().maxX() > 0); 17 | REQUIRE(world.bounds().maxY() > 0); 18 | REQUIRE(world.bounds().maxZ() > 0); 19 | 20 | REQUIRE(world.bounds().maxX() - world.bounds().minX() < 101); 21 | REQUIRE(world.bounds().maxY() - world.bounds().minY() < 55); 22 | REQUIRE(world.bounds().maxZ() - world.bounds().minZ() < 4); 23 | 24 | WHEN("getting non-accessed cell") { 25 | THEN("temperature is zero") { 26 | REQUIRE(world.get(0, 0, 0) == 0); 27 | } 28 | } 29 | 30 | WHEN("set") { 31 | world.set(0, 0, 0, 228); 32 | 33 | THEN("") { 34 | REQUIRE(world.get(0, 0, 0) == 228); 35 | } 36 | } 37 | 38 | WHEN("amplify") { 39 | world.set(0, 0, 0, 228); 40 | world.amplify(0, 0, 0, 100); 41 | 42 | THEN("") { 43 | REQUIRE(world.get(0, 0, 0) == 328); 44 | } 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/headers/temperature-world/types/IntScaleParallelepiped.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Oleg Morozenkov on 14.06.17. 3 | // 4 | 5 | #ifndef RECAST_SCALEDPARALLELEPIPED_H 6 | #define RECAST_SCALEDPARALLELEPIPED_H 7 | 8 | 9 | #include "Parallelepiped.hpp" 10 | #include "IntScale.hpp" 11 | 12 | /** 13 | * Type. 14 | * Holds scales in three dimensions. 15 | */ 16 | struct IntScaleParallelepiped { 17 | IntScaleParallelepiped(IntScale x, IntScale y, IntScale z) : _x(x), _y(y), _z(z) { 18 | } 19 | 20 | IntScaleParallelepiped(int x, int y, int z, IntScale::Mode mode) : _x(IntScale(x, mode)) , _y(IntScale(y, mode)) , _z(IntScale(z, mode)) { 21 | } 22 | 23 | /** 24 | * @return Scale of the world by x axis; 25 | */ 26 | inline IntScale x() const noexcept { 27 | return _x; 28 | }; 29 | 30 | /** 31 | * @return Scale of the world by y axis; 32 | */ 33 | inline IntScale y() const noexcept { 34 | return _y; 35 | }; 36 | 37 | /** 38 | * @return Scale of the world by z axis; 39 | */ 40 | inline IntScale z() const noexcept { 41 | return _z; 42 | }; 43 | 44 | inline bool operator==(const IntScaleParallelepiped& other) const noexcept { 45 | return _x == other._x && _y == other._y && _z == other._z; 46 | } 47 | 48 | inline bool operator!=(const IntScaleParallelepiped& other) const noexcept { 49 | return !(*this == other); 50 | } 51 | 52 | protected: 53 | IntScale _x; 54 | IntScale _y; 55 | IntScale _z; 56 | }; 57 | 58 | 59 | #endif //RECAST_SCALEDPARALLELEPIPED_H 60 | -------------------------------------------------------------------------------- /src/temperature-world/implementation/SynchronizedBlockingTimer.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Oleg Morozenkov on 31.05.17. 3 | // 4 | 5 | #include 6 | #include "temperature-world/implementation/SynchronizedBlockingTimer.hpp" 7 | 8 | using namespace std; 9 | using namespace std::chrono; 10 | 11 | SynchronizedBlockingTimer::SynchronizedBlockingTimer(milliseconds minDelta) 12 | : _minDelta(minDelta), _lastUpdateTime(system_clock::now()), _isFirstUpdate(true) 13 | { 14 | } 15 | 16 | milliseconds SynchronizedBlockingTimer::delta() const { 17 | lock_guard guard(_lastUpdateTimeMutex); 18 | return duration_cast(system_clock::now() - _lastUpdateTime); 19 | } 20 | 21 | milliseconds SynchronizedBlockingTimer::minDelta() const { 22 | return _minDelta; 23 | } 24 | 25 | double SynchronizedBlockingTimer::deltaFloatSeconds() const { 26 | return delta().count() / 1000.0; 27 | } 28 | 29 | bool SynchronizedBlockingTimer::isFirstUpdate() const { 30 | lock_guard guard(_lastUpdateTimeMutex); 31 | return _isFirstUpdate; 32 | } 33 | 34 | void SynchronizedBlockingTimer::update() { 35 | lock_guard guard(_lastUpdateTimeMutex); 36 | _lastUpdateTime = system_clock::now(); 37 | _isFirstUpdate = false; 38 | } 39 | 40 | void SynchronizedBlockingTimer::wait() { 41 | milliseconds dt(0); 42 | { 43 | lock_guard guard(_lastUpdateTimeMutex); 44 | dt = duration_cast(system_clock::now() - _lastUpdateTime); 45 | } 46 | if (dt < _minDelta) { 47 | this_thread::sleep_for(_minDelta - dt); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/headers/temperature-world/interfaces/ITemperatureWorldChunkableObservable.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Oleg Morozenkov on 18.06.17. 3 | // 4 | 5 | #ifndef RECAST_ITEMPERATUREWORLDCHUNKABLEONDEMANDGENERATABLE_H 6 | #define RECAST_ITEMPERATUREWORLDCHUNKABLEONDEMANDGENERATABLE_H 7 | 8 | 9 | #include "temperature-world/interfaces/ITemperatureWorldBoundable.hpp" 10 | 11 | /** 12 | * Should not be derived directly. Use `ITemperatureWorldChunkableObservable`. 13 | * This class is useful for `dynamic_cast`. 14 | */ 15 | class ITemperatureWorldChunkableObservableMixin { 16 | public: 17 | using OnChunkEventFn = std::function>)>; 18 | 19 | /** 20 | * Subscribes listener to chunk add events. 21 | * 22 | * @param func Listener. 23 | */ 24 | virtual void onChunkAdd(OnChunkEventFn func) = 0; 25 | 26 | /** 27 | * Subscribes listener to chunk remove events. 28 | * 29 | * @param func Listener. 30 | */ 31 | virtual void onChunkRemove(OnChunkEventFn func) = 0; 32 | }; 33 | 34 | /** 35 | * Mixin to temperature world. 36 | * Makes temperature world which can be divided by chunks and which can be generatable on demand to be observed. 37 | * Class will emit events on both chunk adding and chunk removing. 38 | * 39 | * @tparam T Base temperature world class. 40 | */ 41 | template 42 | class ITemperatureWorldChunkableObservable : public virtual T, public virtual ITemperatureWorldChunkableObservableMixin { 43 | }; 44 | 45 | 46 | #endif //RECAST_ITEMPERATUREWORLDCHUNKABLEONDEMANDGENERATABLE_H 47 | -------------------------------------------------------------------------------- /libs/Box2D/Dynamics/Contacts/b2CircleContact.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_CIRCLE_CONTACT_H 20 | #define B2_CIRCLE_CONTACT_H 21 | 22 | #include 23 | 24 | class b2BlockAllocator; 25 | 26 | class b2CircleContact : public b2Contact 27 | { 28 | public: 29 | static b2Contact* Create( b2Fixture* fixtureA, int32 indexA, 30 | b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator); 31 | static void Destroy(b2Contact* contact, b2BlockAllocator* allocator); 32 | 33 | b2CircleContact(b2Fixture* fixtureA, b2Fixture* fixtureB); 34 | ~b2CircleContact() {} 35 | 36 | void Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB); 37 | }; 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /libs/Box2D/Box2D/Dynamics/Contacts/b2CircleContact.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_CIRCLE_CONTACT_H 20 | #define B2_CIRCLE_CONTACT_H 21 | 22 | #include 23 | 24 | class b2BlockAllocator; 25 | 26 | class b2CircleContact : public b2Contact 27 | { 28 | public: 29 | static b2Contact* Create( b2Fixture* fixtureA, int32 indexA, 30 | b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator); 31 | static void Destroy(b2Contact* contact, b2BlockAllocator* allocator); 32 | 33 | b2CircleContact(b2Fixture* fixtureA, b2Fixture* fixtureB); 34 | ~b2CircleContact() {} 35 | 36 | void Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB); 37 | }; 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /libs/Box2D/Dynamics/Contacts/b2PolygonContact.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_POLYGON_CONTACT_H 20 | #define B2_POLYGON_CONTACT_H 21 | 22 | #include 23 | 24 | class b2BlockAllocator; 25 | 26 | class b2PolygonContact : public b2Contact 27 | { 28 | public: 29 | static b2Contact* Create( b2Fixture* fixtureA, int32 indexA, 30 | b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator); 31 | static void Destroy(b2Contact* contact, b2BlockAllocator* allocator); 32 | 33 | b2PolygonContact(b2Fixture* fixtureA, b2Fixture* fixtureB); 34 | ~b2PolygonContact() {} 35 | 36 | void Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB); 37 | }; 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /src/core/io/network/NetworkUtils.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file NetworkUtils.cpp 3 | * @brief Basic networking utils source file 4 | * @author StealthTech 5 | * @project Recast-server 6 | * @date 17.06.17 7 | * @email st3althtech@mail.ru 8 | * 9 | **/ 10 | 11 | #include 12 | #include "io/network/NetworkUtils.hpp" 13 | 14 | using namespace std; 15 | string int2ipv4(uint32_t ip) { 16 | char buffer[128]; 17 | snprintf(buffer, sizeof(buffer), "%u.%u.%u.%u", ip&0xFF, (ip&0xFF00) >> 8, (ip&0xFF0000) >> 16, (ip&0xFF000000) >> 24); 18 | return buffer; 19 | } 20 | 21 | struct sockaddr_in resolve(const char* host, int port) { 22 | struct hostent* hp = gethostbyname(host); 23 | if (NULL == hp) { 24 | throw runtime_error("An exception occurred (resolve error): " + string(strerror(errno))); 25 | } 26 | 27 | char** pAddress = hp->h_addr_list; 28 | while(*pAddress) { 29 | unsigned char *ipf = reinterpret_cast(*pAddress); 30 | uint32_t cur_interface_ip = 0; 31 | uint8_t *rimap_local_ip_ptr = reinterpret_cast(&cur_interface_ip); 32 | rimap_local_ip_ptr[0] = ipf[0]; 33 | rimap_local_ip_ptr[1] = ipf[1]; 34 | rimap_local_ip_ptr[2] = ipf[2]; 35 | rimap_local_ip_ptr[3] = ipf[3]; 36 | cerr << "Resolved successfully: " << int2ipv4(cur_interface_ip) << endl; 37 | ++pAddress; 38 | } 39 | 40 | struct sockaddr_in address; 41 | memset(&address, 0, sizeof(address)); 42 | address.sin_family = AF_INET; 43 | address.sin_port = htons(port); 44 | memcpy(&address.sin_addr, hp->h_addr, hp->h_length); 45 | 46 | return address; 47 | } 48 | -------------------------------------------------------------------------------- /libs/Box2D/Box2D/Dynamics/Contacts/b2PolygonContact.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_POLYGON_CONTACT_H 20 | #define B2_POLYGON_CONTACT_H 21 | 22 | #include 23 | 24 | class b2BlockAllocator; 25 | 26 | class b2PolygonContact : public b2Contact 27 | { 28 | public: 29 | static b2Contact* Create( b2Fixture* fixtureA, int32 indexA, 30 | b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator); 31 | static void Destroy(b2Contact* contact, b2BlockAllocator* allocator); 32 | 33 | b2PolygonContact(b2Fixture* fixtureA, b2Fixture* fixtureB); 34 | ~b2PolygonContact() {} 35 | 36 | void Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB); 37 | }; 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /libs/Box2D/Common/b2Timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Erin Catto http://box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_TIMER_H 20 | #define B2_TIMER_H 21 | 22 | #include 23 | 24 | /// Timer for profiling. This has platform specific code and may 25 | /// not work on every platform. 26 | class b2Timer 27 | { 28 | public: 29 | 30 | /// Constructor 31 | b2Timer(); 32 | 33 | /// Reset the timer. 34 | void Reset(); 35 | 36 | /// Get the time since construction or the last reset. 37 | float32 GetMilliseconds() const; 38 | 39 | private: 40 | 41 | #if defined(_WIN32) 42 | float64 m_start; 43 | static float64 s_invFrequency; 44 | #elif defined(__linux__) || defined (__APPLE__) 45 | unsigned long m_start_sec; 46 | unsigned long m_start_usec; 47 | #endif 48 | }; 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /libs/Box2D/Box2D/Common/b2Timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Erin Catto http://box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_TIMER_H 20 | #define B2_TIMER_H 21 | 22 | #include 23 | 24 | /// Timer for profiling. This has platform specific code and may 25 | /// not work on every platform. 26 | class b2Timer 27 | { 28 | public: 29 | 30 | /// Constructor 31 | b2Timer(); 32 | 33 | /// Reset the timer. 34 | void Reset(); 35 | 36 | /// Get the time since construction or the last reset. 37 | float32 GetMilliseconds() const; 38 | 39 | private: 40 | 41 | #if defined(_WIN32) 42 | float64 m_start; 43 | static float64 s_invFrequency; 44 | #elif defined(__linux__) || defined (__APPLE__) 45 | unsigned long m_start_sec; 46 | unsigned long m_start_usec; 47 | #endif 48 | }; 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Recast [![Build Status](https://travis-ci.org/bender-wardrobe/Recast.svg?branch=master)](https://travis-ci.org/bender-wardrobe/Recast) 2 | Основная идея проекта - не ограничивать игрока в создании заклинаний. Игрок может создавать заклинания, опираясь на физические законы окружающего мира. 3 | 4 | ## Основные концепции проекта: 5 | - Проект - игра в жанре RPG 6 | - Двумерный игровой мир в представлении пользователя 7 | - Трёхмерный игровой мир с фиксированной глубиной со стороны логики игры 8 | - Основной “фишкой” игры является возможность построения - произвольных заклинаний 9 | - Заклинания строятся в отдельном трёхмерном интерфейсе, управление глубиной на колёсико мыши или wasd+shift+space 10 | - Заклинания представляют из себя трёхмерные графы, состоящие из узлов и связывающих их рёбер 11 | - Заклинания завязаны на законах физики и связаны с температурой объектов и кинетикой 12 | - Создание заклинаний базируется на схемотехнике 13 | - Приоритет в разработке отдаётся созданию движка создания заклинаний 14 | - Прототип схож с игрой Terraria 15 | - Разрушаемый мир 16 | - Деление мира на тайлы 17 | 18 | ## Примеры заклинаний: 19 | - Огненный шар 20 | - Отталкивание 21 | 22 | ## Документация: 23 | Автоматическая документация генерируется с помощью Doxygen: https://glitchless.github.io/Recast/html/ 24 | 25 | ## Клиентская часть: 26 | Репозиторий с игрой на Unity3D: https://github.com/glitchless/RecastClient 27 | 28 | ## Защита проекта: 29 | Презентация на защите 28 июня 2017 в офисе Mail.Ru: http://files.s.oleg.rocks/recast/presentation.pdf 30 | 31 | ## Команда "Шкаф Бендера": 32 | - Олег Морозенков 33 | - Василий Дмитриев 34 | - Михаил Волынов 35 | - Юрий Голубев 36 | - Куликов Никита 37 | -------------------------------------------------------------------------------- /libs/Box2D/Dynamics/Contacts/b2EdgeAndCircleContact.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_EDGE_AND_CIRCLE_CONTACT_H 20 | #define B2_EDGE_AND_CIRCLE_CONTACT_H 21 | 22 | #include 23 | 24 | class b2BlockAllocator; 25 | 26 | class b2EdgeAndCircleContact : public b2Contact 27 | { 28 | public: 29 | static b2Contact* Create( b2Fixture* fixtureA, int32 indexA, 30 | b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator); 31 | static void Destroy(b2Contact* contact, b2BlockAllocator* allocator); 32 | 33 | b2EdgeAndCircleContact(b2Fixture* fixtureA, b2Fixture* fixtureB); 34 | ~b2EdgeAndCircleContact() {} 35 | 36 | void Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB); 37 | }; 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /libs/Box2D/Box2D/Dynamics/Contacts/b2EdgeAndCircleContact.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_EDGE_AND_CIRCLE_CONTACT_H 20 | #define B2_EDGE_AND_CIRCLE_CONTACT_H 21 | 22 | #include 23 | 24 | class b2BlockAllocator; 25 | 26 | class b2EdgeAndCircleContact : public b2Contact 27 | { 28 | public: 29 | static b2Contact* Create( b2Fixture* fixtureA, int32 indexA, 30 | b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator); 31 | static void Destroy(b2Contact* contact, b2BlockAllocator* allocator); 32 | 33 | b2EdgeAndCircleContact(b2Fixture* fixtureA, b2Fixture* fixtureB); 34 | ~b2EdgeAndCircleContact() {} 35 | 36 | void Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB); 37 | }; 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /libs/Box2D/Dynamics/Contacts/b2EdgeAndPolygonContact.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_EDGE_AND_POLYGON_CONTACT_H 20 | #define B2_EDGE_AND_POLYGON_CONTACT_H 21 | 22 | #include 23 | 24 | class b2BlockAllocator; 25 | 26 | class b2EdgeAndPolygonContact : public b2Contact 27 | { 28 | public: 29 | static b2Contact* Create( b2Fixture* fixtureA, int32 indexA, 30 | b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator); 31 | static void Destroy(b2Contact* contact, b2BlockAllocator* allocator); 32 | 33 | b2EdgeAndPolygonContact(b2Fixture* fixtureA, b2Fixture* fixtureB); 34 | ~b2EdgeAndPolygonContact() {} 35 | 36 | void Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB); 37 | }; 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /libs/Box2D/Dynamics/Contacts/b2PolygonAndCircleContact.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_POLYGON_AND_CIRCLE_CONTACT_H 20 | #define B2_POLYGON_AND_CIRCLE_CONTACT_H 21 | 22 | #include 23 | 24 | class b2BlockAllocator; 25 | 26 | class b2PolygonAndCircleContact : public b2Contact 27 | { 28 | public: 29 | static b2Contact* Create(b2Fixture* fixtureA, int32 indexA, b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator); 30 | static void Destroy(b2Contact* contact, b2BlockAllocator* allocator); 31 | 32 | b2PolygonAndCircleContact(b2Fixture* fixtureA, b2Fixture* fixtureB); 33 | ~b2PolygonAndCircleContact() {} 34 | 35 | void Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB); 36 | }; 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /libs/Box2D/Box2D/Dynamics/Contacts/b2EdgeAndPolygonContact.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_EDGE_AND_POLYGON_CONTACT_H 20 | #define B2_EDGE_AND_POLYGON_CONTACT_H 21 | 22 | #include 23 | 24 | class b2BlockAllocator; 25 | 26 | class b2EdgeAndPolygonContact : public b2Contact 27 | { 28 | public: 29 | static b2Contact* Create( b2Fixture* fixtureA, int32 indexA, 30 | b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator); 31 | static void Destroy(b2Contact* contact, b2BlockAllocator* allocator); 32 | 33 | b2EdgeAndPolygonContact(b2Fixture* fixtureA, b2Fixture* fixtureB); 34 | ~b2EdgeAndPolygonContact() {} 35 | 36 | void Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB); 37 | }; 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /libs/Box2D/Box2D/Dynamics/Contacts/b2PolygonAndCircleContact.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_POLYGON_AND_CIRCLE_CONTACT_H 20 | #define B2_POLYGON_AND_CIRCLE_CONTACT_H 21 | 22 | #include 23 | 24 | class b2BlockAllocator; 25 | 26 | class b2PolygonAndCircleContact : public b2Contact 27 | { 28 | public: 29 | static b2Contact* Create(b2Fixture* fixtureA, int32 indexA, b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator); 30 | static void Destroy(b2Contact* contact, b2BlockAllocator* allocator); 31 | 32 | b2PolygonAndCircleContact(b2Fixture* fixtureA, b2Fixture* fixtureB); 33 | ~b2PolygonAndCircleContact() {} 34 | 35 | void Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB); 36 | }; 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /libs/Box2D/Dynamics/Contacts/b2ChainAndCircleContact.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_CHAIN_AND_CIRCLE_CONTACT_H 20 | #define B2_CHAIN_AND_CIRCLE_CONTACT_H 21 | 22 | #include 23 | 24 | class b2BlockAllocator; 25 | 26 | class b2ChainAndCircleContact : public b2Contact 27 | { 28 | public: 29 | static b2Contact* Create( b2Fixture* fixtureA, int32 indexA, 30 | b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator); 31 | static void Destroy(b2Contact* contact, b2BlockAllocator* allocator); 32 | 33 | b2ChainAndCircleContact(b2Fixture* fixtureA, int32 indexA, b2Fixture* fixtureB, int32 indexB); 34 | ~b2ChainAndCircleContact() {} 35 | 36 | void Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB); 37 | }; 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /libs/Box2D/Box2D/Dynamics/Contacts/b2ChainAndCircleContact.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_CHAIN_AND_CIRCLE_CONTACT_H 20 | #define B2_CHAIN_AND_CIRCLE_CONTACT_H 21 | 22 | #include 23 | 24 | class b2BlockAllocator; 25 | 26 | class b2ChainAndCircleContact : public b2Contact 27 | { 28 | public: 29 | static b2Contact* Create( b2Fixture* fixtureA, int32 indexA, 30 | b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator); 31 | static void Destroy(b2Contact* contact, b2BlockAllocator* allocator); 32 | 33 | b2ChainAndCircleContact(b2Fixture* fixtureA, int32 indexA, b2Fixture* fixtureB, int32 indexB); 34 | ~b2ChainAndCircleContact() {} 35 | 36 | void Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB); 37 | }; 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /libs/Box2D/Dynamics/Contacts/b2ChainAndPolygonContact.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_CHAIN_AND_POLYGON_CONTACT_H 20 | #define B2_CHAIN_AND_POLYGON_CONTACT_H 21 | 22 | #include 23 | 24 | class b2BlockAllocator; 25 | 26 | class b2ChainAndPolygonContact : public b2Contact 27 | { 28 | public: 29 | static b2Contact* Create( b2Fixture* fixtureA, int32 indexA, 30 | b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator); 31 | static void Destroy(b2Contact* contact, b2BlockAllocator* allocator); 32 | 33 | b2ChainAndPolygonContact(b2Fixture* fixtureA, int32 indexA, b2Fixture* fixtureB, int32 indexB); 34 | ~b2ChainAndPolygonContact() {} 35 | 36 | void Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB); 37 | }; 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /libs/Box2D/Box2D/Dynamics/Contacts/b2ChainAndPolygonContact.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_CHAIN_AND_POLYGON_CONTACT_H 20 | #define B2_CHAIN_AND_POLYGON_CONTACT_H 21 | 22 | #include 23 | 24 | class b2BlockAllocator; 25 | 26 | class b2ChainAndPolygonContact : public b2Contact 27 | { 28 | public: 29 | static b2Contact* Create( b2Fixture* fixtureA, int32 indexA, 30 | b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator); 31 | static void Destroy(b2Contact* contact, b2BlockAllocator* allocator); 32 | 33 | b2ChainAndPolygonContact(b2Fixture* fixtureA, int32 indexA, b2Fixture* fixtureB, int32 indexB); 34 | ~b2ChainAndPolygonContact() {} 35 | 36 | void Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB); 37 | }; 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /src/headers/temperature-world/interfaces/IUpdaterTemperatureWorldSemiChunkUpdatable.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Oleg Morozenkov on 24.06.17. 3 | // 4 | 5 | #ifndef RECAST_SERVER_ISEMICHUNKTEMPERATUREWORLDUPDATER_HPP 6 | #define RECAST_SERVER_ISEMICHUNKTEMPERATUREWORLDUPDATER_HPP 7 | 8 | 9 | #include "ITemperatureWorld.hpp" 10 | #include "ITemperatureWorldBoundable.hpp" 11 | #include "IUpdater.hpp" 12 | 13 | /** 14 | * Should not be derived directly. Use `ITemperatureWorldChunkable`. 15 | * This class is useful for `dynamic_cast`. 16 | */ 17 | class IUpdaterTemperatureWorldSemiChunkUpdatableMixin { 18 | public: 19 | /** 20 | * Tells whether it's possible to add this chunk to near chunks collection on specified edge. 21 | * This method is thread-safe. 22 | * 23 | * @param otherChunk Near chunk. 24 | * @return True if this chunk can be added to near chunks collection. 25 | */ 26 | virtual bool canAddNearChunk(Edge edge, const std::shared_ptr>& otherChunk) const noexcept = 0; 27 | 28 | /** 29 | * Adds chunk to near chunks collection on specified edge. 30 | * 31 | * @param otherChunk Near chunk. 32 | */ 33 | virtual void addNearChunk(Edge edge, std::shared_ptr> otherChunk) = 0; 34 | }; 35 | 36 | 37 | /** 38 | * Mixin to temperature world updater. 39 | * Makes updater to updater other chunks. 40 | * 41 | * @tparam T Base temperature world updater class. 42 | */ 43 | template 44 | class IUpdaterTemperatureWorldSemiChunkUpdatable : public virtual T, public virtual IUpdaterTemperatureWorldSemiChunkUpdatableMixin { 45 | }; 46 | 47 | 48 | #endif //RECAST_SERVER_ISEMICHUNKTEMPERATUREWORLDUPDATER_HPP 49 | -------------------------------------------------------------------------------- /libs/Box2D/Dynamics/b2WorldCallbacks.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #include 20 | #include 21 | 22 | // Return true if contact calculations should be performed between these two shapes. 23 | // If you implement your own collision filter you may want to build from this implementation. 24 | bool b2ContactFilter::ShouldCollide(b2Fixture* fixtureA, b2Fixture* fixtureB) 25 | { 26 | const b2Filter& filterA = fixtureA->GetFilterData(); 27 | const b2Filter& filterB = fixtureB->GetFilterData(); 28 | 29 | if (filterA.groupIndex == filterB.groupIndex && filterA.groupIndex != 0) 30 | { 31 | return filterA.groupIndex > 0; 32 | } 33 | 34 | bool collide = (filterA.maskBits & filterB.categoryBits) != 0 && (filterA.categoryBits & filterB.maskBits) != 0; 35 | return collide; 36 | } 37 | -------------------------------------------------------------------------------- /src/headers/commands/ICommand.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief Command file 4 | * @author LionZXY 5 | * @project Recast-server 6 | * @date 08.06.17 7 | * 8 | * Describe ICommandFile 9 | * 10 | **/ 11 | #ifndef RECAST_SERVER_ICOMMAND_H 12 | #define RECAST_SERVER_ICOMMAND_H 13 | 14 | #include 15 | #include 16 | #include "ICommandSender.hpp" 17 | 18 | /** 19 | * @brief Superclass for Command object 20 | * 21 | * If you want to create new command you should extend ICommand class and register that in CommandManager constructor 22 | * 23 | * @warning Don't forget to register your Command in CommandManager!!! 24 | * 25 | */ 26 | class ICommand { 27 | public: 28 | ICommand() {} 29 | 30 | ICommand(const ICommand &other) {} 31 | 32 | virtual bool isOnlyUICommand() { return false; } 33 | 34 | virtual bool isValid(const std::string &cmd, 35 | const std::vector &args) const = 0; //// You should return @var True if this command line satisfied with you. 36 | 37 | /** 38 | * Run command. 39 | * @example On command 'stop now 1 2' from Server console this method receives (Server, 'stop'. {'now','1', '2'}) 40 | * 41 | * @warning ICommandSender is NOT thread-safe. It means @param sender is sent from background thread. If your ICommand needs main thread execution, create an issue. I will create a flag for that command. 42 | * 43 | * @param sender context object 44 | * @param cmd first word in command 45 | * @param args second and next words in command (Always not null) 46 | */ 47 | virtual void onCommand(ICommandSender &sender, const std::string &cmd, const std::vector &args) = 0; 48 | }; 49 | 50 | 51 | #endif //RECAST_SERVER_ICOMMAND_H 52 | -------------------------------------------------------------------------------- /libs/Box2D/Box2D/Dynamics/b2WorldCallbacks.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #include 20 | #include 21 | 22 | // Return true if contact calculations should be performed between these two shapes. 23 | // If you implement your own collision filter you may want to build from this implementation. 24 | bool b2ContactFilter::ShouldCollide(b2Fixture* fixtureA, b2Fixture* fixtureB) 25 | { 26 | const b2Filter& filterA = fixtureA->GetFilterData(); 27 | const b2Filter& filterB = fixtureB->GetFilterData(); 28 | 29 | if (filterA.groupIndex == filterB.groupIndex && filterA.groupIndex != 0) 30 | { 31 | return filterA.groupIndex > 0; 32 | } 33 | 34 | bool collide = (filterA.maskBits & filterB.categoryBits) != 0 && (filterA.categoryBits & filterB.maskBits) != 0; 35 | return collide; 36 | } 37 | -------------------------------------------------------------------------------- /src/headers/io/configs/Config.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief Config file 4 | * @author LionZXY 5 | * @project Recast 6 | * @date 08.06.17 7 | * 8 | * Config file. 9 | * 10 | **/ 11 | #ifndef RECAST_CONFIG_H 12 | #define RECAST_CONFIG_H 13 | 14 | #include 15 | 16 | /** 17 | * @brief Config class 18 | * 19 | * Using Boost ptree struct. 20 | * Config file hashing and buffering in memory. (You can't get an instance of Config from constructor) 21 | * Please call Config::instance to get an instance of Config. 22 | * 23 | **/ 24 | class Config { 25 | public: 26 | Config(const std::string &filename); 27 | 28 | ~Config(); 29 | 30 | Config(const Config &other) = delete; 31 | 32 | boost::property_tree::ptree &tree(); 33 | 34 | void save(); 35 | 36 | void load(); 37 | 38 | static Config *instance(); 39 | 40 | /** 41 | * This method create param if not exist 42 | * 43 | * @tparam T class of config var 44 | * @param key string with path like 'general.server.port' 45 | * @param defaultVar var used when config var is empty 46 | * @return defultVar returned if config var is empty 47 | */ 48 | template 49 | T get(const std::string &key, T defaultVar) { 50 | try { 51 | return tree().get(key); 52 | } catch (std::exception &e) { 53 | tree().put(key, defaultVar); 54 | return defaultVar; 55 | } 56 | } 57 | 58 | template 59 | static T g(const std::string &key, T defaultVar) { 60 | return instance()->get(key, defaultVar); 61 | } 62 | 63 | private: 64 | std::string filename; 65 | boost::property_tree::ptree pt; 66 | }; 67 | 68 | 69 | #endif //RECAST_CONFIG_H 70 | -------------------------------------------------------------------------------- /libs/Box2D/Dynamics/b2ContactManager.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_CONTACT_MANAGER_H 20 | #define B2_CONTACT_MANAGER_H 21 | 22 | #include 23 | 24 | class b2Contact; 25 | class b2ContactFilter; 26 | class b2ContactListener; 27 | class b2BlockAllocator; 28 | 29 | // Delegate of b2World. 30 | class b2ContactManager 31 | { 32 | public: 33 | b2ContactManager(); 34 | 35 | // Broad-phase callback. 36 | void AddPair(void* proxyUserDataA, void* proxyUserDataB); 37 | 38 | void FindNewContacts(); 39 | 40 | void Destroy(b2Contact* c); 41 | 42 | void Collide(); 43 | 44 | b2BroadPhase m_broadPhase; 45 | b2Contact* m_contactList; 46 | int32 m_contactCount; 47 | b2ContactFilter* m_contactFilter; 48 | b2ContactListener* m_contactListener; 49 | b2BlockAllocator* m_allocator; 50 | }; 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /src/headers/temperature-world/interfaces/ITemperatureWorldBoundable.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Oleg Morozenkov on 31.05.17. 3 | // 4 | 5 | #ifndef RECAST_IBOUNDTEMPERATUREWORLD_H 6 | #define RECAST_IBOUNDTEMPERATUREWORLD_H 7 | 8 | 9 | #include 10 | #include "temperature-world/types/Edge.hpp" 11 | #include "temperature-world/types/Coord.hpp" 12 | #include "temperature-world/types/Size.hpp" 13 | #include "temperature-world/types/Temperature.hpp" 14 | #include "ITemperatureWorld.hpp" 15 | #include "temperature-world/types/Parallelepiped.hpp" 16 | 17 | /** 18 | * Should not be derived directly. Use `ITemperatureWorldBoundable`. 19 | * This class is useful for `dynamic_cast`. 20 | */ 21 | class ITemperatureWorldBoundableMixin { 22 | public: 23 | using ForeachCellFn = std::function; 24 | 25 | /** 26 | * Loops over each point. 27 | * 28 | * @param func Function to execute at each point. 29 | */ 30 | virtual void foreach(ForeachCellFn func) const = 0; 31 | 32 | /** 33 | * Loops over each point on specified edge. 34 | * 35 | * @param edge Edge. 36 | * @param func Function to execute at each point. 37 | */ 38 | virtual void foreachCellOnEdge(Edge edge, ForeachCellFn func) const = 0; 39 | 40 | /** 41 | * @return Bounds of this temperature world. 42 | */ 43 | virtual Parallelepiped bounds() const noexcept = 0; 44 | }; 45 | 46 | /** 47 | * Mixin to temperature world. 48 | * Makes temperature world not to be endless. 49 | * 50 | * @tparam T Base temperature world class. 51 | */ 52 | template 53 | class ITemperatureWorldBoundable : public virtual T, public virtual ITemperatureWorldBoundableMixin { 54 | }; 55 | 56 | 57 | #endif //RECAST_IBOUNDTEMPERATUREWORLD_H 58 | -------------------------------------------------------------------------------- /libs/Box2D/Box2D/Dynamics/b2ContactManager.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_CONTACT_MANAGER_H 20 | #define B2_CONTACT_MANAGER_H 21 | 22 | #include 23 | 24 | class b2Contact; 25 | class b2ContactFilter; 26 | class b2ContactListener; 27 | class b2BlockAllocator; 28 | 29 | // Delegate of b2World. 30 | class b2ContactManager 31 | { 32 | public: 33 | b2ContactManager(); 34 | 35 | // Broad-phase callback. 36 | void AddPair(void* proxyUserDataA, void* proxyUserDataB); 37 | 38 | void FindNewContacts(); 39 | 40 | void Destroy(b2Contact* c); 41 | 42 | void Collide(); 43 | 44 | b2BroadPhase m_broadPhase; 45 | b2Contact* m_contactList; 46 | int32 m_contactCount; 47 | b2ContactFilter* m_contactFilter; 48 | b2ContactListener* m_contactListener; 49 | b2BlockAllocator* m_allocator; 50 | }; 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /src/headers/temperature-world/interfaces/ITemperatureWorldChunkableGeneratable.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Oleg Morozenkov on 19.06.17. 3 | // 4 | 5 | #ifndef RECAST_ITEMPERATUREWORLDCHUNKABLEGENERATABLE_H 6 | #define RECAST_ITEMPERATUREWORLDCHUNKABLEGENERATABLE_H 7 | 8 | 9 | /** 10 | * Should not be derived directly. Use `ITemperatureWorldChunkableGeneratable`. 11 | * This class is useful for `dynamic_cast`. 12 | */ 13 | class ITemperatureWorldChunkableGeneratableMixin { 14 | public: 15 | /** 16 | * Tells whether the chunk which holds this point exists. 17 | * If chunk doesn't exist, the method will tell whether it will generated on `getOrGenerateChunk` call. 18 | * This method doesn't throw exceptions. 19 | * 20 | * @param x X coordinate. 21 | * @param y Y coordinate. 22 | * @param z Z coordinate. 23 | * @return True if chunk exists. 24 | */ 25 | virtual bool hasOrIsGeneratableChunk(Coord x, Coord y, Coord z) const noexcept = 0; 26 | 27 | /** 28 | * Retrieves chunk which holds this point. 29 | * If chunk doesn't exist, the method will generate chunk if it's possible. 30 | * 31 | * @param x X coordinate. 32 | * @param y Y coordinate. 33 | * @param z Z coordinate. 34 | * @return Chunk at the point. 35 | */ 36 | virtual std::shared_ptr> getOrGenerateChunk(Coord x, Coord y, Coord z) = 0; 37 | }; 38 | 39 | /** 40 | * Mixin to temperature world. 41 | * Makes temperature world which can be divided by chunks to be generatable on demand. 42 | * 43 | * @tparam T Base temperature world class. 44 | */ 45 | template 46 | class ITemperatureWorldChunkableGeneratable : public virtual T, public virtual ITemperatureWorldChunkableGeneratableMixin { 47 | }; 48 | 49 | #endif //RECAST_ITEMPERATUREWORLDCHUNKABLEGENERATABLE_H 50 | -------------------------------------------------------------------------------- /src/headers/world/Box2DWorld.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file Box2DWorld.h 3 | * @author LionZXY 4 | * @project Recast-server 5 | * @date 25.06.17 6 | * @email nikita@kulikof.ru 7 | **/ 8 | #ifndef RECAST_SERVER_BOX2DWORLD_H 9 | #define RECAST_SERVER_BOX2DWORLD_H 10 | 11 | #include 12 | #include 13 | #include 14 | #include "world/wrappers/Entity.h" 15 | #include 16 | #include 17 | 18 | class Spell; 19 | 20 | class Server; 21 | 22 | class SpellEntity; 23 | 24 | class DelayedSpellCreate; 25 | 26 | class Box2DWorld : public b2DestructionListener, b2ContactListener { 27 | public: 28 | Box2DWorld(Server *server); 29 | 30 | ~Box2DWorld(); 31 | 32 | void update(); 33 | 34 | std::vector getAllEntityInChunk(float x1, float x2); 35 | 36 | Entity *createEntity(b2BodyDef &bodyDef, b2FixtureDef &fixtureDef); 37 | 38 | SpellEntity *createSpellEntity(b2Vec2 position, Spell *spell); 39 | 40 | Entity *getEntityById(int id) { return entitysId[id]; } 41 | void asyncCreateSpellEntity(b2Vec2 position, Spell *spell); 42 | void subscribeToUpdate(Entity *entity) { needTickEntity.push_back(entity); } 43 | 44 | void SayGoodbye(b2Fixture *fixture); 45 | 46 | void SayGoodbye(b2Joint *joint) {} 47 | 48 | void BeginContact(b2Contact *contact); 49 | 50 | private: 51 | b2World *world; 52 | std::set existGround; // Костыль божественной мощи 53 | std::vector needTickEntity; 54 | std::vector beDestroyed; 55 | std::unordered_map entitysId; 56 | boost::lockfree::queue> delayedSpell; 57 | Server *server; 58 | int freeId = 0; 59 | 60 | void checkAndCreateGround(float x1, float x2); 61 | 62 | void checkAndCreateGround(float x); 63 | 64 | void executeAllDelayed(); 65 | }; 66 | 67 | 68 | #endif //RECAST_SERVER_BOX2DWORLD_H 69 | -------------------------------------------------------------------------------- /libs/Box2D/Common/b2StackAllocator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_STACK_ALLOCATOR_H 20 | #define B2_STACK_ALLOCATOR_H 21 | 22 | #include 23 | 24 | const int32 b2_stackSize = 100 * 1024; // 100k 25 | const int32 b2_maxStackEntries = 32; 26 | 27 | struct b2StackEntry 28 | { 29 | char* data; 30 | int32 size; 31 | bool usedMalloc; 32 | }; 33 | 34 | // This is a stack allocator used for fast per step allocations. 35 | // You must nest allocate/free pairs. The code will assert 36 | // if you try to interleave multiple allocate/free pairs. 37 | class b2StackAllocator 38 | { 39 | public: 40 | b2StackAllocator(); 41 | ~b2StackAllocator(); 42 | 43 | void* Allocate(int32 size); 44 | void Free(void* p); 45 | 46 | int32 GetMaxAllocation() const; 47 | 48 | private: 49 | 50 | char m_data[b2_stackSize]; 51 | int32 m_index; 52 | 53 | int32 m_allocation; 54 | int32 m_maxAllocation; 55 | 56 | b2StackEntry m_entries[b2_maxStackEntries]; 57 | int32 m_entryCount; 58 | }; 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /src/spell/Spell.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file Spell.cpp 3 | * @author LionZXY 4 | * @project Recast-server 5 | * @date 21.06.17 6 | * @email nikita@kulikof.ru 7 | **/ 8 | #include 9 | #include 10 | #include "spells/nodes/SpellNode.hpp" 11 | #include "spells/Spell.hpp" 12 | 13 | void Spell::tickSpell(SpellEventListener &listener) { 14 | rootNode->tick(listener, NULL); 15 | } 16 | 17 | Spell::~Spell() { 18 | delete rootNode; 19 | } 20 | 21 | using namespace std; 22 | 23 | void Spell::write(Parcel &in, Spell *obj) { 24 | unordered_map nodes; 25 | vector> pairs; 26 | int id = 0; 27 | 28 | obj->getRootNode()->iterrator([&nodes, &id](SpellNode *node) -> void { 29 | nodes[node] = id++; 30 | return; 31 | }); 32 | 33 | obj->getRootNode()->iterrator([&nodes, &pairs](SpellNode *node) -> void { 34 | int curId = nodes[node]; 35 | for (SpellNode *child: node->getConnectedNodes()) 36 | pairs.push_back(pair(curId, nodes[child])); 37 | return; 38 | }); 39 | 40 | in.put((int) nodes.size()); 41 | for (pair &key : nodes) { 42 | in.put(key.second); 43 | SpellNode::write(in, key.first); 44 | } 45 | 46 | in.put((int) pairs.size()); 47 | for (pair pr : pairs) { 48 | in.put(pr.first); 49 | in.put(pr.second); 50 | } 51 | } 52 | 53 | Spell *Spell::read(Parcel &out) { 54 | unordered_map nodes; 55 | int countNodes = out.readInt(); 56 | 57 | for (int i = 0; i < countNodes; i++) { 58 | int id = out.readInt(); 59 | nodes[id] = SpellNode::read(out); 60 | } 61 | 62 | int countPair = out.readInt(); 63 | 64 | for (int i = 0; i < countPair; i++) { 65 | nodes[out.readInt()]->connectNode(nodes[out.readInt()]); 66 | } 67 | 68 | return new Spell((*nodes.begin()).second); 69 | } 70 | -------------------------------------------------------------------------------- /libs/Box2D/Box2D/Common/b2StackAllocator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_STACK_ALLOCATOR_H 20 | #define B2_STACK_ALLOCATOR_H 21 | 22 | #include 23 | 24 | const int32 b2_stackSize = 100 * 1024; // 100k 25 | const int32 b2_maxStackEntries = 32; 26 | 27 | struct b2StackEntry 28 | { 29 | char* data; 30 | int32 size; 31 | bool usedMalloc; 32 | }; 33 | 34 | // This is a stack allocator used for fast per step allocations. 35 | // You must nest allocate/free pairs. The code will assert 36 | // if you try to interleave multiple allocate/free pairs. 37 | class b2StackAllocator 38 | { 39 | public: 40 | b2StackAllocator(); 41 | ~b2StackAllocator(); 42 | 43 | void* Allocate(int32 size); 44 | void Free(void* p); 45 | 46 | int32 GetMaxAllocation() const; 47 | 48 | private: 49 | 50 | char m_data[b2_stackSize]; 51 | int32 m_index; 52 | 53 | int32 m_allocation; 54 | int32 m_maxAllocation; 55 | 56 | b2StackEntry m_entries[b2_maxStackEntries]; 57 | int32 m_entryCount; 58 | }; 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /src/core/io/configs/Config.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief Config description 4 | * @author LionZXY 5 | * @project Recast 6 | * @date 08.06.17 7 | * 8 | * Save INSTANCE config and get if you need this. 9 | * 10 | **/ 11 | 12 | #include 13 | #include 14 | #include 15 | #include "io/configs/Config.hpp" 16 | 17 | 18 | using namespace boost::property_tree::json_parser; 19 | using namespace std; 20 | using namespace boost::property_tree; 21 | const int CONFIG_VERSION = 1; 22 | const string DEFAULT_FOLDER("./config/"); 23 | const string DEFAULT_CONFIG("general.json"); 24 | const int NOTHING = -1; 25 | static Config *INSTANCE = NULL; 26 | 27 | Config *Config::instance() { 28 | if (INSTANCE == NULL) { 29 | INSTANCE = new Config(DEFAULT_CONFIG); 30 | } 31 | return INSTANCE; 32 | } 33 | 34 | Config::Config(const string &filename) { 35 | this->filename = DEFAULT_FOLDER + filename; 36 | try { 37 | read_json(this->filename, pt); 38 | } catch (const json_parser_error &e) { 39 | save(); 40 | } 41 | if (pt.get("config.version", NOTHING) == NOTHING) { 42 | pt.put("config.version", CONFIG_VERSION); 43 | } 44 | } 45 | 46 | ptree &Config::tree() { 47 | return this->pt; 48 | } 49 | 50 | void Config::save() { 51 | boost::filesystem::path dir(DEFAULT_FOLDER); 52 | if (!boost::filesystem::exists(dir)) { 53 | if (boost::filesystem::create_directory(dir)) { 54 | BOOST_LOG_TRIVIAL(info) << "Folder " << DEFAULT_FOLDER << " create successful"; 55 | write_json(filename, pt); 56 | } else { 57 | BOOST_LOG_TRIVIAL(info) << "Error while create dir: " << DEFAULT_FOLDER; 58 | } 59 | } else { write_json(filename, pt); } 60 | } 61 | 62 | void Config::load() { 63 | read_json(filename, pt); 64 | } 65 | 66 | Config::~Config() { 67 | save(); 68 | INSTANCE = NULL; 69 | } -------------------------------------------------------------------------------- /src/headers/temperature-world/interfaces/ITemperatureWorldChunkable.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Oleg Morozenkov on 13.06.17. 3 | // 4 | 5 | #ifndef RECAST_ICHUNKEDTEMPERATUREWORLD_H 6 | #define RECAST_ICHUNKEDTEMPERATUREWORLD_H 7 | 8 | 9 | #include 10 | #include "ITemperatureWorld.hpp" 11 | #include "ITemperatureWorldBoundable.hpp" 12 | 13 | /** 14 | * Should not be derived directly. Use `ITemperatureWorldChunkable`. 15 | * This class is useful for `dynamic_cast`. 16 | */ 17 | class ITemperatureWorldChunkableMixin { 18 | public: 19 | using ForeachChunkFn = std::function>&)>; 20 | 21 | /** 22 | * Tells whether the chunk which holds this point exists. 23 | * This method doesn't throw exceptions. 24 | * 25 | * @param x X coordinate. 26 | * @param y Y coordinate. 27 | * @param z Z coordinate. 28 | * @return True if chunk exists. 29 | */ 30 | virtual bool hasChunk(Coord x, Coord y, Coord z) const noexcept = 0; 31 | 32 | /** 33 | * Retrieves chunk which holds this point. 34 | * 35 | * @param x X coordinate. 36 | * @param y Y coordinate. 37 | * @param z Z coordinate. 38 | * @return Chunk at the point. 39 | */ 40 | virtual std::shared_ptr> getChunk(Coord x, Coord y, Coord z) const = 0; 41 | 42 | /** 43 | * Loops over each chunk. 44 | * 45 | * @param func Function to execute at each chunk. 46 | */ 47 | virtual void foreachChunk(ForeachChunkFn func) const = 0; 48 | }; 49 | 50 | /** 51 | * Mixin to temperature world. 52 | * Makes temperature world to be divided by chunks. 53 | * 54 | * @tparam T Base temperature world class. 55 | */ 56 | template 57 | class ITemperatureWorldChunkable : public virtual T, public virtual ITemperatureWorldChunkableMixin { 58 | }; 59 | 60 | 61 | #endif //RECAST_ICHUNKEDTEMPERATUREWORLD_H 62 | -------------------------------------------------------------------------------- /src/headers/temperature-world/implementation/BoundTemperatureWorld.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Oleg Morozenkov on 31.05.17. 3 | // 4 | 5 | #ifndef RECAST_VECTORTEMPERATUREWORLD_H 6 | #define RECAST_VECTORTEMPERATUREWORLD_H 7 | 8 | 9 | #include 10 | #include "temperature-world/interfaces/ITemperatureWorldBoundable.hpp" 11 | 12 | /** 13 | * Implementation of temperature world with bounds. It's backed by `std::vector`. 14 | */ 15 | class BoundTemperatureWorld : public virtual ITemperatureWorldBoundable { 16 | public: 17 | BoundTemperatureWorld(Parallelepiped bounds); 18 | 19 | BoundTemperatureWorld(const BoundTemperatureWorld& other); 20 | BoundTemperatureWorld(BoundTemperatureWorld&& other); 21 | BoundTemperatureWorld& operator=(BoundTemperatureWorld other); 22 | 23 | friend void swap(BoundTemperatureWorld& first, BoundTemperatureWorld& second); 24 | 25 | bool has(Coord x, Coord y, Coord z) const noexcept override; 26 | Temperature get(Coord x, Coord y, Coord z) const override; 27 | void set(Coord x, Coord y, Coord z, Temperature temperature) override; 28 | void amplify(Coord x, Coord y, Coord z, Temperature temperature) override; 29 | 30 | void foreach(ForeachCellFn func) const override; 31 | void foreachCellOnEdge(Edge edge, ForeachCellFn func) const override; 32 | 33 | Parallelepiped bounds() const noexcept override; 34 | 35 | Coord previousCoordX(Coord x) const noexcept override; 36 | Coord previousCoordY(Coord y) const noexcept override; 37 | Coord previousCoordZ(Coord z) const noexcept override; 38 | Coord nextCoordX(Coord x) const noexcept override; 39 | Coord nextCoordY(Coord y) const noexcept override; 40 | Coord nextCoordZ(Coord z) const noexcept override; 41 | 42 | protected: 43 | virtual size_t _getIndexInData(Coord x, Coord y, Coord z) const; 44 | 45 | Parallelepiped _bounds; 46 | std::vector _data; 47 | }; 48 | 49 | #include "BoundTemperatureWorld.inc.hpp" 50 | 51 | 52 | #endif //RECAST_VECTORTEMPERATUREWORLD_H 53 | -------------------------------------------------------------------------------- /libs/Box2D/Dynamics/b2TimeStep.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2011 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_TIME_STEP_H 20 | #define B2_TIME_STEP_H 21 | 22 | #include 23 | 24 | /// Profiling data. Times are in milliseconds. 25 | struct b2Profile 26 | { 27 | float32 step; 28 | float32 collide; 29 | float32 solve; 30 | float32 solveInit; 31 | float32 solveVelocity; 32 | float32 solvePosition; 33 | float32 broadphase; 34 | float32 solveTOI; 35 | }; 36 | 37 | /// This is an internal structure. 38 | struct b2TimeStep 39 | { 40 | float32 dt; // time step 41 | float32 inv_dt; // inverse time step (0 if dt == 0). 42 | float32 dtRatio; // dt * inv_dt0 43 | int32 velocityIterations; 44 | int32 positionIterations; 45 | bool warmStarting; 46 | }; 47 | 48 | /// This is an internal structure. 49 | struct b2Position 50 | { 51 | b2Vec2 c; 52 | float32 a; 53 | }; 54 | 55 | /// This is an internal structure. 56 | struct b2Velocity 57 | { 58 | b2Vec2 v; 59 | float32 w; 60 | }; 61 | 62 | /// Solver Data 63 | struct b2SolverData 64 | { 65 | b2TimeStep step; 66 | b2Position* positions; 67 | b2Velocity* velocities; 68 | }; 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /libs/Box2D/Box2D/Dynamics/b2TimeStep.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2011 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_TIME_STEP_H 20 | #define B2_TIME_STEP_H 21 | 22 | #include 23 | 24 | /// Profiling data. Times are in milliseconds. 25 | struct b2Profile 26 | { 27 | float32 step; 28 | float32 collide; 29 | float32 solve; 30 | float32 solveInit; 31 | float32 solveVelocity; 32 | float32 solvePosition; 33 | float32 broadphase; 34 | float32 solveTOI; 35 | }; 36 | 37 | /// This is an internal structure. 38 | struct b2TimeStep 39 | { 40 | float32 dt; // time step 41 | float32 inv_dt; // inverse time step (0 if dt == 0). 42 | float32 dtRatio; // dt * inv_dt0 43 | int32 velocityIterations; 44 | int32 positionIterations; 45 | bool warmStarting; 46 | }; 47 | 48 | /// This is an internal structure. 49 | struct b2Position 50 | { 51 | b2Vec2 c; 52 | float32 a; 53 | }; 54 | 55 | /// This is an internal structure. 56 | struct b2Velocity 57 | { 58 | b2Vec2 v; 59 | float32 w; 60 | }; 61 | 62 | /// Solver Data 63 | struct b2SolverData 64 | { 65 | b2TimeStep step; 66 | b2Position* positions; 67 | b2Velocity* velocities; 68 | }; 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /libs/Box2D/Collision/b2TimeOfImpact.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_TIME_OF_IMPACT_H 20 | #define B2_TIME_OF_IMPACT_H 21 | 22 | #include 23 | #include 24 | 25 | /// Input parameters for b2TimeOfImpact 26 | struct b2TOIInput 27 | { 28 | b2DistanceProxy proxyA; 29 | b2DistanceProxy proxyB; 30 | b2Sweep sweepA; 31 | b2Sweep sweepB; 32 | float32 tMax; // defines sweep interval [0, tMax] 33 | }; 34 | 35 | // Output parameters for b2TimeOfImpact. 36 | struct b2TOIOutput 37 | { 38 | enum State 39 | { 40 | e_unknown, 41 | e_failed, 42 | e_overlapped, 43 | e_touching, 44 | e_separated 45 | }; 46 | 47 | State state; 48 | float32 t; 49 | }; 50 | 51 | /// Compute the upper bound on time before two shapes penetrate. Time is represented as 52 | /// a fraction between [0,tMax]. This uses a swept separating axis and may miss some intermediate, 53 | /// non-tunneling collision. If you change the time interval, you should call this function 54 | /// again. 55 | /// Note: use b2Distance to compute the contact point and normal at the time of impact. 56 | void b2TimeOfImpact(b2TOIOutput* output, const b2TOIInput* input); 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /src/headers/spells/nodes/SpellNode.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file Node.h 3 | * @author LionZXY 4 | * @project Recast-server 5 | * @date 20.06.17 6 | * @email nikita@kulikof.ru 7 | **/ 8 | #ifndef RECAST_SERVER_NODE_H 9 | #define RECAST_SERVER_NODE_H 10 | 11 | #include 12 | #include "utils/Parcel.hpp" 13 | #include "spells/events/IEventListener.hpp" 14 | 15 | enum NodeType { 16 | USUALLY = 0, 17 | ENERGY = 1, 18 | HEATER = 2, 19 | AIM = 3, 20 | GENERATOR = 4 21 | }; 22 | 23 | class SpellNode { 24 | public: 25 | SpellNode(NodeType type, float x, float y, float z) : x(x), y(y), z(z), type(type), nowInTick(false) {} 26 | 27 | ~SpellNode(); 28 | 29 | virtual bool isEnergyNode() { return false; } 30 | 31 | /** 32 | * Link node if not already exist 33 | * The contract involves adding the current node from the calling party 34 | * 35 | * @param otherNode 36 | */ 37 | void connectNode(SpellNode *otherNode); 38 | 39 | /** 40 | * Main tick method. Not execute tick on parent node 41 | * 42 | * @param listener 43 | * @param callable 44 | */ 45 | void tick(IEventListener &listener, SpellNode *callable); 46 | 47 | bool inTick() const { return nowInTick; } 48 | 49 | float getDistance(const SpellNode *otherNode) const; 50 | 51 | NodeType getType() const { return type; } 52 | 53 | void iterrator(std::function next); 54 | 55 | std::set &getConnectedNodes() { return connectedNodes; } 56 | 57 | float getX() const { return x; } 58 | 59 | float getY() const { return y; } 60 | 61 | float getZ() const { return z; } 62 | 63 | 64 | static void write(Parcel &in, SpellNode * obj); 65 | static SpellNode *read(Parcel &out); 66 | 67 | protected: 68 | float x, y, z; //// Relative coordinates from root node 69 | std::set connectedNodes; 70 | bool nowInTick; //// Inside var for iterrator between nodes 71 | NodeType type; 72 | 73 | virtual inline void onTick(IEventListener &listener, SpellNode *callable) {}; 74 | }; 75 | 76 | #endif //RECAST_SERVER_NODE_H 77 | -------------------------------------------------------------------------------- /libs/Box2D/Box2D/Collision/b2TimeOfImpact.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_TIME_OF_IMPACT_H 20 | #define B2_TIME_OF_IMPACT_H 21 | 22 | #include 23 | #include 24 | 25 | /// Input parameters for b2TimeOfImpact 26 | struct b2TOIInput 27 | { 28 | b2DistanceProxy proxyA; 29 | b2DistanceProxy proxyB; 30 | b2Sweep sweepA; 31 | b2Sweep sweepB; 32 | float32 tMax; // defines sweep interval [0, tMax] 33 | }; 34 | 35 | // Output parameters for b2TimeOfImpact. 36 | struct b2TOIOutput 37 | { 38 | enum State 39 | { 40 | e_unknown, 41 | e_failed, 42 | e_overlapped, 43 | e_touching, 44 | e_separated 45 | }; 46 | 47 | State state; 48 | float32 t; 49 | }; 50 | 51 | /// Compute the upper bound on time before two shapes penetrate. Time is represented as 52 | /// a fraction between [0,tMax]. This uses a swept separating axis and may miss some intermediate, 53 | /// non-tunneling collision. If you change the time interval, you should call this function 54 | /// again. 55 | /// Note: use b2Distance to compute the contact point and normal at the time of impact. 56 | void b2TimeOfImpact(b2TOIOutput* output, const b2TOIInput* input); 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /src/headers/temperature-world/implementation/ChunkedTemperatureWorld.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Oleg Morozenkov on 13.06.17. 3 | // 4 | 5 | #ifndef RECAST_SYNCHRONIZEDVECTORCHUNKEDTEMPERATUREWORLD_H 6 | #define RECAST_SYNCHRONIZEDVECTORCHUNKEDTEMPERATUREWORLD_H 7 | 8 | 9 | #include 10 | #include 11 | #include "temperature-world/types/Temperature.hpp" 12 | #include "temperature-world/interfaces/ITemperatureWorldChunkableMutable.hpp" 13 | #include "temperature-world/interfaces/ITemperatureWorldChunkable.hpp" 14 | 15 | /** 16 | * Implementation of temperature world divided by chunks. It's backed by `std::list`. 17 | */ 18 | class ChunkedTemperatureWorld : public virtual ITemperatureWorldChunkableMutable> { 19 | public: 20 | ChunkedTemperatureWorld(); 21 | 22 | bool hasChunk(Coord x, Coord y, Coord z) const noexcept override; 23 | std::shared_ptr> getChunk(Coord x, Coord y, Coord z) const override; 24 | void foreachChunk(ForeachChunkFn func) const override; 25 | 26 | bool has(Coord x, Coord y, Coord z) const noexcept override; 27 | Temperature get(Coord x, Coord y, Coord z) const override; 28 | void set(Coord x, Coord y, Coord z, Temperature temperature) override; 29 | void amplify(Coord x, Coord y, Coord z, Temperature temperature) override; 30 | 31 | void addChunk(std::shared_ptr> chunk) override; 32 | void removeChunk(std::shared_ptr> chunk) override ; 33 | 34 | Coord previousCoordX(Coord x) const noexcept override; 35 | Coord previousCoordY(Coord y) const noexcept override; 36 | Coord previousCoordZ(Coord z) const noexcept override; 37 | Coord nextCoordX(Coord x) const noexcept override; 38 | Coord nextCoordY(Coord y) const noexcept override; 39 | Coord nextCoordZ(Coord z) const noexcept override; 40 | 41 | protected: 42 | std::list>> _chunks; 43 | }; 44 | 45 | 46 | #endif //RECAST_SYNCHRONIZEDVECTORCHUNKEDTEMPERATUREWORLD_H 47 | -------------------------------------------------------------------------------- /libs/Box2D/Common/b2BlockAllocator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_BLOCK_ALLOCATOR_H 20 | #define B2_BLOCK_ALLOCATOR_H 21 | 22 | #include 23 | 24 | const int32 b2_chunkSize = 16 * 1024; 25 | const int32 b2_maxBlockSize = 640; 26 | const int32 b2_blockSizes = 14; 27 | const int32 b2_chunkArrayIncrement = 128; 28 | 29 | struct b2Block; 30 | struct b2Chunk; 31 | 32 | /// This is a small object allocator used for allocating small 33 | /// objects that persist for more than one time step. 34 | /// See: http://www.codeproject.com/useritems/Small_Block_Allocator.asp 35 | class b2BlockAllocator 36 | { 37 | public: 38 | b2BlockAllocator(); 39 | ~b2BlockAllocator(); 40 | 41 | /// Allocate memory. This will use b2Alloc if the size is larger than b2_maxBlockSize. 42 | void* Allocate(int32 size); 43 | 44 | /// Free memory. This will use b2Free if the size is larger than b2_maxBlockSize. 45 | void Free(void* p, int32 size); 46 | 47 | void Clear(); 48 | 49 | private: 50 | 51 | b2Chunk* m_chunks; 52 | int32 m_chunkCount; 53 | int32 m_chunkSpace; 54 | 55 | b2Block* m_freeLists[b2_blockSizes]; 56 | 57 | static int32 s_blockSizes[b2_blockSizes]; 58 | static uint8 s_blockSizeLookup[b2_maxBlockSize + 1]; 59 | static bool s_blockSizeLookupInitialized; 60 | }; 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /libs/Box2D/Box2D/Common/b2BlockAllocator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_BLOCK_ALLOCATOR_H 20 | #define B2_BLOCK_ALLOCATOR_H 21 | 22 | #include 23 | 24 | const int32 b2_chunkSize = 16 * 1024; 25 | const int32 b2_maxBlockSize = 640; 26 | const int32 b2_blockSizes = 14; 27 | const int32 b2_chunkArrayIncrement = 128; 28 | 29 | struct b2Block; 30 | struct b2Chunk; 31 | 32 | /// This is a small object allocator used for allocating small 33 | /// objects that persist for more than one time step. 34 | /// See: http://www.codeproject.com/useritems/Small_Block_Allocator.asp 35 | class b2BlockAllocator 36 | { 37 | public: 38 | b2BlockAllocator(); 39 | ~b2BlockAllocator(); 40 | 41 | /// Allocate memory. This will use b2Alloc if the size is larger than b2_maxBlockSize. 42 | void* Allocate(int32 size); 43 | 44 | /// Free memory. This will use b2Free if the size is larger than b2_maxBlockSize. 45 | void Free(void* p, int32 size); 46 | 47 | void Clear(); 48 | 49 | private: 50 | 51 | b2Chunk* m_chunks; 52 | int32 m_chunkCount; 53 | int32 m_chunkSpace; 54 | 55 | b2Block* m_freeLists[b2_blockSizes]; 56 | 57 | static int32 s_blockSizes[b2_blockSizes]; 58 | static uint8 s_blockSizeLookup[b2_maxBlockSize + 1]; 59 | static bool s_blockSizeLookupInitialized; 60 | }; 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /libs/Box2D/Dynamics/Contacts/b2EdgeAndCircleContact.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2010 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | b2Contact* b2EdgeAndCircleContact::Create(b2Fixture* fixtureA, int32, b2Fixture* fixtureB, int32, b2BlockAllocator* allocator) 26 | { 27 | void* mem = allocator->Allocate(sizeof(b2EdgeAndCircleContact)); 28 | return new (mem) b2EdgeAndCircleContact(fixtureA, fixtureB); 29 | } 30 | 31 | void b2EdgeAndCircleContact::Destroy(b2Contact* contact, b2BlockAllocator* allocator) 32 | { 33 | ((b2EdgeAndCircleContact*)contact)->~b2EdgeAndCircleContact(); 34 | allocator->Free(contact, sizeof(b2EdgeAndCircleContact)); 35 | } 36 | 37 | b2EdgeAndCircleContact::b2EdgeAndCircleContact(b2Fixture* fixtureA, b2Fixture* fixtureB) 38 | : b2Contact(fixtureA, 0, fixtureB, 0) 39 | { 40 | b2Assert(m_fixtureA->GetType() == b2Shape::e_edge); 41 | b2Assert(m_fixtureB->GetType() == b2Shape::e_circle); 42 | } 43 | 44 | void b2EdgeAndCircleContact::Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB) 45 | { 46 | b2CollideEdgeAndCircle( manifold, 47 | (b2EdgeShape*)m_fixtureA->GetShape(), xfA, 48 | (b2CircleShape*)m_fixtureB->GetShape(), xfB); 49 | } 50 | -------------------------------------------------------------------------------- /libs/Box2D/Box2D/Dynamics/Contacts/b2EdgeAndCircleContact.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2010 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | b2Contact* b2EdgeAndCircleContact::Create(b2Fixture* fixtureA, int32, b2Fixture* fixtureB, int32, b2BlockAllocator* allocator) 26 | { 27 | void* mem = allocator->Allocate(sizeof(b2EdgeAndCircleContact)); 28 | return new (mem) b2EdgeAndCircleContact(fixtureA, fixtureB); 29 | } 30 | 31 | void b2EdgeAndCircleContact::Destroy(b2Contact* contact, b2BlockAllocator* allocator) 32 | { 33 | ((b2EdgeAndCircleContact*)contact)->~b2EdgeAndCircleContact(); 34 | allocator->Free(contact, sizeof(b2EdgeAndCircleContact)); 35 | } 36 | 37 | b2EdgeAndCircleContact::b2EdgeAndCircleContact(b2Fixture* fixtureA, b2Fixture* fixtureB) 38 | : b2Contact(fixtureA, 0, fixtureB, 0) 39 | { 40 | b2Assert(m_fixtureA->GetType() == b2Shape::e_edge); 41 | b2Assert(m_fixtureB->GetType() == b2Shape::e_circle); 42 | } 43 | 44 | void b2EdgeAndCircleContact::Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB) 45 | { 46 | b2CollideEdgeAndCircle( manifold, 47 | (b2EdgeShape*)m_fixtureA->GetShape(), xfA, 48 | (b2CircleShape*)m_fixtureB->GetShape(), xfB); 49 | } 50 | -------------------------------------------------------------------------------- /libs/Box2D/Dynamics/Contacts/b2EdgeAndPolygonContact.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2010 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | b2Contact* b2EdgeAndPolygonContact::Create(b2Fixture* fixtureA, int32, b2Fixture* fixtureB, int32, b2BlockAllocator* allocator) 26 | { 27 | void* mem = allocator->Allocate(sizeof(b2EdgeAndPolygonContact)); 28 | return new (mem) b2EdgeAndPolygonContact(fixtureA, fixtureB); 29 | } 30 | 31 | void b2EdgeAndPolygonContact::Destroy(b2Contact* contact, b2BlockAllocator* allocator) 32 | { 33 | ((b2EdgeAndPolygonContact*)contact)->~b2EdgeAndPolygonContact(); 34 | allocator->Free(contact, sizeof(b2EdgeAndPolygonContact)); 35 | } 36 | 37 | b2EdgeAndPolygonContact::b2EdgeAndPolygonContact(b2Fixture* fixtureA, b2Fixture* fixtureB) 38 | : b2Contact(fixtureA, 0, fixtureB, 0) 39 | { 40 | b2Assert(m_fixtureA->GetType() == b2Shape::e_edge); 41 | b2Assert(m_fixtureB->GetType() == b2Shape::e_polygon); 42 | } 43 | 44 | void b2EdgeAndPolygonContact::Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB) 45 | { 46 | b2CollideEdgeAndPolygon( manifold, 47 | (b2EdgeShape*)m_fixtureA->GetShape(), xfA, 48 | (b2PolygonShape*)m_fixtureB->GetShape(), xfB); 49 | } 50 | -------------------------------------------------------------------------------- /src/headers/temperature-world/implementation/GeneratableChunkedTemperatureWorld.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Oleg Morozenkov on 15.06.17. 3 | // 4 | 5 | #ifndef RECAST_ONDEMANDGENERETABLESYNCHRONIZEDLISTGENERICCHUNKEDTEMPERATUREWORLD_H 6 | #define RECAST_ONDEMANDGENERETABLESYNCHRONIZEDLISTGENERICCHUNKEDTEMPERATUREWORLD_H 7 | 8 | 9 | #include "ChunkedTemperatureWorld.hpp" 10 | #include "temperature-world/interfaces/ITemperatureWorldChunkableGeneratable.hpp" 11 | #include "temperature-world/interfaces/ITemperatureWorldChunkableObservable.hpp" 12 | #include "typedefs/GeneratableChunkedTemperatureWorldTypedefs.hpp" 13 | 14 | /** 15 | * Implementation of temperature world divided by chunks. It's backed by `std::list`. 16 | * It will create new chunk if client accesses temperature of point in non-existing chunk. 17 | */ 18 | class GeneratableChunkedTemperatureWorld 19 | : public virtual ITemperatureWorldChunkableObservable>>> 20 | , public virtual ChunkedTemperatureWorld 21 | { 22 | public: 23 | GeneratableChunkedTemperatureWorld( 24 | GeneratableChunkedTemperatureWorldTypedefs::NeedChunkFn needChunkFn, 25 | GeneratableChunkedTemperatureWorldTypedefs::MakeChunkFn makeChunkFn); 26 | 27 | bool hasOrIsGeneratableChunk(Coord x, Coord y, Coord z) const noexcept override; 28 | std::shared_ptr> getOrGenerateChunk(Coord x, Coord y, Coord z) override; 29 | 30 | void addChunk(std::shared_ptr> chunk) override; 31 | void removeChunk(std::shared_ptr> chunk) override; 32 | 33 | void onChunkAdd(OnChunkEventFn func) override; 34 | void onChunkRemove(OnChunkEventFn func) override; 35 | 36 | protected: 37 | GeneratableChunkedTemperatureWorldTypedefs::NeedChunkFn _needChunkFn; 38 | GeneratableChunkedTemperatureWorldTypedefs::MakeChunkFn _makeChunkFn; 39 | 40 | std::list _onChunkAddListeners; 41 | std::list _onChunkRemoveListeners; 42 | }; 43 | 44 | 45 | #endif //RECAST_ONDEMANDGENERETABLESYNCHRONIZEDLISTGENERICCHUNKEDTEMPERATUREWORLD_H 46 | -------------------------------------------------------------------------------- /libs/Box2D/Box2D/Dynamics/Contacts/b2EdgeAndPolygonContact.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2010 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | b2Contact* b2EdgeAndPolygonContact::Create(b2Fixture* fixtureA, int32, b2Fixture* fixtureB, int32, b2BlockAllocator* allocator) 26 | { 27 | void* mem = allocator->Allocate(sizeof(b2EdgeAndPolygonContact)); 28 | return new (mem) b2EdgeAndPolygonContact(fixtureA, fixtureB); 29 | } 30 | 31 | void b2EdgeAndPolygonContact::Destroy(b2Contact* contact, b2BlockAllocator* allocator) 32 | { 33 | ((b2EdgeAndPolygonContact*)contact)->~b2EdgeAndPolygonContact(); 34 | allocator->Free(contact, sizeof(b2EdgeAndPolygonContact)); 35 | } 36 | 37 | b2EdgeAndPolygonContact::b2EdgeAndPolygonContact(b2Fixture* fixtureA, b2Fixture* fixtureB) 38 | : b2Contact(fixtureA, 0, fixtureB, 0) 39 | { 40 | b2Assert(m_fixtureA->GetType() == b2Shape::e_edge); 41 | b2Assert(m_fixtureB->GetType() == b2Shape::e_polygon); 42 | } 43 | 44 | void b2EdgeAndPolygonContact::Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB) 45 | { 46 | b2CollideEdgeAndPolygon( manifold, 47 | (b2EdgeShape*)m_fixtureA->GetShape(), xfA, 48 | (b2PolygonShape*)m_fixtureB->GetShape(), xfB); 49 | } 50 | -------------------------------------------------------------------------------- /src/headers/temperature-world/implementation/ScalingGeneratableChunkedTemperatureWorld.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Oleg Morozenkov on 14.06.17. 3 | // 4 | 5 | #ifndef RECAST_SCALABLESYNCHRONIZEDLISTCHUNKEDTEMPERATUREWORLD_H 6 | #define RECAST_SCALABLESYNCHRONIZEDLISTCHUNKEDTEMPERATUREWORLD_H 7 | 8 | 9 | #include "temperature-world/types/Parallelepiped.hpp" 10 | #include "BoundTemperatureWorld.hpp" 11 | #include "temperature-world/interfaces/ITemperatureWorldChunkable.hpp" 12 | #include "ChunkedTemperatureWorld.hpp" 13 | #include "GeneratableChunkedTemperatureWorld.hpp" 14 | #include "temperature-world/interfaces/ITemperatureWorldPointPrioritizable.hpp" 15 | #include "temperature-world/types/Point.hpp" 16 | 17 | /** 18 | * Implementation of temperature world divided by chunks. It's backed by `std::list`. 19 | * It will create new chunk if client accesses temperature of point in non-existing chunk. 20 | * Also it will automatically upscale cell size in far chunks for optimization. 21 | */ 22 | class ScalingGeneratableChunkedTemperatureWorld 23 | : public virtual ITemperatureWorldPointPrioritizable>>>> 24 | , public virtual GeneratableChunkedTemperatureWorld 25 | { 26 | public: 27 | ScalingGeneratableChunkedTemperatureWorld( 28 | GeneratableChunkedTemperatureWorldTypedefs::NeedChunkFn needChunkFn, 29 | GeneratableChunkedTemperatureWorldTypedefs::MakeChunkFn makeChunkFn, 30 | Parallelepiped baseChunkSize); 31 | 32 | void addPriorityPoint(Coord x, Coord y, Coord z) override; 33 | void removePriorityPoint(Coord x, Coord y, Coord z) override; 34 | 35 | void addChunk(std::shared_ptr> chunk) override; 36 | void removeChunk(std::shared_ptr> chunk) override; 37 | 38 | protected: 39 | virtual void _updateScales(); 40 | virtual void _updateScale(std::shared_ptr>& chunk); 41 | 42 | Parallelepiped _baseChunkSize; 43 | std::list _priorityPoints; 44 | }; 45 | 46 | 47 | #endif //RECAST_SCALABLESYNCHRONIZEDLISTCHUNKEDTEMPERATUREWORLD_H 48 | -------------------------------------------------------------------------------- /libs/Box2D/Dynamics/Contacts/b2PolygonAndCircleContact.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | b2Contact* b2PolygonAndCircleContact::Create(b2Fixture* fixtureA, int32, b2Fixture* fixtureB, int32, b2BlockAllocator* allocator) 26 | { 27 | void* mem = allocator->Allocate(sizeof(b2PolygonAndCircleContact)); 28 | return new (mem) b2PolygonAndCircleContact(fixtureA, fixtureB); 29 | } 30 | 31 | void b2PolygonAndCircleContact::Destroy(b2Contact* contact, b2BlockAllocator* allocator) 32 | { 33 | ((b2PolygonAndCircleContact*)contact)->~b2PolygonAndCircleContact(); 34 | allocator->Free(contact, sizeof(b2PolygonAndCircleContact)); 35 | } 36 | 37 | b2PolygonAndCircleContact::b2PolygonAndCircleContact(b2Fixture* fixtureA, b2Fixture* fixtureB) 38 | : b2Contact(fixtureA, 0, fixtureB, 0) 39 | { 40 | b2Assert(m_fixtureA->GetType() == b2Shape::e_polygon); 41 | b2Assert(m_fixtureB->GetType() == b2Shape::e_circle); 42 | } 43 | 44 | void b2PolygonAndCircleContact::Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB) 45 | { 46 | b2CollidePolygonAndCircle( manifold, 47 | (b2PolygonShape*)m_fixtureA->GetShape(), xfA, 48 | (b2CircleShape*)m_fixtureB->GetShape(), xfB); 49 | } 50 | -------------------------------------------------------------------------------- /libs/Box2D/Dynamics/Contacts/b2CircleContact.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include 27 | 28 | b2Contact* b2CircleContact::Create(b2Fixture* fixtureA, int32, b2Fixture* fixtureB, int32, b2BlockAllocator* allocator) 29 | { 30 | void* mem = allocator->Allocate(sizeof(b2CircleContact)); 31 | return new (mem) b2CircleContact(fixtureA, fixtureB); 32 | } 33 | 34 | void b2CircleContact::Destroy(b2Contact* contact, b2BlockAllocator* allocator) 35 | { 36 | ((b2CircleContact*)contact)->~b2CircleContact(); 37 | allocator->Free(contact, sizeof(b2CircleContact)); 38 | } 39 | 40 | b2CircleContact::b2CircleContact(b2Fixture* fixtureA, b2Fixture* fixtureB) 41 | : b2Contact(fixtureA, 0, fixtureB, 0) 42 | { 43 | b2Assert(m_fixtureA->GetType() == b2Shape::e_circle); 44 | b2Assert(m_fixtureB->GetType() == b2Shape::e_circle); 45 | } 46 | 47 | void b2CircleContact::Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB) 48 | { 49 | b2CollideCircles(manifold, 50 | (b2CircleShape*)m_fixtureA->GetShape(), xfA, 51 | (b2CircleShape*)m_fixtureB->GetShape(), xfB); 52 | } 53 | -------------------------------------------------------------------------------- /libs/Box2D/Box2D/Dynamics/Contacts/b2CircleContact.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include 27 | 28 | b2Contact* b2CircleContact::Create(b2Fixture* fixtureA, int32, b2Fixture* fixtureB, int32, b2BlockAllocator* allocator) 29 | { 30 | void* mem = allocator->Allocate(sizeof(b2CircleContact)); 31 | return new (mem) b2CircleContact(fixtureA, fixtureB); 32 | } 33 | 34 | void b2CircleContact::Destroy(b2Contact* contact, b2BlockAllocator* allocator) 35 | { 36 | ((b2CircleContact*)contact)->~b2CircleContact(); 37 | allocator->Free(contact, sizeof(b2CircleContact)); 38 | } 39 | 40 | b2CircleContact::b2CircleContact(b2Fixture* fixtureA, b2Fixture* fixtureB) 41 | : b2Contact(fixtureA, 0, fixtureB, 0) 42 | { 43 | b2Assert(m_fixtureA->GetType() == b2Shape::e_circle); 44 | b2Assert(m_fixtureB->GetType() == b2Shape::e_circle); 45 | } 46 | 47 | void b2CircleContact::Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB) 48 | { 49 | b2CollideCircles(manifold, 50 | (b2CircleShape*)m_fixtureA->GetShape(), xfA, 51 | (b2CircleShape*)m_fixtureB->GetShape(), xfB); 52 | } 53 | -------------------------------------------------------------------------------- /libs/Box2D/Box2D/Dynamics/Contacts/b2PolygonAndCircleContact.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | b2Contact* b2PolygonAndCircleContact::Create(b2Fixture* fixtureA, int32, b2Fixture* fixtureB, int32, b2BlockAllocator* allocator) 26 | { 27 | void* mem = allocator->Allocate(sizeof(b2PolygonAndCircleContact)); 28 | return new (mem) b2PolygonAndCircleContact(fixtureA, fixtureB); 29 | } 30 | 31 | void b2PolygonAndCircleContact::Destroy(b2Contact* contact, b2BlockAllocator* allocator) 32 | { 33 | ((b2PolygonAndCircleContact*)contact)->~b2PolygonAndCircleContact(); 34 | allocator->Free(contact, sizeof(b2PolygonAndCircleContact)); 35 | } 36 | 37 | b2PolygonAndCircleContact::b2PolygonAndCircleContact(b2Fixture* fixtureA, b2Fixture* fixtureB) 38 | : b2Contact(fixtureA, 0, fixtureB, 0) 39 | { 40 | b2Assert(m_fixtureA->GetType() == b2Shape::e_polygon); 41 | b2Assert(m_fixtureB->GetType() == b2Shape::e_circle); 42 | } 43 | 44 | void b2PolygonAndCircleContact::Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB) 45 | { 46 | b2CollidePolygonAndCircle( manifold, 47 | (b2PolygonShape*)m_fixtureA->GetShape(), xfA, 48 | (b2CircleShape*)m_fixtureB->GetShape(), xfB); 49 | } 50 | -------------------------------------------------------------------------------- /libs/Box2D/Dynamics/Contacts/b2PolygonContact.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include 27 | 28 | b2Contact* b2PolygonContact::Create(b2Fixture* fixtureA, int32, b2Fixture* fixtureB, int32, b2BlockAllocator* allocator) 29 | { 30 | void* mem = allocator->Allocate(sizeof(b2PolygonContact)); 31 | return new (mem) b2PolygonContact(fixtureA, fixtureB); 32 | } 33 | 34 | void b2PolygonContact::Destroy(b2Contact* contact, b2BlockAllocator* allocator) 35 | { 36 | ((b2PolygonContact*)contact)->~b2PolygonContact(); 37 | allocator->Free(contact, sizeof(b2PolygonContact)); 38 | } 39 | 40 | b2PolygonContact::b2PolygonContact(b2Fixture* fixtureA, b2Fixture* fixtureB) 41 | : b2Contact(fixtureA, 0, fixtureB, 0) 42 | { 43 | b2Assert(m_fixtureA->GetType() == b2Shape::e_polygon); 44 | b2Assert(m_fixtureB->GetType() == b2Shape::e_polygon); 45 | } 46 | 47 | void b2PolygonContact::Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB) 48 | { 49 | b2CollidePolygons( manifold, 50 | (b2PolygonShape*)m_fixtureA->GetShape(), xfA, 51 | (b2PolygonShape*)m_fixtureB->GetShape(), xfB); 52 | } 53 | -------------------------------------------------------------------------------- /libs/Box2D/Box2D/Dynamics/Contacts/b2PolygonContact.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include 27 | 28 | b2Contact* b2PolygonContact::Create(b2Fixture* fixtureA, int32, b2Fixture* fixtureB, int32, b2BlockAllocator* allocator) 29 | { 30 | void* mem = allocator->Allocate(sizeof(b2PolygonContact)); 31 | return new (mem) b2PolygonContact(fixtureA, fixtureB); 32 | } 33 | 34 | void b2PolygonContact::Destroy(b2Contact* contact, b2BlockAllocator* allocator) 35 | { 36 | ((b2PolygonContact*)contact)->~b2PolygonContact(); 37 | allocator->Free(contact, sizeof(b2PolygonContact)); 38 | } 39 | 40 | b2PolygonContact::b2PolygonContact(b2Fixture* fixtureA, b2Fixture* fixtureB) 41 | : b2Contact(fixtureA, 0, fixtureB, 0) 42 | { 43 | b2Assert(m_fixtureA->GetType() == b2Shape::e_polygon); 44 | b2Assert(m_fixtureB->GetType() == b2Shape::e_polygon); 45 | } 46 | 47 | void b2PolygonContact::Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB) 48 | { 49 | b2CollidePolygons( manifold, 50 | (b2PolygonShape*)m_fixtureA->GetShape(), xfA, 51 | (b2PolygonShape*)m_fixtureB->GetShape(), xfB); 52 | } 53 | -------------------------------------------------------------------------------- /libs/Box2D/Common/b2GrowableStack.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_GROWABLE_STACK_H 20 | #define B2_GROWABLE_STACK_H 21 | #include 22 | #include 23 | 24 | /// This is a growable LIFO stack with an initial capacity of N. 25 | /// If the stack size exceeds the initial capacity, the heap is used 26 | /// to increase the size of the stack. 27 | template 28 | class b2GrowableStack 29 | { 30 | public: 31 | b2GrowableStack() 32 | { 33 | m_stack = m_array; 34 | m_count = 0; 35 | m_capacity = N; 36 | } 37 | 38 | ~b2GrowableStack() 39 | { 40 | if (m_stack != m_array) 41 | { 42 | b2Free(m_stack); 43 | m_stack = NULL; 44 | } 45 | } 46 | 47 | void Push(const T& element) 48 | { 49 | if (m_count == m_capacity) 50 | { 51 | T* old = m_stack; 52 | m_capacity *= 2; 53 | m_stack = (T*)b2Alloc(m_capacity * sizeof(T)); 54 | memcpy(m_stack, old, m_count * sizeof(T)); 55 | if (old != m_array) 56 | { 57 | b2Free(old); 58 | } 59 | } 60 | 61 | m_stack[m_count] = element; 62 | ++m_count; 63 | } 64 | 65 | T Pop() 66 | { 67 | b2Assert(m_count > 0); 68 | --m_count; 69 | return m_stack[m_count]; 70 | } 71 | 72 | int32 GetCount() 73 | { 74 | return m_count; 75 | } 76 | 77 | private: 78 | T* m_stack; 79 | T m_array[N]; 80 | int32 m_count; 81 | int32 m_capacity; 82 | }; 83 | 84 | 85 | #endif 86 | -------------------------------------------------------------------------------- /libs/Box2D/Box2D/Common/b2GrowableStack.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_GROWABLE_STACK_H 20 | #define B2_GROWABLE_STACK_H 21 | #include 22 | #include 23 | 24 | /// This is a growable LIFO stack with an initial capacity of N. 25 | /// If the stack size exceeds the initial capacity, the heap is used 26 | /// to increase the size of the stack. 27 | template 28 | class b2GrowableStack 29 | { 30 | public: 31 | b2GrowableStack() 32 | { 33 | m_stack = m_array; 34 | m_count = 0; 35 | m_capacity = N; 36 | } 37 | 38 | ~b2GrowableStack() 39 | { 40 | if (m_stack != m_array) 41 | { 42 | b2Free(m_stack); 43 | m_stack = NULL; 44 | } 45 | } 46 | 47 | void Push(const T& element) 48 | { 49 | if (m_count == m_capacity) 50 | { 51 | T* old = m_stack; 52 | m_capacity *= 2; 53 | m_stack = (T*)b2Alloc(m_capacity * sizeof(T)); 54 | memcpy(m_stack, old, m_count * sizeof(T)); 55 | if (old != m_array) 56 | { 57 | b2Free(old); 58 | } 59 | } 60 | 61 | m_stack[m_count] = element; 62 | ++m_count; 63 | } 64 | 65 | T Pop() 66 | { 67 | b2Assert(m_count > 0); 68 | --m_count; 69 | return m_stack[m_count]; 70 | } 71 | 72 | int32 GetCount() 73 | { 74 | return m_count; 75 | } 76 | 77 | private: 78 | T* m_stack; 79 | T m_array[N]; 80 | int32 m_count; 81 | int32 m_capacity; 82 | }; 83 | 84 | 85 | #endif 86 | -------------------------------------------------------------------------------- /libs/Box2D/Common/b2StackAllocator.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #include 20 | #include 21 | 22 | b2StackAllocator::b2StackAllocator() 23 | { 24 | m_index = 0; 25 | m_allocation = 0; 26 | m_maxAllocation = 0; 27 | m_entryCount = 0; 28 | } 29 | 30 | b2StackAllocator::~b2StackAllocator() 31 | { 32 | b2Assert(m_index == 0); 33 | b2Assert(m_entryCount == 0); 34 | } 35 | 36 | void* b2StackAllocator::Allocate(int32 size) 37 | { 38 | b2Assert(m_entryCount < b2_maxStackEntries); 39 | 40 | b2StackEntry* entry = m_entries + m_entryCount; 41 | entry->size = size; 42 | if (m_index + size > b2_stackSize) 43 | { 44 | entry->data = (char*)b2Alloc(size); 45 | entry->usedMalloc = true; 46 | } 47 | else 48 | { 49 | entry->data = m_data + m_index; 50 | entry->usedMalloc = false; 51 | m_index += size; 52 | } 53 | 54 | m_allocation += size; 55 | m_maxAllocation = b2Max(m_maxAllocation, m_allocation); 56 | ++m_entryCount; 57 | 58 | return entry->data; 59 | } 60 | 61 | void b2StackAllocator::Free(void* p) 62 | { 63 | b2Assert(m_entryCount > 0); 64 | b2StackEntry* entry = m_entries + m_entryCount - 1; 65 | b2Assert(p == entry->data); 66 | if (entry->usedMalloc) 67 | { 68 | b2Free(p); 69 | } 70 | else 71 | { 72 | m_index -= entry->size; 73 | } 74 | m_allocation -= entry->size; 75 | --m_entryCount; 76 | 77 | p = NULL; 78 | } 79 | 80 | int32 b2StackAllocator::GetMaxAllocation() const 81 | { 82 | return m_maxAllocation; 83 | } 84 | -------------------------------------------------------------------------------- /libs/Box2D/Box2D/Common/b2StackAllocator.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #include 20 | #include 21 | 22 | b2StackAllocator::b2StackAllocator() 23 | { 24 | m_index = 0; 25 | m_allocation = 0; 26 | m_maxAllocation = 0; 27 | m_entryCount = 0; 28 | } 29 | 30 | b2StackAllocator::~b2StackAllocator() 31 | { 32 | b2Assert(m_index == 0); 33 | b2Assert(m_entryCount == 0); 34 | } 35 | 36 | void* b2StackAllocator::Allocate(int32 size) 37 | { 38 | b2Assert(m_entryCount < b2_maxStackEntries); 39 | 40 | b2StackEntry* entry = m_entries + m_entryCount; 41 | entry->size = size; 42 | if (m_index + size > b2_stackSize) 43 | { 44 | entry->data = (char*)b2Alloc(size); 45 | entry->usedMalloc = true; 46 | } 47 | else 48 | { 49 | entry->data = m_data + m_index; 50 | entry->usedMalloc = false; 51 | m_index += size; 52 | } 53 | 54 | m_allocation += size; 55 | m_maxAllocation = b2Max(m_maxAllocation, m_allocation); 56 | ++m_entryCount; 57 | 58 | return entry->data; 59 | } 60 | 61 | void b2StackAllocator::Free(void* p) 62 | { 63 | b2Assert(m_entryCount > 0); 64 | b2StackEntry* entry = m_entries + m_entryCount - 1; 65 | b2Assert(p == entry->data); 66 | if (entry->usedMalloc) 67 | { 68 | b2Free(p); 69 | } 70 | else 71 | { 72 | m_index -= entry->size; 73 | } 74 | m_allocation -= entry->size; 75 | --m_entryCount; 76 | 77 | p = NULL; 78 | } 79 | 80 | int32 b2StackAllocator::GetMaxAllocation() const 81 | { 82 | return m_maxAllocation; 83 | } 84 | -------------------------------------------------------------------------------- /src/spell/nodes/EnergyNode.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file EnergyNode.cpp 3 | * @author LionZXY 4 | * @project Recast-server 5 | * @date 20.06.17 6 | * @email nikita@kulikof.ru 7 | **/ 8 | #include "spells/nodes/EnergyNode.hpp" 9 | 10 | using namespace std; 11 | /** 12 | * Каждый тик мы рапределяем почти равномерно энергию между всеми дочерними нодами. Энергия переливается только в том случае, если её где-то меньше чем в текущей ноде. 13 | * По умолчанию размер пакета = (Энергия текущего пакета - Энергия дочернего пакета) * 0.1 (10% от транзакции) 14 | * Каждая передача энергии сопровождается потерей. В контексте проекта это называется налог на энергию (energy tax). Это приводит к тому, 15 | * что энергия не вечна и рано или поздно пропадет из плетения. 16 | * 17 | * @param listener Вся передача событий из заклинания наружу происходит с помощью Event'ов 18 | * @param callable Вызывающая нода. Пока не пригождается, но мало ли. Может быть NULL 19 | */ 20 | void EnergyNode::onTick(IEventListener &listener, SpellNode *callable) { 21 | float oldEnergy = energy; 22 | EnergyNode *tmp; 23 | for (SpellNode *node : connectedNodes) { 24 | if (node->isEnergyNode()) { 25 | tmp = (EnergyNode *) node; 26 | if (tmp->getEnergy() < oldEnergy) { 27 | float energyTransfer = ((oldEnergy - tmp->getEnergy()) * 28 | Config::g("spell.general.max_transfer", 0.1F)); 29 | 30 | energy -= tmp->transferEnergy(this, energyTransfer); 31 | } 32 | } 33 | } 34 | } 35 | /** 36 | * 37 | * Передавать энергию ноде можно ТОЛЬКО через этот метод!!! Ни в коем случае не передавать энергию через node->energy+=10; 38 | * Сам метод так же не высчитывает из родительской ноды энергию на передачу. Он возвращает сколько энергии ему удалось забрать 39 | * 40 | * @param from Из какой ноды энергия 41 | * @param count Количество передаваемой энергии 42 | * @return Сколько энергии передалось фактически (нормальным считается @example node->energy -= otherNode->transferEnergy(node,10);) 43 | */ 44 | float EnergyNode::transferEnergy(SpellNode *from, float count) { 45 | float transactionTax = getDistance(from) * Config::g("spell.general.tax", 46 | 0.001F); 47 | if (transactionTax >= count) { 48 | return count; 49 | } 50 | energy += count - transactionTax; 51 | return count; 52 | } 53 | -------------------------------------------------------------------------------- /src/headers/models/collections/PlayersOnline.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file PlayersOnline.h 3 | * @brief PlayerOnline class 4 | * @author LionZXY 5 | * @project Recast-server 6 | * @date 16.06.17 7 | * @email nikita@kulikof.ru 8 | * 9 | * Player online thread-safe class 10 | * 11 | **/ 12 | #ifndef RECAST_SERVER_PLAYERSONLINE_H 13 | #define RECAST_SERVER_PLAYERSONLINE_H 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include "io/SQLite.hpp" 20 | #include "models/Player.hpp" 21 | #include "exceptions/InvalidLoginOrPassword.hpp" 22 | #include "exceptions/ServerFullException.hpp" 23 | 24 | const int SESSION_LENGTH = 128; //// Length of session string 25 | 26 | class PlayersOnline { 27 | public: 28 | PlayersOnline(int playerCount) : maxPlayers(playerCount), currentPlayers(0) {}; 29 | 30 | ~PlayersOnline(); 31 | 32 | std::vector getOnlinePlayers() const; //// Return all online players 33 | 34 | Player *getPlayerBySession(const std::string &session) const; //// Return player by session. Thread-safe 35 | 36 | /** 37 | * Auth player on Server. Get all game data from SQLite 38 | * On failed auth (if user is not in a table) throw InvalidLoginOrPassword 39 | * On fulled server (maxPlayers == currentPlayers) throw ServerFullException 40 | * 41 | * @warning Can throw exception! Must be in try{}catch{} block 42 | * @param login user login 43 | * @param password user password 44 | * @return session string 45 | */ 46 | std::string 47 | authPlayer(std::string login, std::string password); 48 | 49 | /** 50 | * Register player in SQLite. Can throw InvalidLoginOrPassword when login already exists 51 | * @param login new login 52 | * @param password user password 53 | */ 54 | void registerPlayer(std::string login, std::string password); 55 | 56 | /** 57 | * Remove user from user list and save that in SQLite 58 | * 59 | * @param session 60 | * @return 61 | */ 62 | bool logout(const std::string &session); 63 | 64 | int playersOnline() const { return currentPlayers; } 65 | 66 | private: 67 | std::unordered_map players; //// Hashmap 68 | mutable std::mutex lock_writing; 69 | int maxPlayers; 70 | volatile int currentPlayers; 71 | SQLite sqLite; 72 | }; 73 | 74 | 75 | #endif //RECAST_SERVER_PLAYERSONLINE_H 76 | -------------------------------------------------------------------------------- /test/temperature-world/demo.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Oleg Morozenkov on 03.04.17. 3 | // 4 | 5 | #include 6 | #include "temperature-world/interfaces/ITemperatureWorldBoundable.hpp" 7 | #include "lib/crow_all.h" 8 | #include "temperature-world/interfaces/ITemperatureWorld.hpp" 9 | #include "temperature-world/interfaces/IUpdater.hpp" 10 | #include "temperature-world/injectors/BoundTemperatureWorldInjector.hpp" 11 | #include "temperature-world/utils/FileUtils.hpp" 12 | 13 | using namespace std; 14 | 15 | void startUpdater(shared_ptr updater) { 16 | thread t([&]() { 17 | while (true) { 18 | updater->update(); 19 | } 20 | }); 21 | t.detach(); 22 | } 23 | 24 | void startServer(shared_ptr> world, shared_ptr updater) { 25 | crow::SimpleApp app; 26 | 27 | CROW_ROUTE(app, "/")([](){ 28 | return FileUtils::readFile("test/temperature-world/demo-web/index.html"); 29 | }); 30 | CROW_ROUTE(app, "/script.js")([](){ 31 | return FileUtils::readFile("test/temperature-world/demo-web/script.js"); 32 | }); 33 | CROW_ROUTE(app, "/KeyboardState.js")([](){ 34 | return FileUtils::readFile("test/temperature-world/demo-web/KeyboardState.js"); 35 | }); 36 | CROW_ROUTE(app, "/three.min.js")([](){ 37 | return FileUtils::readFile("test/temperature-world/demo-web/three.min.js"); 38 | }); 39 | 40 | CROW_ROUTE(app, "/get_world")([&](){ 41 | crow::json::wvalue json; 42 | size_t i = 0; 43 | world->foreach([&](Coord x, Coord y, Coord z) { 44 | json["blocks"][i]["x"] = x; 45 | json["blocks"][i]["y"] = y; 46 | json["blocks"][i]["z"] = z; 47 | json["blocks"][i]["t"] = world->get(x, y, z); 48 | i++; 49 | }); 50 | return json; 51 | }); 52 | 53 | app.port(18080).multithreaded().run(); 54 | } 55 | 56 | int main() { 57 | Parallelepiped worldBounds(10, 10, 10); 58 | 59 | BoundTemperatureWorldInjector injector; 60 | injector.setWorldBounds(worldBounds); 61 | 62 | auto world = injector.world(); 63 | auto updater = injector.updater(); 64 | 65 | for (Coord x = -2; x <= 2; x++) { 66 | for (Coord z = -2; z <= 2; z++) { 67 | world->set(x, world->bounds().maxY(), z, 750); 68 | } 69 | } 70 | 71 | startUpdater(updater); 72 | startServer(world, updater); 73 | return 0; 74 | } 75 | 76 | --------------------------------------------------------------------------------