⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 macmain.c

📁 This AI for Game Developers
💻 C
字号:
#include "MacMain.h"#include "AICommon.h"// menu constants		#define kAppleID					128		#define kOptionsID				129		#define kAppleM						0		#define kOptionsM					1		#define kQuit							1// globals		UniversalProcPtr		      MyHandleOAppUPP;		UniversalProcPtr		      MyHandleODocUPP;		UniversalProcPtr		      MyHandlePDocUPP;		UniversalProcPtr		      MyHandleQuitUPP;		ModalFilterUPP 		        myGenericFilter;		OSErr											Error;		WindowPtr						    	Window;		Boolean							    	Done;		MenuHandle					    	myMenus[2];		extern int					    	tbWindow;		Boolean							    	applicationSuspended;		TBoolean                	usingX;// external variables		extern ai_World						MainWorld;		extern ai_Entity					entityList[kMaxEntities];	// ----------------------------------------------------------------- //static pascal OSErr MyHandleOApp (const AppleEvent *appleEvt, AppleEvent* reply, long refcon)// ----------------------------------------------------------------- //{	applicationSuspended=false;		return noErr;	}// ----------------------------------------------------------------- //static pascal OSErr MyHandleODoc (const AppleEvent *appleEvt, AppleEvent* reply, long refcon)// ----------------------------------------------------------------- //{	return noErr;	}// ----------------------------------------------------------------- //static pascal OSErr MyHandlePDoc (const AppleEvent *appleEvt, AppleEvent* reply, long refcon)// ----------------------------------------------------------------- //{	return noErr;	}// ----------------------------------------------------------------- //pascal OSErr MyHandleQuit( const AppleEvent *appleEvt, AppleEvent *reply, long refcon )// ----------------------------------------------------------------- //{	Done = true;	return noErr;}// ----------------------------------------------------------------- //void OpenWindow(void)// ----------------------------------------------------------------- //	{				Window = GetNewCWindow(128, nil, (WindowPtr)-1L);		if (Window != nil)			{				SetPortWindowPort(Window);				ShowWindow(Window);				SelectWindow(Window);				tbWindow=tb_SetWindowPtr(Window);			}}// ----------------------------------------------------------------- //void Initialize(void)// ----------------------------------------------------------------- //{	unsigned long           randomSeed;	OSErr                   myErr;	long                    response=0;	  usingX=false;  myErr = Gestalt(gestaltSystemVersion, &response);  if (response>=0x00001000)  	usingX=true;		GetDateTime(&randomSeed);  SetQDGlobalsRandomSeed(randomSeed);	Error = AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, NewAEEventHandlerUPP(MyHandleOApp), 0, false);	Error = AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments,   NewAEEventHandlerUPP(MyHandleODoc), 0, false);	Error = AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments,  NewAEEventHandlerUPP(MyHandlePDoc), 0, false);	Error = AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, NewAEEventHandlerUPP(MyHandleQuit), 0, false);	Done = false;	applicationSuspended=false;	}// ----------------------------------------------------------------- //pascal TBoolean GenericFilter (DialogPtr theDialog, EventRecord *theEvent, SInt16 *itemHit)// ----------------------------------------------------------------- //{	char						theChar;	short						kind;	Handle					item;	TRect						box;	BitMap 					screenBits;	short						windowPart;	Point						globalPt = theEvent->where;	WindowPtr				wp;	Pattern					black;		GetQDGlobalsScreenBits(&screenBits);	GetQDGlobalsBlack(&black);		switch (theEvent->what)		{			case mouseDown: 				windowPart = FindWindow(globalPt, &wp);				if (windowPart==inDrag)					{						InitCursor();						SetPortWindowPort(wp);						DragWindow(wp, theEvent->where, &screenBits.bounds);						return (true);					}				if (windowPart==inGoAway)					{						SetPortWindowPort(wp);						if (TrackGoAway(wp,globalPt))							*itemHit=kCancelButton;						return (true);					}			break;			case keyDown:				theChar=(char)(theEvent->message & charCodeMask);				if ((((theEvent->modifiers & cmdKey) !=0) && (theChar=='.')) || (theChar==(char)27))					{						*itemHit=kCancelButton;						GetDialogItem(theDialog, kCancelButton, &kind, &item, &box);						HiliteControl((ControlHandle)item, 1);						return true;					};				if ((theChar==(char)13) || (theChar==(char)3))					{						*itemHit=kOKButton;						GetDialogItem(theDialog, 1, &kind, &item, &box);						HiliteControl((ControlHandle)item, kOKButton);						return true;					};				break;			case updateEvt:				BeginUpdate(GetDialogWindow(theDialog));				SetPortDialogPort(theDialog);				DrawDialog(theDialog);				EndUpdate(GetDialogWindow(theDialog));				if (Window!=nil)					{						SetPortWindowPort(Window);						BeginUpdate(Window);						MainWorld.Redraw();						EndUpdate(Window);					}				SetPortDialogPort(theDialog);				break;		}		return false;		}// ----------------------------------------------------------------- //void SetUpMenus(void)// ----------------------------------------------------------------- //	{	short							i;	myMenus[kAppleM] 	= GetMenu(kAppleID);	myMenus[kOptionsM]= GetMenu(kOptionsID);			for (i=kAppleM; i<=kOptionsM; i++)		InsertMenu(myMenus[i], 0);  	DrawMenuBar();		}// ----------------------------------------------------------------- //void DoMenus (long menuResult)// ----------------------------------------------------------------- //{	short 				theMenu 								= (menuResult >> 16);	short 				theItem 								= (menuResult & 0x0000FFFF);		switch (theMenu)	 {		case kAppleID:			{				if (theItem==1)					tb_DoDialog(128);			}			break;								case kOptionsID: 			switch (theItem)				{					case kQuit: 						Done=true;						break;				}			break;	}	HiliteMenu(0);	}// ----------------------------------------------------------------- //void DoMouseDown (EventRecord *theEvent)// ----------------------------------------------------------------- //{	Point									globalPt = theEvent->where;	short									windowPart;	WindowPtr							wp;	int										match=-1;	BitMap 								screenBits;	short									MenuHeight=GetMBarHeight();		GetQDGlobalsScreenBits(&screenBits);					windowPart = FindWindow(globalPt, &wp);	switch (windowPart) {		case inMenuBar: 			DoMenus(MenuSelect(globalPt));		break;		case inSysWindow: 		break;		case inDrag:			SetPortWindowPort(wp);			DragWindow(wp, theEvent->where, &screenBits.bounds);		break;	    case inZoomIn:	    case inZoomOut:	    break;				case inGrow:		break;		case inGoAway:			SetPortWindowPort(wp);			if (TrackGoAway(wp,globalPt))				Done = true;		break;		case inContent: 			{			  SetPortWindowPort(wp);				SelectWindow(wp);      }		break;	}	}// ----------------------------------------------------------------- //void DoKey (EventRecord *theEvent)// ----------------------------------------------------------------- //{	char		keyPressed = (theEvent->message & charCodeMask);	if (theEvent->modifiers & cmdKey)		DoMenus(MenuKey(keyPressed));			if ((int)keyPressed==30)		MainWorld.KeyDown(kUpKey);	if ((int)keyPressed==31)		MainWorld.KeyDown(kDownKey);	if ((int)keyPressed==28)		MainWorld.KeyDown(kLeftKey);	if ((int)keyPressed==29)		MainWorld.KeyDown(kRightKey);}// ----------------------------------------------------------------- //void DoActivate (EventRecord *theEvent)// ----------------------------------------------------------------- //{		}// ----------------------------------------------------------------- //void DoSuspendResume(Boolean InForeground)// ----------------------------------------------------------------- //{	if (InForeground) // resume 		{			applicationSuspended=false;		}	else						 // suspend		{			applicationSuspended=true;		}}// ----------------------------------------------------------------- //void MainLoop()// ----------------------------------------------------------------- //{	EventRecord						theEvent;	static  long					sleepTime = 1L;	int										match=-1;	BitMap 								screenBits;		GetQDGlobalsScreenBits(&screenBits);		WaitNextEvent(everyEvent, &theEvent, sleepTime, NULL);			switch (theEvent.what) {			case nullEvent:			MainWorld.UpdateWorld();		break;		case mouseDown: 			DoMouseDown(&theEvent);		break;		case keyDown:		case autoKey: 			DoKey(&theEvent);		break;		case activateEvt: 			DoActivate(&theEvent);		break;		case updateEvt:			{				match=tb_GetWindowMatch((WindowPtr)theEvent.message);				if (match!=-1)					{						BeginUpdate((WindowPtr)theEvent.message);						EndUpdate((WindowPtr)theEvent.message);						MainWorld.Redraw();					}			}		break;				case osEvt:			if ((theEvent.message >> 24) & suspendResumeMessage )				DoSuspendResume((theEvent.message & resumeFlag)!=0);		break;				case kHighLevelEvent:			(void)AEProcessAppleEvent(&theEvent);				}	}// ----------------------------------------------------------------- //void main(void)// ----------------------------------------------------------------- //{	Initialize();	SetUpMenus();					OpenWindow();	tb_FlushMouseEvents();		while (!Done)		MainLoop();			tb_CloseToolbox();}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -