Compare commits

...

2 Commits

5 changed files with 124 additions and 139 deletions

Binary file not shown.

Binary file not shown.

View File

@ -25,7 +25,7 @@
// #define MAC_APP_DEBUGGING
// #define PROFILING 1
#define DEBUG_FUNCTION_CALLS
// #define DEBUG_FUNCTION_CALLS
#ifdef PROFILING
OSErr writeSerialPortProfile(const char* str)
@ -182,7 +182,6 @@ void EventLoop(struct nk_context *ctx)
int lastMouseVPos = 0;
int lastUpdatedTickCountMessagesInChat = 0;
int lastUpdatedTickCountChatCounts = 0;
Boolean gotNewMessages = false;
do {
@ -198,16 +197,11 @@ void EventLoop(struct nk_context *ctx)
ShowCursor();
}
gotNewMessages = false;
// check for new stuff every 10 sec?
// note! this is used by some of the functionality in our nuklear_app to trigger
// new chat lookups
if (TickCount() - lastUpdatedTickCountMessagesInChat > 600) {
if (TickCount() - lastUpdatedTickCountMessagesInChat > 300) {
gotNewMessages = true;
// writeSerialPortDebug(boutRefNum, "update by tick count");
lastUpdatedTickCountMessagesInChat = TickCount();
if (strcmp(activeChat, "no active chat")) {
@ -218,8 +212,8 @@ void EventLoop(struct nk_context *ctx)
}
// this should be out of sync with the counter above it so that we dont end up making
// two coprocessor calls on one event loop iteration
if (!gotNewMessages && TickCount() - lastUpdatedTickCountChatCounts > 300) {
// two coprocessor calls on one event loop iteratio
if (TickCount() - lastUpdatedTickCountChatCounts > 600) {
// writeSerialPortDebug(boutRefNum, "update by tick count");
lastUpdatedTickCountChatCounts = TickCount();
@ -319,18 +313,6 @@ void EventLoop(struct nk_context *ctx)
// only re-render if there is an event, prevents screen flickering, speeds up app
if (beganInput || firstOrMouseMove || forceRedraw) {
if (beganInput) {
writeSerialPortDebug(boutRefNum, "beganInput");
}
if (beganInput) {
writeSerialPortDebug(boutRefNum, "beganInput");
}
if (forceRedraw) {
writeSerialPortDebug(boutRefNum, "forceRedraw");
}
#ifdef PROFILING
PROFILE_START("nk_input_end");
#endif

View File

@ -181,14 +181,16 @@ void sendMessage() {
memset(&box_input_buffer, '\0', 2048);
box_input_len = 0;
refreshNuklearApp(1);
// this was an attempt to get the text in the textbox to go away... doesn't really work for a few more redraws
// so actually just makes things slower:
// refreshNuklearApp(1);
callFunctionOnCoprocessor("sendMessage", output, jsFunctionResponse);
getMessagesFromjsFunctionResponse();
forceRedraw = 2;
firstOrMouseMove = true;
forceRedraw = 3;
return;
}
@ -205,9 +207,10 @@ void getChats() {
callFunctionOnCoprocessor("getChats", "", jsFunctionResponse);
char * token = (char *)strtokm(jsFunctionResponse, ",");
// loop through the string to extract all other tokens
char *token = (char *)strtokm(jsFunctionResponse, ",");
while (token != NULL) {
writeSerialPortDebug(boutRefNum, token);
sprintf(chatFriendlyNames[chatFriendlyNamesCounter++], "%s", token);
token = (char *)strtokm(NULL, ",");
@ -238,7 +241,7 @@ void sendIPAddressToCoprocessor() {
// set up function to get messages in current chat
// limit to recent messages
// figure out pagination?? button on the top that says "get previous chats"?
// figure out pagination?? button on the top that says "get previous chats"?, TODO
void getMessages(char *thread, int page) {
#ifdef DEBUG_FUNCTION_CALLS
@ -284,123 +287,113 @@ void getChatCounts() {
writeSerialPortDebug(boutRefNum, chatCountFunctionResponse);
#endif
if (strcmp(chatCountFunctionResponse, previousChatCountFunctionResponse)) {
// bail out if the responses ARE equal
if (!strcmp(chatCountFunctionResponse, previousChatCountFunctionResponse)) {
#ifdef MESSAGES_FOR_MACINTOSH_DEBUGGING
writeSerialPortDebug(boutRefNum, "update current chat count");
writeSerialPortDebug(boutRefNum, chatCountFunctionResponse);
writeSerialPortDebug(boutRefNum, "no need to update current chat count");
return;
}
//#ifdef MESSAGES_FOR_MACINTOSH_DEBUGGING
writeSerialPortDebug(boutRefNum, "update current chat count");
writeSerialPortDebug(boutRefNum, chatCountFunctionResponse);
writeSerialPortDebug(boutRefNum, previousChatCountFunctionResponse);
//#endif
SysBeep(1);
strcpy(tempChatCountFunctionResponse, chatCountFunctionResponse);
int chatCount = 0;
char *(*chats[16])[64];
chatCount = strsplit(tempChatCountFunctionResponse, (char **)chats, ",");
for (int chatLoopCounter = 0; chatLoopCounter < chatCount; chatLoopCounter++) {
#ifdef MESSAGES_FOR_MACINTOSH_DEBUGGING
writeSerialPortDebug(boutRefNum, "DUMMY DELETE: update current chat count loop");
writeSerialPortDebug(boutRefNum, chats[chatLoopCounter]);
#endif
}
// loop through the string to extract all other tokens
for (int chatLoopCounter = 0; chatLoopCounter < chatCount; chatLoopCounter++) {
#ifdef MESSAGES_FOR_MACINTOSH_DEBUGGING
writeSerialPortDebug(boutRefNum, "update current chat count loop");
writeSerialPortDebug(boutRefNum, chats[chatLoopCounter]);
#endif
SysBeep(1);
// chats[chatLoopCounter] should be in format NAME:::COUNT
strcpy(tempChatCountFunctionResponse, chatCountFunctionResponse);
int chatCount = 0;
char *(*chats[16])[64];
int results = 0;
char *(*chatUpdate[2])[64];
chatCount = strsplit(tempChatCountFunctionResponse, (char **)chats, ",");
results = strsplit((char *)chats[chatLoopCounter], (char **)chatUpdate, ":::");
for (int chatLoopCounter = 0; chatLoopCounter < chatCount; chatLoopCounter++) {
if (results != 2) {
#ifdef MESSAGES_FOR_MACINTOSH_DEBUGGING
writeSerialPortDebug(boutRefNum, "DUMMY DELETE: update current chat count loop");
writeSerialPortDebug(boutRefNum, chats[chatLoopCounter]);
char x[255];
sprintf(x, "ERROR: chat update mismatch splitting on ':::', expected 2 results, got: %d: %s -- bailing out", results, chats[chatLoopCounter]);
writeSerialPortDebug(boutRefNum, x);
for (int errorResultCounter = 0; errorResultCounter < results; errorResultCounter++) {
writeSerialPortDebug(boutRefNum, chatUpdate[errorResultCounter]);
char y[255];
sprintf(y, "%d/%d: '%s'", errorResultCounter, results, chatUpdate[errorResultCounter]);
writeSerialPortDebug(boutRefNum, y);
}
#endif
continue;
}
// loop through the string to extract all other tokens
for (int chatLoopCounter = 0; chatLoopCounter < chatCount; chatLoopCounter++) {
short count = atoi((char *)chatUpdate[1]);
#ifdef MESSAGES_FOR_MACINTOSH_DEBUGGING
writeSerialPortDebug(boutRefNum, "update current chat count loop");
writeSerialPortDebug(boutRefNum, chats[chatLoopCounter]);
#endif
#ifdef MESSAGES_FOR_MACINTOSH_DEBUGGING
char x[255];
sprintf(x, "name: %s, countString: %s, count: %d", chatUpdate[0], chatUpdate[1], count);
writeSerialPortDebug(boutRefNum, x);
#endif
// chats[chatLoopCounter] should be in format NAME:::COUNT
for (int i = 0; i < chatFriendlyNamesCounter; i++) {
strcpy(tempChatCountFunctionResponse, chatCountFunctionResponse);
int results = 0;
char *(*chatUpdate[2])[64];
if (strstr(chatFriendlyNames[i], " new) ") != NULL) {
results = strsplit((char *)chats[chatLoopCounter], (char **)chatUpdate, ":::");
char chatName[64];
sprintf(chatName, "%.63s", chatFriendlyNames[i]);
if (results != 2) {
int updateResults = 0;
char *(*updatePieces[2])[64];
#ifdef MESSAGES_FOR_MACINTOSH_DEBUGGING
char x[255];
sprintf(x, "ERROR: chat update mismatch splitting on ':::', expected 2 results, got: %d: %s -- bailing out", results, chats[chatLoopCounter]);
writeSerialPortDebug(boutRefNum, x);
updateResults = strsplit(chatName, (char **)updatePieces, " new) ");
for (int errorResultCounter = 0; errorResultCounter < results; errorResultCounter++) {
writeSerialPortDebug(boutRefNum, chatUpdate[errorResultCounter]);
char y[255];
sprintf(y, "%d/%d: '%s'", errorResultCounter, results, chatUpdate[errorResultCounter]);
writeSerialPortDebug(boutRefNum, y);
}
#endif
continue;
}
short count = atoi((char *)chatUpdate[1]);
#ifdef MESSAGES_FOR_MACINTOSH_DEBUGGING
char x[255];
sprintf(x, "name: %s, countString: %s, count: %d", chatUpdate[0], chatUpdate[1], count);
writeSerialPortDebug(boutRefNum, x);
#endif
for (int i = 0; i < chatFriendlyNamesCounter; i++) {
if (strstr(chatFriendlyNames[i], " new) ") != NULL) {
char chatName[64];
sprintf(chatName, "%.63s", chatFriendlyNames[i]);
int updateResults = 0;
char *(*updatePieces[2])[64];
updateResults = strsplit(chatName, (char **)updatePieces, " new) ");
if (updateResults != 2) {
#ifdef MESSAGES_FOR_MACINTOSH_DEBUGGING
char x[255];
sprintf(x, "ERROR: individual chat update mismatch splitting on ' new) ', expected 2 results, got: %d: %s -- bailing out", updateResults, chatName);
writeSerialPortDebug(boutRefNum, x);
for (int errorResultCounter = 0; errorResultCounter < updateResults; errorResultCounter++) {
char y[255];
sprintf(y, "%d/%d: '%s'", errorResultCounter, updateResults, updatePieces[errorResultCounter]);
writeSerialPortDebug(boutRefNum, y);
}
#endif
continue;
}
if (prefix((char *)updatePieces[1], (char *)chatUpdate[0])) {
#ifdef MESSAGES_FOR_MACINTOSH_DEBUGGING
writeSerialPortDebug(boutRefNum, "match1");
writeSerialPortDebug(boutRefNum, chatUpdate[0]);
#endif
if (count == 0 || !strcmp(activeChat, (char *)chatUpdate[0])) {
sprintf(chatFriendlyNames[i], "%.63s", (char *)chatUpdate[0]);
} else {
sprintf(chatFriendlyNames[i], "(%d new) %.63s", count, (char *)chatUpdate[0]);
}
break;
}
} else if (prefix(chatFriendlyNames[i], (char *)chatUpdate[0])) {
if (updateResults != 2) {
#ifdef MESSAGES_FOR_MACINTOSH_DEBUGGING
writeSerialPortDebug(boutRefNum, "match2");
char x[255];
sprintf(x, "ERROR: individual chat update mismatch splitting on ' new) ', expected 2 results, got: %d: %s -- bailing out", updateResults, chatName);
writeSerialPortDebug(boutRefNum, x);
for (int errorResultCounter = 0; errorResultCounter < updateResults; errorResultCounter++) {
char y[255];
sprintf(y, "%d/%d: '%s'", errorResultCounter, updateResults, updatePieces[errorResultCounter]);
writeSerialPortDebug(boutRefNum, y);
}
#endif
continue;
}
if (prefix((char *)updatePieces[1], (char *)chatUpdate[0])) {
#ifdef MESSAGES_FOR_MACINTOSH_DEBUGGING
writeSerialPortDebug(boutRefNum, "match1");
writeSerialPortDebug(boutRefNum, chatUpdate[0]);
#endif
@ -413,16 +406,28 @@ void getChatCounts() {
}
break;
}
} else if (prefix(chatFriendlyNames[i], (char *)chatUpdate[0])) {
#ifdef MESSAGES_FOR_MACINTOSH_DEBUGGING
writeSerialPortDebug(boutRefNum, "match2");
writeSerialPortDebug(boutRefNum, chatUpdate[0]);
#endif
if (count == 0 || !strcmp(activeChat, (char *)chatUpdate[0])) {
sprintf(chatFriendlyNames[i], "%.63s", (char *)chatUpdate[0]);
} else {
sprintf(chatFriendlyNames[i], "(%d new) %.63s", count, (char *)chatUpdate[0]);
}
break;
}
}
strcpy(previousChatCountFunctionResponse, chatCountFunctionResponse);
forceRedraw = 3;
} else {
writeSerialPortDebug(boutRefNum, "no need to update current chat count");
}
strcpy(previousChatCountFunctionResponse, chatCountFunctionResponse);
forceRedraw = 3;
return;
}
@ -446,9 +451,6 @@ void getHasNewMessagesInChat(char *thread) {
writeSerialPortDebug(boutRefNum, "update current chat");
SysBeep(1);
getMessages(thread, 0);
// force redraw
forceRedraw = 3;
} else {
writeSerialPortDebug(boutRefNum, "do not update current chat");

View File

@ -451,16 +451,16 @@ NK_API NkQuickDrawFont* nk_quickdraw_font_create_from_file() {
}
// used for bounds checking
int mostLeft = 1;
int mostLeft = WINDOW_WIDTH;
int mostBottom = 1;
int mostTop = WINDOW_HEIGHT;
int mostRight = WINDOW_WIDTH;
int mostRight = 1;
void updateBounds(int top, int bottom, int left, int right) {
#ifdef DEBUG_FUNCTION_CALLS
// #ifdef DEBUG_FUNCTION_CALLS
writeSerialPortDebug(boutRefNum, "DEBUG_FUNCTION_CALLS: updateBounds");
#endif
// #endif
if (left < mostLeft) {
@ -481,6 +481,7 @@ void updateBounds(int top, int bottom, int left, int right) {
mostBottom = bottom;
}
writeSerialPortDebug(boutRefNum, "END OF DEBUG_FUNCTION_CALLS: updateBounds");
}
#ifdef COMMAND_CACHING
@ -1181,10 +1182,10 @@ NK_API void nk_quickdraw_render(WindowPtr window, struct nk_context *ctx) {
CopyBits(&gMainOffScreen.bits->portBits, &window->portBits, &quickDrawRectangle, &quickDrawRectangle, srcCopy, 0L);
mostLeft = 1;
mostLeft = WINDOW_WIDTH;
mostBottom = 1;
mostTop = WINDOW_HEIGHT;
mostRight = WINDOW_WIDTH;
mostRight = 1;
#ifdef PROFILING
PROFILE_END("copy bits");