Skip to content

Commit

Permalink
Update BlocksGenerator.BlockStateBuilder.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
Tides committed Jan 18, 2024
1 parent 3b96a44 commit 55971c2
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ private static void GenerateValueStore(CodeBuilder stateBuilder, BlockProperty[]

private static void GeneratePossibleStates(CodeBuilder stateBuilder, Dictionary<int, List<string>> stateValues, BlockProperty[] properties)
{
stateBuilder.Indent().Append("private int[] stateIds = [");
stateBuilder.Indent().Append("private static ReadOnlySpan<int> StateIds => [");
foreach (var key in stateValues.Keys)
stateBuilder.Append($"{key},");

stateBuilder.Append("];").Line();

stateBuilder.Indent().Append("private int[][] stateIndexes = [");
stateBuilder.Indent().Append("private static int[][] StatePropertyIndexes => [");

foreach (var values in stateValues.Values)
{
Expand Down Expand Up @@ -73,10 +73,10 @@ private static void SetStateFromIdMethod(string fullName, CodeBuilder stateBuild
{
stateBuilder.Line().Line().Method($"public {fullName}(int currentStateId)");

stateBuilder.Line("var arrayIndex = Array.IndexOf(stateIds, currentStateId);");
stateBuilder.Line("var stateIndexes = this.stateIndexes[arrayIndex];");
stateBuilder.Line("var arrayIndex = StateIds.IndexOf(currentStateId);");
stateBuilder.Line("var stateIndexesResult = StatePropertyIndexes[arrayIndex];");

stateBuilder.Line("var values = stateIndexes.GetStateValues(this.valueStore);");
stateBuilder.Line("var values = stateIndexesResult.GetStateValues(this.valueStore);");

var count = 0;
foreach (var property in properties)
Expand Down Expand Up @@ -214,8 +214,8 @@ private static void BuildStateFinder(CodeBuilder stateBuilder, BlockProperty[] p

stateBuilder.Line("];");

stateBuilder.Line().Line($"var stateIndex = this.stateIndexes.GetIndexFromJaggedArray(rawValue);");
stateBuilder.Line().Line($"var stateIndex = StatePropertyIndexes.GetIndexFromJaggedArray(rawValue);");

stateBuilder.Line().Line($"var stateId = this.stateIds[stateIndex];");
stateBuilder.Line().Line($"var stateId = StateIds[stateIndex];");
}
}

0 comments on commit 55971c2

Please sign in to comment.