Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚀 2023.1.1 #197

Merged
merged 73 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
f210e0d
Fixed WorldBrowser inability to update world view list
skelitheprogrammer Sep 16, 2023
024ba0a
Changed from OnInspectorUpdate to OnFocus
skelitheprogrammer Sep 17, 2023
a1d06e0
Merge pull request #195 from skelitheprogrammer/main
olegmrzv Sep 17, 2023
79b6003
Merge branch 'main' into stage-2023.1
olegmrzv Sep 19, 2023
99205e5
🚀 Up version to 2023.1.1
olegmrzv Sep 26, 2023
dd62c7c
🚧 Fix 40B alloc
olegmrzv Sep 26, 2023
fa1e07d
Restored default element in Stash after RemoveAll()
SH42913 Oct 16, 2023
3ec2ea0
Add IBoxedAspect
vanifatovvlad Oct 26, 2023
9ca8294
Merge pull request #207 from scellecs/remove-all-fix
olegmrzv Oct 27, 2023
a2da21f
Merge pull request #208 from codewriter-packages/boxed-aspect
olegmrzv Oct 27, 2023
a39a6a2
Merge remote-tracking branch 'origin/main' into stage-2023.1
olegmrzv Dec 18, 2023
2971841
🚧 Fix stash.IsEmpty, RemoveAll
olegmrzv Dec 18, 2023
34c100a
🚧 Fix World.Dispose logic
olegmrzv Dec 18, 2023
6dd1b10
🚧 Fix Native Support
olegmrzv Dec 18, 2023
8edee71
🚀 Stash clones
olegmrzv Jan 12, 2024
a8b98a1
Merge remote-tracking branch 'origin/main' into stage-2023.1
olegmrzv Jan 12, 2024
12250dd
Update README.md
olegmrzv Jan 12, 2024
5ebaf81
🚧 Fix Native Support
olegmrzv Jan 17, 2024
0b4644c
🚧 Fix Stash Ctor
olegmrzv Jan 24, 2024
8944b57
Reduce Il2cppMemoryAllocator memory usage from generics
Feb 26, 2024
230da06
Merge pull request #217 from scellecs/igor/fix-generics-memory-usage
olegmrzv Feb 26, 2024
bfa4ac2
🚧 Fix Entity Provider
olegmrzv Feb 26, 2024
1f7a32a
🚀 Define for disabling Compilation Report
olegmrzv Feb 26, 2024
bc3e4d0
Merge remote-tracking branch 'origin/main' into stage-2023.1
olegmrzv Feb 26, 2024
a8e89cd
Ability to disable AsDisposable functionality for stashes
Feb 26, 2024
252e0e0
MORPEH_DISABLE_COMPONENT_DISPOSE readme
Feb 26, 2024
74df413
Merge pull request #218 from scellecs/igor/no-disposable-switch
olegmrzv Feb 26, 2024
3278c80
Store stashes in World directly
Feb 26, 2024
6757922
Dispose all worlds in initialization by default
Feb 27, 2024
ad5ef07
Fix for unity
Feb 27, 2024
1da84ea
Rename
Feb 27, 2024
3543be3
One more rename
Feb 27, 2024
3604d6c
Merge pull request #219 from scellecs/igor/store-stashes-in-world
olegmrzv Feb 27, 2024
144a5e2
Update EntityViewer.cs
Feb 27, 2024
b7f21b4
Stash Resize metric
olegmrzv Feb 27, 2024
203aff2
Merge branch 'stage-2023.1' of github.com:scellecs/morpeh into stage-…
olegmrzv Feb 27, 2024
362df9f
Stash Resize metric++
olegmrzv Feb 27, 2024
d2f0ae1
Devirtualize stashes
Mar 6, 2024
4832da8
Cleanup
Mar 6, 2024
2b258a4
Mark as internal
Mar 6, 2024
02651a4
Remove a method that might generate shitton of useless metadata
Mar 6, 2024
bb1238e
Rename for consistency
Mar 6, 2024
adab441
Cleanup
Mar 6, 2024
e214c3d
Update StashMap.cs
Mar 6, 2024
50887ee
Update StashMap.cs
Mar 6, 2024
1ace6a3
Remove ins
Mar 6, 2024
3be8227
Fix missing attributes
Mar 7, 2024
3e603bd
Update Stash.cs
Mar 7, 2024
a6ab4d6
Update StashMap.cs
Mar 7, 2024
553c9c9
Update StashMap.cs
Mar 7, 2024
3d8b99b
Update StashMap.cs
Mar 7, 2024
d3e9687
Update Stash.cs
Mar 7, 2024
dd2adbb
Move enumerator to stashmap to avoid creating extra types for each stash
Mar 7, 2024
406ceb0
Allow iterating over stashes
Mar 7, 2024
4009158
Rename for consistency
Mar 7, 2024
30874ee
Update StashMap.cs
Mar 7, 2024
c06b709
Cleanup
Mar 7, 2024
917101d
Remove unnecessary check
Mar 7, 2024
fe4cd45
Merge pull request #221 from scellecs/igor/devirtualize-stashes
olegmrzv Mar 11, 2024
d021806
Add length property to Stash
Mar 12, 2024
7acdf5c
Fix stash data leak on entity disposal
Mar 25, 2024
608bc04
🐞 Fix MigrateTo Broken Enumerator
olegmrzv May 29, 2024
eb2dd2d
🐞 Fix MigrateTo Broken Enumerator++
olegmrzv May 29, 2024
7f5c871
Fix in HashHelpers
heymeepo Oct 14, 2024
d43d849
Fix in HashHelpers++
heymeepo Oct 14, 2024
b0fc33c
Fix managed memory leak in Remove, RemoveAll and Migrate
heymeepo Oct 14, 2024
1937f50
Update LICENSE.md
heymeepo Oct 14, 2024
595e5c9
Up NuGet to 2023.1.1
heymeepo Oct 14, 2024
70a60df
Update CHANGELOG.md to 2023.1.1
heymeepo Oct 14, 2024
796b785
Update CHANGELOG.md to 2023.1.1
heymeepo Oct 14, 2024
522c319
Update CHANGELOG.md to 2023.1.1
heymeepo Oct 14, 2024
06116d9
Update README.md
heymeepo Oct 14, 2024
41fd6a4
Update CHANGELOG.md to 2023.1.1
heymeepo Oct 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,24 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2023.1.1] - 15.10.2024
### Fixed
- Fixed ``Stash.IsEmpty`` never being true.
- Fixed ``Stash.RemoveAll`` breaking the stash.
- Fixed ``World.Dispose`` throwing on multiple calls.
- Fixed ``WorldBrowser`` inability to update world view list by @skelitheprogrammer.
- Fixed ``MigrateTo`` broken enumerator.
- Fixed ``World.CleanupUpdate`` small allocation.
### Added
- Added ``IBoxedAspectFactory`` to allow aspects to be created via DI by @vanifatovvlad.
- Added ``MORPEH_DISABLE_COMPILATION_REPORT`` and ``MORPEH_DISABLE_COMPONENT_DISPOSE`` defines.
- Added ``Length`` property to ``Stash``.
- Added ``Enumerator`` for ``Stash``.
### Changed
- [Devirtualize stashes](https://github.com/scellecs/morpeh/pull/221).
- Changed method signature for ``GetValueRefByKey`` in ``NativeIntHashMap<TNative>``, added ``ref`` keyword to the first parameter.
- Changed methods signatures for ``Get`` in ``NativeStash<TNative>``, added ``ref`` keyword to the first parameter.

## [2023.1.0] - 09.10.2023
### Fixed
- Fix `NativeFilter` allocations.
Expand Down
19 changes: 17 additions & 2 deletions Core/Aspect.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
namespace Scellecs.Morpeh {
using System;

public interface IAspect {
Entity Entity { get; set; }

void OnGetAspectFactory(World world);
}

public struct AspectFactory<T> where T : struct, IAspect {
public interface IBoxedAspectFactory {
Type AspectType { get; }

IAspect ValueBoxed { get; set; }
}

public struct AspectFactory<T> : IBoxedAspectFactory where T : struct, IAspect {
internal T value;

Type IBoxedAspectFactory.AspectType => typeof(T);

IAspect IBoxedAspectFactory.ValueBoxed {
get => this.value;
set => this.value = (T) value;
}
}
}
}
4 changes: 2 additions & 2 deletions Core/Collections/HashHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ internal static class HashHelpers {
67_108_863,
134_217_727,
268_435_455,
536_870_912,
536_870_911,
1_073_741_823
};

Expand Down Expand Up @@ -59,7 +59,7 @@ internal static class HashHelpers {
67_108_863,
134_217_727,
268_435_455,
536_870_912,
536_870_911,
1_073_741_823
};

Expand Down
20 changes: 20 additions & 0 deletions Core/Collections/IntHashMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,26 @@ public IntHashMap(in int capacity = 0) {
this.slots = new PinnedArray<IntHashMapSlot>(this.capacity);
this.data = new T[this.capacity];
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public IntHashMap(IntHashMap<T> other) {
this.lastIndex = other.lastIndex;
this.length = other.length;
this.freeIndex = other.freeIndex;

this.capacityMinusOne = other.capacityMinusOne;
this.capacity = other.capacity;

this.buckets = new IntPinnedArray(this.capacity);
this.slots = new PinnedArray<IntHashMapSlot>(this.capacity);
this.data = new T[this.capacity];

for (int i = 0, len = this.capacity; i < len; i++) {
this.buckets.data[i] = other.buckets.data[i];
this.slots.data[i] = other.slots.data[i];
this.data[i] = other.data[i];
}
}

~IntHashMap() {
this.buckets.Dispose();
Expand Down
25 changes: 25 additions & 0 deletions Core/Collections/IntHashMapExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,31 @@ public static void CopyTo<T>(this IntHashMap<T> hashMap, T[] array) {
++num;
}
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void CopyFrom<T>(this IntHashMap<T> hashMap, IntHashMap<T> from) {
hashMap.lastIndex = from.lastIndex;
hashMap.length = from.length;
hashMap.freeIndex = from.freeIndex;

var needResize = hashMap.capacity < from.capacity;

hashMap.capacityMinusOne = from.capacityMinusOne;
hashMap.capacity = from.capacity;

if (needResize) {
hashMap.buckets = new IntPinnedArray(hashMap.capacity);
hashMap.slots = new PinnedArray<IntHashMapSlot>(hashMap.capacity);
hashMap.data = new T[hashMap.capacity];
}

for (int i = 0, len = hashMap.capacity; i < len; i++) {
hashMap.buckets.data[i] = from.buckets.data[i];
hashMap.slots.data[i] = from.slots.data[i];
hashMap.data[i] = from.data[i];
}
}


[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Clear<T>(this IntHashMap<T> hashMap) {
Expand Down
2 changes: 1 addition & 1 deletion Core/Constants.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace Scellecs.Morpeh {
internal static class Constants {
internal const int DEFAULT_WORLD_ENTITIES_CAPACITY = 128;
internal const int DEFAULT_WORLD_CACHES_CAPACITY = 16;
internal const int DEFAULT_WORLD_STASHES_CAPACITY = 16;
internal const int DEFAULT_STASH_COMPONENTS_CAPACITY = 16;
}
}
14 changes: 10 additions & 4 deletions Core/EntityExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public static bool Has<T>(this Entity entity) where T : struct, IComponent {
#if MORPEH_LEGACY
[Obsolete("[MORPEH] Use Stash.Migrate() instead.")]
#endif
public static void MigrateTo(this Entity from, Entity to, bool overwrite = true) {
public static unsafe void MigrateTo(this Entity from, Entity to, bool overwrite = true) {
#if MORPEH_DEBUG
if (from.IsNullOrDisposed() || to.IsNullOrDisposed()) {
throw new Exception("[MORPEH] You are trying MigrateTo on null or disposed entities");
Expand All @@ -143,9 +143,15 @@ public static void MigrateTo(this Entity from, Entity to, bool overwrite = true)

var world = from.world;

var components = stackalloc int[from.components.count];
var idx = 0;
foreach (var offset in from.components) {
var id = CommonTypeIdentifier.offsetTypeAssociation[offset].id;
var stash = Stash.stashes.data[world.stashes.GetValueByKey(id)];
components[idx++] = offset;
}

for (int i = 0; i < idx; i++) {
var id = CommonTypeIdentifier.offsetTypeAssociation[components[i]].id;
var stash = world.stashes.GetValueByKey(id);
stash.Migrate(from, to, overwrite);
}
}
Expand Down Expand Up @@ -271,7 +277,7 @@ public static void Dispose(this Entity entity) {
if (entity.currentArchetypeLength > 0) {
foreach (var offset in entity.components) {
var id = CommonTypeIdentifier.offsetTypeAssociation[offset].id;
var stash = Stash.stashes.data[entity.world.stashes.GetValueByKey(id)];
var stash = entity.world.stashes.GetValueByKey(id);
stash.Clean(entity);
}
}
Expand Down
3 changes: 3 additions & 0 deletions Core/Native/NativeIntHashMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public struct NativeIntHashMap<TNative> where TNative : unmanaged {
[NativeDisableParallelForRestriction]
[NativeDisableUnsafePtrRestriction]
public unsafe TNative* data;

[NativeDisableUnsafePtrRestriction]
public TNative empty;

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Enumerator GetEnumerator() {
Expand Down
5 changes: 2 additions & 3 deletions Core/Native/NativeIntHashMapExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ internal static NativeIntHashMap<TNative> AsNative<TNative>(this IntHashMap<TNat
return nativeIntHashMap;
}


[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ref TNative GetValueRefByKey<TNative>(this NativeIntHashMap<TNative> nativeIntHashMap, in int key) where TNative : unmanaged {
public static ref TNative GetValueRefByKey<TNative>(this ref NativeIntHashMap<TNative> nativeIntHashMap, in int key) where TNative : unmanaged {
var rem = key & *nativeIntHashMap.capacityMinusOnePtr;

int next;
Expand All @@ -47,7 +46,7 @@ public static ref TNative GetValueRefByKey<TNative>(this NativeIntHashMap<TNativ
next = slot.next;
}

return ref UnsafeUtility.ArrayElementAsRef<TNative>(nativeIntHashMap.data, 0);
return ref nativeIntHashMap.empty;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand Down
31 changes: 27 additions & 4 deletions Core/Native/NativeStashExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,34 @@ namespace Scellecs.Morpeh.Native {
[Il2CppSetOption(Option.NullChecks, false)]
[Il2CppSetOption(Option.ArrayBoundsChecks, false)]
[Il2CppSetOption(Option.DivideByZeroChecks, false)]
public static class NativeStashExtensions {
public static unsafe class NativeStashExtensions {
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static NativeIntHashMap<TNative> AsNativeIntHashMap<TNative>(this Stash<TNative> hashMap) where TNative : unmanaged, IComponent {
var nativeIntHashMap = new NativeIntHashMap<TNative>();

fixed (int* lengthPtr = &hashMap.map.length)
fixed (int* capacityPtr = &hashMap.map.capacity)
fixed (int* capacityMinusOnePtr = &hashMap.map.capacityMinusOne)
fixed (int* lastIndexPtr = &hashMap.map.lastIndex)
fixed (int* freeIndexPtr = &hashMap.map.freeIndex)
fixed (TNative* dataPtr = &hashMap.data[0]) {
nativeIntHashMap.lengthPtr = lengthPtr;
nativeIntHashMap.capacityPtr = capacityPtr;
nativeIntHashMap.capacityMinusOnePtr = capacityMinusOnePtr;
nativeIntHashMap.lastIndexPtr = lastIndexPtr;
nativeIntHashMap.freeIndexPtr = freeIndexPtr;
nativeIntHashMap.data = dataPtr;
nativeIntHashMap.buckets = hashMap.map.buckets.ptr;
nativeIntHashMap.slots = hashMap.map.slots.ptr;
}

return nativeIntHashMap;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static NativeStash<TNative> AsNative<TNative>(this Stash<TNative> stash) where TNative : unmanaged, IComponent {
var nativeCache = new NativeStash<TNative> {
components = stash.components.AsNative(),
components = stash.AsNativeIntHashMap(),
world = stash.world.AsNative(),
};
return nativeCache;
Expand All @@ -22,12 +45,12 @@ public static bool Has<TNative>(this NativeStash<TNative> nativeStash, in Entity
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ref TNative Get<TNative>(this NativeStash<TNative> nativeStash, in EntityId entityId) where TNative : unmanaged, IComponent {
public static ref TNative Get<TNative>(this ref NativeStash<TNative> nativeStash, in EntityId entityId) where TNative : unmanaged, IComponent {
return ref nativeStash.components.GetValueRefByKey(in entityId.id);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ref TNative Get<TNative>(this NativeStash<TNative> nativeStash, in EntityId entityId, out bool exists) where TNative : unmanaged, IComponent {
public static ref TNative Get<TNative>(this ref NativeStash<TNative> nativeStash, in EntityId entityId, out bool exists) where TNative : unmanaged, IComponent {
exists = nativeStash.world.Has(in entityId) && nativeStash.Has(in entityId);
return ref nativeStash.components.GetValueRefByKey(in entityId.id);
}
Expand Down
Loading