Initial commit

This commit is contained in:
alexpete
2021-03-05 11:26:34 -08:00
commit a10351f38d
27091 changed files with 5521199 additions and 0 deletions
@@ -0,0 +1,174 @@
/*
* 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 "ResourceCompilerPC_precompiled.h"
#include "../CryEngine/Cry3DEngine/CGF/ChunkFile.h"
#include "StaticObjectCompiler.h"
#include "CGF/CGFSaver.h"
#include "MathHelpers.h"
#include "StringHelpers.h"
#include "AssetWriter.h"
#include <SceneAPI/SceneCore/DataTypes/Groups/IAnimationGroup.h>
const bool AssetWriter::s_swapEndian;
bool AssetWriter::WriteCGF(CContentCGF* content)
{
if (!content)
{
return false;
}
CChunkFile chunkFile;
CSaverCGF cgfSaver(chunkFile);
#if defined(AZ_PLATFORM_WINDOWS)
// _EM_INVALID is used to avoid Floating Point Exception inside CryPhysics
MathHelpers::AutoFloatingPointExceptions autoFpe(~(_EM_INEXACT | _EM_UNDERFLOW | _EM_INVALID));
#endif
CStaticObjectCompiler compiler(false);
CContentCGF* const pCompiledCGF = compiler.MakeCompiledCGF(content);
if (!pCompiledCGF)
{
return false;
}
const bool bNeedEndianSwap = false;
const bool bUseQtangents = false;
const bool bStorePositionsAsF16 = false;
const bool bStoreIndicesAsU16 = false;
cgfSaver.SaveContent(pCompiledCGF, bNeedEndianSwap, bStorePositionsAsF16, bUseQtangents, bStoreIndicesAsU16);
chunkFile.Write(content->GetFilename());
return true;
}
//
// Implemented by referencing to ColladaCompiler::CompileToCHR
//
bool AssetWriter::WriteCHR(CContentCGF* content, [[maybe_unused]] IConvertContext* convertContext)
{
if (!content)
{
return false;
}
CChunkFile chunkFile;
CSaverCGF cgfSaver(chunkFile);
cgfSaver.SetContent(content);
cgfSaver.SaveExportFlags(s_swapEndian);
if (!PrepareSkeletonDataChunks(&cgfSaver))
{
return false;
}
return true;
}
bool AssetWriter::WriteSKIN(CContentCGF* content, [[maybe_unused]] IConvertContext* convertContext, bool exportMorphTargets)
{
if (!content)
{
return false;
}
CChunkFile chunkFile;
CSaverCGF cgfSaver(chunkFile);
cgfSaver.SetContent(content);
cgfSaver.SaveExportFlags(s_swapEndian);
cgfSaver.SaveMaterials(s_swapEndian);
cgfSaver.SaveUncompiledNodes();
if (exportMorphTargets)
{
cgfSaver.SaveUncompiledMorphTargets();
}
if (!PrepareSkeletonDataChunks(&cgfSaver))
{
return false;
}
return true;
}
bool AssetWriter::PrepareSkeletonDataChunks(CSaverCGF* cgfSaver)
{
const CSkinningInfo* skinningInfo = cgfSaver->GetContent()->GetSkinningInfo();
if (skinningInfo->m_arrBonesDesc.empty())
{
return false;
}
if (skinningInfo->m_arrBonesDesc.size() != skinningInfo->m_arrBoneEntities.size())
{
RCLogError("Bone description number and bone entity data number don't match.\n");
return false;
}
// Save bone entity data to chunk
DynArray<BONE_ENTITY> tempBoneEntities = skinningInfo->m_arrBoneEntities;
for (int i = 0; i < tempBoneEntities.size(); ++i)
{
tempBoneEntities[i].phys.nPhysGeom = -1;
StringHelpers::SafeCopyPadZeros(tempBoneEntities[i].prop, sizeof(tempBoneEntities[i].prop), skinningInfo->m_arrBoneEntities[i].prop);
}
const int numBones = skinningInfo->m_arrBonesDesc.size();
cgfSaver->SaveBones(s_swapEndian, &tempBoneEntities[0], numBones, numBones*sizeof(BONE_ENTITY));
// Save bone names
std::vector<char> boneNames;
static const int maxBoneNameLength = 32;
boneNames.reserve(maxBoneNameLength * numBones);
std::vector<SBoneInitPosMatrix> boneMatices(numBones);
for (int boneId = 0; boneId < numBones; ++boneId)
{
const char* boneName = skinningInfo->m_arrBonesDesc[boneId].m_arrBoneName;
size_t len = strlen(boneName);
boneNames.insert(boneNames.end(), boneName, boneName + len);
boneNames.push_back('\0');
for (int x = 0; x < 4; ++x)
{
// Reference to ColladaCompiler::CompileToCHR
// CryTek requires the bone matrix is converted from meter unit to centimeter unit
// We have intentionally convert bone transform matrix to meter unit in FbxSceneSystem::ConvertBoneUnit
// For example, a valid bone matrix would look like
// 100 0 0 | 50
// 0 100 0 | 0
// 0 0 100 | 0
// In which 50 means 50 centimeters
Matrix34 m = Matrix34::CreateScale(Vec3(100.0f, 100.0f, 100.0f)) * skinningInfo->m_arrBonesDesc[boneId].m_DefaultB2W;
Vec3 column = m.GetColumn(x);
for (int y = 0; y < 3; ++y)
{
boneMatices[boneId][x][y] = column[y];
}
}
}
boneNames.push_back('\0');
cgfSaver->SaveBoneNames(s_swapEndian, &boneNames[0], numBones, boneNames.size());
cgfSaver->SaveBoneInitialMatrices(s_swapEndian, &boneMatices[0], numBones, sizeof(SBoneInitPosMatrix)*numBones);
return true;
}
@@ -0,0 +1,36 @@
/*
* 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_TOOLS_RC_RESOURCECOMPILERPC_CGF_ASSETWRITER_H
#define CRYINCLUDE_TOOLS_RC_RESOURCECOMPILERPC_CGF_ASSETWRITER_H
#pragma once
#include "CGFContent.h"
class CSaverCGF;
class AssetWriter
: public IAssetWriter
{
public:
bool WriteCGF(CContentCGF* content) override;
bool WriteCHR(CContentCGF* content, IConvertContext* convertContext) override;
bool WriteSKIN(CContentCGF* content, IConvertContext* convertContext, bool exportMorphTargets = false) override;
protected:
bool PrepareSkeletonDataChunks(CSaverCGF* cgfSaver);
static const bool s_swapEndian = false;
};
#endif // CRYINCLUDE_TOOLS_RC_RESOURCECOMPILERPC_CGF_ASSETWRITER_H
@@ -0,0 +1,153 @@
/*
* 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 "ResourceCompilerPC_precompiled.h"
#include "CGFNodeMerger.h"
#include "CGFContent.h"
#include "StringHelpers.h"
//////////////////////////////////////////////////////////////////////////
bool CGFNodeMerger::SetupMeshSubsets(CContentCGF* pCGF, CMesh& mesh, CMaterialCGF* pMaterialCGF, string& errorMessage)
{
const DynArray<int>& usedMaterialIds = pCGF->GetUsedMaterialIDs();
unsigned int i;
if (mesh.m_subsets.empty())
{
//////////////////////////////////////////////////////////////////////////
// Setup mesh subsets.
//////////////////////////////////////////////////////////////////////////
mesh.m_subsets.clear();
for (i = 0; i < usedMaterialIds.size(); i++)
{
SMeshSubset meshSubset;
int nMatID = usedMaterialIds[i];
meshSubset.nMatID = nMatID;
meshSubset.nPhysicalizeType = PHYS_GEOM_TYPE_NONE;
mesh.m_subsets.push_back(meshSubset);
}
}
//////////////////////////////////////////////////////////////////////////
// Setup physicalization type from materials (and autofix matId if needed)
//////////////////////////////////////////////////////////////////////////
if (pMaterialCGF)
{
for (i = 0; i < mesh.m_subsets.size(); i++)
{
SMeshSubset& meshSubset = mesh.m_subsets[i];
if (pMaterialCGF->subMaterials.size() > 0)
{
int id = meshSubset.nMatID;
if (id >= (int)pMaterialCGF->subMaterials.size())
{
// Let's use 3dsMax's approach of handling material ids out of range
id %= (int)pMaterialCGF->subMaterials.size();
}
if (id >= 0 && pMaterialCGF->subMaterials[id] != NULL)
{
meshSubset.nMatID = id;
meshSubset.nPhysicalizeType = pMaterialCGF->subMaterials[id]->nPhysicalizeType;
}
else
{
errorMessage = StringHelpers::Format(
"%s: Submaterial %d is not available for subset %d (%d subsets) in %s",
__FUNCTION__, meshSubset.nMatID, i, (int)mesh.m_subsets.size(), pCGF->GetFilename());
return false;
}
}
else
{
meshSubset.nPhysicalizeType = pMaterialCGF->nPhysicalizeType;
}
}
}
return true;
}
//////////////////////////////////////////////////////////////////////////
bool CGFNodeMerger::MergeNodes(CContentCGF* pCGF, std::vector<CNodeCGF*> nodes, string& errorMessage, CMesh* pMergedMesh)
{
assert(pMergedMesh);
AABB meshBBox;
meshBBox.Reset();
for (size_t i = 0; i < nodes.size(); i++)
{
CNodeCGF* pNode = nodes[i];
assert(pNode->pMesh == 0 || pNode->pMesh->m_pPositionsF16 == 0);
int nOldVerts = pMergedMesh->GetVertexCount();
if (pMergedMesh->GetVertexCount() == 0)
{
pMergedMesh->Copy(*pNode->pMesh);
}
else
{
const char* const errText = pMergedMesh->Append(*pNode->pMesh);
if (errText)
{
errorMessage = errText;
return false;
}
// Keep color stream in sync size with vertex/normals stream.
if (pMergedMesh->m_streamSize[CMesh::COLORS][0] > 0 && pMergedMesh->m_streamSize[CMesh::COLORS][0] < pMergedMesh->GetVertexCount())
{
int nOldCount = pMergedMesh->m_streamSize[CMesh::COLORS][0];
pMergedMesh->ReallocStream(CMesh::COLORS, 0, pMergedMesh->GetVertexCount());
memset(pMergedMesh->m_pColor0 + nOldCount, 255, (pMergedMesh->GetVertexCount() - nOldCount) * sizeof(SMeshColor));
}
if (pMergedMesh->m_streamSize[CMesh::COLORS][1] > 0 && pMergedMesh->m_streamSize[CMesh::COLORS][1] < pMergedMesh->GetVertexCount())
{
int nOldCount = pMergedMesh->m_streamSize[CMesh::COLORS][1];
pMergedMesh->ReallocStream(CMesh::COLORS, 1, pMergedMesh->GetVertexCount());
memset(pMergedMesh->m_pColor1 + nOldCount, 255, (pMergedMesh->GetVertexCount() - nOldCount) * sizeof(SMeshColor));
}
}
AABB bbox = pNode->pMesh->m_bbox;
if (!pNode->bIdentityMatrix)
{
bbox.SetTransformedAABB(pNode->worldTM, bbox);
}
meshBBox.Add(bbox.min);
meshBBox.Add(bbox.max);
pMergedMesh->m_bbox = meshBBox;
if (!pNode->bIdentityMatrix)
{
// Transform merged mesh into the world space.
// Only transform newly added vertices.
for (int j = nOldVerts; j < pMergedMesh->GetVertexCount(); j++)
{
pMergedMesh->m_pPositions[j] = pNode->worldTM.TransformPoint(pMergedMesh->m_pPositions[j]);
pMergedMesh->m_pNorms[j].RotateSafelyBy(pNode->worldTM);
}
}
}
bool setupMeshSuccessful = true;
if (pCGF != NULL)
{
if (!SetupMeshSubsets(pCGF, *pMergedMesh, pCGF->GetCommonMaterial(), errorMessage))
{
return false;
}
}
pMergedMesh->RecomputeTexMappingDensity();
return setupMeshSuccessful;
}
@@ -0,0 +1,30 @@
/*
* 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_TOOLS_RC_RESOURCECOMPILERPC_CGF_CGFNODEMERGER_H
#define CRYINCLUDE_TOOLS_RC_RESOURCECOMPILERPC_CGF_CGFNODEMERGER_H
#pragma once
class CContentCGF;
class CMesh;
struct CMaterialCGF;
struct CNodeCGF;
namespace CGFNodeMerger
{
bool SetupMeshSubsets(CContentCGF* pCGF, CMesh& mesh, CMaterialCGF* pMaterialCGF, string& errorMessage);
bool MergeNodes(CContentCGF* pCGF, std::vector<CNodeCGF*> nodes, string& errorMessage, CMesh* pOutMesh);
};
#endif // CRYINCLUDE_TOOLS_RC_RESOURCECOMPILERPC_CGF_CGFNODEMERGER_H
@@ -0,0 +1,40 @@
/*
* 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_TOOLS_RC_RESOURCECOMPILERPC_CGF_CHUNKDATA_H
#define CRYINCLUDE_TOOLS_RC_RESOURCECOMPILERPC_CGF_CHUNKDATA_H
#pragma once
struct CChunkData
{
char* data;
int size;
CChunkData() { data = 0; size = 0; }
~CChunkData() { free(data); }
template <class T>
void Add(const T& object)
{
AddData(&object, sizeof(object));
}
void AddData(const void* pSrcData, int nSrcDataSize)
{
data = (char*)realloc(data, size + nSrcDataSize);
memcpy(data + size, pSrcData, nSrcDataSize);
size += nSrcDataSize;
}
};
#endif // CRYINCLUDE_TOOLS_RC_RESOURCECOMPILERPC_CGF_CHUNKDATA_H
@@ -0,0 +1,286 @@
/*
* 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 "ResourceCompilerPC_precompiled.h"
#include "DataWriter.h"
#include "CryEndian.h"
DataWriter::DataWriter()
{
m_outputBuffer = NULL;
Reset();
}
DataWriter::~DataWriter()
{
this->Reset();
}
void DataWriter::Reset()
{
if (m_outputBuffer)
{
free(m_outputBuffer);
}
m_currentBufferSize = 0;
m_outputBuffer = NULL;
m_writtenBytes = 0;
m_labelMap.clear();
m_offsetLocations.clear();
m_bClosed = false;
m_bSwapEndian = false;
}
void DataWriter::SetSwapEndian(bool bEnable)
{
m_bSwapEndian = bEnable;
}
void* DataWriter::GetDataAndTakeOwnership()
{
if (m_bClosed && m_outputBuffer)
{
void* returnData = m_outputBuffer;
m_outputBuffer = NULL;
Reset();
return returnData;
}
return NULL;
}
uint32 DataWriter::GetDataSize() const
{
return (m_bClosed && m_outputBuffer) ? m_writtenBytes : 0;
}
void DataWriter::BeginWriting()
{
ExpandBuffer(1);
AddLabel("fileStart");
}
void DataWriter::WriteUInt8(const uint8 v)
{
ExpandBuffer(sizeof(v));
uint8* out = (uint8*)(((uint8*)m_outputBuffer) + m_writtenBytes);
*out = v;
SwapEndian(*out, m_bSwapEndian);
m_writtenBytes += sizeof(v);
}
void DataWriter::WriteInt8(const int8 v)
{
ExpandBuffer(sizeof(v));
int8* out = (int8*)(((uint8*)m_outputBuffer) + m_writtenBytes);
*out = v;
SwapEndian(*out, m_bSwapEndian);
m_writtenBytes += sizeof(v);
}
void DataWriter::WriteUInt16(const uint16 v)
{
ExpandBuffer(sizeof(v));
uint16* out = (uint16*)(((uint8*)m_outputBuffer) + m_writtenBytes);
*out = v;
SwapEndian(*out, m_bSwapEndian);
m_writtenBytes += sizeof(v);
}
void DataWriter::WriteInt16(const int16 v)
{
ExpandBuffer(sizeof(v));
int16* out = (int16*)(((uint8*)m_outputBuffer) + m_writtenBytes);
*out = v;
SwapEndian(*out, m_bSwapEndian);
m_writtenBytes += sizeof(v);
}
void DataWriter::WriteUInt32(const uint32 v)
{
ExpandBuffer(sizeof(v));
uint32* out = (uint32*)(((uint8*)m_outputBuffer) + m_writtenBytes);
*out = v;
SwapEndian(*out, m_bSwapEndian);
m_writtenBytes += sizeof(v);
}
void DataWriter::WriteInt32(const int32 v)
{
ExpandBuffer(sizeof(v));
int32* out = (int32*)(((uint8*)m_outputBuffer) + m_writtenBytes);
*out = v;
SwapEndian(*out, m_bSwapEndian);
m_writtenBytes += sizeof(v);
}
void DataWriter::WriteFloat(const float v)
{
ExpandBuffer(sizeof(v));
float* out = (float*)(((uint8*)m_outputBuffer) + m_writtenBytes);
*out = v;
SwapEndian(*out, m_bSwapEndian);
m_writtenBytes += sizeof(v);
}
void DataWriter::WriteData(const void* v, const uint32 size)
{
ExpandBuffer(size);
void* out = (void*)(((uint8*)m_outputBuffer) + m_writtenBytes);
memcpy(out, v, size);
m_writtenBytes += size;
}
void DataWriter::WriteAlign(const uint32 alignBytes)
{
const uint32 a = m_writtenBytes % alignBytes;
if (a != 0)
{
m_writtenBytes += (alignBytes - a);
}
ExpandBuffer();
}
void DataWriter::AddLabel(const string& label)
{
const std::map<string, uint32>::iterator f = m_labelMap.find(label);
if (f == m_labelMap.end())
{
m_labelMap.insert(std::make_pair(label, m_writtenBytes));
}
}
void DataWriter::WriteOffsetInt32(const string& label)
{
this->WriteOffsetInt32("", label);
}
void DataWriter::WriteOffsetInt32(const string& fromLabel, const string& label)
{
SOffsetLocation loc;
loc.b16Bit = false;
loc.offset = m_writtenBytes;
loc.labelName = label;
loc.fromLabelName = fromLabel;
m_offsetLocations.push_back(loc);
WriteInt32(0); // Make space to write the offset into later
}
void DataWriter::WriteOffsetInt16(const string& label)
{
this->WriteOffsetInt16("", label);
}
void DataWriter::WriteOffsetInt16(const string& fromLabel, const string& label)
{
SOffsetLocation loc;
loc.b16Bit = true;
loc.offset = m_writtenBytes;
loc.labelName = label;
loc.fromLabelName = fromLabel;
m_offsetLocations.push_back(loc);
WriteInt16(0); // Make space to write the offset into later
}
bool DataWriter::EndWriting()
{
m_missingLabels.clear();
for (int iOffset = 0; iOffset < m_offsetLocations.size(); iOffset++)
{
const SOffsetLocation* loc = &m_offsetLocations[iOffset];
const std::map<string, uint32>::iterator itLabel = m_labelMap.find(loc->labelName);
if (itLabel != m_labelMap.end())
{
const uint32 labelLoc = (*itLabel).second;
uint32 fromLoc = 0;
if (loc->fromLabelName.length() > 0)
{
const std::map<string, uint32>::iterator itFromLabel = m_labelMap.find(loc->fromLabelName);
if (itFromLabel != m_labelMap.end())
{
fromLoc = (*itFromLabel).second;
}
else
{
m_missingLabels.push_back(loc->fromLabelName);
}
}
if (loc->b16Bit)
{
const int16 offset = (int16)(labelLoc - fromLoc);
int16* out = (int16*)(((uint8*)m_outputBuffer) + loc->offset);
*out = offset;
SwapEndian(*out, m_bSwapEndian);
}
else
{
const int32 offset = labelLoc - fromLoc;
int32* out = (int32*)(((uint8*)m_outputBuffer) + loc->offset);
*out = offset;
SwapEndian(*out, m_bSwapEndian);
}
}
else
{
m_missingLabels.push_back(loc->labelName);
}
}
m_bClosed = true;
return m_missingLabels.empty();
}
uint32 DataWriter::CalculateSize(const string& fromLabel, const string& toLabel)
{
const std::map<string, uint32>::iterator itFromLabel = m_labelMap.find(fromLabel);
const std::map<string, uint32>::iterator itToLabel = m_labelMap.find(toLabel);
uint32 size = 0;
if (itFromLabel != m_labelMap.end() && itToLabel != m_labelMap.end())
{
const uint32 fromLoc = (*itFromLabel).second;
const uint32 toLoc = (*itToLabel).second;
if (fromLoc < toLoc)
{
size = toLoc - fromLoc;
}
else
{
size = 0;
}
}
return size;
}
#define BUFFERINCREASESIZE (1024 * 1024)
void DataWriter::ExpandBuffer(const uint32 addBytes)
{
if (m_writtenBytes + addBytes > m_currentBufferSize)
{
const uint32 newBufferSize = m_currentBufferSize + BUFFERINCREASESIZE;
if (m_outputBuffer)
{
m_outputBuffer = realloc(m_outputBuffer, newBufferSize);
}
else
{
m_outputBuffer = malloc(newBufferSize);
}
m_currentBufferSize = newBufferSize;
}
}
@@ -0,0 +1,79 @@
/*
* 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_TOOLS_RC_RESOURCECOMPILERPC_CGF_DATAWRITER_H
#define CRYINCLUDE_TOOLS_RC_RESOURCECOMPILERPC_CGF_DATAWRITER_H
#pragma once
class DataWriter
{
public:
DataWriter();
virtual ~DataWriter();
void Reset();
void SetSwapEndian(bool bEnable);
uint32 GetDataSize() const;
void* GetDataAndTakeOwnership();
void BeginWriting();
void WriteUInt8(const uint8 v);
void WriteInt8(const int8 v);
void WriteUInt16(const uint16 v);
void WriteInt16(const int16 v);
void WriteUInt32(const uint32 v);
void WriteInt32(const int32 v);
void WriteFloat(const float v);
void WriteData(const void* v, const uint32 size);
void WriteAlign(const uint32 alignBytes);
void AddLabel(const string& label);
void WriteOffsetInt32(const string& label);
void WriteOffsetInt32(const string& fromLabel, const string& label);
void WriteOffsetInt16(const string& label);
void WriteOffsetInt16(const string& fromLabel, const string& label);
bool EndWriting();
uint32 CalculateSize(const string& fromLabel, const string& toLabel);
private:
void ExpandBuffer(const uint32 addBytes = 0);
uint32 m_currentBufferSize;
void* m_outputBuffer;
uint32 m_writtenBytes;
bool m_bClosed;
bool m_bSwapEndian;
std::map<string, uint32> m_labelMap;
struct SOffsetLocation
{
bool b16Bit;
uint32 offset;
string labelName;
string fromLabelName;
};
std::vector< SOffsetLocation > m_offsetLocations;
std::vector<string> m_missingLabels;
};
#endif // CRYINCLUDE_TOOLS_RC_RESOURCECOMPILERPC_CGF_DATAWRITER_H