diff --git a/Nuake/dependencies/Coral b/Nuake/dependencies/Coral index 96c08dde..1d0ab839 160000 --- a/Nuake/dependencies/Coral +++ b/Nuake/dependencies/Coral @@ -1 +1 @@ -Subproject commit 96c08dde2258ba5938a96fe78f169f1938b97f83 +Subproject commit 1d0ab83990b84a884cde34778d21a282b910a198 diff --git a/Nuake/src/Scene/Systems/ScriptingSystem.cpp b/Nuake/src/Scene/Systems/ScriptingSystem.cpp index fdc479f2..2363ac89 100644 --- a/Nuake/src/Scene/Systems/ScriptingSystem.cpp +++ b/Nuake/src/Scene/Systems/ScriptingSystem.cpp @@ -32,7 +32,7 @@ namespace Nuake if (!wren.mWrenScript->HasCompiledSuccesfully()) { - Logger::Log("ScriptingSystem failed"); + Logger::Log("Failed to compile Wren script: " + wren.Script, "scripting system"); return false; } diff --git a/Nuake/src/Scripting/NetModules/SceneNetAPI.cpp b/Nuake/src/Scripting/NetModules/SceneNetAPI.cpp index 5307bfa6..5cbc8904 100644 --- a/Nuake/src/Scripting/NetModules/SceneNetAPI.cpp +++ b/Nuake/src/Scripting/NetModules/SceneNetAPI.cpp @@ -62,39 +62,64 @@ namespace Nuake { SPRITE }; - bool EntityHasComponent(uint32_t handle, uint32_t componentEnumValue) + bool EntityHasComponent(int id, int componentType) { - Entity entity = { (entt::entity)handle, Engine::GetCurrentScene().get()}; + uint32_t componentEnumValue = 3; + //Entity entity = Engine::GetCurrentScene()->GetEntityByID(id); + Entity entity = { (entt::entity)(id), Engine::GetCurrentScene().get()}; - if (entity.IsValid()) + if (!entity.IsValid()) { return false; } switch (static_cast(componentEnumValue)) { - case PARENT: return entity.HasComponent(); - case NAME: return entity.HasComponent(); - case PREFAB: return entity.HasComponent(); - case TRANSFORM: return entity.HasComponent(); - case LIGHT: return entity.HasComponent(); - case CAMERA: return entity.HasComponent(); - case AUDIO_EMITTER: return entity.HasComponent(); - case MODEL: return entity.HasComponent(); - case SKINNED_MODEL: return entity.HasComponent(); - case BONE: return entity.HasComponent(); - case BOX_COLLIDER: return entity.HasComponent(); - case SPHERE_COLLIDER: return entity.HasComponent(); - case CAPSULE_COLLIDER: return entity.HasComponent(); - case CYLINDER_COLLIDER: return entity.HasComponent(); - case MESH_COLLIDER: return entity.HasComponent(); - case CHARACTER_CONTROLLER: return entity.HasComponent(); - case PARTICLE_EMITTER: return entity.HasComponent(); - case QUAKE_MAP: return entity.HasComponent(); - case BSP_BRUSH: return entity.HasComponent(); - case SPRITE: return entity.HasComponent(); - default: - return false; + case PARENT: return entity.HasComponent(); + case NAME: return entity.HasComponent(); + case PREFAB: return entity.HasComponent(); + case TRANSFORM: return entity.HasComponent(); + case LIGHT: return entity.HasComponent(); + case CAMERA: return entity.HasComponent(); + case AUDIO_EMITTER: return entity.HasComponent(); + case MODEL: return entity.HasComponent(); + case SKINNED_MODEL: return entity.HasComponent(); + case BONE: return entity.HasComponent(); + case BOX_COLLIDER: return entity.HasComponent(); + case SPHERE_COLLIDER: return entity.HasComponent(); + case CAPSULE_COLLIDER: return entity.HasComponent(); + case CYLINDER_COLLIDER: return entity.HasComponent(); + case MESH_COLLIDER: return entity.HasComponent(); + case CHARACTER_CONTROLLER: return entity.HasComponent(); + case PARTICLE_EMITTER: return entity.HasComponent(); + case QUAKE_MAP: return entity.HasComponent(); + case BSP_BRUSH: return entity.HasComponent(); + case SPRITE: return entity.HasComponent(); + default: + return false; + } + } + + void TransformSetPosition(int entityId, float x, float y, float z) + { + Entity entity = { (entt::entity)(entityId), Engine::GetCurrentScene().get() }; + + if (entity.IsValid() && entity.HasComponent()) + { + auto& component = entity.GetComponent(); + component.SetLocalPosition({ x, y, z }); + } + } + + void TransformRotate(int entityId, float x, float y, float z) + { + Entity entity = { (entt::entity)(entityId), Engine::GetCurrentScene().get() }; + + if (entity.IsValid() && entity.HasComponent()) + { + Quat quat = QuatFromEuler(x, y, z); + auto& component = entity.GetComponent(); + component.SetLocalRotation(quat); } } @@ -102,6 +127,10 @@ namespace Nuake { { RegisterMethod("Entity.EntityHasComponentIcall", &EntityHasComponent); RegisterMethod("Scene.GetEntityIcall", &GetEntity); + + // Components + RegisterMethod("TransformComponent.SetPositionIcall", &TransformSetPosition); + RegisterMethod("TransformComponent.RotateIcall", &TransformRotate); } } diff --git a/Nuake/src/Scripting/ScriptingEngineNet.cpp b/Nuake/src/Scripting/ScriptingEngineNet.cpp index 0a8cbf6f..c55dcb95 100644 --- a/Nuake/src/Scripting/ScriptingEngineNet.cpp +++ b/Nuake/src/Scripting/ScriptingEngineNet.cpp @@ -43,7 +43,7 @@ namespace Nuake m_Modules = { CreateRef(), - CreateRef(), + CreateRef(), CreateRef() }; @@ -79,7 +79,7 @@ namespace Nuake for (const auto& [methodName, methodPtr] : netModule->GetMethods()) { auto namespaceClassSplit = String::Split(methodName, '.'); - m_NuakeAssembly.AddInternalCall(m_Scope + '.' + namespaceClassSplit[0], namespaceClassSplit[1], methodPtr); + m_NuakeAssembly.AddInternalCall(m_Scope + '.' + namespaceClassSplit[0], namespaceClassSplit[1], methodPtr); } } @@ -93,11 +93,11 @@ namespace Nuake managedObject.Destroy(); } - m_GameEntityTypes.clear(); Coral::GC::Collect(); m_HostInstance->UnloadAssemblyLoadContext(m_LoadContext); + m_GameEntityTypes.clear(); m_EntityToManagedObjects.clear(); } @@ -123,8 +123,7 @@ namespace Nuake const std::string baseTypeName = std::string(type->GetBaseType().GetName()); if (baseTypeName == "Entity") { - // We have found an entity script. - m_GameEntityTypes[std::string(type->GetName())] = type; + m_GameEntityTypes[std::string(type->GetName())] = type; // We have found an entity script. } } } @@ -197,6 +196,12 @@ namespace Nuake } auto classInstance = m_GameEntityTypes[className]->CreateInstance(); + + int handle = entity.GetHandle(); + int id = entity.GetID(); + classInstance.SetPropertyValue("ECSHandle", handle); + classInstance.SetPropertyValue("ID", id); + m_EntityToManagedObjects.emplace(entity.GetID(), classInstance); } diff --git a/NuakeNet/src/Components.cs b/NuakeNet/src/Components.cs new file mode 100644 index 00000000..6578f433 --- /dev/null +++ b/NuakeNet/src/Components.cs @@ -0,0 +1,261 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Numerics; +using System.Text; +using System.Threading.Tasks; + +namespace Nuake.Net +{ + public class IComponent + { + public int EntityID { get; protected set; } + } + public class ParentComponent : IComponent + { + public ParentComponent(UInt32 entityId) { } + + public Entity Parent { get; set; } + public List Children { get; set; } + } + public class NameComponent : IComponent + { + public NameComponent(int entityId) + { + EntityID = entityId; + } + + public string Name { get; set; } + } + + public class PrefabComponent : IComponent + { + public PrefabComponent(UInt32 entityId) { } + + public string Prefab { get; set; } + } + + public class TransformComponent : IComponent + { + internal static unsafe delegate* SetPositionIcall; + internal static unsafe delegate* RotateIcall; + + public TransformComponent(int entityId) + { + EntityID = entityId; + } + + /// + /// Rotates the transform using euler angles + /// + /// + /// + /// + public void Rotate(float x, float y, float z) + { + unsafe { RotateIcall(EntityID, x, y, z); } + } + + public Vector3 Rotation { get; set; } + public Vector3 GlobalRotation + { + get { return new Vector3(); } + set + { + + } + } + + public Vector3 LocalPosition + { + get { return new Vector3(); } + set + { + unsafe { SetPositionIcall(EntityID, value.X, value.Y, value.Z); } + } + } + public Vector3 GlobalPosition { get; set; } + } + + public class LightComponent : IComponent + { + public enum LightType + { + Directional, + Point, + Spot + } + + public LightComponent(int entityId) + { + EntityID = entityId; + } + + public LightType Type { get; set; } + public float Intensity { get; set; } + public Color Color { get; set; } + public bool CastShadows { get; set; } + public bool Volumetric { get; set; } + public bool SyncWithSky { get; set; } + } + + public class CameraComponent : IComponent + { + public CameraComponent(int entityId) + { + EntityID = entityId; + } + + public float FOV { get; set; } + } + + public class AudioEmitterComponent : IComponent + { + public AudioEmitterComponent(int entityId) + { + EntityID = entityId; + } + + public string AudioClip { get; set; } + + public bool Loop { get; set; } + public bool Spatialized { get; set; } + public bool Playing { get; set; } + } + + public class ModelComponent : IComponent + { + public ModelComponent(int entityId) + { + EntityID = entityId; + } + + public string Mesh { get; set; } + } + + public class SkinnedModelComponent : IComponent + { + public SkinnedModelComponent(int entityId) { } + + public bool Playing { get; set; } + public int CurrentAnimation { get; set; } + } + + public class BoneComponent : IComponent + { + public BoneComponent(int entityId) + { + EntityID = entityId; + } + public string Name { get; set; } + + } + public class RigidbodyComponent : IComponent + { + public RigidbodyComponent(int entityId) { } + + public float Mass { get; set; } + } + + public class BoxCollider : IComponent + { + public BoxCollider(int entityId) + { + EntityID = entityId; + } + + public Vector3 Scale { get; set; } + } + + public class SphereCollider : IComponent + { + public SphereCollider(int entityId) + { + EntityID = entityId; + } + + public float Radius { get; set; } + } + + + public class CapsuleColliderComponent : IComponent + { + public CapsuleColliderComponent(int entityId) + { + EntityID = entityId; + } + + public float Radius { get; set; } + public float Height { get; set; } + } + public class CylinderColliderComponent : IComponent + { + public CylinderColliderComponent(int entityId) + { + EntityID = entityId; + } + + public float Radius { get; set; } + public float Height { get; set; } + } + public class MeshColliderComponent : IComponent + { + public MeshColliderComponent(int entityId) + { + EntityID = entityId; + } + + public int Mesh { get; set; } + } + + public class CharacterControllerComponent : IComponent + { + public CharacterControllerComponent(int entityId) + { + EntityID = entityId; + } + + public void MoveAndSlide(Vector3 velocity) + { + + } + + public bool IsOnGround() + { + return false; + } + } + + public class ParticleEmitterComponent : IComponent + { + public ParticleEmitterComponent(int entityId) { } + + public float Amount { get; set; } + public float Life { get; set; } + public Vector3 Gravity { get; set; } + } + public class QuakeMapComponent : IComponent + { + public QuakeMapComponent(int entityId) { } + + public string Map { get; set; } + + public bool BuildCollisions { get; set; } + + public void Build() { } + } + public class BSPBrushComponent : IComponent + { + public BSPBrushComponent(int entityId) + { + EntityID = entityId; + } + } + public class SpriteComponent : IComponent + { + public SpriteComponent(int entityId) { } + + public string Sprite { get; set; } + } +} diff --git a/NuakeNet/src/Entity.cs b/NuakeNet/src/Entity.cs new file mode 100644 index 00000000..e5b2747f --- /dev/null +++ b/NuakeNet/src/Entity.cs @@ -0,0 +1,90 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Nuake.Net +{ + public class Entity + { + internal static unsafe delegate* EntityHasComponentIcall; + + public enum ComponentTypes + { + Unknown = -1, + PARENT = 0, + NAME, + PREFAB, + TRANSFORM, + LIGHT, + CAMERA, + AUDIO_EMITTER, + MODEL, + SKINNED_MODEL, + BONE, + RIGIDBODY, + BOX_COLLIDER, + SPHERE_COLLIDER, + CAPSULE_COLLIDER, + CYLINDER_COLLIDER, + MESH_COLLIDER, + CHARACTER_CONTROLLER, + PARTICLE_EMITTER, + QUAKE_MAP, + BSP_BRUSH, + SPRITE + } + + public int ID { get; set; } + public int ECSHandle { get; set; } + public virtual void OnInit() { } + public virtual void OnUpdate(float dt) { } + public virtual void OnFixedUpdate(float dt) { } + public virtual void OnDestroy() { } + + protected static Dictionary MappingTypeEnum = new Dictionary() + { + { typeof(ParentComponent), ComponentTypes.PARENT }, + { typeof(NameComponent), ComponentTypes.NAME }, + { typeof(PrefabComponent), ComponentTypes.PREFAB }, + { typeof(TransformComponent), ComponentTypes.TRANSFORM}, + { typeof(LightComponent), ComponentTypes.LIGHT }, + { typeof(CameraComponent), ComponentTypes.CAMERA }, + { typeof(AudioEmitterComponent), ComponentTypes.AUDIO_EMITTER }, + { typeof(ModelComponent), ComponentTypes.MODEL }, + { typeof(SkinnedModelComponent), ComponentTypes.SKINNED_MODEL }, + { typeof(BoneComponent), ComponentTypes.BONE }, + { typeof(BoxCollider), ComponentTypes.BOX_COLLIDER }, + { typeof(SphereCollider), ComponentTypes.SPHERE_COLLIDER }, + { typeof(CapsuleColliderComponent), ComponentTypes.CAPSULE_COLLIDER }, + { typeof(CylinderColliderComponent), ComponentTypes.CYLINDER_COLLIDER }, + { typeof(MeshColliderComponent), ComponentTypes.MESH_COLLIDER }, + { typeof(CharacterControllerComponent), ComponentTypes.CHARACTER_CONTROLLER }, + { typeof(ParticleEmitterComponent), ComponentTypes.PARTICLE_EMITTER }, + { typeof(QuakeMapComponent), ComponentTypes.QUAKE_MAP }, + { typeof(BSPBrushComponent), ComponentTypes.BSP_BRUSH }, + { typeof(SpriteComponent), ComponentTypes.SPRITE } + }; + + public bool HasComponent() + { + if (MappingTypeEnum.ContainsKey(typeof(T))) + { + unsafe { return EntityHasComponentIcall(ECSHandle, (int)MappingTypeEnum[typeof(T)]); }; + } + + return false; + } + + public T? GetComponent() where T : IComponent + { + if (HasComponent()) + { + return (T?)Activator.CreateInstance(typeof(T), ECSHandle); + } + + return null; + } + } +} diff --git a/NuakeNet/src/Input.cs b/NuakeNet/src/Input.cs new file mode 100644 index 00000000..4b672af1 --- /dev/null +++ b/NuakeNet/src/Input.cs @@ -0,0 +1,153 @@ +using Coral.Managed.Interop; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Numerics; +using System.Text; +using System.Threading.Tasks; + +namespace Nuake.Net +{ + public enum Key + { + SPACE = 32, + APOSTROPHE = 39, + COMMA = 44, + MINUS = 45, + PERIOD = 46, + SLASH = 47, + NUM0 = 48, + NUM1 = 49, + NUM2 = 50, + NUM3 = 51, + NUM4 = 52, + NUM5 = 53, + NUM6 = 54, + NUM7 = 55, + NUM8 = 56, + NUM9 = 57, + SEMICOLON = 59, + EQUAL = 61, + A = 65, + B = 66, + C = 67, + D = 68, + E = 69, + F = 70, + G = 71, + H = 72, + I = 73, + J = 74, + K = 75, + L = 76, + M = 77, + N = 78, + O = 79, + P = 80, + Q = 81, + R = 82, + S = 83, + T = 84, + U = 85, + V = 86, + W = 87, + X = 88, + Y = 89, + Z = 90, + LEFT_BRACKET = 91, + BACKSLASH = 92, + RIGHT_BRACKET = 93, + GRAVE_ACCENT = 96, + WORLD_1 = 161, + WORLD_2 = 162, + ESCAPE = 256, + ENTER = 257, + TAB = 258, + BACKSPACE = 259, + INSERT = 260, + DELETE = 261, + RIGHT = 262, + LEFT = 263, + DOWN = 264, + UP = 265, + PAGE_UP = 266, + PAGE_DOWN = 267, + HOME = 268, + END = 269, + CAPS_LOCK = 280, + SCROLL_LOCK = 281, + NUM_LOCK = 282, + PRINT_SCREEN = 283, + PAUSE = 284, + F1 = 290, + F2 = 291, + F3 = 292, + F4 = 293, + F5 = 294, + F6 = 295, + F7 = 296, + F8 = 297, + F9 = 298, + F10 = 299, + F11 = 300, + F12 = 301, + F13 = 302, + F14 = 303, + F15 = 304, + F16 = 305, + F17 = 306, + F18 = 307, + F19 = 308, + F20 = 309, + F21 = 310, + F22 = 311, + F23 = 312, + F24 = 313, + F25 = 314, + KP_0 = 320, + KP_1 = 321, + KP_2 = 322, + KP_3 = 323, + KP_4 = 324, + KP_5 = 325, + KP_6 = 326, + KP_7 = 327, + KP_8 = 328, + KP_9 = 329, + KP_DECIMAL = 330, + KP_DIVIDE = 331, + KP_MULTIPLY = 332, + KP_SUBTRACT = 333, + KP_ADD = 334, + KP_ENTER = 335, + KP_EQUAL = 336, + LEFT_SHIFT = 340, + LEFT_CONTROL = 341, + LEFT_ALT = 342, + LEFT_SUPER = 343, + RIGHT_SHIFT = 344, + RIGHT_CONTROL = 345, + RIGHT_ALT = 346, + RIGHT_SUPER = 347, + MENU = 348, + } + + public class Input + { + internal static unsafe delegate* IsKeyDownIcall; + internal static unsafe delegate*> GetMousePositionIcall; + + public static bool IsKeyDown(Key keys) + { + unsafe { return IsKeyDownIcall((int)keys); } + } + + public static Vector2 GetMousePosition() + { + NativeArray result; + unsafe { result = GetMousePositionIcall(); } + + return new Vector2(result[0], result[1]); + } + } +} diff --git a/NuakeNet/src/Math.cs b/NuakeNet/src/Math.cs new file mode 100644 index 00000000..ae268dd4 --- /dev/null +++ b/NuakeNet/src/Math.cs @@ -0,0 +1,10 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Nuake.Net +{ + +} diff --git a/NuakeNet/src/Scene.cs b/NuakeNet/src/Scene.cs new file mode 100644 index 00000000..1010f094 --- /dev/null +++ b/NuakeNet/src/Scene.cs @@ -0,0 +1,27 @@ +using Coral.Managed.Interop; +using System; + +namespace Nuake.Net +{ + public class Scene + { + internal static unsafe delegate* GetEntityIcall; + + public static Entity GetEntity(string entityName) + { + int handle; + unsafe { handle = GetEntityIcall(entityName); } + + if (handle == -1) + { + throw new Exception("Entity not found"); + } + + Entity entity = new Entity + { + ECSHandle = handle + }; + return entity; + } + } +} \ No newline at end of file diff --git a/NuakeNet/src/main.cs b/NuakeNet/src/main.cs index 9de901ba..d1141f26 100644 --- a/NuakeNet/src/main.cs +++ b/NuakeNet/src/main.cs @@ -13,37 +13,6 @@ namespace Nuake.Net /// All internal call should happen in this file. /// - public class Vector3 - { - public float x { get; set; } - public float y { get; set; } - public float z { get; set; } - - public Vector3(float x, float y, float z) - { - this.x = x; - this.y = y; - this.z = z; - } - - // TODO: Add operator - } - public class Quat - { - public float x { get; set; } - public float y { get; set; } - public float z { get; set; } - public float w { get; set; } - - public Quat(float x, float y, float z, float w) - { - this.x = x; - this.y = y; - this.z = z; - this.w = w; - } - } - public class Engine { internal static unsafe delegate* LoggerLogIcall; @@ -60,471 +29,5 @@ namespace Nuake.Net } } - // Input - public enum Key - { - SPACE = 32, - APOSTROPHE = 39, - COMMA = 44, - MINUS = 45, - PERIOD = 46, - SLASH = 47, - NUM0 = 48, - NUM1 = 49, - NUM2 = 50, - NUM3 = 51, - NUM4 = 52, - NUM5 = 53, - NUM6 = 54, - NUM7 = 55, - NUM8 = 56, - NUM9 = 57, - SEMICOLON = 59, - EQUAL = 61, - A = 65, - B = 66, - C = 67, - D = 68, - E = 69, - F = 70, - G = 71, - H = 72, - I = 73, - J = 74, - K = 75, - L = 76, - M = 77, - N = 78, - O = 79, - P = 80, - Q = 81, - R = 82, - S = 83, - T = 84, - U = 85, - V = 86, - W = 87, - X = 88, - Y = 89, - Z = 90, - LEFT_BRACKET = 91, - BACKSLASH = 92, - RIGHT_BRACKET = 93, - GRAVE_ACCENT = 96, - WORLD_1 = 161, - WORLD_2 = 162, - ESCAPE = 256, - ENTER = 257, - TAB = 258, - BACKSPACE = 259, - INSERT = 260, - DELETE = 261, - RIGHT = 262, - LEFT = 263, - DOWN = 264, - UP = 265, - PAGE_UP = 266, - PAGE_DOWN = 267, - HOME = 268, - END = 269, - CAPS_LOCK = 280, - SCROLL_LOCK = 281, - NUM_LOCK = 282, - PRINT_SCREEN = 283, - PAUSE = 284, - F1 = 290, - F2 = 291, - F3 = 292, - F4 = 293, - F5 = 294, - F6 = 295, - F7 = 296, - F8 = 297, - F9 = 298, - F10 = 299, - F11 = 300, - F12 = 301, - F13 = 302, - F14 = 303, - F15 = 304, - F16 = 305, - F17 = 306, - F18 = 307, - F19 = 308, - F20 = 309, - F21 = 310, - F22 = 311, - F23 = 312, - F24 = 313, - F25 = 314, - KP_0 = 320, - KP_1 = 321, - KP_2 = 322, - KP_3 = 323, - KP_4 = 324, - KP_5 = 325, - KP_6 = 326, - KP_7 = 327, - KP_8 = 328, - KP_9 = 329, - KP_DECIMAL = 330, - KP_DIVIDE = 331, - KP_MULTIPLY = 332, - KP_SUBTRACT = 333, - KP_ADD = 334, - KP_ENTER = 335, - KP_EQUAL = 336, - LEFT_SHIFT = 340, - LEFT_CONTROL = 341, - LEFT_ALT = 342, - LEFT_SUPER = 343, - RIGHT_SHIFT = 344, - RIGHT_CONTROL = 345, - RIGHT_ALT = 346, - RIGHT_SUPER = 347, - MENU = 348, - } - - public class Input - { - internal static unsafe delegate* IsKeyDownIcall; - internal static unsafe delegate*> GetMousePositionIcall; - - public static bool IsKeyDown(Key keys) - { - unsafe { return IsKeyDownIcall((int)keys); } - } - - public static Vector2 GetMousePosition() - { - NativeArray result; - unsafe { result = GetMousePositionIcall(); } - - return new Vector2(result[0], result[1]); - } - } - - public class Scene - { - internal static unsafe delegate* GetEntityIcall; - - public static Entity GetEntity(string entityName) - { - - uint handle; - unsafe { handle = GetEntityIcall(entityName); } - - if(handle == UInt32.MaxValue) - { - throw new Exception("Entity not found"); - } - - Entity entity = new Entity(); - entity.ECSHandle = handle; - return entity; - } - } - - public class IComponent - { - public UInt32 EntityID { get; protected set; } - } - public class ParentComponent : IComponent - { - public ParentComponent(UInt32 entityId) { } - - public Entity Parent { get; set; } - public List Children { get; set; } - } - public class NameComponent : IComponent - { - public NameComponent(UInt32 entityId) - { - EntityID = entityId; - } - - public string Name { get; set; } - } - public class PrefabComponent : IComponent - { - public PrefabComponent(UInt32 entityId) { } - - public string Prefab { get; set; } - } - public class TransformComponent : IComponent - { - public TransformComponent(UInt32 entityId) - { - EntityID = entityId; - } - - public Vector3 LocalPosition { get; set; } - public Vector3 GlobalPosition { get; set; } - } - - public class LightComponent : IComponent - { - public enum LightType - { - Directional, - Point, - Spot - } - - public LightComponent(UInt32 entityId) - { - EntityID = entityId; - } - - public LightType Type { get; set; } - public float Intensity { get; set; } - public Color Color { get; set; } - public bool CastShadows { get; set; } - public bool Volumetric { get; set; } - public bool SyncWithSky { get; set; } - - } - - public class CameraComponent : IComponent - { - public CameraComponent(UInt32 entityId) - { - EntityID = entityId; - } - - public float FOV { get; set; } - } - - public class AudioEmitterComponent : IComponent - { - public AudioEmitterComponent(UInt32 entityId) - { - EntityID = entityId; - } - - public string AudioClip { get; set; } - - public bool Loop { get; set; } - public bool Spatialized { get; set; } - public bool Playing { get; set; } - } - - public class ModelComponent : IComponent - { - public ModelComponent(UInt32 entityId) - { - EntityID = entityId; - } - - public string Mesh { get; set; } - } - - public class SkinnedModelComponent : IComponent - { - public SkinnedModelComponent(UInt32 entityId) { } - - public bool Playing { get; set; } - public int CurrentAnimation { get; set; } - } - - public class BoneComponent : IComponent - { - public BoneComponent(UInt32 entityId) - { - EntityID = entityId; - } - public string Name { get; set; } - - } - public class RigidbodyComponent : IComponent - { - public RigidbodyComponent(UInt32 entityId) { } - - public float Mass { get; set; } - } - - public class BoxCollider : IComponent - { - public BoxCollider(UInt32 entityId) - { - EntityID = entityId; - } - - public Vector3 Scale { get; set; } - } - - public class SphereCollider : IComponent - { - public SphereCollider(UInt32 entityId) - { - EntityID = entityId; - } - - public float Radius { get; set; } - } - - - public class CapsuleColliderComponent : IComponent - { - public CapsuleColliderComponent(UInt32 entityId) - { - EntityID = entityId; - } - - public float Radius { get; set; } - public float Height { get; set; } - } - public class CylinderColliderComponent : IComponent - { - public CylinderColliderComponent(UInt32 entityId) - { - EntityID = entityId; - } - - public float Radius { get; set; } - public float Height { get; set; } - } - public class MeshColliderComponent : IComponent - { - public MeshColliderComponent(UInt32 entityId) - { - EntityID = entityId; - } - - public int Mesh { get; set; } - } - - public class CharacterControllerComponent : IComponent - { - public CharacterControllerComponent(UInt32 entityId) - { - EntityID = entityId; - } - - public void MoveAndSlide(Vector3 velocity) - { - - } - - public bool IsOnGround() - { - return false; - } - } - - public class ParticleEmitterComponent : IComponent - { - public ParticleEmitterComponent(UInt32 entityId) { } - - public float Amount { get; set; } - public float Life { get; set; } - public Vector3 Gravity { get; set; } - } - public class QuakeMapComponent : IComponent - { - public QuakeMapComponent(UInt32 entityId) { } - - public string Map { get; set; } - - public bool BuildCollisions { get; set; } - - public void Build() { } - } - public class BSPBrushComponent : IComponent - { - public BSPBrushComponent(UInt32 entityId) - { - EntityID = entityId; - } - } - public class SpriteComponent : IComponent - { - public SpriteComponent(UInt32 entityId) { } - - public string Sprite { get; set; } - } - - - public class Entity - { - internal static unsafe delegate* EntityHasComponentIcall; - - public enum ComponentTypes - { - Unknown = -1, - PARENT = 0, - NAME, - PREFAB, - TRANSFORM, - LIGHT, - CAMERA, - AUDIO_EMITTER, - MODEL, - SKINNED_MODEL, - BONE, - RIGIDBODY, - BOX_COLLIDER, - SPHERE_COLLIDER, - CAPSULE_COLLIDER, - CYLINDER_COLLIDER, - MESH_COLLIDER, - CHARACTER_CONTROLLER, - PARTICLE_EMITTER, - QUAKE_MAP, - BSP_BRUSH, - SPRITE - } - - public UInt32 ID { get; private set; } - public UInt32 ECSHandle { get; set; } - public virtual void OnInit() { } - public virtual void OnUpdate(float dt) { } - public virtual void OnFixedUpdate(float dt) { } - public virtual void OnDestroy() { } - - protected static Dictionary MappingTypeEnum = new Dictionary() - { - { typeof(ParentComponent), ComponentTypes.PARENT }, - { typeof(NameComponent), ComponentTypes.NAME }, - { typeof(PrefabComponent), ComponentTypes.PREFAB }, - { typeof(TransformComponent), ComponentTypes.TRANSFORM}, - { typeof(LightComponent), ComponentTypes.LIGHT }, - { typeof(CameraComponent), ComponentTypes.CAMERA }, - { typeof(AudioEmitterComponent), ComponentTypes.AUDIO_EMITTER }, - { typeof(ModelComponent), ComponentTypes.MODEL }, - { typeof(SkinnedModelComponent), ComponentTypes.SKINNED_MODEL }, - { typeof(BoneComponent), ComponentTypes.BONE }, - { typeof(BoxCollider), ComponentTypes.BOX_COLLIDER }, - { typeof(SphereCollider), ComponentTypes.SPHERE_COLLIDER }, - { typeof(CapsuleColliderComponent), ComponentTypes.CAPSULE_COLLIDER }, - { typeof(CylinderColliderComponent), ComponentTypes.CYLINDER_COLLIDER }, - { typeof(MeshColliderComponent), ComponentTypes.MESH_COLLIDER }, - { typeof(CharacterControllerComponent), ComponentTypes.CHARACTER_CONTROLLER }, - { typeof(ParticleEmitterComponent), ComponentTypes.PARTICLE_EMITTER }, - { typeof(QuakeMapComponent), ComponentTypes.QUAKE_MAP }, - { typeof(BSPBrushComponent), ComponentTypes.BSP_BRUSH }, - { typeof(SpriteComponent), ComponentTypes.SPRITE } - }; - - public bool HasComponent() where T : IComponent - { - if(MappingTypeEnum.ContainsKey(typeof(T))) - { - unsafe { return EntityHasComponentIcall(ID, (UInt32)ComponentTypes.TRANSFORM); }; - } - - return false; - } - - public T? GetComponent() where T : IComponent - { - if(HasComponent()) - { - return (T)Activator.CreateInstance(typeof(T), ID); - } - - return null; - } - } - + } \ No newline at end of file