Cleanup: ScanContext dispensed by scan.c

git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@3340 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
avolkov
2009-11-22 17:11:33 +00:00
parent 8465e0ab19
commit 68579000ce
5 changed files with 50 additions and 30 deletions
-15
View File
@@ -134,29 +134,14 @@ GenerateChmmr_generateOrbital (SOLARSYS_STATE *solarSys, PLANET_DESC *world)
else if (matchWorld (solarSys, world, 1, 0))
{
/* Starbase */
RECT r;
LockMutex (GraphicsLock);
LoadStdLanderFont (&solarSys->SysInfo.PlanetInfo);
solarSys->SysInfo.PlanetInfo.DiscoveryString =
CaptureStringTable (LoadStringTable (CHMMR_BASE_STRTAB));
ScanContext = CreateContext ("genchmmr.ScanContext");
SetContext (ScanContext);
SetContextFGFrame (Screen);
r.corner.x = (SIS_ORG_X + SIS_SCREEN_WIDTH) - MAP_WIDTH;
r.corner.y = (SIS_ORG_Y + SIS_SCREEN_HEIGHT) - MAP_HEIGHT;
r.extent.width = MAP_WIDTH;
r.extent.height = MAP_HEIGHT;
SetContextClipRect (&r);
DoDiscoveryReport (MenuSounds);
SetContext (SpaceContext);
DestroyContext (ScanContext);
ScanContext = 0;
DestroyStringTable (ReleaseStringTable (
solarSys->SysInfo.PlanetInfo.DiscoveryString));
solarSys->SysInfo.PlanetInfo.DiscoveryString = 0;
-1
View File
@@ -82,7 +82,6 @@ extern LanderInputState *pLanderInputState;
// a function call instead.
extern CONTEXT ScanContext;
extern MUSIC_REF LanderMusic;
extern void PlanetSide (POINT planetLoc);
+8 -1
View File
@@ -17,6 +17,7 @@
*/
#include "lander.h"
#include "scan.h"
#include "planets.h"
#include "../colors.h"
#include "../controls.h"
@@ -245,13 +246,16 @@ void
DoDiscoveryReport (SOUND ReadOutSounds)
{
CONTEXT OldContext;
CONTEXT context;
BOOLEAN ownContext;
#ifdef DEBUG
if (disableInteractivity)
return;
#endif
OldContext = SetContext (ScanContext);
context = GetScanContext (&ownContext);
OldContext = SetContext (context);
{
FONT OldFont;
FRAME OldFontEffect;
@@ -280,6 +284,9 @@ DoDiscoveryReport (SOUND ReadOutSounds)
ClearDrawable ();
#endif /* OLD */
SetContext (OldContext);
// TODO: Make CONTEXT ref-counted
if (ownContext)
DestroyContext (context);
UnlockMutex (GraphicsLock);
FlushInput ();
+41 -13
View File
@@ -50,8 +50,7 @@ extern FRAME SpaceJunkFrame;
#define FLASH_INDEX 105
// TODO: this will become static once genchmmr.c declares its own CONTEXT
CONTEXT ScanContext;
static CONTEXT ScanContext;
static POINT planetLoc;
static RECT cursorRect;
@@ -1168,10 +1167,47 @@ DoScan (MENU_STATE *pMS)
return (TRUE);
}
static CONTEXT
CreateScanContext (void)
{
CONTEXT oldContext;
CONTEXT context;
RECT r;
context = CreateContext ("ScanContext");
oldContext = SetContext (context);
SetContextFGFrame (Screen);
r.corner.x = (SIS_ORG_X + SIS_SCREEN_WIDTH) - MAP_WIDTH;
r.corner.y = (SIS_ORG_Y + SIS_SCREEN_HEIGHT) - MAP_HEIGHT;
r.extent.width = MAP_WIDTH;
r.extent.height = MAP_HEIGHT;
SetContextClipRect (&r);
SetContext (oldContext);
return context;
}
CONTEXT
GetScanContext (BOOLEAN *owner)
{
// TODO: Make CONTEXT ref-counted
if (ScanContext)
{
*owner = FALSE;
return ScanContext;
}
else
{
*owner = TRUE;
return CreateScanContext ();
}
}
void
ScanSystem (void)
{
RECT r;
MENU_STATE MenuState;
MenuState.InputFunc = DoScan;
@@ -1210,17 +1246,9 @@ ScanSystem (void)
planetLoc.y = (MAP_HEIGHT >> 1) << MAG_SHIFT;
LockMutex (GraphicsLock);
ScanContext = CreateContext ("ScanContext");
SetContext (ScanContext);
initPlanetLocationImage ();
SetContextFGFrame (Screen);
r.corner.x = (SIS_ORG_X + SIS_SCREEN_WIDTH) - MAP_WIDTH;
r.corner.y = (SIS_ORG_Y + SIS_SCREEN_HEIGHT) - MAP_HEIGHT;
r.extent.width = MAP_WIDTH;
r.extent.height = MAP_HEIGHT;
SetContextClipRect (&r);
ScanContext = CreateScanContext ();
SetContext (ScanContext);
DrawScannedObjects (FALSE);
UnlockMutex (GraphicsLock);
}
+1
View File
@@ -49,6 +49,7 @@ extern bool callGenerateForScanType (SOLARSYS_STATE *solarSys,
PLANET_DESC *world, COUNT *node, BYTE scanType);
extern void RedrawSurfaceScan (const POINT *newLoc);
extern CONTEXT GetScanContext (BOOLEAN *owner);
bool isNodeRetrieved (PLANET_INFO *planetInfo, BYTE scanType, BYTE nodeNr);
void setNodeRetrieved (PLANET_INFO *planetInfo, BYTE scanType, BYTE nodeNr);