ensure evaluation cannot be racey

This commit is contained in:
profan 2026-06-05 00:14:35 +01:00
parent 0eda244ce2
commit afb608ef7a
1 changed files with 10 additions and 5 deletions

View File

@ -61,8 +61,8 @@ void Main()
}
}
// options??
bool shouldUseParallelism = true;
bool shouldUseSimd = true;
bool isEvaluating = false;
bool shouldEvaluate = false;
@ -75,16 +75,21 @@ void Main()
Raylib.ClearBackground(Color.White);
if (shouldEvaluate & !isEvaluating)
if (shouldEvaluate && isEvaluating)
{
shouldUpdateTexture = true;
currentOutputImageData.AsSpan()[..currentOutputImageData.Length].Clear();
shouldEvaluate = false;
}
if (shouldEvaluate && !isEvaluating)
{
isEvaluating = true;
shouldUpdateTexture = true;
InterpreterOptions interpreterOptions = (shouldUseParallelism ? InterpreterOptions.Parallelism : default);
Task.Run(() =>
{
Instruction[] instructions = Parsing.Parse(programsProsperoVm);
currentOutputImageData.AsSpan()[..currentOutputImageData.Length].Clear();
Interpreter.Evaluate(instructions, imageSize: currentOutputImageSize, interpreterOptions, currentOutputImageData);
Raylib.UpdateTexture(currentOutputTexture, currentOutputImageData);
shouldCancelUpdateTexture = true;