Merge branch 'main' into non-uniform-scale-manipulators
This commit is contained in:
@@ -145,6 +145,7 @@ struct STextDrawContext
|
||||
Vec2 m_size;
|
||||
Vec2i m_requestSize;
|
||||
float m_widthScale;
|
||||
float m_lineSpacing;
|
||||
|
||||
float m_clipX;
|
||||
float m_clipY;
|
||||
@@ -175,6 +176,7 @@ struct STextDrawContext
|
||||
, m_size(16.0f, 16.0f)
|
||||
, m_requestSize(static_cast<int32>(m_size.x), static_cast<int32>(m_size.y))
|
||||
, m_widthScale(1.0f)
|
||||
, m_lineSpacing(0.f)
|
||||
, m_clipX(0)
|
||||
, m_clipY(0)
|
||||
, m_clipWidth(0)
|
||||
@@ -209,11 +211,13 @@ struct STextDrawContext
|
||||
void SetTransform(const Matrix34& transform) { m_transform = transform; }
|
||||
void SetBaseState(int baseState) { m_baseState = baseState; }
|
||||
void SetOverrideViewProjMatrices(bool overrideViewProjMatrices) { m_overrideViewProjMatrices = overrideViewProjMatrices; }
|
||||
void SetLineSpacing(float lineSpacing) { m_lineSpacing = lineSpacing; }
|
||||
|
||||
float GetCharWidth() const { return m_size.x; }
|
||||
float GetCharHeight() const { return m_size.y; }
|
||||
float GetCharWidthScale() const { return m_widthScale; }
|
||||
int GetFlags() const { return m_drawTextFlags; }
|
||||
float GetLineSpacing() const { return m_lineSpacing; }
|
||||
|
||||
bool IsColorOverridden() const { return m_colorOverride.a != 0; }
|
||||
};
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
// Description : Provides the interface for the lz4 hc decompress wrapper
|
||||
|
||||
#ifndef CRYINCLUDE_CRYCOMMON_ILZ4DECOMPRESSOR_H
|
||||
#define CRYINCLUDE_CRYCOMMON_ILZ4DECOMPRESSOR_H
|
||||
#pragma once
|
||||
|
||||
|
||||
struct ILZ4Decompressor
|
||||
{
|
||||
protected:
|
||||
virtual ~ILZ4Decompressor() {}; // use Release()
|
||||
|
||||
public:
|
||||
virtual bool DecompressData(const char* pIn, char* pOut, const uint outputSize) const = 0;
|
||||
|
||||
virtual void Release() = 0;
|
||||
};
|
||||
|
||||
#endif // CRYINCLUDE_CRYCOMMON_ILZ4DECOMPRESSOR_H
|
||||
@@ -76,14 +76,9 @@ struct IViewSystem;
|
||||
class ICrySizer;
|
||||
class IXMLBinarySerializer;
|
||||
struct IReadWriteXMLSink;
|
||||
struct ITextModeConsole;
|
||||
struct IAVI_Reader;
|
||||
class CPNoise3;
|
||||
struct ILocalizationManager;
|
||||
struct IZLibCompressor;
|
||||
struct IZLibDecompressor;
|
||||
struct ILZ4Decompressor;
|
||||
class IZStdDecompressor;
|
||||
struct IOutputPrintSink;
|
||||
struct IWindowMessageHandler;
|
||||
|
||||
@@ -524,7 +519,6 @@ struct SSystemInitParams
|
||||
ISystemUserCallback* pUserCallback;
|
||||
const char* sLogFileName; // File name to use for log.
|
||||
bool autoBackupLogs; // if true, logs will be automatically backed up each startup
|
||||
IValidator* pValidator; // You can specify different validator object to use by System.
|
||||
IOutputPrintSink* pPrintSync; // Print Sync which can be used to catch all output from engine
|
||||
char szSystemCmdLine[2048]; // Command line.
|
||||
|
||||
@@ -554,7 +548,6 @@ struct SSystemInitParams
|
||||
pUserCallback = NULL;
|
||||
sLogFileName = NULL;
|
||||
autoBackupLogs = true;
|
||||
pValidator = NULL;
|
||||
pPrintSync = NULL;
|
||||
memset(szSystemCmdLine, 0, sizeof(szSystemCmdLine));
|
||||
|
||||
@@ -828,14 +821,6 @@ struct ISystem
|
||||
// Retrieve the name of the user currently logged in to the computer.
|
||||
virtual const char* GetUserName() = 0;
|
||||
|
||||
// Summary:
|
||||
// Gets current supported CPU features flags. (CPUF_SSE, CPUF_SSE2, CPUF_3DNOW, CPUF_MMX)
|
||||
virtual int GetCPUFlags() = 0;
|
||||
|
||||
// Summary:
|
||||
// Gets number of CPUs
|
||||
virtual int GetLogicalCPUCount() = 0;
|
||||
|
||||
// Summary:
|
||||
// Quits the application.
|
||||
virtual void Quit() = 0;
|
||||
@@ -852,13 +837,6 @@ struct ISystem
|
||||
|
||||
virtual bool IsRelaunch() const = 0;
|
||||
|
||||
// Summary:
|
||||
// Displays an error message to display info for certain time
|
||||
// Arguments:
|
||||
// acMessage - Message to show
|
||||
// fTime - Amount of seconds to show onscreen
|
||||
virtual void DisplayErrorMessage(const char* acMessage, float fTime, const float* pfColor = 0, bool bHardError = true) = 0;
|
||||
|
||||
// Description:
|
||||
// Displays error message.
|
||||
// Logs it to console and file and error message box then terminates execution.
|
||||
@@ -889,14 +867,9 @@ struct ISystem
|
||||
// return the related subsystem interface
|
||||
|
||||
//
|
||||
virtual IZLibCompressor* GetIZLibCompressor() = 0;
|
||||
virtual IZLibDecompressor* GetIZLibDecompressor() = 0;
|
||||
virtual ILZ4Decompressor* GetLZ4Decompressor() = 0;
|
||||
virtual IZStdDecompressor* GetZStdDecompressor() = 0;
|
||||
virtual IViewSystem* GetIViewSystem() = 0;
|
||||
virtual ILevelSystem* GetILevelSystem() = 0;
|
||||
virtual INameTable* GetINameTable() = 0;
|
||||
virtual IValidator* GetIValidator() = 0;
|
||||
virtual ICmdLine* GetICmdLine() = 0;
|
||||
virtual ILog* GetILog() = 0;
|
||||
virtual AZ::IO::IArchive* GetIPak() = 0;
|
||||
@@ -917,7 +890,6 @@ struct ISystem
|
||||
virtual bool GetForceNonDevMode() const = 0;
|
||||
virtual bool WasInDevMode() const = 0;
|
||||
virtual bool IsDevMode() const = 0;
|
||||
virtual bool IsMODValid(const char* szMODName) const = 0;
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
@@ -974,13 +946,6 @@ struct ISystem
|
||||
// Gets build version.
|
||||
virtual const SFileVersion& GetBuildVersion() = 0;
|
||||
|
||||
// Summary:
|
||||
// Data compression
|
||||
//##@{
|
||||
virtual bool CompressDataBlock(const void* input, size_t inputSize, void* output, size_t& outputSize, int level = 3) = 0;
|
||||
virtual bool DecompressDataBlock(const void* input, size_t inputSize, void* output, size_t& outputSize) = 0;
|
||||
//##@}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Configuration.
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
@@ -1002,21 +967,8 @@ struct ISystem
|
||||
// pCallback - 0 means normal LoadConfigVar behaviour is used
|
||||
virtual void LoadConfiguration(const char* sFilename, ILoadConfigurationEntrySink* pSink = 0, bool warnIfMissing = true) = 0;
|
||||
|
||||
// Summary:
|
||||
// Retrieves current configuration specification for client or server.
|
||||
// Arguments:
|
||||
// bClient - If true returns local client config spec, if false returns server config spec.
|
||||
virtual ESystemConfigSpec GetConfigSpec(bool bClient = true) = 0;
|
||||
|
||||
virtual ESystemConfigSpec GetMaxConfigSpec() const = 0;
|
||||
|
||||
// Summary:
|
||||
// Changes current configuration specification for client or server.
|
||||
// Arguments:
|
||||
// bClient - If true changes client config spec (sys_spec variable changed),
|
||||
// if false changes only server config spec (as known on the client).
|
||||
virtual void SetConfigSpec(ESystemConfigSpec spec, ESystemConfigPlatform platform, bool bClient) = 0;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Summary:
|
||||
@@ -1028,10 +980,6 @@ struct ISystem
|
||||
virtual void SetConfigPlatform(ESystemConfigPlatform platform) = 0;
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Summary:
|
||||
// Detects and set optimal spec.
|
||||
virtual void AutoDetectSpec(bool detectResolution) = 0;
|
||||
|
||||
// Summary:
|
||||
// Query if system is now paused.
|
||||
// Pause flag is set when calling system update with pause mode.
|
||||
@@ -1041,8 +989,6 @@ struct ISystem
|
||||
// Retrieves localized strings manager interface.
|
||||
virtual ILocalizationManager* GetLocalizationManager() = 0;
|
||||
|
||||
virtual ITextModeConsole* GetITextModeConsole() = 0;
|
||||
|
||||
// Summary:
|
||||
// Retrieves the perlin noise singleton instance.
|
||||
virtual CPNoise3* GetNoiseGen() = 0;
|
||||
@@ -1133,22 +1079,10 @@ struct ISystem
|
||||
virtual ESystemGlobalState GetSystemGlobalState(void) = 0;
|
||||
virtual void SetSystemGlobalState(ESystemGlobalState systemGlobalState) = 0;
|
||||
|
||||
// Summary:
|
||||
// Asynchronous memcpy
|
||||
// Note sync variable will be incremented (in calling thread) before job starts
|
||||
// and decremented when job finishes. Multiple async copies can therefore be
|
||||
// tied to the same sync variable, therefore it's advised to wait for completion with
|
||||
// while(*sync) (yield());
|
||||
virtual void AsyncMemcpy(void* dst, const void* src, size_t size, int nFlags, volatile int* sync) = 0;
|
||||
// </interfuscator:shuffle>
|
||||
|
||||
#if !defined(_RELEASE)
|
||||
virtual bool IsSavingResourceList() const = 0;
|
||||
#endif
|
||||
|
||||
// Initializes Steam if needed and returns if it was successful
|
||||
virtual bool SteamInit() = 0;
|
||||
|
||||
// Summary:
|
||||
// Gets the root window message handler function
|
||||
// The returned pointer is platform-specific:
|
||||
@@ -1752,44 +1686,6 @@ inline void CryLogAlways(const char* format, ...)
|
||||
|
||||
#endif // EXCLUDE_NORMAL_LOG
|
||||
|
||||
/*****************************************************
|
||||
ASYNC MEMCPY FUNCTIONS
|
||||
*****************************************************/
|
||||
|
||||
// Complex delegation required because it is not really easy to
|
||||
// export a external standalone symbol like a memcpy function when
|
||||
// building with modules. Dll pay an extra indirection cost for calling this
|
||||
// function.
|
||||
#if !defined(AZ_MONOLITHIC_BUILD)
|
||||
# define CRY_ASYNC_MEMCPY_DELEGATE_TO_CRYSYSTEM
|
||||
#endif
|
||||
#define CRY_ASYNC_MEMCPY_API extern "C"
|
||||
|
||||
// Note sync variable will be incremented (in calling thread) before job starts
|
||||
// and decremented when job finishes. Multiple async copies can therefore be
|
||||
// tied to the same sync variable, therefore wait for completion with
|
||||
// while(*sync) (yield());
|
||||
#if defined(CRY_ASYNC_MEMCPY_DELEGATE_TO_CRYSYSTEM)
|
||||
inline void cryAsyncMemcpy(
|
||||
void* dst
|
||||
, const void* src
|
||||
, size_t size
|
||||
, int nFlags
|
||||
, volatile int* sync)
|
||||
{
|
||||
GetISystem()->AsyncMemcpy(dst, src, size, nFlags, sync);
|
||||
}
|
||||
# else
|
||||
CRY_ASYNC_MEMCPY_API void cryAsyncMemcpy(
|
||||
void* dst
|
||||
, const void* src
|
||||
, size_t size
|
||||
, int nFlags
|
||||
, volatile int* sync);
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Additional headers.
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
// Description : Allows creation of text mode displays the for dedicated server
|
||||
|
||||
|
||||
#ifndef CRYINCLUDE_CRYCOMMON_ITEXTMODECONSOLE_H
|
||||
#define CRYINCLUDE_CRYCOMMON_ITEXTMODECONSOLE_H
|
||||
#pragma once
|
||||
|
||||
|
||||
struct ITextModeConsole
|
||||
{
|
||||
// <interfuscator:shuffle>
|
||||
virtual ~ITextModeConsole() {}
|
||||
virtual Vec2_tpl<int> BeginDraw() = 0;
|
||||
virtual void PutText(int x, int y, const char* msg) = 0;
|
||||
virtual void EndDraw() = 0;
|
||||
virtual void OnShutdown() = 0;
|
||||
|
||||
virtual void SetTitle([[maybe_unused]] const char* title) {}
|
||||
// </interfuscator:shuffle>
|
||||
};
|
||||
|
||||
#endif // CRYINCLUDE_CRYCOMMON_ITEXTMODECONSOLE_H
|
||||
@@ -1,219 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
#ifndef CRYINCLUDE_CRYCOMMON_IZLIBCOMPRESSOR_H
|
||||
#define CRYINCLUDE_CRYCOMMON_IZLIBCOMPRESSOR_H
|
||||
#pragma once
|
||||
|
||||
|
||||
/*
|
||||
wrapper interface for the zlib compression / deflate interface
|
||||
|
||||
supports multiple compression streams with an async compatible wrapper
|
||||
|
||||
Gotchas:
|
||||
the ptr to the input data must remain valid whilst the stream is deflating
|
||||
the ptr to the output buffer must remain valid whilst the stream is deflating
|
||||
|
||||
****************************************************************************************
|
||||
|
||||
usage example:
|
||||
|
||||
IZLibCompressor *pComp=GetISystem()->GetIZLibCompressor();
|
||||
// see deflateInit2() documentation zlib manual for more info on the parameters here
|
||||
// this initializes the stream to produce a gzip format block with fairly low memory requirements
|
||||
IZLibDeflateStream *pStream=pComp->CreateDeflateStream(2,eZMeth_Deflated,24,3,eZStrat_Default,eZFlush_NoFlush);
|
||||
char *pOutput=new char[512]; // arbitrary size
|
||||
const char *pInputData="This is an example piece of data that is to be compressed. It can be any arbitrary block of binary data - not just text";
|
||||
const int inputBlockSize=16; // to simulate streaming of input, this example provides the input in 16 byte blocks
|
||||
int totalInput=sizeof(pInputData);
|
||||
int bytesInput=0;
|
||||
bool done=false;
|
||||
FILE *outputFile=fopen("myfile.gz","rb");
|
||||
|
||||
do
|
||||
{
|
||||
EZDeflateState state=pStream->GetState();
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case eZDefState_AwaitingInput:
|
||||
// 'stream' input data, there is no restriction on the block size you can input, if all the data is available immediately, input all of it at once
|
||||
{
|
||||
int inputSize=min(inputBlockSize,totalInput-bytesInput);
|
||||
|
||||
if (inputSize<=0)
|
||||
{
|
||||
pStream->EndInput();
|
||||
}
|
||||
else
|
||||
{
|
||||
pStream->Input(pInputData+bytesInput,inputSize);
|
||||
bytesInput+=inputSize;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case eZDefState_Deflating:
|
||||
// do something more interesting... like getting out of this loop and running the rest of your game...
|
||||
break;
|
||||
|
||||
case eZDefState_ConsumeOutput:
|
||||
// stream output to a file
|
||||
{
|
||||
int bytesToOutput=pStream->GetBytesOutput();
|
||||
|
||||
if (bytesToOutput>0)
|
||||
{
|
||||
fwrite(pOutput,1,bytesToOutput,outputFile);
|
||||
}
|
||||
|
||||
pStream->SetOutputBuffer(pOutput,sizeof(pOutput));
|
||||
}
|
||||
break;
|
||||
|
||||
case eZDefState_Finished:
|
||||
case ezDefState_Error:
|
||||
done=true;
|
||||
break;
|
||||
}
|
||||
|
||||
} while (!done);
|
||||
|
||||
fclose(outputFile);
|
||||
|
||||
pStream->Release();
|
||||
delete [] pOutput;
|
||||
|
||||
****************************************************************************************/
|
||||
|
||||
// don't change the order of these zlib wrapping enum values without updating the mapping
|
||||
// implementation in CZLibCompressorStream
|
||||
enum EZLibStrategy
|
||||
{
|
||||
eZStrat_Default, // Z_DEFAULT_STRATEGY
|
||||
eZStrat_Filtered, // Z_FILTERED
|
||||
eZStrat_HuffmanOnly, // Z_HUFFMAN_ONLY
|
||||
eZStrat_RLE // Z_RLE
|
||||
};
|
||||
enum EZLibMethod
|
||||
{
|
||||
eZMeth_Deflated // Z_DEFLATED
|
||||
};
|
||||
enum EZLibFlush
|
||||
{
|
||||
eZFlush_NoFlush, // Z_NO_FLUSH
|
||||
eZFlush_PartialFlush, // Z_PARTIAL_FLUSH
|
||||
eZFlush_SyncFlush, // Z_SYNC_FLUSH
|
||||
eZFlush_FullFlush, // Z_FULL_FLUSH
|
||||
};
|
||||
|
||||
enum EZDeflateState
|
||||
{
|
||||
eZDefState_AwaitingInput, // caller must call Input() or Finish() to continue
|
||||
eZDefState_Deflating, // caller must wait
|
||||
eZDefState_ConsumeOutput, // caller must consume output and then call SetOutputBuffer() to continue
|
||||
eZDefState_Finished, // stream finished, caller must call Release() to destroy stream
|
||||
eZDefState_Error // error has occurred and the stream has been closed and will no longer compress
|
||||
};
|
||||
|
||||
struct IZLibDeflateStream
|
||||
{
|
||||
protected:
|
||||
virtual ~IZLibDeflateStream() {}; // use Release()
|
||||
|
||||
public:
|
||||
struct SStats
|
||||
{
|
||||
int bytesInput;
|
||||
int bytesOutput;
|
||||
int curMemoryUsed;
|
||||
int peakMemoryUsed;
|
||||
};
|
||||
|
||||
// <interfuscator:shuffle>
|
||||
// Description:
|
||||
// Specifies the output buffer for the deflate operation
|
||||
// Should be set before providing input
|
||||
// The specified buffer must remain valid (ie do not free) whilst compression is in progress (state == eZDefState_Deflating)
|
||||
virtual void SetOutputBuffer(char* pInBuffer, int inSize) = 0;
|
||||
|
||||
// Description:
|
||||
// Returns the number of bytes from the output buffer that are ready to be consumed. After consuming any output, you should call SetOutputBuffer() again to mark the buffer as available
|
||||
virtual int GetBytesOutput() = 0;
|
||||
|
||||
// Description:
|
||||
// Begins compressing the source data pInSource of length inSourceSize to a previously specified output buffer
|
||||
// Only valid to be called if the stream is in state eZDefState_AwaitingInput
|
||||
// The specified buffer must remain valid (ie do not free) whilst compression is in progress (state == eZDefState_Deflating)
|
||||
virtual void Input(const char* pInSource, int inSourceSize) = 0;
|
||||
|
||||
// Description:
|
||||
// Finishes the compression, causing all data to be flushed to the output buffer
|
||||
// Once called no more data can be input
|
||||
// After calling the caller must wait until GetState() reutrns eZDefState_Finished
|
||||
virtual void EndInput() = 0;
|
||||
|
||||
// Description:
|
||||
// Returns the state of the stream,
|
||||
virtual EZDeflateState GetState() = 0;
|
||||
|
||||
// Description:
|
||||
// Gets stats on deflate stream, valid to call at anytime
|
||||
virtual void GetStats(SStats* pOutStats) = 0;
|
||||
|
||||
// Description:
|
||||
// Deletes the deflate stream. Will assert if stream is in an invalid state to be released (in state eZDefState_Deflating)
|
||||
virtual void Release() = 0;
|
||||
// </interfuscator:shuffle>
|
||||
};
|
||||
|
||||
// md5 support structure
|
||||
struct SMD5Context
|
||||
{
|
||||
uint32 buf[4];
|
||||
uint32 bits[2];
|
||||
unsigned char in[64];
|
||||
};
|
||||
|
||||
struct IZLibCompressor
|
||||
{
|
||||
protected:
|
||||
virtual ~IZLibCompressor() {}; // use Release()
|
||||
|
||||
public:
|
||||
// <interfuscator:shuffle>
|
||||
// Description:
|
||||
// Creates a deflate stream to compress data using zlib
|
||||
// See documentation for zlib deflateInit2() for usage details
|
||||
// inFlushMethod is passed to calls to zlib deflate(), see zlib docs on deflate() for more details
|
||||
virtual IZLibDeflateStream* CreateDeflateStream(int inLevel, EZLibMethod inMethod, int inWindowBits, int inMemLevel, EZLibStrategy inStrategy, EZLibFlush inFlushMethod) = 0;
|
||||
|
||||
virtual void Release() = 0;
|
||||
|
||||
// Description:
|
||||
// Initializes an MD5 context
|
||||
virtual void MD5Init(SMD5Context* pIOCtx) = 0;
|
||||
|
||||
// Description:
|
||||
// Digests some data into an existing MD5 context
|
||||
virtual void MD5Update(SMD5Context* pIOCtx, const char* pInBuff, unsigned int len) = 0;
|
||||
|
||||
// Description:
|
||||
// Closes the MD5 context and extract the final 16 byte MD5 digest value
|
||||
virtual void MD5Final(SMD5Context * pIOCtx, char outDigest[16]) = 0;
|
||||
// </interfuscator:shuffle>
|
||||
};
|
||||
|
||||
#endif // CRYINCLUDE_CRYCOMMON_IZLIBCOMPRESSOR_H
|
||||
|
||||
@@ -1,94 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
// Description : Provides the interface for the zlib inflate wrapper
|
||||
|
||||
|
||||
#ifndef CRYINCLUDE_CRYCOMMON_IZLIBDECOMPRESSOR_H
|
||||
#define CRYINCLUDE_CRYCOMMON_IZLIBDECOMPRESSOR_H
|
||||
#pragma once
|
||||
|
||||
|
||||
enum EZInflateState
|
||||
{
|
||||
eZInfState_AwaitingInput, // caller must call Input() to continue
|
||||
eZInfState_Inflating, // caller must wait
|
||||
eZInfState_ConsumeOutput, // caller must consume output and then call SetOutputBuffer() to continue
|
||||
eZInfState_Finished, // caller must call Release()
|
||||
eZInfState_Error // error has occurred and the stream has been closed and will no longer compress
|
||||
};
|
||||
|
||||
struct IZLibInflateStream
|
||||
{
|
||||
protected:
|
||||
virtual ~IZLibInflateStream() {}; // use Release()
|
||||
|
||||
public:
|
||||
struct SStats
|
||||
{
|
||||
int bytesInput;
|
||||
int bytesOutput;
|
||||
int curMemoryUsed;
|
||||
int peakMemoryUsed;
|
||||
};
|
||||
|
||||
// Description:
|
||||
// Specifies the output buffer for the inflate operation
|
||||
// Should be set before providing input
|
||||
// The specified buffer must remain valid (ie do not free) whilst compression is in progress (state == eZInfState_Inflating)
|
||||
virtual void SetOutputBuffer(char* pInBuffer, unsigned int inSize) = 0;
|
||||
|
||||
// Description:
|
||||
// Returns the number of bytes from the output buffer that are ready to be consumed. After consuming any output, you should call SetOutputBuffer() again to mark the buffer as available
|
||||
virtual unsigned int GetBytesOutput() = 0;
|
||||
|
||||
// Description:
|
||||
// Begins decompressing the source data pInSource of length inSourceSize to a previously specified output buffer
|
||||
// Only valid to be called if the stream is in state eZInfState_AwaitingInput
|
||||
// The specified buffer must remain valid (ie do not free) whilst compression is in progress (state == eZInfState_Inflating)
|
||||
virtual void Input(const char* pInSource, unsigned int inSourceSize) = 0;
|
||||
|
||||
// Description:
|
||||
// Finishes the compression, causing all data to be flushed to the output buffer
|
||||
// Once called no more data can be input
|
||||
// After calling the caller must wait until GetState() reuturns eZInfState_Finished
|
||||
virtual void EndInput() = 0;
|
||||
|
||||
// Description:
|
||||
// Returns the state of the stream,
|
||||
virtual EZInflateState GetState() = 0;
|
||||
|
||||
// Description:
|
||||
// Gets stats on inflate stream, valid to call at anytime
|
||||
virtual void GetStats(SStats* pOutStats) = 0;
|
||||
|
||||
// Description:
|
||||
// Deletes the inflate stream. Will assert if stream is in an invalid state to be released (in state eZInfState_Inflating)
|
||||
virtual void Release() = 0;
|
||||
};
|
||||
|
||||
struct IZLibDecompressor
|
||||
{
|
||||
protected:
|
||||
virtual ~IZLibDecompressor() {}; // use Release()
|
||||
|
||||
public:
|
||||
// Description:
|
||||
// Creates a inflate stream to decompress data using zlib
|
||||
virtual IZLibInflateStream* CreateInflateStream() = 0;
|
||||
|
||||
virtual void Release() = 0;
|
||||
};
|
||||
|
||||
#endif // CRYINCLUDE_CRYCOMMON_IZLIBDECOMPRESSOR_H
|
||||
|
||||
@@ -39,10 +39,6 @@ public:
|
||||
void());
|
||||
MOCK_METHOD0(GetUserName,
|
||||
const char*());
|
||||
MOCK_METHOD0(GetCPUFlags,
|
||||
int());
|
||||
MOCK_METHOD0(GetLogicalCPUCount,
|
||||
int());
|
||||
MOCK_METHOD0(Quit,
|
||||
void());
|
||||
MOCK_METHOD1(Relaunch,
|
||||
@@ -55,8 +51,6 @@ public:
|
||||
int());
|
||||
MOCK_CONST_METHOD0(IsRelaunch,
|
||||
bool());
|
||||
MOCK_METHOD4(DisplayErrorMessage,
|
||||
void(const char*, float, const float*, bool));
|
||||
|
||||
void FatalError([[maybe_unused]] const char* sFormat, ...) override {}
|
||||
void ReportBug([[maybe_unused]] const char* sFormat, ...) override {}
|
||||
@@ -70,22 +64,12 @@ public:
|
||||
int(const char* text, const char* caption, unsigned int uType));
|
||||
MOCK_METHOD1(CheckLogVerbosity,
|
||||
bool(int verbosity));
|
||||
MOCK_METHOD0(GetIZLibCompressor,
|
||||
IZLibCompressor * ());
|
||||
MOCK_METHOD0(GetIZLibDecompressor,
|
||||
IZLibDecompressor * ());
|
||||
MOCK_METHOD0(GetLZ4Decompressor,
|
||||
ILZ4Decompressor * ());
|
||||
MOCK_METHOD0(GetZStdDecompressor,
|
||||
IZStdDecompressor * ());
|
||||
MOCK_METHOD0(GetIViewSystem,
|
||||
IViewSystem * ());
|
||||
MOCK_METHOD0(GetILevelSystem,
|
||||
ILevelSystem * ());
|
||||
MOCK_METHOD0(GetINameTable,
|
||||
INameTable * ());
|
||||
MOCK_METHOD0(GetIValidator,
|
||||
IValidator * ());
|
||||
MOCK_METHOD0(GetICmdLine,
|
||||
ICmdLine * ());
|
||||
MOCK_METHOD0(GetILog,
|
||||
@@ -116,8 +100,6 @@ public:
|
||||
bool());
|
||||
MOCK_CONST_METHOD0(IsDevMode,
|
||||
bool());
|
||||
MOCK_CONST_METHOD1(IsMODValid,
|
||||
bool(const char* szMODName));
|
||||
MOCK_METHOD3(CreateXmlNode,
|
||||
XmlNodeRef(const char*, bool, bool));
|
||||
MOCK_METHOD4(LoadXmlFromBuffer,
|
||||
@@ -147,11 +129,6 @@ public:
|
||||
MOCK_METHOD0(GetBuildVersion,
|
||||
const SFileVersion&());
|
||||
|
||||
MOCK_METHOD5(CompressDataBlock,
|
||||
bool(const void*, size_t, void*, size_t &, int));
|
||||
|
||||
MOCK_METHOD4(DecompressDataBlock,
|
||||
bool(const void* input, size_t inputSize, void* output, size_t & outputSize));
|
||||
MOCK_METHOD1(AddCVarGroupDirectory,
|
||||
void(const string&));
|
||||
MOCK_METHOD0(SaveConfiguration,
|
||||
@@ -159,24 +136,16 @@ public:
|
||||
MOCK_METHOD3(LoadConfiguration,
|
||||
void(const char*, ILoadConfigurationEntrySink*, bool));
|
||||
|
||||
MOCK_METHOD1(GetConfigSpec,
|
||||
ESystemConfigSpec(bool));
|
||||
MOCK_CONST_METHOD0(GetMaxConfigSpec,
|
||||
ESystemConfigSpec());
|
||||
MOCK_METHOD3(SetConfigSpec,
|
||||
void(ESystemConfigSpec spec, ESystemConfigPlatform platform, bool bClient));
|
||||
MOCK_CONST_METHOD0(GetConfigPlatform,
|
||||
ESystemConfigPlatform());
|
||||
MOCK_METHOD1(SetConfigPlatform,
|
||||
void(ESystemConfigPlatform platform));
|
||||
MOCK_METHOD1(AutoDetectSpec,
|
||||
void(bool detectResolution));
|
||||
MOCK_CONST_METHOD0(IsPaused,
|
||||
bool());
|
||||
MOCK_METHOD0(GetLocalizationManager,
|
||||
ILocalizationManager * ());
|
||||
MOCK_METHOD0(GetITextModeConsole,
|
||||
ITextModeConsole * ());
|
||||
MOCK_METHOD0(GetNoiseGen,
|
||||
CPNoise3 * ());
|
||||
MOCK_METHOD0(GetUpdateCounter,
|
||||
@@ -213,16 +182,12 @@ public:
|
||||
ESystemGlobalState(void));
|
||||
MOCK_METHOD1(SetSystemGlobalState,
|
||||
void(ESystemGlobalState systemGlobalState));
|
||||
MOCK_METHOD5(AsyncMemcpy,
|
||||
void(void* dst, const void* src, size_t size, int nFlags, volatile int* sync));
|
||||
|
||||
#if !defined(_RELEASE)
|
||||
MOCK_CONST_METHOD0(IsSavingResourceList,
|
||||
bool());
|
||||
#endif
|
||||
|
||||
MOCK_METHOD0(SteamInit,
|
||||
bool());
|
||||
MOCK_METHOD0(GetRootWindowMessageHandler,
|
||||
void*());
|
||||
MOCK_METHOD1(RegisterWindowMessageHandler,
|
||||
|
||||
@@ -40,8 +40,6 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define USE_STEAM 0 // Enable this to start using Steam
|
||||
|
||||
// The following definitions are used by Sandbox and RC to determine which platform support is needed
|
||||
#define TOOLS_SUPPORT_POWERVR
|
||||
#define TOOLS_SUPPORT_ETC2COMP
|
||||
|
||||
@@ -33,14 +33,6 @@ namespace AZ
|
||||
static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Multiple;
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* This event gets posted at the end of CD3D9Renderer's EF_Scene3D method.
|
||||
* CSystem (in SystemRenderer.cpp) uses this to render the console, aux geom and UI
|
||||
* in a manner that will make sure the render calls end up as part of the scene's render.
|
||||
* This is important or else those render calls won't show up properly in VR.
|
||||
*/
|
||||
virtual void OnScene3DEnd() {};
|
||||
|
||||
/**
|
||||
* This event gets posted at the beginning of CD3D9Renderer's FreeResources method, before the resources have been freed.
|
||||
*/
|
||||
|
||||
@@ -34,7 +34,6 @@ set(FILES
|
||||
LocalizationManagerBus.h
|
||||
LocalizationManagerBus.inl
|
||||
ILog.h
|
||||
ILZ4Decompressor.h
|
||||
IMaterial.h
|
||||
IMeshBaking.h
|
||||
IMiniLog.h
|
||||
@@ -56,7 +55,6 @@ set(FILES
|
||||
IStereoRenderer.h
|
||||
ISurfaceType.h
|
||||
ISystem.h
|
||||
ITextModeConsole.h
|
||||
ITexture.h
|
||||
ITimer.h
|
||||
IValidator.h
|
||||
@@ -64,9 +62,6 @@ set(FILES
|
||||
IViewSystem.h
|
||||
IWindowMessageHandler.h
|
||||
IXml.h
|
||||
IZLibCompressor.h
|
||||
IZlibDecompressor.h
|
||||
IZStdDecompressor.h
|
||||
IProximityTriggerSystem.h
|
||||
MicrophoneBus.h
|
||||
physinterface.h
|
||||
|
||||
@@ -1,94 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
// Description : Console implementation for Android, reports back to the main interface.
|
||||
|
||||
|
||||
#include "CrySystem_precompiled.h"
|
||||
#if defined(ANDROID)
|
||||
#include "AndroidConsole.h"
|
||||
|
||||
#include "android/log.h"
|
||||
CAndroidConsole::CAndroidConsole()
|
||||
: m_isInitialized(false)
|
||||
{
|
||||
}
|
||||
|
||||
CAndroidConsole::~CAndroidConsole()
|
||||
{
|
||||
}
|
||||
|
||||
// Interface IOutputPrintSink /////////////////////////////////////////////
|
||||
void CAndroidConsole::Print(const char* line)
|
||||
{
|
||||
__android_log_print(ANDROID_LOG_VERBOSE, "CryEngine", "MSG: %s\n", line);
|
||||
}
|
||||
// Interface ISystemUserCallback //////////////////////////////////////////
|
||||
bool CAndroidConsole::OnError(const char* errorString)
|
||||
{
|
||||
__android_log_print(ANDROID_LOG_ERROR, "CryEngine", "ERR: %s\n", errorString);
|
||||
return true;
|
||||
}
|
||||
|
||||
void CAndroidConsole::OnInitProgress(const char* sProgressMsg)
|
||||
{
|
||||
(void) sProgressMsg;
|
||||
// Do Nothing
|
||||
}
|
||||
void CAndroidConsole::OnInit(ISystem* pSystem)
|
||||
{
|
||||
if (!m_isInitialized)
|
||||
{
|
||||
IConsole* pConsole = pSystem->GetIConsole();
|
||||
if (pConsole != 0)
|
||||
{
|
||||
pConsole->AddOutputPrintSink(this);
|
||||
}
|
||||
m_isInitialized = true;
|
||||
}
|
||||
}
|
||||
void CAndroidConsole::OnShutdown()
|
||||
{
|
||||
if (m_isInitialized)
|
||||
{
|
||||
// remove outputprintsink
|
||||
m_isInitialized = false;
|
||||
}
|
||||
}
|
||||
void CAndroidConsole::OnUpdate()
|
||||
{
|
||||
// Do Nothing
|
||||
}
|
||||
void CAndroidConsole::GetMemoryUsage(ICrySizer* pSizer)
|
||||
{
|
||||
size_t size = sizeof(*this);
|
||||
|
||||
|
||||
|
||||
pSizer->AddObject(this, size);
|
||||
}
|
||||
|
||||
// Interface ITextModeConsole /////////////////////////////////////////////
|
||||
Vec2_tpl<int> CAndroidConsole::BeginDraw()
|
||||
{
|
||||
return Vec2_tpl<int>(0, 0);
|
||||
}
|
||||
void CAndroidConsole::PutText(int x, int y, const char* msg)
|
||||
{
|
||||
__android_log_print(ANDROID_LOG_VERBOSE, "CryEngine", "PUT: %s\n", msg);
|
||||
}
|
||||
void CAndroidConsole::EndDraw()
|
||||
{
|
||||
// Do Nothing
|
||||
}
|
||||
#endif // ANDROID
|
||||
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
// Description : Console implementation for Android, reports back to the main interface.
|
||||
|
||||
|
||||
#ifndef CRYINCLUDE_CRYSYSTEM_ANDROIDCONSOLE_H
|
||||
#define CRYINCLUDE_CRYSYSTEM_ANDROIDCONSOLE_H
|
||||
#pragma once
|
||||
|
||||
|
||||
#include <IConsole.h>
|
||||
#include <ITextModeConsole.h>
|
||||
|
||||
|
||||
|
||||
class CAndroidConsole
|
||||
: public ISystemUserCallback
|
||||
, public IOutputPrintSink
|
||||
, public ITextModeConsole
|
||||
{
|
||||
CAndroidConsole(const CAndroidConsole&);
|
||||
CAndroidConsole& operator = (const CAndroidConsole&);
|
||||
|
||||
bool m_isInitialized;
|
||||
public:
|
||||
static CryCriticalSectionNonRecursive s_lock;
|
||||
public:
|
||||
CAndroidConsole();
|
||||
~CAndroidConsole();
|
||||
|
||||
// Interface IOutputPrintSink /////////////////////////////////////////////
|
||||
DLL_EXPORT virtual void Print(const char* line);
|
||||
|
||||
// Interface ISystemUserCallback //////////////////////////////////////////
|
||||
virtual bool OnError(const char* errorString);
|
||||
virtual bool OnSaveDocument() { return false; }
|
||||
virtual void OnProcessSwitch() { }
|
||||
virtual void OnInitProgress(const char* sProgressMsg);
|
||||
virtual void OnInit(ISystem*);
|
||||
virtual void OnShutdown();
|
||||
virtual void OnUpdate();
|
||||
virtual void GetMemoryUsage(ICrySizer* pSizer);
|
||||
void SetRequireDedicatedServer(bool) {}
|
||||
void SetHeader(const char*) {}
|
||||
// Interface ITextModeConsole /////////////////////////////////////////////
|
||||
virtual Vec2_tpl<int> BeginDraw();
|
||||
virtual void PutText(int x, int y, const char* msg);
|
||||
virtual void EndDraw();
|
||||
};
|
||||
|
||||
#endif // CRYINCLUDE_CRYSYSTEM_ANDROIDCONSOLE_H
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
#ifndef CRYINCLUDE_CRYSYSTEM_AUTODETECTSPEC_H
|
||||
#define CRYINCLUDE_CRYSYSTEM_AUTODETECTSPEC_H
|
||||
#pragma once
|
||||
|
||||
|
||||
|
||||
#if defined(WIN32) || defined(WIN64)
|
||||
|
||||
// exposed AutoDetectSpec() helper functions for reuse in CrySystem
|
||||
namespace Win32SysInspect
|
||||
{
|
||||
enum DXFeatureLevel
|
||||
{
|
||||
DXFL_Undefined,
|
||||
DXFL_9_1,
|
||||
DXFL_9_2,
|
||||
DXFL_9_3,
|
||||
DXFL_10_0,
|
||||
DXFL_10_1,
|
||||
DXFL_11_0
|
||||
};
|
||||
|
||||
const char* GetFeatureLevelAsString(DXFeatureLevel featureLevel);
|
||||
|
||||
void GetNumCPUCores(unsigned int& totAvailToSystem, unsigned int& totAvailToProcess);
|
||||
bool IsDX11Supported();
|
||||
bool GetGPUInfo(char* pName, size_t bufferSize, unsigned int& vendorID, unsigned int& deviceID, unsigned int& totLocalVidMem, DXFeatureLevel& featureLevel);
|
||||
int GetGPURating(unsigned int vendorId, unsigned int deviceId);
|
||||
void GetOS(SPlatformInfo::EWinVersion& ver, bool& is64Bit, char* pName, size_t bufferSize);
|
||||
bool IsVistaKB940105Required();
|
||||
|
||||
inline size_t SafeMemoryThreshold(size_t memMB)
|
||||
{
|
||||
return (memMB * 8) / 10;
|
||||
}
|
||||
}
|
||||
|
||||
#endif // #if defined(WIN32) || defined(WIN64)
|
||||
|
||||
|
||||
#endif // CRYINCLUDE_CRYSYSTEM_AUTODETECTSPEC_H
|
||||
@@ -9,46 +9,17 @@
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
#
|
||||
|
||||
ly_get_list_relative_pal_filename(pal_dir ${CMAKE_CURRENT_LIST_DIR}/Platform/${PAL_PLATFORM_NAME})
|
||||
ly_get_list_relative_pal_filename(common_dir ${CMAKE_CURRENT_LIST_DIR}/Platform/Common)
|
||||
add_subdirectory(XML)
|
||||
|
||||
# The following target is a 'C' file only library to work around an issue in cmake and VS generators that
|
||||
# will append 'std=c++17' to both C and C++ compiler flags for clang. Do not add any .cpp files to this
|
||||
# library.
|
||||
ly_add_target(
|
||||
NAME CrySystem.DLMalloc.C STATIC
|
||||
NAMESPACE Legacy
|
||||
FILES_CMAKE
|
||||
crysystem_dlmalloc_files.cmake
|
||||
INCLUDE_DIRECTORIES
|
||||
PUBLIC
|
||||
.
|
||||
PRIVATE
|
||||
${pal_dir}
|
||||
)
|
||||
|
||||
|
||||
ly_get_pal_tool_dirs(pal_tool_dirs ${CMAKE_CURRENT_LIST_DIR}/Platform)
|
||||
|
||||
ly_add_target(
|
||||
NAME CrySystem.Static STATIC
|
||||
NAMESPACE Legacy
|
||||
FILES_CMAKE
|
||||
crysystem_files.cmake
|
||||
${pal_dir}/platform_${PAL_PLATFORM_NAME_LOWERCASE}_files.cmake
|
||||
PLATFORM_INCLUDE_FILES
|
||||
${pal_dir}/platform_${PAL_PLATFORM_NAME_LOWERCASE}.cmake
|
||||
INCLUDE_DIRECTORIES
|
||||
PUBLIC
|
||||
.
|
||||
${pal_dir}
|
||||
PRIVATE
|
||||
${common_dir}
|
||||
${pal_tool_dirs}
|
||||
BUILD_DEPENDENCIES
|
||||
PUBLIC
|
||||
Legacy::CrySystem.DLMalloc.C
|
||||
PRIVATE
|
||||
3rdParty::expat
|
||||
3rdParty::lz4
|
||||
@@ -68,19 +39,11 @@ ly_add_source_properties(
|
||||
VALUES ${LY_PAL_TOOLS_DEFINES}
|
||||
)
|
||||
|
||||
ly_add_source_properties(
|
||||
SOURCES SystemCFG.cpp
|
||||
PROPERTY COMPILE_DEFINITIONS
|
||||
VALUES LY_BUILD=${LY_VERSION_BUILD_NUMBER}
|
||||
)
|
||||
|
||||
ly_add_target(
|
||||
NAME CrySystem ${PAL_TRAIT_MONOLITHIC_DRIVEN_LIBRARY_TYPE}
|
||||
NAMESPACE Legacy
|
||||
FILES_CMAKE
|
||||
crysystem_shared_files.cmake
|
||||
PLATFORM_INCLUDE_FILES
|
||||
${pal_dir}/platform_${PAL_PLATFORM_NAME_LOWERCASE}.cmake
|
||||
INCLUDE_DIRECTORIES
|
||||
PUBLIC
|
||||
.
|
||||
@@ -90,29 +53,3 @@ ly_add_target(
|
||||
AZ::AzCore
|
||||
Legacy::CryCommon
|
||||
)
|
||||
|
||||
################################################################################
|
||||
# Tests
|
||||
################################################################################
|
||||
if(PAL_TRAIT_BUILD_TESTS_SUPPORTED)
|
||||
|
||||
ly_add_target(
|
||||
NAME CrySystem.Tests ${PAL_TRAIT_TEST_TARGET_TYPE}
|
||||
NAMESPACE Legacy
|
||||
FILES_CMAKE
|
||||
crysystem_test_files.cmake
|
||||
INCLUDE_DIRECTORIES
|
||||
PRIVATE
|
||||
.
|
||||
BUILD_DEPENDENCIES
|
||||
PRIVATE
|
||||
AZ::AzTest
|
||||
Legacy::CryCommon
|
||||
Legacy::CrySystem.Static
|
||||
AZ::AzFramework
|
||||
)
|
||||
ly_add_googletest(
|
||||
NAME Legacy::CrySystem.Tests
|
||||
)
|
||||
endif()
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,180 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
#ifndef CRYINCLUDE_CRYSYSTEM_CPUDETECT_H
|
||||
#define CRYINCLUDE_CRYSYSTEM_CPUDETECT_H
|
||||
#pragma once
|
||||
|
||||
|
||||
//-------------------------------------------------------
|
||||
/// Cpu class
|
||||
//-------------------------------------------------------
|
||||
#if defined(WIN64) || defined(LINUX)
|
||||
#define MAX_CPU 96
|
||||
#else
|
||||
#define MAX_CPU 32
|
||||
#endif
|
||||
|
||||
/// Cpu Features
|
||||
#define CFI_FPUEMULATION 0x01
|
||||
#define CFI_MMX 0x02
|
||||
#define CFI_3DNOW 0x04
|
||||
#define CFI_SSE 0x08
|
||||
#define CFI_SSE2 0x10
|
||||
#define CFI_SSE3 0x20
|
||||
#define CFI_F16C 0x40
|
||||
#define CFI_SSE41 0x80
|
||||
|
||||
/// Type of Cpu Vendor.
|
||||
enum ECpuVendor
|
||||
{
|
||||
eCVendor_Unknown,
|
||||
eCVendor_Intel,
|
||||
eCVendor_Cyrix,
|
||||
eCVendor_AMD,
|
||||
eCVendor_Centaur,
|
||||
eCVendor_NexGen,
|
||||
eCVendor_UMC,
|
||||
eCVendor_M68K
|
||||
};
|
||||
|
||||
/// Type of Cpu Model.
|
||||
enum ECpuModel
|
||||
{
|
||||
eCpu_Unknown,
|
||||
|
||||
eCpu_8086,
|
||||
eCpu_80286,
|
||||
eCpu_80386,
|
||||
eCpu_80486,
|
||||
eCpu_Pentium,
|
||||
eCpu_PentiumPro,
|
||||
eCpu_Pentium2,
|
||||
eCpu_Pentium3,
|
||||
eCpu_Pentium4,
|
||||
eCpu_Pentium2Xeon,
|
||||
eCpu_Pentium3Xeon,
|
||||
eCpu_Celeron,
|
||||
eCpu_CeleronA,
|
||||
|
||||
eCpu_Am5x86,
|
||||
eCpu_AmK5,
|
||||
eCpu_AmK6,
|
||||
eCpu_AmK6_2,
|
||||
eCpu_AmK6_3,
|
||||
eCpu_AmK6_3D,
|
||||
eCpu_AmAthlon,
|
||||
eCpu_AmDuron,
|
||||
|
||||
eCpu_CyrixMediaGX,
|
||||
eCpu_Cyrix6x86,
|
||||
eCpu_CyrixGXm,
|
||||
eCpu_Cyrix6x86MX,
|
||||
|
||||
eCpu_CenWinChip,
|
||||
eCpu_CenWinChip2,
|
||||
};
|
||||
|
||||
struct SCpu
|
||||
{
|
||||
ECpuVendor meVendor;
|
||||
ECpuModel meModel;
|
||||
unsigned long mFeatures;
|
||||
bool mbSerialPresent;
|
||||
char mSerialNumber[30];
|
||||
int mFamily;
|
||||
int mModel;
|
||||
int mStepping;
|
||||
char mVendor[64];
|
||||
char mCpuType[64];
|
||||
char mFpuType[64];
|
||||
bool mbPhysical; // false for hyperthreaded
|
||||
DWORD_PTR mAffinityMask;
|
||||
|
||||
// constructor
|
||||
SCpu()
|
||||
: meVendor(eCVendor_Unknown)
|
||||
, meModel(eCpu_Unknown)
|
||||
, mFeatures(0)
|
||||
, mbSerialPresent(false)
|
||||
, mFamily(0)
|
||||
, mModel(0)
|
||||
, mStepping(0)
|
||||
, mbPhysical(true)
|
||||
, mAffinityMask(0)
|
||||
{
|
||||
memset(mSerialNumber, 0, sizeof(mSerialNumber));
|
||||
memset(mVendor, 0, sizeof(mVendor));
|
||||
memset(mCpuType, 0, sizeof(mCpuType));
|
||||
memset(mFpuType, 0, sizeof(mFpuType));
|
||||
}
|
||||
};
|
||||
|
||||
class CCpuFeatures
|
||||
{
|
||||
private:
|
||||
int m_NumLogicalProcessors;
|
||||
int m_NumSystemProcessors;
|
||||
int m_NumAvailProcessors;
|
||||
int m_NumPhysicsProcessors;
|
||||
bool m_bOS_ISSE;
|
||||
bool m_bOS_ISSE_EXCEPTIONS;
|
||||
public:
|
||||
|
||||
SCpu m_Cpu[MAX_CPU];
|
||||
|
||||
public:
|
||||
CCpuFeatures()
|
||||
{
|
||||
m_NumLogicalProcessors = 0;
|
||||
m_NumSystemProcessors = 0;
|
||||
m_NumAvailProcessors = 0;
|
||||
m_NumPhysicsProcessors = 0;
|
||||
m_bOS_ISSE = 0;
|
||||
m_bOS_ISSE_EXCEPTIONS = 0;
|
||||
ZeroMemory(m_Cpu, sizeof(m_Cpu));
|
||||
}
|
||||
|
||||
void Detect(void);
|
||||
bool hasSSE() { return (m_Cpu[0].mFeatures & CFI_SSE) != 0; }
|
||||
bool hasSSE2() { return (m_Cpu[0].mFeatures & CFI_SSE2) != 0; }
|
||||
bool hasSSE3() { return (m_Cpu[0].mFeatures & CFI_SSE3) != 0; }
|
||||
bool hasSSE41() { return (m_Cpu[0].mFeatures & CFI_SSE41) != 0; }
|
||||
bool has3DNow() { return (m_Cpu[0].mFeatures & CFI_3DNOW) != 0; }
|
||||
bool hasMMX() { return (m_Cpu[0].mFeatures & CFI_MMX) != 0; }
|
||||
bool hasF16C() { return (m_Cpu[0].mFeatures & CFI_F16C) != 0; }
|
||||
|
||||
unsigned int GetLogicalCPUCount() { return m_NumLogicalProcessors; }
|
||||
unsigned int GetPhysCPUCount() { return m_NumPhysicsProcessors; }
|
||||
unsigned int GetCPUCount() { return m_NumAvailProcessors; }
|
||||
DWORD_PTR GetCPUAffinityMask(unsigned int iCPU) { assert(iCPU < MAX_CPU); return iCPU < GetCPUCount() ? m_Cpu[iCPU].mAffinityMask : 0; }
|
||||
DWORD_PTR GetPhysCPUAffinityMask(unsigned int iCPU)
|
||||
{
|
||||
if (iCPU > GetPhysCPUCount())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
int i;
|
||||
for (i = 0; (int)iCPU >= 0; i++)
|
||||
{
|
||||
if (m_Cpu[i].mbPhysical)
|
||||
{
|
||||
--iCPU;
|
||||
}
|
||||
}
|
||||
PREFAST_ASSUME(i > 0 && i < MAX_CPU);
|
||||
return m_Cpu[i - 1].mAffinityMask;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // CRYINCLUDE_CRYSYSTEM_CPUDETECT_H
|
||||
@@ -1,90 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
#include "CrySystem_precompiled.h"
|
||||
|
||||
#include "ProjectDefines.h"
|
||||
#if defined(MAP_LOADING_SLICING)
|
||||
|
||||
#include "ClientHandler.h"
|
||||
|
||||
ClientHandler::ClientHandler(const char* bucket, int affinity, int clientTimeout)
|
||||
: HandlerBase(bucket, affinity)
|
||||
{
|
||||
m_clientTimeout = clientTimeout;
|
||||
Reset();
|
||||
}
|
||||
|
||||
void ClientHandler::Reset()
|
||||
{
|
||||
m_srvLock.reset(0);
|
||||
for (int i = 0; i < MAX_CLIENTS_NUM; i++)
|
||||
{
|
||||
std::unique_ptr<SSyncLock> srv(new SSyncLock(m_serverLockName, i, false));
|
||||
|
||||
// first get the client lock up!
|
||||
if (!srv->IsValid())
|
||||
{
|
||||
//try to create client lock
|
||||
m_clientLock.reset(new SSyncLock(m_clientLockName, i, true));
|
||||
if (m_clientLock->IsValid())
|
||||
{
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_clientLock.reset(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool ClientHandler::ServerIsValid()
|
||||
{
|
||||
if (!m_srvLock.get())
|
||||
{
|
||||
if (m_clientLock.get() && m_clientLock->IsValid())
|
||||
{
|
||||
m_srvLock.reset(new SSyncLock(m_serverLockName, m_clientLock->number, false));
|
||||
if (m_srvLock->IsValid())
|
||||
{
|
||||
SetAffinity();
|
||||
//got synched
|
||||
return true;
|
||||
}
|
||||
m_srvLock.reset(0);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return m_srvLock->IsValid();
|
||||
}
|
||||
|
||||
bool ClientHandler::Sync()
|
||||
{
|
||||
if (ServerIsValid())
|
||||
{
|
||||
m_clientLock->Signal();//signal that we're done and
|
||||
if (m_srvLock->Wait(m_clientTimeout))//wait for server
|
||||
{
|
||||
//bla bla, track waiting
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Reset();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif // defined(MAP_LOADING_SLICING)
|
||||
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
#ifndef CRYINCLUDE_CRYSYSTEM_CLIENTHANDLER_H
|
||||
#define CRYINCLUDE_CRYSYSTEM_CLIENTHANDLER_H
|
||||
#pragma once
|
||||
|
||||
#include "HandlerBase.h"
|
||||
#include "SyncLock.h"
|
||||
|
||||
struct ClientHandler
|
||||
: public HandlerBase
|
||||
{
|
||||
ClientHandler(const char* bucket, int affinity, int clientTimeout);
|
||||
|
||||
void Reset();
|
||||
bool ServerIsValid();
|
||||
bool Sync();
|
||||
|
||||
private:
|
||||
int m_clientTimeout;
|
||||
std::unique_ptr<SSyncLock> m_clientLock;
|
||||
std::unique_ptr<SSyncLock> m_srvLock;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,167 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
#include "CrySystem_precompiled.h"
|
||||
#include <AzTest/AzTest.h>
|
||||
|
||||
#include <MathConversion.h>
|
||||
#include <Cry_Quat.h>
|
||||
#include <Cry_Matrix34.h>
|
||||
|
||||
//namespace MathConversionUnitTests
|
||||
//{
|
||||
const float kEpsilon = 0.01f;
|
||||
|
||||
bool IsNearlyEqual(const AZ::Vector3& az, const Vec3& ly)
|
||||
{
|
||||
return fcmp(az.GetX(), ly.x, kEpsilon)
|
||||
&& fcmp(az.GetY(), ly.y, kEpsilon)
|
||||
&& fcmp(az.GetZ(), ly.z, kEpsilon);
|
||||
}
|
||||
|
||||
bool IsNearlyEqual(const AZ::Quaternion& az, const Quat& ly)
|
||||
{
|
||||
return fcmp(az.GetX(), ly.v.x, kEpsilon)
|
||||
&& fcmp(az.GetY(), ly.v.y, kEpsilon)
|
||||
&& fcmp(az.GetZ(), ly.v.z, kEpsilon)
|
||||
&& fcmp(az.GetW(), ly.w, kEpsilon);
|
||||
}
|
||||
|
||||
bool IsNearlyEqual(const AZ::Transform& az, const Matrix34& ly)
|
||||
{
|
||||
float azFloats[12];
|
||||
const AZ::Matrix3x4 matrix3x4 = AZ::Matrix3x4::CreateFromTransform(az);
|
||||
matrix3x4.StoreToRowMajorFloat12(azFloats);
|
||||
|
||||
const float* lyFloats = ly.GetData();
|
||||
|
||||
for (int i = 0; i < 12; ++i)
|
||||
{
|
||||
if (!fcmp(azFloats[i], lyFloats[i], kEpsilon))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IsNearlyEqual(const AZ::Transform& az, const QuatT& ly)
|
||||
{
|
||||
return IsNearlyEqual(az.GetTranslation(), ly.t)
|
||||
&& IsNearlyEqual(az.GetRotation(), ly.q);
|
||||
}
|
||||
|
||||
TEST(MathConversionTests, BasicConversions)
|
||||
{
|
||||
{ // check vector3 comparisons
|
||||
AZ::Vector3 az(1.f, 2.f, 3.f);
|
||||
Vec3 ly(1.f, 2.f, 3.f);
|
||||
EXPECT_TRUE(IsNearlyEqual(az, ly));
|
||||
|
||||
// reverse XYZ
|
||||
ly = Vec3(3.f, 2.f, 1.f);
|
||||
EXPECT_TRUE(!IsNearlyEqual(az, ly));
|
||||
|
||||
// off by 0.1
|
||||
ly = Vec3(1.1f, 2.1f, 3.1f);
|
||||
EXPECT_TRUE(!IsNearlyEqual(az, ly));
|
||||
}
|
||||
|
||||
{ // check vector3 conversions
|
||||
Vec3 ly1(1.f, 2.f, 3.f);
|
||||
AZ::Vector3 az = LYVec3ToAZVec3(ly1);
|
||||
EXPECT_TRUE(IsNearlyEqual(az, ly1));
|
||||
|
||||
Vec3 ly2 = AZVec3ToLYVec3(az);
|
||||
EXPECT_TRUE(IsNearlyEqual(az, ly1));
|
||||
EXPECT_TRUE(ly1.IsEquivalent(ly2));
|
||||
}
|
||||
|
||||
{ // check quaternion comparisons
|
||||
AZ::Quaternion az(AZ::Quaternion::CreateIdentity());
|
||||
Quat ly(IDENTITY);
|
||||
EXPECT_TRUE(IsNearlyEqual(az, ly));
|
||||
|
||||
az = AZ::Quaternion(1.f, 2.f, 3.f, 4.f);
|
||||
ly = Quat(4.f, 1.f, 2.f, 3.f);
|
||||
EXPECT_TRUE(IsNearlyEqual(az, ly));
|
||||
|
||||
// w in wrong place
|
||||
ly = Quat(1.f, 2.f, 3.f, 4.f);
|
||||
EXPECT_TRUE(!IsNearlyEqual(az, ly));
|
||||
}
|
||||
|
||||
{ // check quaternion conversions
|
||||
Quat ly1(4.f, 1.f, 2.f, 3.f);
|
||||
AZ::Quaternion az = LYQuaternionToAZQuaternion(ly1);
|
||||
EXPECT_TRUE(IsNearlyEqual(az, ly1));
|
||||
|
||||
Quat ly2 = AZQuaternionToLYQuaternion(az);
|
||||
EXPECT_TRUE(IsNearlyEqual(az, ly2));
|
||||
EXPECT_TRUE(Quat::IsEquivalent(ly1, ly2));
|
||||
}
|
||||
|
||||
{ // check transform comparisons
|
||||
AZ::Transform az = AZ::Transform::Identity();
|
||||
Matrix34 ly = Matrix34::CreateIdentity();
|
||||
EXPECT_TRUE(IsNearlyEqual(az, ly));
|
||||
|
||||
// rotating pi/2 will get us a non-symmetric matrix.
|
||||
// good for testing that we're not confusing rows & columns
|
||||
float rotation = gf_PI / 2.f;
|
||||
|
||||
ly = Matrix34::CreateRotationX(rotation, Vec3(1.f, 2.f, 3.f));
|
||||
az = AZ::Transform::CreateRotationX(rotation);
|
||||
az.SetTranslation(1.f, 2.f, 3.f);
|
||||
EXPECT_TRUE(IsNearlyEqual(az, ly));
|
||||
|
||||
// rotate around different axis
|
||||
ly = Matrix34::CreateRotationY(rotation, Vec3(1.f, 2.f, 3.f));
|
||||
EXPECT_TRUE(!IsNearlyEqual(az, ly));
|
||||
}
|
||||
|
||||
{ // check transform conversions
|
||||
Matrix34 ly1 = Matrix34::CreateRotationXYZ(Ang3(0.1f, 0.5f, 0.9f), Vec3(1.f, 2.f, 3.f));
|
||||
AZ::Transform az = LYTransformToAZTransform(ly1);
|
||||
EXPECT_TRUE(IsNearlyEqual(az, ly1));
|
||||
|
||||
Matrix34 ly2 = AZTransformToLYTransform(az);
|
||||
EXPECT_TRUE(IsNearlyEqual(az, ly2));
|
||||
EXPECT_TRUE(Matrix34::IsEquivalent(ly1, ly2));
|
||||
}
|
||||
|
||||
{ // check QuatT comparisons
|
||||
AZ::Transform az = AZ::Transform::Identity();
|
||||
QuatT ly(IDENTITY);
|
||||
EXPECT_TRUE(IsNearlyEqual(az, ly));
|
||||
|
||||
az = AZ::Transform::CreateRotationX(AZ::Constants::HalfPi);
|
||||
az.SetTranslation(1.f, 2.f, 3.f);
|
||||
ly.q.SetRotationX(AZ::Constants::HalfPi);
|
||||
ly.t.Set(1.f, 2.f, 3.f);
|
||||
EXPECT_TRUE(IsNearlyEqual(az, ly));
|
||||
|
||||
// off by 0.1
|
||||
ly.t.z += 0.1f;
|
||||
EXPECT_TRUE(!IsNearlyEqual(az, ly));
|
||||
}
|
||||
|
||||
{ // check QuatT conversions
|
||||
QuatT ly1(Quat::CreateRotationX(AZ::Constants::HalfPi), Vec3(5.f, 6.f, 7.f));
|
||||
AZ::Transform az = LYQuatTToAZTransform(ly1);
|
||||
EXPECT_TRUE(IsNearlyEqual(az, ly1));
|
||||
|
||||
QuatT ly2 = AZTransformToLYQuatT(az);
|
||||
EXPECT_TRUE(IsNearlyEqual(az, ly2));
|
||||
EXPECT_TRUE(QuatT::IsEquivalent(ly1, ly2));
|
||||
}
|
||||
}
|
||||
//} // namespace MathConversionUnitTests
|
||||
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
#include "CrySystem_precompiled.h"
|
||||
#include "System.h"
|
||||
#include "CryZlib.h"
|
||||
|
||||
bool CSystem::CompressDataBlock(const void* input, size_t inputSize, void* output, size_t& outputSize, int level)
|
||||
{
|
||||
uLongf destLen = outputSize;
|
||||
Bytef* dest = static_cast<Bytef*>(output);
|
||||
uLong sourceLen = inputSize;
|
||||
const Bytef* source = static_cast<const Bytef*>(input);
|
||||
bool ok = Z_OK == compress2(dest, &destLen, source, sourceLen, level);
|
||||
outputSize = destLen;
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool CSystem::DecompressDataBlock(const void* input, size_t inputSize, void* output, size_t& outputSize)
|
||||
{
|
||||
uLongf destLen = outputSize;
|
||||
Bytef* dest = static_cast<Bytef*>(output);
|
||||
uLong sourceLen = inputSize;
|
||||
const Bytef* source = static_cast<const Bytef*>(input);
|
||||
bool ok = Z_OK == uncompress(dest, &destLen, source, sourceLen);
|
||||
outputSize = destLen;
|
||||
return ok;
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
#include "CrySystem_precompiled.h"
|
||||
#include <AzCore/Debug/Profiler.h>
|
||||
#include <AzCore/Jobs/JobFunction.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
static void cryAsyncMemcpy_Int(
|
||||
void* dst
|
||||
, const void* src
|
||||
, size_t size
|
||||
, int nFlags
|
||||
, volatile int* sync)
|
||||
{
|
||||
AZ_PROFILE_FUNCTION(AZ::Debug::ProfileCategory::System);
|
||||
|
||||
cryMemcpy(dst, src, size, nFlags);
|
||||
if (sync)
|
||||
{
|
||||
CryInterlockedDecrement(sync);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if !defined(CRY_ASYNC_MEMCPY_DELEGATE_TO_CRYSYSTEM)
|
||||
CRY_ASYNC_MEMCPY_API void cryAsyncMemcpy(
|
||||
#else
|
||||
CRY_ASYNC_MEMCPY_API void cryAsyncMemcpyDelegate(
|
||||
#endif
|
||||
void* dst
|
||||
, const void* src
|
||||
, size_t size
|
||||
, int nFlags
|
||||
, volatile int* sync)
|
||||
{
|
||||
AZ::Job* job = AZ::CreateJobFunction(
|
||||
[dst, src, size, nFlags, sync]()
|
||||
{
|
||||
cryAsyncMemcpy_Int(dst, src, size, nFlags, sync);
|
||||
},
|
||||
true); // Auto-delete
|
||||
job->Start();
|
||||
}
|
||||
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,91 +0,0 @@
|
||||
// Microsoft Visual C++ generated resource script.
|
||||
//
|
||||
#include "resource.h"
|
||||
|
||||
#define APSTUDIO_READONLY_SYMBOLS
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 2 resource.
|
||||
//
|
||||
#include "winres.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#undef APSTUDIO_READONLY_SYMBOLS
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// German (Germany) resources
|
||||
|
||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_DEU)
|
||||
LANGUAGE LANG_GERMAN, SUBLANG_GERMAN
|
||||
#pragma code_page(1252)
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Version
|
||||
//
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 1,0,0,1
|
||||
PRODUCTVERSION 1,0,0,1
|
||||
FILEFLAGSMASK 0x17L
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
#else
|
||||
FILEFLAGS 0x0L
|
||||
#endif
|
||||
FILEOS 0x4L
|
||||
FILETYPE 0x2L
|
||||
FILESUBTYPE 0x0L
|
||||
BEGIN
|
||||
BLOCK "StringFileInfo"
|
||||
BEGIN
|
||||
BLOCK "000904b0"
|
||||
BEGIN
|
||||
VALUE "CompanyName", "Amazon.com, Inc."
|
||||
VALUE "FileVersion", "1, 0, 0, 1"
|
||||
VALUE "LegalCopyright", "Portions of this file Copyright (c) Amazon.com, Inc. or its affiliates. All Rights Reserved. Original file Copyright (c) Crytek GMBH. Used under license by Amazon.com, Inc. and its affiliates."
|
||||
VALUE "ProductName", "Lumberyard"
|
||||
VALUE "ProductVersion", "1, 0, 0, 1"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
BEGIN
|
||||
VALUE "Translation", 0x9, 1200
|
||||
END
|
||||
END
|
||||
|
||||
#endif // German (Germany) resources
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// English (United States) resources
|
||||
|
||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
|
||||
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
|
||||
#pragma code_page(1252)
|
||||
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// TEXTINCLUDE
|
||||
//
|
||||
|
||||
1 TEXTINCLUDE
|
||||
BEGIN
|
||||
"resource.h\0"
|
||||
END
|
||||
|
||||
2 TEXTINCLUDE
|
||||
BEGIN
|
||||
"#include ""winres.h""\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
3 TEXTINCLUDE
|
||||
BEGIN
|
||||
"\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
#endif // APSTUDIO_INVOKED
|
||||
#endif // English (United States) resources
|
||||
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
// Header for adding a watermark to an exe, which can then be set
|
||||
// by the external CryWaterMark program. To use, simply write:
|
||||
//
|
||||
// WATERMARKDATA(__blah);
|
||||
//
|
||||
// anywhere in the global scope in the program
|
||||
|
||||
|
||||
#ifndef CRYINCLUDE_CRYSYSTEM_CRYWATERMARK_H
|
||||
#define CRYINCLUDE_CRYSYSTEM_CRYWATERMARK_H
|
||||
#pragma once
|
||||
|
||||
|
||||
#define NUMMARKWORDS 10
|
||||
#define WATERMARKDATA(name) unsigned int name[] = { 0xDEBEFECA, 0xFABECEDA, 0xADABAFBE, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
// (the name is such that you can have multiple watermarks in one exe, don't use
|
||||
// names like "watermark" just incase you accidentally give out an exe with
|
||||
// debug information).
|
||||
|
||||
#endif // CRYINCLUDE_CRYSYSTEM_CRYWATERMARK_H
|
||||
@@ -1,131 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
#include "CrySystem_precompiled.h"
|
||||
|
||||
#include "ProjectDefines.h"
|
||||
#if defined(MAP_LOADING_SLICING)
|
||||
|
||||
#include "HandlerBase.h"
|
||||
|
||||
const char* SERVER_LOCK_NAME = "SynchronizeGameServer";
|
||||
const char* CLIENT_LOCK_NAME = "SynchronizeGameClient";
|
||||
|
||||
HandlerBase::HandlerBase(const char* bucket, int affinity)
|
||||
{
|
||||
m_serverLockName.Format("%s_%s", SERVER_LOCK_NAME, bucket);
|
||||
m_clientLockName.Format("%s_%s", CLIENT_LOCK_NAME, bucket);
|
||||
if (affinity != 0)
|
||||
{
|
||||
m_affinity = uint32(1) << (affinity - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_affinity = -1;
|
||||
}
|
||||
m_prevAffinity = 0;
|
||||
}
|
||||
|
||||
HandlerBase::~HandlerBase()
|
||||
{
|
||||
if (m_prevAffinity)
|
||||
{
|
||||
if (SyncSetAffinity(m_prevAffinity))
|
||||
{
|
||||
CryLogAlways("Restored affinity to %d", m_prevAffinity);
|
||||
}
|
||||
else
|
||||
{
|
||||
CryLogAlways("Failed to restore affinity to %d", m_prevAffinity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HandlerBase::SetAffinity()
|
||||
{
|
||||
if (m_prevAffinity) //already set
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (uint32 p = SyncSetAffinity(m_affinity))
|
||||
{
|
||||
CryLogAlways("Changed affinity to %d", m_affinity);
|
||||
m_prevAffinity = p;
|
||||
}
|
||||
else
|
||||
{
|
||||
CryLogAlways("Failed to change affinity to %d", m_affinity);
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(LINUX)
|
||||
|
||||
uint32 HandlerBase::SyncSetAffinity(uint32 cpuMask)//put -1
|
||||
{
|
||||
if (cpuMask != 0)
|
||||
{
|
||||
cpu_set_t cpuSet;
|
||||
uint32 affinity = 0;
|
||||
if (!sched_getaffinity(getpid(), sizeof cpuSet, &cpuSet))
|
||||
{
|
||||
for (int cpu = 0; cpu < sizeof(cpuMask) * 8; ++cpu)
|
||||
{
|
||||
if (CPU_ISSET(cpu, &cpuSet))
|
||||
{
|
||||
affinity |= 1 << cpu;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (affinity)
|
||||
{
|
||||
CPU_ZERO(&cpuSet);
|
||||
for (int cpu = 0; cpu < sizeof(cpuMask) * 8; ++cpu)
|
||||
{
|
||||
if (cpuMask & (1 << cpu))
|
||||
{
|
||||
CPU_SET(cpu, &cpuSet);
|
||||
}
|
||||
}
|
||||
|
||||
if (!sched_setaffinity(getpid(), sizeof(cpuSet), &cpuSet))
|
||||
{
|
||||
return affinity;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#elif AZ_LEGACY_CRYSYSTEM_TRAIT_USE_HANDLER_SYNC_AFFINITY
|
||||
|
||||
uint32 HandlerBase::SyncSetAffinity(uint32 cpuMask)//put -1
|
||||
{
|
||||
uint32 p = (uint32)SetThreadAffinityMask(GetCurrentThread(), cpuMask);
|
||||
if (p == 0)
|
||||
{
|
||||
CryLogAlways("Error updating affinity mask to %d", cpuMask);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
uint32 HandlerBase::SyncSetAffinity(uint32 cpuMask)//put -1
|
||||
{
|
||||
CryLogAlways("Updating thread affinity not supported on this platform");
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif // defined(MAP_LOADING_SLICING)
|
||||
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
#ifndef CRYINCLUDE_CRYSYSTEM_HANDLERBASE_H
|
||||
#define CRYINCLUDE_CRYSYSTEM_HANDLERBASE_H
|
||||
|
||||
#pragma once
|
||||
|
||||
const int MAX_CLIENTS_NUM = 100;
|
||||
|
||||
struct HandlerBase
|
||||
{
|
||||
HandlerBase(const char* bucket, int affinity);
|
||||
~HandlerBase();
|
||||
|
||||
void SetAffinity();
|
||||
uint32 SyncSetAffinity(uint32 cpuMask);
|
||||
|
||||
string m_serverLockName;
|
||||
string m_clientLockName;
|
||||
uint32 m_affinity;
|
||||
uint32 m_prevAffinity;
|
||||
};
|
||||
|
||||
#endif // CRYINCLUDE_CRYSYSTEM_HANDLERBASE_H
|
||||
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
// Description : Console implementation for iOS, reports back to the main interface
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <IConsole.h>
|
||||
#include <ITextModeConsole.h>
|
||||
|
||||
class CIOSConsole
|
||||
: public ISystemUserCallback
|
||||
, public IOutputPrintSink
|
||||
, public ITextModeConsole
|
||||
{
|
||||
CIOSConsole(const CIOSConsole&);
|
||||
CIOSConsole& operator = (const CIOSConsole&);
|
||||
|
||||
bool m_isInitialized;
|
||||
public:
|
||||
static CryCriticalSectionNonRecursive s_lock;
|
||||
public:
|
||||
CIOSConsole();
|
||||
~CIOSConsole();
|
||||
|
||||
// Interface IOutputPrintSink /////////////////////////////////////////////
|
||||
DLL_EXPORT virtual void Print(const char* line);
|
||||
|
||||
// Interface ISystemUserCallback //////////////////////////////////////////
|
||||
virtual bool OnError(const char* errorString);
|
||||
virtual bool OnSaveDocument() { return false; }
|
||||
virtual void OnProcessSwitch() { }
|
||||
virtual void OnInitProgress(const char* sProgressMsg);
|
||||
virtual void OnInit(ISystem*);
|
||||
virtual void OnShutdown();
|
||||
virtual void OnUpdate();
|
||||
virtual void GetMemoryUsage(ICrySizer* pSizer);
|
||||
void SetRequireDedicatedServer(bool) {}
|
||||
void SetHeader(const char*) {}
|
||||
// Interface ITextModeConsole /////////////////////////////////////////////
|
||||
virtual Vec2_tpl<int> BeginDraw();
|
||||
virtual void PutText(int x, int y, const char* msg);
|
||||
virtual void EndDraw();
|
||||
};
|
||||
@@ -1,94 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
#include "CrySystem_precompiled.h"
|
||||
#if defined(IOS)
|
||||
#include "IOSConsole.h"
|
||||
|
||||
|
||||
|
||||
CIOSConsole::CIOSConsole():
|
||||
m_isInitialized(false)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CIOSConsole::~CIOSConsole()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Interface IOutputPrintSink /////////////////////////////////////////////
|
||||
void CIOSConsole::Print(const char *line)
|
||||
{
|
||||
printf("MSG: %s\n", line);
|
||||
}
|
||||
// Interface ISystemUserCallback //////////////////////////////////////////
|
||||
bool CIOSConsole::OnError(const char *errorString)
|
||||
{
|
||||
printf("ERR: %s\n", errorString);
|
||||
return true;
|
||||
}
|
||||
|
||||
void CIOSConsole::OnInitProgress(const char *sProgressMsg)
|
||||
{
|
||||
(void) sProgressMsg;
|
||||
// Do Nothing
|
||||
}
|
||||
void CIOSConsole::OnInit(ISystem *pSystem)
|
||||
{
|
||||
if (!m_isInitialized)
|
||||
{
|
||||
IConsole* pConsole = pSystem->GetIConsole();
|
||||
if (pConsole != 0)
|
||||
{
|
||||
pConsole->AddOutputPrintSink(this);
|
||||
}
|
||||
m_isInitialized = true;
|
||||
}
|
||||
}
|
||||
void CIOSConsole::OnShutdown()
|
||||
{
|
||||
if (m_isInitialized)
|
||||
{
|
||||
// remove outputprintsink
|
||||
m_isInitialized = false;
|
||||
}
|
||||
}
|
||||
void CIOSConsole::OnUpdate()
|
||||
{
|
||||
// Do Nothing
|
||||
}
|
||||
void CIOSConsole::GetMemoryUsage(ICrySizer *pSizer)
|
||||
{
|
||||
size_t size = sizeof(*this);
|
||||
|
||||
|
||||
|
||||
pSizer->AddObject(this, size);
|
||||
}
|
||||
|
||||
// Interface ITextModeConsole /////////////////////////////////////////////
|
||||
Vec2_tpl<int> CIOSConsole::BeginDraw()
|
||||
{
|
||||
return Vec2_tpl<int>(0,0);
|
||||
}
|
||||
void CIOSConsole::PutText( int x, int y, const char * msg )
|
||||
{
|
||||
printf("PUT: %s\n", msg);
|
||||
}
|
||||
void CIOSConsole::EndDraw() {
|
||||
// Do Nothing
|
||||
}
|
||||
#endif // IOS
|
||||
@@ -1,29 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
// Description : lz4 hc decompress wrapper
|
||||
|
||||
|
||||
#include "CrySystem_precompiled.h"
|
||||
#include <lz4.h>
|
||||
#include "LZ4Decompressor.h"
|
||||
|
||||
bool CLZ4Decompressor::DecompressData(const char* pIn, char* pOut, const uint outputSize) const
|
||||
{
|
||||
return LZ4_decompress_fast(pIn, pOut, outputSize) >= 0;
|
||||
}
|
||||
|
||||
void CLZ4Decompressor::Release()
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
// Description : lz4 hc decompress wrapper
|
||||
|
||||
|
||||
#ifndef CRYINCLUDE_CRYSYSTEM_LZ4DECOMPRESSOR_H
|
||||
#define CRYINCLUDE_CRYSYSTEM_LZ4DECOMPRESSOR_H
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "ILZ4Decompressor.h"
|
||||
|
||||
class CLZ4Decompressor
|
||||
: public ILZ4Decompressor
|
||||
{
|
||||
public:
|
||||
virtual bool DecompressData(const char* pIn, char* pOut, const uint outputSize) const;
|
||||
virtual void Release();
|
||||
|
||||
private:
|
||||
virtual ~CLZ4Decompressor() {}
|
||||
};
|
||||
|
||||
#endif // CRYINCLUDE_CRYSYSTEM_LZ4DECOMPRESSOR_H
|
||||
@@ -260,16 +260,6 @@ void CLevelSystem::Rescan(const char* levelsFolder)
|
||||
{
|
||||
if (levelsFolder)
|
||||
{
|
||||
if (const ICmdLineArg* pModArg = m_pSystem->GetICmdLine()->FindArg(eCLAT_Pre, "MOD"))
|
||||
{
|
||||
if (m_pSystem->IsMODValid(pModArg->GetValue()))
|
||||
{
|
||||
m_levelsFolder.format("Mods/%s/%s", pModArg->GetValue(), levelsFolder);
|
||||
m_levelInfos.clear();
|
||||
ScanFolder(0, true);
|
||||
}
|
||||
}
|
||||
|
||||
m_levelsFolder = levelsFolder;
|
||||
}
|
||||
|
||||
|
||||
@@ -417,7 +417,7 @@ void CLog::LogV(const ELogType type, const char* szFormat, va_list args)
|
||||
LogV(type, 0, szFormat, args);
|
||||
}
|
||||
|
||||
void CLog::LogV(const ELogType type, int flags, const char* szFormat, va_list args)
|
||||
void CLog::LogV(const ELogType type, [[maybe_unused]]int flags, const char* szFormat, va_list args)
|
||||
{
|
||||
// this is here in case someone called LogV directly, with an invalid formatter.
|
||||
if (!CheckLogFormatter(szFormat))
|
||||
@@ -595,28 +595,6 @@ void CLog::LogV(const ELogType type, int flags, const char* szFormat, va_list ar
|
||||
GetISystem()->GetIRemoteConsole()->AddLogError(szString);
|
||||
break;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
if (type == eWarningAlways || type == eWarning || type == eError || type == eErrorAlways)
|
||||
{
|
||||
IValidator* pValidator = m_pSystem->GetIValidator();
|
||||
if (pValidator && (flags & VALIDATOR_FLAG_SKIP_VALIDATOR) == 0)
|
||||
{
|
||||
CryAutoCriticalSection scope_lock(m_logCriticalSection);
|
||||
|
||||
SValidatorRecord record;
|
||||
record.text = szBuffer;
|
||||
record.module = VALIDATOR_MODULE_SYSTEM;
|
||||
record.severity = VALIDATOR_WARNING;
|
||||
record.assetScope = GetAssetScopeString();
|
||||
record.flags = flags;
|
||||
if (type == eError || type == eErrorAlways)
|
||||
{
|
||||
record.severity = VALIDATOR_ERROR;
|
||||
}
|
||||
pValidator->Report(record);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//will log the text both to the end of file and console
|
||||
|
||||
@@ -1,151 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
#include "CrySystem_precompiled.h"
|
||||
#include <AzCore/std/string/regex.h>
|
||||
#include <AzCore/std/string/string.h>
|
||||
#include <IXml.h>
|
||||
|
||||
#include "MobileDetectSpec.h"
|
||||
|
||||
namespace MobileSysInspect
|
||||
{
|
||||
struct GpuApiPair
|
||||
{
|
||||
AZStd::string gpuDescription;
|
||||
AZStd::string apiDescription;
|
||||
};
|
||||
|
||||
AZStd::vector<AZStd::pair<AZStd::string, AZStd::string>> deviceSpecMapping;
|
||||
AZStd::vector<AZStd::pair<GpuApiPair, AZStd::string>> gpuSpecMapping;
|
||||
const float LOW_SPEC_RAM = 1.0f;
|
||||
const float MEDIUM_SPEC_RAM = 2.0f;
|
||||
const float HIGH_SPEC_RAM = 3.0f;
|
||||
|
||||
bool GetSpecForGPUAndAPI(const AZStd::string& gpuName, const AZStd::string& apiDescription, AZStd::string& specName)
|
||||
{
|
||||
for (const auto& descriptionSpecPair : gpuSpecMapping)
|
||||
{
|
||||
const GpuApiPair& currentPair = descriptionSpecPair.first;
|
||||
AZStd::regex currentRegex(currentPair.gpuDescription.c_str());
|
||||
if (!AZStd::regex_search(gpuName, currentRegex))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
currentRegex.assign(currentPair.apiDescription.c_str());
|
||||
if (!currentRegex.Empty() && !AZStd::regex_search(apiDescription, currentRegex))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
specName = descriptionSpecPair.second;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
namespace Internal
|
||||
{
|
||||
void LoadDeviceSpecMapping_impl(const char* filename)
|
||||
{
|
||||
XmlNodeRef xmlNode = GetISystem()->LoadXmlFromFile(filename);
|
||||
|
||||
if (!xmlNode)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const int fileCount = xmlNode->getChildCount();
|
||||
|
||||
for (int i = 0; i < fileCount; ++i)
|
||||
{
|
||||
XmlNodeRef fileNode = xmlNode->getChild(i);
|
||||
AZStd::string file = fileNode->getAttr("file");
|
||||
|
||||
if (!file.empty())
|
||||
{
|
||||
const int mappingCount = fileNode->getChildCount();
|
||||
|
||||
deviceSpecMapping.reserve(mappingCount);
|
||||
|
||||
for (int j = 0; j < mappingCount; ++j)
|
||||
{
|
||||
XmlNodeRef modelNode = fileNode->getChild(j);
|
||||
AZStd::string model = modelNode->getAttr("model");
|
||||
|
||||
if (!model.empty())
|
||||
{
|
||||
deviceSpecMapping.push_back(AZStd::make_pair(model, file));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LoadGpuSpecMapping_impl(const char* filename)
|
||||
{
|
||||
XmlNodeRef xmlNode = GetISystem()->LoadXmlFromFile(filename);
|
||||
|
||||
if (!xmlNode)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const int fileCount = xmlNode->getChildCount();
|
||||
|
||||
for (int i = 0; i < fileCount; ++i)
|
||||
{
|
||||
XmlNodeRef fileNode = xmlNode->getChild(i);
|
||||
AZStd::string file = fileNode->getAttr("file");
|
||||
|
||||
if (!file.empty())
|
||||
{
|
||||
const int mappingCount = fileNode->getChildCount();
|
||||
|
||||
gpuSpecMapping.reserve(mappingCount);
|
||||
|
||||
for (int j = 0; j < mappingCount; ++j)
|
||||
{
|
||||
XmlNodeRef modelNode = fileNode->getChild(j);
|
||||
GpuApiPair gpuApiPair;
|
||||
gpuApiPair.gpuDescription = modelNode->getAttr("gpuName");
|
||||
gpuApiPair.apiDescription = modelNode->getAttr("apiVersion");
|
||||
|
||||
if (!gpuApiPair.gpuDescription.empty() || !gpuApiPair.apiDescription.empty())
|
||||
{
|
||||
gpuSpecMapping.push_back(AZStd::make_pair(gpuApiPair, file));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool GetSpecForModelName(const AZStd::string& modelName, AZStd::string& specName)
|
||||
{
|
||||
for (const auto& descriptionSpecPair : deviceSpecMapping)
|
||||
{
|
||||
AZStd::regex currentRegex(descriptionSpecPair.first.c_str());
|
||||
if (AZStd::regex_search(modelName, currentRegex))
|
||||
{
|
||||
specName = descriptionSpecPair.second;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace MobileSysInspect
|
||||
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "AzCore/std/containers/unordered_map.h"
|
||||
|
||||
namespace MobileSysInspect
|
||||
{
|
||||
extern const float LOW_SPEC_RAM;
|
||||
extern const float MEDIUM_SPEC_RAM;
|
||||
extern const float HIGH_SPEC_RAM;
|
||||
|
||||
void LoadDeviceSpecMapping();
|
||||
bool GetAutoDetectedSpecName(AZStd::string &buffer);
|
||||
bool GetSpecForGPUAndAPI(const AZStd::string& gpuName, const AZStd::string& apiDescription, AZStd::string& specName);
|
||||
const float GetDeviceRamInGB();
|
||||
|
||||
namespace Internal
|
||||
{
|
||||
void LoadDeviceSpecMapping_impl(const char* fileName);
|
||||
void LoadGpuSpecMapping_impl(const char* filename);
|
||||
bool GetSpecForModelName(const AZStd::string& modelName, AZStd::string& specName);
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
#include "CrySystem_precompiled.h"
|
||||
#include <AzCore/Android/JNI/JNI.h>
|
||||
#include <AzCore/Android/JNI/Object.h>
|
||||
#include <AzCore/std/string/string.h>
|
||||
|
||||
#include "MobileDetectSpec.h"
|
||||
|
||||
namespace MobileSysInspect
|
||||
{
|
||||
void LoadDeviceSpecMapping()
|
||||
{
|
||||
Internal::LoadDeviceSpecMapping_impl("@assets@/config/gpu/android_models.xml");
|
||||
Internal::LoadGpuSpecMapping_impl("@assets@/config/gpu/android_gpus.xml");
|
||||
}
|
||||
|
||||
// Returns true if device is found in the device spec mapping
|
||||
bool GetAutoDetectedSpecName(AZStd::string &buffer)
|
||||
{
|
||||
static constexpr const char* s_javaFieldName = "MODEL";
|
||||
AZ::Android::JNI::Object obj("android/os/Build");
|
||||
obj.RegisterStaticField(s_javaFieldName, "Ljava/lang/String;");
|
||||
AZStd::string name = obj.GetStaticStringField(s_javaFieldName);
|
||||
|
||||
return Internal::GetSpecForModelName(name, buffer);
|
||||
}
|
||||
|
||||
const float GetDeviceRamInGB()
|
||||
{
|
||||
static constexpr const char* s_javaFuntionNameGetDeviceRamInGB = "GetDeviceRamInGB";
|
||||
AZ::Android::JNI::Object obj("com/amazon/lumberyard/AndroidDeviceManager");
|
||||
obj.RegisterStaticMethod(s_javaFuntionNameGetDeviceRamInGB, "()F");
|
||||
return obj.InvokeStaticFloatMethod(s_javaFuntionNameGetDeviceRamInGB);
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
#include "CrySystem_precompiled.h"
|
||||
#include <AzCore/std/string/string.h>
|
||||
|
||||
#include "MobileDetectSpec.h"
|
||||
#include <AzFramework/Utils/SystemUtilsApple.h>
|
||||
|
||||
namespace MobileSysInspect
|
||||
{
|
||||
void LoadDeviceSpecMapping()
|
||||
{
|
||||
Internal::LoadDeviceSpecMapping_impl("@assets@/config/gpu/ios_models.xml");
|
||||
}
|
||||
|
||||
// Returns true if device is found in the device spec mapping
|
||||
bool GetAutoDetectedSpecName(AZStd::string &buffer)
|
||||
{
|
||||
AZStd::string name = SystemUtilsApple::GetMachineName();
|
||||
|
||||
return Internal::GetSpecForModelName(name, buffer);
|
||||
}
|
||||
|
||||
const float GetDeviceRamInGB()
|
||||
{
|
||||
// not supported on this platform
|
||||
return 0.0f;
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
// Description : declaration of a simple dedicated renderer for the physics subsystem
|
||||
|
||||
|
||||
#ifndef CRYINCLUDE_CRYSYSTEM_PHYSRENDERER_H
|
||||
#define CRYINCLUDE_CRYSYSTEM_PHYSRENDERER_H
|
||||
#pragma once
|
||||
|
||||
|
||||
#endif // CRYINCLUDE_CRYSYSTEM_PHYSRENDERER_H
|
||||
@@ -1,16 +0,0 @@
|
||||
#
|
||||
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
# its licensors.
|
||||
#
|
||||
# For complete copyright and license terms please see the LICENSE at the root of this
|
||||
# distribution (the "License"). All use of this software is governed by the License,
|
||||
# or, if provided, by the license below or the license accompanying this file. Do not
|
||||
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
#
|
||||
|
||||
# Platform specific cmake file for configuring target compiler/link properties
|
||||
# based on the active platform
|
||||
# NOTE: functions in cmake are global, therefore adding functions to this file
|
||||
# is being avoided to prevent overriding functions declared in other targets platfrom
|
||||
# specific cmake files
|
||||
@@ -1,18 +0,0 @@
|
||||
#
|
||||
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
# its licensors.
|
||||
#
|
||||
# For complete copyright and license terms please see the LICENSE at the root of this
|
||||
# distribution (the "License"). All use of this software is governed by the License,
|
||||
# or, if provided, by the license below or the license accompanying this file. Do not
|
||||
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
#
|
||||
|
||||
set(FILES
|
||||
../../MobileDetectSpec_Android.cpp
|
||||
../../MobileDetectSpec.cpp
|
||||
../../MobileDetectSpec.h
|
||||
../../ThermalInfoAndroid.h
|
||||
../../ThermalInfoAndroid.cpp
|
||||
)
|
||||
@@ -1,21 +0,0 @@
|
||||
#
|
||||
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
# its licensors.
|
||||
#
|
||||
# For complete copyright and license terms please see the LICENSE at the root of this
|
||||
# distribution (the "License"). All use of this software is governed by the License,
|
||||
# or, if provided, by the license below or the license accompanying this file. Do not
|
||||
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
#
|
||||
|
||||
# Platform specific cmake file for configuring target compiler/link properties
|
||||
# based on the active platform
|
||||
# NOTE: functions in cmake are global, therefore adding functions to this file
|
||||
# is being avoided to prevent overriding functions declared in other targets platfrom
|
||||
# specific cmake files
|
||||
|
||||
set(LY_BUILD_DEPENDENCIES
|
||||
PRIVATE
|
||||
m
|
||||
)
|
||||
@@ -1,16 +0,0 @@
|
||||
#
|
||||
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
# its licensors.
|
||||
#
|
||||
# For complete copyright and license terms please see the LICENSE at the root of this
|
||||
# distribution (the "License"). All use of this software is governed by the License,
|
||||
# or, if provided, by the license below or the license accompanying this file. Do not
|
||||
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
#
|
||||
|
||||
# Platform specific cmake file for configuring target compiler/link properties
|
||||
# based on the active platform
|
||||
# NOTE: functions in cmake are global, therefore adding functions to this file
|
||||
# is being avoided to prevent overriding functions declared in other targets platfrom
|
||||
# specific cmake files
|
||||
@@ -1,10 +0,0 @@
|
||||
#
|
||||
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
# its licensors.
|
||||
#
|
||||
# For complete copyright and license terms please see the LICENSE at the root of this
|
||||
# distribution (the "License"). All use of this software is governed by the License,
|
||||
# or, if provided, by the license below or the license accompanying this file. Do not
|
||||
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
#
|
||||
@@ -1,16 +0,0 @@
|
||||
#
|
||||
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
# its licensors.
|
||||
#
|
||||
# For complete copyright and license terms please see the LICENSE at the root of this
|
||||
# distribution (the "License"). All use of this software is governed by the License,
|
||||
# or, if provided, by the license below or the license accompanying this file. Do not
|
||||
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
#
|
||||
|
||||
# Platform specific cmake file for configuring target compiler/link properties
|
||||
# based on the active platform
|
||||
# NOTE: functions in cmake are global, therefore adding functions to this file
|
||||
# is being avoided to prevent overriding functions declared in other targets platfrom
|
||||
# specific cmake files
|
||||
@@ -1,13 +0,0 @@
|
||||
#
|
||||
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
# its licensors.
|
||||
#
|
||||
# For complete copyright and license terms please see the LICENSE at the root of this
|
||||
# distribution (the "License"). All use of this software is governed by the License,
|
||||
# or, if provided, by the license below or the license accompanying this file. Do not
|
||||
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
#
|
||||
|
||||
set(FILES
|
||||
)
|
||||
@@ -1,22 +0,0 @@
|
||||
#
|
||||
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
# its licensors.
|
||||
#
|
||||
# For complete copyright and license terms please see the LICENSE at the root of this
|
||||
# distribution (the "License"). All use of this software is governed by the License,
|
||||
# or, if provided, by the license below or the license accompanying this file. Do not
|
||||
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
#
|
||||
|
||||
set(LY_COMPILE_OPTIONS
|
||||
PRIVATE
|
||||
-xobjective-c++
|
||||
)
|
||||
|
||||
find_library(UI_KIT_FRAMEWORK UIKit)
|
||||
|
||||
set(LY_BUILD_DEPENDENCIES
|
||||
PRIVATE
|
||||
${UI_KIT_FRAMEWORK}
|
||||
)
|
||||
@@ -1,3 +0,0 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:45dfbb9836e8a8ac4ed5b427528dadf9134618e6977a1eb67af067e0eaadc185
|
||||
size 561936
|
||||
@@ -1,287 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
#include "CrySystem_precompiled.h"
|
||||
#include "Sampler.h"
|
||||
|
||||
#if defined(WIN32)
|
||||
|
||||
#include <ISystem.h>
|
||||
#include <Mmsystem.h>
|
||||
#include <AzCore/Debug/StackTracer.h>
|
||||
|
||||
#define MAX_SYMBOL_LENGTH 512
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Makes thread.
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
class CSamplingThread
|
||||
{
|
||||
public:
|
||||
CSamplingThread(CSampler* pSampler)
|
||||
{
|
||||
m_hThread = NULL;
|
||||
m_pSampler = pSampler;
|
||||
m_bStop = false;
|
||||
m_samplePeriodMs = pSampler->GetSamplePeriod();
|
||||
|
||||
m_hProcess = GetCurrentProcess();
|
||||
m_hSampledThread = GetCurrentThread();
|
||||
DuplicateHandle(GetCurrentProcess(), GetCurrentThread(), GetCurrentProcess(), &m_hSampledThread, 0, FALSE, DUPLICATE_SAME_ACCESS);
|
||||
}
|
||||
|
||||
// Start thread.
|
||||
void Start();
|
||||
void Stop();
|
||||
|
||||
protected:
|
||||
virtual ~CSamplingThread() {};
|
||||
static DWORD WINAPI ThreadFunc(void* pThreadParam);
|
||||
void Run(); // Derived classes must override this.
|
||||
|
||||
HANDLE m_hProcess;
|
||||
HANDLE m_hThread;
|
||||
HANDLE m_hSampledThread;
|
||||
DWORD m_ThreadId;
|
||||
|
||||
CSampler* m_pSampler;
|
||||
bool m_bStop;
|
||||
int m_samplePeriodMs;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CSamplingThread::Start()
|
||||
{
|
||||
m_hThread = CreateThread(NULL, 0, ThreadFunc, this, 0, &m_ThreadId);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CSamplingThread::Stop()
|
||||
{
|
||||
m_bStop = true;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
DWORD CSamplingThread::ThreadFunc(void* pThreadParam)
|
||||
{
|
||||
CSamplingThread* thread = (CSamplingThread*)pThreadParam;
|
||||
thread->Run();
|
||||
// Auto destruct thread class.
|
||||
delete thread;
|
||||
return 0;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CSamplingThread::Run()
|
||||
{
|
||||
//SetThreadPriority( m_hThread,THREAD_PRIORITY_HIGHEST );
|
||||
SetThreadPriority(m_hThread, THREAD_PRIORITY_TIME_CRITICAL);
|
||||
while (!m_bStop)
|
||||
{
|
||||
SuspendThread(m_hSampledThread);
|
||||
|
||||
CONTEXT context;
|
||||
context.ContextFlags = CONTEXT_CONTROL;
|
||||
|
||||
uint64 ip = 0;
|
||||
if (GetThreadContext(m_hSampledThread, &context))
|
||||
{
|
||||
#ifdef CONTEXT_i386
|
||||
ip = context.Eip;
|
||||
#else
|
||||
ip = context.Rip;
|
||||
#endif
|
||||
}
|
||||
ResumeThread(m_hSampledThread);
|
||||
|
||||
if (!m_pSampler->AddSample(ip))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
Sleep(m_samplePeriodMs);
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
CSampler::CSampler()
|
||||
{
|
||||
m_pSamplingThread = NULL;
|
||||
SetMaxSamples(2000);
|
||||
m_bSamplingFinished = false;
|
||||
m_bSampling = false;
|
||||
m_samplePeriodMs = 1; //1ms
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
CSampler::~CSampler()
|
||||
{
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CSampler::SetMaxSamples(int nMaxSamples)
|
||||
{
|
||||
m_rawSamples.reserve(nMaxSamples);
|
||||
m_nMaxSamples = nMaxSamples;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CSampler::Start()
|
||||
{
|
||||
if (m_bSampling)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
CryLogAlways("Staring Sampling with interval %dms, max samples: %d ...", m_samplePeriodMs, m_nMaxSamples);
|
||||
|
||||
m_bSampling = true;
|
||||
m_bSamplingFinished = false;
|
||||
m_pSamplingThread = new CSamplingThread(this);
|
||||
m_rawSamples.clear();
|
||||
m_functionSamples.clear();
|
||||
|
||||
m_pSamplingThread->Start();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CSampler::Stop()
|
||||
{
|
||||
if (m_bSamplingFinished)
|
||||
{
|
||||
}
|
||||
if (m_bSampling)
|
||||
{
|
||||
m_pSamplingThread->Stop();
|
||||
}
|
||||
m_bSampling = false;
|
||||
m_pSamplingThread = 0;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CSampler::Update()
|
||||
{
|
||||
if (m_bSamplingFinished)
|
||||
{
|
||||
ProcessSampledData();
|
||||
m_bSamplingFinished = false;
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool CSampler::AddSample(uint64 ip)
|
||||
{
|
||||
if ((int)m_rawSamples.size() >= m_nMaxSamples)
|
||||
{
|
||||
m_bSamplingFinished = true;
|
||||
m_bSampling = false;
|
||||
m_pSamplingThread = 0;
|
||||
return false;
|
||||
}
|
||||
m_rawSamples.push_back(ip);
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool CompareFunctionSamples(const CSampler::SFunctionSample& s1, const CSampler::SFunctionSample& s2)
|
||||
{
|
||||
return s1.nSamples < s2.nSamples;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CSampler::ProcessSampledData()
|
||||
{
|
||||
CryLogAlways("Processing collected samples...");
|
||||
|
||||
uint32 i;
|
||||
// Count duplicates.
|
||||
std::map<uint64, int> counts;
|
||||
std::map<uint64, int>::iterator cit;
|
||||
for (i = 0; i < m_rawSamples.size(); i++)
|
||||
{
|
||||
uint32 ip = (uint32)m_rawSamples[i];
|
||||
cit = counts.find(ip);
|
||||
if (cit != counts.end())
|
||||
{
|
||||
cit->second++;
|
||||
}
|
||||
else
|
||||
{
|
||||
counts[ip] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
std::map<string, int> funcCounts;
|
||||
|
||||
AZ::Debug::SymbolStorage::StackLine func, file, module;
|
||||
int line;
|
||||
void* baseAddr;
|
||||
string funcName;
|
||||
for (i = 0; i < m_rawSamples.size(); i++)
|
||||
{
|
||||
// lookup module name here, and aggregate the results
|
||||
AZ::Debug::SymbolStorage::FindFunctionFromIP((void*)m_rawSamples[i], &func, &file, &module, line, baseAddr);
|
||||
|
||||
// Developer note: this file was using the module name instead of the function name. There was stub code
|
||||
// to use the function name instead that. This function was updated to use FindFunctionFromIP(), but
|
||||
// continues to use the module instead of the function.
|
||||
funcName = module;
|
||||
funcCounts[funcName] += 1;
|
||||
}
|
||||
|
||||
{
|
||||
// Combine function samples.
|
||||
std::map<string, int>::iterator it;
|
||||
for (it = funcCounts.begin(); it != funcCounts.end(); ++it)
|
||||
{
|
||||
SFunctionSample fs;
|
||||
fs.function = it->first;
|
||||
fs.nSamples = it->second;
|
||||
m_functionSamples.push_back(fs);
|
||||
}
|
||||
}
|
||||
|
||||
// Sort vector by number of samples.
|
||||
std::sort(m_functionSamples.begin(), m_functionSamples.end(), CompareFunctionSamples);
|
||||
|
||||
LogSampledData();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CSampler::LogSampledData()
|
||||
{
|
||||
int nTotalSamples = m_rawSamples.size();
|
||||
|
||||
// Log sample info.
|
||||
CryLogAlways("=========================================================================");
|
||||
CryLogAlways("= Profiler Output");
|
||||
CryLogAlways("=========================================================================");
|
||||
|
||||
float fOnePercent = (float)nTotalSamples / 100;
|
||||
|
||||
float fPercentTotal = 0;
|
||||
int nSampleSum = 0;
|
||||
for (uint32 i = 0; i < m_functionSamples.size(); i++)
|
||||
{
|
||||
// Calculate percentage.
|
||||
float fPercent = m_functionSamples[i].nSamples / fOnePercent;
|
||||
const char* func = m_functionSamples[i].function;
|
||||
CryLogAlways("%6.2f%% (%4d samples) : %s", fPercent, m_functionSamples[i].nSamples, func);
|
||||
fPercentTotal += fPercent;
|
||||
nSampleSum += m_functionSamples[i].nSamples;
|
||||
}
|
||||
CryLogAlways("Samples: %d / %d (%.2f%%)", nSampleSum, nTotalSamples, fPercentTotal);
|
||||
CryLogAlways("=========================================================================");
|
||||
}
|
||||
|
||||
|
||||
#endif // defined(WIN32)
|
||||
@@ -1,82 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
#ifndef CRYINCLUDE_CRYSYSTEM_SAMPLER_H
|
||||
#define CRYINCLUDE_CRYSYSTEM_SAMPLER_H
|
||||
#pragma once
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
class CSamplingThread;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Sampler class is running a second thread which is at regular intervals
|
||||
// eg 1ms samples main thread and stores current IP in the samples buffers.
|
||||
// After sampling finishes it can resolve collected IP buffer info to
|
||||
// the function names and calculated where most of the execution time spent.
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
class CSampler
|
||||
{
|
||||
public:
|
||||
struct SFunctionSample
|
||||
{
|
||||
string function;
|
||||
uint32 nSamples; // Number of samples per function.
|
||||
};
|
||||
|
||||
CSampler();
|
||||
~CSampler();
|
||||
|
||||
void Start();
|
||||
void Stop();
|
||||
void Update();
|
||||
|
||||
// Adds a new sample to the ip buffer, return false if no more samples can be added.
|
||||
bool AddSample(uint64 ip);
|
||||
void SetMaxSamples(int nMaxSamples);
|
||||
|
||||
int GetSamplePeriod() const { return m_samplePeriodMs; }
|
||||
void SetSamplePeriod(int millis) { m_samplePeriodMs = millis; }
|
||||
|
||||
private:
|
||||
void ProcessSampledData();
|
||||
void LogSampledData();
|
||||
|
||||
// Buffer for IP samples.
|
||||
std::vector<uint64> m_rawSamples;
|
||||
std::vector<SFunctionSample> m_functionSamples;
|
||||
int m_nMaxSamples;
|
||||
bool m_bSampling;
|
||||
bool m_bSamplingFinished;
|
||||
|
||||
int m_samplePeriodMs;
|
||||
|
||||
CSamplingThread* m_pSamplingThread;
|
||||
};
|
||||
|
||||
#else //WIN32
|
||||
|
||||
// Dummy sampler.
|
||||
class CSampler
|
||||
{
|
||||
public:
|
||||
void Start() {}
|
||||
void Stop() {}
|
||||
void Update() {}
|
||||
void SetMaxSamples(int) {}
|
||||
void SetSamplePeriod(int) {}
|
||||
};
|
||||
|
||||
#endif // WIN32
|
||||
|
||||
#endif // CRYINCLUDE_CRYSYSTEM_SAMPLER_H
|
||||
@@ -1,85 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
#include "CrySystem_precompiled.h"
|
||||
|
||||
#include "ProjectDefines.h"
|
||||
#if defined(MAP_LOADING_SLICING)
|
||||
|
||||
#include "ServerHandler.h"
|
||||
|
||||
ServerHandler::ServerHandler(const char* bucket, int affinity, int serverTimeout)
|
||||
: HandlerBase(bucket, affinity)
|
||||
{
|
||||
m_serverTimeout = serverTimeout;
|
||||
DoScan();
|
||||
}
|
||||
|
||||
void ServerHandler::DoScan()
|
||||
{
|
||||
std::set<int> gotIndices;
|
||||
for (int i = 0; i < m_srvLocks.size(); ++i)
|
||||
{
|
||||
gotIndices.insert(m_srvLocks[i]->number);
|
||||
}
|
||||
for (int i = 0; i < MAX_CLIENTS_NUM; ++i)
|
||||
{
|
||||
if (gotIndices.find(i) == gotIndices.end())
|
||||
{
|
||||
std::unique_ptr<SSyncLock> lock(new SSyncLock(m_clientLockName, i, false));
|
||||
if (lock->IsValid())
|
||||
{
|
||||
std::unique_ptr<SSyncLock> srv(new SSyncLock(m_serverLockName, i, true));
|
||||
if (srv->IsValid())
|
||||
{
|
||||
m_srvLocks.push_back(std::move(srv));
|
||||
m_clientLocks.push_back(std::move(lock));
|
||||
CryLogAlways("Client %d bound", i);
|
||||
}
|
||||
else
|
||||
{
|
||||
CryLogAlways("Failed to bind client %d", i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!m_clientLocks.empty())
|
||||
{
|
||||
SetAffinity();
|
||||
}
|
||||
m_lastScan = gEnv->pTimer->GetAsyncTime();
|
||||
}
|
||||
|
||||
bool ServerHandler::Sync()
|
||||
{
|
||||
if ((gEnv->pTimer->GetAsyncTime() - m_lastScan).GetSeconds() > 1.0f)
|
||||
{
|
||||
DoScan();
|
||||
}
|
||||
for (int i = 0; i < m_srvLocks.size(); )
|
||||
{
|
||||
m_srvLocks[i]->Signal();
|
||||
if (!m_clientLocks[i]->Wait(m_serverTimeout))//actually if not waited, let's kill it!
|
||||
{
|
||||
CryLogAlways("Dropped client %d", m_clientLocks[i]->number);
|
||||
m_clientLocks[i]->Own(m_clientLockName);
|
||||
m_clientLocks.erase(m_clientLocks.begin() + i);
|
||||
m_srvLocks.erase(m_srvLocks.begin() + i);
|
||||
continue;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
return false;//!m_clientLocks.empty();
|
||||
}
|
||||
|
||||
#endif // defined(MAP_LOADING_SLICING)
|
||||
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
#ifndef CRYINCLUDE_CRYSYSTEM_SERVERHANDLER_H
|
||||
#define CRYINCLUDE_CRYSYSTEM_SERVERHANDLER_H
|
||||
#pragma once
|
||||
|
||||
#include "HandlerBase.h"
|
||||
#include "SyncLock.h"
|
||||
|
||||
struct ServerHandler
|
||||
: public HandlerBase
|
||||
{
|
||||
ServerHandler(const char* bucket, int affinity, int serverTimeout);
|
||||
|
||||
void DoScan();
|
||||
bool Sync();
|
||||
|
||||
private:
|
||||
int m_serverTimeout;
|
||||
std::vector<std::unique_ptr<SSyncLock> > m_clientLocks;
|
||||
std::vector<std::unique_ptr<SSyncLock> > m_srvLocks;
|
||||
CTimeValue m_lastScan;
|
||||
};
|
||||
|
||||
#endif // CRYINCLUDE_CRYSYSTEM_SERVERHANDLER_H
|
||||
@@ -1,164 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
#include "CrySystem_precompiled.h"
|
||||
#include "ServerThrottle.h"
|
||||
#include "TimeValue.h"
|
||||
#include "ISystem.h"
|
||||
#include "ITimer.h"
|
||||
#include "IConsole.h"
|
||||
|
||||
#if defined(WIN32)
|
||||
static float ftdiff(const FILETIME& b, const FILETIME& a)
|
||||
{
|
||||
uint64 aa = *reinterpret_cast<const uint64*>(&a);
|
||||
uint64 bb = *reinterpret_cast<const uint64*>(&b);
|
||||
return (bb - aa) * 1e-7f;
|
||||
}
|
||||
|
||||
class CCPUMonitor
|
||||
{
|
||||
public:
|
||||
CCPUMonitor(ISystem* pSystem, int nCPUs)
|
||||
: m_lastUpdate(0.0f)
|
||||
, m_pTimer(pSystem->GetITimer())
|
||||
, m_nCPUs(nCPUs)
|
||||
{
|
||||
FILETIME notNeeded;
|
||||
GetProcessTimes(GetCurrentProcess(), ¬Needed, ¬Needed, &m_lastKernel, &m_lastUser);
|
||||
}
|
||||
|
||||
float* Update()
|
||||
{
|
||||
CTimeValue frameTime = gEnv->pTimer->GetFrameStartTime();
|
||||
if (frameTime - m_lastUpdate > 5.0f)
|
||||
{
|
||||
m_lastUpdate = frameTime;
|
||||
|
||||
static float result = 0.0f;
|
||||
|
||||
FILETIME kernel, user, cur;
|
||||
FILETIME notNeeded;
|
||||
GetSystemTimeAsFileTime(&cur);
|
||||
GetProcessTimes(GetCurrentProcess(), ¬Needed, ¬Needed, &kernel, &user);
|
||||
|
||||
float sKernel = ftdiff(kernel, m_lastKernel);
|
||||
float sUser = ftdiff(user, m_lastUser);
|
||||
float sCur = ftdiff(cur, m_lastTime);
|
||||
|
||||
result = 100 * (sKernel + sUser) / sCur / m_nCPUs;
|
||||
|
||||
m_lastTime = cur;
|
||||
m_lastKernel = kernel;
|
||||
m_lastUser = user;
|
||||
|
||||
return &result;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private:
|
||||
ITimer* m_pTimer;
|
||||
CTimeValue m_lastUpdate;
|
||||
FILETIME m_lastKernel, m_lastUser, m_lastTime;
|
||||
int m_nCPUs;
|
||||
};
|
||||
#else
|
||||
class CCPUMonitor
|
||||
{
|
||||
public:
|
||||
CCPUMonitor(ISystem*, int) {}
|
||||
|
||||
float* Update() { return 0; }
|
||||
};
|
||||
#endif
|
||||
|
||||
CServerThrottle::CServerThrottle(ISystem* pSys, int nCPUs)
|
||||
{
|
||||
m_pCPUMonitor.reset(new CCPUMonitor(pSys, nCPUs));
|
||||
m_pDedicatedMaxRate = pSys->GetIConsole()->GetCVar("sv_DedicatedMaxRate");
|
||||
m_pDedicatedCPU = pSys->GetIConsole()->GetCVar("sv_DedicatedCPUPercent");
|
||||
m_pDedicatedCPUVariance = pSys->GetIConsole()->GetCVar("sv_DedicatedCPUVariance");
|
||||
|
||||
m_minFPS = 20;
|
||||
m_maxFPS = 60;
|
||||
m_nSteps = 8;
|
||||
m_nCurStep = 0;
|
||||
|
||||
if (m_pDedicatedCPU->GetFVal() >= 1.0f)
|
||||
{
|
||||
SetStep(m_nSteps / 2, 0);
|
||||
}
|
||||
}
|
||||
|
||||
CServerThrottle::~CServerThrottle()
|
||||
{
|
||||
}
|
||||
|
||||
void CServerThrottle::Update()
|
||||
{
|
||||
float tgtCPU = m_pDedicatedCPU->GetFVal();
|
||||
if (tgtCPU < 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (float* pCPU = m_pCPUMonitor->Update())
|
||||
{
|
||||
float varCPU = m_pDedicatedCPUVariance->GetFVal();
|
||||
if (tgtCPU < 5)
|
||||
{
|
||||
tgtCPU = 5;
|
||||
}
|
||||
else if (tgtCPU > 95)
|
||||
{
|
||||
tgtCPU = 95;
|
||||
}
|
||||
float minCPU = std::max(tgtCPU - varCPU, tgtCPU / 2.0f);
|
||||
float maxCPU = std::min(tgtCPU + varCPU, (100.0f + tgtCPU) / 2.0f);
|
||||
|
||||
if (*pCPU > maxCPU)
|
||||
{
|
||||
SetStep(m_nCurStep - 1, pCPU);
|
||||
}
|
||||
else if (*pCPU < minCPU)
|
||||
{
|
||||
SetStep(m_nCurStep + 1, pCPU);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CServerThrottle::SetStep(int step, float* pDueToCPU)
|
||||
{
|
||||
if (step < 0)
|
||||
{
|
||||
step = 0;
|
||||
}
|
||||
else if (step > m_nSteps)
|
||||
{
|
||||
step = m_nSteps;
|
||||
}
|
||||
if (step != m_nCurStep)
|
||||
{
|
||||
float fps = step * (m_maxFPS - m_minFPS) / m_nSteps + m_minFPS;
|
||||
m_pDedicatedMaxRate->Set(fps);
|
||||
if (pDueToCPU)
|
||||
{
|
||||
CryLog("ServerThrottle: Set framerate to %.1f fps [due to cpu being %d%%]", fps, int(*pDueToCPU + 0.5f));
|
||||
}
|
||||
else
|
||||
{
|
||||
CryLog("ServerThrottle: Set framerate to %.1f fps", fps);
|
||||
}
|
||||
m_nCurStep = step;
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
// Description : Handle raising/lowering the frame rate on server
|
||||
// based upon CPU usage
|
||||
|
||||
|
||||
#ifndef CRYINCLUDE_CRYSYSTEM_SERVERTHROTTLE_H
|
||||
#define CRYINCLUDE_CRYSYSTEM_SERVERTHROTTLE_H
|
||||
#pragma once
|
||||
|
||||
|
||||
struct ISystem;
|
||||
|
||||
class CCPUMonitor;
|
||||
|
||||
class CServerThrottle
|
||||
{
|
||||
public:
|
||||
CServerThrottle(ISystem* pSys, int nCPUs);
|
||||
~CServerThrottle();
|
||||
void Update();
|
||||
|
||||
private:
|
||||
std::unique_ptr<CCPUMonitor> m_pCPUMonitor;
|
||||
|
||||
void SetStep(int step, float* dueToCPU);
|
||||
|
||||
float m_minFPS;
|
||||
float m_maxFPS;
|
||||
int m_nSteps;
|
||||
int m_nCurStep;
|
||||
ICVar* m_pDedicatedMaxRate;
|
||||
ICVar* m_pDedicatedCPU;
|
||||
ICVar* m_pDedicatedCPUVariance;
|
||||
};
|
||||
|
||||
#endif // CRYINCLUDE_CRYSYSTEM_SERVERTHROTTLE_H
|
||||
@@ -1,246 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
#include "CrySystem_precompiled.h"
|
||||
|
||||
#include "ProjectDefines.h"
|
||||
#if defined(MAP_LOADING_SLICING)
|
||||
|
||||
#include "SyncLock.h"
|
||||
|
||||
SSyncLock::SSyncLock(const char* name, int id, bool own)
|
||||
{
|
||||
stack_string ss;
|
||||
ss.Format("%s_%d", name, id);
|
||||
|
||||
Open(ss);
|
||||
if (own)
|
||||
{
|
||||
if (!IsValid())
|
||||
{
|
||||
Create(ss);
|
||||
number = id;
|
||||
}
|
||||
else
|
||||
{
|
||||
Close();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
number = id;
|
||||
}
|
||||
}
|
||||
|
||||
SSyncLock::SSyncLock(const char* name, int minId, int maxId)
|
||||
{
|
||||
ev = 0;
|
||||
stack_string ss;
|
||||
for (int i = minId; i < maxId; ++i)
|
||||
{
|
||||
ss.Format("%s_%d", name, i);
|
||||
if (Open(ss))
|
||||
{
|
||||
Close();
|
||||
continue;
|
||||
}
|
||||
if (Create(ss))
|
||||
{
|
||||
number = i;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
SSyncLock::~SSyncLock()
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
void SSyncLock::Own(const char* name)
|
||||
{
|
||||
o_name.Format("%s_%d", name, number);
|
||||
}
|
||||
|
||||
#if defined(LINUX) || defined(APPLE)
|
||||
|
||||
bool SSyncLock::Open(const char* name)
|
||||
{
|
||||
ev = sem_open(name, 0);
|
||||
if (ev != SEM_FAILED)
|
||||
{
|
||||
CryLogAlways("Opened semaphore %p %s", ev, name);
|
||||
}
|
||||
return IsValid();
|
||||
}
|
||||
|
||||
bool SSyncLock::Create(const char* name)
|
||||
{
|
||||
ev = sem_open(name, O_CREAT | O_EXCL, 0777, 0);
|
||||
if (ev != SEM_FAILED)
|
||||
{
|
||||
CryLogAlways("Created semaphore %p %s", ev, name);
|
||||
}
|
||||
else
|
||||
{
|
||||
CryLogAlways("Failed to create semaphore %s %d", name, errno);
|
||||
}
|
||||
return IsValid();
|
||||
}
|
||||
|
||||
void SSyncLock::Signal()
|
||||
{
|
||||
if (ev)
|
||||
{
|
||||
sem_post(ev);
|
||||
}
|
||||
}
|
||||
|
||||
bool SSyncLock::Wait(int ms)
|
||||
{
|
||||
if (!ev)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
timespec t = { 0 };
|
||||
#if defined(LINUX)
|
||||
clock_gettime(CLOCK_REALTIME, &t);
|
||||
#elif defined(APPLE)
|
||||
// On OSX/iOS there is no sem_timedwait()
|
||||
// We use repeated sem_trywait() instead
|
||||
if (sem_trywait(ev) == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
static const long NANOSECS_IN_MSEC = 1000000L;
|
||||
static const long NANOSECS_IN_SEC = 1000000000L;
|
||||
|
||||
t.tv_sec += ms / 1000;
|
||||
t.tv_nsec += (ms % 1000) * NANOSECS_IN_MSEC;
|
||||
if (t.tv_nsec > NANOSECS_IN_SEC)
|
||||
{
|
||||
t.tv_nsec -= NANOSECS_IN_SEC;
|
||||
++t.tv_sec;
|
||||
}
|
||||
#if defined(LINUX)
|
||||
return sem_timedwait(ev, &t) == 0; //ETIMEDOUT for timeout
|
||||
#elif defined (APPLE)
|
||||
// t = time left, interval = max time between tries, elapsed = actual time elapsed during a try
|
||||
const int num_ms_interval = 50; // poll time, in ms
|
||||
const timespec interval = { 0, NANOSECS_IN_MSEC * num_ms_interval };
|
||||
while (t.tv_sec >= 0 || t.tv_nsec > interval.tv_nsec)
|
||||
{
|
||||
timespec remaining;
|
||||
timespec elapsed = interval;
|
||||
if (nanosleep(&interval, &remaining) == -1)
|
||||
{
|
||||
elapsed.tv_nsec -= remaining.tv_nsec;
|
||||
}
|
||||
t.tv_nsec -= elapsed.tv_nsec;
|
||||
if (t.tv_nsec < 0L)
|
||||
{
|
||||
t.tv_nsec += NANOSECS_IN_SEC;
|
||||
t.tv_sec -= 1;
|
||||
}
|
||||
if (sem_trywait(ev) == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
nanosleep(&t, NULL);
|
||||
return sem_trywait(ev) == 0;
|
||||
#else
|
||||
#error Not implemented
|
||||
#endif
|
||||
}
|
||||
|
||||
void SSyncLock::Close()
|
||||
{
|
||||
if (ev)
|
||||
{
|
||||
sem_close(ev);
|
||||
ev = nullptr;
|
||||
if (!o_name.empty())
|
||||
{
|
||||
sem_unlink(o_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#else // defined(LINUX) || defined(APPLE)
|
||||
|
||||
bool SSyncLock::Open(const char* name)
|
||||
{
|
||||
ev = OpenEvent(SYNCHRONIZE, FALSE, name);
|
||||
if (ev)
|
||||
{
|
||||
CryLogAlways("Opened event %p %s", ev, name);
|
||||
}
|
||||
return IsValid();
|
||||
}
|
||||
|
||||
bool SSyncLock::Create(const char* name)
|
||||
{
|
||||
ev = CreateEvent(NULL, FALSE, FALSE, name);
|
||||
if (ev)
|
||||
{
|
||||
CryLogAlways("Created event %p %s", ev, name);
|
||||
}
|
||||
else
|
||||
{
|
||||
CryLogAlways("Failed to create event %s", name);
|
||||
}
|
||||
return IsValid();
|
||||
}
|
||||
|
||||
bool SSyncLock::Wait(int ms)
|
||||
{
|
||||
// CryLogAlways("Waiting %p", ev);
|
||||
DWORD res = WaitForSingleObject(ev, ms);
|
||||
if (res != WAIT_OBJECT_0)
|
||||
{
|
||||
CryLogAlways("WFS result %d", res);
|
||||
}
|
||||
return res == WAIT_OBJECT_0;
|
||||
}
|
||||
|
||||
void SSyncLock::Signal()
|
||||
{
|
||||
//CryLogAlways("Signaled %p", ev);
|
||||
if (!SetEvent(ev))
|
||||
{
|
||||
CryLogAlways("Error signalling!");
|
||||
}
|
||||
}
|
||||
|
||||
void SSyncLock::Close()
|
||||
{
|
||||
if (ev)
|
||||
{
|
||||
CryLogAlways("Closed event %p", ev);
|
||||
CloseHandle(ev);
|
||||
ev = 0;
|
||||
}
|
||||
}
|
||||
|
||||
#endif // defined(LINUX) || defined(APPLE)
|
||||
|
||||
bool SSyncLock::IsValid() const
|
||||
{
|
||||
return ev != 0;
|
||||
}
|
||||
|
||||
#endif // defined(MAP_LOADING_SLICING)
|
||||
@@ -1,48 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
#ifndef CRYINCLUDE_CRYSYSTEM_SYNCLOCK_H
|
||||
#define CRYINCLUDE_CRYSYSTEM_SYNCLOCK_H
|
||||
|
||||
#pragma once
|
||||
|
||||
#if defined(LINUX) || defined(APPLE)
|
||||
#include <semaphore.h>
|
||||
#endif
|
||||
|
||||
struct SSyncLock
|
||||
{
|
||||
#if defined(LINUX) || defined(APPLE)
|
||||
typedef sem_t* HandleType;
|
||||
#else
|
||||
typedef HANDLE HandleType;
|
||||
#endif
|
||||
|
||||
SSyncLock(const char* name, int id, bool own);
|
||||
SSyncLock(const char* name, int minId, int maxId);
|
||||
~SSyncLock();
|
||||
|
||||
void Own(const char* name);
|
||||
bool Open(const char* name);
|
||||
bool Create(const char* name);
|
||||
void Signal();
|
||||
bool Wait(int ms);
|
||||
void Close();
|
||||
bool IsValid() const;
|
||||
|
||||
HandleType ev;
|
||||
int number;
|
||||
string o_name;
|
||||
};
|
||||
|
||||
#endif // CRYINCLUDE_CRYSYSTEM_SYNCLOCK_H
|
||||
@@ -135,25 +135,16 @@ LRESULT WINAPI WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||
#include "XML/xml.h"
|
||||
#include "XML/ReadWriteXMLSink.h"
|
||||
|
||||
#include "PhysRenderer.h"
|
||||
|
||||
#include "LocalizedStringManager.h"
|
||||
#include "XML/XmlUtils.h"
|
||||
#include "SystemEventDispatcher.h"
|
||||
#include "ServerThrottle.h"
|
||||
#include "HMDBus.h"
|
||||
|
||||
#include "IZLibCompressor.h"
|
||||
#include "IZlibDecompressor.h"
|
||||
#include "ILZ4Decompressor.h"
|
||||
#include "IZStdDecompressor.h"
|
||||
#include "zlib.h"
|
||||
#include "RemoteConsole/RemoteConsole.h"
|
||||
|
||||
#include <PNoise3.h>
|
||||
#include <StringUtils.h>
|
||||
#include "CryWaterMark.h"
|
||||
WATERMARKDATA(_m);
|
||||
|
||||
#include <LyShine/Bus/UiCursorBus.h>
|
||||
#include <AzFramework/Asset/AssetSystemBus.h>
|
||||
@@ -170,10 +161,6 @@ WATERMARKDATA(_m);
|
||||
#include <malloc.h>
|
||||
#endif
|
||||
|
||||
#if USE_STEAM
|
||||
#include "Steamworks/public/steam/steam_api.h"
|
||||
#endif
|
||||
|
||||
#include <ILevelSystem.h>
|
||||
|
||||
#include <AzFramework/IO/LocalFileIO.h>
|
||||
@@ -185,11 +172,6 @@ VTuneFunction VTPause = NULL;
|
||||
// Define global cvars.
|
||||
SSystemCVars g_cvars;
|
||||
|
||||
#include "ITextModeConsole.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
#include "Validator.h"
|
||||
|
||||
#include <IViewSystem.h>
|
||||
|
||||
#include <AzCore/Module/Environment.h>
|
||||
@@ -308,16 +290,9 @@ CSystem::CSystem(SharedEnvironmentInstance* pSharedEnvironment)
|
||||
m_rFullscreen = NULL;
|
||||
m_sysNoUpdate = NULL;
|
||||
m_pProcess = NULL;
|
||||
|
||||
m_pValidator = NULL;
|
||||
m_pCmdLine = NULL;
|
||||
m_pDefaultValidator = NULL;
|
||||
m_pLevelSystem = NULL;
|
||||
m_pViewSystem = NULL;
|
||||
m_pIZLibCompressor = NULL;
|
||||
m_pIZLibDecompressor = NULL;
|
||||
m_pILZ4Decompressor = NULL;
|
||||
m_pIZStdDecompressor = nullptr;
|
||||
m_pLocalizationManager = NULL;
|
||||
#if defined(AZ_RESTRICTED_PLATFORM)
|
||||
#define AZ_RESTRICTED_SECTION SYSTEM_CPP_SECTION_2
|
||||
@@ -332,14 +307,12 @@ CSystem::CSystem(SharedEnvironmentInstance* pSharedEnvironment)
|
||||
m_sys_memory_debug = NULL;
|
||||
m_sysWarnings = NULL;
|
||||
m_sysKeyboard = NULL;
|
||||
m_sys_GraphicsQuality = NULL;
|
||||
m_sys_firstlaunch = NULL;
|
||||
m_sys_enable_budgetmonitoring = NULL;
|
||||
m_sys_preload = NULL;
|
||||
|
||||
// m_sys_filecache = NULL;
|
||||
m_gpu_particle_physics = NULL;
|
||||
m_pCpu = NULL;
|
||||
|
||||
m_bInitializedSuccessfully = false;
|
||||
m_bRelaunch = false;
|
||||
@@ -371,7 +344,6 @@ CSystem::CSystem(SharedEnvironmentInstance* pSharedEnvironment)
|
||||
|
||||
|
||||
m_pXMLUtils = new CXmlUtils(this);
|
||||
m_pTextModeConsole = NULL;
|
||||
|
||||
if (!AZ::AllocatorInstance<AZ::OSAllocator>::IsReady())
|
||||
{
|
||||
@@ -390,7 +362,6 @@ CSystem::CSystem(SharedEnvironmentInstance* pSharedEnvironment)
|
||||
m_eRuntimeState = ESYSTEM_EVENT_LEVEL_UNLOAD;
|
||||
|
||||
m_bHasRenderedErrorMessage = false;
|
||||
m_bIsSteamInitialized = false;
|
||||
|
||||
m_pDataProbe = nullptr;
|
||||
#if AZ_LEGACY_CRYSYSTEM_TRAIT_USE_MESSAGE_HANDLER
|
||||
@@ -509,14 +480,6 @@ void CSystem::ShutDown()
|
||||
GetIRemoteConsole()->Stop();
|
||||
}
|
||||
|
||||
// clean up properly the console
|
||||
if (m_pTextModeConsole)
|
||||
{
|
||||
m_pTextModeConsole->OnShutdown();
|
||||
}
|
||||
|
||||
SAFE_DELETE(m_pTextModeConsole);
|
||||
|
||||
if (m_sys_firstlaunch)
|
||||
{
|
||||
m_sys_firstlaunch->Set("0");
|
||||
@@ -566,10 +529,6 @@ void CSystem::ShutDown()
|
||||
{
|
||||
((CXConsole*)m_env.pConsole)->FreeRenderResources();
|
||||
}
|
||||
SAFE_RELEASE(m_pIZLibCompressor);
|
||||
SAFE_RELEASE(m_pIZLibDecompressor);
|
||||
SAFE_RELEASE(m_pILZ4Decompressor);
|
||||
SAFE_RELEASE(m_pIZStdDecompressor);
|
||||
SAFE_RELEASE(m_pViewSystem);
|
||||
SAFE_RELEASE(m_pLevelSystem);
|
||||
|
||||
@@ -596,7 +555,6 @@ void CSystem::ShutDown()
|
||||
|
||||
SAFE_RELEASE(m_sysWarnings);
|
||||
SAFE_RELEASE(m_sysKeyboard);
|
||||
SAFE_RELEASE(m_sys_GraphicsQuality);
|
||||
SAFE_RELEASE(m_sys_firstlaunch);
|
||||
SAFE_RELEASE(m_sys_enable_budgetmonitoring);
|
||||
|
||||
@@ -608,13 +566,8 @@ void CSystem::ShutDown()
|
||||
SAFE_RELEASE(m_sys_min_step);
|
||||
SAFE_RELEASE(m_sys_max_step);
|
||||
|
||||
SAFE_DELETE(m_pDefaultValidator);
|
||||
m_pValidator = nullptr;
|
||||
|
||||
SAFE_DELETE(m_pLocalizationManager);
|
||||
|
||||
SAFE_DELETE(m_pCpu);
|
||||
|
||||
delete m_pCmdLine;
|
||||
m_pCmdLine = 0;
|
||||
|
||||
@@ -941,13 +894,6 @@ bool CSystem::UpdatePreTickBus(int updateFlags, int nPauseMode)
|
||||
//update time subsystem
|
||||
m_Time.UpdateOnFrameStart();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// update rate limiter for dedicated server
|
||||
if (m_pServerThrottle.get())
|
||||
{
|
||||
m_pServerThrottle->Update();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//update console system
|
||||
if (m_env.pConsole)
|
||||
@@ -1277,21 +1223,6 @@ void CSystem::WarningV(EValidatorModule module, EValidatorSeverity severity, int
|
||||
m_env.pLog->LogWithType(ltype, flags | VALIDATOR_FLAG_SKIP_VALIDATOR, "%s", szBuffer);
|
||||
}
|
||||
|
||||
//if(file)
|
||||
//m_env.pLog->LogWithType( ltype, " ... caused by file '%s'",file);
|
||||
|
||||
if (m_pValidator && (flags & VALIDATOR_FLAG_SKIP_VALIDATOR) == 0)
|
||||
{
|
||||
SValidatorRecord record;
|
||||
record.file = file;
|
||||
record.text = szBuffer;
|
||||
record.module = module;
|
||||
record.severity = severity;
|
||||
record.flags = flags;
|
||||
record.assetScope = m_env.pLog->GetAssetScopeString();
|
||||
m_pValidator->Report(record);
|
||||
}
|
||||
|
||||
if (bDbgBreak && g_cvars.sys_error_debugbreak)
|
||||
{
|
||||
AZ::Debug::Trace::Break();
|
||||
@@ -1412,12 +1343,6 @@ void CSystem::ExecuteCommandLine(bool deferred)
|
||||
|
||||
m_executedCommandLine = true;
|
||||
|
||||
// auto detect system spec (overrides profile settings)
|
||||
if (m_pCmdLine->FindArg(eCLAT_Pre, "autodetect"))
|
||||
{
|
||||
AutoDetectSpec(false);
|
||||
}
|
||||
|
||||
// execute command line arguments e.g. +g_gametype ASSAULT +map "testy"
|
||||
|
||||
ICmdLine* pCmdLine = GetICmdLine();
|
||||
@@ -1446,50 +1371,6 @@ void CSystem::ExecuteCommandLine(bool deferred)
|
||||
//gEnv->pConsole->ExecuteString("sys_RestoreSpec test*"); // to get useful debugging information about current spec settings to the log file
|
||||
}
|
||||
|
||||
ITextModeConsole* CSystem::GetITextModeConsole()
|
||||
{
|
||||
if (m_bDedicatedServer)
|
||||
{
|
||||
return m_pTextModeConsole;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
ESystemConfigSpec CSystem::GetConfigSpec(bool bClient)
|
||||
{
|
||||
if (bClient)
|
||||
{
|
||||
if (m_sys_GraphicsQuality)
|
||||
{
|
||||
return (ESystemConfigSpec)m_sys_GraphicsQuality->GetIVal();
|
||||
}
|
||||
return CONFIG_VERYHIGH_SPEC; // highest spec.
|
||||
}
|
||||
else
|
||||
{
|
||||
return m_nServerConfigSpec;
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CSystem::SetConfigSpec(ESystemConfigSpec spec, ESystemConfigPlatform platform, bool bClient)
|
||||
{
|
||||
if (bClient)
|
||||
{
|
||||
if (m_sys_GraphicsQuality)
|
||||
{
|
||||
SetConfigPlatform(platform);
|
||||
m_sys_GraphicsQuality->Set(static_cast<int>(spec));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_nServerConfigSpec = spec;
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
ESystemConfigSpec CSystem::GetMaxConfigSpec() const
|
||||
{
|
||||
@@ -1539,49 +1420,6 @@ void CProfilingSystem::VTunePause()
|
||||
#endif
|
||||
}
|
||||
|
||||
bool CSystem::SteamInit()
|
||||
{
|
||||
#if USE_STEAM
|
||||
if (m_bIsSteamInitialized)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
AZStd::string_view exePath;
|
||||
AZ::ComponentApplicationBus::BroadcastResult(exePath, &AZ::ComponentApplicationRequests::GetExecutableFolder);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// ** DEVELOPMENT ONLY ** - creates the appropriate steam_appid.txt file needed to call SteamAPI_Init()
|
||||
#if !defined(RELEASE)
|
||||
AZStd::string appidPath = AZStd::string::format("%.*s/steam_appid.txt", aznumeric_cast<int>(exePath.size()), exePath.data());
|
||||
azfopen(&pSteamAppID, appidPath.c_str(), "wt");
|
||||
fprintf(pSteamAppID, "%d", g_cvars.sys_steamAppId);
|
||||
fclose(pSteamAppID);
|
||||
#endif // !defined(RELEASE)
|
||||
// ** END DEVELOPMENT ONLY **
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
if (!SteamAPI_Init())
|
||||
{
|
||||
CryLog("[STEAM] SteamApi_Init failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// ** DEVELOPMENT ONLY ** - deletes the appropriate steam_appid.txt file as it's no longer needed
|
||||
#if !defined(RELEASE)
|
||||
remove(appidPath.c_str());
|
||||
#endif // !defined(RELEASE)
|
||||
// ** END DEVELOPMENT ONLY **
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
m_bIsSteamInitialized = true;
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
void CSystem::OnLanguageCVarChanged(ICVar* language)
|
||||
{
|
||||
|
||||
@@ -23,12 +23,10 @@
|
||||
#include "CmdLine.h"
|
||||
#include "CryName.h"
|
||||
|
||||
#include "CPUDetect.h"
|
||||
#include <AzFramework/Archive/ArchiveVars.h>
|
||||
#include "RenderBus.h"
|
||||
|
||||
#include <LoadScreenBus.h>
|
||||
#include <ThermalInfo.h>
|
||||
|
||||
#include <AzCore/Module/DynamicModuleHandle.h>
|
||||
|
||||
@@ -38,8 +36,6 @@ namespace AzFramework
|
||||
}
|
||||
|
||||
struct IConsoleCmdArgs;
|
||||
class CServerThrottle;
|
||||
struct IZLibCompressor;
|
||||
class CWatchdogThread;
|
||||
|
||||
#if defined(AZ_RESTRICTED_PLATFORM)
|
||||
@@ -50,18 +46,6 @@ class CWatchdogThread;
|
||||
#define SYSTEM_H_SECTION_4 4
|
||||
#endif
|
||||
|
||||
#if defined(ANDROID)
|
||||
#define USE_ANDROIDCONSOLE
|
||||
#elif defined(MAC) // || defined(LINUX)
|
||||
#define USE_UNIXCONSOLE
|
||||
#elif defined(IOS)
|
||||
#define USE_IOSCONSOLE
|
||||
#elif defined(WIN32) || defined(WIN64)
|
||||
#define USE_WINDOWSCONSOLE
|
||||
#else
|
||||
#define USE_NULLCONSOLE
|
||||
#endif
|
||||
|
||||
#if defined(AZ_RESTRICTED_PLATFORM)
|
||||
#define AZ_RESTRICTED_SECTION SYSTEM_H_SECTION_1
|
||||
#include AZ_RESTRICTED_FILE(System_h)
|
||||
@@ -185,20 +169,12 @@ typedef void* WIN_HMODULE;
|
||||
typedef void* WIN_HMODULE;
|
||||
#endif
|
||||
|
||||
#if !defined(CRY_ASYNC_MEMCPY_DELEGATE_TO_CRYSYSTEM)
|
||||
CRY_ASYNC_MEMCPY_API void cryAsyncMemcpy(void* dst, const void* src, size_t size, int nFlags, volatile int* sync);
|
||||
#else
|
||||
CRY_ASYNC_MEMCPY_API void cryAsyncMemcpyDelegate(void* dst, const void* src, size_t size, int nFlags, volatile int* sync);
|
||||
#endif
|
||||
|
||||
|
||||
//forward declarations
|
||||
namespace Audio
|
||||
{
|
||||
struct IAudioSystem;
|
||||
struct IMusicSystem;
|
||||
} // namespace Audio
|
||||
struct SDefaultValidator;
|
||||
struct IDataProbe;
|
||||
|
||||
#define PHSYICS_OBJECT_ENTITY 0
|
||||
@@ -232,7 +208,6 @@ struct SSystemCVars
|
||||
int sys_no_crash_dialog;
|
||||
int sys_no_error_report_window;
|
||||
int sys_dump_aux_threads;
|
||||
int sys_WER;
|
||||
int sys_dump_type;
|
||||
int sys_ai;
|
||||
int sys_entitysystem;
|
||||
@@ -255,12 +230,6 @@ struct SSystemCVars
|
||||
int sys_FilesystemCaseSensitivity;
|
||||
|
||||
int sys_deferAudioUpdateOptim;
|
||||
#if USE_STEAM
|
||||
#ifndef RELEASE
|
||||
int sys_steamAppId;
|
||||
#endif // RELEASE
|
||||
int sys_useSteamCloudForPlatformSaving;
|
||||
#endif // USE_STEAM
|
||||
|
||||
AZ::IO::ArchiveVars archiveVars;
|
||||
|
||||
@@ -343,16 +312,11 @@ public:
|
||||
virtual void DoWorkDuringOcclusionChecks();
|
||||
virtual bool NeedDoWorkDuringOcclusionChecks() { return m_bNeedDoWorkDuringOcclusionChecks; }
|
||||
|
||||
//Called when the renderer finishes rendering the scene
|
||||
void OnScene3DEnd() override;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// CrySystemRequestBus interface implementation
|
||||
ISystem* GetCrySystem() override;
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
virtual bool SteamInit();
|
||||
|
||||
void Relaunch(bool bRelaunch);
|
||||
bool IsRelaunch() const { return m_bRelaunch; };
|
||||
|
||||
@@ -374,17 +338,11 @@ public:
|
||||
ICryFont* GetICryFont(){ return m_env.pCryFont; }
|
||||
ILog* GetILog(){ return m_env.pLog; }
|
||||
ICmdLine* GetICmdLine(){ return m_pCmdLine; }
|
||||
IValidator* GetIValidator() { return m_pValidator; };
|
||||
INameTable* GetINameTable() { return m_env.pNameTable; };
|
||||
IViewSystem* GetIViewSystem();
|
||||
ILevelSystem* GetILevelSystem();
|
||||
ISystemEventDispatcher* GetISystemEventDispatcher() { return m_pSystemEventDispatcher; }
|
||||
ITextModeConsole* GetITextModeConsole();
|
||||
IProfilingSystem* GetIProfilingSystem() { return &m_ProfilingSystem; }
|
||||
IZLibCompressor* GetIZLibCompressor() { return m_pIZLibCompressor; }
|
||||
IZLibDecompressor* GetIZLibDecompressor() { return m_pIZLibDecompressor; }
|
||||
ILZ4Decompressor* GetLZ4Decompressor() { return m_pILZ4Decompressor; }
|
||||
IZStdDecompressor* GetZStdDecompressor() { return m_pIZStdDecompressor; }
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// retrieves the perlin noise singleton instance
|
||||
CPNoise3* GetNoiseGen();
|
||||
@@ -406,45 +364,6 @@ public:
|
||||
void SetViewCamera(CCamera& Camera){ m_ViewCamera = Camera; }
|
||||
CCamera& GetViewCamera() { return m_ViewCamera; }
|
||||
|
||||
virtual int GetCPUFlags()
|
||||
{
|
||||
int Flags = 0;
|
||||
if (!m_pCpu)
|
||||
{
|
||||
return Flags;
|
||||
}
|
||||
if (m_pCpu->hasMMX())
|
||||
{
|
||||
Flags |= CPUF_MMX;
|
||||
}
|
||||
if (m_pCpu->hasSSE())
|
||||
{
|
||||
Flags |= CPUF_SSE;
|
||||
}
|
||||
if (m_pCpu->hasSSE2())
|
||||
{
|
||||
Flags |= CPUF_SSE2;
|
||||
}
|
||||
if (m_pCpu->has3DNow())
|
||||
{
|
||||
Flags |= CPUF_3DNOW;
|
||||
}
|
||||
if (m_pCpu->hasF16C())
|
||||
{
|
||||
Flags |= CPUF_F16C;
|
||||
}
|
||||
|
||||
return Flags;
|
||||
}
|
||||
virtual int GetLogicalCPUCount()
|
||||
{
|
||||
if (m_pCpu)
|
||||
{
|
||||
return m_pCpu->GetLogicalCPUCount();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void IgnoreUpdates(bool bIgnore) { m_bIgnoreUpdates = bIgnore; };
|
||||
|
||||
void SetIProcess(IProcess* process);
|
||||
@@ -455,8 +374,6 @@ public:
|
||||
|
||||
void SleepIfNeeded();
|
||||
|
||||
virtual void DisplayErrorMessage(const char* acMessage, float fTime, const float* pfColor = 0, bool bHardError = true);
|
||||
|
||||
virtual void FatalError(const char* format, ...) PRINTF_PARAMS(2, 3);
|
||||
virtual void ReportBug(const char* format, ...) PRINTF_PARAMS(2, 3);
|
||||
// Validator Warning.
|
||||
@@ -471,8 +388,6 @@ public:
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
virtual void SaveConfiguration();
|
||||
virtual void LoadConfiguration(const char* sFilename, ILoadConfigurationEntrySink* pSink = 0, bool warnIfMissing = true);
|
||||
virtual ESystemConfigSpec GetConfigSpec(bool bClient = true);
|
||||
virtual void SetConfigSpec(ESystemConfigSpec spec, ESystemConfigPlatform platform, bool bClient);
|
||||
virtual ESystemConfigSpec GetMaxConfigSpec() const;
|
||||
virtual ESystemConfigPlatform GetConfigPlatform() const;
|
||||
virtual void SetConfigPlatform(ESystemConfigPlatform platform);
|
||||
@@ -567,24 +482,7 @@ public:
|
||||
virtual bool GetForceNonDevMode() const;
|
||||
virtual bool WasInDevMode() const { return m_bWasInDevMode; };
|
||||
virtual bool IsDevMode() const { return m_bInDevMode && !GetForceNonDevMode(); }
|
||||
virtual bool IsMODValid(const char* szMODName) const
|
||||
{
|
||||
if (!szMODName || strstr(szMODName, ".") || strstr(szMODName, "\\"))
|
||||
{
|
||||
return (false);
|
||||
}
|
||||
return (true);
|
||||
}
|
||||
virtual void AutoDetectSpec(bool detectResolution);
|
||||
|
||||
virtual void AsyncMemcpy(void* dst, const void* src, size_t size, int nFlags, volatile int* sync)
|
||||
{
|
||||
#if !defined(CRY_ASYNC_MEMCPY_DELEGATE_TO_CRYSYSTEM)
|
||||
cryAsyncMemcpy(dst, src, size, nFlags, sync);
|
||||
#else
|
||||
cryAsyncMemcpyDelegate(dst, src, size, nFlags, sync);
|
||||
#endif
|
||||
}
|
||||
virtual void SetConsoleDrawEnabled(bool enabled) { m_bDrawConsole = enabled; }
|
||||
virtual void SetUIDrawEnabled(bool enabled) { m_bDrawUI = enabled; }
|
||||
|
||||
@@ -594,18 +492,11 @@ public:
|
||||
//! recreates the variable if necessary
|
||||
ICVar* attachVariable (const char* szVarName, int* pContainer, const char* szComment, int dwFlags = 0);
|
||||
|
||||
CCpuFeatures* GetCPUFeatures() { return m_pCpu; };
|
||||
|
||||
const CTimeValue& GetLastTickTime(void) const { return m_lastTickTime; }
|
||||
const ICVar* GetDedicatedMaxRate(void) const { return m_svDedicatedMaxRate; }
|
||||
|
||||
std::shared_ptr<AZ::IO::FileIOBase> CreateLocalFileIO();
|
||||
|
||||
// Gets the dimensions (in pixels) of the primary physical display.
|
||||
// Returns true if this info is available, returns false otherwise.
|
||||
bool GetPrimaryPhysicalDisplayDimensions(int& o_widthPixels, int& o_heightPixels);
|
||||
bool IsTablet();
|
||||
|
||||
private: // ------------------------------------------------------
|
||||
|
||||
// System environment.
|
||||
@@ -623,13 +514,10 @@ private: // ------------------------------------------------------
|
||||
bool m_bPreviewMode; //!< If running in Preview mode.
|
||||
bool m_bDedicatedServer; //!< If running as Dedicated server.
|
||||
bool m_bIgnoreUpdates; //!< When set to true will ignore Update and Render calls,
|
||||
IValidator* m_pValidator; //!< Pointer to validator interface.
|
||||
bool m_bForceNonDevMode; //!< true when running on a cheat protected server or a client that is connected to it (not used in singlplayer)
|
||||
bool m_bWasInDevMode; //!< Set to true if was in dev mode.
|
||||
bool m_bInDevMode; //!< Set to true if was in dev mode.
|
||||
bool m_bGameFolderWritable;//!< True when verified that current game folder have write access.
|
||||
SDefaultValidator* m_pDefaultValidator; //!<
|
||||
CCpuFeatures* m_pCpu; //!< CPU features
|
||||
int m_ttMemStatSS; //!< Time to memstat screenshot
|
||||
bool m_bDrawConsole; //!< Set to true if OK to draw the console.
|
||||
bool m_bDrawUI; //!< Set to true if OK to draw UI.
|
||||
@@ -661,18 +549,6 @@ private: // ------------------------------------------------------
|
||||
//! System to manage views.
|
||||
IViewSystem* m_pViewSystem;
|
||||
|
||||
//! System to access zlib compressor
|
||||
IZLibCompressor* m_pIZLibCompressor;
|
||||
|
||||
//! System to access zlib decompressor
|
||||
IZLibDecompressor* m_pIZLibDecompressor;
|
||||
|
||||
//! System to access lz4 hc decompressor
|
||||
ILZ4Decompressor* m_pILZ4Decompressor;
|
||||
|
||||
//! System access to zstd decompressor
|
||||
IZStdDecompressor* m_pIZStdDecompressor;
|
||||
|
||||
// XML Utils interface.
|
||||
class CXmlUtils* m_pXMLUtils;
|
||||
|
||||
@@ -736,7 +612,6 @@ private: // ------------------------------------------------------
|
||||
ICVar* m_sysWarnings; //!< might be 0, "sys_warnings" - Treat warning as errors.
|
||||
ICVar* m_cvSSInfo; //!< might be 0, "sys_SSInfo" 0/1 - get file sourcesafe info
|
||||
ICVar* m_svDedicatedMaxRate;
|
||||
ICVar* m_sys_GraphicsQuality;
|
||||
ICVar* m_sys_firstlaunch;
|
||||
ICVar* m_sys_asset_processor;
|
||||
ICVar* m_sys_load_files_to_memory;
|
||||
@@ -777,8 +652,6 @@ private: // ------------------------------------------------------
|
||||
ESystemConfigSpec m_nMaxConfigSpec;
|
||||
ESystemConfigPlatform m_ConfigPlatform;
|
||||
|
||||
std::unique_ptr<CServerThrottle> m_pServerThrottle;
|
||||
|
||||
CProfilingSystem m_ProfilingSystem;
|
||||
|
||||
// Pause mode.
|
||||
@@ -803,9 +676,6 @@ public:
|
||||
virtual const SFileVersion& GetProductVersion();
|
||||
virtual const SFileVersion& GetBuildVersion();
|
||||
|
||||
bool CompressDataBlock(const void* input, size_t inputSize, void* output, size_t& outputSize, int level);
|
||||
bool DecompressDataBlock(const void* input, size_t inputSize, void* output, size_t& outputSize);
|
||||
|
||||
bool InitVTuneProfiler();
|
||||
|
||||
void OpenBasicPaks();
|
||||
@@ -856,7 +726,6 @@ public:
|
||||
protected: // -------------------------------------------------------------
|
||||
|
||||
CCmdLine* m_pCmdLine;
|
||||
ITextModeConsole* m_pTextModeConsole;
|
||||
|
||||
string m_currentLanguageAudio;
|
||||
string m_systemConfigName; // computed from system_(hardwareplatform)_(assetsPlatform) - eg, system_android_es3.cfg or system_android_opengl.cfg or system_windows_pc.cfg
|
||||
@@ -878,15 +747,7 @@ protected: // -------------------------------------------------------------
|
||||
ESystemEvent m_eRuntimeState;
|
||||
bool m_bIsAsserting;
|
||||
|
||||
friend struct SDefaultValidator;
|
||||
friend struct SCryEngineFoldersLoader;
|
||||
// friend void ScreenshotCmd( IConsoleCmdArgs *pParams );
|
||||
|
||||
bool m_bIsSteamInitialized;
|
||||
|
||||
std::vector<IWindowMessageHandler*> m_windowMessageHandlers;
|
||||
bool m_initedOSAllocator = false;
|
||||
bool m_initedSysAllocator = false;
|
||||
|
||||
AZStd::unique_ptr<ThermalInfoHandler> m_thermalInfoHandler;
|
||||
};
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
#include "CrySystem_precompiled.h"
|
||||
#include "SystemInit.h"
|
||||
#include "System.h"
|
||||
|
||||
#if defined(AZ_RESTRICTED_PLATFORM) || defined(AZ_TOOLS_EXPAND_FOR_RESTRICTED_PLATFORMS)
|
||||
#undef AZ_RESTRICTED_SECTION
|
||||
@@ -95,17 +95,8 @@
|
||||
#include "XConsole.h"
|
||||
#include "Log.h"
|
||||
#include "XML/xml.h"
|
||||
#include "PhysRenderer.h"
|
||||
#include "LocalizedStringManager.h"
|
||||
#include "SystemEventDispatcher.h"
|
||||
#include "Validator.h"
|
||||
#include "ServerThrottle.h"
|
||||
#include "SystemCFG.h"
|
||||
#include "AutoDetectSpec.h"
|
||||
#include "ZLibCompressor.h"
|
||||
#include "ZLibDecompressor.h"
|
||||
#include "ZStdDecompressor.h"
|
||||
#include "LZ4Decompressor.h"
|
||||
#include "LevelSystem/LevelSystem.h"
|
||||
#include "LevelSystem/SpawnableLevelSystem.h"
|
||||
#include "ViewSystem/ViewSystem.h"
|
||||
@@ -114,29 +105,10 @@
|
||||
#include <AzCore/Jobs/JobManagerBus.h>
|
||||
#include <AzFramework/Driller/DrillerConsoleAPI.h>
|
||||
|
||||
#if USE_STEAM
|
||||
#include "Steamworks/public/steam/steam_api.h"
|
||||
#include "Steamworks/public/steam/isteamremotestorage.h"
|
||||
#endif
|
||||
|
||||
#if defined(IOS)
|
||||
#include "IOSConsole.h"
|
||||
#endif
|
||||
|
||||
#if defined(ANDROID)
|
||||
#include <AzCore/Android/Utils.h>
|
||||
#include "AndroidConsole.h"
|
||||
#if !defined(AZ_RELEASE_BUILD)
|
||||
#include "ThermalInfoAndroid.h"
|
||||
#endif // !defined(AZ_RELEASE_BUILD)
|
||||
#endif
|
||||
|
||||
#if defined(AZ_PLATFORM_ANDROID) || defined(AZ_PLATFORM_IOS)
|
||||
#include "MobileDetectSpec.h"
|
||||
#endif
|
||||
|
||||
#include "WindowsConsole.h"
|
||||
|
||||
#if defined(EXTERNAL_CRASH_REPORTING)
|
||||
#include <CrashHandler.h>
|
||||
#endif
|
||||
@@ -150,10 +122,6 @@
|
||||
# include <AzFramework/Network/AssetProcessorConnection.h>
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
extern LONG WINAPI CryEngineExceptionFilterWER(struct _EXCEPTION_POINTERS* pExceptionPointers);
|
||||
#endif
|
||||
|
||||
#if defined(AZ_RESTRICTED_PLATFORM)
|
||||
#define AZ_RESTRICTED_SECTION SYSTEMINIT_CPP_SECTION_14
|
||||
#include AZ_RESTRICTED_FILE(SystemInit_cpp)
|
||||
@@ -196,12 +164,6 @@ void CryEngineSignalHandler(int signal)
|
||||
|
||||
#endif // AZ_TRAIT_USE_CRY_SIGNAL_HANDLER
|
||||
|
||||
#if defined(USE_UNIXCONSOLE)
|
||||
#if defined(LINUX) && !defined(ANDROID)
|
||||
CUNIXConsole* pUnixConsole;
|
||||
#endif
|
||||
#endif // USE_UNIXCONSOLE
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
#define DEFAULT_LOG_FILENAME "@log@/Log.txt"
|
||||
|
||||
@@ -333,26 +295,6 @@ static void CmdCrashTest(IConsoleCmdArgs* pArgs)
|
||||
}
|
||||
AZ_POP_DISABLE_WARNING
|
||||
|
||||
#if USE_STEAM
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
static void CmdWipeSteamCloud(IConsoleCmdArgs* pArgs)
|
||||
{
|
||||
if (!gEnv->pSystem->SteamInit())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int32 fileCount = SteamRemoteStorage()->GetFileCount();
|
||||
for (int i = 0; i < fileCount; i++)
|
||||
{
|
||||
int32 size = 0;
|
||||
const char* name = SteamRemoteStorage()->GetFileNameAndSize(i, &size);
|
||||
bool success = SteamRemoteStorage()->FileDelete(name);
|
||||
CryLog("Deleting file: %s - success: %d", name, success);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
struct SysSpecOverrideSink
|
||||
: public ILoadConfigurationEntrySink
|
||||
@@ -466,275 +408,6 @@ static ESystemConfigPlatform GetDevicePlatform()
|
||||
#endif
|
||||
}
|
||||
|
||||
static void GetSpecConfigFileToLoad(ICVar* pVar, AZStd::string& cfgFile, ESystemConfigPlatform platform)
|
||||
{
|
||||
switch (platform)
|
||||
{
|
||||
case CONFIG_PC:
|
||||
cfgFile = "pc";
|
||||
break;
|
||||
case CONFIG_ANDROID:
|
||||
cfgFile = "android";
|
||||
break;
|
||||
case CONFIG_IOS:
|
||||
cfgFile = "ios";
|
||||
break;
|
||||
#if defined(AZ_PLATFORM_JASPER) || defined(TOOLS_SUPPORT_JASPER)
|
||||
#define AZ_RESTRICTED_SECTION SYSTEMINIT_CPP_SECTION_3
|
||||
#include AZ_RESTRICTED_FILE_EXPLICIT(SystemInit_cpp, jasper)
|
||||
#endif
|
||||
#if defined(AZ_PLATFORM_PROVO) || defined(TOOLS_SUPPORT_PROVO)
|
||||
#define AZ_RESTRICTED_SECTION SYSTEMINIT_CPP_SECTION_3
|
||||
#include AZ_RESTRICTED_FILE_EXPLICIT(SystemInit_cpp, provo)
|
||||
#endif
|
||||
#if defined(AZ_PLATFORM_SALEM) || defined(TOOLS_SUPPORT_SALEM)
|
||||
#define AZ_RESTRICTED_SECTION SYSTEMINIT_CPP_SECTION_3
|
||||
#include AZ_RESTRICTED_FILE_EXPLICIT(SystemInit_cpp, salem)
|
||||
#endif
|
||||
case CONFIG_OSX_METAL:
|
||||
cfgFile = "osx_metal";
|
||||
break;
|
||||
case CONFIG_OSX_GL:
|
||||
// Spec level is hardcoded for these platforms
|
||||
cfgFile = "";
|
||||
return;
|
||||
default:
|
||||
AZ_Assert(false, "Platform not supported");
|
||||
return;
|
||||
}
|
||||
|
||||
switch (pVar->GetIVal())
|
||||
{
|
||||
case CONFIG_AUTO_SPEC:
|
||||
// Spec level is set for autodetection
|
||||
cfgFile = "";
|
||||
break;
|
||||
case CONFIG_LOW_SPEC:
|
||||
cfgFile += "_low.cfg";
|
||||
break;
|
||||
case CONFIG_MEDIUM_SPEC:
|
||||
cfgFile += "_medium.cfg";
|
||||
break;
|
||||
case CONFIG_HIGH_SPEC:
|
||||
cfgFile += "_high.cfg";
|
||||
break;
|
||||
case CONFIG_VERYHIGH_SPEC:
|
||||
#if defined(AZ_RESTRICTED_PLATFORM)
|
||||
#define AZ_RESTRICTED_SECTION SYSTEMINIT_CPP_SECTION_4
|
||||
#include AZ_RESTRICTED_FILE(SystemInit_cpp)
|
||||
#endif
|
||||
cfgFile += "_veryhigh.cfg";
|
||||
break;
|
||||
default:
|
||||
AZ_Assert(false, "Invalid value for r_GraphicsQuality");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void LoadDetectedSpec(ICVar* pVar)
|
||||
{
|
||||
CDebugAllowFileAccess ignoreInvalidFileAccess;
|
||||
SysSpecOverrideSink sysSpecOverrideSink;
|
||||
ILoadConfigurationEntrySink* pSysSpecOverrideSinkConsole = nullptr;
|
||||
|
||||
#if !defined(CONSOLE)
|
||||
SysSpecOverrideSinkConsole sysSpecOverrideSinkConsole;
|
||||
pSysSpecOverrideSinkConsole = &sysSpecOverrideSinkConsole;
|
||||
#endif
|
||||
|
||||
// g_sysSpecChanged = true;
|
||||
static int no_recursive = false;
|
||||
if (no_recursive)
|
||||
{
|
||||
return;
|
||||
}
|
||||
no_recursive = true;
|
||||
|
||||
int spec = pVar->GetIVal();
|
||||
ESystemConfigPlatform platform = GetDevicePlatform();
|
||||
if (gEnv->IsEditor())
|
||||
{
|
||||
ESystemConfigPlatform configPlatform = GetISystem()->GetConfigPlatform();
|
||||
// Check if the config platform is set first.
|
||||
if (configPlatform != CONFIG_INVALID_PLATFORM)
|
||||
{
|
||||
platform = configPlatform;
|
||||
}
|
||||
}
|
||||
|
||||
AZStd::string configFile;
|
||||
GetSpecConfigFileToLoad(pVar, configFile, platform);
|
||||
if (configFile.length())
|
||||
{
|
||||
GetISystem()->LoadConfiguration(configFile.c_str(), platform == CONFIG_PC ? &sysSpecOverrideSink : pSysSpecOverrideSinkConsole);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Automatically sets graphics quality - spec level autodetected for ios/android, hardcoded for all other platforms
|
||||
|
||||
switch (platform)
|
||||
{
|
||||
case CONFIG_PC:
|
||||
{
|
||||
// TODO: add support for autodetection
|
||||
pVar->Set(CONFIG_VERYHIGH_SPEC);
|
||||
GetISystem()->LoadConfiguration("pc_veryhigh.cfg", &sysSpecOverrideSink);
|
||||
break;
|
||||
}
|
||||
case CONFIG_ANDROID:
|
||||
{
|
||||
#if defined(AZ_PLATFORM_ANDROID)
|
||||
AZStd::string file;
|
||||
if (MobileSysInspect::GetAutoDetectedSpecName(file))
|
||||
{
|
||||
if (file == "android_low.cfg")
|
||||
{
|
||||
pVar->Set(CONFIG_LOW_SPEC);
|
||||
}
|
||||
if (file == "android_medium.cfg")
|
||||
{
|
||||
pVar->Set(CONFIG_MEDIUM_SPEC);
|
||||
}
|
||||
if (file == "android_high.cfg")
|
||||
{
|
||||
pVar->Set(CONFIG_HIGH_SPEC);
|
||||
}
|
||||
if (file == "android_veryhigh.cfg")
|
||||
{
|
||||
pVar->Set(CONFIG_VERYHIGH_SPEC);
|
||||
}
|
||||
GetISystem()->LoadConfiguration(file.c_str(), pSysSpecOverrideSinkConsole);
|
||||
}
|
||||
else
|
||||
{
|
||||
float totalRAM = MobileSysInspect::GetDeviceRamInGB();
|
||||
if (totalRAM < MobileSysInspect::LOW_SPEC_RAM)
|
||||
{
|
||||
pVar->Set(CONFIG_LOW_SPEC);
|
||||
GetISystem()->LoadConfiguration("android_low.cfg", pSysSpecOverrideSinkConsole);
|
||||
}
|
||||
else if (totalRAM < MobileSysInspect::MEDIUM_SPEC_RAM)
|
||||
{
|
||||
pVar->Set(CONFIG_MEDIUM_SPEC);
|
||||
GetISystem()->LoadConfiguration("android_medium.cfg", pSysSpecOverrideSinkConsole);
|
||||
}
|
||||
else if (totalRAM < MobileSysInspect::HIGH_SPEC_RAM)
|
||||
{
|
||||
pVar->Set(CONFIG_HIGH_SPEC);
|
||||
GetISystem()->LoadConfiguration("android_high.cfg", pSysSpecOverrideSinkConsole);
|
||||
}
|
||||
else
|
||||
{
|
||||
pVar->Set(CONFIG_VERYHIGH_SPEC);
|
||||
GetISystem()->LoadConfiguration("android_veryhigh.cfg", pSysSpecOverrideSinkConsole);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
case CONFIG_IOS:
|
||||
{
|
||||
#if defined(AZ_PLATFORM_IOS)
|
||||
AZStd::string file;
|
||||
if (MobileSysInspect::GetAutoDetectedSpecName(file))
|
||||
{
|
||||
if (file == "ios_low.cfg")
|
||||
{
|
||||
pVar->Set(CONFIG_LOW_SPEC);
|
||||
}
|
||||
if (file == "ios_medium.cfg")
|
||||
{
|
||||
pVar->Set(CONFIG_MEDIUM_SPEC);
|
||||
}
|
||||
if (file == "ios_high.cfg")
|
||||
{
|
||||
pVar->Set(CONFIG_HIGH_SPEC);
|
||||
}
|
||||
if (file == "ios_veryhigh.cfg")
|
||||
{
|
||||
pVar->Set(CONFIG_VERYHIGH_SPEC);
|
||||
}
|
||||
GetISystem()->LoadConfiguration(file.c_str(), pSysSpecOverrideSinkConsole);
|
||||
}
|
||||
else
|
||||
{
|
||||
pVar->Set(CONFIG_MEDIUM_SPEC);
|
||||
GetISystem()->LoadConfiguration("ios_medium.cfg", pSysSpecOverrideSinkConsole);
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
#if defined(AZ_PLATFORM_JASPER) || defined(TOOLS_SUPPORT_JASPER)
|
||||
#define AZ_RESTRICTED_SECTION SYSTEMINIT_CPP_SECTION_5
|
||||
#include AZ_RESTRICTED_FILE_EXPLICIT(SystemInit_cpp, jasper)
|
||||
#endif
|
||||
#if defined(AZ_PLATFORM_PROVO) || defined(TOOLS_SUPPORT_PROVO)
|
||||
#define AZ_RESTRICTED_SECTION SYSTEMINIT_CPP_SECTION_5
|
||||
#include AZ_RESTRICTED_FILE_EXPLICIT(SystemInit_cpp, provo)
|
||||
#endif
|
||||
#if defined(AZ_PLATFORM_SALEM) || defined(TOOLS_SUPPORT_SALEM)
|
||||
#define AZ_RESTRICTED_SECTION SYSTEMINIT_CPP_SECTION_5
|
||||
#include AZ_RESTRICTED_FILE_EXPLICIT(SystemInit_cpp, salem)
|
||||
#endif
|
||||
|
||||
case CONFIG_OSX_GL:
|
||||
{
|
||||
pVar->Set(CONFIG_HIGH_SPEC);
|
||||
GetISystem()->LoadConfiguration("osx_gl.cfg", pSysSpecOverrideSinkConsole);
|
||||
break;
|
||||
}
|
||||
case CONFIG_OSX_METAL:
|
||||
{
|
||||
pVar->Set(CONFIG_HIGH_SPEC);
|
||||
GetISystem()->LoadConfiguration("osx_metal_high.cfg", pSysSpecOverrideSinkConsole);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
AZ_Assert(false, "Platform not supported");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// make sure editor specific settings are not changed
|
||||
if (gEnv->IsEditor())
|
||||
{
|
||||
GetISystem()->LoadConfiguration("editor.cfg");
|
||||
}
|
||||
|
||||
// override cvars just loaded based on current API version/GPU
|
||||
|
||||
GetISystem()->SetConfigSpec(static_cast<ESystemConfigSpec>(spec), platform, false);
|
||||
|
||||
no_recursive = false;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
struct SCryEngineLanguageConfigLoader
|
||||
: public ILoadConfigurationEntrySink
|
||||
{
|
||||
CSystem* m_pSystem;
|
||||
string m_language;
|
||||
string m_pakFile;
|
||||
|
||||
SCryEngineLanguageConfigLoader(CSystem* pSystem) { m_pSystem = pSystem; }
|
||||
void Load(const char* sCfgFilename)
|
||||
{
|
||||
CSystemConfiguration cfg(sCfgFilename, m_pSystem, this); // Parse folders config file.
|
||||
}
|
||||
virtual void OnLoadConfigurationEntry(const char* szKey, const char* szValue, [[maybe_unused]] const char* szGroup)
|
||||
{
|
||||
if (azstricmp(szKey, "Language") == 0)
|
||||
{
|
||||
m_language = szValue;
|
||||
}
|
||||
else if (azstricmp(szKey, "PAK") == 0)
|
||||
{
|
||||
m_pakFile = szValue;
|
||||
}
|
||||
}
|
||||
virtual void OnLoadConfigurationEntry_End() {}
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
#if !defined(AZ_MONOLITHIC_BUILD)
|
||||
|
||||
@@ -1392,96 +1065,6 @@ string GetUniqueLogFileName(string logFileName)
|
||||
return logFileName;
|
||||
}
|
||||
|
||||
|
||||
#if defined(WIN32) || defined(WIN64)
|
||||
static wstring GetErrorStringUnsupportedCPU()
|
||||
{
|
||||
static const wchar_t s_EN[] = L"Unsupported CPU detected. CPU needs to support SSE, SSE2, SSE3 and SSE4.1.";
|
||||
static const wchar_t s_FR[] = { 0 };
|
||||
static const wchar_t s_RU[] = { 0 };
|
||||
static const wchar_t s_ES[] = { 0 };
|
||||
static const wchar_t s_DE[] = { 0 };
|
||||
static const wchar_t s_IT[] = { 0 };
|
||||
|
||||
const size_t fullLangID = (size_t) GetKeyboardLayout(0);
|
||||
const size_t primLangID = fullLangID & 0x3FF;
|
||||
const wchar_t* pFmt = s_EN;
|
||||
|
||||
/*switch (primLangID)
|
||||
{
|
||||
case 0x07: // German
|
||||
pFmt = s_DE;
|
||||
break;
|
||||
case 0x0a: // Spanish
|
||||
pFmt = s_ES;
|
||||
break;
|
||||
case 0x0c: // French
|
||||
pFmt = s_FR;
|
||||
break;
|
||||
case 0x10: // Italian
|
||||
pFmt = s_IT;
|
||||
break;
|
||||
case 0x19: // Russian
|
||||
pFmt = s_RU;
|
||||
break;
|
||||
case 0x09: // English
|
||||
default:
|
||||
break;
|
||||
}*/
|
||||
wchar_t msg[1024];
|
||||
msg[0] = L'\0';
|
||||
msg[sizeof(msg) / sizeof(msg[0]) - 1] = L'\0';
|
||||
azsnwprintf(msg, sizeof(msg) / sizeof(msg[0]) - 1, pFmt);
|
||||
return msg;
|
||||
}
|
||||
#endif
|
||||
|
||||
static bool CheckCPURequirements([[maybe_unused]] CCpuFeatures* pCpu, [[maybe_unused]] CSystem* pSystem)
|
||||
{
|
||||
#if defined(WIN32) || defined(WIN64)
|
||||
if (!gEnv->IsDedicated())
|
||||
{
|
||||
if (!(pCpu->hasSSE() && pCpu->hasSSE2() && pCpu->hasSSE3() && pCpu->hasSSE41()))
|
||||
{
|
||||
AZ_Printf(AZ_TRACE_SYSTEM_WINDOW, "Unsupported CPU! Need SSE, SSE2, SSE3 and SSE4.1 instructions to be available.");
|
||||
|
||||
#if !defined(_RELEASE)
|
||||
const bool allowPrompts = pSystem->GetICmdLine()->FindArg(eCLAT_Pre, "noprompt") == 0;
|
||||
#else
|
||||
const bool allowPrompts = true;
|
||||
#endif // !defined(_RELEASE)
|
||||
if (allowPrompts)
|
||||
{
|
||||
AZ_Printf(AZ_TRACE_SYSTEM_WINDOW, "Asking user if they wish to continue...");
|
||||
const int mbRes = MessageBoxW(0, GetErrorStringUnsupportedCPU().c_str(), L"Open 3D Engine", MB_ICONWARNING | MB_OKCANCEL | MB_DEFBUTTON2 | MB_DEFAULT_DESKTOP_ONLY);
|
||||
if (mbRes == IDCANCEL)
|
||||
{
|
||||
AZ_Printf(AZ_TRACE_SYSTEM_WINDOW, "User chose to cancel startup.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
#if !defined(_RELEASE)
|
||||
const bool obeyCPUCheck = pSystem->GetICmdLine()->FindArg(eCLAT_Pre, "anycpu") == 0;
|
||||
#else
|
||||
const bool obeyCPUCheck = true;
|
||||
#endif // !defined(_RELEASE)
|
||||
if (obeyCPUCheck)
|
||||
{
|
||||
AZ_Printf(AZ_TRACE_SYSTEM_WINDOW, "No prompts allowed and unsupported CPU check active. Treating unsupported CPU as error and exiting.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
AZ_Printf(AZ_TRACE_SYSTEM_WINDOW, "User chose to continue despite unsupported CPU!");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
class AzConsoleToCryConsoleBinder final
|
||||
{
|
||||
public:
|
||||
@@ -1692,16 +1275,6 @@ AZ_POP_DISABLE_WARNING
|
||||
}
|
||||
}
|
||||
|
||||
if (!startupParams.pValidator)
|
||||
{
|
||||
m_pDefaultValidator = new SDefaultValidator(this);
|
||||
m_pValidator = m_pDefaultValidator;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pValidator = startupParams.pValidator;
|
||||
}
|
||||
|
||||
#if !defined(_RELEASE)
|
||||
if (!m_bDedicatedServer)
|
||||
{
|
||||
@@ -1717,79 +1290,6 @@ AZ_POP_DISABLE_WARNING
|
||||
gEnv->SetIsDedicated(m_bDedicatedServer);
|
||||
#endif
|
||||
|
||||
#if !defined(CONSOLE)
|
||||
#if !defined(_RELEASE)
|
||||
bool isDaemonMode = (m_pCmdLine->FindArg(eCLAT_Pre, "daemon") != 0);
|
||||
#endif // !defined(_RELEASE)
|
||||
|
||||
#if defined(USE_DEDICATED_SERVER_CONSOLE)
|
||||
|
||||
#if !defined(_RELEASE)
|
||||
bool isSimpleConsole = (m_pCmdLine->FindArg(eCLAT_Pre, "simple_console") != 0);
|
||||
|
||||
if (!(isDaemonMode || isSimpleConsole))
|
||||
#endif // !defined(_RELEASE)
|
||||
{
|
||||
#if defined(USE_UNIXCONSOLE)
|
||||
CUNIXConsole* pConsole = new CUNIXConsole();
|
||||
#if defined(LINUX)
|
||||
pUnixConsole = pConsole;
|
||||
#endif
|
||||
#elif defined(USE_IOSCONSOLE)
|
||||
CIOSConsole* pConsole = new CIOSConsole();
|
||||
#elif defined(USE_WINDOWSCONSOLE)
|
||||
CWindowsConsole* pConsole = new CWindowsConsole();
|
||||
#elif defined(USE_ANDROIDCONSOLE)
|
||||
CAndroidConsole* pConsole = new CAndroidConsole();
|
||||
#else
|
||||
CNULLConsole* pConsole = new CNULLConsole(false);
|
||||
#endif
|
||||
m_pTextModeConsole = static_cast<ITextModeConsole*>(pConsole);
|
||||
|
||||
if (m_pUserCallback == nullptr && m_bDedicatedServer)
|
||||
{
|
||||
char headerString[128];
|
||||
m_pUserCallback = pConsole;
|
||||
pConsole->SetRequireDedicatedServer(true);
|
||||
|
||||
azstrcpy(
|
||||
headerString,
|
||||
AZ_ARRAY_SIZE(headerString),
|
||||
"Open 3D Engine - "
|
||||
#if defined(LINUX)
|
||||
"Linux "
|
||||
#elif defined(MAC)
|
||||
"MAC "
|
||||
#elif defined(IOS)
|
||||
"iOS "
|
||||
#endif
|
||||
"Dedicated Server"
|
||||
" - Version ");
|
||||
|
||||
char* str = headerString + strlen(headerString);
|
||||
GetProductVersion().ToString(str, sizeof(headerString) - (str - headerString));
|
||||
pConsole->SetHeader(headerString);
|
||||
}
|
||||
}
|
||||
#if !defined(_RELEASE)
|
||||
else
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if !(defined(USE_DEDICATED_SERVER_CONSOLE) && defined(_RELEASE))
|
||||
{
|
||||
CNULLConsole* pConsole = new CNULLConsole(isDaemonMode);
|
||||
m_pTextModeConsole = pConsole;
|
||||
|
||||
if (m_pUserCallback == nullptr && m_bDedicatedServer)
|
||||
{
|
||||
m_pUserCallback = pConsole;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // !defined(CONSOLE)
|
||||
|
||||
{
|
||||
EBUS_EVENT(CrySystemEventBus, OnCrySystemPreInitialize, *this, startupParams);
|
||||
|
||||
@@ -1909,9 +1409,6 @@ AZ_POP_DISABLE_WARNING
|
||||
|
||||
// Need to load the engine.pak that includes the config files needed during initialization
|
||||
m_env.pCryPak->OpenPack("@assets@", "Engine.pak");
|
||||
#if defined(AZ_PLATFORM_ANDROID) || defined(AZ_PLATFORM_IOS)
|
||||
MobileSysInspect::LoadDeviceSpecMapping();
|
||||
#endif
|
||||
|
||||
InitFileSystem_LoadEngineFolders(startupParams);
|
||||
|
||||
@@ -1920,16 +1417,6 @@ AZ_POP_DISABLE_WARNING
|
||||
GetIRemoteConsole()->Update();
|
||||
#endif
|
||||
|
||||
// CPU features detection.
|
||||
m_pCpu = new CCpuFeatures;
|
||||
m_pCpu->Detect();
|
||||
|
||||
// Check hard minimum CPU requirements
|
||||
if (!CheckCPURequirements(m_pCpu, this))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
InlineInitializationProcessing("CSystem::Init Load Engine Folders");
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
@@ -1998,14 +1485,6 @@ AZ_POP_DISABLE_WARNING
|
||||
|
||||
InlineInitializationProcessing("CSystem::Init LoadConfigurations");
|
||||
|
||||
#ifdef WIN32
|
||||
if ((g_cvars.sys_WER))
|
||||
{
|
||||
SetUnhandledExceptionFilter(CryEngineExceptionFilterWER);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Localization
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
@@ -2014,10 +1493,6 @@ AZ_POP_DISABLE_WARNING
|
||||
}
|
||||
InlineInitializationProcessing("CSystem::Init InitLocalizations");
|
||||
|
||||
#if !defined(AZ_RELEASE_BUILD) && defined(AZ_PLATFORM_ANDROID)
|
||||
m_thermalInfoHandler = AZStd::make_unique<ThermalInfoAndroidHandler>();
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Open basic pak files after intro movie playback started
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
@@ -2129,30 +1604,6 @@ AZ_POP_DISABLE_WARNING
|
||||
|
||||
InlineInitializationProcessing("CSystem::Init View System");
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Zlib compressor
|
||||
m_pIZLibCompressor = new CZLibCompressor();
|
||||
|
||||
InlineInitializationProcessing("CSystem::Init ZLibCompressor");
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Zlib decompressor
|
||||
m_pIZLibDecompressor = new CZLibDecompressor();
|
||||
|
||||
InlineInitializationProcessing("CSystem::Init ZLibDecompressor");
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// LZ4 decompressor
|
||||
m_pILZ4Decompressor = new CLZ4Decompressor();
|
||||
|
||||
InlineInitializationProcessing("CSystem::Init LZ4Decompressor");
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// ZStd decompressor
|
||||
m_pIZStdDecompressor = new CZStdDecompressor();
|
||||
|
||||
InlineInitializationProcessing("CSystem::Init ZStdDecompressor");
|
||||
|
||||
if (m_env.pLyShine)
|
||||
{
|
||||
m_env.pLyShine->PostInit();
|
||||
@@ -2192,9 +1643,6 @@ AZ_POP_DISABLE_WARNING
|
||||
LoadConfiguration("client.cfg", &CVarsClientConfigSink);
|
||||
}
|
||||
|
||||
// All CVars should be registered by this point, we must now flush the cvar groups
|
||||
LoadDetectedSpec(m_sys_GraphicsQuality);
|
||||
|
||||
//Connect to the render bus
|
||||
AZ::RenderNotificationsBus::Handler::BusConnect();
|
||||
|
||||
@@ -2268,153 +1716,6 @@ void CmdSetAwsLogLevel(IConsoleCmdArgs* pArgs)
|
||||
}
|
||||
}
|
||||
|
||||
static void SysRestoreSpecCmd(IConsoleCmdArgs* pParams)
|
||||
{
|
||||
assert(pParams);
|
||||
|
||||
if (pParams->GetArgCount() == 2)
|
||||
{
|
||||
const char* szArg = pParams->GetArg(1);
|
||||
|
||||
ICVar* pCVar = gEnv->pConsole->GetCVar("sys_spec_Full");
|
||||
|
||||
if (!pCVar)
|
||||
{
|
||||
gEnv->pLog->LogWithType(ILog::eInputResponse, "sys_RestoreSpec: no action"); // e.g. running Editor in shder compile mode
|
||||
return;
|
||||
}
|
||||
|
||||
ICVar::EConsoleLogMode mode = ICVar::eCLM_Off;
|
||||
|
||||
if (azstricmp(szArg, "test") == 0)
|
||||
{
|
||||
mode = ICVar::eCLM_ConsoleAndFile;
|
||||
}
|
||||
else if (azstricmp(szArg, "test*") == 0)
|
||||
{
|
||||
mode = ICVar::eCLM_FileOnly;
|
||||
}
|
||||
else if (azstricmp(szArg, "info") == 0)
|
||||
{
|
||||
mode = ICVar::eCLM_FullInfo;
|
||||
}
|
||||
|
||||
if (mode != ICVar::eCLM_Off)
|
||||
{
|
||||
bool bFileOrConsole = (mode == ICVar::eCLM_FileOnly || mode == ICVar::eCLM_FullInfo);
|
||||
|
||||
if (bFileOrConsole)
|
||||
{
|
||||
gEnv->pLog->LogToFile(" ");
|
||||
}
|
||||
else
|
||||
{
|
||||
CryLog(" ");
|
||||
}
|
||||
|
||||
int iSysSpec = pCVar->GetRealIVal();
|
||||
|
||||
if (iSysSpec == -1)
|
||||
{
|
||||
iSysSpec = ((CSystem*)gEnv->pSystem)->GetMaxConfigSpec();
|
||||
|
||||
if (bFileOrConsole)
|
||||
{
|
||||
gEnv->pLog->LogToFile(" sys_spec = Custom (assuming %d)", iSysSpec);
|
||||
}
|
||||
else
|
||||
{
|
||||
gEnv->pLog->LogWithType(ILog::eInputResponse, " $3sys_spec = $6Custom (assuming %d)", iSysSpec);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (bFileOrConsole)
|
||||
{
|
||||
gEnv->pLog->LogToFile(" sys_spec = %d", iSysSpec);
|
||||
}
|
||||
else
|
||||
{
|
||||
gEnv->pLog->LogWithType(ILog::eInputResponse, " $3sys_spec = $6%d", iSysSpec);
|
||||
}
|
||||
}
|
||||
|
||||
pCVar->DebugLog(iSysSpec, mode);
|
||||
|
||||
if (bFileOrConsole)
|
||||
{
|
||||
gEnv->pLog->LogToFile(" ");
|
||||
}
|
||||
else
|
||||
{
|
||||
gEnv->pLog->LogWithType(ILog::eInputResponse, " ");
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
else if (strcmp(szArg, "apply") == 0)
|
||||
{
|
||||
const char* szPrefix = "sys_spec_";
|
||||
|
||||
ESystemConfigSpec originalSpec = CONFIG_AUTO_SPEC;
|
||||
ESystemConfigPlatform originalPlatform = GetDevicePlatform();
|
||||
|
||||
if (gEnv->IsEditor())
|
||||
{
|
||||
originalSpec = gEnv->pSystem->GetConfigSpec(true);
|
||||
}
|
||||
|
||||
std::vector<const char*> cmds;
|
||||
|
||||
cmds.resize(gEnv->pConsole->GetSortedVars(0, 0, szPrefix));
|
||||
gEnv->pConsole->GetSortedVars(&cmds[0], cmds.size(), szPrefix);
|
||||
|
||||
gEnv->pLog->LogWithType(IMiniLog::eInputResponse, " ");
|
||||
|
||||
std::vector<const char*>::const_iterator it, end = cmds.end();
|
||||
|
||||
for (it = cmds.begin(); it != end; ++it)
|
||||
{
|
||||
const char* szName = *it;
|
||||
|
||||
if (azstricmp(szName, "sys_spec_Full") == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
pCVar = gEnv->pConsole->GetCVar(szName);
|
||||
assert(pCVar);
|
||||
|
||||
if (!pCVar)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
bool bNeeded = pCVar->GetIVal() != pCVar->GetRealIVal();
|
||||
|
||||
gEnv->pLog->LogWithType(IMiniLog::eInputResponse, " $3%s = $6%d ... %s",
|
||||
szName, pCVar->GetIVal(),
|
||||
bNeeded ? "$4restored" : "valid");
|
||||
|
||||
if (bNeeded)
|
||||
{
|
||||
pCVar->Set(pCVar->GetIVal());
|
||||
}
|
||||
}
|
||||
|
||||
gEnv->pLog->LogWithType(IMiniLog::eInputResponse, " ");
|
||||
|
||||
if (gEnv->IsEditor())
|
||||
{
|
||||
gEnv->pSystem->SetConfigSpec(originalSpec, originalPlatform, true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
gEnv->pLog->LogWithType(ILog::eInputResponse, "ERROR: sys_RestoreSpec invalid arguments");
|
||||
}
|
||||
|
||||
void CmdDrillToFile(IConsoleCmdArgs* pArgs)
|
||||
{
|
||||
if (azstricmp(pArgs->GetArg(0), "DrillerStop") == 0)
|
||||
@@ -2551,14 +1852,6 @@ void CSystem::CreateSystemVars()
|
||||
"1 - enable optimisation\n"
|
||||
"Default is 1");
|
||||
|
||||
#if USE_STEAM
|
||||
#ifndef RELEASE
|
||||
REGISTER_CVAR2("sys_steamAppId", &g_cvars.sys_steamAppId, 0, VF_NULL, "steam appId used for development testing");
|
||||
REGISTER_COMMAND("sys_wipeSteamCloud", CmdWipeSteamCloud, VF_CHEAT, "Delete all files from steam cloud for this user");
|
||||
#endif // RELEASE
|
||||
REGISTER_CVAR2("sys_useSteamCloudForPlatformSaving", &g_cvars.sys_useSteamCloudForPlatformSaving, 0, VF_NULL, "Use steam cloud for save games and profile on PC (instead of the user folder)");
|
||||
#endif
|
||||
|
||||
m_sysNoUpdate = REGISTER_INT("sys_noupdate", 0, VF_CHEAT,
|
||||
"Toggles updating of system with sys_script_debugger.\n"
|
||||
"Usage: sys_noupdate [0/1]\n"
|
||||
@@ -2622,9 +1915,6 @@ void CSystem::CreateSystemVars()
|
||||
#else
|
||||
const uint32 nJobSystemDefaultCoreNumber = 4;
|
||||
#endif
|
||||
m_sys_GraphicsQuality = REGISTER_INT_CB("r_GraphicsQuality", 0, VF_ALWAYSONCHANGE,
|
||||
"Specifies the system cfg spec. 1=low, 2=med, 3=high, 4=very high)",
|
||||
LoadDetectedSpec);
|
||||
|
||||
m_sys_firstlaunch = REGISTER_INT("sys_firstlaunch", 0, 0,
|
||||
"Indicates that the game was run for the first time.");
|
||||
@@ -2731,14 +2021,6 @@ void CSystem::CreateSystemVars()
|
||||
REGISTER_CVAR2("sys_update_profile_time", &g_cvars.sys_update_profile_time, 1.0f, 0, "Time to keep updates timings history for.");
|
||||
REGISTER_CVAR2("sys_no_crash_dialog", &g_cvars.sys_no_crash_dialog, m_bNoCrashDialog, VF_NULL, "Whether to disable the crash dialog window");
|
||||
REGISTER_CVAR2("sys_no_error_report_window", &g_cvars.sys_no_error_report_window, m_bNoErrorReportWindow, VF_NULL, "Whether to disable the error report list");
|
||||
#if defined(_RELEASE)
|
||||
if (!gEnv->IsDedicated())
|
||||
{
|
||||
REGISTER_CVAR2("sys_WER", &g_cvars.sys_WER, 1, 0, "Enables Windows Error Reporting");
|
||||
}
|
||||
#else
|
||||
REGISTER_CVAR2("sys_WER", &g_cvars.sys_WER, 0, 0, "Enables Windows Error Reporting");
|
||||
#endif
|
||||
|
||||
#ifdef USE_HTTP_WEBSOCKETS
|
||||
REGISTER_CVAR2("sys_simple_http_base_port", &g_cvars.sys_simple_http_base_port, 1880, VF_REQUIRE_APP_RESTART,
|
||||
@@ -2820,11 +2102,6 @@ void CSystem::CreateSystemVars()
|
||||
REGISTER_STRING_CB("g_language", "", VF_NULL, "Defines which language pak is loaded", CSystem::OnLanguageCVarChanged);
|
||||
REGISTER_STRING_CB("g_languageAudio", "", VF_NULL, "Will automatically match g_language setting unless specified otherwise", CSystem::OnLanguageAudioCVarChanged);
|
||||
|
||||
REGISTER_COMMAND("sys_RestoreSpec", &SysRestoreSpecCmd, 0,
|
||||
"Restore or test the cvar settings of game specific spec settings,\n"
|
||||
"'test*' and 'info' log to the log file only\n"
|
||||
"Usage: sys_RestoreSpec [test|test*|apply|info]");
|
||||
|
||||
#if defined(WIN32)
|
||||
REGISTER_CVAR2("sys_display_threads", &g_cvars.sys_display_threads, 0, 0, "Displays Thread info");
|
||||
#elif defined(AZ_RESTRICTED_PLATFORM)
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
#ifndef CRYINCLUDE_CRYSYSTEM_SYSTEMINIT_H
|
||||
#define CRYINCLUDE_CRYSYSTEM_SYSTEMINIT_H
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "System.h"
|
||||
|
||||
#if defined(AZ_PLATFORM_ANDROID)
|
||||
#include "AndroidConsole.h"
|
||||
|
||||
// let the java code know the native renderer is taking over now
|
||||
extern "C" DLL_EXPORT void OnEngineRendererTakeover(bool engineSplashActive);
|
||||
#endif
|
||||
|
||||
#include "UnixConsole.h"
|
||||
|
||||
#if defined(USE_UNIXCONSOLE)
|
||||
#if defined(LINUX) && !defined(ANDROID)
|
||||
extern __attribute__((visibility("default"))) CUNIXConsole* pUnixConsole;
|
||||
#endif
|
||||
#endif // USE_UNIXCONSOLE
|
||||
|
||||
#endif // CRYINCLUDE_CRYSYSTEM_SYSTEMINIT_H
|
||||
@@ -1,115 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
// Description : CryENGINE system core
|
||||
|
||||
|
||||
#include "CrySystem_precompiled.h"
|
||||
#include "System.h"
|
||||
|
||||
#ifdef WIN32
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include "windows.h"
|
||||
#endif
|
||||
|
||||
#if defined(AZ_PLATFORM_IOS)
|
||||
#import <UIKit/UIKit.h>
|
||||
#endif
|
||||
|
||||
#include <IRenderer.h>
|
||||
#include <IRenderAuxGeom.h>
|
||||
#include <IProcess.h>
|
||||
#include "Log.h"
|
||||
#include "XConsole.h"
|
||||
#include <CryLibrary.h>
|
||||
#include "PhysRenderer.h"
|
||||
#include <IMovieSystem.h>
|
||||
|
||||
#include "ITextModeConsole.h"
|
||||
#include <ILevelSystem.h>
|
||||
#include <LyShine/ILyShine.h>
|
||||
|
||||
#include <LoadScreenBus.h>
|
||||
|
||||
#if defined(AZ_RESTRICTED_PLATFORM)
|
||||
#undef AZ_RESTRICTED_SECTION
|
||||
#define SYSTEMRENDERER_CPP_SECTION_1 1
|
||||
#define SYSTEMRENDERER_CPP_SECTION_2 2
|
||||
#endif
|
||||
|
||||
#if defined(AZ_PLATFORM_ANDROID)
|
||||
#include <AzCore/Android/Utils.h>
|
||||
#endif
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
bool CSystem::GetPrimaryPhysicalDisplayDimensions([[maybe_unused]] int& o_widthPixels, [[maybe_unused]] int& o_heightPixels)
|
||||
{
|
||||
#if defined(AZ_PLATFORM_WINDOWS)
|
||||
o_widthPixels = GetSystemMetrics(SM_CXSCREEN);
|
||||
o_heightPixels = GetSystemMetrics(SM_CYSCREEN);
|
||||
return true;
|
||||
#elif defined(AZ_PLATFORM_ANDROID)
|
||||
return AZ::Android::Utils::GetWindowSize(o_widthPixels, o_heightPixels);
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
bool CSystem::IsTablet()
|
||||
{
|
||||
//TODO: Add support for Android tablets
|
||||
#if defined(AZ_PLATFORM_IOS)
|
||||
return [UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
void CSystem::OnScene3DEnd()
|
||||
{
|
||||
//Render Console
|
||||
if (m_bDrawConsole && gEnv->pConsole)
|
||||
{
|
||||
gEnv->pConsole->Draw();
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void CSystem::DisplayErrorMessage(const char* acMessage,
|
||||
[[maybe_unused]] float fTime,
|
||||
const float* pfColor,
|
||||
bool bHardError)
|
||||
{
|
||||
SErrorMessage message;
|
||||
message.m_Message = acMessage;
|
||||
if (pfColor)
|
||||
{
|
||||
memcpy(message.m_Color, pfColor, 4 * sizeof(float));
|
||||
}
|
||||
else
|
||||
{
|
||||
message.m_Color[0] = 1.0f;
|
||||
message.m_Color[1] = 0.0f;
|
||||
message.m_Color[2] = 0.0f;
|
||||
message.m_Color[3] = 1.0f;
|
||||
}
|
||||
message.m_HardFailure = bHardError;
|
||||
#ifdef _RELEASE
|
||||
message.m_fTimeToShow = fTime;
|
||||
#else
|
||||
message.m_fTimeToShow = 1.0f;
|
||||
#endif
|
||||
m_ErrorMessages.push_back(message);
|
||||
}
|
||||
@@ -53,7 +53,6 @@
|
||||
#include "XConsole.h"
|
||||
#include "LocalizedStringManager.h"
|
||||
#include "XML/XmlUtils.h"
|
||||
#include "AutoDetectSpec.h"
|
||||
|
||||
#if defined(WIN32)
|
||||
__pragma(comment(lib, "wininet.lib"))
|
||||
|
||||
@@ -1,187 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
#include "CrySystem_precompiled.h"
|
||||
|
||||
#include <AzTest/AzTest.h>
|
||||
#include <Log.h>
|
||||
|
||||
#include <Mocks/ISystemMock.h>
|
||||
#include <Mocks/IRemoteConsoleMock.h>
|
||||
|
||||
#include <AzCore/IO/SystemFile.h> // for max path decl
|
||||
#include <AzCore/Math/Random.h>
|
||||
#include <AzCore/Memory/AllocatorScope.h>
|
||||
#include <AzCore/UnitTest/UnitTest.h>
|
||||
#include <AzCore/UnitTest/Mocks/MockFileIOBase.h>
|
||||
|
||||
namespace CLogUnitTests
|
||||
{
|
||||
using ::testing::NiceMock;
|
||||
using ::testing::_;
|
||||
using ::testing::Return;
|
||||
|
||||
// for fuzzing test, how much work to do? Not much, as this must be fast.
|
||||
const int NumTrialsToPerform = 16000;
|
||||
|
||||
class CLogUnitTests
|
||||
: public ::testing::Test
|
||||
{
|
||||
public:
|
||||
|
||||
using CryPrimitivesAllocatorScope = AZ::AllocatorScope<AZ::LegacyAllocator, CryStringAllocator>;
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
m_primitiveAllocators.ActivateAllocators();
|
||||
|
||||
m_priorEnv = gEnv;
|
||||
m_priorFileIO = AZ::IO::FileIOBase::GetInstance();
|
||||
m_priorDirectFileIO = AZ::IO::FileIOBase::GetDirectInstance();
|
||||
|
||||
m_data = AZStd::make_unique<DataMembers>();
|
||||
m_data->m_stubEnv.pSystem = &m_data->m_system;
|
||||
|
||||
gEnv = &m_data->m_stubEnv;
|
||||
|
||||
// for FileIO, you must set the instance to null before changing it.
|
||||
// this is a way to tell the singleton system that you mean to replace a singleton and its
|
||||
// not a mistake.
|
||||
AZ::IO::FileIOBase::SetInstance(nullptr);
|
||||
AZ::IO::FileIOBase::SetInstance(&m_data->m_fileIOMock);
|
||||
AZ::IO::FileIOBase::SetDirectInstance(nullptr);
|
||||
AZ::IO::FileIOBase::SetDirectInstance(&m_data->m_fileIOMock);
|
||||
|
||||
ON_CALL(m_data->m_system, GetIRemoteConsole())
|
||||
.WillByDefault(
|
||||
Return(&m_data->m_remoteConsoleMock));
|
||||
|
||||
AZ::IO::MockFileIOBase::InstallDefaultReturns(m_data->m_fileIOMock);
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
AZ::IO::FileIOBase::SetInstance(nullptr);
|
||||
AZ::IO::FileIOBase::SetInstance(m_priorFileIO);
|
||||
AZ::IO::FileIOBase::SetDirectInstance(nullptr);
|
||||
AZ::IO::FileIOBase::SetDirectInstance(m_priorDirectFileIO);
|
||||
|
||||
m_data.reset();
|
||||
|
||||
// restore state.
|
||||
gEnv = m_priorEnv;
|
||||
m_primitiveAllocators.DeactivateAllocators();
|
||||
}
|
||||
|
||||
struct DataMembers
|
||||
{
|
||||
SSystemGlobalEnvironment m_stubEnv;
|
||||
NiceMock<SystemMock> m_system;
|
||||
NiceMock<AZ::IO::MockFileIOBase> m_fileIOMock;
|
||||
NiceMock<IRemoteConsoleMock> m_remoteConsoleMock;
|
||||
};
|
||||
|
||||
AZStd::unique_ptr<DataMembers> m_data;
|
||||
SSystemGlobalEnvironment* m_priorEnv = nullptr;
|
||||
ISystem* m_priorSystem = nullptr;
|
||||
AZ::IO::FileIOBase* m_priorFileIO = nullptr;
|
||||
AZ::IO::FileIOBase* m_priorDirectFileIO = nullptr;
|
||||
CryPrimitivesAllocatorScope m_primitiveAllocators;
|
||||
};
|
||||
|
||||
TEST_F(CLogUnitTests, LogAlways_InvalidString_Asserts)
|
||||
{
|
||||
AZ_TEST_START_TRACE_SUPPRESSION;
|
||||
CLog testLog(&m_data->m_system);
|
||||
testLog.LogAlways(nullptr);
|
||||
AZ_TEST_STOP_TRACE_SUPPRESSION(1);
|
||||
}
|
||||
|
||||
TEST_F(CLogUnitTests, LogAlways_EmptyString_IgnoresWithoutCrashing)
|
||||
{
|
||||
CLog testLog(&m_data->m_system);
|
||||
testLog.LogAlways("");
|
||||
}
|
||||
|
||||
TEST_F(CLogUnitTests, LogAlways_NormalString_NoFileName_DoesNotCrash)
|
||||
{
|
||||
CLog testLog(&m_data->m_system);
|
||||
testLog.LogAlways("test");
|
||||
}
|
||||
|
||||
TEST_F(CLogUnitTests, LogAlways_SetFileName_Empty_DoesNotCrash)
|
||||
{
|
||||
CLog testLog(&m_data->m_system);
|
||||
testLog.SetFileName("", false);
|
||||
testLog.LogAlways("test");
|
||||
}
|
||||
|
||||
#if AZ_TRAIT_DISABLE_LOG_ALWAYS_FUZZ_TEST
|
||||
TEST_F(CLogUnitTests, DISABLED_LogAlways_FuzzTest)
|
||||
#else
|
||||
TEST_F(CLogUnitTests, LogAlways_FuzzTest)
|
||||
#endif // AZ_TRAIT_DISABLE_LOG_ALWAYS_FUZZ_TEST
|
||||
{
|
||||
CLog testLog(&m_data->m_system);
|
||||
AZStd::string randomJunkName;
|
||||
|
||||
randomJunkName.resize(128, '\0');
|
||||
|
||||
// expect the mock to repeatedly get called. If we fail this expectation
|
||||
// it means the code is early-outing somewhere and we are not getting coverage.
|
||||
EXPECT_CALL(m_data->m_fileIOMock, Write(_, _, _, _))
|
||||
.WillRepeatedly(
|
||||
Return(AZ::IO::Result(AZ::IO::ResultCode::Success)));
|
||||
|
||||
// don't rely on randomness in unit tests, they need to be repeatable.
|
||||
// the following random generator is not seeded by the time, but by a constant (default 1234).
|
||||
AZ::SimpleLcgRandom randGen;
|
||||
|
||||
for (int trialNumber = 0; trialNumber < NumTrialsToPerform; ++trialNumber)
|
||||
{
|
||||
for (int randomChar = 0; randomChar < randomJunkName.size(); ++randomChar)
|
||||
{
|
||||
// note that this is intentionally allowing null characters to generate.
|
||||
// note that this also puts characters AFTER the null, if a null appears in the mddle.
|
||||
// so that if there are off by one errors they could include cruft afterwards.
|
||||
|
||||
if (randomChar > trialNumber % randomJunkName.size())
|
||||
{
|
||||
// choose this point for the nulls to begin. It makes sure we test every size of string.
|
||||
randomJunkName[randomChar] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
randomJunkName[randomChar] = (char)(randGen.GetRandom() % 256); // this will trigger invalid UTF8 decoding too
|
||||
}
|
||||
}
|
||||
testLog.LogAlways("%s", randomJunkName.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(CLogUnitTests, LogAlways_SetFileName_Correct_DoesNotCrash_WritesToFile)
|
||||
{
|
||||
CLog testLog(&m_data->m_system);
|
||||
testLog.SetFileName("logfile.log", false);
|
||||
|
||||
// EXPECT a call to the file system - if we dont get a call here, it means something went wrong.
|
||||
// it also expects exactly one call to write. One call to log should be one call to write,
|
||||
// or else performance will suffer.
|
||||
|
||||
EXPECT_CALL(m_data->m_fileIOMock, Write(_, _, _, _))
|
||||
.WillOnce(
|
||||
Return(AZ::IO::Result(AZ::IO::ResultCode::Success)));
|
||||
|
||||
testLog.LogAlways("test");
|
||||
}
|
||||
} // end namespace CLogUnitTests
|
||||
|
||||
|
||||
@@ -1,282 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
#include "CrySystem_precompiled.h"
|
||||
|
||||
#include <AzTest/AzTest.h>
|
||||
|
||||
#include <XConsole.h>
|
||||
|
||||
#include <AzCore/UnitTest/UnitTest.h>
|
||||
#include <AzCore/Memory/AllocatorScope.h>
|
||||
#include <AzCore/Debug/TraceMessageBus.h>
|
||||
#include <AzCore/std/functional.h>
|
||||
|
||||
#include <Mocks/ISystemMock.h>
|
||||
|
||||
namespace UnitTests
|
||||
{
|
||||
class RemoteConsoleMock
|
||||
: public IRemoteConsole
|
||||
{
|
||||
public:
|
||||
MOCK_METHOD0(RegisterConsoleVariables, void());
|
||||
MOCK_METHOD0(UnregisterConsoleVariables, void());
|
||||
MOCK_METHOD0(Start, void());
|
||||
MOCK_METHOD0(Stop, void());
|
||||
MOCK_CONST_METHOD0(IsStarted, bool());
|
||||
MOCK_METHOD1(AddLogMessage, void(const char*));
|
||||
MOCK_METHOD1(AddLogWarning, void(const char*));
|
||||
MOCK_METHOD1(AddLogError, void(const char*));
|
||||
MOCK_METHOD0(Update, void());
|
||||
MOCK_METHOD2(RegisterListener, void(IRemoteConsoleListener*, const char*));
|
||||
MOCK_METHOD1(UnregisterListener, void(IRemoteConsoleListener*));
|
||||
};
|
||||
|
||||
struct TestTraceMessageCapture
|
||||
: public AZ::Debug::TraceMessageBus::Handler
|
||||
{
|
||||
using Callback = AZStd::function<void(const char* window, const char* message)>;
|
||||
Callback m_callback;
|
||||
|
||||
TestTraceMessageCapture()
|
||||
{
|
||||
AZ::Debug::TraceMessageBus::Handler::BusConnect();
|
||||
}
|
||||
|
||||
~TestTraceMessageCapture()
|
||||
{
|
||||
AZ::Debug::TraceMessageBus::Handler::BusDisconnect();
|
||||
}
|
||||
|
||||
bool OnError(const char* window, const char* message) override
|
||||
{
|
||||
if (m_callback)
|
||||
{
|
||||
m_callback(window, message);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool OnWarning(const char* window, const char* message) override
|
||||
{
|
||||
if (m_callback)
|
||||
{
|
||||
m_callback(window, message);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
using SystemAllocatorScope = AZ::AllocatorScope<AZ::LegacyAllocator, CryStringAllocator>;
|
||||
|
||||
struct CommandRegistrationUnitTests
|
||||
: public ::testing::Test
|
||||
, public SystemAllocatorScope
|
||||
{
|
||||
CommandRegistrationUnitTests()
|
||||
{
|
||||
EXPECT_CALL(m_system, GetIRemoteConsole())
|
||||
.WillRepeatedly(::testing::Return(&m_remoteConsole));
|
||||
}
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
SystemAllocatorScope::ActivateAllocators();
|
||||
|
||||
memset(&m_stubEnv, 0, sizeof(SSystemGlobalEnvironment));
|
||||
m_stubEnv.pSystem = &m_system;
|
||||
m_priorEnv = gEnv;
|
||||
gEnv = &m_stubEnv;
|
||||
|
||||
// now it safe to set up the console
|
||||
m_console = AZStd::make_unique<CXConsole>();
|
||||
m_stubEnv.pConsole = m_console.get();
|
||||
|
||||
EXPECT_CALL(m_system, GetIConsole())
|
||||
.WillRepeatedly(::testing::Return(m_stubEnv.pConsole));
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
m_console.reset();
|
||||
gEnv = m_priorEnv;
|
||||
SystemAllocatorScope::DeactivateAllocators();
|
||||
}
|
||||
|
||||
::testing::NiceMock<SystemMock> m_system;
|
||||
::testing::NiceMock<RemoteConsoleMock> m_remoteConsole;
|
||||
AZStd::unique_ptr<CXConsole> m_console;
|
||||
SSystemGlobalEnvironment m_stubEnv;
|
||||
SSystemGlobalEnvironment* m_priorEnv = nullptr;
|
||||
};
|
||||
|
||||
TEST_F(CommandRegistrationUnitTests, RegisterUnregisterTest)
|
||||
{
|
||||
using namespace AzFramework;
|
||||
|
||||
{
|
||||
bool result = false;
|
||||
CommandRegistrationBus::BroadcastResult(result, &CommandRegistrationBus::Events::RegisterCommand, "foo", "", 0, [](const AZStd::vector<AZStd::string_view>&) -> CommandResult
|
||||
{
|
||||
return CommandResult::Success;
|
||||
});
|
||||
EXPECT_TRUE(result);
|
||||
}
|
||||
|
||||
{
|
||||
bool result = false;
|
||||
CommandRegistrationBus::BroadcastResult(result, &CommandRegistrationBus::Events::UnregisterCommand, "foo");
|
||||
EXPECT_TRUE(result);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(CommandRegistrationUnitTests, RegisterUnregisterNegativeTest)
|
||||
{
|
||||
using namespace AzFramework;
|
||||
|
||||
// register too many times
|
||||
{
|
||||
auto fnFoo = [](const AZStd::vector<AZStd::string_view>&) -> CommandResult
|
||||
{
|
||||
return CommandResult::Success;
|
||||
};
|
||||
|
||||
bool result = false;
|
||||
CommandRegistrationBus::BroadcastResult(result, &CommandRegistrationBus::Events::RegisterCommand, "foo", "", 0, fnFoo);
|
||||
EXPECT_TRUE(result);
|
||||
CommandRegistrationBus::BroadcastResult(result, &CommandRegistrationBus::Events::RegisterCommand, "foo", "", 0, fnFoo);
|
||||
EXPECT_FALSE(result);
|
||||
}
|
||||
|
||||
// unregister too many times
|
||||
{
|
||||
bool result = false;
|
||||
CommandRegistrationBus::BroadcastResult(result, &CommandRegistrationBus::Events::UnregisterCommand, "foo");
|
||||
EXPECT_TRUE(result);
|
||||
CommandRegistrationBus::BroadcastResult(result, &CommandRegistrationBus::Events::UnregisterCommand, "foo");
|
||||
EXPECT_FALSE(result);
|
||||
}
|
||||
|
||||
// a null callback should fail
|
||||
{
|
||||
AZ_TEST_START_TRACE_SUPPRESSION;
|
||||
bool result = false;
|
||||
CommandRegistrationBus::BroadcastResult(result, &CommandRegistrationBus::Events::RegisterCommand, "shouldfail", "", 0, nullptr);
|
||||
EXPECT_FALSE(result);
|
||||
AZ_TEST_STOP_TRACE_SUPPRESSION(1);
|
||||
}
|
||||
|
||||
// a null identifier should fail
|
||||
{
|
||||
AZ_TEST_START_TRACE_SUPPRESSION;
|
||||
bool result = false;
|
||||
CommandRegistrationBus::BroadcastResult(result, &CommandRegistrationBus::Events::RegisterCommand, "", "", 0, nullptr);
|
||||
EXPECT_FALSE(result);
|
||||
AZ_TEST_STOP_TRACE_SUPPRESSION(1);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(CommandRegistrationUnitTests, DoCallback)
|
||||
{
|
||||
using namespace AzFramework;
|
||||
|
||||
int count = 0;
|
||||
|
||||
{
|
||||
auto fnCommand = [&count](const AZStd::vector<AZStd::string_view>&) -> CommandResult
|
||||
{
|
||||
++count;
|
||||
return CommandResult::Success;
|
||||
};
|
||||
|
||||
bool result = false;
|
||||
CommandRegistrationBus::BroadcastResult(result, &CommandRegistrationBus::Events::RegisterCommand, "bar", "bar docs", CommandFlags::Development, fnCommand);
|
||||
EXPECT_TRUE(result);
|
||||
}
|
||||
|
||||
const bool bSilentMode = true;
|
||||
const bool bDeferExecution = false;
|
||||
m_console->ExecuteString("bar", bSilentMode, bDeferExecution);
|
||||
EXPECT_EQ(1, count);
|
||||
|
||||
{
|
||||
bool result = false;
|
||||
CommandRegistrationBus::BroadcastResult(result, &CommandRegistrationBus::Events::UnregisterCommand, "bar");
|
||||
EXPECT_TRUE(result);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(CommandRegistrationUnitTests, DoCallbackNegativeTests)
|
||||
{
|
||||
using namespace AzFramework;
|
||||
|
||||
bool result = false;
|
||||
CommandRegistrationBus::BroadcastResult(result, &CommandRegistrationBus::Events::RegisterCommand, "bar", "", 0, [](const AZStd::vector<AZStd::string_view>& args)
|
||||
{
|
||||
if (args.size() > 1)
|
||||
{
|
||||
return CommandResult::ErrorWrongNumberOfArguments;
|
||||
}
|
||||
return CommandResult::Error;
|
||||
});
|
||||
EXPECT_TRUE(result);
|
||||
|
||||
const bool bSilentMode = true;
|
||||
const bool bDeferExecution = false;
|
||||
|
||||
// general error
|
||||
{
|
||||
int found = 0;
|
||||
TestTraceMessageCapture capture;
|
||||
capture.m_callback = [&found](const char* window, const char* message)
|
||||
{
|
||||
if (azstrnicmp(window, "console", AZ_ARRAY_SIZE("console") - 1) == 0)
|
||||
{
|
||||
if (azstrnicmp(message, "Command returned a generic error\n", AZ_ARRAY_SIZE("Command returned a generic error\n") - 1) == 0)
|
||||
{
|
||||
++found;
|
||||
}
|
||||
}
|
||||
};
|
||||
m_console->ExecuteString("bar", bSilentMode, bDeferExecution);
|
||||
EXPECT_EQ(1, found);
|
||||
}
|
||||
|
||||
// too many args
|
||||
{
|
||||
int found = 0;
|
||||
TestTraceMessageCapture capture;
|
||||
capture.m_callback = [&found](const char* window, const char* message)
|
||||
{
|
||||
if (azstrnicmp(window, "console", AZ_ARRAY_SIZE("console") - 1) == 0)
|
||||
{
|
||||
if (azstrnicmp(message, "Command does not have the right number of arguments (send = 4)\n", AZ_ARRAY_SIZE("Command does not have the right number of arguments (send = 4)\n") - 1) == 0)
|
||||
{
|
||||
++found;
|
||||
}
|
||||
}
|
||||
};
|
||||
m_console->ExecuteString("bar 1 2 3", bSilentMode, bDeferExecution);
|
||||
EXPECT_EQ(1, found);
|
||||
}
|
||||
|
||||
// clean up
|
||||
{
|
||||
result = false;
|
||||
CommandRegistrationBus::BroadcastResult(result, &CommandRegistrationBus::Events::UnregisterCommand, "bar");
|
||||
EXPECT_TRUE(result);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace UnitTests
|
||||
|
||||
|
||||
@@ -1,463 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
#include "CrySystem_precompiled.h"
|
||||
#include <AzTest/AzTest.h>
|
||||
#include <AzCore/Memory/AllocatorScope.h>
|
||||
|
||||
TEST(StringTests, CUT_Strings)
|
||||
{
|
||||
bool bOk;
|
||||
char bf[4];
|
||||
|
||||
// cry_strcpy()
|
||||
|
||||
bOk = cry_strcpy(0, 0, 0);
|
||||
EXPECT_TRUE(!bOk);
|
||||
|
||||
bOk = cry_strcpy(0, 0, 0, 0);
|
||||
EXPECT_TRUE(!bOk);
|
||||
|
||||
bOk = cry_strcpy(0, 1, 0);
|
||||
EXPECT_TRUE(!bOk);
|
||||
|
||||
bOk = cry_strcpy(0, 1, 0, 1);
|
||||
EXPECT_TRUE(!bOk);
|
||||
|
||||
bOk = cry_strcpy(0, 1, "");
|
||||
EXPECT_TRUE(!bOk);
|
||||
|
||||
bOk = cry_strcpy(0, 1, "", 1);
|
||||
EXPECT_TRUE(!bOk);
|
||||
|
||||
memcpy(bf, "abcd", 4);
|
||||
bOk = cry_strcpy(bf, 0, "");
|
||||
EXPECT_TRUE(!bOk && !memcmp(bf, "abcd", 4));
|
||||
|
||||
memcpy(bf, "abcd", 4);
|
||||
bOk = cry_strcpy(bf, 0, "", 1);
|
||||
EXPECT_TRUE(!bOk && !memcmp(bf, "abcd", 4));
|
||||
|
||||
memcpy(bf, "abcd", 4);
|
||||
bOk = cry_strcpy(bf, 1, 0);
|
||||
EXPECT_TRUE(!bOk && !memcmp(bf, "\000bcd", 4));
|
||||
|
||||
memcpy(bf, "abcd", 4);
|
||||
bOk = cry_strcpy(bf, 1, 0, 0);
|
||||
EXPECT_TRUE(!bOk && !memcmp(bf, "\000bcd", 4));
|
||||
|
||||
memcpy(bf, "abcd", 4);
|
||||
bOk = cry_strcpy(bf, 0);
|
||||
EXPECT_TRUE(!bOk && !memcmp(bf, "\000bcd", 4));
|
||||
|
||||
memcpy(bf, "abcd", 4);
|
||||
bOk = cry_strcpy(bf, 3, "qwerty");
|
||||
EXPECT_TRUE(!bOk && !memcmp(bf, "qw\000d", 4));
|
||||
|
||||
memcpy(bf, "abcd", 4);
|
||||
bOk = cry_strcpy(bf, 3, "qwerty", 4);
|
||||
EXPECT_TRUE(!bOk && !memcmp(bf, "qw\000d", 4));
|
||||
|
||||
memcpy(bf, "abcd", 4);
|
||||
bOk = cry_strcpy(bf, 3, "qwerty", 3);
|
||||
EXPECT_TRUE(!bOk && !memcmp(bf, "qw\000d", 4));
|
||||
|
||||
memcpy(bf, "abcd", 4);
|
||||
bOk = cry_strcpy(bf, 3, "qwerty", 2);
|
||||
EXPECT_TRUE(bOk && !memcmp(bf, "qw\000d", 4));
|
||||
|
||||
memcpy(bf, "abcd", 4);
|
||||
bOk = cry_strcpy(bf, 3, "qwerty", 1);
|
||||
EXPECT_TRUE(bOk && !memcmp(bf, "q\000cd", 4));
|
||||
|
||||
memcpy(bf, "abcd", 4);
|
||||
bOk = cry_strcpy(bf, 3, "qwerty", 0);
|
||||
EXPECT_TRUE(bOk && !memcmp(bf, "\000bcd", 4));
|
||||
|
||||
memcpy(bf, "abcd", 4);
|
||||
bOk = cry_strcpy(bf, "qwerty");
|
||||
EXPECT_TRUE(!bOk && !memcmp(bf, "qwe\000", 4));
|
||||
|
||||
memcpy(bf, "abcd", 4);
|
||||
bOk = cry_strcpy(bf, "qwerty", 4);
|
||||
EXPECT_TRUE(!bOk && !memcmp(bf, "qwe\000", 4));
|
||||
|
||||
memcpy(bf, "abcd", 4);
|
||||
bOk = cry_strcpy(bf, "qwerty", 3);
|
||||
EXPECT_TRUE(bOk && !memcmp(bf, "qwe\000", 4));
|
||||
|
||||
memcpy(bf, "abcd", 4);
|
||||
bOk = cry_strcpy(bf, "qwerty", 2);
|
||||
EXPECT_TRUE(bOk && !memcmp(bf, "qw\000d", 4));
|
||||
|
||||
memcpy(bf, "abcd", 4);
|
||||
bOk = cry_strcpy(bf, "qwe");
|
||||
EXPECT_TRUE(bOk && !memcmp(bf, "qwe\000", 4));
|
||||
|
||||
memcpy(bf, "abcd", 4);
|
||||
bOk = cry_strcpy(bf, "qwe", 4);
|
||||
EXPECT_TRUE(bOk && !memcmp(bf, "qwe\000", 4));
|
||||
|
||||
memcpy(bf, "abcd", 4);
|
||||
bOk = cry_strcpy(bf, "qw", 3);
|
||||
EXPECT_TRUE(bOk && !memcmp(bf, "qw\000d", 4));
|
||||
|
||||
memcpy(bf, "abcd", 4);
|
||||
bOk = cry_strcpy(bf, sizeof(bf), "q");
|
||||
EXPECT_TRUE(bOk && !memcmp(bf, "q\000cd", 4));
|
||||
|
||||
memcpy(bf, "abcd", 4);
|
||||
bOk = cry_strcpy(bf, sizeof(bf), "q", 2);
|
||||
EXPECT_TRUE(bOk && !memcmp(bf, "q\000cd", 4));
|
||||
|
||||
// cry_strcat()
|
||||
|
||||
bOk = cry_strcat(0, 0, 0);
|
||||
EXPECT_TRUE(!bOk);
|
||||
|
||||
bOk = cry_strcat(0, 0, 0, 0);
|
||||
EXPECT_TRUE(!bOk);
|
||||
|
||||
bOk = cry_strcat(0, 1, 0);
|
||||
EXPECT_TRUE(!bOk);
|
||||
|
||||
bOk = cry_strcat(0, 1, 0, 0);
|
||||
EXPECT_TRUE(!bOk);
|
||||
|
||||
bOk = cry_strcat(0, 1, "");
|
||||
EXPECT_TRUE(!bOk);
|
||||
|
||||
bOk = cry_strcat(0, 1, "", 1);
|
||||
EXPECT_TRUE(!bOk);
|
||||
|
||||
memcpy(bf, "abcd", 4);
|
||||
bOk = cry_strcat(bf, 0, "xy");
|
||||
EXPECT_TRUE(!bOk && !memcmp(bf, "abcd", 4));
|
||||
|
||||
memcpy(bf, "abcd", 4);
|
||||
bOk = cry_strcat(bf, 0, "xy", 3);
|
||||
EXPECT_TRUE(!bOk && !memcmp(bf, "abcd", 4));
|
||||
|
||||
memcpy(bf, "abcd", 4);
|
||||
bOk = cry_strcat(bf, 0, "xy", 0);
|
||||
EXPECT_TRUE(!bOk && !memcmp(bf, "abcd", 4));
|
||||
|
||||
memcpy(bf, "abcd", 4);
|
||||
bOk = cry_strcat(bf, 1, "xyz");
|
||||
EXPECT_TRUE(!bOk && !memcmp(bf, "\000bcd", 4));
|
||||
|
||||
memcpy(bf, "abcd", 4);
|
||||
bOk = cry_strcat(bf, 1, "xyz", 4);
|
||||
EXPECT_TRUE(!bOk && !memcmp(bf, "\000bcd", 4));
|
||||
|
||||
memcpy(bf, "abcd", 4);
|
||||
bOk = cry_strcat(bf, 1, "xyz", 1);
|
||||
EXPECT_TRUE(!bOk && !memcmp(bf, "\000bcd", 4));
|
||||
|
||||
memcpy(bf, "abcd", 4);
|
||||
bOk = cry_strcat(bf, 1, "xyz", 0);
|
||||
EXPECT_TRUE(bOk && !memcmp(bf, "\000bcd", 4));
|
||||
|
||||
memcpy(bf, "abcd", 4);
|
||||
bOk = cry_strcat(bf, 1, 0, 0);
|
||||
EXPECT_TRUE(!bOk && !memcmp(bf, "\000bcd", 4));
|
||||
|
||||
memcpy(bf, "a\000cd", 4);
|
||||
bOk = cry_strcat(bf, 3, "xyz");
|
||||
EXPECT_TRUE(!bOk && !memcmp(bf, "ax\000d", 4));
|
||||
|
||||
memcpy(bf, "a\000cd", 4);
|
||||
bOk = cry_strcat(bf, 3, "xyz", 4);
|
||||
EXPECT_TRUE(!bOk && !memcmp(bf, "ax\000d", 4));
|
||||
|
||||
memcpy(bf, "a\000cd", 4);
|
||||
bOk = cry_strcat(bf, 3, "xyz", 2);
|
||||
EXPECT_TRUE(!bOk && !memcmp(bf, "ax\000d", 4));
|
||||
|
||||
memcpy(bf, "a\000cd", 4);
|
||||
bOk = cry_strcat(bf, 3, "xyz", 1);
|
||||
EXPECT_TRUE(bOk && !memcmp(bf, "ax\000d", 4));
|
||||
|
||||
memcpy(bf, "abcd", 4);
|
||||
bOk = cry_strcat(bf, "xyz");
|
||||
EXPECT_TRUE(!bOk && !memcmp(bf, "abc\000", 4));
|
||||
|
||||
memcpy(bf, "abcd", 4);
|
||||
bOk = cry_strcat(bf, "xyz", 4);
|
||||
EXPECT_TRUE(!bOk && !memcmp(bf, "abc\000", 4));
|
||||
|
||||
memcpy(bf, "abcd", 4);
|
||||
bOk = cry_strcat(bf, "xyz", 1);
|
||||
EXPECT_TRUE(!bOk && !memcmp(bf, "abc\000", 4));
|
||||
|
||||
memcpy(bf, "abcd", 4);
|
||||
bOk = cry_strcat(bf, "xyz", 0);
|
||||
EXPECT_TRUE(bOk && !memcmp(bf, "abc\000", 4));
|
||||
|
||||
memcpy(bf, "ab\000d", 4);
|
||||
bOk = cry_strcat(bf, "xyz");
|
||||
EXPECT_TRUE(!bOk && !memcmp(bf, "abx\000", 4));
|
||||
|
||||
memcpy(bf, "ab\000d", 4);
|
||||
bOk = cry_strcat(bf, "xyz", 4);
|
||||
EXPECT_TRUE(!bOk && !memcmp(bf, "abx\000", 4));
|
||||
|
||||
memcpy(bf, "ab\000d", 4);
|
||||
bOk = cry_strcat(bf, "xyz", 1);
|
||||
EXPECT_TRUE(bOk && !memcmp(bf, "abx\000", 4));
|
||||
|
||||
memcpy(bf, "ab\000d", 4);
|
||||
bOk = cry_strcat(bf, "xyz", 0);
|
||||
EXPECT_TRUE(bOk && !memcmp(bf, "ab\000d", 4));
|
||||
|
||||
memcpy(bf, "ab\000d", 4);
|
||||
bOk = cry_strcat(bf, 0, 0);
|
||||
EXPECT_TRUE(!bOk && !memcmp(bf, "ab\000d", 4));
|
||||
|
||||
memcpy(bf, "ab\000d", 4);
|
||||
bOk = cry_strcat(bf, 0, 1);
|
||||
EXPECT_TRUE(!bOk && !memcmp(bf, "ab\000d", 4));
|
||||
|
||||
memcpy(bf, "a\000cd", 4);
|
||||
bOk = cry_strcat(bf, sizeof(bf), "xy");
|
||||
EXPECT_TRUE(bOk && !memcmp(bf, "axy\000", 4));
|
||||
|
||||
memcpy(bf, "a\000cd", 4);
|
||||
bOk = cry_strcat(bf, sizeof(bf), "xy", 3);
|
||||
EXPECT_TRUE(bOk && !memcmp(bf, "axy\000", 4));
|
||||
|
||||
memcpy(bf, "a\000cd", 4);
|
||||
bOk = cry_strcat(bf, sizeof(bf), "xy", 1);
|
||||
EXPECT_TRUE(bOk && !memcmp(bf, "ax\000d", 4));
|
||||
}
|
||||
|
||||
using CryPrimitivesAllocatorScope = AZ::AllocatorScope<AZ::LegacyAllocator, CryStringAllocator>;
|
||||
|
||||
class CryPrimitives
|
||||
: public ::testing::Test
|
||||
{
|
||||
public:
|
||||
void SetUp() override
|
||||
{
|
||||
m_memory.ActivateAllocators();
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
m_memory.DeactivateAllocators();
|
||||
}
|
||||
|
||||
CryPrimitivesAllocatorScope m_memory;
|
||||
};
|
||||
|
||||
TEST_F(CryPrimitives, CUT_CryString)
|
||||
{
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Based on MS documentation of find_last_of
|
||||
string strTestFindLastOfOverload1("abcd-1234-abcd-1234");
|
||||
string strTestFindLastOfOverload2("ABCD-1234-ABCD-1234");
|
||||
string strTestFindLastOfOverload3("456-EFG-456-EFG");
|
||||
string strTestFindLastOfOverload4("12-ab-12-ab");
|
||||
|
||||
const char* cstr2 = "B1";
|
||||
const char* cstr2b = "D2";
|
||||
const char* cstr3a = "5E";
|
||||
string str4a("ba3");
|
||||
string str4b("a2");
|
||||
|
||||
size_t nPosition(string::npos);
|
||||
|
||||
nPosition = strTestFindLastOfOverload1.find_last_of('d', 14);
|
||||
EXPECT_TRUE(nPosition == 13);
|
||||
|
||||
|
||||
nPosition = strTestFindLastOfOverload2.find_last_of(cstr2, 12);
|
||||
EXPECT_TRUE(nPosition == 11);
|
||||
|
||||
|
||||
nPosition = strTestFindLastOfOverload2.find_last_of(cstr2b);
|
||||
EXPECT_TRUE(nPosition == 16);
|
||||
|
||||
|
||||
nPosition = strTestFindLastOfOverload3.find_last_of(cstr3a, 8, 2);
|
||||
EXPECT_TRUE(nPosition == 4);
|
||||
|
||||
|
||||
nPosition = strTestFindLastOfOverload4.find_last_of(str4a, 8);
|
||||
EXPECT_TRUE(nPosition == 4);
|
||||
|
||||
|
||||
nPosition = strTestFindLastOfOverload4.find_last_of(str4b);
|
||||
EXPECT_TRUE(nPosition == 9);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Based on MS documentation of find_last_not_of
|
||||
string strTestFindLastNotOfOverload1("dddd-1dd4-abdd");
|
||||
string strTestFindLastNotOfOverload2("BBB-1111");
|
||||
string strTestFindLastNotOfOverload3("444-555-GGG");
|
||||
string strTestFindLastNotOfOverload4("12-ab-12-ab");
|
||||
|
||||
const char* cstr2NF = "B1";
|
||||
const char* cstr3aNF = "45G";
|
||||
const char* cstr3bNF = "45G";
|
||||
|
||||
string str4aNF("b-a");
|
||||
string str4bNF("12");
|
||||
|
||||
nPosition = strTestFindLastNotOfOverload1.find_last_not_of('d', 7);
|
||||
EXPECT_TRUE(nPosition == 5);
|
||||
|
||||
nPosition = strTestFindLastNotOfOverload1.find_last_not_of("d");
|
||||
EXPECT_TRUE(nPosition == 11);
|
||||
|
||||
nPosition = strTestFindLastNotOfOverload2.find_last_not_of(cstr2NF, 6);
|
||||
EXPECT_TRUE(nPosition == 3);
|
||||
|
||||
nPosition = strTestFindLastNotOfOverload3.find_last_not_of(cstr3aNF);
|
||||
EXPECT_TRUE(nPosition == 7);
|
||||
|
||||
nPosition = strTestFindLastNotOfOverload3.find_last_not_of(cstr3bNF, 6, 3);//nPosition - 1 );
|
||||
EXPECT_TRUE(nPosition == 3);
|
||||
|
||||
nPosition = strTestFindLastNotOfOverload4.find_last_not_of(str4aNF, 5);
|
||||
EXPECT_TRUE(nPosition == 1);
|
||||
|
||||
nPosition = strTestFindLastNotOfOverload4.find_last_not_of(str4bNF);
|
||||
EXPECT_TRUE(nPosition == 10);
|
||||
}
|
||||
|
||||
|
||||
TEST_F(CryPrimitives, CUT_FixedString)
|
||||
{
|
||||
CryStackStringT<char, 10> str1;
|
||||
CryStackStringT<char, 10> str2;
|
||||
CryStackStringT<char, 4> str3;
|
||||
CryStackStringT<char, 10> str4;
|
||||
CryStackStringT<char, 6> str5;
|
||||
CryStackStringT<wchar_t, 16> wstr1;
|
||||
CryStackStringT<wchar_t, 255> wstr2;
|
||||
CryFixedStringT<100> fixedString100;
|
||||
CryFixedStringT<200> fixedString200;
|
||||
|
||||
typedef CryStackStringT<char, 10> T;
|
||||
T* pStr = new T;
|
||||
*pStr = "adads";
|
||||
delete pStr;
|
||||
|
||||
str1 = "abcd";
|
||||
EXPECT_EQ(str1, "abcd");
|
||||
|
||||
str2 = "efg";
|
||||
EXPECT_EQ(str2, "efg");
|
||||
|
||||
str2 = str1;
|
||||
EXPECT_EQ(str2, "abcd");
|
||||
|
||||
str1 += "XY";
|
||||
EXPECT_EQ(str1, "abcdXY");
|
||||
|
||||
str2 += "efghijk";
|
||||
EXPECT_EQ(str2, "abcdefghijk");
|
||||
|
||||
str1.replace("bc", "");
|
||||
EXPECT_EQ(str1, "adXY");
|
||||
|
||||
str1.replace("XY", "1234");
|
||||
EXPECT_EQ(str1, "ad1234");
|
||||
|
||||
str1.replace("1234", "1234567890");
|
||||
EXPECT_EQ(str1, "ad1234567890");
|
||||
|
||||
str1.reserve(200);
|
||||
EXPECT_EQ(str1, "ad1234567890");
|
||||
EXPECT_TRUE(str1.capacity() == 200);
|
||||
|
||||
str1.reserve(0);
|
||||
EXPECT_EQ(str1, "ad1234567890");
|
||||
EXPECT_TRUE(str1.capacity() == str1.length());
|
||||
|
||||
str1.erase(7); // doesn't change capacity
|
||||
EXPECT_EQ(str1, "ad12345");
|
||||
|
||||
str4.assign("abc");
|
||||
EXPECT_EQ(str4, "abc");
|
||||
str4.reserve(9);
|
||||
EXPECT_TRUE(str4.capacity() >= 9); // capacity is always >= MAX_SIZE-1
|
||||
str4.reserve(0);
|
||||
EXPECT_TRUE(str4.capacity() >= 9); // capacity is always >= MAX_SIZE-1
|
||||
|
||||
size_t idx = str1.find("123");
|
||||
EXPECT_TRUE(idx == 2);
|
||||
|
||||
idx = str1.find("123", 3);
|
||||
EXPECT_TRUE(idx == str1.npos);
|
||||
|
||||
wstr1 = L"abc";
|
||||
EXPECT_EQ(wstr1, L"abc");
|
||||
EXPECT_TRUE(wstr1.compare(L"aBc") > 0);
|
||||
EXPECT_TRUE(wstr1.compare(L"babc") < 0);
|
||||
EXPECT_TRUE(wstr1.compareNoCase(L"aBc") == 0);
|
||||
|
||||
str1.Format("This is a %s %ls with %d params", "mixed", L"string", 3);
|
||||
str2.Format("This is a %ls %s with %d params", L"mixed", "string", 3);
|
||||
EXPECT_EQ(str1, "This is a mixed string with 3 params");
|
||||
EXPECT_EQ(str1, str2);
|
||||
|
||||
wstr1.Format(L"This is a %ls %hs with %d params", L"mixed", "string", 3);
|
||||
wstr2.Format(L"This is a %hs %ls with %d params", "mixed", L"string", 3);
|
||||
EXPECT_EQ(wstr1, L"This is a mixed string with 3 params");
|
||||
|
||||
str5.FormatFast("%s", "12345");
|
||||
EXPECT_EQ("1234", str5);
|
||||
|
||||
// we expect here that the string gets cut since it doesn't fit into the string buffer
|
||||
str5.FormatFast("%s", "012345");
|
||||
EXPECT_EQ("0123", str5);
|
||||
}
|
||||
|
||||
TEST_F(CryPrimitives, CUT_DynArray)
|
||||
{
|
||||
LegacyDynArray<int> a;
|
||||
a.push_back(3);
|
||||
a.insert(&a[0], 1, 1);
|
||||
a.insert(&a[1], 1, 2);
|
||||
a.insert(&a[0], 1, 0);
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
EXPECT_TRUE(a[i] == i);
|
||||
}
|
||||
|
||||
const int nStrs = 11;
|
||||
string Strs[nStrs] = { "nought", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten" };
|
||||
LegacyDynArray<string> s;
|
||||
for (int i = 0; i < nStrs; i += 2)
|
||||
{
|
||||
s.push_back(Strs[i]);
|
||||
}
|
||||
for (int i = 1; i < nStrs; i += 2)
|
||||
{
|
||||
s.insert(i, Strs[i]);
|
||||
}
|
||||
for (int i = 0; i < nStrs; i++)
|
||||
{
|
||||
EXPECT_TRUE(s[i] == Strs[i]);
|
||||
}
|
||||
|
||||
LegacyDynArray<string> s2 = s;
|
||||
s.erase(5, 2);
|
||||
EXPECT_TRUE(s.size() == nStrs - 2);
|
||||
|
||||
s.insert(&s[3], &Strs[5], &Strs[8]);
|
||||
|
||||
s2 = s2(3, 4);
|
||||
EXPECT_TRUE(s2.size() == 4);
|
||||
}
|
||||
@@ -1,157 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
#include "CrySystem_precompiled.h"
|
||||
#include <AzTest/AzTest.h>
|
||||
#include <AzCore/Memory/AllocatorScope.h>
|
||||
#include "LocalizedStringManager.h"
|
||||
#include <Mocks/ISystemMock.h>
|
||||
#include <Mocks/IConsoleMock.h>
|
||||
#include <Mocks/ICryPakMock.h>
|
||||
#include <Mocks/ICVarMock.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
class SystemEventDispatcherMock
|
||||
: public ISystemEventDispatcher
|
||||
{
|
||||
public:
|
||||
virtual ~SystemEventDispatcherMock() {}
|
||||
MOCK_METHOD1(RegisterListener, bool(ISystemEventListener* pListener));
|
||||
MOCK_METHOD1(RemoveListener, bool(ISystemEventListener* pListener));
|
||||
MOCK_METHOD3(OnSystemEvent, void(ESystemEvent event, UINT_PTR wparam, UINT_PTR lparam));
|
||||
MOCK_METHOD0(Update, void());
|
||||
};
|
||||
|
||||
using namespace testing;
|
||||
using ::testing::NiceMock;
|
||||
|
||||
using SystemAllocatorScope = AZ::AllocatorScope<AZ::LegacyAllocator, CryStringAllocator>;
|
||||
|
||||
class SystemFixture
|
||||
: public ::testing::Test
|
||||
, public SystemAllocatorScope
|
||||
{
|
||||
public:
|
||||
SystemFixture()
|
||||
{
|
||||
EXPECT_CALL(m_system, GetISystemEventDispatcher())
|
||||
.WillRepeatedly(Return(&m_dispatcher));
|
||||
|
||||
EXPECT_CALL(m_console, GetCVar(_))
|
||||
.WillRepeatedly(Return(&m_cvarMock));
|
||||
|
||||
EXPECT_CALL(m_cryPak, FindFirst(_, _, _))
|
||||
.WillRepeatedly(Return(AZ::IO::ArchiveFileIterator{}));
|
||||
|
||||
EXPECT_CALL(m_cryPak, GetLocalizationFolder())
|
||||
.WillRepeatedly(Return("french"));
|
||||
|
||||
EXPECT_CALL(m_cvarMock, GetFlags())
|
||||
.WillRepeatedly(Return(VF_WASINCONFIG));
|
||||
}
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
SystemAllocatorScope::ActivateAllocators();
|
||||
|
||||
memset(&m_stubEnv, 0, sizeof(SSystemGlobalEnvironment));
|
||||
m_stubEnv.pConsole = &m_console;
|
||||
m_stubEnv.pSystem = &m_system;
|
||||
m_stubEnv.pCryPak = &m_cryPak;
|
||||
m_stubEnv.pLog = nullptr;
|
||||
m_priorEnv = gEnv;
|
||||
gEnv = &m_stubEnv;
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
gEnv = m_priorEnv;
|
||||
|
||||
SystemAllocatorScope::DeactivateAllocators();
|
||||
}
|
||||
|
||||
NiceMock<SystemMock> m_system;
|
||||
NiceMock<SystemEventDispatcherMock> m_dispatcher;
|
||||
NiceMock<ConsoleMock> m_console;
|
||||
NiceMock<CryPakMock> m_cryPak;
|
||||
NiceMock<CVarMock> m_cvarMock;
|
||||
SSystemGlobalEnvironment m_stubEnv;
|
||||
SSystemGlobalEnvironment* m_priorEnv = nullptr;
|
||||
};
|
||||
|
||||
class UnitTestCLocalizedStringsManager : public CLocalizedStringsManager
|
||||
{
|
||||
public:
|
||||
UnitTestCLocalizedStringsManager(ISystem* pSystem) : CLocalizedStringsManager(pSystem)
|
||||
{
|
||||
}
|
||||
|
||||
bool LocalizeLabel(const char* sLabel, string& outLocalizedString, bool bEnglish = false) override
|
||||
{
|
||||
m_capturedLabels.push_back(sLabel);
|
||||
return CLocalizedStringsManager::LocalizeLabel(sLabel, outLocalizedString, bEnglish);
|
||||
}
|
||||
|
||||
std::vector<string> m_capturedLabels;
|
||||
|
||||
friend class GTEST_TEST_CLASS_NAME_(SystemFixture, LocalizeStringInternal_WhitespaceCharacters_CorrectlyTokenizes);
|
||||
};
|
||||
|
||||
// this test makes sure that whitespace characters such as tab work (not just space) and are considered to be separators.
|
||||
TEST_F(SystemFixture, LocalizeStringInternal_SpecificWhitespaceCharacters_CorrectlyTokenizes)
|
||||
{
|
||||
UnitTestCLocalizedStringsManager manager(&m_system);
|
||||
manager.SetLanguage("french");
|
||||
|
||||
string outString;
|
||||
manager.LocalizeString_s("@hello\t@world", outString, false);
|
||||
ASSERT_EQ(manager.m_capturedLabels.size(), 2);
|
||||
EXPECT_STREQ(manager.m_capturedLabels[0].c_str(), "@hello");
|
||||
EXPECT_STREQ(manager.m_capturedLabels[1].c_str(), "@world");
|
||||
manager.m_capturedLabels.clear();
|
||||
|
||||
manager.LocalizeString_s("@hello\n@world", outString, false);
|
||||
ASSERT_EQ(manager.m_capturedLabels.size(), 2);
|
||||
EXPECT_STREQ(manager.m_capturedLabels[0].c_str(), "@hello");
|
||||
EXPECT_STREQ(manager.m_capturedLabels[1].c_str(), "@world");
|
||||
manager.m_capturedLabels.clear();
|
||||
|
||||
manager.LocalizeString_s("@hello\r@world", outString, false);
|
||||
ASSERT_EQ(manager.m_capturedLabels.size(), 2);
|
||||
EXPECT_STREQ(manager.m_capturedLabels[0].c_str(), "@hello");
|
||||
EXPECT_STREQ(manager.m_capturedLabels[1].c_str(), "@world");
|
||||
manager.m_capturedLabels.clear();
|
||||
|
||||
manager.LocalizeString_s("@hello @world", outString, false);
|
||||
ASSERT_EQ(manager.m_capturedLabels.size(), 2);
|
||||
EXPECT_STREQ(manager.m_capturedLabels[0].c_str(), "@hello");
|
||||
EXPECT_STREQ(manager.m_capturedLabels[1].c_str(), "@world");
|
||||
manager.m_capturedLabels.clear();
|
||||
}
|
||||
|
||||
|
||||
// this test makes sure that multiple whitespace characters in a row don't themselves count as tokens or change the output in undesirable ways.
|
||||
TEST_F(SystemFixture, LocalizeStringInternal_ManyWhitespaceCharacters_CorrectlyTokenizes)
|
||||
{
|
||||
UnitTestCLocalizedStringsManager manager(&m_system);
|
||||
manager.SetLanguage("french");
|
||||
|
||||
string outString;
|
||||
const char* testString = "@hello\n\r\t \t\r\n@world\n\r\t ";
|
||||
manager.LocalizeString_ch(testString, outString, false);
|
||||
ASSERT_EQ(manager.m_capturedLabels.size(), 2);
|
||||
EXPECT_STREQ(manager.m_capturedLabels[0].c_str(), "@hello");
|
||||
EXPECT_STREQ(manager.m_capturedLabels[1].c_str(), "@world");
|
||||
|
||||
// since there are no localizations available it should not have gobbled up whitespace or altered it.
|
||||
EXPECT_STREQ(outString, testString);
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
#include "CrySystem_precompiled.h"
|
||||
#include <AzTest/AzTest.h>
|
||||
#include <AzCore/Memory/OSAllocator.h>
|
||||
#include <AzCore/Memory/SystemAllocator.h>
|
||||
#include <LegacyAllocator.h>
|
||||
#include <System.h>
|
||||
|
||||
namespace UnitTests
|
||||
{
|
||||
class CSystemUnitTests
|
||||
: public ::testing::Test
|
||||
{
|
||||
public:
|
||||
void SetUp() override
|
||||
{
|
||||
SSystemInitParams startupParams;
|
||||
AZ::AllocatorInstance<AZ::LegacyAllocator>::Create();
|
||||
AZ::AllocatorInstance<CryStringAllocator>::Create();
|
||||
m_system = new CSystem(startupParams.pSharedEnvironment);
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
delete m_system;
|
||||
AZ::AllocatorInstance<CryStringAllocator>::Destroy();
|
||||
AZ::AllocatorInstance<AZ::LegacyAllocator>::Destroy();
|
||||
}
|
||||
|
||||
|
||||
CSystem* m_system = nullptr;
|
||||
};
|
||||
|
||||
TEST_F(CSystemUnitTests, ApplicationLogInstanceUnitTests)
|
||||
{
|
||||
const char dummyString[] = "dummy";
|
||||
const char testString[] = "test";
|
||||
EXPECT_EQ(m_system->GetApplicationLogInstance(dummyString), 0);
|
||||
EXPECT_EQ(m_system->GetApplicationLogInstance(testString), 0);
|
||||
#if AZ_TRAIT_OS_USE_WINDOWS_MUTEX
|
||||
EXPECT_EQ(m_system->GetApplicationLogInstance(dummyString), 1);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
#include "CrySystem_precompiled.h"
|
||||
#include <AzTest/AzTest.h>
|
||||
#include <AzCore/Memory/OSAllocator.h>
|
||||
#include <AzCore/Memory/SystemAllocator.h>
|
||||
#include <AzCore/UnitTest/UnitTest.h>
|
||||
|
||||
class CrySystemTestEnvironment
|
||||
: public AZ::Test::ITestEnvironment
|
||||
, public ::UnitTest::TraceBusRedirector
|
||||
{
|
||||
public:
|
||||
virtual ~CrySystemTestEnvironment()
|
||||
{}
|
||||
|
||||
protected:
|
||||
void SetupEnvironment() override
|
||||
{
|
||||
AZ::AllocatorInstance<AZ::OSAllocator>::Create();
|
||||
AZ::AllocatorInstance<AZ::SystemAllocator>::Create();
|
||||
|
||||
::UnitTest::TraceBusRedirector::BusConnect();
|
||||
}
|
||||
|
||||
void TeardownEnvironment() override
|
||||
{
|
||||
::UnitTest::TraceBusRedirector::BusDisconnect();
|
||||
AZ::AllocatorInstance<AZ::OSAllocator>::Destroy();
|
||||
AZ::AllocatorInstance<AZ::SystemAllocator>::Destroy();
|
||||
}
|
||||
};
|
||||
|
||||
AZ_UNIT_TEST_HOOK(new CrySystemTestEnvironment)
|
||||
@@ -1,84 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
#include "CrySystem_precompiled.h"
|
||||
#include <AzTest/AzTest.h>
|
||||
|
||||
#include <AzCore/base.h>
|
||||
#include <AzCore/IO/SystemFile.h>
|
||||
#include "MaterialUtils.h"
|
||||
|
||||
#include <IConsole.h>
|
||||
|
||||
|
||||
TEST(CrySystemMaterialUtilsTests, MaterialUtilsTestBasics)
|
||||
{
|
||||
char tempBuffer[AZ_MAX_PATH_LEN] = { 0 };
|
||||
// call to ensure that it handles nullptr without crashing
|
||||
MaterialUtils::UnifyMaterialName(nullptr);
|
||||
MaterialUtils::UnifyMaterialName(tempBuffer);
|
||||
EXPECT_TRUE(tempBuffer[0] == 0);
|
||||
}
|
||||
|
||||
TEST(CrySystemMaterialUtilsTests, MaterialUtilsTestExtensions)
|
||||
{
|
||||
char tempBuffer[AZ_MAX_PATH_LEN];
|
||||
azstrcpy(tempBuffer, AZ_MAX_PATH_LEN, "blahblah.mtl");
|
||||
MaterialUtils::UnifyMaterialName(tempBuffer);
|
||||
EXPECT_TRUE(strcmp(tempBuffer, "blahblah") == 0);
|
||||
|
||||
azstrcpy(tempBuffer, AZ_MAX_PATH_LEN, "blahblah.mat.mat.abc.test.mtl");
|
||||
MaterialUtils::UnifyMaterialName(tempBuffer);
|
||||
EXPECT_TRUE(strcmp(tempBuffer, "blahblah.mat.mat.abc.test") == 0);
|
||||
|
||||
azstrcpy(tempBuffer, AZ_MAX_PATH_LEN, "test/.mat.mat/blahblah.mat.mat.abc.test.mtl");
|
||||
MaterialUtils::UnifyMaterialName(tempBuffer);
|
||||
EXPECT_TRUE(strcmp(tempBuffer, "test/.mat.mat/blahblah.mat.mat.abc.test") == 0);
|
||||
|
||||
azstrcpy(tempBuffer, AZ_MAX_PATH_LEN, ".mat.mat.blahblah.mat.mat.abc.test.mtl");
|
||||
MaterialUtils::UnifyMaterialName(tempBuffer);
|
||||
EXPECT_TRUE(strcmp(tempBuffer, ".mat.mat.blahblah.mat.mat.abc.test") == 0);
|
||||
}
|
||||
|
||||
TEST(CrySystemMaterialUtilsTests, MaterialUtilsTestPrefixes)
|
||||
{
|
||||
char tempBuffer[AZ_MAX_PATH_LEN];
|
||||
azstrcpy(tempBuffer, AZ_MAX_PATH_LEN, ".\\blahblah.mat");
|
||||
MaterialUtils::UnifyMaterialName(tempBuffer);
|
||||
EXPECT_TRUE(strcmp(tempBuffer, "blahblah") == 0);
|
||||
|
||||
azstrcpy(tempBuffer, AZ_MAX_PATH_LEN, "./materials/blahblah.mat.mat.abc.test");
|
||||
MaterialUtils::UnifyMaterialName(tempBuffer);
|
||||
EXPECT_TRUE(strcmp(tempBuffer, "materials/blahblah.mat.mat.abc") == 0);
|
||||
|
||||
azstrcpy(tempBuffer, AZ_MAX_PATH_LEN, ".\\engine\\materials\\blahblah.mat.mat.abc.test");
|
||||
MaterialUtils::UnifyMaterialName(tempBuffer);
|
||||
EXPECT_TRUE(strcmp(tempBuffer, "materials/blahblah.mat.mat.abc") == 0);
|
||||
|
||||
azstrcpy(tempBuffer, AZ_MAX_PATH_LEN, "engine/materials/blahblah.mat.mat.abc.test");
|
||||
MaterialUtils::UnifyMaterialName(tempBuffer);
|
||||
EXPECT_TRUE(strcmp(tempBuffer, "materials/blahblah.mat.mat.abc") == 0);
|
||||
|
||||
azstrcpy(tempBuffer, AZ_MAX_PATH_LEN, "materials/blahblah.mat");
|
||||
MaterialUtils::UnifyMaterialName(tempBuffer);
|
||||
EXPECT_TRUE(strcmp(tempBuffer, "materials/blahblah") == 0);
|
||||
}
|
||||
|
||||
TEST(CrySystemMaterialUtilsTests, MaterialUtilsTestGameName)
|
||||
{
|
||||
char tempBuffer[AZ_MAX_PATH_LEN];
|
||||
|
||||
auto projectName = AZ::Utils::GetProjectName();
|
||||
azsnprintf(tempBuffer, AZ_MAX_PATH_LEN, ".\\%s\\materials\\blahblah.mat.mat.abc.test", projectName.c_str());
|
||||
|
||||
MaterialUtils::UnifyMaterialName(tempBuffer);
|
||||
EXPECT_TRUE(strcmp(tempBuffer, "materials/blahblah.mat.mat.abc") == 0);
|
||||
}
|
||||
@@ -31,7 +31,7 @@ public:
|
||||
|
||||
// interface ITimer ----------------------------------------------------------
|
||||
|
||||
// TODO: Review m_time usage in System.cpp / SystemRender.cpp
|
||||
// TODO: Review m_time usage in System.cpp
|
||||
// if it wants Game Time / UI Time or a new Render Time?
|
||||
|
||||
virtual void ResetTimer();
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,573 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
// Description : Console implementation for UNIX systems, based on curses ncurses.
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
#include <IConsole.h>
|
||||
#include <ITextModeConsole.h>
|
||||
|
||||
#if defined(USE_DEDICATED_SERVER_CONSOLE)
|
||||
|
||||
class CSyslogStats
|
||||
{
|
||||
public:
|
||||
CSyslogStats();
|
||||
~CSyslogStats();
|
||||
|
||||
void Init();
|
||||
void Update(float srvRate, int numPlayers);
|
||||
|
||||
private:
|
||||
int m_syslog_stats;
|
||||
int m_syslog_period;
|
||||
CTimeValue m_syslogStartTime;
|
||||
CTimeValue m_syslogCurrTime;
|
||||
static const int SYSLOG_DEFAULT_PERIOD = 3000; // default timeout (sec)
|
||||
};
|
||||
|
||||
#if defined(USE_UNIXCONSOLE)
|
||||
|
||||
#if defined(WIN32)
|
||||
// Avoid naming conflict with wincon.h.
|
||||
#undef MOUSE_MOVED
|
||||
#endif
|
||||
|
||||
#include <CryThread.h>
|
||||
#include <ncurses.h>
|
||||
|
||||
// Avoid naming conflicts with pdcurses.
|
||||
// Use werase(stdscr) instead of erase().
|
||||
#undef erase
|
||||
// Use wclear(stdscr) instead of clear().
|
||||
#undef clear
|
||||
// (MATT) Could not compile CONTAINER_VALUE etc templates for Vector{Map,Set} in ISerialise apparently because of the
|
||||
// clear and erase macros. Changed order to undefine them straight after pdcurses. {2009/04/09}
|
||||
|
||||
#include <deque>
|
||||
|
||||
|
||||
// Define if you wish to enable the player count feature.
|
||||
// Note: The player count feature can not be used when building
|
||||
// Windows-style DLLs!
|
||||
#if defined(LINUX) || defined(MAC)
|
||||
#define UC_ENABLE_PLAYER_COUNT 1
|
||||
#else
|
||||
#undef UC_ENABLE_PLAYER_COUNT
|
||||
#endif
|
||||
|
||||
// Define if you wish to enable magic console commands.
|
||||
// These are commands starting with an '@' character, which are intercepted by
|
||||
// the CUNIXConsole class and not passed to the system.
|
||||
//#undef UC_ENABLE_MAGIC_COMMANDS
|
||||
#define UC_ENABLE_MAGIC_COMMANDS 1
|
||||
|
||||
class CUNIXConsoleInputThread;
|
||||
class CUNIXConsoleSignalHandler;
|
||||
|
||||
|
||||
class CUNIXConsole
|
||||
: public ISystemUserCallback
|
||||
, public IOutputPrintSink
|
||||
, public ITextModeConsole
|
||||
{
|
||||
friend class CUNIXConsoleInputThread;
|
||||
friend class CUNIXConsoleSignalHandler;
|
||||
|
||||
static const int DEFAULT_COLOR = -1;
|
||||
|
||||
typedef CryMutex ConsoleLock;
|
||||
ConsoleLock m_Lock;
|
||||
static CryCriticalSectionNonRecursive m_cleanupLock;
|
||||
|
||||
enum EConDrawOp
|
||||
{
|
||||
eCDO_PutText,
|
||||
};
|
||||
struct SConDrawCmd
|
||||
{
|
||||
EConDrawOp op;
|
||||
int x, y;
|
||||
char text[256];
|
||||
};
|
||||
DynArray<SConDrawCmd> m_drawCmds;
|
||||
DynArray<SConDrawCmd> m_newCmds;
|
||||
bool m_fsMode;
|
||||
|
||||
CSyslogStats m_syslogStats;
|
||||
bool m_bShowConsole; // hide or show console
|
||||
|
||||
SSystemUpdateStats m_updStats;
|
||||
|
||||
bool IsLocked() { return m_Lock.IsLocked(); }
|
||||
|
||||
// The header string.
|
||||
//
|
||||
// Should be set by the launcher through SetHeader().
|
||||
string m_HeaderString;
|
||||
|
||||
// The line buffer.
|
||||
//
|
||||
// We'll use the escape sequence "\1" followed by a digit to encode color
|
||||
// changes.
|
||||
typedef std::deque<string> TLineBuffer;
|
||||
TLineBuffer m_LineBuffer;
|
||||
|
||||
// The command queue.
|
||||
//
|
||||
// Commands typed on the console are added to this command queue. It is
|
||||
// processed by the OnUpdate() callback.
|
||||
typedef std::deque<string> TCommandQueue;
|
||||
TCommandQueue m_CommandQueue;
|
||||
|
||||
// The command history.
|
||||
//
|
||||
// The UNIX console is decoupled from the system console object through a
|
||||
// command queue, so we can't use the history buffer from the system
|
||||
// console. This is our own command history.
|
||||
//
|
||||
// The history index indicates the reverse index (counting from the end)
|
||||
// into our command history. The special value -1 indicates that we're not
|
||||
// currently showing a command from the history.
|
||||
typedef std::deque<string> TCommandHistory;
|
||||
TCommandHistory m_CommandHistory;
|
||||
int m_HistoryIndex;
|
||||
|
||||
// Interactive prompt.
|
||||
//
|
||||
// If this is not empty, then this prompt is shown in the command area. The
|
||||
// input thread will wait for one if the response characters. The response is
|
||||
// stored to m_PromptResponse and m_PromptCond is notified.
|
||||
string m_Prompt;
|
||||
char m_PromptResponseChars[16]; // Null-terminated.
|
||||
char m_PromptResponse;
|
||||
CryConditionVariable m_PromptCond;
|
||||
|
||||
ISystem* m_pSystem;
|
||||
IConsole* m_pConsole;
|
||||
ITimer* m_pTimer; // Initialized on the first call to OnUpdate().
|
||||
|
||||
// Flag indicating if OnUpdate() has been called.
|
||||
//
|
||||
// The initialization of the console variable pointers for 'sv_map' and
|
||||
// 'sv_gamerules' is deferred until the first iteration of the update loop,
|
||||
// because OnInit() is called too early for that.
|
||||
bool m_OnUpdateCalled;
|
||||
CTimeValue m_LastUpdateTime;
|
||||
|
||||
ICVar* m_svMap;
|
||||
ICVar* m_svGameRules;
|
||||
|
||||
// Terminal window layout.
|
||||
//
|
||||
// The terminal window is split into 4 logical windows. Top to bottom,
|
||||
// these windows are:
|
||||
// - Header window. May be empty (height 0).
|
||||
// - Log window. This is the area in the middle of the terminal showing the
|
||||
// log messages.
|
||||
// - Status window. This is a window below the log window showing things
|
||||
// like current FPS or other status information.
|
||||
// - Command window. This is a few lines (typically 1 or 2) at the
|
||||
// bottom of the terminal window. The command prompt and command line
|
||||
// editor is shown in the command window.
|
||||
//
|
||||
// The layout is implementated as a single curses window - the standard
|
||||
// screen (stdscr).
|
||||
|
||||
// The width and height of the terminal window.
|
||||
unsigned m_Width, m_Height;
|
||||
|
||||
// The height of the header window.
|
||||
// The header window is displayed at the top of the terminal window.
|
||||
// Typically 0 (no header) or 1 (single header line).
|
||||
unsigned m_HeaderHeight;
|
||||
|
||||
// The height of the status window.
|
||||
// This is typically a single line between the log window and the command
|
||||
// window, displayed in inverse video.
|
||||
unsigned m_StatusHeight;
|
||||
|
||||
// The height of the command window.
|
||||
// This is typically a single line at the bottom of the screen.
|
||||
unsigned m_CmdHeight;
|
||||
|
||||
// The current text color.
|
||||
int m_Color;
|
||||
|
||||
// The default text color pair (read from curses when the app starts).
|
||||
int m_DefaultColorPair;
|
||||
|
||||
// Flag indicating if color output is enabled.
|
||||
bool m_EnableColor;
|
||||
|
||||
// Flag indicating that the window has been resized.
|
||||
// Set by the SIGWINCH signal handler.
|
||||
bool m_WindowResized;
|
||||
|
||||
// Flag indicating that OnShutdown() has been called.
|
||||
bool m_OnShutdownCalled;
|
||||
|
||||
// Flag indicating if the console has been initialized (i.e. Init() has been
|
||||
// called).
|
||||
bool m_Initialized;
|
||||
|
||||
// Flag indicating if the implied console initialization (performed by the
|
||||
// OnInit() callback) requires a dedicated server.
|
||||
// This flag is set through the public SetRequireDedicatedServer() method.
|
||||
bool m_RequireDedicatedServer;
|
||||
|
||||
// The number of (logical) lines scrolled up.
|
||||
// 0 indicates that we're at the bottom of the log.
|
||||
int m_ScrollUp;
|
||||
|
||||
// Array of color pair handles.
|
||||
// 0: default terminal color
|
||||
// 1: default terminal color, reverse video
|
||||
// 2: blue
|
||||
// 3: green
|
||||
// 4: red, bold font
|
||||
// 5: cyan
|
||||
// 6: yellow on black, bold font
|
||||
// 7: magenta
|
||||
// 8: red, normal text
|
||||
// 9: black on white
|
||||
short m_ColorPair[10];
|
||||
|
||||
// The keyboard input thread.
|
||||
CUNIXConsoleInputThread* m_InputThread;
|
||||
|
||||
// The current input line, cursor position, and horizontal scroll position.
|
||||
string m_InputLine;
|
||||
string m_SavedInputLine;
|
||||
int m_CursorPosition;
|
||||
int m_ScrollPosition;
|
||||
|
||||
// The current progress status string.
|
||||
//
|
||||
// Set by the OnInitProgress() method and cleared by OnUpdate(). If this is
|
||||
// not empty, then this is shown in the status line.
|
||||
string m_ProgressStatus;
|
||||
|
||||
// Set the size of the terminal window.
|
||||
//
|
||||
// This method is called when the UNIX console is created and whenever the
|
||||
// size of the terminal window changes (i.e. SIGWINCH received).
|
||||
//
|
||||
// We're relying on the ncurses handler for SIGWINCH, so we'll call this
|
||||
// method when getch() returns KEY_RESIZE.
|
||||
void SetSize(unsigned width, unsigned height);
|
||||
|
||||
// Check if the terminal window is too small for drawing.
|
||||
bool IsTooSmall();
|
||||
|
||||
// Check if the window size has changed.
|
||||
void CheckResize();
|
||||
|
||||
// Get the height of the log window.
|
||||
unsigned GetLogHeight()
|
||||
{
|
||||
return m_Height - m_HeaderHeight - m_StatusHeight - m_CmdHeight;
|
||||
}
|
||||
|
||||
// Scroll the log window and start a new log line.
|
||||
//
|
||||
// Move the cursor position to the beginning of the new log line.
|
||||
void NewLine();
|
||||
|
||||
// Continue the last log line.
|
||||
//
|
||||
// Move the cursor position to the first character following the last
|
||||
// character logged and update the current color.
|
||||
void ContinueLine();
|
||||
|
||||
// Clear the current output line.
|
||||
//
|
||||
// Move the cursor to the beginning of the current output line.
|
||||
//
|
||||
// Note: This is a bit fuzzy to implement because long wrapped lines are not
|
||||
// easy to deal with. Instead I'll simply call NewLine() and maybe
|
||||
// implement this later.
|
||||
void ClearLine() { NewLine(); }
|
||||
|
||||
// Set the output color.
|
||||
//
|
||||
// The color is one of the 10 color codes (0-9) used by the graphical
|
||||
// console. If color output is enabled, then the corresponding terminal
|
||||
// color is set. If color output is not enabled, then only the text
|
||||
// attributes are changed.
|
||||
//
|
||||
// In addition to setting the color (if enabled), the method will set the
|
||||
// following terminal attributes:
|
||||
// 0, 1: Normal text (black, white)
|
||||
// 4, 6: Bold text (red, yellow, typically indicates an error or warning)
|
||||
// other: Underlined text
|
||||
void SetColor(int color = DEFAULT_COLOR);
|
||||
void SetColorRaw(int color);
|
||||
|
||||
// Write a single character or a sequence of characters to the console,
|
||||
// using the currently specified color. The specified character must be a
|
||||
// printable character.
|
||||
//
|
||||
// Note:
|
||||
// - The Put(const char *) method will interpret '\n' as a line separator an
|
||||
// call NewLine() when encountered. All other characters must be
|
||||
// printable characters.
|
||||
// - Both Put() methods will _not_ update the cursor position before writing
|
||||
// the character to the screen. It is up to the caller to update the
|
||||
// cursor position (either by calling NewLine() or ContinueLine()).
|
||||
void Put(int c);
|
||||
void Put(const char* s);
|
||||
|
||||
// Get the length of the line (number of displayed characters), not counting
|
||||
// color change escapes.
|
||||
static unsigned GetLineLength(const string& line);
|
||||
|
||||
// Get the last printable character from the specified line. It is an error
|
||||
// if the specified line contains no printable characters. If color is not
|
||||
// NULL, then the selected color for the last character is stored to *color.
|
||||
static char GetLastCharacter(const string& line, int* color);
|
||||
|
||||
// Get the height of a line of text.
|
||||
//
|
||||
// The method returns the number of terminal lines to display the specified
|
||||
// line (wrapped). If column is not NULL, then *column is set to the column
|
||||
// indicating the end of the last wrapped terminal line.
|
||||
unsigned GetLineHeight(const string& line, unsigned* column = NULL);
|
||||
|
||||
// Scroll the log window one line.
|
||||
void ScrollLog();
|
||||
|
||||
// Flush/repaint the screen.
|
||||
void Flush();
|
||||
|
||||
// Called by the input thread when idle.
|
||||
void InputIdle();
|
||||
|
||||
// Lock/unlock the UNIX console.
|
||||
void Lock() { m_Lock.Lock(); }
|
||||
void Unlock() { m_Lock.Unlock(); }
|
||||
|
||||
// Fix the cursor position and scroll position after updating the command
|
||||
// input line. Returns true if the command window must be repainted.
|
||||
bool FixCursorPosition();
|
||||
|
||||
// Called when the command line has been edited.
|
||||
void OnEdit();
|
||||
|
||||
// Keyboard input.
|
||||
void KeyEnter();
|
||||
void KeyUp();
|
||||
void KeyDown();
|
||||
void KeyLeft();
|
||||
void KeyRight();
|
||||
void KeyHome(bool ctrl);
|
||||
void KeyEnd(bool ctrl);
|
||||
void KeyBackspace();
|
||||
void KeyDelete();
|
||||
void KeyDeleteWord();
|
||||
void KeyKill();
|
||||
void KeyRepaint();
|
||||
void KeyTab();
|
||||
void KeyPgUp(bool ctrl);
|
||||
void KeyPgDown(bool ctrl);
|
||||
void KeyF(int id);
|
||||
void Key(int c);
|
||||
|
||||
// Drawing.
|
||||
void Repaint();
|
||||
void DrawHeader();
|
||||
unsigned DrawLogLine(const string&, bool noOutput = false);
|
||||
void DrawLog();
|
||||
void DrawFullscreen();
|
||||
void DrawStatus(int maxLines = -1);
|
||||
void DrawCmd(bool cursorOnly = false);
|
||||
void DrawCmdPrompt();
|
||||
|
||||
CUNIXConsole(const CUNIXConsole&);
|
||||
void operator = (const CUNIXConsole&);
|
||||
|
||||
public:
|
||||
CUNIXConsole();
|
||||
~CUNIXConsole();
|
||||
|
||||
// Set or clear the RequireDedicatedServer flag.
|
||||
// The implied initialization call performed by the
|
||||
// ISystemUserCallback::OnInit() depends on this flag.
|
||||
// Note: This method _must_ be called before Init() or OnInit() is called.
|
||||
void SetRequireDedicatedServer(bool);
|
||||
|
||||
// Initialize the console for use.
|
||||
//
|
||||
// This method must be called before any other method of the console is
|
||||
// called.
|
||||
// It is perfectly valid to instanciate a console and not use it (i.e. skip
|
||||
// the Init() call).
|
||||
//
|
||||
// Note: If the ISystemUserCallback interface is used, then the call to
|
||||
// Init() is optional. OnInit() will call Init() if it has not been called
|
||||
// already.
|
||||
void Init(const char* headerString = NULL);
|
||||
|
||||
// Check if the console is initialized.
|
||||
bool IsInitialized() { return m_Initialized; }
|
||||
|
||||
// Cleanup function.
|
||||
// This method is called by the destructor.
|
||||
// If the instance has not been initialized (via Init() and/or OnInit()),
|
||||
// then this method has no effect.
|
||||
void Cleanup();
|
||||
|
||||
// Set the header string.
|
||||
// Note:
|
||||
// - Setting the header string does _not_ trigger a redraw.
|
||||
// - This method may be called before Init() has been called.
|
||||
void SetHeader(const char* headerString)
|
||||
{
|
||||
Lock();
|
||||
m_HeaderString = headerString;
|
||||
Unlock();
|
||||
}
|
||||
|
||||
// Issue a query-response prompt.
|
||||
//
|
||||
// promptString is the string to be shown as the query prompt.
|
||||
// responseChars is a null-terminated string of valid response characters.
|
||||
// Add '@' to the response characters if the user may type any character.
|
||||
//
|
||||
// The method blocks the caller until the user has typed a response. The
|
||||
// return value is the response character typed by the user.
|
||||
DLL_EXPORT char Prompt(const char* promptString, const char* responseChars);
|
||||
|
||||
// Check if the calling thread is the input thread.
|
||||
//
|
||||
// This may be used to make sure that you're not calling Prompt() from the
|
||||
// input thread - which will deadlock.
|
||||
DLL_EXPORT bool IsInputThread();
|
||||
|
||||
// Print formatted. Calls Print().
|
||||
DLL_EXPORT void PrintF(const char* format, ...) PRINTF_PARAMS(2, 3);
|
||||
|
||||
// Interface IOutputPrintSink /////////////////////////////////////////////
|
||||
DLL_EXPORT virtual void Print(const char* line);
|
||||
|
||||
// Interface ISystemUserCallback //////////////////////////////////////////
|
||||
virtual bool OnError(const char* errorString);
|
||||
virtual bool OnSaveDocument() { return false; }
|
||||
virtual bool OnBackupDocument() { return false; }
|
||||
virtual void OnProcessSwitch() { }
|
||||
virtual void OnInitProgress(const char* sProgressMsg);
|
||||
virtual void OnInit(ISystem*);
|
||||
virtual void OnShutdown();
|
||||
virtual void OnUpdate();
|
||||
virtual void GetMemoryUsage(ICrySizer* pSizer);
|
||||
|
||||
// Interface ITextModeConsole /////////////////////////////////////////////
|
||||
virtual Vec2_tpl<int> BeginDraw();
|
||||
virtual void PutText(int x, int y, const char* msg);
|
||||
virtual void EndDraw();
|
||||
};
|
||||
|
||||
#endif // USE_UNIXCONSOLE
|
||||
|
||||
#if defined(AZ_RESTRICTED_PLATFORM)
|
||||
#include AZ_RESTRICTED_FILE(UnixConsole_h)
|
||||
#endif
|
||||
#if defined(AZ_RESTRICTED_SECTION_IMPLEMENTED)
|
||||
#undef AZ_RESTRICTED_SECTION_IMPLEMENTED
|
||||
#else
|
||||
// simple light-weight console
|
||||
class CNULLConsole
|
||||
: public IOutputPrintSink
|
||||
, public ISystemUserCallback
|
||||
, public ITextModeConsole
|
||||
{
|
||||
public:
|
||||
CNULLConsole(bool isDaemonMode);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////
|
||||
// IOutputPrintSink
|
||||
///////////////////////////////////////////////////////////////////////////////////////
|
||||
virtual void Print(const char* inszText);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////
|
||||
// ISystemUserCallback
|
||||
///////////////////////////////////////////////////////////////////////////////////////
|
||||
/** this method is called at the earliest point the ISystem pointer can be used
|
||||
the log might not be yet there
|
||||
*/
|
||||
virtual void OnSystemConnect([[maybe_unused]] ISystem* pSystem) {};
|
||||
/** Signals to User that engine error occured.
|
||||
@return true to Halt execution or false to ignore this error.
|
||||
*/
|
||||
virtual bool OnError([[maybe_unused]] const char* szErrorString) { return false; };
|
||||
/** If working in Editor environment notify user that engine want to Save current document.
|
||||
This happens if critical error have occured and engine gives a user way to save data and not lose it
|
||||
due to crash.
|
||||
*/
|
||||
virtual bool OnSaveDocument() { return false; }
|
||||
|
||||
/** If working in Editor environment and a critical error occurs notify the user to backup
|
||||
the current document to prevent data loss due to crash.
|
||||
*/
|
||||
virtual bool OnBackupDocument() { return false; }
|
||||
|
||||
/** Notify user that system wants to switch out of current process.
|
||||
(For ex. Called when pressing ESC in game mode to go to Menu).
|
||||
*/
|
||||
virtual void OnProcessSwitch() {};
|
||||
|
||||
// Notify user, usually editor about initialization progress in system.
|
||||
virtual void OnInitProgress([[maybe_unused]] const char* sProgressMsg) {};
|
||||
|
||||
// Initialization callback. This is called early in CSystem::Init(), before
|
||||
// any of the other callback methods is called.
|
||||
virtual void OnInit(ISystem*);
|
||||
|
||||
// Shutdown callback.
|
||||
virtual void OnShutdown() {};
|
||||
|
||||
// Notify user of an update iteration. Called in the update loop.
|
||||
virtual void OnUpdate();
|
||||
|
||||
// to collect the memory information in the user program/application
|
||||
virtual void GetMemoryUsage([[maybe_unused]] ICrySizer* pSizer) {};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////
|
||||
// ITextModeConsole
|
||||
///////////////////////////////////////////////////////////////////////////////////////
|
||||
virtual Vec2_tpl<int> BeginDraw() { return Vec2_tpl<int>(0, 0); };
|
||||
virtual void PutText(int x, int y, const char* msg);
|
||||
virtual void EndDraw() {};
|
||||
|
||||
void SetRequireDedicatedServer(bool)
|
||||
{
|
||||
// Does nothing
|
||||
}
|
||||
void SetHeader(const char*)
|
||||
{
|
||||
//Does nothing
|
||||
}
|
||||
private:
|
||||
#if defined(WIN32) || defined(WIN64)
|
||||
HANDLE m_hOut;
|
||||
#endif
|
||||
bool m_isDaemon;
|
||||
CSyslogStats m_syslogStats;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif // defined(USE_DEDICATED_SERVER_CONSOLE)
|
||||
@@ -1,66 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
#ifndef CRYINCLUDE_CRYSYSTEM_VALIDATOR_H
|
||||
#define CRYINCLUDE_CRYSYSTEM_VALIDATOR_H
|
||||
|
||||
#pragma once
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Default validator implementation.
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
struct SDefaultValidator
|
||||
: public IValidator
|
||||
{
|
||||
CSystem* m_pSystem;
|
||||
SDefaultValidator(CSystem* system)
|
||||
: m_pSystem(system) {};
|
||||
virtual void Report(SValidatorRecord& record)
|
||||
{
|
||||
if (record.text)
|
||||
{
|
||||
static bool bNoMsgBoxOnWarnings = false;
|
||||
if ((record.text[0] == '!') || (m_pSystem->m_sysWarnings && m_pSystem->m_sysWarnings->GetIVal() != 0))
|
||||
{
|
||||
if (g_cvars.sys_no_crash_dialog)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (bNoMsgBoxOnWarnings)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
string strMessage = record.text;
|
||||
strMessage += "\n---------------------------------------------\nAbort - terminate application\nRetry - continue running the application\nIgnore - don't show this message box any more";
|
||||
switch (::MessageBox(NULL, strMessage.c_str(), "CryEngine Warning", MB_ABORTRETRYIGNORE | MB_DEFBUTTON2 | MB_ICONWARNING | MB_SYSTEMMODAL))
|
||||
{
|
||||
case IDABORT:
|
||||
m_pSystem->GetIConsole()->Exit ("User abort requested during showing the warning box with the following message: %s", record.text);
|
||||
break;
|
||||
case IDRETRY:
|
||||
break;
|
||||
case IDIGNORE:
|
||||
bNoMsgBoxOnWarnings = true;
|
||||
m_pSystem->m_sysWarnings->Set(0);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif // CRYINCLUDE_CRYSYSTEM_VALIDATOR_H
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,245 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
// Description : CWindowsConsole class definition
|
||||
|
||||
|
||||
#ifndef CRYINCLUDE_CRYSYSTEM_WINDOWSCONSOLE_H
|
||||
#define CRYINCLUDE_CRYSYSTEM_WINDOWSCONSOLE_H
|
||||
#pragma once
|
||||
|
||||
|
||||
#include <IConsole.h>
|
||||
#include <ITextModeConsole.h>
|
||||
|
||||
#if defined(USE_WINDOWSCONSOLE)
|
||||
|
||||
class CWindowsConsole;
|
||||
class CWindowsConsoleInputThread;
|
||||
|
||||
#define WINDOWS_CONSOLE_MAX_INPUT_RECORDS 256
|
||||
#define WINDOWS_CONSOLE_NUM_CRYENGINE_COLORS 10
|
||||
|
||||
class CWindowsConsoleInputThread
|
||||
: public CrySimpleThread<>
|
||||
{
|
||||
public:
|
||||
CWindowsConsoleInputThread(CWindowsConsole& console);
|
||||
|
||||
~CWindowsConsoleInputThread();
|
||||
|
||||
virtual void Run();
|
||||
virtual void Cancel();
|
||||
void Interrupt()
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
enum EWaitHandle
|
||||
{
|
||||
eWH_Event,
|
||||
eWH_Console,
|
||||
eWH_NumWaitHandles
|
||||
};
|
||||
|
||||
CWindowsConsole& m_WindowsConsole;
|
||||
HANDLE m_handles[ eWH_NumWaitHandles ];
|
||||
INPUT_RECORD m_inputRecords[ WINDOWS_CONSOLE_MAX_INPUT_RECORDS ];
|
||||
};
|
||||
|
||||
class CWindowsConsole
|
||||
: public ITextModeConsole
|
||||
, public IOutputPrintSink
|
||||
, public ISystemUserCallback
|
||||
{
|
||||
public:
|
||||
|
||||
CWindowsConsole();
|
||||
virtual ~CWindowsConsole();
|
||||
|
||||
// ITextModeConsole
|
||||
virtual Vec2_tpl< int > BeginDraw();
|
||||
virtual void PutText(int x, int y, const char* pMsg);
|
||||
virtual void EndDraw();
|
||||
virtual void SetTitle(const char* title);
|
||||
|
||||
// ~ITextModeConsole
|
||||
|
||||
// IOutputPrintSink
|
||||
virtual void Print(const char* pInszText);
|
||||
// ~IOutputPrintSink
|
||||
|
||||
// ISystemUserCallback
|
||||
virtual bool OnError(const char* szErrorString);
|
||||
virtual bool OnSaveDocument();
|
||||
virtual bool OnBackupDocument();
|
||||
virtual void OnProcessSwitch();
|
||||
virtual void OnInitProgress(const char* sProgressMsg);
|
||||
virtual void OnInit(ISystem* pSystem);
|
||||
virtual void OnShutdown();
|
||||
virtual void OnUpdate();
|
||||
virtual void GetMemoryUsage(ICrySizer* pSizer);
|
||||
// ~ISystemUserCallback
|
||||
|
||||
void SetRequireDedicatedServer(bool value);
|
||||
void SetHeader(const char* pHeader);
|
||||
void InputIdle();
|
||||
|
||||
private:
|
||||
|
||||
struct SConDrawCmd
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
char text[ 256 ];
|
||||
};
|
||||
|
||||
DynArray<SConDrawCmd> m_drawCmds;
|
||||
DynArray<SConDrawCmd> m_newCmds;
|
||||
|
||||
enum ECellBuffer
|
||||
{
|
||||
eCB_Log,
|
||||
eCB_Full,
|
||||
eCB_Status,
|
||||
eCB_Command,
|
||||
eCB_NumCellBuffers
|
||||
};
|
||||
|
||||
enum ECellBufferBit
|
||||
{
|
||||
eCBB_Log = BIT(eCB_Log),
|
||||
eCBB_Full = BIT(eCB_Full),
|
||||
eCBB_Status = BIT(eCB_Status),
|
||||
eCBB_Command = BIT(eCB_Command)
|
||||
};
|
||||
|
||||
class CCellBuffer
|
||||
{
|
||||
public:
|
||||
|
||||
CCellBuffer(SHORT x, short y, SHORT w, SHORT h, SHORT lines, WCHAR emptyChar, uint8 defaultFgColor, uint8 defaultBgColor);
|
||||
~CCellBuffer();
|
||||
|
||||
void PutText(int x, int y, const char* pMsg);
|
||||
void Print(const char* pInszText);
|
||||
void NewLine();
|
||||
void SetCursor(HANDLE hScreenBuffer, SHORT offset);
|
||||
void SetFgColor(WORD color);
|
||||
void Blit(HANDLE hScreenBuffer);
|
||||
bool Scroll(SHORT numLines);
|
||||
bool IsScrolledUp();
|
||||
void FmtScrollStatus(uint32 size, char* pBuffer);
|
||||
void GetMemoryUsage(ICrySizer* pSizer);
|
||||
void Clear();
|
||||
SHORT Width();
|
||||
|
||||
private:
|
||||
|
||||
struct SPosition
|
||||
{
|
||||
SHORT head;
|
||||
SHORT lines;
|
||||
SHORT wrap;
|
||||
SHORT offset;
|
||||
SHORT scroll;
|
||||
};
|
||||
|
||||
typedef std::vector< CHAR_INFO > TBuffer;
|
||||
|
||||
void Print(const char* pInszText, SPosition& position);
|
||||
void AddCharacter(WCHAR ch, SPosition& position);
|
||||
void NewLine(SPosition& position);
|
||||
void ClearLine(SPosition& position);
|
||||
void Tab(SPosition& position);
|
||||
void WrapLine(SPosition& position);
|
||||
void AdvanceLine(SPosition& position);
|
||||
void ClearCells(TBuffer::iterator pDst, TBuffer::iterator pDstEnd);
|
||||
|
||||
TBuffer m_buffer;
|
||||
CHAR_INFO m_emptyCell;
|
||||
WORD m_attr;
|
||||
COORD m_size;
|
||||
SMALL_RECT m_screenArea;
|
||||
SPosition m_position;
|
||||
bool m_escape;
|
||||
bool m_color;
|
||||
};
|
||||
|
||||
void Lock();
|
||||
void Unlock();
|
||||
bool TryLock();
|
||||
void OnConsoleInputEvent(INPUT_RECORD inputRecord);
|
||||
void OnKey(const KEY_EVENT_RECORD& event);
|
||||
void OnResize(const COORD& size);
|
||||
void OnBackspace();
|
||||
void OnTab();
|
||||
void OnReturn();
|
||||
void OnPgUp();
|
||||
void OnPgDn();
|
||||
void OnLeft();
|
||||
void OnUp();
|
||||
void OnRight();
|
||||
void OnDown();
|
||||
void OnDelete();
|
||||
void OnHistory(const char* pHistoryElement);
|
||||
void OnChar(CHAR ch);
|
||||
void DrawFull();
|
||||
void DrawStatus();
|
||||
void DrawCommand();
|
||||
void Repaint();
|
||||
void CleanUp();
|
||||
|
||||
CryCriticalSection m_lock;
|
||||
COORD m_consoleScreenBufferSize;
|
||||
SMALL_RECT m_consoleWindow;
|
||||
HANDLE m_inputBufferHandle;
|
||||
HANDLE m_screenBufferHandle;
|
||||
CCellBuffer m_logBuffer;
|
||||
CCellBuffer m_fullScreenBuffer;
|
||||
CCellBuffer m_statusBuffer;
|
||||
CCellBuffer m_commandBuffer;
|
||||
uint32 m_dirtyCellBuffers;
|
||||
std::deque< CryStringT< char > > m_commandQueue;
|
||||
CryStringT< char > m_commandPrompt;
|
||||
uint32 m_commandPromptLength;
|
||||
CryStringT< char > m_command;
|
||||
uint32 m_commandCursor;
|
||||
CryStringT< char > m_logLine;
|
||||
CryStringT< char > m_progressString;
|
||||
CryStringT< char > m_header;
|
||||
SSystemUpdateStats m_updStats;
|
||||
CWindowsConsoleInputThread* m_pInputThread;
|
||||
ISystem* m_pSystem;
|
||||
IConsole* m_pConsole;
|
||||
ITimer* m_pTimer;
|
||||
ICVar* m_pCVarSvMap;
|
||||
ICVar* m_pCVarSvMission;
|
||||
CryStringT< char > m_title;
|
||||
|
||||
ICVar* m_pCVarSvGameRules;
|
||||
CTimeValue m_lastStatusUpdate;
|
||||
CTimeValue m_lastUpdateTime;
|
||||
bool m_initialized;
|
||||
bool m_OnUpdateCalled;
|
||||
bool m_requireDedicatedServer;
|
||||
|
||||
static const uint8 s_colorTable[ WINDOWS_CONSOLE_NUM_CRYENGINE_COLORS ];
|
||||
|
||||
friend class CWindowsConsoleInputThread;
|
||||
};
|
||||
|
||||
#endif // USE_WINDOWSCONSOLE
|
||||
|
||||
#endif // CRYINCLUDE_CRYSYSTEM_WINDOWSCONSOLE_H
|
||||
@@ -1,151 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
// Description : Support for Windows Error Reporting (WER)
|
||||
|
||||
|
||||
#include "CrySystem_precompiled.h"
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
#include "System.h"
|
||||
#include <windows.h>
|
||||
#include <tchar.h>
|
||||
#include "errorrep.h"
|
||||
#include "ISystem.h"
|
||||
|
||||
#include <DbgHelp.h>
|
||||
|
||||
static WCHAR szPath[MAX_PATH + 1];
|
||||
static WCHAR szFR[] = L"\\System32\\FaultRep.dll";
|
||||
|
||||
WCHAR* GetFullPathToFaultrepDll(void)
|
||||
{
|
||||
UINT rc = GetSystemWindowsDirectoryW(szPath, ARRAYSIZE(szPath));
|
||||
if (rc == 0 || rc > ARRAYSIZE(szPath) - ARRAYSIZE(szFR) - 1)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
wcscat_s(szPath, szFR);
|
||||
return szPath;
|
||||
}
|
||||
|
||||
|
||||
typedef BOOL (WINAPI * MINIDUMPWRITEDUMP)(HANDLE hProcess, DWORD dwPid, HANDLE hFile, MINIDUMP_TYPE DumpType,
|
||||
CONST PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam,
|
||||
CONST PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam,
|
||||
CONST PMINIDUMP_CALLBACK_INFORMATION CallbackParam
|
||||
);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
LONG WINAPI CryEngineExceptionFilterMiniDump(struct _EXCEPTION_POINTERS* pExceptionPointers, const char* szDumpPath, MINIDUMP_TYPE DumpType)
|
||||
{
|
||||
// note: In debug mode, this dll is loaded on startup anyway, so this should not incur an additional load unless it crashes
|
||||
// very early during startup.
|
||||
|
||||
fflush(nullptr); // according to MSDN on fflush, calling fflush on null flushes all buffers.
|
||||
HMODULE hndDBGHelpDLL = LoadLibraryA("DBGHELP.DLL");
|
||||
|
||||
if (!hndDBGHelpDLL)
|
||||
{
|
||||
CryLogAlways("Failed to record DMP file: Could not open DBGHELP.DLL");
|
||||
return EXCEPTION_CONTINUE_SEARCH;
|
||||
}
|
||||
|
||||
MINIDUMPWRITEDUMP dumpFnPtr = (MINIDUMPWRITEDUMP)::GetProcAddress(hndDBGHelpDLL, "MiniDumpWriteDump");
|
||||
if (!dumpFnPtr)
|
||||
{
|
||||
CryLogAlways("Failed to record DMP file: Unable to find MiniDumpWriteDump in DBGHELP.DLL");
|
||||
return EXCEPTION_CONTINUE_SEARCH;
|
||||
}
|
||||
|
||||
HANDLE hFile = ::CreateFile(szDumpPath, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
if (hFile == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
CryLogAlways("Failed to record DMP file: could not open file '%s' for writing - error code: %d", szDumpPath, GetLastError());
|
||||
return EXCEPTION_CONTINUE_SEARCH;
|
||||
}
|
||||
|
||||
_MINIDUMP_EXCEPTION_INFORMATION ExInfo;
|
||||
ExInfo.ThreadId = ::GetCurrentThreadId();
|
||||
ExInfo.ExceptionPointers = pExceptionPointers;
|
||||
ExInfo.ClientPointers = NULL;
|
||||
|
||||
BOOL bOK = dumpFnPtr(GetCurrentProcess(), GetCurrentProcessId(), hFile, DumpType, &ExInfo, NULL, NULL);
|
||||
::CloseHandle(hFile);
|
||||
|
||||
if (bOK)
|
||||
{
|
||||
CryLogAlways("Successfully recorded DMP file: '%s'", szDumpPath);
|
||||
return EXCEPTION_EXECUTE_HANDLER; // SUCCESS! you can execute your handlers now
|
||||
}
|
||||
else
|
||||
{
|
||||
CryLogAlways("Failed to record DMP file: '%s' - error code: %d", szDumpPath, GetLastError());
|
||||
}
|
||||
|
||||
return EXCEPTION_CONTINUE_SEARCH;
|
||||
}
|
||||
|
||||
/*
|
||||
struct AutoSetCryEngineExceptionFilter
|
||||
{
|
||||
AutoSetCryEngineExceptionFilter()
|
||||
{
|
||||
WCHAR * psz = GetFullPathToFaultrepDll();
|
||||
SetUnhandledExceptionFilter(CryEngineExceptionFilterWER);
|
||||
}
|
||||
};
|
||||
AutoSetCryEngineExceptionFilter g_AutoSetCryEngineExceptionFilter;
|
||||
*/
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
LONG WINAPI CryEngineExceptionFilterWER(struct _EXCEPTION_POINTERS* pExceptionPointers)
|
||||
{
|
||||
if (g_cvars.sys_WER > 1)
|
||||
{
|
||||
char szScratch [_MAX_PATH];
|
||||
const char* szDumpPath = gEnv->pCryPak->AdjustFileName("@log@/CE2Dump.dmp", szScratch, AZ_ARRAY_SIZE(szScratch), 0);
|
||||
|
||||
MINIDUMP_TYPE mdumpValue = (MINIDUMP_TYPE)(MiniDumpNormal);
|
||||
if (g_cvars.sys_WER > 1)
|
||||
{
|
||||
mdumpValue = (MINIDUMP_TYPE)(g_cvars.sys_WER - 2);
|
||||
}
|
||||
|
||||
return CryEngineExceptionFilterMiniDump(pExceptionPointers, szDumpPath, mdumpValue);
|
||||
}
|
||||
|
||||
LONG lRet = EXCEPTION_CONTINUE_SEARCH;
|
||||
WCHAR* psz = GetFullPathToFaultrepDll();
|
||||
if (psz)
|
||||
{
|
||||
HMODULE hFaultRepDll = LoadLibraryW(psz);
|
||||
if (hFaultRepDll)
|
||||
{
|
||||
pfn_REPORTFAULT pfn = (pfn_REPORTFAULT)GetProcAddress(hFaultRepDll, "ReportFault");
|
||||
if (pfn)
|
||||
{
|
||||
pfn(pExceptionPointers, 0);
|
||||
lRet = EXCEPTION_EXECUTE_HANDLER;
|
||||
}
|
||||
FreeLibrary(hFaultRepDll);
|
||||
}
|
||||
}
|
||||
return lRet;
|
||||
}
|
||||
|
||||
|
||||
#endif // WIN32
|
||||
|
||||
@@ -1,336 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
#include "CrySystem_precompiled.h"
|
||||
#include "CryZlib.h"
|
||||
#include "ZLibCompressor.h"
|
||||
#include "TypeInfo_impl.h"
|
||||
#include <md5.h>
|
||||
|
||||
// keep these in sync with the enums in IZLibCompressor.h
|
||||
static const int k_stratMap[] = {Z_DEFAULT_STRATEGY, Z_FILTERED, Z_HUFFMAN_ONLY, Z_RLE};
|
||||
static const int k_methodMap[] = {Z_DEFLATED};
|
||||
static const int k_flushMap[] = {Z_NO_FLUSH, Z_PARTIAL_FLUSH, Z_SYNC_FLUSH, Z_FULL_FLUSH};
|
||||
|
||||
struct CZLibDeflateStream
|
||||
: public IZLibDeflateStream
|
||||
{
|
||||
protected:
|
||||
virtual ~CZLibDeflateStream();
|
||||
|
||||
protected:
|
||||
z_stream m_compressStream;
|
||||
int m_zSize;
|
||||
int m_zPeak;
|
||||
int m_level;
|
||||
int m_windowBits;
|
||||
int m_memLevel;
|
||||
int m_zlibFlush;
|
||||
int m_bytesInput;
|
||||
int m_bytesOutput;
|
||||
EZLibStrategy m_strategy;
|
||||
EZLibMethod m_method;
|
||||
EZDeflateState m_curState;
|
||||
bool m_streamOpened;
|
||||
|
||||
|
||||
static voidpf ZAlloc(
|
||||
voidpf pInOpaque,
|
||||
uInt inItems,
|
||||
uInt inSize);
|
||||
static void ZFree(
|
||||
voidpf pInOpaque,
|
||||
voidpf pInAddress);
|
||||
|
||||
EZDeflateState RunDeflate();
|
||||
|
||||
public:
|
||||
CZLibDeflateStream(
|
||||
int inLevel,
|
||||
EZLibMethod inMethod,
|
||||
int inWindowBits,
|
||||
int inMemLevel,
|
||||
EZLibStrategy inStrategy,
|
||||
EZLibFlush inFlushMethod);
|
||||
|
||||
virtual void SetOutputBuffer(
|
||||
char* pInBuffer,
|
||||
int inSize);
|
||||
virtual int GetBytesOutput();
|
||||
|
||||
virtual void Input(
|
||||
const char* pInSource,
|
||||
int inSourceSize);
|
||||
virtual void EndInput();
|
||||
|
||||
virtual EZDeflateState GetState();
|
||||
|
||||
virtual void GetStats(
|
||||
SStats* pOutStats);
|
||||
|
||||
virtual void Release();
|
||||
};
|
||||
|
||||
inline static int Lookup(int inIndex, const int* pInValues, [[maybe_unused]] int inMaxValues)
|
||||
{
|
||||
CRY_ASSERT_MESSAGE(inIndex >= 0 && inIndex < inMaxValues, "CZLibDeflateStream mapping invalid");
|
||||
return pInValues[inIndex];
|
||||
}
|
||||
|
||||
IZLibDeflateStream* CZLibCompressor::CreateDeflateStream(int inLevel, EZLibMethod inMethod, int inWindowBits, int inMemLevel, EZLibStrategy inStrategy, EZLibFlush inFlushMethod)
|
||||
{
|
||||
return new CZLibDeflateStream(inLevel, inMethod, inWindowBits, inMemLevel, inStrategy, inFlushMethod);
|
||||
}
|
||||
|
||||
void CZLibCompressor::Release()
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
|
||||
void CZLibCompressor::MD5Init(SMD5Context* pIOCtx)
|
||||
{
|
||||
COMPILE_TIME_ASSERT(sizeof(*pIOCtx) == sizeof(MD5Context));
|
||||
|
||||
::MD5Init((MD5Context*)pIOCtx);
|
||||
}
|
||||
|
||||
void CZLibCompressor::MD5Update(SMD5Context* pIOCtx, const char* pInBuff, unsigned int len)
|
||||
{
|
||||
::MD5Update((MD5Context*)pIOCtx, (unsigned char*)pInBuff, len);
|
||||
}
|
||||
|
||||
void CZLibCompressor::MD5Final(SMD5Context* pIOCtx, char outDigest[16])
|
||||
{
|
||||
::MD5Final((unsigned char*)outDigest, (MD5Context*)pIOCtx);
|
||||
}
|
||||
|
||||
CZLibCompressor::~CZLibCompressor()
|
||||
{
|
||||
}
|
||||
|
||||
CZLibDeflateStream::CZLibDeflateStream(
|
||||
int inLevel,
|
||||
EZLibMethod inMethod,
|
||||
int inWindowBits,
|
||||
int inMemLevel,
|
||||
EZLibStrategy inStrategy,
|
||||
EZLibFlush inFlushMethod)
|
||||
: m_zSize(0)
|
||||
, m_zPeak(0)
|
||||
, m_level(inLevel)
|
||||
, m_windowBits(inWindowBits)
|
||||
, m_memLevel(inMemLevel)
|
||||
, m_bytesInput(0)
|
||||
, m_bytesOutput(0)
|
||||
, m_strategy(inStrategy)
|
||||
, m_method(inMethod)
|
||||
, m_curState(eZDefState_AwaitingInput)
|
||||
, m_streamOpened(false)
|
||||
{
|
||||
memset(&m_compressStream, 0, sizeof(m_compressStream));
|
||||
m_zlibFlush = Lookup(inFlushMethod, k_flushMap, ARRAY_COUNT(k_flushMap));
|
||||
}
|
||||
|
||||
CZLibDeflateStream::~CZLibDeflateStream()
|
||||
{
|
||||
}
|
||||
|
||||
void CZLibDeflateStream::Release()
|
||||
{
|
||||
if (m_streamOpened)
|
||||
{
|
||||
int err = deflateEnd(&m_compressStream);
|
||||
if (err != Z_OK)
|
||||
{
|
||||
CryLog("zlib deflateEnd() error %d returned when closing stream", err);
|
||||
}
|
||||
}
|
||||
delete this;
|
||||
}
|
||||
|
||||
void CZLibDeflateStream::SetOutputBuffer(
|
||||
char* pInBuffer,
|
||||
int inSize)
|
||||
{
|
||||
m_bytesOutput += m_compressStream.total_out;
|
||||
|
||||
m_compressStream.next_out = (byte*)pInBuffer;
|
||||
m_compressStream.avail_out = inSize;
|
||||
m_compressStream.total_out = 0;
|
||||
}
|
||||
|
||||
void CZLibDeflateStream::GetStats(
|
||||
IZLibDeflateStream::SStats* pOutStats)
|
||||
{
|
||||
pOutStats->bytesInput = m_bytesInput;
|
||||
pOutStats->bytesOutput = m_bytesOutput + m_compressStream.total_out;
|
||||
pOutStats->curMemoryUsed = m_zSize;
|
||||
pOutStats->peakMemoryUsed = m_zPeak;
|
||||
}
|
||||
|
||||
int CZLibDeflateStream::GetBytesOutput()
|
||||
{
|
||||
return m_compressStream.total_out;
|
||||
}
|
||||
|
||||
void CZLibDeflateStream::Input(
|
||||
const char* pInSource,
|
||||
int inSourceSize)
|
||||
{
|
||||
CRY_ASSERT_MESSAGE(m_curState == eZDefState_AwaitingInput, "CZLibDeflateStream::Input() called when stream is not awaiting input");
|
||||
|
||||
m_compressStream.next_in = (Bytef*)pInSource;
|
||||
m_compressStream.avail_in = inSourceSize;
|
||||
m_bytesInput += inSourceSize;
|
||||
}
|
||||
|
||||
void CZLibDeflateStream::EndInput()
|
||||
{
|
||||
CRY_ASSERT_MESSAGE(m_curState == eZDefState_AwaitingInput, "CZLibDeflateStream::EndInput() called when stream is not awaiting input");
|
||||
|
||||
m_zlibFlush = Z_FINISH;
|
||||
}
|
||||
|
||||
voidpf CZLibDeflateStream::ZAlloc(
|
||||
voidpf pInOpaque,
|
||||
uInt inItems,
|
||||
uInt inSize)
|
||||
{
|
||||
CZLibDeflateStream* pStr = reinterpret_cast<CZLibDeflateStream*>(pInOpaque);
|
||||
|
||||
int size = inItems * inSize;
|
||||
|
||||
int* ptr = (int*) CryModuleMalloc(sizeof(int) + size);
|
||||
if (ptr)
|
||||
{
|
||||
*ptr = inItems * inSize;
|
||||
ptr += 1;
|
||||
|
||||
int newSize = pStr->m_zSize + size;
|
||||
pStr->m_zSize = newSize;
|
||||
if (newSize > pStr->m_zPeak)
|
||||
{
|
||||
pStr->m_zPeak = newSize;
|
||||
}
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void CZLibDeflateStream::ZFree(
|
||||
voidpf pInOpaque,
|
||||
voidpf pInAddress)
|
||||
{
|
||||
int* pPtr = reinterpret_cast<int*>(pInAddress);
|
||||
if (pPtr)
|
||||
{
|
||||
CZLibDeflateStream* pStr = reinterpret_cast<CZLibDeflateStream*>(pInOpaque);
|
||||
pStr->m_zSize -= pPtr[-1];
|
||||
CryModuleFree(pPtr - 1);
|
||||
}
|
||||
}
|
||||
|
||||
EZDeflateState CZLibDeflateStream::RunDeflate()
|
||||
{
|
||||
bool runDeflate = false;
|
||||
bool inputAvailable = (m_compressStream.avail_in > 0) || (m_zlibFlush == Z_FINISH);
|
||||
bool outputAvailable = (m_compressStream.avail_out > 0);
|
||||
|
||||
switch (m_curState)
|
||||
{
|
||||
case eZDefState_AwaitingInput:
|
||||
case eZDefState_ConsumeOutput:
|
||||
if (inputAvailable && outputAvailable)
|
||||
{
|
||||
runDeflate = true;
|
||||
}
|
||||
else if (inputAvailable || !outputAvailable)
|
||||
{
|
||||
m_curState = eZDefState_ConsumeOutput;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_curState = eZDefState_AwaitingInput;
|
||||
}
|
||||
break;
|
||||
|
||||
case eZDefState_Finished:
|
||||
break;
|
||||
|
||||
case eZDefState_Deflating:
|
||||
CRY_ASSERT_MESSAGE(0, "Shouldn't be trying to run deflate whilst a deflate is in progress");
|
||||
break;
|
||||
|
||||
case eZDefState_Error:
|
||||
break;
|
||||
|
||||
default:
|
||||
CRY_ASSERT_MESSAGE(0, "unknown state");
|
||||
break;
|
||||
}
|
||||
|
||||
if (runDeflate)
|
||||
{
|
||||
if (!m_streamOpened)
|
||||
{
|
||||
m_streamOpened = true;
|
||||
|
||||
// initialising with deflateInit2 requires that the next_in be initialised
|
||||
m_compressStream.zalloc = &CZLibDeflateStream::ZAlloc;
|
||||
m_compressStream.zfree = &CZLibDeflateStream::ZFree;
|
||||
m_compressStream.opaque = this;
|
||||
|
||||
int error = deflateInit2(&m_compressStream, m_level, Lookup(m_method, k_methodMap, ARRAY_COUNT(k_methodMap)), m_windowBits, m_memLevel, Lookup(m_strategy, k_stratMap, ARRAY_COUNT(k_stratMap)));
|
||||
if (error != Z_OK)
|
||||
{
|
||||
m_curState = eZDefState_Error;
|
||||
CryLog("zlib deflateInit2() error, err %d", error);
|
||||
}
|
||||
}
|
||||
|
||||
if (m_curState != eZDefState_Error)
|
||||
{
|
||||
int error = deflate(&m_compressStream, m_zlibFlush);
|
||||
|
||||
if (error == Z_STREAM_END)
|
||||
{
|
||||
// end of stream has been generated, only produced if we pass Z_FINISH into deflate
|
||||
m_curState = eZDefState_Finished;
|
||||
}
|
||||
else if ((error == Z_OK && m_compressStream.avail_out == 0) || (error == Z_BUF_ERROR && m_compressStream.avail_out == 0))
|
||||
{
|
||||
// output buffer has been filled
|
||||
// data should be available for consumption by caller
|
||||
m_curState = eZDefState_ConsumeOutput;
|
||||
}
|
||||
else if (m_compressStream.avail_in == 0)
|
||||
{
|
||||
// ran out of input data
|
||||
// data may be available for consumption - but we need more input right now
|
||||
m_curState = eZDefState_AwaitingInput;
|
||||
}
|
||||
else
|
||||
{
|
||||
// some sort of error has occurred
|
||||
m_curState = eZDefState_Error;
|
||||
CryLog("zlib deflate() error, err %d", error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return m_curState;
|
||||
}
|
||||
|
||||
EZDeflateState CZLibDeflateStream::GetState()
|
||||
{
|
||||
return RunDeflate();
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
#ifndef CRYINCLUDE_CRYSYSTEM_ZLIBCOMPRESSOR_H
|
||||
#define CRYINCLUDE_CRYSYSTEM_ZLIBCOMPRESSOR_H
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "IZLibCompressor.h"
|
||||
|
||||
class CZLibCompressor
|
||||
: public IZLibCompressor
|
||||
{
|
||||
protected:
|
||||
virtual ~CZLibCompressor();
|
||||
|
||||
public:
|
||||
virtual IZLibDeflateStream* CreateDeflateStream(int inLevel, EZLibMethod inMethod, int inWindowBits, int inMemLevel, EZLibStrategy inStrategy, EZLibFlush inFlushMethod);
|
||||
virtual void Release();
|
||||
|
||||
virtual void MD5Init(SMD5Context* pIOCtx);
|
||||
virtual void MD5Update(SMD5Context* pIOCtx, const char* pInBuff, unsigned int len);
|
||||
virtual void MD5Final(SMD5Context * pIOCtx, char outDigest[16]);
|
||||
};
|
||||
|
||||
#endif // CRYINCLUDE_CRYSYSTEM_ZLIBCOMPRESSOR_H
|
||||
@@ -1,251 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
// Description : zlib inflate wrapper
|
||||
|
||||
|
||||
#include "CrySystem_precompiled.h"
|
||||
|
||||
#include "CryZlib.h"
|
||||
#include "ZLibDecompressor.h"
|
||||
|
||||
class CZLibInflateStream
|
||||
: public IZLibInflateStream
|
||||
{
|
||||
public:
|
||||
CZLibInflateStream()
|
||||
: m_bStreamOpened(false)
|
||||
, m_zlibFlush(0)
|
||||
, m_currentState(eZInfState_AwaitingInput)
|
||||
, m_bytesInput(0)
|
||||
, m_bytesOutput(0)
|
||||
, m_zSize(0)
|
||||
, m_zPeak(0) {}
|
||||
|
||||
virtual void Release();
|
||||
|
||||
virtual void SetOutputBuffer(char* pInBuffer, unsigned int inSize);
|
||||
virtual unsigned int GetBytesOutput();
|
||||
virtual void Input(const char* pInSource, unsigned int inSourceSize);
|
||||
virtual void EndInput();
|
||||
virtual EZInflateState GetState();
|
||||
virtual void GetStats(IZLibInflateStream::SStats* pOutStats);
|
||||
|
||||
private:
|
||||
virtual ~CZLibInflateStream() {}
|
||||
|
||||
EZInflateState RunInflate();
|
||||
|
||||
static voidpf ZAlloc(voidpf pInOpaque, uInt inItems, uInt inSize);
|
||||
static void ZFree(voidpf pInOpaque, voidpf pInAddress);
|
||||
|
||||
z_stream m_decompressStream;
|
||||
bool m_bStreamOpened;
|
||||
int m_zlibFlush;
|
||||
EZInflateState m_currentState;
|
||||
unsigned int m_bytesInput;
|
||||
unsigned int m_bytesOutput;
|
||||
unsigned int m_zSize;
|
||||
unsigned int m_zPeak;
|
||||
};
|
||||
|
||||
IZLibInflateStream* CZLibDecompressor::CreateInflateStream()
|
||||
{
|
||||
return new CZLibInflateStream();
|
||||
}
|
||||
|
||||
void CZLibDecompressor::Release()
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
|
||||
void CZLibInflateStream::Release()
|
||||
{
|
||||
if (m_bStreamOpened)
|
||||
{
|
||||
int err = inflateEnd(&m_decompressStream);
|
||||
if (err != Z_OK)
|
||||
{
|
||||
CryLog("zlib inflateEnd() error %d returned when closing stream", err);
|
||||
}
|
||||
}
|
||||
|
||||
delete this;
|
||||
}
|
||||
|
||||
void CZLibInflateStream::SetOutputBuffer(char* pInBuffer, unsigned int inSize)
|
||||
{
|
||||
m_bytesOutput += m_decompressStream.total_out;
|
||||
|
||||
m_decompressStream.next_out = (byte*)pInBuffer;
|
||||
m_decompressStream.avail_out = inSize;
|
||||
m_decompressStream.total_out = 0;
|
||||
}
|
||||
|
||||
void CZLibInflateStream::GetStats(IZLibInflateStream::SStats* pOutStats)
|
||||
{
|
||||
pOutStats->bytesInput = m_bytesInput;
|
||||
pOutStats->bytesOutput = m_bytesOutput + m_decompressStream.total_out;
|
||||
pOutStats->curMemoryUsed = m_zSize;
|
||||
pOutStats->peakMemoryUsed = m_zPeak;
|
||||
}
|
||||
|
||||
unsigned int CZLibInflateStream::GetBytesOutput()
|
||||
{
|
||||
return m_decompressStream.total_out;
|
||||
}
|
||||
|
||||
void CZLibInflateStream::Input(const char* pInSource, unsigned int inSourceSize)
|
||||
{
|
||||
CRY_ASSERT_MESSAGE(m_currentState == eZInfState_AwaitingInput, "CZLibInflateStream::Input() called when stream is not awaiting input or has finished");
|
||||
|
||||
m_decompressStream.next_in = (Bytef*)pInSource;
|
||||
m_decompressStream.avail_in = inSourceSize;
|
||||
m_bytesInput += inSourceSize;
|
||||
}
|
||||
|
||||
void CZLibInflateStream::EndInput()
|
||||
{
|
||||
CRY_ASSERT_MESSAGE(m_currentState == eZInfState_AwaitingInput, "CZLibInflateStream::EndInput() called when stream is not awaiting input");
|
||||
|
||||
m_zlibFlush = Z_FINISH;
|
||||
}
|
||||
|
||||
voidpf CZLibInflateStream::ZAlloc(voidpf pInOpaque, uInt inItems, uInt inSize)
|
||||
{
|
||||
CZLibInflateStream* pStr = reinterpret_cast<CZLibInflateStream*>(pInOpaque);
|
||||
|
||||
const unsigned int size = inItems * inSize;
|
||||
|
||||
int* pPtr = (int*)CryModuleMalloc(sizeof(int) + size);
|
||||
|
||||
if (pPtr)
|
||||
{
|
||||
*pPtr = inItems * inSize;
|
||||
pPtr += 1;
|
||||
|
||||
const unsigned int newSize = pStr->m_zSize + size;
|
||||
pStr->m_zSize = newSize;
|
||||
if (newSize > pStr->m_zPeak)
|
||||
{
|
||||
pStr->m_zPeak = newSize;
|
||||
}
|
||||
}
|
||||
|
||||
return pPtr;
|
||||
}
|
||||
|
||||
void CZLibInflateStream::ZFree(voidpf pInOpaque, voidpf pInAddress)
|
||||
{
|
||||
int* pPtr = reinterpret_cast<int*>(pInAddress);
|
||||
|
||||
if (pPtr)
|
||||
{
|
||||
CZLibInflateStream* pStr = reinterpret_cast<CZLibInflateStream*>(pInOpaque);
|
||||
pStr->m_zSize -= pPtr[-1];
|
||||
CryModuleFree(pPtr - 1);
|
||||
}
|
||||
}
|
||||
|
||||
EZInflateState CZLibInflateStream::RunInflate()
|
||||
{
|
||||
bool runInflate = false;
|
||||
bool inputAvailable = (m_decompressStream.avail_in > 0) || (m_zlibFlush == Z_FINISH);
|
||||
bool outputAvailable = (m_decompressStream.avail_out > 0);
|
||||
|
||||
switch (m_currentState)
|
||||
{
|
||||
case eZInfState_AwaitingInput:
|
||||
case eZInfState_ConsumeOutput:
|
||||
if (inputAvailable && outputAvailable)
|
||||
{
|
||||
runInflate = true;
|
||||
}
|
||||
else if (inputAvailable || !outputAvailable)
|
||||
{
|
||||
m_currentState = eZInfState_ConsumeOutput;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_currentState = eZInfState_AwaitingInput;
|
||||
}
|
||||
break;
|
||||
|
||||
case eZInfState_Inflating:
|
||||
CRY_ASSERT_MESSAGE(false, "Shouldn't be trying to run inflate whilst a inflate is in progress");
|
||||
break;
|
||||
|
||||
case eZInfState_Error:
|
||||
break;
|
||||
|
||||
default:
|
||||
CRY_ASSERT_MESSAGE(false, "unknown state");
|
||||
break;
|
||||
}
|
||||
|
||||
if (runInflate)
|
||||
{
|
||||
if (!m_bStreamOpened)
|
||||
{
|
||||
m_bStreamOpened = true;
|
||||
|
||||
// initializing with inflateInit2 requires that the next_in be initialized
|
||||
m_decompressStream.zalloc = &CZLibInflateStream::ZAlloc;
|
||||
m_decompressStream.zfree = &CZLibInflateStream::ZFree;
|
||||
m_decompressStream.opaque = this;
|
||||
|
||||
const int error = inflateInit2(&m_decompressStream, -MAX_WBITS);
|
||||
if (error != Z_OK)
|
||||
{
|
||||
m_currentState = eZInfState_Error;
|
||||
CryLog("zlib inflateInit2() error, err %d", error);
|
||||
}
|
||||
}
|
||||
|
||||
if (m_currentState != eZInfState_Error)
|
||||
{
|
||||
int error = inflate(&m_decompressStream, m_zlibFlush);
|
||||
|
||||
if (error == Z_STREAM_END)
|
||||
{
|
||||
// end of stream has been generated, only produced if we pass Z_FINISH into inflate
|
||||
m_currentState = eZInfState_Finished;
|
||||
}
|
||||
else if ((error == Z_OK && m_decompressStream.avail_out == 0) || (error == Z_BUF_ERROR && m_decompressStream.avail_out == 0))
|
||||
{
|
||||
// output buffer has been filled
|
||||
// data should be available for consumption by caller
|
||||
m_currentState = eZInfState_ConsumeOutput;
|
||||
}
|
||||
else if (m_decompressStream.avail_in == 0)
|
||||
{
|
||||
// ran out of input data
|
||||
// data may be available for consumption - but we need more input right now
|
||||
m_currentState = eZInfState_AwaitingInput;
|
||||
}
|
||||
else
|
||||
{
|
||||
// some sort of error has occurred
|
||||
m_currentState = eZInfState_Error;
|
||||
CryLog("zlib inflate() error, err %d", error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return m_currentState;
|
||||
}
|
||||
|
||||
EZInflateState CZLibInflateStream::GetState()
|
||||
{
|
||||
return RunInflate();
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "CrySystem_precompiled.h"
|
||||
#include <zstd.h>
|
||||
#include "ZStdDecompressor.h"
|
||||
|
||||
bool CZStdDecompressor::DecompressData(const char* pIn, const uint inputSize, char* pOut, const uint outputSize)
|
||||
{
|
||||
size_t result = ZSTD_decompress(pOut, outputSize, pIn, inputSize);
|
||||
return !ZSTD_isError(result);
|
||||
}
|
||||
|
||||
void CZStdDecompressor::Release()
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
#ifndef CRYINCLUDE_CRYSYSTEM_ZIPFILE_H
|
||||
#define CRYINCLUDE_CRYSYSTEM_ZIPFILE_H
|
||||
#pragma once
|
||||
|
||||
|
||||
#endif // CRYINCLUDE_CRYSYSTEM_ZIPFILE_H
|
||||
@@ -1,76 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
#ifndef CRYINCLUDE_CRYSYSTEM_ZIPFILEFORMAT_INFO_H
|
||||
#define CRYINCLUDE_CRYSYSTEM_ZIPFILEFORMAT_INFO_H
|
||||
#pragma once
|
||||
|
||||
#include "ZipFileFormat.h"
|
||||
|
||||
#if defined(__clang__)
|
||||
# pragma clang diagnostic push
|
||||
# pragma clang diagnostic ignored "-Waddress-of-packed-member"
|
||||
#endif
|
||||
|
||||
STRUCT_INFO_BEGIN(ZipFile::CDREnd)
|
||||
VAR_INFO(lSignature)
|
||||
VAR_INFO(nDisk)
|
||||
VAR_INFO(nCDRStartDisk)
|
||||
VAR_INFO(numEntriesOnDisk)
|
||||
VAR_INFO(numEntriesTotal)
|
||||
VAR_INFO(lCDRSize)
|
||||
VAR_INFO(lCDROffset)
|
||||
VAR_INFO(nCommentLength)
|
||||
STRUCT_INFO_END(ZipFile::CDREnd)
|
||||
|
||||
STRUCT_INFO_BEGIN(ZipFile::DataDescriptor)
|
||||
VAR_INFO(lCRC32)
|
||||
VAR_INFO(lSizeCompressed)
|
||||
VAR_INFO(lSizeUncompressed)
|
||||
STRUCT_INFO_END(ZipFile::DataDescriptor)
|
||||
|
||||
STRUCT_INFO_BEGIN(ZipFile::CDRFileHeader)
|
||||
VAR_INFO(lSignature)
|
||||
VAR_INFO(nVersionMadeBy)
|
||||
VAR_INFO(nVersionNeeded)
|
||||
VAR_INFO(nFlags)
|
||||
VAR_INFO(nMethod)
|
||||
VAR_INFO(nLastModTime)
|
||||
VAR_INFO(nLastModDate)
|
||||
VAR_INFO(desc)
|
||||
VAR_INFO(nFileNameLength)
|
||||
VAR_INFO(nExtraFieldLength)
|
||||
VAR_INFO(nFileCommentLength)
|
||||
VAR_INFO(nDiskNumberStart)
|
||||
VAR_INFO(nAttrInternal)
|
||||
VAR_INFO(lAttrExternal)
|
||||
VAR_INFO(lLocalHeaderOffset)
|
||||
STRUCT_INFO_END(ZipFile::CDRFileHeader)
|
||||
|
||||
STRUCT_INFO_BEGIN(ZipFile::LocalFileHeader)
|
||||
VAR_INFO(lSignature)
|
||||
VAR_INFO(nVersionNeeded)
|
||||
VAR_INFO(nFlags)
|
||||
VAR_INFO(nMethod)
|
||||
VAR_INFO(nLastModTime)
|
||||
VAR_INFO(nLastModDate)
|
||||
VAR_INFO(desc)
|
||||
VAR_INFO(nFileNameLength)
|
||||
VAR_INFO(nExtraFieldLength)
|
||||
STRUCT_INFO_END(ZipFile::LocalFileHeader)
|
||||
|
||||
#if defined(__clang__)
|
||||
# pragma clang diagnostic pop
|
||||
#endif
|
||||
|
||||
#endif // CRYINCLUDE_CRYSYSTEM_ZIPFILEFORMAT_INFO_H
|
||||
@@ -1,3 +0,0 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:ced9f21365ad5a4159f31f602be10a00becf389fa289694026425e7a6bc73077
|
||||
size 9272
|
||||
@@ -1,18 +0,0 @@
|
||||
#
|
||||
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
# its licensors.
|
||||
#
|
||||
# For complete copyright and license terms please see the LICENSE at the root of this
|
||||
# distribution (the "License"). All use of this software is governed by the License,
|
||||
# or, if provided, by the license below or the license accompanying this file. Do not
|
||||
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
#
|
||||
|
||||
set(FILES
|
||||
MobileDetectSpec_Android.cpp
|
||||
MobileDetectSpec.cpp
|
||||
MobileDetectSpec.h
|
||||
ThermalInfoAndroid.h
|
||||
ThermalInfoAndroid.cpp
|
||||
)
|
||||
@@ -10,41 +10,20 @@
|
||||
#
|
||||
|
||||
set(FILES
|
||||
AutoDetectSpec.cpp
|
||||
AZCrySystemInitLogSink.cpp
|
||||
ClientHandler.cpp
|
||||
CmdLine.cpp
|
||||
CmdLineArg.cpp
|
||||
CompressedFile.cpp
|
||||
ConsoleBatchFile.cpp
|
||||
ConsoleHelpGen.cpp
|
||||
CryAsyncMemcpy.cpp
|
||||
HandlerBase.cpp
|
||||
Log.cpp
|
||||
SystemRender.cpp
|
||||
PhysRenderer.cpp
|
||||
ServerHandler.cpp
|
||||
ServerThrottle.cpp
|
||||
SyncLock.cpp
|
||||
System.cpp
|
||||
SystemCFG.cpp
|
||||
SystemEventDispatcher.cpp
|
||||
SystemInit.cpp
|
||||
SystemWin32.cpp
|
||||
Timer.cpp
|
||||
UnixConsole.cpp
|
||||
WindowsConsole.cpp
|
||||
XConsole.cpp
|
||||
XConsoleVariable.cpp
|
||||
AutoDetectSpec.h
|
||||
ClientHandler.h
|
||||
HandlerBase.h
|
||||
PhysRenderer.h
|
||||
ServerHandler.h
|
||||
ServerThrottle.h
|
||||
SyncLock.h
|
||||
UnixConsole.h
|
||||
SystemInit.h
|
||||
XML/ReadWriteXMLSink.h
|
||||
AZCrySystemInitLogSink.h
|
||||
AZCoreLogSink.h
|
||||
@@ -52,17 +31,13 @@ set(FILES
|
||||
CmdLineArg.h
|
||||
ConsoleBatchFile.h
|
||||
ConsoleHelpGen.h
|
||||
CryWaterMark.h
|
||||
Log.h
|
||||
resource.h
|
||||
SimpleStringPool.h
|
||||
CrySystem_precompiled.h
|
||||
System.h
|
||||
SystemCFG.h
|
||||
SystemEventDispatcher.h
|
||||
Timer.h
|
||||
Validator.h
|
||||
WindowsConsole.h
|
||||
XConsole.h
|
||||
XConsoleVariable.h
|
||||
XML/SerializeXMLReader.cpp
|
||||
@@ -78,24 +53,14 @@ set(FILES
|
||||
XML/XmlUtils.h
|
||||
XML/ReadXMLSink.cpp
|
||||
XML/WriteXMLSource.cpp
|
||||
ZipFile.h
|
||||
ZipFileFormat_info.h
|
||||
Sampler.cpp
|
||||
Sampler.h
|
||||
LocalizedStringManager.cpp
|
||||
LocalizedStringManager.h
|
||||
ZLibCompressor.cpp
|
||||
ZLibCompressor.h
|
||||
Huffman.cpp
|
||||
Huffman.h
|
||||
RemoteConsole/RemoteConsole.cpp
|
||||
RemoteConsole/RemoteConsole.h
|
||||
RemoteConsole/RemoteConsole_impl.inl
|
||||
RemoteConsole/RemoteConsole_none.inl
|
||||
ZLibDecompressor.h
|
||||
ZLibDecompressor.cpp
|
||||
LZ4Decompressor.h
|
||||
LZ4Decompressor.cpp
|
||||
LevelSystem/LevelSystem.cpp
|
||||
LevelSystem/LevelSystem.h
|
||||
LevelSystem/SpawnableLevelSystem.cpp
|
||||
@@ -106,10 +71,5 @@ set(FILES
|
||||
ViewSystem/View.h
|
||||
ViewSystem/ViewSystem.cpp
|
||||
ViewSystem/ViewSystem.h
|
||||
ZStdDecompressor.h
|
||||
ZStdDecompressor.cpp
|
||||
CrySystem_precompiled.cpp
|
||||
CPUDetect.cpp
|
||||
CPUDetect.h
|
||||
WindowsErrorReporting.cpp
|
||||
)
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
#
|
||||
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
# its licensors.
|
||||
#
|
||||
# For complete copyright and license terms please see the LICENSE at the root of this
|
||||
# distribution (the "License"). All use of this software is governed by the License,
|
||||
# or, if provided, by the license below or the license accompanying this file. Do not
|
||||
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
#
|
||||
|
||||
set(FILES
|
||||
MobileDetectSpec_Ios.cpp
|
||||
MobileDetectSpec.cpp
|
||||
MobileDetectSpec.h
|
||||
)
|
||||
@@ -1,11 +0,0 @@
|
||||
#
|
||||
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
# its licensors.
|
||||
#
|
||||
# For complete copyright and license terms please see the LICENSE at the root of this
|
||||
# distribution (the "License"). All use of this software is governed by the License,
|
||||
# or, if provided, by the license below or the license accompanying this file. Do not
|
||||
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
#
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
#
|
||||
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
# its licensors.
|
||||
#
|
||||
# For complete copyright and license terms please see the LICENSE at the root of this
|
||||
# distribution (the "License"). All use of this software is governed by the License,
|
||||
# or, if provided, by the license below or the license accompanying this file. Do not
|
||||
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
#
|
||||
|
||||
set(FILES
|
||||
Components/MathConversionTests.cpp
|
||||
Tests/Test_CLog.cpp
|
||||
Tests/Test_CommandRegistration.cpp
|
||||
Tests/Test_CryPrimitives.cpp
|
||||
Tests/test_CrySystem.cpp
|
||||
Tests/Test_Localization.cpp
|
||||
Tests/test_Main.cpp
|
||||
Tests/test_MaterialUtils.cpp
|
||||
DllMain.cpp
|
||||
)
|
||||
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
#define VS_VERSION_INFO 1
|
||||
#define IDD_CRITICAL_ERROR 101
|
||||
#define IDB_CONFIRM_SAVE 102
|
||||
#define IDB_DONT_SAVE 103
|
||||
#define IDD_CONFIRM_SAVE_LEVEL 127
|
||||
#define IDB_CRASH_FACE 128
|
||||
#define IDD_EXCEPTION 245
|
||||
#define IDC_CALLSTACK 1001
|
||||
#define IDC_EXCEPTION_CODE 1002
|
||||
#define IDC_EXCEPTION_ADDRESS 1003
|
||||
#define IDC_EXCEPTION_MODULE 1004
|
||||
#define IDC_EXCEPTION_DESC 1005
|
||||
#define IDB_EXIT 1008
|
||||
#define IDB_IGNORE 1010
|
||||
|
||||
// Next default values for new objects
|
||||
//
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NEXT_RESOURCE_VALUE 129
|
||||
#define _APS_NEXT_COMMAND_VALUE 40072
|
||||
#define _APS_NEXT_CONTROL_VALUE 1003
|
||||
#define _APS_NEXT_SYMED_VALUE 104
|
||||
#endif
|
||||
#endif
|
||||
@@ -477,7 +477,7 @@ namespace AZ
|
||||
m_console = AZ::Interface<AZ::IConsole>::Get();
|
||||
if (m_console == nullptr)
|
||||
{
|
||||
m_console = aznew AZ::Console();
|
||||
m_console = aznew AZ::Console(*m_settingsRegistry);
|
||||
AZ::Interface<AZ::IConsole>::Register(m_console);
|
||||
m_ownsConsole = true;
|
||||
m_console->LinkDeferredFunctors(AZ::ConsoleFunctorBase::GetDeferredHead());
|
||||
|
||||
@@ -13,7 +13,9 @@
|
||||
#include <AzCore/Console/Console.h>
|
||||
#include <AzCore/Console/ILogger.h>
|
||||
#include <AzCore/Interface/Interface.h>
|
||||
#include <AzCore/Serialization/Json/JsonSerializationSettings.h>
|
||||
#include <AzCore/Settings/CommandLine.h>
|
||||
#include <AzCore/Settings/SettingsRegistryMergeUtils.h>
|
||||
#include <AzCore/StringFunc/StringFunc.h>
|
||||
#include <AzCore/Utils/Utils.h>
|
||||
#include <AzCore/IO/FileIO.h>
|
||||
@@ -43,6 +45,12 @@ namespace AZ
|
||||
{
|
||||
}
|
||||
|
||||
Console::Console(AZ::SettingsRegistryInterface& settingsRegistryInterface)
|
||||
: Console()
|
||||
{
|
||||
RegisterCommandInvokerWithSettingsRegistry(settingsRegistryInterface);
|
||||
}
|
||||
|
||||
Console::~Console()
|
||||
{
|
||||
// on console destruction relink the console functors back to the deferred head
|
||||
@@ -111,51 +119,51 @@ namespace AZ
|
||||
|
||||
void Console::ExecuteConfigFile(AZStd::string_view configFileName)
|
||||
{
|
||||
IO::FixedMaxPath filePathFixed = configFileName;
|
||||
if (AZ::IO::FileIOBase* fileIOBase = AZ::IO::FileIOBase::GetInstance())
|
||||
auto settingsRegistry = AZ::SettingsRegistry::Get();
|
||||
// If the config file is a settings registry file use the SettingsRegistryInterface MergeSettingsFile function
|
||||
// otherwise use the SettingsRegistryMergeUtils MergeSettingsToRegistry_ConfigFile function to merge an INI-style
|
||||
// file to the settings registry
|
||||
AZ::IO::PathView configFile(configFileName);
|
||||
if (configFile.Extension() == ".setreg")
|
||||
{
|
||||
fileIOBase->ResolvePath(filePathFixed, configFileName);
|
||||
settingsRegistry->MergeSettingsFile(configFile.Native(), AZ::SettingsRegistryInterface::Format::JsonMergePatch);
|
||||
}
|
||||
|
||||
IO::SystemFile file;
|
||||
if (!file.Open(filePathFixed.c_str(), AZ::IO::SystemFile::SF_OPEN_READ_ONLY))
|
||||
else if (configFile.Extension() == ".setregpatch")
|
||||
{
|
||||
AZLOG_ERROR("Failed to load '%s'. File could not be opened.", filePathFixed.c_str());
|
||||
return;
|
||||
settingsRegistry->MergeSettingsFile(configFile.Native(), AZ::SettingsRegistryInterface::Format::JsonPatch);
|
||||
}
|
||||
const IO::SizeType length = file.Length();
|
||||
if (length == 0)
|
||||
else
|
||||
{
|
||||
AZLOG_ERROR("Failed to load '%s'. File is empty.", filePathFixed.c_str());
|
||||
return;
|
||||
}
|
||||
file.Seek(0, IO::SystemFile::SF_SEEK_BEGIN);
|
||||
AZStd::string fileBuffer;
|
||||
fileBuffer.resize(length);
|
||||
IO::SizeType bytesRead = file.Read(length, fileBuffer.data());
|
||||
file.Close();
|
||||
// Resize again just in case bytesRead is less than length for some reason
|
||||
fileBuffer.resize(bytesRead);
|
||||
|
||||
AZLOG_INFO("Loading config file %s", filePathFixed.c_str());
|
||||
|
||||
AZStd::vector<AZStd::string_view> separatedCommands;
|
||||
auto BreakCommandsByLine = [&separatedCommands](AZStd::string_view token)
|
||||
{
|
||||
separatedCommands.emplace_back(token);
|
||||
};
|
||||
StringFunc::TokenizeVisitor(fileBuffer, BreakCommandsByLine, "\n\r");
|
||||
|
||||
for (const auto& commandView : separatedCommands)
|
||||
{
|
||||
ConsoleCommandContainer commandArgsView;
|
||||
auto ConvertCommandStringToArray = [&commandArgsView](AZStd::string_view token)
|
||||
AZ::SettingsRegistryMergeUtils::ConfigParserSettings configParserSettings;
|
||||
configParserSettings.m_registryRootPointerPath = "/Amazon/AzCore/Runtime/ConsoleCommands";
|
||||
configParserSettings.m_commandLineSettings.m_delimiterFunc = [](AZStd::string_view line)
|
||||
{
|
||||
commandArgsView.emplace_back(token);
|
||||
SettingsRegistryInterface::CommandLineArgumentSettings::JsonPathValue pathValue;
|
||||
AZStd::string_view parsedLine = line;
|
||||
|
||||
// Splits the line based on the <equal> or <colon>
|
||||
if (auto path = AZ::StringFunc::TokenizeNext(parsedLine, "=:"); path.has_value())
|
||||
{
|
||||
pathValue.m_path = AZ::StringFunc::StripEnds(*path);
|
||||
pathValue.m_value = AZ::StringFunc::StripEnds(parsedLine);
|
||||
}
|
||||
// If the value is empty, then the line either contained an equal sign followed only by whitespace or the line was empty
|
||||
// 1. line="testInit=", pathValue.m_path="testInit", pathValue.m_value=""
|
||||
// 2. line="testInit 1", pathValue.m_path="testInit 1", pathValue.m_value=""
|
||||
// Therefore the path is split the path on whitespace in order to retrieve a value
|
||||
if (pathValue.m_value.empty())
|
||||
{
|
||||
parsedLine = pathValue.m_path;
|
||||
if (auto path = AZ::StringFunc::TokenizeNext(parsedLine, " \t"); path.has_value())
|
||||
{
|
||||
pathValue.m_path = AZ::StringFunc::StripEnds(*path);
|
||||
pathValue.m_value = AZ::StringFunc::StripEnds(parsedLine);
|
||||
}
|
||||
|
||||
}
|
||||
return pathValue;
|
||||
};
|
||||
constexpr AZStd::string_view commandSeparators = " =";
|
||||
StringFunc::TokenizeVisitor(commandView, ConvertCommandStringToArray, commandSeparators);
|
||||
PerformCommand(commandArgsView, ConsoleSilentMode::NotSilent, ConsoleInvokedFrom::AzConsole, ConsoleFunctorFlags::Null, ConsoleFunctorFlags::Null);
|
||||
AZ::SettingsRegistryMergeUtils::MergeSettingsToRegistry_ConfigFile(*settingsRegistry, configFile.Native(), configParserSettings);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -447,4 +455,134 @@ namespace AZ
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
struct ConsoleCommandKeyNotificationHandler
|
||||
{
|
||||
ConsoleCommandKeyNotificationHandler(AZ::SettingsRegistryInterface& registry, Console& console)
|
||||
: m_settingsRegistry(registry)
|
||||
, m_console(console)
|
||||
{
|
||||
}
|
||||
|
||||
// Responsible for using the Json Serialization Issue Callback system
|
||||
// to determine when a JSON Patch or JSON Merge Patch modifies a value
|
||||
// at a path underneath the IConsole::ConsoleRootCommandKey JSON pointer
|
||||
JsonSerializationResult::ResultCode operator()(AZStd::string_view message,
|
||||
JsonSerializationResult::ResultCode result, AZStd::string_view path)
|
||||
{
|
||||
AZ::IO::PathView consoleRootCommandKey{ IConsole::ConsoleRootCommandKey, AZ::IO::PosixPathSeparator };
|
||||
AZ::IO::PathView inputKey{ path, AZ::IO::PosixPathSeparator };
|
||||
if (result.GetTask() == JsonSerializationResult::Tasks::Merge
|
||||
&& result.GetProcessing() == JsonSerializationResult::Processing::Completed
|
||||
&& inputKey.IsRelativeTo(consoleRootCommandKey))
|
||||
{
|
||||
if (auto type = m_settingsRegistry.GetType(path); type != SettingsRegistryInterface::Type::NoType)
|
||||
{
|
||||
operator()(path, type);
|
||||
}
|
||||
}
|
||||
|
||||
// This is the default issue reporting, that logs using the warning category
|
||||
if (result.GetProcessing() != JsonSerializationResult::Processing::Completed)
|
||||
{
|
||||
scratchBuffer.append(message.begin(), message.end());
|
||||
scratchBuffer.append("\n Reason: ");
|
||||
result.AppendToString(scratchBuffer, path);
|
||||
scratchBuffer.append(".");
|
||||
AZ_Warning("JSON Serialization", false, "%s", scratchBuffer.c_str());
|
||||
|
||||
scratchBuffer.clear();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void operator()(AZStd::string_view path, SettingsRegistryInterface::Type type)
|
||||
{
|
||||
using FixedValueString = AZ::SettingsRegistryInterface::FixedValueString;
|
||||
|
||||
AZ::IO::PathView consoleRootCommandKey{ IConsole::ConsoleRootCommandKey, AZ::IO::PosixPathSeparator };
|
||||
AZ::IO::PathView inputKey{ path, AZ::IO::PosixPathSeparator };
|
||||
if (inputKey.IsRelativeTo(consoleRootCommandKey))
|
||||
{
|
||||
FixedValueString command = inputKey.LexicallyRelative(consoleRootCommandKey).Native();
|
||||
ConsoleCommandContainer commandArgs;
|
||||
// Argument string which stores the value from the Settings Registry long enough
|
||||
// to pass into the PerformCommand. The ConsoleCommandContainer stores string_views
|
||||
// and therefore doesn't own the memory.
|
||||
FixedValueString commandArgString;
|
||||
|
||||
if (type == SettingsRegistryInterface::Type::String)
|
||||
{
|
||||
if (m_settingsRegistry.Get(commandArgString, path))
|
||||
{
|
||||
auto ConvertCommandArgumentToArray = [&commandArgs](AZStd::string_view token)
|
||||
{
|
||||
commandArgs.emplace_back(token);
|
||||
};
|
||||
constexpr AZStd::string_view commandSeparators = " \t\n\r";
|
||||
StringFunc::TokenizeVisitor(commandArgString, ConvertCommandArgumentToArray, commandSeparators);
|
||||
}
|
||||
}
|
||||
else if (type == SettingsRegistryInterface::Type::Boolean)
|
||||
{
|
||||
bool commandArgBool{};
|
||||
if (m_settingsRegistry.Get(commandArgBool, path))
|
||||
{
|
||||
commandArgString = commandArgBool ? "true" : "false";
|
||||
commandArgs.emplace_back(commandArgString);
|
||||
}
|
||||
}
|
||||
else if (type == SettingsRegistryInterface::Type::Integer)
|
||||
{
|
||||
// Try converting to a signed 64-bit number first and then an unsigned 64-bit number
|
||||
AZ::s64 commandArgInt{};
|
||||
AZ::u64 commandArgUInt{};
|
||||
if (m_settingsRegistry.Get(commandArgInt, path))
|
||||
{
|
||||
AZStd::to_string(commandArgString, commandArgInt);
|
||||
commandArgs.emplace_back(commandArgString);
|
||||
}
|
||||
else if (m_settingsRegistry.Get(commandArgUInt, path))
|
||||
{
|
||||
AZStd::to_string(commandArgString, commandArgUInt);
|
||||
commandArgs.emplace_back(commandArgString);
|
||||
}
|
||||
}
|
||||
else if (type == SettingsRegistryInterface::Type::FloatingPoint)
|
||||
{
|
||||
double commandArgFloat{};
|
||||
if (m_settingsRegistry.Get(commandArgFloat, path))
|
||||
{
|
||||
AZStd::to_string(commandArgString, commandArgFloat);
|
||||
commandArgs.emplace_back(commandArgString);
|
||||
}
|
||||
}
|
||||
CVarFixedString commandTrace(command);
|
||||
for (AZStd::string_view commandArg : commandArgs)
|
||||
{
|
||||
commandTrace.push_back(' ');
|
||||
commandTrace += commandArg;
|
||||
}
|
||||
|
||||
m_console.PerformCommand(command, commandArgs, ConsoleSilentMode::NotSilent, ConsoleInvokedFrom::AzConsole, ConsoleFunctorFlags::Null, ConsoleFunctorFlags::Null);
|
||||
}
|
||||
}
|
||||
|
||||
AZ::Console& m_console;
|
||||
AZ::SettingsRegistryInterface& m_settingsRegistry;
|
||||
AZStd::string scratchBuffer;
|
||||
};
|
||||
|
||||
void Console::RegisterCommandInvokerWithSettingsRegistry(AZ::SettingsRegistryInterface& settingsRegistry)
|
||||
{
|
||||
// Make sure the there is a JSON object at the path of AZ::IConsole::ConsoleRootCommandKey
|
||||
// So that JSON Patch is able to add values underneath that object (JSON Patch doesn't create intermediate objects)
|
||||
settingsRegistry.MergeSettings(R"({ "Amazon": { "AzCore": { "Runtime": { "ConsoleCommands": {} } }}})",
|
||||
SettingsRegistryInterface::Format::JsonMergePatch);
|
||||
m_consoleCommandKeyHandler = settingsRegistry.RegisterNotifier(ConsoleCommandKeyNotificationHandler{ settingsRegistry, *this });
|
||||
|
||||
JsonApplyPatchSettings applyPatchSettings;
|
||||
applyPatchSettings.m_reporting = ConsoleCommandKeyNotificationHandler{ settingsRegistry, *this };
|
||||
settingsRegistry.SetApplyPatchSettings(applyPatchSettings);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
#include <AzCore/Console/IConsole.h>
|
||||
#include <AzCore/Memory/OSAllocator.h>
|
||||
#include <AzCore/Settings/SettingsRegistry.h>
|
||||
#include <AzCore/std/functional.h>
|
||||
#include <AzCore/std/containers/unordered_map.h>
|
||||
|
||||
@@ -29,6 +30,9 @@ namespace AZ
|
||||
AZ_CLASS_ALLOCATOR(Console, AZ::OSAllocator, 0);
|
||||
|
||||
Console();
|
||||
//! Constructor overload which registers a notifier with the Settings Registry that will execute
|
||||
//! a console command whenever a key is set under the AZ::IConsole::ConsoleCommandRootKey JSON object
|
||||
explicit Console(AZ::SettingsRegistryInterface& settingsRegistry);
|
||||
~Console() override;
|
||||
|
||||
//! IConsole interface
|
||||
@@ -67,6 +71,7 @@ namespace AZ
|
||||
void RegisterFunctor(ConsoleFunctorBase* functor) override;
|
||||
void UnregisterFunctor(ConsoleFunctorBase* functor) override;
|
||||
void LinkDeferredFunctors(ConsoleFunctorBase*& deferredHead) override;
|
||||
void RegisterCommandInvokerWithSettingsRegistry(AZ::SettingsRegistryInterface& settingsRegistry) override;
|
||||
//! @}
|
||||
|
||||
private:
|
||||
@@ -96,6 +101,7 @@ namespace AZ
|
||||
ConsoleFunctorBase* m_head;
|
||||
using CommandMap = AZStd::unordered_map<CVarFixedString, AZStd::vector<ConsoleFunctorBase*>>;
|
||||
CommandMap m_commands;
|
||||
AZ::SettingsRegistryInterface::NotifyEventHandler m_consoleCommandKeyHandler;
|
||||
|
||||
friend class ConsoleFunctorBase;
|
||||
};
|
||||
|
||||
@@ -148,7 +148,15 @@ namespace AZ
|
||||
{
|
||||
AZ::CVarFixedString convertCandidate{ arguments.front() };
|
||||
char* endPtr = nullptr;
|
||||
MAX_TYPE value = static_cast<MAX_TYPE>(strtoll(convertCandidate.c_str(), &endPtr, 0));
|
||||
MAX_TYPE value;
|
||||
if constexpr (AZStd::is_unsigned_v<MAX_TYPE>)
|
||||
{
|
||||
value = aznumeric_cast<MAX_TYPE>(strtoull(convertCandidate.c_str(), &endPtr, 0));
|
||||
}
|
||||
else
|
||||
{
|
||||
value = aznumeric_cast<MAX_TYPE>(strtoll(convertCandidate.c_str(), &endPtr, 0));
|
||||
}
|
||||
|
||||
if (endPtr == convertCandidate.c_str())
|
||||
{
|
||||
|
||||
@@ -22,8 +22,10 @@
|
||||
|
||||
namespace AZ
|
||||
{
|
||||
class SettingsRegistryInterface;
|
||||
class CommandLine;
|
||||
|
||||
|
||||
//! @class IConsole
|
||||
//! A simple console class for providing text based variable and process interaction.
|
||||
class IConsole
|
||||
@@ -33,6 +35,8 @@ namespace AZ
|
||||
|
||||
using FunctorVisitor = AZStd::function<void(ConsoleFunctorBase*)>;
|
||||
|
||||
inline static constexpr AZStd::string_view ConsoleRootCommandKey = "/Amazon/AzCore/Runtime/ConsoleCommands";
|
||||
|
||||
IConsole() = default;
|
||||
virtual ~IConsole() = default;
|
||||
|
||||
@@ -145,6 +149,12 @@ namespace AZ
|
||||
//! Returns the AZ::Event<> invoked whenever a console command could not be found.
|
||||
DispatchCommandNotFoundEvent& GetDispatchCommandNotFoundEvent();
|
||||
|
||||
//! Register a notification event handler with the Settings Registry
|
||||
//! That is responsible for updating console commands whenever
|
||||
//! a key is found underneath the "/Amazon/AzCore/Runtime/ConsoleCommands" JSON entry
|
||||
//! @param Settings Registry reference to register notifier with
|
||||
virtual void RegisterCommandInvokerWithSettingsRegistry(AZ::SettingsRegistryInterface& settingsRegistry) = 0;
|
||||
|
||||
AZ_DISABLE_COPY_MOVE(IConsole);
|
||||
|
||||
protected:
|
||||
|
||||
@@ -24,9 +24,7 @@ namespace AZ
|
||||
AZ_TYPE_INFO_SPECIALIZE(AZStd::chrono::system_clock::time_point, "{5C48FD59-7267-405D-9C06-1EA31379FE82}");
|
||||
|
||||
|
||||
/**
|
||||
* Wrapper that reflects a AZStd::chrono::system_clock::time_point to script.
|
||||
*/
|
||||
//! Wrapper that reflects a AZStd::chrono::system_clock::time_point to script.
|
||||
class ScriptTimePoint
|
||||
{
|
||||
public:
|
||||
@@ -38,33 +36,45 @@ namespace AZ
|
||||
explicit ScriptTimePoint(AZStd::chrono::system_clock::time_point timePoint)
|
||||
: m_timePoint(timePoint) {}
|
||||
|
||||
AZStd::string ToString() const
|
||||
{
|
||||
return AZStd::string::format("Time %llu", m_timePoint.time_since_epoch().count());
|
||||
}
|
||||
//! Formats the time point in a string formatted as: "Time <seconds since epoch>".
|
||||
AZStd::string ToString() const;
|
||||
|
||||
const AZStd::chrono::system_clock::time_point& Get() { return m_timePoint; }
|
||||
//! Returns the time point.
|
||||
const AZStd::chrono::system_clock::time_point& Get() const;
|
||||
|
||||
// Returns the time point in seconds
|
||||
double GetSeconds() const
|
||||
{
|
||||
typedef AZStd::chrono::duration<double> double_seconds;
|
||||
return AZStd::chrono::duration_cast<double_seconds>(m_timePoint.time_since_epoch()).count();
|
||||
}
|
||||
//! Returns the time point in seconds
|
||||
double GetSeconds() const;
|
||||
|
||||
// Returns the time point in milliseconds
|
||||
double GetMilliseconds() const
|
||||
{
|
||||
typedef AZStd::chrono::duration<double, AZStd::milli> double_ms;
|
||||
return AZStd::chrono::duration_cast<double_ms>(m_timePoint.time_since_epoch()).count();
|
||||
}
|
||||
//! Returns the time point in milliseconds
|
||||
double GetMilliseconds() const;
|
||||
|
||||
static void Reflect(ReflectContext* reflection);
|
||||
|
||||
protected:
|
||||
|
||||
AZStd::chrono::system_clock::time_point m_timePoint;
|
||||
};
|
||||
|
||||
inline AZStd::string ScriptTimePoint::ToString() const
|
||||
{
|
||||
return AZStd::string::format("Time %llu", m_timePoint.time_since_epoch().count());
|
||||
}
|
||||
|
||||
inline const AZStd::chrono::system_clock::time_point& ScriptTimePoint::Get() const
|
||||
{
|
||||
return m_timePoint;
|
||||
}
|
||||
|
||||
inline double ScriptTimePoint::GetSeconds() const
|
||||
{
|
||||
typedef AZStd::chrono::duration<double> double_seconds;
|
||||
return AZStd::chrono::duration_cast<double_seconds>(m_timePoint.time_since_epoch()).count();
|
||||
}
|
||||
|
||||
inline double ScriptTimePoint::GetMilliseconds() const
|
||||
{
|
||||
typedef AZStd::chrono::duration<double, AZStd::milli> double_ms;
|
||||
return AZStd::chrono::duration_cast<double_ms>(m_timePoint.time_since_epoch()).count();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -11,13 +11,17 @@
|
||||
*/
|
||||
|
||||
#include <AzCore/Casting/numeric_cast.h>
|
||||
#include <AzCore/JSON/stringbuffer.h>
|
||||
#include <AzCore/Serialization/Json/JsonMerger.h>
|
||||
#include <AzCore/Serialization/Json/JsonSerialization.h>
|
||||
#include <AzCore/Serialization/Json/StackedString.h>
|
||||
#include <AzCore/std/string/fixed_string.h>
|
||||
#include <AzCore/std/string/osstring.h>
|
||||
|
||||
namespace AZ
|
||||
{
|
||||
using ReporterString = AZStd::fixed_string<1024>;
|
||||
|
||||
JsonSerializationResult::ResultCode JsonMerger::ApplyPatch(rapidjson::Value& target,
|
||||
rapidjson::Document::AllocatorType& allocator, const rapidjson::Value& patch,
|
||||
JsonApplyPatchSettings& settings)
|
||||
@@ -105,8 +109,7 @@ namespace AZ
|
||||
}
|
||||
else
|
||||
{
|
||||
AZ::OSString message = AZ::OSString::format(R"(Unknown operation "%.*s".)",
|
||||
aznumeric_cast<int>(operationName.length()), operationName.data());
|
||||
auto message = ReporterString::format(R"(Unknown operation "%.*s".)", AZ_STRING_ARG(operationName));
|
||||
return settings.m_reporting(message.c_str(), ResultCode(Tasks::Merge, Outcomes::Unknown), element);
|
||||
}
|
||||
|
||||
@@ -131,6 +134,14 @@ namespace AZ
|
||||
JsonSerializationResult::ResultCode JsonMerger::ApplyMergePatch(rapidjson::Value& target,
|
||||
rapidjson::Document::AllocatorType& allocator, const rapidjson::Value& patch,
|
||||
JsonApplyPatchSettings& settings)
|
||||
{
|
||||
StackedString element(StackedString::Format::JsonPointer);
|
||||
return ApplyMergePatchInternal(target, allocator, patch, settings, element);
|
||||
}
|
||||
|
||||
JsonSerializationResult::ResultCode JsonMerger::ApplyMergePatchInternal(rapidjson::Value& target,
|
||||
rapidjson::Document::AllocatorType& allocator, const rapidjson::Value& patch,
|
||||
JsonApplyPatchSettings& settings, StackedString& element)
|
||||
{
|
||||
using namespace JsonSerializationResult;
|
||||
|
||||
@@ -150,14 +161,18 @@ namespace AZ
|
||||
{
|
||||
if (targetField != target.MemberEnd())
|
||||
{
|
||||
result.Combine(ApplyMergePatch(targetField->value, allocator, field.value, settings));
|
||||
ScopedStackedString fieldNameScope{ element,
|
||||
AZStd::string_view(field.name.GetString(), field.name.GetStringLength()) };
|
||||
result.Combine(ApplyMergePatchInternal(targetField->value, allocator, field.value, settings, element));
|
||||
}
|
||||
else
|
||||
{
|
||||
rapidjson::Value name;
|
||||
name.CopyFrom(field.name, allocator, true);
|
||||
rapidjson::Value value;
|
||||
result.Combine(ApplyMergePatch(value, allocator, field.value, settings));
|
||||
ScopedStackedString fieldNameScope{ element,
|
||||
AZStd::string_view(field.name.GetString(), field.name.GetStringLength()) };
|
||||
result.Combine(ApplyMergePatchInternal(value, allocator, field.value, settings, element));
|
||||
target.AddMember(AZStd::move(name), AZStd::move(value), allocator);
|
||||
}
|
||||
}
|
||||
@@ -165,7 +180,14 @@ namespace AZ
|
||||
{
|
||||
if (targetField != target.MemberEnd())
|
||||
{
|
||||
ScopedStackedString fieldNameScope{ element,
|
||||
AZStd::string_view(field.name.GetString(), field.name.GetStringLength()) };
|
||||
AZStd::string_view jsonPath = element.Get();
|
||||
|
||||
target.RemoveMember(targetField);
|
||||
result.Combine(settings.m_reporting(ReporterString::format(
|
||||
R"(Successfully removed member from "%.*s" using JSON Merge Patch)", AZ_STRING_ARG(jsonPath)),
|
||||
ResultCode(Tasks::Merge, Outcomes::Success), element));
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -173,6 +195,12 @@ namespace AZ
|
||||
if (targetField != target.MemberEnd())
|
||||
{
|
||||
targetField->value.CopyFrom(field.value, allocator, true);
|
||||
|
||||
ScopedStackedString fieldNameScope{ element, AZStd::string_view(field.name.GetString(), field.name.GetStringLength()) };
|
||||
AZStd::string_view jsonPath = element.Get();
|
||||
result.Combine(settings.m_reporting(ReporterString::format(
|
||||
R"(Successfully updated JSON field "%.*s" using JSON Merge Patch)", AZ_STRING_ARG(jsonPath)),
|
||||
ResultCode(Tasks::Merge, Outcomes::Success), element));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -181,6 +209,12 @@ namespace AZ
|
||||
name.CopyFrom(field.name, allocator, true);
|
||||
value.CopyFrom(field.value, allocator, true);
|
||||
target.AddMember(AZStd::move(name), AZStd::move(value), allocator);
|
||||
|
||||
ScopedStackedString fieldNameScope{ element, AZStd::string_view(field.name.GetString(), field.name.GetStringLength()) };
|
||||
AZStd::string_view jsonPath = element.Get();
|
||||
result.Combine(settings.m_reporting(ReporterString::format(
|
||||
R"(Successfully added JSON field "%.*s" using JSON Merge Patch)", AZ_STRING_ARG(jsonPath)),
|
||||
ResultCode(Tasks::Merge, Outcomes::Success), element));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -190,7 +224,7 @@ namespace AZ
|
||||
target.CopyFrom(patch, allocator, true);
|
||||
}
|
||||
result.Combine(settings.m_reporting("Successfully applied patch to target using JSON Merge Patch.",
|
||||
ResultCode(Tasks::Merge, Outcomes::Success), StackedString(StackedString::Format::JsonPointer)));
|
||||
ResultCode(Tasks::Merge, Outcomes::Success), element));
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -268,9 +302,11 @@ namespace AZ
|
||||
const rapidjson::Pointer::Token* const tokens = path.GetTokens();
|
||||
if (path.GetTokenCount() == 0)
|
||||
{
|
||||
rapidjson::StringBuffer pointerPathString;
|
||||
path.Stringify(pointerPathString);
|
||||
target = AZStd::move(newValue);
|
||||
return settings.m_reporting(R"(Successfully applied "add" operation.)",
|
||||
ResultCode(Tasks::Merge, Outcomes::Success), element);
|
||||
ResultCode(Tasks::Merge, Outcomes::Success), pointerPathString.GetString());
|
||||
}
|
||||
|
||||
rapidjson::Pointer parent = rapidjson::Pointer(tokens, path.GetTokenCount() - 1);
|
||||
@@ -342,8 +378,10 @@ namespace AZ
|
||||
ResultCode(Tasks::Merge, Outcomes::TypeMismatch), element);
|
||||
}
|
||||
|
||||
rapidjson::StringBuffer pointerPathString;
|
||||
path.Stringify(pointerPathString);
|
||||
return settings.m_reporting(R"(Successfully applied "add" operation.)",
|
||||
ResultCode(Tasks::Merge, Outcomes::Success), element);
|
||||
ResultCode(Tasks::Merge, Outcomes::Success), pointerPathString.GetString());
|
||||
}
|
||||
|
||||
JsonSerializationResult::ResultCode JsonMerger::ApplyPatch_Remove(rapidjson::Value& target, const rapidjson::Pointer& path,
|
||||
@@ -393,8 +431,10 @@ namespace AZ
|
||||
ResultCode(Tasks::Merge, Outcomes::TypeMismatch), element);
|
||||
}
|
||||
|
||||
rapidjson::StringBuffer pointerPathString;
|
||||
path.Stringify(pointerPathString);
|
||||
return settings.m_reporting(R"(Successfully applied "remove" operation.)",
|
||||
ResultCode(Tasks::Merge, Outcomes::Success), element);
|
||||
ResultCode(Tasks::Merge, Outcomes::Success), pointerPathString.GetString());
|
||||
}
|
||||
|
||||
JsonSerializationResult::ResultCode JsonMerger::ApplyPatch_Replace(rapidjson::Value& target,
|
||||
@@ -420,8 +460,10 @@ namespace AZ
|
||||
|
||||
memberValue->CopyFrom(value->value, allocator);
|
||||
|
||||
rapidjson::StringBuffer pointerPathString;
|
||||
path.Stringify(pointerPathString);
|
||||
return settings.m_reporting(R"(Successfully applied "replace" operation.)",
|
||||
ResultCode(Tasks::Merge, Outcomes::Success), element);
|
||||
ResultCode(Tasks::Merge, Outcomes::Success), pointerPathString.GetString());
|
||||
}
|
||||
|
||||
JsonSerializationResult::ResultCode JsonMerger::ApplyPatch_Move(rapidjson::Value& target,
|
||||
|
||||
@@ -42,6 +42,11 @@ namespace AZ
|
||||
rapidjson::Document::AllocatorType& allocator, const rapidjson::Value& patch,
|
||||
JsonApplyPatchSettings& settings);
|
||||
|
||||
//! Implementation of the JSON Merge Patch algorithm: https://tools.ietf.org/html/rfc7386
|
||||
static JsonSerializationResult::ResultCode ApplyMergePatchInternal(rapidjson::Value& target,
|
||||
rapidjson::Document::AllocatorType& allocator, const rapidjson::Value& patch,
|
||||
JsonApplyPatchSettings& settings, StackedString& element);
|
||||
|
||||
//! Function to create JSON Merge Patches: https://tools.ietf.org/html/rfc7386
|
||||
static JsonSerializationResult::ResultCode CreateMergePatch(rapidjson::Value& patch,
|
||||
rapidjson::Document::AllocatorType& allocator, const rapidjson::Value& source,
|
||||
|
||||
@@ -88,4 +88,28 @@ namespace AZ
|
||||
{
|
||||
return index < m_names.size() ? m_names[index] : AZStd::string_view();
|
||||
}
|
||||
|
||||
SettingsRegistryInterface::CommandLineArgumentSettings::CommandLineArgumentSettings()
|
||||
{
|
||||
m_delimiterFunc = [](AZStd::string_view line) -> JsonPathValue
|
||||
{
|
||||
constexpr AZStd::string_view CommandLineArgumentDelimiters{ "=:" };
|
||||
JsonPathValue pathValue;
|
||||
pathValue.m_value = line;
|
||||
|
||||
// Splits the line on the first delimiter and stores that in the pathValue.m_path variable
|
||||
// The StringFunc::TokenizeNext function updates the pathValue.m_value parameter in place
|
||||
// to contain all the text after the first delimiter
|
||||
// So if pathValue.m_value="foo = Hello Ice Cream=World:17", the call to TokenizeNext would
|
||||
// split the value as follows
|
||||
// pathValue.m_path = "foo"
|
||||
// pathValue.m_value = "Hello Ice Cream=World:17"
|
||||
if (auto path = AZ::StringFunc::TokenizeNext(pathValue.m_value, CommandLineArgumentDelimiters); path.has_value())
|
||||
{
|
||||
pathValue.m_path = AZ::StringFunc::StripEnds(*path);
|
||||
}
|
||||
pathValue.m_value = AZ::StringFunc::StripEnds(pathValue.m_value);
|
||||
return pathValue;
|
||||
};
|
||||
}
|
||||
} // namespace AZ
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
|
||||
namespace AZ
|
||||
{
|
||||
struct JsonApplyPatchSettings;
|
||||
//! The Settings Registry is the central storage for global settings. Having application-wide settings
|
||||
//! stored in a central location allows different tools such as command lines, consoles, configuration
|
||||
//! files, etc. to work in a universal way.
|
||||
@@ -260,21 +261,20 @@ namespace AZ
|
||||
virtual bool Remove(AZStd::string_view path) = 0;
|
||||
|
||||
//! Structure which contains configuration settings for how to parse a single command line argument
|
||||
//! It supports supplying a functor for determining if a character is a delimiter
|
||||
//! It supports supplying a functor for splitting a line into JSON path and JSON value
|
||||
struct CommandLineArgumentSettings
|
||||
{
|
||||
inline static constexpr AZStd::string_view CommandLineArgumentDelimiters{ "=:"};
|
||||
CommandLineArgumentSettings()
|
||||
struct JsonPathValue
|
||||
{
|
||||
m_delimiterFunc = [](const char delimiter) -> bool
|
||||
{
|
||||
return CommandLineArgumentDelimiters.find_first_of(delimiter) != AZStd::string_view::npos;
|
||||
};
|
||||
}
|
||||
|
||||
//! Callback function which is invoked to determine whether a delimiter has been found
|
||||
//! return value of true indicates that a delimiter has been found
|
||||
using DelimiterFunc = AZStd::function<bool(const char delimiter)>;
|
||||
AZStd::string_view m_path;
|
||||
AZStd::string_view m_value;
|
||||
};
|
||||
|
||||
CommandLineArgumentSettings();
|
||||
|
||||
//! Callback function which is invoked to determine how to split a command line argument
|
||||
//! into a JSON path and a JSON value
|
||||
using DelimiterFunc = AZStd::function<JsonPathValue(AZStd::string_view line)>;
|
||||
DelimiterFunc m_delimiterFunc;
|
||||
};
|
||||
//! Merges a single command line argument into the settings registry. Command line arguments
|
||||
@@ -322,6 +322,14 @@ namespace AZ
|
||||
//! @return True if the registry folder was successfully merged, otherwise false.
|
||||
virtual bool MergeSettingsFolder(AZStd::string_view path, const Specializations& specializations,
|
||||
AZStd::string_view platform = {}, AZStd::string_view rootKey = "", AZStd::vector<char>* scratchBuffer = nullptr) = 0;
|
||||
|
||||
//! Stores the settings structure which is used when merging settings to the Settings Registry
|
||||
//! using JSON Merge Patch or JSON Merge Patch.
|
||||
//! The settings contain an issue reporting callback which can be used to track patching process.
|
||||
//! Potential application of the reporting callback could be to update a UI whenever a key receives an updated value
|
||||
//! @param applyPatchSettings The ApplyPatchSettings which are using during JSON Merging
|
||||
virtual void SetApplyPatchSettings(const AZ::JsonApplyPatchSettings& applyPatchSettings) = 0;
|
||||
virtual void GetApplyPatchSettings(AZ::JsonApplyPatchSettings& applyPatchSettings) = 0;
|
||||
};
|
||||
|
||||
inline SettingsRegistryInterface::Visitor::~Visitor() = default;
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
*/
|
||||
|
||||
#include <cctype>
|
||||
#include <cerrno>
|
||||
#include <AzCore/Casting/numeric_cast.h>
|
||||
#include <AzCore/JSON/error/en.h>
|
||||
#include <AzCore/Serialization/Json/JsonSerialization.h>
|
||||
@@ -419,9 +420,6 @@ namespace AZ
|
||||
bool SettingsRegistryImpl::MergeCommandLineArgument(AZStd::string_view argument, AZStd::string_view rootKey,
|
||||
const CommandLineArgumentSettings& commandLineSettings)
|
||||
{
|
||||
const char* front = argument.begin();
|
||||
const char* back = argument.end();
|
||||
|
||||
if (!commandLineSettings.m_delimiterFunc)
|
||||
{
|
||||
AZ_Error("SettingsRegistry", false,
|
||||
@@ -429,87 +427,40 @@ namespace AZ
|
||||
aznumeric_cast<int>(argument.size()), argument.data());
|
||||
return false;
|
||||
}
|
||||
const char* split = AZStd::find_if(front, back, commandLineSettings.m_delimiterFunc);
|
||||
if (split == front || // There is no key
|
||||
split == (back-1) || // There is no value
|
||||
split == back) // Split character not found.
|
||||
|
||||
auto [key, value] = commandLineSettings.m_delimiterFunc(argument);
|
||||
if (key.empty())
|
||||
{
|
||||
// They key where to set the JSON value cannot be empty
|
||||
// The value of the JSON can be though
|
||||
// This is so that a key can be set to empty string using "/KeyPath="
|
||||
return false;
|
||||
}
|
||||
|
||||
const char* keyStart = front;
|
||||
while (std::isspace(*keyStart)) // This is safe because it will eventually stop on =
|
||||
// Prepend the rootKey as an anchor to the argument key
|
||||
SettingsRegistryInterface::FixedValueString keyPath{ rootKey.ends_with('/')
|
||||
? rootKey.substr(0, rootKey.size() - 1)
|
||||
: rootKey };
|
||||
// Append the JSON reference token prefix of '/' to the keyPath
|
||||
if (!key.starts_with('/'))
|
||||
{
|
||||
keyStart++;
|
||||
keyPath.push_back('/');
|
||||
}
|
||||
if (keyStart == split) // Key is just white spaces
|
||||
if ((key.size() + keyPath.size()) > keyPath.max_size())
|
||||
{
|
||||
// The key portion is longer than the FixedValueString max size that can be stored
|
||||
// This limitation is arbitrary, if an AZStd::string is used or if the C++17 std::to_chars
|
||||
// function is used, there wouldn't need to be a limitation
|
||||
return false;
|
||||
}
|
||||
const char* keyEnd = split;
|
||||
while (std::isspace(*--keyEnd));
|
||||
keyEnd++;
|
||||
keyPath += key;
|
||||
key = keyPath;
|
||||
|
||||
char buffer[MaxJsonPathLength];
|
||||
AZStd::string_view key;
|
||||
bool keyHasDivider = *keyStart == '/';
|
||||
if (!rootKey.empty())
|
||||
if (value.empty())
|
||||
{
|
||||
bool rootKeyHasDivider = (rootKey[rootKey.length() - 1]) == '/';
|
||||
size_t count;
|
||||
if (!rootKeyHasDivider && !keyHasDivider)
|
||||
{
|
||||
count = azsnprintf(buffer, AZ_ARRAY_SIZE(buffer), "%.*s/%.*s",
|
||||
aznumeric_cast<int>(rootKey.length()), rootKey.data(),
|
||||
aznumeric_cast<int>(keyEnd - keyStart), keyStart);
|
||||
}
|
||||
else if (rootKeyHasDivider && keyHasDivider)
|
||||
{
|
||||
count = azsnprintf(buffer, AZ_ARRAY_SIZE(buffer), "%.*s%.*s",
|
||||
aznumeric_cast<int>(rootKey.length()) - 1, rootKey.data(),
|
||||
aznumeric_cast<int>(keyEnd - keyStart), keyStart);
|
||||
}
|
||||
else
|
||||
{
|
||||
count = azsnprintf(buffer, AZ_ARRAY_SIZE(buffer), "%.*s%.*s",
|
||||
aznumeric_cast<int>(rootKey.length()), rootKey.data(),
|
||||
aznumeric_cast<int>(keyEnd - keyStart), keyStart);
|
||||
}
|
||||
if (count >= AZ_ARRAY_SIZE(buffer) - 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
key = AZStd::string_view(buffer, count);
|
||||
}
|
||||
else if (!keyHasDivider)
|
||||
{
|
||||
size_t count = azsnprintf(buffer, AZ_ARRAY_SIZE(buffer), "/%.*s",
|
||||
aznumeric_cast<int>(keyEnd - keyStart), keyStart);
|
||||
if (count >= AZ_ARRAY_SIZE(buffer) - 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
key = AZStd::string_view(buffer, count);
|
||||
}
|
||||
else
|
||||
{
|
||||
key = AZStd::string_view(keyStart, keyEnd);
|
||||
return Set(key, value);
|
||||
}
|
||||
|
||||
const char* valueStart = split + 1;
|
||||
while (std::isspace(*valueStart) && valueStart < back)
|
||||
{
|
||||
valueStart++;
|
||||
}
|
||||
if (valueStart == back)
|
||||
{
|
||||
return false; // The value is empty
|
||||
}
|
||||
const char* valueEnd = back;
|
||||
while (std::isspace(*(--valueEnd)));
|
||||
valueEnd++;
|
||||
|
||||
AZStd::string_view value(valueStart, valueEnd);
|
||||
if (value == "true")
|
||||
{
|
||||
return Set(key, true);
|
||||
@@ -519,23 +470,35 @@ namespace AZ
|
||||
return Set(key, false);
|
||||
}
|
||||
|
||||
if (value.length() - 1 >= MaxCommandLineArgumentLength)
|
||||
SettingsRegistryInterface::FixedValueString valueString;
|
||||
if (value.size() > valueString.max_size())
|
||||
{
|
||||
// The value portion is longer than the FixedValueString max size that can be stored
|
||||
// This limitation is arbitrary, if an AZStd::string is used or if the C++17 std::to_chars
|
||||
// function is used, there wouldn't need to be a limitation
|
||||
return false;
|
||||
}
|
||||
char argumentString[MaxCommandLineArgumentLength];
|
||||
snprintf(argumentString, AZ_ARRAY_SIZE(argument), "%.*s", aznumeric_cast<int>(value.length()), value.data());
|
||||
char* argumentStringEnd = argumentString + value.length();
|
||||
valueString = value;
|
||||
const char* valueStringEnd = valueString.c_str() + valueString.size();
|
||||
|
||||
errno = 0;
|
||||
char* convertEnd = nullptr;
|
||||
s64 intValue = strtoll(argumentString, &convertEnd, 0);
|
||||
if (convertEnd == argumentStringEnd)
|
||||
s64 intValue = strtoll(valueString.c_str(), &convertEnd, 0);
|
||||
if (errno != ERANGE && convertEnd == valueStringEnd)
|
||||
{
|
||||
return Set(key, intValue);
|
||||
}
|
||||
errno = 0;
|
||||
convertEnd = nullptr;
|
||||
double floatingPointValue = strtod(argumentString, &convertEnd);
|
||||
if (convertEnd == argumentStringEnd)
|
||||
u64 uintValue = strtoull(valueString.c_str(), &convertEnd, 0);
|
||||
if (errno != ERANGE && convertEnd == valueStringEnd)
|
||||
{
|
||||
return Set(key, uintValue);
|
||||
}
|
||||
errno = 0;
|
||||
convertEnd = nullptr;
|
||||
double floatingPointValue = strtod(valueString.c_str(), &convertEnd);
|
||||
if (errno != ERANGE && convertEnd == valueStringEnd)
|
||||
{
|
||||
return Set(key, floatingPointValue);
|
||||
}
|
||||
@@ -611,7 +574,7 @@ namespace AZ
|
||||
}
|
||||
else
|
||||
{
|
||||
if (MaxFilePathLength < path.length() + 1)
|
||||
if (AZ::IO::MaxPathLength < path.length() + 1)
|
||||
{
|
||||
AZ_Error("Settings Registry", false,
|
||||
R"(Path "%.*s" is too long. Either make sure that the provided path is terminated or use a shorter path.)",
|
||||
@@ -623,10 +586,8 @@ namespace AZ
|
||||
.AddMember(StringRef("Path"), AZStd::move(pathValue), m_settings.GetAllocator());
|
||||
return false;
|
||||
}
|
||||
char filePath[MaxFilePathLength];
|
||||
azstrncpy(filePath, AZ_ARRAY_SIZE(filePath), path.data(), path.length());
|
||||
filePath[path.length()] = 0;
|
||||
result = MergeSettingsFileInternal(filePath, format, rootKey, *scratchBuffer);
|
||||
AZ::IO::FixedMaxPathString filePath(path);
|
||||
result = MergeSettingsFileInternal(filePath.c_str(), format, rootKey, *scratchBuffer);
|
||||
}
|
||||
|
||||
scratchBuffer->clear();
|
||||
@@ -660,7 +621,7 @@ namespace AZ
|
||||
additionalSpaceRequired += AZ_ARRAY_SIZE(PlatformFolder) + platform.length() + 2; // +2 for the two slashes.
|
||||
}
|
||||
|
||||
if (path.length() + additionalSpaceRequired > MaxFilePathLength)
|
||||
if (path.length() + additionalSpaceRequired > AZ::IO::MaxPathLength)
|
||||
{
|
||||
AZ_Error("Settings Registry", false, "Folder path for the Setting Registry is too long: %.*s",
|
||||
static_cast<int>(path.size()), path.data());
|
||||
@@ -673,7 +634,7 @@ namespace AZ
|
||||
RegistryFileList fileList;
|
||||
scratchBuffer->clear();
|
||||
|
||||
AZStd::fixed_string<MaxFilePathLength> folderPath{ path };
|
||||
AZ::IO::FixedMaxPathString folderPath{ path };
|
||||
constexpr AZStd::string_view pathSeparators{ AZ_CORRECT_AND_WRONG_DATABASE_SEPARATOR };
|
||||
if (pathSeparators.find_first_of(folderPath.back()) == AZStd::string_view::npos)
|
||||
{
|
||||
@@ -926,7 +887,7 @@ namespace AZ
|
||||
// Sort by the name first so the registry file gets applied with all its specializations.
|
||||
if (lhs.m_tags[0] != rhs.m_tags[0])
|
||||
{
|
||||
return strcmp(lhs.m_relativePath, rhs.m_relativePath) < 0;
|
||||
return lhs.m_relativePath < rhs.m_relativePath;
|
||||
}
|
||||
|
||||
// Then sort by size first so the files with the fewest specializations get applied first.
|
||||
@@ -956,14 +917,14 @@ namespace AZ
|
||||
}
|
||||
|
||||
collisionFound = true;
|
||||
AZ_Error("Settings Registry", false, R"(Two registry files point to the same specialization: "%s" and "%s")",
|
||||
lhs.m_relativePath, rhs.m_relativePath);
|
||||
AZ_Error("Settings Registry", false, R"(Two registry files in "%.*s" point to the same specialization: "%s" and "%s")",
|
||||
AZ_STRING_ARG(folderPath), lhs.m_relativePath.c_str(), rhs.m_relativePath.c_str());
|
||||
historyPointer.Create(m_settings, m_settings.GetAllocator()).SetObject()
|
||||
.AddMember(StringRef("Error"), StringRef("Too many files in registry folder."), m_settings.GetAllocator())
|
||||
.AddMember(StringRef("Path"),
|
||||
Value(folderPath.data(), aznumeric_caster(folderPath.length()), m_settings.GetAllocator()), m_settings.GetAllocator())
|
||||
.AddMember(StringRef("File1"), Value(lhs.m_relativePath, m_settings.GetAllocator()), m_settings.GetAllocator())
|
||||
.AddMember(StringRef("File2"), Value(rhs.m_relativePath, m_settings.GetAllocator()), m_settings.GetAllocator());
|
||||
.AddMember(StringRef("File1"), Value(lhs.m_relativePath.c_str(), m_settings.GetAllocator()), m_settings.GetAllocator())
|
||||
.AddMember(StringRef("File2"), Value(rhs.m_relativePath.c_str(), m_settings.GetAllocator()), m_settings.GetAllocator());
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1036,9 +997,9 @@ namespace AZ
|
||||
// thats the name tag.
|
||||
AZStd::sort(AZStd::next(output.m_tags.begin()), output.m_tags.end());
|
||||
|
||||
if (filePathSize < AZ_ARRAY_SIZE(output.m_relativePath))
|
||||
if (filePathSize < output.m_relativePath.max_size())
|
||||
{
|
||||
azstrcpy(output.m_relativePath, AZ_ARRAY_SIZE(output.m_relativePath), filename);
|
||||
output.m_relativePath = filename;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
@@ -1145,7 +1106,7 @@ namespace AZ
|
||||
JsonSerializationResult::ResultCode mergeResult(JsonSerializationResult::Tasks::Merge);
|
||||
if (rootKey.empty())
|
||||
{
|
||||
mergeResult = JsonSerialization::ApplyPatch(m_settings, m_settings.GetAllocator(), jsonPatch, mergeApproach);
|
||||
mergeResult = JsonSerialization::ApplyPatch(m_settings, m_settings.GetAllocator(), jsonPatch, mergeApproach, m_applyPatchSettings);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1153,7 +1114,7 @@ namespace AZ
|
||||
if (root.IsValid())
|
||||
{
|
||||
Value& rootValue = root.Create(m_settings, m_settings.GetAllocator());
|
||||
mergeResult = JsonSerialization::ApplyPatch(rootValue, m_settings.GetAllocator(), jsonPatch, mergeApproach);
|
||||
mergeResult = JsonSerialization::ApplyPatch(rootValue, m_settings.GetAllocator(), jsonPatch, mergeApproach, m_applyPatchSettings);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1180,4 +1141,13 @@ namespace AZ
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void SettingsRegistryImpl::SetApplyPatchSettings(const AZ::JsonApplyPatchSettings& applyPatchSettings)
|
||||
{
|
||||
m_applyPatchSettings = applyPatchSettings;
|
||||
}
|
||||
void SettingsRegistryImpl::GetApplyPatchSettings(AZ::JsonApplyPatchSettings& applyPatchSettings)
|
||||
{
|
||||
applyPatchSettings = m_applyPatchSettings;
|
||||
}
|
||||
} // namespace AZ
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
#include <AzCore/JSON/document.h>
|
||||
#include <AzCore/JSON/pointer.h>
|
||||
#include <AzCore/IO/Path/Path_fwd.h>
|
||||
#include <AzCore/Interface/Interface.h>
|
||||
#include <AzCore/Serialization/Json/JsonSerialization.h>
|
||||
#include <AzCore/Settings/SettingsRegistry.h>
|
||||
@@ -35,9 +36,6 @@ namespace AZ
|
||||
AZ_CLASS_ALLOCATOR(SettingsRegistryImpl, AZ::OSAllocator, 0);
|
||||
AZ_RTTI(AZ::SettingsRegistryImpl, "{E9C34190-F888-48CA-83C9-9F24B4E21D72}", AZ::SettingsRegistryInterface);
|
||||
|
||||
static constexpr size_t MaxFilePathLength = AZ_MAX_PATH_LEN;
|
||||
static constexpr size_t MaxJsonPathLength = 1024;
|
||||
static constexpr size_t MaxCommandLineArgumentLength = 1024;
|
||||
static constexpr size_t MaxRegistryFolderEntries = 128;
|
||||
|
||||
SettingsRegistryImpl();
|
||||
@@ -80,11 +78,14 @@ namespace AZ
|
||||
bool MergeSettingsFolder(AZStd::string_view path, const Specializations& specializations,
|
||||
AZStd::string_view platform, AZStd::string_view rootKey = "", AZStd::vector<char>* scratchBuffer = nullptr) override;
|
||||
|
||||
void SetApplyPatchSettings(const AZ::JsonApplyPatchSettings& applyPatchSettings) override;
|
||||
void GetApplyPatchSettings(AZ::JsonApplyPatchSettings& applyPatchSettings) override;
|
||||
|
||||
private:
|
||||
using TagList = AZStd::fixed_vector<size_t, Specializations::MaxCount + 1>;
|
||||
struct RegistryFile
|
||||
{
|
||||
char m_relativePath[MaxFilePathLength]{ 0 };
|
||||
AZ::IO::FixedMaxPathString m_relativePath;
|
||||
TagList m_tags;
|
||||
bool m_isPatch{ false };
|
||||
bool m_isPlatformFile{ false };
|
||||
@@ -109,5 +110,6 @@ namespace AZ
|
||||
rapidjson::Document m_settings;
|
||||
JsonSerializerSettings m_serializationSettings;
|
||||
JsonDeserializerSettings m_deserializationSettings;
|
||||
JsonApplyPatchSettings m_applyPatchSettings;
|
||||
};
|
||||
} // namespace AZ
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user