Skip to content

Commit c49f818

Browse files
committed
Fixed invalid null assignment in collections, started prototyping reflection system
1 parent 82f3e0c commit c49f818

File tree

13 files changed

+2065
-105
lines changed

13 files changed

+2065
-105
lines changed

resourceDatabase.rdb

529 Bytes
Binary file not shown.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class ESE_DynamicObject: Managed
2+
{
3+
map <string, Managed> Raw;
4+
}

scripts/Game/Collections/ESE_DynamicQueue.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Code example:
2020
class ESE_DynamicQueue<Class T>: Managed
2121
{
2222
ref array<T> Raw = {};
23-
T nullValue = null;
23+
T nullValue;
2424

2525
// ----------------------------------------------------------------------------------------------------------- //
2626
void Enqueue(T value)

scripts/Game/Collections/ESE_Queue.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class ESE_Queue<Class T>: Managed
3434
{
3535
ref array<T> Raw = {};
3636
int MaxSize;
37-
T nullValue = null;
37+
T nullValue;
3838

3939
// ----------------------------------------------------------------------------------------------------------- //
4040
void Enqueue(T value)

scripts/Game/ESE.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,22 @@ Code example:
1818
TODO
1919
@endcode
2020
*/
21+
//#include "$EnforceScriptExtensions:scripts/Game/Namespaces/Core.h"
22+
2123
class ESE
22-
{
24+
{
2325
static const int VERSION_MAJOR = 0;
2426
static const int VERSION_MINOR = 2;
2527
static const int VERSION_PATCH = 2;
2628

29+
// static class references for using main ESE class as a pseudo namespace (e.g. ESE.Entities.SnapToGround(); instead of ESE_Entities.SnapToGround();)
30+
static ESE_Entities Entities;
31+
static ESE_Aliases Aliases;
32+
static ESE_Math Maths;
33+
static ESE_IO IO;
34+
static ESE_Reflection Reflection;
35+
static ESE_InventoryHelper InventoryHelper;
36+
2737
// Base class for all ESE static methods, if we ever get modding support for core types many of these will get added to their respective classes as well
2838

2939
// ================================ Entities ================================
@@ -195,7 +205,7 @@ class ESE
195205

196206

197207
#endif
198-
208+
199209
// ---------------------------------------------------------------- Initialization ---------------------------------------------------------------- //
200210

201211
// This is a huge mess of #ifdef's and all it does it print version information at runtime to the console and the current defines. Kinda useful but

scripts/Game/ESE_Aliases.c

Lines changed: 102 additions & 101 deletions
Large diffs are not rendered by default.

scripts/Game/Namespaces/Core.h

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
Namespace_Core Core = "$core:scripts/Core/";
2+
3+
4+
5+
typedef string Namespace_Core
6+
class Namespace_Core: string
7+
{
8+
private static string Root = "$core:scripts/Core/";
9+
10+
static Namespace_Generated Generated = Root + "generated/";
11+
static Namespace_Proto Proto = Root + "proto/";
12+
static Namespace_Workbench workbench = Root + "workbench/";
13+
}
14+
15+
typedef string Namespace_Generated
16+
class Namespace_Generated: string
17+
{
18+
private static string Root = "$core:scripts/Core/generated";
19+
20+
static string Audio = Root + "Audio/";
21+
static string Containers = Root + "Containers/";
22+
static string debugging = Root + "Debug/"; // This should be called debug not debugging, but it throws a compiler error if i call it that :/
23+
static string Entities = Root + "Entities/";
24+
static string Events = Root + "Events/";
25+
static string Input = Root + "Input/";
26+
static string math = Root + "Math/";
27+
static string physics = Root + "Physics/";
28+
static string replication = Root + "Replication/";
29+
static string Resources = Root + "Resources/";
30+
static string Road = Root + "Road/";
31+
static string system = Root + "System/";
32+
static string Types = Root + "Types/";
33+
static string UI = Root + "UI/";
34+
static string Visual = Root + "Visual/";
35+
static string world = Root + "World/";
36+
37+
void Namespace_Generated(string str)
38+
{
39+
Print("FUCK");
40+
}
41+
}
42+
43+
typedef string Namespace_Proto
44+
class Namespace_Proto: string
45+
{
46+
47+
}
48+
49+
typedef string Namespace_Workbench
50+
class Namespace_Workbench: string
51+
{
52+
53+
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
//#include "$EnforceScriptExtensions:scripts/Game/Reflection/ESE_Reflection_v1.h"
2+
//#include "$EnforceScriptExtensions:scripts/Game/Reflection/ESE_Reflection_v2.h"
3+
4+
class ESE_Type: Managed
5+
{
6+
typename Type;
7+
typename BaseType;
8+
bool IsByRef;
9+
bool IsArray;
10+
bool IsClass;
11+
bool IsEnum;
12+
13+
ESE_Reflection_EMemberTypes MemberType;
14+
string Name;
15+
16+
bool EqualsObj(Class obj) {return Type && obj;}
17+
bool EqualsType(typename T) {return Type && T;}
18+
array<ESE_Type> FindMembers(ESE_Reflection_EMemberTypes memberType, ESE_Reflection_EBindingFlags bindingFlags)
19+
{
20+
21+
}
22+
23+
void ESE_Type(typename type = typename.Empty)
24+
{
25+
if (!type)
26+
return;
27+
Type = type;
28+
BaseType = Type.super.ClassName().ToType();
29+
if (Type.IsInherited(Class)) {IsByRef = true; IsClass = true;}
30+
if (Type.IsInherited(array)) {IsArray = true;}
31+
if (Type.IsInherited(SCR_Enum)) {IsEnum = true;}
32+
Name = Type.ToString();
33+
}
34+
}
35+
36+
// ---------------------------------------------------------------------------------------------------------------
37+
class ESE_Reflection
38+
{
39+
static const ESE_Reflection_EMemberTypes EMemberTypes;
40+
static const ESE_Reflection_EBindingFlags EBindingFlags;
41+
42+
// -----------------------------------------------------------------------------------------------------------
43+
44+
45+
// -----------------------------------------------------------------------------------------------------------
46+
static ESE_Type TypeOf(int in)
47+
{
48+
ESE_Type T = new ESE_Type();
49+
T.Type = int; T.BaseType = int;
50+
T.IsByRef = false; T.IsArray = false; T.IsClass = false; T.IsEnum = false;
51+
T.Name = in.ToString();
52+
return T;
53+
}
54+
static ESE_Type TypeOf(float in)
55+
{
56+
ESE_Type T = new ESE_Type();
57+
T.Type = float; T.BaseType = float;
58+
T.IsByRef = false; T.IsArray = false; T.IsClass = false; T.IsEnum = false;
59+
T.Name = in.ToString();
60+
return T;
61+
}
62+
static ESE_Type TypeOf(bool in)
63+
{
64+
ESE_Type T = new ESE_Type();
65+
T.Type = bool; T.BaseType = bool;
66+
T.IsByRef = false; T.IsArray = false; T.IsClass = false; T.IsEnum = false;
67+
T.Name = in.ToString();
68+
return T;
69+
}
70+
static ESE_Type TypeOf(string in)
71+
{
72+
ESE_Type T = new ESE_Type();
73+
T.Type = string; T.BaseType = string;
74+
T.IsByRef = false; T.IsArray = false; T.IsClass = false; T.IsEnum = false;
75+
T.Name = in;
76+
return T;
77+
}
78+
static ESE_Type TypeOf(vector in)
79+
{
80+
ESE_Type T = new ESE_Type();
81+
T.Type = vector; T.BaseType = vector;
82+
T.IsByRef = false; T.IsArray = false; T.IsClass = false; T.IsEnum = false;
83+
T.Name = in.ToString();
84+
return T;
85+
}
86+
static ESE_Type TypeOf(Class in)
87+
{
88+
ESE_Type T = new ESE_Type();
89+
T.Type = Class; T.BaseType = Class;
90+
T.IsByRef = true; T.IsArray = false; T.IsClass = true; T.IsEnum = false;
91+
T.Name = in.ToString();
92+
return T;
93+
}
94+
static ESE_Type TypeOf(typename in)
95+
{
96+
ESE_Type T = new ESE_Type();
97+
T.Type = typename; T.BaseType = typename;
98+
T.IsByRef = false; T.IsArray = false; T.IsClass = false; T.IsEnum = false;
99+
T.Name = in.ToString();
100+
return T;
101+
}
102+
// -----------------------------------------------------------------------------------------------------------
103+
104+
// -----------------------------------------------------------------------------------------------------------
105+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
enum ESE_Reflection_EMemberTypes
2+
{
3+
Constructor = 1,
4+
Event = 2,
5+
Field = 4,
6+
Method = 8,
7+
Property = 16,
8+
TypeInfo = 32,
9+
Custom = 64,
10+
NestedType = 128,
11+
All = 256
12+
}
13+
14+
enum ESE_Reflection_EBindingFlags
15+
{
16+
Default = 0,
17+
Ignore = 1,
18+
Declared = 2,
19+
Instance = 4,
20+
Static = 8,
21+
Public = 16,
22+
NonPublic = 32,
23+
CreateInstance = 64,
24+
25+
}
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
// v1 reflection testing
2+
class _OLD_ESE_Type<Class T>: Managed
3+
{
4+
typename GetType() {return T;}
5+
}
6+
7+
class _OLD_ESE_ReflectionProp
8+
{
9+
typename type;
10+
string name;
11+
12+
int iValue;
13+
float fValue;
14+
bool bValue;
15+
string sValue;
16+
vector vValue;
17+
Managed mValue;
18+
Class cValue;
19+
typename tValue;
20+
21+
autoptr Managed returnValue;
22+
23+
void Set_iValue(int val) {iValue = val; returnValue = new _OLD_ESE_Type<int>();}
24+
void Set_fValue(float val) {fValue = val; returnValue = new _OLD_ESE_Type<float>();}
25+
void Set_bValue(bool val) {bValue = val; returnValue = new _OLD_ESE_Type<bool>();}
26+
void Set_sValue(string val) {sValue = val; returnValue = new _OLD_ESE_Type<string>();}
27+
void Set_vValue(vector val) {vValue = val; returnValue = new _OLD_ESE_Type<vector>();}
28+
void Set_mValue(Managed val) {mValue = val; returnValue = new _OLD_ESE_Type<Managed>();}
29+
void Set_cValue(Class val) {cValue = val; returnValue = new _OLD_ESE_Type<Class>();}
30+
void Set_tValue(typename val) {tValue = val; returnValue = new _OLD_ESE_Type<typename>();}
31+
32+
typename GetType() {return type;}
33+
string GetName() {return name;}
34+
Managed GetValue() {return _OLD_ESE_Type.Cast( returnValue );}
35+
36+
void _OLD_ESE_ReflectionProp(typename inType)
37+
{
38+
type = inType;
39+
}
40+
}
41+
42+
modded class ESE_Reflection
43+
{
44+
static array<_OLD_ESE_ReflectionProp> _OLD_GetAllProperties(Managed instance)
45+
{
46+
if (!instance)
47+
return null;
48+
49+
typename type = instance.Type();
50+
array<_OLD_ESE_ReflectionProp> output = new array<_OLD_ESE_ReflectionProp>();
51+
for (int i = 0; i < type.GetVariableCount(); i++)
52+
{
53+
typename varType = type.GetVariableType(i);
54+
_OLD_ESE_ReflectionProp entry = new _OLD_ESE_ReflectionProp(varType);
55+
entry.name = type.GetVariableName(i);
56+
57+
// oh here we go
58+
if (varType.IsInherited(int))
59+
{
60+
int val;
61+
type.GetVariableValue(instance, i, val);
62+
entry.Set_iValue(val);
63+
}
64+
else if (varType.IsInherited(float))
65+
{
66+
float val;
67+
type.GetVariableValue(instance, i, val);
68+
entry.Set_fValue(val);
69+
}
70+
else if (varType.IsInherited(bool))
71+
{
72+
bool val;
73+
type.GetVariableValue(instance, i, val);
74+
entry.Set_bValue(val);
75+
}
76+
else if (varType.IsInherited(string))
77+
{
78+
string val;
79+
type.GetVariableValue(instance, i, val);
80+
entry.Set_sValue(val);
81+
}
82+
else if (varType.IsInherited(vector))
83+
{
84+
vector val;
85+
type.GetVariableValue(instance, i, val);
86+
entry.Set_vValue(val);
87+
}
88+
else if (varType.IsInherited(Managed))
89+
{
90+
Managed val;
91+
type.GetVariableValue(instance, i, val);
92+
entry.Set_mValue(val);
93+
}
94+
else if (varType.IsInherited(Class))
95+
{
96+
Class val;
97+
type.GetVariableValue(instance, i, val);
98+
entry.Set_cValue(val);
99+
}
100+
else if (varType.IsInherited(typename))
101+
{
102+
typename val;
103+
type.GetVariableValue(instance, i, val);
104+
entry.Set_tValue(val);
105+
}
106+
else
107+
{
108+
Print("ESE.Reflection.GetAllProperties(): Unknown variable type!", LogLevel.ERROR);
109+
}
110+
output.Insert(entry);
111+
}
112+
return output;
113+
}
114+
}

0 commit comments

Comments
 (0)