From 2b2ddde04f3d61b09129f944387279906c73f6a4 Mon Sep 17 00:00:00 2001 From: oy Date: Thu, 4 Aug 2011 23:43:39 +0200 Subject: sort players in kick/move to spec vote and player options by team. Closes #809 --- src/game/client/gameclient.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/game/client/gameclient.cpp') diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp index 7b6b1192..d110bfe7 100644 --- a/src/game/client/gameclient.cpp +++ b/src/game/client/gameclient.cpp @@ -862,6 +862,17 @@ void CGameClient::OnNewSnapshot() } } } + // sort player infos by team + int Teams[3] = { TEAM_RED, TEAM_BLUE, TEAM_SPECTATORS }; + int Index = 0; + for(int Team = 0; Team < 3; ++Team) + { + for(int i = 0; i < MAX_CLIENTS && Index < MAX_CLIENTS; ++i) + { + if(m_Snap.m_paPlayerInfos[i] && m_Snap.m_paPlayerInfos[i]->m_Team == Teams[Team]) + m_Snap.m_paInfoByTeam[Index++] = m_Snap.m_paPlayerInfos[i]; + } + } CTuningParams StandardTuning; CServerInfo CurrentServerInfo; -- cgit 1.4.1 From b99ac459bea247f2a2474b345b1dd69e4bd59a69 Mon Sep 17 00:00:00 2001 From: oy Date: Sun, 4 Dec 2011 14:04:12 +0100 Subject: fixed envelope rendering when seeking in the demo player --- src/game/client/components/maplayers.cpp | 30 +++++++++++++++++++++--------- src/game/client/components/maplayers.h | 5 +++++ src/game/client/components/menus_demo.cpp | 3 +++ src/game/client/gameclient.cpp | 2 ++ src/game/client/gameclient.h | 2 ++ 5 files changed, 33 insertions(+), 9 deletions(-) (limited to 'src/game/client/gameclient.cpp') diff --git a/src/game/client/components/maplayers.cpp b/src/game/client/components/maplayers.cpp index 3d9c42e7..48f11f26 100644 --- a/src/game/client/components/maplayers.cpp +++ b/src/game/client/components/maplayers.cpp @@ -22,6 +22,9 @@ CMapLayers::CMapLayers(int t) { m_Type = t; m_pLayers = 0; + m_CurrentLocalTick = 0; + m_LastLocalTick = 0; + m_EnvelopeUpdate = false; } void CMapLayers::OnInit() @@ -29,6 +32,17 @@ void CMapLayers::OnInit() m_pLayers = Layers(); } +void CMapLayers::EnvelopeUpdate() +{ + if(Client()->State() == IClient::STATE_DEMOPLAYBACK) + { + const IDemoPlayer::CInfo *pInfo = DemoPlayer()->BaseInfo(); + m_CurrentLocalTick = pInfo->m_CurrentTick; + m_LastLocalTick = pInfo->m_CurrentTick; + m_EnvelopeUpdate = true; + } +} + void CMapLayers::MapScreenToGroup(float CenterX, float CenterY, CMapItemGroup *pGroup) { @@ -67,19 +81,17 @@ void CMapLayers::EnvelopeEval(float TimeOffset, int Env, float *pChannels, void if(pThis->Client()->State() == IClient::STATE_DEMOPLAYBACK) { const IDemoPlayer::CInfo *pInfo = pThis->DemoPlayer()->BaseInfo(); - static int CurrentLocalTick = pInfo->m_CurrentTick; - static int LastLocalTick = pInfo->m_CurrentTick; - - if(!pInfo->m_Paused) + + if(!pInfo->m_Paused || pThis->m_EnvelopeUpdate) { - if(CurrentLocalTick != pInfo->m_CurrentTick) + if(pThis->m_CurrentLocalTick != pInfo->m_CurrentTick) { - LastLocalTick = CurrentLocalTick; - CurrentLocalTick = pInfo->m_CurrentTick; + pThis->m_LastLocalTick = pThis->m_CurrentLocalTick; + pThis->m_CurrentLocalTick = pInfo->m_CurrentTick; } - Time = mix(LastLocalTick / (float)pThis->Client()->GameTickSpeed(), - CurrentLocalTick / (float)pThis->Client()->GameTickSpeed(), + Time = mix(pThis->m_LastLocalTick / (float)pThis->Client()->GameTickSpeed(), + pThis->m_CurrentLocalTick / (float)pThis->Client()->GameTickSpeed(), pThis->Client()->IntraGameTick()); } diff --git a/src/game/client/components/maplayers.h b/src/game/client/components/maplayers.h index 694633ee..d0efcfc7 100644 --- a/src/game/client/components/maplayers.h +++ b/src/game/client/components/maplayers.h @@ -8,6 +8,9 @@ class CMapLayers : public CComponent { CLayers *m_pLayers; // todo refactor: maybe remove it and access it through client* int m_Type; + int m_CurrentLocalTick; + int m_LastLocalTick; + bool m_EnvelopeUpdate; void MapScreenToGroup(float CenterX, float CenterY, CMapItemGroup *pGroup); static void EnvelopeEval(float TimeOffset, int Env, float *pChannels, void *pUser); @@ -21,6 +24,8 @@ public: CMapLayers(int Type); virtual void OnInit(); virtual void OnRender(); + + void EnvelopeUpdate(); }; #endif diff --git a/src/game/client/components/menus_demo.cpp b/src/game/client/components/menus_demo.cpp index f3a75f0c..ec3e648c 100644 --- a/src/game/client/components/menus_demo.cpp +++ b/src/game/client/components/menus_demo.cpp @@ -17,6 +17,7 @@ #include +#include "maplayers.h" #include "menus.h" int CMenus::DoButton_DemoPlayer(const void *pID, const char *pText, int Checked, const CUIRect *pRect) @@ -117,6 +118,8 @@ void CMenus::RenderDemoPlayer(CUIRect MainView) m_pClient->m_SuppressEvents = true; DemoPlayer()->SetPos(Amount); m_pClient->m_SuppressEvents = false; + m_pClient->m_pMapLayersBackGround->EnvelopeUpdate(); + m_pClient->m_pMapLayersForeGround->EnvelopeUpdate(); } } } diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp index d110bfe7..2fd1c2f3 100644 --- a/src/game/client/gameclient.cpp +++ b/src/game/client/gameclient.cpp @@ -126,6 +126,8 @@ void CGameClient::OnConsoleInit() m_pVoting = &::gs_Voting; m_pScoreboard = &::gs_Scoreboard; m_pItems = &::gs_Items; + m_pMapLayersBackGround = &::gs_MapLayersBackGround; + m_pMapLayersForeGround = &::gs_MapLayersForeGround; // make a list of all the systems, make sure to add them in the corrent render order m_All.Add(m_pSkins); diff --git a/src/game/client/gameclient.h b/src/game/client/gameclient.h index 0dff77d4..e8c7e7bd 100644 --- a/src/game/client/gameclient.h +++ b/src/game/client/gameclient.h @@ -242,6 +242,8 @@ public: class CVoting *m_pVoting; class CScoreboard *m_pScoreboard; class CItems *m_pItems; + class CMapLayers *m_pMapLayersBackGround; + class CMapLayers *m_pMapLayersForeGround; }; -- cgit 1.4.1 From afb1d5e20158de57e7e6fcb49be5204b02a8fe12 Mon Sep 17 00:00:00 2001 From: BeaR Date: Sun, 4 Sep 2011 11:13:30 +0200 Subject: Swap and Shuffle Teams --- src/game/client/gameclient.cpp | 2 ++ src/game/server/gamecontext.cpp | 65 +++++++++++++++++++++++++++++++++++++++++ src/game/server/gamecontext.h | 2 ++ 3 files changed, 69 insertions(+) (limited to 'src/game/client/gameclient.cpp') diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp index 2fd1c2f3..836e7a9d 100644 --- a/src/game/client/gameclient.cpp +++ b/src/game/client/gameclient.cpp @@ -194,6 +194,8 @@ void CGameClient::OnConsoleInit() Console()->Register("force_vote", "ss?r", CFGFLAG_SERVER, 0, 0, "Force a voting option"); Console()->Register("clear_votes", "", CFGFLAG_SERVER, 0, 0, "Clears the voting options"); Console()->Register("vote", "r", CFGFLAG_SERVER, 0, 0, "Force a vote to yes/no"); + Console()->Register("swap_teams", "", CFGFLAG_SERVER, 0, 0, "Swap the current teams"); + Console()->Register("shuffle_teams", "", CFGFLAG_SERVER, 0, 0, "Shuffle the current teams"); // propagate pointers diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index ca429d79..707126b1 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -1076,6 +1076,69 @@ void CGameContext::ConSetTeamAll(IConsole::IResult *pResult, void *pUserData) (void)pSelf->m_pController->CheckTeamBalance(); } +void CGameContext::ConSwapTeams(IConsole::IResult *pResult, void *pUserData) +{ + CGameContext *pSelf = (CGameContext *)pUserData; + + char aBuf[256]; + str_format(aBuf, sizeof(aBuf), "swaped the current teams"); + pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf); + + for(int i = 0; i < MAX_CLIENTS; ++i) + { + if(pSelf->m_apPlayers[i] && pSelf->m_apPlayers[i]->GetTeam() != TEAM_SPECTATORS) + { + int Team = pSelf->m_apPlayers[i]->GetTeam(); + if(Team == TEAM_RED) + pSelf->m_apPlayers[i]->SetTeam(TEAM_BLUE); + else + pSelf->m_apPlayers[i]->SetTeam(TEAM_RED); + } + } + + (void)pSelf->m_pController->CheckTeamBalance(); + + + +} + +void CGameContext::ConShuffleTeams(IConsole::IResult *pResult, void *pUserData) +{ + CGameContext *pSelf = (CGameContext *)pUserData; + int counterRed = 0; + int counterBlue = 0; + int PlayerTeam = (g_Config.m_SvMaxClients-g_Config.m_SvSpectatorSlots)/2; + + char aBuf[256]; + str_format(aBuf, sizeof(aBuf), "shuffled the current teams"); + pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf); + + + for(int i = 0; i < MAX_CLIENTS; ++i) + { + if(pSelf->m_apPlayers[i] && pSelf->m_apPlayers[i]->GetTeam() != TEAM_SPECTATORS) + { + if( counterRed == PlayerTeam ) + pSelf->m_apPlayers[i]->SetTeam(TEAM_BLUE); + else if( counterBlue == PlayerTeam ) + pSelf->m_apPlayers[i]->SetTeam(TEAM_RED); + else + { + if(rand() % 2) + { + pSelf->m_apPlayers[i]->SetTeam(TEAM_BLUE); + ++counterBlue; + } + else + { + pSelf->m_apPlayers[i]->SetTeam(TEAM_RED); + ++counterRed; + } + } + } + } +} + void CGameContext::ConAddVote(IConsole::IResult *pResult, void *pUserData) { CGameContext *pSelf = (CGameContext *)pUserData; @@ -1335,6 +1398,8 @@ void CGameContext::OnConsoleInit() Console()->Register("say", "r", CFGFLAG_SERVER, ConSay, this, "Say in chat"); Console()->Register("set_team", "ii?i", CFGFLAG_SERVER, ConSetTeam, this, "Set team of player to team"); Console()->Register("set_team_all", "i", CFGFLAG_SERVER, ConSetTeamAll, this, "Set team of all players to team"); + Console()->Register("swap_teams", "", CFGFLAG_SERVER, ConSwapTeams, this, "Swap the current teams"); + Console()->Register("shuffle_teams", "", CFGFLAG_SERVER, ConShuffleTeams, this, "Shuffle the current teams"); Console()->Register("add_vote", "sr", CFGFLAG_SERVER, ConAddVote, this, "Add a voting option"); Console()->Register("remove_vote", "s", CFGFLAG_SERVER, ConRemoveVote, this, "remove a voting option"); diff --git a/src/game/server/gamecontext.h b/src/game/server/gamecontext.h index 6288850d..b899f2d8 100644 --- a/src/game/server/gamecontext.h +++ b/src/game/server/gamecontext.h @@ -54,6 +54,8 @@ class CGameContext : public IGameServer static void ConSay(IConsole::IResult *pResult, void *pUserData); static void ConSetTeam(IConsole::IResult *pResult, void *pUserData); static void ConSetTeamAll(IConsole::IResult *pResult, void *pUserData); + static void ConSwapTeams(IConsole::IResult *pResult, void *pUserData); + static void ConShuffleTeams(IConsole::IResult *pResult, void *pUserData); static void ConAddVote(IConsole::IResult *pResult, void *pUserData); static void ConRemoveVote(IConsole::IResult *pResult, void *pUserData); static void ConForceVote(IConsole::IResult *pResult, void *pUserData); -- cgit 1.4.1 From b31abc40537bff7e159091ff61d5af442296c4d9 Mon Sep 17 00:00:00 2001 From: Magnus Auvinen Date: Sat, 31 Dec 2011 10:29:25 +0100 Subject: fixed so that you can select graphics backend via gfx_threaded --- src/engine/client/client.cpp | 23 +++++++++++++++-------- src/engine/client/graphics.cpp | 2 +- src/engine/client/graphics_threaded.cpp | 2 +- src/engine/graphics.h | 1 + src/engine/shared/config_variables.h | 2 ++ src/game/client/gameclient.cpp | 12 +++++++----- 6 files changed, 27 insertions(+), 15 deletions(-) (limited to 'src/game/client/gameclient.cpp') diff --git a/src/engine/client/client.cpp b/src/engine/client/client.cpp index 53f60fa8..b54b9084 100644 --- a/src/engine/client/client.cpp +++ b/src/engine/client/client.cpp @@ -1676,7 +1676,7 @@ void CClient::InitInterfaces() // fetch interfaces m_pEngine = Kernel()->RequestInterface(); m_pEditor = Kernel()->RequestInterface(); - m_pGraphics = Kernel()->RequestInterface(); + //m_pGraphics = Kernel()->RequestInterface(); m_pSound = Kernel()->RequestInterface(); m_pGameClient = Kernel()->RequestInterface(); m_pInput = Kernel()->RequestInterface(); @@ -1698,10 +1698,21 @@ void CClient::Run() m_SnapshotParts = 0; // init graphics - if(m_pGraphics->Init() != 0) { - dbg_msg("client", "couldn't init graphics"); - return; + if(g_Config.m_GfxThreaded) + m_pGraphics = CreateEngineGraphicsThreaded(); + else + m_pGraphics = CreateEngineGraphics(); + + bool RegisterFail = false; + RegisterFail = RegisterFail || !Kernel()->RegisterInterface(static_cast(m_pGraphics)); // register graphics as both + RegisterFail = RegisterFail || !Kernel()->RegisterInterface(static_cast(m_pGraphics)); + + if(RegisterFail || m_pGraphics->Init() != 0) + { + dbg_msg("client", "couldn't init graphics"); + return; + } } // open socket @@ -2220,7 +2231,6 @@ int main(int argc, const char **argv) // ignore_convention IConsole *pConsole = CreateConsole(CFGFLAG_CLIENT); IStorage *pStorage = CreateStorage("Teeworlds", argc, argv); // ignore_convention IConfig *pConfig = CreateConfig(); - IEngineGraphics *pEngineGraphics = CreateEngineGraphics(); IEngineSound *pEngineSound = CreateEngineSound(); IEngineInput *pEngineInput = CreateEngineInput(); IEngineTextRender *pEngineTextRender = CreateEngineTextRender(); @@ -2234,9 +2244,6 @@ int main(int argc, const char **argv) // ignore_convention RegisterFail = RegisterFail || !pKernel->RegisterInterface(pConsole); RegisterFail = RegisterFail || !pKernel->RegisterInterface(pConfig); - RegisterFail = RegisterFail || !pKernel->RegisterInterface(static_cast(pEngineGraphics)); // register graphics as both - RegisterFail = RegisterFail || !pKernel->RegisterInterface(static_cast(pEngineGraphics)); - RegisterFail = RegisterFail || !pKernel->RegisterInterface(static_cast(pEngineSound)); // register as both RegisterFail = RegisterFail || !pKernel->RegisterInterface(static_cast(pEngineSound)); diff --git a/src/engine/client/graphics.cpp b/src/engine/client/graphics.cpp index 03a6e7cd..fda85312 100644 --- a/src/engine/client/graphics.cpp +++ b/src/engine/client/graphics.cpp @@ -978,4 +978,4 @@ void CGraphics_SDL::WaitForIdle() { } -//extern IEngineGraphics *CreateEngineGraphics() { return new CGraphics_SDL(); } +extern IEngineGraphics *CreateEngineGraphics() { return new CGraphics_SDL(); } diff --git a/src/engine/client/graphics_threaded.cpp b/src/engine/client/graphics_threaded.cpp index e702133a..2b9147ff 100644 --- a/src/engine/client/graphics_threaded.cpp +++ b/src/engine/client/graphics_threaded.cpp @@ -1293,4 +1293,4 @@ int CGraphics_Threaded::GetVideoModes(CVideoMode *pModes, int MaxModes) } -extern IEngineGraphics *CreateEngineGraphics() { return new CGraphics_Threaded(); } +extern IEngineGraphics *CreateEngineGraphicsThreaded() { return new CGraphics_Threaded(); } diff --git a/src/engine/graphics.h b/src/engine/graphics.h index 1c79ee15..be113b2d 100644 --- a/src/engine/graphics.h +++ b/src/engine/graphics.h @@ -157,5 +157,6 @@ public: }; extern IEngineGraphics *CreateEngineGraphics(); +extern IEngineGraphics *CreateEngineGraphicsThreaded(); #endif diff --git a/src/engine/shared/config_variables.h b/src/engine/shared/config_variables.h index 352cefd8..e7b1f7da 100644 --- a/src/engine/shared/config_variables.h +++ b/src/engine/shared/config_variables.h @@ -72,6 +72,8 @@ MACRO_CONFIG_INT(GfxRefreshRate, gfx_refresh_rate, 0, 0, 0, CFGFLAG_SAVE|CFGFLAG MACRO_CONFIG_INT(GfxFinish, gfx_finish, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "") MACRO_CONFIG_INT(GfxAsyncRender, gfx_asyncrender, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Do rendering async from the the update") +MACRO_CONFIG_INT(GfxThreaded, gfx_threaded, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Use the threaded graphics backend") + MACRO_CONFIG_INT(InpMousesens, inp_mousesens, 100, 5, 100000, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Mouse sensitivity") MACRO_CONFIG_STR(SvName, sv_name, 128, "unnamed server", CFGFLAG_SERVER, "Server name") diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp index 2fd1c2f3..d62a16eb 100644 --- a/src/game/client/gameclient.cpp +++ b/src/game/client/gameclient.cpp @@ -95,7 +95,6 @@ void CGameClient::OnConsoleInit() { m_pEngine = Kernel()->RequestInterface(); m_pClient = Kernel()->RequestInterface(); - m_pGraphics = Kernel()->RequestInterface(); m_pTextRender = Kernel()->RequestInterface(); m_pSound = Kernel()->RequestInterface(); m_pInput = Kernel()->RequestInterface(); @@ -196,10 +195,6 @@ void CGameClient::OnConsoleInit() Console()->Register("vote", "r", CFGFLAG_SERVER, 0, 0, "Force a vote to yes/no"); - // propagate pointers - m_UI.SetGraphics(Graphics(), TextRender()); - m_RenderTools.m_pGraphics = Graphics(); - m_RenderTools.m_pUI = UI(); for(int i = 0; i < m_All.m_Num; i++) m_All.m_paComponents[i]->m_pClient = this; @@ -223,6 +218,13 @@ void CGameClient::OnConsoleInit() void CGameClient::OnInit() { + m_pGraphics = Kernel()->RequestInterface(); + + // propagate pointers + m_UI.SetGraphics(Graphics(), TextRender()); + m_RenderTools.m_pGraphics = Graphics(); + m_RenderTools.m_pUI = UI(); + int64 Start = time_get(); // set the language -- cgit 1.4.1 From b592d7a591f32ecdc2c91a79b76c58f77a2b5fee Mon Sep 17 00:00:00 2001 From: oy Date: Fri, 6 Jan 2012 19:38:40 +0100 Subject: cleaned up playing of global sounds --- src/game/client/components/chat.cpp | 6 +-- src/game/client/components/effects.cpp | 6 +-- src/game/client/components/menus.cpp | 2 +- src/game/client/components/menus_settings.cpp | 4 +- src/game/client/components/players.cpp | 2 +- src/game/client/components/sounds.cpp | 65 ++++++++++++++++++--------- src/game/client/components/sounds.h | 5 ++- src/game/client/gameclient.cpp | 4 +- 8 files changed, 61 insertions(+), 33 deletions(-) (limited to 'src/game/client/gameclient.cpp') diff --git a/src/game/client/components/chat.cpp b/src/game/client/components/chat.cpp index a3bf5252..a89d2b7e 100644 --- a/src/game/client/components/chat.cpp +++ b/src/game/client/components/chat.cpp @@ -323,11 +323,11 @@ void CChat::AddLine(int ClientID, int Team, const char *pLine) // play sound if(ClientID == -1) - m_pClient->m_pSounds->Play(CSounds::CHN_GUI, SOUND_CHAT_SERVER, 0, vec2(0,0)); + m_pClient->m_pSounds->Play(CSounds::CHN_GUI, SOUND_CHAT_SERVER, 0); else if(Highlighted) - m_pClient->m_pSounds->Play(CSounds::CHN_GUI, SOUND_CHAT_HIGHLIGHT, 0, vec2(0.0f, 0.0f)); + m_pClient->m_pSounds->Play(CSounds::CHN_GUI, SOUND_CHAT_HIGHLIGHT, 0); else - m_pClient->m_pSounds->Play(CSounds::CHN_GUI, SOUND_CHAT_CLIENT, 0, vec2(0,0)); + m_pClient->m_pSounds->Play(CSounds::CHN_GUI, SOUND_CHAT_CLIENT, 0); } void CChat::OnRender() diff --git a/src/game/client/components/effects.cpp b/src/game/client/components/effects.cpp index 8554b7ba..933e7fe6 100644 --- a/src/game/client/components/effects.cpp +++ b/src/game/client/components/effects.cpp @@ -44,7 +44,7 @@ void CEffects::AirJump(vec2 Pos) p.m_Pos = Pos + vec2(6.0f, 16.0f); m_pClient->m_pParticles->Add(CParticles::GROUP_GENERAL, &p); - m_pClient->m_pSounds->Play(CSounds::CHN_WORLD, SOUND_PLAYER_AIRJUMP, 1.0f, Pos); + m_pClient->m_pSounds->PlayAt(CSounds::CHN_WORLD, SOUND_PLAYER_AIRJUMP, 1.0f, Pos); } void CEffects::DamageIndicator(vec2 Pos, vec2 Dir) @@ -147,7 +147,7 @@ void CEffects::PlayerSpawn(vec2 Pos) m_pClient->m_pParticles->Add(CParticles::GROUP_GENERAL, &p); } - m_pClient->m_pSounds->Play(CSounds::CHN_WORLD, SOUND_PLAYER_SPAWN, 1.0f, Pos); + m_pClient->m_pSounds->PlayAt(CSounds::CHN_WORLD, SOUND_PLAYER_SPAWN, 1.0f, Pos); } void CEffects::PlayerDeath(vec2 Pos, int ClientID) @@ -242,7 +242,7 @@ void CEffects::HammerHit(vec2 Pos) p.m_EndSize = 0; p.m_Rot = frandom()*pi*2; m_pClient->m_pParticles->Add(CParticles::GROUP_EXPLOSIONS, &p); - m_pClient->m_pSounds->Play(CSounds::CHN_WORLD, SOUND_HAMMER_HIT, 1.0f, Pos); + m_pClient->m_pSounds->PlayAt(CSounds::CHN_WORLD, SOUND_HAMMER_HIT, 1.0f, Pos); } void CEffects::OnRender() diff --git a/src/game/client/components/menus.cpp b/src/game/client/components/menus.cpp index 0e61ec6e..a2ccfba4 100644 --- a/src/game/client/components/menus.cpp +++ b/src/game/client/components/menus.cpp @@ -1404,7 +1404,7 @@ void CMenus::OnStateChange(int NewState, int OldState) if(NewState == IClient::STATE_OFFLINE) { if(OldState >= IClient::STATE_ONLINE) - m_pClient->m_pSounds->Play(CSounds::CHN_MUSIC, SOUND_MENU, 1.0f, vec2(0, 0)); + m_pClient->m_pSounds->Play(CSounds::CHN_MUSIC, SOUND_MENU, 1.0f); m_Popup = POPUP_NONE; if(Client()->ErrorString() && Client()->ErrorString()[0] != 0) { diff --git a/src/game/client/components/menus_settings.cpp b/src/game/client/components/menus_settings.cpp index c9b44567..de4b10bd 100644 --- a/src/game/client/components/menus_settings.cpp +++ b/src/game/client/components/menus_settings.cpp @@ -763,7 +763,7 @@ void CMenus::RenderSettingsSound(CUIRect MainView) if(g_Config.m_SndEnable) { if(g_Config.m_SndMusic) - m_pClient->m_pSounds->Play(CSounds::CHN_MUSIC, SOUND_MENU, 1.0f, vec2(0, 0)); + m_pClient->m_pSounds->Play(CSounds::CHN_MUSIC, SOUND_MENU, 1.0f); } else m_pClient->m_pSounds->Stop(SOUND_MENU); @@ -778,7 +778,7 @@ void CMenus::RenderSettingsSound(CUIRect MainView) { g_Config.m_SndMusic ^= 1; if(g_Config.m_SndMusic) - m_pClient->m_pSounds->Play(CSounds::CHN_MUSIC, SOUND_MENU, 1.0f, vec2(0, 0)); + m_pClient->m_pSounds->Play(CSounds::CHN_MUSIC, SOUND_MENU, 1.0f); else m_pClient->m_pSounds->Stop(SOUND_MENU); } diff --git a/src/game/client/components/players.cpp b/src/game/client/components/players.cpp index 6811c2ad..2ce73384 100644 --- a/src/game/client/components/players.cpp +++ b/src/game/client/components/players.cpp @@ -347,7 +347,7 @@ void CPlayers::RenderPlayer( static int64 SkidSoundTime = 0; if(time_get()-SkidSoundTime > time_freq()/10) { - m_pClient->m_pSounds->Play(CSounds::CHN_WORLD, SOUND_PLAYER_SKID, 0.25f, Position); + m_pClient->m_pSounds->PlayAt(CSounds::CHN_WORLD, SOUND_PLAYER_SKID, 0.25f, Position); SkidSoundTime = time_get(); } diff --git a/src/game/client/components/sounds.cpp b/src/game/client/components/sounds.cpp index 65fb56fb..be63415c 100644 --- a/src/game/client/components/sounds.cpp +++ b/src/game/client/components/sounds.cpp @@ -34,6 +34,30 @@ static int LoadSoundsThread(void *pUser) return 0; } + +int CSounds::GetSampleId(int SetId) +{ + if(!g_Config.m_SndEnable || !Sound()->IsSoundEnabled() || m_WaitForSoundJob || SetId < 0 || SetId >= g_pData->m_NumSounds) + return -1; + + CDataSoundset *pSet = &g_pData->m_aSounds[SetId]; + if(!pSet->m_NumSounds) + return -1; + + if(pSet->m_NumSounds == 1) + return pSet->m_aSounds[0].m_Id; + + // return random one + int Id; + do + { + Id = rand() % pSet->m_NumSounds; + } + while(Id == pSet->m_Last); + pSet->m_Last = Id; + return pSet->m_aSounds[Id].m_Id; +} + void CSounds::OnInit() { // setup sound channels @@ -98,7 +122,7 @@ void CSounds::OnRender() int64 Now = time_get(); if(m_QueueWaitTime <= Now) { - Play(m_aQueue[0].m_Channel, m_aQueue[0].m_SetId, 1.0f, vec2(0,0)); + Play(m_aQueue[0].m_Channel, m_aQueue[0].m_SetId, 1.0f); m_QueueWaitTime = Now+time_freq()*3/10; // wait 300ms before playing the next one if(--m_QueuePos > 0) mem_move(m_aQueue, m_aQueue+1, m_QueuePos*sizeof(QueueEntry)); @@ -132,38 +156,39 @@ void CSounds::PlayAndRecord(int Chn, int SetId, float Vol, vec2 Pos) Msg.m_SoundID = SetId; Client()->SendPackMsg(&Msg, MSGFLAG_NOSEND|MSGFLAG_RECORD); - Play(Chn, SetId, Vol, Pos); + Play(Chn, SetId, Vol); } -void CSounds::Play(int Chn, int SetId, float Vol, vec2 Pos) +void CSounds::Play(int Chn, int SetId, float Vol) { - if(!g_Config.m_SndEnable || !Sound()->IsSoundEnabled() || (Chn == CHN_MUSIC && !g_Config.m_SndMusic) || m_WaitForSoundJob || SetId < 0 || SetId >= g_pData->m_NumSounds) + if(Chn == CHN_MUSIC && !g_Config.m_SndMusic) return; - CDataSoundset *pSet = &g_pData->m_aSounds[SetId]; - - if(!pSet->m_NumSounds) + int SampleId = GetSampleId(SetId); + if(SampleId == -1) return; int Flags = 0; if(Chn == CHN_MUSIC) Flags = ISound::FLAG_LOOP; - if(pSet->m_NumSounds == 1) - { - Sound()->PlayAt(Chn, pSet->m_aSounds[0].m_Id, Flags, Pos.x, Pos.y); + Sound()->Play(Chn, SampleId, Flags); +} + +void CSounds::PlayAt(int Chn, int SetId, float Vol, vec2 Pos) +{ + if(Chn == CHN_MUSIC && !g_Config.m_SndMusic) + return; + + int SampleId = GetSampleId(SetId); + if(SampleId == -1) return; - } - // play a random one - int Id; - do - { - Id = rand() % pSet->m_NumSounds; - } - while(Id == pSet->m_Last); - Sound()->PlayAt(Chn, pSet->m_aSounds[Id].m_Id, Flags, Pos.x, Pos.y); - pSet->m_Last = Id; + int Flags = 0; + if(Chn == CHN_MUSIC) + Flags = ISound::FLAG_LOOP; + + Sound()->PlayAt(Chn, SampleId, Flags, Pos.x, Pos.y); } void CSounds::Stop(int SetId) diff --git a/src/game/client/components/sounds.h b/src/game/client/components/sounds.h index ab9cc8e6..9d647398 100644 --- a/src/game/client/components/sounds.h +++ b/src/game/client/components/sounds.h @@ -19,6 +19,8 @@ class CSounds : public CComponent int64 m_QueueWaitTime; class CJob m_SoundJob; bool m_WaitForSoundJob; + + int GetSampleId(int SetId); public: // sound channels @@ -37,7 +39,8 @@ public: void ClearQueue(); void Enqueue(int Channel, int SetId); - void Play(int Channel, int SetId, float Vol, vec2 Pos); + void Play(int Channel, int SetId, float Vol); + void PlayAt(int Channel, int SetId, float Vol, vec2 Pos); void PlayAndRecord(int Channel, int SetId, float Vol, vec2 Pos); void Stop(int SetId); }; diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp index 6bcf21de..6e94c830 100644 --- a/src/game/client/gameclient.cpp +++ b/src/game/client/gameclient.cpp @@ -551,7 +551,7 @@ void CGameClient::OnMessage(int MsgId, CUnpacker *pUnpacker) pMsg->m_SoundID == SOUND_CTF_GRAB_PL) g_GameClient.m_pSounds->Enqueue(CSounds::CHN_GLOBAL, pMsg->m_SoundID); else - g_GameClient.m_pSounds->Play(CSounds::CHN_GLOBAL, pMsg->m_SoundID, 1.0f, vec2(0,0)); + g_GameClient.m_pSounds->Play(CSounds::CHN_GLOBAL, pMsg->m_SoundID, 1.0f); } } @@ -626,7 +626,7 @@ void CGameClient::ProcessEvents() else if(Item.m_Type == NETEVENTTYPE_SOUNDWORLD) { CNetEvent_SoundWorld *ev = (CNetEvent_SoundWorld *)pData; - g_GameClient.m_pSounds->Play(CSounds::CHN_WORLD, ev->m_SoundID, 1.0f, vec2(ev->m_X, ev->m_Y)); + g_GameClient.m_pSounds->PlayAt(CSounds::CHN_WORLD, ev->m_SoundID, 1.0f, vec2(ev->m_X, ev->m_Y)); } } } -- cgit 1.4.1 From 4fde2cf7f2353c045bcf483e7958d785dac3be64 Mon Sep 17 00:00:00 2001 From: oy Date: Mon, 9 Jan 2012 00:49:20 +0100 Subject: add tuning to demo. Closes #899 --- src/engine/server.h | 1 + src/engine/server/server.cpp | 5 +++++ src/engine/server/server.h | 1 + src/game/client/gameclient.cpp | 9 +++++++++ src/game/server/gamecontext.cpp | 11 +++++++++++ 5 files changed, 27 insertions(+) (limited to 'src/game/client/gameclient.cpp') diff --git a/src/engine/server.h b/src/engine/server.h index 2e4a2f25..5036b654 100644 --- a/src/engine/server.h +++ b/src/engine/server.h @@ -65,6 +65,7 @@ public: virtual void Kick(int ClientID, const char *pReason) = 0; virtual void DemoRecorder_HandleAutoStart() = 0; + virtual bool DemoRecorder_IsRecording() = 0; }; class IGameServer : public IInterface diff --git a/src/engine/server/server.cpp b/src/engine/server/server.cpp index 6e63f747..c15cc96e 100644 --- a/src/engine/server/server.cpp +++ b/src/engine/server/server.cpp @@ -1500,6 +1500,11 @@ void CServer::DemoRecorder_HandleAutoStart() } } +bool CServer::DemoRecorder_IsRecording() +{ + return m_DemoRecorder.IsRecording(); +} + void CServer::ConRecord(IConsole::IResult *pResult, void *pUser) { CServer* pServer = (CServer *)pUser; diff --git a/src/engine/server/server.h b/src/engine/server/server.h index e32f6733..696b472d 100644 --- a/src/engine/server/server.h +++ b/src/engine/server/server.h @@ -170,6 +170,7 @@ public: void Kick(int ClientID, const char *pReason); void DemoRecorder_HandleAutoStart(); + bool DemoRecorder_IsRecording(); //int Tick() int64 TickStartTime(int Tick); diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp index 6e94c830..467a55a0 100644 --- a/src/game/client/gameclient.cpp +++ b/src/game/client/gameclient.cpp @@ -893,6 +893,15 @@ void CGameClient::OnNewSnapshot() m_ServerMode = SERVERMODE_PUREMOD; } + // add tuning to demo + if(DemoRecorder()->IsRecording() && mem_comp(&StandardTuning, &m_Tuning, sizeof(CTuningParams)) != 0) + { + CMsgPacker Msg(NETMSGTYPE_SV_TUNEPARAMS); + int *pParams = (int *)&m_Tuning; + for(unsigned i = 0; i < sizeof(m_Tuning)/sizeof(int); i++) + Msg.AddInt(pParams[i]); + Client()->SendMsg(&Msg, MSGFLAG_RECORD|MSGFLAG_NOSEND); + } } void CGameClient::OnPredict() diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index 868ac593..fdd78f60 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -1511,6 +1511,17 @@ void CGameContext::OnShutdown() void CGameContext::OnSnap(int ClientID) { + // add tuning to demo + CTuningParams StandardTuning; + if(ClientID == -1 && Server()->DemoRecorder_IsRecording() && mem_comp(&StandardTuning, &m_Tuning, sizeof(CTuningParams)) != 0) + { + CMsgPacker Msg(NETMSGTYPE_SV_TUNEPARAMS); + int *pParams = (int *)&m_Tuning; + for(unsigned i = 0; i < sizeof(m_Tuning)/sizeof(int); i++) + Msg.AddInt(pParams[i]); + Server()->SendMsg(&Msg, MSGFLAG_RECORD|MSGFLAG_NOSEND, ClientID); + } + m_World.Snap(ClientID); m_pController->Snap(ClientID); m_Events.Snap(ClientID); -- cgit 1.4.1 From d17ee055a250554e05abb0fcade04da85e85647b Mon Sep 17 00:00:00 2001 From: oy Date: Sun, 29 Jan 2012 12:44:33 +0100 Subject: fixed an issue about resending player info --- src/game/client/gameclient.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/game/client/gameclient.cpp') diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp index 467a55a0..86fb5ad0 100644 --- a/src/game/client/gameclient.cpp +++ b/src/game/client/gameclient.cpp @@ -449,7 +449,7 @@ void CGameClient::OnRender() m_NewPredictedTick = false; // check if client info has to be resent - if(m_LastSendInfo && Client()->State() == IClient::STATE_ONLINE && !m_pMenus->IsActive() && m_LastSendInfo+time_freq()*5 < time_get()) + if(m_LastSendInfo && Client()->State() == IClient::STATE_ONLINE && m_Snap.m_LocalClientID >= 0 && !m_pMenus->IsActive() && m_LastSendInfo+time_freq()*5 < time_get()) { // resend if client info differs if(str_comp(g_Config.m_PlayerName, m_aClients[m_Snap.m_LocalClientID].m_aName) || -- cgit 1.4.1