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<0)screenwidth=640;
960 if(screenheight<0)screenheight=480;
961 #if !USE_SDL // we'll take anything that works.
962 if(screenwidth>3000)screenwidth=640;
963 if(screenheight>3000)screenheight=480;
970 aglSetInteger(gaglContext, AGL_SWAP_INTERVAL, &swapInt);
973 if(kBitsPerPixel!=32&&kBitsPerPixel!=16){
978 GDHandle hGD, hTargetDevice = NULL;
979 short numDevices = 0;
981 short whichDevice = 0; // number of device to try (0 = 1st device)
989 if ((Ptr) kUnresolvedCFragSymbolAddress == (Ptr) DSpStartup)
990 ReportError ("DSp not installed");
992 if (noErr != DSpDebugStr (DSpStartup()))
994 // DSpSetDebugMode (true);
995 #if defined kUseFades
996 DSpDebugStr (DSpContext_FadeGammaOut (NULL, NULL)); // fade display, remove for debug
999 hGD = DMGetFirstScreenDevice (true); // check number of screens
1000 hTargetDevice = hGD; // default to first device
1003 if (numDevices == whichDevice)
1004 hTargetDevice = hGD; // if device number matches
1006 hGD = DMGetNextScreenDevice (hGD, true);
1010 #if defined (kUseAGLFullScreenX)
1011 if (CheckMacOSX ()) // Try AGL full screen on Mac OS X
1013 short depth = kBitsPerPixel, width = kContextWidth, height = kContextHeight;
1014 gaglContext = SetupAGLFullScreen (hTargetDevice, &depth, &width, &height); // Setup the OpenGL context
1015 SetRect (&gRectPort, 0, 0, width, height); // l, t, r, b
1016 sprintf (gcstrMode, "AGL Full Screen: %d x %d x %d", width, height, depth);
1019 if (!gaglContext) //try DSp
1021 if (NULL != (gpDSpPort = SetupDSpFullScreen (hTargetDevice))) // Setup DSp for OpenGL sets hTargetDeviceto device actually used
1023 GetPortBounds (gpDSpPort, &gRectPort);
1024 sprintf (gcstrMode, "DrawSprocket Full Screen: %d x %d x %d", gRectPort.right - gRectPort.left, gRectPort.bottom - gRectPort.top, (**(**hTargetDevice).gdPMap).pixelSize);
1025 gaglContext = SetupAGL (hTargetDevice, gpDSpPort);
1030 GetFNum("\pMonaco", &fNum); // build font
1031 gFontList = BuildFontGL (gaglContext, fNum, normal, 9);
1032 //InstallEventLoopTimer (GetCurrentEventLoop(), 0, 0.0001, GetTimerUPP (), 0, &gTimer);
1035 //gMidPoint.h = (gRectPort.left + gRectPort.right)/2;
1036 //gMidPoint.v = (gRectPort.top + gRectPort.bottom)/2;
1040 //aglSetInteger(gaglContext, AGL_SWAP_INTERVAL, &swapInt);
1042 #if defined kUseFades
1043 DSpDebugStr (DSpContext_FadeGammaIn (NULL, NULL));
1050 GLint width = gRectPort.right - gRectPort.left;
1051 GLint height = gRectPort.bottom - gRectPort.top;
1053 screenheight=height;
1055 game.newdetail=detail;
1056 game.newscreenwidth=screenwidth;
1057 game.newscreenheight=screenheight;
1068 static Boolean RunningOnCarbonX(void)
1070 static Boolean first = true;
1071 static Boolean result = false;
1079 result = (Gestalt(gestaltSystemVersion,
1080 (SInt32 *) &response) == noErr)
1081 && (response >= 0x01000);
1086 static OSStatus LoadFrameworkBundle(CFStringRef pFrameworkCFStrRef, CFBundleRef *pFrameworkCFBndlRef)
1089 FSRef frameworksFolderRef;
1093 if (nil == pFrameworkCFBndlRef) return paramErr;
1095 *pFrameworkCFBndlRef = nil;
1100 err = FSFindFolder(kOnAppropriateDisk, kFrameworksFolderType, true, &frameworksFolderRef);
1102 baseURL = CFURLCreateFromFSRef(kCFAllocatorSystemDefault, &frameworksFolderRef);
1103 if (baseURL == nil) {
1104 err = coreFoundationUnknownErr;
1108 bundleURL = CFURLCreateCopyAppendingPathComponent(kCFAllocatorSystemDefault, baseURL, pFrameworkCFStrRef, false);
1109 if (bundleURL == nil) {
1110 err = coreFoundationUnknownErr;
1114 *pFrameworkCFBndlRef = CFBundleCreate(kCFAllocatorSystemDefault, bundleURL);
1115 if (*pFrameworkCFBndlRef == nil) {
1116 err = coreFoundationUnknownErr;
1120 if ( ! CFBundleLoadExecutable( *pFrameworkCFBndlRef ) ) {
1121 err = coreFoundationUnknownErr;
1127 if (err != noErr && *pFrameworkCFBndlRef != nil) {
1128 CFRelease(*pFrameworkCFBndlRef);
1129 *pFrameworkCFBndlRef = nil;
1131 if (bundleURL != nil) {
1132 CFRelease(bundleURL);
1134 if (baseURL != nil) {
1143 static CFragConnectionID gCFragConnectionID = 0;
1145 typedef pascal OSErr (*CDM_NewDeviceProcPtr)(CursorDevicePtr * ourDevice);
1147 static OSErr MyCursorDeviceNewDevice(CursorDevicePtr * ourDevice)
1149 static CDM_NewDeviceProcPtr sCDM_NewDeviceProcPtr = nil;
1150 OSStatus anErr = noErr;
1152 if (nil == ourDevice) return paramErr;
1154 if (!RunningOnCarbonX())
1156 if (!sCDM_NewDeviceProcPtr)
1158 if (!gCFragConnectionID)
1163 anErr = GetSharedLibrary("\pInterfaceLib", kPowerPCCFragArch,
1164 kFindCFrag, &gCFragConnectionID, &mainAddr, errName);
1165 if (noErr != anErr) return anErr;
1168 if (gCFragConnectionID)
1170 CFragSymbolClass symClass;
1172 anErr = FindSymbol(gCFragConnectionID, "\pCrsrDevNewDevice",
1173 (Ptr*) &sCDM_NewDeviceProcPtr, &symClass);
1174 if (noErr != anErr) return anErr;
1177 if (sCDM_NewDeviceProcPtr)
1178 anErr = (*sCDM_NewDeviceProcPtr)(ourDevice);
1186 typedef pascal OSErr (*CDM_CursorDeviceMoveToProcPtr)(
1187 CursorDevicePtr ourDevice,
1191 typedef UInt32 (*CGWarpMouseCursorPositionProcPtr)(CGPoint newCursorPosition);
1192 typedef UInt32 (*CGSetLocalEventsSuppressionIntervalProcPtr)(double pSeconds);
1194 static OSErr MyCursorDeviceMoveTo( CursorDevicePtr ourDevice,
1198 OSStatus anErr = noErr;
1200 if (RunningOnCarbonX())
1202 static CGWarpMouseCursorPositionProcPtr sCGWarpMouseCursorPositionProcPtr = nil;
1204 if (nil == sCGWarpMouseCursorPositionProcPtr)
1206 CFBundleRef tCFBundleRef;
1208 anErr = LoadFrameworkBundle(CFSTR("ApplicationServices.framework"), &tCFBundleRef);
1212 CGSetLocalEventsSuppressionIntervalProcPtr tCGSetLocalEventsSuppressionIntervalProcPtr = nil;
1214 sCGWarpMouseCursorPositionProcPtr = (CGWarpMouseCursorPositionProcPtr)
1215 CFBundleGetFunctionPointerForName( tCFBundleRef, CFSTR("CGWarpMouseCursorPosition") );
1216 if (nil == sCGWarpMouseCursorPositionProcPtr)
1217 anErr = cfragNoSymbolErr;
1219 tCGSetLocalEventsSuppressionIntervalProcPtr = (CGSetLocalEventsSuppressionIntervalProcPtr)
1220 CFBundleGetFunctionPointerForName(tCFBundleRef,CFSTR("CGSetLocalEventsSuppressionInterval"));
1221 if (nil != tCGSetLocalEventsSuppressionIntervalProcPtr)
1222 (*tCGSetLocalEventsSuppressionIntervalProcPtr)(0.0f);
1226 if (nil != sCGWarpMouseCursorPositionProcPtr)
1233 (*sCGWarpMouseCursorPositionProcPtr)(tCGPoint);
1238 static CDM_CursorDeviceMoveToProcPtr sCDM_CursorDeviceMoveToProcPtr = nil;
1240 if (!ourDevice) return paramErr;
1242 if (!sCDM_CursorDeviceMoveToProcPtr)
1244 if (!gCFragConnectionID)
1249 anErr = GetSharedLibrary("\pInterfaceLib", kPowerPCCFragArch,
1250 kFindCFrag, &gCFragConnectionID, &mainAddr, errName);
1251 if (noErr != anErr) return anErr;
1254 if (gCFragConnectionID)
1256 CFragSymbolClass symClass;
1258 anErr = FindSymbol(gCFragConnectionID, "\pCrsrDevMoveTo",
1259 (Ptr*) &sCDM_CursorDeviceMoveToProcPtr, &symClass);
1260 if (noErr != anErr) return anErr;
1263 if (sCDM_CursorDeviceMoveToProcPtr)
1264 anErr = (*sCDM_CursorDeviceMoveToProcPtr)(ourDevice,absX,absY);
1272 static void DoMouse(void)
1274 static CursorDevicePtr virtualCursorDevicePtr = nil;
1275 OSStatus anErr = noErr;
1279 if (nil == virtualCursorDevicePtr)
1280 anErr = MyCursorDeviceNewDevice(&virtualCursorDevicePtr);
1283 static Point lastMouse = {-1,-1};
1286 GetGlobalMouse(&globalMouse);
1288 if (EqualPt(lastMouse, globalMouse))
1294 if (!EqualPt(lastMouse, globalMouse))
1296 static Point virtualMouse = {0,0};
1297 delta = globalMouse;
1299 SubPt(lastMouse, &delta);
1300 GetGlobalMouse(&lastMouse);
1301 //AddPt(delta, &virtualMouse);
1303 if(mainmenu||(abs(delta.h)<10*realmultiplier*1000&&abs(delta.v)<10*realmultiplier*1000)){
1304 game.deltah=delta.h*usermousesensitivity;
1305 game.deltav=delta.v*usermousesensitivity;
1306 game.mousecoordh=globalMouse.h;
1307 game.mousecoordv=globalMouse.v;
1310 //printf("\nMouse Moved: {%d,%d}.",globalMouse.h,globalMouse.v);
1311 //printf("\tdelta: {%d,%d}.",delta.h,delta.v);
1312 //printf("\tvirtual: {%d,%d}.",virtualMouse.h,virtualMouse.v);
1315 if(lastMouse.h>gMidPoint.h+100||lastMouse.h<gMidPoint.h-100||lastMouse.v>gMidPoint.v+100||lastMouse.v<gMidPoint.v-100){
1316 MyCursorDeviceMoveTo(virtualCursorDevicePtr,gMidPoint.h,gMidPoint.v);
1317 lastMouse = gMidPoint;
1324 // --------------------------------------------------------------------------
1326 void DoMenu (SInt32 menuResult)
1330 MenuRef theMenuHandle;
1332 theMenu = HiWord(menuResult);
1333 theItem = LoWord(menuResult);
1334 theMenuHandle = GetMenuHandle(theMenu);
1360 // --------------------------------------------------------------------------
1362 void DoKey (SInt8 theKey, SInt8 theCode)
1364 #pragma unused (theCode, theKey)
1365 /*if ((theKey == '=') || (theKey == '+'))
1372 // --------------------------------------------------------------------------
1376 /*void DoUpdate (void)
1378 static float sps=200;
1380 static float oldmult;
1384 count = multiplier*sps;
1390 for(int i=0;i<count;i++){
1399 DrawGL (&gRectPort);
1402 void DoUpdate (void)
1404 static float sps=200;
1406 static float oldmult;
1410 if(multiplier>.6)multiplier=.6;
1412 game.fps=1/multiplier;
1414 count = multiplier*sps;
1416 //if(count>10)count=10;
1418 realmultiplier=multiplier;
1419 multiplier*=gamespeed;
1420 if(difficulty==1)multiplier*=.9;
1421 if(difficulty==0)multiplier*=.8;
1423 if(game.loading==4)multiplier*=.00001;
1426 if(slomo&&!mainmenu)multiplier*=slomospeed;
1427 //if(freeze)multiplier*=0.00001;
1429 multiplier/=(float)count;
1435 for(int i=0;i<count;i++){
1440 game.TickOnceAfter();
1442 DrawGL (&gRectPort);
1445 // --------------------------------------------------------------------------
1447 Boolean WaitNextEventWrapper (EventMask eventMask, EventRecord *theEvent, unsigned long sleep,RgnHandle mouseRgn)
1449 return WaitNextEvent (eventMask, theEvent, sleep, mouseRgn);
1452 // --------------------------------------------------------------------------
1454 OSStatus DSpProcessEventWrapper (EventRecord *inEvent, Boolean *outEventWasProcessed)
1456 return DSpProcessEvent (inEvent, outEventWasProcessed);
1459 // --------------------------------------------------------------------------
1461 void UpdateWrapper (EventRecord *theEvent)
1463 WindowRef whichWindow;
1466 whichWindow = (WindowRef) theEvent->message;
1467 GetPort (&pGrafSave);
1468 SetPort((GrafPtr) GetWindowPort(whichWindow));
1469 BeginUpdate(whichWindow);
1471 SetPort((GrafPtr) GetWindowPort(whichWindow));
1472 EndUpdate(whichWindow);
1473 SetPort (pGrafSave);
1476 // --------------------------------------------------------------------------
1478 pascal void IdleTimer (EventLoopTimerRef inTimer, void* userData)
1480 #pragma unused (inTimer, userData)
1481 if(!stillloading)DoUpdate ();
1484 // --------------------------------------------------------------------------
1486 EventLoopTimerUPP GetTimerUPP (void)
1488 static EventLoopTimerUPP sTimerUPP = NULL;
1490 if (sTimerUPP == NULL)
1491 sTimerUPP = NewEventLoopTimerUPP (IdleTimer);
1496 // --------------------------------------------------------------------------
1498 pascal OSStatus mDown (EventHandlerCallRef ref, EventRef e,void * thedata) {
1499 EventMouseButton button;
1502 status = GetEventParameter (e, kEventParamMouseButton, typeMouseButton, NULL,
1503 sizeof (button), NULL, &button);
1505 buttons[button-1] = true;
1507 return eventNotHandledErr;
1510 pascal OSStatus mUp (EventHandlerCallRef ref, EventRef e,void * thedata) {
1511 EventMouseButton button = 0;
1514 status = GetEventParameter (e, kEventParamMouseButton, typeMouseButton, NULL,
1515 sizeof (EventMouseButton), NULL, &button);
1517 buttons[button-1] = false;
1519 return eventNotHandledErr;
1522 void InstallHandlers(void){
1526 spec.eventClass = kEventClassMouse;
1527 spec.eventKind = kEventMouseDown;
1529 status = InstallEventHandler (GetApplicationEventTarget(),
1530 NewEventHandlerUPP (mDown), 1, &spec, NULL, NULL);
1533 spec.eventKind = kEventMouseUp;
1535 status = InstallEventHandler (GetApplicationEventTarget(),
1536 NewEventHandlerUPP (mUp), 1, &spec, NULL, NULL);
1540 void NewEvent(void) {
1545 /*ReceiveNextEvent (0, NULL, 1, true, &er);
1547 s = SendEventToEventTarget (er, GetEventDispatcherTarget());*/
1548 WaitNextEvent (everyEvent, &e, 0, NULL);
1555 EventRecord theEvent;
1556 WindowRef whichWindow;
1562 if (noErr == gProfErr)
1563 ProfilerSetStatus(TRUE); // turn on profiling
1566 if (WaitNextEventWrapper (everyEvent, &theEvent, gSleepTime, NULL))
1568 DSpProcessEventWrapper (&theEvent, &fProcessed);
1571 switch (theEvent.what)
1574 whatPart = FindWindow (theEvent.where, &whichWindow);
1578 // if (GetWindowFromPort (gpDSpPort) != FrontWindow())
1579 // SelectWindow (GetWindowFromPort (gpDSpPort));
1583 SInt32 menuResult = MenuSelect (theEvent.where);
1584 if (HiWord (menuResult) != 0)
1585 DoMenu (menuResult);
1590 // full screen no drag
1595 // full screen no grow
1600 // full screen no go away
1606 // full screen no zoom
1618 theKey = theEvent.message & charCodeMask;
1619 theCode = (theEvent.message & keyCodeMask) >> 8;
1620 if ((theEvent.modifiers & cmdKey) != 0)
1622 SInt32 menuResult = MenuKey (theKey);
1623 if (HiWord(menuResult) != 0)
1624 DoMenu (menuResult);
1627 DoKey (theKey, theCode);
1632 UpdateWrapper (&theEvent);
1638 if (theEvent.message & 0x01000000) // Suspend/resume event
1640 if (theEvent.message & 0x00000001) // Resume
1642 gSleepTime = kForegroundSleep;
1643 gfFrontProcess = true;
1647 gSleepTime = kBackgroundSleep; // Suspend
1648 gfFrontProcess = false;
1653 case kHighLevelEvent:
1654 AEProcessAppleEvent (&theEvent);
1661 if (noErr == gProfErr)
1662 ProfilerSetStatus(FALSE); // turn profiling off again
1666 // --------------------------------------------------------------------------
1674 if (noErr == gProfErr)
1676 ProfilerDump ("\pGL DSp Carbon.prof");
1683 #if defined kUseFades
1684 DSpDebugStr (DSpContext_FadeGammaOut (NULL, NULL)); // fade display, remove for debug
1687 RemoveEventLoopTimer(gTimer);
1690 DeleteFontGL (gFontList);
1691 CleanupAGL (gaglContext); // Cleanup the OpenGL context
1695 ShutdownDSp (gpDSpPort); // DSp shutdown
1700 hMenu = GetMenuHandle (kMenuFile);
1701 DeleteMenu (kMenuFile);
1702 DisposeMenu (hMenu);
1704 hMenu = GetMenuHandle (kMenuApple);
1705 DeleteMenu (kMenuApple);
1706 DisposeMenu (hMenu);
1708 #if defined kUseFades
1709 DSpDebugStr (DSpContext_FadeGammaIn (NULL, NULL)); // fade display, remove for debug
1716 // --------------------------------------------------------------------------
1718 #include <InternetConfig.h>
1723 QString url("http://www.wolfire.com/");
1724 ICInstance icInstance
1725 OSType psiSignature = 'Psi ';
1726 OSStatus error = ::ICStart( &icInstance, psiSignature);
1728 ConstStr255Param hint( 0x0 );
1729 const char* data = url.latin1();
1730 long length = url.length();
1733 ::ICLaunchURL( icInstance, hint, data, length, &start, &end);
1734 ICStop( icInstance);
1739 void LaunchURL(char *url)
1741 ICInstance gICInstance;
1742 ICStart (&gICInstance, 0);
1746 ICLaunchURL(gICInstance, "\p" ,url, fin, &start, &fin);
1756 while (!gDone&&!game.quit&&(!game.tryquit||!game.registered)) {
1761 if(game.registernow){
1763 sprintf(url,"http://www.wolfire.com/register.html");
1767 } catch (const std::exception& error) {
1768 ofstream opstream("error.txt");
1769 opstream << "Caught exception: " << error.what() << std::endl;