Skip to content

Commit e059fa5

Browse files
committed
AR 1.1 compatibility
1 parent 9df4edf commit e059fa5

9 files changed

+54
-94
lines changed

src/Scripts/Game/Components/EPF_SlotManagerComponentSaveData.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,13 @@ class EPF_SlotManagerComponentSaveData : EPF_ComponentSaveData
7979
EPF_PersistenceComponentClass slotAttributes = EPF_ComponentData<EPF_PersistenceComponentClass>.Get(slotEntity);
8080
if (saveData.m_pTransformation.ReadFrom(slotEntity, slotAttributes.m_pSaveData, false))
8181
{
82-
if (!EPF_Const.IsNan(saveData.m_pTransformation.m_vOrigin) &&
82+
if (!EPF_Const.IsInf(saveData.m_pTransformation.m_vOrigin) &&
8383
vector.Distance(saveData.m_pTransformation.m_vOrigin, prefabInfo.m_vOffset) > 0.001)
8484
{
8585
readResult = EPF_EReadResult.OK;
8686
}
8787

88-
if (!EPF_Const.IsNan(saveData.m_pTransformation.m_vAngles))
88+
if (!EPF_Const.IsInf(saveData.m_pTransformation.m_vAngles))
8989
{
9090
vector localFixedAngles = slotEntity.GetLocalAngles();
9191
if (float.AlmostEqual(localFixedAngles[0], -180))
@@ -169,10 +169,10 @@ class EPF_SlotManagerComponentSaveData : EPF_ComponentSaveData
169169
{
170170
vector transform[4];
171171

172-
if (!EPF_Const.IsNan(persistentTransform.m_vOrigin))
172+
if (!EPF_Const.IsInf(persistentTransform.m_vOrigin))
173173
transform[3] = persistentTransform.m_vOrigin;
174174

175-
if (!EPF_Const.IsNan(persistentTransform.m_vAngles))
175+
if (!EPF_Const.IsInf(persistentTransform.m_vAngles))
176176
{
177177
Math3D.AnglesToMatrix(persistentTransform.m_vAngles, transform);
178178
}
@@ -181,7 +181,7 @@ class EPF_SlotManagerComponentSaveData : EPF_ComponentSaveData
181181
Math3D.MatrixIdentity3(transform);
182182
}
183183

184-
if (EPF_Const.IsNan(persistentTransform.m_fScale))
184+
if (EPF_Const.IsInf(persistentTransform.m_fScale))
185185
Math3D.MatrixScale(transform, persistentTransform.m_fScale);
186186

187187
entitySlot.OverrideTransformLS(transform);

src/Scripts/Game/EPF_BaseSceneNameProxyEntity.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,18 +148,19 @@ class EPF_BaseSceneNameProxyEntity : GenericEntity
148148
return;
149149

150150
worldEditorApi.BeginEntityAction("BaseSceneNameProxyEntity__AutoFix");
151-
_WB_GetEditorAPI().ModifyEntityKey(this, "coords", m_pTarget.GetOrigin().ToString(false));
151+
worldEditorApi.SetVariableValue(worldEditorApi.EntityToSource(this), null, "coords", m_pTarget.GetOrigin().ToString(false));
152152
worldEditorApi.EndEntityAction();
153153
}
154154

155-
worldEditorApi.SetEntitySelection(m_pTarget);
155+
worldEditorApi.SetEntitySelection(worldEditorApi.EntityToSource(m_pTarget));
156156
worldEditorApi.UpdateSelectionGui();
157157
}
158158

159159
//------------------------------------------------------------------------------------------------
160160
override void _WB_AfterWorldUpdate(float timeSlice)
161161
{
162-
IEntity selected = _WB_GetEditorAPI().GetSelectedEntity();
162+
WorldEditorAPI worldEditorApi = _WB_GetEditorAPI();
163+
IEntity selected = worldEditorApi.SourceToEntity(worldEditorApi.GetSelectedEntity());
163164
if (!m_pTarget || (selected != this && selected != m_pTarget))
164165
return;
165166

src/Scripts/Game/EPF_Const.c

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,17 @@
11
class EPF_Const
22
{
3-
const vector VECTOR_INFINITY = "inf inf inf";
4-
5-
const vector VECTOR_NAN = "nan nan nan";
6-
const float FLOAT_NAN = "nan".ToFloat();
7-
8-
//------------------------------------------------------------------------------------------------
9-
static bool IsNan(vector value)
10-
{
11-
return value.ToString(false).StartsWith("nan");
12-
}
3+
static const vector VECTOR_INFINITY = "inf inf inf";
134

145
//------------------------------------------------------------------------------------------------
15-
//! NaN safe almost equal. nan == not nan will be false
16-
static bool IsNanEqual(vector v1, vector v2, float epsilon = 0.0001)
6+
sealed static bool IsInf(vector value)
177
{
18-
// nan <-> !nan
19-
bool isNanV1 = IsNan(v1);
20-
bool isNanV2 = IsNan(v2);
21-
if (isNanV1 && isNanV2)
22-
return true;
23-
24-
if (isNanV1 != isNanV2)
25-
return false;
26-
27-
return vector.Distance(v1, v2) < epsilon;
8+
return value == VECTOR_INFINITY;
289
}
2910

3011
//------------------------------------------------------------------------------------------------
31-
static bool IsNan(float value)
12+
sealed static bool IsInf(float value)
3213
{
33-
return value.ToString() == "nan";
14+
return value == float.INFINITY;
3415
}
3516

36-
//------------------------------------------------------------------------------------------------
37-
//! NaN safe almost equal. nan == not nan will be false
38-
static bool IsNanEqual(float f1, float f2, float epsilon = 0.0001)
39-
{
40-
// nan <-> !nan
41-
bool isNanF1 = IsNan(f1);
42-
bool isNanF2 = IsNan(f2);
43-
if (isNanF1 && isNanF2)
44-
return true;
45-
46-
if (isNanF1 != isNanF2)
47-
return false;
48-
49-
return float.AlmostEqual(f1, f2, epsilon);
50-
}
5117
};

src/Scripts/Game/EPF_EntitySaveData.c

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,9 @@ class EPF_EntitySaveData : EPF_MetaDataDbEntity
7070
if (EPF_BitFlags.CheckFlags(flags, EPF_EPersistenceFlags.ROOT) &&
7171
attributes.m_bSaveRemainingLifetime)
7272
{
73-
auto garbageWorld = ChimeraWorld.CastFrom(entity.GetWorld());
74-
if (garbageWorld)
75-
{
76-
auto garbage = garbageWorld.GetGarbageManager();
77-
if (garbage)
78-
m_fRemainingLifetime = garbage.GetRemainingLifetime(entity);
79-
}
73+
auto garbage = SCR_GarbageSystem.GetByEntityWorld(entity);
74+
if (garbage)
75+
m_fRemainingLifetime = garbage.GetRemainingLifetime(entity);
8076

8177
if (m_fRemainingLifetime == -1)
8278
{
@@ -150,13 +146,9 @@ class EPF_EntitySaveData : EPF_MetaDataDbEntity
150146
// Lifetime
151147
if (attributes.m_bSaveRemainingLifetime)
152148
{
153-
auto garbageWorld = ChimeraWorld.CastFrom(entity.GetWorld());
154-
if (garbageWorld)
155-
{
156-
auto garbage = garbageWorld.GetGarbageManager();
157-
if (garbage && m_fRemainingLifetime > 0)
158-
garbage.Insert(entity, m_fRemainingLifetime);
159-
}
149+
auto garbage = SCR_GarbageSystem.GetByEntityWorld(entity);
150+
if (garbage && m_fRemainingLifetime > 0)
151+
garbage.Insert(entity, m_fRemainingLifetime);
160152
}
161153

162154
// Components
@@ -191,9 +183,9 @@ class EPF_EntitySaveData : EPF_MetaDataDbEntity
191183
return false;
192184

193185
// Same transformation?
194-
if (!EPF_Const.IsNanEqual(m_pTransformation.m_vOrigin, other.m_pTransformation.m_vOrigin) ||
195-
!EPF_Const.IsNanEqual(m_pTransformation.m_vAngles, other.m_pTransformation.m_vAngles) ||
196-
!EPF_Const.IsNanEqual(m_pTransformation.m_fScale, other.m_pTransformation.m_fScale))
186+
if (m_pTransformation.m_vOrigin != other.m_pTransformation.m_vOrigin ||
187+
m_pTransformation.m_vAngles != other.m_pTransformation.m_vAngles ||
188+
m_pTransformation.m_fScale != other.m_pTransformation.m_fScale)
197189
{
198190
return false;
199191
}
@@ -394,15 +386,15 @@ class EPF_PersistentTransformation
394386
//------------------------------------------------------------------------------------------------
395387
void Reset()
396388
{
397-
m_vOrigin = EPF_Const.VECTOR_NAN;
398-
m_vAngles = EPF_Const.VECTOR_NAN;
399-
m_fScale = EPF_Const.FLOAT_NAN;
389+
m_vOrigin = EPF_Const.VECTOR_INFINITY;
390+
m_vAngles = EPF_Const.VECTOR_INFINITY;
391+
m_fScale = float.INFINITY;
400392
}
401393

402394
//------------------------------------------------------------------------------------------------
403395
bool IsDefault()
404396
{
405-
return EPF_Const.IsNan(m_vOrigin) && EPF_Const.IsNan(m_vAngles) && EPF_Const.IsNan(m_fScale);
397+
return EPF_Const.IsInf(m_vOrigin) && EPF_Const.IsInf(m_vAngles) && EPF_Const.IsInf(m_fScale);
406398
}
407399

408400
//------------------------------------------------------------------------------------------------
@@ -460,16 +452,16 @@ class EPF_PersistentTransformation
460452
// For binary stream the info which of the 3 possible props will be written after needs to be known.
461453
// JSON just has the keys or not, so there it is not a problem.
462454
EPF_ETransformSaveFlags flags;
463-
if (!EPF_Const.IsNan(m_vOrigin))
455+
if (!EPF_Const.IsInf(m_vOrigin))
464456
flags |= EPF_ETransformSaveFlags.COORDS;
465457

466-
if (!EPF_Const.IsNan(m_vAngles))
458+
if (!EPF_Const.IsInf(m_vAngles))
467459
flags |= EPF_ETransformSaveFlags.ANGLES;
468460

469-
if (!EPF_Const.IsNan(m_fScale))
461+
if (!EPF_Const.IsInf(m_fScale))
470462
flags |= EPF_ETransformSaveFlags.SCALE;
471463

472-
if (ContainerSerializationSaveContext.Cast(saveContext).GetContainer().IsInherited(BinSaveContainer))
464+
if (ContainerSerializationSaveContext.Cast(saveContext).GetContainer().IsInherited(BinSerializationSaveContainer))
473465
saveContext.WriteValue("transformSaveFlags", flags);
474466

475467
if (flags & EPF_ETransformSaveFlags.COORDS)
@@ -490,7 +482,7 @@ class EPF_PersistentTransformation
490482
if (!loadContext.IsValid()) return false;
491483

492484
EPF_ETransformSaveFlags flags = EPF_ETransformSaveFlags.COORDS | EPF_ETransformSaveFlags.ANGLES | EPF_ETransformSaveFlags.SCALE;
493-
if (ContainerSerializationLoadContext.Cast(loadContext).GetContainer().IsInherited(BinLoadContainer))
485+
if (ContainerSerializationLoadContext.Cast(loadContext).GetContainer().IsInherited(BinSerializationLoadContainer))
494486
loadContext.ReadValue("transformSaveFlags", flags);
495487

496488
if (flags & EPF_ETransformSaveFlags.COORDS)

src/Scripts/Game/EPF_PersistenceComponent.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@
764764
if (!worldEditorApi)
765765
return;
766766

767-
worldEditorApi.RenameEntity(owner, GenerateName(owner));
767+
worldEditorApi.RenameEntity(worldEditorApi.EntityToSource(owner), GenerateName(owner));
768768
}
769769

770770
//------------------------------------------------------------------------------------------------
@@ -798,36 +798,37 @@
798798
if (!worldEditorApi)
799799
return;
800800

801-
EPF_BaseSceneNameProxyEntity nameProxy;
801+
IEntitySource nameProxySource;
802802

803803
if (id == 0)
804804
{
805-
nameProxy = EPF_BaseSceneNameProxyEntity.GetProxyForBaseSceneEntity(owner);
805+
auto nameProxy = EPF_BaseSceneNameProxyEntity.GetProxyForBaseSceneEntity(owner);
806+
nameProxySource = worldEditorApi.EntityToSource(nameProxy);
806807
}
807808
else if (id == 2)
808809
{
809810
worldEditorApi.BeginEntityAction("BaseSceneNameProxyEntity__Assign");
810-
nameProxy = EPF_BaseSceneNameProxyEntity.s_pSelectedProxy;
811+
nameProxySource = worldEditorApi.EntityToSource(EPF_BaseSceneNameProxyEntity.s_pSelectedProxy);
811812
EPF_BaseSceneNameProxyEntity.s_pSelectedProxy = null;
812-
worldEditorApi.ModifyEntityKey(nameProxy, "coords", owner.GetOrigin().ToString(false));
813+
worldEditorApi.SetVariableValue(nameProxySource, null, "coords", owner.GetOrigin().ToString(false));
813814
worldEditorApi.EndEntityAction();
814815
}
815816
else
816817
{
817818
worldEditorApi.BeginEntityAction("BaseSceneNameProxyEntity__Create");
818-
nameProxy = EPF_BaseSceneNameProxyEntity.Cast(worldEditorApi.CreateEntity(
819+
nameProxySource = worldEditorApi.CreateEntity(
819820
"EPF_BaseSceneNameProxyEntity",
820821
GenerateName(owner),
821822
worldEditorApi.GetCurrentEntityLayerId(),
822823
null,
823824
owner.GetOrigin(),
824-
owner.GetAngles()));
825+
owner.GetAngles());
825826

826-
worldEditorApi.ModifyEntityKey(nameProxy, "m_rTarget", EPF_Utils.GetPrefabName(owner));
827+
worldEditorApi.SetVariableValue(nameProxySource, null, "m_rTarget", EPF_Utils.GetPrefabName(owner));
827828
worldEditorApi.EndEntityAction();
828829
}
829830

830-
worldEditorApi.SetEntitySelection(nameProxy);
831+
worldEditorApi.SetEntitySelection(nameProxySource);
831832
worldEditorApi.UpdateSelectionGui();
832833
}
833834

src/Scripts/Game/EPF_PersistenceManager.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,19 +166,19 @@ class EPF_PersistenceManager
166166
spawnParams = new EntitySpawnParams();
167167
spawnParams.TransformMode = ETransformMode.WORLD;
168168

169-
if (!EPF_Const.IsNan(saveData.m_pTransformation.m_vOrigin))
169+
if (!EPF_Const.IsInf(saveData.m_pTransformation.m_vOrigin))
170170
{
171171
spawnParams.Transform[3] = saveData.m_pTransformation.m_vOrigin;
172172
needed = true;
173173
}
174174

175-
if (!EPF_Const.IsNan(saveData.m_pTransformation.m_vAngles))
175+
if (!EPF_Const.IsInf(saveData.m_pTransformation.m_vAngles))
176176
{
177177
Math3D.AnglesToMatrix(saveData.m_pTransformation.m_vAngles, spawnParams.Transform);
178178
needed = true;
179179
}
180180

181-
if (!EPF_Const.IsNan(saveData.m_pTransformation.m_fScale))
181+
if (!EPF_Const.IsInf(saveData.m_pTransformation.m_fScale))
182182
{
183183
spawnParams.Scale = saveData.m_pTransformation.m_fScale;
184184
needed = true;

src/Scripts/Game/EPF_Utils.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,14 @@ class EPF_Utils
169169

170170
//------------------------------------------------------------------------------------------------
171171
[Obsolete("Use EPF_WorldUtils.Teleport instead.")]
172-
static void Teleport(notnull IEntity entity, vector position, float yaw = "nan".ToFloat())
172+
static void Teleport(notnull IEntity entity, vector position, float yaw = float.INFINITY)
173173
{
174174
EPF_WorldUtils.Teleport(entity, position, yaw);
175175
}
176176

177177
//------------------------------------------------------------------------------------------------
178178
[Obsolete("Use EPF_WorldUtils.ForceTransform instead.")]
179-
static void ForceTransform(notnull IEntity entity, vector origin = EPF_Const.VECTOR_NAN, vector angles = EPF_Const.VECTOR_NAN, float scale = "nan".ToFloat())
179+
static void ForceTransform(notnull IEntity entity, vector origin = EPF_Const.VECTOR_INFINITY, vector angles = EPF_Const.VECTOR_INFINITY, float scale = float.INFINITY)
180180
{
181181
EPF_WorldUtils.ForceTransform(entity, origin, angles, scale);
182182
}

src/Scripts/Game/EPF_WorldUtils.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ class EPF_WorldUtils
3232
//! \param entity Entity instance to be teleported
3333
//! \param position Position where to teleport to
3434
//! \param angles (yaw, pitch, rolle in degrees) to apply after teleportation
35-
static void Teleport(notnull IEntity entity, vector position, float yaw = "nan".ToFloat())
35+
static void Teleport(notnull IEntity entity, vector position, float yaw = float.INFINITY)
3636
{
3737
vector transform[4];
3838

39-
if (!EPF_Const.IsNan(yaw))
39+
if (!EPF_Const.IsInf(yaw))
4040
{
4141
Math3D.AnglesToMatrix(Vector(yaw, 0, 0), transform);
4242
}
@@ -57,26 +57,26 @@ class EPF_WorldUtils
5757
//! \param origin
5858
//! \param angles (yaw, pitch, roll in degrees)
5959
//! \param scale
60-
static void ForceTransform(notnull IEntity entity, vector origin = EPF_Const.VECTOR_NAN, vector angles = EPF_Const.VECTOR_NAN, float scale = "nan".ToFloat())
60+
static void ForceTransform(notnull IEntity entity, vector origin = EPF_Const.VECTOR_INFINITY, vector angles = EPF_Const.VECTOR_INFINITY, float scale = float.INFINITY)
6161
{
6262
bool needsChange;
6363
vector transform[4];
6464
entity.GetWorldTransform(transform);
6565

66-
if (!EPF_Const.IsNan(origin))
66+
if (!EPF_Const.IsInf(origin))
6767
{
6868
transform[3] = origin;
6969
needsChange = true;
7070
}
7171

72-
if (!EPF_Const.IsNan(angles))
72+
if (!EPF_Const.IsInf(angles))
7373
{
7474
Math3D.AnglesToMatrix(angles, transform);
7575
needsChange = true;
7676
}
7777

7878
// TODO: Repace with EPF_Const.FLOAT_NAN after https://feedback.bistudio.com/T172797 is fixed. In EPF_Utils.Teleport() too.
79-
if (!EPF_Const.IsNan(scale))
79+
if (!EPF_Const.IsInf(scale))
8080
{
8181
Math3D.MatrixScale(transform, scale);
8282
needsChange = true;

src/Scripts/Game/RespawnSystem/EPF_SpawnPoint.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class EPF_SpawnPoint : SCR_Position
88
[Attribute("0", desc: "Find empty position for spawning within given radius. When none is found, entity position will be used.")]
99
protected float m_fSpawnRadius;
1010

11-
protected static ref array<EPF_SpawnPoint> s_aSpawnPoints = new ref array<EPF_SpawnPoint>();
11+
protected static ref array<EPF_SpawnPoint> s_aSpawnPoints = {};
1212

1313
//------------------------------------------------------------------------------------------------
1414
[Obsolete("Use GetRandomSpawnPoint instead.")]

0 commit comments

Comments
 (0)