Skip to content

Commit

Permalink
Added overload for "SetCapacity()", added it where necessary.
Browse files Browse the repository at this point in the history
  • Loading branch information
VladiStep committed Jan 23, 2023
1 parent fc87007 commit 98558f6
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions UndertaleModLib/Models/UndertaleGameObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ protected void OnPropertyChanged([CallerMemberName] string name = null)
/// </summary>
public UndertaleGameObject()
{
Events.SetCapacity(eventTypesLength);
for (int i = 0; i < eventTypesLength; i++)
Events.internalList.Add(new UndertalePointerList<Event>());
}
Expand Down
2 changes: 2 additions & 0 deletions UndertaleModLib/Models/UndertaleRoom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ protected void OnPropertyChanged([CallerMemberName] string name = null)
/// </summary>
public UndertaleRoom()
{
Backgrounds.SetCapacity(8);
Views.SetCapacity(8);
for (int i = 0; i < 8; i++)
Backgrounds.internalList.Add(new Background());
for (int i = 0; i < 8; i++)
Expand Down
2 changes: 2 additions & 0 deletions UndertaleModLib/UndertaleChunkTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ internal override void SerializeChunk(UndertaleWriter writer)
internal override void UnserializeChunk(UndertaleReader reader)
{
uint count = reader.ReadUInt32();
List.SetCapacity(count);

for (int i = 0; i < count; i++)
Align &= (reader.ReadUInt32() % Alignment == 0);
for (int i = 0; i < count; i++)
Expand Down
5 changes: 3 additions & 2 deletions UndertaleModLib/UndertaleLists.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,18 @@ public UndertaleListBase()
/// <inheritdoc />
public abstract void Unserialize(UndertaleReader reader);

public void SetCapacity(uint capacity)
public void SetCapacity(int capacity)
{
try
{
internalList.Capacity = (int)capacity;
internalList.Capacity = capacity;
}
catch (Exception e)
{
throw new UndertaleSerializationException($"{e.Message}\nwhile trying to \"SetCapacity()\" of \"UndertalePointerList<{typeof(T).FullName}>\".");
}
}
public void SetCapacity(uint capacity) => SetCapacity((int)capacity);
}

public class UndertaleSimpleList<T> : UndertaleListBase<T>, UndertaleObject where T : UndertaleObject, new()
Expand Down

0 comments on commit 98558f6

Please sign in to comment.