Updated Drag and drop, & other improvements
This commit is contained in:
parent
c72ff1fc99
commit
fca9640e72
49
imgui.ini
49
imgui.ini
@ -21,13 +21,13 @@ DockId=0x00000018,0
|
|||||||
|
|
||||||
[Window][Scene Tree]
|
[Window][Scene Tree]
|
||||||
Pos=0,19
|
Pos=0,19
|
||||||
Size=347,350
|
Size=335,350
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
DockId=0x0000000F,0
|
DockId=0x0000000F,0
|
||||||
|
|
||||||
[Window][Viewport]
|
[Window][Viewport]
|
||||||
Pos=349,19
|
Pos=337,19
|
||||||
Size=562,202
|
Size=574,202
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
DockId=0x00000017,0
|
DockId=0x00000017,0
|
||||||
|
|
||||||
@ -36,14 +36,14 @@ Size=1280,19
|
|||||||
Collapsed=0
|
Collapsed=0
|
||||||
|
|
||||||
[Window][Performance Info]
|
[Window][Performance Info]
|
||||||
Pos=1094,223
|
Pos=1106,223
|
||||||
Size=186,497
|
Size=174,268
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
DockId=0x00000016,0
|
DockId=0x00000019,0
|
||||||
|
|
||||||
[Window][Console]
|
[Window][Console]
|
||||||
Pos=349,223
|
Pos=337,223
|
||||||
Size=710,273
|
Size=736,497
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
DockId=0x00000013,0
|
DockId=0x00000013,0
|
||||||
|
|
||||||
@ -54,8 +54,8 @@ Collapsed=0
|
|||||||
DockId=0x00000017,1
|
DockId=0x00000017,1
|
||||||
|
|
||||||
[Window][Profiler]
|
[Window][Profiler]
|
||||||
Pos=349,498
|
Pos=482,955
|
||||||
Size=710,222
|
Size=1068,222
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
DockId=0x00000014,0
|
DockId=0x00000014,0
|
||||||
|
|
||||||
@ -78,9 +78,10 @@ Collapsed=0
|
|||||||
DockId=0x00000015,1
|
DockId=0x00000015,1
|
||||||
|
|
||||||
[Window][Color Correction]
|
[Window][Color Correction]
|
||||||
Pos=1196,320
|
Pos=1106,493
|
||||||
Size=317,227
|
Size=174,227
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
|
DockId=0x0000001A,0
|
||||||
|
|
||||||
[Window][Asset Browser]
|
[Window][Asset Browser]
|
||||||
Pos=0,658
|
Pos=0,658
|
||||||
@ -112,8 +113,8 @@ Collapsed=0
|
|||||||
DockId=0x0000000E,0
|
DockId=0x0000000E,0
|
||||||
|
|
||||||
[Window][Audio Output]
|
[Window][Audio Output]
|
||||||
Pos=1061,223
|
Pos=1075,223
|
||||||
Size=31,497
|
Size=29,497
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
DockId=0x00000012,0
|
DockId=0x00000012,0
|
||||||
|
|
||||||
@ -125,12 +126,12 @@ DockId=0x0000000D,0
|
|||||||
|
|
||||||
[Window][Resources]
|
[Window][Resources]
|
||||||
Pos=0,371
|
Pos=0,371
|
||||||
Size=347,349
|
Size=335,349
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
DockId=0x00000010,0
|
DockId=0x00000010,0
|
||||||
|
|
||||||
[Window][Import Preview]
|
[Window][Import Preview]
|
||||||
Pos=351,22
|
Pos=584,22
|
||||||
Size=536,391
|
Size=536,391
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
|
|
||||||
@ -142,22 +143,24 @@ Column 1 Width=120
|
|||||||
[Docking][Data]
|
[Docking][Data]
|
||||||
DockSpace ID=0x11111111 Window=0x1BBC0F80 Pos=0,19 Size=1280,701 Split=X
|
DockSpace ID=0x11111111 Window=0x1BBC0F80 Pos=0,19 Size=1280,701 Split=X
|
||||||
DockNode ID=0x00000005 Parent=0x11111111 SizeRef=989,1158 Split=X
|
DockNode ID=0x00000005 Parent=0x11111111 SizeRef=989,1158 Split=X
|
||||||
DockNode ID=0x00000001 Parent=0x00000005 SizeRef=347,701 Split=Y Selected=0x12EF0F59
|
DockNode ID=0x00000001 Parent=0x00000005 SizeRef=335,701 Split=Y Selected=0x12EF0F59
|
||||||
DockNode ID=0x00000003 Parent=0x00000001 SizeRef=342,637 Split=Y Selected=0x12EF0F59
|
DockNode ID=0x00000003 Parent=0x00000001 SizeRef=342,637 Split=Y Selected=0x12EF0F59
|
||||||
DockNode ID=0x0000000F Parent=0x00000003 SizeRef=342,579 HiddenTabBar=1 Selected=0x12EF0F59
|
DockNode ID=0x0000000F Parent=0x00000003 SizeRef=342,579 HiddenTabBar=1 Selected=0x12EF0F59
|
||||||
DockNode ID=0x00000010 Parent=0x00000003 SizeRef=342,577 HiddenTabBar=1 Selected=0x30401527
|
DockNode ID=0x00000010 Parent=0x00000003 SizeRef=342,577 HiddenTabBar=1 Selected=0x30401527
|
||||||
DockNode ID=0x00000004 Parent=0x00000001 SizeRef=342,519 HiddenTabBar=1 Selected=0x36AF052B
|
DockNode ID=0x00000004 Parent=0x00000001 SizeRef=342,519 HiddenTabBar=1 Selected=0x36AF052B
|
||||||
DockNode ID=0x00000002 Parent=0x00000005 SizeRef=1571,701 Split=Y Selected=0xC450F867
|
DockNode ID=0x00000002 Parent=0x00000005 SizeRef=943,701 Split=Y Selected=0xC450F867
|
||||||
DockNode ID=0x00000007 Parent=0x00000002 SizeRef=606,659 Split=X Selected=0xC450F867
|
DockNode ID=0x00000007 Parent=0x00000002 SizeRef=606,659 Split=X Selected=0xC450F867
|
||||||
DockNode ID=0x00000017 Parent=0x00000007 SizeRef=1202,860 CentralNode=1 HiddenTabBar=1 Selected=0xC450F867
|
DockNode ID=0x00000017 Parent=0x00000007 SizeRef=574,860 CentralNode=1 HiddenTabBar=1 Selected=0xC450F867
|
||||||
DockNode ID=0x00000018 Parent=0x00000007 SizeRef=367,860 HiddenTabBar=1 Selected=0x36DC96AB
|
DockNode ID=0x00000018 Parent=0x00000007 SizeRef=367,860 HiddenTabBar=1 Selected=0x36DC96AB
|
||||||
DockNode ID=0x00000008 Parent=0x00000002 SizeRef=606,497 Split=X Selected=0xEA83D666
|
DockNode ID=0x00000008 Parent=0x00000002 SizeRef=606,497 Split=X Selected=0xEA83D666
|
||||||
DockNode ID=0x00000015 Parent=0x00000008 SizeRef=1255,172 Split=X Selected=0xEA83D666
|
DockNode ID=0x00000015 Parent=0x00000008 SizeRef=767,172 Split=X Selected=0xEA83D666
|
||||||
DockNode ID=0x00000011 Parent=0x00000015 SizeRef=1201,168 Split=Y Selected=0x9B5D3198
|
DockNode ID=0x00000011 Parent=0x00000015 SizeRef=736,168 Split=Y Selected=0x9B5D3198
|
||||||
DockNode ID=0x00000013 Parent=0x00000011 SizeRef=1449,273 HiddenTabBar=1 Selected=0xEA83D666
|
DockNode ID=0x00000013 Parent=0x00000011 SizeRef=1449,273 HiddenTabBar=1 Selected=0xEA83D666
|
||||||
DockNode ID=0x00000014 Parent=0x00000011 SizeRef=1449,222 HiddenTabBar=1 Selected=0x9B5D3198
|
DockNode ID=0x00000014 Parent=0x00000011 SizeRef=1449,222 HiddenTabBar=1 Selected=0x9B5D3198
|
||||||
DockNode ID=0x00000012 Parent=0x00000015 SizeRef=52,168 HiddenTabBar=1 Selected=0x56009A08
|
DockNode ID=0x00000012 Parent=0x00000015 SizeRef=29,168 HiddenTabBar=1 Selected=0x56009A08
|
||||||
DockNode ID=0x00000016 Parent=0x00000008 SizeRef=314,172 HiddenTabBar=1 Selected=0x3FC1A724
|
DockNode ID=0x00000016 Parent=0x00000008 SizeRef=174,172 Split=Y Selected=0x3FC1A724
|
||||||
|
DockNode ID=0x00000019 Parent=0x00000016 SizeRef=314,268 HiddenTabBar=1 Selected=0x3FC1A724
|
||||||
|
DockNode ID=0x0000001A Parent=0x00000016 SizeRef=314,227 HiddenTabBar=1 Selected=0xA873C17F
|
||||||
DockNode ID=0x00000006 Parent=0x11111111 SizeRef=289,1158 Split=Y Selected=0x36DC96AB
|
DockNode ID=0x00000006 Parent=0x11111111 SizeRef=289,1158 Split=Y Selected=0x36DC96AB
|
||||||
DockNode ID=0x00000009 Parent=0x00000006 SizeRef=449,488 Split=Y Selected=0x36DC96AB
|
DockNode ID=0x00000009 Parent=0x00000006 SizeRef=449,488 Split=Y Selected=0x36DC96AB
|
||||||
DockNode ID=0x0000000B Parent=0x00000009 SizeRef=449,556 Split=Y Selected=0x36DC96AB
|
DockNode ID=0x0000000B Parent=0x00000009 SizeRef=449,556 Split=Y Selected=0x36DC96AB
|
||||||
|
@ -0,0 +1,3 @@
|
|||||||
|
[COMPILE] g++ -std=c++20 -Wall -g -Isrc/include -Isrc/include/lua -Isrc/vendor -Isrc/vendor/imgui -Isrc/vendor/box2d -Isrc/vendor/xxhash -Isrc/vendor/miniaudio -Isrc/vendor/imguizmo -IC:/msys64/mingw64/include -IC:\msys64\mingw64\lib\libyaml-cpp.a -Isrc\vendor\imgui -MMD -MP -c src\src\core\audio\AudioEngine.cpp -o src\build\core\audio\AudioEngine.o
|
||||||
|
[COMPILE] g++ -std=c++20 -Wall -g -Isrc/include -Isrc/include/lua -Isrc/vendor -Isrc/vendor/imgui -Isrc/vendor/box2d -Isrc/vendor/xxhash -Isrc/vendor/miniaudio -Isrc/vendor/imguizmo -IC:/msys64/mingw64/include -IC:\msys64\mingw64\lib\libyaml-cpp.a -Isrc\vendor\imgui -MMD -MP -c src\src\Engine.cpp -o src\build\Engine.o
|
||||||
|
[LINK] g++ src\build\Engine.o src\build\main.o src\build\Renderer.o src\build\Components\AnimationComponent.o src\build\Components\AudioPlayerComponent.o src\build\Components\CameraComponent.o src\build\Components\LightComponent.o src\build\Components\ParticleComponent.o src\build\Components\PhysicsComponent.o src\build\Components\ScriptComponent.o src\build\Components\SpriteComponent.o src\build\Components\TextComonent.o src\build\Components\TilemapComponent.o src\build\core\audio\AudioEngine.o src\build\core\functions\Prefab.o src\build\core\utils\AssetManager.o src\build\core\utils\EngineConfig.o src\build\core\utils\ExceptionHandler.o src\build\core\utils\FileDialog.o src\build\core\utils\input.o src\build\core\utils\LoadingWindow.o src\build\core\utils\Logging.o src\build\core\utils\Popup.o src\build\core\utils\Profiler.o src\build\core\utils\Texture.o src\build\core\utils\utils.o src\build\editor\windows\AssetBrowser.o src\build\editor\windows\AudioInfo.o src\build\editor\windows\Inspector.o src\build\Entitys\Object.o src\build\utils\GameObjectsList.o src\build\utils\Shader.o src\build\utils\UID.o src\build\lapi.o src\build\lauxlib.o src\build\lbaselib.o src\build\lcode.o src\build\lcorolib.o src\build\lctype.o src\build\ldblib.o src\build\ldebug.o src\build\ldo.o src\build\ldump.o src\build\lfunc.o src\build\lgc.o src\build\linit.o src\build\liolib.o src\build\llex.o src\build\lmathlib.o src\build\lmem.o src\build\loadlib.o src\build\lobject.o src\build\lopcodes.o src\build\loslib.o src\build\lparser.o src\build\lstate.o src\build\lstring.o src\build\lstrlib.o src\build\ltable.o src\build\ltablib.o src\build\ltm.o src\build\lua.o src\build\luac.o src\build\lundump.o src\build\lutf8lib.o src\build\lvm.o src\build\lzio.o src\build\imgui.o src\build\imgui_demo.o src\build\imgui_draw.o src\build\imgui_impl_glfw.o src\build\imgui_impl_opengl3.o src\build\imgui_tables.o src\build\imgui_widgets.o src\build\aabb.o src\build\arena_allocator.o src\build\array.o src\build\bitset.o src\build\body.o src\build\broad_phase.o src\build\constraint_graph.o src\build\contact.o src\build\contact_solver.o src\build\core.o src\build\distance.o src\build\distance_joint.o src\build\dynamic_tree.o src\build\geometry.o src\build\hull.o src\build\id_pool.o src\build\island.o src\build\joint.o src\build\manifold.o src\build\math_functions.o src\build\motor_joint.o src\build\mouse_joint.o src\build\mover.o src\build\prismatic_joint.o src\build\revolute_joint.o src\build\sensor.o src\build\shape.o src\build\solver.o src\build\solver_set.o src\build\table.o src\build\timer.o src\build\types.o src\build\weld_joint.o src\build\wheel_joint.o src\build\world.o src\build\xxhash.o src\build\miniaudio.o src\build\ImGuizmo.o -o src\build\app.exe -LC:\msys64\mingw64\lib -lglfw3 -lglew32 -lopengl32 -lgdi32 -lyaml-cpp -lcomdlg32 -lssl -lcrypto -ldbghelp
|
File diff suppressed because it is too large
Load Diff
@ -228,11 +228,6 @@ void ShowProfilerTimeline()
|
|||||||
|
|
||||||
if (!g_engineConfig.settings.profile_enabled)
|
if (!g_engineConfig.settings.profile_enabled)
|
||||||
{
|
{
|
||||||
if (ImGui::Begin("Profiler", nullptr, ImGuiWindowFlags_NoScrollbar))
|
|
||||||
{
|
|
||||||
ImGui::Text("Profiling Disabled.");
|
|
||||||
ImGui::End();
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -254,9 +249,6 @@ void ShowProfilerTimeline()
|
|||||||
|
|
||||||
if (cachedFrame.durationMs <= 0.0)
|
if (cachedFrame.durationMs <= 0.0)
|
||||||
{
|
{
|
||||||
ImGui::Begin("Profiler", nullptr, ImGuiWindowFlags_NoScrollbar);
|
|
||||||
ImGui::Text("Waiting for profiler data...");
|
|
||||||
ImGui::End();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1221,20 +1213,38 @@ void Engine::Run()
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
static std::shared_ptr<Object> previewObj = nullptr;
|
||||||
|
static std::shared_ptr<Object> previousSelection = nullptr;
|
||||||
|
static uint64_t previewUAID = 0;
|
||||||
|
static AssetType previewType = AssetType::Unknown;
|
||||||
|
|
||||||
const ImGuiPayload *payload = ImGui::GetDragDropPayload();
|
const ImGuiPayload *payload = ImGui::GetDragDropPayload();
|
||||||
bool draggingPrefab = payload && payload->IsDataType("ASSET_PREFAB") && payload->DataSize == sizeof(uint64_t);
|
bool dragging = payload && payload->DataSize == sizeof(uint64_t);
|
||||||
|
bool mouseHeld = ImGui::IsMouseDown(ImGuiMouseButton_Left);
|
||||||
bool hoveringViewport = ImGui::IsWindowHovered(ImGuiHoveredFlags_AllowWhenBlockedByActiveItem);
|
|
||||||
bool mouseReleased = ImGui::IsMouseReleased(ImGuiMouseButton_Left);
|
bool mouseReleased = ImGui::IsMouseReleased(ImGuiMouseButton_Left);
|
||||||
|
bool hoveringViewport = ImGui::IsWindowHovered(ImGuiHoveredFlags_AllowWhenBlockedByActiveItem);
|
||||||
|
|
||||||
if (draggingPrefab && hoveringViewport && mouseReleased)
|
if (dragging && hoveringViewport)
|
||||||
{
|
{
|
||||||
uint64_t uaid = *(const uint64_t *)payload->Data;
|
uint64_t uaid = *(const uint64_t *)payload->Data;
|
||||||
|
|
||||||
const auto *asset = AssetManager::GetAssetByID(uaid);
|
const auto *asset = AssetManager::GetAssetByID(uaid);
|
||||||
if (!asset || asset->type != AssetType::Prefab)
|
|
||||||
|
if (!asset)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// --- Create Preview ---
|
||||||
|
if (!previewObj || previewUAID != uaid)
|
||||||
|
{
|
||||||
|
previousSelection = selected; // Store current selection on new drag
|
||||||
|
|
||||||
|
if (payload->IsDataType(ASSET_TEXTURE) && asset->type == AssetType::Image)
|
||||||
|
{
|
||||||
|
previewObj = std::make_shared<Object>(asset->filename);
|
||||||
|
previewObj->AddComponent<SpriteComponent>()->SetTexture(uaid);
|
||||||
|
previewType = AssetType::Image;
|
||||||
|
}
|
||||||
|
else if (payload->IsDataType(ASSET_PREFAB) && asset->type == AssetType::Prefab)
|
||||||
|
{
|
||||||
auto prefabInfo = dynamic_cast<const PrefabAssetInfo *>(asset);
|
auto prefabInfo = dynamic_cast<const PrefabAssetInfo *>(asset);
|
||||||
if (!prefabInfo)
|
if (!prefabInfo)
|
||||||
{
|
{
|
||||||
@ -1242,75 +1252,67 @@ void Engine::Run()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Object> newObj = prefabInfo->Instantiate();
|
previewObj = prefabInfo->Instantiate();
|
||||||
if (!newObj)
|
if (!previewObj)
|
||||||
{
|
{
|
||||||
Logger::LogError("[Editor] Failed to instantiate prefab.");
|
Logger::LogError("[Engine] Failed to instantiate prefab.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ImVec2 mousePos = ImGui::GetMousePos();
|
previewObj->SetName(asset->filename);
|
||||||
ImVec2 screenMin = ImGui::GetWindowPos();
|
previewType = AssetType::Prefab;
|
||||||
ImVec2 localPos = ImVec2(mousePos.x - screenMin.x, mousePos.y - screenMin.y);
|
|
||||||
|
|
||||||
core::types::Vec2 worldPos = ScreenToWorld(core::types::Vec2(localPos), size, cameraPos, cameraZoom);
|
|
||||||
newObj->SetWorldPosition(worldPos);
|
|
||||||
|
|
||||||
objects.push_back(newObj);
|
|
||||||
|
|
||||||
Logger::LogInfo("[Editor] Instantiated prefab at (%.2f, %.2f)", worldPos.x, worldPos.y);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::shared_ptr<Object> previewObj = nullptr;
|
if (previewObj)
|
||||||
static uint64_t previewUAID = 0;
|
|
||||||
|
|
||||||
const ImGuiPayload *payload = ImGui::GetDragDropPayload();
|
|
||||||
bool draggingTexture = payload && payload->IsDataType("ASSET_TEXTURE") && payload->DataSize == sizeof(uint64_t);
|
|
||||||
bool mouseHeld = ImGui::IsMouseDown(ImGuiMouseButton_Left);
|
|
||||||
bool mouseReleased = ImGui::IsMouseReleased(ImGuiMouseButton_Left);
|
|
||||||
bool hoveringViewport = ImGui::IsWindowHovered(ImGuiHoveredFlags_AllowWhenBlockedByActiveItem);
|
|
||||||
|
|
||||||
if (draggingTexture && mouseHeld && hoveringViewport)
|
|
||||||
{
|
{
|
||||||
uint64_t uaid = *(const uint64_t *)payload->Data;
|
|
||||||
const auto *asset = AssetManager::GetAssetByID(uaid);
|
|
||||||
if (asset && asset->type == AssetType::Image)
|
|
||||||
{
|
|
||||||
if (!previewObj)
|
|
||||||
{
|
|
||||||
previewObj = std::make_shared<Object>(asset->filename);
|
|
||||||
previewObj->AddComponent<SpriteComponent>()->SetTexture(uaid);
|
|
||||||
objects.push_back(previewObj);
|
objects.push_back(previewObj);
|
||||||
previewUAID = uaid;
|
previewUAID = uaid;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (previewObj)
|
||||||
|
{
|
||||||
glm::vec2 worldPos = ScreenToWorld(screenMousePos, viewportSize, cameraPos, cameraZoom);
|
glm::vec2 worldPos = ScreenToWorld(screenMousePos, viewportSize, cameraPos, cameraZoom);
|
||||||
previewObj->SetLocalPosition(worldPos);
|
previewObj->SetLocalPosition(worldPos);
|
||||||
selected = previewObj;
|
selected = previewObj;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else if (previewObj && mouseReleased && hoveringViewport)
|
if (mouseReleased)
|
||||||
{
|
{
|
||||||
|
auto finalized = previewObj;
|
||||||
|
|
||||||
previewObj = nullptr;
|
previewObj = nullptr;
|
||||||
previewUAID = 0;
|
previewUAID = 0;
|
||||||
|
previewType = AssetType::Unknown;
|
||||||
|
|
||||||
|
selected = finalized;
|
||||||
|
previousSelection = nullptr;
|
||||||
}
|
}
|
||||||
else if (previewObj && (!hoveringViewport || !draggingTexture))
|
}
|
||||||
|
else if (previewObj && (!hoveringViewport || !dragging))
|
||||||
{
|
{
|
||||||
auto it = std::find(objects.begin(), objects.end(), previewObj);
|
auto it = std::find(objects.begin(), objects.end(), previewObj);
|
||||||
if (it != objects.end())
|
if (it != objects.end())
|
||||||
objects.erase(it);
|
objects.erase(it);
|
||||||
|
|
||||||
previewObj = nullptr;
|
previewObj = nullptr;
|
||||||
selected = previewObj;
|
|
||||||
|
|
||||||
previewUAID = 0;
|
previewUAID = 0;
|
||||||
|
previewType = AssetType::Unknown;
|
||||||
|
|
||||||
|
if (previousSelection)
|
||||||
|
{
|
||||||
|
selected = previousSelection;
|
||||||
|
previousSelection = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
glm::mat4 projection = glm::ortho(
|
glm::mat4 projection = glm::ortho(
|
||||||
0.0f, static_cast<float>(size.x), // left, right
|
0.0f, static_cast<float>(size.x),
|
||||||
static_cast<float>(size.y), 0.0f, // bottom, top (y-down)
|
static_cast<float>(size.y), 0.0f,
|
||||||
-1.0f, 1.0f // near, far
|
-1.0f, 1.0f
|
||||||
);
|
);
|
||||||
|
|
||||||
glm::mat4 view = glm::translate(glm::mat4(1.0f), glm::vec3(-cameraPos, 0.0f));
|
glm::mat4 view = glm::translate(glm::mat4(1.0f), glm::vec3(-cameraPos, 0.0f));
|
||||||
@ -1326,28 +1328,21 @@ void Engine::Run()
|
|||||||
{
|
{
|
||||||
PROFILE_ENGINE_SCOPE("Finish Rendering");
|
PROFILE_ENGINE_SCOPE("Finish Rendering");
|
||||||
|
|
||||||
profiler.BeginEngineSection("ImGui::Render");
|
|
||||||
ImGui::Render();
|
ImGui::Render();
|
||||||
profiler.EndEngineSection();
|
profiler.EndEngineSection();
|
||||||
|
|
||||||
int w, h;
|
int w, h;
|
||||||
profiler.BeginEngineSection("glfwGetFramebufferSize");
|
|
||||||
glfwGetFramebufferSize(window, &w, &h);
|
glfwGetFramebufferSize(window, &w, &h);
|
||||||
profiler.EndEngineSection();
|
|
||||||
|
|
||||||
glViewport(0, 0, w, h);
|
glViewport(0, 0, w, h);
|
||||||
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
profiler.BeginEngineSection("ImGui_ImplOpenGL3_RenderDrawData");
|
|
||||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||||
profiler.EndEngineSection();
|
|
||||||
|
|
||||||
profiler.BeginEngineSection("glfwSwapBuffers");
|
|
||||||
|
|
||||||
glfwSwapBuffers(window);
|
glfwSwapBuffers(window);
|
||||||
|
|
||||||
profiler.EndEngineSection();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto &obj : pendingDeletion)
|
for (auto &obj : pendingDeletion)
|
||||||
@ -1788,16 +1783,23 @@ void Engine::LoadState()
|
|||||||
|
|
||||||
void Engine::Shutdown()
|
void Engine::Shutdown()
|
||||||
{
|
{
|
||||||
|
std::filesystem::remove(tempScenePath);
|
||||||
|
|
||||||
g_engineConfig.SaveToFile();
|
g_engineConfig.SaveToFile();
|
||||||
|
|
||||||
|
|
||||||
|
AudioEngine::Shutdown();
|
||||||
|
|
||||||
|
|
||||||
|
AssetManager::ClearAllAssets();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ImGui_ImplOpenGL3_Shutdown();
|
ImGui_ImplOpenGL3_Shutdown();
|
||||||
ImGui_ImplGlfw_Shutdown();
|
ImGui_ImplGlfw_Shutdown();
|
||||||
ImGui::DestroyContext();
|
ImGui::DestroyContext();
|
||||||
glfwDestroyWindow(window);
|
glfwDestroyWindow(window);
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
|
|
||||||
AudioEngine::Shutdown();
|
|
||||||
AssetManager::ClearAllAssets();
|
|
||||||
|
|
||||||
std::filesystem::remove(tempScenePath);
|
|
||||||
}
|
}
|
||||||
|
@ -88,31 +88,34 @@ private:
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
std::shared_ptr<T> Object::GetComponent() const
|
std::shared_ptr<T> Object::GetComponent() const
|
||||||
{
|
{
|
||||||
for (const auto &comp : components)
|
for (const auto& comp : components)
|
||||||
|
{
|
||||||
if (auto casted = std::dynamic_pointer_cast<T>(comp))
|
if (auto casted = std::dynamic_pointer_cast<T>(comp))
|
||||||
return casted;
|
return casted;
|
||||||
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
std::shared_ptr<T> Object::AddComponent()
|
std::shared_ptr<T> Object::AddComponent()
|
||||||
{
|
{
|
||||||
auto existing = GetComponent<T>();
|
if (auto existing = GetComponent<T>())
|
||||||
if (existing)
|
|
||||||
return existing;
|
return existing;
|
||||||
|
|
||||||
auto component = std::make_shared<T>(this);
|
auto component = std::make_shared<T>(this);
|
||||||
components.push_back(component);
|
components.emplace_back(component);
|
||||||
return component;
|
return component;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void Object::RemoveComponent()
|
void Object::RemoveComponent()
|
||||||
{
|
{
|
||||||
components.erase(std::remove_if(components.begin(), components.end(),
|
components.erase(
|
||||||
[](const std::shared_ptr<Component> &comp)
|
std::remove_if(components.begin(), components.end(),
|
||||||
|
[](const std::shared_ptr<Component>& comp)
|
||||||
{
|
{
|
||||||
return std::dynamic_pointer_cast<T>(comp) != nullptr;
|
return std::dynamic_pointer_cast<T>(comp) != nullptr;
|
||||||
}),
|
}),
|
||||||
components.end());
|
components.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,26 +1,24 @@
|
|||||||
#include "AudioEngine.h"
|
#include "AudioEngine.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
// TODO: Lua API
|
||||||
//TODO: Lua API
|
|
||||||
|
|
||||||
|
|
||||||
// Static member definitions
|
// Static member definitions
|
||||||
ma_engine AudioEngine::s_Engine;
|
ma_engine AudioEngine::s_Engine;
|
||||||
std::unordered_map<uint64_t, ma_sound*> AudioEngine::s_SoundMap;
|
std::unordered_map<uint64_t, ma_sound *> AudioEngine::s_SoundMap;
|
||||||
std::unordered_map<uint64_t, PlayingInfo> AudioEngine::s_PlayingInfoMap;
|
std::unordered_map<uint64_t, PlayingInfo> AudioEngine::s_PlayingInfoMap;
|
||||||
|
|
||||||
|
|
||||||
std::vector<float> AudioEngine::s_MasterVU;
|
std::vector<float> AudioEngine::s_MasterVU;
|
||||||
|
|
||||||
|
bool AudioEngine::Init()
|
||||||
bool AudioEngine::Init() {
|
{
|
||||||
ma_engine_config config = ma_engine_config_init();
|
ma_engine_config config = ma_engine_config_init();
|
||||||
config.onProcess = AudioEngine::EngineProcessCallback;
|
config.onProcess = AudioEngine::EngineProcessCallback;
|
||||||
config.pProcessUserData = nullptr;
|
config.pProcessUserData = nullptr;
|
||||||
|
|
||||||
ma_result r = ma_engine_init(&config, &s_Engine);
|
ma_result r = ma_engine_init(&config, &s_Engine);
|
||||||
if (r != MA_SUCCESS) {
|
if (r != MA_SUCCESS)
|
||||||
|
{
|
||||||
Logger::LogError("AudioEngine: ma_engine_init failed (%d)", r);
|
Logger::LogError("AudioEngine: ma_engine_init failed (%d)", r);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -30,13 +28,27 @@ bool AudioEngine::Init() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AudioEngine::Shutdown()
|
||||||
|
{
|
||||||
|
Logger::LogVerbose("[AudioEngine] Shutdown started");
|
||||||
|
|
||||||
void AudioEngine::Shutdown() {
|
for (auto &[id, soundPtr] : s_SoundMap)
|
||||||
|
{
|
||||||
|
if (soundPtr)
|
||||||
|
{
|
||||||
|
ma_result stopResult = ma_sound_stop(soundPtr);
|
||||||
|
if (stopResult != MA_SUCCESS)
|
||||||
|
Logger::LogWarning("[AudioEngine] Failed to stop sound %llu", id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (auto& [id, soundPtr] : s_SoundMap) {
|
for (auto &[id, soundPtr] : s_SoundMap)
|
||||||
if (soundPtr) {
|
{
|
||||||
ma_sound_stop(soundPtr);
|
if (soundPtr)
|
||||||
|
{
|
||||||
ma_sound_uninit(soundPtr);
|
ma_sound_uninit(soundPtr);
|
||||||
|
|
||||||
|
|
||||||
delete soundPtr;
|
delete soundPtr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -44,30 +56,30 @@ void AudioEngine::Shutdown() {
|
|||||||
s_SoundMap.clear();
|
s_SoundMap.clear();
|
||||||
s_PlayingInfoMap.clear();
|
s_PlayingInfoMap.clear();
|
||||||
|
|
||||||
|
Logger::LogVerbose("[AudioEngine] Engine uninit...");
|
||||||
ma_engine_uninit(&s_Engine);
|
ma_engine_uninit(&s_Engine);
|
||||||
|
Logger::LogOk("[AudioEngine] Shutdown complete");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AudioEngine::Play(uint64_t uaid, bool loop)
|
||||||
void AudioEngine::Play(uint64_t uaid, bool loop) {
|
{
|
||||||
Cleanup(uaid);
|
Cleanup(uaid);
|
||||||
|
|
||||||
const AssetInfo* asset = AssetManager::GetAssetByID(uaid);
|
const AssetInfo *asset = AssetManager::GetAssetByID(uaid);
|
||||||
if (!asset || !asset->loaded || asset->type != AssetType::Audio) {
|
if (!asset || !asset->loaded || asset->type != AssetType::Audio)
|
||||||
|
{
|
||||||
Logger::LogError("AudioEngine::Play invalid asset %llu", uaid);
|
Logger::LogError("AudioEngine::Play invalid asset %llu", uaid);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ma_sound* sound = new ma_sound;
|
ma_sound *sound = new ma_sound;
|
||||||
if (ma_sound_init_from_file(
|
if (ma_sound_init_from_file(
|
||||||
&s_Engine,
|
&s_Engine,
|
||||||
asset->path.c_str(),
|
asset->path.c_str(),
|
||||||
/*flags=*/0,
|
/*flags=*/0,
|
||||||
/*pGroup=*/nullptr,
|
/*pGroup=*/nullptr,
|
||||||
/*pFence=*/nullptr,
|
/*pFence=*/nullptr,
|
||||||
sound
|
sound) != MA_SUCCESS)
|
||||||
) != MA_SUCCESS)
|
|
||||||
{
|
{
|
||||||
Logger::LogError("AudioEngine::Play failed to load '%s'", asset->path.c_str());
|
Logger::LogError("AudioEngine::Play failed to load '%s'", asset->path.c_str());
|
||||||
delete sound;
|
delete sound;
|
||||||
@ -85,7 +97,7 @@ void AudioEngine::Play(uint64_t uaid, bool loop) {
|
|||||||
PlayingInfo info;
|
PlayingInfo info;
|
||||||
info.uaid = uaid;
|
info.uaid = uaid;
|
||||||
info.name = asset->filename;
|
info.name = asset->filename;
|
||||||
info.currentTime= 0.0;
|
info.currentTime = 0.0;
|
||||||
info.totalTime = double(frames) / sampleRate;
|
info.totalTime = double(frames) / sampleRate;
|
||||||
info.looping = loop;
|
info.looping = loop;
|
||||||
info.hasStarted = false;
|
info.hasStarted = false;
|
||||||
@ -94,29 +106,32 @@ void AudioEngine::Play(uint64_t uaid, bool loop) {
|
|||||||
s_PlayingInfoMap[uaid] = info;
|
s_PlayingInfoMap[uaid] = info;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioEngine::Stop(uint64_t uaid) {
|
void AudioEngine::Stop(uint64_t uaid)
|
||||||
if (auto it = s_SoundMap.find(uaid); it != s_SoundMap.end()) {
|
{
|
||||||
|
if (auto it = s_SoundMap.find(uaid); it != s_SoundMap.end())
|
||||||
|
{
|
||||||
ma_sound_stop(it->second);
|
ma_sound_stop(it->second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioEngine::StopAll() {
|
void AudioEngine::StopAll()
|
||||||
for (auto& kv : s_SoundMap) {
|
{
|
||||||
|
for (auto &kv : s_SoundMap)
|
||||||
|
{
|
||||||
ma_sound_stop(kv.second);
|
ma_sound_stop(kv.second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioEngine::Unload(uint64_t uaid) {
|
void AudioEngine::Unload(uint64_t uaid)
|
||||||
|
{
|
||||||
Cleanup(uaid);
|
Cleanup(uaid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void AudioEngine::CleanupSound(uint64_t uaid)
|
void AudioEngine::CleanupSound(uint64_t uaid)
|
||||||
{
|
{
|
||||||
auto itSound = s_SoundMap.find(uaid);
|
auto itSound = s_SoundMap.find(uaid);
|
||||||
if (itSound != s_SoundMap.end()) {
|
if (itSound != s_SoundMap.end())
|
||||||
|
{
|
||||||
ma_sound_uninit(itSound->second);
|
ma_sound_uninit(itSound->second);
|
||||||
delete itSound->second;
|
delete itSound->second;
|
||||||
s_SoundMap.erase(itSound);
|
s_SoundMap.erase(itSound);
|
||||||
@ -125,33 +140,36 @@ void AudioEngine::CleanupSound(uint64_t uaid)
|
|||||||
{
|
{
|
||||||
Logger::LogError("[AudioEngine] Invalid Asset ID");
|
Logger::LogError("[AudioEngine] Invalid Asset ID");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AudioEngine::Update()
|
void AudioEngine::Update()
|
||||||
{
|
{
|
||||||
for (auto it = s_PlayingInfoMap.begin(); it != s_PlayingInfoMap.end(); )
|
for (auto it = s_PlayingInfoMap.begin(); it != s_PlayingInfoMap.end();)
|
||||||
{
|
{
|
||||||
uint64_t uaid = it->first;
|
uint64_t uaid = it->first;
|
||||||
PlayingInfo &info = it->second;
|
PlayingInfo &info = it->second;
|
||||||
ma_sound* s = info.sound;
|
ma_sound *s = info.sound;
|
||||||
|
|
||||||
bool shouldErase = (!s) ||
|
bool shouldErase = (!s) ||
|
||||||
(!info.looping && info.hasStarted && !ma_sound_is_playing(s));
|
(!info.looping && info.hasStarted && !ma_sound_is_playing(s));
|
||||||
|
|
||||||
if (shouldErase) {
|
if (shouldErase)
|
||||||
|
{
|
||||||
CleanupSound(uaid);
|
CleanupSound(uaid);
|
||||||
|
|
||||||
it = s_PlayingInfoMap.erase(it);
|
it = s_PlayingInfoMap.erase(it);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
if (!info.hasStarted && ma_sound_is_playing(s)) {
|
if (!info.hasStarted && ma_sound_is_playing(s))
|
||||||
|
{
|
||||||
info.hasStarted = true;
|
info.hasStarted = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ma_uint64 cursor = 0;
|
ma_uint64 cursor = 0;
|
||||||
if (ma_sound_get_cursor_in_pcm_frames(s, &cursor) == MA_SUCCESS) {
|
if (ma_sound_get_cursor_in_pcm_frames(s, &cursor) == MA_SUCCESS)
|
||||||
|
{
|
||||||
info.currentTime = double(cursor) / ma_engine_get_sample_rate(&s_Engine);
|
info.currentTime = double(cursor) / ma_engine_get_sample_rate(&s_Engine);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,65 +178,69 @@ void AudioEngine::Update()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AudioEngine::SetVolume(uint64_t uaid, float v)
|
||||||
void AudioEngine::SetVolume(uint64_t uaid, float v) {
|
{
|
||||||
if (auto it = s_SoundMap.find(uaid); it != s_SoundMap.end()) {
|
if (auto it = s_SoundMap.find(uaid); it != s_SoundMap.end())
|
||||||
|
{
|
||||||
ma_sound_set_volume(it->second, v);
|
ma_sound_set_volume(it->second, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioEngine::SetLooping(uint64_t uaid, bool loop) {
|
void AudioEngine::SetLooping(uint64_t uaid, bool loop)
|
||||||
if (auto it = s_SoundMap.find(uaid); it != s_SoundMap.end()) {
|
{
|
||||||
|
if (auto it = s_SoundMap.find(uaid); it != s_SoundMap.end())
|
||||||
|
{
|
||||||
ma_sound_set_looping(it->second, loop ? MA_TRUE : MA_FALSE);
|
ma_sound_set_looping(it->second, loop ? MA_TRUE : MA_FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioEngine::Cleanup(uint64_t uaid) {
|
void AudioEngine::Cleanup(uint64_t uaid)
|
||||||
if (auto it = s_SoundMap.find(uaid); it != s_SoundMap.end()) {
|
{
|
||||||
|
if (auto it = s_SoundMap.find(uaid); it != s_SoundMap.end())
|
||||||
|
{
|
||||||
ma_sound_uninit(it->second);
|
ma_sound_uninit(it->second);
|
||||||
delete it->second;
|
delete it->second;
|
||||||
s_SoundMap.erase(it);
|
s_SoundMap.erase(it);
|
||||||
}
|
}
|
||||||
else{
|
else
|
||||||
|
{
|
||||||
Logger::LogError("[AudioEngine] Invalid Asset ID");
|
Logger::LogError("[AudioEngine] Invalid Asset ID");
|
||||||
|
|
||||||
}
|
}
|
||||||
s_PlayingInfoMap.erase(uaid);
|
s_PlayingInfoMap.erase(uaid);
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::unordered_map<uint64_t, PlayingInfo>& AudioEngine::GetPlayingInfoMap() {
|
const std::unordered_map<uint64_t, PlayingInfo> &AudioEngine::GetPlayingInfoMap()
|
||||||
|
{
|
||||||
return s_PlayingInfoMap;
|
return s_PlayingInfoMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AudioEngine::EngineProcessCallback(
|
void AudioEngine::EngineProcessCallback(
|
||||||
void* /*pUserData*/,
|
void * /*pUserData*/,
|
||||||
float* pFramesOut,
|
float *pFramesOut,
|
||||||
ma_uint64 frameCount)
|
ma_uint64 frameCount)
|
||||||
{
|
{
|
||||||
// Fetch the playback device and its channel count
|
// Fetch the playback device and its channel count
|
||||||
ma_device* pDevice = ma_engine_get_device(&s_Engine);
|
ma_device *pDevice = ma_engine_get_device(&s_Engine);
|
||||||
uint32_t channels = pDevice->playback.channels;
|
uint32_t channels = pDevice->playback.channels;
|
||||||
|
|
||||||
// Ensure our master VU vector matches the channel count
|
// Ensure our master VU vector matches the channel count
|
||||||
s_MasterVU.assign(channels, 0.0f);
|
s_MasterVU.assign(channels, 0.0f);
|
||||||
|
|
||||||
// Compute peak per channel
|
// Compute peak per channel
|
||||||
for (ma_uint64 i = 0; i < frameCount; ++i) {
|
for (ma_uint64 i = 0; i < frameCount; ++i)
|
||||||
for (uint32_t ch = 0; ch < channels; ++ch) {
|
{
|
||||||
|
for (uint32_t ch = 0; ch < channels; ++ch)
|
||||||
|
{
|
||||||
float v = fabsf(pFramesOut[i * channels + ch]);
|
float v = fabsf(pFramesOut[i * channels + ch]);
|
||||||
if (v > s_MasterVU[ch]) {
|
if (v > s_MasterVU[ch])
|
||||||
|
{
|
||||||
s_MasterVU[ch] = v;
|
s_MasterVU[ch] = v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::vector<float> &AudioEngine::GetMasterVU()
|
||||||
const std::vector<float>& AudioEngine::GetMasterVU()
|
|
||||||
{
|
{
|
||||||
return s_MasterVU;
|
return s_MasterVU;
|
||||||
}
|
}
|
||||||
|
@ -447,6 +447,8 @@ void AssetManager::Load(const YAML::Node &node)
|
|||||||
asset = std::make_shared<ImageAssetInfo>();
|
asset = std::make_shared<ImageAssetInfo>();
|
||||||
else if (type == AssetType::Audio)
|
else if (type == AssetType::Audio)
|
||||||
asset = std::make_shared<AudioAssetInfo>();
|
asset = std::make_shared<AudioAssetInfo>();
|
||||||
|
else if (type == AssetType::Prefab)
|
||||||
|
asset = std::make_shared<PrefabAssetInfo>();
|
||||||
else
|
else
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -473,6 +475,10 @@ void AssetManager::Load(const YAML::Node &node)
|
|||||||
LoadImageInternal(path, uaid);
|
LoadImageInternal(path, uaid);
|
||||||
else if (type == AssetType::Audio)
|
else if (type == AssetType::Audio)
|
||||||
LoadAudioInternal(path, uaid);
|
LoadAudioInternal(path, uaid);
|
||||||
|
else if (type == AssetType::Prefab)
|
||||||
|
LoadPrefabInternal(path, uaid);
|
||||||
|
else
|
||||||
|
Logger::LogError("[Engine Error] Unhandled Internal Asset Loading. %s", AssetTypeToString(type));
|
||||||
|
|
||||||
++index;
|
++index;
|
||||||
}
|
}
|
||||||
@ -500,14 +506,12 @@ void ImageAssetInfo::Load(const YAML::Node &node)
|
|||||||
void AudioAssetInfo::Save(YAML::Emitter &out) const {}
|
void AudioAssetInfo::Save(YAML::Emitter &out) const {}
|
||||||
void AudioAssetInfo::Load(const YAML::Node &node) {}
|
void AudioAssetInfo::Load(const YAML::Node &node) {}
|
||||||
|
|
||||||
|
|
||||||
PrefabAssetInfo::PrefabAssetInfo()
|
PrefabAssetInfo::PrefabAssetInfo()
|
||||||
{
|
{
|
||||||
type = AssetType::Prefab;
|
type = AssetType::Prefab;
|
||||||
|
prefabName = "New Prefab";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void PrefabAssetInfo::Save(YAML::Emitter &out) const
|
void PrefabAssetInfo::Save(YAML::Emitter &out) const
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -536,7 +540,6 @@ void PrefabAssetInfo::Save(YAML::Emitter &out) const
|
|||||||
{
|
{
|
||||||
out << prefabYAML;
|
out << prefabYAML;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrefabAssetInfo::Load(const YAML::Node &node)
|
void PrefabAssetInfo::Load(const YAML::Node &node)
|
||||||
@ -555,6 +558,8 @@ void PrefabAssetInfo::Load(const YAML::Node &node)
|
|||||||
ReloadFromYAML();
|
ReloadFromYAML();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void PrefabAssetInfo::ReloadFromYAML()
|
void PrefabAssetInfo::ReloadFromYAML()
|
||||||
{
|
{
|
||||||
if (!prefabYAML || !prefabYAML.IsMap())
|
if (!prefabYAML || !prefabYAML.IsMap())
|
||||||
@ -566,10 +571,8 @@ void PrefabAssetInfo::ReloadFromYAML()
|
|||||||
|
|
||||||
prefabRoot = std::make_shared<Object>(prefabName);
|
prefabRoot = std::make_shared<Object>(prefabName);
|
||||||
prefabRoot->Load(prefabYAML);
|
prefabRoot->Load(prefabYAML);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::shared_ptr<Object> PrefabAssetInfo::Instantiate() const
|
std::shared_ptr<Object> PrefabAssetInfo::Instantiate() const
|
||||||
{
|
{
|
||||||
if (!prefabYAML || !prefabYAML.IsMap())
|
if (!prefabYAML || !prefabYAML.IsMap())
|
||||||
@ -582,4 +585,3 @@ std::shared_ptr<Object> PrefabAssetInfo::Instantiate() const
|
|||||||
newObj->Load(prefabYAML);
|
newObj->Load(prefabYAML);
|
||||||
return newObj;
|
return newObj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,6 +11,9 @@
|
|||||||
|
|
||||||
class Object;
|
class Object;
|
||||||
|
|
||||||
|
#define ASSET_TEXTURE "ASSET_TEXTURE"
|
||||||
|
#define ASSET_AUDIO "ASSET_AUDIO"
|
||||||
|
#define ASSET_PREFAB "ASSET_PREFAB"
|
||||||
|
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
@ -107,7 +107,7 @@ inline std::string GetFilenameNoExtension(const std::string& path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::string TruncateWithEllipsis(const std::string& str, size_t maxLength)
|
inline std::string TruncateWithEllipsis(const std::string& str, size_t maxLength)
|
||||||
{
|
{
|
||||||
if (maxLength <= 3)
|
if (maxLength <= 3)
|
||||||
return std::string(maxLength, '.'); // handle very small limits
|
return std::string(maxLength, '.'); // handle very small limits
|
||||||
|
@ -12,6 +12,7 @@ static bool sortAscending = true;
|
|||||||
static int sortMode = 0; // 0 = Name, 1 = Type, 2 = UAID
|
static int sortMode = 0; // 0 = Name, 1 = Type, 2 = UAID
|
||||||
static bool showImages = true;
|
static bool showImages = true;
|
||||||
static bool showAudio = true;
|
static bool showAudio = true;
|
||||||
|
static bool showPrefabs = true;
|
||||||
|
|
||||||
static std::vector<std::pair<std::string, AssetType>> pendingImports;
|
static std::vector<std::pair<std::string, AssetType>> pendingImports;
|
||||||
static bool showImportPopup = false;
|
static bool showImportPopup = false;
|
||||||
@ -76,6 +77,8 @@ void ShowAssetBrowser()
|
|||||||
ImGui::Text("Type Filters:");
|
ImGui::Text("Type Filters:");
|
||||||
ImGui::Checkbox("Images", &showImages);
|
ImGui::Checkbox("Images", &showImages);
|
||||||
ImGui::Checkbox("Audio", &showAudio);
|
ImGui::Checkbox("Audio", &showAudio);
|
||||||
|
ImGui::Checkbox("Prefabs", &showPrefabs);
|
||||||
|
|
||||||
|
|
||||||
ImGui::EndPopup();
|
ImGui::EndPopup();
|
||||||
}
|
}
|
||||||
@ -109,6 +112,7 @@ void ShowAssetBrowser()
|
|||||||
asset->path.find(assetSearchQuery) == std::string::npos)
|
asset->path.find(assetSearchQuery) == std::string::npos)
|
||||||
continue;
|
continue;
|
||||||
if ((asset->type == AssetType::Image && !showImages) ||
|
if ((asset->type == AssetType::Image && !showImages) ||
|
||||||
|
(asset->type == AssetType::Prefab && !showPrefabs) ||
|
||||||
(asset->type == AssetType::Audio && !showAudio))
|
(asset->type == AssetType::Audio && !showAudio))
|
||||||
continue;
|
continue;
|
||||||
sortedAssets.push_back(asset.get());
|
sortedAssets.push_back(asset.get());
|
||||||
@ -127,9 +131,9 @@ void ShowAssetBrowser()
|
|||||||
for (const AssetInfo *asset : sortedAssets)
|
for (const AssetInfo *asset : sortedAssets)
|
||||||
{
|
{
|
||||||
ImGui::PushID(idx++);
|
ImGui::PushID(idx++);
|
||||||
std::string displayName = GetFilenameFromPath(asset->path);
|
std::string rawDisplayName = GetFilenameFromPath(asset->path);
|
||||||
|
|
||||||
displayName = TruncateWithEllipsis(GetFilenameNoExtension(displayName), 10);
|
std::string displayName = TruncateWithEllipsis(GetFilenameNoExtension(rawDisplayName), 10);
|
||||||
|
|
||||||
if (asset->type == AssetType::Image)
|
if (asset->type == AssetType::Image)
|
||||||
{
|
{
|
||||||
@ -143,8 +147,8 @@ void ShowAssetBrowser()
|
|||||||
ImGui::Image((ImTextureID)(intptr_t)image->textureID, ImVec2(thumbnailSize, thumbnailSize));
|
ImGui::Image((ImTextureID)(intptr_t)image->textureID, ImVec2(thumbnailSize, thumbnailSize));
|
||||||
if (ImGui::BeginDragDropSource(ImGuiDragDropFlags_SourceAllowNullID))
|
if (ImGui::BeginDragDropSource(ImGuiDragDropFlags_SourceAllowNullID))
|
||||||
{
|
{
|
||||||
ImGui::SetDragDropPayload("ASSET_TEXTURE", &asset->uaid, sizeof(uint64_t));
|
ImGui::SetDragDropPayload(ASSET_TEXTURE, &asset->uaid, sizeof(uint64_t));
|
||||||
ImGui::Text("%s", displayName.c_str());
|
ImGui::Text("%s", rawDisplayName.c_str());
|
||||||
ImGui::EndDragDropSource();
|
ImGui::EndDragDropSource();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -153,8 +157,8 @@ void ShowAssetBrowser()
|
|||||||
ImGui::Button(asset->filetype.empty() ? "Audio" : asset->filetype.c_str(), ImVec2(thumbnailSize, thumbnailSize));
|
ImGui::Button(asset->filetype.empty() ? "Audio" : asset->filetype.c_str(), ImVec2(thumbnailSize, thumbnailSize));
|
||||||
if (ImGui::BeginDragDropSource(ImGuiDragDropFlags_SourceAllowNullID))
|
if (ImGui::BeginDragDropSource(ImGuiDragDropFlags_SourceAllowNullID))
|
||||||
{
|
{
|
||||||
ImGui::SetDragDropPayload("ASSET_AUDIO", &asset->uaid, sizeof(uint64_t));
|
ImGui::SetDragDropPayload(ASSET_AUDIO, &asset->uaid, sizeof(uint64_t));
|
||||||
ImGui::Text("%s", displayName.c_str());
|
ImGui::Text("%s", rawDisplayName.c_str());
|
||||||
ImGui::EndDragDropSource();
|
ImGui::EndDragDropSource();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -165,8 +169,8 @@ void ShowAssetBrowser()
|
|||||||
ImGui::Button("Prefab", ImVec2(thumbnailSize, thumbnailSize));
|
ImGui::Button("Prefab", ImVec2(thumbnailSize, thumbnailSize));
|
||||||
if (ImGui::BeginDragDropSource(ImGuiDragDropFlags_SourceAllowNullID))
|
if (ImGui::BeginDragDropSource(ImGuiDragDropFlags_SourceAllowNullID))
|
||||||
{
|
{
|
||||||
ImGui::SetDragDropPayload("ASSET_PREFAB", &prefab->uaid, sizeof(uint64_t));
|
ImGui::SetDragDropPayload(ASSET_PREFAB, &prefab->uaid, sizeof(uint64_t));
|
||||||
ImGui::Text("%s", displayName.c_str());
|
ImGui::Text("%s", rawDisplayName.c_str());
|
||||||
ImGui::EndDragDropSource();
|
ImGui::EndDragDropSource();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -142,7 +142,7 @@ void DrawInspectorUI(std::shared_ptr<Object> selected)
|
|||||||
|
|
||||||
if (ImGui::BeginDragDropTarget())
|
if (ImGui::BeginDragDropTarget())
|
||||||
{
|
{
|
||||||
if (const ImGuiPayload *payload = ImGui::AcceptDragDropPayload("ASSET_TEXTURE"))
|
if (const ImGuiPayload *payload = ImGui::AcceptDragDropPayload(ASSET_TEXTURE))
|
||||||
{
|
{
|
||||||
if (payload->DataSize == sizeof(uint64_t))
|
if (payload->DataSize == sizeof(uint64_t))
|
||||||
{
|
{
|
||||||
@ -169,7 +169,7 @@ void DrawInspectorUI(std::shared_ptr<Object> selected)
|
|||||||
|
|
||||||
if (ImGui::BeginDragDropTarget())
|
if (ImGui::BeginDragDropTarget())
|
||||||
{
|
{
|
||||||
if (const ImGuiPayload *payload = ImGui::AcceptDragDropPayload("ASSET_TEXTURE"))
|
if (const ImGuiPayload *payload = ImGui::AcceptDragDropPayload(ASSET_TEXTURE))
|
||||||
{
|
{
|
||||||
if (payload->DataSize == sizeof(uint64_t))
|
if (payload->DataSize == sizeof(uint64_t))
|
||||||
{
|
{
|
||||||
@ -301,7 +301,7 @@ void DrawInspectorUI(std::shared_ptr<Object> selected)
|
|||||||
|
|
||||||
if (ImGui::BeginDragDropTarget())
|
if (ImGui::BeginDragDropTarget())
|
||||||
{
|
{
|
||||||
if (const ImGuiPayload *payload = ImGui::AcceptDragDropPayload("ASSET_TEXTURE"))
|
if (const ImGuiPayload *payload = ImGui::AcceptDragDropPayload(ASSET_TEXTURE))
|
||||||
{
|
{
|
||||||
uint64_t droppedUAID = *(const uint64_t *)payload->Data;
|
uint64_t droppedUAID = *(const uint64_t *)payload->Data;
|
||||||
anim->SetTextureAtlas(droppedUAID, frameWidth, frameHeight, frameDuration, startFrame, endFrame);
|
anim->SetTextureAtlas(droppedUAID, frameWidth, frameHeight, frameDuration, startFrame, endFrame);
|
||||||
@ -474,7 +474,7 @@ void DrawInspectorUI(std::shared_ptr<Object> selected)
|
|||||||
// Drag and drop texture
|
// Drag and drop texture
|
||||||
if (ImGui::BeginDragDropTarget())
|
if (ImGui::BeginDragDropTarget())
|
||||||
{
|
{
|
||||||
if (const ImGuiPayload *payload = ImGui::AcceptDragDropPayload("ASSET_TEXTURE"))
|
if (const ImGuiPayload *payload = ImGui::AcceptDragDropPayload(ASSET_TEXTURE))
|
||||||
{
|
{
|
||||||
if (payload->DataSize == sizeof(uint64_t))
|
if (payload->DataSize == sizeof(uint64_t))
|
||||||
{
|
{
|
||||||
@ -722,7 +722,7 @@ void DrawInspectorUI(std::shared_ptr<Object> selected)
|
|||||||
// Drag & Drop from Asset Browser
|
// Drag & Drop from Asset Browser
|
||||||
if (ImGui::BeginDragDropTarget())
|
if (ImGui::BeginDragDropTarget())
|
||||||
{
|
{
|
||||||
if (const ImGuiPayload *payload = ImGui::AcceptDragDropPayload("ASSET_AUDIO"))
|
if (const ImGuiPayload *payload = ImGui::AcceptDragDropPayload(ASSET_AUDIO))
|
||||||
{
|
{
|
||||||
if (payload->DataSize == sizeof(uint64_t))
|
if (payload->DataSize == sizeof(uint64_t))
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user