Merged from main
This commit is contained in:
@@ -1,525 +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 : shadow volume AABB functionality for overlap testings
|
||||
|
||||
|
||||
#ifndef CRYINCLUDE_CRYCOMMON_AABBSV_H
|
||||
#define CRYINCLUDE_CRYCOMMON_AABBSV_H
|
||||
#pragma once
|
||||
|
||||
#include "Cry_Geo.h"
|
||||
|
||||
struct Shadowvolume
|
||||
{
|
||||
uint32 sideamount;
|
||||
uint32 nplanes;
|
||||
|
||||
Plane oplanes[10];
|
||||
};
|
||||
|
||||
namespace NAABB_SV
|
||||
{
|
||||
//***************************************************************************************
|
||||
//***************************************************************************************
|
||||
//*** Calculate a ShadowVolume using an AABB and a point-light ***
|
||||
//***************************************************************************************
|
||||
//*** The planes of the AABB facing away from the point-light are the far-planes ***
|
||||
//*** of the ShadowVolume. There can be 3-6 far-planes. ***
|
||||
//***************************************************************************************
|
||||
void AABB_ReceiverShadowVolume(const Vec3& PointLight, const AABB& Occluder, Shadowvolume& sv);
|
||||
|
||||
//***************************************************************************************
|
||||
//***************************************************************************************
|
||||
//*** Calculate a ShadowVolume using an AABB and a point-light ***
|
||||
//***************************************************************************************
|
||||
//*** The planes of the AABB facing the point-light are the near-planes of the ***
|
||||
//*** the ShadowVolume. There can be 1-3 near-planes. ***
|
||||
//*** The far-plane is defined by lightrange. ***
|
||||
//***************************************************************************************
|
||||
void AABB_ShadowVolume(const Vec3& PointLight, const AABB& Occluder, Shadowvolume& sv, f32 lightrange);
|
||||
|
||||
//***************************************************************************************
|
||||
//*** this is the "fast" version to check if an AABB is overlapping a shadowvolume ***
|
||||
//***************************************************************************************
|
||||
bool Is_AABB_In_ShadowVolume(const Shadowvolume& sv, const AABB& Receiver);
|
||||
|
||||
//***************************************************************************************
|
||||
//*** this is the "hierarchical" check ***
|
||||
//***************************************************************************************
|
||||
char Is_AABB_In_ShadowVolume_hierarchical(const Shadowvolume& sv, const AABB& Receiver);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
inline void NAABB_SV::AABB_ReceiverShadowVolume(const Vec3& PointLight, const AABB& Occluder, Shadowvolume& sv)
|
||||
{
|
||||
sv.sideamount = 0;
|
||||
sv.nplanes = 0;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//-- check if PointLight is in front of any occluder plane or inside occluder --
|
||||
//------------------------------------------------------------------------------
|
||||
uint32 front = 0;
|
||||
if (PointLight.x < Occluder.min.x)
|
||||
{
|
||||
front |= 0x01;
|
||||
}
|
||||
if (PointLight.x > Occluder.max.x)
|
||||
{
|
||||
front |= 0x02;
|
||||
}
|
||||
if (PointLight.y < Occluder.min.y)
|
||||
{
|
||||
front |= 0x04;
|
||||
}
|
||||
if (PointLight.y > Occluder.max.y)
|
||||
{
|
||||
front |= 0x08;
|
||||
}
|
||||
if (PointLight.z < Occluder.min.z)
|
||||
{
|
||||
front |= 0x10;
|
||||
}
|
||||
if (PointLight.z > Occluder.max.z)
|
||||
{
|
||||
front |= 0x20;
|
||||
}
|
||||
|
||||
sv.sideamount = BoxSides[(front << 3) + 7];
|
||||
|
||||
uint32 back = front ^ 0x3f;
|
||||
if (back & 0x01)
|
||||
{
|
||||
sv.oplanes[sv.nplanes].SetPlane(Vec3(-1, +0, +0), Occluder.min);
|
||||
sv.nplanes++;
|
||||
}
|
||||
if (back & 0x02)
|
||||
{
|
||||
sv.oplanes[sv.nplanes].SetPlane(Vec3(+1, +0, +0), Occluder.max);
|
||||
sv.nplanes++;
|
||||
}
|
||||
if (back & 0x04)
|
||||
{
|
||||
sv.oplanes[sv.nplanes].SetPlane(Vec3(+0, -1, +0), Occluder.min);
|
||||
sv.nplanes++;
|
||||
}
|
||||
if (back & 0x08)
|
||||
{
|
||||
sv.oplanes[sv.nplanes].SetPlane(Vec3(+0, +1, +0), Occluder.max);
|
||||
sv.nplanes++;
|
||||
}
|
||||
if (back & 0x10)
|
||||
{
|
||||
sv.oplanes[sv.nplanes].SetPlane(Vec3(+0, +0, -1), Occluder.min);
|
||||
sv.nplanes++;
|
||||
}
|
||||
if (back & 0x20)
|
||||
{
|
||||
sv.oplanes[sv.nplanes].SetPlane(Vec3(+0, +0, +1), Occluder.max);
|
||||
sv.nplanes++;
|
||||
}
|
||||
|
||||
if (front == 0)
|
||||
{
|
||||
return; //light is inside occluder
|
||||
}
|
||||
//all 8 vertices of a AABB
|
||||
Vec3 o[8] =
|
||||
{
|
||||
Vec3(Occluder.min.x, Occluder.min.y, Occluder.min.z),
|
||||
Vec3(Occluder.max.x, Occluder.min.y, Occluder.min.z),
|
||||
Vec3(Occluder.min.x, Occluder.max.y, Occluder.min.z),
|
||||
Vec3(Occluder.max.x, Occluder.max.y, Occluder.min.z),
|
||||
Vec3(Occluder.min.x, Occluder.min.y, Occluder.max.z),
|
||||
Vec3(Occluder.max.x, Occluder.min.y, Occluder.max.z),
|
||||
Vec3(Occluder.min.x, Occluder.max.y, Occluder.max.z),
|
||||
Vec3(Occluder.max.x, Occluder.max.y, Occluder.max.z)
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
//--- find the silhouette-vertices of the occluder-AABB ---
|
||||
//---------------------------------------------------------------------
|
||||
uint32 p0 = BoxSides[(front << 3) + 0];
|
||||
uint32 p1 = BoxSides[(front << 3) + 1];
|
||||
uint32 p2 = BoxSides[(front << 3) + 2];
|
||||
uint32 p3 = BoxSides[(front << 3) + 3];
|
||||
uint32 p4 = BoxSides[(front << 3) + 4];
|
||||
uint32 p5 = BoxSides[(front << 3) + 5];
|
||||
|
||||
float a;
|
||||
if (sv.sideamount == 4)
|
||||
{
|
||||
//sv.oplanes[sv.nplanes+0] = Plane::CreatePlane( o[p0],o[p1], PointLight );
|
||||
//sv.oplanes[sv.nplanes+1] = Plane::CreatePlane( o[p1],o[p2], PointLight );
|
||||
//sv.oplanes[sv.nplanes+2] = Plane::CreatePlane( o[p2],o[p3], PointLight );
|
||||
//sv.oplanes[sv.nplanes+3] = Plane::CreatePlane( o[p3],o[p0], PointLight );
|
||||
sv.sideamount = 0;
|
||||
a = (o[p1] - o[p0]) | (o[p0] - PointLight);
|
||||
if (a)
|
||||
{
|
||||
sv.oplanes[sv.nplanes + sv.sideamount] = Plane::CreatePlane(o[p0], o[p1], PointLight);
|
||||
sv.sideamount++;
|
||||
}
|
||||
a = (o[p2] - o[p1]) | (o[p1] - PointLight);
|
||||
if (a)
|
||||
{
|
||||
sv.oplanes[sv.nplanes + sv.sideamount] = Plane::CreatePlane(o[p1], o[p2], PointLight);
|
||||
sv.sideamount++;
|
||||
}
|
||||
a = (o[p3] - o[p2]) | (o[p2] - PointLight);
|
||||
if (a)
|
||||
{
|
||||
sv.oplanes[sv.nplanes + sv.sideamount] = Plane::CreatePlane(o[p2], o[p3], PointLight);
|
||||
sv.sideamount++;
|
||||
}
|
||||
a = (o[p0] - o[p3]) | (o[p3] - PointLight);
|
||||
if (a)
|
||||
{
|
||||
sv.oplanes[sv.nplanes + sv.sideamount] = Plane::CreatePlane(o[p3], o[p0], PointLight);
|
||||
sv.sideamount++;
|
||||
}
|
||||
}
|
||||
|
||||
if (sv.sideamount == 6)
|
||||
{
|
||||
//sv.oplanes[sv.nplanes+0] = Plane::CreatePlane( o[p0],o[p1], PointLight );
|
||||
//sv.oplanes[sv.nplanes+1] = Plane::CreatePlane( o[p1],o[p2], PointLight );
|
||||
//sv.oplanes[sv.nplanes+2] = Plane::CreatePlane( o[p2],o[p3], PointLight );
|
||||
//sv.oplanes[sv.nplanes+3] = Plane::CreatePlane( o[p3],o[p4], PointLight );
|
||||
//sv.oplanes[sv.nplanes+4] = Plane::CreatePlane( o[p4],o[p5], PointLight );
|
||||
//sv.oplanes[sv.nplanes+5] = Plane::CreatePlane( o[p5],o[p0], PointLight );
|
||||
|
||||
sv.sideamount = 0;
|
||||
a = (o[p1] - o[p0]) | (o[p0] - PointLight);
|
||||
assert(sv.nplanes + sv.sideamount < 10);
|
||||
PREFAST_ASSUME(sv.nplanes + sv.sideamount < 10);
|
||||
if (a)
|
||||
{
|
||||
sv.oplanes[sv.nplanes + sv.sideamount] = Plane::CreatePlane(o[p0], o[p1], PointLight);
|
||||
sv.sideamount++;
|
||||
}
|
||||
a = (o[p2] - o[p1]) | (o[p1] - PointLight);
|
||||
assert(sv.nplanes + sv.sideamount < 10);
|
||||
PREFAST_ASSUME(sv.nplanes + sv.sideamount < 10);
|
||||
if (a)
|
||||
{
|
||||
sv.oplanes[sv.nplanes + sv.sideamount] = Plane::CreatePlane(o[p1], o[p2], PointLight);
|
||||
sv.sideamount++;
|
||||
}
|
||||
a = (o[p3] - o[p2]) | (o[p2] - PointLight);
|
||||
assert(sv.nplanes + sv.sideamount < 10);
|
||||
PREFAST_ASSUME(sv.nplanes + sv.sideamount < 10);
|
||||
if (a)
|
||||
{
|
||||
sv.oplanes[sv.nplanes + sv.sideamount] = Plane::CreatePlane(o[p2], o[p3], PointLight);
|
||||
sv.sideamount++;
|
||||
}
|
||||
a = (o[p4] - o[p3]) | (o[p3] - PointLight);
|
||||
assert(sv.nplanes + sv.sideamount < 10);
|
||||
PREFAST_ASSUME(sv.nplanes + sv.sideamount < 10);
|
||||
if (a)
|
||||
{
|
||||
sv.oplanes[sv.nplanes + sv.sideamount] = Plane::CreatePlane(o[p3], o[p4], PointLight);
|
||||
sv.sideamount++;
|
||||
}
|
||||
a = (o[p5] - o[p4]) | (o[p4] - PointLight);
|
||||
assert(sv.nplanes + sv.sideamount < 10);
|
||||
PREFAST_ASSUME(sv.nplanes + sv.sideamount < 10);
|
||||
if (a)
|
||||
{
|
||||
sv.oplanes[sv.nplanes + sv.sideamount] = Plane::CreatePlane(o[p4], o[p5], PointLight);
|
||||
sv.sideamount++;
|
||||
}
|
||||
a = (o[p0] - o[p5]) | (o[p5] - PointLight);
|
||||
assert(sv.nplanes + sv.sideamount < 10);
|
||||
PREFAST_ASSUME(sv.nplanes + sv.sideamount < 10);
|
||||
if (a)
|
||||
{
|
||||
sv.oplanes[sv.nplanes + sv.sideamount] = Plane::CreatePlane(o[p5], o[p0], PointLight);
|
||||
sv.sideamount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline void NAABB_SV::AABB_ShadowVolume(const Vec3& PointLight, const AABB& Occluder, Shadowvolume& sv, f32 lightrange)
|
||||
{
|
||||
sv.sideamount = 0;
|
||||
sv.nplanes = 0;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//-- check if PointLight is in front of any occluder plane or inside occluder --
|
||||
//------------------------------------------------------------------------------
|
||||
uint32 front = 0;
|
||||
if (PointLight.x < Occluder.min.x)
|
||||
{
|
||||
front |= 0x01;
|
||||
}
|
||||
if (PointLight.x > Occluder.max.x)
|
||||
{
|
||||
front |= 0x02;
|
||||
}
|
||||
if (PointLight.y < Occluder.min.y)
|
||||
{
|
||||
front |= 0x04;
|
||||
}
|
||||
if (PointLight.y > Occluder.max.y)
|
||||
{
|
||||
front |= 0x08;
|
||||
}
|
||||
if (PointLight.z < Occluder.min.z)
|
||||
{
|
||||
front |= 0x10;
|
||||
}
|
||||
if (PointLight.z > Occluder.max.z)
|
||||
{
|
||||
front |= 0x20;
|
||||
}
|
||||
if (front == 0)
|
||||
{
|
||||
return; //light is inside occluder
|
||||
}
|
||||
sv.sideamount = BoxSides[(front << 3) + 7];
|
||||
|
||||
if (front & 0x01)
|
||||
{
|
||||
sv.oplanes[sv.nplanes].SetPlane(Vec3(-1, +0, +0), Occluder.min);
|
||||
sv.nplanes++;
|
||||
}
|
||||
if (front & 0x02)
|
||||
{
|
||||
sv.oplanes[sv.nplanes].SetPlane(Vec3(+1, +0, +0), Occluder.max);
|
||||
sv.nplanes++;
|
||||
}
|
||||
if (front & 0x04)
|
||||
{
|
||||
sv.oplanes[sv.nplanes].SetPlane(Vec3(+0, -1, +0), Occluder.min);
|
||||
sv.nplanes++;
|
||||
}
|
||||
if (front & 0x08)
|
||||
{
|
||||
sv.oplanes[sv.nplanes].SetPlane(Vec3(+0, +1, +0), Occluder.max);
|
||||
sv.nplanes++;
|
||||
}
|
||||
if (front & 0x10)
|
||||
{
|
||||
sv.oplanes[sv.nplanes].SetPlane(Vec3(+0, +0, -1), Occluder.min);
|
||||
sv.nplanes++;
|
||||
}
|
||||
if (front & 0x20)
|
||||
{
|
||||
sv.oplanes[sv.nplanes].SetPlane(Vec3(+0, +0, +1), Occluder.max);
|
||||
sv.nplanes++;
|
||||
}
|
||||
|
||||
//all 8 vertices of a AABB
|
||||
Vec3 o[8] =
|
||||
{
|
||||
Vec3(Occluder.min.x, Occluder.min.y, Occluder.min.z),
|
||||
Vec3(Occluder.max.x, Occluder.min.y, Occluder.min.z),
|
||||
Vec3(Occluder.min.x, Occluder.max.y, Occluder.min.z),
|
||||
Vec3(Occluder.max.x, Occluder.max.y, Occluder.min.z),
|
||||
Vec3(Occluder.min.x, Occluder.min.y, Occluder.max.z),
|
||||
Vec3(Occluder.max.x, Occluder.min.y, Occluder.max.z),
|
||||
Vec3(Occluder.min.x, Occluder.max.y, Occluder.max.z),
|
||||
Vec3(Occluder.max.x, Occluder.max.y, Occluder.max.z)
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
//--- find the silhouette-vertices of the occluder-AABB ---
|
||||
//---------------------------------------------------------------------
|
||||
uint32 p0 = BoxSides[(front << 3) + 0];
|
||||
uint32 p1 = BoxSides[(front << 3) + 1];
|
||||
uint32 p2 = BoxSides[(front << 3) + 2];
|
||||
uint32 p3 = BoxSides[(front << 3) + 3];
|
||||
uint32 p4 = BoxSides[(front << 3) + 4];
|
||||
uint32 p5 = BoxSides[(front << 3) + 5];
|
||||
|
||||
//the new center-position in world-space
|
||||
Vec3 MiddleOfOccluder = (Occluder.max + Occluder.min) * 0.5f;
|
||||
sv.oplanes[sv.nplanes] = Plane::CreatePlane((MiddleOfOccluder - PointLight).GetNormalized(), (MiddleOfOccluder - PointLight).GetNormalized() * lightrange + PointLight);
|
||||
sv.nplanes++;
|
||||
|
||||
float a;
|
||||
if (sv.sideamount == 4)
|
||||
{
|
||||
sv.sideamount = 0;
|
||||
a = (o[p1] - o[p0]) | (o[p0] - PointLight);
|
||||
if (a)
|
||||
{
|
||||
sv.oplanes[sv.nplanes + sv.sideamount] = Plane::CreatePlane(o[p0], o[p1], PointLight);
|
||||
sv.sideamount++;
|
||||
}
|
||||
a = (o[p2] - o[p1]) | (o[p1] - PointLight);
|
||||
if (a)
|
||||
{
|
||||
sv.oplanes[sv.nplanes + sv.sideamount] = Plane::CreatePlane(o[p1], o[p2], PointLight);
|
||||
sv.sideamount++;
|
||||
}
|
||||
a = (o[p3] - o[p2]) | (o[p2] - PointLight);
|
||||
if (a)
|
||||
{
|
||||
sv.oplanes[sv.nplanes + sv.sideamount] = Plane::CreatePlane(o[p2], o[p3], PointLight);
|
||||
sv.sideamount++;
|
||||
}
|
||||
a = (o[p0] - o[p3]) | (o[p3] - PointLight);
|
||||
if (a)
|
||||
{
|
||||
sv.oplanes[sv.nplanes + sv.sideamount] = Plane::CreatePlane(o[p3], o[p0], PointLight);
|
||||
sv.sideamount++;
|
||||
}
|
||||
}
|
||||
|
||||
if (sv.sideamount == 6)
|
||||
{
|
||||
sv.sideamount = 0;
|
||||
a = (o[p1] - o[p0]) | (o[p0] - PointLight);
|
||||
if (a)
|
||||
{
|
||||
sv.oplanes[sv.nplanes + sv.sideamount] = Plane::CreatePlane(o[p0], o[p1], PointLight);
|
||||
sv.sideamount++;
|
||||
}
|
||||
a = (o[p2] - o[p1]) | (o[p1] - PointLight);
|
||||
if (a)
|
||||
{
|
||||
sv.oplanes[sv.nplanes + sv.sideamount] = Plane::CreatePlane(o[p1], o[p2], PointLight);
|
||||
sv.sideamount++;
|
||||
}
|
||||
a = (o[p3] - o[p2]) | (o[p2] - PointLight);
|
||||
if (a)
|
||||
{
|
||||
sv.oplanes[sv.nplanes + sv.sideamount] = Plane::CreatePlane(o[p2], o[p3], PointLight);
|
||||
sv.sideamount++;
|
||||
}
|
||||
a = (o[p4] - o[p3]) | (o[p3] - PointLight);
|
||||
if (a)
|
||||
{
|
||||
sv.oplanes[sv.nplanes + sv.sideamount] = Plane::CreatePlane(o[p3], o[p4], PointLight);
|
||||
sv.sideamount++;
|
||||
}
|
||||
a = (o[p5] - o[p4]) | (o[p4] - PointLight);
|
||||
if (a)
|
||||
{
|
||||
sv.oplanes[sv.nplanes + sv.sideamount] = Plane::CreatePlane(o[p4], o[p5], PointLight);
|
||||
sv.sideamount++;
|
||||
}
|
||||
a = (o[p0] - o[p5]) | (o[p5] - PointLight);
|
||||
if (a)
|
||||
{
|
||||
sv.oplanes[sv.nplanes + sv.sideamount] = Plane::CreatePlane(o[p5], o[p0], PointLight);
|
||||
sv.sideamount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline bool NAABB_SV::Is_AABB_In_ShadowVolume(const Shadowvolume& sv, const AABB& Receiver)
|
||||
{
|
||||
uint32 pa = sv.sideamount + sv.nplanes;
|
||||
|
||||
f32 d;
|
||||
const Vec3* pAABB = &Receiver.min;
|
||||
|
||||
union f32_u
|
||||
{
|
||||
float floatVal;
|
||||
uint32 uintVal;
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//---- check if receiver-AABB is in front of any of these planes ------
|
||||
//------------------------------------------------------------------------------
|
||||
for (uint32 x = 0; x < pa; x++)
|
||||
{
|
||||
d = sv.oplanes[x].d;
|
||||
|
||||
//avoid breaking strict aliasing rules
|
||||
f32_u ux;
|
||||
ux.floatVal = sv.oplanes[x].n.x;
|
||||
f32_u uy;
|
||||
uy.floatVal = sv.oplanes[x].n.y;
|
||||
f32_u uz;
|
||||
uz.floatVal = sv.oplanes[x].n.z;
|
||||
const uint32 bitX = ux.uintVal >> 31;
|
||||
const uint32 bitY = uy.uintVal >> 31;
|
||||
const uint32 bitZ = uz.uintVal >> 31;
|
||||
|
||||
d += sv.oplanes[x].n.x * pAABB[bitX].x;
|
||||
d += sv.oplanes[x].n.y * pAABB[bitY].y;
|
||||
d += sv.oplanes[x].n.z * pAABB[bitZ].z;
|
||||
if (d > 0)
|
||||
{
|
||||
return CULL_EXCLUSION;
|
||||
}
|
||||
}
|
||||
return CULL_OVERLAP;
|
||||
}
|
||||
|
||||
inline char NAABB_SV::Is_AABB_In_ShadowVolume_hierarchical(const Shadowvolume& sv, const AABB& Receiver)
|
||||
{
|
||||
uint32 pa = sv.sideamount + sv.nplanes;
|
||||
const Vec3* pAABB = &Receiver.min;
|
||||
|
||||
f32 dot1, dot2;
|
||||
uint32 notOverlap = 0x80000000; // will be reset to 0 if there's at least one overlapping
|
||||
|
||||
union f32_u
|
||||
{
|
||||
float floatVal;
|
||||
uint32 uintVal;
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//---- check if receiver-AABB is in front of any of these planes ------
|
||||
//------------------------------------------------------------------------------
|
||||
for (uint32 x = 0; x < pa; x++)
|
||||
{
|
||||
dot1 = dot2 = sv.oplanes[x].d;
|
||||
|
||||
//avoid breaking strict aliasing rules
|
||||
f32_u ux;
|
||||
ux.floatVal = sv.oplanes[x].n.x;
|
||||
f32_u uy;
|
||||
uy.floatVal = sv.oplanes[x].n.y;
|
||||
f32_u uz;
|
||||
uz.floatVal = sv.oplanes[x].n.z;
|
||||
const uint32 bitX = ux.uintVal >> 31;
|
||||
const uint32 bitY = uy.uintVal >> 31;
|
||||
const uint32 bitZ = uz.uintVal >> 31;
|
||||
|
||||
dot1 += sv.oplanes[x].n.x * pAABB[0 + bitX].x;
|
||||
dot2 += sv.oplanes[x].n.x * pAABB[1 - bitX].x;
|
||||
dot1 += sv.oplanes[x].n.y * pAABB[0 + bitY].y;
|
||||
dot2 += sv.oplanes[x].n.y * pAABB[1 - bitY].y;
|
||||
dot1 += sv.oplanes[x].n.z * pAABB[0 + bitZ].z;
|
||||
dot2 += sv.oplanes[x].n.z * pAABB[1 - bitZ].z;
|
||||
PREFAST_SUPPRESS_WARNING(6001) f32_u d;
|
||||
d.floatVal = dot1;
|
||||
if (!(d.uintVal & 0x80000000))
|
||||
{
|
||||
return CULL_EXCLUSION;
|
||||
}
|
||||
PREFAST_SUPPRESS_WARNING(6001) f32_u d2;
|
||||
d2.floatVal = dot2;
|
||||
notOverlap &= d2.uintVal;
|
||||
}
|
||||
if (notOverlap)
|
||||
{
|
||||
return CULL_INCLUSION;
|
||||
}
|
||||
return CULL_OVERLAP;
|
||||
}
|
||||
|
||||
#endif // CRYINCLUDE_CRYCOMMON_AABBSV_H
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
#ifndef CRYINCLUDE_CRYCOMMON_ALGORITHM_H
|
||||
#define CRYINCLUDE_CRYCOMMON_ALGORITHM_H
|
||||
#pragma once
|
||||
//short hand for using stl algorithms. same syntax (from users perspective) of c++17 range library. Only the shorthand algorithms from range library(N4128) though.
|
||||
//Not all algorithms are covered. Add any as you need them. It would be a fair amount of work to add them all, so I'm just adding them as needed.
|
||||
//Note Android doesn't have non member cbegin and cend yet.
|
||||
|
||||
#include <algorithm>
|
||||
#include <numeric>
|
||||
#include <iterator>
|
||||
|
||||
namespace std17
|
||||
{
|
||||
template<typename Container, typename Callable>
|
||||
void for_each(const Container& con, Callable callable)
|
||||
{
|
||||
std::for_each(begin(con), end(con), callable);
|
||||
}
|
||||
|
||||
template<typename Container, typename UnaryPredicate>
|
||||
bool any_of(const Container& con, UnaryPredicate pred)
|
||||
{
|
||||
return std::any_of(begin(con), end(con), pred);
|
||||
}
|
||||
|
||||
template<typename Container, typename UnaryPredicate>
|
||||
bool all_of(const Container& con, UnaryPredicate pred)
|
||||
{
|
||||
return std::all_of(begin(con), end(con), pred);
|
||||
}
|
||||
|
||||
template<typename Container, typename UnaryPredicate>
|
||||
bool none_of(const Container& con, UnaryPredicate pred)
|
||||
{
|
||||
return std::none_of(begin(con), end(con), pred);
|
||||
}
|
||||
|
||||
template<typename Container, typename UnaryPredicate>
|
||||
typename Container::iterator find_if(Container& con, UnaryPredicate pred)
|
||||
{
|
||||
return std::find_if(begin(con), end(con), pred);
|
||||
}
|
||||
|
||||
template <typename Container, typename T>
|
||||
T accumulate(const Container& con, T init)
|
||||
{
|
||||
return std::accumulate(begin(con), end(con), init);
|
||||
}
|
||||
|
||||
template <typename Container, typename T, class BinaryOperation>
|
||||
T accumulate(const Container& con, T init, BinaryOperation binary_op)
|
||||
{
|
||||
return std::accumulate(begin(con), end(con), init, binary_op);
|
||||
}
|
||||
|
||||
template <typename Container, typename UnaryPredicate>
|
||||
auto count_if(const Container&con, UnaryPredicate pred)->decltype(std::count_if(begin(con), end(con), pred))
|
||||
{
|
||||
return std::count_if(begin(con), end(con), pred);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // CRYINCLUDE_CRYCOMMON_ALGORITHM_H
|
||||
@@ -1,75 +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_ALLOCATOR_H
|
||||
#define CRYINCLUDE_CRYCOMMON_ALLOCATOR_H
|
||||
#pragma once
|
||||
|
||||
#include "CryMemoryAllocator.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// Allocator default implementation
|
||||
|
||||
struct StdAllocator
|
||||
{
|
||||
// Class-specific alloc/free/size functions. Use aligned versions only when necessary.
|
||||
template<class T>
|
||||
static void* Allocate(T*& p)
|
||||
{
|
||||
return p = NeedAlign<T>() ?
|
||||
(T*)CryModuleMemalign(sizeof(T), alignof(T)) :
|
||||
(T*)CryModuleMalloc(sizeof(T));
|
||||
}
|
||||
|
||||
template<class T>
|
||||
static void Deallocate(T* p)
|
||||
{
|
||||
if (NeedAlign<T>())
|
||||
{
|
||||
CryModuleMemalignFree(p);
|
||||
}
|
||||
else
|
||||
{
|
||||
CryModuleFree(p);
|
||||
}
|
||||
}
|
||||
|
||||
template<class T>
|
||||
static size_t GetMemSize(const T* p)
|
||||
{
|
||||
return NeedAlign<T>() ?
|
||||
sizeof(T) + alignof(T) :
|
||||
sizeof(T);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void GetMemoryUsage(ICrySizer* pSizer) const { /*nothing*/}
|
||||
protected:
|
||||
|
||||
template<class T>
|
||||
static bool NeedAlign()
|
||||
{ PREFAST_SUPPRESS_WARNING(6326); return alignof(T) > _ALIGNMENT; }
|
||||
};
|
||||
|
||||
// Handy delete template function, for any allocator.
|
||||
template<class TAlloc, class T>
|
||||
void Delete(TAlloc& alloc, T* ptr)
|
||||
{
|
||||
if (ptr)
|
||||
{
|
||||
ptr->~T();
|
||||
alloc.Deallocate(ptr);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // CRYINCLUDE_CRYCOMMON_ALLOCATOR_H
|
||||
@@ -1,197 +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.
|
||||
*
|
||||
*/
|
||||
|
||||
// Description : Contains portable definition of structs and enums to match
|
||||
// those in DXGIFormat.h in the DirectX SDK
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AzCore/PlatformDef.h>
|
||||
|
||||
#if defined(AZ_PLATFORM_WINDOWS) && !defined(OPENGL)
|
||||
#include <dxgiformat.h>
|
||||
// For non-windows platforms need to define the formats so that the ImageExtension
|
||||
// class used by the editor can have access to these
|
||||
#elif AZ_TRAIT_OS_PLATFORM_APPLE || defined(OPENGL) || defined(AZ_PLATFORM_LINUX) || defined(AZ_PLATFORM_ANDROID)
|
||||
|
||||
#define DXGI_FORMAT_DEFINED 1
|
||||
|
||||
typedef enum DXGI_FORMAT
|
||||
{
|
||||
DXGI_FORMAT_UNKNOWN = 0,
|
||||
DXGI_FORMAT_R32G32B32A32_TYPELESS = 1,
|
||||
DXGI_FORMAT_R32G32B32A32_FLOAT = 2,
|
||||
DXGI_FORMAT_R32G32B32A32_UINT = 3,
|
||||
DXGI_FORMAT_R32G32B32A32_SINT = 4,
|
||||
DXGI_FORMAT_R32G32B32_TYPELESS = 5,
|
||||
DXGI_FORMAT_R32G32B32_FLOAT = 6,
|
||||
DXGI_FORMAT_R32G32B32_UINT = 7,
|
||||
DXGI_FORMAT_R32G32B32_SINT = 8,
|
||||
DXGI_FORMAT_R16G16B16A16_TYPELESS = 9,
|
||||
DXGI_FORMAT_R16G16B16A16_FLOAT = 10,
|
||||
DXGI_FORMAT_R16G16B16A16_UNORM = 11,
|
||||
DXGI_FORMAT_R16G16B16A16_UINT = 12,
|
||||
DXGI_FORMAT_R16G16B16A16_SNORM = 13,
|
||||
DXGI_FORMAT_R16G16B16A16_SINT = 14,
|
||||
DXGI_FORMAT_R32G32_TYPELESS = 15,
|
||||
DXGI_FORMAT_R32G32_FLOAT = 16,
|
||||
DXGI_FORMAT_R32G32_UINT = 17,
|
||||
DXGI_FORMAT_R32G32_SINT = 18,
|
||||
DXGI_FORMAT_R32G8X24_TYPELESS = 19,
|
||||
DXGI_FORMAT_D32_FLOAT_S8X24_UINT = 20,
|
||||
DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS = 21,
|
||||
DXGI_FORMAT_X32_TYPELESS_G8X24_UINT = 22,
|
||||
DXGI_FORMAT_R10G10B10A2_TYPELESS = 23,
|
||||
DXGI_FORMAT_R10G10B10A2_UNORM = 24,
|
||||
DXGI_FORMAT_R10G10B10A2_UINT = 25,
|
||||
DXGI_FORMAT_R11G11B10_FLOAT = 26,
|
||||
DXGI_FORMAT_R8G8B8A8_TYPELESS = 27,
|
||||
DXGI_FORMAT_R8G8B8A8_UNORM = 28,
|
||||
DXGI_FORMAT_R8G8B8A8_UNORM_SRGB = 29,
|
||||
DXGI_FORMAT_R8G8B8A8_UINT = 30,
|
||||
DXGI_FORMAT_R8G8B8A8_SNORM = 31,
|
||||
DXGI_FORMAT_R8G8B8A8_SINT = 32,
|
||||
DXGI_FORMAT_R16G16_TYPELESS = 33,
|
||||
DXGI_FORMAT_R16G16_FLOAT = 34,
|
||||
DXGI_FORMAT_R16G16_UNORM = 35,
|
||||
DXGI_FORMAT_R16G16_UINT = 36,
|
||||
DXGI_FORMAT_R16G16_SNORM = 37,
|
||||
DXGI_FORMAT_R16G16_SINT = 38,
|
||||
DXGI_FORMAT_R32_TYPELESS = 39,
|
||||
DXGI_FORMAT_D32_FLOAT = 40,
|
||||
DXGI_FORMAT_R32_FLOAT = 41,
|
||||
DXGI_FORMAT_R32_UINT = 42,
|
||||
DXGI_FORMAT_R32_SINT = 43,
|
||||
DXGI_FORMAT_R24G8_TYPELESS = 44,
|
||||
DXGI_FORMAT_D24_UNORM_S8_UINT = 45,
|
||||
DXGI_FORMAT_R24_UNORM_X8_TYPELESS = 46,
|
||||
DXGI_FORMAT_X24_TYPELESS_G8_UINT = 47,
|
||||
DXGI_FORMAT_R8G8_TYPELESS = 48,
|
||||
DXGI_FORMAT_R8G8_UNORM = 49,
|
||||
DXGI_FORMAT_R8G8_UINT = 50,
|
||||
DXGI_FORMAT_R8G8_SNORM = 51,
|
||||
DXGI_FORMAT_R8G8_SINT = 52,
|
||||
DXGI_FORMAT_R16_TYPELESS = 53,
|
||||
DXGI_FORMAT_R16_FLOAT = 54,
|
||||
DXGI_FORMAT_D16_UNORM = 55,
|
||||
DXGI_FORMAT_R16_UNORM = 56,
|
||||
DXGI_FORMAT_R16_UINT = 57,
|
||||
DXGI_FORMAT_R16_SNORM = 58,
|
||||
DXGI_FORMAT_R16_SINT = 59,
|
||||
DXGI_FORMAT_R8_TYPELESS = 60,
|
||||
DXGI_FORMAT_R8_UNORM = 61,
|
||||
DXGI_FORMAT_R8_UINT = 62,
|
||||
DXGI_FORMAT_R8_SNORM = 63,
|
||||
DXGI_FORMAT_R8_SINT = 64,
|
||||
DXGI_FORMAT_A8_UNORM = 65,
|
||||
DXGI_FORMAT_R1_UNORM = 66,
|
||||
DXGI_FORMAT_R9G9B9E5_SHAREDEXP = 67,
|
||||
DXGI_FORMAT_R8G8_B8G8_UNORM = 68,
|
||||
DXGI_FORMAT_G8R8_G8B8_UNORM = 69,
|
||||
DXGI_FORMAT_BC1_TYPELESS = 70,
|
||||
DXGI_FORMAT_BC1_UNORM = 71,
|
||||
DXGI_FORMAT_BC1_UNORM_SRGB = 72,
|
||||
DXGI_FORMAT_BC2_TYPELESS = 73,
|
||||
DXGI_FORMAT_BC2_UNORM = 74,
|
||||
DXGI_FORMAT_BC2_UNORM_SRGB = 75,
|
||||
DXGI_FORMAT_BC3_TYPELESS = 76,
|
||||
DXGI_FORMAT_BC3_UNORM = 77,
|
||||
DXGI_FORMAT_BC3_UNORM_SRGB = 78,
|
||||
DXGI_FORMAT_BC4_TYPELESS = 79,
|
||||
DXGI_FORMAT_BC4_UNORM = 80,
|
||||
DXGI_FORMAT_BC4_SNORM = 81,
|
||||
DXGI_FORMAT_BC5_TYPELESS = 82,
|
||||
DXGI_FORMAT_BC5_UNORM = 83,
|
||||
DXGI_FORMAT_BC5_SNORM = 84,
|
||||
DXGI_FORMAT_B5G6R5_UNORM = 85,
|
||||
DXGI_FORMAT_B5G5R5A1_UNORM = 86,
|
||||
DXGI_FORMAT_B8G8R8A8_UNORM = 87,
|
||||
DXGI_FORMAT_B8G8R8X8_UNORM = 88,
|
||||
DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM = 89,
|
||||
DXGI_FORMAT_B8G8R8A8_TYPELESS = 90,
|
||||
DXGI_FORMAT_B8G8R8A8_UNORM_SRGB = 91,
|
||||
DXGI_FORMAT_B8G8R8X8_TYPELESS = 92,
|
||||
DXGI_FORMAT_B8G8R8X8_UNORM_SRGB = 93,
|
||||
DXGI_FORMAT_BC6H_TYPELESS = 94,
|
||||
DXGI_FORMAT_BC6H_UF16 = 95,
|
||||
DXGI_FORMAT_BC6H_SF16 = 96,
|
||||
DXGI_FORMAT_BC7_TYPELESS = 97,
|
||||
DXGI_FORMAT_BC7_UNORM = 98,
|
||||
DXGI_FORMAT_BC7_UNORM_SRGB = 99,
|
||||
|
||||
DXGI_FORMAT_EAC_R11_TYPELESS = 200,
|
||||
DXGI_FORMAT_EAC_R11_UNORM = 201,
|
||||
DXGI_FORMAT_EAC_R11_SNORM = 202,
|
||||
DXGI_FORMAT_EAC_RG11_TYPELESS = 203,
|
||||
DXGI_FORMAT_EAC_RG11_UNORM = 204,
|
||||
DXGI_FORMAT_EAC_RG11_SNORM = 205,
|
||||
DXGI_FORMAT_ETC2_TYPELESS = 206,
|
||||
DXGI_FORMAT_ETC2_UNORM = 207,
|
||||
DXGI_FORMAT_ETC2_UNORM_SRGB = 208,
|
||||
DXGI_FORMAT_ETC2A_TYPELESS = 209,
|
||||
DXGI_FORMAT_ETC2A_UNORM = 210,
|
||||
DXGI_FORMAT_ETC2A_UNORM_SRGB = 211,
|
||||
|
||||
DXGI_FORMAT_PVRTC2_TYPELESS = 250,
|
||||
DXGI_FORMAT_PVRTC2_UNORM = 251,
|
||||
DXGI_FORMAT_PVRTC2_UNORM_SRGB = 252,
|
||||
DXGI_FORMAT_PVRTC4_TYPELESS = 253,
|
||||
DXGI_FORMAT_PVRTC4_UNORM = 254,
|
||||
DXGI_FORMAT_PVRTC4_UNORM_SRGB = 255,
|
||||
|
||||
DXGI_FORMAT_ASTC_4x4_TYPELESS = 260,
|
||||
DXGI_FORMAT_ASTC_4x4_UNORM = 261,
|
||||
DXGI_FORMAT_ASTC_4x4_UNORM_SRGB = 262,
|
||||
DXGI_FORMAT_ASTC_5x4_TYPELESS = 263,
|
||||
DXGI_FORMAT_ASTC_5x4_UNORM = 264,
|
||||
DXGI_FORMAT_ASTC_5x4_UNORM_SRGB = 265,
|
||||
DXGI_FORMAT_ASTC_5x5_TYPELESS = 266,
|
||||
DXGI_FORMAT_ASTC_5x5_UNORM = 267,
|
||||
DXGI_FORMAT_ASTC_5x5_UNORM_SRGB = 268,
|
||||
DXGI_FORMAT_ASTC_6x5_TYPELESS = 269,
|
||||
DXGI_FORMAT_ASTC_6x5_UNORM = 270,
|
||||
DXGI_FORMAT_ASTC_6x5_UNORM_SRGB = 271,
|
||||
DXGI_FORMAT_ASTC_6x6_TYPELESS = 272,
|
||||
DXGI_FORMAT_ASTC_6x6_UNORM = 273,
|
||||
DXGI_FORMAT_ASTC_6x6_UNORM_SRGB = 274,
|
||||
DXGI_FORMAT_ASTC_8x5_TYPELESS = 275,
|
||||
DXGI_FORMAT_ASTC_8x5_UNORM = 276,
|
||||
DXGI_FORMAT_ASTC_8x5_UNORM_SRGB = 277,
|
||||
DXGI_FORMAT_ASTC_8x6_TYPELESS = 278,
|
||||
DXGI_FORMAT_ASTC_8x6_UNORM = 279,
|
||||
DXGI_FORMAT_ASTC_8x6_UNORM_SRGB = 280,
|
||||
DXGI_FORMAT_ASTC_8x8_TYPELESS = 281,
|
||||
DXGI_FORMAT_ASTC_8x8_UNORM = 282,
|
||||
DXGI_FORMAT_ASTC_8x8_UNORM_SRGB = 283,
|
||||
DXGI_FORMAT_ASTC_10x5_TYPELESS = 284,
|
||||
DXGI_FORMAT_ASTC_10x5_UNORM = 285,
|
||||
DXGI_FORMAT_ASTC_10x5_UNORM_SRGB = 286,
|
||||
DXGI_FORMAT_ASTC_10x6_TYPELESS = 287,
|
||||
DXGI_FORMAT_ASTC_10x6_UNORM = 288,
|
||||
DXGI_FORMAT_ASTC_10x6_UNORM_SRGB = 289,
|
||||
DXGI_FORMAT_ASTC_10x8_TYPELESS = 290,
|
||||
DXGI_FORMAT_ASTC_10x8_UNORM = 291,
|
||||
DXGI_FORMAT_ASTC_10x8_UNORM_SRGB = 292,
|
||||
DXGI_FORMAT_ASTC_10x10_TYPELESS = 293,
|
||||
DXGI_FORMAT_ASTC_10x10_UNORM = 294,
|
||||
DXGI_FORMAT_ASTC_10x10_UNORM_SRGB = 295,
|
||||
DXGI_FORMAT_ASTC_12x10_TYPELESS = 296,
|
||||
DXGI_FORMAT_ASTC_12x10_UNORM = 297,
|
||||
DXGI_FORMAT_ASTC_12x10_UNORM_SRGB = 298,
|
||||
DXGI_FORMAT_ASTC_12x12_TYPELESS = 299,
|
||||
DXGI_FORMAT_ASTC_12x12_UNORM = 300,
|
||||
DXGI_FORMAT_ASTC_12x12_UNORM_SRGB = 301,
|
||||
|
||||
DXGI_FORMAT_FORCE_UINT = 0xffffffff
|
||||
} DXGI_FORMAT;
|
||||
|
||||
#endif
|
||||
@@ -1,903 +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 : Describe contents on CGF file.
|
||||
|
||||
|
||||
#ifndef CRYINCLUDE_CRYCOMMON_CGFCONTENT_H
|
||||
#define CRYINCLUDE_CRYCOMMON_CGFCONTENT_H
|
||||
#pragma once
|
||||
|
||||
#include <IIndexedMesh.h> // <> required for Interfuscator
|
||||
#include <IChunkFile.h> // <> required for Interfuscator
|
||||
#include <CryHeaders.h>
|
||||
#include <Cry_Color.h>
|
||||
#include <CryArray.h>
|
||||
#include <StringUtils.h>
|
||||
#include <AzCore/Casting/numeric_cast.h>
|
||||
|
||||
#include <AzCore/std/containers/unordered_map.h> //Required for LOD support for touch bending vegetation
|
||||
#include <AzCore/std/string/string.h> //Required for LOD support for touch bending vegetation
|
||||
|
||||
const int CGF_NODE_NAME_LENGTH = 64;
|
||||
//END: Add LOD support for touch bending vegetation
|
||||
|
||||
struct CMaterialCGF;
|
||||
struct IConvertContext;
|
||||
|
||||
#define CGF_NODE_NAME_LOD_PREFIX "$lod"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// This structure represents CGF node.
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
struct CNodeCGF
|
||||
: public _cfg_reference_target<CNodeCGF>
|
||||
{
|
||||
enum ENodeType
|
||||
{
|
||||
NODE_MESH,
|
||||
NODE_LIGHT,
|
||||
NODE_HELPER,
|
||||
};
|
||||
enum EPhysicalizeFlags
|
||||
{
|
||||
ePhysicsalizeFlag_MeshNotNeeded = BIT(2), // When set physics data doesn't need additional Mesh indices or vertices.
|
||||
ePhysicsalizeFlag_NoBreaking = BIT(3), // node is unsuitable for procedural 3d breaking
|
||||
};
|
||||
|
||||
ENodeType type;
|
||||
//START: Add LOD support for touch bending vegetation
|
||||
char name[CGF_NODE_NAME_LENGTH];
|
||||
//END: Add LOD support for touch bending vegetation
|
||||
string properties;
|
||||
Matrix34 localTM; // Local space transformation matrix.
|
||||
Matrix34 worldTM; // World space transformation matrix.
|
||||
CNodeCGF* pParent; // Pointer to parent node.
|
||||
CNodeCGF* pSharedMesh; // Not NULL if this node is sharing mesh and physics from referenced Node.
|
||||
CMesh* pMesh; // Pointer to mesh loaded for this node. (Only when type == NODE_MESH)
|
||||
|
||||
HelperTypes helperType; // Only relevant if type==NODE_HELPER
|
||||
Vec3 helperSize; // Only relevant if type==NODE_HELPER
|
||||
|
||||
CMaterialCGF* pMaterial; // Material node.
|
||||
|
||||
// Physical data of the node with mesh.
|
||||
int nPhysicalizeFlags; // Saved into the nFlags2 chunk member.
|
||||
AZStd::vector<char> physicalGeomData[4];
|
||||
int nPhysTriCount; // Not saved! only used for statistics in RC
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Used internally.
|
||||
int nChunkId; // Chunk id as loaded from CGF.
|
||||
int nParentChunkId; // Chunk id of parent Node.
|
||||
int nObjectChunkId; // Chunk id of the corresponding mesh.
|
||||
int pos_cont_id; // position controller chunk id
|
||||
int rot_cont_id; // rotation controller chunk id
|
||||
int scl_cont_id; // scale controller chunk id
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// True if worldTM is identity.
|
||||
bool bIdentityMatrix;
|
||||
// True when this node is invisible physics proxy.
|
||||
bool bPhysicsProxy;
|
||||
|
||||
// These values are not saved, but are only used for loading empty mesh chunks.
|
||||
struct MeshInfo
|
||||
{
|
||||
int nVerts;
|
||||
int nIndices;
|
||||
int nSubsets;
|
||||
Vec3 bboxMin;
|
||||
Vec3 bboxMax;
|
||||
float fGeometricMean;
|
||||
};
|
||||
MeshInfo meshInfo;
|
||||
|
||||
CrySkinVtx* pSkinInfo; // for skinning with skeleton meshes (deformable objects)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Constructor.
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void Init()
|
||||
{
|
||||
type = NODE_MESH;
|
||||
localTM.SetIdentity();
|
||||
worldTM.SetIdentity();
|
||||
pParent = 0;
|
||||
pSharedMesh = 0;
|
||||
pMesh = 0;
|
||||
pMaterial = 0;
|
||||
helperType = HP_POINT;
|
||||
helperSize.Set(0, 0, 0);
|
||||
nPhysicalizeFlags = 0;
|
||||
nChunkId = 0;
|
||||
nParentChunkId = 0;
|
||||
nObjectChunkId = 0;
|
||||
pos_cont_id = rot_cont_id = scl_cont_id = 0;
|
||||
bIdentityMatrix = true;
|
||||
bPhysicsProxy = false;
|
||||
pSkinInfo = 0;
|
||||
nPhysTriCount = 0;
|
||||
|
||||
ZeroStruct(meshInfo);
|
||||
}
|
||||
|
||||
CNodeCGF()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
explicit CNodeCGF(_cfg_reference_target<CNodeCGF>::DeleteFncPtr pDeleteFnc)
|
||||
: _cfg_reference_target<CNodeCGF>(pDeleteFnc)
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
~CNodeCGF()
|
||||
{
|
||||
if (!pSharedMesh)
|
||||
{
|
||||
delete pMesh;
|
||||
}
|
||||
if (pSkinInfo)
|
||||
{
|
||||
delete[] pSkinInfo;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// structures for skinning
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct TFace
|
||||
{
|
||||
uint16 i0, i1, i2;
|
||||
TFace() {}
|
||||
TFace(uint16 v0, uint16 v1, uint16 v2) { i0 = v0; i1 = v1; i2 = v2; }
|
||||
TFace(const CryFace& face) { i0 = aznumeric_caster(face[0]); i1 = aznumeric_caster(face[1]); i2 = aznumeric_caster(face[2]); }
|
||||
void operator = (const TFace& f) { i0 = f.i0; i1 = f.i1; i2 = f.i2; }
|
||||
void GetMemoryUsage([[maybe_unused]] ICrySizer* pSizer) const{}
|
||||
AUTO_STRUCT_INFO
|
||||
};
|
||||
|
||||
struct PhysicalProxy
|
||||
{
|
||||
uint32 ChunkID;
|
||||
DynArray<Vec3> m_arrPoints;
|
||||
DynArray<uint16> m_arrIndices;
|
||||
DynArray<char> m_arrMaterials;
|
||||
};
|
||||
|
||||
struct MorphTargets
|
||||
{
|
||||
uint32 MeshID;
|
||||
string m_strName;
|
||||
DynArray<SMeshMorphTargetVertex> m_arrIntMorph;
|
||||
DynArray<SMeshMorphTargetVertex> m_arrExtMorph;
|
||||
};
|
||||
|
||||
typedef MorphTargets* MorphTargetsPtr;
|
||||
|
||||
struct IntSkinVertex
|
||||
{
|
||||
Vec3 __obsolete0; // thin/fat vertex position. must be removed in the next RC refactoring
|
||||
Vec3 pos; // vertex-position of model.2
|
||||
Vec3 __obsolete2; // thin/fat vertex position. must be removed in the next RC refactoring
|
||||
uint16 boneIDs[4];
|
||||
f32 weights[4];
|
||||
ColorB color; //index for blend-array
|
||||
void GetMemoryUsage([[maybe_unused]] ICrySizer* pSizer) const{}
|
||||
AUTO_STRUCT_INFO
|
||||
};
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// TCB Controller implementation.
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
// retrieves the position and orientation (in the logarithmic space, i.e. instead of quaternion, its logarithm is returned)
|
||||
// may be optimal for motion interpolation
|
||||
struct PQLog
|
||||
{
|
||||
Vec3 vPos;
|
||||
Vec3 vRotLog; // logarithm of the rotation
|
||||
void blendPQ (const PQLog& pqFrom, const PQLog& pqTo, f32 fBlend);
|
||||
void GetMemoryUsage([[maybe_unused]] ICrySizer* pSizer) const{}
|
||||
};
|
||||
|
||||
struct CControllerType
|
||||
{
|
||||
uint16 m_controllertype;
|
||||
uint16 m_index;
|
||||
CControllerType()
|
||||
{
|
||||
m_controllertype = 0xffff;
|
||||
m_index = 0xffff;
|
||||
}
|
||||
};
|
||||
|
||||
struct TCBFlags
|
||||
{
|
||||
uint8 f0, f1;
|
||||
TCBFlags() { f0 = f1 = 0; }
|
||||
};
|
||||
|
||||
struct CStoredSkinningInfo
|
||||
{
|
||||
int32 m_nTicksPerFrame;
|
||||
f32 m_secsPerTick;
|
||||
int32 m_nStart;
|
||||
int32 m_nEnd;
|
||||
f32 m_Speed;
|
||||
f32 m_Distance;
|
||||
f32 m_Slope;
|
||||
int m_nAssetFlags;
|
||||
f32 m_LHeelStart, m_LHeelEnd;
|
||||
f32 m_LToe0Start, m_LToe0End;
|
||||
f32 m_RHeelStart, m_RHeelEnd;
|
||||
f32 m_RToe0Start, m_RToe0End;
|
||||
Vec3 m_MoveDirection; // raw storage
|
||||
|
||||
CStoredSkinningInfo()
|
||||
: m_Speed(-1.0f)
|
||||
, m_Distance(-1.0f)
|
||||
, m_nAssetFlags(0)
|
||||
, m_LHeelStart(-10000.0f)
|
||||
, m_LHeelEnd(-10000.0f)
|
||||
, m_LToe0Start(-10000.0f)
|
||||
, m_LToe0End(-10000.0f)
|
||||
, m_RHeelStart(-10000.0f)
|
||||
, m_RHeelEnd(-10000.0f)
|
||||
, m_RToe0Start(-10000.0f)
|
||||
, m_RToe0End(-10000.0f)
|
||||
, m_Slope(-1.0f)
|
||||
{
|
||||
}
|
||||
AUTO_STRUCT_INFO
|
||||
};
|
||||
|
||||
|
||||
|
||||
// structure for recreating controllers
|
||||
struct CControllerInfo
|
||||
{
|
||||
uint32 m_nControllerID;
|
||||
uint32 m_nPosKeyTimeTrack;
|
||||
uint32 m_nPosTrack;
|
||||
uint32 m_nRotKeyTimeTrack;
|
||||
uint32 m_nRotTrack;
|
||||
|
||||
CControllerInfo()
|
||||
: m_nControllerID(~0)
|
||||
, m_nPosKeyTimeTrack(~0)
|
||||
, m_nPosTrack(~0)
|
||||
, m_nRotKeyTimeTrack(~0)
|
||||
, m_nRotTrack(~0) {}
|
||||
|
||||
AUTO_STRUCT_INFO
|
||||
};
|
||||
|
||||
struct MeshCollisionInfo
|
||||
{
|
||||
AABB m_aABB;
|
||||
OBB m_OBB;
|
||||
Vec3 m_Pos;
|
||||
DynArray<int16> m_arrIndexes;
|
||||
int32 m_iBoneId;
|
||||
|
||||
MeshCollisionInfo()
|
||||
{
|
||||
// This didn't help much.
|
||||
// The BBs are reset to opposite infinites,
|
||||
// but never clamped/grown by any member points.
|
||||
m_aABB.min.zero();
|
||||
m_aABB.max.zero();
|
||||
m_OBB.m33.SetIdentity();
|
||||
m_OBB.h.zero();
|
||||
m_OBB.c.zero();
|
||||
m_Pos.zero();
|
||||
}
|
||||
void GetMemoryUsage(ICrySizer* pSizer) const
|
||||
{
|
||||
pSizer->AddObject(m_arrIndexes);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
struct SJointsAimIK_Rot
|
||||
{
|
||||
const char* m_strJointName;
|
||||
int16 m_nJointIdx;
|
||||
int16 m_nPosIndex;
|
||||
uint8 m_nPreEvaluate;
|
||||
uint8 m_nAdditive;
|
||||
int16 m_nRotJointParentIdx;
|
||||
SJointsAimIK_Rot()
|
||||
{
|
||||
m_strJointName = 0;
|
||||
m_nJointIdx = -1;
|
||||
m_nPosIndex = -1;
|
||||
m_nPreEvaluate = 0;
|
||||
m_nAdditive = 0;
|
||||
m_nRotJointParentIdx = -1;
|
||||
};
|
||||
void GetMemoryUsage([[maybe_unused]] ICrySizer* pSizer) const{}
|
||||
};
|
||||
|
||||
struct SJointsAimIK_Pos
|
||||
{
|
||||
const char* m_strJointName;
|
||||
int16 m_nJointIdx;
|
||||
uint8 m_nAdditive;
|
||||
uint8 m_nEmpty;
|
||||
SJointsAimIK_Pos()
|
||||
{
|
||||
m_strJointName = 0;
|
||||
m_nJointIdx = -1;
|
||||
m_nAdditive = 0;
|
||||
m_nEmpty = 0;
|
||||
};
|
||||
void GetMemoryUsage([[maybe_unused]] ICrySizer* pSizer) const{}
|
||||
};
|
||||
|
||||
|
||||
struct DirectionalBlends
|
||||
{
|
||||
string m_AnimToken;
|
||||
uint32 m_AnimTokenCRC32;
|
||||
const char* m_strParaJointName;
|
||||
int16 m_nParaJointIdx;
|
||||
int16 m_nRotParaJointIdx;
|
||||
const char* m_strStartJointName;
|
||||
int16 m_nStartJointIdx;
|
||||
int16 m_nRotStartJointIdx;
|
||||
const char* m_strReferenceJointName;
|
||||
int32 m_nReferenceJointIdx;
|
||||
DirectionalBlends()
|
||||
{
|
||||
m_AnimTokenCRC32 = 0;
|
||||
m_strParaJointName = 0;
|
||||
m_nParaJointIdx = -1;
|
||||
m_nRotParaJointIdx = -1;
|
||||
m_strStartJointName = 0;
|
||||
m_nStartJointIdx = -1;
|
||||
m_nRotStartJointIdx = -1;
|
||||
m_strReferenceJointName = 0;
|
||||
m_nReferenceJointIdx = 1; //by default we use the Pelvis
|
||||
};
|
||||
void GetMemoryUsage([[maybe_unused]] ICrySizer* pSizer) const {}
|
||||
};
|
||||
|
||||
|
||||
struct CSkinningInfo
|
||||
: public _reference_target_t
|
||||
{
|
||||
DynArray<CryBoneDescData> m_arrBonesDesc; //animation-bones
|
||||
|
||||
DynArray<SJointsAimIK_Rot> m_LookIK_Rot; //rotational joints used for Look-IK
|
||||
DynArray<SJointsAimIK_Pos> m_LookIK_Pos; //positional joints used for Look-IK
|
||||
DynArray<DirectionalBlends> m_LookDirBlends; //positional joints used for Look-IK
|
||||
|
||||
DynArray<SJointsAimIK_Rot> m_AimIK_Rot; //rotational joints used for Aim-IK
|
||||
DynArray<SJointsAimIK_Pos> m_AimIK_Pos; //positional joints used for Aim-IK
|
||||
DynArray<DirectionalBlends> m_AimDirBlends; //positional joints used for Aim-IK
|
||||
|
||||
|
||||
DynArray<PhysicalProxy> m_arrPhyBoneMeshes; //collision proxi
|
||||
DynArray<MorphTargetsPtr> m_arrMorphTargets;
|
||||
DynArray<TFace> m_arrIntFaces;
|
||||
DynArray<IntSkinVertex> m_arrIntVertices;
|
||||
DynArray<uint16> m_arrExt2IntMap;
|
||||
DynArray<BONE_ENTITY> m_arrBoneEntities; //physical-bones
|
||||
DynArray<MeshCollisionInfo> m_arrCollisions;
|
||||
|
||||
uint32 m_numChunks{ 0 };
|
||||
bool m_bRotatedMorphTargets;
|
||||
bool m_bProperBBoxes;
|
||||
|
||||
CSkinningInfo()
|
||||
: m_bRotatedMorphTargets(false)
|
||||
, m_bProperBBoxes(false) {}
|
||||
|
||||
~CSkinningInfo()
|
||||
{
|
||||
for (DynArray<MorphTargetsPtr>::iterator it = m_arrMorphTargets.begin(), end = m_arrMorphTargets.end(); it != end; ++it)
|
||||
{
|
||||
delete *it;
|
||||
}
|
||||
}
|
||||
|
||||
int32 GetJointIDByName(const char* strJointName) const
|
||||
{
|
||||
uint32 numJoints = m_arrBonesDesc.size();
|
||||
for (uint32 i = 0; i < numJoints; i++)
|
||||
{
|
||||
if (_stricmp(m_arrBonesDesc[i].m_arrBoneName, strJointName) == 0)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Return name of bone from bone table, return zero id nId is out of range
|
||||
const char* GetJointNameByID(int32 nJointID) const
|
||||
{
|
||||
int32 numJoints = m_arrBonesDesc.size();
|
||||
if (nJointID >= 0 && nJointID < numJoints)
|
||||
{
|
||||
return m_arrBonesDesc[nJointID].m_arrBoneName;
|
||||
}
|
||||
return ""; // invalid bone id
|
||||
}
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// This structure represents Material inside CGF.
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
struct CMaterialCGF
|
||||
: public _cfg_reference_target<CMaterialCGF>
|
||||
{
|
||||
char name[128]; // Material name;
|
||||
int nFlags; // Material flags.
|
||||
int nPhysicalizeType;
|
||||
bool bOldMaterial;
|
||||
float shOpacity;
|
||||
|
||||
// Array of sub materials.
|
||||
DynArray<CMaterialCGF*> subMaterials;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Used internally.
|
||||
int nChunkId;
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Init()
|
||||
{
|
||||
nFlags = 0;
|
||||
nChunkId = 0;
|
||||
bOldMaterial = false;
|
||||
nPhysicalizeType = PHYS_GEOM_TYPE_DEFAULT;
|
||||
shOpacity = 1.f;
|
||||
}
|
||||
|
||||
CMaterialCGF() { Init(); }
|
||||
|
||||
explicit CMaterialCGF(_cfg_reference_target<CMaterialCGF>::DeleteFncPtr pDeleteFnc)
|
||||
: _cfg_reference_target<CMaterialCGF>(pDeleteFnc)
|
||||
{ Init(); }
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Info about physicalization of the CGF.
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
struct CPhysicalizeInfoCGF
|
||||
{
|
||||
bool bWeldVertices;
|
||||
float fWeldTolerance; // Min Distance between vertices when they collapse to single vertex if bWeldVertices enabled.
|
||||
|
||||
// breakable physics
|
||||
int nGranularity;
|
||||
int nMode;
|
||||
|
||||
Vec3* pRetVtx;
|
||||
int nRetVtx;
|
||||
int* pRetTets;
|
||||
int nRetTets;
|
||||
|
||||
CPhysicalizeInfoCGF()
|
||||
: bWeldVertices(true)
|
||||
, fWeldTolerance(0.01f)
|
||||
, nMode(-1)
|
||||
, nGranularity(-1)
|
||||
, pRetVtx(0)
|
||||
, nRetVtx(0)
|
||||
, pRetTets(0)
|
||||
, nRetTets(0){}
|
||||
|
||||
~CPhysicalizeInfoCGF()
|
||||
{
|
||||
if (pRetVtx)
|
||||
{
|
||||
delete []pRetVtx;
|
||||
pRetVtx = 0;
|
||||
}
|
||||
if (pRetTets)
|
||||
{
|
||||
delete []pRetTets;
|
||||
pRetTets = 0;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Serialized skinnable foliage data
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define NODE_PROPERTY_STIFFNESS "stiffness"
|
||||
#define NODE_PROPERTY_DAMPING "damping"
|
||||
#define NODE_PROPERTY_THICKNESS "thickness"
|
||||
|
||||
struct SSpineRC
|
||||
{
|
||||
SSpineRC()
|
||||
: pVtx(nullptr)
|
||||
, pSegDim(nullptr)
|
||||
, nVtx(0)
|
||||
, len(0)
|
||||
, pBoneIDs(nullptr)
|
||||
, parentBoneID(-1)
|
||||
, pStiffness(nullptr)
|
||||
, pDamping(nullptr)
|
||||
, pThickness(nullptr) {}
|
||||
|
||||
~SSpineRC()
|
||||
{
|
||||
if (pVtx)
|
||||
{
|
||||
delete[] pVtx;
|
||||
}
|
||||
if (pSegDim)
|
||||
{
|
||||
delete[] pSegDim;
|
||||
}
|
||||
if (pBoneIDs)
|
||||
{
|
||||
delete[] pBoneIDs;
|
||||
}
|
||||
if (pStiffness)
|
||||
{
|
||||
delete[] pStiffness;
|
||||
}
|
||||
if (pDamping)
|
||||
{
|
||||
delete[] pDamping;
|
||||
}
|
||||
if (pThickness)
|
||||
{
|
||||
delete[] pThickness;
|
||||
}
|
||||
}
|
||||
|
||||
/// Add Skinned Geometry (.CGF) export type (for touch bending vegetation)
|
||||
static float GetDefaultStiffness() { return 0.5f; }
|
||||
static float GetDefaultDamping() { return 0.5f; }
|
||||
static float GetDefaultThickness() { return 0.03f; }
|
||||
|
||||
Vec3* pVtx;
|
||||
Vec4* pSegDim;
|
||||
int nVtx;
|
||||
float len;
|
||||
Vec3 navg;
|
||||
|
||||
int parentBoneID;
|
||||
int* pBoneIDs;
|
||||
|
||||
//Per Bone parameters.
|
||||
float* pStiffness;
|
||||
float* pDamping;
|
||||
float* pThickness;
|
||||
|
||||
int iAttachSpine;
|
||||
int iAttachSeg;
|
||||
};
|
||||
|
||||
struct SFoliageInfoCGF
|
||||
{
|
||||
SFoliageInfoCGF() { nSpines = 0; pSpines = 0; pBoneMapping = 0; }
|
||||
~SFoliageInfoCGF()
|
||||
{
|
||||
if (pSpines)
|
||||
{
|
||||
for (int i = 1; i < nSpines; i++) // spines 1..n-1 use the same buffer, so make sure they don't delete it
|
||||
{
|
||||
pSpines[i].pVtx = nullptr;
|
||||
pSpines[i].pSegDim = nullptr;
|
||||
pSpines[i].pBoneIDs = nullptr;
|
||||
pSpines[i].pStiffness = nullptr;
|
||||
pSpines[i].pDamping = nullptr;
|
||||
pSpines[i].pThickness = nullptr;
|
||||
}
|
||||
delete[] pSpines;
|
||||
}
|
||||
|
||||
SAFE_DELETE_ARRAY(pBoneMapping);
|
||||
|
||||
AZStd::unordered_map<AZStd::string, SMeshBoneMappingInfo_uint8*>::iterator iter = boneMappings.begin();
|
||||
while (iter != boneMappings.end())
|
||||
{
|
||||
if (iter->second != nullptr)
|
||||
{
|
||||
SAFE_DELETE_ARRAY(iter->second->pBoneMapping);
|
||||
}
|
||||
iter++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
SSpineRC* pSpines;
|
||||
int nSpines;
|
||||
|
||||
///Bone mappings for each LOD level
|
||||
AZStd::unordered_map<AZStd::string, SMeshBoneMappingInfo_uint8*> boneMappings;
|
||||
|
||||
///Bone mapping for legacy format
|
||||
struct SMeshBoneMapping_uint8* pBoneMapping;
|
||||
int nSkinnedVtx;
|
||||
|
||||
DynArray<uint16> chunkBoneIds;
|
||||
};
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
struct CExportInfoCGF
|
||||
{
|
||||
bool bMergeAllNodes;
|
||||
bool bUseCustomNormals;
|
||||
bool bCompiledCGF;
|
||||
bool bHavePhysicsProxy;
|
||||
bool bHaveAutoLods;
|
||||
bool bNoMesh;
|
||||
bool bWantF32Vertices;
|
||||
bool b8WeightsPerVertex;
|
||||
|
||||
/// Prevent reprocessing skinning data for skinned CGF
|
||||
bool bSkinnedCGF;
|
||||
|
||||
bool bFromColladaXSI;
|
||||
bool bFromColladaMAX;
|
||||
bool bFromColladaMAYA;
|
||||
|
||||
unsigned int rc_version[4]; // Resource compiler version.
|
||||
char rc_version_string[16]; // Version as a string.
|
||||
|
||||
unsigned int authorToolVersion;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// This class contain all info loaded from the CGF file.
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
class CContentCGF
|
||||
{
|
||||
public:
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
CContentCGF(const char* filename)
|
||||
{
|
||||
azstrcpy(m_filename, AZ_ARRAY_SIZE(m_filename), filename);
|
||||
memset(&m_exportInfo, 0, sizeof(m_exportInfo));
|
||||
m_exportInfo.bMergeAllNodes = true;
|
||||
m_exportInfo.bUseCustomNormals = false;
|
||||
m_exportInfo.bWantF32Vertices = false;
|
||||
m_exportInfo.b8WeightsPerVertex = false;
|
||||
m_exportInfo.bSkinnedCGF = false;
|
||||
m_pCommonMaterial = 0;
|
||||
m_bConsoleFormat = false;
|
||||
m_pOwnChunkFile = 0;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
virtual ~CContentCGF()
|
||||
{
|
||||
// Free nodes.
|
||||
m_nodes.clear();
|
||||
if (m_pOwnChunkFile)
|
||||
{
|
||||
m_pOwnChunkFile->Release();
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
const char* GetFilename() const
|
||||
{
|
||||
return m_filename;
|
||||
}
|
||||
|
||||
void SetFilename(const char* filename)
|
||||
{
|
||||
azstrcpy(m_filename, AZ_ARRAY_SIZE(m_filename), filename);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Access to CGF nodes.
|
||||
void AddNode(CNodeCGF* pNode)
|
||||
{
|
||||
m_nodes.push_back(pNode);
|
||||
}
|
||||
|
||||
int GetNodeCount() const
|
||||
{
|
||||
return m_nodes.size();
|
||||
}
|
||||
|
||||
CNodeCGF* GetNode(int i)
|
||||
{
|
||||
return m_nodes[i];
|
||||
}
|
||||
|
||||
const CNodeCGF* GetNode(int i) const
|
||||
{
|
||||
return m_nodes[i];
|
||||
}
|
||||
|
||||
void ClearNodes()
|
||||
{
|
||||
m_nodes.clear();
|
||||
}
|
||||
|
||||
void RemoveNode(CNodeCGF* pNode)
|
||||
{
|
||||
assert(pNode);
|
||||
for (int i = 0; i < m_nodes.size(); ++i)
|
||||
{
|
||||
if (m_nodes[i] == pNode)
|
||||
{
|
||||
pNode->pParent = 0;
|
||||
m_nodes.erase(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Access to CGF materials.
|
||||
void AddMaterial(CMaterialCGF* pNode)
|
||||
{
|
||||
m_materials.push_back(pNode);
|
||||
}
|
||||
|
||||
int GetMaterialCount() const
|
||||
{
|
||||
return m_materials.size();
|
||||
}
|
||||
|
||||
CMaterialCGF* GetMaterial(int i)
|
||||
{
|
||||
return m_materials[i];
|
||||
}
|
||||
|
||||
void ClearMaterials()
|
||||
{
|
||||
m_materials.clear();
|
||||
}
|
||||
|
||||
CMaterialCGF* GetCommonMaterial() const
|
||||
{
|
||||
return m_pCommonMaterial;
|
||||
}
|
||||
|
||||
void SetCommonMaterial(CMaterialCGF* pMtl)
|
||||
{
|
||||
m_pCommonMaterial = pMtl;
|
||||
}
|
||||
|
||||
DynArray<int>& GetUsedMaterialIDs()
|
||||
{
|
||||
return m_usedMaterialIds;
|
||||
}
|
||||
|
||||
const DynArray<int>& GetUsedMaterialIDs() const
|
||||
{
|
||||
return m_usedMaterialIds;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
CPhysicalizeInfoCGF* GetPhysicalizeInfo()
|
||||
{
|
||||
return &m_physicsInfo;
|
||||
}
|
||||
|
||||
const CPhysicalizeInfoCGF* GetPhysicalizeInfo() const
|
||||
{
|
||||
return &m_physicsInfo;
|
||||
}
|
||||
|
||||
CExportInfoCGF* GetExportInfo()
|
||||
{
|
||||
return &m_exportInfo;
|
||||
}
|
||||
|
||||
const CExportInfoCGF* GetExportInfo() const
|
||||
{
|
||||
return &m_exportInfo;
|
||||
}
|
||||
|
||||
CSkinningInfo* GetSkinningInfo()
|
||||
{
|
||||
return &m_SkinningInfo;
|
||||
}
|
||||
|
||||
const CSkinningInfo* GetSkinningInfo() const
|
||||
{
|
||||
return &m_SkinningInfo;
|
||||
}
|
||||
|
||||
SFoliageInfoCGF* GetFoliageInfo()
|
||||
{
|
||||
return &m_foliageInfo;
|
||||
}
|
||||
|
||||
bool GetConsoleFormat()
|
||||
{
|
||||
return m_bConsoleFormat;
|
||||
}
|
||||
|
||||
bool ValidateMeshes(const char** const ppErrorDescription) const
|
||||
{
|
||||
for (int i = 0; i < m_nodes.size(); ++i)
|
||||
{
|
||||
const CNodeCGF* const pNode = m_nodes[i];
|
||||
if (pNode && pNode->pMesh && (!pNode->pMesh->Validate(ppErrorDescription)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Set chunk file that this CGF owns.
|
||||
void SetChunkFile(IChunkFile* pChunkFile)
|
||||
{
|
||||
m_pOwnChunkFile = pChunkFile;
|
||||
}
|
||||
|
||||
public:
|
||||
bool m_bConsoleFormat;
|
||||
|
||||
private:
|
||||
char m_filename[260];
|
||||
CSkinningInfo m_SkinningInfo;
|
||||
DynArray<_smart_ptr<CNodeCGF> > m_nodes;
|
||||
DynArray<_smart_ptr<CMaterialCGF> > m_materials;
|
||||
DynArray<int> m_usedMaterialIds;
|
||||
_smart_ptr<CMaterialCGF> m_pCommonMaterial;
|
||||
|
||||
CPhysicalizeInfoCGF m_physicsInfo;
|
||||
CExportInfoCGF m_exportInfo;
|
||||
SFoliageInfoCGF m_foliageInfo;
|
||||
|
||||
IChunkFile* m_pOwnChunkFile;
|
||||
};
|
||||
|
||||
namespace AZ
|
||||
{
|
||||
namespace SceneAPI
|
||||
{
|
||||
namespace DataTypes
|
||||
{
|
||||
class IAnimationGroup;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Asset Writer interface for writing CContentCGF content to asset file
|
||||
struct IAssetWriter
|
||||
{
|
||||
virtual ~IAssetWriter()
|
||||
{
|
||||
}
|
||||
|
||||
virtual bool WriteCGF(CContentCGF* content) = 0;
|
||||
virtual bool WriteCHR(CContentCGF* content, IConvertContext* convertContext) = 0;
|
||||
virtual bool WriteSKIN(CContentCGF* content, IConvertContext* convertContext, bool exportMorphTargets) = 0;
|
||||
};
|
||||
|
||||
|
||||
#endif // CRYINCLUDE_CRYCOMMON_CGFCONTENT_H
|
||||
@@ -1,68 +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 "TypeInfo_impl.h"
|
||||
#include "CGFContent.h"
|
||||
|
||||
STRUCT_INFO_BEGIN(TFace)
|
||||
STRUCT_VAR_INFO(i0, TYPE_INFO(uint16))
|
||||
STRUCT_VAR_INFO(i1, TYPE_INFO(uint16))
|
||||
STRUCT_VAR_INFO(i2, TYPE_INFO(uint16))
|
||||
STRUCT_INFO_END(TFace)
|
||||
|
||||
STRUCT_INFO_BEGIN(IntSkinVertex)
|
||||
STRUCT_VAR_INFO(__obsolete0, TYPE_INFO(Vec3))
|
||||
STRUCT_VAR_INFO(pos, TYPE_INFO(Vec3))
|
||||
STRUCT_VAR_INFO(__obsolete2, TYPE_INFO(Vec3))
|
||||
STRUCT_VAR_INFO(boneIDs, TYPE_ARRAY(4, TYPE_INFO(uint16)))
|
||||
STRUCT_VAR_INFO(weights, TYPE_ARRAY(4, TYPE_INFO(f32)))
|
||||
STRUCT_VAR_INFO(color, TYPE_INFO(ColorB))
|
||||
STRUCT_INFO_END(IntSkinVertex)
|
||||
|
||||
STRUCT_INFO_BEGIN(CStoredSkinningInfo)
|
||||
STRUCT_VAR_INFO(m_nTicksPerFrame, TYPE_INFO(int32))
|
||||
STRUCT_VAR_INFO(m_secsPerTick, TYPE_INFO(f32))
|
||||
STRUCT_VAR_INFO(m_nStart, TYPE_INFO(int32))
|
||||
STRUCT_VAR_INFO(m_nEnd, TYPE_INFO(int32))
|
||||
STRUCT_VAR_INFO(m_Speed, TYPE_INFO(f32))
|
||||
STRUCT_VAR_INFO(m_Distance, TYPE_INFO(f32))
|
||||
STRUCT_VAR_INFO(m_Slope, TYPE_INFO(f32))
|
||||
STRUCT_VAR_INFO(m_nAssetFlags, TYPE_INFO(int))
|
||||
STRUCT_VAR_INFO(m_LHeelStart, TYPE_INFO(f32))
|
||||
STRUCT_VAR_INFO(m_LHeelEnd, TYPE_INFO(f32))
|
||||
STRUCT_VAR_INFO(m_LToe0Start, TYPE_INFO(f32))
|
||||
STRUCT_VAR_INFO(m_LToe0End, TYPE_INFO(f32))
|
||||
STRUCT_VAR_INFO(m_RHeelStart, TYPE_INFO(f32))
|
||||
STRUCT_VAR_INFO(m_RHeelEnd, TYPE_INFO(f32))
|
||||
STRUCT_VAR_INFO(m_RToe0Start, TYPE_INFO(f32))
|
||||
STRUCT_VAR_INFO(m_RToe0End, TYPE_INFO(f32))
|
||||
STRUCT_VAR_INFO(m_MoveDirection, TYPE_INFO(Vec3))
|
||||
STRUCT_INFO_END(CStoredSkinningInfo)
|
||||
|
||||
STRUCT_INFO_BEGIN(CControllerInfo)
|
||||
STRUCT_VAR_INFO(m_nControllerID, TYPE_INFO(uint32))
|
||||
STRUCT_VAR_INFO(m_nPosKeyTimeTrack, TYPE_INFO(uint32))
|
||||
STRUCT_VAR_INFO(m_nPosTrack, TYPE_INFO(uint32))
|
||||
STRUCT_VAR_INFO(m_nRotKeyTimeTrack, TYPE_INFO(uint32))
|
||||
STRUCT_VAR_INFO(m_nRotTrack, TYPE_INFO(uint32))
|
||||
STRUCT_INFO_END(CControllerInfo)
|
||||
|
||||
STRUCT_INFO_BEGIN(UCol)
|
||||
STRUCT_VAR_INFO(dcolor, TYPE_INFO(uint32))
|
||||
STRUCT_INFO_END(UCol)
|
||||
|
||||
STRUCT_INFO_BEGIN(SVF_P3S_C4B_T2S)
|
||||
STRUCT_VAR_INFO(xyz, TYPE_INFO(Vec3f16))
|
||||
STRUCT_VAR_INFO(color, TYPE_INFO(UCol))
|
||||
STRUCT_VAR_INFO(st, TYPE_INFO(Vec2f16))
|
||||
STRUCT_INFO_END(SVF_P3S_C4B_T2S)
|
||||
@@ -1,77 +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 : A wrapper that counts the number of times the wrapped object
|
||||
// has been set This is useful for netserializing an object
|
||||
// that might be given a new value that s the same as the old value
|
||||
|
||||
|
||||
#ifndef CRYINCLUDE_CRYCOMMON_COUNTEDVALUE_H
|
||||
#define CRYINCLUDE_CRYCOMMON_COUNTEDVALUE_H
|
||||
#pragma once
|
||||
|
||||
|
||||
template <typename T>
|
||||
struct CountedValue
|
||||
{
|
||||
public:
|
||||
CountedValue()
|
||||
: m_lastProducedId(0)
|
||||
, m_lastConsumedId(0) {}
|
||||
|
||||
typedef uint32 TCountedID;
|
||||
|
||||
void SetAndDirty(const T& value)
|
||||
{
|
||||
m_value = value;
|
||||
++m_lastProducedId;
|
||||
CRY_ASSERT(m_lastProducedId > 0);
|
||||
}
|
||||
|
||||
const T* GetLatestValue()
|
||||
{
|
||||
bool bHasNewValue = IsDirty(); // check for dirtiness before updating ids
|
||||
m_lastConsumedId = m_lastProducedId;
|
||||
|
||||
return bHasNewValue ? &m_value : NULL;
|
||||
}
|
||||
|
||||
inline bool IsDirty() const
|
||||
{
|
||||
return m_lastProducedId != m_lastConsumedId;
|
||||
}
|
||||
|
||||
const T& Peek() const
|
||||
{
|
||||
return m_value;
|
||||
}
|
||||
|
||||
TCountedID GetLatestID() const
|
||||
{
|
||||
return m_lastProducedId;
|
||||
}
|
||||
|
||||
// This method should only be used to update the object during serialization!
|
||||
void UpdateDuringSerializationOnly(const T& value, TCountedID lastProducedId)
|
||||
{
|
||||
m_value = value;
|
||||
m_lastProducedId = lastProducedId;
|
||||
}
|
||||
|
||||
private:
|
||||
TCountedID m_lastProducedId;
|
||||
TCountedID m_lastConsumedId;
|
||||
T m_value;
|
||||
};
|
||||
|
||||
#endif // CRYINCLUDE_CRYCOMMON_COUNTEDVALUE_H
|
||||
@@ -1,160 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
// support for leak dumping and statistics gathering using vs Crt Debug
|
||||
// should be included in every DLL below DllMain()
|
||||
#ifndef CRYINCLUDE_CRYCOMMON_CRTDEBUGSTATS_H
|
||||
#define CRYINCLUDE_CRYCOMMON_CRTDEBUGSTATS_H
|
||||
#pragma once
|
||||
|
||||
#ifdef WIN32
|
||||
#ifdef _DEBUG
|
||||
|
||||
|
||||
#include <ILog.h>
|
||||
#include <ISystem.h> // CryLogAlways
|
||||
#include <crtdbg.h>
|
||||
|
||||
// copied from DBGINT.H (not a public header!)
|
||||
|
||||
#define nNoMansLandSize 4
|
||||
|
||||
typedef struct _CrtMemBlockHeader
|
||||
{
|
||||
struct _CrtMemBlockHeader* pBlockHeaderNext;
|
||||
struct _CrtMemBlockHeader* pBlockHeaderPrev;
|
||||
char* szFileName;
|
||||
int nLine;
|
||||
size_t nDataSize;
|
||||
int nBlockUse;
|
||||
long lRequest;
|
||||
unsigned char gap[nNoMansLandSize];
|
||||
/* followed by:
|
||||
* unsigned char data[nDataSize];
|
||||
* unsigned char anotherGap[nNoMansLandSize];
|
||||
*/
|
||||
} _CrtMemBlockHeader;
|
||||
|
||||
struct SFileInfo
|
||||
{
|
||||
int blocks;
|
||||
INT_PTR bytes; //AMD Port
|
||||
SFileInfo(INT_PTR b) { blocks = 1; bytes = b; }; //AMD Port
|
||||
};
|
||||
|
||||
_CrtMemState lastcheckpoint;
|
||||
bool checkpointset = false;
|
||||
|
||||
extern "C" void __declspec(dllexport) CheckPoint()
|
||||
{
|
||||
_CrtMemCheckpoint(&lastcheckpoint);
|
||||
checkpointset = true;
|
||||
};
|
||||
|
||||
bool pairgreater(const std::pair<string, SFileInfo>& elem1, const std::pair<string, SFileInfo>& elem2)
|
||||
{
|
||||
return elem1.second.bytes > elem2.second.bytes;
|
||||
}
|
||||
|
||||
extern "C" void __declspec(dllexport) UsageSummary([[maybe_unused]] ILog * log, char* modulename, int* extras)
|
||||
{
|
||||
_CrtMemState state;
|
||||
|
||||
if (checkpointset)
|
||||
{
|
||||
_CrtMemState recent;
|
||||
_CrtMemCheckpoint(&recent);
|
||||
_CrtMemDifference(&state, &lastcheckpoint, &recent);
|
||||
}
|
||||
else
|
||||
{
|
||||
_CrtMemCheckpoint(&state);
|
||||
};
|
||||
|
||||
INT_PTR numblocks = state.lCounts[_NORMAL_BLOCK]; //AMD Port
|
||||
INT_PTR totalalloc = state.lSizes[_NORMAL_BLOCK]; //AMD Port
|
||||
|
||||
check_convert(extras[0]) = totalalloc;
|
||||
check_convert(extras[1]) = numblocks;
|
||||
|
||||
CryLogAlways("$5---------------------------------------------------------------------------------------------------");
|
||||
|
||||
if (!numblocks)
|
||||
{
|
||||
CryLogAlways("$3Module %s has no memory in use", modulename);
|
||||
return;
|
||||
}
|
||||
;
|
||||
|
||||
CryLogAlways("$5Usage summary for module %s", modulename);
|
||||
CryLogAlways("%d kbytes (peak %d) in %d objects of %d average bytes\n",
|
||||
totalalloc / 1024, state.lHighWaterCount / 1024, numblocks, numblocks ? totalalloc / numblocks : 0);
|
||||
CryLogAlways("%d kbytes allocated over time\n", state.lTotalCount / 1024);
|
||||
|
||||
typedef std::map<string, SFileInfo> FileMap;
|
||||
FileMap fm;
|
||||
|
||||
for (_CrtMemBlockHeader* h = state.pBlockHeader; h; h = h->pBlockHeaderNext)
|
||||
{
|
||||
if (_BLOCK_TYPE(h->nBlockUse) != _NORMAL_BLOCK)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
string s = h->szFileName ? h->szFileName : "NO_SOURCE";
|
||||
if (h->nLine > 0)
|
||||
{
|
||||
char buf[16];
|
||||
sprintf_s(buf, "_%d", h->nLine);
|
||||
s += buf;
|
||||
}
|
||||
FileMap::iterator it = fm.find(s);
|
||||
if (it != fm.end())
|
||||
{
|
||||
(*it).second.blocks++;
|
||||
(*it).second.bytes += h->nDataSize;
|
||||
}
|
||||
else
|
||||
{
|
||||
fm.insert(FileMap::value_type(s, SFileInfo(h->nDataSize)));
|
||||
};
|
||||
}
|
||||
;
|
||||
|
||||
typedef std::vector< std::pair<string, SFileInfo> > FileVector;
|
||||
FileVector fv;
|
||||
for (FileMap::iterator it = fm.begin(); it != fm.end(); ++it)
|
||||
{
|
||||
fv.push_back((*it));
|
||||
}
|
||||
std::sort(fv.begin(), fv.end(), pairgreater);
|
||||
|
||||
for (FileVector::iterator it = fv.begin(); it != fv.end(); ++it)
|
||||
{
|
||||
CryLogAlways("%6d kbytes / %6d blocks allocated from %s\n",
|
||||
(*it).second.bytes / 1024, (*it).second.blocks, (*it).first.c_str());
|
||||
}
|
||||
;
|
||||
};
|
||||
|
||||
#endif // _DEBUG
|
||||
|
||||
#if !defined(_RELEASE) && !defined(_DLL) && defined(HANDLE)
|
||||
extern "C" HANDLE _crtheap;
|
||||
extern "C" HANDLE __declspec(dllexport) GetDLLHeap() {
|
||||
return _crtheap;
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif // WIN32
|
||||
|
||||
#endif // CRYINCLUDE_CRYCOMMON_CRTDEBUGSTATS_H
|
||||
@@ -15,7 +15,7 @@
|
||||
#define CRYINCLUDE_CRYCOMMON_CRYARRAY_H
|
||||
#pragma once
|
||||
|
||||
#include <IGeneralMemoryHeap.h> // <> required for Interfuscator
|
||||
#include "CryLegacyAllocator.h"
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Convenient iteration macros
|
||||
@@ -91,8 +91,6 @@ Public classes:
|
||||
Array<T, [I, STORAGE]>
|
||||
StaticArray<T, nSIZE, [I]>
|
||||
DynArray<T, [I, STORAGE, ALLOC]>
|
||||
FastDynArray<T, [I]>
|
||||
FixedDynArray<T, [I]>
|
||||
StaticDynArray<T, nSIZE, [I]>
|
||||
|
||||
Support classes are placed in namespaces NArray and NAlloc to reduce global name usage.
|
||||
@@ -612,13 +610,6 @@ namespace NAlloc
|
||||
//---------------------------------------------------------------------------
|
||||
// Allocators for DynArray.
|
||||
|
||||
// No reallocation, for use in FixedDynArray
|
||||
struct NullAlloc
|
||||
{
|
||||
static void* alloc(void* pMem, [[maybe_unused]] size_t& nSize, [[maybe_unused]] size_t nAlign, [[maybe_unused]] bool bSlack = false)
|
||||
{ return pMem; }
|
||||
};
|
||||
|
||||
// Standard CryModule memory allocation, using aligned versions
|
||||
struct ModuleAlloc
|
||||
{
|
||||
@@ -655,128 +646,15 @@ namespace NAlloc
|
||||
|
||||
// Standard allocator for DynArray stores a compatibility pointer in the memory
|
||||
typedef AllocCompatible<ModuleAlloc> StandardAlloc;
|
||||
|
||||
// Allocator using specific heaps
|
||||
struct GeneralHeapAlloc
|
||||
: ModuleAlloc
|
||||
{
|
||||
IGeneralMemoryHeap* m_pHeap;
|
||||
|
||||
GeneralHeapAlloc()
|
||||
: m_pHeap(0) {}
|
||||
|
||||
explicit GeneralHeapAlloc(IGeneralMemoryHeap* pHeap)
|
||||
: m_pHeap(pHeap) {}
|
||||
|
||||
void* alloc(void* pMem, size_t& nSize, size_t nAlign, bool bSlack = false) const
|
||||
{
|
||||
if (m_pHeap)
|
||||
{
|
||||
if (pMem)
|
||||
{
|
||||
if (!nSize)
|
||||
{
|
||||
// Dealloc
|
||||
m_pHeap->Free(pMem);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else if (nSize)
|
||||
{
|
||||
// Alloc
|
||||
if (bSlack)
|
||||
{
|
||||
nSize = realloc_size(nSize);
|
||||
}
|
||||
return m_pHeap->Memalign(nAlign, nSize, "");
|
||||
}
|
||||
}
|
||||
|
||||
return ModuleAlloc::alloc(pMem, nSize, nAlign, bSlack);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Storage schemes for dynamic arrays
|
||||
namespace NArray
|
||||
{
|
||||
/*---------------------------------------------------------------------------
|
||||
// STORAGE prototype for DynArray<T,I,STORAGE>
|
||||
// Extends ArrayStorage with resizing functionality.
|
||||
|
||||
struct DynStorage
|
||||
{
|
||||
struct Store<T,I>: ArrayStorage<T,I>::Store
|
||||
{
|
||||
I capacity() const;
|
||||
size_t get_alloc_size() const;
|
||||
void resize_raw( I new_size, bool allow_slack );
|
||||
};
|
||||
};
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// FastDynStorage: STORAGE scheme for DynArray<T,I,STORAGE>.
|
||||
// Simple extension to ArrayStorage: size & capacity fields are inline, 3 words storage, fast access.
|
||||
|
||||
template<class A = NAlloc::StandardAlloc>
|
||||
struct FastDynStorage
|
||||
{
|
||||
template<class T, class I>
|
||||
struct Store
|
||||
: private A
|
||||
, public ArrayStorage::Store<T, I>
|
||||
{
|
||||
typedef ArrayStorage::Store<T, I> super_type;
|
||||
|
||||
using super_type::m_aElems;
|
||||
using super_type::m_nCount;
|
||||
|
||||
// Construction.
|
||||
Store()
|
||||
: m_nCapacity(0)
|
||||
{
|
||||
}
|
||||
|
||||
Store(const A& a)
|
||||
: A(a)
|
||||
, m_nCapacity(0)
|
||||
{
|
||||
}
|
||||
|
||||
I capacity() const
|
||||
{ return m_nCapacity; }
|
||||
|
||||
size_t get_alloc_size() const
|
||||
{ return NAlloc::get_alloc_size(*this, m_aElems, capacity() * sizeof(T), alignof(T)); }
|
||||
|
||||
void resize_raw(I new_size, bool allow_slack = false)
|
||||
{
|
||||
if (allow_slack ? new_size > capacity() : new_size != capacity())
|
||||
{
|
||||
m_nCapacity = new_size;
|
||||
m_aElems = NAlloc::reallocate(static_cast<A&>(*this), m_aElems, m_nCount, m_nCapacity, alignof(T), allow_slack);
|
||||
}
|
||||
set_size(new_size);
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
I m_nCapacity;
|
||||
|
||||
void set_size(I new_size)
|
||||
{
|
||||
assert(new_size >= 0 && new_size <= capacity());
|
||||
m_nCount = new_size;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// SmallDynStorage: STORAGE scheme for DynArray<T,I,STORAGE,ALLOC>.
|
||||
// Array is just a single pointer, size and capacity information stored before the array data.
|
||||
// Slightly slower than FastDynStorage, optimal for saving space, especially when array likely to be empty.
|
||||
|
||||
template<class A = NAlloc::StandardAlloc>
|
||||
struct SmallDynStorage
|
||||
@@ -1459,35 +1337,6 @@ struct LegacyDynArray
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
template<class T, class I = int, class A = NAlloc::StandardAlloc>
|
||||
struct FastDynArray
|
||||
: DynArray< T, I, NArray::FastDynStorage<A> >
|
||||
{
|
||||
};
|
||||
|
||||
template<class T, class I = int>
|
||||
struct FixedDynArray
|
||||
: LegacyDynArray< T, I, NArray::FastDynStorage<NAlloc::NullAlloc> >
|
||||
{
|
||||
typedef NArray::ArrayStorage::Store<T, I> S;
|
||||
|
||||
void set(void* elems, I mem_size)
|
||||
{
|
||||
this->m_aElems = (T*)elems;
|
||||
this->m_nCapacity = mem_size / sizeof(T);
|
||||
this->m_nCount = 0;
|
||||
}
|
||||
void set(Array<T, I> array)
|
||||
{
|
||||
this->m_aElems = array.begin();
|
||||
this->m_nCapacity = array.size();
|
||||
this->m_nCount = 0;
|
||||
}
|
||||
};
|
||||
|
||||
template<class T, int nSIZE, class I = int>
|
||||
struct StaticDynArray
|
||||
: LegacyDynArray< T, I, NArray::StaticDynStorage<nSIZE> >
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
#ifndef CRYINCLUDE_CRYCOMMON_ARRAY2D_H
|
||||
#define CRYINCLUDE_CRYCOMMON_ARRAY2D_H
|
||||
#pragma once
|
||||
|
||||
// Dynamic replacement for static 2d array
|
||||
template <class T>
|
||||
struct Array2d
|
||||
{
|
||||
Array2d()
|
||||
{
|
||||
m_nSize = 0;
|
||||
m_pData = 0;
|
||||
}
|
||||
|
||||
int GetSize() const { return m_nSize; }
|
||||
int GetDataSize() const { return m_nSize * m_nSize * sizeof(T); }
|
||||
|
||||
T* GetData() { return m_pData; }
|
||||
|
||||
T* GetDataEnd() { return &m_pData[m_nSize * m_nSize]; }
|
||||
|
||||
void SetData(T* pData, int nSize)
|
||||
{
|
||||
Allocate(nSize);
|
||||
memcpy(m_pData, pData, nSize * nSize * sizeof(T));
|
||||
}
|
||||
|
||||
void Allocate(int nSize)
|
||||
{
|
||||
if (m_nSize == nSize)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
delete [] m_pData;
|
||||
|
||||
m_nSize = nSize;
|
||||
m_pData = new T [nSize * nSize];
|
||||
memset(m_pData, 0, nSize * nSize * sizeof(T));
|
||||
}
|
||||
|
||||
~Array2d()
|
||||
{
|
||||
delete [] m_pData;
|
||||
}
|
||||
|
||||
void Reset()
|
||||
{
|
||||
delete [] m_pData;
|
||||
m_pData = 0;
|
||||
m_nSize = 0;
|
||||
}
|
||||
|
||||
T* m_pData;
|
||||
int m_nSize;
|
||||
|
||||
T* operator [] (const int& nPos) const
|
||||
{
|
||||
assert(nPos >= 0 && nPos < m_nSize);
|
||||
return &m_pData[nPos * m_nSize];
|
||||
}
|
||||
|
||||
Array2d& operator = (const Array2d& other)
|
||||
{
|
||||
Allocate(other.m_nSize);
|
||||
memcpy(m_pData, other.m_pData, m_nSize * m_nSize * sizeof(T));
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // CRYINCLUDE_CRYCOMMON_ARRAY2D_H
|
||||
@@ -1207,23 +1207,4 @@ protected:
|
||||
uint nPrefixLength;
|
||||
};
|
||||
|
||||
|
||||
// Define an irregular enum with TypeInfo
|
||||
|
||||
#define DEFINE_ENUM_VALS(EType, TInt, ...) \
|
||||
struct EType \
|
||||
{ \
|
||||
enum E { __VA_ARGS__ }; \
|
||||
DEFINE_ENUM_VALUE(EType, E, TInt) \
|
||||
ILINE static uint Count() { return TypeInfo().Count(); } \
|
||||
static const CEnumInfo<TInt>& TypeInfo() { \
|
||||
static char enum_str[] = #__VA_ARGS__; \
|
||||
static LegacyDynArray<CEnumDef::SElem> Elems; \
|
||||
CEnumDef::SInit::Init(Elems); \
|
||||
CEnumDef::SInit __VA_ARGS__; \
|
||||
static CEnumInfo<TInt> info( #EType, Elems, enum_str); \
|
||||
return info; \
|
||||
} \
|
||||
};
|
||||
|
||||
#endif // CRYINCLUDE_CRYCOMMON_CRYCUSTOMTYPES_H
|
||||
|
||||
@@ -1,309 +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.
|
||||
|
||||
/*
|
||||
CryFixedArray.h
|
||||
- no longer support being created on the stack (since the alignment code was changed to support adding CryFixedArrays into stl::vectors)
|
||||
- performs construction or destruction only on elements as they become live/dead or are moved around during the RemoveAt() reshuffle
|
||||
- just a range checked equivelant of a standard array
|
||||
- for now only allows push_back() population of array
|
||||
- if using as a class member variable ensure to put the CryFixedArrays after all other member variables at the bottom of your class
|
||||
to ensure all members stay on the same cacheline
|
||||
*/
|
||||
|
||||
#ifndef CRYINCLUDE_CRYCOMMON_CRYFIXEDARRAY_H
|
||||
#define CRYINCLUDE_CRYCOMMON_CRYFIXEDARRAY_H
|
||||
#pragma once
|
||||
|
||||
#define DEBUG_CRYFIXED_ARRAY _DEBUG
|
||||
|
||||
template<
|
||||
unsigned int align >
|
||||
struct CryFixedArrayDatum
|
||||
{
|
||||
};
|
||||
|
||||
template<>
|
||||
struct CryFixedArrayDatum< 4 >
|
||||
{
|
||||
typedef uint32 TDatum;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct CryFixedArrayDatum< 8 >
|
||||
{
|
||||
typedef uint64 TDatum;
|
||||
};
|
||||
|
||||
template <class T, unsigned int N>
|
||||
class CryFixedArray
|
||||
{
|
||||
protected:
|
||||
enum
|
||||
{
|
||||
ALIGN = MAX(alignof(T), sizeof(unsigned int))
|
||||
}; // ALIGN at least sizeof(unsigned int)
|
||||
|
||||
typedef typename CryFixedArrayDatum< ALIGN >::TDatum TDatum;
|
||||
|
||||
uint32 m_curSize[ sizeof (TDatum) / sizeof (uint32) ]; // Padded for alignment
|
||||
|
||||
TDatum m_data[(N * sizeof(T) + (sizeof(TDatum) - 1)) / sizeof(TDatum)]; // simple debugging - in VS: just add to a watch as "(T*)m_data, <N>" to see the array. ie. "(int*)m_data, 5" - the size of the array has to be a literal int
|
||||
|
||||
public:
|
||||
typedef T* iterator;
|
||||
typedef const T* const_iterator;
|
||||
|
||||
CryFixedArray()
|
||||
{
|
||||
#if DEBUG_CRYFIXED_ARRAY
|
||||
if (((uintptr_t)m_data & (ALIGN - 1)) != 0)
|
||||
{
|
||||
CryLogAlways("CryFixedArray() error - data is not aligned. This may happen if you are creating a CryFixedArray on the stack, which isn't supported.");
|
||||
}
|
||||
#endif
|
||||
CRY_ASSERT_MESSAGE(((uintptr_t)m_data & (ALIGN - 1)) == 0, "CryFixedArray() error - data is not aligned. This may happen if you are creating a CryFixedArray on the stack, which isn't supported.");
|
||||
m_curSize[0] = 0;
|
||||
}
|
||||
|
||||
CryFixedArray(const CryFixedArray& other)
|
||||
{
|
||||
// doesn't require clear() this is newly constructed
|
||||
m_curSize[0] = other.m_curSize[0];
|
||||
|
||||
int size = m_curSize[0];
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
T& ele = operator[](i);
|
||||
const T& otherEle = other.operator[](i);
|
||||
new (&ele)T(otherEle); // placement new
|
||||
}
|
||||
}
|
||||
|
||||
CryFixedArray& operator=(const CryFixedArray& other)
|
||||
{
|
||||
if (this != &other)
|
||||
{
|
||||
clear(); // necessary to avoid potentially leaking within existing elements
|
||||
|
||||
m_curSize[0] = other.m_curSize[0];
|
||||
|
||||
int size = m_curSize[0];
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
T& ele = operator[](i);
|
||||
const T& otherEle = other.operator[](i);
|
||||
//ele = otherEle; // assignment instead of placement new to keep type of operation consistent - this cannot be done until this is rewritten to assign over existing elements and deconstruct any left overs, and placement new any new elements
|
||||
new (&ele)T(otherEle); // placement new
|
||||
}
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
virtual ~CryFixedArray()
|
||||
{
|
||||
clear();
|
||||
}
|
||||
|
||||
ILINE T& at(unsigned int i)
|
||||
{
|
||||
#if DEBUG_CRYFIXED_ARRAY
|
||||
if (i < size())
|
||||
{
|
||||
return alias_cast<T*>(m_data)[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
// Log is required now as its possible to turn off assert output logging, yet you really want to know if this is happening!!!!
|
||||
CryLogAlways("CryFixedArray::at(i=%d) failed as i is out of range of curSize=%d (maxSize=%d) - forcing a crash", i, m_curSize[0], N);
|
||||
CRY_ASSERT_MESSAGE(0, string().Format("CryFixedArray::at(i=%d) failed as i is out of range of curSize=%d (maxSize=%d)", i, m_curSize[0], N));
|
||||
abort(); // better option than dereferncing a nullptr?
|
||||
}
|
||||
#else
|
||||
return alias_cast<T*>(m_data)[i];
|
||||
#endif
|
||||
}
|
||||
|
||||
ILINE const T& at(unsigned int i) const
|
||||
{
|
||||
#if DEBUG_CRYFIXED_ARRAY
|
||||
if (i < size())
|
||||
{
|
||||
return alias_cast<const T*>(m_data)[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
// Log is required now as its possible to turn off assert output logging, yet you really want to know if this is happening!!!!
|
||||
CryLogAlways("CryFixedArray::at(i=%d) failed as i is out of range of curSize=%d (maxSize=%d) - forcing a crash", i, m_curSize[0], N);
|
||||
CRY_ASSERT_MESSAGE(0, string().Format("CryFixedArray::at(i=%d) failed as i is out of range of curSize=%d (maxSize=%d)", i, m_curSize[0], N));
|
||||
abort(); // better option than dereferncing a nullptr?
|
||||
}
|
||||
#else
|
||||
return alias_cast<const T*>(m_data)[i];
|
||||
#endif
|
||||
}
|
||||
|
||||
ILINE const T& operator[](unsigned int i) const
|
||||
{
|
||||
return at(i);
|
||||
}
|
||||
|
||||
ILINE T& operator[](unsigned int i)
|
||||
{
|
||||
return at(i);
|
||||
}
|
||||
|
||||
ILINE void clear()
|
||||
{
|
||||
for (uint32 i = 0; i < m_curSize[0]; i++)
|
||||
{
|
||||
T& ele = operator[](i);
|
||||
ele.~T();
|
||||
}
|
||||
m_curSize[0] = 0;
|
||||
#if DEBUG_CRYFIXED_ARRAY
|
||||
memset(m_data, 0, N * sizeof(T));
|
||||
#endif
|
||||
}
|
||||
|
||||
ILINE iterator begin()
|
||||
{
|
||||
return alias_cast<T*>(m_data);
|
||||
}
|
||||
ILINE const_iterator begin() const
|
||||
{
|
||||
return alias_cast<T*>(m_data);
|
||||
}
|
||||
ILINE iterator end()
|
||||
{
|
||||
return &(alias_cast<T*>(m_data))[m_curSize[0]];
|
||||
}
|
||||
ILINE const_iterator end() const
|
||||
{
|
||||
return &(alias_cast<T*>(m_data))[m_curSize[0]];
|
||||
}
|
||||
|
||||
ILINE unsigned int max_size() const { return N; }
|
||||
ILINE unsigned int size() const { return m_curSize[0]; }
|
||||
ILINE bool empty() const { return size() == 0; }
|
||||
ILINE unsigned int isfull() const { return (size() == max_size()); }
|
||||
|
||||
// allows you to push back default constructed elements
|
||||
ILINE void push_back ()
|
||||
{
|
||||
unsigned int curSize = size();
|
||||
if (curSize < N)
|
||||
{
|
||||
T* newT = &(alias_cast<T*>(m_data))[curSize];
|
||||
new (newT) T();
|
||||
|
||||
m_curSize[0]++;
|
||||
}
|
||||
else
|
||||
{
|
||||
CryLogAlways("CryFixedArray::push_back() failing as array of size %u is full - NOT adding element", N);
|
||||
CRY_ASSERT_TRACE(0, ("CryFixedArray::push_back() failing as array of size %u is full - NOT adding element", N));
|
||||
}
|
||||
}
|
||||
|
||||
ILINE void push_back (const T& ele)
|
||||
{
|
||||
unsigned int curSize = size();
|
||||
if (curSize < N)
|
||||
{
|
||||
T* newT = &(alias_cast<T*>(m_data))[curSize];
|
||||
new (newT) T(ele); // placement new copy constructor - setup vtable etc
|
||||
|
||||
m_curSize[0]++;
|
||||
}
|
||||
else
|
||||
{
|
||||
CryLogAlways("CryFixedArray::push_back() failing as array of size %u is full - NOT adding element", N);
|
||||
CRY_ASSERT_TRACE(0, ("CryFixedArray::push_back() failing as array of size %u is full - NOT adding element", N));
|
||||
}
|
||||
}
|
||||
|
||||
ILINE void pop_back()
|
||||
{
|
||||
if (size() > 0)
|
||||
{
|
||||
back().~T(); // destruct back
|
||||
m_curSize[0]--;
|
||||
}
|
||||
else
|
||||
{
|
||||
CryLogAlways("CryFixedArray::pop_back() failed as array is empty");
|
||||
CRY_ASSERT_MESSAGE(0, "CryFixedArray::pop_back() failed as array is empty");
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
ILINE const T& backEx() const
|
||||
{
|
||||
#if DEBUG_CRYFIXED_ARRAY
|
||||
if (m_curSize[0] > 0)
|
||||
{
|
||||
return (alias_cast<T*>(m_data))[m_curSize[0] - 1];
|
||||
}
|
||||
else
|
||||
{
|
||||
CryLogAlways("CryFixedArray::back() failed as array is empty");
|
||||
CRY_ASSERT_MESSAGE(0, "CryFixedArray::back() failed as array is empty");
|
||||
abort(); // better option than dereferncing a nullptr?
|
||||
}
|
||||
#else
|
||||
return (alias_cast<T*>(m_data))[m_curSize[0] - 1];
|
||||
#endif
|
||||
}
|
||||
|
||||
public:
|
||||
ILINE const T& back() const
|
||||
{
|
||||
return backEx();
|
||||
}
|
||||
|
||||
ILINE T& back()
|
||||
{
|
||||
return (T&)(backEx());
|
||||
}
|
||||
|
||||
// if returns true then an element has been swapped into the new element[i] and as such may need updating to reflect its new location in memory
|
||||
ILINE bool removeAt(uint32 i)
|
||||
{
|
||||
bool swappedElement = false;
|
||||
|
||||
if (i < m_curSize[0])
|
||||
{
|
||||
if (i != m_curSize[0] - 1)
|
||||
{
|
||||
operator[](i).~T(); // destruct element being removed
|
||||
|
||||
// copy back() into element i
|
||||
T* newT = &(alias_cast<T*>(m_data))[i];
|
||||
new (newT) T(back()); // placement new copy constructor - setup vtable etc
|
||||
|
||||
swappedElement = true;
|
||||
}
|
||||
pop_back(); // will destruct back()
|
||||
}
|
||||
else
|
||||
{
|
||||
CryLog("CryFixedArray::removeAt() failed as i=%d is out of range of curSize=%d", i, m_curSize[0]);
|
||||
CRY_ASSERT_MESSAGE(0, string().Format("CryFixedArray::removeAt() failed as i=%d is out of range of curSize=%d", i, m_curSize[0]));
|
||||
}
|
||||
return swappedElement;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // CRYINCLUDE_CRYCOMMON_CRYFIXEDARRAY_H
|
||||
@@ -2019,21 +2019,6 @@ inline CryStackStringT<T, S> CryStackStringT<T, S>::Tokenize(const_str charSet,
|
||||
return CryStackStringT<T, S>();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Specialization providing efficient move semantics for array classes.
|
||||
template <class T, size_t S>
|
||||
bool raw_movable(const CryStackStringT<T, S>& str)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
template <class T, size_t S>
|
||||
void move_init(CryStackStringT<T, S>& dest, CryStackStringT<T, S>& source)
|
||||
{
|
||||
dest.move(source);
|
||||
}
|
||||
|
||||
|
||||
#if defined(_RELEASE)
|
||||
#define ASSERT_LEN (void)(0)
|
||||
#define ASSERT_WLEN (void)(0)
|
||||
|
||||
@@ -1,274 +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.
|
||||
/*
|
||||
* Part of this code coming from STLPort alloc
|
||||
*
|
||||
* Copyright (c) 1996,1997
|
||||
* Silicon Graphics Computer Systems, Inc.
|
||||
*
|
||||
* Copyright (c) 1997
|
||||
* Moscow Center for SPARC Technology
|
||||
*
|
||||
* Copyright (c) 1999
|
||||
* Boris Fomitchev
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef CRYINCLUDE_CRYCOMMON_CRYMEMORYALLOCATOR_H
|
||||
#define CRYINCLUDE_CRYCOMMON_CRYMEMORYALLOCATOR_H
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#define CRY_STL_ALLOC
|
||||
|
||||
#if defined(LINUX64) || defined(APPLE)
|
||||
#include <sys/mman.h>
|
||||
#endif
|
||||
|
||||
#include <string.h> // memset
|
||||
|
||||
// DON't USE _MAX_BYTES as identifier for Max Bytes, STLPORT defines the same enum
|
||||
// this leads to situation where the wrong enum is choosen in different compilation units
|
||||
// which in case leads to errors(The stlport one is defined as 128)
|
||||
#if defined (__OS400__) || defined (_WIN64) || defined(MAC) || defined(LINUX64)
|
||||
enum {_ALIGNMENT = 16, _ALIGN_SHIFT = 4, __MAX_BYTES = 512, NFREELISTS=32, ADDRESSSPACE = 2 * 1024 * 1024, ADDRESS_SHIFT = 40};
|
||||
#else
|
||||
enum {_ALIGNMENT = 8, _ALIGN_SHIFT = 3, __MAX_BYTES = 512, NFREELISTS = 64, ADDRESSSPACE = 2 * 1024 * 1024, ADDRESS_SHIFT = 20};
|
||||
#endif /* __OS400__ */
|
||||
|
||||
#define CRY_MEMORY_ALLOCATOR
|
||||
|
||||
#define S_FREELIST_INDEX(__bytes) ((__bytes - size_t(1)) >> (int)_ALIGN_SHIFT)
|
||||
|
||||
class _Node_alloc_obj {
|
||||
public:
|
||||
_Node_alloc_obj * _M_next;
|
||||
};
|
||||
|
||||
#if defined (_WIN64) || defined(APPLE) || defined(LINUX64)
|
||||
#define MASK_COUNT 0x000000FFFFFFFFFF
|
||||
#define MASK_VALUE 0xFFFFFF
|
||||
#define MASK_NEXT 0xFFFFFFFFFF000000
|
||||
#define MASK_SHIFT 24
|
||||
#else
|
||||
#define MASK_COUNT 0x000FFFFF
|
||||
#define MASK_VALUE 0xFFF
|
||||
#define MASK_NEXT 0xFFFFF000
|
||||
#define MASK_SHIFT 12
|
||||
#endif
|
||||
|
||||
#define NUM_OBJ 64
|
||||
|
||||
struct _Obj_Address {
|
||||
// short int * _M_next;
|
||||
// short int
|
||||
size_t GetNext(size_t pBase) {
|
||||
return pBase +(size_t)(_M_value >> MASK_SHIFT);
|
||||
}
|
||||
|
||||
//size_t GetNext() {
|
||||
// return (size_t)(_M_value >> 20);
|
||||
//}
|
||||
|
||||
size_t GetCount() {
|
||||
return _M_value & MASK_VALUE;
|
||||
}
|
||||
|
||||
void SetNext(/*void **/size_t pNext) {
|
||||
_M_value &= MASK_COUNT;
|
||||
_M_value |= (size_t)pNext << MASK_SHIFT;
|
||||
}
|
||||
|
||||
void SetCount(size_t count) {
|
||||
_M_value &= MASK_NEXT;
|
||||
_M_value |= count & MASK_VALUE;
|
||||
}
|
||||
private:
|
||||
size_t _M_value;
|
||||
// short int * _M_end;
|
||||
};
|
||||
|
||||
//struct _Node_Allocations_Tree {
|
||||
// enum { eListSize = _Size / (sizeof(void *) * _Num_obj); };
|
||||
// _Obj_Address * _M_allocations_list[eListSize];
|
||||
// int _M_Count;
|
||||
// _Node_Allocations_Tree * _M_next;
|
||||
//};
|
||||
|
||||
template<int _Size>
|
||||
struct _Node_Allocations_Tree {
|
||||
//Pointer to the end of the memory block
|
||||
char *_M_end;
|
||||
|
||||
enum { eListSize = _Size / (sizeof(void *) * NUM_OBJ) };
|
||||
// List of allocations
|
||||
_Obj_Address _M_allocations_list[eListSize];
|
||||
int _M_allocations_count;
|
||||
//Pointer to the next memory block
|
||||
_Node_Allocations_Tree *_M_Block_next;
|
||||
};
|
||||
|
||||
|
||||
struct _Node_alloc_Mem_block_Huge {
|
||||
//Pointer to the end of the memory block
|
||||
char *_M_end;
|
||||
// number
|
||||
int _M_count;
|
||||
_Node_alloc_Mem_block_Huge *_M_next;
|
||||
};
|
||||
|
||||
template<int _Size>
|
||||
struct _Node_alloc_Mem_block {
|
||||
//Pointer to the end of the memory block
|
||||
char *_M_end;
|
||||
//Pointer to the next memory block
|
||||
_Node_alloc_Mem_block_Huge *_M_huge_block;
|
||||
_Node_alloc_Mem_block *_M_next;
|
||||
};
|
||||
|
||||
|
||||
// Allocators!
|
||||
enum EAllocFreeType
|
||||
{
|
||||
eCryDefaultMalloc,
|
||||
eCryMallocCryFreeCRTCleanup,
|
||||
};
|
||||
|
||||
template <EAllocFreeType type>
|
||||
struct Node_Allocator
|
||||
{
|
||||
inline void * pool_alloc(size_t size)
|
||||
{
|
||||
return CryModuleMalloc(size);
|
||||
};
|
||||
inline void * cleanup_alloc(size_t size)
|
||||
{
|
||||
return CryCrtMalloc(size);
|
||||
};
|
||||
inline size_t pool_free(void * ptr)
|
||||
{
|
||||
CryModuleFree(ptr);
|
||||
return 0;
|
||||
};
|
||||
inline void cleanup_free(void * ptr)
|
||||
{
|
||||
CryCrtFree(ptr);
|
||||
};
|
||||
|
||||
inline size_t getSize(void * ptr)
|
||||
{
|
||||
return CryCrtSize(ptr);
|
||||
}
|
||||
};
|
||||
|
||||
// partial
|
||||
template <>
|
||||
struct Node_Allocator<eCryDefaultMalloc>
|
||||
{
|
||||
inline void * pool_alloc(size_t size)
|
||||
{
|
||||
return CryCrtMalloc(size);
|
||||
};
|
||||
inline void * cleanup_alloc(size_t size)
|
||||
{
|
||||
return CryCrtMalloc(size);
|
||||
};
|
||||
inline size_t pool_free(void * ptr)
|
||||
{
|
||||
size_t n = CryCrtSize(ptr);
|
||||
CryCrtFree(ptr);
|
||||
return n;
|
||||
};
|
||||
inline void cleanup_free(void * ptr)
|
||||
{
|
||||
CryCrtFree(ptr);
|
||||
};
|
||||
inline size_t getSize(void * ptr)
|
||||
{
|
||||
return CryCrtSize(ptr);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// partial
|
||||
template <>
|
||||
struct Node_Allocator<eCryMallocCryFreeCRTCleanup>
|
||||
{
|
||||
inline void * pool_alloc(size_t size)
|
||||
{
|
||||
return CryCrtMalloc(size);
|
||||
};
|
||||
inline void * cleanup_alloc(size_t size)
|
||||
{
|
||||
return CryCrtMalloc(size);
|
||||
};
|
||||
inline size_t pool_free(void * ptr)
|
||||
{
|
||||
return CryCrtFree(ptr);
|
||||
};
|
||||
inline void cleanup_free(void * ptr)
|
||||
{
|
||||
CryCrtFree(ptr);
|
||||
};
|
||||
inline size_t getSize(void * ptr)
|
||||
{
|
||||
return CryCrtSize(ptr);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#include "MultiThread.h"
|
||||
|
||||
struct InternalCriticalSectionDummy {
|
||||
char padding[128];
|
||||
} ;
|
||||
|
||||
inline void CryInternalCreateCriticalSection(void * pCS)
|
||||
{
|
||||
CryCreateCriticalSectionInplace(pCS);
|
||||
}
|
||||
|
||||
// A class that forward node allocator calls directly to CRT
|
||||
struct cry_crt_node_allocator
|
||||
{
|
||||
static const size_t MaxSize = ~0;
|
||||
|
||||
static void *alloc(size_t __n)
|
||||
{
|
||||
return CryCrtMalloc(__n);
|
||||
}
|
||||
static size_t dealloc( void *p )
|
||||
{
|
||||
return CryCrtFree(p);
|
||||
}
|
||||
static void *allocate(size_t __n)
|
||||
{
|
||||
return alloc(__n);
|
||||
}
|
||||
static void *allocate(size_t __n, [[maybe_unused]] size_t nAlignment)
|
||||
{
|
||||
return alloc(__n);
|
||||
}
|
||||
static size_t deallocate(void *__p)
|
||||
{
|
||||
return dealloc(__p);
|
||||
}
|
||||
void cleanup() {}
|
||||
};
|
||||
|
||||
|
||||
//#endif // WIN32|DEBUG
|
||||
|
||||
#endif // CRYINCLUDE_CRYCOMMON_CRYMEMORYALLOCATOR_H
|
||||
@@ -1,295 +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 : Defines functions for CryEngine custom memory manager.
|
||||
|
||||
#pragma once
|
||||
|
||||
// Section dictionary
|
||||
#if defined(AZ_RESTRICTED_PLATFORM)
|
||||
#define CRYMEMORYMANAGER_H_SECTION_TRAITS 1
|
||||
#define CRYMEMORYMANAGER_H_SECTION_ALLOCPOLICY 2
|
||||
#endif
|
||||
|
||||
#include <AzCore/PlatformRestrictedFileDef.h>
|
||||
// Traits
|
||||
#if defined(AZ_RESTRICTED_PLATFORM)
|
||||
#define AZ_RESTRICTED_SECTION CRYMEMORYMANAGER_H_SECTION_TRAITS
|
||||
#include AZ_RESTRICTED_FILE(CryMemoryManager_h)
|
||||
#else
|
||||
#if !defined(APPLE)
|
||||
#define CRYMEMORYMANAGER_H_TRAIT_INCLUDE_MALLOC_H 1
|
||||
#endif
|
||||
#if defined(LINUX) || defined(APPLE)
|
||||
#define CRYMEMORYMANAGER_H_TRAIT_INCLUDE_NEW_NOT_NEW_H 1
|
||||
#endif
|
||||
#if !defined(LINUX) && !defined(APPLE)
|
||||
#define CRYMEMORYMANAGER_H_TRAIT_INCLUDE_CRTDBG_H 1
|
||||
#endif
|
||||
#if !defined(APPLE)
|
||||
#define CRYMEMORYMANAGER_H_TRAIT_USE_CRTCHECKMEMORY 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "platform.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <algorithm>
|
||||
|
||||
#if defined(APPLE) || defined(ANDROID)
|
||||
#include <AzCore/Memory/OSAllocator.h> // memalign
|
||||
#endif // defined(APPLE)
|
||||
|
||||
#ifndef STLALLOCATOR_CLEANUP
|
||||
#define STLALLOCATOR_CLEANUP
|
||||
#endif
|
||||
|
||||
#define _CRY_DEFAULT_MALLOC_ALIGNMENT 4
|
||||
|
||||
#if CRYMEMORYMANAGER_H_TRAIT_INCLUDE_MALLOC_H
|
||||
#include <malloc.h>
|
||||
#endif
|
||||
|
||||
#if defined(__cplusplus)
|
||||
#if CRYMEMORYMANAGER_H_TRAIT_INCLUDE_NEW_NOT_NEW_H
|
||||
#include <new>
|
||||
#else
|
||||
#include <new.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef CRYSYSTEM_EXPORTS
|
||||
#define CRYMEMORYMANAGER_API DLL_EXPORT
|
||||
#else
|
||||
#define CRYMEMORYMANAGER_API DLL_IMPORT
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#if defined(_DEBUG) && CRYMEMORYMANAGER_H_TRAIT_INCLUDE_CRTDBG_H
|
||||
#include <crtdbg.h>
|
||||
#endif //_DEBUG
|
||||
|
||||
#include "LegacyAllocator.h"
|
||||
|
||||
namespace CryMemory
|
||||
{
|
||||
// checks if the heap is valid in debug; in release, this function shouldn't be called
|
||||
// returns non-0 if it's valid and 0 if not valid
|
||||
ILINE int IsHeapValid()
|
||||
{
|
||||
#if (defined(_DEBUG) && !defined(RELEASE_RUNTIME) && CRYMEMORYMANAGER_H_TRAIT_USE_CRTCHECKMEMORY) || (defined(DEBUG_MEMORY_MANAGER))
|
||||
return _CrtCheckMemory();
|
||||
#else
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void* AllocPages(size_t size)
|
||||
{
|
||||
const size_t alignment = AZ_PAGE_SIZE;
|
||||
void* ret = AZ::AllocatorInstance<AZ::LegacyAllocator>::Get().Allocate(size, alignment, 0, "AllocPages", __FILE__, __LINE__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
inline void FreePages(void* p, size_t size)
|
||||
{
|
||||
const size_t alignment = AZ_PAGE_SIZE;
|
||||
AZ::AllocatorInstance<AZ::LegacyAllocator>::Get().DeAllocate(p, size, alignment);
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif //__cplusplus
|
||||
|
||||
struct ICustomMemoryHeap;
|
||||
class IGeneralMemoryHeap;
|
||||
class IPageMappingHeap;
|
||||
class IMemoryAddressRange;
|
||||
|
||||
// Description:
|
||||
// Interfaces that allow access to the CryEngine memory manager.
|
||||
struct IMemoryManager
|
||||
{
|
||||
typedef unsigned char HeapHandle;
|
||||
enum
|
||||
{
|
||||
BAD_HEAP_HANDLE = 0xFF
|
||||
};
|
||||
|
||||
struct SProcessMemInfo
|
||||
{
|
||||
uint64 PageFaultCount;
|
||||
uint64 PeakWorkingSetSize;
|
||||
uint64 WorkingSetSize;
|
||||
uint64 QuotaPeakPagedPoolUsage;
|
||||
uint64 QuotaPagedPoolUsage;
|
||||
uint64 QuotaPeakNonPagedPoolUsage;
|
||||
uint64 QuotaNonPagedPoolUsage;
|
||||
uint64 PagefileUsage;
|
||||
uint64 PeakPagefileUsage;
|
||||
|
||||
uint64 TotalPhysicalMemory;
|
||||
int64 FreePhysicalMemory;
|
||||
|
||||
uint64 TotalVideoMemory;
|
||||
int64 FreeVideoMemory;
|
||||
};
|
||||
|
||||
enum EAllocPolicy
|
||||
{
|
||||
eapDefaultAllocator,
|
||||
eapPageMapped,
|
||||
eapCustomAlignment,
|
||||
#if defined(AZ_RESTRICTED_PLATFORM)
|
||||
#define AZ_RESTRICTED_SECTION CRYMEMORYMANAGER_H_SECTION_ALLOCPOLICY
|
||||
#include AZ_RESTRICTED_FILE(CryMemoryManager_h)
|
||||
#endif
|
||||
};
|
||||
|
||||
virtual ~IMemoryManager(){}
|
||||
|
||||
virtual bool GetProcessMemInfo(SProcessMemInfo& minfo) = 0;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Heap Tracing API
|
||||
virtual HeapHandle TraceDefineHeap(const char* heapName, size_t size, const void* pBase) = 0;
|
||||
virtual void TraceHeapAlloc(HeapHandle heap, void* mem, size_t size, size_t blockSize, const char* sUsage, const char* sNameHint = 0) = 0;
|
||||
virtual void TraceHeapFree(HeapHandle heap, void* mem, size_t blockSize) = 0;
|
||||
virtual void TraceHeapSetColor(uint32 color) = 0;
|
||||
virtual uint32 TraceHeapGetColor() = 0;
|
||||
virtual void TraceHeapSetLabel(const char* sLabel) = 0;
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Create an instance of ICustomMemoryHeap
|
||||
virtual ICustomMemoryHeap* const CreateCustomMemoryHeapInstance(EAllocPolicy const eAllocPolicy) = 0;
|
||||
virtual IGeneralMemoryHeap* CreateGeneralExpandingMemoryHeap(size_t upperLimit, size_t reserveSize, const char* sUsage) = 0;
|
||||
virtual IGeneralMemoryHeap* CreateGeneralMemoryHeap(void* base, size_t sz, const char* sUsage) = 0;
|
||||
|
||||
virtual IMemoryAddressRange* ReserveAddressRange(size_t capacity, const char* sName) = 0;
|
||||
virtual IPageMappingHeap* CreatePageMappingHeap(size_t addressSpace, const char* sName) = 0;
|
||||
};
|
||||
|
||||
// Global function implemented in CryMemoryManager_impl.h
|
||||
IMemoryManager* CryGetIMemoryManager();
|
||||
|
||||
// Summary:
|
||||
// Structure filled by call to CryModuleGetMemoryInfo().
|
||||
struct CryModuleMemoryInfo
|
||||
{
|
||||
uint64 requested;
|
||||
// Total Ammount of memory allocated.
|
||||
uint64 allocated;
|
||||
// Total Ammount of memory freed.
|
||||
uint64 freed;
|
||||
// Total number of memory allocations.
|
||||
int num_allocations;
|
||||
// Allocated in CryString.
|
||||
uint64 CryString_allocated;
|
||||
// Allocated in STL.
|
||||
uint64 STL_allocated;
|
||||
// Amount of memory wasted in pools in stl (not usefull allocations).
|
||||
uint64 STL_wasted;
|
||||
};
|
||||
|
||||
struct CryReplayInfo
|
||||
{
|
||||
uint64 uncompressedLength;
|
||||
uint64 writtenLength;
|
||||
uint32 trackingSize;
|
||||
const char* filename;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Extern declarations of globals inside CrySystem.
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif //__cplusplus
|
||||
|
||||
|
||||
void* CryMalloc(size_t size, size_t& allocated, size_t alignment);
|
||||
void* CryRealloc(void* memblock, size_t size, size_t& allocated, size_t& oldsize, size_t alignment);
|
||||
size_t CryFree(void* p, size_t alignment);
|
||||
size_t CryGetMemSize(void* p, size_t size);
|
||||
int CryStats(char* buf);
|
||||
void CryFlushAll();
|
||||
void CryCleanup();
|
||||
int CryGetUsedHeapSize();
|
||||
int CryGetWastedHeapSize();
|
||||
size_t CrySystemCrtGetUsedSpace();
|
||||
CRYMEMORYMANAGER_API void CryGetIMemoryManagerInterface(void** pIMemoryManager);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif //__cplusplus
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Cry Memory Manager accessible in all build modes.
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
#if !defined(USING_CRY_MEMORY_MANAGER)
|
||||
#define USING_CRY_MEMORY_MANAGER
|
||||
#endif
|
||||
|
||||
#include "CryLegacyAllocator.h"
|
||||
|
||||
|
||||
template<typename T, typename ... Args>
|
||||
inline T* CryAlignedNew(Args&& ... args)
|
||||
{
|
||||
void* pAlignedMemory = CryModuleMemalign(sizeof(T), std::alignment_of<T>::value);
|
||||
return new(pAlignedMemory) T(std::forward<Args>(args) ...);
|
||||
}
|
||||
|
||||
// This utility function should be used for allocating arrays of objects with specific alignment requirements on the heap.
|
||||
// Note: The caller must remember the number of items in the array, since CryAlignedDeleteArray needs this information.
|
||||
template<typename T>
|
||||
inline T* CryAlignedNewArray(size_t count)
|
||||
{
|
||||
T* const pAlignedMemory = reinterpret_cast<T*>(CryModuleMemalign(sizeof(T) * count, std::alignment_of<T>::value));
|
||||
T* pCurrentItem = pAlignedMemory;
|
||||
for (size_t i = 0; i < count; ++i, ++pCurrentItem)
|
||||
{
|
||||
new(static_cast<void*>(pCurrentItem))T();
|
||||
}
|
||||
return pAlignedMemory;
|
||||
}
|
||||
|
||||
// Utility function that frees an object previously allocated with CryAlignedNew.
|
||||
template<typename T>
|
||||
inline void CryAlignedDelete(T* pObject)
|
||||
{
|
||||
if (pObject)
|
||||
{
|
||||
pObject->~T();
|
||||
CryModuleMemalignFree(pObject);
|
||||
}
|
||||
}
|
||||
|
||||
// Utility function that frees an array of objects previously allocated with CryAlignedNewArray.
|
||||
// The same count used to allocate the array must be passed to this function.
|
||||
template<typename T>
|
||||
inline void CryAlignedDeleteArray(T* pObject, size_t count)
|
||||
{
|
||||
if (pObject)
|
||||
{
|
||||
for (size_t i = 0; i < count; ++i)
|
||||
{
|
||||
(pObject + i)->~T();
|
||||
}
|
||||
CryModuleMemalignFree(pObject);
|
||||
}
|
||||
}
|
||||
@@ -1,41 +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 implementation for CryMemoryManager globally defined functions.
|
||||
// This file included only by platform_impl.cpp, do not include it directly in code!
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef AZ_MONOLITHIC_BUILD
|
||||
#include <ISystem.h> // <> required for Interfuscator
|
||||
#endif // AZ_MONOLITHIC_BUILD
|
||||
|
||||
#include "CryLibrary.h"
|
||||
|
||||
#include <AzCore/Module/Environment.h>
|
||||
|
||||
#define DLL_ENTRY_GETMEMMANAGER "CryGetIMemoryManagerInterface"
|
||||
|
||||
// Resolve IMemoryManager by looking in this DLL, then loading and rummaging through
|
||||
// CrySystem. Cache the result per DLL, because this is not quick.
|
||||
IMemoryManager* CryGetIMemoryManager()
|
||||
{
|
||||
static AZ::EnvironmentVariable<IMemoryManager*> memMan = nullptr;
|
||||
if (!memMan)
|
||||
{
|
||||
memMan = AZ::Environment::FindVariable<IMemoryManager*>("CryIMemoryManagerInterface");
|
||||
AZ_Assert(memMan, "Unable to find CryIMemoryManagerInterface via AZ::Environment");
|
||||
}
|
||||
return *memMan;
|
||||
}
|
||||
@@ -19,7 +19,6 @@
|
||||
#include <StlUtils.h>
|
||||
#include <CrySizer.h>
|
||||
#include <CryCrc32.h>
|
||||
#include <STLGlobalAllocator.h>
|
||||
#include <AzCore/std/containers/unordered_map.h>
|
||||
|
||||
class CNameTable;
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
*/
|
||||
|
||||
// Description: Utilities and functions used when cryphysics is disabled
|
||||
|
||||
#pragma once
|
||||
|
||||
// Assert if CryPhysics is disabled and no functionality replacement has been implemented
|
||||
// 1: Runtime AZ_Error
|
||||
// 2: Runtime Assertion
|
||||
// 3: Compilation error
|
||||
// Other: Do nothing
|
||||
#define ENABLE_CRY_PHYSICS_REPLACEMENT_ASSERT 0
|
||||
|
||||
#if (ENABLE_CRY_PHYSICS_REPLACEMENT_ASSERT == 1)
|
||||
#define CRY_PHYSICS_REPLACEMENT_ASSERT() AZ_Error("CryPhysics", false, __FUNCTION__ " - CRYPHYSICS REPLACEMENT NOT IMPLEMENTED")
|
||||
#elif (ENABLE_CRY_PHYSICS_REPLACEMENT_ASSERT == 2)
|
||||
#define CRY_PHYSICS_REPLACEMENT_ASSERT() AZ_Assert(false, "CRYPHYSICS REPLACEMENT NOT IMPLEMENTED")
|
||||
#elif (ENABLE_CRY_PHYSICS_REPLACEMENT_ASSERT == 3)
|
||||
#define CRY_PHYSICS_REPLACEMENT_ASSERT() static_assert(false, __FUNCTION__ " - CRYPHYSICS REPLACEMENT NOT IMPLEMENTED")
|
||||
#else
|
||||
#define CRY_PHYSICS_REPLACEMENT_ASSERT()
|
||||
#endif
|
||||
@@ -1,100 +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_CRYPTRARRAY_H
|
||||
#define CRYINCLUDE_CRYCOMMON_CRYPTRARRAY_H
|
||||
#pragma once
|
||||
|
||||
#include "CryArray.h"
|
||||
#include "CrySizer.h"
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
template<class T, class P = T*>
|
||||
struct PtrArray
|
||||
: DynArray<P>
|
||||
{
|
||||
typedef DynArray<P> super;
|
||||
|
||||
// Overrides.
|
||||
typedef T value_type;
|
||||
|
||||
ILINE ~PtrArray(){}
|
||||
|
||||
inline T& operator [](int i) const
|
||||
{ return *super::operator[](i); }
|
||||
|
||||
// Iterators.
|
||||
struct iterator
|
||||
{
|
||||
iterator(P* p)
|
||||
: _ptr(p)
|
||||
{}
|
||||
|
||||
operator P* () const
|
||||
{
|
||||
return _ptr;
|
||||
}
|
||||
void operator++()
|
||||
{ _ptr++; }
|
||||
void operator--()
|
||||
{ _ptr--; }
|
||||
T& operator*() const
|
||||
{ assert(_ptr); return **_ptr; }
|
||||
T* operator->() const
|
||||
{ assert(_ptr); return *_ptr; }
|
||||
|
||||
protected:
|
||||
P* _ptr;
|
||||
};
|
||||
|
||||
struct const_iterator
|
||||
{
|
||||
const_iterator(const P* p)
|
||||
: _ptr(p)
|
||||
{}
|
||||
|
||||
operator const P* () const
|
||||
{
|
||||
return _ptr;
|
||||
}
|
||||
void operator++()
|
||||
{ _ptr++; }
|
||||
void operator--()
|
||||
{ _ptr--; }
|
||||
T& operator*() const
|
||||
{ assert(_ptr); return **_ptr; }
|
||||
T* operator->() const
|
||||
{ assert(_ptr); return *_ptr; }
|
||||
|
||||
protected:
|
||||
const P* _ptr;
|
||||
};
|
||||
|
||||
void GetMemoryUsage(ICrySizer* pSizer) const
|
||||
{
|
||||
pSizer->AddObject(this->begin(), this->get_alloc_size());
|
||||
for (int i = 0; i < this->size(); ++i)
|
||||
{
|
||||
pSizer->AddObject(this->super::operator [](i));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
template<class T>
|
||||
struct SmartPtrArray
|
||||
: PtrArray< T, _smart_ptr<T> >
|
||||
{
|
||||
};
|
||||
|
||||
#endif // CRYINCLUDE_CRYCOMMON_CRYPTRARRAY_H
|
||||
@@ -33,7 +33,6 @@
|
||||
#include <Cry_Vector3.h>
|
||||
#include <Cry_Quat.h>
|
||||
#include <Cry_Color.h>
|
||||
#include <CryArray2d.h>
|
||||
#include <smartptr.h>
|
||||
|
||||
// forward declarations for overloads
|
||||
@@ -48,8 +47,6 @@ struct SPipTangents;
|
||||
#include <string.h> // workaround for Amd64 compiler
|
||||
#endif
|
||||
|
||||
#include <IResourceCollector.h> // <> required for Interfuscator. IResourceCollector
|
||||
|
||||
namespace AZ
|
||||
{
|
||||
class Vector3;
|
||||
@@ -251,12 +248,6 @@ public:
|
||||
void AddObject([[maybe_unused]] const AZ::Vector3& rObj) {}
|
||||
void AddObject(void*) {}
|
||||
|
||||
template<typename T>
|
||||
void AddObject(const Array2d<T>& array2d)
|
||||
{
|
||||
this->AddObject(array2d.m_pData, array2d.GetDataSize());
|
||||
}
|
||||
|
||||
// overloads for container, will automaticly traverse the content
|
||||
template<typename T, typename Alloc>
|
||||
void AddObject(const std::list<T, Alloc>& rList)
|
||||
@@ -335,20 +326,6 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void AddObject(const TArray<T>& rVector)
|
||||
{
|
||||
if (!this->AddObject(rVector.begin(), rVector.capacity() * sizeof(T)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0, end = rVector.size(); i < end; ++i)
|
||||
{
|
||||
this->AddObject(rVector[i]);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void AddObject(const PodArray<T>& rVector)
|
||||
{
|
||||
@@ -427,11 +404,6 @@ public:
|
||||
return AddObject (&rObject, sizeof(T));
|
||||
}
|
||||
|
||||
// used to collect the assets needed for streaming and to gather statistics
|
||||
// always returns a valid reference
|
||||
virtual IResourceCollector* GetResourceCollector() = 0;
|
||||
virtual void SetResourceCollector(IResourceCollector* pColl) = 0;
|
||||
|
||||
bool Add (const char* szText)
|
||||
{
|
||||
return AddObject(szText, strlen(szText) + 1);
|
||||
|
||||
@@ -1,634 +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 : Specialized Container for Renderer data with the following proberties:
|
||||
// - Created during the 3DEngine Update, comsumed in the renderer in the following frame
|
||||
// - This Container is very restricted and likely not optimal for other situations
|
||||
|
||||
|
||||
#ifndef CRYINCLUDE_CRYCOMMON_CRYTHREADSAFERENDERERCONTAINER_H
|
||||
#define CRYINCLUDE_CRYCOMMON_CRYTHREADSAFERENDERERCONTAINER_H
|
||||
#pragma once
|
||||
|
||||
|
||||
// This container is specialized for data which is generated in the 3DEngine and consumed by the renderer
|
||||
// in the following frame due to multithreaded rendering. To be useable by Jobs as well as other Threads
|
||||
// some very specific desing choices were taken:
|
||||
// First of the underlying continous memory block is only resized during a call to 'CoalesceMemory'
|
||||
// to prevent freeing a memory block which could be used by another thread.
|
||||
// If new memory is requiered, a page of 4 KB is allocated and used as a temp storage till the next
|
||||
// call to 'CoalesceMemory' which then copies all page memory into one continous block.
|
||||
// Also all threading relevant functions are implemented LockLess to prevent lock contention and make
|
||||
// this container useable from Jobs
|
||||
//
|
||||
// Right now, the main usage pattern of this container is by the RenderThread, who calls at the beginning
|
||||
// of its frame 'CoalesceMemory', since then we can be sure that the 3DEngine has finished creating it's elements.
|
||||
//
|
||||
// Since the main purpose of this container is multi-threading adding of elements, a slight change was done to the
|
||||
// push_back interface compared to std::vector:
|
||||
// All implemented push_back variants can return a pointer into the storage (safe since no memory is freed during adding)
|
||||
// and a index for this elements. This is done since calling operator[] could be expensive when called before 'CoalesceMemory'
|
||||
//
|
||||
// For ease of implementation (and a little bit of speed), this container only supports POD types (which can be copied with memcpy)
|
||||
// also note that this container only supports push_back (and resize back to 0) and no pop back due cost (performance and code complexity) of supporting lock-free in parallel pop_back
|
||||
#define TSRC_ALIGN _MS_ALIGN(128)
|
||||
|
||||
template<typename T>
|
||||
class TSRC_ALIGN CThreadSafeRendererContainer
|
||||
{
|
||||
public:
|
||||
CThreadSafeRendererContainer();
|
||||
~CThreadSafeRendererContainer();
|
||||
|
||||
//NOTE: be aware that these valus can potentially change if some objects are added in parallel
|
||||
size_t size() const;
|
||||
size_t empty() const;
|
||||
size_t capacity() const;
|
||||
|
||||
//NOTE: be aware that this operator can be more expensive if the memory was not coalesced before
|
||||
T& operator[](size_t n);
|
||||
const T& operator[](size_t n) const;
|
||||
|
||||
T* push_back_new();
|
||||
T* push_back_new(size_t& nIndex);
|
||||
|
||||
void push_back(const T&);
|
||||
void push_back(const T&, size_t& nIndex);
|
||||
|
||||
// NOTE: These functions are changing the size of the continous memory block and thus are *not* thread-safe
|
||||
void clear();
|
||||
void resize(size_t n);
|
||||
void reserve(size_t n);
|
||||
|
||||
void CoalesceMemory();
|
||||
|
||||
void GetMemoryUsage(ICrySizer*) const;
|
||||
|
||||
// disable copy/assignment
|
||||
CThreadSafeRendererContainer(const CThreadSafeRendererContainer& rOther) = delete;
|
||||
CThreadSafeRendererContainer& operator=(const CThreadSafeRendererContainer& rOther) = delete;
|
||||
|
||||
private:
|
||||
|
||||
/////////////////////////////////////
|
||||
// Struct to represent a memory chunk
|
||||
// used in fallback allocations during 'Fill' phase
|
||||
class CMemoryPage
|
||||
{
|
||||
public:
|
||||
// size of a page to allocate, the CMemoryPage is just the header,
|
||||
// the actual object data is stored in the 4KB chunk right
|
||||
// after the header (while keeping the requiered alignment and so on)
|
||||
enum
|
||||
{
|
||||
nMemoryPageSize = 4096
|
||||
};
|
||||
|
||||
CMemoryPage();
|
||||
|
||||
// allocation functions
|
||||
static CMemoryPage* AllocateNewPage();
|
||||
bool TryAllocateElement(size_t& nIndex, T*& pObj);
|
||||
|
||||
// access to the elements
|
||||
T& GetElement(size_t n);
|
||||
T* GetData() const;
|
||||
|
||||
// information about the page (NOTE: not thread-safe in all combinations)
|
||||
size_t Size() const;
|
||||
size_t Capacity() const;
|
||||
size_t GetDataSize() const;
|
||||
|
||||
CMemoryPage* m_pNext; // Pointer to next entry in single-linked list of CMemoryPages
|
||||
|
||||
private:
|
||||
LONG m_nSize; // Number of elements currently in the page
|
||||
LONG m_nCapacity; // Number of elements which could fit into the page
|
||||
T* m_arrData; // Element memory, from the same memory chunk right after the CMemoryPage class
|
||||
};
|
||||
|
||||
|
||||
/////////////////////////////////////
|
||||
// Private functions which do the lock-less updating
|
||||
T* push_back_impl(size_t& nIndex);
|
||||
bool try_append_to_continous_memory(size_t& nIndex, T*& pObj);
|
||||
|
||||
T& GetMemoryPageElement(size_t n);
|
||||
|
||||
|
||||
/////////////////////////////////////
|
||||
// Private Member Variables
|
||||
T* m_arrData; // Storage for the continous memory part, during coalescing resized to hold all page memory
|
||||
LONG m_nCapacity; // Avaible Memory in continous memory part, if exhausted during 'Fill' phase, pages as temp memory chunks are allocated
|
||||
|
||||
CMemoryPage* m_pMemoryPages; // Single linked list of memory chunks, used for fallback allocations during 'Fill' phase (to prevent changing the continous memory block during 'Fill'
|
||||
|
||||
LONG m_nSize; // Number of elements currently in the container, can be larger than m_nCapacity due the nonContinousPages
|
||||
|
||||
bool m_bElementAccessSafe; // bool to indicate if we are currently doing a 'CoalasceMemory' step, during which some operations are now allowed
|
||||
} _ALIGN(128);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T>
|
||||
inline CThreadSafeRendererContainer<T>::CThreadSafeRendererContainer()
|
||||
: m_arrData(NULL)
|
||||
, m_nCapacity(0)
|
||||
, m_pMemoryPages(NULL)
|
||||
, m_nSize(0)
|
||||
, m_bElementAccessSafe(true)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T>
|
||||
inline CThreadSafeRendererContainer<T>::~CThreadSafeRendererContainer()
|
||||
{
|
||||
clear();
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T>
|
||||
inline size_t CThreadSafeRendererContainer<T>::size() const
|
||||
{
|
||||
return *const_cast<volatile LONG*>(&m_nSize);
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T>
|
||||
inline size_t CThreadSafeRendererContainer<T>::empty() const
|
||||
{
|
||||
return *const_cast<volatile LONG*>(&m_nSize) == 0;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T>
|
||||
inline size_t CThreadSafeRendererContainer<T>::capacity() const
|
||||
{
|
||||
// capacity of continous memory block
|
||||
LONG nCapacity = m_nCapacity;
|
||||
|
||||
// add capacity of all memory pages
|
||||
CMemoryPage* pCurrentMemoryPage = m_pMemoryPages;
|
||||
while (pCurrentMemoryPage)
|
||||
{
|
||||
nCapacity += pCurrentMemoryPage->Capacity();
|
||||
pCurrentMemoryPage = pCurrentMemoryPage->m_pNext;
|
||||
}
|
||||
|
||||
return nCapacity;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T>
|
||||
inline T& CThreadSafeRendererContainer<T>::operator[](size_t n)
|
||||
{
|
||||
assert(m_bElementAccessSafe);
|
||||
T* pRet = NULL;
|
||||
|
||||
#if !defined(NULL_RENDERER)
|
||||
assert((LONG)n < m_nSize);
|
||||
#endif
|
||||
if ((LONG)n < m_nCapacity)
|
||||
{
|
||||
pRet = &m_arrData[n];
|
||||
}
|
||||
else
|
||||
{
|
||||
pRet = &GetMemoryPageElement(n);
|
||||
}
|
||||
return *pRet;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T>
|
||||
inline const T& CThreadSafeRendererContainer<T>::operator[](size_t n) const
|
||||
{
|
||||
return const_cast<const T&>(const_cast<CThreadSafeRendererContainer<T>*>(this)->operator[](n));
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T>
|
||||
inline T* CThreadSafeRendererContainer<T>::push_back_new()
|
||||
{
|
||||
assert(m_bElementAccessSafe);
|
||||
size_t nUnused = ~0;
|
||||
return push_back_impl(nUnused);
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T>
|
||||
inline T* CThreadSafeRendererContainer<T>::push_back_new(size_t& nIndex)
|
||||
{
|
||||
assert(m_bElementAccessSafe);
|
||||
return push_back_impl(nIndex);
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T>
|
||||
inline void CThreadSafeRendererContainer<T>::push_back(const T& rObj)
|
||||
{
|
||||
assert(m_bElementAccessSafe);
|
||||
size_t nUnused = ~0;
|
||||
T* pObj = push_back_impl(nUnused);
|
||||
*pObj = rObj;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T>
|
||||
inline void CThreadSafeRendererContainer<T>::push_back(const T& rObj, size_t& nIndex)
|
||||
{
|
||||
assert(m_bElementAccessSafe);
|
||||
T* pObj = push_back_impl(nIndex);
|
||||
*pObj = rObj;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T>
|
||||
inline void CThreadSafeRendererContainer<T>::clear()
|
||||
{
|
||||
assert(m_bElementAccessSafe);
|
||||
// free continous part
|
||||
CryModuleMemalignFree(m_arrData);
|
||||
m_arrData = NULL;
|
||||
|
||||
// free non-continous pages if we have some
|
||||
CMemoryPage* pCurrentMemoryPage = m_pMemoryPages;
|
||||
while (pCurrentMemoryPage)
|
||||
{
|
||||
CMemoryPage* pOldPage = pCurrentMemoryPage;
|
||||
pCurrentMemoryPage = pCurrentMemoryPage->m_pNext;
|
||||
CryModuleFree(pOldPage);
|
||||
}
|
||||
m_pMemoryPages = NULL;
|
||||
|
||||
m_nSize = 0;
|
||||
m_nCapacity = 0;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T>
|
||||
inline void CThreadSafeRendererContainer<T>::resize(size_t n)
|
||||
{
|
||||
assert(m_bElementAccessSafe);
|
||||
CoalesceMemory();
|
||||
size_t nOldSize = m_nSize;
|
||||
m_nSize = n;
|
||||
|
||||
if ((LONG)n <= m_nCapacity)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
T* arrOldData = m_arrData;
|
||||
m_arrData = reinterpret_cast<T*>(CryModuleMemalign(n * sizeof(T), alignof(T)));
|
||||
memcpy(m_arrData, arrOldData, nOldSize * sizeof(T));
|
||||
memset(&m_arrData[m_nCapacity], 0, (n - m_nCapacity) * sizeof(T));
|
||||
CryModuleMemalignFree(arrOldData);
|
||||
|
||||
m_nCapacity = n;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T>
|
||||
inline void CThreadSafeRendererContainer<T>::reserve(size_t n)
|
||||
{
|
||||
assert(m_bElementAccessSafe);
|
||||
CoalesceMemory();
|
||||
if ((LONG)n <= m_nCapacity)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
T* arrOldData = m_arrData;
|
||||
m_arrData = reinterpret_cast<T*>(CryModuleMemalign(n * sizeof(T), alignof(T)));
|
||||
memcpy(m_arrData, arrOldData, m_nSize * sizeof(T));
|
||||
memset(&m_arrData[m_nCapacity], 0, (n - m_nCapacity) * sizeof(T));
|
||||
CryModuleMemalignFree(arrOldData);
|
||||
|
||||
m_nCapacity = n;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T>
|
||||
inline bool CThreadSafeRendererContainer<T>::try_append_to_continous_memory(size_t& nIndex, T*& pObj)
|
||||
{
|
||||
assert(m_bElementAccessSafe);
|
||||
LONG nSize = ~0;
|
||||
LONG nCapacity = ~0;
|
||||
do
|
||||
{
|
||||
// read volatile the new size
|
||||
nSize = *const_cast<volatile LONG*>(&m_nSize);
|
||||
nCapacity = *const_cast<volatile LONG*>(&m_nCapacity);
|
||||
|
||||
if (nSize >= nCapacity)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
} while (CryInterlockedCompareExchange(alias_cast<volatile LONG*>(&m_nSize), nSize + 1, nSize) != nSize);
|
||||
nIndex = nSize;
|
||||
pObj = &m_arrData[nSize];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T>
|
||||
inline T* CThreadSafeRendererContainer<T>::push_back_impl(size_t& nIndex)
|
||||
{
|
||||
assert(m_bElementAccessSafe);
|
||||
T* pObj = NULL;
|
||||
|
||||
// non atomic check to see if there is space in the continous array
|
||||
if (try_append_to_continous_memory(nIndex, pObj))
|
||||
{
|
||||
return pObj;
|
||||
}
|
||||
|
||||
// exhausted continous memory, falling back to page allocation
|
||||
for (;; )
|
||||
{
|
||||
assert(m_bElementAccessSafe);
|
||||
size_t nPageBaseIndex = 0;
|
||||
|
||||
// traverse the page list till the first page with free memory
|
||||
CMemoryPage* pCurrentMemoryPage = m_pMemoryPages;
|
||||
while (pCurrentMemoryPage)
|
||||
{
|
||||
size_t nAvaibleElements = pCurrentMemoryPage->Capacity() - pCurrentMemoryPage->Size();
|
||||
if (nAvaibleElements)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
// no memory in this page, go to the next one
|
||||
nPageBaseIndex += pCurrentMemoryPage->Capacity();
|
||||
pCurrentMemoryPage = pCurrentMemoryPage->m_pNext;
|
||||
}
|
||||
|
||||
// try to allocate a element on this page
|
||||
if (pCurrentMemoryPage && pCurrentMemoryPage->TryAllocateElement(nIndex, pObj))
|
||||
{
|
||||
// update global elements counter
|
||||
CryInterlockedIncrement(alias_cast<volatile int*>(&m_nSize));
|
||||
|
||||
// adjust in-page-index to global index
|
||||
nIndex += nPageBaseIndex + m_nCapacity;
|
||||
return pObj;
|
||||
}
|
||||
else
|
||||
{
|
||||
// all pages are empty, allocate and link a new one
|
||||
CMemoryPage* pNewPage = CMemoryPage::AllocateNewPage();
|
||||
|
||||
void* volatile* ppLastMemoryPageAddress = NULL;
|
||||
do
|
||||
{
|
||||
// find place to link in page
|
||||
CMemoryPage* pLastMemoryPage = m_pMemoryPages;
|
||||
ppLastMemoryPageAddress = alias_cast<void* volatile*>(&m_pMemoryPages);
|
||||
|
||||
while (pLastMemoryPage)
|
||||
{
|
||||
ppLastMemoryPageAddress = alias_cast<void* volatile*>(&(pLastMemoryPage->m_pNext));
|
||||
pLastMemoryPage = pLastMemoryPage->m_pNext;
|
||||
}
|
||||
} while (CryInterlockedCompareExchangePointer(ppLastMemoryPageAddress, pNewPage, NULL) != NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T>
|
||||
inline T& CThreadSafeRendererContainer<T>::GetMemoryPageElement(size_t n)
|
||||
{
|
||||
assert(m_bElementAccessSafe);
|
||||
size_t nFirstListIndex = m_nCapacity;
|
||||
CMemoryPage* pCurrentMemoryPage = m_pMemoryPages;
|
||||
|
||||
size_t nPageCapacity = pCurrentMemoryPage->Capacity();
|
||||
while (n >= (nFirstListIndex + nPageCapacity))
|
||||
{
|
||||
// this is threadsafe because we assume that if we want to get element 'n'
|
||||
// the clientcode did already fill the container up to element 'n'
|
||||
// thus up to 'n', m_pNonContinousList will have valid pages
|
||||
// NOTE: This is not safe when trying to read a element behind the valid
|
||||
// range (same as std::vector)
|
||||
nFirstListIndex += nPageCapacity;
|
||||
pCurrentMemoryPage = pCurrentMemoryPage->m_pNext;
|
||||
|
||||
// update page capacity, since it can differe due alignment
|
||||
nPageCapacity = pCurrentMemoryPage->Capacity();
|
||||
}
|
||||
|
||||
return pCurrentMemoryPage->GetElement(n - nFirstListIndex);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// When not not in the 'Fill' phase, it is safe to colace all page entries into one continous memory block
|
||||
template<typename T>
|
||||
inline void CThreadSafeRendererContainer<T>::CoalesceMemory()
|
||||
{
|
||||
assert(m_bElementAccessSafe);
|
||||
if (m_pMemoryPages == NULL)
|
||||
{
|
||||
return; // nothing to do
|
||||
}
|
||||
// mark state as not accessable
|
||||
m_bElementAccessSafe = false;
|
||||
|
||||
#if !defined(NDEBUG)
|
||||
size_t nOldSize = m_nSize;
|
||||
#endif
|
||||
|
||||
// compute required memory
|
||||
size_t nRequieredElements = 0;
|
||||
{
|
||||
CMemoryPage* pCurrentMemoryPage = m_pMemoryPages;
|
||||
while (pCurrentMemoryPage)
|
||||
{
|
||||
nRequieredElements += pCurrentMemoryPage->Size();
|
||||
pCurrentMemoryPage = pCurrentMemoryPage->m_pNext;
|
||||
}
|
||||
}
|
||||
|
||||
T* arrOldData = m_arrData;
|
||||
m_arrData = reinterpret_cast<T*>(CryModuleMemalign((m_nCapacity + nRequieredElements) * sizeof(T), alignof(T)));
|
||||
memcpy(m_arrData, arrOldData, m_nCapacity * sizeof(T));
|
||||
CryModuleMemalignFree(arrOldData);
|
||||
|
||||
// copy page data into continous memory block
|
||||
{
|
||||
size_t nBeginToFillIndex = m_nCapacity;
|
||||
CMemoryPage* pCurrentMemoryPage = m_pMemoryPages;
|
||||
while (pCurrentMemoryPage)
|
||||
{
|
||||
// copy data
|
||||
memcpy(&m_arrData[nBeginToFillIndex], pCurrentMemoryPage->GetData(), pCurrentMemoryPage->GetDataSize());
|
||||
nBeginToFillIndex += pCurrentMemoryPage->Size();
|
||||
|
||||
// free page
|
||||
CMemoryPage* pOldPage = pCurrentMemoryPage;
|
||||
pCurrentMemoryPage = pCurrentMemoryPage->m_pNext;
|
||||
CryModuleFree(pOldPage);
|
||||
}
|
||||
|
||||
m_pMemoryPages = NULL;
|
||||
}
|
||||
|
||||
assert(nOldSize == m_nSize);
|
||||
m_nCapacity += nRequieredElements;
|
||||
|
||||
// the container can be used again
|
||||
m_bElementAccessSafe = true;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Collect information about used memory
|
||||
template<typename T>
|
||||
void CThreadSafeRendererContainer<T>::GetMemoryUsage(ICrySizer* pSizer) const
|
||||
{
|
||||
pSizer->AddObject(m_arrData, m_nCapacity * sizeof(T));
|
||||
|
||||
CMemoryPage* pCurrentMemoryPage = m_pMemoryPages;
|
||||
while (pCurrentMemoryPage)
|
||||
{
|
||||
pSizer->AddObject(pCurrentMemoryPage, CMemoryPage::nMemoryPageSize);
|
||||
pCurrentMemoryPage = pCurrentMemoryPage->m_pNext;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T>
|
||||
inline CThreadSafeRendererContainer<T>::CMemoryPage::CMemoryPage()
|
||||
: m_pNext(NULL)
|
||||
, m_nSize(0)
|
||||
{
|
||||
// compute offset for actual data
|
||||
size_t nObjectAlignment = alignof(T);
|
||||
UINT_PTR nMemoryBlockBegin = alias_cast<UINT_PTR>(this);
|
||||
UINT_PTR nMemoryBlockEnd = alias_cast<UINT_PTR>(this) + nMemoryPageSize;
|
||||
|
||||
nMemoryBlockBegin += sizeof(CMemoryPage);
|
||||
nMemoryBlockBegin = (nMemoryBlockBegin + nObjectAlignment - 1) & ~(nObjectAlignment - 1);
|
||||
|
||||
// compute number of avaible elements
|
||||
assert(nMemoryBlockEnd > nMemoryBlockBegin);
|
||||
m_nCapacity = (LONG)((nMemoryBlockEnd - nMemoryBlockBegin) / sizeof(T));
|
||||
|
||||
// store pointer to store data to
|
||||
m_arrData = alias_cast<T*>(nMemoryBlockBegin);
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T>
|
||||
inline typename CThreadSafeRendererContainer<T>::CMemoryPage * CThreadSafeRendererContainer<T>::CMemoryPage::AllocateNewPage()
|
||||
{
|
||||
void* pNewPageMemoryChunk = CryModuleMalloc(nMemoryPageSize);
|
||||
assert(pNewPageMemoryChunk != NULL);
|
||||
|
||||
memset(pNewPageMemoryChunk, 0, nMemoryPageSize);
|
||||
CMemoryPage* pNewPage = new(pNewPageMemoryChunk) CMemoryPage();
|
||||
return pNewPage;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T>
|
||||
inline bool CThreadSafeRendererContainer<T>::CMemoryPage::TryAllocateElement(size_t & nIndex, T * &pObj)
|
||||
{
|
||||
LONG nSize = ~0;
|
||||
LONG nCapacity = ~0;
|
||||
do
|
||||
{
|
||||
// read volatile the new size
|
||||
nSize = *const_cast<volatile LONG*>(&m_nSize);
|
||||
nCapacity = *const_cast<volatile LONG*>(&m_nCapacity);
|
||||
// stop trying if this page is full
|
||||
if (nSize >= nCapacity)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
} while (CryInterlockedCompareExchange(alias_cast<volatile LONG*>(&m_nSize), nSize + 1, nSize) != nSize);
|
||||
|
||||
//Note: this is the index in the page and it is adjusted in the calling context
|
||||
nIndex = nSize;
|
||||
pObj = &m_arrData[nSize];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T>
|
||||
inline T&CThreadSafeRendererContainer<T>::CMemoryPage::GetElement(size_t n)
|
||||
{
|
||||
assert((LONG)n < m_nSize);
|
||||
assert(m_nSize <= m_nCapacity);
|
||||
return m_arrData[n];
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T>
|
||||
inline T * CThreadSafeRendererContainer<T>::CMemoryPage::GetData() const
|
||||
{
|
||||
return m_arrData;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T>
|
||||
inline size_t CThreadSafeRendererContainer<T>::CMemoryPage::Size() const
|
||||
{
|
||||
return m_nSize;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T>
|
||||
inline size_t CThreadSafeRendererContainer<T>::CMemoryPage::GetDataSize() const
|
||||
{
|
||||
return m_nSize * sizeof(T);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T>
|
||||
inline size_t CThreadSafeRendererContainer<T>::CMemoryPage::Capacity() const
|
||||
{
|
||||
return m_nCapacity;
|
||||
}
|
||||
|
||||
#endif // CRYINCLUDE_CRYCOMMON_CRYTHREADSAFERENDERERCONTAINER_H
|
||||
@@ -1,602 +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 : Specialized Container for Renderer data with the following properties:
|
||||
// Created during the 3DEngine Update, consumed in the renderer in the following frame
|
||||
// This Container is very restricted and likely not optimal for other situations
|
||||
|
||||
|
||||
#ifndef CRYINCLUDE_CRYCOMMON_CRYTHREADSAFEWORKERCONTAINER_H
|
||||
#define CRYINCLUDE_CRYCOMMON_CRYTHREADSAFEWORKERCONTAINER_H
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "platform.h"
|
||||
#include <vector>
|
||||
|
||||
#include <AzCore/Jobs/JobContext.h>
|
||||
#include <AzCore/Jobs/JobManager.h>
|
||||
#include <AzCore/std/typetraits/typetraits.h>
|
||||
|
||||
|
||||
//
|
||||
// !!! BE CAREFULL WHEN USING THIS CONTAINER !!!
|
||||
//
|
||||
// --- Properties: ---
|
||||
// - Stores data local to worker thread to avoid thread-safety semantics
|
||||
// - Allows for a single non-worker thread to be tracked which is stored in m_workers[0]
|
||||
// Hence: As m_workers[0] is shared between all non-worker threads, ensure that only one additional non-worker thread may access this container e.g. MainThread
|
||||
// - Coalesce memory to obtain a continues memory block
|
||||
// - Coalesce memory to for faster element access to a continues memory block
|
||||
//
|
||||
// --- Restrictions:---
|
||||
// - The workers own the memory structure
|
||||
// - The coalesced memory stores a copy of the workers used memory
|
||||
// Hence: Be careful when altering data within the coalesced memory.
|
||||
// If the templated element is a pointer type than altering the memory pointed to, is not be an issue
|
||||
// If the templated element is of type class or struct than ensure that data changes are done on the worker local data and not on the coalesced memory. Use worker encoded indices to do so.
|
||||
//
|
||||
|
||||
template <class T>
|
||||
class CThreadSafeWorkerContainer
|
||||
{
|
||||
public:
|
||||
struct SDefaultNoOpFunctor
|
||||
{
|
||||
ILINE void operator()(T* pData) const{}
|
||||
};
|
||||
|
||||
struct SDefaultDestructorFunctor
|
||||
{
|
||||
ILINE void operator()(T* pData) const
|
||||
{
|
||||
pData->~T();
|
||||
}
|
||||
};
|
||||
|
||||
public:
|
||||
CThreadSafeWorkerContainer();
|
||||
~CThreadSafeWorkerContainer();
|
||||
|
||||
void Init();
|
||||
void SetNonWorkerThreadID(threadID nThreadId) { m_foreignThreadId = nThreadId; }
|
||||
|
||||
// Safe access of elements for calling thread via operator[]
|
||||
uint32 ConvertToEncodedWorkerId_threadlocal(uint32 nIndex) const;
|
||||
|
||||
// Returns the number of threads that can use this container, including the one non-worker-thread.
|
||||
uint32 GetNumWorkers() const;
|
||||
|
||||
// Returns the Worker ID for the current thread. Ranges from 0 to GetNumWorkers()-1.
|
||||
// Note, WorkerId is not the same thing as JobManager's WorkerThreadId.
|
||||
uint32 GetWorkerId_threadlocal() const;
|
||||
|
||||
//NOTE: be aware that these values can potentially change if some objects are added in parallel
|
||||
size_t size() const;
|
||||
size_t empty() const;
|
||||
size_t capacity() const;
|
||||
|
||||
size_t size_threadlocal() const;
|
||||
size_t empty_threadlocal() const;
|
||||
size_t capacity_threadlocal() const;
|
||||
|
||||
//NOTE: be aware that this operator is more expensive if the memory was not coalesced before
|
||||
T& operator[](size_t n);
|
||||
const T& operator[](size_t n) const;
|
||||
|
||||
T* push_back_new();
|
||||
T* push_back_new(size_t& nIndex);
|
||||
|
||||
void push_back(const T& rObj);
|
||||
void push_back(const T& rObj, size_t& nIndex);
|
||||
|
||||
// NOTE: These functions are changing the size of the continous memory block and thus are *not* thread-safe
|
||||
void clear();
|
||||
template< class OnElementDeleteFunctor>
|
||||
void clear(const OnElementDeleteFunctor& rFunctor = CThreadSafeWorkerContainer<T>::SDefaultNoOpFunctor());
|
||||
void erase(const T& rObj);
|
||||
void resize(size_t n);
|
||||
void reserve(size_t n);
|
||||
|
||||
// *not* thread-safe functions
|
||||
void PrefillContainer(T* pElement, size_t numElements);
|
||||
void CoalesceMemory();
|
||||
|
||||
void GetMemoryUsage(ICrySizer* pSizer) const;
|
||||
|
||||
private:
|
||||
|
||||
void clear(AZStd::true_type);
|
||||
void clear(AZStd::false_type);
|
||||
|
||||
class SWorker
|
||||
{
|
||||
public:
|
||||
AZ_CLASS_ALLOCATOR(SWorker, AZ::LegacyAllocator, 0);
|
||||
|
||||
SWorker()
|
||||
: m_dataSize(0) {}
|
||||
|
||||
uint32 m_dataSize;
|
||||
AZStd::vector<T> m_data;
|
||||
} _ALIGN(128);
|
||||
|
||||
T* push_back_impl(size_t& nIndex);
|
||||
void ReserverCoalescedMemory(size_t n);
|
||||
|
||||
threadID m_foreignThreadId; // OS thread ID of the non-job-manager-worker-thread allowed to use this container, too.
|
||||
|
||||
AZStd::vector<SWorker> m_workers; // Holds data for each thread that can use this container. A non-worker-thread (Main) has data stored at 0. Actual worker threads range from 1 to m_nNumWorkers-1
|
||||
uint32 m_nNumWorkers = 0; // The number of threads that can use this container, including one non-worker-thread.
|
||||
|
||||
uint32 m_coalescedArrCapacity;
|
||||
T* m_coalescedArr;
|
||||
bool m_isCoalesced;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T>
|
||||
inline CThreadSafeWorkerContainer<T>::CThreadSafeWorkerContainer()
|
||||
: m_nNumWorkers(0)
|
||||
, m_coalescedArrCapacity(0)
|
||||
, m_coalescedArr(0)
|
||||
, m_isCoalesced(false)
|
||||
{
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T>
|
||||
inline CThreadSafeWorkerContainer<T>::~CThreadSafeWorkerContainer()
|
||||
{
|
||||
clear();
|
||||
m_workers.clear();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T>
|
||||
inline void CThreadSafeWorkerContainer<T>::Init()
|
||||
{
|
||||
m_nNumWorkers = AZ::JobContext::GetGlobalContext()->GetJobManager().GetNumWorkerThreads() + 1;
|
||||
m_workers.resize(m_nNumWorkers);
|
||||
|
||||
m_foreignThreadId = THREADID_NULL;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T>
|
||||
inline size_t CThreadSafeWorkerContainer<T>::size() const
|
||||
{
|
||||
uint32 totalSize = 0;
|
||||
for (int i = 0; i < m_nNumWorkers; ++i)
|
||||
{
|
||||
totalSize += m_workers[i].m_dataSize;
|
||||
}
|
||||
return totalSize;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T>
|
||||
inline size_t CThreadSafeWorkerContainer<T>::empty() const
|
||||
{
|
||||
return size() == 0;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T>
|
||||
inline size_t CThreadSafeWorkerContainer<T>::capacity() const
|
||||
{
|
||||
uint32 totalCapacity = 0;
|
||||
for (int i = 0; i < m_nNumWorkers; ++i)
|
||||
{
|
||||
totalCapacity += m_workers[i].m_data.capacity();
|
||||
}
|
||||
return totalCapacity;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T>
|
||||
inline size_t CThreadSafeWorkerContainer<T>::size_threadlocal() const
|
||||
{
|
||||
const uint32 nWorkerThreadId = GetWorkerId_threadlocal();
|
||||
return m_workers[nWorkerThreadId].m_dataSize;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T>
|
||||
inline size_t CThreadSafeWorkerContainer<T>::empty_threadlocal() const
|
||||
{
|
||||
const uint32 nWorkerThreadId = GetWorkerId_threadlocal();
|
||||
return m_workers[nWorkerThreadId].m_data.empty();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T>
|
||||
inline size_t CThreadSafeWorkerContainer<T>::capacity_threadlocal() const
|
||||
{
|
||||
const uint32 nWorkerThreadId = GetWorkerId_threadlocal();
|
||||
return m_workers[nWorkerThreadId].m_data.capacity();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T>
|
||||
inline T& CThreadSafeWorkerContainer<T>::operator[](size_t n)
|
||||
{
|
||||
const uint32 nHasWorkerEncodedIndex = (n & 0x80000000) >> 31;
|
||||
|
||||
IF ((m_isCoalesced && !nHasWorkerEncodedIndex), 1)
|
||||
{
|
||||
AZ_Assert(m_coalescedArr, "null array");
|
||||
AZ_Assert(n < m_coalescedArrCapacity, "Index out of bounds");
|
||||
return m_coalescedArr[n];
|
||||
}
|
||||
else
|
||||
{
|
||||
const uint32 nWorkerThreadId = (n & 0x7F00007F) >> 24; // Mask bit 24-30 (0 is starting bit)
|
||||
const uint32 nOffset = (n & ~0xFF000000); // Mask out top 8 bits
|
||||
|
||||
// Encoded offset into worker local array
|
||||
if (nHasWorkerEncodedIndex)
|
||||
{
|
||||
return m_workers[nWorkerThreadId].m_data[nOffset];
|
||||
}
|
||||
else // None-coalesced and none worker encoded offset
|
||||
{
|
||||
uint32 nTotalOffset = nOffset;
|
||||
for (int i = 0; i < m_nNumWorkers; ++i)
|
||||
{
|
||||
SWorker& worker = m_workers[i];
|
||||
|
||||
if (nTotalOffset < worker.m_dataSize)
|
||||
{
|
||||
return worker.m_data[nTotalOffset];
|
||||
}
|
||||
else
|
||||
{
|
||||
nTotalOffset -= worker.m_dataSize;
|
||||
}
|
||||
}
|
||||
|
||||
// Out of bound access detected!
|
||||
CRY_ASSERT_MESSAGE(false, "CThreadSafeWorkerContainer::operator[] - Out of bounds access");
|
||||
__debugbreak();
|
||||
AZ_Assert(m_coalescedArr, "null array");
|
||||
AZ_Assert(m_coalescedArrCapacity > 0, "Index out of bounds");
|
||||
return m_coalescedArr[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T>
|
||||
inline const T& CThreadSafeWorkerContainer<T>::operator[](size_t n) const
|
||||
{
|
||||
return const_cast<const T&>(const_cast<CThreadSafeWorkerContainer<T>*>(this)->operator[](n));
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T>
|
||||
inline T* CThreadSafeWorkerContainer<T>::push_back_new()
|
||||
{
|
||||
size_t unused = ~0;
|
||||
return push_back_impl(unused);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T>
|
||||
inline T* CThreadSafeWorkerContainer<T>::push_back_new(size_t& nIndex)
|
||||
{
|
||||
return push_back_impl(nIndex);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T>
|
||||
inline void CThreadSafeWorkerContainer<T>::push_back(const T& rObj)
|
||||
{
|
||||
size_t nUnused = ~0;
|
||||
T* pObj = push_back_impl(nUnused);
|
||||
*pObj = rObj;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T>
|
||||
inline void CThreadSafeWorkerContainer<T>::push_back(const T& rObj, size_t& nIndex)
|
||||
{
|
||||
T* pObj = push_back_impl(nIndex);
|
||||
*pObj = rObj;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T>
|
||||
inline void CThreadSafeWorkerContainer<T>::clear()
|
||||
{
|
||||
clear(typename std::is_destructible<T>::type());
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void CThreadSafeWorkerContainer<T>::clear(AZStd::true_type)
|
||||
{
|
||||
clear(SDefaultDestructorFunctor());
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void CThreadSafeWorkerContainer<T>::clear(AZStd::false_type)
|
||||
{
|
||||
clear(SDefaultNoOpFunctor());
|
||||
}
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T>
|
||||
template<class OnElementDeleteFunctor>
|
||||
inline void CThreadSafeWorkerContainer<T>::clear(const OnElementDeleteFunctor& rFunctor)
|
||||
{
|
||||
// Reset worker data
|
||||
for (int i = 0; i < m_nNumWorkers; ++i)
|
||||
{
|
||||
// Delete elements
|
||||
uint32 nSize = m_workers[i].m_data.size();
|
||||
for (int j = 0; j < nSize; ++j)
|
||||
{
|
||||
// Call on element delete functor
|
||||
// Note: Default functor will do nothing with the element
|
||||
rFunctor(&m_workers[i].m_data[j]);
|
||||
}
|
||||
|
||||
m_workers[i].m_data.clear();
|
||||
m_workers[i].m_dataSize = 0;
|
||||
}
|
||||
|
||||
// Reset container data
|
||||
if (m_coalescedArr)
|
||||
{
|
||||
CryModuleMemalignFree(m_coalescedArr);
|
||||
}
|
||||
|
||||
m_coalescedArr = 0;
|
||||
m_coalescedArrCapacity = 0;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T>
|
||||
inline void CThreadSafeWorkerContainer<T>::erase(const T& rObj)
|
||||
{
|
||||
for (int i = 0; i < m_nNumWorkers; ++i)
|
||||
{
|
||||
typename std::vector<T>::iterator iter = m_workers[i].m_data.begin();
|
||||
typename std::vector<T>::iterator iterEnd = m_workers[i].m_data.end();
|
||||
|
||||
for (; iter != iterEnd; ++iter)
|
||||
{
|
||||
if (rObj == *iter)
|
||||
{
|
||||
m_workers[i].m_data.erase(iter);
|
||||
--m_workers[i].m_dataSize;
|
||||
m_isCoalesced = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T>
|
||||
inline void CThreadSafeWorkerContainer<T>::resize(size_t n)
|
||||
{
|
||||
CoalesceMemory();
|
||||
|
||||
uint32 nSizePerWorker = n / m_nNumWorkers;
|
||||
uint32 nExcessSize = n % m_nNumWorkers;
|
||||
|
||||
// Resize workers evenly
|
||||
for (int i = 0; i < m_nNumWorkers; ++i)
|
||||
{
|
||||
uint32 nWorkerSize = nSizePerWorker + nExcessSize;
|
||||
|
||||
if (nWorkerSize > m_workers[i].m_data.size())
|
||||
{
|
||||
m_workers[i].m_data.resize(nWorkerSize);
|
||||
}
|
||||
|
||||
m_workers[i].m_dataSize = nWorkerSize;
|
||||
nExcessSize = 0; // First worker creates excess items
|
||||
}
|
||||
|
||||
ReserverCoalescedMemory(n);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T>
|
||||
inline void CThreadSafeWorkerContainer<T>::reserve(size_t n)
|
||||
{
|
||||
CoalesceMemory();
|
||||
|
||||
uint32 nSizePerWorker = n / m_nNumWorkers;
|
||||
uint32 nExcessSize = n % m_nNumWorkers;
|
||||
|
||||
// Resize workers evenly
|
||||
for (int i = 0; i < m_nNumWorkers; ++i)
|
||||
{
|
||||
uint32 nWorkerSize = nSizePerWorker + nExcessSize;
|
||||
|
||||
if (nWorkerSize > m_workers[i].m_data.size())
|
||||
{
|
||||
m_workers[i].m_data.resize(nWorkerSize);
|
||||
}
|
||||
|
||||
nExcessSize = 0; // First worker creates excess items
|
||||
}
|
||||
|
||||
ReserverCoalescedMemory(n);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T>
|
||||
inline void CThreadSafeWorkerContainer<T>::PrefillContainer(T* pElement, size_t numElements)
|
||||
{
|
||||
reserve(numElements);
|
||||
|
||||
uint32 nOffset = 0;
|
||||
uint32 nNumItemPerWorker = numElements / m_nNumWorkers;
|
||||
uint32 nNumExcessItems = numElements % m_nNumWorkers;
|
||||
|
||||
// Store items evenly in workers
|
||||
for (int i = 0; i < m_nNumWorkers; ++i)
|
||||
{
|
||||
uint32 nNumItems = nNumItemPerWorker + nNumExcessItems;
|
||||
for (int j = 0; j < nNumItems; ++j)
|
||||
{
|
||||
m_workers[i].m_data[j] = pElement[nOffset + j];
|
||||
}
|
||||
|
||||
m_workers[i].m_dataSize = nNumItems;
|
||||
nOffset += nNumItems;
|
||||
nNumExcessItems = 0; // First worker stores excess items
|
||||
}
|
||||
|
||||
m_isCoalesced = false;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T>
|
||||
inline void CThreadSafeWorkerContainer<T>::CoalesceMemory()
|
||||
{
|
||||
if (m_isCoalesced)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Ensure enough memory exists
|
||||
uint32 minSizeNeeded = 0;
|
||||
for (int i = 0; i < m_nNumWorkers; ++i)
|
||||
{
|
||||
minSizeNeeded += m_workers[i].m_dataSize;
|
||||
}
|
||||
|
||||
IF (minSizeNeeded >= m_coalescedArrCapacity, 0)
|
||||
{
|
||||
ReserverCoalescedMemory(minSizeNeeded + (minSizeNeeded / 4));
|
||||
}
|
||||
|
||||
// Copy data to coalesced array
|
||||
uint32 nOffest = 0;
|
||||
for (int i = 0; i < m_nNumWorkers; ++i)
|
||||
{
|
||||
SWorker& rWorker = m_workers[i];
|
||||
if (rWorker.m_dataSize == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
AZ_Assert((nOffest + rWorker.m_dataSize) <= m_coalescedArrCapacity, "Index out of bounds");
|
||||
memcpy(m_coalescedArr + nOffest, &rWorker.m_data[0], sizeof(T) * rWorker.m_dataSize);
|
||||
nOffest += rWorker.m_dataSize;
|
||||
}
|
||||
|
||||
m_isCoalesced = true;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T>
|
||||
uint32 CThreadSafeWorkerContainer<T>::ConvertToEncodedWorkerId_threadlocal(uint32 nIndex) const
|
||||
{
|
||||
const uint32 workerId = GetWorkerId_threadlocal();
|
||||
assert(nIndex < m_workers[workerId].m_dataSize);
|
||||
return (uint32)((1 << 31) | (workerId << 24) | nIndex);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
template<typename T>
|
||||
uint32 CThreadSafeWorkerContainer<T>::GetNumWorkers() const
|
||||
{
|
||||
return m_nNumWorkers;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T>
|
||||
inline void CThreadSafeWorkerContainer<T>::GetMemoryUsage(ICrySizer* pSizer) const
|
||||
{
|
||||
pSizer->AddObject(m_coalescedArr, m_coalescedArrCapacity * sizeof(T));
|
||||
|
||||
for (int i = 0; i < m_nNumWorkers; ++i)
|
||||
{
|
||||
pSizer->AddContainer(m_workers[i].m_data);
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T>
|
||||
inline void CThreadSafeWorkerContainer<T>::ReserverCoalescedMemory(size_t n)
|
||||
{
|
||||
if (n <= m_coalescedArrCapacity)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
T* arrOldData = m_coalescedArr;
|
||||
m_coalescedArr = reinterpret_cast<T*>(CryModuleMemalign(n * sizeof(T), alignof(T)));
|
||||
memcpy(m_coalescedArr, arrOldData, m_coalescedArrCapacity * sizeof(T));
|
||||
if (arrOldData)
|
||||
{
|
||||
CryModuleMemalignFree(arrOldData);
|
||||
}
|
||||
m_coalescedArrCapacity = n;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T>
|
||||
inline T* CThreadSafeWorkerContainer<T>::push_back_impl(size_t& nIndex)
|
||||
{
|
||||
// Avoid writing to thread share resource and take hit of 'if statement to avoid false-sharing between threads
|
||||
IF (m_isCoalesced, 0)
|
||||
{
|
||||
m_isCoalesced = false;
|
||||
}
|
||||
|
||||
// Get worker id
|
||||
const uint32 nWorkerThreadId = GetWorkerId_threadlocal();
|
||||
|
||||
SWorker& activeWorker = m_workers[nWorkerThreadId];
|
||||
|
||||
// Ensure enough space
|
||||
if (activeWorker.m_dataSize >= activeWorker.m_data.size())
|
||||
{
|
||||
activeWorker.m_data.resize(activeWorker.m_data.size() + (activeWorker.m_data.size() / 2) + 1);
|
||||
}
|
||||
|
||||
// Encode worker local offset into index and return
|
||||
T* retItem = &activeWorker.m_data[activeWorker.m_dataSize];
|
||||
nIndex = (size_t)((1 << 31) | (nWorkerThreadId << 24) | activeWorker.m_dataSize);
|
||||
++activeWorker.m_dataSize;
|
||||
return retItem;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
uint32 CThreadSafeWorkerContainer<T>::GetWorkerId_threadlocal() const
|
||||
{
|
||||
const uint32 workerThreadId = AZ::JobContext::GetGlobalContext()->GetJobManager().GetWorkerThreadId();
|
||||
|
||||
if (workerThreadId == AZ::JobManager::InvalidWorkerThreadId)
|
||||
{
|
||||
// Only one non-worker thread is allowed, so check to see if this is that thread.
|
||||
|
||||
const threadID currentThreadId = CryGetCurrentThreadId();
|
||||
if (m_foreignThreadId != currentThreadId)
|
||||
{
|
||||
CryFatalError("Trying to access CThreadSafeWorkerContainer from an unspecified non-worker thread. The only non-worker threadId with access rights: %" PRI_THREADID ". Current threadId: %" PRI_THREADID, m_foreignThreadId, currentThreadId);
|
||||
}
|
||||
}
|
||||
|
||||
// Non-worker has id of ~0 ... add +1 to shift to 0. Worker0 will use slot 1 etc.
|
||||
static_assert(AZ::JobManager::InvalidWorkerThreadId == ~0u, "Assumptions about InvalidWorkerId no longer hold true");
|
||||
return workerThreadId + 1;
|
||||
}
|
||||
|
||||
|
||||
#endif // CRYINCLUDE_CRYCOMMON_CRYTHREADSAFEWORKERCONTAINER_H
|
||||
@@ -1,24 +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 <cstddef> // size_t
|
||||
|
||||
namespace Detail
|
||||
{
|
||||
template <typename T, size_t size>
|
||||
char (&ArrayCountHelper(T(&)[size]))[size];
|
||||
}
|
||||
|
||||
#define CRY_ARRAY_COUNT(arr) sizeof(::Detail::ArrayCountHelper(arr))
|
||||
@@ -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.
|
||||
|
||||
#pragma once
|
||||
|
||||
// Include this file instead of including zlib.h directly
|
||||
// because zconf.h (included by zlib.h) defines WINDOWS and WIN32 - those
|
||||
// definitions conflict with CryEngine's definitions.
|
||||
|
||||
#if defined(CRY_TMP_DEFINED_WINDOWS) || defined(CRY_TMP_DEFINED_WIN32)
|
||||
# error CRY_TMP_DEFINED_WINDOWS and/or CRY_TMP_DEFINED_WIN32 already defined
|
||||
#endif
|
||||
|
||||
#if defined(WINDOWS)
|
||||
# define CRY_TMP_DEFINED_WINDOWS 1
|
||||
#endif
|
||||
#if defined(WIN32)
|
||||
# define CRY_TMP_DEFINED_WIN32 1
|
||||
#endif
|
||||
|
||||
#include <zlib.h>
|
||||
|
||||
#if !defined(CRY_TMP_DEFINED_WINDOWS)
|
||||
# undef WINDOWS
|
||||
#endif
|
||||
#undef CRY_TMP_DEFINED_WINDOWS
|
||||
#if !defined(CRY_TMP_DEFINED_WIN32)
|
||||
# undef WIN32
|
||||
#endif
|
||||
#undef CRY_TMP_DEFINED_WIN32
|
||||
@@ -1,79 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
#ifndef __CustomMemoryHeap_h__
|
||||
#define __CustomMemoryHeap_h__
|
||||
#pragma once
|
||||
|
||||
#include "IMemory.h"
|
||||
|
||||
class CCustomMemoryHeap;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
class CCustomMemoryHeapBlock
|
||||
: public ICustomMemoryBlock
|
||||
{
|
||||
public:
|
||||
CCustomMemoryHeapBlock(CCustomMemoryHeap* pHeap);
|
||||
virtual ~CCustomMemoryHeapBlock();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// IMemoryBlock
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
virtual void* GetData();
|
||||
virtual int GetSize() { return m_nSize; }
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// ICustomMemoryBlock
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
virtual void CopyMemoryRegion(void* pOutputBuffer, size_t nOffset, size_t nSize);
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
private:
|
||||
friend class CCustomMemoryHeap;
|
||||
CCustomMemoryHeap* m_pHeap;
|
||||
string m_sUsage;
|
||||
void* m_pData;
|
||||
uint32 m_nGPUHandle;
|
||||
size_t m_nSize;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
class CCustomMemoryHeap
|
||||
: public ICustomMemoryHeap
|
||||
{
|
||||
public:
|
||||
|
||||
explicit CCustomMemoryHeap(IMemoryManager::EAllocPolicy const eAllocPolicy);
|
||||
~CCustomMemoryHeap();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// ICustomMemoryHeap
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
virtual ICustomMemoryBlock* AllocateBlock(size_t const nAllocateSize, char const* const sUsage, size_t const nAlignment = 16);
|
||||
virtual void GetMemoryUsage(ICrySizer* pSizer);
|
||||
virtual size_t GetAllocated();
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void DeallocateBlock(CCustomMemoryHeapBlock* pBlock);
|
||||
|
||||
private:
|
||||
|
||||
friend class CCustomMemoryHeapBlock;
|
||||
int m_nAllocatedSize;
|
||||
IMemoryManager::EAllocPolicy m_eAllocPolicy;
|
||||
IMemoryManager::HeapHandle m_nTraceHeapHandle;
|
||||
};
|
||||
|
||||
#endif // __CustomMemoryHeap_h__
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,469 +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 : Facility for efficiently generating random positions on geometry
|
||||
|
||||
#ifndef CRYINCLUDE_CRYCOMMON_GEOMQUERY_H
|
||||
#define CRYINCLUDE_CRYCOMMON_GEOMQUERY_H
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "Cry_Geo.h"
|
||||
#include "CryArray.h"
|
||||
#include "Random.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Extents cache
|
||||
|
||||
class CGeomExtent
|
||||
{
|
||||
public:
|
||||
|
||||
CGeomExtent()
|
||||
: m_nEmptyEndParts(0) {}
|
||||
|
||||
ILINE operator bool() const
|
||||
{
|
||||
return m_afCumExtents.capacity() + m_nEmptyEndParts != 0;
|
||||
}
|
||||
ILINE int NumParts() const
|
||||
{
|
||||
return m_afCumExtents.size();
|
||||
}
|
||||
ILINE float TotalExtent() const
|
||||
{
|
||||
return !m_afCumExtents.empty() ? m_afCumExtents.back() : 0.f;
|
||||
}
|
||||
|
||||
void Clear()
|
||||
{
|
||||
m_afCumExtents.clear();
|
||||
m_nEmptyEndParts = 0;
|
||||
}
|
||||
void AddPart(float fExtent)
|
||||
{
|
||||
// Defer empty parts until a non-empty part is added.
|
||||
if (fExtent <= 0.f)
|
||||
{
|
||||
m_nEmptyEndParts++;
|
||||
}
|
||||
else
|
||||
{
|
||||
float fTotal = TotalExtent();
|
||||
for (; m_nEmptyEndParts; m_nEmptyEndParts--)
|
||||
{
|
||||
m_afCumExtents.push_back(fTotal);
|
||||
}
|
||||
m_afCumExtents.push_back(fTotal + fExtent);
|
||||
}
|
||||
}
|
||||
void ReserveParts(int nCount)
|
||||
{
|
||||
m_afCumExtents.reserve(nCount);
|
||||
}
|
||||
|
||||
// Find element in sorted array <= index (normalized 0 to 1)
|
||||
int GetPart(float fIndex) const
|
||||
{
|
||||
int last = m_afCumExtents.size() - 1;
|
||||
if (last <= 0)
|
||||
{
|
||||
return last;
|
||||
}
|
||||
|
||||
fIndex *= m_afCumExtents[last];
|
||||
|
||||
// Binary search thru array.
|
||||
int lo = 0, hi = last;
|
||||
while (lo < hi)
|
||||
{
|
||||
int i = (lo + hi) >> 1;
|
||||
if (fIndex < m_afCumExtents[i])
|
||||
{
|
||||
hi = i;
|
||||
}
|
||||
else
|
||||
{
|
||||
lo = i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
assert(lo == 0 || m_afCumExtents[lo] > m_afCumExtents[lo - 1]);
|
||||
return lo;
|
||||
}
|
||||
|
||||
int RandomPart() const
|
||||
{
|
||||
return GetPart(cry_random(0.0f, 1.0f));
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
DynArray<float> m_afCumExtents;
|
||||
int m_nEmptyEndParts;
|
||||
};
|
||||
|
||||
class CGeomExtents
|
||||
{
|
||||
public:
|
||||
|
||||
ILINE CGeomExtents()
|
||||
: m_aExtents(0) {}
|
||||
~CGeomExtents()
|
||||
{ delete[] m_aExtents; }
|
||||
|
||||
void Clear()
|
||||
{
|
||||
delete[] m_aExtents;
|
||||
m_aExtents = 0;
|
||||
}
|
||||
|
||||
ILINE CGeomExtent const& operator [](EGeomForm eForm) const
|
||||
{
|
||||
assert(eForm >= 0 && eForm < MaxGeomForm);
|
||||
if (m_aExtents)
|
||||
{
|
||||
return m_aExtents[eForm];
|
||||
}
|
||||
|
||||
static CGeomExtent s_empty;
|
||||
return s_empty;
|
||||
}
|
||||
|
||||
ILINE CGeomExtent& Make(EGeomForm eForm)
|
||||
{
|
||||
assert(eForm >= 0 && eForm < MaxGeomForm);
|
||||
if (!m_aExtents)
|
||||
{
|
||||
m_aExtents = new CGeomExtent[4];
|
||||
}
|
||||
return m_aExtents[eForm];
|
||||
}
|
||||
|
||||
protected:
|
||||
CGeomExtent* m_aExtents;
|
||||
};
|
||||
|
||||
|
||||
// Other random/extent functions
|
||||
|
||||
inline float ScaleExtent(EGeomForm eForm, float fScale)
|
||||
{
|
||||
switch (eForm)
|
||||
{
|
||||
default:
|
||||
return 1;
|
||||
case GeomForm_Edges:
|
||||
return fScale;
|
||||
case GeomForm_Surface:
|
||||
return fScale * fScale;
|
||||
case GeomForm_Volume:
|
||||
return fScale * fScale * fScale;
|
||||
}
|
||||
}
|
||||
|
||||
inline float BoxExtent(EGeomForm eForm, Vec3 const& vSize)
|
||||
{
|
||||
switch (eForm)
|
||||
{
|
||||
default:
|
||||
assert(0);
|
||||
case GeomForm_Vertices:
|
||||
return 8.f;
|
||||
case GeomForm_Edges:
|
||||
return (vSize.x + vSize.y + vSize.z) * 8.f;
|
||||
case GeomForm_Surface:
|
||||
return (vSize.x * vSize.y + vSize.x * vSize.z + vSize.y * vSize.z) * 8.f;
|
||||
case GeomForm_Volume:
|
||||
return vSize.x * vSize.y * vSize.z * 8.f;
|
||||
}
|
||||
}
|
||||
|
||||
// Utility functions.
|
||||
|
||||
template<class T>
|
||||
inline
|
||||
const typename T::value_type& RandomElem(const T& array)
|
||||
{
|
||||
int n = cry_random(0U, array.size() - 1);
|
||||
return array[n];
|
||||
}
|
||||
|
||||
// Geometric primitive randomizing functions.
|
||||
ILINE void BoxRandomPos(PosNorm& ran, EGeomForm eForm, Vec3 const& vSize)
|
||||
{
|
||||
ran.vPos = cry_random_componentwise(-vSize, vSize);
|
||||
ran.vNorm = ran.vPos;
|
||||
|
||||
if (eForm != GeomForm_Volume)
|
||||
{
|
||||
// Generate a random corner, for collapsing random point.
|
||||
int nCorner = cry_random(0, 7);
|
||||
ran.vNorm.x = (((nCorner & 1) << 1) - 1) * vSize.x;
|
||||
ran.vNorm.y = (((nCorner & 2)) - 1) * vSize.y;
|
||||
ran.vNorm.z = (((nCorner & 4) >> 1) - 1) * vSize.z;
|
||||
|
||||
if (eForm == GeomForm_Vertices)
|
||||
{
|
||||
ran.vPos = ran.vNorm;
|
||||
}
|
||||
else if (eForm == GeomForm_Surface)
|
||||
{
|
||||
// Collapse one axis.
|
||||
float fAxis = cry_random(0.0f, vSize.x * vSize.y + vSize.y * vSize.z + vSize.z * vSize.x);
|
||||
if ((fAxis -= vSize.y * vSize.z) < 0.f)
|
||||
{
|
||||
ran.vPos.x = ran.vNorm.x;
|
||||
ran.vNorm.y = ran.vNorm.z = 0.f;
|
||||
}
|
||||
else if ((fAxis -= vSize.z * vSize.x) < 0.f)
|
||||
{
|
||||
ran.vPos.y = ran.vNorm.y;
|
||||
ran.vNorm.x = ran.vNorm.z = 0.f;
|
||||
}
|
||||
else
|
||||
{
|
||||
ran.vPos.z = ran.vNorm.z;
|
||||
ran.vNorm.x = ran.vNorm.y = 0.f;
|
||||
}
|
||||
}
|
||||
else if (eForm == GeomForm_Edges)
|
||||
{
|
||||
// Collapse 2 axes.
|
||||
float fAxis = cry_random(0.0f, vSize.x + vSize.y + vSize.z);
|
||||
if ((fAxis -= vSize.x) < 0.f)
|
||||
{
|
||||
ran.vPos.y = ran.vNorm.y;
|
||||
ran.vPos.z = ran.vNorm.z;
|
||||
ran.vNorm.x = 0.f;
|
||||
}
|
||||
else if ((fAxis -= vSize.y) < 0.f)
|
||||
{
|
||||
ran.vPos.x = ran.vNorm.x;
|
||||
ran.vPos.z = ran.vNorm.z;
|
||||
ran.vNorm.y = 0.f;
|
||||
}
|
||||
else
|
||||
{
|
||||
ran.vPos.x = ran.vNorm.x;
|
||||
ran.vPos.y = ran.vNorm.y;
|
||||
ran.vNorm.z = 0.f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ran.vNorm.Normalize();
|
||||
}
|
||||
|
||||
inline float CircleExtent(EGeomForm eForm, float fRadius)
|
||||
{
|
||||
switch (eForm)
|
||||
{
|
||||
case GeomForm_Edges:
|
||||
return gf_PI2 * fRadius;
|
||||
case GeomForm_Surface:
|
||||
return gf_PI * square(fRadius);
|
||||
default:
|
||||
return 1.f;
|
||||
}
|
||||
}
|
||||
|
||||
inline Vec2 CircleRandomPoint(EGeomForm eForm, float fRadius)
|
||||
{
|
||||
Vec2 vPt;
|
||||
switch (eForm)
|
||||
{
|
||||
case GeomForm_Edges:
|
||||
// Generate random angle.
|
||||
sincos_tpl(cry_random(0.0f, gf_PI2), &vPt.y, &vPt.x);
|
||||
vPt *= fRadius;
|
||||
break;
|
||||
case GeomForm_Surface:
|
||||
// Generate random angle, and radius, adjusted for even distribution.
|
||||
sincos_tpl(cry_random(0.0f, gf_PI2), &vPt.y, &vPt.x);
|
||||
vPt *= sqrt(cry_random(0.0f, 1.0f)) * fRadius;
|
||||
break;
|
||||
default:
|
||||
vPt.x = vPt.y = 0.f;
|
||||
}
|
||||
return vPt;
|
||||
}
|
||||
|
||||
inline float SphereExtent(EGeomForm eForm, float fRadius)
|
||||
{
|
||||
switch (eForm)
|
||||
{
|
||||
default:
|
||||
assert(0);
|
||||
case GeomForm_Vertices:
|
||||
case GeomForm_Edges:
|
||||
return 0.f;
|
||||
case GeomForm_Surface:
|
||||
return gf_PI * 4.f * sqr(fRadius);
|
||||
case GeomForm_Volume:
|
||||
return gf_PI * 4.f / 3.f * cube(fRadius);
|
||||
}
|
||||
}
|
||||
|
||||
inline void SphereRandomPos(PosNorm& ran, EGeomForm eForm, float fRadius)
|
||||
{
|
||||
switch (eForm)
|
||||
{
|
||||
default:
|
||||
assert(0);
|
||||
case GeomForm_Vertices:
|
||||
case GeomForm_Edges:
|
||||
ran.vPos.zero();
|
||||
ran.vNorm.zero();
|
||||
return;
|
||||
case GeomForm_Surface:
|
||||
case GeomForm_Volume:
|
||||
{
|
||||
// Generate point on surface, as normal.
|
||||
float fPhi = cry_random(0.0f, gf_PI2);
|
||||
float fZ = cry_random(-1.f, 1.f);
|
||||
float fH = sqrt_tpl(1.f - fZ * fZ);
|
||||
sincos_tpl(fPhi, &ran.vNorm.y, &ran.vNorm.x);
|
||||
ran.vNorm.x *= fH;
|
||||
ran.vNorm.y *= fH;
|
||||
ran.vNorm.z = fZ;
|
||||
|
||||
ran.vPos = ran.vNorm;
|
||||
if (eForm == GeomForm_Volume)
|
||||
{
|
||||
float fV = cry_random(0.0f, 1.0f);
|
||||
float fR = pow_tpl(fV, 0.333333f);
|
||||
ran.vPos *= fR;
|
||||
}
|
||||
ran.vPos *= fRadius;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Triangle randomisation functions
|
||||
|
||||
inline float TriExtent(EGeomForm eForm, Vec3 const aPos[3])
|
||||
{
|
||||
switch (eForm)
|
||||
{
|
||||
default:
|
||||
assert(0);
|
||||
case GeomForm_Edges:
|
||||
return (aPos[1] - aPos[0]).GetLengthFast();
|
||||
case GeomForm_Surface:
|
||||
return ((aPos[1] - aPos[0]) % (aPos[2] - aPos[0])).GetLengthFast() * 0.5f;
|
||||
case GeomForm_Volume:
|
||||
// Generate signed volume of pyramid by computing triple product of vertices.
|
||||
return ((aPos[0] ^ aPos[1]) | aPos[2]) / 6.0f;
|
||||
}
|
||||
}
|
||||
|
||||
inline void TriRandomPos(PosNorm& ran, EGeomForm eForm, PosNorm const aRan[3], bool bDoNormals)
|
||||
{
|
||||
// Generate interpolators for verts.
|
||||
switch (eForm)
|
||||
{
|
||||
default:
|
||||
assert(0);
|
||||
case GeomForm_Vertices:
|
||||
ran = aRan[0];
|
||||
return;
|
||||
case GeomForm_Edges:
|
||||
{
|
||||
float t = cry_random(0.0f, 1.0f);
|
||||
ran.vPos = aRan[0].vPos * (1.f - t) + aRan[1].vPos * t;
|
||||
if (bDoNormals)
|
||||
{
|
||||
ran.vNorm = aRan[0].vNorm * (1.f - t) + aRan[1].vNorm * t;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case GeomForm_Surface:
|
||||
{
|
||||
float t0 = cry_random(0.0f, 1.0f);
|
||||
float t1 = cry_random(0.0f, 1.0f);
|
||||
float t2 = cry_random(0.0f, 1.0f);
|
||||
float fSum = t0 + t1 + t2;
|
||||
ran.vPos = (aRan[0].vPos * t0 + aRan[1].vPos * t1 + aRan[2].vPos * t2) * (1.f / fSum);
|
||||
if (bDoNormals)
|
||||
{
|
||||
ran.vNorm = aRan[0].vNorm * t0 + aRan[1].vNorm * t1 + aRan[2].vNorm * t2;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case GeomForm_Volume:
|
||||
{
|
||||
float t0 = cry_random(0.0f, 1.0f);
|
||||
float t1 = cry_random(0.0f, 1.0f);
|
||||
float t2 = cry_random(0.0f, 1.0f);
|
||||
float t3 = cry_random(0.0f, 1.0f);
|
||||
float fSum = t0 + t1 + t2 + t3;
|
||||
ran.vPos = (aRan[0].vPos * t0 + aRan[1].vPos * t1 + aRan[2].vPos * t2) * (1.f / fSum);
|
||||
if (bDoNormals)
|
||||
{
|
||||
ran.vNorm = (aRan[0].vNorm * t0 + aRan[1].vNorm * t1 + aRan[2].vNorm * t2) * (1.f - t3) + ran.vPos.GetNormalizedFast() * t3;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (bDoNormals)
|
||||
{
|
||||
ran.vNorm.Normalize();
|
||||
}
|
||||
}
|
||||
|
||||
// Mesh random pos functions
|
||||
|
||||
inline int TriMeshPartCount(EGeomForm eForm, int nIndices)
|
||||
{
|
||||
switch (eForm)
|
||||
{
|
||||
default:
|
||||
assert(0);
|
||||
case GeomForm_Vertices:
|
||||
case GeomForm_Edges:
|
||||
// Number of edges = verts.
|
||||
return nIndices;
|
||||
case GeomForm_Surface:
|
||||
case GeomForm_Volume:
|
||||
// Number of tris.
|
||||
assert(nIndices % 3 == 0);
|
||||
return nIndices / 3;
|
||||
}
|
||||
}
|
||||
|
||||
inline int TriIndices(int aIndices[3], int nPart, EGeomForm eForm)
|
||||
{
|
||||
switch (eForm)
|
||||
{
|
||||
default:
|
||||
assert(0);
|
||||
case GeomForm_Vertices: // Part is vert index
|
||||
aIndices[0] = nPart;
|
||||
return 1;
|
||||
case GeomForm_Edges: // Part is vert index
|
||||
aIndices[0] = nPart;
|
||||
aIndices[1] = nPart % 3 < 2 ? nPart + 1 : nPart - 2;
|
||||
return 2;
|
||||
case GeomForm_Surface: // Part is tri index
|
||||
case GeomForm_Volume:
|
||||
aIndices[0] = nPart * 3;
|
||||
aIndices[1] = aIndices[0] + 1;
|
||||
aIndices[2] = aIndices[0] + 2;
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif // CRYINCLUDE_CRYCOMMON_GEOMQUERY_H
|
||||
@@ -1,617 +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_HASHGRID_H
|
||||
#define CRYINCLUDE_CRYCOMMON_HASHGRID_H
|
||||
#pragma once
|
||||
|
||||
|
||||
|
||||
template<typename Key, typename DiscreetKey>
|
||||
struct hash_grid_2d
|
||||
{
|
||||
typedef Key key_type;
|
||||
typedef typename key_type::value_type key_value;
|
||||
|
||||
typedef DiscreetKey discreet_type;
|
||||
typedef typename discreet_type::value_type discreet_value;
|
||||
|
||||
typedef hash_grid_2d<Key, DiscreetKey> type;
|
||||
|
||||
hash_grid_2d(const key_value& cellSizeX, const key_value& cellSizeY, const key_value& cellSizeZ)
|
||||
: scaleFactorX(1 / cellSizeX)
|
||||
, scaleFactorY(1 / cellSizeY)
|
||||
{
|
||||
}
|
||||
|
||||
inline discreet_type discreet(const key_type& key) const
|
||||
{
|
||||
return discreet_type(static_cast<discreet_value>(key[0] * scaleFactorX),
|
||||
static_cast<discreet_value>(key[1] * scaleFactorY),
|
||||
static_cast<discreet_value>(0));
|
||||
}
|
||||
|
||||
inline size_t hash(const key_type& key) const
|
||||
{
|
||||
return hash(discreet(key));
|
||||
}
|
||||
|
||||
inline size_t hash(const discreet_type& discreet) const
|
||||
{
|
||||
return static_cast<size_t>(
|
||||
(discreet[0] ^ 920129341) +
|
||||
(discreet[1] ^ 1926129311));
|
||||
}
|
||||
|
||||
inline void swap(type& other)
|
||||
{
|
||||
std::swap(scaleFactorX, other.scaleFactorX);
|
||||
std::swap(scaleFactorY, other.scaleFactorY);
|
||||
}
|
||||
|
||||
private:
|
||||
key_value scaleFactorX;
|
||||
key_value scaleFactorY;
|
||||
};
|
||||
|
||||
|
||||
template<typename Key, typename DiscreetKey>
|
||||
struct hash_grid_3d
|
||||
{
|
||||
typedef Key key_type;
|
||||
typedef typename key_type::value_type key_value;
|
||||
|
||||
typedef DiscreetKey discreet_type;
|
||||
typedef typename discreet_type::value_type discreet_value;
|
||||
|
||||
typedef hash_grid_3d<Key, DiscreetKey> type;
|
||||
|
||||
hash_grid_3d(const key_value& cellSizeX, const key_value& cellSizeY, const key_value& cellSizeZ)
|
||||
: scaleFactorX(1 / cellSizeX)
|
||||
, scaleFactorY(1 / cellSizeY)
|
||||
, scaleFactorZ(1 / cellSizeZ)
|
||||
{
|
||||
}
|
||||
|
||||
inline discreet_type discreet(const key_type& key) const
|
||||
{
|
||||
return discreet_type(static_cast<discreet_value>(key[0] * scaleFactorX),
|
||||
static_cast<discreet_value>(key[1] * scaleFactorY),
|
||||
static_cast<discreet_value>(key[2] * scaleFactorZ));
|
||||
}
|
||||
|
||||
inline size_t hash(const key_type& key) const
|
||||
{
|
||||
return hash(discreet(key));
|
||||
}
|
||||
|
||||
inline size_t hash(const discreet_type& discreet) const
|
||||
{
|
||||
return static_cast<size_t>(
|
||||
(discreet[0] ^ 920129341ul) +
|
||||
(discreet[1] ^ 1926129311ul) +
|
||||
(discreet[2] ^ 3926129401ul));
|
||||
}
|
||||
|
||||
inline void swap(type& other)
|
||||
{
|
||||
std::swap(scaleFactorX, other.scaleFactorX);
|
||||
std::swap(scaleFactorY, other.scaleFactorY);
|
||||
std::swap(scaleFactorZ, other.scaleFactorZ);
|
||||
}
|
||||
|
||||
private:
|
||||
key_value scaleFactorX;
|
||||
key_value scaleFactorY;
|
||||
key_value scaleFactorZ;
|
||||
};
|
||||
|
||||
|
||||
template<typename KeyType, typename ValueType>
|
||||
struct hash_grid_no_position
|
||||
{
|
||||
KeyType operator()(const ValueType&) const
|
||||
{
|
||||
switch (0)
|
||||
{
|
||||
case 0:
|
||||
"hash_grid query performed without a valid position-retriever implementation";
|
||||
}
|
||||
;
|
||||
|
||||
return KeyType();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template<int NumberOfCells, typename ValueType, typename KeyHash,
|
||||
typename PositionRetriever = hash_grid_no_position<typename KeyHash::key_type, ValueType> >
|
||||
class hash_grid
|
||||
: protected KeyHash
|
||||
{
|
||||
public:
|
||||
enum
|
||||
{
|
||||
CellCount = NumberOfCells,
|
||||
};
|
||||
|
||||
typedef ValueType value_type;
|
||||
typedef KeyHash key_hash;
|
||||
|
||||
typedef typename key_hash::key_type key_type;
|
||||
typedef typename key_type::value_type key_value;
|
||||
typedef typename key_hash::discreet_type discreet_type;
|
||||
typedef typename discreet_type::value_type discreet_value;
|
||||
|
||||
|
||||
typedef PositionRetriever position_retriever_type;
|
||||
|
||||
typedef hash_grid<NumberOfCells, ValueType, KeyHash, PositionRetriever> type;
|
||||
|
||||
typedef std::vector<value_type> items_type;
|
||||
|
||||
struct cell_type
|
||||
{
|
||||
cell_type()
|
||||
: query(0)
|
||||
{
|
||||
}
|
||||
|
||||
mutable uint32 query;
|
||||
items_type items;
|
||||
};
|
||||
typedef std::vector<cell_type> cells_type;
|
||||
|
||||
inline hash_grid(float cellSizeX = 20.0f, float cellSizeY = 20.0f, float cellSizeZ = 20.0f,
|
||||
const position_retriever_type& _position = position_retriever_type())
|
||||
: key_hash(cellSizeX, cellSizeY, cellSizeZ)
|
||||
, position(_position)
|
||||
, m_cells(CellCount)
|
||||
, m_count(0)
|
||||
, m_query(0)
|
||||
{
|
||||
}
|
||||
|
||||
inline void clear()
|
||||
{
|
||||
m_cells.clear();
|
||||
m_cells.resize(CellCount);
|
||||
m_count = 0;
|
||||
m_query = 0;
|
||||
}
|
||||
|
||||
inline void swap(type& other)
|
||||
{
|
||||
m_cells.swap(other);
|
||||
|
||||
std::swap(m_count, other.m_count);
|
||||
key_hash::swap(other);
|
||||
}
|
||||
|
||||
inline size_t size() const
|
||||
{
|
||||
return m_count;
|
||||
}
|
||||
|
||||
inline bool empty() const
|
||||
{
|
||||
return m_count == 0;
|
||||
}
|
||||
|
||||
struct iterator
|
||||
{
|
||||
iterator()
|
||||
: cell(~0u)
|
||||
, item(~0u)
|
||||
, grid(0)
|
||||
{
|
||||
}
|
||||
|
||||
value_type& operator*()
|
||||
{
|
||||
return grid->m_cells[cell][item];
|
||||
}
|
||||
|
||||
const value_type& operator*() const
|
||||
{
|
||||
return grid->m_cells[cell][item];
|
||||
}
|
||||
|
||||
value_type* operator->() const
|
||||
{
|
||||
return (&**this);
|
||||
}
|
||||
|
||||
iterator& operator++()
|
||||
{
|
||||
assert(cell < grid_type::CellCount);
|
||||
cell_type& items = grid->m_cells[cell];
|
||||
|
||||
if (!items.empty() && (item < items.size() - 1))
|
||||
{
|
||||
++item;
|
||||
}
|
||||
else
|
||||
{
|
||||
item = 0;
|
||||
++cell;
|
||||
|
||||
while ((cell < type::CellCount) && grid->m_cells[cell].empty())
|
||||
{
|
||||
++cell;
|
||||
}
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
iterator operator++(int)
|
||||
{
|
||||
iterator tmp = *this;
|
||||
++*this;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
iterator& operator--()
|
||||
{
|
||||
if (item > 0)
|
||||
{
|
||||
--item;
|
||||
}
|
||||
else
|
||||
{
|
||||
--cell;
|
||||
while ((cell > 0) && grid->m_cells[cell].empty())
|
||||
{
|
||||
--cell;
|
||||
}
|
||||
|
||||
assert(cell < type::CellCount);
|
||||
cell_type& items = grid->m_cells[cell];
|
||||
item = items.size() - 1;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
iterator operator--(int)
|
||||
{
|
||||
iterator tmp = *this;
|
||||
++*this;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
bool operator==(const iterator& other) const
|
||||
{
|
||||
return (cell == other.cell) && (item == other.item) && (grid == other.grid);
|
||||
}
|
||||
|
||||
bool operator!=(const iterator& other) const
|
||||
{
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
private:
|
||||
friend class hash_grid<NumberOfCells, ValueType, KeyHash, PositionRetriever>;
|
||||
typedef hash_grid<NumberOfCells, ValueType, KeyHash, PositionRetriever> grid_type;
|
||||
|
||||
iterator(size_t _cell, size_t _item, grid_type* _grid)
|
||||
: grid(_grid)
|
||||
, item(_item)
|
||||
, cell(_cell)
|
||||
{
|
||||
}
|
||||
|
||||
grid_type* grid;
|
||||
size_t cell;
|
||||
size_t item;
|
||||
};
|
||||
|
||||
inline iterator begin()
|
||||
{
|
||||
uint32 item = 0;
|
||||
uint32 cell = 0;
|
||||
|
||||
while ((cell < type::CellCount) && m_cells[cell].empty())
|
||||
{
|
||||
++cell;
|
||||
}
|
||||
|
||||
return iterator(cell, item, this);
|
||||
}
|
||||
|
||||
inline iterator end()
|
||||
{
|
||||
return iterator(CellCount, 0, this);
|
||||
}
|
||||
|
||||
inline iterator insert(const key_type& key, const value_type& value)
|
||||
{
|
||||
size_t hash_value = KeyHash::hash(key);
|
||||
size_t index = hash_value % CellCount;
|
||||
|
||||
cell_type& cell = m_cells[index];
|
||||
items_type& items = cell.items;
|
||||
|
||||
items.push_back(value);
|
||||
++m_count;
|
||||
|
||||
return iterator(index, items.size() - 1, this);
|
||||
}
|
||||
|
||||
inline void erase(const key_type& key, const value_type& value)
|
||||
{
|
||||
size_t hash_value = KeyHash::hash(key);
|
||||
size_t index = hash_value % CellCount;
|
||||
|
||||
cell_type& cell = m_cells[index];
|
||||
items_type& items = cell.items;
|
||||
|
||||
typename items_type::iterator it = items.begin();
|
||||
typename items_type::iterator end = items.end();
|
||||
|
||||
for (; it != end; ++it)
|
||||
{
|
||||
if (*it == value)
|
||||
{
|
||||
std::swap(*it, items.back());
|
||||
items.pop_back();
|
||||
--m_count;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline iterator erase(const iterator& it)
|
||||
{
|
||||
--m_count;
|
||||
cell_type& cell = m_cells[it.cell];
|
||||
items_type& items = cell.items;
|
||||
std::swap(items[it.item], items.back());
|
||||
items.pop_back();
|
||||
if (!items.empty())
|
||||
{
|
||||
return it;
|
||||
}
|
||||
|
||||
uint32 index = it.cell;
|
||||
while ((index < CellCount) && m_cells[index].items.empty())
|
||||
{
|
||||
++index;
|
||||
}
|
||||
|
||||
return iterator(index, 0, this);
|
||||
}
|
||||
|
||||
inline iterator find(const key_type& key, const value_type& value)
|
||||
{
|
||||
size_t index = KeyHash::hash(key) % CellCount;
|
||||
|
||||
cell_type& cell = m_cells[index];
|
||||
items_type& items = cell.items;
|
||||
typename items_type::iterator it = items.begin();
|
||||
typename items_type::iterator iend = items.end();
|
||||
|
||||
for (; it != iend; ++it)
|
||||
{
|
||||
if (*it == value)
|
||||
{
|
||||
return iterator(index, it - items.begin(), this);
|
||||
}
|
||||
}
|
||||
|
||||
return end();
|
||||
}
|
||||
|
||||
inline iterator move(const iterator& it, const key_type& to)
|
||||
{
|
||||
size_t index = KeyHash::hash(to) % CellCount;
|
||||
|
||||
if (index == it.cell)
|
||||
{
|
||||
return it;
|
||||
}
|
||||
|
||||
cell_type& cell = m_cells[it.cell];
|
||||
items_type& items = cell.items;
|
||||
typename items_type::iterator iit = items.begin() + it.item;
|
||||
|
||||
cell_type& to_cell = m_cells[index];
|
||||
items_type& to_items = to_cell.items;
|
||||
to_items.push_back(*iit);
|
||||
|
||||
std::swap(items[it.item], items.back());
|
||||
items.pop_back();
|
||||
|
||||
return iterator(index, to_items.size() - 1, this);
|
||||
}
|
||||
|
||||
template<typename Container>
|
||||
uint32 query_sphere(const key_type& center, const key_value& radius, Container& container) const
|
||||
{
|
||||
uint32 count = 0;
|
||||
|
||||
if (!empty())
|
||||
{
|
||||
++m_query;
|
||||
|
||||
key_type minc(center - key_type(radius));
|
||||
key_type maxc(center + key_type(radius));
|
||||
|
||||
discreet_type mind = KeyHash::discreet(minc);
|
||||
discreet_type maxd = KeyHash::discreet(maxc);
|
||||
discreet_type current = mind;
|
||||
|
||||
float radius_sq = radius * radius;
|
||||
|
||||
for (; current[0] <= maxd[0]; ++current[0])
|
||||
{
|
||||
for (; current[1] <= maxd[1]; ++current[1])
|
||||
{
|
||||
for (; current[2] <= maxd[2]; ++current[2])
|
||||
{
|
||||
size_t hash_value = KeyHash::hash(current);
|
||||
size_t index = hash_value % CellCount;
|
||||
|
||||
const cell_type& cell = m_cells[index];
|
||||
|
||||
if (cell.query != m_query)
|
||||
{
|
||||
cell.query = m_query;
|
||||
const items_type& items = cell.items;
|
||||
|
||||
typename items_type::const_iterator it = items.begin();
|
||||
typename items_type::const_iterator end = items.end();
|
||||
|
||||
for (; it != end; ++it)
|
||||
{
|
||||
if ((position(*it) - center).len2() <= radius_sq)
|
||||
{
|
||||
container.push_back(*it);
|
||||
++count;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
current[2] = mind[2];
|
||||
}
|
||||
current[1] = mind[1];
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
template<typename Container>
|
||||
uint32 query_sphere_distance(const key_type& center, const key_value& radius, Container& container) const
|
||||
{
|
||||
uint32 count = 0;
|
||||
|
||||
if (!empty())
|
||||
{
|
||||
++m_query;
|
||||
|
||||
key_type minc(center - key_type(radius));
|
||||
key_type maxc(center + key_type(radius));
|
||||
|
||||
discreet_type mind = KeyHash::discreet(minc);
|
||||
discreet_type maxd = KeyHash::discreet(maxc);
|
||||
discreet_type current = mind;
|
||||
|
||||
float radius_sq = radius * radius;
|
||||
|
||||
for (; current[0] <= maxd[0]; ++current[0])
|
||||
{
|
||||
for (; current[1] <= maxd[1]; ++current[1])
|
||||
{
|
||||
for (; current[2] <= maxd[2]; ++current[2])
|
||||
{
|
||||
size_t hash_value = KeyHash::hash(current);
|
||||
size_t index = hash_value % CellCount;
|
||||
|
||||
const cell_type& cell = m_cells[index];
|
||||
|
||||
if (cell.query != m_query)
|
||||
{
|
||||
cell.query = m_query;
|
||||
const items_type& items = cell.items;
|
||||
|
||||
typename items_type::const_iterator it = items.begin();
|
||||
typename items_type::const_iterator end = items.end();
|
||||
|
||||
for (; it != end; ++it)
|
||||
{
|
||||
float distance_sq = (position(*it) - center).len2();
|
||||
if (distance_sq <= radius_sq)
|
||||
{
|
||||
container.push_back(std::make_pair(distance_sq, *it));
|
||||
++count;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
current[2] = mind[2];
|
||||
}
|
||||
current[1] = mind[1];
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
template<typename Container>
|
||||
uint32 query_box(const key_type& minc, const key_type& maxc, Container& container) const
|
||||
{
|
||||
uint32 count = 0;
|
||||
|
||||
if (!empty())
|
||||
{
|
||||
++m_query;
|
||||
|
||||
discreet_type mind = KeyHash::discreet(minc);
|
||||
discreet_type maxd = KeyHash::discreet(maxc);
|
||||
discreet_type current = mind;
|
||||
|
||||
for (; current[0] <= maxd[0]; ++current[0])
|
||||
{
|
||||
for (; current[1] <= maxd[1]; ++current[1])
|
||||
{
|
||||
for (; current[2] <= maxd[2]; ++current[2])
|
||||
{
|
||||
size_t hash_value = KeyHash::hash(current);
|
||||
size_t index = hash_value % CellCount;
|
||||
|
||||
const cell_type& cell = m_cells[index];
|
||||
|
||||
if (cell.query != m_query)
|
||||
{
|
||||
cell.query = m_query;
|
||||
const items_type& items = cell.items;
|
||||
|
||||
typename items_type::const_iterator it = items.begin();
|
||||
typename items_type::const_iterator end = items.end();
|
||||
|
||||
for (; it != end; ++it)
|
||||
{
|
||||
key_type pos = position(*it);
|
||||
|
||||
if (pos[0] >= minc[0] &&
|
||||
pos[1] >= minc[1] &&
|
||||
pos[2] >= minc[2] &&
|
||||
pos[0] <= maxc[0] &&
|
||||
pos[1] <= maxc[1] &&
|
||||
pos[2] <= maxc[2])
|
||||
{
|
||||
container.push_back(*it);
|
||||
++count;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
current[2] = mind[2];
|
||||
}
|
||||
current[1] = mind[1];
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
protected:
|
||||
position_retriever_type position;
|
||||
cells_type m_cells;
|
||||
uint32 m_count;
|
||||
mutable uint32 m_query;
|
||||
};
|
||||
|
||||
#endif // CRYINCLUDE_CRYCOMMON_HASHGRID_H
|
||||
@@ -420,7 +420,6 @@ namespace stl
|
||||
{
|
||||
nInterval++;
|
||||
nCount = 0;
|
||||
assert(CryMemory::IsHeapValid());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1,250 +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.
|
||||
|
||||
// Containers that use their own heap for allocation.
|
||||
|
||||
|
||||
#ifndef CRYINCLUDE_CRYCOMMON_HEAPCONTAINER_H
|
||||
#define CRYINCLUDE_CRYCOMMON_HEAPCONTAINER_H
|
||||
#pragma once
|
||||
|
||||
#include "PoolAllocator.h"
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
template<class T, typename L = stl::PSyncMultiThread>
|
||||
struct HeapQueue
|
||||
: public L
|
||||
{
|
||||
typedef typename L::Lock Lock;
|
||||
|
||||
HeapQueue()
|
||||
{
|
||||
reset();
|
||||
}
|
||||
|
||||
T* push_back()
|
||||
{
|
||||
Lock lock(*this);
|
||||
return push_back(m_Allocator.New());
|
||||
}
|
||||
|
||||
template<class I>
|
||||
T* push_back(I const& init)
|
||||
{
|
||||
Lock lock(*this);
|
||||
Node* pNode = (Node*)m_Allocator.Allocate();
|
||||
new(static_cast<T*>(pNode))T(init);
|
||||
return push_back(pNode);
|
||||
}
|
||||
|
||||
template<class I, class J>
|
||||
T* push_back(I const& i, J const& j)
|
||||
{
|
||||
Lock lock(*this);
|
||||
Node* pNode = (Node*)m_Allocator.Allocate();
|
||||
new(static_cast<T*>(pNode))T(i, j);
|
||||
return push_back(pNode);
|
||||
}
|
||||
|
||||
T* pop_front()
|
||||
{
|
||||
Lock lock(*this);
|
||||
|
||||
// Quick check, before locking.
|
||||
if (empty())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
Node* pNode = *m_ppHead;
|
||||
if (pNode)
|
||||
{
|
||||
m_ppHead = &(*m_ppHead)->pNext;
|
||||
m_nQueued--;
|
||||
validate();
|
||||
}
|
||||
return pNode;
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
Lock lock(*this);
|
||||
|
||||
validate();
|
||||
|
||||
// Destruct all elements.
|
||||
size_t nCheckAlloc = 0;
|
||||
while (m_pList)
|
||||
{
|
||||
nCheckAlloc++;
|
||||
Node* pNext = m_pList->pNext;
|
||||
m_pList->~Node();
|
||||
m_pList = pNext;
|
||||
}
|
||||
assert(nCheckAlloc == m_nAlloc);
|
||||
|
||||
// Empty queue structure.
|
||||
reset();
|
||||
|
||||
// Free pool memory all at once.
|
||||
m_Allocator.FreeMemory(false);
|
||||
}
|
||||
|
||||
size_t size() const
|
||||
{
|
||||
return m_nQueued;
|
||||
}
|
||||
|
||||
bool empty() const
|
||||
{
|
||||
return m_nQueued == 0;
|
||||
}
|
||||
|
||||
size_t allocated_memory() const
|
||||
{
|
||||
// Amortise allocated mem over all list instances.
|
||||
Lock lock(*this);
|
||||
return m_Allocator.GetTotalMemory().nAlloc;
|
||||
}
|
||||
|
||||
// Additional lock against storage deletion.
|
||||
L ClearLock;
|
||||
|
||||
void GetMemoryUsage(ICrySizer* pSizer) const
|
||||
{
|
||||
pSizer->AddObject(m_Allocator);
|
||||
}
|
||||
protected:
|
||||
|
||||
struct Node
|
||||
: T
|
||||
{
|
||||
Node* pNext;
|
||||
};
|
||||
|
||||
Node* m_pList; // First (allocated) node in list.
|
||||
Node** m_ppHead; // Points to pointer to front of queue, for popping.
|
||||
Node** m_ppTail; // Points to pointer at end of list, and of queue, for pushing.
|
||||
size_t m_nAlloc, m_nQueued;
|
||||
|
||||
void validate()
|
||||
{
|
||||
assert(m_nQueued <= m_nAlloc);
|
||||
assert(m_ppHead);
|
||||
assert(m_ppTail);
|
||||
assert(!*m_ppTail);
|
||||
assert((m_nQueued == 0) == !*m_ppHead);
|
||||
assert((m_nQueued == 0) == (m_ppHead == m_ppTail));
|
||||
assert((m_nAlloc == 0) == (m_ppTail == &m_pList));
|
||||
assert((m_nAlloc == 0) == !m_pList);
|
||||
}
|
||||
|
||||
void reset()
|
||||
{
|
||||
m_pList = 0;
|
||||
m_ppHead = m_ppTail = &m_pList;
|
||||
m_nAlloc = m_nQueued = 0;
|
||||
validate();
|
||||
}
|
||||
|
||||
Node* push_back(Node* pNode)
|
||||
{
|
||||
pNode->pNext = 0;
|
||||
|
||||
*m_ppTail = pNode;
|
||||
m_ppTail = &pNode->pNext;
|
||||
m_nAlloc++;
|
||||
m_nQueued++;
|
||||
|
||||
validate();
|
||||
|
||||
return pNode;
|
||||
}
|
||||
|
||||
// Allocate all elements from an exclusive pool.
|
||||
// Any locking is performed by the queue, no further locking needed in allocator.
|
||||
stl::TPoolAllocator<Node, stl::PSyncNone> m_Allocator;
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
template<class T, class C = std::less<T>, typename L = stl::PSyncNone>
|
||||
struct HeapPriorityQueue
|
||||
: public HeapQueue<T, L>
|
||||
{
|
||||
// Hand-holding for brain-dead template compiler.
|
||||
typedef HeapQueue<T, L> super;
|
||||
typedef typename super::Node Node;
|
||||
using super::empty;
|
||||
using super::validate;
|
||||
using super::m_ppHead;
|
||||
using super::m_ppTail;
|
||||
using super::m_nQueued;
|
||||
|
||||
public:
|
||||
|
||||
typedef typename super::Lock Lock;
|
||||
|
||||
// Pop the "largest" element, using class C.
|
||||
T* pop_largest()
|
||||
{
|
||||
Lock lock(*this);
|
||||
|
||||
if (!empty())
|
||||
{
|
||||
C comp;
|
||||
|
||||
// Find highest-valued item.
|
||||
// To do: improve linear search! Use priority queue.
|
||||
Node** ppTop = m_ppHead;
|
||||
for (Node** ppNode = &(*m_ppHead)->pNext; *ppNode; ppNode = &(*ppNode)->pNext)
|
||||
{
|
||||
if (comp(**ppTop, **ppNode))
|
||||
{
|
||||
ppTop = ppNode;
|
||||
}
|
||||
}
|
||||
Node* pTop = *ppTop;
|
||||
|
||||
// Move link to head.
|
||||
if (ppTop != m_ppHead)
|
||||
{
|
||||
if (!pTop->pNext)
|
||||
{
|
||||
// End of list.
|
||||
m_ppTail = ppTop;
|
||||
}
|
||||
*ppTop = pTop->pNext;
|
||||
pTop->pNext = *m_ppHead;
|
||||
*m_ppHead = pTop;
|
||||
}
|
||||
|
||||
// Pop head.
|
||||
m_ppHead = &pTop->pNext;
|
||||
m_nQueued--;
|
||||
|
||||
validate();
|
||||
return pTop;
|
||||
}
|
||||
else
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void GetMemoryUsage(ICrySizer* pSizer) const
|
||||
{
|
||||
HeapQueue<T, L>::GetMemoryUsage(pSizer);
|
||||
}
|
||||
};
|
||||
|
||||
#endif // CRYINCLUDE_CRYCOMMON_HEAPCONTAINER_H
|
||||
@@ -1,103 +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_ICHUNKFILE_H
|
||||
#define CRYINCLUDE_CRYCOMMON_ICHUNKFILE_H
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "CryHeaders.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Description:
|
||||
// Chunked File (.cgf, .chr etc.) interface
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
struct IChunkFile
|
||||
: _reference_target_t
|
||||
{
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Chunk Description.
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
struct ChunkDesc
|
||||
{
|
||||
ChunkTypes chunkType;
|
||||
int chunkVersion;
|
||||
int chunkId;
|
||||
uint32 fileOffset;
|
||||
void* data;
|
||||
uint32 size;
|
||||
bool bSwapEndian;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
ChunkDesc()
|
||||
: chunkType(ChunkType_ANY)
|
||||
, chunkVersion(0)
|
||||
, chunkId(0)
|
||||
, fileOffset(0)
|
||||
, data(0)
|
||||
, size(0)
|
||||
, bSwapEndian(false)
|
||||
{
|
||||
}
|
||||
|
||||
void GetMemoryUsage([[maybe_unused]] ICrySizer* pSizer) const{ /*nothing*/}
|
||||
|
||||
static inline bool LessOffset(const ChunkDesc& d1, const ChunkDesc& d2) { return d1.fileOffset < d2.fileOffset; }
|
||||
static inline bool LessOffsetByPtr(const ChunkDesc* d1, const ChunkDesc* d2) { return d1->fileOffset < d2->fileOffset; }
|
||||
static inline bool LessId(const ChunkDesc& d1, const ChunkDesc& d2) { return d1.chunkId < d2.chunkId; }
|
||||
};
|
||||
|
||||
// <interfuscator:shuffle>
|
||||
|
||||
virtual void GetMemoryUsage(ICrySizer* pSizer) const = 0;
|
||||
|
||||
// Releases chunk file interface.
|
||||
virtual void Release() = 0;
|
||||
|
||||
virtual bool IsReadOnly() const = 0;
|
||||
virtual bool IsLoaded() const = 0;
|
||||
|
||||
virtual bool Read(const char* filename) = 0;
|
||||
virtual bool ReadFromMemory(const void* pData, int nDataSize) = 0;
|
||||
|
||||
// Writes chunks to file.
|
||||
virtual bool Write(const char* filename) = 0;
|
||||
// Writes chunks to a memory buffer (allocated inside) and returns
|
||||
// pointer to the allocated memory (pData) and its size (nSize).
|
||||
// The memory will be released on destruction of the ChunkFile object, or
|
||||
// on the next WriteToMemoryBuffer() call, or on ReleaseMemoryBuffer() call.
|
||||
virtual bool WriteToMemoryBuffer(void** pData, int* nSize) = 0;
|
||||
// Releases memory that was allocated in WriteToMemoryBuffer()
|
||||
virtual void ReleaseMemoryBuffer() = 0;
|
||||
|
||||
// Adds chunk to file, returns ChunkID of the added chunk.
|
||||
virtual int AddChunk(ChunkTypes chunkType, int chunkVersion, EEndianness eEndianness, const void* chunkData, int chunkSize) = 0;
|
||||
virtual void DeleteChunkById(int nChunkId) = 0;
|
||||
virtual void DeleteChunksByType(ChunkTypes nChunkType) = 0;
|
||||
|
||||
virtual ChunkDesc* FindChunkByType(ChunkTypes nChunkType) = 0;
|
||||
virtual ChunkDesc* FindChunkById(int nChunkId) = 0;
|
||||
|
||||
// Gets the number of chunks.
|
||||
virtual int NumChunks() const = 0;
|
||||
|
||||
// Gets chunk description at i-th index.
|
||||
virtual ChunkDesc* GetChunk(int nIndex) = 0;
|
||||
virtual const ChunkDesc* GetChunk(int nIndex) const = 0;
|
||||
|
||||
virtual const char* GetLastError() const = 0;
|
||||
|
||||
// </interfuscator:shuffle>
|
||||
};
|
||||
|
||||
#endif // CRYINCLUDE_CRYCOMMON_ICHUNKFILE_H
|
||||
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
#ifndef CRYINCLUDE_CRYCOMMON_ICOLORGRADINGCONTROLLER_H
|
||||
#define CRYINCLUDE_CRYCOMMON_ICOLORGRADINGCONTROLLER_H
|
||||
#pragma once
|
||||
|
||||
|
||||
|
||||
struct SColorChartLayer
|
||||
{
|
||||
int m_texID;
|
||||
float m_blendAmount;
|
||||
|
||||
SColorChartLayer()
|
||||
: m_texID(-1)
|
||||
, m_blendAmount(-1)
|
||||
{
|
||||
}
|
||||
|
||||
SColorChartLayer(int texID, float blendAmount)
|
||||
: m_texID(texID)
|
||||
, m_blendAmount(blendAmount)
|
||||
{
|
||||
}
|
||||
|
||||
SColorChartLayer(const SColorChartLayer& rhs)
|
||||
: m_texID(rhs.m_texID)
|
||||
, m_blendAmount(rhs.m_blendAmount)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct IColorGradingController
|
||||
{
|
||||
public:
|
||||
// <interfuscator:shuffle>
|
||||
virtual ~IColorGradingController(){}
|
||||
virtual int LoadColorChart(const char* pChartFilePath) const = 0;
|
||||
virtual int LoadDefaultColorChart() const = 0;
|
||||
virtual void UnloadColorChart(int texID) const = 0;
|
||||
|
||||
virtual void SetLayers(const SColorChartLayer* pLayers, uint32 numLayers) = 0;
|
||||
// </interfuscator:shuffle>
|
||||
};
|
||||
|
||||
|
||||
#endif // CRYINCLUDE_CRYCOMMON_ICOLORGRADINGCONTROLLER_H
|
||||
@@ -27,7 +27,6 @@ namespace AZ
|
||||
struct IMaterial;
|
||||
struct IVisArea;
|
||||
struct SRenderingPassInfo;
|
||||
struct IGeomCache;
|
||||
struct SRendItemSorter;
|
||||
struct SFrameLodInfo;
|
||||
struct pe_params_area;
|
||||
@@ -259,9 +258,6 @@ struct IRenderNode
|
||||
virtual struct IStatObj* GetEntityStatObj(unsigned int nPartId = 0, unsigned int nSubPartId = 0, Matrix34A* pMatrix = NULL, bool bReturnOnlyVisible = false);
|
||||
virtual _smart_ptr<IMaterial> GetEntitySlotMaterial([[maybe_unused]] unsigned int nPartId, [[maybe_unused]] bool bReturnOnlyVisible = false, [[maybe_unused]] bool* pbDrawNear = NULL) { return NULL; }
|
||||
virtual void SetEntityStatObj([[maybe_unused]] unsigned int nSlot, [[maybe_unused]] IStatObj* pStatObj, [[maybe_unused]] const Matrix34A* pMatrix = NULL) {};
|
||||
#if defined(USE_GEOM_CACHES)
|
||||
virtual struct IGeomCacheRenderNode* GetGeomCacheRenderNode([[maybe_unused]] unsigned int nSlot, [[maybe_unused]] Matrix34A* pMatrix = NULL, [[maybe_unused]] bool bReturnOnlyVisible = false) { return NULL; }
|
||||
#endif
|
||||
virtual int GetSlotCount() const { return 1; }
|
||||
|
||||
// Summary:
|
||||
@@ -572,7 +568,6 @@ struct IVoxelObject
|
||||
: public IRenderNode
|
||||
{
|
||||
// <interfuscator:shuffle>
|
||||
virtual struct IMemoryBlock* GetCompiledData(EEndian eEndian) = 0;
|
||||
virtual void SetCompiledData(void* pData, int nSize, uint8 ucChildId, EEndian eEndian) = 0;
|
||||
virtual void SetObjectName(const char* pName) = 0;
|
||||
virtual void SetMatrix(const Matrix34& mat) = 0;
|
||||
@@ -794,81 +789,4 @@ struct IPrismRenderNode
|
||||
};
|
||||
#endif // EXCLUDE_DOCUMENTATION_PURPOSE
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if defined(USE_GEOM_CACHES)
|
||||
struct IGeomCacheRenderNode
|
||||
: public IRenderNode
|
||||
{
|
||||
virtual bool LoadGeomCache(const char* sGeomCacheFileName) = 0;
|
||||
|
||||
virtual void SetGeomCache(_smart_ptr<IGeomCache> geomCache) = 0;
|
||||
|
||||
// Gets the geometry cache that is rendered
|
||||
virtual IGeomCache* GetGeomCache() const = 0;
|
||||
|
||||
// Sets the time in the animation for the current frame.
|
||||
// Note that you should start streaming before calling this.
|
||||
virtual void SetPlaybackTime(const float time) = 0;
|
||||
|
||||
// Get the current playback time
|
||||
virtual float GetPlaybackTime() const = 0;
|
||||
|
||||
// Check if cache is streaming.
|
||||
virtual bool IsStreaming() const = 0;
|
||||
|
||||
// Need to start streaming before playback, otherwise there will be stalls.
|
||||
virtual void StartStreaming(const float time = 0.0f) = 0;
|
||||
|
||||
// Stops streaming and trashes the buffers
|
||||
virtual void StopStreaming() = 0;
|
||||
|
||||
// Checks if looping is enabled
|
||||
virtual bool IsLooping() const = 0;
|
||||
|
||||
// Enable/disable looping playback
|
||||
virtual void SetLooping(const bool bEnable) = 0;
|
||||
|
||||
// Gets time delta from current playback position to last ready to play frame
|
||||
virtual float GetPrecachedTime() const = 0;
|
||||
|
||||
// Check if bounds changed since last call to this function
|
||||
virtual bool DidBoundsChange() = 0;
|
||||
|
||||
// Set stand in CGFs and distance
|
||||
virtual void SetStandIn(const char* pFilePath, const char* pMaterial) = 0;
|
||||
virtual IStatObj* GetStandIn() = 0;
|
||||
virtual void SetFirstFrameStandIn(const char* pFilePath, const char* pMaterial) = 0;
|
||||
virtual IStatObj* GetFirstFrameStandIn() = 0;
|
||||
virtual void SetLastFrameStandIn(const char* pFilePath, const char* pMaterial) = 0;
|
||||
virtual IStatObj* GetLastFrameStandIn() = 0;
|
||||
virtual void SetStandInDistance(const float distance) = 0;
|
||||
virtual float GetStandInDistance() = 0;
|
||||
|
||||
// Set distance at which cache will start streaming automatically (0 means no auto streaming)
|
||||
virtual void SetStreamInDistance(const float distance) = 0;
|
||||
virtual float GetStreamInDistance() = 0;
|
||||
|
||||
// Start/Stop drawing the cache
|
||||
virtual void SetDrawing(bool bDrawing) = 0;
|
||||
|
||||
// Debug draw geometry
|
||||
virtual void DebugDraw(const struct SGeometryDebugDrawInfo& info, float fExtrudeScale = 0.01f, uint nodeIndex = 0) const = 0;
|
||||
|
||||
// Ray intersection against cache
|
||||
virtual bool RayIntersection(struct SRayHitInfo& hitInfo, _smart_ptr<IMaterial> pCustomMtl = NULL, uint* pHitNodeIndex = NULL) const = 0;
|
||||
|
||||
// Set max view distance
|
||||
virtual void SetBaseMaxViewDistance(float maxViewDistance) = 0;
|
||||
|
||||
// Get node information
|
||||
virtual uint GetNodeCount() const = 0;
|
||||
virtual Matrix34 GetNodeTransform(const uint nodeIndex) const = 0;
|
||||
virtual const char* GetNodeName(const uint nodeIndex) const = 0; // Node name is only stored in editor
|
||||
virtual uint32 GetNodeNameHash(const uint nodeIndex) const = 0;
|
||||
virtual bool IsNodeDataValid(const uint nodeIndex) const = 0; // Returns false if cache isn't loaded yet or index is out of range
|
||||
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif // CRYINCLUDE_CRYCOMMON_IENTITYRENDERSTATE_H
|
||||
|
||||
@@ -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,268 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
#ifndef CRYINCLUDE_CRYCOMMON_IFUNCVARIABLE_H
|
||||
#define CRYINCLUDE_CRYCOMMON_IFUNCVARIABLE_H
|
||||
#pragma once
|
||||
|
||||
#include "Cry_Vector2.h"
|
||||
#include "Cry_Vector3.h"
|
||||
#include "Cry_Matrix33.h"
|
||||
#include "Cry_Color.h"
|
||||
#include "smartptr.h"
|
||||
#include "StringUtils.h"
|
||||
|
||||
class ITexture;
|
||||
|
||||
enum FuncParamType
|
||||
{
|
||||
e_FLOAT, e_INT, e_BOOL, e_VEC2, e_VEC3, e_VEC4, e_COLOR, e_MATRIX33,
|
||||
// Though all types of textures are using the same class, it's important for editor to differentiate between them:
|
||||
e_TEXTURE2D, e_TEXTURE3D, e_TEXTURE_CUBE
|
||||
};
|
||||
|
||||
class IFuncVariable
|
||||
: public _reference_target_t
|
||||
{
|
||||
public:
|
||||
// <interfuscator:shuffle>
|
||||
virtual ~IFuncVariable(){};
|
||||
|
||||
virtual float GetMin() const = 0;
|
||||
virtual float GetMax() const = 0;
|
||||
|
||||
virtual void InvokeSetter(void* param) = 0;
|
||||
|
||||
virtual int GetInt() const = 0;
|
||||
virtual float GetFloat() const = 0;
|
||||
virtual bool GetBool() const = 0;
|
||||
virtual Vec2 GetVec2() const = 0;
|
||||
virtual Vec3 GetVec3() const = 0;
|
||||
virtual Vec4 GetVec4() const = 0;
|
||||
virtual ColorF GetColorF() const = 0;
|
||||
virtual Matrix33 GetMatrix33() const = 0;
|
||||
virtual ITexture* GetTexture() const = 0;
|
||||
// </interfuscator:shuffle>
|
||||
|
||||
enum FuncParamType paramType; // float, string, int, vec3 etc
|
||||
string name;
|
||||
#if defined(FLARES_SUPPORT_EDITING)
|
||||
string humanName;
|
||||
string description;
|
||||
#endif
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class MFPVariable
|
||||
: public IFuncVariable
|
||||
{
|
||||
public:
|
||||
typedef void (T::* OpticsBase_MFPtr)();
|
||||
OpticsBase_MFPtr pSetter;
|
||||
OpticsBase_MFPtr pGetter;
|
||||
T* pObj;
|
||||
std::pair<float, float> range;
|
||||
|
||||
private:
|
||||
MFPVariable ()
|
||||
{
|
||||
Set(e_INT, "", "", NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
float GetMin() const override { return range.first; }
|
||||
float GetMax() const override { return range.second; }
|
||||
|
||||
MFPVariable(FuncParamType type, const char* _humanname, const char* _description, T* obj, OpticsBase_MFPtr setter, OpticsBase_MFPtr getter, float fMin = 0, float fMax = 1.0f)
|
||||
{
|
||||
Set(type, _humanname, _description, obj, setter, getter, fMin, fMax);
|
||||
}
|
||||
|
||||
void Set(FuncParamType type, const char* _humanname, const char* _description, T* obj, OpticsBase_MFPtr setter, OpticsBase_MFPtr getter, float fMin = 0, float fMax = 1.0f)
|
||||
{
|
||||
paramType = type;
|
||||
|
||||
char _nameNoSpace[50];
|
||||
cry_strcpy(_nameNoSpace, _humanname);
|
||||
char* p1 = _nameNoSpace;
|
||||
char* p2 = p1;
|
||||
while (*p1 != 0)
|
||||
{
|
||||
if ((*p1) == ' ')
|
||||
{
|
||||
++p1;
|
||||
}
|
||||
else
|
||||
{
|
||||
*p2++ = *p1++;
|
||||
}
|
||||
}
|
||||
|
||||
*p2 = 0;
|
||||
name = _nameNoSpace;
|
||||
|
||||
#if defined(FLARES_SUPPORT_EDITING)
|
||||
humanName = _humanname;
|
||||
description = _description;
|
||||
#endif
|
||||
|
||||
pObj = obj;
|
||||
pSetter = setter;
|
||||
pGetter = getter;
|
||||
range.first = fMin;
|
||||
range.second = fMax;
|
||||
}
|
||||
|
||||
#define INVOKE_SETTER(PARAM_TYPE, param) (pObj->*(reinterpret_cast<void (T::*)(PARAM_TYPE)>(pSetter)))(*(PARAM_TYPE*)param)
|
||||
#define INVOKE_SETTER_P(PARAM_TYPE, param) (pObj->*(reinterpret_cast<void (T::*)(PARAM_TYPE)>(pSetter)))((PARAM_TYPE)param)
|
||||
|
||||
void InvokeSetter(void* param) override
|
||||
{
|
||||
switch (paramType)
|
||||
{
|
||||
case e_FLOAT:
|
||||
INVOKE_SETTER(float, param);
|
||||
break;
|
||||
case e_INT:
|
||||
INVOKE_SETTER(int, param);
|
||||
break;
|
||||
case e_VEC2:
|
||||
INVOKE_SETTER(Vec2, param);
|
||||
break;
|
||||
case e_VEC3:
|
||||
INVOKE_SETTER(Vec3, param);
|
||||
break;
|
||||
case e_VEC4:
|
||||
INVOKE_SETTER(Vec4, param);
|
||||
break;
|
||||
case e_BOOL:
|
||||
INVOKE_SETTER(bool, param);
|
||||
break;
|
||||
case e_COLOR:
|
||||
INVOKE_SETTER(ColorF, param);
|
||||
break;
|
||||
case e_MATRIX33:
|
||||
INVOKE_SETTER(Matrix33, param);
|
||||
break;
|
||||
case e_TEXTURE2D:
|
||||
INVOKE_SETTER_P(ITexture*, param);
|
||||
break;
|
||||
case e_TEXTURE3D:
|
||||
INVOKE_SETTER_P(ITexture*, param);
|
||||
break;
|
||||
case e_TEXTURE_CUBE:
|
||||
INVOKE_SETTER_P(ITexture*, param);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#define INVOKE_GETTER(PARAM_TYPE) ((pObj->*reinterpret_cast<PARAM_TYPE (T::*)()>(pGetter))())
|
||||
|
||||
int GetInt() const override {return INVOKE_GETTER(int); }
|
||||
float GetFloat() const override {return INVOKE_GETTER(float); }
|
||||
bool GetBool() const override {return INVOKE_GETTER(bool); }
|
||||
Vec2 GetVec2() const override {return INVOKE_GETTER(Vec2); }
|
||||
Vec3 GetVec3() const override {return INVOKE_GETTER(Vec3); }
|
||||
Vec4 GetVec4() const override {return INVOKE_GETTER(Vec4); }
|
||||
ColorF GetColorF() const override {return INVOKE_GETTER(ColorF); }
|
||||
Matrix33 GetMatrix33() const override {return INVOKE_GETTER(Matrix33); }
|
||||
ITexture* GetTexture() const override {return INVOKE_GETTER(ITexture*); }
|
||||
};
|
||||
|
||||
class FuncVariableGroup
|
||||
{
|
||||
private:
|
||||
AZStd::vector<_smart_ptr<IFuncVariable> > variables;
|
||||
string m_name;
|
||||
#if defined(FLARES_SUPPORT_EDITING)
|
||||
string m_humanname;
|
||||
#endif
|
||||
bool bCollapse;
|
||||
|
||||
public:
|
||||
FuncVariableGroup()
|
||||
: bCollapse(false)
|
||||
{
|
||||
SetName("");
|
||||
}
|
||||
|
||||
~FuncVariableGroup()
|
||||
{
|
||||
}
|
||||
|
||||
void SetName(const char* name, [[maybe_unused]] const char* humanname = 0)
|
||||
{
|
||||
if (!name)
|
||||
{
|
||||
return;
|
||||
}
|
||||
m_name = name;
|
||||
#if defined(FLARES_SUPPORT_EDITING)
|
||||
m_humanname = humanname ? humanname : name;
|
||||
#endif
|
||||
}
|
||||
|
||||
const char* GetName()
|
||||
{
|
||||
return m_name.c_str();
|
||||
}
|
||||
|
||||
#if defined(FLARES_SUPPORT_EDITING)
|
||||
const char* GetHumanName()
|
||||
{
|
||||
return m_humanname.c_str();
|
||||
}
|
||||
#endif
|
||||
|
||||
void SetCollapse(bool _bCollapse)
|
||||
{
|
||||
bCollapse = _bCollapse;
|
||||
}
|
||||
|
||||
bool IsCollapse()
|
||||
{
|
||||
return bCollapse;
|
||||
}
|
||||
|
||||
IFuncVariable* FindVariable(const char* name)
|
||||
{
|
||||
for (int i = 0, iSize(variables.size()); i < iSize; ++i)
|
||||
{
|
||||
if (variables[i] == NULL)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (!strcmp(variables[i]->name.c_str(), name))
|
||||
{
|
||||
return variables[i];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void SetVariable(int nIndex, IFuncVariable* v){ variables[nIndex] = v; }
|
||||
|
||||
int GetVariableCount() { return variables.size(); }
|
||||
|
||||
IFuncVariable* GetVariable(int nIndex)
|
||||
{
|
||||
return variables[nIndex];
|
||||
}
|
||||
|
||||
void AddVariable(IFuncVariable* var)
|
||||
{
|
||||
variables.push_back(var);
|
||||
}
|
||||
};
|
||||
#endif // CRYINCLUDE_CRYCOMMON_IFUNCVARIABLE_H
|
||||
@@ -1,52 +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_IGENERALMEMORYHEAP_H
|
||||
#define CRYINCLUDE_CRYCOMMON_IGENERALMEMORYHEAP_H
|
||||
#pragma once
|
||||
|
||||
namespace AZ
|
||||
{
|
||||
class IAllocator;
|
||||
}
|
||||
|
||||
class IGeneralMemoryHeap
|
||||
{
|
||||
public:
|
||||
// <interfuscator:shuffle>
|
||||
virtual bool Cleanup() = 0;
|
||||
|
||||
virtual int AddRef() = 0;
|
||||
virtual int Release() = 0;
|
||||
|
||||
virtual bool IsInAddressRange(void* ptr) const = 0;
|
||||
|
||||
virtual void* Calloc(size_t nmemb, size_t size, const char* sUsage) = 0;
|
||||
virtual void* Malloc(size_t sz, const char* sUsage) = 0;
|
||||
|
||||
// Attempts to free the allocation. Returns the size of the allocation if successful, 0 if the heap doesn't own the address.
|
||||
virtual size_t Free(void* ptr) = 0;
|
||||
virtual void* Realloc(void* ptr, size_t sz, const char* sUsage) = 0;
|
||||
virtual void* ReallocAlign(void* ptr, size_t size, size_t alignment, const char* sUsage) = 0;
|
||||
virtual void* Memalign(size_t boundary, size_t size, const char* sUsage) = 0;
|
||||
|
||||
virtual AZ::IAllocator* GetAllocator() const = 0;
|
||||
|
||||
// Get the size of the allocation. Returns 0 if the ptr doesn't belong to the heap.
|
||||
virtual size_t UsableSize(void* ptr) const = 0;
|
||||
// </interfuscator:shuffle>
|
||||
protected:
|
||||
virtual ~IGeneralMemoryHeap() {}
|
||||
};
|
||||
|
||||
#endif // CRYINCLUDE_CRYCOMMON_IGENERALMEMORYHEAP_H
|
||||
@@ -1,140 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
// Description : Interface for CGeomCache class
|
||||
|
||||
|
||||
#ifndef CRYINCLUDE_CRYCOMMON_IGEOMCACHE_H
|
||||
#define CRYINCLUDE_CRYCOMMON_IGEOMCACHE_H
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "smartptr.h" // TYPEDEF_AUTOPTR
|
||||
|
||||
// Summary:
|
||||
// Interface to hold geom cache data
|
||||
struct IGeomCache
|
||||
: public IStreamable
|
||||
{
|
||||
// Description:
|
||||
// Increase the reference count of the object.
|
||||
// Summary:
|
||||
// Notifies that the object is being used
|
||||
virtual int AddRef() = 0;
|
||||
|
||||
// Description:
|
||||
// Decrease the reference count of the object. If the reference count
|
||||
// reaches zero, the object will be deleted from memory.
|
||||
// Summary:
|
||||
// Notifies that the object is no longer needed
|
||||
virtual int Release() = 0;
|
||||
|
||||
// Description:
|
||||
// Checks if the geometry cache was successfully loaded from disk
|
||||
// Return Value:
|
||||
// True if valid, otherwise false
|
||||
virtual bool IsValid() const = 0;
|
||||
|
||||
// Description:
|
||||
// Set default material for the geometry.
|
||||
// Arguments:
|
||||
// pMaterial - A valid pointer to the material.
|
||||
virtual void SetMaterial(_smart_ptr<IMaterial> pMaterial) = 0;
|
||||
|
||||
// Description:
|
||||
// Returns default material of the geometry.
|
||||
// Arguments:
|
||||
// nType - Pass 0 to get the physic geometry or pass 1 to get the obstruct geometry
|
||||
// Return Value:
|
||||
// A pointer to a phys_geometry class.
|
||||
virtual _smart_ptr<IMaterial> GetMaterial() = 0;
|
||||
virtual const _smart_ptr<IMaterial> GetMaterial() const = 0;
|
||||
|
||||
// Summary:
|
||||
// Returns the filename of the object
|
||||
// Return Value:
|
||||
// A null terminated string which contain the filename of the object.
|
||||
virtual const char* GetFilePath() const = 0;
|
||||
|
||||
// Summary:
|
||||
// Returns the duration of the geom cache animation
|
||||
// Return value:
|
||||
// float value in seconds
|
||||
virtual float GetDuration() const = 0;
|
||||
|
||||
// Summary:
|
||||
// Reloads the cache. Need to call this when cache file changed.
|
||||
virtual void Reload() = 0;
|
||||
|
||||
// Summary:
|
||||
// Returns the max AABB of the geom cache through the whole animation
|
||||
// Return value:
|
||||
// The geom cache's max axis aligned bounding box
|
||||
virtual const AABB& GetAABB() const = 0;
|
||||
|
||||
/**
|
||||
* Tells the GeomCache whether or not it can release its static mesh data
|
||||
*
|
||||
* For the new AZ Geom Cache asset we have to be able
|
||||
* to tell the Geom Cache not to release loaded data.
|
||||
* This only matters when Geom Caches are not streamed.
|
||||
*
|
||||
* The legacy system works like this (if e_streamCGF is 0):
|
||||
* Load a geom cache entity.
|
||||
* Entity creates a geom cache render node.
|
||||
* Node loads geom cache, cache is marked as loaded.
|
||||
* Render node immediately initializes with the Geom Cache data.
|
||||
* Because the Geom Cache is not streamed, it releases unneeded data next tick
|
||||
*
|
||||
* The AZ system works like this:
|
||||
* Geom Cache component is created
|
||||
* Asset is requested
|
||||
* Asset loads Geom Cache
|
||||
* Geom Cache loads data and is marked as loaded
|
||||
* Asset calls AllowReleaseLoadedData(false) and locks loaded state
|
||||
* Tick happens and data is not freed (this is good, we need that data)
|
||||
* OnAssetReady event fires and is picked up by Geom Cache Component
|
||||
* Data is fed from the asset to the Geom Cache Render Node
|
||||
* Component calls AllowReleaseLoadedData(true)
|
||||
* Next tick the Geom Cache cleans up unneeded data
|
||||
*/
|
||||
virtual void SetProcessedByRenderNode(bool) = 0;
|
||||
|
||||
// Summary:
|
||||
// Returns statistics
|
||||
// Return value:
|
||||
// SStatistics struct
|
||||
struct SStatistics
|
||||
{
|
||||
bool m_bPlaybackFromMemory;
|
||||
float m_averageAnimationDataRate;
|
||||
uint m_numStaticMeshes;
|
||||
uint m_numStaticVertices;
|
||||
uint m_numStaticTriangles;
|
||||
uint m_numAnimatedMeshes;
|
||||
uint m_numAnimatedVertices;
|
||||
uint m_numAnimatedTriangles;
|
||||
uint m_numMaterials;
|
||||
uint m_staticDataSize;
|
||||
uint m_diskAnimationDataSize;
|
||||
uint m_memoryAnimationDataSize;
|
||||
};
|
||||
|
||||
virtual SStatistics GetStatistics() const = 0;
|
||||
|
||||
protected:
|
||||
virtual ~IGeomCache() {}; // should be never called, use Release() instead
|
||||
};
|
||||
|
||||
|
||||
#endif // CRYINCLUDE_CRYCOMMON_IGEOMCACHE_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_CRYCOMMON_IIMAGE_H
|
||||
#define CRYINCLUDE_CRYCOMMON_IIMAGE_H
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* Possible errors for IImageFile::mfGet_error.
|
||||
*/
|
||||
enum EImFileError
|
||||
{
|
||||
eIFE_OK = 0, eIFE_IOerror, eIFE_OutOfMemory, eIFE_BadFormat, eIFE_ChunkNotFound
|
||||
};
|
||||
|
||||
// here are all of the flags that can be passed into the image load flags
|
||||
#define FIM_NORMALMAP 0x0001
|
||||
#define FIM_NOTSUPPORTS_MIPS 0x0004
|
||||
#define FIM_ALPHA 0x0008 // request attached alpha image
|
||||
#define FIM_DECAL 0x0010
|
||||
#define FIM_GREYSCALE 0x0020 // hint this texture is greyscale (could be DXT1 with colored artifacts)
|
||||
#define FIM_STREAM_PREPARE 0x0080
|
||||
#define FIM_UNUSED_BIT 0x0100 // Free to use
|
||||
#define FIM_BIG_ENDIANNESS 0x0400 // for textures converted to big endianness format
|
||||
#define FIM_SPLITTED 0x0800 // for dds textures stored in splitted files
|
||||
#define FIM_SRGB_READ 0x1000
|
||||
#define FIM_X360_NOT_PRETILED 0x2000 // for dds textures that cannot be pretiled
|
||||
#define FIM_UNUSED_BIT_1 0x4000 // Free to use
|
||||
#define FIM_RENORMALIZED_TEXTURE 0x8000 // for dds textures with EIF_RenormalizedTexture set in the dds header (not currently supported in the engine at runtime)
|
||||
#define FIM_HAS_ATTACHED_ALPHA 0x10000 // image has an attached alpha image
|
||||
#define FIM_SUPPRESS_DOWNSCALING 0x20000 // don't allow to drop mips when texture is non-streamable
|
||||
#define FIM_DX10IO 0x40000 // for dds textures with extended DX10+ header
|
||||
#define FIM_NOFALLBACKS 0x80000 // if the texture can't be loaded or is not found, do not replace it with a default 'not found' texture.
|
||||
|
||||
class IImageFile
|
||||
{
|
||||
public:
|
||||
virtual int AddRef() = 0;
|
||||
virtual int Release() = 0;
|
||||
|
||||
virtual const string& mfGet_filename () const = 0;
|
||||
|
||||
virtual int mfGet_width () const = 0;
|
||||
virtual int mfGet_height () const = 0;
|
||||
virtual int mfGet_depth () const = 0;
|
||||
virtual int mfGet_NumSides () const = 0;
|
||||
|
||||
virtual EImFileError mfGet_error () const = 0;
|
||||
|
||||
virtual byte* mfGet_image (const int nSide) = 0;
|
||||
virtual bool mfIs_image (const int nSide) const = 0;
|
||||
|
||||
virtual ETEX_Format mfGetFormat() const = 0;
|
||||
virtual ETEX_TileMode mfGetTileMode() const = 0;
|
||||
virtual int mfGet_numMips () const = 0;
|
||||
virtual int mfGet_numPersistentMips () const = 0;
|
||||
virtual int mfGet_Flags () const = 0;
|
||||
virtual const ColorF& mfGet_minColor () const = 0;
|
||||
virtual const ColorF& mfGet_maxColor () const = 0;
|
||||
virtual int mfGet_ImageSize() const = 0;
|
||||
|
||||
protected:
|
||||
virtual ~IImageFile() {}
|
||||
};
|
||||
|
||||
#endif // CRYINCLUDE_CRYCOMMON_IIMAGE_H
|
||||
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
#ifndef CRYINCLUDE_CRYCOMMON_IIMAGEHANDLER_H
|
||||
#define CRYINCLUDE_CRYCOMMON_IIMAGEHANDLER_H
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
/**
|
||||
Utility for loading and saving images. only works with RGB data(no alpha), and lossless compressed tiff files for now.
|
||||
*/
|
||||
struct IImageHandler
|
||||
{
|
||||
struct IImage
|
||||
{
|
||||
virtual ~IImage() {}
|
||||
|
||||
virtual const std::vector<unsigned char>& GetData() const = 0;
|
||||
virtual int GetWidth() const = 0;
|
||||
virtual int GetHeight() const = 0;
|
||||
};
|
||||
|
||||
virtual ~IImageHandler() {}
|
||||
|
||||
///data must be RGB, 3 bytes per pixel.
|
||||
virtual std::unique_ptr<IImage> CreateImage(std::vector<unsigned char>&& data, int width, int height) const = 0;
|
||||
virtual std::unique_ptr<IImage> LoadImage(const char* filename) const = 0;
|
||||
virtual bool SaveImage(IImage* image, const char* filename) const = 0;
|
||||
virtual std::unique_ptr<IImage> CreateDiffImage(IImage* image1, IImage* image2) const = 0;
|
||||
virtual float CalculatePSNR(IImage* diffIimage) const = 0;
|
||||
};
|
||||
#endif // CRYINCLUDE_CRYCOMMON_IIMAGEHANDLER_H
|
||||
@@ -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
|
||||
@@ -1,86 +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_IMEMORY_H
|
||||
#define CRYINCLUDE_CRYCOMMON_IMEMORY_H
|
||||
#pragma once
|
||||
|
||||
#include <smartptr.h>
|
||||
#include <IGeneralMemoryHeap.h> // <> required for Interfuscator
|
||||
#include <smartptr.h>
|
||||
|
||||
struct IMemoryBlock
|
||||
: public CMultiThreadRefCount
|
||||
{
|
||||
// <interfuscator:shuffle>
|
||||
virtual void* GetData() = 0;
|
||||
virtual int GetSize() = 0;
|
||||
// </interfuscator:shuffle>
|
||||
};
|
||||
TYPEDEF_AUTOPTR(IMemoryBlock);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
struct ICustomMemoryBlock
|
||||
: public IMemoryBlock
|
||||
{
|
||||
// Copy region from from source memory to the specified output buffer
|
||||
virtual void CopyMemoryRegion(void* pOutputBuffer, size_t nOffset, size_t nSize) = 0;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
struct ICustomMemoryHeap
|
||||
: public CMultiThreadRefCount
|
||||
{
|
||||
// <interfuscator:shuffle>
|
||||
virtual ICustomMemoryBlock* AllocateBlock(size_t const nAllocateSize, char const* const sUsage, size_t const nAlignment = 16) = 0;
|
||||
virtual void GetMemoryUsage(ICrySizer* pSizer) = 0;
|
||||
virtual size_t GetAllocated() = 0;
|
||||
// </interfuscator:shuffle>
|
||||
};
|
||||
|
||||
class IMemoryAddressRange
|
||||
{
|
||||
public:
|
||||
// <interfuscator:shuffle>
|
||||
virtual void Release() = 0;
|
||||
|
||||
virtual char* GetBaseAddress() const = 0;
|
||||
virtual size_t GetPageCount() const = 0;
|
||||
virtual size_t GetPageSize() const = 0;
|
||||
|
||||
virtual void* MapPage(size_t pageIdx) = 0;
|
||||
virtual void UnmapPage(size_t pageIdx) = 0;
|
||||
// </interfuscator:shuffle>
|
||||
protected:
|
||||
virtual ~IMemoryAddressRange() {}
|
||||
};
|
||||
|
||||
class IPageMappingHeap
|
||||
{
|
||||
public:
|
||||
// <interfuscator:shuffle>
|
||||
virtual void Release() = 0;
|
||||
|
||||
virtual size_t GetGranularity() const = 0;
|
||||
virtual bool IsInAddressRange(void* ptr) const = 0;
|
||||
|
||||
virtual size_t FindLargestFreeBlockSize() const = 0;
|
||||
|
||||
virtual void* Map(size_t sz) = 0;
|
||||
virtual void Unmap(void* ptr, size_t sz) = 0;
|
||||
// </interfuscator:shuffle>
|
||||
protected:
|
||||
virtual ~IPageMappingHeap() {}
|
||||
};
|
||||
|
||||
#endif // CRYINCLUDE_CRYCOMMON_IMEMORY_H
|
||||
@@ -1,50 +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_IMESHBAKING_H
|
||||
#define CRYINCLUDE_CRYCOMMON_IMESHBAKING_H
|
||||
#pragma once
|
||||
|
||||
|
||||
struct SMeshBakingMaterialParams
|
||||
{
|
||||
float rayLength;
|
||||
float rayIndent;
|
||||
bool bAlphaCutout;
|
||||
bool bIgnore;
|
||||
};
|
||||
|
||||
struct SMeshBakingInputParams
|
||||
{
|
||||
IStatObj* pCageMesh;
|
||||
IStatObj* pInputMesh;
|
||||
const SMeshBakingMaterialParams* pMaterialParams;
|
||||
ColorF defaultBackgroundColour;
|
||||
ColorF dilateMagicColour;
|
||||
int outputTextureWidth;
|
||||
int outputTextureHeight;
|
||||
int numMaterialParams;
|
||||
int nLodId;
|
||||
bool bDoDilationPass;
|
||||
bool bSmoothNormals;
|
||||
bool bSaveSpecular;
|
||||
_smart_ptr<IMaterial> pMaterial;
|
||||
};
|
||||
|
||||
struct SMeshBakingOutput
|
||||
{
|
||||
ITexture* ppOuputTexture[3];
|
||||
ITexture* ppIntermediateTexture[3];
|
||||
};
|
||||
|
||||
#endif // CRYINCLUDE_CRYCOMMON_IMESHBAKING_H
|
||||
@@ -1,252 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
struct IStreamable;
|
||||
struct SCheckOcclusionJobData;
|
||||
struct SCheckOcclusionOutput;
|
||||
class COctreeNode;
|
||||
struct IStatInstGroup;
|
||||
|
||||
namespace NAsyncCull
|
||||
{
|
||||
class CCullThread;
|
||||
}
|
||||
|
||||
// Inplace object for IStreamable* to cache StreamableMemoryContentSize
|
||||
struct SStreamAbleObject
|
||||
{
|
||||
explicit SStreamAbleObject(IStreamable* pObj, bool bUpdateMemUsage = true)
|
||||
: m_pObj(pObj)
|
||||
, fCurImportance(-1000.f)
|
||||
{
|
||||
if (pObj && bUpdateMemUsage)
|
||||
{
|
||||
m_nStreamableContentMemoryUsage = pObj->GetStreamableContentMemoryUsage();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_nStreamableContentMemoryUsage = 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool operator==(const SStreamAbleObject& rOther) const
|
||||
{
|
||||
return m_pObj == rOther.m_pObj;
|
||||
}
|
||||
|
||||
int GetStreamableContentMemoryUsage() const { return m_nStreamableContentMemoryUsage; }
|
||||
IStreamable* GetStreamAbleObject() const { return m_pObj; }
|
||||
uint32 GetLastDrawMainFrameId() const
|
||||
{
|
||||
return m_pObj->GetLastDrawMainFrameId();
|
||||
}
|
||||
float fCurImportance;
|
||||
private:
|
||||
IStreamable* m_pObj;
|
||||
int m_nStreamableContentMemoryUsage;
|
||||
};
|
||||
|
||||
struct SObjManPrecacheCamera
|
||||
{
|
||||
SObjManPrecacheCamera()
|
||||
: vPosition(ZERO)
|
||||
, vDirection(ZERO)
|
||||
, bbox(AABB::RESET)
|
||||
, fImportanceFactor(1.0f)
|
||||
{
|
||||
}
|
||||
|
||||
Vec3 vPosition;
|
||||
Vec3 vDirection;
|
||||
AABB bbox;
|
||||
float fImportanceFactor;
|
||||
};
|
||||
|
||||
struct SObjManPrecachePoint
|
||||
{
|
||||
SObjManPrecachePoint()
|
||||
: nId(0)
|
||||
{
|
||||
}
|
||||
|
||||
int nId;
|
||||
CTimeValue expireTime;
|
||||
};
|
||||
|
||||
struct IObjManager
|
||||
{
|
||||
virtual ~IObjManager() {}
|
||||
|
||||
virtual void PreloadLevelObjects() = 0;
|
||||
virtual void UnloadObjects(bool bDeleteAll) = 0;
|
||||
virtual void CheckTextureReadyFlag() = 0;
|
||||
virtual void FreeStatObj(IStatObj* pObj) = 0;
|
||||
virtual _smart_ptr<IStatObj> GetDefaultCGF() = 0;
|
||||
|
||||
typedef std::vector< IDecalRenderNode* > DecalsToPrecreate;
|
||||
virtual DecalsToPrecreate& GetDecalsToPrecreate() = 0;
|
||||
virtual PodArray<SStreamAbleObject>& GetArrStreamableObjects() = 0;
|
||||
virtual PodArray<SObjManPrecacheCamera>& GetStreamPreCacheCameras() = 0;
|
||||
virtual PodArray<COctreeNode*>& GetArrStreamingNodeStack() = 0;
|
||||
virtual PodArray<SObjManPrecachePoint>& GetStreamPreCachePointDefs() = 0;
|
||||
|
||||
typedef std::map<string, IStatObj*, stl::less_stricmp<string> > ObjectsMap;
|
||||
virtual ObjectsMap& GetNameToObjectMap() = 0;
|
||||
|
||||
typedef std::set<IStatObj*> LoadedObjects;
|
||||
virtual LoadedObjects& GetLoadedObjects() = 0;
|
||||
|
||||
virtual Vec3 GetSunColor() = 0;
|
||||
virtual void SetSunColor(const Vec3& color) = 0;
|
||||
|
||||
virtual Vec3 GetSunAnimColor() = 0;
|
||||
virtual void SetSunAnimColor(const Vec3& color) = 0;
|
||||
|
||||
virtual float GetSunAnimSpeed() = 0;
|
||||
virtual void SetSunAnimSpeed(float sunAnimSpeed) = 0;
|
||||
|
||||
virtual AZ::u8 GetSunAnimPhase() = 0;
|
||||
virtual void SetSunAnimPhase(AZ::u8 sunAnimPhase) = 0;
|
||||
|
||||
virtual AZ::u8 GetSunAnimIndex() = 0;
|
||||
virtual void SetSunAnimIndex(AZ::u8 sunAnimIndex) = 0;
|
||||
|
||||
virtual float GetSSAOAmount() = 0;
|
||||
virtual void SetSSAOAmount(float amount) = 0;
|
||||
|
||||
virtual float GetSSAOContrast() = 0;
|
||||
virtual void SetSSAOContrast(float amount) = 0;
|
||||
|
||||
virtual SRainParams& GetRainParams() = 0;
|
||||
virtual SSnowParams& GetSnowParams() = 0;
|
||||
|
||||
virtual bool IsCameraPrecacheOverridden() = 0;
|
||||
virtual void SetCameraPrecacheOverridden(bool state) = 0;
|
||||
|
||||
virtual IStatObj* LoadNewCGF(IStatObj* pObject, int flagCloth, bool bUseStreaming, bool bForceBreakable, unsigned long nLoadingFlags, const char* normalizedFilename, const void* pData, int nDataSize, const char* originalFilename, const char* geomName, IStatObj::SSubObject** ppSubObject) = 0;
|
||||
virtual IStatObj* LoadFromCacheNoRef(IStatObj* pObject, bool bUseStreaming, unsigned long nLoadingFlags, const char* geomName, IStatObj::SSubObject** ppSubObject) = 0;
|
||||
|
||||
virtual IStatObj* AllocateStatObj() = 0;
|
||||
virtual IStatObj* LoadStatObjUnsafeManualRef(const char* szFileName, const char* szGeomName = NULL, IStatObj::SSubObject** ppSubObject = NULL, bool bUseStreaming = true, unsigned long nLoadingFlags = 0, const void* m_pData = 0, int m_nDataSize = 0, const char* szBlockName = NULL) = 0;
|
||||
virtual _smart_ptr<IStatObj> LoadStatObjAutoRef(const char* szFileName, const char* szGeomName = NULL, IStatObj::SSubObject** ppSubObject = NULL, bool bUseStreaming = true, unsigned long nLoadingFlags = 0, const void* m_pData = 0, int m_nDataSize = 0, const char* szBlockName = NULL) = 0;
|
||||
virtual void GetLoadedStatObjArray(IStatObj** pObjectsArray, int& nCount) = 0;
|
||||
virtual bool InternalDeleteObject(IStatObj* pObject) = 0;
|
||||
virtual void MakeShadowCastersList(CVisArea* pReceiverArea, const AABB& aabbReceiver, int dwAllowedTypes, int32 nRenderNodeFlags, Vec3 vLightPos, CDLight* pLight, ShadowMapFrustum* pFr, PodArray<struct SPlaneObject>* pShadowHull, const SRenderingPassInfo& passInfo) = 0;
|
||||
virtual int MakeStaticShadowCastersList(IRenderNode* pIgnoreNode, ShadowMapFrustum* pFrustum, int renderNodeExcludeFlags, int nMaxNodes, const SRenderingPassInfo& passInfo) = 0;
|
||||
virtual void MakeDepthCubemapRenderItemList(CVisArea* pReceiverArea, const AABB& cubemapAABB, int renderNodeFlags, PodArray<struct IShadowCaster*>* objectsList, const SRenderingPassInfo& passInfo) = 0;
|
||||
virtual void PrecacheStatObjMaterial(_smart_ptr<IMaterial> pMaterial, const float fEntDistance, IStatObj* pStatObj, bool bFullUpdate, bool bDrawNear) = 0;
|
||||
virtual void PrecacheStatObj(IStatObj* pStatObj, int nLod, const Matrix34A& statObjMatrix, _smart_ptr<IMaterial> pMaterial, float fImportance, float fEntDistance, bool bFullUpdate, bool bHighPriority) = 0;
|
||||
|
||||
virtual int GetLoadedObjectCount() = 0;
|
||||
|
||||
virtual uint16 CheckCachedNearestCubeProbe(IRenderNode* pEnt) = 0;
|
||||
virtual int16 GetNearestCubeProbe(IVisArea* pVisArea, const AABB& objBox, bool bSpecular = true) = 0;
|
||||
|
||||
virtual void RenderObject(IRenderNode* o, const AABB& objBox, float fEntDistance, EERType eERType, const SRenderingPassInfo& passInfo, const SRendItemSorter& rendItemSorter) = 0;
|
||||
virtual void RenderDecalAndRoad(IRenderNode* pEnt, const AABB& objBox, float fEntDistance, bool nCheckOcclusion, const SRenderingPassInfo& passInfo, const SRendItemSorter& rendItemSorter) = 0;
|
||||
virtual void RenderObjectDebugInfo(IRenderNode* pEnt, float fEntDistance, const SRenderingPassInfo& passInfo) = 0;
|
||||
virtual void RenderAllObjectDebugInfo() = 0;
|
||||
virtual void RenderObjectDebugInfo_Impl(IRenderNode* pEnt, float fEntDistance) = 0;
|
||||
virtual void RemoveFromRenderAllObjectDebugInfo(IRenderNode* pEnt) = 0;
|
||||
|
||||
virtual float GetXYRadius(int nType, int nSID = DEFAULT_SID) = 0;
|
||||
virtual bool GetStaticObjectBBox(int nType, Vec3& vBoxMin, Vec3& vBoxMax, int nSID = DEFAULT_SID) = 0;
|
||||
|
||||
virtual IStatObj* GetStaticObjectByTypeID(int nTypeID, int nSID = DEFAULT_SID) = 0;
|
||||
virtual IStatObj* FindStaticObjectByFilename(const char* filename) = 0;
|
||||
|
||||
//virtual float GetBendingRandomFactor() = 0;
|
||||
virtual float GetGSMMaxDistance() const = 0;
|
||||
virtual void SetGSMMaxDistance(float value) = 0;
|
||||
|
||||
virtual int GetUpdateStreamingPrioriryRoundIdFast() = 0;
|
||||
virtual int GetUpdateStreamingPrioriryRoundId() = 0;
|
||||
virtual void IncrementUpdateStreamingPrioriryRoundIdFast(int amount) = 0;
|
||||
virtual void IncrementUpdateStreamingPrioriryRoundId(int amount) = 0;
|
||||
|
||||
virtual NAsyncCull::CCullThread& GetCullThread() = 0;
|
||||
|
||||
virtual void SetLockCGFResources(bool state) = 0;
|
||||
virtual bool IsLockCGFResources() = 0;
|
||||
|
||||
virtual bool IsBoxOccluded(const AABB& objBox, float fDistance, OcclusionTestClient* const __restrict pOcclTestVars, bool bIndoorOccludersOnly, EOcclusionObjectType eOcclusionObjectType, const SRenderingPassInfo& passInfo) = 0;
|
||||
|
||||
virtual void AddDecalToRenderer(float fDistance, _smart_ptr<IMaterial> pMat, const uint8 sortPrio, Vec3 right, Vec3 up, const UCol& ucResCol, const uint8 uBlendType, const Vec3& vAmbientColor, Vec3 vPos, const int nAfterWater, const SRenderingPassInfo& passInfo, const SRendItemSorter& rendItemSorter) = 0;
|
||||
|
||||
virtual void RegisterForStreaming(IStreamable* pObj) = 0;
|
||||
virtual void UnregisterForStreaming(IStreamable* pObj) = 0;
|
||||
virtual void UpdateRenderNodeStreamingPriority(IRenderNode* pObj, float fEntDistance, float fImportanceFactor, bool bFullUpdate, const SRenderingPassInfo& passInfo, bool bHighPriority = false) = 0;
|
||||
|
||||
virtual void GetMemoryUsage(class ICrySizer* pSizer) const = 0;
|
||||
virtual void GetBandwidthStats(float* fBandwidthRequested) = 0;
|
||||
|
||||
virtual void ReregisterEntitiesInArea(Vec3 vBoxMin, Vec3 vBoxMax) = 0;
|
||||
virtual void UpdateObjectsStreamingPriority(bool bSyncLoad, const SRenderingPassInfo& passInfo) = 0;
|
||||
virtual void ProcessObjectsStreaming(const SRenderingPassInfo& passInfo) = 0;
|
||||
|
||||
virtual void ProcessObjectsStreaming_Impl(bool bSyncLoad, const SRenderingPassInfo& passInfo) = 0;
|
||||
virtual void ProcessObjectsStreaming_Sort(bool bSyncLoad, const SRenderingPassInfo& passInfo) = 0;
|
||||
virtual void ProcessObjectsStreaming_Release() = 0;
|
||||
virtual void ProcessObjectsStreaming_InitLoad(bool bSyncLoad) = 0;
|
||||
virtual void ProcessObjectsStreaming_Finish() = 0;
|
||||
|
||||
// time counters
|
||||
virtual bool IsAfterWater(const Vec3& vPos, const SRenderingPassInfo& passInfo) = 0;
|
||||
virtual void FreeNotUsedCGFs() = 0;
|
||||
virtual void MakeUnitCube() = 0;
|
||||
|
||||
virtual bool CheckOcclusion_TestAABB(const AABB& rAABB, float fEntDistance) = 0;
|
||||
virtual bool CheckOcclusion_TestQuad(const Vec3& vCenter, const Vec3& vAxisX, const Vec3& vAxisY) = 0;
|
||||
|
||||
virtual void PushIntoCullQueue(const SCheckOcclusionJobData& rCheckOcclusionData) = 0;
|
||||
virtual void PopFromCullQueue(SCheckOcclusionJobData* pCheckOcclusionData) = 0;
|
||||
|
||||
virtual void PushIntoCullOutputQueue(const SCheckOcclusionOutput& rCheckOcclusionOutput) = 0;
|
||||
virtual bool PopFromCullOutputQueue(SCheckOcclusionOutput* pCheckOcclusionOutput) = 0;
|
||||
|
||||
virtual void BeginCulling() = 0;
|
||||
virtual void RemoveCullJobProducer() = 0;
|
||||
virtual void AddCullJobProducer() = 0;
|
||||
|
||||
#ifndef _RELEASE
|
||||
virtual void CoverageBufferDebugDraw() = 0;
|
||||
#endif
|
||||
|
||||
virtual bool LoadOcclusionMesh(const char* pFileName) = 0;
|
||||
|
||||
virtual void ClearStatObjGarbage() = 0;
|
||||
virtual void CheckForGarbage(IStatObj* pObject) = 0;
|
||||
virtual void UnregisterForGarbage(IStatObj* pObject) = 0;
|
||||
|
||||
virtual int GetObjectLOD(const IRenderNode* pObj, float fDistance) = 0;
|
||||
virtual bool RayStatObjIntersection(IStatObj* pStatObj, const Matrix34& objMat, _smart_ptr<IMaterial> pMat, Vec3 vStart, Vec3 vEnd, Vec3& vClosestHitPoint, float& fClosestHitDistance, bool bFastTest) = 0;
|
||||
virtual bool RayRenderMeshIntersection(IRenderMesh* pRenderMesh, const Vec3& vInPos, const Vec3& vInDir, Vec3& vOutPos, Vec3& vOutNormal, bool bFastTest, _smart_ptr<IMaterial> pMat) = 0;
|
||||
virtual bool SphereRenderMeshIntersection(IRenderMesh* pRenderMesh, const Vec3& vInPos, const float fRadius, _smart_ptr<IMaterial> pMat) = 0;
|
||||
|
||||
virtual uint8 GetDissolveRef(float fDist, float fMaxViewDist) = 0;
|
||||
virtual float GetLodDistDissolveRef(SLodDistDissolveTransitionState* pState, float curDist, int nNewLod, const SRenderingPassInfo& passInfo) = 0;
|
||||
|
||||
virtual void CleanStreamingData() = 0;
|
||||
virtual IRenderMesh* GetRenderMeshBox() = 0;
|
||||
|
||||
virtual void PrepareCullbufferAsync(const CCamera& rCamera) = 0;
|
||||
virtual void BeginOcclusionCulling(const SRenderingPassInfo& passInfo) = 0;
|
||||
virtual void EndOcclusionCulling(bool waitForOcclusionJobCompletion = false) = 0;
|
||||
virtual void RenderBufferedRenderMeshes(const SRenderingPassInfo& passInfo) = 0;
|
||||
|
||||
virtual int GetListStaticTypesCount() = 0;
|
||||
virtual int GetListStaticTypesGroupCount(int typeId) = 0;
|
||||
virtual IStatInstGroup* GetIStatInstGroup(int typeId, int groupId) = 0;
|
||||
|
||||
virtual int IncrementNextPrecachePointId() = 0;
|
||||
};
|
||||
@@ -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_CRYCOMMON_IPHYSICSDEBUGRENDERER_H
|
||||
#define CRYINCLUDE_CRYCOMMON_IPHYSICSDEBUGRENDERER_H
|
||||
#pragma once
|
||||
|
||||
|
||||
#endif // CRYINCLUDE_CRYCOMMON_IPHYSICSDEBUGRENDERER_H
|
||||
@@ -1,133 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef CRYINCLUDE_CRYCOMMON_IPROXIMITYTRIGGERSYSTEM_H
|
||||
#define CRYINCLUDE_CRYCOMMON_IPROXIMITYTRIGGERSYSTEM_H
|
||||
#pragma once
|
||||
|
||||
#include <AzCore/base.h>
|
||||
#include <AzCore/EBus/EBus.h>
|
||||
#include <AzCore/Component/EntityId.h>
|
||||
#include <AzCore/std/function/function_fwd.h>
|
||||
#include <Cry_Geo.h> // AABB
|
||||
|
||||
|
||||
/**
|
||||
* Represents a registered proximity trigger.
|
||||
*
|
||||
* Contains the id of the trigger, its bounds, and whether or not it's active.
|
||||
*/
|
||||
struct SProximityElement
|
||||
{
|
||||
AZ::EntityId id;
|
||||
AABB aabb;
|
||||
uint32 bActivated : 1;
|
||||
std::vector<SProximityElement*> inside;
|
||||
|
||||
using NarrowPassCheckFunction = AZStd::function<bool(const AZ::Vector3&)>;
|
||||
|
||||
// Can be used to do an optional narrow pass check on this proximity element
|
||||
NarrowPassCheckFunction m_narrowPassChecker;
|
||||
|
||||
SProximityElement()
|
||||
{
|
||||
id = AZ::EntityId(0);
|
||||
bActivated = 0;
|
||||
}
|
||||
~SProximityElement()
|
||||
{
|
||||
}
|
||||
bool AddInside(SProximityElement* elem)
|
||||
{
|
||||
// Sorted add.
|
||||
return stl::binary_insert_unique(inside, elem);
|
||||
}
|
||||
bool RemoveInside(SProximityElement* elem)
|
||||
{
|
||||
// sorted remove.
|
||||
return stl::binary_erase(inside, elem);
|
||||
}
|
||||
bool IsInside(SProximityElement* elem)
|
||||
{
|
||||
return std::binary_search(inside.begin(), inside.end(), elem);
|
||||
}
|
||||
|
||||
void GetMemoryUsage([[maybe_unused]] ICrySizer* pSizer) const{}
|
||||
};
|
||||
|
||||
/**
|
||||
* Bus for events dispatched by the proximity trigger system as triggered are
|
||||
* entered and exited by entities in the world.
|
||||
*/
|
||||
class ProximityTriggerEvents
|
||||
: public AZ::EBusTraits
|
||||
{
|
||||
public:
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Ebus Traits
|
||||
// ID'd on trigger entity Id
|
||||
static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::ById;
|
||||
using BusIdType = AZ::EntityId;
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
virtual ~ProximityTriggerEvents() {}
|
||||
|
||||
/// Dispatched when an entity enters a trigger. The bus message is ID'd on the triggers entity Id.
|
||||
virtual void OnTriggerEnter(AZ::EntityId /*entityEntering*/) {};
|
||||
|
||||
/// Dispatched when an entity exits a trigger. The bus message is ID'd on the triggers entity Id.
|
||||
virtual void OnTriggerExit(AZ::EntityId /*entityExiting*/) {};
|
||||
};
|
||||
|
||||
using ProximityTriggerEventBus = AZ::EBus<ProximityTriggerEvents>;
|
||||
|
||||
/**
|
||||
* Bus for requests sent by components or game code to the proximity trigger system.
|
||||
*/
|
||||
class ProximityTriggerSystemRequests
|
||||
: public AZ::EBusTraits
|
||||
{
|
||||
public:
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// EBusTraits overrides - proximity trigger system is a singleton
|
||||
static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single;
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
virtual ~ProximityTriggerSystemRequests() {}
|
||||
|
||||
/// Creates a new trigger instance.
|
||||
virtual SProximityElement* CreateTrigger(SProximityElement::NarrowPassCheckFunction narrowPassChecker = nullptr) = 0;
|
||||
|
||||
/// Removes a trigger and queues it for deletion.
|
||||
virtual void RemoveTrigger(SProximityElement* pTrigger) = 0;
|
||||
|
||||
/// Moves a trigger in the world or redefines its dimensions.
|
||||
virtual void MoveTrigger(SProximityElement* pTrigger, const AABB& aabb, bool invalidateCachedAABB = false) = 0;
|
||||
|
||||
/// Creates a proxy in the world associated with an entity (Component or Legacy) for interacting with proximity trigger instances.
|
||||
virtual SProximityElement* CreateEntity(AZ::EntityId id) = 0;
|
||||
|
||||
/**
|
||||
* Set the entity's AABB to a unit AABB at the entity's world position if \aabb is empty, otherwise set the entity's AABB to \aabb
|
||||
* @param pEntity The pointer to a SProximityElment whose AABB needs to be updated
|
||||
* @param pos World position of the entity
|
||||
* @param aabb The new AABB in world space to set
|
||||
*/
|
||||
virtual void MoveEntity(SProximityElement* pEntity, const Vec3& pos, const AABB& aabb) = 0;
|
||||
|
||||
/// Removes an entity's proximity trigger proxy.
|
||||
virtual void RemoveEntity(SProximityElement* pEntity, bool instantEvent = false) = 0;
|
||||
};
|
||||
|
||||
using ProximityTriggerSystemRequestBus = AZ::EBus<ProximityTriggerSystemRequests>;
|
||||
|
||||
#endif // CRYINCLUDE_CRYCOMMON_IPROXIMITYTRIGGERSYSTEM_H
|
||||
@@ -16,7 +16,12 @@
|
||||
#include "Cry_Geo.h"
|
||||
#include "Cry_Camera.h"
|
||||
#include "ITexture.h"
|
||||
#include <IFuncVariable.h> // <> required for Interfuscator
|
||||
#include "Cry_Vector2.h"
|
||||
#include "Cry_Vector3.h"
|
||||
#include "Cry_Matrix33.h"
|
||||
#include "Cry_Color.h"
|
||||
#include "smartptr.h"
|
||||
#include "StringUtils.h"
|
||||
#include <IXml.h> // <> required for Interfuscator
|
||||
#include "smartptr.h"
|
||||
#include <AzCore/Casting/numeric_cast.h>
|
||||
@@ -99,7 +104,6 @@ struct ShadowFrustumMGPUCache;
|
||||
struct IAsyncTextureCompileListener;
|
||||
struct IClipVolume;
|
||||
struct SClipVolumeBlendInfo;
|
||||
class IImageFile;
|
||||
class CRenderView;
|
||||
struct SDynTexture2;
|
||||
class CTexture;
|
||||
@@ -693,7 +697,6 @@ public:
|
||||
#include <IShader.h> // <> required for Interfuscator
|
||||
//DOC-IGNORE-END
|
||||
#include <IRenderMesh.h>
|
||||
#include "IMeshBaking.h"
|
||||
|
||||
// Flags passed in function FreeResources.
|
||||
#define FRR_SHADERS 1
|
||||
@@ -1051,11 +1054,6 @@ namespace AZ {
|
||||
namespace Vertex {
|
||||
class Format;
|
||||
}
|
||||
namespace VideoRenderer
|
||||
{
|
||||
struct IVideoRenderer;
|
||||
struct DrawArguments;
|
||||
}
|
||||
}
|
||||
enum eRenderPrimitiveType : int8;
|
||||
enum RenderIndexType : int;
|
||||
@@ -1464,7 +1462,6 @@ struct IRenderer
|
||||
// Is threadsafe
|
||||
virtual bool EF_ReloadFile_Request (const char* szFileName) = 0;
|
||||
|
||||
virtual _smart_ptr<IImageFile> EF_LoadImage(const char* szFileName, uint32 nFlags) = 0;
|
||||
// Summary:
|
||||
// Remaps shader gen mask to common global mask.
|
||||
virtual uint64 EF_GetRemapedShaderMaskGen(const char* name, uint64 nMaskGen = 0, bool bFixup = 0) = 0;
|
||||
@@ -1510,7 +1507,6 @@ struct IRenderer
|
||||
// Summary:
|
||||
// Loads lightmap for name.
|
||||
virtual int EF_LoadLightmap (const char* name) = 0;
|
||||
virtual bool EF_RenderEnvironmentCubeHDR (int size, Vec3& Pos, TArray<unsigned short>& vecData) = 0;
|
||||
|
||||
// Summary:
|
||||
// Starts using of the shaders (return first index for allow recursions).
|
||||
@@ -1547,7 +1543,6 @@ struct IRenderer
|
||||
virtual int EF_AddDeferredLight(const CDLight& pLight, float fMult, const SRenderingPassInfo& passInfo, const SRendItemSorter& rendItemSorter) = 0;
|
||||
virtual uint32 EF_GetDeferredLightsNum(eDeferredLightType eLightType = eDLT_DeferredLight) = 0;
|
||||
virtual void EF_ClearDeferredLightsList() = 0;
|
||||
virtual TArray<SRenderLight>* EF_GetDeferredLights(const SRenderingPassInfo& passInfo, eDeferredLightType eLightType = eDLT_DeferredLight) = 0;
|
||||
|
||||
virtual uint8 EF_AddDeferredClipVolume(const IClipVolume* pClipVolume) = 0;
|
||||
virtual bool EF_SetDeferredClipVolumeBlendData(const IClipVolume* pClipVolume, const SClipVolumeBlendInfo& blendInfo) = 0;
|
||||
@@ -1741,8 +1736,6 @@ struct IRenderer
|
||||
virtual void RemoveTexture(unsigned int TextureId) = 0;
|
||||
virtual void DeleteFont(IFFont* font) = 0;
|
||||
|
||||
virtual bool BakeMesh(const SMeshBakingInputParams* pInputParams, SMeshBakingOutput* pReturnValues) = 0;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// This routines uses 2 destination surfaces. It triggers a backbuffer copy to one of its surfaces,
|
||||
// and then copies the other surface to system memory. This hopefully will remove any
|
||||
@@ -2348,11 +2341,6 @@ struct IRenderer
|
||||
virtual void EndProfilerSection(const char* name) = 0;
|
||||
virtual void AddProfilerLabel(const char* name) = 0;
|
||||
|
||||
// Video Renderer interface
|
||||
virtual void InitializeVideoRenderer(AZ::VideoRenderer::IVideoRenderer* pVideoRenderer) = 0;
|
||||
virtual void CleanupVideoRenderer(AZ::VideoRenderer::IVideoRenderer* pVideoRenderer) = 0;
|
||||
virtual void DrawVideoRenderer(AZ::VideoRenderer::IVideoRenderer* pVideoRenderer, const AZ::VideoRenderer::DrawArguments& drawArguments) = 0;
|
||||
|
||||
private:
|
||||
// use private for EF_Query to prevent client code to submit arbitrary combinations of output data/size
|
||||
virtual void EF_QueryImpl(ERenderQueryTypes eQuery, void* pInOut0, uint32 nInOutSize0, void* pInOut1, uint32 nInOutSize1) = 0;
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
#ifndef CRYINCLUDE_CRYCOMMON_IRESOURCECOLLECTOR_H
|
||||
#define CRYINCLUDE_CRYCOMMON_IRESOURCECOLLECTOR_H
|
||||
#pragma once
|
||||
|
||||
|
||||
// used to collect the assets needed for streaming and to gather statistics
|
||||
struct IResourceCollector
|
||||
{
|
||||
// <interfuscator:shuffle>
|
||||
// Arguments:
|
||||
// dwMemSize 0xffffffff if size is unknown
|
||||
// Returns:
|
||||
// true=new resource was added, false=resource was already registered
|
||||
virtual bool AddResource(const char* szFileName, const uint32 dwMemSize) = 0;
|
||||
|
||||
// Arguments:
|
||||
// szFileName - needs to be registered before with AddResource()
|
||||
// pInstance - must not be 0
|
||||
virtual void AddInstance(const char* szFileName, void* pInstance) = 0;
|
||||
//
|
||||
// Arguments:
|
||||
// szFileName - needs to be registered before with AddResource()
|
||||
virtual void OpenDependencies(const char* szFileName) = 0;
|
||||
//
|
||||
virtual void CloseDependencies() = 0;
|
||||
|
||||
// Resets the internal data structure for the resource collector.
|
||||
virtual void Reset() = 0;
|
||||
// </interfuscator:shuffle>
|
||||
protected:
|
||||
virtual ~IResourceCollector() {}
|
||||
};
|
||||
|
||||
|
||||
class NullResCollector
|
||||
: public IResourceCollector
|
||||
{
|
||||
public:
|
||||
virtual bool AddResource([[maybe_unused]] const char* szFileName, [[maybe_unused]] const uint32 dwMemSize) { return true; }
|
||||
virtual void AddInstance([[maybe_unused]] const char* szFileName, [[maybe_unused]] void* pInstance) {}
|
||||
virtual void OpenDependencies([[maybe_unused]] const char* szFileName) {}
|
||||
virtual void CloseDependencies() {}
|
||||
virtual void Reset() {}
|
||||
|
||||
virtual ~NullResCollector() {}
|
||||
};
|
||||
|
||||
|
||||
#endif // CRYINCLUDE_CRYCOMMON_IRESOURCECOLLECTOR_H
|
||||
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
// Description : Interface to the Resource Manager
|
||||
|
||||
|
||||
#ifndef CRYINCLUDE_CRYCOMMON_IRESOURCEMANAGER_H
|
||||
#define CRYINCLUDE_CRYCOMMON_IRESOURCEMANAGER_H
|
||||
#pragma once
|
||||
|
||||
namespace AZ::IO
|
||||
{
|
||||
struct IResourceList;
|
||||
}
|
||||
|
||||
struct SLayerPakStats
|
||||
{
|
||||
struct SEntry
|
||||
{
|
||||
string name;
|
||||
size_t nSize;
|
||||
string status;
|
||||
bool bStreaming;
|
||||
};
|
||||
typedef std::vector<SEntry> TEntries;
|
||||
TEntries m_entries;
|
||||
|
||||
size_t m_MaxSize;
|
||||
size_t m_UsedSize;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// IResource manager interface
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
struct IResourceManager
|
||||
{
|
||||
// <interfuscator:shuffle>
|
||||
virtual ~IResourceManager(){}
|
||||
// Called by level system to set the level folder
|
||||
virtual void PrepareLevel(const char* sLevelFolder, const char* sLevelName) = 0;
|
||||
// Called by level system after the level has been unloaded.
|
||||
virtual void UnloadLevel() = 0;
|
||||
// Call to get current level resource list.
|
||||
virtual AZ::IO::IResourceList* GetLevelResourceList() = 0;
|
||||
// Load pak file from level cache to memory.
|
||||
// sBindRoot is a path in virtual file system, where new pak will be mapper to (ex. LevelCache/mtl)
|
||||
virtual bool LoadLevelCachePak(const char* sPakName, const char* sBindRoot, bool bOnlyDuringLevelLoading = true) = 0;
|
||||
// Unloads level cache pak file from memory.
|
||||
virtual void UnloadLevelCachePak(const char* sPakName) = 0;
|
||||
|
||||
//Loads the pak file for mode switching into memory e.g. Single player mode to Multiplayer mode
|
||||
virtual bool LoadModeSwitchPak(const char* sPakName, const bool multiplayer) = 0;
|
||||
//Unloads the mode switching pak file
|
||||
virtual void UnloadModeSwitchPak(const char* sPakName, const char* sResourceListName, const bool multiplayer) = 0;
|
||||
|
||||
// Load general pak file to memory.
|
||||
virtual bool LoadPakToMemAsync(const char* pPath, bool bLevelLoadOnly) = 0;
|
||||
// Unload all aync paks
|
||||
virtual void UnloadAllAsyncPaks() = 0;
|
||||
// Load pak file from active layer to memory.
|
||||
virtual bool LoadLayerPak(const char* sLayerName) = 0;
|
||||
// Unloads layer pak file from memory if no more references.
|
||||
virtual void UnloadLayerPak(const char* sLayerName) = 0;
|
||||
// Retrieve stats on the layer pak
|
||||
virtual void GetLayerPakStats(SLayerPakStats& stats, bool bCollectAllStats) const = 0;
|
||||
|
||||
// Return time it took to load and precache the level.
|
||||
virtual CTimeValue GetLastLevelLoadTime() const = 0;
|
||||
|
||||
virtual void GetMemoryStatistics(ICrySizer* pSizer) = 0;
|
||||
// </interfuscator:shuffle>
|
||||
};
|
||||
|
||||
#endif // CRYINCLUDE_CRYCOMMON_IRESOURCEMANAGER_H
|
||||
@@ -20,7 +20,6 @@
|
||||
|
||||
#include <Cry_Math.h>
|
||||
#include <IXml.h>
|
||||
#include "CountedValue.h"
|
||||
#include "MiniQueue.h"
|
||||
#include <VectorSet.h>
|
||||
#include <VectorMap.h>
|
||||
@@ -471,58 +470,6 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void Value(const char* name, CountedValue<T>& countedValue)
|
||||
{
|
||||
if (!BeginOptionalGroup(name, true))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (IsWriting())
|
||||
{
|
||||
T rawValue = countedValue.Peek();
|
||||
Value("Value", rawValue);
|
||||
typename CountedValue<T>::TCountedID rawId = countedValue.GetLatestID();
|
||||
Value("Id", rawId, 'ui32');
|
||||
}
|
||||
|
||||
if (IsReading())
|
||||
{
|
||||
T rawValue;
|
||||
Value("Value", rawValue);
|
||||
typename CountedValue<T>::TCountedID rawId;
|
||||
Value("Id", rawId, 'ui32');
|
||||
countedValue.UpdateDuringSerializationOnly(rawValue, rawId);
|
||||
}
|
||||
EndGroup();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void Value(const char* name, CountedValue<T>& countedValue, int policy)
|
||||
{
|
||||
if (!BeginOptionalGroup(name, true))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (IsWriting())
|
||||
{
|
||||
T rawValue = countedValue.Peek();
|
||||
Value("Value", rawValue, policy);
|
||||
typename CountedValue<T>::TCountedID rawId = countedValue.GetLatestID();
|
||||
Value("Id", rawId, 'ui32');
|
||||
}
|
||||
|
||||
if (IsReading())
|
||||
{
|
||||
T rawValue;
|
||||
Value("Value", rawValue, policy);
|
||||
typename CountedValue<T>::TCountedID rawId;
|
||||
Value("Id", rawId, 'ui32');
|
||||
countedValue.UpdateDuringSerializationOnly(rawValue, rawId);
|
||||
}
|
||||
EndGroup();
|
||||
}
|
||||
|
||||
bool ValueChar(const char* name, char* buffer, int len)
|
||||
{
|
||||
string temp;
|
||||
|
||||
@@ -24,7 +24,12 @@
|
||||
#endif
|
||||
|
||||
#include "smartptr.h"
|
||||
#include <IFuncVariable.h> // <> required for Interfuscator
|
||||
#include "Cry_Vector2.h"
|
||||
#include "Cry_Vector3.h"
|
||||
#include "Cry_Matrix33.h"
|
||||
#include "Cry_Color.h"
|
||||
#include "smartptr.h"
|
||||
#include "StringUtils.h"
|
||||
#include <IXml.h> // <> required for Interfuscator
|
||||
#include "smartptr.h"
|
||||
#include "VertexFormats.h"
|
||||
@@ -36,8 +41,6 @@
|
||||
#include <CrySizer.h>
|
||||
#include <IMaterial.h>
|
||||
|
||||
#include <CryThreadSafeRendererContainer.h>
|
||||
|
||||
struct IMaterial;
|
||||
class CRendElementBase;
|
||||
class CRenderObject;
|
||||
@@ -2238,74 +2241,6 @@ struct SShaderTexSlots
|
||||
}
|
||||
};
|
||||
|
||||
struct SShaderGenBit
|
||||
{
|
||||
SShaderGenBit()
|
||||
{
|
||||
m_Mask = 0;
|
||||
m_Flags = 0;
|
||||
m_nDependencySet = 0;
|
||||
m_nDependencyReset = 0;
|
||||
m_NameLength = 0;
|
||||
m_dwToken = 0;
|
||||
}
|
||||
string m_ParamName;
|
||||
string m_ParamProp;
|
||||
string m_ParamDesc;
|
||||
int m_NameLength;
|
||||
uint64 m_Mask;
|
||||
uint32 m_Flags;
|
||||
uint32 m_dwToken;
|
||||
std::vector<uint32> m_PrecacheNames;
|
||||
std::vector<string> m_DependSets;
|
||||
std::vector<string> m_DependResets;
|
||||
uint32 m_nDependencySet;
|
||||
uint32 m_nDependencyReset;
|
||||
|
||||
void GetMemoryUsage(ICrySizer* pSizer) const
|
||||
{
|
||||
pSizer->AddObject(m_ParamName);
|
||||
pSizer->AddObject(m_ParamProp);
|
||||
pSizer->AddObject(m_ParamDesc);
|
||||
pSizer->AddObject(m_PrecacheNames);
|
||||
pSizer->AddObject(m_DependSets);
|
||||
pSizer->AddObject(m_DependResets);
|
||||
}
|
||||
};
|
||||
|
||||
struct SShaderGen
|
||||
{
|
||||
uint32 m_nRefCount;
|
||||
TArray<SShaderGenBit*> m_BitMask;
|
||||
SShaderGen()
|
||||
{
|
||||
m_nRefCount = 1;
|
||||
}
|
||||
~SShaderGen()
|
||||
{
|
||||
uint32 i;
|
||||
for (i = 0; i < m_BitMask.Num(); i++)
|
||||
{
|
||||
SShaderGenBit* pBit = m_BitMask[i];
|
||||
SAFE_DELETE(pBit);
|
||||
}
|
||||
m_BitMask.Free();
|
||||
}
|
||||
void Release()
|
||||
{
|
||||
m_nRefCount--;
|
||||
if (!m_nRefCount)
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
}
|
||||
|
||||
void GetMemoryUsage(ICrySizer* pSizer) const
|
||||
{
|
||||
pSizer->AddObject(m_BitMask);
|
||||
}
|
||||
};
|
||||
|
||||
//===================================================================================
|
||||
|
||||
enum EShaderType
|
||||
@@ -2570,7 +2505,6 @@ public:
|
||||
virtual void SetFlags2(int Flags) = 0;
|
||||
virtual void ClearFlags2(int Flags) = 0;
|
||||
virtual bool Reload(int nFlags, const char* szShaderName) = 0;
|
||||
virtual TArray<CRendElementBase*>* GetREs (int nTech) = 0;
|
||||
virtual AZStd::vector<SShaderParam>& GetPublicParams() = 0;
|
||||
virtual int GetTexId () = 0;
|
||||
virtual ITexture* GetBaseTexture(int* nPass, int* nTU) = 0;
|
||||
@@ -2579,7 +2513,6 @@ public:
|
||||
virtual ECull GetCull(void) = 0;
|
||||
virtual int Size(int Flags) = 0;
|
||||
virtual uint64 GetGenerationMask() = 0;
|
||||
virtual SShaderGen* GetGenerationParams() = 0;
|
||||
virtual size_t GetNumberOfUVSets() = 0;
|
||||
virtual int GetTechniqueID(int nTechnique, int nRegisteredTechnique) = 0;
|
||||
virtual AZ::Vertex::Format GetVertexFormat(void) = 0;
|
||||
|
||||
@@ -1,78 +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 <IShader.h> // <> required for Interfuscator
|
||||
|
||||
// Traits
|
||||
#if defined(AZ_RESTRICTED_PLATFORM)
|
||||
#include AZ_RESTRICTED_FILE(IShader_info_h)
|
||||
#elif !defined(LINUX) && !defined(APPLE)
|
||||
#define ISHADER_INFO_H_TRAIT_DEFINE_ETEX_INFO 1
|
||||
#endif
|
||||
|
||||
#if ISHADER_INFO_H_TRAIT_DEFINE_ETEX_INFO
|
||||
ENUM_INFO_BEGIN(ETEX_Format)
|
||||
ENUM_ELEM_INFO(, eTF_Unknown)
|
||||
ENUM_ELEM_INFO(, eTF_R8G8B8A8S)
|
||||
ENUM_ELEM_INFO(, eTF_R8G8B8A8)
|
||||
ENUM_ELEM_INFO(, eTF_A8)
|
||||
ENUM_ELEM_INFO(, eTF_R8)
|
||||
ENUM_ELEM_INFO(, eTF_R8S)
|
||||
ENUM_ELEM_INFO(, eTF_R16)
|
||||
ENUM_ELEM_INFO(, eTF_R16F)
|
||||
ENUM_ELEM_INFO(, eTF_R32F)
|
||||
ENUM_ELEM_INFO(, eTF_R8G8)
|
||||
ENUM_ELEM_INFO(, eTF_R8G8S)
|
||||
ENUM_ELEM_INFO(, eTF_R16G16)
|
||||
ENUM_ELEM_INFO(, eTF_R16G16S)
|
||||
ENUM_ELEM_INFO(, eTF_R16G16F)
|
||||
ENUM_ELEM_INFO(, eTF_R11G11B10F)
|
||||
ENUM_ELEM_INFO(, eTF_R10G10B10A2)
|
||||
ENUM_ELEM_INFO(, eTF_R16G16B16A16)
|
||||
ENUM_ELEM_INFO(, eTF_R16G16B16A16S)
|
||||
ENUM_ELEM_INFO(, eTF_R16G16B16A16F)
|
||||
ENUM_ELEM_INFO(, eTF_R32G32B32A32F)
|
||||
ENUM_ELEM_INFO(, eTF_CTX1)
|
||||
ENUM_ELEM_INFO(, eTF_BC1)
|
||||
ENUM_ELEM_INFO(, eTF_BC2)
|
||||
ENUM_ELEM_INFO(, eTF_BC3)
|
||||
ENUM_ELEM_INFO(, eTF_BC4U)
|
||||
ENUM_ELEM_INFO(, eTF_BC4S)
|
||||
ENUM_ELEM_INFO(, eTF_BC5U)
|
||||
ENUM_ELEM_INFO(, eTF_BC5S)
|
||||
ENUM_ELEM_INFO(, eTF_BC6UH)
|
||||
ENUM_ELEM_INFO(, eTF_BC6SH)
|
||||
ENUM_ELEM_INFO(, eTF_BC7)
|
||||
ENUM_ELEM_INFO(, eTF_R9G9B9E5)
|
||||
ENUM_ELEM_INFO(, eTF_D16)
|
||||
ENUM_ELEM_INFO(, eTF_D24S8)
|
||||
ENUM_ELEM_INFO(, eTF_D32F)
|
||||
ENUM_ELEM_INFO(, eTF_D32FS8)
|
||||
ENUM_ELEM_INFO(, eTF_B5G6R5)
|
||||
ENUM_ELEM_INFO(, eTF_B5G5R5)
|
||||
ENUM_ELEM_INFO(, eTF_B4G4R4A4)
|
||||
ENUM_ELEM_INFO(, eTF_EAC_R11)
|
||||
ENUM_ELEM_INFO(, eTF_EAC_RG11)
|
||||
ENUM_ELEM_INFO(, eTF_ETC2)
|
||||
ENUM_ELEM_INFO(, eTF_ETC2A)
|
||||
ENUM_ELEM_INFO(, eTF_A8L8)
|
||||
ENUM_ELEM_INFO(, eTF_L8)
|
||||
ENUM_ELEM_INFO(, eTF_L8V8U8)
|
||||
ENUM_ELEM_INFO(, eTF_B8G8R8)
|
||||
ENUM_ELEM_INFO(, eTF_L8V8U8X8)
|
||||
ENUM_ELEM_INFO(, eTF_B8G8R8X8)
|
||||
ENUM_ELEM_INFO(, eTF_B8G8R8A8)
|
||||
ENUM_INFO_END(ETEX_Format)
|
||||
#endif
|
||||
@@ -1,493 +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.
|
||||
|
||||
// This is the prototypes of interfaces that will be used for asynchronous
|
||||
// I/O (streaming).
|
||||
// THIS IS NOT FINAL AND IS SUBJECT TO CHANGE WITHOUT NOTICE
|
||||
|
||||
// Some excerpts explaining basic ideas behind streaming design here:
|
||||
|
||||
/*
|
||||
* The idea is that the data loaded is ready for usage and ideally doesn't need further transformation,
|
||||
* therefore the client allocates the buffer (to avoid extra copy). All the data transformations should take place in the Resource Compiler. If you have to allocate a lot of small memory objects, you should revise this strategy in favor of one big allocation (again, that will be read directly from the compiled file).
|
||||
* Anyway, we can negotiate that the streaming engine allocates this memory.
|
||||
* In the end, it could make use of a memory pool, and copying data is not the bottleneck in our engine
|
||||
*
|
||||
* The client should take care of all fast operations. Looking up file size should be fast on the virtual
|
||||
* file system in a pak file, because the directory should be preloaded in memory
|
||||
*/
|
||||
|
||||
#ifndef CRYINCLUDE_CRYCOMMON_ISTREAMENGINE_H
|
||||
#define CRYINCLUDE_CRYCOMMON_ISTREAMENGINE_H
|
||||
#pragma once
|
||||
|
||||
|
||||
#include <list>
|
||||
#include "smartptr.h"
|
||||
#include "CryThread.h"
|
||||
|
||||
#include "IStreamEngineDefs.h"
|
||||
|
||||
class IStreamCallback;
|
||||
class ICrySizer;
|
||||
|
||||
#define STREAM_TASK_TYPE_AUDIO_ALL ((1 << eStreamTaskTypeMusic) | (1 << eStreamTaskTypeSound) | (1 << eStreamTaskTypeFSBCache))
|
||||
|
||||
// Description:
|
||||
// This is used as parameter to the asynchronous read function
|
||||
// all the unnecessary parameters go here, because there are many of them.
|
||||
struct StreamReadParams
|
||||
{
|
||||
public:
|
||||
StreamReadParams()
|
||||
{
|
||||
memset(this, 0, sizeof(*this));
|
||||
ePriority = estpNormal;
|
||||
}
|
||||
|
||||
StreamReadParams (
|
||||
DWORD_PTR _dwUserData,
|
||||
EStreamTaskPriority _ePriority = estpNormal,
|
||||
unsigned _nLoadTime = 0,
|
||||
unsigned _nMaxLoadTime = 0,
|
||||
unsigned _nOffset = 0,
|
||||
unsigned _nSize = 0,
|
||||
void* _pBuffer = NULL,
|
||||
unsigned _nFlags = 0
|
||||
)
|
||||
: dwUserData (_dwUserData)
|
||||
, ePriority(_ePriority)
|
||||
, nPerceptualImportance(0)
|
||||
, nLoadTime(_nLoadTime)
|
||||
, nMaxLoadTime(_nMaxLoadTime)
|
||||
, pBuffer (_pBuffer)
|
||||
, nOffset (_nOffset)
|
||||
, nSize (_nSize)
|
||||
, eMediaType(eStreamSourceTypeUnknown)
|
||||
, nFlags (_nFlags)
|
||||
{
|
||||
}
|
||||
|
||||
// Summary:
|
||||
// File name.
|
||||
//const char* szFile;
|
||||
|
||||
// Summary:
|
||||
// The callback.
|
||||
//IStreamCallback* pAsyncCallback;
|
||||
|
||||
// Summary:
|
||||
// The user data that'll be used to call the callback.
|
||||
DWORD_PTR dwUserData;
|
||||
|
||||
// The priority of this read
|
||||
EStreamTaskPriority ePriority;
|
||||
|
||||
// Value from 0-255 of the perceptual importance of the task (used for debugging task sheduling)
|
||||
uint8 nPerceptualImportance;
|
||||
|
||||
// Description:
|
||||
// The desirable loading time, in milliseconds, from the time of call
|
||||
// 0 means as fast as possible (desirably in this frame).
|
||||
unsigned nLoadTime;
|
||||
|
||||
// Description:
|
||||
// The maximum load time, in milliseconds. 0 means forever. If the read lasts longer, it can be discarded.
|
||||
// WARNING: avoid too small max times, like 1-10 ms, because many loads will be discarded in this case.
|
||||
unsigned nMaxLoadTime;
|
||||
|
||||
// Description:
|
||||
// The buffer into which to read the file or the file piece
|
||||
// if this is NULL, the streaming engine will supply the buffer.
|
||||
// Notes:
|
||||
// DO NOT USE THIS BUFFER during read operation! DO NOT READ from it, it can lead to memory corruption!
|
||||
void* pBuffer;
|
||||
|
||||
// Description:
|
||||
// Offset in the file to read; if this is not 0, then the file read
|
||||
// occurs beginning with the specified offset in bytes.
|
||||
// The callback interface receives the size of already read data as nSize
|
||||
// and generally behaves as if the piece of file would be a file of its own.
|
||||
unsigned nOffset;
|
||||
|
||||
// Description:
|
||||
// Number of bytes to read; if this is 0, then the whole file is read,
|
||||
// if nSize == 0 && nOffset != 0, then the file from the offset to the end is read.
|
||||
// If nSize != 0, then the file piece from nOffset is read, at most nSize bytes
|
||||
// (if less, an error is reported). So, from nOffset byte to nOffset + nSize - 1 byte in the file.
|
||||
unsigned nSize;
|
||||
|
||||
// Description:
|
||||
// Media type to use when starting file request - if wrong, the request may take longer to complete
|
||||
EStreamSourceMediaType eMediaType;
|
||||
|
||||
// Description:
|
||||
// The combination of one or several flags from the stream engine general purpose flags.
|
||||
// See also:
|
||||
// IStreamEngine::EFlags
|
||||
unsigned nFlags;
|
||||
};
|
||||
|
||||
struct StreamReadBatchParams
|
||||
{
|
||||
StreamReadBatchParams()
|
||||
: tSource((EStreamTaskType)0)
|
||||
, szFile(NULL)
|
||||
, pCallback(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
EStreamTaskType tSource;
|
||||
const char* szFile;
|
||||
IStreamCallback* pCallback;
|
||||
StreamReadParams params;
|
||||
};
|
||||
|
||||
struct IStreamEngineListener
|
||||
{
|
||||
// <interfuscator:shuffle>
|
||||
virtual ~IStreamEngineListener() {}
|
||||
|
||||
virtual void OnStreamEnqueue(const void* pReq, const char* filename, EStreamTaskType source, const StreamReadParams& readParams) = 0;
|
||||
virtual void OnStreamComputedSortKey(const void* pReq, uint64 key) = 0;
|
||||
virtual void OnStreamBeginIO(const void* pReq, uint32 compressSize, uint32 readSize, EStreamSourceMediaType mediaType) = 0;
|
||||
virtual void OnStreamEndIO(const void* pReq) = 0;
|
||||
virtual void OnStreamBeginInflate(const void* pReq) = 0;
|
||||
virtual void OnStreamEndInflate(const void* pReq) = 0;
|
||||
virtual void OnStreamBeginAsyncCallback(const void* pReq) = 0;
|
||||
virtual void OnStreamEndAsyncCallback(const void* pReq) = 0;
|
||||
virtual void OnStreamDone(const void* pReq) = 0;
|
||||
virtual void OnStreamPreempted(const void* pReq) = 0;
|
||||
virtual void OnStreamResumed(const void* pReq) = 0;
|
||||
// </interfuscator:shuffle>
|
||||
};
|
||||
|
||||
// Description:
|
||||
// The highest level. There is only one StreamingEngine in the application
|
||||
// and it controls all I/O streams.
|
||||
struct IStreamEngine
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
enum EJobType
|
||||
{
|
||||
ejtStarted = 1 << 0,
|
||||
ejtPending = 1 << 1,
|
||||
ejtFinished = 1 << 2,
|
||||
};
|
||||
|
||||
// Summary:
|
||||
// General purpose flags.
|
||||
enum EFlags
|
||||
{
|
||||
// Description:
|
||||
// If this is set only asynchronous callback will be called.
|
||||
FLAGS_NO_SYNC_CALLBACK = BIT(0),
|
||||
// Description:
|
||||
// If this is set the file will be read from disc directly, instead of from the pak system.
|
||||
FLAGS_FILE_ON_DISK = BIT(1),
|
||||
// Description:
|
||||
// Ignore the tmp out of streaming memory for this request
|
||||
FLAGS_IGNORE_TMP_OUT_OF_MEM = BIT(2),
|
||||
// Description:
|
||||
// External buffer is write only
|
||||
FLAGS_WRITE_ONLY_EXTERNAL_BUFFER = BIT(3),
|
||||
};
|
||||
|
||||
// <interfuscator:shuffle>
|
||||
// Description:
|
||||
// Starts asynchronous read from the specified file (the file may be on a
|
||||
// virtual file system, in pak or zip file or wherever).
|
||||
// Reads the file contents into the given buffer, up to the given size.
|
||||
// Upon success, calls success callback. If the file is truncated or for other
|
||||
// reason can not be read, calls error callback. The callback can be NULL (in this case, the client should poll
|
||||
// the returned IReadStream object; the returned object must be locked for that)
|
||||
// NOTE: the error/success/ progress callbacks can also be called from INSIDE this function.
|
||||
// Arguments:
|
||||
// tSource -
|
||||
// szFile -
|
||||
// pCallback -
|
||||
// pParams - PLACEHOLDER for the future additional parameters (like priority), or really
|
||||
// a pointer to a structure that will hold the parameters if there are too many of them.
|
||||
// Return Value:
|
||||
// IReadStream is reference-counted and will be automatically deleted if you don't refer to it;
|
||||
// if you don't store it immediately in an auto-pointer, it may be deleted as soon as on the next line of code,
|
||||
// because the read operation may complete immediately inside StartRead() and the object is self-disposed
|
||||
// as soon as the callback is called.
|
||||
// Remarks:
|
||||
// In some implementations disposal of the old pointers happen synchronously
|
||||
// (in the main thread) outside StartRead() (it happens in the entity update),
|
||||
// so you're guaranteed that it won't trash inside the calling function. However, this may change in the future
|
||||
// and you'll be required to assign it to IReadStream immediately (StartRead will return IReadStream_AutoPtr then).
|
||||
// See also:
|
||||
// IReadStream,IReadStream_AutoPtr
|
||||
virtual IReadStreamPtr StartRead (const EStreamTaskType tSource, const char* szFile, IStreamCallback* pCallback = NULL, const StreamReadParams* pParams = NULL) = 0;
|
||||
|
||||
// Pass a callback to preRequestCallback if you need to execute code right before the requests get enqueued; the callback is called only once per execution
|
||||
virtual size_t StartBatchRead(IReadStreamPtr* pStreamsOut, const StreamReadBatchParams* pReqs, size_t numReqs, AZStd::function<void ()>* preRequestCallback = nullptr) = 0;
|
||||
|
||||
// Call this methods before/after submitting large number of new requests.
|
||||
virtual void BeginReadGroup() = 0;
|
||||
virtual void EndReadGroup() = 0;
|
||||
|
||||
// Pause/resumes streaming of specific data types.
|
||||
// nPauseTypesBitmask is a bit mask of data types (ex, 1<<eStreamTaskTypeGeometry)
|
||||
virtual void PauseStreaming(bool bPause, uint32 nPauseTypesBitmask) = 0;
|
||||
|
||||
// Get pause bit mask
|
||||
virtual uint32 GetPauseMask() const = 0;
|
||||
|
||||
// Pause/resumes any IO active from the streaming engine
|
||||
virtual void PauseIO(bool bPause) = 0;
|
||||
|
||||
// Description:
|
||||
// Is the streaming data available on harddisc for fast streaming
|
||||
virtual bool IsStreamDataOnHDD() const = 0;
|
||||
|
||||
// Description:
|
||||
// Inform streaming engine that the streaming data is available on HDD
|
||||
virtual void SetStreamDataOnHDD(bool bFlag) = 0;
|
||||
|
||||
// Description:
|
||||
// Per frame update ofthe streaming engine, synchronous events are dispatched from this function.
|
||||
virtual void Update() = 0;
|
||||
|
||||
// Description:
|
||||
// Per frame update of the streaming engine, synchronous events are dispatched from this function, by particular TypesBitmask.
|
||||
virtual void Update(uint32 nUpdateTypesBitmask) = 0;
|
||||
|
||||
// Description:
|
||||
// Waits until all submitted requests are complete. (can abort all reads which are currently in flight)
|
||||
virtual void UpdateAndWait(bool bAbortAll = false) = 0;
|
||||
|
||||
// Description:
|
||||
// Puts the memory statistics into the given sizer object.
|
||||
// According to the specifications in interface ICrySizer.
|
||||
// See also:
|
||||
// ICrySizer
|
||||
virtual void GetMemoryStatistics(ICrySizer* pSizer) = 0;
|
||||
|
||||
#if defined(STREAMENGINE_ENABLE_STATS)
|
||||
// Description:
|
||||
// Returns the streaming statistics collected from the previous call.
|
||||
virtual SStreamEngineStatistics& GetStreamingStatistics() = 0;
|
||||
virtual void ClearStatistics() = 0;
|
||||
|
||||
// Description:
|
||||
// returns the bandwidth used for the given type of streaming task
|
||||
virtual void GetBandwidthStats(EStreamTaskType type, float* bandwidth) = 0;
|
||||
#endif
|
||||
|
||||
// Description:
|
||||
// Returns the counts of open streaming requests.
|
||||
virtual void GetStreamingOpenStatistics(SStreamEngineOpenStats& openStatsOut) = 0;
|
||||
|
||||
virtual const char* GetStreamTaskTypeName(EStreamTaskType type) = 0;
|
||||
|
||||
#if defined(STREAMENGINE_ENABLE_LISTENER)
|
||||
// Description:
|
||||
// Sets up a listener for stream events (used for statoscope)
|
||||
virtual void SetListener(IStreamEngineListener* pListener) = 0;
|
||||
virtual IStreamEngineListener* GetListener() = 0;
|
||||
#endif
|
||||
|
||||
virtual ~IStreamEngine() {}
|
||||
// </interfuscator:shuffle>
|
||||
};
|
||||
|
||||
// Description:
|
||||
// This is the file "handle" that can be used to query the status
|
||||
// of the asynchronous operation on the file. The same object may be returned
|
||||
// for the same file to multiple clients.
|
||||
// Notes:
|
||||
// It will actually represent the asynchronous object in memory, and will be
|
||||
// thread-safe reference-counted (both AddRef() and Release() will be virtual
|
||||
// and thread-safe, just like the others)
|
||||
// Example:
|
||||
// USE:
|
||||
// IReadStream_AutoPtr pReadStream = pStreamEngine->StartRead ("bla.xxx", this);
|
||||
// OR:
|
||||
// pStreamEngine->StartRead ("MusicSystem","bla.xxx", this);
|
||||
class IReadStream
|
||||
{
|
||||
public:
|
||||
// <interfuscator:shuffle>
|
||||
// Summary:
|
||||
// Increment ref count, returns new count
|
||||
virtual int AddRef() = 0;
|
||||
// Summary:
|
||||
// Decrement ref count, returns new count
|
||||
virtual int Release() = 0;
|
||||
// Summary:
|
||||
// Returns true if the file read was not successful.
|
||||
virtual bool IsError() = 0;
|
||||
// Return Value:
|
||||
// True if the file read was completed successfully.
|
||||
// Summary:
|
||||
// Checks IsError to check if the whole requested file (piece) was read.
|
||||
virtual bool IsFinished() = 0;
|
||||
// Description:
|
||||
// Returns the number of bytes read so far (the whole buffer size if IsFinished())
|
||||
// Arguments:
|
||||
// bWait - if == true, then waits until the pending I/O operation completes.
|
||||
// Return Value:
|
||||
// The total number of bytes read (if it completes successfully, returns the size of block being read)
|
||||
virtual unsigned int GetBytesRead(bool bWait = false) = 0;
|
||||
// Description:
|
||||
// Returns the buffer into which the data has been or will be read
|
||||
// at least GetBytesRead() bytes in this buffer are guaranteed to be already read.
|
||||
// Notes:
|
||||
// DO NOT USE THIS BUFFER during read operation! DO NOT READ from it, it can lead to memory corruption!
|
||||
virtual const void* GetBuffer () = 0;
|
||||
|
||||
// Description:
|
||||
// Returns the transparent DWORD that was passed in the StreamReadParams::dwUserData field
|
||||
// of the structure passed in the call to IStreamEngine::StartRead.
|
||||
// See also:
|
||||
// StreamReadParams::dwUserData,IStreamEngine::StartRead
|
||||
virtual DWORD_PTR GetUserData() = 0;
|
||||
|
||||
// Summary:
|
||||
// Set user defined data into stream's params.
|
||||
virtual void SetUserData(DWORD_PTR dwUserData) = 0;
|
||||
|
||||
// Description:
|
||||
// Tries to stop reading the stream; this is advisory and may have no effect
|
||||
// but the callback will not be called after this. If you just destructing object,
|
||||
// dereference this object and it will automatically abort and release all associated resources.
|
||||
virtual void Abort() = 0;
|
||||
|
||||
// Description:
|
||||
// Tries to stop reading the stream, as long as IO or the async callback is not currently
|
||||
// in progress.
|
||||
virtual bool TryAbort() = 0;
|
||||
|
||||
// Summary:
|
||||
// Unconditionally waits until the callback is called.
|
||||
// if nMaxWaitMillis is not negative wait for the specified ammount of milliseconds then exit.
|
||||
// Example:
|
||||
// If the stream hasn't yet finish, it's guaranteed that the user-supplied callback
|
||||
// is called before return from this function (unless no callback was specified).
|
||||
virtual void Wait(int nMaxWaitMillis = -1) = 0;
|
||||
|
||||
// Summary:
|
||||
// Returns stream params.
|
||||
virtual const StreamReadParams& GetParams() const = 0;
|
||||
|
||||
// Summary:
|
||||
// Returns caller type.
|
||||
virtual const EStreamTaskType GetCallerType() const = 0;
|
||||
|
||||
// Summary:
|
||||
// Returns media type used to satisfy request - only valid once stream has begun read.
|
||||
virtual EStreamSourceMediaType GetMediaType() const = 0;
|
||||
|
||||
// Summary:
|
||||
// Returns pointer to callback routine(can be NULL).
|
||||
virtual IStreamCallback* GetCallback() const = 0;
|
||||
|
||||
// Summary:
|
||||
// Returns IO error #.
|
||||
virtual unsigned GetError() const = 0;
|
||||
|
||||
// Summary:
|
||||
// Returns IO error name
|
||||
virtual const char* GetErrorName() const = 0;
|
||||
|
||||
// Summary:
|
||||
// Returns stream name.
|
||||
virtual const char* GetName() const = 0;
|
||||
|
||||
// Summary:
|
||||
// Free temporary memory allocated for this stream, when not needed anymore.
|
||||
// Can be called from Async callback, to free memory earlier, not waiting for synchrounus callback.
|
||||
virtual void FreeTemporaryMemory() = 0;
|
||||
// </interfuscator:shuffle>
|
||||
|
||||
protected:
|
||||
// Summary:
|
||||
// The clients are not allowed to destroy this object directly; only via Release().
|
||||
virtual ~IReadStream() {}
|
||||
};
|
||||
|
||||
TYPEDEF_AUTOPTR(IReadStream);
|
||||
|
||||
// Description:
|
||||
// CryPak supports asynchronous reading through this interface. The callback
|
||||
// is called from the main thread in the frame update loop.
|
||||
//
|
||||
// The callback receives packets through StreamOnComplete() and
|
||||
// StreamOnProgress(). The second one can be used to update the asset based
|
||||
// on the partial data that arrived. the callback that will be called by the
|
||||
// streaming engine must be implemented by all clients that want to use
|
||||
// StreamingEngine services
|
||||
// Remarks:
|
||||
// the pStream interface is guaranteed to be locked (have reference count > 0)
|
||||
// while inside the function, but can vanish any time outside the function.
|
||||
// If you need it, keep it from the beginning (after call to StartRead())
|
||||
// some or all callbacks MAY be called from inside IStreamEngine::StartRead()
|
||||
//
|
||||
// Example:
|
||||
// <code>
|
||||
// IStreamEngine *pStreamEngine = g_pISystem->GetStreamEngine(); // get streaming engine
|
||||
// IStreamCallback *pAsyncCallback = &MyClass; // user
|
||||
//
|
||||
// StreamReadParams params;
|
||||
//
|
||||
// params.dwUserData = 0;
|
||||
// params.nSize = 0;
|
||||
// params.pBuffer = NULL;
|
||||
// params.nLoadTime = 10000;
|
||||
// params.nMaxLoadTime = 10000;
|
||||
//
|
||||
// pStreamEngine->StartRead( .. pAsyncCallback .. params .. ); // registers callback
|
||||
// </code>
|
||||
class IStreamCallback
|
||||
{
|
||||
public:
|
||||
// <interfuscator:shuffle>
|
||||
virtual ~IStreamCallback(){}
|
||||
|
||||
// Description:
|
||||
// Signals that the file length for the request has been found, and that storage is needed
|
||||
// Either a pointer to a block of nSize bytes can be returned, into which the file will be
|
||||
// streamed, or NULL can be returned, in which case temporary memory will be allocated
|
||||
// internally by the stream engine (which will be freed upon job completion).
|
||||
virtual void* StreamOnNeedStorage ([[maybe_unused]] IReadStream* pStream, [[maybe_unused]] unsigned nSize, [[maybe_unused]] bool& bAbortOnFailToAlloc) {return NULL; }
|
||||
|
||||
// Description:
|
||||
// Signals that reading the requested data has completed (with or without error).
|
||||
// This callback is always called, whether an error occurs or not.
|
||||
// pStream will signal either IsFinished() or IsError() and will hold the (perhaps partially) read data until this interface is released.
|
||||
// GetBytesRead() will return the size of the file (the completely read buffer) in case of successful operation end
|
||||
// or the size of partially read data in case of error (0 if nothing was read).
|
||||
// Pending status is true during this callback, because the callback itself is the part of IO operation.
|
||||
// nError == 0 : Success
|
||||
// nError != 0 : Error code
|
||||
virtual void StreamAsyncOnComplete ([[maybe_unused]] IReadStream* pStream, [[maybe_unused]] unsigned nError) {}
|
||||
|
||||
// Description:
|
||||
// Signals that reading the requested data has completed (with or without error).
|
||||
// This callback is always called, whether an error occurs or not.
|
||||
// pStream will signal either IsFinished() or IsError() and will hold the (perhaps partially) read data until this interface is released.
|
||||
// GetBytesRead() will return the size of the file (the completely read buffer) in case of successful operation end
|
||||
// or the size of partially read data in case of error (0 if nothing was read).
|
||||
// Pending status is true during this callback, because the callback itself is the part of IO operation.
|
||||
// nError == 0 : Success
|
||||
// nError != 0 : Error code
|
||||
virtual void StreamOnComplete ([[maybe_unused]] IReadStream* pStream, [[maybe_unused]] unsigned nError) {}
|
||||
// </interfuscator:shuffle>
|
||||
};
|
||||
|
||||
#endif // CRYINCLUDE_CRYCOMMON_ISTREAMENGINE_H
|
||||
@@ -1,236 +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_ISTREAMENGINEDEFS_H
|
||||
#define CRYINCLUDE_CRYCOMMON_ISTREAMENGINEDEFS_H
|
||||
#pragma once
|
||||
|
||||
|
||||
#if defined(ENABLE_PROFILING_CODE)
|
||||
#define STREAMENGINE_ENABLE_LISTENER
|
||||
#define STREAMENGINE_ENABLE_STATS
|
||||
#endif
|
||||
|
||||
enum : unsigned int
|
||||
{
|
||||
ERROR_UNKNOWN_ERROR = 0xF0000000,
|
||||
ERROR_UNEXPECTED_DESTRUCTION = 0xF0000001,
|
||||
ERROR_INVALID_CALL = 0xF0000002,
|
||||
ERROR_CANT_OPEN_FILE = 0xF0000003,
|
||||
ERROR_REFSTREAM_ERROR = 0xF0000004,
|
||||
ERROR_OFFSET_OUT_OF_RANGE = 0xF0000005,
|
||||
ERROR_REGION_OUT_OF_RANGE = 0xF0000006,
|
||||
ERROR_SIZE_OUT_OF_RANGE = 0xF0000007,
|
||||
ERROR_CANT_START_READING = 0xF0000008,
|
||||
ERROR_OUT_OF_MEMORY = 0xF0000009,
|
||||
ERROR_ABORTED_ON_SHUTDOWN = 0xF000000A,
|
||||
ERROR_OUT_OF_MEMORY_QUOTA = 0xF000000B,
|
||||
ERROR_ZIP_CACHE_FAILURE = 0xF000000C,
|
||||
ERROR_USER_ABORT = 0xF000000D,
|
||||
ERROR_MISSCHEDULED = 0xF000000F,
|
||||
ERROR_VERIFICATION_FAIL = 0xF0000010,
|
||||
ERROR_PREEMPTED = 0xF0000011,
|
||||
ERROR_DECOMPRESSION_FAIL = 0xF0000012
|
||||
};
|
||||
|
||||
// Summary:
|
||||
// Types of streaming tasks
|
||||
// Affects priority directly
|
||||
enum EStreamTaskType
|
||||
{
|
||||
eStreamTaskTypeCount = 14,
|
||||
eStreamTaskTypeGeomCache = 13,
|
||||
eStreamTaskTypePak = 12,
|
||||
eStreamTaskTypeFlash = 11,
|
||||
eStreamTaskTypeVideo = 10,
|
||||
|
||||
eStreamTaskTypeMergedMesh = 9,
|
||||
eStreamTaskTypeShader = 8,
|
||||
eStreamTaskTypeSound = 7,
|
||||
eStreamTaskTypeMusic = 6,
|
||||
eStreamTaskTypeFSBCache = 5,
|
||||
eStreamTaskTypeAnimation = 4,
|
||||
eStreamTaskTypeTerrain = 3,
|
||||
eStreamTaskTypeGeometry = 2,
|
||||
eStreamTaskTypeTexture = 1,
|
||||
};
|
||||
|
||||
// Summary:
|
||||
// Priority types of streaming tasks
|
||||
// Affects priority directly
|
||||
// Limiting number of priority values allows streaming system to minimize seek time
|
||||
enum EStreamTaskPriority
|
||||
{
|
||||
estpUrgent = 0,
|
||||
estpPreempted = 1, //For internal use only
|
||||
estpAboveNormal = 2,
|
||||
estpNormal = 3,
|
||||
estpBelowNormal = 4,
|
||||
estpIdle = 5,
|
||||
};
|
||||
|
||||
enum EStreamSourceMediaType : int32_t
|
||||
{
|
||||
eStreamSourceTypeUnknown = 0,
|
||||
eStreamSourceTypeHDD,
|
||||
eStreamSourceTypeDisc,
|
||||
eStreamSourceTypeMemory,
|
||||
};
|
||||
|
||||
#if defined(STREAMENGINE_ENABLE_STATS)
|
||||
struct SStreamEngineStatistics
|
||||
{
|
||||
struct SMediaTypeInfo
|
||||
{
|
||||
SMediaTypeInfo()
|
||||
{
|
||||
ResetStats();
|
||||
}
|
||||
void ResetStats()
|
||||
{
|
||||
memset(this, 0, sizeof(SMediaTypeInfo));
|
||||
}
|
||||
|
||||
float fActiveDuringLastSecond; // Amount of time media device was active during last second
|
||||
float fAverageActiveTime; // Average time since last reset that the media device was active
|
||||
|
||||
uint32 nBytesRead; // Bytes read during last second.
|
||||
uint32 nRequestCount; // Amount of requests during last second.
|
||||
uint64 nTotalBytesRead; // Read bytes total from reset.
|
||||
uint32 nTotalRequestCount; // Number of request from reset.
|
||||
|
||||
uint64 nSeekOffsetLastSecond; // Average seek offset during the last second
|
||||
uint64 nAverageSeekOffset; // Average seek offset since last reset
|
||||
|
||||
uint32 nCurrentReadBandwidth; // Bytes/second for last second
|
||||
uint32 nSessionReadBandwidth; // Bytes/second for last second
|
||||
|
||||
uint32 nActualReadBandwidth; // Bytes/second for last second - only taking actual reading into account
|
||||
uint32 nAverageActualReadBandwidth; // Average read bandwidth in total from reset - only taking actual read time into account
|
||||
};
|
||||
|
||||
SMediaTypeInfo hddInfo;
|
||||
SMediaTypeInfo memoryInfo;
|
||||
SMediaTypeInfo discInfo;
|
||||
|
||||
uint32 nTotalSessionReadBandwidth;// Average read bandwidth in total from reset - taking full time into account from reset
|
||||
uint32 nTotalCurrentReadBandwidth;// Total bytes/sec over all types and systems.
|
||||
|
||||
int nPendingReadBytes; // How many bytes still need to be read
|
||||
float fAverageCompletionTime; // Time in seconds on average takes to complete file request.
|
||||
float fAverageRequestCount; // Average requests per second being done to streaming engine
|
||||
|
||||
uint64 nMainStreamingThreadWait;
|
||||
|
||||
uint64 nTotalBytesRead; // Read bytes total from reset.
|
||||
uint32 nTotalRequestCount; // Number of request from reset to the streaming engine.
|
||||
uint32 nTotalStreamingRequestCount; // Number of request from reset which actually resulted in streaming data.
|
||||
|
||||
int nCurrentDecompressCount; // Number of requests currently waiting to be decompresses
|
||||
int nCurrentAsyncCount; // Number of requests currently waiting to be async callback
|
||||
int nCurrentFinishedCount; // Number of requests currently waiting to be finished by mainthread
|
||||
|
||||
uint32 nDecompressBandwidth; // Bytes/second for last second
|
||||
uint32 nVerifyBandwidth; // Bytes/second for last second
|
||||
uint32 nDecompressBandwidthAverage; // Bytes/second in total.
|
||||
uint32 nVerifyBandwidthAverage; // Bytes/second in total.
|
||||
|
||||
bool bTempMemOutOfBudget; // Was the temporary streaming memory out of budget during the last second
|
||||
int nMaxTempMemory; // Maximum temporary memory used by the streaming system
|
||||
int nTempMemory;
|
||||
|
||||
struct SRequestTypeInfo
|
||||
{
|
||||
SRequestTypeInfo()
|
||||
: nPendingReadBytes(0)
|
||||
{
|
||||
ResetStats();
|
||||
}
|
||||
void ResetStats()
|
||||
{
|
||||
nTmpReadBytes = 0;
|
||||
nTotalStreamingRequestCount = 0;
|
||||
nTotalReadBytes = 0;
|
||||
nTotalRequestDataSize = 0;
|
||||
nTotalRequestCount = 0;
|
||||
nCurrentReadBandwidth = 0;
|
||||
nSessionReadBandwidth = 0;
|
||||
fTotalCompletionTime = .0f;
|
||||
fAverageCompletionTime = .0f;
|
||||
}
|
||||
|
||||
void Merge(const SRequestTypeInfo& _other)
|
||||
{
|
||||
nPendingReadBytes += _other.nPendingReadBytes;
|
||||
nTmpReadBytes += _other.nTmpReadBytes;
|
||||
nTotalStreamingRequestCount += _other.nTotalStreamingRequestCount;
|
||||
nTotalReadBytes += _other.nTotalReadBytes;
|
||||
nTotalRequestDataSize += _other.nTotalRequestDataSize;
|
||||
nTotalRequestCount += _other.nTotalRequestCount;
|
||||
fTotalCompletionTime += _other.fTotalCompletionTime;
|
||||
}
|
||||
|
||||
int nPendingReadBytes; // How many bytes still need to be read from media
|
||||
|
||||
uint64 nTmpReadBytes; // Read bytes since last update to compute current bandwidth
|
||||
|
||||
uint32 nTotalStreamingRequestCount; // Total actual streaming requests of this type
|
||||
uint64 nTotalReadBytes; // Total actual read bytes (compressed data)
|
||||
uint64 nTotalRequestDataSize; // Total requested bytes from client (uncompressed data)
|
||||
uint32 nTotalRequestCount; // Total number of finished requests
|
||||
|
||||
uint32 nCurrentReadBandwidth; // Bytes/second for this type during last second
|
||||
uint32 nSessionReadBandwidth; // Average read bandwidth in total from reset - taking full time into account from reset
|
||||
|
||||
float fTotalCompletionTime; // Time it took to finish all current requests
|
||||
float fAverageCompletionTime; // Average time it takes to fully complete a request of this type
|
||||
float fAverageRequestCount; // Average amount of requests made per second
|
||||
};
|
||||
|
||||
SRequestTypeInfo typeInfo[eStreamTaskTypeCount];
|
||||
|
||||
struct SAsset
|
||||
{
|
||||
CryStringLocal m_sName;
|
||||
int m_nSize;
|
||||
const bool operator<(const SAsset& a) const { return m_nSize > a.m_nSize; }
|
||||
SAsset() {}
|
||||
SAsset(const CryStringLocal& sName, const int nSize)
|
||||
: m_sName(sName)
|
||||
, m_nSize(nSize) { }
|
||||
|
||||
friend void swap(SAsset& a, SAsset& b)
|
||||
{
|
||||
using std::swap;
|
||||
|
||||
a.m_sName.swap(b.m_sName);
|
||||
swap(a.m_nSize, b.m_nSize);
|
||||
}
|
||||
};
|
||||
DynArray<SAsset> vecHeavyAssets;
|
||||
};
|
||||
#endif
|
||||
|
||||
struct SStreamEngineOpenStats
|
||||
{
|
||||
int nOpenRequestCount;
|
||||
int nOpenRequestCountByType[eStreamTaskTypeCount];
|
||||
};
|
||||
|
||||
class IReadStream;
|
||||
TYPEDEF_AUTOPTR(IReadStream);
|
||||
|
||||
// typedef IReadStream_AutoPtr auto ptr wrapper
|
||||
typedef IReadStream_AutoPtr IReadStreamPtr;
|
||||
|
||||
#endif // CRYINCLUDE_CRYCOMMON_ISTREAMENGINEDEFS_H
|
||||
@@ -65,12 +65,10 @@ struct IProcess;
|
||||
struct ITimer;
|
||||
struct ICryFont;
|
||||
struct IMovieSystem;
|
||||
struct IMemoryManager;
|
||||
namespace Audio
|
||||
{
|
||||
struct IAudioSystem;
|
||||
} // namespace Audio
|
||||
struct IStreamEngine;
|
||||
struct SFileVersion;
|
||||
struct INameTable;
|
||||
struct ILevelSystem;
|
||||
@@ -78,18 +76,11 @@ struct IViewSystem;
|
||||
class ICrySizer;
|
||||
class IXMLBinarySerializer;
|
||||
struct IReadWriteXMLSink;
|
||||
struct IResourceManager;
|
||||
struct ITextModeConsole;
|
||||
struct IAVI_Reader;
|
||||
class CPNoise3;
|
||||
struct ILocalizationManager;
|
||||
struct IZLibCompressor;
|
||||
struct IZLibDecompressor;
|
||||
struct ILZ4Decompressor;
|
||||
class IZStdDecompressor;
|
||||
struct IOutputPrintSink;
|
||||
struct IWindowMessageHandler;
|
||||
struct IImageHandler;
|
||||
|
||||
namespace AZ
|
||||
{
|
||||
@@ -528,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.
|
||||
|
||||
@@ -558,7 +548,6 @@ struct SSystemInitParams
|
||||
pUserCallback = NULL;
|
||||
sLogFileName = NULL;
|
||||
autoBackupLogs = true;
|
||||
pValidator = NULL;
|
||||
pPrintSync = NULL;
|
||||
memset(szSystemCmdLine, 0, sizeof(szSystemCmdLine));
|
||||
|
||||
@@ -828,22 +817,10 @@ struct ISystem
|
||||
virtual void DoWorkDuringOcclusionChecks() = 0;
|
||||
virtual bool NeedDoWorkDuringOcclusionChecks() = 0;
|
||||
|
||||
// Summary:
|
||||
// Returns the current used memory.
|
||||
virtual uint32 GetUsedMemory() = 0;
|
||||
|
||||
// Summary:
|
||||
// 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;
|
||||
@@ -860,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.
|
||||
@@ -897,35 +867,21 @@ 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 IStreamEngine* GetStreamEngine() = 0;
|
||||
virtual ICmdLine* GetICmdLine() = 0;
|
||||
virtual ILog* GetILog() = 0;
|
||||
virtual AZ::IO::IArchive* GetIPak() = 0;
|
||||
virtual ICryFont* GetICryFont() = 0;
|
||||
virtual IMemoryManager* GetIMemoryManager() = 0;
|
||||
virtual IMovieSystem* GetIMovieSystem() = 0;
|
||||
virtual ::IConsole* GetIConsole() = 0;
|
||||
virtual IRemoteConsole* GetIRemoteConsole() = 0;
|
||||
// Returns:
|
||||
// Can be NULL, because it only exists when running through the editor, not in pure game mode.
|
||||
virtual IResourceManager* GetIResourceManager() = 0;
|
||||
virtual IProfilingSystem* GetIProfilingSystem() = 0;
|
||||
virtual ISystemEventDispatcher* GetISystemEventDispatcher() = 0;
|
||||
|
||||
virtual ITimer* GetITimer() = 0;
|
||||
|
||||
virtual void DebugStats(bool checkpoint, bool leaks) = 0;
|
||||
virtual void DumpWinHeaps() = 0;
|
||||
virtual int DumpMMStats(bool log) = 0;
|
||||
|
||||
// Arguments:
|
||||
// bValue - Set to true when running on a cheat protected server or a client that is connected to it (not used in singleplayer).
|
||||
virtual void SetForceNonDevMode(bool bValue) = 0;
|
||||
@@ -934,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;
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
@@ -991,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.
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
@@ -1019,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:
|
||||
@@ -1045,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.
|
||||
@@ -1058,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;
|
||||
@@ -1150,24 +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;
|
||||
|
||||
virtual const IImageHandler* GetImageHandler() const = 0;
|
||||
|
||||
// Summary:
|
||||
// Gets the root window message handler function
|
||||
// The returned pointer is platform-specific:
|
||||
@@ -1771,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,101 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ITexture.h>
|
||||
|
||||
namespace AZ
|
||||
{
|
||||
// General purpose video 'rendering' solution that abstracts video data into textures
|
||||
// and data to update those textures with.
|
||||
namespace VideoRenderer
|
||||
{
|
||||
enum Constants
|
||||
{
|
||||
MaxInputTextureCount = 4,
|
||||
};
|
||||
|
||||
struct VideoTextureDesc
|
||||
{
|
||||
CryFixedStringT<64> m_name; // fixed string to avoid dll string copying issues
|
||||
uint32 m_width{ 4 };
|
||||
uint32 m_height{ 4 };
|
||||
ETEX_Format m_format{ eTF_Unknown };
|
||||
uint32 m_used{ 0 };
|
||||
};
|
||||
|
||||
// Full description of video texture resources for the renderer to create.
|
||||
struct VideoTexturesDesc
|
||||
{
|
||||
VideoTextureDesc m_outputTextureDesc;
|
||||
VideoTextureDesc m_inputTextureDescs[MaxInputTextureCount];
|
||||
};
|
||||
|
||||
// Full set of textures created from the VideoTexturesDesc provided to the renderer.
|
||||
struct VideoTextures
|
||||
{
|
||||
uint32 m_outputTextureId{ 0 };
|
||||
uint32 m_inputTextureIds[MaxInputTextureCount]{ 0 };
|
||||
};
|
||||
|
||||
struct VideoUpdateData
|
||||
{
|
||||
struct VideoTextureUpdateData
|
||||
{
|
||||
// Data to update the texture with, can be null.
|
||||
const void* m_data{ nullptr };
|
||||
|
||||
// Format of above data, required for format conversions if needed.
|
||||
ETEX_Format m_dataFormat{ eTF_Unknown };
|
||||
}
|
||||
m_inputTextureData[MaxInputTextureCount];
|
||||
};
|
||||
|
||||
// Set of data to update and render a frame of video textures.
|
||||
// Everything should be passed through by value except for the update data, which should be double buffered at the source.
|
||||
struct DrawArguments
|
||||
{
|
||||
// Set of textures to draw with.
|
||||
VideoTextures m_textures;
|
||||
|
||||
// Set of data to update the above textures with if set.
|
||||
VideoUpdateData m_updateData;
|
||||
|
||||
// Flag to indicate that we want to draw to the backbuffer.
|
||||
uint32 m_drawingToBackbuffer{ 0 };
|
||||
|
||||
// Payload information for reference. Useful for debugging.
|
||||
uint32 m_frameReference{ 0 };
|
||||
|
||||
// Scale applied to each texture.
|
||||
Vec4 m_textureScales[MaxInputTextureCount]{};
|
||||
|
||||
// Value added to final composited texture.
|
||||
Vec4 m_colorAdjustment{ ZERO };
|
||||
};
|
||||
|
||||
// Video Rendering interface to provide callbacks from the Render Thread
|
||||
struct IVideoRenderer
|
||||
{
|
||||
// Called from the Render Thread to request the description of the video textures.
|
||||
virtual bool GetVideoTexturesDesc(AZ::VideoRenderer::VideoTexturesDesc& videoTexturesDesc) const = 0;
|
||||
// Called from the Render Thread to get the set of video textures that were previously created. Used at cleanup time.
|
||||
virtual bool GetVideoTextures(AZ::VideoRenderer::VideoTextures& videoTextures) const = 0;
|
||||
|
||||
// Called from the Render Thread to provide the video textures it created from the VideoTexturesDesc.
|
||||
virtual bool NotifyTexturesCreated(const AZ::VideoRenderer::VideoTextures& videoTextures) = 0;
|
||||
// CAlled from the Render Thread to notify the video manager that its textures were destroyed.
|
||||
virtual bool NotifyTexturesDestroyed() = 0;
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -1,86 +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 <CryCommon/ImageExtensionHelper.h>
|
||||
|
||||
namespace CImageExtensionHelper
|
||||
{
|
||||
ColorF GetAverageColor(uint8 const* pMem)
|
||||
{
|
||||
pMem = _findChunkStart(pMem, FOURCC_AvgC);
|
||||
|
||||
if (pMem)
|
||||
{
|
||||
ColorF ret = ColorF(SwapEndianValue(*(uint32*)pMem));
|
||||
//flip red and blue
|
||||
const float cRed = ret.r;
|
||||
ret.r = ret.b;
|
||||
ret.b = cRed;
|
||||
return ret;
|
||||
}
|
||||
|
||||
return Col_White; // chunk does not exist
|
||||
}
|
||||
|
||||
bool IsRangeless(ETEX_Format eTF)
|
||||
{
|
||||
return (eTF == eTF_BC6UH ||
|
||||
eTF == eTF_BC6SH ||
|
||||
eTF == eTF_R9G9B9E5 ||
|
||||
eTF == eTF_R16G16B16A16F ||
|
||||
eTF == eTF_R32G32B32A32F ||
|
||||
eTF == eTF_R16F ||
|
||||
eTF == eTF_R32F ||
|
||||
eTF == eTF_R16G16F ||
|
||||
eTF == eTF_R11G11B10F);
|
||||
}
|
||||
|
||||
bool IsQuantized(ETEX_Format eTF)
|
||||
{
|
||||
return (eTF == eTF_B4G4R4A4 ||
|
||||
eTF == eTF_B5G6R5 ||
|
||||
eTF == eTF_B5G5R5 ||
|
||||
eTF == eTF_BC1 ||
|
||||
eTF == eTF_BC2 ||
|
||||
eTF == eTF_BC3 ||
|
||||
eTF == eTF_BC4U ||
|
||||
eTF == eTF_BC4S ||
|
||||
eTF == eTF_BC5U ||
|
||||
eTF == eTF_BC5S ||
|
||||
eTF == eTF_BC6UH ||
|
||||
eTF == eTF_BC6SH ||
|
||||
eTF == eTF_BC7 ||
|
||||
eTF == eTF_R9G9B9E5 ||
|
||||
eTF == eTF_ETC2 ||
|
||||
eTF == eTF_EAC_R11 ||
|
||||
eTF == eTF_ETC2A ||
|
||||
eTF == eTF_EAC_RG11 ||
|
||||
eTF == eTF_PVRTC2 ||
|
||||
eTF == eTF_PVRTC4 ||
|
||||
eTF == eTF_ASTC_4x4 ||
|
||||
eTF == eTF_ASTC_5x4 ||
|
||||
eTF == eTF_ASTC_5x5 ||
|
||||
eTF == eTF_ASTC_6x5 ||
|
||||
eTF == eTF_ASTC_6x6 ||
|
||||
eTF == eTF_ASTC_8x5 ||
|
||||
eTF == eTF_ASTC_8x6 ||
|
||||
eTF == eTF_ASTC_8x8 ||
|
||||
eTF == eTF_ASTC_10x5 ||
|
||||
eTF == eTF_ASTC_10x6 ||
|
||||
eTF == eTF_ASTC_10x8 ||
|
||||
eTF == eTF_ASTC_10x10 ||
|
||||
eTF == eTF_ASTC_12x10 ||
|
||||
eTF == eTF_ASTC_12x12
|
||||
);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,69 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
#ifndef CRYINCLUDE_CRYCOMMON_IMAGEEXTENSIONHELPER_INFO_H
|
||||
#define CRYINCLUDE_CRYCOMMON_IMAGEEXTENSIONHELPER_INFO_H
|
||||
#pragma once
|
||||
|
||||
#include "CryString.h"
|
||||
#include "TypeInfo_decl.h"
|
||||
#include "ImageExtensionHelper.h"
|
||||
|
||||
// Crytek specific image extensions
|
||||
//
|
||||
// usually added to the end of DDS files
|
||||
|
||||
|
||||
STRUCT_INFO_BEGIN(CImageExtensionHelper::DDS_PIXELFORMAT)
|
||||
STRUCT_VAR_INFO(dwSize, TYPE_INFO(DWORD))
|
||||
STRUCT_VAR_INFO(dwFlags, TYPE_INFO(DWORD))
|
||||
STRUCT_VAR_INFO(dwFourCC, TYPE_INFO(DWORD))
|
||||
STRUCT_VAR_INFO(dwRGBBitCount, TYPE_INFO(DWORD))
|
||||
STRUCT_VAR_INFO(dwRBitMask, TYPE_INFO(DWORD))
|
||||
STRUCT_VAR_INFO(dwGBitMask, TYPE_INFO(DWORD))
|
||||
STRUCT_VAR_INFO(dwBBitMask, TYPE_INFO(DWORD))
|
||||
STRUCT_VAR_INFO(dwABitMask, TYPE_INFO(DWORD))
|
||||
STRUCT_INFO_END(CImageExtensionHelper::DDS_PIXELFORMAT)
|
||||
|
||||
STRUCT_INFO_BEGIN(CImageExtensionHelper::DDS_HEADER_DXT10)
|
||||
STRUCT_VAR_INFO(dxgiFormat, TYPE_INFO(DWORD))
|
||||
STRUCT_VAR_INFO(resourceDimension, TYPE_INFO(DWORD))
|
||||
STRUCT_VAR_INFO(miscFlag, TYPE_INFO(DWORD))
|
||||
STRUCT_VAR_INFO(arraySize, TYPE_INFO(DWORD))
|
||||
STRUCT_VAR_INFO(reserved, TYPE_INFO(DWORD))
|
||||
STRUCT_INFO_END(CImageExtensionHelper::DDS_HEADER_DXT10)
|
||||
|
||||
STRUCT_INFO_BEGIN(CImageExtensionHelper::DDS_HEADER)
|
||||
STRUCT_VAR_INFO(dwSize, TYPE_INFO(DWORD))
|
||||
STRUCT_VAR_INFO(dwHeaderFlags, TYPE_INFO(DWORD))
|
||||
STRUCT_VAR_INFO(dwHeight, TYPE_INFO(DWORD))
|
||||
STRUCT_VAR_INFO(dwWidth, TYPE_INFO(DWORD))
|
||||
STRUCT_VAR_INFO(dwPitchOrLinearSize, TYPE_INFO(DWORD))
|
||||
STRUCT_VAR_INFO(dwDepth, TYPE_INFO(DWORD))
|
||||
STRUCT_VAR_INFO(dwMipMapCount, TYPE_INFO(DWORD))
|
||||
STRUCT_VAR_INFO(dwAlphaBitDepth, TYPE_INFO(DWORD))
|
||||
STRUCT_VAR_INFO(dwReserved1, TYPE_ARRAY(10, TYPE_INFO(DWORD)))
|
||||
STRUCT_VAR_INFO(ddspf, TYPE_INFO(CImageExtensionHelper::DDS_PIXELFORMAT))
|
||||
STRUCT_VAR_INFO(dwSurfaceFlags, TYPE_INFO(DWORD))
|
||||
STRUCT_VAR_INFO(dwCubemapFlags, TYPE_INFO(DWORD))
|
||||
STRUCT_VAR_INFO(bNumPersistentMips, TYPE_INFO(BYTE))
|
||||
STRUCT_VAR_INFO(bReserved2, TYPE_ARRAY(7, TYPE_INFO(BYTE)))
|
||||
STRUCT_VAR_INFO(dwTextureStage, TYPE_INFO(DWORD))
|
||||
STRUCT_INFO_END(CImageExtensionHelper::DDS_HEADER)
|
||||
|
||||
STRUCT_INFO_BEGIN(CImageExtensionHelper::DDS_FILE_DESC)
|
||||
STRUCT_VAR_INFO(dwMagic, TYPE_INFO(DWORD))
|
||||
STRUCT_VAR_INFO(header, TYPE_INFO(CImageExtensionHelper::DDS_HEADER))
|
||||
STRUCT_INFO_END(CImageExtensionHelper::DDS_FILE_DESC)
|
||||
|
||||
#endif // CRYINCLUDE_CRYCOMMON_IMAGEEXTENSIONHELPER_INFO_H
|
||||
@@ -1,310 +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 : Helper to enable inplace construction and destruction of objects
|
||||
#ifndef CRYINCLUDE_CRYCOMMON_INPLACEFACTORY_H
|
||||
#define CRYINCLUDE_CRYCOMMON_INPLACEFACTORY_H
|
||||
#pragma once
|
||||
|
||||
|
||||
// Inspired by the boost inplace/typed_inplace factory, written by
|
||||
// Fernando Luis Cacciola Carballal and Tobias Schwinger
|
||||
//
|
||||
// See
|
||||
// http://www.boost.org/doc/libs/1_42_0/libs/utility/in_place_factories.html
|
||||
// for a detailed description
|
||||
//
|
||||
|
||||
class CInplaceFactory0
|
||||
{
|
||||
public:
|
||||
|
||||
explicit CInplaceFactory0()
|
||||
{}
|
||||
|
||||
template<class T>
|
||||
void* apply(void* address) const
|
||||
{
|
||||
return new(address) T();
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void* apply(void* address, std::size_t n) const
|
||||
{
|
||||
for (char* next = address = this->template apply<T>(address); !!--n; )
|
||||
{
|
||||
this->template apply<T>(next = next + sizeof(T));
|
||||
}
|
||||
return address;
|
||||
}
|
||||
};
|
||||
|
||||
template < typename Arg0 >
|
||||
class CInplaceFactory1
|
||||
{
|
||||
Arg0& m_Arg0;
|
||||
|
||||
public:
|
||||
|
||||
explicit CInplaceFactory1(Arg0& arg)
|
||||
: m_Arg0(arg)
|
||||
{}
|
||||
|
||||
template<class T>
|
||||
void* apply(void* address) const
|
||||
{
|
||||
return new(address) T(m_Arg0);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void* apply(void* address, std::size_t n) const
|
||||
{
|
||||
for (char* next = address = this->template apply<T>(address); !!--n; )
|
||||
{
|
||||
this->template apply<T>(next = next + sizeof(T));
|
||||
}
|
||||
return address;
|
||||
}
|
||||
};
|
||||
|
||||
template
|
||||
<
|
||||
typename Arg0,
|
||||
typename Arg1
|
||||
>
|
||||
class CInplaceFactory2
|
||||
{
|
||||
Arg0& m_Arg0;
|
||||
Arg1& m_Arg1;
|
||||
|
||||
public:
|
||||
|
||||
explicit CInplaceFactory2(Arg0& arg0, Arg1& arg1)
|
||||
: m_Arg0(arg0)
|
||||
, m_Arg1(arg1)
|
||||
{}
|
||||
|
||||
template<class T>
|
||||
void* apply(void* address) const
|
||||
{
|
||||
return new(address) T(
|
||||
m_Arg0,
|
||||
m_Arg1);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void* apply(void* address, std::size_t n) const
|
||||
{
|
||||
for (char* next = address = this->template apply<T>(address); !!--n; )
|
||||
{
|
||||
this->template apply<T>(next = next + sizeof(T));
|
||||
}
|
||||
return address;
|
||||
}
|
||||
};
|
||||
|
||||
template
|
||||
<
|
||||
typename Arg0,
|
||||
typename Arg1,
|
||||
typename Arg2
|
||||
>
|
||||
class CInplaceFactory3
|
||||
{
|
||||
Arg0& m_Arg0;
|
||||
Arg1& m_Arg1;
|
||||
Arg2& m_Arg2;
|
||||
|
||||
public:
|
||||
|
||||
explicit CInplaceFactory3(Arg0& arg0, Arg1& arg1, Arg2& arg2)
|
||||
: m_Arg0(arg0)
|
||||
, m_Arg1(arg1)
|
||||
, m_Arg2(arg2)
|
||||
{}
|
||||
|
||||
template<class T>
|
||||
void* apply(void* address) const
|
||||
{
|
||||
return new(address) T(
|
||||
m_Arg0,
|
||||
m_Arg1,
|
||||
m_Arg2);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void* apply(void* address, std::size_t n) const
|
||||
{
|
||||
for (char* next = address = this->template apply<T>(address); !!--n; )
|
||||
{
|
||||
this->template apply<T>(next = next + sizeof(T));
|
||||
}
|
||||
return address;
|
||||
}
|
||||
};
|
||||
|
||||
template
|
||||
<
|
||||
typename Arg0,
|
||||
typename Arg1,
|
||||
typename Arg2,
|
||||
typename Arg3
|
||||
>
|
||||
class CInplaceFactory4
|
||||
{
|
||||
Arg0& m_Arg0;
|
||||
Arg1& m_Arg1;
|
||||
Arg2& m_Arg2;
|
||||
Arg3& m_Arg3;
|
||||
|
||||
public:
|
||||
|
||||
explicit CInplaceFactory4(Arg0& arg0, Arg1& arg1, Arg2& arg2, Arg3& arg3)
|
||||
: m_Arg0(arg0)
|
||||
, m_Arg1(arg1)
|
||||
, m_Arg2(arg2)
|
||||
, m_Arg3(arg3)
|
||||
{}
|
||||
|
||||
template<class T>
|
||||
void* apply(void* address) const
|
||||
{
|
||||
return new(address) T(
|
||||
m_Arg0,
|
||||
m_Arg1,
|
||||
m_Arg2,
|
||||
m_Arg3);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void* apply(void* address, std::size_t n) const
|
||||
{
|
||||
for (char* next = address = this->template apply<T>(address); !!--n; )
|
||||
{
|
||||
this->template apply<T>(next = next + sizeof(T));
|
||||
}
|
||||
return address;
|
||||
}
|
||||
};
|
||||
|
||||
template
|
||||
<
|
||||
typename Arg0,
|
||||
typename Arg1,
|
||||
typename Arg2,
|
||||
typename Arg3,
|
||||
typename Arg4
|
||||
>
|
||||
class CInplaceFactory5
|
||||
{
|
||||
Arg0& m_Arg0;
|
||||
Arg1& m_Arg1;
|
||||
Arg2& m_Arg2;
|
||||
Arg3& m_Arg3;
|
||||
Arg4& m_Arg4;
|
||||
|
||||
public:
|
||||
|
||||
explicit CInplaceFactory5(Arg0& arg0, Arg1& arg1, Arg2& arg2, Arg3& arg3, Arg4& arg4)
|
||||
: m_Arg0(arg0)
|
||||
, m_Arg1(arg1)
|
||||
, m_Arg2(arg2)
|
||||
, m_Arg3(arg3)
|
||||
, m_Arg4(arg4)
|
||||
{}
|
||||
|
||||
template<class T>
|
||||
void* apply(void* address) const
|
||||
{
|
||||
return new(address) T(
|
||||
m_Arg0,
|
||||
m_Arg1,
|
||||
m_Arg2,
|
||||
m_Arg3,
|
||||
m_Arg4);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void* apply(void* address, std::size_t n) const
|
||||
{
|
||||
for (char* next = address = this->template apply<T>(address); !!--n; )
|
||||
{
|
||||
this->template apply<T>(next = next + sizeof(T));
|
||||
}
|
||||
return address;
|
||||
}
|
||||
};
|
||||
|
||||
inline CInplaceFactory0 InplaceFactory()
|
||||
{
|
||||
return CInplaceFactory0();
|
||||
}
|
||||
|
||||
template < typename Arg0 >
|
||||
inline CInplaceFactory1<Arg0> InplaceFactory(Arg0& arg0)
|
||||
{
|
||||
return CInplaceFactory1<Arg0>(arg0);
|
||||
}
|
||||
|
||||
template
|
||||
<
|
||||
typename Arg0,
|
||||
typename Arg1
|
||||
|
||||
>
|
||||
inline CInplaceFactory2<Arg0, Arg1> InplaceFactory(Arg0& arg0, Arg1& arg1)
|
||||
{
|
||||
return CInplaceFactory2<Arg0, Arg1>(arg0, arg1);
|
||||
}
|
||||
|
||||
template
|
||||
<
|
||||
typename Arg0,
|
||||
typename Arg1,
|
||||
typename Arg2
|
||||
>
|
||||
inline CInplaceFactory3<Arg0, Arg1, Arg2> InplaceFactory(Arg0& arg0, Arg1& arg1, Arg2& arg2)
|
||||
{
|
||||
return CInplaceFactory3<Arg0, Arg1, Arg2> (arg0, arg1, arg2);
|
||||
}
|
||||
|
||||
|
||||
template
|
||||
<
|
||||
typename Arg0,
|
||||
typename Arg1,
|
||||
typename Arg2,
|
||||
typename Arg3
|
||||
>
|
||||
inline CInplaceFactory4<Arg0, Arg1, Arg2, Arg3> InplaceFactory(
|
||||
Arg0& arg0, Arg1& arg1, Arg2& arg2, Arg3& arg3)
|
||||
{
|
||||
return CInplaceFactory4<Arg0, Arg1, Arg2, Arg3>(arg0, arg1, arg2, arg3);
|
||||
}
|
||||
|
||||
|
||||
template
|
||||
<
|
||||
typename Arg0,
|
||||
typename Arg1,
|
||||
typename Arg2,
|
||||
typename Arg3,
|
||||
typename Arg4
|
||||
>
|
||||
inline CInplaceFactory5<Arg0, Arg1, Arg2, Arg3, Arg4> InplaceFactory(
|
||||
Arg0& arg0, Arg1& arg1, Arg2& arg2, Arg3& arg3, Arg4& arg4)
|
||||
{
|
||||
return CInplaceFactory5<Arg0, Arg1, Arg2, Arg3, Arg4>(arg0, arg1, arg2, arg3, arg4);
|
||||
}
|
||||
|
||||
#endif // CRYINCLUDE_CRYCOMMON_INPLACEFACTORY_H
|
||||
@@ -1,134 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
#ifndef CRYINCLUDE_CRYCOMMON_MATERIALUTILS_H
|
||||
#define CRYINCLUDE_CRYCOMMON_MATERIALUTILS_H
|
||||
|
||||
#include <AzCore/base.h>
|
||||
#include <AzCore/IO/SystemFile.h> // for max path len
|
||||
#include <AzCore/std/string/string.h>
|
||||
#include <AzCore/Utils/Utils.h>
|
||||
#include <AzFramework/StringFunc/StringFunc.h>
|
||||
|
||||
#include <ISystem.h>
|
||||
|
||||
namespace MaterialUtils
|
||||
{
|
||||
//! UnifyMaterialName - given a non-unified material name, remove the extension, unify the slashes
|
||||
//! and fix up any legacy naming issues so that the material name can be used in a hash map
|
||||
//! and will work each lookup.
|
||||
inline void UnifyMaterialName(char* inputOutputBuffer)
|
||||
{
|
||||
if (!inputOutputBuffer)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// convert slashes and remove extensions:
|
||||
size_t inputLength = strlen(inputOutputBuffer);
|
||||
if (inputLength == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// this must be done first, so that the extension cutting function below does not mistakenly destroy this when it finds the .
|
||||
if ((azstrnicmp(inputOutputBuffer, "./", 2) == 0) || (azstrnicmp(inputOutputBuffer, ".\\", 2) == 0))
|
||||
{
|
||||
memmove(inputOutputBuffer, inputOutputBuffer + 2, inputLength - 2);
|
||||
inputOutputBuffer[inputLength - 2] = 0;
|
||||
inputLength -= 2;
|
||||
}
|
||||
|
||||
for (size_t pos = 0; pos < inputLength; ++pos)
|
||||
{
|
||||
if (inputOutputBuffer[pos] == '\\')
|
||||
{
|
||||
inputOutputBuffer[pos] = '/'; // unify slashes
|
||||
}
|
||||
else
|
||||
{
|
||||
inputOutputBuffer[pos] = tolower(inputOutputBuffer[pos]);
|
||||
}
|
||||
}
|
||||
AZStd::string tempString(inputOutputBuffer);
|
||||
AzFramework::StringFunc::Path::StripExtension(tempString);
|
||||
|
||||
AZ_Assert(tempString.length() <= inputLength, "Extension stripped string has to be smaller than/same size as original string!");
|
||||
// real size of inputOutputBuffer is inputLength + 1 with Null character
|
||||
azstrcpy(inputOutputBuffer, inputLength + 1, tempString.c_str());
|
||||
#if defined(SUPPORT_LEGACY_MATERIAL_NAMES)
|
||||
|
||||
// LEGACY support Some files may start with ./ in front of them. This is not required anymore.
|
||||
static const char* removals[2] = {
|
||||
"engine/",
|
||||
nullptr // reserved for game name
|
||||
};
|
||||
static size_t removalSize = sizeof(removals) / sizeof(removals[0]);
|
||||
|
||||
// LEGACY support. Some files may start with gamename in front of them. This is not required anymore.
|
||||
static char cachedGameName[AZ_MAX_PATH_LEN] = { 0 };
|
||||
if (!removals[removalSize - 1])
|
||||
{
|
||||
auto projectName = AZ::Utils::GetProjectName();
|
||||
if (!projectName.empty())
|
||||
{
|
||||
azstrcpy(cachedGameName, AZ_MAX_PATH_LEN, projectName.c_str());
|
||||
azstrcat(cachedGameName, AZ_MAX_PATH_LEN, "/");
|
||||
}
|
||||
|
||||
if (cachedGameName[0] == 0)
|
||||
{
|
||||
// at least substitute something so that unit tests can make this assumption:
|
||||
azstrcpy(cachedGameName, AZ_MAX_PATH_LEN, "AutomatedTesting/");
|
||||
}
|
||||
|
||||
removals[removalSize - 1] = cachedGameName;
|
||||
}
|
||||
|
||||
for (size_t pos = 0; pos < removalSize; ++pos)
|
||||
{
|
||||
if (removals[pos])
|
||||
{
|
||||
size_t removalLength = strlen(removals[pos]);
|
||||
if (removalLength >= inputLength)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (azstrnicmp(inputOutputBuffer, removals[pos], removalLength) == 0)
|
||||
{
|
||||
memmove(inputOutputBuffer, inputOutputBuffer + removalLength, inputLength - removalLength);
|
||||
inputOutputBuffer[inputLength - removalLength] = 0;
|
||||
inputLength -= removalLength;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// legacy: Files were saved into a mtl with many leading forward or back slashes, we eat them all here. We want it to start with a rel path.
|
||||
const char* actualFileName = inputOutputBuffer;
|
||||
size_t finalLength = inputLength;
|
||||
while ((actualFileName[0]) && ((actualFileName[0] == '\\') || (actualFileName[0] == '/')))
|
||||
{
|
||||
++actualFileName;
|
||||
--finalLength;
|
||||
}
|
||||
if (finalLength != inputLength)
|
||||
{
|
||||
memmove(inputOutputBuffer, actualFileName, finalLength);
|
||||
inputOutputBuffer[finalLength] = 0;
|
||||
inputLength = finalLength;
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#endif // CRYINCLUDE_CRYCOMMON_MATERIALUTILS_H
|
||||
@@ -12,8 +12,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <IRenderer.h>
|
||||
#include <IVideoRenderer.h>
|
||||
#include <IImage.h>
|
||||
#include <gmock/gmock.h>
|
||||
|
||||
struct SRendItemSorter {};
|
||||
@@ -294,8 +292,6 @@ public:
|
||||
bool(const char* szFileName));
|
||||
MOCK_METHOD1(EF_ReloadFile_Request,
|
||||
bool(const char* szFileName));
|
||||
MOCK_METHOD2(EF_LoadImage,
|
||||
_smart_ptr<IImageFile>(const char* szFileName, uint32 nFlags));
|
||||
MOCK_METHOD3(EF_GetRemapedShaderMaskGen,
|
||||
uint64(const char*, uint64, bool));
|
||||
MOCK_METHOD3(EF_GetShaderGlobalMaskGenFromString,
|
||||
@@ -330,8 +326,6 @@ public:
|
||||
ITexture * (const char* nameTex));
|
||||
MOCK_METHOD1(EF_LoadLightmap,
|
||||
int(const char* name));
|
||||
MOCK_METHOD3(EF_RenderEnvironmentCubeHDR,
|
||||
bool(int size, Vec3 & Pos, TArray<unsigned short>&vecData));
|
||||
MOCK_METHOD1(EF_StartEf,
|
||||
void(const SRenderingPassInfo& passInfo));
|
||||
MOCK_METHOD3(EF_GetObjData,
|
||||
@@ -360,8 +354,6 @@ public:
|
||||
uint32(eDeferredLightType));
|
||||
MOCK_METHOD0(EF_ClearDeferredLightsList,
|
||||
void());
|
||||
MOCK_METHOD2(EF_GetDeferredLights,
|
||||
TArray<SRenderLight>*(const SRenderingPassInfo&, const eDeferredLightType));
|
||||
MOCK_METHOD1(EF_AddDeferredClipVolume,
|
||||
uint8(const IClipVolume * pClipVolume));
|
||||
MOCK_METHOD2(EF_SetDeferredClipVolumeBlendData,
|
||||
@@ -537,8 +529,6 @@ public:
|
||||
void(unsigned int TextureId));
|
||||
MOCK_METHOD1(DeleteFont,
|
||||
void(IFFont * font));
|
||||
MOCK_METHOD2(BakeMesh,
|
||||
bool(const SMeshBakingInputParams * pInputParams, SMeshBakingOutput * pReturnValues));
|
||||
MOCK_METHOD3(CaptureFrameBufferFast,
|
||||
bool(unsigned char* pDstRGBA8, int destinationWidth, int destinationHeight));
|
||||
MOCK_METHOD3(CopyFrameBufferFast,
|
||||
@@ -861,13 +851,6 @@ public:
|
||||
MOCK_METHOD1(AddProfilerLabel,
|
||||
void(const char*));
|
||||
|
||||
MOCK_METHOD1(InitializeVideoRenderer,
|
||||
void(AZ::VideoRenderer::IVideoRenderer* pVideoRenderer));
|
||||
MOCK_METHOD1(CleanupVideoRenderer,
|
||||
void(AZ::VideoRenderer::IVideoRenderer* pVideoRenderer));
|
||||
MOCK_METHOD2(DrawVideoRenderer,
|
||||
void(AZ::VideoRenderer::IVideoRenderer* pVideoRenderer, const AZ::VideoRenderer::DrawArguments& drawArguments));
|
||||
|
||||
MOCK_METHOD5(EF_QueryImpl,
|
||||
void(ERenderQueryTypes eQuery, void* pInOut0, uint32 nInOutSize0, void* pInOut1, uint32 nInOutSize1));
|
||||
};
|
||||
|
||||
@@ -37,14 +37,8 @@ public:
|
||||
bool());
|
||||
MOCK_METHOD0(RenderStatistics,
|
||||
void());
|
||||
MOCK_METHOD0(GetUsedMemory,
|
||||
uint32());
|
||||
MOCK_METHOD0(GetUserName,
|
||||
const char*());
|
||||
MOCK_METHOD0(GetCPUFlags,
|
||||
int());
|
||||
MOCK_METHOD0(GetLogicalCPUCount,
|
||||
int());
|
||||
MOCK_METHOD0(Quit,
|
||||
void());
|
||||
MOCK_METHOD1(Relaunch,
|
||||
@@ -57,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 {}
|
||||
@@ -72,24 +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(GetStreamEngine,
|
||||
IStreamEngine * ());
|
||||
MOCK_METHOD0(GetICmdLine,
|
||||
ICmdLine * ());
|
||||
MOCK_METHOD0(GetILog,
|
||||
@@ -98,8 +78,6 @@ public:
|
||||
AZ::IO::IArchive * ());
|
||||
MOCK_METHOD0(GetICryFont,
|
||||
ICryFont * ());
|
||||
MOCK_METHOD0(GetIMemoryManager,
|
||||
IMemoryManager * ());
|
||||
MOCK_METHOD0(GetIMovieSystem,
|
||||
IMovieSystem * ());
|
||||
MOCK_METHOD0(GetIAudioSystem,
|
||||
@@ -108,20 +86,12 @@ public:
|
||||
::IConsole * ());
|
||||
MOCK_METHOD0(GetIRemoteConsole,
|
||||
IRemoteConsole * ());
|
||||
MOCK_METHOD0(GetIResourceManager,
|
||||
IResourceManager * ());
|
||||
MOCK_METHOD0(GetIProfilingSystem,
|
||||
IProfilingSystem * ());
|
||||
MOCK_METHOD0(GetISystemEventDispatcher,
|
||||
ISystemEventDispatcher * ());
|
||||
MOCK_METHOD0(GetITimer,
|
||||
ITimer * ());
|
||||
MOCK_METHOD2(DebugStats,
|
||||
void(bool checkpoint, bool leaks));
|
||||
MOCK_METHOD0(DumpWinHeaps,
|
||||
void());
|
||||
MOCK_METHOD1(DumpMMStats,
|
||||
int(bool log));
|
||||
MOCK_METHOD1(SetForceNonDevMode,
|
||||
void(bool bValue));
|
||||
MOCK_CONST_METHOD0(GetForceNonDevMode,
|
||||
@@ -130,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,
|
||||
@@ -161,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,
|
||||
@@ -173,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,
|
||||
@@ -227,18 +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_CONST_METHOD0(GetImageHandler,
|
||||
const IImageHandler * ());
|
||||
MOCK_METHOD0(GetRootWindowMessageHandler,
|
||||
void*());
|
||||
MOCK_METHOD1(RegisterWindowMessageHandler,
|
||||
|
||||
@@ -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.
|
||||
|
||||
#ifndef CRYINCLUDE_CRYCOMMON_NAME_TYPEINFO_H
|
||||
#define CRYINCLUDE_CRYCOMMON_NAME_TYPEINFO_H
|
||||
#pragma once
|
||||
|
||||
#include "CryName.h"
|
||||
|
||||
// CCryName TypeInfo
|
||||
|
||||
TYPE_INFO_BASIC(CCryName)
|
||||
|
||||
string ToString(CCryName const& val)
|
||||
{
|
||||
return string(val.c_str());
|
||||
}
|
||||
bool FromString(CCryName& val, const char* s)
|
||||
{
|
||||
val = s;
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif // CRYINCLUDE_CRYCOMMON_NAME_TYPEINFO_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.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
#include <AzCore/Math/Color.h>
|
||||
#include <AzCore/Math/MathUtils.h>
|
||||
|
||||
// Water level unknown.
|
||||
#define WATER_LEVEL_UNKNOWN -1000000.f
|
||||
#define BOTTOM_LEVEL_UNKNOWN -1000000.f
|
||||
|
||||
namespace AZ
|
||||
{
|
||||
/**
|
||||
* Numeric constants that the editors should use for the ocean properties
|
||||
*/
|
||||
namespace OceanConstants
|
||||
{
|
||||
// Ocean Height consts are maintained for backwards compatibility
|
||||
// @TODO: Remove height / depth related consts when feature toggle is removed.
|
||||
static const float s_HeightMin = -AZ::Constants::MaxFloatBeforePrecisionLoss;
|
||||
static const float s_HeightMax = AZ::Constants::MaxFloatBeforePrecisionLoss;
|
||||
static const float s_HeightUnknown = WATER_LEVEL_UNKNOWN;
|
||||
static const float s_BottomUnknown = BOTTOM_LEVEL_UNKNOWN;
|
||||
static const float s_DefaultHeight = 16.0f;
|
||||
|
||||
static const float s_CausticsDistanceAttenMin = 0.0f;
|
||||
static const float s_CausticsDistanceAttenDefault = 10.0f;
|
||||
static const float s_CausticsDistanceAttenMax = 100.0f;
|
||||
static const float s_CausticsDepthMin = 0.0f;
|
||||
static const float s_CausticsDepthDefault = 8.0f;
|
||||
static const float s_CausticsDepthMax = 100.0f;
|
||||
static const float s_CausticsIntensityMin = 0.0f;
|
||||
static const float s_CausticsIntensityDefault = 1.0f;
|
||||
static const float s_CausticsIntensityMax = 10.0f;
|
||||
static const float s_CausticsTilingMin = 0.10f;
|
||||
static const float s_CausticsTilingDefault = 2.0f;
|
||||
static const float s_CausticsTilingMax = 10.0f;
|
||||
|
||||
static const float s_animationWavesAmountMin = 0.2f;
|
||||
static const float s_animationWavesAmountMax = 5.0f;
|
||||
static const float s_animationWavesAmountDefault = 0.75f;
|
||||
static const float s_animationWavesSizeMin = 0.0f;
|
||||
static const float s_animationWavesSizeMax = 3.0f;
|
||||
static const float s_animationWavesSizeDefault = 1.25f;
|
||||
static const float s_animationWavesSpeedMin = 0.0f;
|
||||
static const float s_animationWavesSpeedMax = 5.0f;
|
||||
static const float s_animationWavesSpeedDefault = 1.0f;
|
||||
static const float s_animationWindDirectionMin = 0.0f;
|
||||
static const float s_animationWindDirectionMax = 6.2832f;
|
||||
static const float s_animationWindDirectionDefault = 1;
|
||||
static const float s_animationWindSpeedMin = 0.0f;
|
||||
static const float s_animationWindSpeedMax = 1000.0f;
|
||||
static const float s_animationWindSpeedDefault = 40.0f;
|
||||
|
||||
static const AZ::Color s_oceanFogColorDefault((AZ::u8)5, (AZ::u8)36, (AZ::u8)32, (AZ::u8)255);
|
||||
static const AZ::Color s_oceanNearFogColorDefault((AZ::u8)1, (AZ::u8)7, (AZ::u8)5, (AZ::u8)255);
|
||||
static const float s_oceanFogColorMultiplierDefault = 0.15f;
|
||||
static const float s_oceanFogDensityDefault = 0.07f;
|
||||
static const float s_OceanFogColorMultiplierMin = 0.0f;
|
||||
static const float s_OceanFogColorMultiplierMax = 1.0f;
|
||||
static const float s_OceanFogDensityMin = 0.0f;
|
||||
static const float s_OceanFogDensityMax = 1.0f;
|
||||
|
||||
static const int s_waterTessellationAmountMin = 10;
|
||||
static const int s_waterTessellationAmountMax = 500;
|
||||
static const int s_waterTessellationDefault = 85;
|
||||
|
||||
static const bool s_UseOceanBottom = true;
|
||||
|
||||
static const bool s_GodRaysEnabled = true;
|
||||
static const float s_UnderwaterDistortion = 1.0f;
|
||||
|
||||
static const float s_oceanIsVeryFarAway = 1000000.f;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,363 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <AzFramework/Archive/IArchive.h>
|
||||
|
||||
//! Everybody should use fxopen instead of fopen so it opens on all platforms
|
||||
inline AZ::IO::HandleType fxopen(const char* file, const char* mode, bool bGameRelativePath = false)
|
||||
{
|
||||
if (gEnv && gEnv->pCryPak)
|
||||
{
|
||||
gEnv->pCryPak->CheckFileAccessDisabled(file, mode);
|
||||
}
|
||||
bool bWriteAccess = false;
|
||||
for (const char* s = mode; *s; s++)
|
||||
{
|
||||
if (*s == 'w' || *s == 'W' || *s == 'a' || *s == 'A' || *s == '+')
|
||||
{
|
||||
bWriteAccess = true;
|
||||
break;
|
||||
}
|
||||
;
|
||||
}
|
||||
|
||||
if (gEnv && gEnv->pCryPak)
|
||||
{
|
||||
int nAdjustFlags = 0;
|
||||
if (!bGameRelativePath)
|
||||
{
|
||||
nAdjustFlags |= AZ::IO::IArchive::FLAGS_PATH_REAL;
|
||||
}
|
||||
if (bWriteAccess)
|
||||
{
|
||||
nAdjustFlags |= AZ::IO::IArchive::FLAGS_FOR_WRITING;
|
||||
}
|
||||
char path[_MAX_PATH];
|
||||
const char* szAdjustedPath = gEnv->pCryPak->AdjustFileName(file, path, AZ_ARRAY_SIZE(path), nAdjustFlags);
|
||||
|
||||
#if !AZ_TRAIT_LEGACY_CRYPAK_UNIX_LIKE_FILE_SYSTEM
|
||||
if (bWriteAccess)
|
||||
{
|
||||
// Make sure folder is created.
|
||||
gEnv->pCryPak->MakeDir(szAdjustedPath);
|
||||
}
|
||||
#endif
|
||||
AZ::IO::HandleType fileHandle = AZ::IO::InvalidHandle;
|
||||
AZ::IO::FileIOBase::GetInstance()->Open(szAdjustedPath, AZ::IO::GetOpenModeFromStringMode(mode), fileHandle);
|
||||
return fileHandle;
|
||||
}
|
||||
else
|
||||
{
|
||||
return AZ::IO::InvalidHandle;
|
||||
}
|
||||
}
|
||||
|
||||
class CDebugAllowFileAccess
|
||||
{
|
||||
public:
|
||||
#if defined(_RELEASE)
|
||||
ILINE CDebugAllowFileAccess() { }
|
||||
ILINE void End() { }
|
||||
#else
|
||||
CDebugAllowFileAccess()
|
||||
{
|
||||
m_threadId = AZStd::this_thread::get_id();
|
||||
m_oldDisable = gEnv->pCryPak ? gEnv->pCryPak->DisableRuntimeFileAccess(false, m_threadId) : false;
|
||||
m_active = true;
|
||||
}
|
||||
~CDebugAllowFileAccess()
|
||||
{
|
||||
End();
|
||||
}
|
||||
void End()
|
||||
{
|
||||
if (m_active)
|
||||
{
|
||||
if (gEnv && gEnv->pCryPak)
|
||||
{
|
||||
gEnv->pCryPak->DisableRuntimeFileAccess(m_oldDisable, m_threadId);
|
||||
}
|
||||
m_active = false;
|
||||
}
|
||||
}
|
||||
protected:
|
||||
AZStd::thread_id m_threadId;
|
||||
bool m_oldDisable;
|
||||
bool m_active;
|
||||
#endif
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
class CInMemoryFileLoader
|
||||
{
|
||||
public:
|
||||
CInMemoryFileLoader(AZ::IO::IArchive* pCryPak)
|
||||
: m_pPak(pCryPak)
|
||||
, m_fileHandle(AZ::IO::InvalidHandle)
|
||||
, m_pBuffer(0)
|
||||
, m_pCursor(0)
|
||||
, m_nFileSize(0) {}
|
||||
~CInMemoryFileLoader()
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
bool IsFileExists() const
|
||||
{
|
||||
return m_fileHandle != AZ::IO::InvalidHandle;
|
||||
}
|
||||
|
||||
AZ::IO::HandleType GetFileHandle() const
|
||||
{
|
||||
return m_fileHandle;
|
||||
}
|
||||
|
||||
bool FOpen(const char* name, const char* mode, bool bImmediateCloseFile = false)
|
||||
{
|
||||
if (m_pPak)
|
||||
{
|
||||
assert(m_fileHandle == AZ::IO::InvalidHandle);
|
||||
m_fileHandle = m_pPak->FOpen(name, mode);
|
||||
if (m_fileHandle == AZ::IO::InvalidHandle)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
m_nFileSize = m_pPak->FGetSize(m_fileHandle);
|
||||
if (m_nFileSize == 0)
|
||||
{
|
||||
Close();
|
||||
return false;
|
||||
}
|
||||
|
||||
m_pCursor = m_pBuffer = (char*)m_pPak->PoolMalloc(m_nFileSize);
|
||||
|
||||
size_t nReaded = m_pPak->FReadRawAll(m_pBuffer, m_nFileSize, m_fileHandle);
|
||||
if (nReaded != m_nFileSize)
|
||||
{
|
||||
Close();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (bImmediateCloseFile)
|
||||
{
|
||||
m_pPak->FClose(m_fileHandle);
|
||||
m_fileHandle = AZ::IO::InvalidHandle;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void FClose()
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
size_t FReadRaw(void* data, size_t length, size_t elems)
|
||||
{
|
||||
ptrdiff_t dist = m_pCursor - m_pBuffer;
|
||||
|
||||
size_t count = length;
|
||||
if (dist + count * elems > m_nFileSize)
|
||||
{
|
||||
count = (m_nFileSize - dist) / elems;
|
||||
}
|
||||
|
||||
memmove(data, m_pCursor, count * elems);
|
||||
m_pCursor += count * elems;
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
size_t FRead(T* data, size_t elems, bool bSwapEndian = eLittleEndian)
|
||||
{
|
||||
ptrdiff_t dist = m_pCursor - m_pBuffer;
|
||||
|
||||
size_t count = elems;
|
||||
if (dist + count * sizeof(T) > m_nFileSize)
|
||||
{
|
||||
count = (m_nFileSize - dist) / sizeof(T);
|
||||
}
|
||||
|
||||
memmove(data, m_pCursor, count * sizeof(T));
|
||||
m_pCursor += count * sizeof(T);
|
||||
|
||||
SwapEndian(data, count, bSwapEndian);
|
||||
return count;
|
||||
}
|
||||
|
||||
size_t FTell()
|
||||
{
|
||||
ptrdiff_t dist = m_pCursor - m_pBuffer;
|
||||
return dist;
|
||||
}
|
||||
|
||||
int FSeek(int64_t origin, int command)
|
||||
{
|
||||
int retCode = -1;
|
||||
int64_t newPos;
|
||||
char* newPosBuf;
|
||||
switch (command)
|
||||
{
|
||||
case SEEK_SET:
|
||||
newPos = origin;
|
||||
if (newPos <= (int64_t)m_nFileSize)
|
||||
{
|
||||
m_pCursor = m_pBuffer + newPos;
|
||||
retCode = 0;
|
||||
}
|
||||
break;
|
||||
case SEEK_CUR:
|
||||
newPosBuf = m_pCursor + origin;
|
||||
if (newPosBuf <= m_pBuffer + m_nFileSize)
|
||||
{
|
||||
m_pCursor = newPosBuf;
|
||||
retCode = 0;
|
||||
}
|
||||
break;
|
||||
case SEEK_END:
|
||||
newPos = m_nFileSize - origin;
|
||||
if (newPos <= (int64_t)m_nFileSize)
|
||||
{
|
||||
m_pCursor = m_pBuffer + newPos;
|
||||
retCode = 0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// Not valid disk operation!
|
||||
AZ_Assert(false, "Invalid disk operation");
|
||||
}
|
||||
return retCode;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
|
||||
void Close()
|
||||
{
|
||||
if (m_fileHandle != AZ::IO::InvalidHandle)
|
||||
{
|
||||
m_pPak->FClose(m_fileHandle);
|
||||
}
|
||||
|
||||
if (m_pBuffer)
|
||||
{
|
||||
m_pPak->PoolFree(m_pBuffer);
|
||||
}
|
||||
|
||||
m_pBuffer = m_pCursor = 0;
|
||||
m_nFileSize = 0;
|
||||
m_fileHandle = AZ::IO::InvalidHandle;
|
||||
}
|
||||
|
||||
private:
|
||||
AZ::IO::HandleType m_fileHandle;
|
||||
char* m_pBuffer;
|
||||
AZ::IO::IArchive* m_pPak;
|
||||
char* m_pCursor;
|
||||
size_t m_nFileSize;
|
||||
};
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Helper class that can be used to recursively scan the directory.
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
struct SDirectoryEnumeratorHelper
|
||||
{
|
||||
public:
|
||||
void ScanDirectoryRecursive(AZ::IO::IArchive* pIPak, const AZStd::string& root, const AZStd::string& pathIn, const AZStd::string& fileSpec, AZStd::vector<AZStd::string>& files)
|
||||
{
|
||||
auto AddSlash = [](AZStd::string_view path) -> AZStd::string
|
||||
{
|
||||
if (path.ends_with(AZ_CORRECT_DATABASE_SEPARATOR))
|
||||
{
|
||||
return path;
|
||||
}
|
||||
else if (path.ends_with(AZ_WRONG_DATABASE_SEPARATOR))
|
||||
{
|
||||
return AZStd::string{ path.substr(0, path.size() - 1) } + AZ_CORRECT_DATABASE_SEPARATOR;
|
||||
}
|
||||
return path.empty() ? AZStd::string(path) : AZStd::string(path) + AZ_CORRECT_DATABASE_SEPARATOR;
|
||||
};
|
||||
AZStd::string dir;
|
||||
AZ::StringFunc::Path::Join(root.c_str(), pathIn.c_str(), dir);
|
||||
dir = AddSlash(dir);
|
||||
|
||||
ScanDirectoryFiles(pIPak, "", dir, fileSpec, files);
|
||||
|
||||
AZStd::string findFilter;
|
||||
AZ::StringFunc::Path::Join(dir.c_str(), "*", findFilter);
|
||||
|
||||
// Add all directories.
|
||||
|
||||
AZ::IO::ArchiveFileIterator pakFileIterator = pIPak->FindFirst(findFilter.c_str());
|
||||
if (pakFileIterator)
|
||||
{
|
||||
do
|
||||
{
|
||||
// Skip back folders.
|
||||
if (pakFileIterator.m_filename[0] == '.')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (pakFileIterator.m_filename.empty())
|
||||
{
|
||||
AZ_Fatal("Archive", "IArchive FindFirst/FindNext returned empty name while looking for '%s'", findFilter.c_str());
|
||||
continue;
|
||||
}
|
||||
if ((pakFileIterator.m_fileDesc.nAttrib & AZ::IO::FileDesc::Attribute::Subdirectory) == AZ::IO::FileDesc::Attribute::Subdirectory) // skip sub directories.
|
||||
{
|
||||
AZStd::string scanDir = AZStd::string::format("%s%.*s/", AddSlash(pathIn).c_str(), aznumeric_cast<int>(pakFileIterator.m_filename.size()), pakFileIterator.m_filename.data());
|
||||
scanDir += AZ_CORRECT_DATABASE_SEPARATOR;
|
||||
ScanDirectoryRecursive(pIPak, root, scanDir, fileSpec, files);
|
||||
continue;
|
||||
}
|
||||
} while (pakFileIterator = pIPak->FindNext(pakFileIterator));
|
||||
pIPak->FindClose(pakFileIterator);
|
||||
}
|
||||
}
|
||||
private:
|
||||
void ScanDirectoryFiles(AZ::IO::IArchive* pIPak, const AZStd::string& root, const AZStd::string& path, const AZStd::string& fileSpec, AZStd::vector<AZStd::string>& files)
|
||||
{
|
||||
AZStd::string dir;
|
||||
AZ::StringFunc::Path::Join(root.c_str(), path.c_str(), dir);
|
||||
|
||||
AZStd::string findFilter;
|
||||
AZ::StringFunc::Path::Join(dir.c_str(), fileSpec.c_str(), findFilter);
|
||||
|
||||
AZ::IO::ArchiveFileIterator pakFileIterator = pIPak->FindFirst(findFilter.c_str());
|
||||
if (pakFileIterator)
|
||||
{
|
||||
do
|
||||
{
|
||||
// Skip back folders and subdirectories.
|
||||
if (pakFileIterator.m_filename[0] == '.' || (pakFileIterator.m_fileDesc.nAttrib & AZ::IO::FileDesc::Attribute::Subdirectory) == AZ::IO::FileDesc::Attribute::Subdirectory)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
AZStd::string fullPath;
|
||||
AZ::StringFunc::Path::Join(path.c_str(), AZStd::string(pakFileIterator.m_filename).c_str(), fullPath);
|
||||
files.push_back(fullPath);
|
||||
} while (pakFileIterator = pIPak->FindNext(pakFileIterator));
|
||||
pIPak->FindClose(pakFileIterator);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
@@ -1,57 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <CryCommon/PakLoadDataUtils.h>
|
||||
|
||||
namespace PakLoadDataUtils
|
||||
{
|
||||
bool LoadDataFromFile_Seek(size_t elems, AZ::IO::HandleType& fileHandle, int& nDataSize, [[maybe_unused]] EEndian eEndian)
|
||||
{
|
||||
GetISystem()->GetIPak()->FSeek(fileHandle, elems, SEEK_CUR);
|
||||
nDataSize -= elems;
|
||||
AZ_Assert(nDataSize >= 0, "nDataSize must be equal or greater than 0");
|
||||
return (nDataSize >= 0);
|
||||
}
|
||||
|
||||
bool LoadDataFromFile_Seek(size_t elems, uint8*& f, int& nDataSize, [[maybe_unused]] EEndian eEndian)
|
||||
{
|
||||
nDataSize -= elems;
|
||||
f += elems;
|
||||
AZ_Assert(nDataSize >= 0, "nDataSize must be equal or greater than 0");
|
||||
return true;
|
||||
}
|
||||
|
||||
void LoadDataFromFile_FixAlignment(AZ::IO::HandleType& fileHandle, int& nDataSize)
|
||||
{
|
||||
while (nDataSize & 3)
|
||||
{
|
||||
[[maybe_unused]] size_t nRes = GetISystem()->GetIPak()->FSeek(fileHandle, 1, SEEK_CUR);
|
||||
AZ_Assert(nRes == 0, "FSeek failed for 1 byte");
|
||||
AZ_Assert(nDataSize, "nDataSize reached zero" );
|
||||
nDataSize--;
|
||||
}
|
||||
AZ_Assert(nDataSize >= 0, "nDataSize must be equal or greater than 0");
|
||||
}
|
||||
|
||||
void LoadDataFromFile_FixAlignment(uint8*& f, int& nDataSize)
|
||||
{
|
||||
while (nDataSize & 3)
|
||||
{
|
||||
AZ_Assert(*f == 222, "Found invalid data in buffer.");
|
||||
f++;
|
||||
AZ_Assert(nDataSize, "nDataSize reached zero");
|
||||
nDataSize--;
|
||||
}
|
||||
AZ_Assert(nDataSize >= 0, "nDataSize must be equal or greater than 0");
|
||||
}
|
||||
|
||||
} //namespace PakLoadDataUtils
|
||||
@@ -1,55 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <ISystem.h>
|
||||
#include <AzFramework/Archive/IArchive.h>
|
||||
|
||||
namespace PakLoadDataUtils
|
||||
{
|
||||
template <class T>
|
||||
static bool LoadDataFromFile(T* data, size_t elems, AZ::IO::HandleType& fileHandle, int& nDataSize, EEndian eEndian, int* pSeek = 0)
|
||||
{
|
||||
auto ipak = GetISystem()->GetIPak();
|
||||
if (pSeek)
|
||||
{
|
||||
*pSeek = aznumeric_cast<int>(ipak->FTell(fileHandle));
|
||||
}
|
||||
|
||||
if (ipak->FRead(data, elems, fileHandle, eEndian) != elems)
|
||||
{
|
||||
AZ_Assert(false, "Failed to read %zu elements", elems);
|
||||
return false;
|
||||
}
|
||||
nDataSize -= sizeof(T) * elems;
|
||||
AZ_Assert(nDataSize >= 0, "nDataSize must be equal or greater than 0");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LoadDataFromFile_Seek(size_t elems, AZ::IO::HandleType& fileHandle, int& nDataSize, [[maybe_unused]] EEndian eEndian);
|
||||
|
||||
template <class T>
|
||||
static bool LoadDataFromFile(T* data, size_t elems, uint8*& f, int& nDataSize, EEndian eEndian, [[maybe_unused]] int* pSeek = 0)
|
||||
{
|
||||
StepDataCopy(data, f, elems, eEndian);
|
||||
nDataSize -= elems * sizeof(T);
|
||||
AZ_Assert(nDataSize >= 0, "nDataSize must be equal or greater than 0");
|
||||
return (nDataSize >= 0);
|
||||
}
|
||||
|
||||
bool LoadDataFromFile_Seek(size_t elems, uint8*& f, int& nDataSize, [[maybe_unused]] EEndian eEndian);
|
||||
|
||||
void LoadDataFromFile_FixAlignment(AZ::IO::HandleType& fileHandle, int& nDataSize);
|
||||
|
||||
void LoadDataFromFile_FixAlignment(uint8*& f, int& nDataSize);
|
||||
|
||||
} //namespace PakLoadDataUtils
|
||||
@@ -36,9 +36,6 @@
|
||||
// require a pointer to the bucket be stored, whereas now no memory is used
|
||||
// while the block is allocated.
|
||||
//
|
||||
// This allocator is suitable for use with STL lists - see STLPoolAllocator
|
||||
// for an STL-compatible interface.
|
||||
//
|
||||
// The class can optionally support multi-threading, using the second
|
||||
// template parameter. By default it is multithread-safe.
|
||||
// See Synchronization.h.
|
||||
|
||||
@@ -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
|
||||
@@ -244,9 +242,6 @@ typedef uint32 vtx_idx;
|
||||
#endif // TESSELLATION
|
||||
#endif // !defined(MOBILE)
|
||||
|
||||
|
||||
#define USE_GEOM_CACHES
|
||||
|
||||
//------------------------------------------------------
|
||||
// SVO GI
|
||||
//------------------------------------------------------
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
#ifndef CRYINCLUDE_CRYCOMMON_QTANGENT_H
|
||||
#define CRYINCLUDE_CRYCOMMON_QTANGENT_H
|
||||
#pragma once
|
||||
|
||||
namespace QTangent {
|
||||
// Computes a QTangent from a frame and reflection scalar representing the
|
||||
// tangent space.
|
||||
// Will also ensure the resulting QTangent is suitable for 16bit quantization.
|
||||
ILINE Quat FromFrameReflection(Quat frame, const float reflection)
|
||||
{
|
||||
frame.v = -frame.v;
|
||||
if (frame.w < 0.0f)
|
||||
{
|
||||
frame = -frame;
|
||||
}
|
||||
|
||||
// Make sure w is never 0 by applying the smallest possible bias.
|
||||
// This is needed in order to have sign() never return 0 in the shaders.
|
||||
static const float BIAS_16BIT = 1.0f / 32767.0f;
|
||||
static const float BIAS_SCALE_16BIT = sqrtf(1.0f - BIAS_16BIT * BIAS_16BIT);
|
||||
if (frame.w < BIAS_16BIT && frame.w > -BIAS_16BIT)
|
||||
{
|
||||
frame *= BIAS_SCALE_16BIT;
|
||||
frame.w = BIAS_16BIT;
|
||||
}
|
||||
|
||||
if (reflection < 0.0f)
|
||||
{
|
||||
frame = -frame;
|
||||
}
|
||||
|
||||
return frame;
|
||||
}
|
||||
|
||||
ILINE Quat FromFrameReflection(const Matrix33& frame, const float reflection)
|
||||
{
|
||||
Quat quat(frame);
|
||||
quat.Normalize();
|
||||
return FromFrameReflection(quat, reflection);
|
||||
}
|
||||
|
||||
ILINE Quat FromFrameReflection16Safe(Matrix33 frame, const float reflection)
|
||||
{
|
||||
frame.OrthonormalizeFast();
|
||||
if (!frame.IsOrthonormalRH(0.1f))
|
||||
{
|
||||
frame.SetIdentity();
|
||||
}
|
||||
|
||||
return FromFrameReflection(frame, reflection);
|
||||
}
|
||||
|
||||
ILINE void ToTangentBitangentReflection(const Quat& qtangent, Vec3& tangent, Vec3& bitangent, float& reflection)
|
||||
{
|
||||
tangent = qtangent.GetColumn0();
|
||||
bitangent = qtangent.GetColumn1();
|
||||
reflection = qtangent.w < 0.0f ? -1.0f : +1.0f;
|
||||
}
|
||||
} // namespace QTangent
|
||||
|
||||
// Auxiliary helper functions
|
||||
|
||||
#include <IIndexedMesh.h> // <> required for Interfuscator
|
||||
|
||||
ILINE Quat MeshTangentFrameToQTangent(const SMeshTangents& tangents)
|
||||
{
|
||||
SMeshTangents tb = tangents;
|
||||
Vec3 tangent32, bitangent32;
|
||||
int16 reflection;
|
||||
|
||||
tb.GetTB(tangent32, bitangent32);
|
||||
tb.GetR(reflection);
|
||||
|
||||
Matrix33 frame;
|
||||
|
||||
frame.SetRow(0, tangent32);
|
||||
frame.SetRow(1, bitangent32);
|
||||
frame.SetRow(2, tangent32.Cross(bitangent32).GetNormalized());
|
||||
|
||||
return QTangent::FromFrameReflection16Safe(frame, reflection);
|
||||
}
|
||||
|
||||
ILINE Quat MeshTangentFrameToQTangent(const Vec4sf& tangent, const Vec4sf& bitangent)
|
||||
{
|
||||
return MeshTangentFrameToQTangent(SMeshTangents(tangent, bitangent));
|
||||
}
|
||||
|
||||
ILINE Quat MeshTangentFrameToQTangent(const SPipTangents& tangents)
|
||||
{
|
||||
return MeshTangentFrameToQTangent(SMeshTangents(tangents));
|
||||
}
|
||||
|
||||
ILINE bool MeshTangentsFrameToQTangents(
|
||||
const Vec4sf* pTangent, const uint tangentStride,
|
||||
const Vec4sf* pBitangent, const uint bitangentStride, const uint count,
|
||||
SPipQTangents* pQTangents, const uint qtangentStride)
|
||||
{
|
||||
Quat qtangent;
|
||||
for (uint i = 0; i < count; ++i)
|
||||
{
|
||||
qtangent = MeshTangentFrameToQTangent(*pTangent, *pBitangent);
|
||||
SMeshQTangents(qtangent).ExportTo(*pQTangents);
|
||||
|
||||
pTangent = (const Vec4sf*)(((const uint8*)pTangent) + tangentStride);
|
||||
pBitangent = (const Vec4sf*)(((const uint8*)pBitangent) + bitangentStride);
|
||||
pQTangents = (SPipQTangents*)(((uint8*)pQTangents) + qtangentStride);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
ILINE bool MeshTangentsFrameToQTangents(
|
||||
const SPipTangents* pTangents, const uint tangentStride, const uint count,
|
||||
SPipQTangents* pQTangents, const uint qtangentStride)
|
||||
{
|
||||
Quat qtangent;
|
||||
for (uint i = 0; i < count; ++i)
|
||||
{
|
||||
qtangent = MeshTangentFrameToQTangent(*pTangents);
|
||||
SMeshQTangents(qtangent).ExportTo(*pQTangents);
|
||||
|
||||
pTangents = (const SPipTangents*)(((const uint8*)pTangents) + tangentStride);
|
||||
pQTangents = (SPipQTangents*)(((uint8*)pQTangents) + qtangentStride);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
ILINE bool MeshTangentsFrameToQTangents(
|
||||
const SMeshTangents* pTangents, const uint tangentStride, const uint count,
|
||||
SMeshQTangents* pQTangents, const uint qtangentStride)
|
||||
{
|
||||
Quat qtangent;
|
||||
for (uint i = 0; i < count; ++i)
|
||||
{
|
||||
qtangent = MeshTangentFrameToQTangent(*pTangents);
|
||||
*pQTangents = SMeshQTangents(qtangent);
|
||||
|
||||
pTangents = (const SMeshTangents*)(((const uint8*)pTangents) + tangentStride);
|
||||
pQTangents = (SMeshQTangents*)(((uint8*)pQTangents) + qtangentStride);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif // CRYINCLUDE_CRYCOMMON_QTANGENT_H
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -1,86 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AzCore/RTTI/RTTI.h>
|
||||
#include <AzCore/Memory/SystemAllocator.h>
|
||||
|
||||
namespace AZ
|
||||
{
|
||||
class ReflectContext;
|
||||
}
|
||||
|
||||
namespace AzRTT
|
||||
{
|
||||
typedef AZ::Uuid RenderContextId;
|
||||
|
||||
// various post screen effects will fail if we attempt to render the scene to very
|
||||
// small render target sizes so provide a reasonable minimum (tile/icon size)
|
||||
constexpr uint32_t MinRenderTargetWidth = 32;
|
||||
constexpr uint32_t MinRenderTargetHeight = 32;
|
||||
|
||||
// this maximum recommended texture size applies to width and height
|
||||
// using sizes larger than this can lead to performance issues and instability
|
||||
constexpr uint32_t MaxRecommendedRenderTargetSize = 2048;
|
||||
|
||||
enum class AlphaMode {
|
||||
ALPHA_DISABLED = 0,
|
||||
ALPHA_OPAQUE,
|
||||
ALPHA_DEPTH_BASED
|
||||
};
|
||||
|
||||
// RenderContextConfig stores the render settings to use when rendering to texture.
|
||||
// It also provides a more developer-friendly interface to deal with by exposing
|
||||
// the most commonly used properties in one place.
|
||||
struct RenderContextConfig
|
||||
{
|
||||
AZ_CLASS_ALLOCATOR(RenderContextConfig, AZ::SystemAllocator, 0);
|
||||
AZ_RTTI(RenderContextConfig, "{6114F930-CBE4-4373-AF9D-3B5319471C8F}");
|
||||
virtual ~RenderContextConfig() = default;
|
||||
static void Reflect(AZ::ReflectContext* context);
|
||||
|
||||
//! render target width
|
||||
uint32_t m_width = 256;
|
||||
|
||||
//! render target height
|
||||
uint32_t m_height = 256;
|
||||
|
||||
//! write srgb or linear output
|
||||
bool m_sRGBWrite = false;
|
||||
|
||||
//! alpha mode to use for the render target
|
||||
AlphaMode m_alphaMode = AlphaMode::ALPHA_OPAQUE;
|
||||
|
||||
//! scene settings
|
||||
bool m_oceanEnabled = true;
|
||||
bool m_terrainEnabled = true;
|
||||
bool m_vegetationEnabled = true;
|
||||
|
||||
//! shadow settings
|
||||
bool m_shadowsEnabled = true;
|
||||
int32_t m_shadowsNumCascades = -1;
|
||||
float m_shadowsGSMRange = -1.f;
|
||||
float m_shadowsGSMRangeStep = -1.f;
|
||||
|
||||
//! post-effects settings
|
||||
bool m_depthOfFieldEnabled = false;
|
||||
bool m_motionBlurEnabled = false;
|
||||
int m_aaMode = 0;
|
||||
|
||||
//! visiblity for shadow settings
|
||||
AZ::Crc32 GetShadowSettingsVisible();
|
||||
|
||||
//! confirm if user wants to use texture size larger than MaxRecommendedRenderTargetSize
|
||||
bool ValidateTextureSize(void* newValue, const AZ::Uuid& valueType);
|
||||
};
|
||||
}
|
||||
@@ -1,273 +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 (C), Crytek, 1999-2015.
|
||||
#pragma once
|
||||
|
||||
// A fixed-size type-safe ring buffer (ie, fixed-size double-ended queue).
|
||||
// Note: It's possible to add support for iterators, indexing if needed.
|
||||
template<typename T, size_t N, typename I = uint32>
|
||||
class CRingBuffer
|
||||
{
|
||||
static_assert(std::is_integral<I>::value && std::is_unsigned<I>::value, "I is not unsigned integral type");
|
||||
static_assert(N != 0 && N <= I(-1), "N is not a valid value (or I is too small)");
|
||||
enum : I
|
||||
{
|
||||
kPowerOf2 = (N & (N - 1)) == 0,
|
||||
kMaxSize = static_cast<I>(N),
|
||||
};
|
||||
|
||||
public:
|
||||
typedef T value_type;
|
||||
typedef T& reference;
|
||||
typedef const T& const_reference;
|
||||
typedef T* pointer;
|
||||
typedef const T* const_pointer;
|
||||
typedef I size_type;
|
||||
|
||||
// Constructs an empty ring buffer.
|
||||
CRingBuffer()
|
||||
: m_begin(0)
|
||||
, m_count(0)
|
||||
{}
|
||||
|
||||
// Destroy a ring buffer.
|
||||
~CRingBuffer()
|
||||
{
|
||||
clear();
|
||||
}
|
||||
|
||||
// Retrieve the size of the collection.
|
||||
size_type size() const
|
||||
{
|
||||
return m_count;
|
||||
}
|
||||
|
||||
// Retrieve the maximum size of the collection.
|
||||
size_type max_size() const
|
||||
{
|
||||
return kMaxSize;
|
||||
}
|
||||
|
||||
// Test if the collection is empty.
|
||||
bool empty() const
|
||||
{
|
||||
return m_count == 0;
|
||||
}
|
||||
|
||||
// Test if the collection is full.
|
||||
bool full() const
|
||||
{
|
||||
return m_count == kMaxSize;
|
||||
}
|
||||
|
||||
// Get the front-most item of the collection.
|
||||
// If the collection is empty, the behavior is undefined.
|
||||
reference front()
|
||||
{
|
||||
CRY_ASSERT_MESSAGE(m_count != 0, "Container is empty");
|
||||
return *ptr(m_begin);
|
||||
}
|
||||
|
||||
// Get the front-most item of the collection.
|
||||
// If the collection is empty, the behavior is undefined.
|
||||
const_reference front() const
|
||||
{
|
||||
CRY_ASSERT_MESSAGE(m_count != 0, "Container is empty");
|
||||
return *ptr(m_begin);
|
||||
}
|
||||
|
||||
// Get the back-most item of the collection.
|
||||
// If the collection is empty, the behavior is undefined.
|
||||
reference back()
|
||||
{
|
||||
CRY_ASSERT_MESSAGE(m_count != 0, "Container is empty");
|
||||
return *ptr(wrap(m_begin + m_count - 1));
|
||||
}
|
||||
|
||||
// Get the back-most item of the collection.
|
||||
// If the collection is empty, the behavior is undefined.
|
||||
const_reference back() const
|
||||
{
|
||||
CRY_ASSERT_MESSAGE(m_count != 0, "Container is empty");
|
||||
return *ptr(wrap(m_begin + m_count - 1));
|
||||
}
|
||||
|
||||
// Adds an item to the front of the collection.
|
||||
// In case the collection is full, the function returns false and the collection remains unmodified.
|
||||
template<typename X>
|
||||
bool push_front(X&& value)
|
||||
{
|
||||
static_assert(std::is_constructible<T, X&&>::value, "T cannot be constructed from the given type");
|
||||
if (full())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
const I index = decrement(m_begin);
|
||||
::new(static_cast<void*>(ptr(index)))T(std::forward<X>(value));
|
||||
m_begin = index;
|
||||
++m_count;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Adds an item to the front of the collection.
|
||||
// In case the collection is full, the function overwrites the last item in the collection.
|
||||
template<typename X>
|
||||
void push_front_overwrite(X&& value)
|
||||
{
|
||||
static_assert(std::is_constructible<T, X&&>::value, "T cannot be constructed from the given type");
|
||||
const I index = decrement(m_begin);
|
||||
if (full())
|
||||
{
|
||||
ptr(index)->~T();
|
||||
--m_count;
|
||||
}
|
||||
::new(static_cast<void*>(ptr(index)))T(std::forward<X>(value));
|
||||
m_begin = index;
|
||||
++m_count;
|
||||
}
|
||||
|
||||
// Removes an item from the front of the collection.
|
||||
// If the collection is empty, the behavior is undefined.
|
||||
void pop_front()
|
||||
{
|
||||
CRY_ASSERT_MESSAGE(m_count != 0, "Container is empty");
|
||||
ptr(m_begin)->~T();
|
||||
m_begin = increment(m_begin);
|
||||
--m_count;
|
||||
}
|
||||
|
||||
// Attempts to remove an item from the front of the collection, and assigns it to 'value'.
|
||||
// Returns true if an item was removed, false if the collection was empty (and 'value' remains unmodified).
|
||||
bool try_pop_front(T& value)
|
||||
{
|
||||
if (m_count != 0)
|
||||
{
|
||||
T* const pItem = ptr(m_begin);
|
||||
value = std::move(*pItem);
|
||||
pItem->~T();
|
||||
m_begin = increment(m_begin);
|
||||
--m_count;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Adds an item to the back of the collection.
|
||||
// In case the collection is full, the function returns false and the collection remains unmodified.
|
||||
template<typename X>
|
||||
bool push_back(X&& value)
|
||||
{
|
||||
static_assert(std::is_constructible<T, X&&>::value, "T cannot be constructed from the given type");
|
||||
if (full())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
const I index = wrap(m_begin + m_count);
|
||||
::new(static_cast<void*>(ptr(index)))T(std::forward<X>(value));
|
||||
++m_count;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Adds an item to the back of the collection.
|
||||
// In case the collection is full, the function overwrites the first item in the collection.
|
||||
template<typename X>
|
||||
void push_back_overwrite(X&& value)
|
||||
{
|
||||
static_assert(std::is_constructible<T, X&&>::value, "T cannot be constructed from the given type");
|
||||
const I index = wrap(m_begin + m_count);
|
||||
if (full())
|
||||
{
|
||||
ptr(index)->~T();
|
||||
m_begin = increment(index);
|
||||
--m_count;
|
||||
}
|
||||
::new(static_cast<void*>(ptr(index)))T(std::forward<X>(value));
|
||||
++m_count;
|
||||
}
|
||||
|
||||
// Removes an item from the back of the collection.
|
||||
// If the collection is empty, the behavior is undefined.
|
||||
void pop_back()
|
||||
{
|
||||
CRY_ASSERT_MESSAGE(m_count != 0, "Container is empty");
|
||||
const I index = wrap(m_begin + m_count - 1);
|
||||
ptr(index)->~T();
|
||||
--m_count;
|
||||
}
|
||||
|
||||
// Attempts to remove an item from the back of the collection, and assigns it to 'value'.
|
||||
// Returns true if an item was removed, false if the collection was empty (and 'value' remains unmodified).
|
||||
bool try_pop_back(T& value)
|
||||
{
|
||||
if (m_count != 0)
|
||||
{
|
||||
const I index = wrap(m_begin + m_count - 1);
|
||||
T* const pItem = ptr(index);
|
||||
value = std::move(*pItem);
|
||||
pItem->~T();
|
||||
--m_count;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Destroy all items in a ring buffer.
|
||||
void clear()
|
||||
{
|
||||
size_type index = m_begin;
|
||||
for (size_type i = 0; i < m_count; ++i, index = increment(index))
|
||||
{
|
||||
ptr(index)->~T();
|
||||
}
|
||||
m_begin = 0;
|
||||
m_count = 0;
|
||||
}
|
||||
|
||||
private:
|
||||
// Decrements a given index, wrapping it around N.
|
||||
static size_type decrement(size_type index)
|
||||
{
|
||||
return kPowerOf2 ? ((index - 1) & (kMaxSize - 1)) : index ? index - 1 : kMaxSize - 1;
|
||||
}
|
||||
|
||||
// Increments a given index, wrapping it around N.
|
||||
static size_type increment(size_type index)
|
||||
{
|
||||
++index;
|
||||
return kPowerOf2 ? index & (kMaxSize - 1) : index == kMaxSize ? 0 : index;
|
||||
}
|
||||
|
||||
// Wraps an index, which has a maximum value of 2N-1.
|
||||
static size_type wrap(size_type index)
|
||||
{
|
||||
return kPowerOf2 ? index & (kMaxSize - 1) : index >= kMaxSize ? index - kMaxSize : index;
|
||||
}
|
||||
|
||||
// Obtain pointer to raw storage at given index.
|
||||
pointer ptr(size_type index)
|
||||
{
|
||||
return reinterpret_cast<pointer>(&m_storage) + index;
|
||||
}
|
||||
|
||||
// Obtain pointer to raw storage at given index.
|
||||
const_pointer ptr(size_type index) const
|
||||
{
|
||||
return reinterpret_cast<const_pointer>(&m_storage) + index;
|
||||
}
|
||||
|
||||
// No copy/assign supported.
|
||||
CRingBuffer(const CRingBuffer&);
|
||||
void operator=(const CRingBuffer&);
|
||||
|
||||
size_type m_begin, m_count;
|
||||
typename std::aligned_storage<sizeof(T)* N, std::alignment_of<T>::value>::type m_storage;
|
||||
};
|
||||
@@ -1,185 +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_STLGLOBALALLOCATOR_H
|
||||
#define CRYINCLUDE_CRYCOMMON_STLGLOBALALLOCATOR_H
|
||||
#pragma once
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// STL-compatible interface for an std::allocator using the global heap.
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
#include <stddef.h>
|
||||
#include <climits>
|
||||
|
||||
#include "CryMemoryManager.h"
|
||||
|
||||
#include <AzCore/Memory/AllocatorBase.h>
|
||||
#include <AzCore/Memory/HphaSchema.h>
|
||||
#include <AzCore/Memory/AllocatorManager.h>
|
||||
|
||||
struct CryLegacySTLAllocatorDescriptor
|
||||
: public AZ::HphaSchema::Descriptor
|
||||
{
|
||||
CryLegacySTLAllocatorDescriptor()
|
||||
{
|
||||
m_systemChunkSize = 4 * 1024 * 1024; // Ask the OS for 4MB at a time
|
||||
}
|
||||
};
|
||||
|
||||
class CryLegacySTLAllocator
|
||||
: public AZ::SimpleSchemaAllocator<AZ::HphaSchema, CryLegacySTLAllocatorDescriptor>
|
||||
{
|
||||
public:
|
||||
AZ_TYPE_INFO(CryLegacySTLAllocator, "{87EE21F1-8215-4979-B493-AF13D8D91DAD}");
|
||||
using Descriptor = CryLegacySTLAllocatorDescriptor;
|
||||
using Base = AZ::SimpleSchemaAllocator<AZ::HphaSchema, CryLegacySTLAllocatorDescriptor>;
|
||||
CryLegacySTLAllocator()
|
||||
: Base("CryLegacySTLAllocator", "Allocator used to dodge limits on static init time allocations")
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
// Specialize for the CryLegacySTLAllocator to provide one per module that does not use the
|
||||
// environment for its storage, since this thing is designed to get around the lack
|
||||
// of static allocators
|
||||
namespace AZ
|
||||
{
|
||||
template <>
|
||||
class AllocatorInstance<CryLegacySTLAllocator> : public Internal::AllocatorInstanceBase<CryLegacySTLAllocator, AllocatorStorage::ModuleStoragePolicy<CryLegacySTLAllocator>>
|
||||
{
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
class ICrySizer;
|
||||
namespace stl
|
||||
{
|
||||
template <class T>
|
||||
class STLGlobalAllocator
|
||||
{
|
||||
public:
|
||||
typedef size_t size_type;
|
||||
typedef ptrdiff_t difference_type;
|
||||
typedef T* pointer;
|
||||
typedef const T* const_pointer;
|
||||
typedef T& reference;
|
||||
typedef const T& const_reference;
|
||||
typedef T value_type;
|
||||
|
||||
template <class U>
|
||||
struct rebind
|
||||
{
|
||||
typedef STLGlobalAllocator<U> other;
|
||||
};
|
||||
|
||||
STLGlobalAllocator() throw()
|
||||
{
|
||||
}
|
||||
|
||||
STLGlobalAllocator(const STLGlobalAllocator&) throw()
|
||||
{
|
||||
}
|
||||
|
||||
template <class U>
|
||||
STLGlobalAllocator(const STLGlobalAllocator<U>&) throw()
|
||||
{
|
||||
}
|
||||
|
||||
~STLGlobalAllocator() throw()
|
||||
{
|
||||
}
|
||||
|
||||
pointer address(reference x) const
|
||||
{
|
||||
return &x;
|
||||
}
|
||||
|
||||
const_pointer address(const_reference x) const
|
||||
{
|
||||
return &x;
|
||||
}
|
||||
|
||||
pointer allocate(size_type n = 1, const void* hint = 0)
|
||||
{
|
||||
(void)hint;
|
||||
pointer ret = static_cast<pointer>(AZ::AllocatorInstance<CryLegacySTLAllocator>::Get().Allocate(n * sizeof(T), 0));
|
||||
return ret;
|
||||
}
|
||||
|
||||
void deallocate(pointer p, [[maybe_unused]] size_type n = 1)
|
||||
{
|
||||
AZ::AllocatorInstance<CryLegacySTLAllocator>::Get().DeAllocate(p);
|
||||
}
|
||||
|
||||
size_type max_size() const throw()
|
||||
{
|
||||
return INT_MAX;
|
||||
}
|
||||
#if !defined(_LIBCPP_VERSION)
|
||||
void construct(pointer p, const T& val)
|
||||
{
|
||||
new(static_cast<void*>(p))T(val);
|
||||
}
|
||||
|
||||
void construct(pointer p)
|
||||
{
|
||||
new(static_cast<void*>(p))T();
|
||||
}
|
||||
#endif // !_LIBCPP_VERSION
|
||||
void destroy(pointer p)
|
||||
{
|
||||
p->~T();
|
||||
}
|
||||
|
||||
pointer new_pointer()
|
||||
{
|
||||
return new(allocate())T();
|
||||
}
|
||||
|
||||
pointer new_pointer(const T& val)
|
||||
{
|
||||
return new(allocate())T(val);
|
||||
}
|
||||
|
||||
void delete_pointer(pointer p)
|
||||
{
|
||||
p->~T();
|
||||
deallocate(p);
|
||||
}
|
||||
|
||||
bool operator==(const STLGlobalAllocator&) const { return true; }
|
||||
bool operator!=(const STLGlobalAllocator&) const { return false; }
|
||||
|
||||
static void GetMemoryUsage(ICrySizer* pSizer)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
class STLGlobalAllocator<void>
|
||||
{
|
||||
public:
|
||||
typedef void* pointer;
|
||||
typedef const void* const_pointer;
|
||||
typedef void value_type;
|
||||
template <class U>
|
||||
struct rebind
|
||||
{
|
||||
typedef STLGlobalAllocator<U> other;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
#endif // CRYINCLUDE_CRYCOMMON_STLGLOBALALLOCATOR_H
|
||||
@@ -1,208 +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_STLPOOLALLOCATOR_H
|
||||
#define CRYINCLUDE_CRYCOMMON_STLPOOLALLOCATOR_H
|
||||
#pragma once
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// STL-compatible interface for the pool allocator (see PoolAllocator.h).
|
||||
//
|
||||
// This class is suitable for use as an allocator for STL lists. Note it will
|
||||
// not work with vectors, since it allocates fixed-size blocks, while vectors
|
||||
// allocate elements in variable-sized contiguous chunks.
|
||||
//
|
||||
// To create a list of type UserDataType using this allocator, use the
|
||||
// following syntax:
|
||||
//
|
||||
// std::list<UserDataType, STLPoolAllocator<UserDataType> > myList;
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
#include "PoolAllocator.h"
|
||||
#include "MetaUtils.h"
|
||||
#include <stddef.h>
|
||||
#include <climits>
|
||||
|
||||
namespace stl
|
||||
{
|
||||
namespace STLPoolAllocatorHelper
|
||||
{
|
||||
inline void destruct(char*) {}
|
||||
inline void destruct(wchar_t*) {}
|
||||
template <typename T>
|
||||
inline void destruct(T* t) {t->~T(); }
|
||||
}
|
||||
|
||||
template <size_t S, class L, size_t A, bool FreeWhenEmpty, typename T>
|
||||
struct STLPoolAllocatorStatic
|
||||
{
|
||||
// Non-freeing stl pool allocators should just go on the global heap - only if they've been explicitly
|
||||
// set to cleanup should they go on the default heap.
|
||||
typedef SizePoolAllocator<
|
||||
HeapAllocator<
|
||||
L,
|
||||
typename metautils::select<FreeWhenEmpty, HeapSysAllocator, GlobalHeapSysAllocator>::type>
|
||||
> AllocatorType;
|
||||
|
||||
static AllocatorType* GetOrCreateAllocator()
|
||||
{
|
||||
if (allocator)
|
||||
{
|
||||
return allocator;
|
||||
}
|
||||
|
||||
allocator = new AllocatorType(S, A, FHeap().FreeWhenEmpty(FreeWhenEmpty));
|
||||
return allocator;
|
||||
}
|
||||
|
||||
static AllocatorType* allocator;
|
||||
};
|
||||
|
||||
template <class T, class L, size_t A, bool FreeWhenEmpty>
|
||||
struct STLPoolAllocatorKungFu
|
||||
: public STLPoolAllocatorStatic<sizeof(T), L, A, FreeWhenEmpty, T>
|
||||
{
|
||||
};
|
||||
|
||||
template <class T, class L = PSyncMultiThread, size_t A = 0, bool FreeWhenEmpty = false>
|
||||
class STLPoolAllocator
|
||||
{
|
||||
public:
|
||||
typedef size_t size_type;
|
||||
typedef ptrdiff_t difference_type;
|
||||
typedef T* pointer;
|
||||
typedef const T* const_pointer;
|
||||
typedef T& reference;
|
||||
typedef const T& const_reference;
|
||||
typedef T value_type;
|
||||
|
||||
template <class U>
|
||||
struct rebind
|
||||
{
|
||||
typedef STLPoolAllocator<U, L, A, FreeWhenEmpty> other;
|
||||
};
|
||||
|
||||
STLPoolAllocator() throw()
|
||||
{
|
||||
}
|
||||
|
||||
STLPoolAllocator(const STLPoolAllocator&) throw()
|
||||
{
|
||||
}
|
||||
|
||||
template <class U, class M, size_t B, bool FreeWhenEmptyA>
|
||||
STLPoolAllocator(const STLPoolAllocator<U, M, B, FreeWhenEmptyA>&) throw()
|
||||
{
|
||||
}
|
||||
|
||||
~STLPoolAllocator() throw()
|
||||
{
|
||||
}
|
||||
|
||||
pointer address(reference x) const
|
||||
{
|
||||
return &x;
|
||||
}
|
||||
|
||||
const_pointer address(const_reference x) const
|
||||
{
|
||||
return &x;
|
||||
}
|
||||
|
||||
pointer allocate([[maybe_unused]] size_type n = 1, [[maybe_unused]] const void* hint = 0)
|
||||
{
|
||||
assert(n == 1);
|
||||
typename STLPoolAllocatorKungFu<T, L, A, FreeWhenEmpty>::AllocatorType * allocator = STLPoolAllocatorKungFu<T, L, A, FreeWhenEmpty>::GetOrCreateAllocator();
|
||||
return static_cast<T*>(allocator->Allocate());
|
||||
}
|
||||
|
||||
void deallocate(pointer p, [[maybe_unused]] size_type n = 1)
|
||||
{
|
||||
assert(n == 1);
|
||||
typename STLPoolAllocatorKungFu<T, L, A, FreeWhenEmpty>::AllocatorType * allocator = STLPoolAllocatorKungFu<T, L, A, FreeWhenEmpty>::allocator;
|
||||
allocator->Deallocate(p);
|
||||
}
|
||||
|
||||
size_type max_size() const throw()
|
||||
{
|
||||
return INT_MAX;
|
||||
}
|
||||
#ifndef _LIBCPP_VERSION
|
||||
void construct(pointer p, const T& val)
|
||||
{
|
||||
new(static_cast<void*>(p))T(val);
|
||||
}
|
||||
|
||||
void construct(pointer p)
|
||||
{
|
||||
new(static_cast<void*>(p))T();
|
||||
}
|
||||
#endif // !(_LIBCPP_VERSION)
|
||||
void destroy(pointer p)
|
||||
{
|
||||
STLPoolAllocatorHelper::destruct(p);
|
||||
}
|
||||
|
||||
pointer new_pointer()
|
||||
{
|
||||
return new(allocate())T();
|
||||
}
|
||||
|
||||
pointer new_pointer(const T& val)
|
||||
{
|
||||
return new(allocate())T(val);
|
||||
}
|
||||
|
||||
void delete_pointer(pointer p)
|
||||
{
|
||||
p->~T();
|
||||
deallocate(p);
|
||||
}
|
||||
|
||||
bool operator==(const STLPoolAllocator&) {return true; }
|
||||
bool operator!=(const STLPoolAllocator&) {return false; }
|
||||
|
||||
static void GetMemoryUsage(ICrySizer* pSizer)
|
||||
{
|
||||
pSizer->AddObject(STLPoolAllocatorKungFu<T, L, A, FreeWhenEmpty>::allocator);
|
||||
}
|
||||
};
|
||||
|
||||
template <class T, size_t A = 0, bool FreeWhenEmpty = false>
|
||||
class STLPoolAllocatorNoMT
|
||||
: public STLPoolAllocator<T, PSyncNone, A, FreeWhenEmpty>
|
||||
{
|
||||
};
|
||||
|
||||
template <>
|
||||
class STLPoolAllocator<void>
|
||||
{
|
||||
public:
|
||||
typedef void* pointer;
|
||||
typedef const void* const_pointer;
|
||||
typedef void value_type;
|
||||
template <class U, class L>
|
||||
struct rebind
|
||||
{
|
||||
typedef STLPoolAllocator<U> other;
|
||||
};
|
||||
};
|
||||
|
||||
template <size_t S, typename L, size_t A, bool FreeWhenEmpty, typename T>
|
||||
typename STLPoolAllocatorStatic<S, L, A, FreeWhenEmpty, T>::AllocatorType * STLPoolAllocatorStatic<S, L, A, FreeWhenEmpty, T>::allocator;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif // CRYINCLUDE_CRYCOMMON_STLPOOLALLOCATOR_H
|
||||
@@ -1,107 +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_STLPOOLALLOCATOR_MANYELEMS_H
|
||||
#define CRYINCLUDE_CRYCOMMON_STLPOOLALLOCATOR_MANYELEMS_H
|
||||
#pragma once
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// STL-compatible interface for the pool allocator (see PoolAllocator.h).
|
||||
//
|
||||
// this class acts like STLPoolAllocator, but it is also usable for vectors
|
||||
// which means that it can be used as a more efficient allocator for many
|
||||
// implementations of hash_map (typically this uses internally a vector and
|
||||
// a list with the same allocator)
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
#include "STLPoolAllocator.h"
|
||||
|
||||
namespace stl
|
||||
{
|
||||
template <size_t S, typename L, size_t A>
|
||||
struct STLPoolAllocator_ManyElemsStatic
|
||||
{
|
||||
static PoolAllocator<S, L, A>* allocator;
|
||||
};
|
||||
|
||||
template <typename T, typename L = PSyncMultiThread, size_t LargeAllocationSizeThreshold = 54* sizeof(void*), size_t A = 0>
|
||||
class STLPoolAllocator_ManyElems
|
||||
: public STLPoolAllocator<T, L, A>
|
||||
{
|
||||
typedef STLPoolAllocator<T, L, A> Super;
|
||||
typedef PoolAllocator<LargeAllocationSizeThreshold, L, A> LargeAllocator;
|
||||
|
||||
public:
|
||||
typedef typename Super::pointer pointer;
|
||||
typedef typename Super::pointer pointer_type;
|
||||
typedef typename Super::size_type size_type;
|
||||
typedef AZStd::false_type allow_memory_leaks;
|
||||
|
||||
template <typename U>
|
||||
struct rebind
|
||||
{
|
||||
typedef STLPoolAllocator_ManyElems<U, L, LargeAllocationSizeThreshold, A> other;
|
||||
};
|
||||
|
||||
STLPoolAllocator_ManyElems() throw()
|
||||
{
|
||||
}
|
||||
|
||||
template <typename U, typename M, size_t C, size_t B>
|
||||
STLPoolAllocator_ManyElems(const STLPoolAllocator_ManyElems<U, M, C, B>&) throw()
|
||||
{
|
||||
}
|
||||
|
||||
pointer allocate(size_type n = 1, const void* hint = 0)
|
||||
{
|
||||
if (n == 1)
|
||||
{
|
||||
return Super::allocate(n, hint);
|
||||
}
|
||||
else if (n * sizeof(T) <= LargeAllocationSizeThreshold)
|
||||
{
|
||||
if (!STLPoolAllocator_ManyElemsStatic<LargeAllocationSizeThreshold, L, A>::allocator)
|
||||
{
|
||||
STLPoolAllocator_ManyElemsStatic<LargeAllocationSizeThreshold, L, A>::allocator = new LargeAllocator();
|
||||
}
|
||||
return static_cast<T*>(STLPoolAllocator_ManyElemsStatic<LargeAllocationSizeThreshold, L, A>::allocator->Allocate());
|
||||
}
|
||||
else
|
||||
{
|
||||
return static_cast<pointer>(CryModuleMalloc(n * sizeof(T)));
|
||||
}
|
||||
}
|
||||
|
||||
void deallocate(pointer p, size_type n = 1)
|
||||
{
|
||||
if (n == 1)
|
||||
{
|
||||
Super::deallocate(p);
|
||||
}
|
||||
else if (n * sizeof(T) <= LargeAllocationSizeThreshold)
|
||||
{
|
||||
STLPoolAllocator_ManyElemsStatic<LargeAllocationSizeThreshold, L, A>::allocator->Deallocate(p);
|
||||
}
|
||||
else
|
||||
{
|
||||
CryModuleFree(p);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <size_t S, typename L, size_t A>
|
||||
PoolAllocator<S, L, A>* STLPoolAllocator_ManyElemsStatic<S, L, A>::allocator;
|
||||
}
|
||||
|
||||
#endif // CRYINCLUDE_CRYCOMMON_STLPOOLALLOCATOR_MANYELEMS_H
|
||||
@@ -1,188 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
#if defined(AZ_RESTRICTED_PLATFORM)
|
||||
#undef AZ_RESTRICTED_SECTION
|
||||
#define SCOPEGUARD_H_SECTION_1 1
|
||||
#define SCOPEGUARD_H_SECTION_2 2
|
||||
#endif
|
||||
|
||||
/**
|
||||
This is from the c++17 working draft paper N3949 http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n3949.pdf
|
||||
It is a new library addition targeted for c++17. I didn't feel like waiting. Only modification is as required to get the
|
||||
code compiling in the yet to be c++11 compliant visual studio. It is similar to boost scope exit, but in a modern and
|
||||
more feature rich form. scope_guard just executes a lambda when it goes out of scope. unique_resource is a more complete
|
||||
RAII wrapper. Its stands in for a resource (i.e. overloads cast operator to the wrapped resource) and frees it when it
|
||||
goes out of scope. see the paper for more examples and a better description. Get rid of this once c++17 is available.
|
||||
*/
|
||||
namespace std17
|
||||
{
|
||||
template <typename D>
|
||||
struct scope_guard_t
|
||||
{
|
||||
// construction
|
||||
explicit scope_guard_t(D&& f)
|
||||
: deleter(std::move(f))
|
||||
, execute_on_destruction(true)
|
||||
{
|
||||
}
|
||||
// move
|
||||
scope_guard_t(scope_guard_t&& rhs)
|
||||
: deleter(std::move(rhs.deleter))
|
||||
, execute_on_destruction(rhs.execute_on_destruction)
|
||||
{
|
||||
rhs.release();
|
||||
}
|
||||
// release
|
||||
~scope_guard_t()
|
||||
{
|
||||
if (execute_on_destruction)
|
||||
{
|
||||
deleter();
|
||||
}
|
||||
}
|
||||
void release() { execute_on_destruction = false; }
|
||||
private:
|
||||
#if defined(AZ_RESTRICTED_PLATFORM)
|
||||
#define AZ_RESTRICTED_SECTION SCOPEGUARD_H_SECTION_1
|
||||
#include AZ_RESTRICTED_FILE(ScopeGuard_h)
|
||||
#endif
|
||||
#if defined(AZ_RESTRICTED_SECTION_IMPLEMENTED)
|
||||
#undef AZ_RESTRICTED_SECTION_IMPLEMENTED
|
||||
#else
|
||||
scope_guard_t(scope_guard_t const&) = delete;
|
||||
void operator=(scope_guard_t const&) = delete;
|
||||
scope_guard_t& operator=(scope_guard_t&&) = delete;
|
||||
#endif
|
||||
D deleter;
|
||||
bool execute_on_destruction;
|
||||
// exposition only
|
||||
};
|
||||
|
||||
template <typename D>
|
||||
scope_guard_t<D> scope_guard(D&& deleter)
|
||||
{
|
||||
return scope_guard_t<D>(std::move(deleter));
|
||||
// fails with curlies
|
||||
}
|
||||
|
||||
enum class invoke_it
|
||||
{
|
||||
once, again
|
||||
};
|
||||
template<typename R, typename D>
|
||||
class unique_resource_t
|
||||
{
|
||||
R resource;
|
||||
D deleter;
|
||||
bool execute_on_destruction;
|
||||
// exposition only
|
||||
#if defined(AZ_RESTRICTED_PLATFORM)
|
||||
#define AZ_RESTRICTED_SECTION SCOPEGUARD_H_SECTION_2
|
||||
#include AZ_RESTRICTED_FILE(ScopeGuard_h)
|
||||
#endif
|
||||
#if defined(AZ_RESTRICTED_SECTION_IMPLEMENTED)
|
||||
#undef AZ_RESTRICTED_SECTION_IMPLEMENTED
|
||||
#else
|
||||
unique_resource_t& operator=(unique_resource_t const&) = delete;
|
||||
unique_resource_t(unique_resource_t const&) = delete;
|
||||
#endif
|
||||
// no copies!
|
||||
public:
|
||||
// construction
|
||||
explicit unique_resource_t(R&& _resource, D&& _deleter, bool _shouldrun = true)
|
||||
: resource(std::move(_resource))
|
||||
, deleter(std::move(_deleter))
|
||||
, execute_on_destruction(_shouldrun)
|
||||
{
|
||||
}
|
||||
// move
|
||||
unique_resource_t(unique_resource_t&& other)
|
||||
: resource(std::move(other.resource))
|
||||
, deleter(std::move(other.deleter))
|
||||
, execute_on_destruction(other.execute_on_destruction)
|
||||
{
|
||||
other.release();
|
||||
}
|
||||
unique_resource_t& operator=(unique_resource_t&& other)
|
||||
{
|
||||
this->invoke(invoke_it::once);
|
||||
deleter = std::move(other.deleter);
|
||||
resource = std::move(other.resource);
|
||||
execute_on_destruction = other.execute_on_destruction;
|
||||
other.release();
|
||||
return *this;
|
||||
}
|
||||
// resource release
|
||||
~unique_resource_t()
|
||||
{
|
||||
this->invoke(invoke_it::once);
|
||||
}
|
||||
void invoke(invoke_it const strategy = invoke_it::once)
|
||||
{
|
||||
if (execute_on_destruction)
|
||||
{
|
||||
get_deleter()(resource);
|
||||
}
|
||||
execute_on_destruction = strategy == invoke_it::again;
|
||||
}
|
||||
R const& release()
|
||||
{
|
||||
execute_on_destruction = false;
|
||||
return this->get();
|
||||
}
|
||||
void reset(R&& newresource)
|
||||
{
|
||||
invoke(invoke_it::again);
|
||||
resource = std::move(newresource);
|
||||
}
|
||||
// resource access
|
||||
R const& get() const
|
||||
{
|
||||
return resource;
|
||||
}
|
||||
operator R const& () const
|
||||
{
|
||||
return resource;
|
||||
}
|
||||
R operator->() const
|
||||
{
|
||||
return resource;
|
||||
}
|
||||
typename std::add_lvalue_reference<typename std::remove_pointer<R>::type>::type operator*() const
|
||||
{
|
||||
return *resource;
|
||||
}
|
||||
// deleter access
|
||||
const D& get_deleter() const
|
||||
{
|
||||
return deleter;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename R, typename D>
|
||||
unique_resource_t<R, D> unique_resource(R&& r, D t)
|
||||
{
|
||||
return unique_resource_t<R, D>(std::move(r), std::move(t), true);
|
||||
}
|
||||
|
||||
template<typename R, typename D>
|
||||
unique_resource_t<R, D> unique_resource_checked(R r, R invalid, D t)
|
||||
{
|
||||
bool shouldrun = (r != invalid);
|
||||
return unique_resource_t<R, D>(std::move(r), std::move(t), shouldrun);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,27 +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.
|
||||
|
||||
// This header is provided for backwards compatibility. Avoid including this header, instead
|
||||
// include the needed smart ptr headers
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AzCore/std/smart_ptr/shared_ptr.h>
|
||||
#include <AzCore/std/smart_ptr/make_shared.h>
|
||||
#include <AzCore/std/smart_ptr/weak_ptr.h>
|
||||
|
||||
#define DECLARE_SMART_POINTERS(name) \
|
||||
typedef AZStd::shared_ptr<name> name##Ptr; \
|
||||
typedef AZStd::shared_ptr<const name> name##ConstPtr; \
|
||||
typedef AZStd::weak_ptr<name> name##WeakPtr; \
|
||||
typedef AZStd::weak_ptr<const name> name##ConstWeakPtr;
|
||||
@@ -1,64 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
// Description : Helper to enable inplace construction and destruction of objects
|
||||
|
||||
#ifndef CRYINCLUDE_CRYCOMMON_STACKCONTAINER_H
|
||||
#define CRYINCLUDE_CRYCOMMON_STACKCONTAINER_H
|
||||
#pragma once
|
||||
|
||||
#include <InplaceFactory.h>
|
||||
|
||||
// Class that contains a non-pod data type allocated on the stack via placement
|
||||
// new. Constructor parameters up to an arity of 5 are forwarded over an
|
||||
// inplace factory expression.
|
||||
template<typename T>
|
||||
class CStackContainer
|
||||
{
|
||||
// The backing storage
|
||||
uint8 m_Storage[ sizeof (T) ];
|
||||
|
||||
// Constructs the object via an inplace factory
|
||||
template<class Factory>
|
||||
void construct (const Factory& factory)
|
||||
{
|
||||
factory.template apply<T>(m_Storage);
|
||||
}
|
||||
|
||||
// Destructs the object. The destructor of the contained object is called
|
||||
void destruct ()
|
||||
{
|
||||
reinterpret_cast<T*>(m_Storage)->~T();
|
||||
}
|
||||
|
||||
// Prevent the object to be placed on the heap
|
||||
// (.... it simply wouldn't make much sense)
|
||||
void* operator new(size_t);
|
||||
void operator delete(void*);
|
||||
|
||||
public:
|
||||
|
||||
// Constructs inside the object
|
||||
template<class Expr>
|
||||
CStackContainer (const Expr& expr)
|
||||
{ construct(expr); }
|
||||
|
||||
// Destructs the object contained
|
||||
~CStackContainer() { destruct(); }
|
||||
|
||||
// Accessor methods
|
||||
T* get() { return reinterpret_cast<T*>(m_Storage); }
|
||||
const T* get() const { return reinterpret_cast<const T*>(m_Storage); }
|
||||
};
|
||||
|
||||
#endif // CRYINCLUDE_CRYCOMMON_STACKCONTAINER_H
|
||||
@@ -27,7 +27,6 @@
|
||||
#endif
|
||||
|
||||
#define STATIC_ASSERT(condition, errMessage) static_assert(condition, errMessage)
|
||||
#include "STLGlobalAllocator.h"
|
||||
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
||||
@@ -1,88 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <CrySizer.h>
|
||||
#include <CryPodArray.h>
|
||||
|
||||
template <class T>
|
||||
class TPool
|
||||
{
|
||||
public:
|
||||
|
||||
TPool(int nPoolSize)
|
||||
{
|
||||
m_nPoolSize = nPoolSize;
|
||||
m_pPool = new T[nPoolSize];
|
||||
m_lstFree.PreAllocate(nPoolSize, 0);
|
||||
m_lstUsed.PreAllocate(nPoolSize, 0);
|
||||
for (int i = 0; i < nPoolSize; i++)
|
||||
{
|
||||
m_lstFree.Add(&m_pPool[i]);
|
||||
}
|
||||
}
|
||||
|
||||
~TPool()
|
||||
{
|
||||
delete[] m_pPool;
|
||||
}
|
||||
|
||||
void ReleaseObject(T* pInst)
|
||||
{
|
||||
if (m_lstUsed.Delete(pInst))
|
||||
{
|
||||
m_lstFree.Add(pInst);
|
||||
}
|
||||
}
|
||||
|
||||
int GetUsedInstancesCount(int& nAll)
|
||||
{
|
||||
nAll = m_nPoolSize;
|
||||
return m_lstUsed.Count();
|
||||
}
|
||||
|
||||
T* GetObject()
|
||||
{
|
||||
T* pInst = NULL;
|
||||
if (m_lstFree.Count())
|
||||
{
|
||||
pInst = m_lstFree.Last();
|
||||
m_lstFree.DeleteLast();
|
||||
m_lstUsed.Add(pInst);
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(!"TPool::GetObject: Out of free elements error");
|
||||
}
|
||||
|
||||
return pInst;
|
||||
}
|
||||
|
||||
void GetMemoryUsage(class ICrySizer* pSizer) const
|
||||
{
|
||||
pSizer->AddObject(m_lstFree);
|
||||
pSizer->AddObject(m_lstUsed);
|
||||
|
||||
if (m_pPool)
|
||||
{
|
||||
for (int i = 0; i < m_nPoolSize; i++)
|
||||
{
|
||||
m_pPool[i].GetMemoryUsage(pSizer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PodArray<T*> m_lstFree;
|
||||
PodArray<T*> m_lstUsed;
|
||||
T* m_pPool;
|
||||
int m_nPoolSize;
|
||||
};
|
||||
@@ -19,7 +19,6 @@
|
||||
#include <ILog.h>
|
||||
#include <Cry_Math.h>
|
||||
#include <AzCore/IO/FileIO.h>
|
||||
#include <STLGlobalAllocator.h>
|
||||
|
||||
#ifndef CLAMP
|
||||
#define CLAMP(X, mn, mx) ((X) < (mn) ? (mn) : ((X) < (mx) ? (X) : (mx)))
|
||||
@@ -58,400 +57,4 @@
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
// General array class.
|
||||
// Can refer to a general (unowned) region of memory (m_nAllocatedCount = 0).
|
||||
// Can allocate, grow, and shrink an array.
|
||||
// Does not deep copy.
|
||||
|
||||
template<class T>
|
||||
class TArray
|
||||
{
|
||||
protected:
|
||||
T* m_pElements;
|
||||
unsigned int m_nCount;
|
||||
unsigned int m_nAllocatedCount;
|
||||
|
||||
public:
|
||||
typedef T value_type;
|
||||
|
||||
// Empty array.
|
||||
TArray()
|
||||
{
|
||||
ClearArr();
|
||||
}
|
||||
|
||||
// Create a new array, delete it on destruction.
|
||||
TArray(int Count)
|
||||
{
|
||||
m_nCount = Count;
|
||||
m_nAllocatedCount = Count;
|
||||
m_pElements = NULL;
|
||||
Realloc(0);
|
||||
}
|
||||
TArray(int Use, int Max)
|
||||
{
|
||||
m_nCount = Use;
|
||||
m_nAllocatedCount = Max;
|
||||
m_pElements = NULL;
|
||||
Realloc(0);
|
||||
}
|
||||
|
||||
// Reference pre-existing memory. Does not delete it.
|
||||
TArray(T* Elems, int Count)
|
||||
{
|
||||
m_pElements = Elems;
|
||||
m_nCount = Count;
|
||||
m_nAllocatedCount = 0;
|
||||
}
|
||||
~TArray()
|
||||
{
|
||||
Free();
|
||||
}
|
||||
|
||||
void Free()
|
||||
{
|
||||
m_nCount = 0;
|
||||
if (m_nAllocatedCount && AZ::AllocatorInstance<CryLegacySTLAllocator>::IsReady())
|
||||
{
|
||||
AZ::AllocatorInstance<CryLegacySTLAllocator>::Get().DeAllocate(m_pElements);
|
||||
}
|
||||
m_nAllocatedCount = 0;
|
||||
m_pElements = NULL;
|
||||
}
|
||||
|
||||
void Create (int Count)
|
||||
{
|
||||
m_pElements = NULL;
|
||||
m_nCount = Count;
|
||||
m_nAllocatedCount = Count;
|
||||
Realloc(0);
|
||||
Clear();
|
||||
}
|
||||
void Copy (const TArray<T>& src)
|
||||
{
|
||||
m_pElements = NULL;
|
||||
m_nCount = m_nAllocatedCount = src.Num();
|
||||
Realloc(0);
|
||||
PREFAST_ASSUME(m_pElements); // realloc asserts if it fails - so this is safe
|
||||
memcpy(m_pElements, src.m_pElements, src.Num() * sizeof(T));
|
||||
}
|
||||
void Copy (const T* src, unsigned int numElems)
|
||||
{
|
||||
int nOffs = m_nCount;
|
||||
Grow(numElems);
|
||||
memcpy(&m_pElements[nOffs], src, numElems * sizeof(T));
|
||||
}
|
||||
void Align4Copy (const T* src, unsigned int& numElems)
|
||||
{
|
||||
int nOffs = m_nCount;
|
||||
Grow((numElems + 3) & ~3);
|
||||
memcpy(&m_pElements[nOffs], src, numElems * sizeof(T));
|
||||
if (numElems & 3)
|
||||
{
|
||||
int nSet = 4 - (numElems & 3);
|
||||
memset(&m_pElements[nOffs + numElems], 0, nSet);
|
||||
numElems += nSet;
|
||||
}
|
||||
}
|
||||
|
||||
void Realloc([[maybe_unused]] int nOldAllocatedCount)
|
||||
{
|
||||
if (!m_nAllocatedCount)
|
||||
{
|
||||
m_pElements = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pElements = static_cast<decltype(m_pElements)>(AZ::AllocatorInstance<CryLegacySTLAllocator>::Get().ReAllocate(m_pElements, m_nAllocatedCount * sizeof(T), alignof(T)));
|
||||
assert (m_pElements);
|
||||
}
|
||||
}
|
||||
|
||||
void Remove(unsigned int Index, unsigned int Count = 1)
|
||||
{
|
||||
if (Count)
|
||||
{
|
||||
memmove(m_pElements + Index, m_pElements + (Index + Count), sizeof(T) * (m_nCount - Index - Count));
|
||||
m_nCount -= Count;
|
||||
}
|
||||
}
|
||||
|
||||
void Shrink()
|
||||
{
|
||||
if (m_nCount == 0 || m_nAllocatedCount == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
assert(m_nAllocatedCount >= m_nCount);
|
||||
if (m_nAllocatedCount != m_nCount)
|
||||
{
|
||||
int nOldAllocatedCount = m_nAllocatedCount;
|
||||
m_nAllocatedCount = m_nCount;
|
||||
Realloc(nOldAllocatedCount);
|
||||
}
|
||||
}
|
||||
|
||||
void _Remove(unsigned int Index, unsigned int Count)
|
||||
{
|
||||
assert (Index >= 0);
|
||||
assert (Index <= m_nCount);
|
||||
assert ((Index + Count) <= m_nCount);
|
||||
|
||||
Remove(Index, Count);
|
||||
}
|
||||
|
||||
unsigned int Num(void) const { return m_nCount; }
|
||||
unsigned int Capacity(void) const { return m_nAllocatedCount; }
|
||||
unsigned int MemSize(void) const { return m_nCount * sizeof(T); }
|
||||
void SetNum(unsigned int n) { m_nCount = m_nAllocatedCount = n; }
|
||||
void SetUse(unsigned int n) { m_nCount = n; }
|
||||
void Alloc(unsigned int n) { int nOldAllocatedCount = m_nAllocatedCount; m_nAllocatedCount = n; Realloc(nOldAllocatedCount); }
|
||||
void Reserve(unsigned int n) { int nOldAllocatedCount = m_nAllocatedCount; SetNum(n); Realloc(nOldAllocatedCount); Clear(); }
|
||||
void ReserveNoClear(unsigned int n) { int nOldAllocatedCount = m_nAllocatedCount; SetNum(n); Realloc(nOldAllocatedCount); }
|
||||
void Expand(unsigned int n)
|
||||
{
|
||||
if (n > m_nAllocatedCount)
|
||||
{
|
||||
ReserveNew(n);
|
||||
}
|
||||
}
|
||||
void ReserveNew(unsigned int n)
|
||||
{
|
||||
int num = m_nCount;
|
||||
if (n > m_nAllocatedCount)
|
||||
{
|
||||
int nOldAllocatedCount = m_nAllocatedCount;
|
||||
m_nAllocatedCount = n * 2;
|
||||
Realloc(nOldAllocatedCount);
|
||||
}
|
||||
m_nCount = n;
|
||||
memset(&m_pElements[num], 0, sizeof(T) * (m_nCount - num));
|
||||
}
|
||||
T* Grow(unsigned int n)
|
||||
{
|
||||
int nStart = m_nCount;
|
||||
m_nCount += n;
|
||||
if (m_nCount > m_nAllocatedCount)
|
||||
{
|
||||
int nOldAllocatedCount = m_nAllocatedCount;
|
||||
m_nAllocatedCount = m_nCount * 2;
|
||||
Realloc(nOldAllocatedCount);
|
||||
}
|
||||
return &m_pElements[nStart];
|
||||
}
|
||||
T* GrowReset(unsigned int n)
|
||||
{
|
||||
int num = m_nAllocatedCount;
|
||||
T* Obj = AddIndex(n);
|
||||
if (num != m_nAllocatedCount)
|
||||
{
|
||||
memset(&m_pElements[num], 0, sizeof(T) * (m_nAllocatedCount - num));
|
||||
}
|
||||
return Obj;
|
||||
}
|
||||
|
||||
unsigned int* GetNumAddr(void) { return &m_nCount; }
|
||||
T** GetDataAddr(void) { return &m_pElements; }
|
||||
|
||||
T* Data(void) const { return m_pElements; }
|
||||
T& Get(unsigned int id) const { return m_pElements[id]; }
|
||||
|
||||
|
||||
void Assign(TArray& fa)
|
||||
{
|
||||
m_pElements = fa.m_pElements;
|
||||
m_nCount = fa.m_nCount;
|
||||
m_nAllocatedCount = fa.m_nAllocatedCount;
|
||||
}
|
||||
|
||||
|
||||
/*const TArray operator=(TArray fa) const
|
||||
{
|
||||
TArray<T> t = TArray(fa.m_nCount,fa.m_nAllocatedCount);
|
||||
for ( int i=0; i<fa.Num(); i++ )
|
||||
{
|
||||
t.AddElem(fa[i]);
|
||||
}
|
||||
return t;
|
||||
}*/
|
||||
|
||||
const T& operator[](unsigned int i) const { assert(i < m_nCount); return m_pElements[i]; }
|
||||
T& operator[](unsigned int i) { assert(i < m_nCount); return m_pElements[i]; }
|
||||
T& operator * () { assert(m_nCount > 0); return *m_pElements; }
|
||||
|
||||
TArray<T> operator()(unsigned int Start)
|
||||
{
|
||||
assert(Start < m_nCount);
|
||||
return TArray<T>(m_pElements + Start, m_nCount - Start);
|
||||
}
|
||||
TArray<T> operator()(unsigned int Start, unsigned int Count)
|
||||
{
|
||||
assert(Start < m_nCount);
|
||||
assert(Start + Count <= m_nCount);
|
||||
return TArray<T>(m_pElements + Start, Count);
|
||||
}
|
||||
|
||||
// For simple types only
|
||||
TArray(const TArray<T>& cTA)
|
||||
{
|
||||
m_pElements = NULL;
|
||||
m_nCount = m_nAllocatedCount = cTA.Num();
|
||||
Realloc(0);
|
||||
if (m_pElements)
|
||||
{
|
||||
memcpy(m_pElements, &cTA[0], m_nCount * sizeof(T));
|
||||
}
|
||||
/*for (unsigned int i=0; i<cTA.Num(); i++ )
|
||||
{
|
||||
AddElem(cTA[i]);
|
||||
}*/
|
||||
}
|
||||
inline TArray& operator = (const TArray& cTA)
|
||||
{
|
||||
Free();
|
||||
new(this)TArray(cTA);
|
||||
return *this;
|
||||
}
|
||||
void ClearArr(void)
|
||||
{
|
||||
m_nCount = 0;
|
||||
m_nAllocatedCount = 0;
|
||||
m_pElements = NULL;
|
||||
}
|
||||
|
||||
void Clear(void)
|
||||
{
|
||||
memset(m_pElements, 0, m_nCount * sizeof(T));
|
||||
}
|
||||
|
||||
void AddString(const char* szStr)
|
||||
{
|
||||
assert(szStr);
|
||||
int nLen = strlen(szStr) + 1;
|
||||
T* pDst = Grow(nLen);
|
||||
memcpy(pDst, szStr, nLen);
|
||||
}
|
||||
|
||||
void Set(unsigned int m)
|
||||
{
|
||||
memset(m_pElements, m, m_nCount * sizeof(T));
|
||||
}
|
||||
|
||||
ILINE T* AddIndex(unsigned int inc)
|
||||
{
|
||||
unsigned int nIndex = m_nCount;
|
||||
unsigned int nNewCount = m_nCount + inc;
|
||||
|
||||
if (nNewCount > m_nAllocatedCount)
|
||||
{
|
||||
int nOldAllocatedCount = m_nAllocatedCount;
|
||||
m_nAllocatedCount = nNewCount + (nNewCount >> 1) + 10;
|
||||
Realloc(nOldAllocatedCount);
|
||||
}
|
||||
|
||||
m_nCount = nNewCount;
|
||||
return &m_pElements[nIndex];
|
||||
}
|
||||
|
||||
T& Insert(unsigned int nIndex, unsigned int inc = 1)
|
||||
{
|
||||
m_nCount += inc;
|
||||
if (m_nCount > m_nAllocatedCount)
|
||||
{
|
||||
int nOldAllocatedCount = m_nAllocatedCount;
|
||||
m_nAllocatedCount = m_nCount + (m_nCount >> 1) + 32;
|
||||
Realloc(nOldAllocatedCount);
|
||||
}
|
||||
memmove(&m_pElements[nIndex + inc], &m_pElements[nIndex], (m_nCount - inc - nIndex) * sizeof(T));
|
||||
|
||||
return m_pElements[nIndex];
|
||||
}
|
||||
|
||||
void AddIndexNoCache(unsigned int inc)
|
||||
{
|
||||
m_nCount += inc;
|
||||
if (m_nCount > m_nAllocatedCount)
|
||||
{
|
||||
int nOldAllocatedCount = m_nAllocatedCount;
|
||||
m_nAllocatedCount = m_nCount;
|
||||
Realloc(nOldAllocatedCount);
|
||||
}
|
||||
}
|
||||
|
||||
void Add(const T& elem){AddElem(elem); }
|
||||
void AddElem(const T& elem)
|
||||
{
|
||||
unsigned int m = m_nCount;
|
||||
AddIndex(1);
|
||||
m_pElements[m] = elem;
|
||||
}
|
||||
void AddElemNoCache(const T& elem)
|
||||
{
|
||||
unsigned int m = m_nCount;
|
||||
AddIndexNoCache(1);
|
||||
m_pElements[m] = elem;
|
||||
}
|
||||
|
||||
int Find(const T& p)
|
||||
{
|
||||
for (unsigned int i = 0; i < m_nCount; i++)
|
||||
{
|
||||
if (p == (*this)[i])
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void Delete(unsigned int n){DelElem(n); }
|
||||
void DelElem(unsigned int n)
|
||||
{
|
||||
// memset(&m_pElements[n],0,sizeof(T));
|
||||
_Remove(n, 1);
|
||||
}
|
||||
|
||||
// Standard compliance interface
|
||||
//
|
||||
// This is for those who don't want to learn the non standard and
|
||||
// thus not very convenient interface of TArray, but are unlucky
|
||||
// enough not to be able to avoid using it.
|
||||
void clear(){Free(); }
|
||||
void resize(unsigned int nSize) { reserve(nSize); m_nCount = nSize; }
|
||||
void reserve(unsigned int nSize)
|
||||
{
|
||||
if (nSize > m_nAllocatedCount)
|
||||
{
|
||||
Alloc(nSize);
|
||||
}
|
||||
}
|
||||
unsigned size() const {return m_nCount; }
|
||||
unsigned capacity() const {return m_nAllocatedCount; }
|
||||
bool empty() const {return size() == 0; }
|
||||
void push_back (const T& rSample) {Add(rSample); }
|
||||
void pop_back () {m_nCount--; }
|
||||
void erase (T* pElem)
|
||||
{
|
||||
int n = int(pElem - m_pElements);
|
||||
assert(n >= 0 && n < m_nCount);
|
||||
_Remove(n, 1);
|
||||
}
|
||||
T* begin() {return m_pElements; }
|
||||
T* end() {return m_pElements + m_nCount; }
|
||||
T last() {return m_pElements[m_nCount - 1]; }
|
||||
const T* begin() const {return m_pElements; }
|
||||
const T* end() const {return m_pElements + m_nCount; }
|
||||
|
||||
int GetMemoryUsage() const { return (int)(m_nAllocatedCount * sizeof(T)); }
|
||||
};
|
||||
|
||||
template <class T>
|
||||
inline void Exchange(T& X, T& Y)
|
||||
{
|
||||
const T Tmp = X;
|
||||
X = Y;
|
||||
Y = Tmp;
|
||||
}
|
||||
|
||||
#endif // CRYINCLUDE_CRYCOMMON_TARRAY_H
|
||||
|
||||
@@ -1,141 +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.
|
||||
|
||||
// Generic unaligned memory access helpers.
|
||||
#pragma once
|
||||
#include <stddef.h>
|
||||
#include <type_traits>
|
||||
|
||||
namespace Detail
|
||||
{
|
||||
template<typename RealType, typename BlittedElement>
|
||||
struct Blitter
|
||||
{
|
||||
static_assert(std::is_trivial<BlittedElement>::value, "Blittable elements should be trivial (ie, integral types)");
|
||||
static_assert((std::alignment_of<BlittedElement>::value < std::alignment_of<RealType>::value), "Blittable memory has sufficient alignment, do not use unaligned store or load");
|
||||
static_assert(sizeof(RealType) > sizeof(BlittedElement), "Blittable element is larger than real type");
|
||||
static_assert((sizeof(RealType) % sizeof(BlittedElement)) == 0, "Blitted element has the wrong size for the real type");
|
||||
typedef std::integral_constant<size_t, sizeof(RealType) / sizeof(BlittedElement)> NumElements;
|
||||
|
||||
static void BlitLoad(const BlittedElement* pSource, RealType& target)
|
||||
{
|
||||
BlittedElement* pTarget = alias_cast<BlittedElement*>(&target);
|
||||
for (size_t i = 0; i < NumElements::value; ++i, ++pSource, ++pTarget)
|
||||
{
|
||||
* pTarget = *pSource;
|
||||
}
|
||||
}
|
||||
|
||||
static void BlitStore(const RealType& source, BlittedElement* pTarget)
|
||||
{
|
||||
const BlittedElement* pSource = alias_cast<const BlittedElement*>(&source);
|
||||
for (size_t i = 0; i < NumElements::value; ++i, ++pSource, ++pTarget)
|
||||
{
|
||||
* pTarget = *pSource;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Load RealType from unaligned memory using some blittable type.
|
||||
// The source memory must be suitably aligned for accessing BlittedElement.
|
||||
// If no memory alignment can be guaranteed, use char for BlittedElement.
|
||||
template<typename RealType, typename BlittedElement>
|
||||
inline void LoadUnaligned(const BlittedElement* pMemory, RealType& value,
|
||||
typename std::enable_if<(std::alignment_of<RealType>::value > std::alignment_of<BlittedElement>::value)>::type* = nullptr)
|
||||
{
|
||||
Detail::Blitter<RealType, BlittedElement>::BlitLoad(pMemory, value);
|
||||
}
|
||||
|
||||
// Load RealType from aligned memory (fallback overload).
|
||||
// This is used if there is no reason to call the blitter, because sufficient alignment is guaranteed by BlittedElement.
|
||||
template<typename RealType, typename BlittedElement>
|
||||
inline void LoadUnaligned(const BlittedElement* pMemory, RealType& value,
|
||||
typename std::enable_if<(std::alignment_of<RealType>::value <= std::alignment_of<BlittedElement>::value)>::type* = nullptr)
|
||||
{
|
||||
value = *alias_cast<RealType*>(pMemory);
|
||||
}
|
||||
|
||||
// Store to unaligned memory using some blittable type.
|
||||
// The target memory must be suitably aligned for accessing BlittedElement.
|
||||
// If no memory alignment can be guaranteed, use char for BlittedElement.
|
||||
template<typename RealType, typename BlittedElement>
|
||||
inline void StoreUnaligned(BlittedElement* pMemory, const RealType& value,
|
||||
typename std::enable_if<(std::alignment_of<RealType>::value > std::alignment_of<BlittedElement>::value)>::type* = nullptr)
|
||||
{
|
||||
Detail::Blitter<RealType, BlittedElement>::BlitStore(value, pMemory);
|
||||
}
|
||||
|
||||
// Store to aligned memory (fallback overload).
|
||||
// This is used if there is no reason to call the blitter, because sufficient alignment is guaranteed by BlittedElement.
|
||||
template<typename RealType, typename BlittedElement>
|
||||
inline void StoreUnaligned(BlittedElement* pMemory, const RealType& value,
|
||||
typename std::enable_if<(std::alignment_of<RealType>::value <= std::alignment_of<BlittedElement>::value)>::type* = nullptr)
|
||||
{
|
||||
*alias_cast<RealType*>(pMemory) = value;
|
||||
}
|
||||
|
||||
// Pads the given pointer to the next possible aligned location for RealType
|
||||
// Use this to ensure RealType can be referenced in some buffer of BlittedElement's, without using LoadUnaligned/StoreUnaligned
|
||||
template<typename RealType, typename BlittedElement>
|
||||
inline BlittedElement* AlignPointer(BlittedElement* pMemory,
|
||||
typename std::enable_if<(std::alignment_of<RealType>::value % std::alignment_of<BlittedElement>::value) == 0>::type* = nullptr)
|
||||
{
|
||||
const size_t align = std::alignment_of<RealType>::value;
|
||||
const size_t mask = align - 1;
|
||||
const size_t address = reinterpret_cast<size_t>(pMemory);
|
||||
const size_t offset = (align - (address & mask)) & mask;
|
||||
return pMemory + (offset / sizeof(BlittedElement));
|
||||
}
|
||||
|
||||
// Pads the given address to the next possible aligned location for RealType
|
||||
// Use this to ensure RealType can be referenced inside memory, without using LoadUnaligned/StoreUnaligned
|
||||
template<typename RealType>
|
||||
inline size_t AlignAddress(size_t address)
|
||||
{
|
||||
return reinterpret_cast<size_t>(AlignPointer<RealType>(reinterpret_cast<char*>(address)));
|
||||
}
|
||||
|
||||
// Provides aligned storage for T, optionally aligned at a specific boundary (default being the native alignment of T)
|
||||
// The specified T is not initialized automatically, use of placement new/delete is the user's responsibility
|
||||
template<typename T, size_t Align = std::alignment_of<T>::value>
|
||||
struct SUninitialized
|
||||
{
|
||||
typedef typename std::aligned_storage<sizeof(T), Align>::type Storage;
|
||||
Storage storage;
|
||||
|
||||
void DefaultConstruct()
|
||||
{
|
||||
new(static_cast<void*>(&storage))T();
|
||||
}
|
||||
|
||||
void CopyConstruct(const T& value)
|
||||
{
|
||||
new(static_cast<void*>(&storage))T(value);
|
||||
}
|
||||
|
||||
void MoveConstruct(T&& value)
|
||||
{
|
||||
new(static_cast<void*>(&storage))T(std::move(value));
|
||||
}
|
||||
|
||||
void Destruct()
|
||||
{
|
||||
alias_cast<T*>(&storage)->~T();
|
||||
}
|
||||
|
||||
operator T& ()
|
||||
{
|
||||
return *alias_cast<T*>(&storage);
|
||||
}
|
||||
};
|
||||
@@ -10,26 +10,16 @@
|
||||
#
|
||||
|
||||
set(FILES
|
||||
QTangent.h
|
||||
CryCommon.cpp
|
||||
Allocator.h
|
||||
FinalizingSpline.h
|
||||
IAudioInterfacesCommonData.h
|
||||
IAudioSystem.h
|
||||
IChunkFile.h
|
||||
ICmdLine.h
|
||||
IColorGradingController.h
|
||||
IConsole.h
|
||||
IEntityRenderState.h
|
||||
IEntityRenderState_info.cpp
|
||||
IFont.h
|
||||
IFunctorBase.h
|
||||
IFuncVariable.h
|
||||
IGem.h
|
||||
IGeneralMemoryHeap.h
|
||||
IGeomCache.h
|
||||
IImage.h
|
||||
IImageHandler.h
|
||||
IIndexedMesh.h
|
||||
IIndexedMesh_info.cpp
|
||||
ILevelSystem.h
|
||||
@@ -37,58 +27,40 @@ set(FILES
|
||||
LocalizationManagerBus.h
|
||||
LocalizationManagerBus.inl
|
||||
ILog.h
|
||||
ILZ4Decompressor.h
|
||||
IMaterial.h
|
||||
IMemory.h
|
||||
IMeshBaking.h
|
||||
IMiniLog.h
|
||||
IMovieSystem.h
|
||||
IPhysics.h
|
||||
IPhysicsDebugRenderer.h
|
||||
IPostEffectGroup.h
|
||||
IProcess.h
|
||||
IReadWriteXMLSink.h
|
||||
IRenderAuxGeom.h
|
||||
IRenderer.h
|
||||
IRenderMesh.h
|
||||
IResourceCollector.h
|
||||
IResourceManager.h
|
||||
ISerialize.h
|
||||
IShader.h
|
||||
IShader_info.h
|
||||
ISplines.h
|
||||
IStatObj.h
|
||||
StatObjBus.h
|
||||
IStereoRenderer.h
|
||||
IStreamEngine.h
|
||||
IStreamEngineDefs.h
|
||||
ISurfaceType.h
|
||||
ISystem.h
|
||||
ITextModeConsole.h
|
||||
ITexture.h
|
||||
ITimer.h
|
||||
IValidator.h
|
||||
IVideoRenderer.h
|
||||
IViewSystem.h
|
||||
IWindowMessageHandler.h
|
||||
IXml.h
|
||||
IZLibCompressor.h
|
||||
IZlibDecompressor.h
|
||||
IZStdDecompressor.h
|
||||
IProximityTriggerSystem.h
|
||||
MicrophoneBus.h
|
||||
physinterface.h
|
||||
HMDBus.h
|
||||
VRCommon.h
|
||||
StereoRendererBus.h
|
||||
HeightmapUpdateNotificationBus.h
|
||||
IObjManager.h
|
||||
INavigationSystem.h
|
||||
IMNM.h
|
||||
AzDXGIFormat.h
|
||||
SFunctor.h
|
||||
FunctorBaseFunction.h
|
||||
CustomMemoryHeap.h
|
||||
FunctorBaseMember.h
|
||||
stridedptr.h
|
||||
Options.h
|
||||
@@ -97,83 +69,52 @@ set(FILES
|
||||
CryRandomInternal.h
|
||||
Random.h
|
||||
LCGRandom.h
|
||||
MaterialUtils.h
|
||||
MTPseudoRandom.cpp
|
||||
CryTypeInfo.cpp
|
||||
BaseTypes.h
|
||||
CompileTimeAssert.h
|
||||
CryThreadSafeWorkerContainer.h
|
||||
CryThreadSafeRendererContainer.h
|
||||
intrusive_list.hpp
|
||||
MemoryAccess.h
|
||||
Algorithm.h
|
||||
AnimKey.h
|
||||
BitFiddling.h
|
||||
CGFContent.h
|
||||
CGFContent_info.cpp
|
||||
Common_TypeInfo.cpp
|
||||
CountedValue.h
|
||||
CrtDebugStats.h
|
||||
CryArray.h
|
||||
CryArray2d.h
|
||||
CryAssert.h
|
||||
CryCrc32.h
|
||||
CryCustomTypes.h
|
||||
CryFile.h
|
||||
CryFixedArray.h
|
||||
CryFixedString.h
|
||||
CryHeaders.h
|
||||
CryHeaders_info.cpp
|
||||
CryListenerSet.h
|
||||
CryMemoryAllocator.h
|
||||
CryMemoryManager.h
|
||||
CryLegacyAllocator.h
|
||||
CryName.h
|
||||
CryPath.h
|
||||
CryPodArray.h
|
||||
CryPtrArray.h
|
||||
CrySizer.h
|
||||
CryString.h
|
||||
CrySystemBus.h
|
||||
CryThread.h
|
||||
CryThreadImpl.h
|
||||
CryTypeInfo.h
|
||||
CryUtils.h
|
||||
CryVersion.h
|
||||
CryZlib.h
|
||||
FrameProfiler.h
|
||||
HashGrid.h
|
||||
HeapAllocator.h
|
||||
HeapContainer.h
|
||||
ImageExtensionHelper.cpp
|
||||
ImageExtensionHelper.h
|
||||
ImageExtensionHelper_info.h
|
||||
InplaceFactory.h
|
||||
LegacyAllocator.h
|
||||
MetaUtils.h
|
||||
MiniQueue.h
|
||||
MTPseudoRandom.h
|
||||
MultiThread.h
|
||||
MultiThread_Containers.h
|
||||
Name_TypeInfo.h
|
||||
NullAudioSystem.h
|
||||
PNoise3.h
|
||||
PoolAllocator.h
|
||||
primitives.h
|
||||
primitives_info.h
|
||||
ProjectDefines.h
|
||||
Range.h
|
||||
RenderContextConfig.h
|
||||
RingBuffer.h
|
||||
ScopeGuard.h
|
||||
ScopedVariableSetter.h
|
||||
SerializeFwd.h
|
||||
SimpleSerialize.h
|
||||
SmartPointersHelpers.h
|
||||
smartptr.h
|
||||
StackContainer.h
|
||||
STLGlobalAllocator.h
|
||||
STLPoolAllocator.h
|
||||
StlUtils.h
|
||||
StringUtils.h
|
||||
Synchronization.h
|
||||
@@ -183,7 +124,6 @@ set(FILES
|
||||
TimeValue_info.h
|
||||
TypeInfo_decl.h
|
||||
TypeInfo_impl.h
|
||||
UnalignedBlit.h
|
||||
UnicodeBinding.h
|
||||
UnicodeEncoding.h
|
||||
UnicodeFunctions.h
|
||||
@@ -194,16 +134,11 @@ set(FILES
|
||||
XMLBinaryHeaders.h
|
||||
RenderBus.h
|
||||
MainThreadRenderRequestBus.h
|
||||
OceanConstants.h
|
||||
PakLoadDataUtils.cpp
|
||||
PakLoadDataUtils.h
|
||||
TPool.h
|
||||
Cry_Matrix33.h
|
||||
Cry_Matrix34.h
|
||||
Cry_Matrix44.h
|
||||
Cry_MatrixDiag.h
|
||||
Cry_Vector4.h
|
||||
AABBSV.h
|
||||
Cry_Camera.h
|
||||
Cry_Color.h
|
||||
Cry_Geo.h
|
||||
@@ -217,14 +152,12 @@ set(FILES
|
||||
Cry_Vector3.h
|
||||
Cry_XOptimise.h
|
||||
CryHalf_info.h
|
||||
GeomQuery.h
|
||||
CryHalf.inl
|
||||
MathConversion.h
|
||||
Cry_HWMatrix.h
|
||||
Cry_HWVector3.h
|
||||
AndroidSpecific.h
|
||||
AppleSpecific.h
|
||||
Console_std.h
|
||||
CryAssert_Android.h
|
||||
CryAssert_impl.h
|
||||
CryAssert_iOS.h
|
||||
@@ -232,7 +165,6 @@ set(FILES
|
||||
CryAssert_Mac.h
|
||||
CryLibrary.cpp
|
||||
CryLibrary.h
|
||||
CryMemoryManager_impl.h
|
||||
CryThread_dummy.h
|
||||
CryThread_pthreads.h
|
||||
CryThread_windows.h
|
||||
@@ -341,6 +273,5 @@ set(FILES
|
||||
Maestro/Types/AssetBlends.h
|
||||
Maestro/Types/SequenceType.h
|
||||
StaticInstance.h
|
||||
Pak/CryPakUtils.h
|
||||
WinBase.cpp
|
||||
)
|
||||
|
||||
@@ -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 _INTRUSIVE_LIST_HPP
|
||||
#define _INTRUSIVE_LIST_HPP
|
||||
#if !defined(WIN32)
|
||||
#include <stdint.h>
|
||||
#endif //!defined(WIN32)
|
||||
|
||||
|
||||
namespace util
|
||||
{
|
||||
// Simple lightweight intrusive list utility
|
||||
//
|
||||
template<typename Host>
|
||||
struct list
|
||||
{
|
||||
typedef Host value_type;
|
||||
|
||||
list* next;
|
||||
list* prev;
|
||||
|
||||
// Default (initializing) constructor
|
||||
list()
|
||||
{
|
||||
next = this;
|
||||
prev = this;
|
||||
}
|
||||
|
||||
// Inserts this list into a given list item between
|
||||
// prev and next (note: they need to be sequential!)
|
||||
void insert(list* _prev, list* _next)
|
||||
{
|
||||
_next->prev = this;
|
||||
this->next = _next;
|
||||
this->prev = _prev;
|
||||
_prev->next = this;
|
||||
}
|
||||
|
||||
// Should only be called on heads
|
||||
void clear() { next = prev = this; }
|
||||
|
||||
// Removes from a list, then inserts this list item into a given list between
|
||||
// prev and next (note: they need to be sequential!)
|
||||
void re_insert(list* _prev, list* _next)
|
||||
{
|
||||
erase();
|
||||
insert(_prev, _next);
|
||||
}
|
||||
|
||||
|
||||
// Remove this list instance from a list
|
||||
// Safe to be called even if not attached to a list
|
||||
void erase()
|
||||
{
|
||||
next->prev = prev;
|
||||
prev->next = next;
|
||||
next = prev = this;
|
||||
}
|
||||
|
||||
// Predicate to determine if a list structure is linked to a list
|
||||
bool empty() const { return prev == this && next == this; }
|
||||
bool linked() const { return !empty(); }
|
||||
|
||||
// Get the host instance of the instrusive list
|
||||
template<list Host::* member>
|
||||
Host* item()
|
||||
{
|
||||
return ((Host*)((uintptr_t)(this) - (uintptr_t)(&(((Host*)0)->*member))));
|
||||
}
|
||||
template<list Host::* member>
|
||||
const Host* item() const
|
||||
{
|
||||
return ((Host*)((uintptr_t)(this) - (uintptr_t)(&(((Host*)0)->*member))));
|
||||
}
|
||||
template<list (Host::* Member)[2]>
|
||||
Host * item(int threadId)
|
||||
{
|
||||
uintptr_t value = (uintptr_t)this - (uintptr_t)&((((Host*)(NULL))->*Member)[threadId]);
|
||||
return alias_cast<Host*>(value);
|
||||
}
|
||||
|
||||
// Insert & relink functions
|
||||
void insert_tail(list* _list) { insert(_list->prev, _list); }
|
||||
void insert_tail(list& _list) { insert_tail(&_list); }
|
||||
void insert_head(list* _list) { insert(_list, _list->next); }
|
||||
void insert_head(list& _list) { insert_head(&_list); }
|
||||
void relink_tail(list* _list) { erase(); insert_tail(_list); }
|
||||
void relink_tail(list& _list) { relink_tail(&_list); }
|
||||
void relink_head(list* _list) { erase(); insert_head(_list); }
|
||||
void relink_head(list& _list) { relink_head(&_list); }
|
||||
|
||||
static inline void splice(const list* _list, list* prev, list* next)
|
||||
{
|
||||
list* first = _list->next;
|
||||
list* last = _list->prev;
|
||||
|
||||
first->prev = prev;
|
||||
prev->next = first;
|
||||
|
||||
last->next = next;
|
||||
next->prev = last;
|
||||
}
|
||||
|
||||
void splice_front(const list* _list)
|
||||
{
|
||||
if (!_list->empty())
|
||||
{
|
||||
splice(_list, this, this->next);
|
||||
_list->clear();
|
||||
}
|
||||
}
|
||||
|
||||
void splice_tail(list* _list)
|
||||
{
|
||||
if (!_list->empty())
|
||||
{
|
||||
splice(_list, this->prev, this);
|
||||
_list->clear();
|
||||
}
|
||||
}
|
||||
|
||||
// Accessors
|
||||
list<Host>* tail() { return prev; }
|
||||
const list<Host>* tail() const { return prev; }
|
||||
list<Host>* head() { return head; }
|
||||
const list<Host>* head() const { return head; }
|
||||
};
|
||||
|
||||
// utility to extract the host type of an intrusive list at compile time
|
||||
template<typename List>
|
||||
struct list_value_type
|
||||
{
|
||||
typedef typename List::value_type value_type;
|
||||
};
|
||||
|
||||
// Loops over the list in forward manner, pos will be of type list<T>*
|
||||
# define list_for_each(pos, head) \
|
||||
for (typeof(head)pos = (head)->next; pos != (head); \
|
||||
pos = pos->next)
|
||||
|
||||
// Loops over the list in backward manner, pos will be of type list<T>*
|
||||
# define list_for_each_backwards(pos, head) \
|
||||
for (typeof(head)pos = (head)->prev; pos != (head); \
|
||||
pos = pos->prev)
|
||||
|
||||
// Loops over the list in forward manner while safeguarding
|
||||
// against list removal during iteration. pos will be of type list<T>*
|
||||
# define list_for_each_safe(pos, head) \
|
||||
for (typeof(head)pos = (head)->next, n = pos->next; pos != (head); \
|
||||
pos = n, n = pos->next)
|
||||
|
||||
// Loops over the list in forward manner. pos will be of type list<T>*
|
||||
# define list_for_each_entry(pos, head, member) \
|
||||
for (util::list_value_type<typeof((head))>::value_type* pos = \
|
||||
(head)->next->item<member>(); \
|
||||
&(pos->*(member)) != &list; \
|
||||
pos = ((pos->*(member)).next->item<member>()))
|
||||
|
||||
// Loops over the list in forward manner while safeguarding against list
|
||||
// removal during iteratation. pos will be of type T*
|
||||
# define list_for_each_entry_safe(pos, head, member) \
|
||||
for (util::list_value_type<typeof((head))>::value_type* pos = \
|
||||
(head)->next->item<member>(), \
|
||||
* n = ((pos->*(member)).next->item<member>()); \
|
||||
&(pos->*(member)) != &list; \
|
||||
pos = n, n = ((n->*(member)).next->item<member>()))
|
||||
} // end namespace util
|
||||
#endif // ifndef _INTRUSIVE_LIST_HPP
|
||||
|
||||
@@ -479,15 +479,7 @@ ILINE DestinationType alias_cast(SourceType pPtr)
|
||||
return conv_union.pDst;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "CryMemoryManager.h"
|
||||
|
||||
// Memory manager breaks strdup
|
||||
// Use something higher level, like CryString
|
||||
#undef strdup
|
||||
#define strdup dont_use_strdup
|
||||
|
||||
#include "CryLegacyAllocator.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
#ifndef DEPRECATED
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
|
||||
#include <AzCore/Debug/Profiler.h>
|
||||
#include <AzCore/Debug/ProfileModuleInit.h>
|
||||
#include <AzCore/Memory/AllocatorManager.h>
|
||||
#include <AzCore/Module/Environment.h>
|
||||
|
||||
// Section dictionary
|
||||
@@ -194,11 +195,6 @@ void __stl_debug_message(const char* format_str, ...)
|
||||
#include <intrin.h>
|
||||
#endif
|
||||
|
||||
// If we use cry memory manager this should be also included in every module.
|
||||
#if defined(USING_CRY_MEMORY_MANAGER)
|
||||
#include <CryMemoryManager_impl.h>
|
||||
#endif
|
||||
|
||||
#if defined(APPLE) || defined(LINUX)
|
||||
#include "CryAssert_impl.h"
|
||||
#endif
|
||||
|
||||
@@ -1,50 +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_PRIMITIVES_INFO_H
|
||||
#define CRYINCLUDE_CRYCOMMON_PRIMITIVES_INFO_H
|
||||
#pragma once
|
||||
|
||||
#include "primitives.h"
|
||||
|
||||
STRUCT_INFO_TYPE_EMPTY(primitives::primitive)
|
||||
|
||||
STRUCT_INFO_BEGIN(primitives::box)
|
||||
STRUCT_BASE_INFO(primitives::primitive)
|
||||
STRUCT_VAR_INFO(Basis, TYPE_INFO(Matrix33))
|
||||
STRUCT_VAR_INFO(bOriented, TYPE_INFO(int))
|
||||
STRUCT_VAR_INFO(center, TYPE_INFO(Vec3))
|
||||
STRUCT_VAR_INFO(size, TYPE_INFO(Vec3))
|
||||
STRUCT_INFO_END(primitives::box)
|
||||
|
||||
STRUCT_INFO_BEGIN(primitives::sphere)
|
||||
STRUCT_BASE_INFO(primitives::primitive)
|
||||
STRUCT_VAR_INFO(center, TYPE_INFO(Vec3))
|
||||
STRUCT_VAR_INFO(r, TYPE_INFO(float))
|
||||
STRUCT_INFO_END(primitives::sphere)
|
||||
|
||||
STRUCT_INFO_BEGIN(primitives::cylinder)
|
||||
STRUCT_BASE_INFO(primitives::primitive)
|
||||
STRUCT_VAR_INFO(center, TYPE_INFO(Vec3))
|
||||
STRUCT_VAR_INFO(axis, TYPE_INFO(Vec3))
|
||||
STRUCT_VAR_INFO(r, TYPE_INFO(float))
|
||||
STRUCT_VAR_INFO(hh, TYPE_INFO(float))
|
||||
STRUCT_INFO_END(primitives::cylinder)
|
||||
|
||||
STRUCT_INFO_BEGIN(primitives::plane)
|
||||
STRUCT_BASE_INFO(primitives::primitive)
|
||||
STRUCT_VAR_INFO(n, TYPE_INFO(Vec3))
|
||||
STRUCT_VAR_INFO(origin, TYPE_INFO(Vec3))
|
||||
STRUCT_INFO_END(primitives::plane)
|
||||
|
||||
#endif // CRYINCLUDE_CRYCOMMON_PRIMITIVES_INFO_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
|
||||
@@ -1,516 +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 : Manage async pak files
|
||||
|
||||
|
||||
#include "CrySystem_precompiled.h"
|
||||
#include "AsyncPakManager.h"
|
||||
#include "System.h"
|
||||
#include "IStreamEngine.h"
|
||||
#include <AzFramework/Archive/Archive.h>
|
||||
#include <AzFramework/API/ApplicationAPI.h>
|
||||
#include "ResourceManager.h"
|
||||
|
||||
#define MEGA_BYTE 1024* 1024
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
string& CAsyncPakManager::SAsyncPak::GetStatus(string& status) const
|
||||
{
|
||||
switch (eState)
|
||||
{
|
||||
case STATE_UNLOADED:
|
||||
status = "Unloaded";
|
||||
break;
|
||||
case STATE_REQUESTED:
|
||||
status = "Requested";
|
||||
break;
|
||||
case STATE_REQUESTUNLOAD:
|
||||
status = "RequestUnload";
|
||||
break;
|
||||
case STATE_LOADED:
|
||||
status = "Loaded";
|
||||
break;
|
||||
default:
|
||||
status = "Unknown";
|
||||
break;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
CAsyncPakManager::CAsyncPakManager()
|
||||
{
|
||||
m_nTotalOpenLayerPakSize = 0;
|
||||
m_bRequestLayerUpdate = false;
|
||||
}
|
||||
|
||||
CAsyncPakManager::~CAsyncPakManager()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void CAsyncPakManager::Clear()
|
||||
{
|
||||
//float startTime = gEnv->pTimer->GetAsyncCurTime();
|
||||
|
||||
for (TPakMap::iterator it = m_paks.begin();
|
||||
it != m_paks.end(); ++it)
|
||||
{
|
||||
SAsyncPak& layerPak = it->second;
|
||||
if (layerPak.bStreaming)
|
||||
{
|
||||
// wait until finished
|
||||
layerPak.pReadStream->Abort();
|
||||
}
|
||||
|
||||
ReleaseData(&layerPak);
|
||||
}
|
||||
m_paks.clear();
|
||||
m_bRequestLayerUpdate = false;
|
||||
|
||||
assert(m_nTotalOpenLayerPakSize == 0);
|
||||
m_nTotalOpenLayerPakSize = 0;
|
||||
|
||||
//printf("CAsyncPakManager::Clear() %0.4f secs\n", gEnv->pTimer->GetAsyncCurTime() - startTime);
|
||||
}
|
||||
|
||||
void CAsyncPakManager::UnloadLevelLoadPaks()
|
||||
{
|
||||
for (TPakMap::iterator it = m_paks.begin();
|
||||
it != m_paks.end(); ++it)
|
||||
{
|
||||
SAsyncPak& layerPak = it->second;
|
||||
|
||||
if (layerPak.eLifeTime == SAsyncPak::LIFETIME_LOAD_ONLY)
|
||||
{
|
||||
if (layerPak.bStreaming)
|
||||
{
|
||||
// wait until finished
|
||||
layerPak.pReadStream->Abort();
|
||||
}
|
||||
|
||||
ReleaseData(&layerPak);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void CAsyncPakManager::ParseLayerPaks(const string& levelCachePath)
|
||||
{
|
||||
string layerPath = levelCachePath + "/"; // "/layers/";
|
||||
string search = layerPath + "*";
|
||||
auto pPak = gEnv->pCryPak;
|
||||
|
||||
|
||||
// allow this find first to actually touch the file system
|
||||
AZ::IO::ArchiveFileIterator fileIterator= pPak->FindFirst(search.c_str(), 0, true);
|
||||
|
||||
if (fileIterator)
|
||||
{
|
||||
do
|
||||
{
|
||||
if ((fileIterator.m_fileDesc.nAttrib & AZ::IO::FileDesc::Attribute::Subdirectory) == AZ::IO::FileDesc::Attribute::Subdirectory || fileIterator.m_filename == "." || fileIterator.m_filename == "..")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
string pakName(fileIterator.m_filename.data(), fileIterator.m_filename.size());
|
||||
size_t findPos = pakName.find_last_of('.');
|
||||
if (findPos == string::npos)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
string extension = pakName.substr(findPos + 1, pakName.size());
|
||||
if (extension != "pak")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
SAsyncPak layerPak;
|
||||
layerPak.layername = pakName.substr(0, findPos);
|
||||
layerPak.filename = layerPath + pakName;
|
||||
layerPak.nSize = pPak->FGetSize(layerPak.filename.c_str(), true); // allow to go to disc for this access
|
||||
layerPak.bClosePakOnRelease = true;
|
||||
|
||||
m_paks[layerPak.layername] = layerPak;
|
||||
} while (fileIterator = pPak->FindNext(fileIterator));
|
||||
|
||||
pPak->FindClose(fileIterator);
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void CAsyncPakManager::StartStreaming(SAsyncPak* pLayerPak)
|
||||
{
|
||||
StreamReadParams params;
|
||||
params.dwUserData = (DWORD_PTR) pLayerPak;
|
||||
params.nSize = 0;
|
||||
params.pBuffer = NULL;
|
||||
params.nFlags = IStreamEngine::FLAGS_FILE_ON_DISK;
|
||||
params.ePriority = estpIdle;
|
||||
|
||||
pLayerPak->pReadStream = gEnv->pSystem->GetStreamEngine()->StartRead(eStreamTaskTypePak, pLayerPak->filename.c_str(), this, ¶ms);
|
||||
|
||||
if (pLayerPak->pReadStream)
|
||||
{
|
||||
pLayerPak->bStreaming = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
pLayerPak->eState = SAsyncPak::STATE_UNLOADED;
|
||||
pLayerPak->pData.reset();
|
||||
}
|
||||
}
|
||||
|
||||
void CAsyncPakManager::ReleaseData(SAsyncPak* pLayerPak)
|
||||
{
|
||||
if (pLayerPak->eState == SAsyncPak::STATE_LOADED)
|
||||
{
|
||||
if (pLayerPak->bClosePakOnRelease)
|
||||
{
|
||||
gEnv->pCryPak->ClosePack(pLayerPak->filename.c_str(), 0);
|
||||
//printf("Unload pak from mem: %s\n", pLayerPak->filename.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
gEnv->pCryPak->LoadPakToMemory(pLayerPak->filename.c_str(), AZ::IO::IArchive::eInMemoryPakLocale_Unload);
|
||||
//printf("Close pak: %s\n", pLayerPak->filename.c_str());
|
||||
}
|
||||
|
||||
m_nTotalOpenLayerPakSize -= pLayerPak->nSize;
|
||||
}
|
||||
|
||||
if (pLayerPak->pData)
|
||||
{
|
||||
assert(pLayerPak->pData->use_count() == 1);
|
||||
}
|
||||
|
||||
assert((!pLayerPak->pData) || (pLayerPak->pData && pLayerPak->pData->use_count() == 1));
|
||||
pLayerPak->pData.reset();
|
||||
pLayerPak->eState = SAsyncPak::STATE_UNLOADED;
|
||||
|
||||
m_bRequestLayerUpdate = true;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool CAsyncPakManager::LoadLayerPak(const char* sLayerName)
|
||||
{
|
||||
// only load layer paks from valid files
|
||||
TPakMap::iterator findResult = m_paks.find(sLayerName);
|
||||
if (findResult != m_paks.end())
|
||||
{
|
||||
return LoadPak(findResult->second);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool CAsyncPakManager::LoadPakToMemAsync(const char* pPath, bool bLevelLoadOnly)
|
||||
{
|
||||
//check if pak reference exists
|
||||
TPakMap::iterator findResult = m_paks.find(pPath);
|
||||
if (findResult != m_paks.end())
|
||||
{
|
||||
return LoadPak(findResult->second);
|
||||
}
|
||||
else
|
||||
{
|
||||
char szFullPathBuf[AZ::IO::IArchive::MaxPath];
|
||||
const char* szFullPath = gEnv->pCryPak->AdjustFileName(pPath, szFullPathBuf, AZ_ARRAY_SIZE(szFullPathBuf), AZ::IO::IArchive::FOPEN_HINT_QUIET | AZ::IO::IArchive::FLAGS_PATH_REAL);
|
||||
|
||||
// Check if the pak file actually exists before trying to load
|
||||
if (!gEnv->pCryPak->IsFileExist(szFullPath, AZ::IO::IArchive::eFileLocation_Any))
|
||||
{
|
||||
// Cached file does not exist
|
||||
CryWarning(VALIDATOR_MODULE_SYSTEM, VALIDATOR_WARNING, "Level cache pak file %s does not exist", szFullPath);
|
||||
return false;
|
||||
}
|
||||
|
||||
SAsyncPak layerPak;
|
||||
layerPak.layername = pPath;
|
||||
layerPak.filename = szFullPathBuf;
|
||||
layerPak.nSize = 0;
|
||||
layerPak.eLifeTime = bLevelLoadOnly ? SAsyncPak::LIFETIME_LOAD_ONLY : SAsyncPak::LIFETIME_LEVEL_COMPLETE;
|
||||
|
||||
m_paks[layerPak.layername] = layerPak;
|
||||
|
||||
return LoadPak(m_paks[layerPak.layername]);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CAsyncPakManager::LoadPak(SAsyncPak& layerPak)
|
||||
{
|
||||
layerPak.nRequestCount++;
|
||||
if (layerPak.eState == SAsyncPak::STATE_LOADED || layerPak.bStreaming ||
|
||||
layerPak.eState == SAsyncPak::STATE_REQUESTED)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
layerPak.eState = SAsyncPak::STATE_REQUESTED;
|
||||
|
||||
//printf("Streaming level pak: %s\n", layerPak.layername.c_str());
|
||||
|
||||
StartStreaming(&layerPak);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void CAsyncPakManager::UnloadLayerPak(const char* sLayerName)
|
||||
{
|
||||
TPakMap::iterator findResult = m_paks.find(sLayerName);
|
||||
if (findResult == m_paks.end())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
SAsyncPak& layerPak = findResult->second;
|
||||
layerPak.nRequestCount--;
|
||||
assert(layerPak.nRequestCount >= 0);
|
||||
if (layerPak.nRequestCount > 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (layerPak.bStreaming)
|
||||
{
|
||||
if (layerPak.pReadStream)
|
||||
{
|
||||
layerPak.pReadStream->Abort();
|
||||
}
|
||||
layerPak.eState = SAsyncPak::STATE_REQUESTUNLOAD;
|
||||
return;
|
||||
}
|
||||
|
||||
if (layerPak.eState == SAsyncPak::STATE_LOADED)
|
||||
{
|
||||
ReleaseData(&layerPak);
|
||||
m_bRequestLayerUpdate = true;
|
||||
}
|
||||
|
||||
if (layerPak.eState == SAsyncPak::STATE_REQUESTED)
|
||||
{
|
||||
layerPak.eState = SAsyncPak::STATE_UNLOADED;
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void CAsyncPakManager::GetLayerPakStats(
|
||||
SLayerPakStats& stats, bool bCollectAllStats) const
|
||||
{
|
||||
stats.m_MaxSize = (g_cvars.archiveVars.nTotalInMemoryPakSizeLimit * MEGA_BYTE);
|
||||
stats.m_UsedSize = m_nTotalOpenLayerPakSize;
|
||||
|
||||
for (TPakMap::const_iterator it = m_paks.begin(); it != m_paks.end(); ++it)
|
||||
{
|
||||
const SAsyncPak& layerPak = it->second;
|
||||
if (bCollectAllStats || layerPak.eState != SAsyncPak::STATE_UNLOADED)
|
||||
{
|
||||
SLayerPakStats::SEntry entry;
|
||||
entry.name = it->first;
|
||||
entry.nSize = layerPak.nSize;
|
||||
entry.bStreaming = layerPak.bStreaming;
|
||||
layerPak.GetStatus(entry.status);
|
||||
|
||||
stats.m_entries.push_back(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void CAsyncPakManager::StreamAsyncOnComplete(
|
||||
IReadStream* pStream, unsigned nError)
|
||||
{
|
||||
if (nError != 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
SAsyncPak* pLayerPak = (SAsyncPak*) pStream->GetUserData();
|
||||
|
||||
//Check is pak is already open, if so, just assign mem
|
||||
if (gEnv->pCryPak->LoadPakToMemory(pLayerPak->filename.c_str(), AZ::IO::IArchive::eInMemoryPakLocale_GPU, pLayerPak->pData))
|
||||
{
|
||||
pLayerPak->bPakAlreadyOpen = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
bool usePrefabSystemForLevels = false;
|
||||
AzFramework::ApplicationRequests::Bus::BroadcastResult(
|
||||
usePrefabSystemForLevels,
|
||||
&AzFramework::ApplicationRequests::IsPrefabSystemForLevelsEnabled);
|
||||
|
||||
if (usePrefabSystemForLevels)
|
||||
{
|
||||
gEnv->pCryPak->OpenPack(
|
||||
"@assets@", {pLayerPak->filename.c_str(), pLayerPak->filename.size()}, AZ::IO::IArchive::FLAGS_FILENAMES_AS_CRC32, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// ugly hack - depending on the pak file pak may need special root info / open flags
|
||||
//
|
||||
if (pLayerPak->layername.find("level.pak") != string::npos)
|
||||
{
|
||||
gEnv->pCryPak->OpenPack(
|
||||
{pLayerPak->filename.c_str(), pLayerPak->filename.size()}, AZ::IO::IArchive::FLAGS_FILENAMES_AS_CRC32, NULL);
|
||||
}
|
||||
else if (pLayerPak->layername.find("levelshadercache.pak") != string::npos)
|
||||
{
|
||||
gEnv->pCryPak->OpenPack(
|
||||
"@assets@", {pLayerPak->filename.c_str(), pLayerPak->filename.size()}, AZ::IO::IArchive::FLAGS_PATH_REAL, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
gEnv->pCryPak->OpenPack(
|
||||
"@assets@", {pLayerPak->filename.c_str(), pLayerPak->filename.size()}, AZ::IO::IArchive::FLAGS_FILENAMES_AS_CRC32,
|
||||
NULL);
|
||||
}
|
||||
}
|
||||
gEnv->pCryPak->LoadPakToMemory(pLayerPak->filename.c_str(), AZ::IO::IArchive::eInMemoryPakLocale_GPU, pLayerPak->pData);
|
||||
}
|
||||
|
||||
pLayerPak->eState = SAsyncPak::STATE_LOADED;
|
||||
|
||||
//printf("Finished streaming level pak: %s\n", pLayerPak->layername.c_str());
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void CAsyncPakManager::StreamOnComplete(
|
||||
IReadStream* pStream, unsigned nError)
|
||||
{
|
||||
SAsyncPak* pLayerPak = (SAsyncPak*) pStream->GetUserData();
|
||||
|
||||
if (nError != 0)
|
||||
{
|
||||
ReleaseData(pLayerPak);
|
||||
}
|
||||
|
||||
pLayerPak->bStreaming = false;
|
||||
pLayerPak->pReadStream = NULL;
|
||||
|
||||
m_bRequestLayerUpdate = true;
|
||||
}
|
||||
|
||||
void* CAsyncPakManager::StreamOnNeedStorage(IReadStream* pStream, unsigned nSize, bool& bAbortOnFailToAlloc)
|
||||
{
|
||||
SAsyncPak* pAsyncPak = (SAsyncPak*)pStream->GetUserData();
|
||||
|
||||
pAsyncPak->nSize = nSize;
|
||||
|
||||
if ((m_nTotalOpenLayerPakSize + nSize) > (size_t)(g_cvars.archiveVars.nTotalInMemoryPakSizeLimit * MEGA_BYTE))
|
||||
{
|
||||
CryWarning(VALIDATOR_MODULE_SYSTEM, VALIDATOR_WARNING, "Not enough space to load in memory layer pak %s (Current: %" PRISIZE_T " Required: %d)",
|
||||
pAsyncPak->filename.c_str(), m_nTotalOpenLayerPakSize, nSize);
|
||||
|
||||
//printf("Not enough space to load in memory layer pak %s (Current: %d Required: %d)\n", pAsyncPak->filename.c_str(), m_nTotalOpenLayerPakSize, nSize);
|
||||
|
||||
pAsyncPak->eState = SAsyncPak::STATE_UNLOADED;
|
||||
pAsyncPak->bStreaming = false;
|
||||
pAsyncPak->pReadStream = NULL;
|
||||
|
||||
bAbortOnFailToAlloc = true;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (nSize)
|
||||
{
|
||||
auto pCryPak = static_cast<AZ::IO::Archive*>(gEnv->pCryPak);
|
||||
|
||||
// allocate the data
|
||||
const char* szUsage = "In Memory Zip File";
|
||||
pAsyncPak->pData = pCryPak->PoolAllocMemoryBlock(nSize, szUsage, alignof(uint8_t));
|
||||
|
||||
m_nTotalOpenLayerPakSize += nSize;
|
||||
|
||||
return pAsyncPak->pData->m_address.get();
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void CAsyncPakManager::Update()
|
||||
{
|
||||
if (!m_bRequestLayerUpdate)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m_bRequestLayerUpdate = false;
|
||||
|
||||
for (TPakMap::iterator it = m_paks.begin();
|
||||
it != m_paks.end(); ++it)
|
||||
{
|
||||
SAsyncPak& layerPak = it->second;
|
||||
if (!layerPak.bStreaming)
|
||||
{
|
||||
if (layerPak.eState == SAsyncPak::STATE_REQUESTUNLOAD)
|
||||
{
|
||||
// done streaming and not interested in it anymore, then release it again
|
||||
ReleaseData(&layerPak);
|
||||
}
|
||||
else if (layerPak.eState == SAsyncPak::STATE_REQUESTED &&
|
||||
(m_nTotalOpenLayerPakSize + layerPak.nSize <= ((size_t)g_cvars.archiveVars.nTotalInMemoryPakSizeLimit * MEGA_BYTE)))
|
||||
{
|
||||
// do we have enough memory now to start streaming the pak
|
||||
StartStreaming(&layerPak);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Abort streaming jobs and prevent any more requests
|
||||
// Paks which are loaded remain, they will be cleaned up as usual
|
||||
void CAsyncPakManager::CancelPendingJobs()
|
||||
{
|
||||
for (TPakMap::iterator it = m_paks.begin(); it != m_paks.end(); ++it)
|
||||
{
|
||||
SAsyncPak& layerPak = it->second;
|
||||
|
||||
if (layerPak.bStreaming)
|
||||
{
|
||||
layerPak.pReadStream->Abort();
|
||||
ReleaseData(&layerPak);
|
||||
|
||||
//printf("Pak %s Aborted\n", layerPak.filename.c_str());
|
||||
}
|
||||
else if (layerPak.eState == SAsyncPak::STATE_REQUESTED)
|
||||
{
|
||||
layerPak.eState = SAsyncPak::STATE_UNLOADED;
|
||||
ReleaseData(&layerPak);
|
||||
|
||||
//printf("Pak %s Cancelled\n", layerPak.filename.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
@@ -1,116 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
// Description : Manage async pak files
|
||||
|
||||
#ifndef CRYINCLUDE_CRYSYSTEM_ASYNCPAKMANAGER_H
|
||||
#define CRYINCLUDE_CRYSYSTEM_ASYNCPAKMANAGER_H
|
||||
#pragma once
|
||||
|
||||
#include <AzCore/std/smart_ptr/intrusive_ptr.h>
|
||||
#include <IResourceManager.h>
|
||||
#include <IStreamEngine.h>
|
||||
|
||||
namespace AZ::IO
|
||||
{
|
||||
struct MemoryBlock;
|
||||
}
|
||||
|
||||
class CAsyncPakManager
|
||||
: public IStreamCallback
|
||||
{
|
||||
protected:
|
||||
|
||||
struct SAsyncPak
|
||||
{
|
||||
enum EState
|
||||
{
|
||||
STATE_UNLOADED,
|
||||
STATE_REQUESTED,
|
||||
STATE_REQUESTUNLOAD,
|
||||
STATE_LOADED,
|
||||
};
|
||||
|
||||
enum ELifeTime
|
||||
{
|
||||
LIFETIME_LOAD_ONLY,
|
||||
LIFETIME_LEVEL_COMPLETE,
|
||||
LIFETIME_PERMANENT
|
||||
};
|
||||
|
||||
SAsyncPak()
|
||||
: nRequestCount(0)
|
||||
, eState(STATE_UNLOADED)
|
||||
, eLifeTime(LIFETIME_LOAD_ONLY)
|
||||
, nSize(0)
|
||||
, pData(0)
|
||||
, bStreaming(false)
|
||||
, bPakAlreadyOpen(false)
|
||||
, bClosePakOnRelease(false)
|
||||
, pReadStream(0) {}
|
||||
|
||||
string& GetStatus(string&) const;
|
||||
|
||||
string layername;
|
||||
string filename;
|
||||
size_t nSize;
|
||||
AZStd::intrusive_ptr<AZ::IO::MemoryBlock> pData;
|
||||
EState eState;
|
||||
ELifeTime eLifeTime;
|
||||
bool bStreaming;
|
||||
bool bPakAlreadyOpen;
|
||||
bool bClosePakOnRelease;
|
||||
int nRequestCount;
|
||||
IReadStreamPtr pReadStream;
|
||||
};
|
||||
typedef std::map<string, SAsyncPak> TPakMap;
|
||||
|
||||
public:
|
||||
|
||||
CAsyncPakManager();
|
||||
~CAsyncPakManager();
|
||||
|
||||
void ParseLayerPaks(const string& levelCachePath);
|
||||
|
||||
bool LoadPakToMemAsync(const char* pPath, bool bLevelLoadOnly);
|
||||
void UnloadLevelLoadPaks();
|
||||
bool LoadLayerPak(const char* sLayerName);
|
||||
void UnloadLayerPak(const char* sLayerName);
|
||||
void CancelPendingJobs();
|
||||
|
||||
void GetLayerPakStats(SLayerPakStats& stats, bool bCollectAllStats) const;
|
||||
|
||||
void Clear();
|
||||
void Update();
|
||||
|
||||
protected:
|
||||
|
||||
bool LoadPak(SAsyncPak& layerPak);
|
||||
|
||||
void StartStreaming(SAsyncPak* pLayerPak);
|
||||
void ReleaseData(SAsyncPak* pLayerPak);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// IStreamCallback interface implementation.
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
virtual void StreamAsyncOnComplete (IReadStream* pStream, unsigned nError);
|
||||
virtual void StreamOnComplete (IReadStream* pStream, unsigned nError);
|
||||
virtual void* StreamOnNeedStorage(IReadStream* pStream, unsigned nSize, bool& bAbortOnFailToAlloc);
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TPakMap m_paks;
|
||||
size_t m_nTotalOpenLayerPakSize;
|
||||
bool m_bRequestLayerUpdate;
|
||||
};
|
||||
|
||||
#endif // CRYINCLUDE_CRYSYSTEM_ASYNCPAKMANAGER_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
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user