//------------------------------------------------------------------------------ void UpdateNode (pNPnode node, pData dataRef) { if (node->freeze) //do not update if frozen return; switch (node->type) //types organized to optimize switch statement speed { case kNodePin : UpdateNodePin (node, dataRef); break; case kNodeLink : UpdateNodeDefault (node, dataRef); break; case kNodeDefault : UpdateNodeDefault (node, dataRef); break; case kNodeCamera : UpdateNodeCamera (node, dataRef); break; case kNodeVideo : UpdateNodeVideo (node, dataRef); break; case kNodeSurface : UpdateNodeSurface (node, dataRef); break; case kNodePoints : UpdateNodePoints (node, dataRef); break; case kNodeGrid : UpdateNodeGrid (node, dataRef); break; case kNodeHUD : break; default : npPostMsg("err 2559 - unknown node type", kNPmsgErr, dataRef); } }
//zzd r void* npShowDatabases(int dbID, struct dbFunction *db, void* dataRef ) { char* statement = NULL; void* error = NULL; statement = (*db->StatementShow)("DATABASES"); if( statement ) { printf("query: %s\n", statement); error = (*db->query)(dbID, statement); if( error ) printf( "err 5572 - failed DB query statement", kNPmsgErr, dataRef ); free(statement); } else npPostMsg("err 5573 - failed DB StatementShow", kNPmsgErr, dataRef ); return error; }
//zz modified to generate a single null terminated string if str == NULL //JJ---------------------------------------------------------------------------- char* npNewStrcpy (const char* str, void* dataRef) { char* result = NULL; if (str == NULL) { result = malloc (1); *result = '\0'; return result; } result = (char*) malloc (strlen(str) + 1); if (result == NULL) { npPostMsg ("err 4299 - malloc failed, npNewStrcpy\n", kNPmsgErr, dataRef); return NULL; } strcpy (result, str); return result; }
//----------------------------------------------------------------------------- FILE* openFileDialog (const char* fileName, int dialogType, void* dataRef) { //zz-osx debug FILE* filePtr = NULL; NavDialogCreationOptions dialogOptions; NavDialogRef dialog; NavReplyRecord replyRecord; CFURLRef fileAsCFURLRef = NULL; FSRef fileAsFSRef; OSStatus status; bool result = false; unsigned char filePath[1024]; char msg[4096]; // Get the standard set of defaults status = NavGetDefaultDialogCreationOptions (&dialogOptions); require_noerr( status, CantGetNavOptions ); // Make the window app-wide modal dialogOptions.modality = kWindowModalityAppModal; // dialogOptions.location = fileName; // Create the dialog status = NavCreateGetFileDialog (&dialogOptions, NULL, NULL, NULL, NULL, NULL, &dialog); require_noerr( status, CantCreateDialog ); // Show it status = NavDialogRun (dialog); require_noerr( status, CantRunDialog ); // Get the reply status = NavDialogGetReply (dialog, &replyRecord); require( ((status == noErr) || (status == userCanceledErr)), CantGetReply ); // If the user clicked "Cancel", just bail if ( status == userCanceledErr ) goto UserCanceled; // Get the file status = AEGetNthPtr ( &(replyRecord.selection), 1, typeFSRef, NULL, NULL, &fileAsFSRef, sizeof(FSRef), NULL); require_noerr( status, CantExtractFSRef ); // Convert it to a CFURL fileAsCFURLRef = CFURLCreateFromFSRef(NULL, &fileAsFSRef); result = CFURLGetFileSystemRepresentation(fileAsCFURLRef, true, filePath, 1024); if (!result) npPostMsg("err 9824 - cannot convert file dialog path", kNPmsgErr, dataRef); else { // printf ("\nFile Path: %s\n", filePath); sprintf (msg, "%s", filePath); filePtr = fopen (msg, "r"); if (filePtr != NULL) { sprintf (msg, "File Open: %s", filePath); npPostMsg (msg, kNPmsgCtrl, dataRef); } else npPostMsg ("err 2995 - File Pointer is NULL", kNPmsgErr, dataRef); return filePtr; } // Cleanup CantExtractFSRef: UserCanceled: verify_noerr( NavDisposeReply(&replyRecord) ); CantGetReply: CantRunDialog: NavDialogDispose(dialog); CantCreateDialog: CantGetNavOptions: // return fileAsCFURLRef; //part of original sample, does not apply here return NULL; }
//------------------------------------------------------------------------------ void npInitGlut (int argc, char **argv, void* dataRef) { GLboolean stereoSupport = false; int depth = 0; int result = 0; int gMainWindow = 0; char msg[256]; pData data = (pData) dataRef; pNPgl gl = &data->io.gl; // init glut app framework glutInit (&argc, argv); //zz debug stereo3D not yet supported on OSX //zz debug move OS specific code to npos.h ? nposPostFramework() #ifndef NP_OSX_ sprintf (msg, "freeglut ver: %d", glutGet(GLUT_VERSION)); npPostMsg (msg, kNPmsgCtrl, data); glGetBooleanv (GL_STEREO, (GLboolean*)&gl->stereo3D); #else npPostMsg ("Apple GLUT", kNPmsgCtrl, data); gl->stereo3D = false; #endif if (gl->stereo3D) sprintf (msg, "OpenGL Stereo 3D: YES"); else sprintf (msg, "OpenGL Stereo 3D: NO"); npPostMsg (msg, kNPmsgCtrl, data); /// OpenGL stereo 3D is ONLY supported by Quadro and AMD Fire Pro if (gl->stereo3D) glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH | GLUT_STEREO); else glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowPosition (gl->position.x, gl->position.y); glutInitWindowSize (gl->windowSize.x, gl->windowSize.y); gl->windowID = glutCreateWindow (gl->name); glutSetWindow (gl->windowID); //S3D glutHideWindow(); //S3D //zz stereo 3D and GameMode stripped out on 2016-07-03 /// register keyboard, mouse and display events with GLUT npGlutEventFuncs(); /// init OpenGL npInitGL (dataRef); /// show the window glutShowWindow (); if (gl->fullscreen) { npPostMsg ("FullScreen Window", kNPmsgCtrl, data); glutFullScreen (); } /// System Ready... data->ctrl.startup = false; npPostMsg( "www.openANTz.com", kNPmsgCtrl, data); npPostMsg( "System Ready...", kNPmsgCtrl, data); npPostMsg( data->map.startupMsg, kNPmsgCtrl, data); }
//fullscreen GameMode creates a new GL context //currently requires re-registering event callbacks and re-loading texture maps //------------------------------------------------------------------------------ void npglFullscreen (void* dataRef) { int deltaX = 0, deltaY = 0; int result = 0; //fullscreen window used only if gamemode fails pData data = (pData) dataRef; pNPgl gl = &data->io.gl; if (gl->fullscreen) { if (glutGameModeGet(GLUT_GAME_MODE_ACTIVE) != 0) //stereo 3D { glutLeaveGameMode(); glutSetWindow (gl->windowID); glutShowWindow (); //! register keyboard, mouse and display events with GLUT npGlutEventFuncs(); npInitGL (data); } //exit fullscreen and restore previous window position gl->fullscreen = false; glutReshapeWindow (gl->windowSize.x, gl->windowSize.y); glutPositionWindow (gl->position.x, gl->position.y); //correct for window border offset, glut workaround deltaX = gl->position.x - glutGet((GLenum)GLUT_WINDOW_X); deltaY = gl->position.y - glutGet((GLenum)GLUT_WINDOW_Y); if (deltaX != 0 || deltaY != 0) glutPositionWindow (gl->position.x + deltaX, gl->position.y + deltaY); npPostMsg("Exit FullScreen", kNPmsgGL, data); } else { /* glutSetWindow ( gl->windowID); glutHideWindow (); //Game Mode with stereo 3D if (gl->stereo3D) glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_STEREO); // stereo display mode for glut else glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH); //stereo 3D and GameMode printf("Attempting Game Mode, please ignore GLUT warnings\n"); glutGameModeString("1920x1080:32@121"); if ( glutEnterGameMode() == 0 ) { glutGameModeString("1920x1080:32@120"); if ( glutEnterGameMode() == 0 ) { glutGameModeString("1920x1080:32@119"); if ( glutEnterGameMode() == 0 ) { glutGameModeString("1920x1080:32@60"); //does not specify refresh result = ( glutEnterGameMode() ); }}} */ gl->position.x = glutGet((GLenum)GLUT_WINDOW_X); gl->position.y = glutGet((GLenum)GLUT_WINDOW_Y); gl->windowSize.x = gl->width; gl->windowSize.y = gl->height; if (result == 0) //fullscreen window used only if gamemode fails { printf("FullScreen Window\n"); glutShowWindow (); glutFullScreen (); } else { //GameMode may be different then what we requested, so get the modes glutSetWindowTitle("ANTz - GameMode"); gl->width = glutGameModeGet( GLUT_GAME_MODE_WIDTH ); gl->height = glutGameModeGet( GLUT_GAME_MODE_HEIGHT ); gl->pixelDepth = glutGameModeGet( GLUT_GAME_MODE_PIXEL_DEPTH ); gl->refreshRate = (float)glutGameModeGet( GLUT_GAME_MODE_REFRESH_RATE ); printf("FullScreen Game Mode: %dx%d:%d@%d\n", gl->width, gl->height, gl->pixelDepth, (int)gl->refreshRate); } gl->fullscreen = true; } }