Moved small network code parts away from racestate.cpp, for legacy code consistency

git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@2689 30fe4595-0a0c-4342-8851-515496e4dcbd

Former-commit-id: 26aaf9a8b7a0f0d1f855c0603dce2b036be45ac4
Former-commit-id: 6ef3e635a8da51f35e444c5e817b00197fe76662
This commit is contained in:
pouillot 2010-08-21 19:43:16 +00:00
parent d6d3e0f19f
commit 15873c479a
5 changed files with 79 additions and 93 deletions

View file

@ -422,7 +422,10 @@ reRaceRealStart(void)
ReInfo->_reTimeMult = 1.0;
ReInfo->_reLastTime = -1.0;
ReInfo->s->currentTime = -2.0; //we start 2 seconds before the start
if (GetNetwork())
ReInfo->s->currentTime = GfTimeClock() - GetNetwork()->GetRaceStartTime();
else
ReInfo->s->currentTime = -2.0; //we start 2 seconds before the start
ReInfo->s->deltaTime = RCM_MAX_DT_SIMU;
ReInfo->s->_raceState = RM_RACE_STARTING;
@ -443,6 +446,14 @@ reRaceRealStart(void)
ReInitCarGraphics();
}
if (GetNetwork())
{
RmLoadingScreenSetText("Preparing online race ...");
GetNetwork()->RaceInit(ReInfo->s);
GetNetwork()->SetRaceActive(true);
}
RmLoadingScreenSetText("Ready.");
GfuiScreenActivate(ReInfo->_reGameScreen);
@ -493,7 +504,8 @@ ReRaceStart(void)
curSurf = track->surfaces;
do
{
printf("Raceinit Function Friction = %f - RollRes = %f No Rain\n", curSurf->kFriction, curSurf->kRollRes);
GfLogDebug("Raceinit Function Friction = %f - RollRes = %f No Rain\n",
curSurf->kFriction, curSurf->kRollRes);
curSurf = curSurf->next;
} while ( curSurf != 0);
#endif
@ -518,8 +530,6 @@ ReRaceStart(void)
GfParmSetStr(params, path2, RM_ATTR_MODULE, GfParmGetStr(params, path, RM_ATTR_MODULE, ""));
GfParmSetNum(params, path2, RM_ATTR_IDX, NULL, GfParmGetNum(params, path, RM_ATTR_IDX, NULL, 0));
GfParmSetNum(params, path2, RM_ATTR_EXTENDED, NULL, GfParmGetNum(params, path, RM_ATTR_EXTENDED, NULL, 0));
//GfParmSetStr(params, path2, ROB_ATTR_NAME, GfParmGetStr(params, path, ROB_ATTR_NAME, "none"));
//GfParmSetStr(params, path2, ROB_ATTR_CAR, GfParmGetStr(params, path, ROB_ATTR_CAR, ""));
const char* pszSkinName = GfParmGetStr(params, path, RM_ATTR_SKINNAME, 0);
if (pszSkinName && strlen(pszSkinName) > 0)
GfParmSetStr(params, path2, RM_ATTR_SKINNAME, pszSkinName);
@ -543,9 +553,6 @@ ReRaceStart(void)
GfParmSetStr(params, path2, RM_ATTR_MODULE, GfParmGetStr(results, path, RE_ATTR_MODULE, ""));
GfParmSetNum(params, path2, RM_ATTR_IDX, NULL, GfParmGetNum(results, path, RE_ATTR_IDX, NULL, 0));
GfParmSetNum(params, path2, RM_ATTR_EXTENDED, NULL, GfParmGetNum(results, path, RM_ATTR_EXTENDED, NULL, 0));
// TODO (D30) : Copy human ROB_ATTR_CAR (no more in human.xml).
//GfParmSetStr(params, path2, ROB_ATTR_NAME, GfParmGetStr(results, path, ROB_ATTR_NAME, "<none>"));
//GfParmSetStr(params, path2, ROB_ATTR_CAR, GfParmGetStr(results, path, ROB_ATTR_CAR, ""));
const char* pszSkinName = GfParmGetStr(results, path, RM_ATTR_SKINNAME, 0);
if (pszSkinName && strlen(pszSkinName) > 0)
GfParmSetStr(results, path2, RM_ATTR_SKINNAME, pszSkinName);
@ -565,9 +572,6 @@ ReRaceStart(void)
GfParmSetStr(params, path2, RM_ATTR_MODULE, GfParmGetStr(results, path, RE_ATTR_MODULE, ""));
GfParmSetNum(params, path2, RM_ATTR_IDX, NULL, GfParmGetNum(results, path, RE_ATTR_IDX, NULL, 0));
GfParmSetNum(params, path2, RM_ATTR_EXTENDED, NULL, GfParmGetNum(results, path, RM_ATTR_EXTENDED, NULL, 0));
// TODO (D30) : Copy human ROB_ATTR_CAR (no more in human.xml).
//GfParmSetStr(params, path2, ROB_ATTR_NAME, GfParmGetStr(results, path, ROB_ATTR_NAME, "<none>"));
//GfParmSetStr(params, path2, ROB_ATTR_CAR, GfParmGetStr(results, path, ROB_ATTR_CAR, ""));
const char* pszSkinName = GfParmGetStr(results, path, RM_ATTR_SKINNAME, 0);
if (pszSkinName && strlen(pszSkinName) > 0)
GfParmSetStr(results, path2, RM_ATTR_SKINNAME, pszSkinName);
@ -583,23 +587,9 @@ ReRaceStart(void)
GfParmSetStr(params, path2, RM_ATTR_MODULE, GfParmGetStr(params, path, RM_ATTR_MODULE, ""));
GfParmSetNum(params, path2, RM_ATTR_IDX, NULL, GfParmGetNum(params, path, RM_ATTR_IDX, NULL, 0));
GfParmSetNum(params, path2, RM_ATTR_EXTENDED, NULL, GfParmGetNum(params, path, RM_ATTR_EXTENDED, NULL, 0));
// TODO (D30) : Copy human ROB_ATTR_CAR (no more in human.xml).
//GfParmSetStr(params, path2, ROB_ATTR_NAME, GfParmGetStr(params, path, ROB_ATTR_NAME, "<none>"));
//GfParmSetStr(params, path2, ROB_ATTR_CAR, GfParmGetStr(params, path, ROB_ATTR_CAR, ""));
// Pb : Incoherence avec raceinit !!!!!!!!!!!!
const char* pszSkinName = GfParmGetStr(params, path, RM_ATTR_SKINNAME, 0);
if (pszSkinName && strlen(pszSkinName) > 0)
GfParmSetStr(params, path2, RM_ATTR_SKINNAME, pszSkinName);
GfTrace("RaceMain: File '%s', path '%s', path2 '%s'\n",
GfParmGetFileName(params), path, path2);
// GfTrace("Driverx #%d : module='%s', skin='%s'\n",
// GfParmGetNum(params, path, RM_ATTR_IDX, NULL, -1),
// GfParmGetStr(params, path, RM_ATTR_MODULE, ""),
// GfParmGetStr(params, path, RM_ATTR_SKINNAME, ""));
GfTrace("RaceMain: Driver #%d : ",
GfParmGetNum(params, path, RM_ATTR_IDX, NULL, -1));
GfTrace("module='%s', ", GfParmGetStr(params, path, RM_ATTR_MODULE, ""));
GfTrace("skin='%s'\n", GfParmGetStr(params, path, RM_ATTR_SKINNAME, ""));
}
}
}
@ -758,7 +748,11 @@ ReRaceEnd(void)
ReRaceCleanup();
if ((ReInfo->s->_raceType == RM_TYPE_QUALIF || ReInfo->s->_raceType == RM_TYPE_PRACTICE) && !(ReInfo->s->_features & RM_FEATURE_TIMEDSESSION))
if (GetNetwork())
GetNetwork()->RaceDone();
if ((ReInfo->s->_raceType == RM_TYPE_QUALIF || ReInfo->s->_raceType == RM_TYPE_PRACTICE)
&& !(ReInfo->s->_features & RM_FEATURE_TIMEDSESSION))
{
curDrvIdx = (int)GfParmGetNum(results, RE_SECT_CURRENT, RE_ATTR_CUR_DRIVER, NULL, 1);
curDrvIdx++;

View file

@ -22,9 +22,11 @@
@version $Id$
*/
#include <tgfclient.h>
#include <network.h>
#include "racesituation.h"
#include "racegl.h"
#include "racenetwork.h"
@ -181,3 +183,48 @@ ReNetworkOneStep()
GetNetwork()->UnlockNetworkData();
}
int
ReNetworkWaitReady()
{
bool bWaitFinished = false;
if (!GetNetwork())
bWaitFinished = true;
// If network race wait for other players and start when the server says too
else if (GetClient())
{
GetClient()->SendReadyToStartPacket();
ReInfo->s->currentTime = GetClient()->WaitForRaceStart();
GfLogInfo("Client beginning race in %lf seconds!\n", ReInfo->s->currentTime);
bWaitFinished = true;
}
else if (GetServer())
{
if (GetServer()->ClientsReadyToRace())
{
ReInfo->s->currentTime = GetServer()->WaitForRaceStart();
GfLogInfo("Server beginning race in %lf seconds!\n", ReInfo->s->currentTime);
bWaitFinished = true;
}
}
int mode = RM_SYNC;
if (bWaitFinished)
{
ReSetRaceBigMsg("");
mode |= RM_NEXT_STEP;
}
else
{
ReSetRaceBigMsg("Waiting for online players");
GfuiDisplay();
ReInfo->_reGraphicItf.refresh(ReInfo->s);
GfelPostRedisplay(); /* Callback -> reDisplay */
}
return mode;
}

View file

@ -26,6 +26,7 @@
#define _RACENETWORK_H_
extern void ReNetworkOneStep();
extern int ReNetworkWaitReady();
#endif /* _RACENETWORK_H_ */

View file

@ -2,7 +2,7 @@
file : racestate.cpp
created : Sat Nov 16 12:00:42 CET 2002
copyright : (C) 2002 by Eric Espi<EFBFBD>
copyright : (C) 2002 by Eric Espie
email : eric.espie@torcs.org
version : $Id: racestate.cpp,v 1.5 2005/08/17 20:48:39 berniw Exp $
@ -28,13 +28,13 @@
#include <cstdio>
#include <tgfclient.h>
#include <network.h>
#include <raceman.h>
#include <racescreens.h>
#include "racesituation.h"
#include "racemain.h"
#include "raceinit.h"
#include "racenetwork.h"
#include "raceupdate.h"
#include "racegl.h"
#include "raceresults.h"
@ -45,34 +45,6 @@
static void *mainMenu;
bool
WaitForNetwork()
{
if (!GetNetwork())
return false;
//If network race wait for other players and start when the server says too
if (GetClient())
{
GetClient()->SendReadyToStartPacket();
ReInfo->s->currentTime = GetClient()->WaitForRaceStart();
printf("Client beginning race in %lf seconds!\n",ReInfo->s->currentTime);
return false;
}
else if (GetServer())
{
if (GetServer()->ClientsReadyToRace())
{
ReInfo->s->currentTime = GetServer()->WaitForRaceStart();
printf("Server beginning race in %lf seconds!\n",ReInfo->s->currentTime);
return false;
}
}
return true;
}
/* State Automaton Init */
void
ReStateInit(void *prevMenu)
@ -124,37 +96,17 @@ ReStateManage(void)
GfOut("RaceEngine: state = RE_STATE_RACE_START\n");
mode = ReRaceStart();
if (GetNetwork())
{
float f = GfTimeClock();
float rs = GetNetwork()->GetRaceStartTime();
ReInfo->s->currentTime = GfTimeClock() - GetNetwork()->GetRaceStartTime();
GetNetwork()->RaceInit(ReInfo->s);
GetNetwork()->SetRaceActive(true);
}
if (mode & RM_NEXT_STEP) {
ReInfo->_reState = RE_STATE_NETWORK_WAIT;
}
break;
case RE_STATE_NETWORK_WAIT:
if (!WaitForNetwork())
{
ReInfo->_reState = RE_STATE_RACE;
ReSetRaceBigMsg("");
break;
}
if (GetNetwork())
{
ReSetRaceBigMsg("Waiting for other players");
GfuiDisplay();
ReInfo->_reGraphicItf.refresh(ReInfo->s);
GfelPostRedisplay(); /* Callback -> reDisplay */
}
mode = ReNetworkWaitReady();
if (mode & RM_NEXT_STEP) {
/* Not an online race, or else all online players ready */
ReInfo->_reState = RE_STATE_RACE;
}
break;
case RE_STATE_RACE:
@ -166,14 +118,6 @@ ReStateManage(void)
/* Race was interrupted (paused) by the player */
ReInfo->_reState = RE_STATE_RACE_STOP;
}
if (GetNetwork())
{
if (GetNetwork()->FinishRace(ReInfo->s->currentTime))
{
ReInfo->_reState = RE_STATE_RACE_END;
}
}
break;
case RE_STATE_RACE_STOP:
@ -188,11 +132,6 @@ ReStateManage(void)
case RE_STATE_RACE_END:
GfOut("RaceEngine: state = RE_STATE_RACE_END\n");
mode = ReRaceEnd();
if (GetNetwork())
{
GetNetwork()->RaceDone();
}
if (mode & RM_NEXT_STEP) {
ReInfo->_reState = RE_STATE_POST_RACE;
} else if (mode & RM_NEXT_RACE) {

View file

@ -678,6 +678,11 @@ ReUpdate(void)
}
}
// Check for end of online race.
if (GetNetwork() && GetNetwork()->FinishRace(ReInfo->s->currentTime))
ReInfo->s->_raceState = RM_RACE_ENDED;
GfProfStopProfile("ReUpdate");
return RM_ASYNC;