4 extern bool buttons[3];
5 extern float multiplier;
6 extern float screenwidth,screenheight;
8 extern float realmultiplier;
10 extern bool ismotionblur;
11 extern float usermousesensitivity;
13 extern bool floatjump;
14 extern bool cellophane;
15 extern int terraindetail;
17 extern int bloodtoggle;
19 extern bool autoslomo;
21 extern bool musictoggle;
22 extern bool trilinear;
23 extern float gamespeed;
24 extern int difficulty;
25 extern bool damageeffects;
26 extern int numplayers;
28 extern bool invertmouse;
29 extern bool texttoggle;
30 extern bool ambientsound;
31 extern bool mousejump;
33 extern Person player[maxplayers];
35 extern bool stillloading;
36 extern bool showpoints;
37 extern bool alwaysblur;
38 extern bool immediate;
39 extern bool velocityblur;
40 extern bool debugmode;
42 extern int kBitsPerPixel;
43 extern float slomospeed;
44 extern float slomofreq;
45 extern float oldgamespeed;
47 #define kUseAGLFullScreenX 1
50 // system includes ----------------------------------------------------------
53 #include "Carbon Include.h"
54 #include <Carbon/Carbon.h>
56 #include <DrawSprocket/DrawSprocket.h>
58 #include <AGL/aglRenderers.h>
59 #include <OpenGL/gl.h>
60 #include <OpenGL/glu.h>
62 #include <DrawSprocket.h>
66 #include <DriverServices.h>
72 #include <ToolUtils.h>
89 // project includes ---------------------------------------------------------
91 #include "aglString.h"
94 // functions (internal/private) ---------------------------------------------
96 static UInt32 CheckMacOSX (void);
97 void CToPStr (StringPtr outString, const char *inString);
98 void ReportError (char * strError);
99 OSStatus DSpDebugStr (OSStatus error);
100 GLenum aglDebugStr (void);
101 GLenum glDebugStr (void);
103 CGrafPtr SetupDSpFullScreen (GDHandle hGD);
104 void ShutdownDSp (CGrafPtr pDSpPort);
106 AGLContext SetupAGL (GDHandle hGD, AGLDrawable win);
107 AGLContext SetupAGLFullScreen (GDHandle display, short * pDepth, short * pWidth, short * pHeight);
108 void CleanupAGL (AGLContext ctx);
109 void DrawGL (Rect * pRectPort);
111 void InitToolbox(void);
112 void CreateGLWindow (void);
113 Boolean SetUp (void);
114 void DoMenu (SInt32 menuResult);
115 void DoKey (SInt8 theKey, SInt8 theCode);
116 void DoUpdate (void);
118 pascal void IdleTimer (EventLoopTimerRef inTimer, void* userData);
119 EventLoopTimerUPP GetTimerUPP (void);
120 static Boolean RunningOnCarbonX(void);
126 Boolean WaitNextEventWrapper (EventMask eventMask, EventRecord *theEvent, unsigned long sleep,RgnHandle mouseRgn);
127 OSStatus DSpProcessEventWrapper (EventRecord *inEvent, Boolean *outEventWasProcessed);
128 void UpdateWrapper (EventRecord *theEvent);
130 // statics/globals (internal only) ------------------------------------------
146 kForegroundSleep = 10,
147 kBackgroundSleep = 10000
149 EventLoopTimerRef gTimer = NULL;
154 const RGBColor rgbBlack = { 0x0000, 0x0000, 0x0000 };
156 NumVersion gVersionDSp;
157 DSpContextAttributes gContextAttributes;
158 DSpContextReference gContext = 0;
159 extern AGLContext gaglContext;
161 char gcstrMode [256] = "";
163 AGLDrawable gpDSpPort = NULL; // will be NULL for full screen under X
164 Rect gRectPort = {0, 0, 0, 0};
166 UInt32 gSleepTime = kForegroundSleep;
167 Boolean gDone = false, gfFrontProcess = true;
173 OSErr gProfErr = noErr;
178 //-----------------------------------------------------------------------------------------------------------------------
180 // are we running on Mac OS X
181 // returns 0 if < Mac OS X or version number of Mac OS X (10.0 for GM)
183 static UInt32 CheckMacOSX (void)
187 if ((Gestalt(gestaltSystemVersion, (SInt32 *) &response) == noErr) && (response >= 0x01000))
193 //-----------------------------------------------------------------------------------------------------------------------
195 // Copy C string to Pascal string
197 void CToPStr (StringPtr outString, const char *inString)
201 *(((char*)outString) + x + 1) = *(inString + x++);
202 while ((*(inString + x) != 0) && (x < 256));
203 *((char*)outString) = (char) x;
206 // --------------------------------------------------------------------------
208 void ReportError (char * strError)
210 char errMsgCStr [256];
213 sprintf (errMsgCStr, "%s", strError);
215 // out as debug string
216 CToPStr (strErr, errMsgCStr);
220 //-----------------------------------------------------------------------------------------------------------------------
222 OSStatus DSpDebugStr (OSStatus error)
228 case kDSpNotInitializedErr:
229 ReportError ("DSp Error: Not initialized");
231 case kDSpSystemSWTooOldErr:
232 ReportError ("DSp Error: system Software too old");
234 case kDSpInvalidContextErr:
235 ReportError ("DSp Error: Invalid context");
237 case kDSpInvalidAttributesErr:
238 ReportError ("DSp Error: Invalid attributes");
240 case kDSpContextAlreadyReservedErr:
241 ReportError ("DSp Error: Context already reserved");
243 case kDSpContextNotReservedErr:
244 ReportError ("DSp Error: Context not reserved");
246 case kDSpContextNotFoundErr:
247 ReportError ("DSp Error: Context not found");
249 case kDSpFrameRateNotReadyErr:
250 ReportError ("DSp Error: Frame rate not ready");
252 case kDSpConfirmSwitchWarning:
253 // ReportError ("DSp Warning: Must confirm switch"); // removed since it is just a warning, add back for debugging
254 return 0; // don't want to fail on this warning
256 case kDSpInternalErr:
257 ReportError ("DSp Error: Internal error");
259 case kDSpStereoContextErr:
260 ReportError ("DSp Error: Stereo context");
266 //-----------------------------------------------------------------------------------------------------------------------
268 // if error dump agl errors to debugger string, return error
270 GLenum aglDebugStr (void)
272 GLenum err = aglGetError();
273 if (AGL_NO_ERROR != err)
274 ReportError ((char *)aglErrorString(err));
278 //-----------------------------------------------------------------------------------------------------------------------
280 // if error dump agl errors to debugger string, return error
282 GLenum glDebugStr (void)
284 GLenum err = glGetError();
285 if (GL_NO_ERROR != err)
286 ReportError ((char *)gluErrorString(err));
291 //-----------------------------------------------------------------------------------------------------------------------
293 // Set up DSp screen on graphics device requested
294 // side effect: sets both gpDSpWindow and gpPort
296 CGrafPtr SetupDSpFullScreen (GDHandle hGD)
298 DSpContextAttributes foundAttributes;
299 DisplayIDType displayID = NULL;
301 if ((Ptr) kUnresolvedCFragSymbolAddress == (Ptr) DSpGetVersion)
303 ReportError ("DrawSprocket not installed.");
307 gVersionDSp = DSpGetVersion ();
309 if ((gVersionDSp.majorRev == 0x01) && (gVersionDSp.minorAndBugRev < 0x99))
311 // this version of DrawSprocket is not completely functional on Mac OS X
314 ReportError ("DrawSprocket 1.99 or greate required on Mac OS X, please update to at least Mac OS X 10.1.");
319 // Note: DSp < 1.7.3 REQUIRES the back buffer attributes even if only one buffer is required
320 memset(&gContextAttributes, 0, sizeof (DSpContextAttributes));
321 gContextAttributes.displayWidth = kContextWidth;
322 gContextAttributes.displayHeight = kContextHeight;
323 gContextAttributes.colorNeeds = kDSpColorNeeds_Require;
324 gContextAttributes.displayBestDepth = kBitsPerPixel;
325 gContextAttributes.backBufferBestDepth = kBitsPerPixel;
326 gContextAttributes.displayDepthMask = kDSpDepthMask_All;
327 gContextAttributes.backBufferDepthMask = kDSpDepthMask_All;
328 gContextAttributes.pageCount = 1; // only the front buffer is needed
330 screenwidth=kContextWidth;
331 screenheight=kContextHeight;
333 DMGetDisplayIDByGDevice (hGD, &displayID, true);
335 if (noErr != DSpDebugStr (DSpFindBestContextOnDisplayID (&gContextAttributes, &gContext, displayID)))
337 ReportError ("DSpFindBestContext() had an error.");
341 if (noErr != DSpDebugStr (DSpContext_GetAttributes (gContext, &foundAttributes))) // see what we actually found
343 ReportError ("DSpContext_GetAttributes() had an error.");
347 // reset width and height to full screen and handle our own centering
348 // HWA will not correctly center less than full screen size contexts
349 gContextAttributes.displayWidth = foundAttributes.displayWidth;
350 gContextAttributes.displayHeight = foundAttributes.displayHeight;
351 gContextAttributes.pageCount = 1; // only the front buffer is needed
352 gContextAttributes.contextOptions = 0 | kDSpContextOption_DontSyncVBL; // no page flipping and no VBL sync needed
354 DSpSetBlankingColor(&rgbBlack);
356 if (noErr != DSpDebugStr (DSpContext_Reserve ( gContext, &gContextAttributes))) // reserve our context
358 ReportError ("DSpContext_Reserve() had an error.");
364 if (noErr != DSpDebugStr (DSpContext_SetState (gContext, kDSpContextState_Active))) // activate our context
366 ReportError ("DSpContext_SetState() had an error.");
371 if ((CheckMacOSX ()) && !((gVersionDSp.majorRev > 0x01) || ((gVersionDSp.majorRev == 0x01) && (gVersionDSp.minorAndBugRev >= 0x99))))// DSp should be supported in version after 1.98
373 ReportError ("Mac OS X with DSp < 1.99 does not support DrawSprocket for OpenGL full screen");
376 else if (CheckMacOSX ()) // DSp should be supported in versions 1.99 and later
379 // use DSp's front buffer on Mac OS X
380 if (noErr != DSpDebugStr (DSpContext_GetFrontBuffer (gContext, &pPort)))
382 ReportError ("DSpContext_GetFrontBuffer() had an error.");
385 // there is a problem in Mac OS X 10.0 GM CoreGraphics that may not size the port pixmap correctly
386 // this will check the vertical sizes and offset if required to fix the problem
387 // this will not center ports that are smaller then a particular resolution
391 PixMapHandle hPix = GetPortPixMap (pPort);
392 Rect pixBounds = (**hPix).bounds;
393 GetPortBounds (pPort, &portBounds);
394 deltaV = (portBounds.bottom - portBounds.top) - (pixBounds.bottom - pixBounds.top) +
395 (portBounds.bottom - portBounds.top - kContextHeight) / 2;
396 deltaH = -(portBounds.right - portBounds.left - kContextWidth) / 2;
397 if (deltaV || deltaH)
400 GetPort (&pPortSave);
401 SetPort ((GrafPtr)pPort);
402 // set origin to account for CG offset and if requested drawable smaller than screen rez
403 SetOrigin (deltaH, deltaV);
409 else // Mac OS 9 or less
415 // create a new window in our context
416 // note: OpenGL is expecting a window so it can enumerate the devices it spans,
417 // center window in our context's gdevice
418 rectWin.top = (short) ((**hGD).gdRect.top + ((**hGD).gdRect.bottom - (**hGD).gdRect.top) / 2); // h center
419 rectWin.top -= (short) (kContextHeight / 2);
420 rectWin.left = (short) ((**hGD).gdRect.left + ((**hGD).gdRect.right - (**hGD).gdRect.left) / 2); // v center
421 rectWin.left -= (short) (kContextWidth / 2);
422 rectWin.right = (short) (rectWin.left + kContextWidth);
423 rectWin.bottom = (short) (rectWin.top + kContextHeight);
425 pWindow = NewCWindow (NULL, &rectWin, "\p", 0, plainDBox, (WindowPtr)-1, 0, 0);
427 // paint back ground black before fade in to avoid white background flash
429 GetPort (&pGrafSave);
430 SetPortWindowPort (pWindow);
431 GetForeColor (&rgbSave);
432 RGBForeColor (&rgbBlack);
435 GetWindowPortBounds (pWindow, &paintRect);
436 PaintRect (&paintRect);
438 RGBForeColor (&rgbSave); // ensure color is reset for proper blitting
440 return (GetWindowPort (pWindow));
444 //-----------------------------------------------------------------------------------------------------------------------
448 void ShutdownDSp (CGrafPtr pDSpPort)
450 if ((NULL != pDSpPort) && !CheckMacOSX ())
451 DisposeWindow (GetWindowFromPort (pDSpPort));
452 DSpContext_SetState( gContext, kDSpContextState_Inactive);
453 DSpContext_Release (gContext);
457 //-----------------------------------------------------------------------------------------------------------------------
462 AGLContext SetupAGL (GDHandle hGD, AGLDrawable drawable)
469 // different possible pixel format choices for different renderers
470 // basics requirements are RGBA and double buffer
471 // OpenGLz will select acclerated context if available
474 attrib [i++] = AGL_RGBA; // red green blue and alpha
475 attrib [i++] = AGL_DOUBLEBUFFER; // double buffered
476 attrib [i++] = AGL_DEPTH_SIZE;
478 attrib [i++] = AGL_ACCELERATED; // HWA pixel format only
479 attrib [i++] = AGL_NONE;
481 if ((Ptr) kUnresolvedCFragSymbolAddress == (Ptr) aglChoosePixelFormat) // check for existance of OpenGL
483 ReportError ("OpenGL not installed");
488 fmt = aglChoosePixelFormat (&hGD, 1, attrib); // get an appropriate pixel format
490 fmt = aglChoosePixelFormat(NULL, 0, attrib); // get an appropriate pixel format
494 ReportError("Could not find valid pixel format");
498 ctx = aglCreateContext (fmt, NULL); // Create an AGL context
502 ReportError ("Could not create context");
506 if (!aglSetDrawable (ctx, drawable)) // attach the window to the context
508 ReportError ("SetDrawable failed");
514 if (!aglSetCurrentContext (ctx)) // make the context the current context
517 aglSetDrawable (ctx, NULL);
521 aglDestroyPixelFormat(fmt); // pixel format is no longer needed
526 //-----------------------------------------------------------------------------------------------------------------------
530 AGLContext SetupAGLFullScreen (GDHandle display, short * pDepth, short * pWidth, short * pHeight)
533 GLint attrib[] ={AGL_RGBA, AGL_DOUBLEBUFFER,AGL_DEPTH_SIZE, 16, AGL_FULLSCREEN,AGL_ALL_RENDERERS, AGL_NONE};
539 if ((Ptr) kUnresolvedCFragSymbolAddress == (Ptr) aglChoosePixelFormat) // check for existance of OpenGL
541 ReportError ("OpenGL not installed");
545 fmt = aglChoosePixelFormat(&display, 1, attrib); // this may fail if looking for acclerated across multiple monitors
548 ReportError("Could not find valid pixel format");
553 ctx = aglCreateContext (fmt, NULL); // Create an AGL context
556 ReportError ("Could not create context");
561 if (!aglSetFullScreen (ctx, *pWidth, *pHeight, 60, 0))
563 ReportError ("SetFullScreen failed");
568 if (!aglSetCurrentContext (ctx)) // make the context the current context
570 ReportError ("SetCurrentContext failed");
572 aglSetDrawable (ctx, NULL); // turn off full screen
576 aglDestroyPixelFormat(fmt); // pixel format is no longer needed
581 //-----------------------------------------------------------------------------------------------------------------------
585 void CleanupAGL(AGLContext ctx)
587 aglSetDrawable (ctx, NULL);
588 aglSetCurrentContext (NULL);
589 aglDestroyContext (ctx);
592 //-----------------------------------------------------------------------------------------------------------------------
596 void DrawGL (Rect * pRectPort)
598 if (gaglContext == 0)
600 aglSetCurrentContext (gaglContext); // ensure our context is current prior to drawing
603 GLint width = pRectPort->right - pRectPort->left;
604 GLint height = pRectPort->bottom - pRectPort->top;
607 /* glViewport ((width - (width * 1)) / 2, (height - (height * 1)) / 2,
608 width * 1, height * 1);*/
619 glViewport (0, 0, pRectPort->right - pRectPort->left, pRectPort->bottom - pRectPort->top);
620 glGetIntegerv (GL_MATRIX_MODE, &matrixMode);
621 glMatrixMode (GL_PROJECTION);
624 glMatrixMode (GL_MODELVIEW);
627 glScalef (2.0 / (pRectPort->right - pRectPort->left), -2.0 / (pRectPort->bottom - pRectPort->top), 1.0);
628 glTranslatef (-(pRectPort->right - pRectPort->left) / 2.0, -(pRectPort->bottom - pRectPort->top) / 2.0, 0.0);
629 glColor3f (1.0, 1.0, 1.0);
630 glRasterPos3d (10, 12, 0);
631 DrawFrameRate (gFontList);
632 glRasterPos3d (10, 24, 0);
633 DrawCStringGL (gcstrMode, gFontList);
634 glRasterPos3d (10, (pRectPort->bottom - pRectPort->top) - 15, 0);
635 DrawCStringGL ((char*) glGetString (GL_VENDOR), gFontList);
636 glRasterPos3d (10, (pRectPort->bottom - pRectPort->top) - 3, 0);
637 DrawCStringGL ((char*) glGetString (GL_RENDERER), gFontList);
638 static char aChar[256] = "";
639 sprintf (aChar, " Mac OS X: %d", RunningOnCarbonX());
640 DrawCStringGL (aChar, gFontList);
642 glMatrixMode (GL_PROJECTION);
644 glMatrixMode (matrixMode);
647 //aglSwapBuffers(gaglContext); // send swap command
651 //-----------------------------------------------------------------------------------------------------------------------
653 static pascal OSErr QuitAppleEventHandler( const AppleEvent *appleEvt, AppleEvent* reply, SInt32 refcon )
655 #pragma unused (appleEvt, reply, refcon)
661 //-----------------------------------------------------------------------------------------------------------------------
663 void InitToolbox(void)
674 // ProfilerInit (collection method, time base, num funcs, stack depth)
676 gProfErr = ProfilerInit (collectDetailed, bestTimeBase, 20, 10); // set up profiling
677 // something that you may need to do (may need more memory)
678 // gProfErr = ProfilerInit (collectSummary, bestTimeBase, 1000, 100); // set up profiling
679 // Note: application will likely run slower, but still should be useful info
680 if (noErr == gProfErr)
681 ProfilerSetStatus(FALSE);
685 menu = NewMenu (kMenuApple, "\p\024"); // new apple menu
686 InsertMenu (menu, 0); // add menu to end
688 menu = NewMenu (kMenuFile, "\pFile"); // new menu
689 InsertMenu (menu, 0); // add menu to end
691 // insert application menus here
693 // add quit if not under Mac OS X
694 err = Gestalt (gestaltMenuMgrAttr, &response);
695 if ((err == noErr) && !(response & gestaltMenuMgrAquaLayoutMask))
696 AppendMenu (menu, "\pQuit/Q"); // add quit
699 err = AEInstallEventHandler( kCoreEventClass, kAEQuitApplication, NewAEEventHandlerUPP(QuitAppleEventHandler), 0, false );
704 // --------------------------------------------------------------------------
706 static Point gMidPoint;
712 SetQDGlobalsRandomSeed(TickCount());
715 if(CheckMacOSX ())osx = 1;
716 ifstream ipstream(":Data:config.txt");
719 usermousesensitivity=1;
745 game.crouchkey=MAC_SHIFT_KEY;
746 game.jumpkey=MAC_SPACE_KEY;
747 game.leftkey=MAC_A_KEY;
748 game.forwardkey=MAC_W_KEY;
749 game.backkey=MAC_S_KEY;
750 game.rightkey=MAC_D_KEY;
751 game.drawkey=MAC_E_KEY;
752 game.throwkey=MAC_Q_KEY;
753 game.attackkey=MAC_MOUSEBUTTON1;
754 game.chatkey=MAC_T_KEY;
760 ofstream opstream(":Data:config.txt");
761 opstream << "Screenwidth:\n";
762 opstream << kContextWidth;
763 opstream << "\nScreenheight:\n";
764 opstream << kContextHeight;
765 opstream << "\nMouse sensitivity:\n";
766 opstream << usermousesensitivity;
767 opstream << "\nBlur(0,1):\n";
768 opstream << ismotionblur;
769 opstream << "\nOverall Detail(0,1,2) higher=better:\n";
771 opstream << "\nFloating jump:\n";
772 opstream << floatjump;
773 opstream << "\nMouse jump:\n";
774 opstream << mousejump;
775 opstream << "\nAmbient sound:\n";
776 opstream << ambientsound;
777 opstream << "\nBlood (0,1,2):\n";
778 opstream << bloodtoggle;
779 opstream << "\nAuto slomo:\n";
780 opstream << autoslomo;
781 opstream << "\nFoliage:\n";
783 opstream << "\nMusic:\n";
784 opstream << musictoggle;
785 opstream << "\nTrilinear:\n";
786 opstream << trilinear;
787 opstream << "\nDecals(shadows,blood puddles,etc):\n";
789 opstream << "\nInvert mouse:\n";
790 opstream << invertmouse;
791 opstream << "\nGamespeed:\n";
792 opstream << gamespeed;
793 opstream << "\nDifficulty(0,1,2) higher=harder:\n";
794 opstream << difficulty;
795 opstream << "\nDamage effects(blackout, doublevision):\n";
796 opstream << damageeffects;
797 opstream << "\nText:\n";
798 opstream << texttoggle;
799 opstream << "\nDebug:\n";
800 opstream << debugmode;
801 opstream << "\nVBL Sync:\n";
803 opstream << "\nShow Points:\n";
804 opstream << showpoints;
805 opstream << "\nAlways Blur:\n";
806 opstream << alwaysblur;
807 opstream << "\nImmediate mode (turn on on G5):\n";
808 opstream << immediate;
809 opstream << "\nVelocity blur:\n";
810 opstream << velocityblur;
811 opstream << "\nForward key:\n";
812 opstream << KeyToChar(game.forwardkey);
813 opstream << "\nBack key:\n";
814 opstream << KeyToChar(game.backkey);
815 opstream << "\nLeft key:\n";
816 opstream << KeyToChar(game.leftkey);
817 opstream << "\nRight key:\n";
818 opstream << KeyToChar(game.rightkey);
819 opstream << "\nJump key:\n";
820 opstream << KeyToChar(game.jumpkey);
821 opstream << "\nCrouch key:\n";
822 opstream << KeyToChar(game.crouchkey);
823 opstream << "\nDraw key:\n";
824 opstream << KeyToChar(game.drawkey);
825 opstream << "\nThrow key:\n";
826 opstream << KeyToChar(game.throwkey);
827 opstream << "\nAttack key:\n";
828 opstream << KeyToChar(game.attackkey);
829 opstream << "\nChat key:\n";
830 opstream << KeyToChar(game.chatkey);
834 ipstream.ignore(256,'\n');
835 ipstream >> kContextWidth;
836 ipstream.ignore(256,'\n');
837 ipstream.ignore(256,'\n');
838 ipstream >> kContextHeight;
839 ipstream.ignore(256,'\n');
840 ipstream.ignore(256,'\n');
841 ipstream >> usermousesensitivity;
842 ipstream.ignore(256,'\n');
843 ipstream.ignore(256,'\n');
844 ipstream >> ismotionblur;
845 ipstream.ignore(256,'\n');
846 ipstream.ignore(256,'\n');
848 if(detail!=0)kBitsPerPixel=32;
849 else kBitsPerPixel=16;
850 ipstream.ignore(256,'\n');
851 ipstream.ignore(256,'\n');
852 ipstream >> floatjump;
853 ipstream.ignore(256,'\n');
854 ipstream.ignore(256,'\n');
855 ipstream >> mousejump;
856 ipstream.ignore(256,'\n');
857 ipstream.ignore(256,'\n');
858 ipstream >> ambientsound;
859 ipstream.ignore(256,'\n');
860 ipstream.ignore(256,'\n');
861 ipstream >> bloodtoggle;
862 ipstream.ignore(256,'\n');
863 ipstream.ignore(256,'\n');
864 ipstream >> autoslomo;
865 ipstream.ignore(256,'\n');
866 ipstream.ignore(256,'\n');
868 ipstream.ignore(256,'\n');
869 ipstream.ignore(256,'\n');
870 ipstream >> musictoggle;
871 ipstream.ignore(256,'\n');
872 ipstream.ignore(256,'\n');
873 ipstream >> trilinear;
874 ipstream.ignore(256,'\n');
875 ipstream.ignore(256,'\n');
877 ipstream.ignore(256,'\n');
878 ipstream.ignore(256,'\n');
879 ipstream >> invertmouse;
880 ipstream.ignore(256,'\n');
881 ipstream.ignore(256,'\n');
882 ipstream >> gamespeed;
883 oldgamespeed=gamespeed;
888 ipstream.ignore(256,'\n');
889 ipstream.ignore(256,'\n');
890 ipstream >> difficulty;
891 ipstream.ignore(256,'\n');
892 ipstream.ignore(256,'\n');
893 ipstream >> damageeffects;
894 ipstream.ignore(256,'\n');
895 ipstream.ignore(256,'\n');
896 ipstream >> texttoggle;
897 ipstream.ignore(256,'\n');
898 ipstream.ignore(256,'\n');
899 ipstream >> debugmode;
900 ipstream.ignore(256,'\n');
901 ipstream.ignore(256,'\n');
903 ipstream.ignore(256,'\n');
904 ipstream.ignore(256,'\n');
905 ipstream >> showpoints;
906 ipstream.ignore(256,'\n');
907 ipstream.ignore(256,'\n');
908 ipstream >> alwaysblur;
909 ipstream.ignore(256,'\n');
910 ipstream.ignore(256,'\n');
911 ipstream >> immediate;
912 ipstream.ignore(256,'\n');
913 ipstream.ignore(256,'\n');
914 ipstream >> velocityblur;
915 ipstream.ignore(256,'\n');
916 ipstream.ignore(256,'\n');
918 game.forwardkey=CharToKey(string);
919 ipstream.ignore(256,'\n');
920 ipstream.ignore(256,'\n');
922 game.backkey=CharToKey(string);
923 ipstream.ignore(256,'\n');
924 ipstream.ignore(256,'\n');
926 game.leftkey=CharToKey(string);
927 ipstream.ignore(256,'\n');
928 ipstream.ignore(256,'\n');
930 game.rightkey=CharToKey(string);
931 ipstream.ignore(256,'\n');
932 ipstream.ignore(256,'\n');
934 game.jumpkey=CharToKey(string);
935 ipstream.ignore(256,'\n');
936 ipstream.ignore(256,'\n');
938 game.crouchkey=CharToKey(string);
939 ipstream.ignore(256,'\n');
940 ipstream.ignore(256,'\n');
942 game.drawkey=CharToKey(string);
943 ipstream.ignore(256,'\n');
944 ipstream.ignore(256,'\n');
946 game.throwkey=CharToKey(string);
947 ipstream.ignore(256,'\n');
948 ipstream.ignore(256,'\n');
950 game.attackkey=CharToKey(string);
951 ipstream.ignore(256,'\n');
952 ipstream.ignore(256,'\n');
954 game.chatkey=CharToKey(string);
957 if(detail>2)detail=2;
958 if(detail<0)detail=0;
959 if(screenwidth>3000)screenwidth=640;
960 if(screenwidth<0)screenwidth=640;
961 if(screenheight>3000)screenheight=480;
962 if(screenheight<0)screenheight=480;
968 aglSetInteger(gaglContext, AGL_SWAP_INTERVAL, &swapInt);
971 if(kBitsPerPixel!=32&&kBitsPerPixel!=16){
976 GDHandle hGD, hTargetDevice = NULL;
977 short numDevices = 0;
979 short whichDevice = 0; // number of device to try (0 = 1st device)
987 if ((Ptr) kUnresolvedCFragSymbolAddress == (Ptr) DSpStartup)
988 ReportError ("DSp not installed");
990 if (noErr != DSpDebugStr (DSpStartup()))
992 // DSpSetDebugMode (true);
993 #if defined kUseFades
994 DSpDebugStr (DSpContext_FadeGammaOut (NULL, NULL)); // fade display, remove for debug
997 hGD = DMGetFirstScreenDevice (true); // check number of screens
998 hTargetDevice = hGD; // default to first device
1001 if (numDevices == whichDevice)
1002 hTargetDevice = hGD; // if device number matches
1004 hGD = DMGetNextScreenDevice (hGD, true);
1008 #if defined (kUseAGLFullScreenX)
1009 if (CheckMacOSX ()) // Try AGL full screen on Mac OS X
1011 short depth = kBitsPerPixel, width = kContextWidth, height = kContextHeight;
1012 gaglContext = SetupAGLFullScreen (hTargetDevice, &depth, &width, &height); // Setup the OpenGL context
1013 SetRect (&gRectPort, 0, 0, width, height); // l, t, r, b
1014 sprintf (gcstrMode, "AGL Full Screen: %d x %d x %d", width, height, depth);
1017 if (!gaglContext) //try DSp
1019 if (NULL != (gpDSpPort = SetupDSpFullScreen (hTargetDevice))) // Setup DSp for OpenGL sets hTargetDeviceto device actually used
1021 GetPortBounds (gpDSpPort, &gRectPort);
1022 sprintf (gcstrMode, "DrawSprocket Full Screen: %d x %d x %d", gRectPort.right - gRectPort.left, gRectPort.bottom - gRectPort.top, (**(**hTargetDevice).gdPMap).pixelSize);
1023 gaglContext = SetupAGL (hTargetDevice, gpDSpPort);
1028 GetFNum("\pMonaco", &fNum); // build font
1029 gFontList = BuildFontGL (gaglContext, fNum, normal, 9);
1030 //InstallEventLoopTimer (GetCurrentEventLoop(), 0, 0.0001, GetTimerUPP (), 0, &gTimer);
1033 //gMidPoint.h = (gRectPort.left + gRectPort.right)/2;
1034 //gMidPoint.v = (gRectPort.top + gRectPort.bottom)/2;
1038 //aglSetInteger(gaglContext, AGL_SWAP_INTERVAL, &swapInt);
1040 #if defined kUseFades
1041 DSpDebugStr (DSpContext_FadeGammaIn (NULL, NULL));
1048 GLint width = gRectPort.right - gRectPort.left;
1049 GLint height = gRectPort.bottom - gRectPort.top;
1051 screenheight=height;
1053 game.newdetail=detail;
1054 game.newscreenwidth=screenwidth;
1055 game.newscreenheight=screenheight;
1066 static Boolean RunningOnCarbonX(void)
1068 static Boolean first = true;
1069 static Boolean result = false;
1077 result = (Gestalt(gestaltSystemVersion,
1078 (SInt32 *) &response) == noErr)
1079 && (response >= 0x01000);
1084 static OSStatus LoadFrameworkBundle(CFStringRef pFrameworkCFStrRef, CFBundleRef *pFrameworkCFBndlRef)
1087 FSRef frameworksFolderRef;
1091 if (nil == pFrameworkCFBndlRef) return paramErr;
1093 *pFrameworkCFBndlRef = nil;
1098 err = FSFindFolder(kOnAppropriateDisk, kFrameworksFolderType, true, &frameworksFolderRef);
1100 baseURL = CFURLCreateFromFSRef(kCFAllocatorSystemDefault, &frameworksFolderRef);
1101 if (baseURL == nil) {
1102 err = coreFoundationUnknownErr;
1106 bundleURL = CFURLCreateCopyAppendingPathComponent(kCFAllocatorSystemDefault, baseURL, pFrameworkCFStrRef, false);
1107 if (bundleURL == nil) {
1108 err = coreFoundationUnknownErr;
1112 *pFrameworkCFBndlRef = CFBundleCreate(kCFAllocatorSystemDefault, bundleURL);
1113 if (*pFrameworkCFBndlRef == nil) {
1114 err = coreFoundationUnknownErr;
1118 if ( ! CFBundleLoadExecutable( *pFrameworkCFBndlRef ) ) {
1119 err = coreFoundationUnknownErr;
1125 if (err != noErr && *pFrameworkCFBndlRef != nil) {
1126 CFRelease(*pFrameworkCFBndlRef);
1127 *pFrameworkCFBndlRef = nil;
1129 if (bundleURL != nil) {
1130 CFRelease(bundleURL);
1132 if (baseURL != nil) {
1141 static CFragConnectionID gCFragConnectionID = 0;
1143 typedef pascal OSErr (*CDM_NewDeviceProcPtr)(CursorDevicePtr * ourDevice);
1145 static OSErr MyCursorDeviceNewDevice(CursorDevicePtr * ourDevice)
1147 static CDM_NewDeviceProcPtr sCDM_NewDeviceProcPtr = nil;
1148 OSStatus anErr = noErr;
1150 if (nil == ourDevice) return paramErr;
1152 if (!RunningOnCarbonX())
1154 if (!sCDM_NewDeviceProcPtr)
1156 if (!gCFragConnectionID)
1161 anErr = GetSharedLibrary("\pInterfaceLib", kPowerPCCFragArch,
1162 kFindCFrag, &gCFragConnectionID, &mainAddr, errName);
1163 if (noErr != anErr) return anErr;
1166 if (gCFragConnectionID)
1168 CFragSymbolClass symClass;
1170 anErr = FindSymbol(gCFragConnectionID, "\pCrsrDevNewDevice",
1171 (Ptr*) &sCDM_NewDeviceProcPtr, &symClass);
1172 if (noErr != anErr) return anErr;
1175 if (sCDM_NewDeviceProcPtr)
1176 anErr = (*sCDM_NewDeviceProcPtr)(ourDevice);
1184 typedef pascal OSErr (*CDM_CursorDeviceMoveToProcPtr)(
1185 CursorDevicePtr ourDevice,
1189 typedef UInt32 (*CGWarpMouseCursorPositionProcPtr)(CGPoint newCursorPosition);
1190 typedef UInt32 (*CGSetLocalEventsSuppressionIntervalProcPtr)(double pSeconds);
1192 static OSErr MyCursorDeviceMoveTo( CursorDevicePtr ourDevice,
1196 OSStatus anErr = noErr;
1198 if (RunningOnCarbonX())
1200 static CGWarpMouseCursorPositionProcPtr sCGWarpMouseCursorPositionProcPtr = nil;
1202 if (nil == sCGWarpMouseCursorPositionProcPtr)
1204 CFBundleRef tCFBundleRef;
1206 anErr = LoadFrameworkBundle(CFSTR("ApplicationServices.framework"), &tCFBundleRef);
1210 CGSetLocalEventsSuppressionIntervalProcPtr tCGSetLocalEventsSuppressionIntervalProcPtr = nil;
1212 sCGWarpMouseCursorPositionProcPtr = (CGWarpMouseCursorPositionProcPtr)
1213 CFBundleGetFunctionPointerForName( tCFBundleRef, CFSTR("CGWarpMouseCursorPosition") );
1214 if (nil == sCGWarpMouseCursorPositionProcPtr)
1215 anErr = cfragNoSymbolErr;
1217 tCGSetLocalEventsSuppressionIntervalProcPtr = (CGSetLocalEventsSuppressionIntervalProcPtr)
1218 CFBundleGetFunctionPointerForName(tCFBundleRef,CFSTR("CGSetLocalEventsSuppressionInterval"));
1219 if (nil != tCGSetLocalEventsSuppressionIntervalProcPtr)
1220 (*tCGSetLocalEventsSuppressionIntervalProcPtr)(0.0f);
1224 if (nil != sCGWarpMouseCursorPositionProcPtr)
1231 (*sCGWarpMouseCursorPositionProcPtr)(tCGPoint);
1236 static CDM_CursorDeviceMoveToProcPtr sCDM_CursorDeviceMoveToProcPtr = nil;
1238 if (!ourDevice) return paramErr;
1240 if (!sCDM_CursorDeviceMoveToProcPtr)
1242 if (!gCFragConnectionID)
1247 anErr = GetSharedLibrary("\pInterfaceLib", kPowerPCCFragArch,
1248 kFindCFrag, &gCFragConnectionID, &mainAddr, errName);
1249 if (noErr != anErr) return anErr;
1252 if (gCFragConnectionID)
1254 CFragSymbolClass symClass;
1256 anErr = FindSymbol(gCFragConnectionID, "\pCrsrDevMoveTo",
1257 (Ptr*) &sCDM_CursorDeviceMoveToProcPtr, &symClass);
1258 if (noErr != anErr) return anErr;
1261 if (sCDM_CursorDeviceMoveToProcPtr)
1262 anErr = (*sCDM_CursorDeviceMoveToProcPtr)(ourDevice,absX,absY);
1270 static void DoMouse(void)
1272 static CursorDevicePtr virtualCursorDevicePtr = nil;
1273 OSStatus anErr = noErr;
1277 if (nil == virtualCursorDevicePtr)
1278 anErr = MyCursorDeviceNewDevice(&virtualCursorDevicePtr);
1281 static Point lastMouse = {-1,-1};
1284 GetGlobalMouse(&globalMouse);
1286 if (EqualPt(lastMouse, globalMouse))
1292 if (!EqualPt(lastMouse, globalMouse))
1294 static Point virtualMouse = {0,0};
1295 delta = globalMouse;
1297 SubPt(lastMouse, &delta);
1298 GetGlobalMouse(&lastMouse);
1299 //AddPt(delta, &virtualMouse);
1301 if(mainmenu||(abs(delta.h)<10*realmultiplier*1000&&abs(delta.v)<10*realmultiplier*1000)){
1302 game.deltah=delta.h*usermousesensitivity;
1303 game.deltav=delta.v*usermousesensitivity;
1304 game.mousecoordh=globalMouse.h;
1305 game.mousecoordv=globalMouse.v;
1308 //printf("\nMouse Moved: {%d,%d}.",globalMouse.h,globalMouse.v);
1309 //printf("\tdelta: {%d,%d}.",delta.h,delta.v);
1310 //printf("\tvirtual: {%d,%d}.",virtualMouse.h,virtualMouse.v);
1313 if(lastMouse.h>gMidPoint.h+100||lastMouse.h<gMidPoint.h-100||lastMouse.v>gMidPoint.v+100||lastMouse.v<gMidPoint.v-100){
1314 MyCursorDeviceMoveTo(virtualCursorDevicePtr,gMidPoint.h,gMidPoint.v);
1315 lastMouse = gMidPoint;
1322 // --------------------------------------------------------------------------
1324 void DoMenu (SInt32 menuResult)
1328 MenuRef theMenuHandle;
1330 theMenu = HiWord(menuResult);
1331 theItem = LoWord(menuResult);
1332 theMenuHandle = GetMenuHandle(theMenu);
1358 // --------------------------------------------------------------------------
1360 void DoKey (SInt8 theKey, SInt8 theCode)
1362 #pragma unused (theCode, theKey)
1363 /*if ((theKey == '=') || (theKey == '+'))
1370 // --------------------------------------------------------------------------
1374 /*void DoUpdate (void)
1376 static float sps=200;
1378 static float oldmult;
1382 count = multiplier*sps;
1388 for(int i=0;i<count;i++){
1397 DrawGL (&gRectPort);
1400 void DoUpdate (void)
1402 static float sps=200;
1404 static float oldmult;
1408 if(multiplier>.6)multiplier=.6;
1410 game.fps=1/multiplier;
1412 count = multiplier*sps;
1414 //if(count>10)count=10;
1416 realmultiplier=multiplier;
1417 multiplier*=gamespeed;
1418 if(difficulty==1)multiplier*=.9;
1419 if(difficulty==0)multiplier*=.8;
1421 if(game.loading==4)multiplier*=.00001;
1424 if(slomo&&!mainmenu)multiplier*=slomospeed;
1425 //if(freeze)multiplier*=0.00001;
1427 multiplier/=(float)count;
1433 for(int i=0;i<count;i++){
1438 game.TickOnceAfter();
1440 DrawGL (&gRectPort);
1443 // --------------------------------------------------------------------------
1445 Boolean WaitNextEventWrapper (EventMask eventMask, EventRecord *theEvent, unsigned long sleep,RgnHandle mouseRgn)
1447 return WaitNextEvent (eventMask, theEvent, sleep, mouseRgn);
1450 // --------------------------------------------------------------------------
1452 OSStatus DSpProcessEventWrapper (EventRecord *inEvent, Boolean *outEventWasProcessed)
1454 return DSpProcessEvent (inEvent, outEventWasProcessed);
1457 // --------------------------------------------------------------------------
1459 void UpdateWrapper (EventRecord *theEvent)
1461 WindowRef whichWindow;
1464 whichWindow = (WindowRef) theEvent->message;
1465 GetPort (&pGrafSave);
1466 SetPort((GrafPtr) GetWindowPort(whichWindow));
1467 BeginUpdate(whichWindow);
1469 SetPort((GrafPtr) GetWindowPort(whichWindow));
1470 EndUpdate(whichWindow);
1471 SetPort (pGrafSave);
1474 // --------------------------------------------------------------------------
1476 pascal void IdleTimer (EventLoopTimerRef inTimer, void* userData)
1478 #pragma unused (inTimer, userData)
1479 if(!stillloading)DoUpdate ();
1482 // --------------------------------------------------------------------------
1484 EventLoopTimerUPP GetTimerUPP (void)
1486 static EventLoopTimerUPP sTimerUPP = NULL;
1488 if (sTimerUPP == NULL)
1489 sTimerUPP = NewEventLoopTimerUPP (IdleTimer);
1494 // --------------------------------------------------------------------------
1496 pascal OSStatus mDown (EventHandlerCallRef ref, EventRef e,void * thedata) {
1497 EventMouseButton button;
1500 status = GetEventParameter (e, kEventParamMouseButton, typeMouseButton, NULL,
1501 sizeof (button), NULL, &button);
1503 buttons[button-1] = true;
1505 return eventNotHandledErr;
1508 pascal OSStatus mUp (EventHandlerCallRef ref, EventRef e,void * thedata) {
1509 EventMouseButton button = 0;
1512 status = GetEventParameter (e, kEventParamMouseButton, typeMouseButton, NULL,
1513 sizeof (EventMouseButton), NULL, &button);
1515 buttons[button-1] = false;
1517 return eventNotHandledErr;
1520 void InstallHandlers(void){
1524 spec.eventClass = kEventClassMouse;
1525 spec.eventKind = kEventMouseDown;
1527 status = InstallEventHandler (GetApplicationEventTarget(),
1528 NewEventHandlerUPP (mDown), 1, &spec, NULL, NULL);
1531 spec.eventKind = kEventMouseUp;
1533 status = InstallEventHandler (GetApplicationEventTarget(),
1534 NewEventHandlerUPP (mUp), 1, &spec, NULL, NULL);
1538 void NewEvent(void) {
1543 /*ReceiveNextEvent (0, NULL, 1, true, &er);
1545 s = SendEventToEventTarget (er, GetEventDispatcherTarget());*/
1546 WaitNextEvent (everyEvent, &e, 0, NULL);
1553 EventRecord theEvent;
1554 WindowRef whichWindow;
1560 if (noErr == gProfErr)
1561 ProfilerSetStatus(TRUE); // turn on profiling
1564 if (WaitNextEventWrapper (everyEvent, &theEvent, gSleepTime, NULL))
1566 DSpProcessEventWrapper (&theEvent, &fProcessed);
1569 switch (theEvent.what)
1572 whatPart = FindWindow (theEvent.where, &whichWindow);
1576 // if (GetWindowFromPort (gpDSpPort) != FrontWindow())
1577 // SelectWindow (GetWindowFromPort (gpDSpPort));
1581 SInt32 menuResult = MenuSelect (theEvent.where);
1582 if (HiWord (menuResult) != 0)
1583 DoMenu (menuResult);
1588 // full screen no drag
1593 // full screen no grow
1598 // full screen no go away
1604 // full screen no zoom
1616 theKey = theEvent.message & charCodeMask;
1617 theCode = (theEvent.message & keyCodeMask) >> 8;
1618 if ((theEvent.modifiers & cmdKey) != 0)
1620 SInt32 menuResult = MenuKey (theKey);
1621 if (HiWord(menuResult) != 0)
1622 DoMenu (menuResult);
1625 DoKey (theKey, theCode);
1630 UpdateWrapper (&theEvent);
1636 if (theEvent.message & 0x01000000) // Suspend/resume event
1638 if (theEvent.message & 0x00000001) // Resume
1640 gSleepTime = kForegroundSleep;
1641 gfFrontProcess = true;
1645 gSleepTime = kBackgroundSleep; // Suspend
1646 gfFrontProcess = false;
1651 case kHighLevelEvent:
1652 AEProcessAppleEvent (&theEvent);
1659 if (noErr == gProfErr)
1660 ProfilerSetStatus(FALSE); // turn profiling off again
1664 // --------------------------------------------------------------------------
1672 if (noErr == gProfErr)
1674 ProfilerDump ("\pGL DSp Carbon.prof");
1681 #if defined kUseFades
1682 DSpDebugStr (DSpContext_FadeGammaOut (NULL, NULL)); // fade display, remove for debug
1685 RemoveEventLoopTimer(gTimer);
1688 DeleteFontGL (gFontList);
1689 CleanupAGL (gaglContext); // Cleanup the OpenGL context
1693 ShutdownDSp (gpDSpPort); // DSp shutdown
1698 hMenu = GetMenuHandle (kMenuFile);
1699 DeleteMenu (kMenuFile);
1700 DisposeMenu (hMenu);
1702 hMenu = GetMenuHandle (kMenuApple);
1703 DeleteMenu (kMenuApple);
1704 DisposeMenu (hMenu);
1706 #if defined kUseFades
1707 DSpDebugStr (DSpContext_FadeGammaIn (NULL, NULL)); // fade display, remove for debug
1714 // --------------------------------------------------------------------------
1716 #include <InternetConfig.h>
1721 QString url("http://www.wolfire.com/");
1722 ICInstance icInstance
1723 OSType psiSignature = 'Psi ';
1724 OSStatus error = ::ICStart( &icInstance, psiSignature);
1726 ConstStr255Param hint( 0x0 );
1727 const char* data = url.latin1();
1728 long length = url.length();
1731 ::ICLaunchURL( icInstance, hint, data, length, &start, &end);
1732 ICStop( icInstance);
1737 void LaunchURL(char *url)
1739 ICInstance gICInstance;
1740 ICStart (&gICInstance, 0);
1744 ICLaunchURL(gICInstance, "\p" ,url, fin, &start, &fin);
1754 while (!gDone&&!game.quit&&(!game.tryquit||!game.registered)) {
1759 if(game.registernow){
1761 sprintf(url,"http://www.wolfire.com/register.html");
1765 } catch (const std::exception& error) {
1766 ofstream opstream("error.txt");
1767 opstream << "Caught exception: " << error.what() << std::endl;