Replaced CMapData and CEntityDef property gets with field gets for performance

This commit is contained in:
dexy 2019-01-09 18:09:12 +11:00
parent dd3b8bdab4
commit 6c244c6406
5 changed files with 51 additions and 52 deletions

View File

@ -109,7 +109,7 @@ namespace CodeWalker.GameFiles
}
}
physicsDictionaries = MetaTypes.GetHashArray(Meta, CMapData.physicsDictionaries);
physicsDictionaries = MetaTypes.GetHashArray(Meta, _CMapData.physicsDictionaries);
EnsureEntities(Meta); //load all the entity data and create the YmapEntityDefs
@ -254,7 +254,7 @@ namespace CodeWalker.GameFiles
if (CMloInstanceDefs != null)
{ }
var eptrs = MetaTypes.GetPointerArray(Meta, CMapData.entities);
var eptrs = MetaTypes.GetPointerArray(Meta, _CMapData.entities);
//CEntityDefs = MetaTypes.ConvertDataArray<CEntityDef>(Meta, MetaName.CEntityDef, CMapData.entities);
CEntityDefs = MetaTypes.GetTypedDataArray<CEntityDef>(Meta, MetaName.CEntityDef);
if (CEntityDefs != null)
@ -303,7 +303,7 @@ namespace CodeWalker.GameFiles
for (int i = 0; i < alldefs.Count; i++)
{
YmapEntityDef d = alldefs[i];
int pind = d.CEntityDef.parentIndex;
int pind = d._CEntityDef.parentIndex;
bool isroot = false;
if ((pind < 0) || (pind >= alldefs.Count) || (pind >= i)) //index check? might be a problem
{
@ -312,9 +312,9 @@ namespace CodeWalker.GameFiles
else
{
YmapEntityDef p = alldefs[pind];
if ((p.CEntityDef.lodLevel <= d.CEntityDef.lodLevel) ||
((p.CEntityDef.lodLevel == Unk_1264241711.LODTYPES_DEPTH_ORPHANHD) &&
(d.CEntityDef.lodLevel != Unk_1264241711.LODTYPES_DEPTH_ORPHANHD)))
if ((p._CEntityDef.lodLevel <= d._CEntityDef.lodLevel) ||
((p._CEntityDef.lodLevel == Unk_1264241711.LODTYPES_DEPTH_ORPHANHD) &&
(d._CEntityDef.lodLevel != Unk_1264241711.LODTYPES_DEPTH_ORPHANHD)))
{
isroot = true;
p = null;
@ -346,7 +346,7 @@ namespace CodeWalker.GameFiles
foreach (var ent in AllEntities)
{
ent.Extensions = MetaTypes.GetExtensions(Meta, ent.CEntityDef.extensions);
ent.Extensions = MetaTypes.GetExtensions(Meta, ent._CEntityDef.extensions);
}
}
@ -354,9 +354,9 @@ namespace CodeWalker.GameFiles
private void EnsureInstances(Meta Meta)
{
if (CMapData.instancedData.GrassInstanceList.Count1 != 0)
if (_CMapData.instancedData.GrassInstanceList.Count1 != 0)
{
rage__fwGrassInstanceListDef[] batches = MetaTypes.ConvertDataArray<rage__fwGrassInstanceListDef>(Meta, MetaName.rage__fwGrassInstanceListDef, CMapData.instancedData.GrassInstanceList);
rage__fwGrassInstanceListDef[] batches = MetaTypes.ConvertDataArray<rage__fwGrassInstanceListDef>(Meta, MetaName.rage__fwGrassInstanceListDef, _CMapData.instancedData.GrassInstanceList);
YmapGrassInstanceBatch[] gbatches = new YmapGrassInstanceBatch[batches.Length];
for (int i = 0; i < batches.Length; i++)
{
@ -374,7 +374,7 @@ namespace CodeWalker.GameFiles
}
GrassInstanceBatches = gbatches;
}
if (CMapData.instancedData.PropInstanceList.Count1 != 0)
if (_CMapData.instancedData.PropInstanceList.Count1 != 0)
{
}
}
@ -382,27 +382,27 @@ namespace CodeWalker.GameFiles
private void EnsureLodLights(Meta Meta)
{
//TODO!
if (CMapData.LODLightsSOA.direction.Count1 != 0)
if (_CMapData.LODLightsSOA.direction.Count1 != 0)
{
}
}
private void EnsureDistantLODLights(Meta Meta)
{
if (CMapData.DistantLODLightsSOA.position.Count1 != 0)
if (_CMapData.DistantLODLightsSOA.position.Count1 != 0)
{
DistantLODLights = new YmapDistantLODLights();
DistantLODLights.Ymap = this;
DistantLODLights.CDistantLODLight = CMapData.DistantLODLightsSOA;
DistantLODLights.colours = MetaTypes.GetUintArray(Meta, CMapData.DistantLODLightsSOA.RGBI);
DistantLODLights.positions = MetaTypes.ConvertDataArray<MetaVECTOR3>(Meta, MetaName.VECTOR3, CMapData.DistantLODLightsSOA.position);
DistantLODLights.CDistantLODLight = _CMapData.DistantLODLightsSOA;
DistantLODLights.colours = MetaTypes.GetUintArray(Meta, _CMapData.DistantLODLightsSOA.RGBI);
DistantLODLights.positions = MetaTypes.ConvertDataArray<MetaVECTOR3>(Meta, MetaName.VECTOR3, _CMapData.DistantLODLightsSOA.position);
DistantLODLights.CalcBB();
}
}
private void EnsureTimeCycleModifiers(Meta Meta)
{
CTimeCycleModifiers = MetaTypes.ConvertDataArray<CTimeCycleModifier>(Meta, MetaName.CTimeCycleModifier, CMapData.timeCycleModifiers);
CTimeCycleModifiers = MetaTypes.ConvertDataArray<CTimeCycleModifier>(Meta, MetaName.CTimeCycleModifier, _CMapData.timeCycleModifiers);
if (CTimeCycleModifiers != null)
{
TimeCycleModifiers = new YmapTimeCycleModifier[CTimeCycleModifiers.Length];
@ -421,7 +421,7 @@ namespace CodeWalker.GameFiles
private void EnsureCarGens(Meta Meta)
{
CCarGens = MetaTypes.ConvertDataArray<CCarGen>(Meta, MetaName.CCarGen, CMapData.carGenerators);
CCarGens = MetaTypes.ConvertDataArray<CCarGen>(Meta, MetaName.CCarGen, _CMapData.carGenerators);
if (CCarGens != null)
{
//string str = MetaTypes.GetTypesInitString(resentry, Meta); //to generate structinfos and enuminfos
@ -435,7 +435,7 @@ namespace CodeWalker.GameFiles
private void EnsureBoxOccluders(Meta meta)
{
CBoxOccluders = MetaTypes.ConvertDataArray<BoxOccluder>(Meta, MetaName.BoxOccluder, CMapData.boxOccluders);
CBoxOccluders = MetaTypes.ConvertDataArray<BoxOccluder>(Meta, MetaName.BoxOccluder, _CMapData.boxOccluders);
if (CBoxOccluders != null)
{
BoxOccluders = new YmapBoxOccluder[CBoxOccluders.Length];
@ -449,7 +449,7 @@ namespace CodeWalker.GameFiles
private void EnsureOccludeModels(Meta meta)
{
COccludeModels = MetaTypes.ConvertDataArray<OccludeModel>(Meta, MetaName.OccludeModel, CMapData.occludeModels);
COccludeModels = MetaTypes.ConvertDataArray<OccludeModel>(Meta, MetaName.OccludeModel, _CMapData.occludeModels);
if (COccludeModels != null)
{
OccludeModels = new YmapOccludeModel[COccludeModels.Length];
@ -467,7 +467,7 @@ namespace CodeWalker.GameFiles
{
//TODO: containerLods
if (CMapData.containerLods.Count1 > 0)
if (_CMapData.containerLods.Count1 > 0)
{
//string str = MetaTypes.GetTypesInitString(Meta); //to generate structinfos and enuminfos
@ -500,7 +500,7 @@ namespace CodeWalker.GameFiles
}
else
{
centdefs.Add(ent.CEntityDef);
centdefs.Add(ent._CEntityDef);
}
}
@ -779,10 +779,10 @@ namespace CodeWalker.GameFiles
{
foreach (var rcent in cmap.RootEntities)
{
int pind = rcent.CEntityDef.parentIndex;
int pind = rcent._CEntityDef.parentIndex;
if (pind < 0)
{
if (rcent.CEntityDef.lodLevel != Unk_1264241711.LODTYPES_DEPTH_ORPHANHD)
if (rcent._CEntityDef.lodLevel != Unk_1264241711.LODTYPES_DEPTH_ORPHANHD)
{
}
//pind = 0;
@ -985,8 +985,7 @@ namespace CodeWalker.GameFiles
{
foreach (var yent in AllEntities)
{
var cent = yent.CEntityDef;
switch (cent.lodLevel)
switch (yent._CEntityDef.lodLevel)
{
case Unk_1264241711.LODTYPES_DEPTH_ORPHANHD:
case Unk_1264241711.LODTYPES_DEPTH_HD:
@ -1185,7 +1184,7 @@ namespace CodeWalker.GameFiles
for (int i = 0; i < AllEntities.Length; i++)
{
var ent = AllEntities[i];
var arch = gfc.GetArchetype(ent.CEntityDef.archetypeName);
var arch = gfc.GetArchetype(ent._CEntityDef.archetypeName);
ent.SetArchetype(arch);
if (ent.IsMlo) ent.MloInstance.InitYmapEntityArchetypes(gfc);
}
@ -1283,9 +1282,9 @@ namespace CodeWalker.GameFiles
Ymap = ymap;
Index = index;
CEntityDef = def;
Scale = new Vector3(new Vector2(CEntityDef.scaleXY), CEntityDef.scaleZ);
Position = CEntityDef.position;
Orientation = new Quaternion(CEntityDef.rotation);
Scale = new Vector3(new Vector2(_CEntityDef.scaleXY), _CEntityDef.scaleZ);
Position = _CEntityDef.position;
Orientation = new Quaternion(_CEntityDef.rotation);
if (Orientation != Quaternion.Identity)
{
Orientation = Quaternion.Invert(Orientation);
@ -1301,9 +1300,9 @@ namespace CodeWalker.GameFiles
Ymap = ymap;
Index = index;
CEntityDef = mlo.CEntityDef;
Scale = new Vector3(new Vector2(CEntityDef.scaleXY), CEntityDef.scaleZ);
Position = CEntityDef.position;
Orientation = new Quaternion(CEntityDef.rotation);
Scale = new Vector3(new Vector2(_CEntityDef.scaleXY), _CEntityDef.scaleZ);
Position = _CEntityDef.position;
Orientation = new Quaternion(_CEntityDef.rotation);
//if (Orientation != Quaternion.Identity)
//{
// Orientation = Quaternion.Invert(Orientation);
@ -1363,7 +1362,7 @@ namespace CodeWalker.GameFiles
if (BSRadius == 0.0f)
{
BSRadius = CEntityDef.lodDist;//need something so it doesn't get culled...
BSRadius = _CEntityDef.lodDist;//need something so it doesn't get culled...
}
}
else if (IsMlo) // archetype is no longer an mlo
@ -1551,7 +1550,7 @@ namespace CodeWalker.GameFiles
ChildList = new List<YmapEntityDef>();
}
c.Parent = this;
c.ParentName = CEntityDef.archetypeName;
c.ParentName = _CEntityDef.archetypeName;
ChildList.Add(c);
}
@ -1594,7 +1593,7 @@ namespace CodeWalker.GameFiles
public override string ToString()
{
return CEntityDef.ToString() + ((ChildList != null) ? (" (" + ChildList.Count.ToString() + " children) ") : " ") + CEntityDef.lodLevel.ToString();
return _CEntityDef.ToString() + ((ChildList != null) ? (" (" + ChildList.Count.ToString() + " children) ") : " ") + _CEntityDef.lodLevel.ToString();
}
}

View File

@ -433,7 +433,7 @@ namespace CodeWalker.GameFiles
for (int j = 0; j < Entities.Length; j++)
{
var ient = Entities[j];
var iarch = gfc.GetArchetype(ient.CEntityDef.archetypeName);
var iarch = gfc.GetArchetype(ient._CEntityDef.archetypeName);
ient.SetArchetype(iarch);
if (iarch == null)
@ -453,7 +453,7 @@ namespace CodeWalker.GameFiles
for (int i = 0; i < entities.Count; i++)
{
var ient = entities[i];
var iarch = gfc.GetArchetype(ient.CEntityDef.archetypeName);
var iarch = gfc.GetArchetype(ient._CEntityDef.archetypeName);
ient.SetArchetype(iarch);
if (iarch == null)

View File

@ -1063,7 +1063,7 @@ namespace CodeWalker.World
{
if (!IsYmapAvailable(hash, hour, weather)) break;
ymaps[hash] = ymap;
hash = ymap.CMapData.parent;
hash = ymap._CMapData.parent;
if (ymaps.ContainsKey(hash)) break;
ymap = (hash > 0) ? GameFileCache.GetYmap(hash) : null;
}

View File

@ -1544,11 +1544,11 @@ namespace CodeWalker.Rendering
if (ymap.RootEntities != null)
{
YmapFile pymap;
renderworldVisibleYmapDict.TryGetValue(ymap.CMapData.parent, out pymap);
renderworldVisibleYmapDict.TryGetValue(ymap._CMapData.parent, out pymap);
for (int i = 0; i < ymap.RootEntities.Length; i++)
{
var ent = ymap.RootEntities[i];
int pind = ent.CEntityDef.parentIndex;
int pind = ent._CEntityDef.parentIndex;
if (pind >= 0) //connect root entities to parents if they have them..
{
YmapEntityDef p = null;
@ -1558,7 +1558,7 @@ namespace CodeWalker.Rendering
{
p = pymap.AllEntities[pind];
ent.Parent = p;
ent.ParentName = p.CEntityDef.archetypeName;
ent.ParentName = p._CEntityDef.archetypeName;
}
}
else
@ -1684,8 +1684,8 @@ namespace CodeWalker.Rendering
}
var loddist = ent.CEntityDef.lodDist;
var cloddist = ent.CEntityDef.childLodDist;
var loddist = ent._CEntityDef.lodDist;
var cloddist = ent._CEntityDef.childLodDist;
if (loddist <= 0.0f)//usually -1 or -2
{
@ -1694,7 +1694,7 @@ namespace CodeWalker.Rendering
loddist = ent.Archetype.LodDist * renderworldLodDistMult;
}
}
else if (ent.CEntityDef.lodLevel == Unk_1264241711.LODTYPES_DEPTH_ORPHANHD)
else if (ent._CEntityDef.lodLevel == Unk_1264241711.LODTYPES_DEPTH_ORPHANHD)
{
loddist *= renderworldDetailDistMult * 1.5f; //orphan view dist adjustment...
}
@ -1719,19 +1719,19 @@ namespace CodeWalker.Rendering
ent.Distance = dist;
ent.IsVisible = (dist <= loddist);
ent.ChildrenVisible = (dist <= cloddist) && (ent.CEntityDef.numChildren > 0);
ent.ChildrenVisible = (dist <= cloddist) && (ent._CEntityDef.numChildren > 0);
if (renderworldMaxLOD != Unk_1264241711.LODTYPES_DEPTH_ORPHANHD)
{
if ((ent.CEntityDef.lodLevel == Unk_1264241711.LODTYPES_DEPTH_ORPHANHD) ||
(ent.CEntityDef.lodLevel < renderworldMaxLOD))
if ((ent._CEntityDef.lodLevel == Unk_1264241711.LODTYPES_DEPTH_ORPHANHD) ||
(ent._CEntityDef.lodLevel < renderworldMaxLOD))
{
ent.IsVisible = false;
ent.ChildrenVisible = false;
}
if (ent.CEntityDef.lodLevel == renderworldMaxLOD)
if (ent._CEntityDef.lodLevel == renderworldMaxLOD)
{
ent.ChildrenVisible = false;
}
@ -2008,7 +2008,7 @@ namespace CodeWalker.Rendering
float dist = (camrel + entity.BSCenter).Length();
entity.Distance = dist;
float rad = arch.BSRadius;
float loddist = entity.CEntityDef.lodDist;
float loddist = entity._CEntityDef.lodDist;
if (loddist < 1.0f)
{
loddist = 200.0f;
@ -2384,7 +2384,7 @@ namespace CodeWalker.Rendering
position = entity.Position;
scale = entity.Scale;
orientation = entity.Orientation;
tintPaletteIndex = entity.CEntityDef.tintValue;
tintPaletteIndex = entity._CEntityDef.tintValue;
bbmin = entity.BBMin;
bbmax = entity.BBMax;
bscen = entity.BSCenter;

View File

@ -338,7 +338,7 @@ namespace CodeWalker
}
else if (EntityDef != null)
{
name = EntityDef.CEntityDef.archetypeName.ToString();
name = EntityDef._CEntityDef.archetypeName.ToString();
}
else if (Archetype != null)
{
@ -424,7 +424,7 @@ namespace CodeWalker
}
else if (EntityDef != null)
{
name = EntityDef.CEntityDef.archetypeName.ToString();
name = EntityDef._CEntityDef.archetypeName.ToString();
}
else if (Archetype != null)
{