Skip to content

Commit

Permalink
Reimplemented and fixed some stuff
Browse files Browse the repository at this point in the history
* Graphs can now be saved/loaded again
* Components can now be added/removed from C#
* Removed some abundant code
  • Loading branch information
ChunkTreasure1 committed Sep 27, 2023
1 parent 454362b commit fe98fa3
Show file tree
Hide file tree
Showing 9 changed files with 151 additions and 1,565 deletions.
30 changes: 27 additions & 3 deletions Engine/Volt-ScriptCore/Source/Volt/Scene/Components.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ public enum VideoStatus : uint
public abstract class Component
{
public Entity entity { get; internal set; }
public virtual string GUID { get; set; }
}

public class TransformComponent : Component
{
public override string GUID { get => "{E1B8016B-1CAA-4782-927E-C17C29B25893}"; }

public Vector3 position
{
get
Expand Down Expand Up @@ -182,6 +185,8 @@ public bool visible

public class TagComponent : Component
{
public override string GUID { get => "{282FA5FB-6A77-47DB-8340-3D34F1A1FBBD}"; }

public string tag
{
get
Expand All @@ -198,6 +203,8 @@ public string tag

public class RelationshipComponent : Component
{
public override string GUID { get => "{4A5FEDD2-4D0B-4696-A9E6-DCDFFB25B32C}"; }

public Entity[] children
{
get
Expand Down Expand Up @@ -261,6 +268,8 @@ public enum ClimbingMode : uint

public class RigidbodyComponent : Component
{
public override string GUID { get => "{460B7722-00C0-48BE-8B3E-B549BCC9269B}"; }

public BodyType bodyType
{
get
Expand Down Expand Up @@ -466,6 +475,8 @@ public void PutToSleep()

public class BoxColliderComponent : Component
{
public override string GUID { get => "{29707475-D536-4DA4-8D3A-A98948C89A5}"; }

public Vector3 halfSize
{
get
Expand Down Expand Up @@ -510,6 +521,8 @@ public bool isTrigger

public class SphereColliderComponent : Component
{
public override string GUID { get => "{90246BCE-FF83-41A2-A076-AB0A947C0D6A}"; }

public float radius
{
get
Expand Down Expand Up @@ -553,6 +566,8 @@ public bool isTrigger

public class CapsuleColliderComponent : Component
{
public override string GUID { get => "{54A48952-7A77-492B-8A9C-2440D82EE5E2}"; }

public float radius
{
get
Expand Down Expand Up @@ -609,6 +624,8 @@ public bool isTrigger

public class MeshColliderComponent : Component
{
public override string GUID { get => "{E709C708-ED3C-4F68-BC1D-2FE32B897722}"; }

public Mesh colliderMesh
{
get
Expand Down Expand Up @@ -671,6 +688,8 @@ public int subMeshIndex

public class CharacterControllerComponent : Component
{
public override string GUID { get => "{DC5C002A-B72E-42A0-83FC-FFBE1FB2DEF2}"; }

public float slopeLimit
{
get
Expand Down Expand Up @@ -858,11 +877,10 @@ public Vector3 GetPosition()
}
}

public class VisualScriptingComponent : Component
{ }

public class AnimationControllerComponent : Component
{
public override string GUID { get => "{36D3CFA2-538E-4036-BB28-2B672F294478}"; }

private AnimationController myController;

public AnimationController controller
Expand Down Expand Up @@ -942,6 +960,8 @@ public Mesh overrideSkin

public class TextRendererComponent : Component
{
public override string GUID { get => "{8AAA0646-40D2-47E6-B83F-72EA26BD8C01}"; }

public string text
{
get
Expand Down Expand Up @@ -971,6 +991,8 @@ public Vector4 color

public class MeshComponent : Component
{
public override string GUID { get => "{45D008BE-65C9-4D6F-A0C6-377F7B384E47}"; }

public Mesh mesh
{
get
Expand Down Expand Up @@ -1026,6 +1048,8 @@ public enum ObstacleAvoidanceQuality : uint

public class NavAgentComponent : Component
{
public override string GUID { get => "{2B4469CE-9B15-4FA9-ABA6-77BA83465357}"; }

public bool active
{
get
Expand Down
50 changes: 18 additions & 32 deletions Engine/Volt-ScriptCore/Source/Volt/Scene/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ public class Entity
public readonly uint Id = 0;
ulong[] ScriptIds;

private Dictionary<string, Component> myComponentCache = new Dictionary<string, Component>();
private GraphKeyScript myGraphKeyScript;
private Dictionary<string, Component> m_componentCache = new Dictionary<string, Component>();

public Entity() { }
public Entity(uint id) { Id = id; }
Expand Down Expand Up @@ -107,21 +106,6 @@ public Entity FindChild(string name)
return entity as Entity;
}

public GraphKeyScript GetGraphKeyScript()
{
if (HasComponent<VisualScriptingComponent>())
{
if (myGraphKeyScript == null)
{
myGraphKeyScript = new GraphKeyScript(this);
}

return myGraphKeyScript;
}

return null;
}

public string name
{
get
Expand Down Expand Up @@ -352,41 +336,43 @@ public bool visible

public bool HasComponent<T>() where T : Component, new()
{
Type componentType = typeof(T);
T tempVar = new T();

return InternalCalls.Entity_HasComponent(Id, componentType.Name);
return InternalCalls.Entity_HasComponent(Id, tempVar.GUID);
}

public void RemoveComponent<T>() where T : Component, new()
{
Type componentType = typeof(T);
T tempVar = new T();

if (!HasComponent<T>())
{
Type componentType = typeof(T);
Log.Error($"Component with name {componentType.Name} does not exist on entity {Id}");
return;
}

InternalCalls.Entity_RemoveComponent(Id, componentType.Name);
InternalCalls.Entity_RemoveComponent(Id, tempVar.GUID);
}

public T AddComponent<T>() where T : Component, new()
{
Type componentType = typeof(T);
if (HasComponent<T>())
{
return myComponentCache[componentType.Name] as T;
return m_componentCache[componentType.Name] as T;
}

if (myComponentCache == null)
if (m_componentCache == null)
{
this.myComponentCache = new Dictionary<string, Component>();
this.m_componentCache = new Dictionary<string, Component>();
}

InternalCalls.Entity_AddComponent(Id, componentType.Name);

T newComp = new T() { entity = this };
InternalCalls.Entity_AddComponent(Id, newComp.GUID);


myComponentCache[componentType.Name] = newComp;
m_componentCache[componentType.Name] = newComp;

return newComp;
}
Expand All @@ -398,19 +384,19 @@ public bool visible
return null;
}

if (myComponentCache == null)
if (m_componentCache == null)
{
this.myComponentCache = new Dictionary<string, Component>();
this.m_componentCache = new Dictionary<string, Component>();
}

Type componentType = typeof(T);
if (myComponentCache.ContainsKey(componentType.Name))
if (m_componentCache.ContainsKey(componentType.Name))
{
return myComponentCache[componentType.Name] as T;
return m_componentCache[componentType.Name] as T;
}

T newComp = new T() { entity = this };
myComponentCache.Add(componentType.Name, newComp);
m_componentCache.Add(componentType.Name, newComp);
return newComp;
}

Expand Down
42 changes: 0 additions & 42 deletions Engine/Volt-ScriptCore/Source/Volt/Scene/GraphKeyScript.cs

This file was deleted.

Loading

0 comments on commit fe98fa3

Please sign in to comment.