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

Game data loading optimizations. #1161

Merged
merged 36 commits into from
Mar 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
d591dde
Optimized "UndertaleGameObject" initialization.
VladiStep Jan 21, 2023
71af62e
Little optimization of `UndertalePointerList.Unserialize()`.
VladiStep Jan 22, 2023
394a18a
Optimized most of "UndertaleLists.cs" lists.
VladiStep Jan 23, 2023
972eefd
Another optimization of `UndertaleGameObject` initialization.
VladiStep Jan 23, 2023
e2a8065
Optimized "UndertaleSimpleListShort" unserialization.
VladiStep Jan 23, 2023
fc87007
Got rid of all garbage "NotifyCollectionChangedEventArgs" on data loa…
VladiStep Jan 23, 2023
98558f6
Added overload for "SetCapacity()", added it where necessary.
VladiStep Jan 23, 2023
0d6055a
Made "internalList" private, replaced "internalList.Add()" with "AddD…
VladiStep Jan 24, 2023
f227a49
A little optimization of a texture data unserialization.
VladiStep Jan 29, 2023
735e2fc
Optimized "UndertaleChunkVARI" unserialization.
VladiStep Jan 29, 2023
8d43b4f
Initial changes for unserializing the total count of all child object…
VladiStep Jan 31, 2023
22575bc
Fixed count unserialization of all "UndertaleList"s, implemented "Uns…
VladiStep Feb 1, 2023
b13e7bb
Simplified count unserialization of every "UndertaleSingleChunk<>".
VladiStep Feb 1, 2023
9359326
The count unserialization related changes.
VladiStep Feb 8, 2023
892ec5c
Implemented "UnserializeChildObjectCount()" for more models, and othe…
VladiStep Feb 13, 2023
8a027d2
Implemented "UnserializeChildObjectCount()" for more models, and othe…
VladiStep Feb 15, 2023
ddcf873
Fixed "UndertaleSound" count unserialization.
VladiStep Feb 15, 2023
802ebd6
Implemented "UnserializeChildObjectCount()" for the remaining models,…
VladiStep Feb 16, 2023
eb001ad
Fixed all count unserialization inaccuracies.
VladiStep Feb 18, 2023
2c55f33
Optimized code chunk unserialization.
VladiStep Feb 19, 2023
394fc35
Game data loads by copying every chunk to the buffer.
VladiStep Feb 26, 2023
c68d527
"AdaptiveBinaryReader" optimizations.
VladiStep Feb 26, 2023
68c67f2
Final "AdaptiveBinaryReader" related changes.
VladiStep Feb 27, 2023
9e0ea8d
Merge branch 'master' into dataLoadingOptimizations
VladiStep Feb 28, 2023
777159c
Final changes for the 'master' branch merging.
VladiStep Feb 28, 2023
9b1fa5b
Added pool size check; fixed #1194.
VladiStep Feb 28, 2023
b7b07d1
Fixed extension object count unserialization.
VladiStep Feb 28, 2023
263f03c
Optimized rooms unserialization.
VladiStep Feb 28, 2023
39aa2cc
Removed redundant `Dispose()` declaration.
VladiStep Mar 2, 2023
841ac26
Slightly optimized count unserialization (thanks to @Jacky720).
VladiStep Mar 2, 2023
341a274
Fixed `UndertaleSprite` count unserialization.
VladiStep Mar 2, 2023
17d63a6
Merge branch 'master' into dataLoadingOptimizations
VladiStep Mar 3, 2023
29e9c50
Removed redundant line
VladiStep Mar 3, 2023
35ac55d
Updated `Track.UnserializeChildObjectCount()`.
VladiStep Mar 3, 2023
fe50bb8
Fixed grammar mistake.
VladiStep Mar 4, 2023
f0afee9
Little optimizations related to count unserialization.
VladiStep Mar 4, 2023
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
14 changes: 14 additions & 0 deletions UndertaleModCli/Program.UMTLibInherited.cs
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,9 @@ public string GetDecompiledText(string codeName, GlobalDecompileContext context
/// <inheritdoc/>
public string GetDecompiledText(UndertaleCode code, GlobalDecompileContext context = null)
{
if (code.ParentEntry is not null)
return $"// This code entry is a reference to an anonymous function within \"{code.ParentEntry.Name.Content}\", decompile that instead.";

GlobalDecompileContext decompileContext = context is null ? new(Data, false) : context;
try
{
Expand All @@ -437,6 +440,9 @@ public string GetDisassemblyText(string codeName)
/// <inheritdoc/>
public string GetDisassemblyText(UndertaleCode code)
{
if (code.ParentEntry is not null)
return $"; This code entry is a reference to an anonymous function within \"{code.ParentEntry.Name.Content}\", disassemble that instead.";

try
{
return code != null ? code.Disassemble(Data.Variables, Data.CodeLocals.For(code)) : "";
Expand Down Expand Up @@ -639,6 +645,8 @@ public void ReplaceTextInGML(string codeName, string keyword, string replacement
public void ReplaceTextInGML(UndertaleCode code, string keyword, string replacement, bool caseSensitive = false, bool isRegex = false, GlobalDecompileContext context = null)
{
if (code == null) throw new ArgumentNullException(nameof(code));
if (code.ParentEntry is not null)
return;

EnsureDataLoaded();

Expand Down Expand Up @@ -748,6 +756,9 @@ void ImportCode(string codeName, string gmlCode, bool isGML = true, bool doParse
code.Name = Data.Strings.MakeString(codeName);
Data.Code.Add(code);
}
else if (code.ParentEntry is not null)
return;

if (Data?.GeneralInfo.BytecodeVersion > 14 && Data.CodeLocals.ByName(codeName) == null)
{
UndertaleCodeLocals locals = new UndertaleCodeLocals();
Expand Down Expand Up @@ -1155,6 +1166,9 @@ public string GetGUIDFromCodeName(string codeName)
void SafeImport(string codeName, string gmlCode, bool isGML, bool destroyASM = true, bool checkDecompiler = false, bool throwOnError = false)
{
UndertaleCode code = Data.Code.ByName(codeName);
if (code?.ParentEntry is not null)
return;

try
{
if (isGML)
Expand Down
52 changes: 34 additions & 18 deletions UndertaleModLib/Models/UndertaleAnimationCurve.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,25 @@ public void Unserialize(UndertaleReader reader, bool includeName)
Channels = reader.ReadUndertaleObject<UndertaleSimpleList<Channel>>();
}

/// <inheritdoc cref="UndertaleObject.UnserializeChildObjectCount(UndertaleReader)"/>
public static uint UnserializeChildObjectCount(UndertaleReader reader)
{
return UnserializeChildObjectCount(reader, true);
}

/// <inheritdoc cref="UndertaleObject.UnserializeChildObjectCount(UndertaleReader)"/>
/// <param name="reader">Where to deserialize from.</param>
/// <param name="includeName">Whether to include <see cref="Name"/> in the deserialization.</param>
public static uint UnserializeChildObjectCount(UndertaleReader reader, bool includeName)
{
if (!includeName)
reader.Position += 4; // "GraphType"
else
reader.Position += 4 + 4; // + "Name"

return 1 + UndertaleSimpleList<Channel>.UnserializeChildObjectCount(reader);
}

/// <inheritdoc />
public override string ToString()
{
Expand Down Expand Up @@ -117,6 +136,21 @@ public void Unserialize(UndertaleReader reader)
Points = reader.ReadUndertaleObject<UndertaleSimpleList<Point>>();
}

/// <inheritdoc cref="UndertaleObject.UnserializeChildObjectCount(UndertaleReader)"/>
public static uint UnserializeChildObjectCount(UndertaleReader reader)
{
reader.Position += 12;

// "Points"
uint count = reader.ReadUInt32();
if (reader.undertaleData.IsVersionAtLeast(2, 3, 1))
reader.Position += 24 * count;
else
reader.Position += 12 * count;

return 1 + count;
}

/// <inheritdoc/>
public void Dispose()
{
Expand Down Expand Up @@ -159,24 +193,6 @@ public void Unserialize(UndertaleReader reader)
X = reader.ReadSingle();
Value = reader.ReadSingle();

if (!reader.undertaleData.IsVersionAtLeast(2, 3, 1))
{
if (reader.ReadUInt32() != 0) // in 2.3 a int with the value of 0 would be set here,
{ // it cannot be version 2.3 if this value isn't 0
reader.undertaleData.SetGMS2Version(2, 3, 1);
reader.Position -= 4;
}
else
{
// At all points (besides the first one)
// if BezierX0 equals to 0 (the above check)
// then BezierY0 equals to 0 as well (the below check)
if (reader.ReadUInt32() == 0)
reader.undertaleData.SetGMS2Version(2, 3, 1);
reader.Position -= 8;
}
}

if (reader.undertaleData.IsVersionAtLeast(2, 3, 1))
{
BezierX0 = reader.ReadSingle();
Expand Down
Loading