#ifdef ACTIVE_EDITOR // { //========================================================================= // CPAProject.cpp : Defines the class behaviors for the application. // This is a part of the CPA project. // // Version 1.0 // Creation date 06/06/96 // Revision date // // (c) Ubi Studios 1996 // // DO NOT MODIFY THAT FILE. IF SOMETHING NEEDS TO BE CHANGE, PLEASE CONTACT // VINCENT GRECO OR CHRISTOPHE BEAUDET. //========================================================================= #include "stdafx.h" #include "acp_base.h" #define __DeclareGlobalVariableErrInt_h__ #include "ErrInt.h" #undef __DeclareGlobalVariableErrInt_h__ #define __DeclareGlobalVariableMmgInt_h__ #include "MmgInt.h" #undef __DeclareGlobalVariableMmgInt_h__ #include "direct.h" #undef EXTERN #include "geo.h" #include "gli.h" #include "col.h" #define HieFriend #include "spo.h" #include "lst.h" #undef HieFriend #include "Itf/CPARes.h" #include "Itf/CPAProj.hpp" #include "Itf/CPADoc.hpp" #include "Itf/DEVMul3D.hpp" #include "Itf/FRMGest.Hpp" #include "Itf/CPACont.hpp" #include "Itf/CPAConst.hpp" #include "Itf/CPAkacnf.hpp" #include "Itf/cpamworl.hpp" #include "Itf/cpakacnf.hpp" #include "Itf/CPAAbout.hpp" #include "Itf/CPAInter.hpp" //*********************************************** //*** DR (20/01/98) ***************************** extern HMODULE g_hWawModule; //*** End DR ************************************ //*********************************************** #include "x:\cpa\main\inc\_EditID.h" #include "TUT.h" //CPA2 Corneliu Babiuc 13-05-98 //definition of constant for keyboard action //************************ WARNING!!! ********************************* //these constant must be also defined in devvp3d.cpp file as they are!!! //I didt put them in a .hpp file in order to not modify the public files or a project // object drawing flags #define KA_CancelAllDrawingFlags 10 #define KA_IgnoreDrawingFlags 11 #define KA_NormalObject 12 #define KA_GridedObject 13 #define KA_WiredObject 14 // object parameters #define KA_ShowObjectAxis 20 #define KA_BVObject 22 // centers #define KA_ShowMainCenters 25 #define KA_ShowAllCenters 26 #define KA_ShowNoCenter 27 // world drawing flags #define KA_NormalWorld 30 #define KA_GridedWorld 31 #define KA_WiredWorld 32 // world display mode #define KA_WorldSectors 40 #define KA_VisibleSectors 41 #define KA_CurrentSector 42 #define KA_CollisionMap 43 // bounding volumes #define KA_SectorsBV 50 #define KA_ActorsBV 51 #define KA_ObjectsBV 52 #define KA_NoBV 53 // colors #define KA_SelectBackgroundColor 55 // selection #define KA_CancelSelection 60 #define KA_FullSelection 61 #define KA_DeltaSelection 62 #define KA_FixedDepthPyramid 63 #define KA_RealTimePyramid 64 // status bar #define KA_DisplayInstanceInfo 70 #define KA_DisplayInstanceToCam 71 #define KA_DisplayCameraInfo 72 #define KA_DisplayDistance 73 // options #define KA_ScaleEditorObjects 80 #define KA_ShowNoAxis 81 #define KA_ShowAxisLeft 82 #define KA_ShowAxisRight 83 #define KA_Borders 100 #define KA_ComputeCenters 110 #define KA_ForceMousePos 120 char p_cVersionName[80]; //END CPA2 Corneliu Babiuc 14-05-98 ///////////////////////////////////////////////////////////////////////////// // CPA_ProjectApp BEGIN_MESSAGE_MAP(CPA_ProjectApp, CWinApp) //{{AFX_MSG_MAP(CPA_ProjectApp) ON_THREAD_MESSAGE(WM_USER,OnUserMsg) // NOTE - the ClassWizard will add and remove mapping macros here. // DO NOT EDIT what you see in these blocks of generated code! //}}AFX_MSG END_MESSAGE_MAP() static tdstKeyboardActionDef gs_a_stMul3DKeys[] = { //CPA2 Corneliu Babiuc 13-05-98 // colors {"Select Background Color", KA_SelectBackgroundColor}, {"Proportionnal sizing", KA_PropSizing}, // object drawing flags {"Cancel all drawing flags", KA_CancelAllDrawingFlags}, {"Ignore Drawing Flags", KA_IgnoreDrawingFlags}, {"Normal Object", KA_NormalObject}, {"Grided Object", KA_GridedObject}, {"Wired Object", KA_WiredObject}, // object parameters {"Show Object BV", KA_BVObject}, {"Show Object Axis", KA_ShowObjectAxis}, // world drawing flags {"Normal World", KA_NormalWorld}, {"Grided World", KA_GridedWorld}, {"Wired World", KA_WiredWorld}, // world display mode {"World Sectors", KA_WorldSectors}, {"Visible Sectors", KA_VisibleSectors}, {"Current Sector", KA_CurrentSector}, {"Collision Map", KA_CollisionMap}, // bounding volumes {"Sectors BV", KA_SectorsBV}, {"Actors BV", KA_ActorsBV}, {"Objects BV", KA_ObjectsBV}, {"No BV", KA_NoBV}, // centers {"Show Main Centers", KA_ShowMainCenters}, {"Show All Centers", KA_ShowAllCenters}, {"Show No Center", KA_ShowNoCenter}, // axis { "Show Axis Left", KA_ShowAxisLeft}, { "Show Axis Right", KA_ShowAxisRight}, { "Show No Axis", KA_ShowNoAxis}, // status bar { "Display Instance Info", KA_DisplayInstanceInfo}, { "Display Instance To Camera", KA_DisplayInstanceToCam}, { "Display Camera Info", KA_DisplayCameraInfo}, { "Display Distance", KA_DisplayDistance}, // options { "Compute Centers", KA_ComputeCenters}, { "Show Borders", KA_Borders}, { "Scale Editor Objects", KA_ScaleEditorObjects}, // selection {"Unselect all", KA_CancelSelection}, {"Full selection", KA_FullSelection}, {"Delta selection", KA_DeltaSelection}, // pyramidal selection { "Fixed depth pyramid", KA_FixedDepthPyramid}, { "Real Time pyramid", KA_RealTimePyramid}, // options { "Force Mouse Cursor", KA_ForceMousePos}, //END CPA2 Corneliu Babiuc 19-05-98 {NULL, 0}, }; //########################################################################### // Constructor and destructor of application //########################################################################### //=========================================================================== // Description: CONSTRUCTOR // => Change windows parameters // Creation date: 27 Jun 96 // Author: CB //--------------------------------------------------------------------------- // Revision date: // Author: //=========================================================================== CPA_ProjectApp::CPA_ProjectApp() { //--------------------------------------------------------------------------- // memory and error messages initialisations // For memory usage and errors Erm_M_InitErrMsg(Erm); // Erm_fn_vSetThreadId4Request(m_nThreadID); Erm_M_InitErrMsg(Mmg); Erm_M_InitErrMsg(Int); Mmg_fn_vFirstInitMmgModule(10); Mmg_M_InitMmg(Int); m_bWasInFullScreenBeforeLooseFocus = FALSE; m_bLeavingApplication = FALSE; m_bBadResolution = FALSE; m_bFlagTaken = FALSE; // Mmg_M_SetModeAlloc(Int, E_ucDynamic); //--------------------------------------------------------------------------- m_bProjectIsClosing = 0; // m_bViewerOpened = FALSE; m_bFullScreenInEditor = FALSE; m_bEngineOneStep = 0; m_iNumRef = 0; m_bCursorInFirstScreen = TRUE; mp_oDevKeyboard = new CPA_KeyActionConfiguration("CPAMul3D.ini", gs_a_stMul3DKeys); mp_oDevKeyboard->mfn_vSetObjectName("3D View"); m_csApplicationName = "CPAProj"; m_csApplicationVersion = "v0.0.0"; m_p_oDlgAbout = NULL; // POS_fn_vSetIdentityMatrix(&m_stWorldBaseMatrix); MTH3D_M_vNullVector(&(m_stWorldBaseMatrix.stTranslationVector)); MTH3D_M_vSetIdentityMatrix(&(m_stWorldBaseMatrix.stRotationMatrix)); MTH3D_M_vSetIdentityMatrix(&(m_stWorldBaseMatrix.stTransformMatrix)); m_stWorldBaseMatrix.ulType = POS_C_ulIdentityMatrixFlag; m_bAutoReinitTheMap = TRUE; m_bEngineIsStopped = FALSE; m_bEditorsAreActive = FALSE; m_bAppliAskedToStopEngine = FALSE; m_bAppliPulsedOneStep = FALSE; m_bAppliAskedToActivateEditors = FALSE; m_bEngineAskedToForceEditors = FALSE; m_bAppliAskedToEndGame = FALSE; m_bEngineIsOver = FALSE; m_bFinishEngine = FALSE; } //=========================================================================== // Description: DESTRUCTOR // => Kill all editors // => Restore windows parameters // Creation date: 27 Jun 96 // Author: CB //--------------------------------------------------------------------------- // Revision date: // Author: //=========================================================================== CPA_ProjectApp::~CPA_ProjectApp() { delete mp_oDevKeyboard; mp_oDevKeyboard = NULL; //it's not my job to delete list elements, m_lstKeyboard.RemoveAll(); } //########################################################################### // CPA_ProjectApp initializations and close //########################################################################### //=========================================================================== // Description: Set and reset windows parameters. // Creation date: 27 Jun 96 // Author: CB //--------------------------------------------------------------------------- // Return void //--------------------------------------------------------------------------- // Revision date: // Author: //=========================================================================== void CPA_ProjectApp::fn_vSetWindowsParameters(void) { // => No screen saver /* SystemParametersInfo(SPI_GETSCREENSAVEACTIVE, 0, &m_bOldScreenSaveActive, 0); SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, FALSE, NULL, 0);*/ } void CPA_ProjectApp::fn_vResetWindowsParameters(void) { // => Screen saver //SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, m_bOldScreenSaveActive, NULL, 0); } //=========================================================================== // Description: Test windows config. to be sure that it's correct for // game. // Fatal error if not correct. // Creation date: 27 Jun 96 // Author: CB //--------------------------------------------------------------------------- // Return void //--------------------------------------------------------------------------- // Revision date: // Author: //=========================================================================== void CPA_ProjectApp::fn_vTestWindowsConfig(void) { HDC hdc; int iAppBPP; hdc = ::GetDC(NULL); iAppBPP = ::GetDeviceCaps(hdc, PLANES); iAppBPP *= ::GetDeviceCaps(hdc, BITSPIXEL); ReleaseDC(NULL, hdc); // if(iAppBPP != 16) // { // m_bBadResolution = TRUE; // MessageBox(NULL, "Bad display resolution. You won't be able to run game in windowed.", "Warning", MB_OK|MB_ICONWARNING); // } } //=========================================================================== // Description: Init camera to see the world correctly // Creation date: 05 sept 96 // Author: FBF //--------------------------------------------------------------------------- // Return niet //--------------------------------------------------------------------------- // Revision date: ? // Author: //=========================================================================== void CPA_ProjectApp::fn_vSetWorldBaseMatrix() { MTH3D_tdstVector stI , stJ , stK; POS_fn_vSetIdentityMatrix(&m_stWorldBaseMatrix); MTH3D_M_vNullVector(&stI); MTH3D_M_vNullVector(&stJ); MTH3D_M_vNullVector(&stK); MTH3D_M_vSetXofVector(&stI,GLI_M_LongToValue(-1)); MTH3D_M_vSetZofVector(&stJ,GLI_M_LongToValue(1)); MTH3D_M_vSetYofVector(&stK,GLI_M_LongToValue(1)); POS_fn_vSetRotationMatrix(&m_stWorldBaseMatrix, &stI, &stJ, &stK); } //=========================================================================== // Description: First init of application. // Creation date: 21 Jun 96 // Author: CB //--------------------------------------------------------------------------- // Return BOOL //--------------------------------------------------------------------------- // Revision date: // Author: //=========================================================================== BOOL CPA_ProjectApp::InitApplication(void) { // Change protection of EXE if there's auto generate code, and virtual lock // code. // fn_vChangeExeProtection((unsigned long) m_hInstance); // Test windows environment fn_vTestWindowsConfig(); // Change windows parameters fn_vSetWindowsParameters(); // Create all semaphores m_hDrawSem = CreateSemaphore(NULL, 1, 1, (LPCTSTR) "DRAWSEM"); // To avoid list of dump memory at the end of execution AfxEnableMemoryTracking(FALSE); // Set base matrix for world fn_vSetWorldBaseMatrix(); // register editor superobject script callback CPA_SuperObject::fn_vInitLoadEditor(); //FBFFBF temporaire V3.1, à virer ds la prochaine version HIE_fn_vInitGlobalMatrixFrameCounter(3); return CWinApp::InitApplication(); } //=========================================================================== // Description: Last exit of application. // Creation date: 27 Jun 96 // Author: CB //--------------------------------------------------------------------------- // Return BOOL //--------------------------------------------------------------------------- // Revision date: // Author: //=========================================================================== void CPA_ProjectApp::ExitApplication(void) { ClipCursor(NULL); // show cursor while (ShowCursor(TRUE) < 0); m_bLeavingApplication = TRUE; // delete m_p_oMainWorld; // m_p_oMainWorld = NULL; CPA_SuperObjectBase::DestroyParallelBoxGeometricObject(); CPA_SuperObjectBase::DestroyBoundingSphereGeometricObject(); // Free all semaphores CloseHandle(m_hDrawSem); // Restore windows parameters fn_vResetWindowsParameters(); } //=========================================================================== // Description: Call for each new instance of application. // Creation date: 10 Jun 96 // Author: CB //--------------------------------------------------------------------------- // Return void //--------------------------------------------------------------------------- // Revision date: // Author: //=========================================================================== BOOL CPA_ProjectApp::InitInstance() { char szPath[MAX_PATH]; GetCurrentDirectory(MAX_PATH,szPath); m_csEditorDataPath = (CString)szPath + "\\EDT_Data\\"; m_csEngineDataPath = (CString)szPath + "\\GameData\\"; CSize Screen(GetSystemMetrics(SM_CXFULLSCREEN), GetSystemMetrics(SM_CYFULLSCREEN)); char date[255]; FILE *p_File; p_File = fopen("RII_VersionNum.ini","rt"); if (p_File) { fgets(p_cVersionName,79,p_File); if (!fgets(p_cVersionName,79,p_File)) { strcpy(p_cVersionName,"no editor version name available... check file RII_VersionNum.ini "); } else { p_cVersionName[strlen(p_cVersionName)-1] = ' '; } fclose(p_File); } else { strcpy(p_cVersionName,"no version name available... check file RII_VersionNum.ini "); } sprintf(date, "%s [%s - %s]",p_cVersionName, __DATE__, __TIME__); g_oBaseFrame.Create(NULL, date, WS_MINIMIZEBOX|WS_MAXIMIZEBOX|WS_SYSMENU|WS_CLIPCHILDREN|WS_THICKFRAME, CRect(0, 0, Screen.cx, Screen.cy)); g_oBaseFrame.ShowWindow(SW_SHOWMAXIMIZED); // Register document templates CSingleDocTemplate* pDocTemplate; pDocTemplate = new CSingleDocTemplate( CPA_IDR_MAINFRAME, RUNTIME_CLASS(CPA_ProjectDoc), RUNTIME_CLASS(CPA_MainFrame), RUNTIME_CLASS(DEV_MultiDevice3D)); AddDocTemplate(pDocTemplate); // // Add all DLLs to list. // fn_vLoadAllDLLs(); // New file OnFileNew(); if (m_pMainWnd == NULL) return FALSE; //Erm_fn_vSetThreadId4Request(m_nThreadID); m_nCmdShow = SW_SHOWNORMAL; // Clear main device GLD_bClearDevice(M_GetMainDevice()->GetDevice(0)->m_hDisplayDevice); GLD_bFlipDevice(M_GetMainDevice()->GetDevice(0)->m_hDisplayDevice); // Special frame g_oFrameGest.mfn_vAddOneFrame(M_GetMainWnd()); g_oFrameGest.mp_oFirstWindow = M_GetMainWnd(); M_GetMainWnd()->m_iCol = 2; M_GetMainWnd()->m_iRow = 2; M_GetMainDevice()->SetFocusDevice(0); M_GetMainWnd()->SetParent(&g_oBaseFrame); // M_GetMainWnd()->ShowWindow(FALSE); //--------------------------------------------------------------- //------------INIT----------------------------------------------- //--------------------------------------------------------------- CPA_Interface *p_oInterface; CSize sizeScreen(GetSystemMetrics(SM_CXFULLSCREEN), GetSystemMetrics(SM_CYFULLSCREEN)); // create multidevice main contact M_GetMainDevice()->SetContact(new CPA_Contact()); // create new event editor p_oInterface = new CPA_Interface(); p_oInterface->StaticInit(); // create main world with this event editor m_p_oMainWorld = new CPA_MainWorld(0,M_GetMainDevice(), p_oInterface); // activate frame ((FRMBase*)M_GetMainWnd())->m_p_oMainWorld = m_p_oMainWorld; M_GetMainWnd()->m_iInitWidth = 0; M_GetMainWnd()->m_iInitHeight = 0; g_oFrameGest.mfn_vActivateWindow(M_GetMainWnd()); //call justafterregistered on every DLL M_GetListOfAllDLL()->CallJustAfterRegistered(); //call construct on every DLL M_GetListOfAllDLL()->CallConstruct(); // final init for interface p_oInterface->Init(); // M_GetMainWnd()->fn_vShowGeneralInterface(TRUE); TUT_M_vGetTutDll(); TUT_M_vRegisterControl( M_GetMainActiveViewport() -> m_hWnd, "CPA_Main3DView", TUT_e_3DView ); CPA_SuperObjectBase::CreateParallelBoxGeometricObject(); CPA_SuperObjectBase::CreateBoundingSphereGeometricObject(); // // Create a new process for engine // fn_vCreateEngineThread(); g_oBaseFrame.SetFocus(); if (GLI_lWhatIsGLI() != GLI_C_VersionGlide) m_p_oEngineThread->ResumeThread(); #ifdef NDEBUG while (ShowCursor(FALSE) >= 0); #endif return TRUE; } //########################################################################### // MAIN LOOP //########################################################################### BOOL CPA_ProjectApp::PreTranslateMessageEditor(MSG *p_stMsg) { BOOL bRes = FALSE; switch(p_stMsg->message) { // Sys Keyup case WM_SYSKEYUP: switch(p_stMsg->wParam) { case VK_RETURN: // ALT + ENTER M_GetMainDevice2()->GetDevice(0)->SwapFullScreen(); m_bFullScreenInEditor = M_GetMainDevice2()->GetDevice(0)->IsFullScreen(); bRes = TRUE; break; } break; //CPA2 Corneliu Babiuc 19-05-98 case WM_SYSKEYDOWN: //if ALT key is not pressed skip : the 29th bit of lParam tells this if (p_stMsg->lParam & 20000000) { //check if the combination is an user defined shortkey //and let processing to continue if is not POSITION pos = M_GetMainApp()->m_lstKeyboard.GetHeadPosition(); while (pos) { CPA_KeyActionConfiguration * p_oKAConfig = M_GetMainApp()->m_lstKeyboard.GetNext( pos ); bRes = bRes || p_oKAConfig->mfn_bKeyIsUsed((int)p_stMsg->wParam, C_KeybALT); } //message should still be dispatched if ( bRes ) ::DispatchMessage(p_stMsg); } //END CPA2 Corneliu Babiuc 19-05-98 } return bRes; } //=========================================================================== // Description: A filter for all windows messages when motor is running. // Creation date: 06 Jun 96 // Author: CB //--------------------------------------------------------------------------- // p_stMsg Address of message to test // Return TRUE to not dispatch message, FALSE else. //--------------------------------------------------------------------------- // Revision date: // Author: //=========================================================================== BOOL CPA_ProjectApp::PreTranslateMessageEngine(MSG *p_stMsg) { BOOL bRes = FALSE; switch(p_stMsg->message) { /*se WM_ACTIVATE: { short wActive = LOWORD(p_stMsg->wParam); // activation flag BOOL bMinimized = (BOOL) HIWORD(p_stMsg->wParam); // minimized flag (nonzero is minimized) HWND hwndPrevious = (HWND) p_stMsg->lParam; // window handle if ( wActive == WA_INACTIVE ) //app is deactivated { } else //app is activated { } return TRUE; } break;*/ /*se WM_ACTIVATEAPP: //when another application is activated, both the current and newly activated apps receive this message //if(((!wParam)&&((DWORD)lParam!=hEngineThreadId)&&((DWORD)lParam!=GetCurrentThreadId()))) // SendMessage(Glob_hwnd, WM_CLOSE, 0, 0); break;*/ // Sys Keyup case WM_SYSKEYUP: switch(p_stMsg->wParam) { case VK_RETURN: // ALT + ENTER if ( (m_bBadResolution) && (M_GetMainDevice()->GetDevice(0)->IsFullScreen()) ) { M_GetMainApp()->fn_vAppliAskToStopEngine(); M_GetMainDevice()->GetDevice(0)->SwapFullScreen(); m_bWasInFullScreenBeforeLooseFocus = TRUE; // M_GetMainWnd()->SendMessage(WM_SYSCOMMAND, SC_MINIMIZE); } else { // M_GetMainApp()->fn_vSuspendEngine(); M_GetMainDevice()->GetDevice(0)->SwapFullScreen(); // M_GetMainApp()->fn_vResumeEngine(); } bRes = TRUE; break; case VK_TAB: // ALT + TAB // if we are in fullscreen, then swap to windowed // and tell we were in full screen // M_GetMainApp()->fn_vAppliAskToStopEngine(); // if (M_GetMainDevice()->GetDevice(0)->IsFullScreen()) // { // M_GetMainDevice()->GetDevice(0)->SwapFullScreen(); // m_bWasInFullScreenBeforeLooseFocus = TRUE; // M_GetMainWnd()->SendMessage(WM_SYSCOMMAND, SC_MINIMIZE); // } bRes = TRUE; break; case VK_F10: // F10 = open menu // if we are in fullscreen, do nothing if (M_GetMainDevice()->GetDevice(0)->IsFullScreen()) bRes = TRUE; break; } break; // Keyboard messages case WM_KEYDOWN: case WM_KEYUP: case WM_CHAR: case WM_DEADCHAR: // if key is caps lock or num lock or scroll lock, let pass // else, skip if (p_stMsg->wParam == VK_NUMLOCK || p_stMsg->wParam == VK_SCROLL || p_stMsg->wParam == VK_CAPITAL || p_stMsg->wParam == VK_SHIFT || p_stMsg->wParam == VK_LSHIFT || p_stMsg->wParam == VK_RSHIFT) bRes = FALSE; else bRes = TRUE; break; // No mouse messages case WM_LBUTTONDOWN: case WM_RBUTTONDOWN: case WM_LBUTTONUP: case WM_RBUTTONUP: case WM_MOUSEMOVE: case WM_LBUTTONDBLCLK: case WM_RBUTTONDBLCLK: // No messages if we are in full screen if(((DEV_MultiDevice3D *)M_GetMainWnd()->m_oSplitter.GetPane(0, 0))->GetFocusDevice()->IsFullScreen()) return TRUE; // Can resize splitters, so we must translate messages to them POINT pt; CWnd *pWnd; if(p_stMsg->hwnd == M_GetMainWnd()->m_oSplitter.GetSafeHwnd()) return FALSE; if(p_stMsg->hwnd == M_GetMainWnd()->GetSafeHwnd()) return FALSE; GetCursorPos(&pt); pWnd = M_GetMainWnd()->WindowFromPoint(pt); if(pWnd->IsKindOf(RUNTIME_CLASS(FRMSplitter))) return FALSE; return TRUE; /* POINT pt; CWnd *pWnd; GetCursorPos(&pt); pWnd = M_GetMainWnd()->WindowFromPoint(pt); if(!(pWnd->IsKindOf(RUNTIME_CLASS(DEV_ViewPort3D)))) return FALSE; return TRUE;*/ break; default: bRes = FALSE; break; } return bRes; } //=========================================================================== // Description: Windows main loop to dispatch messages. // Creation date: 06 Jun 96 // Author: CB //--------------------------------------------------------------------------- // void // Return int that is return value of application (return by Winmain) //--------------------------------------------------------------------------- // Revision date: // Author: //=========================================================================== /*int CPA_ProjectApp::fn_iWindowsMainLoop(void) { MSG stMsg; BOOL bRes; while (::GetMessage(&stMsg, NULL, 0, 0)) { bRes = CWinApp::PreTranslateMessage(&stMsg); if (!bRes) { bRes = M_GetListOfAllDLL()->CallPreTranslateMessage(&stMsg); if((!bRes) && (stMsg.message == WM_KEYDOWN)) bRes = M_GetMainApp()->fn_bTreatAppKeyboard((UINT) stMsg.wParam); if((!bRes) && (!M_bEditorsActive())) bRes = CPA_ProjectApp::PreTranslateMessageEngine(&stMsg); } if(!bRes) { ::TranslateMessage(&stMsg); ::DispatchMessage(&stMsg); } } // Application exit code ExitApplication(); return stMsg.wParam; } */ //=========================================================================== // Description: To suspend/reactive engine // Creation date: 24 Jun 96 // Author: CB //--------------------------------------------------------------------------- // Return void //--------------------------------------------------------------------------- // Revision date: // Author: //=========================================================================== /*void CPA_ProjectApp::fn_vSuspendEngine(void) { BOOL bLastEnginePause; BOOL bRes; MSG stMsg; if ( m_p_oEngineThread ) { // Engine is already in pause : do nothing if ( m_bEngineIsInPause == 0 ) { // We force engine to pause to be sure that it has terminated all its // VBL cycle. Then we suspend thread execution. m_bEngineIsInPause = 0; bLastEnginePause = m_bEnginePause; m_bEnginePause = 1; m_bAppSaysBye = 0; while ( m_bEngineIsInPause == 0 ) { if ( ::PeekMessage(&stMsg, NULL, 0, 0, PM_REMOVE) ) { bRes = CWinApp::PreTranslateMessage(&stMsg); if (!bRes) { bRes = M_GetListOfAllDLL()->CallPreTranslateMessage(&stMsg); if((!bRes) && (stMsg.message == WM_KEYDOWN)) bRes = M_GetMainApp()->fn_bTreatAppKeyboard((UINT) stMsg.wParam); if((!bRes) && (!M_bEditorsActive())) bRes = CPA_ProjectApp::PreTranslateMessageEngine(&stMsg); } if ( !bRes ) { ::TranslateMessage(&stMsg); ::DispatchMessage(&stMsg); } } Sleep(0); } m_p_oEngineThread->SuspendThread(); m_bEnginePause = (unsigned char) bLastEnginePause; } } } */ /*void CPA_ProjectApp::fn_vResumeEngine(void) { if (m_p_oEngineThread) { DWORD dwResumeResult; do { dwResumeResult = m_p_oEngineThread->ResumeThread(); } while ( dwResumeResult > 1 && dwResumeResult != 0xFFFFFFFF ); } } */ BOOL CPA_ProjectApp::PreTranslateMessage( MSG* pMsg ) { BOOL bRes; //call base member bRes = CWinApp::PreTranslateMessage(pMsg); if (!bRes) { bRes = M_GetListOfAllDLL()->CallPreTranslateMessage(pMsg); if((!bRes) && ( (pMsg->message == WM_KEYDOWN) //CPA2 Corneliu Babiuc (Alt Key) 14-05-98 //let now Alt key to be processed by application || (pMsg->message == WM_SYSKEYDOWN) ) ) //END CPA2 Corneliu Babiuc (Alt Key) 14-05-98 { bRes = M_GetMainApp()->fn_bTreatAppKeyboard((UINT) pMsg->wParam); } if((!bRes) && (!M_bEditorsActive())) bRes = CPA_ProjectApp::PreTranslateMessageEngine(pMsg); if((!bRes) && (M_bEditorsActive())) bRes = CPA_ProjectApp::PreTranslateMessageEditor(pMsg); } return bRes; } //=========================================================================== // Description: Main loop of CPP application. // Creation date: 06 Jun 96 // Author: CB //--------------------------------------------------------------------------- // void // Return int that is return value of application (return by Winmain) //--------------------------------------------------------------------------- // Revision date: // Author: //=========================================================================== int CPA_ProjectApp::Run(void) { MSG stMsg; BOOL bRes; // loop while message is not WM_QUIT while (::GetMessage(&stMsg, NULL, 0, 0)) { bRes = PreTranslateMessage(&stMsg); if(!bRes) { ::TranslateMessage(&stMsg); ::DispatchMessage(&stMsg); } } // Application exit code ExitApplication(); return stMsg.wParam; } //########################################################################### //=========================================================================== // Description: Call to update all editors that need. // Creation date: 20 Jun 96 // Author: CB //--------------------------------------------------------------------------- // Return void //--------------------------------------------------------------------------- // Revision date: // Author: //=========================================================================== void CPA_ProjectApp::fn_vDataHasChanged(void) { M_GetListOfAllDLL()->CallRefreshDatas(); //*********************************** //*** DR (20/01/98) ***************** if( g_hWawModule != NULL ) { void (*WawRefreshFunction)(void) = (void (__cdecl*)(void))GetProcAddress( g_hWawModule, "WAW_fn_vRefreshWatchWindow" ); if( WawRefreshFunction != NULL ) WawRefreshFunction(); else AfxMessageBox("Refresh function has not been found in DLL (WAW module)"); } //*** End DR (20/01/98) ************* //*********************************** } //=========================================================================== // Description: Call to update all editors that need. // Creation date: 20 Jun 96 // Author: CB //--------------------------------------------------------------------------- // Return void //--------------------------------------------------------------------------- // Revision date: // Author: //=========================================================================== void CPA_ProjectApp::OnHelpAbout(void) { m_p_oDlgAbout = new CPA_DlgAbout( m_pMainWnd ); m_p_oDlgAbout -> fn_vSetMainWorld( m_p_oMainWorld ); m_p_oDlgAbout -> DoModal(); delete m_p_oDlgAbout; } //=========================================================================== // Description: This is the function that loads and register all DLLs. // Creation date: 23 Sep 96 // Author: CB //--------------------------------------------------------------------------- // Revision date: // Author: //=========================================================================== void CPA_ProjectApp::fn_vLoadAllDLLs(void) { char szCurPath[MAX_PATH]; //let's save the current path GetCurrentDirectory(MAX_PATH, szCurPath); // move to editor data directory if(chdir(m_csEditorDataPath) == -1) M_vFatalError("Unable to find 'EDT_DATA\\' directory. Can't load DLL."); // load the DLLs m_oListOfAllDLL.LoadAllDLL(); // we restore initial directory chdir(szCurPath); //check if there's at least one object DLL present... if (m_oListOfAllDLL.GetObjectDLLCount() == 0) M_vFatalError("no objects DLL loaded"); } //=========================================================================== // Description: This is the function that loads and register all DLLs. // Creation date: 23 Sep 96 // Author: Shaitan //--------------------------------------------------------------------------- // Revision date: // Author: //=========================================================================== CPA_Interface * CPA_ProjectApp::GetInterface (void) { return m_p_oMainWorld->GetInterface(); } //=========================================================================== // Description: Called by the appli when the appli wants to stop the engine // result : // The Engine has not been stopped, but it has been notified to do so. We will receive a // user message when the engine wants to be stopped // Creation date: 19 jun 97 // Author: FBF //--------------------------------------------------------------------------- // Revision date: // Author: //=========================================================================== void CPA_ProjectApp::fn_vAppliAskToStopEngine(void) { m_bAppliAskedToStopEngine = TRUE; } //=========================================================================== // Description: Called by the appli when the appli wants to start the engine // result : // The Engine will restart // Creation date: 19 jun 97 // Author: FBF //--------------------------------------------------------------------------- // Revision date: // Author: //=========================================================================== void CPA_ProjectApp::fn_vAppliAskToStartEngine(void) { m_bAppliAskedToStopEngine = FALSE; if (m_bEngineIsStopped) fn_vRestartEngine(); } //=========================================================================== // Description: Called by the appli when the appli wants to end the game // result : // The Engine has been notified to begin the closing process // we will receive a user message when the engine begin this process, // and when the engine has finished this process // Creation date: 19 jun 97 // Author: FBF //--------------------------------------------------------------------------- // Revision date: // Author: //=========================================================================== void CPA_ProjectApp::fn_vAppliAskToEndGame(void) { // tell that we want to close m_bAppliAskedToEndGame = TRUE; // if editors are active, then we must restart the engine so that it can close // to allow the engine to restart M_GetMainApp()->m_bEditorsAreActive = FALSE; // to prevent the engine from going back to editors M_GetMainApp()->m_bAppliAskedToActivateEditors = FALSE; M_GetMainApp()->fn_vRestartEngine(); } //=========================================================================== // Description: Called by the appli when the appli wants to step the engine one trame // result : // if the engine was in pause, then it restart until it reach the next pause check // // Creation date: 08 jul 97 // Author: FBF //--------------------------------------------------------------------------- // Revision date: // Author: //=========================================================================== void CPA_ProjectApp::fn_vAppliAskOneStep(void) { // pulse if engine has been stopped by the appli // and if the engine is stopped // and if one step has not allready been asked if ((m_bAppliAskedToStopEngine == TRUE) && (m_bEngineIsStopped == TRUE) && (m_bAppliPulsedOneStep == FALSE)) { m_bAppliPulsedOneStep = TRUE; fn_vRestartEngine(); } } //=========================================================================== // Description: Called by the appli when the appli wants to start editors // result : // the engine has been notified that we want to start editors. We will receive a // user message when the engine is ready // Creation date: 19 jun 97 // Author: FBF //--------------------------------------------------------------------------- // Revision date: // Author: //=========================================================================== void CPA_ProjectApp::fn_vAppliAskToStartEditors(void) { m_bAppliAskedToActivateEditors = TRUE; } //=========================================================================== // Description: Called by the appli when the appli wants to leave editors and resume engine // result : // the engine will restart // Creation date: 19 jun 97 // Author: FBF //--------------------------------------------------------------------------- // Revision date: // Author: //=========================================================================== void CPA_ProjectApp::fn_vAppliAskToStopEditors(void) { m_bAppliAskedToActivateEditors = FALSE; if (m_bEditorsAreActive == FALSE) return; m_bEngineAskedToForceEditors = FALSE; M_GetMainWnd()->DisactivateEditors(); } //=========================================================================== // Description: a user message has been received // return value: // Creation date: 19 jun 97 // Author: FBF //--------------------------------------------------------------------------- // Revision date: // Author: //=========================================================================== afx_msg void CPA_ProjectApp::OnUserMsg(UINT wParam,LONG lParam) { // structure for Message box request tdstMsgBox * p_stMsgBox; switch(wParam) { case C_uiWinCm_RequestMessageBox: p_stMsgBox = (tdstMsgBox*) lParam; // SendMessage(m_pMainWnd->m_hWnd, WM_SYSCOMMAND, SC_MINIMIZE, 0); p_stMsgBox->iResult = MessageBox(NULL,p_stMsgBox->szText,p_stMsgBox->szTitle,p_stMsgBox->uiStyle); // SendMessage(m_pMainWnd->m_hWnd, WM_SYSCOMMAND, SC_RESTORE, 0); // SetEvent(p_stMsgBox->hEvent); break; case USERM_STOP_ENGINE: // if the flag is not right, do nothing if (m_bAppliAskedToStopEngine == FALSE) break; fn_vStopEngine(); break; case USERM_ENGINE_IS_CLOSING: m_bLeavingApplication = TRUE; break; case USERM_ENGINE_IS_DONE: m_bLeavingApplication = TRUE; m_bEngineIsOver = TRUE; m_bFinishEngine = TRUE; M_GetMainWnd()->PostMessage(WM_CLOSE,0,0); break; case USERM_SWAP_FULLSCREEN: if (GLI_lWhatIsGLI() != GLI_C_VersionGlide) { /* BeforeWindows(); if (M_GetMainDevice()->GetDevice(0)->IsFullScreen()) { M_GetMainDevice()->GetDevice(0)->SwapFullScreen(); M_GetMainWnd()->SendMessage(WM_SYSCOMMAND, SC_MINIMIZE); } else { if ((M_GetMainWnd()->IsIconic())) { M_GetMainWnd()->SendMessage(WM_SYSCOMMAND, SC_RESTORE); } else { M_GetMainDevice()->GetDevice(0)->SwapFullScreen(); } } AfterWindows(); break;*/ } else { M_GetMainDevice()->GetDevice(0)->SwapFullScreen(); } case USERM_START_EDITORS: // if the flag is not right, do nothing if (m_bAppliAskedToActivateEditors == FALSE) break; fn_vStartEditors(); break; case USERM_FORCE_START_EDITORS: // if the flag is not right, do nothing if (m_bEngineAskedToForceEditors == FALSE) break; fn_vStopEngine(); fn_vStartEditors(); break; } } //=========================================================================== // Description: Stops the engine // return value: // Creation date: 19 jun 97 // Author: FBF //--------------------------------------------------------------------------- // Revision date: // Author: //=========================================================================== void CPA_ProjectApp::fn_vStopEngine() { // if the engine is allready stopped, do nothing if (m_bEngineIsStopped) return; // stop the engine m_p_oEngineThread->SuspendThread(); m_bEngineIsStopped = TRUE; } //=========================================================================== // Description: resume the engine // return value: // Creation date: 19 jun 97 // Author: FBF //--------------------------------------------------------------------------- // Revision date: // Author: //=========================================================================== void CPA_ProjectApp::fn_vRestartEngine() { // if engine runs, do nothing if (!m_bEngineIsStopped) return; ASSERT(m_bEditorsAreActive == FALSE); if (m_p_oEngineThread) { m_bEngineIsStopped = FALSE; m_p_oEngineThread->ResumeThread(); } } //=========================================================================== // Description: Starts the editors // return value: // Creation date: 19 jun 97 // Author: FBF //--------------------------------------------------------------------------- // Revision date: // Author: //=========================================================================== void CPA_ProjectApp::fn_vStartEditors() { // if editors already active, do nothing if (m_bEditorsAreActive == TRUE) return; fn_vStopEngine(); M_GetMainWnd()->ActivateEditors(); } #endif ACTIVE_EDITOR // }