New Broadcast/Timer System

This commit is contained in:
GreYFoXGTi 2010-11-30 04:24:15 +02:00
parent b22f6e0036
commit af44a79b03
5 changed files with 95 additions and 81 deletions

View file

@ -56,9 +56,12 @@ void CHud::RenderGameTimer()
else
Time = (Client()->GameTick()-m_pClient->m_Snap.m_pGameobj->m_RoundStartTick)/Client()->GameTickSpeed();
str_format(Buf, sizeof(Buf), "%d:%02d", Time/60, Time%60);
if(Time <= 0)
str_format(Buf, sizeof(Buf), "00:00.0");
else
str_format(Buf, sizeof(Buf), "%02d:%02d.%d", Time/60, Time%60, m_DDRaceTick/10);
float FontSize = 10.0f;
float w = TextRender()->TextWidth(0, FontSize, Buf, -1);
float w = TextRender()->TextWidth(0, 12,"00:00.0",-1);
TextRender()->Text(0, Half-w/2, 2, FontSize, Buf, -1);
}
}
@ -319,7 +322,7 @@ void CHud::RenderHealthAndAmmo()
Graphics()->QuadsEnd();
}
void CHud::RenderTime()
void CHud::RenderDDRaceEffects()
{
// check racestate
if(m_FinishTime && m_LastReceivedTimeTick + Client()->GameTickSpeed()*2 < Client()->GameTick())
@ -336,14 +339,9 @@ void CHud::RenderTime()
{
str_format(aBuf, sizeof(aBuf), "Finish time: %02d:%02d.%02d", m_DDRaceTime/6000, m_DDRaceTime/100-m_DDRaceTime/6000 * 60, m_DDRaceTime % 100);
TextRender()->Text(0, 150*Graphics()->ScreenAspect()-TextRender()->TextWidth(0,12,aBuf,-1)/2, 20, 12, aBuf, -1);
m_CheckpointTick = 0;
}
else if(m_DDRaceTimeReceived)
{
str_format(aBuf, sizeof(aBuf), "%02d:%02d.%d", m_DDRaceTime/60, m_DDRaceTime%60, m_DDRaceTick/10);
TextRender()->Text(0, 150*Graphics()->ScreenAspect()-TextRender()->TextWidth(0,12,"00:00.0",-1)/2, 20, 12, aBuf, -1); // use fixed value for text width so its not shaky
}
if(m_CheckpointTick+Client()->GameTickSpeed()*6 > Client()->GameTick())
else if(m_CheckpointTick + Client()->GameTickSpeed()*6 > Client()->GameTick())
{
str_format(aBuf, sizeof(aBuf), "%+5.2f", m_CheckpointDiff);
@ -361,11 +359,18 @@ void CHud::RenderTime()
TextRender()->TextColor(0.5f,1.0f,0.5f,a); // green
else if(!m_CheckpointDiff)
TextRender()->TextColor(1,1,1,a); // white
TextRender()->Text(0, 150*Graphics()->ScreenAspect()-TextRender()->TextWidth(0, 10, aBuf, -1)/2, 33, 10, aBuf, -1);
TextRender()->Text(0, 150*Graphics()->ScreenAspect()-TextRender()->TextWidth(0, 10, aBuf, -1)/2, 20, 10, aBuf, -1);
TextRender()->TextColor(1,1,1,1);
}
}
/*else if(m_DDRaceTimeReceived)
{
str_format(aBuf, sizeof(aBuf), "%02d:%02d.%d", m_DDRaceTime/60, m_DDRaceTime%60, m_DDRaceTick/10);
TextRender()->Text(0, 150*Graphics()->ScreenAspect()-TextRender()->TextWidth(0, 12,"00:00.0",-1)/2, 20, 12, aBuf, -1); // use fixed value for text width so its not shaky
}*/
static int LastChangeTick = 0;
if(LastChangeTick != Client()->PredGameTick())
@ -412,7 +417,7 @@ void CHud::OnRender()
if(m_pClient->m_Snap.m_pLocalCharacter && !Spectate && !(m_pClient->m_Snap.m_pGameobj && m_pClient->m_Snap.m_pGameobj->m_GameOver)) {
RenderHealthAndAmmo();
RenderTime();
RenderDDRaceEffects();
}

View file

@ -31,7 +31,7 @@ class CHud : public CComponent
void RenderSuddenDeath();
void RenderScoreHud();
void RenderWarmupTimer();
void RenderTime();
void RenderDDRaceEffects();
void RenderRecord();
void MapscreenToGroup(float CenterX, float CenterY, struct CMapItemGroup *PGroup);

View file

@ -78,7 +78,7 @@ bool CCharacter::Spawn(CPlayer *pPlayer, vec2 Pos)
m_BroadCast = true;
m_EyeEmote = true;
m_Fly = true;
m_TimerReseted = false;
m_LastBroadcast = 0;
m_TeamBeforeSuper = 0;
CGameControllerDDRace* Controller = (CGameControllerDDRace*)GameServer()->m_pController;
m_Core.Init(&GameServer()->m_World.m_Core, GameServer()->Collision(), &Controller->m_Teams.m_Core);
@ -771,88 +771,58 @@ void CCharacter::Tick()
m_Core.m_HookTick = 0;
/*dbg_msg("character","m_TileIndex=%d , m_TileFIndex=%d",m_TileIndex,m_TileFIndex); //REMOVE*/
//DDRace
char aBuftime[128];
char aBroadcast[128];
m_Time = (float)(Server()->Tick() - m_StartTime) / ((float)Server()->TickSpeed());
CPlayerData *pData = GameServer()->Score()->PlayerData(m_pPlayer->GetCID());
if(!m_TimerReseted && m_DDRaceState == DDRACE_CHEAT) {
m_TimerReseted = true;
CNetMsg_Sv_DDRaceTime Msg;
Msg.m_Time = 0;
Msg.m_Check = 0;
Msg.m_Finish = 0;
Server()->SendPackMsg(&Msg, MSGFLAG_VITAL, m_pPlayer->GetCID());
}
if(Server()->Tick() - m_RefreshTime >= Server()->TickSpeed())
{
if (m_DDRaceState == DDRACE_STARTED) {
int IntTime = (int)m_Time;
if(m_pPlayer->m_IsUsingDDRaceClient) {
CNetMsg_Sv_DDRaceTime Msg;
Msg.m_Time = IntTime;
Msg.m_Check = 0;
Msg.m_Finish = 0;
if(m_CpActive != -1 && m_CpTick > Server()->Tick())
if (m_DDRaceState == DDRACE_STARTED)
{
if(m_CpActive != -1 && m_CpTick > Server()->Tick() && !m_pPlayer->m_IsUsingDDRaceClient)
{
if(pData->m_BestTime && pData->m_aBestCpTime[m_CpActive] != 0)
{
if(pData->m_BestTime && pData->m_aBestCpTime[m_CpActive] != 0)
{
float Diff = (m_CpCurrent[m_CpActive] - pData->m_aBestCpTime[m_CpActive])*100;
Msg.m_Check = (int)Diff;
}
}
Server()->SendPackMsg(&Msg, MSGFLAG_VITAL, m_pPlayer->GetCID());
} else {
if(m_BroadTime)
str_format(aBuftime, sizeof(aBuftime), "%s%d:%s%d", ((IntTime/60) > 9)?"":"0", IntTime/60, ((IntTime%60) > 9)?"":"0", IntTime%60);
else
str_format(aBuftime, sizeof(aBuftime), "");
if(m_CpActive != -1 && m_CpTick > Server()->Tick())
{
if(pData->m_BestTime && pData->m_aBestCpTime[m_CpActive] != 0)
{
char aTmp[128];
float Diff = m_CpCurrent[m_CpActive] - pData->m_aBestCpTime[m_CpActive];
str_format(aTmp, sizeof(aTmp), "\nCheckpoint | Diff : %+5.2f", Diff);
strcat(aBuftime, aTmp);
}
}
if( g_Config.m_SvBroadcast[0] != 0 && m_BroadCast)
{
char aTmp[128];
str_format(aTmp, sizeof(aTmp), "\n%s\n", g_Config.m_SvBroadcast);
strcat(aBuftime, aTmp);
}
if(Server()->Tick() >= (m_LastBroadcast + Server()->TickSpeed()))
{
GameServer()->SendBroadcast(aBuftime, m_pPlayer->GetCID());
float Diff = m_CpCurrent[m_CpActive] - pData->m_aBestCpTime[m_CpActive];
str_format(aBroadcast, sizeof(aBroadcast), "Checkpoint | Diff : %+5.2f", Diff);
GameServer()->SendBroadcast(aBroadcast, m_pPlayer->GetCID());
m_LastBroadcast = Server()->Tick();
}
}
} else {
else if( g_Config.m_SvBroadcast[0] != 0 && m_BroadCast)
{
str_format(aBroadcast, sizeof(aBroadcast), "%s", g_Config.m_SvBroadcast);
if(Server()->Tick() >= (m_LastBroadcast + Server()->TickSpeed()))
{
GameServer()->SendBroadcast(aBroadcast, m_pPlayer->GetCID());
m_LastBroadcast = Server()->Tick();
}
}
}
else
{
char aTmp[128];
if(!m_pPlayer->m_IsUsingDDRaceClient)
{
if( g_Config.m_SvBroadcast[0] != 0 && (Server()->Tick() > (m_LastBroadcast + (Server()->TickSpeed() * 9)))) {
char aTmp[128], aYourBest[64],aServerBest[64];
if( g_Config.m_SvBroadcast[0] != 0 && (Server()->Tick() > (m_LastBroadcast + (Server()->TickSpeed() * 9))))
{
char aYourBest[64],aServerBest[64];
str_format(aYourBest, sizeof(aYourBest), "Your Best:'%s%d:%s%d'", ((pData->m_BestTime / 60) < 10)?"0":"", (int)(pData->m_BestTime / 60), (((int)pData->m_BestTime % 60) < 10)?"0":"", (int)pData->m_BestTime % 60);
CPlayerData *pData = GameServer()->Score()->PlayerData(m_pPlayer->GetCID());
str_format(aServerBest, sizeof(aServerBest), "Server Best:'%s%d:%s%d'", ((GameServer()->m_pController->m_CurrentRecord / 60) < 10)?"0":"", (int)(GameServer()->m_pController->m_CurrentRecord / 60), (((int)GameServer()->m_pController->m_CurrentRecord % 60) < 10)?"0":"", (int)GameServer()->m_pController->m_CurrentRecord % 60);
str_format(aTmp, sizeof(aTmp), "%s\n%s %s", g_Config.m_SvBroadcast, (GameServer()->m_pController->m_CurrentRecord)?aServerBest:"", (pData->m_BestTime)?aYourBest:"");
str_format(aTmp, sizeof(aTmp), "%s %s", (GameServer()->m_pController->m_CurrentRecord)?aServerBest:"", (pData->m_BestTime)?aYourBest:"");
GameServer()->SendBroadcast(aTmp, m_pPlayer->GetCID());
m_LastBroadcast = Server()->Tick();
}
} else {
//make there smthing with broadcast
}
else if( g_Config.m_SvBroadcast[0] != 0 && (Server()->Tick() > (m_LastBroadcast + (Server()->TickSpeed() * 9))))
{
str_format(aTmp, sizeof(aTmp), "%s", g_Config.m_SvBroadcast);
GameServer()->SendBroadcast(aTmp, m_pPlayer->GetCID());
m_LastBroadcast = Server()->Tick();
}
}
m_RefreshTime = Server()->Tick();
@ -950,6 +920,24 @@ void CCharacter::HandleTiles(int Index)
m_CpActive = cp;
m_CpCurrent[cp] = m_Time;
m_CpTick = Server()->Tick() + Server()->TickSpeed()*2;
if(m_pPlayer->m_IsUsingDDRaceClient) {
CPlayerData *pData = GameServer()->Score()->PlayerData(m_pPlayer->GetCID());
CNetMsg_Sv_DDRaceTime Msg;
Msg.m_Time = (int)m_Time;
Msg.m_Check = 0;
Msg.m_Finish = 0;
if(m_CpActive != -1 && m_CpTick > Server()->Tick())
{
if(pData->m_BestTime && pData->m_aBestCpTime[m_CpActive] != 0)
{
float Diff = (m_CpCurrent[m_CpActive] - pData->m_aBestCpTime[m_CpActive])*100;
Msg.m_Check = (int)Diff;
}
}
Server()->SendPackMsg(&Msg, MSGFLAG_VITAL, m_pPlayer->GetCID());
}
}
int cpf = GameServer()->Collision()->IsFCheckpoint(MapIndex);
if(cpf != -1 && m_DDRaceState == DDRACE_STARTED && cpf > m_CpActive)
@ -957,6 +945,24 @@ void CCharacter::HandleTiles(int Index)
m_CpActive = cpf;
m_CpCurrent[cpf] = m_Time;
m_CpTick = Server()->Tick() + Server()->TickSpeed()*2;
if(m_pPlayer->m_IsUsingDDRaceClient) {
CPlayerData *pData = GameServer()->Score()->PlayerData(m_pPlayer->GetCID());
CNetMsg_Sv_DDRaceTime Msg;
Msg.m_Time = (int)m_Time;
Msg.m_Check = 0;
Msg.m_Finish = 0;
if(m_CpActive != -1 && m_CpTick > Server()->Tick())
{
if(pData->m_BestTime && pData->m_aBestCpTime[m_CpActive] != 0)
{
float Diff = (m_CpCurrent[m_CpActive] - pData->m_aBestCpTime[m_CpActive])*100;
Msg.m_Check = (int)Diff;
}
}
Server()->SendPackMsg(&Msg, MSGFLAG_VITAL, m_pPlayer->GetCID());
}
}
if(((m_TileIndex == TILE_BEGIN) || (m_TileFIndex == TILE_BEGIN) || FTile1 == TILE_BEGIN || FTile2 == TILE_BEGIN || FTile3 == TILE_BEGIN || FTile4 == TILE_BEGIN || Tile1 == TILE_BEGIN || Tile2 == TILE_BEGIN || Tile3 == TILE_BEGIN || Tile4 == TILE_BEGIN) && (m_DDRaceState == DDRACE_NONE || (m_DDRaceState == DDRACE_STARTED && !Team())))
{

View file

@ -132,9 +132,6 @@ public:
// weapon info
CEntity *m_apHitObjects[10];
int m_NumObjectsHit;
bool m_TimerReseted;
int m_QueuedWeapon;

View file

@ -741,7 +741,13 @@ void IGameController::Snap(int SnappingClient)
//pGameObj->m_ScoreLimit = g_Config.m_SvScorelimit;
//pGameObj->m_TimeLimit = g_Config.m_SvTimelimit;
pGameObj->m_RoundStartTick = m_RoundStartTick;
CCharacter *pChar;
CPlayer *pPlayer;
if (pPlayer = GameServer()->m_apPlayers[SnappingClient])
if(pChar = pPlayer->GetCharacter())
pGameObj->m_RoundStartTick = (pChar->m_DDRaceState == DDRACE_STARTED)?pChar->m_StartTime:Server()->Tick();
pGameObj->m_Flags = m_GameFlags;
pGameObj->m_Warmup = m_Warmup;