merge 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,173 +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 __animtime_h__
|
||||
#define __animtime_h__
|
||||
|
||||
#include <IXml.h>
|
||||
#include <AzCore/Casting/numeric_cast.h>
|
||||
#include <Serialization/IArchive.h>
|
||||
|
||||
struct SAnimTime
|
||||
{
|
||||
static const uint numTicksPerSecond = 6000;
|
||||
|
||||
// List of possible frame rates (dividers of 6000). Most commonly used ones first.
|
||||
enum EFrameRate
|
||||
{
|
||||
// Common
|
||||
eFrameRate_30fps, eFrameRate_60fps, eFrameRate_120fps,
|
||||
|
||||
// Possible
|
||||
eFrameRate_10fps, eFrameRate_12fps, eFrameRate_15fps, eFrameRate_24fps,
|
||||
eFrameRate_25fps, eFrameRate_40fps, eFrameRate_48fps, eFrameRate_50fps,
|
||||
eFrameRate_75fps, eFrameRate_80fps, eFrameRate_100fps, eFrameRate_125fps,
|
||||
eFrameRate_150fps, eFrameRate_200fps, eFrameRate_240fps, eFrameRate_250fps,
|
||||
eFrameRate_300fps, eFrameRate_375fps, eFrameRate_400fps, eFrameRate_500fps,
|
||||
eFrameRate_600fps, eFrameRate_750fps, eFrameRate_1000fps, eFrameRate_1200fps,
|
||||
eFrameRate_1500fps, eFrameRate_2000fps, eFrameRate_3000fps, eFrameRate_6000fps,
|
||||
|
||||
eFrameRate_Num
|
||||
};
|
||||
|
||||
SAnimTime()
|
||||
: m_ticks(0) {}
|
||||
explicit SAnimTime(int32 ticks)
|
||||
: m_ticks(ticks) {}
|
||||
explicit SAnimTime(float time)
|
||||
: m_ticks(aznumeric_caster(std::lround(static_cast<double>(time) * numTicksPerSecond))) {}
|
||||
|
||||
static uint GetFrameRateValue(EFrameRate frameRate)
|
||||
{
|
||||
const uint frameRateValues[eFrameRate_Num] =
|
||||
{
|
||||
// Common
|
||||
30, 60, 120,
|
||||
|
||||
// Possible
|
||||
10, 12, 15, 24, 25, 40, 48, 50, 75, 80, 100, 125,
|
||||
150, 200, 240, 250, 300, 375, 400, 500, 600, 750,
|
||||
1000, 1200, 1500, 2000, 3000, 6000
|
||||
};
|
||||
|
||||
return frameRateValues[frameRate];
|
||||
}
|
||||
|
||||
static const char* GetFrameRateName(EFrameRate frameRate)
|
||||
{
|
||||
const char* frameRateNames[eFrameRate_Num] =
|
||||
{
|
||||
// Common
|
||||
"30 fps", "60 fps", "120 fps",
|
||||
|
||||
// Possible
|
||||
"10 fps", "12 fps", "15 fps", "24 fps",
|
||||
"25 fps", "40 fps", "48 fps", "50 fps",
|
||||
"75 fps", "80 fps", "100 fps", "125 fps",
|
||||
"150 fps", "200 fps", "240 fps", "250 fps",
|
||||
"300 fps", "375 fps", "400 fps", "500 fps",
|
||||
"600 fps", "750 fps", "1000 fps", "1200 fps",
|
||||
"1500 fps", "2000 fps", "3000 fps", "6000 fps"
|
||||
};
|
||||
|
||||
return frameRateNames[frameRate];
|
||||
}
|
||||
|
||||
float ToFloat() const { return static_cast<float>(m_ticks) / numTicksPerSecond; }
|
||||
|
||||
void Serialize(Serialization::IArchive& ar)
|
||||
{
|
||||
ar(m_ticks, "ticks", "Ticks");
|
||||
}
|
||||
|
||||
// Helper to serialize from ticks or old float time
|
||||
void Serialize(XmlNodeRef keyNode, bool bLoading, const char* pName, const char* pLegacyName)
|
||||
{
|
||||
if (bLoading)
|
||||
{
|
||||
int32 ticks;
|
||||
if (!keyNode->getAttr(pName, ticks))
|
||||
{
|
||||
// Backwards compatibility
|
||||
float time = 0.0f;
|
||||
keyNode->getAttr(pLegacyName, time);
|
||||
*this = SAnimTime(time);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ticks = ticks;
|
||||
}
|
||||
}
|
||||
else if (m_ticks > 0)
|
||||
{
|
||||
keyNode->setAttr(pName, m_ticks);
|
||||
}
|
||||
}
|
||||
|
||||
int32 GetTicks() const { return m_ticks; }
|
||||
|
||||
static SAnimTime Min() { SAnimTime minTime; minTime.m_ticks = std::numeric_limits<int32>::lowest(); return minTime; }
|
||||
static SAnimTime Max() { SAnimTime maxTime; maxTime.m_ticks = (std::numeric_limits<int32>::max)(); return maxTime; }
|
||||
|
||||
SAnimTime operator-() const { return SAnimTime(-m_ticks); }
|
||||
SAnimTime operator-(SAnimTime r) const { SAnimTime temp = *this; temp.m_ticks -= r.m_ticks; return temp; }
|
||||
SAnimTime operator+(SAnimTime r) const { SAnimTime temp = *this; temp.m_ticks += r.m_ticks; return temp; }
|
||||
SAnimTime operator*(SAnimTime r) const { SAnimTime temp = *this; temp.m_ticks *= r.m_ticks; return temp; }
|
||||
SAnimTime operator/(SAnimTime r) const { SAnimTime temp; temp.m_ticks = static_cast<int32>((static_cast<int64>(m_ticks) * numTicksPerSecond) / r.m_ticks); return temp; }
|
||||
SAnimTime operator%(SAnimTime r) const { SAnimTime temp = *this; temp.m_ticks %= r.m_ticks; return temp; }
|
||||
SAnimTime operator*(float r) const { SAnimTime temp; temp.m_ticks = aznumeric_caster(std::lround(static_cast<double>(m_ticks) * r)); return temp; }
|
||||
SAnimTime operator/(float r) const { SAnimTime temp; temp.m_ticks = aznumeric_caster(std::lround(static_cast<double>(m_ticks) / r)); return temp; }
|
||||
SAnimTime& operator+=(SAnimTime r) { *this = *this + r; return *this; }
|
||||
SAnimTime& operator-=(SAnimTime r) { *this = *this - r; return *this; }
|
||||
SAnimTime& operator*=(SAnimTime r) { *this = *this * r; return *this; }
|
||||
SAnimTime& operator/=(SAnimTime r) { *this = *this / r; return *this; }
|
||||
SAnimTime& operator%=(SAnimTime r) { *this = *this % r; return *this; }
|
||||
SAnimTime& operator*=(float r) { *this = *this * r; return *this; }
|
||||
SAnimTime& operator/=(float r) { *this = *this / r; return *this; }
|
||||
|
||||
bool operator<(SAnimTime r) const { return m_ticks < r.m_ticks; }
|
||||
bool operator<=(SAnimTime r) const { return m_ticks <= r.m_ticks; }
|
||||
bool operator>(SAnimTime r) const { return m_ticks > r.m_ticks; }
|
||||
bool operator>=(SAnimTime r) const { return m_ticks >= r.m_ticks; }
|
||||
bool operator==(SAnimTime r) const { return m_ticks == r.m_ticks; }
|
||||
bool operator!=(SAnimTime r) const { return m_ticks != r.m_ticks; }
|
||||
|
||||
// Snap to nearest multiple of given frame rate
|
||||
SAnimTime SnapToNearest(const EFrameRate frameRate)
|
||||
{
|
||||
const int sign = sgn(m_ticks);
|
||||
const int32 absTicks = abs(m_ticks);
|
||||
|
||||
const int framesMod = numTicksPerSecond / GetFrameRateValue(frameRate);
|
||||
const int32 remainder = absTicks % framesMod;
|
||||
const bool bNextMultiple = remainder >= (framesMod / 2);
|
||||
return SAnimTime(sign * ((absTicks - remainder) + (bNextMultiple ? framesMod : 0)));
|
||||
}
|
||||
|
||||
private:
|
||||
int32 m_ticks;
|
||||
|
||||
friend bool Serialize(Serialization::IArchive& ar, SAnimTime& animTime, const char* name, const char* label);
|
||||
};
|
||||
|
||||
inline bool Serialize(Serialization::IArchive& ar, SAnimTime& animTime, const char* name, const char* label)
|
||||
{
|
||||
return ar(animTime.m_ticks, name, label);
|
||||
}
|
||||
|
||||
inline SAnimTime abs(SAnimTime time)
|
||||
{
|
||||
return (time >= SAnimTime(0)) ? time : -time;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -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,321 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
#ifndef __BEZIER_H__
|
||||
#define __BEZIER_H__
|
||||
|
||||
#include <AnimTime.h>
|
||||
#include <Serialization/IArchive.h>
|
||||
#include <Serialization/Math.h>
|
||||
|
||||
struct SBezierControlPoint
|
||||
{
|
||||
SBezierControlPoint()
|
||||
: m_value(0.0f)
|
||||
, m_inTangent(ZERO)
|
||||
, m_outTangent(ZERO)
|
||||
, m_inTangentType(eTangentType_Auto)
|
||||
, m_outTangentType(eTangentType_Auto)
|
||||
, m_bBreakTangents(false)
|
||||
{
|
||||
}
|
||||
|
||||
enum ETangentType
|
||||
{
|
||||
eTangentType_Custom,
|
||||
eTangentType_Auto,
|
||||
eTangentType_Zero,
|
||||
eTangentType_Step,
|
||||
eTangentType_Linear,
|
||||
};
|
||||
|
||||
void Serialize(Serialization::IArchive& ar)
|
||||
{
|
||||
ar(m_value, "value", "Value");
|
||||
|
||||
if (ar.IsOutput())
|
||||
{
|
||||
bool breakTangents = m_bBreakTangents;
|
||||
ar(breakTangents, "breakTangents", "Break Tangents");
|
||||
}
|
||||
else
|
||||
{
|
||||
bool breakTangents = false;
|
||||
ar(breakTangents, "breakTangents", "Break Tangents");
|
||||
m_bBreakTangents = breakTangents;
|
||||
}
|
||||
|
||||
if (ar.IsOutput())
|
||||
{
|
||||
ETangentType inTangentType = m_inTangentType;
|
||||
ar(inTangentType, "inTangentType", "Incoming tangent type");
|
||||
}
|
||||
else
|
||||
{
|
||||
ETangentType inTangentType = eTangentType_Auto;
|
||||
ar(inTangentType, "inTangentType", "Incoming tangent type");
|
||||
m_inTangentType = inTangentType;
|
||||
}
|
||||
|
||||
ar(m_inTangent, "inTangent", (m_inTangentType == eTangentType_Custom) ? "Incoming Tangent" : NULL);
|
||||
|
||||
if (ar.IsOutput())
|
||||
{
|
||||
ETangentType outTangentType = m_outTangentType;
|
||||
ar(outTangentType, "outTangentType", "Outgoing tangent type");
|
||||
}
|
||||
else
|
||||
{
|
||||
ETangentType outTangentType = eTangentType_Auto;
|
||||
ar(outTangentType, "outTangentType", "Outgoing tangent type");
|
||||
m_outTangentType = outTangentType;
|
||||
}
|
||||
|
||||
ar(m_outTangent, "outTangent", (m_outTangentType == eTangentType_Custom) ? "Outgoing Tangent" : NULL);
|
||||
}
|
||||
|
||||
float m_value;
|
||||
|
||||
// For 1D Bezier only the Y component is used
|
||||
Vec2 m_inTangent;
|
||||
Vec2 m_outTangent;
|
||||
|
||||
ETangentType m_inTangentType : 4;
|
||||
ETangentType m_outTangentType : 4;
|
||||
bool m_bBreakTangents : 1;
|
||||
};
|
||||
|
||||
struct SBezierKey
|
||||
{
|
||||
SBezierKey()
|
||||
: m_time(0) {}
|
||||
|
||||
void Serialize(Serialization::IArchive& ar)
|
||||
{
|
||||
ar(m_time, "time", "Time");
|
||||
ar(m_controlPoint, "controlPoint", "Control Point");
|
||||
}
|
||||
|
||||
SAnimTime m_time;
|
||||
SBezierControlPoint m_controlPoint;
|
||||
};
|
||||
|
||||
namespace Bezier
|
||||
{
|
||||
inline float Evaluate(float t, float p0, float p1, float p2, float p3)
|
||||
{
|
||||
const float a = 1 - t;
|
||||
const float aSq = a * a;
|
||||
const float tSq = t * t;
|
||||
return (aSq * a * p0) + (3.0f * aSq * t * p1) + (3.0f * a * tSq * p2) + (tSq * t * p3);
|
||||
}
|
||||
|
||||
inline float EvaluateDeriv(float t, float p0, float p1, float p2, float p3)
|
||||
{
|
||||
const float a = 1 - t;
|
||||
const float ta = t * a;
|
||||
const float aSq = a * a;
|
||||
const float tSq = t * t;
|
||||
return 3.0f * ((-p2 * tSq) + (p3 * tSq) - (p0 * aSq) + (p1 * aSq) + 2.0f * ((-p1 * ta) + (p2 * ta)));
|
||||
}
|
||||
|
||||
inline float EvaluateX(const float t, const float duration, const SBezierControlPoint& start, const SBezierControlPoint& end)
|
||||
{
|
||||
const float p0 = 0.0f;
|
||||
const float p1 = p0 + start.m_outTangent.x;
|
||||
const float p3 = duration;
|
||||
const float p2 = p3 + end.m_inTangent.x;
|
||||
return Evaluate(t, p0, p1, p2, p3);
|
||||
}
|
||||
|
||||
inline float EvaluateY(const float t, const SBezierControlPoint& start, const SBezierControlPoint& end)
|
||||
{
|
||||
const float p0 = start.m_value;
|
||||
const float p1 = p0 + start.m_outTangent.y;
|
||||
const float p3 = end.m_value;
|
||||
const float p2 = p3 + end.m_inTangent.y;
|
||||
return Evaluate(t, p0, p1, p2, p3);
|
||||
}
|
||||
|
||||
// Duration = (time at end key) - (time at start key)
|
||||
inline float EvaluateDerivX(const float t, const float duration, const SBezierControlPoint& start, const SBezierControlPoint& end)
|
||||
{
|
||||
const float p0 = 0.0f;
|
||||
const float p1 = p0 + start.m_outTangent.x;
|
||||
const float p3 = duration;
|
||||
const float p2 = p3 + end.m_inTangent.x;
|
||||
return EvaluateDeriv(t, p0, p1, p2, p3);
|
||||
}
|
||||
|
||||
inline float EvaluateDerivY(const float t, const SBezierControlPoint& start, const SBezierControlPoint& end)
|
||||
{
|
||||
const float p0 = start.m_value;
|
||||
const float p1 = p0 + start.m_outTangent.y;
|
||||
const float p3 = end.m_value;
|
||||
const float p2 = p3 + end.m_inTangent.y;
|
||||
return EvaluateDeriv(t, p0, p1, p2, p3);
|
||||
}
|
||||
|
||||
// Find interpolation factor where 2D bezier curve has the given x value. Works only for curves where x is monotonically increasing.
|
||||
// The passed x must be in range [0, duration]. Uses the Newton-Raphson root finding method. Usually takes 2 or 3 iterations.
|
||||
//
|
||||
// Note: This is for "1D" 2D bezier curves as used in TrackView. The curves are restricted by the curve editor to be monotonically increasing.
|
||||
//
|
||||
inline float InterpolationFactorFromX(const float x, const float duration, const SBezierControlPoint& start, const SBezierControlPoint& end)
|
||||
{
|
||||
float t = (x / duration);
|
||||
|
||||
const float epsilon = 0.00001f;
|
||||
const uint maxSteps = 10;
|
||||
|
||||
for (uint i = 0; i < maxSteps; ++i)
|
||||
{
|
||||
const float currentX = EvaluateX(t, duration, start, end) - x;
|
||||
if (fabs(currentX) <= epsilon)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
const float currentXDeriv = EvaluateDerivX(t, duration, start, end);
|
||||
t -= currentX / currentXDeriv;
|
||||
}
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
inline SBezierControlPoint CalculateInTangent(
|
||||
float time, const SBezierControlPoint& point,
|
||||
float leftTime, const SBezierControlPoint* pLeftPoint,
|
||||
float rightTime, const SBezierControlPoint* pRightPoint)
|
||||
{
|
||||
SBezierControlPoint newPoint = point;
|
||||
|
||||
// In tangent X can never be positive
|
||||
newPoint.m_inTangent.x = std::min(point.m_inTangent.x, 0.0f);
|
||||
|
||||
if (pLeftPoint)
|
||||
{
|
||||
switch (point.m_inTangentType)
|
||||
{
|
||||
case SBezierControlPoint::eTangentType_Custom:
|
||||
{
|
||||
// Need to clamp tangent if it is reaching over last point
|
||||
const float deltaTime = time - leftTime;
|
||||
if (deltaTime < -newPoint.m_inTangent.x)
|
||||
{
|
||||
if (newPoint.m_inTangent.x == 0)
|
||||
{
|
||||
newPoint.m_inTangent = Vec2(ZERO);
|
||||
}
|
||||
else
|
||||
{
|
||||
float scaleFactor = deltaTime / -newPoint.m_inTangent.x;
|
||||
newPoint.m_inTangent.x = -deltaTime;
|
||||
newPoint.m_inTangent.y *= scaleFactor;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SBezierControlPoint::eTangentType_Zero:
|
||||
// Fall through. Zero for y is same as Auto, x is set to 0.0f
|
||||
case SBezierControlPoint::eTangentType_Auto:
|
||||
{
|
||||
const SBezierControlPoint& rightPoint = pRightPoint ? *pRightPoint : point;
|
||||
const float deltaTime = (pRightPoint ? rightTime : time) - leftTime;
|
||||
if (deltaTime > 0.0f)
|
||||
{
|
||||
const float ratio = (time - leftTime) / deltaTime;
|
||||
const float deltaValue = rightPoint.m_value - pLeftPoint->m_value;
|
||||
const bool bIsZeroTangent = (point.m_inTangentType == SBezierControlPoint::eTangentType_Zero);
|
||||
newPoint.m_inTangent = Vec2(-(deltaTime * ratio) / 3.0f, bIsZeroTangent ? 0.0f : -(deltaValue * ratio) / 3.0f);
|
||||
}
|
||||
else
|
||||
{
|
||||
newPoint.m_inTangent = Vec2(ZERO);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SBezierControlPoint::eTangentType_Linear:
|
||||
newPoint.m_inTangent = Vec2((leftTime - time) / 3.0f,
|
||||
(pLeftPoint->m_value - point.m_value) / 3.0f);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return newPoint;
|
||||
}
|
||||
|
||||
inline SBezierControlPoint CalculateOutTangent(
|
||||
float time, const SBezierControlPoint& point,
|
||||
float leftTime, const SBezierControlPoint* pLeftPoint,
|
||||
float rightTime, const SBezierControlPoint* pRightPoint)
|
||||
{
|
||||
SBezierControlPoint newPoint = point;
|
||||
|
||||
// Out tangent X can never be negative
|
||||
newPoint.m_outTangent.x = std::max(point.m_outTangent.x, 0.0f);
|
||||
|
||||
if (pRightPoint)
|
||||
{
|
||||
switch (point.m_outTangentType)
|
||||
{
|
||||
case SBezierControlPoint::eTangentType_Custom:
|
||||
{
|
||||
// Need to clamp tangent if it is reaching over next point
|
||||
const float deltaTime = rightTime - time;
|
||||
if (deltaTime < newPoint.m_outTangent.x)
|
||||
{
|
||||
if (newPoint.m_outTangent.x == 0)
|
||||
{
|
||||
newPoint.m_outTangent = Vec2(ZERO);
|
||||
}
|
||||
else
|
||||
{
|
||||
float scaleFactor = deltaTime / newPoint.m_outTangent.x;
|
||||
newPoint.m_outTangent.x = deltaTime;
|
||||
newPoint.m_outTangent.y *= scaleFactor;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SBezierControlPoint::eTangentType_Zero:
|
||||
// Fall through. Zero for y is same as Auto, x is set to 0.0f
|
||||
case SBezierControlPoint::eTangentType_Auto:
|
||||
{
|
||||
const SBezierControlPoint& leftPoint = pLeftPoint ? *pLeftPoint : point;
|
||||
const float deltaTime = rightTime - (pLeftPoint ? leftTime : time);
|
||||
if (deltaTime > 0.0f)
|
||||
{
|
||||
const float ratio = (rightTime - time) / deltaTime;
|
||||
const float deltaValue = pRightPoint->m_value - leftPoint.m_value;
|
||||
const bool bIsZeroTangent = (point.m_outTangentType == SBezierControlPoint::eTangentType_Zero);
|
||||
newPoint.m_outTangent = Vec2((deltaTime * ratio) / 3.0f, bIsZeroTangent ? 0.0f : (deltaValue * ratio) / 3.0f);
|
||||
}
|
||||
else
|
||||
{
|
||||
newPoint.m_outTangent = Vec2(ZERO);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SBezierControlPoint::eTangentType_Linear:
|
||||
newPoint.m_outTangent = Vec2((rightTime - time) / 3.0f,
|
||||
(pRightPoint->m_value - point.m_value) / 3.0f);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return newPoint;
|
||||
}
|
||||
}
|
||||
|
||||
#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)
|
||||
@@ -9,58 +9,15 @@
|
||||
# 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_pal_tool_dirs(pal_tool_dirs ${CMAKE_CURRENT_LIST_DIR}/Platform)
|
||||
|
||||
ly_add_target(
|
||||
NAME CryCommon STATIC
|
||||
NAMESPACE Legacy
|
||||
FILES_CMAKE
|
||||
crycommon_files.cmake
|
||||
${pal_dir}/crycommon_${PAL_PLATFORM_NAME_LOWERCASE}_files.cmake
|
||||
PLATFORM_INCLUDE_FILES
|
||||
${pal_dir}/crycommon_${PAL_PLATFORM_NAME_LOWERCASE}.cmake
|
||||
INCLUDE_DIRECTORIES
|
||||
PUBLIC
|
||||
. # Lots of code without CryCommon/
|
||||
.. # Dangerous since exports CryEngine's path (client code can do CrySystem/ without depending on that target)
|
||||
${pal_dir}
|
||||
${pal_tool_dirs}
|
||||
BUILD_DEPENDENCIES
|
||||
PUBLIC
|
||||
AZ::AzCore
|
||||
AZ::AzFramework
|
||||
)
|
||||
|
||||
ly_add_target(
|
||||
NAME CryCommon.EngineSettings.Static STATIC
|
||||
NAMESPACE Legacy
|
||||
FILES_CMAKE
|
||||
crycommon_enginesettings_files.cmake
|
||||
${pal_dir}/crycommon_enginesettings_${PAL_PLATFORM_NAME_LOWERCASE}_files.cmake
|
||||
INCLUDE_DIRECTORIES
|
||||
PUBLIC
|
||||
.
|
||||
${pal_dir}
|
||||
BUILD_DEPENDENCIES
|
||||
PUBLIC
|
||||
AZ::AzCore
|
||||
AZ::AzFramework
|
||||
)
|
||||
|
||||
ly_add_target(
|
||||
NAME CryCommon.EngineSettings.RC.Static STATIC
|
||||
NAMESPACE Legacy
|
||||
FILES_CMAKE
|
||||
crycommon_enginesettings_files.cmake
|
||||
${pal_dir}/crycommon_enginesettings_${PAL_PLATFORM_NAME_LOWERCASE}_files.cmake
|
||||
INCLUDE_DIRECTORIES
|
||||
PUBLIC
|
||||
.
|
||||
${pal_dir}
|
||||
COMPILE_DEFINITIONS
|
||||
PRIVATE
|
||||
RESOURCE_COMPILER
|
||||
BUILD_DEPENDENCIES
|
||||
PUBLIC
|
||||
AZ::AzCore
|
||||
|
||||
@@ -1,158 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
#ifndef __CREBASECLOUD_H__
|
||||
#define __CREBASECLOUD_H__
|
||||
|
||||
//================================================================================
|
||||
|
||||
class SCloudParticle
|
||||
{
|
||||
public:
|
||||
inline SCloudParticle();
|
||||
inline SCloudParticle(const Vec3& vPos, float fRadius, const ColorF& baseColor, float fTransparency = 0);
|
||||
inline SCloudParticle(const Vec3& vPos, float fRadiusX, float fRadiusY, float fRotMin, float fRotMax, Vec2 vUV[]);
|
||||
inline ~SCloudParticle();
|
||||
|
||||
float GetRadiusX() const { return m_fSize[0]; }
|
||||
float GetRadiusY() const { return m_fSize[1]; }
|
||||
float GetTransparency() const { return m_fTransparency; }
|
||||
const Vec3& GetPosition() const { return m_vPosition; }
|
||||
const ColorF& GetBaseColor() const { return m_vBaseColor; }
|
||||
uint32 GetNumLitColors() const { return m_vLitColors.size(); }
|
||||
inline const ColorF GetLitColor(unsigned int index) const;
|
||||
float GetSquareSortDistance() const { return m_fSquareSortDistance; }
|
||||
|
||||
//! Sets the radius of the particle.
|
||||
void SetRadiusX(float rad) { m_fSize[0] = rad; }
|
||||
void SetRadiusY(float rad) { m_fSize[1] = rad; }
|
||||
void SetTransparency(float trans) { m_fTransparency = trans; }
|
||||
void SetPosition(const Vec3& pos) { m_vPosition = pos; }
|
||||
void SetBaseColor(const ColorF& col) { m_vBaseColor = col; }
|
||||
void AddLitColor(const ColorF& col) { m_vLitColors.push_back(col); }
|
||||
void ClearLitColors() { m_vLitColors.clear(); }
|
||||
void SetSquareSortDistance(float fSquareDistance) { m_fSquareSortDistance = fSquareDistance; }
|
||||
|
||||
bool operator<(const SCloudParticle& p) const
|
||||
{
|
||||
return (m_fSquareSortDistance < p.m_fSquareSortDistance);
|
||||
}
|
||||
|
||||
bool operator>(const SCloudParticle& p) const
|
||||
{
|
||||
return (m_fSquareSortDistance > p.m_fSquareSortDistance);
|
||||
}
|
||||
|
||||
protected:
|
||||
float m_fTransparency;
|
||||
Vec3 m_vPosition;
|
||||
float m_fSize[2];
|
||||
float m_fRotMin;
|
||||
float m_fRotMax;
|
||||
ColorF m_vBaseColor;
|
||||
TArray<ColorF> m_vLitColors;
|
||||
Vec3 m_vEye;
|
||||
|
||||
// for sorting particles during shading
|
||||
float m_fSquareSortDistance;
|
||||
public:
|
||||
Vec2 m_vUV[2];
|
||||
};
|
||||
|
||||
inline SCloudParticle::SCloudParticle()
|
||||
{
|
||||
m_fSize[0] = 0;
|
||||
m_fTransparency = 0;
|
||||
m_vPosition = Vec3(0, 0, 0);
|
||||
m_vBaseColor = Col_Black;
|
||||
m_vEye = Vec3(0, 0, 0);
|
||||
m_fSquareSortDistance = 0;
|
||||
|
||||
m_vLitColors.clear();
|
||||
}
|
||||
|
||||
inline SCloudParticle::SCloudParticle(const Vec3& pos, float fRadius, const ColorF& baseColor, float fTransparency)
|
||||
{
|
||||
m_fSize[0] = fRadius;
|
||||
m_fSize[1] = fRadius;
|
||||
m_fTransparency = fTransparency;
|
||||
m_vPosition = pos;
|
||||
m_vBaseColor = baseColor;
|
||||
m_vUV[0] = Vec2(0, 0);
|
||||
m_vUV[1] = Vec2(1, 1);
|
||||
|
||||
m_fRotMin = 0;
|
||||
m_fRotMax = 0;
|
||||
m_vEye = Vec3(0, 0, 0);
|
||||
m_fSquareSortDistance = 0;
|
||||
|
||||
m_vLitColors.clear();
|
||||
}
|
||||
|
||||
inline SCloudParticle::SCloudParticle(const Vec3& vPos, float fRadiusX, float fRadiusY, float fRotMin, float fRotMax, Vec2 vUV[2])
|
||||
{
|
||||
m_fSize[0] = fRadiusX;
|
||||
m_fSize[1] = fRadiusY;
|
||||
m_vPosition = vPos;
|
||||
m_vBaseColor = Col_White;
|
||||
m_vUV[0] = vUV[0];
|
||||
m_vUV[1] = vUV[1];
|
||||
m_fRotMin = fRotMin;
|
||||
m_fRotMax = fRotMax;
|
||||
|
||||
m_fTransparency = 1.0f;
|
||||
m_vEye = Vec3(0, 0, 0);
|
||||
m_fSquareSortDistance = 0;
|
||||
|
||||
m_vLitColors.clear();
|
||||
}
|
||||
|
||||
inline SCloudParticle::~SCloudParticle()
|
||||
{
|
||||
m_vLitColors.clear();
|
||||
}
|
||||
|
||||
inline const ColorF SCloudParticle::GetLitColor(unsigned int index) const
|
||||
{
|
||||
if (index <= m_vLitColors.size())
|
||||
{
|
||||
return m_vLitColors[index];
|
||||
}
|
||||
else
|
||||
{
|
||||
return Col_Black;
|
||||
}
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
class CREBaseCloud
|
||||
: public CRendElementBase
|
||||
{
|
||||
friend class CRECloud;
|
||||
|
||||
public:
|
||||
CREBaseCloud()
|
||||
: CRendElementBase()
|
||||
{
|
||||
mfSetType(eDATA_Cloud);
|
||||
mfUpdateFlags(FCEF_TRANSFORM);
|
||||
}
|
||||
virtual void SetParticles(SCloudParticle* pParticles, int nNumParticles) = 0;
|
||||
|
||||
virtual void GetMemoryUsage(ICrySizer* pSizer) const
|
||||
{
|
||||
pSizer->AddObject(this, sizeof(*this));
|
||||
}
|
||||
};
|
||||
|
||||
#endif // __CREBASECLOUD_H__
|
||||
@@ -1,66 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
#ifndef _CREFOGVOLUME_
|
||||
#define _CREFOGVOLUME_
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "VertexFormats.h"
|
||||
|
||||
|
||||
struct IFogVolumeRenderNode;
|
||||
|
||||
|
||||
class CREFogVolume
|
||||
: public CRendElementBase
|
||||
{
|
||||
public:
|
||||
CREFogVolume();
|
||||
|
||||
virtual ~CREFogVolume();
|
||||
virtual void mfPrepare(bool bCheckOverflow);
|
||||
virtual bool mfDraw(CShader* ef, SShaderPass* sfm);
|
||||
|
||||
virtual void GetMemoryUsage(ICrySizer* pSizer) const
|
||||
{
|
||||
pSizer->AddObject(this, sizeof(*this));
|
||||
}
|
||||
|
||||
Vec3 m_center;
|
||||
uint32 m_viewerInsideVolume : 1;
|
||||
uint32 m_affectsThisAreaOnly : 1;
|
||||
uint32 m_stencilRef : 8;
|
||||
uint32 m_volumeType : 1;
|
||||
uint32 m_reserved : 21;
|
||||
AABB m_localAABB;
|
||||
Matrix34 m_matWSInv;
|
||||
float m_globalDensity;
|
||||
float m_densityOffset;
|
||||
float m_nearCutoff;
|
||||
Vec2 m_softEdgesLerp;
|
||||
ColorF m_fogColor; // color already combined with fHDRDynamic
|
||||
Vec3 m_heightFallOffDirScaled;
|
||||
Vec3 m_heightFallOffBasePoint;
|
||||
Vec3 m_eyePosInWS;
|
||||
Vec3 m_eyePosInOS;
|
||||
Vec3 m_rampParams;
|
||||
Vec3 m_windOffset;
|
||||
float m_noiseScale;
|
||||
Vec3 m_noiseFreq;
|
||||
float m_noiseOffset;
|
||||
float m_noiseElapsedTime;
|
||||
Vec3 m_scale;
|
||||
};
|
||||
|
||||
|
||||
#endif // #ifndef _CREFOGVOLUME_
|
||||
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
#ifndef _CREGameEffect_
|
||||
#define _CREGameEffect_
|
||||
|
||||
#pragma once
|
||||
|
||||
//==================================================================================================
|
||||
// Name: IREGameEffect
|
||||
// Desc: Interface for game effect render elements, designed to be instantiated in game code, and
|
||||
// called from the CREGameEffect within the engine. This then allows render elements
|
||||
// to be created in game code as well as in the engine.
|
||||
// Author: James Chilvers
|
||||
//==================================================================================================
|
||||
struct IREGameEffect
|
||||
{
|
||||
virtual ~IREGameEffect(){}
|
||||
|
||||
virtual void mfPrepare(bool bCheckOverflow) = 0;
|
||||
virtual bool mfDraw(CShader* ef, SShaderPass* sfm, CRenderObject* renderObj) = 0;
|
||||
};//------------------------------------------------------------------------------------------------
|
||||
|
||||
//==================================================================================================
|
||||
// Name: CREGameEffect
|
||||
// Desc: Render element that uses the IREGameEffect interface for its functionality
|
||||
// Author: James Chilvers
|
||||
//==================================================================================================
|
||||
class CREGameEffect
|
||||
: public CRendElementBase
|
||||
{
|
||||
public:
|
||||
|
||||
CREGameEffect();
|
||||
~CREGameEffect();
|
||||
|
||||
// CRendElementBase interface
|
||||
void mfPrepare(bool bCheckOverflow);
|
||||
bool mfDraw(CShader* ef, SShaderPass* sfm);
|
||||
|
||||
// CREGameEffect interface
|
||||
inline void SetPrivateImplementation(IREGameEffect* pImpl) { m_pImpl = pImpl; }
|
||||
inline IREGameEffect* GetPrivateImplementation() const { return m_pImpl; }
|
||||
|
||||
virtual void GetMemoryUsage(ICrySizer* pSizer) const
|
||||
{
|
||||
pSizer->AddObject(this, sizeof(*this));
|
||||
}
|
||||
private:
|
||||
|
||||
IREGameEffect* m_pImpl; // Implementation of of render element
|
||||
};//------------------------------------------------------------------------------------------------
|
||||
|
||||
#endif // #ifndef _CREGameEffect_
|
||||
@@ -1,95 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
// Description : Backend part of geometry cache rendering
|
||||
|
||||
#ifndef CRYINCLUDE_CRYCOMMON_CREGEOMCACHE_H
|
||||
#define CRYINCLUDE_CRYCOMMON_CREGEOMCACHE_H
|
||||
#pragma once
|
||||
|
||||
#if defined(USE_GEOM_CACHES)
|
||||
|
||||
#include "../RenderDll/Common/Shaders/Vertex.h"
|
||||
#include <CryCommon/StaticInstance.h>
|
||||
|
||||
class CREGeomCache
|
||||
: public CRendElementBase
|
||||
{
|
||||
public:
|
||||
struct SMeshInstance
|
||||
{
|
||||
AABB m_aabb;
|
||||
Matrix34 m_matrix;
|
||||
Matrix34 m_prevMatrix;
|
||||
};
|
||||
|
||||
struct SMeshRenderData
|
||||
{
|
||||
DynArray<SMeshInstance> m_instances;
|
||||
_smart_ptr<IRenderMesh> m_pRenderMesh;
|
||||
};
|
||||
|
||||
struct UpdateList
|
||||
{
|
||||
CryCriticalSection m_mutex;
|
||||
AZStd::vector<CREGeomCache*, AZ::AZStdAlloc<CryLegacySTLAllocator>> m_geoms;
|
||||
};
|
||||
|
||||
public:
|
||||
CREGeomCache();
|
||||
~CREGeomCache();
|
||||
|
||||
bool Update(const int flags, const bool bTesselation);
|
||||
static void UpdateModified();
|
||||
|
||||
// CRendElementBase interface
|
||||
virtual bool mfUpdate(int Flags, bool bTessellation);
|
||||
virtual void mfPrepare(bool bCheckOverflow);
|
||||
virtual bool mfDraw(CShader* ef, SShaderPass* sfm);
|
||||
|
||||
// CREGeomCache interface
|
||||
virtual void InitializeRenderElement(const uint numMeshes, _smart_ptr<IRenderMesh>* pMeshes, uint16 materialId);
|
||||
virtual void SetupMotionBlur(CRenderObject* pRenderObject, const SRenderingPassInfo& passInfo);
|
||||
|
||||
virtual volatile int* SetAsyncUpdateState(int& threadId);
|
||||
virtual DynArray<SMeshRenderData>* GetMeshFillDataPtr();
|
||||
virtual DynArray<SMeshRenderData>* GetRenderDataPtr();
|
||||
virtual void DisplayFilledBuffer(const int threadId);
|
||||
|
||||
|
||||
AZ::Vertex::Format GetVertexFormat() const override;
|
||||
bool GetGeometryInfo(SGeometryInfo &streams) override;
|
||||
|
||||
private:
|
||||
uint16 m_materialId;
|
||||
volatile bool m_bUpdateFrame[2];
|
||||
volatile int m_transformUpdateState[2];
|
||||
|
||||
// We use a double buffered m_meshFillData array for input from the main thread. When data
|
||||
// was successfully sent from the main thread it gets copied to m_meshRenderData
|
||||
// This simplifies the cases where frame data is missing, e.g. meshFillData is not updated for a frame
|
||||
// Note that meshFillData really needs to be double buffered because the copy occurs in render thread
|
||||
// so the next main thread could already be touching the data again
|
||||
//
|
||||
// Note: m_meshRenderData is directly accessed for ray intersections via GetRenderDataPtr.
|
||||
// This is safe, because it's only used in editor.
|
||||
DynArray<SMeshRenderData> m_meshFillData[2];
|
||||
DynArray<SMeshRenderData> m_meshRenderData;
|
||||
|
||||
static StaticInstance<UpdateList> sm_updateList[2]; // double buffered update lists
|
||||
|
||||
AZ::Vertex::Format m_geomCacheVertexFormat;
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif // CRYINCLUDE_CRYCOMMON_CREGEOMCACHE_H
|
||||
@@ -1,194 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <IRenderer.h>
|
||||
#include "Cry_Camera.h"
|
||||
|
||||
//================================================================================
|
||||
|
||||
struct SDynTexture2;
|
||||
struct SDynTexture;
|
||||
class IDynTexture;
|
||||
class CameraViewParameters;
|
||||
|
||||
struct IImposterRenderElement
|
||||
{
|
||||
virtual void GetMemoryUsage(ICrySizer* pSizer) const = 0;
|
||||
virtual void mfPrepare(bool bCheckOverflow) = 0;
|
||||
virtual bool mfDraw(CShader* ef, SShaderPass* sl) = 0;
|
||||
virtual const SMinMaxBox& mfGetWorldSpaceBounds() = 0;
|
||||
|
||||
virtual bool IsSplit() = 0;
|
||||
virtual bool IsScreenImposter() = 0;
|
||||
|
||||
virtual float GetRadiusX() = 0;
|
||||
virtual float GetRadiusY() = 0;
|
||||
virtual Vec3* GetQuadCorners() = 0;
|
||||
virtual Vec3 GetNearPoint() = 0;
|
||||
virtual Vec3 GetFarPoint() = 0;
|
||||
virtual float GetErrorToleranceCosAngle() = 0;
|
||||
virtual uint32 GetState() = 0;
|
||||
virtual int GetAlphaRef() = 0;
|
||||
virtual ColorF GetColorHelper() = 0;
|
||||
virtual Vec3 GetLastSunDirection() = 0;
|
||||
virtual uint8 GetLastBestEdge() = 0;
|
||||
virtual float GetNear() = 0;
|
||||
virtual float GetFar() = 0;
|
||||
virtual float GetTransparency() = 0;
|
||||
virtual Vec3 GetPosition();
|
||||
virtual int GetLogResolutionX() = 0;
|
||||
virtual int GetLogResolutionY() = 0;
|
||||
virtual CameraViewParameters& GetLastViewParameters() = 0;
|
||||
virtual IDynTexture* GetTexture() = 0;
|
||||
virtual IDynTexture* GetScreenTexture() = 0;
|
||||
virtual IDynTexture* GetFrontTexture() = 0;
|
||||
virtual IDynTexture* GetDepthTexture() = 0;
|
||||
virtual const SMinMaxBox& GetWorldSpaceBounds() = 0;
|
||||
|
||||
virtual void SetBBox(const Vec3& min, const Vec3& max) = 0;
|
||||
virtual void SetScreenImposterState(bool state) = 0;
|
||||
virtual void SetState(uint32 state) = 0;
|
||||
virtual void SetAlphaRef(uint32 ref) = 0;
|
||||
virtual void SetPosition(Vec3 pos) = 0;
|
||||
virtual void SetFrameResetValue(int frameResetValue) = 0;
|
||||
virtual void SetTexture(IDynTexture* texture) = 0;
|
||||
virtual void SetScreenTexture(IDynTexture* texture) = 0;
|
||||
virtual void SetFrontTexture(IDynTexture* texture) = 0;
|
||||
virtual void SetDepthTexture(IDynTexture* texture) = 0;
|
||||
};
|
||||
|
||||
class CREImposter
|
||||
: public CRendElementBase
|
||||
{
|
||||
friend class CRECloud;
|
||||
static IDynTexture* m_pScreenTexture;
|
||||
|
||||
CameraViewParameters m_LastViewParameters;
|
||||
bool m_bScreenImposter;
|
||||
bool m_bSplit;
|
||||
float m_fRadiusX;
|
||||
float m_fRadiusY;
|
||||
Vec3 m_vQuadCorners[4]; // in world space, relative to m_vPos, in clockwise order, can be rotated
|
||||
Vec3 m_vNearPoint;
|
||||
Vec3 m_vFarPoint;
|
||||
int m_nLogResolutionX;
|
||||
int m_nLogResolutionY;
|
||||
IDynTexture* m_pTexture;
|
||||
IDynTexture* m_pFrontTexture;
|
||||
IDynTexture* m_pTextureDepth;
|
||||
float m_fErrorToleranceCosAngle; // cosine of m_fErrorToleranceAngle used to check if IsImposterValid
|
||||
SMinMaxBox m_WorldSpaceBV;
|
||||
uint32 m_State;
|
||||
int m_AlphaRef;
|
||||
float m_fCurTransparency;
|
||||
ColorF m_ColorHelper;
|
||||
Vec3 m_vPos;
|
||||
Vec3 m_vLastSunDir;
|
||||
uint8 m_nLastBestEdge; // 0..11 this edge is favored to not jitter between different edges
|
||||
float m_fNear;
|
||||
float m_fFar;
|
||||
|
||||
bool IsImposterValid(const CameraViewParameters& viewParameters, float fRadiusX, float fRadiusY, float fCamRadiusX, float fCamRadiusY,
|
||||
const int iRequiredLogResX, const int iRequiredLogResY, const uint32 dwBestEdge);
|
||||
|
||||
bool Display(bool bDisplayFrontOfSplit);
|
||||
|
||||
public:
|
||||
int m_nFrameReset;
|
||||
int m_FrameUpdate;
|
||||
float m_fTimeUpdate;
|
||||
|
||||
static int m_MemUpdated;
|
||||
static int m_MemPostponed;
|
||||
static int m_PrevMemUpdated;
|
||||
static int m_PrevMemPostponed;
|
||||
|
||||
CREImposter()
|
||||
: CRendElementBase()
|
||||
, m_pTexture(NULL)
|
||||
, m_pFrontTexture(NULL)
|
||||
, m_pTextureDepth(NULL)
|
||||
, m_bSplit(false)
|
||||
, m_fRadiusX(0)
|
||||
, m_fRadiusY(0)
|
||||
, m_fErrorToleranceCosAngle(cos(DEG2RAD(0.25f)))
|
||||
, m_bScreenImposter(false)
|
||||
, m_State(GS_DEPTHWRITE)
|
||||
, m_AlphaRef(-1)
|
||||
, m_fCurTransparency(1.0f)
|
||||
, m_FrameUpdate(0)
|
||||
, m_nFrameReset(0)
|
||||
, m_fTimeUpdate(0)
|
||||
, m_vLastSunDir(0, 0, 0)
|
||||
, m_nLogResolutionX(0)
|
||||
, m_nLogResolutionY(0)
|
||||
, m_nLastBestEdge(0)
|
||||
{
|
||||
mfSetType(eDATA_Imposter);
|
||||
mfUpdateFlags(FCEF_TRANSFORM);
|
||||
m_ColorHelper = Col_White;
|
||||
}
|
||||
virtual ~CREImposter()
|
||||
{
|
||||
ReleaseResources();
|
||||
}
|
||||
|
||||
bool UpdateImposter();
|
||||
void ReleaseResources();
|
||||
|
||||
bool PrepareForUpdate();
|
||||
|
||||
virtual void GetMemoryUsage(ICrySizer* pSizer) const
|
||||
{
|
||||
pSizer->AddObject(this, sizeof(*this));
|
||||
}
|
||||
virtual void mfPrepare(bool bCheckOverflow);
|
||||
virtual bool mfDraw(CShader* ef, SShaderPass* sl);
|
||||
const SMinMaxBox& mfGetWorldSpaceBounds() { return m_WorldSpaceBV; }
|
||||
|
||||
virtual bool IsSplit() { return m_bSplit; }
|
||||
virtual bool IsScreenImposter() { return m_bScreenImposter; }
|
||||
|
||||
virtual float GetRadiusX() { return m_fRadiusX; }
|
||||
virtual float GetRadiusY() { return m_fRadiusY; }
|
||||
virtual Vec3* GetQuadCorners() { return &m_vQuadCorners[0]; }
|
||||
virtual Vec3 GetNearPoint() { return m_vNearPoint; }
|
||||
virtual Vec3 GetFarPoint() { return m_vFarPoint; }
|
||||
virtual float GetErrorToleranceCosAngle() { return m_fErrorToleranceCosAngle; }
|
||||
virtual uint32 GetState() { return m_State; }
|
||||
virtual int GetAlphaRef() { return m_AlphaRef; }
|
||||
virtual ColorF GetColorHelper() { return m_ColorHelper; }
|
||||
virtual Vec3 GetLastSunDirection() { return m_vLastSunDir; }
|
||||
virtual uint8 GetLastBestEdge() { return m_nLastBestEdge; }
|
||||
virtual float GetNear() { return m_fNear; }
|
||||
virtual float GetFar() { return m_fFar; }
|
||||
virtual float GetTransparency() { return m_fCurTransparency; }
|
||||
virtual Vec3 GetPosition();
|
||||
virtual int GetLogResolutionX() { return m_nLogResolutionX; }
|
||||
virtual int GetLogResolutionY() { return m_nLogResolutionY; }
|
||||
virtual CameraViewParameters& GetLastViewParameters() { return m_LastViewParameters; }
|
||||
virtual IDynTexture** GetTexture() { return &m_pTexture; }
|
||||
virtual IDynTexture** GetScreenTexture() { return &m_pScreenTexture; }
|
||||
virtual IDynTexture** GetFrontTexture() { return &m_pFrontTexture; }
|
||||
virtual IDynTexture** GetDepthTexture() { return &m_pTextureDepth; }
|
||||
virtual const SMinMaxBox& GetWorldSpaceBounds() { return m_WorldSpaceBV; }
|
||||
virtual int GetFrameReset() { return m_nFrameReset; }
|
||||
virtual void SetBBox(const Vec3& min, const Vec3& max) { m_WorldSpaceBV.SetMin(min); m_WorldSpaceBV.SetMax(max); }
|
||||
virtual void SetScreenImposterState(bool state) { m_bScreenImposter = state; }
|
||||
virtual void SetState(uint32 state) { m_State = state; }
|
||||
virtual void SetAlphaRef(uint32 ref) { m_AlphaRef = ref; }
|
||||
virtual void SetPosition(Vec3 pos) { m_vPos = pos; }
|
||||
virtual void SetFrameResetValue(int frameResetValue) { m_nFrameReset = frameResetValue; }
|
||||
};
|
||||
@@ -1,57 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
#ifndef __CREMESH_H__
|
||||
#define __CREMESH_H__
|
||||
|
||||
class CREMesh
|
||||
: public CRendElementBase
|
||||
{
|
||||
public:
|
||||
|
||||
struct CRenderChunk* m_pChunk;
|
||||
class CRenderMesh* m_pRenderMesh;
|
||||
|
||||
// Copy of Chunk to avoid indirections
|
||||
int32 m_nFirstIndexId;
|
||||
int32 m_nNumIndices;
|
||||
|
||||
uint32 m_nFirstVertId;
|
||||
uint32 m_nNumVerts;
|
||||
|
||||
protected:
|
||||
CREMesh()
|
||||
{
|
||||
mfSetType(eDATA_Mesh);
|
||||
mfUpdateFlags(FCEF_TRANSFORM);
|
||||
|
||||
m_pChunk = NULL;
|
||||
m_pRenderMesh = NULL;
|
||||
m_nFirstIndexId = -1;
|
||||
m_nNumIndices = -1;
|
||||
m_nFirstVertId = 0;
|
||||
m_nNumVerts = 0;
|
||||
}
|
||||
|
||||
virtual ~CREMesh()
|
||||
{
|
||||
}
|
||||
|
||||
// Ideally should be declared and left unimplemented to prevent slicing at compile time
|
||||
// but this would prevent auto code gen in renderer later on.
|
||||
// To track potential slicing, uncomment the following (and their equivalent in CREMeshImpl)
|
||||
//CREMesh(CREMesh&);
|
||||
//CREMesh& operator=(CREMesh& rhs);
|
||||
};
|
||||
|
||||
#endif // __CREMESH_H__
|
||||
@@ -1,116 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
#ifndef __CREOCCLUSIONQUERY_H__
|
||||
#define __CREOCCLUSIONQUERY_H__
|
||||
|
||||
#define SUPP_HMAP_OCCL
|
||||
#define SUPP_HWOBJ_OCCL
|
||||
|
||||
//=============================================================
|
||||
|
||||
class CRenderMesh;
|
||||
|
||||
class CREOcclusionQuery
|
||||
: public CRendElementBase
|
||||
{
|
||||
friend class CRender3D;
|
||||
bool m_bSucceeded;
|
||||
public:
|
||||
|
||||
int m_nVisSamples;
|
||||
int m_nCheckFrame;
|
||||
int m_nDrawFrame;
|
||||
Vec3 m_vBoxMin;
|
||||
Vec3 m_vBoxMax;
|
||||
|
||||
UINT_PTR m_nOcclusionID; // this will carry a pointer LPDIRECT3DQUERY9, so it needs to be 64-bit on Windows 64
|
||||
|
||||
CRenderMesh* m_pRMBox;
|
||||
static uint32 m_nQueriesPerFrameCounter;
|
||||
static uint32 m_nReadResultNowCounter;
|
||||
static uint32 m_nReadResultTryCounter;
|
||||
|
||||
CREOcclusionQuery()
|
||||
{
|
||||
m_nOcclusionID = 0;
|
||||
|
||||
m_nVisSamples = 800 * 600;
|
||||
m_nCheckFrame = 0;
|
||||
m_nDrawFrame = 0;
|
||||
m_vBoxMin = Vec3(0, 0, 0);
|
||||
m_vBoxMax = Vec3(0, 0, 0);
|
||||
m_pRMBox = NULL;
|
||||
|
||||
mfSetType(eDATA_OcclusionQuery);
|
||||
mfUpdateFlags(FCEF_TRANSFORM);
|
||||
}
|
||||
|
||||
bool RT_ReadResult_Try(uint32 nDefaultNumSamples);
|
||||
|
||||
ILINE bool HasSucceeded() const { return m_bSucceeded; }
|
||||
|
||||
virtual ~CREOcclusionQuery();
|
||||
|
||||
virtual void mfPrepare(bool bCheckOverflow);
|
||||
virtual bool mfDraw(CShader* ef, SShaderPass* sfm);
|
||||
virtual void mfReset();
|
||||
virtual bool mfReadResult_Try(uint32 nDefaultNumSamples = 1);
|
||||
virtual bool mfReadResult_Now();
|
||||
|
||||
virtual void GetMemoryUsage(ICrySizer* pSizer) const
|
||||
{
|
||||
pSizer->AddObject(this, sizeof(*this));
|
||||
}
|
||||
};
|
||||
|
||||
struct OcclusionTestClient
|
||||
{
|
||||
OcclusionTestClient()
|
||||
: nLastOccludedMainFrameID(0)
|
||||
, nLastVisibleMainFrameID(0)
|
||||
{
|
||||
#ifdef SUPP_HMAP_OCCL
|
||||
vLastVisPoint.Set(0, 0, 0);
|
||||
nTerrainOccLastFrame = 0;
|
||||
#endif
|
||||
#ifdef SUPP_HWOBJ_OCCL
|
||||
bOccluded = true;
|
||||
pREOcclusionQuery = 0;
|
||||
#endif
|
||||
//nInstantTestRequested=0;
|
||||
}
|
||||
#ifdef SUPP_HWOBJ_OCCL
|
||||
~OcclusionTestClient()
|
||||
{
|
||||
if (pREOcclusionQuery)
|
||||
{
|
||||
pREOcclusionQuery->Release(false);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
uint32 nLastVisibleMainFrameID, nLastOccludedMainFrameID;
|
||||
uint32 nLastShadowCastMainFrameID, nLastNoShadowCastMainFrameID;
|
||||
#ifdef SUPP_HMAP_OCCL
|
||||
Vec3 vLastVisPoint;
|
||||
int nTerrainOccLastFrame;
|
||||
#endif
|
||||
#ifdef SUPP_HWOBJ_OCCL
|
||||
CREOcclusionQuery* pREOcclusionQuery;
|
||||
uint8 bOccluded;
|
||||
#endif
|
||||
//uint8 nInstantTestRequested;
|
||||
};
|
||||
|
||||
|
||||
#endif // CRYINCLUDE_CRYCOMMON_CREOCCLUSIONQUERY_H
|
||||
@@ -1,56 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
#ifndef CRYINCLUDE_CRYCOMMON_CREPOSTPROCESS_H
|
||||
#define CRYINCLUDE_CRYCOMMON_CREPOSTPROCESS_H
|
||||
#pragma once
|
||||
|
||||
|
||||
class CREPostProcess
|
||||
: public CRendElementBase
|
||||
{
|
||||
friend class CD3D9Renderer;
|
||||
|
||||
public:
|
||||
|
||||
CREPostProcess();
|
||||
virtual ~CREPostProcess();
|
||||
|
||||
virtual void mfPrepare(bool bCheckOverflow);
|
||||
virtual bool mfDraw(CShader* ef, SShaderPass* sfm);
|
||||
|
||||
// Use for setting numeric values, vec4 (colors, position, vectors, wtv), strings
|
||||
virtual int mfSetParameter(const char* pszParam, float fValue, bool bForceValue = false) const;
|
||||
virtual int mfSetParameterVec4(const char* pszParam, const Vec4& pValue, bool bForceValue = false) const;
|
||||
virtual int mfSetParameterString(const char* pszParam, const char* pszArg) const;
|
||||
|
||||
virtual void mfGetParameter(const char* pszParam, float& fValue) const;
|
||||
virtual void mfGetParameterVec4(const char* pszParam, Vec4& pValue) const;
|
||||
virtual void mfGetParameterString(const char* pszParam, const char*& pszArg) const;
|
||||
|
||||
virtual int32 mfGetPostEffectID(const char* pPostEffectName) const;
|
||||
|
||||
// Reset all post processing effects
|
||||
virtual void Reset(bool bOnSpecChange = false);
|
||||
virtual void mfReset()
|
||||
{
|
||||
Reset();
|
||||
}
|
||||
|
||||
virtual void GetMemoryUsage(ICrySizer* pSizer) const
|
||||
{
|
||||
pSizer->AddObject(this, sizeof(*this));
|
||||
}
|
||||
};
|
||||
|
||||
#endif // CRYINCLUDE_CRYCOMMON_CREPOSTPROCESS_H
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
#ifndef _CREPRISMOBJECT_
|
||||
#define _CREPRISMOBJECT_
|
||||
|
||||
#pragma once
|
||||
|
||||
#if !defined(EXCLUDE_DOCUMENTATION_PURPOSE)
|
||||
|
||||
class CREPrismObject
|
||||
: public CRendElementBase
|
||||
{
|
||||
public:
|
||||
CREPrismObject();
|
||||
|
||||
virtual ~CREPrismObject() {}
|
||||
virtual void mfPrepare(bool bCheckOverflow);
|
||||
virtual bool mfDraw(CShader* ef, SShaderPass* sfm);
|
||||
|
||||
virtual void GetMemoryUsage(ICrySizer* pSizer) const
|
||||
{
|
||||
pSizer->AddObject(this, sizeof(*this));
|
||||
}
|
||||
|
||||
Vec3 m_center;
|
||||
};
|
||||
|
||||
#endif // EXCLUDE_DOCUMENTATION_PURPOSE
|
||||
|
||||
#endif // _CREPRISMOBJECT_
|
||||
@@ -1,92 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
#ifndef __CRESKY_H__
|
||||
#define __CRESKY_H__
|
||||
|
||||
//=============================================================
|
||||
|
||||
#include "VertexFormats.h"
|
||||
#include "../RenderDll/Common/Shaders/Vertex.h"
|
||||
|
||||
struct SSkyLightRenderParams;
|
||||
|
||||
class CRESky
|
||||
: public CRendElementBase
|
||||
{
|
||||
friend class CRender3D;
|
||||
|
||||
public:
|
||||
|
||||
float m_fTerrainWaterLevel;
|
||||
float m_fSkyBoxStretching;
|
||||
float m_fAlpha;
|
||||
int m_nSphereListId;
|
||||
|
||||
public:
|
||||
CRESky();
|
||||
virtual ~CRESky();
|
||||
virtual void mfPrepare(bool bCheckOverflow);
|
||||
virtual bool mfDraw(CShader* ef, SShaderPass* sfm);
|
||||
|
||||
virtual void GetMemoryUsage(ICrySizer* pSizer) const
|
||||
{
|
||||
pSizer->AddObject(this, sizeof(*this));
|
||||
}
|
||||
|
||||
AZ::Vertex::Format GetVertexFormat() const override;
|
||||
bool GetGeometryInfo(SGeometryInfo& streams) override;
|
||||
|
||||
private:
|
||||
AZ::Vertex::Format m_skyVertexFormat;
|
||||
};
|
||||
|
||||
class CREHDRSky
|
||||
: public CRendElementBase
|
||||
{
|
||||
public:
|
||||
CREHDRSky();
|
||||
virtual ~CREHDRSky();
|
||||
virtual void mfPrepare(bool bCheckOverflow);
|
||||
virtual bool mfDraw(CShader* ef, SShaderPass* sfm);
|
||||
|
||||
virtual void GetMemoryUsage(ICrySizer* pSizer) const
|
||||
{
|
||||
pSizer->AddObject(this, sizeof(*this));
|
||||
}
|
||||
|
||||
void GenerateSkyDomeTextures(int32 width, int32 height);
|
||||
|
||||
virtual AZ::Vertex::Format GetVertexFormat() const override;
|
||||
virtual bool GetGeometryInfo(SGeometryInfo& streams) override;
|
||||
|
||||
public:
|
||||
const SSkyLightRenderParams* m_pRenderParams;
|
||||
int m_moonTexId;
|
||||
class CTexture* m_pSkyDomeTextureMie;
|
||||
class CTexture* m_pSkyDomeTextureRayleigh;
|
||||
|
||||
static void SetCommonMoonParams(CShader* ef, bool bUseMoon = false);
|
||||
|
||||
private:
|
||||
void Init();
|
||||
|
||||
private:
|
||||
int m_skyDomeTextureLastTimeStamp;
|
||||
int m_frameReset;
|
||||
class CStars* m_pStars;
|
||||
AZ::Vertex::Format m_hdrSkyVertexFormat;
|
||||
};
|
||||
|
||||
|
||||
#endif // __CRESKY_H__
|
||||
@@ -1,70 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
#ifndef _CREVOLUMEOBJECT_
|
||||
#define _CREVOLUMEOBJECT_
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "VertexFormats.h"
|
||||
|
||||
|
||||
struct IVolumeObjectRenderNode;
|
||||
|
||||
struct IVolumeTexture
|
||||
{
|
||||
public:
|
||||
virtual ~IVolumeTexture() {}
|
||||
virtual void Release() = 0;
|
||||
virtual bool Create(unsigned int width, unsigned int height, unsigned int depth, unsigned char* pData) = 0;
|
||||
virtual bool Update(unsigned int width, unsigned int height, unsigned int depth, const unsigned char* pData) = 0;
|
||||
virtual int GetTexID() const = 0;
|
||||
virtual uint32 GetWidth() const = 0;
|
||||
virtual uint32 GetHeight() const = 0;
|
||||
virtual uint32 GetDepth() const = 0;
|
||||
virtual ITexture* GetTexture() const = 0;
|
||||
};
|
||||
|
||||
class CREVolumeObject
|
||||
: public CRendElementBase
|
||||
{
|
||||
public:
|
||||
CREVolumeObject();
|
||||
|
||||
virtual ~CREVolumeObject();
|
||||
virtual void mfPrepare(bool bCheckOverflow);
|
||||
virtual bool mfDraw(CShader* ef, SShaderPass* sfm);
|
||||
|
||||
virtual IVolumeTexture* CreateVolumeTexture() const;
|
||||
|
||||
virtual void GetMemoryUsage(ICrySizer* pSizer) const
|
||||
{
|
||||
pSizer->AddObject(this, sizeof(*this));
|
||||
}
|
||||
|
||||
Vec3 m_center;
|
||||
Matrix34 m_matInv;
|
||||
Vec3 m_eyePosInWS;
|
||||
Vec3 m_eyePosInOS;
|
||||
Plane m_volumeTraceStartPlane;
|
||||
AABB m_renderBoundsOS;
|
||||
bool m_viewerInsideVolume;
|
||||
bool m_nearPlaneIntersectsVolume;
|
||||
float m_alpha;
|
||||
float m_scale;
|
||||
|
||||
IVolumeTexture* m_pDensVol;
|
||||
IVolumeTexture* m_pShadVol;
|
||||
_smart_ptr<IRenderMesh> m_pHullMesh;
|
||||
};
|
||||
|
||||
#endif // #ifndef _CREVOLUMEOBJECT_
|
||||
@@ -1,57 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
#ifndef _CREWATEROCEAN_
|
||||
#define _CREWATEROCEAN_
|
||||
|
||||
class CWater;
|
||||
|
||||
class CREWaterOcean
|
||||
: public CRendElementBase
|
||||
{
|
||||
public:
|
||||
CREWaterOcean();
|
||||
virtual ~CREWaterOcean();
|
||||
|
||||
virtual void mfPrepare(bool bCheckOverflow);
|
||||
virtual bool mfDraw(CShader* ef, SShaderPass* sfm);
|
||||
virtual void mfGetPlane(Plane& pl);
|
||||
|
||||
virtual void Create(uint32 nVerticesCount, SVF_P3F_C4B_T2F* pVertices, uint32 nIndicesCount, const void* pIndices, uint32 nIndexSizeof);
|
||||
void ReleaseOcean();
|
||||
|
||||
virtual Vec3 GetPositionAt(float x, float y) const;
|
||||
virtual Vec4* GetDisplaceGrid() const;
|
||||
|
||||
virtual void GetMemoryUsage(ICrySizer* pSizer) const
|
||||
{
|
||||
pSizer->AddObject(this, sizeof(*this));
|
||||
}
|
||||
private:
|
||||
|
||||
uint32 m_nVerticesCount;
|
||||
uint32 m_nIndicesCount;
|
||||
uint32 m_nIndexSizeof;
|
||||
|
||||
void* m_pVertDecl;
|
||||
void* m_pVertices;
|
||||
void* m_pIndices;
|
||||
|
||||
private:
|
||||
|
||||
void UpdateFFT();
|
||||
void FrameUpdate();
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,110 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
#ifndef _CREWATERVOLUME_
|
||||
#define _CREWATERVOLUME_
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "VertexFormats.h"
|
||||
|
||||
class CREWaterVolume
|
||||
: public CRendElementBase
|
||||
{
|
||||
public:
|
||||
CREWaterVolume();
|
||||
|
||||
virtual ~CREWaterVolume();
|
||||
virtual void mfPrepare(bool bCheckOverflow);
|
||||
virtual bool mfDraw(CShader* ef, SShaderPass* sfm);
|
||||
virtual void mfGetPlane(Plane& pl);
|
||||
virtual void mfCenter(Vec3& vCenter, CRenderObject* pObj);
|
||||
|
||||
virtual void GetMemoryUsage(ICrySizer* pSizer) const
|
||||
{
|
||||
pSizer->AddObject(this, sizeof(*this));
|
||||
}
|
||||
|
||||
public:
|
||||
struct SParams
|
||||
{
|
||||
SParams()
|
||||
: m_pVertices(0)
|
||||
, m_pIndices(0)
|
||||
, m_numVertices(0)
|
||||
, m_numIndices(0)
|
||||
, m_center(0, 0, 0)
|
||||
, m_WSBBox(Vec3(-1, -1, -1), Vec3(1, 1, 1))
|
||||
, m_fogPlane(Vec3(0, 0, 1), 0)
|
||||
, m_fogDensity(0.1f)
|
||||
, m_fogColor(0.2f, 0.5f, 0.7f)
|
||||
, m_fogColorAffectedBySun(true)
|
||||
, m_fogShadowing(0.5f)
|
||||
, m_caustics(true)
|
||||
, m_causticIntensity(1.0f)
|
||||
, m_causticTiling(1.0f)
|
||||
, m_causticHeight(0.9f)
|
||||
, m_viewerInsideVolume(false)
|
||||
, m_viewerCloseToWaterPlane(false)
|
||||
, m_viewerCloseToWaterVolume(false)
|
||||
{
|
||||
}
|
||||
|
||||
const SVF_P3F_C4B_T2F* m_pVertices;
|
||||
const uint16* m_pIndices;
|
||||
|
||||
size_t m_numVertices;
|
||||
size_t m_numIndices;
|
||||
|
||||
Vec3 m_center;
|
||||
AABB m_WSBBox;
|
||||
|
||||
Plane m_fogPlane;
|
||||
float m_fogDensity;
|
||||
Vec3 m_fogColor;
|
||||
bool m_fogColorAffectedBySun;
|
||||
float m_fogShadowing;
|
||||
|
||||
bool m_caustics;
|
||||
float m_causticIntensity;
|
||||
float m_causticTiling;
|
||||
float m_causticHeight;
|
||||
|
||||
bool m_viewerInsideVolume;
|
||||
bool m_viewerCloseToWaterPlane;
|
||||
bool m_viewerCloseToWaterVolume;
|
||||
};
|
||||
|
||||
struct SOceanParams
|
||||
{
|
||||
SOceanParams()
|
||||
: m_fogColor(0.2f, 0.5f, 0.7f)
|
||||
, m_fogColorShallow(0.2f, 0.5f, 0.7f)
|
||||
, m_fogDensity(0.2f)
|
||||
{
|
||||
}
|
||||
|
||||
Vec3 m_fogColor;
|
||||
Vec3 m_fogColorShallow;
|
||||
float m_fogDensity;
|
||||
};
|
||||
|
||||
public:
|
||||
const SParams* m_pParams;
|
||||
const SOceanParams* m_pOceanParams;
|
||||
bool m_drawWaterSurface;
|
||||
bool m_drawFastPath;
|
||||
};
|
||||
|
||||
|
||||
#endif // #ifndef _CREWATERVOLUME_
|
||||
@@ -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.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AzCore/PlatformRestrictedFileDef.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace std
|
||||
{
|
||||
#if defined(AZ_RESTRICTED_PLATFORM)
|
||||
#include AZ_RESTRICTED_FILE(Console_std_h)
|
||||
#endif
|
||||
}
|
||||
@@ -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
|
||||
@@ -31,7 +31,7 @@ void CryAssertTrace(const char* szFormat, ...)
|
||||
return;
|
||||
}
|
||||
|
||||
if (!gEnv->bIgnoreAllAsserts || gEnv->bTesting)
|
||||
if (!gEnv->bIgnoreAllAsserts)
|
||||
{
|
||||
if (szFormat == NULL)
|
||||
{
|
||||
|
||||
@@ -34,7 +34,7 @@ void CryAssertTrace(const char* szFormat, ...)
|
||||
return;
|
||||
}
|
||||
|
||||
if (!gEnv->bIgnoreAllAsserts || gEnv->bTesting)
|
||||
if (!gEnv->bIgnoreAllAsserts)
|
||||
{
|
||||
if (szFormat == NULL)
|
||||
{
|
||||
|
||||
@@ -30,7 +30,7 @@ void CryAssertTrace(const char* szFormat, ...)
|
||||
return;
|
||||
}
|
||||
|
||||
if (!gEnv->bIgnoreAllAsserts || gEnv->bTesting)
|
||||
if (!gEnv->bIgnoreAllAsserts)
|
||||
{
|
||||
if (szFormat == NULL)
|
||||
{
|
||||
@@ -45,43 +45,6 @@ void CryAssertTrace(const char* szFormat, ...)
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
bool CryAssert(const char* szCondition, const char* szFile,unsigned int line, bool *pIgnore)
|
||||
{
|
||||
if (!gEnv) return false;
|
||||
|
||||
gEnv->pSystem->OnAssert(szCondition, gs_szMessage, szFile, line);
|
||||
|
||||
if (!gEnv->bNoAssertDialog && !gEnv->bIgnoreAllAsserts)
|
||||
{
|
||||
EDialogAction action = MacOSXHandleAssert(szCondition, szFile, line, gs_szMessage, gEnv->pRenderer != NULL);
|
||||
|
||||
switch (action) {
|
||||
case eDAStop:
|
||||
raise(SIGABRT);
|
||||
exit(-1);
|
||||
case eDABreak:
|
||||
return true;
|
||||
case eDAIgnoreAll:
|
||||
gEnv->bIgnoreAllAsserts = true;
|
||||
break;
|
||||
case eDAIgnore:
|
||||
*pIgnore = true;
|
||||
break;
|
||||
case eDAReportAsBug:
|
||||
if ( gEnv && gEnv->pSystem)
|
||||
{
|
||||
gEnv->pSystem->ReportBug("Assert: %s - %s", szCondition,gs_szMessage);
|
||||
}
|
||||
|
||||
case eDAContinue:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}*/
|
||||
|
||||
bool CryAssert(const char* szCondition, const char* szFile, unsigned int line, bool* pIgnore)
|
||||
{
|
||||
|
||||
@@ -31,7 +31,7 @@ void CryAssertTrace(const char* szFormat, ...)
|
||||
return;
|
||||
}
|
||||
|
||||
if (!gEnv->bIgnoreAllAsserts || gEnv->bTesting)
|
||||
if (!gEnv->bIgnoreAllAsserts)
|
||||
{
|
||||
if (szFormat == NULL)
|
||||
{
|
||||
|
||||
@@ -305,7 +305,7 @@ void CryAssertTrace(const char* _pszFormat, ...)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!gEnv->bIgnoreAllAsserts || gEnv->bTesting)
|
||||
if (!gEnv->bIgnoreAllAsserts)
|
||||
{
|
||||
if (NULL == _pszFormat)
|
||||
{
|
||||
|
||||
@@ -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,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 : declaration of struct CryEngineDecalInfo.
|
||||
|
||||
// Note:
|
||||
// 3D Engine and Character Animation subsystems (as well as perhaps
|
||||
// some others) transfer data about the decals that need to be spawned
|
||||
// via this structure. This is to avoid passing many parameters through
|
||||
// each function call, and to save on copying these parameters when just
|
||||
// simply passing the structure from one function to another.
|
||||
|
||||
#ifndef CRYINCLUDE_CRYCOMMON_CRYENGINEDECALINFO_H
|
||||
#define CRYINCLUDE_CRYCOMMON_CRYENGINEDECALINFO_H
|
||||
#pragma once
|
||||
|
||||
#include "Cry_Math.h"
|
||||
|
||||
// Summary:
|
||||
// Structure containing common parameters that describe a decal
|
||||
|
||||
struct SDecalOwnerInfo
|
||||
{
|
||||
SDecalOwnerInfo() { memset(this, 0, sizeof(*this)); nRenderNodeSlotId = nRenderNodeSlotSubObjectId = -1; }
|
||||
struct IStatObj* GetOwner(Matrix34A& objMat);
|
||||
|
||||
struct IRenderNode* pRenderNode; // Owner (decal will be attached to or wrapped around of this object)
|
||||
PodArray<struct SRNInfo>* pDecalReceivers;
|
||||
int nRenderNodeSlotId; // is set internally by 3dengine
|
||||
int nRenderNodeSlotSubObjectId; // is set internally by 3dengine
|
||||
int nMatID;
|
||||
};
|
||||
|
||||
struct CryEngineDecalInfo
|
||||
{
|
||||
SDecalOwnerInfo ownerInfo;
|
||||
Vec3 vPos; // Decal position (world coordinates)
|
||||
Vec3 vNormal; // Decal/face normal
|
||||
float fSize; // Decal size
|
||||
float fLifeTime; // Decal life time (in seconds)
|
||||
float fAngle; // Angle of rotation
|
||||
struct IStatObj* pIStatObj; // Decal geometry
|
||||
Vec3 vHitDirection; // Direction from weapon/player position to decal position (bullet direction)
|
||||
float fGrowTime, fGrowTimeAlpha;// Used for blood pools
|
||||
unsigned int nGroupId; // Used for multi-component decals
|
||||
bool bSkipOverlappingTest; // Always spawn decals even if there are a lot of other decals in same place
|
||||
bool bAssemble; // Assemble to bigger decals if more than 1 decal is on the same place
|
||||
bool bForceEdge; // force the decal to the nearest edge of the owner mesh and project it accordingly
|
||||
bool bForceSingleOwner; // Do not attempt to cast the decal into the environment even if it's large enough
|
||||
bool bDeferred;
|
||||
uint8 sortPrio;
|
||||
char szMaterialName[_MAX_PATH]; // name of material used for rendering the decal (in favor of szTextureName/nTid and the default decal shader)
|
||||
bool preventDecalOnGround; // mainly for decal placement support
|
||||
const Matrix33* pExplicitRightUpFront; // mainly for decal placement support
|
||||
|
||||
void GetMemoryUsage([[maybe_unused]] ICrySizer* pSizer) const{}
|
||||
|
||||
// the constructor fills in some non-obligatory fields; the other fields must be filled in by the client
|
||||
CryEngineDecalInfo ()
|
||||
{
|
||||
memset(this, 0, sizeof(*this));
|
||||
ownerInfo.nRenderNodeSlotId = ownerInfo.nRenderNodeSlotSubObjectId = -1;
|
||||
sortPrio = 255;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // CRYINCLUDE_CRYCOMMON_CRYENGINEDECALINFO_H
|
||||
@@ -1,96 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
// Description : Part of CryEngine's extension framework.
|
||||
|
||||
|
||||
#ifndef CRYINCLUDE_CRYEXTENSION_CRYCREATECLASSINSTANCE_H
|
||||
#define CRYINCLUDE_CRYEXTENSION_CRYCREATECLASSINSTANCE_H
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "ICryUnknown.h"
|
||||
#include "ICryFactory.h"
|
||||
#include "ICryFactoryRegistry.h"
|
||||
#include <ISystem.h> // <> required for Interfuscator
|
||||
|
||||
|
||||
template <class T>
|
||||
bool CryCreateClassInstance(const CryClassID& cid, AZStd::shared_ptr<T>& p)
|
||||
{
|
||||
p = AZStd::shared_ptr<T>();
|
||||
ICryFactoryRegistry* pFactoryReg = gEnv->pSystem->GetCryFactoryRegistry();
|
||||
if (pFactoryReg)
|
||||
{
|
||||
ICryFactory* pFactory = pFactoryReg->GetFactory(cid);
|
||||
if (pFactory && pFactory->ClassSupports(cryiidof<T>()))
|
||||
{
|
||||
ICryUnknownPtr pUnk = pFactory->CreateClassInstance();
|
||||
AZStd::shared_ptr<T> pT = cryinterface_cast<T>(pUnk);
|
||||
if (pT)
|
||||
{
|
||||
p = pT;
|
||||
}
|
||||
}
|
||||
}
|
||||
return p.get() != NULL;
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
bool CryCreateClassInstance(const char* cname, AZStd::shared_ptr<T>& p)
|
||||
{
|
||||
p = AZStd::shared_ptr<T>();
|
||||
ICryFactoryRegistry* pFactoryReg = gEnv->pSystem->GetCryFactoryRegistry();
|
||||
if (pFactoryReg)
|
||||
{
|
||||
ICryFactory* pFactory = pFactoryReg->GetFactory(cname);
|
||||
if (pFactory != NULL && pFactory->ClassSupports(cryiidof<T>()))
|
||||
{
|
||||
ICryUnknownPtr pUnk = pFactory->CreateClassInstance();
|
||||
AZStd::shared_ptr<T> pT = cryinterface_cast<T>(pUnk);
|
||||
if (pT)
|
||||
{
|
||||
p = pT;
|
||||
}
|
||||
}
|
||||
}
|
||||
return p.get() != NULL;
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
bool CryCreateClassInstanceForInterface(const CryInterfaceID& iid, AZStd::shared_ptr<T>& p)
|
||||
{
|
||||
p = AZStd::shared_ptr<T>();
|
||||
ICryFactoryRegistry* pFactoryReg = gEnv->pSystem->GetCryFactoryRegistry();
|
||||
if (pFactoryReg)
|
||||
{
|
||||
size_t numFactories = 1;
|
||||
ICryFactory* pFactory = 0;
|
||||
pFactoryReg->IterateFactories(iid, &pFactory, numFactories);
|
||||
if (numFactories == 1 && pFactory)
|
||||
{
|
||||
ICryUnknownPtr pUnk = pFactory->CreateClassInstance();
|
||||
AZStd::shared_ptr<T> pT = cryinterface_cast<T>(pUnk);
|
||||
if (pT)
|
||||
{
|
||||
p = pT;
|
||||
}
|
||||
}
|
||||
}
|
||||
return p.get() != NULL;
|
||||
}
|
||||
|
||||
|
||||
#endif // CRYINCLUDE_CRYEXTENSION_CRYCREATECLASSINSTANCE_H
|
||||
@@ -1,123 +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 : Part of CryEngine's extension framework.
|
||||
|
||||
|
||||
#ifndef CRYINCLUDE_CRYEXTENSION_CRYGUID_H
|
||||
#define CRYINCLUDE_CRYEXTENSION_CRYGUID_H
|
||||
#pragma once
|
||||
|
||||
#include "Serialization/IArchive.h"
|
||||
#include "Random.h"
|
||||
|
||||
#include <functional>
|
||||
|
||||
struct CryGUID
|
||||
{
|
||||
uint64 hipart;
|
||||
uint64 lopart;
|
||||
|
||||
// !!! Do NOT turn CryGUID into a non-aggregate !!!
|
||||
// It will prevent inlining and type list unrolling opportunities within
|
||||
// cryinterface_cast<T>() and cryiidof<T>(). As such prevent constructors,
|
||||
// non-public members, base classes and virtual functions!
|
||||
|
||||
//CryGUID() : hipart(0), lopart(0) {}
|
||||
//CryGUID(uint64 h, uint64 l) : hipart(h), lopart(l) {}
|
||||
|
||||
static CryGUID Construct(const uint64& hipart, const uint64& lopart)
|
||||
{
|
||||
CryGUID guid = {hipart, lopart};
|
||||
return guid;
|
||||
}
|
||||
|
||||
static CryGUID Create()
|
||||
{
|
||||
uint64 lopart = 0;
|
||||
uint64 hipart = 0;
|
||||
while (lopart == 0 || hipart == 0)
|
||||
{
|
||||
const uint32 a = cry_random_uint32();
|
||||
const uint32 b = cry_random_uint32();
|
||||
const uint32 c = cry_random_uint32();
|
||||
const uint32 d = cry_random_uint32();
|
||||
lopart = (uint64)a | ((uint64)b << 32);
|
||||
hipart = (uint64)c | ((uint64)d << 32);
|
||||
}
|
||||
|
||||
return Construct(lopart, hipart);
|
||||
}
|
||||
|
||||
static CryGUID Null()
|
||||
{
|
||||
return Construct(0, 0);
|
||||
}
|
||||
|
||||
bool operator ==(const CryGUID& rhs) const {return hipart == rhs.hipart && lopart == rhs.lopart; }
|
||||
bool operator !=(const CryGUID& rhs) const {return hipart != rhs.hipart || lopart != rhs.lopart; }
|
||||
bool operator <(const CryGUID& rhs) const {return hipart == rhs.hipart ? lopart < rhs.lopart : hipart < rhs.hipart; }
|
||||
|
||||
void Serialize(Serialization::IArchive& ar)
|
||||
{
|
||||
if (ar.IsInput())
|
||||
{
|
||||
uint32 dwords[4];
|
||||
ar(dwords, "guid");
|
||||
lopart = (((uint64)dwords[1]) << 32) | (uint64)dwords[0];
|
||||
hipart = (((uint64)dwords[3]) << 32) | (uint64)dwords[2];
|
||||
}
|
||||
else
|
||||
{
|
||||
uint32 guid[4] = {
|
||||
(uint32)(lopart & 0xFFFFFFFF), (uint32)((lopart >> 32) & 0xFFFFFFFF),
|
||||
(uint32)(hipart & 0xFFFFFFFF), (uint32)((hipart >> 32) & 0xFFFFFFFF)
|
||||
};
|
||||
ar(guid, "guid");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// This is only used by the editor where we use C++ 11.
|
||||
namespace std
|
||||
{
|
||||
template<>
|
||||
struct hash<CryGUID>
|
||||
{
|
||||
public:
|
||||
size_t operator()(const CryGUID& guid) const
|
||||
{
|
||||
std::hash<uint64> hasher;
|
||||
return hasher(guid.lopart) ^ hasher(guid.hipart);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
namespace AZStd
|
||||
{
|
||||
template<>
|
||||
struct hash<CryGUID>
|
||||
{
|
||||
public:
|
||||
size_t operator()(const CryGUID& guid) const
|
||||
{
|
||||
std::hash<CryGUID> hasher;
|
||||
return hasher(guid);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#define MAKE_CRYGUID(high, low) CryGUID::Construct((uint64) high##LL, (uint64) low##LL)
|
||||
|
||||
|
||||
#endif // CRYINCLUDE_CRYEXTENSION_CRYGUID_H
|
||||
@@ -1,29 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
// Description : Part of CryEngine's extension framework.
|
||||
|
||||
|
||||
#ifndef CRYINCLUDE_CRYEXTENSION_CRYTYPEID_H
|
||||
#define CRYINCLUDE_CRYEXTENSION_CRYTYPEID_H
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "CryGUID.h"
|
||||
|
||||
|
||||
typedef CryGUID CryInterfaceID;
|
||||
typedef CryGUID CryClassID;
|
||||
|
||||
|
||||
#endif // CRYINCLUDE_CRYEXTENSION_CRYTYPEID_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.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
// Description : Part of CryEngine's extension framework.
|
||||
|
||||
|
||||
#ifndef CRYINCLUDE_CRYEXTENSION_ICRYFACTORY_H
|
||||
#define CRYINCLUDE_CRYEXTENSION_ICRYFACTORY_H
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "CryTypeID.h"
|
||||
#include <SmartPointersHelpers.h>
|
||||
|
||||
struct ICryUnknown;
|
||||
DECLARE_SMART_POINTERS(ICryUnknown);
|
||||
|
||||
struct ICryFactory
|
||||
{
|
||||
virtual const char* GetName() const = 0;
|
||||
virtual const CryClassID& GetClassID() const = 0;
|
||||
virtual bool ClassSupports(const CryInterfaceID& iid) const = 0;
|
||||
virtual void ClassSupports(const CryInterfaceID*& pIIDs, size_t& numIIDs) const = 0;
|
||||
virtual ICryUnknownPtr CreateClassInstance() const = 0;
|
||||
|
||||
protected:
|
||||
// prevent explicit destruction from client side (delete, shared_ptr, etc)
|
||||
virtual ~ICryFactory() {}
|
||||
};
|
||||
|
||||
#endif // CRYINCLUDE_CRYEXTENSION_ICRYFACTORY_H
|
||||
@@ -1,56 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
// Description : Part of CryEngine's extension framework.
|
||||
|
||||
|
||||
#ifndef CRYINCLUDE_CRYEXTENSION_ICRYFACTORYREGISTRY_H
|
||||
#define CRYINCLUDE_CRYEXTENSION_ICRYFACTORYREGISTRY_H
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "CryTypeID.h"
|
||||
|
||||
|
||||
struct ICryFactory;
|
||||
|
||||
|
||||
struct ICryFactoryRegistry
|
||||
{
|
||||
virtual ICryFactory* GetFactory(const char* cname) const = 0;
|
||||
virtual ICryFactory* GetFactory(const CryClassID& cid) const = 0;
|
||||
/**
|
||||
* Iterates all factories implementing the interface specified by \p iid.
|
||||
* \param[in] iid ID of the interface to iterate. Often procured using cryiidof<...>().
|
||||
* \param[out] pFactories A pointer of the array of factories to fill in. May be nullptr (see below).
|
||||
* \param[in] Size (in elements) of the pFactories array [out] Number of elements actually written to pFactories or, when pFactories is null, the number of elements that would be written if sufficient storage was available.
|
||||
*
|
||||
* Example:
|
||||
* \code{.cpp}
|
||||
* size_t factoryCount = 0;
|
||||
* // Assigns the number of found factories to factoryCount
|
||||
* factoryRegistry->IterateFactories(cryiidof<TPointer>(), 0, factoryCount);
|
||||
* // Allocate an array of the proper length on the stack
|
||||
* ICryFactory** factories = static_cast<ICryFactory**>(alloca(sizeof(ICryFactory*) * factoryCount);
|
||||
* // Fill in factories with factoryCount results.
|
||||
* factoryRegistry->IterateFactories(cryiidof<TPointer>(), factories, factoryCount);
|
||||
* \endcode
|
||||
*/
|
||||
virtual void IterateFactories(const CryInterfaceID& iid, ICryFactory** pFactories, size_t& numFactories) const = 0;
|
||||
|
||||
protected:
|
||||
// prevent explicit destruction from client side (delete, shared_ptr, etc)
|
||||
virtual ~ICryFactoryRegistry() {}
|
||||
};
|
||||
|
||||
#endif // CRYINCLUDE_CRYEXTENSION_ICRYFACTORYREGISTRY_H
|
||||
@@ -1,224 +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 : Part of CryEngine's extension framework.
|
||||
|
||||
|
||||
#ifndef CRYINCLUDE_CRYEXTENSION_ICRYUNKNOWN_H
|
||||
#define CRYINCLUDE_CRYEXTENSION_ICRYUNKNOWN_H
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "CryTypeID.h"
|
||||
#include <SmartPointersHelpers.h>
|
||||
|
||||
|
||||
struct ICryFactory;
|
||||
struct ICryUnknown;
|
||||
|
||||
namespace InterfaceCastSemantics
|
||||
{
|
||||
template <class T>
|
||||
const CryInterfaceID& cryiidof()
|
||||
{
|
||||
return T::IID();
|
||||
}
|
||||
|
||||
#define _BEFRIEND_CRYIIDOF() \
|
||||
template <class T> \
|
||||
friend const CryInterfaceID&InterfaceCastSemantics::cryiidof();
|
||||
|
||||
|
||||
template <class Dst, class Src>
|
||||
Dst* cryinterface_cast(Src* p)
|
||||
{
|
||||
return static_cast<Dst*>(p ? p->QueryInterface(cryiidof<Dst>()) : 0);
|
||||
}
|
||||
|
||||
template <class Dst, class Src>
|
||||
Dst* cryinterface_cast(const Src* p)
|
||||
{
|
||||
return static_cast<const Dst*>(p ? p->QueryInterface(cryiidof<Dst>()) : 0);
|
||||
}
|
||||
|
||||
namespace Internal
|
||||
{
|
||||
template <class Dst, class Src>
|
||||
struct cryinterface_cast_shared_ptr_helper;
|
||||
|
||||
template <class Dst, class Src>
|
||||
struct cryinterface_cast_shared_ptr_helper
|
||||
{
|
||||
static AZStd::shared_ptr<Dst> Op(const AZStd::shared_ptr<Src>& p)
|
||||
{
|
||||
Dst* dp = cryinterface_cast<Dst>(p.get());
|
||||
return dp ? AZStd::shared_ptr<Dst>(p, dp) : AZStd::shared_ptr<Dst>();
|
||||
}
|
||||
};
|
||||
|
||||
template <class Src>
|
||||
struct cryinterface_cast_shared_ptr_helper<ICryUnknown, Src>
|
||||
{
|
||||
static AZStd::shared_ptr<ICryUnknown> Op(const AZStd::shared_ptr<Src>& p)
|
||||
{
|
||||
ICryUnknown* dp = cryinterface_cast<ICryUnknown>(p.get());
|
||||
return dp ? AZStd::shared_ptr<ICryUnknown>(*((const AZStd::shared_ptr<ICryUnknown>*) & p), dp) : AZStd::shared_ptr<ICryUnknown>();
|
||||
}
|
||||
};
|
||||
|
||||
template <class Src>
|
||||
struct cryinterface_cast_shared_ptr_helper<const ICryUnknown, Src>
|
||||
{
|
||||
static AZStd::shared_ptr<const ICryUnknown> Op(const AZStd::shared_ptr<Src>& p)
|
||||
{
|
||||
const ICryUnknown* dp = cryinterface_cast<const ICryUnknown>(p.get());
|
||||
return dp ? AZStd::shared_ptr<const ICryUnknown>(*((const AZStd::shared_ptr<const ICryUnknown>*) & p), dp) : AZStd::shared_ptr<const ICryUnknown>();
|
||||
}
|
||||
};
|
||||
} // namespace Internal
|
||||
|
||||
template <class Dst, class Src>
|
||||
AZStd::shared_ptr<Dst> cryinterface_cast(const AZStd::shared_ptr<Src>& p)
|
||||
{
|
||||
return Internal::cryinterface_cast_shared_ptr_helper<Dst, Src>::Op(p);
|
||||
}
|
||||
|
||||
#define _BEFRIEND_CRYINTERFACE_CAST() \
|
||||
template <class Dst, class Src> \
|
||||
friend Dst * InterfaceCastSemantics::cryinterface_cast(Src*); \
|
||||
template <class Dst, class Src> \
|
||||
friend Dst * InterfaceCastSemantics::cryinterface_cast(const Src*); \
|
||||
template <class Dst, class Src> \
|
||||
friend AZStd::shared_ptr<Dst> InterfaceCastSemantics::cryinterface_cast(const AZStd::shared_ptr<Src>&);
|
||||
} // namespace InterfaceCastSemantics
|
||||
|
||||
using InterfaceCastSemantics::cryiidof;
|
||||
using InterfaceCastSemantics::cryinterface_cast;
|
||||
|
||||
|
||||
template <class S, class T>
|
||||
bool CryIsSameClassInstance(S* p0, T* p1)
|
||||
{
|
||||
return static_cast<const void*>(p0) == static_cast<const void*>(p1) || cryinterface_cast<const ICryUnknown>(p0) == cryinterface_cast<const ICryUnknown>(p1);
|
||||
}
|
||||
|
||||
template <class S, class T>
|
||||
bool CryIsSameClassInstance(const AZStd::shared_ptr<S>& p0, T* p1)
|
||||
{
|
||||
return CryIsSameClassInstance(p0.get(), p1);
|
||||
}
|
||||
|
||||
template <class S, class T>
|
||||
bool CryIsSameClassInstance(S* p0, const AZStd::shared_ptr<T>& p1)
|
||||
{
|
||||
return CryIsSameClassInstance(p0, p1.get());
|
||||
}
|
||||
|
||||
template <class S, class T>
|
||||
bool CryIsSameClassInstance(const AZStd::shared_ptr<S>& p0, const AZStd::shared_ptr<T>& p1)
|
||||
{
|
||||
return CryIsSameClassInstance(p0.get(), p1.get());
|
||||
}
|
||||
|
||||
|
||||
namespace CompositeQuerySemantics
|
||||
{
|
||||
template <class Src>
|
||||
AZStd::shared_ptr<ICryUnknown> crycomposite_query(Src* p, const char* name, bool* pExposed = 0)
|
||||
{
|
||||
void* pComposite = p ? p->QueryComposite(name) : 0;
|
||||
pExposed ? *pExposed = pComposite != 0 : 0;
|
||||
return pComposite ? *static_cast<AZStd::shared_ptr<ICryUnknown>*>(pComposite) : AZStd::shared_ptr<ICryUnknown>();
|
||||
}
|
||||
|
||||
template <class Src>
|
||||
AZStd::shared_ptr<const ICryUnknown> crycomposite_query(const Src* p, const char* name, bool* pExposed = 0)
|
||||
{
|
||||
void* pComposite = p ? p->QueryComposite(name) : 0;
|
||||
pExposed ? *pExposed = pComposite != 0 : 0;
|
||||
return pComposite ? *static_cast<AZStd::shared_ptr<const ICryUnknown>*>(pComposite) : AZStd::shared_ptr<const ICryUnknown>();
|
||||
}
|
||||
|
||||
template <class Src>
|
||||
AZStd::shared_ptr<ICryUnknown> crycomposite_query(const AZStd::shared_ptr<Src>& p, const char* name, bool* pExposed = 0)
|
||||
{
|
||||
return crycomposite_query(p.get(), name, pExposed);
|
||||
}
|
||||
|
||||
template <class Src>
|
||||
AZStd::shared_ptr<const ICryUnknown> crycomposite_query(const AZStd::shared_ptr<const Src>& p, const char* name, bool* pExposed = 0)
|
||||
{
|
||||
return crycomposite_query(p.get(), name, pExposed);
|
||||
}
|
||||
|
||||
#define _BEFRIEND_CRYCOMPOSITE_QUERY() \
|
||||
template <class Src> \
|
||||
friend AZStd::shared_ptr<ICryUnknown> CompositeQuerySemantics::crycomposite_query(Src*, const char*, bool*); \
|
||||
template <class Src> \
|
||||
friend AZStd::shared_ptr<const ICryUnknown> CompositeQuerySemantics::crycomposite_query(const Src*, const char*, bool*); \
|
||||
template <class Src> \
|
||||
friend AZStd::shared_ptr<ICryUnknown> CompositeQuerySemantics::crycomposite_query(const AZStd::shared_ptr<Src>&, const char*, bool*); \
|
||||
template <class Src> \
|
||||
friend AZStd::shared_ptr<const ICryUnknown> CompositeQuerySemantics::crycomposite_query(const AZStd::shared_ptr<const Src>&, const char*, bool*);
|
||||
} // namespace CompositeQuerySemantics
|
||||
|
||||
using CompositeQuerySemantics::crycomposite_query;
|
||||
|
||||
|
||||
#define _BEFRIEND_MAKE_SHARED() \
|
||||
template <class T> \
|
||||
friend class AZStd::Internal::sp_ms_deleter; \
|
||||
template <class T> \
|
||||
friend AZStd::shared_ptr<T> AZStd::make_shared(); \
|
||||
template <class T, class A> \
|
||||
friend AZStd::shared_ptr<T> AZStd::allocate_shared(A const& a);
|
||||
|
||||
// prevent explicit destruction from client side
|
||||
#define _PROTECTED_DTOR(iname) \
|
||||
protected: \
|
||||
virtual ~iname() {}
|
||||
|
||||
|
||||
// Befriending cryinterface_cast<T>() and crycomposite_query() via CRYINTERFACE_DECLARE is actually only needed for ICryUnknown
|
||||
// since QueryInterface() and QueryComposite() are usually not redeclared in derived interfaces but it doesn't hurt either
|
||||
#define CRYINTERFACE_DECLARE(iname, iidHigh, iidLow) \
|
||||
_BEFRIEND_CRYIIDOF() \
|
||||
_BEFRIEND_CRYINTERFACE_CAST() \
|
||||
_BEFRIEND_CRYCOMPOSITE_QUERY() \
|
||||
_BEFRIEND_MAKE_SHARED() \
|
||||
_PROTECTED_DTOR(iname) \
|
||||
\
|
||||
private: \
|
||||
static const CryInterfaceID& IID() \
|
||||
{ \
|
||||
static const CryInterfaceID iid = {(uint64) iidHigh##LL, (uint64) iidLow##LL}; \
|
||||
return iid; \
|
||||
} \
|
||||
public:
|
||||
|
||||
|
||||
struct ICryUnknown
|
||||
{
|
||||
CRYINTERFACE_DECLARE(ICryUnknown, 0x1000000010001000, 0x1000100000000000)
|
||||
|
||||
virtual ICryFactory * GetFactory() const = 0;
|
||||
|
||||
protected:
|
||||
virtual void* QueryInterface(const CryInterfaceID& iid) const = 0;
|
||||
virtual void* QueryComposite(const char* name) const = 0;
|
||||
};
|
||||
|
||||
DECLARE_SMART_POINTERS(ICryUnknown);
|
||||
|
||||
|
||||
#endif // CRYINCLUDE_CRYEXTENSION_ICRYUNKNOWN_H
|
||||
@@ -1,461 +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 : Part of CryEngine's extension framework.
|
||||
|
||||
|
||||
#ifndef CRYINCLUDE_CRYEXTENSION_IMPL_CLASSWEAVER_H
|
||||
#define CRYINCLUDE_CRYEXTENSION_IMPL_CLASSWEAVER_H
|
||||
#pragma once
|
||||
|
||||
#include "TypeList.h"
|
||||
#include "Conversion.h"
|
||||
#include "RegFactoryNode.h"
|
||||
#include "../ICryUnknown.h"
|
||||
#include "../ICryFactory.h"
|
||||
#include <AzCore/Memory/Memory.h>
|
||||
|
||||
namespace CW
|
||||
{
|
||||
namespace Internal
|
||||
{
|
||||
template <class Dst>
|
||||
struct InterfaceCast;
|
||||
|
||||
template <class Dst>
|
||||
struct InterfaceCast
|
||||
{
|
||||
template <class T>
|
||||
static void* Op(T* p)
|
||||
{
|
||||
return (Dst*) p;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct InterfaceCast<ICryUnknown>
|
||||
{
|
||||
template <class T>
|
||||
static void* Op(T* p)
|
||||
{
|
||||
return const_cast<ICryUnknown*>(static_cast<const ICryUnknown*>(static_cast<const void*>(p)));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
template <class TList>
|
||||
struct InterfaceCast;
|
||||
|
||||
template <>
|
||||
struct InterfaceCast<TL::NullType>
|
||||
{
|
||||
template <class T>
|
||||
static void* Op(T*, const CryInterfaceID&)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
template <class Head, class Tail>
|
||||
struct InterfaceCast<TL::Typelist<Head, Tail> >
|
||||
{
|
||||
template <class T>
|
||||
static void* Op(T* p, const CryInterfaceID& iid)
|
||||
{
|
||||
if (cryiidof<Head>() == iid)
|
||||
{
|
||||
return Internal::InterfaceCast<Head>::Op(p);
|
||||
}
|
||||
return InterfaceCast<Tail>::Op(p, iid);
|
||||
}
|
||||
};
|
||||
|
||||
template <class TList>
|
||||
struct FillIIDs;
|
||||
|
||||
template <>
|
||||
struct FillIIDs<TL::NullType>
|
||||
{
|
||||
static void Op(CryInterfaceID*)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
template <class Head, class Tail>
|
||||
struct FillIIDs<TL::Typelist<Head, Tail> >
|
||||
{
|
||||
static void Op(CryInterfaceID* p)
|
||||
{
|
||||
*p++ = cryiidof<Head>();
|
||||
FillIIDs<Tail>::Op(p);
|
||||
}
|
||||
};
|
||||
|
||||
namespace Internal
|
||||
{
|
||||
template <bool, typename S>
|
||||
struct PickList;
|
||||
|
||||
template <bool, typename S>
|
||||
struct PickList
|
||||
{
|
||||
typedef TL::BuildTypelist<>::Result Result;
|
||||
};
|
||||
|
||||
template <typename S>
|
||||
struct PickList<true, S>
|
||||
{
|
||||
typedef typename S::FullCompositeList Result;
|
||||
};
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
struct ProbeFullCompositeList
|
||||
{
|
||||
private:
|
||||
typedef char y[1];
|
||||
typedef char n[2];
|
||||
|
||||
template <typename S>
|
||||
static y& test(typename S::FullCompositeList*);
|
||||
|
||||
template <typename>
|
||||
static n& test(...);
|
||||
|
||||
public:
|
||||
enum
|
||||
{
|
||||
listFound = sizeof(test<T>(0)) == sizeof(y)
|
||||
};
|
||||
|
||||
typedef typename Internal::PickList<listFound, T>::Result ListType;
|
||||
};
|
||||
|
||||
namespace Internal
|
||||
{
|
||||
template <class TList>
|
||||
struct CompositeQuery;
|
||||
|
||||
template <>
|
||||
struct CompositeQuery<TL::NullType>
|
||||
{
|
||||
template<typename T>
|
||||
static void* Op(const T&, const char*)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
template <class Head, class Tail>
|
||||
struct CompositeQuery<TL::Typelist<Head, Tail> >
|
||||
{
|
||||
template<typename T>
|
||||
static void* Op(const T& ref, const char* name)
|
||||
{
|
||||
void* p = ref.Head::CompositeQueryImpl(name);
|
||||
return p ? p : CompositeQuery<Tail>::Op(ref, name);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
struct CompositeQuery
|
||||
{
|
||||
template <typename T>
|
||||
static void* Op(const T& ref, const char* name)
|
||||
{
|
||||
return Internal::CompositeQuery<typename ProbeFullCompositeList<T>::ListType>::Op(ref, name);
|
||||
}
|
||||
};
|
||||
|
||||
inline bool NameMatch(const char* name, const char* compositeName)
|
||||
{
|
||||
if (!name || !compositeName)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
size_t i = 0;
|
||||
for (; name[i] && name[i] == compositeName[i]; ++i)
|
||||
{
|
||||
}
|
||||
return name[i] == compositeName[i];
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void* CheckCompositeMatch(const char* name, const AZStd::shared_ptr<T>& composite, const char* compositeName)
|
||||
{
|
||||
typedef TC::SuperSubClass<ICryUnknown, T> Rel;
|
||||
COMPILE_TIME_ASSERT(Rel::exists);
|
||||
return NameMatch(name, compositeName) ? const_cast<void*>(static_cast<const void*>(&composite)) : 0;
|
||||
}
|
||||
} // namespace CW
|
||||
|
||||
|
||||
#define CRYINTERFACE_BEGIN() \
|
||||
private: \
|
||||
typedef TL::BuildTypelist < ICryUnknown
|
||||
|
||||
#define CRYINTERFACE_ADD(iname) , iname
|
||||
|
||||
#define CRYINTERFACE_END() > ::Result _UserDefinedPartialInterfaceList; \
|
||||
protected: \
|
||||
typedef TL::NoDuplicates<_UserDefinedPartialInterfaceList>::Result FullInterfaceList;
|
||||
|
||||
#define _CRY_TPL_APPEND0(base) TL::Append<base::FullInterfaceList, _UserDefinedPartialInterfaceList>::Result
|
||||
#define _CRY_TPL_APPEND(base, intermediate) TL::Append<base::FullInterfaceList, intermediate>::Result
|
||||
|
||||
#define CRYINTERFACE_ENDWITHBASE(base) > ::Result _UserDefinedPartialInterfaceList; \
|
||||
protected: \
|
||||
typedef TL::NoDuplicates<_CRY_TPL_APPEND0(base)>::Result FullInterfaceList;
|
||||
|
||||
#define CRYINTERFACE_ENDWITHBASE2(base0, base1) > ::Result _UserDefinedPartialInterfaceList; \
|
||||
protected: \
|
||||
typedef TL::NoDuplicates<_CRY_TPL_APPEND(base0, _CRY_TPL_APPEND0(base1))>::Result FullInterfaceList;
|
||||
|
||||
#define CRYINTERFACE_ENDWITHBASE3(base0, base1, base2) > ::Result _UserDefinedPartialInterfaceList; \
|
||||
protected: \
|
||||
typedef TL::NoDuplicates<_CRY_TPL_APPEND(base0, _CRY_TPL_APPEND(base1, _CRY_TPL_APPEND0(base2)))>::Result FullInterfaceList;
|
||||
|
||||
#define CRYINTERFACE_SIMPLE(iname) \
|
||||
CRYINTERFACE_BEGIN() \
|
||||
CRYINTERFACE_ADD(iname) \
|
||||
CRYINTERFACE_END()
|
||||
|
||||
#define CRYCOMPOSITE_BEGIN() \
|
||||
private: \
|
||||
void* CompositeQueryImpl(const char* name) const \
|
||||
{ \
|
||||
(void)(name); \
|
||||
void* res = 0; (void)(res); \
|
||||
|
||||
#define CRYCOMPOSITE_ADD(member, membername) \
|
||||
COMPILE_TIME_ASSERT((sizeof(membername) / sizeof(membername[0])) > 1); \
|
||||
if ((res = CW::CheckCompositeMatch(name, member, membername)) != 0) { \
|
||||
return res; }
|
||||
|
||||
#define _CRYCOMPOSITE_END(implclassname) \
|
||||
return 0; \
|
||||
}; \
|
||||
protected: \
|
||||
typedef TL::BuildTypelist<implclassname>::Result _PartialCompositeList; \
|
||||
\
|
||||
template <bool, typename S> \
|
||||
friend struct CW::Internal::PickList;
|
||||
|
||||
#define CRYCOMPOSITE_END(implclassname) \
|
||||
_CRYCOMPOSITE_END(implclassname) \
|
||||
protected: \
|
||||
typedef _PartialCompositeList FullCompositeList;
|
||||
|
||||
#define _CRYCOMPOSITE_APPEND0(base) TL::Append<_PartialCompositeList, CW::ProbeFullCompositeList<base>::ListType>::Result
|
||||
#define _CRYCOMPOSITE_APPEND(base, intermediate) TL::Append<intermediate, CW::ProbeFullCompositeList<base>::ListType>::Result
|
||||
|
||||
#define CRYCOMPOSITE_ENDWITHBASE(implclassname, base) \
|
||||
_CRYCOMPOSITE_END(implclassname) \
|
||||
protected: \
|
||||
typedef _CRYCOMPOSITE_APPEND0 (base) FullCompositeList;
|
||||
|
||||
#define CRYCOMPOSITE_ENDWITHBASE2(implclassname, base0, base1) \
|
||||
_CRYCOMPOSITE_END(implclassname) \
|
||||
protected: \
|
||||
typedef TL::NoDuplicates<_CRYCOMPOSITE_APPEND(base1, _CRYCOMPOSITE_APPEND0(base0))>::Result FullCompositeList;
|
||||
|
||||
#define CRYCOMPOSITE_ENDWITHBASE3(implclassname, base0, base1, base2) \
|
||||
_CRYCOMPOSITE_END(implclassname) \
|
||||
protected: \
|
||||
typedef TL::NoDuplicates<_CRYCOMPOSITE_APPEND(base2, _CRYCOMPOSITE_APPEND(base1, _CRYCOMPOSITE_APPEND0(base0)))>::Result FullCompositeList;
|
||||
|
||||
template<typename T>
|
||||
class CFactory
|
||||
: public ICryFactory
|
||||
{
|
||||
public:
|
||||
virtual const char* GetName() const
|
||||
{
|
||||
return T::GetCName();
|
||||
}
|
||||
|
||||
virtual const CryClassID& GetClassID() const
|
||||
{
|
||||
return T::GetCID();
|
||||
}
|
||||
|
||||
virtual bool ClassSupports(const CryInterfaceID& iid) const
|
||||
{
|
||||
for (size_t i = 0; i < m_numIIDs; ++i)
|
||||
{
|
||||
if (iid == m_pIIDs[i])
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual void ClassSupports(const CryInterfaceID*& pIIDs, size_t& numIIDs) const
|
||||
{
|
||||
pIIDs = m_pIIDs;
|
||||
numIIDs = m_numIIDs;
|
||||
}
|
||||
public:
|
||||
virtual ICryUnknownPtr CreateClassInstance() const
|
||||
{
|
||||
AZStd::shared_ptr<T> p = AZStd::make_shared<T>();
|
||||
return cryinterface_cast<ICryUnknown> (p);
|
||||
}
|
||||
|
||||
CFactory<T>()
|
||||
: m_numIIDs(0)
|
||||
, m_pIIDs(0)
|
||||
, m_regFactory()
|
||||
{
|
||||
static CryInterfaceID supportedIIDs[TL::Length < typename T::FullInterfaceList > ::value];
|
||||
CW::FillIIDs<typename T::FullInterfaceList>::Op(supportedIIDs);
|
||||
m_pIIDs = &supportedIIDs[0];
|
||||
m_numIIDs = TL::Length<typename T::FullInterfaceList>::value;
|
||||
new(&m_regFactory)SRegFactoryNode(this);
|
||||
}
|
||||
|
||||
protected:
|
||||
CFactory(const CFactory&);
|
||||
CFactory& operator =(const CFactory&);
|
||||
|
||||
|
||||
size_t m_numIIDs;
|
||||
CryInterfaceID* m_pIIDs;
|
||||
SRegFactoryNode m_regFactory;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class CSingletonFactory
|
||||
: public CFactory<T>
|
||||
{
|
||||
public:
|
||||
CSingletonFactory()
|
||||
: CFactory<T>()
|
||||
, m_csCreateClassInstance()
|
||||
{
|
||||
}
|
||||
|
||||
virtual ICryUnknownPtr CreateClassInstance() const
|
||||
{
|
||||
CryAutoLock<CryCriticalSection> lock(m_csCreateClassInstance);
|
||||
// override the allocator. These function static instances are being destroyed after the AZ alloctor has been deleted.
|
||||
// On win, TerminateProcess() prevents these destructors from being called, but that is not the case on OSX.
|
||||
static typename AZStd::aligned_storage<sizeof(AZStd::Internal::sp_counted_impl_pda<T*, AZStd::Internal::sp_ms_deleter<T>,SingletonAllocator>), AZStd::alignment_of<T>::value>::type m_storage;
|
||||
static ICryUnknownPtr p = AZStd::allocate_shared<T>(SingletonAllocator(AZStd::addressof(m_storage)));
|
||||
return p;
|
||||
}
|
||||
|
||||
mutable CryCriticalSection m_csCreateClassInstance;
|
||||
|
||||
struct SingletonAllocator
|
||||
{
|
||||
SingletonAllocator(void* ptr) :
|
||||
m_data(ptr)
|
||||
{}
|
||||
void* allocate(size_t /*byteSize*/, size_t /*alignment*/, int /*flags*/ = 0)
|
||||
{
|
||||
return m_data;
|
||||
}
|
||||
void deallocate(void* /*ptr*/, size_t /*byteSize*/, size_t /*alignment*/)
|
||||
{
|
||||
// nothing to see here
|
||||
}
|
||||
void* m_data;
|
||||
};
|
||||
};
|
||||
|
||||
#define _CRYFACTORY_DECLARE(implclassname) \
|
||||
private: \
|
||||
friend class CFactory<implclassname>; \
|
||||
static CFactory<implclassname> s_factory;
|
||||
|
||||
#define _CRYFACTORY_DECLARE_SINGLETON(implclassname) \
|
||||
private: \
|
||||
friend class CFactory<implclassname>; \
|
||||
friend void* Get##implclassname##Factory(); \
|
||||
static CSingletonFactory<implclassname> s_factory;
|
||||
|
||||
#define _IMPLEMENT_ICRYUNKNOWN() \
|
||||
public: \
|
||||
virtual ICryFactory* GetFactory() const \
|
||||
{ \
|
||||
return &s_factory; \
|
||||
} \
|
||||
\
|
||||
protected: \
|
||||
virtual void* QueryInterface(const CryInterfaceID&iid) const \
|
||||
{ \
|
||||
return CW::InterfaceCast<FullInterfaceList>::Op(this, iid); \
|
||||
} \
|
||||
\
|
||||
template <class TList> \
|
||||
friend struct CW::Internal::CompositeQuery; \
|
||||
\
|
||||
virtual void* QueryComposite(const char* name) const \
|
||||
{ \
|
||||
return CW::CompositeQuery::Op(*this, name); \
|
||||
}
|
||||
|
||||
#define _ENFORCE_CRYFACTORY_USAGE(implclassname, cname, cidHigh, cidLow) \
|
||||
public: \
|
||||
static const char* GetCName() \
|
||||
{ \
|
||||
return cname; \
|
||||
} \
|
||||
static const CryClassID& GetCID() \
|
||||
{ \
|
||||
static const CryClassID cid = {(uint64) cidHigh##LL, (uint64) cidLow##LL}; \
|
||||
return cid; \
|
||||
} \
|
||||
static AZStd::shared_ptr<implclassname> CreateClassInstance() \
|
||||
{ \
|
||||
ICryUnknownPtr p = s_factory.CreateClassInstance(); \
|
||||
return AZStd::shared_ptr<implclassname>(*static_cast<AZStd::shared_ptr<implclassname>*>(static_cast<void*>(&p))); \
|
||||
} \
|
||||
\
|
||||
protected: \
|
||||
implclassname(); \
|
||||
virtual ~implclassname();
|
||||
|
||||
#define _BEFRIEND_OPS() \
|
||||
_BEFRIEND_CRYINTERFACE_CAST() \
|
||||
_BEFRIEND_CRYCOMPOSITE_QUERY() \
|
||||
_BEFRIEND_MAKE_SHARED()
|
||||
|
||||
#define CRYGENERATE_CLASS(implclassname, cname, cidHigh, cidLow) \
|
||||
_CRYFACTORY_DECLARE(implclassname) \
|
||||
_BEFRIEND_OPS() \
|
||||
_IMPLEMENT_ICRYUNKNOWN() \
|
||||
_ENFORCE_CRYFACTORY_USAGE(implclassname, cname, cidHigh, cidLow)
|
||||
|
||||
#define CRYGENERATE_SINGLETONCLASS(implclassname, cname, cidHigh, cidLow) \
|
||||
_CRYFACTORY_DECLARE_SINGLETON(implclassname) \
|
||||
_BEFRIEND_OPS() \
|
||||
_IMPLEMENT_ICRYUNKNOWN() \
|
||||
_ENFORCE_CRYFACTORY_USAGE(implclassname, cname, cidHigh, cidLow)
|
||||
|
||||
|
||||
#define CRYREGISTER_CLASS(implclassname) \
|
||||
CFactory<implclassname> implclassname::s_factory;
|
||||
|
||||
#define DECLARE_CRYREGISTER_SINGLETON_CLASS(implclassname) \
|
||||
void* Get##implclassname##Factory();
|
||||
|
||||
#define CRYREGISTER_SINGLETON_CLASS(implclassname) \
|
||||
CSingletonFactory<implclassname> implclassname::s_factory; \
|
||||
void* Get##implclassname##Factory() { \
|
||||
return &implclassname::s_factory; \
|
||||
}
|
||||
|
||||
#endif // CRYINCLUDE_CRYEXTENSION_IMPL_CLASSWEAVER_H
|
||||
@@ -1,109 +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 : Part of CryEngine's extension framework.
|
||||
|
||||
|
||||
#ifndef CRYINCLUDE_CRYEXTENSION_IMPL_CONVERSION_H
|
||||
#define CRYINCLUDE_CRYEXTENSION_IMPL_CONVERSION_H
|
||||
#pragma once
|
||||
|
||||
|
||||
namespace TC
|
||||
{
|
||||
//template <class T, class U>
|
||||
//struct Conversion
|
||||
//{
|
||||
//private:
|
||||
// typedef char y[1];
|
||||
// typedef char n[2];
|
||||
// static y& Test(U);
|
||||
// static n& Test(...);
|
||||
// static T MakeT();
|
||||
|
||||
//public:
|
||||
// enum
|
||||
// {
|
||||
// exists = sizeof(Test(MakeT())) == sizeof(y),
|
||||
// sameType = false
|
||||
// };
|
||||
//};
|
||||
|
||||
//template <class T>
|
||||
//struct Conversion<T, T>
|
||||
//{
|
||||
//public:
|
||||
// enum
|
||||
// {
|
||||
// exists = true,
|
||||
// sameType = true
|
||||
// };
|
||||
//};
|
||||
|
||||
//template<typename Base, typename Derived>
|
||||
//struct CheckInheritance
|
||||
//{
|
||||
// enum
|
||||
// {
|
||||
// exists = Conversion<const Derived*, const Base*>::exists && !Conversion<const Base*, const void*>::sameType
|
||||
// };
|
||||
//};
|
||||
|
||||
//template<typename Base, typename Derived>
|
||||
//struct CheckStrictInheritance
|
||||
//{
|
||||
// enum
|
||||
// {
|
||||
// exists = CheckInheritance<Base, Derived>::exists && !Conversion<const Base*, const Derived*>::sameType
|
||||
// };
|
||||
//};
|
||||
|
||||
|
||||
template <typename Base, typename Derived>
|
||||
struct SuperSubClass
|
||||
{
|
||||
private:
|
||||
typedef char y[1];
|
||||
typedef char n[2];
|
||||
|
||||
template<typename T>
|
||||
static y& check(const volatile Derived&, T);
|
||||
static n& check(const volatile Base&, int);
|
||||
|
||||
struct C
|
||||
{
|
||||
operator const volatile Base&() const;
|
||||
operator const volatile Derived&();
|
||||
};
|
||||
|
||||
static C getC();
|
||||
|
||||
public:
|
||||
enum
|
||||
{
|
||||
exists = sizeof(check(getC(), 0)) == sizeof(y),
|
||||
sameType = false
|
||||
};
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct SuperSubClass<T, T>
|
||||
{
|
||||
enum
|
||||
{
|
||||
exists = true
|
||||
};
|
||||
};
|
||||
} // namespace TC
|
||||
|
||||
#endif // CRYINCLUDE_CRYEXTENSION_IMPL_CONVERSION_H
|
||||
@@ -1,67 +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 : Part of CryEngine's extension framework.
|
||||
|
||||
|
||||
#ifndef CRYINCLUDE_CRYEXTENSION_IMPL_CRYGUIDHELPER_H
|
||||
#define CRYINCLUDE_CRYEXTENSION_IMPL_CRYGUIDHELPER_H
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "../CryGUID.h"
|
||||
#include "../../CryString.h"
|
||||
|
||||
|
||||
namespace CryGUIDHelper
|
||||
{
|
||||
string Print(const CryGUID& val)
|
||||
{
|
||||
char buf[39]; // sizeof("{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}")
|
||||
|
||||
static const char hex[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
|
||||
char* p = buf;
|
||||
*p++ = '{';
|
||||
for (int i = 15; i >= 8; --i)
|
||||
{
|
||||
*p++ = hex[(unsigned char) ((val.hipart >> (i << 2)) & 0xF)];
|
||||
}
|
||||
*p++ = '-';
|
||||
for (int i = 7; i >= 4; --i)
|
||||
{
|
||||
*p++ = hex[(unsigned char) ((val.hipart >> (i << 2)) & 0xF)];
|
||||
}
|
||||
*p++ = '-';
|
||||
for (int i = 3; i >= 0; --i)
|
||||
{
|
||||
*p++ = hex[(unsigned char) ((val.hipart >> (i << 2)) & 0xF)];
|
||||
}
|
||||
*p++ = '-';
|
||||
for (int i = 15; i >= 12; --i)
|
||||
{
|
||||
*p++ = hex[(unsigned char) ((val.lopart >> (i << 2)) & 0xF)];
|
||||
}
|
||||
*p++ = '-';
|
||||
for (int i = 11; i >= 0; --i)
|
||||
{
|
||||
*p++ = hex[(unsigned char) ((val.lopart >> (i << 2)) & 0xF)];
|
||||
}
|
||||
*p++ = '}';
|
||||
*p++ = '\0';
|
||||
|
||||
return string(buf);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif // CRYINCLUDE_CRYEXTENSION_IMPL_CRYGUIDHELPER_H
|
||||
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
// Description : Part of CryEngine's extension framework.
|
||||
|
||||
|
||||
#ifndef CRYINCLUDE_CRYEXTENSION_IMPL_ICRYFACTORYREGISTRYIMPL_H
|
||||
#define CRYINCLUDE_CRYEXTENSION_IMPL_ICRYFACTORYREGISTRYIMPL_H
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "../ICryFactoryRegistry.h"
|
||||
|
||||
|
||||
struct SRegFactoryNode;
|
||||
|
||||
|
||||
struct ICryFactoryRegistryCallback
|
||||
{
|
||||
virtual void OnNotifyFactoryRegistered(ICryFactory* pFactory) = 0;
|
||||
virtual void OnNotifyFactoryUnregistered(ICryFactory* pFactory) = 0;
|
||||
|
||||
protected:
|
||||
virtual ~ICryFactoryRegistryCallback() {}
|
||||
};
|
||||
|
||||
|
||||
struct ICryFactoryRegistryImpl
|
||||
: public ICryFactoryRegistry
|
||||
{
|
||||
virtual ICryFactory* GetFactory(const char* cname) const = 0;
|
||||
virtual ICryFactory* GetFactory(const CryClassID& cid) const = 0;
|
||||
virtual void IterateFactories(const CryInterfaceID& iid, ICryFactory** pFactories, size_t& numFactories) const = 0;
|
||||
|
||||
virtual void RegisterCallback(ICryFactoryRegistryCallback* pCallback) = 0;
|
||||
virtual void UnregisterCallback(ICryFactoryRegistryCallback* pCallback) = 0;
|
||||
|
||||
virtual void RegisterFactories(const SRegFactoryNode* pFactories) = 0;
|
||||
virtual void UnregisterFactories(const SRegFactoryNode* pFactories) = 0;
|
||||
|
||||
virtual void UnregisterFactory(ICryFactory* const pFactory) = 0;
|
||||
|
||||
protected:
|
||||
// prevent explicit destruction from client side (delete, shared_ptr, etc)
|
||||
virtual ~ICryFactoryRegistryImpl() {}
|
||||
};
|
||||
|
||||
#endif // CRYINCLUDE_CRYEXTENSION_IMPL_ICRYFACTORYREGISTRYIMPL_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.
|
||||
|
||||
// Description : Part of CryEngine's extension framework.
|
||||
|
||||
|
||||
#ifndef CRYINCLUDE_CRYEXTENSION_IMPL_REGFACTORYNODE_H
|
||||
#define CRYINCLUDE_CRYEXTENSION_IMPL_REGFACTORYNODE_H
|
||||
#pragma once
|
||||
|
||||
struct ICryFactory;
|
||||
struct SRegFactoryNode;
|
||||
|
||||
extern SRegFactoryNode* g_pHeadToRegFactories;
|
||||
|
||||
struct SRegFactoryNode
|
||||
{
|
||||
SRegFactoryNode()
|
||||
{
|
||||
}
|
||||
|
||||
SRegFactoryNode(ICryFactory* pFactory)
|
||||
: m_pFactory(pFactory)
|
||||
, m_pNext(g_pHeadToRegFactories)
|
||||
{
|
||||
g_pHeadToRegFactories = this;
|
||||
}
|
||||
|
||||
static void* operator new(size_t, void* p)
|
||||
{
|
||||
return p;
|
||||
}
|
||||
|
||||
static void operator delete(void*, void*)
|
||||
{
|
||||
}
|
||||
|
||||
ICryFactory* m_pFactory;
|
||||
SRegFactoryNode* m_pNext;
|
||||
};
|
||||
|
||||
#endif // CRYINCLUDE_CRYEXTENSION_IMPL_REGFACTORYNODE_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.
|
||||
|
||||
// Description : Part of CryEngine's extension framework.
|
||||
|
||||
|
||||
#ifndef CRYINCLUDE_CRYEXTENSION_TYPELIST_H
|
||||
#define CRYINCLUDE_CRYEXTENSION_TYPELIST_H
|
||||
#pragma once
|
||||
|
||||
|
||||
namespace TL
|
||||
{
|
||||
// typelist terminator
|
||||
class NullType
|
||||
{
|
||||
};
|
||||
|
||||
|
||||
// structure for typelist generation
|
||||
template <class T, class U = NullType>
|
||||
struct Typelist
|
||||
{
|
||||
typedef T Head;
|
||||
typedef U Tail;
|
||||
};
|
||||
|
||||
|
||||
// helper structure to automatically build typelists containing n types
|
||||
template
|
||||
<
|
||||
typename T0 = NullType, typename T1 = NullType, typename T2 = NullType, typename T3 = NullType, typename T4 = NullType,
|
||||
typename T5 = NullType, typename T6 = NullType, typename T7 = NullType, typename T8 = NullType, typename T9 = NullType,
|
||||
typename T10 = NullType, typename T11 = NullType, typename T12 = NullType, typename T13 = NullType, typename T14 = NullType,
|
||||
typename T15 = NullType, typename T16 = NullType, typename T17 = NullType, typename T18 = NullType, typename T19 = NullType
|
||||
>
|
||||
struct BuildTypelist
|
||||
{
|
||||
private:
|
||||
typedef typename BuildTypelist<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19>::Result TailResult;
|
||||
|
||||
public:
|
||||
typedef Typelist<T0, TailResult> Result;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct BuildTypelist<>
|
||||
{
|
||||
typedef NullType Result;
|
||||
};
|
||||
|
||||
// typelist operation : Length
|
||||
template <class TList>
|
||||
struct Length;
|
||||
|
||||
template <>
|
||||
struct Length<NullType>
|
||||
{
|
||||
enum
|
||||
{
|
||||
value = 0
|
||||
};
|
||||
};
|
||||
|
||||
template <class T, class U>
|
||||
struct Length<Typelist<T, U> >
|
||||
{
|
||||
enum
|
||||
{
|
||||
value = 1 + Length<U>::value
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
// typelist operation : TypeAt
|
||||
template <class TList, unsigned int index>
|
||||
struct TypeAt;
|
||||
|
||||
template <class Head, class Tail>
|
||||
struct TypeAt<Typelist<Head, Tail>, 0>
|
||||
{
|
||||
typedef Head Result;
|
||||
};
|
||||
|
||||
template <class Head, class Tail, unsigned int index>
|
||||
struct TypeAt<Typelist<Head, Tail>, index>
|
||||
{
|
||||
typedef typename TypeAt<Tail, index - 1>::Result Result;
|
||||
};
|
||||
|
||||
|
||||
// typelist operation : IndexOf
|
||||
template <class TList, class T>
|
||||
struct IndexOf;
|
||||
|
||||
template <class T>
|
||||
struct IndexOf<NullType, T>
|
||||
{
|
||||
enum
|
||||
{
|
||||
value = -1
|
||||
};
|
||||
};
|
||||
|
||||
template <class T, class Tail>
|
||||
struct IndexOf<Typelist<T, Tail>, T>
|
||||
{
|
||||
enum
|
||||
{
|
||||
value = 0
|
||||
};
|
||||
};
|
||||
|
||||
template <class Head, class Tail, class T>
|
||||
struct IndexOf<Typelist<Head, Tail>, T>
|
||||
{
|
||||
private:
|
||||
enum
|
||||
{
|
||||
temp = IndexOf<Tail, T>::value
|
||||
};
|
||||
public:
|
||||
enum
|
||||
{
|
||||
value = temp == -1 ? -1 : 1 + temp
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
// typelist operation : Append
|
||||
template <class TList, class T>
|
||||
struct Append;
|
||||
|
||||
template <>
|
||||
struct Append<NullType, NullType>
|
||||
{
|
||||
typedef NullType Result;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct Append<NullType, T>
|
||||
{
|
||||
typedef Typelist<T, NullType> Result;
|
||||
};
|
||||
|
||||
template <class Head, class Tail>
|
||||
struct Append<NullType, Typelist<Head, Tail> >
|
||||
{
|
||||
typedef Typelist<Head, Tail> Result;
|
||||
};
|
||||
|
||||
template <class Head, class Tail, class T>
|
||||
struct Append<Typelist<Head, Tail>, T>
|
||||
{
|
||||
typedef Typelist<Head, typename Append<Tail, T>::Result> Result;
|
||||
};
|
||||
|
||||
|
||||
// typelist operation : Erase
|
||||
template <class TList, class T>
|
||||
struct Erase;
|
||||
|
||||
template <class T>
|
||||
struct Erase<NullType, T>
|
||||
{
|
||||
typedef NullType Result;
|
||||
};
|
||||
|
||||
template <class T, class Tail>
|
||||
struct Erase<Typelist<T, Tail>, T>
|
||||
{
|
||||
typedef Tail Result;
|
||||
};
|
||||
|
||||
template <class Head, class Tail, class T>
|
||||
struct Erase<Typelist<Head, Tail>, T>
|
||||
{
|
||||
typedef Typelist<Head, typename Erase<Tail, T>::Result> Result;
|
||||
};
|
||||
|
||||
|
||||
// typelist operation : Erase All
|
||||
template <class TList, class T>
|
||||
struct EraseAll;
|
||||
|
||||
template <class T>
|
||||
struct EraseAll<NullType, T>
|
||||
{
|
||||
typedef NullType Result;
|
||||
};
|
||||
|
||||
template <class T, class Tail>
|
||||
struct EraseAll<Typelist<T, Tail>, T>
|
||||
{
|
||||
typedef typename EraseAll<Tail, T>::Result Result;
|
||||
};
|
||||
|
||||
template <class Head, class Tail, class T>
|
||||
struct EraseAll<Typelist<Head, Tail>, T>
|
||||
{
|
||||
typedef Typelist<Head, typename EraseAll<Tail, T>::Result> Result;
|
||||
};
|
||||
|
||||
|
||||
// typelist operation : NoDuplicates
|
||||
template <class TList>
|
||||
struct NoDuplicates;
|
||||
|
||||
template <>
|
||||
struct NoDuplicates<NullType>
|
||||
{
|
||||
typedef NullType Result;
|
||||
};
|
||||
|
||||
template <class Head, class Tail>
|
||||
struct NoDuplicates<Typelist<Head, Tail> >
|
||||
{
|
||||
private:
|
||||
typedef typename NoDuplicates<Tail>::Result L1;
|
||||
typedef typename Erase<L1, Head>::Result L2;
|
||||
public:
|
||||
typedef Typelist<Head, L2> Result;
|
||||
};
|
||||
} // namespace TL
|
||||
|
||||
#endif // CRYINCLUDE_CRYEXTENSION_TYPELIST_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,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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AzCore/EBus/EBus.h>
|
||||
|
||||
#include <CryCommon/ISystem.h>
|
||||
|
||||
namespace AZ
|
||||
{
|
||||
/*!
|
||||
* Signal LY to create an ICryFont
|
||||
*/
|
||||
class CryFontCreationRequests
|
||||
: public AZ::EBusTraits
|
||||
{
|
||||
public:
|
||||
using MutexType = AZStd::recursive_mutex;
|
||||
static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single;
|
||||
static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single;
|
||||
|
||||
virtual bool CreateCryFont([[maybe_unused]] SSystemGlobalEnvironment& env, [[maybe_unused]] const SSystemInitParams& initParams) {return false;} //! return false to fall back to default CryFont initialization
|
||||
};
|
||||
using CryFontCreationRequestBus = AZ::EBus<CryFontCreationRequests>;
|
||||
|
||||
}
|
||||
@@ -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,298 +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 IDefragAllocator;
|
||||
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;
|
||||
|
||||
virtual IDefragAllocator* CreateDefragAllocator() = 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,207 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
#ifndef CRYINCLUDE_CRYPOOL_ALLOCATOR_H
|
||||
#define CRYINCLUDE_CRYPOOL_ALLOCATOR_H
|
||||
#pragma once
|
||||
|
||||
|
||||
namespace NCryPoolAlloc
|
||||
{
|
||||
template<class TPool, class TItem>
|
||||
class CFirstFit
|
||||
: public TPool
|
||||
{
|
||||
public:
|
||||
ILINE CFirstFit()
|
||||
{
|
||||
}
|
||||
|
||||
template<class T>
|
||||
ILINE T Allocate(size_t Size, size_t Align = 1)
|
||||
{
|
||||
//fastpath?
|
||||
if (TPool::m_pEmpty && TPool::m_pEmpty->Available(Size, Align))
|
||||
{
|
||||
TItem* pItem = TPool::Split(TPool::m_pEmpty, Size, Align);
|
||||
if (!pItem)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
pItem->InUse(Align);
|
||||
TPool::AllocatedMemory(pItem->MemSize());
|
||||
|
||||
//not fully occupied empty space?
|
||||
TPool::m_pEmpty = pItem != TPool::m_pEmpty ? TPool::m_pEmpty : 0;
|
||||
return TPool::Handle(pItem);
|
||||
}
|
||||
|
||||
TItem* pBestItem;
|
||||
for (pBestItem = TPool::m_Items.First(); pBestItem; pBestItem = pBestItem->Next())
|
||||
{
|
||||
if (pBestItem->Available(Size, Align)) // && (!pBestItem || pItem->MemSize()<pBestItem->MemSize()))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!pBestItem)
|
||||
{
|
||||
return 0; //out of mem
|
||||
}
|
||||
TItem* pItem = TPool::Split(pBestItem, Size, Align);
|
||||
if (!pItem) //no free node
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
pItem->InUse(Align);
|
||||
TPool::AllocatedMemory(pItem->MemSize());
|
||||
|
||||
//not fully occupied empty space?
|
||||
TPool::m_pEmpty = pItem != pBestItem ? pBestItem : 0;
|
||||
return TPool::Handle(pItem);
|
||||
}
|
||||
template<class T>
|
||||
ILINE bool Free(T Handle, bool ForceBoundsCheck = false)
|
||||
{
|
||||
return Handle ? TPool::Free(Handle, ForceBoundsCheck) : false;
|
||||
}
|
||||
};
|
||||
|
||||
template<class TPool, class TItem>
|
||||
class CWorstFit
|
||||
: public TPool
|
||||
{
|
||||
public:
|
||||
ILINE CWorstFit()
|
||||
{
|
||||
}
|
||||
|
||||
template<class T>
|
||||
ILINE T Allocate(size_t Size, size_t Align = 1)
|
||||
{
|
||||
TItem* pBestItem = 0;
|
||||
for (TItem* pItem = TPool::m_Items.First(); pItem; pItem = pItem->Next())
|
||||
{
|
||||
if (pItem->IsFree() && (!pBestItem || pItem->MemSize() > pBestItem->MemSize()))
|
||||
{
|
||||
pBestItem = pItem;
|
||||
}
|
||||
}
|
||||
if (!pBestItem || !pBestItem->Available(Size, Align))
|
||||
{
|
||||
return 0; //out of mem
|
||||
}
|
||||
TItem* pItem = Split(pBestItem, Size, Align);
|
||||
if (!pItem) //no free node
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
pItem->InUse(Align);
|
||||
AllocatedMemory(pItem->MemSize());
|
||||
return Handle(pItem);
|
||||
}
|
||||
};
|
||||
|
||||
template<class TPool, class TItem>
|
||||
class CBestFit
|
||||
: public TPool
|
||||
{
|
||||
public:
|
||||
ILINE CBestFit()
|
||||
{
|
||||
}
|
||||
|
||||
template<class T>
|
||||
ILINE T Allocate(size_t Size, size_t Align = 1)
|
||||
{
|
||||
TItem* pBestItem = 0;
|
||||
for (TItem* pItem = TPool::m_Items.First(); pItem; pItem = pItem->Next())
|
||||
{
|
||||
if ((!pBestItem || pItem->MemSize() < pBestItem->MemSize()) && pItem->Available(Size, Align))
|
||||
{
|
||||
if (pItem->MemSize() == Size)
|
||||
{
|
||||
pItem->InUse(Align);
|
||||
AllocatedMemory(pItem->MemSize());
|
||||
return (T)Handle(pItem);
|
||||
}
|
||||
pBestItem = pItem;
|
||||
}
|
||||
}
|
||||
if (!pBestItem)
|
||||
{
|
||||
return 0; //out of mem
|
||||
}
|
||||
TItem* pItem = Split(pBestItem, Size, Align);
|
||||
if (!pItem) //no free node
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
pItem->InUse(Align);
|
||||
AllocatedMemory(pItem->MemSize());
|
||||
return (T)Handle(pItem);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template<class TAllocator>
|
||||
class CReallocator
|
||||
: public TAllocator
|
||||
{
|
||||
public:
|
||||
|
||||
template<class T>
|
||||
ILINE bool Reallocate(T* pData, size_t Size, size_t Alignment)
|
||||
{
|
||||
//special cases
|
||||
if (!Size) //just free?
|
||||
{
|
||||
TAllocator::Free(*pData);
|
||||
*pData = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!*pData) //just alloc?
|
||||
{
|
||||
*pData = TAllocator::template Allocate<T>(Size, Alignment);
|
||||
return *pData != 0;
|
||||
}
|
||||
|
||||
//same size, nothing to do at all?
|
||||
if (TAllocator::Item(*pData)->MemSize() == Size)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (TAllocator::ReSize(pData, Size))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
T pNewData = TAllocator::template Allocate<T>(Size, Alignment);
|
||||
if (!pNewData)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
memcpy(TAllocator::template Resolve<uint8*>(pNewData),
|
||||
TAllocator::template Resolve<uint8*>(*pData), min(TAllocator::Item(*pData)->MemSize(), Size));
|
||||
TAllocator::template Free(*pData);
|
||||
*pData = pNewData;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif // CRYINCLUDE_CRYPOOL_ALLOCATOR_H
|
||||
|
||||
@@ -1,655 +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_CRYPOOL_CONTAINER_H
|
||||
#define CRYINCLUDE_CRYPOOL_CONTAINER_H
|
||||
#pragma once
|
||||
|
||||
|
||||
namespace NCryPoolAlloc
|
||||
{
|
||||
template<size_t TElementCount, class TElement>
|
||||
class CPool
|
||||
: public CMemoryStatic<TElementCount* sizeof(TElement)>
|
||||
{
|
||||
class CPoolNode;
|
||||
class CPoolNode
|
||||
: public CListItem<CPoolNode>
|
||||
{
|
||||
};
|
||||
CList<CPoolNode> m_List;
|
||||
public:
|
||||
ILINE CPool()
|
||||
{
|
||||
CPoolNode* pPrev = 0;
|
||||
CPoolNode* pNode = 0;
|
||||
for (size_t a = 1; a < TElementCount; a++) //skip first element as it would be counted as zero ptr
|
||||
{
|
||||
uint8* pData = &CMemoryStatic<TElementCount* sizeof(TElement)>::Data()[a * sizeof(TElement)];
|
||||
pNode = reinterpret_cast<CPoolNode*>(pData);
|
||||
pNode->Prev(pPrev);
|
||||
if (pPrev)
|
||||
{
|
||||
pPrev->Next(pNode);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_List.First(pNode);
|
||||
}
|
||||
pPrev = pNode;
|
||||
// m_List.AddLast(pNode);
|
||||
}
|
||||
if (pPrev)
|
||||
{
|
||||
pPrev->Next(0);
|
||||
m_List.Last(pPrev);
|
||||
}
|
||||
}
|
||||
ILINE uint8* Allocate([[maybe_unused]] size_t Size, [[maybe_unused]] size_t Align = 1)
|
||||
{
|
||||
CPoolNode* pNode = m_List.PopFirst();
|
||||
return reinterpret_cast<uint8*>(pNode);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
ILINE void Free(T* pData)
|
||||
{
|
||||
if (pData)
|
||||
{
|
||||
CPoolNode* pNode = reinterpret_cast<CPoolNode*>(pData);
|
||||
m_List.AddLast(pNode);
|
||||
}
|
||||
}
|
||||
|
||||
ILINE TElement& operator[](uint32 Idx)
|
||||
{
|
||||
uint8* pData = &CMemoryStatic<TElementCount* sizeof(TElement)>::Data()[Idx * sizeof(TElement)];
|
||||
return *reinterpret_cast<TElement*>(pData);
|
||||
}
|
||||
|
||||
ILINE const TElement& operator[](uint32 Idx) const
|
||||
{
|
||||
const uint8* pData = &CMemoryStatic<TElementCount* sizeof(TElement)>::Data()[Idx * sizeof(TElement)];
|
||||
return *reinterpret_cast<const TElement*>(pData);
|
||||
}
|
||||
};
|
||||
|
||||
template<class TMemory, bool BoundsCheck = false>
|
||||
class CInPlace
|
||||
: public TMemory
|
||||
{
|
||||
protected:
|
||||
CList<CListItemInPlace> m_Items;
|
||||
size_t m_Allocated;
|
||||
CListItemInPlace* m_pEmpty;
|
||||
|
||||
|
||||
ILINE void AllocatedMemory(size_t S)
|
||||
{
|
||||
m_Allocated += S + sizeof(CListItemInPlace);
|
||||
}
|
||||
ILINE void FreedMemory(size_t S)
|
||||
{
|
||||
m_Allocated -= S + sizeof(CListItemInPlace);
|
||||
}
|
||||
ILINE void Stack(CListItemInPlace* pItem)
|
||||
{
|
||||
}
|
||||
public:
|
||||
ILINE CInPlace()
|
||||
: m_Allocated(0)
|
||||
{
|
||||
}
|
||||
|
||||
ILINE void InitMem(const size_t S = 0, uint8* pData = 0)
|
||||
{
|
||||
TMemory::InitMem(S, pData);
|
||||
if (!TMemory::MemSize())
|
||||
{
|
||||
return;
|
||||
}
|
||||
pData = TMemory::Data();
|
||||
CListItemInPlace* pFirst = reinterpret_cast<CListItemInPlace*>(pData);
|
||||
CListItemInPlace* pFree = pFirst + 1;
|
||||
CListItemInPlace* pLast = reinterpret_cast<CListItemInPlace*>(pData + TMemory::MemSize()) - 1;
|
||||
m_Items.~CList<CListItemInPlace>();
|
||||
new (&m_Items)CList<CListItemInPlace>();
|
||||
m_Items.AddLast(pFirst);
|
||||
m_Items.AddLast(pFree);
|
||||
m_Items.AddLast(pLast);
|
||||
|
||||
pFirst->InUse(0); //static first item
|
||||
pFree->Free();
|
||||
pLast->InUse(0); //static last item
|
||||
m_pEmpty = pFree;
|
||||
m_Allocated = 0;
|
||||
}
|
||||
|
||||
ILINE size_t FragmentCount() const
|
||||
{
|
||||
return m_Items.Count();
|
||||
}
|
||||
|
||||
ILINE CListItemInPlace* Split(CListItemInPlace* pItem, size_t Size, size_t Align)
|
||||
{
|
||||
size_t Offset = reinterpret_cast<size_t>(pItem->Data());
|
||||
Offset += pItem->MemSize(); //ptr to end
|
||||
Offset -= Size; //minus size
|
||||
Size += Offset & (Align - 1); //adjust size to fit required alignment
|
||||
Offset -= Offset & (Align - 1);
|
||||
size_t TSize = sizeof(CListItemInPlace);
|
||||
Offset -= TSize; //header
|
||||
|
||||
if (Offset <= reinterpret_cast<size_t>(pItem + 1)) //not enough space for splitting?
|
||||
{
|
||||
return pItem;
|
||||
}
|
||||
|
||||
CListItemInPlace* pItemNext = reinterpret_cast<CListItemInPlace*>(Offset);
|
||||
|
||||
const size_t Offset2 = reinterpret_cast<size_t>(pItemNext->Data());
|
||||
CPA_ASSERT(!(Offset2 & (Align - 1)));
|
||||
m_Items.AddBehind(pItemNext, pItem);
|
||||
//pItemNext->Prev(pItem);
|
||||
//pItemNext->Next(pItem->Next());
|
||||
|
||||
// if(pItem->Next())
|
||||
// pItem->Next()->Prev(pItemNext);
|
||||
|
||||
// pItem->Next(pItemNext);
|
||||
pItemNext->Free();
|
||||
return pItemNext;
|
||||
}
|
||||
|
||||
ILINE void Merge(CListItemInPlace* pItem)
|
||||
{
|
||||
//merge with next if possible
|
||||
CListItemInPlace* pItemNext = pItem->Next();
|
||||
if (pItemNext->IsFree())
|
||||
{
|
||||
if (m_pEmpty == pItemNext)
|
||||
{
|
||||
m_pEmpty = pItem;
|
||||
}
|
||||
m_Items.Remove(pItemNext);
|
||||
//pItem->Next(pItemNext->Next());
|
||||
//pItem->Next()->Prev(pItem);
|
||||
}
|
||||
//merge with prev if possible
|
||||
CListItemInPlace* pItemPrev = pItem->Prev();
|
||||
if (pItemPrev->IsFree())
|
||||
{
|
||||
if (m_pEmpty == pItem)
|
||||
{
|
||||
m_pEmpty = pItemPrev;
|
||||
}
|
||||
m_Items.Remove(pItem);
|
||||
//pItemPrev->Next(pItem->Next());
|
||||
//pItem->Next()->Prev(pItemPrev);
|
||||
pItem = pItemPrev;
|
||||
}
|
||||
}
|
||||
template<class T>
|
||||
ILINE T Resolve(void* rItem) const
|
||||
{
|
||||
return reinterpret_cast<T>(rItem);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
ILINE size_t Size(const T* pData) const
|
||||
{
|
||||
const CListItemInPlace* pItem = Item(pData);
|
||||
return pItem->MemSize();
|
||||
}
|
||||
|
||||
bool InBounds(const void* pData, const bool Check) const
|
||||
{
|
||||
return !Check || (
|
||||
reinterpret_cast<size_t>(pData) >= reinterpret_cast<size_t>(TMemory::Data()) &&
|
||||
reinterpret_cast<size_t>(pData) < reinterpret_cast<size_t>(TMemory::Data()) + TMemory::MemSize());
|
||||
}
|
||||
|
||||
template<class T>
|
||||
ILINE bool Free(T* pData, bool ForceBoundsCheck = false)
|
||||
{
|
||||
if (pData && InBounds(pData, BoundsCheck | ForceBoundsCheck))
|
||||
{
|
||||
CListItemInPlace* pItem = Item(pData);
|
||||
FreedMemory(pItem->MemSize());
|
||||
pItem->Free();
|
||||
Merge(pItem);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
ILINE bool Beat(){return false; }//dummy beat in case no defragmentator is wraping
|
||||
ILINE size_t MemFree() const{return TMemory::MemSize() - m_Allocated; }
|
||||
ILINE size_t MemSize() const{return TMemory::MemSize(); }
|
||||
|
||||
ILINE uint8* Handle(CListItemInPlace* pItem) const
|
||||
{
|
||||
return pItem->Data();
|
||||
}
|
||||
template<class T>
|
||||
ILINE CListItemInPlace* Item(T* pData)
|
||||
{
|
||||
return reinterpret_cast<CListItemInPlace*>(pData) - 1;
|
||||
}
|
||||
template<class T>
|
||||
ILINE const CListItemInPlace* Item(const T* pData) const
|
||||
{
|
||||
return reinterpret_cast<const CListItemInPlace*>(pData) - 1;
|
||||
}
|
||||
ILINE static bool Defragmentable(){return false; }
|
||||
|
||||
template<class T>
|
||||
ILINE bool ReSize(T* pData, size_t SizeNew)
|
||||
{
|
||||
//special cases
|
||||
CListItemInPlace* pItem = Item(*pData);
|
||||
const size_t SizeOld = pItem->MemSize();
|
||||
|
||||
//reduction
|
||||
if (SizeOld > SizeNew)
|
||||
{
|
||||
if (pItem->Next()->IsFree())
|
||||
{
|
||||
CListItemInPlace* pNextNext = pItem->Next()->Next();
|
||||
size_t Offset = reinterpret_cast<size_t>(pItem->Data());
|
||||
Offset += SizeNew; //Offset to next
|
||||
CListItemInPlace* pItemNext = reinterpret_cast<CListItemInPlace*>(Offset);
|
||||
pItem->Next(pItemNext);
|
||||
pNextNext->Prev(pItemNext);
|
||||
pItemNext->Prev(pItem);
|
||||
pItemNext->Next(pNextNext);
|
||||
pItemNext->Free();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (SizeOld - SizeNew <= sizeof(CListItemInPlace))
|
||||
{
|
||||
return true; //header is bigger than the amount of freed memory
|
||||
}
|
||||
//split
|
||||
size_t Offset = reinterpret_cast<size_t>(pItem->Data());
|
||||
Offset += SizeNew; //Offset to next
|
||||
CListItemInPlace* pItemNext = reinterpret_cast<CListItemInPlace*>(Offset);
|
||||
m_Items.AddBehind(pItemNext, pItem);
|
||||
pItemNext->Free();
|
||||
return true;
|
||||
}
|
||||
|
||||
//SizeOld<SizeNew grow
|
||||
CListItemInPlace* pNext = pItem->Next();
|
||||
CListItemInPlace* pNextNext = pNext->Next();
|
||||
const size_t SizeNext = pNext->IsFree() ? pNext->MemSize() + sizeof(CListItemInPlace) : 0;
|
||||
if (SizeNew <= SizeNext + SizeOld)
|
||||
{
|
||||
if (SizeNew + sizeof(CListItemInPlace) + 1 < SizeNext + SizeOld)
|
||||
{
|
||||
size_t Offset = reinterpret_cast<size_t>(pItem->Data());
|
||||
Offset += SizeNew; //Offset to next
|
||||
CListItemInPlace* pItemNext = reinterpret_cast<CListItemInPlace*>(Offset);
|
||||
pItem->Next(pItemNext);
|
||||
pNextNext->Prev(pItemNext);
|
||||
pItemNext->Prev(pItem);
|
||||
pItemNext->Next(pNextNext);
|
||||
pItemNext->Free();
|
||||
}
|
||||
else
|
||||
{
|
||||
pItem->Next(pNextNext);
|
||||
pNextNext->Prev(pItem);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false; //no further in-place realloc possible
|
||||
}
|
||||
};
|
||||
|
||||
template<class TMemory, size_t TNodeCount, bool BoundsCheck = false>
|
||||
class CReferenced
|
||||
: public TMemory
|
||||
{
|
||||
typedef CPool<TNodeCount, CListItemReference> tdNodePool;
|
||||
|
||||
protected:
|
||||
tdNodePool m_NodePool;
|
||||
CList<CListItemReference> m_Items;
|
||||
size_t m_Allocated;
|
||||
CListItemReference* m_pEmpty;
|
||||
|
||||
ILINE void AllocatedMemory(size_t S)
|
||||
{
|
||||
m_Allocated += S;
|
||||
}
|
||||
ILINE void FreedMemory(size_t S)
|
||||
{
|
||||
m_Allocated -= S;
|
||||
}
|
||||
ILINE void Stack(CListItemReference* pItem)
|
||||
{
|
||||
m_Items.Validate(pItem);
|
||||
CListItemReference* pItem2 = 0;
|
||||
CListItemReference* pNext = pItem->Next();
|
||||
uint8* pData = pItem->Data(pNext->Align());
|
||||
if (pData != pItem->Data()) //needs splitting 'cause of alignment?
|
||||
{
|
||||
pItem2 = reinterpret_cast<CListItemReference*>(m_NodePool.Allocate(1, 1));
|
||||
if (!pItem2) //no free node found for splitting?
|
||||
{
|
||||
return; //failed to stack -> return
|
||||
}
|
||||
}
|
||||
|
||||
memmove(pData, pNext->Data(), pNext->MemSize());
|
||||
|
||||
if (pItem2) //was not aligned?
|
||||
{
|
||||
//then keep the current ITem
|
||||
const size_t SizeItem = pItem->MemSize();
|
||||
const size_t SizeNext = pNext->MemSize();
|
||||
m_Items.AddBehind(pItem2, pNext);
|
||||
pItem2->Data(pData + SizeNext);
|
||||
pNext->Data(pData);
|
||||
pItem2->MemSize(pItem2->Next()->Data() - pItem2->Data());
|
||||
pNext->MemSize(SizeNext);
|
||||
pItem->MemSize(pNext->Data() - pItem->Data());
|
||||
m_Items.Validate(pItem);
|
||||
m_Items.Validate(pItem2);
|
||||
m_Items.Validate(pNext);
|
||||
}
|
||||
else
|
||||
{
|
||||
const size_t SizeItem = pItem->MemSize();
|
||||
const size_t SizeNext = pNext->MemSize();
|
||||
m_Items.Remove(pItem);
|
||||
m_Items.AddBehind(pItem, pNext);
|
||||
pItem->Data(pNext->Data());
|
||||
pNext->Data(pData);
|
||||
pNext->MemSize(SizeItem);
|
||||
pItem->MemSize(SizeNext);
|
||||
m_Items.Validate(pItem);
|
||||
m_Items.Validate(pNext);
|
||||
}
|
||||
}
|
||||
public:
|
||||
ILINE CReferenced()
|
||||
: m_Allocated(0)
|
||||
{
|
||||
}
|
||||
|
||||
ILINE void InitMem(const size_t S = 0, uint8* pData = 0)
|
||||
{
|
||||
TMemory::InitMem(S, pData);
|
||||
if (!TMemory::MemSize())
|
||||
{
|
||||
return;
|
||||
}
|
||||
pData = TMemory::Data();
|
||||
CListItemReference* pItem = reinterpret_cast<CListItemReference*>(m_NodePool.Allocate(1, 1));
|
||||
CListItemReference* pLast = reinterpret_cast<CListItemReference*>(m_NodePool.Allocate(1, 1));
|
||||
m_Items.AddFirst(pItem);
|
||||
m_Items.AddLast(pLast);
|
||||
pLast->Init(pData + TMemory::MemSize(), 0, pItem, 0);
|
||||
pLast->InUse(0);
|
||||
pItem->Init(pData, TMemory::MemSize(), 0, pLast);
|
||||
pItem->Free();
|
||||
m_pEmpty = pItem;
|
||||
m_Allocated = 0;
|
||||
}
|
||||
|
||||
ILINE size_t FragmentCount() const
|
||||
{
|
||||
return m_Items.Count();
|
||||
}
|
||||
|
||||
ILINE CListItemReference* Split(CListItemReference* pItem, size_t Size, size_t Align)
|
||||
{
|
||||
size_t Offset = reinterpret_cast<size_t>(pItem->Data());
|
||||
if (!(Offset & (Align - 1))) //perfectly aligned?
|
||||
{
|
||||
if (pItem->MemSize() != Size) //not perfectly fitting?
|
||||
{ //then split
|
||||
CListItemReference* pItemPrev = reinterpret_cast<CListItemReference*>(m_NodePool.Allocate(1, 1));
|
||||
if (!pItemPrev)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
const size_t OrgSize = pItem->MemSize();
|
||||
m_Items.AddBefore(pItemPrev, pItem);
|
||||
pItemPrev->Data(pItem->Data());
|
||||
pItem->Data(pItem->Data() + Size);
|
||||
pItem->MemSize(OrgSize - Size);
|
||||
pItemPrev->MemSize(Size);
|
||||
pItem = pItemPrev;
|
||||
}
|
||||
return pItem;
|
||||
}
|
||||
|
||||
//not aligned to block start
|
||||
//then lets try to align to block end
|
||||
Offset += pItem->MemSize(); //ptr to end
|
||||
Offset -= Size; //minus size
|
||||
if (!(Offset & (Align - 1))) //perfectly aligned?
|
||||
{
|
||||
CListItemReference* pItemPrev = reinterpret_cast<CListItemReference*>(m_NodePool.Allocate(1, 1));
|
||||
if (!pItemPrev)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
const size_t OrgSize = pItem->MemSize();
|
||||
m_Items.AddBefore(pItemPrev, pItem);
|
||||
pItemPrev->Data(pItem->Data());
|
||||
pItem->Data(reinterpret_cast<uint8*>(Offset));
|
||||
pItemPrev->MemSize(OrgSize - Size);
|
||||
pItem->MemSize(Size);
|
||||
pItemPrev->Free();
|
||||
return pItem;
|
||||
}
|
||||
//last resort, fragment it into 3 parts
|
||||
|
||||
//Size +=Offset&(Align-1); //adjust size to fit required alignment
|
||||
Offset -= Offset & (Align - 1);
|
||||
|
||||
CListItemReference* pItemPrev = reinterpret_cast<CListItemReference*>(m_NodePool.Allocate(1, 1));
|
||||
CListItemReference* pItemNext = reinterpret_cast<CListItemReference*>(m_NodePool.Allocate(1, 1));
|
||||
if (!pItemPrev || !pItemNext)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
const size_t OrgSize = pItem->MemSize();
|
||||
|
||||
m_Items.AddBefore(pItemPrev, pItem);
|
||||
m_Items.AddBehind(pItemNext, pItem);
|
||||
|
||||
pItemPrev->Data(pItem->Data());
|
||||
pItem->Data(reinterpret_cast<uint8*>(Offset));
|
||||
pItemNext->Data(pItem->Data() + Size);
|
||||
pItemPrev->MemSize(pItem->Data() - pItemPrev->Data());
|
||||
pItemNext->MemSize(OrgSize - pItemPrev->MemSize() - Size);
|
||||
pItem->MemSize(Size);
|
||||
|
||||
pItemPrev->Free();
|
||||
pItemNext->Free();
|
||||
return pItem;
|
||||
}
|
||||
|
||||
ILINE void Merge(CListItemReference* pItem)
|
||||
{
|
||||
m_Items.Validate(pItem);
|
||||
|
||||
//merge with next if possible
|
||||
CListItemReference* pItemNext = pItem->Next();
|
||||
if (pItemNext && pItemNext->IsFree())
|
||||
{
|
||||
if (m_pEmpty == pItemNext)
|
||||
{
|
||||
m_pEmpty = pItem;
|
||||
}
|
||||
const size_t OrgSize = pItem->MemSize();
|
||||
const size_t NextSize = pItemNext->MemSize();
|
||||
m_Items.Remove(pItemNext);
|
||||
pItem->MemSize(OrgSize + NextSize);
|
||||
m_NodePool.Free(pItemNext);
|
||||
}
|
||||
//merge with prev if possible
|
||||
CListItemReference* pItemPrev = pItem->Prev();
|
||||
if (pItemPrev && pItemPrev->IsFree())
|
||||
{
|
||||
if (m_pEmpty == pItem)
|
||||
{
|
||||
m_pEmpty = pItemPrev;
|
||||
}
|
||||
const size_t OrgSize = pItem->MemSize();
|
||||
const size_t PrevSize = pItemPrev->MemSize();
|
||||
m_Items.Remove(pItem);
|
||||
pItemPrev->MemSize(PrevSize + OrgSize);
|
||||
m_NodePool.Free(pItem);
|
||||
}
|
||||
}
|
||||
|
||||
template<class T>
|
||||
ILINE T Resolve(const uint32 ID)
|
||||
{
|
||||
CPA_ASSERT(ID); //0 is invalid
|
||||
return reinterpret_cast<T>(Item(ID)->Data());
|
||||
}
|
||||
|
||||
ILINE uint32 AddressToHandle(void* pData)
|
||||
{
|
||||
for (CListItemReference* pItem = m_Items.First(); pItem; pItem = pItem->Next())
|
||||
{
|
||||
if (pItem->Data() == pData)
|
||||
{
|
||||
return Handle(pItem);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
ILINE size_t Size(T ID) const
|
||||
{
|
||||
CPA_ASSERT(ID); //0 is invalid
|
||||
return Item(ID)->MemSize();
|
||||
}
|
||||
template<class T>
|
||||
bool InBounds([[maybe_unused]] T ID, [[maybe_unused]] const bool Check) const
|
||||
{
|
||||
//boundscheck doesn't work for Referenced containers
|
||||
return true;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
ILINE bool Free(T ID, bool ForceBoundsCheck = false)
|
||||
{
|
||||
IF (!ID, false)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
IF (!InBounds(ID, BoundsCheck | ForceBoundsCheck), false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
CListItemReference* pItem = Item(ID);
|
||||
FreedMemory(pItem->MemSize());
|
||||
pItem->Free();
|
||||
Merge(pItem);
|
||||
return true;
|
||||
}
|
||||
|
||||
ILINE bool Beat(){return false; }//dummy beat in case no defragmentator is wraping
|
||||
|
||||
ILINE size_t MemFree() const{return TMemory::MemSize() - m_Allocated; }
|
||||
|
||||
ILINE size_t MemSize() const{return TMemory::MemSize(); }
|
||||
|
||||
ILINE uint32 Handle(CListItemReference* pItem) const
|
||||
{
|
||||
return static_cast<uint32>(pItem - &m_NodePool[0]);
|
||||
}
|
||||
ILINE CListItemReference* Item(uint32 ID)
|
||||
{
|
||||
return &m_NodePool[ID];
|
||||
}
|
||||
ILINE const CListItemReference* Item(uint32 ID) const
|
||||
{
|
||||
return &m_NodePool[ID];
|
||||
}
|
||||
ILINE static bool Defragmentable(){return true; }
|
||||
|
||||
|
||||
|
||||
template<class T>
|
||||
ILINE bool ReSize(T* pData, size_t SizeNew)
|
||||
{
|
||||
CListItemReference* pItem = Item(*pData);
|
||||
const size_t SizeOld = pItem->MemSize();
|
||||
|
||||
//reduction
|
||||
if (SizeOld > SizeNew)
|
||||
{
|
||||
if (pItem->Next()->IsFree())
|
||||
{
|
||||
CListItemReference* pNext = pItem->Next();
|
||||
const size_t NextSize = pNext->MemSize();
|
||||
pNext->Data(pNext->Data() + SizeNew - SizeOld);
|
||||
pNext->MemSize(NextSize - SizeNew + SizeOld);
|
||||
pItem->MemSize(SizeNew);
|
||||
return true;
|
||||
}
|
||||
|
||||
//split
|
||||
CListItemReference* pItemNext = reinterpret_cast<CListItemReference*>(m_NodePool.Allocate(1, 1));
|
||||
m_Items.AddBehind(pItemNext, pItem);
|
||||
pItemNext->Data(pItem->Data() + SizeNew);
|
||||
pItem->MemSize(SizeNew);
|
||||
pItemNext->MemSize(SizeOld - SizeNew);
|
||||
pItemNext->Free();
|
||||
return true;
|
||||
}
|
||||
|
||||
//SizeOld<SizeNew grow
|
||||
CListItemReference* pNext = pItem->Next();
|
||||
const size_t SizeNext = pNext->IsFree() ? pNext->MemSize() : 0;
|
||||
if (SizeNew <= SizeNext + SizeOld)
|
||||
{
|
||||
if (SizeNew == SizeNext + SizeOld)
|
||||
{
|
||||
m_Items.Remove(pNext);
|
||||
m_NodePool.Free(pNext);
|
||||
}
|
||||
else
|
||||
{
|
||||
pNext->Data(pNext->Data() + SizeNew - SizeOld);
|
||||
pNext->MemSize(SizeNext - SizeNew + SizeOld);
|
||||
}
|
||||
pItem->MemSize(SizeNew);
|
||||
return true;
|
||||
}
|
||||
return false; //no further in-place realloc possible
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // CRYINCLUDE_CRYPOOL_CONTAINER_H
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
#ifndef CRYINCLUDE_CRYPOOL_DEFRAG_H
|
||||
#define CRYINCLUDE_CRYPOOL_DEFRAG_H
|
||||
#pragma once
|
||||
|
||||
|
||||
namespace NCryPoolAlloc
|
||||
{
|
||||
template<class T>
|
||||
class CDefragStacked
|
||||
: public T
|
||||
{
|
||||
template<class TItem>
|
||||
ILINE bool DefragElement(TItem* pItem)
|
||||
{
|
||||
T::m_Items.Validate();
|
||||
if (pItem)
|
||||
{
|
||||
for (; pItem->Next(); pItem = pItem->Next())
|
||||
{
|
||||
if (!pItem->IsFree())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (pItem->Next()->Locked())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (!pItem->Available(pItem->Next()->Align(), pItem->Next()->Align()))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
T::m_Items.Validate(pItem);
|
||||
Stack(pItem);
|
||||
T::m_Items.Validate(pItem);
|
||||
Merge(pItem);
|
||||
T::m_Items.Validate();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public:
|
||||
ILINE bool Beat()
|
||||
{
|
||||
return T::Defragmentable() && DefragElement(T::m_Items.First());
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif // CRYINCLUDE_CRYPOOL_DEFRAG_H
|
||||
|
||||
@@ -1,81 +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_CRYPOOL_FALLBACK_H
|
||||
#define CRYINCLUDE_CRYPOOL_FALLBACK_H
|
||||
#pragma once
|
||||
|
||||
|
||||
namespace NCryPoolAlloc
|
||||
{
|
||||
enum EFallbackMode
|
||||
{
|
||||
EFM_DISABLED,
|
||||
EFM_ENABLED,
|
||||
EFM_ALWAYS
|
||||
};
|
||||
template<class TAllocator>
|
||||
class CFallback
|
||||
: public TAllocator
|
||||
{
|
||||
EFallbackMode m_Fallback;
|
||||
public:
|
||||
ILINE CFallback()
|
||||
: m_Fallback(EFM_DISABLED)
|
||||
{
|
||||
}
|
||||
|
||||
template<class T>
|
||||
ILINE T Allocate(size_t Size, size_t Align = 1)
|
||||
{
|
||||
if (EFM_ALWAYS == m_Fallback)
|
||||
{
|
||||
return reinterpret_cast<T>(CPA_ALLOC(Align, Size));
|
||||
}
|
||||
T pRet = TAllocator::template Allocate<T>(Size, Align);
|
||||
if (!pRet && EFM_ENABLED == m_Fallback)
|
||||
{
|
||||
return reinterpret_cast<T>(CPA_ALLOC(Align, Size));
|
||||
}
|
||||
return pRet;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
ILINE bool Free(T Handle)
|
||||
{
|
||||
if (!Handle)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (EFM_ALWAYS == m_Fallback)
|
||||
{
|
||||
CPA_FREE(Handle);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (EFM_ENABLED == m_Fallback && TAllocator::InBounds(Handle, true))
|
||||
{
|
||||
CPA_FREE(Handle);
|
||||
return true;
|
||||
}
|
||||
return TAllocator::template Free<T>(Handle);
|
||||
}
|
||||
|
||||
void FallbackMode(EFallbackMode M){m_Fallback = M; }
|
||||
EFallbackMode FallbaclMode() const{return m_Fallback; }
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif // CRYINCLUDE_CRYPOOL_FALLBACK_H
|
||||
|
||||
@@ -1,203 +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_CRYPOOL_INSPECTOR_H
|
||||
#define CRYINCLUDE_CRYPOOL_INSPECTOR_H
|
||||
#pragma once
|
||||
|
||||
|
||||
namespace NCryPoolAlloc
|
||||
{
|
||||
template<class TAllocator>
|
||||
class CInspector
|
||||
: public TAllocator
|
||||
{
|
||||
enum
|
||||
{
|
||||
EITableSize = 30
|
||||
};
|
||||
size_t m_Allocations[EITableSize];
|
||||
size_t m_Alignment[EITableSize];
|
||||
char m_LogFileName[1024];
|
||||
size_t m_AllocCount;
|
||||
size_t m_FreeCount;
|
||||
size_t m_ResizeCount;
|
||||
size_t m_FailAllocCount;
|
||||
size_t m_FailFreeCount;
|
||||
size_t m_FailResizeCount;
|
||||
|
||||
void WriteOut(const char* pFileName, uint32 Stack, const char* pFormat, ...) const
|
||||
{
|
||||
/*
|
||||
if(!pFileName)
|
||||
{
|
||||
if(!*m_LogFileName)
|
||||
return;
|
||||
pFileName = m_LogFileName;
|
||||
}
|
||||
FILE* File = fopen(pFileName,"a");
|
||||
if(File)
|
||||
{
|
||||
|
||||
char Buffer[1024];
|
||||
for(uint32 a=0;a<Stack;a++)
|
||||
Buffer[a]=' ';
|
||||
va_list args;
|
||||
va_start(args,pFormat);
|
||||
vsprintf(Buffer+Stack,pFormat,args);
|
||||
fwrite(Buffer,1,strlen(Buffer),File);
|
||||
fclose(File);
|
||||
va_end(args);
|
||||
}
|
||||
*/
|
||||
}
|
||||
size_t Bit(size_t C) const
|
||||
{
|
||||
size_t Count = 0;
|
||||
C >>= 1;
|
||||
while (C)
|
||||
{
|
||||
Count++;
|
||||
C >>= 1;
|
||||
}
|
||||
return Count >= EITableSize ? EITableSize - 1 : Count;
|
||||
}
|
||||
public:
|
||||
CInspector()
|
||||
{
|
||||
for (size_t a = 0; a < EITableSize; a++)
|
||||
{
|
||||
m_Allocations[a] = m_Alignment[a] = 0;
|
||||
}
|
||||
|
||||
m_LogFileName[0] = 0;
|
||||
m_AllocCount = 0;
|
||||
m_FreeCount = 0;
|
||||
m_ResizeCount = 0;
|
||||
m_FailAllocCount = 0;
|
||||
m_FailFreeCount = 0;
|
||||
m_FailResizeCount = 0;
|
||||
}
|
||||
|
||||
bool LogFileName(const char* pFileName)
|
||||
{
|
||||
const size_t Size = strlen(pFileName) + 1;
|
||||
if (Size > sizeof(m_LogFileName))
|
||||
{
|
||||
m_LogFileName[0] = 0;
|
||||
return false;
|
||||
}
|
||||
memcpy(m_LogFileName, pFileName, Size);
|
||||
WriteOut(0, "[log start]\n");
|
||||
return true;
|
||||
}
|
||||
void SaveStats(const char* pFileName) const
|
||||
{
|
||||
WriteOut(pFileName, 0, "stats:\n");
|
||||
|
||||
WriteOut(pFileName, 1, "Counter calls|fails\n");
|
||||
WriteOut(pFileName, 2, "Alloc: %6d|%6d\n", m_AllocCount, m_FailAllocCount);
|
||||
WriteOut(pFileName, 2, "Free: %6d|%6d\n", m_FreeCount, m_FailFreeCount);
|
||||
WriteOut(pFileName, 2, "Resize:%6d|%6d\n", m_ResizeCount, m_FailResizeCount);
|
||||
|
||||
WriteOut(pFileName, 1, "Allocations:\n");
|
||||
for (size_t a = 0; a < EITableSize; a++)
|
||||
{
|
||||
WriteOut(pFileName, 2, "%9dByte: %8d\n", 1 << a, m_Allocations[a]);
|
||||
}
|
||||
|
||||
WriteOut(pFileName, 1, "Alignment:\n");
|
||||
for (size_t a = 0; a < EITableSize; a++)
|
||||
{
|
||||
WriteOut(pFileName, 2, "%9dByte: %8d\n", 1 << a, m_Alignment[a]);
|
||||
}
|
||||
}
|
||||
|
||||
template<class T>
|
||||
ILINE T Allocate(size_t Size, size_t Align = 1)
|
||||
{
|
||||
m_AllocCount++;
|
||||
m_Allocations[Bit(Size)]++;
|
||||
m_Alignment[Bit(Align)]++;
|
||||
T pData = TAllocator::template Allocate<T>(Size, Align);
|
||||
WriteOut(0, 0, "[A|%d|%d|%d]", (int)pData, Size, Align);
|
||||
if (!pData)
|
||||
{
|
||||
m_FailAllocCount++;
|
||||
WriteOut(0, 0, "[failed]", Size, Align);
|
||||
}
|
||||
return pData;
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
ILINE bool Free(T pData, bool ForceBoundsCheck = false)
|
||||
{
|
||||
m_FreeCount++;
|
||||
const bool Ret = TAllocator::Free(pData, ForceBoundsCheck);
|
||||
WriteOut(0, 0, "[F|%d|%d|%d]", (int)pData, (int)ForceBoundsCheck, (int)Ret);
|
||||
m_FailFreeCount += !Ret;
|
||||
return Ret;
|
||||
}
|
||||
//template<class T>
|
||||
//ILINE bool Free(T pData)
|
||||
// {
|
||||
// m_FreeCount++;
|
||||
// const bool Ret = TAllocator::Free(pData);
|
||||
// WriteOut(0,0,"[F|%d|%d|%d]",(int)pData,(int)-1,(int)Ret);
|
||||
// m_FailFreeCount+=!Ret;
|
||||
// return Ret;
|
||||
// }
|
||||
|
||||
template<class T>
|
||||
ILINE bool Resize(T** pData, size_t Size, size_t Alignment)
|
||||
{
|
||||
m_ResizeCount++;
|
||||
const bool Ret = TAllocator::Resize(pData, Size, Alignment);
|
||||
WriteOut(0, 0, "[R|%d|%d|%d]", (int)*pData, (int)-1, (int)Ret);
|
||||
m_FailResizeCount += !Ret;
|
||||
return Ret;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
ILINE size_t FindBiggest(const T* pItem)
|
||||
{
|
||||
size_t Biggest = 0;
|
||||
while (pItem)
|
||||
{
|
||||
if (pItem->IsFree() && pItem->MemSize() > Biggest)
|
||||
{
|
||||
Biggest = pItem->MemSize();
|
||||
}
|
||||
pItem = pItem->Next();
|
||||
}
|
||||
return Biggest;
|
||||
}
|
||||
|
||||
ILINE size_t BiggestFreeBlock()
|
||||
{
|
||||
return FindBiggest(TAllocator::m_Items.First());
|
||||
}
|
||||
|
||||
ILINE uint8* FirstItem()
|
||||
{
|
||||
return TAllocator::m_Items.First()->Data();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // CRYINCLUDE_CRYPOOL_INSPECTOR_H
|
||||
|
||||
@@ -1,366 +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_CRYPOOL_LIST_H
|
||||
#define CRYINCLUDE_CRYPOOL_LIST_H
|
||||
#pragma once
|
||||
|
||||
namespace NCryPoolAlloc
|
||||
{
|
||||
class CListItemInPlace;
|
||||
class CListItemReference;
|
||||
|
||||
template<typename TItem>
|
||||
class CListItem
|
||||
{
|
||||
TItem* m_pPrev;
|
||||
TItem* m_pNext;
|
||||
public:
|
||||
|
||||
ILINE TItem* Prev(){return m_pPrev; }
|
||||
ILINE TItem* Next(){return m_pNext; }
|
||||
ILINE const TItem* Prev() const{return m_pPrev; }
|
||||
ILINE const TItem* Next() const{return m_pNext; }
|
||||
ILINE void Prev(TItem* pPrev){ m_pPrev = pPrev; }
|
||||
ILINE void Next(TItem* pNext){ m_pNext = pNext; }
|
||||
|
||||
//debugging
|
||||
void Validate();
|
||||
};
|
||||
|
||||
template<typename TItem>
|
||||
class CListItemFlagged
|
||||
: public CListItem<TItem>
|
||||
{
|
||||
enum
|
||||
{
|
||||
ELIF_INUSE = (1 << 0),
|
||||
ELIF_LOCKED = (1 << 1),
|
||||
};
|
||||
uint32 m_Flags : 8;
|
||||
uint32 m_Align : 24;
|
||||
public:
|
||||
ILINE CListItemFlagged()
|
||||
: m_Flags(0)
|
||||
{
|
||||
}
|
||||
ILINE bool IsFree() const{return (m_Flags & ELIF_INUSE) != ELIF_INUSE; }
|
||||
ILINE void Free(){m_Flags &= ~ELIF_INUSE; }
|
||||
ILINE void InUse(uint32 A){m_Flags |= ELIF_INUSE; m_Align = A; }
|
||||
ILINE bool Locked() const{return ELIF_LOCKED == (m_Flags & ELIF_LOCKED); }
|
||||
ILINE void Lock(){m_Flags |= ELIF_LOCKED; }
|
||||
ILINE void Unlock(){m_Flags &= ~ELIF_LOCKED; }
|
||||
ILINE uint32 Align() const{return m_Align; }
|
||||
};
|
||||
|
||||
class CListItemInPlace
|
||||
: public CListItemFlagged<CListItemInPlace>
|
||||
{
|
||||
public:
|
||||
ILINE void Init([[maybe_unused]] uint8* pData, [[maybe_unused]] size_t Size, CListItemInPlace* pPrev, CListItemInPlace* pNext)
|
||||
{
|
||||
Prev(pPrev);
|
||||
Next(pNext);
|
||||
CPA_ASSERT(Size == MemSize());
|
||||
}
|
||||
|
||||
ILINE bool Available(size_t Size, size_t Align) const
|
||||
{
|
||||
size_t Offset = reinterpret_cast<size_t>(Data());
|
||||
if (Offset & (Align - 1)) //not aligned?
|
||||
{
|
||||
Size += sizeof(CListItemInPlace) + Align - 1; //then an intermedian node needs to fit
|
||||
}
|
||||
return Size <= MemSize() && IsFree();
|
||||
}
|
||||
ILINE uint8* Data(){return reinterpret_cast<uint8*>(this) + sizeof(CListItemInPlace); }
|
||||
ILINE const uint8* Data() const{return reinterpret_cast<const uint8*>(this) + sizeof(CListItemInPlace); }
|
||||
ILINE size_t MemSize() const
|
||||
{
|
||||
const uint8* pNext = reinterpret_cast<const uint8*>(Next());
|
||||
const uint8* pThis = reinterpret_cast<const uint8*>(this);
|
||||
const size_t ESize = sizeof(CListItemInPlace);
|
||||
size_t Delta = pNext - pThis;
|
||||
Delta -= ESize;
|
||||
return Delta;
|
||||
}
|
||||
};
|
||||
|
||||
class CListItemReference
|
||||
: public CListItemFlagged<CListItemReference>
|
||||
{
|
||||
uint8* m_pData;
|
||||
// size_t m_Size;
|
||||
public:
|
||||
ILINE void Init(uint8* pData, size_t Size, CListItemReference* pPrev, CListItemReference* pNext)
|
||||
{
|
||||
Data(pData);
|
||||
Prev(pPrev);
|
||||
Next(pNext);
|
||||
MemSize(Size);
|
||||
}
|
||||
ILINE bool Available(size_t Size, size_t Align) const
|
||||
{
|
||||
size_t Offset = reinterpret_cast<size_t>(Data());
|
||||
if ((Offset & (Align - 1)))
|
||||
{
|
||||
Size += Align - (Offset & (Align - 1));
|
||||
}
|
||||
return Size <= MemSize() && IsFree();
|
||||
}
|
||||
ILINE void Data(uint8* pData){m_pData = pData; }
|
||||
ILINE uint8* Data(size_t Align)
|
||||
{
|
||||
Align--;
|
||||
size_t Offset = reinterpret_cast<size_t>(m_pData);
|
||||
Offset = (Offset + Align) & ~Align;
|
||||
return reinterpret_cast<uint8*>(Offset);
|
||||
}
|
||||
ILINE uint8* Data(){return m_pData; }
|
||||
ILINE const uint8* Data() const{return m_pData; }
|
||||
ILINE void MemSize([[maybe_unused]] size_t Size) { }
|
||||
ILINE size_t MemSize() const
|
||||
{
|
||||
const size_t T = reinterpret_cast<size_t>(Data());
|
||||
const size_t N = Next() ? reinterpret_cast<size_t>(Next()->Data()) : T;
|
||||
return N - T;
|
||||
}
|
||||
//ILINE void MemSize(size_t Size){m_Size=Size;}
|
||||
//ILINE size_t MemSize()const{return m_Size;}
|
||||
};
|
||||
|
||||
template<class TItem, bool VALIDATE = false>
|
||||
class CList
|
||||
{
|
||||
TItem* m_pFirst;
|
||||
TItem* m_pLast;
|
||||
size_t m_Count;
|
||||
public:
|
||||
ILINE CList()
|
||||
: m_pFirst(0)
|
||||
, m_pLast(0)
|
||||
, m_Count(0)
|
||||
{
|
||||
}
|
||||
|
||||
ILINE void First(TItem* pItem){m_pFirst = pItem; }
|
||||
ILINE TItem* First(){return m_pFirst; }
|
||||
ILINE void Last(TItem* pItem){m_pLast = pItem; }
|
||||
ILINE TItem* Last(){return m_pLast; }
|
||||
ILINE bool Empty() const{return m_pFirst == 0; }
|
||||
|
||||
ILINE TItem* PopFirst()
|
||||
{
|
||||
Validate();
|
||||
|
||||
if (!m_pFirst)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
TItem* pRet = m_pFirst;
|
||||
|
||||
m_pFirst = m_pFirst->Next();
|
||||
|
||||
if (m_pFirst) //if any element exists
|
||||
{
|
||||
m_pFirst->Prev(0); //set prev ptr of this element to 0
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pLast = 0; //set ptr to last element to 0 if ptr to first is zero as well
|
||||
}
|
||||
Validate();
|
||||
m_Count--;
|
||||
return pRet;
|
||||
}
|
||||
|
||||
ILINE TItem* PopLast()
|
||||
{
|
||||
Validate();
|
||||
|
||||
if (!m_pLast)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
TItem* pRet = m_pLast;
|
||||
|
||||
m_pLast = m_pLast->Prev();
|
||||
|
||||
if (m_pLast) //if any element exists
|
||||
{
|
||||
m_pLast->Next(0); //set prev ptr of this element to 0
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pFirst = 0; //set ptr to last element to 0 if ptr to first is zero as well
|
||||
}
|
||||
Validate();
|
||||
m_Count--;
|
||||
return pRet;
|
||||
}
|
||||
|
||||
ILINE void AddFirst(TItem* pItem)
|
||||
{
|
||||
CPA_ASSERT(pItem); //ERROR AddFirst got 0 pointer
|
||||
|
||||
Validate();
|
||||
|
||||
pItem->Prev(0);
|
||||
pItem->Next(m_pFirst);
|
||||
if (!m_pFirst)
|
||||
{
|
||||
m_pLast = pItem;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pFirst->Prev(pItem);
|
||||
}
|
||||
m_pFirst = pItem;
|
||||
|
||||
m_Count++;
|
||||
Validate();
|
||||
}
|
||||
|
||||
ILINE void AddLast(TItem* pItem)
|
||||
{
|
||||
CPA_ASSERT(pItem); //ERROR AddLast got 0 pointer
|
||||
|
||||
Validate();
|
||||
|
||||
pItem->Prev(m_pLast);
|
||||
pItem->Next(0);
|
||||
if (!m_pLast)
|
||||
{
|
||||
m_pFirst = pItem;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pLast->Next(pItem);
|
||||
}
|
||||
m_pLast = pItem;
|
||||
|
||||
m_Count++;
|
||||
Validate();
|
||||
}
|
||||
ILINE void AddBefore(TItem* pItem, TItem* pItemSuccessor)
|
||||
{
|
||||
CPA_ASSERT(pItem);
|
||||
CPA_ASSERT(pItemSuccessor);
|
||||
|
||||
Validate();
|
||||
|
||||
pItem->Next(pItemSuccessor);
|
||||
pItem->Prev(pItemSuccessor->Prev());
|
||||
pItemSuccessor->Prev(pItem);
|
||||
|
||||
if (pItemSuccessor == m_pFirst)
|
||||
{
|
||||
m_pFirst = pItem;
|
||||
}
|
||||
else
|
||||
{
|
||||
pItem->Prev()->Next(pItem);
|
||||
}
|
||||
|
||||
m_Count++;
|
||||
Validate();
|
||||
}
|
||||
ILINE void AddBehind(TItem* pItem, TItem* pItemPredecessor)
|
||||
{
|
||||
CPA_ASSERT(pItem);
|
||||
CPA_ASSERT(pItemPredecessor);
|
||||
|
||||
Validate();
|
||||
|
||||
pItem->Next(pItemPredecessor->Next());
|
||||
pItem->Prev(pItemPredecessor);
|
||||
pItemPredecessor->Next(pItem);
|
||||
|
||||
if (pItemPredecessor == m_pLast)
|
||||
{
|
||||
m_pLast = pItem;
|
||||
}
|
||||
else
|
||||
{
|
||||
pItem->Next()->Prev(pItem);
|
||||
}
|
||||
|
||||
m_Count++;
|
||||
Validate();
|
||||
}
|
||||
|
||||
ILINE void Remove(TItem* pItem)
|
||||
{
|
||||
CPA_ASSERT(pItem); //ERROR releasing empty item
|
||||
|
||||
if (pItem == m_pFirst)
|
||||
{
|
||||
PopFirst();
|
||||
return;
|
||||
}
|
||||
if (pItem == m_pLast)
|
||||
{
|
||||
PopLast();
|
||||
return;
|
||||
}
|
||||
|
||||
Validate(pItem);
|
||||
|
||||
pItem->Prev()->Next(pItem->Next());
|
||||
pItem->Next()->Prev(pItem->Prev());
|
||||
|
||||
m_Count--;
|
||||
Validate();
|
||||
}
|
||||
|
||||
//debug
|
||||
ILINE void Validate(TItem* pReferenceItem = 0)
|
||||
{
|
||||
if (!VALIDATE)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//one-sided empty?
|
||||
CPA_ASSERT((!First() && !Last()) || (First() && Last())); //ERROR validating item-list, just one end is 0
|
||||
|
||||
// endles linking?
|
||||
TItem* pPrev = 0;
|
||||
TItem* pItem = First();
|
||||
while (pItem)
|
||||
{
|
||||
if (pReferenceItem == pItem)
|
||||
{
|
||||
pReferenceItem = 0;
|
||||
}
|
||||
CPA_ASSERT(pPrev == pItem->Prev()); //ERROR validating item-list, endless linking NULL
|
||||
pPrev = pItem;
|
||||
pItem = pItem->Next();
|
||||
}
|
||||
|
||||
CPA_ASSERT(pPrev == Last()); //ERROR validating item-list, broken list, does not end at specified Last item
|
||||
CPA_ASSERT(!pReferenceItem); //ERROR reference item not found in the item-list
|
||||
}
|
||||
ILINE size_t Count() const{return m_Count; }
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // CRYINCLUDE_CRYPOOL_LIST_H
|
||||
|
||||
@@ -1,70 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
#ifndef CRYINCLUDE_CRYPOOL_MEMORY_H
|
||||
#define CRYINCLUDE_CRYPOOL_MEMORY_H
|
||||
#pragma once
|
||||
|
||||
namespace NCryPoolAlloc
|
||||
{
|
||||
class CMemoryDynamic
|
||||
{
|
||||
size_t m_Size;
|
||||
uint8* m_pData;
|
||||
|
||||
protected:
|
||||
ILINE CMemoryDynamic()
|
||||
: m_Size(0)
|
||||
, m_pData(0){}
|
||||
|
||||
public:
|
||||
ILINE void InitMem(const size_t S, uint8* pData)
|
||||
{
|
||||
m_Size = S;
|
||||
m_pData = pData;
|
||||
CPA_ASSERT(S);
|
||||
CPA_ASSERT(pData);
|
||||
}
|
||||
|
||||
ILINE size_t MemSize() const{return m_Size; }
|
||||
ILINE uint8* Data(){return m_pData; }
|
||||
ILINE const uint8* Data() const{return m_pData; }
|
||||
};
|
||||
|
||||
template<size_t TSize>
|
||||
class CMemoryStatic
|
||||
{
|
||||
uint8 m_Data[TSize];
|
||||
|
||||
protected:
|
||||
ILINE CMemoryStatic()
|
||||
{
|
||||
}
|
||||
public:
|
||||
ILINE void InitMem(const size_t S, uint8* pData)
|
||||
{
|
||||
}
|
||||
ILINE size_t MemSize() const{return TSize; }
|
||||
ILINE uint8* Data(){return m_Data; }
|
||||
ILINE const uint8* Data() const{return m_Data; }
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // CRYINCLUDE_CRYPOOL_MEMORY_H
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
#pragma once
|
||||
|
||||
#if defined(POOLALLOCTESTSUIT)
|
||||
//cheat just for unit testing on windows
|
||||
#include "BaseTypes.h"
|
||||
#define ILINE inline
|
||||
#endif
|
||||
|
||||
// Traits
|
||||
#if defined(AZ_RESTRICTED_PLATFORM)
|
||||
#include AZ_RESTRICTED_FILE(CryPool/PoolAlloc_h)
|
||||
#elif defined(APPLE) || defined(LINUX)
|
||||
#define POOLALLOC_H_TRAIT_USE_MEMALIGN 1
|
||||
#endif
|
||||
|
||||
|
||||
#if POOLALLOC_H_TRAIT_USE_MEMALIGN
|
||||
#define CPA_ALLOC memalign
|
||||
#define CPA_FREE free
|
||||
#else
|
||||
#define CPA_ALLOC _aligned_malloc
|
||||
#define CPA_FREE _aligned_free
|
||||
#endif
|
||||
#define CPA_ASSERT assert
|
||||
#define CPA_ASSERT_STATIC(X) {uint8 assertdata[(X) ? 0 : 1]; }
|
||||
#define CPA_BREAK __debugbreak()
|
||||
|
||||
#include "List.h"
|
||||
#include "Memory.h"
|
||||
#include "Container.h"
|
||||
#include "Allocator.h"
|
||||
#include "Defrag.h"
|
||||
#include "STLWrapper.h"
|
||||
#include "Inspector.h"
|
||||
#include "Fallback.h"
|
||||
#if !defined(POOLALLOCTESTSUIT)
|
||||
#include "ThreadSafe.h"
|
||||
#endif
|
||||
|
||||
#undef CPA_ASSERT
|
||||
#undef CPA_ASSERT_STATIC
|
||||
#undef CPA_BREAK
|
||||
@@ -1,148 +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_CRYPOOL_STLWRAPPER_H
|
||||
#define CRYINCLUDE_CRYPOOL_STLWRAPPER_H
|
||||
#pragma once
|
||||
|
||||
namespace NCryPoolAlloc
|
||||
{
|
||||
//namespace CSTLPoolAllocWrapperHelper
|
||||
//{
|
||||
// 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, typename T>
|
||||
//struct CSTLPoolAllocWrapperStatic
|
||||
//{
|
||||
// static PoolAllocator<S, L, A> * allocator;
|
||||
//};
|
||||
|
||||
//template <class T, class L, size_t A>
|
||||
//struct CSTLPoolAllocWrapperKungFu : public CSTLPoolAllocWrapperStatic<sizeof(T),L,A,T>
|
||||
//{
|
||||
//};
|
||||
|
||||
template <class T, class TCont>
|
||||
class CSTLPoolAllocWrapper
|
||||
{
|
||||
private:
|
||||
static TCont* m_pContainer;
|
||||
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;
|
||||
|
||||
static TCont* Container(){return m_pContainer; }
|
||||
static void Container(TCont* pContainer){m_pContainer = pContainer; }
|
||||
|
||||
|
||||
template <class U>
|
||||
struct rebind
|
||||
{
|
||||
typedef CSTLPoolAllocWrapper<T, TCont> other;
|
||||
};
|
||||
|
||||
CSTLPoolAllocWrapper() throw()
|
||||
{
|
||||
}
|
||||
|
||||
CSTLPoolAllocWrapper(const CSTLPoolAllocWrapper&) throw()
|
||||
{
|
||||
}
|
||||
|
||||
template <class TTemp, class TTempCont>
|
||||
CSTLPoolAllocWrapper(const CSTLPoolAllocWrapper<TTemp, TTempCont>&) throw()
|
||||
{
|
||||
}
|
||||
|
||||
~CSTLPoolAllocWrapper() throw()
|
||||
{
|
||||
}
|
||||
|
||||
pointer address(reference x) const
|
||||
{
|
||||
return &x;
|
||||
}
|
||||
|
||||
const_pointer address(const_reference x) const
|
||||
{
|
||||
return &x;
|
||||
}
|
||||
|
||||
pointer allocate(size_type n = 1, const_pointer hint = 0)
|
||||
{
|
||||
TCont* pContainer = Container();
|
||||
uint8* pData = pContainer->TCont::template Allocate<uint8*>(n * sizeof(T), sizeof(T));
|
||||
return pContainer->TCont::template Resolve<pointer>(pData);
|
||||
// return Container()?Container()->Allocate<void*>(n*sizeof(T),sizeof(T)):0
|
||||
}
|
||||
|
||||
void deallocate(pointer p, size_type n = 1)
|
||||
{
|
||||
if (Container())
|
||||
{
|
||||
Container()->Free(p);
|
||||
}
|
||||
}
|
||||
|
||||
size_type max_size() const throw()
|
||||
{
|
||||
return Container() ? Container()->MemSize() : 0;
|
||||
}
|
||||
|
||||
void construct(pointer p, const T& val)
|
||||
{
|
||||
new(static_cast<void*>(p))T(val);
|
||||
}
|
||||
|
||||
void construct(pointer p)
|
||||
{
|
||||
new(static_cast<void*>(p))T();
|
||||
}
|
||||
|
||||
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 CSTLPoolAllocWrapper&) {return true; }
|
||||
bool operator!=(const CSTLPoolAllocWrapper&) {return false; }
|
||||
};
|
||||
}
|
||||
|
||||
#endif // CRYINCLUDE_CRYPOOL_STLWRAPPER_H
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
#ifndef CRYINCLUDE_CRYPOOL_THREADSAFE_H
|
||||
#define CRYINCLUDE_CRYPOOL_THREADSAFE_H
|
||||
#pragma once
|
||||
|
||||
|
||||
#include <CryThread.h>
|
||||
|
||||
namespace NCryPoolAlloc
|
||||
{
|
||||
template<class TAllocator>
|
||||
class CThreadSafe
|
||||
: public TAllocator
|
||||
{
|
||||
CryCriticalSection m_Mutex;
|
||||
public:
|
||||
|
||||
template<class T>
|
||||
ILINE T Allocate(size_t Size, size_t Align = 1)
|
||||
{
|
||||
CryAutoLock<CryCriticalSection> lock(m_Mutex);
|
||||
return TAllocator::template Allocate<T>(Size, Align);
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
ILINE bool Free(T pData, bool ForceBoundsCheck = false)
|
||||
{
|
||||
CryAutoLock<CryCriticalSection> lock(m_Mutex);
|
||||
return TAllocator::Free(pData, ForceBoundsCheck);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
ILINE bool Resize(T** pData, size_t Size, size_t Alignment)
|
||||
{
|
||||
CryAutoLock<CryCriticalSection> lock(m_Mutex);
|
||||
return TAllocator::Resize(pData, Size, Alignment);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // CRYINCLUDE_CRYPOOL_THREADSAFE_H
|
||||
|
||||
@@ -1,287 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
#ifndef CRYINCLUDE_CRYPOOL_EXAMPLE_H
|
||||
#define CRYINCLUDE_CRYPOOL_EXAMPLE_H
|
||||
#pragma once
|
||||
|
||||
|
||||
//The documentation is split up into 3 main parts, so strg+f for
|
||||
// -Theory
|
||||
// -Building blocks
|
||||
// -Usage
|
||||
// -FAQ
|
||||
// -Realloc/Resize
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// -Theory
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
//this includes the 3 major parts of the allocate suite
|
||||
//1. the memory location templates
|
||||
//2. container types
|
||||
//3. some allocator version
|
||||
//addtional you get
|
||||
//4. a simple stack based defragmentation template
|
||||
//5. helper
|
||||
|
||||
//1. memory location templates
|
||||
// There are two types of them, static and dynamic
|
||||
//1.1 CMemoryStatic<size> allows you do define on compile time what size
|
||||
// it should have, suitable for pool you know that they won't grow or
|
||||
// shrink
|
||||
//1.2 CMemoryDynamic, this one has no template parameter, it has just one
|
||||
// indirection via ptr to the memory location and size, that you will
|
||||
// set during initialization.
|
||||
|
||||
//2. Container types
|
||||
// We have also two container types, one so called "In Place"
|
||||
// and one "Referenced".
|
||||
//2.1 "In Place" means that a header is placed above every allocation,
|
||||
// this is the usual way most allocators work.
|
||||
//2.2 "Referenced", has an extra pool of headers that point to the actual
|
||||
// memory. This is suitable for
|
||||
// - external memory locations that are not directly accessable by the
|
||||
// cpu. E.g. pools on disk, networks, rsx memory..
|
||||
// - defragmentation, because you don't save a ptr to the real memory
|
||||
// location, just a "handle" of the referencing item.
|
||||
// - big alignments, having 4kb of alignment would waste also
|
||||
// - 4kb for ever "In Place" header, you might not want that.
|
||||
|
||||
//3. Allocators
|
||||
// This time we have 3 of them, "BestFit", "WorstFit" and "FirstFit"
|
||||
//3.1 FirstFit just seeks for any location big enought to fit your
|
||||
// requested size of memory. Internally it also saves the last used
|
||||
// free memory area to speed up allocations.
|
||||
// Use this also if you have just one particular allocation size.
|
||||
//3.2 WorstFit, although it might sound illogical, WorstFit can reduce
|
||||
// memory fragmentation in a cases with very random allocation sizes,
|
||||
// because it gives smaller free blocks the chance to concatenate to
|
||||
// bigger free blocks again while filling up those previously
|
||||
// generated big blocks. The bad side is that it takes quite some time
|
||||
// to find the biggest block as this needs to be done every time you
|
||||
// allocate, so use this just when having a low amount of allocations
|
||||
// or you're really desperately looking for mem.
|
||||
//3.3 BestFit, it's best used if you don't have just one allocation size,
|
||||
// but still very few varying sizes. Previously released blocks of
|
||||
// the currently allocating sizes will be seeked and reused, this
|
||||
// strongly helps to reduce fragmentation. While this might be slow
|
||||
// in some cases, it can save you from doing any defragmentation.
|
||||
|
||||
//4. Defragmentation
|
||||
// At the moment just one defragmentation algorithm is implemented:
|
||||
// "Stack defragmentator"
|
||||
// If you don't want some block to be moved, "Lock" it using your
|
||||
// memory handle.
|
||||
//4.1 Stack based
|
||||
// To reduce fragmentation, holes are filled up with the next used,
|
||||
// memory area. This defragmentation sheme is useful when you have
|
||||
// some long living locations as well as very short living ones.
|
||||
// At some point all long live memory will end up at the bottom of
|
||||
// the stack, while leaving empty memory areas at the top for short
|
||||
// living allocations.
|
||||
|
||||
//5. Helper
|
||||
// this should be filled up with some handy helper tools for this
|
||||
// pool suite.
|
||||
// The first tool is a wrapper for the usage with stl
|
||||
//5.1 Wrapper for STL
|
||||
// As you know, you can pass your own allocator as the last
|
||||
// parameter of stl containers, with this helper you can use a pool
|
||||
// created with this suite and wrap it for the stl.
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// -Building blocks
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//That's the theory, so how does it work?
|
||||
//It's pretty simple, you compose the pool of your dreams by cascading
|
||||
//templates.
|
||||
//Lets start with an exmaple
|
||||
//Per level you want to allocate a fixed amount of memory for your
|
||||
//textures.
|
||||
CMemoryDynamic
|
||||
//- They are placed in some memory you can access directly with the cpu:
|
||||
CInPlace
|
||||
//- and you don't want to defragmentate, so you prefer an allocation
|
||||
// sheme that reduces fragmentation.
|
||||
CBestFit
|
||||
//now you combine them
|
||||
typedef CBestFit<CInPlace<CMemoryDynamic>, CListItemInPlace> TMyOwnPool;
|
||||
|
||||
//Yes, it's that simple.
|
||||
//ok, ok, texture memory is usually nothing you want to access directly
|
||||
//with your cpu, so let's create a referencing pool. Therefor you need
|
||||
//to also specify how many nodes that can reference your pool will have.
|
||||
//We won't have more than 4000 textures, so let's start with
|
||||
{
|
||||
enum TEXTURE_NODE_COUNT = 4096
|
||||
};
|
||||
//and now our referencing pool
|
||||
typedef CBestFit < CReferenced<CMemoryDynamic, TEXTURE_NODE_COUNT> TMyOwnPool;
|
||||
|
||||
//But yeah, you're right, texture memory has also a fixed size, lets
|
||||
//assume it's 128MB.
|
||||
{
|
||||
enum TEXTURE_MEMORY_SIZE = 128 * 1024 * 1024
|
||||
};
|
||||
//and our fixed sized memory pool
|
||||
typedef CBestFit < CReferenced<CMemoryStatic<TEXTURE_MEMORY_SIZE>, TEXTURE_NODE_COUNT> TMyOwnPool;
|
||||
|
||||
//ok, but you don't trust the best fit allocator in all cases, you prefer
|
||||
//a fast one and you accept the slow down for defragmentation incase the
|
||||
//allocation fails.
|
||||
//So lets created a straight First Fit allocator with defragmentation:
|
||||
typedef CDefragStacked < CFirstFit<CReferenced<CMemoryStatic<TEXTURE_MEMORY_SIZE>, TEXTURE_NODE_COUNT> > TMyOwnPool;
|
||||
|
||||
//here you see how simple you can add defragmentation, but be careful, it
|
||||
//works of course just on Reference based memory containers, if you have
|
||||
//Direct pointers to In Place allocation, we cannot shuffle them around.
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// -Usage
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
//it all starts by including the meain header
|
||||
#include "PoolAlloc.h"
|
||||
|
||||
//Define your dream allocator, preferably using a typedef (or macro)
|
||||
typedef CBestFit<CInPlace<CMemoryDynamic>, CListItemInPlace> TMyOwnPool;
|
||||
//also typedef (or macro) your handle
|
||||
typedef uint8* TMyHandle; //in case of "In Place" allocations
|
||||
typedef uint32 TMyHandle; //in case of "Referenced"
|
||||
|
||||
//Instantiate it
|
||||
TMyOwnPool g_MyMemory;
|
||||
|
||||
//now you need to initialize it,
|
||||
g_MyMemory.InitMem(pMemoryArea, MemorySize); //in case you use "CMemoryDynamic"
|
||||
g_MyMemory.InitMem(); //in case you use "CmemoryStatic,
|
||||
//altough you could pass the same
|
||||
//parameters, they'd be ignored.
|
||||
//Use this also to flush the pool
|
||||
//quickly
|
||||
|
||||
|
||||
//now allocate
|
||||
TMyHandle MemID = g_MyMemory.Allocate<TMyHandle>(Size);
|
||||
//optionally alignment can be passed as 2nd parameter
|
||||
TMyHandle MemID = g_MyMemory.Allocate<TMyHandle>(Size, Align);
|
||||
|
||||
//free it simply by calling
|
||||
g_Memory.Free(MemID);
|
||||
|
||||
//you might want to call the beat function to defragment the memory
|
||||
//on regular base
|
||||
g_Memory.Beat();
|
||||
//you might also want to call it just when an allocation failed to
|
||||
//defragmentate the memory as good as possible
|
||||
if (!(MemID = g_Memoery.Allocate<TMyHandle>(Size)))
|
||||
{
|
||||
while (g_Memory.Beat())
|
||||
{
|
||||
;
|
||||
}
|
||||
MemID = g_Memoery.Allocate<TMyHandle>(Size);
|
||||
}
|
||||
|
||||
//To acquire the pointer to your data, you need to resolve the handle
|
||||
MyObject* pObject = g_Memory.Resolve<MyOBject*>(MemID);
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// -Realloc/Resize
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// The Containers provide a "resize" function. This one does nothing else
|
||||
// than the name suggest, it is freeing some memory at the end of your
|
||||
// allocation or, if free memory is available, allocates some memory to
|
||||
// the end of your buffer. But it may also fail, if not enough memory
|
||||
// available to allocate.
|
||||
// "Realloc" on the other side requires an extra template that you wrap
|
||||
// around your existing one like:
|
||||
typedef CReallocator<TMyOwnPool> TMyOwnPoolWithReallocation;
|
||||
// This one will first try to use resize, but in case it fails, it will
|
||||
// allocate a seperate memory area, copy the data and free the old one.
|
||||
//
|
||||
// But this may fail as well, therefor the result is not a pointer to the
|
||||
// allocation, but true/false.
|
||||
// There for you need to pass a pointer to your pointer to the memory area
|
||||
// or handle you deal with.
|
||||
Handle = rMemory.Allocate<TPtr>(10, 1);
|
||||
if (!rMemory.Reallocate<TPtr>(&Handles, 11, 1))
|
||||
{
|
||||
//handle realloc failure
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// -FAQ
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//"DO I HAVE TO ALWAYS RESOLVE?"
|
||||
//if you use "In Place" memory, not at all, all resolve does is to
|
||||
//cast your handle to your object ptr and returns it.
|
||||
//if you use "Referenced" memory and you don't defragmentate, you
|
||||
//can do it once and keep the ptr, but you also need to keep the
|
||||
//handle to free the memory later on.
|
||||
|
||||
//"any reason I should resolve?"
|
||||
//Yes, first of all, it makes it very easy to switch between various
|
||||
//pool configuration for testing, you simply change some params of
|
||||
//your typedef (or macro) and it should work out of the box.
|
||||
//second, for defragmentation it's the only way to go and for future
|
||||
//things it might be needed as well
|
||||
|
||||
//"but isn't resolving just overhead?"
|
||||
//in case of "In Place": no, the resolve function just returns the
|
||||
//pointer, casting to your wanted type
|
||||
//in case of "Referenced": it cost you one indirection.
|
||||
|
||||
|
||||
//"How do I flush the whole pool without freeing all items?"
|
||||
g_Memory.InitMem()
|
||||
//yes, you can call "InitMem" once again, you need to pass the mem
|
||||
//ptr and size if using CMemoryDynamic e.g.
|
||||
g_Memory.Init(g_Memory.Size(), g_Memory.Data());
|
||||
|
||||
//"How do I lock the allocated memory to avoid any reallocation"
|
||||
g_Memory.Item(ptr)->Lock();
|
||||
|
||||
|
||||
//"How do I get the size of a memory block?"
|
||||
g_Memory.Item(ptr)->MemSize();
|
||||
|
||||
|
||||
|
||||
|
||||
//"Is there any example?"
|
||||
//for a real life example check PAUnitTest.cpp used to validate all
|
||||
//functions of this pool.
|
||||
|
||||
|
||||
//bug reports? questions? support?
|
||||
//just ask me :) (michael kopietz)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // CRYINCLUDE_CRYPOOL_EXAMPLE_H
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -49,12 +49,6 @@ public:
|
||||
//! ISystem has shut down.
|
||||
virtual void OnCrySystemPostShutdown() {}
|
||||
|
||||
//! Engine pre physics update.
|
||||
virtual void OnCrySystemPrePhysicsUpdate() {}
|
||||
|
||||
//! Engine post physics update.
|
||||
virtual void OnCrySystemPostPhysicsUpdate() {}
|
||||
|
||||
//! Sent when a new level is being created.
|
||||
virtual void OnCryEditorBeginCreate() {}
|
||||
|
||||
|
||||
@@ -37,9 +37,6 @@ enum CryLockType
|
||||
|
||||
#define CRYLOCK_HAVE_FASTLOCK 1
|
||||
|
||||
void CryThreadSetName(threadID nThreadId, const char* sThreadName);
|
||||
const char* CryThreadGetName(threadID nThreadId);
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Primitive locks and conditions.
|
||||
|
||||
@@ -31,22 +31,3 @@
|
||||
#else
|
||||
// Put other platform specific includes here!
|
||||
#endif
|
||||
|
||||
#include <IThreadTask.h>
|
||||
|
||||
void CryThreadSetName(threadID dwThreadId, const char* sThreadName)
|
||||
{
|
||||
if (gEnv && gEnv->pSystem && gEnv->pSystem->GetIThreadTaskManager())
|
||||
{
|
||||
gEnv->pSystem->GetIThreadTaskManager()->SetThreadName(dwThreadId, sThreadName);
|
||||
}
|
||||
}
|
||||
|
||||
const char* CryThreadGetName(threadID dwThreadId)
|
||||
{
|
||||
if (gEnv && gEnv->pSystem && gEnv->pSystem->GetIThreadTaskManager())
|
||||
{
|
||||
return gEnv->pSystem->GetIThreadTaskManager()->GetThreadName(dwThreadId);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -13,8 +13,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
//#include <IThreadTask.h>
|
||||
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#endif
|
||||
|
||||
@@ -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
|
||||
@@ -249,10 +249,6 @@ public:
|
||||
void SetName(const char* Name)
|
||||
{
|
||||
m_name = Name;
|
||||
if (m_threadId)
|
||||
{
|
||||
CryThreadSetName(m_threadId, m_name);
|
||||
}
|
||||
}
|
||||
const char* GetName() { return m_name; }
|
||||
|
||||
@@ -289,11 +285,6 @@ private:
|
||||
self->m_bIsStarted = true;
|
||||
self->m_bIsRunning = true;
|
||||
|
||||
if (!self->m_name.empty())
|
||||
{
|
||||
CryThreadSetName(-1, self->m_name);
|
||||
}
|
||||
|
||||
self->m_Runnable->Run();
|
||||
self->m_bIsRunning = false;
|
||||
self->m_bCreatedThread = false;
|
||||
@@ -311,11 +302,6 @@ private:
|
||||
self->m_bIsStarted = true;
|
||||
self->m_bIsRunning = true;
|
||||
|
||||
if (!self->m_name.empty())
|
||||
{
|
||||
CryThreadSetName(-1, self->m_name);
|
||||
}
|
||||
|
||||
self->Run();
|
||||
self->m_bIsRunning = false;
|
||||
self->m_bCreatedThread = false;
|
||||
|
||||
@@ -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
|
||||
@@ -594,7 +594,7 @@ public:
|
||||
ILINE const Vec3& GetFPVertex(int nId) const; //get far-plane vertices
|
||||
ILINE const Vec3& GetPPVertex(int nId) const; //get projection-plane vertices
|
||||
|
||||
ILINE const Plane* GetFrustumPlane(int numplane) const { return &m_fp[numplane]; }
|
||||
ILINE const Plane_tpl<f32>* GetFrustumPlane(int numplane) const { return &m_fp[numplane]; }
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Z-Buffer ranges.
|
||||
@@ -620,24 +620,24 @@ public:
|
||||
bool IsPointVisible(const Vec3& p) const;
|
||||
|
||||
//sphere-frustum test
|
||||
bool IsSphereVisible_F(const Sphere& s) const;
|
||||
uint8 IsSphereVisible_FH(const Sphere& s) const; //this is going to be the exact version of sphere-culling
|
||||
bool IsSphereVisible_F(const ::Sphere& s) const;
|
||||
uint8 IsSphereVisible_FH(const ::Sphere& s) const; //this is going to be the exact version of sphere-culling
|
||||
|
||||
// AABB-frustum test
|
||||
// Fast
|
||||
bool IsAABBVisible_F(const AABB& aabb) const;
|
||||
uint8 IsAABBVisible_FH(const AABB& aabb, bool* pAllInside) const;
|
||||
uint8 IsAABBVisible_FH(const AABB& aabb) const;
|
||||
bool IsAABBVisible_F(const ::AABB& aabb) const;
|
||||
uint8 IsAABBVisible_FH(const ::AABB& aabb, bool* pAllInside) const;
|
||||
uint8 IsAABBVisible_FH(const ::AABB& aabb) const;
|
||||
|
||||
// Exact
|
||||
bool IsAABBVisible_E(const AABB& aabb) const;
|
||||
uint8 IsAABBVisible_EH(const AABB& aabb, bool* pAllInside) const;
|
||||
uint8 IsAABBVisible_EH(const AABB& aabb) const;
|
||||
bool IsAABBVisible_E(const ::AABB& aabb) const;
|
||||
uint8 IsAABBVisible_EH(const ::AABB& aabb, bool* pAllInside) const;
|
||||
uint8 IsAABBVisible_EH(const ::AABB& aabb) const;
|
||||
|
||||
// Multi-camera
|
||||
bool IsAABBVisible_EHM(const AABB& aabb, bool* pAllInside) const;
|
||||
bool IsAABBVisible_EM(const AABB& aabb) const;
|
||||
bool IsAABBVisible_FM(const AABB& aabb) const;
|
||||
bool IsAABBVisible_EHM(const ::AABB& aabb, bool* pAllInside) const;
|
||||
bool IsAABBVisible_EM(const ::AABB& aabb) const;
|
||||
bool IsAABBVisible_FM(const ::AABB& aabb) const;
|
||||
|
||||
//OBB-frustum test
|
||||
bool IsOBBVisible_F(const Vec3& wpos, const OBB& obb) const;
|
||||
@@ -720,7 +720,7 @@ private:
|
||||
Vec3 m_cltn, m_crtn, m_clbn, m_crbn; //this are the 4 vertices of the near-plane in cam-space
|
||||
Vec3 m_cltf, m_crtf, m_clbf, m_crbf; //this are the 4 vertices of the farclip-plane in cam-space
|
||||
|
||||
Plane m_fp [FRUSTUM_PLANES]; //
|
||||
Plane_tpl<f32> m_fp [FRUSTUM_PLANES]; //
|
||||
uint32 m_idx1[FRUSTUM_PLANES], m_idy1[FRUSTUM_PLANES], m_idz1[FRUSTUM_PLANES]; //
|
||||
uint32 m_idx2[FRUSTUM_PLANES], m_idy2[FRUSTUM_PLANES], m_idz2[FRUSTUM_PLANES]; //
|
||||
|
||||
@@ -742,7 +742,7 @@ public:
|
||||
m_crtp = arrvVerts[2];
|
||||
m_crbp = arrvVerts[3];
|
||||
}
|
||||
inline void SetFrustumPlane(int i, const Plane& plane)
|
||||
inline void SetFrustumPlane(int i, const Plane_tpl<f32>& plane)
|
||||
{
|
||||
m_fp[i] = plane;
|
||||
//do not break strict aliasing rules, use union instead of reinterpret_casts
|
||||
@@ -1180,12 +1180,12 @@ inline void CCamera::UpdateFrustum()
|
||||
//-------------------------------------------------------------------------------
|
||||
//--- calculate the six frustum-planes using the frustum edges in world-space ---
|
||||
//-------------------------------------------------------------------------------
|
||||
m_fp[FR_PLANE_NEAR ] = Plane::CreatePlane(m_crtn + GetPosition(), m_cltn + GetPosition(), m_crbn + GetPosition());
|
||||
m_fp[FR_PLANE_RIGHT ] = Plane::CreatePlane(m_crbf + GetPosition(), m_crtf + GetPosition(), GetPosition());
|
||||
m_fp[FR_PLANE_LEFT ] = Plane::CreatePlane(m_cltf + GetPosition(), m_clbf + GetPosition(), GetPosition());
|
||||
m_fp[FR_PLANE_TOP ] = Plane::CreatePlane(m_crtf + GetPosition(), m_cltf + GetPosition(), GetPosition());
|
||||
m_fp[FR_PLANE_BOTTOM] = Plane::CreatePlane(m_clbf + GetPosition(), m_crbf + GetPosition(), GetPosition());
|
||||
m_fp[FR_PLANE_FAR ] = Plane::CreatePlane(m_crtf + GetPosition(), m_crbf + GetPosition(), m_cltf + GetPosition()); //clip-plane
|
||||
m_fp[FR_PLANE_NEAR ] = Plane_tpl<f32>::CreatePlane(m_crtn + GetPosition(), m_cltn + GetPosition(), m_crbn + GetPosition());
|
||||
m_fp[FR_PLANE_RIGHT ] = Plane_tpl<f32>::CreatePlane(m_crbf + GetPosition(), m_crtf + GetPosition(), GetPosition());
|
||||
m_fp[FR_PLANE_LEFT ] = Plane_tpl<f32>::CreatePlane(m_cltf + GetPosition(), m_clbf + GetPosition(), GetPosition());
|
||||
m_fp[FR_PLANE_TOP ] = Plane_tpl<f32>::CreatePlane(m_crtf + GetPosition(), m_cltf + GetPosition(), GetPosition());
|
||||
m_fp[FR_PLANE_BOTTOM] = Plane_tpl<f32>::CreatePlane(m_clbf + GetPosition(), m_crbf + GetPosition(), GetPosition());
|
||||
m_fp[FR_PLANE_FAR ] = Plane_tpl<f32>::CreatePlane(m_crtf + GetPosition(), m_crbf + GetPosition(), m_cltf + GetPosition()); //clip-plane
|
||||
|
||||
uint32 rh = m_Matrix.IsOrthonormalRH();
|
||||
if (rh == 0)
|
||||
@@ -1386,7 +1386,7 @@ inline bool CCamera::IsPointVisible(const Vec3& p) const
|
||||
// return values
|
||||
// CULL_EXCLUSION = sphere outside of frustum (very fast rejection-test)
|
||||
// CULL_INTERSECT = sphere and frustum intersects or sphere in completely inside frustum
|
||||
inline bool CCamera::IsSphereVisible_F(const Sphere& s) const
|
||||
inline bool CCamera::IsSphereVisible_F(const ::Sphere& s) const
|
||||
{
|
||||
if ((m_fp[0] | s.center) > s.radius)
|
||||
{
|
||||
@@ -1427,7 +1427,7 @@ inline bool CCamera::IsSphereVisible_F(const Sphere& s) const
|
||||
// CULL_EXCLUSION = sphere outside of frustum (very fast rejection-test)
|
||||
// CULL_INTERSECT = sphere intersects the borders of the frustum, further checks necessary
|
||||
// CULL_INCLUSION = sphere is complete inside the frustum, no further checks necessary
|
||||
inline uint8 CCamera::IsSphereVisible_FH(const Sphere& s) const
|
||||
inline uint8 CCamera::IsSphereVisible_FH(const ::Sphere& s) const
|
||||
{
|
||||
f32 nc, rc, lc, tc, bc, cc;
|
||||
if ((nc = m_fp[0] | s.center) > s.radius)
|
||||
|
||||
@@ -794,7 +794,7 @@ struct HWVSphere
|
||||
radius = r;
|
||||
}
|
||||
|
||||
ILINE HWVSphere(const Sphere& sp)
|
||||
ILINE HWVSphere(const ::Sphere& sp)
|
||||
{
|
||||
center = HWVLoadVecUnaligned(&sp.center);
|
||||
radius = SIMDFLoadFloat(sp.radius);
|
||||
|
||||
@@ -1168,17 +1168,6 @@ namespace Distance {
|
||||
return fDist2;
|
||||
}
|
||||
|
||||
// Compute both the min and max distances of a box to a plane, in the sense of the plane normal.
|
||||
inline void AABB_Plane(float* pfDistMin, float* pfDistMax, const AABB& box, const Plane& pl)
|
||||
{
|
||||
float fDist0 = pl.DistFromPlane(box.min),
|
||||
fDistX = (box.max.x - box.min.x) * pl.n.x,
|
||||
fDistY = (box.max.y - box.min.y) * pl.n.y,
|
||||
fDistZ = (box.max.z - box.min.z) * pl.n.z;
|
||||
*pfDistMin = fDist0 + min(fDistX, 0.f) + min(fDistY, 0.f) + min(fDistZ, 0.f);
|
||||
*pfDistMax = fDist0 + max(fDistX, 0.f) + max(fDistY, 0.f) + max(fDistZ, 0.f);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Distance: Sphere_Triangle
|
||||
//----------------------------------------------------------------------------------
|
||||
@@ -1190,7 +1179,7 @@ namespace Distance {
|
||||
// float result = Distance::Point_TriangleSq( pos, triangle );
|
||||
//----------------------------------------------------------------------------------
|
||||
template<typename F>
|
||||
ILINE F Sphere_TriangleSq(const Sphere& s, const Triangle_tpl<F>& t)
|
||||
ILINE F Sphere_TriangleSq(const ::Sphere& s, const Triangle_tpl<F>& t)
|
||||
{
|
||||
F sqdistance = Distance::Point_TriangleSq(s.center, t) - (s.radius * s.radius);
|
||||
if (sqdistance < 0)
|
||||
@@ -1201,7 +1190,7 @@ namespace Distance {
|
||||
}
|
||||
|
||||
template<typename F>
|
||||
ILINE F Sphere_TriangleSq(const Sphere& s, const Triangle_tpl<F>& t, Vec3_tpl<F>& output)
|
||||
ILINE F Sphere_TriangleSq(const ::Sphere& s, const Triangle_tpl<F>& t, Vec3_tpl<F>& output)
|
||||
{
|
||||
F sqdistance = Distance::Point_TriangleSq(s.center, t, output) - (s.radius * s.radius);
|
||||
if (sqdistance < 0)
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
#include <Cry_Geo.h>
|
||||
|
||||
namespace Intersect {
|
||||
inline bool Ray_Plane(const Ray& ray, const Plane& plane, Vec3& output, bool bSingleSidePlane = true)
|
||||
inline bool Ray_Plane(const Ray& ray, const Plane_tpl<f32>& plane, Vec3& output, bool bSingleSidePlane = true)
|
||||
{
|
||||
float cosine = plane.n | ray.direction;
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace Intersect {
|
||||
return true; //intersection occurred
|
||||
}
|
||||
|
||||
inline bool Line_Plane(const Line& line, const Plane& plane, Vec3& output, bool bSingleSidePlane = true)
|
||||
inline bool Line_Plane(const Line& line, const Plane_tpl<f32>& plane, Vec3& output, bool bSingleSidePlane = true)
|
||||
{
|
||||
float cosine = plane.n | line.direction;
|
||||
|
||||
@@ -792,7 +792,7 @@ namespace Intersect {
|
||||
//--- 0x03 = two intersection, lineseg has ENTRY and EXIT point --
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
inline unsigned char Line_Sphere(const Line& line, const Sphere& s, Vec3& i0, Vec3& i1)
|
||||
inline unsigned char Line_Sphere(const Line& line, const ::Sphere& s, Vec3& i0, Vec3& i1)
|
||||
{
|
||||
Vec3 end = line.pointonline + line.direction;
|
||||
|
||||
@@ -830,7 +830,7 @@ namespace Intersect {
|
||||
//--- 0x03 = two intersection, lineseg has ENTRY and EXIT point --
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
inline unsigned char Ray_Sphere(const Ray& ray, const Sphere& s, Vec3& i0, Vec3& i1)
|
||||
inline unsigned char Ray_Sphere(const Ray& ray, const ::Sphere& s, Vec3& i0, Vec3& i1)
|
||||
{
|
||||
Vec3 end = ray.origin + ray.direction;
|
||||
float a = ray.direction | ray.direction;
|
||||
@@ -863,7 +863,7 @@ namespace Intersect {
|
||||
return intersection;
|
||||
}
|
||||
|
||||
inline bool Ray_SphereFirst(const Ray& ray, const Sphere& s, Vec3& intPoint)
|
||||
inline bool Ray_SphereFirst(const Ray& ray, const ::Sphere& s, Vec3& intPoint)
|
||||
{
|
||||
Vec3 p2;
|
||||
unsigned char res = Ray_Sphere(ray, s, intPoint, p2);
|
||||
@@ -886,7 +886,7 @@ namespace Intersect {
|
||||
//--- 0x02 = one intersection, lineseg has just an EXIT point but no ENTRY point (ls.start is inside the sphere) --
|
||||
//--- 0x03 = two intersection, lineseg has ENTRY and EXIT point --
|
||||
//----------------------------------------------------------------------------------
|
||||
inline unsigned char Lineseg_Sphere(const Lineseg& ls, const Sphere& s, Vec3& i0, Vec3& i1)
|
||||
inline unsigned char Lineseg_Sphere(const Lineseg& ls, const ::Sphere& s, Vec3& i0, Vec3& i1)
|
||||
{
|
||||
Vec3 dir = (ls.end - ls.start);
|
||||
|
||||
@@ -931,7 +931,7 @@ namespace Intersect {
|
||||
}
|
||||
|
||||
|
||||
inline bool Lineseg_SphereFirst(const Lineseg& lineseg, const Sphere& s, Vec3& intPoint)
|
||||
inline bool Lineseg_SphereFirst(const Lineseg& lineseg, const ::Sphere& s, Vec3& intPoint)
|
||||
{
|
||||
Vec3 p2;
|
||||
uint8 res = Lineseg_Sphere(lineseg, s, intPoint, p2);
|
||||
|
||||
@@ -103,7 +103,7 @@ namespace Overlap {
|
||||
// Checks if a point is inside a sphere.
|
||||
// Example:
|
||||
// bool result=Overlap::Point_Sphere( point, sphere );
|
||||
ILINE bool Point_Sphere(const Vec3& p, const Sphere& s)
|
||||
ILINE bool Point_Sphere(const Vec3& p, const ::Sphere& s)
|
||||
{
|
||||
Vec3 distc = p - s.center;
|
||||
f32 sqrad = s.radius * s.radius;
|
||||
@@ -407,7 +407,7 @@ namespace Overlap {
|
||||
|
||||
|
||||
//! check if a Lineseg and a Sphere overlap
|
||||
inline bool Lineseg_Sphere(const Lineseg& ls, const Sphere& s)
|
||||
inline bool Lineseg_Sphere(const Lineseg& ls, const ::Sphere& s)
|
||||
{
|
||||
float radius2 = s.radius * s.radius;
|
||||
|
||||
@@ -729,7 +729,7 @@ namespace Overlap {
|
||||
* 0 = no overlap
|
||||
* 1 = overlap
|
||||
*----------------------------------------------------------------------------------*/
|
||||
ILINE bool Sphere_AABB(const Sphere& s, const AABB& aabb)
|
||||
ILINE bool Sphere_AABB(const ::Sphere& s, const AABB& aabb)
|
||||
{
|
||||
Vec3 center(s.center);
|
||||
|
||||
@@ -746,7 +746,7 @@ namespace Overlap {
|
||||
}
|
||||
|
||||
// As Sphere_AABB but ignores z parts
|
||||
ILINE bool Sphere_AABB2D(const Sphere& s, const AABB& aabb)
|
||||
ILINE bool Sphere_AABB2D(const ::Sphere& s, const AABB& aabb)
|
||||
{
|
||||
Vec3 center(s.center);
|
||||
|
||||
@@ -776,7 +776,7 @@ namespace Overlap {
|
||||
* 0x01 = Sphere and AABB overlap
|
||||
* 0x02 = Sphere in inside AABB
|
||||
*/
|
||||
ILINE char Sphere_AABB_Inside(const Sphere& s, const AABB& aabb)
|
||||
ILINE char Sphere_AABB_Inside(const ::Sphere& s, const AABB& aabb)
|
||||
{
|
||||
if (Sphere_AABB(s, aabb))
|
||||
{
|
||||
@@ -819,7 +819,7 @@ namespace Overlap {
|
||||
//--- 0 = no overlap ---------------------------
|
||||
//--- 1 = overlap -----------------
|
||||
//----------------------------------------------------------------------------------
|
||||
inline bool Sphere_OBB(const Sphere& s, const OBB& obb)
|
||||
inline bool Sphere_OBB(const ::Sphere& s, const OBB& obb)
|
||||
{
|
||||
//first we transform the sphere-center into the AABB-space of the OBB
|
||||
Vec3 SphereInOBBSpace = s.center * obb.m33;
|
||||
@@ -861,7 +861,7 @@ namespace Overlap {
|
||||
//--- 0 = no overlap ---------------------------
|
||||
//--- 1 = overlap -----------------
|
||||
//----------------------------------------------------------------------------------
|
||||
inline bool Sphere_Sphere(const Sphere& s1, const Sphere& s2)
|
||||
inline bool Sphere_Sphere(const ::Sphere& s1, const ::Sphere& s2)
|
||||
{
|
||||
Vec3 distc = s1.center - s2.center;
|
||||
f32 sqrad = (s1.radius + s2.radius) * (s1.radius + s2.radius);
|
||||
@@ -884,7 +884,7 @@ namespace Overlap {
|
||||
//--- 1 = overlap -----------------
|
||||
//----------------------------------------------------------------------------------
|
||||
template<typename F>
|
||||
ILINE bool Sphere_Triangle(const Sphere& s, const Triangle_tpl<F>& t)
|
||||
ILINE bool Sphere_Triangle(const ::Sphere& s, const Triangle_tpl<F>& t)
|
||||
{
|
||||
//create a "bouding sphere" around triangle for fast rejection test
|
||||
Vec3_tpl<F> middle = (t.v0 + t.v1 + t.v2) * (1 / 3.0f);
|
||||
@@ -899,7 +899,7 @@ namespace Overlap {
|
||||
SqRad0 = (F)fsel(SqRad0 - SqRad2, SqRad0, SqRad2);
|
||||
|
||||
//first simple rejection-test...
|
||||
if (Sphere_Sphere(s, Sphere(middle, sqrt_tpl(SqRad0))) == 0)
|
||||
if (Sphere_Sphere(s, ::Sphere(middle, sqrt_tpl(SqRad0))) == 0)
|
||||
{
|
||||
return 0; //overlap not possible
|
||||
}
|
||||
@@ -945,29 +945,6 @@ namespace Overlap {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
*
|
||||
* we use the SEPARATING-AXIS-TEST for OBB/Plane overlap.
|
||||
*
|
||||
* Example:
|
||||
* bool result=Overlap::OBB_Plane( pos,obb, plane );
|
||||
*
|
||||
*/
|
||||
inline bool OBB_Plane(const Vec3& pos, const OBB& obb, const Plane& plane)
|
||||
{
|
||||
//the new center-position in world-space
|
||||
Vec3 p = obb.m33 * obb.c + pos;
|
||||
//extract the orientation-vectors from the columns of the 3x3 matrix
|
||||
//and scale them by the half-lengths
|
||||
Vec3 ax = Vec3(obb.m33.m00, obb.m33.m10, obb.m33.m20) * obb.h.x;
|
||||
Vec3 ay = Vec3(obb.m33.m01, obb.m33.m11, obb.m33.m21) * obb.h.y;
|
||||
Vec3 az = Vec3(obb.m33.m02, obb.m33.m12, obb.m33.m22) * obb.h.z;
|
||||
//check OBB against Plane, using the plane-normal as separating axis
|
||||
return fabsf(plane | p) < (fabsf(plane.n | ax) + fabsf(plane.n | ay) + fabsf(plane.n | az));
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
*
|
||||
* we use the SEPARATING AXIS TEST to check if a triangle and AABB overlap.
|
||||
@@ -1214,7 +1191,7 @@ namespace Overlap {
|
||||
|
||||
//test if the box intersects the plane of the triangle
|
||||
//compute plane equation of triangle: normal*x+d=0
|
||||
Plane plane = Plane::CreatePlane((e0 % e1), v0);
|
||||
Plane_tpl<f32> plane = Plane_tpl<f32>::CreatePlane((e0 % e1), v0);
|
||||
|
||||
Vec3 vmin, vmax;
|
||||
if (plane.n.x > 0.0f)
|
||||
@@ -1505,7 +1482,7 @@ namespace Overlap {
|
||||
|
||||
//test if the box overlaps the plane of the triangle
|
||||
//compute plane equation of triangle: normal*x+d=0
|
||||
Plane plane = Plane::CreatePlane((e0 % e1), v0);
|
||||
Plane_tpl<f32> plane = Plane_tpl<f32>::CreatePlane((e0 % e1), v0);
|
||||
|
||||
Vec3 vmin, vmax;
|
||||
if (plane.n.x > 0.0f)
|
||||
|
||||
@@ -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__
|
||||
@@ -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.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "EngineSettingsBackend.h"
|
||||
|
||||
#ifdef CRY_ENABLE_RC_HELPER
|
||||
|
||||
CEngineSettingsBackend::CEngineSettingsBackend(CEngineSettingsManager* parent, const wchar_t* moduleName)
|
||||
: m_parent(parent)
|
||||
, m_moduleName()
|
||||
{
|
||||
if (moduleName != nullptr)
|
||||
{
|
||||
m_moduleName = moduleName;
|
||||
}
|
||||
}
|
||||
|
||||
CEngineSettingsBackend::~CEngineSettingsBackend()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#endif // CRY_ENABLE_RC_HELPER
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
#ifndef CRYINCLUDE_CRYCOMMON_ENGINESETTINGSBACKEND_H
|
||||
#define CRYINCLUDE_CRYCOMMON_ENGINESETTINGSBACKEND_H
|
||||
#pragma once
|
||||
|
||||
#include "ProjectDefines.h"
|
||||
|
||||
#ifdef CRY_ENABLE_RC_HELPER
|
||||
|
||||
#include "SettingsManagerHelpers.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
class CEngineSettingsManager;
|
||||
|
||||
class CEngineSettingsBackend
|
||||
{
|
||||
public:
|
||||
CEngineSettingsBackend(CEngineSettingsManager* parent, const wchar_t* moduleName = NULL);
|
||||
virtual ~CEngineSettingsBackend();
|
||||
|
||||
virtual std::wstring GetModuleFilePath() const = 0;
|
||||
|
||||
virtual bool GetModuleSpecificStringEntryUtf16(const char* key, SettingsManagerHelpers::CWCharBuffer wbuffer) = 0;
|
||||
virtual bool GetModuleSpecificIntEntry(const char* key, int& value) = 0;
|
||||
virtual bool GetModuleSpecificBoolEntry(const char* key, bool& value) = 0;
|
||||
|
||||
virtual bool SetModuleSpecificStringEntryUtf16(const char* key, const wchar_t* str) = 0;
|
||||
virtual bool SetModuleSpecificIntEntry(const char* key, const int& value) = 0;
|
||||
virtual bool SetModuleSpecificBoolEntry(const char* key, const bool& value) = 0;
|
||||
|
||||
virtual bool GetInstalledBuildRootPathUtf16(const int index, SettingsManagerHelpers::CWCharBuffer name, SettingsManagerHelpers::CWCharBuffer path) = 0;
|
||||
|
||||
virtual void LoadEngineSettingsFromRegistry() = 0;
|
||||
virtual bool StoreEngineSettingsToRegistry() = 0;
|
||||
|
||||
protected:
|
||||
CEngineSettingsManager* parent() const
|
||||
{
|
||||
return m_parent;
|
||||
}
|
||||
|
||||
const std::wstring& moduleName() const
|
||||
{
|
||||
return m_moduleName;
|
||||
}
|
||||
|
||||
private:
|
||||
std::wstring m_moduleName;
|
||||
CEngineSettingsManager* m_parent;
|
||||
};
|
||||
|
||||
#endif // CRY_ENABLE_RC_HELPER
|
||||
|
||||
#endif // CRYINCLUDE_CRYCOMMON_ENGINESETTINGSBACKEND_H
|
||||
@@ -1,486 +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 "EngineSettingsBackendApple.h"
|
||||
|
||||
#ifdef CRY_ENABLE_RC_HELPER
|
||||
|
||||
#include "AzCore/PlatformDef.h"
|
||||
|
||||
#if AZ_TRAIT_OS_PLATFORM_APPLE
|
||||
|
||||
#include "EngineSettingsManager.h"
|
||||
#include "SettingsManagerHelpers.h"
|
||||
|
||||
#include "platform.h"
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <mach-o/dyld.h>
|
||||
#include <mach-o/nlist.h>
|
||||
|
||||
#include <cassert>
|
||||
#include <codecvt>
|
||||
#include <cstdlib>
|
||||
#include <fstream>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
using namespace SettingsManagerHelpers;
|
||||
|
||||
static const char gDefaultRegistryLocation[] = "/EngineSettings.reg";
|
||||
|
||||
#define REG_SOFTWARE L"Software\\"
|
||||
#define REG_COMPANY_NAME L"Amazon\\"
|
||||
#define REG_PRODUCT_NAME L"Lumberyard\\"
|
||||
#define REG_SETTING L"Settings\\"
|
||||
#define REG_BASE_SETTING_KEY REG_SOFTWARE REG_COMPANY_NAME REG_PRODUCT_NAME REG_SETTING
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
class SimpleRegistry
|
||||
{
|
||||
typedef std::map< std::wstring, std::wstring > WStringMap;
|
||||
std::map< std::wstring, WStringMap * > m_modules;
|
||||
|
||||
public:
|
||||
SimpleRegistry();
|
||||
~SimpleRegistry();
|
||||
|
||||
void setBoolValue(const std::wstring& module, const std::wstring& key, bool value);
|
||||
void setIntValue(const std::wstring& module, const std::wstring& key, int value);
|
||||
void setStrValue(const std::wstring& module, const std::wstring& key, const std::wstring& value);
|
||||
|
||||
bool getBoolValue(const std::wstring& module, const std::wstring& key, bool& value);
|
||||
bool getIntValue(const std::wstring& module, const std::wstring& key, int& value);
|
||||
bool getStrValue(const std::wstring& module, const std::wstring& key, std::wstring& value);
|
||||
|
||||
bool loadFromFile(const char* fileName);
|
||||
bool saveToFile(const char* fileName);
|
||||
|
||||
protected:
|
||||
void clear();
|
||||
|
||||
private:
|
||||
static const wchar_t gSimpleMagic[];
|
||||
static const size_t gMetaCharCount;
|
||||
};
|
||||
|
||||
const wchar_t SimpleRegistry::gSimpleMagic[] = L"FR0";
|
||||
const size_t SimpleRegistry::gMetaCharCount = sizeof(size_t) / sizeof(wchar_t);
|
||||
|
||||
SimpleRegistry::SimpleRegistry()
|
||||
{
|
||||
}
|
||||
|
||||
SimpleRegistry::~SimpleRegistry()
|
||||
{
|
||||
clear();
|
||||
}
|
||||
|
||||
void SimpleRegistry::setBoolValue(const std::wstring& module, const std::wstring& key, bool value)
|
||||
{
|
||||
return setStrValue(module, key, value ? L"true" : L"false");
|
||||
}
|
||||
|
||||
void SimpleRegistry::setIntValue(const std::wstring& module, const std::wstring& key, int value)
|
||||
{
|
||||
return setStrValue(module, key, std::to_wstring(value));
|
||||
}
|
||||
|
||||
void SimpleRegistry::setStrValue(const std::wstring& module, const std::wstring& key, const std::wstring& value)
|
||||
{
|
||||
WStringMap *map = nullptr;
|
||||
|
||||
auto i = m_modules.find(module);
|
||||
|
||||
if (i == m_modules.end())
|
||||
{
|
||||
map = new WStringMap;
|
||||
m_modules.emplace(module, map);
|
||||
}
|
||||
else
|
||||
{
|
||||
map = i->second;
|
||||
}
|
||||
|
||||
assert(map);
|
||||
|
||||
(*map)[key] = value;
|
||||
}
|
||||
|
||||
bool SimpleRegistry::getBoolValue(const std::wstring& module, const std::wstring& key, bool& value)
|
||||
{
|
||||
std::wstring str;
|
||||
|
||||
if (!getStrValue(module, key, str))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
value = (0 == str.compare(L"true"));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SimpleRegistry::getIntValue(const std::wstring& module, const std::wstring& key, int& value)
|
||||
{
|
||||
std::wstring str;
|
||||
|
||||
if (!getStrValue(module, key, str))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
value = std::stoi(str);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SimpleRegistry::getStrValue(const std::wstring& module, const std::wstring& key, std::wstring& value)
|
||||
{
|
||||
WStringMap *map = nullptr;
|
||||
|
||||
auto mi = m_modules.find(module);
|
||||
if (mi == m_modules.end())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
map = mi->second;
|
||||
assert(map);
|
||||
|
||||
auto ki = map->find(key);
|
||||
if (ki == map->end())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
value = ki->second;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SimpleRegistry::loadFromFile(const char* fileName)
|
||||
{
|
||||
clear();
|
||||
|
||||
std::wifstream file(fileName, std::ios_base::in|std::ios_base::binary);
|
||||
file.imbue(std::locale(file.getloc(), new std::codecvt_utf16<wchar_t>));
|
||||
if (!file.is_open())
|
||||
{
|
||||
AZ_Warning("EngineSettings", false, "Failed to open registry settings file: %s", fileName);
|
||||
return false;
|
||||
}
|
||||
|
||||
std::wstring module;
|
||||
std::wstring key;
|
||||
std::wstring value;
|
||||
|
||||
wchar_t buffer[512];
|
||||
size_t size;
|
||||
wchar_t meta[gMetaCharCount];
|
||||
|
||||
/* magic number */
|
||||
if(!file.read(buffer, sizeof(gSimpleMagic) / sizeof(wchar_t)) ||
|
||||
wcsncmp(gSimpleMagic, buffer, sizeof(gSimpleMagic) / sizeof(wchar_t)) != 0)
|
||||
{
|
||||
file.close();
|
||||
AZ_Warning("EngineSettings", false, "Failed to load registry settings from file: %s", fileName);
|
||||
return false;
|
||||
}
|
||||
|
||||
while (file.good())
|
||||
{
|
||||
file.read(meta, gMetaCharCount);
|
||||
if (!file.good())
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
memcpy(&size, meta, sizeof(size));
|
||||
file.read(buffer, size);
|
||||
buffer[file.gcount()] = L'\0';
|
||||
module = buffer;
|
||||
|
||||
file.read(meta, gMetaCharCount);
|
||||
memcpy(&size, meta, sizeof(size));
|
||||
file.read(buffer, size);
|
||||
buffer[file.gcount()] = L'\0';
|
||||
key = buffer;
|
||||
|
||||
file.read(meta, gMetaCharCount);
|
||||
memcpy(&size, meta, sizeof(size));
|
||||
file.read(buffer, size);
|
||||
buffer[file.gcount()] = L'\0';
|
||||
value = buffer;
|
||||
|
||||
setStrValue(module, key, value);
|
||||
}
|
||||
|
||||
file.close();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SimpleRegistry::saveToFile(const char* fileName)
|
||||
{
|
||||
std::wofstream file(fileName, std::ios_base::out|std::ios_base::trunc|std::ios_base::binary);
|
||||
file.imbue(std::locale(file.getloc(), new std::codecvt_utf16<wchar_t>));
|
||||
if (!file.is_open())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
std::wstring module;
|
||||
|
||||
size_t size;
|
||||
wchar_t meta[gMetaCharCount];
|
||||
|
||||
/* magic number */
|
||||
file.write(gSimpleMagic, sizeof(gSimpleMagic) / sizeof(wchar_t));
|
||||
|
||||
for (auto j : m_modules)
|
||||
{
|
||||
module = j.first;
|
||||
|
||||
for (auto i : *j.second)
|
||||
{
|
||||
size = module.size();
|
||||
memcpy(meta, &size, sizeof(meta));
|
||||
file.write(meta, gMetaCharCount);
|
||||
file.write(module.c_str(), size);
|
||||
|
||||
size = i.first.size();
|
||||
memcpy(meta, &size, sizeof(meta));
|
||||
file.write(meta, gMetaCharCount);
|
||||
file.write(i.first.c_str(), size);
|
||||
|
||||
size = i.second.size();
|
||||
memcpy(meta, &size, sizeof(meta));
|
||||
file.write(meta, gMetaCharCount);
|
||||
file.write(i.second.c_str(), size);
|
||||
}
|
||||
}
|
||||
|
||||
file.close();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void SimpleRegistry::clear()
|
||||
{
|
||||
for (auto pair : m_modules)
|
||||
{
|
||||
delete pair.second;
|
||||
}
|
||||
|
||||
m_modules.clear();
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
CEngineSettingsBackendApple::CEngineSettingsBackendApple(CEngineSettingsManager* parent, const wchar_t* moduleName)
|
||||
: CEngineSettingsBackend(parent, moduleName)
|
||||
, m_registry(new SimpleRegistry)
|
||||
, m_registryFilePath()
|
||||
{
|
||||
std::string rootValue = gEnv->pFileIO->GetAlias("@root@");
|
||||
if (rootValue.empty())
|
||||
{
|
||||
AZ_Warning("EngineSettings", false, "Could not get engine root.");
|
||||
return;
|
||||
}
|
||||
|
||||
rootValue.append(gDefaultRegistryLocation);
|
||||
m_registryFilePath = rootValue;
|
||||
}
|
||||
|
||||
CEngineSettingsBackendApple::~CEngineSettingsBackendApple()
|
||||
{
|
||||
delete m_registry, m_registry = nullptr;
|
||||
}
|
||||
|
||||
std::wstring CEngineSettingsBackendApple::GetModuleFilePath() const
|
||||
{
|
||||
std::string path;
|
||||
|
||||
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
|
||||
std::string module = converter.to_bytes(moduleName());
|
||||
|
||||
void* handle = ::dlopen(module.c_str(), RTLD_LAZY);
|
||||
if (handle)
|
||||
{
|
||||
const int c = _dyld_image_count();
|
||||
for (int i = 0; i < c; ++i)
|
||||
{
|
||||
const char* image = _dyld_get_image_name(i);
|
||||
const void* altHandle = dlopen(image, RTLD_LAZY);
|
||||
if (handle == altHandle)
|
||||
{
|
||||
char absImage[PATH_MAX];
|
||||
realpath(image, absImage);
|
||||
char *ext = rindex(absImage, '.');
|
||||
if (ext)
|
||||
{
|
||||
*ext = '\0';
|
||||
}
|
||||
path.append(absImage);
|
||||
path.append(".ini");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return converter.from_bytes(path);
|
||||
}
|
||||
|
||||
bool CEngineSettingsBackendApple::GetModuleSpecificStringEntryUtf16(const char* key, CWCharBuffer wbuffer)
|
||||
{
|
||||
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
|
||||
std::wstring wkey = converter.from_bytes(key);
|
||||
|
||||
std::wstring str;
|
||||
if (!m_registry->getStrValue(moduleName(), wkey, str))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
std::wcscpy(wbuffer.getPtr(), str.c_str());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CEngineSettingsBackendApple::GetModuleSpecificIntEntry(const char* key, int& value)
|
||||
{
|
||||
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
|
||||
std::wstring wkey = converter.from_bytes(key);
|
||||
|
||||
return m_registry->getIntValue(moduleName(), wkey, value);
|
||||
}
|
||||
|
||||
bool CEngineSettingsBackendApple::GetModuleSpecificBoolEntry(const char* key, bool& value)
|
||||
{
|
||||
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
|
||||
std::wstring wkey = converter.from_bytes(key);
|
||||
|
||||
return m_registry->getBoolValue(moduleName(), wkey, value);
|
||||
}
|
||||
|
||||
bool CEngineSettingsBackendApple::SetModuleSpecificStringEntryUtf16(const char* key, const wchar_t* str)
|
||||
{
|
||||
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
|
||||
std::wstring wkey = converter.from_bytes(key);
|
||||
|
||||
m_registry->setStrValue(moduleName(), wkey, str);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CEngineSettingsBackendApple::SetModuleSpecificIntEntry(const char* key, const int& value)
|
||||
{
|
||||
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
|
||||
std::wstring wkey = converter.from_bytes(key);
|
||||
|
||||
m_registry->setIntValue(moduleName(), wkey, value);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CEngineSettingsBackendApple::SetModuleSpecificBoolEntry(const char* key, const bool& value)
|
||||
{
|
||||
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
|
||||
std::wstring wkey = converter.from_bytes(key);
|
||||
|
||||
m_registry->setBoolValue(moduleName(), wkey, value);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CEngineSettingsBackendApple::GetInstalledBuildRootPathUtf16(const int index, CWCharBuffer name, CWCharBuffer path)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CEngineSettingsBackendApple::StoreEngineSettingsToRegistry()
|
||||
{
|
||||
bool bRet = true;
|
||||
wchar_t buffer[1024];
|
||||
|
||||
// ResourceCompiler Specific
|
||||
if (parent()->GetValueByRef("RC_ShowWindow", SettingsManagerHelpers::CWCharBuffer(buffer, sizeof(buffer))))
|
||||
{
|
||||
const bool b = wcscmp(buffer, L"true") == 0;
|
||||
m_registry->setBoolValue(REG_BASE_SETTING_KEY, L"RC_ShowWindow", b);
|
||||
}
|
||||
|
||||
if (parent()->GetValueByRef("RC_HideCustom", SettingsManagerHelpers::CWCharBuffer(buffer, sizeof(buffer))))
|
||||
{
|
||||
const bool b = wcscmp(buffer, L"true") == 0;
|
||||
m_registry->setBoolValue(REG_BASE_SETTING_KEY, L"RC_HideCustom", b);
|
||||
}
|
||||
|
||||
if (parent()->GetValueByRef("RC_Parameters", SettingsManagerHelpers::CWCharBuffer(buffer, sizeof(buffer))))
|
||||
{
|
||||
m_registry->setStrValue(REG_BASE_SETTING_KEY, L"RC_Parameters", buffer);
|
||||
}
|
||||
|
||||
if (parent()->GetValueByRef("RC_EnableSourceControl", SettingsManagerHelpers::CWCharBuffer(buffer, sizeof(buffer))))
|
||||
{
|
||||
const bool b = wcscmp(buffer, L"true") == 0;
|
||||
m_registry->setBoolValue(REG_BASE_SETTING_KEY, L"RC_EnableSourceControl", b);
|
||||
}
|
||||
|
||||
bRet &= m_registry->saveToFile(m_registryFilePath.c_str());
|
||||
return bRet;
|
||||
}
|
||||
|
||||
void CEngineSettingsBackendApple::LoadEngineSettingsFromRegistry()
|
||||
{
|
||||
if (!m_registry->loadFromFile(m_registryFilePath.c_str()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
std::wstring wStrResult;
|
||||
bool bResult;
|
||||
|
||||
if (m_registry->getStrValue(REG_BASE_SETTING_KEY, L"RootPath", wStrResult))
|
||||
{
|
||||
parent()->SetKey("ENG_RootPath", wStrResult.c_str());
|
||||
}
|
||||
|
||||
// Engine Specific
|
||||
if (m_registry->getStrValue(REG_BASE_SETTING_KEY, L"ENG_RootPath", wStrResult))
|
||||
{
|
||||
parent()->SetKey("ENG_RootPath", wStrResult.c_str());
|
||||
}
|
||||
|
||||
// ResourceCompiler Specific
|
||||
if (m_registry->getBoolValue(REG_BASE_SETTING_KEY, L"RC_ShowWindow", bResult))
|
||||
{
|
||||
parent()->SetKey("RC_ShowWindow", bResult);
|
||||
}
|
||||
if (m_registry->getBoolValue(REG_BASE_SETTING_KEY, L"RC_HideCustom", bResult))
|
||||
{
|
||||
parent()->SetKey("RC_HideCustom", bResult);
|
||||
}
|
||||
if (m_registry->getStrValue(REG_BASE_SETTING_KEY, L"RC_Parameters", wStrResult))
|
||||
{
|
||||
parent()->SetKey("RC_Parameters", wStrResult.c_str());
|
||||
}
|
||||
if (m_registry->getBoolValue(REG_BASE_SETTING_KEY, L"RC_EnableSourceControl", bResult))
|
||||
{
|
||||
parent()->SetKey("RC_EnableSourceControl", bResult);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // AZ_TRAIT_OS_PLATFORM_APPLE
|
||||
#endif // CRY_ENABLE_RC_HELPER
|
||||
|
||||
@@ -1,51 +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_ENGINESETTINGSBACKENDAPPLE_H
|
||||
#define CRYINCLUDE_CRYCOMMON_ENGINESETTINGSBACKENDAPPLE_H
|
||||
#pragma once
|
||||
|
||||
#include "EngineSettingsBackend.h"
|
||||
|
||||
#ifdef CRY_ENABLE_RC_HELPER
|
||||
|
||||
class CEngineSettingsManager;
|
||||
class SimpleRegistry;
|
||||
|
||||
class CEngineSettingsBackendApple : public CEngineSettingsBackend
|
||||
{
|
||||
public:
|
||||
CEngineSettingsBackendApple(CEngineSettingsManager* parent, const wchar_t* moduleName = NULL);
|
||||
~CEngineSettingsBackendApple();
|
||||
|
||||
std::wstring GetModuleFilePath() const override;
|
||||
|
||||
bool GetModuleSpecificStringEntryUtf16(const char* key, SettingsManagerHelpers::CWCharBuffer wbuffer) override;
|
||||
bool GetModuleSpecificIntEntry(const char* key, int& value) override;
|
||||
bool GetModuleSpecificBoolEntry(const char* key, bool& value) override;
|
||||
|
||||
bool SetModuleSpecificStringEntryUtf16(const char* key, const wchar_t* str) override;
|
||||
bool SetModuleSpecificIntEntry(const char* key, const int& value) override;
|
||||
bool SetModuleSpecificBoolEntry(const char* key, const bool& value) override;
|
||||
|
||||
bool GetInstalledBuildRootPathUtf16(const int index, SettingsManagerHelpers::CWCharBuffer name, SettingsManagerHelpers::CWCharBuffer path) override;
|
||||
|
||||
void LoadEngineSettingsFromRegistry() override;
|
||||
bool StoreEngineSettingsToRegistry() override;
|
||||
|
||||
private:
|
||||
SimpleRegistry *m_registry;
|
||||
std::string m_registryFilePath;
|
||||
};
|
||||
|
||||
#endif // CRY_ENABLE_RC_HELPER
|
||||
|
||||
#endif // CRYINCLUDE_CRYCOMMON_ENGINESETTINGSBACKENDAPPLE_H
|
||||
@@ -1,431 +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 "EngineSettingsBackendWin32.h"
|
||||
|
||||
#ifdef CRY_ENABLE_RC_HELPER
|
||||
|
||||
#include "AzCore/PlatformDef.h"
|
||||
|
||||
#ifdef AZ_PLATFORM_WINDOWS
|
||||
|
||||
#include "EngineSettingsManager.h"
|
||||
|
||||
#include "platform.h"
|
||||
#include <windows.h>
|
||||
|
||||
#define REG_SOFTWARE L"Software\\"
|
||||
#define REG_COMPANY_NAME L"Amazon\\"
|
||||
#define REG_PRODUCT_NAME L"Open 3D Engine\\"
|
||||
#define REG_SETTING L"Settings\\"
|
||||
#define REG_BASE_SETTING_KEY REG_SOFTWARE REG_COMPANY_NAME REG_PRODUCT_NAME REG_SETTING
|
||||
|
||||
EXTERN_C IMAGE_DOS_HEADER __ImageBase;
|
||||
|
||||
using namespace SettingsManagerHelpers;
|
||||
|
||||
static bool g_bWindowQuit;
|
||||
static CEngineSettingsManager* g_pThis = 0;
|
||||
static const unsigned int IDC_hEditRootPath = 100;
|
||||
static const unsigned int IDC_hBtnBrowse = 101;
|
||||
|
||||
namespace
|
||||
{
|
||||
class RegKey
|
||||
{
|
||||
public:
|
||||
RegKey(const wchar_t* key, bool writeable);
|
||||
~RegKey();
|
||||
void* pKey;
|
||||
};
|
||||
|
||||
RegKey::RegKey(const wchar_t* key, bool writeable)
|
||||
{
|
||||
HKEY hKey;
|
||||
LONG result;
|
||||
if (writeable)
|
||||
{
|
||||
result = RegCreateKeyExW(HKEY_CURRENT_USER, key, 0, 0, 0, KEY_WRITE, 0, &hKey, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = RegOpenKeyExW(HKEY_CURRENT_USER, key, 0, KEY_READ, &hKey);
|
||||
}
|
||||
pKey = hKey;
|
||||
}
|
||||
|
||||
RegKey::~RegKey()
|
||||
{
|
||||
RegCloseKey((HKEY)pKey);
|
||||
}
|
||||
}
|
||||
|
||||
CEngineSettingsBackendWin32::CEngineSettingsBackendWin32(CEngineSettingsManager* parent, const wchar_t* moduleName)
|
||||
: CEngineSettingsBackend(parent, moduleName)
|
||||
{
|
||||
}
|
||||
|
||||
std::wstring CEngineSettingsBackendWin32::GetModuleFilePath() const
|
||||
{
|
||||
wchar_t szFilename[_MAX_PATH];
|
||||
GetModuleFileNameW((HINSTANCE)&__ImageBase, szFilename, _MAX_PATH);
|
||||
wchar_t drive[_MAX_DRIVE];
|
||||
wchar_t dir[_MAX_DIR];
|
||||
wchar_t fname[_MAX_FNAME];
|
||||
wchar_t ext[1] = L"";
|
||||
_wsplitpath_s(szFilename, drive, dir, fname, ext);
|
||||
_wmakepath_s(szFilename, drive, dir, fname, L"ini");
|
||||
return szFilename;
|
||||
}
|
||||
|
||||
bool CEngineSettingsBackendWin32::GetModuleSpecificStringEntryUtf16(const char* key, CWCharBuffer wbuffer)
|
||||
{
|
||||
CFixedString<wchar_t, 256> s = REG_BASE_SETTING_KEY;
|
||||
s.append(moduleName().c_str());
|
||||
RegKey superKey(s.c_str(), false);
|
||||
if (!superKey.pKey)
|
||||
{
|
||||
wbuffer[0] = 0;
|
||||
return false;
|
||||
}
|
||||
if (!GetRegValue(superKey.pKey, key, wbuffer))
|
||||
{
|
||||
wbuffer[0] = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CEngineSettingsBackendWin32::GetModuleSpecificIntEntry(const char* key, int& value)
|
||||
{
|
||||
CFixedString<wchar_t, 256> s = REG_BASE_SETTING_KEY;
|
||||
s.append(moduleName().c_str());
|
||||
RegKey superKey(s.c_str(), false);
|
||||
if (!superKey.pKey)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!GetRegValue(superKey.pKey, key, value))
|
||||
{
|
||||
value = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CEngineSettingsBackendWin32::GetModuleSpecificBoolEntry(const char* key, bool& value)
|
||||
{
|
||||
CFixedString<wchar_t, 256> s = REG_BASE_SETTING_KEY;
|
||||
s.append(moduleName().c_str());
|
||||
RegKey superKey(s.c_str(), false);
|
||||
if (!superKey.pKey)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!GetRegValue(superKey.pKey, key, value))
|
||||
{
|
||||
value = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CEngineSettingsBackendWin32::SetModuleSpecificStringEntryUtf16(const char* key, const wchar_t* str)
|
||||
{
|
||||
CFixedString<wchar_t, 256> s = REG_BASE_SETTING_KEY;
|
||||
s.append(moduleName().c_str());
|
||||
RegKey superKey(s.c_str(), true);
|
||||
if (superKey.pKey)
|
||||
{
|
||||
return SetRegValue(superKey.pKey, key, str);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CEngineSettingsBackendWin32::SetModuleSpecificIntEntry(const char* key, const int& value)
|
||||
{
|
||||
CFixedString<wchar_t, 256> s = REG_BASE_SETTING_KEY;
|
||||
s.append(moduleName().c_str());
|
||||
RegKey superKey(s.c_str(), true);
|
||||
if (superKey.pKey)
|
||||
{
|
||||
return SetRegValue(superKey.pKey, key, value);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CEngineSettingsBackendWin32::SetModuleSpecificBoolEntry(const char* key, const bool& value)
|
||||
{
|
||||
CFixedString<wchar_t, 256> s = REG_BASE_SETTING_KEY;
|
||||
s.append(moduleName().c_str());
|
||||
RegKey superKey(s.c_str(), true);
|
||||
if (superKey.pKey)
|
||||
{
|
||||
return SetRegValue(superKey.pKey, key, value);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CEngineSettingsBackendWin32::GetInstalledBuildRootPathUtf16(const int index, CWCharBuffer name, CWCharBuffer path)
|
||||
{
|
||||
RegKey key(REG_BASE_SETTING_KEY L"O3DEExport\\ProjectBuilds", false);
|
||||
if (key.pKey)
|
||||
{
|
||||
DWORD type;
|
||||
DWORD nameSizeInBytes = DWORD(name.getSizeInBytes());
|
||||
DWORD pathSizeInBytes = DWORD(path.getSizeInBytes());
|
||||
LONG result = RegEnumValueW((HKEY)key.pKey, index, name.getPtr(), &nameSizeInBytes, NULL, &type, (BYTE*)path.getPtr(), &pathSizeInBytes);
|
||||
if (result == ERROR_SUCCESS)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CEngineSettingsBackendWin32::StoreEngineSettingsToRegistry()
|
||||
{
|
||||
// make sure the path in registry exists
|
||||
{
|
||||
RegKey key0(REG_SOFTWARE REG_COMPANY_NAME, true);
|
||||
if (!key0.pKey)
|
||||
{
|
||||
RegKey software(REG_SOFTWARE, true);
|
||||
HKEY hKey;
|
||||
RegCreateKeyW((HKEY)software.pKey, REG_COMPANY_NAME, &hKey);
|
||||
if (!hKey)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
RegKey key1(REG_SOFTWARE REG_COMPANY_NAME REG_PRODUCT_NAME, true);
|
||||
if (!key1.pKey)
|
||||
{
|
||||
RegKey softwareCompany(REG_SOFTWARE REG_COMPANY_NAME, true);
|
||||
HKEY hKey;
|
||||
RegCreateKeyW((HKEY)softwareCompany.pKey, REG_COMPANY_NAME, &hKey);
|
||||
if (!hKey)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
RegKey key2(REG_BASE_SETTING_KEY, true);
|
||||
if (!key2.pKey)
|
||||
{
|
||||
RegKey softwareCompanyProduct(REG_SOFTWARE REG_COMPANY_NAME REG_PRODUCT_NAME, true);
|
||||
HKEY hKey;
|
||||
RegCreateKeyW((HKEY)key2.pKey, REG_SETTING, &hKey);
|
||||
if (!hKey)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool bRet = true;
|
||||
|
||||
RegKey key(REG_BASE_SETTING_KEY, true);
|
||||
if (!key.pKey)
|
||||
{
|
||||
bRet = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
wchar_t buffer[1024];
|
||||
|
||||
// ResourceCompiler Specific
|
||||
|
||||
if (parent()->GetValueByRef("RC_ShowWindow", SettingsManagerHelpers::CWCharBuffer(buffer, sizeof(buffer))))
|
||||
{
|
||||
const bool b = wcscmp(buffer, L"true") == 0;
|
||||
SetRegValue(key.pKey, "RC_ShowWindow", b);
|
||||
}
|
||||
|
||||
if (parent()->GetValueByRef("RC_HideCustom", SettingsManagerHelpers::CWCharBuffer(buffer, sizeof(buffer))))
|
||||
{
|
||||
const bool b = wcscmp(buffer, L"true") == 0;
|
||||
SetRegValue(key.pKey, "RC_HideCustom", b);
|
||||
}
|
||||
|
||||
if (parent()->GetValueByRef("RC_Parameters", SettingsManagerHelpers::CWCharBuffer(buffer, sizeof(buffer))))
|
||||
{
|
||||
SetRegValue(key.pKey, "RC_Parameters", buffer);
|
||||
}
|
||||
|
||||
if (parent()->GetValueByRef("RC_EnableSourceControl", SettingsManagerHelpers::CWCharBuffer(buffer, sizeof(buffer))))
|
||||
{
|
||||
const bool b = wcscmp(buffer, L"true") == 0;
|
||||
SetRegValue(key.pKey, "RC_EnableSourceControl", b);
|
||||
}
|
||||
}
|
||||
|
||||
return bRet;
|
||||
}
|
||||
|
||||
void CEngineSettingsBackendWin32::LoadEngineSettingsFromRegistry()
|
||||
{
|
||||
wchar_t buffer[1024];
|
||||
|
||||
bool bResult;
|
||||
|
||||
// Engine Specific (Deprecated value)
|
||||
RegKey key(REG_BASE_SETTING_KEY, false);
|
||||
if (key.pKey)
|
||||
{
|
||||
if (GetRegValue(key.pKey, "RootPath", SettingsManagerHelpers::CWCharBuffer(buffer, sizeof(buffer))))
|
||||
{
|
||||
parent()->SetKey("ENG_RootPath", buffer);
|
||||
}
|
||||
|
||||
// Engine Specific
|
||||
if (GetRegValue(key.pKey, "ENG_RootPath", SettingsManagerHelpers::CWCharBuffer(buffer, sizeof(buffer))))
|
||||
{
|
||||
parent()->SetKey("ENG_RootPath", buffer);
|
||||
}
|
||||
|
||||
// ResourceCompiler Specific
|
||||
if (GetRegValue(key.pKey, "RC_ShowWindow", bResult))
|
||||
{
|
||||
parent()->SetKey("RC_ShowWindow", bResult);
|
||||
}
|
||||
if (GetRegValue(key.pKey, "RC_HideCustom", bResult))
|
||||
{
|
||||
parent()->SetKey("RC_HideCustom", bResult);
|
||||
}
|
||||
if (GetRegValue(key.pKey, "RC_Parameters", SettingsManagerHelpers::CWCharBuffer(buffer, sizeof(buffer))))
|
||||
{
|
||||
parent()->SetKey("RC_Parameters", buffer);
|
||||
}
|
||||
if (GetRegValue(key.pKey, "RC_EnableSourceControl", bResult))
|
||||
{
|
||||
parent()->SetKey("RC_EnableSourceControl", bResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool CEngineSettingsBackendWin32::SetRegValue(void* key, const char* valueName, const wchar_t* value)
|
||||
{
|
||||
CFixedString<wchar_t, 256> name;
|
||||
name.appendAscii(valueName);
|
||||
|
||||
size_t const sizeInBytes = (wcslen(value) + 1) * sizeof(value[0]);
|
||||
return (ERROR_SUCCESS == RegSetValueExW((HKEY)key, name.c_str(), 0, REG_SZ, (BYTE*)value, DWORD(sizeInBytes)));
|
||||
}
|
||||
|
||||
bool CEngineSettingsBackendWin32::SetRegValue(void* key, const char* valueName, bool value)
|
||||
{
|
||||
CFixedString<wchar_t, 256> name;
|
||||
name.appendAscii(valueName);
|
||||
|
||||
DWORD dwVal = value;
|
||||
return (ERROR_SUCCESS == RegSetValueExW((HKEY)key, name.c_str(), 0, REG_DWORD, (BYTE*)&dwVal, sizeof(dwVal)));
|
||||
}
|
||||
|
||||
bool CEngineSettingsBackendWin32::SetRegValue(void* key, const char* valueName, int value)
|
||||
{
|
||||
CFixedString<wchar_t, 256> name;
|
||||
name.appendAscii(valueName);
|
||||
|
||||
DWORD dwVal = value;
|
||||
return (ERROR_SUCCESS == RegSetValueExW((HKEY)key, name.c_str(), 0, REG_DWORD, (BYTE*)&dwVal, sizeof(dwVal)));
|
||||
}
|
||||
|
||||
bool CEngineSettingsBackendWin32::GetRegValue(void* key, const char* valueName, CWCharBuffer wbuffer)
|
||||
{
|
||||
if (wbuffer.getSizeInElements() <= 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
CFixedString<wchar_t, 256> name;
|
||||
name.appendAscii(valueName);
|
||||
|
||||
DWORD type;
|
||||
DWORD sizeInBytes = DWORD(wbuffer.getSizeInBytes());
|
||||
if (ERROR_SUCCESS != RegQueryValueExW((HKEY)key, name.c_str(), NULL, &type, (BYTE*)wbuffer.getPtr(), &sizeInBytes))
|
||||
{
|
||||
wbuffer[0] = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
const size_t sizeInElements = sizeInBytes / sizeof(wbuffer[0]);
|
||||
if (sizeInElements > wbuffer.getSizeInElements()) // paranoid check
|
||||
{
|
||||
wbuffer[0] = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
// According to MSDN documentation for RegQueryValueEx(), strings returned by the function
|
||||
// are not zero-terminated sometimes, so we need to terminate them by ourselves.
|
||||
if (wbuffer[sizeInElements - 1] != 0)
|
||||
{
|
||||
if (sizeInElements >= wbuffer.getSizeInElements())
|
||||
{
|
||||
// No space left to put terminating zero character
|
||||
wbuffer[0] = 0;
|
||||
return false;
|
||||
}
|
||||
wbuffer[sizeInElements] = 0;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CEngineSettingsBackendWin32::GetRegValue(void* key, const char* valueName, bool& value)
|
||||
{
|
||||
CFixedString<wchar_t, 256> name;
|
||||
name.appendAscii(valueName);
|
||||
|
||||
// Open the appropriate registry key
|
||||
DWORD type, dwVal = 0, size = sizeof(dwVal);
|
||||
bool res = (ERROR_SUCCESS == RegQueryValueExW((HKEY)key, name.c_str(), NULL, &type, (BYTE*)&dwVal, &size));
|
||||
if (res)
|
||||
{
|
||||
value = (dwVal != 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
wchar_t buffer[100];
|
||||
res = GetRegValue(key, valueName, CWCharBuffer(buffer, sizeof(buffer)));
|
||||
if (res)
|
||||
{
|
||||
value = (wcscmp(buffer, L"true") == 0);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
bool CEngineSettingsBackendWin32::GetRegValue(void* key, const char* valueName, int& value)
|
||||
{
|
||||
CFixedString<wchar_t, 256> name;
|
||||
name.appendAscii(valueName);
|
||||
|
||||
// Open the appropriate registry key
|
||||
DWORD type, dwVal = 0, size = sizeof(dwVal);
|
||||
|
||||
bool res = (ERROR_SUCCESS == RegQueryValueExW((HKEY)key, name.c_str(), NULL, &type, (BYTE*)&dwVal, &size));
|
||||
if (res)
|
||||
{
|
||||
value = dwVal;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
#endif // AZ_PLATFORM_WINDOWS
|
||||
#endif // CRY_ENABLE_RC_HELPER
|
||||
@@ -1,53 +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_ENGINESETTINGSBACKENDWIN32_H
|
||||
#define CRYINCLUDE_CRYCOMMON_ENGINESETTINGSBACKENDWIN32_H
|
||||
#pragma once
|
||||
|
||||
#include "EngineSettingsBackend.h"
|
||||
|
||||
#ifdef CRY_ENABLE_RC_HELPER
|
||||
|
||||
class CEngineSettingsManager;
|
||||
|
||||
class CEngineSettingsBackendWin32 : public CEngineSettingsBackend
|
||||
{
|
||||
public:
|
||||
CEngineSettingsBackendWin32(CEngineSettingsManager* parent, const wchar_t* moduleName = NULL);
|
||||
|
||||
std::wstring GetModuleFilePath() const override;
|
||||
|
||||
bool GetModuleSpecificStringEntryUtf16(const char* key, SettingsManagerHelpers::CWCharBuffer wbuffer) override;
|
||||
bool GetModuleSpecificIntEntry(const char* key, int& value) override;
|
||||
bool GetModuleSpecificBoolEntry(const char* key, bool& value) override;
|
||||
|
||||
bool SetModuleSpecificStringEntryUtf16(const char* key, const wchar_t* str) override;
|
||||
bool SetModuleSpecificIntEntry(const char* key, const int& value) override;
|
||||
bool SetModuleSpecificBoolEntry(const char* key, const bool& value) override;
|
||||
|
||||
bool GetInstalledBuildRootPathUtf16(const int index, SettingsManagerHelpers::CWCharBuffer name, SettingsManagerHelpers::CWCharBuffer path) override;
|
||||
|
||||
void LoadEngineSettingsFromRegistry() override;
|
||||
bool StoreEngineSettingsToRegistry() override;
|
||||
|
||||
protected:
|
||||
bool SetRegValue(void* key, const char* valueName, const wchar_t* value);
|
||||
bool SetRegValue(void* key, const char* valueName, bool value);
|
||||
bool SetRegValue(void* key, const char* valueName, int value);
|
||||
bool GetRegValue(void* key, const char* valueName, SettingsManagerHelpers::CWCharBuffer wbuffer);
|
||||
bool GetRegValue(void* key, const char* valueName, bool& value);
|
||||
bool GetRegValue(void* key, const char* valueName, int& value);
|
||||
};
|
||||
|
||||
#endif // CRY_ENABLE_RC_HELPER
|
||||
|
||||
#endif // CRYINCLUDE_CRYCOMMON_ENGINESETTINGSBACKENDWIN32_H
|
||||
@@ -1,479 +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 "ProjectDefines.h"
|
||||
#include "EngineSettingsManager.h"
|
||||
|
||||
#if defined(CRY_ENABLE_RC_HELPER)
|
||||
|
||||
#include <assert.h> // assert()
|
||||
#include "EngineSettingsBackend.h"
|
||||
|
||||
#include "AzCore/PlatformDef.h"
|
||||
#include "platform.h"
|
||||
|
||||
#if defined(AZ_PLATFORM_WINDOWS)
|
||||
#include "EngineSettingsBackendWin32.h"
|
||||
#include <AzCore/PlatformIncl.h>
|
||||
#elif AZ_TRAIT_OS_PLATFORM_APPLE
|
||||
#include "EngineSettingsBackendApple.h"
|
||||
#endif
|
||||
|
||||
|
||||
#include <climits>
|
||||
#include <cstdio>
|
||||
|
||||
#define INFOTEXT L"Please specify the directory of your CryENGINE installation (RootPath):"
|
||||
|
||||
|
||||
using namespace SettingsManagerHelpers;
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
CEngineSettingsManager::CEngineSettingsManager(const wchar_t* moduleName, const wchar_t* iniFileName)
|
||||
: m_hWndParent(0)
|
||||
, m_backend(NULL)
|
||||
{
|
||||
m_sModuleName.clear();
|
||||
|
||||
#if defined(AZ_PLATFORM_WINDOWS)
|
||||
m_backend = new CEngineSettingsBackendWin32(this, moduleName);
|
||||
#elif AZ_TRAIT_OS_PLATFORM_APPLE
|
||||
m_backend = new CEngineSettingsBackendApple(this, moduleName);
|
||||
#endif
|
||||
assert(m_backend);
|
||||
|
||||
// std initialization
|
||||
RestoreDefaults();
|
||||
|
||||
// try to load content from INI file
|
||||
if (moduleName != NULL)
|
||||
{
|
||||
m_sModuleName = moduleName;
|
||||
|
||||
if (iniFileName == NULL)
|
||||
{
|
||||
// find INI filename located in module path
|
||||
m_sModuleFileName = m_backend->GetModuleFilePath().c_str();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_sModuleFileName = iniFileName;
|
||||
}
|
||||
|
||||
if (LoadValuesFromConfigFile(m_sModuleFileName.c_str()))
|
||||
{
|
||||
m_bGetDataFromBackend = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
m_bGetDataFromBackend = true;
|
||||
|
||||
// load basic content from registry
|
||||
LoadEngineSettingsFromRegistry();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
CEngineSettingsManager::~CEngineSettingsManager()
|
||||
{
|
||||
delete m_backend, m_backend = NULL;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CEngineSettingsManager::RestoreDefaults()
|
||||
{
|
||||
// Engine
|
||||
SetKey("ENG_RootPath", L"");
|
||||
|
||||
// RC
|
||||
SetKey("RC_ShowWindow", false);
|
||||
SetKey("RC_HideCustom", false);
|
||||
SetKey("RC_Parameters", L"");
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool CEngineSettingsManager::GetModuleSpecificStringEntryUtf16(const char* key, SettingsManagerHelpers::CWCharBuffer wbuffer)
|
||||
{
|
||||
if (wbuffer.getSizeInElements() <= 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!m_bGetDataFromBackend)
|
||||
{
|
||||
if (!HasKey(key))
|
||||
{
|
||||
wbuffer[0] = 0;
|
||||
return false;
|
||||
}
|
||||
if (!GetValueByRef(key, wbuffer))
|
||||
{
|
||||
wbuffer[0] = 0;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(m_backend);
|
||||
return m_backend->GetModuleSpecificStringEntryUtf16(key, wbuffer);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool CEngineSettingsManager::GetModuleSpecificStringEntryUtf8(const char* key, SettingsManagerHelpers::CCharBuffer buffer)
|
||||
{
|
||||
if (buffer.getSizeInElements() <= 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
wchar_t wBuffer[1024];
|
||||
|
||||
if (!GetModuleSpecificStringEntryUtf16(key, SettingsManagerHelpers::CWCharBuffer(wBuffer, sizeof(wBuffer))))
|
||||
{
|
||||
buffer[0] = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
SettingsManagerHelpers::ConvertUtf16ToUtf8(wBuffer, buffer);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool CEngineSettingsManager::GetModuleSpecificIntEntry(const char* key, int& value)
|
||||
{
|
||||
value = 0;
|
||||
|
||||
if (!m_bGetDataFromBackend)
|
||||
{
|
||||
if (!HasKey(key))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!GetValueByRef(key, value))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(m_backend);
|
||||
return m_backend->GetModuleSpecificIntEntry(key, value);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool CEngineSettingsManager::GetModuleSpecificBoolEntry(const char* key, bool& value)
|
||||
{
|
||||
value = false;
|
||||
|
||||
if (!m_bGetDataFromBackend)
|
||||
{
|
||||
if (!HasKey(key))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!GetValueByRef(key, value))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(m_backend);
|
||||
return m_backend->GetModuleSpecificBoolEntry(key, value);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool CEngineSettingsManager::SetModuleSpecificStringEntryUtf16(const char* key, const wchar_t* str)
|
||||
{
|
||||
SetKey(key, str);
|
||||
if (!m_bGetDataFromBackend)
|
||||
{
|
||||
return StoreData();
|
||||
}
|
||||
|
||||
assert(m_backend);
|
||||
return m_backend->SetModuleSpecificStringEntryUtf16(key, str);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool CEngineSettingsManager::SetModuleSpecificIntEntry(const char* key, const int& value)
|
||||
{
|
||||
SetKey(key, value);
|
||||
if (!m_bGetDataFromBackend)
|
||||
{
|
||||
return StoreData();
|
||||
}
|
||||
|
||||
assert(m_backend);
|
||||
return m_backend->SetModuleSpecificIntEntry(key, value);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool CEngineSettingsManager::SetModuleSpecificBoolEntry(const char* key, const bool& value)
|
||||
{
|
||||
SetKey(key, value);
|
||||
if (!m_bGetDataFromBackend)
|
||||
{
|
||||
return StoreData();
|
||||
}
|
||||
|
||||
assert(m_backend);
|
||||
return m_backend->SetModuleSpecificBoolEntry(key, value);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool CEngineSettingsManager::SetModuleSpecificStringEntryUtf8(const char* key, const char* str)
|
||||
{
|
||||
wchar_t wbuffer[512];
|
||||
SettingsManagerHelpers::ConvertUtf8ToUtf16(str, SettingsManagerHelpers::CWCharBuffer(wbuffer, sizeof(wbuffer)));
|
||||
|
||||
return SetModuleSpecificStringEntryUtf16(key, wbuffer);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool CEngineSettingsManager::HasKey(const char* key)
|
||||
{
|
||||
return m_keyValueArray.find(key) != 0;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CEngineSettingsManager::SetKey(const char* key, const wchar_t* value)
|
||||
{
|
||||
m_keyValueArray.set(key, value);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CEngineSettingsManager::SetKey(const char* key, bool value)
|
||||
{
|
||||
m_keyValueArray.set(key, (value ? L"true" : L"false"));
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CEngineSettingsManager::SetKey(const char* key, int value)
|
||||
{
|
||||
m_keyValueArray.set(key, std::to_wstring(value).c_str());
|
||||
}
|
||||
|
||||
bool CEngineSettingsManager::GetInstalledBuildRootPathUtf16(const int index, SettingsManagerHelpers::CWCharBuffer name, SettingsManagerHelpers::CWCharBuffer path)
|
||||
{
|
||||
assert(m_backend);
|
||||
return m_backend->GetInstalledBuildRootPathUtf16(index, name, path);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CEngineSettingsManager::SetParentDialog(size_t window)
|
||||
{
|
||||
m_hWndParent = window;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool CEngineSettingsManager::StoreData()
|
||||
{
|
||||
if (m_bGetDataFromBackend)
|
||||
{
|
||||
bool res = StoreEngineSettingsToRegistry();
|
||||
|
||||
if (!res)
|
||||
{
|
||||
#ifdef AZ_PLATFORM_WINDOWS
|
||||
MessageBoxA(reinterpret_cast<HWND>(m_hWndParent), "Could not store data to registry.", "Error", MB_OK | MB_ICONERROR);
|
||||
#endif
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
// store data to INI file
|
||||
|
||||
FILE* file;
|
||||
#ifdef AZ_PLATFORM_WINDOWS
|
||||
_wfopen_s(&file, m_sModuleFileName.c_str(), L"wb");
|
||||
#else
|
||||
char fname[MAX_PATH];
|
||||
memset(fname, 0, MAX_PATH);
|
||||
wcstombs(fname, m_sModuleFileName.c_str(), MAX_PATH);
|
||||
file = fopen(fname, "wb");
|
||||
#endif
|
||||
if (file == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
char buffer[2048];
|
||||
|
||||
for (size_t i = 0; i < m_keyValueArray.size(); ++i)
|
||||
{
|
||||
const SKeyValue& kv = m_keyValueArray[i];
|
||||
|
||||
fprintf_s(file, kv.key.c_str());
|
||||
fprintf_s(file, " = ");
|
||||
|
||||
if (kv.value.length() > 0)
|
||||
{
|
||||
SettingsManagerHelpers::ConvertUtf16ToUtf8(kv.value.c_str(), SettingsManagerHelpers::CCharBuffer(buffer, sizeof(buffer)));
|
||||
fprintf_s(file, "%s", buffer);
|
||||
}
|
||||
|
||||
fprintf_s(file, "\r\n");
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool CEngineSettingsManager::LoadValuesFromConfigFile(const wchar_t* szFileName)
|
||||
{
|
||||
m_keyValueArray.clear();
|
||||
|
||||
// read file to memory
|
||||
|
||||
FILE* file;
|
||||
#ifdef AZ_PLATFORM_WINDOWS
|
||||
_wfopen_s(&file, szFileName, L"rb");
|
||||
#else
|
||||
char fname[MAX_PATH];
|
||||
memset(fname, 0, MAX_PATH);
|
||||
wcstombs(fname, szFileName, MAX_PATH);
|
||||
file = fopen(fname, "rb");
|
||||
#endif
|
||||
if (file == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
fseek(file, 0, SEEK_END);
|
||||
long size = ftell(file);
|
||||
fseek(file, 0, SEEK_SET);
|
||||
char* data = new char[size + 1];
|
||||
fread_s(data, size, 1, size, file);
|
||||
fclose(file);
|
||||
|
||||
wchar_t wBuffer[1024];
|
||||
|
||||
// parse file for root path
|
||||
|
||||
int start = 0, end = 0;
|
||||
while (end < size)
|
||||
{
|
||||
while (end < size && data[end] != '\n')
|
||||
{
|
||||
end++;
|
||||
}
|
||||
|
||||
memcpy(data, &data[start], end - start);
|
||||
data[end - start] = 0;
|
||||
start = end = end + 1;
|
||||
|
||||
CFixedString<char, 2048> line(data);
|
||||
size_t equalsOfs;
|
||||
for (equalsOfs = 0; equalsOfs < line.length(); ++equalsOfs)
|
||||
{
|
||||
if (line[equalsOfs] == '=')
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (equalsOfs < line.length())
|
||||
{
|
||||
CFixedString<char, 256> key;
|
||||
CFixedString<wchar_t, 1024> value;
|
||||
|
||||
key.appendAscii(line.c_str(), equalsOfs);
|
||||
key.trim();
|
||||
|
||||
SettingsManagerHelpers::ConvertUtf8ToUtf16(line.c_str() + equalsOfs + 1, SettingsManagerHelpers::CWCharBuffer(wBuffer, sizeof(wBuffer)));
|
||||
value.append(wBuffer);
|
||||
value.trim();
|
||||
|
||||
m_keyValueArray.set(key.c_str(), value.c_str());
|
||||
}
|
||||
}
|
||||
delete[] data;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool CEngineSettingsManager::StoreEngineSettingsToRegistry()
|
||||
{
|
||||
assert(m_backend);
|
||||
return m_backend->StoreEngineSettingsToRegistry();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CEngineSettingsManager::LoadEngineSettingsFromRegistry()
|
||||
{
|
||||
assert(m_backend);
|
||||
m_backend->LoadEngineSettingsFromRegistry();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool CEngineSettingsManager::GetValueByRef(const char* key, SettingsManagerHelpers::CWCharBuffer wbuffer) const
|
||||
{
|
||||
if (wbuffer.getSizeInElements() <= 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const SKeyValue* p = m_keyValueArray.find(key);
|
||||
if (!p || (p->value.length() + 1) > wbuffer.getSizeInElements())
|
||||
{
|
||||
wbuffer[0] = 0;
|
||||
return false;
|
||||
}
|
||||
azwcscpy(wbuffer.getPtr(), wbuffer.getSizeInElements(), p->value.c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool CEngineSettingsManager::GetValueByRef(const char* key, bool& value) const
|
||||
{
|
||||
wchar_t buffer[100];
|
||||
if (!GetValueByRef(key, SettingsManagerHelpers::CWCharBuffer(buffer, sizeof(buffer))))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
value = (wcscmp(buffer, L"true") == 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool CEngineSettingsManager::GetValueByRef(const char* key, int& value) const
|
||||
{
|
||||
wchar_t buffer[100];
|
||||
if (!GetValueByRef(key, SettingsManagerHelpers::CWCharBuffer(buffer, sizeof(buffer))))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
value = wcstol(buffer, 0, 10);
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif //(CRY_ENABLE_RC_HELPER)
|
||||
@@ -1,89 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
#ifndef CRYINCLUDE_CRYCOMMON_ENGINESETTINGSMANAGER_H
|
||||
#define CRYINCLUDE_CRYCOMMON_ENGINESETTINGSMANAGER_H
|
||||
#pragma once
|
||||
|
||||
#include "ProjectDefines.h"
|
||||
|
||||
#if defined(CRY_ENABLE_RC_HELPER)
|
||||
|
||||
#include "SettingsManagerHelpers.h"
|
||||
|
||||
class CEngineSettingsBackend;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Manages storage and loading of all information for tools and CryENGINE, by either registry or an INI file.
|
||||
// Information can be read and set by key-to-value functions.
|
||||
// Specific information can be set by a dialog application called by this class.
|
||||
// If the engine root path is not found, a fall-back dialog is opened.
|
||||
class CEngineSettingsManager
|
||||
{
|
||||
public:
|
||||
// prepares CEngineSettingsManager to get requested information either from registry or an INI file,
|
||||
// if existent as a file with name an directory equal to the module, or from registry.
|
||||
CEngineSettingsManager(const wchar_t* moduleName = NULL, const wchar_t* iniFileName = NULL);
|
||||
~CEngineSettingsManager();
|
||||
|
||||
void RestoreDefaults();
|
||||
|
||||
// stores/loads user specific information for modules to/from registry or INI file
|
||||
bool GetModuleSpecificStringEntryUtf16(const char* key, SettingsManagerHelpers::CWCharBuffer wbuffer);
|
||||
bool GetModuleSpecificStringEntryUtf8(const char* key, SettingsManagerHelpers::CCharBuffer buffer);
|
||||
bool GetModuleSpecificIntEntry(const char* key, int& value);
|
||||
bool GetModuleSpecificBoolEntry(const char* key, bool& value);
|
||||
|
||||
bool SetModuleSpecificStringEntryUtf16(const char* key, const wchar_t* str);
|
||||
bool SetModuleSpecificStringEntryUtf8(const char* key, const char* str);
|
||||
bool SetModuleSpecificIntEntry(const char* key, const int& value);
|
||||
bool SetModuleSpecificBoolEntry(const char* key, const bool& value);
|
||||
|
||||
bool GetValueByRef(const char* key, SettingsManagerHelpers::CWCharBuffer wbuffer) const;
|
||||
bool GetValueByRef(const char* key, bool& value) const;
|
||||
bool GetValueByRef(const char* key, int& value) const;
|
||||
|
||||
void SetKey(const char* key, const wchar_t* value);
|
||||
void SetKey(const char* key, bool value);
|
||||
void SetKey(const char* key, int value);
|
||||
|
||||
bool StoreData();
|
||||
|
||||
bool GetInstalledBuildRootPathUtf16(const int index, SettingsManagerHelpers::CWCharBuffer name, SettingsManagerHelpers::CWCharBuffer path);
|
||||
|
||||
void SetParentDialog(size_t window);
|
||||
|
||||
private:
|
||||
bool HasKey(const char* key);
|
||||
|
||||
void LoadEngineSettingsFromRegistry();
|
||||
bool StoreEngineSettingsToRegistry();
|
||||
|
||||
// parses a file and stores all flags in a private key-value-map
|
||||
bool LoadValuesFromConfigFile(const wchar_t* szFileName);
|
||||
|
||||
private:
|
||||
CEngineSettingsBackend *m_backend;
|
||||
|
||||
SettingsManagerHelpers::CFixedString<wchar_t, 256> m_sModuleName; // name to store key-value pairs of modules in (registry) or to identify INI file
|
||||
SettingsManagerHelpers::CFixedString<wchar_t, 256> m_sModuleFileName; // used in case of data being loaded from INI file
|
||||
bool m_bGetDataFromBackend;
|
||||
SettingsManagerHelpers::CKeyValueArray<30> m_keyValueArray;
|
||||
|
||||
void* m_hBtnBrowse;
|
||||
size_t m_hWndParent;
|
||||
};
|
||||
|
||||
#endif // CRY_ENABLE_RC_HELPER
|
||||
|
||||
#endif // CRYINCLUDE_CRYCOMMON_ENGINESETTINGSMANAGER_H
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,98 +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 <platform.h>
|
||||
|
||||
#if defined(AZ_RESTRICTED_PLATFORM)
|
||||
#include AZ_RESTRICTED_FILE(Gem_h)
|
||||
#endif
|
||||
|
||||
#if defined(LINUX) || defined(APPLE) || defined(ANDROID)
|
||||
#define OPENGL 1
|
||||
#endif
|
||||
|
||||
#include <Common/RendererDefs.h>
|
||||
|
||||
#include <Cry_Math.h>
|
||||
#include <Cry_XOptimise.h>
|
||||
#include <Cry_Math.h>
|
||||
#include <Cry_Geo.h>
|
||||
#include <CryArray.h>
|
||||
#include <CryHeaders.h>
|
||||
#include <CrySizer.h>
|
||||
#include <CryArray.h>
|
||||
|
||||
#include <IProcess.h>
|
||||
#include <ITimer.h>
|
||||
#include <ISystem.h>
|
||||
#include <ILog.h>
|
||||
#include <IConsole.h>
|
||||
#include <IRenderer.h>
|
||||
#include <IRenderAuxGeom.h>
|
||||
#include <IEntityRenderState.h>
|
||||
#include <I3DEngine.h>
|
||||
#include <IStreamEngine.h>
|
||||
|
||||
#include <CryArray2d.h>
|
||||
#include <PoolAllocator.h>
|
||||
#include <Cry3DEngineBase.h>
|
||||
#include <cvars.h>
|
||||
#include <Material.h>
|
||||
#include <3dEngine.h>
|
||||
#include <ObjMan.h>
|
||||
#include <StlUtils.h>
|
||||
|
||||
#include <Common/CommonRender.h>
|
||||
#include <Common/Shaders/ShaderComponents.h>
|
||||
#include <Common/Shaders/Shader.h>
|
||||
#include <Common/Shaders/CShader.h>
|
||||
#include <Common/RenderMesh.h>
|
||||
#include <Common/RenderPipeline.h>
|
||||
#include <Common/RenderThread.h>
|
||||
#include <Common/Renderer.h>
|
||||
#include <Common/Textures/Texture.h>
|
||||
#include <Common/Shaders/Parser.h>
|
||||
|
||||
#include <RenderDll/Common/OcclQuery.h>
|
||||
#include <RenderDll/Common/DeferredRenderUtils.h>
|
||||
#include <RenderDll/Common/Textures/TextureManager.h>
|
||||
#include <RenderDll/Common/FrameProfiler.h>
|
||||
#include <RenderDll/XRenderD3D9/DeviceManager/DeviceManagerInline.h>
|
||||
#include <RenderDll/XRenderD3D9/DriverD3D.h>
|
||||
#include <RenderDll/XRenderD3D9/DeviceManager/TempDynBuffer.h>
|
||||
|
||||
#include <AzCore/PlatformDef.h>
|
||||
#include <AzCore/Asset/AssetCommon.h>
|
||||
#include <AzCore/Asset/AssetManager.h>
|
||||
#include <AzCore/Asset/AssetManagerBus.h>
|
||||
#include <AzCore/Asset/AssetTypeInfoBus.h>
|
||||
#include <AzCore/Component/Component.h>
|
||||
#include <AzCore/Component/ComponentBus.h>
|
||||
#include <AzCore/Component/ComponentApplicationBus.h>
|
||||
#include <AzCore/Component/Entity.h>
|
||||
#include <AzCore/Component/TickBus.h>
|
||||
#include <AzCore/Component/TransformBus.h>
|
||||
#include <AzCore/IO/GenericStreams.h>
|
||||
#include <AzCore/IO/FileIO.h>
|
||||
#include <AzCore/Math/Quaternion.h>
|
||||
#include <AzCore/Math/Vector3.h>
|
||||
#include <AzCore/RTTI/BehaviorContext.h>
|
||||
#include <AzCore/Serialization/SerializeContext.h>
|
||||
#include <AzCore/Serialization/EditContext.h>
|
||||
#include <AzCore/XML/rapidxml.h>
|
||||
|
||||
#include <AzFramework/Asset/SimpleAsset.h>
|
||||
#include <AzFramework/Asset/AssetCatalogBus.h>
|
||||
#include <AzFramework/Entity/EntityDebugDisplayBus.h>
|
||||
|
||||
#include <LmbrCentral/Rendering/RenderNodeBus.h>
|
||||
@@ -1,202 +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_GEOMCACHEFILEFORMAT_H
|
||||
#define CRYINCLUDE_CRYCOMMON_GEOMCACHEFILEFORMAT_H
|
||||
#pragma once
|
||||
|
||||
#include "CryExtension/CryGUID.h"
|
||||
|
||||
#if !defined(LINUX)
|
||||
#pragma pack(push)
|
||||
#pragma pack(1)
|
||||
#define PACK_GCC
|
||||
#else
|
||||
#define PACK_GCC __attribute__ ((packed))
|
||||
#endif
|
||||
|
||||
namespace GeomCacheFile
|
||||
{
|
||||
// Important: The enums are serialized, don't change the values
|
||||
// without increasing the file version, conversion code etc!
|
||||
|
||||
typedef Vec3_tpl<uint16> Position;
|
||||
typedef Vec2_tpl<int16> Texcoords;
|
||||
typedef Vec4_tpl<int16> QTangent;
|
||||
typedef uint8 Color;
|
||||
|
||||
// ASCII "CAXCACHE"
|
||||
const uint64 kFileSignature = 0x4548434143584143ull;
|
||||
|
||||
// The smallest 'UVmax' we'll support - this avoids division by zero when encoding/decoding UVs
|
||||
const float kMinUVrange = .01f;
|
||||
|
||||
// Bit Precision of tangents quaternions
|
||||
const uint kTangentQuatPrecision = 10;
|
||||
|
||||
// Current file version GUID. Files with other GUIDs will not be loaded by the engine.
|
||||
const CryGUID kCurrentVersion = MAKE_CRYGUID(0x1641defe440af501, 0x7ec5e9164c8c2d1c);
|
||||
|
||||
// Mesh prediction look back array size
|
||||
const uint kMeshPredictorLookBackMaxDist = 4096;
|
||||
|
||||
// Number of frames between index frames. Needs to be <= g_kMaxBufferedFrames.
|
||||
const uint kMaxIFrameDistance = 30;
|
||||
|
||||
enum EFileHeaderFlags
|
||||
{
|
||||
eFileHeaderFlags_PlaybackFromMemory = BIT(0),
|
||||
eFileHeaderFlags_32BitIndices = BIT(1)
|
||||
};
|
||||
|
||||
enum EBlockCompressionFormat
|
||||
{
|
||||
eBlockCompressionFormat_None = 0,
|
||||
eBlockCompressionFormat_Deflate = 1, // zlib
|
||||
eBlockCompressionFormat_LZ4HC = 2, // LZ4 HC
|
||||
eBlockCompressionFormat_ZSTD = 3, //ZStandard
|
||||
};
|
||||
|
||||
enum EStreams
|
||||
{
|
||||
eStream_Indices = BIT(0),
|
||||
eStream_Positions = BIT(1),
|
||||
eStream_Texcoords = BIT(2),
|
||||
eStream_QTangents = BIT(3),
|
||||
eStream_Colors = BIT(4)
|
||||
};
|
||||
|
||||
enum ETransformType
|
||||
{
|
||||
eTransformType_Constant,
|
||||
eTransformType_Animated
|
||||
};
|
||||
|
||||
enum ENodeType
|
||||
{
|
||||
eNodeType_Transform = 0, // Transforms all sub nodes
|
||||
eNodeType_Mesh = 1,
|
||||
eNodeType_PhysicsGeometry = 2,
|
||||
};
|
||||
|
||||
// Common frame
|
||||
enum EFrameType
|
||||
{
|
||||
eFrameType_IFrame = 0,
|
||||
eFrameType_BFrame = 1
|
||||
};
|
||||
|
||||
// Common frame flags
|
||||
enum EFrameFlags
|
||||
{
|
||||
eFrameFlags_Hidden = BIT(0)
|
||||
};
|
||||
|
||||
// Flags for mesh index frames
|
||||
enum EMeshIFrameFlags
|
||||
{
|
||||
eMeshIFrameFlags_UsePredictor = BIT(1)
|
||||
};
|
||||
|
||||
struct SHeader
|
||||
{
|
||||
SHeader()
|
||||
: m_signature(0)
|
||||
, m_version(kCurrentVersion)
|
||||
, m_blockCompressionFormat(0)
|
||||
, m_flags(0)
|
||||
, m_numFrames(0) {}
|
||||
|
||||
uint64 m_signature;
|
||||
CryGUID m_version;
|
||||
uint16 m_blockCompressionFormat;
|
||||
uint32 m_flags;
|
||||
uint32 m_numFrames;
|
||||
uint64 m_totalUncompressedAnimationSize;
|
||||
float m_aabbMin[3];
|
||||
float m_aabbMax[3];
|
||||
} PACK_GCC;
|
||||
|
||||
struct SFrameInfo
|
||||
{
|
||||
uint32 m_frameType;
|
||||
uint32 m_frameSize;
|
||||
uint64 m_frameOffset;
|
||||
float m_frameTime;
|
||||
} PACK_GCC;
|
||||
|
||||
struct SCompressedBlockHeader
|
||||
{
|
||||
uint32 m_uncompressedSize;
|
||||
uint32 m_compressedSize;
|
||||
} PACK_GCC;
|
||||
|
||||
struct SFrameHeader
|
||||
{
|
||||
uint32 m_nodeDataOffset;
|
||||
float m_frameAABBMin[3];
|
||||
float m_frameAABBMax[3];
|
||||
uint32 m_padding;
|
||||
} PACK_GCC;
|
||||
|
||||
struct STemporalPredictorControl
|
||||
{
|
||||
uint8 m_acceleration;
|
||||
uint8 m_indexFrameLerpFactor;
|
||||
uint8 m_combineFactor;
|
||||
uint8 m_padding;
|
||||
} PACK_GCC;
|
||||
|
||||
struct SMeshFrameHeader
|
||||
{
|
||||
uint32 m_flags;
|
||||
STemporalPredictorControl m_positionStreamPredictorControl;
|
||||
STemporalPredictorControl m_texcoordStreamPredictorControl;
|
||||
STemporalPredictorControl m_qTangentStreamPredictorControl;
|
||||
STemporalPredictorControl m_colorStreamPredictorControl[4];
|
||||
} PACK_GCC;
|
||||
|
||||
struct SMeshInfo
|
||||
{
|
||||
uint8 m_constantStreams;
|
||||
uint8 m_animatedStreams;
|
||||
uint8 m_positionPrecision[3];
|
||||
float m_uvMax;
|
||||
uint8 m_padding;
|
||||
uint16 m_numMaterials;
|
||||
uint32 m_numVertices;
|
||||
uint32 m_flags;
|
||||
float m_aabbMin[3];
|
||||
float m_aabbMax[3];
|
||||
uint32 m_nameLength;
|
||||
uint64 m_hash;
|
||||
} PACK_GCC;
|
||||
|
||||
struct SNodeInfo
|
||||
{
|
||||
uint8 m_type;
|
||||
uint8 m_bVisible;
|
||||
uint16 m_transformType;
|
||||
uint32 m_meshIndex;
|
||||
uint32 m_numChildren;
|
||||
uint32 m_nameLength;
|
||||
} PACK_GCC;
|
||||
}
|
||||
|
||||
#undef PACK_GCC
|
||||
|
||||
#if !defined(LINUX)
|
||||
#pragma pack(pop)
|
||||
#endif
|
||||
|
||||
#endif // CRYINCLUDE_CRYCOMMON_GEOMCACHEFILEFORMAT_H
|
||||
@@ -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
|
||||
@@ -35,4 +35,4 @@ namespace AZ
|
||||
};
|
||||
|
||||
typedef AZ::EBus<HeightmapUpdateNotification> HeightmapUpdateNotificationBus;
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,53 +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_I3DENGINE_INFO_H
|
||||
#define CRYINCLUDE_CRYCOMMON_I3DENGINE_INFO_H
|
||||
#pragma once
|
||||
|
||||
#include "TypeInfo_impl.h"
|
||||
#include "IShader_info.h"
|
||||
#include <I3DEngine.h> // <> required for Interfuscator
|
||||
|
||||
STRUCT_INFO_BEGIN(SVisAreaManChunkHeader)
|
||||
STRUCT_VAR_INFO(nVersion, TYPE_INFO(int8))
|
||||
STRUCT_VAR_INFO(nDummy, TYPE_INFO(int8))
|
||||
STRUCT_VAR_INFO(nFlags, TYPE_INFO(int8))
|
||||
STRUCT_VAR_INFO(nFlags2, TYPE_INFO(int8))
|
||||
STRUCT_VAR_INFO(nChunkSize, TYPE_INFO(int))
|
||||
STRUCT_VAR_INFO(nVisAreasNum, TYPE_INFO(int))
|
||||
STRUCT_VAR_INFO(nPortalsNum, TYPE_INFO(int))
|
||||
STRUCT_VAR_INFO(nOcclAreasNum, TYPE_INFO(int))
|
||||
STRUCT_INFO_END(SVisAreaManChunkHeader)
|
||||
|
||||
STRUCT_INFO_BEGIN(SOcTreeNodeChunk)
|
||||
STRUCT_VAR_INFO(nChunkVersion, TYPE_INFO(int16))
|
||||
STRUCT_VAR_INFO(ucChildsMask, TYPE_INFO(int16))
|
||||
STRUCT_VAR_INFO(nodeBox, TYPE_INFO(AABB))
|
||||
STRUCT_VAR_INFO(nObjectsBlockSize, TYPE_INFO(int32))
|
||||
STRUCT_INFO_END(SOcTreeNodeChunk)
|
||||
|
||||
STRUCT_INFO_BEGIN(SHotUpdateInfo)
|
||||
STRUCT_VAR_INFO(nHeigtmap, TYPE_INFO(uint32))
|
||||
STRUCT_VAR_INFO(nObjTypeMask, TYPE_INFO(uint32))
|
||||
STRUCT_VAR_INFO(areaBox, TYPE_INFO(AABB))
|
||||
STRUCT_INFO_END(SHotUpdateInfo)
|
||||
|
||||
STRUCT_INFO_BEGIN(SCommonFileHeader)
|
||||
STRUCT_VAR_INFO(signature, TYPE_ARRAY(4, TYPE_INFO(char)))
|
||||
STRUCT_VAR_INFO(file_type, TYPE_INFO(uint8))
|
||||
STRUCT_VAR_INFO(flags, TYPE_INFO(uint8))
|
||||
STRUCT_VAR_INFO(version, TYPE_INFO(uint16))
|
||||
STRUCT_INFO_END(SCommonFileHeader)
|
||||
|
||||
#endif // CRYINCLUDE_CRYCOMMON_I3DENGINE_INFO_H
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user