#define _WIN32_WINNT 0x0501 #include "TRACK.h" #include "SCENE.h" #include "ShotTracker.h" #ifdef ONLINE_MODE #include "account.h" #endif #include u32 FILEIO_IsModePackedEXE(); void FreePrevs(); extern void DW_WatchDirectoryCheck(); #ifdef ONLINE_MODE extern CCamCamAccount Account; #endif int frameTime = 0; void WORLD::FrameCall() { u32 Counter; u32 ulMustReloadTM = 0; extern u32 IsMinimized; extern int mouseX; extern int mouseY; if (!IsMinimized) { RECT Rect; POINT Point; GetClientRect(OwnerHwnd , &Rect); float CX = (float)XSize / (float)(Rect.right - Rect.left); float CY = (float)YSize / (float)(Rect.bottom - Rect.top); GetCursorPos(&Point); ScreenToClient(OwnerHwnd, &Point); mouseX = (int)(CX * (float)Point.x); // horizontal position of cursor mouseY = (int)(CY * (float)Point.y); // vertical position of cursor } else { mouseX = -1; mouseY = -1; } memset(&FrmSmooth, 0, sizeof(FrmSmooth)); FrmQuatMode = 0; if (LuaScriptManage) { if (LuaScriptManage < 0) LuaSetLevel(LuaScriptManage); else { BOOL clearAll = 2; switch (LuaScriptManage) { case 1: break; case 2: LuaSetLevel(1); break; case 255: clearAll = 0; LuaSetLevel(0); break; } #ifdef USER_MODE BOOL IsFileAllowed(char *filename, bool fromLua); if (IsFileAllowed(ScriptNameStack[currentScript], 0)) LoadLua(ScriptNameStack[currentScript], clearAll); else { void displayIntegrityError(int num); displayIntegrityError(4); exit(0); } #else LoadLua(ScriptNameStack[currentScript], clearAll); #endif } LuaScriptManage = 0; } if (*LuaScriptRestart) { extern void API_RESTART(char* luaFileToBoot); API_RESTART(LuaScriptRestart); } STOP_RASTER(TheRest); START_RASTER(Media); PickReportCurrent.PickFrozed ++; TrackRes = 0; for (u32 Priority = 0 ;Priority < 4;Priority++) { for (Counter = 0 ; Counter < MAX_INPMED ; Counter++) { if (ID_MEDIA[Counter]) { ID_MEDIA[Counter]->ulMediaRedirectValue = -1; } if (ID_MEDIA[Counter] && (ID_MEDIA[Counter]->Priority == Priority) && (ID_MEDIA[Counter]->VirtuallyDestroyed == 0)) { if (SkipFunctions & SKIP_MEDIA) continue; if ((ID_MEDIA[Counter]->GetType() == IOtype_AVI) && (SkipFunctions & SKIP_AVI)) continue; if ((ID_MEDIA[Counter]->GetType() == IOtype_REVR) && (SkipFunctions & SKIP_REVERSE)) continue; if ((ID_MEDIA[Counter]->GetType() == IOtype_CAM) && (SkipFunctions & SKIP_CAMERA)) continue; u32 FrameRaster = timeGetTime(); u32 Framed = ID_MEDIA[Counter]->FRAME(); ID_MEDIA[Counter]->HasBeenUpdated = Framed; if ((Framed || (MediaToTrack == Counter))) { if (Framed && (MediaToTrack == Counter)) { static u32 u32stticLastTime = 0; if (u32stticLastTime) { u32stticLastTime = timeGetTime() - u32stticLastTime; trackMiliseconds_x_16 -= trackMiliseconds_x_16>>4; trackMiliseconds_x_16 += (u32stticLastTime)<<4; } else { trackMiliseconds_x_16 = (1000 / 30)<<8; } u32stticLastTime = timeGetTime(); } if (MediaToTrack == Counter && ID_MEDIA[MediaToTrack]->Image.GetBase() && !(SkipFunctions & SKIP_TRACKER)) { STOP_RASTER(Media); START_RASTER(Tracker); /* Save Tracked media Picture */ #define SAVE_TRACKED_MEDIA #ifdef SAVE_TRACKED_MEDIA ulMustReloadTM = 0; u32 Size; Size = ID_MEDIA[Counter]->Image.PITCH * ID_MEDIA[Counter]->Image.SY * 4; if (Size) { if (Size != SaveTrackedMediaSize) { if (SaveTrackedMedia) CC_free(SaveTrackedMedia); SaveTrackedMedia = (u32 *)CC_malloc(Size); SaveTrackedMediaSize = Size; } memcpy(SaveTrackedMedia,ID_MEDIA[MediaToTrack]->Image.GetBase(),Size); } #endif SetCurrentFocale(ID_MEDIA[Counter]->MediaFocale); extern void *pZBUFFERMEDIA; if (ID_MEDIA[Counter]->GetType() == IOtype_PRIMESENS) TrackRes = TRACK_OneFrameCall(ID_MEDIA[Counter]->Image,&((INPUT_IO *)ID_MEDIA[Counter]->GetData(0))->Image); else TrackRes = TRACK_OneFrameCall(ID_MEDIA[Counter]->Image,NULL); STOP_RASTER(Tracker); START_RASTER(Media); if (TrackRes) { if ((ID_MEDIA[Counter]->ulAssociatedTextureIndex != -1) ) { ulMustReloadTM = 1; DI->UpdateTexture_BM_2_HW(ID_MEDIA[Counter]->ulAssociatedTextureIndex); } } } else if ((ID_MEDIA[Counter]->ulAssociatedTextureIndex != -1) ) { DI->UpdateTexture_BM_2_HW(ID_MEDIA[Counter]->ulAssociatedTextureIndex); } } ID_MEDIA[Counter]->FrameRaster = (float)(timeGetTime() - FrameRaster) * 0.1f + ID_MEDIA[Counter]->FrameRaster * 0.9f; } } if (Priority == 0) { /* Parse animated ID's */ for (Counter = 0 ; Counter < MAX_ID ; Counter++) { if (ID_TABLE[Counter] && ID_TABLE[Counter]->SF_U.IsAnimatedTrack) { u32 TM; TM = ID_TABLE[Counter]->AnimatedMedia; if ((TM != -1) && (TM < MAX_INPMED) && ID_MEDIA[TM]) { SetCurrentFocale(ID_MEDIA[TM]->MediaFocale); if (ID_MEDIA[TM]->Tracks) { //ID_MEDIA[TM]->Tracks->Get( // ID_TABLE[Counter]->AnimatedMedia_SubIndex, // ID_MEDIA[TM]->ulCurrentFrame+ID_MEDIA[TM]->lCurrentTrackOffset, // &ID_TABLE[Counter]->CurrentMatrix_U); ID_MEDIA[TM]->Tracks->Get( ID_TABLE[Counter]->AnimatedMedia_SubIndex, ID_MEDIA[TM]->dCurrentTime*ID_MEDIA[TM]->dAvgFramePerSecond, &ID_TABLE[Counter]->CurrentMatrix_U); ID_MEDIA[TM]->Tracks->GetScale( ID_TABLE[Counter]->AnimatedMedia_SubIndex, &ID_TABLE[Counter]->vModelScale); } //if (ID_TABLE[CurrentID] && ID_TABLE[CurrentID]->SF_U.DrawMesh) if (ID_TABLE[Counter] && ID_TABLE[Counter]->SF_U.DrawMesh) { ID_TABLE[Counter]->p_UsedMesh->MatrixSrc = ID_TABLE[Counter]->CurrentMatrix_U; ID_TABLE[Counter]->p_UsedMesh->Render(ID_MEDIA[TM]->Image, 0xffff, 1,1); DI->UpdateTexture_BM_2_HW(ID_MEDIA[TM]->ulAssociatedTextureIndex); } } } } } } STOP_RASTER(Media); PickReportCurrent.PickFrozed --; /* Picking */ extern s32 mouseX; extern s32 mouseY; DI->MousePicking.x = mouseX; DI->MousePicking.y = mouseY; DI->PickingEnable = 0; // Process events memcpy(&PickReportToWatch , &PickReportResult , sizeof(PickReportResult)); if (!CaptureMode) { if (memcmp(&PickReportFinal, &PickReportResult, sizeof(PickReportResult ))) { if (luaScriptTable[currentScript]) { LuaProcessEvent(EVT_onRollOut); LuaProcessEvent(EVT_onRollOver); } memcpy(&PickReportFinal , &PickReportResult, sizeof(PickReportResult )); } } #ifndef TEST_PHILIPPE extern DWORD CurrentSessionID; static int currentUserNameCounter = 0; if (!(currentUserNameCounter++ & 0xFF)) { if (CurrentSessionID != WTSGetActiveConsoleSessionId()) { CurrentSessionID = WTSGetActiveConsoleSessionId(); LuaProcessEvent(EVT_onSessionChange); } } #endif LuaEventsExec(); memset(&PickReportCurrent,0,sizeof(PickReportCurrent)); memset(&PickReportResult,0,sizeof(PickReportResult)); u32 TextOrigin = DI->RectifyTextOrigin; if (bManualBoot & !oldManualBoot) { if (ID_MEDIA[MediaToTrack]) { DI->ClearZ(); DI->SetBackGround(ID_MEDIA[MediaToTrack]->ulAssociatedTextureIndex); } } else { START_RASTER(Script); SceneScript_EXECUTE(); STOP_RASTER(Script); LuaProcessEvent(EVT_loop); LuaEventsExec(); DI->RectifyTextOrigin = 0; DI->ClearZ(); DI->SetQuadRot(0,NULL,NULL); LUA_DEBUG(); #ifndef USER_MODE if (*LuaErrors) { int nbLines = 0; char *luaErrorPtr = LuaErrors; while (strchr(luaErrorPtr, '\n')) { luaErrorPtr = strchr(luaErrorPtr, '\n') + 1; nbLines++; } DI->DrawText((unsigned char *)LuaErrors, 0, nbLines*16, 1, 1, 0xff000000 | RGB(255,0,0)); } #endif if (SkipFunctions & SKIP_NOMOSAIC) { DI->ClearZ(); Mosaique(); } } InputHookPickEnd(); /* Restore Tracked media Picture */ #ifdef SAVE_TRACKED_MEDIA if (ulMustReloadTM && ID_MEDIA[MediaToTrack]) { u32 Size; Size = ID_MEDIA[MediaToTrack]->Image.PITCH * ID_MEDIA[MediaToTrack]->Image.SY * 4; if (Size && (Size == SaveTrackedMediaSize)) { memcpy(ID_MEDIA[MediaToTrack]->Image.GetBase(),SaveTrackedMedia,Size); } } #endif RS Nullmlml; GLOB_SetDefaultRS(&Nullmlml); DI->SetRS(&Nullmlml,-1); if (bDrawConsole) DrawConsole(); DI->SetViewport(0,0,XSize,YSize); DI->FORCE_RENDER_FLAG = 0; STOP_RASTER(Global); DrawRasters(bDrawRasters); START_RASTER(Global); #ifndef SKIMMED_NET ConnectedNumber = GetBitNumber(NetObj->ValidMask); NetObj->OneFrameCall(); #endif RenderFlip(); DI->RectifyTextOrigin = TextOrigin; START_RASTER(TheRest); DW_WatchDirectoryCheck(); FlashCom_OneFrame(); RenderingCounter++; RestoreAllSmallScene(false); ResetMaterialOverload(); } extern int DW_WatchDirectory(char *DirectoryToWatch,void Callback(void *,char *),void *); extern int DW_UnWatchDirectory(); // Not used, DW_WatchDirectory() calls a specific callback void DW_WatchDirectory_CALLBACK(void *pSCN,char *STR) { } WORLD *CreateWORLD(HWND hwnd,u32 SizeX,u32 SizeY, char *iniFile) { WORLD *NS; #ifndef NO_DIR_CREATE if (!FILEIO_IsModePackedEXE()) { CreateDirectory(".\\Mads\\",NULL); CreateDirectory(".\\IDs\\",NULL); CreateDirectory(".\\Anims\\",NULL); CreateDirectory(".\\Particles\\",NULL); CreateDirectory(".\\Sounds\\",NULL); CreateDirectory(".\\TAG\\",NULL); } #endif SHOTS_CLASS::Init(); extern void ComputeBitNum(); ComputeBitNum(); NS = new(WORLD); #ifndef SKIMMED_NET NS->NetObj = new(NET_IO); NS->NetObj->NET_Init(); NS->NetObj->Owner = NS; #endif NS->SceneScript_INIT(); NS->FlashCom_Init(); u32 Counter = 0; NS->OwnerHwnd = hwnd; NS->hbmScreen = NULL; NS->hdcCompatible = NULL; extern int D3DDisplay; char d3d[64]; if (D3DDisplay < 0) { if (iniFile && NS->GetIniValue(iniFile, "d3d", d3d)) D3DDisplay = *d3d - '0'; else D3DDisplay = -D3DDisplay-1; } else if (iniFile) { sprintf(d3d, "%i", D3DDisplay); NS->SetIniValue(iniFile, "d3d", d3d); NS->SaveIniFile(iniFile); } if (D3DDisplay == 2) NS->DI = CreateNulObject(hwnd,SizeX,SizeY); else { if (D3DDisplay == 1) NS->DI = CreateD3DObject(hwnd,SizeX,SizeY); else NS->DI = CreateOglObject(hwnd,SizeX,SizeY); } NS->DI->MotherClass = NS; NS->WebCamXInvert = 1; NS->MediaDico.Init(); NS->luaLoaddedFilesDICO.Init(); NS->PGeneratorDico.Init(); NS->SmallSceneDico.Init(); NS->PackFileDico.Init(); NS->AnimDico.Init(); NS->CollisionDico.Init(); NS->XSize = SizeX; NS->YSize = SizeY; NS->FrameBufferResult.SetSize(SizeX, SizeY); NS->MediaToTrack = 0; NS->ulMustUpdateFrameBufferResult = 0; NS->IniFileDico.Init(); NS->ResetMaterialOverload(); { memset(NS->ID_TABLE,0,sizeof(NS->ID_TABLE)); NS->ID_New(); //NS->ID_AutoStart(NS->ID_New()); } NS->WFlags = LUA_AUTO_RELOAD; #ifndef USER_MODE //#ifndef ONLINE_MODE // Must not auto reload lua files when downloading an asset DW_WatchDirectory(".\\",&DW_WatchDirectory_CALLBACK,(void*)NS); //#endif #endif NS->forceAdVisibility = false; //NS->bDrawConsole = 1; //void CreateTags(); //CreateTags(); return NS; } void WORLD::ChangeDriver(u32 NewIndex) { if (NewIndex>2) return; if (DI->GetDriverType() == NewIndex) return; for (u32 Counter = 0 ; Counter < MAX_INPMED; Counter++) { if (ID_MEDIA[Counter]) { if (ID_MEDIA[Counter]->ulAssociatedTextureIndex != -1) { if (ID_MEDIA[Counter]->GetType() == IOtype_LAYER) DI->DestroyLayerTexture(ID_MEDIA[Counter]->ulAssociatedTextureIndex); else DI->DestroyTexture(ID_MEDIA[Counter]->ulAssociatedTextureIndex); } } } u32 RectifyTextOrigin = DI->RectifyTextOrigin; DI->Destroy(); delete DI; DI = NULL; if (NewIndex == 2) DI = CreateNulObject(OwnerHwnd,XSize,YSize); if (NewIndex == 1) DI = CreateD3DObject(OwnerHwnd,XSize,YSize); if (NewIndex == 0) DI = CreateOglObject(OwnerHwnd,XSize,YSize); if (!DI) DI = CreateOglObject(OwnerHwnd,XSize,YSize); DI->MotherClass = this; for (u32 Counter = 0 ; Counter < MAX_INPMED; Counter++) { if (ID_MEDIA[Counter]) { u32 LAYER_GetIndex(INPUT_IO *Ret); if (ID_MEDIA[Counter]->GetType() != IOtype_LAYER) ID_MEDIA[Counter]->ulAssociatedTextureIndex = DI->CreateTexture(&ID_MEDIA[Counter]->Image,ID_MEDIA[Counter]->ulColorMode); else ID_MEDIA[Counter]->ulAssociatedTextureIndex = DI->CreateLayerTexture(&ID_MEDIA[Counter]->Image,LAYER_GetIndex(ID_MEDIA[Counter])); } } DI->RectifyTextOrigin = RectifyTextOrigin ; return; } u32 DestroyWORLD(WORLD *pW) { if (pW) { TerminateThread(pW->FlashthreadHandle, 0); FreePrevs(); /* Kill tracking thread */ pW->DestroyTrackeur(); pW->DestroyAllMedia(); pW->DestroyAllPGenerator(); pW->DestroyAllAnim(); pW->DestroyAllSMSC(); pW->DestroyAllAnim(); pW->FlashCom_Destroy(); if (pW->WSPC) WSPC_Destroy(pW->WSPC); pW->WSPC = NULL; u32 Counter = MAX_ID; while (Counter--) { pW->ID_Destroy(Counter); } Counter = MAX_INIFILES; while (Counter--) { pW->IniFiles[Counter].Destroy(); } pW->luaLoaddedFilesDICO.Destroy(); pW->MediaDico.Destroy(); pW->PGeneratorDico.Destroy(); Counter = MAX_INIFILES; while (Counter--) pW->IniFiles[Counter].Destroy(); pW->IniFileDico.Destroy(); pW->SmallSceneDico.Destroy(); pW->AnimDico.Destroy(); pW->PackFileDico.Destroy(); pW->PackFileDicoNeredondance.Destroy(); pW->FrameBufferResult.Delete(); if (pW->SaveTrackedMedia) CC_free(pW->SaveTrackedMedia); pW->LuaSetLevel(0); if (pW->ComputingBuffer2) CC_free(pW->ComputingBuffer2); if (pW->ComputingBuffer_Normales) CC_free(pW->ComputingBuffer_Normales); if (pW->ComputingBuffer_UV) CC_free(pW->ComputingBuffer_UV); if (pW->ComputingBuffer) CC_free(pW->ComputingBuffer); if (pW->pRenderDrawSort) CC_free(pW->pRenderDrawSort); pW->RenderDrawSortNumberMax = 0; if (pW->hbmScreen) DeleteObject(pW->hbmScreen); if (pW->hdcCompatible) DeleteDC(pW->hdcCompatible); pW->hbmScreen = NULL; pW->hdcCompatible = NULL; MicroInStop(&pW->microIn); MicroOutStop(&pW->microOut); delete pW->DI; pW->DI = NULL; #ifndef SKIMMED_NET pW->NetObj->NET_Close(); delete pW->NetObj; pW->NetObj = NULL; #endif delete pW; } extern Subfile* subfiles; if (subfiles) { CC_free(subfiles); subfiles = 0; } #ifndef USER_MODE DW_UnWatchDirectory(); // dir monitor callback would crash in UNIC_Dico when quitting #endif return 0; } WORLD *MyCreateWORLD(HWND HwNd,u32 SizeX,u32 SizeY, char *iniFile) { return CreateWORLD(HwNd,SizeX,SizeY,iniFile); }