Merge branch 'development' into cmake/SPEC-2513_w4018
Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com> # Conflicts: # Gems/EMotionFX/Code/EMotionFX/Source/Actor.cppmonroegm-disable-blank-issue-2
commit
2d1ed48fea
@ -0,0 +1,44 @@
|
||||
"""
|
||||
Copyright (c) Contributors to the Open 3D Engine Project.
|
||||
For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||
|
||||
SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
|
||||
UI Apps: AutomatedTesting.GameLauncher
|
||||
Launch AutomatedTesting.GameLauncher with Simple level
|
||||
Test should run in both gpu and non gpu
|
||||
"""
|
||||
|
||||
import pytest
|
||||
import psutil
|
||||
|
||||
import ly_test_tools.environment.waiter as waiter
|
||||
import editor_python_test_tools.hydra_test_utils as editor_test_utils
|
||||
from ly_remote_console.remote_console_commands import RemoteConsole as RemoteConsole
|
||||
from ly_remote_console.remote_console_commands import (
|
||||
send_command_and_expect_response as send_command_and_expect_response,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("launcher_platform", ["windows"])
|
||||
@pytest.mark.parametrize("project", ["AutomatedTesting"])
|
||||
@pytest.mark.parametrize("level", ["Simple"])
|
||||
@pytest.mark.SUITE_smoke
|
||||
class TestRemoteConsoleLoadLevelWorks(object):
|
||||
@pytest.fixture
|
||||
def remote_console_instance(self, request):
|
||||
console = RemoteConsole()
|
||||
|
||||
def teardown():
|
||||
if console.connected:
|
||||
console.stop()
|
||||
|
||||
request.addfinalizer(teardown)
|
||||
|
||||
return console
|
||||
|
||||
def test_RemoteConsole_LoadLevel_Works(self, launcher, level, remote_console_instance, launcher_platform):
|
||||
expected_lines = ['Level system is loading "Simple"']
|
||||
|
||||
editor_test_utils.launch_and_validate_results_launcher(launcher, level, remote_console_instance, expected_lines, null_renderer=True)
|
||||
@ -0,0 +1,43 @@
|
||||
"""
|
||||
Copyright (c) Contributors to the Open 3D Engine Project.
|
||||
For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||
|
||||
SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
|
||||
UI Apps: AutomatedTesting.GameLauncher
|
||||
Launch AutomatedTesting.GameLauncher with Simple level
|
||||
Test should run in both gpu and non gpu
|
||||
"""
|
||||
|
||||
import pytest
|
||||
import psutil
|
||||
|
||||
import ly_test_tools.environment.waiter as waiter
|
||||
import editor_python_test_tools.hydra_test_utils as editor_test_utils
|
||||
from ly_remote_console.remote_console_commands import RemoteConsole as RemoteConsole
|
||||
from ly_remote_console.remote_console_commands import (
|
||||
send_command_and_expect_response as send_command_and_expect_response,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("launcher_platform", ["windows"])
|
||||
@pytest.mark.parametrize("project", ["AutomatedTesting"])
|
||||
@pytest.mark.parametrize("level", ["Simple"])
|
||||
class TestRemoteConsoleLoadLevelWorks(object):
|
||||
@pytest.fixture
|
||||
def remote_console_instance(self, request):
|
||||
console = RemoteConsole()
|
||||
|
||||
def teardown():
|
||||
if console.connected:
|
||||
console.stop()
|
||||
|
||||
request.addfinalizer(teardown)
|
||||
|
||||
return console
|
||||
|
||||
def test_RemoteConsole_LoadLevel_Works(self, launcher, level, remote_console_instance, launcher_platform):
|
||||
expected_lines = ['Level system is loading "Simple"']
|
||||
|
||||
editor_test_utils.launch_and_validate_results_launcher(launcher, level, remote_console_instance, expected_lines, null_renderer=False)
|
||||
@ -1,105 +0,0 @@
|
||||
"""
|
||||
Copyright (c) Contributors to the Open 3D Engine Project.
|
||||
For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||
|
||||
SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
|
||||
UI Apps: AutomatedTesting.GameLauncher
|
||||
Launch AutomatedTesting.GameLauncher with Simple level
|
||||
Test should run in both gpu and non gpu
|
||||
"""
|
||||
|
||||
import pytest
|
||||
import psutil
|
||||
|
||||
# Bail on the test if ly_test_tools doesn't exist.
|
||||
pytest.importorskip("ly_test_tools")
|
||||
import ly_test_tools.environment.waiter as waiter
|
||||
from ly_remote_console.remote_console_commands import RemoteConsole as RemoteConsole
|
||||
from ly_remote_console.remote_console_commands import (
|
||||
send_command_and_expect_response as send_command_and_expect_response,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("launcher_platform", ["windows"])
|
||||
@pytest.mark.parametrize("project", ["AutomatedTesting"])
|
||||
@pytest.mark.parametrize("level", ["Simple"])
|
||||
@pytest.mark.SUITE_sandbox
|
||||
class TestRemoteConsoleLoadLevelWorks(object):
|
||||
@pytest.fixture
|
||||
def remote_console_instance(self, request):
|
||||
console = RemoteConsole()
|
||||
|
||||
def teardown():
|
||||
if console.connected:
|
||||
console.stop()
|
||||
|
||||
request.addfinalizer(teardown)
|
||||
|
||||
return console
|
||||
|
||||
def test_RemoteConsole_LoadLevel_Works(self, launcher, level, remote_console_instance, launcher_platform):
|
||||
expected_lines = ['Level system is loading "Simple"']
|
||||
|
||||
self.launch_and_validate_results_launcher(launcher, level, remote_console_instance, expected_lines)
|
||||
|
||||
def launch_and_validate_results_launcher(
|
||||
self,
|
||||
launcher,
|
||||
level,
|
||||
remote_console_instance,
|
||||
expected_lines,
|
||||
null_renderer=False,
|
||||
port_listener_timeout=120,
|
||||
log_monitor_timeout=300,
|
||||
remote_console_port=4600,
|
||||
):
|
||||
"""
|
||||
Runs the launcher with the specified level, and monitors Game.log for expected lines.
|
||||
:param launcher: Configured launcher object to run test against.
|
||||
:param level: The level to load in the launcher.
|
||||
:param remote_console_instance: Configured Remote Console object.
|
||||
:param expected_lines: Expected lines to search log for.
|
||||
:oaram null_renderer: Specifies the test does not require the renderer. Defaults to True.
|
||||
:param port_listener_timeout: Timeout for verifying successful connection to Remote Console.
|
||||
:param log_monitor_timeout: Timeout for monitoring for lines in Game.log
|
||||
:param remote_console_port: The port used to communicate with the Remote Console.
|
||||
"""
|
||||
|
||||
def _check_for_listening_port(port):
|
||||
"""
|
||||
Checks to see if the connection to the designated port was established.
|
||||
:param port: Port to listen to.
|
||||
:return: True if port is listening.
|
||||
"""
|
||||
port_listening = False
|
||||
for conn in psutil.net_connections():
|
||||
if "port={}".format(port) in str(conn):
|
||||
port_listening = True
|
||||
return port_listening
|
||||
|
||||
if null_renderer:
|
||||
launcher.args.extend(["-NullRenderer"])
|
||||
|
||||
# Start the Launcher
|
||||
with launcher.start():
|
||||
|
||||
# Ensure Remote Console can be reached
|
||||
waiter.wait_for(
|
||||
lambda: _check_for_listening_port(remote_console_port),
|
||||
port_listener_timeout,
|
||||
exc=AssertionError("Port {} not listening.".format(remote_console_port)),
|
||||
)
|
||||
remote_console_instance.start(timeout=30)
|
||||
|
||||
# Load the specified level in the launcher
|
||||
send_command_and_expect_response(
|
||||
remote_console_instance, f"loadlevel {level}", "LEVEL_LOAD_END", timeout=30
|
||||
)
|
||||
|
||||
# Monitor the console for expected lines
|
||||
for line in expected_lines:
|
||||
assert remote_console_instance.expect_log_line(
|
||||
line, log_monitor_timeout
|
||||
), f"Expected line not found: {line}"
|
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project.
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include <AzCore/Component/ComponentApplication.h>
|
||||
#include <AzCore/Memory/SystemAllocator.h>
|
||||
#include <AzCore/Settings/SettingsRegistryMergeUtils.h>
|
||||
#include <AzCore/Utils/Utils.h>
|
||||
#include <AzFramework/Process/ProcessWatcher.h>
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
// Create a ComponentApplication to initialize the AZ::SystemAllocator and initialize the SettingsRegistry
|
||||
AZ::ComponentApplication::Descriptor desc;
|
||||
AZ::ComponentApplication application;
|
||||
application.Create(desc);
|
||||
|
||||
AZStd::vector<AZStd::string> envVars;
|
||||
|
||||
const char* homePath = std::getenv("HOME");
|
||||
envVars.push_back(AZStd::string::format("HOME=%s", homePath));
|
||||
|
||||
if (auto settingsRegistry = AZ::SettingsRegistry::Get(); settingsRegistry != nullptr)
|
||||
{
|
||||
const char* dyldLibPathOrig = std::getenv("DYLD_LIBRARY_PATH");
|
||||
AZStd::string dyldSearchPath = AZStd::string::format("DYLD_LIBRARY_PATH=%s", dyldLibPathOrig);
|
||||
if (AZ::IO::FixedMaxPath projectModulePath;
|
||||
settingsRegistry->Get(projectModulePath.Native(), AZ::SettingsRegistryMergeUtils::FilePathKey_ProjectConfigurationBinPath))
|
||||
{
|
||||
dyldSearchPath.append(":");
|
||||
dyldSearchPath.append(projectModulePath.c_str());
|
||||
}
|
||||
|
||||
if (AZ::IO::FixedMaxPath installedBinariesFolder;
|
||||
settingsRegistry->Get(installedBinariesFolder.Native(), AZ::SettingsRegistryMergeUtils::FilePathKey_InstalledBinaryFolder))
|
||||
{
|
||||
if (AZ::IO::FixedMaxPath engineRootFolder;
|
||||
settingsRegistry->Get(engineRootFolder.Native(), AZ::SettingsRegistryMergeUtils::FilePathKey_EngineRootFolder))
|
||||
{
|
||||
installedBinariesFolder = engineRootFolder / installedBinariesFolder;
|
||||
dyldSearchPath.append(":");
|
||||
dyldSearchPath.append(installedBinariesFolder.c_str());
|
||||
}
|
||||
}
|
||||
envVars.push_back(dyldSearchPath);
|
||||
}
|
||||
|
||||
AZStd::string commandArgs;
|
||||
for (int i = 1; i < argc; i++)
|
||||
{
|
||||
commandArgs.append(argv[i]);
|
||||
commandArgs.append(" ");
|
||||
}
|
||||
|
||||
AzFramework::ProcessLauncher::ProcessLaunchInfo processLaunchInfo;
|
||||
AZ::IO::Path processPath{ AZ::IO::PathView(AZ::Utils::GetExecutableDirectory()) };
|
||||
processPath /= "Editor";
|
||||
processLaunchInfo.m_processExecutableString = AZStd::move(processPath.Native());
|
||||
processLaunchInfo.m_commandlineParameters = commandArgs;
|
||||
processLaunchInfo.m_environmentVariables = &envVars;
|
||||
processLaunchInfo.m_showWindow = true;
|
||||
|
||||
AzFramework::ProcessWatcher* processWatcher = AzFramework::ProcessWatcher::LaunchProcess(processLaunchInfo, AzFramework::ProcessCommunicationType::COMMUNICATOR_TYPE_NONE);
|
||||
|
||||
application.Destroy();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,649 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project.
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef CRYINCLUDE_EDITOR_RENDERVIEWPORT_H
|
||||
#define CRYINCLUDE_EDITOR_RENDERVIEWPORT_H
|
||||
|
||||
#pragma once
|
||||
// RenderViewport.h : header file
|
||||
//
|
||||
|
||||
#if !defined(Q_MOC_RUN)
|
||||
#include <Cry_Camera.h>
|
||||
|
||||
#include <QSet>
|
||||
|
||||
#include "Viewport.h"
|
||||
#include "Objects/DisplayContext.h"
|
||||
#include "Undo/Undo.h"
|
||||
#include "Util/PredefinedAspectRatios.h"
|
||||
|
||||
#include <AzCore/Component/EntityId.h>
|
||||
#include <AzCore/std/optional.h>
|
||||
#include <AzFramework/Input/Buses/Requests/InputSystemCursorRequestBus.h>
|
||||
#include <AzToolsFramework/API/ToolsApplicationAPI.h>
|
||||
#include <AzToolsFramework/API/EditorCameraBus.h>
|
||||
#include <AzToolsFramework/Entity/EditorEntityContextBus.h>
|
||||
#include <AzToolsFramework/Viewport/ViewportMessages.h>
|
||||
#include <MathConversion.h>
|
||||
#endif
|
||||
|
||||
#include <AzFramework/Windowing/WindowBus.h>
|
||||
#include <AzFramework/Visibility/EntityVisibilityQuery.h>
|
||||
|
||||
// forward declarations.
|
||||
class CBaseObject;
|
||||
class QMenu;
|
||||
class QKeyEvent;
|
||||
class EditorEntityNotifications;
|
||||
struct ray_hit;
|
||||
struct IRenderMesh;
|
||||
struct IVariable;
|
||||
|
||||
namespace AzToolsFramework
|
||||
{
|
||||
class ManipulatorManager;
|
||||
}
|
||||
|
||||
// CRenderViewport window
|
||||
AZ_PUSH_DISABLE_DLL_EXPORT_BASECLASS_WARNING
|
||||
AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING
|
||||
class SANDBOX_API CRenderViewport
|
||||
: public QtViewport
|
||||
, public IEditorNotifyListener
|
||||
, public IUndoManagerListener
|
||||
, public Camera::EditorCameraRequestBus::Handler
|
||||
, public AzFramework::InputSystemCursorConstraintRequestBus::Handler
|
||||
, public AzToolsFramework::ViewportInteraction::ViewportFreezeRequestBus::Handler
|
||||
, public AzToolsFramework::ViewportInteraction::ViewportInteractionRequestBus::Handler
|
||||
, public AzToolsFramework::ViewportInteraction::MainEditorViewportInteractionRequestBus::Handler
|
||||
, public AzFramework::WindowRequestBus::Handler
|
||||
{
|
||||
AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING
|
||||
AZ_POP_DISABLE_DLL_EXPORT_BASECLASS_WARNING
|
||||
Q_OBJECT
|
||||
public:
|
||||
struct SResolution
|
||||
{
|
||||
SResolution()
|
||||
: width(0)
|
||||
, height(0)
|
||||
{
|
||||
}
|
||||
|
||||
SResolution(int w, int h)
|
||||
: width(w)
|
||||
, height(h)
|
||||
{
|
||||
}
|
||||
|
||||
int width;
|
||||
int height;
|
||||
};
|
||||
|
||||
public:
|
||||
CRenderViewport(const QString& name, QWidget* parent = nullptr);
|
||||
|
||||
static const GUID& GetClassID()
|
||||
{
|
||||
return QtViewport::GetClassID<CRenderViewport>();
|
||||
}
|
||||
|
||||
/** Get type of this viewport.
|
||||
*/
|
||||
virtual EViewportType GetType() const { return ET_ViewportCamera; }
|
||||
virtual void SetType([[maybe_unused]] EViewportType type) { assert(type == ET_ViewportCamera); };
|
||||
|
||||
// Implementation
|
||||
public:
|
||||
virtual ~CRenderViewport();
|
||||
|
||||
Q_INVOKABLE void InjectFakeMouseMove(int deltaX, int deltaY, Qt::MouseButtons buttons);
|
||||
|
||||
public:
|
||||
virtual void Update();
|
||||
|
||||
virtual void ResetContent();
|
||||
virtual void UpdateContent(int flags);
|
||||
|
||||
void OnTitleMenu(QMenu* menu) override;
|
||||
|
||||
void SetCamera(const CCamera& camera);
|
||||
const CCamera& GetCamera() const { return m_Camera; };
|
||||
virtual void SetViewTM(const Matrix34& tm)
|
||||
{
|
||||
if (m_viewSourceType == ViewSourceType::None)
|
||||
{
|
||||
m_defaultViewTM = tm;
|
||||
}
|
||||
SetViewTM(tm, false);
|
||||
}
|
||||
|
||||
//! Map world space position to viewport position.
|
||||
virtual QPoint WorldToView(const Vec3& wp) const;
|
||||
virtual QPoint WorldToViewParticleEditor(const Vec3& wp, int width, int height) const;
|
||||
virtual Vec3 WorldToView3D(const Vec3& wp, int nFlags = 0) const;
|
||||
|
||||
//! Map viewport position to world space position.
|
||||
virtual Vec3 ViewToWorld(const QPoint& vp, bool* collideWithTerrain = nullptr, bool onlyTerrain = false, bool bSkipVegetation = false, bool bTestRenderMesh = false, bool* collideWithObject = nullptr) const override;
|
||||
virtual void ViewToWorldRay(const QPoint& vp, Vec3& raySrc, Vec3& rayDir) const override;
|
||||
virtual Vec3 ViewToWorldNormal(const QPoint& vp, bool onlyTerrain, bool bTestRenderMesh = false) override;
|
||||
virtual float GetScreenScaleFactor(const Vec3& worldPoint) const;
|
||||
virtual float GetScreenScaleFactor(const CCamera& camera, const Vec3& object_position);
|
||||
virtual float GetAspectRatio() const;
|
||||
virtual bool HitTest(const QPoint& point, HitContext& hitInfo);
|
||||
virtual bool IsBoundsVisible(const AABB& box) const;
|
||||
virtual void CenterOnSelection();
|
||||
virtual void CenterOnAABB(const AABB& aabb);
|
||||
void CenterOnSliceInstance() override;
|
||||
|
||||
void focusOutEvent(QFocusEvent* event) override;
|
||||
void keyPressEvent(QKeyEvent* event) override;
|
||||
void keyReleaseEvent(QKeyEvent* event) override;
|
||||
|
||||
void SetFOV(float fov);
|
||||
float GetFOV() const;
|
||||
|
||||
void SetDefaultCamera();
|
||||
bool IsDefaultCamera() const;
|
||||
void SetSequenceCamera();
|
||||
bool IsSequenceCamera() const { return m_viewSourceType == ViewSourceType::SequenceCamera; }
|
||||
void SetSelectedCamera();
|
||||
bool IsSelectedCamera() const;
|
||||
void SetComponentCamera(const AZ::EntityId& entityId);
|
||||
void SetEntityAsCamera(const AZ::EntityId& entityId, bool lockCameraMovement = false);
|
||||
void SetFirstComponentCamera();
|
||||
void SetViewEntity(const AZ::EntityId& cameraEntityId, bool lockCameraMovement = false);
|
||||
void PostCameraSet();
|
||||
// This switches the active camera to the next one in the list of (default, all custom cams).
|
||||
void CycleCamera();
|
||||
|
||||
// Camera::EditorCameraRequestBus
|
||||
void SetViewFromEntityPerspective(const AZ::EntityId& entityId) override;
|
||||
void SetViewAndMovementLockFromEntityPerspective(const AZ::EntityId& entityId, bool lockCameraMovement) override;
|
||||
AZ::EntityId GetCurrentViewEntityId() override { return m_viewEntityId; }
|
||||
bool GetActiveCameraPosition(AZ::Vector3& cameraPos) override;
|
||||
bool GetActiveCameraState(AzFramework::CameraState& cameraState) override;
|
||||
|
||||
// AzToolsFramework::EditorEntityContextNotificationBus (handler moved to cpp to resolve link issues in unity builds)
|
||||
virtual void OnStartPlayInEditor();
|
||||
virtual void OnStopPlayInEditor();
|
||||
|
||||
// AzToolsFramework::EditorContextMenu::Bus (handler moved to cpp to resolve link issues in unity builds)
|
||||
// We use this to determine when the viewport context menu is being displayed so we can exit move mode
|
||||
void PopulateEditorGlobalContextMenu(QMenu* /*menu*/, const AZ::Vector2& /*point*/, int /*flags*/);
|
||||
|
||||
// AzToolsFramework::ViewportInteractionRequestBus
|
||||
AzFramework::CameraState GetCameraState() override;
|
||||
bool GridSnappingEnabled() override;
|
||||
float GridSize() override;
|
||||
bool ShowGrid() override;
|
||||
bool AngleSnappingEnabled() override;
|
||||
float AngleStep() override;
|
||||
AzFramework::ScreenPoint ViewportWorldToScreen(const AZ::Vector3& worldPosition) override;
|
||||
AZStd::optional<AZ::Vector3> ViewportScreenToWorld(const AzFramework::ScreenPoint&, float) override
|
||||
{
|
||||
return {};
|
||||
}
|
||||
AZStd::optional<AzToolsFramework::ViewportInteraction::ProjectedViewportRay> ViewportScreenToWorldRay(
|
||||
const AzFramework::ScreenPoint&) override
|
||||
{
|
||||
return {};
|
||||
}
|
||||
float DeviceScalingFactor() override { return 1.0f; }
|
||||
|
||||
// AzToolsFramework::ViewportFreezeRequestBus
|
||||
bool IsViewportInputFrozen() override;
|
||||
void FreezeViewportInput(bool freeze) override;
|
||||
|
||||
// AzToolsFramework::MainEditorViewportInteractionRequestBus
|
||||
AZ::EntityId PickEntity(const AzFramework::ScreenPoint& point) override;
|
||||
AZ::Vector3 PickTerrain(const AzFramework::ScreenPoint& point) override;
|
||||
float TerrainHeight(const AZ::Vector2& position) override;
|
||||
void FindVisibleEntities(AZStd::vector<AZ::EntityId>& visibleEntitiesOut) override;
|
||||
bool ShowingWorldSpace() override;
|
||||
QWidget* GetWidgetForViewportContextMenu() override;
|
||||
void BeginWidgetContext() override;
|
||||
void EndWidgetContext() override;
|
||||
|
||||
// WindowRequestBus::Handler...
|
||||
void SetWindowTitle(const AZStd::string& title) override;
|
||||
AzFramework::WindowSize GetClientAreaSize() const override;
|
||||
void ResizeClientArea(AzFramework::WindowSize) override;
|
||||
bool GetFullScreenState() const override;
|
||||
void SetFullScreenState(bool fullScreenState) override;
|
||||
bool CanToggleFullScreenState() const override;
|
||||
void ToggleFullScreenState() override;
|
||||
float GetDpiScaleFactor() const override { return 1.0f; };
|
||||
|
||||
void ConnectViewportInteractionRequestBus();
|
||||
void DisconnectViewportInteractionRequestBus();
|
||||
|
||||
void ActivateWindowAndSetFocus();
|
||||
|
||||
void LockCameraMovement(bool bLock) { m_bLockCameraMovement = bLock; }
|
||||
bool IsCameraMovementLocked() const { return m_bLockCameraMovement; }
|
||||
|
||||
void EnableCameraObjectMove(bool bMove) { m_bMoveCameraObject = bMove; }
|
||||
bool IsCameraObjectMove() const { return m_bMoveCameraObject; }
|
||||
|
||||
void SetPlayerControl(uint32 i) { m_PlayerControl = i; };
|
||||
uint32 GetPlayerControl() { return m_PlayerControl; };
|
||||
|
||||
const DisplayContext& GetDisplayContext() const { return m_displayContext; }
|
||||
CBaseObject* GetCameraObject() const;
|
||||
|
||||
QPoint WidgetToViewport(const QPoint& point) const;
|
||||
QPoint ViewportToWidget(const QPoint& point) const;
|
||||
QSize WidgetToViewport(const QSize& size) const;
|
||||
|
||||
AzToolsFramework::ViewportInteraction::MouseInteraction BuildMouseInteraction(
|
||||
Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, const QPoint& point) override;
|
||||
|
||||
void SetPlayerPos()
|
||||
{
|
||||
Matrix34 m = GetViewTM();
|
||||
m.SetTranslation(m.GetTranslation() - m_PhysicalLocation.t);
|
||||
SetViewTM(m);
|
||||
|
||||
m_AverageFrameTime = 0.14f;
|
||||
|
||||
m_PhysicalLocation.SetIdentity();
|
||||
|
||||
m_LocalEntityMat.SetIdentity();
|
||||
m_PrevLocalEntityMat.SetIdentity();
|
||||
|
||||
m_absCameraHigh = 2.0f;
|
||||
m_absCameraPos = Vec3(0, 3, 2);
|
||||
m_absCameraPosVP = Vec3(0, -3, 1.5);
|
||||
|
||||
m_absCurrentSlope = 0.0f;
|
||||
|
||||
m_absLookDirectionXY = Vec2(0, 1);
|
||||
|
||||
m_LookAt = Vec3(ZERO);
|
||||
m_LookAtRate = Vec3(ZERO);
|
||||
m_vCamPos = Vec3(ZERO);
|
||||
m_vCamPosRate = Vec3(ZERO);
|
||||
|
||||
m_relCameraRotX = 0;
|
||||
m_relCameraRotZ = 0;
|
||||
|
||||
uint32 numSample6 = static_cast<uint32>(m_arrAnimatedCharacterPath.size());
|
||||
for (uint32 i = 0; i < numSample6; i++)
|
||||
{
|
||||
m_arrAnimatedCharacterPath[i] = Vec3(ZERO);
|
||||
}
|
||||
|
||||
numSample6 = static_cast<uint32>(m_arrSmoothEntityPath.size());
|
||||
for (uint32 i = 0; i < numSample6; i++)
|
||||
{
|
||||
m_arrSmoothEntityPath[i] = Vec3(ZERO);
|
||||
}
|
||||
|
||||
uint32 numSample7 = static_cast<uint32>(m_arrRunStrafeSmoothing.size());
|
||||
for (uint32 i = 0; i < numSample7; i++)
|
||||
{
|
||||
m_arrRunStrafeSmoothing[i] = 0;
|
||||
}
|
||||
|
||||
m_vWorldDesiredBodyDirection = Vec2(0, 1);
|
||||
m_vWorldDesiredBodyDirectionSmooth = Vec2(0, 1);
|
||||
m_vWorldDesiredBodyDirectionSmoothRate = Vec2(0, 1);
|
||||
|
||||
m_vWorldDesiredBodyDirection2 = Vec2(0, 1);
|
||||
|
||||
m_vWorldDesiredMoveDirection = Vec2(0, 1);
|
||||
m_vWorldDesiredMoveDirectionSmooth = Vec2(0, 1);
|
||||
m_vWorldDesiredMoveDirectionSmoothRate = Vec2(0, 1);
|
||||
m_vLocalDesiredMoveDirection = Vec2(0, 1);
|
||||
m_vLocalDesiredMoveDirectionSmooth = Vec2(0, 1);
|
||||
m_vLocalDesiredMoveDirectionSmoothRate = Vec2(0, 1);
|
||||
|
||||
m_vWorldAimBodyDirection = Vec2(0, 1);
|
||||
|
||||
m_MoveSpeedMSec = 5.0f;
|
||||
m_key_W = 0;
|
||||
m_keyrcr_W = 0;
|
||||
m_key_S = 0;
|
||||
m_keyrcr_S = 0;
|
||||
m_key_A = 0;
|
||||
m_keyrcr_A = 0;
|
||||
m_key_D = 0;
|
||||
m_keyrcr_D = 0;
|
||||
m_key_SPACE = 0;
|
||||
m_keyrcr_SPACE = 0;
|
||||
m_ControllMode = 0;
|
||||
|
||||
m_State = -1;
|
||||
m_Stance = 1; //combat
|
||||
|
||||
m_udGround = 0.0f;
|
||||
m_lrGround = 0.0f;
|
||||
AABB aabb = AABB(Vec3(-40.0f, -40.0f, -0.25f), Vec3(+40.0f, +40.0f, +0.0f));
|
||||
m_GroundOBB = OBB::CreateOBBfromAABB(Matrix33(IDENTITY), aabb);
|
||||
m_GroundOBBPos = Vec3(0, 0, -0.01f);
|
||||
};
|
||||
|
||||
static CRenderViewport* GetPrimaryViewport();
|
||||
|
||||
AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING
|
||||
CCamera m_Camera;
|
||||
AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING
|
||||
|
||||
protected:
|
||||
struct SScopedCurrentContext;
|
||||
|
||||
void SetViewTM(const Matrix34& tm, bool bMoveOnly);
|
||||
|
||||
virtual float GetCameraMoveSpeed() const;
|
||||
virtual float GetCameraRotateSpeed() const;
|
||||
virtual bool GetCameraInvertYRotation() const;
|
||||
virtual float GetCameraInvertPan() const;
|
||||
|
||||
// Called to render stuff.
|
||||
virtual void OnRender();
|
||||
|
||||
virtual void OnEditorNotifyEvent(EEditorNotifyEvent event);
|
||||
|
||||
//! Get currently active camera object.
|
||||
void ToggleCameraObject();
|
||||
|
||||
void RenderConstructionPlane();
|
||||
void RenderSnapMarker();
|
||||
void RenderCursorString();
|
||||
void RenderSnappingGrid();
|
||||
void ProcessMouse();
|
||||
void ProcessKeys();
|
||||
|
||||
void RenderAll();
|
||||
void DrawAxis();
|
||||
void DrawBackground();
|
||||
void InitDisplayContext();
|
||||
void ResetCursor();
|
||||
|
||||
struct SPreviousContext
|
||||
{
|
||||
CCamera rendererCamera;
|
||||
HWND window;
|
||||
int width;
|
||||
int height;
|
||||
bool mainViewport;
|
||||
};
|
||||
|
||||
SPreviousContext m_preWidgetContext;
|
||||
|
||||
// Create an auto-sized render context that is sized based on the Editor's current
|
||||
// viewport.
|
||||
SPreviousContext SetCurrentContext() const;
|
||||
|
||||
SPreviousContext SetCurrentContext(int newWidth, int newHeight) const;
|
||||
void RestorePreviousContext(const SPreviousContext& x) const;
|
||||
|
||||
void PreWidgetRendering() override;
|
||||
void PostWidgetRendering() override;
|
||||
|
||||
// Update the safe frame, safe action, safe title, and borders rectangles based on
|
||||
// viewport size and target aspect ratio.
|
||||
void UpdateSafeFrame();
|
||||
|
||||
// Draw safe frame, safe action, safe title rectangles and borders.
|
||||
void RenderSafeFrame();
|
||||
|
||||
// Draw one of the safe frame rectangles with the desired color.
|
||||
void RenderSafeFrame(const QRect& frame, float r, float g, float b, float a);
|
||||
|
||||
// Draw the selection rectangle.
|
||||
void RenderSelectionRectangle();
|
||||
|
||||
// Draw a selected region if it has been selected
|
||||
void RenderSelectedRegion();
|
||||
|
||||
virtual bool CreateRenderContext();
|
||||
virtual void DestroyRenderContext();
|
||||
|
||||
void OnMenuCommandChangeAspectRatio(unsigned int commandId);
|
||||
|
||||
bool AdjustObjectPosition(const ray_hit& hit, Vec3& outNormal, Vec3& outPos) const;
|
||||
bool RayRenderMeshIntersection(IRenderMesh* pRenderMesh, const Vec3& vInPos, const Vec3& vInDir, Vec3& vOutPos, Vec3& vOutNormal) const;
|
||||
|
||||
bool AddCameraMenuItems(QMenu* menu);
|
||||
void ResizeView(int width, int height);
|
||||
|
||||
void OnCameraFOVVariableChanged(IVariable* var);
|
||||
|
||||
void HideCursor();
|
||||
void ShowCursor();
|
||||
|
||||
bool IsKeyDown(Qt::Key key) const;
|
||||
|
||||
enum class ViewSourceType
|
||||
{
|
||||
None,
|
||||
SequenceCamera,
|
||||
LegacyCamera,
|
||||
CameraComponent,
|
||||
AZ_Entity,
|
||||
ViewSourceTypesCount,
|
||||
};
|
||||
void ResetToViewSourceType(const ViewSourceType& viewSourType);
|
||||
|
||||
//! Assigned renderer.
|
||||
IRenderer* m_renderer = nullptr;
|
||||
bool m_bRenderContextCreated = false;
|
||||
bool m_bInRotateMode = false;
|
||||
bool m_bInMoveMode = false;
|
||||
bool m_bInOrbitMode = false;
|
||||
bool m_bInZoomMode = false;
|
||||
|
||||
QPoint m_mousePos = QPoint(0, 0);
|
||||
QPoint m_prevMousePos = QPoint(0, 0); // for tablets, you can't use SetCursorPos and need to remember the prior point and delta with that.
|
||||
|
||||
|
||||
float m_moveSpeed = 1;
|
||||
|
||||
float m_orbitDistance = 10.0f;
|
||||
AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING
|
||||
Vec3 m_orbitTarget;
|
||||
|
||||
//-------------------------------------------
|
||||
//--- player-control in CharEdit ---
|
||||
//-------------------------------------------
|
||||
f32 m_MoveSpeedMSec;
|
||||
|
||||
uint32 m_key_W, m_keyrcr_W;
|
||||
uint32 m_key_S, m_keyrcr_S;
|
||||
uint32 m_key_A, m_keyrcr_A;
|
||||
uint32 m_key_D, m_keyrcr_D;
|
||||
|
||||
uint32 m_key_SPACE, m_keyrcr_SPACE;
|
||||
uint32 m_ControllMode;
|
||||
|
||||
int32 m_Stance;
|
||||
int32 m_State;
|
||||
f32 m_AverageFrameTime;
|
||||
|
||||
uint32 m_PlayerControl = 0;
|
||||
|
||||
f32 m_absCameraHigh;
|
||||
Vec3 m_absCameraPos;
|
||||
Vec3 m_absCameraPosVP;
|
||||
|
||||
f32 m_absCurrentSlope; //in radiants
|
||||
|
||||
Vec2 m_absLookDirectionXY;
|
||||
|
||||
Vec3 m_LookAt;
|
||||
Vec3 m_LookAtRate;
|
||||
Vec3 m_vCamPos;
|
||||
Vec3 m_vCamPosRate;
|
||||
float m_camFOV;
|
||||
|
||||
f32 m_relCameraRotX;
|
||||
f32 m_relCameraRotZ;
|
||||
|
||||
QuatTS m_PhysicalLocation;
|
||||
|
||||
Matrix34 m_AnimatedCharacterMat;
|
||||
|
||||
Matrix34 m_LocalEntityMat; //this is used for data-driven animations where the character is running on the spot
|
||||
Matrix34 m_PrevLocalEntityMat;
|
||||
|
||||
std::vector<Vec3> m_arrVerticesHF;
|
||||
std::vector<vtx_idx> m_arrIndicesHF;
|
||||
|
||||
std::vector<Vec3> m_arrAnimatedCharacterPath;
|
||||
std::vector<Vec3> m_arrSmoothEntityPath;
|
||||
std::vector<f32> m_arrRunStrafeSmoothing;
|
||||
|
||||
Vec2 m_vWorldDesiredBodyDirection;
|
||||
Vec2 m_vWorldDesiredBodyDirectionSmooth;
|
||||
Vec2 m_vWorldDesiredBodyDirectionSmoothRate;
|
||||
|
||||
Vec2 m_vWorldDesiredBodyDirection2;
|
||||
|
||||
|
||||
Vec2 m_vWorldDesiredMoveDirection;
|
||||
Vec2 m_vWorldDesiredMoveDirectionSmooth;
|
||||
Vec2 m_vWorldDesiredMoveDirectionSmoothRate;
|
||||
Vec2 m_vLocalDesiredMoveDirection;
|
||||
Vec2 m_vLocalDesiredMoveDirectionSmooth;
|
||||
Vec2 m_vLocalDesiredMoveDirectionSmoothRate;
|
||||
Vec2 m_vWorldAimBodyDirection;
|
||||
|
||||
f32 m_udGround;
|
||||
f32 m_lrGround;
|
||||
OBB m_GroundOBB;
|
||||
Vec3 m_GroundOBBPos;
|
||||
|
||||
// Index of camera objects.
|
||||
mutable GUID m_cameraObjectId = GUID_NULL;
|
||||
mutable AZ::EntityId m_viewEntityId;
|
||||
mutable ViewSourceType m_viewSourceType = ViewSourceType::None;
|
||||
AZ::EntityId m_viewEntityIdCachedForEditMode;
|
||||
Matrix34 m_preGameModeViewTM;
|
||||
uint m_disableRenderingCount = 0;
|
||||
bool m_bLockCameraMovement;
|
||||
bool m_bUpdateViewport = false;
|
||||
bool m_bMoveCameraObject = true;
|
||||
|
||||
enum class KeyPressedState
|
||||
{
|
||||
AllUp,
|
||||
PressedThisFrame,
|
||||
PressedInPreviousFrame,
|
||||
};
|
||||
KeyPressedState m_pressedKeyState = KeyPressedState::AllUp;
|
||||
|
||||
Matrix34 m_defaultViewTM;
|
||||
const QString m_defaultViewName;
|
||||
|
||||
DisplayContext m_displayContext;
|
||||
|
||||
|
||||
bool m_isOnPaint = false;
|
||||
static CRenderViewport* m_pPrimaryViewport;
|
||||
|
||||
QRect m_safeFrame;
|
||||
QRect m_safeAction;
|
||||
QRect m_safeTitle;
|
||||
|
||||
CPredefinedAspectRatios m_predefinedAspectRatios;
|
||||
|
||||
IVariable* m_pCameraFOVVariable = nullptr;
|
||||
bool m_bCursorHidden = false;
|
||||
|
||||
void OnMenuResolutionCustom();
|
||||
void OnMenuCreateCameraEntityFromCurrentView();
|
||||
void OnMenuSelectCurrentCamera();
|
||||
|
||||
int OnCreate();
|
||||
void resizeEvent(QResizeEvent* event) override;
|
||||
void paintEvent(QPaintEvent* event) override;
|
||||
void mousePressEvent(QMouseEvent* event) override;
|
||||
void OnLButtonDown(Qt::KeyboardModifiers modifiers, const QPoint& point) override;
|
||||
void OnLButtonUp(Qt::KeyboardModifiers modifiers, const QPoint& point) override;
|
||||
void OnLButtonDblClk(Qt::KeyboardModifiers modifiers, const QPoint& point) override;
|
||||
void OnMButtonDown(Qt::KeyboardModifiers modifiers, const QPoint& point) override;
|
||||
void OnMButtonUp(Qt::KeyboardModifiers modifiers, const QPoint& point) override;
|
||||
void OnRButtonDown(Qt::KeyboardModifiers modifiers, const QPoint& point) override;
|
||||
void OnRButtonUp(Qt::KeyboardModifiers modifiers, const QPoint& point) override;
|
||||
void OnMouseMove(Qt::KeyboardModifiers modifiers, Qt::MouseButtons buttons, const QPoint& point) override;
|
||||
void OnMouseWheel(Qt::KeyboardModifiers modifiers, short zDelta, const QPoint& pt) override;
|
||||
|
||||
// From a series of input primitives, compose a complete mouse interaction.
|
||||
AzToolsFramework::ViewportInteraction::MouseInteraction BuildMouseInteractionInternal(
|
||||
AzToolsFramework::ViewportInteraction::MouseButtons buttons,
|
||||
AzToolsFramework::ViewportInteraction::KeyboardModifiers modifiers,
|
||||
const AzToolsFramework::ViewportInteraction::MousePick& mousePick) const;
|
||||
// Given a point in the viewport, return the pick ray into the scene.
|
||||
// note: The argument passed to parameter **point**, originating
|
||||
// from a Qt event, must first be passed to WidgetToViewport before being
|
||||
// passed to BuildMousePick.
|
||||
AzToolsFramework::ViewportInteraction::MousePick BuildMousePick(const QPoint& point);
|
||||
|
||||
bool event(QEvent* event) override;
|
||||
void OnDestroy();
|
||||
|
||||
bool CheckRespondToInput() const;
|
||||
|
||||
// AzFramework::InputSystemCursorConstraintRequestBus
|
||||
void* GetSystemCursorConstraintWindow() const override;
|
||||
|
||||
void BuildDragDropContext(AzQtComponents::ViewportDragContext& context, const QPoint& pt) override;
|
||||
|
||||
private:
|
||||
void ProcessKeyRelease(QKeyEvent* event);
|
||||
void PushDisableRendering();
|
||||
void PopDisableRendering();
|
||||
bool IsRenderingDisabled() const;
|
||||
AzToolsFramework::ViewportInteraction::MousePick BuildMousePickInternal(
|
||||
const QPoint& point) const;
|
||||
|
||||
void RestoreViewportAfterGameMode();
|
||||
|
||||
double WidgetToViewportFactor() const
|
||||
{
|
||||
#if defined(AZ_PLATFORM_WINDOWS)
|
||||
// Needed for high DPI mode on windows
|
||||
return devicePixelRatioF();
|
||||
#else
|
||||
return 1.0f;
|
||||
#endif
|
||||
}
|
||||
|
||||
void BeginUndoTransaction() override;
|
||||
void EndUndoTransaction() override;
|
||||
|
||||
void UpdateCurrentMousePos(const QPoint& newPosition);
|
||||
|
||||
AzFramework::EntityVisibilityQuery m_entityVisibilityQuery;
|
||||
|
||||
SPreviousContext m_previousContext;
|
||||
QSet<int> m_keyDown;
|
||||
|
||||
bool m_freezeViewportInput = false;
|
||||
|
||||
size_t m_cameraSetForWidgetRenderingCount = 0; ///< How many calls to PreWidgetRendering happened before
|
||||
///< subsequent calls to PostWidetRendering.
|
||||
AZStd::shared_ptr<AzToolsFramework::ManipulatorManager> m_manipulatorManager;
|
||||
|
||||
// Used to prevent circular set camera events
|
||||
bool m_ignoreSetViewFromEntityPerspective = false;
|
||||
bool m_windowResizedEvent = false;
|
||||
|
||||
// Cache hwnd value for teardown to avoid infinite loops in retrieving it from destroyed widgets.
|
||||
HWND m_hwnd;
|
||||
|
||||
AZStd::unique_ptr<EditorEntityNotifications> m_editorEntityNotifications;
|
||||
|
||||
AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING
|
||||
};
|
||||
|
||||
#endif // CRYINCLUDE_EDITOR_RENDERVIEWPORT_H
|
||||
@ -1,202 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project.
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
// Description : Tagged files database for 'SmartFileOpen' dialog
|
||||
|
||||
#include "EditorDefs.h"
|
||||
|
||||
#include "IndexedFiles.h"
|
||||
|
||||
volatile TIntAtomic CIndexedFiles::s_bIndexingDone;
|
||||
CIndexedFiles* CIndexedFiles::s_pIndexedFiles = nullptr;
|
||||
|
||||
bool CIndexedFiles::m_startedFileIndexing = false;
|
||||
|
||||
void CIndexedFiles::Initialize(const QString& path, IFileUtil::ScanDirectoryUpdateCallBack updateCB)
|
||||
{
|
||||
m_files.clear();
|
||||
m_pathToIndex.clear();
|
||||
m_tags.clear();
|
||||
m_rootPath = path;
|
||||
|
||||
bool anyFiles = CFileUtil::ScanDirectory(path, "*.*", m_files, true, true, updateCB);
|
||||
|
||||
if (anyFiles == false)
|
||||
{
|
||||
m_files.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
if (updateCB)
|
||||
{
|
||||
updateCB("Parsing & tagging...");
|
||||
}
|
||||
|
||||
for (int i = 0; i < m_files.size(); ++i)
|
||||
{
|
||||
m_pathToIndex[m_files[i].filename] = i;
|
||||
}
|
||||
|
||||
PrepareTagTable();
|
||||
|
||||
InvokeUpdateCallbacks();
|
||||
}
|
||||
|
||||
void CIndexedFiles::AddFile(const IFileUtil::FileDesc& path)
|
||||
{
|
||||
assert(m_pathToIndex.find(path.filename) == m_pathToIndex.end());
|
||||
m_files.push_back(path);
|
||||
m_pathToIndex[path.filename] = m_files.size() - 1;
|
||||
QStringList tags;
|
||||
GetTags(tags, path.filename);
|
||||
for (int k = 0; k < tags.size(); ++k)
|
||||
{
|
||||
m_tags[tags[k]].insert(m_files.size() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
void CIndexedFiles::RemoveFile(const QString& path)
|
||||
{
|
||||
if (m_pathToIndex.find(path) == m_pathToIndex.end())
|
||||
{
|
||||
return;
|
||||
}
|
||||
std::map<QString, int>::iterator itr = m_pathToIndex.find(path);
|
||||
int index = itr->second;
|
||||
m_pathToIndex.erase(itr);
|
||||
m_files.erase(m_files.begin() + index);
|
||||
QStringList tags;
|
||||
GetTags(tags, path);
|
||||
for (int k = 0; k < tags.size(); ++k)
|
||||
{
|
||||
m_tags[tags[k]].erase(index);
|
||||
}
|
||||
}
|
||||
|
||||
void CIndexedFiles::Refresh(const QString& path, bool recursive)
|
||||
{
|
||||
IFileUtil::FileArray files;
|
||||
bool anyFiles = CFileUtil::ScanDirectory(m_rootPath, Path::Make(path, "*.*"), files, recursive, recursive ? true : false);
|
||||
|
||||
if (anyFiles == false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < files.size(); ++i)
|
||||
{
|
||||
if (m_pathToIndex.find(files[i].filename) == m_pathToIndex.end())
|
||||
{
|
||||
AddFile(files[i]);
|
||||
}
|
||||
}
|
||||
|
||||
InvokeUpdateCallbacks();
|
||||
}
|
||||
|
||||
void CIndexedFiles::GetFilesWithTags(IFileUtil::FileArray& files, const QStringList& tags) const
|
||||
{
|
||||
files.clear();
|
||||
if (tags.empty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
int_set candidates;
|
||||
TagTable::const_iterator i;
|
||||
// Gets candidate files from the first tag.
|
||||
for (i = m_tags.begin(); i != m_tags.end(); ++i)
|
||||
{
|
||||
if (i->first.startsWith(tags[0]))
|
||||
{
|
||||
candidates.insert(i->second.begin(), i->second.end());
|
||||
}
|
||||
}
|
||||
// Reduces the candidates further using additional tags, if any.
|
||||
for (int k = 1; k < tags.size(); ++k)
|
||||
{
|
||||
// Gathers the filter set.
|
||||
int_set filter;
|
||||
for (i = m_tags.begin(); i != m_tags.end(); ++i)
|
||||
{
|
||||
if (i->first.startsWith(tags[k]))
|
||||
{
|
||||
filter.insert(i->second.begin(), i->second.end());
|
||||
}
|
||||
}
|
||||
|
||||
// Filters the candidates using it.
|
||||
for (int_set::iterator m = candidates.begin(); m != candidates.end(); )
|
||||
{
|
||||
if (filter.find(*m) == filter.end())
|
||||
{
|
||||
int_set::iterator target = m;
|
||||
++m;
|
||||
candidates.erase(target);
|
||||
}
|
||||
else
|
||||
{
|
||||
++m;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Outputs the result.
|
||||
files.reserve(candidates.size());
|
||||
for (int_set::const_iterator m = candidates.begin(); m != candidates.end(); ++m)
|
||||
{
|
||||
files.push_back(m_files[*m]);
|
||||
}
|
||||
}
|
||||
|
||||
void CIndexedFiles::GetTags(QStringList& tags, const QString& path) const
|
||||
{
|
||||
tags = path.split(QRegularExpression(QStringLiteral(R"([\\/.])")), Qt::SkipEmptyParts);
|
||||
}
|
||||
|
||||
void CIndexedFiles::GetTagsOfPrefix(QStringList& tags, const QString& prefix) const
|
||||
{
|
||||
tags.clear();
|
||||
TagTable::const_iterator i;
|
||||
for (i = m_tags.begin(); i != m_tags.end(); ++i)
|
||||
{
|
||||
if (i->first.startsWith(prefix))
|
||||
{
|
||||
tags.push_back(i->first);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CIndexedFiles::PrepareTagTable()
|
||||
{
|
||||
QStringList tags;
|
||||
for (int i = 0; i < m_files.size(); ++i)
|
||||
{
|
||||
GetTags(tags, m_files[i].filename);
|
||||
for (int k = 0; k < tags.size(); ++k)
|
||||
{
|
||||
m_tags[tags[k]].insert(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CIndexedFiles::AddUpdateCallback(std::function<void()> updateCallback)
|
||||
{
|
||||
CryAutoLock<CryMutex> lock(m_updateCallbackMutex);
|
||||
|
||||
m_updateCallbacks.push_back(updateCallback);
|
||||
}
|
||||
|
||||
void CIndexedFiles::InvokeUpdateCallbacks()
|
||||
{
|
||||
CryAutoLock<CryMutex> lock(m_updateCallbackMutex);
|
||||
|
||||
for (auto updateCallback : m_updateCallbacks)
|
||||
{
|
||||
updateCallback();
|
||||
}
|
||||
}
|
||||
@ -1,176 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project.
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
// Description : Tagged files database for 'SmartFileOpen' dialog
|
||||
//
|
||||
// Notice : Refer SmartFileOpenDialog h
|
||||
|
||||
|
||||
#ifndef CRYINCLUDE_EDITOR_UTIL_INDEXEDFILES_H
|
||||
#define CRYINCLUDE_EDITOR_UTIL_INDEXEDFILES_H
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "FileUtil.h"
|
||||
#include <functional>
|
||||
|
||||
class CIndexedFiles
|
||||
{
|
||||
friend class CFileIndexingThread;
|
||||
public:
|
||||
static CIndexedFiles& GetDB()
|
||||
{
|
||||
if (!s_pIndexedFiles)
|
||||
{
|
||||
assert(!"CIndexedFiles not created! Make sure you use CIndexedFiles::GetDB() after CIndexedFiles::StartFileIndexing() is called.");
|
||||
}
|
||||
assert(s_pIndexedFiles);
|
||||
return *s_pIndexedFiles;
|
||||
}
|
||||
|
||||
static bool HasFileIndexingDone()
|
||||
{ return s_bIndexingDone > 0; }
|
||||
|
||||
static void Create()
|
||||
{
|
||||
assert(!s_pIndexedFiles);
|
||||
s_pIndexedFiles = new CIndexedFiles;
|
||||
}
|
||||
|
||||
static void Destroy()
|
||||
{
|
||||
SAFE_DELETE(s_pIndexedFiles);
|
||||
}
|
||||
|
||||
static void StartFileIndexing()
|
||||
{
|
||||
assert(s_bIndexingDone == 0);
|
||||
assert(s_pIndexedFiles);
|
||||
|
||||
if (!s_pIndexedFiles)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
GetFileIndexingThread().Start(-1, "FileIndexing");
|
||||
m_startedFileIndexing = true;
|
||||
}
|
||||
|
||||
static void AbortFileIndexing()
|
||||
{
|
||||
if (!m_startedFileIndexing)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (HasFileIndexingDone() == false)
|
||||
{
|
||||
GetFileIndexingThread().Abort();
|
||||
}
|
||||
m_startedFileIndexing = false;
|
||||
}
|
||||
|
||||
static void RegisterCallback(std::function<void()> callback)
|
||||
{
|
||||
assert(s_pIndexedFiles);
|
||||
if (!s_pIndexedFiles)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
s_pIndexedFiles->AddUpdateCallback(callback);
|
||||
}
|
||||
|
||||
public:
|
||||
void Initialize(const QString& path, IFileUtil::ScanDirectoryUpdateCallBack updateCB = nullptr);
|
||||
|
||||
// Adds a new file to the database.
|
||||
void AddFile(const IFileUtil::FileDesc& path);
|
||||
// Removes a no-longer-existing file from the database.
|
||||
void RemoveFile(const QString& path);
|
||||
// Refreshes this database for the subdirectory.
|
||||
void Refresh(const QString& path, bool recursive = true);
|
||||
|
||||
void GetFilesWithTags(IFileUtil::FileArray& files, const QStringList& tags) const;
|
||||
|
||||
//! This method returns all the tags which start with a given prefix.
|
||||
//! It is useful for the tag auto-completion.
|
||||
void GetTagsOfPrefix(QStringList& tags, const QString& prefix) const;
|
||||
|
||||
uint32 GetTotalCount() const
|
||||
{ return (uint32)m_files.size(); }
|
||||
|
||||
private:
|
||||
static bool m_startedFileIndexing;
|
||||
|
||||
std::vector <std::function<void()> > m_updateCallbacks;
|
||||
IFileUtil::FileArray m_files;
|
||||
std::map<QString, int> m_pathToIndex;
|
||||
typedef std::set<int, std::less<int> > int_set;
|
||||
typedef std::map<QString, int_set, std::less<QString> > TagTable;
|
||||
TagTable m_tags;
|
||||
QString m_rootPath;
|
||||
|
||||
void GetTags(QStringList& tags, const QString& path) const;
|
||||
void PrepareTagTable();
|
||||
|
||||
CryMutex m_updateCallbackMutex;
|
||||
|
||||
void AddUpdateCallback(std::function<void()> updateCallback);
|
||||
void InvokeUpdateCallbacks();
|
||||
|
||||
// A done flag for the background file indexing
|
||||
static volatile TIntAtomic s_bIndexingDone;
|
||||
// A thread for the background file indexing
|
||||
class CFileIndexingThread
|
||||
: public CryThread<CFileIndexingThread>
|
||||
{
|
||||
public:
|
||||
virtual void Run()
|
||||
{
|
||||
CIndexedFiles::GetDB().Initialize("@assets@", CallBack);
|
||||
CryInterlockedAdd(CIndexedFiles::s_bIndexingDone.Addr(), 1);
|
||||
}
|
||||
|
||||
CFileIndexingThread()
|
||||
: m_abort(false) {}
|
||||
|
||||
void Abort()
|
||||
{
|
||||
m_abort = true;
|
||||
WaitForThread();
|
||||
}
|
||||
|
||||
virtual ~CFileIndexingThread()
|
||||
{
|
||||
Abort();
|
||||
}
|
||||
private:
|
||||
bool m_abort;
|
||||
static bool CallBack([[maybe_unused]] const QString& msg)
|
||||
{
|
||||
if (CIndexedFiles::GetFileIndexingThread().m_abort)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
static CFileIndexingThread& GetFileIndexingThread()
|
||||
{
|
||||
static CFileIndexingThread s_fileIndexingThread;
|
||||
|
||||
return s_fileIndexingThread;
|
||||
}
|
||||
|
||||
// A global database for tagged files
|
||||
static CIndexedFiles* s_pIndexedFiles;
|
||||
};
|
||||
#endif // CRYINCLUDE_EDITOR_UTIL_INDEXEDFILES_H
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue