try a different strategy for managing mangled cached commands

This commit is contained in:
camh 2022-02-25 10:19:19 -08:00
parent c17620ce52
commit 32b72fe50d
4 changed files with 50 additions and 38 deletions

Binary file not shown.

Binary file not shown.

View File

@ -4050,25 +4050,25 @@ NK_API void nk_textedit_redo(struct nk_text_edit*);
update what is actually necessary which is crucial for performance. update what is actually necessary which is crucial for performance.
*/ */
enum nk_command_type { enum nk_command_type {
NK_COMMAND_NOP, NK_COMMAND_NOP, // 0
NK_COMMAND_SCISSOR, NK_COMMAND_SCISSOR, // 1
NK_COMMAND_LINE, NK_COMMAND_LINE, // 2
NK_COMMAND_CURVE, NK_COMMAND_CURVE, // 3
NK_COMMAND_RECT, NK_COMMAND_RECT, // 4
NK_COMMAND_RECT_FILLED, NK_COMMAND_RECT_FILLED, // 5
NK_COMMAND_RECT_MULTI_COLOR, NK_COMMAND_RECT_MULTI_COLOR, // 6
NK_COMMAND_CIRCLE, NK_COMMAND_CIRCLE, // 7
NK_COMMAND_CIRCLE_FILLED, NK_COMMAND_CIRCLE_FILLED, // 8
NK_COMMAND_ARC, NK_COMMAND_ARC, // 9
NK_COMMAND_ARC_FILLED, NK_COMMAND_ARC_FILLED, // 10
NK_COMMAND_TRIANGLE, NK_COMMAND_TRIANGLE, // 11
NK_COMMAND_TRIANGLE_FILLED, NK_COMMAND_TRIANGLE_FILLED, // 12
NK_COMMAND_POLYGON, NK_COMMAND_POLYGON, // 13
NK_COMMAND_POLYGON_FILLED, NK_COMMAND_POLYGON_FILLED, // 14
NK_COMMAND_POLYLINE, NK_COMMAND_POLYLINE, // 15
NK_COMMAND_TEXT, NK_COMMAND_TEXT, // 16
NK_COMMAND_IMAGE, NK_COMMAND_IMAGE, // 17
NK_COMMAND_CUSTOM NK_COMMAND_CUSTOM // 18
}; };
/* command base and header of every command inside the buffer */ /* command base and header of every command inside the buffer */

View File

@ -52,7 +52,7 @@ NK_API NkQuickDrawFont* nk_quickdraw_font_create_from_file();
* *
* =============================================================== * ===============================================================
*/ */
#define MAX_MEMORY_IN_KB 8 #define MAX_MEMORY_IN_KB 6
#ifdef NK_QUICKDRAW_IMPLEMENTATION #ifdef NK_QUICKDRAW_IMPLEMENTATION
#ifndef NK_QUICKDRAW_TEXT_MAX #ifndef NK_QUICKDRAW_TEXT_MAX
#define NK_QUICKDRAW_TEXT_MAX 256 #define NK_QUICKDRAW_TEXT_MAX 256
@ -495,6 +495,13 @@ void updateBounds(int top, int bottom, int left, int right) {
writeSerialPortDebug(boutRefNum, "DEBUG_FUNCTION_CALLS: runDrawCommand"); writeSerialPortDebug(boutRefNum, "DEBUG_FUNCTION_CALLS: runDrawCommand");
#endif #endif
char x[255];
sprintf(x, "cmd: %d", cmd->type);
writeSerialPortDebug(boutRefNum, x);
char y[255];
sprintf(y, "lastCmd: %d", lastCmd->type);
writeSerialPortDebug(boutRefNum, y);
switch (cmd->type) { switch (cmd->type) {
case NK_COMMAND_NOP: case NK_COMMAND_NOP:
@ -559,13 +566,6 @@ void updateBounds(int top, int bottom, int left, int right) {
#ifdef COMMAND_CACHING #ifdef COMMAND_CACHING
char x[255];
sprintf(x, "cmd: %d", cmd->type);
writeSerialPortDebug(boutRefNum, x);
char y[255];
sprintf(y, "lastCmd: %d", lastCmd->type);
writeSerialPortDebug(boutRefNum, y);
if (!lastInputWasBackspace && cmd->type == lastCmd->type && memcmp(r, lastCmd, sizeof(struct nk_command_rect)) == 0) { if (!lastInputWasBackspace && cmd->type == lastCmd->type && memcmp(r, lastCmd, sizeof(struct nk_command_rect)) == 0) {
#ifdef NK_QUICKDRAW_GRAPHICS_DEBUGGING #ifdef NK_QUICKDRAW_GRAPHICS_DEBUGGING
@ -630,13 +630,6 @@ void updateBounds(int top, int bottom, int left, int right) {
writeSerialPortDebug(boutRefNum, "NK_COMMAND_RECT_FILLED5"); writeSerialPortDebug(boutRefNum, "NK_COMMAND_RECT_FILLED5");
#ifdef COMMAND_CACHING #ifdef COMMAND_CACHING
char x[255];
sprintf(x, "cmd: %d", cmd->type);
writeSerialPortDebug(boutRefNum, x);
char y[255];
sprintf(y, "lastCmd: %d", lastCmd->type);
writeSerialPortDebug(boutRefNum, y);
if (!lastInputWasBackspace && cmd->type == lastCmd->type && memcmp(r, lastCmd, sizeof(struct nk_command_rect_filled)) == 0) { if (!lastInputWasBackspace && cmd->type == lastCmd->type && memcmp(r, lastCmd, sizeof(struct nk_command_rect_filled)) == 0) {
#ifdef NK_QUICKDRAW_GRAPHICS_DEBUGGING #ifdef NK_QUICKDRAW_GRAPHICS_DEBUGGING
@ -1114,6 +1107,27 @@ void updateBounds(int top, int bottom, int left, int right) {
int lastCalls = 0; int lastCalls = 0;
int currentCalls; int currentCalls;
const struct nk_command *lastCmd; const struct nk_command *lastCmd;
Boolean VALID_COMMANDS[18] = {
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true
};
#endif #endif
NK_API void nk_quickdraw_render(WindowPtr window, struct nk_context *ctx) { NK_API void nk_quickdraw_render(WindowPtr window, struct nk_context *ctx) {
@ -1180,10 +1194,8 @@ NK_API void nk_quickdraw_render(WindowPtr window, struct nk_context *ctx) {
#ifdef NK_QUICKDRAW_GRAPHICS_DEBUGGING #ifdef NK_QUICKDRAW_GRAPHICS_DEBUGGING
writeSerialPortDebug(boutRefNum, "COMMAND_CACHING: get next cached command"); writeSerialPortDebug(boutRefNum, "COMMAND_CACHING: get next cached command");
#endif #endif
// TODO: if this becomes worth pursuing later, it causes address errors. I suspect that the memcpy
// command that builds up the last variable is not properly allocating memory. if (currentCalls < lastCalls && lastCmd && VALID_COMMANDS[lastCmd->type]) {
// the address error pops up on the line of the conditional itself and can sometimes take hours to trigger.
if (currentCalls < lastCalls - 1 && lastCmd && lastCmd->next) {
#ifdef NK_QUICKDRAW_GRAPHICS_DEBUGGING #ifdef NK_QUICKDRAW_GRAPHICS_DEBUGGING
writeSerialPortDebug(boutRefNum, "COMMAND_CACHING: inside conditional"); writeSerialPortDebug(boutRefNum, "COMMAND_CACHING: inside conditional");