diff --git a/Code/CryEngine/CryCommon/CREBaseCloud.h b/Code/CryEngine/CryCommon/CREBaseCloud.h deleted file mode 100644 index b7a95d88d4..0000000000 --- a/Code/CryEngine/CryCommon/CREBaseCloud.h +++ /dev/null @@ -1,158 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef __CREBASECLOUD_H__ -#define __CREBASECLOUD_H__ - -//================================================================================ - -class SCloudParticle -{ -public: - inline SCloudParticle(); - inline SCloudParticle(const Vec3& vPos, float fRadius, const ColorF& baseColor, float fTransparency = 0); - inline SCloudParticle(const Vec3& vPos, float fRadiusX, float fRadiusY, float fRotMin, float fRotMax, Vec2 vUV[]); - inline ~SCloudParticle(); - - float GetRadiusX() const { return m_fSize[0]; } - float GetRadiusY() const { return m_fSize[1]; } - float GetTransparency() const { return m_fTransparency; } - const Vec3& GetPosition() const { return m_vPosition; } - const ColorF& GetBaseColor() const { return m_vBaseColor; } - uint32 GetNumLitColors() const { return m_vLitColors.size(); } - inline const ColorF GetLitColor(unsigned int index) const; - float GetSquareSortDistance() const { return m_fSquareSortDistance; } - - //! Sets the radius of the particle. - void SetRadiusX(float rad) { m_fSize[0] = rad; } - void SetRadiusY(float rad) { m_fSize[1] = rad; } - void SetTransparency(float trans) { m_fTransparency = trans; } - void SetPosition(const Vec3& pos) { m_vPosition = pos; } - void SetBaseColor(const ColorF& col) { m_vBaseColor = col; } - void AddLitColor(const ColorF& col) { m_vLitColors.push_back(col); } - void ClearLitColors() { m_vLitColors.clear(); } - void SetSquareSortDistance(float fSquareDistance) { m_fSquareSortDistance = fSquareDistance; } - - bool operator<(const SCloudParticle& p) const - { - return (m_fSquareSortDistance < p.m_fSquareSortDistance); - } - - bool operator>(const SCloudParticle& p) const - { - return (m_fSquareSortDistance > p.m_fSquareSortDistance); - } - -protected: - float m_fTransparency; - Vec3 m_vPosition; - float m_fSize[2]; - float m_fRotMin; - float m_fRotMax; - ColorF m_vBaseColor; - TArray m_vLitColors; - Vec3 m_vEye; - - // for sorting particles during shading - float m_fSquareSortDistance; -public: - Vec2 m_vUV[2]; -}; - -inline SCloudParticle::SCloudParticle() -{ - m_fSize[0] = 0; - m_fTransparency = 0; - m_vPosition = Vec3(0, 0, 0); - m_vBaseColor = Col_Black; - m_vEye = Vec3(0, 0, 0); - m_fSquareSortDistance = 0; - - m_vLitColors.clear(); -} - -inline SCloudParticle::SCloudParticle(const Vec3& pos, float fRadius, const ColorF& baseColor, float fTransparency) -{ - m_fSize[0] = fRadius; - m_fSize[1] = fRadius; - m_fTransparency = fTransparency; - m_vPosition = pos; - m_vBaseColor = baseColor; - m_vUV[0] = Vec2(0, 0); - m_vUV[1] = Vec2(1, 1); - - m_fRotMin = 0; - m_fRotMax = 0; - m_vEye = Vec3(0, 0, 0); - m_fSquareSortDistance = 0; - - m_vLitColors.clear(); -} - -inline SCloudParticle::SCloudParticle(const Vec3& vPos, float fRadiusX, float fRadiusY, float fRotMin, float fRotMax, Vec2 vUV[2]) -{ - m_fSize[0] = fRadiusX; - m_fSize[1] = fRadiusY; - m_vPosition = vPos; - m_vBaseColor = Col_White; - m_vUV[0] = vUV[0]; - m_vUV[1] = vUV[1]; - m_fRotMin = fRotMin; - m_fRotMax = fRotMax; - - m_fTransparency = 1.0f; - m_vEye = Vec3(0, 0, 0); - m_fSquareSortDistance = 0; - - m_vLitColors.clear(); -} - -inline SCloudParticle::~SCloudParticle() -{ - m_vLitColors.clear(); -} - -inline const ColorF SCloudParticle::GetLitColor(unsigned int index) const -{ - if (index <= m_vLitColors.size()) - { - return m_vLitColors[index]; - } - else - { - return Col_Black; - } -} - -//=========================================================================== -class CREBaseCloud - : public CRendElementBase -{ - friend class CRECloud; - -public: - CREBaseCloud() - : CRendElementBase() - { - mfSetType(eDATA_Cloud); - mfUpdateFlags(FCEF_TRANSFORM); - } - virtual void SetParticles(SCloudParticle* pParticles, int nNumParticles) = 0; - - virtual void GetMemoryUsage(ICrySizer* pSizer) const - { - pSizer->AddObject(this, sizeof(*this)); - } -}; - -#endif // __CREBASECLOUD_H__ diff --git a/Code/CryEngine/CryCommon/CREFogVolume.h b/Code/CryEngine/CryCommon/CREFogVolume.h deleted file mode 100644 index 83a024d15e..0000000000 --- a/Code/CryEngine/CryCommon/CREFogVolume.h +++ /dev/null @@ -1,66 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. -#ifndef _CREFOGVOLUME_ -#define _CREFOGVOLUME_ - -#pragma once - -#include "VertexFormats.h" - - -struct IFogVolumeRenderNode; - - -class CREFogVolume - : public CRendElementBase -{ -public: - CREFogVolume(); - - virtual ~CREFogVolume(); - virtual void mfPrepare(bool bCheckOverflow); - virtual bool mfDraw(CShader* ef, SShaderPass* sfm); - - virtual void GetMemoryUsage(ICrySizer* pSizer) const - { - pSizer->AddObject(this, sizeof(*this)); - } - - Vec3 m_center; - uint32 m_viewerInsideVolume : 1; - uint32 m_affectsThisAreaOnly : 1; - uint32 m_stencilRef : 8; - uint32 m_volumeType : 1; - uint32 m_reserved : 21; - AABB m_localAABB; - Matrix34 m_matWSInv; - float m_globalDensity; - float m_densityOffset; - float m_nearCutoff; - Vec2 m_softEdgesLerp; - ColorF m_fogColor; // color already combined with fHDRDynamic - Vec3 m_heightFallOffDirScaled; - Vec3 m_heightFallOffBasePoint; - Vec3 m_eyePosInWS; - Vec3 m_eyePosInOS; - Vec3 m_rampParams; - Vec3 m_windOffset; - float m_noiseScale; - Vec3 m_noiseFreq; - float m_noiseOffset; - float m_noiseElapsedTime; - Vec3 m_scale; -}; - - -#endif // #ifndef _CREFOGVOLUME_ diff --git a/Code/CryEngine/CryCommon/CREGameEffect.h b/Code/CryEngine/CryCommon/CREGameEffect.h deleted file mode 100644 index 17e68813ed..0000000000 --- a/Code/CryEngine/CryCommon/CREGameEffect.h +++ /dev/null @@ -1,63 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. -#ifndef _CREGameEffect_ -#define _CREGameEffect_ - -#pragma once - -//================================================================================================== -// Name: IREGameEffect -// Desc: Interface for game effect render elements, designed to be instantiated in game code, and -// called from the CREGameEffect within the engine. This then allows render elements -// to be created in game code as well as in the engine. -// Author: James Chilvers -//================================================================================================== -struct IREGameEffect -{ - virtual ~IREGameEffect(){} - - virtual void mfPrepare(bool bCheckOverflow) = 0; - virtual bool mfDraw(CShader* ef, SShaderPass* sfm, CRenderObject* renderObj) = 0; -};//------------------------------------------------------------------------------------------------ - -//================================================================================================== -// Name: CREGameEffect -// Desc: Render element that uses the IREGameEffect interface for its functionality -// Author: James Chilvers -//================================================================================================== -class CREGameEffect - : public CRendElementBase -{ -public: - - CREGameEffect(); - ~CREGameEffect(); - - // CRendElementBase interface - void mfPrepare(bool bCheckOverflow); - bool mfDraw(CShader* ef, SShaderPass* sfm); - - // CREGameEffect interface - inline void SetPrivateImplementation(IREGameEffect* pImpl) { m_pImpl = pImpl; } - inline IREGameEffect* GetPrivateImplementation() const { return m_pImpl; } - - virtual void GetMemoryUsage(ICrySizer* pSizer) const - { - pSizer->AddObject(this, sizeof(*this)); - } -private: - - IREGameEffect* m_pImpl; // Implementation of of render element -};//------------------------------------------------------------------------------------------------ - -#endif // #ifndef _CREGameEffect_ diff --git a/Code/CryEngine/CryCommon/CREGeomCache.h b/Code/CryEngine/CryCommon/CREGeomCache.h deleted file mode 100644 index 6911b8486e..0000000000 --- a/Code/CryEngine/CryCommon/CREGeomCache.h +++ /dev/null @@ -1,95 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// Description : Backend part of geometry cache rendering - -#ifndef CRYINCLUDE_CRYCOMMON_CREGEOMCACHE_H -#define CRYINCLUDE_CRYCOMMON_CREGEOMCACHE_H -#pragma once - -#if defined(USE_GEOM_CACHES) - -#include -#include - -class CREGeomCache - : public CRendElementBase -{ -public: - struct SMeshInstance - { - AABB m_aabb; - Matrix34 m_matrix; - Matrix34 m_prevMatrix; - }; - - struct SMeshRenderData - { - DynArray m_instances; - _smart_ptr m_pRenderMesh; - }; - - struct UpdateList - { - CryCriticalSection m_mutex; - AZStd::vector> m_geoms; - }; - -public: - CREGeomCache(); - ~CREGeomCache(); - - bool Update(const int flags, const bool bTesselation); - static void UpdateModified(); - - // CRendElementBase interface - virtual bool mfUpdate(int Flags, bool bTessellation); - virtual void mfPrepare(bool bCheckOverflow); - virtual bool mfDraw(CShader* ef, SShaderPass* sfm); - - // CREGeomCache interface - virtual void InitializeRenderElement(const uint numMeshes, _smart_ptr* pMeshes, uint16 materialId); - virtual void SetupMotionBlur(CRenderObject* pRenderObject, const SRenderingPassInfo& passInfo); - - virtual volatile int* SetAsyncUpdateState(int& threadId); - virtual DynArray* GetMeshFillDataPtr(); - virtual DynArray* GetRenderDataPtr(); - virtual void DisplayFilledBuffer(const int threadId); - - - AZ::Vertex::Format GetVertexFormat() const override; - bool GetGeometryInfo(SGeometryInfo &streams) override; - -private: - uint16 m_materialId; - volatile bool m_bUpdateFrame[2]; - volatile int m_transformUpdateState[2]; - - // We use a double buffered m_meshFillData array for input from the main thread. When data - // was successfully sent from the main thread it gets copied to m_meshRenderData - // This simplifies the cases where frame data is missing, e.g. meshFillData is not updated for a frame - // Note that meshFillData really needs to be double buffered because the copy occurs in render thread - // so the next main thread could already be touching the data again - // - // Note: m_meshRenderData is directly accessed for ray intersections via GetRenderDataPtr. - // This is safe, because it's only used in editor. - DynArray m_meshFillData[2]; - DynArray m_meshRenderData; - - static StaticInstance sm_updateList[2]; // double buffered update lists - - AZ::Vertex::Format m_geomCacheVertexFormat; -}; - -#endif -#endif // CRYINCLUDE_CRYCOMMON_CREGEOMCACHE_H diff --git a/Code/CryEngine/CryCommon/CREImposter.h b/Code/CryEngine/CryCommon/CREImposter.h deleted file mode 100644 index 1150212b7d..0000000000 --- a/Code/CryEngine/CryCommon/CREImposter.h +++ /dev/null @@ -1,194 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#pragma once - -#include -#include "Cry_Camera.h" - -//================================================================================ - -struct SDynTexture2; -struct SDynTexture; -class IDynTexture; -class CameraViewParameters; - -struct IImposterRenderElement -{ - virtual void GetMemoryUsage(ICrySizer* pSizer) const = 0; - virtual void mfPrepare(bool bCheckOverflow) = 0; - virtual bool mfDraw(CShader* ef, SShaderPass* sl) = 0; - virtual const SMinMaxBox& mfGetWorldSpaceBounds() = 0; - - virtual bool IsSplit() = 0; - virtual bool IsScreenImposter() = 0; - - virtual float GetRadiusX() = 0; - virtual float GetRadiusY() = 0; - virtual Vec3* GetQuadCorners() = 0; - virtual Vec3 GetNearPoint() = 0; - virtual Vec3 GetFarPoint() = 0; - virtual float GetErrorToleranceCosAngle() = 0; - virtual uint32 GetState() = 0; - virtual int GetAlphaRef() = 0; - virtual ColorF GetColorHelper() = 0; - virtual Vec3 GetLastSunDirection() = 0; - virtual uint8 GetLastBestEdge() = 0; - virtual float GetNear() = 0; - virtual float GetFar() = 0; - virtual float GetTransparency() = 0; - virtual Vec3 GetPosition(); - virtual int GetLogResolutionX() = 0; - virtual int GetLogResolutionY() = 0; - virtual CameraViewParameters& GetLastViewParameters() = 0; - virtual IDynTexture* GetTexture() = 0; - virtual IDynTexture* GetScreenTexture() = 0; - virtual IDynTexture* GetFrontTexture() = 0; - virtual IDynTexture* GetDepthTexture() = 0; - virtual const SMinMaxBox& GetWorldSpaceBounds() = 0; - - virtual void SetBBox(const Vec3& min, const Vec3& max) = 0; - virtual void SetScreenImposterState(bool state) = 0; - virtual void SetState(uint32 state) = 0; - virtual void SetAlphaRef(uint32 ref) = 0; - virtual void SetPosition(Vec3 pos) = 0; - virtual void SetFrameResetValue(int frameResetValue) = 0; - virtual void SetTexture(IDynTexture* texture) = 0; - virtual void SetScreenTexture(IDynTexture* texture) = 0; - virtual void SetFrontTexture(IDynTexture* texture) = 0; - virtual void SetDepthTexture(IDynTexture* texture) = 0; -}; - -class CREImposter - : public CRendElementBase -{ - friend class CRECloud; - static IDynTexture* m_pScreenTexture; - - CameraViewParameters m_LastViewParameters; - bool m_bScreenImposter; - bool m_bSplit; - float m_fRadiusX; - float m_fRadiusY; - Vec3 m_vQuadCorners[4]; // in world space, relative to m_vPos, in clockwise order, can be rotated - Vec3 m_vNearPoint; - Vec3 m_vFarPoint; - int m_nLogResolutionX; - int m_nLogResolutionY; - IDynTexture* m_pTexture; - IDynTexture* m_pFrontTexture; - IDynTexture* m_pTextureDepth; - float m_fErrorToleranceCosAngle; // cosine of m_fErrorToleranceAngle used to check if IsImposterValid - SMinMaxBox m_WorldSpaceBV; - uint32 m_State; - int m_AlphaRef; - float m_fCurTransparency; - ColorF m_ColorHelper; - Vec3 m_vPos; - Vec3 m_vLastSunDir; - uint8 m_nLastBestEdge; // 0..11 this edge is favored to not jitter between different edges - float m_fNear; - float m_fFar; - - bool IsImposterValid(const CameraViewParameters& viewParameters, float fRadiusX, float fRadiusY, float fCamRadiusX, float fCamRadiusY, - const int iRequiredLogResX, const int iRequiredLogResY, const uint32 dwBestEdge); - - bool Display(bool bDisplayFrontOfSplit); - -public: - int m_nFrameReset; - int m_FrameUpdate; - float m_fTimeUpdate; - - static int m_MemUpdated; - static int m_MemPostponed; - static int m_PrevMemUpdated; - static int m_PrevMemPostponed; - - CREImposter() - : CRendElementBase() - , m_pTexture(NULL) - , m_pFrontTexture(NULL) - , m_pTextureDepth(NULL) - , m_bSplit(false) - , m_fRadiusX(0) - , m_fRadiusY(0) - , m_fErrorToleranceCosAngle(cos(DEG2RAD(0.25f))) - , m_bScreenImposter(false) - , m_State(GS_DEPTHWRITE) - , m_AlphaRef(-1) - , m_fCurTransparency(1.0f) - , m_FrameUpdate(0) - , m_nFrameReset(0) - , m_fTimeUpdate(0) - , m_vLastSunDir(0, 0, 0) - , m_nLogResolutionX(0) - , m_nLogResolutionY(0) - , m_nLastBestEdge(0) - { - mfSetType(eDATA_Imposter); - mfUpdateFlags(FCEF_TRANSFORM); - m_ColorHelper = Col_White; - } - virtual ~CREImposter() - { - ReleaseResources(); - } - - bool UpdateImposter(); - void ReleaseResources(); - - bool PrepareForUpdate(); - - virtual void GetMemoryUsage(ICrySizer* pSizer) const - { - pSizer->AddObject(this, sizeof(*this)); - } - virtual void mfPrepare(bool bCheckOverflow); - virtual bool mfDraw(CShader* ef, SShaderPass* sl); - const SMinMaxBox& mfGetWorldSpaceBounds() { return m_WorldSpaceBV; } - - virtual bool IsSplit() { return m_bSplit; } - virtual bool IsScreenImposter() { return m_bScreenImposter; } - - virtual float GetRadiusX() { return m_fRadiusX; } - virtual float GetRadiusY() { return m_fRadiusY; } - virtual Vec3* GetQuadCorners() { return &m_vQuadCorners[0]; } - virtual Vec3 GetNearPoint() { return m_vNearPoint; } - virtual Vec3 GetFarPoint() { return m_vFarPoint; } - virtual float GetErrorToleranceCosAngle() { return m_fErrorToleranceCosAngle; } - virtual uint32 GetState() { return m_State; } - virtual int GetAlphaRef() { return m_AlphaRef; } - virtual ColorF GetColorHelper() { return m_ColorHelper; } - virtual Vec3 GetLastSunDirection() { return m_vLastSunDir; } - virtual uint8 GetLastBestEdge() { return m_nLastBestEdge; } - virtual float GetNear() { return m_fNear; } - virtual float GetFar() { return m_fFar; } - virtual float GetTransparency() { return m_fCurTransparency; } - virtual Vec3 GetPosition(); - virtual int GetLogResolutionX() { return m_nLogResolutionX; } - virtual int GetLogResolutionY() { return m_nLogResolutionY; } - virtual CameraViewParameters& GetLastViewParameters() { return m_LastViewParameters; } - virtual IDynTexture** GetTexture() { return &m_pTexture; } - virtual IDynTexture** GetScreenTexture() { return &m_pScreenTexture; } - virtual IDynTexture** GetFrontTexture() { return &m_pFrontTexture; } - virtual IDynTexture** GetDepthTexture() { return &m_pTextureDepth; } - virtual const SMinMaxBox& GetWorldSpaceBounds() { return m_WorldSpaceBV; } - virtual int GetFrameReset() { return m_nFrameReset; } - virtual void SetBBox(const Vec3& min, const Vec3& max) { m_WorldSpaceBV.SetMin(min); m_WorldSpaceBV.SetMax(max); } - virtual void SetScreenImposterState(bool state) { m_bScreenImposter = state; } - virtual void SetState(uint32 state) { m_State = state; } - virtual void SetAlphaRef(uint32 ref) { m_AlphaRef = ref; } - virtual void SetPosition(Vec3 pos) { m_vPos = pos; } - virtual void SetFrameResetValue(int frameResetValue) { m_nFrameReset = frameResetValue; } -}; diff --git a/Code/CryEngine/CryCommon/CREMesh.h b/Code/CryEngine/CryCommon/CREMesh.h deleted file mode 100644 index 40df816808..0000000000 --- a/Code/CryEngine/CryCommon/CREMesh.h +++ /dev/null @@ -1,57 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef __CREMESH_H__ -#define __CREMESH_H__ - -class CREMesh - : public CRendElementBase -{ -public: - - struct CRenderChunk* m_pChunk; - class CRenderMesh* m_pRenderMesh; - - // Copy of Chunk to avoid indirections - int32 m_nFirstIndexId; - int32 m_nNumIndices; - - uint32 m_nFirstVertId; - uint32 m_nNumVerts; - -protected: - CREMesh() - { - mfSetType(eDATA_Mesh); - mfUpdateFlags(FCEF_TRANSFORM); - - m_pChunk = NULL; - m_pRenderMesh = NULL; - m_nFirstIndexId = -1; - m_nNumIndices = -1; - m_nFirstVertId = 0; - m_nNumVerts = 0; - } - - virtual ~CREMesh() - { - } - - // Ideally should be declared and left unimplemented to prevent slicing at compile time - // but this would prevent auto code gen in renderer later on. - // To track potential slicing, uncomment the following (and their equivalent in CREMeshImpl) - //CREMesh(CREMesh&); - //CREMesh& operator=(CREMesh& rhs); -}; - -#endif // __CREMESH_H__ diff --git a/Code/CryEngine/CryCommon/CREOcclusionQuery.h b/Code/CryEngine/CryCommon/CREOcclusionQuery.h deleted file mode 100644 index 9350a74104..0000000000 --- a/Code/CryEngine/CryCommon/CREOcclusionQuery.h +++ /dev/null @@ -1,116 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef __CREOCCLUSIONQUERY_H__ -#define __CREOCCLUSIONQUERY_H__ - -#define SUPP_HMAP_OCCL -#define SUPP_HWOBJ_OCCL - -//============================================================= - -class CRenderMesh; - -class CREOcclusionQuery - : public CRendElementBase -{ - friend class CRender3D; - bool m_bSucceeded; -public: - - int m_nVisSamples; - int m_nCheckFrame; - int m_nDrawFrame; - Vec3 m_vBoxMin; - Vec3 m_vBoxMax; - - UINT_PTR m_nOcclusionID; // this will carry a pointer LPDIRECT3DQUERY9, so it needs to be 64-bit on Windows 64 - - CRenderMesh* m_pRMBox; - static uint32 m_nQueriesPerFrameCounter; - static uint32 m_nReadResultNowCounter; - static uint32 m_nReadResultTryCounter; - - CREOcclusionQuery() - { - m_nOcclusionID = 0; - - m_nVisSamples = 800 * 600; - m_nCheckFrame = 0; - m_nDrawFrame = 0; - m_vBoxMin = Vec3(0, 0, 0); - m_vBoxMax = Vec3(0, 0, 0); - m_pRMBox = NULL; - - mfSetType(eDATA_OcclusionQuery); - mfUpdateFlags(FCEF_TRANSFORM); - } - - bool RT_ReadResult_Try(uint32 nDefaultNumSamples); - - ILINE bool HasSucceeded() const { return m_bSucceeded; } - - virtual ~CREOcclusionQuery(); - - virtual void mfPrepare(bool bCheckOverflow); - virtual bool mfDraw(CShader* ef, SShaderPass* sfm); - virtual void mfReset(); - virtual bool mfReadResult_Try(uint32 nDefaultNumSamples = 1); - virtual bool mfReadResult_Now(); - - virtual void GetMemoryUsage(ICrySizer* pSizer) const - { - pSizer->AddObject(this, sizeof(*this)); - } -}; - -struct OcclusionTestClient -{ - OcclusionTestClient() - : nLastOccludedMainFrameID(0) - , nLastVisibleMainFrameID(0) - { -#ifdef SUPP_HMAP_OCCL - vLastVisPoint.Set(0, 0, 0); - nTerrainOccLastFrame = 0; -#endif -#ifdef SUPP_HWOBJ_OCCL - bOccluded = true; - pREOcclusionQuery = 0; -#endif - //nInstantTestRequested=0; - } -#ifdef SUPP_HWOBJ_OCCL - ~OcclusionTestClient() - { - if (pREOcclusionQuery) - { - pREOcclusionQuery->Release(false); - } - } -#endif - uint32 nLastVisibleMainFrameID, nLastOccludedMainFrameID; - uint32 nLastShadowCastMainFrameID, nLastNoShadowCastMainFrameID; -#ifdef SUPP_HMAP_OCCL - Vec3 vLastVisPoint; - int nTerrainOccLastFrame; -#endif -#ifdef SUPP_HWOBJ_OCCL - CREOcclusionQuery* pREOcclusionQuery; - uint8 bOccluded; -#endif - //uint8 nInstantTestRequested; -}; - - -#endif // CRYINCLUDE_CRYCOMMON_CREOCCLUSIONQUERY_H diff --git a/Code/CryEngine/CryCommon/CREPostProcess.h b/Code/CryEngine/CryCommon/CREPostProcess.h deleted file mode 100644 index 4803ae2166..0000000000 --- a/Code/CryEngine/CryCommon/CREPostProcess.h +++ /dev/null @@ -1,56 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_CRYCOMMON_CREPOSTPROCESS_H -#define CRYINCLUDE_CRYCOMMON_CREPOSTPROCESS_H -#pragma once - - -class CREPostProcess - : public CRendElementBase -{ - friend class CD3D9Renderer; - -public: - - CREPostProcess(); - virtual ~CREPostProcess(); - - virtual void mfPrepare(bool bCheckOverflow); - virtual bool mfDraw(CShader* ef, SShaderPass* sfm); - - // Use for setting numeric values, vec4 (colors, position, vectors, wtv), strings - virtual int mfSetParameter(const char* pszParam, float fValue, bool bForceValue = false) const; - virtual int mfSetParameterVec4(const char* pszParam, const Vec4& pValue, bool bForceValue = false) const; - virtual int mfSetParameterString(const char* pszParam, const char* pszArg) const; - - virtual void mfGetParameter(const char* pszParam, float& fValue) const; - virtual void mfGetParameterVec4(const char* pszParam, Vec4& pValue) const; - virtual void mfGetParameterString(const char* pszParam, const char*& pszArg) const; - - virtual int32 mfGetPostEffectID(const char* pPostEffectName) const; - - // Reset all post processing effects - virtual void Reset(bool bOnSpecChange = false); - virtual void mfReset() - { - Reset(); - } - - virtual void GetMemoryUsage(ICrySizer* pSizer) const - { - pSizer->AddObject(this, sizeof(*this)); - } -}; - -#endif // CRYINCLUDE_CRYCOMMON_CREPOSTPROCESS_H diff --git a/Code/CryEngine/CryCommon/CREPrismObject.h b/Code/CryEngine/CryCommon/CREPrismObject.h deleted file mode 100644 index 4ec290f1b9..0000000000 --- a/Code/CryEngine/CryCommon/CREPrismObject.h +++ /dev/null @@ -1,40 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. -#ifndef _CREPRISMOBJECT_ -#define _CREPRISMOBJECT_ - -#pragma once - -#if !defined(EXCLUDE_DOCUMENTATION_PURPOSE) - -class CREPrismObject - : public CRendElementBase -{ -public: - CREPrismObject(); - - virtual ~CREPrismObject() {} - virtual void mfPrepare(bool bCheckOverflow); - virtual bool mfDraw(CShader* ef, SShaderPass* sfm); - - virtual void GetMemoryUsage(ICrySizer* pSizer) const - { - pSizer->AddObject(this, sizeof(*this)); - } - - Vec3 m_center; -}; - -#endif // EXCLUDE_DOCUMENTATION_PURPOSE - -#endif // _CREPRISMOBJECT_ diff --git a/Code/CryEngine/CryCommon/CRESky.h b/Code/CryEngine/CryCommon/CRESky.h deleted file mode 100644 index 3dfc7d184f..0000000000 --- a/Code/CryEngine/CryCommon/CRESky.h +++ /dev/null @@ -1,92 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef __CRESKY_H__ -#define __CRESKY_H__ - -//============================================================= - -#include "VertexFormats.h" -#include - -struct SSkyLightRenderParams; - -class CRESky - : public CRendElementBase -{ - friend class CRender3D; - -public: - - float m_fTerrainWaterLevel; - float m_fSkyBoxStretching; - float m_fAlpha; - int m_nSphereListId; - -public: - CRESky(); - virtual ~CRESky(); - virtual void mfPrepare(bool bCheckOverflow); - virtual bool mfDraw(CShader* ef, SShaderPass* sfm); - - virtual void GetMemoryUsage(ICrySizer* pSizer) const - { - pSizer->AddObject(this, sizeof(*this)); - } - - AZ::Vertex::Format GetVertexFormat() const override; - bool GetGeometryInfo(SGeometryInfo& streams) override; - -private: - AZ::Vertex::Format m_skyVertexFormat; -}; - -class CREHDRSky - : public CRendElementBase -{ -public: - CREHDRSky(); - virtual ~CREHDRSky(); - virtual void mfPrepare(bool bCheckOverflow); - virtual bool mfDraw(CShader* ef, SShaderPass* sfm); - - virtual void GetMemoryUsage(ICrySizer* pSizer) const - { - pSizer->AddObject(this, sizeof(*this)); - } - - void GenerateSkyDomeTextures(int32 width, int32 height); - - virtual AZ::Vertex::Format GetVertexFormat() const override; - virtual bool GetGeometryInfo(SGeometryInfo& streams) override; - -public: - const SSkyLightRenderParams* m_pRenderParams; - int m_moonTexId; - class CTexture* m_pSkyDomeTextureMie; - class CTexture* m_pSkyDomeTextureRayleigh; - - static void SetCommonMoonParams(CShader* ef, bool bUseMoon = false); - -private: - void Init(); - -private: - int m_skyDomeTextureLastTimeStamp; - int m_frameReset; - class CStars* m_pStars; - AZ::Vertex::Format m_hdrSkyVertexFormat; -}; - - -#endif // __CRESKY_H__ diff --git a/Code/CryEngine/CryCommon/CREVolumeObject.h b/Code/CryEngine/CryCommon/CREVolumeObject.h deleted file mode 100644 index 2137053a8e..0000000000 --- a/Code/CryEngine/CryCommon/CREVolumeObject.h +++ /dev/null @@ -1,70 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. -#ifndef _CREVOLUMEOBJECT_ -#define _CREVOLUMEOBJECT_ - -#pragma once - -#include "VertexFormats.h" - - -struct IVolumeObjectRenderNode; - -struct IVolumeTexture -{ -public: - virtual ~IVolumeTexture() {} - virtual void Release() = 0; - virtual bool Create(unsigned int width, unsigned int height, unsigned int depth, unsigned char* pData) = 0; - virtual bool Update(unsigned int width, unsigned int height, unsigned int depth, const unsigned char* pData) = 0; - virtual int GetTexID() const = 0; - virtual uint32 GetWidth() const = 0; - virtual uint32 GetHeight() const = 0; - virtual uint32 GetDepth() const = 0; - virtual ITexture* GetTexture() const = 0; -}; - -class CREVolumeObject - : public CRendElementBase -{ -public: - CREVolumeObject(); - - virtual ~CREVolumeObject(); - virtual void mfPrepare(bool bCheckOverflow); - virtual bool mfDraw(CShader* ef, SShaderPass* sfm); - - virtual IVolumeTexture* CreateVolumeTexture() const; - - virtual void GetMemoryUsage(ICrySizer* pSizer) const - { - pSizer->AddObject(this, sizeof(*this)); - } - - Vec3 m_center; - Matrix34 m_matInv; - Vec3 m_eyePosInWS; - Vec3 m_eyePosInOS; - Plane_tpl m_volumeTraceStartPlane; - AABB m_renderBoundsOS; - bool m_viewerInsideVolume; - bool m_nearPlaneIntersectsVolume; - float m_alpha; - float m_scale; - - IVolumeTexture* m_pDensVol; - IVolumeTexture* m_pShadVol; - _smart_ptr m_pHullMesh; -}; - -#endif // #ifndef _CREVOLUMEOBJECT_ diff --git a/Code/CryEngine/CryCommon/CREWaterOcean.h b/Code/CryEngine/CryCommon/CREWaterOcean.h deleted file mode 100644 index e8ca310d41..0000000000 --- a/Code/CryEngine/CryCommon/CREWaterOcean.h +++ /dev/null @@ -1,57 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef _CREWATEROCEAN_ -#define _CREWATEROCEAN_ - -class CWater; - -class CREWaterOcean - : public CRendElementBase -{ -public: - CREWaterOcean(); - virtual ~CREWaterOcean(); - - virtual void mfPrepare(bool bCheckOverflow); - virtual bool mfDraw(CShader* ef, SShaderPass* sfm); - virtual void mfGetPlane(Plane_tpl& pl); - - virtual void Create(uint32 nVerticesCount, SVF_P3F_C4B_T2F* pVertices, uint32 nIndicesCount, const void* pIndices, uint32 nIndexSizeof); - void ReleaseOcean(); - - virtual Vec3 GetPositionAt(float x, float y) const; - virtual Vec4* GetDisplaceGrid() const; - - virtual void GetMemoryUsage(ICrySizer* pSizer) const - { - pSizer->AddObject(this, sizeof(*this)); - } -private: - - uint32 m_nVerticesCount; - uint32 m_nIndicesCount; - uint32 m_nIndexSizeof; - - void* m_pVertDecl; - void* m_pVertices; - void* m_pIndices; - -private: - - void UpdateFFT(); - void FrameUpdate(); -}; - - -#endif diff --git a/Code/CryEngine/CryCommon/CREWaterVolume.h b/Code/CryEngine/CryCommon/CREWaterVolume.h deleted file mode 100644 index 89102e3097..0000000000 --- a/Code/CryEngine/CryCommon/CREWaterVolume.h +++ /dev/null @@ -1,110 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. -#ifndef _CREWATERVOLUME_ -#define _CREWATERVOLUME_ - -#pragma once - - -#include "VertexFormats.h" - -class CREWaterVolume - : public CRendElementBase -{ -public: - CREWaterVolume(); - - virtual ~CREWaterVolume(); - virtual void mfPrepare(bool bCheckOverflow); - virtual bool mfDraw(CShader* ef, SShaderPass* sfm); - virtual void mfGetPlane(Plane_tpl& pl); - virtual void mfCenter(Vec3& vCenter, CRenderObject* pObj); - - virtual void GetMemoryUsage(ICrySizer* pSizer) const - { - pSizer->AddObject(this, sizeof(*this)); - } - -public: - struct SParams - { - SParams() - : m_pVertices(0) - , m_pIndices(0) - , m_numVertices(0) - , m_numIndices(0) - , m_center(0, 0, 0) - , m_WSBBox(Vec3(-1, -1, -1), Vec3(1, 1, 1)) - , m_fogPlane(Vec3(0, 0, 1), 0) - , m_fogDensity(0.1f) - , m_fogColor(0.2f, 0.5f, 0.7f) - , m_fogColorAffectedBySun(true) - , m_fogShadowing(0.5f) - , m_caustics(true) - , m_causticIntensity(1.0f) - , m_causticTiling(1.0f) - , m_causticHeight(0.9f) - , m_viewerInsideVolume(false) - , m_viewerCloseToWaterPlane(false) - , m_viewerCloseToWaterVolume(false) - { - } - - const SVF_P3F_C4B_T2F* m_pVertices; - const uint16* m_pIndices; - - size_t m_numVertices; - size_t m_numIndices; - - Vec3 m_center; - AABB m_WSBBox; - - Plane_tpl m_fogPlane; - float m_fogDensity; - Vec3 m_fogColor; - bool m_fogColorAffectedBySun; - float m_fogShadowing; - - bool m_caustics; - float m_causticIntensity; - float m_causticTiling; - float m_causticHeight; - - bool m_viewerInsideVolume; - bool m_viewerCloseToWaterPlane; - bool m_viewerCloseToWaterVolume; - }; - - struct SOceanParams - { - SOceanParams() - : m_fogColor(0.2f, 0.5f, 0.7f) - , m_fogColorShallow(0.2f, 0.5f, 0.7f) - , m_fogDensity(0.2f) - { - } - - Vec3 m_fogColor; - Vec3 m_fogColorShallow; - float m_fogDensity; - }; - -public: - const SParams* m_pParams; - const SOceanParams* m_pOceanParams; - bool m_drawWaterSurface; - bool m_drawFastPath; -}; - - -#endif // #ifndef _CREWATERVOLUME_ diff --git a/Code/CryEngine/CryCommon/CryAssert_Mac.h b/Code/CryEngine/CryCommon/CryAssert_Mac.h index 8cf49e1a5d..9502605fea 100644 --- a/Code/CryEngine/CryCommon/CryAssert_Mac.h +++ b/Code/CryEngine/CryCommon/CryAssert_Mac.h @@ -45,43 +45,6 @@ void CryAssertTrace(const char* szFormat, ...) } } } -/* -bool CryAssert(const char* szCondition, const char* szFile,unsigned int line, bool *pIgnore) -{ - if (!gEnv) return false; - - gEnv->pSystem->OnAssert(szCondition, gs_szMessage, szFile, line); - - if (!gEnv->bNoAssertDialog && !gEnv->bIgnoreAllAsserts) - { - EDialogAction action = MacOSXHandleAssert(szCondition, szFile, line, gs_szMessage, gEnv->pRenderer != NULL); - - switch (action) { - case eDAStop: - raise(SIGABRT); - exit(-1); - case eDABreak: - return true; - case eDAIgnoreAll: - gEnv->bIgnoreAllAsserts = true; - break; - case eDAIgnore: - *pIgnore = true; - break; - case eDAReportAsBug: - if ( gEnv && gEnv->pSystem) - { - gEnv->pSystem->ReportBug("Assert: %s - %s", szCondition,gs_szMessage); - } - - case eDAContinue: - default: - break; - } - } - - return false; -}*/ bool CryAssert(const char* szCondition, const char* szFile, unsigned int line, bool* pIgnore) { diff --git a/Code/CryEngine/CryCommon/CryMemoryManager.h b/Code/CryEngine/CryCommon/CryMemoryManager.h index 4547ae70bc..b3f8ba7c8e 100644 --- a/Code/CryEngine/CryCommon/CryMemoryManager.h +++ b/Code/CryEngine/CryCommon/CryMemoryManager.h @@ -116,7 +116,6 @@ namespace CryMemory struct ICustomMemoryHeap; class IGeneralMemoryHeap; class IPageMappingHeap; -class IDefragAllocator; class IMemoryAddressRange; // Description: @@ -180,8 +179,6 @@ struct IMemoryManager virtual IMemoryAddressRange* ReserveAddressRange(size_t capacity, const char* sName) = 0; virtual IPageMappingHeap* CreatePageMappingHeap(size_t addressSpace, const char* sName) = 0; - - virtual IDefragAllocator* CreateDefragAllocator() = 0; }; // Global function implemented in CryMemoryManager_impl.h diff --git a/Code/CryEngine/CryCommon/ICryMiniGUI.h b/Code/CryEngine/CryCommon/ICryMiniGUI.h deleted file mode 100644 index 95db2e6518..0000000000 --- a/Code/CryEngine/CryCommon/ICryMiniGUI.h +++ /dev/null @@ -1,286 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// Description : Interface to the Mini GUI subsystem - - -#ifndef CRYINCLUDE_CRYCOMMON_ICRYMINIGUI_H -#define CRYINCLUDE_CRYCOMMON_ICRYMINIGUI_H -#pragma once - - -#include -#include -#include - -namespace minigui -{ - struct IMiniCtrl; - - // Rectangle class - struct Rect - { - float left; - float top; - float right; - float bottom; - - Rect() - : left(0) - , top(0) - , right(0) - , bottom(0) {} - Rect(float l, float t, float r, float b) - : left(l) - , top(t) - , right(r) - , bottom(b) {} - Rect(const Rect& rc) { left = rc.left; top = rc.top; right = rc.right; bottom = rc.bottom; } - bool IsPointInside(float x, float y) const { return x >= left && x <= right && y >= top && y <= bottom; } - float Width() const { return right - left; } - float Height() const { return bottom - top; } - }; - - typedef void(* ClickCallback)(void* data, bool onOff); - typedef void(* RenderCallback)(float x, float y); - - enum EMiniCtrlStatus - { - eCtrl_Hidden = BIT(0), // Control is hidden. - eCtrl_Highlight = BIT(1), // Control is highlight (probably mouse over). - eCtrl_Focus = BIT(2), // Control have focus (from keyboard). - eCtrl_Checked = BIT(3), // Control have checked mark. - eCtrl_NoBorder = BIT(4), // Control have no border. - eCtrl_CheckButton = BIT(5), // Button control behave as a check button. - eCtrl_TextAlignCentre = BIT(6), // Draw text aligned centre - eCtrl_AutoResize = BIT(7), // Auto resize depending on text length - eCtrl_Moveable = BIT(8), // Dynamically reposition ctrl - eCtrl_CloseButton = BIT(9), // Control has close button - }; - enum EMiniCtrlEvent - { - eCtrlEvent_LButtonDown = BIT(0), - eCtrlEvent_LButtonUp = BIT(1), - eCtrlEvent_LButtonPressed = BIT(2), - eCtrlEvent_MouseOver = BIT(3), - eCtrlEvent_MouseOff = BIT(4), - eCtrlEvent_DPadLeft = BIT(5), - eCtrlEvent_DPadRight = BIT(6), - eCtrlEvent_DPadUp = BIT(7), - eCtrlEvent_DPadDown = BIT(8), - }; - - // Types of the supported controls - enum EMiniCtrlType - { - eCtrlType_Unknown = 0, - eCtrlType_Button, - eCtrlType_Menu, - eCtrlType_InfoBox, - eCtrlType_Table, - }; - - struct SMetrics - { - float fTextSize; - float fTitleSize; - - // Colors. - ColorB clrFrameBorder; - ColorB clrFrameBorderHighlight; - ColorB clrFrameBorderOutOfFocus; - ColorB clrChecked; - ColorB clrBackground; - ColorB clrBackgroundHighlight; - ColorB clrBackgroundSelected; - ColorB clrTitle; - ColorB clrText; - ColorB clrTextSelected; - - uint8 outOfFocusAlpha; - }; - - enum ECommand - { - eCommand_ButtonPress, - eCommand_ButtonChecked, - eCommand_ButtonUnchecked, - }; - // Command sent from the control. - struct SCommand - { - ECommand command; - IMiniCtrl* pCtrl; - int nCtrlID; - }; - - ////////////////////////////////////////////////////////////////////////// - // Event listener interface for the MiniGUI - ////////////////////////////////////////////////////////////////////////// - struct IMiniGUIEventListener - { - // - virtual ~IMiniGUIEventListener(){} - virtual void OnCommand(SCommand& cmd) = 0; - // - }; - - // Interface to the GUI - struct IMiniGUI - : public ICryUnknown - { - public: - CRYINTERFACE_DECLARE(IMiniGUI, 0xea09d34268814f2a, 0xaf1034e04b076011); - - // - virtual void Init() = 0; - virtual void Done() = 0; - virtual void Draw() = 0; - virtual void Reset() = 0; - - virtual void SaveState() = 0; - virtual void RestoreState() = 0; - - virtual void SetEnabled(bool status) = 0; - virtual void SetInFocus(bool status) = 0; - virtual bool InFocus() = 0; - - virtual void SetEventListener(IMiniGUIEventListener* pListener) = 0; - - virtual SMetrics& Metrics() = 0; - - // Makes a new control - virtual IMiniCtrl* CreateCtrl(IMiniCtrl* pParentCtrl, int nCtrlID, EMiniCtrlType type, int nCtrlFlags, const Rect& rc, const char* title) = 0; - - // Remove all controls. - virtual void RemoveAllCtrl() = 0; - - virtual void OnCommand(SCommand& cmd) = 0; - - virtual IMiniCtrl* GetCtrlFromPoint(float x, float y) const = 0; - - virtual void SetMovingCtrl(IMiniCtrl* pCtrl) = 0; - // - }; - - DECLARE_SMART_POINTERS(IMiniGUI); - - struct IMiniCtrl - : public _reference_target_t - { - // - virtual void Reset() = 0; - - virtual void SaveState() = 0; - virtual void RestoreState() = 0; - - // For system call only. - virtual void SetGUI(IMiniGUI* pGUI) = 0; - virtual IMiniGUI* GetGUI() const = 0; - - virtual EMiniCtrlType GetType() const = 0; - - virtual int GetId() const = 0; - virtual void SetId(int id) = 0; - - virtual const char* GetTitle() const = 0; - virtual void SetTitle(const char* title) = 0; - - virtual Rect GetRect() const = 0; - virtual void SetRect(const Rect& rc) = 0; - - virtual void SetFlag(uint32 flag) = 0; - virtual void ClearFlag(uint32 flag) = 0; - virtual bool CheckFlag(uint32 flag) const = 0; - - // Sub Controls handling. - virtual void AddSubCtrl(IMiniCtrl* pCtrl) = 0; - virtual void RemoveSubCtrl(IMiniCtrl* pCtrl) = 0; - virtual void RemoveAllSubCtrl() = 0; - virtual int GetSubCtrlCount() const = 0; - virtual IMiniCtrl* GetSubCtrl(int nIndex) const = 0; - virtual IMiniCtrl* GetParent() const = 0; - - // Check if point is inside any of the sub controls. - virtual IMiniCtrl* GetCtrlFromPoint(float x, float y) = 0; - - virtual void OnPaint(class CDrawContext& dc) = 0; - - virtual void SetVisible(bool state) = 0; - - // Events from GUI - virtual void OnEvent([[maybe_unused]] float x, [[maybe_unused]] float y, EMiniCtrlEvent) {}; - - ////////////////////////////////////////////////////////////////////////// - // When set, this control will be enabling/disabling specified cvar - // when button not checked fOffValue will be set on cvar, when checked fOnValue will be set. - virtual bool SetControlCVar(const char* sCVarName, float fOffValue, float fOnValue) = 0; - - virtual bool SetClickCallback(ClickCallback callback, void* pCallbackData) = 0; - - virtual bool SetRenderCallback(RenderCallback callback) = 0; - - virtual bool SetConnectedCtrl(IMiniCtrl* pConnectedCtrl) = 0; - - //resize text box based what text is present - virtual void AutoResize() = 0; - - //Create close 'X' button for control - virtual void CreateCloseButton() = 0; - - //Move control - virtual void Move(float x, float y) = 0; - // - }; - typedef _smart_ptr IMiniCtrlPtr; - - class IMiniGuiCommon - { - public: - // - virtual ~IMiniGuiCommon(){} - virtual bool IsHidden() = 0; - virtual void Hide(bool stat) = 0; - // - }; - - class IMiniTable - : public IMiniGuiCommon - { - public: - // - virtual int AddColumn(const char* name) = 0; - virtual void RemoveColumns() = 0; - virtual int AddData(int columnIndex, ColorB col, const char* format, ...) = 0; - virtual void ClearTable() = 0; - // - }; - - class IMiniInfoBox - : public IMiniGuiCommon - { - public: - // - virtual void SetTextIndent(float x) = 0; - virtual void SetTextSize(float sz) = 0; - virtual void ClearEntries() = 0; - virtual void AddEntry(const char* str, ColorB col, float textSize) = 0; - // - }; -} - - -#define MINIGUI_BEGIN namespace minigui { -#define MINIGUI_END } - -#endif // CRYINCLUDE_CRYCOMMON_ICRYMINIGUI_H diff --git a/Code/CryEngine/CryCommon/IDeferredCollisionEvent.h b/Code/CryEngine/CryCommon/IDeferredCollisionEvent.h deleted file mode 100644 index 2dee198d0a..0000000000 --- a/Code/CryEngine/CryCommon/IDeferredCollisionEvent.h +++ /dev/null @@ -1,95 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_CRYCOMMON_IDEFERREDCOLLISIONEVENT_H -#define CRYINCLUDE_CRYCOMMON_IDEFERREDCOLLISIONEVENT_H -#pragma once - - -#include - -struct EventPhys; - -// Base class for all deferred physics events -// Basically this class works like a future, -// Start() start the computation(some in the main thread, major part in a task/job) -// Result() will sync the task operation and return the result -struct IDeferredPhysicsEvent - : public IThreadTask -{ - // enum list of all types of deferred events - enum DeferredEventType - { - PhysCallBack_OnCollision - }; - - IDeferredPhysicsEvent(){} - // - virtual ~IDeferredPhysicsEvent(){} - - // == "future" like interface == // - - // start the execution of the event - virtual void Start() = 0; - - // sync the event and do all necessary post-processing, then return the result - virtual int Result(EventPhys* pOrigEvent = 0) = 0; - - // just wait for the event to finish - virtual void Sync() = 0; - - // check if the async computation part has finished - virtual bool HasFinished() = 0; - - // Get the concrete Type of this deferred event - virtual DeferredEventType GetType() const = 0; - - // returns a ptr to the original physics event - virtual EventPhys* PhysicsEvent() = 0; - // -}; - - -// Manager class for deferred physics events -struct IDeferredPhysicsEventManager -{ - // type of create function used to create needed deferred events in the HandleEvent function - typedef IDeferredPhysicsEvent*(* CreateEventFunc)(const EventPhys* pEvent); - - IDeferredPhysicsEventManager(){} - // - virtual ~IDeferredPhysicsEventManager(){} - - // dispatch an deferred event to the task thread - virtual void DispatchDeferredEvent(IDeferredPhysicsEvent* pEvent) = 0; - - // Encapsulates common logic for deferred events, should be called from the physics callbacks - // handles the cvar management as well as deferred event creating - virtual int HandleEvent(const EventPhys* pEvent, IDeferredPhysicsEventManager::CreateEventFunc, IDeferredPhysicsEvent::DeferredEventType) = 0; - - // Register and Unregister Deferred events in the manager to allow - virtual void RegisterDeferredEvent(IDeferredPhysicsEvent* pDeferredEvent) = 0; - virtual void UnRegisterDeferredEvent(IDeferredPhysicsEvent* pDeferredEvent) = 0; - - // Delete all Deferred Events in flight, use only when also clearing the physics event queue - // or else this call results in dangling points, mostly used for save/load - virtual void ClearDeferredEvents() = 0; - - virtual void Update() = 0; - - virtual IDeferredPhysicsEvent* GetLastCollisionEventForEntity(IPhysicalEntity* pPhysEnt) = 0; - // -}; - - -#endif // CRYINCLUDE_CRYCOMMON_IDEFERREDCOLLISIONEVENT_H diff --git a/Code/CryEngine/CryCommon/IDefragAllocator.h b/Code/CryEngine/CryCommon/IDefragAllocator.h deleted file mode 100644 index a415b3af67..0000000000 --- a/Code/CryEngine/CryCommon/IDefragAllocator.h +++ /dev/null @@ -1,155 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_CRYCOMMON_IDEFRAGALLOCATOR_H -#define CRYINCLUDE_CRYCOMMON_IDEFRAGALLOCATOR_H -#pragma once - - -struct IDefragAllocatorStats -{ - size_t nCapacity; - size_t nInUseSize; - uint32 nInUseBlocks; - uint32 nFreeBlocks; - uint32 nPinnedBlocks; - uint32 nMovingBlocks; - uint32 nLargestFreeBlockSize; - uint32 nSmallestFreeBlockSize; - uint32 nMeanFreeBlockSize; - uint32 nCancelledMoveCount; -}; - -struct IDefragAllocatorCopyNotification -{ - IDefragAllocatorCopyNotification() - : bDstIsValid(false) - , bSrcIsUnneeded(false) - , bCancel(false) - { - } - - bool bDstIsValid; - bool bSrcIsUnneeded; - - // Flag to indicate that the copy can't be initiated after all - currently only cancelling before a relocate - // is begun is supported, and the destination region must be stable - bool bCancel; -}; - -class IDefragAllocatorPolicy -{ -public: - enum - { - InvalidUserMoveId = 0xffffffff - }; - -public: - // - virtual uint32 BeginCopy(void* pContext, UINT_PTR dstOffset, UINT_PTR srcOffset, UINT_PTR size, IDefragAllocatorCopyNotification* pNotification) = 0; - virtual void Relocate(uint32 userMoveId, void* pContext, UINT_PTR newOffset, UINT_PTR oldOffset, UINT_PTR size) = 0; - virtual void CancelCopy(uint32 userMoveId, void* pContext, bool bSync) = 0; - - // Perform the copy and relocate immediately - will only be called when UnAppendSegment is - virtual void SyncCopy(void* pContext, UINT_PTR dstOffset, UINT_PTR srcOffset, UINT_PTR size) = 0; - // - -protected: - virtual ~IDefragAllocatorPolicy() {} -}; - -class IDefragAllocator -{ -public: - typedef uint32 Hdl; - enum - { - InvalidHdl = 0, - }; - - struct AllocatePinnedResult - { - Hdl hdl; - UINT_PTR offs; - UINT_PTR usableSize; - }; - - enum EBlockSearchKind - { - eBSK_BestFit, - eBSK_FirstFit - }; - - struct Policy - { - Policy() - : pDefragPolicy(NULL) - , maxAllocs(0) - , maxSegments(1) - , blockSearchKind(eBSK_BestFit) - { - } - - IDefragAllocatorPolicy* pDefragPolicy; - size_t maxAllocs; - size_t maxSegments; - EBlockSearchKind blockSearchKind; - }; - -public: - // - virtual void Release(bool bDiscard = false) = 0; - - virtual void Init(UINT_PTR capacity, UINT_PTR alignment, const Policy& policy = Policy()) = 0; - - virtual bool AppendSegment(UINT_PTR capacity) = 0; - virtual void UnAppendSegment() = 0; - - virtual Hdl Allocate(size_t sz, const char* source, void* pContext = NULL) = 0; - virtual Hdl AllocateAligned(size_t sz, size_t alignment, const char* source, void* pContext = NULL) = 0; - virtual AllocatePinnedResult AllocatePinned(size_t sz, const char* source, void* pContext = NULL) = 0; - virtual bool Free(Hdl hdl) = 0; - - virtual void ChangeContext(Hdl hdl, void* pNewContext) = 0; - - virtual size_t GetAllocated() const = 0; - virtual IDefragAllocatorStats GetStats() = 0; - - virtual void DisplayMemoryUsage(const char* title, unsigned int allocatorDisplayOffset = 0) = 0; - - virtual size_t DefragmentTick(size_t maxMoves, size_t maxAmount, bool bForce = false) = 0; - - virtual UINT_PTR UsableSize(Hdl hdl) = 0; - - // Pin the chunk until the next defrag tick, when it will be automatically unpinned - virtual UINT_PTR WeakPin(Hdl hdl) = 0; - - // Pin the chunk until Unpin is called - virtual UINT_PTR Pin(Hdl hdl) = 0; - - virtual void Unpin(Hdl hdl) = 0; - - virtual const char* GetSourceOf(Hdl hdl) = 0; - // - -#ifndef _RELEASE - virtual void DumpState(const char* filename) = 0; - virtual void RestoreState(const char* filename) = 0; -#endif - -protected: - virtual ~IDefragAllocator() {} -}; - -#endif // CRYINCLUDE_CRYCOMMON_IDEFRAGALLOCATOR_H diff --git a/Code/CryEngine/CryCommon/IFileChangeMonitor.h b/Code/CryEngine/CryCommon/IFileChangeMonitor.h deleted file mode 100644 index 4ad46852ed..0000000000 --- a/Code/CryEngine/CryCommon/IFileChangeMonitor.h +++ /dev/null @@ -1,56 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_CRYCOMMON_IFILECHANGEMONITOR_H -#define CRYINCLUDE_CRYCOMMON_IFILECHANGEMONITOR_H -#pragma once - -struct IFileChangeListener -{ - enum EChangeType - { - //! error or unknown change type - eChangeType_Unknown, - //! the file was created - eChangeType_Created, - //! the file was deleted - eChangeType_Deleted, - //! the file was modified (size changed,write) - eChangeType_Modified, - //! this is the old name of a renamed file - eChangeType_RenamedOldName, - //! this is the new name of a renamed file - eChangeType_RenamedNewName - }; - - virtual ~IFileChangeListener() = default; - - virtual void OnFileChange(const char* sFilename, EChangeType eType) = 0; -}; - -struct IFileChangeMonitor -{ - virtual ~IFileChangeMonitor() = default; - - // - // Register the path of a file or directory to monitor - // Path is relative to game directory, e.g. "Libs/WoundSystem/" or "Libs/WoundSystem/HitLocations.xml" - virtual bool RegisterListener(IFileChangeListener* pListener, const char* sMonitorItem) = 0; - // This function can be used to monitor files of specific type, e.g. - // RegisterListener(pListener, "Animations", "caf") - virtual bool RegisterListener(IFileChangeListener* pListener, const char* sFolder, const char* sExtension) = 0; - virtual bool UnregisterListener(IFileChangeListener* pListener) = 0; - // -}; - -#endif // CRYINCLUDE_CRYCOMMON_IFILECHANGEMONITOR_H diff --git a/Code/CryEngine/CryCommon/IFont.h b/Code/CryEngine/CryCommon/IFont.h index c8634fa854..2706c350a3 100644 --- a/Code/CryEngine/CryCommon/IFont.h +++ b/Code/CryEngine/CryCommon/IFont.h @@ -33,8 +33,6 @@ struct ICryFont; struct IFFont; struct FontFamily; -struct IRenderer; - struct SVF_P2F_C4B_T2F_F4B; extern "C" @@ -100,9 +98,6 @@ struct ICryFont //! \param glyphSizeY Height (in pixels) of the characters to be rendered at in the font texture. virtual void AddCharsToFontTextures(FontFamilyPtr pFontFamily, const char* pChars, int glyphSizeX = defaultGlyphSizeX, int glyphSizeY = defaultGlyphSizeY) = 0; - // Summary: - // Globally sets common font render properties based on the initialized renderer - virtual void SetRendererProperties(IRenderer* pRenderer) = 0; // Summary: // Puts the objects used in this module into the sizer interface virtual void GetMemoryUsage(ICrySizer* pSizer) const = 0; diff --git a/Code/CryEngine/CryCommon/IMemory.h b/Code/CryEngine/CryCommon/IMemory.h index 4a96bae2c0..a3b1dc1c2c 100644 --- a/Code/CryEngine/CryCommon/IMemory.h +++ b/Code/CryEngine/CryCommon/IMemory.h @@ -16,7 +16,6 @@ #pragma once #include -#include // <> required for Interfuscator #include // <> required for Interfuscator #include diff --git a/Code/CryEngine/CryCommon/IOverloadSceneManager.h b/Code/CryEngine/CryCommon/IOverloadSceneManager.h deleted file mode 100644 index 9d391c5701..0000000000 --- a/Code/CryEngine/CryCommon/IOverloadSceneManager.h +++ /dev/null @@ -1,47 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// Description : IOverloadSceneManager interface declaration. - - -#ifndef CRYINCLUDE_CRYCOMMON_IOVERLOADSCENEMANAGER_H -#define CRYINCLUDE_CRYCOMMON_IOVERLOADSCENEMANAGER_H -#pragma once - -//================================================================================================== -// Name: COverloadSceneManager -// Desc: Manages overload values (eg CPU,GPU etc) -// 1.0="everything is ok" 0.0="very bad frame rate" -// various systems can use this information and control what is currently in the scene -// Author: James Chilvers -//================================================================================================== -struct IOverloadSceneManager -{ -public: - // - virtual ~IOverloadSceneManager() {} - - virtual void Reset() = 0; - virtual void Update() = 0; - - // Override auto-calculated scale to reach targetfps. - // frameScale is clamped to internal min/max values, - // dt is the length of time in seconds to transition - virtual void OverrideScale(float frameScale, float dt) = 0; - - // Go back to auto-calculated scale from an overridden scale - virtual void ResetScale(float dt) = 0; - // -};//------------------------------------------------------------------------------------------------ - -#endif // CRYINCLUDE_CRYCOMMON_IOVERLOADSCENEMANAGER_H diff --git a/Code/CryEngine/CryCommon/IPerfHud.h b/Code/CryEngine/CryCommon/IPerfHud.h deleted file mode 100644 index 33104435dc..0000000000 --- a/Code/CryEngine/CryCommon/IPerfHud.h +++ /dev/null @@ -1,145 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// Description : Interface to the Performance HUD - - -#ifndef CRYINCLUDE_CRYCOMMON_IPERFHUD_H -#define CRYINCLUDE_CRYCOMMON_IPERFHUD_H -#pragma once - - -#include -#include -#include -#include - -struct ICryPerfHUDWidget - : public _reference_target_t -{ - // - enum EWidgetID - { - eWidget_Warnings = 0, - eWidget_RenderStats, - eWidget_StreamingStats, - eWidget_RenderBatchStats, - eWidget_FpsBuckets, - eWidget_Particles, - eWidget_PakFile, - eWidget_Num, //number of widgets - }; - - ICryPerfHUDWidget(int id = -1) - : m_id(id) - {} - - // - virtual ~ICryPerfHUDWidget() {} - - virtual void Reset() = 0; - virtual void Update() = 0; - virtual bool ShouldUpdate() = 0; - virtual void LoadBudgets(XmlNodeRef perfXML) = 0; - virtual void SaveStats(XmlNodeRef statsXML) = 0; - virtual void Enable(int mode) = 0; - virtual void Disable() = 0; - // - - int m_id; -}; - -// Base Interface for all engine module extensions -struct ICryPerfHUD - : public ICryUnknown -{ - CRYINTERFACE_DECLARE(ICryPerfHUD, 0x268d142e043d464c, 0xa0776580f81b988a); - - struct PerfBucket - { - ILINE PerfBucket(float _target) - { - target = _target; - timeAtTarget = 0.f; - } - - float target; - float timeAtTarget; - }; - - enum EHudState - { - eHudOff = 0, - eHudInFocus, - eHudOutOfFocus, - eHudNumStates, - }; - - // - // Called once to initialize HUD. - virtual void Init() = 0; - virtual void Done() = 0; - virtual void Draw() = 0; - virtual void LoadBudgets() = 0; - virtual void SaveStats(const char* filename = NULL) = 0; - virtual void ResetWidgets() = 0; - virtual void SetState(EHudState state) = 0; - virtual void Reset() = 0; - virtual void Destroy() = 0; - - // Retrieve name of the extension module. - virtual void Show(bool bRestoreState) = 0; - - virtual void AddWidget(ICryPerfHUDWidget* pWidget) = 0; - virtual void RemoveWidget(ICryPerfHUDWidget* pWidget) = 0; - - virtual minigui::IMiniCtrl* CreateMenu(const char* name, minigui::IMiniCtrl* pParent = NULL) = 0; - virtual bool CreateCVarMenuItem(minigui::IMiniCtrl* pMenu, const char* name, const char* controlVar, float controlVarOn, float controlVarOff) = 0; - virtual bool CreateCallbackMenuItem(minigui::IMiniCtrl* pMenu, const char* name, minigui::ClickCallback clickCallback, void* pCallbackData) = 0; - virtual minigui::IMiniInfoBox* CreateInfoMenuItem(minigui::IMiniCtrl* pMenu, const char* name, minigui::RenderCallback renderCallback, const minigui::Rect& rect, bool onAtStart = false) = 0; - virtual minigui::IMiniTable* CreateTableMenuItem(minigui::IMiniCtrl* pMenu, const char* name) = 0; - - virtual minigui::IMiniCtrl* GetMenu(const char* name) = 0; - - virtual void EnableWidget(ICryPerfHUDWidget::EWidgetID id, int mode) = 0; - virtual void DisableWidget(ICryPerfHUDWidget::EWidgetID id) = 0; - - //Warnings - Widget Specific interface - virtual void AddWarning(float duration, const char* fmt, va_list argList) = 0; - virtual bool WarningsWindowEnabled() const = 0; - - //FPS - Widget Specific interface - virtual const std::vector* GetFpsBuckets(float& totalTime) const = 0; - // -}; - -DECLARE_SMART_POINTERS(ICryPerfHUD); - -void CryPerfHUDWarning(float duration, const char*, ...) PRINTF_PARAMS(2, 3); -inline void CryPerfHUDWarning(float duration, const char* format, ...) -{ - if (gEnv && gEnv->pSystem) - { - ICryPerfHUD* pPerfHud = gEnv->pSystem->GetPerfHUD(); - - if (pPerfHud) - { - va_list args; - va_start(args, format); - pPerfHud->AddWarning(duration, format, args); - va_end(args); - } - } -} - -#endif // CRYINCLUDE_CRYCOMMON_IPERFHUD_H diff --git a/Code/CryEngine/CryCommon/IRenderer.h b/Code/CryEngine/CryCommon/IRenderer.h index 71c2500d80..94f8772e71 100644 --- a/Code/CryEngine/CryCommon/IRenderer.h +++ b/Code/CryEngine/CryCommon/IRenderer.h @@ -1472,7 +1472,6 @@ struct IRenderer ///////////////////////////////////////////////////////////////////////////////// // Shaders/Shaders management ///////////////////////////////////////////////////////////////////////////////// - virtual void EF_SetShaderMissCallback(ShaderCacheMissCallback callback) = 0; virtual const char* EF_GetShaderMissLogPath() = 0; ///////////////////////////////////////////////////////////////////////////////// @@ -1533,10 +1532,6 @@ struct IRenderer virtual int EF_LoadLightmap (const char* name) = 0; virtual bool EF_RenderEnvironmentCubeHDR (int size, Vec3& Pos, TArray& vecData) = 0; - // Summary: - // Creates new RE (RenderElement) of type (edt). - virtual IRenderElement* EF_CreateRE (EDataType edt) = 0; - // Summary: // Starts using of the shaders (return first index for allow recursions). virtual void EF_StartEf (const SRenderingPassInfo& passInfo) = 0; @@ -2385,26 +2380,6 @@ private: virtual void EF_QueryImpl(ERenderQueryTypes eQuery, void* pInOut0, uint32 nInOutSize0, void* pInOut1, uint32 nInOutSize1) = 0; }; -// util class to change wireframe mode -class CScopedWireFrameMode -{ -public: - CScopedWireFrameMode(IRenderer* pRenderer, int nMode) - : m_pRenderer(pRenderer) - , m_nMode(nMode) - { - (void) m_nMode; // removes not used warning - pRenderer->PushWireframeMode(nMode); - } - ~CScopedWireFrameMode() - { - m_pRenderer->PopWireframeMode(); - } -private: - IRenderer* m_pRenderer; - int m_nMode; -}; - struct SShaderCacheStatistics { size_t m_nTotalLevelShaderCacheMisses; diff --git a/Code/CryEngine/CryCommon/IShader.h b/Code/CryEngine/CryCommon/IShader.h index 7fcbdefebb..a87144a8c2 100644 --- a/Code/CryEngine/CryCommon/IShader.h +++ b/Code/CryEngine/CryCommon/IShader.h @@ -3413,6 +3413,6 @@ struct SShaderGraphBlock typedef std::vector FXShaderGraphBlocks; typedef FXShaderGraphBlocks::iterator FXShaderGraphBlocksItor; -#include "RendElement.h" +#include #endif // CRYINCLUDE_CRYCOMMON_ISHADER_H diff --git a/Code/CryEngine/CryCommon/ISystem.h b/Code/CryEngine/CryCommon/ISystem.h index 96d9a6ad10..93de0008b0 100644 --- a/Code/CryEngine/CryCommon/ISystem.h +++ b/Code/CryEngine/CryCommon/ISystem.h @@ -89,7 +89,6 @@ struct IResourceManager; struct ITextModeConsole; struct IAVI_Reader; class CPNoise3; -struct IFileChangeMonitor; struct IVisualLog; struct ILocalizationManager; struct ICryFactoryRegistry; @@ -99,7 +98,6 @@ struct IZLibDecompressor; struct ILZ4Decompressor; class IZStdDecompressor; struct IOutputPrintSink; -struct IOverloadSceneManager; struct IThreadManager; struct IServiceNetwork; struct IRemoteCommandManager; @@ -130,7 +128,6 @@ struct CLoadingTimeProfiler; class ICmdLine; struct INotificationNetwork; -struct ICryPerfHUD; class ILyShine; namespace JobManager { @@ -641,14 +638,12 @@ struct SSystemInitParams bool bDedicatedServer; // When running a dedicated server. bool bExecuteCommandLine; // can be switched of to suppress the feature or do it later during the initialization. bool bSkipFont; // Don't load CryFont.dll - bool bSkipRenderer; // Don't load Renderer bool bSkipConsole; // Don't create console bool bSkipNetwork; // Don't create Network bool bSkipWebsocketServer; // Don't create the WebSocket server bool bMinimal; // Don't load banks bool bTesting; // CryUnit bool bNoRandom; //use fixed generator init/seed - bool bShaderCacheGen; // When running in shadercache gen mode bool bUnattendedMode; // When running as part of a build on build-machines: Prevent popping up of any dialog bool bSkipMovie; // Don't load movie bool bSkipAnimation; // Don't load animation @@ -699,7 +694,6 @@ struct SSystemInitParams bExecuteCommandLine = true; bExecuteCommandLine = true; bSkipFont = false; - bSkipRenderer = false; bSkipConsole = false; bSkipNetwork = false; #if defined(WIN32) || defined(WIN64) @@ -712,7 +706,6 @@ struct SSystemInitParams bMinimal = false; bTesting = false; bNoRandom = false; - bShaderCacheGen = false; bUnattendedMode = false; bSkipMovie = false; bSkipAnimation = false; @@ -792,7 +785,6 @@ struct SSystemGlobalEnvironment { AZ::IO::IArchive* pCryPak; AZ::IO::FileIOBase* pFileIO; - IFileChangeMonitor* pFileChangeMonitor; IProfileLogSystem* pProfileLogSystem; IOpticsManager* pOpticsManager; ITimer* pTimer; @@ -806,7 +798,6 @@ struct SSystemGlobalEnvironment IRenderer* pRenderer; IMaterialEffects* pMaterialEffects; ISoftCodeMgr* pSoftCodeMgr; - IOverloadSceneManager* pOverloadSceneManager; IServiceNetwork* pServiceNetwork; IRemoteCommandManager* pRemoteCommandManager; ILyShine* pLyShine; @@ -1127,14 +1118,6 @@ struct ISystem // Gets number of CPUs virtual int GetLogicalCPUCount() = 0; - // Summary: - // Return the rendering driver name. GL or Metal - virtual const char* GetRenderingDriverName() const = 0; - - // Summary: - // Dumps the memory usage statistics to the logging default MB. (can be KB) - virtual void DumpMemoryUsageStatistics(bool bUseKB = false) = 0; - // Summary: // Quits the application. virtual void Quit() = 0; @@ -1145,9 +1128,6 @@ struct ISystem // Returns true if the application is in the shutdown phase. virtual bool IsQuitting() const = 0; // Summary: - // Returns true if the application was initialized to generate the shader cache. - virtual bool IsShaderCacheGenMode() const = 0; - // Summary: // Tells the system in which way we are using the serialization system. virtual void SerializingFile(int mode) = 0; virtual int IsSerializingFile() const = 0; @@ -1195,7 +1175,6 @@ struct ISystem virtual IZLibDecompressor* GetIZLibDecompressor() = 0; virtual ILZ4Decompressor* GetLZ4Decompressor() = 0; virtual IZStdDecompressor* GetZStdDecompressor() = 0; - virtual ICryPerfHUD* GetPerfHUD() = 0; virtual INotificationNetwork* GetINotificationNetwork() = 0; virtual IViewSystem* GetIViewSystem() = 0; virtual ILevelSystem* GetILevelSystem() = 0; @@ -1217,16 +1196,10 @@ struct ISystem virtual IProfilingSystem* GetIProfilingSystem() = 0; virtual ISystemEventDispatcher* GetISystemEventDispatcher() = 0; virtual IVisualLog* GetIVisualLog() = 0; - virtual IFileChangeMonitor* GetIFileChangeMonitor() = 0; - virtual WIN_HWND GetHWND() = 0; - - virtual IRenderer* GetIRenderer() = 0; virtual ITimer* GetITimer() = 0; virtual IThreadManager* GetIThreadManager() = 0; - //irtual IThreadManager* GetIThreadManager() = 0; - virtual void SetLoadingProgressListener(ILoadingProgressListener* pListener) = 0; virtual ISystem::ILoadingProgressListener* GetLoadingProgressListener() const = 0; @@ -1234,7 +1207,6 @@ struct ISystem // Game is created after System init, so has to be set explicitly. virtual void SetIMaterialEffects(IMaterialEffects* pMaterialEffects) = 0; virtual void SetIOpticsManager(IOpticsManager* pOpticsManager) = 0; - virtual void SetIFileChangeMonitor(IFileChangeMonitor* pFileChangeMonitor) = 0; virtual void SetIVisualLog(IVisualLog* pVisualLog) = 0; //virtual const char *GetGamePath()=0; @@ -1377,10 +1349,6 @@ struct ISystem // Non-0 if the state was indeed changed, 0 if already in that state. virtual int SetThreadState(ESubsystem subsys, bool bActive) = 0; - // Summary: - // Creates and returns a usable object implementing ICrySizer interface. - virtual ICrySizer* CreateSizer() = 0; - // Summary: // Query if system is now paused. // Pause flag is set when calling system update with pause mode. @@ -1491,11 +1459,6 @@ struct ISystem // returns zeroes if no updates happened yet virtual void GetUpdateStats(SSystemUpdateStats& stats) = 0; - // Description: - // Useful to investigate memory fragmentation. - // Every time you call this from the console: #System.DumpMemoryCoverage() - // it adds a line to "MemoryCoverage.bmp" (generated the first time, there is a max line count). - virtual void DumpMemoryCoverage() = 0; virtual ESystemGlobalState GetSystemGlobalState(void) = 0; virtual void SetSystemGlobalState(ESystemGlobalState systemGlobalState) = 0; diff --git a/Code/CryEngine/CryCommon/LoadScreenComponent.cpp b/Code/CryEngine/CryCommon/LoadScreenComponent.cpp deleted file mode 100644 index 3059e8a1fc..0000000000 --- a/Code/CryEngine/CryCommon/LoadScreenComponent.cpp +++ /dev/null @@ -1,373 +0,0 @@ -/* - * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or - * its licensors. - * - * For complete copyright and license terms please see the LICENSE at the root of this - * distribution (the "License"). All use of this software is governed by the License, - * or, if provided, by the license below or the license accompanying this file. Do not - * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * - */ - -#include -#include -#include - -#include "LoadScreenComponent.h" -#include - -#if AZ_LOADSCREENCOMPONENT_ENABLED - -namespace -{ - // Due to issues with DLLs sometimes there can be different values of gEnv in different DLLs. - // So we use this preferred method of getting the global environment - SSystemGlobalEnvironment* GetGlobalEnv() - { - if (!GetISystem()) - { - return nullptr; - } - - return GetISystem()->GetGlobalEnvironment(); - } - - static const char* const s_gameFixedFpsCvarName = "game_load_screen_sequence_fixed_fps"; - static const char* const s_gameMaxFpsCvarName = "game_load_screen_max_fps"; - static const char* const s_gameMinimumLoadTimeCvarName = "game_load_screen_minimum_time"; - - static const char* const s_levelFixedFpsCvarName = "level_load_screen_sequence_fixed_fps"; - static const char* const s_levelMaxFpsCvarName = "level_load_screen_max_fps"; - static const char* const s_levelMinimumLoadTimeCvarName = "level_load_screen_minimum_time"; -} - -void LoadScreenComponent::Reflect(AZ::ReflectContext* context) -{ - AZ::SerializeContext* serializeContext = azrtti_cast(context); - - if (serializeContext) - { - serializeContext->Class() - ->Version(1) - ; - - AZ::EditContext* editContext = serializeContext->GetEditContext(); - if (editContext) - { - editContext->Class( - "Load screen manager", "Allows management of a load screen") - ->ClassElement(AZ::Edit::ClassElements::EditorData, "") - ->Attribute(AZ::Edit::Attributes::Category, "Game") - ->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC("System", 0xc94d118b)) - ; - } - } -} - -void LoadScreenComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided) -{ - provided.push_back(AZ_CRC("LoadScreenService", 0x901b031c)); -} - -void LoadScreenComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible) -{ - incompatible.push_back(AZ_CRC("LoadScreenService", 0x901b031c)); -} - -void LoadScreenComponent::Reset() -{ - m_loadScreenState = LoadScreenState::None; - - m_fixedDeltaTimeInSeconds = -1.0f; - m_maxDeltaTimeInSeconds = -1.0f; - m_previousCallTimeForUpdateAndRender = CTimeValue(); - m_processingLoadScreen.store(false); - - // Reset CVars so they're not carried over to other levels - SSystemGlobalEnvironment* pGEnv = GetGlobalEnv(); - if (pGEnv && pGEnv->pConsole) - { - if (ICVar* var = pGEnv->pConsole->GetCVar(s_levelFixedFpsCvarName)) - { - var->Set(""); - } - if (ICVar* var = pGEnv->pConsole->GetCVar(s_levelMaxFpsCvarName)) - { - var->Set(""); - } - if (ICVar* var = pGEnv->pConsole->GetCVar(s_levelMinimumLoadTimeCvarName)) - { - var->Set(""); - } - } -} - -void LoadScreenComponent::LoadConfigSettings(const char* fixedFpsVarName, const char* maxFpsVarName, const char* minimumLoadTimeVarName) -{ - m_fixedDeltaTimeInSeconds = -1.0f; - m_maxDeltaTimeInSeconds = -1.0f; - m_minimumLoadTimeInSeconds = 0.0f; - - SSystemGlobalEnvironment* pGEnv = GetGlobalEnv(); - if (pGEnv && pGEnv->pConsole) - { - ICVar* fixedFpsVar = pGEnv->pConsole->GetCVar(fixedFpsVarName); - if (fixedFpsVar && fixedFpsVar->GetFVal() > 0.0f) - { - m_fixedDeltaTimeInSeconds = (1.0f / fixedFpsVar->GetFVal()); - } - - ICVar* maxFpsVar = pGEnv->pConsole->GetCVar(maxFpsVarName); - if (maxFpsVar && maxFpsVar->GetFVal() > 0.0f) - { - m_maxDeltaTimeInSeconds = (1.0f / maxFpsVar->GetFVal()); - } - - if (ICVar* minimumLoadTimeVar = pGEnv->pConsole->GetCVar(minimumLoadTimeVarName)) - { - // Never allow values below 0 seconds - m_minimumLoadTimeInSeconds = AZStd::max(minimumLoadTimeVar->GetFVal(), 0.0f); - } - } -} - -void LoadScreenComponent::Init() -{ - Reset(); -} - -void LoadScreenComponent::Activate() -{ - CrySystemEventBus::Handler::BusConnect(); - LoadScreenBus::Handler::BusConnect(GetEntityId()); -} - -void LoadScreenComponent::Deactivate() -{ - CrySystemEventBus::Handler::BusDisconnect(); - LoadScreenBus::Handler::BusDisconnect(GetEntityId()); -} - -void LoadScreenComponent::OnCrySystemInitialized(ISystem& system, const SSystemInitParams&) -{ - SSystemGlobalEnvironment* pGEnv = system.GetGlobalEnvironment(); - - // Can't use macros here because we have to use our pointer. - if (pGEnv && pGEnv->pConsole) - { - pGEnv->pConsole->Register("ly_EnableLoadingThread", &m_loadingThreadEnabled, 0, VF_NULL, - "EXPERIMENTAL. Enable fully threaded loading where the LoadingScreen is drawn on a thread that isn't loading data."); - } - - if (pGEnv && !pGEnv->IsEditor()) - { - // If not running from the editor, then run GameStart - GameStart(); - } -} - -void LoadScreenComponent::OnCrySystemShutdown(ISystem&) -{ -} - -void LoadScreenComponent::UpdateAndRender() -{ - SSystemGlobalEnvironment* pGEnv = GetGlobalEnv(); - - if (m_loadScreenState == LoadScreenState::Showing && pGEnv && pGEnv->pTimer) - { - AZ_Assert(GetCurrentThreadId() == pGEnv->mMainThreadId, "UpdateAndRender should only be called from the main thread"); - - // Throttling. - if (!m_previousCallTimeForUpdateAndRender.GetValue()) - { - // This is the first call to UpdateAndRender(). - m_previousCallTimeForUpdateAndRender = pGEnv->pTimer->GetAsyncTime(); - } - - const CTimeValue callTimeForUpdateAndRender = pGEnv->pTimer->GetAsyncTime(); - const float deltaTimeInSeconds = fabs((callTimeForUpdateAndRender - m_previousCallTimeForUpdateAndRender).GetSeconds()); - - // Early-out: We DON'T need to execute UpdateAndRender() at a higher frequency than 30 FPS. - const bool shouldThrottle = m_maxDeltaTimeInSeconds > 0.0f && deltaTimeInSeconds < m_maxDeltaTimeInSeconds; - - if (!shouldThrottle) - { - bool expectedValue = false; - if (m_processingLoadScreen.compare_exchange_strong(expectedValue, true)) - { - m_previousCallTimeForUpdateAndRender = callTimeForUpdateAndRender; - - const float updateDeltaTime = (m_fixedDeltaTimeInSeconds == -1.0f) ? deltaTimeInSeconds : m_fixedDeltaTimeInSeconds; - - EBUS_EVENT(LoadScreenUpdateNotificationBus, UpdateAndRender, updateDeltaTime); - - // Some platforms (iOS, OSX) require system events to be pumped in order to update the screen - AzFramework::ApplicationRequests::Bus::Broadcast(&AzFramework::ApplicationRequests::PumpSystemEventLoopUntilEmpty); - - m_processingLoadScreen.store(false); - } - } - } -} - -void LoadScreenComponent::GameStart() -{ - if (m_loadScreenState == LoadScreenState::None) - { - LoadConfigSettings(s_gameFixedFpsCvarName, s_gameMaxFpsCvarName, s_gameMinimumLoadTimeCvarName); - - const bool usingLoadingThread = IsLoadingThreadEnabled(); - - AZ::EBusLogicalResult> anyHandled(false); - EBUS_EVENT_RESULT(anyHandled, LoadScreenNotificationBus, NotifyGameLoadStart, usingLoadingThread); - - if (anyHandled.value) - { - if (usingLoadingThread) - { - m_loadScreenState = LoadScreenState::ShowingMultiThreaded; - - GetGlobalEnv()->pRenderer->StartLoadtimePlayback(this); - } - else - { - m_loadScreenState = LoadScreenState::Showing; - - // Kick-start the first frame. - UpdateAndRender(); - } - - if (ITimer* timer = GetGlobalEnv()->pTimer) - { - m_lastStartTime = timer->GetAsyncTime(); - } - } - } -} - -void LoadScreenComponent::LevelStart() -{ - if (m_loadScreenState == LoadScreenState::None) - { - LoadConfigSettings(s_levelFixedFpsCvarName, s_levelMaxFpsCvarName, s_levelMinimumLoadTimeCvarName); - - const bool usingLoadingThread = IsLoadingThreadEnabled(); - - AZ::EBusLogicalResult> anyHandled(false); - EBUS_EVENT_RESULT(anyHandled, LoadScreenNotificationBus, NotifyLevelLoadStart, usingLoadingThread); - - if (anyHandled.value) - { - if (usingLoadingThread) - { - m_loadScreenState = LoadScreenState::ShowingMultiThreaded; - - GetGlobalEnv()->pRenderer->StartLoadtimePlayback(this); - } - else - { - m_loadScreenState = LoadScreenState::Showing; - - // Kick-start the first frame. - UpdateAndRender(); - } - - if (ITimer* timer = GetGlobalEnv()->pTimer) - { - m_lastStartTime = timer->GetAsyncTime(); - } - } - } -} - -void LoadScreenComponent::Pause() -{ - if (m_loadScreenState == LoadScreenState::Showing) - { - m_loadScreenState = LoadScreenState::Paused; - } - else if (m_loadScreenState == LoadScreenState::ShowingMultiThreaded) - { - m_loadScreenState = LoadScreenState::PausedMultithreaded; - } -} - -void LoadScreenComponent::Resume() -{ - if (m_loadScreenState == LoadScreenState::Paused) - { - m_loadScreenState = LoadScreenState::Showing; - } - else if (m_loadScreenState == LoadScreenState::PausedMultithreaded) - { - m_loadScreenState = LoadScreenState::ShowingMultiThreaded; - } -} - -void LoadScreenComponent::Stop() -{ - // If we were actually in a load screen, check if we need to wait longer. - if (m_loadScreenState != LoadScreenState::None && m_minimumLoadTimeInSeconds > 0.0f) - { - if (ITimer* timer = GetGlobalEnv()->pTimer) - { - CTimeValue currentTime = timer->GetAsyncTime(); - float timeSinceStart = currentTime.GetDifferenceInSeconds(m_lastStartTime); - - while (timeSinceStart < m_minimumLoadTimeInSeconds) - { - // Simple loop that makes sure the loading screens update but also doesn't consume the whole core. - - if (m_loadScreenState == LoadScreenState::Showing) - { - EBUS_EVENT(LoadScreenBus, UpdateAndRender); - } - - CrySleep(0); - - currentTime = timer->GetAsyncTime(); - timeSinceStart = currentTime.GetDifferenceInSeconds(m_lastStartTime); - } - } - } - - if (m_loadScreenState == LoadScreenState::ShowingMultiThreaded) - { - // This will block until the other thread completes. - GetGlobalEnv()->pRenderer->StopLoadtimePlayback(); - } - - if (m_loadScreenState != LoadScreenState::None) - { - EBUS_EVENT(LoadScreenNotificationBus, NotifyLoadEnd); - } - - Reset(); - - m_loadScreenState = LoadScreenState::None; -} - -bool LoadScreenComponent::IsPlaying() -{ - return m_loadScreenState != LoadScreenState::None; -} - -void LoadScreenComponent::LoadtimeUpdate(float deltaTime) -{ - if (m_loadScreenState == LoadScreenState::ShowingMultiThreaded) - { - EBUS_EVENT(LoadScreenUpdateNotificationBus, LoadThreadUpdate, deltaTime); - } -} - -void LoadScreenComponent::LoadtimeRender() -{ - if (m_loadScreenState == LoadScreenState::ShowingMultiThreaded) - { - EBUS_EVENT(LoadScreenUpdateNotificationBus, LoadThreadRender); - } -} - -#endif // if AZ_LOADSCREENCOMPONENT_ENABLED diff --git a/Code/CryEngine/CryCommon/LoadScreenComponent.h b/Code/CryEngine/CryCommon/LoadScreenComponent.h deleted file mode 100644 index 71ed6287f1..0000000000 --- a/Code/CryEngine/CryCommon/LoadScreenComponent.h +++ /dev/null @@ -1,106 +0,0 @@ -/* - * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or - * its licensors. - * - * For complete copyright and license terms please see the LICENSE at the root of this - * distribution (the "License"). All use of this software is governed by the License, - * or, if provided, by the license below or the license accompanying this file. Do not - * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * - */ -#pragma once - -#include -#include -#include - -#include -#include -#include - -#if AZ_LOADSCREENCOMPONENT_ENABLED - -/* -* This component is responsible for managing the load screen. -*/ -class LoadScreenComponent - : public AZ::Component - , public CrySystemEventBus::Handler - , public LoadScreenBus::Handler - , public ILoadtimeCallback -{ -public: - AZ_COMPONENT(LoadScreenComponent, "{97CDBD6C-C621-4427-87C8-10E1B8F947FF}"); - - LoadScreenComponent() = default; - ~LoadScreenComponent() = default; - - ////////////////////////////////////////////////////////////////////////// - // AZ::Component interface implementation - void Init() override; - void Activate() override; - void Deactivate() override; - ////////////////////////////////////////////////////////////////////////// - - //////////////////////////////////////////////////////////////////////// - // CrySystemEvents - void OnCrySystemInitialized(ISystem&, const SSystemInitParams& params) override; - void OnCrySystemShutdown(ISystem&) override; - //////////////////////////////////////////////////////////////////////// - - ////////////////////////////////////////////////////////////////////////// - // LoadScreenBus interface implementation - void UpdateAndRender() override; - void GameStart() override; - void LevelStart() override; - void Pause() override; - void Resume() override; - void Stop() override; - bool IsPlaying() override; - ////////////////////////////////////////////////////////////////////////// - - ////////////////////////////////////////////////////////////////////////// - // ILoadtimeCallback interface implementation - void LoadtimeUpdate(float deltaTime) override; - void LoadtimeRender() override; - ////////////////////////////////////////////////////////////////////////// - - inline bool IsLoadingThreadEnabled() const - { - return m_loadingThreadEnabled != 0; - } - -protected: - static void Reflect(AZ::ReflectContext* context); - static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided); - static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible); - -private: - void Reset(); - void LoadConfigSettings(const char* fixedFpsVarName, const char* maxFpsVarName, const char* minimumLoadTimeVarName); - - ////////////////////////////////////////////////////////////////////////// - enum class LoadScreenState - { - None, - Showing, - ShowingMultiThreaded, - Paused, - PausedMultithreaded, - }; - LoadScreenState m_loadScreenState{ LoadScreenState::None }; - - float m_fixedDeltaTimeInSeconds{ -1.0f }; - float m_maxDeltaTimeInSeconds{ -1.0f }; - float m_minimumLoadTimeInSeconds{ 0.0f }; - - CTimeValue m_lastStartTime; - CTimeValue m_previousCallTimeForUpdateAndRender; - AZStd::atomic_bool m_processingLoadScreen{ false }; - - int32_t m_loadingThreadEnabled{ 0 }; - ////////////////////////////////////////////////////////////////////////// -}; - -#endif // if AZ_LOADSCREENCOMPONENT_ENABLED diff --git a/Code/CryEngine/CryCommon/Mocks/IMemoryManagerMock.h b/Code/CryEngine/CryCommon/Mocks/IMemoryManagerMock.h index 3f458d7f52..63df006e14 100644 --- a/Code/CryEngine/CryCommon/Mocks/IMemoryManagerMock.h +++ b/Code/CryEngine/CryCommon/Mocks/IMemoryManagerMock.h @@ -40,6 +40,4 @@ public: IMemoryAddressRange* (size_t capacity, const char* sName)); MOCK_METHOD2(CreatePageMappingHeap, IPageMappingHeap* (size_t addressSpace, const char* sName)); - MOCK_METHOD0(CreateDefragAllocator, - IDefragAllocator*()); }; diff --git a/Code/CryEngine/CryCommon/Mocks/IRendererMock.h b/Code/CryEngine/CryCommon/Mocks/IRendererMock.h index 757c586261..7b0b7b76a2 100644 --- a/Code/CryEngine/CryCommon/Mocks/IRendererMock.h +++ b/Code/CryEngine/CryCommon/Mocks/IRendererMock.h @@ -286,8 +286,6 @@ public: CRenderObject * (SShaderItem & si, CRenderObject * obj, const SRenderingPassInfo& passInfo, int numPts, int ninds, SVF_P3F_C4B_T2F * &verts, SPipTangents * &tangs, uint16 * &inds, int nAW, const SRendItemSorter& rendItemSorter)); MOCK_METHOD0(ForceUpdateGlobalShaderParameters, void()); - MOCK_METHOD1(EF_SetShaderMissCallback, - void(ShaderCacheMissCallback callback)); MOCK_METHOD0(EF_GetShaderMissLogPath, const char*()); MOCK_METHOD1(EF_GetShaderNames, @@ -334,8 +332,6 @@ public: int(const char* name)); MOCK_METHOD3(EF_RenderEnvironmentCubeHDR, bool(int size, Vec3 & Pos, TArray&vecData)); - MOCK_METHOD1(EF_CreateRE, - IRenderElement * (EDataType edt)); MOCK_METHOD1(EF_StartEf, void(const SRenderingPassInfo& passInfo)); MOCK_METHOD3(EF_GetObjData, diff --git a/Code/CryEngine/CryCommon/Mocks/ISystemMock.h b/Code/CryEngine/CryCommon/Mocks/ISystemMock.h index 4d2e80a2f3..9e5182ebcf 100644 --- a/Code/CryEngine/CryCommon/Mocks/ISystemMock.h +++ b/Code/CryEngine/CryCommon/Mocks/ISystemMock.h @@ -49,18 +49,12 @@ public: int()); MOCK_METHOD0(GetLogicalCPUCount, int()); - MOCK_CONST_METHOD0(GetRenderingDriverName, - const char*()); - MOCK_METHOD1(DumpMemoryUsageStatistics, - void(bool)); MOCK_METHOD0(Quit, void()); MOCK_METHOD1(Relaunch, void(bool bRelaunch)); MOCK_CONST_METHOD0(IsQuitting, bool()); - MOCK_CONST_METHOD0(IsShaderCacheGenMode, - bool()); MOCK_METHOD1(SerializingFile, void(int mode)); MOCK_CONST_METHOD0(IsSerializingFile, @@ -90,8 +84,6 @@ public: ILZ4Decompressor * ()); MOCK_METHOD0(GetZStdDecompressor, IZStdDecompressor * ()); - MOCK_METHOD0(GetPerfHUD, - ICryPerfHUD * ()); MOCK_METHOD0(GetINotificationNetwork, INotificationNetwork * ()); MOCK_METHOD0(GetIViewSystem, @@ -132,12 +124,6 @@ public: ISystemEventDispatcher * ()); MOCK_METHOD0(GetIVisualLog, IVisualLog * ()); - MOCK_METHOD0(GetIFileChangeMonitor, - IFileChangeMonitor * ()); - MOCK_METHOD0(GetHWND, - WIN_HWND()); - MOCK_METHOD0(GetIRenderer, - IRenderer * ()); MOCK_METHOD0(GetITimer, ITimer * ()); MOCK_METHOD0(GetIThreadManager, @@ -150,8 +136,6 @@ public: void(IMaterialEffects * pMaterialEffects)); MOCK_METHOD1(SetIOpticsManager, void(IOpticsManager * pOpticsManager)); - MOCK_METHOD1(SetIFileChangeMonitor, - void(IFileChangeMonitor * pFileChangeMonitor)); MOCK_METHOD1(SetIVisualLog, void(IVisualLog * pVisualLog)); MOCK_METHOD2(DebugStats, @@ -229,8 +213,6 @@ public: void(bool detectResolution)); MOCK_METHOD2(SetThreadState, int(ESubsystem subsys, bool bActive)); - MOCK_METHOD0(CreateSizer, - ICrySizer * ()); MOCK_CONST_METHOD0(IsPaused, bool()); MOCK_METHOD0(GetLocalizationManager, @@ -275,8 +257,6 @@ public: void(bool)); MOCK_METHOD1(GetUpdateStats, void(SSystemUpdateStats & stats)); - MOCK_METHOD0(DumpMemoryCoverage, - void()); MOCK_METHOD0(GetSystemGlobalState, ESystemGlobalState(void)); MOCK_METHOD1(SetSystemGlobalState, diff --git a/Code/CryEngine/CryCommon/ProjectDefines.h b/Code/CryEngine/CryCommon/ProjectDefines.h index 9308412c15..f82861d6e0 100644 --- a/Code/CryEngine/CryCommon/ProjectDefines.h +++ b/Code/CryEngine/CryCommon/ProjectDefines.h @@ -162,10 +162,6 @@ typedef uint32 vtx_idx; #endif #endif -#if defined(ENABLE_PROFILING_CODE) - #define USE_PERFHUD -#endif - #if defined(ENABLE_PROFILING_CODE) #define ENABLE_ART_RT_TIME_ESTIMATE #endif diff --git a/Code/CryEngine/CryCommon/RendElement.h b/Code/CryEngine/CryCommon/RendElement.h deleted file mode 100644 index 41bcf2bf67..0000000000 --- a/Code/CryEngine/CryCommon/RendElement.h +++ /dev/null @@ -1,321 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_CRYCOMMON_RENDELEMENT_H -#define CRYINCLUDE_CRYCOMMON_RENDELEMENT_H -#pragma once - - -//============================================================= - -#include "VertexFormats.h" - -class CRendElementBase; -struct CRenderChunk; -struct PrimitiveGroup; -class CShader; -struct SShaderTechnique; -class CParserBin; -struct SParserFrame; - -namespace AZ -{ - namespace Vertex - { - class Format; - } -} - -enum EDataType -{ - eDATA_Unknown = 0, - eDATA_Sky, - eDATA_Beam, - eDATA_ClientPoly, - eDATA_Flare, - eDATA_Terrain, - eDATA_SkyZone, - eDATA_Mesh, - eDATA_Imposter, - eDATA_LensOptics, - eDATA_FarTreeSprites_Deprecated, - eDATA_OcclusionQuery, - eDATA_Particle, - eDATA_GPUParticle, - eDATA_PostProcess, - eDATA_HDRProcess, - eDATA_Cloud, - eDATA_HDRSky, - eDATA_FogVolume, - eDATA_WaterVolume, - eDATA_WaterOcean, - eDATA_VolumeObject, - eDATA_PrismObject, // normally this would be #if !defined(EXCLUDE_DOCUMENTATION_PURPOSE) but we keep it to get consistent numbers for serialization - eDATA_DeferredShading, - eDATA_GameEffect, - eDATA_BreakableGlass, - eDATA_GeomCache, - eDATA_Gem, -}; - -#include - -//======================================================= - -#define FCEF_TRANSFORM 1 -#define FCEF_DIRTY 2 -#define FCEF_NODEL 4 -#define FCEF_DELETED 8 - -#define FCEF_MODIF_TC 0x10 -#define FCEF_MODIF_VERT 0x20 -#define FCEF_MODIF_COL 0x40 -#define FCEF_MODIF_MASK 0xf0 - -#define FCEF_UPDATEALWAYS 0x100 -#define FCEF_ALLOC_CUST_FLOAT_DATA 0x200 -#define FCEF_MERGABLE 0x400 - -#define FCEF_SKINNED 0x800 -#define FCEF_PRE_DRAW_DONE 0x1000 - -#define FGP_NOCALC 1 -#define FGP_SRC 2 -#define FGP_REAL 4 -#define FGP_WAIT 8 - -#define FGP_STAGE_SHIFT 0x10 - -#define MAX_CUSTOM_TEX_BINDS_NUM 2 - -struct SGeometryInfo; -class CRendElement; - -struct IRenderElementDelegate -{ - virtual void mfPrepare(bool bCheckOverflow) = 0; - virtual bool mfDraw(CShader* shader, SShaderPass* pass) = 0; - virtual bool mfSetSampler([[maybe_unused]] int customId, [[maybe_unused]] int nTUnit, [[maybe_unused]] int nTState, [[maybe_unused]] int nTexMaterialSlot, [[maybe_unused]] int nSUnit) { return true; }; -}; - -struct IRenderElement -{ - virtual int mfGetMatId() = 0; - virtual uint16 mfGetFlags() = 0; - virtual void mfSetFlags(uint16 fl) = 0; - virtual void mfUpdateFlags(uint16 fl) = 0; - virtual void mfClearFlags(uint16 fl) = 0; - virtual void mfPrepare(bool bCheckOverflow) = 0; - virtual void mfCenter(Vec3& centr, CRenderObject* pObj) = 0; - virtual void mfGetBBox(Vec3& vMins, Vec3& vMaxs) = 0; - virtual void mfReset() = 0; - virtual void mfGetPlane(Plane_tpl& pl) = 0; - virtual void mfExport(struct SShaderSerializeContext& SC) = 0; - virtual void mfImport(struct SShaderSerializeContext& SC, uint32& offset) = 0; - virtual void mfPrecache(const SShaderItem& SH) = 0; - virtual bool mfIsHWSkinned() = 0; - virtual bool mfCheckUpdate(int Flags, uint16 nFrame, bool bTessellation = false) = 0; - virtual bool mfUpdate(int Flags, bool bTessellation = false) = 0; - virtual bool mfCompile(CParserBin& Parser, SParserFrame& Frame) = 0; - virtual bool mfDraw(CShader* ef, SShaderPass* sfm) = 0; - virtual bool mfPreDraw(SShaderPass* sl) = 0; - virtual bool mfSetSampler(int customId, int nTUnit, int nTState, int nTexMaterialSlot, int nSUnit) = 0; - virtual void mfSetDelegate(IRenderElementDelegate* pDelegate) = 0; - virtual IRenderElementDelegate* mfGetDelegate() = 0; - virtual CRenderChunk* mfGetMatInfo() = 0; - virtual TRenderChunkArray* mfGetMatInfoList() = 0; - virtual void* mfGetPointer(ESrcPointer ePT, int* Stride, EParamType Type, ESrcPointer Dst, int Flags) = 0; - virtual AZ::Vertex::Format GetVertexFormat() const = 0; - virtual void* GetCustomData() const = 0; - virtual int GetCustomTexBind(int i) const = 0; - virtual CRendElementBase* mfCopyConstruct() = 0; - virtual EDataType mfGetType() = 0; - virtual int Size() = 0; - virtual void GetMemoryUsage(ICrySizer* pSizer) const = 0; - -}; - -class CRendElement -{ -public: - static CRendElement m_RootGlobal; - static CRendElement m_RootRelease[]; - CRendElement* m_NextGlobal; - CRendElement* m_PrevGlobal; - - EDataType m_Type; - -protected: - virtual void UnlinkGlobal() - { - if (!m_NextGlobal || !m_PrevGlobal) - { - return; - } - m_NextGlobal->m_PrevGlobal = m_PrevGlobal; - m_PrevGlobal->m_NextGlobal = m_NextGlobal; - m_NextGlobal = m_PrevGlobal = NULL; - } - - virtual void LinkGlobal(CRendElement* Before) - { - if (m_NextGlobal || m_PrevGlobal) - { - return; - } - m_NextGlobal = Before->m_NextGlobal; - Before->m_NextGlobal->m_PrevGlobal = this; - Before->m_NextGlobal = this; - m_PrevGlobal = Before; - } - -public: - CRendElement(); - virtual ~CRendElement(); - virtual void Release(bool bForce = false); - virtual const char* mfTypeString(); - virtual void mfSetType(EDataType t) { m_Type = t; } - virtual void GetMemoryUsage([[maybe_unused]] ICrySizer* pSizer) const {} - virtual int Size() { return 0; } - - static void ShutDown(); - static void Tick(); - static void Cleanup(); -}; - -class CRendElementBase - : public CRendElement - , public IRenderElement -{ -public: - uint16 m_Flags; - uint16 m_nFrameUpdated; - -public: - void* m_CustomData; - int m_CustomTexBind[MAX_CUSTOM_TEX_BINDS_NUM]; - - struct SGeometryStreamInfo - { - const void* pStream; - int nOffset; - int nStride; - }; - struct SGeometryInfo - { - uint32 bonesRemapGUID; // Input paremeter to fetch correct skinning stream. - - int primitiveType; //!< \see eRenderPrimitiveType - AZ::Vertex::Format vertexFormat; - uint32 streamMask; - - int32 nFirstIndex; - int32 nNumIndices; - uint32 nFirstVertex; - uint32 nNumVertices; - - uint32 nMaxVertexStreams; - - SGeometryStreamInfo indexStream; - SGeometryStreamInfo vertexStream[VSF_NUM]; - - void* pTessellationAdjacencyBuffer; - void* pSkinningExtraBonesBuffer; - }; - -public: - CRendElementBase(); - virtual ~CRendElementBase(); - - - virtual void mfPrepare(bool bCheckOverflow) override - { - if (m_delegate) - { - m_delegate->mfPrepare(bCheckOverflow); - } - } - bool mfDraw(CShader* ef, SShaderPass* sfm) override { return m_delegate ? m_delegate->mfDraw(ef, sfm) : true; } - bool mfSetSampler(int customId, int nTUnit, int nTState, int nTexMaterialSlot, int nSUnit) override { return m_delegate ? m_delegate->mfSetSampler(customId, nTUnit, nTState, nTexMaterialSlot, nSUnit) : false; } - void mfSetDelegate(IRenderElementDelegate* pDelegate) override { m_delegate = pDelegate; } - IRenderElementDelegate* mfGetDelegate() { return m_delegate; } - - EDataType mfGetType() override { return m_Type; }; - - CRenderChunk* mfGetMatInfo() override { return nullptr; } - TRenderChunkArray* mfGetMatInfoList() override { return nullptr; } - int mfGetMatId() override { return -1; } - void mfReset() override {}; - CRendElementBase* mfCopyConstruct() override; - void mfCenter(Vec3& centr, CRenderObject* pObj) override; - - bool mfCompile([[maybe_unused]] CParserBin& Parser, [[maybe_unused]] SParserFrame& Frame) override { return false; } - bool mfPreDraw([[maybe_unused]] SShaderPass* sl) override { return true; } - bool mfUpdate([[maybe_unused]] int Flags, [[maybe_unused]] bool bTessellation = false) override { return true; } - void mfPrecache([[maybe_unused]] const SShaderItem& SH) override {} - void mfExport([[maybe_unused]] struct SShaderSerializeContext& SC) override { CryFatalError("mfExport has not been implemented for this render element type"); } - void mfImport([[maybe_unused]] struct SShaderSerializeContext& SC, [[maybe_unused]] uint32& offset) override { CryFatalError("mfImport has not been implemented for this render element type"); } - void mfGetPlane(Plane_tpl& pl) override; - void* mfGetPointer([[maybe_unused]] ESrcPointer ePT, [[maybe_unused]] int* Stride, [[maybe_unused]] EParamType Type, [[maybe_unused]] ESrcPointer Dst, [[maybe_unused]] int Flags) override { return nullptr; } - - uint16 mfGetFlags() override { return m_Flags; } - void mfSetFlags(uint16 fl) override { m_Flags = fl; } - void mfUpdateFlags(uint16 fl) override { m_Flags |= fl; } - void mfClearFlags(uint16 fl) override { m_Flags &= ~fl; } - bool mfCheckUpdate(int Flags, uint16 nFrame, bool bTessellation = false) override - { - if (nFrame != m_nFrameUpdated || (m_Flags & (FCEF_DIRTY | FCEF_SKINNED | FCEF_UPDATEALWAYS))) - { - m_nFrameUpdated = nFrame; - return mfUpdate(Flags, bTessellation); - } - return true; - } - void mfGetBBox(Vec3& vMins, Vec3& vMaxs) override - { - vMins.Set(0, 0, 0); - vMaxs.Set(0, 0, 0); - } - bool mfIsHWSkinned() override { return false; } - int Size() override { return 0; } - void GetMemoryUsage([[maybe_unused]] ICrySizer* pSizer) const override {} - AZ::Vertex::Format GetVertexFormat() const override { return AZ::Vertex::Format(eVF_Unknown); }; - virtual bool GetGeometryInfo([[maybe_unused]] SGeometryInfo& streams) { return false; } - void Draw([[maybe_unused]] CRenderObject* pObj, [[maybe_unused]] const struct SGraphicsPiplinePassContext& ctx) {}; - void* GetCustomData() const { return m_CustomData; } - int GetCustomTexBind(int index) const { return m_CustomTexBind[index]; } - -protected: - IRenderElementDelegate * m_delegate = nullptr; -}; - -#include "CREMesh.h" -#include "CRESky.h" -#include "CREOcclusionQuery.h" -#include "CREImposter.h" -#include "CREBaseCloud.h" -#include "CREPostProcess.h" -#include "CREFogVolume.h" -#include "CREWaterVolume.h" -#include "CREWaterOcean.h" -#include "CREVolumeObject.h" -#include "CREGameEffect.h" -#include "CREGeomCache.h" - -#if !defined(EXCLUDE_DOCUMENTATION_PURPOSE) -#include "CREPrismObject.h" -#endif // EXCLUDE_DOCUMENTATION_PURPOSE - -//========================================================== - -#endif // CRYINCLUDE_CRYCOMMON_RENDELEMENT_H diff --git a/Code/CryEngine/CryCommon/TypeLibrary.h b/Code/CryEngine/CryCommon/TypeLibrary.h deleted file mode 100644 index 03d608a24e..0000000000 --- a/Code/CryEngine/CryCommon/TypeLibrary.h +++ /dev/null @@ -1,512 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_CRYCOMMON_TYPELIBRARY_H -#define CRYINCLUDE_CRYCOMMON_TYPELIBRARY_H -#pragma once - -#include // <> required for Interfuscator - -#include -#include - -#ifdef SOFTCODE_ENABLED - -// Internal: Used by SC types to auto-remove themselves from their TypeRegistrar on destruction. -struct InstanceTracker -{ - InstanceTracker() - : m_pRegistrar() - {} - - ~InstanceTracker() - { - if (m_pRegistrar) - { - m_pRegistrar->RemoveInstance(this); - } - } - - void SetRegistrar(ITypeRegistrar* pRegistrar) - { - m_pRegistrar = pRegistrar; - } - - ITypeRegistrar* m_pRegistrar; // Valid if created by a registrar, otherwise NULL -}; - -#endif - - -#ifdef SOFTCODE_ENABLED - -// Include this for SEH support - #include - -/* - Used to declare the interface as having an associated TypeLibrary. - Usage: - struct IMyInterface - { - DECLARE_TYPELIB(IMyInterface); -*/ - #define DECLARE_TYPELIB(IName) \ - static void VisitMembers(IExchanger & ex) {} \ - typedef CTypeLibrary TLibrary - -/* - Exposes a class to a TypeLibrary for registration. - Usage: - class MyThing : public IThing - { - DECLARE_TYPE(MyThing, IThing); - ... -*/ - #define DECLARE_TYPE(TName, TSuperType) \ -public: \ - void VisitMembers(IExchanger & ex) { TSuperType::VisitMembers(ex); VisitMember<__START_MEMBERS>(ex); } \ -private: \ - friend class TypeRegistrar; \ - static const size_t __START_MEMBERS = __COUNTER__ + 1; \ - template \ - void VisitMember(IExchanger & exchanger) {} \ - InstanceTracker __instanceTracker - - #ifdef SOFTCODE - #define _EXPORT_TYPE_LIB(Interface) \ - extern "C" ITypeLibrary * GetTypeLibrary() { return CTypeLibrary::Instance(); } - #else - #define _EXPORT_TYPE_LIB(Interface) - #endif - -// Internal: Outputs the specialized method template for the member at index - #define _SOFT_MEMBER_VISITOR(member, index) \ - template <> \ - void VisitMember(IExchanger & ex) { ex.Visit(#member, member); VisitMember(ex); } - -/* - Used to expose a class member to SoftCoding (to allow run-time member exchange) - If SoftCode is disabled this does nothing and simple emits the member. - For array types, use SOFT_ARRAY() instead or use AZStd::array which allows assignment. - Usage: std::vector SOFT(m_myStrings); -*/ - #define SOFT(member) \ - member; \ - _SOFT_MEMBER_VISITOR(member, __COUNTER__) - -/* - Used to expose a primitive array type to SoftCoding. - Declare it directly after the member. - NOTE: It's cleaner to convert the member to AZStd::array as - this avoid having to use this special case while preserving semantics. - Usage: - ColorB m_colors[20]; - SOFT_ARRAY(m_colors); -*/ - #define SOFT_ARRAY(arrayMember) _SOFT_MEMBER_VISITOR(arrayMember, __COUNTER__) - -// Internal: Executes given lambda in an SEH try block. -template -void SoftCodeTry(TLambda& lambda) -{ - __try - { - lambda(); - } - __except (EXCEPTION_EXECUTE_HANDLER) - { - } -} - -// Internal: Used by TypeRegistry. Use SOFTCODE_RETRY() for user code. - #define SOFTCODE_TRY(exp) SoftCodeTry([&](){ exp; }) - #define SOFTCODE_TRY_BLOCK SoftCodeTry([&]() { - #define SOFTCODE_TRY_END }); - -/* - Internal: Attempt a given lambda functor. In the even on an exception execution will pause - to allow the user to provide a replacement implementation for the failing instance. - Usage: See SOFTCODE_RETRY & SOFTCODE_RETRY_BLOCK below. -*/ -template -void SoftCodeRetry(TPtr& pointer, TLambda& lambda) -{ - bool complete = false; - while (pointer && !complete) - { - __try - { - lambda(); - complete = true; - } - __except (EXCEPTION_EXECUTE_HANDLER) - { - if (gEnv->pSoftCodeMgr) - { - pointer = reinterpret_cast(gEnv->pSoftCodeMgr->WaitForUpdate(pointer)); - } - } - } - ; -} - -/* - Attempts to call an expression based the given pointer. - If a Structured Exception is raised the thread will wait for a replacement of - the pointer to be provided via the SoftCodeMgr. This will repeat until no exception is raised. - - Usage: SOFTCODE_RETRY(pThing, (pThing->Update(frameTime))); // Same as pThing->Update(frameTime); -*/ - #define SOFTCODE_RETRY(pointer, exp) SoftCodeRetry(pointer, [&](){ exp; }) - -/* - Attempts to call an expression based the given pointer. - If a Structured Exception is raised the thread will wait for a replacement of - the pointer to be provided via the SoftCodeMgr. This will repeat until no exception is raised. - - Usage: - SOFTCODE_RETRY_BLOCK(pThing) - { - pSomething = pThing->GetSomething(); - } - SOFTCODE_RETRY_END -*/ - #define SOFTCODE_RETRY_BLOCK(pointer) SoftCodeRetry(pointer, [&]() { - #define SOFTCODE_RETRY_END }); - -#else // !SOFTCODE_ENABLED ... - -// IMPORTANT: Docs for these macros are found above. - - #define DECLARE_TYPELIB(IName) \ - typedef CTypeLibrary TLibrary - - #define DECLARE_TYPE(TName, TSuperType) \ -private: \ - friend class TypeRegistrar; - - #define _EXPORT_TYPE_LIB(Interface) - - #define SOFT(member) member - #define SOFT_ARRAY(arrayMember) - - #define SOFTCODE_TRY(exp) (exp) - #define SOFTCODE_TRY_BLOCK { - #define SOFTCODE_TRY_END }; - - #define SOFTCODE_RETRY(pointer, exp) (exp) - #define SOFTCODE_RETRY_BLOCK(pointer) { - #define SOFTCODE_RETRY_END }; - -#endif // !SOFTCODE_ENABLED - -/* - Implements registration for a type to a TypeLibrary. - Usage: - // MyThing.cpp - DECLARE_TYPE(MyThing); -*/ -#define IMPLEMENT_TYPE(TName) \ - static TypeRegistrar s_register##TName(#TName) - -/* - Provides the singleton for the TypeLibrary implementation. - Also exports the accessors function for SoftCode builds. - Usage: - // ThingLibrary.cpp - IMPLEMENT_TYPELIB(IThing, "Things") -*/ -#define IMPLEMENT_TYPELIB(Interface, Name) \ - _EXPORT_TYPE_LIB(Interface) \ - template <> \ - CTypeLibrary* CTypeLibrary::Instance() \ - { \ - static CTypeLibrary s_instance(Name); \ - return &s_instance; \ - } - -/* - Internal: Used to register a type with a TypeLibrary. - Also provides instance construction (factory) access. - For SC builds it also provides copying and instance tracking. -*/ -template -class TypeRegistrar - : public ITypeRegistrar -{ -public: - TypeRegistrar(const char* name) - : m_name(name) - { - typedef typename T::TLibrary TLib; - TLib::Instance()->RegisterType(this); - } - - virtual const char* GetName() const { return m_name; } - - virtual void* CreateInstance() - { - T* pInstance = NULL; - - SOFTCODE_TRY_BLOCK - { - pInstance = ConstructInstance(); - } - SOFTCODE_TRY_END - - if (pInstance) - { - RegisterInstance(pInstance); - } - - return pInstance; - } - -#ifdef SOFTCODE_ENABLED - virtual size_t InstanceCount() const - { - return m_instances.size(); - } - - virtual void RemoveInstance(InstanceTracker* pTracker) - { - T* pInstance = GetInstanceFromTracker(pTracker); - TInstanceVec::iterator iter(std::find(m_instances.begin(), m_instances.end(), pInstance)); - std::swap(*iter, m_instances.back()); - m_instances.pop_back(); - } - - virtual bool ExchangeInstances(IExchanger& exchanger) - { - if (exchanger.IsLoading()) - { - const size_t instanceCount = exchanger.InstanceCount(); - - // Ensure we have the correct number of instances - if (m_instances.size() != instanceCount) - { - // TODO: Destroy any existing instances - for (size_t i = 0; i < instanceCount; ++i) - { - if (!CreateInstance()) - { - return false; - } - } - } - } - - bool complete = false; - SOFTCODE_TRY_BLOCK - { - for (std::vector::iterator iter(m_instances.begin()); iter != m_instances.end(); ++iter) - { - T* pInstance = *iter; - if (exchanger.BeginInstance(pInstance)) - { - // Exchanges the members of pInstance as defined in T - // Should also exchange members of parent types - pInstance->VisitMembers(exchanger); - } - } - complete = true; - } - SOFTCODE_TRY_END - - return complete; - } - - virtual bool DestroyInstances() - { - bool complete = false; - SOFTCODE_TRY_BLOCK - { - while (!m_instances.empty()) - { - delete m_instances.back(); - // NOTE: No need to pop_back() as already done by the InstanceTracker via RemoveInstance() - } - complete = true; - } - SOFTCODE_TRY_END - - return complete; - } - - - virtual bool HasInstance(void* pInstance) const - { - return std::find(m_instances.begin(), m_instances.end(), pInstance) != m_instances.end(); - } -#endif - -private: - void RegisterInstance(T* pInstance) - { -#ifdef SOFTCODE_ENABLED - pInstance->__instanceTracker.SetRegistrar(this); - m_instances.push_back(pInstance); -#endif - } - -#ifdef SOFTCODE_ENABLED - // Util: Avoids having to redundantly store the instance address in the tracker - T* GetInstanceFromTracker(InstanceTracker* pTracker) - { - ptrdiff_t trackerOffset = reinterpret_cast(&((static_cast(0))->__instanceTracker)); - return reinterpret_cast(reinterpret_cast(pTracker) - trackerOffset); - } -#endif - - // Needed to avoid C2712 due to lack of stack unwind within SEH try blocks - T* ConstructInstance() - { - return new T(); - } - -private: - const char* m_name; // Name of the type - -#ifdef SOFTCODE_ENABLED - typedef std::vector TInstanceVec; - TInstanceVec m_instances; // Tracks the active instances (SC only) -#endif -}; - -/* - Provides factory creation support for a set of types that - derive from a single interface T. Users need to provide a - specialization of the static CTypeLibrary* Instance() member - in a cpp file to provide the singleton instance. -*/ -template -class CTypeLibrary - #ifdef SOFTCODE_ENABLED - : public ITypeLibrary - #endif -{ -public: - CTypeLibrary(const char* name) - : m_name(name) -#ifdef SOFTCODE_ENABLED - , m_pOverrideLib() - , m_overrideActive() - , m_registered() -#endif - { - } - - // Implemented in the export cpp - static CTypeLibrary* Instance(); - - void RegisterType(ITypeRegistrar* pType) - { - m_typeMap[pType->GetName()] = pType; - } - - // The global identifier for this library module - /*virtual*/ const char* GetName() { return m_name; } - -#ifdef SOFTCODE_ENABLED - virtual void* CreateInstanceVoid(const char* typeName) - { - return CreateInstance(typeName); - } -#endif - - // Generic creation function - T* CreateInstance(const char* typeName) - { -#ifdef SOFTCODE_ENABLED - RegisterWithSoftCode(); - - // If override is enabled, use it - if (m_pOverrideLib) - { - return reinterpret_cast(m_pOverrideLib->CreateInstanceVoid(typeName)); - } -#endif - - TTypeMap::const_iterator typeIter(m_typeMap.find(typeName)); - if (typeIter != m_typeMap.end()) - { - ITypeRegistrar* pRegistrar = typeIter->second; - return reinterpret_cast(pRegistrar->CreateInstance()); - } - - return NULL; - } - -#ifdef SOFTCODE_ENABLED - // Indicates CreateInstance requests should be forwarded to the specified lib - virtual void SetOverride(ITypeLibrary* pOverrideLib) - { - m_pOverrideLib = pOverrideLib; - } - - virtual size_t GetTypes(ITypeRegistrar** ppTypes, size_t& count) const - { - size_t returnedCount = 0; - - if (ppTypes && count >= m_typeMap.size()) - { - for (TTypeMap::const_iterator iter(m_typeMap.begin()); iter != m_typeMap.end(); ++iter) - { - *ppTypes = iter->second; - ++ppTypes; - ++returnedCount; - } - } - - count = m_typeMap.size(); - return returnedCount; - } - - // Inform the Mgr of this Library and allow it to set an override - inline void RegisterWithSoftCode() - { - // Only register built-in types, SC types are handled directly by - // the SoftCodeMgr, so there's no need to auto-register. -#ifndef SOFTCODE - if (!m_registered) - { - if (ISoftCodeMgr* pSoftCodeMgr = gEnv->pSoftCodeMgr) - { - pSoftCodeMgr->RegisterLibrary(this); - } - - m_registered = true; - } -#endif - } -#endif - -private: - typedef AZStd::basic_string, AZ::AZStdAlloc> TypeString; - typedef AZStd::map, AZ::AZStdAlloc> TTypeMap; - TTypeMap m_typeMap; - - // The name for this TypeLibrary used during SC registration - const char* m_name; - -#ifdef SOFTCODE_ENABLED - // Used to patch in a new TypeLib at run-time - ITypeLibrary* m_pOverrideLib; - // True when the owning object system enables the override - bool m_overrideActive; - // True when registration with SoftCodeMgr has been attempted - bool m_registered; -#endif -}; - -#endif // CRYINCLUDE_CRYCOMMON_TYPELIBRARY_H diff --git a/Code/CryEngine/CryCommon/crycommon_files.cmake b/Code/CryEngine/CryCommon/crycommon_files.cmake index 7d169c2643..3b63dab649 100644 --- a/Code/CryEngine/CryCommon/crycommon_files.cmake +++ b/Code/CryEngine/CryCommon/crycommon_files.cmake @@ -20,13 +20,9 @@ set(FILES ICmdLine.h IColorGradingController.h IConsole.h - ICryMiniGUI.h - IDeferredCollisionEvent.h - IDefragAllocator.h IEngineModule.h IEntityRenderState.h IEntityRenderState_info.cpp - IFileChangeMonitor.h IFlares.h IFont.h IFunctorBase.h @@ -51,8 +47,6 @@ set(FILES IMiniLog.h IMovieSystem.h INotificationNetwork.h - IOverloadSceneManager.h - IPerfHud.h IPhysics.h IPhysicsDebugRenderer.h IPostEffectGroup.h @@ -109,7 +103,6 @@ set(FILES FunctorBaseMember.h stridedptr.h Options.h - CREGeomCache.h SerializationTypes.h CryEndian.h CryRandomInternal.h @@ -205,7 +198,6 @@ set(FILES TimeValue_info.h TypeInfo_decl.h TypeInfo_impl.h - TypeLibrary.h UnalignedBlit.h UnicodeBinding.h UnicodeEncoding.h @@ -222,18 +214,6 @@ set(FILES PakLoadDataUtils.cpp PakLoadDataUtils.h TPool.h - CREBaseCloud.h - CREFogVolume.h - CREGameEffect.h - CREImposter.h - CREMesh.h - CREOcclusionQuery.h - CREPostProcess.h - CRESky.h - CREVolumeObject.h - CREWaterOcean.h - CREWaterVolume.h - RendElement.h Cry_Matrix33.h Cry_Matrix34.h Cry_Matrix44.h @@ -280,8 +260,6 @@ set(FILES Linux_Win32Wrapper.h LinuxSpecific.h LoadScreenBus.h - LoadScreenComponent.cpp - LoadScreenComponent.h MacSpecific.h platform.h platform_impl.cpp @@ -478,7 +456,6 @@ set(FILES Terrain/Bus/TerrainRendererBus.h Terrain/Bus/HeightmapDataBus.h Terrain/Bus/TerrainProviderBus.h - CREPrismObject.h StaticInstance.h Pak/CryPakUtils.h ) diff --git a/Code/CryEngine/CrySystem/AutoDetectSpec.cpp b/Code/CryEngine/CrySystem/AutoDetectSpec.cpp index dd7739bb79..31eee85d90 100644 --- a/Code/CryEngine/CrySystem/AutoDetectSpec.cpp +++ b/Code/CryEngine/CrySystem/AutoDetectSpec.cpp @@ -711,31 +711,6 @@ static Win32SysInspect::DXFeatureLevel GetFeatureLevel(D3D_FEATURE_LEVEL feature } } - -static int GetDXGIAdapterOverride() -{ -#if defined(WIN32) || defined(WIN64) - ICVar* pCVar = gEnv->pConsole ? gEnv->pConsole->GetCVar("r_overrideDXGIAdapter") : 0; - return pCVar ? pCVar->GetIVal() : -1; -#else - return -1; -#endif -} - - -static void LogDeviceInfo(unsigned int adapterIdx, const DXGI_ADAPTER_DESC1& ad, Win32SysInspect::DXFeatureLevel fl, bool displaysConnected) -{ - const bool suitableDevice = fl >= Win32SysInspect::DXFL_11_0 && displaysConnected; - - CryLogAlways("- %s (vendor = 0x%.4x, device = 0x%.4x)", CryStringUtils::WStrToUTF8(ad.Description).c_str(), ad.VendorId, ad.DeviceId); - CryLogAlways(" - Adapter index: %d", adapterIdx); - CryLogAlways(" - Dedicated video memory: %d MB", ad.DedicatedVideoMemory >> 20); - CryLogAlways(" - Feature level: %s", GetFeatureLevelAsString(fl)); - CryLogAlways(" - Displays connected: %s", displaysConnected ? "yes" : "no"); - CryLogAlways(" - Suitable rendering device: %s", suitableDevice ? "yes" : "no"); -} - - static bool FindGPU(DXGI_ADAPTER_DESC1& adapterDesc, Win32SysInspect::DXFeatureLevel& featureLevel) { memset(&adapterDesc, 0, sizeof(adapterDesc)); @@ -757,15 +732,7 @@ static bool FindGPU(DXGI_ADAPTER_DESC1& adapterDesc, Win32SysInspect::DXFeatureL if (pD3D11CD) { - const int r_overrideDXGIAdapter = GetDXGIAdapterOverride(); - const bool logDeviceInfo = !gEnv->pRenderer && r_overrideDXGIAdapter < 0; - - if (logDeviceInfo) - { - CryLogAlways("Logging video adapters:"); - } - - unsigned int nAdapter = r_overrideDXGIAdapter >= 0 ? r_overrideDXGIAdapter : 0; + unsigned int nAdapter = 0; IDXGIAdapter1* pAdapter = 0; while (pFactory->EnumAdapters1(nAdapter, &pAdapter) != DXGI_ERROR_NOT_FOUND) { @@ -786,29 +753,16 @@ static bool FindGPU(DXGI_ADAPTER_DESC1& adapterDesc, Win32SysInspect::DXFeatureL const Win32SysInspect::DXFeatureLevel fl = GetFeatureLevel(deviceFeatureLevel); - if (logDeviceInfo) - { - LogDeviceInfo(nAdapter, ad, fl, displaysConnected); - } - if (featureLevel < fl && displaysConnected) { adapterDesc = ad; featureLevel = fl; } - else if (r_overrideDXGIAdapter >= 0) - { - CryLogAlways("No display connected to DXGI adapter override %d. Adapter cannot be used for rendering.", r_overrideDXGIAdapter); - } } SAFE_RELEASE(pDevice); SAFE_RELEASE(pAdapter); } - if (r_overrideDXGIAdapter >= 0) - { - break; - } ++nAdapter; } } diff --git a/Code/CryEngine/CrySystem/CrySizerImpl.cpp b/Code/CryEngine/CrySystem/CrySizerImpl.cpp deleted file mode 100644 index bd26b05b9e..0000000000 --- a/Code/CryEngine/CrySystem/CrySizerImpl.cpp +++ /dev/null @@ -1,251 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "CrySystem_precompiled.h" -#include -#include -#include "CrySizerImpl.h" - -CrySizerImpl::CrySizerImpl() - : m_pResourceCollector(0) -{ - m_nFlags = 0; - m_nTotalSize = 0; - // to avoid reallocations during walk through the memory tree, reserve the space for the names - clear(); -} - -CrySizerImpl::~CrySizerImpl() -{ -} - -void CrySizerImpl::Push (const char* szComponentName) -{ - m_stackNames.push_back (getNameIndex(getCurrentName(), szComponentName)); - // if the depth is too deep, something is wrong, perhaps an infinite loop - assert (m_stackNames.size() < 128); -} - -void CrySizerImpl::PushSubcomponent (const char* szSubcomponentName) -{ - Push (szSubcomponentName); -} - - -void CrySizerImpl::Pop () -{ - if (!m_stackNames.empty()) - { - m_stackNames.pop_back(); - } - else - { - assert (0); - } -} - -// returns the index of the current name on the top of the name stack -size_t CrySizerImpl::getCurrentName() const -{ - assert(!m_stackNames.empty()); - return m_stackNames.empty() ? 0 : m_stackNames.back(); -} - - - -// searches for the name in the name array; adds the name if it's not there and returns the index -size_t CrySizerImpl::getNameIndex(size_t nParent, const char* szComponentName) -{ - NameArray::const_iterator it = m_arrNames.begin(), itEnd = it + m_arrNames.size(); - for (; it != itEnd; ++it) - { -#if defined(LINUX) - if (!strcasecmp(it->strName.c_str(), szComponentName) && it->nParent == nParent) -#else - if (!strcmp(it->strName.c_str(), szComponentName) && it->nParent == nParent) -#endif - { - return (size_t)(it - m_arrNames.begin());//it-m_arrNames.begin(); - } - } - - size_t nNewName = m_arrNames.size(); - m_arrNames.resize(nNewName + 1); - - m_arrNames[nNewName].assign(szComponentName, nParent); - - m_arrNames[nParent].arrChildren.push_back(nParent); - - return nNewName; -} - -static NullResCollector s_nullCollector; - -IResourceCollector* CrySizerImpl::GetResourceCollector() -{ - return m_pResourceCollector != 0 ? m_pResourceCollector : &s_nullCollector; -} - -void CrySizerImpl::Reset() -{ - clear(); - - m_nTotalSize = 0; - - //m_arrNames.resize(0); - //m_arrNames.push_back("TOTAL"); // the default name, with index 0 - //m_LastObject.clear(); - ////m_nFlags; - //m_nTotalSize=0; - //if (m_pResourceCollector) - //{ - // m_pResourceCollector->Reset(); - //} - //m_setObjects->clear(); - //m_stackNames.resize(0); - //m_stackNames.push_back(0); -} - - -// adds an object identified by the unique pointer (it needs not be -// the actual object position in the memory, though it would be nice, -// but it must be unique throughout the system and unchanging for this object) -// RETURNS: true if the object has actually been added (for the first time) -// and calculated -bool CrySizerImpl::AddObject (const void* pIdentifier, size_t sizeBytes, int nCount) -{ - if (!pIdentifier || !sizeBytes) - { - return false; // we don't add the NULL objects - } - Object NewObject(pIdentifier, sizeBytes, getCurrentName()); - - // check if the last object was the same - if (NewObject == m_LastObject) - { - assert (m_LastObject.nSize == sizeBytes); - return false; - } - - ObjectSet& rSet = m_setObjects[getHash(pIdentifier)]; - ObjectSet::iterator it = rSet.find (NewObject); - if (it == rSet.end()) - { - // there's no such object in the map, add it - rSet.insert (NewObject); - ComponentName& CompName = m_arrNames[getCurrentName()]; - CompName.numObjects += nCount; - CompName.sizeObjects += sizeBytes; - - m_nTotalSize += sizeBytes; - return true; - } - else - { - Object* pObj = const_cast(&(*it)); - - // if we do an heap check, don't accept the same object twice - if (sizeBytes != pObj->nSize) - { - // if the following assert fails: - // assert (0); - // .. it means we have one object that's added two times with different sizes; that's screws up the whole idea - // we assume there are two different objects that are for some reason assigned the same id - pObj->nSize += sizeBytes; // anyway it's an invalid situation - ComponentName& CompName = m_arrNames[getCurrentName()]; - CompName.sizeObjects += sizeBytes; - return true; // yes we added the object, though there were an error condition - } - - return false; - } -} - -size_t CrySizerImpl::GetObjectCount() -{ - size_t count = m_stackNames.size(); - for (int i = 0; i < g_nHashSize; i++) - { - count += m_setObjects[i].size(); - } - return count; -} - - -// finalizes data collection, should be called after all objects have been added -void CrySizerImpl::End() -{ - // clean up the totals of each name - int i; - for (i = 0; i < m_arrNames.size(); ++i) - { - assert (i == 0 || ((int)m_arrNames[i].nParent < i && m_arrNames[i].nParent >= 0)); - m_arrNames[i].sizeObjectsTotal = m_arrNames[i].sizeObjects; - } - - // add the component's size to the total size of the parent. - // for every component, all their children are put after them in the name array - // we don't include the root because it doesn't belong to any other parent (nowhere further to add) - for (i = m_arrNames.size() - 1; i > 0; --i) - { - // the parent's total size is increased by the _total_ size (already calculated) of this object - m_arrNames[m_arrNames[i].nParent].sizeObjectsTotal += m_arrNames[i].sizeObjectsTotal; - } -} - - -void CrySizerImpl::clear() -{ - for (unsigned i = 0; i < g_nHashSize; ++i) - { - m_setObjects[i].clear(); - } - - m_arrNames.clear(); - m_arrNames.push_back("TOTAL"); // the default name, with index 0 - m_stackNames.clear(); - m_stackNames.push_back(0); - m_LastObject.pId = NULL; - - if (m_pResourceCollector) - { - m_pResourceCollector->Reset(); - } -} - -// hash function for an address; returns value 0..1<> 4) & (g_nHashSize-1); - - // pseudorandomizing transform - ldiv_t Qrem = (ldiv_t)ldiv(((uint32)(UINT_PTR)pId >> 2), 127773); - Qrem.rem = 16807 * Qrem.rem - 2836 * Qrem.quot; - if (Qrem.rem < 0) - { - Qrem.rem += 2147483647; // 0x7FFFFFFF - } - return ((unsigned)Qrem.rem) & (g_nHashSize - 1); -} -unsigned CrySizerImpl::GetDepthLevel(unsigned nCurrent) -{ - uint32 nDepth = 0; - nCurrent = m_arrNames[nCurrent].nParent; - while (nCurrent != 0) - { - nDepth++; - nCurrent = m_arrNames[nCurrent].nParent; - } - return nDepth; -} - diff --git a/Code/CryEngine/CrySystem/CrySizerImpl.h b/Code/CryEngine/CrySystem/CrySizerImpl.h deleted file mode 100644 index f43ee25297..0000000000 --- a/Code/CryEngine/CrySystem/CrySizerImpl.h +++ /dev/null @@ -1,184 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// Description : Implementation of the ICrySizer interface, which is used to -// calculate the memory usage by the subsystems and components, to help -// the artists keep the memory budged low. - - -#ifndef CRYINCLUDE_CRYSYSTEM_CRYSIZERIMPL_H -#define CRYINCLUDE_CRYSYSTEM_CRYSIZERIMPL_H -#pragma once - - - -// prerequisities - -////////////////////////////////////////////////////////////////////////// -// implementation of interface ICrySizer -// ICrySizer is passed to all subsystems and has a lot of helper functions that -// are compiled in the appropriate subsystems. CrySizerImpl is created in CrySystem -// and is passed to all the other subsystems -class CrySizerImpl - : public ICrySizer -{ -public: - CrySizerImpl(); - ~CrySizerImpl(); - - virtual void Release() { delete this; } - virtual size_t GetTotalSize() { return m_nTotalSize; }; - virtual size_t GetObjectCount(); - - void Reset(); - - // adds an object identified by the unique pointer (it needs not be - // the actual object position in the memory, though it would be nice, - // but it must be unique throughout the system and unchanging for this object) - // RETURNS: true if the object has actually been added (for the first time) - // and calculated - virtual bool AddObject (const void* pIdentifier, size_t nSizeBytes, int nCount = 1); - - virtual IResourceCollector* GetResourceCollector(); - - // finalizes data collection, should be called after all objects have been added - void End(); - - void clear(); - - // Arguments: - // pColl - can be 0 - void SetResourceCollector(IResourceCollector* pColl) { m_pResourceCollector = pColl; } - -protected: - - IResourceCollector* m_pResourceCollector; // - - // these functions must operate on the component name stack - // they are to be only accessible from within class CrySizerComponentNameHelper - // which should be used through macro SIZER_COMPONENT_NAME - virtual void Push (const char* szComponentName); - virtual void PushSubcomponent (const char* szSubcomponentName); - virtual void Pop (); - - // searches for the name in the name array; adds the name if it's not there and returns the index - size_t getNameIndex (size_t nParent, const char* szComponentName); - - // returns the index of the current name on the top of the name stack - size_t getCurrentName() const; - -protected: - friend class CrySizerStatsBuilder; - - // the stack of subsystem names; the indices in the name array are kept, not the names themselves - typedef DynArray NameStack; - NameStack m_stackNames; - - // the array of names; each name ever pushed on the stack is present here - struct ComponentName - { - ComponentName (){} - ComponentName (const char* szName, size_t parent = 0) - : strName (szName) - , nParent (parent) - , numObjects(0) - , sizeObjects (0) - , sizeObjectsTotal (0) - { - } - - void assign (const char* szName, size_t parent = 0) - { - strName = szName; - nParent = parent; - numObjects = 0; - sizeObjects = 0; - sizeObjectsTotal = 0; - arrChildren.clear(); - } - - // the component name, not including the parents' names - string strName; - // the index of the parent, 0 being the root - size_t nParent; - // the number of objects within this component - size_t numObjects; - // the size of the objects belonging to this component, in bytes - size_t sizeObjects; - // the total size of all objects; gets filled by the end() method of the CrySizerImpl - size_t sizeObjectsTotal; - // the children components - DynArray arrChildren; - }; - typedef DynArray NameArray; - NameArray m_arrNames; - - - - // the set of objects and their sizes: the key is the object address/id, - // the value is the size of the object and its name (the index of the name actually) - struct Object - { - const void* pId; // unique pointer identifying the object in memory - size_t nSize; // the size of the object in bytes - size_t nName; // the index of the name in the name array - - Object () - {clear(); } - - Object (const void* id, size_t size = 0, size_t name = 0) - : pId(id) - , nSize(size) - , nName(name) {} - - // the objects are sorted by their Id - bool operator < (const Object& right) const {return (UINT_PTR)pId < (UINT_PTR)right.pId; } - bool operator < (const void* right) const {return (UINT_PTR)pId < (UINT_PTR)right; } - //friend bool operator < (const void* left, const Object& right); - - bool operator == (const Object& right) const {return pId == right.pId; } - - void clear() - { - pId = NULL; - nSize = 0; - nName = 0; - } - }; - typedef std::set ObjectSet; - // 2^g_nHashPower == the number of subsets comprising the hash - - enum - { - g_nHashPower = 12 - }; - - // hash size (number of subsets) - enum - { - g_nHashSize = 1 << g_nHashPower - }; - // hash function for an address; returns value 0..1< 0x10000000 ? 0 : nMinSubcomponentBytes) -{ -} - - -// creates the map of names from old (in the sizer Impl) to new (in the Stats) -void CrySizerStatsBuilder::processNames() -{ - size_t numCompNames = m_pSizer->m_arrNames.size(); - m_pStats->m_arrComponents.reserve (numCompNames); - m_pStats->m_arrComponents.clear(); - - m_mapNames.resize (numCompNames, (size_t)-1); - - // add all root objects - addNameSubtree(0, 0); -} - - -////////////////////////////////////////////////////////////////////////// -// given the name in the old system, adds the subtree of names to the -// name map and components. In case all the subtree is empty, returns false and -// adds nothing -size_t CrySizerStatsBuilder::addNameSubtree (unsigned nDepth, size_t nName) -{ - assert ((int)nName < m_pSizer->m_arrNames.size()); - - CrySizerImpl::ComponentName& rCompName = m_pSizer->m_arrNames[nName]; - size_t sizeObjectsTotal = rCompName.sizeObjectsTotal; - - if (sizeObjectsTotal <= m_nMinSubcomponentBytes) - { - return sizeObjectsTotal; // the subtree didn't pass - } - // the index of the component in the stats object (sorted by the depth-first traverse order) - size_t nNewName = m_pStats->m_arrComponents.size(); - m_pStats->m_arrComponents.resize (nNewName + 1); - - Component& rNewComp = m_pStats->m_arrComponents[nNewName]; - rNewComp.strName = rCompName.strName; - rNewComp.nDepth = nDepth; - rNewComp.numObjects = rCompName.numObjects; - rNewComp.sizeBytes = rCompName.sizeObjects; - rNewComp.sizeBytesTotal = sizeObjectsTotal; - m_mapNames[nName] = nNewName; - - // find the immediate children and sort them by their total size - typedef std::map UintUintMap; - UintUintMap mapSizeName; // total size -> child index (name in old indexation) - - for (int i = nName + 1; i < m_pSizer->m_arrNames.size(); ++i) - { - CrySizerImpl::ComponentName& rChild = m_pSizer->m_arrNames[i]; - if (rChild.nParent == nName && rChild.sizeObjectsTotal > m_nMinSubcomponentBytes) - { - mapSizeName.insert (UintUintMap::value_type(rChild.sizeObjectsTotal, i)); - } - } - - // add the sorted components - /* - for (unsigned i = nName + 1; i < m_pSizer->m_arrNames.size(); ++i) - if (m_pSizer->m_arrNames[i].nParent == nName) - addNameSubtree(nDepth+1,i); - */ - - for (UintUintMap::reverse_iterator it = mapSizeName.rbegin(); it != mapSizeName.rend(); ++it) - { - addNameSubtree(nDepth + 1, it->second); - } - - return sizeObjectsTotal; -} - - -////////////////////////////////////////////////////////////////////////// -// creates the statistics out of the given CrySizerImpl into the given CrySizerStats -// Maps the old to new names according to the depth-walk tree rule -void CrySizerStatsBuilder::build (CrySizerStats* pStats) -{ - m_pStats = pStats; - - m_mapNames.clear(); - - processNames(); - - m_pSizer->clear(); - pStats->refresh(); - pStats->m_nAgeFrames = 0; -} - - -////////////////////////////////////////////////////////////////////////// -// constructs the statistics based on the given cry sizer -CrySizerStats::CrySizerStats (CrySizerImpl* pCrySizer) -{ - CrySizerStatsBuilder builder (pCrySizer); - builder.build(this); -} - -CrySizerStats::CrySizerStats () - : m_nStartRow(0) -{ -} - -void CrySizerStats::updateKeys() -{ - const unsigned int statSize = size(); - //assume 10 pixels for font - unsigned int height = gEnv->pRenderer->GetHeight() / 12; - if (CryGetAsyncKeyState(VK_UP)) - { - if (m_nStartRow > 0) - { - --m_nStartRow; - } - } - if (CryGetAsyncKeyState(VK_DOWN)) - { - if (statSize > height + m_nStartRow) - { - ++m_nStartRow; - } - } - if (CryGetAsyncKeyState(VK_RIGHT) & 1) - { - //assume 10 pixels for font - if (statSize > height) - { - m_nStartRow = statSize - height; - } - } - if (CryGetAsyncKeyState(VK_LEFT) & 1) - { - m_nStartRow = 0; - } -} - -// if there is already such name in the map, then just returns the index -// of the compoentn in the component array; otherwise adds an entry to themap -// and to the component array nad returns its index -CrySizerStatsBuilder::Component& CrySizerStatsBuilder::mapName (unsigned nName) -{ - assert (m_mapNames[nName] != -1); - return m_pStats->m_arrComponents[m_mapNames[nName]]; - /* - IdToIdMap::iterator it = m_mapNames.find (nName); - if (it == m_mapNames.end()) - { - unsigned nNewName = m_arrComponents.size(); - m_mapNames.insert (IdToIdMap::value_type(nName, nNewName)); - m_arrComponents.resize(nNewName + 1); - m_arrComponents[nNewName].strName.swap(m_pSizer->m_arrNames[nName]); - return m_arrComponents.back(); - } - else - { - assert (it->second < m_arrComponents.size()); - return m_arrComponents[it->second]; - } - */ -} - -// refreshes the statistics built after the component array is built -void CrySizerStats::refresh() -{ - m_nMaxNameLength = 0; - for (size_t i = 0; i < m_arrComponents.size(); ++i) - { - size_t nLength = m_arrComponents[i].strName.length() + m_arrComponents[i].nDepth; - if (nLength > m_nMaxNameLength) - { - m_nMaxNameLength = nLength; - } - } -} - - -bool CrySizerStats::Component::GenericOrder::operator () (const Component& left, const Component& right) const -{ - return left.strName < right.strName; -} - - -CrySizerStatsRenderer::CrySizerStatsRenderer (ISystem* pSystem, CrySizerStats* pStats, unsigned nMaxSubcomponentDepth, int nMinSubcomponentBytes) - : m_pStats(pStats) - , m_pRenderer(pSystem->GetIRenderer()) - , m_pLog (pSystem->GetILog()) - , m_pTextModeConsole(pSystem->GetITextModeConsole()) - , m_nMinSubcomponentBytes (nMinSubcomponentBytes < 0 || nMinSubcomponentBytes > 0x10000000 ? 0x8000 : nMinSubcomponentBytes) - , m_nMaxSubcomponentDepth (nMaxSubcomponentDepth) -{ -} - - -static void DrawStatsText(float x, float y, float fScale, float color[4], const char* format, ...) -{ - va_list args; - va_start(args, format); - SDrawTextInfo ti; - ti.xscale = fScale; - ti.yscale = fScale; - ti.color[0] = color[0]; - ti.color[1] = color[1]; - ti.color[2] = color[2]; - ti.color[3] = color[3]; - ti.flags = eDrawText_2D | eDrawText_FixedSize | eDrawText_Monospace; - gEnv->pRenderer->DrawTextQueued(Vec3(x, y, 0.5f), ti, format, args); - va_end(args); -} - -void CrySizerStatsRenderer::render(bool bRefreshMark) -{ - if (!m_pStats->size()) - { - return; - } - - int x, y, dx, dy; - m_pRenderer->GetViewport(&x, &y, &dx, &dy); - - // left coordinate of the text - unsigned nNameWidth = (unsigned)(m_pStats->getMaxNameLength() + 1); - if (nNameWidth < 25) - { - nNameWidth = 25; - } - float fCharScaleX = 1.2f; - float fLeft = 0; - float fTop = 8; - float fVStep = 9; - -#ifdef _DEBUG - const char* szCountStr1 = "count"; - const char* szCountStr2 = "_____"; -#else // _DEBUG - const char* szCountStr1 = "", * szCountStr2 = ""; -#endif // _DEBUG - - float fTextColor[4] = {0.9f, 0.85f, 1, 0.85f}; - DrawStatsText(fLeft, fTop, fCharScaleX, fTextColor, - "%-*s total partial %s", nNameWidth, bRefreshMark ? "Memory usage (refresh*)" : "Memory usage (refresh )", szCountStr1); - DrawStatsText(fLeft, fTop + fVStep * 0.25f, fCharScaleX, fTextColor, - "%*s _____ _______ %s", nNameWidth, "", szCountStr2); - - unsigned nSubgroupDepth = 1; - - // different colors used to paint the statistics subgroups - // a new statistic subgroup starts with a new subtree of depth <= specified - float fGray = 0;//0.45f; - float fLightGray = 0.5f;//0.8f; - float fColors[] = - { - fLightGray, fLightGray, fGray, 1, - 1, 1, 1, 1, - fGray, 1, 1, 1, - 1, fGray, 1, 1, - 1, 1, fGray, 1, - fGray, fLightGray, 1, 1, - fGray, 1, fGray, 1, - 1, fGray, fGray, 1 - }; - float* pColor = fColors; - - unsigned statSize = m_pStats->size(); - unsigned startRow = m_pStats->row(); - unsigned i = 0; - for (; i < startRow; ++i) - { - const Component& rComp = (*m_pStats)[i]; - if (rComp.nDepth <= nSubgroupDepth) - { - //switch the color - pColor += 4; - if (pColor >= fColors + sizeof(fColors) / sizeof(fColors[0])) - { - pColor = fColors; - } - - fTop += fVStep * (0.333333f + (nSubgroupDepth - rComp.nDepth) * 0.15f); - } - } - - for (unsigned r = startRow; i < statSize; ++i) - { - const Component& rComp = (*m_pStats)[i]; - if (rComp.nDepth <= nSubgroupDepth) - { - //switch the color - pColor += 4; - if (pColor >= fColors + sizeof(fColors) / sizeof(fColors[0])) - { - pColor = fColors; - } - - fTop += fVStep * (0.333333f + (nSubgroupDepth - rComp.nDepth) * 0.15f); - } - - if (rComp.sizeBytesTotal <= m_nMinSubcomponentBytes || rComp.nDepth > m_nMaxSubcomponentDepth) - { - continue; - } - - fTop += fVStep; - - char szDepth[32] = " .............................."; - if (rComp.nDepth < sizeof(szDepth)) - { - szDepth[rComp.nDepth] = '\0'; - } - - char szSize[32]; - if (rComp.sizeBytes > 0) - { - if (rComp.sizeBytesTotal > rComp.sizeBytes) - { - azsprintf(szSize, "%7.3f %7.3f", rComp.getTotalSizeMBytes(), rComp.getSizeMBytes()); - } - else - { - azsprintf(szSize, " %7.3f", rComp.getSizeMBytes()); - } - } - else - { - assert (rComp.sizeBytesTotal > 0); - azsprintf(szSize, "%7.3f ", rComp.getTotalSizeMBytes()); - } - char szCount[16]; -#ifdef _DEBUG - if (rComp.numObjects) - { - azsprintf(szCount, "%zd" PRIu64 "", rComp.numObjects); - } - else -#endif - szCount[0] = '\0'; - - DrawStatsText(fLeft, fTop, fCharScaleX, pColor, - "%s%-*s:%s%s", szDepth, nNameWidth - rComp.nDepth, rComp.strName.c_str(), szSize, szCount); - - if (m_pTextModeConsole) - { - string text; - text.Format("%s%-*s:%s%s", szDepth, nNameWidth - rComp.nDepth, rComp.strName.c_str(), szSize, szCount); - m_pTextModeConsole->PutText(0, r++, text.c_str()); - } - } - - float fLTGrayColor[4] = {fLightGray, fLightGray, fLightGray, 1.0f}; - fTop += 0.25f * fVStep; - DrawStatsText(fLeft, fTop, fCharScaleX, fLTGrayColor, - "%-*s %s", nNameWidth, "___________________________", "________________"); - fTop += fVStep; - - const char* szOverheadNames[CrySizerStats::g_numTimers] = - { - ".Collection", - ".Transformation", - ".Cleanup" - }; - bool bOverheadsHeaderPrinted = false; - for (i = 0; i < CrySizerStats::g_numTimers; ++i) - { - float fTime = m_pStats->getTime(i); - if (fTime < 20) - { - continue; - } - // print the header - if (!bOverheadsHeaderPrinted) - { - DrawStatsText(fLeft, fTop, fCharScaleX, fTextColor, - "%-*s", nNameWidth, "Overheads"); - fTop += fVStep; - bOverheadsHeaderPrinted = true; - } - - DrawStatsText(fLeft, fTop, fCharScaleX, fTextColor, - "%-*s:%7.1f ms", nNameWidth, szOverheadNames[i], fTime); - fTop += fVStep; - } -} - -void CrySizerStatsRenderer::dump(bool bUseKB) -{ - if (!m_pStats->size()) - { - return; - } - - unsigned nNameWidth = (unsigned)(m_pStats->getMaxNameLength() + 1); - - // left coordinate of the text - m_pLog->LogToFile ("Memory Statistics: %s", bUseKB ? "KB" : "MB"); - m_pLog->LogToFile("%-*s TOTAL partial count", nNameWidth, ""); - - // different colors used to paint the statistics subgroups - // a new statistic subgroup starts with a new subtree of depth <= specified - - for (unsigned i = 0; i < m_pStats->size(); ++i) - { - const Component& rComp = (*m_pStats)[i]; - - if (rComp.sizeBytesTotal <= m_nMinSubcomponentBytes || rComp.nDepth > m_nMaxSubcomponentDepth) - { - continue; - } - - char szDepth[32] = " .............................."; - if (rComp.nDepth < sizeof(szDepth)) - { - szDepth[rComp.nDepth] = '\0'; - } - - char szSize[32]; - if (rComp.sizeBytes > 0) - { - if (rComp.sizeBytesTotal > rComp.sizeBytes) - { - azsprintf(szSize, bUseKB ? "%7.2f %7.2f" : "%7.3f %7.3f", bUseKB ? rComp.getTotalSizeKBytes() : rComp.getTotalSizeMBytes(), bUseKB ? rComp.getSizeKBytes() : rComp.getSizeMBytes()); - } - else - { - azsprintf(szSize, bUseKB ? " %7.2f" : " %7.3f", bUseKB ? rComp.getSizeKBytes() : rComp.getSizeMBytes()); - } - } - else - { - assert (rComp.sizeBytesTotal > 0); - azsprintf(szSize, bUseKB ? "%7.2f " : "%7.3f ", bUseKB ? rComp.getTotalSizeKBytes() : rComp.getTotalSizeMBytes()); - } - char szCount[16]; - - if (rComp.numObjects) - { - azsprintf(szCount, "%8u", (unsigned int)rComp.numObjects); - } - else - { - szCount[0] = '\0'; - } - - m_pLog->LogToFile ("%s%-*s:%s%s", szDepth, nNameWidth - rComp.nDepth, rComp.strName.c_str(), szSize, szCount); - } -} - - -void CrySizerStats::startTimer(unsigned nTimer, ITimer* pTimer) -{ - assert (nTimer < g_numTimers); - m_fTime[nTimer] = pTimer->GetAsyncCurTime(); -} - -void CrySizerStats::stopTimer(unsigned nTimer, ITimer* pTimer) -{ - assert (nTimer < g_numTimers); - m_fTime[nTimer] = 1000 * (pTimer->GetAsyncCurTime() - m_fTime[nTimer]); -} diff --git a/Code/CryEngine/CrySystem/CrySizerStats.h b/Code/CryEngine/CrySystem/CrySizerStats.h deleted file mode 100644 index fc8c43a7c2..0000000000 --- a/Code/CryEngine/CrySystem/CrySizerStats.h +++ /dev/null @@ -1,207 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// Description : Declaration of the CrySizerStats class, which is used to -// calculate the memory usage by the subsystems and components, to help -// the artists keep the memory budged low. - -#ifndef CRYINCLUDE_CRYSYSTEM_CRYSIZERSTATS_H -#define CRYINCLUDE_CRYSYSTEM_CRYSIZERSTATS_H -#pragma once - - -class CrySizerImpl; - -////////////////////////////////////////////////////////////////////////// -// This class holds only the necessary statistics data, which can be carried -// over a few frames without significant impact on memory usage -// CrySizerImpl is an implementation of ICrySizer, which is used to collect -// those data; it must be destructed immediately after constructing the Stats -// object to avoid excessive memory usage. -class CrySizerStats -{ -public: - // constructs the statistics based on the given cry sizer - CrySizerStats (CrySizerImpl* pCrySizer); - - CrySizerStats (); - - // this structure describes one component of the memory size statistics - struct Component - { - Component() {clear(); } - Component (const string& name, unsigned size = 0, unsigned num = 0) - : strName(name) - , sizeBytes(size) - , numObjects(num) - , nDepth(0) {} - void clear() - { - strName = ""; - sizeBytes = 0; - numObjects = 0; - nDepth = 0; - } - - // the name of the component, as it appeared in the push() call - string strName; - // the total size, in bytes, of objects in the component - size_t sizeBytes; - // the total size including the subcomponents - size_t sizeBytesTotal; - // the number of objects allocated - size_t numObjects; - unsigned nDepth; - - float getSizeKBytes() const {return sizeBytes / float(1 << 10); } - - float getTotalSizeKBytes () const {return sizeBytesTotal / float(1 << 10); } - - float getSizeMBytes() const {return sizeBytes / float(1 << 20); } - - float getTotalSizeMBytes () const {return sizeBytesTotal / float(1 << 20); } - - struct NameOrder - { - bool operator () (const Component& left, const Component& right) const {return left.strName < right.strName; } - }; - - struct SizeOrder - { - bool operator () (const Component& left, const Component& right) const {return left.sizeBytes < right.sizeBytes; } - }; - - struct GenericOrder - { - bool operator () (const Component& left, const Component& right) const; - }; - }; - - // returns the number of different subsystems/components used - unsigned numComponents() const {return (unsigned)m_arrComponents.size(); } - // returns the name of the i-th component - const Component& getComponent(unsigned nComponent) const {return m_arrComponents[nComponent]; } - - unsigned size() const {return numComponents(); } - const Component& operator [] (unsigned i) const {return getComponent(i); } - const Component& operator [] (signed i) const {return getComponent(i); } - - unsigned row() const {return m_nStartRow; } - void updateKeys(); - - size_t getMaxNameLength() const {return m_nMaxNameLength; } - enum - { - g_numTimers = 3 - }; - - void startTimer(unsigned nTimer, ITimer* pTimer); - void stopTimer(unsigned nTimer, ITimer* pTimer); - float getTime(unsigned nTimer) const {assert (nTimer < g_numTimers); return m_fTime[nTimer]; } - int getAgeFrames() const {return m_nAgeFrames; } - void incAgeFrames() {++m_nAgeFrames; } -protected: - // refreshes the statistics built after the component array is built - void refresh(); -protected: - // the names of the components - typedef std::vector ComponentArray; - ComponentArray m_arrComponents; - - // the maximum length of the component name, in characters - size_t m_nMaxNameLength; - - // the timer that counts the time spent on statistics gathering - float m_fTime[g_numTimers]; - - // the age of the statistics, in frames - int m_nAgeFrames; - - //current row offset inc/dec by cursor keys - unsigned m_nStartRow; - - friend class CrySizerStatsBuilder; -}; - - -////////////////////////////////////////////////////////////////////////// -// this is the constructor for the CrySizerStats -class CrySizerStatsBuilder -{ -public: - CrySizerStatsBuilder (CrySizerImpl* pSizer, int nMinSubcomponentBytes = 0); - - void build (CrySizerStats* pStats); - -protected: - typedef CrySizerStats::Component Component; - // if there is already such name in the map, then just returns the index - // of the compoentn in the component array; otherwise adds an entry to themap - // and to the component array nad returns its index - Component& mapName (unsigned nName); - - // creates the map of names from old to new, and initializes the components themselves - void processNames(); - - // given the name in the old system, adds the subtree of names to the - // name map and components. In case all the subtree is empty, returns 0 and - // adds nothing. Otherwise, returns the total size of objects belonging to the - // subtree - size_t addNameSubtree (unsigned nDepth, size_t nName); - -protected: - CrySizerStats* m_pStats; - CrySizerImpl* m_pSizer; - - // this is the mapping from the old names into the new componentn indices - typedef std::vector IdToIdMap; - // from old to new - IdToIdMap m_mapNames; - - // this is the threshold: if the total number of bytes in the subcomponent - // is less than this, the subcomponent isn't shown - unsigned m_nMinSubcomponentBytes; -}; - - - -////////////////////////////////////////////////////////////////////////// -// Renders the given usage stats; gets created upon every rendering -class CrySizerStatsRenderer -{ -public: - // constructor - CrySizerStatsRenderer (ISystem* pSystem, CrySizerStats* pStats, unsigned nMaxDepth = 2, int nMinSubcomponentBytes = -1); - void render(bool bRefreshMark = false); - // dumps it to log. uses MB as default - void dump (bool bUseKB = false); - -protected: // ------------------------------------------------- - - typedef CrySizerStats::Component Component; - - IRenderer* m_pRenderer; // - ILog* m_pLog; // - CrySizerStats* m_pStats; // - - ITextModeConsole* m_pTextModeConsole; - - // this is the threshold: if the total number of bytes in the subcomponent - // is less than this, the subcomponent isn't shown - unsigned m_nMinSubcomponentBytes; - - // the max depth of the branch to output - unsigned m_nMaxSubcomponentDepth; -}; - -#endif // CRYINCLUDE_CRYSYSTEM_CRYSIZERSTATS_H diff --git a/Code/CryEngine/CrySystem/DebugCallStack.cpp b/Code/CryEngine/CrySystem/DebugCallStack.cpp index da3876a422..f33e793db6 100644 --- a/Code/CryEngine/CrySystem/DebugCallStack.cpp +++ b/Code/CryEngine/CrySystem/DebugCallStack.cpp @@ -287,18 +287,6 @@ int DebugCallStack::handleException(EXCEPTION_POINTERS* exception_pointer) gEnv->szDebugStatus[SSystemGlobalEnvironment::MAX_DEBUG_STRING_LENGTH - 1] = '\0'; WriteLineToLog("Debug Status: %s", gEnv->szDebugStatus); } - - if (gEnv->pRenderer) - { - ID3DDebugMessage* pMsg = 0; - gEnv->pRenderer->EF_Query(EFQ_GetLastD3DDebugMessage, pMsg); - if (pMsg) - { - const char* pStr = pMsg->GetMessage(); - WriteLineToLog("Last D3D debug message: %s", pStr ? pStr : "#unknown#"); - SAFE_RELEASE(pMsg); - } - } } firstTime = false; @@ -832,17 +820,6 @@ int DebugCallStack::SubmitBug(EXCEPTION_POINTERS* exception_pointer) assert(!hwndException); - // If in full screen minimize render window - { - ICVar* pFullscreen = (gEnv && gEnv->pConsole) ? gEnv->pConsole->GetCVar("r_Fullscreen") : 0; - if (pFullscreen && pFullscreen->GetIVal() != 0 && gEnv->pRenderer && gEnv->pRenderer->GetHWND()) - { - ::ShowWindow((HWND)gEnv->pRenderer->GetHWND(), SW_MINIMIZE); - } - } - - //hwndException = CreateDialog( gDLLHandle,MAKEINTRESOURCE(IDD_EXCEPTION),NULL,NULL ); - RemoveOldFiles(); AZ::Debug::Trace::PrintCallstack("", 2); diff --git a/Code/CryEngine/CrySystem/DefragAllocator.cpp b/Code/CryEngine/CrySystem/DefragAllocator.cpp deleted file mode 100644 index 8858724be1..0000000000 --- a/Code/CryEngine/CrySystem/DefragAllocator.cpp +++ /dev/null @@ -1,1976 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "CrySystem_precompiled.h" -#include "DefragAllocator.h" -#include "IRenderAuxGeom.h" - -CDefragAllocatorWalker::CDefragAllocatorWalker(CDefragAllocator& alloc) -{ - m_pAlloc = &alloc; - m_pAlloc->m_lock.Lock(); - - m_nChunkIdx = CDefragAllocator::AddrStartSentinal; -} - -CDefragAllocatorWalker::~CDefragAllocatorWalker() -{ - m_pAlloc->m_lock.Unlock(); -} - -const SDefragAllocChunk* CDefragAllocatorWalker::Next() -{ - m_nChunkIdx = m_pAlloc->m_chunks[m_nChunkIdx].addrNextIdx; - if (m_nChunkIdx == CDefragAllocator::AddrEndSentinal) - { - return NULL; - } - return &m_pAlloc->m_chunks[m_nChunkIdx]; -} - -CDefragAllocator::CDefragAllocator() - : m_isThreadSafe(false) - , m_chunksAreFixed(false) - , m_capacity(0) - , m_available(0) - , m_numAllocs(0) - , m_minAlignment(1) - , m_logMinAlignment(0) - , m_nCancelledMoves(0) -{ -} - -CDefragAllocator::~CDefragAllocator() -{ -} - -void CDefragAllocator::Release(bool bDiscard) -{ - if (!bDiscard) - { - if (m_policy.pDefragPolicy) - { - Defrag_CompletePendingMoves(); - } - - for (PendingMoveVec::iterator it = m_pendingMoves.begin(), itEnd = m_pendingMoves.end(); it != itEnd; ++it) - { - CDBA_ASSERT(it->dstChunkIdx == InvalidChunkIdx); - } - } - - delete this; -} - -void CDefragAllocator::Init(UINT_PTR capacity, UINT_PTR minAlignment, const Policy& policy) -{ - CDBA_ASSERT((capacity & (minAlignment - 1)) == 0); - CDBA_ASSERT((minAlignment & (minAlignment - 1)) == 0); - CDBA_ASSERT(!policy.pDefragPolicy || policy.maxAllocs > 0); - CDBA_ASSERT((capacity / minAlignment) < (1 << SDefragAllocChunkAttr::SizeWidth)); - - uint32 logMinAlignment = (uint32)IntegerLog2(minAlignment); - - capacity >>= logMinAlignment; - - CDBA_ASSERT(capacity <= (uint32) - 1); - - m_isThreadSafe = policy.pDefragPolicy != NULL; - - m_capacity = (uint32)capacity; - m_available = (uint32)capacity; - m_numAllocs = 0; - - m_minAlignment = (uint32)minAlignment; - m_logMinAlignment = logMinAlignment; - - m_chunks.clear(); - m_unusedChunks.clear(); - - m_policy = policy; - if (policy.pDefragPolicy) - { - m_pendingMoves.resize(MaxPendingMoves); - } - - m_chunks.reserve(NumBuckets + 3); - - // Create sentinal chunk for by-address list - { - SDefragAllocChunk addrStartSentinal = {0}; - addrStartSentinal.addrNextIdx = 1; - addrStartSentinal.addrPrevIdx = 1; - addrStartSentinal.attr.SetBusy(true); - addrStartSentinal.ptr = 0; - m_chunks.push_back(addrStartSentinal); - - SDefragAllocChunk addrEndSentinal = {0}; - addrEndSentinal.addrNextIdx = 0; - addrEndSentinal.addrPrevIdx = 0; - addrEndSentinal.attr.SetBusy(true); - addrEndSentinal.ptr = m_capacity; - m_chunks.push_back(addrEndSentinal); - } - - SDefragAllocSegment seg; - seg.address = 0; - seg.capacity = (uint32)capacity; - seg.headSentinalChunkIdx = AddrStartSentinal; - - // Create sentinal chunks for the bucket lists - for (size_t bucketIdx = 0; bucketIdx < NumBuckets; ++bucketIdx) - { - Index chunkIdx = bucketIdx + 2; - - SDefragAllocChunk chunk = {0}; - chunk.attr.SetBusy(true); - chunk.freeNextIdx = chunkIdx; - chunk.freePrevIdx = chunkIdx; - - m_freeBuckets[bucketIdx] = chunkIdx; - m_chunks.push_back(chunk); - } - - Index totalChunkIdx = AllocateChunk(); - SDefragAllocChunk& totalChunk = m_chunks[totalChunkIdx]; - totalChunk.attr.SetSize((unsigned int)capacity); - totalChunk.attr.SetPinCount(0); - totalChunk.attr.SetMoving(0); - LinkAddrChunk(totalChunkIdx, 0); - LinkFreeChunk(totalChunkIdx); - - if (policy.maxAllocs > 0) - { - size_t curChunksSize = m_chunks.size(); - m_chunks.resize(policy.maxAllocs); - for (Index i = (Index)curChunksSize, c = (Index)m_chunks.size(); i < c; ++i) - { - m_unusedChunks.push_back(i); - } - } - - m_chunksAreFixed = policy.pDefragPolicy != NULL; - - m_segments.reserve(policy.maxSegments); - m_segments.push_back(seg); -} - -#ifndef _RELEASE -void CDefragAllocator::DumpState(const char* filename) -{ - CryOptionalAutoLock lock(m_lock, m_isThreadSafe); - - FILE* fp = nullptr; - azfopen(&fp, filename, "wb"); - if (fp) - { - uint32 magic = 0xdef7a6e7; - fwrite(&magic, sizeof(magic), 1, fp); - - fwrite(&m_capacity, sizeof(m_capacity), 1, fp); - fwrite(&m_available, sizeof(m_available), 1, fp); - fwrite(&m_numAllocs, sizeof(m_numAllocs), 1, fp); - fwrite(&m_minAlignment, sizeof(m_minAlignment), 1, fp); - fwrite(&m_logMinAlignment, sizeof(m_logMinAlignment), 1, fp); - fwrite(&m_freeBuckets[0], sizeof(m_freeBuckets), 1, fp); - - uint32 numChunks = (uint32)m_chunks.size(); - fwrite(&numChunks, sizeof(numChunks), 1, fp); - fwrite(&m_chunks[0], sizeof(m_chunks[0]), numChunks, fp); - uint32 numUnused = (uint32)m_unusedChunks.size(); - fwrite(&numUnused, sizeof(numUnused), 1, fp); - fwrite(&m_unusedChunks[0], sizeof(m_unusedChunks[0]), numUnused, fp); - uint32 numPending = (uint32)m_pendingMoves.size(); - fwrite(&numPending, sizeof(numPending), 1, fp); - fwrite(&m_pendingMoves[0], sizeof(m_pendingMoves[0]), numPending, fp); - uint32 numSegs = (uint32)m_segments.size(); - fwrite(&numSegs, sizeof(numSegs), 1, fp); - fwrite(&m_segments[0], sizeof(m_segments[0]), numSegs, fp); - - fclose(fp); - } -} - -void CDefragAllocator::RestoreState(const char* filename) -{ - CryOptionalAutoLock lock(m_lock, m_isThreadSafe); - - FILE* fp = nullptr; - azfopen(&fp, filename, "rb"); - if (fp) - { - uint32 magic; - fread(&magic, sizeof(magic), 1, fp); - - bool bSwap = magic == 0xe7a6f7de; - - fread(&m_capacity, sizeof(m_capacity), 1, fp); - SwapEndian(m_capacity, bSwap); - - fread(&m_available, sizeof(m_available), 1, fp); - SwapEndian(m_available, bSwap); - - fread(&m_numAllocs, sizeof(m_numAllocs), 1, fp); - SwapEndian(m_numAllocs, bSwap); - - fread(&m_minAlignment, sizeof(m_minAlignment), 1, fp); - SwapEndian(m_minAlignment, bSwap); - - fread(&m_logMinAlignment, sizeof(m_logMinAlignment), 1, fp); - SwapEndian(m_logMinAlignment, bSwap); - - fread(&m_freeBuckets[0], sizeof(m_freeBuckets), 1, fp); - SwapEndian(&m_freeBuckets[0], NumBuckets, bSwap); - - uint32 numChunks; - fread(&numChunks, sizeof(numChunks), 1, fp); - SwapEndian(numChunks, bSwap); - - m_chunks.resize(numChunks); - fread(&m_chunks[0], sizeof(m_chunks[0]), numChunks, fp); - if (bSwap) - { - for (size_t ci = 0, cc = m_chunks.size(); ci != cc; ++ci) - { - m_chunks[ci].SwapEndian(); - } - } - - uint32 numUnused; - fread(&numUnused, sizeof(numUnused), 1, fp); - SwapEndian(numUnused, bSwap); - - m_unusedChunks.resize(numUnused); - fread(&m_unusedChunks[0], sizeof(m_unusedChunks[0]), numUnused, fp); - SwapEndian(&m_unusedChunks[0], m_unusedChunks.size(), bSwap); - - uint32 numPending; - fread(&numPending, sizeof(numPending), 1, fp); - SwapEndian(numPending, bSwap); - - m_pendingMoves.resize(numPending); - fread(&m_pendingMoves[0], sizeof(m_pendingMoves[0]), numPending, fp); - if (bSwap) - { - for (size_t pi = 0, pc = m_pendingMoves.size(); pi != pc; ++pi) - { - m_pendingMoves[pi].SwapEndian(); - } - } - - uint32 numSegs; - fread(&numSegs, sizeof(numSegs), 1, fp); - SwapEndian(numSegs, bSwap); - - m_segments.resize(numSegs); - fread(&m_segments[0], sizeof(m_segments[0]), numSegs, fp); - if (bSwap) - { - for (size_t si = 0, sc = m_segments.size(); si != sc; ++si) - { - m_segments[si].SwapEndian(); - } - } - - fclose(fp); - - RebuildFreeLists(); - -#ifdef CDBA_MORE_DEBUG - ValidateAddressChain(); - ValidateFreeLists(); -#endif - } -} -#endif - -bool CDefragAllocator::AppendSegment(UINT_PTR capacity) -{ - CDBA_ASSERT((capacity & (m_minAlignment - 1)) == 0); - - bool bSuccessful = false; - - CryOptionalAutoLock lock(m_lock, m_isThreadSafe); - - capacity >>= m_logMinAlignment; - - // Create a sentinal chunk for the head of the new segment. - Index headSentinalIdx = AllocateChunk(); - if (headSentinalIdx != InvalidChunkIdx) - { - // And a free block. - Index freeBlockIdx = AllocateChunk(); - if (freeBlockIdx != InvalidChunkIdx) - { - SDefragAllocChunk& headSentinalChunk = m_chunks[headSentinalIdx]; - SDefragAllocChunk& freeChunk = m_chunks[freeBlockIdx]; - SDefragAllocChunk& addrEndSentinal = m_chunks[AddrEndSentinal]; - - uint32 allocCapacity = m_capacity; - - headSentinalChunk.ptr = allocCapacity; -#ifndef _RELEASE - headSentinalChunk.source = "Segment Sentinal"; -#endif - headSentinalChunk.attr.SetBusy(true); - headSentinalChunk.attr.SetMoving(false); - headSentinalChunk.attr.SetPinCount(1); - headSentinalChunk.attr.SetSize(0); - - freeChunk.ptr = allocCapacity; - freeChunk.attr.SetBusy(false); - freeChunk.attr.SetMoving(false); - freeChunk.attr.SetPinCount(0); - freeChunk.attr.SetSize((unsigned int)capacity); - - LinkAddrChunk(headSentinalIdx, addrEndSentinal.addrPrevIdx); - LinkAddrChunk(freeBlockIdx, headSentinalIdx); - LinkFreeChunk(freeBlockIdx); - addrEndSentinal.ptr = allocCapacity + (uint32)capacity; - - SDefragAllocSegment seg; - seg.address = allocCapacity; - seg.capacity = (uint32)capacity; - seg.headSentinalChunkIdx = headSentinalIdx; - m_segments.push_back(seg); - - m_capacity = allocCapacity + (uint32)capacity; - m_available += (uint32)capacity; - bSuccessful = true; - -#ifdef CDBA_MORE_DEBUG - ValidateAddressChain(); -#endif - } - else - { - ReleaseChunk(headSentinalIdx); - } - } - - return bSuccessful; -} - -void CDefragAllocator::UnAppendSegment() -{ - CryOptionalAutoLock lock(m_lock, m_isThreadSafe); - - // Can't remove the last segment! - CDBA_ASSERT(m_segments.size() > 1); - - [[maybe_unused]] bool bHasMoves = Defrag_CompletePendingMoves(); - - // All outstanding moves should be completed. - CDBA_ASSERT(!bHasMoves); - - // Move all live chunks from this segment into another. - SyncMoveSegment((uint32)m_segments.size() - 1); - - SDefragAllocSegment& segment = m_segments.back(); - SDefragAllocChunk& headSentinalChunk = m_chunks[segment.headSentinalChunkIdx]; - - // Assert that the segment is empty, and release all chunks within it. - uint32 endAddress = m_capacity; - Index chunkIdx = headSentinalChunk.addrNextIdx; - - UnlinkAddrChunk(segment.headSentinalChunkIdx); - ReleaseChunk(segment.headSentinalChunkIdx); - - SDefragAllocChunk* pChunk = &m_chunks[chunkIdx]; - - while (pChunk->ptr != endAddress) - { - CDBA_ASSERT(!pChunk->attr.IsBusy()); - - Index nextChunkIdx = pChunk->addrNextIdx; - - UnlinkFreeChunk(chunkIdx); - UnlinkAddrChunk(chunkIdx); - ReleaseChunk(chunkIdx); - - chunkIdx = nextChunkIdx; - pChunk = &m_chunks[chunkIdx]; - } - - // chunkIdx/pChunk should be the end of memory sentinal. - CDBA_ASSERT(chunkIdx == AddrEndSentinal && pChunk->attr.IsBusy() && !pChunk->attr.GetSize()); - - pChunk->ptr -= segment.capacity; - - m_capacity -= segment.capacity; - m_available -= segment.capacity; - m_segments.pop_back(); -} - -IDefragAllocator::Hdl CDefragAllocator::Allocate(size_t sz, const char* source, void* pContext) -{ - CDBA_ASSERT((IntegerLog2(NextPower2(Align(sz, m_minAlignment))) - m_logMinAlignment) < (1u << SDefragAllocChunkAttr::SizeWidth)); - - CryOptionalAutoLock lock(m_lock, m_isThreadSafe); - return Allocate_Locked(sz, m_minAlignment, source, pContext); -} - -IDefragAllocator::Hdl CDefragAllocator::AllocateAligned(size_t sz, size_t alignment, const char* source, void* pContext) -{ - alignment = max((size_t)m_minAlignment, alignment); - - // Just to check the alignment can be stored - CDBA_ASSERT((IntegerLog2(alignment) - m_logMinAlignment) < (1u << SDefragAllocChunk::AlignBitCount)); - CDBA_ASSERT((IntegerLog2(NextPower2(Align(sz, alignment))) - m_logMinAlignment) < (1u << SDefragAllocChunkAttr::SizeWidth)); - - CryOptionalAutoLock lock(m_lock, m_isThreadSafe); - return Allocate_Locked(sz, alignment, source, pContext); -} - -IDefragAllocator::AllocatePinnedResult CDefragAllocator::AllocatePinned(size_t sz, const char* source, void* pContext /* = NULL */) -{ - CryOptionalAutoLock lock(m_lock, m_isThreadSafe); - AllocatePinnedResult apr = {0}; - apr.hdl = Allocate_Locked(sz, m_minAlignment, source, pContext); - if (apr.hdl != InvalidHdl) - { - apr.offs = Pin(apr.hdl); - apr.usableSize = CDefragAllocator::UsableSize(apr.hdl); - } - - return apr; -} - -bool CDefragAllocator::Free(Hdl hdl) -{ - CryOptionalAutoLock lock(m_lock, m_isThreadSafe); - - if (hdl != InvalidHdl) - { - // Assume that the allocator now has exclusive ownership of hdl - that is, - // that the caller won't be modifying it externally. - - Index hdlIdx = ChunkIdxFromHdl(hdl); - CDBA_ASSERT(hdlIdx < m_chunks.size()); - - SDefragAllocChunk* chunk = &m_chunks[hdlIdx]; - CDBA_ASSERT(chunk->attr.IsBusy()); - - // Moving state can only be acquired by defrag and released by CancelMove, both own lock as well as Free. - if (chunk->attr.IsMoving()) - { - CancelMove_Locked(hdlIdx, false); - CDBA_ASSERT(!chunk->attr.IsMoving()); - } - - MarkAsFree(*chunk); - MergeFreeBlock(hdlIdx); - - return true; - } - - return false; -} - -void CDefragAllocator::ChangeContext(Hdl hdl, void* pNewContext) -{ - CryOptionalAutoLock lock(m_lock, m_isThreadSafe); - CDBA_ASSERT(hdl != InvalidHdl); - - Index hdlIdx = ChunkIdxFromHdl(hdl); - SDefragAllocChunk& chunk = m_chunks[hdlIdx]; - CDBA_ASSERT(chunk.attr.IsBusy()); - chunk.pContext = pNewContext; -} - -IDefragAllocatorStats CDefragAllocator::GetStats() -{ - CryOptionalAutoLock lock(m_lock, m_isThreadSafe); - - IDefragAllocatorStats stats = {0}; - - stats.nCapacity = static_cast(m_capacity) << m_logMinAlignment; - stats.nInUseSize = static_cast(m_capacity - m_available) << m_logMinAlignment; - stats.nInUseBlocks = m_numAllocs; - - uint32 numFreeBlocks = 0; - uint32 numPinnedBlocks = 0; - uint32 numMovingBlocks = 0; - uint32 maxFreeBlockSize = 0; - uint32 minFreeBlockSize = (uint32) - 1; - - SDefragAllocChunk* pChunks = &m_chunks[0]; - for (Index idx = pChunks[AddrStartSentinal].addrNextIdx; idx != AddrEndSentinal; idx = pChunks[idx].addrNextIdx) - { - SDefragAllocChunk& c = pChunks[idx]; - SDefragAllocChunkAttr ca = c.attr; - - if (ca.IsBusy()) - { - if (ca.IsPinned()) - { - ++numPinnedBlocks; - } - if (ca.IsMoving()) - { - ++numMovingBlocks; - } - } - else - { - maxFreeBlockSize = max(maxFreeBlockSize, ca.GetSize()); - minFreeBlockSize = min(minFreeBlockSize, ca.GetSize()); - ++numFreeBlocks; - } - } - - stats.nFreeBlocks = numFreeBlocks; - stats.nPinnedBlocks = numPinnedBlocks - numMovingBlocks - (int)(m_segments.size() - 1); // Each moving block pins a block for the destination - stats.nMovingBlocks = numMovingBlocks; - stats.nLargestFreeBlockSize = maxFreeBlockSize << m_logMinAlignment; - stats.nSmallestFreeBlockSize = minFreeBlockSize << m_logMinAlignment; - stats.nMeanFreeBlockSize = (numFreeBlocks > 0) - ? ((m_available << m_logMinAlignment) / numFreeBlocks) - : 0; - stats.nCancelledMoveCount = (uint32)m_nCancelledMoves; - - return stats; -} - -size_t CDefragAllocator::DefragmentTick(size_t maxMoves, size_t maxAmount, bool bForce) -{ - if (m_isThreadSafe) - { - if (bForce) - { - m_lock.Lock(); - } - else if (!m_lock.TryLock()) - { - return 0; - } - } - - Defrag_CompletePendingMoves(); - - maxMoves = min(maxMoves, (size_t)MaxPendingMoves); - maxMoves = min(maxMoves, m_unusedChunks.size()); // Assume that each move requires a split - maxAmount >>= m_logMinAlignment; - - PendingMove* moves[MaxPendingMoves]; - size_t numMoves = 0; - size_t curAmount = 0; - -#ifdef CDBA_MORE_DEBUG - Defrag_ValidateFreeBlockIteration(); -#endif - - if (maxMoves > 0) - { - numMoves = Defrag_FindMovesBwd(moves + numMoves, maxMoves - numMoves, curAmount, maxAmount); - if (numMoves < maxMoves) - { - numMoves += Defrag_FindMovesFwd(moves + numMoves, maxMoves - numMoves, curAmount, maxAmount); - } - -#ifdef CDBA_DEBUG - for (size_t moveIdx = 0; moveIdx < numMoves; ++moveIdx) - { - PendingMove& pm = *moves[moveIdx]; - - SDefragAllocChunk& srcChunk = m_chunks[pm.srcChunkIdx]; - SDefragAllocChunk& dstChunk = m_chunks[pm.dstChunkIdx]; - SDefragAllocChunkAttr srcChunkAttr = srcChunk.attr; - SDefragAllocChunkAttr dstChunkAttr = dstChunk.attr; - - CDBA_ASSERT(srcChunkAttr.IsMoving()); - CDBA_ASSERT(dstChunkAttr.IsPinned()); - CDBA_ASSERT(dstChunkAttr.IsBusy()); - CDBA_ASSERT(dstChunkAttr.GetSize() == srcChunkAttr.GetSize()); - } -#endif - } - - if (m_isThreadSafe) - { - m_lock.Unlock(); - } - - return curAmount; -} - -CDefragAllocator::Index CDefragAllocator::AllocateChunk() -{ - Index result = InvalidChunkIdx; - - if (!m_unusedChunks.empty()) - { - result = m_unusedChunks.back(); - m_unusedChunks.pop_back(); - } - else if (!m_chunksAreFixed) - { - m_chunks.push_back(SDefragAllocChunk()); - result = (Index) (m_chunks.size() - 1); - CDBA_ASSERT(result == (m_chunks.size() - 1)); - } - - IF_LIKELY (result != InvalidChunkIdx) - { - SDefragAllocChunk& chunk = m_chunks[result]; - chunk.attr.SetBusy(false); - chunk.attr.SetPinCount(0); - chunk.attr.SetMoving(false); - chunk.pContext = NULL; -#ifndef _RELEASE - chunk.source = ""; -#endif - } - - return result; -} - -void CDefragAllocator::DisplayMemoryUsage([[maybe_unused]] const char* title, [[maybe_unused]] unsigned int allocatorDisplayOffset) -{ -#if !defined(_RELEASE) || defined(PERFORMANCE_BUILD) // We want this vis in Performance builds - if (IRenderAuxGeom* pAuxGeom = gEnv->pRenderer->GetIRenderAuxGeom()) - { - int width = gEnv->pRenderer->GetWidth(); - int height = gEnv->pRenderer->GetHeight(); - - // The height of the bar is 40 pixels, but DrawTriangles is in screen UV coords - const float c_barHeight = 40.0f / height; - - unsigned int currentSize = 0; - unsigned int chunkCount = m_chunks.size(); - AZStd::vector chunkVerts; - chunkVerts.reserve(chunkCount * 4); - AZStd::vector chunkIndices; - chunkIndices.reserve(chunkCount * 6); - AZStd::vector chunkColors; - chunkColors.reserve(chunkCount * 4); - - // Chunks use banded colors to show delineations between adjacent allocations - const ColorB usedColor[2] = { ColorB(255, 0, 0), ColorB(200, 0, 0) }; - const ColorB freeColor[2] = { ColorB(0, 255, 0), ColorB(0, 200, 0) }; - - uint32 i = 0; - float minBarY = 1.0f - allocatorDisplayOffset * c_barHeight; - float maxBarY = 1.0f - (allocatorDisplayOffset + 1) * c_barHeight; - for (size_t idx = m_chunks[0].addrNextIdx; idx != 0; idx = m_chunks[idx].addrNextIdx) - { - SDefragAllocChunk& chunk = m_chunks[idx]; - unsigned int chunkSize = chunk.attr.GetSize(); - if (chunkSize != 0) - { - // Start and end x locations in screen UV coords - float startX = static_cast(currentSize) / m_capacity; - float endX = static_cast(currentSize + chunkSize) / m_capacity; - - // Ensure a valid size is at least one pixel wide - endX = AZStd::max(endX, startX + 1.0f / width); - - chunkVerts.push_back(Vec3(startX, minBarY, 0.0f)); - chunkVerts.push_back(Vec3(endX, minBarY, 0.0f)); - chunkVerts.push_back(Vec3(endX, maxBarY, 0.0f)); - chunkVerts.push_back(Vec3(startX, maxBarY, 0.0f)); - - chunkIndices.push_back(i * 4 + 0); - chunkIndices.push_back(i * 4 + 1); - chunkIndices.push_back(i * 4 + 2); - chunkIndices.push_back(i * 4 + 0); - chunkIndices.push_back(i * 4 + 2); - chunkIndices.push_back(i * 4 + 3); - - if (chunk.attr.IsPinned()) - { - chunkColors.push_back(usedColor[i & 1]); - chunkColors.push_back(usedColor[i & 1]); - chunkColors.push_back(usedColor[i & 1]); - chunkColors.push_back(usedColor[i & 1]); - } - else - { - chunkColors.push_back(freeColor[i & 1]); - chunkColors.push_back(freeColor[i & 1]); - chunkColors.push_back(freeColor[i & 1]); - chunkColors.push_back(freeColor[i & 1]); - } - - currentSize += chunkSize; - i++; - } - } - - SAuxGeomRenderFlags savedFlags = pAuxGeom->GetRenderFlags(); - SAuxGeomRenderFlags tempFlags; - tempFlags.SetMode2D3DFlag(e_Mode2D); - pAuxGeom->SetRenderFlags(tempFlags); - pAuxGeom->DrawTriangles(chunkVerts.data(), chunkVerts.size(), chunkIndices.data(), chunkIndices.size(), chunkColors.data()); - pAuxGeom->SetRenderFlags(savedFlags); - - // Draw other stats about the system - const float statisticsWidth = 384.0f; - float statsXOffset = allocatorDisplayOffset * statisticsWidth; - IDefragAllocatorStats stats = GetStats(); - ColorF statsTextColor(1.0f, 1.0f, 0.5f, 1.0f); - pAuxGeom->Draw2dLabel(10 + statsXOffset, 85, 1.7f, statsTextColor, false, title); - pAuxGeom->Draw2dLabel(20 + statsXOffset, 110, 1.5f, statsTextColor, false, "Capacity (MB): %.2f", stats.nCapacity / 1024.0f / 1024.0f); - pAuxGeom->Draw2dLabel(20 + statsXOffset, 130, 1.5f, statsTextColor, false, "In Use (MB): %.2f", stats.nInUseSize / 1024.0f / 1024.0f); - pAuxGeom->Draw2dLabel(20 + statsXOffset, 150, 1.5f, statsTextColor, false, "In Use Blocks: %u", stats.nInUseBlocks); - pAuxGeom->Draw2dLabel(20 + statsXOffset, 170, 1.5f, statsTextColor, false, "Free Blocks: %u", stats.nFreeBlocks); - pAuxGeom->Draw2dLabel(20 + statsXOffset, 190, 1.5f, statsTextColor, false, "Largest Free Block (B): %u", stats.nLargestFreeBlockSize); - pAuxGeom->Draw2dLabel(20 + statsXOffset, 210, 1.5f, statsTextColor, false, "Smallest Free Block (B): %u", stats.nSmallestFreeBlockSize); - pAuxGeom->Draw2dLabel(20 + statsXOffset, 230, 1.5f, statsTextColor, false, "Mean Free Block (B): %u", stats.nMeanFreeBlockSize); - } -#endif -} - -void CDefragAllocator::ReleaseChunk(Index idx) -{ - m_unusedChunks.push_back(idx); -} - -void CDefragAllocator::LinkFreeChunk(Index idx) -{ - SDefragAllocChunk* pChunks = &m_chunks[0]; - SDefragAllocChunk& chunk = pChunks[idx]; - - CDBA_ASSERT(!chunk.attr.IsBusy()); - - int bucket = BucketForSize(chunk.attr.GetSize()); - - Index rootIdx = m_freeBuckets[bucket]; - Index beforeIdx; - - // Search for the position in the list to insert the new block, maintaining address order - for (beforeIdx = pChunks[rootIdx].freeNextIdx; beforeIdx != rootIdx; beforeIdx = pChunks[beforeIdx].freeNextIdx) - { - if (pChunks[beforeIdx].ptr > chunk.ptr) - { - break; - } - } - - Index afterIdx = pChunks[beforeIdx].freePrevIdx; - SDefragAllocChunk& after = pChunks[afterIdx]; - - chunk.freeNextIdx = after.freeNextIdx; - chunk.freePrevIdx = afterIdx; - pChunks[after.freeNextIdx].freePrevIdx = idx; - after.freeNextIdx = idx; -} - -IDefragAllocator::Hdl CDefragAllocator::Allocate_Locked(size_t sz, size_t alignment, [[maybe_unused]] const char* source, void* pContext) -{ -#if AZ_LEGACY_CRYSYSTEM_TRAIT_USE_BIT64 - CDBA_ASSERT(sz <= (BIT64(NumBuckets))); -#else - CDBA_ASSERT(sz <= (BIT(NumBuckets))); -#endif - - sz = Align(sz, alignment) >> m_logMinAlignment; - alignment >>= m_logMinAlignment; - - if (sz > m_available) - { - return InvalidHdl; - } - - Index bestChunkIdx = InvalidChunkIdx; - switch (m_policy.blockSearchKind) - { - case eBSK_BestFit: - bestChunkIdx = BestFit_FindFreeBlockFor(sz, alignment, 0, ~(uint32)0, true); - break; - case eBSK_FirstFit: - bestChunkIdx = FirstFit_FindFreeBlockFor(sz, alignment, 0, ~(uint32)0, true); - break; - default: - __debugbreak(); - break; - } - - if (bestChunkIdx != InvalidChunkIdx) - { - SplitResult sr = SplitFreeBlock(bestChunkIdx, sz, alignment, true); - - IF_LIKELY (sr.bSuccessful) - { - SDefragAllocChunk& bestChunk = m_chunks[bestChunkIdx]; - CDBA_ASSERT(bestChunk.attr.GetSize() == sz); - - MarkAsInUse(bestChunk); - bestChunk.pContext = pContext; -#ifndef _RELEASE - bestChunk.source = source; -#endif - bestChunk.attr.SetPinCount(0); - bestChunk.attr.SetMoving(false); - - return ChunkHdlFromIdx(bestChunkIdx); - } - } - - return InvalidHdl; -} - -CDefragAllocator::SplitResult CDefragAllocator::SplitFreeBlock(Index fbId, size_t sz, size_t alignment, bool allocateInLowHalf) -{ - CDefragAllocator::SplitResult res; - res.bSuccessful = false; - res.nLeftSplitChunkIdx = InvalidChunkIdx; - res.nRightSplitChunkIdx = InvalidChunkIdx; - - SDefragAllocChunk* allocChunk = &m_chunks[fbId]; - - CDBA_ASSERT(!allocChunk->attr.IsBusy()); - CDBA_ASSERT(sz <= allocChunk->attr.GetSize()); - - if ((allocChunk->ptr & (alignment - 1)) != 0 || allocChunk->attr.GetSize() != sz) - { - // Determine the sizes of the new chunks - UINT_PTR baseAddress = allocChunk->ptr; - UINT_PTR endAddress = allocChunk->ptr + allocChunk->attr.GetSize(); - UINT_PTR allocAddress = allocateInLowHalf - ? Align(baseAddress, alignment) - : ((endAddress - sz) & ~(alignment - 1)); - UINT_PTR allocEndAddress = allocAddress + sz; - - // Allocate split chunks - Index nLeftSplitChunkIdx = InvalidChunkIdx; - if (baseAddress != allocAddress) - { - nLeftSplitChunkIdx = AllocateChunk(); - if (nLeftSplitChunkIdx == InvalidChunkIdx) - { - return res; - } - } - - Index nRightSplitChunkIdx = InvalidChunkIdx; - if (allocEndAddress != endAddress) - { - nRightSplitChunkIdx = AllocateChunk(); - if (nRightSplitChunkIdx == InvalidChunkIdx) - { - if (nLeftSplitChunkIdx != InvalidChunkIdx) - { - ReleaseChunk(nLeftSplitChunkIdx); - } - return res; - } - } - - // Split - UnlinkFreeChunk(fbId); - - allocChunk = &m_chunks[fbId]; - - if (nLeftSplitChunkIdx != InvalidChunkIdx) - { - SDefragAllocChunk& splitChunk = m_chunks[nLeftSplitChunkIdx]; - - splitChunk.ptr = baseAddress; - splitChunk.attr.SetSize((int)(allocAddress - baseAddress)); - LinkAddrChunk(nLeftSplitChunkIdx, allocChunk->addrPrevIdx); - } - - if (nRightSplitChunkIdx != InvalidChunkIdx) - { - SDefragAllocChunk& splitChunk = m_chunks[nRightSplitChunkIdx]; - - splitChunk.ptr = allocEndAddress; - splitChunk.attr.SetSize((int)(endAddress - allocEndAddress)); - LinkAddrChunk(nRightSplitChunkIdx, fbId); - } - - allocChunk->ptr = allocAddress; - allocChunk->attr.SetSize((int)(allocEndAddress - allocAddress)); - allocChunk->logAlign = IntegerLog2(alignment); - - if (nLeftSplitChunkIdx != InvalidChunkIdx) - { - LinkFreeChunk(nLeftSplitChunkIdx); - } - if (nRightSplitChunkIdx != InvalidChunkIdx) - { - LinkFreeChunk(nRightSplitChunkIdx); - } - - res.bSuccessful = true; - res.nLeftSplitChunkIdx = nLeftSplitChunkIdx; - res.nRightSplitChunkIdx = nRightSplitChunkIdx; - } - else - { - // Perfect fit. - UnlinkFreeChunk(fbId); - - res.bSuccessful = true; - } - -#ifdef CDBA_MORE_DEBUG - ValidateFreeLists(); -#endif - - return res; -} - -CDefragAllocator::Index CDefragAllocator::MergeFreeBlock(Index fbId) -{ - SDefragAllocChunk* pChunks = &m_chunks[0]; - - SDefragAllocChunk* chunk = &pChunks[fbId]; - - CDBA_ASSERT(m_available <= m_capacity); - CDBA_ASSERT(!chunk->attr.IsBusy()); - - LinkFreeChunk(fbId); - - Index prevChunkIdx = chunk->addrPrevIdx; - SDefragAllocChunk& prevChunk = pChunks[prevChunkIdx]; - if (!prevChunk.attr.IsBusy()) - { - // Merge with previous chunk - - UnlinkFreeChunk(fbId); - UnlinkFreeChunk(prevChunkIdx); - - prevChunk.attr.AddSize(chunk->attr.GetSize()); - prevChunk.addrNextIdx = chunk->addrNextIdx; - pChunks[chunk->addrNextIdx].addrPrevIdx = prevChunkIdx; - - CDBA_ASSERT(pChunks[prevChunk.addrPrevIdx].ptr + pChunks[prevChunk.addrPrevIdx].attr.GetSize() == prevChunk.ptr); - CDBA_ASSERT(prevChunk.ptr + prevChunk.attr.GetSize() == pChunks[prevChunk.addrNextIdx].ptr); - CDBA_ASSERT(pChunks[prevChunk.addrPrevIdx].addrNextIdx == prevChunkIdx); - CDBA_ASSERT(pChunks[prevChunk.addrNextIdx].addrPrevIdx == prevChunkIdx); - - LinkFreeChunk(prevChunkIdx); - ReleaseChunk(fbId); - - // Pretend the released chunk is the previous one, so the next merge can happen - - fbId = prevChunkIdx; - chunk = &prevChunk; - } - - Index nextChunkIdx = chunk->addrNextIdx; - SDefragAllocChunk& nextChunk = pChunks[nextChunkIdx]; - if (!nextChunk.attr.IsBusy()) - { - // Merge with next chunk - - UnlinkFreeChunk(fbId); - UnlinkFreeChunk(nextChunkIdx); - - chunk->attr.AddSize(nextChunk.attr.GetSize()); - chunk->addrNextIdx = nextChunk.addrNextIdx; - pChunks[chunk->addrNextIdx].addrPrevIdx = fbId; - - CDBA_ASSERT(pChunks[chunk->addrPrevIdx].ptr + pChunks[chunk->addrPrevIdx].attr.GetSize() == chunk->ptr); - CDBA_ASSERT(chunk->ptr + chunk->attr.GetSize() == pChunks[chunk->addrNextIdx].ptr); - CDBA_ASSERT(pChunks[chunk->addrPrevIdx].addrNextIdx == fbId); - CDBA_ASSERT(pChunks[chunk->addrNextIdx].addrPrevIdx == fbId); - - LinkFreeChunk(fbId); - ReleaseChunk(nextChunkIdx); - } - - return fbId; -} - -#ifdef CDBA_MORE_DEBUG -void CDefragAllocator::Defrag_ValidateFreeBlockIteration() -{ - Index freeLists[NumBuckets]; - size_t numFreeLists = 0; - - { - PrepareMergePopPrev(freeLists); - UINT_PTR addr = (UINT_PTR)-1; - - if (numFreeLists) - { - do - { - size_t list = MergePeekPrevChunk(freeLists); - Index chk = freeLists[list]; - UINT_PTR chkAddr = m_chunks[chk].ptr; - CDBA_ASSERT(chkAddr < addr); - addr = chkAddr; - MergePopPrevChunk(freeLists, list); - } while (numFreeLists > 0); - } - } - { - PrepareMergePopNext(freeLists); - UINT_PTR addr = 0; - - if (numFreeLists) - { - do - { - size_t list = MergePeekNextChunk(freeLists); - Index chk = freeLists[list]; - UINT_PTR chkAddr = m_chunks[chk].ptr; - CDBA_ASSERT(chkAddr > addr); - addr = chkAddr; - MergePopNextChunk(freeLists, list); - } while (numFreeLists > 0); - } - } -} -#endif - -CDefragAllocator::Index CDefragAllocator::BestFit_FindFreeBlockForSegment(size_t sz, size_t alignment, uint32 seg) -{ - SDefragAllocSegment& segment = m_segments[seg]; - return BestFit_FindFreeBlockFor(sz, alignment, segment.address, segment.address + segment.capacity, true); -} - -CDefragAllocator::Index CDefragAllocator::BestFit_FindFreeBlockFor(size_t sz, size_t alignment, [[maybe_unused]] UINT_PTR addressMin, UINT_PTR addressMax, bool allocateInLowHalf) -{ - Index bestChunkIdx = InvalidChunkIdx; - UINT_PTR bestWastage = (UINT_PTR)-1; - - for (int bucket = BucketForSize(sz); (bestChunkIdx == InvalidChunkIdx) && (bucket < NumBuckets); ++bucket) - { - size_t rootIdx = m_freeBuckets[bucket]; - SDefragAllocChunk& root = m_chunks[rootIdx]; - - for (size_t idx = root.freeNextIdx; idx != rootIdx; idx = m_chunks[idx].freeNextIdx) - { - SDefragAllocChunk& chunk = m_chunks[idx]; - - CDBA_ASSERT(!chunk.attr.IsBusy()); - CDBA_ASSERT(max(1U, chunk.attr.GetSize()) >= (1U << bucket)); - - if (chunk.ptr < addressMax) - { - UINT_PTR chunkStart = chunk.ptr; - UINT_PTR chunkSize = chunk.attr.GetSize(); - UINT_PTR chunkEnd = chunkStart + chunkSize; - UINT_PTR allocStart = allocateInLowHalf - ? Align(chunkStart, alignment) - : ((chunkEnd - sz) & ~(alignment - 1)); - UINT_PTR allocEnd = allocStart + sz; - - if (chunkStart <= allocStart && allocEnd <= chunkEnd) - { - if (allocStart == chunkStart && chunkSize == sz) - { - bestChunkIdx = idx; - bestWastage = 0; - - break; - } - - UINT_PTR wastage = (allocStart - chunkStart) + (chunkEnd - allocEnd); - if (wastage < bestWastage) - { - bestChunkIdx = idx; - bestWastage = wastage; - } - } - } - else - { - break; - } - } - } - - return bestChunkIdx; -} - -CDefragAllocator::Index CDefragAllocator::FirstFit_FindFreeBlockFor(size_t sz, size_t alignment, [[maybe_unused]] UINT_PTR addressMin, UINT_PTR addressMax, bool allocateInLowHalf) -{ - for (int bucket = BucketForSize(sz); bucket < NumBuckets; ++bucket) - { - size_t rootIdx = m_freeBuckets[bucket]; - SDefragAllocChunk& root = m_chunks[rootIdx]; - for (size_t idx = root.freeNextIdx; idx != rootIdx; idx = m_chunks[idx].freeNextIdx) - { - SDefragAllocChunk& chunk = m_chunks[idx]; - CDBA_ASSERT(!chunk.attr.IsBusy()); - CDBA_ASSERT(max(1U, chunk.attr.GetSize()) >= (1U << bucket)); - if (chunk.ptr < addressMax) - { - UINT_PTR chunkStart = chunk.ptr; - UINT_PTR chunkSize = chunk.attr.GetSize(); - UINT_PTR chunkEnd = chunkStart + chunkSize; - UINT_PTR allocStart = allocateInLowHalf - ? Align(chunkStart, alignment) - : ((chunkEnd - sz) & ~(alignment - 1)); - UINT_PTR allocEnd = allocStart + sz; - if (chunkStart <= allocStart && allocEnd <= chunkEnd) - { - return idx; - } - } - else - { - break; - } - } - } - return InvalidChunkIdx; -} -size_t CDefragAllocator::Defrag_FindMovesBwd(PendingMove** pMoves, size_t maxMoves, size_t& curAmount, size_t maxAmount) -{ - Index freeLists[NumBuckets]; - - size_t numMoves = 0; - bool bIsLast = true; - - PrepareMergePopPrev(freeLists); - - int nSegmentIdx = (int)m_segments.size() - 1; - - // Try and copy a block from the back to the front - do - { - size_t freeChunkList = MergePeekPrevChunk(freeLists); - if (freeChunkList == (size_t)-1) - { - break; - } - - assert(freeChunkList < sizeof(freeLists) / sizeof(freeLists[0])); - Index freeChunkIdx = freeLists[freeChunkList]; - MergePopPrevChunk(freeLists, freeChunkList); - - // Keep track of the last free block in each segment, by watching free blocks - // crossing segment boundaries. - if (nSegmentIdx >= 0) - { - if (m_chunks[freeChunkIdx].ptr < m_segments[nSegmentIdx].address) - { - bIsLast = true; - --nSegmentIdx; - } - } - - // Don't move free block->next blocks if they're at the end of a segment - they're defragged enough. - // TODO - could allow this (and self moves below) if defragging stalls in a bad state - if (!bIsLast) - { - for (Index candidateIdx = m_chunks[freeChunkIdx].addrNextIdx; freeChunkIdx != InvalidChunkIdx && numMoves < maxMoves && curAmount < maxAmount; ) - { - SDefragAllocChunk& freeChunk = m_chunks[freeChunkIdx]; - SDefragAllocChunk& candidateChunk = m_chunks[candidateIdx]; - SDefragAllocChunkAttr candidateChunkAttr = candidateChunk.attr; - - CDBA_ASSERT(!freeChunk.attr.IsBusy()); - - if (IsMoveableCandidate(candidateChunkAttr, 0xffffffff)) - { -#if AZ_LEGACY_CRYSYSTEM_TRAIT_USE_BIT64 - size_t candidateChunkAlign = BIT64(candidateChunk.logAlign); -#else - size_t candidateChunkAlign = BIT(candidateChunk.logAlign); -#endif - - // Try and reallocate this chunk. For the time being, assume that it's going to remain in a valid moveable state. - Index dstChunkIdx = Defrag_Bwd_FindFreeBlockFor(candidateChunkAttr.GetSize(), candidateChunkAlign, freeChunk.ptr);// + freeChunk.attr.GetSize()); - - if (dstChunkIdx != InvalidChunkIdx) - { - PendingMove* pPM = AllocPendingMove(); - IF_UNLIKELY (!pPM) - { - return numMoves; - } - - // Found a possible move, so try and mark the chunk as moveable - as long as it's still a valid candidate. - if (TryMarkAsMoving(candidateChunk, 0xffffffff)) - { - // Chunk has been marked as moveable - can now split the dest chunk and set up the move state. - // If the chunk gets pinned in the meantime, it'll sync (through CancelMove) on the allocator lock. - - if (TryScheduleCopy(candidateChunk, m_chunks[dstChunkIdx], pPM, true)) - { - SplitResult sr = SplitFreeBlock(dstChunkIdx, candidateChunkAttr.GetSize(), candidateChunkAlign, true); - CDBA_ASSERT(sr.bSuccessful); - - MergePatchPrevRemove(freeLists, dstChunkIdx); - - if (sr.nRightSplitChunkIdx != InvalidChunkIdx) - { - MergePatchPrevInsert(freeLists, sr.nRightSplitChunkIdx); - } - - pPM->srcChunkIdx = candidateIdx; - pPM->dstChunkIdx = dstChunkIdx; - - // dstChunk is owned by the allocator, so we don't need to be atomic when changing it's state. - SDefragAllocChunk& dstChunk = m_chunks[dstChunkIdx]; - MarkAsInUse(dstChunk); - dstChunk.attr.SetPinCount(1); - - CDBA_ASSERT(sr.nRightSplitChunkIdx == InvalidChunkIdx || (m_chunks[sr.nRightSplitChunkIdx].ptr > dstChunk.ptr)); - CDBA_ASSERT(dstChunk.ptr < candidateChunk.ptr); - -#ifdef CDBA_MORE_DEBUG - ValidateAddressChain(); -#endif - - pMoves[numMoves++] = pPM; - curAmount += dstChunk.attr.GetSize(); - - candidateIdx = m_chunks[candidateIdx].addrNextIdx; - if (dstChunkIdx == freeChunkIdx) - { - freeChunkIdx = sr.nRightSplitChunkIdx; - } - continue; - } - else - { - MarkAsNotMoving(candidateChunk); - } - } - - // Candidate (probably) got pinned whilst finding a free block, or the copy schedule failed. Nevermind - undo what we need to. - FreePendingMove(pPM); - pPM = NULL; - } - } - - break; - } - } - - if (freeChunkIdx != InvalidChunkIdx) - { - for (Index candidateIdx = m_chunks[freeChunkIdx].addrPrevIdx; numMoves < maxMoves && curAmount < maxAmount; ) - { - SDefragAllocChunk& candidateChunk = m_chunks[candidateIdx]; - SDefragAllocChunkAttr candidateChunkAttr = candidateChunk.attr; - - if (IsMoveableCandidate(candidateChunkAttr, 0xffffffff)) - { -#if AZ_LEGACY_CRYSYSTEM_TRAIT_USE_BIT64 - size_t candidateChunkAlign = BIT64(candidateChunk.logAlign); -#else - size_t candidateChunkAlign = BIT(candidateChunk.logAlign); -#endif - - // Try and reallocate this chunk. For the time being, assume that it's going to remain in a valid moveable state. - Index dstChunkIdx = Defrag_Bwd_FindFreeBlockFor(candidateChunkAttr.GetSize(), candidateChunkAlign, candidateChunk.ptr); - CDBA_ASSERT(dstChunkIdx != freeChunkIdx); - - if (dstChunkIdx != InvalidChunkIdx) - { - PendingMove* pPM = AllocPendingMove(); - IF_UNLIKELY (!pPM) - { - return numMoves; - } - - // Found a possible move, so try and mark the chunk as moveable - as long as it's still a valid candidate. - if (TryMarkAsMoving(candidateChunk, 0xffffffff)) - { - // Chunk has been marked as moveable - can now split the chunk and set up the move state. - // If the chunk gets pinned in the meantime, it'll sync (through CancelMove) on the allocator lock. - - if (TryScheduleCopy(candidateChunk, m_chunks[dstChunkIdx], pPM, true)) - { - SplitResult sr = SplitFreeBlock(dstChunkIdx, candidateChunkAttr.GetSize(), candidateChunkAlign, true); - CDBA_ASSERT(sr.bSuccessful); - - MergePatchPrevRemove(freeLists, dstChunkIdx); - - if (sr.nRightSplitChunkIdx != InvalidChunkIdx) - { - MergePatchPrevInsert(freeLists, sr.nRightSplitChunkIdx); - } - - pPM->srcChunkIdx = candidateIdx; - pPM->dstChunkIdx = dstChunkIdx; - - // dstChunk is owned by the allocator, so don't need to be atomic when changing it's state. - SDefragAllocChunk& dstChunk = m_chunks[dstChunkIdx]; - MarkAsInUse(dstChunk); - dstChunk.attr.SetPinCount(1); - - CDBA_ASSERT(sr.nRightSplitChunkIdx == InvalidChunkIdx || (m_chunks[sr.nRightSplitChunkIdx].ptr > dstChunk.ptr)); - CDBA_ASSERT(dstChunk.ptr < candidateChunk.ptr); - -#ifdef CDBA_MORE_DEBUG - ValidateAddressChain(); -#endif - - pMoves[numMoves++] = pPM; - curAmount += dstChunk.attr.GetSize(); - - candidateIdx = m_chunks[candidateIdx].addrPrevIdx; - continue; - } - else - { - MarkAsNotMoving(candidateChunk); - } - } - - // Candidate (probably) got pinned whilst finding a free block, or the copy schedule failed. Nevermind - undo what we need to. - FreePendingMove(pPM); - pPM = NULL; - } - } - - break; - } - } - bIsLast = false; - } - while (numMoves < maxMoves); - - return numMoves; -} - -size_t CDefragAllocator::Defrag_FindMovesFwd(PendingMove** pMoves, size_t maxMoves, size_t& curAmount, size_t maxAmount) -{ - Index freeLists[NumBuckets]; - - size_t numMoves = 0; - - PrepareMergePopNext(freeLists); - - // Try and copy a block from the front to the back - do - { - size_t freeChunkList = MergePeekNextChunk(freeLists); - if (freeChunkList == (size_t)-1) - { - break; - } - - assert(freeChunkList < sizeof(freeLists) / sizeof(freeLists[0])); - - Index freeChunkIdx = freeLists[freeChunkList]; - MergePopNextChunk(freeLists, freeChunkList); - - CDBA_ASSERT(!m_chunks[freeChunkIdx].attr.IsBusy()); - - for (Index candidateIdx = m_chunks[freeChunkIdx].addrNextIdx; numMoves < maxMoves && curAmount < maxAmount; ) - { - SDefragAllocChunk& freeChunk = m_chunks[freeChunkIdx]; - SDefragAllocChunk& candidateChunk = m_chunks[candidateIdx]; - SDefragAllocChunkAttr candidateChunkAttr = candidateChunk.attr; - - if (IsMoveableCandidate(candidateChunkAttr, 0xffffffff)) - { -#if AZ_LEGACY_CRYSYSTEM_TRAIT_USE_BIT64 - size_t candidateChunkAlign = BIT64(candidateChunk.logAlign); -#else - size_t candidateChunkAlign = BIT(candidateChunk.logAlign); -#endif - - // Try and reallocate this chunk. For the time being, assume that it's going to remain in a valid moveable state. - Index dstChunkIdx = Defrag_Fwd_FindFreeBlockFor(candidateChunkAttr.GetSize(), candidateChunkAlign, freeChunk.ptr + freeChunk.attr.GetSize()); - - CDBA_ASSERT(dstChunkIdx != freeChunkIdx); - - if (dstChunkIdx != InvalidChunkIdx) - { - PendingMove* pPM = AllocPendingMove(); - IF_UNLIKELY (!pPM) - { - return numMoves; - } - - CDBA_ASSERT(!m_chunks[dstChunkIdx].attr.IsBusy()); - CDBA_ASSERT(m_chunks[dstChunkIdx].attr.GetSize() >= candidateChunkAttr.GetSize()); - - // Found a possible move, so try and mark the chunk as moveable - as long as it's still a valid candidate. - if (TryMarkAsMoving(candidateChunk, 0xffffffff)) - { - // Chunk has been marked as moveable - can now split the dest chunk and set up the move state. - // If the chunk gets pinned in the meantime, it'll sync (through CancelMove) on the allocator lock. - - if (TryScheduleCopy(candidateChunk, m_chunks[dstChunkIdx], pPM, false)) - { - SplitResult sr = SplitFreeBlock(dstChunkIdx, candidateChunkAttr.GetSize(), candidateChunkAlign, false); - CDBA_ASSERT(sr.bSuccessful); - - MergePatchNextRemove(freeLists, dstChunkIdx); - - if (sr.nLeftSplitChunkIdx != InvalidChunkIdx) - { - MergePatchNextInsert(freeLists, sr.nLeftSplitChunkIdx); - } - - pPM->srcChunkIdx = candidateIdx; - pPM->dstChunkIdx = dstChunkIdx; - - // dstChunk is owned by the allocator, so we don't need to be atomic when changing it's state. - SDefragAllocChunk& dstChunk = m_chunks[dstChunkIdx]; - MarkAsInUse(dstChunk); - dstChunk.attr.SetPinCount(1); - - CDBA_ASSERT(sr.nLeftSplitChunkIdx == InvalidChunkIdx || (m_chunks[sr.nLeftSplitChunkIdx].ptr < dstChunk.ptr)); - CDBA_ASSERT(dstChunk.ptr > candidateChunk.ptr); - -#ifdef CDBA_MORE_DEBUG - ValidateAddressChain(); -#endif - - pMoves[numMoves++] = pPM; - curAmount += dstChunk.attr.GetSize(); - - candidateIdx = m_chunks[candidateIdx].addrNextIdx; - continue; - } - else - { - MarkAsNotMoving(candidateChunk); - } - } - - // Candidate (probably) got pinned whilst finding a free block, or the copy schedule failed. Nevermind - undo what we need to. - FreePendingMove(pPM); - pPM = NULL; - } - } - - break; - } - } - while (numMoves < maxMoves); - - return numMoves; -} - -bool CDefragAllocator::Defrag_CompletePendingMoves() -{ - CDBA_ASSERT(m_policy.pDefragPolicy); - - bool bHasMoves = false; - - for (DynArray::iterator it = m_pendingMoves.begin(), itEnd = m_pendingMoves.end(); it != itEnd; ++it) - { - if (it->notify.bCancel) - { - // Currently only support cancelling before a move has really begun - // Also assume that there is no copy in flight - the policy has requested it, so it's their responsibility to - // make sure that this is the case - CDBA_ASSERT(!it->relocated); - - MarkAsFree(m_chunks[it->dstChunkIdx]); - MergeFreeBlock(it->dstChunkIdx); - - MarkAsNotMoving(m_chunks[it->srcChunkIdx]); - - FreePendingMove(&*it); - } - else - { - if (it->notify.bDstIsValid) - { - if (!it->relocated) - { - CDBA_ASSERT(it->dstChunkIdx != InvalidChunkIdx); - - if (!it->cancelled) - { - Relocate(it->userMoveId, it->srcChunkIdx, it->dstChunkIdx); - } - - it->relocated = true; - } - - if (it->notify.bSrcIsUnneeded) - { - SDefragAllocChunk& dst = m_chunks[it->dstChunkIdx]; - MarkAsFree(dst); - MergeFreeBlock(it->dstChunkIdx); - - if (!it->cancelled) - { - CDBA_ASSERT(it->srcChunkIdx != InvalidChunkIdx); - - SDefragAllocChunk& src = m_chunks[it->srcChunkIdx]; - - // Should be the last thing to occur during move - MarkAsNotMoving(src); - } - else - { - // Only the destination chunk is now valid - just free it. - CDBA_ASSERT(it->srcChunkIdx == InvalidChunkIdx); - } - - FreePendingMove(&*it); - } - } - - if (it->dstChunkIdx != InvalidChunkIdx) - { - bHasMoves = true; - } - } - } - - return bHasMoves; -} - -CDefragAllocator::Index CDefragAllocator::Defrag_Bwd_FindFreeBlockFor(size_t sz, size_t alignment, UINT_PTR addressLimit) -{ - Index bestChunkIdx = InvalidChunkIdx; - UINT_PTR maxAddress = addressLimit; - - int minBucket = BucketForSize(sz); - - // Search for an exact fit - { - size_t rootIdx = m_freeBuckets[minBucket]; - SDefragAllocChunk& root = m_chunks[rootIdx]; - - for (size_t idx = root.freeNextIdx; idx != rootIdx; idx = m_chunks[idx].freeNextIdx) - { - SDefragAllocChunk& chunk = m_chunks[idx]; - - CDBA_ASSERT(!chunk.attr.IsBusy()); - CDBA_ASSERT(max((uint32)1, (uint32)chunk.attr.GetSize()) >= (1U << minBucket)); - - UINT_PTR chunkBase = chunk.ptr; - UINT_PTR chunkEnd = chunkBase + chunk.attr.GetSize(); - UINT_PTR allocBase = Align(chunkBase, alignment); - UINT_PTR allocEnd = allocBase + sz; - - if (chunk.ptr < maxAddress) - { - if (chunkBase == allocBase && chunkEnd == allocEnd) - { - bestChunkIdx = idx; - maxAddress = chunk.ptr; - break; - } - } - else - { - break; - } - } - } - - for (size_t bucket = minBucket; (bestChunkIdx == InvalidChunkIdx) && (bucket < NumBuckets); ++bucket) - { - size_t rootIdx = m_freeBuckets[bucket]; - SDefragAllocChunk& root = m_chunks[rootIdx]; - - for (size_t idx = root.freeNextIdx; idx != rootIdx; idx = m_chunks[idx].freeNextIdx) - { - SDefragAllocChunk& chunk = m_chunks[idx]; - - CDBA_ASSERT(!chunk.attr.IsBusy()); - CDBA_ASSERT(max((uint32)1, (uint32)chunk.attr.GetSize()) >= (1U << bucket)); - - UINT_PTR chunkBase = chunk.ptr; - UINT_PTR chunkEnd = chunkBase + chunk.attr.GetSize(); - UINT_PTR allocBase = Align(chunkBase, alignment); - UINT_PTR allocEnd = allocBase + sz; - - if (allocEnd <= maxAddress) - { - if (chunkBase <= allocBase && allocEnd <= chunkEnd) - { - bestChunkIdx = idx; - maxAddress = chunkBase; - break; - } - } - else - { - // Chunks are ordered by address. If the maxAddress has been exceeded, there's no point in searching the rest of the list. - break; - } - } - } - - return bestChunkIdx; -} - -CDefragAllocator::Index CDefragAllocator::Defrag_Fwd_FindFreeBlockFor(size_t sz, size_t alignment, UINT_PTR addressLimit) -{ - Index bestChunkIdx = InvalidChunkIdx; - UINT_PTR minAddress = addressLimit; - - int minBucket = BucketForSize(sz); - - // Search for an exact fit - { - size_t rootIdx = m_freeBuckets[minBucket]; - SDefragAllocChunk& root = m_chunks[rootIdx]; - - for (size_t idx = root.freePrevIdx; idx != rootIdx; idx = m_chunks[idx].freePrevIdx) - { - SDefragAllocChunk& chunk = m_chunks[idx]; - - CDBA_ASSERT(!chunk.attr.IsBusy()); - CDBA_ASSERT(max((uint32)1, (uint32)chunk.attr.GetSize()) >= (1U << minBucket)); - - UINT_PTR chunkBase = chunk.ptr; - UINT_PTR chunkEnd = chunkBase + chunk.attr.GetSize(); - UINT_PTR allocBase = (chunkEnd - sz) & ~(alignment - 1); - UINT_PTR allocEnd = allocBase + sz; - - if (chunkBase >= minAddress) - { - if (allocBase == chunkBase && allocEnd == chunkEnd) - { - bestChunkIdx = idx; - minAddress = chunk.ptr; - break; - } - } - else - { - break; - } - } - } - - for (size_t bucket = minBucket; (bestChunkIdx == InvalidChunkIdx) && (bucket < NumBuckets); ++bucket) - { - size_t rootIdx = m_freeBuckets[bucket]; - SDefragAllocChunk& root = m_chunks[rootIdx]; - - for (size_t idx = root.freePrevIdx; idx != rootIdx; idx = m_chunks[idx].freePrevIdx) - { - SDefragAllocChunk& chunk = m_chunks[idx]; - - CDBA_ASSERT(!chunk.attr.IsBusy()); - CDBA_ASSERT(max((uint32)1, (uint32)chunk.attr.GetSize()) >= (1U << bucket)); - - UINT_PTR chunkBase = chunk.ptr; - UINT_PTR chunkEnd = chunkBase + chunk.attr.GetSize(); - UINT_PTR allocBase = (chunkEnd - sz) & ~(alignment - 1); - UINT_PTR allocEnd = allocBase + sz; - - if (chunkBase > minAddress) - { - if (chunkBase <= allocBase && allocEnd <= chunkEnd) - { - bestChunkIdx = idx; - minAddress = chunkBase; - break; - } - } - else - { - // Chunks are ordered by address. If the minAddress has been exceeded, there's no point in searching the rest of the list. - break; - } - } - } - - return bestChunkIdx; -} - -CDefragAllocator::PendingMove* CDefragAllocator::AllocPendingMove() -{ - // Naive - just search for a free slot. - for (PendingMoveVec::iterator it = m_pendingMoves.begin(), itEnd = m_pendingMoves.end(); it != itEnd; ++it) - { - if (it->dstChunkIdx == InvalidChunkIdx) - { - return &*it; - } - } - - return NULL; -} - -void CDefragAllocator::FreePendingMove(PendingMove* pMove) -{ - stl::reconstruct(*pMove); -} - -void CDefragAllocator::CancelMove(Index srcChunkIdx, bool bIsContentNeeded) -{ - CryOptionalAutoLock lock(m_lock, m_isThreadSafe); - CancelMove_Locked(srcChunkIdx, bIsContentNeeded); -} - -void CDefragAllocator::CancelMove_Locked(Index srcChunkIdx, [[maybe_unused]] bool bIsContentNeeded) -{ - SDefragAllocChunk* pChunk = &m_chunks[srcChunkIdx]; - - // In theory CancelMove could get called twice for the same chunk - make sure that - // redundant cancels are ignored - if (pChunk->attr.IsMoving()) - { - // Chunk is being moved. Find the job responsible and cancel it (if it's not complete). - PendingMoveVec::iterator it = std::find_if(m_pendingMoves.begin(), m_pendingMoves.end(), PendingMoveSrcChunkPredicate(srcChunkIdx)); - CDBA_ASSERT(it != m_pendingMoves.end()); - CDBA_ASSERT(it->srcChunkIdx != InvalidChunkIdx); - - if (it->notify.bDstIsValid && it->notify.bSrcIsUnneeded) - { - // Chunk has actually completed, just not finalised. Discard the destination chunk. - MarkAsFree(m_chunks[it->dstChunkIdx]); - MergeFreeBlock(it->dstChunkIdx); - FreePendingMove(&*it); - } - else - { - // Chunk is still in flight. - - // If the content is important, then we can either cancel the copy (if not overlapped), or - // sync and wait for it complete. TODO. - - m_policy.pDefragPolicy->CancelCopy(it->userMoveId, pChunk->pContext, false); - it->srcChunkIdx = InvalidChunkIdx; - it->cancelled = true; - } - - MarkAsNotMoving(*pChunk); - ++m_nCancelledMoves; - } -} - -void CDefragAllocator::Relocate(uint32 userMoveId, Index srcChunkIdx, Index dstChunkIdx) -{ - using std::swap; - - SDefragAllocChunk* pChunks = &m_chunks[0]; - uint32 logAlignment = m_logMinAlignment; - - SDefragAllocChunk& src = pChunks[srcChunkIdx]; - SDefragAllocChunk& dst = pChunks[dstChunkIdx]; - SDefragAllocChunkAttr srcAttr = src.attr; - SDefragAllocChunkAttr dstAttr = dst.attr; - - CDBA_ASSERT(srcAttr.IsMoving()); - CDBA_ASSERT(dstAttr.IsPinned()); - CDBA_ASSERT(!dstAttr.IsMoving()); - CDBA_ASSERT(srcAttr.GetSize() == dstAttr.GetSize()); - - UINT_PTR oldPtr = src.ptr; - UINT_PTR newPtr = dst.ptr; - - // src and dst are linked in the addr chain only - src needs to move where dst is (so user handles remain consistent) - // and the src block be freed. - - SDefragAllocChunk* pA = &dst; - SDefragAllocChunk* pB = &src; - - CDBA_ASSERT(pChunks[pA->addrPrevIdx].ptr + pChunks[pA->addrPrevIdx].attr.GetSize() == pA->ptr); - CDBA_ASSERT(pA->ptr + pA->attr.GetSize() == pChunks[pA->addrNextIdx].ptr); - CDBA_ASSERT(pChunks[pB->addrPrevIdx].ptr + pChunks[pB->addrPrevIdx].attr.GetSize() == pB->ptr); - CDBA_ASSERT(pB->ptr + pB->attr.GetSize() == pChunks[pB->addrNextIdx].ptr); - CDBA_ASSERT(&pChunks[pChunks[pA->addrNextIdx].addrPrevIdx] == pA); - CDBA_ASSERT(&pChunks[pChunks[pA->addrPrevIdx].addrNextIdx] == pA); - CDBA_ASSERT(&pChunks[pChunks[pB->addrNextIdx].addrPrevIdx] == pB); - CDBA_ASSERT(&pChunks[pChunks[pB->addrPrevIdx].addrNextIdx] == pB); - - Index nA = dstChunkIdx; - Index nB = srcChunkIdx; - - if (pA->addrNextIdx == nB) - { - // Neighbours - pB->addrPrevIdx = pA->addrPrevIdx; - pA->addrNextIdx = pB->addrNextIdx; - pA->addrPrevIdx = nB; - pB->addrNextIdx = nA; - pChunks[pB->addrPrevIdx].addrNextIdx = nB; - pChunks[pA->addrNextIdx].addrPrevIdx = nA; - } - else if (pA->addrPrevIdx == nB) - { - // Neighbours - pB->addrNextIdx = pA->addrNextIdx; - pA->addrPrevIdx = pB->addrPrevIdx; - pB->addrPrevIdx = nA; - pA->addrNextIdx = nB; - pChunks[pA->addrPrevIdx].addrNextIdx = nA; - pChunks[pB->addrNextIdx].addrPrevIdx = nB; - } - else - { - swap(pB->addrNextIdx, pA->addrNextIdx); - swap(pA->addrPrevIdx, pB->addrPrevIdx); - pChunks[pA->addrPrevIdx].addrNextIdx = nA; - pChunks[pA->addrNextIdx].addrPrevIdx = nA; - pChunks[pB->addrNextIdx].addrPrevIdx = nB; - pChunks[pB->addrPrevIdx].addrNextIdx = nB; - } - - swap(src.packedPtr, dst.packedPtr); - -#ifdef CDBA_MORE_DEBUG - ValidateAddressChain(); -#endif - - CDBA_ASSERT(pChunks[pA->addrPrevIdx].ptr + pChunks[pA->addrPrevIdx].attr.GetSize() == pA->ptr); - CDBA_ASSERT(pA->ptr + pA->attr.GetSize() == pChunks[pA->addrNextIdx].ptr); - CDBA_ASSERT(pChunks[pB->addrPrevIdx].ptr + pChunks[pB->addrPrevIdx].attr.GetSize() == pB->ptr); - CDBA_ASSERT(pB->ptr + pB->attr.GetSize() == pChunks[pB->addrNextIdx].ptr); - CDBA_ASSERT(&pChunks[pChunks[pA->addrNextIdx].addrPrevIdx] == pA); - CDBA_ASSERT(&pChunks[pChunks[pA->addrPrevIdx].addrNextIdx] == pA); - CDBA_ASSERT(&pChunks[pChunks[pB->addrNextIdx].addrPrevIdx] == pB); - CDBA_ASSERT(&pChunks[pChunks[pB->addrPrevIdx].addrNextIdx] == pB); - - if (userMoveId != IDefragAllocatorPolicy::InvalidUserMoveId) - { - m_policy.pDefragPolicy->Relocate(userMoveId, src.pContext, newPtr << logAlignment, oldPtr << logAlignment, (UINT_PTR)srcAttr.GetSize() << logAlignment); - } -} - -void CDefragAllocator::SyncMoveSegment(uint32 seg) -{ - SDefragAllocSegment& segment = m_segments[seg]; - SDefragAllocChunk& headSentinalChunk = m_chunks[segment.headSentinalChunkIdx]; - - // Assert that the segment is empty. - uint32 endAddress = segment.address + segment.capacity; - - Index chunkIdx = headSentinalChunk.addrNextIdx; - SDefragAllocChunk* pChunk = &m_chunks[chunkIdx]; - - int numValidSegs = seg; - - while (pChunk->ptr != endAddress) - { - if (pChunk->attr.IsBusy()) - { - CDBA_ASSERT(!pChunk->attr.IsMoving()); - CDBA_ASSERT(!pChunk->attr.IsPinned()); - CDBA_ASSERT(m_policy.pDefragPolicy != NULL); - -#if AZ_LEGACY_CRYSYSTEM_TRAIT_USE_BIT64 - size_t chunkAlign = BIT64(pChunk->logAlign); -#else - size_t chunkAlign = BIT(pChunk->logAlign); -#endif - - // Try and synchronously move the allocation - Index destinationChunkIdx = InvalidChunkIdx; - for (int segIdx = 0; destinationChunkIdx == InvalidChunkIdx && segIdx < numValidSegs; ++segIdx) - { - destinationChunkIdx = BestFit_FindFreeBlockForSegment(pChunk->attr.GetSize(), chunkAlign, segIdx); - } - - CDBA_ASSERT(destinationChunkIdx != InvalidChunkIdx); - - SplitResult sr = SplitFreeBlock(destinationChunkIdx, pChunk->attr.GetSize(), chunkAlign, true); - CDBA_ASSERT(sr.bSuccessful); - - SDefragAllocChunk& destinationChunk = m_chunks[destinationChunkIdx]; - MarkAsInUse(destinationChunk); - - Pin(ChunkHdlFromIdx(destinationChunkIdx)); - MarkAsMoving(*pChunk); - - m_policy.pDefragPolicy->SyncCopy(pChunk->pContext, destinationChunk.ptr << m_logMinAlignment, pChunk->ptr << m_logMinAlignment, (UINT_PTR)pChunk->attr.GetSize() << m_logMinAlignment); - Relocate(IDefragAllocatorPolicy::InvalidUserMoveId, chunkIdx, destinationChunkIdx); - - MarkAsNotMoving(*pChunk); - Unpin(ChunkHdlFromIdx(destinationChunkIdx)); - - MarkAsFree(destinationChunk); - destinationChunkIdx = MergeFreeBlock(destinationChunkIdx); - pChunk = &m_chunks[destinationChunkIdx]; - } - - chunkIdx = pChunk->addrNextIdx; - pChunk = &m_chunks[chunkIdx]; - } -} - -void CDefragAllocator::RebuildFreeLists() -{ - for (int bi = 0; bi < NumBuckets; ++bi) - { - Index ci = m_freeBuckets[bi]; - m_chunks[ci].freeNextIdx = ci; - m_chunks[ci].freePrevIdx = ci; - } - - for (Index ci = m_chunks[AddrStartSentinal].addrNextIdx; ci != AddrEndSentinal; ci = m_chunks[ci].addrNextIdx) - { - SDefragAllocChunk& ch = m_chunks[ci]; - if (!ch.attr.IsBusy()) - { - LinkFreeChunk(ci); - } - } - -#ifdef CDBA_MORE_DEBUG - ValidateFreeLists(); -#endif -} - -void CDefragAllocator::ValidateAddressChain() -{ - UINT_PTR p = 0; - - Index hdr = 0; - for (Index ci = m_chunks[hdr].addrNextIdx; ci != hdr; ) - { - SDefragAllocChunk& c = m_chunks[ci]; - - CDBA_ASSERT(p == c.ptr); - p += c.attr.GetSize(); - - ci = c.addrNextIdx; - } - - for (int bi = 0; bi < NumBuckets; ++bi) - { - hdr = m_freeBuckets[bi]; - - for (Index ci = m_chunks[hdr].freeNextIdx; ci != hdr; ) - { - SDefragAllocChunk& c = m_chunks[ci]; - - CDBA_ASSERT(!c.attr.IsBusy()); - - ci = c.freeNextIdx; - } - } -} - -void CDefragAllocator::ValidateFreeLists() -{ -#if defined(CDBA_DEBUG) - for (size_t bucket = 0; bucket < NumBuckets; ++bucket) - { - size_t rootIdx = m_freeBuckets[bucket]; - SDefragAllocChunk& root = m_chunks[rootIdx]; - - for (size_t idx = root.freeNextIdx; idx != rootIdx; idx = m_chunks[idx].freeNextIdx) - { - SDefragAllocChunk& chunk = m_chunks[idx]; - - CDBA_ASSERT(!chunk.attr.IsBusy()); - CDBA_ASSERT(max((uint32)1, (uint32)chunk.attr.GetSize()) >= (1U << bucket)); - CDBA_ASSERT(idx >= NumBuckets + 2); - - CDBA_ASSERT(m_chunks[chunk.freeNextIdx].freePrevIdx == idx); - CDBA_ASSERT(m_chunks[chunk.freePrevIdx].freeNextIdx == idx); - } - - for (size_t idx = root.freePrevIdx; idx != rootIdx; idx = m_chunks[idx].freePrevIdx) - { - SDefragAllocChunk& chunk = m_chunks[idx]; - - CDBA_ASSERT(!chunk.attr.IsBusy()); - CDBA_ASSERT(max((uint32)1, (uint32)chunk.attr.GetSize()) >= (1U << bucket)); - CDBA_ASSERT(idx >= NumBuckets + 2); - - CDBA_ASSERT(m_chunks[chunk.freeNextIdx].freePrevIdx == idx); - CDBA_ASSERT(m_chunks[chunk.freePrevIdx].freeNextIdx == idx); - } - } -#endif -} diff --git a/Code/CryEngine/CrySystem/DefragAllocator.h b/Code/CryEngine/CrySystem/DefragAllocator.h deleted file mode 100644 index 183b10bb7f..0000000000 --- a/Code/CryEngine/CrySystem/DefragAllocator.h +++ /dev/null @@ -1,712 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_CRYSYSTEM_DEFRAGALLOCATOR_H -#define CRYINCLUDE_CRYSYSTEM_DEFRAGALLOCATOR_H -#pragma once - - -#include "IDefragAllocator.h" - -#include "System.h" - -#ifndef _RELEASE -#define CDBA_DEBUG -#endif - -//#define CDBA_MORE_DEBUG - -#ifdef CDBA_DEBUG -#define CDBA_ASSERT(x) do { assert(x); if (!(x)) {__debugbreak(); } \ -} while (0) -#else -#define CDBA_ASSERT(x) assert(x) -#endif - -union SDefragAllocChunkAttr -{ - enum - { - SizeWidth = 27, - SizeMask = (1 << SizeWidth) - 1, - BusyMask = 1 << 27, - MovingMask = 1 << 28, - MaxPinCount = 7, - PinnedCountShift = 29, - PinnedIncMask = 1 << PinnedCountShift, - PinnedCountMask = MaxPinCount << PinnedCountShift, - }; - - uint32 ui; - - ILINE unsigned int GetSize() const { return ui & SizeMask; } - ILINE void SetSize(unsigned int size) { ui = (ui & ~SizeMask) | size; } - ILINE void AddSize(int size) { ui += size; } - ILINE bool IsBusy() const { return (ui & BusyMask) != 0; } - ILINE void SetBusy(bool b) { ui = b ? (ui | BusyMask) : (ui & ~BusyMask); } - ILINE bool IsMoving() const { return (ui & MovingMask) != 0; } - ILINE void SetMoving(bool m) { ui = m ? (ui | MovingMask) : (ui & ~MovingMask); } - ILINE void IncPinCount() { ui += PinnedIncMask; } - ILINE void DecPinCount() { ui -= PinnedIncMask; } - ILINE bool IsPinned() const { return (ui & PinnedCountMask) != 0; } - ILINE unsigned int GetPinCount() const { return (ui & PinnedCountMask) >> PinnedCountShift; } - ILINE void SetPinCount(unsigned int p) { ui = (ui & ~PinnedCountMask) | (p << PinnedCountShift); } -}; - -struct SDefragAllocChunk -{ - enum - { - AlignBitCount = 4, - }; - typedef IDefragAllocator::Hdl Index; - - Index addrPrevIdx; - Index addrNextIdx; - - union - { - struct - { - UINT_PTR ptr : sizeof(UINT_PTR) * 8 - AlignBitCount; - UINT_PTR logAlign: AlignBitCount; - }; - UINT_PTR packedPtr; - }; - SDefragAllocChunkAttr attr; - - union - { - void* pContext; - struct - { - Index freePrevIdx; - Index freeNextIdx; - }; - }; - -#ifndef _RELEASE - const char* source; -#endif - - void SwapEndian() - { - ::SwapEndian(addrPrevIdx, true); - ::SwapEndian(addrNextIdx, true); - ::SwapEndian(packedPtr, true); - ::SwapEndian(attr.ui, true); - - if (attr.IsBusy()) - { - ::SwapEndian(pContext, true); - } - else - { - ::SwapEndian(freePrevIdx, true); - ::SwapEndian(freeNextIdx, true); - } - -#ifndef _RELEASE - ::SwapEndian(source, true); -#endif - } -}; - -struct SDefragAllocSegment -{ - uint32 address; - uint32 capacity; - SDefragAllocChunk::Index headSentinalChunkIdx; - - void SwapEndian() - { - ::SwapEndian(address, true); - ::SwapEndian(capacity, true); - ::SwapEndian(headSentinalChunkIdx, true); - } -}; - -class CDefragAllocator; - -class CDefragAllocatorWalker -{ -public: - explicit CDefragAllocatorWalker(CDefragAllocator& alloc); - ~CDefragAllocatorWalker(); - - const SDefragAllocChunk* Next(); - -private: - CDefragAllocatorWalker(const CDefragAllocatorWalker&); - CDefragAllocatorWalker& operator = (const CDefragAllocatorWalker&); - -private: - CDefragAllocator* m_pAlloc; - SDefragAllocChunk::Index m_nChunkIdx; -}; - -class CDefragAllocator - : public IDefragAllocator -{ - friend class CDefragAllocatorWalker; - typedef SDefragAllocChunk::Index Index; - -public: - CDefragAllocator(); - - void Release(bool bDiscard); - - void Init(UINT_PTR capacity, UINT_PTR minAlignment, const Policy& policy); - -#ifndef _RELEASE - void DumpState(const char* filename); - void RestoreState(const char* filename); -#endif - - // allocatorDisplayOffset will offset the statistics for the allocator depending on the index. - // 0 means no offset and default location, 1 means bar will be rendered above the 0th bar and stats to the right of the 0th stats - void DisplayMemoryUsage(const char* title, unsigned int allocatorDisplayOffset = 0); - - bool AppendSegment(UINT_PTR capacity); - void UnAppendSegment(); - - Hdl Allocate(size_t sz, const char* source, void* pContext = NULL); - Hdl AllocateAligned(size_t sz, size_t alignment, const char* source, void* pContext = NULL); - AllocatePinnedResult AllocatePinned(size_t sz, const char* source, void* pContext = NULL); - bool Free(Hdl hdl); - - void ChangeContext(Hdl hdl, void* pNewContext); - - size_t GetAllocated() const { return (size_t)(m_capacity - m_available) << m_logMinAlignment; } - IDefragAllocatorStats GetStats(); - - size_t DefragmentTick(size_t maxMoves, size_t maxAmount, bool bForce); - - ILINE UINT_PTR UsableSize(Hdl hdl) - { - Index chunkIdx = ChunkIdxFromHdl(hdl); - CDBA_ASSERT(chunkIdx < m_chunks.size()); - - SDefragAllocChunk& chunk = m_chunks[chunkIdx]; - SDefragAllocChunkAttr attr = chunk.attr; - - CDBA_ASSERT(attr.IsBusy()); - return (UINT_PTR)attr.GetSize() << m_logMinAlignment; - } - - // Pin the chunk until the next defrag tick, when it will be automatically unpinned - ILINE UINT_PTR WeakPin(Hdl hdl) - { - Index chunkIdx = ChunkIdxFromHdl(hdl); - CDBA_ASSERT(chunkIdx < m_chunks.size()); - - SDefragAllocChunk& chunk = m_chunks[chunkIdx]; - SDefragAllocChunkAttr attr = chunk.attr; - CDBA_ASSERT(attr.IsBusy()); - - if (attr.IsMoving()) - { - CancelMove(chunkIdx, true); - } - - return chunk.ptr << m_logMinAlignment; - } - - // Pin the chunk until Unpin is called - ILINE UINT_PTR Pin(Hdl hdl) - { - Index chunkIdx = ChunkIdxFromHdl(hdl); - - SDefragAllocChunk& chunk = m_chunks[chunkIdx]; - SDefragAllocChunkAttr attr; - SDefragAllocChunkAttr newAttr; - - do - { - attr.ui = const_cast(chunk.attr.ui); - newAttr.ui = attr.ui; - - CDBA_ASSERT(attr.GetPinCount() < SDefragAllocChunkAttr::MaxPinCount); - CDBA_ASSERT(attr.IsBusy()); - - newAttr.IncPinCount(); - } - while (CryInterlockedCompareExchange(alias_cast(&chunk.attr.ui), newAttr.ui, attr.ui) != attr.ui); - - // Potentially a Relocate could be in progress here. Either the Relocate is mid-way, in which case 'IsMoving()' will - // still be set, and CancelMove will sync and all is well. - - // If 'IsMoving()' is not set, the Relocate should have just completed, in which case ptr should validly point - // to the new location. - - if (attr.IsMoving()) - { - CancelMove(chunkIdx, true); - } - - return chunk.ptr << m_logMinAlignment; - } - - ILINE void Unpin(Hdl hdl) - { - SDefragAllocChunk& chunk = m_chunks[ChunkIdxFromHdl(hdl)]; - SDefragAllocChunkAttr attr; - SDefragAllocChunkAttr newAttr; - do - { - attr.ui = const_cast(chunk.attr.ui); - newAttr.ui = attr.ui; - - CDBA_ASSERT(attr.IsPinned()); - CDBA_ASSERT(attr.IsBusy()); - - newAttr.DecPinCount(); - } - while (CryInterlockedCompareExchange(alias_cast(&chunk.attr.ui), newAttr.ui, attr.ui) != attr.ui); - } - - ILINE const char* GetSourceOf([[maybe_unused]] Hdl hdl) - { -#ifndef _RELEASE - return m_chunks[ChunkIdxFromHdl(hdl)].source; -#else - return ""; -#endif - } - -private: - enum - { - NumBuckets = 31, // 2GB - MaxPendingMoves = 64, - - AddrStartSentinal = 0, - AddrEndSentinal = 1, - }; - - struct SplitResult - { - bool bSuccessful; - Index nLeftSplitChunkIdx; - Index nRightSplitChunkIdx; - }; - - struct PendingMove - { - PendingMove() - : srcChunkIdx(InvalidChunkIdx) - , dstChunkIdx(InvalidChunkIdx) - , userMoveId(0) - , relocated(false) - , cancelled(false) - { - } - - Index srcChunkIdx; - Index dstChunkIdx; - uint32 userMoveId; - IDefragAllocatorCopyNotification notify; - bool relocated; - bool cancelled; - - void SwapEndian() - { - ::SwapEndian(srcChunkIdx, true); - ::SwapEndian(dstChunkIdx, true); - ::SwapEndian(userMoveId, true); - } - }; - - struct PendingMoveSrcChunkPredicate - { - PendingMoveSrcChunkPredicate(Index ci) - : m_ci(ci) {} - bool operator () (const PendingMove& pm) const { return pm.srcChunkIdx == m_ci; } - Index m_ci; - }; - - typedef DynArray PendingMoveVec; - typedef std::vector SegmentVec; - - static const Index InvalidChunkIdx = (Index) - 1; - -private: - static ILINE Index ChunkIdxFromHdl(Hdl id) { return id - 1; } - static ILINE Hdl ChunkHdlFromIdx(Index idx) { return idx + 1; } - -private: - ~CDefragAllocator(); - - Index AllocateChunk(); - void ReleaseChunk(Index idx); - - ILINE void MarkAsInUse(SDefragAllocChunk& chunk) - { - CDBA_ASSERT(!chunk.attr.IsBusy()); - - chunk.attr.SetBusy(true); - m_available -= chunk.attr.GetSize(); - ++m_numAllocs; - - // m_available is unsigned, so check for underflow - CDBA_ASSERT(m_available <= m_capacity); - } - - ILINE void MarkAsFree(SDefragAllocChunk& chunk) - { - CDBA_ASSERT(chunk.attr.IsBusy()); - - chunk.attr.SetPinCount(0); - chunk.attr.SetMoving(false); - chunk.attr.SetBusy(0); - m_available += chunk.attr.GetSize(); - --m_numAllocs; - - // m_available is unsigned, so check for underflow - CDBA_ASSERT(m_available <= m_capacity); - } - - void LinkFreeChunk(Index idx); - void UnlinkFreeChunk(Index idx) - { - SDefragAllocChunk& chunk = m_chunks[idx]; - m_chunks[chunk.freePrevIdx].freeNextIdx = chunk.freeNextIdx; - m_chunks[chunk.freeNextIdx].freePrevIdx = chunk.freePrevIdx; - } - - void LinkAddrChunk(Index idx, Index afterIdx) - { - SDefragAllocChunk& chunk = m_chunks[idx]; - SDefragAllocChunk& afterChunk = m_chunks[afterIdx]; - - chunk.addrNextIdx = afterChunk.addrNextIdx; - chunk.addrPrevIdx = afterIdx; - m_chunks[chunk.addrNextIdx].addrPrevIdx = idx; - afterChunk.addrNextIdx = idx; - } - - void UnlinkAddrChunk(Index id) - { - SDefragAllocChunk& chunk = m_chunks[id]; - - m_chunks[chunk.addrPrevIdx].addrNextIdx = chunk.addrNextIdx; - m_chunks[chunk.addrNextIdx].addrPrevIdx = chunk.addrPrevIdx; - } - - void PrepareMergePopNext(Index* pLists) - { - for (int bucketIdx = 0; bucketIdx < NumBuckets; ++bucketIdx) - { - Index hdrChunkId = m_freeBuckets[bucketIdx]; - Index nextId = m_chunks[hdrChunkId].freeNextIdx; - if (nextId != hdrChunkId) - { - pLists[bucketIdx] = nextId; - } - else - { - pLists[bucketIdx] = InvalidChunkIdx; - } - } - } - - size_t MergePeekNextChunk(Index* pLists) - { - size_t farList = (size_t)-1; - UINT_PTR farPtr = (UINT_PTR)-1; - - for (size_t listIdx = 0; listIdx < NumBuckets; ++listIdx) - { - Index chunkIdx = pLists[listIdx]; - if (chunkIdx != InvalidChunkIdx) - { - SDefragAllocChunk& chunk = m_chunks[chunkIdx]; - if (chunk.ptr < farPtr) - { - farPtr = chunk.ptr; - farList = listIdx; - } - } - } - - return farList; - } - - void MergePopNextChunk(Index* pLists, size_t list) - { - using std::swap; - - Index fni = m_chunks[pLists[list]].freeNextIdx; - pLists[list] = fni; - if (m_chunks[fni].attr.IsBusy()) - { - // End of the list - pLists[list] = InvalidChunkIdx; - } - } - - void MergePatchNextRemove(Index* pLists, Index removeIdx) - { - for (int bucketIdx = 0; bucketIdx < NumBuckets; ++bucketIdx) - { - if (pLists[bucketIdx] == removeIdx) - { - Index nextIdx = m_chunks[removeIdx].freeNextIdx; - if (!m_chunks[nextIdx].attr.IsBusy()) - { - pLists[bucketIdx] = nextIdx; - } - else - { - pLists[bucketIdx] = InvalidChunkIdx; - } - } - } - } - - void MergePatchNextInsert(Index* pLists, Index insertIdx) - { - SDefragAllocChunk& insertChunk = m_chunks[insertIdx]; - int bucket = BucketForSize(insertChunk.attr.GetSize()); - - if (pLists[bucket] != InvalidChunkIdx) - { - SDefragAllocChunk& listChunk = m_chunks[pLists[bucket]]; - if (listChunk.ptr > insertChunk.ptr) - { - pLists[bucket] = insertIdx; - } - } - } - - void PrepareMergePopPrev(Index* pLists) - { - for (int bucketIdx = 0; bucketIdx < NumBuckets; ++bucketIdx) - { - Index hdrChunkId = m_freeBuckets[bucketIdx]; - Index prevIdx = m_chunks[hdrChunkId].freePrevIdx; - if (prevIdx != hdrChunkId) - { - pLists[bucketIdx] = prevIdx; - } - else - { - pLists[bucketIdx] = InvalidChunkIdx; - } - } - } - - size_t MergePeekPrevChunk(Index* pLists) - { - size_t farList = (size_t)-1; - UINT_PTR farPtr = 0; - - for (size_t listIdx = 0; listIdx < NumBuckets; ++listIdx) - { - Index chunkIdx = pLists[listIdx]; - if (chunkIdx != InvalidChunkIdx) - { - SDefragAllocChunk& chunk = m_chunks[chunkIdx]; - if (chunk.ptr >= farPtr) - { - farPtr = chunk.ptr; - farList = listIdx; - } - } - } - - return farList; - } - - void MergePopPrevChunk(Index* pLists, size_t list) - { - using std::swap; - - Index fpi = m_chunks[pLists[list]].freePrevIdx; - pLists[list] = fpi; - if (m_chunks[fpi].attr.IsBusy()) - { - // End of the list - pLists[list] = InvalidChunkIdx; - } - } - - void MergePatchPrevInsert(Index* pLists, Index insertIdx) - { - SDefragAllocChunk& insertChunk = m_chunks[insertIdx]; - int bucket = BucketForSize(insertChunk.attr.GetSize()); - - if (pLists[bucket] != InvalidChunkIdx) - { - SDefragAllocChunk& listChunk = m_chunks[pLists[bucket]]; - if (listChunk.ptr < insertChunk.ptr) - { - pLists[bucket] = insertIdx; - } - } - } - - void MergePatchPrevRemove(Index* pLists, Index removeIdx) - { - for (int bucketIdx = 0; bucketIdx < NumBuckets; ++bucketIdx) - { - if (pLists[bucketIdx] == removeIdx) - { - Index nextIdx = m_chunks[removeIdx].freePrevIdx; - if (!m_chunks[nextIdx].attr.IsBusy()) - { - pLists[bucketIdx] = nextIdx; - } - else - { - pLists[bucketIdx] = InvalidChunkIdx; - } - } - } - } - - void MarkAsMoving(SDefragAllocChunk& src) - { - SDefragAllocChunkAttr srcAttr, srcNewAttr; - do - { - srcAttr.ui = const_cast(src.attr.ui); - srcNewAttr.ui = srcAttr.ui; - srcNewAttr.SetMoving(true); - } - while (CryInterlockedCompareExchange(alias_cast(&src.attr.ui), srcNewAttr.ui, srcAttr.ui) != srcAttr.ui); - } - - void MarkAsNotMoving(SDefragAllocChunk& src) - { - SDefragAllocChunkAttr srcAttr, srcNewAttr; - do - { - srcAttr.ui = const_cast(src.attr.ui); - srcNewAttr.ui = srcAttr.ui; - srcNewAttr.SetMoving(false); - } - while (CryInterlockedCompareExchange(alias_cast(&src.attr.ui), srcNewAttr.ui, srcAttr.ui) != srcAttr.ui); - } - - ILINE bool IsMoveableCandidate(const SDefragAllocChunkAttr& a, uint32 sizeUpperBound) - { - return a.IsBusy() && !a.IsPinned() && !a.IsMoving() && (0 < a.GetSize()) && (a.GetSize() <= sizeUpperBound); - } - - bool TryMarkAsMoving(SDefragAllocChunk& src, uint32 sizeUpperBound) - { - SDefragAllocChunkAttr srcAttr, srcNewAttr; - do - { - srcAttr.ui = const_cast(src.attr.ui); - srcNewAttr.ui = srcAttr.ui; - if (!IsMoveableCandidate(srcAttr, sizeUpperBound)) - { - return false; - } - srcNewAttr.SetMoving(true); - } - while (CryInterlockedCompareExchange(alias_cast(&src.attr.ui), srcNewAttr.ui, srcAttr.ui) != srcAttr.ui); - return true; - } - - bool TryScheduleCopy(SDefragAllocChunk& srcChunk, SDefragAllocChunk& dstChunk, PendingMove* pPM, bool bLowHalf) - { - UINT_PTR dstChunkBase = dstChunk.ptr; - UINT_PTR dstChunkEnd = dstChunkBase + dstChunk.attr.GetSize(); -#if AZ_LEGACY_CRYSYSTEM_TRAIT_USE_BIT64 - UINT_PTR allocAlign = BIT64(srcChunk.logAlign); -#else - UINT_PTR allocAlign = BIT(srcChunk.logAlign); -#endif - UINT_PTR allocSize = srcChunk.attr.GetSize(); - UINT_PTR dstAllocBase = bLowHalf - ? Align(dstChunkBase, allocAlign) - : ((dstChunkEnd - allocSize) & ~(allocAlign - 1)); - - uint32 userId = m_policy.pDefragPolicy->BeginCopy( - srcChunk.pContext, - dstAllocBase << m_logMinAlignment, - srcChunk.ptr << m_logMinAlignment, - allocSize << m_logMinAlignment, - &pPM->notify); - pPM->userMoveId = userId; - - return userId != 0; - } - - Hdl Allocate_Locked(size_t sz, size_t alignment, const char* source, void* pContext); - SplitResult SplitFreeBlock(Index fbId, size_t sz, size_t alignment, bool allocateInLowHalf); - Index MergeFreeBlock(Index fbId); - -#ifdef CDBA_MORE_DEBUG - void Defrag_ValidateFreeBlockIteration(); -#endif - - Index BestFit_FindFreeBlockForSegment(size_t sz, size_t alignment, uint32 nSegment); - Index BestFit_FindFreeBlockFor(size_t sz, size_t alignment, UINT_PTR addressMin, UINT_PTR addressMax, bool allocateInLowHalf); - Index FirstFit_FindFreeBlockFor(size_t sz, size_t alignment, UINT_PTR addressMin, UINT_PTR addressMax, bool allocateInLowHalf); - - size_t Defrag_FindMovesBwd(PendingMove** pMoves, size_t maxMoves, size_t& curAmount, size_t maxAmount); - size_t Defrag_FindMovesFwd(PendingMove** pMoves, size_t maxMoves, size_t& curAmount, size_t maxAmount); - bool Defrag_CompletePendingMoves(); - Index Defrag_Bwd_FindFreeBlockFor(size_t sz, size_t alignment, UINT_PTR addressLimit); - Index Defrag_Fwd_FindFreeBlockFor(size_t sz, size_t alignment, UINT_PTR addressLimit); - - PendingMove* AllocPendingMove(); - void FreePendingMove(PendingMove* pMove); - - void CancelMove(Index srcChunkIdx, bool bIsContentNeeded); - void CancelMove_Locked(Index srcChunkIdx, bool bIsContentNeeded); - void Relocate(uint32 userMoveId, Index srcChunkIdx, Index dstChunkIdx); - - void SyncMoveSegment(uint32 seg); - - void RebuildFreeLists(); - void ValidateAddressChain(); - void ValidateFreeLists(); - - int BucketForSize(size_t sz) const - { - return sz > 0 - ? static_cast(IntegerLog2(sz)) - : 0; - } - -private: - bool m_isThreadSafe; - bool m_chunksAreFixed; - - CryCriticalSection m_lock; - - uint32 m_capacity; - uint32 m_available; - Index m_numAllocs; - - uint16 m_minAlignment; - uint16 m_logMinAlignment; - - Index m_freeBuckets[NumBuckets]; - - std::vector m_chunks; - std::vector m_unusedChunks; - PendingMoveVec m_pendingMoves; - SegmentVec m_segments; - - uint32 m_nCancelledMoves; - - Policy m_policy; -}; - -#endif // CRYINCLUDE_CRYSYSTEM_DEFRAGALLOCATOR_H diff --git a/Code/CryEngine/CrySystem/HMDCVars.cpp b/Code/CryEngine/CrySystem/HMDCVars.cpp deleted file mode 100644 index 4ef08db729..0000000000 --- a/Code/CryEngine/CrySystem/HMDCVars.cpp +++ /dev/null @@ -1,102 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "CrySystem_precompiled.h" -#include "HMDCVars.h" -#include -#include - -namespace AZ -{ -namespace VR -{ - -void HMDCVars::OnHMDRecenter([[maybe_unused]] IConsoleCmdArgs* args) -{ - EBUS_EVENT(AZ::VR::HMDDeviceRequestBus, RecenterPose); -} - -void HMDCVars::OnHMDTrackingLevelChange(IConsoleCmdArgs* args) -{ - if (args->GetArgCount() != 2) - { - // First arg should be the command itself, second arg should be the requested tracking level. - return; - } - - // Read the new tracking level. - int argVal = 0; - std::stringstream stream(args->GetArg(1)); - stream >> argVal; - - AZ::VR::HMDTrackingLevel level = static_cast(argVal); - EBUS_EVENT(AZ::VR::HMDDeviceRequestBus, SetTrackingLevel, level); -} - -void HMDCVars::OnOutputToHMDChanged(ICVar* var) -{ - // Set the necessary cvars for turning on/off output to an HMD. - ICVar* mode = gEnv->pConsole->GetCVar("r_StereoMode"); - ICVar* output = gEnv->pConsole->GetCVar("r_StereoOutput"); - ICVar* height = gEnv->pConsole->GetCVar("r_height"); - ICVar* width = gEnv->pConsole->GetCVar("r_width"); - - if (!mode || !output || !height || !width) - { - return; - } - - bool enable = (var->GetIVal() == 1); - if (enable) - { - // Auto-set the resolution. - { - const AZ::VR::HMDDeviceInfo* deviceInfo = nullptr; - EBUS_EVENT_RESULT(deviceInfo, AZ::VR::HMDDeviceRequestBus, GetDeviceInfo); - - // If the device info exists then there is a VR device connected and working. - if (deviceInfo) - { - mode->Set(EStereoMode::STEREO_MODE_DUAL_RENDERING); - output->Set(EStereoOutput::STEREO_OUTPUT_HMD); - - width->Set(static_cast(deviceInfo->renderWidth)); - height->Set(static_cast(deviceInfo->renderHeight)); - } - } - } - else - { - mode->Set(EStereoMode::STEREO_MODE_NO_STEREO); - output->Set(EStereoOutput::STEREO_OUTPUT_STANDARD); - } -} - -void HMDCVars::OnHMDDebugInfo(ICVar* var) -{ - bool enable = (var->GetIVal() == 1); - EBUS_EVENT(AZ::VR::HMDDebuggerRequestBus, EnableInfo, enable); -} - -void HMDCVars::OnHMDDebugCamera(ICVar* var) -{ - bool enable = (var->GetIVal() == 1); - EBUS_EVENT(AZ::VR::HMDDebuggerRequestBus, EnableCamera, enable); -} - -int HMDCVars::hmd_social_screen = static_cast(HMDSocialScreen::UndistortedLeftEye); -int HMDCVars::hmd_debug_info = 0; -int HMDCVars::hmd_debug_camera = 0; - -} // namespace VR -} // namespace AZ diff --git a/Code/CryEngine/CrySystem/HMDCVars.h b/Code/CryEngine/CrySystem/HMDCVars.h deleted file mode 100644 index f449bb0725..0000000000 --- a/Code/CryEngine/CrySystem/HMDCVars.h +++ /dev/null @@ -1,71 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - - -#pragma once - -#include -#include - -namespace AZ -{ - namespace VR - { - class HMDCVars - { - public: - - static int hmd_social_screen; - static int hmd_debug_info; - static int hmd_debug_camera; - - static void Register() - { - REGISTER_CVAR2("hmd_social_screen", &hmd_social_screen, hmd_social_screen, - VF_NULL, "Selects the social screen mode: \n" - "-1- Off\n" - "0 - Undistorted left eye\n" - "1 - Undistorted right eye\n" - ); - - REGISTER_INT_CB("hmd_debug_info", 0, VF_ALWAYSONCHANGE, - "Enable/disable HMD and VR controller debug info/rendering", - OnHMDDebugInfo); - - REGISTER_INT_CB("hmd_debug_camera", 0, VF_ALWAYSONCHANGE, - "Enable/disable HMD debug camera", - OnHMDDebugCamera); - - REGISTER_COMMAND("hmd_tracking_level", &OnHMDTrackingLevelChange, - VF_NULL, "Set the HMD center reference point.\n" - "0 - Camera (Actor's head)\n" - "1 - Actor's feet (floor)\n"); - - REGISTER_COMMAND("hmd_recenter_pose", &OnHMDRecenter, - VF_NULL, "Re-centers sensor orientation of the HMD."); - - REGISTER_INT_CB("output_to_hmd", 0, VF_ALWAYSONCHANGE, - "Enable/disable output to any connected HMD (for VR)", - OnOutputToHMDChanged); - } - - private: - - static void OnHMDRecenter(IConsoleCmdArgs* args); - static void OnHMDTrackingLevelChange(IConsoleCmdArgs* args); - static void OnOutputToHMDChanged(ICVar* var); - static void OnHMDDebugInfo(ICVar* var); - static void OnHMDDebugCamera(ICVar* var); - }; - } // namespace VR -} // namespace AZ diff --git a/Code/CryEngine/CrySystem/IDebugCallStack.cpp b/Code/CryEngine/CrySystem/IDebugCallStack.cpp index d73d70ab8b..3d865dee6c 100644 --- a/Code/CryEngine/CrySystem/IDebugCallStack.cpp +++ b/Code/CryEngine/CrySystem/IDebugCallStack.cpp @@ -258,28 +258,6 @@ void IDebugCallStack::WriteLineToLog(const char* format, ...) } } -void IDebugCallStack::Screenshot(const char* szFileName) -{ - WriteLineToLog("Attempting to create error screenshot \"%s\"", szFileName); - - static int g_numScreenshots = 0; - if (gEnv->pRenderer && !g_numScreenshots++) - { - if (gEnv->pRenderer->ScreenShot(szFileName)) - { - WriteLineToLog("Successfully created screenshot."); - } - else - { - WriteLineToLog("Error creating screenshot."); - } - } - else - { - WriteLineToLog("Ignoring multiple calls to Screenshot"); - } -} - ////////////////////////////////////////////////////////////////////////// void IDebugCallStack::StartMemLog() { diff --git a/Code/CryEngine/CrySystem/IDebugCallStack.h b/Code/CryEngine/CrySystem/IDebugCallStack.h index 7b54c0cac0..f181b73913 100644 --- a/Code/CryEngine/CrySystem/IDebugCallStack.h +++ b/Code/CryEngine/CrySystem/IDebugCallStack.h @@ -77,8 +77,6 @@ protected: static const char* TranslateExceptionCode(DWORD dwExcept); static void PutVersion(char* str, size_t length); - static void Screenshot(const char* szFileName); - bool m_bIsFatalError; static const char* const s_szFatalErrorCode; diff --git a/Code/CryEngine/CrySystem/LevelSystem/LevelSystem.cpp b/Code/CryEngine/CrySystem/LevelSystem/LevelSystem.cpp index 8818dfa0d9..b8002b74a9 100644 --- a/Code/CryEngine/CrySystem/LevelSystem/LevelSystem.cpp +++ b/Code/CryEngine/CrySystem/LevelSystem/LevelSystem.cpp @@ -20,7 +20,6 @@ #include "IMaterialEffects.h" #include #include -#include "IDeferredCollisionEvent.h" #include "CryPath.h" #include @@ -846,11 +845,6 @@ void CLevelSystem::OnLoadingError(const char* levelName, const char* error) return; } - if (gEnv->pRenderer) - { - gEnv->pRenderer->SetTexturePrecaching(false); - } - for (AZStd::vector::const_iterator it = m_listeners.begin(); it != m_listeners.end(); ++it) { (*it)->OnLoadingError(levelName, error); @@ -968,33 +962,6 @@ void CLevelSystem::UnloadLevel() CTimeValue tBegin = gEnv->pTimer->GetAsyncTime(); - //AM: Flush render thread (Flush is not exposed - using EndFrame()) - //We are about to delete resources that could be in use - if (gEnv->pRenderer) - { - gEnv->pRenderer->EndFrame(); - - - bool isLoadScreenPlaying = false; -#if AZ_LOADSCREENCOMPONENT_ENABLED - LoadScreenBus::BroadcastResult(isLoadScreenPlaying, &LoadScreenBus::Events::IsPlaying); -#endif // if AZ_LOADSCREENCOMPONENT_ENABLED - - // force a black screen as last render command. - //if load screen is playing do not call this draw as it may lead to a crash due to UI loading code getting - //pumped while loading the shaders for this draw. - if (!isLoadScreenPlaying) - { - gEnv->pRenderer->BeginFrame(); - gEnv->pRenderer->SetState(GS_BLSRC_SRCALPHA | GS_BLDST_ONEMINUSSRCALPHA | GS_NODEPTHTEST); - gEnv->pRenderer->Draw2dImage(0, 0, 800, 600, -1, 0.0f, 0.0f, 1.0f, 1.0f, 0.f, 0.0f, 0.0f, 0.0f, 1.0, 0.f); - gEnv->pRenderer->EndFrame(); - } - - //flush any outstanding texture requests - gEnv->pRenderer->FlushPendingTextureTasks(); - } - // Clear level entities and prefab instances. EBUS_EVENT(AzFramework::GameEntityContextRequestBus, ResetGameContext); @@ -1045,27 +1012,6 @@ void CLevelSystem::UnloadLevel() // Normally the GC step is triggered at the end of this method (by the ESYSTEM_EVENT_LEVEL_POST_UNLOAD event). EBUS_EVENT(AZ::ScriptSystemRequestBus, GarbageCollect); - // Force to clean render resources left after deleting all objects and materials. - IRenderer* pRenderer = gEnv->pRenderer; - if (pRenderer) - { - pRenderer->FlushRTCommands(true, true, true); - - CryComment("Deleting Render meshes, render resources and flush texture streaming"); - // This may also release some of the materials. - int flags = FRR_DELETED_MESHES | FRR_FLUSH_TEXTURESTREAMING | FRR_OBJECTS | FRR_RENDERELEMENTS | FRR_RP_BUFFERS | FRR_POST_EFFECTS; - - // Always keep the system resources around in the editor. - // If a level load fails for any reason, then do not unload the system resources, otherwise we will not have any system resources to continue rendering the console and debug output text. - if (!gEnv->IsEditor() && !GetLevelLoadFailed()) - { - flags |= FRR_SYSTEM_RESOURCES; - } - - pRenderer->FreeResources(flags); - CryComment("done"); - } - // Perform level unload procedures for the LyShine UI system if (gEnv && gEnv->pLyShine) { diff --git a/Code/CryEngine/CrySystem/LevelSystem/SpawnableLevelSystem.cpp b/Code/CryEngine/CrySystem/LevelSystem/SpawnableLevelSystem.cpp index 4b6e210522..2a7f8d5c5e 100644 --- a/Code/CryEngine/CrySystem/LevelSystem/SpawnableLevelSystem.cpp +++ b/Code/CryEngine/CrySystem/LevelSystem/SpawnableLevelSystem.cpp @@ -15,7 +15,6 @@ #include #include "IMovieSystem.h" #include -#include "IDeferredCollisionEvent.h" #include @@ -423,11 +422,6 @@ namespace LegacyLevelSystem { AZ_Error("LevelSystem", false, "Error loading level '%s': %s\n", levelName, error); - if (gEnv->pRenderer) - { - gEnv->pRenderer->SetTexturePrecaching(false); - } - for (auto& listener : m_listeners) { listener->OnLoadingError(levelName, error); @@ -541,32 +535,6 @@ namespace LegacyLevelSystem CTimeValue tBegin = gEnv->pTimer->GetAsyncTime(); - // AM: Flush render thread (Flush is not exposed - using EndFrame()) - // We are about to delete resources that could be in use - if (gEnv->pRenderer) - { - gEnv->pRenderer->EndFrame(); - - bool isLoadScreenPlaying = false; - #if AZ_LOADSCREENCOMPONENT_ENABLED - LoadScreenBus::BroadcastResult(isLoadScreenPlaying, &LoadScreenBus::Events::IsPlaying); - #endif // if AZ_LOADSCREENCOMPONENT_ENABLED - - // force a black screen as last render command. - // if load screen is playing do not call this draw as it may lead to a crash due to UI loading code getting - // pumped while loading the shaders for this draw. - if (!isLoadScreenPlaying) - { - gEnv->pRenderer->BeginFrame(); - gEnv->pRenderer->SetState(GS_BLSRC_SRCALPHA | GS_BLDST_ONEMINUSSRCALPHA | GS_NODEPTHTEST); - gEnv->pRenderer->Draw2dImage(0, 0, 800, 600, -1, 0.0f, 0.0f, 1.0f, 1.0f, 0.f, 0.0f, 0.0f, 0.0f, 1.0, 0.f); - gEnv->pRenderer->EndFrame(); - } - - // flush any outstanding texture requests - gEnv->pRenderer->FlushPendingTextureTasks(); - } - // Clear level entities and prefab instances. EBUS_EVENT(AzFramework::GameEntityContextRequestBus, ResetGameContext); @@ -608,28 +576,6 @@ namespace LegacyLevelSystem // Normally the GC step is triggered at the end of this method (by the ESYSTEM_EVENT_LEVEL_POST_UNLOAD event). EBUS_EVENT(AZ::ScriptSystemRequestBus, GarbageCollect); - // Force to clean render resources left after deleting all objects and materials. - IRenderer* pRenderer = gEnv->pRenderer; - if (pRenderer) - { - pRenderer->FlushRTCommands(true, true, true); - - CryComment("Deleting Render meshes, render resources and flush texture streaming"); - // This may also release some of the materials. - int flags = FRR_DELETED_MESHES | FRR_FLUSH_TEXTURESTREAMING | FRR_OBJECTS | FRR_RENDERELEMENTS | FRR_RP_BUFFERS | FRR_POST_EFFECTS; - - // Always keep the system resources around in the editor. - // If a level load fails for any reason, then do not unload the system resources, otherwise we will not have any system resources to - // continue rendering the console and debug output text. - if (!gEnv->IsEditor() && !GetLevelLoadFailed()) - { - flags |= FRR_SYSTEM_RESOURCES; - } - - pRenderer->FreeResources(flags); - CryComment("done"); - } - // Perform level unload procedures for the LyShine UI system if (gEnv && gEnv->pLyShine) { diff --git a/Code/CryEngine/CrySystem/LocalizedStringManager.cpp b/Code/CryEngine/CrySystem/LocalizedStringManager.cpp index a11e068a9b..7a2ad51e8b 100644 --- a/Code/CryEngine/CrySystem/LocalizedStringManager.cpp +++ b/Code/CryEngine/CrySystem/LocalizedStringManager.cpp @@ -32,9 +32,6 @@ #include #include -#if !defined(_RELEASE) -#include "CrySizerImpl.h" -#endif //#if !defined(_RELEASE) #define MAX_CELL_COUNT 32 @@ -165,52 +162,6 @@ static void TestFormatMessage ([[maybe_unused]] IConsoleCmdArgs* pArgs) } #endif //#if !defined(_RELEASE) - -////////////////////////////////////////////////////////////////////////// -#if !defined(_RELEASE) -void CLocalizedStringsManager::LocalizationDumpLoadedInfo([[maybe_unused]] IConsoleCmdArgs* pArgs) -{ - CLocalizedStringsManager* pLoca = (CLocalizedStringsManager*) gEnv->pSystem->GetLocalizationManager(); - - for (TTagFileNames::iterator tagit = pLoca->m_tagFileNames.begin(); tagit != pLoca->m_tagFileNames.end(); ++tagit) - { - CryLogAlways("Tag %s (%d)", tagit->first.c_str(), tagit->second.id); - - int entries = 0; - CrySizerImpl* pSizer = new CrySizerImpl(); - - for (tmapFilenames::iterator it = pLoca->m_loadedTables.begin(); it != pLoca->m_loadedTables.end(); it++) - { - if (tagit->second.id == it->second.nTagID) - { - CryLogAlways("\t%s", it->first.c_str()); - } - - if (pLoca->m_pLanguage) - { - const uint32 numEntries = pLoca->m_pLanguage->m_vLocalizedStrings.size(); - for (int32 i = numEntries - 1; i >= 0; i--) - { - SLocalizedStringEntry* entry = pLoca->m_pLanguage->m_vLocalizedStrings[i]; - if (tagit->second.id == entry->nTagID) - { - entries++; - entry->GetMemoryUsage((ICrySizer*) pSizer); - } - } - } - } - - // This line messes up Uncrustify so turn it off: *INDENT-OFF* - CryLogAlways("\t\tEntries %d, Approx Size %" PRISIZE_T "Kb", entries, pSizer->GetTotalSize() / 1024); - // turn it back on again: *INDENT-ON* - - SAFE_RELEASE(pSizer); - } -} - -#endif //#if !defined(_RELEASE) - ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// @@ -249,9 +200,6 @@ CLocalizedStringsManager::CLocalizedStringsManager(ISystem* pSystem) "0: No encoding, store as wide strings\n" "1: Huffman encode translated text, saves approx 30% with a small runtime performance cost\n" "Default is 1."); - - - REGISTER_COMMAND("LocalizationDumpLoadedInfo", LocalizationDumpLoadedInfo, VF_NULL, "Dump out into about the loaded localization files"); #endif //#if !defined(_RELEASE) REGISTER_CVAR2(c_sys_localization_format, &m_cvarLocalizationFormat, 1, VF_NULL, diff --git a/Code/CryEngine/CrySystem/LocalizedStringManager.h b/Code/CryEngine/CrySystem/LocalizedStringManager.h index 6b7ef6060b..1f18ba5c4a 100644 --- a/Code/CryEngine/CrySystem/LocalizedStringManager.h +++ b/Code/CryEngine/CrySystem/LocalizedStringManager.h @@ -96,10 +96,6 @@ public: void GetLoadedTags(TLocalizationTagVec& tagVec); void FreeLocalizationData(); -#if !defined(_RELEASE) - static void LocalizationDumpLoadedInfo(IConsoleCmdArgs* pArgs); -#endif //#if !defined(_RELEASE) - private: void SetAvailableLocalizationsBitfield(const ILocalizationManager::TLocalizationBitfield availableLocalizations); diff --git a/Code/CryEngine/CrySystem/MemoryFragmentationProfiler.h b/Code/CryEngine/CrySystem/MemoryFragmentationProfiler.h deleted file mode 100644 index 7d373bb472..0000000000 --- a/Code/CryEngine/CrySystem/MemoryFragmentationProfiler.h +++ /dev/null @@ -1,325 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_CRYSYSTEM_MEMORYFRAGMENTATIONPROFILER_H -#define CRYINCLUDE_CRYSYSTEM_MEMORYFRAGMENTATIONPROFILER_H -#pragma once - - -// useful class to investigate memory fragmentation -// every time you call this from the console: -// -// #System.DumpMemoryCoverage() -// -// it adds a line to "MemoryCoverage.bmp" (generated the first time, there is a max line count) -// blue stripes mark some special positions (DLL positions) - -// Dependencies: only CryLog() - - -#include // STL vector<> - - -#if defined(WIN32) || defined(WIN64) - -class CMemoryFragmentationProfiler -{ -public: - - // constructor - clean file - CMemoryFragmentationProfiler() - : m_dwLine(0xffffffff) // 0xffffffff means not initialized yet - { - } - - // call this if you want to add one line (on first call the file is generated) - void DumpMemoryCoverage() - { - if (m_dwLine == 0xffffffff) - { - Init(); - } - - const size_t nMinMemoryPerUnit = 4 * 1024; // down to a few KB - const size_t nUnitsPerLine = 1024 * 8; // amount of bits, should only occupy a few KB memory - - const size_t nMaxMemoryPerUnit = 0x100000000 / nUnitsPerLine; // 4GB in total - - static std::vector vCoverage; - - vCoverage.clear(); - vCoverage.resize(nUnitsPerLine, 0); // should occupy nUnitsPerLine/8 bytes (vector is specialized) - - size_t nAvailableMem = 0, nUsedMem = 0; - - const size_t nMallocOverhead = 24; // depends on used runtime (debug:32, release:24) - - size_t nCurrentUnitSize = 256 * 1024 * 1024; // start with 256 MB blocks - - void** pMemoryBlocks = 0; // linked list of memory blocks (to free them) - - size_t nUnits = 0; - uint32 dwAllocCnt = 0, dwFreeCnt = 0; - - while (nCurrentUnitSize >= nMinMemoryPerUnit) - { - size_t nLocalUnits = 0; - - for (;; ) - { - void** pMem = (void**)::malloc(nCurrentUnitSize - nMallocOverhead); - - if (!pMem) - { - break; - } - - ++dwAllocCnt; - - // update coverage (conservative) - { - size_t nStartUnit = ((size_t)pMem + nMaxMemoryPerUnit - 1) / (nMaxMemoryPerUnit); - size_t nEndUnit = ((size_t)pMem + nCurrentUnitSize) / (nMaxMemoryPerUnit); - - if (nStartUnit > nUnitsPerLine) - { - nStartUnit = nUnitsPerLine; - } - - if (nEndUnit > nUnitsPerLine) - { - nEndUnit = nUnitsPerLine; - } - - for (size_t i = nStartUnit; i < nEndUnit; ++i) - { - vCoverage[i] = 1; - } - } - - ++nLocalUnits; - - // insert in linked list - *pMem = pMemoryBlocks; - pMemoryBlocks = pMem; - } - - nUnits += nLocalUnits; - nAvailableMem += nLocalUnits * nCurrentUnitSize; - - nCurrentUnitSize /= 2; - nUnits *= 2; - } - - // free all memory blocks allocated - while (pMemoryBlocks) - { - void* pNext = *pMemoryBlocks; - - ::free(pMemoryBlocks); - ++dwFreeCnt; - - pMemoryBlocks = (void**)pNext; - } - - - // _heapmin(); - - CryLog("CMemoryFragmentationProfiler Y=%d, available memory=%d MB, used memory=%d MB", - m_dwLine, (nAvailableMem + 1024 * 1024 - 1) / (1024 * 1024), (nUsedMem + 1024 * 1024 - 1) / (1024 * 1024)); - - LogCoverage(vCoverage); - - DumpToRAWCoverage(vCoverage); - } - -private: // ------------------------------------------------------------------ - - void Init() - { - FILE* out = nullptr; - azfopen(&out, "MemoryCoverage.bmp", "wb"); - - if (out) - { - BITMAPFILEHEADER pHeader; - BITMAPINFOHEADER pInfoHeader; - - memset(&pHeader, 0, sizeof(BITMAPFILEHEADER)); - memset(&pInfoHeader, 0, sizeof(BITMAPINFOHEADER)); - - pHeader.bfType = 0x4D42; - pHeader.bfSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + m_nPixelsPerLine * m_nLineCount * 3; - pHeader.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER); - - pInfoHeader.biSize = sizeof(BITMAPINFOHEADER); - pInfoHeader.biWidth = m_nPixelsPerLine; - pInfoHeader.biHeight = m_nLineCount; - pInfoHeader.biPlanes = 1; - pInfoHeader.biBitCount = 24; - pInfoHeader.biCompression = 0; - pInfoHeader.biSizeImage = m_nPixelsPerLine * m_nLineCount; - - fwrite(&pHeader, 1, sizeof(BITMAPFILEHEADER), out); - fwrite(&pInfoHeader, 1, sizeof(BITMAPINFOHEADER), out); - - for (int y = 0; y < m_nLineCount; y++) // amount of lines - { - for (int x = 0; x < m_nPixelsPerLine; x++) - { - size_t nAddress = x * (0x100000000 / m_nPixelsPerLine); - - if (nAddress == 0x30000000 - || nAddress == 0x30500000 - || nAddress == 0x31000000 - || nAddress == 0x31500000 - || nAddress == 0x32000000 - || nAddress == 0x32500000 - || nAddress == 0x33500000 - || nAddress == 0x34000000 - || nAddress == 0x35000000 - || nAddress == 0x35500000 - || nAddress == 0x36000000 - || nAddress == 0x36500000 - || nAddress == 0x38000000 - || nAddress == 0x39000000) - { - putc((unsigned char)100, out); // blue DLL start - } - else - { - putc((unsigned char)0, out); // black - } - putc((unsigned char)0, out); - putc((unsigned char)0, out); - } - } - - fclose(out); - m_dwLine = 0; - } - } - - void LogCoverage(std::vector& vCov) - { - const size_t nCharPerLine = 128; // readable amount - - char szResult[nCharPerLine + 1], * pCursor = szResult; - - szResult[nCharPerLine] = 0; // zero termination - - size_t nSize = vCov.size(); - size_t nUnitsPerChar = nSize / nCharPerLine; - - for (size_t i = 0; i < nSize; ) - { - unsigned int nLocalCov = 0; - - for (size_t e = 0; e < nUnitsPerChar; ++e, ++i) - { - if (vCov[i]) - { - ++nLocalCov; - } - } - - if (nLocalCov == 0) - { - *pCursor++ = '#'; // occupied - } - else if (nLocalCov == nUnitsPerChar) - { - *pCursor++ = '.'; // free - } - else - { - *pCursor++ = '+'; // partly - } - } - - CryLog(" Coverage=%s", szResult); - } - - - void DumpToRAWCoverage(std::vector& vCov) - { - FILE* out = nullptr; - azfopen(&out, "MemoryCoverage.bmp", "rb+"); - - if (!out) - { - return; - } - - if (fseek(out, sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + 3 * (m_nLineCount - 1 - m_dwLine) * m_nPixelsPerLine, SEEK_SET) != 0) - { - fclose(out); - return; - } - - size_t nSize = vCov.size(); - size_t nUnitsPerChar = nSize / m_nPixelsPerLine; - - for (size_t i = 0; i < nSize; ) - { - unsigned int nLocalCov = 0; - - for (size_t e = 0; e < nUnitsPerChar; ++e, ++i) - { - if (vCov[i]) - { - ++nLocalCov; - } - } - - size_t Val = 256 - (256 * nLocalCov) / nUnitsPerChar; - - if (Val > 0) - { - Val = 127 + Val / 2; - } - - putc((unsigned char)Val, out); - putc((unsigned char)Val, out); - putc((unsigned char)Val, out); // grey - } - - fclose(out); - - ++m_dwLine; - } - - - - unsigned int m_dwLine; // [0..m_nLineCount-1], m_nLineCount means bitmap is full, 0xffffffff means not initialized yet - static const size_t m_nPixelsPerLine = 1024; // bitmap width - static const size_t m_nLineCount = 128; // -}; - - -#else // defined(WIN32) || defined(WIN64) - - -class CMemoryFragmentationProfiler -{ -public: - void DumpMemoryCoverage() {} -}; - -#endif // defined(WIN32) || defined(WIN64) - - - -#endif // CRYINCLUDE_CRYSYSTEM_MEMORYFRAGMENTATIONPROFILER_H - - diff --git a/Code/CryEngine/CrySystem/MemoryManager.cpp b/Code/CryEngine/CrySystem/MemoryManager.cpp index 4704d2f5fe..3021d68539 100644 --- a/Code/CryEngine/CrySystem/MemoryManager.cpp +++ b/Code/CryEngine/CrySystem/MemoryManager.cpp @@ -17,7 +17,6 @@ #include "CustomMemoryHeap.h" #include "GeneralMemoryHeap.h" #include "PageMappingHeap.h" -#include "DefragAllocator.h" #if defined(AZ_RESTRICTED_PLATFORM) @@ -217,11 +216,6 @@ IPageMappingHeap* CCryMemoryManager::CreatePageMappingHeap(size_t addressSpace, return new CPageMappingHeap(addressSpace, sName); } -IDefragAllocator* CCryMemoryManager::CreateDefragAllocator() -{ - return new CDefragAllocator(); -} - extern "C" { CRYMEMORYMANAGER_API void CryGetIMemoryManagerInterface(void** pIMemoryManager) diff --git a/Code/CryEngine/CrySystem/MemoryManager.h b/Code/CryEngine/CrySystem/MemoryManager.h index e9d748e481..e29d5404d8 100644 --- a/Code/CryEngine/CrySystem/MemoryManager.h +++ b/Code/CryEngine/CrySystem/MemoryManager.h @@ -44,8 +44,6 @@ public: virtual IMemoryAddressRange* ReserveAddressRange(size_t capacity, const char* sName); virtual IPageMappingHeap* CreatePageMappingHeap(size_t addressSpace, const char* sName); - - virtual IDefragAllocator* CreateDefragAllocator(); }; #else typedef IMemoryManager CCryMemoryManager; diff --git a/Code/CryEngine/CrySystem/MiniGUI/DrawContext.cpp b/Code/CryEngine/CrySystem/MiniGUI/DrawContext.cpp deleted file mode 100644 index a45fde272b..0000000000 --- a/Code/CryEngine/CrySystem/MiniGUI/DrawContext.cpp +++ /dev/null @@ -1,160 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "CrySystem_precompiled.h" -#include "DrawContext.h" -#include -#include -#include - -MINIGUI_BEGIN - -////////////////////////////////////////////////////////////////////////// -CDrawContext::CDrawContext(SMetrics* pMetrics) -{ - m_currentStackLevel = 0; - m_x = 0; - m_y = 0; - m_pMetrics = pMetrics; - m_color = ColorB(0, 0, 0, 0); - m_defaultZ = 0.0f; - m_pAuxRender = gEnv->pRenderer->GetIRenderAuxGeom(); - - m_frameWidth = (float)gEnv->pRenderer->GetWidth(); - m_frameHeight = (float)gEnv->pRenderer->GetHeight(); -} - -////////////////////////////////////////////////////////////////////////// -void CDrawContext::SetColor(ColorB color) -{ - m_color = color; -} - -////////////////////////////////////////////////////////////////////////// -void CDrawContext::DrawLine(float x0, float y0, float x1, float y1, float thickness /*= 1.0f */) -{ - m_pAuxRender->DrawLine(Vec3(m_x + x0, m_y + y0, m_defaultZ), m_color, Vec3(m_x + x1, m_y + y1, m_defaultZ), m_color, thickness); -} - -////////////////////////////////////////////////////////////////////////// -void CDrawContext::DrawTriangle(float x0, float y0, float x1, float y1, float x2, float y2) -{ - m_pAuxRender->DrawTriangle(Vec3(m_x + x0, m_y + y0, m_defaultZ), m_color, Vec3(m_x + x1, m_y + y1, m_defaultZ), m_color, Vec3(m_x + x2, m_y + y2, m_defaultZ), m_color); -} - -////////////////////////////////////////////////////////////////////////// -void CDrawContext::DrawRect(const Rect& rc) -{ - m_pAuxRender->DrawTriangle(Vec3(m_x + rc.left, m_y + rc.top, m_defaultZ), m_color, Vec3(m_x + rc.left, m_y + rc.bottom, m_defaultZ), m_color, Vec3(m_x + rc.right, m_y + rc.top, m_defaultZ), m_color); - m_pAuxRender->DrawTriangle(Vec3(m_x + rc.left, m_y + rc.bottom, m_defaultZ), m_color, Vec3(m_x + rc.right, m_y + rc.bottom, m_defaultZ), m_color, Vec3(m_x + rc.right, m_y + rc.top, m_defaultZ), m_color); -} - -////////////////////////////////////////////////////////////////////////// -void CDrawContext::DrawFrame(const Rect& rc, ColorB lineColor, ColorB solidColor, float thickness) -{ - ColorB prevColor = m_color; - - SetColor(solidColor); - DrawRect(rc); - - SetColor(lineColor); - - uint32 curFlags = m_pAuxRender->GetRenderFlags().m_renderFlags; - m_pAuxRender->SetRenderFlags(curFlags | e_DrawInFrontOn); - DrawLine(rc.left, rc.top, rc.right, rc.top, thickness); - DrawLine(rc.right, rc.top, rc.right, rc.bottom, thickness); - DrawLine(rc.left, rc.top, rc.left, rc.bottom, thickness); - DrawLine(rc.left, rc.bottom, rc.right, rc.bottom, thickness); - m_pAuxRender->SetRenderFlags(curFlags); - - m_color = prevColor; -} - -////////////////////////////////////////////////////////////////////////// -void CDrawContext::StartDrawing() -{ - uint32 width = gEnv->pRenderer->GetWidth(); - uint32 height = gEnv->pRenderer->GetHeight(); - - gEnv->pRenderer->Set2DMode(width, height, m_backupSceneMatrices); - - m_prevRenderFlags = m_pAuxRender->GetRenderFlags().m_renderFlags; - m_pAuxRender->SetRenderFlags(e_Mode3D | e_AlphaBlended | e_FillModeSolid | e_CullModeBack | e_DepthWriteOff | e_DepthTestOff); -} - -////////////////////////////////////////////////////////////////////////// -void CDrawContext::StopDrawing() -{ - // Restore old flags that where set before our draw context. - m_pAuxRender->SetRenderFlags(m_prevRenderFlags); - - gEnv->pRenderer->Unset2DMode(m_backupSceneMatrices); -} - -////////////////////////////////////////////////////////////////////////// -void CDrawContext::DrawString(float x, float y, float font_size, ETextAlign align, const char* format, ...) -{ - //text will be off screen - if (y > m_frameHeight || x > m_frameWidth) - { - return; - } - - va_list args; - va_start(args, format); - SDrawTextInfo ti; - ti.xscale = ti.yscale = font_size / 12.0f; // font size in pixels to text scale. - - ti.flags = eDrawText_Monospace | eDrawText_2D | eDrawText_FixedSize | eDrawText_IgnoreOverscan; - if (align == eTextAlign_Left) - { - } - else if (align == eTextAlign_Right) - { - ti.flags |= eDrawText_Right; - } - else if (align == eTextAlign_Center) - { - ti.flags |= eDrawText_Center; - } - ti.color[0] = (float)m_color.r / 255.0f; - ti.color[1] = (float)m_color.g / 255.0f; - ti.color[2] = (float)m_color.b / 255.0f; - ti.color[3] = (float)m_color.a / 255.0f; - gEnv->pRenderer->DrawTextQueued(Vec3(m_x + x, m_y + y, m_defaultZ), ti, format, args); - va_end(args); -} - -////////////////////////////////////////////////////////////////////////// -void CDrawContext::PushClientRect(const Rect& rc) -{ - m_currentStackLevel++; - assert(m_currentStackLevel < MAX_ORIGIN_STACK); - m_clientRectStack[m_currentStackLevel] = rc; - m_x += rc.left; - m_y += rc.top; -} - -////////////////////////////////////////////////////////////////////////// -void CDrawContext::PopClientRect() -{ - if (m_currentStackLevel > 0) - { - Rect& rc = m_clientRectStack[m_currentStackLevel]; - m_x -= rc.left; - m_y -= rc.top; - - m_currentStackLevel--; - } -} -MINIGUI_END diff --git a/Code/CryEngine/CrySystem/MiniGUI/DrawContext.h b/Code/CryEngine/CrySystem/MiniGUI/DrawContext.h deleted file mode 100644 index 6b1b8000ae..0000000000 --- a/Code/CryEngine/CrySystem/MiniGUI/DrawContext.h +++ /dev/null @@ -1,89 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// Description : DrawContext helper class for MiniGUI - - -#ifndef CRYINCLUDE_CRYSYSTEM_MINIGUI_DRAWCONTEXT_H -#define CRYINCLUDE_CRYSYSTEM_MINIGUI_DRAWCONTEXT_H -#pragma once - - -#include "ICryMiniGUI.h" -#include - -struct IRenderAuxGeom; - -MINIGUI_BEGIN - -enum ETextAlign -{ - eTextAlign_Left, - eTextAlign_Right, - eTextAlign_Center -}; - -////////////////////////////////////////////////////////////////////////// -// Context of MiniGUI drawing. -////////////////////////////////////////////////////////////////////////// -class CDrawContext -{ -public: - CDrawContext(SMetrics* pMetrics); - - // Must be called before any drawing happens - void StartDrawing(); - // Must be called after all drawing have been complete. - void StopDrawing(); - - void PushClientRect(const Rect& rc); - void PopClientRect(); - - SMetrics& Metrics() { return *m_pMetrics; } - void SetColor(ColorB color); - - void DrawLine(float x0, float y0, float x1, float y1, float thickness = 1.0f); - void DrawTriangle(float x0, float y0, float x1, float y1, float x2, float y2); - void DrawRect(const Rect& rc); - void DrawFrame(const Rect& rc, ColorB lineColor, ColorB solidColor, float thickness = 1.0f); - - void DrawString(float x, float y, float font_size, ETextAlign align, const char* format, ...); - - -protected: - SMetrics* m_pMetrics; - - ColorB m_color; - float m_defaultZ; - IRenderAuxGeom* m_pAuxRender; - uint32 m_prevRenderFlags; - - enum - { - MAX_ORIGIN_STACK = 16 - }; - - int m_currentStackLevel; - float m_x, m_y; // Reference X,Y positions - Rect m_clientRectStack[MAX_ORIGIN_STACK]; - - float m_frameWidth; - float m_frameHeight; - -private: - TransformationMatrices m_backupSceneMatrices; -}; - -MINIGUI_END - -#endif // CRYINCLUDE_CRYSYSTEM_MINIGUI_DRAWCONTEXT_H diff --git a/Code/CryEngine/CrySystem/MiniGUI/MiniButton.cpp b/Code/CryEngine/CrySystem/MiniGUI/MiniButton.cpp deleted file mode 100644 index cbedfe1eae..0000000000 --- a/Code/CryEngine/CrySystem/MiniGUI/MiniButton.cpp +++ /dev/null @@ -1,316 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// Description : Button implementation in the MiniGUI - - -#include "CrySystem_precompiled.h" -#include "MiniButton.h" -#include "DrawContext.h" -#include -#include - -MINIGUI_BEGIN - - -CMiniButton::CMiniButton() -{ - m_pCVar = NULL; - m_fCVarValue[0] = 0; - m_fCVarValue[1] = 1; - m_saveStateOn = false; - m_clickCallback = NULL; - m_pCallbackData = NULL; - m_pConnectedCtrl = NULL; -} - -////////////////////////////////////////////////////////////////////////// -void CMiniButton::Reset() -{ - /*if (m_pCVar) - { - pCVar->Set( m_fCVarValue[0] ); - }*/ - - /*if(m_pConnectedCtrl) - { - m_pConnectedCtrl->SetVisible(false); - }*/ - - clear_flag(eCtrl_Checked); -} - -////////////////////////////////////////////////////////////////////////// -void CMiniButton::SaveState() -{ - if (is_flag(eCtrl_Checked)) - { - if (m_pConnectedCtrl && m_pConnectedCtrl->CheckFlag(eCtrl_Hidden)) - { - m_saveStateOn = false; - } - else - { - m_saveStateOn = true; - } - } - else - { - m_saveStateOn = false; - } -} - -////////////////////////////////////////////////////////////////////////// -void CMiniButton::RestoreState() -{ - if (m_pCVar) - { - if (m_pCVar->GetFVal() == m_fCVarValue[1]) - { - set_flag(eCtrl_Checked); - - - //Restoring CVars has caused a few issues, especially when the user is changing - //CVars through the console while perfHud is active, removing for now - //pCVar->Set( m_saveStateOn ? m_fCVarValue[1] : m_fCVarValue[0] ); - } - else - { - clear_flag(eCtrl_Checked); - } - } - else - { - //connected controls (tables / info boxes etc) now look after themselves - /*if(m_pConnectedCtrl) - { - m_pConnectedCtrl->SetVisible(m_saveStateOn); - }*/ - - if (CheckFlag(eCtrl_CheckButton)) - { - if (m_saveStateOn) - { - set_flag(eCtrl_Checked); - } - else - { - clear_flag(eCtrl_Checked); - } - } - } -} - -////////////////////////////////////////////////////////////////////////// -void CMiniButton::OnPaint(CDrawContext& dc) -{ - ColorB bkgColor = dc.Metrics().clrBackground; - - if (is_flag(eCtrl_Highlight)) - { - bkgColor = dc.Metrics().clrBackgroundHighlight; - } - else if (is_flag(eCtrl_Checked)) - { - //if connected control has been hidden, this button should not be checked - if (m_pConnectedCtrl && m_pConnectedCtrl->CheckFlag(eCtrl_Hidden)) - { - clear_flag(eCtrl_Checked); - } - else - { - bkgColor = dc.Metrics().clrBackgroundSelected; - } - } - - float borderThickness = 1.0f; - - if (is_flag(eCtrl_Focus)) - { - borderThickness = 3.0f; - } - - ColorB borderCol = dc.Metrics().clrFrameBorder; - - if (!m_pGUI->InFocus()) - { - borderCol = dc.Metrics().clrFrameBorderOutOfFocus; - bkgColor.a = dc.Metrics().outOfFocusAlpha; - } - - dc.DrawFrame(m_rect, borderCol, bkgColor, borderThickness); - - ColorB textColor = dc.Metrics().clrText; - - if (is_flag(eCtrl_Checked | eCtrl_Highlight)) - { - textColor = dc.Metrics().clrTextSelected; - } - - dc.SetColor(textColor); - - ETextAlign align; - float startX; - - if (is_flag(eCtrl_TextAlignCentre)) - { - startX = (m_rect.left + m_rect.right) / 2.f; - align = eTextAlign_Center; - } - else - { - startX = m_rect.left + 5.f; - align = eTextAlign_Left; - } - - dc.DrawString(startX, m_rect.top, dc.Metrics().fTitleSize, align, GetTitle()); - - //Check not very obvious -#if 0 - if (is_flag(eCtrl_Checked)) - { - // Draw checked mark. - float checkX = m_rect.left + 4; - float checkY = (m_rect.bottom + m_rect.top) * 0.5f; - dc.SetColor(dc.Metrics().clrChecked); - dc.DrawLine(checkX, checkY, checkX + 3, checkY + 3); - dc.DrawLine(checkX + 3, checkY + 3, checkX + 7, checkY - 6); - } -#endif -} - -////////////////////////////////////////////////////////////////////////// -void CMiniButton::SetRect(const Rect& rc) -{ - Rect newrc = rc; - newrc.bottom = newrc.top + m_pGUI->Metrics().fTitleSize + 2; - CMiniCtrl::SetRect(newrc); -} - -////////////////////////////////////////////////////////////////////////// -void CMiniButton::OnEvent(float x, float y, EMiniCtrlEvent event) -{ - switch (event) - { - case eCtrlEvent_LButtonDown: - { - SCommand cmd; - - if (CheckFlag(eCtrl_CheckButton)) - { - if (!CheckFlag(eCtrl_Checked)) - { - cmd.command = eCommand_ButtonChecked; - } - else - { - cmd.command = eCommand_ButtonUnchecked; - } - } - else - { - cmd.command = eCommand_ButtonPress; - } - - cmd.nCtrlID = GetId(); - cmd.pCtrl = this; - GetGUI()->OnCommand(cmd); - - if (CheckFlag(eCtrl_CheckButton)) - { - bool bOn = false; - - if (CheckFlag(eCtrl_Checked)) - { - bOn = false; - ClearFlag(eCtrl_Checked); - } - else - { - bOn = true; - SetFlag(eCtrl_Checked); - } - - if (m_pCVar) - { - m_pCVar->Set(m_fCVarValue[bOn ? 1 : 0]); - } - - if (m_pConnectedCtrl) - { - m_pConnectedCtrl->SetVisible(bOn); - } - } - else - { - //cross button behavior - if (m_pConnectedCtrl) - { - m_pConnectedCtrl->SetVisible(false); - } - } - - if (m_clickCallback) - { - m_clickCallback(m_pCallbackData, true); - } - } - break; - case eCtrlEvent_MouseOff: - { - if (m_pParent) - { - m_pParent->OnEvent(x, y, eCtrlEvent_MouseOff); - } - } - break; - } -} - -////////////////////////////////////////////////////////////////////////// -bool CMiniButton::SetControlCVar(const char* sCVarName, float fOffValue, float fOnValue) -{ - m_pCVar = GetISystem()->GetIConsole()->GetCVar(sCVarName); - - if (!m_pCVar) - { - CryLogAlways("failed to find CVar: %s\n", sCVarName); - } - - m_fCVarValue[0] = fOffValue; - m_fCVarValue[1] = fOnValue; - - if (m_pCVar && m_pCVar->GetFVal() == fOnValue) - { - set_flag(eCtrl_Checked); - } - - return true; -} - -////////////////////////////////////////////////////////////////////////// -bool CMiniButton::SetClickCallback(ClickCallback callback, void* pCallbackData) -{ - m_clickCallback = callback; - m_pCallbackData = pCallbackData; - return true; -} - -////////////////////////////////////////////////////////////////////////// -bool CMiniButton::SetConnectedCtrl(IMiniCtrl* pConnectedCtrl) -{ - m_pConnectedCtrl = pConnectedCtrl; - return true; -} - -MINIGUI_END diff --git a/Code/CryEngine/CrySystem/MiniGUI/MiniButton.h b/Code/CryEngine/CrySystem/MiniGUI/MiniButton.h deleted file mode 100644 index 3e45f6b4e4..0000000000 --- a/Code/CryEngine/CrySystem/MiniGUI/MiniButton.h +++ /dev/null @@ -1,60 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// Description : Button implementation in the MiniGUI - - -#ifndef CRYINCLUDE_CRYSYSTEM_MINIGUI_MINIBUTTON_H -#define CRYINCLUDE_CRYSYSTEM_MINIGUI_MINIBUTTON_H -#pragma once - - -#include "MiniGUI.h" - -MINIGUI_BEGIN - -////////////////////////////////////////////////////////////////////////// -// Root window all other controls derive from -class CMiniButton - : public CMiniCtrl -{ -public: - CMiniButton(); - - ////////////////////////////////////////////////////////////////////////// - // CMiniCtrl interface implementation. - ////////////////////////////////////////////////////////////////////////// - virtual EMiniCtrlType GetType() const { return eCtrlType_Button; } - virtual void SetRect(const Rect& rc); - virtual void OnPaint(CDrawContext& dc); - virtual void OnEvent(float x, float y, EMiniCtrlEvent event); - virtual void Reset(); - virtual void SaveState(); - virtual void RestoreState(); - ////////////////////////////////////////////////////////////////////////// - - virtual bool SetControlCVar(const char* sCVarName, float fOffValue, float fOnValue); - virtual bool SetClickCallback(ClickCallback callback, void* pCallbackData); - virtual bool SetConnectedCtrl(IMiniCtrl* pConnectedCtrl); - -protected: - ICVar* m_pCVar; - float m_fCVarValue[2]; - ClickCallback m_clickCallback; - void* m_pCallbackData; - IMiniCtrl* m_pConnectedCtrl; -}; - -MINIGUI_END - -#endif // CRYINCLUDE_CRYSYSTEM_MINIGUI_MINIBUTTON_H diff --git a/Code/CryEngine/CrySystem/MiniGUI/MiniGUI.cpp b/Code/CryEngine/CrySystem/MiniGUI/MiniGUI.cpp deleted file mode 100644 index 9b074ce537..0000000000 --- a/Code/CryEngine/CrySystem/MiniGUI/MiniGUI.cpp +++ /dev/null @@ -1,862 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// Description : Implementation of the MiniGUI class - - -#include "CrySystem_precompiled.h" -#include "MiniGUI.h" -#include "DrawContext.h" - -#include "MiniButton.h" -#include "MiniMenu.h" -#include "MiniInfoBox.h" -#include "MiniTable.h" - -#include -#include - -#include -#include -#include - -namespace minigui -{ - CRYREGISTER_SINGLETON_CLASS(CMiniGUI) -} - - -MINIGUI_BEGIN - -////////////////////////////////////////////////////////////////////////// -void CMiniGUI::InitMetrics() -{ - m_metrics.clrText = ColorB(255, 255, 255, 255); - m_metrics.clrTextSelected = ColorB(0, 255, 0, 255); - m_metrics.fTextSize = 12.0f; - - m_metrics.clrTitle = ColorB(255, 255, 255, 255); - - m_metrics.fTitleSize = 14.0f; - - const int backgroundAlpha = 255; - - m_metrics.clrBackground = ColorB(20, 20, 20, backgroundAlpha); - m_metrics.clrBackgroundHighlight = ColorB(10, 10, 150, backgroundAlpha); - m_metrics.clrBackgroundSelected = ColorB(10, 120, 10, backgroundAlpha); - - m_metrics.clrFrameBorder = ColorB(255, 0, 0, 255); - m_metrics.clrFrameBorderHighlight = ColorB(255, 255, 0, 255); - m_metrics.clrFrameBorderOutOfFocus = ColorB(0, 0, 0, 255); - - m_metrics.clrChecked = ColorB(0, 0, 0, 255); - m_metrics.outOfFocusAlpha = 32; -} - -class CMiniCtrlRoot - : public CMiniCtrl -{ -public: - CMiniCtrlRoot() {}; - virtual EMiniCtrlType GetType() const { return eCtrlType_Unknown; }; - virtual void OnPaint([[maybe_unused]] class CDrawContext& dc) {}; -}; - -////////////////////////////////////////////////////////////////////////// -CMiniGUI::CMiniGUI() - : m_enabled(false) - , m_inFocus(true) - , m_pDPadMenu(NULL) - , m_pMovingCtrl(NULL) -{ -} - -////////////////////////////////////////////////////////////////////////// -CMiniGUI::~CMiniGUI() -{ -} - -////////////////////////////////////////////////////////////////////////// -void CMiniGUI::Init() -{ - m_pEventListener = NULL; - InitMetrics(); - - AzFramework::InputChannelEventListener::Connect(); - - m_pRootCtrl = new CMiniCtrlRoot; -} - -////////////////////////////////////////////////////////////////////////// -void CMiniGUI::Reset() -{ - m_pRootCtrl->Reset(); -} - -////////////////////////////////////////////////////////////////////////// -void CMiniGUI::SaveState() -{ - m_pRootCtrl->SaveState(); -} - -////////////////////////////////////////////////////////////////////////// -void CMiniGUI::RestoreState() -{ - m_pRootCtrl->RestoreState(); -} - -////////////////////////////////////////////////////////////////////////// -void CMiniGUI::SetEnabled(bool status) -{ - m_enabled = status; -} - -////////////////////////////////////////////////////////////////////////// -void CMiniGUI::SetInFocus(bool status) -{ - if (status) - { - m_inFocus = true; - } - else - { - CloseDPadMenu(); - m_inFocus = false; - } -} - -////////////////////////////////////////////////////////////////////////// -void CMiniGUI::Done() -{ - AzFramework::InputChannelEventListener::Disconnect(); -} - - -////////////////////////////////////////////////////////////////////////// -void CMiniGUI::Draw() -{ - FUNCTION_PROFILER_FAST(GetISystem(), PROFILE_SYSTEM, g_bProfilerEnabled); - - // When console opened hide MiniGui - bool bConsoleOpened = gEnv->pConsole->IsOpened(); - if (m_enabled && !bConsoleOpened) - { - ProcessInput(); - - CDrawContext dc(&m_metrics); - dc.StartDrawing(); - { - // Draw all controls. - m_pRootCtrl->DrawCtrl(dc); - } - dc.StopDrawing(); - } -} - -////////////////////////////////////////////////////////////////////////// -void CMiniGUI::ProcessInput() -{ - //check we are not in digital selection mode - if (!m_pDPadMenu) - { - float mx(0), my(0); - AZ::Vector2 systemCursorPositionNormalized = AZ::Vector2::CreateZero(); - AzFramework::InputSystemCursorRequestBus::EventResult(systemCursorPositionNormalized, - AzFramework::InputDeviceMouse::Id, - &AzFramework::InputSystemCursorRequests::GetSystemCursorPositionNormalized); - mx = systemCursorPositionNormalized.GetX() * gEnv->pRenderer->GetWidth(); - my = systemCursorPositionNormalized.GetY() * gEnv->pRenderer->GetHeight(); - - //update moving control - if (m_pMovingCtrl) - { - m_pMovingCtrl->Move(mx, my); - } - - IMiniCtrl* pCtrl = GetCtrlFromPoint(mx, my); - if (pCtrl) - { - SetHighlight(pCtrl, true, mx, my); - } - else - { - SetHighlight(m_highlightedCtrl, false, mx, my); - } - } -} - -////////////////////////////////////////////////////////////////////////// -IMiniCtrl* CMiniGUI::GetCtrlFromPoint(float x, float y) const -{ - // Draw all controls. - return m_pRootCtrl->GetCtrlFromPoint(x, y); -} - -////////////////////////////////////////////////////////////////////////// -void CMiniGUI::SetHighlight(IMiniCtrl* pCtrl, bool bEnable, float x, float y) -{ - if (pCtrl) - { - if (m_highlightedCtrl && m_highlightedCtrl != pCtrl) - { - m_highlightedCtrl->OnEvent(x, y, eCtrlEvent_MouseOff); - m_highlightedCtrl->ClearFlag(eCtrl_Highlight); - } - - if (bEnable) - { - pCtrl->OnEvent(x, y, eCtrlEvent_MouseOver); - pCtrl->SetFlag(eCtrl_Highlight); - - m_highlightedCtrl = pCtrl; - } - else - { - pCtrl->OnEvent(x, y, eCtrlEvent_MouseOff); - pCtrl->ClearFlag(eCtrl_Highlight); - m_highlightedCtrl = NULL; - } - } - else - { - assert(bEnable == false); - - if (m_highlightedCtrl) - { - m_highlightedCtrl->OnEvent(x, y, eCtrlEvent_MouseOff); - m_highlightedCtrl->ClearFlag(eCtrl_Highlight); - m_highlightedCtrl = NULL; - } - } -} - -////////////////////////////////////////////////////////////////////////// -void CMiniGUI::SetFocus(IMiniCtrl* pCtrl, bool bEnable) -{ - if (m_focusCtrl) - { - m_focusCtrl->ClearFlag(eCtrl_Focus); - } - m_focusCtrl = pCtrl; - if (m_focusCtrl) - { - if (bEnable) - { - m_focusCtrl->SetFlag(eCtrl_Focus); - } - else - { - m_focusCtrl->ClearFlag(eCtrl_Focus); - } - } -} - -////////////////////////////////////////////////////////////////////////// -SMetrics& CMiniGUI::Metrics() -{ - return m_metrics; -} - -////////////////////////////////////////////////////////////////////////// -IMiniCtrl* CMiniGUI::CreateCtrl(IMiniCtrl* pParentCtrl, int nCtrlID, EMiniCtrlType type, int nCtrlFlags, const Rect& rc, const char* title) -{ - CMiniCtrl* pCtrl = 0; - // Test code. - switch (type) - { - case eCtrlType_Button: - pCtrl = new CMiniButton; - break; - case eCtrlType_Menu: - pCtrl = new CMiniMenu; - break; - case eCtrlType_InfoBox: - pCtrl = new CMiniInfoBox; - break; - case eCtrlType_Table: - pCtrl = new CMiniTable; - break; - default: - assert(0 && "Unknown MiniGUI control type"); - break; - } - ; - if (pCtrl) - { - pCtrl->SetGUI(this); - pCtrl->SetFlag(nCtrlFlags); - pCtrl->SetTitle(title); - pCtrl->SetRect(rc); - pCtrl->SetId(nCtrlID); - - if (pCtrl->CheckFlag(eCtrl_AutoResize)) - { - pCtrl->AutoResize(); - } - - if (pCtrl->CheckFlag(eCtrl_CloseButton)) - { - pCtrl->CreateCloseButton(); - } - - if (pParentCtrl) - { - pParentCtrl->AddSubCtrl(pCtrl); - } - else - { - m_pRootCtrl->AddSubCtrl(pCtrl); - } - - if (type == eCtrlType_Menu && pParentCtrl == NULL) - { - m_rootMenus.push_back(pCtrl); - } - } - return pCtrl; -} - -////////////////////////////////////////////////////////////////////////// -void CMiniGUI::OnCommand(SCommand& cmd) -{ - if (m_pEventListener) - { - m_pEventListener->OnCommand(cmd); - } -} - -////////////////////////////////////////////////////////////////////////// -void CMiniGUI::OnMouseInputEvent(const AzFramework::InputChannel& inputChannel) -{ - if (!m_inFocus || !m_enabled) - { - return; - } - - const AzFramework::InputChannel::PositionData2D* positionData2D = inputChannel.GetCustomData(); - if (!positionData2D) - { - return; - } - const float mx = positionData2D->m_normalizedPosition.GetX() * gEnv->pRenderer->GetWidth(); - const float my = positionData2D->m_normalizedPosition.GetY() * gEnv->pRenderer->GetHeight(); - IMiniCtrl* pCtrl = GetCtrlFromPoint(mx, my); - if (pCtrl) - { - const AzFramework::InputChannelId& channelId = inputChannel.GetInputChannelId(); - if (channelId == AzFramework::InputDeviceMouse::Button::Left) - { - if (inputChannel.IsStateBegan()) - { - pCtrl->OnEvent(mx, my, eCtrlEvent_LButtonDown); - } - else if (inputChannel.IsStateEnded()) - { - pCtrl->OnEvent(mx, my, eCtrlEvent_LButtonUp); - } - } - } -} - -void CMiniGUI::SetDPadMenu(IMiniCtrl* pMenu) -{ - m_pDPadMenu = (CMiniMenu*)pMenu; - UiCursorBus::Broadcast(&UiCursorInterface::DecrementVisibleCounter); -} - -void CMiniGUI::CloseDPadMenu() -{ - if (m_pDPadMenu) - { - CMiniMenu* closeMenu = m_pDPadMenu; - - //close menu and all parent menus - do - { - closeMenu->Close(); - closeMenu = (CMiniMenu*)closeMenu->GetParent(); - } while (closeMenu->GetType() == eCtrlType_Menu); - - m_pDPadMenu->ClearFlag(eCtrl_Highlight); - m_pDPadMenu = NULL; - UiCursorBus::Broadcast(&UiCursorInterface::IncrementVisibleCounter); - } -} - -void CMiniGUI::UpdateDPadMenu(const AzFramework::InputChannel& inputChannel) -{ - const AzFramework::InputChannelId& channelId = inputChannel.GetInputChannelId(); - const bool isPressed = inputChannel.IsStateBegan(); - - if (m_pDPadMenu) - { - if (channelId == AzFramework::InputDeviceGamepad::Button::B) - { - CloseDPadMenu(); - return; - } - - if (isPressed) - { - if (channelId == AzFramework::InputDeviceGamepad::Button::DD || - channelId == AzFramework::InputDeviceGamepad::ThumbStickDirection::LD) - { - m_pDPadMenu = m_pDPadMenu->UpdateSelection(eCtrlEvent_DPadDown); - } - else if (channelId == AzFramework::InputDeviceGamepad::Button::DU || - channelId == AzFramework::InputDeviceGamepad::ThumbStickDirection::LU) - { - m_pDPadMenu = m_pDPadMenu->UpdateSelection(eCtrlEvent_DPadUp); - } - else if (channelId == AzFramework::InputDeviceGamepad::Button::DL || - channelId == AzFramework::InputDeviceGamepad::ThumbStickDirection::LL) - { - CMiniMenu* pNewMenu = m_pDPadMenu->UpdateSelection(eCtrlEvent_DPadLeft); - - //get previous root menu - if (pNewMenu == NULL) - { - int i = 0, nRootMenus = m_rootMenus.size(); - - for (i = 0; i < nRootMenus; i++) - { - if (m_rootMenus[i] == m_pDPadMenu) - { - break; - } - } - - if (i > 0) - { - m_pDPadMenu->Close(); - m_pDPadMenu->ClearFlag(eCtrl_Highlight); - - m_pDPadMenu = (CMiniMenu*)m_rootMenus[i - 1]; - m_pDPadMenu->Open(); - m_pDPadMenu->SetFlag(eCtrl_Highlight); - } - //else selected menu remains the same - } - else - { - m_pDPadMenu = pNewMenu; - } - } - else if (channelId == AzFramework::InputDeviceGamepad::Button::DR || - channelId == AzFramework::InputDeviceGamepad::ThumbStickDirection::LR) - { - CMiniMenu* pNewMenu = m_pDPadMenu->UpdateSelection(eCtrlEvent_DPadRight); - - //get next root menu - if (pNewMenu == NULL) - { - int i = 0, nRootMenus = m_rootMenus.size(); - - for (i = 0; i < nRootMenus; i++) - { - if (m_rootMenus[i] == m_pDPadMenu) - { - break; - } - } - - if (i < nRootMenus - 1) - { - m_pDPadMenu->Close(); - m_pDPadMenu->ClearFlag(eCtrl_Highlight); - - m_pDPadMenu = (CMiniMenu*)m_rootMenus[i + 1]; - m_pDPadMenu->Open(); - m_pDPadMenu->SetFlag(eCtrl_Highlight); - } - //else selected menu remains the same - } - else - { - m_pDPadMenu = pNewMenu; - } - } - else if (channelId == AzFramework::InputDeviceGamepad::Button::A) - { - m_pDPadMenu = m_pDPadMenu->UpdateSelection(eCtrlEvent_LButtonDown); - } - } - } -} - -bool CMiniGUI::OnInputChannelEventFiltered(const AzFramework::InputChannel& inputChannel) -{ - const AzFramework::InputDeviceId& deviceId = inputChannel.GetInputDevice().GetInputDeviceId(); - if (AzFramework::InputDeviceMouse::IsMouseDevice(deviceId)) - { - OnMouseInputEvent(inputChannel); - return false; - } - - if (!m_inFocus) - { - return false; - } - - if (!AzFramework::InputDeviceGamepad::IsGamepadDevice(deviceId)) - { - return false; - } - - if (m_pDPadMenu) - { - UpdateDPadMenu(inputChannel); - } - else - { - float posX = 0.0f; - float posY = 0.0f; - const AzFramework::InputChannel::PositionData2D* positionData2D = inputChannel.GetCustomData(); - if (positionData2D) - { - posX = positionData2D->m_normalizedPosition.GetX() * gEnv->pRenderer->GetWidth(); - posY = positionData2D->m_normalizedPosition.GetY() * gEnv->pRenderer->GetHeight(); - } - - IMiniCtrl* pCtrl = GetCtrlFromPoint(posX, posY); - - if (pCtrl) - { - const AzFramework::InputChannelId& channelId = inputChannel.GetInputChannelId(); - if (channelId == AzFramework::InputDeviceGamepad::Button::A) - { - switch (inputChannel.GetState()) - { - case AzFramework::InputChannel::State::Began: - pCtrl->OnEvent(posX, posY, eCtrlEvent_LButtonDown); - break; - - case AzFramework::InputChannel::State::Ended: - pCtrl->OnEvent(posX, posY, eCtrlEvent_LButtonUp); - break; - - case AzFramework::InputChannel::State::Updated: - pCtrl->OnEvent(posX, posY, eCtrlEvent_LButtonPressed); - - //if we've clicked on a menu, enter menu selection mode, disable mouse - if (pCtrl->GetType() == eCtrlType_Menu) - { - SetDPadMenu(pCtrl); - } - - break; - } - } - } - } - - return false; -} - -////////////////////////////////////////////////////////////////////////// -void CMiniGUI::SetEventListener(IMiniGUIEventListener* pListener) -{ - m_pEventListener = pListener; -} - -////////////////////////////////////////////////////////////////////////// -void CMiniGUI::RemoveAllCtrl() -{ - m_highlightedCtrl = NULL; - - //reset all console variables to default state - Reset(); - - m_pRootCtrl->RemoveAllSubCtrl(); -} - -////////////////////////////////////////////////////////////////////////// -//CMiniCtrl -////////////////////////////////////////////////////////////////////////// - -////////////////////////////////////////////////////////////////////////// -void CMiniCtrl::Reset() -{ - for (int i = 0, num = GetSubCtrlCount(); i < num; i++) - { - IMiniCtrl* pSubCtrl = GetSubCtrl(i); - pSubCtrl->Reset(); - } -} - -////////////////////////////////////////////////////////////////////////// -void CMiniCtrl::SaveState() -{ - for (int i = 0, num = GetSubCtrlCount(); i < num; i++) - { - IMiniCtrl* pSubCtrl = GetSubCtrl(i); - pSubCtrl->SaveState(); - } -} - -////////////////////////////////////////////////////////////////////////// -void CMiniCtrl::RestoreState() -{ - for (int i = 0, num = GetSubCtrlCount(); i < num; i++) - { - IMiniCtrl* pSubCtrl = GetSubCtrl(i); - pSubCtrl->RestoreState(); - } -} - -////////////////////////////////////////////////////////////////////////// -void CMiniCtrl::AddSubCtrl(IMiniCtrl* pCtrl) -{ - assert(pCtrl); - _smart_ptr pTempCtrl(pCtrl); - IMiniCtrl* pParent = pCtrl->GetParent(); - if (pParent) - { - pParent->RemoveSubCtrl(pCtrl); - } - - static_cast(pCtrl)->m_pParent = this; - m_subCtrls.push_back(pCtrl); -} - -////////////////////////////////////////////////////////////////////////// -void CMiniCtrl::RemoveSubCtrl(IMiniCtrl* pCtrl) -{ - assert(pCtrl); - _smart_ptr pTempCtrl(pCtrl); - IMiniCtrl* pParent = pCtrl->GetParent(); - if (pParent == this) - { - static_cast(pCtrl)->m_pParent = 0; - for (int i = 0, num = (int)m_subCtrls.size(); i < num; i++) - { - if (m_subCtrls[i] == pCtrl) - { - m_subCtrls.erase(m_subCtrls.begin() + i); - break; - } - } - } -} - -////////////////////////////////////////////////////////////////////////// -void CMiniCtrl::RemoveAllSubCtrl() -{ - int nSubCtrls = m_subCtrls.size(); - - if (nSubCtrls) - { - for (int i = 0; i < nSubCtrls; i++) - { - IMiniCtrl* pSubCtrl = m_subCtrls[i].get(); - pSubCtrl->RemoveAllSubCtrl(); - } - - m_subCtrls.clear(); - } -} - -////////////////////////////////////////////////////////////////////////// -IMiniCtrl* CMiniCtrl::GetCtrlFromPoint(float x, float y) -{ - if (is_flag(eCtrl_Hidden)) - { - return 0; - } - - for (int i = 0, num = (int)m_subCtrls.size(); i < num; i++) - { - float lx = x - m_rect.left; - float ly = y - m_rect.top; - IMiniCtrl* pHit = m_subCtrls[i]->GetCtrlFromPoint(lx, ly); - if (pHit) - { - return pHit; - } - } - if (m_rect.IsPointInside(x, y)) - { - return this; - } - - return 0; -} - -////////////////////////////////////////////////////////////////////////// -void CMiniCtrl::DrawCtrl(CDrawContext& dc) -{ - OnPaint(dc); - - dc.PushClientRect(m_rect); - - for (int i = 0, num = (int)m_subCtrls.size(); i < num; i++) - { - CMiniCtrl* pCtrl = static_cast((IMiniCtrl*)m_subCtrls[i]); - if (!pCtrl->is_flag(eCtrl_Hidden)) - { - pCtrl->DrawCtrl(dc); - } - } - - dc.PopClientRect(); -} - -////////////////////////////////////////////////////////////////////////// -int CMiniCtrl::GetSubCtrlCount() const -{ - return (int)m_subCtrls.size(); -} - -////////////////////////////////////////////////////////////////////////// -IMiniCtrl* CMiniCtrl::GetSubCtrl(int nIndex) const -{ - assert(nIndex >= 0 && nIndex < (int)m_subCtrls.size()); - return m_subCtrls[nIndex]; -} - -////////////////////////////////////////////////////////////////////////// -void CMiniCtrl::SetRect(const Rect& rc) -{ - m_rect = rc; - - if (m_pCloseButton) - { - float width = rc.Width(); - - //relative position of cross box - Rect closeRect(width - 20.f, 0.f, width, 20.f); - m_pCloseButton->SetRect(closeRect); - } -} - -////////////////////////////////////////////////////////////////////////// -void CMiniCtrl::SetVisible(bool state) -{ - if (state) - { - clear_flag(eCtrl_Hidden); - } - else - { - set_flag(eCtrl_Hidden); - } - - if (m_pCloseButton) - { - m_pCloseButton->SetVisible(state); - } -} - -////////////////////////////////////////////////////////////////////////// -void CMiniCtrl::AutoResize() -{ - uint32 stringLen = m_title.length(); - - if (stringLen) - { - //just an approximation for now - should take into account font size / kerning - m_rect.right = m_rect.left + (8.5f * stringLen); - } - - m_requiresResize = false; -} - -////////////////////////////////////////////////////////////////////////// -void CMiniCtrl::StartMoving(float x, float y) -{ - if (!m_moving) - { - m_prevX = x; - m_prevY = y; - m_moving = true; - - m_pGUI->SetMovingCtrl(this); - } -} - -////////////////////////////////////////////////////////////////////////// -void CMiniCtrl::StopMoving() -{ - if (m_moving) - { - m_moving = false; - m_pGUI->SetMovingCtrl(NULL); - } -} - -////////////////////////////////////////////////////////////////////////// -void CMiniCtrl::Move(float x, float y) -{ - if (m_moving) - { - float moveX = x - m_prevX; - float moveY = y - m_prevY; - - m_rect.top += moveY; - m_rect.bottom += moveY; - - m_rect.left += moveX; - m_rect.right += moveX; - - m_prevX = x; - m_prevY = y; - } -} - -////////////////////////////////////////////////////////////////////////// -void CMiniCtrl::OnEvent(float x, float y, EMiniCtrlEvent event) -{ - switch (event) - { - case eCtrlEvent_LButtonDown: - { - if (is_flag(eCtrl_Highlight | eCtrl_Moveable)) - { - StartMoving(x, y); - } - } - break; - - case eCtrlEvent_LButtonUp: - if (m_moving) - { - StopMoving(); - } - break; - - case eCtrlEvent_MouseOver: - break; - } -} - -////////////////////////////////////////////////////////////////////////// -void CMiniCtrl::CreateCloseButton() -{ - if (m_pGUI) - { - m_pCloseButton = m_pGUI->CreateCtrl(this, 100, eCtrlType_Button, 0, Rect(0, 0, 100, 20), "X"); - - if (m_pCloseButton) - { - m_pCloseButton->SetConnectedCtrl(this); - - float width = m_rect.Width(); - - //relative position of cross box - Rect closeRect(width - 20.f, 0.f, width, 20.f); - m_pCloseButton->SetRect(closeRect); - } - } -} - -MINIGUI_END diff --git a/Code/CryEngine/CrySystem/MiniGUI/MiniGUI.h b/Code/CryEngine/CrySystem/MiniGUI/MiniGUI.h deleted file mode 100644 index a4db53070f..0000000000 --- a/Code/CryEngine/CrySystem/MiniGUI/MiniGUI.h +++ /dev/null @@ -1,219 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// Description : Interface to the Mini GUI subsystem - - -#ifndef CRYINCLUDE_CRYSYSTEM_MINIGUI_MINIGUI_H -#define CRYINCLUDE_CRYSYSTEM_MINIGUI_MINIGUI_H -#pragma once - - -#include "ICryMiniGUI.h" -#include - -#include - -#include - -MINIGUI_BEGIN - -class CMiniMenu; - -////////////////////////////////////////////////////////////////////////// -// Root window all other controls derive from -class CMiniCtrl - : public IMiniCtrl -{ -public: - - CMiniCtrl() - : m_nFlags(0) - , m_id(0) - , m_renderCallback(NULL) - , m_fTextSize(12.f) - , m_prevX(0.f) - , m_prevY(0.f) - , m_moving(false) - , m_requiresResize(false) - , m_pCloseButton(NULL) - , m_saveStateOn(false) - {}; - - ////////////////////////////////////////////////////////////////////////// - // IMiniCtrl interface implementation. - ////////////////////////////////////////////////////////////////////////// - virtual void Reset(); - virtual void SaveState(); - virtual void RestoreState(); - - virtual void SetGUI(IMiniGUI* pGUI) { m_pGUI = pGUI; }; - virtual IMiniGUI* GetGUI() const { return m_pGUI; }; - - virtual int GetId() const { return m_id; }; - virtual void SetId(int id) { m_id = id; }; - - virtual const char* GetTitle() const { return m_title; }; - virtual void SetTitle(const char* title) { m_title = title; }; - - virtual Rect GetRect() const { return m_rect; } - virtual void SetRect(const Rect& rc); - - virtual void SetFlag(uint32 flag) { set_flag(flag); } - virtual void ClearFlag(uint32 flag) { clear_flag(flag); }; - virtual bool CheckFlag(uint32 flag) const { return is_flag(flag); } - - virtual void AddSubCtrl(IMiniCtrl* pCtrl); - virtual void RemoveSubCtrl(IMiniCtrl* pCtrl); - virtual void RemoveAllSubCtrl(); - virtual int GetSubCtrlCount() const; - virtual IMiniCtrl* GetSubCtrl(int nIndex) const; - virtual IMiniCtrl* GetParent() const { return m_pParent; }; - - virtual IMiniCtrl* GetCtrlFromPoint(float x, float y); - - virtual void SetVisible(bool state); - - virtual void OnEvent(float x, float y, EMiniCtrlEvent); - - virtual bool SetRenderCallback(RenderCallback callback) { m_renderCallback = callback; return true; }; - - - // Not implemented in base control - virtual bool SetControlCVar([[maybe_unused]] const char* sCVarName, [[maybe_unused]] float fOffValue, [[maybe_unused]] float fOnValue) { assert(0); return false; }; - virtual bool SetClickCallback([[maybe_unused]] ClickCallback callback, [[maybe_unused]] void* pCallbackData) { assert(0); return false; }; - virtual bool SetConnectedCtrl([[maybe_unused]] IMiniCtrl* pConnectedCtrl) { assert(0); return false; }; - - ////////////////////////////////////////////////////////////////////////// - - ////////////////////////////////////////////////////////////////////////// - virtual void AutoResize(); - - ////////////////////////////////////////////////////////////////////////// - virtual void CreateCloseButton(); - - void DrawCtrl(CDrawContext& dc); - - virtual void Move(float x, float y); - -protected: - void set_flag(uint32 flag) { m_nFlags |= flag; } - void clear_flag(uint32 flag) { m_nFlags &= ~flag; }; - bool is_flag(uint32 flag) const { return (m_nFlags & flag) == flag; } - - //dynamic movement - void StartMoving(float x, float y); - void StopMoving(); - -protected: - int m_id; - IMiniGUI* m_pGUI; - uint32 m_nFlags; - CryFixedStringT<32> m_title; - Rect m_rect; - _smart_ptr m_pParent; - std::vector m_subCtrls; - RenderCallback m_renderCallback; - float m_fTextSize; - - //optional close 'X' button on controls, ref counted by m_subCtrls - IMiniCtrl* m_pCloseButton; - - //dynamic movement - float m_prevX; - float m_prevY; - bool m_moving; - bool m_requiresResize; - bool m_saveStateOn; -}; - -////////////////////////////////////////////////////////////////////////// -class CMiniGUI - : public IMiniGUI - , public AzFramework::InputChannelEventListener -{ -public: - CRYINTERFACE_BEGIN() - CRYINTERFACE_ADD(IMiniGUI) - CRYINTERFACE_END() - CRYGENERATE_SINGLETONCLASS(CMiniGUI, "MiniGUI", 0x1a049b879a4e4b58, 0xac14026e17e6255e) - -public: - void InitMetrics(); - void ProcessInput(); - - ////////////////////////////////////////////////////////////////////////// - // IMiniGUI interface implementation. - ////////////////////////////////////////////////////////////////////////// - virtual void Init(); - virtual void Done(); - virtual void Draw(); - virtual void Reset(); - virtual void SaveState(); - virtual void RestoreState(); - virtual void SetEnabled(bool status); - virtual void SetInFocus(bool status); - virtual bool InFocus() {return m_inFocus; } - - virtual void SetEventListener(IMiniGUIEventListener* pListener); - - virtual SMetrics& Metrics(); - - virtual void OnCommand(SCommand& cmd); - - virtual void RemoveAllCtrl(); - virtual IMiniCtrl* CreateCtrl(IMiniCtrl* pParentCtrl, int nCtrlID, EMiniCtrlType type, int nCtrlFlags, const Rect& rc, const char* title); - - virtual IMiniCtrl* GetCtrlFromPoint(float x, float y) const; - - void SetHighlight(IMiniCtrl* pCtrl, bool bEnable, float x, float y); - void SetFocus(IMiniCtrl* pCtrl, bool bEnable); - - // AzFramework::InputChannelEventListener - bool OnInputChannelEventFiltered(const AzFramework::InputChannel& inputChannel) override; - AZ::s32 GetPriority() const override { return AzFramework::InputChannelEventListener::GetPriorityUI(); } - - virtual void SetMovingCtrl(IMiniCtrl* pCtrl) - { - m_pMovingCtrl = pCtrl; - } - -protected: - void OnMouseInputEvent(const AzFramework::InputChannel& inputChannel); - - //DPad menu navigation - void UpdateDPadMenu(const AzFramework::InputChannel& inputChannel); - void SetDPadMenu(IMiniCtrl* pMenu); - void CloseDPadMenu(); - -protected: - bool m_enabled; - bool m_inFocus; - - SMetrics m_metrics; - - _smart_ptr m_pRootCtrl; - - _smart_ptr m_highlightedCtrl; - _smart_ptr m_focusCtrl; - - IMiniGUIEventListener* m_pEventListener; - - CMiniMenu* m_pDPadMenu; - IMiniCtrl* m_pMovingCtrl; - std::vector m_rootMenus; -}; - -MINIGUI_END - -#endif // CRYINCLUDE_CRYSYSTEM_MINIGUI_MINIGUI_H diff --git a/Code/CryEngine/CrySystem/MiniGUI/MiniInfoBox.cpp b/Code/CryEngine/CrySystem/MiniGUI/MiniInfoBox.cpp deleted file mode 100644 index 74114b9156..0000000000 --- a/Code/CryEngine/CrySystem/MiniGUI/MiniInfoBox.cpp +++ /dev/null @@ -1,174 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// Description : Button implementation in the MiniGUI - - -#include "CrySystem_precompiled.h" -#include "MiniInfoBox.h" -#include "DrawContext.h" -#include - -MINIGUI_BEGIN - - -CMiniInfoBox::CMiniInfoBox() - : m_fTextIndent(4) -{ -} - -////////////////////////////////////////////////////////////////////////// -void CMiniInfoBox::SaveState() -{ - if (CheckFlag(eCtrl_Hidden)) - { - m_saveStateOn = false; - } - else - { - m_saveStateOn = true; - } -} - -////////////////////////////////////////////////////////////////////////// -void CMiniInfoBox::Reset() -{ - SetFlag(eCtrl_Hidden); -} - -////////////////////////////////////////////////////////////////////////// -void CMiniInfoBox::RestoreState() -{ - if (m_saveStateOn) - { - ClearFlag(eCtrl_Hidden); - } -} - -////////////////////////////////////////////////////////////////////////// -void CMiniInfoBox::OnPaint(CDrawContext& dc) -{ - if (m_requiresResize) - { - AutoResize(); - } - - ColorB borderCol = dc.Metrics().clrFrameBorder; - ColorB backgroundCol = dc.Metrics().clrBackground; - - if (!m_pGUI->InFocus()) - { - borderCol = dc.Metrics().clrFrameBorderOutOfFocus; - backgroundCol.a = dc.Metrics().outOfFocusAlpha; - } - else if (m_moving) - { - borderCol = dc.Metrics().clrFrameBorderHighlight; - } - - dc.DrawFrame(m_rect, borderCol, backgroundCol); - - dc.SetColor(dc.Metrics().clrTitle); - dc.DrawString(m_rect.left + 4, m_rect.top, dc.Metrics().fTitleSize, eTextAlign_Left, GetTitle()); - - float fTextSize = m_fTextSize; - if (fTextSize == 0) - { - fTextSize = dc.Metrics().fTextSize; - } - - float x = m_fTextIndent + m_rect.left + 8; - float y = m_rect.top + fTextSize + fTextSize; - // Draw entries. - for (int i = 0, num = (int)m_entries.size(); i < num; i++) - { - SInfoEntry& info = m_entries[i]; - dc.SetColor(info.color); - dc.DrawString(x, y, info.textSize, eTextAlign_Left, info.text); - y += info.textSize * 0.8f; - if (y + info.textSize > m_rect.bottom) - { - break; - } - } - - if (m_renderCallback) - { - m_renderCallback(m_rect.left, m_rect.top); - } -} - - -////////////////////////////////////////////////////////////////////////// -void CMiniInfoBox::OnEvent(float x, float y, EMiniCtrlEvent event) -{ - CMiniCtrl::OnEvent(x, y, event); -} - -void CMiniInfoBox::AddEntry(const char* str, ColorB col, float textSize) -{ - SInfoEntry info; - - info.color = col; - info.textSize = textSize; - cry_strcpy(info.text, str); - - m_entries.push_back(info); - - if (CheckFlag(eCtrl_AutoResize)) - { - //set dirty flag instead of resizing for every elem - m_requiresResize = true; //AutoResize(); - } -} - -void CMiniInfoBox::ClearEntries() -{ - m_entries.clear(); - m_requiresResize = true; -} - -////////////////////////////////////////////////////////////////////////// -void CMiniInfoBox::AutoResize() -{ - float width = 0.f; - float height = 32.f; - - //must be at least the size of title and cross box - width = m_fTextIndent + ((float)m_title.size() * 14.f) + 30.f; - - for (int i = 0, num = (int)m_entries.size(); i < num; i++) - { - SInfoEntry& info = m_entries[i]; - - uint32 strLength = strlen(info.text); - - float strSize = info.textSize * strLength; - - width = max(strSize, width); - height += info.textSize * 0.8f; - } - - //scale width, could do with kerning info - width *= 0.6f; - - Rect newRect = m_rect; - newRect.right = newRect.left + width; - newRect.bottom = newRect.top + height; - - SetRect(newRect); - - m_requiresResize = false; -} - -MINIGUI_END diff --git a/Code/CryEngine/CrySystem/MiniGUI/MiniInfoBox.h b/Code/CryEngine/CrySystem/MiniGUI/MiniInfoBox.h deleted file mode 100644 index dbe8a668d6..0000000000 --- a/Code/CryEngine/CrySystem/MiniGUI/MiniInfoBox.h +++ /dev/null @@ -1,79 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// Description : Button implementation in the MiniGUI - -#ifndef CRYINCLUDE_CRYSYSTEM_MINIGUI_MINIINFOBOX_H -#define CRYINCLUDE_CRYSYSTEM_MINIGUI_MINIINFOBOX_H -#pragma once - - -#include "MiniGUI.h" - -MINIGUI_BEGIN - -////////////////////////////////////////////////////////////////////////// -// Root window all other controls derive from -class CMiniInfoBox - : public CMiniCtrl - , public IMiniInfoBox -{ -public: - CMiniInfoBox(); - - ////////////////////////////////////////////////////////////////////////// - // CMiniCtrl interface implementation. - ////////////////////////////////////////////////////////////////////////// - virtual EMiniCtrlType GetType() const { return eCtrlType_InfoBox; } - virtual void OnPaint(CDrawContext& dc); - virtual void OnEvent(float x, float y, EMiniCtrlEvent event); - virtual void Reset(); - virtual void SaveState(); - virtual void RestoreState(); - virtual void AutoResize(); - ////////////////////////////////////////////////////////////////////////// - - virtual void SetTextIndent(float x) { m_fTextIndent = x; } - virtual void SetTextSize(float sz) { m_fTextSize = sz; } - virtual void ClearEntries(); - virtual void AddEntry(const char* str, ColorB col, float textSize); - - ////////////////////////////////////////////////////////////////////////// - // IMiniTable interface implementation. - ////////////////////////////////////////////////////////////////////////// - virtual bool IsHidden() { return CheckFlag(eCtrl_Hidden); } - virtual void Hide(bool stat) { SetVisible(!stat); } - -public: - - ////////////////////////////////////////////////////////////////////////// - - static const int MAX_TEXT_LENGTH = 64; - - struct SInfoEntry - { - char text[MAX_TEXT_LENGTH]; - ColorB color; - float textSize; - }; - ////////////////////////////////////////////////////////////////////////// - -protected: - - std::vector m_entries; - float m_fTextIndent; -}; - -MINIGUI_END - -#endif // CRYINCLUDE_CRYSYSTEM_MINIGUI_MINIINFOBOX_H diff --git a/Code/CryEngine/CrySystem/MiniGUI/MiniMenu.cpp b/Code/CryEngine/CrySystem/MiniGUI/MiniMenu.cpp deleted file mode 100644 index f905f0f998..0000000000 --- a/Code/CryEngine/CrySystem/MiniGUI/MiniMenu.cpp +++ /dev/null @@ -1,364 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// Description : Button implementation in the MiniGUI - - -#include "CrySystem_precompiled.h" -#include "MiniMenu.h" -#include "DrawContext.h" - -MINIGUI_BEGIN - - -CMiniMenu::CMiniMenu() -{ - m_bVisible = false; - m_bSubMenu = false; - m_menuWidth = 0.f; - m_selectionIndex = -1; -} - -////////////////////////////////////////////////////////////////////////// -void CMiniMenu::OnPaint(CDrawContext& dc) -{ - CMiniButton::OnPaint(dc); - - if (m_bSubMenu) - { - // Draw checked mark. - float x1 = m_rect.right - 12; - float y1 = m_rect.top + 3; - - float x2 = m_rect.right - 3; - float y2 = (m_rect.bottom + m_rect.top) / 2; - - float x3 = m_rect.right - 12; - float y3 = m_rect.bottom - 3; - - dc.SetColor(ColorB(0, 0, 0, 255)); - - dc.DrawLine(x1, y1, x2, y2, 2.f); - dc.DrawLine(x2, y2, x3, y3, 2.f); - - x1 -= 1; - x2 -= 1; - x3 -= 1; - y1 -= 1; - y2 -= 1; - y3 -= 1; - - dc.SetColor(ColorB(255, 255, 255, 255)); - - dc.DrawLine(x1, y1, x2, y2, 2.f); - dc.DrawLine(x2, y2, x3, y3, 2.f); - } - - - //dc.DrawFrame( m_rect,dc.Metrics().clrFrameBorder,dc.Metrics().clrBackground ); -} - -////////////////////////////////////////////////////////////////////////// -void CMiniMenu::SetRect(const Rect& rc) -{ - Rect newrc = rc; - newrc.bottom = newrc.top + m_pGUI->Metrics().fTitleSize + 2; - CMiniCtrl::SetRect(newrc); -} - -////////////////////////////////////////////////////////////////////////// -void CMiniMenu::OnEvent(float x, float y, EMiniCtrlEvent event) -{ - switch (event) - { - case eCtrlEvent_LButtonDown: - { - if (m_bVisible) - { - Close(); - } - else - { - Open(); - } - } - break; - case eCtrlEvent_MouseOff: - { - bool closeMenu = true; - IMiniCtrl* pCtrl = m_pGUI->GetCtrlFromPoint(x, y); - - //check if the cursor is still in one of the menu's children - if (pCtrl) - { - for (int i = 0, num = GetSubCtrlCount(); i < num; i++) - { - if (pCtrl == GetSubCtrl(i)) - { - closeMenu = false; - break; - } - } - } - - if (closeMenu) - { - Close(); - - if (m_pParent) - { - m_pParent->OnEvent(x, y, eCtrlEvent_MouseOff); - } - } - } - break; - } -} - -CMiniMenu* CMiniMenu::UpdateSelection(EMiniCtrlEvent event) -{ - CMiniMenu* pNewMenu = this; - IMiniCtrl* pCurrentSelection = NULL; - - if (m_selectionIndex != -1) - { - pCurrentSelection = m_subCtrls[m_selectionIndex]; - } - - switch (event) - { - case eCtrlEvent_DPadLeft: //move to parent - if (!pCurrentSelection) - { - //move to previous root menu - pNewMenu = NULL; - } - else if (m_bSubMenu) - { - Close(); - pNewMenu = (CMiniMenu*)m_pParent.get(); - //pNewMenu->SetFlag(eCtrl_Highlight); - } - break; - - case eCtrlEvent_DPadRight: //move to child - if (!pCurrentSelection) - { - //move to next root menu - pNewMenu = NULL; - } - else if (pCurrentSelection->GetType() == eCtrlType_Menu) - { - pNewMenu = (CMiniMenu*)pCurrentSelection; - pNewMenu->Open(); - pNewMenu->ClearFlag(eCtrl_Highlight); - } - break; - - case eCtrlEvent_DPadUp: //move up list - if (m_bSubMenu) - { - if (m_selectionIndex > 0) - { - m_selectionIndex--; - } - } - else - { - if (m_selectionIndex >= 0) - { - m_selectionIndex--; - - if (m_selectionIndex == -1) - { - SetFlag(eCtrl_Highlight); - } - } - } - break; - - case eCtrlEvent_DPadDown: //move down the list - if (m_selectionIndex < (int)(m_subCtrls.size() - 1)) - { - if (m_selectionIndex == -1) - { - ClearFlag(eCtrl_Highlight); - } - m_selectionIndex++; - } - break; - - case eCtrlEvent_LButtonDown: //pass on button press - { - if (pCurrentSelection) - { - if (pCurrentSelection->GetType() == eCtrlType_Menu) - { - pNewMenu = (CMiniMenu*)pCurrentSelection; - } - pCurrentSelection->OnEvent(0, 0, eCtrlEvent_LButtonDown); - } - else - { - OnEvent(0, 0, eCtrlEvent_LButtonDown); - } - } - break; - } - - if (pCurrentSelection) - { - pCurrentSelection->ClearFlag(eCtrl_Highlight); - } - - if (m_selectionIndex >= 0) - { - m_subCtrls[m_selectionIndex]->SetFlag(eCtrl_Highlight); - } - - return pNewMenu; -} - -////////////////////////////////////////////////////////////////////////// -void CMiniMenu::Open() -{ - m_bVisible = true; - - Rect rc(0, 0, m_menuWidth, 1); - - //render sub menu to the right - if (m_bSubMenu) - { - CMiniMenu* pParent = static_cast(m_pParent.get()); - rc.left = pParent->m_menuWidth; //rcParent.right; - rc.right = rc.left + m_menuWidth; - } - else - { - Rect rcThis = GetRect(); - rc.top = rcThis.Height(); - } - - for (int i = 0, num = GetSubCtrlCount(); i < num; i++) - { - IMiniCtrl* pSubCtrl = GetSubCtrl(i); - pSubCtrl->ClearFlag(eCtrl_Hidden); - float h = pSubCtrl->GetRect().Height(); - Rect rcCtrl = rc; - rcCtrl.top = rc.top; - rcCtrl.bottom = rcCtrl.top + h; - pSubCtrl->SetRect(rcCtrl); - rc.top += h; - } - - //highlight first item when opened - if (m_bSubMenu) - { - m_selectionIndex = 0; - m_subCtrls[m_selectionIndex]->SetFlag(eCtrl_Highlight); - } -} - -////////////////////////////////////////////////////////////////////////// -void CMiniMenu::Close() -{ - m_bVisible = false; - - for (int i = 0, num = GetSubCtrlCount(); i < num; i++) - { - IMiniCtrl* pSubCtrl = GetSubCtrl(i); - pSubCtrl->SetFlag(eCtrl_Hidden); - } - - if (m_selectionIndex != -1) - { - m_subCtrls[m_selectionIndex]->ClearFlag(eCtrl_Highlight); - } - m_selectionIndex = -1; -} - -////////////////////////////////////////////////////////////////////////// -void CMiniMenu::Reset() -{ - m_bVisible = false; - - for (int i = 0, num = GetSubCtrlCount(); i < num; i++) - { - IMiniCtrl* pSubCtrl = GetSubCtrl(i); - pSubCtrl->Reset(); - } -} - -////////////////////////////////////////////////////////////////////////// -void CMiniMenu::SaveState() -{ - for (int i = 0, num = GetSubCtrlCount(); i < num; i++) - { - IMiniCtrl* pSubCtrl = GetSubCtrl(i); - pSubCtrl->SaveState(); - } -} - -////////////////////////////////////////////////////////////////////////// -void CMiniMenu::RestoreState() -{ - for (int i = 0, num = GetSubCtrlCount(); i < num; i++) - { - IMiniCtrl* pSubCtrl = GetSubCtrl(i); - pSubCtrl->RestoreState(); - } -} - -////////////////////////////////////////////////////////////////////////// -void CMiniMenu::AddSubCtrl(IMiniCtrl* pCtrl) -{ - assert(pCtrl); - pCtrl->SetFlag(eCtrl_Hidden); - pCtrl->SetFlag(eCtrl_NoBorder); - - bool bSubMenu = false; - - if (pCtrl->GetType() == eCtrlType_Menu) - { - CMiniMenu* pSubMenu = static_cast(pCtrl); - pSubMenu->m_bSubMenu = true; - bSubMenu = true; - } - - if (!m_bSubMenu) - { - //menu is at least the size of title bar - m_menuWidth = max(m_menuWidth, strlen(GetTitle()) * 8.5f); - } - - const char* title = pCtrl->GetTitle(); - - if (title) - { - uint32 titleLen = strlen(title); - - float width = (float)titleLen * 8.5f; - - if (bSubMenu) - { - //increase width for submenu arrow - width += 10.f; - } - - m_menuWidth = max(m_menuWidth, width); - } - - // Call parent - CMiniButton::AddSubCtrl(pCtrl); -} -MINIGUI_END diff --git a/Code/CryEngine/CrySystem/MiniGUI/MiniMenu.h b/Code/CryEngine/CrySystem/MiniGUI/MiniMenu.h deleted file mode 100644 index c288d840df..0000000000 --- a/Code/CryEngine/CrySystem/MiniGUI/MiniMenu.h +++ /dev/null @@ -1,66 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// Description : Button implementation in the MiniGUI - - -#ifndef CRYINCLUDE_CRYSYSTEM_MINIGUI_MINIMENU_H -#define CRYINCLUDE_CRYSYSTEM_MINIGUI_MINIMENU_H -#pragma once - - -#include "MiniGUI.h" -#include "MiniButton.h" - -MINIGUI_BEGIN - -////////////////////////////////////////////////////////////////////////// -// Root window all other controls derive from -class CMiniMenu - : public CMiniButton -{ -public: - CMiniMenu(); - - ////////////////////////////////////////////////////////////////////////// - // CMiniCtrl interface implementation. - ////////////////////////////////////////////////////////////////////////// - virtual EMiniCtrlType GetType() const { return eCtrlType_Menu; } - virtual void SetRect(const Rect& rc); - virtual void OnPaint(CDrawContext& dc); - virtual void OnEvent(float x, float y, EMiniCtrlEvent event); - virtual void AddSubCtrl(IMiniCtrl* pCtrl); - virtual void Reset(); - virtual void SaveState(); - virtual void RestoreState(); - ////////////////////////////////////////////////////////////////////////// - - //digital selection funcs - CMiniMenu* UpdateSelection(EMiniCtrlEvent event); - - void Open(); - void Close(); - -protected: - -protected: - bool m_bVisible; - bool m_bSubMenu; - float m_menuWidth; - - int m_selectionIndex; -}; - -MINIGUI_END - -#endif // CRYINCLUDE_CRYSYSTEM_MINIGUI_MINIMENU_H diff --git a/Code/CryEngine/CrySystem/MiniGUI/MiniTable.cpp b/Code/CryEngine/CrySystem/MiniGUI/MiniTable.cpp deleted file mode 100644 index 6a306a2f9e..0000000000 --- a/Code/CryEngine/CrySystem/MiniGUI/MiniTable.cpp +++ /dev/null @@ -1,336 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// Description : Table implementation in the MiniGUI - - -#include "CrySystem_precompiled.h" -#include "MiniTable.h" -#include "DrawContext.h" - -#include - -MINIGUI_BEGIN - -CMiniTable::CMiniTable() -{ - m_fTextSize = 15.f; - m_pageNum = 0; - m_pageSize = 35; -} - -void CMiniTable::OnPaint(CDrawContext& dc) -{ - if (m_requiresResize) - { - AutoResize(); - } - - ColorB borderCol; - ColorB backgroundCol = dc.Metrics().clrBackground; - - if (m_pGUI->InFocus()) - { - if (m_moving) - { - borderCol = dc.Metrics().clrFrameBorderHighlight; - } - else - { - borderCol = dc.Metrics().clrFrameBorder; - } - } - else - { - borderCol = dc.Metrics().clrFrameBorderOutOfFocus; - backgroundCol.a = dc.Metrics().outOfFocusAlpha; - } - - dc.DrawFrame(m_rect, borderCol, backgroundCol); - - float fTextSize = m_fTextSize; - if (fTextSize == 0) - { - fTextSize = dc.Metrics().fTextSize; - } - - float indent = 4.f; - - float x = m_rect.left + indent; - float y = m_rect.top + indent; - - const int nColumns = m_columns.size(); - int numEntries = nColumns > 0 ? m_columns[0].cells.size() : 0; - - int startIdx = 0; - int endIdx = numEntries; - - //Page number - if (nColumns) - { - int numPages = numEntries / m_pageSize; - - if (numPages) - { - startIdx = m_pageNum * m_pageSize; - endIdx = min(startIdx + m_pageSize, numEntries); - dc.SetColor(ColorB(255, 255, 255, 255)); - - //print page details (adjust for zero indexed) - dc.DrawString(x, y, fTextSize, eTextAlign_Left, "Page %d of %d (Page Up / Page Down)", m_pageNum + 1, numPages + 1); - y += fTextSize; - } - } - - float topOfTable = y; - - for (int i = 0; i < nColumns; i++) - { - SColumn& column = m_columns[i]; - - y = topOfTable; - - dc.SetColor(ColorB(32, 32, 255, 255)); - - dc.DrawString(x, y, fTextSize, eTextAlign_Left, column.name); - y += fTextSize + indent; - - ColorB currentCol(255, 255, 255, 255); - - dc.SetColor(currentCol); - - const int nCells = column.cells.size(); - - for (int j = startIdx; j < endIdx && j < nCells; j++) - { - if (column.cells[j].col != currentCol) - { - dc.SetColor(column.cells[j].col); - currentCol = column.cells[j].col; - } - - dc.DrawString(x, y, fTextSize, eTextAlign_Left, column.cells[j].text); - y += fTextSize; - } - - x += column.width; - } -} - -void CMiniTable::OnEvent(float x, float y, EMiniCtrlEvent event) -{ - //movement - CMiniCtrl::OnEvent(x, y, event); -} - -void CMiniTable::AutoResize() -{ - //must be at least the size of cross box - float tableWidth = 30.f; - - float tableHeight = 0.f; - const float widthScale = 0.6f; - const int nColumns = m_columns.size(); - - int startIdx = 0; - int endIdx = 0; - - bool bPageHeader = false; - - //Update Page index - if (nColumns) - { - int numEntries = m_columns[0].cells.size(); - - //page index is now invalid, cap at max - if ((m_pageNum * m_pageSize) > numEntries) - { - m_pageNum = (numEntries / m_pageSize); - } - - startIdx = m_pageNum * m_pageSize; - endIdx = min(startIdx + m_pageSize, numEntries); - - if (numEntries > m_pageSize) - { - bPageHeader = true; - } - } - - for (int i = 0; i < nColumns; i++) - { - SColumn& column = m_columns[i]; - - float width = strlen(column.name) * m_fTextSize; - - int nCells = column.cells.size(); - - for (int j = startIdx; j < endIdx && j < nCells; j++) - { - width = max(width, strlen(column.cells[j].text) * m_fTextSize); - } - - width *= widthScale; - - column.width = width; - tableWidth += width; - tableHeight = max(tableHeight, min(endIdx - startIdx, m_pageSize) * m_fTextSize); - } - - tableHeight += m_fTextSize * 2.f; - - //Page index - if (bPageHeader) - { - tableHeight += m_fTextSize; - } - - Rect newRect = m_rect; - - newRect.right = newRect.left + tableWidth; - newRect.bottom = newRect.top + tableHeight; - - SetRect(newRect); - - m_requiresResize = false; -} - -void CMiniTable::Reset() -{ - SetFlag(eCtrl_Hidden); - - m_pageNum = 0; -} - -void CMiniTable::SaveState() -{ - if (CheckFlag(eCtrl_Hidden)) - { - m_saveStateOn = false; - } - else - { - m_saveStateOn = true; - } -} - -void CMiniTable::RestoreState() -{ - if (m_saveStateOn) - { - ClearFlag(eCtrl_Hidden); - } -} - -int CMiniTable::AddColumn(const char* name) -{ - assert(name); - - SColumn col; - - cry_strcpy(col.name, name); - col.width = strlen(col.name) * 8.f; - - m_columns.push_back(col); - - m_requiresResize = true; - - return m_columns.size() - 1; -} - -void CMiniTable::RemoveColumns() -{ - m_columns.clear(); -} - -int CMiniTable::AddData(int columnIndex, ColorB col, const char* format, ...) -{ - assert(columnIndex < (int)m_columns.size()); - - SCell cell; - - va_list args; - va_start(args, format); - int written = vsnprintf_s(cell.text, MAX_TEXT_LENGTH, MAX_TEXT_LENGTH - 1, format, args); - va_end(args); - - if (written == -1) - { - cell.text[MAX_TEXT_LENGTH - 1] = '\0'; - } - - cell.col = col; - - m_columns[columnIndex].cells.push_back(cell); - - m_requiresResize = true; - - return m_columns[columnIndex].cells.size() - 1; -} - -void CMiniTable::ClearTable() -{ - const int nColumns = m_columns.size(); - - for (int i = 0; i < nColumns; i++) - { - m_columns[i].cells.clear(); - } -} - -void CMiniTable::SetVisible(bool state) -{ - if (state) - { - clear_flag(eCtrl_Hidden); - AzFramework::InputChannelEventListener::Connect(); - } - else - { - set_flag(eCtrl_Hidden); - AzFramework::InputChannelEventListener::Disconnect(); - } - - if (m_pCloseButton) - { - m_pCloseButton->SetVisible(state); - } -} - -void CMiniTable::Hide(bool stat) -{ - SetVisible(!stat); -} - -bool CMiniTable::OnInputChannelEventFiltered(const AzFramework::InputChannel& inputChannel) -{ - if (!IsHidden() && inputChannel.IsStateBegan()) - { - const AzFramework::InputChannelId& channelId = inputChannel.GetInputChannelId(); - if (channelId == AzFramework::InputDeviceKeyboard::Key::NavigationPageUp) - { - m_pageNum++; - m_requiresResize = true; - } - else if (channelId == AzFramework::InputDeviceKeyboard::Key::NavigationPageDown) - { - if (m_pageNum > 0) - { - m_pageNum--; - m_requiresResize = true; - } - } - } - return false; -} -MINIGUI_END diff --git a/Code/CryEngine/CrySystem/MiniGUI/MiniTable.h b/Code/CryEngine/CrySystem/MiniGUI/MiniTable.h deleted file mode 100644 index fb89aca2dc..0000000000 --- a/Code/CryEngine/CrySystem/MiniGUI/MiniTable.h +++ /dev/null @@ -1,96 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// Description : Table implementation in the MiniGUI - - -#ifndef CRYINCLUDE_CRYSYSTEM_MINIGUI_MINITABLE_H -#define CRYINCLUDE_CRYSYSTEM_MINIGUI_MINITABLE_H -#pragma once - - -#include "MiniGUI.h" - -MINIGUI_BEGIN - -class CMiniTable - : public CMiniCtrl - , public IMiniTable - , public AzFramework::InputChannelEventListener -{ -public: - CMiniTable(); - - ////////////////////////////////////////////////////////////////////////// - // CMiniCtrl interface implementation. - ////////////////////////////////////////////////////////////////////////// - virtual EMiniCtrlType GetType() const { return eCtrlType_Table; } - virtual void OnPaint(CDrawContext& dc); - virtual void OnEvent(float x, float y, EMiniCtrlEvent event); - virtual void Reset(); - virtual void SaveState(); - virtual void RestoreState(); - virtual void AutoResize(); - virtual void SetVisible(bool state); - - ////////////////////////////////////////////////////////////////////////// - - ////////////////////////////////////////////////////////////////////////// - // IMiniTable interface implementation. - ////////////////////////////////////////////////////////////////////////// - - //Add a new column to the table, return column index - virtual int AddColumn(const char* name); - - //Remove all columns an associated data - virtual void RemoveColumns(); - - //Add data to specified column (add onto the end), return row index - virtual int AddData(int columnIndex, ColorB col, const char* format, ...); - - //Clear all data from table - virtual void ClearTable(); - - virtual bool IsHidden() { return CheckFlag(eCtrl_Hidden); } - - virtual void Hide(bool stat); - - // AzFramework::InputChannelEventListener - bool OnInputChannelEventFiltered(const AzFramework::InputChannel& inputChannel) override; - AZ::s32 GetPriority() const override { return AzFramework::InputChannelEventListener::GetPriorityUI(); } - - static const int MAX_TEXT_LENGTH = 64; - -protected: - - struct SCell - { - char text[MAX_TEXT_LENGTH]; - ColorB col; - }; - - struct SColumn - { - char name[MAX_TEXT_LENGTH]; - float width; - std::vector cells; - }; - - std::vector m_columns; - int m_pageSize; - int m_pageNum; -}; - -MINIGUI_END - -#endif // CRYINCLUDE_CRYSYSTEM_MINIGUI_MINITABLE_H diff --git a/Code/CryEngine/CrySystem/OverloadSceneManager/OverloadSceneManager.cpp b/Code/CryEngine/CrySystem/OverloadSceneManager/OverloadSceneManager.cpp deleted file mode 100644 index 044d44fade..0000000000 --- a/Code/CryEngine/CrySystem/OverloadSceneManager/OverloadSceneManager.cpp +++ /dev/null @@ -1,290 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// Description : Manages overload values (eg CPU,GPU etc) -// 1.0="everything is ok" 0.0="very bad frame rate" -// various systems can use this information and control what is currently in the scene - - -#include "CrySystem_precompiled.h" -#include "OverloadSceneManager.h" - -//-------------------------------------------------------------------------------------------------- -// Name: COverloadSceneManager -// Desc: Constructor -//-------------------------------------------------------------------------------------------------- -COverloadSceneManager::COverloadSceneManager() -{ - InitialiseCVars(); - - m_currentFrameStat = 0; - - ResetDefaultValues(); -}//------------------------------------------------------------------------------------------------- - -//-------------------------------------------------------------------------------------------------- -// Desc: static console callback functions -//-------------------------------------------------------------------------------------------------- -static void OnChange_osm_enabled(ICVar* pCVar) -{ - if (pCVar->GetIVal() == 0) - { - gEnv->pOverloadSceneManager->Reset(); - //gEnv->pRenderer->EnablePipelineProfiler(false); // would need push/pop since something else might have enabled it - } - else if (pCVar->GetIVal() == 1) - { - gEnv->pRenderer->EnablePipelineProfiler(true); - } -} - -static void cmd_setFBScale(IConsoleCmdArgs* pParams) -{ - int argCount = pParams->GetArgCount(); - - Vec2 newScale = Vec2(0.0f, 0.0f); - gEnv->pRenderer->EF_Query(EFQ_GetViewportDownscaleFactor, newScale); - - if (argCount > 1) - { - newScale.x = clamp_tpl((float)atof(pParams->GetArg(1)), 0.0f, 1.0f); - - if (argCount > 2) - { - newScale.y = clamp_tpl((float)atof(pParams->GetArg(2)), 0.0f, 1.0f); - } - else - { - newScale.y = newScale.x; - } - - newScale = gEnv->pRenderer->SetViewportDownscale(newScale.x, newScale.y); - } - - int nWidth = gEnv->pRenderer->GetWidth(); - int nHeight = gEnv->pRenderer->GetHeight(); - - gEnv->pLog->LogWithType(ILog::eInputResponse, "Current Viewport Resolution: %dx%d", - int(nWidth * newScale.x), int(nHeight * newScale.y)); -} - -//-------------------------------------------------------------------------------------------------- -// Name: InitialiseCVars -// Desc: Initialises CVars -//-------------------------------------------------------------------------------------------------- -void COverloadSceneManager::InitialiseCVars() -{ - // depending on final requirements, these could be made into const cvars - REGISTER_CVAR_CB(osm_enabled, 0, VF_NULL, "Enables/disables overload scene manager", &OnChange_osm_enabled); - REGISTER_CVAR(osm_historyLength, 5, VF_NULL, "Overload scene manager number of frames to record stats for"); - REGISTER_CVAR(osm_targetFPS, 28.0f, VF_NULL, "Overload scene manager target frame rate"); - REGISTER_CVAR(osm_targetFPSTolerance, 1.0f, VF_NULL, "The overload scene manager will make adjustments if fps is outside targetFPS +/- this value"); - REGISTER_CVAR(osm_fbScaleDeltaDown, 5.0f, VF_NULL, "The speed multiplier for the overload scene manager frame buffer scaling down"); - REGISTER_CVAR(osm_fbScaleDeltaUp, 1.0f, VF_NULL, "The speed multiplier for the overload scene manager frame buffer scaling up"); - REGISTER_CVAR(osm_fbMinScale, 0.66f, VF_NULL, "The minimum scale factor the overload scene manager will drop to"); - - REGISTER_COMMAND("osm_setFBScale", cmd_setFBScale, VF_NULL, "Sets the framebuffer scale to either a single scale on both X and Y, or independent scales.\n" - "NOTE: Will be overridden immediately if Overload scene manager is still enabled - see osm_enabled"); -}//------------------------------------------------------------------------------------------------- - -//-------------------------------------------------------------------------------------------------- -// Name: Reset -// Desc: Resets overload scene manager outputs to sensible defaults -//-------------------------------------------------------------------------------------------------- -void COverloadSceneManager::Reset() -{ - ResetDefaultValues(); - - gEnv->pRenderer->SetViewportDownscale(m_fbScale, m_fbScale); -} - -void COverloadSceneManager::ResetDefaultValues() -{ - m_fbScale = 1.0f; - m_scaleState = FBSCALE_AUTO; - m_lerpOverride.m_start = m_lerpOverride.m_length = 1.0f; - m_lerpOverride.m_reversed = false; - m_lerpAuto.m_start = m_lerpAuto.m_length = 1.0f; - m_lerpAuto.m_reversed = true; - m_fbAutoScale = m_fbOverrideDestScale = m_fbOverrideCurScale = 1.0f; - - // completely reset history - for (int i = 0; i < osm_historyLength; i++) - { - SScenePerformanceStats& stats = m_sceneStats[i]; - stats.frameRate = stats.gpuFrameRate = osm_targetFPS; - } - - m_smoothedSceneStats.frameRate = m_smoothedSceneStats.gpuFrameRate = osm_targetFPS; -} -//------------------------------------------------------------------------------------------------- - -//-------------------------------------------------------------------------------------------------- -// Name: Update -// Desc: Updates overload scene manager -//-------------------------------------------------------------------------------------------------- -void COverloadSceneManager::Update() -{ - if (!osm_enabled) - { - return; - } - - UpdateStats(); - ResizeFB(); -}//------------------------------------------------------------------------------------------------- - -//-------------------------------------------------------------------------------------------------- -// Name: OverrideScale and ResetScale -// Desc: sets up appropriate members for lerping between automatic framebuffer scale and manual -// overrides. -//-------------------------------------------------------------------------------------------------- -void COverloadSceneManager::OverrideScale(float frameScale, float dt) -{ - dt = max(dt, 1.0f / 1000.0f); - - float curTime = gEnv->pTimer->GetCurrTime(); - - frameScale = clamp_tpl(frameScale, osm_fbMinScale, 1.0f); - - m_fbOverrideDestScale = frameScale; - - if (m_scaleState == FBSCALE_AUTO) - { - // remove any override lerp - we want to lerp straight from auto to the given value. - m_lerpOverride.m_start = m_lerpOverride.m_length = 1.0f; - m_lerpOverride.m_reversed = false; - m_fbOverrideCurScale = frameScale; - - m_lerpAuto.m_start = curTime; - m_lerpAuto.m_length = dt; - m_lerpAuto.m_reversed = false; - } - else if (m_scaleState == FBSCALE_OVERRIDE) - { - m_lerpOverride.m_start = curTime; - m_lerpOverride.m_length = dt; - m_lerpOverride.m_reversed = false; - - m_fbOverrideCurScale = m_fbScale; - } - - m_scaleState = FBSCALE_OVERRIDE; -} - -void COverloadSceneManager::ResetScale(float dt) -{ - dt = max(dt, 1.0f / 1000.0f); - - float curTime = gEnv->pTimer->GetCurrTime(); - - // remove any override lerp - we want to lerp straight to auto - m_lerpOverride.m_start = m_lerpOverride.m_length = 1.0f; - m_lerpOverride.m_reversed = false; - m_fbOverrideCurScale = m_fbOverrideDestScale = m_fbScale; - - m_lerpAuto.m_start = curTime; - m_lerpAuto.m_length = dt; - m_lerpAuto.m_reversed = true; // want to lerp back to auto mode - - m_scaleState = FBSCALE_AUTO; -}//------------------------------------------------------------------------------------------------- - -//-------------------------------------------------------------------------------------------------- -// Name: UpdateStats -// Desc: Updates overload stats -//-------------------------------------------------------------------------------------------------- -void COverloadSceneManager::UpdateStats() -{ - m_currentFrameStat++; - - if (m_currentFrameStat >= osm_historyLength) - { - m_currentFrameStat = 0; - } - - SScenePerformanceStats& currentStats = m_sceneStats[m_currentFrameStat]; - const float frameLength = gEnv->pTimer->GetRealFrameTime() * 1000.0f; - const float gpuFrameLength = gEnv->pRenderer->GetGPUFrameTime() * 1000.0f; - - currentStats.frameRate = frameLength > 0.0f ? 1000.0f / frameLength : 0.0f; - currentStats.gpuFrameRate = gpuFrameLength > 0.0f ? 1000.0f / gpuFrameLength : 0.0f; - - CalculateSmoothedStats(); -}//------------------------------------------------------------------------------------------------- - -void COverloadSceneManager::CalculateSmoothedStats() -{ - m_smoothedSceneStats.Reset(); - - for (int i = 0; i < osm_historyLength; i++) - { - SScenePerformanceStats& stats = m_sceneStats[i]; - m_smoothedSceneStats.frameRate += stats.frameRate; - m_smoothedSceneStats.gpuFrameRate += stats.gpuFrameRate; - } - - m_smoothedSceneStats.frameRate /= osm_historyLength; - m_smoothedSceneStats.gpuFrameRate /= osm_historyLength; -} - -float COverloadSceneManager::CalcFBScale() -{ - float curTime = gEnv->pTimer->GetCurrTime(); - - // first calculate delta of the override lerp - float delta = clamp_tpl((curTime - m_lerpOverride.m_start) / m_lerpOverride.m_length, 0.0f, 1.0f); - if (m_lerpOverride.m_reversed) - { - delta = 1.0f - delta; - } - - // get the current target override - float curOverrideScale = LERP(m_fbOverrideCurScale, m_fbOverrideDestScale, delta); - - // calculate the delta from (or two) automatic scaling - delta = clamp_tpl((curTime - m_lerpAuto.m_start) / m_lerpAuto.m_length, 0.0f, 1.0f); - if (m_lerpAuto.m_reversed) - { - delta = 1.0f - delta; - } - - // final lerp from automatic to current override - return LERP(m_fbAutoScale, curOverrideScale, delta); -} - -void COverloadSceneManager::ResizeFB() -{ - // don't do anything for invalid framerates - if (m_smoothedSceneStats.gpuFrameRate < 5.0f || m_smoothedSceneStats.gpuFrameRate > 100.0f) - { - return; - } - - float fpsDiff = fabsf(m_smoothedSceneStats.gpuFrameRate - osm_targetFPS); - - if (m_smoothedSceneStats.gpuFrameRate < osm_targetFPS - osm_targetFPSTolerance) - { - m_fbAutoScale -= osm_fbScaleDeltaDown / 1000.0f * fpsDiff; - } - else if (m_smoothedSceneStats.gpuFrameRate > osm_targetFPS + osm_targetFPSTolerance) - { - m_fbAutoScale += osm_fbScaleDeltaUp / 1000.0f * fpsDiff; - } - - m_fbAutoScale = clamp_tpl(m_fbAutoScale, osm_fbMinScale, 1.0f); - - m_fbScale = clamp_tpl(CalcFBScale(), osm_fbMinScale, 1.0f); - - gEnv->pRenderer->SetViewportDownscale(m_fbScale, m_fbScale); -} diff --git a/Code/CryEngine/CrySystem/OverloadSceneManager/OverloadSceneManager.h b/Code/CryEngine/CrySystem/OverloadSceneManager/OverloadSceneManager.h deleted file mode 100644 index 06a901b3df..0000000000 --- a/Code/CryEngine/CrySystem/OverloadSceneManager/OverloadSceneManager.h +++ /dev/null @@ -1,127 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_CRYSYSTEM_OVERLOADSCENEMANAGER_OVERLOADSCENEMANAGER_H -#define CRYINCLUDE_CRYSYSTEM_OVERLOADSCENEMANAGER_OVERLOADSCENEMANAGER_H -#pragma once - - -// Includes -#include "IOverloadSceneManager.h" - -#define SCENE_PERFORMANCE_FRAME_HISTORY 64 - -//================================================================================================== -// Name: SOverloadSceneStats -// Desc: Overload scene stats -// Author: James Chilvers -//================================================================================================== -struct SScenePerformanceStats -{ - SScenePerformanceStats() - { - Reset(); - } - - void Reset() - { - frameRate = 0.0f; - gpuFrameRate = 0.0f; - } - - float frameRate; - float gpuFrameRate; -};//------------------------------------------------------------------------------------------------ - -//================================================================================================== -// Name: COverloadSceneManager -// Desc: Manages overload values (eg CPU,GPU etc) -// 1.0="everything is ok" 0.0="very bad frame rate" -// various systems can use this information and control what is currently in the scene -// Author: James Chilvers -//================================================================================================== -class COverloadSceneManager - : public IOverloadSceneManager -{ - friend class COverloadDG; - -public: - - COverloadSceneManager(); - ~COverloadSceneManager() override = default; - - virtual void Reset(); - - virtual void Update(); - - virtual void OverrideScale(float frameScale, float dt); - virtual void ResetScale(float dt); - -private: - - void ResetDefaultValues(); - void InitialiseCVars(); - void UpdateStats(); - void CalculateSmoothedStats(); - void ResizeFB(); - - float CalcFBScale(); // performs all lerping and returns final framebuffer scale - - // cvars - int osm_enabled; - int osm_historyLength; - float osm_targetFPS; - float osm_targetFPSTolerance; - float osm_fbScaleDeltaUp, osm_fbScaleDeltaDown; - float osm_fbMinScale; - - SScenePerformanceStats m_smoothedSceneStats; - SScenePerformanceStats m_sceneStats[SCENE_PERFORMANCE_FRAME_HISTORY]; - int m_currentFrameStat; - - // current output scale, set to the renderer - float m_fbScale; - - // Lerping behaviour is to lerp from autoscale to (lerp between cur/dest override) - // - // m_fbOverrideCurScale - // | - // | - // m_fbAutoScale ---- m_lerpAuto ---> m_lerpOverride - // | - // v - // m_fbOverrideDestScale - - // framebuffer scales to support lerping & overriding of calculated scale - float m_fbAutoScale, m_fbOverrideCurScale, m_fbOverrideDestScale; - - struct ScaleLerp - { - bool m_reversed; // Normally lerp is 0 -> 1. If reversed it's 1 -> 0 - float m_start; // time in seconds - float m_length; // time in seconds - }; - - // lerpAuto is the lerp between auto scale and whatever override is. - // lerpOverride is the lerp between m_fbOverrideCurScale and m_fbOverrideDestScale - ScaleLerp m_lerpAuto, m_lerpOverride; - - // State is the current destination of any lerps. - enum ScaleState - { - FBSCALE_AUTO, - FBSCALE_OVERRIDE, - } m_scaleState; -};//------------------------------------------------------------------------------------------------ - -#endif // CRYINCLUDE_CRYSYSTEM_OVERLOADSCENEMANAGER_OVERLOADSCENEMANAGER_H diff --git a/Code/CryEngine/CrySystem/PerfHUD.cpp b/Code/CryEngine/CrySystem/PerfHUD.cpp deleted file mode 100644 index 2aeabe2650..0000000000 --- a/Code/CryEngine/CrySystem/PerfHUD.cpp +++ /dev/null @@ -1,2166 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// Description : Button implementation in the MiniGUI - -#include "CrySystem_precompiled.h" - -#ifdef USE_PERFHUD - -#include "PerfHUD.h" -#include "MiniGUI/MiniInfoBox.h" -#include "MiniGUI/MiniMenu.h" -#include "MiniGUI/MiniTable.h" -#include -#include -#include "System.h" - -#include - -#include - -#include -#include - -#include - -#define PERFHUD_CONFIG_FILE "Config/PerfHud_PC.xml" - -using namespace minigui; - -const float CPerfHUD::OVERSCAN_X = 15; -const float CPerfHUD::OVERSCAN_Y = 15; - -const ColorB CPerfHUD::COL_NORM = ColorB(255, 255, 255, 255); -const ColorB CPerfHUD::COL_WARN = ColorB(255, 255, 0, 255); -const ColorB CPerfHUD::COL_ERROR = ColorB(255, 0, 0, 255); - -const float CPerfHUD::TEXT_SIZE_NORM = 14.f; -const float CPerfHUD::TEXT_SIZE_WARN = 18.f; -const float CPerfHUD::TEXT_SIZE_ERROR = 26.f; - -const float CPerfHUD::ACTIVATE_TIME_FROM_GAME = 1.f; -const float CPerfHUD::ACTIVATE_TIME_FROM_HUD = 0.1f; - -CRYREGISTER_SINGLETON_CLASS(CPerfHUD) -CPerfHUD::CPerfHUD() - : m_menuStartX(OVERSCAN_X) - , m_menuStartY(OVERSCAN_Y) - , m_hudCreated(false) - , m_L1Pressed(false) - , m_L2Pressed(false) - , m_R1Pressed(false) - , m_R2Pressed(false) - , m_changingState(false) - , m_hwMouseEnabled(false) - , m_triggersDownStartTime(-1.f) - , m_hudState(eHudOff) - , m_hudLastState(eHudOff) -{ - m_widgets.reserve(ICryPerfHUDWidget::eWidget_Num); -} - -CPerfHUD::~CPerfHUD() {} - -void CPerfHUD::Destroy() -{ - m_widgets.clear(); - - m_rootMenus.clear(); - - IMiniGUIPtr pGUI; - if (CryCreateClassInstanceForInterface(cryiidof(), pGUI)) - { - pGUI->RemoveAllCtrl(); - } -} - -// -// CONSOLE COMMAND CALLBACKS -// - -int CPerfHUD::m_sys_perfhud = 0; -int CPerfHUD::m_sys_perfhud_pause = 0; - -void CPerfHUD::CVarChangeCallback(ICVar* pCvar) -{ - ICryPerfHUD* pPerfHud = gEnv->pSystem->GetPerfHUD(); - - if (pPerfHud) - { - int val = pCvar->GetIVal(); - //Check for invalid value - if (val >= 0 && val < eHudNumStates) - { - pPerfHud->SetState((EHudState)val); - } - } -} - -SET_WIDGET_DEF(Warnings, eWidget_Warnings) -SET_WIDGET_DEF(RenderSummary, eWidget_RenderStats) -SET_WIDGET_DEF(RenderBatchStats, eWidget_RenderBatchStats) -SET_WIDGET_DEF(FpsBuckets, eWidget_FpsBuckets) -SET_WIDGET_DEF(Particles, eWidget_Particles) -SET_WIDGET_DEF(PakFile, eWidget_PakFile) - -////////////////////////////////////////////////////////////////////////// -void CPerfHUD::Init() -{ - m_sys_perfhud_prev = 0; - - if (gEnv->pConsole) - { - REGISTER_CVAR2_CB("sys_perfhud", &m_sys_perfhud, 0, VF_ALWAYSONCHANGE, "PerfHUD 0:off, 1:In focus, 2:Out of focus", CVarChangeCallback); - - REGISTER_CVAR2("sys_perfhud_pause", &m_sys_perfhud_pause, 0, VF_NULL, "Toggle FPS Buckets exclusive / inclusive"); - - SET_WIDGET_COMMAND("stats_Warnings", Warnings); - SET_WIDGET_COMMAND("stats_RenderSummary", RenderSummary); - SET_WIDGET_COMMAND("stats_RenderBatchStats", RenderBatchStats); - SET_WIDGET_COMMAND("stats_FpsBuckets", FpsBuckets); - SET_WIDGET_COMMAND("stats_Particles", Particles); - SET_WIDGET_COMMAND("stats_PakFile", PakFile); - } - - AzFramework::InputChannelEventListener::Connect(); - - IMiniGUIPtr pGUI; - if (CryCreateClassInstanceForInterface(cryiidof(), pGUI)) - { - InitUI(pGUI.get()); - } -} - -////////////////////////////////////////////////////////////////////////// -void CPerfHUD::LoadBudgets() -{ - XmlNodeRef budgets = gEnv->pSystem->LoadXmlFromFile(PERFHUD_CONFIG_FILE); - - if (budgets) - { - const int nWidgets = m_widgets.size(); - - for (int i = 0; i < nWidgets; i++) - { - m_widgets[i]->LoadBudgets(budgets); - } - } -} - -////////////////////////////////////////////////////////////////////////// -void CPerfHUD::SaveStats(const char* filename) -{ - XmlNodeRef rootNode = GetISystem()->CreateXmlNode("PerfHudStats"); - - if (rootNode) - { - const int nWidgets = m_widgets.size(); - - for (int i = 0; i < nWidgets; i++) - { - m_widgets[i]->SaveStats(rootNode); - } - - if (!filename) - { - filename = "PerfHudStats.xml"; - } - rootNode->saveToFile(filename); - } -} - -////////////////////////////////////////////////////////////////////////// -void CPerfHUD::ResetWidgets() -{ - TWidgetIterator itWidget; - for (itWidget = m_widgets.begin(); itWidget != m_widgets.end(); ++itWidget) - { - (*itWidget)->Reset(); - } -} - -void CPerfHUD::AddWidget(ICryPerfHUDWidget* pWidget) -{ - assert(pWidget); - static int s_widgetUID = ICryPerfHUDWidget::eWidget_Num; - - if (pWidget->m_id == -1) - { - pWidget->m_id = s_widgetUID++; - } - - m_widgets.push_back(pWidget); -} - -void CPerfHUD::RemoveWidget(ICryPerfHUDWidget* pWidget) -{ - TWidgetIterator widgetIter = m_widgets.begin(); - TWidgetIterator widgetEnd = m_widgets.end(); - - while (widgetIter != widgetEnd) - { - if (pWidget == (*widgetIter).get()) - { - m_widgets.erase(widgetIter); - break; - } - ++widgetIter; - } -} - -////////////////////////////////////////////////////////////////////////// -void CPerfHUD::Done() -{ - AzFramework::InputChannelEventListener::Disconnect(); -} - -////////////////////////////////////////////////////////////////////////// -void CPerfHUD::Draw() -{ - FUNCTION_PROFILER_FAST(GetISystem(), PROFILE_SYSTEM, g_bProfilerEnabled); - - if (m_hudState != m_hudLastState) - { - //restore gui state if the last state was off - bool bRestoreState = (m_hudLastState == eHudOff); - - Show(bRestoreState); - m_hudLastState = m_hudState; - } - - if (m_hudState != eHudOff) - { - //Pause - if (m_sys_perfhud_pause) - { - if ((gEnv->pRenderer->GetFrameID(false) % 40) < 20) - { - float col[4] = {1.f, 1.f, 0.f, 1.f}; - gEnv->pRenderer->Draw2dLabel(500.f, 220.f, 2.f, col, false, "PefHUD Paused"); - } - } - else //Update - { - const int nWidgets = m_widgets.size(); - - for (int i = 0; i < nWidgets; i++) - { - if (m_widgets[i]->ShouldUpdate()) - { - m_widgets[i]->Update(); - } - } - } - } -} - -////////////////////////////////////////////////////////////////////////// -void CPerfHUD::Show(bool bRestoreState) -{ - IMiniGUIPtr pGUI; - if (!CryCreateClassInstanceForInterface(cryiidof(), pGUI)) - { - return; - } - - switch (m_hudState) - { - case eHudInFocus: - { - pGUI->SetEventListener(this); - - if (!m_hudCreated) - { - InitUI(pGUI.get()); - } - else if (bRestoreState) - { - pGUI->RestoreState(); - } - pGUI->SetEnabled(true); - pGUI->SetInFocus(true); - - int nRootMenus = m_rootMenus.size(); - for (int i = 0; i < nRootMenus; i++) - { - m_rootMenus[i]->SetVisible(1); - } - } - break; - - case eHudOutOfFocus: - { - if (bRestoreState) - { - pGUI->RestoreState(); - } - - int nRootMenus = m_rootMenus.size(); - for (int i = 0; i < nRootMenus; i++) - { - m_rootMenus[i]->SetVisible(0); - } - - pGUI->SetEventListener(0); - pGUI->SetEnabled(true); - pGUI->SetInFocus(false); - } - break; - - case eHudOff: - { - pGUI->SaveState(); - pGUI->Reset(); - pGUI->SetEnabled(false); - } - break; - - default: - break; - } -} - -////////////////////////////////////////////////////////////////////////// -void CPerfHUD::InitUI(IMiniGUI* pGUI) -{ - assert(m_hudCreated == false); - - IMiniCtrl* pMenu; - XmlNodeRef perfXML = gEnv->pSystem->LoadXmlFromFile(PERFHUD_CONFIG_FILE); - - // - // RENDERING MENU - // - pMenu = CreateMenu("Rendering"); - - IMiniCtrl* pDebugMenu = CreateMenu("Debug", pMenu); - CreateCVarMenuItem(pDebugMenu, "Wireframe", "r_wireframe", 0, 1); - CreateCVarMenuItem(pDebugMenu, "Overdraw", "r_MeasureOverdrawScale", 0, 1); - CreateCVarMenuItem(pDebugMenu, "Freeze Camera", "e_CameraFreeze", 0, 1); - CreateCVarMenuItem(pDebugMenu, "Post Effects", "r_PostProcessEffects", 0, 1); - CreateCVarMenuItem(pDebugMenu, "Deferred decals debug", "r_deferredDecalsDebug", 0, 1); - CreateCVarMenuItem(pDebugMenu, "Shadows", "e_Shadows", 0, 1); - CreateCVarMenuItem(pDebugMenu, "Ocean", "e_WaterOcean", 0, 1); - CreateCVarMenuItem(pDebugMenu, "Characters", "ca_DrawChr", 0, 1); - CreateCVarMenuItem(pDebugMenu, "Coverage Buffer", "e_CoverageBuffer", 0, 1); - CreateCVarMenuItem(pDebugMenu, "Sun", "e_Sun", 0, 1); - CreateCVarMenuItem(pDebugMenu, "Unlit", "r_Unlit", 0, 1); - CreateCVarMenuItem(pDebugMenu, "Disable Normal Maps", "r_texbindmode", 0, 5); - CreateCVarMenuItem(pDebugMenu, "Env Probes", "r_deferredShadingEnvProbes", 0, 1); - CreateCVarMenuItem(pDebugMenu, "Lighting View", "r_texbindmode", 0, 11); - CreateCVarMenuItem(pDebugMenu, "Normal and Lighting View", "r_texbindmode", 0, 6); - CreateCVarMenuItem(pDebugMenu, "Default Material", "e_defaultMaterial", 0, 1); - - //this cvar is not created when perfHUD is initialised - so it doesn't work - //CreateCVarMenuItem(pDebugMenu, "MFX visual debug", "mfx_DebugVisual", 0, 1 ); - - - IMiniCtrl* pStatsMenu = CreateMenu("Stats", pMenu); - //Render Info - CRenderStatsWidget* pRenderStats = new CRenderStatsWidget(pStatsMenu, this); - - if (pRenderStats) - { - if (perfXML) - { - pRenderStats->LoadBudgets(perfXML); - } - m_widgets.push_back(pRenderStats); - } - - CRenderBatchWidget* pRenderBatchStats = new CRenderBatchWidget(pStatsMenu, this); - - if (pRenderBatchStats) - { - m_widgets.push_back(pRenderBatchStats); - } - -#ifndef _RELEASE - CreateCVarMenuItem(pStatsMenu, "Debug Gun", "e_debugDraw", 0, 16); -#endif - CreateCVarMenuItem(pStatsMenu, "Poly / Lod info", "e_debugDraw", 0, 1); - CreateCVarMenuItem(pStatsMenu, "Texture Memory Usage", "e_debugDraw", 0, 4); - CreateCVarMenuItem(pStatsMenu, "Detailed Render Stats", "r_Stats", 0, 1); - CreateCVarMenuItem(pStatsMenu, "Shader Stats", "r_ProfileShaders", 0, 1); - - // - // SYSTEM MENU - // - pMenu = CreateMenu("System"); - - //FPS Buckets - CWarningsWidget* pWarningsWidget = new CWarningsWidget(pMenu, this); - - if (pWarningsWidget) - { - m_widgets.push_back(pWarningsWidget); - } - - CreateCVarMenuItem(pMenu, "Profiler", "profile", 0, 1); - CreateCVarMenuItem(pMenu, "Thread Summary", "r_showmt", 0, 1); - CreateCVarMenuItem(pMenu, "Track File Access", "sys_PakLogInvalidFileAccess", 0, 1); - - //FPS Buckets - CFpsWidget* pFpsBuckets = new CFpsWidget(pMenu, this); - - if (pFpsBuckets) - { - if (perfXML) - { - pFpsBuckets->LoadBudgets(perfXML); - } - m_widgets.push_back(pFpsBuckets); - } - - // - // STREAMING MENU - // - pMenu = CreateMenu("Streaming"); - CreateCVarMenuItem(pMenu, "Streaming Debug", "sys_streaming_debug", 0, 1); - CreateCVarMenuItem(pMenu, "Loaded Geometry Info", "e_streamcgfdebug", 0, 3); - CreateCVarMenuItem(pMenu, "Texture Load/Unload Debug", "r_TexBindMode", 0, 9); - CreateCVarMenuItem(pMenu, "Textures by Size", "r_TexturesStreamingDebug", 0, 4); - CreateCVarMenuItem(pMenu, "Textures by Prio", "r_TexturesStreamingDebug", 0, 5); - - // - // SETUP MENU - // - pMenu = CreateMenu("Setup"); - CreateCallbackMenuItem(pMenu, "Reset HUD", CPerfHUD::ResetCallback, NULL); - CreateCallbackMenuItem(pMenu, "Reload Budgets", CPerfHUD::ReloadBudgetsCallback, NULL); - CreateCallbackMenuItem(pMenu, "Save Stats", CPerfHUD::SaveStatsCallback, NULL); - CreateCVarMenuItem(pMenu, "Pause PerfHUD", "sys_perfhud_pause", 0, 1); - - //save default windows - pGUI->SaveState(); - - m_hudCreated = true; -} -////////////////////////////////////////////////////////////////////////// -// GUI CREATION HELPER FUNCS -////////////////////////////////////////////////////////////////////////// - -IMiniCtrl* CPerfHUD::CreateMenu(const char* name, IMiniCtrl* pParent) -{ - assert(name); - - IMiniGUIPtr pGUI; - if (CryCreateClassInstanceForInterface(cryiidof(), pGUI)) - { - bool subMenu = false; - - if (pParent) - { - assert(pParent->GetType() == eCtrlType_Menu); - subMenu = true; - } - - const float ButtonWidth = 10.f; //arbitrary, button will be scaled based on contained text - - int ctrlFlags = 0; - - if (!subMenu) - { - ctrlFlags = eCtrl_TextAlignCentre | eCtrl_AutoResize; - } - - Rect rcMenuBtn = Rect(m_menuStartX, m_menuStartY, m_menuStartX + ButtonWidth, m_menuStartY + 20); - - IMiniCtrl* pMenu = pGUI->CreateCtrl(pParent, 1, eCtrlType_Menu, ctrlFlags, rcMenuBtn, name); - - if (pMenu && !subMenu) - { - const float MenuBtnSepration = 10.f; - - //Update Menu Positions - rcMenuBtn = pMenu->GetRect(); - m_menuStartX = rcMenuBtn.right + MenuBtnSepration; - m_menuStartY = rcMenuBtn.top; - - m_rootMenus.push_back(pMenu); - } - - return pMenu; - } - return NULL; -} - -////////////////////////////////////////////////////////////////////////// -bool CPerfHUD::CreateCVarMenuItem(IMiniCtrl* pMenu, const char* name, const char* controlVar, float controlVarOff, float controlVarOn) -{ - assert(pMenu && name && controlVar); - assert(pMenu->GetType() == eCtrlType_Menu); - - IMiniGUIPtr pGUI; - if (CryCreateClassInstanceForInterface(cryiidof(), pGUI)) - { - IMiniCtrl* pCtrl = pGUI->CreateCtrl(pMenu, 100, eCtrlType_Button, eCtrl_CheckButton, Rect(0, 0, 100, 20), name); - - if (pCtrl) - { - if (controlVar) - { - pCtrl->SetControlCVar(controlVar, controlVarOff, controlVarOn); - } - return true; - } - } - return false; -} - -////////////////////////////////////////////////////////////////////////// -bool CPerfHUD::CreateCallbackMenuItem(IMiniCtrl* pMenu, const char* name, ClickCallback clickCallback, void* pCallbackData) -{ - assert(pMenu && name && clickCallback); - assert(pMenu->GetType() == eCtrlType_Menu); - - IMiniGUIPtr pGUI; - if (CryCreateClassInstanceForInterface(cryiidof(), pGUI)) - { - IMiniCtrl* pCtrl = pGUI->CreateCtrl(pMenu, 100, eCtrlType_Button, 0 /*eCtrl_CheckButton*/, Rect(0, 0, 100, 20), name); - - if (pCtrl) - { - pCtrl->SetClickCallback(clickCallback, pCallbackData); - return true; - } - } - return false; -} - -////////////////////////////////////////////////////////////////////////// -IMiniInfoBox* CPerfHUD::CreateInfoMenuItem(IMiniCtrl* pMenu, const char* name, RenderCallback renderCallback, const Rect& rect, bool onAtStart) -{ - assert(pMenu->GetType() == eCtrlType_Menu); - - IMiniGUIPtr pGUI; - if (CryCreateClassInstanceForInterface(cryiidof(), pGUI)) - { - IMiniCtrl* pCtrl = pGUI->CreateCtrl(pMenu, 100, eCtrlType_Button, eCtrl_CheckButton, Rect(0, 0, 100, 20), name); - - int infoFlags = eCtrl_Moveable | eCtrl_CloseButton; - - if (!renderCallback) - { - infoFlags |= eCtrl_AutoResize; - } - - CMiniInfoBox* pInfo = (CMiniInfoBox*)pGUI->CreateCtrl(NULL, 200, eCtrlType_InfoBox, infoFlags, rect, name); - - if (pCtrl) - { - pCtrl->SetConnectedCtrl(pInfo); - - if (onAtStart) - { - pCtrl->SetFlag(eCtrl_Checked); - } - else - { - pInfo->SetVisible(false); - } - - if (renderCallback) - { - pInfo->SetRenderCallback(renderCallback); - } - - return pInfo; - } - } - return NULL; -} - -////////////////////////////////////////////////////////////////////////// -IMiniTable* CPerfHUD::CreateTableMenuItem(IMiniCtrl* pMenu, const char* name) -{ - assert(pMenu && name); - assert(pMenu->GetType() == eCtrlType_Menu); - - IMiniGUIPtr pGUI; - if (CryCreateClassInstanceForInterface(cryiidof(), pGUI)) - { - CMiniTable* pTable = (CMiniTable*)pGUI->CreateCtrl(NULL, 200, eCtrlType_Table, eCtrl_AutoResize | eCtrl_Moveable | eCtrl_CloseButton, Rect(50, 100, 400, 350), name); - - if (pTable) - { - IMiniCtrl* pCtrl = pGUI->CreateCtrl(pMenu, 100, eCtrlType_Button, eCtrl_CheckButton, Rect(0, 0, 100, 20), name); - - if (pCtrl) - { - pCtrl->SetConnectedCtrl(pTable); - - pTable->SetVisible(false); - - return pTable; - } - } - } - return NULL; -} - -IMiniCtrl* CPerfHUD::GetMenu(const char* name) -{ - int nRootMenus = m_rootMenus.size(); - - for (int i = 0; i < nRootMenus; i++) - { - if (strcmp(m_rootMenus[i]->GetTitle(), name) == 0) - { - return m_rootMenus[i]; - } - } - return NULL; -} - -////////////////////////////////////////////////////////////////////////// -void CPerfHUD::OnCommand([[maybe_unused]] SCommand& cmd) -{ - //CryLog( "Button Clicked = %d",cmd.nCtrlID ); -} - -////////////////////////////////////////////////////////////////////////// -bool CPerfHUD::OnInputChannelEventFiltered(const AzFramework::InputChannel& inputChannel) -{ - const AzFramework::InputChannelId& channelId = inputChannel.GetInputChannelId(); - const AzFramework::InputDeviceId& deviceId = inputChannel.GetInputDevice().GetInputDeviceId(); - if (AzFramework::InputDeviceKeyboard::IsKeyboardDevice(deviceId) && inputChannel.IsStateBegan()) - { - if (channelId == AzFramework::InputDeviceKeyboard::Key::WindowsSystemPrint) - { - //Cycle modes - const AzFramework::ModifierKeyStates* customData = inputChannel.GetCustomData(); - const AzFramework::ModifierKeyStates modifierKeyStates = customData ? *customData : AzFramework::ModifierKeyStates(); - const bool isAltModifierActive = modifierKeyStates.IsActive(AzFramework::ModifierKeyMask::AltAny); - const bool isCtrlModifierActive = modifierKeyStates.IsActive(AzFramework::ModifierKeyMask::CtrlAny); - if (isAltModifierActive || isCtrlModifierActive) - { - SetNextState(); - } - } - else if (channelId == AzFramework::InputDeviceKeyboard::Key::WindowsSystemScrollLock) - { - //toggle pause - m_sys_perfhud_pause ^= 1; - } - } - - - if (deviceId == AzFramework::InputDeviceGamepad::IdForIndex0) - { - if (inputChannel.IsStateBegan()) - { - bool checkState = false; - - if (channelId == AzFramework::InputDeviceGamepad::Button::L1) - { - m_L1Pressed = true; - checkState = true; - } - else if (channelId == AzFramework::InputDeviceGamepad::Button::R1) - { - m_R1Pressed = true; - checkState = true; - } - else if (channelId == AzFramework::InputDeviceGamepad::Button::X) - { - if (m_changingState) - { - SetNextState(); - } - } - - //if(checkState&&m_L1Pressed&&m_L2Pressed&&m_R1Pressed&&m_R2Pressed) - if (checkState && m_L1Pressed && m_R1Pressed) - { - m_triggersDownStartTime = gEnv->pTimer->GetAsyncCurTime(); - } - } - else if (inputChannel.IsStateUpdated()) - { - float activateTime = (m_hudState == eHudOff) ? ACTIVATE_TIME_FROM_GAME : ACTIVATE_TIME_FROM_HUD; - - if (m_triggersDownStartTime > 0.f && gEnv->pTimer->GetAsyncCurTime() - m_triggersDownStartTime > activateTime) - { - m_changingState = true; - - const char* hudStateStr = NULL; - - switch (m_hudState) - { - case eHudInFocus: - hudStateStr = "CryPerfHUD Edit Mode"; - break; - - case eHudOutOfFocus: - hudStateStr = "CryPerfHUD Game Mode"; - break; - - case eHudOff: - hudStateStr = "CryPerfHUD Off"; - break; - - default: - hudStateStr = "CryPerfHud unknown"; - break; - } - - float col[4] = {1.f, 1.f, 1.f, 1.f}; - gEnv->pRenderer->Draw2dLabel(450.f, 200.f, 2.f, col, false, hudStateStr); - gEnv->pRenderer->Draw2dLabel(450.f, 220.f, 2.f, col, false, "Press X to change Mode"); - } - } - else if (inputChannel.IsStateEnded()) - { - bool triggerReleased = false; - - if (channelId == AzFramework::InputDeviceGamepad::Button::L1) - { - m_L1Pressed = false; - triggerReleased = true; - } - else if (channelId == AzFramework::InputDeviceGamepad::Button::R1) - { - m_R1Pressed = false; - triggerReleased = true; - } - - if (triggerReleased) - { - m_triggersDownStartTime = 0.f; - - if (m_changingState) - { - m_changingState = false; - - //workaround: hardware mouse resets all input states when enabled - //this breaks perfhud selection mode (as triggers are released) - //don't enable mouse until we've finished selection mode - if (m_hudState == eHudInFocus) - { - if (!m_hwMouseEnabled) - { - UiCursorBus::Broadcast(&UiCursorInterface::IncrementVisibleCounter); - m_hwMouseEnabled = true; - } - } - else if (m_hwMouseEnabled) - { - UiCursorBus::Broadcast(&UiCursorInterface::DecrementVisibleCounter); - m_hwMouseEnabled = false; - } - } - } - } - - if (m_hudState == eHudInFocus) - { - //PerfHUD takes control of the input - return true; - } - } - return false; -} - -void CPerfHUD::SetNextState() -{ - if (m_sys_perfhud != eHudOff) - { - m_hudState = (EHudState)((m_hudState + 1) % eHudNumStates); - //CryLogAlways("Setting new HUD state: %d", m_hudState); - - //what to do about cvar? - //ICVar *pPerfCVar = GetISystem()->GetIConsole()->GetCVar("sys_perfhud"); - //pPerfCVar->Set( 1 ); - } -} - -void CPerfHUD::SetState(EHudState state) -{ - if (state != m_hudState) - { - if (m_hwMouseEnabled) - { - if (state != eHudInFocus) - { - UiCursorBus::Broadcast(&UiCursorInterface::DecrementVisibleCounter); - m_hwMouseEnabled = false; - } - } - else if (state == eHudInFocus) - { - UiCursorBus::Broadcast(&UiCursorInterface::IncrementVisibleCounter); - m_hwMouseEnabled = true; - } - - m_hudState = state; - } -} - -void CPerfHUD::Reset() -{ - IMiniGUIPtr pGUI; - if (CryCreateClassInstanceForInterface(cryiidof(), pGUI)) - { - pGUI->Reset(); - } -} - -////////////////////////////////////////////////////////////////////////// -// CLICK CALLBACKS -////////////////////////////////////////////////////////////////////////// - -void CPerfHUD::ResetCallback([[maybe_unused]] void* data, [[maybe_unused]] bool status) -{ - ICryPerfHUDPtr pPerfHUD; - if (CryCreateClassInstanceForInterface(cryiidof(), pPerfHUD)) - { - pPerfHUD->Reset(); - } -} - -void CPerfHUD::ReloadBudgetsCallback([[maybe_unused]] void* data, [[maybe_unused]] bool status) -{ - ICryPerfHUDPtr pPerfHUD; - if (CryCreateClassInstanceForInterface(cryiidof(), pPerfHUD)) - { - pPerfHUD->LoadBudgets(); - } -} - -void CPerfHUD::SaveStatsCallback([[maybe_unused]] void* data, [[maybe_unused]] bool status) -{ - ICryPerfHUDPtr pPerfHUD; - if (CryCreateClassInstanceForInterface(cryiidof(), pPerfHUD)) - { - pPerfHUD->SaveStats(); - } -} - -////////////////////////////////////////////////////////////////////////// -// RENDER CALLBACKS -////////////////////////////////////////////////////////////////////////// - -void CPerfHUD::EnableWidget(ICryPerfHUDWidget::EWidgetID id, int mode) -{ - const int nWidgets = m_widgets.size(); - - for (int i = 0; i < nWidgets; i++) - { - if (m_widgets[i]->m_id == id) - { - m_widgets[i]->Enable(mode); - return; - } - } -} - -void CPerfHUD::DisableWidget(ICryPerfHUDWidget::EWidgetID id) -{ - const int nWidgets = m_widgets.size(); - - for (int i = 0; i < nWidgets; i++) - { - if (m_widgets[i]->m_id == id) - { - m_widgets[i]->Disable(); - return; - } - } -} - -////////////////////////////////////////////////////////////////////////// -// Widget Specific Interface -////////////////////////////////////////////////////////////////////////// -void CPerfHUD::AddWarning(float duration, const char* fmt, va_list argList) -{ - if (m_hudState != eHudOff) - { - //could cache warnings window ptr for efficiency - const int nWidgets = m_widgets.size(); - - for (int i = 0; i < nWidgets; i++) - { - if (m_widgets[i]->m_id == ICryPerfHUDWidget::eWidget_Warnings) - { - CWarningsWidget* warnings = (CWarningsWidget*)m_widgets[i].get(); - - if (warnings->ShouldUpdate()) - { - warnings->AddWarningV(duration, fmt, argList); - break; - } - } - } - } -} - -bool CPerfHUD::WarningsWindowEnabled() const -{ - const int nWidgets = m_widgets.size(); - - for (int i = 0; i < nWidgets; i++) - { - if (m_widgets[i]->m_id == ICryPerfHUDWidget::eWidget_Warnings) - { - return m_widgets[i]->ShouldUpdate(); - } - } - - return false; -} - -const std::vector* CPerfHUD::GetFpsBuckets(float& totalTime) const -{ - const int nWidgets = m_widgets.size(); - - for (int i = 0; i < nWidgets; i++) - { - if (m_widgets[i]->m_id == ICryPerfHUDWidget::eWidget_FpsBuckets) - { - return ((CFpsWidget*)m_widgets[i].get())->GetFpsBuckets(totalTime); - } - } - - return NULL; -} - -////////////////////////////////////////////////////////////////////////// -//FPS Buckets Widget -////////////////////////////////////////////////////////////////////////// - -int CFpsWidget::m_cvarPerfHudFpsExclusive = 0; - -CFpsWidget::CFpsWidget(IMiniCtrl* pParentMenu, ICryPerfHUD* pPerfHud) - : ICryPerfHUDWidget(eWidget_FpsBuckets) -{ - m_fpsBucketSize = 5.f; - m_fpsBudget = 30.f; - m_dpBudget = 2500.f; - m_dpBucketSize = 250.f; - - //FPS Buckets - IMiniCtrl* pFPSMenu = pPerfHud->CreateMenu("FPS", pParentMenu); - m_pInfoBox = pPerfHud->CreateInfoMenuItem(pFPSMenu, "FPS Buckets", NULL, Rect(850, 395, 860, 405)); - pPerfHud->CreateCallbackMenuItem(pFPSMenu, "Reset Buckets", CFpsWidget::ResetCallback, this); - - //Display framerates buckets as inclusive or exclusive - REGISTER_CVAR2("sys_perfhud_fpsBucketsExclusive", &m_cvarPerfHudFpsExclusive, 0, VF_CHEAT, "Toggle FPS Buckets exclusive / inclusive"); - - Init(); -} - -void CFpsWidget::LoadBudgets(XmlNodeRef PerfXML) -{ - if (PerfXML) - { - XmlNodeRef xmlNode; - - //FPS / GPU - explicit bucket values - if ((xmlNode = PerfXML->findChild("fpsBucketValues"))) - { - m_perfBuckets[BUCKET_FPS].buckets.clear(); - m_perfBuckets[BUCKET_GPU].buckets.clear(); - - uint32 nBuckets = xmlNode->getChildCount(); - - for (uint32 i = 0; i < nBuckets; i++) - { - XmlNodeRef bucketVal = xmlNode->getChild(i); - - float target; - bucketVal->getAttr("value", target); - - ICryPerfHUD::PerfBucket bucket(target); - - m_perfBuckets[BUCKET_FPS].buckets.push_back(bucket); - m_perfBuckets[BUCKET_GPU].buckets.push_back(bucket); - } - - m_perfBuckets[BUCKET_FPS].totalTime = 0.f; - m_perfBuckets[BUCKET_GPU].totalTime = 0.f; - } - //Auto generated buckets based on max fps and bucket size - else if ((xmlNode = PerfXML->findChild("fpsBucketMax"))) - { - xmlNode->getAttr("value", m_fpsBudget); - - if ((xmlNode = PerfXML->findChild("fpsBucketSize"))) - { - xmlNode->getAttr("value", m_fpsBucketSize); - } - else - { - m_fpsBucketSize = 5; - } - - m_perfBuckets[BUCKET_FPS].buckets.clear(); - m_perfBuckets[BUCKET_GPU].buckets.clear(); - - float targetFPS = m_fpsBudget; - - for (uint32 i = 0; i < NUM_FPS_BUCKETS_DEFAULT; i++) - { - ICryPerfHUD::PerfBucket bucket(targetFPS); - - m_perfBuckets[BUCKET_FPS].buckets.push_back(bucket); - m_perfBuckets[BUCKET_GPU].buckets.push_back(bucket); - - targetFPS -= m_fpsBucketSize; - } - - m_perfBuckets[BUCKET_FPS].totalTime = 0.f; - m_perfBuckets[BUCKET_GPU].totalTime = 0.f; - } - - //DP buckets - explicit bucket values - if ((xmlNode = PerfXML->findChild("dpBucketValues"))) - { - m_perfBuckets[BUCKET_DP].buckets.clear(); - - uint32 nBuckets = xmlNode->getChildCount(); - - for (uint32 i = 0; i < nBuckets; i++) - { - XmlNodeRef bucketVal = xmlNode->getChild(i); - - float target; - bucketVal->getAttr("value", target); - - ICryPerfHUD::PerfBucket bucket(target); - - m_perfBuckets[BUCKET_DP].buckets.push_back(bucket); - } - m_perfBuckets[BUCKET_DP].totalTime = 0.f; - } - //DPs auto values - else if ((xmlNode = PerfXML->findChild("drawPrimBucketMax"))) - { - xmlNode->getAttr("value", m_dpBudget); - - //Auto generated buckets based on max dp and bucket size - if ((xmlNode = PerfXML->findChild("dpBucketSize"))) - { - xmlNode->getAttr("value", m_dpBucketSize); - } - else - { - m_dpBucketSize = 250.f; - } - - m_perfBuckets[BUCKET_DP].buckets.clear(); - - float nDPs = m_dpBudget - ((NUM_FPS_BUCKETS_DEFAULT - 1) * m_dpBucketSize); - - for (uint32 i = 0; i < NUM_FPS_BUCKETS_DEFAULT; i++) - { - ICryPerfHUD::PerfBucket bucket(nDPs); - - m_perfBuckets[BUCKET_DP].buckets.push_back(bucket); - - nDPs += m_dpBucketSize; - } - m_perfBuckets[BUCKET_DP].totalTime = 0.f; - } - } -} - -template -void CFpsWidget::UpdateBuckets(PerfBucketsStat& bucketStat, float frameTime, const char* name, float stat) -{ - char entryBuffer[CMiniInfoBox::MAX_TEXT_LENGTH] = {0}; - - const uint32 numBuckets = bucketStat.buckets.size(); - - if (frameTime > 0.f) - { - bucketStat.totalTime += frameTime; - - for (uint32 i = 0; i < numBuckets; i++) - { - if (LESS_THAN) - { - if (stat <= bucketStat.buckets[i].target) - { - bucketStat.buckets[i].timeAtTarget += frameTime; - } - } - else - { - if (stat >= bucketStat.buckets[i].target) - { - bucketStat.buckets[i].timeAtTarget += frameTime; - } - } - } - } - - if (bucketStat.totalTime > 0.f) - { - sprintf_s(entryBuffer, CMiniInfoBox::MAX_TEXT_LENGTH, "%s: %.2f", name, stat); - m_pInfoBox->AddEntry(entryBuffer, CPerfHUD::COL_NORM, CPerfHUD::TEXT_SIZE_NORM); - - //render exclusive stats - if (m_cvarPerfHudFpsExclusive) - { - for (uint32 i = 0; i < numBuckets; i++) - { - //inclusive time - float timeAtTarget = bucketStat.buckets[i].timeAtTarget; - - if (i > 0) - { - //exclusive time - timeAtTarget -= bucketStat.buckets[i - 1].timeAtTarget; - - //Add info to gui - float percentAtTarget = 100.f * (timeAtTarget / bucketStat.totalTime); - sprintf_s(entryBuffer, CMiniInfoBox::MAX_TEXT_LENGTH, "%.2f%%%% of time %.1f -> %.1f FPS", percentAtTarget, bucketStat.buckets[i].target, bucketStat.buckets[i - 1].target); - } - else - { - float percentAtTarget = 100.f * (bucketStat.buckets[i].timeAtTarget / bucketStat.totalTime); - sprintf_s(entryBuffer, CMiniInfoBox::MAX_TEXT_LENGTH, "%.2f%%%% of time >= %.1f FPS", percentAtTarget, bucketStat.buckets[i].target); - } - m_pInfoBox->AddEntry(entryBuffer, CPerfHUD::COL_NORM, CPerfHUD::TEXT_SIZE_NORM); - } - } - else //render inclusive stats - { - for (uint32 i = 0; i < numBuckets; i++) - { - float percentAtTarget = 100.f * (bucketStat.buckets[i].timeAtTarget / bucketStat.totalTime); - sprintf_s(entryBuffer, CMiniInfoBox::MAX_TEXT_LENGTH, "%.2f%%%% of time %s %.1f", percentAtTarget, LESS_THAN ? "<=" : ">=", bucketStat.buckets[i].target); - m_pInfoBox->AddEntry(entryBuffer, CPerfHUD::COL_NORM, CPerfHUD::TEXT_SIZE_NORM); - } - } - } -} - -void CFpsWidget::Update() -{ - m_pInfoBox->ClearEntries(); - - // - // FPS - // - { - float frameTime = gEnv->pTimer->GetRealFrameTime(); - UpdateBuckets(m_perfBuckets[BUCKET_FPS], frameTime, "FPS", 1.f / frameTime); - } - - // - // GPU FPS - // - { - float gpuFrameTime = gEnv->pRenderer->GetGPUFrameTime(); - - if (gpuFrameTime > 0.f) - { - m_pInfoBox->AddEntry("", CPerfHUD::COL_NORM, CPerfHUD::TEXT_SIZE_NORM); - UpdateBuckets(m_perfBuckets[BUCKET_GPU], gpuFrameTime, "GPU FPS", 1.f / gpuFrameTime); - } - } - - // - // Draw Call - // - { - //ugly, but buckets are float only at the moment - float nDPs = (float)gEnv->pRenderer->GetCurrentNumberOfDrawCalls(); - m_pInfoBox->AddEntry("", CPerfHUD::COL_NORM, CPerfHUD::TEXT_SIZE_NORM); - UpdateBuckets(m_perfBuckets[BUCKET_DP], 1.f, "DPs", nDPs); - } -} - -//Init buckets with default values -void CFpsWidget::Init() -{ - float targetFPS = m_fpsBudget; - float nDPs = m_dpBudget - ((NUM_FPS_BUCKETS_DEFAULT - 1) * m_dpBucketSize); - - for (uint32 i = 0; i < NUM_FPS_BUCKETS_DEFAULT; i++) - { - ICryPerfHUD::PerfBucket bucket(targetFPS); - - m_perfBuckets[BUCKET_FPS].buckets.push_back(bucket); - m_perfBuckets[BUCKET_GPU].buckets.push_back(bucket); - - bucket.target = (float)nDPs; - - m_perfBuckets[BUCKET_DP].buckets.push_back(bucket); - - targetFPS -= m_fpsBucketSize; - nDPs += m_dpBucketSize; - } - - for (uint32 i = 0; i < BUCKET_TYPE_NUM; i++) - { - m_perfBuckets[i].totalTime = 0.f; - } -} - -//Clear bucket totals -void CFpsWidget::Reset() -{ - for (uint32 i = 0; i < BUCKET_TYPE_NUM; i++) - { - PerfBucketsStat& stat = m_perfBuckets[i]; - - const uint32 nBuckets = stat.buckets.size(); - - //Init fps buckets - for (uint32 j = 0; j < nBuckets; j++) - { - stat.buckets[j].timeAtTarget = 0.f; - } - - stat.totalTime = 0.f; - } -} - -void CFpsWidget::ResetCallback(void* data, [[maybe_unused]] bool status) -{ - assert(data); - ((CFpsWidget*)data)->Reset(); -} - -bool CFpsWidget::ShouldUpdate() -{ - return !m_pInfoBox->IsHidden(); -} - -//TODO -void CFpsWidget::SaveStats(XmlNodeRef statsXML) -{ - if (statsXML) - { - const char* perfBucketTypeStr[] = - { - "BUCKET_FPS", - "BUCKET_GPU", - "BUCKET_DP", - }; - - XmlNodeRef fpsNode; - - for (int i = 0; i < BUCKET_TYPE_NUM; i++) - { - PerfBucketsStat& perfBucket = m_perfBuckets[i]; - - if (perfBucket.totalTime > 0.f) - { - if ((fpsNode = statsXML->newChild(perfBucketTypeStr[i]))) - { - XmlNodeRef child; - - const uint32 numBuckets = perfBucket.buckets.size(); - - for (uint32 j = 0; j < numBuckets; j++) - { - float percentAtTarget = 100.f * (perfBucket.buckets[j].timeAtTarget / perfBucket.totalTime); - - if ((child = fpsNode->newChild("bucket"))) - { - child->setAttr("target", perfBucket.buckets[j].target); - } - - if ((child = fpsNode->newChild("percentAtTime"))) - { - child->setAttr("value", percentAtTarget); - } - } - } - } - } - } -} - -const std::vector* CFpsWidget::GetFpsBuckets(float& totalTime) const -{ - totalTime = m_perfBuckets[BUCKET_FPS].totalTime; - return &m_perfBuckets[BUCKET_FPS].buckets; -} - -////////////////////////////////////////////////////////////////////////// -//Render Stats Widget -////////////////////////////////////////////////////////////////////////// - -CRenderStatsWidget::CRenderStatsWidget(IMiniCtrl* pParentMenu, ICryPerfHUD* pPerfHud) - : ICryPerfHUDWidget(eWidget_RenderStats) -{ - m_pPerfHUD = pPerfHud; - m_fpsBudget = 30.f; - m_dpBudget = 2000; - m_polyBudget = 500000; - m_postEffectBudget = 3; - m_shadowCastBudget = 2; - m_particlesBudget = 1000; - m_pInfoBox = NULL; - m_buildNum = 0; - - ZeroStruct(m_runtimeData); - - m_pInfoBox = pPerfHud->CreateInfoMenuItem(pParentMenu, "Scene Summary", NULL, Rect(45, 350, 100, 400) /*, true*/); - - //Get build number from BuildName.txt - //FILE *buildFile = fxopen("BuildName.txt", "r"); - CCryFile buildFile; - - if (buildFile.Open("./BuildName.txt", "rb", AZ::IO::IArchive::FOPEN_ONDISK | AZ::IO::IArchive::FOPEN_HINT_QUIET)) - { - size_t fileSize = buildFile.GetLength(); - - if (fileSize > 0 && fileSize < 64) - { - char buffer[64] = {0}; - - buildFile.ReadRaw(buffer, fileSize); - - if (buffer[0]) - { - const char* ptr = strchr(buffer, '('); - - if (ptr) - { - ptr++; - m_buildNum = atoi(ptr); - } - } - } - } -} - -void CRenderStatsWidget::Update() -{ - IRenderer* pRenderer = gEnv->pRenderer; - - char entryBuffer[CMiniInfoBox::MAX_TEXT_LENGTH] = {0}; - - //Clear old entries - m_pInfoBox->ClearEntries(); - ZeroStruct(m_runtimeData); - - // - // FPS - // - m_runtimeData.fps = min(9999.f, gEnv->pTimer->GetFrameRate()); - - sprintf_s(entryBuffer, CMiniInfoBox::MAX_TEXT_LENGTH, "FPS: %.2f (%.2f)", m_runtimeData.fps, m_fpsBudget); - - if (m_runtimeData.fps >= m_fpsBudget) - { - m_pInfoBox->AddEntry(entryBuffer, CPerfHUD::COL_NORM, CPerfHUD::TEXT_SIZE_NORM); - } - else - { - m_pInfoBox->AddEntry(entryBuffer, CPerfHUD::COL_ERROR, CPerfHUD::TEXT_SIZE_NORM); - CryPerfHUDWarning(1.f, "FPS Too Low: %.2f", m_runtimeData.fps); - - //PerfHud / AuxRenderer causes us to be RenderThread limited - //Need to investigate vertex buffer locks in AuxRenderer before enabling - - /* - // Fran: please call me before re-enabling this code - - SRenderTimes renderTimes; - pRenderer->GetRenderTimes(renderTimes); - - //wait for main is never 0 - if(renderTimes.fWaitForMain>renderTimes.fWaitForRender && renderTimes.fWaitForMain>renderTimes.fWaitForGPU) - { - m_pInfoBox->AddEntry("Main Thread Limited", CPerfHUD::COL_ERROR, CPerfHUD::TEXT_SIZE_ERROR); - m_pPerfHud->AddWarning("Main Thread Limited",1.f); - } - else if(renderTimes.fWaitForRender>renderTimes.fWaitForGPU) - { - m_pInfoBox->AddEntry("Render Thread Limited", CPerfHUD::COL_ERROR, CPerfHUD::TEXT_SIZE_ERROR); - m_pPerfHud->AddWarning("Render Thread Limited",1.f); - } - else - { - m_pInfoBox->AddEntry("GPU Limited", CPerfHUD::COL_ERROR, CPerfHUD::TEXT_SIZE_ERROR); - m_pPerfHud->AddWarning("GPU Limited",1.f); - }*/ - } - - // - // GPU Time - // - float gpuTime = pRenderer->GetGPUFrameTime(); - - if (gpuTime > 0.f) - { - float gpuFPS = 1.f / gpuTime; - - sprintf_s(entryBuffer, CMiniInfoBox::MAX_TEXT_LENGTH, "GPU FPS: %.2f (%.2f)", gpuFPS, m_fpsBudget); - if (gpuFPS >= m_fpsBudget) - { - m_pInfoBox->AddEntry(entryBuffer, CPerfHUD::COL_NORM, CPerfHUD::TEXT_SIZE_NORM); - } - else - { - m_pInfoBox->AddEntry(entryBuffer, CPerfHUD::COL_ERROR, CPerfHUD::TEXT_SIZE_NORM); - CryPerfHUDWarning(1.f, "GPU FPS Too Low: %.2f", gpuFPS); - } - } - - - // - // HDR - // - bool bHDRModeEnabled = false; - pRenderer->EF_Query(EFQ_HDRModeEnabled, bHDRModeEnabled); - if (bHDRModeEnabled) - { - m_runtimeData.hdrEnabled = true; - if (!m_runtimeData.hdrEnabled) - { - CryPerfHUDWarning(1.f, "HDR Disabled"); - } - } - - if (!gEnv->IsEditor()) - { - // - // Render Thread - // - static ICVar* pMultiThreaded = gEnv->pConsole->GetCVar("r_MultiThreaded"); - if (pMultiThreaded && pMultiThreaded->GetIVal() > 0) - { - //sprintf_s(entryBuffer, CMiniInfoBox::MAX_TEXT_LENGTH, "Render Thread Enabled"); - //m_pInfoBox->AddEntry(entryBuffer, CPerfHUD::COL_NORM, CPerfHUD::TEXT_SIZE_NORM); - m_runtimeData.renderThreadEnabled = true; - } - else - { - sprintf_s(entryBuffer, CMiniInfoBox::MAX_TEXT_LENGTH, "Render Thread Disabled"); - m_pInfoBox->AddEntry(entryBuffer, CPerfHUD::COL_ERROR, CPerfHUD::TEXT_SIZE_NORM); - m_runtimeData.renderThreadEnabled = false; - CryPerfHUDWarning(1.f, "Render Thread Disabled"); - } - } - - - // - // Camera - // - Matrix33 m = Matrix33(pRenderer->GetCamera().GetMatrix()); - m_runtimeData.cameraRot = RAD2DEG(Ang3::GetAnglesXYZ(m)); - m_runtimeData.cameraPos = pRenderer->GetCamera().GetPosition(); - - - // - // Polys / Draw Prims - // - int nShadowVolPolys; - int nPolys; - pRenderer->GetPolyCount(nPolys, nShadowVolPolys); - m_runtimeData.nPolys = nPolys; - m_runtimeData.nDrawPrims = pRenderer->GetCurrentNumberOfDrawCalls(); - - sprintf_s(entryBuffer, CMiniInfoBox::MAX_TEXT_LENGTH, "Draw Calls: %d (%d)", m_runtimeData.nDrawPrims, m_dpBudget); - - if (m_runtimeData.nDrawPrims <= m_dpBudget) - { - m_pInfoBox->AddEntry(entryBuffer, CPerfHUD::COL_NORM, CPerfHUD::TEXT_SIZE_NORM); - } - else - { - m_pInfoBox->AddEntry(entryBuffer, CPerfHUD::COL_ERROR, CPerfHUD::TEXT_SIZE_NORM); - CryPerfHUDWarning(1.f, "Too Many Draw Calls: %d", m_runtimeData.nDrawPrims); - } - - sprintf_s(entryBuffer, CMiniInfoBox::MAX_TEXT_LENGTH, "Num Tris: %d (%d)", m_runtimeData.nPolys, m_polyBudget); - - if (m_runtimeData.nPolys <= m_polyBudget) - { - m_pInfoBox->AddEntry(entryBuffer, CPerfHUD::COL_NORM, CPerfHUD::TEXT_SIZE_NORM); - } - else - { - m_pInfoBox->AddEntry(entryBuffer, CPerfHUD::COL_ERROR, CPerfHUD::TEXT_SIZE_NORM); - CryPerfHUDWarning(1.f, "Too Many Tris: %d", m_runtimeData.nPolys); - } - - // - // Post Effects - // - - gEnv->pRenderer->EF_Query(EFQ_NumActivePostEffects, m_runtimeData.nPostEffects); - sprintf_s(entryBuffer, CMiniInfoBox::MAX_TEXT_LENGTH, "Num Post Effects: %d (%d)", m_runtimeData.nPostEffects, m_postEffectBudget); - - if (m_runtimeData.nPostEffects <= m_postEffectBudget) - { - m_pInfoBox->AddEntry(entryBuffer, CPerfHUD::COL_NORM, CPerfHUD::TEXT_SIZE_NORM); - } - else - { - m_pInfoBox->AddEntry(entryBuffer, CPerfHUD::COL_ERROR, CPerfHUD::TEXT_SIZE_NORM); - CryPerfHUDWarning(1.f, "Too Many Post Effects: %d", m_runtimeData.nPostEffects); - } - - m_runtimeData.nFwdLights = 0; - m_runtimeData.nFwdShadowLights = 0; - - ////////////////////////////////////////////////////////////////////////// - if (gEnv->pRenderer) - { - STextureStreamingStats textureStats(true); - gEnv->pRenderer->EF_Query(EFQ_GetTexStreamingInfo, textureStats); - - float fTexRequiredMB = (float)(textureStats.nRequiredStreamedTexturesSize) / (1024 * 1024); - sprintf_s(entryBuffer, "Textures Required: %.2f (%dMB)", fTexRequiredMB, azlossy_cast(textureStats.nMaxPoolSize / (1024 * 1024))); - if (fTexRequiredMB < textureStats.nMaxPoolSize) - { - m_pInfoBox->AddEntry(entryBuffer, CPerfHUD::COL_NORM, CPerfHUD::TEXT_SIZE_NORM); - } - else - { - m_pInfoBox->AddEntry(entryBuffer, CPerfHUD::COL_ERROR, CPerfHUD::TEXT_SIZE_NORM); - CryPerfHUDWarning(1.f, "Too Many Textures: %.2fMB", fTexRequiredMB); - } - } -} -bool CRenderStatsWidget::ShouldUpdate() -{ - if (!m_pInfoBox->IsHidden() || - m_pPerfHUD->WarningsWindowEnabled()) - { - return true; - } - return false; -} - -void CRenderStatsWidget::LoadBudgets(XmlNodeRef perfXML) -{ - if (perfXML) - { - XmlNodeRef xmlNode; - - if ((xmlNode = perfXML->findChild("fps"))) - { - xmlNode->getAttr("value", m_fpsBudget); - } - - if ((xmlNode = perfXML->findChild("drawPrim"))) - { - xmlNode->getAttr("value", m_dpBudget); - } - - if ((xmlNode = perfXML->findChild("tris"))) - { - xmlNode->getAttr("value", m_polyBudget); - } - - if ((xmlNode = perfXML->findChild("postEffects"))) - { - xmlNode->getAttr("value", m_postEffectBudget); - } - - if ((xmlNode = perfXML->findChild("shadowCastingLights"))) - { - xmlNode->getAttr("value", m_shadowCastBudget); - } - - if ((xmlNode = perfXML->findChild("particles"))) - { - xmlNode->getAttr("value", m_particlesBudget); - } - } -} - -void CRenderStatsWidget::SaveStats(XmlNodeRef statsXML) -{ - if (!ShouldUpdate()) - { - //Force update of stats, widget may not be currently enabled - Update(); - } - - if (statsXML) - { - XmlNodeRef renderNode; - - if ((renderNode = statsXML->newChild("RenderStats"))) - { - XmlNodeRef child; - - if ((child = renderNode->newChild("fps"))) - { - child->setAttr("value", m_runtimeData.fps); - } - - if ((child = renderNode->newChild("hdr"))) - { - child->setAttr("value", m_runtimeData.hdrEnabled); - } - - if ((child = renderNode->newChild("renderThread"))) - { - child->setAttr("value", m_runtimeData.renderThreadEnabled); - } - - if ((child = renderNode->newChild("cameraPos"))) - { - child->setAttr("x", m_runtimeData.cameraPos.x); - child->setAttr("y", m_runtimeData.cameraPos.y); - child->setAttr("z", m_runtimeData.cameraPos.z); - } - - if ((child = renderNode->newChild("cameraRot"))) - { - child->setAttr("x", m_runtimeData.cameraRot.x); - child->setAttr("y", m_runtimeData.cameraRot.y); - child->setAttr("z", m_runtimeData.cameraRot.z); - } - - if ((child = renderNode->newChild("drawPrims"))) - { - child->setAttr("value", m_runtimeData.nDrawPrims); - } - - if ((child = renderNode->newChild("numPolys"))) - { - child->setAttr("value", m_runtimeData.nPolys); - } - - if ((child = renderNode->newChild("numPostEffects"))) - { - child->setAttr("value", m_runtimeData.nPostEffects); - } - - if ((child = renderNode->newChild("numFwdLights"))) - { - child->setAttr("value", m_runtimeData.nFwdLights); - } - - if ((child = renderNode->newChild("numFwdShadowLights"))) - { - child->setAttr("value", m_runtimeData.nFwdShadowLights); - } - - if ((child = renderNode->newChild("numDefLights"))) - { - child->setAttr("value", m_runtimeData.nDefLights); - } - - if ((child = renderNode->newChild("numDefShadowLights"))) - { - child->setAttr("value", m_runtimeData.nDefShadowLights); - } - - if ((child = renderNode->newChild("numDefCubeMaps"))) - { - child->setAttr("value", m_runtimeData.nDefCubeMaps); - } - - if ((child = renderNode->newChild("numParticles"))) - { - child->setAttr("value", m_runtimeData.nParticles); - } - } - } -} - -////////////////////////////////////////////////////////////////////////// -//Streaming Stats Widget -////////////////////////////////////////////////////////////////////////// - -CStreamingStatsWidget::CStreamingStatsWidget(IMiniCtrl* pParentMenu, ICryPerfHUD* pPerfHud) - : ICryPerfHUDWidget(eWidget_StreamingStats) -{ - m_pPerfHUD = pPerfHud; - m_pInfoBox = pPerfHud->CreateInfoMenuItem(pParentMenu, "Streaming", NULL, Rect(45, 200, 100, 300), true); - - //m_maxMeshSizeArroundMB = 0; - //m_maxTextureSizeArroundMB = 0; -} - -////////////////////////////////////////////////////////////////////////// -void CStreamingStatsWidget::Update() -{ -} - -////////////////////////////////////////////////////////////////////////// -bool CStreamingStatsWidget::ShouldUpdate() -{ - if (!m_pInfoBox->IsHidden() || - m_pPerfHUD->WarningsWindowEnabled()) - { - return true; - } - return false; -} - -////////////////////////////////////////////////////////////////////////// -void CStreamingStatsWidget::LoadBudgets(XmlNodeRef perfXML) -{ - /* -if(perfXML) -{ -XmlNodeRef xmlNode; -if( (xmlNode=perfXML->findChild("MeshSizeArround")) ) -{ - xmlNode->getAttr("value", m_maxMeshSizeArroundMB); -} -if( (xmlNode=perfXML->findChild("TextureSizeArround")) ) -{ - xmlNode->getAttr("value", m_maxTextureSizeArroundMB); -} -} -*/ -} - -////////////////////////////////////////////////////////////////////////// -//Warnings Widget -////////////////////////////////////////////////////////////////////////// - -CWarningsWidget::CWarningsWidget(IMiniCtrl* pParentMenu, ICryPerfHUD* pPerfHud) - : ICryPerfHUDWidget(eWidget_Warnings) -{ - m_pInfoBox = pPerfHud->CreateInfoMenuItem(pParentMenu, "Warnings", NULL, Rect(890, 150, 900, 200) /*, true*/); - - m_nMainThreadId = CryGetCurrentThreadId(); -} - -void CWarningsWidget::Reset() -{ - m_warnings.clear(); -} - -void CWarningsWidget::Update() -{ - //must be Main thread for MT warnings to work - assert(CryGetCurrentThreadId() == m_nMainThreadId); - - //Update from multithreaded queue - while (!m_threadWarnings.empty()) - { - SWarning warning; - if (m_threadWarnings.try_pop(warning)) - { - AddWarning(warning.remainingDuration, warning.text); - } - } - - float frameTime = gEnv->pTimer->GetRealFrameTime(); - - //delete old warnings - // [K01]: fixing Linux crash - TSWarnings::iterator iter = m_warnings.begin(); - while (iter != m_warnings.end()) - { - SWarning* pW = &(*iter); - pW->remainingDuration -= frameTime; - - if (pW->remainingDuration <= 0.f) - { - iter = m_warnings.erase(iter); - } - else - { - ++iter; - } - } - - int nWarnings = m_warnings.size(); - m_pInfoBox->ClearEntries(); - - //display warnings - for (int i = 0; i < nWarnings; i++) - { - m_pInfoBox->AddEntry(m_warnings[i].text, CPerfHUD::COL_ERROR, CPerfHUD::TEXT_SIZE_WARN); - } -} - -bool CWarningsWidget::ShouldUpdate() -{ - return !m_pInfoBox->IsHidden(); -} - -void CWarningsWidget::SaveStats(XmlNodeRef statsXML) -{ - if (statsXML) - { - const int nWarnings = m_warnings.size(); - - if (nWarnings > 0) - { - XmlNodeRef warningNode; - - if ((warningNode = statsXML->newChild("warnings"))) - { - XmlNodeRef child; - - for (int i = 0; i < nWarnings; i++) - { - if ((child = warningNode->newChild("warning"))) - { - child->setAttr("value", m_warnings[i].text); - } - } - } - } - } -} - -void CWarningsWidget::AddWarningV(float duration, const char* fmt, va_list argList) -{ - char warningText[WARNING_LENGTH]; - - int written = vsnprintf_s(warningText, WARNING_LENGTH, WARNING_LENGTH - 1, fmt, argList); - - if (written == -1) - { - warningText[WARNING_LENGTH - 1] = '\0'; - } - - AddWarning(duration, warningText); -} - -void CWarningsWidget::AddWarning(float duration, const char* warning) -{ - if (CryGetCurrentThreadId() == m_nMainThreadId) - { - const size_t nWarnings = m_warnings.size(); - bool bNewWarning = true; - - ptrdiff_t nCompareLen = strlen(warning); - const char* s = strchr(warning, ':'); - if (s) - { - nCompareLen = s - warning; - } - - for (size_t i = 0; i < nWarnings; i++) - { - if (strncmp(m_warnings[i].text, warning, nCompareLen) == 0) - { - //warning already exists, update duration - m_warnings[i].remainingDuration = duration; - cry_strcpy(m_warnings[i].text, warning); - bNewWarning = false; - break; - } - } - - if (bNewWarning) - { - SWarning newWarning; - newWarning.remainingDuration = duration; - cry_strcpy(newWarning.text, warning); - - m_warnings.push_back(newWarning); - } - } - else - { - //add to thread safe queue, warning will be added next update - SWarning newWarning; - newWarning.remainingDuration = duration; - cry_strcpy(newWarning.text, warning); - m_threadWarnings.push(newWarning); - } -} - -////////////////////////////////////////////////////////////////////////// -//Render Batch Stats Widget -////////////////////////////////////////////////////////////////////////// - -CRenderBatchWidget::CRenderBatchWidget(IMiniCtrl* pParentMenu, ICryPerfHUD* pPerfHud) - : ICryPerfHUDWidget(eWidget_RenderBatchStats) -{ - m_pTable = pPerfHud->CreateTableMenuItem(pParentMenu, "Render Batch Stats"); - - m_pRStatsCVar = GetISystem()->GetIConsole()->GetCVar("r_stats"); - - m_displayMode = DISPLAY_MODE_BATCH_STATS; - - m_pTable->RemoveColumns(); - m_pTable->AddColumn("Name"); - m_pTable->AddColumn("DPs"); - m_pTable->AddColumn("Instances"); - m_pTable->AddColumn("ZPass"); - m_pTable->AddColumn("Shadows"); - m_pTable->AddColumn("General"); - m_pTable->AddColumn("Transparent"); - m_pTable->AddColumn("Misc"); -} - -void CRenderBatchWidget::Reset() -{ -} - -void CRenderBatchWidget::SaveStats(XmlNodeRef statsXML) -{ -} - -void CRenderBatchWidget::Enable(int mode) -{ - mode = min(mode, DISPLAY_MODE_NUM - 1); - EDisplayMode newMode = (EDisplayMode)mode; - - if (m_displayMode != newMode) - { - //workaround for now, - //since we poke renderer in order to gather stats - switch (m_displayMode) - { - case DISPLAY_MODE_BATCH_STATS: - gEnv->pRenderer->CollectDrawCallsInfo(false); - break; - - case DISPLAY_MODE_GPU_TIMES: - m_pRStatsCVar->Set(0); - break; - } - - switch (newMode) - { - case DISPLAY_MODE_BATCH_STATS: - m_pTable->RemoveColumns(); - m_pTable->AddColumn("Name"); - m_pTable->AddColumn("DPs"); - m_pTable->AddColumn("Instances"); - m_pTable->AddColumn("ZPass"); - m_pTable->AddColumn("Shadows"); - m_pTable->AddColumn("General"); - m_pTable->AddColumn("Transparent"); - m_pTable->AddColumn("Misc"); - m_displayMode = newMode; - break; - - case DISPLAY_MODE_GPU_TIMES: - m_pTable->RemoveColumns(); - m_pTable->AddColumn("Name"); - m_pTable->AddColumn("Num Batches"); - m_pTable->AddColumn("Num Verts"); - m_pTable->AddColumn("Num Tris"); - m_displayMode = newMode; - break; - - default: - CryLogAlways("[Render Batch Stats] Attempting to set incorrect display mode set: %d", mode); - break; - } - } - - m_pTable->Hide(false); -} - -void CRenderBatchWidget::Disable() -{ - //ensure renderer is not doing unnecessary work - m_pRStatsCVar->Set(0); - gEnv->pRenderer->CollectDrawCallsInfo(false); - m_pTable->Hide(true); -} - - -bool CRenderBatchWidget::ShouldUpdate() -{ - return !m_pTable->IsHidden(); -} - -void CRenderBatchWidget::Update() -{ - switch (m_displayMode) - { - case DISPLAY_MODE_BATCH_STATS: - Update_ModeBatchStats(); - break; - case DISPLAY_MODE_GPU_TIMES: - Update_ModeGpuTimes(); - break; - default: - CryLogAlways("[Render Batch Stats]Incorrect Display mode set: %d", m_displayMode); - break; - } -} - -void CRenderBatchWidget::Update_ModeBatchStats() -{ -#if !defined(_RELEASE) - IRenderer* pRenderer = gEnv->pRenderer; - - pRenderer->CollectDrawCallsInfo(true); - - typedef std::map BatchMap; - typedef std::map::iterator BatchMapItor; - - //sorted Map elements - std::vector sortedBatchList; - - BatchMap batchMap; - - //mesh totals - static const char* strMeshTotals = "TOTAL (Mesh)"; - BatchInfoPerPass totalsMesh; - totalsMesh.col.set(255, 255, 255, 255); - totalsMesh.name = strMeshTotals; - - int nDPs = gEnv->pRenderer->GetCurrentNumberOfDrawCalls(); - - //scene totals - static const char* strSceneTotals = "TOTAL (Scene)"; - - BatchInfoPerPass totalsScene; - totalsScene.col.set(0, 255, 255, 255); - totalsScene.name = strSceneTotals; - totalsScene.nBatches = nDPs; - - int unknownDPs = nDPs; - - m_pTable->ClearTable(); - - IRenderer::RNDrawcallsMapMesh& drawCallsInfo = gEnv->pRenderer->GetDrawCallsInfoPerMesh(); - - IRenderer::RNDrawcallsMapMeshItor pEnd = drawCallsInfo.end(); - IRenderer::RNDrawcallsMapMeshItor pItor = drawCallsInfo.begin(); - - //Per RenderNode Stats - for (; pItor != pEnd; ++pItor) - { - IRenderer::SDrawCallCountInfo& drawInfo = pItor->second; - - uint32 nDrawcalls = drawInfo.nShadows + drawInfo.nZpass + drawInfo.nGeneral + drawInfo.nTransparent + drawInfo.nMisc; - - const char* pRenderNodeName = drawInfo.meshName; - const char* pNameShort = strrchr(pRenderNodeName, '/'); - - if (pNameShort) - { - pRenderNodeName = pNameShort + 1; - } - - BatchInfoPerPass batch; - - batch.name = pRenderNodeName; - batch.nBatches = nDrawcalls; - batch.nInstances = 1; - batch.nZpass = drawInfo.nZpass; - batch.nShadows = drawInfo.nShadows; - batch.nGeneral = drawInfo.nGeneral; - batch.nTransparent = drawInfo.nTransparent; - batch.nMisc = drawInfo.nMisc; - - BatchMapItor batchIter = batchMap.find(string(pRenderNodeName)); - - //already an entry for this stat obj - append details - if (batchIter != batchMap.end()) - { - BatchInfoPerPass& currentBatch = batchIter->second; - currentBatch += batch; - } - else - { - //insert new entry into map - std::pair newElem = batchMap.insert(BatchMapItor::value_type(string(pRenderNodeName), batch)); - BatchInfoPerPass& newBatch = newElem.first->second; - sortedBatchList.push_back(&newBatch); - } - - totalsMesh += batch; - } - - unknownDPs -= totalsMesh.nBatches; - - // - // Unknown counts (sceneDP - sum of batches) - // - //could be -ve or +ve (-ve for conditional rendering) - if (unknownDPs != 0) - { - static const char* s_strUnknown = "Unknown"; - static BatchInfoPerPass s_unknownBatch; - s_unknownBatch.Reset(); - s_unknownBatch.name = s_strUnknown; - s_unknownBatch.nBatches = max(0, unknownDPs); - s_unknownBatch.col.set(255, 255, 0, 255); - sortedBatchList.push_back(&s_unknownBatch); - } - - //Scene Totals - m_pTable->AddData(0, totalsScene.col, totalsScene.name); - m_pTable->AddData(1, totalsScene.col, "%d", totalsScene.nBatches); - m_pTable->AddData(2, totalsScene.col, "%d", totalsScene.nInstances); - m_pTable->AddData(3, totalsScene.col, "%d", totalsScene.nZpass); - m_pTable->AddData(4, totalsScene.col, "%d", totalsScene.nShadows); - m_pTable->AddData(5, totalsScene.col, "%d", totalsScene.nGeneral); - m_pTable->AddData(6, totalsScene.col, "%d", totalsScene.nTransparent); - m_pTable->AddData(7, totalsScene.col, "%d", totalsScene.nMisc); - - //Mesh Totals - m_pTable->AddData(0, totalsMesh.col, totalsMesh.name); - m_pTable->AddData(1, totalsMesh.col, "%d", totalsMesh.nBatches); - m_pTable->AddData(2, totalsMesh.col, "%d", totalsMesh.nInstances); - m_pTable->AddData(3, totalsMesh.col, "%d", totalsMesh.nZpass); - m_pTable->AddData(4, totalsMesh.col, "%d", totalsMesh.nShadows); - m_pTable->AddData(5, totalsMesh.col, "%d", totalsMesh.nGeneral); - m_pTable->AddData(6, totalsMesh.col, "%d", totalsMesh.nTransparent); - m_pTable->AddData(7, totalsMesh.col, "%d", totalsMesh.nMisc); - - - if (int nBatches = sortedBatchList.size()) - { - std::sort(sortedBatchList.begin(), sortedBatchList.end(), BatchInfoSortPerPass()); - - for (int i = 0; i < nBatches; i++) - { - BatchInfoPerPass* batch = sortedBatchList[i]; - - int nInstances = max(1, (int)batch->nInstances); - - m_pTable->AddData(0, batch->col, batch->name); - - //Due to different render meshes with the same name, averaged - //stats are a bit confusing, disabling for now - if constexpr (0 && batch->nInstances > 1) - { - m_pTable->AddData(1, batch->col, "%d (%d)", batch->nBatches, batch->nBatches / nInstances); - m_pTable->AddData(2, batch->col, "%d", batch->nInstances); - m_pTable->AddData(3, batch->col, "%d (%d)", batch->nZpass, batch->nZpass / nInstances); - m_pTable->AddData(4, batch->col, "%d (%d)", batch->nShadows, batch->nShadows / nInstances); - m_pTable->AddData(5, batch->col, "%d (%d)", batch->nGeneral, batch->nGeneral / nInstances); - m_pTable->AddData(6, batch->col, "%d (%d)", batch->nTransparent, batch->nTransparent / nInstances); - m_pTable->AddData(7, batch->col, "%d (%d)", batch->nMisc, batch->nMisc / nInstances); - } - else - { - m_pTable->AddData(1, batch->col, "%d", batch->nBatches); - m_pTable->AddData(2, batch->col, "%d", batch->nInstances); - m_pTable->AddData(3, batch->col, "%d", batch->nZpass); - m_pTable->AddData(4, batch->col, "%d", batch->nShadows); - m_pTable->AddData(5, batch->col, "%d", batch->nGeneral); - m_pTable->AddData(6, batch->col, "%d", batch->nTransparent); - m_pTable->AddData(7, batch->col, "%d", batch->nMisc); - } - } - } -#else - m_pTable->ClearTable(); - m_pTable->AddData(0, ColorB(255, 0, 0, 255), "Not supported in Release builds"); -#endif//RELEASE (DO_RENDERSTATS - not available in CrySystem) -} - -void CRenderBatchWidget::Update_ModeGpuTimes() -{ - m_pTable->ClearTable(); - m_pTable->AddData(0, ColorB(255, 0, 0, 255), "Not supported for this platform"); -} - - -#endif //USE_PERFHUD - diff --git a/Code/CryEngine/CrySystem/PerfHUD.h b/Code/CryEngine/CrySystem/PerfHUD.h deleted file mode 100644 index 27078eb3c6..0000000000 --- a/Code/CryEngine/CrySystem/PerfHUD.h +++ /dev/null @@ -1,478 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// Description : Button implementation in the MiniGUI - - -#ifndef CRYINCLUDE_CRYSYSTEM_PERFHUD_H -#define CRYINCLUDE_CRYSYSTEM_PERFHUD_H -#pragma once - - -#include - -#ifdef USE_PERFHUD - -#include -#include "MiniGUI/MiniInfoBox.h" -#include "MiniGUI/MiniTable.h" - -//Macros for console based widget control - -#define SET_WIDGET_DECL(WIDGET_NAME) \ - static int s_cvar_##WIDGET_NAME; \ - static void Set_##WIDGET_NAME##_Widget(ICVar * pCvar); - -#define SET_WIDGET_DEF(WIDGET_NAME, WIDGET_ID) \ - int CPerfHUD::s_cvar_##WIDGET_NAME = 0; \ - void CPerfHUD::Set_##WIDGET_NAME##_Widget(ICVar * pCvar) \ - { \ - ICryPerfHUD* pPerfHud = gEnv->pSystem->GetPerfHUD(); \ - if (pPerfHud) \ - { \ - int val = pCvar->GetIVal(); \ - if (val) \ - { \ - pPerfHud->SetState(eHudOutOfFocus); \ - pPerfHud->EnableWidget(ICryPerfHUDWidget::WIDGET_ID, val); \ - } \ - else \ - { \ - pPerfHud->DisableWidget(ICryPerfHUDWidget::WIDGET_ID); \ - } \ - } \ - } - -#define SET_WIDGET_COMMAND(COMMAND_NAME, WIDGET_NAME) \ - REGISTER_CVAR2_CB(COMMAND_NAME, &s_cvar_##WIDGET_NAME, 0, VF_ALWAYSONCHANGE, "", Set_##WIDGET_NAME##_Widget); - -////////////////////////////////////////////////////////////////////////// -// Root window all other controls derive from -class CPerfHUD - : public ICryPerfHUD - , public minigui::IMiniGUIEventListener - , public AzFramework::InputChannelEventListener -{ -public: - CRYINTERFACE_BEGIN() - CRYINTERFACE_ADD(ICryPerfHUD) - CRYINTERFACE_END() - CRYGENERATE_SINGLETONCLASS(CPerfHUD, "PerfHUD", 0x006945f9985e4ce2, 0x872120bfdec09ca5) - -public: - ////////////////////////////////////////////////////////////////////////// - // ICryPerfHUD implementation - ////////////////////////////////////////////////////////////////////////// - virtual void Init(); - virtual void Done(); - virtual void Draw(); - virtual void LoadBudgets(); - virtual void SaveStats(const char* filename); - virtual void ResetWidgets(); - virtual void Reset(); - virtual void Destroy(); - - //Set state through code (rather than using joypad input) - virtual void SetState(EHudState state); - - virtual void Show(bool bRestoreState); - - virtual void AddWidget(ICryPerfHUDWidget* pWidget); - virtual void RemoveWidget(ICryPerfHUDWidget* pWidget); - - ////////////////////////////////////////////////////////////////////////// - // Gui Creation helper funcs - ////////////////////////////////////////////////////////////////////////// - virtual minigui::IMiniCtrl* CreateMenu(const char* name, minigui::IMiniCtrl* pParent = NULL); - virtual bool CreateCVarMenuItem(minigui::IMiniCtrl* pMenu, const char* name, const char* controlVar, float controlVarOn, float controlVarOff); - virtual bool CreateCallbackMenuItem(minigui::IMiniCtrl* pMenu, const char* name, minigui::ClickCallback callback, void* pCallbackData); - virtual minigui::IMiniInfoBox* CreateInfoMenuItem(minigui::IMiniCtrl* pMenu, const char* name, minigui::RenderCallback renderCallback, const minigui::Rect& rect, bool onAtStart = false); - virtual minigui::IMiniTable* CreateTableMenuItem(minigui::IMiniCtrl* pMenu, const char* name); - - virtual minigui::IMiniCtrl* GetMenu(const char* name); - - virtual void EnableWidget(ICryPerfHUDWidget::EWidgetID id, int mode); - virtual void DisableWidget(ICryPerfHUDWidget::EWidgetID id); - - ////////////////////////////////////////////////////////////////////////// - // WARNINGS - Widget Specific Interface - ////////////////////////////////////////////////////////////////////////// - virtual void AddWarning(float duration, const char* fmt, va_list argList); - virtual bool WarningsWindowEnabled() const; - - ////////////////////////////////////////////////////////////////////////// - // FPS - Widget Specific Interface - ////////////////////////////////////////////////////////////////////////// - virtual const std::vector* GetFpsBuckets(float& totalTime) const; - - ////////////////////////////////////////////////////////////////////////// - // IMiniGUIEventListener implementation - ////////////////////////////////////////////////////////////////////////// - virtual void OnCommand(minigui::SCommand& cmd); - ////////////////////////////////////////////////////////////////////////// - - // AzFramework::InputChannelEventListener - bool OnInputChannelEventFiltered(const AzFramework::InputChannel& inputChannel) override; - AZ::s32 GetPriority() const override { return AzFramework::InputChannelEventListener::GetPriorityUI(); } - - ////////////////////////////////////////////////////////////////////////// - // CLICK CALLBACKS - ////////////////////////////////////////////////////////////////////////// - - static void ResetCallback(void* data, bool status); - static void ReloadBudgetsCallback(void* data, bool status); - static void SaveStatsCallback(void* data, bool status); - - ////////////////////////////////////////////////////////////////////////// - // RENDER CALLBACKS - ////////////////////////////////////////////////////////////////////////// - - static void DisplayRenderInfoCallback(const minigui::Rect& rect); - - ////////////////////////////////////////////////////////////////////////// - // CVAR CALLBACK - ////////////////////////////////////////////////////////////////////////// - - static void CVarChangeCallback(ICVar* pCvar); - - SET_WIDGET_DECL(Warnings); - SET_WIDGET_DECL(RenderSummary); - SET_WIDGET_DECL(RenderBatchStats); - SET_WIDGET_DECL(FpsBuckets); - SET_WIDGET_DECL(Particles); - SET_WIDGET_DECL(PakFile); - - ////////////////////////////////////////////////////////////////////////// - // Static Data - ////////////////////////////////////////////////////////////////////////// - - static const float OVERSCAN_X; - static const float OVERSCAN_Y; - - static const ColorB COL_NORM; - static const ColorB COL_WARN; - static const ColorB COL_ERROR; - - static const float TEXT_SIZE_NORM; - static const float TEXT_SIZE_WARN; - static const float TEXT_SIZE_ERROR; - - static const float ACTIVATE_TIME_FROM_GAME; - static const float ACTIVATE_TIME_FROM_HUD; - -protected: - void InitUI(minigui::IMiniGUI* pGUI); - void SetNextState(); - -protected: - - static int m_sys_perfhud; - static int m_sys_perfhud_pause; - - int m_sys_perfhud_prev; - - //record last menu position - float m_menuStartX; - float m_menuStartY; - - bool m_hudCreated; - - bool m_L1Pressed; - bool m_L2Pressed; - bool m_R1Pressed; - bool m_R2Pressed; - bool m_changingState; - bool m_hwMouseEnabled; - - float m_triggersDownStartTime; - - EHudState m_hudState; - EHudState m_hudLastState; - - typedef std::vector< _smart_ptr, stl::STLGlobalAllocator<_smart_ptr > >::iterator TWidgetIterator; - - std::vector< _smart_ptr, stl::STLGlobalAllocator<_smart_ptr > > m_widgets; - std::vector > m_rootMenus; -}; - -class CFpsWidget - : public ICryPerfHUDWidget -{ -public: - - CFpsWidget(minigui::IMiniCtrl* pParentMenu, ICryPerfHUD* pPerfHud); - - virtual void Reset(); - virtual void Update(); - virtual bool ShouldUpdate(); - virtual void LoadBudgets(XmlNodeRef perfXML); - virtual void SaveStats(XmlNodeRef statsXML); - virtual void Enable([[maybe_unused]] int mode) { m_pInfoBox->Hide(false); } - virtual void Disable() { m_pInfoBox->Hide(true); } - - void Init(); - - const std::vector* GetFpsBuckets(float& totalTime) const; - - static void ResetCallback(void* data, bool status); - -protected: - - static const uint32 NUM_FPS_BUCKETS_DEFAULT = 6; - - struct PerfBucketsStat - { - std::vector buckets; - float totalTime; - }; - - template - void UpdateBuckets(PerfBucketsStat& buckets, float frameTime, const char* name, float stat); - - // Data - static int m_cvarPerfHudFpsExclusive; - - enum EPerfBucketType - { - BUCKET_FPS = 0, - BUCKET_GPU, - BUCKET_DP, - BUCKET_TYPE_NUM - }; - - - PerfBucketsStat m_perfBuckets[BUCKET_TYPE_NUM]; - - float m_fpsBucketSize; - float m_fpsBudget; - float m_dpBudget; - float m_dpBucketSize; - - minigui::IMiniInfoBox* m_pInfoBox; -}; - -class CRenderStatsWidget - : public ICryPerfHUDWidget -{ -public: - - CRenderStatsWidget(minigui::IMiniCtrl* pParentMenu, ICryPerfHUD* pPerfHud); - - virtual void Reset() {} - virtual void Update(); - virtual bool ShouldUpdate(); - virtual void LoadBudgets(XmlNodeRef perfXML); - virtual void SaveStats(XmlNodeRef statsXML); - virtual void Enable([[maybe_unused]] int mode) { m_pInfoBox->Hide(false); } - virtual void Disable() { m_pInfoBox->Hide(true); } - -protected: - - //budgets - float m_fpsBudget; - uint32 m_dpBudget; - uint32 m_polyBudget; - uint32 m_postEffectBudget; - uint32 m_shadowCastBudget; - uint32 m_particlesBudget; - - //runtime data - struct SRuntimeData - { - Vec3 cameraPos; - Ang3 cameraRot; - float fps; - uint32 nDrawPrims; - uint32 nPolys; - uint32 nPostEffects; - uint32 nFwdLights; - uint32 nFwdShadowLights; - uint32 nDefLights; - uint32 nDefShadowLights; - uint32 nDefCubeMaps; - int nParticles; - bool hdrEnabled; - bool renderThreadEnabled; - }; - - SRuntimeData m_runtimeData; - minigui::IMiniInfoBox* m_pInfoBox; - ICryPerfHUD* m_pPerfHUD; - uint32 m_buildNum; -}; - -class CStreamingStatsWidget - : public ICryPerfHUDWidget -{ -public: - - CStreamingStatsWidget(minigui::IMiniCtrl* pParentMenu, ICryPerfHUD* pPerfHud); - - virtual void Reset() {} - virtual void Update(); - virtual bool ShouldUpdate(); - virtual void LoadBudgets(XmlNodeRef perfXML); - virtual void SaveStats(XmlNodeRef statsXML) {}; - virtual void Enable([[maybe_unused]] int mode) { m_pInfoBox->Hide(false); } - virtual void Disable() { m_pInfoBox->Hide(true); } - -protected: - //float m_maxMeshSizeArroundMB; - //float m_maxTextureSizeArroundMB; - minigui::IMiniInfoBox* m_pInfoBox; - ICryPerfHUD* m_pPerfHUD; -}; - - -class CWarningsWidget - : public ICryPerfHUDWidget -{ -public: - - CWarningsWidget(minigui::IMiniCtrl* pParentMenu, ICryPerfHUD* pPerfHud); - - virtual void Reset(); - virtual void Update(); - virtual bool ShouldUpdate(); - virtual void LoadBudgets(XmlNodeRef perfXML) {}; - virtual void SaveStats(XmlNodeRef statsXML); - virtual void Enable([[maybe_unused]] int mode) { m_pInfoBox->Hide(false); } - virtual void Disable() { m_pInfoBox->Hide(true); } - - void AddWarningV(float duration, const char* fmt, va_list argList); - void AddWarning(float duration, const char* warning); - -protected: - - static const uint32 WARNING_LENGTH = 64; - - struct SWarning - { - char text[WARNING_LENGTH]; - float remainingDuration; - }; - - minigui::IMiniInfoBox* m_pInfoBox; - - typedef std::vector< SWarning > TSWarnings; - - TSWarnings m_warnings; - - CryMT::queue m_threadWarnings; - - threadID m_nMainThreadId; -}; - -class CRenderBatchWidget - : public ICryPerfHUDWidget -{ -public: - - CRenderBatchWidget(minigui::IMiniCtrl* pParentMenu, ICryPerfHUD* pPerfHud); - - virtual void Reset(); - virtual void Update(); - virtual bool ShouldUpdate(); - virtual void LoadBudgets(XmlNodeRef perfXML) {}; - virtual void SaveStats(XmlNodeRef statsXML); - virtual void Enable(int mode); - virtual void Disable(); - - void Update_ModeGpuTimes(); - void Update_ModeBatchStats(); - -protected: - - struct BatchInfoGpuTimes - { - const char* name; - uint32 nBatches; - float gpuTime; - int numVerts; - int numIndices; - }; - - struct BatchInfoSortGpuTimes - { - inline bool operator() (const BatchInfoGpuTimes& lhs, const BatchInfoGpuTimes& rhs) const - { - return lhs.gpuTime > rhs.gpuTime; - } - }; - - struct BatchInfoPerPass - { - const char* name; - uint16 nBatches; - uint16 nInstances; - uint16 nZpass; - uint16 nShadows; - uint16 nGeneral; - uint16 nTransparent; - uint16 nMisc; - ColorB col; - - BatchInfoPerPass() - { - Reset(); - } - - void Reset() - { - name = NULL; - nBatches = 0; - nInstances = 0; - nZpass = 0; - nShadows = 0; - nGeneral = 0; - nTransparent = 0; - nMisc = 0; - col.set(255, 255, 255, 255); - } - - void operator += (const BatchInfoPerPass& rhs) - { - nBatches += rhs.nBatches; - nInstances += rhs.nInstances; - nZpass += rhs.nZpass; - nShadows += rhs.nShadows; - nGeneral += rhs.nGeneral; - nTransparent += rhs.nTransparent; - nMisc += rhs.nMisc; - } - }; - - struct BatchInfoSortPerPass - { - inline bool operator() (const BatchInfoPerPass* lhs, const BatchInfoPerPass* rhs) const - { - return lhs->nBatches > rhs->nBatches; - } - }; - - enum EDisplayMode - { - DISPLAY_MODE_NONE = 0, - DISPLAY_MODE_BATCH_STATS, - DISPLAY_MODE_GPU_TIMES, - DISPLAY_MODE_NUM, - }; - - minigui::IMiniTable* m_pTable; - ICVar* m_pRStatsCVar; - EDisplayMode m_displayMode; -}; - -#endif //USE_PERFHUD - -#endif // CRYINCLUDE_CRYSYSTEM_PERFHUD_H diff --git a/Code/CryEngine/CrySystem/ResourceManager.cpp b/Code/CryEngine/CrySystem/ResourceManager.cpp index 08a674136d..f78538760f 100644 --- a/Code/CryEngine/CrySystem/ResourceManager.cpp +++ b/Code/CryEngine/CrySystem/ResourceManager.cpp @@ -320,7 +320,6 @@ bool CResourceManager::LoadFastLoadPaks(bool bToMemory) } const char* const assetsDir = "@assets@"; - const char* shaderPakPath = "ShaderCacheStartup.pak"; #if defined(AZ_RESTRICTED_PLATFORM) #define AZ_RESTRICTED_SECTION RESOURCEMANAGER_CPP_SECTION_2 @@ -328,7 +327,6 @@ bool CResourceManager::LoadFastLoadPaks(bool bToMemory) #endif gEnv->pCryPak->OpenPacks(assetsDir, AZ::IO::PathString(FAST_LOADING_PAKS_SRC_FOLDER) + "*.pak", nPakPreloadFlags, &m_fastLoadPakPaths); - gEnv->pCryPak->OpenPack(assetsDir, shaderPakPath, AZ::IO::IArchive::FLAGS_PAK_IN_MEMORY | AZ::IO::INestedArchive::FLAGS_OVERRIDE_PAK); gEnv->pCryPak->OpenPack(assetsDir, "Engine.pak", AZ::IO::IArchive::FLAGS_PAK_IN_MEMORY); return !m_fastLoadPakPaths.empty(); } @@ -343,11 +341,6 @@ void CResourceManager::UnloadFastLoadPaks() gEnv->pCryPak->ClosePack(m_fastLoadPakPaths[i].c_str(), AZ::IO::IArchive::FLAGS_PATH_REAL); } m_fastLoadPakPaths.clear(); - - if (gEnv && gEnv->pRenderer) - { - gEnv->pRenderer->UnloadShaderStartupCache(); - } } ////////////////////////////////////////////////////////////////////////// @@ -712,23 +705,11 @@ void CResourceManager::OnSystemEvent(ESystemEvent event, [[maybe_unused]] UINT_P } } - //Load and precache frontend shader cache - if (g_cvars.archiveVars.nLoadFrontendShaderCache) - { - gEnv->pRenderer->LoadShaderLevelCache(); - gEnv->pRenderer->EF_Query(EFQ_SetShaderCombinations); - } - break; } case ESYSTEM_EVENT_LEVEL_LOAD_PREPARE: { - if (g_cvars.archiveVars.nLoadFrontendShaderCache) - { - gEnv->pRenderer->UnloadShaderLevelCache(); - } - if (!gEnv->bMultiplayer) { UnloadMenuCommonPak(FRONTEND_COMMON_PAK_FILENAME_SP, FRONTEND_COMMON_LIST_FILENAME "_sp"); diff --git a/Code/CryEngine/CrySystem/StreamEngine/StreamEngine.cpp b/Code/CryEngine/CrySystem/StreamEngine/StreamEngine.cpp index 37a7de8391..7f8c75b2a8 100644 --- a/Code/CryEngine/CrySystem/StreamEngine/StreamEngine.cpp +++ b/Code/CryEngine/CrySystem/StreamEngine/StreamEngine.cpp @@ -1211,20 +1211,9 @@ void CStreamEngine::TempFree(void* p, size_t nSize) namespace { #ifdef STREAMENGINE_ENABLE_STATS - void DrawText(const float x, const float y, ColorF c, const char* format, ...) + void DrawText(const float, const float, ColorF, const char*, ...) { - va_list args; - va_start(args, format); - - SDrawTextInfo ti; - ti.flags = eDrawText_FixedSize | eDrawText_2D | eDrawText_Monospace; - ti.xscale = ti.yscale = 1.2f; - ti.color[0] = c.r; - ti.color[1] = c.g; - ti.color[2] = c.b; - ti.color[3] = c.a; - gEnv->pRenderer->DrawTextQueued(Vec3(x, y, 1.0f), ti, format, args); - va_end(args); + // ToDo: Remove whole file with SPEC-343, or update to draw with Atom? Likely the former as I think this whole system is dead. } #endif diff --git a/Code/CryEngine/CrySystem/System.cpp b/Code/CryEngine/CrySystem/System.cpp index af9b674f6a..31eb286a17 100644 --- a/Code/CryEngine/CrySystem/System.cpp +++ b/Code/CryEngine/CrySystem/System.cpp @@ -127,7 +127,6 @@ LRESULT WINAPI WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) #include #include #include -#include "VisRegTest.h" #include #include @@ -135,8 +134,6 @@ LRESULT WINAPI WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) #include #include "XConsole.h" #include "Log.h" -#include "CrySizerStats.h" -#include "CrySizerImpl.h" #include "NotificationNetwork.h" #include "ProfileLog.h" @@ -153,7 +150,6 @@ LRESULT WINAPI WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) #include "ServerThrottle.h" #include "ResourceManager.h" #include "HMDBus.h" -#include "OverloadSceneManager/OverloadSceneManager.h" #include #include "IZLibCompressor.h" @@ -318,11 +314,6 @@ CSystem::CSystem(SharedEnvironmentInstance* pSharedEnvironment) m_pSystemEventDispatcher->RegisterListener(this); } -#ifdef WIN32 - m_hInst = NULL; - m_hWnd = NULL; -#endif - ////////////////////////////////////////////////////////////////////////// // Clear environment. ////////////////////////////////////////////////////////////////////////// @@ -357,7 +348,6 @@ CSystem::CSystem(SharedEnvironmentInstance* pSharedEnvironment) m_pIFont = NULL; m_pIFontUi = NULL; - m_pVisRegTest = NULL; m_rWidth = NULL; m_rHeight = NULL; m_rWidthAndHeightAsFractionOfScreenSize = NULL; @@ -368,7 +358,6 @@ CSystem::CSystem(SharedEnvironmentInstance* pSharedEnvironment) m_cvSSInfo = NULL; m_rStencilBits = NULL; m_rFullscreen = NULL; - m_rDriver = NULL; m_sysNoUpdate = NULL; m_pMemoryManager = NULL; m_pProcess = NULL; @@ -413,7 +402,6 @@ CSystem::CSystem(SharedEnvironmentInstance* pSharedEnvironment) m_pCpu = NULL; m_bInitializedSuccessfully = false; - m_bShaderCacheGenMode = false; m_bRelaunch = false; m_iLoadingMode = 0; m_bTestMode = false; @@ -430,9 +418,6 @@ CSystem::CSystem(SharedEnvironmentInstance* pSharedEnvironment) m_expectingMapCommand = false; #endif - // no mem stats at the moment - m_pMemStats = NULL; - m_pSizer = NULL; m_pCVarQuit = NULL; m_bForceNonDevMode = false; @@ -468,9 +453,6 @@ CSystem::CSystem(SharedEnvironmentInstance* pSharedEnvironment) InitThreadSystem(); - m_pMiniGUI = NULL; - m_pPerfHUD = NULL; - g_pPakHeap = new CMTSafeHeap; if (!AZ::AllocatorInstance::IsReady()) @@ -516,7 +498,6 @@ CSystem::~CSystem() CRY_ASSERT(m_windowMessageHandlers.empty() && "There exists a dangling window message handler somewhere"); - SAFE_DELETE(m_pVisRegTest); SAFE_DELETE(m_pXMLUtils); SAFE_DELETE(m_pArchiveHost); SAFE_DELETE(m_pThreadTaskManager); @@ -704,13 +685,6 @@ void CSystem::ShutDown() SAFE_RELEASE(m_pViewSystem); SAFE_RELEASE(m_pLevelSystem); - //Can't kill renderer before we delete CryFont, 3DEngine, etc - if (GetIRenderer()) - { - GetIRenderer()->ShutDown(); - SAFE_RELEASE(m_env.pRenderer); - } - if (m_env.pLog) { m_env.pLog->UnregisterConsoleVariables(); @@ -731,7 +705,6 @@ void CSystem::ShutDown() SAFE_RELEASE(m_cvSSInfo); SAFE_RELEASE(m_rStencilBits); SAFE_RELEASE(m_rFullscreen); - SAFE_RELEASE(m_rDriver); SAFE_RELEASE(m_sysWarnings); SAFE_RELEASE(m_sysKeyboard); @@ -751,13 +724,9 @@ void CSystem::ShutDown() SAFE_RELEASE(m_pNotificationNetwork); SAFE_DELETE(m_env.pSoftCodeMgr); - SAFE_DELETE(m_pMemStats); - SAFE_DELETE(m_pSizer); SAFE_DELETE(m_pDefaultValidator); m_pValidator = nullptr; - SAFE_DELETE(m_env.pOverloadSceneManager); - SAFE_DELETE(m_pLocalizationManager); //DebugStats(false, false);//true); @@ -816,11 +785,6 @@ void CSystem::Quit() m_pUserCallback->OnQuit(); } - if (GetIRenderer()) - { - GetIRenderer()->RestoreGamma(); - } - gEnv->pLog->FlushAndClose(); // Latest possible place to flush any pending messages to disk before the forceful termination. @@ -1229,8 +1193,6 @@ bool CSystem::UpdatePreTickBus(int updateFlags, int nPauseMode) } #endif //EXCLUDE_UPDATE_ON_CONSOLE - gEnv->pOverloadSceneManager->Update(); - #ifdef WIN32 // enable/disable SSE fp exceptions (#nan and /0) // need to do it each frame since sometimes they are being reset @@ -1242,12 +1204,6 @@ bool CSystem::UpdatePreTickBus(int updateFlags, int nPauseMode) m_nUpdateCounter++; #ifndef EXCLUDE_UPDATE_ON_CONSOLE - if (!m_sDelayedScreeenshot.empty()) - { - gEnv->pRenderer->ScreenShot(m_sDelayedScreeenshot.c_str()); - m_sDelayedScreeenshot.clear(); - } - // Check if game needs to be sleeping when not active. SleepIfInactive(); @@ -1278,27 +1234,6 @@ bool CSystem::UpdatePreTickBus(int updateFlags, int nPauseMode) #ifdef USE_REMOTE_CONSOLE GetIRemoteConsole()->Update(); #endif - - if (!gEnv->IsEditor() && gEnv->pRenderer) - { - // If the dimensions of the render target change, - // or are different from the camera defaults, - // we need to update the camera frustum. - CCamera& viewCamera = GetViewCamera(); - const int renderTargetWidth = m_rWidth->GetIVal(); - const int renderTargetHeight = m_rHeight->GetIVal(); - - if (renderTargetWidth != viewCamera.GetViewSurfaceX() || - renderTargetHeight != viewCamera.GetViewSurfaceZ()) - { - viewCamera.SetFrustum(renderTargetWidth, - renderTargetHeight, - viewCamera.GetFov(), - viewCamera.GetNearPlane(), - viewCamera.GetFarPlane(), - gEnv->pRenderer->GetPixelAspectRatio()); - } - } if (nPauseMode != 0) { m_bPaused = true; @@ -1346,53 +1281,6 @@ bool CSystem::UpdatePreTickBus(int updateFlags, int nPauseMode) m_pStreamEngine->Update(); } - if (g_cvars.az_streaming_stats) - { - SDrawTextInfo ti; - ti.flags = eDrawText_FixedSize | eDrawText_2D | eDrawText_Monospace; - ti.xscale = ti.yscale = 1.2f; - - const int viewportHeight = GetViewCamera().GetViewSurfaceZ(); - -#if defined(AZ_RESTRICTED_PLATFORM) - #define AZ_RESTRICTED_SECTION SYSTEM_CPP_SECTION_8 -#include AZ_RESTRICTED_FILE(System_cpp) -#else - float y = static_cast(viewportHeight) - 85.0f; -#endif - - AZStd::vector stats; - AZ::Interface::Get()->CollectStatistics(stats); - - for (AZ::IO::Statistic& stat : stats) - { - switch (stat.GetType()) - { - case AZ::IO::Statistic::Type::FloatingPoint: - gEnv->pRenderer->DrawTextQueued(Vec3(10, y, 1.0f), ti, - AZStd::string::format("%s/%s: %.3f", stat.GetOwner().data(), stat.GetName().data(), stat.GetFloatValue()).c_str()); - break; - case AZ::IO::Statistic::Type::Integer: - gEnv->pRenderer->DrawTextQueued(Vec3(10, y, 1.0f), ti, - AZStd::string::format("%s/%s: %lli", stat.GetOwner().data(), stat.GetName().data(), stat.GetIntegerValue()).c_str()); - break; - case AZ::IO::Statistic::Type::Percentage: - gEnv->pRenderer->DrawTextQueued(Vec3(10, y, 1.0f), ti, - AZStd::string::format("%s/%s: %.2f (percent)", stat.GetOwner().data(), stat.GetName().data(), stat.GetPercentage()).c_str()); - break; - default: - gEnv->pRenderer->DrawTextQueued(Vec3(10, y, 1.0f), ti, AZStd::string::format("Unsupported stat type: %i", static_cast(stat.GetType())).c_str()); - break; - } - y -= 12.0f; - if (y < 0.0f) - { - //Exit the loop because there's no purpose on rendering text outside of the visible area. - break; - } - } - } - #ifndef EXCLUDE_UPDATE_ON_CONSOLE if (m_bIgnoreUpdates) { @@ -1476,12 +1364,6 @@ bool CSystem::UpdatePreTickBus(int updateFlags, int nPauseMode) m_pServerThrottle->Update(); } - ////////////////////////////////////////////////////////////////////////// - if (m_env.pRenderer && m_env.pRenderer->GetIStereoRenderer()->IsRenderingToHMD()) - { - EBUS_EVENT(AZ::VR::HMDDeviceRequestBus, UpdateInternalState); - } - ////////////////////////////////////////////////////////////////////// //update console system if (m_env.pConsole) @@ -1527,6 +1409,7 @@ bool CSystem::UpdatePreTickBus(int updateFlags, int nPauseMode) ////////////////////////////////////////////////////////////////////////// // Update Threads Task Manager. ////////////////////////////////////////////////////////////////////////// + if (m_pThreadTaskManager) { FRAME_PROFILER("SysUpdate:ThreadTaskManager", this, PROFILE_SYSTEM); m_pThreadTaskManager->OnUpdate(); @@ -2000,12 +1883,6 @@ void CSystem::Relaunch(bool bRelaunch) SaveConfiguration(); } -////////////////////////////////////////////////////////////////////////// -ICrySizer* CSystem::CreateSizer() -{ - return new CrySizerImpl; -} - ////////////////////////////////////////////////////////////////////////// uint32 CSystem::GetUsedMemory() { @@ -2113,11 +1990,6 @@ void CSystem::ExecuteCommandLine(bool deferred) //gEnv->pConsole->ExecuteString("sys_RestoreSpec test*"); // to get useful debugging information about current spec settings to the log file } -void CSystem::DumpMemoryCoverage() -{ - m_MemoryFragmentationProfiler.DumpMemoryCoverage(); -} - ITextModeConsole* CSystem::GetITextModeConsole() { if (m_bDedicatedServer) diff --git a/Code/CryEngine/CrySystem/System.h b/Code/CryEngine/CrySystem/System.h index f5235f2ea8..5f87fd1ad1 100644 --- a/Code/CryEngine/CrySystem/System.h +++ b/Code/CryEngine/CrySystem/System.h @@ -26,7 +26,6 @@ #include "MTSafeAllocator.h" #include "CPUDetect.h" #include -#include "MemoryFragmentationProfiler.h" // CMemoryFragmentationProfiler #include "ThreadTask.h" #include "RenderBus.h" @@ -48,12 +47,6 @@ struct IZLibCompressor; class CWatchdogThread; class CThreadManager; -struct ICryPerfHUD; -namespace minigui -{ - struct IMiniGUI; -} - #if defined(AZ_RESTRICTED_PLATFORM) #undef AZ_RESTRICTED_SECTION #define SYSTEM_H_SECTION_1 1 @@ -214,7 +207,6 @@ namespace Audio } // namespace Audio struct SDefaultValidator; struct IDataProbe; -class CVisRegTest; #define PHSYICS_OBJECT_ENTITY 0 @@ -227,7 +219,6 @@ extern VTuneFunction VTPause; struct SSystemCVars { - int az_streaming_stats; int sys_streaming_requests_grouping_time_period; int sys_streaming_sleep; int sys_streaming_memory_budget; @@ -270,15 +261,6 @@ struct SSystemCVars int sys_error_debugbreak; int sys_FilesystemCaseSensitivity; - int sys_rendersplashscreen; - const char* sys_splashscreen; - - enum SplashScreenScaleMode - { - SplashScreenScaleMode_Fit = 0, - SplashScreenScaleMode_Fill - }; - int sys_splashScreenScaleMode; int sys_deferAudioUpdateOptim; #if USE_STEAM @@ -424,10 +406,6 @@ public: uint32 GetUsedMemory(); - virtual void DumpMemoryUsageStatistics(bool bUseKB); - virtual void DumpMemoryCoverage(); - void CollectMemInfo(SCryEngineStatsGlobalMemInfo&); - #ifndef _RELEASE virtual void GetCheckpointData(ICheckpointData& data); virtual void IncreaseCheckpointLoadCount(); @@ -444,7 +422,6 @@ public: void Quit(); bool IsQuitting() const; void ShutdownFileSystem(); // used to cleanup any file resources, such as cache handle. - bool IsShaderCacheGenMode() const { return m_bShaderCacheGenMode; } void SetAffinity(); virtual const char* GetUserName(); virtual int GetApplicationInstance(); @@ -452,7 +429,6 @@ public: virtual sUpdateTimes& GetCurrentUpdateTimeStats(); virtual const sUpdateTimes* GetUpdateTimeStats(uint32&, uint32&); - IRenderer* GetIRenderer(){ return m_env.pRenderer; } ITimer* GetITimer(){ return m_env.pTimer; } AZ::IO::IArchive* GetIPak() { return m_env.pCryPak; }; IConsole* GetIConsole() { return m_env.pConsole; }; @@ -472,16 +448,13 @@ public: IThreadTaskManager* GetIThreadTaskManager(); IResourceManager* GetIResourceManager(); ITextModeConsole* GetITextModeConsole(); - IFileChangeMonitor* GetIFileChangeMonitor() { return m_env.pFileChangeMonitor; } IVisualLog* GetIVisualLog() { return m_env.pVisualLog; } INotificationNetwork* GetINotificationNetwork() { return m_pNotificationNetwork; } IProfilingSystem* GetIProfilingSystem() { return &m_ProfilingSystem; } - ICryPerfHUD* GetPerfHUD() { return m_pPerfHUD; } IZLibCompressor* GetIZLibCompressor() { return m_pIZLibCompressor; } IZLibDecompressor* GetIZLibDecompressor() { return m_pIZLibDecompressor; } ILZ4Decompressor* GetLZ4Decompressor() { return m_pILZ4Decompressor; } IZStdDecompressor* GetZStdDecompressor() { return m_pIZStdDecompressor; } - WIN_HWND GetHWND(){ return m_hWnd; } ////////////////////////////////////////////////////////////////////////// // retrieves the perlin noise singleton instance CPNoise3* GetNoiseGen(); @@ -499,7 +472,6 @@ public: void SetIMaterialEffects(IMaterialEffects* pMaterialEffects) { m_env.pMaterialEffects = pMaterialEffects; } void SetIOpticsManager(IOpticsManager* pOpticsManager) { m_env.pOpticsManager = pOpticsManager; } - void SetIFileChangeMonitor(IFileChangeMonitor* pFileChangeMonitor) { m_env.pFileChangeMonitor = pFileChangeMonitor; } void SetIVisualLog(IVisualLog* pVisualLog) { m_env.pVisualLog = pVisualLog; } void DetectGameFolderAccessRights(); @@ -603,7 +575,6 @@ public: ////////////////////////////////////////////////////////////////////////// virtual int SetThreadState(ESubsystem subsys, bool bActive); - virtual ICrySizer* CreateSizer(); virtual bool IsPaused() const { return m_bPaused; }; virtual ILocalizationManager* GetLocalizationManager(); @@ -616,18 +587,6 @@ public: virtual ICryFactoryRegistry* GetCryFactoryRegistry() const; public: - // this enumeration describes the purpose for which the statistics is gathered. - // if it's gathered to be dumped, then some different rules may be applied - enum MemStatsPurposeEnum - { - nMSP_ForDisplay, nMSP_ForDump, nMSP_ForCrashLog, nMSP_ForBudget - }; - // collects the whole memory statistics into the given sizer object - void CollectMemStats (class ICrySizer* pSizer, MemStatsPurposeEnum nPurpose = nMSP_ForDisplay, std::vector* pStats = 0); - void GetExeSizes (ICrySizer* pSizer, MemStatsPurposeEnum nPurpose = nMSP_ForDisplay); - //! refreshes the m_pMemStats if necessary; creates it if it's not created - void TickMemStats(MemStatsPurposeEnum nPurpose = nMSP_ForDisplay, IResourceCollector* pResourceCollector = 0); - #if !defined(RELEASE) void SetVersionInfo(const char* const szVersion); #endif @@ -680,7 +639,6 @@ private: ////////////////////////////////////////////////////////////////////////// // Helper functions. ////////////////////////////////////////////////////////////////////////// - void CreateRendererVars(const SSystemInitParams& startupParams); void CreateSystemVars(); void CreateAudioVars(); @@ -755,23 +713,9 @@ public: CCpuFeatures* GetCPUFeatures() { return m_pCpu; }; - string& GetDelayedScreeenshot() {return m_sDelayedScreeenshot; } - - CVisRegTest*& GetVisRegTestPtrRef() {return m_pVisRegTest; } - const CTimeValue& GetLastTickTime(void) const { return m_lastTickTime; } const ICVar* GetDedicatedMaxRate(void) const { return m_svDedicatedMaxRate; } - const char* GetRenderingDriverName(void) const - { - if(m_rDriver) - { - return m_rDriver->GetString(); - } - return nullptr; - } - - std::shared_ptr CreateLocalFileIO(); // Gets the dimensions (in pixels) of the primary physical display. @@ -787,7 +731,6 @@ private: // ------------------------------------------------------ CTimer m_Time; //!< CCamera m_ViewCamera; //!< bool m_bInitializedSuccessfully; //!< true if the system completed all initialization steps - bool m_bShaderCacheGenMode;//!< true if the application runs in shader cache generation mode bool m_bRelaunch; //!< relaunching the app or not (true beforerelaunch) int m_iLoadingMode; //!< Game is loading w/o changing context (0 not, 1 quickloading, 2 full loading) bool m_bTestMode; //!< If running in testing mode. @@ -804,7 +747,6 @@ private: // ------------------------------------------------------ bool m_bInDevMode; //!< Set to true if was in dev mode. bool m_bGameFolderWritable;//!< True when verified that current game folder have write access. SDefaultValidator* m_pDefaultValidator; //!< - string m_sDelayedScreeenshot;//!< to delay a screenshot call for a frame CCpuFeatures* m_pCpu; //!< CPU features int m_ttMemStatSS; //!< Time to memstat screenshot string m_szCmdLine; @@ -917,7 +859,6 @@ private: // ------------------------------------------------------ ICVar* m_rFullscreen; ICVar* m_rFullscreenWindow; ICVar* m_rFullscreenNativeRes; - ICVar* m_rDriver; ICVar* m_rDisplayInfo; ICVar* m_rOverscanBordersDrawDebugView; ICVar* m_sysNoUpdate; @@ -966,17 +907,6 @@ private: // ------------------------------------------------------ ILoadConfigurationEntrySink* m_pCVarsWhitelistConfigSink; #endif // defined(CVARS_WHITELIST) - WIN_HWND m_hWnd; - WIN_HINSTANCE m_hInst; - - // this is the memory statistics that is retained in memory between frames - // in which it's not gathered - class CrySizerStats* m_pMemStats; - class CrySizerImpl* m_pSizer; - - ICryPerfHUD* m_pPerfHUD; - minigui::IMiniGUI* m_pMiniGUI; - //int m_nCurrentLogVerbosity; SFileVersion m_fileVersion; @@ -1085,7 +1015,6 @@ protected: // ------------------------------------------------------------- ILoadingProgressListener* m_pProgressListener; CCmdLine* m_pCmdLine; - CVisRegTest* m_pVisRegTest; CThreadManager* m_pThreadManager; CThreadTaskManager* m_pThreadTaskManager; class CResourceManager* m_pResourceManager; @@ -1097,8 +1026,6 @@ protected: // ------------------------------------------------------------- std::vector< std::pair > m_updateTimes; - CMemoryFragmentationProfiler m_MemoryFragmentationProfiler; - struct SErrorMessage { string m_Message; diff --git a/Code/CryEngine/CrySystem/SystemInit.cpp b/Code/CryEngine/CrySystem/SystemInit.cpp index 22445ec4a5..83ef4fcd2b 100644 --- a/Code/CryEngine/CrySystem/SystemInit.cpp +++ b/Code/CryEngine/CrySystem/SystemInit.cpp @@ -95,7 +95,6 @@ #include #include #include -#include "HMDCVars.h" #include #include @@ -112,7 +111,6 @@ #include "SystemCFG.h" #include "AutoDetectSpec.h" #include "ResourceManager.h" -#include "VisRegTest.h" #include "MTSafeAllocator.h" #include "NotificationNetwork.h" #include "ExtensionSystem/CryFactoryRegistryImpl.h" @@ -123,7 +121,6 @@ #include "ZLibDecompressor.h" #include "ZStdDecompressor.h" #include "LZ4Decompressor.h" -#include "OverloadSceneManager/OverloadSceneManager.h" #include "ServiceNetwork.h" #include "RemoteCommand.h" #include "LevelSystem/LevelSystem.h" @@ -134,9 +131,6 @@ #include #include -#include "PerfHUD.h" -#include "MiniGUI/MiniGUI.h" - #if USE_STEAM #include "Steamworks/public/steam/steam_api.h" #include "Steamworks/public/steam/isteamremotestorage.h" @@ -740,28 +734,6 @@ static void LoadDetectedSpec(ICVar* pVar) GetISystem()->LoadConfiguration("editor.cfg"); } - bool bMultiGPUEnabled = false; - if (gEnv->pRenderer) - { - gEnv->pRenderer->EF_Query(EFQ_MultiGPUEnabled, bMultiGPUEnabled); - -#if defined(AZ_PLATFORM_ANDROID) - AZStd::string gpuConfigFile; - const AZStd::string& adapterDesc = gEnv->pRenderer->GetAdapterDescription(); - const AZStd::string& apiver = gEnv->pRenderer->GetApiVersion(); - - if (!adapterDesc.empty()) - { - MobileSysInspect::GetSpecForGPUAndAPI(adapterDesc, apiver, gpuConfigFile); - GetISystem()->LoadConfiguration(gpuConfigFile.c_str(), pSysSpecOverrideSinkConsole); - } -#endif - } - if (bMultiGPUEnabled) - { - GetISystem()->LoadConfiguration("mgpu.cfg"); - } - // override cvars just loaded based on current API version/GPU GetISystem()->SetConfigSpec(static_cast(spec), platform, false); @@ -1279,7 +1251,7 @@ void CSystem::ShutdownFileSystem() } ///////////////////////////////////////////////////////////////////////////////// -bool CSystem::InitFileSystem_LoadEngineFolders(const SSystemInitParams& initParams) +bool CSystem::InitFileSystem_LoadEngineFolders(const SSystemInitParams&) { LOADING_TIME_PROFILE_SECTION; { @@ -1320,10 +1292,6 @@ bool CSystem::InitFileSystem_LoadEngineFolders(const SSystemInitParams& initPara static const char* g_additionalConfig = gEnv->IsDedicated() ? "server_cfg" : "client_cfg"; LoadConfiguration(g_additionalConfig, nullptr, false); - if (initParams.bShaderCacheGen) - { - LoadConfiguration("shadercachegen.cfg"); - } // We do not use CVar groups on the consoles AddCVarGroupDirectory("Config/CVarGroups"); @@ -1359,7 +1327,6 @@ bool CSystem::InitAudioSystem(const SSystemInitParams& initParams) bool useRealAudioSystem = false; if (!initParams.bPreview - && !initParams.bShaderCacheGen && !initParams.bMinimal && !m_bDedicatedServer && m_sys_audio_disable->GetIVal() == 0) @@ -1859,7 +1826,6 @@ bool CSystem::Init(const SSystemInitParams& startupParams) m_env.bTesting = startupParams.bTesting; m_env.bNoAssertDialog = startupParams.bTesting; m_env.bNoRandomSeed = startupParams.bNoRandom; - m_bShaderCacheGenMode = startupParams.bShaderCacheGen; m_bNoCrashDialog = gEnv->IsDedicated(); @@ -1938,9 +1904,6 @@ AZ_POP_DISABLE_WARNING QueryVersionInfo(); DetectGameFolderAccessRights(); - m_hInst = (WIN_HINSTANCE)startupParams.hInstance; - m_hWnd = (WIN_HWND)startupParams.hWnd; - m_bEditor = startupParams.bEditor; m_bPreviewMode = startupParams.bPreview; m_bTestMode = startupParams.bTestMode; @@ -2226,11 +2189,6 @@ AZ_POP_DISABLE_WARNING InlineInitializationProcessing("CSystem::Init Create console"); - if (!startupParams.bSkipRenderer) - { - CreateRendererVars(startupParams); - } - // Need to load the engine.pak that includes the config files needed during initialization m_env.pCryPak->OpenPack("@assets@", "Engine.pak"); #if defined(AZ_PLATFORM_ANDROID) || defined(AZ_PLATFORM_IOS) @@ -2305,17 +2263,6 @@ AZ_POP_DISABLE_WARNING // Optional user defined overrides LoadConfiguration("user.cfg", pCVarsWhiteListConfigSink); - if (!startupParams.bSkipRenderer) - { - // Load the hmd.cfg if it exists. This will enable optional stereo rendering. - LoadConfiguration("hmd.cfg"); - } - - if (startupParams.bShaderCacheGen) - { - LoadConfiguration("shadercachegen.cfg", pCVarsWhiteListConfigSink); - } - #if defined(ENABLE_STATS_AGENT) if (m_pCmdLine->FindArg(eCLAT_Pre, "useamblecfg")) { @@ -2365,30 +2312,6 @@ AZ_POP_DISABLE_WARNING InlineInitializationProcessing("CSystem::Init LoadConfigurations"); - m_env.pOverloadSceneManager = new COverloadSceneManager; - - if (m_bDedicatedServer && m_rDriver) - { - m_sSavedRDriver = m_rDriver->GetString(); - m_rDriver->Set("NULL"); - } - -#if defined(WIN32) || defined(WIN64) - if (!startupParams.bSkipRenderer) - { - if (azstricmp(m_rDriver->GetString(), "Auto") == 0) - { - m_rDriver->Set("DX11"); - } - } - - if (gEnv->IsEditor() && azstricmp(m_rDriver->GetString(), "DX12") == 0) - { - AZ_Warning(AZ_TRACE_SYSTEM_WINDOW, false, "DX12 mode is not supported in the editor. Reverting to DX11 mode."); - m_rDriver->Set("DX11"); - } -#endif - #ifdef WIN32 if ((g_cvars.sys_WER) && (!startupParams.bMinimal)) { @@ -2410,72 +2333,6 @@ AZ_POP_DISABLE_WARNING m_thermalInfoHandler = AZStd::make_unique(); #endif - if (g_cvars.sys_rendersplashscreen && !startupParams.bEditor && !startupParams.bShaderCacheGen) - { - if (m_env.pRenderer) - { - LOADING_TIME_PROFILE_SECTION_NAMED("Rendering Splash Screen"); - ITexture* pTex = m_env.pRenderer->EF_LoadTexture(g_cvars.sys_splashscreen, FT_DONT_STREAM | FT_NOMIPS | FT_USAGE_ALLOWREADSRGB); - //check the width and height as extra verification hack. This texture is loaded before the replace me, so there is - //no backup if it fails to load. - if (pTex && pTex->GetWidth() && pTex->GetHeight()) - { - const int splashWidth = pTex->GetWidth(); - const int splashHeight = pTex->GetHeight(); - - const int screenWidth = m_env.pRenderer->GetOverlayWidth(); - const int screenHeight = m_env.pRenderer->GetOverlayHeight(); - - const float scaleX = (float)screenWidth / (float)splashWidth; - const float scaleY = (float)screenHeight / (float)splashHeight; - - float scale = 1.0f; - switch (g_cvars.sys_splashScreenScaleMode) - { - case SSystemCVars::SplashScreenScaleMode_Fit: - { - scale = AZStd::GetMin(scaleX, scaleY); - } - break; - case SSystemCVars::SplashScreenScaleMode_Fill: - { - scale = AZStd::GetMax(scaleX, scaleY); - } - break; - } - - const float w = splashWidth * scale; - const float h = splashHeight * scale; - const float x = (screenWidth - w) * 0.5f; - const float y = (screenHeight - h) * 0.5f; - - const float vx = (800.0f / (float) screenWidth); - const float vy = (600.0f / (float) screenHeight); - - m_env.pRenderer->SetViewport(0, 0, screenWidth, screenHeight); - -#if defined(AZ_PLATFORM_IOS) || defined(AZ_PLATFORM_MAC) - // Pump system events in order to update the screen - AzFramework::ApplicationRequests::Bus::Broadcast(&AzFramework::ApplicationRequests::PumpSystemEventLoopUntilEmpty); -#endif - - pTex->Release(); - } - - #if defined(AZ_PLATFORM_ANDROID) - bool engineSplashEnabled = (g_cvars.sys_rendersplashscreen != 0); - if (engineSplashEnabled) - { - AZ::Android::Utils::DismissSplashScreen(); - } - #endif - } - else - { - AZ_Warning(AZ_TRACE_SYSTEM_WINDOW, false, "Could not load startscreen image: %s.", g_cvars.sys_splashscreen); - } - } - ////////////////////////////////////////////////////////////////////////// // Open basic pak files after intro movie playback started ////////////////////////////////////////////////////////////////////////// @@ -2507,21 +2364,6 @@ AZ_POP_DISABLE_WARNING m_pUserCallback->OnInitProgress("First time asset processing - may take a minute..."); } - ////////////////////////////////////////////////////////////////////////// - // POST RENDERER - ////////////////////////////////////////////////////////////////////////// - if (!startupParams.bSkipRenderer && m_env.pRenderer) - { - m_env.pRenderer->PostInit(); - - if (!startupParams.bShaderCacheGen) - { - // try to do a flush to keep the renderer busy during loading - m_env.pRenderer->TryFlush(); - } - } - InlineInitializationProcessing("CSystem::Init Renderer::PostInit"); - #ifdef SOFTCODE_SYSTEM_ENABLED m_env.pSoftCodeMgr = new SoftCodeMgr(); #else @@ -2537,10 +2379,8 @@ AZ_POP_DISABLE_WARNING // - System cursor has to be enabled manually by the Game if needed; the custom UiCursor will typically be used instead if (!gEnv->IsDedicated() && - m_env.pRenderer && !gEnv->IsEditor() && - !startupParams.bTesting && - !m_pCmdLine->FindArg(eCLAT_Pre, "nomouse")) + !startupParams.bTesting) { AzFramework::InputSystemCursorRequestBus::Event(AzFramework::InputDeviceMouse::Id, &AzFramework::InputSystemCursorRequests::SetSystemCursorState, @@ -2561,7 +2401,7 @@ AZ_POP_DISABLE_WARNING ////////////////////////////////////////////////////////////////////////// // UI. Should be after input and hardware mouse ////////////////////////////////////////////////////////////////////////// - if (!startupParams.bShaderCacheGen && !m_bDedicatedServer) + if (!m_bDedicatedServer) { AZ_Printf(AZ_TRACE_SYSTEM_WINDOW, "UI system initialization"); INDENT_LOG_DURING_SCOPE(); @@ -2573,21 +2413,6 @@ AZ_POP_DISABLE_WARNING InlineInitializationProcessing("CSystem::Init InitShine"); - ////////////////////////////////////////////////////////////////////////// - // Create MiniGUI - ////////////////////////////////////////////////////////////////////////// - if (!startupParams.bMinimal) - { - minigui::IMiniGUIPtr pMiniGUI; - if (CryCreateClassInstanceForInterface(cryiidof(), pMiniGUI)) - { - m_pMiniGUI = pMiniGUI.get(); - m_pMiniGUI->Init(); - } - } - - InlineInitializationProcessing("CSystem::Init InitMiniGUI"); - ////////////////////////////////////////////////////////////////////////// // CONSOLE ////////////////////////////////////////////////////////////////////////// @@ -2612,62 +2437,6 @@ AZ_POP_DISABLE_WARNING m_env.pRemoteCommandManager = new CRemoteCommandManager(); } - ////////////////////////////////////////////////////////////////////////// - - ////////////////////////////////////////////////////////////////////////// - // VR SYSTEM INITIALIZATION - ////////////////////////////////////////////////////////////////////////// - if ((!startupParams.bSkipRenderer) && (!startupParams.bMinimal)) - { - if (m_pUserCallback) - { - m_pUserCallback->OnInitProgress("Initializing VR Systems..."); - } - - AZStd::vector devices; - AZ::VR::HMDInitRequestBus::EnumerateHandlers([&devices](AZ::VR::HMDInitBus* device) - { - devices.emplace_back(device); - return true; - }); - - // Order the devices so that devices that only support one type of HMD are ordered first as we want - // to use any device-specific drivers over more general ones. - std::sort(devices.begin(), devices.end(), [](AZ::VR::HMDInitBus* left, AZ::VR::HMDInitBus* right) - { - return left->GetInitPriority() > right->GetInitPriority(); - }); - - //Start up a job to init the HMDs since they may take a while to start up - AZ::JobContext* jobContext = nullptr; - EBUS_EVENT_RESULT(jobContext, AZ::JobManagerBus, GetGlobalContext); - AZ::Job* hmdJob = AZ::CreateJobFunction([devices]() - { - // Loop through the attached devices and attempt to initialize them. We'll use the first - // one that succeeds since we currently only support a single HMD. - for (AZ::VR::HMDInitBus* device : devices) - { - if (device->AttemptInit()) - { - // At this point if any device connected to the HMDDeviceRequestBus then we are good to go for VR. - EBUS_EVENT(AZ::VR::HMDDeviceRequestBus, OutputHMDInfo); - EBUS_EVENT(AZ::VR::HMDDeviceRequestBus, EnableDebugging, false); - - // Since this was a job and we may have beaten the level's output_to_hmd cvar initialization - // We just want to retrigger the callback to this cvar - ICVar* outputToHMD = gEnv->pConsole->GetCVar("output_to_hmd"); - if (outputToHMD != nullptr) - { - int outputToHMDVal = gEnv->pConsole->GetCVar("output_to_hmd")->GetIVal(); - gEnv->pConsole->GetCVar("output_to_hmd")->Set(outputToHMDVal); - } - break; - } - } - }, true, jobContext); - hmdJob->Start(); - } - if (m_pUserCallback) { m_pUserCallback->OnInitProgress("Initializing additional systems..."); @@ -2724,28 +2493,10 @@ AZ_POP_DISABLE_WARNING m_pIZStdDecompressor = new CZStdDecompressor(); InlineInitializationProcessing("CSystem::Init ZStdDecompressor"); - ////////////////////////////////////////////////////////////////////////// - // Create PerfHUD - ////////////////////////////////////////////////////////////////////////// - -#if defined(USE_PERFHUD) - if (!gEnv->bTesting && !gEnv->IsInToolMode()) - { - //Create late in Init so that associated CVars have already been created - ICryPerfHUDPtr pPerfHUD; - if (CryCreateClassInstanceForInterface(cryiidof(), pPerfHUD)) - { - m_pPerfHUD = pPerfHUD.get(); - m_pPerfHUD->Init(); - } - } -#endif - ////////////////////////////////////////////////////////////////////////// // Initialize task threads. ////////////////////////////////////////////////////////////////////////// - if (!startupParams.bSkipRenderer) { m_pThreadTaskManager->InitThreads(); @@ -2775,12 +2526,6 @@ AZ_POP_DISABLE_WARNING AZ::Interface::Get()->VisitRegisteredFunctors([](AZ::ConsoleFunctorBase* functor) { AzConsoleToCryConsoleBinder::Visit(functor); }); AzConsoleToCryConsoleBinder::s_commandRegisteredHandler.Connect(AZ::Interface::Get()->GetConsoleCommandRegisteredEvent()); - // final tryflush to be sure that all framework init request have been processed - if (!startupParams.bShaderCacheGen && m_env.pRenderer) - { - m_env.pRenderer->TryFlush(); - } - if (g_cvars.sys_float_exceptions > 0) { if (g_cvars.sys_float_exceptions == 3 && gEnv->IsEditor()) // Turn off float exceptions in editor if sys_float_exceptions = 3 @@ -2874,99 +2619,6 @@ static string ConcatPath(const char* szPart1, const char* szPart2) return ret; } -static void ScreenshotCmd(IConsoleCmdArgs* pParams) -{ - assert(pParams); - - uint32 dwCnt = pParams->GetArgCount(); - - if (dwCnt <= 1) - { - if (!gEnv->IsEditing()) - { - // open console one line only - - //line should lie within title safe area, so calculate overscan border - Vec2 overscanBorders = Vec2(0.0f, 0.0f); - gEnv->pRenderer->EF_Query(EFQ_OverscanBorders, overscanBorders); - float yDelta = /*((float)gEnv->pRenderer->GetHeight())*/ 600.0f * overscanBorders.y; - - //set console height depending on top/bottom overscan border - gEnv->pConsole->ShowConsole(true, (int)(16 + yDelta)); - gEnv->pConsole->SetInputLine("Screenshot "); - } - else - { - gEnv->pLog->LogWithType(ILog::eInputResponse, "Screenshot missing - no screenshot was done"); - } - } - else - { - static int iScreenshotNumber = -1; - - const char* szPrefix = "Screenshot"; - uint32 dwPrefixSize = strlen(szPrefix); - - char path[AZ::IO::IArchive::MaxPath]; - path[sizeof(path) - 1] = 0; - gEnv->pCryPak->AdjustFileName("@user@/ScreenShots", path, AZ_ARRAY_SIZE(path), AZ::IO::IArchive::FLAGS_PATH_REAL | AZ::IO::IArchive::FLAGS_FOR_WRITING); - - if (iScreenshotNumber == -1) // first time - find max number to start - { - auto pCryPak = gEnv->pCryPak; - - AZ::IO::ArchiveFileIterator handle = pCryPak->FindFirst((string(path) + "/*").c_str()); // mastercd folder - if (handle) - { - do - { - int iCurScreenshotNumber; - - if (_strnicmp(handle.m_filename.data(), szPrefix, dwPrefixSize) == 0) - { - int iCnt = azsscanf(handle.m_filename.data() + dwPrefixSize, "%d", &iCurScreenshotNumber); - - if (iCnt) - { - iScreenshotNumber = max(iCurScreenshotNumber, iScreenshotNumber); - } - } - - handle = pCryPak->FindNext(handle); - } while (handle); - pCryPak->FindClose(handle); - } - } - - ++iScreenshotNumber; - - char szNumber[16]; - azsprintf(szNumber, "%.4d ", iScreenshotNumber); - - string sScreenshotName = string(szPrefix) + szNumber; - - for (uint32 dwI = 1; dwI < dwCnt; ++dwI) - { - if (dwI > 1) - { - sScreenshotName += "_"; - } - - sScreenshotName += pParams->GetArg(dwI); - } - - sScreenshotName.replace("\\", "_"); - sScreenshotName.replace("/", "_"); - sScreenshotName.replace(":", "_"); - sScreenshotName.replace(".", "_"); - - gEnv->pConsole->ShowConsole(false); - - CSystem* pCSystem = (CSystem*)(gEnv->pSystem); - pCSystem->GetDelayedScreeenshot() = string(path) + "/" + sScreenshotName;// to delay a screenshot call for a frame - } -} - // Helper to maintain backwards compatibility with our CVar but not force our new code to // pull in CryCommon by routing through an environment variable void CmdSetAwsLogLevel(IConsoleCmdArgs* pArgs) @@ -3182,18 +2834,6 @@ void ChangeLogAllocations(ICVar* pVal) } } -static void VisRegTest(IConsoleCmdArgs* pParams) -{ - CSystem* pCSystem = (CSystem*)(gEnv->pSystem); - CVisRegTest*& visRegTest = pCSystem->GetVisRegTestPtrRef(); - if (!visRegTest) - { - visRegTest = new CVisRegTest(); - } - - visRegTest->Init(pParams); -} - ////////////////////////////////////////////////////////////////////////// void CSystem::CreateSystemVars() { @@ -3278,28 +2918,10 @@ void CSystem::CreateSystemVars() attachVariable("sys_PakLogAllFileAccess", &g_cvars.archiveVars.nLogAllFileAccess, "Log all file access allowing you to easily see whether a file has been loaded directly, or which pak file."); #endif attachVariable("sys_PakValidateFileHash", &g_cvars.archiveVars.nValidateFileHashes, "Validate file hashes in pak files for collisions"); - attachVariable("sys_LoadFrontendShaderCache", &g_cvars.archiveVars.nLoadFrontendShaderCache, "Load frontend shader cache (on/off)"); attachVariable("sys_UncachedStreamReads", &g_cvars.archiveVars.nUncachedStreamReads, "Enable stream reads via an uncached file handle"); attachVariable("sys_PakDisableNonLevelRelatedPaks", &g_cvars.archiveVars.nDisableNonLevelRelatedPaks, "Disables all paks that are not required by specific level; This is used with per level splitted assets."); attachVariable("sys_PakWarnOnPakAccessFailures", &g_cvars.archiveVars.nWarnOnPakAccessFails, "If 1, access failure for Paks is treated as a warning, if zero it is only a log message."); - - { - int nDefaultRenderSplashScreen = 1; -#if defined(AZ_RESTRICTED_PLATFORM) -#define AZ_RESTRICTED_SECTION SYSTEMINIT_CPP_SECTION_10 -#include AZ_RESTRICTED_FILE(SystemInit_cpp) -#endif - REGISTER_CVAR2("sys_rendersplashscreen", &g_cvars.sys_rendersplashscreen, nDefaultRenderSplashScreen, VF_NULL, - "Render the splash screen during game initialization"); - REGISTER_CVAR2("sys_splashscreenscalemode", &g_cvars.sys_splashScreenScaleMode, static_cast(SSystemCVars::SplashScreenScaleMode_Fill), VF_NULL, - "0 - scale to fit (letterbox)\n" - "1 - scale to fill (cropped)\n" - "Default is 1"); - REGISTER_CVAR2("sys_splashscreen", &g_cvars.sys_splashscreen, "EngineAssets/Textures/startscreen.tif", VF_NULL, - "The splash screen to render during game initialization"); - } - static const int fileSystemCaseSensitivityDefault = 0; REGISTER_CVAR2("sys_FilesystemCaseSensitivity", &g_cvars.sys_FilesystemCaseSensitivity, fileSystemCaseSensitivityDefault, VF_NULL, "0 - CryPak lowercases all input file names\n" @@ -3452,10 +3074,6 @@ void CSystem::CreateSystemVars() REGISTER_CVAR2("sys_streaming_max_finalize_per_frame", &g_cvars.sys_streaming_max_finalize_per_frame, 0, VF_NULL, "Maximum stream finalizing calls per frame to reduce the CPU impact on main thread (0 to disable)"); REGISTER_CVAR2("sys_streaming_max_bandwidth", &g_cvars.sys_streaming_max_bandwidth, 0, VF_NULL, "Enables capping of max streaming bandwidth in MB/s"); - REGISTER_CVAR2("az_streaming_stats", &g_cvars.az_streaming_stats, 0, VF_NULL, "Show stats from AZ::IO::Streamer\n" - "0=off\n" - "1=on\n" - ); REGISTER_CVAR2("sys_streaming_debug", &g_cvars.sys_streaming_debug, 0, VF_NULL, "Enable streaming debug information\n" "0=off\n" "1=Streaming Stats\n" @@ -3580,12 +3198,6 @@ void CSystem::CreateSystemVars() m_env.pConsole->CreateKeyBind("alt_keyboard_key_function_F12", "Screenshot"); m_env.pConsole->CreateKeyBind("alt_keyboard_key_function_F11", "RecordClip"); - // screenshot functionality in system as console - REGISTER_COMMAND("Screenshot", &ScreenshotCmd, VF_BLOCKFRAME, - "Create a screenshot with annotation\n" - "e.g. Screenshot beach scene with shark\n" - "Usage: Screenshot "); - /* // experimental feature? - needs to be created very early m_sys_filecache = REGISTER_INT("sys_FileCache",0,0, @@ -3606,9 +3218,6 @@ void CSystem::CreateSystemVars() "'test*' and 'info' log to the log file only\n" "Usage: sys_RestoreSpec [test|test*|apply|info]"); - REGISTER_COMMAND("VisRegTest", &VisRegTest, 0, "Run visual regression test.\n" - "Usage: VisRegTest [=test] [=visregtest.xml] [quit=false]"); - #if defined(WIN32) REGISTER_CVAR2("sys_display_threads", &g_cvars.sys_display_threads, 0, 0, "Displays Thread info"); #elif defined(AZ_RESTRICTED_PLATFORM) @@ -3629,9 +3238,6 @@ void CSystem::CreateSystemVars() REGISTER_CVAR2("sys_error_debugbreak", &g_cvars.sys_error_debugbreak, 0, VF_CHEAT, "__debugbreak() if a VALIDATOR_ERROR_DBGBREAK message is hit"); - // [VR] - AZ::VR::HMDCVars::Register(); - REGISTER_STRING("dlc_directory", "", 0, "Holds the path to the directory where DLC should be installed to and read from"); #if defined(MAP_LOADING_SLICING) @@ -3694,11 +3300,6 @@ void CSystem::AddCVarGroupDirectory(const string& sPath) string sCVarName = sFilePath; PathUtil::RemoveExtension(sCVarName); - - if (m_env.pConsole != 0) - { - ((CXConsole*)m_env.pConsole)->RegisterCVarGroup(PathUtil::GetFile(sCVarName), sFilePath); - } } } while (handle = gEnv->pCryPak->FindNext(handle)); diff --git a/Code/CryEngine/CrySystem/SystemRender.cpp b/Code/CryEngine/CrySystem/SystemRender.cpp index 68045a86ea..9e148bbc2b 100644 --- a/Code/CryEngine/CrySystem/SystemRender.cpp +++ b/Code/CryEngine/CrySystem/SystemRender.cpp @@ -35,15 +35,10 @@ #include "PhysRenderer.h" #include -#include "CrySizerStats.h" -#include "CrySizerImpl.h" -#include "VisRegTest.h" #include "ITextModeConsole.h" #include #include -#include "MiniGUI/MiniGUI.h" -#include "PerfHUD.h" #include "ThreadInfo.h" #include @@ -61,17 +56,6 @@ extern CMTSafeHeap* g_pPakHeap; extern int CryMemoryGetAllocatedSize(); -///////////////////////////////////////////////////////////////////////////////// -static void VerifySizeRenderVar(ICVar* pVar) -{ - const int size = pVar->GetIVal(); - if (size <= 0) - { - AZ_Error("Console Variable", false, "'%s' set to invalid value: %i. Setting to nearest safe value: 1.", pVar->GetName(), size); - pVar->Set(1); - } -} - ///////////////////////////////////////////////////////////////////////////////// bool CSystem::GetPrimaryPhysicalDisplayDimensions([[maybe_unused]] int& o_widthPixels, [[maybe_unused]] int& o_heightPixels) { @@ -97,130 +81,6 @@ bool CSystem::IsTablet() #endif } -///////////////////////////////////////////////////////////////////////////////// -void CSystem::CreateRendererVars(const SSystemInitParams& startupParams) -{ - int iFullScreenDefault = 1; - int iDisplayInfoDefault = 0; - int iWidthDefault = 1280; - int iHeightDefault = 720; -#if defined(AZ_PLATFORM_ANDROID) || defined(AZ_PLATFORM_IOS) - GetPrimaryPhysicalDisplayDimensions(iWidthDefault, iHeightDefault); -#elif defined(WIN32) || defined(WIN64) - iFullScreenDefault = 0; - iWidthDefault = GetSystemMetrics(SM_CXFULLSCREEN) * 2 / 3; - iHeightDefault = GetSystemMetrics(SM_CYFULLSCREEN) * 2 / 3; -#endif - - if (IsDevMode()) - { - iFullScreenDefault = 0; - iDisplayInfoDefault = 1; - } - - // load renderer settings from engine.ini - m_rWidth = REGISTER_INT_CB("r_Width", iWidthDefault, VF_DUMPTODISK, - "Sets the display width, in pixels. Default is 1280.\n" - "Usage: r_Width [800/1024/..]", VerifySizeRenderVar); - m_rHeight = REGISTER_INT_CB("r_Height", iHeightDefault, VF_DUMPTODISK, - "Sets the display height, in pixels. Default is 720.\n" - "Usage: r_Height [600/768/..]", VerifySizeRenderVar); - m_rWidthAndHeightAsFractionOfScreenSize = REGISTER_FLOAT("r_WidthAndHeightAsFractionOfScreenSize", 1.0f, VF_DUMPTODISK, - "(iOS/Android only) Sets the display width and height as a fraction of the physical screen size. Default is 1.0.\n" - "Usage: rWidthAndHeightAsFractionOfScreenSize [0.1 - 1.0]"); - m_rTabletWidthAndHeightAsFractionOfScreenSize = REGISTER_FLOAT("r_TabletWidthAndHeightAsFractionOfScreenSize", 1.0f, VF_DUMPTODISK, - "(iOS only) NOTE: TABLETS ONLY Sets the display width and height as a fraction of the physical screen size. Default is 1.0.\n" - "Usage: rTabletWidthAndHeightAsFractionOfScreenSize [0.1 - 1.0]"); - m_rMaxWidth = REGISTER_INT("r_MaxWidth", 0, VF_DUMPTODISK, - "(iOS/Android only) Sets the maximum display width while maintaining the device aspect ratio.\n" - "Usage: r_MaxWidth [1024/1920/..] (0 for no max), combined with r_WidthAndHeightAsFractionOfScreenSize [0.1 - 1.0]"); - m_rMaxHeight = REGISTER_INT("r_MaxHeight", 0, VF_DUMPTODISK, - "(iOS/Android only) Sets the maximum display height while maintaining the device aspect ratio.\n" - "Usage: r_MaxHeight [768/1080/..] (0 for no max), combined with r_WidthAndHeightAsFractionOfScreenSize [0.1 - 1.0]"); - m_rColorBits = REGISTER_INT("r_ColorBits", 32, VF_DUMPTODISK, - "Sets the color resolution, in bits per pixel. Default is 32.\n" - "Usage: r_ColorBits [32/24/16/8]"); - m_rDepthBits = REGISTER_INT("r_DepthBits", 24, VF_DUMPTODISK | VF_REQUIRE_APP_RESTART, - "Sets the depth precision, in bits per pixel. Default is 24.\n" - "Usage: r_DepthBits [32/24]"); - m_rStencilBits = REGISTER_INT("r_StencilBits", 8, VF_DUMPTODISK, - "Sets the stencil precision, in bits per pixel. Default is 8.\n"); - - // Needs to be initialized as soon as possible due to swap chain creation modifications.. - m_rHDRDolby = REGISTER_INT_CB("r_HDRDolby", 0, VF_DUMPTODISK, - "HDR dolby output mode\n" - "Usage: r_HDRDolby [Value]\n" - "0: Off (default)\n" - "1: Dolby maui output\n" - "2: Dolby vision output\n", - [] (ICVar* cvar) - { - eDolbyVisionMode mode = static_cast(cvar->GetIVal()); - - if (mode == eDVM_Vision && gEnv->IsEditor()) - { - cvar->Set(static_cast(eDVM_Disabled)); - } - }); - // Restrict the limits of this cvar to the eDolbyVisionMode values - m_rHDRDolby->SetLimits(static_cast(eDVM_Disabled), static_cast(eDVM_Vision)); - -#if defined(WIN32) || defined(WIN64) - REGISTER_INT("r_overrideDXGIAdapter", -1, VF_REQUIRE_APP_RESTART, - "Specifies index of the preferred video adapter to be used for rendering (-1=off, loops until first suitable adapter is found).\n" - "Use this to resolve which video card to use if more than one DX11 capable GPU is available in the system."); -#endif - -#if defined(WIN32) || defined(WIN64) - const char* p_r_DriverDef = "Auto"; -#elif defined(APPLE) - const char* p_r_DriverDef = "METAL"; -#elif defined(ANDROID) - const char* p_r_DriverDef = "GL"; -#elif defined(LINUX) - const char* p_r_DriverDef = "GL"; - if (gEnv->IsDedicated()) - { - p_r_DriverDef = "NULL"; - } -#elif defined(AZ_RESTRICTED_PLATFORM) -#define AZ_RESTRICTED_SECTION SYSTEMRENDERER_CPP_SECTION_1 -#include AZ_RESTRICTED_FILE(SystemRender_cpp) -#else - const char* p_r_DriverDef = "DX9"; // required to be deactivated for final release -#endif - if (startupParams.pCvarsDefault) - { // hack to customize the default value of r_Driver - SCvarsDefault* pCvarsDefault = startupParams.pCvarsDefault; - if (pCvarsDefault->sz_r_DriverDef && pCvarsDefault->sz_r_DriverDef[0]) - { - p_r_DriverDef = startupParams.pCvarsDefault->sz_r_DriverDef; - } - } - - m_rDriver = REGISTER_STRING("r_Driver", p_r_DriverDef, VF_DUMPTODISK | VF_INVISIBLE, - "Sets the renderer driver ( DX11/AUTO/NULL ).\n" - "Specify in bootstrap.cfg like this: r_Driver = \"DX11\""); - - m_rFullscreen = REGISTER_INT("r_Fullscreen", iFullScreenDefault, VF_DUMPTODISK, - "Toggles fullscreen mode. Default is 1 in normal game and 0 in DevMode.\n" - "Usage: r_Fullscreen [0=window/1=fullscreen]"); - - m_rFullscreenWindow = REGISTER_INT("r_FullscreenWindow", 0, VF_DUMPTODISK, - "Toggles fullscreen-as-window mode. Fills screen but allows seamless switching. Default is 0.\n" - "Usage: r_FullscreenWindow [0=locked fullscreen/1=fullscreen as window]"); - - m_rFullscreenNativeRes = REGISTER_INT("r_FullscreenNativeRes", 0, VF_DUMPTODISK, ""); - - m_rDisplayInfo = REGISTER_INT("r_DisplayInfo", iDisplayInfoDefault, VF_RESTRICTEDMODE | VF_DUMPTODISK, - "Toggles debugging information display.\n" - "Usage: r_DisplayInfo [0=off/1=show/2=enhanced/3=compact]"); - - m_rOverscanBordersDrawDebugView = REGISTER_INT("r_OverscanBordersDrawDebugView", 0, VF_RESTRICTEDMODE | VF_DUMPTODISK, - "Toggles drawing overscan borders.\n" - "Usage: r_OverscanBordersDrawDebugView [0=off/1=show]"); -} - void CSystem::OnScene3DEnd() { //Render Console diff --git a/Code/CryEngine/CrySystem/SystemWin32.cpp b/Code/CryEngine/CrySystem/SystemWin32.cpp index b47519eb03..c694979a14 100644 --- a/Code/CryEngine/CrySystem/SystemWin32.cpp +++ b/Code/CryEngine/CrySystem/SystemWin32.cpp @@ -53,8 +53,6 @@ #endif #include "XConsole.h" -#include "CrySizerStats.h" -#include "CrySizerImpl.h" #include "StreamEngine/StreamEngine.h" #include "LocalizedStringManager.h" #include "XML/XmlUtils.h" @@ -69,51 +67,6 @@ __pragma(comment(lib, "Winmm.lib")) #include #endif - - -static AZStd::vector GetModuleNames() -{ - AZStd::vector moduleNames; - if (moduleNames.empty()) - { -# ifdef MODULE_EXTENSION -# error MODULE_EXTENSION already defined! -# endif -# if defined(LINUX) -# define MODULE_EXTENSION ".so" -# elif defined(APPLE) -# define MODULE_EXTENSION ".dylib" -# else -# define MODULE_EXTENSION ".dll" -# endif - - moduleNames.push_back("Cry3DEngine" MODULE_EXTENSION); - moduleNames.push_back("CryFont" MODULE_EXTENSION); - moduleNames.push_back("CrySystem" MODULE_EXTENSION); - -#undef MODULE_EXTENSION - -# if defined(LINUX) - moduleNames.push_back("CryRenderNULL.so"); -# elif defined(APPLE) - moduleNames.push_back("CryRenderNULL.dylib"); -# else - moduleNames.push_back("Editor.exe"); - moduleNames.push_back("CryRenderD3D9.dll"); - moduleNames.push_back("CryRenderD3D10.dll"); - moduleNames.push_back("CryRenderNULL.dll"); - //TODO: launcher? -# endif - } - - return moduleNames; -} - -static bool QueryModuleMemoryInfo([[maybe_unused]] SCryEngineStatsModuleInfo& moduleInfo, [[maybe_unused]] int index) -{ - return false; -} - // this is the list of modules that can be loaded into the game process // Each array element contains 2 strings: the name of the module (case-insensitive) // and the name of the group the module belongs to @@ -158,30 +111,6 @@ void CSystem::SetAffinity() #endif } - - - - -//! dumps the memory usage statistics to the log -////////////////////////////////////////////////////////////////////////// -void CSystem::DumpMemoryUsageStatistics(bool bUseKB) -{ - // CResourceCollector ResourceCollector; - - // TickMemStats(nMSP_ForDump,&ResourceCollector); - TickMemStats(nMSP_ForDump); - - CrySizerStatsRenderer StatsRenderer (this, m_pMemStats, 10, 0); - StatsRenderer.dump(bUseKB); - - // since we've recalculated this mem stats for dumping, we'll want to calculate it anew the next time it's rendered - SAFE_DELETE(m_pMemStats); -} - -// collects the whole memory statistics into the given sizer object -////////////////////////////////////////////////////////////////////////// - - #if defined(WIN32) #pragma pack(push,1) struct PEHeader_DLL @@ -207,162 +136,6 @@ const SmallModuleInfo* FindModuleInfo(std::vector& vec, const c return 0; } -////////////////////////////////////////////////////////////////////////// -void CSystem::CollectMemInfo(SCryEngineStatsGlobalMemInfo& m_stats) -{ - m_stats.totalUsedInModules = 0; - m_stats.totalCodeAndStatic = 0; - m_stats.countedMemoryModules = 0; - m_stats.totalAllocatedInModules = 0; - m_stats.totalNumAllocsInModules = 0; - - AZStd::vector szModules = GetModuleNames(); - const int numModules = szModules.size(); - - ////////////////////////////////////////////////////////////////////////// - // Hardcoded value for the OS memory allocation. - ////////////////////////////////////////////////////////////////////////// - for (int i = 0; i < numModules; i++) - { - const char* szModule = szModules[i].c_str(); - - SCryEngineStatsModuleInfo moduleInfo; - ZeroStruct(moduleInfo.memInfo); - moduleInfo.moduleStaticSize = moduleInfo.SizeOfCode = moduleInfo.SizeOfInitializedData = moduleInfo.SizeOfUninitializedData = moduleInfo.usedInModule = 0; - moduleInfo.name = szModule; - - if (!QueryModuleMemoryInfo(moduleInfo, i)) - { - continue; - } - - m_stats.totalNumAllocsInModules += moduleInfo.memInfo.num_allocations; - m_stats.totalAllocatedInModules += moduleInfo.memInfo.allocated; - m_stats.totalUsedInModules += moduleInfo.usedInModule; - m_stats.countedMemoryModules++; - m_stats.totalCodeAndStatic += moduleInfo.moduleStaticSize; - - m_stats.modules.push_back(moduleInfo); - } -} - - -void CSystem::CollectMemStats (ICrySizer* pSizer, MemStatsPurposeEnum nPurpose, std::vector* pStats) -{ - std::vector stats; - if (pStats) - { - pStats->assign(stats.begin(), stats.end()); - } - - if (nMSP_ForCrashLog == nPurpose || nMSP_ForBudget == nPurpose) - { - return; - } - - { - SIZER_COMPONENT_NAME(pSizer, "CrySystem"); - { - pSizer->AddObject(this, sizeof(*this)); - { - //SIZER_COMPONENT_NAME (pSizer, "$Allocations waste"); - //const SmallModuleInfo* info = FindModuleInfo(stats, "CrySystem.dll"); - //if (info) - //pSizer->AddObject(info, info->memInfo.allocated - info->memInfo.requested ); - } - - { - SIZER_COMPONENT_NAME(pSizer, "VFS"); - if (m_pStreamEngine) - { - SIZER_COMPONENT_NAME(pSizer, "Stream Engine"); - m_pStreamEngine->GetMemoryStatistics(pSizer); - } - } - { - SIZER_COMPONENT_NAME(pSizer, "Localization Data"); - m_pLocalizationManager->GetMemoryUsage(pSizer); - } - { - SIZER_COMPONENT_NAME(pSizer, "XML"); - m_pXMLUtils->GetMemoryUsage(pSizer); - } - if (m_env.pConsole) - { - SIZER_COMPONENT_NAME (pSizer, "Console"); - m_env.pConsole->GetMemoryUsage (pSizer); - } - - if (m_env.pLog) - { - SIZER_COMPONENT_NAME (pSizer, "Log"); - m_env.pLog->GetMemoryUsage(pSizer); - } - } - } - - if (m_env.pRenderer) - { - SIZER_COMPONENT_NAME(pSizer, "CryRenderer"); - { - { - SIZER_COMPONENT_NAME (pSizer, "$Allocations waste D3D9"); - const SmallModuleInfo* info = FindModuleInfo(stats, "CryRenderD3D9.dll"); - if (info) - { - pSizer->AddObject(info, info->memInfo.allocated - info->memInfo.requested); - } - } - { - SIZER_COMPONENT_NAME (pSizer, "$Allocations waste D3D10"); - const SmallModuleInfo* info = FindModuleInfo(stats, "CryRenderD3D10.dll"); - if (info) - { - pSizer->AddObject(info, info->memInfo.allocated - info->memInfo.requested); - } - } - - m_env.pRenderer->GetMemoryUsage(pSizer); - } - } - - if (m_env.pCryFont) - { - SIZER_COMPONENT_NAME(pSizer, "CryFont"); - { - { - SIZER_COMPONENT_NAME (pSizer, "$Allocations waste"); - const SmallModuleInfo* info = FindModuleInfo(stats, "CryFont.dll"); - if (info) - { - pSizer->AddObject(info, info->memInfo.allocated - info->memInfo.requested); - } - } - - m_env.pCryFont->GetMemoryUsage(pSizer); - // m_pIFont and m_pIFontUi are both counted in pCryFont sizing if they exist. - // no need to manually add them here. - } - } - - { - SIZER_COMPONENT_NAME(pSizer, "UserData"); - if (m_pUserCallback) - { - m_pUserCallback->GetMemoryUsage(pSizer); - } - } - -#ifdef WIN32 - { - SIZER_COMPONENT_NAME(pSizer, "Code"); - GetExeSizes (pSizer, nPurpose); - } -#endif - - pSizer->End(); -} - ////////////////////////////////////////////////////////////////////////// const char* CSystem::GetUserName() { @@ -460,52 +233,6 @@ int CSystem::GetApplicationLogInstance([[maybe_unused]] const char* logFilePath) #endif } - -// refreshes the m_pMemStats if necessary; creates it if it's not created -////////////////////////////////////////////////////////////////////////// -void CSystem::TickMemStats(MemStatsPurposeEnum nPurpose, IResourceCollector* pResourceCollector) -{ - // gather the statistics, if required - // if there's no object, or if it's time to recalculate, or if it's for dump, then recalculate it - if (!m_pMemStats || (m_env.pRenderer->GetFrameID(false) % m_cvMemStats->GetIVal()) == 0 || nPurpose == nMSP_ForDump) - { - if (!m_pMemStats) - { - if (m_cvMemStats->GetIVal() < 4 && m_cvMemStats->GetIVal()) - { - GetILog()->LogToConsole("memstats is too small (%d). Performance impact can be significant. Please set to a greater value.", m_cvMemStats->GetIVal()); - } - m_pMemStats = new CrySizerStats(); - } - - if (!m_pSizer) - { - m_pSizer = new CrySizerImpl(); - } - - m_pSizer->SetResourceCollector(pResourceCollector); - - m_pMemStats->startTimer(0, GetITimer()); - CollectMemStats (m_pSizer, nPurpose); - m_pMemStats->stopTimer(0, GetITimer()); - - m_pMemStats->startTimer(1, GetITimer()); - CrySizerStatsBuilder builder (m_pSizer); - builder.build (m_pMemStats); - m_pMemStats->stopTimer(1, GetITimer()); - - m_pMemStats->startTimer(2, GetITimer()); - m_pSizer->clear(); - m_pMemStats->stopTimer(2, GetITimer()); - } - else - { - m_pMemStats->incAgeFrames(); - } -} - -//#define __HASXP - // these 2 functions are duplicated in System.cpp in editor ////////////////////////////////////////////////////////////////////////// #if !defined(LINUX) @@ -839,51 +566,6 @@ const char* GetModuleGroup (const char* szString) return "Other"; } -////////////////////////////////////////////////////////////////////////// -void CSystem::GetExeSizes (ICrySizer* pSizer, MemStatsPurposeEnum nPurpose) -{ - HANDLE hSnapshot; - hSnapshot = CreateToolhelp32Snapshot (TH32CS_SNAPMODULE, 0); - if (hSnapshot == INVALID_HANDLE_VALUE) - { - CryLogAlways ("Cannot get the module snapshot, error code %d", GetLastError()); - return; - } - - DWORD dwProcessID = GetCurrentProcessId(); - - MODULEENTRY32 me; - memset (&me, 0, sizeof(me)); - me.dwSize = sizeof(me); - - if (Module32First (hSnapshot, &me)) - { - // the sizes of each module group - StringToSizeMap mapGroupSize; - do - { - dwProcessID = me.th32ProcessID; - const char* szGroup = GetModuleGroup (me.szModule); - SIZER_COMPONENT_NAME(pSizer, szGroup); - if (nPurpose == nMSP_ForDump) - { - SIZER_COMPONENT_NAME(pSizer, me.szModule); - pSizer->AddObject(me.modBaseAddr, me.modBaseSize); - } - else - { - pSizer->AddObject(me.modBaseAddr, me.modBaseSize); - } - } while (Module32Next(hSnapshot, &me)); - } - else - { - CryLogAlways ("No modules to dump"); - } - - CloseHandle (hSnapshot); -} - #endif ////////////////////////////////////////////////////////////////////////// @@ -1061,18 +743,11 @@ void CSystem::FatalError(const char* format, ...) LogSystemInfo(); - CollectMemStats(0, nMSP_ForCrashLog); - OutputDebugString(szBuffer); #ifdef WIN32 OnFatalError(szBuffer); if (!g_cvars.sys_no_crash_dialog) { - ICVar* pFullscreen = (gEnv && gEnv->pConsole) ? gEnv->pConsole->GetCVar("r_Fullscreen") : 0; - if (pFullscreen && pFullscreen->GetIVal() != 0 && gEnv->pRenderer && gEnv->pRenderer->GetHWND()) - { - ::ShowWindow((HWND)gEnv->pRenderer->GetHWND(), SW_MINIMIZE); - } ::MessageBox(NULL, szBuffer, "Open 3D Engine Error", MB_OK | MB_ICONERROR | MB_SYSTEMMODAL); } @@ -1169,12 +844,6 @@ void CSystem::debug_LogCallStack(int nMaxFuncs, [[maybe_unused]] int nFlags) // Print call stack for each find. const char* funcs[32]; int nCount = nMaxFuncs; - int nCurFrame = 0; - if (m_env.pRenderer) - { - nCurFrame = (int)m_env.pRenderer->GetFrameID(false); - } - CryLogAlways(" ----- CallStack (Frame: %d) -----", nCurFrame); GetISystem()->debug_GetCallStack(funcs, nCount); for (int i = 1; i < nCount; i++) // start from 1 to skip this function. { diff --git a/Code/CryEngine/CrySystem/Tests/Test_CrySizer.cpp b/Code/CryEngine/CrySystem/Tests/Test_CrySizer.cpp deleted file mode 100644 index c9aa248eee..0000000000 --- a/Code/CryEngine/CrySystem/Tests/Test_CrySizer.cpp +++ /dev/null @@ -1,102 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#include "CrySystem_precompiled.h" - -#include -#include -#include - -#include - -#include "CrySizerImpl.h" - -namespace UnitTest -{ - class CrySizerTest - : public AllocatorsFixture - { - public: - void SetUp() override - { - AZ::AllocatorInstance::Create(); - AZ::AllocatorInstance::Create(); - - m_sizer = new CrySizerImpl(); - } - - void TearDown() override - { - delete m_sizer; - - AZ::AllocatorInstance::Destroy(); - AZ::AllocatorInstance::Destroy(); - } - protected: - CrySizerImpl* m_sizer; - }; //class StatisticsTest - - /** - * The key data structures fed to ICrySizer in CTerrain::GetMemoryUsage(class ICrySizer* pSizer): - * 1. structs and classes. - * 2. PodArray< of structs / classes> - * 3. PodArray< of pointers> - */ - TEST_F(CrySizerTest, CrySizerTest_AddSomeObjectsUsedInCTerrain_GetExpectedSize) - { - struct TmpStruct - { - AZ::u32 a; - AZ::u32 b; - }; - TmpStruct tmpStructObj; - //Tracking a simple struct. - m_sizer->AddObjectSize(&tmpStructObj); - - //The AddObject method is only available when using the ICrySizer base class. - ICrySizer* sizer = static_cast(m_sizer); - - const int numItemsPerArray = 1024; - - //PodArray of structs - PodArray podArrayOfTmpStruct; - podArrayOfTmpStruct.resize(numItemsPerArray); - sizer->AddObject(podArrayOfTmpStruct); - - //PodArray of pointers - PodArray podArrayOfTmpStructPointers; - podArrayOfTmpStructPointers.resize(numItemsPerArray); - sizer->AddObject(podArrayOfTmpStructPointers); - - //PodArray of Array2d of pointers. - const int array2dAxisSize = 64; - PodArray> podArrayOfArray2d; - podArrayOfArray2d.resize(numItemsPerArray); - for (int i = 0; i < numItemsPerArray; ++i) - { - //Array2d will allocate array2dAxisSize * array2dAxisSize elements. - podArrayOfArray2d[i].Allocate(array2dAxisSize); - } - sizer->AddObject(podArrayOfArray2d); - - //Calculate the total expected size - const size_t expectedSizeOfArray2d = sizeof(Array2d) - + (array2dAxisSize * array2dAxisSize) * sizeof(TmpStruct*); - const size_t expectedTotalSize = sizeof(TmpStruct) - + numItemsPerArray * sizeof(TmpStruct) - + numItemsPerArray * sizeof(TmpStruct*) - + numItemsPerArray * expectedSizeOfArray2d; - - EXPECT_EQ( m_sizer->GetTotalSize(), expectedTotalSize); - } - -}//namespace UnitTest diff --git a/Code/CryEngine/CrySystem/Timer.cpp b/Code/CryEngine/CrySystem/Timer.cpp index eb53c1b257..7545b42765 100644 --- a/Code/CryEngine/CrySystem/Timer.cpp +++ b/Code/CryEngine/CrySystem/Timer.cpp @@ -26,9 +26,6 @@ #include "Mmsystem.h" #endif -//this should not be included here -#include // needed for m_pSystem->GetIRenderer()->EF_Query(EFQ_RecurseLevel) - //#define PROFILING 1 #ifdef PROFILING static int64 g_lCurrentTime = 0; @@ -432,7 +429,7 @@ void CTimer::UpdateOnFrameStart() if (m_TimeDebug > 1) { - CryLogAlways("[CTimer]: Frame=%d Cur=%lld Now=%lld Off=%lld Async=%f CurrTime=%f UI=%f", gEnv->pRenderer->GetFrameID(false), (long long)currentTime, (long long)now, (long long)m_lOffsetTime, GetAsyncCurTime(), GetCurrTime(ETIMER_GAME), GetCurrTime(ETIMER_UI)); + CryLogAlways("[CTimer]: Cur=%lld Now=%lld Off=%lld Async=%f CurrTime=%f UI=%f", (long long)currentTime, (long long)now, (long long)m_lOffsetTime, GetAsyncCurTime(), GetCurrTime(ETIMER_GAME), GetCurrTime(ETIMER_UI)); } } @@ -558,7 +555,7 @@ void CTimer::Serialize(TSerialize ser) if (m_TimeDebug) { const int64 now = CryGetTicks(); - CryLogAlways("[CTimer]: Serialize: Frame=%d Last=%lld Now=%lld Off=%lld Async=%f CurrTime=%f UI=%f", gEnv->pRenderer->GetFrameID(false), (long long)m_lLastTime, (long long)now, (long long)m_lOffsetTime, GetAsyncCurTime(), GetCurrTime(ETIMER_GAME), GetCurrTime(ETIMER_UI)); + CryLogAlways("[CTimer]: Serialize: Last=%lld Now=%lld Off=%lld Async=%f CurrTime=%f UI=%f", (long long)m_lLastTime, (long long)now, (long long)m_lOffsetTime, GetAsyncCurTime(), GetCurrTime(ETIMER_GAME), GetCurrTime(ETIMER_UI)); } } } @@ -584,7 +581,7 @@ bool CTimer::PauseTimer(ETimer which, bool bPause) m_lGameTimerPausedTime = m_lLastTime + m_lOffsetTime; if (m_TimeDebug) { - CryLogAlways("[CTimer]: Pausing ON: Frame=%d Last=%lld Off=%lld Async=%f CurrTime=%f UI=%f", gEnv->pRenderer->GetFrameID(false), (long long)m_lLastTime, (long long)m_lOffsetTime, GetAsyncCurTime(), GetCurrTime(ETIMER_GAME), GetCurrTime(ETIMER_UI)); + CryLogAlways("[CTimer]: Pausing ON: Last=%lld Off=%lld Async=%f CurrTime=%f UI=%f", (long long)m_lLastTime, (long long)m_lOffsetTime, GetAsyncCurTime(), GetCurrTime(ETIMER_GAME), GetCurrTime(ETIMER_UI)); } } else @@ -593,7 +590,7 @@ bool CTimer::PauseTimer(ETimer which, bool bPause) m_lGameTimerPausedTime = 0; if (m_TimeDebug) { - CryLogAlways("[CTimer]: Pausing OFF: Frame=%d Last=%lld Off=%lld Async=%f CurrTime=%f UI=%f", gEnv->pRenderer->GetFrameID(false), (long long)m_lLastTime, (long long)m_lOffsetTime, GetAsyncCurTime(), GetCurrTime(ETIMER_GAME), GetCurrTime(ETIMER_UI)); + CryLogAlways("[CTimer]: Pausing OFF: Last=%lld Off=%lld Async=%f CurrTime=%f UI=%f", (long long)m_lLastTime, (long long)m_lOffsetTime, GetAsyncCurTime(), GetCurrTime(ETIMER_GAME), GetCurrTime(ETIMER_UI)); } } diff --git a/Code/CryEngine/CrySystem/Validator.h b/Code/CryEngine/CrySystem/Validator.h index 409377ee28..83dc0533f6 100644 --- a/Code/CryEngine/CrySystem/Validator.h +++ b/Code/CryEngine/CrySystem/Validator.h @@ -43,11 +43,6 @@ struct SDefaultValidator } #ifdef WIN32 - ICVar* pFullscreen = (gEnv && gEnv->pConsole) ? gEnv->pConsole->GetCVar("r_Fullscreen") : 0; - if (pFullscreen && pFullscreen->GetIVal() != 0 && gEnv->pRenderer && gEnv->pRenderer->GetHWND()) - { - ::ShowWindow((HWND)gEnv->pRenderer->GetHWND(), SW_MINIMIZE); - } string strMessage = record.text; strMessage += "\n---------------------------------------------\nAbort - terminate application\nRetry - continue running the application\nIgnore - don't show this message box any more"; switch (::MessageBox(NULL, strMessage.c_str(), "CryEngine Warning", MB_ABORTRETRYIGNORE | MB_DEFBUTTON2 | MB_ICONWARNING | MB_SYSTEMMODAL)) diff --git a/Code/CryEngine/CrySystem/ViewSystem/DebugCamera.cpp b/Code/CryEngine/CrySystem/ViewSystem/DebugCamera.cpp index ace30d5df7..f38dda32c7 100644 --- a/Code/CryEngine/CrySystem/ViewSystem/DebugCamera.cpp +++ b/Code/CryEngine/CrySystem/ViewSystem/DebugCamera.cpp @@ -137,15 +137,6 @@ void DebugCamera::PostUpdate() CCamera& camera = gEnv->pSystem->GetViewCamera(); camera.SetMatrix(Matrix34(m_view, m_position)); - - const float FONT_COLOR[4] = { 1.0f, 0.0f, 0.0f, 1.0f }; - gEnv->pRenderer->Draw2dLabel(0.0f, 700.0f, 1.3f, FONT_COLOR, false, - "Debug Camera: pos [ %.3f, %.3f, %.3f ] p/y [ %.1f, %.1f ] dir [ %.3f, %.3f, %.3f ] scl %.2f inv %d", - m_position.x, m_position.y, m_position.z, - m_cameraPitch, m_cameraYaw, - m_view.GetColumn1().x, m_view.GetColumn1().y, m_view.GetColumn1().z, - m_moveScale, - m_isYInverted); } /////////////////////////////////////////////////////////////////////////////// diff --git a/Code/CryEngine/CrySystem/ViewSystem/View.cpp b/Code/CryEngine/CrySystem/ViewSystem/View.cpp index f8b84bea19..0ab2d6169b 100644 --- a/Code/CryEngine/CrySystem/ViewSystem/View.cpp +++ b/Code/CryEngine/CrySystem/ViewSystem/View.cpp @@ -101,25 +101,6 @@ void CView::Update(float frameTime, bool isActive) const float farPlane = (m_viewParams.farplane > 0.f) ? m_viewParams.farplane : DEFAULT_FAR; float fov = (m_viewParams.fov < 0.001f) ? DEFAULT_FOV : m_viewParams.fov; - // [VR] specific - // Modify FOV based on the HMD device configuration - bool isRenderingToHMD = gEnv->pRenderer ? gEnv->pRenderer->GetIStereoRenderer()->IsRenderingToHMD() : false; - if (isRenderingToHMD) - { - const AZ::VR::HMDDeviceInfo* deviceInfo = nullptr; - EBUS_EVENT_RESULT(deviceInfo, AZ::VR::HMDDeviceRequestBus, GetDeviceInfo); - if (deviceInfo) - { - //Add 12 degrees to the FOV here used for culling. - //It won't be used for rendering, just to make sure we don't cull - //anything out incorrectly. - //This value was decided based on experimentation with the HTC Vive - //and works perfectly fine for the Oculus Rift - const float fovCorrection = 12.0f; - fov = deviceInfo->fovV + DEG2RAD(fovCorrection); - } - } - m_camera.SetFrustum(pSysCam->GetViewSurfaceX(), pSysCam->GetViewSurfaceZ(), fov, nearPlane, farPlane, pSysCam->GetPixelAspectRatio()); //apply shake & set the view matrix @@ -140,20 +121,6 @@ void CView::Update(float frameTime, bool isActive) Vec3 pos = m_viewParams.position; Vec3 p = Vec3(ZERO); - if (isRenderingToHMD) - { - //This HMD tracking state is used JUST for use in the visibility system. - //RT_SetStereoCamera in D3DRendPipeline will override this info before rendering with the absolute - //latest tracking info. - const AZ::VR::TrackingState* trackingState = nullptr; - EBUS_EVENT_RESULT(trackingState, AZ::VR::HMDDeviceRequestBus, GetTrackingState); - if (trackingState && trackingState->CheckStatusFlags(AZ::VR::HMDStatus_IsUsable)) - { - p = q * AZVec3ToLYVec3(trackingState->pose.position); - q = q * AZQuaternionToLYQuaternion(trackingState->pose.orientation); - } - } - Matrix34 viewMtx(q); viewMtx.SetTranslation(pos + p); m_camera.SetMatrix(viewMtx); diff --git a/Code/CryEngine/CrySystem/ViewSystem/ViewSystem.cpp b/Code/CryEngine/CrySystem/ViewSystem/ViewSystem.cpp index 13f7f5b82d..c0f681511b 100644 --- a/Code/CryEngine/CrySystem/ViewSystem/ViewSystem.cpp +++ b/Code/CryEngine/CrySystem/ViewSystem/ViewSystem.cpp @@ -640,30 +640,6 @@ void CViewSystem::ClearAllViews() //////////////////////////////////////////////////////////////////// void CViewSystem::DebugDraw() { - IRenderer* pRenderer = gEnv->pRenderer; - if (pRenderer) - { - float xpos = 20; - float ypos = 15; - float fColor[4] = {1.0f, 1.0f, 1.0f, 0.7f}; - float fColorRed[4] = {1.0f, 0.0f, 0.0f, 0.7f}; - float fColorGreen[4] = {0.0f, 1.0f, 0.0f, 0.7f}; - - pRenderer->Draw2dLabel(xpos, 5, 1.35f, fColor, false, "ViewSystem Stats: %" PRISIZE_T " Views ", m_views.size()); - - IView* pActiveView = GetActiveView(); - for (TViewMap::iterator it = m_views.begin(); it != m_views.end(); ++it) - { - IView* pView = it->second; - const CCamera& cam = pView->GetCamera(); - bool isActive = (pView == pActiveView); - Vec3 pos = cam.GetPosition(); - Ang3 ang = cam.GetAngles(); - pRenderer->Draw2dLabel(xpos, ypos, 1.35f, isActive ? fColorGreen : fColorRed, false, "View Camera: %p . View Id: %d, pos (%f, %f, %f), ang (%f, %f, %f)", &cam, it->first, pos.x, pos.y, pos.z, ang.x, ang.y, ang.z); - - ypos += 11; - } - } } ////////////////////////////////////////////////////////////////////////// diff --git a/Code/CryEngine/CrySystem/VisRegTest.cpp b/Code/CryEngine/CrySystem/VisRegTest.cpp deleted file mode 100644 index 206d8f349a..0000000000 --- a/Code/CryEngine/CrySystem/VisRegTest.cpp +++ /dev/null @@ -1,384 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// Description : Visual Regression Test - - -#include "CrySystem_precompiled.h" -#include "VisRegTest.h" - -#include "ISystem.h" -#include "IRenderer.h" -#include "IConsole.h" -#include "ITimer.h" -#include "IStreamEngine.h" -#include - -#include - -const float CVisRegTest::MaxStreamingWait = 30.0f; - -CVisRegTest::CVisRegTest() - : m_nextCmd(0) - , m_waitFrames(0) -{ - CryLog("Enabled visual regression tests"); -} - - -void CVisRegTest::Init(IConsoleCmdArgs* pParams) -{ - assert(pParams); - - stack_string configFile("visregtest.xml"); - - // Reset - m_cmdBuf.clear(); - m_dataSamples.clear(); - m_nextCmd = 0; - m_cmdFreq = 0; - m_waitFrames = 0; - m_streamingTimeout = 0.0f; - m_testName = "test"; - m_quitAfterTests = false; - - // Parse arguments - if (pParams->GetArgCount() >= 2) - { - m_testName = pParams->GetArg(1); - } - if (pParams->GetArgCount() >= 3) - { - configFile = pParams->GetArg(2); - } - if (pParams->GetArgCount() >= 4) - { - if (_stricmp(pParams->GetArg(3), "quit") == 0) - { - m_quitAfterTests = true; - } - } - - // Fill cmd buffer - if (!LoadConfig(configFile.c_str())) - { - CryWarning(VALIDATOR_MODULE_SYSTEM, VALIDATOR_ERROR, "VisRegTest: Failed to load config file '%s' from game folder", configFile.c_str()); - return; - } - - gEnv->pTimer->SetTimeScale(0); - GetISystem()->GetISystemEventDispatcher()->OnSystemEvent(ESYSTEM_EVENT_RANDOM_SEED, 0, 0); - srand(0); - - gEnv->pRenderer->EnableGPUTimers2(true); -} - - -void CVisRegTest::AfterRender() -{ - ExecCommands(); -} - - -bool CVisRegTest::LoadConfig(const char* configFile) -{ - XmlNodeRef rootNode = GetISystem()->LoadXmlFromFile(configFile); - if (!rootNode || !rootNode->isTag("VisRegTest")) - { - return false; - } - - m_cmdBuf.push_back(SCmd(eCMDStart, "")); - - for (int i = 0; i < rootNode->getChildCount(); ++i) - { - XmlNodeRef node = rootNode->getChild(i); - - if (node->isTag("Config")) - { - SCmd cmd; - for (int j = 0; j < node->getChildCount(); ++j) - { - XmlNodeRef node2 = node->getChild(j); - - if (node2->isTag("ConsoleCmd")) - { - m_cmdBuf.push_back(SCmd(eCMDConsoleCmd, node2->getAttr("cmd"))); - } - } - } - else if (node->isTag("Map")) - { - const char* mapName = node->getAttr("name"); - int imageIndex = 0; - - m_cmdBuf.push_back(SCmd(eCMDLoadMap, mapName)); - m_cmdBuf.push_back(SCmd(eCMDOnMapLoaded, "")); - - for (int j = 0; j < node->getChildCount(); ++j) - { - XmlNodeRef node2 = node->getChild(j); - - if (node2->isTag("ConsoleCmd")) - { - m_cmdBuf.push_back(SCmd(eCMDConsoleCmd, node2->getAttr("cmd"))); - } - else if (node2->isTag("Sample")) - { - m_cmdBuf.push_back(SCmd(eCMDGoto, node2->getAttr("location"))); - m_cmdBuf.push_back(SCmd(eCMDWaitStreaming, "")); - - char strbuf[256]; -#ifdef WIN32 - sprintf_s(strbuf, "%s_%i.bmp", mapName, imageIndex++); -#else - sprintf_s(strbuf, "%s_%i.tga", mapName, imageIndex++); -#endif - m_cmdBuf.push_back(SCmd(eCMDCaptureSample, strbuf, SampleCount)); - } - } - } - } - - m_cmdBuf.push_back(SCmd(eCMDFinish, "")); - - return true; -} - - -void CVisRegTest::ExecCommands() -{ - if (m_nextCmd >= m_cmdBuf.size()) - { - return; - } - - float col[] = {0, 1, 0, 1}; - gEnv->pRenderer->Draw2dLabel(10, 10, 2, col, false, "Visual Regression Test"); - - if (m_waitFrames > 0) - { - --m_waitFrames; - return; - } - else if (m_waitFrames < 0) // Wait for streaming - { - SStreamEngineOpenStats stats; - gEnv->pSystem->GetStreamEngine()->GetStreamingOpenStatistics(stats); - if (stats.nOpenRequestCount > 0 && m_streamingTimeout > 0) - { - gEnv->pConsole->ExecuteString("t_FixedStep 0"); - m_streamingTimeout -= gEnv->pTimer->GetRealFrameTime(); - m_waitFrames = -16; - } - else if (++m_waitFrames == 0) - { - gEnv->pConsole->ExecuteString("t_FixedStep 0.033333"); - m_waitFrames = 64; // Wait some more frames for tone-mapper to adapt - } - - return; - } - - stack_string tmp; - - while (m_nextCmd < m_cmdBuf.size()) - { - SCmd& cmd = m_cmdBuf[m_nextCmd]; - - if (m_cmdFreq == 0) - { - m_cmdFreq = cmd.freq; - } - - switch (cmd.cmd) - { - case eCMDStart: - break; - case eCMDFinish: - Finish(); - break; - case eCMDOnMapLoaded: - gEnv->pTimer->SetTimer(ITimer::ETIMER_GAME, 0); - gEnv->pTimer->SetTimer(ITimer::ETIMER_UI, 0); - gEnv->pConsole->ExecuteString("t_FixedStep 0.033333"); - GetISystem()->GetISystemEventDispatcher()->OnSystemEvent(ESYSTEM_EVENT_RANDOM_SEED, 0, 0); - srand(0); - break; - case eCMDConsoleCmd: - gEnv->pConsole->ExecuteString(cmd.args.c_str()); - break; - case eCMDLoadMap: - LoadMap(cmd.args.c_str()); - break; - case eCMDWaitStreaming: - m_waitFrames = -1; - m_streamingTimeout = MaxStreamingWait; - break; - case eCMDWaitFrames: - m_waitFrames = (uint32)atoi(cmd.args.c_str()); - break; - case eCMDGoto: - tmp = "playerGoto "; - tmp.append(cmd.args.c_str()); - gEnv->pConsole->ExecuteString(tmp.c_str()); - m_waitFrames = 1; - break; - case eCMDCaptureSample: - CaptureSample(cmd); - break; - } - - if (m_cmdFreq-- == 1) - { - ++m_nextCmd; - } - - if (m_waitFrames != 0) - { - break; - } - } -} - - -void CVisRegTest::LoadMap(const char* mapName) -{ - string mapCmd("map "); - mapCmd.append(mapName); - gEnv->pConsole->ExecuteString(mapCmd.c_str()); - - gEnv->pTimer->SetTimer(ITimer::ETIMER_GAME, 0); - gEnv->pTimer->SetTimer(ITimer::ETIMER_UI, 0); - gEnv->pConsole->ExecuteString("t_FixedStep 0"); - GetISystem()->GetISystemEventDispatcher()->OnSystemEvent(ESYSTEM_EVENT_RANDOM_SEED, 0, 0); - srand(0); -} - - -void CVisRegTest::CaptureSample(const SCmd& cmd) -{ - if (m_cmdFreq == SampleCount) // First sample - { - m_dataSamples.push_back(SSample()); - gEnv->pConsole->ExecuteString("t_FixedStep 0"); - } - - SSample& sample = m_dataSamples.back(); - - // Collect stats - sample.imageName = cmd.args.c_str(); - sample.frameTime += gEnv->pTimer->GetRealFrameTime() * 1000.f; - sample.drawCalls += gEnv->pRenderer->GetCurrentNumberOfDrawCalls(); - - const RPProfilerStats* pRPPStats = gEnv->pRenderer->GetRPPStatsArray(); - - if (pRPPStats) - { - sample.gpuTimes[0] += pRPPStats[eRPPSTATS_OverallFrame].gpuTime; - - sample.gpuTimes[1] += pRPPStats[eRPPSTATS_SceneOverall].gpuTime; - sample.gpuTimes[2] += pRPPStats[eRPPSTATS_ShadowsOverall].gpuTime; - sample.gpuTimes[3] += pRPPStats[eRPPSTATS_LightingOverall].gpuTime; - sample.gpuTimes[4] += pRPPStats[eRPPSTATS_VfxOverall].gpuTime; - } - - if (m_cmdFreq == 1) // Final sample - { - // Screenshot - stack_string filename("@usercache@/TestResults/VisReg/"); // the default unaliased assets folder is read-only! - filename += m_testName + "/" + cmd.args.c_str(); - gEnv->pRenderer->ScreenShot(filename); - - // Average results - sample.frameTime /= (float)SampleCount; - sample.drawCalls /= SampleCount; - for (uint32 i = 0; i < MaxNumGPUTimes; ++i) - { - sample.gpuTimes[i] /= (float)SampleCount; - } - - gEnv->pConsole->ExecuteString("t_FixedStep 0.033333"); - } -} - - -void CVisRegTest::Finish() -{ - WriteResults(); - - gEnv->pConsole->ExecuteString("t_FixedStep 0"); - gEnv->pTimer->SetTimeScale(1); - - gEnv->pRenderer->EnableGPUTimers2(false); - - CryLog("VisRegTest: Finished tests"); - - if (m_quitAfterTests) - { - gEnv->pConsole->ExecuteString("quit"); - return; - } -} - - -bool CVisRegTest::WriteResults() -{ - stack_string filename("@usercache@/TestResults/VisReg/"); - filename += m_testName + "/visreg_results.xml"; - - AZ::IO::HandleType fileHandle = fxopen(filename.c_str(), "wb"); - if (fileHandle == AZ::IO::InvalidHandle) - { - return false; - } - - AZ::IO::Print(fileHandle, "\n"); - AZ::IO::Print(fileHandle, "\t\n"); - - for (int i = 0; i < (int)m_dataSamples.size(); ++i) - { - SSample sample = m_dataSamples[i]; - - AZ::IO::Print(fileHandle, "\t\t\n", i, sample.imageName); - - AZ::IO::Print(fileHandle, "\t\t\t\n"); - AZ::IO::Print(fileHandle, "\t\t\t\t\n", sample.frameTime); - AZ::IO::Print(fileHandle, "\t\t\t\t\n", sample.drawCalls); - AZ::IO::Print(fileHandle, "\t\t\t\n"); - - AZ::IO::Print(fileHandle, "\t\t\t\n"); - AZ::IO::Print(fileHandle, "\t\t\t\t\n", sample.gpuTimes[0]); - AZ::IO::Print(fileHandle, "\t\t\t\t\n", sample.gpuTimes[1]); - AZ::IO::Print(fileHandle, "\t\t\t\t\n", sample.gpuTimes[2]); - AZ::IO::Print(fileHandle, "\t\t\t\t\n", sample.gpuTimes[3]); - AZ::IO::Print(fileHandle, "\t\t\t\t\n", sample.gpuTimes[4]); - AZ::IO::Print(fileHandle, "\t\t\t\t\n", sample.gpuTimes[5]); - AZ::IO::Print(fileHandle, "\t\t\t\t\n", sample.gpuTimes[6]); - AZ::IO::Print(fileHandle, "\t\t\t\t\n", sample.gpuTimes[7]); - AZ::IO::Print(fileHandle, "\t\t\t\t\n", sample.gpuTimes[8]); - AZ::IO::Print(fileHandle, "\t\t\t\t\n", sample.gpuTimes[9]); - AZ::IO::Print(fileHandle, "\t\t\t\t\n", sample.gpuTimes[10]); - AZ::IO::Print(fileHandle, "\t\t\t\t\n", sample.gpuTimes[11]); - AZ::IO::Print(fileHandle, "\t\t\t\t\n", sample.gpuTimes[12]); - AZ::IO::Print(fileHandle, "\t\t\t\n"); - - AZ::IO::Print(fileHandle, "\t\t\n"); - } - - AZ::IO::Print(fileHandle, "\t\n"); - AZ::IO::Print(fileHandle, ""); - gEnv->pFileIO->Close(fileHandle); - - return true; -} diff --git a/Code/CryEngine/CrySystem/VisRegTest.h b/Code/CryEngine/CrySystem/VisRegTest.h deleted file mode 100644 index 19653940a4..0000000000 --- a/Code/CryEngine/CrySystem/VisRegTest.h +++ /dev/null @@ -1,104 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// Description : Visual Regression Test - - -#ifndef CRYINCLUDE_CRYSYSTEM_VISREGTEST_H -#define CRYINCLUDE_CRYSYSTEM_VISREGTEST_H -#pragma once - - -struct IConsoleCmdArgs; - -class CVisRegTest -{ -public: - static const uint32 SampleCount = 16; - static const uint32 MaxNumGPUTimes = 13; - static const float MaxStreamingWait; - -protected: - - enum ECmd - { - eCMDStart, - eCMDFinish, - eCMDOnMapLoaded, - eCMDConsoleCmd, - eCMDLoadMap, - eCMDWaitStreaming, - eCMDWaitFrames, - eCMDGoto, - eCMDCaptureSample - }; - - struct SCmd - { - ECmd cmd; - uint32 freq; - string args; - - SCmd() {} - SCmd(ECmd _cmd, const string& _args, uint32 _freq = 1) - { this->cmd = _cmd; this->args = _args; this->freq = _freq; } - }; - - struct SSample - { - const char* imageName; - float frameTime; - uint32 drawCalls; - float gpuTimes[MaxNumGPUTimes]; - - SSample() - : imageName(NULL) - , frameTime(0.f) - , drawCalls(0) - { - for (uint32 i = 0; i < MaxNumGPUTimes; ++i) - { - gpuTimes[i] = 0; - } - } - }; - -protected: - string m_testName; - std::vector< SCmd > m_cmdBuf; - std::vector< SSample > m_dataSamples; - uint32 m_nextCmd; - uint32 m_cmdFreq; - int m_waitFrames; - float m_streamingTimeout; - int m_curSample; - bool m_quitAfterTests; - -public: - - CVisRegTest(); - - void Init(IConsoleCmdArgs* pParams); - void AfterRender(); - -protected: - - bool LoadConfig(const char* configFile); - void ExecCommands(); - void LoadMap(const char* mapName); - void CaptureSample(const SCmd& cmd); - void Finish(); - bool WriteResults(); -}; - -#endif // CRYINCLUDE_CRYSYSTEM_VISREGTEST_H diff --git a/Code/CryEngine/CrySystem/XConsole.cpp b/Code/CryEngine/CrySystem/XConsole.cpp index f4271d6dc4..ee5b500b0b 100644 --- a/Code/CryEngine/CrySystem/XConsole.cpp +++ b/Code/CryEngine/CrySystem/XConsole.cpp @@ -328,7 +328,6 @@ CXConsole::CXConsole() m_fRepeatTimer = 0; m_pSysDeactivateConsole = 0; m_pFont = NULL; - m_pRenderer = NULL; m_pImage = NULL; m_nCursorPos = 0; m_nScrollPos = 0; @@ -397,18 +396,6 @@ CXConsole::~CXConsole() ////////////////////////////////////////////////////////////////////////// void CXConsole::FreeRenderResources() { - if (m_pRenderer) - { - if (m_nLoadingBackTexID) - { - m_pRenderer->RemoveTexture(m_nLoadingBackTexID); - m_nLoadingBackTexID = -1; - } - if (m_pImage) - { - m_pImage->Release(); - } - } } ////////////////////////////////////////////////////////////////////////// @@ -485,7 +472,6 @@ void CXConsole::Init(ISystem* pSystem) { m_pFont = pSystem->GetICryFont()->GetFont("default"); } - m_pRenderer = pSystem->GetIRenderer(); m_pTimer = pSystem->GetITimer(); AzFramework::InputChannelEventListener::Connect(); @@ -534,10 +520,7 @@ void CXConsole::Init(ISystem* pSystem) // ---------------------------------------------------------- - if (!m_pRenderer || gEnv->IsInToolMode()) - { - m_nLoadingBackTexID = -1; - } + m_nLoadingBackTexID = -1; if (gEnv->IsDedicated()) { @@ -1176,7 +1159,6 @@ void CXConsole::Clear() ////////////////////////////////////////////////////////////////////////// void CXConsole::Update() { - // Repeat GetIRenderer (For Editor). if (!m_pSystem) { return; @@ -1192,8 +1174,6 @@ void CXConsole::Update() // Execute the deferred commands ExecuteDeferredCommands(); - m_pRenderer = m_pSystem->GetIRenderer(); - if (!m_bConsoleActive) { m_nRepeatEventId = s_nullRepeatEventId; @@ -1588,206 +1568,10 @@ const char* CXConsole::GetHistoryElement(const bool bUpOrDown) ////////////////////////////////////////////////////////////////////////// void CXConsole::Draw() { - //ShowConsole(true); - if (!m_pSystem || !m_nTempScrollMax) - { - return; - } - - if (!m_pRenderer) - { - // For Editor. - m_pRenderer = m_pSystem->GetIRenderer(); - } - - if (!m_pRenderer) - { - return; - } - - if (!m_pFont) - { - // For Editor. - ICryFont* pICryFont = m_pSystem->GetICryFont(); - - if (pICryFont) - { - m_pFont = m_pSystem->GetICryFont()->GetFont("default"); - } - } - - ScrollConsole(); - - if (!m_bConsoleActive && con_display_last_messages == 0) - { - return; - } - - if (m_pRenderer->GetIRenderAuxGeom()) - { - m_pRenderer->GetIRenderAuxGeom()->Flush(); - } - - m_pRenderer->EF_RenderTextMessages(); - - m_pRenderer->PushProfileMarker("DISPLAY_CONSOLE"); - - if (m_nScrollPos <= 0) - { - DrawBuffer(70, "console"); - } - else - { - // cursor blinking - { - m_fCursorBlinkTimer += gEnv->pTimer->GetRealFrameTime(); // works even when time is manipulated - // m_fCursorBlinkTimer += gEnv->pTimer->GetFrameTime(ITimer::ETIMER_UI); // can be used once ETIMER_UI works even with t_FixedTime - - const float fCursorBlinkDelay = 0.5f; // in sec (similar to Windows default but might differ from actual setting) - - if (m_fCursorBlinkTimer > fCursorBlinkDelay) - { - m_bDrawCursor = !m_bDrawCursor; - m_fCursorBlinkTimer = 0.0f; - } - } - - CScopedWireFrameMode scopedWireFrame(m_pRenderer, R_SOLID_MODE); - - if (!m_nProgressRange) - { - int whiteTexId = gEnv->pRenderer ? gEnv->pRenderer->GetWhiteTextureId() : -1; - - if (m_bStaticBackground) - { - m_pRenderer->SetState(GS_NODEPTHTEST); - m_pRenderer->Draw2dImage(0, 0, 800, 600, m_pImage ? m_pImage->GetTextureID() : whiteTexId, 0.0f, 1.0f, 1.0f, 0.0f); - } - else - { - TransformationMatrices backupSceneMatrices; - m_pRenderer->Set2DMode(m_pRenderer->GetWidth(), m_pRenderer->GetHeight(), backupSceneMatrices); - - float fReferenceSize = 600.0f; - - float fSizeX = (float)m_pRenderer->GetWidth(); - float fSizeY = m_nTempScrollMax * m_pRenderer->GetHeight() / fReferenceSize; - - m_pRenderer->SetState(GS_NODEPTHTEST | GS_BLSRC_SRCALPHA | GS_BLDST_ONEMINUSSRCALPHA); - m_pRenderer->DrawImage(0, 0, fSizeX, fSizeY, whiteTexId, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.7f); - m_pRenderer->DrawImage(0, fSizeY, fSizeX, 2.0f * m_pRenderer->GetHeight() / fReferenceSize, whiteTexId, 0, 0, 0, 0, 0.0f, 0.0f, 0.0f, 1.0f); - - m_pRenderer->Unset2DMode(backupSceneMatrices); - } - } - - // draw progress bar - if (m_nProgressRange) - { - m_pRenderer->SetState(GS_BLSRC_SRCALPHA | GS_BLDST_ONEMINUSSRCALPHA | GS_NODEPTHTEST); - m_pRenderer->Draw2dImage(0.0, 0.0, 800.0f, 600.0f, m_nLoadingBackTexID, 0.0f, 1.0f, 1.0f, 0.0f); - } - - DrawBuffer(m_nScrollPos, "console"); - } - - m_pRenderer->PopProfileMarker("DISPLAY_CONSOLE"); } -void CXConsole::DrawBuffer(int nScrollPos, const char* szEffect) +void CXConsole::DrawBuffer(int, const char*) { - if (m_pFont && m_pRenderer) - { - // The scroll position is in pixels for a 800x600 screen so we scale it to the current resolution. - Vec2 referenceSize(800.0f, 600.0f); - const float fontSizeIn800x600 = 14; - const float maxYPos = nScrollPos * (m_pRenderer->GetHeight() / referenceSize.y); - // We also scale the font from the original 800x600 size - float fontSize = fontSizeIn800x600 * (m_pRenderer->GetWidth() / referenceSize.x); - const float fontAspectRatio = 0.75f; - float minFontSize = 10.f; - float maxFontSize = 50.f; - ICVar* minFontCVar = GetCVar("r_minConsoleFontSize"); - if (minFontCVar) - { - minFontSize = minFontCVar->GetFVal(); - } - - ICVar* maxFontCVar = GetCVar("r_maxConsoleFontSize"); - if (maxFontCVar) - { - maxFontSize = maxFontCVar->GetFVal(); - } - - // Limit max font size in case minFontSize > maxFontSize - maxFontSize = AZStd::max(minFontSize, maxFontSize); - fontSize = AZStd::min(AZStd::max(fontSize, minFontSize), maxFontSize); - - STextDrawContext ctx; - //ctx.Reset(); - ctx.SetEffect(m_pFont->GetEffectId(szEffect)); - ctx.SetProportional(false); - ctx.SetCharWidthScale(0.5f); - ctx.SetSize(Vec2(fontSize, fontAspectRatio * fontSize)); - ctx.SetColor(ColorF(1, 1, 1, 1)); - ctx.SetFlags(eDrawText_CenterV | eDrawText_2D); - - float csize = 0.8f * ctx.GetCharHeight(); - ctx.SetSizeIn800x600(false); - - float yPos = maxYPos - csize - 3.0f; - float xPos = LINE_BORDER; - - float fCharWidth = (ctx.GetCharWidth() * ctx.GetCharWidthScale()); - - //int ypos=nScrollPos-csize-3; - - //Draw the input line - if (m_bConsoleActive && !m_nProgressRange) - { - /*m_pRenderer->DrawString(xPos-nCharWidth, yPos, false, ">"); - m_pRenderer->DrawString(xPos, yPos, false, m_sInputBuffer.c_str()); - if(m_bDrawCursor) - m_pRenderer->DrawString(xPos+nCharWidth*m_nCursorPos, yPos, false, "_");*/ - - m_pFont->DrawString((float)(xPos - fCharWidth), (float)yPos, ">", false, ctx); - m_pFont->DrawString((float)xPos, (float)yPos, m_sInputBuffer.c_str(), false, ctx); - - if (m_bDrawCursor) - { - string szCursorLeft(m_sInputBuffer.c_str(), m_sInputBuffer.c_str() + m_nCursorPos); - int n = m_pFont->GetTextLength(szCursorLeft.c_str(), false); - - m_pFont->DrawString((float)(xPos + (fCharWidth * n)), (float)yPos, "_", false, ctx); - } - } - - yPos -= csize; - - ConsoleBufferRItor ritor; - ritor = m_dqConsoleBuffer.rbegin(); - int nScroll = 0; - while (ritor != m_dqConsoleBuffer.rend() && yPos >= 0) - { - if (nScroll >= m_nScrollLine) - { - const char* buf = ritor->c_str();// GetBuf(k); - - if (*buf > 0 && *buf < 32) - { - buf++; // to jump over verbosity level character - } - if (yPos + csize > 0) - { - m_pFont->DrawString((float)xPos, (float)yPos, buf, false, ctx); - } - yPos -= csize; - } - nScroll++; - - ++ritor; - } //k - } } @@ -1828,44 +1612,6 @@ int CXConsole::GetLineCount() const ////////////////////////////////////////////////////////////////////////// void CXConsole::ScrollConsole() { - if (!m_pRenderer) - { - return; - } - - int nCurrHeight = m_pRenderer->GetHeight(); - - switch (m_sdScrollDir) - { - ///////////////////////////////// - case sdDOWN: // The console is scrolling down - - // Vlads note: console should go down immediately, otherwise it can look very bad on startup - //m_nScrollPos+=nCurrHeight/2; - m_nScrollPos = m_nTempScrollMax; - - if (m_nScrollPos > m_nTempScrollMax) - { - m_nScrollPos = m_nTempScrollMax; - m_sdScrollDir = sdNONE; - } - break; - ///////////////////////////////// - case sdUP: // The console is scrolling up - - m_nScrollPos -= nCurrHeight;//2; - - if (m_nScrollPos < 0) - { - m_nScrollPos = 0; - m_sdScrollDir = sdNONE; - } - break; - ///////////////////////////////// - case sdNONE: - break; - ///////////////////////////////// - } } @@ -2467,13 +2213,6 @@ void CXConsole::ExecuteStringInternal(const char* command, const bool bFromConso if (!sTemp.empty() || (pCVar->GetType() == CVAR_STRING)) { - // renderer cvars will be updated in the render thread - if ((pCVar->GetFlags() & VF_RENDERER_CVAR) && m_pRenderer) - { - m_pRenderer->SetRendererCVar(pCVar, sTemp.c_str(), bSilentMode); - continue; - } - pCVar->Set(sTemp.c_str()); } } @@ -2500,36 +2239,8 @@ void CXConsole::ExecuteDeferredCommands() { TDeferredCommandList::iterator it; - // const float fontHeight = 10; - // ColorF col = Col_Yellow; - // - // float curX = 10; - // float curY = 10; - - //IRenderer* pRenderer = gEnv->pRenderer; - - // Print the deferred messages - // it = m_deferredCommands.begin(); - // if (it != m_deferredCommands.end()) - // { - // pRenderer->Draw2dLabel( curX, curY += fontHeight, 1.2f, &col.r, false - // , "Pending deferred commands = %d", m_deferredCommands.size() ); - // } - // - // for ( - // ; it != m_deferredCommands.end() - // ; ++it - // ) - // { - // pRenderer->Draw2dLabel( curX + fontHeight * 2.0f, curY += fontHeight, 1.2f, &col.r, false - // , "Cmd: %s", it->command.c_str() ); - // } - if (m_waitFrames) { - // pRenderer->Draw2dLabel( curX, curY += fontHeight, 1.2f, &col.r, false - // , "Waiting frames = %d", m_waitFrames ); - --m_waitFrames; return; } @@ -2538,10 +2249,6 @@ void CXConsole::ExecuteDeferredCommands() { if (m_waitSeconds > gEnv->pTimer->GetFrameStartTime()) { - // pRenderer->Draw2dLabel( curX, curY += fontHeight, 1.2f, &col.r, false - // , "Waiting seconds = %f" - // , m_waitSeconds.GetSeconds() - gEnv->pTimer->GetFrameStartTime().GetSeconds() ); - return; } @@ -2566,8 +2273,6 @@ void CXConsole::ExecuteDeferredCommands() break; } } - - //m_deferredExecution = false; } ////////////////////////////////////////////////////////////////////////// @@ -3143,71 +2848,18 @@ void CXConsole::PostLine(const char* lineOfText, size_t len) } ////////////////////////////////////////////////////////////////////////// -void CXConsole::ResetProgressBar(int nProgressBarRange) +void CXConsole::ResetProgressBar(int) { - m_nProgressRange = nProgressBarRange; - m_nProgress = 0; - - if (nProgressBarRange < 0) - { - nProgressBarRange = 0; - } - - if (!m_nProgressRange) - { - if (m_nLoadingBackTexID) - { - if (m_pRenderer) - { - m_pRenderer->RemoveTexture(m_nLoadingBackTexID); - } - m_nLoadingBackTexID = -1; - } - } - - static ICVar* log_Verbosity = GetCVar("log_Verbosity"); - - if (log_Verbosity && (!log_Verbosity->GetIVal())) - { - Clear(); - } } ////////////////////////////////////////////////////////////////////////// void CXConsole::TickProgressBar() { - if (m_nProgressRange != 0 && m_nProgressRange > m_nProgress) - { - m_nProgress++; - m_pSystem->UpdateLoadingScreen(); - } - if (m_pSystem->GetIRenderer()) - { - m_pSystem->GetIRenderer()->FlushRTCommands(false, false, false); // Try to switch render thread contexts to make RT always busy during loading - } } ////////////////////////////////////////////////////////////////////////// -void CXConsole::SetLoadingImage(const char* szFilename) +void CXConsole::SetLoadingImage(const char*) { - ITexture* pTex = 0; - - pTex = m_pSystem->GetIRenderer()->EF_LoadTexture(szFilename, FT_DONT_STREAM | FT_NOMIPS); - - if (!pTex || (pTex->GetFlags() & FT_FAILED)) - { - SAFE_RELEASE(pTex); - pTex = m_pSystem->GetIRenderer()->EF_LoadTexture("Textures/Console/loadscreen_default.dds", FT_DONT_STREAM | FT_NOMIPS); - } - - if (pTex) - { - m_nLoadingBackTexID = pTex->GetTextureID(); - } - else - { - m_nLoadingBackTexID = -1; - } } ////////////////////////////////////////////////////////////////////////// diff --git a/Code/CryEngine/CrySystem/XConsole.h b/Code/CryEngine/CrySystem/XConsole.h index ed3a3e9b82..01649872ba 100644 --- a/Code/CryEngine/CrySystem/XConsole.h +++ b/Code/CryEngine/CrySystem/XConsole.h @@ -418,7 +418,6 @@ private: // ---------------------------------------------------------- CSystem* m_pSystem; IFFont* m_pFont; - IRenderer* m_pRenderer; ITimer* m_pTimer; ICVar* m_pSysDeactivateConsole; diff --git a/Code/CryEngine/CrySystem/crysystem_files.cmake b/Code/CryEngine/CrySystem/crysystem_files.cmake index bfc7b092fd..0b62483e43 100644 --- a/Code/CryEngine/CrySystem/crysystem_files.cmake +++ b/Code/CryEngine/CrySystem/crysystem_files.cmake @@ -19,7 +19,6 @@ set(FILES ConsoleBatchFile.cpp ConsoleHelpGen.cpp CryAsyncMemcpy.cpp - CrySizerStats.cpp DebugCallStack.cpp GeneralMemoryHeap.cpp HandlerBase.cpp @@ -57,7 +56,6 @@ set(FILES UnixConsole.h SystemInit.h Serialization/MemoryReader.h - MemoryFragmentationProfiler.h XML/ReadWriteXMLSink.h Serialization/ArchiveHost.h Serialization/MemoryWriter.h @@ -70,7 +68,6 @@ set(FILES CmdLineArg.h ConsoleBatchFile.h ConsoleHelpGen.h - CrySizerStats.h CryWaterMark.h DebugCallStack.h GeneralMemoryHeap.h @@ -92,13 +89,11 @@ set(FILES crash_face.bmp ImageHandler.h ImageHandler.cpp - DefragAllocator.cpp MemoryAddressRange.cpp PageMappingHeap.cpp CustomMemoryHeap.cpp MemoryManager.cpp MTSafeAllocator.cpp - DefragAllocator.h MemoryAddressRange.h PageMappingHeap.h MemoryManager.h @@ -118,10 +113,8 @@ set(FILES XML/WriteXMLSource.cpp ZipFile.h ZipFileFormat_info.h - PerfHUD.cpp ProfileLogSystem.cpp Sampler.cpp - PerfHUD.h ProfileLogSystem.h Sampler.h LocalizedStringManager.cpp @@ -138,24 +131,10 @@ set(FILES ExtensionSystem/CryFactoryRegistryImpl.h ExtensionSystem/TestCases/TestExtensions.cpp ExtensionSystem/TestCases/TestExtensions.h - MiniGUI/DrawContext.cpp - MiniGUI/MiniButton.cpp - MiniGUI/MiniGUI.cpp - MiniGUI/MiniInfoBox.cpp - MiniGUI/MiniMenu.cpp - MiniGUI/MiniTable.cpp - MiniGUI/DrawContext.h - MiniGUI/MiniButton.h - MiniGUI/MiniGUI.h - MiniGUI/MiniInfoBox.h - MiniGUI/MiniMenu.h - MiniGUI/MiniTable.h ZLibCompressor.cpp ZLibCompressor.h SoftCode/SoftCodeMgr.cpp SoftCode/SoftCodeMgr.h - OverloadSceneManager/OverloadSceneManager.cpp - OverloadSceneManager/OverloadSceneManager.h Huffman.cpp Huffman.h RemoteConsole/RemoteConsole.cpp @@ -197,8 +176,6 @@ set(FILES Serialization/XmlIArchive.h Serialization/XmlOArchive.cpp Serialization/XmlOArchive.h - HMDCVars.h - HMDCVars.cpp StreamEngine/StreamAsyncFileRequest.cpp StreamEngine/StreamAsyncFileRequest_Jobs.cpp StreamEngine/StreamEngine.cpp @@ -210,13 +187,9 @@ set(FILES StreamEngine/StreamIOThread.h StreamEngine/StreamReadStream.h StreamEngine/AZRequestReadStream.h - VisRegTest.cpp - VisRegTest.h CrashHandler.rc CrySystem_precompiled.cpp CPUDetect.cpp CPUDetect.h - CrySizerImpl.cpp - CrySizerImpl.h WindowsErrorReporting.cpp ) diff --git a/Code/CryEngine/CrySystem/crysystem_test_files.cmake b/Code/CryEngine/CrySystem/crysystem_test_files.cmake index 650e9b0063..fc236afcf3 100644 --- a/Code/CryEngine/CrySystem/crysystem_test_files.cmake +++ b/Code/CryEngine/CrySystem/crysystem_test_files.cmake @@ -15,7 +15,6 @@ set(FILES Tests/Test_CLog.cpp Tests/Test_CommandRegistration.cpp Tests/Test_CryPrimitives.cpp - Tests/Test_CrySizer.cpp Tests/test_CrySystem.cpp Tests/Test_Localization.cpp Tests/test_Main.cpp diff --git a/Code/Framework/AzFramework/AzFramework/Archive/ArchiveVars.h b/Code/Framework/AzFramework/AzFramework/Archive/ArchiveVars.h index fd72c37b60..4e89e0a45c 100644 --- a/Code/Framework/AzFramework/AzFramework/Archive/ArchiveVars.h +++ b/Code/Framework/AzFramework/AzFramework/Archive/ArchiveVars.h @@ -51,7 +51,6 @@ namespace AZ::IO : ArchiveLocationPriority::ePakPriorityFileFirst }; // Which file location to favor (loose vs. pak files) int nMessageInvalidFileAccess{}; int nLogInvalidFileAccess{ IsReleaseConfig ? 0 : 1 }; - int nLoadFrontendShaderCache{ FRONTEND_SHADER_CACHE_DEFAULT }; int nDisableNonLevelRelatedPaks{ 1 }; int nWarnOnPakAccessFails{ 1 }; // Whether to treat failed pak access as a warning or log message int nSetLogLevel{ 3 }; diff --git a/Code/Framework/AzFramework/Platform/Android/AzFramework/Archive/ArchiveVars_Android.h b/Code/Framework/AzFramework/Platform/Android/AzFramework/Archive/ArchiveVars_Android.h index f8ca242409..40fbe0bf30 100644 --- a/Code/Framework/AzFramework/Platform/Android/AzFramework/Archive/ArchiveVars_Android.h +++ b/Code/Framework/AzFramework/Platform/Android/AzFramework/Archive/ArchiveVars_Android.h @@ -13,4 +13,3 @@ #pragma once #define STREAM_CACHE_DEFAULT 0 -#define FRONTEND_SHADER_CACHE_DEFAULT 0 diff --git a/Code/Framework/AzFramework/Platform/Linux/AzFramework/Archive/ArchiveVars_Linux.h b/Code/Framework/AzFramework/Platform/Linux/AzFramework/Archive/ArchiveVars_Linux.h index f8ca242409..40fbe0bf30 100644 --- a/Code/Framework/AzFramework/Platform/Linux/AzFramework/Archive/ArchiveVars_Linux.h +++ b/Code/Framework/AzFramework/Platform/Linux/AzFramework/Archive/ArchiveVars_Linux.h @@ -13,4 +13,3 @@ #pragma once #define STREAM_CACHE_DEFAULT 0 -#define FRONTEND_SHADER_CACHE_DEFAULT 0 diff --git a/Code/Framework/AzFramework/Platform/Mac/AzFramework/Archive/ArchiveVars_Mac.h b/Code/Framework/AzFramework/Platform/Mac/AzFramework/Archive/ArchiveVars_Mac.h index f8ca242409..40fbe0bf30 100644 --- a/Code/Framework/AzFramework/Platform/Mac/AzFramework/Archive/ArchiveVars_Mac.h +++ b/Code/Framework/AzFramework/Platform/Mac/AzFramework/Archive/ArchiveVars_Mac.h @@ -13,4 +13,3 @@ #pragma once #define STREAM_CACHE_DEFAULT 0 -#define FRONTEND_SHADER_CACHE_DEFAULT 0 diff --git a/Code/Framework/AzFramework/Platform/Windows/AzFramework/Archive/ArchiveVars_Windows.h b/Code/Framework/AzFramework/Platform/Windows/AzFramework/Archive/ArchiveVars_Windows.h index f8ca242409..40fbe0bf30 100644 --- a/Code/Framework/AzFramework/Platform/Windows/AzFramework/Archive/ArchiveVars_Windows.h +++ b/Code/Framework/AzFramework/Platform/Windows/AzFramework/Archive/ArchiveVars_Windows.h @@ -13,4 +13,3 @@ #pragma once #define STREAM_CACHE_DEFAULT 0 -#define FRONTEND_SHADER_CACHE_DEFAULT 0 diff --git a/Code/Framework/AzFramework/Platform/iOS/AzFramework/Archive/ArchiveVars_iOS.h b/Code/Framework/AzFramework/Platform/iOS/AzFramework/Archive/ArchiveVars_iOS.h index f8ca242409..40fbe0bf30 100644 --- a/Code/Framework/AzFramework/Platform/iOS/AzFramework/Archive/ArchiveVars_iOS.h +++ b/Code/Framework/AzFramework/Platform/iOS/AzFramework/Archive/ArchiveVars_iOS.h @@ -13,4 +13,3 @@ #pragma once #define STREAM_CACHE_DEFAULT 0 -#define FRONTEND_SHADER_CACHE_DEFAULT 0 diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/API/ToolsApplicationAPI.h b/Code/Framework/AzToolsFramework/AzToolsFramework/API/ToolsApplicationAPI.h index 83e40474d6..82fa3f94f5 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/API/ToolsApplicationAPI.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/API/ToolsApplicationAPI.h @@ -761,16 +761,6 @@ namespace AzToolsFramework /// If the view pane was not registered with the ViewPaneOptions.isDeletable set to true, the view pane will be hidden instead. virtual void CloseViewPane(const char* /*paneName*/) {} - /// Request generation of all level cubemaps. - virtual void GenerateAllCubemaps() {} - - /// Regenerate cubemap for a particular entity. - /// \param entityId ID of the entity that the cubemap is for - /// \param cubemapOutputPath path to a image file to generate - /// \param hideEntity Indicates whether the entity should be hidden during cubemap generation. Controls whether the entity's current cubemap output is baked into the new cubemap. - virtual void GenerateCubemapForEntity(AZ::EntityId /*entityId*/, AZStd::string* /*cubemapOutputPath*/, bool /*hideEntity*/) {} - virtual void GenerateCubemapWithIDForEntity(AZ::EntityId /*entityId*/, AZ::Uuid /*cubemapId*/, AZStd::string* /*cubemapOutputPath*/, bool /*hideEntity*/, bool /*hasCubemapId*/) {} - //! Spawn asset browser for the appropriate asset types. virtual void BrowseForAssets(AssetBrowser::AssetSelectionModel& /*selection*/) = 0; diff --git a/Code/Sandbox/Editor/2DViewport.cpp b/Code/Sandbox/Editor/2DViewport.cpp index 0487c9381f..a511be0e2a 100644 --- a/Code/Sandbox/Editor/2DViewport.cpp +++ b/Code/Sandbox/Editor/2DViewport.cpp @@ -86,7 +86,6 @@ inline Vec3 SnapToSize(Vec3 v, double size) ////////////////////////////////////////////////////////////////////// Q2DViewport::Q2DViewport(QWidget* parent) : QtViewport(parent) - , m_renderer(nullptr) { // Scroll offset equals origin m_rcSelect.setRect(0, 0, 0, 0); @@ -528,15 +527,6 @@ void Q2DViewport::paintEvent([[maybe_unused]] QPaintEvent* event) ////////////////////////////////////////////////////////////////////////// int Q2DViewport::OnCreate() { - m_renderer = GetIEditor()->GetRenderer(); - assert (m_renderer != NULL); - if (m_renderer) - { - WIN_HWND previousContext = m_renderer->GetCurrentContextHWND(); - m_renderer->CreateContext(renderOverlayHWND()); - m_renderer->SetCurrentContext(previousContext); - } - // Calculate the View transformation matrix. CalculateViewTM(); @@ -641,10 +631,6 @@ void Q2DViewport::OnTitleMenu(QMenu* menu) ////////////////////////////////////////////////////////////////////////// void Q2DViewport::OnDestroy() { - if (m_renderer) - { - m_renderer->DeleteContext(renderOverlayHWND()); - } } ////////////////////////////////////////////////////////////////////////// diff --git a/Code/Sandbox/Editor/2DViewport.h b/Code/Sandbox/Editor/2DViewport.h index 818f01064c..d7e6ee17f4 100644 --- a/Code/Sandbox/Editor/2DViewport.h +++ b/Code/Sandbox/Editor/2DViewport.h @@ -159,7 +159,6 @@ protected: ////////////////////////////////////////////////////////////////////////// // Variables. ////////////////////////////////////////////////////////////////////////// - IRenderer* m_renderer; //! XY/XZ/YZ mode of this 2D viewport. EViewportType m_viewType; diff --git a/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyCtrl.cpp b/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyCtrl.cpp index f0367ffdc1..3f7a3142e9 100644 --- a/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyCtrl.cpp +++ b/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyCtrl.cpp @@ -28,7 +28,6 @@ void RegisterReflectedVarHandlers() registered = true; EBUS_EVENT(AzToolsFramework::PropertyTypeRegistrationMessages::Bus, RegisterPropertyType, aznew AnimationPropertyWidgetHandler()); EBUS_EVENT(AzToolsFramework::PropertyTypeRegistrationMessages::Bus, RegisterPropertyType, aznew FileResourceSelectorWidgetHandler()); - EBUS_EVENT(AzToolsFramework::PropertyTypeRegistrationMessages::Bus, RegisterPropertyType, aznew ShaderPropertyHandler()); EBUS_EVENT(AzToolsFramework::PropertyTypeRegistrationMessages::Bus, RegisterPropertyType, aznew ReverbPresetPropertyHandler()); EBUS_EVENT(AzToolsFramework::PropertyTypeRegistrationMessages::Bus, RegisterPropertyType, aznew SequencePropertyHandler()); EBUS_EVENT(AzToolsFramework::PropertyTypeRegistrationMessages::Bus, RegisterPropertyType, aznew SequenceIdPropertyHandler()); diff --git a/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyGenericCtrl.cpp b/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyGenericCtrl.cpp index 75344b2172..5fde2c39a5 100644 --- a/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyGenericCtrl.cpp +++ b/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyGenericCtrl.cpp @@ -26,7 +26,6 @@ #include // Editor -#include "ShadersDialog.h" #include "SelectLightAnimationDialog.h" #include "SelectSequenceDialog.h" #include "SelectEAXPresetDlg.h" @@ -78,16 +77,6 @@ void GenericPopupPropertyEditor::SetPropertyType(PropertyType type) m_propertyType = type; } -void ShaderPropertyEditor::onEditClicked() -{ - CShadersDialog cShaders(GetValue()); - if (cShaders.exec() == QDialog::Accepted) - { - SetValue(cShaders.GetSelection()); - } - -} - void ReverbPresetPropertyEditor::onEditClicked() { CSelectEAXPresetDlg PresetDlg(this); diff --git a/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyGenericCtrl.h b/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyGenericCtrl.h index cdbb18ae12..f0d5ed4db7 100644 --- a/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyGenericCtrl.h +++ b/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyGenericCtrl.h @@ -100,15 +100,6 @@ public: } }; -class ShaderPropertyEditor - : public GenericPopupPropertyEditor -{ -public: - ShaderPropertyEditor(QWidget* pParent = nullptr) - : GenericPopupPropertyEditor(pParent){} - void onEditClicked() override; -}; - class ReverbPresetPropertyEditor : public GenericPopupPropertyEditor { @@ -168,7 +159,6 @@ public: // So we use our own #define CONST_AZ_CRC(name, value) AZ::u32(value) -using ShaderPropertyHandler = GenericPopupWidgetHandler; using ReverbPresetPropertyHandler = GenericPopupWidgetHandler; using MissionObjPropertyHandler = GenericPopupWidgetHandler; using SequencePropertyHandler = GenericPopupWidgetHandler; diff --git a/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/ReflectedPropertyItem.cpp b/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/ReflectedPropertyItem.cpp index 13584d9b82..4ac5733401 100644 --- a/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/ReflectedPropertyItem.cpp +++ b/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/ReflectedPropertyItem.cpp @@ -268,7 +268,6 @@ void ReflectedPropertyItem::SetVariable(IVariable *var) case ePropertyUser: m_reflectedVarAdapter = new ReflectedVarUserAdapter; break; - case ePropertyShader: case ePropertyEquip: case ePropertyReverbPreset: case ePropertyGameToken: diff --git a/Code/Sandbox/Editor/CryEdit.cpp b/Code/Sandbox/Editor/CryEdit.cpp index b88aee8bd9..e413eb4d79 100644 --- a/Code/Sandbox/Editor/CryEdit.cpp +++ b/Code/Sandbox/Editor/CryEdit.cpp @@ -132,7 +132,6 @@ AZ_POP_DISABLE_WARNING #include "Util/AutoDirectoryRestoreFileDialog.h" #include "Util/EditorAutoLevelLoadTest.h" -#include "Util/Ruler.h" #include "Util/IndexedFiles.h" #include "AboutDialog.h" #include @@ -390,7 +389,6 @@ void CCryEditApp::RegisterActionHandlers() ON_COMMAND(ID_PREFERENCES, OnPreferences) ON_COMMAND(ID_REDO, OnRedo) ON_COMMAND(ID_TOOLBAR_WIDGET_REDO, OnRedo) - ON_COMMAND(ID_RELOAD_TEXTURES, OnReloadTextures) ON_COMMAND(ID_FILE_OPEN_LEVEL, OnOpenLevel) #ifdef ENABLE_SLICE_EDITOR ON_COMMAND(ID_FILE_NEW_SLICE, OnCreateSlice) @@ -527,12 +525,6 @@ public: bool m_bExportTexture = false; bool m_bMatEditMode = false; - bool m_bPrecacheShaders = false; - bool m_bPrecacheShadersLevels = false; - bool m_bPrecacheShaderList = false; - bool m_bStatsShaders = false; - bool m_bStatsShaderList = false; - bool m_bMergeShaders = false; bool m_bConsoleMode = false; bool m_bNullRenderer = false; @@ -574,12 +566,6 @@ public: { "exportTexture", m_bExportTexture }, { "test", m_bTest }, { "auto_level_load", m_bAutoLoadLevel }, - { "PrecacheShaders", m_bPrecacheShaders }, - { "PrecacheShadersLevels", m_bPrecacheShadersLevels }, - { "PrecacheShaderList", m_bPrecacheShaderList }, - { "StatsShaders", m_bStatsShaders }, - { "StatsShaderList", m_bStatsShaderList }, - { "MergeShaders", m_bMergeShaders }, { "MatEdit", m_bMatEditMode }, { "BatchMode", m_bConsoleMode }, { "NullRenderer", m_bNullRenderer }, @@ -1024,26 +1010,12 @@ void CCryEditApp::OutputStartupMessage(QString str) ////////////////////////////////////////////////////////////////////////// void CCryEditApp::InitFromCommandLine(CEditCommandLineInfo& cmdInfo) { - //! Setup flags from command line - if (cmdInfo.m_bPrecacheShaders || cmdInfo.m_bPrecacheShadersLevels || cmdInfo.m_bMergeShaders - || cmdInfo.m_bPrecacheShaderList || cmdInfo.m_bStatsShaderList || cmdInfo.m_bStatsShaders) - { - m_bPreviewMode = true; - m_bConsoleMode = true; - m_bTestMode = true; - } m_bConsoleMode |= cmdInfo.m_bConsoleMode; inEditorBatchMode = AZ::Environment::CreateVariable("InEditorBatchMode", m_bConsoleMode); m_bTestMode |= cmdInfo.m_bTest; m_bSkipWelcomeScreenDialog = cmdInfo.m_bSkipWelcomeScreenDialog || !cmdInfo.m_execFile.isEmpty() || !cmdInfo.m_execLineCmd.isEmpty() || cmdInfo.m_bAutotestMode; - m_bPrecacheShaderList = cmdInfo.m_bPrecacheShaderList; - m_bStatsShaderList = cmdInfo.m_bStatsShaderList; - m_bStatsShaders = cmdInfo.m_bStatsShaders; - m_bPrecacheShaders = cmdInfo.m_bPrecacheShaders; - m_bPrecacheShadersLevels = cmdInfo.m_bPrecacheShadersLevels; - m_bMergeShaders = cmdInfo.m_bMergeShaders; m_bExportMode = cmdInfo.m_bExport; m_bRunPythonTestScript = cmdInfo.m_bRunPythonTestScript; m_bRunPythonScript = cmdInfo.m_bRunPythonScript || cmdInfo.m_bRunPythonTestScript; @@ -1079,11 +1051,9 @@ void CCryEditApp::InitFromCommandLine(CEditCommandLineInfo& cmdInfo) ///////////////////////////////////////////////////////////////////////////// AZ::Outcome CCryEditApp::InitGameSystem(HWND hwndForInputSystem) { - bool bShaderCacheGen = m_bPrecacheShaderList | m_bPrecacheShaders | m_bPrecacheShadersLevels; - CGameEngine* pGameEngine = new CGameEngine; - AZ::Outcome initOutcome = pGameEngine->Init(m_bPreviewMode, m_bTestMode, bShaderCacheGen, qApp->arguments().join(" ").toUtf8().data(), g_pInitializeUIInfo, hwndForInputSystem); + AZ::Outcome initOutcome = pGameEngine->Init(m_bPreviewMode, m_bTestMode, qApp->arguments().join(" ").toUtf8().data(), g_pInitializeUIInfo, hwndForInputSystem); if (!initOutcome.IsSuccess()) { return initOutcome; @@ -1124,8 +1094,7 @@ BOOL CCryEditApp::CheckIfAlreadyRunning() } } - // Shader pre-caching may start multiple editor copies - if (!FirstInstance(bForceNewInstance) && !m_bPrecacheShaderList) + if (!FirstInstance(bForceNewInstance)) { return false; } @@ -1347,37 +1316,6 @@ void CCryEditApp::InitLevel(const CEditCommandLineInfo& cmdInfo) ///////////////////////////////////////////////////////////////////////////// BOOL CCryEditApp::InitConsole() { - if (m_bPrecacheShaderList) - { - GetIEditor()->GetSystem()->GetIConsole()->ExecuteString("r_PrecacheShaderList"); - return false; - } - else if (m_bStatsShaderList) - { - GetIEditor()->GetSystem()->GetIConsole()->ExecuteString("r_StatsShaderList"); - return false; - } - else if (m_bStatsShaders) - { - GetIEditor()->GetSystem()->GetIConsole()->ExecuteString("r_StatsShaders"); - return false; - } - else if (m_bPrecacheShaders) - { - GetIEditor()->GetSystem()->GetIConsole()->ExecuteString("r_PrecacheShaders"); - return false; - } - else if (m_bPrecacheShadersLevels) - { - GetIEditor()->GetSystem()->GetIConsole()->ExecuteString("r_PrecacheShadersLevels"); - return false; - } - else if (m_bMergeShaders) - { - GetIEditor()->GetSystem()->GetIConsole()->ExecuteString("r_MergeShaders"); - return false; - } - // Execute command from cmdline -exec_line if applicable if (!m_execLineCmd.isEmpty()) { @@ -2930,14 +2868,6 @@ void CCryEditApp::OnPreferences() */ } -void CCryEditApp::OnReloadTextures() -{ - QWaitCursor wait; - CLogFile::WriteLine("Reloading Static objects textures and shaders."); - GetIEditor()->GetObjectManager()->SendEvent(EVENT_RELOAD_TEXTURES); - GetIEditor()->GetRenderer()->EF_ReloadTextures(); -} - ////////////////////////////////////////////////////////////////////////// void CCryEditApp::OnUndo() { diff --git a/Code/Sandbox/Editor/CryEdit.h b/Code/Sandbox/Editor/CryEdit.h index c0b26a9405..97768b55c9 100644 --- a/Code/Sandbox/Editor/CryEdit.h +++ b/Code/Sandbox/Editor/CryEdit.h @@ -229,7 +229,6 @@ public: void OnFileResaveSlices(); void OnFileEditEditorini(); void OnPreferences(); - void OnReloadTextures(); void OnRedo(); void OnUpdateRedo(QAction* action); void OnUpdateUndo(QAction* action); @@ -284,12 +283,6 @@ private: //! Test mode is a special mode enabled when Editor ran with /test command line. //! In this mode editor starts up, but exit immediately after all initialization. bool m_bTestMode = false; - bool m_bPrecacheShaderList = false; - bool m_bPrecacheShaders = false; - bool m_bPrecacheShadersLevels = false; - bool m_bMergeShaders = false; - bool m_bStatsShaderList = false; - bool m_bStatsShaders = false; //! In this mode editor will load specified cry file, export t, and then close. bool m_bExportMode = false; QString m_exportFile; diff --git a/Code/Sandbox/Editor/CryEditDoc.cpp b/Code/Sandbox/Editor/CryEditDoc.cpp index ffcbd00a5f..83f7b482ae 100644 --- a/Code/Sandbox/Editor/CryEditDoc.cpp +++ b/Code/Sandbox/Editor/CryEditDoc.cpp @@ -51,7 +51,6 @@ #include "Include/IObjectManager.h" #include "ErrorReportDialog.h" #include "SurfaceTypeValidator.h" -#include "ShaderCache.h" #include "Util/AutoLogTime.h" #include "CheckOutDialog.h" #include "GameExporter.h" @@ -143,7 +142,6 @@ CCryEditDoc::CCryEditDoc() m_environmentTemplate = XmlHelpers::CreateXmlNode("Environment"); } - m_pLevelShaderCache = new CLevelShaderCache; m_bDocumentReady = false; GetIEditor()->SetDocument(this); CLogFile::WriteLine("Document created"); @@ -156,8 +154,6 @@ CCryEditDoc::~CCryEditDoc() { GetIEditor()->SetDocument(nullptr); - delete m_pLevelShaderCache; - CLogFile::WriteLine("Document destroyed"); AzToolsFramework::SliceEditorEntityOwnershipServiceNotificationBus::Handler::BusDisconnect(); @@ -337,7 +333,6 @@ void CCryEditDoc::Save(TDocMultiArchive& arrXmlAr) // Fog settings /////////////////////////////////////////////////////// SerializeFogSettings((*arrXmlAr[DMAS_GENERAL])); - SerializeShaderCache((*arrXmlAr[DMAS_GENERAL_NAMED_DATA])); SerializeNameSelection((*arrXmlAr[DMAS_GENERAL])); } } @@ -486,7 +481,6 @@ void CCryEditDoc::Load(TDocMultiArchive& arrXmlAr, const QString& szFilename) { // Serialize Shader Cache. CAutoLogTime logtime("Load Level Shader Cache"); - SerializeShaderCache((*arrXmlAr[DMAS_GENERAL_NAMED_DATA])); } { @@ -668,39 +662,6 @@ void CCryEditDoc::SerializeFogSettings(CXmlArchive& xmlAr) } } -void CCryEditDoc::SerializeShaderCache(CXmlArchive& xmlAr) -{ - if (xmlAr.bLoading) - { - void* pData = 0; - int nSize = 0; - - if (xmlAr.pNamedData->GetDataBlock("ShaderCache", pData, nSize)) - { - if (nSize <= 0) - { - return; - } - - QByteArray str(nSize + 1, 0); - memcpy(str.data(), pData, nSize); - str[nSize] = 0; - m_pLevelShaderCache->LoadBuffer(str); - } - } - else - { - QString buf; - - m_pLevelShaderCache->SaveBuffer(buf); - - if (!buf.isEmpty()) - { - xmlAr.pNamedData->AddDataBlock("ShaderCache", buf.toUtf8().data(), buf.toUtf8().count()); - } - } -} - void CCryEditDoc::SerializeNameSelection(CXmlArchive& xmlAr) { IObjectManager* pObjManager = GetIEditor()->GetObjectManager(); diff --git a/Code/Sandbox/Editor/CryEditDoc.h b/Code/Sandbox/Editor/CryEditDoc.h index be8a5fcec7..1ca3dc85f4 100644 --- a/Code/Sandbox/Editor/CryEditDoc.h +++ b/Code/Sandbox/Editor/CryEditDoc.h @@ -22,7 +22,6 @@ #include #endif -class CLevelShaderCache; class CClouds; struct LightingSettings; struct IVariable; @@ -123,7 +122,6 @@ public: // Create from serialization only const char* GetTemporaryLevelName() const; void DeleteTemporaryLevel(); - CLevelShaderCache* GetShaderCache() { return m_pLevelShaderCache; } CClouds* GetClouds() { return m_pClouds; } void SetWaterColor(const QColor& col) { m_waterColor = col; } QColor GetWaterColor() { return m_waterColor; } @@ -165,7 +163,6 @@ protected: bool LoadEntitiesFromSlice(const QString& sliceFile); void SerializeFogSettings(CXmlArchive& xmlAr); virtual void SerializeViewSettings(CXmlArchive& xmlAr); - void SerializeShaderCache(CXmlArchive& xmlAr); void SerializeNameSelection(CXmlArchive& xmlAr); void LogLoadTime(int time); @@ -201,7 +198,6 @@ protected: CClouds* m_pClouds; std::list m_listeners; bool m_bDocumentReady; - CLevelShaderCache* m_pLevelShaderCache; ICVar* doc_validate_surface_types; int m_modifiedModuleFlags; bool m_boLevelExported; diff --git a/Code/Sandbox/Editor/EditorFileMonitor.cpp b/Code/Sandbox/Editor/EditorFileMonitor.cpp index 1898ae5f7a..f627b61255 100644 --- a/Code/Sandbox/Editor/EditorFileMonitor.cpp +++ b/Code/Sandbox/Editor/EditorFileMonitor.cpp @@ -35,9 +35,6 @@ void CEditorFileMonitor::OnEditorNotifyEvent(EEditorNotifyEvent ev) { if (ev == eNotify_OnInit) { - // Setup file change monitoring - gEnv->pSystem->SetIFileChangeMonitor(this); - // We don't want the file monitor to be enabled while // in console mode... if (!GetIEditor()->IsInConsolewMode()) @@ -49,7 +46,6 @@ void CEditorFileMonitor::OnEditorNotifyEvent(EEditorNotifyEvent ev) } else if (ev == eNotify_OnQuit) { - gEnv->pSystem->SetIFileChangeMonitor(NULL); CFileChangeMonitor::Instance()->StopMonitor(); GetIEditor()->UnregisterNotifyListener(this); } diff --git a/Code/Sandbox/Editor/EditorFileMonitor.h b/Code/Sandbox/Editor/EditorFileMonitor.h index 9af68a6179..916c0cb11a 100644 --- a/Code/Sandbox/Editor/EditorFileMonitor.h +++ b/Code/Sandbox/Editor/EditorFileMonitor.h @@ -15,7 +15,6 @@ #define CRYINCLUDE_EDITOR_EDITORFILEMONITOR_H #pragma once #include "Include/IEditorFileMonitor.h" -#include "IFileChangeMonitor.h" #include "Util/FileChangeMonitor.h" class CEditorFileMonitor diff --git a/Code/Sandbox/Editor/EditorViewportWidget.cpp b/Code/Sandbox/Editor/EditorViewportWidget.cpp index 0b3ff87e43..717c476e0b 100644 --- a/Code/Sandbox/Editor/EditorViewportWidget.cpp +++ b/Code/Sandbox/Editor/EditorViewportWidget.cpp @@ -791,10 +791,6 @@ void EditorViewportWidget::OnRender() // This is necessary so that automated editor tests using the null renderer to test systems like dynamic vegetation // are still able to manipulate the current logical camera position, even if nothing is rendered. GetIEditor()->GetSystem()->SetViewCamera(m_Camera); - if (GetIEditor()->GetRenderer()) - { - GetIEditor()->GetRenderer()->SetCamera(gEnv->pSystem->GetViewCamera()); - } return; } diff --git a/Code/Sandbox/Editor/GameEngine.cpp b/Code/Sandbox/Editor/GameEngine.cpp index 073684eaad..1c91ce58aa 100644 --- a/Code/Sandbox/Editor/GameEngine.cpp +++ b/Code/Sandbox/Editor/GameEngine.cpp @@ -38,7 +38,6 @@ // CryCommon #include -#include #include #include @@ -46,7 +45,6 @@ #include "CryEdit.h" #include "ViewManager.h" -#include "Util/Ruler.h" #include "AnimationContext.h" #include "UndoViewPosition.h" #include "UndoViewRotation.h" @@ -386,7 +384,6 @@ void CGameEngine::SetCurrentViewRotation(const AZ::Vector3& rotation) AZ::Outcome CGameEngine::Init( bool bPreviewMode, bool bTestMode, - bool bShaderCacheGen, const char* sInCmdLine, IInitializeUIInfo* logo, HWND hwndForInputSystem) @@ -444,10 +441,6 @@ AZ::Outcome CGameEngine::Init( m_modalWindowDismisser = AZStd::make_unique(); } - if (bShaderCacheGen) - { - sip.bSkipFont = true; - } AssetProcessConnectionStatus apConnectionStatus; m_pISystem = pfnCreateSystemInterface(sip); @@ -620,12 +613,6 @@ void CGameEngine::SwitchToInGame() m_pISystem->GetIMovieSystem()->EnablePhysicsEvents(true); m_bInGameMode = true; - CRuler* pRuler = GetIEditor()->GetRuler(); - if (pRuler) - { - pRuler->SetActive(false); - } - gEnv->pSystem->GetViewCamera().SetMatrix(m_playerViewTM); // Disable accelerators. @@ -792,12 +779,6 @@ void CGameEngine::SetSimulationMode(bool enabled, bool bOnlyPhysics) if (enabled) { - CRuler* pRuler = GetIEditor()->GetRuler(); - if (pRuler) - { - pRuler->SetActive(false); - } - GetIEditor()->Notify(eNotify_OnBeginSimulationMode); } else @@ -923,9 +904,6 @@ void CGameEngine::Update() // but if in game mode, 'cos is already done in the above call to game->update() unsigned int updateFlags = ESYSUPDATE_EDITOR; - CRuler* pRuler = GetIEditor()->GetRuler(); - const bool bRulerNeedsUpdate = (pRuler && pRuler->HasQueuedPaths()); - if (!m_bSimulationMode) { updateFlags |= ESYSUPDATE_IGNORE_PHYSICS; diff --git a/Code/Sandbox/Editor/GameEngine.h b/Code/Sandbox/Editor/GameEngine.h index b59e2c9ac8..669b37bbb3 100644 --- a/Code/Sandbox/Editor/GameEngine.h +++ b/Code/Sandbox/Editor/GameEngine.h @@ -79,7 +79,6 @@ public: AZ::Outcome Init( bool bPreviewMode, bool bTestMode, - bool bShaderCacheGen, const char* sCmdLine, IInitializeUIInfo* logo, HWND hwndForInputSystem); diff --git a/Code/Sandbox/Editor/GameExporter.cpp b/Code/Sandbox/Editor/GameExporter.cpp index 1b42f75ba3..60746041a7 100644 --- a/Code/Sandbox/Editor/GameExporter.cpp +++ b/Code/Sandbox/Editor/GameExporter.cpp @@ -24,7 +24,6 @@ #include "GameExporter.h" #include "GameEngine.h" #include "CryEditDoc.h" -#include "ShaderCache.h" #include "UsedResources.h" #include "WaitProgress.h" #include "Util/CryMemFile.h" @@ -197,7 +196,6 @@ bool CGameExporter::Export(unsigned int flags, [[maybe_unused]] EEndian eExportE ExportLevelResourceList(sLevelPath); ExportLevelUsedResourceList(sLevelPath); - ExportLevelShaderCache(sLevelPath); ////////////////////////////////////////////////////////////////////////// // End Exporting Game data. @@ -379,18 +377,6 @@ void CGameExporter::ExportLevelUsedResourceList(const QString& path) m_levelPak.m_pakFile.UpdateFile(resFile.toUtf8().data(), memFile, true); } -////////////////////////////////////////////////////////////////////////// -void CGameExporter::ExportLevelShaderCache(const QString& path) -{ - QString buf; - GetIEditor()->GetDocument()->GetShaderCache()->SaveBuffer(buf); - CCryMemFile memFile; - memFile.Write(buf.toUtf8().data(), buf.toUtf8().length()); - - QString filename = Path::Make(path, SHADER_LIST_FILE); - m_levelPak.m_pakFile.UpdateFile(filename.toUtf8().data(), memFile, true); -} - ////////////////////////////////////////////////////////////////////////// void CGameExporter::ExportFileList(const QString& path, const QString& levelName) { diff --git a/Code/Sandbox/Editor/GameExporter.h b/Code/Sandbox/Editor/GameExporter.h index 18ec79189a..08af3e7473 100644 --- a/Code/Sandbox/Editor/GameExporter.h +++ b/Code/Sandbox/Editor/GameExporter.h @@ -95,8 +95,6 @@ private: void ExportLevelResourceList(const QString& path); void ExportLevelUsedResourceList(const QString& path); - void ExportLevelShaderCache(const QString& path); - void ExportGameData(const QString& path); void ExportFileList(const QString& path, const QString& levelName); void Error(const QString& error); diff --git a/Code/Sandbox/Editor/IEditor.h b/Code/Sandbox/Editor/IEditor.h index f11beacf10..62672a6505 100644 --- a/Code/Sandbox/Editor/IEditor.h +++ b/Code/Sandbox/Editor/IEditor.h @@ -66,7 +66,6 @@ class CDialog; #if defined(AZ_PLATFORM_WINDOWS) class C3DConnexionDriver; #endif -class CRuler; class CSettingsManager; struct IExportManager; class CDisplaySettings; @@ -425,7 +424,6 @@ struct IEditor virtual void DeleteThis() = 0; //! Access to Editor ISystem interface. virtual ISystem* GetSystem() = 0; - virtual IRenderer* GetRenderer() = 0; //! Access to class factory. virtual IEditorClassFactory* GetClassFactory() = 0; //! Access to commands manager. @@ -589,8 +587,6 @@ struct IEditor virtual void SetSelectedRegion(const AABB& box) = 0; //! Get currently selected region. virtual void GetSelectedRegion(AABB& box) = 0; - //! Get current ruler - virtual CRuler* GetRuler() = 0; virtual void SetOperationMode(EOperationMode mode) = 0; virtual EOperationMode GetOperationMode() = 0; @@ -635,7 +631,6 @@ struct IEditor //! Returns true if selection is made and false if selection is canceled. virtual bool SelectColor(QColor& color, QWidget* parent = 0) = 0; //! Get shader enumerator. - virtual class CShaderEnum* GetShaderEnum() = 0; virtual class CUndoManager* GetUndoManager() = 0; //! Begin operation requiring undo //! Undo manager enters holding state. diff --git a/Code/Sandbox/Editor/IEditorImpl.cpp b/Code/Sandbox/Editor/IEditorImpl.cpp index 53a2c120c4..95091a5992 100644 --- a/Code/Sandbox/Editor/IEditorImpl.cpp +++ b/Code/Sandbox/Editor/IEditorImpl.cpp @@ -49,7 +49,6 @@ AZ_POP_DISABLE_WARNING #include "Objects/GizmoManager.h" #include "Objects/AxisGizmo.h" #include "DisplaySettings.h" -#include "ShaderEnum.h" #include "KeyboardCustomizationSettings.h" #include "Export/ExportManager.h" #include "LevelIndependentFileMan.h" @@ -60,7 +59,6 @@ AZ_POP_DISABLE_WARNING #include "MainWindow.h" #include "Alembic/AlembicCompiler.h" #include "UIEnumsDatabase.h" -#include "Util/Ruler.h" #include "RenderHelpers/AxisHelper.h" #include "Settings.h" #include "Include/IObjectManager.h" @@ -134,7 +132,6 @@ CEditorImpl::CEditorImpl() , m_bUpdates(true) , m_bTerrainAxisIgnoreObjects(false) , m_pDisplaySettings(nullptr) - , m_pShaderEnum(nullptr) , m_pIconManager(nullptr) , m_bSelectionLocked(true) , m_pAxisGizmo(nullptr) @@ -149,7 +146,6 @@ CEditorImpl::CEditorImpl() , m_pSourceControl(nullptr) , m_pSelectionTreeManager(nullptr) , m_pUIEnumsDatabase(nullptr) - , m_pRuler(nullptr) , m_pConsoleSync(nullptr) , m_pSettingsManager(nullptr) , m_pLevelIndependentFileMan(nullptr) @@ -185,7 +181,6 @@ CEditorImpl::CEditorImpl() m_pBackgroundScheduleManager.reset(new BackgroundScheduleManager::CScheduleManager); m_pUIEnumsDatabase = new CUIEnumsDatabase; m_pDisplaySettings = new CDisplaySettings; - m_pShaderEnum = new CShaderEnum; m_pDisplaySettings->LoadRegistry(); m_pPluginManager = new CPluginManager; @@ -202,7 +197,6 @@ CEditorImpl::CEditorImpl() m_pImageUtil = new CImageUtil_impl(); m_pResourceSelectorHost.reset(CreateResourceSelectorHost()); - m_pRuler = new CRuler; m_selectedRegion.min = Vec3(0, 0, 0); m_selectedRegion.max = Vec3(0, 0, 0); DetectVersion(); @@ -335,8 +329,6 @@ CEditorImpl::~CEditorImpl() } SAFE_DELETE(m_pDisplaySettings) - SAFE_DELETE(m_pRuler) - SAFE_DELETE(m_pShaderEnum) SAFE_DELETE(m_pToolBoxManager) SAFE_DELETE(m_pCommandManager) SAFE_DELETE(m_pClassFactory) @@ -419,7 +411,6 @@ void CEditorImpl::Update() m_bUpdates = false; FUNCTION_PROFILER(GetSystem(), PROFILE_EDITOR); - m_pRuler->Update(); //@FIXME: Restore this latter. //if (GetGameEngine() && GetGameEngine()->IsLevelLoaded()) @@ -440,15 +431,6 @@ ISystem* CEditorImpl::GetSystem() return m_pSystem; } -IRenderer* CEditorImpl::GetRenderer() -{ - if (gEnv) - { - return gEnv->pRenderer; - } - return nullptr; -} - IEditorClassFactory* CEditorImpl::GetClassFactory() { return m_pClassFactory; @@ -1182,11 +1164,6 @@ void CEditorImpl::AddTemplate(const QString& templateName, XmlNodeRef& tmpl) m_templateRegistry.AddTemplate(templateName, tmpl); } -CShaderEnum* CEditorImpl::GetShaderEnum() -{ - return m_pShaderEnum; -} - bool CEditorImpl::ExecuteConsoleApp(const QString& CommandLine, QString& OutputText, [[maybe_unused]] bool bNoTimeOut, bool bShowWindow) { CLogFile::FormatLine("Executing console application '%s'", CommandLine.toUtf8().data()); @@ -1569,7 +1546,6 @@ void CEditorImpl::ReduceMemory() GetIEditor()->GetUndoManager()->ClearRedoStack(); GetIEditor()->GetUndoManager()->ClearUndoStack(); GetIEditor()->GetObjectManager()->SendEvent(EVENT_FREE_GAME_DATA); - gEnv->pRenderer->FreeResources(FRR_TEXTURES); #if defined(AZ_PLATFORM_WINDOWS) HANDLE hHeap = GetProcessHeap(); diff --git a/Code/Sandbox/Editor/IEditorImpl.h b/Code/Sandbox/Editor/IEditorImpl.h index bbef338cb2..7ad97d79e5 100644 --- a/Code/Sandbox/Editor/IEditorImpl.h +++ b/Code/Sandbox/Editor/IEditorImpl.h @@ -53,7 +53,6 @@ class CAlembicCompiler; struct IBackgroundTaskManager; struct IBackgroundScheduleManager; struct IEditorFileMonitor; -class CShaderEnum; class CVegetationMap; @@ -116,7 +115,6 @@ public: bool IsInitialized() const{ return m_bInitialized; } bool SaveDocument(); ISystem* GetSystem(); - IRenderer* GetRenderer(); void WriteToConsole(const char* string) { CLogFile::WriteLine(string); }; void WriteToConsole(const QString& string) { CLogFile::WriteLine(string); }; // Change the message in the status bar @@ -215,7 +213,6 @@ public: void SetMarkerPosition(const Vec3& pos) { m_marker = pos; }; void SetSelectedRegion(const AABB& box); void GetSelectedRegion(AABB& box); - CRuler* GetRuler() { return m_pRuler; } bool AddToolbarItem(uint8 iId, IUIEvent* pIHandler); void SetDataModified(); void SetOperationMode(EOperationMode mode); @@ -256,7 +253,6 @@ public: SFileVersion GetFileVersion() { return m_fileVersion; }; SFileVersion GetProductVersion() { return m_productVersion; }; //! Get shader enumerator. - CShaderEnum* GetShaderEnum(); CUndoManager* GetUndoManager() { return m_pUndoManager; }; void BeginUndo(); void RestoreUndo(bool undo); @@ -365,7 +361,6 @@ protected: SFileVersion m_productVersion; CXmlTemplateRegistry m_templateRegistry; CDisplaySettings* m_pDisplaySettings; - CShaderEnum* m_pShaderEnum; CIconManager* m_pIconManager; std::unique_ptr m_pGizmoParameters; QString m_primaryCDFolder; @@ -390,8 +385,6 @@ protected: CSelectionTreeManager* m_pSelectionTreeManager; CUIEnumsDatabase* m_pUIEnumsDatabase; - //! Currently used ruler - CRuler* m_pRuler; //! CConsole Synchronization CConsoleSynchronization* m_pConsoleSync; //! Editor Settings Manager diff --git a/Code/Sandbox/Editor/Include/IEditorFileMonitor.h b/Code/Sandbox/Editor/Include/IEditorFileMonitor.h index 670e4fdf7e..cfd14f8942 100644 --- a/Code/Sandbox/Editor/Include/IEditorFileMonitor.h +++ b/Code/Sandbox/Editor/Include/IEditorFileMonitor.h @@ -15,9 +15,43 @@ #define CRYINCLUDE_EDITOR_INCLUDE_IEDITORFILEMONITOR_H #pragma once -#include +struct IFileChangeListener +{ + enum EChangeType + { + //! error or unknown change type + eChangeType_Unknown, + //! the file was created + eChangeType_Created, + //! the file was deleted + eChangeType_Deleted, + //! the file was modified (size changed,write) + eChangeType_Modified, + //! this is the old name of a renamed file + eChangeType_RenamedOldName, + //! this is the new name of a renamed file + eChangeType_RenamedNewName + }; -struct IFileChangeListener; + virtual ~IFileChangeListener() = default; + + virtual void OnFileChange(const char* sFilename, EChangeType eType) = 0; +}; + +struct IFileChangeMonitor +{ + virtual ~IFileChangeMonitor() = default; + + // + // Register the path of a file or directory to monitor + // Path is relative to game directory, e.g. "Libs/WoundSystem/" or "Libs/WoundSystem/HitLocations.xml" + virtual bool RegisterListener(IFileChangeListener* pListener, const char* sMonitorItem) = 0; + // This function can be used to monitor files of specific type, e.g. + // RegisterListener(pListener, "Animations", "caf") + virtual bool RegisterListener(IFileChangeListener* pListener, const char* sFolder, const char* sExtension) = 0; + virtual bool UnregisterListener(IFileChangeListener* pListener) = 0; + // +}; struct IEditorFileMonitor : public IFileChangeMonitor diff --git a/Code/Sandbox/Editor/Include/ObjectEvent.h b/Code/Sandbox/Editor/Include/ObjectEvent.h index 3f6addb736..e90610872f 100644 --- a/Code/Sandbox/Editor/Include/ObjectEvent.h +++ b/Code/Sandbox/Editor/Include/ObjectEvent.h @@ -33,7 +33,6 @@ enum ObjectEvent EVENT_DBLCLICK, //!< Signals that object have been double clicked. EVENT_KEEP_HEIGHT, //!< Signals that object must preserve its height over changed terrain. EVENT_RELOAD_ENTITY,//!< Signals that entities scripts must be reloaded. - EVENT_RELOAD_TEXTURES,//!< Signals that all possible textures in objects should be reloaded. EVENT_RELOAD_GEOM, //!< Signals that all possible geometries should be reloaded. EVENT_UNLOAD_GEOM, //!< Signals that all possible geometries should be unloaded. EVENT_MISSION_CHANGE, //!< Signals that mission have been changed. diff --git a/Code/Sandbox/Editor/Lib/Tests/IEditorMock.h b/Code/Sandbox/Editor/Lib/Tests/IEditorMock.h index 4a20bd6b60..38a35e6684 100644 --- a/Code/Sandbox/Editor/Lib/Tests/IEditorMock.h +++ b/Code/Sandbox/Editor/Lib/Tests/IEditorMock.h @@ -32,7 +32,6 @@ public: public: MOCK_METHOD0(DeleteThis, void()); MOCK_METHOD0(GetSystem, ISystem*()); - MOCK_METHOD0(GetRenderer, IRenderer* ()); MOCK_METHOD0(GetClassFactory, IEditorClassFactory* ()); MOCK_METHOD0(GetCommandManager, CEditorCommandManager*()); MOCK_METHOD0(GetICommandManager, ICommandManager* ()); @@ -117,7 +116,6 @@ public: MOCK_METHOD1(SetMarkerPosition, void(const Vec3&)); MOCK_METHOD1(SetSelectedRegion, void(const AABB& box)); MOCK_METHOD1(GetSelectedRegion, void(AABB& box)); - MOCK_METHOD0(GetRuler, CRuler* ()); MOCK_METHOD1(SetOperationMode, void(EOperationMode )); MOCK_METHOD0(GetOperationMode, EOperationMode()); MOCK_METHOD1(ShowTransformManipulator, ITransformManipulator* (bool)); @@ -140,7 +138,6 @@ public: MOCK_METHOD1(OpenWinWidget, QWidget* (WinWidgetId )); MOCK_CONST_METHOD0(GetWinWidgetManager, WinWidget::WinWidgetManager* ()); MOCK_METHOD2(SelectColor, bool(QColor &, QWidget *)); - MOCK_METHOD0(GetShaderEnum, class CShaderEnum* ()); MOCK_METHOD0(GetUndoManager, class CUndoManager* ()); MOCK_METHOD0(BeginUndo, void()); MOCK_METHOD1(RestoreUndo, void(bool)); diff --git a/Code/Sandbox/Editor/MainWindow.cpp b/Code/Sandbox/Editor/MainWindow.cpp index e9bfd96a1d..cd55ccd2da 100644 --- a/Code/Sandbox/Editor/MainWindow.cpp +++ b/Code/Sandbox/Editor/MainWindow.cpp @@ -1075,8 +1075,6 @@ void MainWindow::InitActions() .RegisterUpdateCallback(cryEdit, &CCryEditApp::OnUpdateSelected); // Tools actions - am->AddAction(ID_RELOAD_TEXTURES, tr("Reload Textures/Shaders")) - .SetStatusTip(tr("Reload all textures.")); am->AddAction(ID_TOOLS_ENABLEFILECHANGEMONITORING, tr("Enable File Change Monitoring")); am->AddAction(ID_CLEAR_REGISTRY, tr("Clear Registry Data")) .SetStatusTip(tr("Clear Registry Data")); diff --git a/Code/Sandbox/Editor/Objects/BaseObject.cpp b/Code/Sandbox/Editor/Objects/BaseObject.cpp index 3ec505172e..6819bb5469 100644 --- a/Code/Sandbox/Editor/Objects/BaseObject.cpp +++ b/Code/Sandbox/Editor/Objects/BaseObject.cpp @@ -894,314 +894,10 @@ void CBaseObject::DrawDefault(DisplayContext& dc, const QColor& labelColor) } ////////////////////////////////////////////////////////////////////////// -void CBaseObject::DrawDimensions(DisplayContext& dc, AABB* pMergedBoundBox) +void CBaseObject::DrawDimensions(DisplayContext&, AABB*) { - if (HasMeasurementAxis() && GetIEditor()->GetDisplaySettings()->IsDisplayDimensionFigures()) - { - AABB localBoundBox; - GetLocalBounds(localBoundBox); - DrawDimensionsImpl(dc, localBoundBox, pMergedBoundBox); - } } -////////////////////////////////////////////////////////////////////////// -void CBaseObject::DrawDimensionsImpl(DisplayContext& dc, const AABB& localBoundBox, AABB* pMergedBoundBox) -{ - AABB boundBox; - Matrix34 rotatedTM; - bool bHave2Axis(false); - float xLength(0); - float yLength(0); - float zLength(0); - - if (pMergedBoundBox) - { - rotatedTM = Matrix34::CreateIdentity(); - boundBox = *pMergedBoundBox; - xLength = boundBox.max.x - boundBox.min.x; - zLength = boundBox.max.z - boundBox.min.z; - yLength = boundBox.max.y - boundBox.min.y; - } - else - { - rotatedTM = GetWorldRotTM(); - Matrix34 scaledTranslatedTM = GetWorldScaleTM(); - scaledTranslatedTM.SetTranslation(GetWorldPos()); - boundBox.SetTransformedAABB(scaledTranslatedTM, localBoundBox); - - IVariable* pVarXLength(NULL); - IVariable* pVarYLength(NULL); - IVariable* pVarZLength(NULL); - - IVariable* pVarDimX(NULL); - IVariable* pVarDimY(NULL); - IVariable* pVarDimZ(NULL); - - CVarBlock* pVarBlock(GetVarBlock()); - if (pVarBlock) - { - pVarXLength = pVarBlock->FindVariable("Width"); - pVarYLength = pVarBlock->FindVariable("Length"); - pVarZLength = pVarBlock->FindVariable("Height"); - pVarDimX = pVarBlock->FindVariable("DimX"); - pVarDimY = pVarBlock->FindVariable("DimY"); - pVarDimZ = pVarBlock->FindVariable("DimZ"); - } - - xLength = boundBox.max.x - boundBox.min.x; - zLength = boundBox.max.z - boundBox.min.z; - yLength = boundBox.max.y - boundBox.min.y; - - if (pVarDimX && pVarDimY && pVarDimZ) - { - pVarDimX->Get(xLength); - pVarDimZ->Get(zLength); - pVarDimY->Get(yLength); - xLength *= m_scale.x; - zLength *= m_scale.z; - yLength *= m_scale.y; - } - else if (pVarXLength && pVarYLength && pVarZLength) - { - // A case of an area box. - pVarXLength->Get(xLength); - pVarZLength->Get(zLength); - pVarYLength->Get(yLength); - xLength *= m_scale.x; - zLength *= m_scale.z; - yLength *= m_scale.y; - } - else if (!pVarXLength && !pVarYLength && pVarZLength) - { - // A case of an area shape. - pVarZLength->Get(zLength); - zLength *= m_scale.z; - } - } - - const float kMinimumLimitation(0.4f); - if (xLength < kMinimumLimitation && yLength < kMinimumLimitation && zLength < kMinimumLimitation) - { - return; - } - - const float kEpsilon(0.001f); - bHave2Axis = fabs(zLength) < kEpsilon; - - Vec3 basePoints[] = { - Vec3(boundBox.min.x, boundBox.min.y, boundBox.min.z), - Vec3(boundBox.min.x, boundBox.max.y, boundBox.min.z), - Vec3(boundBox.max.x, boundBox.max.y, boundBox.min.z), - Vec3(boundBox.max.x, boundBox.min.y, boundBox.min.z), - Vec3(boundBox.min.x, boundBox.min.y, boundBox.max.z), - Vec3(boundBox.min.x, boundBox.max.y, boundBox.max.z), - Vec3(boundBox.max.x, boundBox.max.y, boundBox.max.z), - Vec3(boundBox.max.x, boundBox.min.y, boundBox.max.z) - }; - const int kElementSize(sizeof(basePoints) / sizeof(*basePoints)); - Vec3 axisDirections[kElementSize] = { Vec3(1, 1, 1), Vec3(1, -1, 1), Vec3(-1, -1, 1), Vec3(-1, 1, 1), Vec3(1, 1, -1), Vec3(1, -1, -1), Vec3(-1, -1, -1), Vec3(-1, 1, -1) }; - int nLoopCount = bHave2Axis ? (kElementSize / 2) : kElementSize; - if (bHave2Axis) - { - for (int i = 0; i < nLoopCount; ++i) - { - basePoints[i].z = 0.5f * (boundBox.min.z + boundBox.max.z); - } - } - - // Find out the nearest base point of a bounding box from a camera position and use it as a pivot. - const CCamera& camera = gEnv->pRenderer->GetCamera(); - Vec3 cameraPos(camera.GetPosition()); - Vec3 pivot(rotatedTM.TransformVector(basePoints[0] - GetWorldPos()) + GetWorldPos()); - float fNearestDist = (cameraPos - pivot).GetLength(); - int nNearestAxisIndex(0); - bool bPrevVisible(camera.IsPointVisible(pivot)); - - for (int i = 1; i < nLoopCount; ++i) - { - Vec3 candidatePivot(rotatedTM.TransformVector(basePoints[i] - GetWorldPos()) + GetWorldPos()); - float candidateLength = (candidatePivot - cameraPos).GetLength(); - bool bVisible = camera.IsPointVisible(candidatePivot); - if (bVisible) - { - if (!bPrevVisible || candidateLength < fNearestDist) - { - fNearestDist = candidateLength; - pivot = candidatePivot; - nNearestAxisIndex = i; - } - bPrevVisible = bVisible; - } - } - - float fScale = dc.view->GetScreenScaleFactor(pivot); - float fArrowScale = fScale * 0.04f; - - Vec3 vX(xLength, 0, 0); - Vec3 vY(0, yLength, 0); - Vec3 vZ(0, 0, zLength); - - vX = vX * axisDirections[nNearestAxisIndex].x; - vY = vY * axisDirections[nNearestAxisIndex].y; - vZ = vZ * axisDirections[nNearestAxisIndex].z; - vX = rotatedTM.TransformVector(vX); - vY = rotatedTM.TransformVector(vY); - vZ = rotatedTM.TransformVector(vZ); - - const float kArrowPivotOffset = 0.1f; - pivot = pivot + (-(vX + vY + vZ)).GetNormalized() * kArrowPivotOffset; - - Vec3 centerPt(boundBox.GetCenter()); - - // Display texts of width, height and depth - float fTextScale(1.3f); - dc.SetColor(QColor(200, 200, 200)); - QString str; - - const float kBrightness(0.35f); - const ColorF kXColor(1.0f, kBrightness, kBrightness, 0.9f); - const ColorF kYColor(kBrightness, 1.0f, kBrightness, 0.9f); - const ColorF kZColor(kBrightness, kBrightness, 1.0f, 0.9f); - const ColorF TextBoxColor(0, 0, 0, 0.75f); - - ColorB backupcolor = dc.GetColor(); - uint32 backupstate = dc.GetState(); - int backupThickness = dc.GetLineWidth(); - - dc.SetState(backupstate | e_DepthTestOff); - - Vec3 vNX = vX.GetNormalized(); - Vec3 vNY = vY.GetNormalized(); - Vec3 vNZ = vZ.GetNormalized(); - - const float kMinimumOffset(0.20f); - const float kMaximumOffset(30.0f); - float fMaximumOffset[3] = { kMaximumOffset, kMaximumOffset, kMaximumOffset }; - if (xLength > kMaximumOffset * 0.5f) - { - fMaximumOffset[0] = xLength * 3.0f; - } - if (yLength > kMaximumOffset * 0.5f) - { - fMaximumOffset[1] = yLength * 3.0f; - } - if (zLength > kMaximumOffset * 0.5f) - { - fMaximumOffset[2] = zLength * 3.0f; - } - Vec3 textPos[3] = {pivot, pivot, pivot}; - Vec3 textMinPos[3] = { pivot + vNX * kMinimumOffset, pivot + vNY * kMinimumOffset, pivot + vNZ * kMinimumOffset }; - Vec3 textCenterPos[3] = { pivot + vX * 0.5f, pivot + vY * 0.5f, pivot + vZ * 0.5f }; - Vec3 textMaxPos[3] = { pivot + vNX * fMaximumOffset[0], pivot + vNY * fMaximumOffset[1], pivot + vNZ * fMaximumOffset[2] }; - - const Vec3& cameraDir(camera.GetViewdir()); - - for (int i = 0; i < 3; ++i) - { - Vec3 d = (textMaxPos[i] - cameraPos).GetNormalized(); - float fCameraDir = d.Dot(cameraDir); - if (fCameraDir < 0) - { - fCameraDir = 0; - } - textPos[i] = textMinPos[i] + (textCenterPos[i] - textPos[i]) * fCameraDir; - } - - str = QString::number(xLength, 'f', 3); - DrawTextOn2DBox(dc, textPos[0], str.toUtf8().data(), fTextScale, kXColor, TextBoxColor); - - if (!bHave2Axis) - { - str = QString::number(zLength, 'f', 3); - DrawTextOn2DBox(dc, textPos[2], str.toUtf8().data(), fTextScale, kZColor, TextBoxColor); - } - - str = QString::number(yLength, 'f', 3); - DrawTextOn2DBox(dc, textPos[1], str.toUtf8().data(), fTextScale, kYColor, TextBoxColor); - - dc.SetState(backupstate | e_DepthTestOn); - dc.SetLineWidth(4); - - // Draw arrows of each axis. - dc.SetColor(kXColor); - dc.DrawArrow(pivot, pivot + vX, fArrowScale, true); - if (!bHave2Axis) - { - dc.SetColor(kZColor); - dc.DrawArrow(pivot, pivot + vZ, fArrowScale, true); - } - dc.SetColor(kYColor); - dc.DrawArrow(pivot, pivot + vY, fArrowScale, true); - - dc.SetState(backupstate); - dc.SetColor(backupcolor); - dc.SetLineWidth(backupThickness); -} - -////////////////////////////////////////////////////////////////////////// -void CBaseObject::DrawTextOn2DBox(DisplayContext& dc, const Vec3& pos, const char* text, float textScale, const ColorF& TextColor, const ColorF& TextBackColor) -{ - Vec3 worldPos = dc.ToWorldSpacePosition(pos); - int vx, vy, vw, vh; - gEnv->pRenderer->GetViewport(&vx, &vy, &vw, &vh); - - const CCamera& camera = gEnv->pRenderer->GetCamera(); - Vec3 screenPos; - camera.Project(worldPos, screenPos, Vec2i(0, 0), Vec2i(0, 0)); - - //! Font size information doesn't seem to exist so the proper size is used - int textlen = strlen(text); - float fontsize = 7.5f; - float textwidth = fontsize * textlen; - float textheight = 16.0f; - - screenPos.x = screenPos.x - textwidth * 0.5f; - - Vec3 textregion[4] = { - Vec3(screenPos.x, screenPos.y, screenPos.z), - Vec3(screenPos.x + textwidth, screenPos.y, screenPos.z), - Vec3(screenPos.x + textwidth, screenPos.y + textheight, screenPos.z), - Vec3(screenPos.x, screenPos.y + textheight, screenPos.z) - }; - - Vec3 textworldreign[4]; - Matrix34 dcInvTm = dc.GetMatrix().GetInverted(); - - Matrix44A mProj, mView; - mathMatrixPerspectiveFov(&mProj, camera.GetFov(), camera.GetProjRatio(), camera.GetNearPlane(), camera.GetFarPlane()); - mathMatrixLookAt(&mView, camera.GetPosition(), camera.GetPosition() + camera.GetViewdir(), Vec3(0, 0, 1)); - Matrix44A mInvViewProj = (mView * mProj).GetInverted(); - - for (int i = 0; i < 4; ++i) - { - Vec4 projectedpos = Vec4((textregion[i].x - vx) / vw * 2.0f - 1.0f, - -((textregion[i].y - vy) / vh) * 2.0f + 1.0f, - textregion[i].z, - 1.0f); - - Vec4 wp = projectedpos * mInvViewProj; - wp.x /= wp.w; - wp.y /= wp.w; - wp.z /= wp.w; - textworldreign[i] = dcInvTm.TransformPoint(Vec3(wp.x, wp.y, wp.z)); - } - - ColorB backupcolor = dc.GetColor(); - uint32 backupstate = dc.GetState(); - - dc.SetColor(TextBackColor); - dc.SetDrawInFrontMode(true); - - dc.DrawQuad(textworldreign[3], textworldreign[2], textworldreign[1], textworldreign[0]); - dc.SetColor(TextColor); - dc.DrawTextLabel(pos, textScale, text); - - dc.SetDrawInFrontMode(false); - dc.SetColor(backupcolor); - dc.SetState(backupstate); -} - - ////////////////////////////////////////////////////////////////////////// void CBaseObject::DrawSelectionHelper(DisplayContext& dc, const Vec3& pos, const QColor& labelColor, [[maybe_unused]] float alpha) { diff --git a/Code/Sandbox/Editor/Objects/BaseObject.h b/Code/Sandbox/Editor/Objects/BaseObject.h index 5d6f800a58..73e2394f6c 100644 --- a/Code/Sandbox/Editor/Objects/BaseObject.h +++ b/Code/Sandbox/Editor/Objects/BaseObject.h @@ -604,9 +604,6 @@ public: virtual IStatObj* GetIStatObj() { return NULL; } - //! Display length of each axis. - void DrawDimensionsImpl(DisplayContext& dc, const AABB& localBoundBox, AABB* pMergedBoundBox = NULL); - // Invalidates cached transformation matrix. // nWhyFlags - Flags that indicate the reason for matrix invalidation. virtual void InvalidateTM(int nWhyFlags); @@ -678,8 +675,6 @@ protected: virtual void DrawTextureIcon(DisplayContext& dc, const Vec3& pos, float alpha = 1.0f); //! Draw warning icons virtual void DrawWarningIcons(DisplayContext& dc, const Vec3& pos); - //! Display text with a 3d world coordinate. - void DrawTextOn2DBox(DisplayContext& dc, const Vec3& pos, const char* text, float textScale, const ColorF& TextColor, const ColorF& TextBackColor); //! Check if dimension's figures can be displayed before draw them. virtual void DrawDimensions(DisplayContext& dc, AABB* pMergedBoundBox = NULL); diff --git a/Code/Sandbox/Editor/Objects/DisplayContext.h b/Code/Sandbox/Editor/Objects/DisplayContext.h index 13363a923e..de33388eb4 100644 --- a/Code/Sandbox/Editor/Objects/DisplayContext.h +++ b/Code/Sandbox/Editor/Objects/DisplayContext.h @@ -227,7 +227,6 @@ struct SANDBOX_API DisplayContext void DrawTextLabel(const Vec3& pos, float size, const char* text, const bool bCenter = false, int srcOffsetX = 0, int scrOffsetY = 0); void Draw2dTextLabel(float x, float y, float size, const char* text, bool bCenter = false); - void DrawTextOn2DBox(const Vec3& pos, const char* text, float textScale, const ColorF& TextColor, const ColorF& TextBackColor); void SetLineWidth(float width); //! Is given bbox visible in this display context. diff --git a/Code/Sandbox/Editor/Objects/DisplayContextShared.inl b/Code/Sandbox/Editor/Objects/DisplayContextShared.inl index 4d284faea7..419b7c0406 100644 --- a/Code/Sandbox/Editor/Objects/DisplayContextShared.inl +++ b/Code/Sandbox/Editor/Objects/DisplayContextShared.inl @@ -37,7 +37,7 @@ DisplayContext::DisplayContext() m_currentMatrix = 0; m_matrixStack[m_currentMatrix].SetIdentity(); - pRenderAuxGeom = gEnv->pRenderer ? gEnv->pRenderer->GetIRenderAuxGeom() : nullptr; + pRenderAuxGeom = nullptr; // ToDo: Remove DisplayContext or update to work with Atom: LYN-3670 m_thickness = 0; m_width = 0; @@ -1105,85 +1105,6 @@ void DisplayContext::Draw2dTextLabel(float x, float y, float size, const char* t renderer->Draw2dLabel(x, y, size, col, bCenter, "%s", text); } -void DisplayContext::DrawTextOn2DBox(const Vec3& pos, const char* text, float textScale, const ColorF& TextColor, const ColorF& TextBackColor) -{ - Vec3 worldPos = ToWorldSpacePosition(pos); - int vx, vy, vw, vh; - gEnv->pRenderer->GetViewport(&vx, &vy, &vw, &vh); - uint32 backupstate = GetState(); - - SetState(backupstate | e_DepthTestOff); - - const CCamera& renderCamera = gEnv->pRenderer->GetCamera(); - Vec3 screenPos; - - renderCamera.Project(worldPos, screenPos, Vec2i(0, 0), Vec2i(0, 0)); - - //! Font size information doesn't seem to exist so the proper size is used - int textlen = strlen(text); - float fontsize = 7.5f * textScale; - float textwidth = fontsize * textlen; - float textheight = 16.0f * textScale; - - screenPos.x = screenPos.x - (textwidth * 0.5f); - - Vec3 textregion[4] = { - Vec3(screenPos.x, screenPos.y, screenPos.z), - Vec3(screenPos.x + textwidth, screenPos.y, screenPos.z), - Vec3(screenPos.x + textwidth, screenPos.y + textheight, screenPos.z), - Vec3(screenPos.x, screenPos.y + textheight, screenPos.z) - }; - - Vec3 textworldreign[4]; - Matrix34 dcInvTm = GetMatrix().GetInverted(); - - Matrix44A mProj, mView; - mathMatrixPerspectiveFov(&mProj, renderCamera.GetFov(), renderCamera.GetProjRatio(), renderCamera.GetNearPlane(), renderCamera.GetFarPlane()); - mathMatrixLookAt(&mView, renderCamera.GetPosition(), renderCamera.GetPosition() + renderCamera.GetViewdir(), Vec3(0, 0, 1)); - Matrix44A mInvViewProj = (mView * mProj).GetInverted(); - - if (vw == 0) - { - vw = 1; - } - - if (vh == 0) - { - vh = 1; - } - - for (int i = 0; i < 4; ++i) - { - Vec4 projectedpos = Vec4((textregion[i].x - vx) / vw * 2.0f - 1.0f, - -((textregion[i].y - vy) / vh) * 2.0f + 1.0f, - textregion[i].z, - 1.0f); - - Vec4 wp = projectedpos * mInvViewProj; - - if (wp.w == 0.0f) - { - wp.w = 0.0001f; - } - - wp.x /= wp.w; - wp.y /= wp.w; - wp.z /= wp.w; - textworldreign[i] = dcInvTm.TransformPoint(Vec3(wp.x, wp.y, wp.z)); - } - - ColorB backupcolor = GetColor(); - - SetColor(TextBackColor); - SetDrawInFrontMode(true); - DrawQuad(textworldreign[3], textworldreign[2], textworldreign[1], textworldreign[0]); - SetColor(TextColor); - DrawTextLabel(pos, textScale, text); - SetDrawInFrontMode(false); - SetColor(backupcolor); - SetState(backupstate); -} - ////////////////////////////////////////////////////////////////////////// void DisplayContext::SetLineWidth(float width) { diff --git a/Code/Sandbox/Editor/PythonEditorFuncs.cpp b/Code/Sandbox/Editor/PythonEditorFuncs.cpp index 29cb8eb478..afd28f7070 100644 --- a/Code/Sandbox/Editor/PythonEditorFuncs.cpp +++ b/Code/Sandbox/Editor/PythonEditorFuncs.cpp @@ -31,7 +31,6 @@ #include "ViewManager.h" #include "StringDlg.h" #include "GenericSelectItemDialog.h" -#include "Util/Ruler.h" #include "Objects/BaseObject.h" #include "Commands/CommandManager.h" @@ -608,8 +607,9 @@ namespace } else { - float color[] = {r, g, b, a}; - gEnv->pRenderer->Draw2dLabel(x, y, size, color, false, pLabel); + // ToDo: Remove function or update to work with Atom? LYN-3672 + // float color[] = {r, g, b, a}; + // ???->Draw2dLabel(x, y, size, color, false, pLabel); } } diff --git a/Code/Sandbox/Editor/Resource.h b/Code/Sandbox/Editor/Resource.h index ea8ec828cf..ddc9ff2359 100644 --- a/Code/Sandbox/Editor/Resource.h +++ b/Code/Sandbox/Editor/Resource.h @@ -99,7 +99,6 @@ #define ID_FILE_SAVELEVELRESOURCES 32942 #define ID_VALIDATELEVEL 32943 #define ID_TERRAIN_RESIZE 32944 -#define ID_RELOAD_TEXTURES 32952 #define ID_TERRAIN_COLLISION 32960 #define ID_TOOL_FIRST 32972 #define ID_EDIT_UNFREEZE 32973 diff --git a/Code/Sandbox/Editor/ShaderCache.cpp b/Code/Sandbox/Editor/ShaderCache.cpp deleted file mode 100644 index 3beeb9a7c4..0000000000 --- a/Code/Sandbox/Editor/ShaderCache.cpp +++ /dev/null @@ -1,183 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "EditorDefs.h" - -#include "ShaderCache.h" - -// Editor -#include "GameEngine.h" - - -////////////////////////////////////////////////////////////////////////// -bool CLevelShaderCache::Reload() -{ - return Load(m_filename.toUtf8().data()); -} - -////////////////////////////////////////////////////////////////////////// -bool CLevelShaderCache::Load(const char* filename) -{ - FILE* f = nullptr; - azfopen(&f, filename, "rt"); - if (!f) - { - return false; - } - - int nNumLines = 0; - m_entries.clear(); - m_filename = filename; - char str[65535]; - while (fgets(str, sizeof(str), f) != NULL) - { - if (str[0] == '<') - { - m_entries.insert(str); - nNumLines++; - } - } - fclose(f); - if (nNumLines == m_entries.size()) - { - m_bModified = false; - } - else - { - m_bModified = true; - } - return true; -} - -////////////////////////////////////////////////////////////////////////// -bool CLevelShaderCache::LoadBuffer(const QString& textBuffer, bool bClearOld) -{ - const char* separators = "\r\n,"; - - int nNumLines = 0; - if (bClearOld) - { - m_entries.clear(); - } - m_filename = ""; - - for (auto resToken : textBuffer.split(QRegularExpression(QStringLiteral("[%1]").arg(separators)), Qt::SkipEmptyParts)) - { - if (!resToken.isEmpty() && resToken[0] == '<') - { - m_entries.insert(resToken); - nNumLines++; - } - } - if (nNumLines == m_entries.size() && !bClearOld) - { - m_bModified = false; - } - else - { - m_bModified = true; - } - - int numShaders = m_entries.size(); - CLogFile::FormatLine("%d shader combination loaded for level %s", numShaders, GetIEditor()->GetGameEngine()->GetLevelPath().toUtf8().data()); - - return true; -} - -////////////////////////////////////////////////////////////////////////// -bool CLevelShaderCache::Save() -{ - if (m_filename.isEmpty()) - { - return false; - } - - Update(); - - FILE* f = nullptr; - azfopen(&f, m_filename.toUtf8().data(), "wt"); - if (f) - { - for (Entries::iterator it = m_entries.begin(); it != m_entries.end(); ++it) - { - fputs(it->toLatin1().data(), f); - } - fclose(f); - } - m_bModified = false; - return true; -} - -////////////////////////////////////////////////////////////////////////// -bool CLevelShaderCache::SaveBuffer(QString& textBuffer) -{ - Update(); - - textBuffer.reserve(m_entries.size() * 1024); - for (Entries::iterator it = m_entries.begin(); it != m_entries.end(); ++it) - { - textBuffer += (*it); - textBuffer += "\n"; - } - m_bModified = false; - - return true; -} - -////////////////////////////////////////////////////////////////////////// -void CLevelShaderCache::Update() -{ - IRenderer* pRenderer = gEnv->pRenderer; - if (pRenderer) - { - QString buf; - char* str = NULL; - pRenderer->EF_Query(EFQ_GetShaderCombinations, str); - if (str) - { - buf = str; - pRenderer->EF_Query(EFQ_DeleteMemoryArrayPtr, str); - } - LoadBuffer(buf, true); - } -} - -////////////////////////////////////////////////////////////////////////// -void CLevelShaderCache::Clear() -{ - m_entries.clear(); - m_bModified = true; -} - -////////////////////////////////////////////////////////////////////////// -void CLevelShaderCache::ActivateShaders() -{ - bool bPreload = false; - ICVar* pSysPreload = gEnv->pConsole->GetCVar("sys_preload"); - if (pSysPreload && pSysPreload->GetIVal() != 0) - { - bPreload = true; - } - - if (bPreload) - { - QString textBuffer; - textBuffer.reserve(m_entries.size() * 1024); - for (Entries::iterator it = m_entries.begin(); it != m_entries.end(); ++it) - { - textBuffer += (*it); - textBuffer += "\n"; - } - gEnv->pRenderer->EF_Query(EFQ_SetShaderCombinations, textBuffer); - } -} diff --git a/Code/Sandbox/Editor/ShaderCache.h b/Code/Sandbox/Editor/ShaderCache.h deleted file mode 100644 index c75ab1554f..0000000000 --- a/Code/Sandbox/Editor/ShaderCache.h +++ /dev/null @@ -1,45 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_EDITOR_SHADERCACHE_H -#define CRYINCLUDE_EDITOR_SHADERCACHE_H -#pragma once - -////////////////////////////////////////////////////////////////////////// -class CLevelShaderCache -{ -public: - CLevelShaderCache() - { - m_bModified = false; - } - bool Load(const char* filename); - bool LoadBuffer(const QString& textBuffer, bool bClearOld = true); - bool SaveBuffer(QString& textBuffer); - bool Save(); - bool Reload(); - void Clear(); - - void Update(); - void ActivateShaders(); - -private: - ////////////////////////////////////////////////////////////////////////// - bool m_bModified; - QString m_filename; - typedef std::set Entries; - Entries m_entries; -}; - - -#endif // CRYINCLUDE_EDITOR_SHADERCACHE_H diff --git a/Code/Sandbox/Editor/ShaderEnum.cpp b/Code/Sandbox/Editor/ShaderEnum.cpp deleted file mode 100644 index 65518303ce..0000000000 --- a/Code/Sandbox/Editor/ShaderEnum.cpp +++ /dev/null @@ -1,125 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// Description : Enumerate Installed Shaders. - - -#include "EditorDefs.h" - -#include "ShaderEnum.h" - -////////////////////////////////////////////////////////////////////////// -CShaderEnum::CShaderEnum() -{ - m_bEnumerated = false; -} - -CShaderEnum::~CShaderEnum() -{ -} - - -inline bool ShaderLess(const CShaderEnum::ShaderDesc& s1, const CShaderEnum::ShaderDesc& s2) -{ - return QString::compare(s1.name, s2.name, Qt::CaseInsensitive) < 0; -} -/* -struct StringLess { - bool operator()( const CString &s1,const CString &s2 ) - { - return _stricmp( s1,s2 ) < 0; - } -}; -*/ - -//! Enum shaders. -int CShaderEnum::EnumShaders() -{ - IRenderer* renderer = GetIEditor()->GetSystem()->GetIRenderer(); - if (!renderer) - { - return 0; - } - - m_bEnumerated = true; - - m_shaders.clear(); - m_shaders.reserve(100); - //! Enumerate Shaders. - int nNumShaders = 0; - string* files = renderer->EF_GetShaderNames(nNumShaders); - for (int i = 0; i < nNumShaders; i++) - { - ShaderDesc sd; - sd.name = files[i].c_str(); - sd.file = files[i].c_str(); - if (!sd.name.isEmpty()) - { - // Capitalize first character of the string. - sd.name[0] = sd.name[0].toUpper(); - } - m_shaders.push_back(sd); - } - - XmlNodeRef root = GetISystem()->GetXmlUtils()->LoadXmlFromFile("Materials/ShaderList.xml"); - if (root) - { - for (int i = 0; i < root->getChildCount(); ++i) - { - XmlNodeRef ChildNode = root->getChild(i); - const char* pTagName = ChildNode->getTag(); - if (!_stricmp(pTagName, "Shader")) - { - QString name; - if (ChildNode->getAttr("name", name) && !name.isEmpty()) - { - // make sure there is no duplication - bool isUnique = true; - for (std::vector::iterator pSD = m_shaders.begin(); pSD != m_shaders.end(); ++pSD) - { - if (!QString::compare((*pSD).file, name, Qt::CaseInsensitive)) - { - isUnique = false; - break; - } - } - if (isUnique) - { - ShaderDesc sd; - sd.name = name; - sd.file = name.toLower(); - m_shaders.push_back(sd); - } - } - } - } - } - - std::sort(m_shaders.begin(), m_shaders.end(), ShaderLess); - return m_shaders.size(); -} - -int CShaderEnum::GetShaderCount() const -{ - return m_shaders.size(); -} - -QString CShaderEnum::GetShader(int i) const -{ - return m_shaders[i].name; -} - -QString CShaderEnum::GetShaderFile(int i) const -{ - return m_shaders[i].file; -} diff --git a/Code/Sandbox/Editor/ShaderEnum.h b/Code/Sandbox/Editor/ShaderEnum.h deleted file mode 100644 index ccc86bd089..0000000000 --- a/Code/Sandbox/Editor/ShaderEnum.h +++ /dev/null @@ -1,60 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// Description : Enumerate Installed Shaders. - - -#ifndef CRYINCLUDE_EDITOR_SHADERENUM_H -#define CRYINCLUDE_EDITOR_SHADERENUM_H - -#pragma once - -/*! - * CShaderEnum class enumerates shaders installed on system. - * It scans all effector files, and gather from them all defined effectors. - */ -class CShaderEnum -{ -public: - struct ShaderDesc - { - QString name; - QString file; - }; - - CShaderEnum(); - virtual ~CShaderEnum(); - - //! Enumerate shaders installed on system. - //! @return Number of enumerated shaders. - virtual int EnumShaders(); - - //! Get number of shaders in system. - //! @return Number of installed shaders. - virtual int GetShaderCount() const; - - //! Get name of shader by index. - //! index must be between 0 and number returned by EnumShaders. - //! @return Name of shader. - virtual QString GetShader(int i) const; - virtual QString GetShaderFile(int i) const; - -private: - bool m_bEnumerated; - - //! Array of shader names. - std::vector m_shaders; -}; - - -#endif // CRYINCLUDE_EDITOR_SHADERENUM_H diff --git a/Code/Sandbox/Editor/ShadersDialog.cpp b/Code/Sandbox/Editor/ShadersDialog.cpp deleted file mode 100644 index 6a09d00232..0000000000 --- a/Code/Sandbox/Editor/ShadersDialog.cpp +++ /dev/null @@ -1,150 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "EditorDefs.h" - -#include "ShadersDialog.h" - -// Qt -#include - -// Editor -#include "ShaderEnum.h" - - -AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING -#include -AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING - -///////////////////////////////////////////////////////////////////////////// -// CShadersDialog dialog - - -CShadersDialog::CShadersDialog(const QString& selection, QWidget* pParent /*=NULL*/) - : QDialog(pParent) - , m_shadersModel(new QStringListModel(this)) - , ui(new Ui::CShadersDialog) - , m_selection(selection) -{ - ui->setupUi(this); - ui->m_shaders->setModel(m_shadersModel); - OnInitDialog(); - - connect(ui->m_shaders->selectionModel(), &QItemSelectionModel::selectionChanged, this, &CShadersDialog::OnSelchangeShaders); - connect(ui->m_shaders, &QListView::doubleClicked, this, &CShadersDialog::OnDblclkShaders); - connect(ui->m_shaderText, &QTextEdit::textChanged, this, &CShadersDialog::OnEnChangeText); - connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); - connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); - connect(ui->m_saveButton, &QPushButton::clicked, this, &CShadersDialog::OnBnClickedSave); - connect(ui->m_editButton, &QPushButton::clicked, this, &CShadersDialog::OnBnClickedEdit); -} - - -CShadersDialog::~CShadersDialog() -{ -} - - -void CShadersDialog::OnSelchangeShaders() -{ - // When shader changes. - // Edit shader file. - auto index = ui->m_shaders->currentIndex(); - if (index.isValid()) - { - QString file = GetIEditor()->GetShaderEnum()->GetShaderFile(index.row()); - file.replace('/', '\\'); - ui->m_shaderText->LoadFile(file); - // Just loaded file.. Not savable. - ui->m_saveButton->setEnabled(false); - - QString shaderName = QStringLiteral("'%1'").arg(index.data().toString()); - - if (ui->m_shaderText->find(shaderName)) - { - auto cursor = ui->m_shaderText->textCursor(); - cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, shaderName.size()); - } - - m_selection = index.data().toString(); - } -} - -void CShadersDialog::OnInitDialog() -{ - QWaitCursor wait; - - // Fill with shaders. - CShaderEnum* shaderEnum = GetIEditor()->GetShaderEnum(); - int numShaders = shaderEnum->EnumShaders(); - - QStringList shaders; - for (int i = 0; i < numShaders; i++) - { - shaders.append(shaderEnum->GetShader(i)); - } - m_shadersModel->setStringList(shaders); - - /* - if (numShaders > 0) - { - int i = m_shaders.FindString(m_sel); - if (i != LB_ERR) - m_shaders.SetCurSel( i ); - } - */ -} - -void CShadersDialog::OnDblclkShaders() -{ - // Same as IDOK. - accept(); -} - -void CShadersDialog::OnBnClickedEdit() -{ - // Edit shader file. - auto index = ui->m_shaders->currentIndex(); - if (index.isValid()) - { - CShaderEnum* shaderEnum = GetIEditor()->GetShaderEnum(); - QString file = shaderEnum->GetShaderFile(index.row()); - CFileUtil::EditTextFile(file.toUtf8().data(), IFileUtil::FILE_TYPE_SHADER); - } -} - -////////////////////////////////////////////////////////////////////////// -void CShadersDialog::OnBnClickedSave() -{ - if (ui->m_shaderText->IsModified()) - { - ui->m_shaderText->SaveFile(ui->m_shaderText->GetFilename()); - if (ui->m_shaderText->IsModified()) - { - ui->m_saveButton->setEnabled(true); - } - else - { - ui->m_saveButton->setEnabled(false); - } - } -} - -////////////////////////////////////////////////////////////////////////// -void CShadersDialog::OnEnChangeText() -{ - // File can be saved. - ui->m_saveButton->setEnabled(true); -} - -#include diff --git a/Code/Sandbox/Editor/ShadersDialog.h b/Code/Sandbox/Editor/ShadersDialog.h deleted file mode 100644 index bafad56a8f..0000000000 --- a/Code/Sandbox/Editor/ShadersDialog.h +++ /dev/null @@ -1,62 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_EDITOR_SHADERSDIALOG_H -#define CRYINCLUDE_EDITOR_SHADERSDIALOG_H - -#pragma once -// ShadersDialog.h : header file -// - -#if !defined(Q_MOC_RUN) -#include -#endif - -class QStringListModel; - -namespace Ui { - class CShadersDialog; -} - -///////////////////////////////////////////////////////////////////////////// -// CShadersDialog dialog - -class CShadersDialog - : public QDialog -{ - Q_OBJECT - - // Construction -public: - CShadersDialog(const QString& selection, QWidget* pParent = nullptr); // standard constructor - ~CShadersDialog(); - - QString m_selection; - - QString GetSelection() { return m_selection; }; - -protected: - void OnSelchangeShaders(); - virtual void OnInitDialog(); - void OnDblclkShaders(); - -public: - void OnBnClickedEdit(); - void OnBnClickedSave(); - void OnEnChangeText(); - - QStringListModel* m_shadersModel; - QScopedPointer ui; -}; - -#endif // CRYINCLUDE_EDITOR_SHADERSDIALOG_H diff --git a/Code/Sandbox/Editor/ShadersDialog.ui b/Code/Sandbox/Editor/ShadersDialog.ui deleted file mode 100644 index c103cd0dec..0000000000 --- a/Code/Sandbox/Editor/ShadersDialog.ui +++ /dev/null @@ -1,118 +0,0 @@ - - - CShadersDialog - - - - 0 - 0 - 615 - 458 - - - - Select Shader - - - - - - - - - - Select Shader - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - - - - - - - - - - - - Shader Script - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - - - - - - - - - - - - - - - - QFrame::HLine - - - QFrame::Sunken - - - - - - - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Save - - - - - - - External Edit - - - - - - - - - - CTextEditorCtrl - QTextEdit -
Controls/TextEditorCtrl.h
-
-
- - -
diff --git a/Code/Sandbox/Editor/TopRendererWnd.cpp b/Code/Sandbox/Editor/TopRendererWnd.cpp index bc979902e7..78fce1bc24 100644 --- a/Code/Sandbox/Editor/TopRendererWnd.cpp +++ b/Code/Sandbox/Editor/TopRendererWnd.cpp @@ -150,7 +150,7 @@ void QTopRendererWnd::UpdateContent(int flags) } ////////////////////////////////////////////////////////////////////////// -void QTopRendererWnd::Draw(DisplayContext& dc) +void QTopRendererWnd::Draw([[maybe_unused]] DisplayContext& dc) { FUNCTION_PROFILER(GetIEditor()->GetSystem(), PROFILE_EDITOR); @@ -165,7 +165,8 @@ void QTopRendererWnd::Draw(DisplayContext& dc) //////////////////////////////////////////////////////////////////////// // Render the 2D map //////////////////////////////////////////////////////////////////////// - if (!m_terrainTextureId) + // ToDo: Remove TopRendererWnd or update to work with Atom: LYN-3671 + /*if (!m_terrainTextureId) { //GL_BGRA_EXT if (m_terrainTexture.IsValid()) @@ -238,7 +239,7 @@ void QTopRendererWnd::Draw(DisplayContext& dc) dc.DepthTestOn(); - Q2DViewport::Draw(dc); + Q2DViewport::Draw(dc);*/ } ////////////////////////////////////////////////////////////////////////// diff --git a/Code/Sandbox/Editor/TrackView/SequenceBatchRenderDialog.cpp b/Code/Sandbox/Editor/TrackView/SequenceBatchRenderDialog.cpp index 73f8ce7344..69322c481c 100644 --- a/Code/Sandbox/Editor/TrackView/SequenceBatchRenderDialog.cpp +++ b/Code/Sandbox/Editor/TrackView/SequenceBatchRenderDialog.cpp @@ -643,7 +643,7 @@ void CSequenceBatchRenderDialog::OnResolutionSelected() CCustomResolutionDlg resDlg(defaultW, defaultH, this); if (resDlg.exec() == QDialog::Accepted) { - const int maxRes = GetIEditor()->GetRenderer()->GetMaxSquareRasterDimension(); + const int maxRes = 8192; m_customResW = min(resDlg.GetWidth(), maxRes); m_customResH = min(resDlg.GetHeight(), maxRes); const QString resText = QString(customResFormat).arg(m_customResW).arg(m_customResH); diff --git a/Code/Sandbox/Editor/Util/ArcBall.cpp b/Code/Sandbox/Editor/Util/ArcBall.cpp deleted file mode 100644 index 25607e392b..0000000000 --- a/Code/Sandbox/Editor/Util/ArcBall.cpp +++ /dev/null @@ -1,769 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "EditorDefs.h" - -#include "ArcBall.h" - -bool CArcBall3D::ArcControl(const Matrix34& reference, const Ray& ray, uint32 mouseleft) -{ - RotControl <<= 1; - - if (mouseleft) - { - RotControl |= 1; - } - - Quat WObjectRotation = Quat(reference * Matrix34(ObjectRotation)); - Matrix34 WMat = reference * Matrix34(Matrix33(DragRotation * ObjectRotation), sphere.center); - Sphere WSphere(WMat.GetTranslation(), sphere.radius); - - Mouse_CutFlag = 0; - Vec3 Mouse_CutOn3DSphere(0, 0, 0); - Mouse_CutOnUnitSphere = Vec3(ZERO); - Mouse_CutFlag = Intersect::Ray_SphereFirst(ray, WSphere, Mouse_CutOn3DSphere); - - if (Mouse_CutFlag) - { - Mouse_CutOnUnitSphere = WObjectRotation.GetInverted() * (Mouse_CutOn3DSphere - WSphere.center).GetNormalized(); - } - - if (RotControl & 3) - { - if (Mouse_CutFlag) - { - if ((RotControl & 3) == 0x01) - { - Mouse_CutFlagStart = 1; - LineStart3D = Mouse_CutOnUnitSphere; - AxisSnap = 0; - - Matrix33 bym33; - - //get the distance to the axis - f32 xdist = fabsf(Mouse_CutOnUnitSphere.x); - f32 ydist = fabsf(Mouse_CutOnUnitSphere.y); - f32 zdist = fabsf(Mouse_CutOnUnitSphere.z); - - //if to close to an axis-crossing, disable axis choosing - if ((xdist < CrossDist) && (zdist < CrossDist)) - { - xdist = 1.0f; - ydist = 1.0f; - zdist = 1.0f; - } - if ((xdist < CrossDist) && (ydist < CrossDist)) - { - xdist = 1.0f; - ydist = 1.0f; - zdist = 1.0f; - } - if ((ydist < CrossDist) && (zdist < CrossDist)) - { - xdist = 1.0f; - ydist = 1.0f; - zdist = 1.0f; - } - - //check snap with YZ-plane - if (xdist < AxisDist) - { - bym33.SetIdentity(); - - if ((LineStart3D.x) || (LineStart3D.z)) - { - Vec3 n = Vec3(LineStart3D.x, 0, LineStart3D.z).GetNormalized(); - bym33.SetRotationY(acos_tpl(fabsf(n.z))); - } - - Vec3 SnapLineStart3D = bym33 * Vec3(fabsf(LineStart3D.x), LineStart3D.y, -fabsf(LineStart3D.z)); - - if (LineStart3D.z > 0.0f) - { - SnapLineStart3D.z = -SnapLineStart3D.z; - } - - LineStart3D = SnapLineStart3D; - AxisSnap = 1; - } - - //check snap with XZ-plane - if (ydist < AxisDist) - { - bym33.SetIdentity(); - - if ((LineStart3D.y) || (LineStart3D.z)) - { - Vec3 bn_xz = Vec3(0, LineStart3D.y, LineStart3D.z).GetNormalized(); - bym33.SetRotationX(-acos_tpl(fabsf(bn_xz.z))); - } - - Vec3 SnapLineStart3D = bym33 * Vec3((LineStart3D.x), fabsf(LineStart3D.y), -fabsf(LineStart3D.z)); - - if (LineStart3D.z > 0.0f) - { - SnapLineStart3D.z = -SnapLineStart3D.z; - } - - LineStart3D = SnapLineStart3D; - AxisSnap = 2; - } - - //check snap with XY-plane - if (zdist < AxisDist) - { - bym33.SetIdentity(); - - if ((LineStart3D.x) || (LineStart3D.z)) - { - Vec3 bn_xz = Vec3(LineStart3D.x, 0, LineStart3D.z).GetNormalized(); - bym33.SetRotationY(-acos_tpl(fabsf(bn_xz.x))); - } - - Vec3 SnapLineStart3D = bym33 * Vec3(fabsf(LineStart3D.x), LineStart3D.y, -fabsf(LineStart3D.z)); - - if (LineStart3D.x < 0.0f) - { - SnapLineStart3D.x = -SnapLineStart3D.x; - } - - LineStart3D = SnapLineStart3D; - AxisSnap = 3; - } - } - - if ((RotControl & 3) == 0x03) - { - ArcRotation(); - } - - if ((RotControl & 3) == 0x02) - { - ObjectRotation = (DragRotation * ObjectRotation).GetNormalized(); - DragRotation.SetIdentity(); - Mouse_CutFlagStart = 0; - LineStart3D = Vec3(0, -1, 0); - AxisSnap = 0; - - return true; - } - } - else - { - Vec3 ClostestPointOnLine; - IntersectSphereLineSegment(WSphere, ray.origin, ray.origin + ray.direction * 1000.0f, ClostestPointOnLine); - - Mouse_CutOn3DSphere = ((ClostestPointOnLine - WSphere.center).GetNormalized() * WSphere.radius) + WSphere.center; - Mouse_CutOnUnitSphere = WObjectRotation.GetInverted() * (Mouse_CutOn3DSphere - WSphere.center).GetNormalized(); - - if ((RotControl & 3) == 0x01) - { - LineStart3D = Mouse_CutOnUnitSphere; - Mouse_CutFlagStart = 0; - AxisSnap = 0; - } - - if ((RotControl & 3) == 0x03) - { - ArcRotation(); - } - - if ((RotControl & 3) == 0x02) - { - ObjectRotation = (DragRotation * ObjectRotation).GetNormalized(); - DragRotation.SetIdentity(); - Mouse_CutFlagStart = 0; - LineStart3D = Vec3(0, -1, 0); - AxisSnap = 0; - - return true; - } - } - } - - return false; -} - -void CArcBall3D::ArcRotation() -{ - Vec3 rv; - f32 gradius = 0; - f32 distance_YZ = 0; - f32 bias = 0; - f32 cosine = 0; - Vec3 XYVector; - - DragRotation.SetIdentity(); - - //first we calculate an ordinary drag-quaternion - cosine = (LineStart3D | Mouse_CutOnUnitSphere); - - if (fabsf(cosine) < 0.99999f) - { - DragRotation.SetRotationAA(acos_tpl(cosine), (LineStart3D % Mouse_CutOnUnitSphere).GetNormalized()); - } - - if (AxisSnap == 1) - { - //m_ButtonArcRotate an UpVector with our drag-quaternion - rv = (DragRotation) * Vec3(0, -1, 0); - DragRotation.SetIdentity(); - - //project rotated UpVector into XY_Plane (this is a simple y_axis rotation) - Matrix33 ym33; - ym33.SetIdentity(); - - if ((rv.x) || (rv.z)) - { - Vec3 n_xz = Vec3(rv.x, 0, rv.z).GetNormalized(); - ym33.SetRotationY(-acos_tpl(fabsf(n_xz.z))); - } - - XYVector = ym33 * Vec3(-fabsf(rv.x), rv.y, -fabsf(rv.z)); - - //find the rotation direction around z-axis - if (rv.z > 0) - { - XYVector.z = -XYVector.z; - } - - //calculate the xy-constrained quaternion - cosine = (Vec3(0, -1, 0) | XYVector); - - if (fabsf(cosine) < 0.99999f) - { - gradius = Vec3(rv.x, 0, rv.z).GetLength(); - distance_YZ = fabsf(rv.z); - bias = distance_YZ / gradius; - DragRotation.SetRotationAA(acos_tpl(cosine) * bias, (Vec3(0, -1, 0) % XYVector).GetNormalized()); - } - } - - if (AxisSnap == 2) - { - //m_ButtonArcRotate an UpVector with our DRAG-QUATERNION - rv = DragRotation * Vec3(-1, 0, 0); - DragRotation.SetIdentity(); - - //project rotated UpVector into XY_Plane (this is a simple x_axis rotation) - Matrix33 ym33; - ym33.SetIdentity(); - - if ((rv.y) || (rv.z)) - { - Vec3 n_xz = Vec3(0, rv.y, rv.z).GetNormalized(); - ym33.SetRotationX(-acos_tpl(fabsf(n_xz.z))); - } - - XYVector = ym33 * Vec3((rv.x), fabsf(rv.y), -fabsf(rv.z)); - - //find the rotation direction around y-axis - if (rv.z > 0) - { - XYVector.z = -XYVector.z; - } - - //calculate the xz-constrained quaternion - cosine = (Vec3(-1, 0, 0) | XYVector); - - if (fabsf(cosine) < 0.99999f) - { - gradius = Vec3(0, rv.y, rv.z).GetLength(); - distance_YZ = fabsf(rv.z); - bias = distance_YZ / gradius; - DragRotation.SetRotationAA(acos_tpl(cosine) * bias, (Vec3(-1, 0, 0) % XYVector).GetNormalized()); - } - } - - if (AxisSnap == 3) - { - //m_ButtonArcRotate an UpVector with our DRAG-QUATERNION - rv = DragRotation * Vec3(0, -1, 0); - DragRotation.SetIdentity(); - - //project rotated UpVector into XY_Plane (this is a simple y_axis rotation) - Matrix33 ym33; - - ym33.SetIdentity(); - - if ((rv.x) || (rv.z)) - { - Vec3 n_xz = Vec3(rv.x, 0, rv.z).GetNormalized(); - ym33.SetRotationY(-acos_tpl(fabsf(n_xz.x))); - } - - XYVector = ym33 * Vec3(fabsf(rv.x), rv.y, -fabsf(rv.z)); - - //find the rotation direction around z-axis - if (rv.x < 0) - { - XYVector.x = -XYVector.x; - } - - //calculate the xy-constrained quaternion - cosine = (Vec3(0, -1, 0) | XYVector); - - if (fabsf(cosine) < 0.99999f) - { - gradius = Vec3(rv.x, 0, rv.z).GetLength(); - distance_YZ = fabsf(rv.x); - bias = distance_YZ / gradius; - DragRotation.SetRotationAA(acos_tpl(cosine) * bias, (Vec3(0, -1, 0) % XYVector).GetNormalized()); - } - } - - //BINGO!!!! the final drag quaternion - DragRotation = ObjectRotation * DragRotation * ObjectRotation.GetInverted(); -} - -uint32 CArcBall3D::IntersectSphereLineSegment(const Sphere& sphere, const Vec3& LineStart, const Vec3& LineEnd, Vec3& I) -{ - //this is the code to produce a real z-rotation! - Vec3 LineDir = (LineEnd - LineStart).GetNormalized(); - Vec3 ShereCenterDir = (sphere.center - LineStart).GetNormalized(); - f32 LengthToSphereCenter = (sphere.center - LineStart).GetLength(); - - f32 cosine = (ShereCenterDir | LineDir); - - //this vector is perpendicular to the vector "ShereCenterDir" - Vec3 PerpVector = LengthToSphereCenter / cosine * LineDir + LineStart; - Vec3 PerpVectorOnSphere = ((PerpVector - sphere.center).GetNormalized() * sphere.radius) + sphere.center; - I = PerpVectorOnSphere; - - { - //find closest point on Lineseg - Vec3 LineDir2 = (LineEnd - LineStart).GetNormalized(); - f32 proj = LineDir2 | (sphere.center - LineStart); - I = LineDir2 * proj + LineStart; - } - - return 0; -} - -void CArcBall3D::DrawSphere(const Matrix34& reference, const CCamera& cam, IRenderAuxGeom* pRenderer) -{ - f32 thicknessX = 1.0f; - f32 thicknessY = 1.0f; - f32 thicknessZ = 1.0f; - - uint32 start; - Vec3 Vertices3D[64 * 32]; - Vec3 sVertices3D[64 * 32]; - Vec3 tVertices3D[64 * 32]; - uint32 c; - - Matrix34 WMat = reference * Matrix34(Matrix33(DragRotation * ObjectRotation), sphere.center); - Quat WObjectRotation = Quat(reference * Matrix34(ObjectRotation)); - Quat WRotation = Quat(reference * Matrix34(DragRotation * ObjectRotation)); - Sphere WSphere(WMat.GetTranslation(), sphere.radius); - - SAuxGeomRenderFlags renderFlags(e_Def3DPublicRenderflags); - renderFlags.SetDepthWriteFlag(e_DepthWriteOff); - renderFlags.SetFillMode(e_FillModeSolid); - - //------------------------------------------------------------------------------------------------------ - - uint32 s = 0; - uint32 t = 0; - Vec3 CamPos = cam.GetPosition(); - - renderFlags.SetAlphaBlendMode(e_AlphaAdditive); - pRenderer->SetRenderFlags(renderFlags); - pRenderer->DrawSphere(WSphere.center, WSphere.radius, RGBA8(0x3f, 0x3f, 0x3f, 0x00)); - - ColorB col; - f32 xdist = fabsf(Mouse_CutOnUnitSphere.x); - f32 ydist = fabsf(Mouse_CutOnUnitSphere.y); - f32 zdist = fabsf(Mouse_CutOnUnitSphere.z); - - if ((xdist < CrossDist) && (zdist < CrossDist)) - { - xdist = 1.0f; - ydist = 1.0f; - zdist = 1.0f; - } - if ((xdist < CrossDist) && (ydist < CrossDist)) - { - xdist = 1.0f; - ydist = 1.0f; - zdist = 1.0f; - } - if ((ydist < CrossDist) && (zdist < CrossDist)) - { - xdist = 1.0f; - ydist = 1.0f; - zdist = 1.0f; - } - - //---------------------------------------------------------------------------------- - // draw circle around X-axis - //---------------------------------------------------------------------------------- - thicknessX = 1.0f; - - if (AxisSnap == 0) - { - if (Mouse_CutFlag) - { - if (xdist < AxisDist) - { - thicknessX = 5.0f; - } - } - } - else if (AxisSnap == 1) - { - thicknessX = 5.0f; - } - - c = 0; - - for (f32 cz = 0; cz < (gf_PI * 2); cz = cz + (2 * gf_PI / 256.0f), ++c) - { - Vertices3D[c] = WMat * (Vec3(0, -cosf(cz), sinf(cz)) * WSphere.radius); - } - - assert(c == 0x100); - - for (start = 0; start < c; ++start) - { - Vec3 p0 = Vertices3D[(start + 0) & 0xff]; - f32 dot0 = (p0 - CamPos) | (p0 - WSphere.center); - Vec3 p1 = Vertices3D[(start + 1) & 0xff]; - f32 dot1 = (p1 - CamPos) | (p1 - WSphere.center); - - if ((dot0 < 0) && !(dot1 < 0)) - { - break; - } - } - - s = 0; - t = 0; - start = (start + 1) & 0xff; - - for (uint32 i = 0; i < c; ++i) - { - Vec3 p = Vertices3D[start]; - f32 dot = (p - CamPos) | (p - WSphere.center); - - if (dot < 0) - { - sVertices3D[s] = p; - s++; - } - else - { - tVertices3D[t] = p; - t++; - } - - start = (start + 1) & 0xff; - } - - renderFlags.SetAlphaBlendMode(e_AlphaNone); - pRenderer->SetRenderFlags(renderFlags); - - if (s > 2) - { - pRenderer->DrawPolyline(sVertices3D, s, 0, RGBA8(0xff, 0x12, 0x12, 0x00), thicknessX); - } - - renderFlags.SetAlphaBlendMode(e_AlphaAdditive); - pRenderer->SetRenderFlags(renderFlags); - - if (t > 2) - { - pRenderer->DrawPolyline(tVertices3D, t, 0, RGBA8(0x1f, 0x07, 0x07, 0x00), thicknessX); - } - - //---------------------------------------------------------------------------------- - // draw circle around Y-axis - //---------------------------------------------------------------------------------- - thicknessY = 1.0f; - - if (AxisSnap == 0) - { - if (Mouse_CutFlag) - { - if (ydist < AxisDist) - { - thicknessY = 5.0f; - } - } - } - else if (AxisSnap == 2) - { - thicknessY = 5.0f; - } - - c = 0; - - for (f32 cz = 0; cz < (gf_PI * 2); cz = cz + (2 * gf_PI / 256.0f), ++c) - { - Vertices3D[c] = WMat * (Vec3(-cosf(cz), 0, sinf(cz)) * WSphere.radius); - } - - assert(c == 0x100); - - for (start = 0; start < c; ++start) - { - Vec3 p0 = Vertices3D[(start + 0) & 0xff]; - f32 dot0 = (p0 - CamPos) | (p0 - WSphere.center); - Vec3 p1 = Vertices3D[(start + 1) & 0xff]; - f32 dot1 = (p1 - CamPos) | (p1 - WSphere.center); - - if ((dot0 < 0) && !(dot1 < 0)) - { - break; - } - } - - s = 0; - t = 0; - start = (start + 1) & 0xff; - - for (uint32 i = 0; i < c; ++i) - { - Vec3 p = Vertices3D[start]; - f32 dot = (p - CamPos) | (p - WSphere.center); - if (dot < 0) - { - sVertices3D[s] = p; - s++; - } - else - { - tVertices3D[t] = p; - t++; - } - - start = (start + 1) & 0xff; - } - - renderFlags.SetAlphaBlendMode(e_AlphaNone); - pRenderer->SetRenderFlags(renderFlags); - - if (s > 2) - { - pRenderer->DrawPolyline(sVertices3D, s, 0, RGBA8(0x12, 0xff, 0x12, 0x00), thicknessY); - } - - renderFlags.SetAlphaBlendMode(e_AlphaAdditive); - pRenderer->SetRenderFlags(renderFlags); - - if (t > 2) - { - pRenderer->DrawPolyline(tVertices3D, t, 0, RGBA8(0x07, 0x1f, 0x07, 0x00), thicknessY); - } - - //---------------------------------------------------------------------------------- - // draw circle around Z-axis - //---------------------------------------------------------------------------------- - thicknessZ = 1.0f; - - if (AxisSnap == 0) - { - if (Mouse_CutFlag) - { - if (zdist < AxisDist) - { - thicknessZ = 5.0f; - } - } - } - else if (AxisSnap == 3) - { - thicknessZ = 5.0f; - } - - c = 0; - for (f32 cz = 0; cz < (gf_PI * 2); cz = cz + (2 * gf_PI / 256.0f), ++c) - { - Vertices3D[c] = WMat * (Vec3(sinf(cz), -cosf(cz), 0) * WSphere.radius); - } - - assert(c == 0x100); - - for (start = 0; start < c; ++start) - { - Vec3 p0 = Vertices3D[(start + 0) & 0xff]; - f32 dot0 = (p0 - CamPos) | (p0 - WSphere.center); - Vec3 p1 = Vertices3D[(start + 1) & 0xff]; - f32 dot1 = (p1 - CamPos) | (p1 - WSphere.center); - - if ((dot0 < 0) && !(dot1 < 0)) - { - break; - } - } - - s = 0; - t = 0; - start = (start + 1) & 0xff; - - for (uint32 i = 0; i < c; ++i) - { - Vec3 p = Vertices3D[start]; - f32 dot = (p - CamPos) | (p - WSphere.center); - - if (dot < 0) - { - sVertices3D[s] = p; - s++; - } - else - { - tVertices3D[t] = p; - t++; - } - - start = (start + 1) & 0xff; - } - - renderFlags.SetAlphaBlendMode(e_AlphaNone); - pRenderer->SetRenderFlags(renderFlags); - - if (s > 2) - { - pRenderer->DrawPolyline(sVertices3D, s, 0, RGBA8(0x12, 0x12, 0xff, 0x00), thicknessZ); - } - - renderFlags.SetAlphaBlendMode(e_AlphaAdditive); - pRenderer->SetRenderFlags(renderFlags); - - if (t > 2) - { - pRenderer->DrawPolyline(tVertices3D, t, 0, RGBA8(0x07, 0x07, 0x1f, 0x00), thicknessZ); - } - - uint32 v; - - Vec3 VBuffer[1000]; - ColorB CBuffer[1000]; - - if ((RotControl & 3) == 3) - { - Vec3 Blue = WObjectRotation * LineStart3D; - Vec3 Red = WObjectRotation * Mouse_CutOnUnitSphere; - - VBuffer[0] = Vec3(0, 0, 0); - CBuffer[0] = RGBA8(0x00, 0x00, 0x00, 0x00); - - VBuffer[1] = Blue; - CBuffer[1] = RGBA8(0x00, 0x00, 0xff, 0x00); - - VBuffer[102] = Red; - CBuffer[102] = RGBA8(0xff, 0x00, 0x00, 0x00); - - for (v = 0; v < 100; ++v) - { - f32 t0 = (1.0f / 101.0f * v) + 1.0f / 101.0f; - - VBuffer[v + 2] = Vec3::CreateSlerp(Blue, Red, t0); - - f32 t1 = (1.0f / 101.0f * v); - - CBuffer[v + 2].b = uint8((1.0f - t1) * CBuffer[1].b + t1 * CBuffer[102].b); - CBuffer[v + 2].g = uint8((1.0f - t1) * CBuffer[1].g + t1 * CBuffer[102].g); - CBuffer[v + 2].r = uint8((1.0f - t1) * CBuffer[1].r + t1 * CBuffer[102].r); - } - - for (v = 0; v < 103; ++v) - { - VBuffer[v] = VBuffer[v] * WSphere.radius + WSphere.center; - } - - if (AxisSnap == 0) - { - SAuxGeomRenderFlags renderFlags2(e_Def3DPublicRenderflags); - - renderFlags2.SetFillMode(e_FillModeSolid); - renderFlags2.SetAlphaBlendMode(e_AlphaAdditive); - pRenderer->SetRenderFlags(renderFlags2); - - for (v = 0; v < 100; ++v) - { - pRenderer->DrawTriangle(VBuffer[0], CBuffer[0], VBuffer[v + 1], CBuffer[v + 1], VBuffer[v + 2], CBuffer[v + 2]); - pRenderer->DrawTriangle(VBuffer[0], CBuffer[0], VBuffer[v + 2], CBuffer[v + 2], VBuffer[v + 1], CBuffer[v + 1]); - } - } - } - - if (AxisSnap) - { - //project vector into the xy-plane - VBuffer[0] = Vec3(0, 0, 0); - CBuffer[0] = RGBA8(0x00, 0x00, 0x00, 0x00); - - VBuffer[1] = WObjectRotation * LineStart3D; - CBuffer[1] = RGBA8(0x12, 0x1f, 0x12, 0x00); - - VBuffer[102] = WRotation * LineStart3D; - CBuffer[102] = RGBA8(0x22, 0x7f, 0x22, 0x00); - - ColorB c0 = CBuffer[1]; - ColorB c1 = CBuffer[102]; - - for (v = 0; v < 100; ++v) - { - f32 t0 = (1.0f / 101.0f * v) + 1.0f / 101.0f; - - VBuffer[v + 2] = Vec3::CreateSlerp(VBuffer[1], VBuffer[102], t0); - - f32 t1 = (1.0f / 101.0f * v); - CBuffer[v + 2].r = uint8((1.0f - t1) * c0.r + t1 * c1.r); - CBuffer[v + 2].g = uint8((1.0f - t1) * c0.g + t1 * c1.g); - CBuffer[v + 2].b = uint8((1.0f - t1) * c0.b + t1 * c1.b); - } - - for (v = 0; v < 103; ++v) - { - VBuffer[v] = VBuffer[v] * WSphere.radius + WSphere.center; - } - - SAuxGeomRenderFlags renderFlags2(e_Def3DPublicRenderflags); - renderFlags2.SetFillMode(e_FillModeSolid); - renderFlags2.SetAlphaBlendMode(e_AlphaAdditive); - pRenderer->SetRenderFlags(renderFlags2); - - for (v = 0; v < 100; ++v) - { - pRenderer->DrawTriangle(VBuffer[0], CBuffer[0], VBuffer[v + 1], CBuffer[v + 1], VBuffer[v + 2], CBuffer[v + 2]); - pRenderer->DrawTriangle(VBuffer[0], CBuffer[0], VBuffer[v + 2], CBuffer[v + 2], VBuffer[v + 1], CBuffer[v + 1]); - } - } - - renderFlags = e_Def3DPublicRenderflags; - renderFlags.SetFillMode(e_FillModeSolid); - renderFlags.SetAlphaBlendMode(e_AlphaNone); - pRenderer->SetRenderFlags(renderFlags); - - #define CROSS (0.25f) - - Vec3 rmin = WMat * Vec3(0, 0.0f, 0.0f); - Vec3 rmax = WMat * Vec3(CROSS, 0.0f, 0.0f); - - pRenderer->DrawLine(rmin, RGBA8(0xff, 0x00, 0x00, 0x00), rmax, RGBA8(0xff, 0x7f, 0x7f, 0x00), thicknessX); - - Vec3 gmin = WMat * Vec3(0.0f, 0, 0.0f); - Vec3 gmax = WMat * Vec3(0.0f, CROSS, 0.0f); - - pRenderer->DrawLine(gmin, RGBA8(0x00, 0xff, 0x00, 0x00), gmax, RGBA8(0x7f, 0xff, 0x7f, 0x00), thicknessY); - - Vec3 bmin = WMat * Vec3(0.0f, 0.0f, 0); - Vec3 bmax = WMat * Vec3(0.0f, 0.0f, CROSS); - - pRenderer->DrawLine(bmin, RGBA8(0x00, 0x00, 0xff, 0x00), bmax, RGBA8(0x7f, 0x7f, 0xff, 0x00), thicknessZ); - renderFlags.SetDepthWriteFlag(e_DepthWriteOn); - pRenderer->SetRenderFlags(renderFlags); -} diff --git a/Code/Sandbox/Editor/Util/ArcBall.h b/Code/Sandbox/Editor/Util/ArcBall.h deleted file mode 100644 index 5adf02216c..0000000000 --- a/Code/Sandbox/Editor/Util/ArcBall.h +++ /dev/null @@ -1,64 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_EDITOR_UTIL_ARCBALL_H -#define CRYINCLUDE_EDITOR_UTIL_ARCBALL_H -#pragma once -#include -#include - -#define CrossDist (0.05f) -#define AxisDist (0.05f) - -class SANDBOX_API CArcBall3D -{ -public: - AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING - uint32 RotControl; - Sphere sphere; - uint32 Mouse_CutFlag; - uint32 Mouse_CutFlagStart; - uint32 AxisSnap; - Vec3 LineStart3D; - Vec3 Mouse_CutOnUnitSphere; - Quat DragRotation; - Quat ObjectRotation; - AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING - - CArcBall3D() - { - InitArcBall(); - }; - - void InitArcBall() - { - RotControl = 0; - sphere(Vec3(ZERO), 0.25f); - Mouse_CutFlag = 0; - Mouse_CutOnUnitSphere(0, 0, 0); - LineStart3D(0, -1, 0); - AxisSnap = 0; - DragRotation.SetIdentity(); - ObjectRotation.SetIdentity(); - } - - //--------------------------------------------------------------- - // ArcControl - // Returns true if the rotation has changed - //--------------------------------------------------------------- - bool ArcControl(const Matrix34& reference, const Ray& ray, uint32 mouseleft); - void ArcRotation(); - void DrawSphere(const Matrix34& reference, const CCamera& cam, struct IRenderAuxGeom* pRenderer); - static uint32 IntersectSphereLineSegment(const Sphere& s, const Vec3& LineStart, const Vec3& LineEnd, Vec3& I); -}; -#endif // CRYINCLUDE_EDITOR_UTIL_ARCBALL_H diff --git a/Code/Sandbox/Editor/Util/CubemapUtils.cpp b/Code/Sandbox/Editor/Util/CubemapUtils.cpp deleted file mode 100644 index bd650abaa8..0000000000 --- a/Code/Sandbox/Editor/Util/CubemapUtils.cpp +++ /dev/null @@ -1,251 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "EditorDefs.h" - -#include "CubemapUtils.h" - -// Qt -#include -#include -#include -#include -#include -#include - -// AzToolsFramework -#include - -// Editor -#include "Util/ImageTIF.h" -#include "Objects/BaseObject.h" - -#include - -class CubemapSizeModel - : public QAbstractListModel -{ -public: - CubemapSizeModel(QObject* parent = nullptr) - : QAbstractListModel(parent) - { } - - int rowCount(const QModelIndex& parent = {}) const override - { - return parent.isValid() ? 0 : kNumResolutions; - } - - QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override - { - if (!index.isValid() || index.row() >= kNumResolutions) - { - return {}; - } - - switch (role) - { - case Qt::DisplayRole: - case Qt::UserRole: - return 32 << index.row(); - } - - return {}; - } - -private: - static const int kNumResolutions = 6; -}; - -class CubemapSizeDialog - : public QDialog -{ -public: - CubemapSizeDialog(QWidget* parent = nullptr) - : QDialog(parent) - , m_model(new CubemapSizeModel(this)) - { - setWindowTitle(tr("Enter Cubemap Resolution")); - - m_comboBox = new QComboBox; - m_comboBox->setModel(m_model); - m_comboBox->setCurrentIndex(3); - - auto horLine = new QLabel; - horLine->setFrameShape(QFrame::HLine); - horLine->setFrameShadow(QFrame::Sunken); - - auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); - connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); - connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); - - auto layout = new QVBoxLayout; - layout->addWidget(m_comboBox); - layout->addWidget(horLine); - layout->addWidget(buttonBox); - - setLayout(layout); - } - - int GetValue() const - { - return m_comboBox->currentData().toInt(); - } - -private: - CubemapSizeModel* m_model; - QComboBox* m_comboBox; -}; - -/////////////////////////////////////////////////////////////////////////////////// -bool CubemapUtils::GenCubemapWithObjectPathAndSize(QString& filename, CBaseObject* pObject, const int size, const bool hideObject) -{ - if (!pObject) - { - Warning("Select One Entity to Generate Cubemap"); - return false; - } - - if (pObject->GetType() != OBJTYPE_AZENTITY) - { - Warning("Only Entities are allowed as a selected object. Please Select Entity objects"); - return false; - } - - int res = 1; - // Make size power of 2. - for (int i = 0; i < 16; i++) - { - if (res * 2 > size) - { - break; - } - res *= 2; - } - if (res > 4096) - { - Warning("Bad texture resolution.\nMust be power of 2 and less or equal to 4096"); - return false; - } - - IRenderNode* pRenderNode = pObject->GetEngineNode(); - - // Hide the object before Cubemap generation (maybe). This is useful for when generating a cubemap at an entity's position, like the player, - // and you don't want their model showing up in the cubemap. But you want to leave the entity alone if it's a light or something that - // has a desired contribution to the cubemap. - bool bIsHidden = false; - if (pRenderNode) - { - bIsHidden = (pRenderNode->GetRndFlags() & ERF_HIDDEN) != 0; - if (hideObject) - { - pRenderNode->SetRndFlags(ERF_HIDDEN, true); - } - } - - QString texname = Path::GetFileName(filename); - QString path = Path::GetPath(filename); - - // Add _CM suffix if missing - int32 nCMSufixCheck = texname.indexOf("_cm"); - texname = Path::Make(path, texname + ((nCMSufixCheck == -1) ? "_cm.tif" : ".tif")); - - // Assign this texname to current material. - texname = Path::ToUnixPath(texname); - - // Temporary solution to save both dds and tiff hdr cubemap - AABB pObjAABB; - pObject->GetBoundBox(pObjAABB); - - Vec3 pObjCenter = pObjAABB.GetCenter(); - - bool success = GenHDRCubemapTiff(texname, res, pObjCenter); - - // restore object's visibility - if (pRenderNode) - { - pRenderNode->SetRndFlags(ERF_HIDDEN, bIsHidden); - } - - filename = Path::ToUnixPath(texname); - - return success; -} - -////////////////////////////////////////////////////////////////////////// -bool CubemapUtils::GenHDRCubemapTiff(const QString& fileName, int nDstSize, Vec3& pos) -{ - int nSrcSize = nDstSize * 4; // Render 16x bigger cubemap (4x4) - 16x SSAA - - TArray vecData; - vecData.Reserve(nSrcSize * nSrcSize * 6 * 4); - vecData.SetUse(0); - - if (!GetIEditor()->GetRenderer()->EF_RenderEnvironmentCubeHDR(nSrcSize, pos, vecData)) - { - assert(0); - return false; - } - - assert(vecData.size() == nSrcSize * nSrcSize * 6 * 4); - - // todo: such big downsampling should be on gpu - - // save data to tiff - // resample the image at the original size - CWordImage img; - img.Allocate(nDstSize * 4 * 6, nDstSize); - - size_t srcPitch = nSrcSize * 4; - size_t srcSlideSize = nSrcSize * srcPitch; - - size_t dstPitch = nDstSize * 4; - for (int side = 0; side < 6; ++side) - { - for (uint32 y = 0; y < nDstSize; ++y) - { - CryHalf4* pSrcSide = (CryHalf4*)&vecData[side * srcSlideSize]; - CryHalf4* pDst = (CryHalf4*)&img.ValueAt(side * dstPitch, y); - for (uint32 x = 0; x < nDstSize; ++x) - { - Vec4 cResampledColor(0.f, 0.f, 0.f, 0.f); - - // resample the image at the original size - for (uint32 yres = 0; yres < 4; ++yres) - { - for (uint32 xres = 0; xres < 4; ++xres) - { - const CryHalf4& pSrc = pSrcSide[(y * 4 + yres) * nSrcSize + (x * 4 + xres)]; - cResampledColor += Vec4(CryConvertHalfToFloat(pSrc.x), CryConvertHalfToFloat(pSrc.y), CryConvertHalfToFloat(pSrc.z), CryConvertHalfToFloat(pSrc.w)); - } - } - - cResampledColor /= 16.f; - - *pDst++ = CryHalf4(cResampledColor.x, cResampledColor.y, cResampledColor.z, cResampledColor.w); - } - } - } - - assert(CryMemory::IsHeapValid()); - - CImageTIF tif; - const bool res = tif.SaveRAW(fileName, img.GetData(), nDstSize * 6, nDstSize, 2, 4, true, "HDRCubemap_highQ"); - assert(res); - return res; -} - -//function will recurse all probes and generate a cubemap for each -void CubemapUtils::RegenerateAllEnvironmentProbeCubemaps() -{ - EBUS_EVENT(AzToolsFramework::EditorRequests::Bus, GenerateAllCubemaps); -} diff --git a/Code/Sandbox/Editor/Util/CubemapUtils.h b/Code/Sandbox/Editor/Util/CubemapUtils.h deleted file mode 100644 index dfc2d47306..0000000000 --- a/Code/Sandbox/Editor/Util/CubemapUtils.h +++ /dev/null @@ -1,33 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_EDITOR_UTIL_CUBEMAPUTILS_H -#define CRYINCLUDE_EDITOR_UTIL_CUBEMAPUTILS_H -#pragma once - - -namespace CubemapUtils -{ - //! Generate a cubemap - //! \param filename - //! \param pObject The cubemap will be generated at this object's location - //! \param size Texel dimension of the cubemap - //! \param hideObject If true, pObject will be hidden when rendering the cubemap. For example, set this to true if pObject is a model that shouldn't - //! show up in the cubemap, or set to false if pObject is a light or probe that should contribute to the cubemap. - SANDBOX_API bool GenCubemapWithObjectPathAndSize(QString& filename, CBaseObject* pObject, const int size, const bool hideObject); - - SANDBOX_API bool GenHDRCubemapTiff(const QString& fileName, int size, Vec3& pos); - SANDBOX_API void RegenerateAllEnvironmentProbeCubemaps(); -} - -#endif // CRYINCLUDE_EDITOR_UTIL_CUBEMAPUTILS_H diff --git a/Code/Sandbox/Editor/Util/ImageUtil.cpp b/Code/Sandbox/Editor/Util/ImageUtil.cpp index ae44833a75..874d74e9bb 100644 --- a/Code/Sandbox/Editor/Util/ImageUtil.cpp +++ b/Code/Sandbox/Editor/Util/ImageUtil.cpp @@ -22,7 +22,6 @@ #include "Util/ImageGif.h" #include "Util/ImageTIF.h" #include "Util/ImageHDR.h" -#include "Util/Image_DXTC.h" ////////////////////////////////////////////////////////////////////////// bool CImageUtil::Save(const QString& strFileName, CImageEx& inImage) @@ -272,10 +271,6 @@ bool CImageUtil::LoadImage(const QString& fileName, CImageEx& image, bool* pQual { return LoadPGM(fileName, image); } - else if (azstricmp(ext, ".dds") == 0) - { - return CImage_DXTC().Load(fileName.toUtf8().data(), image, pQualityLoss); - } else if (azstricmp(ext, ".png") == 0) { return CImageUtil::Load(fileName, image); diff --git a/Code/Sandbox/Editor/Util/Image_DXTC.cpp b/Code/Sandbox/Editor/Util/Image_DXTC.cpp deleted file mode 100644 index 834da7b5a3..0000000000 --- a/Code/Sandbox/Editor/Util/Image_DXTC.cpp +++ /dev/null @@ -1,806 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "EditorDefs.h" - -#include "Image_DXTC.h" - -// CryCommon -#include -#include - -// Editor -#include "Util/Image.h" -#include "BitFiddling.h" - - -#ifndef MAKEFOURCC -#define MAKEFOURCC(ch0, ch1, ch2, ch3) \ - ((DWORD)(BYTE)(ch0) | ((DWORD)(BYTE)(ch1) << 8) | \ - ((DWORD)(BYTE)(ch2) << 16) | ((DWORD)(BYTE)(ch3) << 24)) -#endif //defined(MAKEFOURCC) - - -////////////////////////////////////////////////////////////////////////// -// HDR_UPPERNORM -> factor used when converting from [0,32768] high dynamic range images -// to [0,1] low dynamic range images; 32768 = 2^(2^4-1), 4 exponent bits -// LDR_UPPERNORM -> factor used when converting from [0,1] low dynamic range images -// to 8bit outputs - -#define HDR_UPPERNORM 1.0f // factor set to 1.0, to be able to see content in our rather dark HDR images -#define LDR_UPPERNORM 255.0f - -static float GammaToLinear(float x) -{ - return (x <= 0.04045f) ? x / 12.92f : powf((x + 0.055f) / 1.055f, 2.4f); -} - -static float LinearToGamma(float x) -{ - return (x <= 0.0031308f) ? x * 12.92f : 1.055f * powf(x, 1.0f / 2.4f) - 0.055f; -} - -////////////////////////////////////////////////////////////////////////// - -// Squish uses non-standard inline friend templates which Recode cannot parse -#ifndef __RECODE__ -AZ_PUSH_DISABLE_WARNING(4819 4828, "-Wunknown-warning-option") // Invalid character not in default code page -#include -AZ_POP_DISABLE_WARNING -#endif - -// number of bytes per block per type -#define BLOCKSIZE_BC1 8 -#define BLOCKSIZE_BC2 16 -#define BLOCKSIZE_BC3 16 -#define BLOCKSIZE_BC4 8 -#define BLOCKSIZE_BC5 16 -#define BLOCKSIZE_BC6 16 -#define BLOCKSIZE_BC7 16 - -CImage_DXTC::COMPRESSOR_ERROR CImage_DXTC::DecompressTextureBTC( - int width, - int height, - ETEX_Format sourceFormat, - CImage_DXTC::UNCOMPRESSED_FORMAT destinationFormat, - [[maybe_unused]] const int imageFlags, - const void* sourceData, - void* destinationData, - int destinationDataSize, - int destinationPageOffset) -{ - // Squish uses non-standard inline friend templates which Recode cannot parse -#ifndef __RECODE__ - { - const COMPRESSOR_ERROR result = CheckParameters( - width, - height, - destinationFormat, - sourceData, - destinationData, - destinationDataSize); - - if (result != COMPRESSOR_ERROR_NONE) - { - return result; - } - } - - int flags = 0; - int offs = 0; - int sourceChannels = 4; - switch (sourceFormat) - { - case eTF_BC1: - sourceChannels = 4; - flags = squish::kBtc1; - break; - case eTF_BC2: - sourceChannels = 4; - flags = squish::kBtc2; - break; - case eTF_BC3: - sourceChannels = 4; - flags = squish::kBtc3; - break; - case eTF_BC4U: - sourceChannels = 1; - flags = squish::kBtc4; - break; - case eTF_BC5U: - sourceChannels = 2; - flags = squish::kBtc5 + squish::kColourMetricUnit; - break; - case eTF_BC6UH: - sourceChannels = 3; - flags = squish::kBtc6; - break; - case eTF_BC7: - sourceChannels = 4; - flags = squish::kBtc7; - break; - - case eTF_BC4S: - sourceChannels = 1; - flags = squish::kBtc4 + squish::kSignedInternal + squish::kSignedExternal; - offs = 0x80; - break; - case eTF_BC5S: - sourceChannels = 2; - flags = squish::kBtc5 + squish::kSignedInternal + squish::kSignedExternal + squish::kColourMetricUnit; - offs = 0x80; - break; - case eTF_BC6SH: - sourceChannels = 3; - flags = squish::kBtc6 + squish::kSignedInternal + squish::kSignedExternal; - offs = 0x80; - break; - - default: - return COMPRESSOR_ERROR_UNSUPPORTED_SOURCE_FORMAT; - } - - squish::sqio::dtp datatype = !IsLimitedHDR(sourceFormat) ? squish::sqio::dtp::DT_U8 : squish::sqio::dtp::DT_F23; - switch (destinationFormat) - { - case FORMAT_ARGB_8888: /*datatype = squish::sqio::dtp::DT_U8;*/ - break; - // case FORMAT_ARGB_16161616: datatype = squish::sqio::dtp::DT_U16; break; - // case FORMAT_ARGB_32323232F: datatype = squish::sqio::dtp::DT_F23; break; - default: - return COMPRESSOR_ERROR_UNSUPPORTED_DESTINATION_FORMAT; - } - - struct squish::sqio sqio = squish::GetSquishIO(width, height, datatype, flags); - - const int blockChannels = 4; - const int blockWidth = 4; - const int blockHeight = 4; - - const int pixelStride = blockChannels * sizeof(uint8); - const int rowStride = (destinationPageOffset ? destinationPageOffset : pixelStride * width); - - if ((datatype == squish::sqio::dtp::DT_U8) && (destinationFormat == FORMAT_ARGB_8888)) - { - const char* src = (const char*)sourceData; - for (int y = 0; y < height; y += blockHeight) - { - uint8* dst = ((uint8*)destinationData) + (y * rowStride); - - for (int x = 0; x < width; x += blockWidth) - { - uint8 values[blockHeight][blockWidth][blockChannels] = { { { 0 } } }; - - // decode - sqio.decoder((uint8*)values, src, sqio.flags); - - // transfer - for (int by = 0; by < blockHeight; by += 1) - { - uint8* bdst = ((uint8*)dst) + (by * rowStride); - - for (int bx = 0; bx < blockWidth; bx += 1) - { - bdst[bx * pixelStride + 0] = sourceChannels <= 0 ? 0U : (values[by][bx][0] + offs); - bdst[bx * pixelStride + 1] = sourceChannels <= 1 ? bdst[bx * pixelStride + 0] : (values[by][bx][1] + offs); - bdst[bx * pixelStride + 2] = sourceChannels <= 1 ? bdst[bx * pixelStride + 0] : (values[by][bx][2] + offs); - bdst[bx * pixelStride + 3] = sourceChannels <= 3 ? 255U : (values[by][bx][3]); - } - } - - dst += blockWidth * pixelStride; - src += sqio.blocksize; - } - } - } - else if ((datatype == squish::sqio::dtp::DT_F23) && (destinationFormat == FORMAT_ARGB_8888)) - { - const char* src = (const char*)sourceData; - for (int y = 0; y < height; y += blockHeight) - { - uint8* dst = ((uint8*)destinationData) + (y * rowStride); - - for (int x = 0; x < width; x += blockWidth) - { - float values[blockHeight][blockWidth][blockChannels] = { { { 0 } } }; - - // decode - sqio.decoder((float*)values, src, sqio.flags); - - // transfer - for (int by = 0; by < blockHeight; by += 1) - { - uint8* bdst = ((uint8*)dst) + (by * rowStride); - - for (int bx = 0; bx < blockWidth; bx += 1) - { - bdst[bx * pixelStride + 0] = sourceChannels <= 0 ? 0U : std::min((uint8)255, (uint8)floorf(values[by][bx][0] * LDR_UPPERNORM / HDR_UPPERNORM + 0.5f)); - bdst[bx * pixelStride + 1] = sourceChannels <= 1 ? bdst[bx * pixelStride + 0] : std::min((uint8)255, (uint8)floorf(values[by][bx][1] * LDR_UPPERNORM / HDR_UPPERNORM + 0.5f)); - bdst[bx * pixelStride + 2] = sourceChannels <= 1 ? bdst[bx * pixelStride + 0] : std::min((uint8)255, (uint8)floorf(values[by][bx][2] * LDR_UPPERNORM / HDR_UPPERNORM + 0.5f)); - bdst[bx * pixelStride + 3] = sourceChannels <= 3 ? 255U : 255U; - } - } - - dst += blockWidth * pixelStride; - src += sqio.blocksize; - } - } - } -#endif - - return COMPRESSOR_ERROR_NONE; -} - -////////////////////////////////////////////////////////////////////////// -CImage_DXTC::CImage_DXTC() -{ -} -////////////////////////////////////////////////////////////////////////// -CImage_DXTC::~CImage_DXTC() -{ -} -////////////////////////////////////////////////////////////////////////// -bool CImage_DXTC::Load(const char* filename, CImageEx& outImage, bool* pQualityLoss) -{ - if (pQualityLoss) - { - *pQualityLoss = false; - } - - _smart_ptr pImage = gEnv->pRenderer->EF_LoadImage(filename, 0); - - if (!pImage) - { - return(false); - } - - BYTE* pDecompBytes; - - ETEX_Format eFormat = pImage->mfGetFormat(); - int imageFlags = pImage->mfGet_Flags(); - - if (eFormat == eTF_Unknown) - { - return false; - } - - _smart_ptr pAlphaImage; - - ETEX_Format eAttachedFormat = eTF_Unknown; - - if (imageFlags & FIM_HAS_ATTACHED_ALPHA) - { - if (pAlphaImage = gEnv->pRenderer->EF_LoadImage(filename, FIM_ALPHA)) - { - eAttachedFormat = pAlphaImage->mfGetFormat(); - } - } - - const bool bIsSRGB = (imageFlags & FIM_SRGB_READ) != 0; - outImage.SetSRGB(bIsSRGB); - - const uint32 imageWidth = pImage->mfGet_width(); - const uint32 imageHeight = pImage->mfGet_height(); - const uint32 numMips = pImage->mfGet_numMips(); - - int nHorizontalFaces(1); - int nVerticalFaces(1); - int nTargetPitch(imageWidth * 4); - int nTargetPageSize(nTargetPitch * imageHeight); - - int nHorizontalPageOffset(nTargetPitch); - int nVerticalPageOffset(0); - bool boIsCubemap = pImage->mfGet_NumSides() == 6; - if (boIsCubemap) - { - nHorizontalFaces = 3; - nVerticalFaces = 2; - nHorizontalPageOffset = nTargetPitch * nHorizontalFaces; - nVerticalPageOffset = nTargetPageSize * nHorizontalFaces; - } - - outImage.Allocate(imageWidth * nHorizontalFaces, imageHeight * nVerticalFaces); - pDecompBytes = (BYTE*)outImage.GetData(); - if (!pDecompBytes) - { - Warning("Cannot allocate image %dx%d, Out of memory", imageWidth, imageHeight); - return false; - } - - if (pQualityLoss) - { - *pQualityLoss = CImageExtensionHelper::IsQuantized(eFormat); - } - - bool bOk = true; - - int nCurrentFace(0); - int nCurrentHorizontalFace(0); - int nCurrentVerticalFace(0); - unsigned char* dest(NULL); - const unsigned char* src(NULL); - - unsigned char* basedest(NULL); - const unsigned char* basesrc(NULL); - - for (nCurrentHorizontalFace = 0; nCurrentHorizontalFace < nHorizontalFaces; ++nCurrentHorizontalFace) - { - basedest = &pDecompBytes[nTargetPitch * nCurrentHorizontalFace]; // Horizontal offset. - for (nCurrentVerticalFace = 0; nCurrentVerticalFace < nVerticalFaces; ++nCurrentVerticalFace, ++nCurrentFace) - { - basedest += nVerticalPageOffset * nCurrentVerticalFace; // Vertical offset. - - basesrc = src = pImage->mfGet_image(nCurrentFace); - - if (eFormat == eTF_R8G8B8A8 || eFormat == eTF_R8G8B8A8S) - { - for (int y = 0; y < imageHeight; y++) - { - dest = basedest + nHorizontalPageOffset * y; // Pixel position. - - for (int x = 0; x < imageWidth; x++) - { - dest[0] = src[0]; - dest[1] = src[1]; - dest[2] = src[2]; - dest[3] = src[3]; - - dest += 4; - src += 4; - } - } - } - else if (eFormat == eTF_B8G8R8A8) - { - for (int y = 0; y < imageHeight; y++) - { - dest = basedest + nHorizontalPageOffset * y; // Pixel position. - - for (int x = 0; x < imageWidth; x++) - { - dest[0] = src[2]; - dest[1] = src[1]; - dest[2] = src[0]; - dest[3] = src[3]; - - dest += 4; - src += 4; - } - } - } - else if (eFormat == eTF_B8G8R8X8) - { - for (int y = 0; y < imageHeight; y++) - { - dest = basedest + nHorizontalPageOffset * y; // Pixel position. - - for (int x = 0; x < imageWidth; x++) - { - dest[0] = src[2]; - dest[1] = src[1]; - dest[2] = src[0]; - dest[3] = 255; - - dest += 4; - src += 4; - } - } - } - else if (eFormat == eTF_B8G8R8) - { - for (int y = 0; y < imageHeight; y++) - { - dest = basedest + nHorizontalPageOffset * y; // Pixel position. - - for (int x = 0; x < imageWidth; x++) - { - dest[0] = src[2]; - dest[1] = src[1]; - dest[2] = src[0]; - dest[3] = 255; - - dest += 4; - src += 3; - } - } - } - else if (eFormat == eTF_L8) - { - for (int y = 0; y < imageHeight; y++) - { - dest = basedest + nHorizontalPageOffset * y; // Pixel position. - - for (int x = 0; x < imageWidth; x++) - { - dest[0] = *src; - dest[1] = *src; - dest[2] = *src; - dest[3] = 255; - - dest += 4; - src += 1; - } - } - } - else if (eFormat == eTF_A8) - { - for (int y = 0; y < imageHeight; y++) - { - dest = basedest + nHorizontalPageOffset * y; // Pixel position. - - for (int x = 0; x < imageWidth; x++) - { - dest[0] = 0; - dest[1] = 0; - dest[2] = 0; - dest[3] = *src; - - dest += 4; - src += 1; - } - } - } - else if (eFormat == eTF_A8L8) - { - for (int y = 0; y < imageHeight; y++) - { - dest = basedest + nHorizontalPageOffset * y; // Pixel position. - - for (int x = 0; x < imageWidth; x++) - { - dest[0] = src[0]; - dest[1] = src[0]; - dest[2] = src[0]; - dest[3] = src[1]; - - dest += 4; - src += 2; - } - } - } - else if (eFormat == eTF_R9G9B9E5) - { - const int nSourcePitch = imageWidth * 4; - - for (int y = 0; y < imageHeight; y++) - { - src = basesrc + nSourcePitch * y; //Scanline position. - dest = basedest + nHorizontalPageOffset * y; // Pixel position. - - for (int x = 0; x < imageWidth; x++) - { - const struct RgbE - { - unsigned int r : 9, g : 9, b : 9, e : 5; - }* srcv = (const struct RgbE*)src; - - const float escale = powf(2.0f, int(srcv->e) - 15 - 9) * LDR_UPPERNORM / HDR_UPPERNORM; - - dest[0] = std::min((uint8)255, (uint8)floorf(srcv->r * escale + 0.5f)); - dest[1] = std::min((uint8)255, (uint8)floorf(srcv->g * escale + 0.5f)); - dest[2] = std::min((uint8)255, (uint8)floorf(srcv->b * escale + 0.5f)); - dest[3] = 255U; - - dest += 4; - src += 4; - } - } - } - else - { - const int pixelCount = imageWidth * imageHeight; - const int outputBufferSize = pixelCount * 4; - const int mipCount = numMips; - - const COMPRESSOR_ERROR err = DecompressTextureBTC(imageWidth, imageHeight, eFormat, FORMAT_ARGB_8888, imageFlags, basesrc, basedest, outputBufferSize, nHorizontalPageOffset); - if (err != COMPRESSOR_ERROR_NONE) - { - return false; - } - } - - // alpha channel might be attached - if (imageFlags & FIM_HAS_ATTACHED_ALPHA) - { - if (IsBlockCompressed(eAttachedFormat)) - { - const byte* const basealpha = pAlphaImage->mfGet_image(0); - const int alphaImageWidth = pAlphaImage->mfGet_width(); - const int alphaImageHeight = pAlphaImage->mfGet_height(); - const int alphaImageFlags = pAlphaImage->mfGet_Flags(); - const int tmpOutputBufferSize = imageWidth * imageHeight * 4; - uint8* tmpOutputBuffer = new uint8[tmpOutputBufferSize]; - - const COMPRESSOR_ERROR err = DecompressTextureBTC(alphaImageWidth, alphaImageHeight, eAttachedFormat, FORMAT_ARGB_8888, alphaImageFlags, basealpha, tmpOutputBuffer, tmpOutputBufferSize, 0); - if (err != COMPRESSOR_ERROR_NONE) - { - delete []tmpOutputBuffer; - return false; - } - - // assuming attached image can have lower res and difference is power of two - const uint32 reducex = IntegerLog2((uint32)(imageWidth / alphaImageWidth)); - const uint32 reducey = IntegerLog2((uint32)(imageHeight / alphaImageHeight)); - - for (int y = 0; y < imageHeight; ++y) - { - dest = basedest + nHorizontalPageOffset * y; // Pixel position. - - for (int x = 0; x < imageWidth; ++x) - { - dest[3] = tmpOutputBuffer[((x >> reducex) + (y >> reducey) * alphaImageWidth) * 4]; - dest += 4; - } - } - - delete []tmpOutputBuffer; - } - else if (eAttachedFormat != eTF_Unknown) - { - const byte* const basealpha = pAlphaImage->mfGet_image(0); // assuming it's A8 format (ensured with assets when loading) - const int alphaImageWidth = pAlphaImage->mfGet_width(); - const int alphaImageHeight = pAlphaImage->mfGet_height(); - const int alphaImageFlags = pAlphaImage->mfGet_Flags(); - - // assuming attached image can have lower res and difference is power of two - const uint32 reducex = IntegerLog2((uint32)(imageWidth / alphaImageWidth)); - const uint32 reducey = IntegerLog2((uint32)(imageHeight / alphaImageHeight)); - - for (int y = 0; y < imageHeight; ++y) - { - dest = basedest + nHorizontalPageOffset * y; // Pixel position. - - for (int x = 0; x < imageWidth; ++x) - { - dest[3] = basealpha[(x >> reducex) + (y >> reducey) * alphaImageWidth]; - dest += 4; - } - } - } - } - } - } - - ////////////////////////////////////////////////////////////////////////// - // destination range is 8bits - // rescale in linear space - float cScaleR = 1.0f; - float cScaleG = 1.0f; - float cScaleB = 1.0f; - float cScaleA = 1.0f; - float cLowR = 0.0f; - float cLowG = 0.0f; - float cLowB = 0.0f; - float cLowA = 0.0f; - - if (imageFlags & FIM_RENORMALIZED_TEXTURE) - { - const ColorF cMinColor = pImage->mfGet_minColor(); - const ColorF cMaxColor = pImage->mfGet_maxColor(); - - // base range after normalization, fe. [0,1] for 8bit images, or [0,2^15] for RGBE/HDR data - float cUprValue = 1.0f; - if ((eFormat == eTF_R9G9B9E5) || (eFormat == eTF_BC6UH) || (eFormat == eTF_BC6SH)) - { - cUprValue = cMaxColor.a / HDR_UPPERNORM; - } - - // original range before normalization, fe. [0,1.83567] - cScaleR = (cMaxColor.r - cMinColor.r) / cUprValue; - cScaleG = (cMaxColor.g - cMinColor.g) / cUprValue; - cScaleB = (cMaxColor.b - cMinColor.b) / cUprValue; - // original offset before normalization, fe. [0.0001204] - cLowR = cMinColor.r; - cLowG = cMinColor.g; - cLowB = cMinColor.b; - } - - if (imageFlags & FIM_HAS_ATTACHED_ALPHA) - { - if (pAlphaImage) - { - const int alphaImageFlags = pAlphaImage->mfGet_Flags(); - - if (alphaImageFlags & FIM_RENORMALIZED_TEXTURE) - { - const ColorF cMinColor = pAlphaImage->mfGet_minColor(); - const ColorF cMaxColor = pAlphaImage->mfGet_maxColor(); - - // base range after normalization, fe. [0,1] for 8bit images, or [0,2^15] for RGBE/HDR data - float cUprValue = 1.0f; - if ((eFormat == eTF_R9G9B9E5) || (eFormat == eTF_BC6UH) || (eFormat == eTF_BC6SH)) - { - cUprValue = cMaxColor.a / HDR_UPPERNORM; - } - - // original range before normalization, fe. [0,1.83567] - cScaleA = (cMaxColor.r - cMinColor.r) / cUprValue; - // original offset before normalization, fe. [0.0001204] - cLowA = cMinColor.r; - } - } - } - - if (cScaleR != 1.0f || cScaleG != 1.0f || cScaleB != 1.0f || cScaleA != 1.0f || - cLowR != 0.0f || cLowG != 0.0f || cLowB != 0.0f || cLowA != 0.0f) - { - if ((eFormat == eTF_R9G9B9E5) || (eFormat == eTF_BC6UH) || (eFormat == eTF_BC6SH)) - { - imageFlags &= ~FIM_SRGB_READ; - } - - if (imageFlags & FIM_SRGB_READ) - { - for (int s = 0; s < (imageWidth * nHorizontalFaces * imageHeight * nVerticalFaces * 4); s += 4) - { - pDecompBytes[s + 0] = std::min((uint8)255, uint8(LinearToGamma(GammaToLinear(pDecompBytes[s + 0] / LDR_UPPERNORM) * cScaleR + cLowR) * LDR_UPPERNORM + 0.5f)); - pDecompBytes[s + 1] = std::min((uint8)255, uint8(LinearToGamma(GammaToLinear(pDecompBytes[s + 1] / LDR_UPPERNORM) * cScaleG + cLowG) * LDR_UPPERNORM + 0.5f)); - pDecompBytes[s + 2] = std::min((uint8)255, uint8(LinearToGamma(GammaToLinear(pDecompBytes[s + 2] / LDR_UPPERNORM) * cScaleB + cLowB) * LDR_UPPERNORM + 0.5f)); - pDecompBytes[s + 3] = std::min((uint8)255, uint8(LinearToGamma(GammaToLinear(pDecompBytes[s + 3] / LDR_UPPERNORM) * cScaleA + cLowA) * LDR_UPPERNORM + 0.5f)); - } - } - else - { - for (int s = 0; s < (imageWidth * nHorizontalFaces * imageHeight * nVerticalFaces * 4); s += 4) - { - pDecompBytes[s + 0] = std::min((uint8)255, uint8(pDecompBytes[s + 0] * cScaleR + cLowR * LDR_UPPERNORM + 0.5f)); - pDecompBytes[s + 1] = std::min((uint8)255, uint8(pDecompBytes[s + 1] * cScaleG + cLowG * LDR_UPPERNORM + 0.5f)); - pDecompBytes[s + 2] = std::min((uint8)255, uint8(pDecompBytes[s + 2] * cScaleB + cLowB * LDR_UPPERNORM + 0.5f)); - pDecompBytes[s + 3] = std::min((uint8)255, uint8(pDecompBytes[s + 3] * cScaleA + cLowA * LDR_UPPERNORM + 0.5f)); - } - } - } - - bool hasAlpha = (eAttachedFormat != eTF_Unknown) /*|| CImageExtensionHelper::HasAlphaForTextureFormat(eFormat)*/; - for (int s = 0; s < (imageWidth * nHorizontalFaces * imageHeight * nVerticalFaces); s += 4) - { - hasAlpha |= (pDecompBytes[s + 3] != 0xFF); - } - - ////////////////////////////////////////////////////////////////////////// - QString strFormat = NameForTextureFormat(eFormat); - QString mips; - mips = QStringLiteral(" Mips:%1").arg(numMips); - - if (eAttachedFormat != eTF_Unknown) - { - strFormat += " + "; - strFormat += NameForTextureFormat(eAttachedFormat); - } - - strFormat += mips; - - // Check whether it's gamma-corrected or not and add a description accordingly. - if (imageFlags & FIM_SRGB_READ) - { - strFormat += ", SRGB/Gamma corrected"; - } - if (imageFlags & FIM_RENORMALIZED_TEXTURE) - { - strFormat += ", Renormalized"; - } - if (IsLimitedHDR(eFormat)) - { - strFormat += ", HDR"; - } - - outImage.SetFormatDescription(strFormat); - outImage.SetNumberOfMipMaps(numMips); - outImage.SetHasAlphaChannel(hasAlpha); - outImage.SetIsLimitedHDR(IsLimitedHDR(eFormat)); - outImage.SetIsCubemap(boIsCubemap); - outImage.SetFormat(eFormat); - outImage.SetSRGB(imageFlags & FIM_SRGB_READ); - - // done reading file - return bOk; -} - -////////////////////////////////////////////////////////////////////////// -int CImage_DXTC::TextureDataSize(int nWidth, int nHeight, int nDepth, int nMips, ETEX_Format eTF) -{ - if (eTF == eTF_Unknown) - { - return 0; - } - - if (nMips <= 0) - { - nMips = 0; - } - int nSize = 0; - int nM = 0; - while (nWidth || nHeight || nDepth) - { - if (!nWidth) - { - nWidth = 1; - } - if (!nHeight) - { - nHeight = 1; - } - if (!nDepth) - { - nDepth = 1; - } - nM++; - - int nSingleMipSize; - if (IsBlockCompressed(eTF)) - { - int blockSize = CImageExtensionHelper::BytesPerBlock(eTF); - const Vec2i blockDim = CImageExtensionHelper::GetBlockDim(eTF); - nSingleMipSize = ((nWidth + blockDim.x - 1) / blockDim.x) * ((nHeight + blockDim.y - 1) / blockDim.y) * nDepth * blockSize; - } - else - { - nSingleMipSize = nWidth * nHeight * nDepth * CImageExtensionHelper::BytesPerBlock(eTF); - } - nSize += nSingleMipSize; - - nWidth >>= 1; - nHeight >>= 1; - nDepth >>= 1; - if (nMips == nM) - { - break; - } - } - //assert (nM == nMips); - - return nSize; -} - -////////////////////////////////////////////////////////////////////////// -CImage_DXTC::COMPRESSOR_ERROR CImage_DXTC::CheckParameters( - int width, - int height, - CImage_DXTC::UNCOMPRESSED_FORMAT destinationFormat, - const void* sourceData, - void* destinationData, - int destinationDataSize) -{ - const int blockWidth = 4; - const int blockHeight = 4; - - const int bgraPixelSize = 4 * sizeof(uint8); - const int bgraRowSize = bgraPixelSize * width; - - if ((width <= 0) || (height <= 0) || (!sourceData)) - { - return COMPRESSOR_ERROR_NO_INPUT_DATA; - } - - if ((width % blockWidth) || (height % blockHeight)) - { - return COMPRESSOR_ERROR_GENERIC; - } - - if ((destinationData == 0) || (destinationDataSize <= 0)) - { - return COMPRESSOR_ERROR_NO_OUTPUT_POINTER; - } - - if (destinationFormat != FORMAT_ARGB_8888) - { - return COMPRESSOR_ERROR_UNSUPPORTED_DESTINATION_FORMAT; - } - - if ((height * bgraRowSize <= 0) || (height * bgraRowSize > destinationDataSize)) - { - return COMPRESSOR_ERROR_GENERIC; - } - - return COMPRESSOR_ERROR_NONE; -} diff --git a/Code/Sandbox/Editor/Util/Image_DXTC.h b/Code/Sandbox/Editor/Util/Image_DXTC.h deleted file mode 100644 index 507d0232f1..0000000000 --- a/Code/Sandbox/Editor/Util/Image_DXTC.h +++ /dev/null @@ -1,87 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_EDITOR_UTIL_IMAGE_DXTC_H -#define CRYINCLUDE_EDITOR_UTIL_IMAGE_DXTC_H -#pragma once - -#include "ImageExtensionHelper.h" - -class CImageEx; - -class CImage_DXTC -{ - // Typedefs -public: -protected: - ////////////////////////////////////////////////////////////////////////// - // Extracted from Compressorlib.h on SDKs\CompressATI directory. - // Added here because we are not really using the elements inside - // this header file apart from those definitions as we are currently - // loading the DLL CompressATI2.dll manually as recommended by the rendering - // team. - typedef enum - { - FORMAT_ARGB_8888, - FORMAT_ARGB_TOOBIG - } UNCOMPRESSED_FORMAT; - - typedef enum - { - COMPRESSOR_ERROR_NONE, - COMPRESSOR_ERROR_NO_INPUT_DATA, - COMPRESSOR_ERROR_NO_OUTPUT_POINTER, - COMPRESSOR_ERROR_UNSUPPORTED_SOURCE_FORMAT, - COMPRESSOR_ERROR_UNSUPPORTED_DESTINATION_FORMAT, - COMPRESSOR_ERROR_UNABLE_TO_INIT_CODEC, - COMPRESSOR_ERROR_GENERIC - } COMPRESSOR_ERROR; - ////////////////////////////////////////////////////////////////////////// - - // Methods -public: - CImage_DXTC(); - ~CImage_DXTC(); - - // Arguments: - // pQualityLoss - 0 if info is not needed, pointer to the result otherwise - not need to preinitialize - bool Load(const char* filename, CImageEx& outImage, bool* pQualityLoss = 0); // true if success - - static inline const char* NameForTextureFormat(ETEX_Format ETF) { return CImageExtensionHelper::NameForTextureFormat(ETF); } - static inline bool IsBlockCompressed(ETEX_Format ETF) { return CImageExtensionHelper::IsBlockCompressed(ETF); } - static inline bool IsLimitedHDR(ETEX_Format ETF) { return CImageExtensionHelper::IsRangeless(ETF); } - - int TextureDataSize(int nWidth, int nHeight, int nDepth, int nMips, ETEX_Format eTF); - -private: - static COMPRESSOR_ERROR CheckParameters( - int width, - int height, - UNCOMPRESSED_FORMAT destinationFormat, - const void* sourceData, - void* destinationData, - int destinationDataSize); - - static COMPRESSOR_ERROR DecompressTextureBTC( - int width, - int height, - ETEX_Format sourceFormat, - UNCOMPRESSED_FORMAT destinationFormat, - const int imageFlags, - const void* sourceData, - void* destinationData, - int destinationDataSize, - int destinationPageOffset); -}; - -#endif // CRYINCLUDE_EDITOR_UTIL_IMAGE_DXTC_H diff --git a/Code/Sandbox/Editor/Util/Ruler.cpp b/Code/Sandbox/Editor/Util/Ruler.cpp deleted file mode 100644 index 9f802b8b5e..0000000000 --- a/Code/Sandbox/Editor/Util/Ruler.cpp +++ /dev/null @@ -1,268 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// Description : Ruler helper for Editor to determine distances - - -#include "EditorDefs.h" - -#include "Ruler.h" - -// Editor -#include "Settings.h" -#include "Viewport.h" -#include "Include/HitContext.h" -#include "Include/IObjectManager.h" -#include "Objects/BaseObject.h" - -// Qt -#include - -////////////////////////////////////////////////////////////////////////// -CRuler::CRuler() - : m_bActive(false) - , m_MouseOverObject(GUID_NULL) - , m_sphereScale(0.5f) - , m_sphereTrans(0.5f) -{ -} - -////////////////////////////////////////////////////////////////////////// -CRuler::~CRuler() -{ - SetActive(false); -} - -////////////////////////////////////////////////////////////////////////// -bool CRuler::HasQueuedPaths() const -{ - return false; -} - -////////////////////////////////////////////////////////////////////////// -void CRuler::SetActive(bool bActive) -{ - if (m_bActive != bActive) - { - m_bActive = bActive; - - if (m_bActive) - { - m_sphereScale = gSettings.gizmo.rulerSphereScale; - m_sphereTrans = gSettings.gizmo.rulerSphereTrans; - } - - // Reset - m_startPoint.Reset(); - m_endPoint.Reset(); - - CBaseObject* pObject = GetIEditor()->GetObjectManager()->FindObject(m_MouseOverObject); - if (pObject) - { - pObject->SetHighlight(false); - } - m_MouseOverObject = GUID_NULL; - } -} - -////////////////////////////////////////////////////////////////////////// -void CRuler::Update() -{ - if (!IsActive()) - { - return; - } - - if (CheckVirtualKey(Qt::Key_Escape)) - { - SetActive(false); - return; - } - - static const ColorF colours[] = - { - Col_Blue, - Col_Green, - Col_Red, - Col_Yellow, - Col_Magenta, - Col_Black, - }; - - IRenderer* pRenderer = GetIEditor()->GetSystem()->GetIRenderer(); - CRY_ASSERT(pRenderer); - IRenderAuxGeom* pAuxGeom = pRenderer->GetIRenderAuxGeom(); - CRY_ASSERT(pAuxGeom); - - CViewport* pActiveView = GetIEditor()->GetActiveView(); - if (pActiveView) - { - // Draw where cursor currently is - if (!IsObjectSelectMode(pActiveView)) - { - QPoint vCursorPoint = QCursor::pos(); - pActiveView->ScreenToClient(vCursorPoint); - vCursorPoint = QHighDpi::toNativePixels(vCursorPoint, QGuiApplication::screenAt(vCursorPoint)); - Vec3 vCursorWorldPos = pActiveView->SnapToGrid(pActiveView->ViewToWorld(vCursorPoint)); - Vec3 vOffset(0.1f, 0.1f, 0.1f); - pAuxGeom->SetRenderFlags(e_Def3DPublicRenderflags | e_AlphaBlended); - pAuxGeom->DrawSphere(vCursorWorldPos, m_sphereScale, ColorF(0.5, 0.5, 0.5, m_sphereTrans)); - pAuxGeom->DrawAABB(AABB(vCursorWorldPos - vOffset * m_sphereScale, vCursorWorldPos + vOffset * m_sphereScale), false, ColorF(1.0f, 0.0f, 0.0f, 1.0f), eBBD_Faceted); - } - - uint32 x = 12, y = 60; - - if (!m_startPoint.IsEmpty()) - { - //pAuxGeom->DrawSphere(m_startPoint.GetPos(), 1.0f, ColorB(255,255,255,255)); - m_startPoint.Render(pRenderer); - } - if (!m_endPoint.IsEmpty()) - { - //pAuxGeom->DrawSphere(m_endPoint.GetPos(), 1.0f, ColorB(255,255,255,255)); - m_endPoint.Render(pRenderer); - - pAuxGeom->DrawLine(m_startPoint.GetPos(), ColorB(255, 255, 255, 255), m_endPoint.GetPos(), ColorB(255, 255, 255, 255)); - - string sTempText; - - // Compute distance and output results - // TODO: Consider movement speed outputs here as well? - const float fDistance = m_startPoint.GetDistance(m_endPoint); - sTempText.Format("Straight-line distance: %.3f", fDistance); - - // Draw mid text - float white[] = {1.0f, 1.0f, 1.0f, 1.0f}; - pRenderer->Draw2dLabel(x, y, 2.0f, white, false, sTempText.c_str()); - y += 18; - } - } -} - -////////////////////////////////////////////////////////////////////////// -bool CRuler::IsObjectSelectMode([[maybe_unused]] CViewport* pView) const -{ - const bool bShiftDown = CheckVirtualKey(Qt::Key_Shift); - - return (bShiftDown); -} - -////////////////////////////////////////////////////////////////////////// -void CRuler::UpdateRulerPoint(CViewport* pView, const QPoint& point, CRulerPoint& rulerPoint, bool bRequestPath) -{ - CRY_ASSERT(pView); - - const bool bObjectSelect = IsObjectSelectMode(pView); - - rulerPoint.SetHelperSettings(m_sphereScale, m_sphereTrans); - - // Do entity hit check - if (bObjectSelect) - { - HitContext hitInfo; - pView->HitTest(point, hitInfo); - - CBaseObject* pHitObj = hitInfo.object; - rulerPoint.Set(pHitObj); - } - else - { - Vec3 vWorldPoint = pView->SnapToGrid(pView->ViewToWorld(point)); - rulerPoint.Set(vWorldPoint); - } - - if (bRequestPath) - { - RequestPath(); - } -} - -////////////////////////////////////////////////////////////////////////// -void CRuler::RequestPath() -{ -} - -////////////////////////////////////////////////////////////////////////// -bool CRuler::MouseCallback(CViewport* pView, EMouseEvent event, QPoint& point, int flags) -{ - bool bResult = IsActive(); - - if (bResult) - { - switch (event) - { - case eMouseMove: - OnMouseMove(pView, point, flags); - break; - case eMouseLUp: - OnLButtonUp(pView, point, flags); - break; - } - } - - return bResult; -} - -////////////////////////////////////////////////////////////////////////// -void CRuler::OnMouseMove(CViewport* pView, QPoint& point, [[maybe_unused]] int flags) -{ - GUID hitGUID = GUID_NULL; - - if (IsObjectSelectMode(pView)) - { - // Check for hit entity - HitContext hitInfo; - pView->HitTest(point, hitInfo); - CBaseObject* pHitObj = hitInfo.object; - if (pHitObj) - { - hitGUID = pHitObj->GetId(); - } - } - - if (hitGUID != m_MouseOverObject) - { - // Kill highlight on old - CBaseObject* pOldObj = GetIEditor()->GetObjectManager()->FindObject(m_MouseOverObject); - if (pOldObj) - { - pOldObj->SetHighlight(false); - } - - CBaseObject* pHitObj = GetIEditor()->GetObjectManager()->FindObject(hitGUID); - if (pHitObj) - { - pHitObj->SetHighlight(true); - } - - m_MouseOverObject = hitGUID; - } -} - -////////////////////////////////////////////////////////////////////////// -void CRuler::OnLButtonUp(CViewport* pView, QPoint& point, [[maybe_unused]] int flags) -{ - if (m_startPoint.IsEmpty()) - { - UpdateRulerPoint(pView, point, m_startPoint, false); - } - else if (m_endPoint.IsEmpty()) - { - UpdateRulerPoint(pView, point, m_endPoint, true); - } - else - { - UpdateRulerPoint(pView, point, m_startPoint, false); - m_endPoint.Reset(); - } -} diff --git a/Code/Sandbox/Editor/Util/Ruler.h b/Code/Sandbox/Editor/Util/Ruler.h deleted file mode 100644 index 1e04e2a1f9..0000000000 --- a/Code/Sandbox/Editor/Util/Ruler.h +++ /dev/null @@ -1,69 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// Description : Ruler helper for Editor to determine distances - - -#ifndef CRYINCLUDE_EDITOR_UTIL_RULER_H -#define CRYINCLUDE_EDITOR_UTIL_RULER_H -#pragma once - - -#include "RulerPoint.h" - -//! The Ruler utility helps to determine distances between user-specified points -class CRuler -{ -public: - CRuler(); - ~CRuler(); - - //! Returns if ruler has queued paths in the path agent - bool HasQueuedPaths() const; - - //! Activate the ruler - void SetActive(bool bActive); - bool IsActive() const { return m_bActive; } - - //! Update - void Update(); - - //! Mouse callback handling from viewport - bool MouseCallback(CViewport* pView, EMouseEvent event, QPoint& point, int flags); - -private: - //! Mouse callback helpers - void OnMouseMove(CViewport* pView, QPoint& point, int flags); - void OnLButtonUp(CViewport* pView, QPoint& point, int flags); - - //! Returns world point based on mouse point - void UpdateRulerPoint(CViewport* pView, const QPoint& point, CRulerPoint& rulerPoint, bool bRequestPath); - - //! Request a path using the path agent - void RequestPath(); - - bool IsObjectSelectMode(CViewport* pView) const; - -private: - bool m_bActive; - GUID m_MouseOverObject; - - // Base point - CRulerPoint m_startPoint; - CRulerPoint m_endPoint; - - float m_sphereScale; - float m_sphereTrans; -}; - -#endif // CRYINCLUDE_EDITOR_UTIL_RULER_H diff --git a/Code/Sandbox/Editor/Util/RulerPoint.cpp b/Code/Sandbox/Editor/Util/RulerPoint.cpp deleted file mode 100644 index d9f148d26a..0000000000 --- a/Code/Sandbox/Editor/Util/RulerPoint.cpp +++ /dev/null @@ -1,216 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// Description : Ruler helper for Editor to determine distances - - -#include "EditorDefs.h" - -#include "RulerPoint.h" - -// Editor -#include "Objects/BaseObject.h" -#include "Include/IObjectManager.h" - -////////////////////////////////////////////////////////////////////////// -CRulerPoint::CRulerPoint() - : m_type(eType_Invalid) - , m_vPoint(ZERO) - , m_ObjectGUID(GUID_NULL) -{ - Reset(); -} - -////////////////////////////////////////////////////////////////////////// -CRulerPoint& CRulerPoint::operator =(CRulerPoint const& other) -{ - if (this != &other) - { - Reset(); // Manage deselect of current object, etc. - - m_type = other.m_type; - m_vPoint = other.m_vPoint; - m_ObjectGUID = other.m_ObjectGUID; - m_sphereScale = other.m_sphereScale; - m_sphereTrans = other.m_sphereTrans; - } - - return *this; -} - -////////////////////////////////////////////////////////////////////////// -void CRulerPoint::Reset() -{ - // Kill highlight of current object - CBaseObject* pObject = GetObject(); - if (pObject) - { - pObject->SetHighlight(false); - } - - m_type = eType_Invalid; - m_vPoint.zero(); - m_ObjectGUID = GUID_NULL; -} - -////////////////////////////////////////////////////////////////////////// -void CRulerPoint::Render(IRenderer* pRenderer) -{ - CRY_ASSERT(pRenderer); - IRenderAuxGeom* pAuxGeom = pRenderer->GetIRenderAuxGeom(); - - switch (m_type) - { - case eType_Point: - { - Vec3 vOffset(0.1f, 0.1f, 0.1f); - pAuxGeom->SetRenderFlags(e_Def3DPublicRenderflags | e_AlphaBlended); - pAuxGeom->DrawSphere(m_vPoint, m_sphereScale, ColorF(1, 1, 1, m_sphereTrans)); - pAuxGeom->DrawAABB(AABB(m_vPoint - vOffset * m_sphereScale, m_vPoint + vOffset * m_sphereScale), false, ColorF(0.0f, 1.0f, 0.0f, 1.0f), eBBD_Faceted); - } - break; - - case eType_Object: - { - CBaseObject* pObject = GetObject(); - if (pObject) - { - pObject->SetHighlight(true); - } - } - break; - - default: - return; // No extra drawing - } -} - -////////////////////////////////////////////////////////////////////////// -void CRulerPoint::Set(const Vec3& vPos) -{ - Reset(); - - m_type = eType_Point; - m_vPoint = vPos; -} - -////////////////////////////////////////////////////////////////////////// -void CRulerPoint::Set(CBaseObject* pObject) -{ - Reset(); - - m_type = eType_Object; - m_ObjectGUID = (pObject ? pObject->GetId() : GUID_NULL); -} - -////////////////////////////////////////////////////////////////////////// -void CRulerPoint::SetHelperSettings(float scale, float trans) -{ - m_sphereScale = scale; - m_sphereTrans = trans; -} - -////////////////////////////////////////////////////////////////////////// -bool CRulerPoint::IsEmpty() const -{ - bool bResult = true; - - switch (m_type) - { - case eType_Invalid: - bResult = true; - break; - - case eType_Point: - bResult = m_vPoint.IsZero(); - break; - - case eType_Object: - bResult = (GetObject() == 0); - break; - } - - return bResult; -} - -////////////////////////////////////////////////////////////////////////// -Vec3 CRulerPoint::GetPos() const -{ - Vec3 vResult(ZERO); - - switch (m_type) - { - case eType_Point: - vResult = m_vPoint; - break; - - case eType_Object: - { - CBaseObject* pObject = GetObject(); - if (pObject) - { - vResult = pObject->GetWorldPos(); - } - } - break; - } - - return vResult; -} - -////////////////////////////////////////////////////////////////////////// -Vec3 CRulerPoint::GetMidPoint(const CRulerPoint& otherPoint) const -{ - Vec3 vResult(ZERO); - - if (!IsEmpty() && !otherPoint.IsEmpty()) - { - vResult = GetPos() + (otherPoint.GetPos() - GetPos()) * 0.5f; - } - else if (!IsEmpty()) - { - vResult = GetPos(); - } - else - { - vResult = otherPoint.GetPos(); - } - - return vResult; -} - -////////////////////////////////////////////////////////////////////////// -float CRulerPoint::GetDistance(const CRulerPoint& otherPoint) const -{ - float fResult = 0.0f; - - if (!IsEmpty() && !otherPoint.IsEmpty()) - { - fResult = GetPos().GetDistance(otherPoint.GetPos()); - } - - return fResult; -} - -////////////////////////////////////////////////////////////////////////// -CBaseObject* CRulerPoint::GetObject() const -{ - CBaseObject* pResult = NULL; - - if (m_type == eType_Object) - { - pResult = GetIEditor()->GetObjectManager()->FindObject(m_ObjectGUID); - } - - return pResult; -} diff --git a/Code/Sandbox/Editor/Util/RulerPoint.h b/Code/Sandbox/Editor/Util/RulerPoint.h deleted file mode 100644 index 0d68c9450c..0000000000 --- a/Code/Sandbox/Editor/Util/RulerPoint.h +++ /dev/null @@ -1,65 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// Description : Ruler point helper, used by CRuler - - -#ifndef CRYINCLUDE_EDITOR_UTIL_RULERPOINT_H -#define CRYINCLUDE_EDITOR_UTIL_RULERPOINT_H -#pragma once - - -class CRuler; - -//! Ruler point helper - Defines a point for the ruler -class CRulerPoint -{ -public: - CRulerPoint(); - CRulerPoint& operator =(CRulerPoint const& other); - - void Reset(); - void Render(IRenderer* pRenderer); - - //! Set helpers - void Set(const Vec3& vPos); - void Set(CBaseObject* pObject); - void SetHelperSettings(float scale, float trans); - - //! Returns is point has valid data in it (in use) - bool IsEmpty() const; - - //! Helpers to get correct data out - Vec3 GetPos() const; - Vec3 GetMidPoint(const CRulerPoint& otherPoint) const; - float GetDistance(const CRulerPoint& otherPoint) const; - CBaseObject* GetObject() const; - -private: - enum EType - { - eType_Invalid, - eType_Point, - eType_Object, - - eType_COUNT, - }; - EType m_type; - - Vec3 m_vPoint; - GUID m_ObjectGUID; - float m_sphereScale; - float m_sphereTrans; -}; - -#endif // CRYINCLUDE_EDITOR_UTIL_RULERPOINT_H diff --git a/Code/Sandbox/Editor/ViewPane.cpp b/Code/Sandbox/Editor/ViewPane.cpp index 480e39bedf..eda0f390fa 100644 --- a/Code/Sandbox/Editor/ViewPane.cpp +++ b/Code/Sandbox/Editor/ViewPane.cpp @@ -643,27 +643,6 @@ void CLayoutViewPane::SetFullscren(bool f) m_bFullscreen = f; } -////////////////////////////////////////////////////////////////////////// -void CLayoutViewPane::SetFullscreenViewport(bool b) -{ - if (!m_viewport) - { - return; - } - - if (b) - { - m_viewport->setParent(0); - - GetIEditor()->GetRenderer()->ChangeResolution(800, 600, 32, 80, true, false); - } - else - { - m_viewport->setParent(this); - GetIEditor()->GetRenderer()->ChangeResolution(800, 600, 32, 80, false, false); - } -} - ////////////////////////////////////////////////////////////////////////// void CLayoutViewPane::SetFocusToViewport() { diff --git a/Code/Sandbox/Editor/ViewPane.h b/Code/Sandbox/Editor/ViewPane.h index 53d13c105d..80647e7a15 100644 --- a/Code/Sandbox/Editor/ViewPane.h +++ b/Code/Sandbox/Editor/ViewPane.h @@ -63,8 +63,6 @@ public: void SetFullscren(bool f); bool IsFullscreen() const { return m_bFullscreen; } - void SetFullscreenViewport(bool b); - QWidget* GetViewport() { return m_viewport; } ////////////////////////////////////////////////////////////////////////// diff --git a/Code/Sandbox/Editor/Viewport.cpp b/Code/Sandbox/Editor/Viewport.cpp index 37a9ee5f29..cc278b18b0 100644 --- a/Code/Sandbox/Editor/Viewport.cpp +++ b/Code/Sandbox/Editor/Viewport.cpp @@ -30,7 +30,6 @@ #include "Include/HitContext.h" #include "Objects/ObjectManager.h" #include "Util/3DConnexionDriver.h" -#include "Util/Ruler.h" #include "PluginManager.h" #include "Include/IRenderListener.h" #include "GameEngine.h" @@ -1414,17 +1413,7 @@ bool QtViewport::MouseCallback(EMouseEvent event, const QPoint& point, Qt::Keybo break; } - ////////////////////////////////////////////////////////////////////////// - // Asks Ruler to handle mouse callback. - CRuler* pRuler = GetIEditor()->GetRuler(); QPoint tempPoint(point.x(), point.y()); - if (pRuler) - { - if (pRuler->MouseCallback(this, event, tempPoint, flags)) - { - return true; - } - } ////////////////////////////////////////////////////////////////////////// // Handle viewport manipulators. diff --git a/Code/Sandbox/Editor/ViewportTitleDlg.cpp b/Code/Sandbox/Editor/ViewportTitleDlg.cpp index 427a5c32e8..95531e117c 100644 --- a/Code/Sandbox/Editor/ViewportTitleDlg.cpp +++ b/Code/Sandbox/Editor/ViewportTitleDlg.cpp @@ -95,8 +95,6 @@ CViewportTitleDlg::~CViewportTitleDlg() { GetISystem()->GetISystemEventDispatcher()->RemoveListener(this); GetIEditor()->UnregisterNotifyListener(this); - ICVar* pDisplayInfo(gEnv->pConsole->GetCVar("r_displayInfo")); - pDisplayInfo->RemoveOnChangeFunctor(m_displayInfoCallbackIndex); } ////////////////////////////////////////////////////////////////////////// @@ -158,8 +156,6 @@ void CViewportTitleDlg::OnToggleHelpers() ////////////////////////////////////////////////////////////////////////// void CViewportTitleDlg::OnToggleDisplayInfo() { - int currentDisplayInfo = gEnv->pConsole->GetCVar("r_displayInfo")->GetIVal(); - gEnv->pConsole->GetCVar("r_displayInfo")->Set(currentDisplayInfo >= 3 ? 0 : currentDisplayInfo + 1); } ////////////////////////////////////////////////////////////////////////// @@ -548,12 +544,8 @@ void CViewportTitleDlg::UpdateCustomPresets(const QString& text, QStringList& cu } } -void CViewportTitleDlg::OnChangedDisplayInfo([[maybe_unused]] ICVar* pDisplayInfo, QAbstractButton* pDisplayInfoButton) +void CViewportTitleDlg::OnChangedDisplayInfo([[maybe_unused]] ICVar* pDisplayInfo, [[maybe_unused]] QAbstractButton* pDisplayInfoButton) { - if (pDisplayInfoButton) - { - pDisplayInfoButton->setChecked(gEnv->pConsole->GetCVar("r_displayInfo")->GetIVal()); - } } bool CViewportTitleDlg::eventFilter(QObject* object, QEvent* event) diff --git a/Code/Sandbox/Editor/editor_lib_files.cmake b/Code/Sandbox/Editor/editor_lib_files.cmake index f6537909e9..5f6c1ed2bd 100644 --- a/Code/Sandbox/Editor/editor_lib_files.cmake +++ b/Code/Sandbox/Editor/editor_lib_files.cmake @@ -465,9 +465,6 @@ set(FILES SelectLightAnimationDialog.h SelectSequenceDialog.cpp SelectSequenceDialog.h - ShadersDialog.cpp - ShadersDialog.h - ShadersDialog.ui StartupLogoDialog.cpp StartupLogoDialog.h StartupLogoDialog.ui @@ -659,10 +656,6 @@ set(FILES ProcessInfo.cpp ProcessInfo.h Report.h - ShaderCache.cpp - ShaderCache.h - ShaderEnum.cpp - ShaderEnum.h SurfaceTypeValidator.cpp SurfaceTypeValidator.h TrackView/AtomOutputFrameCapture.cpp @@ -751,15 +744,11 @@ set(FILES SettingsBlock.cpp SettingsBlock.h Util/AffineParts.h - Util/ArcBall.cpp - Util/ArcBall.h Util/AutoLogTime.cpp Util/AutoLogTime.h Util/AutoDirectoryRestoreFileDialog.h Util/AutoDirectoryRestoreFileDialog.cpp Util/CryMemFile.h - Util/CubemapUtils.cpp - Util/CubemapUtils.h Util/DynamicArray2D.cpp Util/DynamicArray2D.h Util/EditorAutoLevelLoadTest.cpp @@ -833,17 +822,11 @@ set(FILES Util/ImageASC.h Util/ImageBT.cpp Util/ImageBT.h - Util/Image_DXTC.cpp - Util/Image_DXTC.h Util/ImageGif.cpp Util/ImageGif.h Util/ImageTIF.cpp Util/ImageTIF.h Util/Math.h - Util/Ruler.cpp - Util/RulerPoint.cpp - Util/Ruler.h - Util/RulerPoint.h Util/UIEnumerations.cpp Util/UIEnumerations.h WelcomeScreen/WelcomeScreenDialog.h diff --git a/Code/Sandbox/Plugins/ComponentEntityEditorPlugin/ComponentEntityDebugPrinter.cpp b/Code/Sandbox/Plugins/ComponentEntityEditorPlugin/ComponentEntityDebugPrinter.cpp deleted file mode 100644 index 2eff76c738..0000000000 --- a/Code/Sandbox/Plugins/ComponentEntityEditorPlugin/ComponentEntityDebugPrinter.cpp +++ /dev/null @@ -1,71 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -#include "ComponentEntityEditorPlugin_precompiled.h" -#include "ComponentEntityDebugPrinter.h" - -#include -#include - -ComponentEntityDebugPrinter::ComponentEntityDebugPrinter() -{ - AZ::TickBus::Handler::BusConnect(); -} - -void ComponentEntityDebugPrinter::OnTick(float /*deltaTime*/, AZ::ScriptTimePoint /*time*/) -{ - if (!GetIEditor()->GetRenderer()) - { - return; - } - - ICVar* displayInfo = GetIEditor()->GetSystem()->GetIConsole()->GetCVar("r_DisplayInfo"); - if (!displayInfo || displayInfo->GetIVal() == 0) - { - return; - } - - float x = 2.f; - float y = 2.f; - - SDrawTextInfo textInfo; - textInfo.xscale = 1.25f; - textInfo.yscale = textInfo.xscale; - textInfo.flags = eDrawText_2D | eDrawText_FixedSize | eDrawText_800x600 | eDrawText_Monospace; - - // Figure out whether we're querying the Game or Editor entity context - AzFramework::EntityContextId entityContextId = AzFramework::EntityContextId::CreateNull(); - if (GetIEditor()->IsInGameMode()) - { - AzFramework::GameEntityContextRequestBus::BroadcastResult(entityContextId, &AzFramework::GameEntityContextRequestBus::Events::GetGameEntityContextId); - } - else - { - AzToolsFramework::EditorEntityContextRequestBus::BroadcastResult(entityContextId, &AzToolsFramework::EditorEntityContextRequestBus::Events::GetEditorEntityContextId); - } - if (entityContextId.IsNull()) - { - return; - } - - // Print the number of entities in the level - AZ::SliceComponent* rootSlice = nullptr; - AzFramework::SliceEntityOwnershipServiceRequestBus::EventResult(rootSlice, entityContextId, - &AzFramework::SliceEntityOwnershipServiceRequestBus::Events::GetRootSlice); - if (rootSlice) - { - size_t numEntities = rootSlice->GetInstantiatedEntityCount(); - if (numEntities > 0) - { - GetIEditor()->GetRenderer()->DrawTextQueued(Vec3(x, y, 0), textInfo, AZStd::string::format("Entities: %zu", numEntities).c_str()); - } - } -} diff --git a/Code/Sandbox/Plugins/ComponentEntityEditorPlugin/ComponentEntityDebugPrinter.h b/Code/Sandbox/Plugins/ComponentEntityEditorPlugin/ComponentEntityDebugPrinter.h deleted file mode 100644 index 5a8c1d4856..0000000000 --- a/Code/Sandbox/Plugins/ComponentEntityEditorPlugin/ComponentEntityDebugPrinter.h +++ /dev/null @@ -1,32 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -#pragma once - -#include - -/** - * Prints debug statistics about Component Entities to screen - */ -class ComponentEntityDebugPrinter - : private AZ::TickBus::Handler -{ -public: - AZ_CLASS_ALLOCATOR(ComponentEntityDebugPrinter, AZ::SystemAllocator, 0); - - ComponentEntityDebugPrinter(); - -private: - ////////////////////////////////////////////////////////////////////////// - // TickBus - void OnTick(float deltaTime, AZ::ScriptTimePoint time) override; - ////////////////////////////////////////////////////////////////////////// -}; diff --git a/Code/Sandbox/Plugins/ComponentEntityEditorPlugin/Objects/ComponentEntityObject.cpp b/Code/Sandbox/Plugins/ComponentEntityEditorPlugin/Objects/ComponentEntityObject.cpp index c85ed1248f..df2e6bae10 100644 --- a/Code/Sandbox/Plugins/ComponentEntityEditorPlugin/Objects/ComponentEntityObject.cpp +++ b/Code/Sandbox/Plugins/ComponentEntityEditorPlugin/Objects/ComponentEntityObject.cpp @@ -915,14 +915,6 @@ void CComponentEntityObject::Display(DisplayContext& dc) m_entityId, &AzFramework::EntityDebugDisplayEvents::DisplayEntityViewport, AzFramework::ViewportInfo{ dc.GetView()->asCViewport()->GetViewportId() }, *debugDisplay); - - if (showIcons) - { - if (!displaySelectionHelper && !IsSelected()) - { - m_entityIconVisible = DisplayEntityIcon(dc, *debugDisplay); - } - } } } } @@ -984,38 +976,6 @@ void CComponentEntityObject::OnContextMenu(QMenu* /*pMenu*/) // Deliberately bypass the base class implementation (CEntityObject::OnContextMenu()). } -bool CComponentEntityObject::DisplayEntityIcon( - DisplayContext& displayContext, AzFramework::DebugDisplayRequests& debugDisplay) -{ - if (!m_hasIcon) - { - return false; - } - - const QPoint entityScreenPos = displayContext.GetView()->WorldToView(GetWorldPos()); - - const Vec3 worldPos = GetWorldPos(); - const CCamera& camera = gEnv->pRenderer->GetCamera(); - const Vec3 cameraToEntity = (worldPos - camera.GetMatrix().GetTranslation()); - const float distSq = cameraToEntity.GetLengthSquared(); - if (distSq > square(s_kIconMaxWorldDist)) - { - return false; - } - - // Draw component icons on top of meshes (no depth testing) - int iconFlags = (int) DisplayContext::ETextureIconFlags::TEXICON_ON_TOP; - SetDrawTextureIconProperties(displayContext, worldPos, 1.0f, iconFlags); - - const float iconScale = s_kIconMinScale + (s_kIconMaxScale - s_kIconMinScale) * (1.0f - clamp_tpl(max(0.0f, sqrt_tpl(distSq) - s_kIconCloseDist) / s_kIconFarDist, 0.0f, 1.0f)); - const float worldDistToScreenScaleFraction = 0.045f; - const float screenScale = displayContext.GetView()->GetScreenScaleFactor(GetWorldPos()) * worldDistToScreenScaleFraction; - - debugDisplay.DrawTextureLabel(m_iconTexture, LYVec3ToAZVec3(worldPos), s_kIconSize * iconScale, s_kIconSize * iconScale, GetTextureIconFlags()); - - return true; -} - void CComponentEntityObject::SetupEntityIcon() { bool hideIconInViewport = false; @@ -1031,8 +991,9 @@ void CComponentEntityObject::SetupEntityIcon() { m_hasIcon = true; - int textureId = GetIEditor()->GetIconManager()->GetIconTexture(m_icon.c_str()); - m_iconTexture = GetIEditor()->GetRenderer() ? GetIEditor()->GetRenderer()->EF_GetTextureByID(textureId) : nullptr; + // ToDo: Get from Atom? + // int textureId = GetIEditor()->GetIconManager()->GetIconTexture(m_icon.c_str()); + m_iconTexture = nullptr; } } } diff --git a/Code/Sandbox/Plugins/ComponentEntityEditorPlugin/SandboxIntegration.cpp b/Code/Sandbox/Plugins/ComponentEntityEditorPlugin/SandboxIntegration.cpp index c7c501c70a..33d4b5baf4 100644 --- a/Code/Sandbox/Plugins/ComponentEntityEditorPlugin/SandboxIntegration.cpp +++ b/Code/Sandbox/Plugins/ComponentEntityEditorPlugin/SandboxIntegration.cpp @@ -59,7 +59,6 @@ #include #include "Objects/ComponentEntityObject.h" -#include "ComponentEntityDebugPrinter.h" #include "ISourceControl.h" #include "UI/QComponentEntityEditorMainWindow.h" @@ -72,7 +71,6 @@ #include #include #include -#include #include #include #include @@ -141,7 +139,6 @@ SandboxIntegrationManager::SandboxIntegrationManager() , m_startedUndoRecordingNestingLevel(0) , m_dc(nullptr) , m_notificationWindowManager(new AzToolsFramework::SliceOverridesNotificationWindowManager()) - , m_entityDebugPrinter(aznew ComponentEntityDebugPrinter()) { // Required to receive events from the Cry Engine undo system GetIEditor()->GetUndoManager()->AddListener(this); @@ -1998,92 +1995,6 @@ void SandboxIntegrationManager::BrowseForAssets(AssetSelectionModel& selection) AssetBrowserComponentRequestBus::Broadcast(&AssetBrowserComponentRequests::PickAssets, selection, GetMainWindow()); } -void SandboxIntegrationManager::GenerateCubemapForEntity(AZ::EntityId entityId, AZStd::string* cubemapOutputPath, bool hideEntity) -{ - GenerateCubemapWithIDForEntity(entityId, AZ::Uuid::CreateNull(), cubemapOutputPath, hideEntity, false); -} - -void SandboxIntegrationManager::GenerateCubemapWithIDForEntity(AZ::EntityId entityId, AZ::Uuid cubemapId, - AZStd::string* cubemapOutputPath, bool hideEntity, bool hasCubemapId) -{ - AZ::u32 resolution = 0; - EBUS_EVENT_ID_RESULT(resolution, entityId, LmbrCentral::EditorLightComponentRequestBus, GetCubemapResolution); - - if (resolution > 0) - { - CComponentEntityObject* componentEntity = CComponentEntityObject::FindObjectForEntity(entityId); - - if (componentEntity) - { - QString levelfolder = GetIEditor()->GetGameEngine()->GetLevelPath(); - QString levelname = Path::GetFile(levelfolder).toLower(); - QString fullGameFolder = QString(Path::GetEditingGameDataFolder().c_str()); - QString texturename; - if (hasCubemapId) - { - texturename = QStringLiteral("%1_cm.tif").arg(cubemapId.ToString(false, false)); - } - else - { - texturename = QStringLiteral("%1_cm.tif").arg(static_cast(componentEntity->GetAssociatedEntityId())); - } - texturename = texturename.toLower(); - - QString fullFolder = Path::SubDirectoryCaseInsensitive(fullGameFolder, {"textures", "cubemaps", levelname}); - QString fullFilename = QDir(fullFolder).absoluteFilePath(texturename); - QString relFilename = QDir(fullGameFolder).relativeFilePath(fullFilename); - - bool directlyExists = CFileUtil::CreateDirectory(fullFolder.toUtf8().data()); - if (!directlyExists) - { - QMessageBox::warning(GetMainWindow(), QObject::tr("Cubemap Generation Failed"), QString(QObject::tr("Failed to create destination path '%1'")).arg(fullFolder)); - return; - } - - if (CubemapUtils::GenCubemapWithObjectPathAndSize(fullFilename, componentEntity, static_cast(resolution), hideEntity)) - { - AZStd::string assetPath = relFilename.toUtf8().data(); - AzFramework::StringFunc::Path::ReplaceExtension(assetPath, ".dds"); - - EBUS_EVENT_ID(entityId, LmbrCentral::EditorLightComponentRequestBus, SetCubemap, assetPath); - - if (cubemapOutputPath) - { - *cubemapOutputPath = AZStd::move(assetPath); - } - } - else - { - QMessageBox::warning(GetMainWindow(), QObject::tr("Cubemap Generation Failed"), QObject::tr("Unspecified error")); - } - } - } -} - -void SandboxIntegrationManager::GenerateAllCubemaps() -{ - AZStd::string cubemapOutputPath; - - std::vector results; - results.reserve(128); - GetIEditor()->GetObjectManager()->FindObjectsOfType(OBJTYPE_AZENTITY, results); - for (std::vector::iterator end = results.end(), item = results.begin(); item != end; ++item) - { - CComponentEntityObject* componentEntity = static_cast(*item); - - //check if it's customized cubemap, only generate it if it's not. - bool isCustomizedCubemap = true; - EBUS_EVENT_ID_RESULT(isCustomizedCubemap, componentEntity->GetAssociatedEntityId(), LmbrCentral::EditorLightComponentRequestBus, UseCustomizedCubemap); - - if (isCustomizedCubemap) - { - continue; - } - - GenerateCubemapForEntity(componentEntity->GetAssociatedEntityId(), nullptr, true); - } -} - void SandboxIntegrationManager::SetColor(float r, float g, float b, float a) { if (m_dc) @@ -2575,19 +2486,6 @@ void SandboxIntegrationManager::Draw2dTextLabel(float x, float y, float size, co } } -void SandboxIntegrationManager::DrawTextOn2DBox(const AZ::Vector3& pos, const char* text, float textScale, const AZ::Vector4& textColor, const AZ::Vector4& textBackColor) -{ - if (m_dc) - { - m_dc->DrawTextOn2DBox( - AZVec3ToLYVec3(pos), - text, - textScale, - ColorF(AZVec3ToLYVec3(textColor.GetAsVector3()), textColor.GetW()), - ColorF(AZVec3ToLYVec3(textBackColor.GetAsVector3()), textBackColor.GetW())); - } -} - void SandboxIntegrationManager::DrawTextureLabel(ITexture* texture, const AZ::Vector3& pos, float sizeX, float sizeY, int texIconFlags) { if (m_dc) @@ -2614,8 +2512,12 @@ void SandboxIntegrationManager::DrawTextureLabel(ITexture* texture, const AZ::Ve void SandboxIntegrationManager::DrawTextureLabel(int textureId, const AZ::Vector3& pos, float sizeX, float sizeY, int texIconFlags) { - ITexture* texture = GetIEditor()->GetRenderer()->EF_GetTextureByID(textureId); - DrawTextureLabel(texture, pos, sizeX, sizeY, texIconFlags); + // ToDo: With Atom? + AZ_UNUSED(textureId); + AZ_UNUSED(pos); + AZ_UNUSED(sizeX); + AZ_UNUSED(sizeY); + AZ_UNUSED(texIconFlags); } void SandboxIntegrationManager::SetLineWidth(float width) diff --git a/Code/Sandbox/Plugins/ComponentEntityEditorPlugin/SandboxIntegration.h b/Code/Sandbox/Plugins/ComponentEntityEditorPlugin/SandboxIntegration.h index 0cbfe1df93..b3c60bca45 100644 --- a/Code/Sandbox/Plugins/ComponentEntityEditorPlugin/SandboxIntegration.h +++ b/Code/Sandbox/Plugins/ComponentEntityEditorPlugin/SandboxIntegration.h @@ -143,9 +143,6 @@ private: QDockWidget* InstanceViewPane(const char* paneName) override; void CloseViewPane(const char* paneName) override; void BrowseForAssets(AzToolsFramework::AssetBrowser::AssetSelectionModel& selection) override; - void GenerateAllCubemaps() override; - void GenerateCubemapForEntity(AZ::EntityId entityId, AZStd::string* cubemapOutputPath, bool hideEntity) override; - void GenerateCubemapWithIDForEntity(AZ::EntityId entityId, AZ::Uuid cubemapId, AZStd::string* cubemapOutputPath, bool hideEntity, bool hasCubemapId) override; void HandleObjectModeSelection(const AZ::Vector2& point, int flags, bool& handled) override; void UpdateObjectModeCursor(AZ::u32& cursorId, AZStd::string& cursorStr) override; void CreateEditorRepresentation(AZ::Entity* entity) override; @@ -249,7 +246,6 @@ private: void DrawArrow(const AZ::Vector3& src, const AZ::Vector3& trg, float fHeadScale, bool b2SidedArrow) override; void DrawTextLabel(const AZ::Vector3& pos, float size, const char* text, const bool bCenter, int srcOffsetX, int scrOffsetY) override; void Draw2dTextLabel(float x, float y, float size, const char* text, bool bCenter) override; - void DrawTextOn2DBox(const AZ::Vector3& pos, const char* text, float textScale, const AZ::Vector4& TextColor, const AZ::Vector4& TextBackColor) override; void DrawTextureLabel(ITexture* texture, const AZ::Vector3& pos, float sizeX, float sizeY, int texIconFlags) override; void DrawTextureLabel(int textureId, const AZ::Vector3& pos, float sizeX, float sizeY, int texIconFlags) override; void SetLineWidth(float width) override; @@ -365,8 +361,6 @@ private: DisplayContext* m_dc; - AZStd::unique_ptr m_entityDebugPrinter; - AZStd::vector m_sliceAssetDeletionErrorRestoreInfos; // Tracks new entities that have not yet been saved. diff --git a/Code/Sandbox/Plugins/ComponentEntityEditorPlugin/componententityeditorplugin_files.cmake b/Code/Sandbox/Plugins/ComponentEntityEditorPlugin/componententityeditorplugin_files.cmake index 26998a5bda..6672bc8b47 100644 --- a/Code/Sandbox/Plugins/ComponentEntityEditorPlugin/componententityeditorplugin_files.cmake +++ b/Code/Sandbox/Plugins/ComponentEntityEditorPlugin/componententityeditorplugin_files.cmake @@ -17,8 +17,6 @@ set(FILES SandboxIntegration.cpp ComponentEntityEditorPlugin_precompiled.cpp ComponentEntityEditorPlugin_precompiled.h - ComponentEntityDebugPrinter.h - ComponentEntityDebugPrinter.cpp UI/ComponentEntityEditorOutlinerWindow.qrc UI/QComponentEntityEditorMainWindow.h UI/QComponentEntityEditorMainWindow.cpp diff --git a/Code/Sandbox/Plugins/EditorCommon/ManipScene.cpp b/Code/Sandbox/Plugins/EditorCommon/ManipScene.cpp deleted file mode 100644 index 5b76ca8804..0000000000 --- a/Code/Sandbox/Plugins/EditorCommon/ManipScene.cpp +++ /dev/null @@ -1,1739 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "EditorCommon_precompiled.h" -#include "ManipScene.h" - -#include "Serialization.h" -#include "QViewportEvents.h" - -#include -#include -#include -#include -#include - -#include "../EditorCommon/QViewport.h" - -#include - -// from Sandbox/Editor: -#include "Include/IDisplayViewport.h" -#include "Include/HitContext.h" -#include "Objects/DisplayContext.h" -#include "RenderHelpers/AxisHelper.h" -#include "Util/EditorUtils.h" -#include "Util/Math.h" -// ^^^ - -#include "DisplayViewportAdapter.h" -#include - -namespace Manip -{ - static unsigned int GetLayerBits(const SElements& elements) - { - unsigned int result = 0; - for (size_t i = 0; i < elements.size(); ++i) - { - result |= 1 << elements[i].layer; - } - return result; - } - - - static unsigned int GetLayerBits(const SElements& elements, const SSelectionSet& selection) - { - unsigned int result = 0; - for (size_t i = 0; i < elements.size(); ++i) - { - if (selection.Contains(elements[i].id)) - { - result |= 1 << elements[i].layer; - } - } - return result; - } - - - static QuatT GetGizmoOrientation(const QuatT& transform, [[maybe_unused]] const CCamera* camera, ETransformationSpace space) - { - if (space == SPACE_LOCAL) - { - return transform; - } - else - { - return QuatT(IDENTITY, transform.t); - } - } - // --------------------------------------------------------------------------- - - SERIALIZATION_ENUM_BEGIN(ETransformationMode, "Transformation Mode") - SERIALIZATION_ENUM(MODE_TRANSLATE, "translate", "Translate") - SERIALIZATION_ENUM(MODE_ROTATE, "rotate", "Rotate") - SERIALIZATION_ENUM(MODE_SCALE, "scale", "Scale") - SERIALIZATION_ENUM_END() - - // --------------------------------------------------------------------------- - - CScene::CScene() - : m_axisHelper(new CAxisHelper()) - , m_showGizmo(true) - , m_transformationMode(MODE_TRANSLATE) - , m_transformationSpace(SPACE_LOCAL) - , m_customDrawer(0) - , m_customTracer(0) - , m_spaceProvider(0) - , m_temporaryLocalDelta(IDENTITY) - , m_visibleLayerMask(0xffffffff) - { - m_axisHelper->SetMode(CAxisHelper::MOVE_MODE); - } - - - CScene::~CScene() - { - } - - static void DrawElement([[maybe_unused]] const SRenderContext& rc, const SElement& element, ElementId highlightedItem, bool isSelected, bool xRay, IElementDrawer* customDrawer, CScene* spaceProvider, const SLookSettings& lookSettings) - { - if (element.hidden) - { - return; - } - - IRenderer* renderer = GetIEditor()->GetRenderer(); - IRenderAuxGeom* aux = renderer->GetIRenderAuxGeom(); - - SAuxGeomRenderFlags defaultFlags(e_Mode3D | e_AlphaBlended | e_DrawInFrontOff | e_FillModeSolid | e_CullModeNone | e_DepthWriteOn | e_DepthTestOn); - SAuxGeomRenderFlags xRayFlags(e_Mode3D | e_AlphaBlended | e_DrawInFrontOn | e_FillModeSolid | e_CullModeNone | e_DepthWriteOff | e_DepthTestOff); - aux->SetRenderFlags(xRay ? xRayFlags : defaultFlags); - - QuatT transform = spaceProvider->ElementToWorldSpace(element); - Matrix34 transformM(transform); - - if (element.shape == SHAPE_BOX) - { - OBB obb; - obb.m33 = Matrix33(IDENTITY); - obb.c = element.placement.center; - obb.h = element.placement.size * 0.5f; - - bool isHighlighted2 = highlightedItem == element.id; - ColorB color; - if (isHighlighted2) - { - color = lookSettings.proxyHighlightColor; - } - else if (isSelected) - { - color = lookSettings.proxySelectionColor; - } - else if (element.colorGroup == ELEMENT_COLOR_CLOTH) - { - color = lookSettings.clothProxyColor; - } - else - { - color = lookSettings.proxyColor; - } - - ColorB innerColor = color; - - ColorB edgeColor(innerColor.r, innerColor.g, innerColor.b, 255); - - bool drawBB = false; - if (!customDrawer || !customDrawer->Draw(element)) - { - drawBB = true; - } - - if (isSelected || isHighlighted2) - { - drawBB = true; - } - - if (drawBB) - { - aux->DrawOBB(obb, transformM, false, edgeColor, eBBD_Faceted); - } - } - else if (element.shape == SHAPE_AXES) - { - OBB obb; - obb.m33 = Matrix33(IDENTITY); - obb.c = element.placement.center; - obb.h = Vec3(0.01f, 0.01f, 0.01f); - - bool isHighlighted2 = highlightedItem == element.id; - ColorB color; - if (isHighlighted2) - { - color = lookSettings.proxyHighlightColor; - } - else if (isSelected) - { - color = lookSettings.proxySelectionColor; - } - else - { - color = lookSettings.proxyColor; - } - - ColorB innerColor = color; - - ColorB edgeColor(innerColor.r, innerColor.g, innerColor.b, 255); - - bool drawBB = false; - if (!customDrawer || !customDrawer->Draw(element)) - { - drawBB = true; - } - if (isSelected || isHighlighted2) - { - drawBB = true; - } - - if (drawBB) - { - aux->DrawOBB(obb, transformM, false, edgeColor, eBBD_Faceted); - } - } - } - - void CScene::OnViewportRender(const SRenderContext& rc) - { - SignalRenderElements(m_elements, rc); - - for (int xRayPass = 0; xRayPass < 2; ++xRayPass) - { - size_t numElements = m_elements.size(); - for (size_t i = 0; i < numElements; ++i) - { - SElement& element = m_elements[i]; - bool isSelected = m_selection.Contains(element.id); - if (!isSelected && !IsLayerVisible(element.layer)) - { - continue; - } - - bool xRay = isSelected || element.id == m_highlightedItem || element.alwaysXRay; - - if (int(xRay) != xRayPass) - { - continue; - } - - DrawElement(rc, element, m_highlightedItem, m_selection.Contains(element.id), xRay, m_customDrawer, this, m_lookSettings); - } - } - - if (m_mouseDragHandler.get()) - { - m_mouseDragHandler->Render(rc); - } - - bool hasSelection = !m_selection.IsEmpty(); - - if (m_showGizmo && hasSelection) - { - int selectionCaps = GetSelectionCaps(); - Matrix34 m = Matrix34(GetGizmoOrientation(GetSelectionTransform(SPACE_WORLD), rc.viewport->Camera(), m_transformationSpace)); - DisplayContext dc; - CDisplayViewportAdapter view(rc.viewport); - dc.SetView(&view); - - SGizmoParameters gizmoParameters; - gizmoParameters.axisGizmoScale = 0.2f; - - if (m_axisHelper.get()) - { - switch (m_transformationMode) - { - case MODE_TRANSLATE: - m_axisHelper->SetMode(CAxisHelper::MOVE_MODE); - gizmoParameters.enabled = (selectionCaps & CAP_MOVE) != 0; - break; - case MODE_ROTATE: - m_axisHelper->SetMode(CAxisHelper::ROTATE_MODE); - gizmoParameters.enabled = (selectionCaps & CAP_ROTATE) != 0; - break; - case MODE_SCALE: - m_axisHelper->SetMode(CAxisHelper::SCALE_MODE); - gizmoParameters.enabled = (selectionCaps & CAP_SCALE) != 0; - break; - } - m_axisHelper->DrawAxis(m, gizmoParameters, dc); - } - } - } - - void CScene::SetTransformationMode(ETransformationMode mode) - { - m_transformationMode = mode; - } - - void CScene::SetTransformationSpace(ETransformationSpace space) - { - m_transformationSpace = space; - } - - ETransformationMode CScene::TransformationMode() const - { - return m_transformationMode; - } - - void CScene::SetSelection(const SSelectionSet& selection) - { - if (m_selection != selection) - { - m_selection = selection; - SignalSelectionChanged(); - } - } - - void CScene::AddToSelection(ElementId elementId) - { - m_selection.Add(elementId); - SignalSelectionChanged(); - } - - void CScene::ApplyToAll(EElementAction action) - { - size_t count = m_elements.size(); - for (size_t i = 0; i < count; ++i) - { - SElement& m = m_elements[i]; - if (m.hidden) - { - m.action = action; - //m.hidden = false; - } - } - SignalElementsChanged(GetLayerBits(m_elements)); - } - - void CScene::ApplyToSelection(EElementAction action) - { - size_t count = m_elements.size(); - for (size_t i = 0; i < count; ++i) - { - SElement& m = m_elements[i]; - if (m_selection.Contains(m.id)) - { - m.action = action; - //m.hidden = true; - } - } - SignalElementsChanged(GetLayerBits(m_elements, m_selection)); - } - - void CScene::OnViewportKey(const SKeyEvent& ev) - { - QKeySequence key(ev.key); - if (ev.type == SKeyEvent::TYPE_PRESS) - { - if (key == QKeySequence(Qt::Key_U) || key == QKeySequence(Qt::Key_Z | Qt::CTRL)) - { - SignalUndo(); - } - else if (key == QKeySequence(Qt::Key_Y | Qt::CTRL) || key == QKeySequence(Qt::Key_Z | Qt::CTRL | Qt::SHIFT)) - { - SignalRedo(); - } - else if (key == QKeySequence(Qt::ALT | Qt::Key_H) || key == QKeySequence(Qt::SHIFT | Qt::Key_H)) - { - ApplyToAll(ACTION_UNHIDE); - } - else if (key == QKeySequence(Qt::Key_H)) - { - ApplyToSelection(ACTION_HIDE); - } - else if (key == QKeySequence(Qt::Key_Delete)) - { - ApplyToSelection(ACTION_DELETE); - } - else if (key == QKeySequence(Qt::Key_1)) - { - m_transformationMode = MODE_TRANSLATE; - SignalManipulationModeChanged(); - SignalPropertiesChanged(); - } - else if (key == QKeySequence(Qt::Key_2)) - { - m_transformationMode = MODE_ROTATE; - SignalManipulationModeChanged(); - SignalPropertiesChanged(); - } - else if (key == QKeySequence(Qt::Key_3)) - { - m_transformationMode = MODE_SCALE; - SignalManipulationModeChanged(); - SignalPropertiesChanged(); - } - } - } - - bool CScene::ProcessesViewportKey(const QKeySequence& key) - { - static QSet overriddenKeys = { - QKeySequence(Qt::Key_U), - QKeySequence(Qt::Key_Z | Qt::CTRL), - QKeySequence(Qt::Key_Y | Qt::CTRL), - QKeySequence(Qt::Key_Z | Qt::CTRL | Qt::SHIFT), - QKeySequence(Qt::ALT | Qt::Key_H), - QKeySequence(Qt::SHIFT | Qt::Key_H), - QKeySequence(Qt::Key_H), - QKeySequence(Qt::Key_Delete), - QKeySequence(Qt::Key_1), - QKeySequence(Qt::Key_2), - QKeySequence(Qt::Key_3) - }; - - // Check if the parameter key is one that we care about in OnViewportKey - // If we don't, matching shortcuts attached to the widget will get processed - // instead, and CScene::OnViewportKey will never get called - return overriddenKeys.contains(key); - } - - bool RayHitsElement(Vec3* intersectionPoint, const Ray& ray, const SElement& element, IElementTracer* customTracer, CScene* spaceProvider) - { - QuatT parentSpace(IDENTITY); - if (spaceProvider) - { - parentSpace = spaceProvider->GetParentSpace(element); - } - - OBB obb; - if (element.shape == SHAPE_BOX) - { - obb.m33 = Matrix33((parentSpace * element.placement.transform).q); - obb.c = element.placement.center; - obb.h = element.placement.size * 0.5f; - } - else - { - obb.m33 = IDENTITY; - obb.c = Vec3(ZERO); - obb.h = element.placement.size * 0.5f; - } - - if (Intersect::Ray_OBB(ray, (parentSpace * element.placement.transform).t, obb, *intersectionPoint) != 0) - { - if (customTracer) - { - return customTracer->HitRay(intersectionPoint, ray, element); - } - - return true; - } - return false; - } - - static SElement* HitElementWithRay(Vec3* hitPoint, SElements& elements, const Ray& ray, IElementTracer* customTracer, CScene* spaceProvider) - { - const float BIG_VALUE = 1e20f; - float closestDistanceSquare = BIG_VALUE; - int hitPickPriority = INT_MIN; - SElement* closestElement = 0; - - size_t numElements = elements.size(); - for (size_t i = 0; i < numElements; ++i) - { - SElement& element = elements[i]; - if (element.hidden) - { - continue; - } - if (!spaceProvider->IsLayerVisible(element.layer) && - !spaceProvider->Selection().Contains(element.id)) - { - continue; - } - - Vec3 intersectionPoint; - if (RayHitsElement(&intersectionPoint, ray, element, customTracer, spaceProvider)) - { - float distanceSquare = (intersectionPoint - ray.origin).GetLengthSquared(); - if (distanceSquare < closestDistanceSquare || int(element.mousePickPriority) > hitPickPriority) - { - closestDistanceSquare = distanceSquare; - closestElement = &element; - hitPickPriority = element.mousePickPriority; - *hitPoint = intersectionPoint; - } - } - } - return closestElement; - } - - static ElementId HitSelectionWithRay(Vec3* hitPoint, SElements& elements, const Ray& ray, IElementTracer* customTracer, CScene* spaceProvider) - { - SElement* element = HitElementWithRay(hitPoint, elements, ray, customTracer, spaceProvider); - if (element) - { - return element->id; - } - - return 0; - } - - struct STransformConstraint - { - enum EType - { - NONE, - AXIS, - PLANE - }; - - EType type; - Plane plane; - Vec3 axis; - Vec3 localAxis; - - Vec3 GetAxis(ETransformationSpace space) - { - switch (space) - { - case SPACE_LOCAL: - return localAxis; - default: - return axis; - } - } - - STransformConstraint() - : type(NONE) - { - } - }; - - struct CScene::SMoveHandler - : IMouseDragHandler - { - CScene* m_scene; - Vec3 m_lastPoint; - Vec3 m_startPoint; - Vec2i m_startMousePosition; - STransformConstraint m_constraint; - SElements m_elements; - SElements m_transformedElements; - int m_layerBits; - - SMoveHandler(CScene* scene, const STransformConstraint& constraint) - : m_scene(scene) - , m_constraint(constraint) - , m_layerBits(0) - , m_lastPoint(ZERO) - , m_startPoint(ZERO) - { - } - - bool Begin(const SMouseEvent& ev, Vec3 hitPoint) override - { - m_startMousePosition = Vec2i(ev.x, ev.y); - m_startPoint = hitPoint; - - m_scene->GetSelectedElements(&m_elements); - m_layerBits = GetLayerBits(m_elements); - - if (!ReprojectStartPoint(ev.viewport)) - { - return false; - } - return true; - } - - - bool ReprojectStartPoint(QViewport* viewport) - { - Ray ray; - MAKE_SURE(viewport->ScreenToWorldRay(&ray, m_startMousePosition.x, m_startMousePosition.y), return false); - - if (m_constraint.type == STransformConstraint::PLANE) - { - Intersect::Ray_Plane(ray, m_constraint.plane, m_startPoint, false); - } - else if (m_constraint.type == STransformConstraint::AXIS) - { - Vec3 point; - Vec3 axis = m_constraint.GetAxis(m_scene->TransformationSpace()); - RayToLineDistance(ray.origin, ray.origin + ray.direction, - m_startPoint - axis * 10000.0f, m_startPoint + axis * 10000.0f, point); - m_startPoint = m_startPoint + axis * axis.dot(point - m_startPoint); - } - return true; - } - - void Update(const SMouseEvent& ev) override - { - ReprojectStartPoint(ev.viewport); - - Ray ray; - MAKE_SURE(ev.viewport->ScreenToWorldRay(&ray, ev.x, ev.y), return ); - - if (m_constraint.type == STransformConstraint::PLANE) - { - Vec3 point(0.0f, 0.0f, 0.0f); - Intersect::Ray_Plane(ray, m_constraint.plane, point, false); - - Vec3 delta = point - m_startPoint; - Move(delta); - } - else if (m_constraint.type == STransformConstraint::AXIS) - { - Vec3 point = m_startPoint; - Vec3 axis = m_constraint.GetAxis(m_scene->TransformationSpace()); - RayToLineDistance(ray.origin, ray.origin + ray.direction, - m_startPoint - axis * 10000.0f, m_startPoint + axis * 10000.0f, point); - Vec3 newPoint = m_startPoint + axis * axis.dot(point - m_startPoint); - Vec3 delta = newPoint - m_startPoint; - Move(delta); - } - } - - void Move(Vec3 delta) - { - m_transformedElements = m_elements; - for (size_t i = 0; i < m_transformedElements.size(); ++i) - { - SElement& e = m_transformedElements[i]; - QuatT parentSpace = m_scene->GetParentSpace(e) * QuatT(e.placement.transform.q, ZERO); - QuatT localDelta = parentSpace.GetInverted() * (QuatT(IDENTITY, delta) * parentSpace); - m_scene->m_temporaryLocalDelta = localDelta; - e.placement.transform = e.placement.transform * localDelta; - e.placement.transform.q.Normalize(); - } - m_scene->UpdateElements(m_transformedElements); - m_scene->SignalElementContinousChange(m_layerBits); - } - - void End([[maybe_unused]] const SMouseEvent& ev) override - { - m_scene->m_temporaryLocalDelta = QuatT(IDENTITY); - m_scene->SignalElementsChanged(m_layerBits); - } - }; - - struct CScene::SRotationHandler - : public IMouseDragHandler - { - CScene* m_scene; - STransformConstraint m_constraint; - SElements m_elements; - SElements m_transformedElements; - int m_layerBits; - Vec3 m_origin; - Vec2i m_startPoint; - - SRotationHandler(CScene* scene, const STransformConstraint& constraint) - : m_scene(scene) - , m_constraint(constraint) - , m_layerBits(0) - , m_origin(ZERO) - , m_startPoint(ZERO) - { - if (m_constraint.type == STransformConstraint::PLANE) - { - // TODO: Apart from having rotation around axis of gizmo (as Sandbox does) it - // is possible here to rotate around viewer axis. This part can be considerably - // improved by making sure that picked point on the proxy keeps touching the - // mouse pointer. - - m_constraint.localAxis = m_constraint.plane.n; - m_constraint.axis = Vec3(0.0f, 0.0f, 1.0f); - m_constraint.type = STransformConstraint::AXIS; - } - - m_scene->GetSelectedElements(&m_elements); - m_layerBits = GetLayerBits(m_elements); - - m_origin = m_scene->GetSelectionTransform(SPACE_WORLD).t; - } - - bool Begin(const SMouseEvent& ev, [[maybe_unused]] Vec3 hitPoint) override - { - m_startPoint = Vec2i(ev.x, ev.y); - return true; - } - - void Update(const SMouseEvent& ev) override - { - if (ev.y != m_startPoint.y) - { - float angle = ((ev.y - m_startPoint.y) * 0.01f) * 3.1415926f; - QuatT rotation; - float cos, sin; - sin = sinf(angle); - cos = cosf(angle); - Vec3 axis = m_constraint.GetAxis(m_scene->TransformationSpace()); - rotation.SetRotationAA(cos, sin, axis); - - m_transformedElements = m_elements; - for (size_t i = 0; i < m_elements.size(); ++i) - { - SElement& e = m_transformedElements[i]; - QuatT t = m_scene->ElementToWorldSpace(e); - t.t -= m_origin; - t = rotation * t; - t.t += m_origin; - m_scene->m_temporaryLocalDelta = m_scene->ElementToWorldSpace(m_elements[i]).GetInverted() * t; - m_scene->WorldSpaceToElement(&e, t); - } - m_scene->UpdateElements(m_transformedElements); - m_scene->SignalElementContinousChange(m_layerBits); - } - } - - void End([[maybe_unused]] const SMouseEvent& ev) override - { - m_scene->m_temporaryLocalDelta = QuatT(IDENTITY); - m_scene->SignalElementsChanged(m_layerBits); - } - }; - - static Vec3 ScaleAround(Vec3 p, Vec3 origin, float scale) - { - return (p - origin) * scale + origin; - } - - struct CScene::SScalingHandler - : public IMouseDragHandler - { - CScene* m_scene; - STransformConstraint m_constraint; - SElements m_elements; - SElements m_transformedElements; - Vec3 m_origin; - Vec3 m_size; - Vec3 m_hitPoint; - Vec2i m_startPoint; - unsigned int m_layerBits; - - SScalingHandler(CScene* scene, const STransformConstraint& constraint) - : m_scene(scene) - , m_constraint(constraint) - , m_layerBits(0) - , m_origin(ZERO) - , m_size(ZERO) - , m_hitPoint(ZERO) - , m_startPoint(ZERO) - { - } - - bool Begin(const SMouseEvent& ev, Vec3 hitPoint) override - { - m_hitPoint = hitPoint; - m_startPoint = Vec2i(ev.x, ev.y); - m_scene->GetSelectedElements(&m_elements); - m_layerBits = GetLayerBits(m_elements); - m_origin = m_scene->GetSelectionTransform(SPACE_WORLD).t; - m_size = m_scene->GetSelectionSize(); - return true; - } - - void Update(const SMouseEvent& ev) override - { - float screenScaleFactor = 0.0f; - if (const CCamera* camera = ev.viewport->Camera()) - { - screenScaleFactor = camera->GetPosition().GetDistance(m_hitPoint); - if (screenScaleFactor < camera->GetNearPlane()) - { - screenScaleFactor = camera->GetNearPlane(); - } - } - - m_transformedElements = m_elements; - - if (m_transformedElements.size() == 1) - { - Vec3& size = m_transformedElements[0].placement.size; - float difference = -(ev.y - m_startPoint.y) * 0.01f * screenScaleFactor; - Vec3 axis = m_constraint.GetAxis(m_scene->TransformationSpace()); - size = (size + size.CompMul(axis * difference)).abs(); - } - else - { - float difference = -(ev.y - m_startPoint.y) * 0.01f * screenScaleFactor; - float sizeDifference = max(0.01f, fabsf(1.0f + difference)); - - for (size_t i = 0; i < m_transformedElements.size(); ++i) - { - SElement& g = m_transformedElements[i]; - g.placement.transform.t = ScaleAround(g.placement.transform.t, m_origin, sizeDifference); - g.placement.size = g.placement.size * sizeDifference; - } - } - - m_scene->UpdateElements(m_transformedElements); - m_scene->SignalElementContinousChange(m_layerBits); - } - - void End([[maybe_unused]] const SMouseEvent& ev) override - { - m_scene->SignalElementsChanged(m_layerBits); - } - }; - - template - struct SRange - { - T low; - T high; - - SRange(T low, T high) - : low(low) - , high(high) - { - } - - SRange() - : low(T(0)) - , high(T(0)) - { - } - - void Add(T value) - { - if (value < low) - { - low = value; - } - if (value > high) - { - high = value; - } - } - - bool Intersects(const SRange& r) const - { - if (high < r.low) - { - return false; - } - if (low > r.high) - { - return false; - } - return true; - } - }; - - static bool RectsIntersect(Vec2i amin, Vec2i amax, Vec2i bmin, Vec2i bmax) - { - if (!SRange(amin.x, amax.x).Intersects(SRange(bmin.x, bmax.x))) - { - return false; - } - - if (!SRange(amin.y, amax.y).Intersects(SRange(bmin.y, bmax.y))) - { - return false; - } - - return true; - } - - static bool OBBOverlapsSelectionFrustum(const OBB& box, Vec2i rectMin, Vec2i rectMax, [[maybe_unused]] const Plane (&frustum)[4], IDisplayViewport* viewport) - { - Vec3 s = box.h; - Vec3 points[8] = { - box.m33 * Vec3(-s.x, -s.y, -s.z) + box.c, - box.m33 * Vec3(s.x, -s.y, -s.z) + box.c, - box.m33 * Vec3(s.x, s.y, -s.z) + box.c, - box.m33 * Vec3(-s.x, s.y, -s.z) + box.c, - box.m33 * Vec3(-s.x, -s.y, s.z) + box.c, - box.m33 * Vec3(s.x, -s.y, s.z) + box.c, - box.m33 * Vec3(s.x, s.y, s.z) + box.c, - box.m33 * Vec3(-s.x, s.y, s.z) + box.c, - }; - - Vec2i projectedPoints[8]; - Vec2i boundMin(INT_MAX, INT_MAX); - Vec2i boundMax(INT_MIN, INT_MIN); - for (int i = 0; i < 8; ++i) - { - Vec2i& p = projectedPoints[i]; - QPoint pt = viewport->WorldToView(points[i]); - p.x = pt.x(); - p.y = pt.y(); - if (p.x < boundMin.x) - { - boundMin.x = p.x; - } - if (p.y < boundMin.y) - { - boundMin.y = p.y; - } - if (p.x > boundMax.x) - { - boundMax.x = p.x; - } - if (p.y > boundMax.y) - { - boundMax.y = p.y; - } - } - - if (boundMin.x > rectMin.x && - boundMax.x < rectMax.x && - boundMin.y > rectMin.y && - boundMax.y < rectMax.y) - { - return true; - } - - if (!RectsIntersect(boundMin, boundMax, rectMin, rectMax)) - { - return false; - } - - struct Edge - { - Vec2 a; - Vec2 b; - }; - - Edge boxEdges[12] = { - { projectedPoints[0], projectedPoints[1] }, - { projectedPoints[1], projectedPoints[2] }, - { projectedPoints[2], projectedPoints[3] }, - { projectedPoints[3], projectedPoints[0] }, - { projectedPoints[4], projectedPoints[5] }, - { projectedPoints[5], projectedPoints[6] }, - { projectedPoints[6], projectedPoints[7] }, - { projectedPoints[7], projectedPoints[4] }, - { projectedPoints[0], projectedPoints[4] }, - { projectedPoints[1], projectedPoints[5] }, - { projectedPoints[2], projectedPoints[6] }, - { projectedPoints[3], projectedPoints[7] } - }; - - Vec2 rectPoints[4] = { - Vec2(float(rectMin.x), float(rectMin.y)), - Vec2(float(rectMax.x), float(rectMin.y)), - Vec2(float(rectMin.x), float(rectMax.y)), - Vec2(float(rectMax.x), float(rectMax.y)) - }; - - for (size_t i = 0; i < 12; ++i) - { - const Edge& e = boxEdges[i]; - Vec2 dir = e.b - e.a; - if (dir.GetLength2() < 1.0f) - { - continue; - } - dir.Normalize(); - Vec2 ort(dir.y, -dir.x); - - SRange range1; - range1.low = ort.Dot(projectedPoints[0]); - range1.high = range1.low; - for (size_t j = 1; j < 8; ++j) - { - float pos = ort.Dot(projectedPoints[j]); - range1.Add(pos); - } - - SRange range2; - range2.low = ort.Dot(rectPoints[0]); - range2.high = range2.low; - range2.Add(ort.Dot(rectPoints[1])); - range2.Add(ort.Dot(rectPoints[2])); - range2.Add(ort.Dot(rectPoints[3])); - - if (!range1.Intersects(range2)) - { - return false; - } - } - - return true; - } - - static bool ElementInFrustum(const SElement& element, Vec2i rectMin, Vec2i rectMax, const Plane (&frustum)[4], IDisplayViewport* viewport, CScene* scene) - { - OBB obb; - QuatT parentSpace = scene->GetParentSpace(element); - obb.m33 = Matrix33((parentSpace * element.placement.transform).q); - obb.c = Vec3((parentSpace * element.placement.transform).t); - obb.h = element.placement.size * 0.5f; - - return OBBOverlapsSelectionFrustum(obb, rectMin, rectMax, frustum, viewport); - } - - static void FindElementsInRect(vector* out, Vec2i point1, Vec2i point2, QViewport* viewport, - const vector& elements, [[maybe_unused]] ISpaceProvider* spaceProvider, CScene* scene) - { - int minX = min(point1.x, point2.x); - int minY = min(point1.y, point2.y); - int maxX = max(point1.x, point2.x); - int maxY = max(point1.y, point2.y); - Ray ray1; - if (!viewport->ScreenToWorldRay(&ray1, minX, minY)) - { - return; - } - Ray ray2; - if (!viewport->ScreenToWorldRay(&ray2, maxX, maxY)) - { - return; - } - - Matrix34 m = viewport->Camera()->GetMatrix(); - Vec3 xdir = m.GetColumn0().GetNormalized(); - Vec3 zdir = m.GetColumn2().GetNormalized(); - Vec3 pos = m.GetTranslation(); - - Vec3 normals[4] = { - ray1.direction.Cross(xdir).GetNormalized(), - (zdir).Cross(ray2.direction).GetNormalized(), - ray2.direction.Cross(-xdir).GetNormalized(), - (-zdir).Cross(ray1.direction).GetNormalized(), - }; - Plane frustum[4]; - for (int i = 0; i < 4; ++i) - { - frustum[i].SetPlane(-normals[i], pos); - } - - CDisplayViewportAdapter view(viewport); - - for (int j = 0; j < elements.size(); ++j) - { - const SElement& m2 = elements[j]; - if (m2.hidden) - { - continue; - } - if (!scene->IsLayerVisible(m2.layer) && !scene->Selection().Contains(m2.id)) - { - continue; - } - if (ElementInFrustum(m2, Vec2i(minX, minY), Vec2i(maxX, maxY), frustum, &view, scene)) - { - out->push_back(&m2); - } - } - } - - static void GetSelectionInRect(SSelectionSet* selection, Vec2i p1, Vec2i p2, QViewport* viewport, const vector& elements, ISpaceProvider* spaceProvider, CScene* scene) - { - vector elementsIn; - FindElementsInRect(&elementsIn, p1, p2, viewport, elements, spaceProvider, scene); - - for (size_t i = 0; i < elementsIn.size(); ++i) - { - selection->Add(elementsIn[i]->id); - } - } - - static void DrawLine2D(const SRenderContext& rc, Vec2i p1, Vec2i p2, ColorB color) - { - IRenderer* renderer = GetIEditor()->GetRenderer(); - IRenderAuxGeom* aux = renderer->GetIRenderAuxGeom(); - int w = rc.viewport->Width(); - int h = rc.viewport->Height(); - if (w == 0 || h == 0) - { - return; - } - - int renderFlags = aux->GetRenderFlags().m_renderFlags; - aux->SetRenderFlags((renderFlags | e_Mode2D) & ~e_Mode3D); - - Vec3 start(float(p1.x) / w, float(p1.y) / h, 0.0f); - Vec3 end(float(p2.x) / w, float(p2.y) / h, 0.0f); - aux->DrawLine(start, color, end, color); - - aux->SetRenderFlags(renderFlags); - } - - struct CScene::SBlockSelectHandler - : public IMouseDragHandler - { - CScene* m_scene; - Vec2i m_startPoint; - Vec2i m_endPoint; - SSelectionSet m_lastSelection; - - SBlockSelectHandler(CScene* scene) - : m_scene(scene) - { - } - - bool Begin(const SMouseEvent& ev, [[maybe_unused]] Vec3 hitPoint) override - { - m_startPoint = Vec2i(ev.x, ev.y); - m_endPoint = m_startPoint; - m_scene->SignalPushUndo("Selection change", 0); - m_scene->SetSelection(SSelectionSet()); - return true; - } - - void Update(const SMouseEvent& ev) override - { - m_endPoint = Vec2i(ev.x, ev.y); - - SSelectionSet selection; - GetSelectionInRect(&selection, m_startPoint, m_endPoint, ev.viewport, m_scene->Elements(), m_scene->SpaceProvider(), m_scene); - - if (selection != m_lastSelection || (selection.IsEmpty() && !m_scene->Selection().IsEmpty())) - { - m_scene->SetSelection(selection); - } - } - - void Render(const SRenderContext& rc) override - { - ColorB color(255, 255, 255, 255); - Vec2i points[4] = { m_startPoint, Vec2i(m_startPoint.x, m_endPoint.y), m_endPoint, Vec2i(m_endPoint.x, m_startPoint.y) }; - DrawLine2D(rc, points[0], points[1], color); - DrawLine2D(rc, points[1], points[2], color); - DrawLine2D(rc, points[2], points[3], color); - DrawLine2D(rc, points[3], points[0], color); - } - - void End([[maybe_unused]] const SMouseEvent& ev) override - { - } - }; - - - void CScene::OnMouseMove(const SMouseEvent& ev) - { - SGizmoParameters gizmoParameters; - gizmoParameters.axisGizmoScale = 0.2f; - CDisplayViewportAdapter displayView(ev.viewport); - - QuatT selectionTransform = GetSelectionTransform(SPACE_WORLD); - int selectionCaps = GetSelectionCaps(); - QuatT axesTransform = GetGizmoOrientation(selectionTransform, ev.viewport->Camera(), m_transformationSpace); - - if (m_mouseDragHandler.get()) - { - m_mouseDragHandler->Update(ev); - } - else if (m_showGizmo) - { - bool gizmoEnabled = true; - - switch (m_transformationMode) - { - case MODE_TRANSLATE: - gizmoEnabled = (selectionCaps & CAP_MOVE) != 0; - break; - case MODE_ROTATE: - gizmoEnabled = (selectionCaps & CAP_ROTATE) != 0; - break; - case MODE_SCALE: - gizmoEnabled = (selectionCaps & CAP_SCALE) != 0; - break; - } - - if (gizmoEnabled) - { - HitContext hc; - hc.point2d = QPoint(ev.x, ev.y); - hc.view = &displayView; - m_axisHelper->HitTest(Matrix34(axesTransform), gizmoParameters, hc); - m_axisHelper->SetHighlightAxis(hc.axis); - } - else - { - m_axisHelper->SetHighlightAxis(0); - } - - Ray ray; - if (ev.viewport->ScreenToWorldRay(&ray, ev.x, ev.y)) - { - Vec3 hitPoint; - m_highlightedItem = aznumeric_cast(HitSelectionWithRay(&hitPoint, m_elements, ray, m_customTracer, this)); - } - } - } - - void CScene::OnViewportMouse(const SMouseEvent& ev) - { - if (!ev.viewport) - { - return; - } - - SGizmoParameters gizmoParameters; - gizmoParameters.axisGizmoScale = 0.2f; - CDisplayViewportAdapter displayView(ev.viewport); - - QuatT selectionTransform = GetSelectionTransform(SPACE_WORLD); - int selectionCaps = GetSelectionCaps(); - QuatT axesTransform = GetGizmoOrientation(selectionTransform, ev.viewport->Camera(), m_transformationSpace); - - if (ev.type == SMouseEvent::TYPE_PRESS) - { - int button = ev.button; - if (button == SMouseEvent::BUTTON_LEFT) - { - Ray ray; - if (ev.viewport->ScreenToWorldRay(&ray, ev.x, ev.y)) - { - STransformConstraint constraint; - - Vec3 hitPoint = selectionTransform.t; - if (m_showGizmo) - { - HitContext hc; - hc.point2d = QPoint(ev.x, ev.y); - hc.view = &displayView; - if (!Selection().IsEmpty() && m_axisHelper->HitTest(Matrix34(axesTransform), gizmoParameters, hc)) - { - Quat localRot(selectionTransform.q); - Quat planeRot(GetGizmoOrientation(QuatT(selectionTransform.q, ZERO), ev.viewport->Camera(), m_transformationSpace).q); - switch (hc.axis) - { - case AXIS_X: - constraint.type = STransformConstraint::AXIS; - constraint.axis = Vec3(1.0f, 0.0f, 0.0f); - constraint.localAxis = localRot * constraint.axis; - break; - case AXIS_Y: - constraint.type = STransformConstraint::AXIS; - constraint.axis = Vec3(0.0f, 1.0f, 0.0f); - constraint.localAxis = localRot * constraint.axis; - break; - case AXIS_Z: - constraint.type = STransformConstraint::AXIS; - constraint.axis = Vec3(0.0f, 0.0f, 1.0f); - constraint.localAxis = localRot * constraint.axis; - break; - case AXIS_XY: - constraint.type = STransformConstraint::PLANE; - constraint.plane.SetPlane(planeRot * Vec3(0.0f, 0.0f, 1.0f), hitPoint); - constraint.axis = Vec3(1.0f, 1.0f, 0.0f); - break; - case AXIS_XZ: - constraint.type = STransformConstraint::PLANE; - constraint.plane.SetPlane(planeRot * Vec3(0.0f, 1.0f, 0.0f), hitPoint); - constraint.axis = Vec3(1.0f, 0.0f, 1.0f); - break; - case AXIS_YZ: - constraint.type = STransformConstraint::PLANE; - constraint.plane.SetPlane(planeRot * Vec3(1.0f, 0.0f, 0.0f), hitPoint); - constraint.axis = Vec3(0.0f, 1.0f, 1.0f); - break; - case AXIS_XYZ: - constraint.type = STransformConstraint::AXIS; - constraint.localAxis = Vec3(1.0f, 1.0f, 1.0f); - constraint.axis = Vec3(1.0f, 1.0f, 1.0f); - break; - } - } - } - - if (constraint.type == STransformConstraint::NONE) - { - ElementId selected_id = HitSelectionWithRay(&hitPoint, m_elements, ray, m_customTracer, this); - if (selected_id != 0) - { - if (!m_selection.Contains(aznumeric_cast(selected_id)) || m_selection.Size() > 1) - { - if (ev.control) - { - AddToSelection(selected_id); - } - else - { - SetSelection(SSelectionSet(selected_id)); - } - } - - if (m_transformationMode == MODE_SCALE) - { - constraint.type = STransformConstraint::AXIS; - constraint.axis = Vec3(1.0f, 1.0f, 1.0f); - constraint.localAxis = Vec3(1.0f, 1.0f, 1.0f); - } - else - { - Matrix34 m = ev.viewport->Camera()->GetMatrix(); - Vec3 xdir = m.GetColumn0().GetNormalized(); - Vec3 ydir = m.GetColumn1().GetNormalized(); - Vec3 zdir = m.GetColumn2().GetNormalized(); - Vec3 pos = m.GetTranslation(); - - Vec3 fromScreenToSelection = pos - hitPoint; - float distance = ydir.Dot(fromScreenToSelection); - Vec3 planeCenter = pos + -ydir * distance; - - constraint.type = STransformConstraint::PLANE; - constraint.plane.SetPlane(-ydir, planeCenter); - constraint.axis = Vec3(1.0f, 0.0f, 1.0f); - } - } - else - { - m_mouseDragHandler.reset(new SBlockSelectHandler(this)); - } - } - - if (constraint.type != STransformConstraint::NONE) - { - switch (m_transformationMode) - { - case MODE_TRANSLATE: - if (selectionCaps & CAP_MOVE) - { - m_mouseDragHandler.reset(new SMoveHandler(this, constraint)); - } - break; - case MODE_ROTATE: - if (selectionCaps & CAP_ROTATE) - { - m_mouseDragHandler.reset(new SRotationHandler(this, constraint)); - } - break; - case MODE_SCALE: - if (selectionCaps & CAP_SCALE) - { - m_mouseDragHandler.reset(new SScalingHandler(this, constraint)); - } - break; - default: - break; - } - } - - if (m_mouseDragHandler.get()) - { - if (!m_mouseDragHandler->Begin(ev, hitPoint)) - { - m_mouseDragHandler.reset(); - } - } - } - } - } - else if (ev.type == SMouseEvent::TYPE_RELEASE) - { - if (m_mouseDragHandler.get()) - { - m_mouseDragHandler->End(ev); - m_mouseDragHandler.reset(); - ev.viewport->ReleaseMouse(); - } - } - else if (ev.type == SMouseEvent::TYPE_MOVE) - { - OnMouseMove(ev); - } - } - - struct CScene::STransformBox - { - CScene* m_scene; - - STransformBox(CScene* scene) - : m_scene(scene) - { - } - - void Serialize(IArchive& ar) - { - QuatT transform = m_scene->GetSelectionTransform(SPACE_WORLD); - int caps = m_scene->GetSelectionCaps(); - - Vec3 position = transform.t; - if ((caps & CAP_MOVE)) - { - ar(position, "position", "GetSelectionSize(); - Vec3 sizeOld = size; - if ((caps & CAP_SCALE)) - { - ar(size, "size", "SetSelectionTransform(SPACE_WORLD, transform); - } - - if (sizeChanged) - { - m_scene->SetSelectionSize(size); - } - } - } - }; - - struct SSpaceSelector - { - ETransformationSpace& space; - - SSpaceSelector(ETransformationSpace& space) - : space(space) - { - } - - void Serialize(Serialization::IArchive& ar) - { - using Serialization::RadioButton; - ar(RadioButton((int&)space, SPACE_WORLD), "transformWorld", "^Global"); - ar(RadioButton((int&)space, SPACE_LOCAL), "transformLocal", "^Local"); - } - }; - - - void CScene::Serialize(IArchive& ar) - { - ar(m_transformationMode, "transformationMode", 0); - if (ar.IsEdit()) - { - ar(SSpaceSelector(m_transformationSpace), "transformationSpace", "clear(); - size_t numElements = m_elements.size(); - for (size_t i = 0; i < numElements; ++i) - { - const SElement& element = m_elements[i]; - if (m_selection.Contains(element.id)) - { - elements->push_back(element); - } - } - } - - void CScene::UpdateElements(const SElements& elements) - { - // TODO: remove quadratic complexity here - size_t numElements = m_elements.size(); - for (size_t i = 0; i < numElements; ++i) - { - for (size_t j = 0; j < elements.size(); ++j) - { - if (m_elements[i].id == elements[j].id) - { - m_elements[i].placement = elements[j].placement; - m_elements[i].changed = true; - } - } - } - } - - void CScene::Clear() - { - m_elements.clear(); - m_lastIdByLayer.clear(); - } - - void CScene::ClearLayer(int layer) - { - auto newEnd = std::remove_if(m_elements.begin(), m_elements.end(), [=](const SElement& e){ return e.layer == layer; }); - m_elements.erase(newEnd, m_elements.end()); - if (layer < m_lastIdByLayer.size()) - { - m_lastIdByLayer[layer] = layer << 24; - } - } - - - void CScene::AddElement(const SElement& element) - { - ElementId& lastId = m_lastIdByLayer[element.layer]; - AddElement(element, lastId); - ++lastId; - } - - void CScene::AddElement(const SElement& element, ElementId id) - { - m_elements.push_back(element); - if (element.layer >= m_lastIdByLayer.size()) - { - while (m_lastIdByLayer.size() <= element.layer) - { - m_lastIdByLayer.push_back(m_lastIdByLayer.size() << 24); - } - } - m_elements.back().id = aznumeric_cast(id); - - ElementId& lastId = m_lastIdByLayer[element.layer]; - lastId = max(lastId, id) + 1; - } - - QuatT CScene::GetSelectionTransform(ETransformationSpace space) const - { - if (space == SPACE_WORLD) - { - QuatT r(IDENTITY); - - vector selectedElements; - GetSelectedElements(&selectedElements); - - if (selectedElements.size() == 1) - { - r = ElementToWorldSpace(selectedElements[0]); - } - else if (selectedElements.size() > 1) - { - r = GetParentSpace(selectedElements[0]) * selectedElements[0].placement.transform; - for (size_t i = 1; i < selectedElements.size(); ++i) - { - SElement& e = selectedElements[i]; - QuatT parentSpace = GetParentSpace(e); - r.t = r.t + ElementToWorldSpace(e).t; - } - r.SetTranslation(r.t / float(selectedElements.size())); - } - - if (!_finite(r.t.x) || - !_finite(r.t.y) || - !_finite(r.t.z)) - { - Q_ASSERT(false); - r.SetIdentity(); - } - return r; - } - else if (space == SPACE_LOCAL) - { - return m_temporaryLocalDelta; - } - - return IDENTITY; - } - - bool CScene::SelectionCanBeMoved() const - { - return (GetSelectionCaps() & CAP_MOVE) != 0; - } - - bool CScene::SelectionCanBeRotated() const - { - return (GetSelectionCaps() & CAP_ROTATE) != 0; - } - - int CScene::GetSelectionCaps() const - { - int caps = 0; - vector selectedElements; - GetSelectedElements(&selectedElements); - for (size_t i = 0; i < selectedElements.size(); ++i) - { - if (selectedElements[i].caps & CAP_MOVE && (caps & CAP_MOVE) != 0) - { - // enable rotation and scale of two or more positions - caps |= CAP_ROTATE | CAP_SCALE; - } - - caps |= selectedElements[i].caps; - } - ; - - return caps; - } - - bool CScene::SetSelectionTransform(ETransformationSpace space, const QuatT& newTransform) - { - QuatT transform = GetSelectionTransform(SPACE_WORLD); - QuatT deltaWorld; - if (space == SPACE_WORLD) - { - deltaWorld = transform.GetInverted() * newTransform; - } - else - { - deltaWorld = newTransform; - } - - bool hasElementsChanged = false; - - size_t numElements = m_elements.size(); - for (size_t i = 0; i < numElements; ++i) - { - SElement& element = m_elements[i]; - if (m_selection.Contains(element.id)) - { - QuatT parentSpace = GetParentSpace(element); - QuatT newWorldTransform = parentSpace * element.placement.transform * deltaWorld; - element.placement.transform = parentSpace.GetInverted() * newWorldTransform; - element.changed = true; - hasElementsChanged = true; - } - } - - return hasElementsChanged; - } - - Vec3 CScene::GetSelectionSize() const - { - Vec3 size(1.0f, 1.0f, 1.0f); - - vector selectedElements; - GetSelectedElements(&selectedElements); - - if (selectedElements.size() == 1) - { - size = selectedElements[0].placement.size; - } - else if (selectedElements.size() > 1) - { - AABB combinedSize(AABB::RESET); - - for (size_t i = 0; i < selectedElements.size(); ++i) - { - const SElement& element = m_elements[i]; - AABB box(element.placement.size * -0.5f, element.placement.size * 0.5f); - AABB transformedBox = AABB::CreateTransformedAABB(Matrix34(element.placement.transform), box); - combinedSize.Add(transformedBox); - } - size = combinedSize.IsReset() ? Vec3(1.0f, 1.0f, 1.0f) : combinedSize.GetSize(); - } - - return size; - } - - - bool CScene::SetSelectionSize(const Vec3& size) - { - bool hasElementsChanged = false; - - vector selectedElements; - GetSelectedElements(&selectedElements); - - if (selectedElements.size() == 1) - { - selectedElements[0].placement.size = size; - selectedElements[0].changed = true; - hasElementsChanged = true; - } - - return hasElementsChanged; - } - - void CScene::SetSpaceProvider(ISpaceProvider* provider) - { - m_spaceProvider = provider; - } - - QuatT CScene::GetParentSpace(const SElement& e) const - { - if (!m_spaceProvider) - { - return QuatT(IDENTITY); - } - QuatT result = m_spaceProvider->GetTransform(e.parentSpaceIndex); - return result; - } - - QuatT CScene::ElementToWorldSpace(const SElement& e) const - { - if (!m_spaceProvider) - { - return e.placement.transform; - } - QuatT parent = m_spaceProvider->GetTransform(e.parentSpaceIndex); - if (e.parentOrientationSpaceIndex.m_attachmentCRC32 == -1 && e.parentOrientationSpaceIndex.m_jointCRC32 == -1) - { - return parent * e.placement.transform; - } - - QuatT parentOrientation = m_spaceProvider->GetTransform(e.parentOrientationSpaceIndex); - QuatT result = parent * e.placement.transform; - result.q = parentOrientation.q * e.placement.transform.q; - return result; - } - - - void CScene::WorldSpaceToElement(SElement* e, const QuatT& worldSpaceTransform) - { - if (!e) - { - return; - } - if (!m_spaceProvider) - { - e->placement.transform = worldSpaceTransform; - return; - } - - QuatT parent = m_spaceProvider->GetTransform(e->parentSpaceIndex); - - if (e->parentOrientationSpaceIndex.m_attachmentCRC32 == -1 && e->parentOrientationSpaceIndex.m_jointCRC32 == -1) - { - e->placement.transform = parent.GetInverted() * worldSpaceTransform; - return; - } - QuatT parentOrientation = m_spaceProvider->GetTransform(e->parentOrientationSpaceIndex); - e->placement.transform = parent.GetInverted() * worldSpaceTransform; - e->placement.transform.q = parentOrientation.GetInverted().q * worldSpaceTransform.q; - } - - bool CScene::IsLayerVisible(int layer) const - { - return (m_visibleLayerMask & (1 << layer)) != 0; - } - - void CScene::SetVisibleLayerMask(unsigned int layerMask) - { - m_visibleLayerMask = layerMask; - } -} diff --git a/Code/Sandbox/Plugins/EditorCommon/ManipScene.h b/Code/Sandbox/Plugins/EditorCommon/ManipScene.h deleted file mode 100644 index dbb735d493..0000000000 --- a/Code/Sandbox/Plugins/EditorCommon/ManipScene.h +++ /dev/null @@ -1,336 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_EDITORCOMMON_MANIPSCENE_H -#define CRYINCLUDE_EDITORCOMMON_MANIPSCENE_H -#pragma once - -#include -#include -#include -#include "EditorCommonAPI.h" -#include -#include "QViewportConsumer.h" - - -namespace Serialization { - class IArchive; -} - -class CAxisHelper; - -// Manip is a set of reusable utilities for creating interactive 3d scene that -// can be manipulated with gizmos. -namespace Manip -{ - using std::unique_ptr; - using std::set; - using std::vector; - - enum EElementCaps - { - CAP_SELECT = 1 << 0, - CAP_HIDE = 1 << 1, - CAP_MOVE = 1 << 2, - CAP_ROTATE = 1 << 3, - CAP_SCALE = 1 << 4, - CAP_DELETE = 1 << 5, - }; - - enum EElementShape - { - SHAPE_AXES, - SHAPE_BOX - }; - - enum EElementAction - { - ACTION_NONE, - ACTION_DELETE, - ACTION_HIDE, - ACTION_UNHIDE - }; - - enum EElementColorGroup - { - ELEMENT_COLOR_PROXY, - ELEMENT_COLOR_CLOTH - }; - - struct SElementPlacement - { - QuatT transform; - QuatT startTransform; - Vec3 center; - Vec3 size; - - SElementPlacement() - : transform(IDENTITY) - , startTransform(IDENTITY) - , size(1.0f, 1.0f, 1.0f) - , center(0.0f, 0.0f, 0.0f) - {} - - void Serialize(Serialization::IArchive& ar); - }; - - typedef uint64 ElementId; - - struct SSpaceAndIndex - { - int m_space; - int m_jointCRC32; - int m_attachmentCRC32; - SSpaceAndIndex() - { - m_space = -1; - m_jointCRC32 = -1; - m_attachmentCRC32 = -1; - }; - }; - - struct SElement - { - int id; - union - { - int originalId; - const void* originalHandle; - }; - int layer; - SElementPlacement placement; - int caps; - EElementAction action; - EElementShape shape; - EElementColorGroup colorGroup; - SSpaceAndIndex parentSpaceIndex; - SSpaceAndIndex parentOrientationSpaceIndex; - QuatT parentSpaceConcatenation; - int mousePickPriority; - bool hidden; - bool changed; - bool alwaysXRay; - - SElement() - : id() - , layer(0) - , originalHandle(0) - , action(ACTION_NONE) - , shape(SHAPE_AXES) - , hidden(false) - , changed(false) - , colorGroup(ELEMENT_COLOR_PROXY) - , mousePickPriority(0) - , alwaysXRay(false) - , parentSpaceIndex() - , parentOrientationSpaceIndex() - , parentSpaceConcatenation(IDENTITY) - { - } - }; - typedef std::vector SElements; - - struct SElementData {}; - - struct IMouseDragHandler - { - virtual ~IMouseDragHandler() = default; - virtual bool Begin(const SMouseEvent& ev, Vec3 hitPoint) = 0; - virtual void Update(const SMouseEvent& ev) = 0; - virtual void Render([[maybe_unused]] const SRenderContext& rc) {} - virtual void End(const SMouseEvent& ev) = 0; - }; - - struct SSelectionSet - { - SSelectionSet() {} - SSelectionSet(ElementId id) { items.push_back(id); } - void Clear(); - void Add(ElementId elementId) - { - items.erase(std::remove(items.begin(), items.end(), elementId), items.end()); - items.push_back(elementId); - std::sort(items.begin(), items.end()); - } - void Remove(int elementId); - bool IsEmpty() const{ return items.empty(); } - bool Contains(int id) const{ return std::find(items.begin(), items.end(), id) != items.end(); } - size_t Size() const{ return items.size(); } - - bool operator==(const SSelectionSet& rhs) const - { - return items == rhs.items; - } - - bool operator!=(const SSelectionSet& rhs) const{ return !operator==(rhs); } - - std::vector items; - }; - - struct ICommand {}; - - struct IElementTracer - { - virtual bool HitRay(Vec3* intersectionPoint, const Ray& ray, const SElement& element) const = 0; - }; - - struct IElementDrawer - { - virtual bool Draw(const SElement& element); - }; - - enum ETransformationSpace - { - SPACE_WORLD, - SPACE_LOCAL - }; - - enum ETransformationMode - { - MODE_TRANSLATE, - MODE_ROTATE, - MODE_SCALE - }; - - struct SLookSettings - { - ColorB proxyColor; - ColorB proxySelectionColor; - ColorB proxyHighlightColor; - ColorB clothProxyColor; - - ColorB jointColor; - ColorB jointHighlightColor; - ColorB jointSelectionColor; - - SLookSettings() - : proxyColor(126, 159, 243, 128) - , proxySelectionColor(255, 255, 255, 128) - , proxyHighlightColor(233, 255, 122, 128) - , clothProxyColor(243, 159, 126, 128) - , jointColor(0, 249, 48, 255) - , jointHighlightColor(255, 248, 0, 128) - , jointSelectionColor(255, 255, 255, 128) - { - } - }; - - struct ISpaceProvider - { - virtual ~ISpaceProvider() = default; - virtual SSpaceAndIndex FindSpaceIndexByName(int spaceType, const char* name, int parentsUp) const = 0; - virtual QuatT GetTransform(const SSpaceAndIndex& index) const = 0; - }; - - AZ_PUSH_DISABLE_DLL_EXPORT_BASECLASS_WARNING - class EDITOR_COMMON_API CScene - : public QObject - , public QViewportConsumer - { - AZ_POP_DISABLE_DLL_EXPORT_BASECLASS_WARNING - Q_OBJECT - public: - CScene(); - ~CScene(); - - void OnViewportKey(const SKeyEvent& ev) override; - bool ProcessesViewportKey(const QKeySequence& key) override; - void OnViewportMouse(const SMouseEvent& ev) override; - void OnViewportRender(const SRenderContext& rc) override; - - void SetTransformationMode(ETransformationMode mode); - ETransformationMode TransformationMode() const; - void SetTransformationSpace(ETransformationSpace space); - ETransformationSpace TransformationSpace() const { return m_transformationSpace; } - void SetVisibleLayerMask(unsigned int layerMask); - unsigned int VisibleLayerMask() const { return m_visibleLayerMask; } - bool IsLayerVisible(int layer) const; - - void Clear(); - void ClearLayer(int layer); - void AddElement(const SElement& element); - void AddElement(const SElement& element, ElementId id); - void ApplyToAll(EElementAction); - void ApplyToSelection(EElementAction); - - void SetSpaceProvider(ISpaceProvider* spaceProvider); - ISpaceProvider* SpaceProvider() const{ return m_spaceProvider; } - QuatT GetParentSpace(const SElement& e) const; - QuatT ElementToWorldSpace(const SElement& e) const; - void WorldSpaceToElement(SElement* e, const QuatT& worldSpaceTransform); - - void SetCustomTracer(IElementTracer* tracer); - - const SElements& Elements() const{ return m_elements; } - SElements& Elements() { return m_elements; } - void GetSelectedElements(SElements* elements) const; - const SSelectionSet& Selection() const{ return m_selection; } - void SetSelection(const SSelectionSet& selection); - void AddToSelection(const SSelectionSet& selection); - void AddToSelection(ElementId elementId); - - bool SelectionCanBeMoved() const; - bool SelectionCanBeRotated() const; - QuatT GetSelectionTransform(ETransformationSpace space) const; - bool SetSelectionTransform(ETransformationSpace space, const QuatT& newTransform); - - void Serialize(Serialization::IArchive& ar); - signals: - void SignalUndo(); - void SignalRedo(); - void SignalPushUndo(const char* description, ICommand* cause); - void SignalElementsChanged(unsigned int layerBits); - void SignalElementContinousChange(unsigned int layerBits); - void SignalPropertiesChanged(); - void SignalRenderElements(const SElements& elements, const SRenderContext& rc); - void SignalSelectionChanged(); - void SignalManipulationModeChanged(); - - private: - void UpdateElements(const SElements& elements); - bool SetSelectionTransform(const Matrix34& newMatrix); - Matrix34 GetSelectionTransform() const; - int GetSelectionCaps() const; - Vec3 GetSelectionSize() const; - bool SetSelectionSize(const Vec3& size); - void OnMouseMove(const SMouseEvent& ev); - - struct SBlockSelectHandler; - struct SMoveHandler; - struct SRotationHandler; - struct SScalingHandler; - struct STransformBox; - - IElementTracer* m_customTracer; - IElementDrawer* m_customDrawer; - - AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING - SSelectionSet m_selection; - unique_ptr m_mouseDragHandler; - ISpaceProvider* m_spaceProvider; - unique_ptr m_axisHelper; - SElements m_elements; - std::vector m_lastIdByLayer; - ETransformationMode m_transformationMode; - ETransformationSpace m_transformationSpace; - int m_highlightItem; - unsigned int m_visibleLayerMask; - bool m_showGizmo; - SLookSettings m_lookSettings; - int m_highlightedItem; - QuatT m_temporaryLocalDelta; - AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING - }; -} - -#endif // CRYINCLUDE_EDITORCOMMON_MANIPSCENE_H diff --git a/Code/Sandbox/Plugins/EditorCommon/QViewport.cpp b/Code/Sandbox/Plugins/EditorCommon/QViewport.cpp index 2d9598ba83..36f9511e60 100644 --- a/Code/Sandbox/Plugins/EditorCommon/QViewport.cpp +++ b/Code/Sandbox/Plugins/EditorCommon/QViewport.cpp @@ -145,7 +145,6 @@ QViewport::QViewport(QWidget* parent, StartupMode startupMode) void QViewport::Startup() { m_frameTimer = new QElapsedTimer(); - CreateRenderContext(); m_camera.reset(new CCamera()); ResetCamera(); @@ -162,8 +161,6 @@ void QViewport::Startup() QViewport::~QViewport() { - DestroyRenderContext(); - m_viewportRequests.reset(); } @@ -180,51 +177,14 @@ void QViewport::UpdateBackgroundColor() bool QViewport::ScreenToWorldRay(Ray* ray, int x, int y) { - if (!GetIEditor()->GetEnv()->pRenderer) - { - return false; - } - - SetCurrentContext(); - - Vec3 pos0, pos1; - float wx, wy, wz; - if (!GetIEditor()->GetEnv()->pRenderer->UnProjectFromScreen(float(x), float(m_height - y), 0, &wx, &wy, &wz)) - { - RestorePreviousContext(); - return false; - } - pos0(wx, wy, wz); - if (!GetIEditor()->GetEnv()->pRenderer->UnProjectFromScreen(float(x), float(m_height - y), 1, &wx, &wy, &wz)) - { - RestorePreviousContext(); - return false; - } - pos1(wx, wy, wz); - - RestorePreviousContext(); - - Vec3 v = (pos1 - pos0); - v = v.GetNormalized(); - - ray->origin = pos0; - ray->direction = v; - return true; + AZ_UNUSED(ray); + AZ_UNUSED(x); + AZ_UNUSED(y); + return false; } -QPoint QViewport::ProjectToScreen(const Vec3& wp) +QPoint QViewport::ProjectToScreen(const Vec3&) { - float x, y, z; - - SetCurrentContext(); - GetIEditor()->GetEnv()->pRenderer->ProjectToScreen(wp.x, wp.y, wp.z, &x, &y, &z); - if (_finite(x) || _finite(y)) - { - RestorePreviousContext(); - return QPoint(int((x / 100.0) * Width()), int((y / 100.0) * Height())); - } - RestorePreviousContext(); - return QPoint(0, 0); } @@ -245,105 +205,6 @@ int QViewport::Height() const return rect().height(); } -bool QViewport::CreateRenderContext() -{ - if (m_creatingRenderContext || !isVisible()) - { - return false; - } - - HWND windowHandle = reinterpret_cast(QWidget::winId()); - - if( m_renderContextCreated && windowHandle == m_lastHwnd) - { - // the hwnd has not changed, no need to destroy and recreate context (and swap chain etc) - return false; - } - - m_creatingRenderContext = true; - DestroyRenderContext(); - if (windowHandle && GetIEditor()->GetEnv()->pRenderer && !m_renderContextCreated) - { - m_renderContextCreated = true; - - m_viewportRequests.get()->BusConnect(windowHandle); - AzFramework::WindowSystemNotificationBus::Broadcast(&AzFramework::WindowSystemNotificationBus::Handler::OnWindowCreated, windowHandle); - - m_lastHwnd = windowHandle; - - StorePreviousContext(); - GetIEditor()->GetEnv()->pRenderer->CreateContext(windowHandle); - RestorePreviousContext(); - - m_creatingRenderContext = false; - return true; - } - m_creatingRenderContext = false; - return false; -} - -void QViewport::DestroyRenderContext() -{ - if (GetIEditor()->GetEnv()->pRenderer && m_renderContextCreated) - { - HWND windowHandle = reinterpret_cast(QWidget::winId()); - - if (windowHandle != GetIEditor()->GetEnv()->pRenderer->GetHWND()) - { - GetIEditor()->GetEnv()->pRenderer->DeleteContext(windowHandle); - } - m_renderContextCreated = false; - - AzFramework::WindowNotificationBus::Event(windowHandle, &AzFramework::WindowNotificationBus::Handler::OnWindowClosed); - m_viewportRequests.get()->BusDisconnect(); - m_lastHwnd = 0; - } -} - -void QViewport::StorePreviousContext() -{ - SPreviousContext previous; - previous.width = GetIEditor()->GetEnv()->pRenderer->GetWidth(); - previous.height = GetIEditor()->GetEnv()->pRenderer->GetHeight(); - previous.window = reinterpret_cast(GetIEditor()->GetEnv()->pRenderer->GetCurrentContextHWND()); - previous.renderCamera = GetIEditor()->GetEnv()->pRenderer->GetCamera(); - previous.systemCamera = GetISystem()->GetViewCamera(); - previous.isMainViewport = GetIEditor()->GetEnv()->pRenderer->IsCurrentContextMainVP(); - m_previousContexts.push_back(previous); -} - -void QViewport::SetCurrentContext() -{ - StorePreviousContext(); - - if (m_camera.get() == 0) - { - return; - } - - HWND windowHandle = reinterpret_cast(QWidget::winId()); - GetIEditor()->GetEnv()->pRenderer->SetCurrentContext(windowHandle); - GetIEditor()->GetEnv()->pRenderer->ChangeViewport(0, 0, m_width, m_height); - GetIEditor()->GetEnv()->pRenderer->SetCamera(*m_camera); - GetIEditor()->GetEnv()->pSystem->SetViewCamera(*m_camera); -} - -void QViewport::RestorePreviousContext() -{ - if (m_previousContexts.empty()) - { - assert(0); - return; - } - - SPreviousContext x = m_previousContexts.back(); - m_previousContexts.pop_back(); - GetIEditor()->GetEnv()->pRenderer->SetCurrentContext(x.window); - GetIEditor()->GetEnv()->pRenderer->ChangeViewport(0, 0, x.width, x.height, x.isMainViewport); - GetIEditor()->GetEnv()->pRenderer->SetCamera(x.renderCamera); - GetIEditor()->GetEnv()->pSystem->SetViewCamera(x.systemCamera); -} - void QViewport::Serialize(IArchive& ar) { if (!ar.IsEdit()) @@ -720,45 +581,6 @@ void QViewport::RenderInternal() { } -void QViewport::GetImageOffscreen(CImageEx& image, const QSize& customSize) -{ - if ((m_width == 0) || (m_height == 0)) - { - // This can occur, for example, if the material editor window is sized to zero OR - // if it is docked as a tab in another view pane window and is not the active tab when the editor starts. - image.Allocate(1, 1); - image.Clear(); - return; - } - - IRenderer* renderer = GetIEditor()->GetRenderer(); - - renderer->EnableSwapBuffers(false); - RenderInternal(); - renderer->EnableSwapBuffers(true); - - int w; - int h; - - if (customSize.isValid()) - { - w = customSize.width(); - h = customSize.height(); - } - else - { - w = width(); - h = height(); - } - - image.Allocate(w, h); - - // the renderer will read the frame buffer of the current render context, so we need to set ours as the current before we execute this command. - SetCurrentContext(); - renderer->ReadFrameBufferFast(image.GetData(), w, h); - RestorePreviousContext(); -} - void QViewport::SetWindowTitle(const AZStd::string& title) { // Do not support the WindowRequestBus changing the editor window title @@ -1022,12 +844,6 @@ void QViewport::resizeEvent(QResizeEvent* ev) m_width = cx; m_height = cy; - // We queue the window resize event in case the windows is hidden. - // If the QWidget is hidden, the native windows does not resize and the - // swapchain may have the incorrect size. We need to wait - // until it's visible to trigger the resize event. - m_resizeWindowEvent = true; - GetIEditor()->GetEnv()->pSystem->GetISystemEventDispatcher()->OnSystemEvent(ESYSTEM_EVENT_RESIZE, cx, cy); SignalUpdate(); Update(); @@ -1035,18 +851,9 @@ void QViewport::resizeEvent(QResizeEvent* ev) void QViewport::showEvent(QShowEvent* ev) { - // force a context create once we're shown - // This must be queued, as the showEvent is sent before the widget is actually shown, not after - QMetaObject::invokeMethod(this, "ForceRebuildRenderContext", Qt::QueuedConnection); - QWidget::showEvent(ev); } -void QViewport::ForceRebuildRenderContext() -{ - CreateRenderContext(); -} - void QViewport::moveEvent(QMoveEvent* ev) { QWidget::moveEvent(ev); @@ -1058,11 +865,6 @@ bool QViewport::event(QEvent* ev) { bool result = QWidget::event(ev); - if (ev->type() == QEvent::WinIdChange) - { - CreateRenderContext(); - } - if (ev->type() == QEvent::ShortcutOverride) { // When a shortcut is matched, Qt's event processing sends out a shortcut override event diff --git a/Code/Sandbox/Plugins/EditorCommon/QViewport.h b/Code/Sandbox/Plugins/EditorCommon/QViewport.h index 72b2024bc4..5566edc126 100644 --- a/Code/Sandbox/Plugins/EditorCommon/QViewport.h +++ b/Code/Sandbox/Plugins/EditorCommon/QViewport.h @@ -104,7 +104,6 @@ public: int Width() const; int Height() const; void SetSize(const QSize& size); - void GetImageOffscreen(CImageEx& image, const QSize& customSize); // WindowRequestBus::Handler... (handler moved to cpp to resolve link issues in unity builds) void SetWindowTitle(const AZStd::string& title); @@ -119,7 +118,6 @@ public slots: void Update(); protected slots: void RenderInternal(); - void ForceRebuildRenderContext(); signals: void SignalPreRender(const SRenderContext&); void SignalRender(const SRenderContext&); @@ -146,12 +144,6 @@ protected: private: struct SPrivate; - bool CreateRenderContext(); - void DestroyRenderContext(); - void StorePreviousContext(); -protected: - void SetCurrentContext(); - void RestorePreviousContext(); private: void UpdateBackgroundColor(); @@ -198,6 +190,4 @@ private: std::vector m_consumers; AZStd::unique_ptr m_viewportRequests; AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING - HWND m_lastHwnd = 0; - bool m_resizeWindowEvent = false; }; diff --git a/Code/Sandbox/Plugins/EditorCommon/editorcommon_files.cmake b/Code/Sandbox/Plugins/EditorCommon/editorcommon_files.cmake index e1a63b77da..5551c07be1 100644 --- a/Code/Sandbox/Plugins/EditorCommon/editorcommon_files.cmake +++ b/Code/Sandbox/Plugins/EditorCommon/editorcommon_files.cmake @@ -15,8 +15,6 @@ set(FILES EditorCommon.rc EditorCommon.qrc EditorCommonAPI.h - ManipScene.cpp - ManipScene.h moc.cpp QViewportConsumer.h TimelineContent.h diff --git a/Code/Sandbox/Plugins/EditorCommon/moc.cpp b/Code/Sandbox/Plugins/EditorCommon/moc.cpp index 9fc66faa8c..ce9570b673 100644 --- a/Code/Sandbox/Plugins/EditorCommon/moc.cpp +++ b/Code/Sandbox/Plugins/EditorCommon/moc.cpp @@ -13,11 +13,9 @@ #include "EditorCommon_precompiled.h" #include -#include #include #include #include -#include #include #include diff --git a/Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/AtomFont.h b/Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/AtomFont.h index fbefc84aad..d5463fc15c 100644 --- a/Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/AtomFont.h +++ b/Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/AtomFont.h @@ -79,7 +79,6 @@ namespace AZ FontFamilyPtr LoadFontFamily(const char* fontFamilyName) override; FontFamilyPtr GetFontFamily(const char* fontFamilyName) override; void AddCharsToFontTextures(FontFamilyPtr fontFamily, const char* chars, int glyphSizeX = ICryFont::defaultGlyphSizeX, int glyphSizeY = ICryFont::defaultGlyphSizeY) override; - void SetRendererProperties([[maybe_unused]] IRenderer* renderer) override {} void GetMemoryUsage([[maybe_unused]] ICrySizer* sizer) const override {} string GetLoadedFontNames() const; void OnLanguageChanged() override; diff --git a/Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/AtomNullFont.h b/Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/AtomNullFont.h index 11efc35109..4951f909e8 100644 --- a/Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/AtomNullFont.h +++ b/Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/AtomNullFont.h @@ -79,7 +79,6 @@ namespace AZ virtual FontFamilyPtr LoadFontFamily([[maybe_unused]] const char* fontFamilyName) override { CRY_ASSERT(false); return nullptr; } virtual FontFamilyPtr GetFontFamily([[maybe_unused]] const char* fontFamilyName) override { CRY_ASSERT(false); return nullptr; } virtual void AddCharsToFontTextures([[maybe_unused]] FontFamilyPtr fontFamily, [[maybe_unused]] const char* chars, [[maybe_unused]] int glyphSizeX, [[maybe_unused]] int glyphSizeY) override {}; - virtual void SetRendererProperties([[maybe_unused]] IRenderer* pRenderer) override {} virtual void GetMemoryUsage([[maybe_unused]] ICrySizer* sizer) const override {} virtual string GetLoadedFontNames() const override { return ""; } virtual void OnLanguageChanged() override { } diff --git a/Gems/AtomLyIntegration/AtomFont/Code/Source/FFont.cpp b/Gems/AtomLyIntegration/AtomFont/Code/Source/FFont.cpp index 40684640d6..75b0e22e4a 100644 --- a/Gems/AtomLyIntegration/AtomFont/Code/Source/FFont.cpp +++ b/Gems/AtomLyIntegration/AtomFont/Code/Source/FFont.cpp @@ -1233,7 +1233,8 @@ void AZ::FFont::WrapText(string& result, float maxWidth, const char* str, const if (ctx.m_sizeIn800x600) { - maxWidth = gEnv->pRenderer->ScaleCoordX(maxWidth); + // ToDo: Update to work with Atom? LYN-3676 + // maxWidth = ???->ScaleCoordX(maxWidth); } Vec2 strSize = GetTextSize(result.c_str(), true, ctx); diff --git a/Gems/AudioSystem/Code/Source/Engine/ATL.cpp b/Gems/AudioSystem/Code/Source/Engine/ATL.cpp index 2398836e48..dc6742d460 100644 --- a/Gems/AudioSystem/Code/Source/Engine/ATL.cpp +++ b/Gems/AudioSystem/Code/Source/Engine/ATL.cpp @@ -2018,7 +2018,8 @@ namespace Audio { AZ_PROFILE_FUNCTION(AZ::Debug::ProfileCategory::Audio); - if (IRenderAuxGeom* pAuxGeom = (g_audioCVars.m_nDrawAudioDebug > 0 && gEnv->pRenderer) ? gEnv->pRenderer->GetIRenderAuxGeom() : nullptr) + // ToDo: Update to work with Atom? LYN-3677 + /*if (g_audioCVars.m_nDrawAudioDebug > 0) { DrawAudioObjectDebugInfo(*pAuxGeom); // needs to be called first so that the rest of the labels are printed // on top (Draw2dLabel doesn't provide a way set which labels are printed on top) @@ -2108,7 +2109,7 @@ namespace Audio DrawATLComponentDebugInfo(*pAuxGeom, fPosX, fPosY); pAuxGeom->Commit(7); - } + }*/ } /////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/Gems/AudioSystem/Code/Source/Engine/ATLAudioObject.cpp b/Gems/AudioSystem/Code/Source/Engine/ATLAudioObject.cpp index 7f3735dacf..3b820eb51d 100644 --- a/Gems/AudioSystem/Code/Source/Engine/ATLAudioObject.cpp +++ b/Gems/AudioSystem/Code/Source/Engine/ATLAudioObject.cpp @@ -839,16 +839,16 @@ namespace Audio const AZ::Vector3 vPos(m_oPosition.GetPositionVec()); AZ::Vector3 vScreenPos(0.f); - if (IRenderer* pRenderer = gEnv->pRenderer) - { + // ToDo: Update to work with Atom? LYN-3677 + /*{ float screenProj[3]; - pRenderer->ProjectToScreen(vPos.GetX(), vPos.GetY(), vPos.GetZ(), &screenProj[0], &screenProj[1], &screenProj[2]); + ???->ProjectToScreen(vPos.GetX(), vPos.GetY(), vPos.GetZ(), &screenProj[0], &screenProj[1], &screenProj[2]); - screenProj[0] *= 0.01f * static_cast(pRenderer->GetWidth()); - screenProj[1] *= 0.01f * static_cast(pRenderer->GetHeight()); + screenProj[0] *= 0.01f * static_cast(???->GetWidth()); + screenProj[1] *= 0.01f * static_cast(???->GetHeight()); vScreenPos.Set(screenProj); } - else + else*/ { vScreenPos.SetZ(-1.0f); } @@ -1081,8 +1081,8 @@ namespace Audio ); } - IRenderer* renderer = gEnv->pRenderer; - if (drawLabels && renderer) + // ToDo: Update to work with Atom? LYN-3677 + /*if (drawLabels) { float screenProj[3]; renderer->ProjectToScreen(rayEnd.GetX(), rayEnd.GetY(), rayEnd.GetZ(), @@ -1108,7 +1108,7 @@ namespace Audio rayInfo.GetDistanceScaledContribution() ); } - } + }*/ } auxGeom.SetRenderFlags(previousRenderFlags); diff --git a/Gems/EMotionFX/Code/Tests/UI/LODSkinnedMeshTests.cpp b/Gems/EMotionFX/Code/Tests/UI/LODSkinnedMeshTests.cpp index b9b512da36..9fa3e17263 100644 --- a/Gems/EMotionFX/Code/Tests/UI/LODSkinnedMeshTests.cpp +++ b/Gems/EMotionFX/Code/Tests/UI/LODSkinnedMeshTests.cpp @@ -77,7 +77,6 @@ namespace EMotionFX m_app.RegisterComponentDescriptor(AzFramework::TransformComponent::CreateDescriptor()); m_envPrev = gEnv; - m_env.pRenderer = &m_data.m_renderer; m_env.pSystem = &m_data.m_system; gEnv = &m_env; } diff --git a/Gems/ImGui/Code/CMakeLists.txt b/Gems/ImGui/Code/CMakeLists.txt index 9b594d86f9..2f7d6c6ce7 100644 --- a/Gems/ImGui/Code/CMakeLists.txt +++ b/Gems/ImGui/Code/CMakeLists.txt @@ -95,8 +95,6 @@ if(PAL_TRAIT_BUILD_HOST_TOOLS) NAME ImGui.Editor GEM_MODULE NAMESPACE Gem - AUTOMOC - AUTOUIC FILES_CMAKE imgui_editor_files.cmake COMPILE_DEFINITIONS @@ -112,9 +110,6 @@ if(PAL_TRAIT_BUILD_HOST_TOOLS) BUILD_DEPENDENCIES PRIVATE Gem::ImGui.Static - 3rdParty::Qt::Widgets - AZ::AzToolsFramework - Legacy::Editor.Headers RUNTIME_DEPENDENCIES Gem::LmbrCentral.Editor ) diff --git a/Gems/ImGui/Code/Editor/ImGuiEditorWindowBus.h b/Gems/ImGui/Code/Editor/ImGuiEditorWindowBus.h deleted file mode 100644 index 1ee987a74d..0000000000 --- a/Gems/ImGui/Code/Editor/ImGuiEditorWindowBus.h +++ /dev/null @@ -1,32 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#pragma once - -#include - -namespace ImGui -{ - class ImGuiEditorWindowRequests - : public AZ::EBusTraits - { - public: - ////////////////////////////////////////////////////////////////////////// - // EBusTraits overrides - static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single; - static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single; - ////////////////////////////////////////////////////////////////////////// - - // Put your public methods here - }; - using ImGuiEditorWindowRequestBus = AZ::EBus; -} // namespace ImGuiEditorWindow diff --git a/Gems/ImGui/Code/Editor/ImGuiEditorWindowModule.cpp b/Gems/ImGui/Code/Editor/ImGuiEditorWindowModule.cpp index f44d5cb61e..b02f470ad9 100644 --- a/Gems/ImGui/Code/Editor/ImGuiEditorWindowModule.cpp +++ b/Gems/ImGui/Code/Editor/ImGuiEditorWindowModule.cpp @@ -13,7 +13,6 @@ #include "ImGui_precompiled.h" #include "ImGuiGem.h" -#include "ImGuiEditorWindowSystemComponent.h" namespace ImGui { @@ -26,22 +25,6 @@ namespace ImGui ImGuiEditorWindowModule() : ImGuiModule() { - // Push results of [MyComponent]::CreateDescriptor() into m_descriptors here. - m_descriptors.insert(m_descriptors.end(), { - ImGuiEditorWindowSystemComponent::CreateDescriptor(), - }); - } - - /** - * Add required SystemComponents to the SystemEntity. - */ - AZ::ComponentTypeList GetRequiredSystemComponents() const override - { - AZ::ComponentTypeList requiredComponents = ImGuiModule::GetRequiredSystemComponents(); - - requiredComponents.push_back(azrtti_typeid()); - - return requiredComponents; } }; } diff --git a/Gems/ImGui/Code/Editor/ImGuiEditorWindowSystemComponent.cpp b/Gems/ImGui/Code/Editor/ImGuiEditorWindowSystemComponent.cpp deleted file mode 100644 index 07ab3b0a42..0000000000 --- a/Gems/ImGui/Code/Editor/ImGuiEditorWindowSystemComponent.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#include "ImGui_precompiled.h" - -#include -#include -#include -#include "ImGuiEditorWindowSystemComponent.h" -#include "ImGuiMainWindow.h" -#include - -static const char* s_ImGuiQtViewPaneName = "ImGui Editor"; - -namespace ImGui -{ - void ImGuiEditorWindowSystemComponent::Reflect(AZ::ReflectContext* context) - { - if (AZ::SerializeContext* serialize = azrtti_cast(context)) - { - serialize->Class() - ->Version(0) - ; - } - } - - void ImGuiEditorWindowSystemComponent::Activate() - { - AzToolsFramework::EditorEvents::Bus::Handler::BusConnect(); - ImGuiEditorWindowRequestBus::Handler::BusConnect(); - ImGuiUpdateListenerBus::Handler::BusConnect(); - } - - void ImGuiEditorWindowSystemComponent::Deactivate() - { - ImGuiUpdateListenerBus::Handler::BusDisconnect(); - ImGuiEditorWindowRequestBus::Handler::BusDisconnect(); - AzToolsFramework::EditorEvents::Bus::Handler::BusDisconnect(); - } - - ImGuiEditorWindowSystemComponent::~ImGuiEditorWindowSystemComponent() - { - EBUS_EVENT(AzToolsFramework::EditorRequests::Bus, UnregisterViewPane, s_ImGuiQtViewPaneName); - } - - void ImGuiEditorWindowSystemComponent::OnOpenEditorWindow() - { - EBUS_EVENT(AzToolsFramework::EditorRequests::Bus, OpenViewPane, s_ImGuiQtViewPaneName); - } - - void ImGuiEditorWindowSystemComponent::NotifyRegisterViews() - { - } -} diff --git a/Gems/ImGui/Code/Editor/ImGuiEditorWindowSystemComponent.h b/Gems/ImGui/Code/Editor/ImGuiEditorWindowSystemComponent.h deleted file mode 100644 index 1f9d3cdc52..0000000000 --- a/Gems/ImGui/Code/Editor/ImGuiEditorWindowSystemComponent.h +++ /dev/null @@ -1,59 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#pragma once - -#include - -#include -#include -#include "ImGuiManager.h" -#include "ImGuiBus.h" - -namespace ImGui -{ - class ImGuiEditorWindowSystemComponent - : public AZ::Component - , protected ImGuiEditorWindowRequestBus::Handler - , public ImGuiUpdateListenerBus::Handler - , protected AzToolsFramework::EditorEvents::Bus::Handler - { - public: - AZ_COMPONENT(ImGuiEditorWindowSystemComponent, "{91021F3E-B5F0-4E26-A7C9-6ED0F6CB6C5A}"); - - virtual ~ImGuiEditorWindowSystemComponent(); - - static void Reflect(AZ::ReflectContext* context); - - protected: - //////////////////////////////////////////////////////////////////////// - // ImGuiEditorWindowRequestBus interface implementation - - //////////////////////////////////////////////////////////////////////// - - //////////////////////////////////////////////////////////////////////// - // AZ::Component interface implementation - void Activate() override; - void Deactivate() override; - //////////////////////////////////////////////////////////////////////// - - //////////////////////////////////////////////////////////////////////// - // ImGuiUpdateListenerBus interface implementation - void OnOpenEditorWindow() override; - //////////////////////////////////////////////////////////////////////// - - //////////////////////////////////////////////////////////////////////// - // EditorEvents - void NotifyRegisterViews() override; - //////////////////////////////////////////////////////////////////////// - }; -} diff --git a/Gems/ImGui/Code/Editor/ImGuiMainWindow.cpp b/Gems/ImGui/Code/Editor/ImGuiMainWindow.cpp deleted file mode 100644 index b4774d1334..0000000000 --- a/Gems/ImGui/Code/Editor/ImGuiMainWindow.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -#include "ImGui_precompiled.h" -#include "ImGuiMainWindow.h" -#include "QtViewPaneManager.h" -#include "ImGuiViewport.h" -#include - -using namespace ImGui; - -ImGuiMainWindow::ImGuiMainWindow(QWidget* parent) - : QMainWindow(parent) - , m_ui(new Ui::ImGuiMainWindow) - , m_viewport(new ImGuiViewportWidget(this)) -{ - m_ui->setupUi(this); - - //@rky: Add the ImGuiViewport to this window - m_viewport->setFocusPolicy(Qt::StrongFocus); - m_ui->gridLayout->addWidget(m_viewport, 0, 0, 1, 1); -} - -#include diff --git a/Gems/ImGui/Code/Editor/ImGuiMainWindow.h b/Gems/ImGui/Code/Editor/ImGuiMainWindow.h deleted file mode 100644 index 659ec7b4c1..0000000000 --- a/Gems/ImGui/Code/Editor/ImGuiMainWindow.h +++ /dev/null @@ -1,55 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -#ifndef __IMGUI_MAINWINDOW_H__ -#define __IMGUI_MAINWINDOW_H__ - -#pragma once - -#if !defined(Q_MOC_RUN) -#include -#include "IEditor.h" -#include -#endif - -namespace Ui -{ - class ImGuiMainWindow; -} - -namespace ImGui -{ - class ImGuiViewportWidget; - - class ImGuiMainWindow : public QMainWindow - { - Q_OBJECT - public: - - static const GUID& GetClassID() - { - // {ECA9F41C-716E-4395-A096-5A519227F9A4} - static const GUID guid = - { 0xeca9f41c, 0x716e, 0x4395, { 0xa0, 0x96, 0x5a, 0x51, 0x92, 0x27, 0xf9, 0xa4 } }; - - return guid; - } - - explicit ImGuiMainWindow(QWidget* parent = nullptr); - - private: - QScopedPointer m_ui; - - ImGuiViewportWidget* m_viewport; - }; -} - -#endif //__IMGUI_MAINWINDOW_H__ diff --git a/Gems/ImGui/Code/Editor/ImGuiMainwindow.ui b/Gems/ImGui/Code/Editor/ImGuiMainwindow.ui deleted file mode 100644 index 7124e22c7a..0000000000 --- a/Gems/ImGui/Code/Editor/ImGuiMainwindow.ui +++ /dev/null @@ -1,33 +0,0 @@ - - - ImGuiMainWindow - - - - 0 - 0 - 1263 - 740 - - - - MainWindow - - - - - - - - 0 - 0 - 1263 - 21 - - - - - - - - diff --git a/Gems/ImGui/Code/Editor/ImGuiViewport.cpp b/Gems/ImGui/Code/Editor/ImGuiViewport.cpp deleted file mode 100644 index 7c467d7f08..0000000000 --- a/Gems/ImGui/Code/Editor/ImGuiViewport.cpp +++ /dev/null @@ -1,339 +0,0 @@ -/* - * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or - * its licensors. - * - * For complete copyright and license terms please see the LICENSE at the root of this - * distribution (the "License"). All use of this software is governed by the License, - * or, if provided, by the license below or the license accompanying this file. Do not - * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * - */ -#include "ImGui_precompiled.h" - -#include "ImGuiViewport.h" -#include -#include -#include -#include -#include "ImGuiBus.h" -#include "ImGuiManager.h" -#include - -using namespace ImGui; - -ImGuiViewportWidget::ImGuiViewportWidget(QWidget* parent) - : QWidget(parent) - , m_width(0) - , m_height(0) - , m_renderContextCreated(false) - , m_creatingRenderContext(false) - , m_lastTime(0) - , m_lastFrameTime(0.f) - , m_averageFrameTime(0.f) -{ - // Setup a timer for the maximum refresh rate we want. - // Refresh is actually triggered by interaction events and by the IdleUpdate. This avoids the UI - // Editor slowing down the main editor when no UI interaction is occurring. - QObject::connect(&m_updateTimer, SIGNAL(timeout()), this, SLOT(RefreshTick())); - const int kUpdateIntervalInMillseconds = 1000 / 60; // 60 Hz - m_updateTimer.start(kUpdateIntervalInMillseconds); - - CreateRenderContext(); -} - -ImGuiViewportWidget::~ImGuiViewportWidget() -{ - DestroyRenderContext(); - ImGuiManagerBus::Broadcast(&IImGuiManager::SetEditorWindowState, - DisplayState::Hidden); -} - -bool ImGuiViewportWidget::CreateRenderContext() -{ - if (m_creatingRenderContext) - { - return false; - } - m_creatingRenderContext = true; - DestroyRenderContext(); - HWND window = (HWND)QWidget::winId(); - IEditor* editor = nullptr; - EBUS_EVENT_RESULT(editor, AzToolsFramework::EditorRequests::Bus, GetEditor); - if (window && editor->GetEnv()->pRenderer && !m_renderContextCreated) - { - m_renderContextCreated = true; - - StorePreviousContext(); - editor->GetEnv()->pRenderer->CreateContext(window); - RestorePreviousContext(); - - ImGuiManagerBus::Broadcast(&IImGuiManager::SetEditorWindowState, - DisplayState::Visible); - - m_creatingRenderContext = false; - return true; - } - m_creatingRenderContext = false; - return false; -} - -void ImGuiViewportWidget::DestroyRenderContext() -{ - IEditor* editor = nullptr; - EBUS_EVENT_RESULT(editor, AzToolsFramework::EditorRequests::Bus, GetEditor); - if (editor->GetEnv()->pRenderer && m_renderContextCreated) - { - HWND window = (HWND)QWidget::winId(); - if (window != editor->GetEnv()->pRenderer->GetHWND()) - { - editor = nullptr; - EBUS_EVENT_RESULT(editor, AzToolsFramework::EditorRequests::Bus, GetEditor); - editor->GetEnv()->pRenderer->DeleteContext(window); - } - m_renderContextCreated = false; - } -} - -void ImGuiViewportWidget::StorePreviousContext() -{ - SPreviousContext previous; - IEditor* editor = nullptr; - EBUS_EVENT_RESULT(editor, AzToolsFramework::EditorRequests::Bus, GetEditor); - previous.width = editor->GetEnv()->pRenderer->GetWidth(); - previous.height = editor->GetEnv()->pRenderer->GetHeight(); - previous.window = (HWND)editor->GetEnv()->pRenderer->GetCurrentContextHWND(); - previous.renderCamera = editor->GetEnv()->pRenderer->GetCamera(); - previous.systemCamera = gEnv->pSystem->GetViewCamera(); - previous.isMainViewport = editor->GetEnv()->pRenderer->IsCurrentContextMainVP(); - m_previousContexts.push(previous); -} - -void ImGuiViewportWidget::SetCurrentContext() -{ - StorePreviousContext(); - - IEditor* editor = nullptr; - EBUS_EVENT_RESULT(editor, AzToolsFramework::EditorRequests::Bus, GetEditor); - - HWND window = (HWND)QWidget::winId(); - editor->GetEnv()->pRenderer->SetCurrentContext(window); - editor->GetEnv()->pRenderer->ChangeViewport(0, 0, m_width, m_height); -} - -void ImGuiViewportWidget::RestorePreviousContext() -{ - if (m_previousContexts.empty()) - { - return; - } - - SPreviousContext x = m_previousContexts.top(); - m_previousContexts.pop(); - IEditor* editor = nullptr; - EBUS_EVENT_RESULT(editor, AzToolsFramework::EditorRequests::Bus, GetEditor); - editor->GetEnv()->pRenderer->SetCurrentContext(x.window); - editor->GetEnv()->pRenderer->ChangeViewport(0, 0, x.width, x.height, x.isMainViewport); - - editor->GetEnv()->pRenderer->SetCamera(x.renderCamera); - gEnv->pSystem->SetViewCamera(x.systemCamera); -} - -void ImGuiViewportWidget::Render() -{ - SetCurrentContext(); - - IEditor* editor = nullptr; - EBUS_EVENT_RESULT(editor, AzToolsFramework::EditorRequests::Bus, GetEditor); - - IRenderer* renderer = editor->GetEnv()->pRenderer; - - ColorF viewportBackgroundColor(Col_Gray); - ColorF stateMessageColor(Col_Gray); - AZStd::string stateMessage = "No State"; - DisplayState visibilityState = DisplayState::Hidden; - ImGuiManagerBus::BroadcastResult(visibilityState, - &IImGuiManager::GetEditorWindowState); - switch (visibilityState) - { - case ImGui::DisplayState::Hidden: - stateMessage = "Invisible"; - break; - case ImGui::DisplayState::Visible: - stateMessage = "ImGui Window"; - stateMessageColor = Col_SteelBlue; - viewportBackgroundColor = Col_SkyBlue; - break; - case ImGui::DisplayState::VisibleNoMouse: - stateMessage = "Game Focus"; - stateMessageColor = Col_Gray; - viewportBackgroundColor = Col_LightGray; - break; - } - - renderer->ClearTargetsImmediately(FRT_CLEAR | FRT_CLEAR_IMMEDIATE, viewportBackgroundColor); - renderer->ResetToDefault(); - - renderer->Draw2dLabel( - 12.0f, m_height - 50.f, 1.25f, Col_White, false, "FPS: %.2f", 1.0f / m_averageFrameTime); - renderer->Draw2dLabel( - 12.0f, m_height - 30.f, 2.f, stateMessageColor, false, "State: %s", stateMessage.c_str()); - - if (ImDrawData* drawData = ImGui::GetDrawData()) - { - // Configure renderer for 2d imgui rendering - renderer->SetCullMode(R_CULL_DISABLE); - TransformationMatrices backupSceneMatrices; - renderer->Set2DMode(renderer->GetWidth(), renderer->GetHeight(), backupSceneMatrices); - renderer->SetColorOp(eCO_REPLACE, eCO_MODULATE, eCA_Diffuse, DEF_TEXARG0); - renderer->SetSrgbWrite(false); - renderer->SetState(GS_BLSRC_SRCALPHA | GS_BLDST_ONEMINUSSRCALPHA | GS_NODEPTHTEST); - - // Expand vertex buffer if necessary - m_vertBuffer.reserve(drawData->TotalVtxCount); - if (m_vertBuffer.size() < drawData->TotalVtxCount) - { - m_vertBuffer.insert(m_vertBuffer.end(), - drawData->TotalVtxCount - m_vertBuffer.size(), - SVF_P3F_C4B_T2F()); - } - - // Expand index buffer if necessary - m_idxBuffer.reserve(drawData->TotalIdxCount); - if (m_idxBuffer.size() < drawData->TotalIdxCount) - { - m_idxBuffer.insert(m_idxBuffer.end(), drawData->TotalIdxCount - m_idxBuffer.size(), 0); - } - - // Process each draw command list individually - for (int n = 0; n < drawData->CmdListsCount; n++) - { - const ImDrawList* cmd_list = drawData->CmdLists[n]; - - // Cache max vert count for easy access - int numVerts = cmd_list->VtxBuffer.Size; - - // Copy command list verts into buffer - for (int i = 0; i < numVerts; ++i) - { - const ImDrawVert& imguiVert = cmd_list->VtxBuffer[i]; - SVF_P3F_C4B_T2F& vert = m_vertBuffer[i]; - - vert.xyz = Vec3(imguiVert.pos.x, imguiVert.pos.y, 0.0f); - // Convert color from RGBA to ARGB - vert.color.dcolor = (imguiVert.col & 0xFF00FF00) - | ((imguiVert.col & 0xFF0000) >> 16) - | ((imguiVert.col & 0xFF) << 16); - vert.st = Vec2(imguiVert.uv.x, imguiVert.uv.y); - } - - // Copy command list indices into buffer - for (int i = 0; i < cmd_list->IdxBuffer.Size; ++i) - { - m_idxBuffer[i] = uint16(cmd_list->IdxBuffer[i]); - } - - // Use offset pointer to step along rendering operation - uint16* idxBufferDataOffset = m_idxBuffer.data(); - - // Process each draw command individually - for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.size(); cmd_i++) - { - const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i]; - - // Defer to user rendering callback, if appropriate - if (pcmd->UserCallback) - { - pcmd->UserCallback(cmd_list, pcmd); - } - // Otherwise render our buffers - else - { - int textureId = ((ITexture*)pcmd->TextureId)->GetTextureID(); - renderer->SetTexture(textureId); - renderer->SetScissor((int)pcmd->ClipRect.x, - (int)(pcmd->ClipRect.y), - (int)(pcmd->ClipRect.z - pcmd->ClipRect.x), - (int)(pcmd->ClipRect.w - pcmd->ClipRect.y)); - renderer->DrawDynVB(m_vertBuffer.data(), - idxBufferDataOffset, - numVerts, - pcmd->ElemCount, - prtTriangleList); - } - - // Update offset pointer into command list's index buffer - idxBufferDataOffset += pcmd->ElemCount; - } - } - - // Reset scissor usage on renderer - renderer->SetScissor(); - - // Clean up renderer settings - renderer->Unset2DMode(backupSceneMatrices); - } - - RestorePreviousContext(); -} - -void ImGuiViewportWidget::resizeEvent(QResizeEvent* ev) -{ - QWidget::resizeEvent(ev); - - int cx = ev->size().width(); - int cy = ev->size().height(); - if (cx == 0 || cy == 0) - { - return; - } - - m_width = cx; - m_height = cy; - - IEditor* editor = nullptr; - EBUS_EVENT_RESULT(editor, AzToolsFramework::EditorRequests::Bus, GetEditor); - editor->GetEnv()->pSystem->GetISystemEventDispatcher()->OnSystemEvent( - ESYSTEM_EVENT_RESIZE, cx, cy); - - RefreshTick(); -} - -void ImGuiViewportWidget::RefreshTick() -{ - IEditor* editor = nullptr; - EBUS_EVENT_RESULT(editor, AzToolsFramework::EditorRequests::Bus, GetEditor); - int64 time = editor->GetEnv()->pSystem->GetITimer()->GetAsyncTime().GetMilliSecondsAsInt64(); - if (m_lastTime == 0) - { - m_lastTime = time; - } - m_lastFrameTime = (time - m_lastTime) * 0.001f; - m_lastTime = time; - if (m_averageFrameTime == 0.0f) - { - m_averageFrameTime = m_lastFrameTime; - } - else - { - m_averageFrameTime = 0.01f * m_lastFrameTime + 0.99f * m_averageFrameTime; - } - - Render(); - - m_updateTimer.start(); -} - -bool ImGuiViewportWidget::event(QEvent* ev) -{ - bool result = QWidget::event(ev); - - if (ev->type() == QEvent::WinIdChange) - { - CreateRenderContext(); - } - - return result; -} - -#include diff --git a/Gems/ImGui/Code/Editor/ImGuiViewport.h b/Gems/ImGui/Code/Editor/ImGuiViewport.h deleted file mode 100644 index 2f7c475395..0000000000 --- a/Gems/ImGui/Code/Editor/ImGuiViewport.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or - * its licensors. - * - * For complete copyright and license terms please see the LICENSE at the root of this - * distribution (the "License"). All use of this software is governed by the License, - * or, if provided, by the license below or the license accompanying this file. Do not - * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * - */ - -#pragma once -#if !defined(Q_MOC_RUN) -#include -#include -#include -#include -#include -#include -#include -#endif - -namespace ImGui -{ - class ImGuiViewportWidget : public QWidget - { - Q_OBJECT - public: - ImGuiViewportWidget(QWidget* parent); - ~ImGuiViewportWidget(); - - void Render(); - - private slots: - void RefreshTick(); - - private: - struct SPreviousContext - { - int width; - int height; - HWND window; - CCamera renderCamera; - CCamera systemCamera; - bool isMainViewport; - }; - - bool CreateRenderContext(); - void DestroyRenderContext(); - void StorePreviousContext(); - void SetCurrentContext(); - void RestorePreviousContext(); - - void resizeEvent(QResizeEvent* ev) override; - bool event(QEvent* ev) override; - - AZStd::stack m_previousContexts; - unsigned int m_width; - unsigned int m_height; - bool m_renderContextCreated; - bool m_creatingRenderContext; - int64 m_lastTime; - float m_lastFrameTime; - float m_averageFrameTime; - AZStd::vector m_vertBuffer; - AZStd::vector m_idxBuffer; - QTimer m_updateTimer; - }; -} diff --git a/Gems/ImGui/Code/imgui_editor_files.cmake b/Gems/ImGui/Code/imgui_editor_files.cmake index 75a98524ae..842fde7965 100644 --- a/Gems/ImGui/Code/imgui_editor_files.cmake +++ b/Gems/ImGui/Code/imgui_editor_files.cmake @@ -10,15 +10,7 @@ # set(FILES - Editor/ImGuiEditorWindowBus.h Editor/ImGuiEditorWindowModule.cpp - Editor/ImGuiEditorWindowSystemComponent.cpp - Editor/ImGuiEditorWindowSystemComponent.h - Editor/ImGuiMainWindow.h - Editor/ImGuiMainWindow.cpp - Editor/ImGuiMainwindow.ui - Editor/ImGuiViewport.h - Editor/ImGuiViewport.cpp Source/ImGuiGem.h Source/ImGuiGem.cpp ) diff --git a/Gems/LmbrCentral/Code/Source/Asset/AssetSystemDebugComponent.cpp b/Gems/LmbrCentral/Code/Source/Asset/AssetSystemDebugComponent.cpp index 70d84dee6f..20ec7627bd 100644 --- a/Gems/LmbrCentral/Code/Source/Asset/AssetSystemDebugComponent.cpp +++ b/Gems/LmbrCentral/Code/Source/Asset/AssetSystemDebugComponent.cpp @@ -72,25 +72,8 @@ namespace LmbrCentral return; } - ISystem* crySystem = GetISystem(); - if (!crySystem) - { - return; - } - - IRenderer* renderer = crySystem->GetIRenderer(); - if (!renderer) - { - return; - } - - IRenderAuxGeom* auxGeom = renderer->GetIRenderAuxGeom(); - if (!auxGeom) - { - return; - } - - float x = 10; + // ToDo: Remove class or update to work with Atom? LYN-3672 + /*float x = 10; float y = 15; ColorF color(1, 1, 1); constexpr bool center = false; @@ -161,7 +144,7 @@ namespace LmbrCentral StatusToString(asset.GetStatus()).c_str(), activeAssetLoadTime.count()); } - } + }*/ } void AssetSystemDebugComponent::AssetStatusUpdate(AZ::Data::AssetId id, AZ::Data::AssetData::AssetStatus status) diff --git a/Gems/LmbrCentral/Code/Source/LmbrCentral.cpp b/Gems/LmbrCentral/Code/Source/LmbrCentral.cpp index 10b3c3a317..d23ce13bfe 100644 --- a/Gems/LmbrCentral/Code/Source/LmbrCentral.cpp +++ b/Gems/LmbrCentral/Code/Source/LmbrCentral.cpp @@ -63,8 +63,6 @@ #include "Unhandled/UI/FontAssetTypeInfo.h" #include "Unhandled/UI/UICanvasAssetTypeInfo.h" -#include - // Asset types #include #include diff --git a/Gems/LyShine/Code/Source/LyShine.cpp b/Gems/LyShine/Code/Source/LyShine.cpp index 3ea451b7c5..bc6a27dac4 100644 --- a/Gems/LyShine/Code/Source/LyShine.cpp +++ b/Gems/LyShine/Code/Source/LyShine.cpp @@ -166,11 +166,6 @@ CLyShine::CLyShine(ISystem* system) UiAnimationSystem::StaticInitialize(); - if (m_system->GetIRenderer()) - { - m_system->GetIRenderer()->AddRenderDebugListener(this); - } - AzFramework::InputChannelEventListener::Connect(); AzFramework::InputTextEventListener::Connect(); UiCursorBus::Handler::BusConnect(); @@ -254,11 +249,6 @@ CLyShine::~CLyShine() AzFramework::InputTextEventListener::Disconnect(); AzFramework::InputChannelEventListener::Disconnect(); - if (m_system->GetIRenderer()) - { - m_system->GetIRenderer()->RemoveRenderDebugListener(this); - } - UiCanvasComponent::Shutdown(); // must be done after UiCanvasComponent::Shutdown diff --git a/Gems/LyShine/Code/Source/UiCanvasManager.cpp b/Gems/LyShine/Code/Source/UiCanvasManager.cpp index 958dba0ab8..e09a6d0efd 100644 --- a/Gems/LyShine/Code/Source/UiCanvasManager.cpp +++ b/Gems/LyShine/Code/Source/UiCanvasManager.cpp @@ -815,7 +815,10 @@ bool UiCanvasManager::HandleInputEventForInWorldCanvases(const AzFramework::Inpu // First we need to construct a ray from the either the center of the screen or the mouse position. // This requires knowledge of the camera // for initial testing we will just use a ray in the center of the viewport - const CCamera& cam = GetISystem()->GetIRenderer()->GetCamera(); + + // ToDo: Re-implement by getting the camera from Atom. LYN-3680 + return false; + const CCamera cam; // construct a ray from the camera position in the view direction of the camera const float rayLength = 5000.0f; diff --git a/Gems/LyShineExamples/Code/Source/UiCustomImageComponent.cpp b/Gems/LyShineExamples/Code/Source/UiCustomImageComponent.cpp index cb33ccac98..1bd2bd10be 100644 --- a/Gems/LyShineExamples/Code/Source/UiCustomImageComponent.cpp +++ b/Gems/LyShineExamples/Code/Source/UiCustomImageComponent.cpp @@ -98,7 +98,7 @@ namespace LyShineExamples { // if there is no texture we will just use a white texture // TODO: Get a default atom texture here when possible - //texture = gEnv->pRenderer->EF_GetTextureByID(gEnv->pRenderer->GetWhiteTextureId()); + //texture = ???->EF_GetTextureByID(???->GetWhiteTextureId()); } if (m_isRenderCacheDirty) diff --git a/Gems/Maestro/Code/Source/Cinematics/AnimScreenFaderNode.cpp b/Gems/Maestro/Code/Source/Cinematics/AnimScreenFaderNode.cpp index ba30c3de39..ca1e73fc65 100644 --- a/Gems/Maestro/Code/Source/Cinematics/AnimScreenFaderNode.cpp +++ b/Gems/Maestro/Code/Source/Cinematics/AnimScreenFaderNode.cpp @@ -348,34 +348,6 @@ bool CAnimScreenFaderNode::GetParamInfoFromType(const CAnimParamType& paramId, S //----------------------------------------------------------------------------- void CAnimScreenFaderNode::Render() { - if (!m_bActive) - { - return; - } - - if (gEnv->pRenderer) - { - size_t const paramCount = m_tracks.size(); - for (size_t paramIndex = 0; paramIndex < paramCount; ++paramIndex) - { - CScreenFaderTrack* pTrack = static_cast(GetTrackForParameter(AnimParamType::ScreenFader, paramIndex)); - - if (!pTrack) - { - continue; - } - - int textureId = -1; - if (pTrack->IsTextureVisible()) - { - textureId = (pTrack->GetActiveTexture() != 0) ? pTrack->GetActiveTexture()->GetTextureID() : -1; - } - - gEnv->pRenderer->SetState(GS_BLSRC_SRCALPHA | GS_BLDST_ONEMINUSSRCALPHA | GS_NODEPTHTEST); - gEnv->pRenderer->Draw2dImage(0, 0, m_screenWidth, m_screenHeight, textureId, 0.0f, 1.0f, 1.0f, 0.0f, 0.f, - pTrack->GetDrawColor().x, pTrack->GetDrawColor().y, pTrack->GetDrawColor().z, pTrack->GetDrawColor().w, 0.f); - } - } } bool CAnimScreenFaderNode::IsAnyTextureVisible() const diff --git a/Gems/Maestro/Code/Source/Cinematics/Movie.cpp b/Gems/Maestro/Code/Source/Cinematics/Movie.cpp index f68ddb2b49..8ee2c68cc4 100644 --- a/Gems/Maestro/Code/Source/Cinematics/Movie.cpp +++ b/Gems/Maestro/Code/Source/Cinematics/Movie.cpp @@ -993,9 +993,6 @@ void CMovieSystem::ShowPlayedSequencesDebug() continue; } - const char* fullname = playingSequence.sequence->GetName(); - gEnv->pRenderer->Draw2dLabel(1.0f, y, 1.3f, green, false, "Sequence %s : %f (x %f)", fullname, playingSequence.currentTime, playingSequence.currentSpeed); - y += 16.0f; for (int i = 0; i < playingSequence.sequence->GetNodeCount(); ++i) @@ -1017,8 +1014,6 @@ void CMovieSystem::ShowPlayedSequencesDebug() { names.push_back(name); } - - gEnv->pRenderer->Draw2dLabel((21.0f + 100.0f * i), ((i % 2) ? (y + 8.0f) : y), 1.0f, alreadyThere ? white : purple, false, "%s", name); } y += 32.0f; diff --git a/Gems/Maestro/Code/Source/Cinematics/ScreenFaderTrack.cpp b/Gems/Maestro/Code/Source/Cinematics/ScreenFaderTrack.cpp index 8b2e615c26..3465b137b1 100644 --- a/Gems/Maestro/Code/Source/Cinematics/ScreenFaderTrack.cpp +++ b/Gems/Maestro/Code/Source/Cinematics/ScreenFaderTrack.cpp @@ -113,12 +113,6 @@ void CScreenFaderTrack::PreloadTextures() GetKey(nKeyIndex, &key); if (!key.m_strTexture.empty()) { - ITexture* pTexture = gEnv->pRenderer->EF_LoadTexture(key.m_strTexture.c_str(), FT_DONT_STREAM | FT_STATE_CLAMP); - if (pTexture) - { - pTexture->SetClamp(true); - m_preloadedTextures.push_back(pTexture); - } } else { diff --git a/Gems/Maestro/Code/Source/MaestroSystemComponent.cpp b/Gems/Maestro/Code/Source/MaestroSystemComponent.cpp index e300607fd7..cd0dfb02b3 100644 --- a/Gems/Maestro/Code/Source/MaestroSystemComponent.cpp +++ b/Gems/Maestro/Code/Source/MaestroSystemComponent.cpp @@ -122,7 +122,7 @@ namespace Maestro /////////////////////////////////////////////////////////////////////////////////////////////// void MaestroSystemComponent::OnCrySystemInitialized(ISystem& system, const SSystemInitParams& startupParams) { - if (!startupParams.bSkipMovie && !startupParams.bShaderCacheGen) + if (!startupParams.bSkipMovie) { // OnCrySystemInitialized should only ever be called once, and we should be the only one initializing gEnv->pMovieSystem AZ_Assert(!m_movieSystemEventListener && gEnv && !gEnv->pMovieSystem, "MaestroSystemComponent::OnCrySystemInitialized - movie system was alread initialized."); diff --git a/Gems/TextureAtlas/Code/Source/TextureAtlasSystemComponent.cpp b/Gems/TextureAtlas/Code/Source/TextureAtlasSystemComponent.cpp index 1fe3e07e61..80d4898c41 100644 --- a/Gems/TextureAtlas/Code/Source/TextureAtlasSystemComponent.cpp +++ b/Gems/TextureAtlas/Code/Source/TextureAtlasSystemComponent.cpp @@ -98,14 +98,16 @@ namespace TextureAtlasNamespace SResourceAsync* pInfo = new SResourceAsync(); pInfo->eClassName = eRCN_Texture; pInfo->pResource = iterator->second.m_atlas->GetTexture(); - gEnv->pRenderer->ReleaseResourceAsync(pInfo); + // ToDo: Update to work with Atom? LYN-3680 + // ???->ReleaseResourceAsync(pInfo); } // Reload Texture AZStd::string imagePath = iterator->second.m_path.substr(0, iterator->second.m_path.find_last_of('.')); imagePath.append(".dds"); - uint32 loadTextureFlags = (FT_USAGE_ALLOWREADSRGB | FT_DONT_STREAM); - ITexture* texture = gEnv->pRenderer->EF_LoadTexture(imagePath.c_str(), loadTextureFlags); + // ToDo: Update to work with Atom? LYN-3680 + // uint32 loadTextureFlags = (FT_USAGE_ALLOWREADSRGB | FT_DONT_STREAM); + ITexture* texture = nullptr; if (!texture || !texture->IsTextureLoaded()) { @@ -189,8 +191,9 @@ namespace TextureAtlasNamespace AzFramework::StringFunc::Path::ReplaceExtension(imagePath, "dds"); // Load the image in - uint32 loadTextureFlags = (FT_USAGE_ALLOWREADSRGB | FT_DONT_STREAM); - ITexture* texture = gEnv->pRenderer->EF_LoadTexture(imagePath.c_str(), loadTextureFlags); + // ToDo: Update to work with Atom? LYN-3680 + // uint32 loadTextureFlags = (FT_USAGE_ALLOWREADSRGB | FT_DONT_STREAM); + ITexture* texture = nullptr; if (!texture || !texture->IsTextureLoaded()) { @@ -241,7 +244,8 @@ namespace TextureAtlasNamespace SResourceAsync* pInfo = new SResourceAsync(); pInfo->eClassName = eRCN_Texture; pInfo->pResource = temp.m_atlas->GetTexture(); - gEnv->pRenderer->ReleaseResourceAsync(pInfo); + // ToDo: Update to work with Atom? LYN-3680 + // ???->ReleaseResourceAsync(pInfo); } // Delete the atlas SAFE_DELETE(temp.m_atlas); diff --git a/Gems/Vegetation/Code/Source/Debugger/DebugComponent.cpp b/Gems/Vegetation/Code/Source/Debugger/DebugComponent.cpp index ec8c929719..099bd2e90c 100644 --- a/Gems/Vegetation/Code/Source/Debugger/DebugComponent.cpp +++ b/Gems/Vegetation/Code/Source/Debugger/DebugComponent.cpp @@ -192,25 +192,8 @@ void DebugComponent::DrawGlobalDebugInfo() void DebugComponent::DrawInstanceDebug() { #if defined(VEG_PROFILE_ENABLED) - ISystem* crySystem = GetISystem(); - if (!crySystem) - { - return; - } - - IRenderer* renderer = crySystem->GetIRenderer(); - if (!renderer) - { - return; - } - - IRenderAuxGeom* renderAuxGeom = renderer->GetIRenderAuxGeom(); - if (!renderAuxGeom) - { - return; - } - - renderAuxGeom->SetRenderFlags(e_Mode3D | e_FillModeSolid | e_CullModeBack | e_DepthWriteOff | e_DepthTestOn); + // ToDo: Re-implement with Atom. LYN-3681 + /*renderAuxGeom->SetRenderFlags(e_Mode3D | e_FillModeSolid | e_CullModeBack | e_DepthWriteOff | e_DepthTestOn); AZStd::unordered_map areaDebugDisplayDataMap; @@ -241,7 +224,7 @@ void DebugComponent::DrawInstanceDebug() AABB bounds(pos - radius, pos + radius); renderAuxGeom->DrawAABB(bounds, true, ColorB(areaDebugDisplayData.m_instanceColor.ToU32()), eBBD_Faceted); - } + }*/ #endif } @@ -922,25 +905,8 @@ void DebugComponent::RemoveConsoleVariables() void DebugComponent::DrawDebugStats() { - ISystem* crySystem = GetISystem(); - if (!crySystem) - { - return; - } - - IRenderer* renderer = crySystem->GetIRenderer(); - if (!renderer) - { - return; - } - - IRenderAuxGeom* renderAuxGeom = renderer->GetIRenderAuxGeom(); - if (!renderAuxGeom) - { - return; - } - - if (!m_debugData) + // ToDo: Re-implement with Atom. LYN-3681 + /*if (!m_debugData) { return; } @@ -961,7 +927,7 @@ void DebugComponent::DrawDebugStats() destroyTaskCount, m_debugData->m_areaTaskQueueCount.load(AZStd::memory_order_relaxed), m_debugData->m_areaTaskActiveCount.load(AZStd::memory_order_relaxed) - ).c_str()); + ).c_str());*/ } void DebugComponent::AddConsoleVariables()