forked from Albeoris/Memoria
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'Albeoris:main' into main
- Loading branch information
Showing
50 changed files
with
2,338 additions
and
1,303 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 33 additions & 21 deletions
54
Assembly-CSharp/Assets/Sources/Scripts/EventEngine/Utils/CalcStack.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,79 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Memoria.Prime; | ||
|
||
namespace Assets.Sources.Scripts.EventEngine.Utils | ||
{ | ||
public class CalcStack | ||
{ | ||
public Boolean push(Int32 arg0) | ||
public Boolean push(Int32 val) | ||
{ | ||
if (this.topOfStackID >= this.stack.Length - 1) | ||
return false; | ||
this.stack[this.topOfStackID] = arg0; | ||
this.topOfStackID++; | ||
while (topOfStackID >= stack.Count) | ||
stack.Add(0); | ||
stack[topOfStackID++] = val; | ||
return true; | ||
} | ||
|
||
public Boolean pop(out Int32 output) | ||
{ | ||
if (this.topOfStackID == 0) | ||
if (topOfStackID == 0) | ||
{ | ||
Log.Error($"[{nameof(CalcStack)}.{nameof(pop)}] this.topOfStackID == 0"); | ||
Log.Error($"[{nameof(CalcStack)}.{nameof(pop)}] topOfStackID == 0"); | ||
output = default; | ||
return false; | ||
} | ||
output = this.stack[this.topOfStackID - 1]; | ||
this.topOfStackID--; | ||
output = stack[--topOfStackID]; | ||
return true; | ||
} | ||
|
||
public Boolean advanceTopOfStack() | ||
{ | ||
if (this.topOfStackID >= this.stack.Length - 1) | ||
return false; | ||
this.topOfStackID++; | ||
topOfStackID++; | ||
while (topOfStackID > stack.Count) | ||
stack.Add(0); | ||
return true; | ||
} | ||
|
||
public Boolean retreatTopOfStack() | ||
{ | ||
if (this.topOfStackID == 0) | ||
if (topOfStackID == 0) | ||
return false; | ||
this.topOfStackID--; | ||
topOfStackID--; | ||
return true; | ||
} | ||
|
||
public void emptyCalcStack() | ||
{ | ||
for (Int32 i = 0; i < this.stack.Length; i++) | ||
this.stack[i] = 0; | ||
this.topOfStackID = 0; | ||
substack.Clear(); | ||
for (Int32 i = 0; i < stack.Count; i++) | ||
stack[i] = 0; | ||
topOfStackID = 0; | ||
} | ||
|
||
public Int32 getTopOfStackID() | ||
{ | ||
return this.topOfStackID; | ||
return topOfStackID; | ||
} | ||
|
||
public Int32 getValueAtOffset(Int32 offset) | ||
{ | ||
return this.stack[this.topOfStackID + offset]; | ||
return stack[topOfStackID + offset]; | ||
} | ||
|
||
public void pushSubs(params Int32[] val) | ||
{ | ||
substack[topOfStackID] = new List<Int32>(val); | ||
} | ||
|
||
public List<Int32> getSubs() | ||
{ | ||
if (substack.TryGetValue(topOfStackID, out List<Int32> result)) | ||
return result; | ||
return new List<Int32>(); | ||
} | ||
|
||
private const Int32 STACK_SIZE = 16; | ||
private Int32[] stack = new Int32[STACK_SIZE]; | ||
private Dictionary<Int32, List<Int32>> substack = new Dictionary<Int32, List<Int32>>(); | ||
private List<Int32> stack = new List<Int32>(16); | ||
private Int32 topOfStackID; | ||
} | ||
} |
Oops, something went wrong.