Skip to content

Commit

Permalink
Refactor editor style freecam PR
Browse files Browse the repository at this point in the history
  • Loading branch information
OrfeasZ committed Dec 30, 2023
1 parent 40735de commit ff36dae
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 26 deletions.
28 changes: 10 additions & 18 deletions Mods/Editor/Src/Components/EntityTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,35 +379,27 @@ void Editor::DrawEntityTree() {
}
}

void Editor::OnSelectEntity(ZEntityRef p_Entity, std::optional<std::string> p_ClientId)
{
void Editor::OnSelectEntity(ZEntityRef p_Entity, std::optional<std::string> p_ClientId) {
const bool s_DifferentEntity = m_SelectedEntity != p_Entity;

m_SelectedEntity = p_Entity;
m_ShouldScrollToEntity = p_Entity.GetEntity() != nullptr;

if (s_DifferentEntity)
{
if (s_DifferentEntity) {
m_Server.OnEntitySelected(p_Entity, std::move(p_ClientId));
}

if (!m_SelectionForEntityCreated)
{
s_SelectionForFreeCameraEditorStyleEntity2 = std::unique_ptr<unsigned char[]>(new unsigned char[sizeof(ZSelectionForFreeCameraEditorStyleEntity)]);
s_SelectionForFreeCameraEditorStyleEntity = reinterpret_cast<ZSelectionForFreeCameraEditorStyleEntity*>(s_SelectionForFreeCameraEditorStyleEntity2.get());
entityRef.m_pInterfaceRef = s_SelectionForFreeCameraEditorStyleEntity;
if (!m_SelectionForFreeCameraEditorStyleEntity) {
m_SelectionForFreeCameraEditorStyleEntity = reinterpret_cast<ZSelectionForFreeCameraEditorStyleEntity*>(calloc(1, sizeof(ZSelectionForFreeCameraEditorStyleEntity)));

Globals::Selections->push_back(entityRef);
TEntityRef<ZSelectionForFreeCameraEditorStyleEntity> s_EntityRef;
s_EntityRef.m_pInterfaceRef = m_SelectionForFreeCameraEditorStyleEntity;

m_SelectionForEntityCreated = true;
Globals::Selections->push_back(s_EntityRef);
}

if (m_SelectionForEntityCreated)
{
s_Selection.clear();
s_Selection.push_back(p_Entity);

s_SelectionForFreeCameraEditorStyleEntity->m_selection = s_Selection;
else {
m_SelectionForFreeCameraEditorStyleEntity->m_selection.clear();
m_SelectionForFreeCameraEditorStyleEntity->m_selection.push_back(p_Entity);
}
}

Expand Down
13 changes: 10 additions & 3 deletions Mods/Editor/Src/Editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ Editor::~Editor()
{
const ZMemberDelegate<Editor, void(const SGameUpdateEvent&)> s_Delegate(this, &Editor::OnFrameUpdate);
Globals::GameLoopManager->UnregisterFrameUpdate(s_Delegate, 1, EUpdateMode::eUpdatePlayMode);

if (m_SelectionForFreeCameraEditorStyleEntity) {
Globals::Selections->clear();
free(m_SelectionForFreeCameraEditorStyleEntity);
m_SelectionForFreeCameraEditorStyleEntity = nullptr;
}
}

void Editor::Init()
Expand Down Expand Up @@ -618,6 +624,10 @@ DEFINE_PLUGIN_DETOUR(Editor, void, OnLoadScene, ZEntitySceneContext* th, ZSceneD
// p_SceneData.m_sceneName = "assembly:/_pro/scenes/missions/golden/mission_gecko/scene_gecko_basic.entity";
*/

if (m_SelectionForFreeCameraEditorStyleEntity) {
m_SelectionForFreeCameraEditorStyleEntity->m_selection.clear();
}

m_CachedEntityTreeMutex.lock();
m_CachedEntityTree.reset();
m_CachedEntityTreeMutex.unlock();
Expand All @@ -630,9 +640,6 @@ DEFINE_PLUGIN_DETOUR(Editor, void, OnLoadScene, ZEntitySceneContext* th, ZSceneD

m_Server.OnSceneLoading(p_SceneData.m_sceneName.c_str(), s_Bricks);

// Clear SelectionForFreeCameraEditorStyleEntity's entity array just in case it wasn't cleared from previous scene
s_Selection.clear();

return HookResult<void>(HookAction::Continue());
}

Expand Down
6 changes: 1 addition & 5 deletions Mods/Editor/Src/Editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,7 @@ class Editor : public IPluginInterface
bool m_CameraActive = false;
ZEntityRef m_OriginalCam;

bool m_SelectionForEntityCreated = false;
TArray<ZEntityRef> s_Selection;
ZSelectionForFreeCameraEditorStyleEntity* s_SelectionForFreeCameraEditorStyleEntity;
std::unique_ptr<unsigned char[]> s_SelectionForFreeCameraEditorStyleEntity2;
TEntityRef<ZSelectionForFreeCameraEditorStyleEntity> entityRef;
ZSelectionForFreeCameraEditorStyleEntity* m_SelectionForFreeCameraEditorStyleEntity = nullptr;

bool m_HoldingMouse = false;
bool m_UseSnap = false;
Expand Down
20 changes: 20 additions & 0 deletions ZHMModSDK/Include/Glacier/TArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,26 @@ class TArray
m_pBegin[s_Size] = p_Value;
}

T* erase(T* p_Value) {
size_t s_Size = size();

for (size_t i = 0; i < s_Size; i++) {
if (m_pBegin[i] != p_Value) {
continue;
}

// TODO: Call destructor?

for (size_t j = i; j < s_Size - 1; j++) {
m_pBegin[j] = m_pBegin[j + 1];
}

resize(s_Size - 1);
return &m_pBegin[i];
}
}


void resize(size_t p_Size)
{
// TODO: Inline support.
Expand Down

0 comments on commit ff36dae

Please sign in to comment.