diff --git a/.idea/misc.xml b/.idea/misc.xml
index 56bcc68c..fa3f5e2d 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -6,14 +6,12 @@
-
-
-
+
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 17f5a6c4..ab0391aa 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,321 +1,321 @@
add_library(Zepha_Core
- client/Client.cpp
- client/Client.h
- client/conn/ClientNetworkInterpreter.cpp
- client/conn/ClientNetworkInterpreter.h
- client/conn/ServerConnection.cpp
- client/conn/ServerConnection.h
- client/entity/ParticleEntity.cpp
- client/entity/ParticleEntity.h
- client/entity/PlayerEntity.h
- client/entity/WireframeEntity.cpp
- client/entity/WireframeEntity.h
- client/graph/Camera.cpp
- client/graph/Camera.h
- client/graph/Drawable.h
- client/graph/DrawableGroup.cpp
- client/graph/DrawableGroup.h
- client/graph/Font.cpp
- client/graph/Font.h
- client/graph/mesh/ChunkMesh.cpp
- client/graph/mesh/ChunkMesh.h
- client/graph/mesh/ChunkMeshGenerator.cpp
- client/graph/mesh/ChunkMeshGenerator.h
- client/graph/mesh/ChunkRenderElem.h
- client/graph/mesh/ChunkVertex.h
- client/graph/mesh/EntityMesh.cpp
- client/graph/mesh/EntityMesh.h
- client/graph/mesh/EntityVertex.h
- client/graph/mesh/Mesh.cpp
- client/graph/mesh/Mesh.h
- client/graph/mesh/MeshChunk.cpp
- client/graph/mesh/MeshChunk.h
- client/graph/Model.cpp
- client/graph/Model.h
- client/graph/ModelAnimation.cpp
- client/graph/ModelAnimation.h
- client/graph/ModelBone.cpp
- client/graph/ModelBone.h
- client/graph/Renderer.cpp
- client/graph/Renderer.h
- client/graph/shader/BlurShader.cpp
- client/graph/shader/BlurShader.h
- client/graph/shader/EntityGeometryShader.cpp
- client/graph/shader/EntityGeometryShader.h
- client/graph/shader/GuiUniforms.h
- client/graph/shader/LightingShader.cpp
- client/graph/shader/LightingShader.h
- client/graph/shader/Shader.cpp
- client/graph/shader/Shader.h
- client/graph/shader/SSAOShader.cpp
- client/graph/shader/SSAOShader.h
- client/graph/shader/WorldGeometryShader.cpp
- client/graph/shader/WorldGeometryShader.h
- client/graph/Texture.cpp
- client/graph/Texture.h
- client/gui/basic/GuiContainer.cpp
- client/gui/basic/GuiContainer.h
- client/gui/basic/GuiGraph.cpp
- client/gui/basic/GuiGraph.h
- client/gui/basic/GuiInventoryItem.cpp
- client/gui/basic/GuiInventoryItem.h
- client/gui/basic/GuiModel.cpp
- client/gui/basic/GuiModel.h
- client/gui/basic/GuiRect.cpp
- client/gui/basic/GuiRect.h
- client/gui/basic/GuiText.cpp
- client/gui/basic/GuiText.h
- client/gui/compound/GuiImageButton.cpp
- client/gui/compound/GuiImageButton.h
- client/gui/compound/GuiInventoryList.cpp
- client/gui/compound/GuiInventoryList.h
- client/gui/compound/GuiLabelledGraph.cpp
- client/gui/compound/GuiLabelledGraph.cpp
- client/gui/DebugGui.cpp
- client/gui/DebugGui.h
- client/gui/GameGui.cpp
- client/gui/GameGui.h
- client/gui/GameGuiBuilder.cpp
- client/gui/GameGuiBuilder.h
- client/gui/GuiBuilder.cpp
- client/gui/GuiBuilder.h
- client/gui/GuiComponent.cpp
- client/gui/GuiComponent.h
- client/gui/SerialGui.h
- client/Input.cpp
- client/Input.h
- client/LocalServerInstance.cpp
- client/LocalServerInstance.h
- client/menu/MenuSandbox.cpp
- client/menu/MenuSandbox.h
- client/menu/SubgameConfig.h
- client/menu/SubgameDef.h
- client/scene/ConnectScene.cpp
- client/scene/ConnectScene.h
- client/scene/GameScene.cpp
- client/scene/GameScene.h
- client/scene/LuaErrorScene.cpp
- client/scene/LuaErrorScene.h
- client/scene/MainMenuScene.cpp
- client/scene/MainMenuScene.h
- client/scene/Scene.h
- client/scene/SceneManager.cpp
- client/scene/SceneManager.h
- client/stream/ChunkMeshDetails.h
- client/stream/MeshGenStream.cpp
- client/stream/MeshGenStream.h
- client/stream/WorldInterpolationStream.cpp
- client/stream/WorldInterpolationStream.h
- client/Window.cpp
- client/Window.h
- game/atlas/asset/AssetStorage.h
- game/atlas/asset/AssetType.h
- game/atlas/asset/AtlasRef.h
- game/atlas/asset/ModelStore.h
- game/atlas/asset/SerializedModel.h
- game/atlas/asset/ServerTexture.h
- game/atlas/BiomeAtlas.cpp
- game/atlas/BiomeAtlas.h
- game/atlas/DefinitionAtlas.cpp
- game/atlas/DefinitionAtlas.h
- game/atlas/LocalBiomeAtlas.cpp
- game/atlas/LocalBiomeAtlas.h
- game/atlas/LocalDefinitionAtlas.cpp
- game/atlas/LocalDefinitionAtlas.h
- game/atlas/ServerBiomeAtlas.cpp
- game/atlas/ServerBiomeAtlas.h
- game/atlas/ServerDefinitionAtlas.cpp
- game/atlas/ServerDefinitionAtlas.h
- game/atlas/TextureAtlas.cpp
- game/atlas/TextureAtlas.h
+ client/Client.cpp
+ client/Client.h
+ client/conn/ClientNetworkInterpreter.cpp
+ client/conn/ClientNetworkInterpreter.h
+ client/conn/ServerConnection.cpp
+ client/conn/ServerConnection.h
+ client/entity/ParticleEntity.cpp
+ client/entity/ParticleEntity.h
+ client/entity/PlayerEntity.h
+ client/entity/WireframeEntity.cpp
+ client/entity/WireframeEntity.h
+ client/graph/Camera.cpp
+ client/graph/Camera.h
+ client/graph/Drawable.h
+ client/graph/DrawableGroup.cpp
+ client/graph/DrawableGroup.h
+ client/graph/Font.cpp
+ client/graph/Font.h
+ client/graph/mesh/ChunkMesh.cpp
+ client/graph/mesh/ChunkMesh.h
+ client/graph/mesh/ChunkMeshGenerator.cpp
+ client/graph/mesh/ChunkMeshGenerator.h
+ client/graph/mesh/ChunkRenderElem.h
+ client/graph/mesh/ChunkVertex.h
+ client/graph/mesh/EntityMesh.cpp
+ client/graph/mesh/EntityMesh.h
+ client/graph/mesh/EntityVertex.h
+ client/graph/mesh/Mesh.cpp
+ client/graph/mesh/Mesh.h
+ client/graph/mesh/MeshChunk.cpp
+ client/graph/mesh/MeshChunk.h
+ client/graph/Model.cpp
+ client/graph/Model.h
+ client/graph/ModelAnimation.cpp
+ client/graph/ModelAnimation.h
+ client/graph/ModelBone.cpp
+ client/graph/ModelBone.h
+ client/graph/Renderer.cpp
+ client/graph/Renderer.h
+ client/graph/shader/BlurShader.cpp
+ client/graph/shader/BlurShader.h
+ client/graph/shader/EntityGeometryShader.cpp
+ client/graph/shader/EntityGeometryShader.h
+ client/graph/shader/GuiUniforms.h
+ client/graph/shader/LightingShader.cpp
+ client/graph/shader/LightingShader.h
+ client/graph/shader/Shader.cpp
+ client/graph/shader/Shader.h
+ client/graph/shader/SSAOShader.cpp
+ client/graph/shader/SSAOShader.h
+ client/graph/shader/WorldGeometryShader.cpp
+ client/graph/shader/WorldGeometryShader.h
+ client/graph/Texture.cpp
+ client/graph/Texture.h
+ client/gui/basic/GuiContainer.cpp
+ client/gui/basic/GuiContainer.h
+ client/gui/basic/GuiGraph.cpp
+ client/gui/basic/GuiGraph.h
+ client/gui/basic/GuiInventoryItem.cpp
+ client/gui/basic/GuiInventoryItem.h
+ client/gui/basic/GuiModel.cpp
+ client/gui/basic/GuiModel.h
+ client/gui/basic/GuiRect.cpp
+ client/gui/basic/GuiRect.h
+ client/gui/basic/GuiText.cpp
+ client/gui/basic/GuiText.h
+ client/gui/compound/GuiImageButton.cpp
+ client/gui/compound/GuiImageButton.h
+ client/gui/compound/GuiInventoryList.cpp
+ client/gui/compound/GuiInventoryList.h
+ client/gui/compound/GuiLabelledGraph.cpp
+ client/gui/compound/GuiLabelledGraph.cpp
+ client/gui/DebugGui.cpp
+ client/gui/DebugGui.h
+ client/gui/GameGui.cpp
+ client/gui/GameGui.h
+ client/gui/GameGuiBuilder.cpp
+ client/gui/GameGuiBuilder.h
+ client/gui/GuiBuilder.cpp
+ client/gui/GuiBuilder.h
+ client/gui/GuiComponent.cpp
+ client/gui/GuiComponent.h
+ client/gui/SerialGui.h
+ client/Input.cpp
+ client/Input.h
+ client/LocalServerInstance.cpp
+ client/LocalServerInstance.h
+ client/menu/MenuSandbox.cpp
+ client/menu/MenuSandbox.h
+ client/menu/SubgameConfig.h
+ client/menu/SubgameDef.h
+ client/scene/ConnectScene.cpp
+ client/scene/ConnectScene.h
+ client/scene/GameScene.cpp
+ client/scene/GameScene.h
+ client/scene/LuaErrorScene.cpp
+ client/scene/LuaErrorScene.h
+ client/scene/MainMenuScene.cpp
+ client/scene/MainMenuScene.h
+ client/scene/Scene.h
+ client/scene/SceneManager.cpp
+ client/scene/SceneManager.h
+ client/stream/ChunkMeshDetails.h
+ client/stream/MeshGenStream.cpp
+ client/stream/MeshGenStream.h
+ client/stream/WorldInterpolationStream.cpp
+ client/stream/WorldInterpolationStream.h
+ client/Window.cpp
+ client/Window.h
+ game/atlas/asset/AssetStorage.h
+ game/atlas/asset/AssetType.h
+ game/atlas/asset/AtlasRef.h
+ game/atlas/asset/ModelStore.h
+ game/atlas/asset/SerializedModel.h
+ game/atlas/asset/ServerTexture.h
+ game/atlas/BiomeAtlas.cpp
+ game/atlas/BiomeAtlas.h
+ game/atlas/DefinitionAtlas.cpp
+ game/atlas/DefinitionAtlas.h
+ game/atlas/LocalBiomeAtlas.cpp
+ game/atlas/LocalBiomeAtlas.h
+ game/atlas/LocalDefinitionAtlas.cpp
+ game/atlas/LocalDefinitionAtlas.h
+ game/atlas/ServerBiomeAtlas.cpp
+ game/atlas/ServerBiomeAtlas.h
+ game/atlas/ServerDefinitionAtlas.cpp
+ game/atlas/ServerDefinitionAtlas.h
+ game/atlas/TextureAtlas.cpp
+ game/atlas/TextureAtlas.h
game/def/BiomeDef.h
- game/def/BlockDef.cpp
- game/def/BlockDef.h
- game/def/CraftItemDef.cpp
- game/def/CraftItemDef.h
- game/def/ItemDef.h
- game/def/mesh/BlockModel.cpp
- game/def/mesh/BlockModel.h
- game/def/mesh/BlockModelVertex.h
- game/def/mesh/MeshPart.cpp
- game/def/mesh/MeshPart.h
- game/def/mesh/SelectionBox.h
- game/def/mesh/ShaderMod.h
- game/LocalSubgame.cpp
- game/LocalSubgame.h
- game/ServerSubgame.cpp
- game/ServerSubgame.h
- game/Subgame.h
- lua/Callback.h
- lua/customization/vec3.hpp
- lua/ErrorFormatter.cpp
- lua/ErrorFormatter.h
- lua/LocalLuaParser.cpp
- lua/LocalLuaParser.h
- lua/LocalModHandler.cpp
- lua/LocalModHandler.h
- lua/LuaKeybindHandler.cpp
- lua/LuaKeybindHandler.h
- lua/LuaMod.cpp
- lua/LuaMod.h
- lua/LuaParser.cpp
- lua/LuaParser.h
- lua/modules/BaseModule.h
- lua/modules/create_structure.h
- lua/modules/Dimension.cpp
- lua/modules/Dimension.h
- lua/modules/mSetGui.h
- lua/modules/mStartGame.h
- lua/modules/SubgameModule.cpp
- lua/modules/SubgameModule.h
- lua/modules/Time.cpp
- lua/modules/Time.h
- lua/register/RegisterBiome.h
+ game/def/BlockDef.cpp
+ game/def/BlockDef.h
+ game/def/CraftItemDef.cpp
+ game/def/CraftItemDef.h
+ game/def/ItemDef.h
+ game/def/mesh/BlockModel.cpp
+ game/def/mesh/BlockModel.h
+ game/def/mesh/BlockModelVertex.h
+ game/def/mesh/MeshPart.cpp
+ game/def/mesh/MeshPart.h
+ game/def/mesh/SelectionBox.h
+ game/def/mesh/ShaderMod.h
+ game/LocalSubgame.cpp
+ game/LocalSubgame.h
+ game/ServerSubgame.cpp
+ game/ServerSubgame.h
+ game/Subgame.h
+ lua/Callback.h
+ lua/customization/vec3.hpp
+ lua/ErrorFormatter.cpp
+ lua/ErrorFormatter.h
+ lua/LocalLuaParser.cpp
+ lua/LocalLuaParser.h
+ lua/LocalModHandler.cpp
+ lua/LocalModHandler.h
+ lua/LuaKeybindHandler.cpp
+ lua/LuaKeybindHandler.h
+ lua/LuaMod.cpp
+ lua/LuaMod.h
+ lua/LuaParser.cpp
+ lua/LuaParser.h
+ lua/modules/BaseModule.h
+ lua/modules/create_structure.h
+ lua/modules/Dimension.cpp
+ lua/modules/Dimension.h
+ lua/modules/mSetGui.h
+ lua/modules/mStartGame.h
+ lua/modules/SubgameModule.cpp
+ lua/modules/SubgameModule.h
+ lua/modules/Time.cpp
+ lua/modules/Time.h
+ lua/register/RegisterBiome.h
lua/register/RegisterBlock.h
lua/register/RegisterItem.h
- lua/register/RegisterKeybind.h
- lua/ServerLuaParser.cpp
- lua/ServerLuaParser.h
- lua/ServerModHandler.cpp
- lua/ServerModHandler.h
- lua/usertype/AnimationManager.cpp
- lua/usertype/AnimationManager.h
- lua/usertype/BaseUsertype.h
- lua/usertype/Dimension.cpp
- lua/usertype/Dimension.h
- lua/usertype/Entity.cpp
- lua/usertype/Entity.h
- lua/usertype/Inventory.cpp
- lua/usertype/Inventory.h
- lua/usertype/InventoryList.cpp
- lua/usertype/InventoryList.h
- lua/usertype/ItemStack.cpp
- lua/usertype/ItemStack.h
- lua/usertype/LuaGuiElement.cpp
- lua/usertype/LuaGuiElement.h
- lua/usertype/Player.cpp
- lua/usertype/Player.h
- lua/usertype/SubgameUsertype.h
- lua/usertype/Target.cpp
- lua/usertype/Target.h
- server/Server.cpp
- server/Server.h
- server/ServerClient.cpp
- server/ServerClient.h
- server/ServerClients.cpp
- server/ServerClients.h
- server/ServerConfig.cpp
- server/ServerConfig.h
- server/stream/ServerGenStream.cpp
- server/stream/ServerGenStream.h
- server/stream/ServerPacketStream.cpp
- server/stream/ServerPacketStream.h
- StartGame.h
- util/Any.h
- util/CovariantPtr.h
- util/frustum/Frustum.cpp
- util/frustum/Frustum.h
- util/frustum/FrustumAABB.cpp
- util/frustum/FrustumAABB.h
- util/frustum/FrustumPlane.cpp
- util/frustum/FrustumPlane.h
- util/Interp.h
- util/Lockable.h
- util/Log.h
- util/Mat4Conv.h
- util/net/Address.h
- util/net/Deserializer.h
- util/net/NetHandler.cpp
- util/net/NetHandler.h
- util/net/NetState.h
- util/net/Packet.cpp
- util/net/Packet.h
- util/net/PacketView.cpp
- util/net/PacketView.h
- util/net/Serializer.h
- util/Ray.cpp
- util/Ray.h
- util/RIE.h
- util/Schematic.cpp
- util/Schematic.h
- util/Space.h
- util/Target.cpp
- util/Target.h
- util/Timer.cpp
- util/Timer.h
- util/Util.h
- util/Vec.h
- util/Voronoi3D.cpp
- util/Voronoi3D.h
- world/dim/chunk/Chunk.cpp
- world/dim/chunk/Chunk.h
- world/dim/chunk/MapBlock.cpp
- world/dim/chunk/MapBlock.h
- world/dim/chunk/Region.cpp
- world/dim/chunk/Region.h
- world/dim/Dimension.cpp
- world/dim/Dimension.h
- world/dim/DimensionBase.cpp
- world/dim/DimensionBase.h
- world/dim/ent/AnimationSegment.h
- world/dim/ent/AnimationState.cpp
- world/dim/ent/AnimationState.h
- world/dim/ent/AnimChannel.cpp
- world/dim/ent/AnimChannel.h
- world/dim/ent/Collision.cpp
- world/dim/ent/Collision.h
- world/dim/ent/DrawableEntity.cpp
- world/dim/ent/DrawableEntity.h
- world/dim/ent/Entity.cpp
- world/dim/ent/Entity.h
- world/dim/ent/LocalLuaEntity.cpp
- world/dim/ent/LocalLuaEntity.h
- world/dim/ent/LuaEntity.cpp
- world/dim/ent/LuaEntity.h
- world/dim/ent/ServerLuaEntity.cpp
- world/dim/ent/ServerLuaEntity.h
- world/dim/file/FileManipulator.cpp
- world/dim/file/FileManipulator.h
- world/dim/LocalDimension.cpp
- world/dim/LocalDimension.h
- world/dim/ServerDimension.cpp
- world/dim/ServerDimension.h
- world/gen/MapGen.cpp
- world/gen/MapGen.h
- world/gen/MapGenProps.cpp
- world/gen/MapGenProps.h
- world/gen/NoiseSample.cpp
- world/gen/NoiseSample.h
- world/inv/Inventory.cpp
- world/inv/Inventory.h
- world/inv/InventoryList.cpp
- world/inv/InventoryList.h
- world/inv/InventoryRefs.cpp
- world/inv/InventoryRefs.h
- world/inv/ItemStack.cpp
- world/inv/ItemStack.h
- world/inv/LocalInventory.cpp
- world/inv/LocalInventory.h
- world/inv/LocalInventoryRefs.cpp
- world/inv/LocalInventoryRefs.h
- world/inv/ServerInventory.cpp
- world/inv/ServerInventory.h
- world/inv/ServerInventoryList.cpp
- world/inv/ServerInventoryList.h
- world/inv/ServerInventoryRefs.cpp
- world/inv/ServerInventoryRefs.h
- world/LocalWorld.cpp
- world/LocalWorld.h
- world/player/LocalPlayer.cpp
- world/player/LocalPlayer.h
- world/player/Player.cpp
- world/player/Player.h
- world/player/ServerPlayer.cpp
- world/player/ServerPlayer.h
- world/ServerWorld.cpp
- world/ServerWorld.h
- world/World.cpp
- world/World.h
+ lua/register/RegisterKeybind.h
+ lua/ServerLuaParser.cpp
+ lua/ServerLuaParser.h
+ lua/ServerModHandler.cpp
+ lua/ServerModHandler.h
+ lua/usertype/AnimationManager.cpp
+ lua/usertype/AnimationManager.h
+ lua/usertype/BaseUsertype.h
+ lua/usertype/Dimension.cpp
+ lua/usertype/Dimension.h
+ lua/usertype/Entity.cpp
+ lua/usertype/Entity.h
+ lua/usertype/Inventory.cpp
+ lua/usertype/Inventory.h
+ lua/usertype/InventoryList.cpp
+ lua/usertype/InventoryList.h
+ lua/usertype/ItemStack.cpp
+ lua/usertype/ItemStack.h
+ lua/usertype/LuaGuiElement.cpp
+ lua/usertype/LuaGuiElement.h
+ lua/usertype/Player.cpp
+ lua/usertype/Player.h
+ lua/usertype/SubgameUsertype.h
+ lua/usertype/Target.cpp
+ lua/usertype/Target.h
+ server/Server.cpp
+ server/Server.h
+ server/ServerClient.cpp
+ server/ServerClient.h
+ server/ServerClients.cpp
+ server/ServerClients.h
+ server/ServerConfig.cpp
+ server/ServerConfig.h
+ server/stream/ServerGenStream.cpp
+ server/stream/ServerGenStream.h
+ server/stream/ServerPacketStream.cpp
+ server/stream/ServerPacketStream.h
+ StartGame.h
+ util/Any.h
+ util/CovariantPtr.h
+ util/frustum/Frustum.cpp
+ util/frustum/Frustum.h
+ util/frustum/FrustumAABB.cpp
+ util/frustum/FrustumAABB.h
+ util/frustum/FrustumPlane.cpp
+ util/frustum/FrustumPlane.h
+ util/Interp.h
+ util/Lockable.h
+ util/Log.h
+ util/Mat4Conv.h
+ util/net/Address.h
+ util/net/Deserializer.h
+ util/net/NetHandler.cpp
+ util/net/NetHandler.h
+ util/net/NetState.h
+ util/net/Packet.cpp
+ util/net/Packet.h
+ util/net/PacketView.cpp
+ util/net/PacketView.h
+ util/net/Serializer.h
+ util/Ray.cpp
+ util/Ray.h
+ util/RIE.h
+ util/Schematic.cpp
+ util/Schematic.h
+ util/Space.h
+ util/Target.cpp
+ util/Target.h
+ util/Timer.cpp
+ util/Timer.h
+ util/Util.h
+ util/Vec.h
+ util/Voronoi3D.cpp
+ util/Voronoi3D.h
+ world/dim/chunk/Chunk.cpp
+ world/dim/chunk/Chunk.h
+ world/dim/chunk/MapBlock.cpp
+ world/dim/chunk/MapBlock.h
+ world/dim/chunk/Region.cpp
+ world/dim/chunk/Region.h
+ world/dim/Dimension.cpp
+ world/dim/Dimension.h
+ world/dim/DimensionBase.cpp
+ world/dim/DimensionBase.h
+ world/dim/ent/AnimationSegment.h
+ world/dim/ent/AnimationState.cpp
+ world/dim/ent/AnimationState.h
+ world/dim/ent/AnimChannel.cpp
+ world/dim/ent/AnimChannel.h
+ world/dim/ent/Collision.cpp
+ world/dim/ent/Collision.h
+ world/dim/ent/DrawableEntity.cpp
+ world/dim/ent/DrawableEntity.h
+ world/dim/ent/Entity.cpp
+ world/dim/ent/Entity.h
+ world/dim/ent/LocalLuaEntity.cpp
+ world/dim/ent/LocalLuaEntity.h
+ world/dim/ent/LuaEntity.cpp
+ world/dim/ent/LuaEntity.h
+ world/dim/ent/ServerLuaEntity.cpp
+ world/dim/ent/ServerLuaEntity.h
+ world/dim/file/FileManipulator.cpp
+ world/dim/file/FileManipulator.h
+ world/dim/LocalDimension.cpp
+ world/dim/LocalDimension.h
+ world/dim/ServerDimension.cpp
+ world/dim/ServerDimension.h
+ world/gen/MapGen.cpp
+ world/gen/MapGen.h
+ world/gen/MapGenProps.cpp
+ world/gen/MapGenProps.h
+ world/gen/NoiseSample.cpp
+ world/gen/NoiseSample.h
+ world/inv/Inventory.cpp
+ world/inv/Inventory.h
+ world/inv/InventoryList.cpp
+ world/inv/InventoryList.h
+ world/inv/InventoryRefs.cpp
+ world/inv/InventoryRefs.h
+ world/inv/ItemStack.cpp
+ world/inv/ItemStack.h
+ world/inv/LocalInventory.cpp
+ world/inv/LocalInventory.h
+ world/inv/LocalInventoryRefs.cpp
+ world/inv/LocalInventoryRefs.h
+ world/inv/ServerInventory.cpp
+ world/inv/ServerInventory.h
+ world/inv/ServerInventoryList.cpp
+ world/inv/ServerInventoryList.h
+ world/inv/ServerInventoryRefs.cpp
+ world/inv/ServerInventoryRefs.h
+ world/LocalWorld.cpp
+ world/LocalWorld.h
+ world/player/LocalPlayer.cpp
+ world/player/LocalPlayer.h
+ world/player/Player.cpp
+ world/player/Player.h
+ world/player/ServerPlayer.cpp
+ world/player/ServerPlayer.h
+ world/ServerWorld.cpp
+ world/ServerWorld.h
+ world/World.cpp
+ world/World.h
util/net/Address.cpp util/Bounds.cpp util/Bounds.h lua/register/CreateRegister.h lua/register/CreateRegister.cpp)
target_include_directories(Zepha_Core PUBLIC .)
\ No newline at end of file
diff --git a/src/Main.cpp b/src/Main.cpp
index 51bc0c5f..f00e3384 100644
--- a/src/Main.cpp
+++ b/src/Main.cpp
@@ -21,12 +21,13 @@
/**
* Main entrance point to the program. (Am I really describing what the main function is?)
- * Intentionally kept minimal to allow for testing. Real startup logic is done in StartGame. *
+ * Intentionally kept minimal to allow for testing. Real startup logic is done in StartGame.
+ *
* @param argc - Argument array length
* @param argv - Argument array
* @returns - A numerical value indicating exit status.
*/
int main(int argc, char* argv[]) {
- return StartGame(argc, argv);
+ return StartGame(argc, argv);
}
diff --git a/src/StartGame.h b/src/StartGame.h
index d52444f2..dcaf4421 100644
--- a/src/StartGame.h
+++ b/src/StartGame.h
@@ -11,7 +11,9 @@
#include "client/Client.h"
#include "server/Server.h"
-enum class Mode { CLIENT, SERVER };
+enum class Mode {
+ CLIENT, SERVER
+};
/**
@@ -23,22 +25,21 @@ enum class Mode { CLIENT, SERVER };
*/
std::map ParseArgs(int argc, char* argv[]) {
- //Collect arguments into `args` map
- std::map args;
- for (int i = 1; i < argc; i++) {
-
- std::string arg(argv[i]);
- size_t equals = arg.find('=');
- std::string first = (equals == -1) ? arg : arg.substr(0, equals);
-
- if (args.count(first)) throw std::invalid_argument("Duplicate argument " + first + ".");
-
- if (equals == -1) args.emplace(first, "");
- else if (equals == arg.length() - 1) throw std::invalid_argument("Empty argument " + first + ".");
- else args.emplace(first, arg.substr(equals + 1, arg.length()));
- }
-
- return args;
+ std::map args;
+ for (int i = 1; i < argc; i++) {
+
+ std::string arg(argv[i]);
+ size_t equals = arg.find('=');
+ std::string first = (equals == -1) ? arg : arg.substr(0, equals);
+
+ if (args.count(first)) throw std::invalid_argument("Duplicate argument " + first + ".");
+
+ if (equals == -1) args.emplace(first, "");
+ else if (equals == arg.length() - 1) throw std::invalid_argument("Empty argument " + first + ".");
+ else args.emplace(first, arg.substr(equals + 1, arg.length()));
+ }
+
+ return args;
}
@@ -50,74 +51,63 @@ std::map ParseArgs(int argc, char* argv[]) {
*/
int StartGame(int argc, char* argv[]) {
- Mode mode = Mode::CLIENT;
-
- try {
- unsigned short port = Address::DEFAULT_PORT;
- std::string subgame = "";
- bool ascii = true;
-
- /**
- * Handle command line arguments.
- * @arg mode ("client" | "server") - Whether to initialize a client instance, or a server. Defaults to "client".
- * @arg port (unsigned short) - The port that the server should listen on. Defaults to Address::DEFAULT_PORT.
- * @arg subgame (std::string) - The subgame that the server should load.
- * @arg noascii - Switch to disable ASCII from the console output.
- */
-
- for (auto arg : ParseArgs(argc, argv)) {
- switch (Util::hash(arg.first.c_str())) {
- default:
- throw std::runtime_error("Invalid argument '" + arg.first + "'.");
-
- case Util::hash("--mode"):
- if (arg.second == "client") mode = Mode::CLIENT;
- else if (arg.second == "server") mode = Mode::SERVER;
- else throw std::runtime_error("Invalid mode specified.");
- break;
+ Mode mode = Mode::CLIENT;
+
+ try {
+ unsigned short port = Address::DEFAULT_PORT;
+ std::string subgame = "";
+ bool ascii = true;
+
+ /**
+ * Handle command line arguments.
+ * @arg mode ("client" | "server") - Whether to initialize a client instance, or a server. Defaults to "client".
+ * @arg port (unsigned short) - The port that the server should listen on. Defaults to Address::DEFAULT_PORT.
+ * @arg subgame (std::string) - The subgame that the server should load.
+ * @arg noascii - Switch to disable ASCII from the console output.
+ */
+
+ for (auto arg : ParseArgs(argc, argv)) {
+ switch (Util::hash(arg.first.c_str())) {
+ default: throw std::runtime_error("Invalid argument '" + arg.first + "'.");
+
+ case Util::hash("--mode"):
+ if (arg.second == "client") mode = Mode::CLIENT;
+ else if (arg.second == "server") mode = Mode::SERVER;
+ else throw std::runtime_error("Invalid mode specified.");
+ break;
// case Util::hash("--address"):
// addr.host = arg.second;
// break;
-
- case Util::hash("--port"):
- port = static_cast(stoi(arg.second));
- break;
-
- case Util::hash("--subgame"):
- subgame = arg.second;
- break;
-
- case Util::hash("--noascii"):
- ascii = false;
- break;
- }
- }
-
- if (ascii) {
- Log::clear();
- std::cout <<
- "\n"
- "\t\t ____ ____ ____ _ _ __ \n"
- "\t\t(__ )( __)( _ \\/ )( \\ / _\\ \n"
- "\t\t / _/ ) _) ) __/) __ (/ \\\n"
- "\t\t(____)(____)(__) \\_)(_/\\_/\\_/\n" << std::endl;
- }
-
- switch (mode) {
- case Mode::CLIENT: {
- Client c({1366, 768});
- break; }
-
- case Mode::SERVER: {
- Server s(port, subgame);
- break; }
- }
-
- return 0;
- }
- catch (const std::exception& e) {
- std::cout << Log::err << "Zepha failed to start.\n" << e.what() << Log::endl;
- return 1;
- }
+
+ case Util::hash("--port"): port = static_cast(stoi(arg.second));
+ break;
+
+ case Util::hash("--subgame"): subgame = arg.second;
+ break;
+
+ case Util::hash("--noascii"): ascii = false;
+ break;
+ }
+ }
+
+ if (ascii) {
+ Log::clear();
+ std::cout <<
+ "\n"
+ "\t\t ____ ____ ____ _ _ __ \n"
+ "\t\t(__ )( __)( _ \\/ )( \\ / _\\ \n"
+ "\t\t / _/ ) _) ) __/) __ (/ \\\n"
+ "\t\t(____)(____)(__) \\_)(_/\\_/\\_/\n" << std::endl;
+ }
+
+ if (mode == Mode::CLIENT) Client({ 1366, 768 });
+ else Server(port, subgame);
+
+ return 0;
+ }
+ catch (const std::exception& e) {
+ std::cout << Log::err << "Zepha failed to start.\n" << e.what() << Log::endl;
+ return 1;
+ }
}
diff --git a/src/client/Client.cpp b/src/client/Client.cpp
index a603fb92..7edc72d8 100644
--- a/src/client/Client.cpp
+++ b/src/client/Client.cpp
@@ -18,12 +18,12 @@
*/
Client::Client(glm::ivec2 window) :
- renderer(window) {
-
- std::cout << Log::info << "Starting Zepha Client." << Log::endl;
-
- scene.setScene(std::make_unique(*this));
- while (!renderer.window.shouldClose()) loop();
+ renderer(window) {
+
+ std::cout << Log::info << "Starting Zepha Client." << Log::endl;
+
+ scene.setScene(std::make_unique(*this));
+ while (!renderer.window.shouldClose()) loop();
}
@@ -33,7 +33,7 @@ Client::Client(glm::ivec2 window) :
*/
double Client::getDelta() {
- return delta;
+ return delta;
}
@@ -44,11 +44,11 @@ double Client::getDelta() {
*/
void Client::startLocalServer(const std::string& subgame) {
- //TODO: Implement Local Server
+ //TODO: Implement Local Server
// localServer = std::make_shared(executablePath, addr.port, state.subgame);
// localServer->start();
-
- scene.setScene(std::make_unique(*this, Address { "127.0.0.1", Address::DEFAULT_PORT }));
+
+ scene.setScene(std::make_unique(*this, Address{ "127.0.0.1", Address::DEFAULT_PORT }));
}
@@ -58,12 +58,12 @@ void Client::startLocalServer(const std::string& subgame) {
*/
void Client::loop() {
- double now = glfwGetTime();
- delta = now - timeElapsed;
- timeElapsed = now;
-
- glfwPollEvents();
-
- scene.update();
- renderer.update(delta);
+ double now = glfwGetTime();
+ delta = now - timeElapsed;
+ timeElapsed = now;
+
+ glfwPollEvents();
+
+ scene.update();
+ renderer.update(delta);
}
\ No newline at end of file
diff --git a/src/client/Client.h b/src/client/Client.h
index 8d5d5d45..7f10d32e 100644
--- a/src/client/Client.h
+++ b/src/client/Client.h
@@ -16,26 +16,27 @@
class LocalServerInstance;
class Client {
-public:
- Client(const Client& o) = delete;
- explicit Client(glm::ivec2 window);
-
- double getDelta();
-
- void startLocalServer(const std::string& subgame);
-
- Renderer renderer;
- SceneManager scene;
- ServerConnection connection {};
-
- std::shared_ptr game = std::make_shared("../assets/textures");
-
-private:
- void loop();
-
- std::shared_ptr localServer = nullptr;
-
- double delta = 0;
- double timeElapsed = 0;
+ public:
+ Client(const Client& o) = delete;
+
+ explicit Client(glm::ivec2 window);
+
+ double getDelta();
+
+ void startLocalServer(const std::string& subgame);
+
+ Renderer renderer;
+ SceneManager scene;
+ ServerConnection connection{};
+
+ std::shared_ptr game = std::make_shared("../assets/textures");
+
+ private:
+ void loop();
+
+ std::shared_ptr localServer = nullptr;
+
+ double delta = 0;
+ double timeElapsed = 0;
};
diff --git a/src/client/Input.cpp b/src/client/Input.cpp
index 03f9e273..d82913aa 100644
--- a/src/client/Input.cpp
+++ b/src/client/Input.cpp
@@ -11,161 +11,161 @@
#include "Window.h"
Input::Input() {
- for (bool& key : keysDown) key = false;
- for (bool& key : keysPressed) key = false;
- for (bool& key : keysReleased) key = false;
- for (bool& key : keysNew) key = false;
+ for (bool& key : keysDown) key = false;
+ for (bool& key : keysPressed) key = false;
+ for (bool& key : keysReleased) key = false;
+ for (bool& key : keysNew) key = false;
}
-void Input::init(GLFWwindow *window, glm::ivec2* winDimensions) {
- this->window = window;
- this->winDimensions = winDimensions;
- glfwSetKeyCallback(window, keyCallback);
- glfwSetScrollCallback(window, scrollCallback);
+void Input::init(GLFWwindow* window, glm::ivec2* winDimensions) {
+ this->window = window;
+ this->winDimensions = winDimensions;
+ glfwSetKeyCallback(window, keyCallback);
+ glfwSetScrollCallback(window, scrollCallback);
}
void Input::setCallback(std::function callback) {
- this->callback = callback;
+ this->callback = callback;
}
void Input::update() {
- for (bool &key : keysPressed) key = false;
- for (bool &key : keysReleased) key = false;
-
- for (int i = 0; i < 1024; i++) {
- bool key = keysNew[i];
-
- if (key) {
- if (!keysDown[i]) {
- keysPressed[i] = true;
- if (callback) callback(true, i);
- }
- keysDown[i] = true;
- }
- else {
- if (keysDown[i]) {
- keysReleased[i] = true;
- if (callback) callback(false, i);
- }
- keysDown[i] = false;
- }
- }
-
- for (auto& s : mouseState) {
- s.pressed = false;
- s.released = false;
- }
-
- for (int i = 0; i < 12; i++) {
- keysNew[i] = false;
- }
-
- updateMouse(0);
- updateMouse(1);
- updateMouse(2);
-
- if (glfwGetWindowAttrib(window, GLFW_FOCUSED) == GL_FALSE) {
- mouseIsLocked = false;
- delta = {};
- }
- else {
- double mouseX, mouseY;
- glfwGetCursorPos(window, &mouseX, &mouseY);
-
- if (!mouseIsLocked) {
- if (!forceMouseUnlocked && mousePressed(GLFW_MOUSE_BUTTON_LEFT)) {
- glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
- glfwSetCursorPos(window, winDimensions->x / 2, winDimensions->y / 2);
- mouseIsLocked = true;
- }
- }
- else {
- delta = {mouseX - (winDimensions->x / 2), -(mouseY - (winDimensions->y / 2))};
- glfwSetCursorPos(window, winDimensions->x / 2, winDimensions->y / 2);
- }
- }
+ for (bool& key : keysPressed) key = false;
+ for (bool& key : keysReleased) key = false;
+
+ for (int i = 0; i < 1024; i++) {
+ bool key = keysNew[i];
+
+ if (key) {
+ if (!keysDown[i]) {
+ keysPressed[i] = true;
+ if (callback) callback(true, i);
+ }
+ keysDown[i] = true;
+ }
+ else {
+ if (keysDown[i]) {
+ keysReleased[i] = true;
+ if (callback) callback(false, i);
+ }
+ keysDown[i] = false;
+ }
+ }
+
+ for (auto& s : mouseState) {
+ s.pressed = false;
+ s.released = false;
+ }
+
+ for (int i = 0; i < 12; i++) {
+ keysNew[i] = false;
+ }
+
+ updateMouse(0);
+ updateMouse(1);
+ updateMouse(2);
+
+ if (glfwGetWindowAttrib(window, GLFW_FOCUSED) == GL_FALSE) {
+ mouseIsLocked = false;
+ delta = {};
+ }
+ else {
+ double mouseX, mouseY;
+ glfwGetCursorPos(window, &mouseX, &mouseY);
+
+ if (!mouseIsLocked) {
+ if (!forceMouseUnlocked && mousePressed(GLFW_MOUSE_BUTTON_LEFT)) {
+ glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
+ glfwSetCursorPos(window, winDimensions->x / 2, winDimensions->y / 2);
+ mouseIsLocked = true;
+ }
+ }
+ else {
+ delta = { mouseX - (winDimensions->x / 2), -(mouseY - (winDimensions->y / 2)) };
+ glfwSetCursorPos(window, winDimensions->x / 2, winDimensions->y / 2);
+ }
+ }
}
bool Input::keyDown(int key) {
- return keysDown[key];
+ return keysDown[key];
}
bool Input::keyPressed(int key) {
- return keysPressed[key];
+ return keysPressed[key];
}
bool Input::keyReleased(int key) {
- return keysReleased[key];
+ return keysReleased[key];
}
bool Input::mouseDown(int button) {
- return mouseState[button].down;
+ return mouseState[button].down;
}
bool Input::mousePressed(int button) {
- return mouseState[button].pressed;
+ return mouseState[button].pressed;
}
bool Input::mouseReleased(int button) {
- return mouseState[button].released;
+ return mouseState[button].released;
}
void Input::updateMouse(int button) {
- if (glfwGetMouseButton(window, button) == GLFW_PRESS) {
- if (!mouseState[button].down) mouseState[button].pressed = true;
- mouseState[button].down = true;
- }
- else {
- if (mouseState[button].down) mouseState[button].released = true;
- mouseState[button].down = false;
- }
+ if (glfwGetMouseButton(window, button) == GLFW_PRESS) {
+ if (!mouseState[button].down) mouseState[button].pressed = true;
+ mouseState[button].down = true;
+ }
+ else {
+ if (mouseState[button].down) mouseState[button].released = true;
+ mouseState[button].down = false;
+ }
}
void Input::keyCallback(GLFWwindow* window, int key, int code, int action, int mode) {
- auto w = static_cast(glfwGetWindowUserPointer(window));
- if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) glfwSetWindowShouldClose(window, GL_TRUE);
- if (key >= 32 && key < 1024) {
- if (action == GLFW_PRESS) w->input.keysNew[key] = true;
- else if (action == GLFW_RELEASE) w->input.keysNew[key] = false;
- }
+ auto w = static_cast(glfwGetWindowUserPointer(window));
+ if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) glfwSetWindowShouldClose(window, GL_TRUE);
+ if (key >= 32 && key < 1024) {
+ if (action == GLFW_PRESS) w->input.keysNew[key] = true;
+ else if (action == GLFW_RELEASE) w->input.keysNew[key] = false;
+ }
}
-void Input::scrollCallback(GLFWwindow *window, double xO, double yO) {
- auto w = static_cast(glfwGetWindowUserPointer(window));
-
- if (xO > 0) {
- //Right
- w->input.keysNew[11] = true;
- }
- else if (xO < 0) {
- // Left
- w->input.keysNew[10] = true;
- }
-
- if (yO > 0) {
- // Up
- w->input.keysNew[8] = true;
- }
- else if (yO < 0) {
- // Down
- w->input.keysNew[9] = true;
- }
+void Input::scrollCallback(GLFWwindow* window, double xO, double yO) {
+ auto w = static_cast(glfwGetWindowUserPointer(window));
+
+ if (xO > 0) {
+ //Right
+ w->input.keysNew[11] = true;
+ }
+ else if (xO < 0) {
+ // Left
+ w->input.keysNew[10] = true;
+ }
+
+ if (yO > 0) {
+ // Up
+ w->input.keysNew[8] = true;
+ }
+ else if (yO < 0) {
+ // Down
+ w->input.keysNew[9] = true;
+ }
}
void Input::lockMouse(bool lock) {
- forceMouseUnlocked = !lock;
- mouseIsLocked = lock;
- glfwSetCursorPos(window, winDimensions->x / 2, winDimensions->y / 2);
- glfwSetInputMode(window, GLFW_CURSOR, (mouseIsLocked ? GLFW_CURSOR_HIDDEN : GLFW_CURSOR_NORMAL));
- delta = {};
+ forceMouseUnlocked = !lock;
+ mouseIsLocked = lock;
+ glfwSetCursorPos(window, winDimensions->x / 2, winDimensions->y / 2);
+ glfwSetInputMode(window, GLFW_CURSOR, (mouseIsLocked ? GLFW_CURSOR_HIDDEN : GLFW_CURSOR_NORMAL));
+ delta = {};
}
glm::ivec2 Input::mousePos() {
- double xPos, yPos;
- glfwGetCursorPos(window, &xPos, &yPos);
- return glm::ivec2 { static_cast(xPos), static_cast(yPos) };
+ double xPos, yPos;
+ glfwGetCursorPos(window, &xPos, &yPos);
+ return glm::ivec2{ static_cast(xPos), static_cast(yPos) };
}
glm::vec2 Input::mouseDelta() {
- return delta;
+ return delta;
}
diff --git a/src/client/Input.h b/src/client/Input.h
index f3e2aae0..afd09b2b 100644
--- a/src/client/Input.h
+++ b/src/client/Input.h
@@ -9,43 +9,58 @@
#include
class Input {
-public:
- Input();
- void init(GLFWwindow* window, glm::ivec2* winDimensions);
- void setCallback(std::function callback);
-
- void update();
-
- bool keyDown(int key);
- bool keyPressed(int key);
- bool keyReleased(int key);
-
- bool mouseDown(int button);
- bool mousePressed(int button);
- bool mouseReleased(int button);
-
- void lockMouse(bool lock);
- glm::ivec2 mousePos();
- glm::vec2 mouseDelta();
-private:
- void updateMouse(int key);
- static void keyCallback(GLFWwindow* window, int key, int code, int action, int mode);
- static void scrollCallback(GLFWwindow* window, double, double yO);
-
- GLFWwindow* window = nullptr;
- glm::ivec2* winDimensions = nullptr;
-
- bool keysNew[1024] {false};
- bool keysDown[1024] {false};
- bool keysPressed[1024] {false};
- bool keysReleased[1024] {false};
-
- struct mouse { bool down = false; bool pressed = false; bool released = false; };
- std::array mouseState {};
- glm::vec2 delta;
-
- bool mouseIsLocked = false;
- bool forceMouseUnlocked = false;
-
- std::function callback = nullptr;
+ public:
+ Input();
+
+ void init(GLFWwindow* window, glm::ivec2* winDimensions);
+
+ void setCallback(std::function callback);
+
+ void update();
+
+ bool keyDown(int key);
+
+ bool keyPressed(int key);
+
+ bool keyReleased(int key);
+
+ bool mouseDown(int button);
+
+ bool mousePressed(int button);
+
+ bool mouseReleased(int button);
+
+ void lockMouse(bool lock);
+
+ glm::ivec2 mousePos();
+
+ glm::vec2 mouseDelta();
+
+ private:
+ void updateMouse(int key);
+
+ static void keyCallback(GLFWwindow* window, int key, int code, int action, int mode);
+
+ static void scrollCallback(GLFWwindow* window, double, double yO);
+
+ GLFWwindow* window = nullptr;
+ glm::ivec2* winDimensions = nullptr;
+
+ bool keysNew[1024]{ false };
+ bool keysDown[1024]{ false };
+ bool keysPressed[1024]{ false };
+ bool keysReleased[1024]{ false };
+
+ struct mouse {
+ bool down = false;
+ bool pressed = false;
+ bool released = false;
+ };
+ std::array mouseState{};
+ glm::vec2 delta;
+
+ bool mouseIsLocked = false;
+ bool forceMouseUnlocked = false;
+
+ std::function callback = nullptr;
};
\ No newline at end of file
diff --git a/src/client/LocalServerInstance.cpp b/src/client/LocalServerInstance.cpp
index de9a36fb..c498e3e4 100644
--- a/src/client/LocalServerInstance.cpp
+++ b/src/client/LocalServerInstance.cpp
@@ -7,45 +7,45 @@
#include "server/Server.h"
#include
-LocalServerInstance::LocalServerInstance(const std::string &path, unsigned short port, const std::string& subgame) :
- port(port),
- path(path),
- subgame(subgame) {}
+LocalServerInstance::LocalServerInstance(const std::string& path, unsigned short port, const std::string& subgame) :
+ port(port),
+ path(path),
+ subgame(subgame) {}
bool LocalServerInstance::start() {
#ifndef _WIN32
- pid = fork();
- if (pid == 0) {
- const auto sub = ("--subgame=" + subgame);
- char *arr[] = {
- const_cast (""),
+ pid = fork();
+ if (pid == 0) {
+ const auto sub = ("--subgame=" + subgame);
+ char* arr[] = {
+ const_cast (""),
// const_cast ("-iconic"),
- const_cast ("-e"),
- const_cast (path.data()),
- const_cast ("--mode=server"),
- const_cast (sub.data()),
- static_cast(nullptr)
- };
-
- execvp("xterm", arr);
- }
- return true;
+ const_cast ("-e"),
+ const_cast (path.data()),
+ const_cast ("--mode=server"),
+ const_cast (sub.data()),
+ static_cast(nullptr)
+ };
+
+ execvp("xterm", arr);
+ }
+ return true;
#else
- std::thread([&]() {
- Server s(port, subgame);
- }).detach();
- return true;
+ std::thread([&]() {
+ Server s(port, subgame);
+ }).detach();
+ return true;
#endif
}
void LocalServerInstance::stop() {
- #ifndef _WIN32
- if (pid != 0) kill(pid, SIGKILL);
- #else
- std::cout << Log::err << "Local Server destructor not implemented on Windows!" << Log::endl;
- #endif
+#ifndef _WIN32
+ if (pid != 0) kill(pid, SIGKILL);
+#else
+ std::cout << Log::err << "Local Server destructor not implemented on Windows!" << Log::endl;
+#endif
}
LocalServerInstance::~LocalServerInstance() {
- stop();
+ stop();
}
\ No newline at end of file
diff --git a/src/client/LocalServerInstance.h b/src/client/LocalServerInstance.h
index 06c4c05b..582821fb 100644
--- a/src/client/LocalServerInstance.h
+++ b/src/client/LocalServerInstance.h
@@ -7,23 +7,27 @@
#include
#ifndef _WIN32
+
#include
#include
#include
+
#endif
class LocalServerInstance {
-public:
- LocalServerInstance(const std::string& path, unsigned short port, const std::string& subgame);
-
- bool start();
- void stop();
-
- ~LocalServerInstance();
-private:
- std::string path;
- std::string subgame;
- unsigned short port = 0;
-
- int pid = 0;
+ public:
+ LocalServerInstance(const std::string& path, unsigned short port, const std::string& subgame);
+
+ bool start();
+
+ void stop();
+
+ ~LocalServerInstance();
+
+ private:
+ std::string path;
+ std::string subgame;
+ unsigned short port = 0;
+
+ int pid = 0;
};
diff --git a/src/client/Window.cpp b/src/client/Window.cpp
index 2b0309ad..352fd7ba 100644
--- a/src/client/Window.cpp
+++ b/src/client/Window.cpp
@@ -6,85 +6,85 @@
#include "util/Log.h"
-Window::Window() : Window({800, 600}) {};
+Window::Window() : Window({ 800, 600 }) {};
Window::Window(glm::ivec2 win) :
- win(win), center(win.x / 2, win.y / 2) {
-
- if (!glfwInit()) {
- glfwTerminate();
- throw std::runtime_error("Failed to initialize GLFW context.");
- }
-
- // Version 3.3
- glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
- glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
-
- // Compatibility - No Backwards compat, only forwards
- glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
- glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
-
- // Create the window
- if (!(mainWindow = glfwCreateWindow(win.x, win.y, "Zepha", nullptr, nullptr))) {
- glfwTerminate();
- throw std::runtime_error("Failed to initialize GLFW window.");
- }
-
- glfwGetFramebufferSize(mainWindow, &win.x, &win.y);
- glfwMakeContextCurrent(mainWindow);
- glewExperimental = GL_TRUE;
-
- handCursor = glfwCreateStandardCursor(GLFW_HAND_CURSOR);
-
- // Initialize GLEW
- GLenum error;
- if ((error = glewInit()) != GLEW_OK) {
- glfwTerminate();
- glfwDestroyWindow(mainWindow);
- printf("%s", reinterpret_cast(glewGetErrorString(error)));
- throw std::runtime_error("GLEW Fatal error.");
- }
-
- glEnable(GL_DEPTH_TEST);
- glViewport(0, 0, win.x, win.y);
-
- // Setup callbacks
- glfwSetWindowUserPointer(mainWindow, this);
- glfwSetScrollCallback(mainWindow, scrollCallback);
- glfwSetWindowSizeCallback(mainWindow, resizeCallback);
-
- glfwSetInputMode(mainWindow, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
- glfwMaximizeWindow(mainWindow);
-
- input.init(mainWindow, &this->win);
+ win(win), center(win.x / 2, win.y / 2) {
+
+ if (!glfwInit()) {
+ glfwTerminate();
+ throw std::runtime_error("Failed to initialize GLFW context.");
+ }
+
+ // Version 3.3
+ glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
+ glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
+
+ // Compatibility - No Backwards compat, only forwards
+ glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
+ glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
+
+ // Create the window
+ if (!(mainWindow = glfwCreateWindow(win.x, win.y, "Zepha", nullptr, nullptr))) {
+ glfwTerminate();
+ throw std::runtime_error("Failed to initialize GLFW window.");
+ }
+
+ glfwGetFramebufferSize(mainWindow, &win.x, &win.y);
+ glfwMakeContextCurrent(mainWindow);
+ glewExperimental = GL_TRUE;
+
+ handCursor = glfwCreateStandardCursor(GLFW_HAND_CURSOR);
+
+ // Initialize GLEW
+ GLenum error;
+ if ((error = glewInit()) != GLEW_OK) {
+ glfwTerminate();
+ glfwDestroyWindow(mainWindow);
+ printf("%s", reinterpret_cast(glewGetErrorString(error)));
+ throw std::runtime_error("GLEW Fatal error.");
+ }
+
+ glEnable(GL_DEPTH_TEST);
+ glViewport(0, 0, win.x, win.y);
+
+ // Setup callbacks
+ glfwSetWindowUserPointer(mainWindow, this);
+ glfwSetScrollCallback(mainWindow, scrollCallback);
+ glfwSetWindowSizeCallback(mainWindow, resizeCallback);
+
+ glfwSetInputMode(mainWindow, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
+ glfwMaximizeWindow(mainWindow);
+
+ input.init(mainWindow, &this->win);
}
void Window::update() {
- input.update();
+ input.update();
}
bool Window::shouldClose() {
- return static_cast(glfwWindowShouldClose(mainWindow));
+ return static_cast(glfwWindowShouldClose(mainWindow));
}
void Window::swapBuffers() {
- glfwSwapBuffers(mainWindow);
+ glfwSwapBuffers(mainWindow);
}
-void Window::addResizeCallback(const std::string &identifier, std::function cb) {
- resizeCallbacks.emplace(identifier, cb);
+void Window::addResizeCallback(const std::string& identifier, std::function cb) {
+ resizeCallbacks.emplace(identifier, cb);
}
-void Window::removeResizeCallback(const std::string &identifier) {
- resizeCallbacks.erase(identifier);
+void Window::removeResizeCallback(const std::string& identifier) {
+ resizeCallbacks.erase(identifier);
}
glm::ivec2 Window::getSize() {
- return win;
+ return win;
}
void Window::setCursorHand(bool hand) {
- glfwSetCursor(mainWindow, hand ? handCursor : nullptr);
+ glfwSetCursor(mainWindow, hand ? handCursor : nullptr);
}
void Window::scrollCallback(GLFWwindow* window, double xO, double yO) {
@@ -93,16 +93,16 @@ void Window::scrollCallback(GLFWwindow* window, double xO, double yO) {
}
void Window::resizeCallback(GLFWwindow* window, int width, int height) {
- auto w = static_cast(glfwGetWindowUserPointer(window));
-
- glfwGetFramebufferSize(window, &w->win.x, &w->win.y);
- glViewport(0, 0, w->win.x, w->win.y);
-
- w->center = glm::ivec2(w->win.x / 2, w->win.y / 2);
- for (auto& cb : w->resizeCallbacks) cb.second(w->win);
+ auto w = static_cast(glfwGetWindowUserPointer(window));
+
+ glfwGetFramebufferSize(window, &w->win.x, &w->win.y);
+ glViewport(0, 0, w->win.x, w->win.y);
+
+ w->center = glm::ivec2(w->win.x / 2, w->win.y / 2);
+ for (auto& cb : w->resizeCallbacks) cb.second(w->win);
}
Window::~Window() {
- glfwDestroyWindow(mainWindow);
- glfwTerminate();
+ glfwDestroyWindow(mainWindow);
+ glfwTerminate();
}
\ No newline at end of file
diff --git a/src/client/Window.h b/src/client/Window.h
index 3cc8e446..a25c6259 100644
--- a/src/client/Window.h
+++ b/src/client/Window.h
@@ -11,36 +11,42 @@
#include "Input.h"
class Window {
-public:
- Window();
- Window(glm::ivec2 win);
-
- void update();
- bool shouldClose();
- void swapBuffers();
-
- void addResizeCallback(const std::string& identifier, std::function cb);
- void removeResizeCallback(const std::string& identifier);
-
- glm::ivec2 getSize();
- void setCursorHand(bool hand);
-
- ~Window();
-
- Input input;
- GLFWwindow* mainWindow = nullptr;
-private:
- static void scrollCallback(GLFWwindow* window, double xO, double yO);
- static void resizeCallback(GLFWwindow* window, int width, int height);
-
- GLFWcursor* handCursor = nullptr;
-
- glm::ivec2 win;
- glm::ivec2 center;
-
- bool keys[1024] {};
-
- std::map> resizeCallbacks;
-
+ public:
+ Window();
+
+ Window(glm::ivec2 win);
+
+ void update();
+
+ bool shouldClose();
+
+ void swapBuffers();
+
+ void addResizeCallback(const std::string& identifier, std::function cb);
+
+ void removeResizeCallback(const std::string& identifier);
+
+ glm::ivec2 getSize();
+
+ void setCursorHand(bool hand);
+
+ ~Window();
+
+ Input input;
+ GLFWwindow* mainWindow = nullptr;
+ private:
+ static void scrollCallback(GLFWwindow* window, double xO, double yO);
+
+ static void resizeCallback(GLFWwindow* window, int width, int height);
+
+ GLFWcursor* handCursor = nullptr;
+
+ glm::ivec2 win;
+ glm::ivec2 center;
+
+ bool keys[1024]{};
+
+ std::map> resizeCallbacks;
+
};
diff --git a/src/client/conn/ClientNetworkInterpreter.cpp b/src/client/conn/ClientNetworkInterpreter.cpp
index 98485bf6..85194efa 100644
--- a/src/client/conn/ClientNetworkInterpreter.cpp
+++ b/src/client/conn/ClientNetworkInterpreter.cpp
@@ -14,126 +14,131 @@
#include "util/net/NetHandler.h"
#include "world/player/LocalPlayer.h"
-ClientNetworkInterpreter::ClientNetworkInterpreter(ServerConnection &connection, LocalWorld& world) :
- world(world), connection(connection) {}
+ClientNetworkInterpreter::ClientNetworkInterpreter(ServerConnection& connection, LocalWorld& world) :
+ world(world), connection(connection) {}
void ClientNetworkInterpreter::init(std::function)> invCallback) {
- this->onInvPacket = invCallback;
+ this->onInvPacket = invCallback;
}
void ClientNetworkInterpreter::update() {
- recvPackets = 0;
-
- ENetEvent event;
- while (connection.pollEvents(&event)) {
- recvPackets++;
-
- switch (event.type) {
- default: break;
- case ENET_EVENT_TYPE_CONNECT: {
- std::cout << Log::info << "Connected to server "
- << NetHandler::intToIPString(event.peer->address.host)
- << ":" << event.peer->address.port << "." << Log::endl;
- break;
- }
- case ENET_EVENT_TYPE_RECEIVE: {
- std::unique_ptr p = std::make_unique(event.packet);
- receivedPacket(std::move(p));
- break;
- }
- case ENET_EVENT_TYPE_DISCONNECT: {
- std::cout << Log::info << "Disconnected from server "
- << event.peer->address.host << ":" << event.peer->address.port << "." << Log::endl;
- break;
- }
- }
- }
-
- auto player = world.getPlayer();
- if (player) Serializer()
- .appendE(NetField::POS).append(player->getPos())
- .appendE(NetField::VEL).append(player->getVel())
- .appendE(NetField::LOOK_PITCH).append(player->getPitch())
- .appendE(NetField::LOOK_YAW).append(player->getYaw())
- .packet(Packet::Type::THIS_PLAYER_INFO, false).sendTo(connection.getPeer(), Packet::Channel::INTERACT);
+ recvPackets = 0;
+
+ ENetEvent event;
+ while (connection.pollEvents(&event)) {
+ recvPackets++;
+
+ switch (event.type) {
+ default: break;
+ case ENET_EVENT_TYPE_CONNECT: {
+ std::cout << Log::info << "Connected to server "
+ << NetHandler::intToIPString(event.peer->address.host)
+ << ":" << event.peer->address.port << "." << Log::endl;
+ break;
+ }
+ case ENET_EVENT_TYPE_RECEIVE: {
+ std::unique_ptr p = std::make_unique(event.packet);
+ receivedPacket(std::move(p));
+ break;
+ }
+ case ENET_EVENT_TYPE_DISCONNECT: {
+ std::cout << Log::info << "Disconnected from server "
+ << event.peer->address.host << ":" << event.peer->address.port << "." << Log::endl;
+ break;
+ }
+ }
+ }
+
+ auto player = world.getPlayer();
+ if (player)
+ Serializer()
+ .appendE(NetField::POS).append(player->getPos())
+ .appendE(NetField::VEL).append(player->getVel())
+ .appendE(NetField::LOOK_PITCH).append(player->getPitch())
+ .appendE(NetField::LOOK_YAW).append(player->getYaw())
+ .packet(Packet::Type::THIS_PLAYER_INFO, false).sendTo(connection.getPeer(), Packet::Channel::INTERACT);
}
void ClientNetworkInterpreter::receivedPacket(std::unique_ptr p) {
- switch (p->type) {
- default:
- std::cout << Log::err << "Received unknown packet of type " << static_cast(p->type)
- << ". Is the server on a different protocol version?" << Log::endl; break;
-
- case Packet::Type::SERVER_INFO:
- serverSideChunkGens = p->d.read(); break;
-
- case Packet::Type::THIS_PLAYER_INFO:
- world.getPlayer()->handleAssertion(p->d); break;
-
- case Packet::Type::PLAYER_ENT_INFO:
- world.handlePlayerEntPacket(std::move(p)); break;
-
- case Packet::Type::CHUNK:
- case Packet::Type::MAPBLOCK:
- world.handleWorldPacket(std::move(p)); break;
-
- case Packet::Type::BLOCK_SET: {
- auto pos = p->d.read();
- auto block = p->d.read();
- world.getActiveDimension()->setBlock(pos, block);
- break; }
-
- case Packet::Type::ENTITY_INFO:
- world.getActiveDimension().l()->serverEntitiesInfo(p->d); break;
-
- case Packet::Type::ENTITY_REMOVED:
- world.getActiveDimension().l()->serverEntitiesRemoved(p->d); break;
-
- case Packet::Type::INV_DATA:
- onInvPacket(std::move(p)); break;
-
- case Packet::Type::INV_INVALID: {
- std::string source = p->d.read();
- std::string list = p->d.read();
- throw std::runtime_error("Invalid inventory " + source + ":" + list + " was request by client."); }
- }
+ switch (p->type) {
+ default:
+ std::cout << Log::err << "Received unknown packet of type " << static_cast(p->type)
+ << ". Is the server on a different protocol version?" << Log::endl;
+ break;
+
+ case Packet::Type::SERVER_INFO:serverSideChunkGens = p->d.read();
+ break;
+
+ case Packet::Type::THIS_PLAYER_INFO:world.getPlayer()->handleAssertion(p->d);
+ break;
+
+ case Packet::Type::PLAYER_ENT_INFO:world.handlePlayerEntPacket(std::move(p));
+ break;
+
+ case Packet::Type::CHUNK:
+ case Packet::Type::MAPBLOCK:world.handleWorldPacket(std::move(p));
+ break;
+
+ case Packet::Type::BLOCK_SET: {
+ auto pos = p->d.read();
+ auto block = p->d.read();
+ world.getActiveDimension()->setBlock(pos, block);
+ break;
+ }
+
+ case Packet::Type::ENTITY_INFO:world.getActiveDimension().l()->serverEntitiesInfo(p->d);
+ break;
+
+ case Packet::Type::ENTITY_REMOVED:world.getActiveDimension().l()->serverEntitiesRemoved(p->d);
+ break;
+
+ case Packet::Type::INV_DATA:onInvPacket(std::move(p));
+ break;
+
+ case Packet::Type::INV_INVALID: {
+ std::string source = p->d.read();
+ std::string list = p->d.read();
+ throw std::runtime_error("Invalid inventory " + source + ":" + list + " was request by client.");
+ }
+ }
}
-void ClientNetworkInterpreter::blockHit(const Target &target) {
- Serializer().append(target.pos).append(static_cast(target.face))
- .packet(Packet::Type::BLOCK_HIT).sendTo(connection.getPeer(), Packet::Channel::INTERACT);
+void ClientNetworkInterpreter::blockHit(const Target& target) {
+ Serializer().append(target.pos).append(static_cast(target.face))
+ .packet(Packet::Type::BLOCK_HIT).sendTo(connection.getPeer(), Packet::Channel::INTERACT);
}
-void ClientNetworkInterpreter::blockPlace(const Target &target) {
- Serializer().append(target.pos).append(static_cast(target.face))
- .packet(Packet::Type::BLOCK_PLACE).sendTo(connection.getPeer(), Packet::Channel::INTERACT);
+void ClientNetworkInterpreter::blockPlace(const Target& target) {
+ Serializer().append(target.pos).append(static_cast(target.face))
+ .packet(Packet::Type::BLOCK_PLACE).sendTo(connection.getPeer(), Packet::Channel::INTERACT);
}
-void ClientNetworkInterpreter::blockInteract(const Target &target) {
- Serializer().append(target.pos).append(static_cast(target.face))
- .packet(Packet::Type::BLOCK_INTERACT).sendTo(connection.getPeer(), Packet::Channel::INTERACT);
+void ClientNetworkInterpreter::blockInteract(const Target& target) {
+ Serializer().append(target.pos).append(static_cast(target.face))
+ .packet(Packet::Type::BLOCK_INTERACT).sendTo(connection.getPeer(), Packet::Channel::INTERACT);
}
-void ClientNetworkInterpreter::blockPlaceOrInteract(const Target &target) {
- Serializer().append(target.pos).append(static_cast(target.face))
- .packet(Packet::Type::BLOCK_PLACE_OR_INTERACT).sendTo(connection.getPeer(), Packet::Channel::INTERACT);
+void ClientNetworkInterpreter::blockPlaceOrInteract(const Target& target) {
+ Serializer().append(target.pos).append(static_cast(target.face))
+ .packet(Packet::Type::BLOCK_PLACE_OR_INTERACT).sendTo(connection.getPeer(), Packet::Channel::INTERACT);
}
void ClientNetworkInterpreter::invWatch(const std::string& inv, const std::string& list) {
- Serializer().append(inv).append(list).packet(Packet::Type::INV_WATCH)
- .sendTo(connection.getPeer(), Packet::Channel::INTERACT);
+ Serializer().append(inv).append(list).packet(Packet::Type::INV_WATCH)
+ .sendTo(connection.getPeer(), Packet::Channel::INTERACT);
}
void ClientNetworkInterpreter::invUnwatch(const std::string& inv, const std::string& list) {
- Serializer().append(inv).append(list).packet(Packet::Type::INV_UNWATCH)
- .sendTo(connection.getPeer(), Packet::Channel::INTERACT);
+ Serializer().append(inv).append(list).packet(Packet::Type::INV_UNWATCH)
+ .sendTo(connection.getPeer(), Packet::Channel::INTERACT);
}
-void ClientNetworkInterpreter::invInteract(const std::string &inv, const std::string &list, bool primary, unsigned short ind) {
- Serializer().append(primary).append(inv).append(list).append(ind)
- .packet(Packet::Type::INV_INTERACT).sendTo(connection.getPeer(), Packet::Channel::INTERACT);
+void ClientNetworkInterpreter::invInteract(const std::string& inv, const std::string& list, bool primary,
+ unsigned short ind) {
+ Serializer().append(primary).append(inv).append(list).append(ind)
+ .packet(Packet::Type::INV_INTERACT).sendTo(connection.getPeer(), Packet::Channel::INTERACT);
}
-void ClientNetworkInterpreter::sendPacket(const Packet &packet, Packet::Channel channel) {
- packet.sendTo(connection.getPeer(), channel);
+void ClientNetworkInterpreter::sendPacket(const Packet& packet, Packet::Channel channel) {
+ packet.sendTo(connection.getPeer(), channel);
}
diff --git a/src/client/conn/ClientNetworkInterpreter.h b/src/client/conn/ClientNetworkInterpreter.h
index 33947749..c347dbd3 100644
--- a/src/client/conn/ClientNetworkInterpreter.h
+++ b/src/client/conn/ClientNetworkInterpreter.h
@@ -13,40 +13,53 @@
#include "client/conn/ServerConnection.h"
class Model;
+
class Target;
+
class LocalWorld;
+
class PacketView;
+
class LocalPlayer;
+
class LocalSubgame;
+
enum class NetPlayerField;
class ClientNetworkInterpreter {
-public:
- ClientNetworkInterpreter(const ClientNetworkInterpreter& other) = delete;
- ClientNetworkInterpreter(ServerConnection& connection, LocalWorld& world);
-
- void init(std::function)> invCallback);
- void update();
-
- void blockHit(const Target& target);
- void blockPlace(const Target& target);
- void blockInteract(const Target& target);
- void blockPlaceOrInteract(const Target& target);
-
- void invWatch(const std::string& inv, const std::string& list);
- void invUnwatch(const std::string& inv, const std::string& list);
- void invInteract(const std::string& inv, const std::string& list, bool primary, unsigned short ind);
-
- void sendPacket(const Packet& packet, Packet::Channel channel);
-
- int recvPackets = 0;
- int serverSideChunkGens = 0;
-private:
- void receivedPacket(std::unique_ptr ePacket);
-
- LocalWorld& world;
- ServerConnection& connection;
-
- std::function)> onInvPacket;
+ public:
+ ClientNetworkInterpreter(const ClientNetworkInterpreter& other) = delete;
+
+ ClientNetworkInterpreter(ServerConnection& connection, LocalWorld& world);
+
+ void init(std::function)> invCallback);
+
+ void update();
+
+ void blockHit(const Target& target);
+
+ void blockPlace(const Target& target);
+
+ void blockInteract(const Target& target);
+
+ void blockPlaceOrInteract(const Target& target);
+
+ void invWatch(const std::string& inv, const std::string& list);
+
+ void invUnwatch(const std::string& inv, const std::string& list);
+
+ void invInteract(const std::string& inv, const std::string& list, bool primary, unsigned short ind);
+
+ void sendPacket(const Packet& packet, Packet::Channel channel);
+
+ int recvPackets = 0;
+ int serverSideChunkGens = 0;
+ private:
+ void receivedPacket(std::unique_ptr ePacket);
+
+ LocalWorld& world;
+ ServerConnection& connection;
+
+ std::function)> onInvPacket;
};
diff --git a/src/client/conn/ServerConnection.cpp b/src/client/conn/ServerConnection.cpp
index 2679d995..af9be53a 100644
--- a/src/client/conn/ServerConnection.cpp
+++ b/src/client/conn/ServerConnection.cpp
@@ -12,94 +12,94 @@
#include "util/net/NetHandler.h"
void ServerConnection::attemptConnect(Address addr) {
- if (state != State::UNCONNECTED) {
- disconnect();
- }
-
- if (enet_initialize() != 0) {
- std::cout << Log::err << "Failed to Initialize ENet." << Log::endl;
- state = State::ENET_ERROR;
- return;
- }
-
- host = enet_host_create(nullptr, 1, NetHandler::PACKET_CHANNELS, 0, 0);
-
- if (host == nullptr) {
- std::cout << Log::err << "Failed to create ENet client." << Log::endl;
- state = State::ENET_ERROR;
- return;
- }
-
- ENetAddress eNetAddr;
- enet_address_set_host(&eNetAddr, addr.host.c_str());
- eNetAddr.port = addr.port;
-
- peer = enet_host_connect(host, &eNetAddr, NetHandler::PACKET_CHANNELS, 0);
-
- if (peer == nullptr) {
- std::cout << Log::err << "Failed to initialize ENet peer." << Log::endl;
- state = State::ENET_ERROR;
- return;
- }
-
- connectionTime = std::chrono::high_resolution_clock::now();
- state = State::ATTEMPTING_CONNECT;
+ if (state != State::UNCONNECTED) {
+ disconnect();
+ }
+
+ if (enet_initialize() != 0) {
+ std::cout << Log::err << "Failed to Initialize ENet." << Log::endl;
+ state = State::ENET_ERROR;
+ return;
+ }
+
+ host = enet_host_create(nullptr, 1, NetHandler::PACKET_CHANNELS, 0, 0);
+
+ if (host == nullptr) {
+ std::cout << Log::err << "Failed to create ENet client." << Log::endl;
+ state = State::ENET_ERROR;
+ return;
+ }
+
+ ENetAddress eNetAddr;
+ enet_address_set_host(&eNetAddr, addr.host.c_str());
+ eNetAddr.port = addr.port;
+
+ peer = enet_host_connect(host, &eNetAddr, NetHandler::PACKET_CHANNELS, 0);
+
+ if (peer == nullptr) {
+ std::cout << Log::err << "Failed to initialize ENet peer." << Log::endl;
+ state = State::ENET_ERROR;
+ return;
+ }
+
+ connectionTime = std::chrono::high_resolution_clock::now();
+ state = State::ATTEMPTING_CONNECT;
}
void ServerConnection::processConnecting() {
- if (state == State::ATTEMPTING_CONNECT) {
- ENetEvent event;
-
- auto time = std::chrono::high_resolution_clock::now();
- long elapsedMs = std::chrono::duration_cast(time - connectionTime).count();
-
- if (elapsedMs < timeout) {
- if (enet_host_service(host, &event, 0) > 0 && event.type == ENET_EVENT_TYPE_CONNECT) {
- std::cout << Log::info << "Connected to "
- << NetHandler::intToIPString(event.peer->address.host)
- << ":" << event.peer->address.port << "." << Log::endl;
-
- state = State::CONNECTED;
- }
- }
- else {
- enet_peer_reset(peer);
- if (attempt < attempts) {
- std::cout << Log::info << "Failed to connect to server, retrying." << Log::endl;
- connectionTime = std::chrono::high_resolution_clock::now();
- attempt ++;
- }
- else {
- std::cout << Log::err << "Failed to connect to server." << Log::endl;
- state = State::FAILED_CONNECT;
- }
- }
- }
+ if (state == State::ATTEMPTING_CONNECT) {
+ ENetEvent event;
+
+ auto time = std::chrono::high_resolution_clock::now();
+ long elapsedMs = std::chrono::duration_cast(time - connectionTime).count();
+
+ if (elapsedMs < timeout) {
+ if (enet_host_service(host, &event, 0) > 0 && event.type == ENET_EVENT_TYPE_CONNECT) {
+ std::cout << Log::info << "Connected to "
+ << NetHandler::intToIPString(event.peer->address.host)
+ << ":" << event.peer->address.port << "." << Log::endl;
+
+ state = State::CONNECTED;
+ }
+ }
+ else {
+ enet_peer_reset(peer);
+ if (attempt < attempts) {
+ std::cout << Log::info << "Failed to connect to server, retrying." << Log::endl;
+ connectionTime = std::chrono::high_resolution_clock::now();
+ attempt++;
+ }
+ else {
+ std::cout << Log::err << "Failed to connect to server." << Log::endl;
+ state = State::FAILED_CONNECT;
+ }
+ }
+ }
}
ServerConnection::State ServerConnection::getConnectionStatus() {
- return state;
+ return state;
}
void ServerConnection::disconnect() {
- if (state == State::CONNECTED) {
- std::cout << Log::info << "Disconnecting from server." << Log::endl;
- enet_peer_disconnect(peer, 0);
- enet_host_flush(host);
- state = State::DISCONNECTED;
- }
+ if (state == State::CONNECTED) {
+ std::cout << Log::info << "Disconnecting from server." << Log::endl;
+ enet_peer_disconnect(peer, 0);
+ enet_host_flush(host);
+ state = State::DISCONNECTED;
+ }
}
-bool ServerConnection::pollEvents(ENetEvent *event) {
- return enet_host_service(host, event, 0) > 0;
+bool ServerConnection::pollEvents(ENetEvent* event) {
+ return enet_host_service(host, event, 0) > 0;
}
-ENetPeer *ServerConnection::getPeer() {
- return peer;
+ENetPeer* ServerConnection::getPeer() {
+ return peer;
}
ServerConnection::~ServerConnection() {
- disconnect();
- delete host;
- delete peer;
+ disconnect();
+ delete host;
+ delete peer;
}
diff --git a/src/client/conn/ServerConnection.h b/src/client/conn/ServerConnection.h
index 0d2c940b..3cd99108 100644
--- a/src/client/conn/ServerConnection.h
+++ b/src/client/conn/ServerConnection.h
@@ -10,38 +10,41 @@
class Address;
class ServerConnection {
-public:
- enum class State {
- UNCONNECTED,
- ATTEMPTING_CONNECT,
- CONNECTED,
- FAILED_CONNECT,
- DISCONNECTED,
- ENET_ERROR
- };
-
- ServerConnection() = default;
-
- void attemptConnect(Address addr);
- State getConnectionStatus();
- void disconnect();
-
- void processConnecting();
- bool pollEvents(ENetEvent* event);
-
- ENetPeer* getPeer();
-
- ~ServerConnection();
-
-private:
- unsigned long timeout = 1000;
- unsigned int attempts = 10;
-
- ENetHost* host = nullptr;
- ENetPeer* peer = nullptr;
-
- State state = State::UNCONNECTED;
- unsigned int attempt = 0;
- std::chrono::time_point connectionTime;
+ public:
+ enum class State {
+ UNCONNECTED,
+ ATTEMPTING_CONNECT,
+ CONNECTED,
+ FAILED_CONNECT,
+ DISCONNECTED,
+ ENET_ERROR
+ };
+
+ ServerConnection() = default;
+
+ void attemptConnect(Address addr);
+
+ State getConnectionStatus();
+
+ void disconnect();
+
+ void processConnecting();
+
+ bool pollEvents(ENetEvent* event);
+
+ ENetPeer* getPeer();
+
+ ~ServerConnection();
+
+ private:
+ unsigned long timeout = 1000;
+ unsigned int attempts = 10;
+
+ ENetHost* host = nullptr;
+ ENetPeer* peer = nullptr;
+
+ State state = State::UNCONNECTED;
+ unsigned int attempt = 0;
+ std::chrono::time_point connectionTime;
};
diff --git a/src/client/entity/ParticleEntity.cpp b/src/client/entity/ParticleEntity.cpp
index 9e7cd5df..896dc6fa 100644
--- a/src/client/entity/ParticleEntity.cpp
+++ b/src/client/entity/ParticleEntity.cpp
@@ -9,65 +9,65 @@
#include "game/def/BlockDef.h"
#include "game/atlas/asset/AtlasRef.h"
-ParticleEntity::ParticleEntity(SubgamePtr game, DimensionPtr dim, glm::vec3 pos, BlockDef &block) :
- DrawableEntity(game, dim, std::make_shared()), Entity(game, dim) {
- setPos(pos + glm::vec3(.5,.3,.5));
-
- std::set>& textureRefs = block.model.textureRefs;
- auto it = textureRefs.cbegin();
- advance(it, rand() % textureRefs.size());
-
- auto uv = (*it)->uv;
-
- auto spanX = uv.z - uv.x;
- auto spanY = uv.w - uv.y;
-
- float offX = spanX / 16 * (rand() % 12);
- float offY = spanX / 16 * (rand() % 12);
-
- uv -= glm::vec4(0, 0, spanX * 0.75, spanY * 0.75);
- uv += glm::vec4(offX, offY, offX, offY);
-
- std::vector vertices {
- {{-0.05, -0.05, 0}, {uv.x, uv.w, 0, 1}, {1, 1, 1}, true, {0, 0, 1}, {}, {}},
- {{-0.05, 0.05, 0}, {uv.x, uv.y, 0, 1}, {1, 1, 1}, true, {0, 0, 1}, {}, {}},
- {{ 0.05, 0.05, 0}, {uv.z, uv.y, 0, 1}, {1, 1, 1}, true, {0, 0, 1}, {}, {}},
- {{ 0.05, -0.05, 0}, {uv.z, uv.w, 0, 1}, {1, 1, 1}, true, {0, 0, 1}, {}, {}},
- };
- std::vector indices {
- 0, 1, 2, 2, 3, 0,
- 0, 2, 1, 2, 0, 3,
- };
-
- auto dir = glm::radians(static_cast(rand() % 360));
- float xDir = sinf(dir);
- float zDir = cosf(dir);
-
- float horiScale = 0.5f + (rand() % 100 / 100.f);
-
- velocity.y = 6.f;
- velocity.x = xDir * 2.f * horiScale;
- velocity.z = zDir * 2.f * horiScale;
-
- setPos(getPos() + glm::vec3(xDir, 0, zDir) / 4.f);
-
- std::unique_ptr mesh = std::make_unique();
- mesh->create(vertices, indices);
- this->model->fromMesh(std::move(mesh));
- this->setScale(0.75f + (rand() % 10 / 20.f));
+ParticleEntity::ParticleEntity(SubgamePtr game, DimensionPtr dim, glm::vec3 pos, BlockDef& block) :
+ DrawableEntity(game, dim, std::make_shared()), Entity(game, dim) {
+ setPos(pos + glm::vec3(.5, .3, .5));
+
+ std::set>& textureRefs = block.model.textureRefs;
+ auto it = textureRefs.cbegin();
+ advance(it, rand() % textureRefs.size());
+
+ auto uv = (*it)->uv;
+
+ auto spanX = uv.z - uv.x;
+ auto spanY = uv.w - uv.y;
+
+ float offX = spanX / 16 * (rand() % 12);
+ float offY = spanX / 16 * (rand() % 12);
+
+ uv -= glm::vec4(0, 0, spanX * 0.75, spanY * 0.75);
+ uv += glm::vec4(offX, offY, offX, offY);
+
+ std::vector vertices{
+ {{ -0.05, -0.05, 0 }, { uv.x, uv.w, 0, 1 }, { 1, 1, 1 }, true, { 0, 0, 1 }, {}, {}},
+ {{ -0.05, 0.05, 0 }, { uv.x, uv.y, 0, 1 }, { 1, 1, 1 }, true, { 0, 0, 1 }, {}, {}},
+ {{ 0.05, 0.05, 0 }, { uv.z, uv.y, 0, 1 }, { 1, 1, 1 }, true, { 0, 0, 1 }, {}, {}},
+ {{ 0.05, -0.05, 0 }, { uv.z, uv.w, 0, 1 }, { 1, 1, 1 }, true, { 0, 0, 1 }, {}, {}},
+ };
+ std::vector indices{
+ 0, 1, 2, 2, 3, 0,
+ 0, 2, 1, 2, 0, 3,
+ };
+
+ auto dir = glm::radians(static_cast(rand() % 360));
+ float xDir = sinf(dir);
+ float zDir = cosf(dir);
+
+ float horiScale = 0.5f + (rand() % 100 / 100.f);
+
+ velocity.y = 6.f;
+ velocity.x = xDir * 2.f * horiScale;
+ velocity.z = zDir * 2.f * horiScale;
+
+ setPos(getPos() + glm::vec3(xDir, 0, zDir) / 4.f);
+
+ std::unique_ptr mesh = std::make_unique();
+ mesh->create(vertices, indices);
+ this->model->fromMesh(std::move(mesh));
+ this->setScale(0.75f + (rand() % 10 / 20.f));
}
void ParticleEntity::update(double delta, glm::vec3 player) {
- time += delta;
-
- setPos(getPos() + velocity * glm::vec3(static_cast(delta)));
-
- double angle = -glm::degrees(std::atan2(player.z - pos.z, player.x - pos.x)) + 90.f;
- setRotateY(static_cast(angle));
-
- velocity.y -= 32.f * delta;
+ time += delta;
+
+ setPos(getPos() + velocity * glm::vec3(static_cast(delta)));
+
+ double angle = -glm::degrees(std::atan2(player.z - pos.z, player.x - pos.x)) + 90.f;
+ setRotateY(static_cast(angle));
+
+ velocity.y -= 32.f * delta;
}
-void ParticleEntity::draw(Renderer &renderer) {
- DrawableEntity::draw(renderer);
+void ParticleEntity::draw(Renderer& renderer) {
+ DrawableEntity::draw(renderer);
}
\ No newline at end of file
diff --git a/src/client/entity/ParticleEntity.h b/src/client/entity/ParticleEntity.h
index 97a4cc26..82b62ee4 100644
--- a/src/client/entity/ParticleEntity.h
+++ b/src/client/entity/ParticleEntity.h
@@ -9,14 +9,15 @@
class BlockDef;
class ParticleEntity : public DrawableEntity {
-public:
- ParticleEntity(SubgamePtr game, DimensionPtr dim, glm::vec3 pos, BlockDef& block);
-
- void update(double delta, glm::vec3 player);
- void draw(Renderer& renderer) override;
-
- float time = 0;
-private:
- glm::vec3 velocity {};
+ public:
+ ParticleEntity(SubgamePtr game, DimensionPtr dim, glm::vec3 pos, BlockDef& block);
+
+ void update(double delta, glm::vec3 player);
+
+ void draw(Renderer& renderer) override;
+
+ float time = 0;
+ private:
+ glm::vec3 velocity{};
};
diff --git a/src/client/entity/PlayerEntity.h b/src/client/entity/PlayerEntity.h
index b9312304..437931bd 100644
--- a/src/client/entity/PlayerEntity.h
+++ b/src/client/entity/PlayerEntity.h
@@ -7,16 +7,17 @@
#include "world/dim/ent/DrawableEntity.h"
class PlayerEntity : public DrawableEntity {
-public:
- PlayerEntity(SubgamePtr game, DimensionPtr dim, glm::vec3 pos, unsigned int id, const std::shared_ptr& model) :
- DrawableEntity(game, dim, model), Entity(game, dim), id(id) {
- setPos(pos);
- }
-
- unsigned int getId() {
- return id;
- }
-
-private:
- unsigned int id;
+ public:
+ PlayerEntity(SubgamePtr game, DimensionPtr dim, glm::vec3 pos, unsigned int id, const std::shared_ptr& model)
+ :
+ DrawableEntity(game, dim, model), Entity(game, dim), id(id) {
+ setPos(pos);
+ }
+
+ unsigned int getId() {
+ return id;
+ }
+
+ private:
+ unsigned int id;
};
\ No newline at end of file
diff --git a/src/client/entity/WireframeEntity.cpp b/src/client/entity/WireframeEntity.cpp
index d39dbec2..c485cc11 100644
--- a/src/client/entity/WireframeEntity.cpp
+++ b/src/client/entity/WireframeEntity.cpp
@@ -7,71 +7,83 @@
#include "world/dim/ent/DrawableEntity.h"
void WireframeEntity::updateMesh(const std::vector& boxes, float width) {
- this->width = width;
- buildMesh(boxes);
+ this->width = width;
+ buildMesh(boxes);
}
void WireframeEntity::buildMesh(const std::vector& boxes) {
- indOffset = 0;
-
- vertices.clear();
- indices.clear();
-
- for (auto& box : boxes) {
- glm::vec3 a = box.a;
- glm::vec3 b = box.b - box.a;
-
- createBox(a, b, 0, 0, 0, 0, b.y, 0);
- createBox(a, b, b.x, 0, 0, 0, b.y, 0);
- createBox(a, b, b.x, 0, b.z, 0, b.y, 0);
- createBox(a, b, 0, 0, b.z, 0, b.y, 0);
-
- createBox(a, b, 0, 0, 0, b.x, 0, 0);
- createBox(a, b, 0, b.y, 0, b.x, 0, 0);
- createBox(a, b, 0, b.y, b.z, b.x, 0, 0);
- createBox(a, b, 0, 0, b.z, b.x, 0, 0);
-
- createBox(a, b, 0, 0, 0, 0, 0, b.z);
- createBox(a, b, 0, b.y, 0, 0, 0, b.z);
- createBox(a, b, b.x, b.y, 0, 0, 0, b.z);
- createBox(a, b, b.x, 0, 0, 0, 0, b.z);
- }
-
-
- std::unique_ptr mesh = std::make_unique();
- mesh->create(vertices, indices);
- this->model->fromMesh(std::move(mesh));
+ indOffset = 0;
+
+ vertices.clear();
+ indices.clear();
+
+ for (auto& box : boxes) {
+ glm::vec3 a = box.a;
+ glm::vec3 b = box.b - box.a;
+
+ createBox(a, b, 0, 0, 0, 0, b.y, 0);
+ createBox(a, b, b.x, 0, 0, 0, b.y, 0);
+ createBox(a, b, b.x, 0, b.z, 0, b.y, 0);
+ createBox(a, b, 0, 0, b.z, 0, b.y, 0);
+
+ createBox(a, b, 0, 0, 0, b.x, 0, 0);
+ createBox(a, b, 0, b.y, 0, b.x, 0, 0);
+ createBox(a, b, 0, b.y, b.z, b.x, 0, 0);
+ createBox(a, b, 0, 0, b.z, b.x, 0, 0);
+
+ createBox(a, b, 0, 0, 0, 0, 0, b.z);
+ createBox(a, b, 0, b.y, 0, 0, 0, b.z);
+ createBox(a, b, b.x, b.y, 0, 0, 0, b.z);
+ createBox(a, b, b.x, 0, 0, 0, 0, b.z);
+ }
+
+
+ std::unique_ptr mesh = std::make_unique();
+ mesh->create(vertices, indices);
+ this->model->fromMesh(std::move(mesh));
}
-void WireframeEntity::createBox(glm::vec3 a, glm::vec3 b, float x, float y, float z, float xSize, float ySize, float zSize) {
- float hw = (width/2.0f);
- float w = width;
- glm::vec3 c = color;
-
- std::vector myVerts {
- /*0*/ {{x - hw + a.x, y - hw + a.y, z - hw + a.z }, {c.x, c.y, c.z, 1}, {1, 1, 1}, false, {0, 1, 0}, {}, {}},
- /*1*/ {{x - hw + a.x + xSize + w, y - hw + a.y, z - hw + a.z }, {c.x, c.y, c.z, 1}, {1, 1, 1}, false, {0, 1, 0}, {}, {}},
- /*2*/ {{x - hw + a.x + xSize + w, y - hw + a.y, z - hw + a.z + zSize + w}, {c.x, c.y, c.z, 1}, {1, 1, 1}, false, {0, 1, 0}, {}, {}},
- /*3*/ {{x - hw + a.x, y - hw + a.y, z - hw + a.z + zSize + w}, {c.x, c.y, c.z, 1}, {1, 1, 1}, false, {0, 1, 0}, {}, {}},
-
- /*4*/ {{x - hw + a.x, y - hw + a.y + ySize + w, z - hw + a.z }, {c.x, c.y, c.z, 1}, {1, 1, 1}, false, {0, 1, 0}, {}, {}},
- /*5*/ {{x - hw + a.x + xSize + w, y - hw + a.y + ySize + w, z - hw + a.z }, {c.x, c.y, c.z, 1}, {1, 1, 1}, false, {0, 1, 0}, {}, {}},
- /*6*/ {{x - hw + a.x + xSize + w, y - hw + a.y + ySize + w, z - hw + a.z + zSize + w}, {c.x, c.y, c.z, 1}, {1, 1, 1}, false, {0, 1, 0}, {}, {}},
- /*7*/ {{x - hw + a.x, y - hw + a.y + ySize + w, z - hw + a.z + zSize + w}, {c.x, c.y, c.z, 1}, {1, 1, 1}, false, {0, 1, 0}, {}, {}},
- };
-
- std::vector myInds {
- 0, 1, 2, 2, 3, 0,
- 4, 7, 6, 6, 5, 4,
- 0, 4, 5, 5, 1, 0,
- 3, 2, 6, 6, 7, 3,
- 0, 3, 7, 7, 4, 0,
- 1, 5, 6, 6, 2, 1,
- };
-
- vertices.insert(vertices.end(), myVerts.begin(), myVerts.end());
- for (auto i : myInds) indices.push_back(i + indOffset);
-
- indOffset += 8;
+void
+WireframeEntity::createBox(glm::vec3 a, glm::vec3 b, float x, float y, float z, float xSize, float ySize, float zSize) {
+ float hw = (width / 2.0f);
+ float w = width;
+ glm::vec3 c = color;
+
+ std::vector myVerts{
+ /*0*/
+ {{ x - hw + a.x, y - hw + a.y, z - hw + a.z }, { c.x, c.y, c.z, 1 }, { 1, 1, 1 }, false, { 0, 1, 0 }, {}, {}},
+ /*1*/{{ x - hw + a.x + xSize + w, y - hw + a.y, z - hw + a.z }, { c.x, c.y, c.z, 1 }, { 1, 1, 1 }, false,
+ { 0, 1, 0 }, {}, {}},
+ /*2*/
+ {{ x - hw + a.x + xSize + w, y - hw + a.y, z - hw + a.z + zSize + w }, { c.x, c.y, c.z, 1 }, { 1, 1, 1 }, false,
+ { 0, 1, 0 }, {}, {}},
+ /*3*/{{ x - hw + a.x, y - hw + a.y, z - hw + a.z + zSize + w }, { c.x, c.y, c.z, 1 }, { 1, 1, 1 }, false,
+ { 0, 1, 0 }, {}, {}},
+
+ /*4*/{{ x - hw + a.x, y - hw + a.y + ySize + w, z - hw + a.z }, { c.x, c.y, c.z, 1 }, { 1, 1, 1 }, false,
+ { 0, 1, 0 }, {}, {}},
+ /*5*/
+ {{ x - hw + a.x + xSize + w, y - hw + a.y + ySize + w, z - hw + a.z }, { c.x, c.y, c.z, 1 }, { 1, 1, 1 }, false,
+ { 0, 1, 0 }, {}, {}},
+ /*6*/{{ x - hw + a.x + xSize + w, y - hw + a.y + ySize + w, z - hw + a.z + zSize + w }, { c.x, c.y, c.z, 1 },
+ { 1, 1, 1 }, false, { 0, 1, 0 }, {}, {}},
+ /*7*/
+ {{ x - hw + a.x, y - hw + a.y + ySize + w, z - hw + a.z + zSize + w }, { c.x, c.y, c.z, 1 }, { 1, 1, 1 }, false,
+ { 0, 1, 0 }, {}, {}},
+ };
+
+ std::vector myInds{
+ 0, 1, 2, 2, 3, 0,
+ 4, 7, 6, 6, 5, 4,
+ 0, 4, 5, 5, 1, 0,
+ 3, 2, 6, 6, 7, 3,
+ 0, 3, 7, 7, 4, 0,
+ 1, 5, 6, 6, 2, 1,
+ };
+
+ vertices.insert(vertices.end(), myVerts.begin(), myVerts.end());
+ for (auto i : myInds) indices.push_back(i + indOffset);
+
+ indOffset += 8;
}
\ No newline at end of file
diff --git a/src/client/entity/WireframeEntity.h b/src/client/entity/WireframeEntity.h
index fe0ca8db..86a4f1db 100644
--- a/src/client/entity/WireframeEntity.h
+++ b/src/client/entity/WireframeEntity.h
@@ -10,21 +10,23 @@
#include "client/graph/mesh/EntityVertex.h"
class WireframeEntity : public DrawableEntity {
-public:
- WireframeEntity(SubgamePtr game, DimensionPtr dim, glm::vec3 color) :
- DrawableEntity(game, dim, std::make_shared()), Entity(game, dim),
- color(color) {};
-
- void updateMesh(const std::vector& boxes, float width);
-private:
- std::vector vertices {};
- std::vector indices {};
-
- void buildMesh(const std::vector& boxes);
- void createBox(glm::vec3 a, glm::vec3 b, float x, float y, float z, float xSize, float ySize, float zSize);
-
- glm::vec3 color {};
-
- float width = 0.5;
- int indOffset = 0;
+ public:
+ WireframeEntity(SubgamePtr game, DimensionPtr dim, glm::vec3 color) :
+ DrawableEntity(game, dim, std::make_shared()), Entity(game, dim),
+ color(color) {};
+
+ void updateMesh(const std::vector& boxes, float width);
+
+ private:
+ std::vector vertices{};
+ std::vector indices{};
+
+ void buildMesh(const std::vector& boxes);
+
+ void createBox(glm::vec3 a, glm::vec3 b, float x, float y, float z, float xSize, float ySize, float zSize);
+
+ glm::vec3 color{};
+
+ float width = 0.5;
+ int indOffset = 0;
};
diff --git a/src/client/graph/Camera.cpp b/src/client/graph/Camera.cpp
index 2a09959f..afc3c57b 100644
--- a/src/client/graph/Camera.cpp
+++ b/src/client/graph/Camera.cpp
@@ -9,91 +9,91 @@
Camera::Camera() = default;
void Camera::create(float buffWidth, float buffHeight, glm::vec3 up) {
- this->bufferDimensions = glm::vec2(buffWidth, buffHeight);
-
- this->position = glm::vec3(0, 0, 0);
-
- this->worldUp = up;
- this->yaw = 0;
- this->pitch = 0;
- this->front = glm::vec3(0.0f, 0.0f, -1.0f);
-
- createMatrices();
+ this->bufferDimensions = glm::vec2(buffWidth, buffHeight);
+
+ this->position = glm::vec3(0, 0, 0);
+
+ this->worldUp = up;
+ this->yaw = 0;
+ this->pitch = 0;
+ this->front = glm::vec3(0.0f, 0.0f, -1.0f);
+
+ createMatrices();
}
void Camera::createMatrices() {
- ratio = bufferDimensions.x / bufferDimensions.y;
-
- projectionMatrix = glm::perspective(glm::radians(fov), ratio, nearClip, farClip);
- frustum.setCamInternals(glm::radians(fov) / 1.2f, ratio, nearClip, farClip);
-
- orthographicMatrix = glm::ortho(0.0f, bufferDimensions.x, bufferDimensions.y, 0.0f, -1000.0f, 1000.0f);
+ ratio = bufferDimensions.x / bufferDimensions.y;
+
+ projectionMatrix = glm::perspective(glm::radians(fov), ratio, nearClip, farClip);
+ frustum.setCamInternals(glm::radians(fov) / 1.2f, ratio, nearClip, farClip);
+
+ orthographicMatrix = glm::ortho(0.0f, bufferDimensions.x, bufferDimensions.y, 0.0f, -1000.0f, 1000.0f);
}
void Camera::changeWindowDimensions(glm::vec2 size) {
- this->bufferDimensions = size;
- createMatrices();
+ this->bufferDimensions = size;
+ createMatrices();
}
glm::mat4 Camera::getProjectionMatrix() {
- return projectionMatrix;
+ return projectionMatrix;
}
glm::mat4 Camera::getOrthographicMatrix() {
- return orthographicMatrix;
+ return orthographicMatrix;
}
glm::mat4 Camera::getViewMatrix() {
- update();
- return glm::lookAt(position, position + front, up);
+ update();
+ return glm::lookAt(position, position + front, up);
}
void Camera::setPos(glm::vec3 pos) {
- position = pos;
+ position = pos;
}
glm::vec3 Camera::getPos() {
- return position;
+ return position;
}
void Camera::setYaw(double yaw) {
- this->yaw = yaw;
+ this->yaw = yaw;
}
void Camera::setPitch(double pitch) {
- this->pitch = pitch;
+ this->pitch = pitch;
}
void Camera::update() {
- front.x = (float)(cos(glm::radians(yaw)) * cos(glm::radians(pitch)));
- front.y = (float)(sin(glm::radians(pitch)));
- front.z = (float)(sin(glm::radians(yaw)) * cos(glm::radians(pitch)));
- front = glm::normalize(front);
-
- right = glm::normalize(glm::cross(front, worldUp));
- up = glm::normalize(glm::cross(right, front));
-
- frustum.update(position, front, up, right);
+ front.x = (float) (cos(glm::radians(yaw)) * cos(glm::radians(pitch)));
+ front.y = (float) (sin(glm::radians(pitch)));
+ front.z = (float) (sin(glm::radians(yaw)) * cos(glm::radians(pitch)));
+ front = glm::normalize(front);
+
+ right = glm::normalize(glm::cross(front, worldUp));
+ up = glm::normalize(glm::cross(right, front));
+
+ frustum.update(position, front, up, right);
}
glm::vec3 Camera::getFront() {
- return front;
+ return front;
}
glm::vec3 Camera::getRight() {
- return right;
+ return right;
}
glm::vec2 Camera::getBufferDimensions() {
- return bufferDimensions;
+ return bufferDimensions;
}
-bool Camera::inFrustum(glm::vec3 &p) {
- return frustum.pointInFrustum(p) == Frustum::INSIDE;
+bool Camera::inFrustum(glm::vec3& p) {
+ return frustum.pointInFrustum(p) == Frustum::INSIDE;
}
-int Camera::inFrustum(FrustumAABB &b) {
- return frustum.boxInFrustum(b);
+int Camera::inFrustum(FrustumAABB& b) {
+ return frustum.boxInFrustum(b);
}
Camera::~Camera() = default;
diff --git a/src/client/graph/Camera.h b/src/client/graph/Camera.h
index f801af17..4d548dab 100644
--- a/src/client/graph/Camera.h
+++ b/src/client/graph/Camera.h
@@ -11,61 +11,69 @@
#include "util/frustum/Frustum.h"
class Camera {
-public:
- Camera();
- void create(float buffWidth, float buffHeight, glm::vec3 up);
-
- void changeWindowDimensions(glm::vec2 size);
-
- glm::vec3 getPos();
- void setPos(glm::vec3 pos);
-
- void setYaw(double yaw);
- void setPitch(double pitch);
-
- glm::mat4 getProjectionMatrix();
- glm::mat4 getOrthographicMatrix();
-
- glm::mat4 getViewMatrix();
-
- glm::vec3 getFront();
- glm::vec3 getRight();
-
- glm::vec2 getBufferDimensions();
-
- bool inFrustum(glm::vec3 &p);
- int inFrustum(FrustumAABB &b);
-
- ~Camera();
-private:
- //Window Size
- glm::vec2 bufferDimensions;
-
- //Matrices
- glm::mat4 projectionMatrix;
- glm::mat4 orthographicMatrix;
-
- //Perspective Matrix Properties
- float fov = 80.0f;
- float ratio;
- float nearClip = 0.1f;
- float farClip = 1000.0f;
-
- //View Frustum
- Frustum frustum;
-
- //Movement translation variables
- glm::vec3 front;
- glm::vec3 up;
- glm::vec3 right;
- glm::vec3 worldUp;
-
- //Angle and Position
- glm::vec3 position;
- double yaw;
- double pitch;
-
- void createMatrices();
- void update();
+ public:
+ Camera();
+
+ void create(float buffWidth, float buffHeight, glm::vec3 up);
+
+ void changeWindowDimensions(glm::vec2 size);
+
+ glm::vec3 getPos();
+
+ void setPos(glm::vec3 pos);
+
+ void setYaw(double yaw);
+
+ void setPitch(double pitch);
+
+ glm::mat4 getProjectionMatrix();
+
+ glm::mat4 getOrthographicMatrix();
+
+ glm::mat4 getViewMatrix();
+
+ glm::vec3 getFront();
+
+ glm::vec3 getRight();
+
+ glm::vec2 getBufferDimensions();
+
+ bool inFrustum(glm::vec3& p);
+
+ int inFrustum(FrustumAABB& b);
+
+ ~Camera();
+
+ private:
+ //Window Size
+ glm::vec2 bufferDimensions;
+
+ //Matrices
+ glm::mat4 projectionMatrix;
+ glm::mat4 orthographicMatrix;
+
+ //Perspective Matrix Properties
+ float fov = 80.0f;
+ float ratio;
+ float nearClip = 0.1f;
+ float farClip = 1000.0f;
+
+ //View Frustum
+ Frustum frustum;
+
+ //Movement translation variables
+ glm::vec3 front;
+ glm::vec3 up;
+ glm::vec3 right;
+ glm::vec3 worldUp;
+
+ //Angle and Position
+ glm::vec3 position;
+ double yaw;
+ double pitch;
+
+ void createMatrices();
+
+ void update();
};
diff --git a/src/client/graph/Drawable.h b/src/client/graph/Drawable.h
index 0918f3c8..3eb1caa0 100644
--- a/src/client/graph/Drawable.h
+++ b/src/client/graph/Drawable.h
@@ -7,15 +7,18 @@
class Renderer;
class Drawable {
-public:
- virtual void update(double delta) {};
- virtual void draw(Renderer& renderer) {};
-
- virtual bool isVisible() { return visible; }
- virtual void setVisible(bool visible) { this->visible = visible; }
-
- virtual ~Drawable() = default;
-protected:
- bool visible = true;
+ public:
+ virtual void update(double delta) {};
+
+ virtual void draw(Renderer& renderer) {};
+
+ virtual bool isVisible() { return visible; }
+
+ virtual void setVisible(bool visible) { this->visible = visible; }
+
+ virtual ~Drawable() = default;
+
+ protected:
+ bool visible = true;
};
diff --git a/src/client/graph/DrawableGroup.cpp b/src/client/graph/DrawableGroup.cpp
index 83990ab3..a0deec8e 100644
--- a/src/client/graph/DrawableGroup.cpp
+++ b/src/client/graph/DrawableGroup.cpp
@@ -4,37 +4,37 @@
#include "DrawableGroup.h"
-void DrawableGroup::draw(Renderer &renderer) {
- for (auto drawable : children) {
- drawable->draw(renderer);
- }
+void DrawableGroup::draw(Renderer& renderer) {
+ for (auto drawable : children) {
+ drawable->draw(renderer);
+ }
}
-void DrawableGroup::addDrawable(Drawable *drawable) {
- children.push_back(drawable);
+void DrawableGroup::addDrawable(Drawable* drawable) {
+ children.push_back(drawable);
}
-void DrawableGroup::removeDrawable(Drawable *drawable) {
- for (auto it = children.begin(); it < children.end(); ++it) {
- if (*it == drawable) {
- children.erase(it);
- delete *it;
- return;
- }
- }
+void DrawableGroup::removeDrawable(Drawable* drawable) {
+ for (auto it = children.begin(); it < children.end(); ++it) {
+ if (*it == drawable) {
+ children.erase(it);
+ delete *it;
+ return;
+ }
+ }
}
void DrawableGroup::clearDrawables() {
- for (auto drawable : children) {
- delete drawable;
- }
- children.clear();
+ for (auto drawable : children) {
+ delete drawable;
+ }
+ children.clear();
}
DrawableGroup::~DrawableGroup() {
- clearDrawables();
+ clearDrawables();
}
-std::vector &DrawableGroup::getChildren() {
- return children;
+std::vector& DrawableGroup::getChildren() {
+ return children;
}
diff --git a/src/client/graph/DrawableGroup.h b/src/client/graph/DrawableGroup.h
index 4a435c20..95fd9731 100644
--- a/src/client/graph/DrawableGroup.h
+++ b/src/client/graph/DrawableGroup.h
@@ -9,17 +9,20 @@
#include "Drawable.h"
class DrawableGroup : public Drawable {
-public:
- void draw(Renderer& renderer) override;
-
- void addDrawable(Drawable* drawable);
- void removeDrawable(Drawable* drawable);
- void clearDrawables();
-
- std::vector& getChildren();
-
- ~DrawableGroup() override;
-protected:
- std::vector children {};
+ public:
+ void draw(Renderer& renderer) override;
+
+ void addDrawable(Drawable* drawable);
+
+ void removeDrawable(Drawable* drawable);
+
+ void clearDrawables();
+
+ std::vector& getChildren();
+
+ ~DrawableGroup() override;
+
+ protected:
+ std::vector children{};
};
diff --git a/src/client/graph/Font.cpp b/src/client/graph/Font.cpp
index 9e00b3ff..e13a95c8 100644
--- a/src/client/graph/Font.cpp
+++ b/src/client/graph/Font.cpp
@@ -10,62 +10,62 @@
#include "game/atlas/TextureAtlas.h"
Font::Font(TextureAtlas& atlas, std::shared_ptr tex) :
- fontTex(std::move(tex)),
- atlasSize(atlas.pixelSize) {
-
- getCharWidths(atlas);
+ fontTex(std::move(tex)),
+ atlasSize(atlas.pixelSize) {
+
+ getCharWidths(atlas);
}
unsigned int Font::getCharWidth(char c) {
- unsigned int index = static_cast(c) - 32;
- if (index >= amountOfChars) throw std::runtime_error("Invalid char index.");
- return charWidths[index];
+ unsigned int index = static_cast(c) - 32;
+ if (index >= amountOfChars) throw std::runtime_error("Invalid char index.");
+ return charWidths[index];
}
-void Font::getCharWidths(TextureAtlas &atlas) {
- auto& data = atlas.atlasData;
-
- charWidths[0] = 2;
-
- for (unsigned int i = 1; i < amountOfChars; i++) {
- glm::vec2 charPos = {i % 18 * charWidth, std::floor(i / 18) * charHeight};
-
- unsigned int xBase = static_cast(fontTex->pos.x) + static_cast(charPos.x);
- unsigned int yBase = static_cast(fontTex->pos.y) + static_cast(charPos.y);
-
- unsigned short width = 0;
-
- for (unsigned int j = 0; j < charWidth; j++) {
- bool empty = true;
- for (unsigned int k = 0; k < charHeight; k++) {
- unsigned int xx = xBase + j;
- unsigned int yy = yBase + k;
-
- unsigned int offset = yy * static_cast(atlasSize.x) * 4 + xx * 4 + 3;
-
- if (data[offset] != 0) {
- empty = false;
- break;
- }
- }
- if (!empty) width = static_cast(j);
- }
-
- charWidths[i] = width;
- }
+void Font::getCharWidths(TextureAtlas& atlas) {
+ auto& data = atlas.atlasData;
+
+ charWidths[0] = 2;
+
+ for (unsigned int i = 1; i < amountOfChars; i++) {
+ glm::vec2 charPos = { i % 18 * charWidth, std::floor(i / 18) * charHeight };
+
+ unsigned int xBase = static_cast(fontTex->pos.x) + static_cast(charPos.x);
+ unsigned int yBase = static_cast(fontTex->pos.y) + static_cast(charPos.y);
+
+ unsigned short width = 0;
+
+ for (unsigned int j = 0; j < charWidth; j++) {
+ bool empty = true;
+ for (unsigned int k = 0; k < charHeight; k++) {
+ unsigned int xx = xBase + j;
+ unsigned int yy = yBase + k;
+
+ unsigned int offset = yy * static_cast(atlasSize.x) * 4 + xx * 4 + 3;
+
+ if (data[offset] != 0) {
+ empty = false;
+ break;
+ }
+ }
+ if (!empty) width = static_cast(j);
+ }
+
+ charWidths[i] = width;
+ }
}
glm::vec4 Font::getCharUVs(char c) {
- unsigned int index = static_cast(c) - 32;
- if (index >= amountOfChars) throw std::runtime_error("Invalid char index.");
-
- glm::vec2 charPos = {(index % 18) * charWidth, std::floor(index / 18) * charHeight};
- glm::vec4 uv = {
- fontTex->uv.x + (charPos.x) / atlasSize.x,
- fontTex->uv.y + (charPos.y) / atlasSize.y,
- fontTex->uv.x + (charPos.x + getCharWidth(c) + 1) / atlasSize.x,
- fontTex->uv.y + (charPos.y + charHeight) / atlasSize.y
- };
-
- return uv;
+ unsigned int index = static_cast(c) - 32;
+ if (index >= amountOfChars) throw std::runtime_error("Invalid char index.");
+
+ glm::vec2 charPos = { (index % 18) * charWidth, std::floor(index / 18) * charHeight };
+ glm::vec4 uv = {
+ fontTex->uv.x + (charPos.x) / atlasSize.x,
+ fontTex->uv.y + (charPos.y) / atlasSize.y,
+ fontTex->uv.x + (charPos.x + getCharWidth(c) + 1) / atlasSize.x,
+ fontTex->uv.y + (charPos.y + charHeight) / atlasSize.y
+ };
+
+ return uv;
}
diff --git a/src/client/graph/Font.h b/src/client/graph/Font.h
index 93c1eb97..ac7f6688 100644
--- a/src/client/graph/Font.h
+++ b/src/client/graph/Font.h
@@ -9,23 +9,27 @@
#include
class AtlasRef;
+
class TextureAtlas;
class Font {
-public:
- Font() = default;
- Font(TextureAtlas& atlas, std::shared_ptr tex);
- unsigned int getCharWidth(char c);
- glm::vec4 getCharUVs(char c);
-
- const static unsigned int amountOfChars = 95;
- const static unsigned int charWidth = 7;
- const static unsigned int charHeight = 9;
-private:
- void getCharWidths(TextureAtlas& atlas);
-
- glm::vec2 atlasSize {};
-
- std::shared_ptr fontTex = nullptr;
- std::array charWidths {};
+ public:
+ Font() = default;
+
+ Font(TextureAtlas& atlas, std::shared_ptr tex);
+
+ unsigned int getCharWidth(char c);
+
+ glm::vec4 getCharUVs(char c);
+
+ const static unsigned int amountOfChars = 95;
+ const static unsigned int charWidth = 7;
+ const static unsigned int charHeight = 9;
+ private:
+ void getCharWidths(TextureAtlas& atlas);
+
+ glm::vec2 atlasSize{};
+
+ std::shared_ptr fontTex = nullptr;
+ std::array charWidths{};
};
diff --git a/src/client/graph/Model.cpp b/src/client/graph/Model.cpp
index 4fbcc399..49216aa4 100644
--- a/src/client/graph/Model.cpp
+++ b/src/client/graph/Model.cpp
@@ -17,56 +17,57 @@
#include "game/atlas/asset/SerializedModel.h"
void Model::fromMesh(std::unique_ptr mesh) {
- meshes.clear();
- meshes.push_back(std::move(mesh));
+ meshes.clear();
+ meshes.push_back(std::move(mesh));
}
-int Model::fromFile(const std::string &path, const std::vector> &textures) {
- this->textures = textures;
-
- Assimp::Importer importer;
- const aiScene* scene = importer.ReadFile(path, aiProcess_Triangulate | aiProcess_FlipUVs | aiProcess_GenNormals);
-
- if (!scene || scene->mFlags & AI_SCENE_FLAGS_INCOMPLETE || !scene->mRootNode) {
- std::cout << Log::err << "ERROR::ASSIMP::" << importer.GetErrorString() << Log::endl;
- return 1;
- }
-
- loadModelMeshes(scene->mRootNode, scene);
- loadAnimations(scene);
-
- calcBoneHeirarchy(scene->mRootNode, scene, -1);
-
- globalInverseTransform = glm::inverse(MatConv::AiToGLMMat4(scene->mRootNode->mTransformation));
-
- return 0;
+int Model::fromFile(const std::string& path, const std::vector>& textures) {
+ this->textures = textures;
+
+ Assimp::Importer importer;
+ const aiScene* scene = importer.ReadFile(path, aiProcess_Triangulate | aiProcess_FlipUVs | aiProcess_GenNormals);
+
+ if (!scene || scene->mFlags & AI_SCENE_FLAGS_INCOMPLETE || !scene->mRootNode) {
+ std::cout << Log::err << "ERROR::ASSIMP::" << importer.GetErrorString() << Log::endl;
+ return 1;
+ }
+
+ loadModelMeshes(scene->mRootNode, scene);
+ loadAnimations(scene);
+
+ calcBoneHeirarchy(scene->mRootNode, scene, -1);
+
+ globalInverseTransform = glm::inverse(MatConv::AiToGLMMat4(scene->mRootNode->mTransformation));
+
+ return 0;
}
int Model::fromSerialized(const SerializedModel& model, const std::vector>& textures) {
- this->textures = textures;
-
- Assimp::Importer importer;
- const aiScene* scene = importer.ReadFileFromMemory(model.data.data(), model.data.length(), aiProcess_Triangulate | aiProcess_FlipUVs | aiProcess_GenNormals, "B3D");
-
- if (!scene || scene->mFlags & AI_SCENE_FLAGS_INCOMPLETE || !scene->mRootNode) {
- std::cout << Log::err << "ERROR::ASSIMP::" << importer.GetErrorString() << Log::endl;
- return 1;
- }
-
- loadModelMeshes(scene->mRootNode, scene);
- loadAnimations(scene);
-
- calcBoneHeirarchy(scene->mRootNode, scene, -1);
- globalInverseTransform = glm::inverse(MatConv::AiToGLMMat4(scene->mRootNode->mTransformation));
- return 0;
+ this->textures = textures;
+
+ Assimp::Importer importer;
+ const aiScene* scene = importer.ReadFileFromMemory(model.data.data(), model.data.length(),
+ aiProcess_Triangulate | aiProcess_FlipUVs | aiProcess_GenNormals, "B3D");
+
+ if (!scene || scene->mFlags & AI_SCENE_FLAGS_INCOMPLETE || !scene->mRootNode) {
+ std::cout << Log::err << "ERROR::ASSIMP::" << importer.GetErrorString() << Log::endl;
+ return 1;
+ }
+
+ loadModelMeshes(scene->mRootNode, scene);
+ loadAnimations(scene);
+
+ calcBoneHeirarchy(scene->mRootNode, scene, -1);
+ globalInverseTransform = glm::inverse(MatConv::AiToGLMMat4(scene->mRootNode->mTransformation));
+ return 0;
}
void Model::getTransformsByFrame(double frame, glm::ivec2 bounds, std::vector& transforms) {
- transforms.resize(bones.size());
-
- if (!rootBones.empty())
- for (auto bone : rootBones)
- calcBoneTransformation(frame, *bone, glm::mat4(1.0f), bounds, transforms);
+ transforms.resize(bones.size());
+
+ if (!rootBones.empty())
+ for (auto bone : rootBones)
+ calcBoneTransformation(frame, *bone, glm::mat4(1.0f), bounds, transforms);
}
//void Model::getTransformsByTime(double time, std::vector& transforms) {
@@ -76,187 +77,191 @@ void Model::getTransformsByFrame(double frame, glm::ivec2 bounds, std::vectormNumMeshes; i++) {
- aiMesh* mesh = scene->mMeshes[node->mMeshes[i]];
- meshes.emplace_back(std::make_unique());
- loadMeshAndBone(mesh, meshes[i]);
- }
-
- for (unsigned int i = 0; i < node->mNumChildren; i++) {
- loadModelMeshes(node->mChildren[i], scene); //Recurse down
- }
+void Model::loadModelMeshes(aiNode* node, const aiScene* scene) {
+ for (unsigned int i = 0; i < node->mNumMeshes; i++) {
+ aiMesh* mesh = scene->mMeshes[node->mMeshes[i]];
+ meshes.emplace_back(std::make_unique());
+ loadMeshAndBone(mesh, meshes[i]);
+ }
+
+ for (unsigned int i = 0; i < node->mNumChildren; i++) {
+ loadModelMeshes(node->mChildren[i], scene); //Recurse down
+ }
}
-void Model::loadMeshAndBone(aiMesh *mesh, std::unique_ptr& target) {
- std::vector vertices;
- std::vector indices;
-
- //Process Vertices
- for (unsigned int i = 0; i < mesh->mNumVertices; i++) {
- EntityVertex vertex {};
-
- vertex.position = {mesh->mVertices[i].x, mesh->mVertices[i].y, mesh->mVertices[i].z};
- vertex.normal = {mesh->mNormals[i].x, mesh->mNormals[i].y, mesh->mNormals[i].z};
- vertex.colorBlend = {1, 1, 1};
-
- assert(mesh->mMaterialIndex >= 0 && mesh->mMaterialIndex < textures.size());
-
- if (mesh->mTextureCoords[0]) {
- auto& texture = textures[mesh->mMaterialIndex];
-
- //Set texture coordinates
- vertex.useTex = true;
- vertex.colorData = {
- texture->uv.x + mesh->mTextureCoords[0][i].x * (texture->uv.z - texture->uv.x),
- texture->uv.y + mesh->mTextureCoords[0][i].y * (texture->uv.w - texture->uv.y), 0, 1 //Alpha
- };
- }
- else vertex.colorData = {1, 1, 1, 1};
-
- vertices.push_back(vertex);
- }
-
- //Process Indices
- for (unsigned int i = 0; i < mesh->mNumFaces; i++) {
- aiFace face = mesh->mFaces[i];
- for (unsigned int j = 0; j < face.mNumIndices; j++) {
- indices.push_back(face.mIndices[j]);
- }
- }
-
- //Process Mesh Bones and add to bone list
- bones.resize(mesh->mNumBones);
- for (unsigned int i = 0; i < mesh->mNumBones; i++) {
- aiBone* bone = mesh->mBones[i];
-
- bones[i] = ModelBone(static_cast(i), -1, {bone->mName.data});
- bones[i].offsetMatrix = glm::transpose(MatConv::AiToGLMMat4(bone->mOffsetMatrix));
-
- for (unsigned int j = 0; j < bone->mNumWeights; j++) {
- aiVertexWeight* weight = &bone->mWeights[j];
- if (weight->mVertexId >= vertices.size()) assert(0);
-
- unsigned int bid = 0;
- while (vertices[weight->mVertexId].boneWeights[bid] != 0) {
- bid++;
- assert(bid < 4);
- }
-
- vertices[weight->mVertexId].boneIDs[bid] = i;
- vertices[weight->mVertexId].boneWeights[bid] = weight->mWeight;
- }
- }
-
- //Create mesh
- target->create(vertices, indices);
+void Model::loadMeshAndBone(aiMesh* mesh, std::unique_ptr& target) {
+ std::vector vertices;
+ std::vector indices;
+
+ //Process Vertices
+ for (unsigned int i = 0; i < mesh->mNumVertices; i++) {
+ EntityVertex vertex{};
+
+ vertex.position = { mesh->mVertices[i].x, mesh->mVertices[i].y, mesh->mVertices[i].z };
+ vertex.normal = { mesh->mNormals[i].x, mesh->mNormals[i].y, mesh->mNormals[i].z };
+ vertex.colorBlend = { 1, 1, 1 };
+
+ assert(mesh->mMaterialIndex >= 0 && mesh->mMaterialIndex < textures.size());
+
+ if (mesh->mTextureCoords[0]) {
+ auto& texture = textures[mesh->mMaterialIndex];
+
+ //Set texture coordinates
+ vertex.useTex = true;
+ vertex.colorData = {
+ texture->uv.x + mesh->mTextureCoords[0][i].x * (texture->uv.z - texture->uv.x),
+ texture->uv.y + mesh->mTextureCoords[0][i].y * (texture->uv.w - texture->uv.y), 0, 1 //Alpha
+ };
+ }
+ else vertex.colorData = { 1, 1, 1, 1 };
+
+ vertices.push_back(vertex);
+ }
+
+ //Process Indices
+ for (unsigned int i = 0; i < mesh->mNumFaces; i++) {
+ aiFace face = mesh->mFaces[i];
+ for (unsigned int j = 0; j < face.mNumIndices; j++) {
+ indices.push_back(face.mIndices[j]);
+ }
+ }
+
+ //Process Mesh Bones and add to bone list
+ bones.resize(mesh->mNumBones);
+ for (unsigned int i = 0; i < mesh->mNumBones; i++) {
+ aiBone* bone = mesh->mBones[i];
+
+ bones[i] = ModelBone(static_cast(i), -1, { bone->mName.data });
+ bones[i].offsetMatrix = glm::transpose(MatConv::AiToGLMMat4(bone->mOffsetMatrix));
+
+ for (unsigned int j = 0; j < bone->mNumWeights; j++) {
+ aiVertexWeight* weight = &bone->mWeights[j];
+ if (weight->mVertexId >= vertices.size()) assert(0);
+
+ unsigned int bid = 0;
+ while (vertices[weight->mVertexId].boneWeights[bid] != 0) {
+ bid++;
+ assert(bid < 4);
+ }
+
+ vertices[weight->mVertexId].boneIDs[bid] = i;
+ vertices[weight->mVertexId].boneWeights[bid] = weight->mWeight;
+ }
+ }
+
+ //Create mesh
+ target->create(vertices, indices);
}
-void Model::loadAnimations(const aiScene *scene) {
- assert(scene->mNumAnimations <= 1);
-
- if (scene->mNumAnimations == 1) {
- const aiAnimation* aiAnim = scene->mAnimations[0];
-
- animation = ModelAnimation(aiAnim->mName.data);
-
- animation.duration = static_cast(aiAnim->mDuration);
- animation.ticksPerSecond = aiAnim->mTicksPerSecond;
-
- animation.channels.resize(bones.size());
-
- for (unsigned int j = 0; j < aiAnim->mNumChannels; j++) {
- const aiNodeAnim* aiChannel = aiAnim->mChannels[j];
-
- int index = -1;
- for (unsigned int k = 0; k < bones.size(); k++) {
- if (std::string {aiChannel->mNodeName.data} == bones[k].name) {
- index = k;
- continue;
- }
- }
-
- if (index == -1) {
+void Model::loadAnimations(const aiScene* scene) {
+ assert(scene->mNumAnimations <= 1);
+
+ if (scene->mNumAnimations == 1) {
+ const aiAnimation* aiAnim = scene->mAnimations[0];
+
+ animation = ModelAnimation(aiAnim->mName.data);
+
+ animation.duration = static_cast(aiAnim->mDuration);
+ animation.ticksPerSecond = aiAnim->mTicksPerSecond;
+
+ animation.channels.resize(bones.size());
+
+ for (unsigned int j = 0; j < aiAnim->mNumChannels; j++) {
+ const aiNodeAnim* aiChannel = aiAnim->mChannels[j];
+
+ int index = -1;
+ for (unsigned int k = 0; k < bones.size(); k++) {
+ if (std::string{ aiChannel->mNodeName.data } == bones[k].name) {
+ index = k;
+ continue;
+ }
+ }
+
+ if (index == -1) {
// std::cout << aiChannel->mNodeName.data << std::endl;
- }
- else {
- animation.channels[index] = AnimChannel(static_cast(index), aiChannel->mNodeName.data);
- AnimChannel &channel = animation.channels[index];
-
- //Copy Rotation Keys
- channel.rotationKeys.reserve(aiChannel->mNumRotationKeys);
- for (unsigned int k = 0; k < aiChannel->mNumRotationKeys; k++) {
- aiQuatKey *key = &aiChannel->mRotationKeys[k];
- channel.rotationKeys.emplace_back(key->mTime, key->mValue);
- }
-
- //Copy Position Keys
- channel.positionKeys.reserve(aiChannel->mNumPositionKeys);
- for (unsigned int k = 0; k < aiChannel->mNumPositionKeys; k++) {
- aiVectorKey *key = &aiChannel->mPositionKeys[k];
- channel.positionKeys.emplace_back(key->mTime,
- glm::vec3{key->mValue.x, key->mValue.y, key->mValue.z});
- }
-
- //Copy Scale Keys
- channel.scaleKeys.reserve(aiChannel->mNumScalingKeys);
- for (unsigned int k = 0; k < aiChannel->mNumScalingKeys; k++) {
- aiVectorKey *key = &aiChannel->mScalingKeys[k];
- channel.scaleKeys.emplace_back(key->mTime, glm::vec3{key->mValue.x, key->mValue.y, key->mValue.z});
- }
- }
- }
- }
+ }
+ else {
+ animation.channels[index] = AnimChannel(static_cast(index), aiChannel->mNodeName.data);
+ AnimChannel& channel = animation.channels[index];
+
+ //Copy Rotation Keys
+ channel.rotationKeys.reserve(aiChannel->mNumRotationKeys);
+ for (unsigned int k = 0; k < aiChannel->mNumRotationKeys; k++) {
+ aiQuatKey* key = &aiChannel->mRotationKeys[k];
+ channel.rotationKeys.emplace_back(key->mTime, key->mValue);
+ }
+
+ //Copy Position Keys
+ channel.positionKeys.reserve(aiChannel->mNumPositionKeys);
+ for (unsigned int k = 0; k < aiChannel->mNumPositionKeys; k++) {
+ aiVectorKey* key = &aiChannel->mPositionKeys[k];
+ channel.positionKeys.emplace_back(key->mTime,
+ glm::vec3{ key->mValue.x, key->mValue.y, key->mValue.z });
+ }
+
+ //Copy Scale Keys
+ channel.scaleKeys.reserve(aiChannel->mNumScalingKeys);
+ for (unsigned int k = 0; k < aiChannel->mNumScalingKeys; k++) {
+ aiVectorKey* key = &aiChannel->mScalingKeys[k];
+ channel.scaleKeys.emplace_back(key->mTime,
+ glm::vec3{ key->mValue.x, key->mValue.y, key->mValue.z });
+ }
+ }
+ }
+ }
}
-void Model::calcBoneHeirarchy(aiNode *node, const aiScene *scene, int parentBoneIndex) {
- int index = -1;
-
- for (auto &bone : bones) {
- if (bone.name == std::string(node->mName.data)) {
- bone.parent = parentBoneIndex;
- index = bone.index;
- if (parentBoneIndex == -1) rootBones.push_back(&bone);
- else bones[bone.parent].children.push_back(&bone);
- break;
- }
- }
-
- for (unsigned int i = 0; i < node->mNumChildren; i++) calcBoneHeirarchy(node->mChildren[i], scene, index);
+void Model::calcBoneHeirarchy(aiNode* node, const aiScene* scene, int parentBoneIndex) {
+ int index = -1;
+
+ for (auto& bone : bones) {
+ if (bone.name == std::string(node->mName.data)) {
+ bone.parent = parentBoneIndex;
+ index = bone.index;
+ if (parentBoneIndex == -1) rootBones.push_back(&bone);
+ else bones[bone.parent].children.push_back(&bone);
+ break;
+ }
+ }
+
+ for (unsigned int i = 0; i < node->mNumChildren; i++) calcBoneHeirarchy(node->mChildren[i], scene, index);
}
-void Model::calcBoneTransformation(double animTime, ModelBone& bone, glm::mat4 parentTransform, glm::ivec2 bounds, std::vector& transforms) {
- AnimChannel* channel = nullptr;
- for (auto &i : animation.channels) {
- if (i.index == bone.index) {
- channel = &i;
- break;
- }
- }
-
- glm::mat4 boneTransformation(1.0f);
- if (channel) {
- glm::mat4 position = glm::translate(glm::mat4(1.0), calcBoneVal(animTime, bounds, channel->positionKeys, {},
- [](const glm::vec3 &a, const glm::vec3 &b, float factor) { return glm::mix(a, b, factor); }));
- glm::mat4 scale = glm::scale(glm::mat4(1.0), calcBoneVal(animTime, bounds, channel->scaleKeys, {},
- [](const glm::vec3 &a, const glm::vec3 &b, float factor) { return glm::mix(a, b, factor); }));
- glm::mat4 rotation = glm::transpose(glm::mat4(MatConv::AiToGLMMat3(
- calcBoneVal(animTime, bounds, channel->rotationKeys, {},
- [](const aiQuaternion& a, const aiQuaternion& b, float factor) {
- aiQuaternion result;
- aiQuaternion::Interpolate(result, a, b, factor);
- return result.Normalize();
- }).GetMatrix())));
-
- boneTransformation = position * rotation * scale;
- }
-
- glm::mat4 globalTransformation = parentTransform * boneTransformation;
- transforms[bone.index] = globalInverseTransform * globalTransformation * bone.offsetMatrix;
-
- for (auto& child : bone.children) calcBoneTransformation(animTime, *child, globalTransformation, bounds, transforms);
+void Model::calcBoneTransformation(double animTime, ModelBone& bone, glm::mat4 parentTransform, glm::ivec2 bounds,
+ std::vector& transforms) {
+ AnimChannel* channel = nullptr;
+ for (auto& i : animation.channels) {
+ if (i.index == bone.index) {
+ channel = &i;
+ break;
+ }
+ }
+
+ glm::mat4 boneTransformation(1.0f);
+ if (channel) {
+ glm::mat4 position = glm::translate(glm::mat4(1.0),
+ calcBoneVal(animTime, bounds, channel->positionKeys, {},
+ [](const glm::vec3& a, const glm::vec3& b, float factor) { return glm::mix(a, b, factor); }));
+ glm::mat4 scale = glm::scale(glm::mat4(1.0), calcBoneVal(animTime, bounds, channel->scaleKeys, {},
+ [](const glm::vec3& a, const glm::vec3& b, float factor) { return glm::mix(a, b, factor); }));
+ glm::mat4 rotation = glm::transpose(glm::mat4(MatConv::AiToGLMMat3(
+ calcBoneVal(animTime, bounds, channel->rotationKeys, {},
+ [](const aiQuaternion& a, const aiQuaternion& b, float factor) {
+ aiQuaternion result;
+ aiQuaternion::Interpolate(result, a, b, factor);
+ return result.Normalize();
+ }).GetMatrix())));
+
+ boneTransformation = position * rotation * scale;
+ }
+
+ glm::mat4 globalTransformation = parentTransform * boneTransformation;
+ transforms[bone.index] = globalInverseTransform * globalTransformation * bone.offsetMatrix;
+
+ for (auto& child : bone.children)
+ calcBoneTransformation(animTime, *child, globalTransformation, bounds, transforms);
}
\ No newline at end of file
diff --git a/src/client/graph/Model.h b/src/client/graph/Model.h
index 65c4c47d..963238ed 100644
--- a/src/client/graph/Model.h
+++ b/src/client/graph/Model.h
@@ -16,60 +16,68 @@
#include "client/graph/mesh/EntityMesh.h"
class AtlasRef;
+
class SerializedModel;
class Model {
-public:
- Model() = default;
-
- void fromMesh(std::unique_ptr mesh);
- int fromFile(const std::string &path, const std::vector> &texture);
- int fromSerialized(const SerializedModel &model, const std::vector> &texture);
-
- void getTransformsByFrame(double frame, glm::ivec2 bounds, std::vector& transforms);
+ public:
+ Model() = default;
+
+ void fromMesh(std::unique_ptr mesh);
+
+ int fromFile(const std::string& path, const std::vector>& texture);
+
+ int fromSerialized(const SerializedModel& model, const std::vector>& texture);
+
+ void getTransformsByFrame(double frame, glm::ivec2 bounds, std::vector& transforms);
// void getTransformsByTime(double time, std::tuple bounds, std::vector& transforms);
-
- const ModelAnimation& getAnimation();
-
- std::vector> meshes;
-private:
- void loadModelMeshes(aiNode *node, const aiScene *scene);
- void loadMeshAndBone(aiMesh *mesh, std::unique_ptr &target);
- void loadAnimations(const aiScene *scene);
-
- void calcBoneHeirarchy(aiNode *node, const aiScene *scene, int parentBoneIndex);
- void calcBoneTransformation(double animTime, ModelBone& bone, glm::mat4 parentTransform, glm::ivec2 bounds, std::vector& transforms);
-
- template static inline T calcBoneVal(
- double animTime, glm::ivec2 bounds, const std::vector>& keysArray,
- const T& def, std::function merge) {
-
- if (keysArray.empty()) return def;
- if (keysArray.size() == 1) return keysArray[0].second;
-
- unsigned int index = 0;
- for (unsigned int i = 1; i < keysArray.size(); i++) {
- if (keysArray[i].first > animTime) {
- index = i - 1;
- break;
- }
- }
- float factor = 1;
- unsigned int nextIndex = index + 1;
- if (nextIndex >= keysArray.size() || nextIndex > bounds.y) nextIndex = bounds.x;
- else {
- double delta = keysArray[nextIndex].first - keysArray[index].first;
- factor = (animTime - keysArray[index].first) / delta;
- }
-
- return merge(keysArray[index].second, keysArray[nextIndex].second, factor);
- }
-
- ModelAnimation animation {};
- std::vector rootBones {};
- std::vector bones {};
- std::vector> textures {};
-
- glm::mat4 globalInverseTransform {};
+
+ const ModelAnimation& getAnimation();
+
+ std::vector> meshes;
+ private:
+ void loadModelMeshes(aiNode* node, const aiScene* scene);
+
+ void loadMeshAndBone(aiMesh* mesh, std::unique_ptr& target);
+
+ void loadAnimations(const aiScene* scene);
+
+ void calcBoneHeirarchy(aiNode* node, const aiScene* scene, int parentBoneIndex);
+
+ void calcBoneTransformation(double animTime, ModelBone& bone, glm::mat4 parentTransform, glm::ivec2 bounds,
+ std::vector& transforms);
+
+ template
+ static inline T calcBoneVal(
+ double animTime, glm::ivec2 bounds, const std::vector>& keysArray,
+ const T& def, std::function merge) {
+
+ if (keysArray.empty()) return def;
+ if (keysArray.size() == 1) return keysArray[0].second;
+
+ unsigned int index = 0;
+ for (unsigned int i = 1; i < keysArray.size(); i++) {
+ if (keysArray[i].first > animTime) {
+ index = i - 1;
+ break;
+ }
+ }
+ float factor = 1;
+ unsigned int nextIndex = index + 1;
+ if (nextIndex >= keysArray.size() || nextIndex > bounds.y) nextIndex = bounds.x;
+ else {
+ double delta = keysArray[nextIndex].first - keysArray[index].first;
+ factor = (animTime - keysArray[index].first) / delta;
+ }
+
+ return merge(keysArray[index].second, keysArray[nextIndex].second, factor);
+ }
+
+ ModelAnimation animation{};
+ std::vector rootBones{};
+ std::vector bones{};
+ std::vector> textures{};
+
+ glm::mat4 globalInverseTransform{};
};
diff --git a/src/client/graph/ModelAnimation.cpp b/src/client/graph/ModelAnimation.cpp
index 85ebf676..ad807f4c 100644
--- a/src/client/graph/ModelAnimation.cpp
+++ b/src/client/graph/ModelAnimation.cpp
@@ -5,4 +5,4 @@
#include "ModelAnimation.h"
ModelAnimation::ModelAnimation(const std::string& name)
- : name(name) {}
+ : name(name) {}
diff --git a/src/client/graph/ModelAnimation.h b/src/client/graph/ModelAnimation.h
index 7d8c9265..35a7215e 100644
--- a/src/client/graph/ModelAnimation.h
+++ b/src/client/graph/ModelAnimation.h
@@ -10,12 +10,13 @@
#include "world/dim/ent/AnimChannel.h"
class ModelAnimation {
-public:
- ModelAnimation() = default;
- explicit ModelAnimation(const std::string& name);
-
- std::string name = "";
- std::vector channels {};
- unsigned int duration = 0;
- double ticksPerSecond = 0;
+ public:
+ ModelAnimation() = default;
+
+ explicit ModelAnimation(const std::string& name);
+
+ std::string name = "";
+ std::vector channels{};
+ unsigned int duration = 0;
+ double ticksPerSecond = 0;
};
diff --git a/src/client/graph/ModelBone.cpp b/src/client/graph/ModelBone.cpp
index 0d8a8275..041daf9c 100644
--- a/src/client/graph/ModelBone.cpp
+++ b/src/client/graph/ModelBone.cpp
@@ -5,6 +5,6 @@
#include "ModelBone.h"
ModelBone::ModelBone(unsigned int index, int parent, const std::string& name) :
- index(index),
- parent(parent),
- name(name) {}
\ No newline at end of file
+ index(index),
+ parent(parent),
+ name(name) {}
\ No newline at end of file
diff --git a/src/client/graph/ModelBone.h b/src/client/graph/ModelBone.h
index bb360b72..53152656 100644
--- a/src/client/graph/ModelBone.h
+++ b/src/client/graph/ModelBone.h
@@ -9,15 +9,16 @@
#include
class ModelBone {
-public:
- ModelBone() = default;
- ModelBone(unsigned int index, int parent, const std::string& name);
-
- std::string name {};
- unsigned int index = 0;
- int parent = 0;
-
- glm::mat4 offsetMatrix {};
-
- std::vector children;
+ public:
+ ModelBone() = default;
+
+ ModelBone(unsigned int index, int parent, const std::string& name);
+
+ std::string name{};
+ unsigned int index = 0;
+ int parent = 0;
+
+ glm::mat4 offsetMatrix{};
+
+ std::vector children;
};
diff --git a/src/client/graph/Renderer.cpp b/src/client/graph/Renderer.cpp
index 786ed242..350a08a3 100644
--- a/src/client/graph/Renderer.cpp
+++ b/src/client/graph/Renderer.cpp
@@ -6,229 +6,232 @@
#include "Renderer.h"
-Renderer::Renderer() : Renderer({1366, 768}) {};
+Renderer::Renderer() : Renderer({ 1366, 768 }) {};
Renderer::Renderer(glm::ivec2 win) :
- activeTexture(nullptr),
- window(win),
-
- world (win, 2),
- entity(win, 2),
- ssao (win, 1, 24),
- blur (win, 1),
- light (win, 2) {
-
- camera.create(window.getSize().x, window.getSize().y, glm::vec3(0, 1, 0));
-
- ssao.createFromFile("../assets/shader/post/passThrough.vs", "../assets/shader/post/ssaoCalc.fs");
- blur.createFromFile("../assets/shader/post/passThrough.vs", "../assets/shader/post/ssaoBlur.fs");
- light.createFromFile("../assets/shader/post/passThrough.vs", "../assets/shader/post/deferredLighting.fs");
- world.createFromFile("../assets/shader/world/world.vs", "../assets/shader/world/world.fs", "../assets/shader/world/world.gs");
- entity.createFromFile("../assets/shader/world/entity.vs", "../assets/shader/world/entity.fs");
-
- guiShader = Shader();
- guiShader.createFromFile("../assets/shader/ortho/hud.vs", "../assets/shader/ortho/hud.fs");
-
- gu.matrix = camera.getOrthographicMatrix();
- gu.ortho = guiShader.get("ortho");
- gu.model = guiShader.get("model");
- gu.bones = guiShader.get("uBones");
- gu.clipBounds = guiShader.get("uClipBounds");
-
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-
- window.addResizeCallback("renderer", [&](glm::ivec2 win) {
- ssao.windowResized(win);
- blur.windowResized(win);
- light.windowResized(win);
- world.windowResized(win);
-
- camera.changeWindowDimensions(win);
-
- gu.matrix = camera.getOrthographicMatrix();
- });
+ activeTexture(nullptr),
+ window(win),
+
+ world(win, 2),
+ entity(win, 2),
+ ssao(win, 1, 24),
+ blur(win, 1),
+ light(win, 2) {
+
+ camera.create(window.getSize().x, window.getSize().y, glm::vec3(0, 1, 0));
+
+ ssao.createFromFile("../assets/shader/post/passThrough.vs", "../assets/shader/post/ssaoCalc.fs");
+ blur.createFromFile("../assets/shader/post/passThrough.vs", "../assets/shader/post/ssaoBlur.fs");
+ light.createFromFile("../assets/shader/post/passThrough.vs", "../assets/shader/post/deferredLighting.fs");
+ world.createFromFile("../assets/shader/world/world.vs", "../assets/shader/world/world.fs",
+ "../assets/shader/world/world.gs");
+ entity.createFromFile("../assets/shader/world/entity.vs", "../assets/shader/world/entity.fs");
+
+ guiShader = Shader();
+ guiShader.createFromFile("../assets/shader/ortho/hud.vs", "../assets/shader/ortho/hud.fs");
+
+ gu.matrix = camera.getOrthographicMatrix();
+ gu.ortho = guiShader.get("ortho");
+ gu.model = guiShader.get("model");
+ gu.bones = guiShader.get("uBones");
+ gu.clipBounds = guiShader.get("uClipBounds");
+
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+
+ window.addResizeCallback("renderer", [&](glm::ivec2 win) {
+ ssao.windowResized(win);
+ blur.windowResized(win);
+ light.windowResized(win);
+ world.windowResized(win);
+
+ camera.changeWindowDimensions(win);
+
+ gu.matrix = camera.getOrthographicMatrix();
+ });
}
void Renderer::update(double delta) {
- //VSync 1 = On, 0 = Off
- glfwSwapInterval(1);
- elapsedTime += delta;
-
- window.update();
- world.updateSwayMap(delta);
+ //VSync 1 = On, 0 = Off
+ glfwSwapInterval(1);
+ elapsedTime += delta;
+
+ window.update();
+ world.updateSwayMap(delta);
}
void Renderer::beginChunkDeferredCalls() {
- activeTexture = nullptr;
- currentModelUniform = world.uniforms.model;
-
- glClearColor(0, 0, 0, 0);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- glEnable(GL_CULL_FACE);
- glEnable(GL_DEPTH_TEST);
- glDepthFunc(GL_LESS);
- glDisable(GL_BLEND);
-
- glViewport(0, 0, static_cast(world.windowSize.x * world.bufferScale), static_cast(world.windowSize.y * world.bufferScale));
-
- glBindFramebuffer(GL_FRAMEBUFFER, light.gBuffer);
- glClear(GL_DEPTH_BUFFER_BIT);
-
- const float skyColor[] = {clearColor.x, clearColor.y, clearColor.z, 1};
- static const float clearTransparent[] = {0, 0, 0, 1};
- glClearBufferfv(GL_COLOR, 0, clearTransparent);
- glClearBufferfv(GL_COLOR, 1, clearTransparent);
- glClearBufferfv(GL_COLOR, 2, skyColor);
-
- setShader(world);
- world.set(world.uniforms.proj, camera.getProjectionMatrix());
- world.set(world.uniforms.view, camera.getViewMatrix());
- world.set(world.uniforms.time, static_cast(elapsedTime));
- world.swayTex.use(1);
+ activeTexture = nullptr;
+ currentModelUniform = world.uniforms.model;
+
+ glClearColor(0, 0, 0, 0);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ glEnable(GL_CULL_FACE);
+ glEnable(GL_DEPTH_TEST);
+ glDepthFunc(GL_LESS);
+ glDisable(GL_BLEND);
+
+ glViewport(0, 0, static_cast(world.windowSize.x * world.bufferScale),
+ static_cast(world.windowSize.y * world.bufferScale));
+
+ glBindFramebuffer(GL_FRAMEBUFFER, light.gBuffer);
+ glClear(GL_DEPTH_BUFFER_BIT);
+
+ const float skyColor[] = { clearColor.x, clearColor.y, clearColor.z, 1 };
+ static const float clearTransparent[] = { 0, 0, 0, 1 };
+ glClearBufferfv(GL_COLOR, 0, clearTransparent);
+ glClearBufferfv(GL_COLOR, 1, clearTransparent);
+ glClearBufferfv(GL_COLOR, 2, skyColor);
+
+ setShader(world);
+ world.set(world.uniforms.proj, camera.getProjectionMatrix());
+ world.set(world.uniforms.view, camera.getViewMatrix());
+ world.set(world.uniforms.time, static_cast(elapsedTime));
+ world.swayTex.use(1);
}
void Renderer::beginEntityDeferredCalls() {
- currentModelUniform = entity.uniforms.model;
-
- setShader(entity);
- entity.set(entity.uniforms.proj, camera.getProjectionMatrix());
- entity.set(entity.uniforms.view, camera.getViewMatrix());
+ currentModelUniform = entity.uniforms.model;
+
+ setShader(entity);
+ entity.set(entity.uniforms.proj, camera.getProjectionMatrix());
+ entity.set(entity.uniforms.view, camera.getViewMatrix());
}
void Renderer::endDeferredCalls() {
- activeTexture = nullptr;
-
- glBindFramebuffer(GL_FRAMEBUFFER, ssao.fbo);
- glClearColor(clearColor.x, clearColor.y, clearColor.z, 0);
- glClear(GL_COLOR_BUFFER_BIT);
-
- setShader(ssao);
- ssao.set(ssao.uniforms.proj, camera.getProjectionMatrix());
- ssao.set(ssao.uniforms.view, camera.getViewMatrix());
- ssao.set(ssao.uniforms.kernelCount, ssao.kernelCount);
-
- for (unsigned int i = 0; i < ssao.kernelCount; i++) {
- GLint uni = ssao.get("samples[" + std::to_string(i) + "]");
- ssao.set(uni, ssao.kernels[i]);
- }
-
- glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D, light.gPosition);
- glActiveTexture(GL_TEXTURE1);
- glBindTexture(GL_TEXTURE_2D, light.gNormal);
- glActiveTexture(GL_TEXTURE2);
- glBindTexture(GL_TEXTURE_2D, ssao.tex);
-
- renderQuad();
-
- auto winSize = window.getSize();
- glViewport(0, 0, static_cast(winSize.x), static_cast(winSize.y));
-
- glBindFramebuffer(GL_FRAMEBUFFER, blur.fbo);
- glClear(GL_COLOR_BUFFER_BIT);
- setShader(blur);
- glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D, ssao.colorBuffer);
- renderQuad();
-
- glBindFramebuffer(GL_FRAMEBUFFER, 0);
-
- glClearColor(clearColor.r, clearColor.g, clearColor.b, clearColor.a);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- setShader(light);
- light.set(light.uniforms.camPosition, camera.getPos());
-
- glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D, light.gPosition);
- glActiveTexture(GL_TEXTURE1);
- glBindTexture(GL_TEXTURE_2D, light.gNormal);
- glActiveTexture(GL_TEXTURE2);
- glBindTexture(GL_TEXTURE_2D, light.gColorSpec);
- glActiveTexture(GL_TEXTURE3);
- glBindTexture(GL_TEXTURE_2D, blur.colorBuffer);
-
- glEnable(GL_BLEND);
- renderQuad();
+ activeTexture = nullptr;
+
+ glBindFramebuffer(GL_FRAMEBUFFER, ssao.fbo);
+ glClearColor(clearColor.x, clearColor.y, clearColor.z, 0);
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ setShader(ssao);
+ ssao.set(ssao.uniforms.proj, camera.getProjectionMatrix());
+ ssao.set(ssao.uniforms.view, camera.getViewMatrix());
+ ssao.set(ssao.uniforms.kernelCount, ssao.kernelCount);
+
+ for (unsigned int i = 0; i < ssao.kernelCount; i++) {
+ GLint uni = ssao.get("samples[" + std::to_string(i) + "]");
+ ssao.set(uni, ssao.kernels[i]);
+ }
+
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_2D, light.gPosition);
+ glActiveTexture(GL_TEXTURE1);
+ glBindTexture(GL_TEXTURE_2D, light.gNormal);
+ glActiveTexture(GL_TEXTURE2);
+ glBindTexture(GL_TEXTURE_2D, ssao.tex);
+
+ renderQuad();
+
+ auto winSize = window.getSize();
+ glViewport(0, 0, static_cast(winSize.x), static_cast(winSize.y));
+
+ glBindFramebuffer(GL_FRAMEBUFFER, blur.fbo);
+ glClear(GL_COLOR_BUFFER_BIT);
+ setShader(blur);
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_2D, ssao.colorBuffer);
+ renderQuad();
+
+ glBindFramebuffer(GL_FRAMEBUFFER, 0);
+
+ glClearColor(clearColor.r, clearColor.g, clearColor.b, clearColor.a);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ setShader(light);
+ light.set(light.uniforms.camPosition, camera.getPos());
+
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_2D, light.gPosition);
+ glActiveTexture(GL_TEXTURE1);
+ glBindTexture(GL_TEXTURE_2D, light.gNormal);
+ glActiveTexture(GL_TEXTURE2);
+ glBindTexture(GL_TEXTURE_2D, light.gColorSpec);
+ glActiveTexture(GL_TEXTURE3);
+ glBindTexture(GL_TEXTURE_2D, blur.colorBuffer);
+
+ glEnable(GL_BLEND);
+ renderQuad();
}
void Renderer::beginGUIDrawCalls() {
- activeTexture = nullptr;
- currentModelUniform = gu.model;
-
- glClear(GL_DEPTH_BUFFER_BIT);
- glDisable(GL_DEPTH_TEST);
- glDisable(GL_CULL_FACE);
- glEnable(GL_BLEND);
-
- setShader(guiShader);
- guiShader.set(gu.ortho, gu.matrix);
+ activeTexture = nullptr;
+ currentModelUniform = gu.model;
+
+ glClear(GL_DEPTH_BUFFER_BIT);
+ glDisable(GL_DEPTH_TEST);
+ glDisable(GL_CULL_FACE);
+ glEnable(GL_BLEND);
+
+ setShader(guiShader);
+ guiShader.set(gu.ortho, gu.matrix);
}
void Renderer::swapBuffers() {
- Shader::clearShader();
- window.swapBuffers();
+ Shader::clearShader();
+ window.swapBuffers();
}
void Renderer::setShader(Shader& s) {
- s.use();
- this->currentShader = &s;
+ s.use();
+ this->currentShader = &s;
}
void Renderer::setClearColor(unsigned char r, unsigned char g, unsigned char b) {
- clearColor = {static_cast(r)/255.f, static_cast