- fix warning (fall through)
git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@7871 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: 3e31cc826e5db4ab3f2b50b35e2ebace141da792 Former-commit-id: 0bc4abe3559c6520f417a9eeb021561b32fec28e
This commit is contained in:
parent
f61c1da1a7
commit
9d76275de9
5 changed files with 978 additions and 942 deletions
|
@ -428,7 +428,7 @@ void TSimpleStrategy::Update(PtCarElt Car,
|
|||
//==========================================================================*
|
||||
// State (Sequential logic system)
|
||||
//--------------------------------------------------------------------------*
|
||||
void TSimpleStrategy::CheckPitState(float PitScaleBrake)
|
||||
void TSimpleStrategy::CheckPitState(float /*PitScaleBrake*/)
|
||||
{
|
||||
if (oPit == NULL) // No Pit no service
|
||||
return;
|
||||
|
@ -485,8 +485,10 @@ void TSimpleStrategy::CheckPitState(float PitScaleBrake)
|
|||
// We reached the poit to stopp
|
||||
oState = PIT_ASKED;
|
||||
LogSimplix.debug("#PIT_ENTER: %g\n", TrackPos);
|
||||
|
||||
// falls through...
|
||||
// falls through...
|
||||
#if ( __GNUC__ >= 5 || _MSVC_VER >= 1910)
|
||||
[[fallthrough]];
|
||||
#endif
|
||||
|
||||
case PIT_ASKED:
|
||||
// We are still going to the pit
|
||||
|
@ -496,7 +498,7 @@ void TSimpleStrategy::CheckPitState(float PitScaleBrake)
|
|||
oDriver->oStanding = true; // For motion survey!
|
||||
oPitTicker = 0; // Start service timer
|
||||
CarAccelCmd = 0; // release throttle
|
||||
CarBrakeCmd = 1.0 * PitScaleBrake; // Start braking
|
||||
CarBrakeCmd = 1.0; // Start braking
|
||||
CarRaceCmd = RM_CMD_PIT_ASKED; // Tell TORCS to service us! To test oPitTicker comment out
|
||||
oState = PIT_SERVICE;
|
||||
}
|
||||
|
|
|
@ -138,6 +138,7 @@ grAdaptScreenSize(void)
|
|||
switch (grNbArrangeScreens) {
|
||||
default:
|
||||
grNbArrangeScreens = 0;
|
||||
[[fallthrough]];
|
||||
case 0:
|
||||
// Top & Bottom half of the window
|
||||
grScreens[0]->activate(grWinx, grWiny + grWinh / 2, grWinw, grWinh / 2, 0.0);
|
||||
|
@ -167,6 +168,9 @@ grAdaptScreenSize(void)
|
|||
switch (grNbArrangeScreens) {
|
||||
default:
|
||||
grNbArrangeScreens = 0;
|
||||
#if ( __GNUC__ >= 5 || _MSVC_VER >= 1910)
|
||||
[[fallthrough]];
|
||||
#endif
|
||||
case 0:
|
||||
// Left/Right below wide
|
||||
grScreens[0]->activate(grWinx, grWiny + grWinh / 2, grWinw, grWinh / 2, 0.0);
|
||||
|
@ -224,8 +228,12 @@ grAdaptScreenSize(void)
|
|||
grScreens[3]->activate(grWinx + grWinw * 3/4, grWiny, grWinw / 4, grWinh, 0.0);
|
||||
break;
|
||||
}
|
||||
#if ( __GNUC__ >= 5 || _MSVC_VER >= 1910)
|
||||
[[fallthrough]];
|
||||
#endif
|
||||
default:
|
||||
grNbArrangeScreens = 0;
|
||||
[[fallthrough]];
|
||||
case 0:
|
||||
// Top/Bottom Left/Rigth Quarters
|
||||
grScreens[0]->activate(grWinx, grWiny + grWinh / 2, grWinw / 2, grWinh / 2, 0.0);
|
||||
|
@ -290,6 +298,9 @@ grAdaptScreenSize(void)
|
|||
switch (grNbArrangeScreens) {
|
||||
default:
|
||||
grNbArrangeScreens = 0;
|
||||
#if ( __GNUC__ >= 5 || _MSVC_VER >= 1910)
|
||||
[[fallthrough]];
|
||||
#endif
|
||||
case 0:
|
||||
// Top/Bottom Left/Middle/Rigth Matrix
|
||||
grScreens[0]->activate(grWinx, grWiny + grWinh / 2, grWinw / 2, grWinh / 2, 0.0);
|
||||
|
@ -323,8 +334,14 @@ grAdaptScreenSize(void)
|
|||
grScreens[5]->activate(grWinx + grWinw * 5/6, grWiny, grWinw / 6, grWinh, 0.0);
|
||||
break;
|
||||
}
|
||||
#if ( __GNUC__ >= 5 || _MSVC_VER >= 1910)
|
||||
[[fallthrough]];
|
||||
#endif
|
||||
default:
|
||||
grNbArrangeScreens = 0;
|
||||
#if ( __GNUC__ >= 5 || _MSVC_VER >= 1910)
|
||||
[[fallthrough]];
|
||||
#endif
|
||||
case 0:
|
||||
// Top/Bottom Left/Middle/Rigth Matrix
|
||||
grScreens[0]->activate(grWinx, grWiny + grWinh / 2, grWinw / 3, grWinh / 2, 0.0);
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -3,7 +3,7 @@
|
|||
file : racestate.cpp
|
||||
created : Sat Nov 16 12:00:42 CET 2002
|
||||
copyright : (C) 2002 by Eric Espie
|
||||
email : eric.espie@torcs.org
|
||||
email : eric.espie@torcs.org
|
||||
version : $Id$
|
||||
***************************************************************************/
|
||||
|
||||
|
@ -16,8 +16,8 @@
|
|||
* *
|
||||
***************************************************************************/
|
||||
|
||||
/** @file
|
||||
The Race Engine State Automaton
|
||||
/** @file
|
||||
The Race Engine State Automaton
|
||||
@author <a href=mailto:eric.espie@torcs.org>Eric Espie</a>
|
||||
@version $Id$
|
||||
*/
|
||||
|
@ -52,197 +52,202 @@ ReStateInit(void *prevMenu)
|
|||
void
|
||||
ReStateManage(void)
|
||||
{
|
||||
int mode = RM_SYNC | RM_NEXT_STEP;
|
||||
int mode = RM_SYNC | RM_NEXT_STEP;
|
||||
|
||||
do {
|
||||
switch (ReInfo->_reState) {
|
||||
case RE_STATE_CONFIG:
|
||||
GfLogInfo("%s now in CONFIG state\n", ReInfo->_reName);
|
||||
// Race configuration
|
||||
mode = ReConfigure();
|
||||
if (mode & RM_NEXT_STEP) {
|
||||
ReInfo->_reState = RE_STATE_EVENT_INIT;
|
||||
}
|
||||
break;
|
||||
do
|
||||
{
|
||||
switch (ReInfo->_reState)
|
||||
{
|
||||
case RE_STATE_CONFIG:
|
||||
GfLogInfo("%s now in CONFIG state\n", ReInfo->_reName);
|
||||
// Race configuration
|
||||
mode = ReConfigure();
|
||||
if (mode & RM_NEXT_STEP) {
|
||||
ReInfo->_reState = RE_STATE_EVENT_INIT;
|
||||
}
|
||||
break;
|
||||
|
||||
case RE_STATE_EVENT_INIT:
|
||||
GfLogInfo("%s now in EVENT_INIT state\n", ReInfo->_reName);
|
||||
// Use new Memory Manager ...
|
||||
#ifdef __DEBUG_MEMORYMANAGER__
|
||||
//fprintf(stderr,"Initialise memory manager tracking ...\n");
|
||||
GfMemoryManagerSetGroup(1);
|
||||
#endif
|
||||
// ... Use new Memory Manager
|
||||
case RE_STATE_EVENT_INIT:
|
||||
GfLogInfo("%s now in EVENT_INIT state\n", ReInfo->_reName);
|
||||
// Use new Memory Manager ...
|
||||
#ifdef __DEBUG_MEMORYMANAGER__
|
||||
//fprintf(stderr,"Initialise memory manager tracking ...\n");
|
||||
GfMemoryManagerSetGroup(1);
|
||||
#endif
|
||||
// ... Use new Memory Manager
|
||||
#if ( __GNUC__ >= 5 || _MSVC_VER >= 1910)
|
||||
[[fallthrough]];
|
||||
#endif
|
||||
|
||||
case RE_STATE_EVENT_LOOP:
|
||||
GfLogInfo("%s now in EVENT_INIT_LOOP state\n", ReInfo->_reName);
|
||||
// Load the event description (track and drivers list)
|
||||
mode = ReRaceEventInit();
|
||||
if (mode & RM_NEXT_STEP) {
|
||||
ReInfo->_reState = RE_STATE_PRE_RACE;
|
||||
}
|
||||
break;
|
||||
case RE_STATE_EVENT_LOOP:
|
||||
GfLogInfo("%s now in EVENT_INIT_LOOP state\n", ReInfo->_reName);
|
||||
// Load the event description (track and drivers list)
|
||||
mode = ReRaceEventInit();
|
||||
if (mode & RM_NEXT_STEP) {
|
||||
ReInfo->_reState = RE_STATE_PRE_RACE;
|
||||
}
|
||||
break;
|
||||
|
||||
case RE_STATE_PRE_RACE:
|
||||
GfLogInfo("%s now in PRE_RACE state\n", ReInfo->_reName);
|
||||
mode = RePreRace();
|
||||
if (mode & RM_NEXT_RACE) {
|
||||
if (mode & RM_NEXT_STEP) {
|
||||
ReInfo->_reState = RE_STATE_EVENT_SHUTDOWN;
|
||||
}
|
||||
} else if (mode & RM_NEXT_STEP) {
|
||||
ReInfo->_reState = RE_STATE_RACE_START;
|
||||
}
|
||||
break;
|
||||
case RE_STATE_PRE_RACE:
|
||||
GfLogInfo("%s now in PRE_RACE state\n", ReInfo->_reName);
|
||||
mode = RePreRace();
|
||||
if (mode & RM_NEXT_RACE) {
|
||||
if (mode & RM_NEXT_STEP) {
|
||||
ReInfo->_reState = RE_STATE_EVENT_SHUTDOWN;
|
||||
}
|
||||
} else if (mode & RM_NEXT_STEP) {
|
||||
ReInfo->_reState = RE_STATE_RACE_START;
|
||||
}
|
||||
break;
|
||||
|
||||
case RE_STATE_RACE_START:
|
||||
GfLogInfo("%s now in RACE_START state\n", ReInfo->_reName);
|
||||
mode = ReRaceStart();
|
||||
if (mode & RM_NEXT_STEP) {
|
||||
ReInfo->_reState = RE_STATE_RACE;
|
||||
GfLogInfo("%s now in RACE state\n", ReInfo->_reName);
|
||||
}
|
||||
break;
|
||||
case RE_STATE_RACE_START:
|
||||
GfLogInfo("%s now in RACE_START state\n", ReInfo->_reName);
|
||||
mode = ReRaceStart();
|
||||
if (mode & RM_NEXT_STEP) {
|
||||
ReInfo->_reState = RE_STATE_RACE;
|
||||
GfLogInfo("%s now in RACE state\n", ReInfo->_reName);
|
||||
}
|
||||
break;
|
||||
|
||||
case RE_STATE_RACE:
|
||||
mode = ReUpdate();
|
||||
if (ReInfo->s->_raceState == RM_RACE_ENDED) {
|
||||
// Race is finished
|
||||
ReInfo->_reState = RE_STATE_RACE_END;
|
||||
} else if (mode & RM_END_RACE) {
|
||||
// Race was interrupted (paused) by the player
|
||||
ReInfo->_reState = RE_STATE_RACE_STOP;
|
||||
}
|
||||
break;
|
||||
case RE_STATE_RACE:
|
||||
mode = ReUpdate();
|
||||
if (ReInfo->s->_raceState == RM_RACE_ENDED) {
|
||||
// Race is finished
|
||||
ReInfo->_reState = RE_STATE_RACE_END;
|
||||
} else if (mode & RM_END_RACE) {
|
||||
// Race was interrupted (paused) by the player
|
||||
ReInfo->_reState = RE_STATE_RACE_STOP;
|
||||
}
|
||||
break;
|
||||
|
||||
case RE_STATE_RACE_STOP:
|
||||
GfLogInfo("%s now in RACE_STOP state\n", ReInfo->_reName);
|
||||
// Race was interrupted (paused) by the player
|
||||
mode = ReRaceStop();
|
||||
if (mode & RM_NEXT_STEP) {
|
||||
ReInfo->_reState = RE_STATE_RACE_END;
|
||||
}
|
||||
break;
|
||||
case RE_STATE_RACE_STOP:
|
||||
GfLogInfo("%s now in RACE_STOP state\n", ReInfo->_reName);
|
||||
// Race was interrupted (paused) by the player
|
||||
mode = ReRaceStop();
|
||||
if (mode & RM_NEXT_STEP) {
|
||||
ReInfo->_reState = RE_STATE_RACE_END;
|
||||
}
|
||||
break;
|
||||
|
||||
case RE_STATE_RACE_END:
|
||||
GfLogInfo("%s now in RACE_END state\n", ReInfo->_reName);
|
||||
mode = ReRaceEnd();
|
||||
if (mode & RM_NEXT_STEP) {
|
||||
ReInfo->_reState = RE_STATE_POST_RACE;
|
||||
} else if (mode & RM_NEXT_RACE) {
|
||||
ReInfo->_reState = RE_STATE_RACE_START;
|
||||
}
|
||||
break;
|
||||
case RE_STATE_RACE_END:
|
||||
GfLogInfo("%s now in RACE_END state\n", ReInfo->_reName);
|
||||
mode = ReRaceEnd();
|
||||
if (mode & RM_NEXT_STEP) {
|
||||
ReInfo->_reState = RE_STATE_POST_RACE;
|
||||
} else if (mode & RM_NEXT_RACE) {
|
||||
ReInfo->_reState = RE_STATE_RACE_START;
|
||||
}
|
||||
break;
|
||||
|
||||
case RE_STATE_POST_RACE:
|
||||
GfLogInfo("%s now in POST_RACE state\n", ReInfo->_reName);
|
||||
mode = RePostRace();
|
||||
if (mode & RM_NEXT_STEP) {
|
||||
ReInfo->_reState = RE_STATE_EVENT_SHUTDOWN;
|
||||
} else if (mode & RM_NEXT_RACE) {
|
||||
ReInfo->_reState = RE_STATE_PRE_RACE;
|
||||
}
|
||||
break;
|
||||
case RE_STATE_POST_RACE:
|
||||
GfLogInfo("%s now in POST_RACE state\n", ReInfo->_reName);
|
||||
mode = RePostRace();
|
||||
if (mode & RM_NEXT_STEP) {
|
||||
ReInfo->_reState = RE_STATE_EVENT_SHUTDOWN;
|
||||
} else if (mode & RM_NEXT_RACE) {
|
||||
ReInfo->_reState = RE_STATE_PRE_RACE;
|
||||
}
|
||||
break;
|
||||
|
||||
case RE_STATE_EVOLUTION:
|
||||
GfLogInfo("RaceEngine: state = RE_STATE_EVOLUTION\n");
|
||||
mode = ReEvolution();
|
||||
// Setup short cut
|
||||
if (mode & RM_NEXT_STEP) {
|
||||
/* Back to optimization */
|
||||
ReInfo->_reState = RE_STATE_EVENT_LOOP;
|
||||
} else {
|
||||
/* Next step */
|
||||
// Use new Memory Manager ...
|
||||
#ifdef __DEBUG_MEMORYMANAGER__
|
||||
fprintf(stderr,"... Reset memory manager tracking\n");
|
||||
GfMemoryManagerSetGroup(0);
|
||||
#endif
|
||||
// ... Use new Memory Manager
|
||||
case RE_STATE_EVOLUTION:
|
||||
GfLogInfo("RaceEngine: state = RE_STATE_EVOLUTION\n");
|
||||
mode = ReEvolution();
|
||||
// Setup short cut
|
||||
if (mode & RM_NEXT_STEP) {
|
||||
/* Back to optimization */
|
||||
ReInfo->_reState = RE_STATE_EVENT_LOOP;
|
||||
} else {
|
||||
/* Next step */
|
||||
// Use new Memory Manager ...
|
||||
#ifdef __DEBUG_MEMORYMANAGER__
|
||||
fprintf(stderr,"... Reset memory manager tracking\n");
|
||||
GfMemoryManagerSetGroup(0);
|
||||
#endif
|
||||
// ... Use new Memory Manager
|
||||
|
||||
ReInfo->_reState = RE_STATE_SHUTDOWN;
|
||||
}
|
||||
break;
|
||||
ReInfo->_reState = RE_STATE_SHUTDOWN;
|
||||
}
|
||||
break;
|
||||
|
||||
case RE_STATE_EVENT_SHUTDOWN:
|
||||
GfLogInfo("%s now in EVENT_SHUTDOWN state\n", ReInfo->_reName);
|
||||
mode = ReRaceEventShutdown();
|
||||
if (mode & RM_NEXT_STEP) {
|
||||
ReInfo->_reState = RE_STATE_EVOLUTION;
|
||||
} else if (mode & RM_NEXT_RACE) {
|
||||
ReInfo->_reState = RE_STATE_EVENT_INIT;
|
||||
}
|
||||
break;
|
||||
case RE_STATE_EVENT_SHUTDOWN:
|
||||
GfLogInfo("%s now in EVENT_SHUTDOWN state\n", ReInfo->_reName);
|
||||
mode = ReRaceEventShutdown();
|
||||
if (mode & RM_NEXT_STEP) {
|
||||
ReInfo->_reState = RE_STATE_EVOLUTION;
|
||||
} else if (mode & RM_NEXT_RACE) {
|
||||
ReInfo->_reState = RE_STATE_EVENT_INIT;
|
||||
}
|
||||
break;
|
||||
|
||||
case RE_STATE_SHUTDOWN:
|
||||
GfLogInfo("%s now in SHUTDOWN state\n", ReInfo->_reName);
|
||||
ReCleanupGeneticOptimisation();
|
||||
ReInfo->_reState = RE_STATE_RESULTS;
|
||||
mode = RM_SYNC;
|
||||
break;
|
||||
case RE_STATE_SHUTDOWN:
|
||||
GfLogInfo("%s now in SHUTDOWN state\n", ReInfo->_reName);
|
||||
ReCleanupGeneticOptimisation();
|
||||
ReInfo->_reState = RE_STATE_RESULTS;
|
||||
mode = RM_SYNC;
|
||||
break;
|
||||
|
||||
case RE_STATE_RESULTS:
|
||||
GfLogInfo("%s now in RESULTS state\n", ReInfo->_reName);
|
||||
ReDisplayResults();
|
||||
ReInfo->_reState = RE_STATE_CLEANUP;
|
||||
mode = RM_SYNC;
|
||||
break;
|
||||
case RE_STATE_RESULTS:
|
||||
GfLogInfo("%s now in RESULTS state\n", ReInfo->_reName);
|
||||
ReDisplayResults();
|
||||
ReInfo->_reState = RE_STATE_CLEANUP;
|
||||
mode = RM_SYNC;
|
||||
break;
|
||||
|
||||
case RE_STATE_CLEANUP:
|
||||
GfLogInfo("%s now in CLEANUP state\n", ReInfo->_reName);
|
||||
ReCleanupReInfo();
|
||||
// Back to the race manager menu
|
||||
ReInfo->_reState = RE_STATE_WAITFORKEYPRESS;
|
||||
mode = RM_SYNC;
|
||||
break;
|
||||
case RE_STATE_CLEANUP:
|
||||
GfLogInfo("%s now in CLEANUP state\n", ReInfo->_reName);
|
||||
ReCleanupReInfo();
|
||||
// Back to the race manager menu
|
||||
ReInfo->_reState = RE_STATE_WAITFORKEYPRESS;
|
||||
mode = RM_SYNC;
|
||||
break;
|
||||
|
||||
case RE_STATE_WAITFORKEYPRESS:
|
||||
GfLogInfo("%s now in WAITFORKEYPRESS state\n", ReInfo->_reName);
|
||||
mode = ReWaitForKeyPress();
|
||||
if (mode & RM_NEXT_STEP){
|
||||
ReInfo->_reState = RE_STATE_CONFIG;
|
||||
} else {
|
||||
ReInfo->_reState = RE_STATE_WAITFORKEYPRESS;
|
||||
}
|
||||
mode = RM_SYNC;
|
||||
break;
|
||||
case RE_STATE_WAITFORKEYPRESS:
|
||||
GfLogInfo("%s now in WAITFORKEYPRESS state\n", ReInfo->_reName);
|
||||
mode = ReWaitForKeyPress();
|
||||
if (mode & RM_NEXT_STEP){
|
||||
ReInfo->_reState = RE_STATE_CONFIG;
|
||||
} else {
|
||||
ReInfo->_reState = RE_STATE_WAITFORKEYPRESS;
|
||||
}
|
||||
mode = RM_SYNC;
|
||||
break;
|
||||
|
||||
case RE_STATE_ERROR:
|
||||
// If this state is set, there was a serious error:
|
||||
// i.e. no driver in the race (no one selected OR parameters out of range)
|
||||
// Error messages are normally dumped in the game trace stream !
|
||||
// TODO: Define another screen showing the error messages instead of
|
||||
// only having it in the console window!
|
||||
GfLogInfo("%s now in ERROR state\n", ReInfo->_reName);
|
||||
ReCleanupGeneticOptimisation();
|
||||
// Back to race manager menu
|
||||
ReInfo->_reState = RE_STATE_CONFIG;
|
||||
mode = RM_SYNC;
|
||||
break;
|
||||
case RE_STATE_ERROR:
|
||||
// If this state is set, there was a serious error:
|
||||
// i.e. no driver in the race (no one selected OR parameters out of range)
|
||||
// Error messages are normally dumped in the game trace stream !
|
||||
// TODO: Define another screen showing the error messages instead of
|
||||
// only having it in the console window!
|
||||
GfLogInfo("%s now in ERROR state\n", ReInfo->_reName);
|
||||
ReCleanupGeneticOptimisation();
|
||||
// Back to race manager menu
|
||||
ReInfo->_reState = RE_STATE_CONFIG;
|
||||
mode = RM_SYNC;
|
||||
break;
|
||||
|
||||
case RE_STATE_EXIT:
|
||||
// Exit the race engine.
|
||||
mode = ReExit();
|
||||
break;
|
||||
}
|
||||
case RE_STATE_EXIT:
|
||||
// Exit the race engine.
|
||||
mode = ReExit();
|
||||
break;
|
||||
}
|
||||
|
||||
if (mode & RM_ERROR) {
|
||||
GfLogError("Race engine error (see above messages)\n");
|
||||
ReInfo->_reState = RE_STATE_ERROR;
|
||||
mode = RM_SYNC;
|
||||
}
|
||||
if (mode & RM_ERROR) {
|
||||
GfLogError("Race engine error (see above messages)\n");
|
||||
ReInfo->_reState = RE_STATE_ERROR;
|
||||
mode = RM_SYNC;
|
||||
}
|
||||
|
||||
//GfLogDebug("ReStateManage : New state 0x%X, %sing.\n",
|
||||
// ReInfo->_reState, (mode & RM_SYNC) ? "loop" : "return");
|
||||
|
||||
} while (mode & RM_SYNC);
|
||||
//GfLogDebug("ReStateManage : New state 0x%X, %sing.\n",
|
||||
// ReInfo->_reState, (mode & RM_SYNC) ? "loop" : "return");
|
||||
|
||||
} while (mode & RM_SYNC);
|
||||
}
|
||||
|
||||
// Change and Execute a New State
|
||||
void
|
||||
ReStateApply(void *pvState)
|
||||
{
|
||||
ReInfo->_reState = (int)(long)pvState;
|
||||
ReInfo->_reState = (int)(long)pvState;
|
||||
|
||||
ReStateManage();
|
||||
ReStateManage();
|
||||
}
|
||||
|
|
|
@ -17,8 +17,8 @@
|
|||
* *
|
||||
***************************************************************************/
|
||||
|
||||
/** @file
|
||||
|
||||
/** @file
|
||||
|
||||
@author <a href=mailto:torcs@free.fr>Eric Espie</a>
|
||||
@version $Id$
|
||||
*/
|
||||
|
@ -106,17 +106,17 @@ class Application : public GfApplication
|
|||
{
|
||||
public:
|
||||
|
||||
//! Constructor.
|
||||
Application();
|
||||
//! Constructor.
|
||||
Application();
|
||||
|
||||
//! Initialization.
|
||||
virtual void initialize(bool bLoggingEnabled, int argc = 0, char **argv = 0);
|
||||
|
||||
//! Parse the command line options.
|
||||
// TODO: Move to the GfApplication way of parsing options ?
|
||||
bool parseOptions();
|
||||
|
||||
void generate();
|
||||
// TODO: Move to the GfApplication way of parsing options ?
|
||||
bool parseOptions();
|
||||
|
||||
void generate();
|
||||
};
|
||||
|
||||
//! Constructor.
|
||||
|
@ -127,33 +127,33 @@ Application::Application()
|
|||
|
||||
void Application::initialize(bool bLoggingEnabled, int argc, char **argv)
|
||||
{
|
||||
// Base initialization first.
|
||||
GfApplication::initialize(bLoggingEnabled, argc, argv);
|
||||
|
||||
// Specific options.
|
||||
registerOption("c", "category", /* nHasValue = */ true);
|
||||
registerOption("n", "name", /* nHasValue = */ true);
|
||||
registerOption("b", "bump", /* nHasValue = */ false);
|
||||
registerOption("r", "raceline", /* nHasValue = */ false);
|
||||
registerOption("B", "noborder", /* nHasValue = */ false);
|
||||
registerOption("a", "all", /* nHasValue = */ false);
|
||||
registerOption("z", "calc", /* nHasValue = */ false);
|
||||
registerOption("s", "split", /* nHasValue = */ false);
|
||||
registerOption("S", "splitall", /* nHasValue = */ false);
|
||||
registerOption("E", "saveelev", /* nHasValue = */ true);
|
||||
registerOption("H", "height4", /* nHasValue = */ true);
|
||||
// Base initialization first.
|
||||
GfApplication::initialize(bLoggingEnabled, argc, argv);
|
||||
|
||||
// Specific options.
|
||||
registerOption("c", "category", /* nHasValue = */ true);
|
||||
registerOption("n", "name", /* nHasValue = */ true);
|
||||
registerOption("b", "bump", /* nHasValue = */ false);
|
||||
registerOption("r", "raceline", /* nHasValue = */ false);
|
||||
registerOption("B", "noborder", /* nHasValue = */ false);
|
||||
registerOption("a", "all", /* nHasValue = */ false);
|
||||
registerOption("z", "calc", /* nHasValue = */ false);
|
||||
registerOption("s", "split", /* nHasValue = */ false);
|
||||
registerOption("S", "splitall", /* nHasValue = */ false);
|
||||
registerOption("E", "saveelev", /* nHasValue = */ true);
|
||||
registerOption("H", "height4", /* nHasValue = */ true);
|
||||
|
||||
// Help on specific options.
|
||||
addOptionsHelpSyntaxLine("-c|--category <cat> -n|--name <name> [-b|bump] [-r|--raceline] [-B|--noborder]");
|
||||
addOptionsHelpSyntaxLine("[-a|--all] [-z|--calc] [-s|split] [-S|splitall]");
|
||||
addOptionsHelpSyntaxLine("[-E|--saveelev <#ef> [-H|height4 <#hs>]]");
|
||||
|
||||
// Help on specific options.
|
||||
addOptionsHelpSyntaxLine("-c|--category <cat> -n|--name <name> [-b|bump] [-r|--raceline] [-B|--noborder]");
|
||||
addOptionsHelpSyntaxLine("[-a|--all] [-z|--calc] [-s|split] [-S|splitall]");
|
||||
addOptionsHelpSyntaxLine("[-E|--saveelev <#ef> [-H|height4 <#hs>]]");
|
||||
|
||||
addOptionsHelpExplainLine("<cat> : track category (road, speedway, dirt...)");
|
||||
addOptionsHelpExplainLine("<name> : track name");
|
||||
addOptionsHelpExplainLine("bump : draw bump track");
|
||||
addOptionsHelpExplainLine("raceline : draw raceline track\n");
|
||||
addOptionsHelpExplainLine("raceline : draw raceline track\n");
|
||||
addOptionsHelpExplainLine("noborder : don't use terrain border "
|
||||
"(relief supplied int clockwise, ext CC)");
|
||||
"(relief supplied int clockwise, ext CC)");
|
||||
addOptionsHelpExplainLine("all : draw all (default is track only)");
|
||||
addOptionsHelpExplainLine("calc : only calculate track parameters and exit");
|
||||
addOptionsHelpExplainLine("split : split the track and the terrain");
|
||||
|
@ -170,228 +170,237 @@ void Application::initialize(bool bLoggingEnabled, int argc, char **argv)
|
|||
// Parse the command line options.
|
||||
bool Application::parseOptions()
|
||||
{
|
||||
// Parse command line for registered options, and interpret standard ones.
|
||||
if (!GfApplication::parseOptions())
|
||||
return false;
|
||||
// Parse command line for registered options, and interpret standard ones.
|
||||
if (!GfApplication::parseOptions())
|
||||
return false;
|
||||
|
||||
// Then interpret the specific ones.
|
||||
TrackName = NULL;
|
||||
TrackCategory = NULL;
|
||||
// Then interpret the specific ones.
|
||||
TrackName = NULL;
|
||||
TrackCategory = NULL;
|
||||
TrackOnly = 1;
|
||||
JustCalculate = 0;
|
||||
JustCalculate = 0;
|
||||
MergeAll = 1;
|
||||
MergeTerrain = 1;
|
||||
DoSaveElevation = -1;
|
||||
|
||||
std::list<Option>::const_iterator itOpt;
|
||||
for (itOpt = _lstOptions.begin(); itOpt != _lstOptions.end(); ++itOpt)
|
||||
{
|
||||
// Not found in the command line => ignore / default value.
|
||||
if (!itOpt->bFound)
|
||||
continue;
|
||||
|
||||
std::list<Option>::const_iterator itOpt;
|
||||
for (itOpt = _lstOptions.begin(); itOpt != _lstOptions.end(); ++itOpt)
|
||||
{
|
||||
// Not found in the command line => ignore / default value.
|
||||
if (!itOpt->bFound)
|
||||
continue;
|
||||
|
||||
if (itOpt->strLongName == "all")
|
||||
{
|
||||
TrackOnly = 0;
|
||||
}
|
||||
else if (itOpt->strLongName == "calc")
|
||||
{
|
||||
JustCalculate = 1;
|
||||
}
|
||||
else if (itOpt->strLongName == "bump")
|
||||
{
|
||||
Bump = 1;
|
||||
}
|
||||
else if (itOpt->strLongName == "raceline")
|
||||
{
|
||||
Raceline = 1;
|
||||
}
|
||||
else if (itOpt->strLongName == "split")
|
||||
{
|
||||
MergeAll = 0;
|
||||
MergeTerrain = 1;
|
||||
}
|
||||
else if (itOpt->strLongName == "splitall")
|
||||
{
|
||||
MergeAll = 0;
|
||||
MergeTerrain = 0;
|
||||
}
|
||||
else if (itOpt->strLongName == "noborder")
|
||||
{
|
||||
UseBorder = 0;
|
||||
}
|
||||
else if (itOpt->strLongName == "name")
|
||||
{
|
||||
TrackName = strdup(itOpt->strValue.c_str());
|
||||
}
|
||||
else if (itOpt->strLongName == "saveelev")
|
||||
{
|
||||
DoSaveElevation = strtol(itOpt->strValue.c_str(), NULL, 0);
|
||||
TrackOnly = 0;
|
||||
}
|
||||
else if (itOpt->strLongName == "category")
|
||||
{
|
||||
TrackCategory = strdup(itOpt->strValue.c_str());
|
||||
}
|
||||
else if (itOpt->strLongName == "steps4")
|
||||
{
|
||||
HeightSteps = strtol(itOpt->strValue.c_str(), NULL, 0);
|
||||
}
|
||||
TrackOnly = 0;
|
||||
}
|
||||
else if (itOpt->strLongName == "calc")
|
||||
{
|
||||
JustCalculate = 1;
|
||||
}
|
||||
else if (itOpt->strLongName == "bump")
|
||||
{
|
||||
Bump = 1;
|
||||
}
|
||||
else if (itOpt->strLongName == "raceline")
|
||||
{
|
||||
Raceline = 1;
|
||||
}
|
||||
else if (itOpt->strLongName == "split")
|
||||
{
|
||||
MergeAll = 0;
|
||||
MergeTerrain = 1;
|
||||
}
|
||||
else if (itOpt->strLongName == "splitall")
|
||||
{
|
||||
MergeAll = 0;
|
||||
MergeTerrain = 0;
|
||||
}
|
||||
else if (itOpt->strLongName == "noborder")
|
||||
{
|
||||
UseBorder = 0;
|
||||
}
|
||||
else if (itOpt->strLongName == "name")
|
||||
{
|
||||
TrackName = strdup(itOpt->strValue.c_str());
|
||||
}
|
||||
else if (itOpt->strLongName == "saveelev")
|
||||
{
|
||||
DoSaveElevation = strtol(itOpt->strValue.c_str(), NULL, 0);
|
||||
TrackOnly = 0;
|
||||
}
|
||||
else if (itOpt->strLongName == "category")
|
||||
{
|
||||
TrackCategory = strdup(itOpt->strValue.c_str());
|
||||
}
|
||||
else if (itOpt->strLongName == "steps4")
|
||||
{
|
||||
HeightSteps = strtol(itOpt->strValue.c_str(), NULL, 0);
|
||||
}
|
||||
}
|
||||
|
||||
if (!TrackName || !TrackCategory)
|
||||
{
|
||||
printUsage("No track name or category specified");
|
||||
return false;
|
||||
if (!TrackName || !TrackCategory)
|
||||
{
|
||||
printUsage("No track name or category specified");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void Application::generate()
|
||||
{
|
||||
const char *extName;
|
||||
FILE *outfd = NULL;
|
||||
const char *extName;
|
||||
FILE *outfd = NULL;
|
||||
|
||||
// Get the trackgen paramaters.
|
||||
CfgHandle = GfParmReadFile(CFG_FILE, GFPARM_RMODE_STD | GFPARM_RMODE_CREAT);
|
||||
// Get the trackgen paramaters.
|
||||
CfgHandle = GfParmReadFile(CFG_FILE, GFPARM_RMODE_STD | GFPARM_RMODE_CREAT);
|
||||
|
||||
// Load and initialize the track loader module.
|
||||
GfLogInfo("Loading Track Loader ...\n");
|
||||
std::ostringstream ossModLibName;
|
||||
ossModLibName << GfLibDir() << "modules/track/" << "trackv1" << '.' << DLLEXT;
|
||||
GfModule* pmodTrkLoader = GfModule::load(ossModLibName.str());
|
||||
// Load and initialize the track loader module.
|
||||
GfLogInfo("Loading Track Loader ...\n");
|
||||
std::ostringstream ossModLibName;
|
||||
ossModLibName << GfLibDir() << "modules/track/" << "trackv1" << '.' << DLLEXT;
|
||||
GfModule* pmodTrkLoader = GfModule::load(ossModLibName.str());
|
||||
|
||||
// Check that it implements ITrackLoader.
|
||||
ITrackLoader* PiTrackLoader = 0;
|
||||
if (pmodTrkLoader)
|
||||
PiTrackLoader = pmodTrkLoader->getInterface<ITrackLoader>();
|
||||
if (!PiTrackLoader)
|
||||
return;
|
||||
// Check that it implements ITrackLoader.
|
||||
ITrackLoader* PiTrackLoader = 0;
|
||||
if (pmodTrkLoader)
|
||||
PiTrackLoader = pmodTrkLoader->getInterface<ITrackLoader>();
|
||||
if (!PiTrackLoader)
|
||||
return;
|
||||
|
||||
// This is the track definition.
|
||||
sprintf(trackdef, "%stracks/%s/%s/%s.xml", GfDataDir(), TrackCategory, TrackName, TrackName);
|
||||
TrackHandle = GfParmReadFile(trackdef, GFPARM_RMODE_STD);
|
||||
if (!TrackHandle) {
|
||||
fprintf(stderr, "Cannot find %s\n", trackdef);
|
||||
::exit(1);
|
||||
}
|
||||
// This is the track definition.
|
||||
sprintf(trackdef, "%stracks/%s/%s/%s.xml", GfDataDir(), TrackCategory, TrackName, TrackName);
|
||||
TrackHandle = GfParmReadFile(trackdef, GFPARM_RMODE_STD);
|
||||
if (!TrackHandle) {
|
||||
fprintf(stderr, "Cannot find %s\n", trackdef);
|
||||
::exit(1);
|
||||
}
|
||||
|
||||
// Build the track structure with graphic extensions.
|
||||
Track = PiTrackLoader->load(trackdef, true);
|
||||
// Build the track structure with graphic extensions.
|
||||
Track = PiTrackLoader->load(trackdef, true);
|
||||
|
||||
if (!JustCalculate) {
|
||||
// Get the output file radix.
|
||||
sprintf(buf2, "%stracks/%s/%s/%s", GfDataDir(), Track->category, Track->internalname, Track->internalname);
|
||||
OutputFileName = strdup(buf2);
|
||||
if (!JustCalculate) {
|
||||
// Get the output file radix.
|
||||
sprintf(buf2, "%stracks/%s/%s/%s", GfDataDir(), Track->category, Track->internalname, Track->internalname);
|
||||
OutputFileName = strdup(buf2);
|
||||
|
||||
// Number of groups for the complete track.
|
||||
if (TrackOnly) {
|
||||
sprintf(buf2, "%s.ac", OutputFileName);
|
||||
// Track.
|
||||
if (!Bump && !Raceline)
|
||||
outfd = Ac3dOpen(buf2, 1);
|
||||
} else if (MergeAll) {
|
||||
sprintf(buf2, "%s.ac", OutputFileName);
|
||||
// track + terrain + objects.
|
||||
outfd = Ac3dOpen(buf2, 2 + GetObjectsNb(TrackHandle));
|
||||
}
|
||||
// Number of groups for the complete track.
|
||||
if (TrackOnly) {
|
||||
sprintf(buf2, "%s.ac", OutputFileName);
|
||||
// Track.
|
||||
if (!Bump && !Raceline)
|
||||
outfd = Ac3dOpen(buf2, 1);
|
||||
} else if (MergeAll) {
|
||||
sprintf(buf2, "%s.ac", OutputFileName);
|
||||
// track + terrain + objects.
|
||||
outfd = Ac3dOpen(buf2, 2 + GetObjectsNb(TrackHandle));
|
||||
}
|
||||
|
||||
// Main Track.
|
||||
if (Bump) {
|
||||
extName = "trk-bump";
|
||||
} else if (Raceline) {
|
||||
extName = "trk-raceline";
|
||||
} else {
|
||||
extName = "trk";
|
||||
}
|
||||
// Main Track.
|
||||
if (Bump) {
|
||||
extName = "trk-bump";
|
||||
} else if (Raceline) {
|
||||
extName = "trk-raceline";
|
||||
} else {
|
||||
extName = "trk";
|
||||
}
|
||||
|
||||
sprintf(buf2, "%s-%s.ac", OutputFileName, extName);
|
||||
OutTrackName = strdup(buf2);
|
||||
}
|
||||
sprintf(buf2, "%s-%s.ac", OutputFileName, extName);
|
||||
OutTrackName = strdup(buf2);
|
||||
}
|
||||
|
||||
if (JustCalculate){
|
||||
CalculateTrack(Track, TrackHandle, Bump, Raceline);
|
||||
return;
|
||||
}
|
||||
if (JustCalculate){
|
||||
CalculateTrack(Track, TrackHandle, Bump, Raceline);
|
||||
return;
|
||||
}
|
||||
|
||||
GenerateTrack(Track, TrackHandle, OutTrackName, outfd, Bump, Raceline);
|
||||
GenerateTrack(Track, TrackHandle, OutTrackName, outfd, Bump, Raceline);
|
||||
|
||||
if (TrackOnly) {
|
||||
return;
|
||||
}
|
||||
if (TrackOnly) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Terrain.
|
||||
if (MergeTerrain && !MergeAll) {
|
||||
sprintf(buf2, "%s.ac", OutputFileName);
|
||||
/* terrain + objects */
|
||||
outfd = Ac3dOpen(buf2, 1 + GetObjectsNb(TrackHandle));
|
||||
}
|
||||
// Terrain.
|
||||
if (MergeTerrain && !MergeAll) {
|
||||
sprintf(buf2, "%s.ac", OutputFileName);
|
||||
/* terrain + objects */
|
||||
outfd = Ac3dOpen(buf2, 1 + GetObjectsNb(TrackHandle));
|
||||
}
|
||||
|
||||
extName = "msh";
|
||||
sprintf(buf2, "%s-%s.ac", OutputFileName, extName);
|
||||
OutMeshName = strdup(buf2);
|
||||
extName = "msh";
|
||||
sprintf(buf2, "%s-%s.ac", OutputFileName, extName);
|
||||
OutMeshName = strdup(buf2);
|
||||
|
||||
GenerateTerrain(Track, TrackHandle, OutMeshName, outfd, DoSaveElevation);
|
||||
GenerateTerrain(Track, TrackHandle, OutMeshName, outfd, DoSaveElevation);
|
||||
|
||||
if (DoSaveElevation != -1) {
|
||||
if (outfd) {
|
||||
Ac3dClose(outfd);
|
||||
}
|
||||
switch (DoSaveElevation) {
|
||||
case 0:
|
||||
case 1:
|
||||
sprintf(buf2, "%s.ac", OutputFileName);
|
||||
sprintf(buf, "%s-elv.png", OutputFileName);
|
||||
SaveElevation(Track, TrackHandle, buf, buf2, 1);
|
||||
if (DoSaveElevation) {
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
sprintf(buf, "%s-elv2.png", OutputFileName);
|
||||
SaveElevation(Track, TrackHandle, buf, OutMeshName, 1);
|
||||
if (DoSaveElevation) {
|
||||
break;
|
||||
}
|
||||
case 3:
|
||||
sprintf(buf, "%s-elv3.png", OutputFileName);
|
||||
SaveElevation(Track, TrackHandle, buf, OutMeshName, 0);
|
||||
if (DoSaveElevation) {
|
||||
break;
|
||||
}
|
||||
case 4:
|
||||
sprintf(buf, "%s-elv4.png", OutputFileName);
|
||||
SaveElevation(Track, TrackHandle, buf, OutTrackName, 2);
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (DoSaveElevation != -1) {
|
||||
if (outfd) {
|
||||
Ac3dClose(outfd);
|
||||
}
|
||||
switch (DoSaveElevation) {
|
||||
case 0:
|
||||
case 1:
|
||||
sprintf(buf2, "%s.ac", OutputFileName);
|
||||
sprintf(buf, "%s-elv.png", OutputFileName);
|
||||
SaveElevation(Track, TrackHandle, buf, buf2, 1);
|
||||
if (DoSaveElevation) {
|
||||
break;
|
||||
}
|
||||
#if ( __GNUC__ >= 5 || _MSVC_VER >= 1910)
|
||||
[[fallthrough]];
|
||||
#endif
|
||||
case 2:
|
||||
sprintf(buf, "%s-elv2.png", OutputFileName);
|
||||
SaveElevation(Track, TrackHandle, buf, OutMeshName, 1);
|
||||
if (DoSaveElevation) {
|
||||
break;
|
||||
}
|
||||
#if ( __GNUC__ >= 5 || _MSVC_VER >= 1910)
|
||||
[[fallthrough]];
|
||||
#endif
|
||||
case 3:
|
||||
sprintf(buf, "%s-elv3.png", OutputFileName);
|
||||
SaveElevation(Track, TrackHandle, buf, OutMeshName, 0);
|
||||
if (DoSaveElevation) {
|
||||
break;
|
||||
}
|
||||
#if ( __GNUC__ >= 5 || _MSVC_VER >= 1910)
|
||||
[[fallthrough]];
|
||||
#endif
|
||||
case 4:
|
||||
sprintf(buf, "%s-elv4.png", OutputFileName);
|
||||
SaveElevation(Track, TrackHandle, buf, OutTrackName, 2);
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
GenerateObjects(Track, TrackHandle, CfgHandle, outfd, OutMeshName);
|
||||
GenerateObjects(Track, TrackHandle, CfgHandle, outfd, OutMeshName);
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
// Create and initialize the application
|
||||
Application app;
|
||||
app.initialize(/*bLoggingEnabled=*/true, argc, argv);
|
||||
|
||||
// Parse the command line options
|
||||
if (!app.parseOptions())
|
||||
return 1;
|
||||
// Create and initialize the application
|
||||
Application app;
|
||||
app.initialize(/*bLoggingEnabled=*/true, argc, argv);
|
||||
|
||||
// If "data dir" specified in any way, cd to it.
|
||||
if(chdir(GfDataDir()))
|
||||
{
|
||||
GfLogError("Could not start %s : failed to cd to the datadir '%s' (%s)\n",
|
||||
app.name().c_str(), GfDataDir(), strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Do the requested job.
|
||||
app.generate();
|
||||
|
||||
// That's all.
|
||||
return 0;
|
||||
// Parse the command line options
|
||||
if (!app.parseOptions())
|
||||
return 1;
|
||||
|
||||
// If "data dir" specified in any way, cd to it.
|
||||
if(chdir(GfDataDir()))
|
||||
{
|
||||
GfLogError("Could not start %s : failed to cd to the datadir '%s' (%s)\n",
|
||||
app.name().c_str(), GfDataDir(), strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Do the requested job.
|
||||
app.generate();
|
||||
|
||||
// That's all.
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue