|
From: <av...@us...> - 2012-01-29 20:18:57
|
Revision: 3759
http://sc2.svn.sourceforge.net/sc2/?rev=3759&view=rev
Author: avolkov
Date: 2012-01-29 20:18:50 +0000 (Sun, 29 Jan 2012)
Log Message:
-----------
Split debug key function into sync and async parts (wrt the game logic thread), paving the way for GraphicsLock and GameClock lock removal
Modified Paths:
--------------
trunk/sc2/ChangeLog
trunk/sc2/src/uqm/clock.c
trunk/sc2/src/uqm/gameinp.c
trunk/sc2/src/uqm/planets/calc.c
trunk/sc2/src/uqm/starcon.c
trunk/sc2/src/uqm/uqmdebug.c
trunk/sc2/src/uqm/uqmdebug.h
Modified: trunk/sc2/ChangeLog
===================================================================
--- trunk/sc2/ChangeLog 2012-01-29 18:35:35 UTC (rev 3758)
+++ trunk/sc2/ChangeLog 2012-01-29 20:18:50 UTC (rev 3759)
@@ -1,4 +1,6 @@
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
Scott A. Colcord, Nic
- Annihigate flash thread - SvdB
Modified: trunk/sc2/src/uqm/clock.c
===================================================================
--- trunk/sc2/src/uqm/clock.c 2012-01-29 18:35:35 UTC (rev 3758)
+++ trunk/sc2/src/uqm/clock.c 2012-01-29 20:18:50 UTC (rev 3759)
@@ -157,22 +157,16 @@
BOOLEAN
GameClockRunning (void)
{
- SIZE prev_tick, cur_tick;
+ SIZE day_in_ticks;
if (!clock_mutex)
return FALSE;
LockMutex (clock_mutex);
- prev_tick = GLOBAL (GameClock.tick_count);
+ day_in_ticks = GLOBAL (GameClock.day_in_ticks);
UnlockMutex (clock_mutex);
- SleepThread (ONE_SECOND / 5);
-
- LockMutex (clock_mutex);
- cur_tick = GLOBAL (GameClock.tick_count);
- UnlockMutex (clock_mutex);
-
- return cur_tick != prev_tick;
+ return day_in_ticks != 0;
}
void
Modified: trunk/sc2/src/uqm/gameinp.c
===================================================================
--- trunk/sc2/src/uqm/gameinp.c 2012-01-29 18:35:35 UTC (rev 3758)
+++ trunk/sc2/src/uqm/gameinp.c 2012-01-29 20:18:50 UTC (rev 3759)
@@ -275,6 +275,11 @@
if (CurrentInputState.menu[KEY_EXIT])
ExitRequested = TRUE;
+
+#if defined(DEBUG) || defined(USE_DEBUG_KEY)
+ if (PulsedInputState.menu[KEY_DEBUG])
+ debugKeyPressedSynchronous ();
+#endif
}
InputFrameCallback *
@@ -365,19 +370,6 @@
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 (ArrowInput != DemoInput)
#endif
Modified: trunk/sc2/src/uqm/planets/calc.c
===================================================================
--- trunk/sc2/src/uqm/planets/calc.c 2012-01-29 18:35:35 UTC (rev 3758)
+++ trunk/sc2/src/uqm/planets/calc.c 2012-01-29 20:18:50 UTC (rev 3759)
@@ -352,7 +352,8 @@
void
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);
Modified: trunk/sc2/src/uqm/starcon.c
===================================================================
--- trunk/sc2/src/uqm/starcon.c 2012-01-29 18:35:35 UTC (rev 3758)
+++ trunk/sc2/src/uqm/starcon.c 2012-01-29 20:18:50 UTC (rev 3759)
@@ -105,6 +105,7 @@
}
}
+// Executes on the main() thread
void
SignalStopMainThread (void)
{
@@ -113,6 +114,7 @@
TaskSwitch ();
}
+// Executes on the main() thread
void
ProcessUtilityKeys (void)
{
@@ -132,11 +134,17 @@
}
#if defined(DEBUG) || defined(USE_DEBUG_KEY)
- if (ImmediateInputState.menu[KEY_DEBUG])
- {
- // clear ImmediateInputState so we don't repeat this next frame
- FlushInput ();
- debugKeyPressed ();
+ { // Only call the debug func on the rising edge of
+ // ImmediateInputState[KEY_DEBUG] so it does not execute repeatedly.
+ // This duplicates the PulsedInputState somewhat, but we cannot
+ // use PulsedInputState here because it is meant for another thread.
+ static int debugKeyState;
+
+ if (ImmediateInputState.menu[KEY_DEBUG] && debugKeyState == 0)
+ {
+ debugKeyPressed ();
+ }
+ debugKeyState = ImmediateInputState.menu[KEY_DEBUG];
}
#endif /* DEBUG */
}
Modified: trunk/sc2/src/uqm/uqmdebug.c
===================================================================
--- trunk/sc2/src/uqm/uqmdebug.c 2012-01-29 18:35:35 UTC (rev 3758)
+++ trunk/sc2/src/uqm/uqmdebug.c 2012-01-29 20:18:50 UTC (rev 3759)
@@ -72,11 +72,12 @@
BOOLEAN instantMove = FALSE;
BOOLEAN disableInteractivity = FALSE;
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
-debugKeyPressed (void)
+debugKeyPressedSynchronous (void)
{
// State modifying:
equipShip ();
@@ -107,28 +108,36 @@
// SET_GAME_STATE (MELNORME_CREDIT1, 100);
// 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
// Scale_PerfTest ();
// Informational:
// dumpStrings (stdout);
-// dumpEvents (stderr);
// dumpPlanetTypes(stderr);
// debugHook = dumpUniverseToFile;
// 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.
// debugHook = tallyResourcesToFile;
// 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.
- // 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:
// uio_debugInteractive(stdin, stdout, stderr);
}
@@ -137,6 +146,9 @@
// Fast forwards to the next event.
// 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
forwardToNextEvent (BOOLEAN skipHEE)
{
@@ -596,6 +608,8 @@
////////////////////////////////////////////////////////////////////////////
+// Must be called from the Starcon2Main thread.
+// TODO: LockGameClock may be removed
void
UniverseRecurse (UniverseRecurseArg *universeRecurseArg)
{
@@ -728,10 +742,13 @@
if (universeRecurseArg->moonFunc != NULL)
{
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,
// generateOrbital will also call DoPlanetaryAnalysis,
// but with other GenerateFunctions this is not guaranteed.
+ }
(*system->genFuncs->generateOrbital) (system, moon);
(*universeRecurseArg->moonFunc) (
moon, universeRecurseArg->arg);
@@ -745,6 +762,7 @@
FILE *out;
} DumpUniverseArg;
+// Must be called from the Starcon2Main thread.
void
dumpUniverse (FILE *out)
{
@@ -763,7 +781,7 @@
UniverseRecurse (&universeRecurseArg);
}
-// Must be called from the main thread.
+// Must be called from the Starcon2Main thread.
void
dumpUniverseToFile (void)
{
@@ -1146,6 +1164,7 @@
COUNT bioCount;
};
+// Must be called from the Starcon2Main thread.
void
tallyResources (FILE *out)
{
@@ -1164,7 +1183,7 @@
UniverseRecurse (&universeRecurseArg);
}
-// Must be called from the main thread.
+// Must be called from the Starcon2Main thread.
void
tallyResourcesToFile (void)
{
Modified: trunk/sc2/src/uqm/uqmdebug.h
===================================================================
--- trunk/sc2/src/uqm/uqmdebug.h 2012-01-29 18:35:35 UTC (rev 3758)
+++ trunk/sc2/src/uqm/uqmdebug.h 2012-01-29 20:18:50 UTC (rev 3759)
@@ -33,19 +33,19 @@
// Starcon2Main thread, in the main game loop.
extern void (* volatile debugHook) (void);
-// If a function is assigned to this, it will be called from the
-// Starcon2Main thread, in doInput().
-extern void (* volatile doInputDebugHook) (void);
-
-
-// Called when the debug key (symbol 'Debug' in the keys.cfg) is pressed.
+// Called on the main() thread when the debug key (symbol 'Debug' in the
+// keys.cfg) is pressed
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
// HYPERSPACE_ENCOUNTER_EVENT, which normally occurs every game day,
-// is skipped.
+// is skipped. Must be called on the Starcon2Main thread.
void forwardToNextEvent (BOOLEAN skipHEE);
// Generate a list of all events in the event queue.
+// Must be called on the Starcon2Main thread.
void dumpEvents (FILE *out);
// Describe one event.
void dumpEvent (FILE *out, const EVENT *eventPtr);
@@ -102,11 +102,13 @@
// User data.
} UniverseRecurseArg;
// Recurse through all systems, planets, and moons in the universe.
+// Must be called on the Starcon2Main thread.
void UniverseRecurse (UniverseRecurseArg *universeRecurseArg);
-// Describe the entire universe.
+// Describe the entire universe. Must be called on the Starcon2Main thread.
void dumpUniverse (FILE *out);
// Describe the entire universe, output to a file "./PlanetInfo".
+// Must be called on the Starcon2Main thread.
void dumpUniverseToFile (void);
// Describe one star system.
void dumpSystem (FILE *out, const STAR_DESC *star,
@@ -137,9 +139,10 @@
const PLANET_DESC *world, COUNT bio[]);
// Tally the resources for each star system.
+// Must be called on the Starcon2Main thread.
void tallyResources (FILE *out);
// Tally the resources for each star system, output to a file
-// "./ResourceTally".
+// "./ResourceTally". Must be called on the Starcon2Main thread.
void tallyResourcesToFile (void);
@@ -186,7 +189,7 @@
// Graphically and textually show all the contexts.
-// Should be called from debugHook.
+// Must be called on the Starcon2Main thread.
void debugContexts (void);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|