From acc4111de8eb1bd04164454479c083b326120377 Mon Sep 17 00:00:00 2001 From: mcmartin Date: Sun, 16 Mar 2003 18:38:48 +0000 Subject: [PATCH] Fixed bug #33; Crossfades are consistent and don't glitch anymore git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@891 8092fc87-c524-0410-9efc-e669fe64eaf9 --- sc2/ChangeLog | 3 + sc2/src/sc2code/battle.c | 33 +++++---- sc2/src/sc2code/comm.c | 5 +- sc2/src/sc2code/credits.c | 1 + sc2/src/sc2code/encount.c | 22 +++--- sc2/src/sc2code/gameopt.c | 69 +++++++++---------- sc2/src/sc2code/libs/graphics/gfx_common.h | 1 + sc2/src/sc2code/libs/graphics/sdl/3do_funcs.c | 8 ++- sc2/src/sc2code/outfit.c | 1 + sc2/src/sc2code/planets/lander.c | 2 + sc2/src/sc2code/planets/planets.c | 3 +- sc2/src/sc2code/planets/pstarmap.c | 5 ++ sc2/src/sc2code/planets/solarsys.c | 16 +++-- sc2/src/sc2code/shipyard.c | 19 ++--- sc2/src/sc2code/starbase.c | 19 ++--- 15 files changed, 117 insertions(+), 90 deletions(-) diff --git a/sc2/ChangeLog b/sc2/ChangeLog index 5b4955846..1a3bd49dd 100644 --- a/sc2/ChangeLog +++ b/sc2/ChangeLog @@ -1,4 +1,7 @@ Changes towards version 0.3: +- Crossfade code now explicitly caches the screen to transition from, and + thus no longer glitches. The code needed a slight rewrite, but this + does fix bug #33 -McMartin - Melee scaling is now trilinear by default, but it's still possible to choose nearest neighbour with --meleescale; fixes #34 -Mika - Minimum scaling extent is now 1,1; fixes mostly small-objects-disappearing diff --git a/sc2/src/sc2code/battle.c b/sc2/src/sc2code/battle.c index 5a0e85365..9fd6c2200 100644 --- a/sc2/src/sc2code/battle.c +++ b/sc2/src/sc2code/battle.c @@ -188,7 +188,7 @@ Battle (void) if (num_ships) { DWORD NextTime; -BOOLEAN first_time; + BOOLEAN first_time; GLOBAL (CurrentActivity) |= IN_BATTLE; battle_counter = MAKE_WORD ( @@ -204,27 +204,30 @@ BOOLEAN first_time; BattleSong (TRUE); NextTime = 0; -first_time = (BOOLEAN)(LOBYTE (GLOBAL (CurrentActivity)) == IN_HYPERSPACE); + first_time = (BOOLEAN)(LOBYTE (GLOBAL (CurrentActivity)) == IN_HYPERSPACE); do { extern UWORD nth_frame; + RECT r; -BatchGraphics (); + if (first_time) + { + r.corner.x = SIS_ORG_X; + r.corner.y = SIS_ORG_Y; + r.extent.width = SIS_SCREEN_WIDTH; + r.extent.height = SIS_SCREEN_HEIGHT; + SetTransitionSource (&r); + } + BatchGraphics (); if (LOBYTE (GLOBAL (CurrentActivity)) == IN_HYPERSPACE) SeedUniverse (); RedrawQueue (TRUE); -if (first_time) -{ - RECT r; - - first_time = FALSE; - r.corner.x = SIS_ORG_X; - r.corner.y = SIS_ORG_Y; - r.extent.width = SIS_SCREEN_WIDTH; - r.extent.height = SIS_SCREEN_HEIGHT; - ScreenTransition (3, &r); -} -UnbatchGraphics (); + if (first_time) + { + first_time = FALSE; + ScreenTransition (3, &r); + } + UnbatchGraphics (); ClearSemaphore (GraphicsSem); if (nth_frame) TaskSwitch (); diff --git a/sc2/src/sc2code/comm.c b/sc2/src/sc2code/comm.c index 016e061ae..138b94436 100644 --- a/sc2/src/sc2code/comm.c +++ b/sc2/src/sc2code/comm.c @@ -1492,7 +1492,9 @@ static BOOLEAN DoCommunication (INPUT_STATE InputState, PENCOUNTER_STATE pES) { if (!(CommData.AlienTransitionDesc.AnimFlags & (TALK_INTRO | TALK_DONE))) + { AlienTalkSegue ((COUNT)~0); + } if (GLOBAL (CurrentActivity) & CHECK_ABORT) ; @@ -1719,7 +1721,8 @@ HailAlien (void) r.corner.y = SIS_ORG_Y; r.extent.width = SIS_SCREEN_WIDTH; -BatchGraphics (); + SetTransitionSource (NULL); + BatchGraphics (); if (LOBYTE (GLOBAL (CurrentActivity)) == WON_LAST_BATTLE) { r.corner.x = (SCREEN_WIDTH - SIS_SCREEN_WIDTH) >> 1; diff --git a/sc2/src/sc2code/credits.c b/sc2/src/sc2code/credits.c index e57b86314..f611e1c2a 100644 --- a/sc2/src/sc2code/credits.c +++ b/sc2/src/sc2code/credits.c @@ -84,6 +84,7 @@ FreeHyperData (); TimeIn = GetTimeCounter (); for (i = 1; i < NUM_CREDITS; ++i) { + SetTransitionSource (&r); BatchGraphics (); s.frame = f[0]; DrawStamp (&s); diff --git a/sc2/src/sc2code/encount.c b/sc2/src/sc2code/encount.c index fc1b61c5b..9ea8ef94e 100644 --- a/sc2/src/sc2code/encount.c +++ b/sc2/src/sc2code/encount.c @@ -169,7 +169,7 @@ InitEncounter (void) STAMP s; TEXT t; extern FRAME planet[]; -MUSIC_REF MR; + MUSIC_REF MR; SetSemaphore (GraphicsSem); @@ -178,17 +178,18 @@ MUSIC_REF MR; SetContext (SpaceContext); SetContextFont (TinyFont); -MR = LoadMusicInstance (REDALERT_MUSIC); -PlayMusic (MR, FALSE, 1); + MR = LoadMusicInstance (REDALERT_MUSIC); + PlayMusic (MR, FALSE, 1); SegueFrame = CaptureDrawable (LoadGraphic (SEGUE_PMAP_ANIM)); -ClearSemaphore (GraphicsSem); -while (PLRPlaying (MR)) - TaskSwitch (); -StopMusic (); -DestroyMusic (MR); -SetSemaphore (GraphicsSem); + ClearSemaphore (GraphicsSem); + while (PLRPlaying (MR)) + TaskSwitch (); + StopMusic (); + DestroyMusic (MR); + SetSemaphore (GraphicsSem); s.origin.x = s.origin.y = 0; - + + SetTransitionSource (NULL); BatchGraphics (); SetContextBackGroundColor (BLACK_COLOR); @@ -293,6 +294,7 @@ SetSemaphore (GraphicsSem); UnbatchGraphics (); DestroyDrawable (ReleaseDrawable (SegueFrame)); + ScreenTransition (3, NULL); SetResourceIndex (hOldIndex); diff --git a/sc2/src/sc2code/gameopt.c b/sc2/src/sc2code/gameopt.c index 0e3f964f4..c227ce58a 100644 --- a/sc2/src/sc2code/gameopt.c +++ b/sc2/src/sc2code/gameopt.c @@ -909,6 +909,7 @@ DoPickGame (INPUT_STATE InputState, PMENU_STATE pMS) } SetSemaphore (GraphicsSem); + SetTransitionSource (NULL); BatchGraphics (); Restart: SetContext (SpaceContext); @@ -927,20 +928,20 @@ Restart: SetFlashRect ((PRECT)~0L, (FRAME)0); ClearSemaphore (GraphicsSem); -pMS->ModuleFrame = 0; + pMS->ModuleFrame = 0; pMS->CurState = (BYTE)pMS->delta_item; -ResumeMusic (); -if (pSolarSysState) -{ + ResumeMusic (); + if (pSolarSysState) + { #define DRAW_REFRESH (1 << 5) #define REPAIR_SCAN (1 << 6) - extern BYTE draw_sys_flags; + extern BYTE draw_sys_flags; - if (pSolarSysState->MenuState.Initialized < 3) - draw_sys_flags |= DRAW_REFRESH; - else if (pSolarSysState->MenuState.Initialized == 4) - draw_sys_flags |= REPAIR_SCAN; -} + if (pSolarSysState->MenuState.Initialized < 3) + draw_sys_flags |= DRAW_REFRESH; + else if (pSolarSysState->MenuState.Initialized == 4) + draw_sys_flags |= REPAIR_SCAN; + } return (FALSE); } else if (InputState & DEVICE_BUTTON1) @@ -980,26 +981,21 @@ RetrySave: goto Restart; } ResumeMusic (); -if (pSolarSysState) -{ + if (pSolarSysState) + { #define DRAW_REFRESH (1 << 5) #define REPAIR_SCAN (1 << 6) - extern BYTE draw_sys_flags; - - if (pSolarSysState->MenuState.Initialized < 3) - draw_sys_flags |= DRAW_REFRESH; - else if (pSolarSysState->MenuState.Initialized == 4) - draw_sys_flags |= REPAIR_SCAN; -} + extern BYTE draw_sys_flags; + + if (pSolarSysState->MenuState.Initialized < 3) + draw_sys_flags |= DRAW_REFRESH; + else if (pSolarSysState->MenuState.Initialized == 4) + draw_sys_flags |= REPAIR_SCAN; + } } else { - extern BOOLEAN - LoadGame - (COUNT - which_game, - SUMMARY_DESC - *summary_desc); + extern BOOLEAN LoadGame (COUNT which_game, SUMMARY_DESC *summary_desc); ConfirmSaveLoad (0); if (LoadGame ((COUNT)pMS->CurState, NULL_PTR)) @@ -1008,7 +1004,7 @@ if (pSolarSysState) SetFlashRect (NULL_PTR, (FRAME)0); ClearSemaphore (GraphicsSem); -pMS->ModuleFrame = 0; + pMS->ModuleFrame = 0; pMS->CurState = (BYTE)pMS->delta_item; return (FALSE); } @@ -1029,7 +1025,9 @@ pMS->ModuleFrame = 0; if (NewState != pMS->CurState) { + RECT r; SetSemaphore (GraphicsSem); + BatchGraphics (); if (((SUMMARY_DESC *)pMS->CurString)[NewState].year_index != 0) { @@ -1070,26 +1068,22 @@ ChangeGameSelection: { if (first_time) { - RECT r; - r.corner.x = SIS_ORG_X; r.corner.y = SIS_ORG_Y; r.extent.width = SIS_SCREEN_WIDTH; r.extent.height = SIS_SCREEN_HEIGHT; + ScreenTransition (3, &r); } UnbatchGraphics (); } - { - RECT r; - - r.corner.x = 3 + (NewState * 21); - r.corner.y = 176; - r.extent.width = 18; - r.extent.height = 18; - SetFlashRect (&r, (FRAME)0); - } + r.corner.x = 3 + (NewState * 21); + r.corner.y = 176; + r.extent.width = 18; + r.extent.height = 18; + SetFlashRect (&r, (FRAME)0); + ClearSemaphore (GraphicsSem); } } @@ -1153,6 +1147,7 @@ PickGame (PMENU_STATE || !(pSolarSysState && pSolarSysState->MenuState.Initialized < 3)) { + SetTransitionSource (&DlgRect); BatchGraphics (); DrawStamp(&DlgStamp); ScreenTransition (3, &DlgRect); diff --git a/sc2/src/sc2code/libs/graphics/gfx_common.h b/sc2/src/sc2code/libs/graphics/gfx_common.h index b8c7c0faf..aa49d1536 100644 --- a/sc2/src/sc2code/libs/graphics/gfx_common.h +++ b/sc2/src/sc2code/libs/graphics/gfx_common.h @@ -56,6 +56,7 @@ void SetGraphicGrabOther (int grab_other); void SetGraphicScale (int scale); int GetGraphicScale (void); void SetGraphicUseOtherExtra (int other); +void SetTransitionSource (PRECT pRect); void ScreenTransition (int transition, PRECT pRect); extern float FrameRate; diff --git a/sc2/src/sc2code/libs/graphics/sdl/3do_funcs.c b/sc2/src/sc2code/libs/graphics/sdl/3do_funcs.c index 7f8a93903..228d5e39b 100644 --- a/sc2/src/sc2code/libs/graphics/sdl/3do_funcs.c +++ b/sc2/src/sc2code/libs/graphics/sdl/3do_funcs.c @@ -114,6 +114,12 @@ transition_task_func (void *data) return 0; } +void +SetTransitionSource (PRECT pRect) +{ + TFB_DrawScreen_Copy(pRect, TFB_SCREEN_MAIN, TFB_SCREEN_TRANSITION); +} + // Status: Implemented void ScreenTransition (int TransType, PRECT pRect) @@ -140,8 +146,6 @@ ScreenTransition (int TransType, PRECT pRect) TransitionClipRect.h = ScreenHeight; } - SDL_BlitSurface (SDL_Screen, &TransitionClipRect, TransitionScreen, &TransitionClipRect); - #ifdef HAVE_OPENGL if (GraphicsDriver == TFB_GFXDRIVER_SDL_OPENGL) { diff --git a/sc2/src/sc2code/outfit.c b/sc2/src/sc2code/outfit.c index de6db9f52..f79985c52 100644 --- a/sc2/src/sc2code/outfit.c +++ b/sc2/src/sc2code/outfit.c @@ -600,6 +600,7 @@ DoOutfit (INPUT_STATE InputState, PMENU_STATE pMS) LoadGraphic (OUTFIT_PMAP_ANIM) ); + SetTransitionSource (NULL); BatchGraphics (); DrawSISFrame (); SetSemaphore(GraphicsSem); diff --git a/sc2/src/sc2code/planets/lander.c b/sc2/src/sc2code/planets/lander.c index d25641170..b28b20dde 100644 --- a/sc2/src/sc2code/planets/lander.c +++ b/sc2/src/sc2code/planets/lander.c @@ -1515,6 +1515,7 @@ InitPlanetSide (void) SetContextClipRect (&r); SetContextClipping (TRUE); + SetTransitionSource (&r); BatchGraphics (); { @@ -1856,6 +1857,7 @@ ReturnToOrbit (PRECT pRect) OldContext = SetContext (SpaceContext); SetContextClipRect (pRect); + SetTransitionSource (pRect); BatchGraphics (); DrawStarBackGround (TRUE); SetContext (ScanContext); diff --git a/sc2/src/sc2code/planets/planets.c b/sc2/src/sc2code/planets/planets.c index f9f63843a..16da4007f 100644 --- a/sc2/src/sc2code/planets/planets.c +++ b/sc2/src/sc2code/planets/planets.c @@ -64,6 +64,7 @@ LoadPlanet (BOOLEAN IsDefined) SetSemaphore (GraphicsSem); BatchGraphics (); + SetTransitionSource (NULL); if (!(LastActivity & CHECK_LOAD)) DrawStarBackGround (TRUE); @@ -176,7 +177,7 @@ LoadPlanet (BOOLEAN IsDefined) BatchGraphics(); DrawPlanet (SIS_SCREEN_WIDTH - MAP_WIDTH, SIS_SCREEN_HEIGHT - MAP_HEIGHT, 0, 0); UnbatchGraphics(); - ScreenTransition (3, &r); + ScreenTransition (3, &r); // How does this work? UnbatchGraphics (); LoadIntoExtraScreen (&r); ClearSemaphore (GraphicsSem); diff --git a/sc2/src/sc2code/planets/pstarmap.c b/sc2/src/sc2code/planets/pstarmap.c index a84da190e..0d5b12ae9 100644 --- a/sc2/src/sc2code/planets/pstarmap.c +++ b/sc2/src/sc2code/planets/pstarmap.c @@ -268,6 +268,11 @@ DrawStarMap (COUNT race_update, PRECT pClipRect) SetFrameHot (Screen, MAKE_HOT_SPOT (pClipRect->corner.x, pClipRect->corner.y)); } + + if (transition_pending) + { + SetTransitionSource (NULL); + } BatchGraphics (); which_space = GET_GAME_STATE (ARILOU_SPACE_SIDE); diff --git a/sc2/src/sc2code/planets/solarsys.c b/sc2/src/sc2code/planets/solarsys.c index 5df87425e..bfc3706f2 100644 --- a/sc2/src/sc2code/planets/solarsys.c +++ b/sc2/src/sc2code/planets/solarsys.c @@ -490,6 +490,7 @@ ShowPlanet: GenerateMoons (); NewWaitPlanet = 0; + SetTransitionSource (NULL); BatchGraphics (); SetGraphicGrabOther (1); DrawSystem (pSolarSysState->pBaseDesc->pPrevDesc->radius, TRUE); @@ -673,7 +674,12 @@ void ZoomSystem (void) { RECT r; + r.corner.x = SIS_ORG_X; + r.corner.y = SIS_ORG_Y; + r.extent.width = SIS_SCREEN_WIDTH; + r.extent.height = SIS_SCREEN_HEIGHT; + SetTransitionSource (&r); BatchGraphics (); if (pSolarSysState->pBaseDesc == pSolarSysState->MoonDesc) DrawSystem (pSolarSysState->pBaseDesc->pPrevDesc->radius, TRUE); @@ -684,10 +690,6 @@ ZoomSystem (void) DrawSystem (pSolarSysState->SunDesc[0].radius, FALSE); } - r.corner.x = SIS_ORG_X; - r.corner.y = SIS_ORG_Y; - r.extent.width = SIS_SCREEN_WIDTH; - r.extent.height = SIS_SCREEN_HEIGHT; ScreenTransition (3, &r); UnbatchGraphics (); LoadIntoExtraScreen (&r); @@ -974,9 +976,10 @@ ScaleSystem (void) CONTEXT OldContext; OldContext = SetContext (SpaceContext); + GetContextClipRect (&r); + SetTransitionSource (&r); BatchGraphics (); DrawSystem (pSolarSysState->SunDesc[0].radius, FALSE); - GetContextClipRect (&r); ScreenTransition (3, &r); UnbatchGraphics (); LoadIntoExtraScreen (&r); @@ -1085,8 +1088,8 @@ TheMess: if (old_radius) ScaleSystem (); + SetTransitionSource (NULL); BatchGraphics (); - if (!(draw_sys_flags & DRAW_REFRESH)) // don't repair from Extra or draw ship if forcing repair { CONTEXT OldContext; @@ -1405,6 +1408,7 @@ LoadLanderData (); if (pSolarSysState->MenuState.Initialized == 0) { + SetTransitionSource (NULL); BatchGraphics (); draw_sys_flags |= UNBATCH_SYS; diff --git a/sc2/src/sc2code/shipyard.c b/sc2/src/sc2code/shipyard.c index d8f8770c6..7d8049fe2 100644 --- a/sc2/src/sc2code/shipyard.c +++ b/sc2/src/sc2code/shipyard.c @@ -1205,6 +1205,7 @@ DoShipyard (INPUT_STATE InputState, PMENU_STATE pMS) pMS->hMusic = LoadMusicInstance (SHIPYARD_MUSIC); + SetTransitionSource (NULL); BatchGraphics (); DrawSISFrame (); @@ -1237,15 +1238,15 @@ DoShipyard (INPUT_STATE InputState, PMENU_STATE pMS) SetContextFont (TinyFont); -{ - RECT r; - - r.corner.x = 0; - r.corner.y = 0; - r.extent.width = SCREEN_WIDTH; - r.extent.height = SCREEN_HEIGHT; - ScreenTransition (3, &r); -} + { + RECT r; + + r.corner.x = 0; + r.corner.y = 0; + r.extent.width = SCREEN_WIDTH; + r.extent.height = SCREEN_HEIGHT; + ScreenTransition (3, &r); + } PlayMusic (pMS->hMusic, TRUE, 1); UnbatchGraphics (); BeginHangarAnim (pMS); diff --git a/sc2/src/sc2code/starbase.c b/sc2/src/sc2code/starbase.c index 4bfb92302..052097760 100644 --- a/sc2/src/sc2code/starbase.c +++ b/sc2/src/sc2code/starbase.c @@ -314,20 +314,21 @@ s.origin.x = SAFE_X, s.origin.y = SAFE_Y + 4; pMS->hMusic = LoadMusicInstance (STARBASE_MUSIC); SetSemaphore (GraphicsSem); + SetTransitionSource (NULL); BatchGraphics (); SetContextBackGroundColor (BLACK_COLOR); ClearDrawable (); DrawStamp (&s); DrawBaseStateStrings ((STARBASE_STATE)~0, pMS->CurState); -{ - RECT r; - - r.corner.x = 0; - r.corner.y = 0; - r.extent.width = SCREEN_WIDTH; - r.extent.height = SCREEN_HEIGHT; - ScreenTransition (3, &r); -} + { + RECT r; + + r.corner.x = 0; + r.corner.y = 0; + r.extent.width = SCREEN_WIDTH; + r.extent.height = SCREEN_HEIGHT; + ScreenTransition (3, &r); + } PlayMusic (pMS->hMusic, TRUE, 1); UnbatchGraphics (); pMS->flash_task = AssignTask (rotate_starbase, 4096,