ensure evaluation cannot be racey
This commit is contained in:
parent
0eda244ce2
commit
afb608ef7a
15
Program.cs
15
Program.cs
|
|
@ -60,9 +60,9 @@ void Main()
|
||||||
currentOutputTexture = Raylib.LoadTextureFromImage(currentOutputImage);
|
currentOutputTexture = Raylib.LoadTextureFromImage(currentOutputImage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// options??
|
||||||
bool shouldUseParallelism = true;
|
bool shouldUseParallelism = true;
|
||||||
bool shouldUseSimd = true;
|
|
||||||
|
|
||||||
bool isEvaluating = false;
|
bool isEvaluating = false;
|
||||||
bool shouldEvaluate = false;
|
bool shouldEvaluate = false;
|
||||||
|
|
@ -75,16 +75,21 @@ void Main()
|
||||||
|
|
||||||
Raylib.ClearBackground(Color.White);
|
Raylib.ClearBackground(Color.White);
|
||||||
|
|
||||||
if (shouldEvaluate & !isEvaluating)
|
if (shouldEvaluate && isEvaluating)
|
||||||
{
|
{
|
||||||
shouldUpdateTexture = true;
|
shouldEvaluate = false;
|
||||||
currentOutputImageData.AsSpan()[..currentOutputImageData.Length].Clear();
|
}
|
||||||
|
|
||||||
|
if (shouldEvaluate && !isEvaluating)
|
||||||
|
{
|
||||||
|
isEvaluating = true;
|
||||||
|
shouldUpdateTexture = true;
|
||||||
InterpreterOptions interpreterOptions = (shouldUseParallelism ? InterpreterOptions.Parallelism : default);
|
InterpreterOptions interpreterOptions = (shouldUseParallelism ? InterpreterOptions.Parallelism : default);
|
||||||
|
|
||||||
Task.Run(() =>
|
Task.Run(() =>
|
||||||
{
|
{
|
||||||
Instruction[] instructions = Parsing.Parse(programsProsperoVm);
|
Instruction[] instructions = Parsing.Parse(programsProsperoVm);
|
||||||
|
currentOutputImageData.AsSpan()[..currentOutputImageData.Length].Clear();
|
||||||
Interpreter.Evaluate(instructions, imageSize: currentOutputImageSize, interpreterOptions, currentOutputImageData);
|
Interpreter.Evaluate(instructions, imageSize: currentOutputImageSize, interpreterOptions, currentOutputImageData);
|
||||||
Raylib.UpdateTexture(currentOutputTexture, currentOutputImageData);
|
Raylib.UpdateTexture(currentOutputTexture, currentOutputImageData);
|
||||||
shouldCancelUpdateTexture = true;
|
shouldCancelUpdateTexture = true;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue