Entity Creation and Destruction from scripts

- ScriptEngine: Allow destroying scripts during runtime
- Scripting:
    - Create new entities using Constructors
    - Added Destroy functions for Entities
    - Added SetScript/RemoveScript functions for Entities
    - Allow adding multiple components at once
    - Added Is-Method
- Mono Wrapper: Added Array-Functions
- WorldEnumerator: Fixed crash due to dangling list pointer after entity creation
- Scene:
    - Basic create Rigidbodies during runtime
    - Start of entity copying (For runtime use)
    - Added DestroyEntityDeferred
- SceneSerializer:
    - Added option to assign new IDs to entities
This commit is contained in:
Simon Lübeß
2023-09-15 23:22:27 +02:00
parent ff54eb738e
commit 754c149493
9 changed files with 470 additions and 62 deletions
+7 -7
View File
@@ -10,16 +10,14 @@ namespace GlitchyEngine.World
{
internal EcsWorld _world;
internal BitArray _bitMask;
internal EcsWorld.BitmaskEntry* _currentEntry;
internal EcsWorld.BitmaskEntry* _endEntry;
internal List<EcsWorld.BitmaskEntry>.Enumerator _entitiesEnumerator;
public bool IsEmpty => _bitMask == null;
public this(EcsWorld world, Type[] componentTypes)
{
_world = world;
_currentEntry = _world._entities.Ptr;
_endEntry = _world._entities.Ptr + _world._entities.Count;
_entitiesEnumerator = _world._entities.GetEnumerator();
_bitMask = new BitArray(_world._componentPools.Count);
for(var type in componentTypes)
@@ -39,7 +37,6 @@ namespace GlitchyEngine.World
Log.EngineLogger.Warning($"Queried component of type \"{type}\" is not registered for this world. The query will never return any results.");
#endif
DeleteAndNullify!(_bitMask);
_endEntry = _currentEntry;
break;
}
}
@@ -47,9 +44,12 @@ namespace GlitchyEngine.World
public Result<EcsEntity> GetNext() mut
{
while(_currentEntry < _endEntry)
if (IsEmpty)
return .Err;
while(_entitiesEnumerator.GetNext() case .Ok(let entry))
{
EcsWorld.BitmaskEntry* entry = _currentEntry++;
//EcsWorld.BitmaskEntry* entry = _currentEntry++;
// Skip deleted entities
if(entry.ID.Index == EcsEntity.InvalidEntity.Index)