Updated Toy

This commit is contained in:
2023-06-13 08:27:31 +10:00
parent 3fba4e9b48
commit 301b4ad636
5 changed files with 43 additions and 11 deletions

2
Toy

Submodule Toy updated: 50d03e28fc...67fce427eb

View File

@@ -460,8 +460,11 @@ void Box_execEngine() {
SDL_RenderClear(engine.renderer); //NOTE: This line can be disabled later
Dbg_stopTimer(&dbgTimer);
Dbg_startTimer(&dbgTimer, "draw screen");
Dbg_startTimer(&dbgTimer, "onDraw() calls");
Box_callRecursiveEngineNode(engine.rootNode, &engine.interpreter, "onDraw", NULL);
Dbg_stopTimer(&dbgTimer);
Dbg_startTimer(&dbgTimer, "render screen");
SDL_RenderPresent(engine.renderer);
Dbg_stopTimer(&dbgTimer);
}

View File

@@ -66,7 +66,6 @@ void Dbg_clearConsole()
void Dbg_initTimer(Dbg_Timer* timer) {
timer->name = NULL;
timer->start = 0;
timer->log = TOY_ALLOCATE(char, 2048);
memset(timer->log, 0, 2048);
timer->logPos = 0;
}
@@ -87,13 +86,12 @@ void Dbg_printTimerLog(Dbg_Timer* timer) {
}
void Dbg_freeTimer(Dbg_Timer* timer) {
TOY_FREE_ARRAY(char, timer->log, 2048);
//
}
void Dbg_initFPSCounter(Dbg_FPSCounter* counter) {
counter->count = 0;
counter->start = clock();
counter->log = TOY_ALLOCATE(char, 256);
memset(counter->log, 0, 256);
}
@@ -112,5 +110,5 @@ void Dbg_printFPSCounter(Dbg_FPSCounter* counter) {
}
void Dbg_freeFPSCounter(Dbg_FPSCounter* counter) {
TOY_FREE_ARRAY(char, counter->log, 256);
//
}

View File

@@ -7,7 +7,7 @@ void Dbg_clearConsole();
typedef struct Dbg_Timer {
const char* name;
clock_t start;
char* log;
char log[2048];
int logPos;
} Dbg_Timer;
@@ -20,7 +20,7 @@ void Dbg_freeTimer(Dbg_Timer*);
typedef struct Dbg_FPSCounter {
int count;
clock_t start;
char* log;
char log[256];
} Dbg_FPSCounter;
void Dbg_initFPSCounter(Dbg_FPSCounter*);

View File

@@ -1471,9 +1471,14 @@ static void recursiveLiteralQuicksortUtil(Toy_Interpreter* interpreter, Toy_Lite
swapLiteralsUtil(&ptr[runner], &ptr[literalCount - 1]);
//recurse on each end
if (runner > 0) {
recursiveLiteralQuicksortUtil(interpreter, &ptr[0], runner, fnCompareLiteral);
}
if (runner < literalCount) {
recursiveLiteralQuicksortUtil(interpreter, &ptr[runner + 1], literalCount - runner - 1, fnCompareLiteral);
}
}
static int nativeSort(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) {
//no arguments
@@ -1511,8 +1516,34 @@ static int nativeSort(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments)
return -1;
}
//BUGFIX: check if the array is already sorted
bool sorted = true;
for (int checker = 0; checker < TOY_AS_ARRAY(selfLiteral)->count - 1 && sorted; checker++) {
Toy_LiteralArray arguments;
Toy_LiteralArray returns;
Toy_initLiteralArray(&arguments);
Toy_initLiteralArray(&returns);
Toy_pushLiteralArray(&arguments, TOY_AS_ARRAY(selfLiteral)->literals[checker]);
Toy_pushLiteralArray(&arguments, TOY_AS_ARRAY(selfLiteral)->literals[checker + 1]);
Toy_callLiteralFn(interpreter, fnLiteral, &arguments, &returns);
Toy_Literal lessThan = Toy_popLiteralArray(&returns);
Toy_freeLiteralArray(&arguments);
Toy_freeLiteralArray(&returns);
if (!TOY_IS_TRUTHY(lessThan)) {
sorted = false;
}
Toy_freeLiteral(lessThan);
}
//call the quicksort util
if (TOY_IS_ARRAY(selfLiteral)) {
if (!sorted) {
recursiveLiteralQuicksortUtil(interpreter, TOY_AS_ARRAY(selfLiteral)->literals, TOY_AS_ARRAY(selfLiteral)->count, fnLiteral);
}