Button FX now uses the easing functions. Viewport can now be fixed at an AR. #371
|
@ -0,0 +1,147 @@
|
|||
- EID: 0
|
||||
PrefabID: 117058283
|
||||
Name: ====Raccoon====
|
||||
IsActive: true
|
||||
NumberOfChildren: 2
|
||||
Components: ~
|
||||
Scripts: ~
|
||||
- EID: 1
|
||||
Name: Player
|
||||
IsActive: true
|
||||
NumberOfChildren: 3
|
||||
Components:
|
||||
Transform Component:
|
||||
Translate: {x: 2.35245037, y: 0.38365531, z: 7.10571432}
|
||||
Rotate: {x: -0, y: 0, z: -0}
|
||||
Scale: {x: 0.999999881, y: 1, z: 0.999999881}
|
||||
IsActive: true
|
||||
Renderable Component:
|
||||
Mesh: 149697411
|
||||
Material: 126974645
|
||||
IsActive: true
|
||||
RigidBody Component:
|
||||
Type: Dynamic
|
||||
Drag: 0.00999999978
|
||||
Angular Drag: 0.100000001
|
||||
Use Gravity: false
|
||||
Interpolate: false
|
||||
Sleeping Enabled: true
|
||||
Freeze Position X: false
|
||||
Freeze Position Y: true
|
||||
Freeze Position Z: false
|
||||
Freeze Rotation X: true
|
||||
Freeze Rotation Y: true
|
||||
Freeze Rotation Z: true
|
||||
IsActive: true
|
||||
Collider Component:
|
||||
Colliders:
|
||||
- Is Trigger: false
|
||||
Collision Tag: 0
|
||||
Type: Box
|
||||
Half Extents: {x: 0.400000006, y: 0.5, z: 0.300000012}
|
||||
Friction: 0.400000006
|
||||
Bounciness: 0
|
||||
Density: 1
|
||||
Position Offset: {x: 0, y: 0.25, z: 0}
|
||||
Rotation Offset: {x: 0, y: 0, z: 0}
|
||||
IsActive: true
|
||||
Scripts:
|
||||
- Type: PlayerController
|
||||
Enabled: true
|
||||
respawnPoint: 239
|
||||
currentState: 0
|
||||
maxMoveVel: 3
|
||||
moveForce: 50
|
||||
sprintMultiplier: 1.5
|
||||
rotationFactorPerFrame: 5
|
||||
maxJumpHeight: 2
|
||||
maxJumpTime: 0.75
|
||||
fallMultipler: 3
|
||||
lightMultiper: 0.899999976
|
||||
mediumMultiper: 0.699999988
|
||||
heavyMultiper: 0.5
|
||||
- Type: PickAndThrow
|
||||
Enabled: true
|
||||
throwForce: [10, 8, 10]
|
||||
cameraArmOffSet: [0.25, 0.600000024, 0.200000003]
|
||||
delayTimer: 1
|
||||
aimingLength: 1
|
||||
throwItem: false
|
||||
rayDistance: 0.75
|
||||
rayHeight: 0.100000001
|
||||
- EID: 2
|
||||
Name: HoldingPoint
|
||||
IsActive: true
|
||||
NumberOfChildren: 0
|
||||
Components:
|
||||
Transform Component:
|
||||
Translate: {x: 0, y: 0.899999976, z: 0.200000286}
|
||||
Rotate: {x: 0, y: 0, z: -0}
|
||||
Scale: {x: 1, y: 1, z: 1}
|
||||
IsActive: true
|
||||
Scripts: ~
|
||||
- EID: 3
|
||||
Name: PlayerCamera
|
||||
IsActive: true
|
||||
NumberOfChildren: 0
|
||||
Components:
|
||||
Transform Component:
|
||||
Translate: {x: 0, y: -5.96046448e-08, z: 0}
|
||||
Rotate: {x: 0, y: 6.28318548, z: 2.23517329e-08}
|
||||
Scale: {x: 1, y: 1, z: 1}
|
||||
IsActive: true
|
||||
Camera Component:
|
||||
Position: {x: 2.12735963, y: 0.362327784, z: 7.98933029}
|
||||
Pitch: 0
|
||||
Yaw: 360
|
||||
Roll: 1.28065994e-06
|
||||
Width: 2560
|
||||
Near: 0.00999999978
|
||||
Far: 10000
|
||||
Perspective: true
|
||||
FOV: 45
|
||||
IsActive: true
|
||||
Camera Arm Component:
|
||||
Arm Pitch: 0
|
||||
Arm Yaw: 0
|
||||
Arm Length: 3
|
||||
Look At Camera Origin: true
|
||||
Target Offset: {x: 0, y: 0.75, z: 0}
|
||||
Camera Collision: true
|
||||
IsActive: true
|
||||
Scripts:
|
||||
- Type: SHADE_Scripting.ThirdPersonCamera
|
||||
Enabled: true
|
||||
armLength: 3
|
||||
turnSpeedPitch: 0.200000003
|
||||
turnSpeedYaw: 0.400000006
|
||||
pitchClamp: 45
|
||||
inverseXControls: false
|
||||
inverseYControls: false
|
||||
lowerClamp: 5
|
||||
- EID: 4
|
||||
Name: PlayerBag
|
||||
IsActive: true
|
||||
NumberOfChildren: 0
|
||||
Components:
|
||||
Transform Component:
|
||||
Translate: {x: 0, y: -2.98023224e-08, z: 4.76837158e-07}
|
||||
Rotate: {x: 0, y: 0, z: -0}
|
||||
Scale: {x: 1, y: 1, z: 1}
|
||||
IsActive: true
|
||||
Renderable Component:
|
||||
Mesh: 144838771
|
||||
Material: 123745521
|
||||
IsActive: true
|
||||
Scripts: ~
|
||||
- EID: 5
|
||||
Name: RespawnPoint
|
||||
IsActive: true
|
||||
NumberOfChildren: 0
|
||||
Components:
|
||||
Transform Component:
|
||||
Translate: {x: 2.5, y: 0.660660267, z: 7}
|
||||
Rotate: {x: 0, y: 0, z: 0}
|
||||
Scale: {x: 1, y: 1, z: 1}
|
||||
IsActive: true
|
||||
Scripts: ~
|
|
@ -0,0 +1,3 @@
|
|||
Name: ====Raccoon====
|
||||
ID: 117058283
|
||||
Type: 6
|
|
@ -19,6 +19,10 @@
|
|||
#include "Tools/Utilities/SHStringUtilities.h"
|
||||
#include <filesystem>
|
||||
#include <rttr/type>
|
||||
#include "Assets/Asset Types/SHPrefabAsset.h"
|
||||
#include "Serialization/SHSerialization.h"
|
||||
#include <Editor/EditorWindow/HierarchyPanel/SHHierarchyPanel.h>
|
||||
#include "Serialization/Prefab/SHPrefabManager.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
|
@ -247,6 +251,7 @@ namespace SHADE
|
|||
const ImRect childRect = DrawAsset(file.assetMeta, file.ext);
|
||||
return childRect;
|
||||
}
|
||||
return ImRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax());
|
||||
}
|
||||
|
||||
ImRect SHAssetBrowser::DrawAsset(SHAsset const* const asset, FileExt const& ext /*= ""*/) noexcept
|
||||
|
@ -365,6 +370,35 @@ namespace SHADE
|
|||
}
|
||||
}
|
||||
|
||||
if(ImGui::BeginPopupContextItem())
|
||||
{
|
||||
switch (asset->type)
|
||||
{
|
||||
case AssetType::INVALID: break;
|
||||
case AssetType::SHADER: break;
|
||||
case AssetType::SHADER_BUILT_IN: break;
|
||||
case AssetType::TEXTURE: break;
|
||||
case AssetType::MESH: break;
|
||||
case AssetType::SCENE:
|
||||
break;
|
||||
case AssetType::PREFAB:
|
||||
{
|
||||
if(ImGui::Selectable("Insert into scene"))
|
||||
{
|
||||
auto createdEntitiesList = SHSerialization::DeserializeEntitiesFromString(SHAssetManager::GetData<SHPrefabAsset>(asset->id)->data);
|
||||
SHEditorWindowManager::GetEditorWindow<SHHierarchyPanel>()->SetScrollTo(createdEntitiesList.begin()->second);
|
||||
SHPrefabManager::AddEntity(asset->id, createdEntitiesList.begin()->second);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case AssetType::MATERIAL: break;
|
||||
case AssetType::SCRIPT: break;
|
||||
case AssetType::MAX_COUNT: break;
|
||||
default:;
|
||||
}
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
|
||||
if (ImGui::IsItemHovered())
|
||||
{
|
||||
ImGui::BeginTooltip();
|
||||
|
|
|
@ -26,6 +26,9 @@
|
|||
#include "Serialization/SHSerialization.h"
|
||||
#include "Tools/Utilities/SHClipboardUtilities.h"
|
||||
#include "Tools/Utilities/SHStringUtilities.h"
|
||||
#include "Serialization/Prefab/SHPrefabManager.h"
|
||||
#include "../SHEditorWindowManager.h"
|
||||
#include "../AssetBrowser/SHAssetBrowser.h"
|
||||
|
||||
|
||||
namespace SHADE
|
||||
|
@ -96,30 +99,32 @@ namespace SHADE
|
|||
}
|
||||
ImGui::SeparatorEx(ImGuiSeparatorFlags_Horizontal);
|
||||
|
||||
if (ImGui::IsKeyDown(ImGuiKey_LeftCtrl) && ImGui::IsKeyReleased(ImGuiKey_A))
|
||||
if (!ImGui::IsAnyItemFocused())
|
||||
{
|
||||
SelectAllEntities();
|
||||
}
|
||||
if (ImGui::IsKeyDown(ImGuiKey_LeftCtrl) && ImGui::IsKeyReleased(ImGuiKey_C))
|
||||
{
|
||||
CopySelectedEntities();
|
||||
}
|
||||
if (ImGui::IsKeyDown(ImGuiKey_LeftCtrl) && !ImGui::IsKeyDown(ImGuiKey_LeftShift) && ImGui::IsKeyReleased(ImGuiKey_V))
|
||||
{
|
||||
PasteEntities();
|
||||
}
|
||||
if (ImGui::IsKeyDown(ImGuiKey_LeftCtrl) && ImGui::IsKeyDown(ImGuiKey_LeftShift) && ImGui::IsKeyReleased(ImGuiKey_V))
|
||||
{
|
||||
if (editor->selectedEntities.size() == 1)
|
||||
if (ImGui::IsKeyDown(ImGuiKey_LeftCtrl) && ImGui::IsKeyReleased(ImGuiKey_A))
|
||||
{
|
||||
PasteEntities(editor->selectedEntities.back());
|
||||
SelectAllEntities();
|
||||
}
|
||||
if (ImGui::IsKeyDown(ImGuiKey_LeftCtrl) && ImGui::IsKeyReleased(ImGuiKey_C))
|
||||
{
|
||||
CopySelectedEntities();
|
||||
}
|
||||
if (ImGui::IsKeyDown(ImGuiKey_LeftCtrl) && !ImGui::IsKeyDown(ImGuiKey_LeftShift) && ImGui::IsKeyReleased(ImGuiKey_V))
|
||||
{
|
||||
PasteEntities();
|
||||
}
|
||||
if (ImGui::IsKeyDown(ImGuiKey_LeftCtrl) && ImGui::IsKeyDown(ImGuiKey_LeftShift) && ImGui::IsKeyReleased(ImGuiKey_V))
|
||||
{
|
||||
if (editor->selectedEntities.size() == 1)
|
||||
{
|
||||
PasteEntities(editor->selectedEntities.back());
|
||||
}
|
||||
}
|
||||
if (ImGui::IsKeyReleased(ImGuiKey_Delete))
|
||||
{
|
||||
DeleteSelectedEntities();
|
||||
}
|
||||
}
|
||||
if (ImGui::IsKeyReleased(ImGuiKey_Delete))
|
||||
{
|
||||
DeleteSelectedEntities();
|
||||
}
|
||||
|
||||
}
|
||||
if(ImGui::IsWindowHovered() && !ImGui::IsAnyItemHovered() && ImGui::IsMouseReleased(ImGuiMouseButton_Left))
|
||||
{
|
||||
|
@ -315,7 +320,7 @@ namespace SHADE
|
|||
|
||||
const ImGuiTreeNodeFlags nodeFlags = ((isSelected) ? ImGuiTreeNodeFlags_Selected : 0) | ((children.empty()) ? ImGuiTreeNodeFlags_Leaf : ImGuiTreeNodeFlags_OpenOnArrow);
|
||||
//Draw Node
|
||||
bool isNodeOpen = ImGui::TreeNodeEx(reinterpret_cast<void*>(eid), nodeFlags, "%u: %s", SHEntityManager::GetEntityIndex(eid), entity->name.c_str());
|
||||
bool isNodeOpen = ImGui::TreeNodeEx((void*)(eid), nodeFlags, "%u: %s", SHEntityManager::GetEntityIndex(eid), entity->name.c_str());
|
||||
|
||||
if(!filter.empty())
|
||||
{
|
||||
|
@ -388,6 +393,11 @@ namespace SHADE
|
|||
//SHEntityManager::DestroyEntity(eid);
|
||||
DeleteSelectedEntities();
|
||||
}
|
||||
if(ImGui::Selectable("Save entity as Prefab"))
|
||||
{
|
||||
SHPrefabManager::SaveEntityAsPrefab(eid);
|
||||
SHEditorWindowManager::GetEditorWindow<SHAssetBrowser>()->QueueRefresh();
|
||||
}
|
||||
|
||||
if ((currentNode->GetParent() != sceneGraph.GetRoot()) && ImGui::Selectable(std::format("{} Unparent Selected", ICON_MD_NORTH_WEST).data()))
|
||||
{
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
#include "Serialization/Configurations/SHConfigurationManager.h"
|
||||
#include "Editor/EditorWindow/SHEditorWindowManager.h"
|
||||
#include "Physics/System/SHPhysicsDebugDrawSystem.h"
|
||||
#include "Camera/SHCameraSystem.h"
|
||||
#include "Tools/Utilities/SHClipboardUtilities.h"
|
||||
|
||||
const std::string LAYOUT_FOLDER_PATH{ std::string(ASSET_ROOT) + "/Editor/Layouts" };
|
||||
|
||||
|
@ -154,7 +156,39 @@ namespace SHADE
|
|||
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImGui::GetStyle().Colors[ImGuiCol_MenuBarBg]);
|
||||
if (ImGui::BeginViewportSideBar("MainStatusBar", ImGui::GetMainViewport(), ImGuiDir_Down, menuBarHeight, editorMenuBarFlags))
|
||||
{
|
||||
ImGui::Text("Entity count: %zu", SHEntityManager::GetEntityCount());
|
||||
auto camSystem = SHSystemManager::GetSystem<SHCameraSystem>();
|
||||
std::string editorCamPosText{};
|
||||
auto editorCam = camSystem->GetEditorCamera();
|
||||
if(editorCam)
|
||||
{
|
||||
auto editorCamPos = editorCam->GetPosition();
|
||||
editorCamPosText = std::format("Editor Cam [X: {:.3f}, Y: {:.3f}, Z: {:.3f}]", editorCamPos.x, editorCamPos.y, editorCamPos.z);
|
||||
|
||||
//ImGui::Text(editorCamPosText.data());
|
||||
}
|
||||
ImGui::Text("Entity count: %zu %s", SHEntityManager::GetEntityCount(), editorCamPosText.data());
|
||||
if(ImGui::BeginPopupContextItem("EditorCamPosContext"))
|
||||
{
|
||||
if(editorCam)
|
||||
{
|
||||
if(ImGui::Selectable("Copy Editor Cam Pos X"))
|
||||
{
|
||||
auto editorCamPos = editorCam->GetPosition();
|
||||
SHClipboardUtilities::WriteToClipboard(std::format("{:.3f}", editorCamPos.x));
|
||||
}
|
||||
if (ImGui::Selectable("Copy Editor Cam Pos Y"))
|
||||
{
|
||||
auto editorCamPos = editorCam->GetPosition();
|
||||
SHClipboardUtilities::WriteToClipboard(std::format("{:.3f}", editorCamPos.y));
|
||||
}
|
||||
if (ImGui::Selectable("Copy Editor Cam Pos Z"))
|
||||
{
|
||||
auto editorCamPos = editorCam->GetPosition();
|
||||
SHClipboardUtilities::WriteToClipboard(std::format("{:.3f}", editorCamPos.z));
|
||||
}
|
||||
}
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
}
|
||||
ImGui::End();
|
||||
ImGui::PopStyleColor();
|
||||
|
|
|
@ -122,12 +122,22 @@ namespace SHADE
|
|||
|
||||
//auto pos = ImGui::GetCursorPos();
|
||||
//windowCursorPos = {}
|
||||
|
||||
if (beginContentRegionAvailable.x == 0 || beginContentRegionAvailable.y == 0)
|
||||
{
|
||||
beginContentRegionAvailable = windowSize;
|
||||
}
|
||||
gfxSystem->PrepareResize(static_cast<uint32_t>(beginContentRegionAvailable.x), static_cast<uint32_t>(beginContentRegionAvailable.y));
|
||||
|
||||
//beginContentRegionAvailable = CalculateWindowSize(beginContentRegionAvailable);
|
||||
SHVec2 viewportSize = CalculateWindowSize(beginContentRegionAvailable);
|
||||
gfxSystem->PrepareResize(static_cast<uint32_t>(viewportSize.x), static_cast<uint32_t>(viewportSize.y));
|
||||
shouldUpdateCamera = true;
|
||||
//if (aspectRatio != AspectRatio::FREE && (ImGui::IsMouseDown(ImGuiMouseButton_Left) || ImGui::IsMouseReleased(ImGuiMouseButton_Left)))
|
||||
//{
|
||||
// windowSize = CalculateWindowSize(windowSize);
|
||||
// beginContentRegionAvailable = CalculateWindowSize(beginContentRegionAvailable);
|
||||
// ImGui::SetWindowSize(windowName.data(), CalculateWindowSize(windowSize));
|
||||
//}
|
||||
}
|
||||
|
||||
void SHEditorViewport::OnPosChange()
|
||||
|
@ -195,13 +205,73 @@ namespace SHADE
|
|||
ImGui::PopStyleColor();
|
||||
ImGui::EndDisabled();
|
||||
|
||||
//TODO: Shift to constructor
|
||||
auto arRTTRtype = rttr::type::get<SHEditorViewport::AspectRatio>();
|
||||
auto enumAlign = arRTTRtype.get_enumeration();
|
||||
auto names = enumAlign.get_names();
|
||||
std::vector<const char*> arNames;
|
||||
for (auto const& name : names)
|
||||
{
|
||||
arNames.push_back(name.data());
|
||||
}
|
||||
int currentAR = static_cast<int>(aspectRatio);
|
||||
ImGui::SetNextItemWidth(80.0f);
|
||||
if (ImGui::Combo("Aspect Ratio", ¤tAR, arNames.data(), arNames.size()))
|
||||
{
|
||||
aspectRatio = static_cast<AspectRatio>(currentAR);
|
||||
windowSize = CalculateWindowSize(windowSize);
|
||||
ImGui::SetWindowSize(windowSize);
|
||||
//beginContentRegionAvailable = CalculateWindowSize(beginContentRegionAvailable);
|
||||
//OnResize();
|
||||
}
|
||||
|
||||
auto camSystem = SHSystemManager::GetSystem<SHCameraSystem>();
|
||||
auto editorCamera = camSystem->GetEditorCamera();
|
||||
//ImGui::SetNextItemWidth(10.0f);
|
||||
SHEditorWidgets::SliderFloat("CamSpeed", 0.0f, 5.0f, [editorCamera] {return editorCamera->movementSpeed; }, [editorCamera](float const& value) {editorCamera->movementSpeed = value; });
|
||||
SHEditorWidgets::DragVec3("TurnSpeed", { "X", "Y", "Z" }, [editorCamera] {return editorCamera->turnSpeed; }, [editorCamera](SHVec3 const& value) {editorCamera->turnSpeed = value; });
|
||||
|
||||
//if(ImGui::BeginCombo("Aspect Ratio", arNames[(uint8_t)aspectRatio].data()))
|
||||
//{
|
||||
// auto nameIt = names.begin();
|
||||
// auto valueIt = values.end();
|
||||
// while(nameIt != names.end() && valueIt != values.end())
|
||||
// {
|
||||
// if ImGui::Beg
|
||||
// }
|
||||
//}
|
||||
|
||||
ImGui::EndMenuBar();
|
||||
}
|
||||
}
|
||||
|
||||
SHVec2 SHEditorViewport::CalculateWindowSize(SHVec2 const& rhs) noexcept
|
||||
{
|
||||
switch (aspectRatio)
|
||||
{
|
||||
case SHADE::SHEditorViewport::AspectRatio::FREE:
|
||||
return rhs;
|
||||
case SHADE::SHEditorViewport::AspectRatio::AR16_9:
|
||||
return SHVec2(rhs.x, rhs.x * 0.5625f);
|
||||
case SHADE::SHEditorViewport::AspectRatio::AR21_9:
|
||||
return SHVec2(rhs.x, rhs.x * 0.42857f);
|
||||
case SHADE::SHEditorViewport::AspectRatio::AR21_10:
|
||||
return SHVec2(rhs.x, rhs.x * 0.47619f);
|
||||
default:
|
||||
return rhs;
|
||||
}
|
||||
}
|
||||
|
||||
}//namespace SHADE
|
||||
|
||||
RTTR_REGISTRATION
|
||||
{
|
||||
using namespace rttr;
|
||||
using namespace SHADE;
|
||||
registration::enumeration<SHEditorViewport::AspectRatio>("AspectRatio")(
|
||||
value("FREE", SHEditorViewport::AspectRatio::FREE),
|
||||
value("16:9", SHEditorViewport::AspectRatio::AR16_9),
|
||||
value("21:9", SHEditorViewport::AspectRatio::AR21_9),
|
||||
value("21:10", SHEditorViewport::AspectRatio::AR21_10)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -16,7 +16,15 @@ namespace SHADE
|
|||
{
|
||||
class SHEditorViewport final : public SHEditorWindow
|
||||
{
|
||||
|
||||
public:
|
||||
enum class AspectRatio : uint8_t
|
||||
{
|
||||
FREE,
|
||||
AR16_9,
|
||||
AR21_9,
|
||||
AR21_10
|
||||
};
|
||||
SHEditorViewport();
|
||||
void Init() override;
|
||||
void Update() override;
|
||||
|
@ -27,9 +35,12 @@ namespace SHADE
|
|||
void OnPosChange() override;
|
||||
private:
|
||||
void DrawMenuBar() noexcept;
|
||||
SHVec2 beginCursorPos;
|
||||
SHVec2 CalculateWindowSize(SHVec2 const& rhs) noexcept;
|
||||
|
||||
bool shouldUpdateCamera = false;
|
||||
bool shouldUpdateCamArm = false;
|
||||
AspectRatio aspectRatio {AspectRatio::FREE};
|
||||
SHVec2 beginCursorPos;
|
||||
SHVec3 targetPos;
|
||||
};//class SHEditorViewport
|
||||
}//namespace SHADE
|
||||
|
|
|
@ -1,13 +1,29 @@
|
|||
#include "SHpch.h"
|
||||
#include "SHPrefabManager.h"
|
||||
#include "ECS_Base/Managers/SHEntityManager.h"
|
||||
#include "Assets/SHAssetManager.h"
|
||||
#include "Assets/Asset Types/SHPrefabAsset.h"
|
||||
#include "Serialization/SHSerialization.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
SHPrefabManager::PrefabMap SHPrefabManager::prefabMap{};
|
||||
|
||||
AssetID SHPrefabManager::GetPrefabAssetID(EntityID eid) noexcept
|
||||
{
|
||||
for(auto const& [assetId, entityList] : prefabMap)
|
||||
{
|
||||
if(std::ranges::find(entityList, eid) != entityList.end())
|
||||
{
|
||||
return assetId;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void SHPrefabManager::AddPrefab(AssetID const& prefabAssetID) noexcept
|
||||
{
|
||||
prefabMap.insert({ prefabAssetID, {} });
|
||||
prefabMap[prefabAssetID] = {};
|
||||
}
|
||||
|
||||
void SHPrefabManager::RemovePrefab(AssetID const& prefabAssetID) noexcept
|
||||
|
@ -30,20 +46,30 @@ namespace SHADE
|
|||
|
||||
void SHPrefabManager::AddEntity(AssetID const& prefabAssetID, EntityID const& eid) noexcept
|
||||
{
|
||||
if (prefabMap.contains(prefabAssetID))
|
||||
{
|
||||
prefabMap[prefabAssetID].insert(eid);
|
||||
}
|
||||
|
||||
prefabMap[prefabAssetID].push_back(eid);
|
||||
|
||||
}
|
||||
|
||||
void SHPrefabManager::RemoveEntity(AssetID const& prefabAssetID, EntityID const& eid) noexcept
|
||||
{
|
||||
if (prefabMap.contains(prefabAssetID))
|
||||
{
|
||||
prefabMap[prefabAssetID].erase(eid);
|
||||
(void)std::ranges::remove(prefabMap[prefabAssetID], eid);
|
||||
}
|
||||
}
|
||||
|
||||
void SHPrefabManager::SaveEntityAsPrefab(EntityID const& eid) noexcept
|
||||
{
|
||||
SHEntity* const entity = SHEntityManager::GetEntityByID(eid);
|
||||
AssetID const assetID = SHAssetManager::CreateNewAsset(AssetType::PREFAB, entity->name);
|
||||
AddEntity(assetID, eid);
|
||||
auto assetData = SHAssetManager::GetData<SHPrefabAsset>(assetID);
|
||||
assetData->data = SHSerialization::SerializeEntityToString(eid);
|
||||
|
||||
SHAssetManager::SaveAsset(assetID);
|
||||
}
|
||||
|
||||
void SHPrefabManager::Clear() noexcept
|
||||
{
|
||||
prefabMap.clear();
|
||||
|
|
|
@ -2,7 +2,8 @@
|
|||
|
||||
#include "Assets/SHAssetMacros.h"
|
||||
#include "ECS_Base/SHECSMacros.h"
|
||||
#include <unordered_set>
|
||||
#include "ECS_Base/General/SHFamily.h"
|
||||
#include "ECS_Base/Components/SHComponent.h"
|
||||
#include <unordered_map>
|
||||
|
||||
|
||||
|
@ -11,18 +12,34 @@ namespace SHADE
|
|||
class SHPrefabManager
|
||||
{
|
||||
public:
|
||||
using PrefabMap = std::unordered_map<AssetID, std::unordered_set<EntityID>>;
|
||||
|
||||
enum class PrefabEntityComponentStatus : uint8_t
|
||||
{
|
||||
PES_UNCHANGED = 0,
|
||||
PES_MODIFIED,
|
||||
PES_ADDED,
|
||||
PES_REMOVED
|
||||
};
|
||||
|
||||
using PrefabMap = std::unordered_map<AssetID, std::vector<EntityID>>;
|
||||
using PrefabEntitiesComponentStatusData = std::unordered_map<EntityID, std::unordered_map<SHFamilyID<SHComponent>,PrefabEntityComponentStatus>>;
|
||||
|
||||
static AssetID GetPrefabAssetID(EntityID eid) noexcept;
|
||||
static void AddPrefab(AssetID const& prefabAssetID) noexcept;
|
||||
static void RemovePrefab(AssetID const& prefabAssetID) noexcept;
|
||||
static void ClearPrefab(AssetID const& prefabAssetID) noexcept;
|
||||
static void UpdateAllPrefabEntities(AssetID const& prefabAssetID) noexcept;
|
||||
static void AddEntity(AssetID const& prefabAssetID, EntityID const& eid) noexcept;
|
||||
static void RemoveEntity(AssetID const& prefabAssetID, EntityID const& eid) noexcept;
|
||||
static void SaveEntityAsPrefab(EntityID const& eid) noexcept;
|
||||
static void Clear() noexcept;
|
||||
static bool Empty() noexcept;
|
||||
|
||||
private:
|
||||
static PrefabMap prefabMap;
|
||||
static PrefabEntitiesComponentStatusData prefabEntitiesComponentStatusData;
|
||||
|
||||
friend class SHSerialization;
|
||||
friend struct SHSerializationHelper;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include "ECS_Base/Managers/SHSystemManager.h"
|
||||
#include "Scripting/SHScriptEngine.h"
|
||||
#include "Tools/FileIO/SHFileIO.h"
|
||||
#include "Prefab/SHPrefabManager.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
|
@ -23,7 +24,7 @@ namespace SHADE
|
|||
auto assetData = SHAssetManager::GetData<SHSceneAsset>(sceneAssetID);
|
||||
if(!assetData)
|
||||
{
|
||||
SHLOG_ERROR("Asset does not exist: {}", sceneAssetID);
|
||||
SHLOG_ERROR("Serialization: Asset does not exist: {}", sceneAssetID);
|
||||
return false;
|
||||
}
|
||||
YAML::Emitter out;
|
||||
|
@ -45,7 +46,7 @@ namespace SHADE
|
|||
auto const& sceneGraph = SHSceneManager::GetCurrentSceneGraph();
|
||||
auto root = sceneGraph.GetRoot();
|
||||
|
||||
SHASSERT(root != nullptr, "Root is null. Failed to serialize scene to node.");
|
||||
SHASSERT(root != nullptr, "Serialization: Root is null. Failed to serialize scene to node.");
|
||||
|
||||
auto const& children = root->GetChildren();
|
||||
out << YAML::BeginSeq;
|
||||
|
@ -62,6 +63,7 @@ namespace SHADE
|
|||
EntityID eid{MAX_EID}, oldEID{MAX_EID};
|
||||
if (!node)
|
||||
return eid;
|
||||
|
||||
if (node[EIDNode])
|
||||
oldEID = eid = node[EIDNode].as<EntityID>();
|
||||
std::string name = "UnnamedEntitiy";
|
||||
|
@ -105,7 +107,7 @@ namespace SHADE
|
|||
auto assetData = SHAssetManager::GetData<SHSceneAsset>(sceneAssetID);
|
||||
if(!assetData)
|
||||
{
|
||||
SHLOG_ERROR("Attempted to load scene that doesn't exist {}", sceneAssetID)
|
||||
SHLOG_ERROR("Serialization: Attempted to load scene that doesn't exist {}", sceneAssetID)
|
||||
SHSceneManager::SetCurrentSceneAssetID(0);
|
||||
return NewSceneName.data();
|
||||
}
|
||||
|
@ -119,7 +121,7 @@ namespace SHADE
|
|||
}
|
||||
if (createdEntities.empty())
|
||||
{
|
||||
SHLOG_ERROR("Failed to create entities from deserializaiton")
|
||||
SHLOG_ERROR("Serialization: Failed to create entities from deserialization")
|
||||
return NewSceneName.data();
|
||||
}
|
||||
auto entityVecIt = createdEntities.begin();
|
||||
|
@ -139,13 +141,16 @@ namespace SHADE
|
|||
return assetData->name;
|
||||
}
|
||||
|
||||
void SHSerialization::EmitEntity(SHSceneNode* entityNode, YAML::Emitter& out)
|
||||
void SHSerialization::EmitEntity(SHSceneNode* entityNode, YAML::Emitter& out, bool isPrefab /*= false*/, EntityID* entityIndex /*= nullptr*/)
|
||||
{
|
||||
out << SerializeEntityToNode(entityNode);
|
||||
out << SerializeEntityToNode(entityNode, isPrefab, entityIndex);
|
||||
if(isPrefab)
|
||||
++(*entityIndex);
|
||||
|
||||
auto const& children = entityNode->GetChildren();
|
||||
for (auto const& child : children)
|
||||
{
|
||||
EmitEntity(child, out);
|
||||
EmitEntity(child, out, isPrefab, entityIndex);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -155,6 +160,7 @@ namespace SHADE
|
|||
YAML::Node node;
|
||||
auto const& sceneGraph = SHSceneManager::GetCurrentSceneGraph();
|
||||
out << YAML::BeginSeq;
|
||||
EntityID entityIndex = 0;
|
||||
for (auto const& eid : entities)
|
||||
{
|
||||
auto entityNode = sceneGraph.GetNode(eid);
|
||||
|
@ -164,6 +170,21 @@ namespace SHADE
|
|||
return std::string(out.c_str());
|
||||
}
|
||||
|
||||
std::string SHSerialization::SerializeEntityToString(EntityID eid) noexcept
|
||||
{
|
||||
YAML::Emitter out;
|
||||
YAML::Node node;
|
||||
auto const& sceneGraph = SHSceneManager::GetCurrentSceneGraph();
|
||||
out << YAML::BeginSeq;
|
||||
EntityID entityIndex = 0;
|
||||
|
||||
auto entityNode = sceneGraph.GetNode(eid);
|
||||
EmitEntity(entityNode, out, true, &entityIndex);
|
||||
|
||||
out << YAML::EndSeq;
|
||||
return std::string(out.c_str());
|
||||
}
|
||||
|
||||
//void SHSerialization::SerializeEntityToFile(std::filesystem::path const& path)
|
||||
//{
|
||||
//}
|
||||
|
@ -179,8 +200,11 @@ namespace SHADE
|
|||
}
|
||||
}
|
||||
|
||||
YAML::Node SHSerialization::SerializeEntityToNode(SHSceneNode* sceneNode)
|
||||
YAML::Node SHSerialization::SerializeEntityToNode(SHSceneNode* sceneNode, bool isPrefab /*= false*/, EntityID* entityIndex /*= nullptr*/)
|
||||
{
|
||||
if(!sceneNode)
|
||||
return YAML::Node();
|
||||
|
||||
YAML::Node node;
|
||||
auto eid = sceneNode->GetEntityID();
|
||||
auto entity = SHEntityManager::GetEntityByID(eid);
|
||||
|
@ -190,7 +214,15 @@ namespace SHADE
|
|||
return node;
|
||||
}
|
||||
node.SetStyle(YAML::EmitterStyle::Block);
|
||||
node[EIDNode] = eid;
|
||||
|
||||
node[EIDNode] = (entityIndex) ? *entityIndex : eid;
|
||||
|
||||
AssetID prefabAssetID = SHPrefabManager::GetPrefabAssetID(eid);
|
||||
if(prefabAssetID != 0)
|
||||
{
|
||||
node[PrefabID] = prefabAssetID;
|
||||
}
|
||||
|
||||
node[EntityNameNode] = entity->name;
|
||||
node[IsActiveNode] = sceneNode->IsActive();
|
||||
auto const& children = sceneNode->GetChildren();
|
||||
|
@ -237,7 +269,7 @@ namespace SHADE
|
|||
}
|
||||
if (createdEntities.empty())
|
||||
{
|
||||
SHLOG_ERROR("Failed to create entities from deserializaiton")
|
||||
SHLOG_ERROR("Failed to create entities from deserialization")
|
||||
return createdEntities;
|
||||
}
|
||||
//auto entityVecIt = createdEntities.begin();
|
||||
|
|
|
@ -24,6 +24,7 @@ namespace SHADE
|
|||
constexpr const char* IsActiveNode = "IsActive";
|
||||
constexpr const char* NumberOfChildrenNode = "NumberOfChildren";
|
||||
constexpr const char* ScriptsNode = "Scripts";
|
||||
constexpr const char* PrefabID = "PrefabID";
|
||||
|
||||
class SH_API SHSerialization
|
||||
{
|
||||
|
@ -37,12 +38,13 @@ namespace SHADE
|
|||
|
||||
static std::string DeserializeSceneFromFile(AssetID const& sceneAssetID) noexcept;
|
||||
|
||||
|
||||
static void EmitEntity(SHSceneNode* entityNode, YAML::Emitter& out);
|
||||
static void EmitEntity(SHSceneNode* entityNode, YAML::Emitter& out, bool isPrefab = false, EntityID* entityIndex = nullptr);
|
||||
|
||||
static std::string SerializeEntitiesToString(std::vector<EntityID> const& entities) noexcept;
|
||||
|
||||
static std::string SerializeEntityToString(EntityID eid) noexcept;
|
||||
//static void SerializeEntityToFile(std::filesystem::path const& path);
|
||||
static YAML::Node SerializeEntityToNode(SHSceneNode* sceneNode);
|
||||
static YAML::Node SerializeEntityToNode(SHSceneNode* sceneNode, bool isPrefab = false, EntityID* entityIndex = nullptr);
|
||||
|
||||
static CreatedEntitiesList DeserializeEntitiesFromString(std::string const& data, EntityID const& parentEID = MAX_EID) noexcept;
|
||||
|
||||
|
|
|
@ -135,6 +135,7 @@ namespace SHADE
|
|||
|
||||
}
|
||||
}
|
||||
return YAML::Node();
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
|
|
|
@ -482,11 +482,20 @@ namespace SHADE
|
|||
{
|
||||
SAFE_NATIVE_CALL_BEGIN
|
||||
// Clear the awake queue
|
||||
for each (Script^ script in awakeList)
|
||||
for each (Script ^ script in awakeList)
|
||||
{
|
||||
script->Awake();
|
||||
if (script->Owner.IsActiveInHierarchy)
|
||||
{
|
||||
script->Awake();
|
||||
}
|
||||
else
|
||||
{
|
||||
inactiveAwakeList.Add(script);
|
||||
}
|
||||
}
|
||||
awakeList.Clear();
|
||||
awakeList.UnionWith(%inactiveAwakeList);
|
||||
inactiveAwakeList.Clear();
|
||||
|
||||
// Clear the start queue
|
||||
for each (Script^ script in startList)
|
||||
|
@ -501,10 +510,7 @@ namespace SHADE
|
|||
}
|
||||
}
|
||||
startList.Clear();
|
||||
for each (Script ^ script in startList)
|
||||
{
|
||||
startList.Add(script);
|
||||
}
|
||||
startList.UnionWith(%inactiveStartList);
|
||||
inactiveStartList.Clear();
|
||||
|
||||
SAFE_NATIVE_CALL_END_N("SHADE_Managed.ScriptStore")
|
||||
|
|
|
@ -353,6 +353,7 @@ namespace SHADE
|
|||
/*-----------------------------------------------------------------------------*/
|
||||
static ScriptDictionary scripts;
|
||||
static ScriptSet awakeList;
|
||||
static ScriptSet inactiveAwakeList;
|
||||
static ScriptSet startList;
|
||||
static ScriptSet inactiveStartList;
|
||||
static ScriptSet disposalQueue;
|
||||
|
|
Loading…
Reference in New Issue