Merge branch 'development' of https://github.com/o3de/o3de into carlitosan/development

This commit is contained in:
chcurran
2021-09-08 11:59:43 -07:00
283 changed files with 2868 additions and 16703 deletions
@@ -17,15 +17,15 @@ if(PAL_TRAIT_BUILD_TESTS_SUPPORTED AND PAL_TRAIT_BUILD_HOST_TOOLS)
return()
endif()
# Enable after installing NodeJS and CDK on jenkins Windows AMI.
ly_add_pytest(
NAME AutomatedTesting::AWSTests
TEST_SUITE periodic
TEST_SUITE awsi
TEST_SERIAL
PATH ${CMAKE_CURRENT_LIST_DIR}/${PAL_PLATFORM_NAME}/
RUNTIME_DEPENDENCIES
Legacy::Editor
AZ::AssetProcessor
AutomatedTesting.GameLauncher
AutomatedTesting.Assets
COMPONENT
AWS
@@ -133,7 +133,7 @@ def update_kinesis_analytics_application_status(aws_metrics_utils: pytest.fixtur
aws_metrics_utils.stop_kinesis_data_analytics_application(
resource_mappings.get_resource_name_id('AWSMetrics.AnalyticsApplicationName'))
@pytest.mark.SUITE_periodic
@pytest.mark.SUITE_awsi
@pytest.mark.usefixtures('automatic_process_killer')
@pytest.mark.usefixtures('aws_credentials')
@pytest.mark.usefixtures('resource_mappings')
@@ -21,7 +21,7 @@ AWS_CLIENT_AUTH_FEATURE_NAME = 'AWSClientAuth'
logger = logging.getLogger(__name__)
@pytest.mark.SUITE_periodic
@pytest.mark.SUITE_awsi
@pytest.mark.usefixtures('asset_processor')
@pytest.mark.usefixtures('automatic_process_killer')
@pytest.mark.usefixtures('aws_utils')
@@ -74,7 +74,7 @@ def write_test_data_to_dynamodb_table(resource_mappings: pytest.fixture, aws_uti
raise
@pytest.mark.SUITE_periodic
@pytest.mark.SUITE_awsi
@pytest.mark.usefixtures('automatic_process_killer')
@pytest.mark.usefixtures('asset_processor')
@pytest.mark.parametrize('feature_name', [AWS_CORE_FEATURE_NAME])
@@ -7,8 +7,10 @@ SPDX-License-Identifier: Apache-2.0 OR MIT
Tests that require a GPU in order to run.
"""
import datetime
import logging
import os
import zipfile
import pytest
@@ -40,6 +42,33 @@ def golden_images_directory():
return golden_images_dir
def create_screenshots_archive(screenshot_path):
"""
Creates a new zip file archive at archive_path containing all files listed within archive_path.
:param screenshot_path: location containing the files to archive, the zip archive file will also be saved here.
:return: None, but creates a new zip file archive inside path containing all of the files inside archive_path.
"""
files_to_archive = []
# Search for .png and .ppm files to add to the zip archive file.
for (folder_name, sub_folders, file_names) in os.walk(screenshot_path):
for file_name in file_names:
if file_name.endswith(".png") or file_name.endswith(".ppm"):
file_path = os.path.join(folder_name, file_name)
files_to_archive.append(file_path)
# Setup variables for naming the zip archive file.
timestamp = datetime.datetime.now().timestamp()
formatted_timestamp = datetime.datetime.utcfromtimestamp(timestamp).strftime("%Y-%m-%d_%H-%M-%S")
screenshots_file = os.path.join(screenshot_path, f'zip_archive_{formatted_timestamp}.zip')
# Write all of the valid .png and .ppm files to the archive file.
with zipfile.ZipFile(screenshots_file, 'w', compression=zipfile.ZIP_DEFLATED, allowZip64=True) as zip_archive:
for file_path in files_to_archive:
file_name = os.path.basename(file_path)
zip_archive.write(file_path, file_name)
@pytest.mark.parametrize("project", ["AutomatedTesting"])
@pytest.mark.parametrize("launcher_platform", ["windows_editor"])
@pytest.mark.parametrize("level", ["auto_test"])
@@ -53,8 +82,8 @@ class TestAllComponentsIndepthTests(object):
Tests that a basic rendering level setup can be created (lighting, meshes, materials, etc.).
"""
# Clear existing test screenshots before starting test.
test_screenshots = [os.path.join(
workspace.paths.project(), DEFAULT_SUBFOLDER_PATH, screenshot_name)]
screenshot_directory = os.path.join(workspace.paths.project(), DEFAULT_SUBFOLDER_PATH)
test_screenshots = [os.path.join(screenshot_directory, screenshot_name)]
file_system.delete(test_screenshots, True, True)
golden_images = [os.path.join(golden_images_directory(), screenshot_name)]
@@ -86,6 +115,8 @@ class TestAllComponentsIndepthTests(object):
for test_screenshot, golden_screenshot in zip(test_screenshots, golden_images):
compare_screenshots(test_screenshot, golden_screenshot)
create_screenshots_archive(screenshot_directory)
def test_LightComponent_ScreenshotMatchesGoldenImage(
self, request, editor, workspace, project, launcher_platform, level):
"""
@@ -105,9 +136,10 @@ class TestAllComponentsIndepthTests(object):
"SpotLight_5.ppm",
"SpotLight_6.ppm",
]
screenshot_directory = os.path.join(workspace.paths.project(), DEFAULT_SUBFOLDER_PATH)
test_screenshots = []
for screenshot in screenshot_names:
screenshot_path = os.path.join(workspace.paths.project(), DEFAULT_SUBFOLDER_PATH, screenshot)
screenshot_path = os.path.join(screenshot_directory, screenshot)
test_screenshots.append(screenshot_path)
file_system.delete(test_screenshots, True, True)
@@ -139,6 +171,8 @@ class TestAllComponentsIndepthTests(object):
for test_screenshot, golden_screenshot in zip(test_screenshots, golden_images):
compare_screenshots(test_screenshot, golden_screenshot)
create_screenshots_archive(screenshot_directory)
@pytest.mark.parametrize('rhi', ['dx12', 'vulkan'])
@pytest.mark.parametrize("project", ["AutomatedTesting"])
+3 -12
View File
@@ -236,10 +236,7 @@ QString CEditorCommandManager::Execute(const AZStd::string& module, const AZStd:
}
else
{
QString errMsg;
errMsg = QStringLiteral("Error: Trying to execute a unknown command, '%1'!").arg(fullName.c_str());
CryLogAlways(errMsg.toUtf8().data());
CryLogAlways("Error: Trying to execute a unknown command, '%s'!", fullName.c_str());
}
return "";
@@ -272,10 +269,7 @@ QString CEditorCommandManager::Execute(const AZStd::string& cmdLine)
}
else
{
QString errMsg;
errMsg = QStringLiteral("Error: Trying to execute a unknown command, '%1'!").arg(cmdLine.c_str());
CryLogAlways(errMsg.toUtf8().data());
CryLogAlways("Error: Trying to execute a unknown command, '%s'!", cmdLine.c_str());
}
return "";
@@ -294,10 +288,7 @@ void CEditorCommandManager::Execute(int commandId)
}
else
{
QString errMsg;
errMsg = QStringLiteral("Error: Trying to execute a unknown command of ID '%1'!").arg(commandId);
CryLogAlways(errMsg.toUtf8().data());
CryLogAlways("Error: Trying to execute a unknown command of ID '%d'!", commandId);
}
}
+1 -1
View File
@@ -36,7 +36,7 @@ void CConsoleDialog::SetInfoText(const char* text)
{
if (gEnv && gEnv->pLog) // before log system was initialized
{
CryLogAlways(text);
CryLogAlways("%s", text);
}
}
+3 -7
View File
@@ -26,9 +26,6 @@
#include <AzQtComponents/Components/Widgets/ScrollBar.h>
#include <AzQtComponents/Components/Widgets/SliderCombo.h>
// CryCommon
#include <CryCommon/SFunctor.h>
// Editor
#include "QtViewPaneManager.h"
#include "Core/QtEditorApplication.h"
@@ -392,7 +389,7 @@ void CConsoleSCB::RegisterViewClass()
opts.showInMenu = true;
opts.builtInActionId = ID_VIEW_CONSOLEWINDOW;
opts.shortcut = QKeySequence(Qt::Key_QuoteLeft);
AzToolsFramework::RegisterViewPane<CConsoleSCB>(LyViewPane::Console, LyViewPane::CategoryTools, opts);
}
@@ -606,8 +603,7 @@ static CVarBlock* VarBlockFromConsoleVars()
// Add our on change handler so we can update the CVariable created for
// the matching ICVar that has been modified
SFunctor onChange;
onChange.Set(OnVariableUpdated, i, pCVar);
AZStd::function<void()> onChange = [row=i,pCVar=pCVar]() { OnVariableUpdated(row,pCVar); };
pCVar->AddOnChangeFunctor(onChange);
pVariable->SetDescription(pCVar->GetHelp());
@@ -929,7 +925,7 @@ QWidget* ConsoleVariableItemDelegate::createEditor(QWidget* parent, const QStyle
return editor;
}
}
// If we get here, value being edited is a string, so use our styled line
// edit widget
AzQtComponents::StyledLineEdit* lineEdit = new AzQtComponents::StyledLineEdit(parent);
-10
View File
@@ -1887,16 +1887,6 @@ void CCryEditDoc::SetDocumentReady(bool bReady)
m_bDocumentReady = bReady;
}
void CCryEditDoc::GetMemoryUsage(ICrySizer* pSizer) const
{
{
SIZER_COMPONENT_NAME(pSizer, "UndoManager(estimate)");
GetIEditor()->GetUndoManager()->GetMemoryUsage(pSizer);
}
pSizer->Add(*this);
}
void CCryEditDoc::RegisterConsoleVariables()
{
doc_validate_surface_types = gEnv->pConsole->GetCVar("doc_validate_surface_types");
-2
View File
@@ -129,8 +129,6 @@ public: // Create from serialization only
void RegisterListener(IDocListener* listener);
void UnregisterListener(IDocListener* listener);
void GetMemoryUsage(ICrySizer* pSizer) const;
static bool IsBackupOrTempLevelSubdirectory(const QString& folderName);
protected:
+2
View File
@@ -1087,6 +1087,7 @@ void EditorViewportWidget::ConnectViewportInteractionRequestBus()
{
AzToolsFramework::ViewportInteraction::ViewportFreezeRequestBus::Handler::BusConnect(GetViewportId());
AzToolsFramework::ViewportInteraction::MainEditorViewportInteractionRequestBus::Handler::BusConnect(GetViewportId());
AzToolsFramework::ViewportInteraction::EditorEntityViewportInteractionRequestBus::Handler::BusConnect(GetViewportId());
m_viewportUi.ConnectViewportUiBus(GetViewportId());
AzFramework::InputSystemCursorConstraintRequestBus::Handler::BusConnect();
@@ -1097,6 +1098,7 @@ void EditorViewportWidget::DisconnectViewportInteractionRequestBus()
AzFramework::InputSystemCursorConstraintRequestBus::Handler::BusDisconnect();
m_viewportUi.DisconnectViewportUiBus();
AzToolsFramework::ViewportInteraction::EditorEntityViewportInteractionRequestBus::Handler::BusDisconnect();
AzToolsFramework::ViewportInteraction::MainEditorViewportInteractionRequestBus::Handler::BusDisconnect();
AzToolsFramework::ViewportInteraction::ViewportFreezeRequestBus::Handler::BusDisconnect();
}
+17 -11
View File
@@ -91,6 +91,7 @@ class SANDBOX_API EditorViewportWidget final
, private AzFramework::InputSystemCursorConstraintRequestBus::Handler
, private AzToolsFramework::ViewportInteraction::ViewportFreezeRequestBus::Handler
, private AzToolsFramework::ViewportInteraction::MainEditorViewportInteractionRequestBus::Handler
, private AzToolsFramework::ViewportInteraction::EditorEntityViewportInteractionRequestBus::Handler
, private AzFramework::AssetCatalogEventBus::Handler
, private AZ::RPI::SceneNotificationBus::Handler
{
@@ -128,10 +129,12 @@ private:
CameraComponent,
ViewSourceTypesCount,
};
enum class PlayInEditorState
{
Editor, Starting, Started
};
enum class KeyPressedState
{
AllUp,
@@ -142,7 +145,7 @@ private:
////////////////////////////////////////////////////////////////////////
// Method overrides ...
// QWidget
// QWidget overrides ...
void focusOutEvent(QFocusEvent* event) override;
void keyPressEvent(QKeyEvent* event) override;
bool event(QEvent* event) override;
@@ -150,7 +153,7 @@ private:
void paintEvent(QPaintEvent* event) override;
void mousePressEvent(QMouseEvent* event) override;
// QtViewport/IDisplayViewport/CViewport
// QtViewport/IDisplayViewport/CViewport overrides ...
EViewportType GetType() const override { return ET_ViewportCamera; }
void SetType([[maybe_unused]] EViewportType type) override { assert(type == ET_ViewportCamera); };
AzToolsFramework::ViewportInteraction::MouseInteraction BuildMouseInteraction(
@@ -176,16 +179,17 @@ private:
void Update() override;
void UpdateContent(int flags) override;
// SceneNotificationBus
// SceneNotificationBus overrides ...
void OnBeginPrepareRender() override;
// Camera::CameraNotificationBus
// Camera::CameraNotificationBus overrides ...
void OnActiveViewChanged(const AZ::EntityId&) override;
// IEditorEventListener
// IEditorEventListener overrides ...
void OnEditorNotifyEvent(EEditorNotifyEvent event) override;
// AzToolsFramework::EditorEntityContextNotificationBus (handler moved to cpp to resolve link issues in unity builds)
// AzToolsFramework::EditorEntityContextNotificationBus overrides ...
// note: handler moved to cpp to resolve link issues in unity builds
void OnStartPlayInEditor();
void OnStopPlayInEditor();
void OnStartPlayInEditorBegin();
@@ -194,10 +198,10 @@ private:
void BeginUndoTransaction() override;
void EndUndoTransaction() override;
// AzFramework::InputSystemCursorConstraintRequestBus
// AzFramework::InputSystemCursorConstraintRequestBus overrides ...
void* GetSystemCursorConstraintWindow() const override;
// AzToolsFramework::ViewportFreezeRequestBus
// AzToolsFramework::ViewportFreezeRequestBus overrides ...
bool IsViewportInputFrozen() override;
void FreezeViewportInput(bool freeze) override;
@@ -205,13 +209,15 @@ private:
AZ::EntityId PickEntity(const AzFramework::ScreenPoint& point) override;
AZ::Vector3 PickTerrain(const AzFramework::ScreenPoint& point) override;
float TerrainHeight(const AZ::Vector2& position) override;
void FindVisibleEntities(AZStd::vector<AZ::EntityId>& visibleEntitiesOut) override;
bool ShowingWorldSpace() override;
QWidget* GetWidgetForViewportContextMenu() override;
void BeginWidgetContext() override;
void EndWidgetContext() override;
// Camera::EditorCameraRequestBus
// EditorEntityViewportInteractionRequestBus overrides ...
void FindVisibleEntities(AZStd::vector<AZ::EntityId>& visibleEntities) override;
// Camera::EditorCameraRequestBus overrides ...
void SetViewFromEntityPerspective(const AZ::EntityId& entityId) override;
void SetViewAndMovementLockFromEntityPerspective(const AZ::EntityId& entityId, bool lockCameraMovement) override;
AZ::EntityId GetCurrentViewEntityId() override;
@@ -327,7 +333,7 @@ private:
// Determines also if the current camera for this viewport is default editor camera
ViewSourceType m_viewSourceType = ViewSourceType::None;
// During play game in editor, holds the editor entity ID of the last
// During play game in editor, holds the editor entity ID of the last
AZ::EntityId m_viewEntityIdCachedForEditMode;
// The editor camera TM before switching to game mode
-54
View File
@@ -249,60 +249,6 @@ void CErrorReport::SetImmediateMode(bool bEnable)
}
}
//////////////////////////////////////////////////////////////////////////
void CErrorReport::Report(SValidatorRecord& record)
{
if ((record.flags & VALIDATOR_FLAG_IGNORE_IN_EDITOR))
{
return;
}
CErrorRecord err;
if (record.text)
{
err.error = record.text;
}
if (record.description)
{
err.description = record.description;
}
if (record.file)
{
err.file = record.file;
}
else
{
err.file = m_currentFilename;
}
err.severity = (CErrorRecord::ESeverity)record.severity;
err.assetScope = record.assetScope;
err.flags = 0;
if (record.flags & VALIDATOR_FLAG_FILE)
{
err.flags |= CErrorRecord::FLAG_NOFILE;
}
if (record.flags & VALIDATOR_FLAG_TEXTURE)
{
err.flags |= CErrorRecord::FLAG_TEXTURE;
}
if (record.flags & VALIDATOR_FLAG_SCRIPT)
{
err.flags |= CErrorRecord::FLAG_SCRIPT;
}
if (record.flags & VALIDATOR_FLAG_AI)
{
err.flags |= CErrorRecord::FLAG_AI;
}
err.module = record.module;
err.pObject = m_pObject;
err.pItem = m_pItem;
ReportError(err);
}
//////////////////////////////////////////////////////////////////////////
void CErrorReport::SetCurrentValidatorObject(CBaseObject* pObject)
{
-5
View File
@@ -121,11 +121,6 @@ public:
//! Assign current filename.
void SetCurrentFile(const QString& file);
//////////////////////////////////////////////////////////////////////////
// Implement IValidator interface.
//////////////////////////////////////////////////////////////////////////
virtual void Report(SValidatorRecord& record);
private:
//! Array of all error records added to report.
std::vector<CErrorRecord> m_errors;
-5
View File
@@ -176,11 +176,6 @@ struct SSystemUserCallback
return CryMessageBox(text, caption, uType);
}
void GetMemoryUsage(ICrySizer* pSizer) override
{
GetIEditor()->GetMemoryUsage(pSizer);
}
void OnSplashScreenDone()
{
m_pLogo = nullptr;
+1 -7
View File
@@ -5,10 +5,6 @@
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#ifndef CRYINCLUDE_EDITOR_GAMEEXPORTER_H
#define CRYINCLUDE_EDITOR_GAMEEXPORTER_H
#pragma once
#include "Util/PakFile.h"
@@ -62,7 +58,7 @@ public:
// In auto exporting mode, highest possible settings will be chosen and no UI dialogs will be shown.
void SetAutoExportMode(bool bAuto) { m_bAutoExportMode = bAuto; }
bool Export(unsigned int flags = 0, EEndian eExportEndian = GetPlatformEndian(), const char* subdirectory = 0);
bool Export(unsigned int flags = 0, EEndian eExportEndian = eEndianness_Little, const char* subdirectory = 0);
static CGameExporter* GetCurrentExporter() { return m_pCurrentExporter; }
@@ -116,5 +112,3 @@ void SetupTerrainInfo(const size_t octreeCompiledDataSize, Func&& setupTerrainFn
setupTerrainFn(octreeCompiledDataSize);
}
}
#endif // CRYINCLUDE_EDITOR_GAMEEXPORTER_H
-1
View File
@@ -701,7 +701,6 @@ struct IEditor
virtual CUIEnumsDatabase* GetUIEnumsDatabase() = 0;
virtual void AddUIEnums() = 0;
virtual void GetMemoryUsage(ICrySizer* pSizer) = 0;
virtual void ReduceMemory() = 0;
//! Export manager for exporting objects and a terrain from the game to DCC tools
-12
View File
@@ -1506,18 +1506,6 @@ void CEditorImpl::ShowStatusText(bool bEnable)
m_bShowStatusText = bEnable;
}
void CEditorImpl::GetMemoryUsage(ICrySizer* pSizer)
{
SIZER_COMPONENT_NAME(pSizer, "Editor");
if (GetDocument())
{
SIZER_COMPONENT_NAME(pSizer, "Document");
GetDocument()->GetMemoryUsage(pSizer);
}
}
void CEditorImpl::ReduceMemory()
{
GetIEditor()->GetUndoManager()->ClearRedoStack();
-1
View File
@@ -280,7 +280,6 @@ public:
void SetMatEditMode(bool bIsMatEditMode);
CUIEnumsDatabase* GetUIEnumsDatabase() { return m_pUIEnumsDatabase; };
void AddUIEnums();
void GetMemoryUsage(ICrySizer* pSizer);
void ReduceMemory();
// Get Export manager
IExportManager* GetExportManager();
+1 -4
View File
@@ -64,10 +64,7 @@ void CIconManager::Reset()
int i;
for (i = 0; i < sizeof(m_objects) / sizeof(m_objects[0]); i++)
{
if (m_objects[i])
{
m_objects[i]->Release();
}
delete m_objects[i];
m_objects[i] = nullptr;
}
for (i = 0; i < eIcon_COUNT; i++)
+6 -7
View File
@@ -24,16 +24,15 @@ inline AZStd::string ToString(const QString& s)
class CCommand
{
static inline bool FromString(int32 &val, const char* s) {
if(!s)
static inline bool FromString(int32& val, const char* s)
{
if (!s)
{
return false;
}
val = (int)strtol(s, nullptr, 10);
if(val==0 && errno!=0) {
return false;
}
return true;
val = static_cast<int>(strtol(s, nullptr, 10));
const bool parsing_error = val == 0 && errno != 0;
return !parsing_error;
}
public:
CCommand(
+1 -1
View File
@@ -15,6 +15,6 @@ struct IEditorMaterial
: public CBaseLibraryItem
{
virtual int GetFlags() const = 0;
virtual _smart_ptr<IMaterial> GetMatInfo(bool bUseExistingEngineMaterial = false) = 0;
virtual IMaterial* GetMatInfo(bool bUseExistingEngineMaterial = false) = 0;
virtual void DisableHighlightForFrame() = 0;
};
+1 -1
View File
@@ -19,7 +19,7 @@
struct IEditorMaterialManager
{
virtual void GotoMaterial(_smart_ptr<IMaterial> pMaterial) = 0;
virtual void GotoMaterial(IMaterial* pMaterial) = 0;
};
#endif // CRYINCLUDE_EDITOR_MATERIAL_MATERIALMANAGER_H
+1 -14
View File
@@ -9,23 +9,18 @@
// Description : Class that collects error reports to present them later.
#ifndef CRYINCLUDE_EDITOR_INTERFACE_ERRORREPORT_H
#define CRYINCLUDE_EDITOR_INTERFACE_ERRORREPORT_H
#pragma once
#include <IValidator.h>
// forward declarations.
class CParticleItem;
class CBaseObject;
class CBaseLibraryItem;
class CErrorRecord;
class QString;
/*! Error report manages collection of errors occurred during map analyzes or level load.
*/
struct IErrorReport
: public IValidator
{
virtual ~IErrorReport(){}
@@ -62,12 +57,4 @@ struct IErrorReport
//! Assign current filename.
virtual void SetCurrentFile(const QString& file) = 0;
//////////////////////////////////////////////////////////////////////////
// Implement IValidator interface.
//////////////////////////////////////////////////////////////////////////
virtual void Report(SValidatorRecord& record) = 0;
};
#endif // CRYINCLUDE_EDITOR_ERRORREPORT_H
-1
View File
@@ -89,7 +89,6 @@ public:
//! Get array of objects, managed by manager (not contain sub objects of groups).
//! @param layer if 0 get objects for all layers, or layer to get objects from.
virtual void GetObjects(CBaseObjectsArray& objects) const = 0;
//virtual void GetObjects(DynArray<CBaseObject*>& objects) const = 0;
//! Get array of objects that pass the filter.
//! @param filter The filter functor, return true if you want to get the certain obj, return false if want to skip it.
-1
View File
@@ -170,7 +170,6 @@ public:
MOCK_METHOD0(IsSourceControlConnected, bool());
MOCK_METHOD0(GetUIEnumsDatabase, CUIEnumsDatabase* ());
MOCK_METHOD0(AddUIEnums, void());
MOCK_METHOD1(GetMemoryUsage, void(ICrySizer* ));
MOCK_METHOD0(ReduceMemory, void());
MOCK_METHOD0(GetExportManager, IExportManager* ());
MOCK_METHOD2(SetEditorConfigSpec, void(ESystemConfigSpec , ESystemConfigPlatform ));
+3 -3
View File
@@ -67,7 +67,7 @@ SANDBOX_API void ErrorV(const char* format, va_list argList)
str += szBuffer;
//CLogFile::WriteLine( str );
CryWarning(VALIDATOR_MODULE_EDITOR, VALIDATOR_ERROR, str.toUtf8().data());
CryWarning(VALIDATOR_MODULE_EDITOR, VALIDATOR_ERROR, "%s", str.toUtf8().data());
if (!CCryEditApp::instance()->IsInTestMode() && !CCryEditApp::instance()->IsInExportMode() && !CCryEditApp::instance()->IsInLevelLoadTestMode())
{
@@ -95,7 +95,7 @@ SANDBOX_API void WarningV(const char* format, va_list argList)
char szBuffer[MAX_LOGBUFFER_SIZE];
azvsnprintf(szBuffer, MAX_LOGBUFFER_SIZE, format, argList);
CryWarning(VALIDATOR_MODULE_EDITOR, VALIDATOR_WARNING, szBuffer);
CryWarning(VALIDATOR_MODULE_EDITOR, VALIDATOR_WARNING, "%s", szBuffer);
bool bNoUI = false;
ICVar* pCVar = gEnv->pConsole->GetCVar("sys_no_crash_dialog");
@@ -478,7 +478,7 @@ void CLogFile::WriteString(const char* pszString)
{
if (gEnv && gEnv->pLog)
{
gEnv->pLog->LogPlus(pszString);
gEnv->pLog->LogPlus("%s", pszString);
}
}
+2 -2
View File
@@ -2735,7 +2735,7 @@ bool CBaseObject::IntersectRayMesh(const Vec3& raySrc, const Vec3& rayDir, SRayH
return false;
}
Matrix34A worldTM;
Matrix34 worldTM;
IStatObj* pStatObj = pRenderNode->GetEntityStatObj(0, 0, &worldTM);
if (!pStatObj)
{
@@ -2743,7 +2743,7 @@ bool CBaseObject::IntersectRayMesh(const Vec3& raySrc, const Vec3& rayDir, SRayH
}
// transform decal into object space
Matrix34A worldTM_Inverted = worldTM.GetInverted();
Matrix34 worldTM_Inverted = worldTM.GetInverted();
Matrix33 worldRot(worldTM_Inverted);
worldRot.Transpose();
// put hit direction into the object space
+1 -12
View File
@@ -709,7 +709,7 @@ void CObjectManager::ShowDuplicationMsgWarning(CBaseObject* obj, const QString&
);
// If id is taken.
CryWarning(VALIDATOR_MODULE_EDITOR, VALIDATOR_WARNING, sRenameWarning.toUtf8().data());
CryWarning(VALIDATOR_MODULE_EDITOR, VALIDATOR_WARNING, "%s", sRenameWarning.toUtf8().data());
if (bShowMsgBox)
{
@@ -759,17 +759,6 @@ void CObjectManager::GetObjects(CBaseObjectsArray& objects) const
}
}
//void CObjectManager::GetObjects(DynArray<CBaseObject*>& objects) const
//{
// CBaseObjectsArray objectArray;
// GetObjects(objectArray);
// objects.clear();
// for (size_t i = 0, iCount(objectArray.size()); i < iCount; ++i)
// {
// objects.push_back(objectArray[i]);
// }
//}
void CObjectManager::GetObjects(CBaseObjectsArray& objects, BaseObjectFilterFunctor const& filter) const
{
objects.clear();
-1
View File
@@ -122,7 +122,6 @@ public:
//! Get array of objects, managed by manager (not contain sub objects of groups).
//! @param layer if 0 get objects for all layers, or layer to get objects from.
void GetObjects(CBaseObjectsArray& objects) const;
//void GetObjects(DynArray<CBaseObject*>& objects) const;
//! Get array of objects that pass the filter.
//! @param filter The filter functor, return true if you want to get the certain obj, return false if want to skip it.
@@ -37,7 +37,6 @@
#include <AzToolsFramework/ToolsComponents/EditorEntityIconComponentBus.h>
#include <AzToolsFramework/Undo/UndoCacheInterface.h>
#include <LmbrCentral/Rendering/RenderNodeBus.h>
#include <LmbrCentral/Rendering/MaterialOwnerBus.h>
#include <IDisplayViewport.h>
#include <CryCommon/Cry_GeoIntersect.h>
+1 -5
View File
@@ -24,11 +24,7 @@ PLUGIN_API IPlugin* CreatePluginInstance(PLUGIN_INIT_PARAM* pInitParam)
// Make sure the ffmpeg command can be executed before registering the command
if (!CFFMPEGPlugin::RuntimeTest())
{
AZStd::string msg =
"FFMPEG plugin: Failed to execute FFmepg. Please run Setup Assistant, "
"go to the 'Optional software' section of the 'Install software' tab, "
"and make sure the FFmpeg executable is correctly configured.";
GetIEditor()->GetSystem()->GetILog()->Log(msg.c_str());
GetIEditor()->GetSystem()->GetILog()->Log("FFMPEG plugin: Failed to execute FFmpeg. Please install FFmpeg.");
}
else
{
+1 -1
View File
@@ -313,7 +313,7 @@ namespace
{
if (strcmp(pMessage, "") != 0)
{
CryLogAlways(pMessage);
CryLogAlways("%s", pMessage);
}
}
@@ -719,8 +719,7 @@ bool CSequenceBatchRenderDialog::GetResolutionFromCustomResText(const char* cust
int scannedWidth = retCustomWidth; // initialize with default fall-back values - they'll be overwritten in the case of a succesful sscanf below.
int scannedHeight = retCustomHeight;
QString strFormat = QString::fromLatin1(customResFormat).replace(QRegularExpression(QStringLiteral("%\\d")), QStringLiteral("%d"));
scanSuccess = (azsscanf(customResText, strFormat.toStdString().c_str(), &scannedWidth, &scannedHeight) == 2);
scanSuccess = (azsscanf(customResText, "Custom(%d x %d)...", &scannedWidth, &scannedHeight) == 2);
if (scanSuccess)
{
retCustomWidth = scannedWidth;
-36
View File
@@ -62,17 +62,6 @@ public:
}
}
// to get memory statistics
void GetMemoryUsage(ICrySizer* pSizer)
{
for (int i = 0; i < m_undoSteps.size(); i++)
{
m_undoSteps[i]->GetMemoryUsage(pSizer);
}
pSizer->Add(*this);
}
private:
//! Undo steps included in this step.
std::vector<CUndoStep*> m_undoSteps;
@@ -746,31 +735,6 @@ int CUndoManager::GetMaxUndoStep() const
return GetIEditor()->GetEditorSettings()->undoLevels;
}
void CUndoManager::GetMemoryUsage(ICrySizer* pSizer)
{
if (m_currentUndo)
{
m_currentUndo->GetMemoryUsage(pSizer);
}
if (m_superUndo)
{
m_superUndo->GetMemoryUsage(pSizer);
}
for (std::list<CUndoStep*>::const_iterator it = m_undoStack.begin(); it != m_undoStack.end(); it++)
{
(*it)->GetMemoryUsage(pSizer);
}
for (std::list<CUndoStep*>::const_iterator it = m_redoStack.begin(); it != m_redoStack.end(); it++)
{
(*it)->GetMemoryUsage(pSizer);
}
pSizer->Add(*this);
}
void CUndoManager::AddListener(IUndoManagerListener* pListener)
{
stl::push_back_unique(m_listeners, pListener);
+1 -18
View File
@@ -12,9 +12,9 @@
#pragma once
#include "IUndoManagerListener.h"
#include "CrySizer.h" // ICrySizer
#include "IUndoObject.h"
#include <AzCore/Asset/AssetManager.h>
#include <CryCommon/StlUtils.h>
struct IUndoObject;
class CSuperUndoStep;
@@ -79,20 +79,6 @@ public:
}
}
// to get memory statistics
void GetMemoryUsage(ICrySizer* pSizer)
{
size_t nThisSize = sizeof(*this);
for (int i = 0; i < m_undoObjects.size(); i++)
{
nThisSize += m_undoObjects[i]->GetSize();
}
pSizer->Add(m_name);
pSizer->Add(this, nThisSize);
}
// get undo object at index i
IUndoObject* GetUndoObject(int i = 0)
{
@@ -241,9 +227,6 @@ public:
void ClearUndoStack(int num);
void ClearRedoStack(int num);
// to get memory statistics
void GetMemoryUsage(ICrySizer* pSizer);
void AddListener(IUndoManagerListener* pListener);
void RemoveListener(IUndoManagerListener* pListener);
-3
View File
@@ -20,9 +20,6 @@
#include <Cry_Color.h>
#include <CryCommon/ISystem.h>
//! Typedef for quaternion.
//typedef CryQuat Quat;
#include <QColor>
#include <QDataStream>
#include <QGuiApplication>
+1 -1
View File
@@ -52,7 +52,7 @@ bool CImageASC::Save(const QString& fileName, const CFloatImage& image)
}
// First print the file header
fprintf(file, fileHeader.c_str());
fprintf(file, "%s", fileHeader.c_str());
// Then print all the pixels.
for (uint32 y = 0; y < height; y++)
+1 -1
View File
@@ -103,7 +103,7 @@ bool CImageUtil::SavePGM(const QString& fileName, const CImageEx& image)
}
// First print the file header
fprintf(file, fileHeader.c_str());
fprintf(file, "%s", fileHeader.c_str());
// Then print all the pixels.
for (uint32 y = 0; y < height; y++)
+1 -1
View File
@@ -37,7 +37,7 @@ public:
struct SStatObj
{
Matrix34 tm;
_smart_ptr<IStatObj> pStatObj;
IStatObj* pStatObj;
};
private:
+1 -1
View File
@@ -78,7 +78,7 @@ bool CMemoryBlock::Allocate(int size, int uncompressedSize)
{
QString str;
str = QStringLiteral("CMemoryBlock::Allocate failed to allocate %1Mb of Memory").arg(size / (1024 * 1024));
CryLogAlways(str.toUtf8().data());
CryLogAlways("%s", str.toUtf8().data());
QMessageBox::critical(QApplication::activeWindow(), QString(), str + QString("\r\nSandbox will try to reduce its working memory set to free memory for this allocation."));
GetIEditor()->ReduceMemory();
+2 -3
View File
@@ -1092,9 +1092,8 @@ bool QtViewport::HitTest(const QPoint& point, HitContext& hitInfo)
const int viewportId = GetViewportId();
AzToolsFramework::EntityIdList visibleEntityIds;
AzToolsFramework::ViewportInteraction::MainEditorViewportInteractionRequestBus::Event(
viewportId,
&AzToolsFramework::ViewportInteraction::MainEditorViewportInteractionRequests::FindVisibleEntities,
AzToolsFramework::ViewportInteraction::EditorEntityViewportInteractionRequestBus::Event(
viewportId, &AzToolsFramework::ViewportInteraction::EditorEntityViewportInteractionRequestBus::Events::FindVisibleEntities,
visibleEntityIds);
// Look through all visible entities to find the closest one to the specified mouse point
@@ -18,7 +18,7 @@ namespace AZ
{
void OutputToDebugger([[maybe_unused]] const char* window, [[maybe_unused]] const char* message)
{
__android_log_print(ANDROID_LOG_INFO, window, message);
__android_log_print(ANDROID_LOG_INFO, window, "%s", message);
}
}
}
@@ -14,6 +14,7 @@
#include <AzCore/Math/Vector2.h>
#include <AzCore/Math/Vector3.h>
#include <AzCore/Math/Vector4.h>
#include <AzCore/Math/Matrix3x4.h>
#include <AzCore/Math/Color.h>
#include <AzCore/Math/Transform.h>
#include <AzCore/Component/ComponentBus.h>
@@ -100,6 +101,8 @@ namespace AzFramework
virtual AZ::u32 SetState(AZ::u32 state) { (void)state; return 0; }
virtual void PushMatrix(const AZ::Transform& tm) { (void)tm; }
virtual void PopMatrix() {}
virtual void PushPremultipliedMatrix(const AZ::Matrix3x4& matrix) { (void)matrix; }
virtual AZ::Matrix3x4 PopPremultipliedMatrix() { return AZ::Matrix3x4::CreateIdentity(); }
protected:
~DebugDisplayRequests() = default;
@@ -311,7 +311,6 @@ namespace AzFramework
// On some platforms, threadid is just a number but on other platforms it is a pointer of some kind
// uintptr_t will ensure that the data will always fit
uintptr_t threadID = threadId ? threadId : (uintptr_t)(AZStd::this_thread::get_id().m_id);
const char* printFormatter = m_machineReadable ? "~~%p~~%s~~" : "{%p}[%14s]";
// while it may be tempting to check the fileio Pointer here, any emit of any warning or error would be fatal
// since we're already logging, and we don't want to log while you log.
@@ -331,7 +330,14 @@ namespace AzFramework
azsnprintf(buffer, 80, "~~%llu~~%i", rawTime, severity);
m_fileIO->Write(m_fileHandle, buffer, strlen(buffer));
azsnprintf(buffer, 80, printFormatter, threadID, categoryActual);
if (m_machineReadable) // Branching instead of using a ternary on the format string to avoid warning 4774 (format literal expected)
{
azsnprintf(buffer, 80, "~~%p~~%s~~", reinterpret_cast<void*>(threadID), categoryActual);
}
else
{
azsnprintf(buffer, 80, "{%p}[%14s]", reinterpret_cast<void*>(threadID), categoryActual);
}
m_fileIO->Write(m_fileHandle, buffer, strlen(buffer));
m_fileIO->Write(m_fileHandle, dataSource, dataLength);
@@ -349,8 +355,14 @@ namespace AzFramework
{
return;
}
azsnprintf(categorybuffer, 64, printFormatter, threadID, categoryActual);
if (m_machineReadable) // Branching instead of using a ternary on the format string to avoid warning 4774 (format literal expected)
{
azsnprintf(categorybuffer, 64, "~~%p~~%s~~", reinterpret_cast<void*>(threadID), categoryActual);
}
else
{
azsnprintf(categorybuffer, 64, "{%p}[%14s]", reinterpret_cast<void*>(threadID), categoryActual);
}
if ((category) && (categoryLen))
{
@@ -588,6 +588,12 @@ namespace AzFramework
// pass through the camera's position and look vector for use in the lookAt function
if (const auto lookAt = lookAtFn(targetCamera.Translation(), targetCamera.Rotation().GetBasisY()))
{
// default to internal look at behavior if the look at point matches the camera translation
if (targetCamera.m_lookAt.IsClose(*lookAt))
{
return false;
}
auto transform = AZ::Transform::CreateLookAt(targetCamera.m_lookAt, *lookAt);
nextCamera.m_lookDist = -lookAt->GetDistance(targetCamera.m_lookAt);
UpdateCameraFromTransform(nextCamera, transform);
@@ -45,6 +45,7 @@ namespace AzFramework
protected:
~BoundsRequests() = default;
};
using BoundsRequestBus = AZ::EBus<BoundsRequests>;
//! Returns a union of all local Aabbs provided by components implementing the BoundsRequestBus.
@@ -6,6 +6,7 @@
*
*/
#include <AZTestShared/Math/MathTestHelpers.h>
#include <AzCore/UnitTest/TestTypes.h>
#include <AzCore/std/smart_ptr/make_shared.h>
#include <AzFramework/Input/Devices/Keyboard/InputDeviceKeyboard.h>
@@ -47,18 +48,17 @@ namespace UnitTest
m_firstPersonTranslateCamera =
AZStd::make_shared<AzFramework::TranslateCameraInput>(AzFramework::LookTranslation, m_translateCameraInputChannelIds);
auto orbitCamera =
AZStd::make_shared<AzFramework::OrbitCameraInput>(AzFramework::InputChannelId("keyboard_key_modifier_alt_l"));
m_orbitCamera = AZStd::make_shared<AzFramework::OrbitCameraInput>(m_orbitChannelId);
auto orbitRotateCamera = AZStd::make_shared<AzFramework::RotateCameraInput>(AzFramework::InputDeviceMouse::Button::Left);
auto orbitTranslateCamera =
AZStd::make_shared<AzFramework::TranslateCameraInput>(AzFramework::OrbitTranslation, m_translateCameraInputChannelIds);
orbitCamera->m_orbitCameras.AddCamera(orbitRotateCamera);
orbitCamera->m_orbitCameras.AddCamera(orbitTranslateCamera);
m_orbitCamera->m_orbitCameras.AddCamera(orbitRotateCamera);
m_orbitCamera->m_orbitCameras.AddCamera(orbitTranslateCamera);
m_cameraSystem->m_cameras.AddCamera(m_firstPersonRotateCamera);
m_cameraSystem->m_cameras.AddCamera(m_firstPersonTranslateCamera);
m_cameraSystem->m_cameras.AddCamera(orbitCamera);
m_cameraSystem->m_cameras.AddCamera(m_orbitCamera);
// these tests rely on using motion delta, not cursor positions (default is true)
AzFramework::ed_cameraSystemUseCursor = false;
@@ -68,6 +68,7 @@ namespace UnitTest
{
AzFramework::ed_cameraSystemUseCursor = true;
m_orbitCamera.reset();
m_firstPersonRotateCamera.reset();
m_firstPersonTranslateCamera.reset();
@@ -77,12 +78,14 @@ namespace UnitTest
AllocatorsTestFixture::TearDown();
}
AzFramework::InputChannelId m_orbitChannelId = AzFramework::InputChannelId("keyboard_key_modifier_alt_l");
AzFramework::TranslateCameraInputChannelIds m_translateCameraInputChannelIds;
AZStd::shared_ptr<AzFramework::RotateCameraInput> m_firstPersonRotateCamera;
AZStd::shared_ptr<AzFramework::TranslateCameraInput> m_firstPersonTranslateCamera;
AZStd::shared_ptr<AzFramework::OrbitCameraInput> m_orbitCamera;
};
TEST_F(CameraInputFixture, Begin_and_end_OrbitCameraInput_consumes_correct_events)
TEST_F(CameraInputFixture, BeginAndEndOrbitCameraInputConsumesCorrectEvents)
{
// begin orbit camera
const bool consumed1 = HandleEventAndUpdate(AzFramework::DiscreteInputEvent{ AzFramework::InputDeviceKeyboard::Key::ModifierAltL,
@@ -102,7 +105,7 @@ namespace UnitTest
EXPECT_THAT(allConsumed, ElementsAre(true, false, true, false));
}
TEST_F(CameraInputFixture, Begin_CameraInput_notifies_ActivationBeganFn_for_TranslateCameraInput)
TEST_F(CameraInputFixture, BeginCameraInputNotifiesActivationBeganFnForTranslateCameraInput)
{
bool activationBegan = false;
m_firstPersonTranslateCamera->SetActivationBeganFn(
@@ -111,13 +114,13 @@ namespace UnitTest
activationBegan = true;
});
HandleEventAndUpdate(
AzFramework::DiscreteInputEvent{ m_translateCameraInputChannelIds.m_forwardChannelId, AzFramework::InputChannel::State::Began });
HandleEventAndUpdate(AzFramework::DiscreteInputEvent{ m_translateCameraInputChannelIds.m_forwardChannelId,
AzFramework::InputChannel::State::Began });
EXPECT_TRUE(activationBegan);
}
TEST_F(CameraInputFixture, Begin_CameraInput_notifies_ActivationBeganFn_after_delta_for_RotateCameraInput)
TEST_F(CameraInputFixture, BeginCameraInputNotifiesActivationBeganFnAfterDeltaForRotateCameraInput)
{
bool activationBegan = false;
m_firstPersonRotateCamera->SetActivationBeganFn(
@@ -133,7 +136,7 @@ namespace UnitTest
EXPECT_TRUE(activationBegan);
}
TEST_F(CameraInputFixture, Begin_CameraInput_does_not_notify_ActivationBeganFn_with_no_delta_for_RotateCameraInput)
TEST_F(CameraInputFixture, BeginCameraInputDoesNotNotifyActivationBeganFnWithNoDeltaForRotateCameraInput)
{
bool activationBegan = false;
m_firstPersonRotateCamera->SetActivationBeganFn(
@@ -148,7 +151,7 @@ namespace UnitTest
EXPECT_FALSE(activationBegan);
}
TEST_F(CameraInputFixture, End_CameraInput_notifies_ActivationEndFn_after_delta_for_RotateCameraInput)
TEST_F(CameraInputFixture, EndCameraInputNotifiesActivationEndFnAfterDeltaForRotateCameraInput)
{
bool activationEnded = false;
m_firstPersonRotateCamera->SetActivationEndedFn(
@@ -166,7 +169,7 @@ namespace UnitTest
EXPECT_TRUE(activationEnded);
}
TEST_F(CameraInputFixture, End_CameraInput_does_not_notify_ActivationBeganFn_or_ActivationBeganFn_with_no_delta_for_RotateCameraInput)
TEST_F(CameraInputFixture, EndCameraInputDoesNotNotifyActivationBeganFnOrActivationBeganFnWithNoDeltaForRotateCameraInput)
{
bool activationBegan = false;
m_firstPersonRotateCamera->SetActivationBeganFn(
@@ -191,7 +194,7 @@ namespace UnitTest
EXPECT_FALSE(activationEnded);
}
TEST_F(CameraInputFixture, End_CameraInput_notifies_ActivationBeganFn_or_ActivationEndFn_with_TranslateCamera)
TEST_F(CameraInputFixture, End_CameraInputNotifiesActivationBeganFnOrActivationEndFnWithTranslateCamera)
{
bool activationBegan = false;
m_firstPersonTranslateCamera->SetActivationBeganFn(
@@ -207,16 +210,16 @@ namespace UnitTest
activationEnded = true;
});
HandleEventAndUpdate(
AzFramework::DiscreteInputEvent{ m_translateCameraInputChannelIds.m_forwardChannelId, AzFramework::InputChannel::State::Began });
HandleEventAndUpdate(
AzFramework::DiscreteInputEvent{ m_translateCameraInputChannelIds.m_forwardChannelId, AzFramework::InputChannel::State::Ended });
HandleEventAndUpdate(AzFramework::DiscreteInputEvent{ m_translateCameraInputChannelIds.m_forwardChannelId,
AzFramework::InputChannel::State::Began });
HandleEventAndUpdate(AzFramework::DiscreteInputEvent{ m_translateCameraInputChannelIds.m_forwardChannelId,
AzFramework::InputChannel::State::Ended });
EXPECT_TRUE(activationBegan);
EXPECT_TRUE(activationEnded);
}
TEST_F(CameraInputFixture, End_activation_called_for_CameraInput_if_active_when_cameras_are_cleared)
TEST_F(CameraInputFixture, EndActivationCalledForCameraInputIfActiveWhenCamerasAreCleared)
{
bool activationEnded = false;
m_firstPersonTranslateCamera->SetActivationEndedFn(
@@ -225,11 +228,37 @@ namespace UnitTest
activationEnded = true;
});
HandleEventAndUpdate(
AzFramework::DiscreteInputEvent{ m_translateCameraInputChannelIds.m_forwardChannelId, AzFramework::InputChannel::State::Began });
HandleEventAndUpdate(AzFramework::DiscreteInputEvent{ m_translateCameraInputChannelIds.m_forwardChannelId,
AzFramework::InputChannel::State::Began });
m_cameraSystem->m_cameras.Clear();
EXPECT_TRUE(activationEnded);
}
TEST_F(CameraInputFixture, OrbitCameraInputHandlesLookAtPointAndSelfAtSamePositionWhenOrbiting)
{
// create pathological lookAtFn that just returns the same position as the camera
m_orbitCamera->SetLookAtFn(
[](const AZ::Vector3& position, [[maybe_unused]] const AZ::Vector3& direction)
{
return position;
});
AzFramework::UpdateCameraFromTransform(
m_targetCamera,
AZ::Transform::CreateFromQuaternionAndTranslation(
AZ::Quaternion::CreateFromEulerAnglesDegrees(AZ::Vector3(0.0f, 0.0f, 90.0f)), AZ::Vector3(10.0f, 10.0f, 10.0f)));
m_camera = m_targetCamera;
HandleEventAndUpdate(AzFramework::DiscreteInputEvent{ m_orbitChannelId, AzFramework::InputChannel::State::Began });
// verify the camera yaw has not changed and the look at point
// does not match that of the camera translation
using ::testing::Eq;
using ::testing::Not;
EXPECT_THAT(m_camera.m_yaw, Eq(AZ::DegToRad(90.0f)));
EXPECT_THAT(m_camera.m_lookAt, Not(IsClose(m_camera.Translation())));
}
} // namespace UnitTest
@@ -92,8 +92,7 @@ namespace AzManipulatorTestFramework
{
if (m_logging)
{
AZStd::string message = AZStd::string::format(format, args...);
AZ_Printf("[ActionDispatcher] %s", message.c_str());
AZ_Printf("ActionDispatcher", format, args...);
}
}
@@ -150,7 +149,7 @@ namespace AzManipulatorTestFramework
template <typename DerivedDispatcherT>
DerivedDispatcherT* ActionDispatcher<DerivedDispatcherT>::MouseLButtonDown()
{
Log("Mouse left button down");
Log("%s", "Mouse left button down");
MouseLButtonDownImpl();
return static_cast<DerivedDispatcherT*>(this);
}
@@ -158,7 +157,7 @@ namespace AzManipulatorTestFramework
template <typename DerivedDispatcherT>
DerivedDispatcherT* ActionDispatcher<DerivedDispatcherT>::MouseLButtonUp()
{
Log("Mouse left button up");
Log("%s", "Mouse left button up");
MouseLButtonUpImpl();
return static_cast<DerivedDispatcherT*>(this);
}
@@ -45,6 +45,9 @@ namespace AzManipulatorTestFramework
virtual void SetAngularStep(float step) = 0;
//! Get the viewport id.
virtual int GetViewportId() const = 0;
//! Updates the visibility state.
//! Updates which entities are currently visible given the current camera state.
virtual void UpdateVisibility() = 0;
};
//! This interface is used to simulate the manipulator manager while the manipulators are under test.
@@ -12,8 +12,8 @@
#include <AzManipulatorTestFramework/AzManipulatorTestFrameworkUtils.h>
#include <AzManipulatorTestFramework/ImmediateModeActionDispatcher.h>
#include <AzManipulatorTestFramework/IndirectManipulatorViewportInteraction.h>
#include <AzToolsFramework/ViewportSelection/EditorInteractionSystemViewportSelectionRequestBus.h>
#include <AzToolsFramework/ViewportSelection/EditorDefaultSelection.h>
#include <AzToolsFramework/ViewportSelection/EditorInteractionSystemViewportSelectionRequestBus.h>
#include <type_traits>
namespace UnitTest
@@ -21,20 +21,18 @@ namespace UnitTest
//! Fixture to provide the indirect call viewport interaction that is dependent on AzToolsFramework::ToolsApplication.
//! \tparam ToolsApplicationFixtureT The fixture that provides the AzToolsFramework::ToolsApplication functionality.
template<typename ToolsApplicationFixtureT>
class IndirectCallManipulatorViewportInteractionFixtureMixin
: public ToolsApplicationFixtureT
class IndirectCallManipulatorViewportInteractionFixtureMixin : public ToolsApplicationFixtureT
{
using IndirectCallManipulatorViewportInteraction =
AzManipulatorTestFramework::IndirectCallManipulatorViewportInteraction;
using IndirectCallManipulatorViewportInteraction = AzManipulatorTestFramework::IndirectCallManipulatorViewportInteraction;
using ImmediateModeActionDispatcher = AzManipulatorTestFramework::ImmediateModeActionDispatcher;
void SetUpEditorFixtureImpl() override
{
ToolsApplicationFixtureT::SetUpEditorFixtureImpl();
m_viewportManipulatorInteraction = AZStd::make_unique<IndirectCallManipulatorViewportInteraction>();
m_actionDispatcher = AZStd::make_unique<ImmediateModeActionDispatcher>(*m_viewportManipulatorInteraction);
m_cameraState = AzFramework::CreateIdentityDefaultCamera(
AZ::Vector3::CreateZero(), AzManipulatorTestFramework::DefaultViewportSize);
m_cameraState =
AzFramework::CreateIdentityDefaultCamera(AZ::Vector3::CreateZero(), AzManipulatorTestFramework::DefaultViewportSize);
}
void TearDownEditorFixtureImpl() override
@@ -9,8 +9,8 @@
#pragma once
#include <AzManipulatorTestFramework/AzManipulatorTestFramework.h>
#include <AzToolsFramework/ViewportSelection/EditorInteractionSystemViewportSelectionRequestBus.h>
#include <AzToolsFramework/ViewportSelection/EditorDefaultSelection.h>
#include <AzToolsFramework/ViewportSelection/EditorInteractionSystemViewportSelectionRequestBus.h>
namespace AzManipulatorTestFramework
{
@@ -18,13 +18,12 @@ namespace AzManipulatorTestFramework
class IndirectCallManipulatorManager;
//! Implementation of manipulator viewport interaction that manipulates the manager indirectly via bus calls.
class IndirectCallManipulatorViewportInteraction
: public ManipulatorViewportInteraction
class IndirectCallManipulatorViewportInteraction : public ManipulatorViewportInteraction
{
public:
IndirectCallManipulatorViewportInteraction();
~IndirectCallManipulatorViewportInteraction();
// ManipulatorViewportInteractionInterface ...
const ViewportInteractionInterface& GetViewportInteraction() const override;
const ManipulatorManagerInterface& GetManipulatorManager() const override;
@@ -8,6 +8,7 @@
#pragma once
#include <AzFramework/Visibility/EntityVisibilityQuery.h>
#include <AzManipulatorTestFramework/AzManipulatorTestFramework.h>
namespace AzManipulatorTestFramework
@@ -19,6 +20,7 @@ namespace AzManipulatorTestFramework
: public ViewportInteractionInterface
, public AzToolsFramework::ViewportInteraction::ViewportInteractionRequestBus::Handler
, public AzToolsFramework::ViewportInteraction::ViewportSettingsRequestBus::Handler
, private AzToolsFramework::ViewportInteraction::EditorEntityViewportInteractionRequestBus::Handler
{
public:
ViewportInteraction();
@@ -34,6 +36,7 @@ namespace AzManipulatorTestFramework
void SetGridSize(float size) override;
void SetAngularStep(float step) override;
int GetViewportId() const override;
void UpdateVisibility() override;
// ViewportInteractionRequestBus overrides ...
AzFramework::CameraState GetCameraState() override;
@@ -52,7 +55,11 @@ namespace AzManipulatorTestFramework
float ManipulatorLineBoundWidth() const override;
float ManipulatorCircleBoundWidth() const override;
// EditorEntityViewportInteractionRequestBus overrides ...
void FindVisibleEntities(AZStd::vector<AZ::EntityId>& visibleEntities) override;
private:
AzFramework::EntityVisibilityQuery m_entityVisibilityQuery;
AZStd::unique_ptr<NullDebugDisplayRequests> m_nullDebugDisplayRequests;
const int m_viewportId = 1234; // Arbitrary viewport id for manipulator tests
AzFramework::CameraState m_cameraState;
@@ -91,12 +91,12 @@ namespace AzManipulatorTestFramework
AzToolsFramework::ViewportInteraction::MousePick BuildMousePick(
const AzFramework::ScreenPoint& screenPoint, const AzFramework::CameraState& cameraState)
{
const auto screenToWorld = AzFramework::ScreenToWorld(screenPoint, cameraState);
const auto nearPlaneWorldPosition = AzFramework::ScreenToWorld(screenPoint, cameraState);
AzToolsFramework::ViewportInteraction::MousePick mousePick;
mousePick.m_screenCoordinates = screenPoint;
mousePick.m_rayOrigin = screenToWorld;
mousePick.m_rayDirection = (screenToWorld - cameraState.m_position).GetNormalized();
mousePick.m_rayOrigin = cameraState.m_position;
mousePick.m_rayDirection = (nearPlaneWorldPosition - cameraState.m_position).GetNormalized();
return mousePick;
}
@@ -16,8 +16,7 @@ namespace AzManipulatorTestFramework
using MouseInteractionEvent = AzToolsFramework::ViewportInteraction::MouseInteractionEvent;
//! Implementation of the manipulator interface using bus calls to access to the manipulator manager.
class IndirectCallManipulatorManager
: public ManipulatorManagerInterface
class IndirectCallManipulatorManager : public ManipulatorManagerInterface
{
public:
IndirectCallManipulatorManager(ViewportInteractionInterface& viewportInteraction);
@@ -39,11 +38,12 @@ namespace AzManipulatorTestFramework
void IndirectCallManipulatorManager::ConsumeMouseInteractionEvent(const MouseInteractionEvent& event)
{
m_viewportInteraction.UpdateVisibility();
DrawManipulators();
AzToolsFramework::EditorInteractionSystemViewportSelectionRequestBus::Event(
AzToolsFramework::GetEntityContextId(),
&AzToolsFramework::ViewportInteraction::InternalMouseViewportRequests::InternalHandleAllMouseInteractions,
event);
&AzToolsFramework::ViewportInteraction::InternalMouseViewportRequests::InternalHandleAllMouseInteractions, event);
DrawManipulators();
}
@@ -24,7 +24,7 @@ namespace AzManipulatorTestFramework
{
const char* error = "Couldn't add action to sequence, dispatcher is locked (you must call ResetSequence() \
before adding actions to this dispatcher)";
Log(error);
Log("%s", error);
AZ_Assert(false, "Error: %s", error);
}
@@ -108,7 +108,7 @@ namespace AzManipulatorTestFramework
RetainedModeActionDispatcher* RetainedModeActionDispatcher::ResetSequence()
{
Log("Resetting the action sequence");
Log("%s", "Resetting the action sequence");
m_actions.clear();
m_dispatcher.ResetEvent();
m_locked = false;
@@ -26,10 +26,12 @@ namespace AzManipulatorTestFramework
{
AzToolsFramework::ViewportInteraction::ViewportInteractionRequestBus::Handler::BusConnect(m_viewportId);
AzToolsFramework::ViewportInteraction::ViewportSettingsRequestBus::Handler::BusConnect(m_viewportId);
AzToolsFramework::ViewportInteraction::EditorEntityViewportInteractionRequestBus::Handler::BusConnect(m_viewportId);
}
ViewportInteraction::~ViewportInteraction()
{
AzToolsFramework::ViewportInteraction::EditorEntityViewportInteractionRequestBus::Handler::BusDisconnect();
AzToolsFramework::ViewportInteraction::ViewportSettingsRequestBus::Handler::BusDisconnect();
AzToolsFramework::ViewportInteraction::ViewportInteractionRequestBus::Handler::BusDisconnect();
}
@@ -74,6 +76,16 @@ namespace AzManipulatorTestFramework
return 0.1f;
}
void ViewportInteraction::FindVisibleEntities(AZStd::vector<AZ::EntityId>& visibleEntitiesOut)
{
visibleEntitiesOut.assign(m_entityVisibilityQuery.Begin(), m_entityVisibilityQuery.End());
}
void ViewportInteraction::UpdateVisibility()
{
m_entityVisibilityQuery.UpdateVisibility(m_cameraState);
}
AzFramework::ScreenPoint ViewportInteraction::ViewportWorldToScreen(const AZ::Vector3& worldPosition)
{
return AzFramework::WorldToScreen(worldPosition, m_cameraState);
@@ -96,7 +96,7 @@ namespace AzToolsFramework
{
AZ::EBusReduceResult<AZ::Aabb, AzFramework::AabbUnionAggregator> aabbResult(AZ::Aabb::CreateNull());
EditorComponentSelectionRequestsBus::EventResult(
aabbResult, entityId, &EditorComponentSelectionRequests::GetEditorSelectionBoundsViewport, viewportInfo);
aabbResult, entityId, &EditorComponentSelectionRequestsBus::Events::GetEditorSelectionBoundsViewport, viewportInfo);
return aabbResult.value;
}
@@ -10,6 +10,25 @@
namespace AzToolsFramework
{
AzFramework::ClickDetector::ClickEvent ClickDetectorEventFromViewportInteraction(
const ViewportInteraction::MouseInteractionEvent& mouseInteraction)
{
if (mouseInteraction.m_mouseInteraction.m_mouseButtons.Left())
{
if (mouseInteraction.m_mouseEvent == ViewportInteraction::MouseEvent::Down)
{
return AzFramework::ClickDetector::ClickEvent::Down;
}
if (mouseInteraction.m_mouseEvent == ViewportInteraction::MouseEvent::Up)
{
return AzFramework::ClickDetector::ClickEvent::Up;
}
}
return AzFramework::ClickDetector::ClickEvent::Nil;
}
float ManipulatorLineBoundWidth(const AzFramework::ViewportId viewportId /*= AzFramework::InvalidViewportId*/)
{
float lineBoundWidth = 0.0f;
@@ -250,8 +250,6 @@ namespace AzToolsFramework
virtual AZ::Vector3 PickTerrain(const AzFramework::ScreenPoint& point) = 0;
//! Return the terrain height given a world position in 2d (xy plane).
virtual float TerrainHeight(const AZ::Vector2& position) = 0;
//! Given the current view frustum (viewport) return all visible entities.
virtual void FindVisibleEntities(AZStd::vector<AZ::EntityId>& visibleEntities) = 0;
//! Is the user holding a modifier key to move the manipulator space from local to world.
virtual bool ShowingWorldSpace() = 0;
//! Return the widget to use as the parent for the viewport context menu.
@@ -269,7 +267,20 @@ namespace AzToolsFramework
//! Type to inherit to implement MainEditorViewportInteractionRequests.
using MainEditorViewportInteractionRequestBus = AZ::EBus<MainEditorViewportInteractionRequests, ViewportEBusTraits>;
//! Viewport requests for managing the viewport's cursor state.
//! Editor entity requests to be made about the viewport.
class EditorEntityViewportInteractionRequests
{
public:
//! Given the current view frustum (viewport) return all visible entities.
virtual void FindVisibleEntities(AZStd::vector<AZ::EntityId>& visibleEntities) = 0;
protected:
~EditorEntityViewportInteractionRequests() = default;
};
using EditorEntityViewportInteractionRequestBus = AZ::EBus<EditorEntityViewportInteractionRequests, ViewportEBusTraits>;
//! Viewport requests for managing the viewport cursor state.
class ViewportMouseCursorRequests
{
public:
@@ -321,23 +332,8 @@ namespace AzToolsFramework
//! Maps a mouse interaction event to a ClickDetector event.
//! @note Function only cares about up or down events, all other events are mapped to Nil (ignored).
inline AzFramework::ClickDetector::ClickEvent ClickDetectorEventFromViewportInteraction(
const ViewportInteraction::MouseInteractionEvent& mouseInteraction)
{
if (mouseInteraction.m_mouseInteraction.m_mouseButtons.Left())
{
if (mouseInteraction.m_mouseEvent == ViewportInteraction::MouseEvent::Down)
{
return AzFramework::ClickDetector::ClickEvent::Down;
}
if (mouseInteraction.m_mouseEvent == ViewportInteraction::MouseEvent::Up)
{
return AzFramework::ClickDetector::ClickEvent::Up;
}
}
return AzFramework::ClickDetector::ClickEvent::Nil;
}
AzFramework::ClickDetector::ClickEvent ClickDetectorEventFromViewportInteraction(
const ViewportInteraction::MouseInteractionEvent& mouseInteraction);
//! Wrap EBus call to retrieve manipulator line bound width.
//! @note It is possible to pass AzFramework::InvalidViewportId (the default) to perform a Broadcast as opposed to a targeted Event.
@@ -19,7 +19,7 @@
namespace AzToolsFramework
{
// default ray length for picking in the viewport
static const float s_pickRayLength = 1000.0f;
static const float EditorPickRayLength = 1000.0f;
AZ::Vector3 CalculateCenterOffset(const AZ::EntityId entityId, const EditorTransformComponentSelectionRequests::Pivot pivot)
{
@@ -60,16 +60,27 @@ namespace AzToolsFramework
return screenPosition;
}
bool AabbIntersectMouseRay(const ViewportInteraction::MouseInteraction& mouseInteraction, const AZ::Aabb& aabb)
bool AabbIntersectRay(const AZ::Vector3& origin, const AZ::Vector3& direction, const AZ::Aabb& aabb, float& distance)
{
AZ_PROFILE_FUNCTION(AzToolsFramework);
const AZ::Vector3 rayScaledDir = mouseInteraction.m_mousePick.m_rayDirection * s_pickRayLength;
const AZ::Vector3 rayScaledDir = direction * EditorPickRayLength;
AZ::Vector3 startNormal;
float t, end;
return AZ::Intersect::IntersectRayAABB(
mouseInteraction.m_mousePick.m_rayOrigin, rayScaledDir, rayScaledDir.GetReciprocal(), aabb, t, end, startNormal) > 0;
AZ::Vector3 startNormal;
if (AZ::Intersect::IntersectRayAABB(origin, rayScaledDir, rayScaledDir.GetReciprocal(), aabb, t, end, startNormal) > 0)
{
distance = t * EditorPickRayLength;
return true;
}
return false;
}
bool AabbIntersectMouseRay(const ViewportInteraction::MouseInteraction& mouseInteraction, const AZ::Aabb& aabb)
{
float unused;
return AabbIntersectRay(mouseInteraction.m_mousePick.m_rayOrigin, mouseInteraction.m_mousePick.m_rayDirection, aabb, unused);
}
bool PickEntity(
@@ -117,8 +128,7 @@ namespace AzToolsFramework
{
float scaling = 1.0f;
ViewportInteraction::ViewportInteractionRequestBus::EventResult(
scaling, viewportId,
&ViewportInteraction::ViewportInteractionRequestBus::Events::DeviceScalingFactor);
scaling, viewportId, &ViewportInteraction::ViewportInteractionRequestBus::Events::DeviceScalingFactor);
return scaling;
}
@@ -46,6 +46,10 @@ namespace AzToolsFramework
//! in screen space intersected an aabb in world space.
bool AabbIntersectMouseRay(const ViewportInteraction::MouseInteraction& mouseInteraction, const AZ::Aabb& aabb);
//! Wrapper to perform an intersection between a ray and an aabb.
//! Note: direction should be normalized (it is scaled internally by the editor pick distance).
bool AabbIntersectRay(const AZ::Vector3& origin, const AZ::Vector3& direction, const AZ::Aabb& aabb, float& distance);
//! Return if a mouse interaction (pick ray) did intersect the tested EntityId.
bool PickEntity(
AZ::EntityId entityId, const ViewportInteraction::MouseInteraction& mouseInteraction, float& closestDistance, int viewportId);
@@ -161,8 +161,8 @@ namespace AzToolsFramework
// request list of visible entities from authoritative system
EntityIdList nextVisibleEntityIds;
ViewportInteraction::MainEditorViewportInteractionRequestBus::Event(
viewportInfo.m_viewportId, &ViewportInteraction::MainEditorViewportInteractionRequestBus::Events::FindVisibleEntities,
ViewportInteraction::EditorEntityViewportInteractionRequestBus::Event(
viewportInfo.m_viewportId, &ViewportInteraction::EditorEntityViewportInteractionRequestBus::Events::FindVisibleEntities,
nextVisibleEntityIds);
// only bother resorting if we know the lists have changed
@@ -6,8 +6,8 @@
*
*/
#include "ComponentModeTestDoubles.h"
#include "ComponentModeTestFixture.h"
#include "ComponentModeTestDoubles.h"
#include <AzCore/UserSettings/UserSettingsComponent.h>
@@ -15,17 +15,15 @@ namespace UnitTest
{
void ComponentModeTestFixture::SetUpEditorFixtureImpl()
{
using namespace AzToolsFramework;
using namespace AzToolsFramework::ComponentModeFramework;
namespace AztfCmf = AzToolsFramework::ComponentModeFramework;
auto* app = GetApplication();
ASSERT_TRUE(app);
app->RegisterComponentDescriptor(PlaceholderEditorComponent::CreateDescriptor());
app->RegisterComponentDescriptor(AnotherPlaceholderEditorComponent::CreateDescriptor());
app->RegisterComponentDescriptor(DependentPlaceholderEditorComponent::CreateDescriptor());
app->RegisterComponentDescriptor(AztfCmf::PlaceholderEditorComponent::CreateDescriptor());
app->RegisterComponentDescriptor(AztfCmf::AnotherPlaceholderEditorComponent::CreateDescriptor());
app->RegisterComponentDescriptor(AztfCmf::DependentPlaceholderEditorComponent::CreateDescriptor());
app->RegisterComponentDescriptor(
TestComponentModeComponent<OverrideMouseInteractionComponentMode>::CreateDescriptor());
app->RegisterComponentDescriptor(IncompatiblePlaceholderEditorComponent::CreateDescriptor());
AztfCmf::TestComponentModeComponent<AztfCmf::OverrideMouseInteractionComponentMode>::CreateDescriptor());
app->RegisterComponentDescriptor(AztfCmf::IncompatiblePlaceholderEditorComponent::CreateDescriptor());
}
} // namespace UnitTest
+14 -4
View File
@@ -305,10 +305,20 @@ namespace O3DELauncher
m_commandLine[m_commandLineLen++] = ' ';
}
azsnprintf(m_commandLine + m_commandLineLen,
AZ_COMMAND_LINE_LEN - m_commandLineLen,
needsQuote ? "\"%s\"" : "%s",
arg);
if (needsQuote) // Branching instead of using a ternary on the format string to avoid warning 4774 (format literal expected)
{
azsnprintf(m_commandLine + m_commandLineLen,
AZ_COMMAND_LINE_LEN - m_commandLineLen,
"\"%s\"",
arg);
}
else
{
azsnprintf(m_commandLine + m_commandLineLen,
AZ_COMMAND_LINE_LEN - m_commandLineLen,
"%s",
arg);
}
// Inject the argument in the argument buffer to preserve/replicate argC and argV
azstrncpy(&m_commandLineArgBuffer[m_nextCommandLineArgInsertPoint],
@@ -426,7 +426,7 @@ void android_main(android_app* appState)
if (status != ReturnCode::Success)
{
MAIN_EXIT_FAILURE(appState, GetReturnCodeString(status));
MAIN_EXIT_FAILURE(appState, "%s", GetReturnCodeString(status));
}
}
-5
View File
@@ -6,9 +6,6 @@
*
*/
#ifndef CRYINCLUDE_CRYCOMMON_BASETYPES_H
#define CRYINCLUDE_CRYCOMMON_BASETYPES_H
#pragma once
static_assert(sizeof(char) == 1);
@@ -78,5 +75,3 @@ typedef float f32;
typedef double f64;
static_assert(sizeof(f32) == 4);
static_assert(sizeof(f64) == 8);
#endif // CRYINCLUDE_CRYCOMMON_BASETYPES_H
-543
View File
@@ -1,543 +0,0 @@
/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
// Description : various integer bit fiddling hacks
#pragma once
#include <AzCore/Casting/numeric_cast.h>
// Section dictionary
#if defined(AZ_RESTRICTED_PLATFORM)
#define BITFIDDLING_H_SECTION_TRAITS 1
#define BITFIDDLING_H_SECTION_INTEGERLOG2 2
#endif
// Traits
#if defined(AZ_RESTRICTED_PLATFORM)
#define AZ_RESTRICTED_SECTION BITFIDDLING_H_SECTION_TRAITS
#include AZ_RESTRICTED_FILE(BitFiddling_h)
#elif defined(LINUX) || defined(APPLE)
#define BITFIDDLING_H_TRAIT_HAS_COUNT_LEADING_ZEROS 1
#endif
#if BITFIDDLING_H_TRAIT_HAS_COUNT_LEADING_ZEROS
#define countLeadingZeros32(x) __builtin_clz(x)
#else // Windows implementation
ILINE uint32 countLeadingZeros32(uint32 x)
{
DWORD result = 32 ^ 31; // assumes result is unmodified if _BitScanReverse returns 0
_BitScanReverse(&result, x);
result ^= 31; // needed because the index is from LSB (whereas all other implementations are from MSB)
return result;
}
#endif
inline uint32 circularShift(uint32 nbits, uint32 i)
{
return (i << nbits) | (i >> (32 - nbits));
}
template <typename T>
inline size_t countTrailingZeroes(T v)
{
size_t n = 0;
v = ~v & (v - 1);
while (v)
{
++n;
v >>= 1;
}
return n;
}
// this function returns the integer logarithm of various numbers without branching
#define IL2VAL(mask, shift) \
c |= ((x & mask) != 0) * shift; \
x >>= ((x & mask) != 0) * shift
template <typename TInteger>
inline bool IsPowerOfTwo(TInteger x)
{
return (x & (x - 1)) == 0;
}
inline uint32 NextPower2(uint32 n)
{
n--;
n |= n >> 1;
n |= n >> 2;
n |= n >> 4;
n |= n >> 8;
n |= n >> 16;
n++;
return n;
}
inline uint8 IntegerLog2(uint8 x)
{
uint8 c = 0;
IL2VAL(0xf0, 4);
IL2VAL(0xc, 2);
IL2VAL(0x2, 1);
return c;
}
inline uint16 IntegerLog2(uint16 x)
{
uint16 c = 0;
IL2VAL(0xff00, 8);
IL2VAL(0xf0, 4);
IL2VAL(0xc, 2);
IL2VAL(0x2, 1);
return c;
}
inline uint32 IntegerLog2(uint32 x)
{
return 31 - countLeadingZeros32(x);
}
inline uint64 IntegerLog2(uint64 x)
{
uint64 c = 0;
IL2VAL(0xffffffff00000000ull, 32);
IL2VAL(0xffff0000u, 16);
IL2VAL(0xff00, 8);
IL2VAL(0xf0, 4);
IL2VAL(0xc, 2);
IL2VAL(0x2, 1);
return c;
}
#if defined(APPLE) || defined(LINUX)
inline unsigned long int IntegerLog2(unsigned long int x)
{
#if defined(PLATFORM_64BIT)
return IntegerLog2((uint64)x);
#else
return IntegerLog2((uint32)x);
#endif
}
#endif
#undef IL2VAL
#if defined(AZ_RESTRICTED_PLATFORM)
#define AZ_RESTRICTED_SECTION BITFIDDLING_H_SECTION_INTEGERLOG2
#include AZ_RESTRICTED_FILE(BitFiddling_h)
#endif
template <typename TInteger>
inline TInteger IntegerLog2_RoundUp(TInteger x)
{
return 1 + IntegerLog2(x - 1);
}
static ILINE uint8 BitIndex(uint8 v)
{
uint32 vv = v;
return aznumeric_caster(31 - countLeadingZeros32(vv));
}
static ILINE uint8 BitIndex(uint16 v)
{
uint32 vv = v;
return aznumeric_caster(31 - countLeadingZeros32(vv));
}
static ILINE uint8 BitIndex(uint32 v)
{
return aznumeric_caster(31 - countLeadingZeros32(v));
}
static ILINE uint8 CountBits(uint8 v)
{
uint8 c = v;
c = ((c >> 1) & 0x55) + (c & 0x55);
c = ((c >> 2) & 0x33) + (c & 0x33);
c = ((c >> 4) & 0x0f) + (c & 0x0f);
return c;
}
static ILINE uint8 CountBits(uint16 v)
{
return CountBits((uint8)(v & 0xff)) +
CountBits((uint8)((v >> 8) & 0xff));
}
static ILINE uint8 CountBits(uint32 v)
{
return CountBits((uint8)(v & 0xff)) +
CountBits((uint8)((v >> 8) & 0xff)) +
CountBits((uint8)((v >> 16) & 0xff)) +
CountBits((uint8)((v >> 24) & 0xff));
}
// Branchless version of return v < 0 ? alt : v;
ILINE int32 Isel32(int32 v, int32 alt)
{
return ((static_cast<int32>(v) >> 31) & alt) | ((static_cast<int32>(~v) >> 31) & v);
}
// Character-to-bitfield mapping
inline uint32 AlphaBit(char c)
{
return c >= 'a' && c <= 'z' ? 1 << (c - 'z' + 31) : 0;
}
inline uint64 AlphaBit64(char c)
{
return (c >= 'a' && c <= 'z' ? 1U << (c - 'z' + 31) : 0) |
(c >= 'A' && c <= 'Z' ? 1LL << (c - 'Z' + 63) : 0);
}
inline uint32 AlphaBits(uint32 wc)
{
// Handle wide multi-char constants, can be evaluated at compile-time.
return AlphaBit((char)wc)
| AlphaBit((char)(wc >> 8))
| AlphaBit((char)(wc >> 16))
| AlphaBit((char)(wc >> 24));
}
inline uint32 AlphaBits(const char* s)
{
// Handle string of any length.
uint32 n = 0;
while (*s)
{
n |= AlphaBit(*s++);
}
return n;
}
inline uint64 AlphaBits64(const char* s)
{
// Handle string of any length.
uint64 n = 0;
while (*s)
{
n |= AlphaBit64(*s++);
}
return n;
}
// s should point to a buffer at least 65 chars long
inline void BitsAlpha64(uint64 n, char* s)
{
for (int i = 0; n != 0; n >>= 1, i++)
{
if (n & 1)
{
*s++ = i < 32 ? static_cast<char>(i + 'z' - 31) : static_cast<char>(i + 'Z' - 63);
}
}
*s++ = '\0';
}
// if hardware doesn't support 3Dc we can convert to DXT5 (different channels are used)
// with almost the same quality but the same memory requirements
inline void ConvertBlock3DcToDXT5(uint8 pDstBlock[16], const uint8 pSrcBlock[16])
{
assert(pDstBlock != pSrcBlock); // does not work in place
// 4x4 block requires 8 bytes in DXT5 or 3DC
// DXT5: 8 bit alpha0, 8 bit alpha1, 16*3 bit alpha lerp
// 16bit col0, 16 bit col1 (R5G6B5 low byte then high byte), 16*2 bit color lerp
// 3DC: 8 bit x0, 8 bit x1, 16*3 bit x lerp
// 8 bit y0, 8 bit y1, 16*3 bit y lerp
for (uint32 dwK = 0; dwK < 8; ++dwK)
{
pDstBlock[dwK] = pSrcBlock[dwK];
}
for (uint32 dwK = 8; dwK < 16; ++dwK)
{
pDstBlock[dwK] = 0;
}
// 6 bit green channel (highest bits)
// by using all 3 channels with a slight offset we can get more precision but then a dot product would be needed in PS
// because of bilinear filter we cannot just distribute bits to get perfect result
uint16 colDst0 = (((uint16)pSrcBlock[8] + 2) >> 2) << 5;
uint16 colDst1 = (((uint16)pSrcBlock[9] + 2) >> 2) << 5;
bool bFlip = colDst0 <= colDst1;
if (bFlip)
{
uint16 help = colDst0;
colDst0 = colDst1;
colDst1 = help;
}
bool bEqual = colDst0 == colDst1;
// distribute bytes by hand to not have problems with endianess
pDstBlock[8 + 0] = (uint8)colDst0;
pDstBlock[8 + 1] = (uint8)(colDst0 >> 8);
pDstBlock[8 + 2] = (uint8)colDst1;
pDstBlock[8 + 3] = (uint8)(colDst1 >> 8);
uint16* pSrcBlock16 = (uint16*)(pSrcBlock + 10);
uint16* pDstBlock16 = (uint16*)(pDstBlock + 12);
// distribute 16 3 bit values to 16 2 bit values (loosing LSB)
for (uint32 dwK = 0; dwK < 16; ++dwK)
{
uint32 dwBit0 = dwK * 3 + 0;
uint32 dwBit1 = dwK * 3 + 1;
uint32 dwBit2 = dwK * 3 + 2;
uint8 hexDataIn = (((pSrcBlock16[(dwBit2 >> 4)] >> (dwBit2 & 0xf)) & 1) << 2) // get HSB
| (((pSrcBlock16[(dwBit1 >> 4)] >> (dwBit1 & 0xf)) & 1) << 1)
| ((pSrcBlock16[(dwBit0 >> 4)] >> (dwBit0 & 0xf)) & 1); // get LSB
uint8 hexDataOut = 0;
switch (hexDataIn)
{
case 0:
hexDataOut = 0;
break; // color 0
case 1:
hexDataOut = 1;
break; // color 1
case 2:
hexDataOut = 0;
break; // mostly color 0
case 3:
hexDataOut = 2;
break;
case 4:
hexDataOut = 2;
break;
case 5:
hexDataOut = 3;
break;
case 6:
hexDataOut = 3;
break;
case 7:
hexDataOut = 1;
break; // mostly color 1
default:
assert(0);
}
if (bFlip)
{
if (hexDataOut < 2)
{
hexDataOut = 1 - hexDataOut; // 0<->1
}
else
{
hexDataOut = 5 - hexDataOut; // 2<->3
}
}
if (bEqual)
{
if (hexDataOut == 3)
{
hexDataOut = 1;
}
}
pDstBlock16[(dwK >> 3)] |= (hexDataOut << ((dwK & 0x7) << 1));
}
}
// is a bit on in a new bit field, but off in an old bit field
static ILINE bool TurnedOnBit(unsigned bit, unsigned oldBits, unsigned newBits)
{
return (newBits & bit) != 0 && (oldBits & bit) == 0;
}
inline uint32 cellUtilCountLeadingZero(uint32 x)
{
uint32 y;
uint32 n = 32;
y = x >> 16;
if (y != 0)
{
n = n - 16;
x = y;
}
y = x >> 8;
if (y != 0)
{
n = n - 8;
x = y;
}
y = x >> 4;
if (y != 0)
{
n = n - 4;
x = y;
}
y = x >> 2;
if (y != 0)
{
n = n - 2;
x = y;
}
y = x >> 1;
if (y != 0)
{
return n - 2;
}
return n - x;
}
inline uint32 cellUtilLog2(uint32 x)
{
return 31 - cellUtilCountLeadingZero(x);
}
inline void convertSwizzle(uint8*& dst, const uint8*& src,
const uint32 SrcPitch, const uint32 depth,
const uint32 xpos, const uint32 ypos,
const uint32 SciX1, const uint32 SciY1,
const uint32 SciX2, const uint32 SciY2,
const uint32 level)
{
if (level == 1)
{
switch (depth)
{
case 16:
if (xpos >= SciX1 && xpos < SciX2 && ypos >= SciY1 && ypos < SciY2)
{
// *((uint32*&)dst)++ = ((uint32*)src)[ypos * width + xpos];
// *((uint32*&)dst)++ = ((uint32*)src)[ypos * width + xpos+1];
// *((uint32*&)dst)++ = ((uint32*)src)[ypos * width + xpos+2];
// *((uint32*&)dst)++ = ((uint32*)src)[ypos * width + xpos+3];
*((uint32*&)dst)++ = *((uint32*)(src + (ypos * SrcPitch + xpos * 16)));
*((uint32*&)dst)++ = *((uint32*)(src + (ypos * SrcPitch + xpos * 16 + 4)));
*((uint32*&)dst)++ = *((uint32*)(src + (ypos * SrcPitch + xpos * 16 + 8)));
*((uint32*&)dst)++ = *((uint32*)(src + (ypos * SrcPitch + xpos * 16 + 12)));
}
else
{
((uint32*&)dst) += 4;
}
break;
case 8:
if (xpos >= SciX1 && xpos < SciX2 && ypos >= SciY1 && ypos < SciY2)
{
*((uint32*&)dst)++ = *((uint32*)(src + (ypos * SrcPitch + xpos * 8)));
*((uint32*&)dst)++ = *((uint32*)(src + (ypos * SrcPitch + xpos * 8 + 4)));
}
else
{
((uint32*&)dst) += 2;
}
break;
case 4:
if (xpos >= SciX1 && xpos < SciX2 && ypos >= SciY1 && ypos < SciY2)
{
*((uint32*&)dst) = *((uint32*)(src + (ypos * SrcPitch + xpos * 4)));
}
dst += 4;
break;
case 3:
if (xpos >= SciX1 && xpos < SciX2 && ypos >= SciY1 && ypos < SciY2)
{
*dst++ = src[ypos * SrcPitch + xpos * depth];
*dst++ = src[ypos * SrcPitch + xpos * depth + 1];
*dst++ = src[ypos * SrcPitch + xpos * depth + 2];
}
else
{
dst += 3;
}
break;
case 1:
if (xpos >= SciX1 && xpos < SciX2 && ypos >= SciY1 && ypos < SciY2)
{
*dst++ = src[ypos * SrcPitch + xpos * depth];
}
else
{
dst++;
}
break;
default:
assert(0);
}
return;
}
else
{
convertSwizzle(dst, src, SrcPitch, depth, xpos, ypos, SciX1, SciY1, SciX2, SciY2, level - 1);
convertSwizzle(dst, src, SrcPitch, depth, xpos + (1U << (level - 2)), ypos, SciX1, SciY1, SciX2, SciY2, level - 1);
convertSwizzle(dst, src, SrcPitch, depth, xpos, ypos + (1U << (level - 2)), SciX1, SciY1, SciX2, SciY2, level - 1);
convertSwizzle(dst, src, SrcPitch, depth, xpos + (1U << (level - 2)), ypos + (1U << (level - 2)), SciX1, SciY1, SciX2, SciY2, level - 1);
}
}
inline void Linear2Swizzle(uint8* dst,
const uint8* src,
const uint32 SrcPitch,
const uint32 width,
const uint32 height,
const uint32 depth,
const uint32 SciX1, const uint32 SciY1,
const uint32 SciX2, const uint32 SciY2)
{
src -= SciY1 * SrcPitch + SciX1 * depth;
if (width == height)
{
convertSwizzle(dst, src, SrcPitch, depth, 0, 0, SciX1, SciY1, SciX2, SciY2, cellUtilLog2(width) + 1);
}
else
if (width > height)
{
uint32 baseLevel = cellUtilLog2(width) - (cellUtilLog2(width) - cellUtilLog2(height));
for (uint32 i = 0; i < (1UL << (cellUtilLog2(width) - cellUtilLog2(height))); i++)
{
convertSwizzle(dst, src, SrcPitch, depth, (1U << baseLevel) * i, 0, SciX1, SciY1, SciX2, SciY2, baseLevel + 1);
}
}
else
// if (width < height)//wtf
{
uint32 baseLevel = cellUtilLog2(height) - (cellUtilLog2(height) - cellUtilLog2(width));
for (uint32 i = 0; i < (1UL << (cellUtilLog2(height) - cellUtilLog2(width))); i++)
{
convertSwizzle(dst, src, SrcPitch, depth, 0, (1U << baseLevel) * i, SciX1, SciY1, SciX2, SciY2, baseLevel + 1);
}
}
}
-21
View File
@@ -1,21 +0,0 @@
/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#include "Cry_Geo.h"
#include "Cry_Color.h"
#include "Cry_Vector3.h"
// Manually instantiate templates as needed here.
template struct Vec3_tpl<float>;
template struct Vec4_tpl<float>;
template struct Vec2_tpl<float>;
template struct Ang3_tpl<float>;
template struct Plane_tpl<float>;
template struct Matrix33_tpl<float>;
template struct Color_tpl<float>;
-210
View File
@@ -1,210 +0,0 @@
/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#pragma once
#include "BaseTypes.h"
// CRC-32
//
// Polynomial:
// 0x04C11DB7
// x^32 + x^26 + x^23 + x^22 + x^16 + x^12 + x^11 + x^10 + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1
//
// Validation:
// CCrc32::Compute("123456789") == 0xCBF43926
//
// Examples of using:
//
// printf("crc32: %08x\n", (unsigned)CCrc32::Compute(ptr, size));
//
// CCrc32 crc;
// crc.Add(ptr0, size0);
// crc.Add(ptr1, size1);
// printf("crc32: %08x\n", (unsigned)crc.Get());
class CCrc32
{
public:
static uint32 Compute(const void* const pData, const size_t sizeInBytes)
{
CCrc32 c;
c.Add(pData, sizeInBytes);
return c.Get();
}
static uint32 Compute(const char* const szData)
{
CCrc32 c;
c.Add(szData);
return c.Get();
}
static uint32 ComputeLowercase(const char* const pData, const size_t sizeInBytes)
{
CCrc32 c;
c.AddLowercase(pData, sizeInBytes);
return c.Get();
}
static uint32 ComputeLowercase(const char* const szData)
{
CCrc32 c;
c.AddLowercase(szData);
return c.Get();
}
CCrc32()
: m_crc(0xFFFFffff)
, m_pTable(GetTable())
{
}
CCrc32(unsigned int initializer)
: m_crc(initializer)
, m_pTable(GetTable())
{
}
void Reset()
{
m_crc = 0xFFFFffff;
}
uint32 Get() const
{
return ~m_crc;
}
unsigned int Add(const void* const pData, size_t sizeInBytes)
{
const uint8* p = (const uint8*)pData;
while (sizeInBytes--)
{
m_crc = (m_crc >> 8) ^ m_pTable[(m_crc & 0xFF) ^ (*p++)];
}
return Get();
}
unsigned int Add(const char* szData)
{
while (*szData)
{
m_crc = (m_crc >> 8) ^ m_pTable[(m_crc & 0xFF) ^ uint8(*szData++)];
}
return Get();
}
#if defined(CRY_TMP_ASCII_TO_LOWER)
# error CRY_TMP_ASCII_TO_LOWER already defined
#endif
#define CRY_TMP_ASCII_TO_LOWER(c) uint8(((c) <= 'Z' && (c) >= 'A') ? (c) + ('a' - 'A') : (c))
unsigned int AddLowercase(const char* pData, size_t sizeInBytes)
{
while (sizeInBytes--)
{
const uint8 c = *pData++;
m_crc = (m_crc >> 8) ^ m_pTable[(m_crc & 0xFF) ^ CRY_TMP_ASCII_TO_LOWER(c)];
}
return Get();
}
unsigned int AddLowercase(const char* szData)
{
while (*szData)
{
const uint8 c = *szData++;
m_crc = (m_crc >> 8) ^ m_pTable[(m_crc & 0xFF) ^ CRY_TMP_ASCII_TO_LOWER(c)];
}
return Get();
}
#undef CRY_TMP_ASCII_TO_LOWER
private:
static const uint32* GetTable()
{
static const uint32 table[256] =
{
0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA,
0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3,
0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988,
0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91,
0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE,
0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7,
0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC,
0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5,
0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172,
0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B,
0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940,
0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59,
0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116,
0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F,
0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924,
0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D,
0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A,
0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433,
0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818,
0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01,
0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E,
0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457,
0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C,
0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65,
0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2,
0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB,
0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0,
0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9,
0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086,
0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F,
0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4,
0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD,
0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A,
0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683,
0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8,
0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1,
0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE,
0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7,
0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC,
0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5,
0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252,
0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B,
0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60,
0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79,
0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236,
0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F,
0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04,
0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D,
0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A,
0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713,
0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38,
0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21,
0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E,
0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777,
0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C,
0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45,
0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2,
0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB,
0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0,
0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9,
0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6,
0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF,
0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94,
0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D
};
return &table[0];
}
private:
uint32 m_crc;
const uint32* const m_pTable;
};
// eof
-75
View File
@@ -6,9 +6,6 @@
*
*/
#ifndef CRYINCLUDE_CRYCOMMON_CRYENDIAN_H
#define CRYINCLUDE_CRYCOMMON_CRYENDIAN_H
#pragma once
#include <BaseTypes.h>
@@ -68,18 +65,6 @@ enum EEndianness
#endif
};
// Legacy macros
#define GetPlatformEndian() false
/////////////////////////////////////////////////////////////////////////////////////
inline bool IsSystemLittleEndian()
{
const int a = 1;
return 1 == *(const char*)&a;
}
/////////////////////////////////////////////////////////////////////////////////////
// SwapEndian function, using TypeInfo.
@@ -233,63 +218,3 @@ inline void SwapEndian(T& t, bool bSwapEndian = eLittleEndian)
SwapEndianBase(&t, 1);
}
}
template<class T>
inline T SwapEndianValue(T t, bool bSwapEndian = eLittleEndian)
{
if (bSwapEndian)
{
SwapEndianBase(&t, 1);
}
return t;
}
//---------------------------------------------------------------------------
// Object-oriented data extraction for endian-swapping reading.
template<class T, class D>
inline T* StepData(D*& pData, size_t nCount, bool bSwapEndian)
{
T* Elems = (T*)pData;
SwapEndian(Elems, nCount, bSwapEndian);
pData = (D*)((T*)pData + nCount);
return Elems;
}
template<class T, class D>
inline T* StepData(D*& pData, bool bSwapEndian)
{
return StepData<T, D>(pData, 1, bSwapEndian);
}
template<class T, class D>
inline void StepData(T*& Result, D*& pData, size_t nCount, bool bSwapEndian)
{
Result = StepData<T, D>(pData, nCount, bSwapEndian);
}
template<class T, class D>
inline void StepDataCopy(T* Dest, D*& pData, size_t nCount, bool bSwapEndian)
{
memcpy(Dest, pData, nCount * sizeof(T));
SwapEndian(Dest, nCount, bSwapEndian);
pData = (D*)((T*)pData + nCount);
}
template<class T, class D>
inline void StepDataWrite(D*& pDest, const T* aSrc, size_t nCount, bool bSwapEndian)
{
memcpy(pDest, aSrc, nCount * sizeof(T));
if (bSwapEndian)
{
SwapEndianBase((T*)pDest, nCount, true);
}
(T*&)pDest += nCount;
}
template<class T, class D>
inline void StepDataWrite(D*& pDest, const T& Src, bool bSwapEndian)
{
StepDataWrite(pDest, &Src, 1, bSwapEndian);
}
#endif // CRYINCLUDE_CRYCOMMON_CRYENDIAN_H
-163
View File
@@ -6,12 +6,7 @@
*
*/
// Description : File wrapper.
#ifndef CRYINCLUDE_CRYCOMMON_CRYFILE_H
#define CRYINCLUDE_CRYCOMMON_CRYFILE_H
#pragma once
#include <CryPath.h>
@@ -20,86 +15,16 @@
#include <IConsole.h>
#include <AzCore/IO/FileIO.h>
//////////////////////////////////////////////////////////////////////////
// Defines for CryEngine filetypes extensions.
//////////////////////////////////////////////////////////////////////////
#define CRY_GEOMETRY_FILE_EXT "cgf"
#define CRY_SKEL_FILE_EXT "chr" //will be a SKEL soon
#define CRY_SKIN_FILE_EXT "skin"
#define CRY_CHARACTER_ANIMATION_FILE_EXT "caf"
#define CRY_CHARACTER_DEFINITION_FILE_EXT "cdf"
#define CRY_CHARACTER_LIST_FILE_EXT "cid"
#define CRY_ANIM_GEOMETRY_FILE_EXT "cga"
#define CRY_ANIM_GEOMETRY_ANIMATION_FILE_EXT "anm"
#define CRY_COMPILED_FILE_EXT "(c)"
#define CRY_BINARY_XML_FILE_EXT "binxml"
#define CRY_XML_FILE_EXT "xml"
#define CRY_CHARACTER_PARAM_FILE_EXT "chrparams"
#define CRY_GEOM_CACHE_FILE_EXT "cax"
//////////////////////////////////////////////////////////////////////////
#define CRYFILE_MAX_PATH 260
//////////////////////////////////////////////////////////////////////////
inline const char* CryGetExt(const char* filepath)
{
const char* str = filepath;
size_t len = strlen(filepath);
for (const char* p = str + len - 1; p >= str; --p)
{
switch (*p)
{
case ':':
case '/':
case '\\':
// we've reached a path separator - it means there's no extension in this name
return "";
case '.':
// there's an extension in this file name
return p + 1;
}
}
return "";
}
// Summary:
// Checks if specified file name is a character file.
// Summary:
// Checks if specified file name is a character file.
inline bool IsCharacterFile(const char* filename)
{
const char* ext = CryGetExt(filename);
if (_stricmp(ext, CRY_SKEL_FILE_EXT) == 0 || _stricmp(ext, CRY_SKIN_FILE_EXT) == 0 || _stricmp(ext, CRY_CHARACTER_DEFINITION_FILE_EXT) == 0 || _stricmp(ext, CRY_ANIM_GEOMETRY_FILE_EXT) == 0)
{
return true;
}
else
{
return false;
}
}
// Description:
// Checks if specified file name is a static geometry file.
inline bool IsStatObjFile(const char* filename)
{
const char* ext = CryGetExt(filename);
if (_stricmp(ext, CRY_GEOMETRY_FILE_EXT) == 0)
{
return true;
}
else
{
return false;
}
}
// Summary:
// Wrapper on file system.
class CCryFile
{
public:
CCryFile();
CCryFile(AZ::IO::IArchive* pIArchive); // allow an alternative IArchiveinterface
CCryFile(const char* filename, const char* mode);
~CCryFile();
@@ -112,13 +37,6 @@ public:
// Summary:
// Reads data from a file at the current file position.
size_t ReadRaw(void* lpBuf, size_t nSize);
// Summary:
// Template version, for automatic size support.
template<class T>
inline size_t ReadTypeRaw(T* pDest, size_t nCount = 1)
{
return ReadRaw(pDest, sizeof(T) * nCount);
}
// Summary:
// Automatic endian-swapping version.
@@ -137,27 +55,6 @@ public:
// Summary:
// Moves the current file pointer to the specified position.
size_t Seek(size_t seek, int mode);
// Summary:
// Moves the current file pointer at the beginning of the file.
void SeekToBegin();
// Summary:
// Moves the current file pointer at the end of the file.
size_t SeekToEnd();
// Summary:
// Retrieves the current file pointer.
size_t GetPosition();
// Summary:
// Tests for end-of-file on a selected file.
bool IsEof();
// Summary:
// Flushes any data yet to be written.
void Flush();
// Summary:
// Gets a handle to a pack object.
AZ::IO::HandleType GetHandle() const { return m_fileHandle; };
// Description:
// Retrieves the filename of the selected file.
@@ -193,12 +90,6 @@ inline CCryFile::CCryFile()
m_pIArchive = gEnv ? gEnv->pCryPak : NULL;
}
inline CCryFile::CCryFile(AZ::IO::IArchive* pIArchive)
{
m_fileHandle = AZ::IO::InvalidHandle;
m_pIArchive = pIArchive;
}
//////////////////////////////////////////////////////////////////////////
inline CCryFile::CCryFile(const char* filename, const char* mode)
{
@@ -336,58 +227,6 @@ inline size_t CCryFile::Seek(size_t seek, int mode)
return 1;
}
//////////////////////////////////////////////////////////////////////////
inline void CCryFile::SeekToBegin()
{
Seek(0, SEEK_SET);
}
//////////////////////////////////////////////////////////////////////////
inline size_t CCryFile::SeekToEnd()
{
return Seek(0, SEEK_END);
}
//////////////////////////////////////////////////////////////////////////
inline size_t CCryFile::GetPosition()
{
assert(m_fileHandle != AZ::IO::InvalidHandle);
if (m_pIArchive)
{
return m_pIArchive->FTell(m_fileHandle);
}
AZ::u64 tellOffset = 0;
AZ::IO::FileIOBase::GetInstance()->Tell(m_fileHandle, tellOffset);
return static_cast<size_t>(tellOffset);
}
//////////////////////////////////////////////////////////////////////////
inline bool CCryFile::IsEof()
{
assert(m_fileHandle != AZ::IO::InvalidHandle);
if (m_pIArchive)
{
return m_pIArchive->FEof(m_fileHandle) != 0;
}
return AZ::IO::FileIOBase::GetInstance()->Eof(m_fileHandle);
}
//////////////////////////////////////////////////////////////////////////
inline void CCryFile::Flush()
{
assert(m_fileHandle != AZ::IO::InvalidHandle);
if (m_pIArchive)
{
m_pIArchive->FFlush(m_fileHandle);
}
AZ::IO::FileIOBase::GetInstance()->Flush(m_fileHandle);
}
//////////////////////////////////////////////////////////////////////////
inline bool CCryFile::IsInPak() const
{
@@ -433,5 +272,3 @@ inline const char* CCryFile::GetAdjustedFilename() const
}
return szAdjustedFile;
}
#endif // CRYINCLUDE_CRYCOMMON_CRYFILE_H
-7
View File
@@ -15,7 +15,6 @@
typedef uint16 CryHalf;
class ICrySizer;
typedef union floatint_union
{
@@ -138,9 +137,6 @@ struct CryHalf2
{
return x != rhs.x || y != rhs.y;
}
void GetMemoryUsage([[maybe_unused]] ICrySizer* pSizer) const {}
};
struct CryHalf4
@@ -193,9 +189,6 @@ struct CryHalf4
{
return x != rhs.x || y != rhs.y || z != rhs.z || w != rhs.w;
}
void GetMemoryUsage([[maybe_unused]] ICrySizer* pSizer) const {}
};
#endif // #ifndef CRY_HALF_INL
+2 -8
View File
@@ -21,7 +21,8 @@
#pragma once
#include <CrySizer.h>
#include "Cry_Math.h"
#include <StlUtils.h>
/************************************************************************
Core elements:
@@ -151,13 +152,6 @@ public:
// Allow TListeners::Notifier style usage
typedef class CListenerNotifier<T> Notifier;
void GetMemoryUsage(ICrySizer* pSizer) const
{
pSizer->AddContainer(m_listeners);
#if defined(CRY_LISTENERSET_DEBUG)
pSizer->AddContainer(m_allocatedNames);
#endif
}
private: // DO NOT REMOVE - following methods only to be accessed only via CNotifier
struct ListenerRecord
-212
View File
@@ -1,212 +0,0 @@
/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
// Description : Simple POD types container
#ifndef CRYINCLUDE_CRYCOMMON_CRYPODARRAY_H
#define CRYINCLUDE_CRYCOMMON_CRYPODARRAY_H
#pragma once
#include <AzCore/std/containers/vector.h>
//////////////////////////////////////////////////////////////////////////
// POD Array
// vector like class (random access O(1)) without construction/destructor/copy constructor/assignment handling
// over-allocation allows safe prefetching where required without worrying about memory page boundaries
//////////////////////////////////////////////////////////////////////////
template <class T, size_t overAllocBytes = 0>
class PodArray
{
AZStd::vector<T> m_elements;
public:
typedef T value_type;
typedef T* iterator;
typedef const T* const_iterator;
//////////////////////////////////////////////////////////////////////////
// STL compatible interface
//////////////////////////////////////////////////////////////////////////
void resize(size_t numElements)
{
m_elements.resize(numElements);
}
//////////////////////////////////////////////////////////////////////////
ILINE void reserve(unsigned numElements) { m_elements.reserve(numElements); }
ILINE void push_back(const T& rElement) { m_elements.push_back(rElement); }
ILINE size_t size() const { return m_elements.size(); }
ILINE size_t capacity() const { return m_elements.capacity(); }
ILINE void clear() { m_elements.clear(); }
ILINE T* begin() { return m_elements.begin(); }
ILINE T* end() { return m_elements.end(); }
ILINE const T* begin() const { return m_elements.begin(); }
ILINE const T* end() const { return m_elements.end(); }
ILINE bool empty() const { return m_elements.empty(); }
ILINE const T& front() const { return m_elements.front(); }
ILINE T& front() { return m_elements.front(); }
ILINE const T& back() const { return m_elements.back(); }
ILINE T& back() { return m_elements.back(); }
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
PodArray()
: m_elements()
{
}
PodArray(int elem_count, int nNewCount = 0)
{
m_elements.reserve(elem_count);
m_elements.resize(nNewCount);
}
PodArray(const PodArray<T>& from)
: m_elements(from.m_elements)
{
}
~PodArray()
{
}
void Reset() { m_elements.clear(); }
void Free()
{
m_elements.clear();
m_elements.shrink_to_fit();
}
ILINE void Clear()
{
m_elements.clear();
}
int Find(const T& p)
{
const auto it = AZStd::find(m_elements.begin(), m_elements.end(), p);
if (it != m_elements.end())
{
return static_cast<int>(AZStd::distance(m_elements.begin(), it));
}
return -1;
}
inline void AddList(const PodArray<T>& lstAnother)
{
AZStd::copy(lstAnother.m_elements.begin(), lstAnother.m_elements.end(), AZStd::back_inserter(m_elements));
}
inline void AddList(T* pAnotherArray, int nAnotherCount)
{
AZStd::copy(pAnotherArray, pAnotherArray + nAnotherCount, AZStd::back_inserter(m_elements));
}
ILINE void Add(const T& p)
{
m_elements.push_back(p);
}
ILINE T& AddNew()
{
m_elements.emplace_back();
return m_elements.back();
}
void InsertBefore(const T& p, const unsigned int nBefore)
{
m_elements.insert(m_elements.begin() + nBefore, p);
}
void CheckAllocated(int elem_count)
{
if (m_elements.size() < elem_count)
{
m_elements.resize(elem_count);
}
}
void PreAllocate(int elem_count, int nNewCount = -1)
{
m_elements.reserve(elem_count);
if (nNewCount >= 0)
{
m_elements.resize(nNewCount);
}
}
inline void Delete(const int nElemId, const int nElemCount = 1)
{
AZ_Assert(nElemId >= 0 && nElemId + nElemCount <= size(), "Index out of bounds");
m_elements.erase(m_elements.begin() + nElemId, m_elements.begin() + nElemId + nElemCount);
}
inline void DeleteFastUnsorted(const int nElemId, const int nElemCount = 1)
{
AZ_Assert(nElemId >= 0 && nElemId + nElemCount <= size(), "Index out of bounds");
m_elements.erase(m_elements.begin() + nElemId, m_elements.begin() + nElemId + nElemCount);
}
inline bool Delete(const T& del)
{
const size_t numElements = m_elements.size();
m_elements.erase(std::remove(m_elements.begin(), m_elements.end(), del), m_elements.end());
return numElements != m_elements.size();
}
ILINE size_t Count() const { return m_elements.size(); }
ILINE size_t Size() const { return m_elements.size(); }
ILINE int IsEmpty() const { return m_elements.empty(); }
ILINE const T& operator [] (int i) const { return m_elements[i]; }
ILINE T& operator [] (int i) { return m_elements[i]; }
ILINE const T& GetAt(int i) const { return m_elements[i]; }
ILINE T& GetAt(int i) { return m_elements[i]; }
ILINE const T* Get(int i) const { return &m_elements[i]; }
ILINE T* Get(int i) { return &m_elements[i]; }
ILINE const T* GetElements() const { return m_elements.data(); }
ILINE T* GetElements() { return m_elements.data(); }
ILINE unsigned int GetDataSize() const { return m_elements.size() * sizeof(T); }
const T& Last() const { return m_elements.back(); }
T& Last() { return m_elements.back(); }
ILINE void DeleteLast()
{
assert(!m_elements.empty());
m_elements.pop_back();
}
PodArray<T>& operator=(const PodArray<T>& source_list)
{
m_elements = source_list.m_elements;
return *this;
}
//////////////////////////////////////////////////////////////////////////
// Return true if arrays have the same data.
bool Compare(const PodArray<T>& l) const
{
return m_elements == l.m_elements;
}
// for statistics
ILINE size_t ComputeSizeInMemory() const
{
return (sizeof(*this) + sizeof(T) * m_elements.capacity()) + overAllocBytes;
}
ILINE void RemoveIf(AZStd::function<bool(const T&)> testFunc)
{
m_elements.erase(AZStd::remove_if(m_elements.begin(), m_elements.end(), testFunc), m_elements.end());
}
};
#endif // CRYINCLUDE_CRYCOMMON_CRYPODARRAY_H
-563
View File
@@ -1,563 +0,0 @@
/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
// Description : Declaration and definition of the CrySizer 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_CRYCOMMON_CRYSIZER_H
#define CRYINCLUDE_CRYCOMMON_CRYSIZER_H
#pragma once
//////////////////////////////////////////////////////////////////////////
// common containers for overloads
#include <list>
#include "Cry_Math.h"
#include <StlUtils.h>
#include <CryPodArray.h>
#include <Cry_Vector3.h>
#include <Cry_Quat.h>
#include <Cry_Color.h>
#include <smartptr.h>
#include <AzCore/std/smart_ptr/shared_ptr.h>
// forward declarations for overloads
struct AABB;
struct SVF_P3F;
struct SVF_P3F_C4B_T2F;
struct SVF_P3S_C4B_T2S;
struct SPipTangents;
#ifdef WIN64
#include <string.h> // workaround for Amd64 compiler
#endif
namespace AZ
{
class Vector3;
}
// flags applicable to the ICrySizer (retrieved via getFlags() method)
//
enum ICrySizerFlagsEnum
{
// if this flag is set, during getSize(), the subsystem must count all the objects
// it uses in the other subsystems also
CSF_RecurseSubsystems = 1 << 0,
CSF_Reserved1 = 1 << 1,
CSF_Reserved2 = 1 << 2
};
//////////////////////////////////////////////////////////////////////////
// Helper functions to calculate size of the std containers.
//////////////////////////////////////////////////////////////////////////
namespace stl
{
template <class Map>
inline size_t size_of_map(const Map& m)
{
if (!m.empty())
{
return m.size() * sizeof(typename Map::value_type) + m.size() * sizeof(MapLikeStruct);
}
return 0;
}
template <class Map>
inline size_t size_of_set(const Map& m)
{
if (!m.empty())
{
return m.size() * sizeof(typename Map::value_type) + m.size() * sizeof(MapLikeStruct);
}
return 0;
}
template <class List>
inline size_t size_of_list(const List& c)
{
if (!c.empty())
{
return c.size() * sizeof(typename List::value_type) + c.size() * sizeof(void*) * 2; // sizeof stored type + 2 pointers prev,next
}
return 0;
}
template <class Deque>
inline size_t size_of_deque(const Deque& c)
{
if (!c.empty())
{
return c.size() * sizeof(typename Deque::value_type);
}
return 0;
}
};
//////////////////////////////////////////////////////////////////////////
// interface ICrySizer
// USAGE
// An instance of this class is passed down to each and every component in the system.
// Every component it's passed to optionally pushes its name on top of the
// component name stack (thus ensuring that all the components calculated down
// the tree will be assigned the correct subsystem/component name)
// Every component must Add its size with one of the Add* functions, and Add the
// size of all its subcomponents recursively
// In order to push the component/system name on the name stack, the clients must
// use the SIZER_COMPONENT_NAME macro or CrySizerComponentNameHelper class:
//
// void X::getSize (ICrySizer* pSizer)
// {
// SIZER_COMPONENT_NAME(pSizer, X);
// if (!pSizer->Add (this))
// return;
// pSizer->Add (m_arrMySimpleArray);
// pSizer->Add (m_setMySimpleSet);
// m_pSubobject->getSize (pSizer);
// }
//
// The Add* functions return bool. If they return true, then the object has been added
// to the set for the first time, and you should go on recursively adding all its children.
// If it returns false, then you can spare time and rather not go on into recursion;
// however it doesn't reflect on the results: an object that's added more than once is
// counted only once.
//
// WARNING:
// If you have an array (pointer), you should Add its size with addArray
class ICrySizer
{
public:
virtual ~ICrySizer(){}
// this class is used to push/pop the name to/from the stack automatically
// (to exclude stack overruns or underruns at runtime)
friend class CrySizerComponentNameHelper;
virtual void Release() = 0;
// Return total calculated size.
virtual size_t GetTotalSize() = 0;
// Return total objects added.
virtual size_t GetObjectCount() = 0;
// Resets the counting.
virtual void Reset() = 0;
virtual void End() = 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)
// nCount parameter is only used for counting number of objects, it doesnt affect the size of the 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) = 0;
template<typename Type>
bool AddObjectSize(const Type* pObj)
{
return AddObject(pObj, sizeof *pObj);
}
////////////////////////////////////////////////////////////////////////////////////////
// temp dummy function while checking in the CrySizer changes, will be removed soon
template<typename Type>
void AddObject(const Type& rObj)
{
(void)rObj;
}
template<typename Type>
void AddObject(Type* pObj)
{
if (pObj)
{
//forward to reference object to allow function overload
this->AddObject(*pObj);
}
}
// overloads for smart_ptr and other common objects
template<typename T>
void AddObject(const _smart_ptr<T>& rObj) { this->AddObject(rObj.get()); }
template<typename T>
void AddObject(const AZStd::shared_ptr<T>& rObj) { this->AddObject(rObj.get()); }
template<typename T>
void AddObject(const std::shared_ptr<T>& rObj) { this->AddObject(rObj.get()); }
template<typename T>
void AddObject(const std::unique_ptr<T>& rObj) { this->AddObject(rObj.get()); }
template<typename T, typename U>
void AddObject(const std::pair<T, U>& rPair)
{
this->AddObject(rPair.first);
this->AddObject(rPair.second);
}
template<typename T, typename U>
void AddObject(const AZStd::pair<T, U>& rPair)
{
this->AddObject(rPair.first);
this->AddObject(rPair.second);
}
void AddObject(const AZStd::string& rString) {this->AddObject(rString.c_str(), rString.capacity()); }
void AddObject(const wchar_t&) {}
void AddObject(const char&) {}
void AddObject(const unsigned char&) {}
void AddObject(const signed char&) {}
void AddObject(const short&) {}
void AddObject(const unsigned short&) {}
void AddObject(const int&) {}
void AddObject(const unsigned int&) {}
void AddObject(const long&) {}
void AddObject(const unsigned long&) {}
void AddObject(const float&) {}
void AddObject(const bool&) {}
void AddObject(const unsigned long long&) {}
void AddObject(const long long&) {}
void AddObject(const double&) {}
void AddObject(const Vec2&) {}
void AddObject(const Vec3&) {}
void AddObject(const Vec4&) {}
void AddObject(const Ang3&) {}
void AddObject(const Matrix34&) {}
void AddObject(const Quat&) {}
void AddObject(const QuatT&) {}
void AddObject(const QuatTS&) {}
void AddObject(const ColorF&) {}
void AddObject(const AABB&) {}
void AddObject(const SVF_P3F&) {}
void AddObject(const SVF_P3F_C4B_T2F&) {}
void AddObject(const SVF_P3S_C4B_T2S&) {}
void AddObject(const SPipTangents&) {}
void AddObject([[maybe_unused]] const AZ::Vector3& rObj) {}
void AddObject(void*) {}
// overloads for container, will automaticly traverse the content
template<typename T, typename Alloc>
void AddObject(const std::list<T, Alloc>& rList)
{
// dummy struct to get correct element size
struct Dummy
{
void* a;
void* b;
T t;
};
for (typename std::list<T, Alloc>::const_iterator it = rList.begin(); it != rList.end(); ++it)
{
if (this->AddObject(&(*it), sizeof(Dummy)))
{
this->AddObject(*it);
}
}
}
template<typename K, typename T, typename Comp, typename Equal, typename Alloc>
void AddObject([[maybe_unused]] const AZStd::unordered_map<K, T, Comp, Equal, Alloc>& rVector)
{
}
template<typename T, typename Alloc>
void AddObject(const std::vector<T, Alloc>& rVector)
{
if (rVector.empty())
{
this->AddObject(&rVector, rVector.capacity() * sizeof(T));
return;
}
if (!this->AddObject(&rVector[0], rVector.capacity() * sizeof(T)))
{
return;
}
for (typename std::vector<T, Alloc>::const_iterator it = rVector.begin(); it != rVector.end(); ++it)
{
this->AddObject(*it);
}
}
template<typename T, typename Alloc>
void AddObject(const std::deque<T, Alloc>& rVector)
{
for (typename std::deque<T, Alloc>::const_iterator it = rVector.begin(); it != rVector.end(); ++it)
{
if (this->AddObject(&(*it), sizeof(T)))
{
this->AddObject(*it);
}
}
}
template<typename T>
void AddObject(const PodArray<T>& rVector)
{
if (!this->AddObject(rVector.begin(), rVector.capacity() * sizeof(T)))
{
return;
}
for (typename PodArray<T>::const_iterator it = rVector.begin(); it != rVector.end(); ++it)
{
this->AddObject(*it);
}
}
template<typename K, typename T, typename Comp, typename Alloc>
void AddObject(const std::map<K, T, Comp, Alloc>& rVector)
{
// dummy struct to get correct element size
struct Dummy
{
void* a;
void* b;
void* c;
void* d;
K k;
T t;
};
for (typename std::map<K, T, Comp, Alloc>::const_iterator it = rVector.begin(); it != rVector.end(); ++it)
{
if (this->AddObject(&(*it), sizeof(Dummy)))
{
this->AddObject(it->first);
this->AddObject(it->second);
}
}
}
template<typename T, typename Comp, typename Alloc>
void AddObject(const std::set<T, Comp, Alloc>& rVector)
{
// dummy struct to get correct element size
struct Dummy
{
void* a;
void* b;
void* c;
void* d;
T t;
};
for (typename std::set<T, Comp, Alloc>::const_iterator it = rVector.begin(); it != rVector.end(); ++it)
{
if (this->AddObject(&(*it), sizeof(Dummy)))
{
this->AddObject(*it);
}
}
}
template <typename TKey, typename TValue, typename TPredicate, typename TAlloc>
void AddObject (const std::multimap<TKey, TValue, TPredicate, TAlloc>& rContainer)
{
AddContainer(rContainer);
}
////////////////////////////////////////////////////////////////////////////////////////
template <typename T>
bool Add (const T* pId, size_t num)
{
return AddObject(pId, num * sizeof(T));
}
template <class T>
bool Add (const T& rObject)
{
return AddObject (&rObject, sizeof(T));
}
bool Add (const char* szText)
{
return AddObject(szText, strlen(szText) + 1);
}
template <class StringCls>
bool AddString (const StringCls& strText)
{
if (!strText.empty())
{
return AddObject (strText.c_str(), strText.size());
}
else
{
return false;
}
}
#ifdef _XSTRING_
template <class Elem, class Traits, class Allocator>
bool Add (const std::basic_string<Elem, Traits, Allocator>& strText)
{
AddString (strText);
return true;
}
#endif
#ifndef NOT_USE_CRY_STRING
bool Add (const AZStd::string& strText)
{
AddString(strText);
return true;
}
#endif
// Template helper function to add generic stl container
template <typename Container>
bool AddContainer (const Container& rContainer)
{
if (rContainer.capacity())
{
return AddObject (&rContainer, rContainer.capacity() * sizeof(typename Container::value_type));
}
return false;
}
template <typename Container>
bool AddHashMap(const Container& rContainer)
{
if (!rContainer.empty())
{
return AddObject (&(*rContainer.begin()), rContainer.size() * sizeof(typename Container::value_type));
}
return false;
}
// Specialization of the AddContainer for the std::list
template <typename Type, typename TAlloc>
bool AddContainer (const std::list<Type, TAlloc>& rContainer)
{
if (!rContainer.empty())
{
return AddObject(&(*rContainer.begin()), stl::size_of_list(rContainer));
}
return false;
}
// Specialization of the AddContainer for the std::deque
template <typename Type, typename TAlloc>
bool AddContainer (const std::deque<Type, TAlloc>& rContainer)
{
if (!rContainer.empty())
{
return AddObject(&(*rContainer.begin()), stl::size_of_deque(rContainer));
}
return false;
}
// Specialization of the AddContainer for the std::map
template <typename TKey, typename TValue, typename TPredicate, typename TAlloc>
bool AddContainer (const std::map<TKey, TValue, TPredicate, TAlloc>& rContainer)
{
if (!rContainer.empty())
{
return AddObject(&(*rContainer.begin()), stl::size_of_map(rContainer));
}
return false;
}
// Specialization of the AddContainer for the std::multimap
template <typename TKey, typename TValue, typename TPredicate, typename TAlloc>
bool AddContainer (const std::multimap<TKey, TValue, TPredicate, TAlloc>& rContainer)
{
if (!rContainer.empty())
{
return AddObject(&(*rContainer.begin()), stl::size_of_map(rContainer));
}
return false;
}
// Specialization of the AddContainer for the std::set
template <typename TKey, typename TPredicate, typename TAlloc>
bool AddContainer (const std::set<TKey, TPredicate, TAlloc>& rContainer)
{
if (!rContainer.empty())
{
return AddObject(&(*rContainer.begin()), stl::size_of_set(rContainer));
}
return false;
}
// Specialization of the AddContainer for the AZStd::unordered_map
template <typename KEY, typename TYPE, class HASH, class EQUAL, class ALLOCATOR>
bool AddContainer(const AZStd::unordered_map<KEY, TYPE, HASH, EQUAL, ALLOCATOR>& rContainer)
{
if (!rContainer.empty())
{
return AddObject(&(*rContainer.begin()), rContainer.size() * sizeof(typename AZStd::unordered_map<KEY, TYPE, HASH, EQUAL, ALLOCATOR>::value_type));
}
else
{
return false;
}
}
void Test()
{
std::map<int, float> mymap;
AddContainer(mymap);
}
// returns the flags
unsigned GetFlags() const {return m_nFlags; }
protected:
// 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) = 0;
// pushes the name that is the name of the previous component . (dot) this name
virtual void PushSubcomponent (const char* szSubcomponentName) = 0;
virtual void Pop () = 0;
unsigned m_nFlags;
};
//////////////////////////////////////////////////////////////////////////
// This is on-stack class that is only used to push/pop component names
// to/from the sizer name stack.
//
// USAGE:
//
// Create an instance of this class at the start of a function, before
// calling Add* methods of the sizer interface. Everything added in the
// function and below will be considered this component, unless
// explicitly set otherwise.
//
class CrySizerComponentNameHelper
{
public:
// pushes the component name on top of the name stack of the given sizer
CrySizerComponentNameHelper (ICrySizer* pSizer, const char* szComponentName, bool bSubcomponent)
: m_pSizer(pSizer)
{
if (bSubcomponent)
{
pSizer->PushSubcomponent (szComponentName);
}
else
{
pSizer->Push (szComponentName);
}
}
// pops the component name off top of the name stack of the sizer
~CrySizerComponentNameHelper()
{
m_pSizer->Pop();
}
protected:
ICrySizer* m_pSizer;
};
// use this to push (and automatically pop) the sizer component name at the beginning of the
// getSize() function
#define SIZER_COMPONENT_NAME(pSizerPointer, szComponentName) CrySizerComponentNameHelper AZ_JOIN(sizerHelper, __LINE__)(pSizerPointer, szComponentName, false)
#define SIZER_SUBCOMPONENT_NAME(pSizerPointer, szComponentName) CrySizerComponentNameHelper AZ_JOIN(sizerHelper, __LINE__)(pSizerPointer, szComponentName, true)
#endif // CRYINCLUDE_CRYCOMMON_CRYSIZER_H
File diff suppressed because it is too large Load Diff
-779
View File
@@ -8,21 +8,12 @@
// Description : 4D Color template.
#ifndef CRYINCLUDE_CRYCOMMON_CRY_COLOR_H
#define CRYINCLUDE_CRYCOMMON_CRY_COLOR_H
#pragma once
#include <platform.h>
#include <AzCore/std/containers/array.h>
#include "Cry_Math.h"
ILINE float FClamp(float X, float Min, float Max)
{
return X < Min ? Min : X < Max ? X : Max;
}
template <class T>
struct Color_tpl;
@@ -54,44 +45,6 @@ struct Color_tpl
ILINE Color_tpl(const Vec3& c, float fAlpha);
ILINE Color_tpl(const Vec4& c);
void Clamp(float Min = 0, float Max = 1.0f)
{
r = ::FClamp(r, Min, Max);
g = ::FClamp(g, Min, Max);
b = ::FClamp(b, Min, Max);
a = ::FClamp(a, Min, Max);
}
void ScaleCol (float f)
{
r = static_cast<T>(r * f);
g = static_cast<T>(g * f);
b = static_cast<T>(b * f);
}
float Luminance() const
{
return r * 0.30f + g * 0.59f + b * 0.11f;
}
ILINE float Max() const
{
return max(r, max(b, g));
}
float NormalizeCol (ColorF& out) const
{
float max = Max();
if (max == 0)
{
return 0;
}
out = *this / max;
return max;
}
ILINE Color_tpl(const Vec3& vVec)
{
r = (T)vVec.x;
@@ -114,20 +67,6 @@ struct Color_tpl
a = static_cast<T>(fA);
}
ILINE void set(T _x, T _y = 0, T _z = 0, T _w = 0)
{
r = _x;
g = _y;
b = _z;
a = _w;
}
ILINE void set(T _x, T _y = 0, T _z = 0)
{
r = _x;
g = _y;
b = _z;
a = 1;
}
ILINE Color_tpl operator + () const
{
return *this;
@@ -227,117 +166,12 @@ struct Color_tpl
return (r != v.r) || (g != v.g) || (b != v.b) || (a != v.a);
}
ILINE unsigned char pack_rgb332() const;
ILINE unsigned short pack_argb4444() const;
ILINE unsigned short pack_rgb555() const;
ILINE unsigned short pack_rgb565() const;
ILINE unsigned int pack_bgr888() const;
ILINE unsigned int pack_rgb888() const;
ILINE unsigned int pack_abgr8888() const;
ILINE unsigned int pack_argb8888() const;
inline Vec4 toVec4() const { return Vec4(r, g, b, a); }
inline Vec3 toVec3() const { return Vec3(r, g, b); }
inline void toFloat4(f32* out) const;
inline void toHSV(f32& h, f32& s, f32& v) const;
inline void fromHSV(f32 h, f32 s, f32 v);
inline void clamp(T bottom = 0.0f, T top = 1.0f);
inline void maximum(const Color_tpl<T>& ca, const Color_tpl<T>& cb);
inline void minimum(const Color_tpl<T>& ca, const Color_tpl<T>& cb);
inline void abs();
inline void adjust_contrast(T c);
inline void adjust_saturation(T s);
inline void adjust_luminance(float newLum);
inline void lerpFloat(const Color_tpl<T>& ca, const Color_tpl<T>& cb, float s);
inline void negative(const Color_tpl<T>& c);
inline void grey(const Color_tpl<T>& c);
// helper function - maybe we can improve the integration
static inline uint32 ComputeAvgCol_Fast(const uint32 dwCol0, const uint32 dwCol1)
{
uint32 dwHalfCol0 = (dwCol0 / 2) & 0x7f7f7f7f; // each component /2
uint32 dwHalfCol1 = (dwCol1 / 2) & 0x7f7f7f7f; // each component /2
return dwHalfCol0 + dwHalfCol1;
}
// mCIE: adjusted to compensate problems of DXT compression (extra bit in green channel causes green/purple artifacts)
// explained in CryEngine wiki: ColorSpaces
Color_tpl<T> RGB2mCIE() const
{
Color_tpl<T> in = *this;
// to get grey chrominance for dark colors
in.r += 0.000001f;
in.g += 0.000001f;
in.b += 0.000001f;
float RGBSum = in.r + in.g + in.b;
float fInv = 1.0f / RGBSum;
float RNorm = 3 * 10.0f / 31.0f * in.r * fInv;
float GNorm = 3 * 21.0f / 63.0f * in.g * fInv;
float Scale = RGBSum / 3.0f;
// test grey
// out.r = 10.0f/31.0f; // 1/3 = 10/30 Red range 0..30, 31 unused
// out.g = 21.0f/63.0f; // 1/3 = 21/63 Green range 0..63
RNorm = max(0.0f, min(1.0f, RNorm));
GNorm = max(0.0f, min(1.0f, GNorm));
return Color_tpl<T>(RNorm, GNorm, Scale);
}
// mCIE: adjusted to compensate problems of DXT compression (extra bit in green channel causes green/purple artefacts)
// explained in CryEngine wiki: ColorSpaces
Color_tpl<T> mCIE2RGB() const
{
Color_tpl<T> out = *this;
float fScale = out.b; // Blue range 0..31
// test grey
// out.r = 10.0f/31.0f; // 1/3 = 10/30 Red range 0..30, 31 unused
// out.g = 21.0f/63.0f; // 1/3 = 21/63 Green range 0..63
out.r *= 31.0f / 30.0f; //
out.g *= 63.0f / 63.0f; //
out.b = 0.999f - out.r - out.g;
float s = 3.0f * fScale;
out.r *= s;
out.g *= s;
out.b *= s;
out.Clamp();
return out;
}
void rgb2srgb()
{
for (int i = 0; i < 3; i++)
{
T& c = (*this)[i];
if (c < 0.0031308f)
{
c = 12.92f * c;
}
else
{
c = 1.055f * pow(c, 1.0f / 2.4f) - 0.055f;
}
}
}
void srgb2rgb()
{
for (int i = 0; i < 3; i++)
@@ -355,8 +189,6 @@ struct Color_tpl
}
}
void GetMemoryUsage([[maybe_unused]] class ICrySizer* pSizer) const { /*nothing*/}
AZStd::array<T, 4> GetAsArray() const
{
AZStd::array<T, 4> primitiveArray = { { r, g, b, a } };
@@ -512,35 +344,10 @@ ILINE Color_tpl<uint8>::Color_tpl(const Vec4& c)
a = (uint8)(c.w * 255);
}
template<>
inline void Color_tpl<uint8>::toFloat4(f32* out) const
{
out[0] = r / 255.0f;
out[1] = g / 255.0f;
out[2] = b / 255.0f;
out[3] = a / 255.0f;
}
template<>
inline void Color_tpl<f32>::toFloat4(f32* out) const
{
out[0] = r;
out[1] = g;
out[2] = b;
out[3] = a;
}
//////////////////////////////////////////////////////////////////////////////////////////////
// functions implementation
///////////////////////////////////////////////
///////////////////////////////////////////////
/*template <class T>
inline Color_tpl<T>::Color_tpl(const T *p_elts)
{
r = p_elts[0]; g = p_elts[1]; b = p_elts[2]; a = p_elts[3];
}*/
///////////////////////////////////////////////
///////////////////////////////////////////////
template <class T>
@@ -549,178 +356,6 @@ ILINE Color_tpl<T> operator * (T s, const Color_tpl<T>& v)
return Color_tpl<T>(v.r * s, v.g * s, v.b * s, v.a * s);
}
///////////////////////////////////////////////
template <class T>
ILINE unsigned char Color_tpl<T>::pack_rgb332() const
{
unsigned char cr;
unsigned char cg;
unsigned char cb;
if constexpr (sizeof(r) == 1) // char and unsigned char
{
cr = (unsigned char)r;
cg = (unsigned char)g;
cb = (unsigned char)b;
}
else if constexpr (sizeof(r) == 2) // short and unsigned short
{
cr = (unsigned short)(r) >> 8;
cg = (unsigned short)(g) >> 8;
cb = (unsigned short)(b) >> 8;
}
else // float or double
{
cr = (unsigned char)(r * 255.0f);
cg = (unsigned char)(g * 255.0f);
cb = (unsigned char)(b * 255.0f);
}
return ((cr >> 5) << 5) | ((cg >> 5) << 2) | (cb >> 5);
}
///////////////////////////////////////////////
template <class T>
ILINE unsigned short Color_tpl<T>::pack_argb4444() const
{
unsigned char cr;
unsigned char cg;
unsigned char cb;
unsigned char ca;
if constexpr (sizeof(r) == 1) // char and unsigned char
{
cr = (unsigned char)r;
cg = (unsigned char)g;
cb = (unsigned char)b;
ca = (unsigned char)a;
}
else if constexpr (sizeof(r) == 2) // short and unsigned short
{
cr = (unsigned short)(r) >> 8;
cg = (unsigned short)(g) >> 8;
cb = (unsigned short)(b) >> 8;
ca = (unsigned short)(a) >> 8;
}
else // float or double
{
cr = (unsigned char)(r * 255.0f);
cg = (unsigned char)(g * 255.0f);
cb = (unsigned char)(b * 255.0f);
ca = (unsigned char)(a * 255.0f);
}
return ((ca >> 4) << 12) | ((cr >> 4) << 8) | ((cg >> 4) << 4) | (cb >> 4);
}
///////////////////////////////////////////////
template <class T>
ILINE unsigned short Color_tpl<T>::pack_rgb555() const
{
unsigned char cr;
unsigned char cg;
unsigned char cb;
if constexpr (sizeof(r) == 1) // char and unsigned char
{
cr = (unsigned char)r;
cg = (unsigned char)g;
cb = (unsigned char)b;
}
else if constexpr (sizeof(r) == 2) // short and unsigned short
{
cr = (unsigned short)(r) >> 8;
cg = (unsigned short)(g) >> 8;
cb = (unsigned short)(b) >> 8;
}
else // float or double
{
cr = (unsigned char)(r * 255.0f);
cg = (unsigned char)(g * 255.0f);
cb = (unsigned char)(b * 255.0f);
}
return ((cr >> 3) << 10) | ((cg >> 3) << 5) | (cb >> 3);
}
///////////////////////////////////////////////
template <class T>
ILINE unsigned short Color_tpl<T>::pack_rgb565() const
{
unsigned short cr;
unsigned short cg;
unsigned short cb;
if constexpr (sizeof(r) == 1) // char and unsigned char
{
cr = (unsigned short)r;
cg = (unsigned short)g;
cb = (unsigned short)b;
}
else if constexpr (sizeof(r) == 2) // short and unsigned short
{
cr = (unsigned short)(r) >> 8;
cg = (unsigned short)(g) >> 8;
cb = (unsigned short)(b) >> 8;
}
else // float or double
{
cr = (unsigned short)(r * 255.0f);
cg = (unsigned short)(g * 255.0f);
cb = (unsigned short)(b * 255.0f);
}
return ((cr >> 3) << 11) | ((cg >> 2) << 5) | (cb >> 3);
}
///////////////////////////////////////////////
template <class T>
ILINE unsigned int Color_tpl<T>::pack_bgr888() const
{
unsigned char cr;
unsigned char cg;
unsigned char cb;
if constexpr (sizeof(r) == 1) // char and unsigned char
{
cr = (unsigned char)r;
cg = (unsigned char)g;
cb = (unsigned char)b;
}
else if constexpr (sizeof(r) == 2) // short and unsigned short
{
cr = (unsigned short)(r) >> 8;
cg = (unsigned short)(g) >> 8;
cb = (unsigned short)(b) >> 8;
}
else // float or double
{
cr = (unsigned char)(r * 255.0f);
cg = (unsigned char)(g * 255.0f);
cb = (unsigned char)(b * 255.0f);
}
return (cb << 16) | (cg << 8) | cr;
}
///////////////////////////////////////////////
template <class T>
ILINE unsigned int Color_tpl<T>::pack_rgb888() const
{
unsigned char cr;
unsigned char cg;
unsigned char cb;
if constexpr (sizeof(r) == 1) // char and unsigned char
{
cr = (unsigned char)r;
cg = (unsigned char)g;
cb = (unsigned char)b;
}
else if constexpr (sizeof(r) == 2) // short and unsigned short
{
cr = (unsigned short)(r) >> 8;
cg = (unsigned short)(g) >> 8;
cb = (unsigned short)(b) >> 8;
}
else // float or double
{
cr = (unsigned char)(r * 255.0f);
cg = (unsigned char)(g * 255.0f);
cb = (unsigned char)(b * 255.0f);
}
return (cr << 16) | (cg << 8) | cb;
}
///////////////////////////////////////////////
template <class T>
ILINE unsigned int Color_tpl<T>::pack_abgr8888() const
@@ -786,211 +421,6 @@ ILINE unsigned int Color_tpl<T>::pack_argb8888() const
return (ca << 24) | (cr << 16) | (cg << 8) | cb;
}
///////////////////////////////////////////////
template <class T>
inline void Color_tpl<T>::toHSV(f32& h, f32& s, f32& v) const
{
f32 red, green, blue;
if constexpr (sizeof(this->r) == 1) // 8bit integer
{
red = this->r * (1.0f / f32(0xff));
green = this->g * (1.0f / f32(0xff));
blue = this->b * (1.0f / f32(0xff));
}
else if constexpr (sizeof(this->r) == 2) // 16bit integer
{
red = this->r * (1.0f / f32(0xffff));
green = this->g * (1.0f / f32(0xffff));
blue = this->b * (1.0f / f32(0xffff));
}
else // floating point
{
red = this->r;
green = this->g;
blue = this->b;
}
if ((blue > green) && (blue > red))
{
if (!::iszero(v = blue))
{
const f32 min = red < green ? red : green;
const f32 delta = v - min;
if (!::iszero(delta))
{
s = delta / v;
h = (240.0f / 360.0f) + (red - green) / delta * (60.0f / 360.0f);
}
else
{
s = 0.0f;
h = (240.0f / 360.0f) + (red - green) * (60.0f / 360.0f);
}
if (h < 0.0f)
{
h += 1.0f;
}
}
else
{
s = 0.0f;
h = 0.0f;
}
}
else if (green > red)
{
if (!::iszero(v = green))
{
const f32 min = red < blue ? red : blue;
const f32 delta = v - min;
if (!::iszero(delta))
{
s = delta / v;
h = (120.0f / 360.0f) + (blue - red) / delta * (60.0f / 360.0f);
}
else
{
s = 0.0f;
h = (120.0f / 360.0f) + (blue - red) * (60.0f / 360.0f);
}
if (h < 0.0f)
{
h += 1.0f;
}
}
else
{
s = 0.0f;
h = 0.0f;
}
}
else
{
if (!::iszero(v = red))
{
const f32 min = green < blue ? green : blue;
const f32 delta = v - min;
if (!::iszero(delta))
{
s = delta / v;
h = (green - blue) / delta * (60.0f / 360.0f);
}
else
{
s = 0.0f;
h = (green - blue) * (60.0f / 360.0f);
}
if (h < 0.0f)
{
h += 1.0f;
}
}
else
{
s = 0.0f;
h = 0.0f;
}
}
}
///////////////////////////////////////////////
template <class T>
inline void Color_tpl<T>::fromHSV(f32 h, f32 s, f32 v)
{
f32 red, green, blue;
if (::iszero(v))
{
red = 0.0f;
green = 0.0f;
blue = 0.0f;
}
else if (::iszero(s))
{
red = v;
green = v;
blue = v;
}
else
{
const f32 hi = h * 6.0f;
const int32 i = (int32)::floor(hi);
const f32 f = hi - i;
const f32 v0 = v * (1.0f - s);
const f32 v1 = v * (1.0f - s * f);
const f32 v2 = v * (1.0f - s * (1.0f - f));
switch (i)
{
case 0:
red = v;
green = v2;
blue = v0;
break;
case 1:
red = v1;
green = v;
blue = v0;
break;
case 2:
red = v0;
green = v;
blue = v2;
break;
case 3:
red = v0;
green = v1;
blue = v;
break;
case 4:
red = v2;
green = v0;
blue = v;
break;
case 5:
red = v;
green = v0;
blue = v1;
break;
case 6:
red = v;
green = v2;
blue = v0;
break;
case -1:
red = v;
green = v0;
blue = v1;
break;
default:
red = 0.0f;
green = 0.0f;
blue = 0.0f;
break;
}
}
if constexpr (sizeof(this->r) == 1) // 8bit integer
{
this->r = red * f32(0xff);
this->g = green * f32(0xff);
this->b = blue * f32(0xff);
}
else if constexpr (sizeof(this->r) == 2) // 16bit integer
{
this->r = red * f32(0xffff);
this->g = green * f32(0xffff);
this->b = blue * f32(0xffff);
}
else // floating point
{
this->r = red;
this->g = green;
this->b = blue;
}
}
///////////////////////////////////////////////
template <class T>
inline void Color_tpl<T>::clamp(T bottom, T top)
@@ -1001,214 +431,5 @@ inline void Color_tpl<T>::clamp(T bottom, T top)
a = min(top, max(bottom, a));
}
///////////////////////////////////////////////
template <class T>
inline void Color_tpl<T>::maximum(const Color_tpl<T>& ca, const Color_tpl<T>& cb)
{
r = max(ca.r, cb.r);
g = max(ca.g, cb.g);
b = max(ca.b, cb.b);
a = max(ca.a, cb.a);
}
///////////////////////////////////////////////
template <class T>
inline void Color_tpl<T>::minimum(const Color_tpl<T>& ca, const Color_tpl<T>& cb)
{
r = min(ca.r, cb.r);
g = min(ca.g, cb.g);
b = min(ca.b, cb.b);
a = min(ca.a, cb.a);
}
///////////////////////////////////////////////
template <class T>
inline void Color_tpl<T>::abs()
{
r = fabs_tpl(r);
g = fabs_tpl(g);
b = fabs_tpl(b);
a = fabs_tpl(a);
}
///////////////////////////////////////////////
template <class T>
inline void Color_tpl<T>::adjust_contrast(T c)
{
r = 0.5f + c * (r - 0.5f);
g = 0.5f + c * (g - 0.5f);
b = 0.5f + c * (b - 0.5f);
a = 0.5f + c * (a - 0.5f);
}
///////////////////////////////////////////////
template <class T>
inline void Color_tpl<T>::adjust_saturation(T s)
{
// Approximate values for each component's contribution to luminance.
// Based upon the NTSC standard described in ITU-R Recommendation BT.709.
T grey = r * 0.2125f + g * 0.7154f + b * 0.0721f;
r = grey + s * (r - grey);
g = grey + s * (g - grey);
b = grey + s * (b - grey);
a = grey + s * (a - grey);
}
///////////////////////////////////////////////
template <class T>
inline void Color_tpl<T>::adjust_luminance(float newLum)
{
// Optimized yet equivalent version of replacing luminance in XYZ space.
// Color and luminance are expected to be linear.
Color_tpl<f32> colF(r, g, b, a);
float lum = colF.r * 0.212671f + colF.g * 0.715160f + colF.b * 0.072169f;
if (iszero(lum))
{
return;
}
*this = Color_tpl<T>(colF * newLum / lum);
}
///////////////////////////////////////////////
template <class T>
inline void Color_tpl<T>::lerpFloat(const Color_tpl<T>& ca, const Color_tpl<T>& cb, float s)
{
r = (T)(ca.r + s * (cb.r - ca.r));
g = (T)(ca.g + s * (cb.g - ca.g));
b = (T)(ca.b + s * (cb.b - ca.b));
a = (T)(ca.a + s * (cb.a - ca.a));
}
///////////////////////////////////////////////
template <class T>
inline void Color_tpl<T>::negative([[maybe_unused]] const Color_tpl<T>& c)
{
r = T(1.0f) - r;
g = T(1.0f) - g;
b = T(1.0f) - b;
a = T(1.0f) - a;
}
///////////////////////////////////////////////
template <class T>
inline void Color_tpl<T>::grey([[maybe_unused]] const Color_tpl<T>& c)
{
T m = (r + g + b) / T(3);
r = m;
g = m;
b = m;
}
//////////////////////////////////////////////////////////////////////////////////////////////
//#define RGBA8(r,g,b,a) (ColorB((uint8)(r),(uint8)(g),(uint8)(b),(uint8)(a)))
#if defined(NEED_ENDIAN_SWAP)
#define RGBA8(a, b, g, r) ((uint32)(((uint8)(r) | ((uint16)((uint8)(g)) << 8)) | (((uint32)(uint8)(b)) << 16)) | (((uint32)(uint8)(a)) << 24))
#else
#define RGBA8(r, g, b, a) ((uint32)(((uint8)(r) | ((uint16)((uint8)(g)) << 8)) | (((uint32)(uint8)(b)) << 16)) | (((uint32)(uint8)(a)) << 24))
#endif
#define Col_Black ColorF (0.000f, 0.000f, 0.000f) // 0xFF000000 RGB: 0, 0, 0
#define Col_White ColorF (1.000f, 1.000f, 1.000f) // 0xFFFFFFFF RGB: 255, 255, 255
#define Col_Aquamarine ColorF (0.498f, 1.000f, 0.831f) // 0xFF7FFFD4 RGB: 127, 255, 212
#define Col_Azure ColorF (0.000f, 0.498f, 1.000f) // 0xFF007FFF RGB: 0, 127, 255
#define Col_Blue ColorF (0.000f, 0.000f, 1.000f) // 0xFF0000FF RGB: 0, 0, 255
#define Col_BlueViolet ColorF (0.541f, 0.169f, 0.886f) // 0xFF8A2BE2 RGB: 138, 43, 226
#define Col_Brown ColorF (0.647f, 0.165f, 0.165f) // 0xFFA52A2A RGB: 165, 42, 42
#define Col_CadetBlue ColorF (0.373f, 0.620f, 0.627f) // 0xFF5F9EA0 RGB: 95, 158, 160
#define Col_Coral ColorF (1.000f, 0.498f, 0.314f) // 0xFFFF7F50 RGB: 255, 127, 80
#define Col_CornflowerBlue ColorF (0.392f, 0.584f, 0.929f) // 0xFF6495ED RGB: 100, 149, 237
#define Col_Cyan ColorF (0.000f, 1.000f, 1.000f) // 0xFF00FFFF RGB: 0, 255, 255
#define Col_DarkGray ColorF (0.663f, 0.663f, 0.663f) // 0xFFA9A9A9 RGB: 169, 169, 169
#define Col_DarkGrey ColorF (0.663f, 0.663f, 0.663f) // 0xFFA9A9A9 RGB: 169, 169, 169
#define Col_DarkGreen ColorF (0.000f, 0.392f, 0.000f) // 0xFF006400 RGB: 0, 100, 0
#define Col_DarkOliveGreen ColorF (0.333f, 0.420f, 0.184f) // 0xFF556B2F RGB: 85, 107, 47
#define Col_DarkOrchid ColorF (0.600f, 0.196f, 0.800f) // 0xFF9932CC RGB: 153, 50, 204
#define Col_DarkSlateBlue ColorF (0.282f, 0.239f, 0.545f) // 0xFF483D8B RGB: 72, 61, 139
#define Col_DarkSlateGray ColorF (0.184f, 0.310f, 0.310f) // 0xFF2F4F4F RGB: 47, 79, 79
#define Col_DarkSlateGrey ColorF (0.184f, 0.310f, 0.310f) // 0xFF2F4F4F RGB: 47, 79, 79
#define Col_DarkTurquoise ColorF (0.000f, 0.808f, 0.820f) // 0xFF00CED1 RGB: 0, 206, 209
#define Col_DarkWood ColorF (0.050f, 0.010f, 0.005f) // 0xFF0D0301 RGB: 13, 3, 1
#define Col_DeepPink ColorF (1.000f, 0.078f, 0.576f) // 0xFFFF1493 RGB: 255, 20, 147
#define Col_DimGray ColorF (0.412f, 0.412f, 0.412f) // 0xFF696969 RGB: 105, 105, 105
#define Col_DimGrey ColorF (0.412f, 0.412f, 0.412f) // 0xFF696969 RGB: 105, 105, 105
#define Col_FireBrick ColorF (0.698f, 0.133f, 0.133f) // 0xFFB22222 RGB: 178, 34, 34
#define Col_ForestGreen ColorF (0.133f, 0.545f, 0.133f) // 0xFF228B22 RGB: 34, 139, 34
#define Col_Gold ColorF (1.000f, 0.843f, 0.000f) // 0xFFFFD700 RGB: 255, 215, 0
#define Col_Goldenrod ColorF (0.855f, 0.647f, 0.125f) // 0xFFDAA520 RGB: 218, 165, 32
#define Col_Gray ColorF (0.502f, 0.502f, 0.502f) // 0xFF808080 RGB: 128, 128, 128
#define Col_Grey ColorF (0.502f, 0.502f, 0.502f) // 0xFF808080 RGB: 128, 128, 128
#define Col_Green ColorF (0.000f, 0.502f, 0.000f) // 0xFF008000 RGB: 0, 128, 0
#define Col_GreenYellow ColorF (0.678f, 1.000f, 0.184f) // 0xFFADFF2F RGB: 173, 255, 47
#define Col_IndianRed ColorF (0.804f, 0.361f, 0.361f) // 0xFFCD5C5C RGB: 205, 92, 92
#define Col_Khaki ColorF (0.941f, 0.902f, 0.549f) // 0xFFF0E68C RGB: 240, 230, 140
#define Col_LightBlue ColorF (0.678f, 0.847f, 0.902f) // 0xFFADD8E6 RGB: 173, 216, 230
#define Col_LightGray ColorF (0.827f, 0.827f, 0.827f) // 0xFFD3D3D3 RGB: 211, 211, 211
#define Col_LightGrey ColorF (0.827f, 0.827f, 0.827f) // 0xFFD3D3D3 RGB: 211, 211, 211
#define Col_LightSteelBlue ColorF (0.690f, 0.769f, 0.871f) // 0xFFB0C4DE RGB: 176, 196, 222
#define Col_LightWood ColorF (0.600f, 0.240f, 0.100f) // 0xFF993D1A RGB: 153, 61, 26
#define Col_Lime ColorF (0.000f, 1.000f, 0.000f) // 0xFF00FF00 RGB: 0, 255, 0
#define Col_LimeGreen ColorF (0.196f, 0.804f, 0.196f) // 0xFF32CD32 RGB: 50, 205, 50
#define Col_Magenta ColorF (1.000f, 0.000f, 1.000f) // 0xFFFF00FF RGB: 255, 0, 255
#define Col_Maroon ColorF (0.502f, 0.000f, 0.000f) // 0xFF800000 RGB: 128, 0, 0
#define Col_MedianWood ColorF (0.300f, 0.120f, 0.030f) // 0xFF4D1F09 RGB: 77, 31, 9
#define Col_MediumAquamarine ColorF (0.400f, 0.804f, 0.667f) // 0xFF66CDAA RGB: 102, 205, 170
#define Col_MediumBlue ColorF (0.000f, 0.000f, 0.804f) // 0xFF0000CD RGB: 0, 0, 205
#define Col_MediumForestGreen ColorF (0.420f, 0.557f, 0.137f) // 0xFF6B8E23 RGB: 107, 142, 35
#define Col_MediumGoldenrod ColorF (0.918f, 0.918f, 0.678f) // 0xFFEAEAAD RGB: 234, 234, 173
#define Col_MediumOrchid ColorF (0.729f, 0.333f, 0.827f) // 0xFFBA55D3 RGB: 186, 85, 211
#define Col_MediumSeaGreen ColorF (0.235f, 0.702f, 0.443f) // 0xFF3CB371 RGB: 60, 179, 113
#define Col_MediumSlateBlue ColorF (0.482f, 0.408f, 0.933f) // 0xFF7B68EE RGB: 123, 104, 238
#define Col_MediumSpringGreen ColorF (0.000f, 0.980f, 0.604f) // 0xFF00FA9A RGB: 0, 250, 154
#define Col_MediumTurquoise ColorF (0.282f, 0.820f, 0.800f) // 0xFF48D1CC RGB: 72, 209, 204
#define Col_MediumVioletRed ColorF (0.780f, 0.082f, 0.522f) // 0xFFC71585 RGB: 199, 21, 133
#define Col_MidnightBlue ColorF (0.098f, 0.098f, 0.439f) // 0xFF191970 RGB: 25, 25, 112
#define Col_Navy ColorF (0.000f, 0.000f, 0.502f) // 0xFF000080 RGB: 0, 0, 128
#define Col_NavyBlue ColorF (0.137f, 0.137f, 0.557f) // 0xFF23238E RGB: 35, 35, 142
#define Col_Orange ColorF (1.000f, 0.647f, 0.000f) // 0xFFFFA500 RGB: 255, 165, 0
#define Col_OrangeRed ColorF (1.000f, 0.271f, 0.000f) // 0xFFFF4500 RGB: 255, 69, 0
#define Col_Orchid ColorF (0.855f, 0.439f, 0.839f) // 0xFFDA70D6 RGB: 218, 112, 214
#define Col_PaleGreen ColorF (0.596f, 0.984f, 0.596f) // 0xFF98FB98 RGB: 152, 251, 152
#define Col_Pink ColorF (1.000f, 0.753f, 0.796f) // 0xFFFFC0CB RGB: 255, 192, 203
#define Col_Plum ColorF (0.867f, 0.627f, 0.867f) // 0xFFDDA0DD RGB: 221, 160, 221
#define Col_Red ColorF (1.000f, 0.000f, 0.000f) // 0xFFFF0000 RGB: 255, 0, 0
#define Col_Salmon ColorF (0.980f, 0.502f, 0.447f) // 0xFFFA8072 RGB: 250, 128, 114
#define Col_SeaGreen ColorF (0.180f, 0.545f, 0.341f) // 0xFF2E8B57 RGB: 46, 139, 87
#define Col_Sienna ColorF (0.627f, 0.322f, 0.176f) // 0xFFA0522D RGB: 160, 82, 45
#define Col_SkyBlue ColorF (0.529f, 0.808f, 0.922f) // 0xFF87CEEB RGB: 135, 206, 235
#define Col_SlateBlue ColorF (0.416f, 0.353f, 0.804f) // 0xFF6A5ACD RGB: 106, 90, 205
#define Col_SpringGreen ColorF (0.000f, 1.000f, 0.498f) // 0xFF00FF7F RGB: 0, 255, 127
#define Col_SteelBlue ColorF (0.275f, 0.510f, 0.706f) // 0xFF4682B4 RGB: 70, 130, 180
#define Col_Tan ColorF (0.824f, 0.706f, 0.549f) // 0xFFD2B48C RGB: 210, 180, 140
#define Col_Thistle ColorF (0.847f, 0.749f, 0.847f) // 0xFFD8BFD8 RGB: 216, 191, 216
#define Col_Transparent ColorF (0.0f, 0.0f, 0.0f, 0.0f) // 0x00000000 RGB: 0, 0, 0
#define Col_Turquoise ColorF (0.251f, 0.878f, 0.816f) // 0xFF40E0D0 RGB: 64, 224, 208
#define Col_Violet ColorF (0.933f, 0.510f, 0.933f) // 0xFFEE82EE RGB: 238, 130, 238
#define Col_VioletRed ColorF (0.800f, 0.196f, 0.600f) // 0xFFCC3299 RGB: 204, 50, 153
#define Col_Wheat ColorF (0.961f, 0.871f, 0.702f) // 0xFFF5DEB3 RGB: 245, 222, 179
#define Col_Yellow ColorF (1.000f, 1.000f, 0.000f) // 0xFFFFFF00 RGB: 255, 255, 0
#define Col_YellowGreen ColorF (0.604f, 0.804f, 0.196f) // 0xFF9ACD32 RGB: 154, 205, 50
#define Col_TrackviewDefault ColorF (0.187820792f, 0.187820792f, 1.0f)
#define Clr_Empty ColorF(0.0f, 0.0f, 0.0f, 1.0f)
#define Clr_Dark ColorF(0.15f, 0.15f, 0.15f, 1.0f)
#define Clr_White ColorF(1.0f, 1.0f, 1.0f, 1.0f)
#define Clr_WhiteTrans ColorF(1.0f, 1.0f, 1.0f, 0.0f)
#define Clr_Full ColorF(1.0f, 1.0f, 1.0f, 1.0f)
#define Clr_Neutral ColorF(1.0f, 1.0f, 1.0f, 1.0f)
#define Clr_Transparent ColorF(0.0f, 0.0f, 0.0f, 0.0f)
#define Clr_FrontVector ColorF(0.0f, 0.0f, 0.5f, 1.0f)
#define Clr_Static ColorF(127.0f / 255.0f, 127.0f / 255.0f, 0.0f, 0.0f)
#define Clr_Median ColorF(0.5f, 0.5f, 0.5f, 0.0f)
#define Clr_MedianHalf ColorF(0.5f, 0.5f, 0.5f, 0.5f)
#define Clr_FarPlane ColorF(1.0f, 0.0f, 0.0f, 0.0f)
#define Clr_FarPlane_R ColorF(bReverseDepth ? 0.0f : 1.0f, 0.0f, 0.0f, 0.0f)
#define Clr_Unknown ColorF(0.0f, 0.0f, 0.0f, 0.0f)
#define Clr_Unused ColorF(0.0f, 0.0f, 0.0f, 0.0f)
#define Clr_Debug ColorF(1.0f, 0.0f, 0.0f, 1.0f)
#endif // CRYINCLUDE_CRYCOMMON_CRY_COLOR_H
+7 -790
View File
@@ -8,10 +8,6 @@
// Description : Common structures for geometry computations
#ifndef CRYINCLUDE_CRYCOMMON_CRY_GEO_H
#define CRYINCLUDE_CRYCOMMON_CRY_GEO_H
#pragma once
#include "Cry_Math.h"
@@ -29,11 +25,6 @@ struct AABB;
template <typename F>
struct OBB_tpl;
struct Sphere;
struct AAEllipsoid;
struct Ellipsoid;
struct Cone;
//-----------------------------------------------------
@@ -41,127 +32,12 @@ struct Cone;
// Definitions //
///////////////////////////////////////////////////////////////////////////////
//
// Random geometry generation functions.
//
enum EGeomForm
{
GeomForm_Vertices,
GeomForm_Edges,
GeomForm_Surface,
GeomForm_Volume,
MaxGeomForm
};
enum EGeomType
{
GeomType_None,
GeomType_BoundingBox,
GeomType_Physics,
GeomType_Render,
};
struct PosNorm
{
Vec3 vPos;
Vec3 vNorm;
void zero()
{
vPos.zero();
vNorm.zero();
}
// transform by matrix, etc
void operator <<= (Matrix34 const& mx)
{
vPos = mx * vPos;
vNorm = Matrix33(mx) * vNorm;
}
void operator <<= (QuatTS const& qts)
{
vPos = qts * vPos;
vNorm = qts.q * vNorm;
}
void operator <<= (DualQuat const& dq)
{
vPos = dq * vPos;
vNorm = dq.nq * vNorm;
}
};
struct RectF
{
float x, y, w, h;
RectF()
: x(0)
, y(0)
, w(1)
, h(1)
{
}
};
struct RectI
{
int x, y, w, h;
RectI()
: x(0)
, y(0)
, w(1)
, h(1)
{
}
RectI(int inX, int inY, int inW, int inH)
: x(inX)
, y(inY)
, w(inW)
, h(inH)
{
}
_inline void Add(RectI rcAdd)
{
int x2 = x + w;
int y2 = y + h;
int x22 = rcAdd.x + rcAdd.w;
int y22 = rcAdd.y + rcAdd.h;
x = min(x, rcAdd.x);
y = min(y, rcAdd.y);
x2 = max(x2, x22);
y2 = max(y2, y22);
w = x2 - x;
h = y2 - y;
}
_inline void Add(int inX, int inY, int inW, int inH)
{
Add(RectI(inX, inY, inW, inH));
}
};
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// struct Line
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
struct Line
{
Vec3 pointonline;
Vec3 direction; //caution: the direction is important for any intersection test
//default Line constructor (without initialisation)
inline Line(void) {}
inline Line(const Vec3& o, const Vec3& d) { pointonline = o; direction = d; }
inline void operator () (const Vec3& o, const Vec3& d) { pointonline = o; direction = d; }
~Line(void) {};
};
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
@@ -190,26 +66,18 @@ struct Ray
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
template <typename F>
struct Lineseg_tpl
struct Lineseg
{
Vec3_tpl<F> start;
Vec3_tpl<F> end;
Vec3_tpl<float> start;
Vec3_tpl<float> end;
//default Lineseg constructor (without initialisation)
inline Lineseg_tpl(void) {}
inline Lineseg_tpl(const Vec3_tpl<F>& s, const Vec3_tpl<F>& e) { start = s; end = e; }
inline void operator () (const Vec3_tpl<F>& s, const Vec3_tpl<F>& e) { start = s; end = e; }
inline Lineseg(void) {}
inline Lineseg(const Vec3_tpl<float>& s, const Vec3_tpl<float>& e) { start = s; end = e; }
Vec3 GetPoint(F t) const {return t * end + (F(1.0) - t) * start; }
~Lineseg_tpl(void) {};
~Lineseg(void) {};
};
typedef Lineseg_tpl<float> Lineseg;
typedef Lineseg_tpl<real> Linesegr;
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
@@ -240,33 +108,6 @@ struct Triangle_tpl
}
};
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// struct Cone
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
struct Cone
{
Vec3 mTip;
Vec3 mDir;
Vec3 mBase;
float mHeight;
float mBaseRadius;
Cone() {}
Cone(const Vec3& tip, const Vec3& dir, float height, float baseRadius)
: mTip(tip)
, mDir(dir)
, mBase(tip + dir * height)
, mHeight(height)
, mBaseRadius(baseRadius) {}
};
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
@@ -343,12 +184,6 @@ struct AABB
ILINE float GetRadius() const
{ return IsResetSel(0.0f, (max - min).GetLengthFloat() * 0.5f); }
ILINE float GetRadiusSqr() const
{ return IsResetSel(0.0f, ((max - min) * 0.5f).GetLengthSquaredFloat()); }
ILINE float GetVolume() const
{ return IsResetSel(0.0f, (max.x - min.x) * (max.y - min.y) * (max.z - min.z)); }
ILINE void Add(const Vec3& v)
{
min.CheckMin(v);
@@ -368,133 +203,6 @@ struct AABB
max.CheckMax(bb.max);
}
inline void Move(const Vec3& v)
{
const float moveMult = IsResetSel(0.0f, 1.0f);
const Vec3 vMove = v * moveMult;
min += vMove;
max += vMove;
}
inline void Expand(Vec3 const& v)
{
if (!IsReset())
{
min -= v;
max += v;
}
}
// Augment the box on all sides by a box.
inline void Augment(AABB const& bb)
{
if (!IsReset() && !bb.IsReset())
{
Add(min + bb.min);
Add(max + bb.max);
}
}
void ClipToBox(AABB const& bb)
{
min.CheckMax(bb.min);
max.CheckMin(bb.max);
}
void ClipMoveToBox(AABB const& bb)
{
for (int a = 0; a < 3; a++)
{
if (max[a] - min[a] > bb.max[a] - bb.min[a])
{
min[a] = bb.min[a];
max[a] = bb.max[a];
}
else if (min[a] < bb.min[a])
{
max[a] += bb.min[a] - min[a];
min[a] = bb.min[a];
}
else if (max[a] > bb.max[a])
{
min[a] += bb.max[a] - max[a];
max[a] = bb.max[a];
}
}
}
//! Check if this bounding box overlap with bounding box of sphere.
bool IsOverlapSphereBounds(const Vec3& pos, float radius) const
{
assert(min.IsValid());
assert(max.IsValid());
assert(pos.IsValid());
if (pos.x > min.x && pos.x < max.x && pos.y > min.y && pos.y < max.y && pos.z > min.z && pos.z < max.z)
{
return true;
}
if (pos.x + radius < min.x)
{
return false;
}
if (pos.y + radius < min.y)
{
return false;
}
if (pos.z + radius < min.z)
{
return false;
}
if (pos.x - radius > max.x)
{
return false;
}
if (pos.y - radius > max.y)
{
return false;
}
if (pos.z - radius > max.z)
{
return false;
}
return true;
}
//! Check if this bounding box contain sphere within itself.
bool IsContainSphere(const Vec3& pos, float radius) const
{
assert(min.IsValid());
assert(max.IsValid());
assert(pos.IsValid());
if (pos.x - radius < min.x)
{
return false;
}
if (pos.y - radius < min.y)
{
return false;
}
if (pos.z - radius < min.z)
{
return false;
}
if (pos.x + radius > max.x)
{
return false;
}
if (pos.y + radius > max.y)
{
return false;
}
if (pos.z + radius > max.z)
{
return false;
}
return true;
}
//! Check if this bounding box contains a point within itself.
bool IsContainPoint(const Vec3& pos) const
{
@@ -541,27 +249,6 @@ struct AABB
return sqrt(GetDistanceSqr(v));
}
bool ContainsBox(AABB const& b) const
{
assert(min.IsValid());
assert(max.IsValid());
assert(b.min.IsValid());
assert(b.max.IsValid());
return min.x <= b.min.x && min.y <= b.min.y && min.z <= b.min.z
&& max.x >= b.max.x && max.y >= b.max.y && max.z >= b.max.z;
}
bool ContainsBox2D(AABB const& b) const
{
assert(min.IsValid());
assert(max.IsValid());
assert(b.min.IsValid());
assert(b.max.IsValid());
return min.x <= b.min.x && min.y <= b.min.y
&& max.x >= b.max.x && max.y >= b.max.y;
}
// Check two bounding boxes for intersection.
inline bool IsIntersectBox(const AABB& b) const
{
@@ -622,86 +309,6 @@ struct AABB
max = pos + sz;
}
}
ILINE static AABB CreateTransformedAABB(const Matrix34& m34, const AABB& aabb)
{ AABB taabb; taabb.SetTransformedAABB(m34, aabb); return taabb; }
ILINE void SetTransformedAABB(const QuatT& qt, const AABB& aabb)
{
if (aabb.IsReset())
{
Reset();
}
else
{
Matrix33 m33 = Matrix33(qt.q);
m33.m00 = fabs_tpl(m33.m00);
m33.m01 = fabs_tpl(m33.m01);
m33.m02 = fabs_tpl(m33.m02);
m33.m10 = fabs_tpl(m33.m10);
m33.m11 = fabs_tpl(m33.m11);
m33.m12 = fabs_tpl(m33.m12);
m33.m20 = fabs_tpl(m33.m20);
m33.m21 = fabs_tpl(m33.m21);
m33.m22 = fabs_tpl(m33.m22);
Vec3 sz = m33 * ((aabb.max - aabb.min) * 0.5f);
Vec3 pos = qt * ((aabb.max + aabb.min) * 0.5f);
min = pos - sz;
max = pos + sz;
}
}
ILINE static AABB CreateTransformedAABB(const QuatT& qt, const AABB& aabb)
{ AABB taabb; taabb.SetTransformedAABB(qt, aabb); return taabb; }
//create an AABB using just the extensions of the OBB and ignore the orientation.
template<typename F>
ILINE void SetAABBfromOBB(const OBB_tpl<F>& obb)
{ min = obb.c - obb.h; max = obb.c + obb.h; }
template<typename F>
ILINE static AABB CreateAABBfromOBB(const OBB_tpl<F>& obb)
{ return AABB(obb.c - obb.h, obb.c + obb.h); }
/*!
* converts an OBB into an tight fitting AABB
*
* Example:
* AABB aabb = AABB::CreateAABBfromOBB(wposition,obb,1.0f);
*
* return values:
* expanded AABB in world-space
*/
template<typename F>
ILINE void SetAABBfromOBB(const Vec3& wpos, const OBB_tpl<F>& obb, f32 scaling = 1.0f)
{
Vec3 pos = obb.m33 * obb.c * scaling + wpos;
Vec3 sz = obb.m33.GetFabs() * obb.h * scaling;
min = pos - sz;
max = pos + sz;
}
template<typename F>
ILINE static AABB CreateAABBfromOBB(const Vec3& wpos, const OBB_tpl<F>& obb, f32 scaling = 1.0f)
{ AABB taabb; taabb.SetAABBfromOBB(wpos, obb, scaling); return taabb; }
/* Converts a Cone into a tight fitting AABB */
ILINE static AABB CreateAABBfromCone(const Cone& c)
{
// Construct AABB for cone base
Vec3 baseX = Vec3(1.f - c.mDir.x * c.mDir.x, c.mDir.x * c.mDir.y, c.mDir.x * c.mDir.z).GetNormalized() * c.mBaseRadius;
Vec3 baseY = Vec3(c.mDir.y * c.mDir.x, 1.f - c.mDir.y * c.mDir.y, c.mDir.y * c.mDir.z).GetNormalized() * c.mBaseRadius;
Vec3 baseZ = Vec3(c.mDir.z * c.mDir.x, c.mDir.z * c.mDir.y, 1.f - c.mDir.z * c.mDir.z).GetNormalized() * c.mBaseRadius;
Vec3 aabbMax = Vec3(baseX.x, baseY.y, baseZ.z).abs();
Vec3 aabbMin = -aabbMax;
AABB result(aabbMin, aabbMax);
result.Move(c.mBase);
// add tip
result.Add(c.mTip);
return result;
}
};
ILINE bool IsEquivalent(const AABB& a, const AABB& b, float epsilon = VEC_EPSILON)
@@ -710,9 +317,6 @@ ILINE bool IsEquivalent(const AABB& a, const AABB& b, float epsilon = VEC_EPSILO
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
@@ -752,6 +356,7 @@ struct OBB_tpl
~OBB_tpl(void) {};
};
typedef OBB_tpl<f32> OBB;
@@ -774,392 +379,4 @@ struct Sphere
void operator()(const Vec3& c, float r) { center = c; radius = r; }
};
struct HWVSphere
{
hwvec3 center;
simdf radius;
ILINE HWVSphere(const hwvec3& c, const simdf& r)
{
center = c;
radius = r;
}
ILINE HWVSphere(const ::Sphere& sp)
{
center = HWVLoadVecUnaligned(&sp.center);
radius = SIMDFLoadFloat(sp.radius);
}
};
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// struct AAEllipsoid
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
struct AAEllipsoid
{
Vec3 center;
Vec3 radius_vec;
//default AAEllipsoid constructor (without initialisation)
inline AAEllipsoid(void) {}
inline AAEllipsoid(const Vec3& c, const Vec3& rv) { radius_vec = rv; center = c; }
inline void operator () (const Vec3& c, const Vec3& rv) { radius_vec = rv; center = c; }
~AAEllipsoid(void) {};
};
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// struct Ellipsoid
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
struct Ellipsoid
{
Matrix34 ExtensionPos;
//default Ellipsoid constructor (without initialisation)
inline Ellipsoid(void) {}
inline Ellipsoid(const Matrix34& ep) { ExtensionPos = ep; }
inline void operator () (const Matrix34& ep) { ExtensionPos = ep; }
~Ellipsoid(void) {};
};
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// struct TRect
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
template <class Num>
struct TRect_tpl
{
typedef Vec2_tpl<Num> Vec;
Vec Min, Max;
inline TRect_tpl() {}
inline TRect_tpl(Num x1, Num y1, Num x2, Num y2)
: Min(x1, y1)
, Max(x2, y2) {}
inline TRect_tpl(const TRect_tpl<Num>& rc)
: Min(rc.Min)
, Max(rc.Max) {}
inline TRect_tpl(const Vec& min, const Vec& max)
: Min(min)
, Max(max) {}
inline TRect_tpl<Num> operator * (Num k) const
{
return TRect_tpl<Num>(Min.x * k, Min.y * k, Max.x * k, Max.y * k);
}
inline TRect_tpl<Num> operator / (Num k) const
{
return TRect_tpl<Num>(Min.x / k, Min.y / k, Max.x / k, Max.y / k);
}
inline bool IsEmpty() const { return Max.x < Min.x && Max.y < Min.y; }
inline TRect_tpl<Num>& SetEmpty() { Max = Vec(-1, -1); Min = Vec(0, 0); return *this; }
inline Vec GetDim() const { return Max - Min; }
inline Num GetWidth() const { return Max.x - Min.x; }
inline Num GetHeight() const { return Max.y - Min.y; }
inline bool IsEqual(const TRect_tpl<Num>& rc) const { return Min.x == rc.Min.x && Min.y == rc.Min.y && Max.x == rc.Max.x && Max.y == rc.Max.y; }
inline bool InRect(const TRect_tpl<Num>& rc) const { return rc.Min.x >= Min.x && rc.Max.x <= Max.x && rc.Min.y >= Min.y && rc.Max.y <= Max.y; }
inline bool InRect(Vec pt) const { return pt.x >= Min.x && pt.x <= Max.x && pt.y >= Min.y && pt.y <= Max.y; }
inline Vec& IntoRect(Vec& pt) const
{
if (pt.x < Min.x)
{
pt.x = Min.x;
}
else if (pt.x > Max.x)
{
pt.x = Max.x;
}
if (pt.y < Min.y)
{
pt.y = Min.y;
}
else if (pt.y > Max.y)
{
pt.y = Max.y;
}
return pt;
}
inline bool Intersects(const TRect_tpl<Num>& rc) const
{
return !IsEmpty() && !rc.IsEmpty() &&
!(Min.x > rc.Max.x || Max.x < rc.Min.x ||
Min.y > rc.Max.y || Max.y < rc.Min.y);
}
inline TRect_tpl<Num>& DoUnite(const TRect_tpl<Num>& rc)
{
if (IsEmpty())
{
Min = rc.Min;
Max = rc.Max;
return *this;
}
if (rc.IsEmpty())
{
return *this;
}
if (Min.x > rc.Min.x)
{
Min.x = rc.Min.x;
}
if (Min.y > rc.Min.y)
{
Min.y = rc.Min.y;
}
if (Max.x < rc.Max.x)
{
Max.x = rc.Max.x;
}
if (Max.y < rc.Max.y)
{
Max.y = rc.Max.y;
}
return *this;
}
inline TRect_tpl<Num>& DoIntersect(const TRect_tpl<Num>& rc)
{
if (IsEmpty())
{
return *this;
}
if (rc.IsEmpty())
{
return SetEmpty();
}
if (Min.x < rc.Min.x)
{
Min.x = rc.Min.x;
}
if (Min.y < rc.Min.y)
{
Min.y = rc.Min.y;
}
if (Max.x > rc.Max.x)
{
Max.x = rc.Max.x;
}
if (Max.y > rc.Max.y)
{
Max.y = rc.Max.y;
}
if (Min.x == Max.x || Min.y == Max.y)
{
return SetEmpty();
}
return *this;
}
inline TRect_tpl<Num> GetSubRect(const TRect_tpl<Num>& rc) const
{
if (IsEmpty())
{
return *this;
}
if (rc.IsEmpty())
{
return rc;
}
return TRect_tpl<Num>(Min.x + rc.Min.x * GetWidth(),
Min.y + rc.Min.y * GetHeight(),
Min.x + rc.Max.x * GetWidth(),
Min.y + rc.Max.y * GetHeight());
}
inline TRect_tpl<Num> GetSubRectInv(const TRect_tpl<Num>& rcSub) const
{
if (IsEmpty())
{
return *this;
}
if (rcSub.IsEmpty())
{
return rcSub;
}
return TRect_tpl((rcSub.Min.x - Min.x) / GetWidth(),
(rcSub.Min.y - Min.y) / GetHeight(),
(rcSub.Max.x - Min.x) / GetWidth(),
(rcSub.Max.y - Min.y) / GetHeight());
}
};
typedef TRect_tpl<float> Rectf;
typedef TRect_tpl<int> Recti;
typedef Triangle_tpl<f32> Triangle;
typedef Triangle_tpl<f64> Triangle_f64;
typedef OBB_tpl<f32> OBB;
//////////////////////////////////////////////////////////////////////////
// Manage linear and rotational 3D velocity in a class
class Velocity3
{
public:
Vec3 vLin, vRot;
Velocity3()
{}
Velocity3(type_zero)
: vLin(ZERO)
, vRot(ZERO) {}
Velocity3(Vec3 const& lin)
: vLin(lin)
, vRot(ZERO) {}
Velocity3(Vec3 const& lin, Vec3 const& rot)
: vLin(lin)
, vRot(rot) {}
void FromDelta(QuatT const& loc0, QuatT const& loc1, float fTime)
{
float fInvT = 1.f / fTime;
vLin = (loc1.t - loc0.t) * fInvT;
vRot = Quat::log(loc1.q * loc0.q.GetInverted()) * fInvT;
}
Vec3 VelocityAt(Vec3 const& vPosRel) const
{ return vLin + (vRot % vPosRel); }
void operator += (Velocity3 const& vv)
{
vLin += vv.vLin;
vRot += vv.vRot;
}
void operator *= (float f)
{
vLin *= f;
vRot *= f;
}
void Interp(Velocity3 const& vv, float f)
{
vLin += (vv.vLin - vLin) * f;
vRot += (vv.vRot - vRot) * f;
}
};
/////////////////////////////////////////////////////////////////////////
//this is some special engine stuff, should be moved to a better location
/////////////////////////////////////////////////////////////////////////
// for bbox's checks and calculations
#define MAX_BB +99999.0f
#define MIN_BB -99999.0f
//! checks if this has been set to minBB
inline bool IsMinBB(const Vec3& v)
{
if (v.x <= MIN_BB)
{
return (true);
}
if (v.y <= MIN_BB)
{
return (true);
}
if (v.z <= MIN_BB)
{
return (true);
}
return (false);
}
//! checks if this has been set to maxBB
inline bool IsMaxBB(const Vec3& v)
{
if (v.x >= MAX_BB)
{
return (true);
}
if (v.y >= MAX_BB)
{
return (true);
}
if (v.z >= MAX_BB)
{
return (true);
}
return (false);
}
inline Vec3 SetMaxBB(void) { return Vec3(MAX_BB, MAX_BB, MAX_BB); }
inline Vec3 SetMinBB(void) { return Vec3(MIN_BB, MIN_BB, MIN_BB); }
inline void AddToBounds (const Vec3& v, Vec3& mins, Vec3& maxs)
{
if (v.x < mins.x)
{
mins.x = v.x;
}
if (v.x > maxs.x)
{
maxs.x = v.x;
}
if (v.y < mins.y)
{
mins.y = v.y;
}
if (v.y > maxs.y)
{
maxs.y = v.y;
}
if (v.z < mins.z)
{
mins.z = v.z;
}
if (v.z > maxs.z)
{
maxs.z = v.z;
}
}
////////////////////////////////////////////////////////////////
//! calc the area of a polygon giving a list of vertices and normal
inline float CalcArea(const Vec3* vertices, int numvertices, const Vec3& normal)
{
Vec3 csum(0, 0, 0);
int n = numvertices;
for (int i = 0, j = 1; i <= n - 2; i++, j++)
{
csum.x += vertices[i].y * vertices[j].z - vertices[i].z * vertices[j].y;
csum.y += vertices[i].z * vertices[j].x - vertices[i].x * vertices[j].z;
csum.z += vertices[i].x * vertices[j].y - vertices[i].y * vertices[j].x;
}
csum.x += vertices[n - 1].y * vertices[0].z - vertices[n - 1].z * vertices[0].y;
csum.y += vertices[n - 1].z * vertices[0].x - vertices[n - 1].x * vertices[0].z;
csum.z += vertices[n - 1].x * vertices[0].y - vertices[n - 1].y * vertices[0].x;
float area = 0.5f * (float)fabs(normal | csum);
return (area);
}
#endif // CRYINCLUDE_CRYCOMMON_CRY_GEO_H
-85
View File
@@ -1,85 +0,0 @@
/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
// Description : Scalar implementation of hardware vector based matrix
#ifndef CRYINCLUDE_CRYCOMMON_CRY_HWMATRIX_H
#define CRYINCLUDE_CRYCOMMON_CRY_HWMATRIX_H
#pragma once
struct hwmtx33
{
hwvec3 m0, m1, m2;
};
ILINE void HWMtx33LoadAligned(hwmtx33& out, const Matrix34A& inMtx)
{
out.m0 = HWVLoadVecAligned(reinterpret_cast<const Vec4A*>(&inMtx.m00));
out.m1 = HWVLoadVecAligned(reinterpret_cast<const Vec4A*>(&inMtx.m10));
out.m2 = HWVLoadVecAligned(reinterpret_cast<const Vec4A*>(&inMtx.m20));
}
ILINE hwvec3 HWMtx33RotateVec(const hwmtx33& m, const hwvec3& v)
{
return Vec3((m.m0[0] * v.x) + (m.m0[1] * v.y) + (m.m0[2] * v.z),
(m.m1[0] * v.x) + (m.m1[1] * v.y) + (m.m1[2] * v.z),
(m.m2[0] * v.x) + (m.m2[1] * v.y) + (m.m2[2] * v.z));
}
ILINE hwvec3 HWMtx33RotateVecOpt(const hwmtx33& m, const hwvec3& v)
{
return HWMtx33RotateVec(m, v);
}
ILINE hwmtx33 HWMtx33CreateRotationV0V1(const hwvec3& v0, const hwvec3& v1)
{
assert((fabs_tpl(1 - (v0 | v0))) < 0.01); //check if unit-vector
assert((fabs_tpl(1 - (v1 | v1))) < 0.01); //check if unit-vector
hwmtx33 m;
float dot = v0 | v1;
if (dot < -0.9999f)
{
Vec3 axis = v0.GetOrthogonal().GetNormalized();
m.m0[0] = (2.0f * axis.x * axis.x - 1);
m.m0[1] = (2.0f * axis.x * axis.y);
m.m0[2] = (2.0f * axis.x * axis.z);
m.m1[0] = (2.0f * axis.y * axis.x);
m.m1[1] = (2.0f * axis.y * axis.y - 1);
m.m1[2] = (2.0f * axis.y * axis.z);
m.m2[0] = (2.0f * axis.z * axis.x);
m.m2[1] = (2.0f * axis.z * axis.y);
m.m2[2] = (2.0f * axis.z * axis.z - 1);
}
else
{
Vec3 v = v0 % v1;
f32 h = 1.0f / (1.0f + dot);
m.m0[0] = (dot + h * v.x * v.x);
m.m0[1] = (h * v.x * v.y - v.z);
m.m0[2] = (h * v.x * v.z + v.y);
m.m1[0] = (h * v.x * v.y + v.z);
m.m1[1] = (dot + h * v.y * v.y);
m.m1[2] = (h * v.y * v.z - v.x);
m.m2[0] = (h * v.x * v.z - v.y);
m.m2[1] = (h * v.y * v.z + v.x);
m.m2[2] = (dot + h * v.z * v.z);
}
return m;
}
//Returns a matrix optimized for this platform's matrix ops, in this case, not doing a thing;
ILINE hwmtx33 HWMtx33GetOptimized(const hwmtx33& m)
{
return (hwmtx33)m;
}
#endif // CRYINCLUDE_CRYCOMMON_CRY_HWMATRIX_H
-278
View File
@@ -1,278 +0,0 @@
/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
// Description: Hardware vector class - scalar implementation
#ifndef CRYINCLUDE_CRYCOMMON_CRY_HWVECTOR3_H
#define CRYINCLUDE_CRYCOMMON_CRY_HWVECTOR3_H
#pragma once
#define HWV_PERMUTE_0X 0
#define HWV_PERMUTE_0Y 1
#define HWV_PERMUTE_0Z 2
#define HWV_PERMUTE_0W 3
#define HWV_PERMUTE_1X 4
#define HWV_PERMUTE_1Y 5
#define HWV_PERMUTE_1Z 6
#define HWV_PERMUTE_1W 7
typedef Vec3 hwvec3;
typedef Vec4 hwvec4;
typedef float simdf;
typedef Vec4 hwvec4fconst;
typedef int hwvec4i[4];
#define HWV3Constant(name, f0, f1, f2) const Vec3 name(f0, f1, f2)
#define SIMDFConstant(name, f0) const simdf name = f0
#define HWV4PermuteControl(name, i0, i1, i2, i3) static const hwvec4i name = {i0, i1, i2, i3};
#define SIMDFAsVec3(a) (hwvec3)a
#define HWV3AsSIMDF(a) (simdf)a.x
ILINE hwvec3 HWVLoadVecUnaligned(const Vec3* pLoadFrom)
{
return *pLoadFrom;
}
ILINE hwvec3 HWVLoadVecAligned(const Vec4A* pLoadFrom)
{
return Vec3(pLoadFrom->x, pLoadFrom->y, pLoadFrom->z);
}
ILINE void HWVSaveVecUnaligned(Vec3* pSaveTo, const hwvec3& pLoadFrom)
{
*pSaveTo = pLoadFrom;
}
ILINE void HWVSaveVecAligned(Vec4* pSaveTo, const hwvec4& pLoadFrom)
{
*pSaveTo = pLoadFrom;
}
ILINE hwvec3 HWVAdd(const hwvec3& a, const hwvec3& b)
{
return hwvec3(a.x + b.x, a.y + b.y, a.z + b.z);
}
ILINE hwvec3 HWVMultiply(const hwvec3& a, const hwvec3& b)
{
return hwvec3(a.x * b.x, a.y * b.y, a.z * b.z);
}
ILINE hwvec3 HWVMultiplySIMDF(const hwvec3& a, const simdf& b)
{
return hwvec3(a.x * b, a.y * b, a.z * b);
}
ILINE hwvec3 HWVMultiplyAdd(const hwvec3& a, const hwvec3& b, const hwvec3& c)
{
return hwvec3((a.x * b.x) + c.x, (a.y * b.y) + c.y, (a.z * b.z) + c.z);
}
ILINE hwvec3 HWVMultiplySIMDFAdd(const hwvec3& a, const simdf& b, const hwvec3& c)
{
return hwvec3((a.x * b) + c.x, (a.y * b) + c.y, (a.z * b) + c.z);
}
ILINE hwvec3 HWVSub(const hwvec3& a, const hwvec3& b)
{
return (a - b);
}
ILINE hwvec3 HWVCross(const hwvec3& a, const hwvec3& b)
{
return hwvec3((a.y * b.z) - (a.z * b.y)
, (a.z * b.x) - (a.x * b.z)
, (a.x * b.y) - (a.y * b.x));
}
ILINE simdf HWV3Dot(const hwvec3& a, const hwvec3& b)
{
return (a.x * b.x) + (a.y * b.y) + (a.z * b.z);
}
ILINE hwvec3 HWVMax(const hwvec3& a, const hwvec3& b)
{
return Vec3(a.x > b.x ? a.x : b.x,
a.y > b.y ? a.y : b.y,
a.z > b.z ? a.z : b.z);
}
ILINE hwvec3 HWVMin(const hwvec3& a, const hwvec3& b)
{
return Vec3(a.x < b.x ? a.x : b.x,
a.y < b.y ? a.y : b.y,
a.z < b.z ? a.z : b.z);
}
ILINE hwvec3 HWVClamp(const hwvec3& a, const hwvec3& min, const hwvec3& max)
{
return HWVMax(min, HWVMin(a, max));
}
ILINE hwvec3 HWV3Normalize(const hwvec3& a)
{
float fInvLen = isqrt_safe_tpl((a.x * a.x) + (a.y * a.y) + (a.z * a.z));
return Vec3(a.x * fInvLen, a.y * fInvLen, a.z * fInvLen);
}
ILINE hwvec3 HWVGetOrthogonal(const hwvec3& a)
{
hwvec3 result = a;
//int i = isneg(square(0.9f)*a.GetLengthSquared()-(a.x*a.x));
int i = isneg(square(0.9f) * a.GetLengthSquared() - a.x * a.x);
result[i] = 0;
result[incm3(i)] = a[decm3(i)];
result[decm3(i)] = -a[incm3(i)];
return result;
}
ILINE simdf HWV3SplatXToSIMDF(const hwvec3& a)
{
return a.x;
}
ILINE simdf HWV3SplatYToSIMDF(const hwvec3& a)
{
return a.y;
}
ILINE hwvec3 HWV3PermuteWord(const hwvec3& a, const hwvec3& b, const hwvec4i& p)
{
hwvec3 selection[2] = {a, b};
float* fSelection = (float*)selection;
return Vec3(fSelection[p[0]], fSelection[p[1]], fSelection[p[2]]);
}
ILINE hwvec3 HWV3Zero()
{
return Vec3(0.0f, 0.0f, 0.0f);
}
ILINE hwvec4 HWV4Zero()
{
return Vec4(0.0f, 0.0f, 0.0f, 0.0f);
}
ILINE hwvec3 HWV3Negate(const hwvec3& a)
{
return Vec3(-a.x, -a.y, -a.z);
}
ILINE hwvec3 HWVSelect(const hwvec3& a, const hwvec3& b, const hwvec3& control)
{
return Vec3(control[0] > 0.0f ? b[0] : a[0],
control[1] > 0.0f ? b[1] : a[1],
control[2] > 0.0f ? b[2] : a[2]);
}
ILINE hwvec3 HWVSelectSIMDF(const hwvec3& a, const hwvec3& b, const bool& control)
{
return control ? b : a;
}
ILINE simdf HWV3LengthSq(const hwvec3& a)
{
return a.len2();
}
//////////////////////////////////////////////////
//SIMDF functions for float stored in HWVEC4 data
//////////////////////////////////////////////////
ILINE simdf SIMDFLoadFloat(const float& f)
{
return f;
}
ILINE void SIMDFSaveFloat(float* f, const simdf& a)
{
*f = a;
}
ILINE bool SIMDFGreaterThan(const simdf& a, const simdf& b)
{
return (a > b);
}
ILINE bool SIMDFLessThanEqualB(const simdf& a, const simdf& b)
{
return (a <= b);
}
ILINE bool SIMDFLessThanEqual(const simdf& a, const simdf& b)
{
return (a <= b);
}
ILINE bool SIMDFLessThanB(const simdf& a, const simdf& b)
{
return (a < b);
}
ILINE bool SIMDFLessThan(const simdf& a, const simdf& b)
{
return (a < b);
}
ILINE simdf SIMDFAdd(const simdf& a, const simdf& b)
{
return a + b;
}
ILINE simdf SIMDFMult(const simdf& a, const simdf& b)
{
return a * b;
}
ILINE simdf SIMDFReciprocal(const simdf& a)
{
return 1.0f / a;
}
ILINE simdf SIMDFSqrt(const simdf& a)
{
return sqrt_tpl(a);
}
ILINE simdf SIMDFSqrtEst(const simdf& a)
{
return sqrt_tpl(a);
}
ILINE simdf SIMDFSqrtEstFast(const simdf& a)
{
return sqrt_tpl(a);
}
ILINE simdf SIMDFMax(const simdf& a, const simdf& b)
{
return max(a, b);
}
ILINE simdf SIMDFMin(const simdf& a, const simdf& b)
{
return min(a, b);
}
ILINE simdf SIMDFClamp(const simdf& a, const simdf& min, const simdf& max)
{
return clamp_tpl(a, min, max);
}
ILINE simdf SIMDFAbs(const simdf& a)
{
return fabsf(a);
}
#endif // CRYINCLUDE_CRYCOMMON_CRY_HWVECTOR3_H
+1 -187
View File
@@ -8,8 +8,6 @@
// Description : Common math class
#pragma once
//========================================================================================
@@ -18,7 +16,6 @@
#include "Cry_ValidNumber.h"
#include <CryEndian.h> // eLittleEndian
#include <CryHalf.inl>
//#include <MetaUtils.h>
#include <float.h>
///////////////////////////////////////////////////////////////////////////////
// Forward declarations //
@@ -27,8 +24,7 @@ template <typename F>
struct Vec2_tpl;
template <typename F>
struct Vec3_tpl;
template <typename F>
struct Vec4_tpl;
struct Vec4;
template <typename F>
struct Ang3_tpl;
@@ -38,14 +34,6 @@ template <typename F>
struct AngleAxis_tpl;
template <typename F>
struct Quat_tpl;
template <typename F>
struct QuatT_tpl;
template <typename F>
struct DualQuat_tpl;
template <typename F>
struct QuatTS_tpl;
template <typename F>
struct QuatTNS_tpl;
template <typename F>
struct Diag33_tpl;
@@ -94,14 +82,8 @@ const f32 gf_halfPI = f32(1.57079632679489661923132169163975144209858469968755);
#define TANGENT30_2 0.57735026918962576450914878050196f * 2 // 2*tan(30)
#define LN2 0.69314718055994530941723212145818f // ln(2)
ILINE f32 fsel(const f32 _a, const f32 _b, const f32 _c) { return (_a < 0.0f) ? _c : _b; }
ILINE f64 fsel(const f64 _a, const f64 _b, const f64 _c) { return (_a < 0.0f) ? _c : _b; }
ILINE f32 fself(const f32 _a, const f32 _b, const f32 _c) { return (_a < 0.0f) ? _c : _b; }
ILINE f32 fsels(const f32 _a, const f32 _b, const f32 _c) { return (_a < 0.0f) ? _c : _b; }
ILINE f32 fres(const f32 _a) { return 1.f / _a; }
template<class T>
ILINE T isel(int c, T a, T b) { return (c < 0) ? b : a; }
@@ -319,13 +301,6 @@ ILINE int64 pos_round(f64 f) { return int64(f + 0.5); }
ILINE int32 int_ceil(f32 f) { int32 i = int32(f); return (f > f32(i)) ? i + 1 : i; }
ILINE int64 int_ceil(f64 f) { int64 i = int64(f); return (f > f64(i)) ? i + 1 : i; }
ILINE float ufrac8_to_float(float u) { return u * (1.f / 255.f); }
ILINE float ifrac8_to_float(float i) { return i * (1.f / 127.f); }
ILINE uint8 float_to_ufrac8(float f) { int i = pos_round(f * 255.f); assert(i >= 0 && i < 256); return uint8(i); }
ILINE int8 float_to_ifrac8(float f) { int i = int_round(f * 127.f); assert(abs(i) <= 127); return int8(i); }
template<class F>
ILINE F sqr(const F& op) { return op * op; }
template<class F>
@@ -490,11 +465,8 @@ ILINE int64 iszero(long int x) { return -(x >> 63 ^ (x - 1) >> 63); }
#endif
ILINE float if_neg_else(float test, float val_neg, float val_nonneg) { return (float)fsel(test, val_nonneg, val_neg); }
ILINE float if_pos_else(float test, float val_pos, float val_nonpos) { return (float)fsel(-test, val_nonpos, val_pos); }
template<class F>
ILINE int32 inrange(F x, F end1, F end2) { return isneg(fabs_tpl(end1 + end2 - x * (F)2) - fabs_tpl(end1 - end2)); }
template<class F>
ILINE F cond_select(int32 bFirst, F op1, F op2) { F arg[2] = { op1, op2 }; return arg[bFirst ^ 1]; }
template<class F>
ILINE int32 idxmax3(const F* pdata)
@@ -510,56 +482,6 @@ ILINE int32 idxmax3(const Vec3_tpl<F>& vec)
imax |= isneg(vec[imax] - vec.z) << 1;
return imax & (2 | (imax >> 1 ^ 1));
}
template<class F>
ILINE int32 idxmin3(const F* pdata)
{
int32 imin = isneg(pdata[1] - pdata[0]);
imin |= isneg(pdata[2] - pdata[imin]) << 1;
return imin & (2 | (imin >> 1 ^ 1));
}
template<class F>
ILINE int32 idxmin3(const Vec3_tpl<F>& vec)
{
int32 imin = isneg(vec.y - vec.x);
imin |= isneg(vec.z - vec[imin]) << 1;
return imin & (2 | (imin >> 1 ^ 1));
}
// Approximation of exp(-x)
ILINE float approxExp(float x) { return fres(1.f + x); }
// Approximation of 1.f - exp(-x)
ILINE float approxOneExp(float x) { return x * fres(1.f + x); }
ILINE int ilog2(uint64 x) // if x==1<<i (i=0..63), returns i
{
#if defined(CRY_PLATFORM_X64)
# if defined(AZ_RESTRICTED_PLATFORM)
# include AZ_RESTRICTED_FILE(Cry_Math_h)
# endif
# if defined(AZ_RESTRICTED_SECTION_IMPLEMENTED)
# undef AZ_RESTRICTED_SECTION_IMPLEMENTED
# elif defined(CRY_PLATFORM_LINUX)
# define HAS_BIT_SCAN_FORWARD64 0
# else
# define HAS_BIT_SCAN_FORWARD64 1
# endif
#endif
#if HAS_BIT_SCAN_FORWARD64
unsigned long i;
_BitScanForward64(&i, x);
return i;
#else
union
{
float f;
uint i;
} u;
u.f = (float)x;
return (u.i >> 23) - 127;
#endif
}
static int32 inc_mod3[] = {1, 2, 0}, dec_mod3[] = {2, 0, 1};
#ifdef PHYSICS_EXPORTS
@@ -596,114 +518,6 @@ enum type_identity
#include "Cry_Matrix34.h"
#include "Cry_Matrix44.h"
#include "Cry_Quat.h"
#include "Cry_HWVector3.h"
#include "Cry_HWMatrix.h"
//////////////////////////////////////////////////////////////////////////
/// This function relaxes a value (val) towards a desired value (to) whilst maintaining continuity
/// of val and its rate of change (valRate). timeDelta is the time between this call and the previous one.
/// The caller would normally keep val and valRate as working variables, and smoothTime is normally
/// a fixed parameter. The to/timeDelta values can change.
///
/// Implementation details:
///
/// This is a critically damped spring system. A linear spring is attached between "val" and "to" that
/// drags "val" to "to". At the same time a damper between the two removes oscillations; it's tweaked
/// so it doesn't dampen more than necessary. In combination this gives smooth ease-in and ease-out behavior.
///
/// smoothTime can be interpreted in a couple of ways:
/// - it's the "expected time to reach the target when at maximum velocity" (the target will, however, not be reached
/// in that time because the speed will decrease the closer it gets to the target)
/// - it's the 'lag time', how many seconds "val" lags behind "to". If your
/// target has a certain speed, the lag distance is simply the smoothTime times that speed.
/// - it's 2/omega, where omega is the spring's natural frequency (or less formally a measure of the spring stiffness)
///
/// The implementation is stable for varying timeDelta, but for performance reasons it uses a polynomial approximation
/// to the exponential function. The approximation works well (within 0.1% of accuracy) when smoothTime > 2*deltaTime,
/// which is usually the case. (but it might be troublesome when you want a stiff spring or have frame hikes!)
/// The implementation handles cases where smoothTime==0 separately and reliably. In that case the target will be
/// reached immediately, and valRate is updated appropriately.
///
/// Based on "Critically Damped Ease-In/Ease-Out Smoothing", Thomas Lowe, Game Programming Gems IV
///
template <typename T>
ILINE void SmoothCD(
T& val, ///< in/out: value to be smoothed
T& valRate, ///< in/out: rate of change of the value
const float timeDelta, ///< in: time interval
const T& to, ///< in: the target value
const float smoothTime) ///< in: timescale for smoothing
{
if (smoothTime > 0.0f)
{
const float omega = 2.0f / smoothTime;
const float x = omega * timeDelta;
const float exp = 1.0f / (1.0f + x + 0.48f * x * x + 0.235f * x * x * x);
const T change = (val - to);
const T temp = (T)((valRate + change * omega) * timeDelta);
valRate = (T)((valRate - temp * omega) * exp);
val = (T)(to + (change + temp) * exp);
}
else if (timeDelta > 0.0f)
{
valRate = (T)((to - val) / timeDelta);
val = to;
}
else
{
val = to;
T zeroizeAmount = valRate;
valRate -= zeroizeAmount; // zero it...
}
}
template <typename T>
ILINE void SmoothCDWithMaxRate(
T& val, ///< in/out: value to be smoothed
T& valRate, ///< in/out: rate of change of the value
const float timeDelta, ///< in: time interval
const T& to, ///< in: the target value
const float smoothTime, ///< in: timescale for smoothing
const T& maxValRate) ///< in: maximum allowed rate of change
{
if (smoothTime > 0.0f)
{
const float omega = 2.0f / smoothTime;
const float x = omega * timeDelta;
const float exp = 1.0f / (1.0f + x + 0.48f * x * x + 0.235f * x * x * x);
const T unclampedChange = val - to;
const T maxChange = maxValRate * smoothTime;
const T clampedChange = clamp_tpl<T>(unclampedChange, -maxChange, maxChange);
const T clampedTo = val - clampedChange;
const T temp = (T)((valRate + clampedChange * omega) * timeDelta);
valRate = (T)((valRate - temp * omega) * exp);
val = (T)(clampedTo + (clampedChange + temp) * exp);
}
else if (timeDelta > 0.0f)
{
const T unclampedRate = (T)((to - val) / timeDelta);
valRate = clamp_tpl<T>(unclampedRate, -maxValRate, maxValRate);
val += valRate * timeDelta;
}
else
{
val = to;
T zeroizeAmount = valRate;
valRate -= zeroizeAmount; // zero it...
}
}
// Smoothes linear blending into cubic (b-spline) with 0-derivatives
// near 0 and 1
inline f32 SmoothBlendValue (const f32 fBlend)
{
const f32 fBlendAdj = fBlend - 0.5f;
return (f32)fsel(-fBlend, 0.f, fsel(fBlend - 1.f, 1.f, 0.5f - 2.f * (fBlendAdj * fBlendAdj * fBlendAdj) + 1.5f * fBlendAdj));
}
// function for safe comparsion of floating point values
ILINE bool fcmp(f32 fA, f32 fB, f32 fEpsilon = FLT_EPSILON)
+4 -273
View File
@@ -8,10 +8,6 @@
// Description : Common matrix class
#ifndef CRYINCLUDE_CRYCOMMON_CRY_MATRIX33_H
#define CRYINCLUDE_CRYCOMMON_CRY_MATRIX33_H
#pragma once
@@ -64,7 +60,6 @@ struct Matrix33_tpl
#else
ILINE Matrix33_tpl(){};
#endif
//set matrix to Identity
ILINE Matrix33_tpl(type_identity)
{
@@ -78,21 +73,6 @@ struct Matrix33_tpl
m21 = 0;
m22 = 1;
}
//set matrix to Zero
ILINE Matrix33_tpl(type_zero)
{
m00 = 0;
m01 = 0;
m02 = 0;
m10 = 0;
m11 = 0;
m12 = 0;
m20 = 0;
m21 = 0;
m22 = 0;
}
//ASSIGNMENT OPERATOR of identical Matrix33 types.
//The assignment operator has precedence over assignment constructor
//Matrix33 m; m=m33;
@@ -118,7 +98,7 @@ struct Matrix33_tpl
//CONSTRUCTOR for identical float-types. It initializes a Matrix33 with 9 floats.
//Matrix33(0,1,2, 3,4,5, 6,7,8);
explicit ILINE Matrix33_tpl<F>(F x00, F x01, F x02, F x10, F x11, F x12, F x20, F x21, F x22)
explicit ILINE Matrix33_tpl(F x00, F x01, F x02, F x10, F x11, F x12, F x20, F x21, F x22)
{
m00 = x00;
m01 = x01;
@@ -130,26 +110,11 @@ struct Matrix33_tpl
m21 = x21;
m22 = x22;
}
//CONSTRUCTOR for different float-types. It initializes a Matrix33 with 9 floats.
//Matrix33(0.0,1.0,2.0, 3.0,4.0,5.0, 6.0,7.0,8.0);
template<class F1>
explicit ILINE Matrix33_tpl<F>(F1 x00, F1 x01, F1 x02, F1 x10, F1 x11, F1 x12, F1 x20, F1 x21, F1 x22)
{
m00 = F(x00);
m01 = F(x01);
m02 = F(x02);
m10 = F(x10);
m11 = F(x11);
m12 = F(x12);
m20 = F(x20);
m21 = F(x21);
m22 = F(x22);
}
//CONSTRUCTOR for identical float-types. It initializes a Matrix33 with 3 vectors stored in the columns.
//Matrix33(v0,v1,v2);
explicit ILINE Matrix33_tpl<F>(const Vec3_tpl<F>&vx, const Vec3_tpl<F>&vy, const Vec3_tpl<F>&vz)
explicit ILINE Matrix33_tpl(const Vec3_tpl<F>&vx, const Vec3_tpl<F>&vy, const Vec3_tpl<F>&vz)
{
m00 = vx.x;
m01 = vy.x;
@@ -164,7 +129,7 @@ struct Matrix33_tpl
//CONSTRUCTOR for different float-types. It initializes a Matrix33 with 3 vectors stored in the columns and converts between floats/doubles.
//Matrix33r(v0,v1,v2);
template<class F1>
explicit ILINE Matrix33_tpl<F>(const Vec3_tpl<F1>&vx, const Vec3_tpl<F1>&vy, const Vec3_tpl<F1>&vz)
explicit ILINE Matrix33_tpl(const Vec3_tpl<F1>&vx, const Vec3_tpl<F1>&vy, const Vec3_tpl<F1>&vz)
{
m00 = F(vx.x);
m01 = F(vy.x);
@@ -209,8 +174,6 @@ struct Matrix33_tpl
m22 = F(m.m22);
}
//CONSTRUCTOR for identical float-types. It converts a Matrix34 into a Matrix33.
//Needs to be 'explicit' because we loose the translation vector in the conversion process
//Matrix33(m34);
@@ -245,9 +208,6 @@ struct Matrix33_tpl
m22 = F(m.m22);
}
//CONSTRUCTOR for identical float-types. It converts a Matrix44 into a Matrix33.
//Needs to be 'explicit' because we loose the translation vector and the 3rd row in the conversion process
//Matrix33(m44);
@@ -356,26 +316,6 @@ struct Matrix33_tpl
SetRotationXYZ(Ang3_tpl<F>(F(ang.x), F(ang.y), F(ang.z)));
}
//Bracket OPERATOR: initializes a Matrix33 with 9 floats.
//Matrix33 m; m(0,1,2, 3,4,5, 6,7,8);
ILINE void operator () (F x00, F x01, F x02, F x10, F x11, F x12, F x20, F x21, F x22)
{
m00 = x00;
m01 = x01;
m02 = x02;
m10 = x10;
m11 = x11;
m12 = x12;
m20 = x20;
m21 = x21;
m22 = x22;
assert(IsValid());
}
//---------------------------------------------------------------------------------------
ILINE void SetIdentity(void)
@@ -391,27 +331,6 @@ struct Matrix33_tpl
m22 = 1;
}
ILINE static Matrix33_tpl<F> CreateIdentity()
{
Matrix33_tpl<F> m33;
m33.SetIdentity();
return m33;
}
ILINE void SetZero()
{
m00 = 0;
m01 = 0;
m02 = 0;
m10 = 0;
m11 = 0;
m12 = 0;
m20 = 0;
m21 = 0;
m22 = 0;
}
/*!
* Create a rotation matrix around an arbitrary axis (Eulers Theorem).
* The axis is specified as a normalized Vec3. The angle is assumed to be in radians.
@@ -597,7 +516,7 @@ struct Matrix33_tpl
F dot = v0 | v1;
if (dot < F(-0.9999f))
{
Vec3d axis = v0.GetOrthogonal().GetNormalized();
Vec3_tpl<F> axis = v0.GetOrthogonal().GetNormalized();
m00 = F(2 * axis.x * axis.x - 1);
m01 = F(2 * axis.x * axis.y);
m02 = F(2 * axis.x * axis.z);
@@ -723,28 +642,6 @@ struct Matrix33_tpl
return m33;
}
//! calculate 2 vector that form a orthogonal base with a given input vector (by M.M.)
//! /param invDirection input direction (has to be normalized)
//! /param outvA first output vector that is perpendicular to the input direction
//! /param outvB second output vector that is perpendicular the input vector and the first output vector
ILINE static Matrix33_tpl<F> CreateOrthogonalBase(const Vec3& invDirection)
{
Vec3 outvA;
if (invDirection.z < -0.5f || invDirection.z > 0.5f)
{
outvA = Vec3(invDirection.z, invDirection.y, -invDirection.x);
}
else
{
outvA = Vec3(invDirection.y, -invDirection.x, invDirection.z);
}
Vec3 outvB = (invDirection % outvA).GetNormalized();
outvA = (invDirection % outvB).GetNormalized();
return CreateFromVectors(invDirection, outvA, outvB);
}
//////////////////////////////////////////////////////////////////////////
ILINE static Matrix33_tpl<F> CreateOrientation(const Vec3_tpl<F>& dir, const Vec3_tpl<F>& up, float rollAngle)
{
@@ -779,77 +676,6 @@ struct Matrix33_tpl
return tm;
}
/*!
* Direct-Matrix-Slerp: for the sake of completeness, I have included the following expression
* for Spherical-Linear-Interpolation without using quaternions. This is much faster then converting
* both matrices into quaternions in order to do a quaternion slerp and then converting the slerped
* quaternion back into a matrix.
* This is a high-precision calculation. Given two orthonormal 3x3 matrices this function calculates
* the shortest possible interpolation-path between the two rotations. The interpolation curve forms
* a great arc on the rotation sphere (geodesic). Not only does Slerp follow a great arc it follows
* the shortest great arc. Furthermore Slerp has constant angular velocity. All in all Slerp is the
* optimal interpolation curve between two rotations.
*
* STABILITY PROBLEM: There are two singularities at angle=0 and angle=PI. At 0 the interpolation-axis
* is arbitrary, which means any axis will produce the same result because we have no rotation. Thats
* why I'm using (1,0,0). At PI the rotations point away from each other and the interpolation-axis
* is unpredictable. In this case I'm also using the axis (1,0,0). If the angle is ~0 or ~PI, then we
* have to normalize a very small vector and this can cause numerical instability. The quaternion-slerp
* has exactly the same problems.
* Ivo
* Example:
* Matrix33 slerp=Matrix33::CreateSlerp( m,n,0.333f );
*/
ILINE void SetSlerp(const Matrix33_tpl<F>& m, const Matrix33_tpl<F>& n, F t)
{
assert(m.IsValid());
assert(n.IsValid());
//calculate delta-rotation between m and n (=39 flops)
Matrix33_tpl<F> d, i;
d.m00 = m.m00 * n.m00 + m.m10 * n.m10 + m.m20 * n.m20;
d.m01 = m.m00 * n.m01 + m.m10 * n.m11 + m.m20 * n.m21;
d.m02 = m.m00 * n.m02 + m.m10 * n.m12 + m.m20 * n.m22;
d.m10 = m.m01 * n.m00 + m.m11 * n.m10 + m.m21 * n.m20;
d.m11 = m.m01 * n.m01 + m.m11 * n.m11 + m.m21 * n.m21;
d.m12 = m.m01 * n.m02 + m.m11 * n.m12 + m.m21 * n.m22;
d.m20 = d.m01 * d.m12 - d.m02 * d.m11;
d.m21 = d.m02 * d.m10 - d.m00 * d.m12;
d.m22 = d.m00 * d.m11 - d.m01 * d.m10;
assert(d.IsOrthonormalRH(0.0001f));
Vec3_tpl<F> axis(d.m21 - d.m12, d.m02 - d.m20, d.m10 - d.m01);
F l = sqrt(axis | axis);
if (l > F(0.00001))
{
axis /= l;
}
else
{
axis(1, 0, 0);
}
i.SetRotationAA(acos(clamp_tpl((d.m00 + d.m11 + d.m22 - 1) * 0.5f, F(-1), F(+1))) * t, axis); //angle interpolation and calculation of new delta-matrix (=26 flops)
//final concatenation (=39 flops)
m00 = F(m.m00 * i.m00 + m.m01 * i.m10 + m.m02 * i.m20);
m01 = F(m.m00 * i.m01 + m.m01 * i.m11 + m.m02 * i.m21);
m02 = F(m.m00 * i.m02 + m.m01 * i.m12 + m.m02 * i.m22);
m10 = F(m.m10 * i.m00 + m.m11 * i.m10 + m.m12 * i.m20);
m11 = F(m.m10 * i.m01 + m.m11 * i.m11 + m.m12 * i.m21);
m12 = F(m.m10 * i.m02 + m.m11 * i.m12 + m.m12 * i.m22);
m20 = m01 * m12 - m02 * m11;
m21 = m02 * m10 - m00 * m12;
m22 = m00 * m11 - m01 * m10;
assert(this->IsOrthonormalRH(0.0001f));
}
ILINE static Matrix33_tpl<F> CreateSlerp(const Matrix33_tpl<F> m, const Matrix33_tpl<F> n, F t)
{
Matrix33_tpl<F> m33;
m33.SetSlerp(m, n, t);
return m33;
}
ILINE void SetScale(const Vec3_tpl<F>& s)
{
m00 = s.x;
@@ -880,9 +706,6 @@ struct Matrix33_tpl
}
ILINE static Matrix33_tpl<F> CreateFromVectors(const Vec3_tpl<F>& vx, const Vec3_tpl<F>& vy, const Vec3_tpl<F>& vz) { Matrix33_tpl<F> dst; dst.SetFromVectors(vx, vy, vz); return dst; }
ILINE void Transpose() // in-place transposition
{
F t;
@@ -896,56 +719,6 @@ struct Matrix33_tpl
m12 = m21;
m21 = t;
}
ILINE Matrix33_tpl<F> GetTransposed() const
{
Matrix33_tpl<F> dst;
dst.m00 = m00;
dst.m01 = m10;
dst.m02 = m20;
dst.m10 = m01;
dst.m11 = m11;
dst.m12 = m21;
dst.m20 = m02;
dst.m21 = m12;
dst.m22 = m22;
return dst;
}
ILINE Matrix33_tpl<F> T() const { return GetTransposed(); }
ILINE Matrix33_tpl& Fabs()
{
m00 = fabs_tpl(m00);
m01 = fabs_tpl(m01);
m02 = fabs_tpl(m02);
m10 = fabs_tpl(m10);
m11 = fabs_tpl(m11);
m12 = fabs_tpl(m12);
m20 = fabs_tpl(m20);
m21 = fabs_tpl(m21);
m22 = fabs_tpl(m22);
return *this;
}
ILINE Matrix33_tpl<F> GetFabs() const { Matrix33_tpl<F> m = *this; m.Fabs(); return m; }
ILINE void Adjoint(void)
{
//rescue members
Matrix33_tpl<F> m = *this;
//calculate the adjoint-matrix
m00 = m.m11 * m.m22 - m.m12 * m.m21;
m01 = m.m12 * m.m20 - m.m10 * m.m22;
m02 = m.m10 * m.m21 - m.m11 * m.m20;
m10 = m.m21 * m.m02 - m.m22 * m.m01;
m11 = m.m22 * m.m00 - m.m20 * m.m02;
m12 = m.m20 * m.m01 - m.m21 * m.m00;
m20 = m.m01 * m.m12 - m.m02 * m.m11;
m21 = m.m02 * m.m10 - m.m00 * m.m12;
m22 = m.m00 * m.m11 - m.m01 * m.m10;
}
ILINE Matrix33_tpl<F> GetAdjoint() const { Matrix33_tpl<F> dst = *this; dst.Adjoint(); return dst; }
/*!
*
@@ -1201,8 +974,6 @@ struct Matrix33_tpl
///////////////////////////////////////////////////////////////////////////////
typedef Matrix33_tpl<f32> Matrix33; //always 32 bit
typedef Matrix33_tpl<f64> Matrix33d; //always 64 bit
typedef Matrix33_tpl<real> Matrix33r; //variable float precision. depending on the target system it can be between 32, 64 or 80 bit
//----------------------------------------------------------------------------------
//----------------------------------------------------------------------------------
@@ -1360,9 +1131,6 @@ ILINE Matrix33_tpl<F1>& operator+=(Matrix33_tpl<F1>& l, const Matrix33_tpl<F2>&
return l;
}
template<class F1, class F2>
ILINE Matrix33_tpl<F1> operator - (const Matrix33_tpl<F1>& l, const Matrix33_tpl<F2>& r)
{
@@ -1397,9 +1165,6 @@ ILINE Matrix33_tpl<F1>& operator-=(Matrix33_tpl<F1>& l, const Matrix33_tpl<F2>&
return l;
}
template<class F>
ILINE Matrix33_tpl<F> operator*(const Matrix33_tpl<F>& m, F op)
{
@@ -1462,37 +1227,3 @@ ILINE Vec2_tpl<F1> operator*(const Vec2_tpl<F1>& v, const Matrix33_tpl<F2>& m)
assert(v.IsValid());
return Vec2_tpl<F1>(v.x * m.m00 + v.y * m.m10, v.x * m.m01 + v.y * m.m11);
}
template<class F1>
ILINE Matrix33_tpl<F1>& crossproduct_matrix(const Vec3_tpl<F1>& v, Matrix33_tpl<F1>& m)
{
m.m00 = 0;
m.m01 = -v.z;
m.m02 = v.y;
m.m10 = v.z;
m.m11 = 0;
m.m12 = -v.x;
m.m20 = -v.y;
m.m21 = v.x;
m.m22 = 0;
return m;
}
template<class F1>
ILINE Matrix33_tpl<F1>& dotproduct_matrix(const Vec3_tpl<F1>& v, const Vec3_tpl<F1>& op, Matrix33_tpl<F1>& m)
{
m.m00 = v.x * op.x;
m.m10 = v.y * op.x;
m.m20 = v.z * op.x;
m.m01 = v.x * op.y;
m.m11 = v.y * op.y;
m.m21 = v.z * op.y;
m.m02 = v.x * op.z;
m.m12 = v.y * op.z;
m.m22 = v.z * op.z;
return m;
}
#endif // CRYINCLUDE_CRYCOMMON_CRY_MATRIX33_H
+4 -430
View File
@@ -8,16 +8,8 @@
// Description : Common matrix class
#ifndef CRYINCLUDE_CRYCOMMON_CRY_MATRIX34_H
#define CRYINCLUDE_CRYCOMMON_CRY_MATRIX34_H
#pragma once
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
@@ -347,220 +339,6 @@ struct Matrix34_tpl
*this = Matrix33_tpl<F>(q);
}
//CONSTRUCTOR for identical float-types. It converts a QuatT into a Matrix34.
//Needs to be 'explicit' because we loose float-precision in the conversion process
//Matrix34(QuatT);
explicit ILINE Matrix34_tpl<F>(const QuatT_tpl<F> &q)
{
*this = Matrix34_tpl<F>(Matrix33_tpl<F>(q.q), q.t);
}
//CONSTRUCTOR for different float-types. It converts a QuatT into a Matrix34.
//Needs to be 'explicit' because we loose float-precision in the conversion process
//Matrix34(QuatT);
template<class F1>
ILINE explicit Matrix34_tpl(const QuatT_tpl<F1> q)
{
*this = Matrix34_tpl<F>(Matrix33_tpl<F1>(q.q), q.t);
}
//CONSTRUCTOR for identical float-types. It converts a QuatTS into a Matrix34.
//Needs to be 'explicit' because we loose float-precision in the conversion process
//Matrix34(QuatT);
explicit ILINE Matrix34_tpl<F>(const QuatTS_tpl<F> &q)
{
assert(q.q.IsValid());
Vec3_tpl<F> v2 = q.q.v + q.q.v;
F xx = 1 - v2.x * q.q.v.x;
F yy = v2.y * q.q.v.y;
F xw = v2.x * q.q.w;
F xy = v2.y * q.q.v.x;
F yz = v2.z * q.q.v.y;
F yw = v2.y * q.q.w;
F xz = v2.z * q.q.v.x;
F zz = v2.z * q.q.v.z;
F zw = v2.z * q.q.w;
m00 = (1 - yy - zz) * q.s;
m01 = (xy - zw) * q.s;
m02 = (xz + yw) * q.s;
m03 = q.t.x;
m10 = (xy + zw) * q.s;
m11 = (xx - zz) * q.s;
m12 = (yz - xw) * q.s;
m13 = q.t.y;
m20 = (xz - yw) * q.s;
m21 = (yz + xw) * q.s;
m22 = (xx - yy) * q.s;
m23 = q.t.z;
}
//CONSTRUCTOR for different float-types. It converts a QuatTS into a Matrix34.
//Needs to be 'explicit' because we loose float-precision in the conversion process
//Matrix34(QuatT);
template<class F1>
ILINE explicit Matrix34_tpl<F>(const QuatTS_tpl<F1> &q)
{
assert(q.q.IsValid());
Vec3_tpl<F1> v2 = q.q.v + q.q.v;
F1 xx = 1 - v2.x * q.q.v.x;
F1 yy = v2.y * q.q.v.y;
F1 xw = v2.x * q.q.w;
F1 xy = v2.y * q.q.v.x;
F1 yz = v2.z * q.q.v.y;
F1 yw = v2.y * q.q.w;
F1 xz = v2.z * q.q.v.x;
F1 zz = v2.z * q.q.v.z;
F1 zw = v2.z * q.q.w;
m00 = F((1 - yy - zz) * q.s);
m01 = F((xy - zw) * q.s);
m02 = F((xz + yw) * q.s);
m03 = F(q.t.x);
m10 = F((xy + zw) * q.s);
m11 = F((xx - zz) * q.s);
m12 = F((yz - xw) * q.s);
m13 = F(q.t.y);
m20 = F((xz - yw) * q.s);
m21 = F((yz + xw) * q.s);
m22 = F((xx - yy) * q.s);
m23 = F(q.t.z);
}
//CONSTRUCTOR for identical float-types. It converts a QuatTNS into a Matrix34.
//Needs to be 'explicit' because we loose float-precision in the conversion process
//Matrix34(QuatT);
explicit ILINE Matrix34_tpl<F>(const QuatTNS_tpl<F> &q)
{
assert(q.q.IsValid());
Vec3_tpl<F> v2 = q.q.v + q.q.v;
F xx = 1 - v2.x * q.q.v.x;
F yy = v2.y * q.q.v.y;
F xw = v2.x * q.q.w;
F xy = v2.y * q.q.v.x;
F yz = v2.z * q.q.v.y;
F yw = v2.y * q.q.w;
F xz = v2.z * q.q.v.x;
F zz = v2.z * q.q.v.z;
F zw = v2.z * q.q.w;
m00 = (1 - yy - zz) * q.s.x;
m01 = (xy - zw) * q.s.y;
m02 = (xz + yw) * q.s.z;
m03 = q.t.x;
m10 = (xy + zw) * q.s.x;
m11 = (xx - zz) * q.s.y;
m12 = (yz - xw) * q.s.z;
m13 = q.t.y;
m20 = (xz - yw) * q.s.x;
m21 = (yz + xw) * q.s.y;
m22 = (xx - yy) * q.s.z;
m23 = q.t.z;
}
//CONSTRUCTOR for different float-types. It converts a QuatTNS into a Matrix34.
//Needs to be 'explicit' because we loose float-precision in the conversion process
//Matrix34(QuatT);
template<class F1>
ILINE explicit Matrix34_tpl<F>(const QuatTNS_tpl<F1> &q)
{
assert(q.q.IsValid());
Vec3_tpl<F1> v2 = q.q.v + q.q.v;
F1 xx = 1 - v2.x * q.q.v.x;
F1 yy = v2.y * q.q.v.y;
F1 xw = v2.x * q.q.w;
F1 xy = v2.y * q.q.v.x;
F1 yz = v2.z * q.q.v.y;
F1 yw = v2.y * q.q.w;
F1 xz = v2.z * q.q.v.x;
F1 zz = v2.z * q.q.v.z;
F1 zw = v2.z * q.q.w;
m00 = F((1 - yy - zz) * q.s.x);
m01 = F((xy - zw) * q.s.y);
m02 = F((xz + yw) * q.s.z);
m03 = F(q.t.x);
m10 = F((xy + zw) * q.s.x);
m11 = F((xx - zz) * q.s.y);
m12 = F((yz - xw) * q.s.z);
m13 = F(q.t.y);
m20 = F((xz - yw) * q.s.x);
m21 = F((yz + xw) * q.s.y);
m22 = F((xx - yy) * q.s.z);
m23 = F(q.t.z);
}
//CONSTRUCTOR for identical float-types. It converts a DualQuat into a Matrix34.
//Needs to be 'explicit' because we loose float-precision in the conversion process
//Matrix34(QuatT);
ILINE explicit Matrix34_tpl<F>(const DualQuat_tpl<F> &q)
{
assert((fabs_tpl(1 - (q.nq | q.nq))) < 0.01); //check if unit-quaternion
Vec3_tpl<F> t = (q.nq.w * q.dq.v - q.dq.w * q.nq.v + q.nq.v % q.dq.v); //perfect for HLSL
Vec3_tpl<F> v2 = q.nq.v + q.nq.v;
F xx = 1 - v2.x * q.nq.v.x;
F yy = v2.y * q.nq.v.y;
F xw = v2.x * q.nq.w;
F xy = v2.y * q.nq.v.x;
F yz = v2.z * q.nq.v.y;
F yw = v2.y * q.nq.w;
F xz = v2.z * q.nq.v.x;
F zz = v2.z * q.nq.v.z;
F zw = v2.z * q.nq.w;
m00 = 1 - yy - zz;
m01 = xy - zw;
m02 = xz + yw;
m03 = t.x + t.x;
m10 = xy + zw;
m11 = xx - zz;
m12 = yz - xw;
m13 = t.y + t.y;
m20 = xz - yw;
m21 = yz + xw;
m22 = xx - yy;
m23 = t.z + t.z;
}
//CONSTRUCTOR for different float-types. It converts a DualQuat into a Matrix34.
//Needs to be 'explicit' because we loose float-precision in the conversion process
//Matrix34(QuatT);
template<class F1>
ILINE explicit Matrix34_tpl<F>(const DualQuat_tpl<F1> &q)
{
assert((fabs_tpl(1 - (q.nq | q.nq))) < 0.01); //check if unit-quaternion
Vec3_tpl<F1> t = (q.nq.w * q.dq.v - q.dq.w * q.nq.v + q.nq.v % q.dq.v); //perfect for HLSL
Vec3_tpl<F1> v2 = q.nq.v + q.nq.v;
F1 xx = 1 - v2.x * q.nq.v.x;
F1 yy = v2.y * q.nq.v.y;
F1 xw = v2.x * q.nq.w;
F1 xy = v2.y * q.nq.v.x;
F1 yz = v2.z * q.nq.v.y;
F1 yw = v2.y * q.nq.w;
F1 xz = v2.z * q.nq.v.x;
F1 zz = v2.z * q.nq.v.z;
F1 zw = v2.z * q.nq.w;
m00 = F(1 - yy - zz);
m01 = F(xy - zw);
m02 = F(xz + yw);
m03 = F(t.x + t.x);
m10 = F(xy + zw);
m11 = F(xx - zz);
m12 = F(yz - xw);
m13 = F(t.y + t.y);
m20 = F(xz - yw);
m21 = F(yz + xw);
m22 = F(xx - yy);
m23 = F(t.z + t.z);
}
//apply scaling to the columns of the matrix.
ILINE void ScaleColumn(const Vec3_tpl<F>& s)
{
@@ -580,7 +358,7 @@ struct Matrix34_tpl
* Initializes the Matrix34 with the identity.
*
*/
void SetIdentity(void)
void SetIdentity()
{
m00 = 1.0f;
m01 = 0.0f;
@@ -596,58 +374,12 @@ struct Matrix34_tpl
m23 = 0.0f;
}
ILINE static Matrix34_tpl<F> CreateIdentity(void)
ILINE static Matrix34_tpl<F> CreateIdentity()
{
Matrix34_tpl<F> m;
m.SetIdentity();
return m;
}
ILINE bool IsIdentity() const
{
return 0 == (fabs_tpl((F)1 - m00) + fabs_tpl(m01) + fabs_tpl(m02) + fabs_tpl(m03) + fabs_tpl(m10) + fabs_tpl((F)1 - m11) + fabs_tpl(m12) + fabs_tpl(m13) + fabs_tpl(m20) + fabs_tpl(m21) + fabs_tpl((F)1 - m22)) + fabs_tpl(m23);
}
ILINE int IsZero() const
{
return 0 == (fabs_tpl(m00) + fabs_tpl(m01) + fabs_tpl(m02) + fabs_tpl(m03) + fabs_tpl(m10) + fabs_tpl(m11) + fabs_tpl(m12) + fabs_tpl(m13) + fabs_tpl(m20) + fabs_tpl(m21) + fabs_tpl(m22)) + fabs_tpl(m23);
}
/*!
* Create a rotation matrix around an arbitrary axis (Eulers Theorem).
* The axis is specified as an normalized Vec3. The angle is assumed to be in radians.
* This function also assumes a translation-vector and stores it in the right column.
*
* Example:
* Matrix34 m34;
* Vec3 axis=GetNormalized( Vec3(-1.0f,-0.3f,0.0f) );
* m34.SetRotationAA( 3.14314f, axis, Vec3(5,5,5) );
*/
ILINE void SetRotationAA(const F rad, const Vec3_tpl<F>& axis, const Vec3_tpl<F>& t = Vec3(ZERO))
{
*this = Matrix33_tpl<F>::CreateRotationAA(rad, axis);
this->SetTranslation(t);
}
ILINE static Matrix34_tpl<F> CreateRotationAA(const F rad, const Vec3_tpl<F>& axis, const Vec3_tpl<F>& t = Vec3(ZERO))
{
Matrix34_tpl<F> m34;
m34.SetRotationAA(rad, axis, t);
return m34;
}
ILINE void SetRotationAA(const Vec3_tpl<F>& rot, const Vec3_tpl<F>& t = Vec3(ZERO))
{
*this = Matrix33_tpl<F>::CreateRotationAA(rot);
this->SetTranslation(t);
}
ILINE static Matrix34_tpl<F> CreateRotationAA(const Vec3_tpl<F>& rot, const Vec3_tpl<F>& t = Vec3(ZERO))
{
Matrix34_tpl<F> m34;
m34.SetRotationAA(rot, t);
return m34;
}
/*!
* Create rotation-matrix about X axis using an angle.
* The angle is assumed to be in radians.
@@ -690,28 +422,6 @@ struct Matrix34_tpl
return m34;
}
/*!
* Create rotation-matrix about Z axis using an angle.
* The angle is assumed to be in radians.
* The translation-vector is set to zero.
*
* Example:
* Matrix34 m34;
* m34.SetRotationZ(0.5f);
*/
ILINE void SetRotationZ(const f32 rad, const Vec3_tpl<F>& t = Vec3(ZERO))
{
*this = Matrix33_tpl<F>::CreateRotationZ(rad);
this->SetTranslation(t);
}
ILINE static Matrix34_tpl<F> CreateRotationZ(const f32 rad, const Vec3_tpl<F>& t = Vec3(ZERO))
{
Matrix34_tpl<F> m34;
m34.SetRotationZ(rad, t);
return m34;
}
/*!
*
* Convert three Euler angle to mat33 (rotation order:XYZ)
@@ -742,22 +452,6 @@ struct Matrix34_tpl
}
ILINE void SetRotationAA(F c, F s, Vec3_tpl<F> axis, const Vec3_tpl<F>& t = Vec3(ZERO))
{
assert(axis.IsValid());
assert(t.IsValid());
*this = Matrix33_tpl<F>::CreateRotationAA(c, s, axis);
m03 = t.x;
m13 = t.y;
m23 = t.z;
}
ILINE static Matrix34_tpl<F> CreateRotationAA(F c, F s, Vec3_tpl<F> axis, const Vec3_tpl<F>& t = Vec3(ZERO))
{
Matrix34_tpl<F> m34;
m34.SetRotationAA(c, s, axis, t);
return m34;
}
ILINE void SetTranslationMat(const Vec3_tpl<F>& v)
{
m00 = 1.0f;
@@ -804,25 +498,6 @@ struct Matrix34_tpl
return m;
}
void InvertFast()
{ // in-place transposition
assert(IsOrthonormal());
F t;
Vec3 v(m03, m13, m23);
t = m01;
m01 = m10;
m10 = t;
m03 = -v.x * m00 - v.y * m01 - v.z * m20;
t = m02;
m02 = m20;
m20 = t;
m13 = -v.x * m10 - v.y * m11 - v.z * m21;
t = m12;
m12 = m21;
m21 = t;
m23 = -v.x * m20 - v.y * m21 - v.z * m22;
}
Matrix34_tpl<F> GetInvertedFast() const
{
assert(IsOrthonormal());
@@ -875,14 +550,6 @@ struct Matrix34_tpl
m22 = z.z;
}
//determinant is ambiguous: only the upper-left-submatrix's determinant is calculated
ILINE f32 Determinant() const
{
return (m00 * m11 * m22) + (m01 * m12 * m20) + (m02 * m10 * m21) - (m02 * m11 * m20) - (m00 * m12 * m21) - (m01 * m10 * m22);
}
//--------------------------------------------------------------------------------
//---- helper functions to access matrix-members ------------
//--------------------------------------------------------------------------------
@@ -896,10 +563,8 @@ struct Matrix34_tpl
ILINE void SetRow(int i, const Vec3_tpl<F>& v) { assert(i < 3); F* p = (F*)(&m00); p[0 + 4 * i] = v.x; p[1 + 4 * i] = v.y; p[2 + 4 * i] = v.z; }
ILINE const Vec3_tpl<F>& GetRow(int i) const { assert(i < 3); return *(const Vec3_tpl<F>*)(&m00 + 4 * i); }
ILINE const Vec4_tpl<F>& GetRow4(int i) const { assert(i < 3); return *(const Vec4_tpl<F>*)(&m00 + 4 * i); }
ILINE const Vec4& GetRow4(int i) const { assert(i < 3); return *(const Vec4*)(&m00 + 4 * i); }
ILINE void SetColumn(int i, const Vec3_tpl<F>& v) { assert(i < 4); F* p = (F*)(&m00); p[i + 4 * 0] = v.x; p[i + 4 * 1] = v.y; p[i + 4 * 2] = v.z; }
ILINE Vec3_tpl<F> GetColumn(int i) const { assert(i < 4); F* p = (F*)(&m00); return Vec3(p[i + 4 * 0], p[i + 4 * 1], p[i + 4 * 2]); }
ILINE Vec3_tpl<F> GetColumn0() const { return Vec3_tpl<F>(m00, m10, m20); }
ILINE Vec3_tpl<F> GetColumn1() const { return Vec3_tpl<F>(m01, m11, m21); }
ILINE Vec3_tpl<F> GetColumn2() const { return Vec3_tpl<F>(m02, m12, m22); }
@@ -908,8 +573,6 @@ struct Matrix34_tpl
ILINE void SetTranslation(const Vec3_tpl<F>& t) { m03 = t.x; m13 = t.y; m23 = t.z; }
ILINE Vec3_tpl<F> GetTranslation() const { return Vec3_tpl<F>(m03, m13, m23); }
ILINE void ScaleTranslation (F s) { m03 *= s; m13 *= s; m23 *= s; }
ILINE Matrix34_tpl<F> AddTranslation(const Vec3_tpl<F>& t) { m03 += t.x; m13 += t.y; m23 += t.z; return *this; }
ILINE void SetRotation33(const Matrix33_tpl<F>& m33)
{
@@ -924,19 +587,6 @@ struct Matrix34_tpl
m22 = m33.m22;
}
ILINE void GetRotation33(Matrix33_tpl<F>& m33) const
{
m33.m00 = m00;
m33.m01 = m01;
m33.m02 = m02;
m33.m10 = m10;
m33.m11 = m11;
m33.m12 = m12;
m33.m20 = m20;
m33.m21 = m21;
m33.m22 = m22;
}
//check if we have an orthonormal-base (general case, works even with reflection matrices)
int IsOrthonormal(F threshold = 0.001) const
{
@@ -1031,15 +681,6 @@ struct Matrix34_tpl
return true;
}
bool IsDegenerate(float epsilon = FLT_EPSILON) const
{
//check the basis vectors for 0 vector
return GetColumn0().len2() < epsilon
|| GetColumn1().len2() < epsilon
|| GetColumn2().len2() < epsilon;
}
/*!
* Create a matrix with SCALING, ROTATION and TRANSLATION (in this order).
*
@@ -1093,43 +734,12 @@ struct Matrix34_tpl
* Example 1:
* Matrix m34;
* m34.SetScale( Vec3(0.5f, 1.0f, 2.0f) );
* Example 2:
* Matrix34 m34 = Matrix34::CreateScale( Vec3(0.5f, 1.0f, 2.0f) );
*/
ILINE void SetScale(const Vec3_tpl<F>& s, const Vec3_tpl<F>& t = Vec3(ZERO))
{
*this = Matrix33::CreateScale(s);
this->SetTranslation(t);
}
ILINE static Matrix34_tpl<F> CreateScale(const Vec3_tpl<F>& s, const Vec3_tpl<F>& t = Vec3(ZERO))
{
Matrix34_tpl<F> m34;
m34.SetScale(s, t);
return m34;
}
ILINE Matrix44_tpl<F> GetTransposed() const
{
Matrix44_tpl<F> tmp;
tmp.m00 = m00;
tmp.m01 = m10;
tmp.m02 = m20;
tmp.m03 = 0;
tmp.m10 = m01;
tmp.m11 = m11;
tmp.m12 = m21;
tmp.m13 = 0;
tmp.m20 = m02;
tmp.m21 = m12;
tmp.m22 = m22;
tmp.m23 = 0;
tmp.m30 = m03;
tmp.m31 = m13;
tmp.m32 = m23;
tmp.m33 = 1;
return tmp;
}
/*!
* calculate a real inversion of a Matrix34
@@ -1141,7 +751,7 @@ struct Matrix34_tpl
* Example 2:
* Matrix34 im34 = m34.GetInverted();
*/
void Invert(void)
void Invert()
{
//rescue members
Matrix34_tpl<F> m = *this;
@@ -1182,37 +792,6 @@ struct Matrix34_tpl
dst.Invert();
return dst;
}
/*!
* Name: ReflectMat34
* Description: reflect a rotation matrix with respect to a plane.
*
* Example:
* Vec3 normal( 0.0f,-1.0f, 0.0f);
* Vec3 pos(0,1000,0);
* Matrix34 m34=CreateReflectionMat( pos, normal );
*/
ILINE static Matrix34_tpl<F> CreateReflectionMat (const Vec3_tpl<F>& p, const Vec3_tpl<F>& n)
{
Matrix34_tpl<F> m;
F vxy = -2.0f * n.x * n.y;
F vxz = -2.0f * n.x * n.z;
F vyz = -2.0f * n.y * n.z;
F pdotn = 2.0f * (p | n);
m.m00 = 1.0f - 2.0f * n.x * n.x;
m.m01 = vxy;
m.m02 = vxz;
m.m03 = pdotn * n.x;
m.m10 = vxy;
m.m11 = 1.0f - 2.0f * n.y * n.y;
m.m12 = vyz;
m.m13 = pdotn * n.y;
m.m20 = vxz;
m.m21 = vyz;
m.m22 = 1.0f - 2.0f * n.z * n.z;
m.m23 = pdotn * n.z;
return m;
}
};
///////////////////////////////////////////////////////////////////////////////
@@ -1220,8 +799,6 @@ struct Matrix34_tpl
///////////////////////////////////////////////////////////////////////////////
typedef Matrix34_tpl<f32> Matrix34; //always 32 bit
typedef Matrix34_tpl<f64> Matrix34d;//always 64 bit
typedef Matrix34_tpl<real> Matrix34r;//variable float precision. depending on the target system it can be between 32, 64 or bit
#if AZ_COMPILER_MSVC
typedef __declspec(align(16)) Matrix34_tpl<f32> Matrix34A;
#elif AZ_COMPILER_CLANG
@@ -1423,6 +1000,3 @@ ILINE Matrix44_tpl<F> operator * (const Matrix34_tpl<F>& l, const Matrix44_tpl<F
m.m33 = r.m33;
return m;
}
#endif // CRYINCLUDE_CRYCOMMON_CRY_MATRIX34_H
+8 -8
View File
@@ -568,12 +568,12 @@ struct Matrix44_tpl
ILINE F& operator () (uint32 i, uint32 j) { assert ((i < 4) && (j < 4)); F* p_data = (F*)(&m00); return p_data[i * 4 + j]; }
ILINE void SetRow(int i, const Vec3_tpl<F>& v) { assert(i < 4); F* p = (F*)(&m00); p[0 + 4 * i] = v.x; p[1 + 4 * i] = v.y; p[2 + 4 * i] = v.z; }
ILINE void SetRow4(int i, const Vec4_tpl<F>& v) { assert(i < 4); F* p = (F*)(&m00); p[0 + 4 * i] = v.x; p[1 + 4 * i] = v.y; p[2 + 4 * i] = v.z; p[3 + 4 * i] = v.w; }
ILINE void SetRow4(int i, const Vec4& v) { assert(i < 4); F* p = (F*)(&m00); p[0 + 4 * i] = v.x; p[1 + 4 * i] = v.y; p[2 + 4 * i] = v.z; p[3 + 4 * i] = v.w; }
ILINE const Vec3_tpl<F>& GetRow(int i) const { assert(i < 4); return *(const Vec3_tpl<F>*)(&m00 + 4 * i); }
ILINE void SetColumn(int i, const Vec3_tpl<F>& v) { assert(i < 4); F* p = (F*)(&m00); p[i + 4 * 0] = v.x; p[i + 4 * 1] = v.y; p[i + 4 * 2] = v.z; }
ILINE Vec3_tpl<F> GetColumn(int i) const { assert(i < 4); F* p = (F*)(&m00); return Vec3(p[i + 4 * 0], p[i + 4 * 1], p[i + 4 * 2]); }
ILINE Vec4_tpl<F> GetColumn4(int i) const { assert(i < 4); F* p = (F*)(&m00); return Vec4(p[i + 4 * 0], p[i + 4 * 1], p[i + 4 * 2], p[i + 4 * 3]); }
ILINE Vec4 GetColumn4(int i) const { assert(i < 4); F* p = (F*)(&m00); return Vec4(p[i + 4 * 0], p[i + 4 * 1], p[i + 4 * 2], p[i + 4 * 3]); }
ILINE Vec3 GetTranslation() const { return Vec3(m03, m13, m23); }
ILINE void SetTranslation(const Vec3& t) { m03 = t.x; m13 = t.y; m23 = t.z; }
@@ -792,24 +792,24 @@ ILINE Matrix44_tpl<F1> operator * (const Matrix44_tpl<F1>& l, const Matrix44_tpl
}
//post-multiply
template<class F1, class F2>
ILINE Vec4_tpl<F1> operator*(const Matrix44_tpl<F2>& m, const Vec4_tpl<F1>& v)
template<class F2>
ILINE Vec4 operator*(const Matrix44_tpl<F2>& m, const Vec4& v)
{
assert(m.IsValid());
assert(v.IsValid());
return Vec4_tpl<F1>(v.x * m.m00 + v.y * m.m01 + v.z * m.m02 + v.w * m.m03,
return Vec4(v.x * m.m00 + v.y * m.m01 + v.z * m.m02 + v.w * m.m03,
v.x * m.m10 + v.y * m.m11 + v.z * m.m12 + v.w * m.m13,
v.x * m.m20 + v.y * m.m21 + v.z * m.m22 + v.w * m.m23,
v.x * m.m30 + v.y * m.m31 + v.z * m.m32 + v.w * m.m33);
}
//pre-multiply
template<class F1, class F2>
ILINE Vec4_tpl<F1> operator*(const Vec4_tpl<F1>& v, const Matrix44_tpl<F2>& m)
template<class F2>
ILINE Vec4 operator*(const Vec4& v, const Matrix44_tpl<F2>& m)
{
assert(m.IsValid());
assert(v.IsValid());
return Vec4_tpl<F1>(v.x * m.m00 + v.y * m.m10 + v.z * m.m20 + v.w * m.m30,
return Vec4(v.x * m.m00 + v.y * m.m10 + v.z * m.m20 + v.w * m.m30,
v.x * m.m01 + v.y * m.m11 + v.z * m.m21 + v.w * m.m31,
v.x * m.m02 + v.y * m.m12 + v.z * m.m22 + v.w * m.m32,
v.x * m.m03 + v.y * m.m13 + v.z * m.m23 + v.w * m.m33);
File diff suppressed because it is too large Load Diff
-8
View File
@@ -302,21 +302,13 @@ struct Vec2_tpl
///////////////////////////////////////////////////////////////////////////////
typedef Vec2_tpl<f32> Vec2; // always 32 bit
typedef Vec2_tpl<f64> Vec2d; // always 64 bit
typedef Vec2_tpl<int32> Vec2i;
typedef Vec2_tpl<uint32> Vec2ui;
typedef Vec2_tpl<real> Vec2r; // variable float precision. depending on the target system it can be 32, 64 or 80 bit
typedef Vec2_tpl<float> vector2f;
#if defined(LINUX64)
typedef Vec2_tpl<int> vector2l;
#else
typedef Vec2_tpl<long> vector2l;
#endif
typedef Vec2_tpl<float> vector2df;
typedef Vec2_tpl<real> vector2d;
typedef Vec2_tpl<int> vector2di;
typedef Vec2_tpl<unsigned int> vector2dui;
template<class F>
Vec2_tpl<F> operator*(F op1, const Vec2_tpl<F>& op2) {return Vec2_tpl<F>(op1 * op2.x, op1 * op2.y); }
+2 -45
View File
@@ -178,21 +178,6 @@ struct Vec3_tpl
assert(IsValid());
}
explicit ILINE Vec3_tpl<F>(const Vec4_tpl<F> &v) {
x = F(v.x);
y = F(v.y);
z = F(v.z);
}
template<class T>
explicit ILINE Vec3_tpl<F>(const Vec4_tpl<T> &v) {
x = F(v.x);
y = F(v.y);
z = F(v.z);
}
/*!
* overloaded arithmetic operator
*
@@ -847,6 +832,8 @@ struct Vec3_tpl
}
};
using Vec3i = Vec3_tpl<int32>;
// dot product (2 versions)
template<class F1, class F2>
ILINE F1 operator * (const Vec3_tpl<F1>& v0, const Vec3_tpl<F2>& v1)
@@ -943,15 +930,6 @@ ILINE bool IsEquivalent(const Vec3_tpl<F>& v0, const Vec3_tpl<F>& v1, f32 epsilo
///////////////////////////////////////////////////////////////////////////////
typedef Vec3_tpl<f32> Vec3; // always 32 bit
typedef Vec3_tpl<f64> Vec3d; // always 64 bit
typedef Vec3_tpl<int32> Vec3i;
typedef Vec3_tpl<uint32> Vec3ui;
typedef Vec3_tpl<real> Vec3r; // variable float precision. depending on the target system it can be 32, 64 or 80 bit
template<>
inline Vec3_tpl<f64>::Vec3_tpl(type_min) { x = y = z = -1.7E308; }
template<>
inline Vec3_tpl<f64>::Vec3_tpl(type_max) { x = y = z = 1.7E308; }
template<>
inline Vec3_tpl<f32>::Vec3_tpl(type_min) { x = y = z = -3.3E38f; }
template<>
@@ -1176,8 +1154,6 @@ struct Ang3_tpl
};
typedef Ang3_tpl<f32> Ang3;
typedef Ang3_tpl<real> Ang3r;
typedef Ang3_tpl<f64> Ang3_f64;
//---------------------------------------
@@ -1251,7 +1227,6 @@ struct AngleAxis_tpl
};
typedef AngleAxis_tpl<f32> AngleAxis;
typedef AngleAxis_tpl<f64> AngleAxis_f64;
template<typename F>
ILINE const Vec3_tpl<F> AngleAxis_tpl<F>::operator * (const Vec3_tpl<F>& v) const
@@ -1260,22 +1235,6 @@ ILINE const Vec3_tpl<F> AngleAxis_tpl<F>::operator * (const Vec3_tpl<F>& v) cons
return origin + (v - origin) * cos_tpl(angle) + (axis % v) * sin_tpl(angle);
}
//////////////////////////////////////////////////////////////////////
template<typename F>
struct Plane_tpl
@@ -1405,8 +1364,6 @@ struct Plane_tpl
};
typedef Plane_tpl<f32> Plane; //always 32 bit
typedef Plane_tpl<f64> Planed;//always 64 bit
typedef Plane_tpl<real> Planer;//variable float precision. depending on the target system it can be between 32, 64 or 80 bit
// declare common constants. Must be done after the class for compiler conformance
+41 -111
View File
@@ -5,37 +5,31 @@
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
// Description : Common vector class
#pragma once
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// class Vec4_tpl
// class Vec4
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
template <typename F>
struct Vec4_tpl
struct Vec4
{
typedef F value_type;
using value_type = f32;
enum
{
component_count = 4
};
F x, y, z, w;
f32 x, y, z, w;
#if defined(_DEBUG)
ILINE Vec4_tpl()
ILINE Vec4()
{
if constexpr (sizeof(F) == 4)
if constexpr (sizeof(f32) == 4)
{
uint32* p = alias_cast<uint32*>(&x);
p[0] = F32NAN;
@@ -43,49 +37,25 @@ struct Vec4_tpl
p[2] = F32NAN;
p[3] = F32NAN;
}
if constexpr (sizeof(F) == 8)
{
uint64* p = alias_cast<uint64*>(&x);
p[0] = F64NAN;
p[1] = F64NAN;
p[2] = F64NAN;
p[3] = F64NAN;
}
}
#else
ILINE Vec4_tpl() {}
ILINE Vec4() {}
#endif
template<typename F2>
ILINE Vec4_tpl<F>& operator = (const Vec4_tpl<F2>& v1)
{
x = F(v1.x);
y = F(v1.y);
z = F(v1.z);
w = F(v1.w);
return (*this);
}
ILINE Vec4(f32 vx, f32 vy, f32 vz, f32 vw) { x = vx; y = vy; z = vz; w = vw; }
ILINE Vec4(const Vec3_tpl<f32>& v, f32 vw) { x = v.x; y = v.y; z = v.z; w = vw; }
explicit ILINE Vec4(f32 m) { x = y = z = w = m; }
ILINE Vec4(type_zero) { x = y = z = w = f32(0); }
ILINE Vec4_tpl(F vx, F vy, F vz, F vw) { x = vx; y = vy; z = vz; w = vw; }
ILINE Vec4_tpl(const Vec3_tpl<F>& v, F vw) { x = v.x; y = v.y; z = v.z; w = vw; }
explicit ILINE Vec4_tpl(F m) { x = y = z = w = m; }
ILINE Vec4_tpl(type_zero) { x = y = z = w = F(0); }
ILINE void operator () (f32 vx, f32 vy, f32 vz, f32 vw) { x = vx; y = vy; z = vz; w = vw; }
ILINE void operator () (const Vec3_tpl<f32>& v, f32 vw) { x = v.x; y = v.y; z = v.z; w = vw; }
ILINE void operator () (F vx, F vy, F vz, F vw) { x = vx; y = vy; z = vz; w = vw; }
ILINE void operator () (const Vec3_tpl<F>& v, F vw) { x = v.x; y = v.y; z = v.z; w = vw; }
ILINE f32& operator [] (int index) { assert(index >= 0 && index <= 3); return ((f32*)this)[index]; }
ILINE f32 operator [] (int index) const { assert(index >= 0 && index <= 3); return ((f32*)this)[index]; }
ILINE F& operator [] (int index) { assert(index >= 0 && index <= 3); return ((F*)this)[index]; }
ILINE F operator [] (int index) const { assert(index >= 0 && index <= 3); return ((F*)this)[index]; }
template <class T>
ILINE Vec4_tpl(const Vec4_tpl<T>& v)
: x((F)v.x)
, y((F)v.y)
, z((F)v.z)
, w((F)v.w) { assert(this->IsValid()); }
ILINE Vec4& zero() { x = y = z = w = 0; return *this; }
ILINE Vec4_tpl& zero() { x = y = z = w = 0; return *this; }
ILINE bool IsEquivalent(const Vec4_tpl<F>& v1, F epsilon = VEC_EPSILON) const
ILINE bool IsEquivalent(const Vec4& v1, f32 epsilon = VEC_EPSILON) const
{
assert(v1.IsValid());
assert(this->IsValid());
@@ -93,7 +63,7 @@ struct Vec4_tpl
}
ILINE Vec4_tpl& operator=(const Vec4_tpl& src)
ILINE Vec4& operator=(const Vec4& src)
{
x = src.x;
y = src.y;
@@ -102,17 +72,17 @@ struct Vec4_tpl
return *this;
}
ILINE Vec4_tpl<F> operator * (F k) const
ILINE Vec4 operator * (f32 k) const
{
return Vec4_tpl<F>(x * k, y * k, z * k, w * k);
return Vec4(x * k, y * k, z * k, w * k);
}
ILINE Vec4_tpl<F> operator / (F k) const
ILINE Vec4 operator / (f32 k) const
{
k = (F)1.0 / k;
return Vec4_tpl<F>(x * k, y * k, z * k, w * k);
k = (f32)1.0 / k;
return Vec4(x * k, y * k, z * k, w * k);
}
ILINE Vec4_tpl<F>& operator *= (F k)
ILINE Vec4& operator *= (f32 k)
{
x *= k;
y *= k;
@@ -120,9 +90,9 @@ struct Vec4_tpl
w *= k;
return *this;
}
ILINE Vec4_tpl<F>& operator /= (F k)
ILINE Vec4& operator /= (f32 k)
{
k = (F)1.0 / k;
k = (f32)1.0 / k;
x *= k;
y *= k;
z *= k;
@@ -130,7 +100,7 @@ struct Vec4_tpl
return *this;
}
ILINE void operator += (const Vec4_tpl<F>& v)
ILINE void operator += (const Vec4& v)
{
x += v.x;
y += v.y;
@@ -138,7 +108,7 @@ struct Vec4_tpl
w += v.w;
}
ILINE void operator -= (const Vec4_tpl<F>& v)
ILINE void operator -= (const Vec4& v)
{
x -= v.x;
y -= v.y;
@@ -147,17 +117,17 @@ struct Vec4_tpl
}
ILINE F Dot (const Vec4_tpl<F>& vec2) const
ILINE f32 Dot (const Vec4& vec2) const
{
return x * vec2.x + y * vec2.y + z * vec2.z + w * vec2.w;
}
ILINE F GetLength() const
ILINE f32 GetLength() const
{
return sqrt_tpl(Dot(*this));
}
ILINE F GetLengthSquared() const
ILINE f32 GetLengthSquared() const
{
return Dot(*this);
}
@@ -190,24 +160,24 @@ struct Vec4_tpl
* Example:
* if (v0==v1) dosomething;
*/
ILINE bool operator==(const Vec4_tpl<F>& vec)
ILINE bool operator==(const Vec4& vec)
{
return x == vec.x && y == vec.y && z == vec.z && w == vec.w;
}
ILINE bool operator!=(const Vec4_tpl<F>& vec) { return !(*this == vec); }
ILINE bool operator!=(const Vec4& vec) { return !(*this == vec); }
ILINE friend bool operator ==(const Vec4_tpl<F>& v0, const Vec4_tpl<F>& v1)
ILINE friend bool operator ==(const Vec4& v0, const Vec4& v1)
{
return ((v0.x == v1.x) && (v0.y == v1.y) && (v0.z == v1.z) && (v0.w == v1.w));
}
ILINE friend bool operator !=(const Vec4_tpl<F>& v0, const Vec4_tpl<F>& v1) { return !(v0 == v1); }
ILINE friend bool operator !=(const Vec4& v0, const Vec4& v1) { return !(v0 == v1); }
//! normalize the vector
// The default Normalize function is in fact "safe". 0 vectors remain unchanged.
ILINE void Normalize()
{
assert(this->IsValid());
F fInvLen = isqrt_safe_tpl(x * x + y * y + z * z + w * w);
f32 fInvLen = isqrt_safe_tpl(x * x + y * y + z * z + w * w);
x *= fInvLen;
y *= fInvLen;
z *= fInvLen;
@@ -218,61 +188,21 @@ struct Vec4_tpl
ILINE void NormalizeFast()
{
assert(this->IsValid());
F fInvLen = isqrt_fast_tpl(x * x + y * y + z * z + w * w);
f32 fInvLen = isqrt_fast_tpl(x * x + y * y + z * z + w * w);
x *= fInvLen;
y *= fInvLen;
z *= fInvLen;
w *= fInvLen;
}
ILINE void SetLerp(const Vec4_tpl<F>& p, const Vec4_tpl<F>& q, F t) { *this = p * (1.0f - t) + q * t; }
ILINE static Vec4_tpl<F> CreateLerp(const Vec4_tpl<F>& p, const Vec4_tpl<F>& q, F t) { return p * (1.0f - t) + q * t; }
};
typedef Vec4_tpl<f32> Vec4; // always 32 bit
typedef Vec4_tpl<f64> Vec4d; // always 64 bit
typedef Vec4_tpl<int32> Vec4i;
typedef Vec4_tpl<uint32> Vec4ui;
typedef Vec4_tpl<real> Vec4r; // variable float precision. depending on the target system it can be 32, 64 or 80 bit
#if defined(WIN32) || defined(WIN64) || defined(LINUX) || defined(APPLE)
typedef Vec4_tpl<f32> Vec4A;
#elif defined(AZ_RESTRICTED_PLATFORM)
#include AZ_RESTRICTED_FILE(Cry_Vector4_h)
#endif
//vector self-addition
template<class F1, class F2>
ILINE Vec4_tpl<F1>& operator += (Vec4_tpl<F1>& v0, const Vec4_tpl<F2>& v1)
{
v0 = v0 + v1;
return v0;
}
//vector addition
template<class F1, class F2>
ILINE Vec4_tpl<F1> operator + (const Vec4_tpl<F1>& v0, const Vec4_tpl<F2>& v1)
ILINE Vec4 operator + (const Vec4& v0, const Vec4& v1)
{
return Vec4_tpl<F1>(v0.x + v1.x, v0.y + v1.y, v0.z + v1.z, v0.w + v1.w);
return Vec4(v0.x + v1.x, v0.y + v1.y, v0.z + v1.z, v0.w + v1.w);
}
//vector subtraction
template<class F1, class F2>
ILINE Vec4_tpl<F1> operator - (const Vec4_tpl<F1>& v0, const Vec4_tpl<F2>& v1)
ILINE Vec4 operator - (const Vec4& v0, const Vec4& v1)
{
return Vec4_tpl<F1>(v0.x - v1.x, v0.y - v1.y, v0.z - v1.z, v0.w - v1.w);
}
//vector multiplication
template<class F1, class F2>
ILINE Vec4_tpl<F1> operator * (const Vec4_tpl<F1> v0, const Vec4_tpl<F2>& v1)
{
return Vec4_tpl<F1>(v0.x * v1.x, v0.y * v1.y, v0.z * v1.z, v0.w * v1.w);
}
//vector division
template<class F1, class F2>
ILINE Vec4_tpl<F1> operator / (const Vec4_tpl<F1>& v0, const Vec4_tpl<F2>& v1)
{
return Vec4_tpl<F1>(v0.x / v1.x, v0.y / v1.y, v0.z / v1.z, v0.w / v1.w);
return Vec4(v0.x - v1.x, v0.y - v1.y, v0.z - v1.z, v0.w - v1.w);
}
@@ -1,93 +0,0 @@
/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
// Description : Implementation of the common function template specializations.
#ifndef CRYINCLUDE_CRYCOMMON_FUNCTORBASEFUNCTION_H
#define CRYINCLUDE_CRYCOMMON_FUNCTORBASEFUNCTION_H
#pragma once
#include "IFunctorBase.h"
//////////////////////////////////////////////////////////////////////////
// Return type void
// No arguments.
template<>
class TFunctor<void (*)()>
: public IFunctorBase
{
public:
typedef void (* TFunctionType)();
TFunctor(TFunctionType pFunction)
: m_pfnFunction(pFunction){}
virtual void Call()
{
m_pfnFunction();
}
private:
TFunctionType m_pfnFunction;
};
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
// Return type void
// 1 argument.
template<typename tArgument1>
class TFunctor<void (*)(tArgument1)>
: public IFunctorBase
{
public:
typedef void (* TFunctionType)(tArgument1);
TFunctor(TFunctionType pFunction, tArgument1 Argument1)
: m_pfnFunction(pFunction)
, m_tArgument1(Argument1){}
virtual void Call()
{
m_pfnFunction(m_tArgument1);
}
private:
TFunctionType m_pfnFunction;
tArgument1 m_tArgument1;
};
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
// Return type void
// 2 arguments.
template<typename tArgument1, typename tArgument2>
class TFunctor<void (*)(tArgument1, tArgument2)>
: public IFunctorBase
{
public:
typedef void (* TFunctionType)(tArgument1, tArgument2);
TFunctor(TFunctionType pFunction, const tArgument1& Argument1, const tArgument2& Argument2)
: m_pfnFunction(pFunction)
, m_tArgument1(Argument1)
, m_tArgument2(Argument2){}
virtual void Call()
{
m_pfnFunction(m_tArgument1, m_tArgument2);
}
private:
TFunctionType m_pfnFunction;
tArgument1 m_tArgument1;
tArgument2 m_tArgument2;
};
//////////////////////////////////////////////////////////////////////////
#endif // CRYINCLUDE_CRYCOMMON_FUNCTORBASEFUNCTION_H
-97
View File
@@ -1,97 +0,0 @@
/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
// Description : Implementation of the member function template specializations.
#ifndef CRYINCLUDE_CRYCOMMON_FUNCTORBASEMEMBER_H
#define CRYINCLUDE_CRYCOMMON_FUNCTORBASEMEMBER_H
#pragma once
#include "IFunctorBase.h"
//////////////////////////////////////////////////////////////////////////
// Return type void
// No Arguments
template<typename tCalleeType>
class TFunctor<void (tCalleeType::*)()>
: public IFunctorBase
{
public:
typedef void (tCalleeType::* TMemberFunctionType)();
TFunctor(tCalleeType* pCallee, TMemberFunctionType pMemberFunction)
: m_pCalee(pCallee)
, m_pfnMemberFunction(pMemberFunction){}
virtual void Call()
{
(m_pCalee->*m_pfnMemberFunction)();
}
private:
tCalleeType* m_pCalee;
TMemberFunctionType m_pfnMemberFunction;
};
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
// Return type void
// 1 argument.
template<typename tCalleeType, typename tArgument1>
class TFunctor<void (tCalleeType::*)(tArgument1)>
: public IFunctorBase
{
public:
typedef void (tCalleeType::* TMemberFunctionType)(tArgument1);
TFunctor(tCalleeType* pCallee, TMemberFunctionType pMemberFunction, const tArgument1& Argument1)
: m_pCalee(pCallee)
, m_pfnMemberFunction(pMemberFunction)
, m_tArgument1(Argument1){}
virtual void Call()
{
(m_pCalee->*m_pfnMemberFunction)(m_tArgument1);
}
private:
tCalleeType* m_pCalee;
TMemberFunctionType m_pfnMemberFunction;
tArgument1 m_tArgument1;
};
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
// Return type void
// 2 arguments.
template<typename tCalleeType, typename tArgument1, typename tArgument2>
class TFunctor<void (tCalleeType::*)(tArgument1, tArgument2)>
: public IFunctorBase
{
public:
typedef void (tCalleeType::* TMemberFunctionType)(tArgument1, tArgument2);
TFunctor(tCalleeType* pCallee, TMemberFunctionType pMemberFunction, const tArgument1& Argument1, const tArgument2& Argument2)
: m_pCalee(pCallee)
, m_pfnMemberFunction(pMemberFunction)
, m_tArgument1(Argument1)
, m_tArgument2(Argument2){}
virtual void Call()
{
(m_pCalee->*m_pfnMemberFunction)(m_tArgument1, m_tArgument2);
}
private:
tCalleeType* m_pCalee;
TMemberFunctionType m_pfnMemberFunction;
tArgument1 m_tArgument1;
tArgument2 m_tArgument2;
};
//////////////////////////////////////////////////////////////////////////
#endif // CRYINCLUDE_CRYCOMMON_FUNCTORBASEMEMBER_H
+2 -28
View File
@@ -10,15 +10,13 @@
#include <CryCommon/platform.h>
#include <AzCore/std/containers/vector.h>
#include <AzCore/std/function/function_template.h>
#include <AzCore/std/string/string_view.h>
struct SFunctor;
struct ConsoleBind;
struct ICVar;
class ITexture;
class ICrySizer;
struct ISystem;
#define CVAR_INT 1
@@ -192,15 +190,6 @@ struct IConsole
// Return:
// pointer to the interface ICVar
virtual ICVar* RegisterInt(const char* sName, int iValue, int nFlags, const char* help = "", ConsoleVarFunc pChangeFunc = 0) = 0;
// Create a new console variable that store the value in a int64
// Arguments:
// sName - console variable name
// iValue - default value
// nFlags - user defined flag, this parameter is used by other subsystems and doesn't affect the console variable (basically of user data)
// help - help text that is shown when you use <sName> ? in the console
// Return:
// pointer to the interface ICVar
virtual ICVar* RegisterInt64(const char* sName, int64 iValue, int nFlags, const char* help = "", ConsoleVarFunc pChangeFunc = 0) = 0;
// Create a new console variable that store the value in a float
// Arguments:
// sName - console variable name
@@ -243,14 +232,6 @@ struct IConsole
// pointer to the interface ICVar
virtual ICVar* Register(const char* name, const char** src, const char* defaultvalue, int nFlags = 0, const char* help = "", ConsoleVarFunc pChangeFunc = 0, bool allowModify = true) = 0;
// Registers an existing console variable
// Should only be used with static duration objects, object is never freed
// Arguments:
// pVar - the existing console variable
// Return:
// pointer to the interface ICVar (that was passed in)
virtual ICVar* Register(ICVar* pVar) = 0;
// ! Remove a variable from the console
// @param sVarName console variable name
// @param bDelete if true the variable is deleted
@@ -431,9 +412,6 @@ struct IConsole
virtual void ResetAutoCompletion() = 0;
//////////////////////////////////////////////////////////////////////////
// Calculation of the memory used by the whole console system
virtual void GetMemoryUsage (ICrySizer* pSizer) const = 0;
// Function related to progress bar
virtual void ResetProgressBar(int nProgressRange) = 0;
// Function related to progress bar
@@ -619,16 +597,12 @@ struct ICVar
// Adds a new on change functor to the list.
// It will add from index 1 on (0 is reserved).
// Returns an ID to use when getting or removing the functor
virtual uint64 AddOnChangeFunctor(const SFunctor& pChangeFunctor) = 0;
virtual uint64 AddOnChangeFunctor(const AZStd::function<void()>& pChangeFunctor) = 0;
//////////////////////////////////////////////////////////////////////////
// Get the current callback function.
virtual ConsoleVarFunc GetOnChangeCallback() const = 0;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
virtual void GetMemoryUsage(class ICrySizer* pSizer) const = 0;
//////////////////////////////////////////////////////////////////////////
// only useful for CVarGroups, other types return GetIVal()
// CVarGroups set multiple other CVars and this function returns
+3 -22
View File
@@ -7,33 +7,14 @@
*/
#pragma once
#include <CryCommon/Cry_Matrix34.h>
#include "IStatObj.h"
#include <IRenderer.h>
#include <limits>
#include <AzCore/Component/EntityId.h>
#include <AzCore/std/algorithm.h>
namespace AZ
{
class Vector2;
}
struct IMaterial;
struct IRenderNode;
struct IVisArea;
struct SRenderingPassInfo;
struct SRendItemSorter;
struct SFrameLodInfo;
struct pe_params_area;
struct pe_articgeomparams;
struct IStatObj;
struct IRenderNode
{
// Gives access to object components.
struct IStatObj* GetEntityStatObj(unsigned int = 0, unsigned int = 0, Matrix34A* = NULL, bool = false) {
IStatObj* GetEntityStatObj(unsigned int = 0, unsigned int = 0, Matrix34* = nullptr, bool = false) {
return nullptr;
}
-8
View File
@@ -23,7 +23,6 @@
#include <AzCore/EBus/EBus.h>
struct ISystem;
class ICrySizer;
struct ICryFont;
struct IFFont;
@@ -94,9 +93,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:
// Puts the objects used in this module into the sizer interface
virtual void GetMemoryUsage(ICrySizer* pSizer) const = 0;
// Summary:
// All font names separated by ,
// Example:
@@ -266,10 +262,6 @@ struct IFFont
// Wraps text based on specified maximum line width (UTF-8)
virtual void WrapText(AZStd::string& result, float maxWidth, const char* pStr, const STextDrawContext& ctx) = 0;
// Description:
// Puts the memory used by this font into the given sizer.
virtual void GetMemoryUsage(ICrySizer* pSizer) const = 0;
// Description:
// useful for special feature rendering interleaved with fonts (e.g. box behind the text)
virtual void GetGradientTextureCoord(float& minU, float& minV, float& maxU, float& maxV) const = 0;
-50
View File
@@ -10,13 +10,8 @@
#pragma once
#include "Cry_Color.h"
#include "StlUtils.h"
#include "CryEndian.h"
#include <Cry_Geo.h> // for AABB
#include <VertexFormats.h>
#include <Vertex.h>
#include <AzCore/Casting/numeric_cast.h>
// Description:
// 2D Texture coordinates used by CMesh.
@@ -28,32 +23,6 @@ private:
float s, t;
public:
explicit SMeshTexCoord(float x, float y)
{
s = x;
t = y;
}
explicit SMeshTexCoord(const Vec2f16& other)
{
const Vec2 uv = other.ToVec2();
s = uv.x;
t = uv.y;
}
explicit SMeshTexCoord(const Vec2& other)
{
s = other.x;
t = other.y;
}
explicit SMeshTexCoord(const Vec4& other)
{
s = other.x;
t = other.y;
}
bool IsEquivalent(const SMeshTexCoord& other, float epsilon = 0.00005f) const
{
return
@@ -113,16 +82,6 @@ public:
};
struct SMeshBoneMapping_uint8
{
typedef uint8 BoneId;
typedef uint8 Weight;
BoneId boneIds[4];
Weight weights[4];
};
// Subset of mesh is a continuous range of vertices and indices that share same material.
struct SMeshSubset
{
@@ -181,7 +140,6 @@ struct IIndexedMesh
int m_nIndexCount; // number of elements in m_pIndices array
};
// <interfuscator:shuffle>
virtual ~IIndexedMesh() {}
// Release indexed mesh.
@@ -190,15 +148,9 @@ struct IIndexedMesh
//! Gives read-only access to mesh data
virtual void GetMeshDescription(SMeshDescription& meshDesc) const = 0;
/*! Frees vertex and face streams. Calling this function invalidates SMeshDescription pointers */
virtual void FreeStreams() = 0;
//! Return number of allocated faces
virtual int GetFaceCount() const = 0;
/*! Reallocates faces. Calling this function invalidates SMeshDescription pointers */
virtual void SetFaceCount(int nNewCount) = 0;
//! Return number of allocated vertices, normals and colors
virtual int GetVertexCount() const = 0;
@@ -216,6 +168,4 @@ struct IIndexedMesh
//////////////////////////////////////////////////////////////////////////
virtual int GetSubSetCount() const = 0;
virtual const SMeshSubset& GetSubSet(int nIndex) const = 0;
// </interfuscator:shuffle>
};
-9
View File
@@ -8,13 +8,8 @@
// Description : Gathers level information. Loads a level.
#ifndef CRYINCLUDE_CRYACTION_ILEVELSYSTEM_H
#define CRYINCLUDE_CRYACTION_ILEVELSYSTEM_H
#pragma once
#include <CrySizer.h>
#include <IXml.h>
#include <AzCore/Asset/AssetCommon.h>
@@ -56,8 +51,6 @@ struct ILevelSystemListener
virtual void OnLoadingProgress([[maybe_unused]] const char* levelName, [[maybe_unused]] int progressAmount) {}
//! Called after a level is unloaded, before the data is freed.
virtual void OnUnloadComplete([[maybe_unused]] const char* levelName) {}
void GetMemoryUsage([[maybe_unused]] ICrySizer* pSizer) const { }
};
struct ILevelSystem
@@ -95,5 +88,3 @@ protected:
static constexpr const char* LevelsDirectoryName = "levels";
};
#endif // CRYINCLUDE_CRYACTION_ILEVELSYSTEM_H
@@ -43,10 +43,6 @@ struct SLocalizedAdvancesSoundEntry
{
AZStd::string sName;
float fValue;
void GetMemoryUsage(ICrySizer* pSizer) const
{
pSizer->AddObject(sName);
}
};
// Localization Sound Info structure, containing sound related parameters.
-7
View File
@@ -16,9 +16,6 @@
// this code is disable by default due it's runtime cost
//#define SUPPORT_LOG_IDENTER
// forward declarations
class ICrySizer;
// Summary:
// Callback interface to the ILog.
struct ILogCallback
@@ -121,10 +118,6 @@ struct ILog
virtual const char* GetModuleFilter() = 0;
// Notes:
// Collect memory statistics in CrySizer
virtual void GetMemoryUsage(ICrySizer* pSizer) const = 0;
// Asset scope strings help to figure out asset dependencies in case of asset loading errors.
// Should not be used directly, only by using define CRY_DEFINE_ASSET_SCOPE
// @see CRY_DEFINE_ASSET_SCOPE
-6
View File
@@ -14,7 +14,6 @@
#include <AzCore/EBus/EBus.h>
struct IShader;
struct ISurfaceType;
struct SShaderItem;
namespace AZ
@@ -38,12 +37,7 @@ namespace AZ
struct IMaterial
{
// TODO: Remove it!
virtual ~IMaterial() {}
virtual void AddRef() = 0;
virtual void Release() = 0;
virtual SShaderItem& GetShaderItem() = 0;
virtual const SShaderItem& GetShaderItem() const = 0;
};
-47
View File
@@ -6,9 +6,6 @@
*
*/
#ifndef CRYINCLUDE_CRYCOMMON_IMOVIESYSTEM_H
#define CRYINCLUDE_CRYCOMMON_IMOVIESYSTEM_H
#pragma once
#include <AzCore/Component/ComponentBus.h>
@@ -255,8 +252,6 @@ struct SAnimContext
// TODO: Mask should be stored with dynamic length
uint32 trackMask; //!< To update certain types of tracks only
float startTime; //!< The start time of this playing sequence
void Serialize(XmlNodeRef& xmlNode, bool loading);
};
/** Parameters for cut-scene cameras
@@ -891,7 +886,6 @@ struct ITrackEventListener
// event - Track event added
// pUserData - Data to accompany reason
virtual void OnTrackEvent(IAnimSequence* sequence, int reason, const char* event, void* pUserData) = 0;
virtual void GetMemoryUsage([[maybe_unused]] ICrySizer* pSizer) const{};
// </interfuscator:shuffle>
};
@@ -1152,8 +1146,6 @@ struct IMovieListener
//! callback on movie events
virtual void OnMovieEvent(EMovieEvent movieEvent, IAnimSequence* pAnimSequence) = 0;
// </interfuscator:shuffle>
void GetMemoryUsage([[maybe_unused]] ICrySizer* pSizer) const{}
};
/** Movie System interface.
@@ -1326,7 +1318,6 @@ struct IMovieSystem
virtual bool IsRecording() const = 0;
virtual void EnableCameraShake(bool bEnabled) = 0;
virtual bool IsCameraShakeEnabled() const = 0;
// Pause any playing sequences.
virtual void Pause() = 0;
@@ -1381,8 +1372,6 @@ struct IMovieSystem
virtual void EnableBatchRenderMode(bool bOn) = 0;
virtual bool IsInBatchRenderMode() const = 0;
virtual ILightAnimWrapper* CreateLightAnimWrapper(const char* name) const = 0;
virtual void LoadParamTypeFromXml(CAnimParamType& animParamType, const XmlNodeRef& xmlNode, const uint version) = 0;
virtual void SaveParamTypeToXml(const CAnimParamType& animParamType, XmlNodeRef& xmlNode) = 0;
@@ -1408,40 +1397,6 @@ struct IMovieSystem
// </interfuscator:shuffle>
};
inline void SAnimContext::Serialize(XmlNodeRef& xmlNode, bool bLoading)
{
if (bLoading)
{
XmlString name;
if (xmlNode->getAttr("sequence", name))
{
sequence = gEnv->pMovieSystem->FindLegacySequenceByName(name.c_str());
}
xmlNode->getAttr("dt", dt);
xmlNode->getAttr("fps", fps);
xmlNode->getAttr("time", time);
xmlNode->getAttr("bSingleFrame", singleFrame);
xmlNode->getAttr("bResetting", resetting);
xmlNode->getAttr("trackMask", trackMask);
xmlNode->getAttr("startTime", startTime);
}
else
{
if (sequence)
{
AZStd::string fullname = sequence->GetName();
xmlNode->setAttr("sequence", fullname.c_str());
}
xmlNode->setAttr("dt", dt);
xmlNode->setAttr("fps", fps);
xmlNode->setAttr("time", time);
xmlNode->setAttr("bSingleFrame", singleFrame);
xmlNode->setAttr("bResetting", resetting);
xmlNode->setAttr("trackMask", trackMask);
xmlNode->setAttr("startTime", startTime);
}
}
inline void CAnimParamType::SaveToXml(XmlNodeRef& xmlNode) const
{
gEnv->pMovieSystem->SaveParamTypeToXml(*this, xmlNode);
@@ -1456,5 +1411,3 @@ inline void CAnimParamType::Serialize(XmlNodeRef& xmlNode, bool bLoading, const
{
gEnv->pMovieSystem->SerializeParamType(*this, xmlNode, bLoading, version);
}
#endif // CRYINCLUDE_CRYCOMMON_IMOVIESYSTEM_H

Some files were not shown because too many files have changed in this diff Show More