Skip to content

Commit

Permalink
Added extended camera position information to CameraInfo
Browse files Browse the repository at this point in the history
Fixed an issue where we would spawn multiple of the same Model
Fixed a missing return statement in TerrainLoader
Fixed missing includes
Fixed Basic Water Rendering
Updated Submodule Engine
  • Loading branch information
NixAJ committed Sep 25, 2023
1 parent ac10f6c commit 6267d33
Show file tree
Hide file tree
Showing 12 changed files with 239 additions and 159 deletions.
25 changes: 13 additions & 12 deletions Source/Game/Game/Application/Application.cpp
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
#include "Application.h"

#include "Game/Animation/AnimationSystem.h"
#include "Game/ECS/Scheduler.h"
#include "Game/ECS/Singletons/EngineStats.h"
#include "Game/ECS/Singletons/RenderState.h"
#include "Game/Editor/EditorHandler.h"
#include "Game/Gameplay/GameConsole/GameConsole.h"
#include "Game/Rendering/GameRenderer.h"
#include "Game/Scripting/LuaManager.h"
#include "Game/Util/ServiceLocator.h"
#include "Game/Loaders/LoaderSystem.h"
#include "Game/Scripting/LuaManager.h"
#include "Game/Scripting/Systems/LuaSystemBase.h"

#include <Base/Types.h>
#include <Base/CVarSystem/CVarSystem.h>
#include <Base/Util/Timer.h>
#include <Base/Util/JsonUtils.h>
#include <Base/Util/DebugHandler.h>
#include <Base/Util/CPUInfo.h>

#include <Game/ECS/Scheduler.h>
#include <Game/ECS/Singletons/EngineStats.h>
#include <Game/ECS/Singletons/RenderState.h>
#include <Game/Editor/EditorHandler.h>
#include <Game/Gameplay/GameConsole/GameConsole.h>
#include <Game/Rendering/GameRenderer.h>
#include <Game/Scripting/LuaManager.h>
#include <Game/Util/ServiceLocator.h>
#include <Game/Loaders/LoaderSystem.h>
#include <Game/Scripting/LuaManager.h>
#include <Game/Scripting/Systems/LuaSystemBase.h>

#include <enkiTS/TaskScheduler.h>
#include <entt/entt.hpp>
#include <imgui/backends/imgui_impl_vulkan.h>
Expand Down
7 changes: 5 additions & 2 deletions Source/Game/Game/Editor/CVarEditor.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#include "CVarEditor.h"

#include <string>
#include <Base/CVarSystem/CVarSystemPrivate.h>

#include <imgui/imgui.h>
#include <imgui/imgui_internal.h>
#include <imgui/misc/cpp/imgui_stdlib.h>
#include <Base/CVarSystem/CVarSystemPrivate.h>

#include <map>
#include <string>

namespace Editor
{
Expand Down
86 changes: 86 additions & 0 deletions Source/Game/Game/Editor/CameraInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
#include "Game/ECS/Components/Camera.h"

#include <Base/CVarSystem/CVarSystemPrivate.h>
#include <Base/Math/Math.h>

#include <FileFormat/Shared.h>

#include <entt/entt.hpp>
#include <imgui/imgui.h>
Expand All @@ -24,6 +27,54 @@ namespace Editor

}

inline vec2 WorldPositionToChunkGlobalPos(const vec3& position)
{
// This is translated to remap positions [-17066 .. 17066] to [0 .. 34132]
// This is because we want the Chunk Pos to be between [0 .. 64] and not [-32 .. 32]

return vec2(Terrain::MAP_HALF_SIZE - -position.x, Terrain::MAP_HALF_SIZE - position.z);
}
inline vec2 GetChunkIndicesFromAdtPosition(const vec2& adtPosition)
{
return adtPosition / Terrain::CHUNK_SIZE;
}

inline u32 GetChunkIdFromChunkPos(const vec2& chunkPos)
{
return Math::FloorToInt(chunkPos.x) + (Math::FloorToInt(chunkPos.y) * Terrain::CHUNK_NUM_PER_MAP_STRIDE);
}

vec2 GetChunkPosition(u32 chunkID)
{
const u32 chunkX = chunkID / Terrain::CHUNK_NUM_PER_MAP_STRIDE;
const u32 chunkY = chunkID % Terrain::CHUNK_NUM_PER_MAP_STRIDE;

const vec2 chunkPos = -Terrain::MAP_HALF_SIZE + (vec2(chunkX, chunkY) * Terrain::CHUNK_SIZE);
return chunkPos;
}

inline u32 GetCellIdFromCellPos(const vec2& cellPos)
{
return Math::FloorToInt(cellPos.y) + (Math::FloorToInt(cellPos.x) * Terrain::CHUNK_NUM_CELLS_PER_STRIDE);
}

inline u32 GetPatchIdFromPatchPos(const vec2& patchPos)
{
return Math::FloorToInt(patchPos.y) + (Math::FloorToInt(patchPos.x) * Terrain::CELL_NUM_PATCHES_PER_STRIDE);
}

vec2 GetCellPosition(u32 chunkID, u32 cellID)
{
const u32 cellX = cellID % Terrain::CHUNK_NUM_CELLS_PER_STRIDE;
const u32 cellY = cellID / Terrain::CHUNK_NUM_CELLS_PER_STRIDE;

const vec2 chunkPos = GetChunkPosition(chunkID);
const vec2 cellPos = vec2(cellX + 1, cellY) * Terrain::CELL_SIZE;

vec2 cellWorldPos = chunkPos + cellPos;
return vec2(cellWorldPos.x, -cellWorldPos.y);
}

void CameraInfo::DrawImGui()
{
EnttRegistries* registries = ServiceLocator::GetEnttRegistries();
Expand Down Expand Up @@ -59,6 +110,41 @@ namespace Editor
ImGui::Text("Forward: (%.2f, %.2f, %.2f)", cameraTransform.forward.x, cameraTransform.forward.y, cameraTransform.forward.z);
ImGui::Text("Right: (%.2f, %.2f, %.2f)", cameraTransform.right.x, cameraTransform.right.y, cameraTransform.right.z);
ImGui::Text("Up: (%.2f, %.2f, %.2f)", cameraTransform.up.x, cameraTransform.up.y, cameraTransform.up.z);

ImGui::Separator();

vec2 chunkGlobalPos = WorldPositionToChunkGlobalPos(cameraTransform.position);

vec2 chunkPos = GetChunkIndicesFromAdtPosition(chunkGlobalPos);
vec2 chunkRemainder = chunkPos - glm::floor(chunkPos);

vec2 cellLocalPos = (chunkRemainder * Terrain::CHUNK_SIZE);
vec2 cellPos = cellLocalPos / Terrain::CELL_SIZE;
vec2 cellRemainder = cellPos - glm::floor(cellPos);

vec2 patchLocalPos = (cellRemainder * Terrain::CELL_SIZE);
vec2 patchPos = patchLocalPos / Terrain::PATCH_SIZE;
vec2 patchRemainder = patchPos - glm::floor(patchPos);

u32 currentChunkID = GetChunkIdFromChunkPos(chunkPos);
u32 currentCellID = GetCellIdFromCellPos(cellPos);
u32 currentPatchID = GetCellIdFromCellPos(patchPos);

ImGui::Text("Chunk : (%u)", currentChunkID);
ImGui::Text("Chunk : (%f, %f)", chunkPos.x, chunkPos.y);
ImGui::Text("Chunk Remainder : (%f, %f)", chunkRemainder.x, chunkRemainder.y);

ImGui::Spacing();
ImGui::Text("Cell : (%u)", currentCellID);
ImGui::Text("ID : (%f, %f)", cellPos.x, cellPos.y);
ImGui::Text("Pos : (%f, %f)", cellLocalPos.x, cellLocalPos.y);
ImGui::Text("Remainder : (%f, %f)", cellRemainder.x, cellRemainder.y);

ImGui::Spacing();
ImGui::Text("Patch : (%u)", currentPatchID);
ImGui::Text("ID : (%f, %f)", patchPos.x, patchPos.y);
ImGui::Text("Pos : (%f, %f)", patchLocalPos.x, patchLocalPos.y);
ImGui::Text("Remainder : (%f, %f)", patchRemainder.x, patchRemainder.y);
}
ImGui::End();
}
Expand Down
2 changes: 2 additions & 0 deletions Source/Game/Game/Editor/EaseCurveTool.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma once
#include "BaseEditor.h"

#include <imgui/imgui.h>

namespace Editor
{
class EaseCurveTool : public BaseEditor
Expand Down
5 changes: 5 additions & 0 deletions Source/Game/Game/Rendering/Model/ModelLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ void ModelLoader::Clear()
}
_nameHashToLoadingMutex.clear();

_uniqueIDToinstanceID.clear();
_instanceIDToModelID.clear();
_instanceIDToEntityID.clear();
_modelIDToNameHash.clear();
Expand Down Expand Up @@ -259,6 +260,9 @@ void ModelLoader::Update(f32 deltaTime)
continue;
}

if (_uniqueIDToinstanceID.contains(request.placement.uniqueID))
continue;

u32 index = numCreatedInstances.fetch_add(1);
AddInstance(_createdEntities[index], request);
}
Expand Down Expand Up @@ -407,6 +411,7 @@ void ModelLoader::AddInstance(entt::entity entityID, const LoadRequestInternal&
aabb.extents = modelAABB.extents;

std::scoped_lock lock(_instanceIDToModelIDMutex);
_uniqueIDToinstanceID[request.placement.uniqueID] = instanceID;
_instanceIDToModelID[instanceID] = modelID;
_instanceIDToEntityID[instanceID] = entityID;

Expand Down
1 change: 1 addition & 0 deletions Source/Game/Game/Rendering/Model/ModelLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class ModelLoader
robin_hood::unordered_map<u32, DiscoveredModel> _nameHashToDiscoveredModel;
robin_hood::unordered_map<u32, std::mutex*> _nameHashToLoadingMutex;

robin_hood::unordered_map<u32, u32> _uniqueIDToinstanceID;
robin_hood::unordered_map<u32, u32> _instanceIDToModelID;
robin_hood::unordered_map<u32, entt::entity> _instanceIDToEntityID;
std::mutex _instanceIDToModelIDMutex;
Expand Down
2 changes: 2 additions & 0 deletions Source/Game/Game/Rendering/Terrain/TerrainLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,8 @@ void TerrainLoader::LoadFullMapRequest(const LoadRequestInternal& request)
}
}
}

return true;
});

DebugHandler::Print("TerrainLoader : Started Preparing Chunk Loading");
Expand Down
Loading

0 comments on commit 6267d33

Please sign in to comment.