Split debug key function into sync and async parts (wrt the game logic thread), paving the way for GraphicsLock and GameClock lock removal

git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@3759 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
avolkov
2012-01-29 20:18:50 +00:00
parent f1a1ca2075
commit 8aab2ae592
7 changed files with 71 additions and 52 deletions
+2
View File
@@ -1,4 +1,6 @@
Changes towards version 0.8: Changes towards version 0.8:
- Split debug key function into sync and async parts, paving the way
for GraphicsLock removal - Alex
- PageUp/PageDown now add/remove 10 fuel in the shipyard, from - PageUp/PageDown now add/remove 10 fuel in the shipyard, from
Scott A. Colcord, Nic Scott A. Colcord, Nic
- Annihigate flash thread - SvdB - Annihigate flash thread - SvdB
+3 -9
View File
@@ -157,22 +157,16 @@ UnlockGameClock (void)
BOOLEAN BOOLEAN
GameClockRunning (void) GameClockRunning (void)
{ {
SIZE prev_tick, cur_tick; SIZE day_in_ticks;
if (!clock_mutex) if (!clock_mutex)
return FALSE; return FALSE;
LockMutex (clock_mutex); LockMutex (clock_mutex);
prev_tick = GLOBAL (GameClock.tick_count); day_in_ticks = GLOBAL (GameClock.day_in_ticks);
UnlockMutex (clock_mutex); UnlockMutex (clock_mutex);
SleepThread (ONE_SECOND / 5); return day_in_ticks != 0;
LockMutex (clock_mutex);
cur_tick = GLOBAL (GameClock.tick_count);
UnlockMutex (clock_mutex);
return cur_tick != prev_tick;
} }
void void
+5 -13
View File
@@ -275,6 +275,11 @@ UpdateInputState (void)
if (CurrentInputState.menu[KEY_EXIT]) if (CurrentInputState.menu[KEY_EXIT])
ExitRequested = TRUE; ExitRequested = TRUE;
#if defined(DEBUG) || defined(USE_DEBUG_KEY)
if (PulsedInputState.menu[KEY_DEBUG])
debugKeyPressedSynchronous ();
#endif
} }
InputFrameCallback * InputFrameCallback *
@@ -365,19 +370,6 @@ DoInput (void *pInputState, BOOLEAN resetInput)
UpdateInputState (); UpdateInputState ();
#ifdef DEBUG
if (doInputDebugHook != NULL)
{
void (*saveDebugHook) (void);
saveDebugHook = doInputDebugHook;
doInputDebugHook = NULL;
// No further debugHook calls unless the called
// function resets doInputDebugHook.
(*saveDebugHook) ();
continue;
}
#endif
#if DEMO_MODE || CREATE_JOURNAL #if DEMO_MODE || CREATE_JOURNAL
if (ArrowInput != DemoInput) if (ArrowInput != DemoInput)
#endif #endif
+2 -1
View File
@@ -352,7 +352,8 @@ CalcLifeChance (const PLANET_INFO *PlanetInfoPtr)
void void
DoPlanetaryAnalysis (SYSTEM_INFO *SysInfoPtr, PLANET_DESC *pPlanetDesc) DoPlanetaryAnalysis (SYSTEM_INFO *SysInfoPtr, PLANET_DESC *pPlanetDesc)
{ {
assert (pPlanetDesc->data_index != HIERARCHY_STARBASE); assert ((pPlanetDesc->data_index & ~WORLD_TYPE_SPECIAL)
< NUMBER_OF_PLANET_TYPES);
RandomContext_SeedRandom (SysGenRNG, pPlanetDesc->rand_seed); RandomContext_SeedRandom (SysGenRNG, pPlanetDesc->rand_seed);
+13 -5
View File
@@ -105,6 +105,7 @@ BackgroundInitKernel (DWORD TimeOut)
} }
} }
// Executes on the main() thread
void void
SignalStopMainThread (void) SignalStopMainThread (void)
{ {
@@ -113,6 +114,7 @@ SignalStopMainThread (void)
TaskSwitch (); TaskSwitch ();
} }
// Executes on the main() thread
void void
ProcessUtilityKeys (void) ProcessUtilityKeys (void)
{ {
@@ -132,11 +134,17 @@ ProcessUtilityKeys (void)
} }
#if defined(DEBUG) || defined(USE_DEBUG_KEY) #if defined(DEBUG) || defined(USE_DEBUG_KEY)
if (ImmediateInputState.menu[KEY_DEBUG]) { // Only call the debug func on the rising edge of
{ // ImmediateInputState[KEY_DEBUG] so it does not execute repeatedly.
// clear ImmediateInputState so we don't repeat this next frame // This duplicates the PulsedInputState somewhat, but we cannot
FlushInput (); // use PulsedInputState here because it is meant for another thread.
debugKeyPressed (); static int debugKeyState;
if (ImmediateInputState.menu[KEY_DEBUG] && debugKeyState == 0)
{
debugKeyPressed ();
}
debugKeyState = ImmediateInputState.menu[KEY_DEBUG];
} }
#endif /* DEBUG */ #endif /* DEBUG */
} }
+33 -14
View File
@@ -72,11 +72,12 @@ static void dumpPlanetTypeCallback (int index, const PlanetFrame *planet,
BOOLEAN instantMove = FALSE; BOOLEAN instantMove = FALSE;
BOOLEAN disableInteractivity = FALSE; BOOLEAN disableInteractivity = FALSE;
void (* volatile debugHook) (void) = NULL; void (* volatile debugHook) (void) = NULL;
void (* volatile doInputDebugHook) (void) = NULL;
// Must be called on the Starcon2Main thread.
// This function is called synchronously wrt the game logic thread.
void void
debugKeyPressed (void) debugKeyPressedSynchronous (void)
{ {
// State modifying: // State modifying:
equipShip (); equipShip ();
@@ -107,28 +108,36 @@ debugKeyPressed (void)
// SET_GAME_STATE (MELNORME_CREDIT1, 100); // SET_GAME_STATE (MELNORME_CREDIT1, 100);
// GLOBAL_SIS (ResUnits) = 100000; // GLOBAL_SIS (ResUnits) = 100000;
// Informational:
// dumpEvents (stderr);
// Graphical and textual:
// debugContexts();
}
// Can be called on any thread, but usually on main()
// This function is called asynchronously wrt the game logic thread,
// which means locking applies. Use carefully.
// TODO: Once game logic thread is purged of graphics and clock locks,
// this function may not call graphics and game clock functions at all.
void
debugKeyPressed (void)
{
// Tests // Tests
// Scale_PerfTest (); // Scale_PerfTest ();
// Informational: // Informational:
// dumpStrings (stdout); // dumpStrings (stdout);
// dumpEvents (stderr);
// dumpPlanetTypes(stderr); // dumpPlanetTypes(stderr);
// debugHook = dumpUniverseToFile; // debugHook = dumpUniverseToFile;
// This will cause dumpUniverseToFile to be called from the // This will cause dumpUniverseToFile to be called from the
// main loop. Calling it from here would give threading // Starcon2Main loop. Calling it from here would give threading
// problems. // problems.
// debugHook = tallyResourcesToFile; // debugHook = tallyResourcesToFile;
// This will cause tallyResourcesToFile to be called from the // This will cause tallyResourcesToFile to be called from the
// main loop. Calling it from here would give threading // Starcon2Main loop. Calling it from here would give threading
// problems. // problems.
// Graphical and textual:
//doInputDebugHook = debugContexts;
// This will cause debugContexts to be called from the
// Starcon2Main thread, from DoInput(). Calling it from here
// would give threading problems.
// Interactive: // Interactive:
// uio_debugInteractive(stdin, stdout, stderr); // uio_debugInteractive(stdin, stdout, stderr);
} }
@@ -137,6 +146,9 @@ debugKeyPressed (void)
// Fast forwards to the next event. // Fast forwards to the next event.
// If skipHEE is set, HYPERSPACE_ENCOUNTER_EVENTs are skipped. // If skipHEE is set, HYPERSPACE_ENCOUNTER_EVENTs are skipped.
// Must be called from the Starcon2Main thread.
// TODO: GraphicsLock and LockGameClock may be removed since it is only
// supposed to be called synchronously wrt the game logic thread.
void void
forwardToNextEvent (BOOLEAN skipHEE) forwardToNextEvent (BOOLEAN skipHEE)
{ {
@@ -596,6 +608,8 @@ forAllMoons (STAR_DESC *star, SOLARSYS_STATE *system, PLANET_DESC *planet,
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// Must be called from the Starcon2Main thread.
// TODO: LockGameClock may be removed
void void
UniverseRecurse (UniverseRecurseArg *universeRecurseArg) UniverseRecurse (UniverseRecurseArg *universeRecurseArg)
{ {
@@ -728,10 +742,13 @@ moonRecurse (STAR_DESC *star, SOLARSYS_STATE *system, PLANET_DESC *planet,
if (universeRecurseArg->moonFunc != NULL) if (universeRecurseArg->moonFunc != NULL)
{ {
system->pOrbitalDesc = moon; system->pOrbitalDesc = moon;
DoPlanetaryAnalysis (&system->SysInfo, moon); if (moon->data_index != HIERARCHY_STARBASE && moon->data_index != SA_MATRA)
{
DoPlanetaryAnalysis (&system->SysInfo, moon);
// When GenerateDefaultFunctions is used as genFuncs, // When GenerateDefaultFunctions is used as genFuncs,
// generateOrbital will also call DoPlanetaryAnalysis, // generateOrbital will also call DoPlanetaryAnalysis,
// but with other GenerateFunctions this is not guaranteed. // but with other GenerateFunctions this is not guaranteed.
}
(*system->genFuncs->generateOrbital) (system, moon); (*system->genFuncs->generateOrbital) (system, moon);
(*universeRecurseArg->moonFunc) ( (*universeRecurseArg->moonFunc) (
moon, universeRecurseArg->arg); moon, universeRecurseArg->arg);
@@ -745,6 +762,7 @@ typedef struct
FILE *out; FILE *out;
} DumpUniverseArg; } DumpUniverseArg;
// Must be called from the Starcon2Main thread.
void void
dumpUniverse (FILE *out) dumpUniverse (FILE *out)
{ {
@@ -763,7 +781,7 @@ dumpUniverse (FILE *out)
UniverseRecurse (&universeRecurseArg); UniverseRecurse (&universeRecurseArg);
} }
// Must be called from the main thread. // Must be called from the Starcon2Main thread.
void void
dumpUniverseToFile (void) dumpUniverseToFile (void)
{ {
@@ -1146,6 +1164,7 @@ struct TallyResourcesArg
COUNT bioCount; COUNT bioCount;
}; };
// Must be called from the Starcon2Main thread.
void void
tallyResources (FILE *out) tallyResources (FILE *out)
{ {
@@ -1164,7 +1183,7 @@ tallyResources (FILE *out)
UniverseRecurse (&universeRecurseArg); UniverseRecurse (&universeRecurseArg);
} }
// Must be called from the main thread. // Must be called from the Starcon2Main thread.
void void
tallyResourcesToFile (void) tallyResourcesToFile (void)
{ {
+13 -10
View File
@@ -33,19 +33,19 @@ extern BOOLEAN disableInteractivity;
// Starcon2Main thread, in the main game loop. // Starcon2Main thread, in the main game loop.
extern void (* volatile debugHook) (void); extern void (* volatile debugHook) (void);
// If a function is assigned to this, it will be called from the // Called on the main() thread when the debug key (symbol 'Debug' in the
// Starcon2Main thread, in doInput(). // keys.cfg) is pressed
extern void (* volatile doInputDebugHook) (void);
// Called when the debug key (symbol 'Debug' in the keys.cfg) is pressed.
void debugKeyPressed (void); void debugKeyPressed (void);
// Called on the Starcon2Main() thread when the debug key (symbol 'Debug'
// in the keys.cfg) is pressed.
void debugKeyPressedSynchronous (void);
// Forward time to the next event. If skipHEE is set, the event named // Forward time to the next event. If skipHEE is set, the event named
// HYPERSPACE_ENCOUNTER_EVENT, which normally occurs every game day, // HYPERSPACE_ENCOUNTER_EVENT, which normally occurs every game day,
// is skipped. // is skipped. Must be called on the Starcon2Main thread.
void forwardToNextEvent (BOOLEAN skipHEE); void forwardToNextEvent (BOOLEAN skipHEE);
// Generate a list of all events in the event queue. // Generate a list of all events in the event queue.
// Must be called on the Starcon2Main thread.
void dumpEvents (FILE *out); void dumpEvents (FILE *out);
// Describe one event. // Describe one event.
void dumpEvent (FILE *out, const EVENT *eventPtr); void dumpEvent (FILE *out, const EVENT *eventPtr);
@@ -102,11 +102,13 @@ typedef struct
// User data. // User data.
} UniverseRecurseArg; } UniverseRecurseArg;
// Recurse through all systems, planets, and moons in the universe. // Recurse through all systems, planets, and moons in the universe.
// Must be called on the Starcon2Main thread.
void UniverseRecurse (UniverseRecurseArg *universeRecurseArg); void UniverseRecurse (UniverseRecurseArg *universeRecurseArg);
// Describe the entire universe. // Describe the entire universe. Must be called on the Starcon2Main thread.
void dumpUniverse (FILE *out); void dumpUniverse (FILE *out);
// Describe the entire universe, output to a file "./PlanetInfo". // Describe the entire universe, output to a file "./PlanetInfo".
// Must be called on the Starcon2Main thread.
void dumpUniverseToFile (void); void dumpUniverseToFile (void);
// Describe one star system. // Describe one star system.
void dumpSystem (FILE *out, const STAR_DESC *star, void dumpSystem (FILE *out, const STAR_DESC *star,
@@ -137,9 +139,10 @@ void generateBioIndex(const SOLARSYS_STATE *system,
const PLANET_DESC *world, COUNT bio[]); const PLANET_DESC *world, COUNT bio[]);
// Tally the resources for each star system. // Tally the resources for each star system.
// Must be called on the Starcon2Main thread.
void tallyResources (FILE *out); void tallyResources (FILE *out);
// Tally the resources for each star system, output to a file // Tally the resources for each star system, output to a file
// "./ResourceTally". // "./ResourceTally". Must be called on the Starcon2Main thread.
void tallyResourcesToFile (void); void tallyResourcesToFile (void);
@@ -186,7 +189,7 @@ void dumpStrings(FILE *out);
// Graphically and textually show all the contexts. // Graphically and textually show all the contexts.
// Should be called from debugHook. // Must be called on the Starcon2Main thread.
void debugContexts (void); void debugContexts (void);