diff options
Diffstat (limited to 'src/game')
| -rw-r--r-- | src/game/client/components/chat.cpp | 1 | ||||
| -rw-r--r-- | src/game/client/components/effects.cpp | 2 | ||||
| -rw-r--r-- | src/game/client/components/menus.cpp | 9 | ||||
| -rw-r--r-- | src/game/client/components/menus.h | 6 | ||||
| -rw-r--r-- | src/game/client/components/players.cpp | 1 | ||||
| -rw-r--r-- | src/game/client/components/sounds.cpp | 63 | ||||
| -rw-r--r-- | src/game/client/components/sounds.h | 2 | ||||
| -rw-r--r-- | src/game/client/gameclient.cpp | 75 | ||||
| -rw-r--r-- | src/game/client/gameclient.h | 2 | ||||
| -rw-r--r-- | src/game/variables.h | 2 |
10 files changed, 90 insertions, 73 deletions
diff --git a/src/game/client/components/chat.cpp b/src/game/client/components/chat.cpp index 524f0e75..79b9720e 100644 --- a/src/game/client/components/chat.cpp +++ b/src/game/client/components/chat.cpp @@ -1,6 +1,7 @@ /* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */ /* If you are missing that file, acquire a complete release at teeworlds.com. */ +#include <engine/engine.h> #include <engine/graphics.h> #include <engine/textrender.h> #include <engine/keys.h> diff --git a/src/game/client/components/effects.cpp b/src/game/client/components/effects.cpp index edf39c97..20c9b055 100644 --- a/src/game/client/components/effects.cpp +++ b/src/game/client/components/effects.cpp @@ -1,6 +1,8 @@ /* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */ /* If you are missing that file, acquire a complete release at teeworlds.com. */ #include <engine/demo.h> +#include <engine/engine.h> + #include <engine/shared/config.h> #include <game/generated/client_data.h> diff --git a/src/game/client/components/menus.cpp b/src/game/client/components/menus.cpp index 81a06011..ed49f8b1 100644 --- a/src/game/client/components/menus.cpp +++ b/src/game/client/components/menus.cpp @@ -593,9 +593,10 @@ int CMenus::RenderMenubar(CUIRect r) return 0; } -void CMenus::RenderLoading(float Percent) +void CMenus::RenderLoading() { static int64 LastLoadRender = 0; + float Percent = m_LoadCurrent++/(float)m_LoadTotal; // make sure that we don't render for each little thing we load // because that will slow down loading if we have vsync @@ -704,6 +705,12 @@ void CMenus::OnInit() g_Config.m_ClShowWelcome = 0; Console()->Chain("add_favorite", ConchainServerbrowserUpdate, this); + + // setup load amount + m_LoadCurrent = 0; + m_LoadTotal = g_pData->m_NumImages; + if(!g_Config.m_ClThreadsoundloading) + m_LoadTotal += g_pData->m_NumSounds; } void CMenus::PopupMessage(const char *pTopic, const char *pBody, const char *pButton) diff --git a/src/game/client/components/menus.h b/src/game/client/components/menus.h index 59b3f159..8bdd75ee 100644 --- a/src/game/client/components/menus.h +++ b/src/game/client/components/menus.h @@ -124,6 +124,10 @@ class CMenus : public CComponent vec2 m_MousePos; int64 m_LastInput; + + // loading + int m_LoadCurrent; + int m_LoadTotal; // char m_aMessageTopic[512]; @@ -234,7 +238,7 @@ public: CMenus(); - void RenderLoading(float Percent); + void RenderLoading(); bool IsActive() const { return m_MenuActive; } diff --git a/src/game/client/components/players.cpp b/src/game/client/components/players.cpp index 3094a738..40197e9f 100644 --- a/src/game/client/components/players.cpp +++ b/src/game/client/components/players.cpp @@ -1,6 +1,7 @@ /* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */ /* If you are missing that file, acquire a complete release at teeworlds.com. */ #include <engine/demo.h> +#include <engine/engine.h> #include <engine/graphics.h> #include <engine/shared/config.h> #include <game/generated/protocol.h> diff --git a/src/game/client/components/sounds.cpp b/src/game/client/components/sounds.cpp index f162e5e6..f481b494 100644 --- a/src/game/client/components/sounds.cpp +++ b/src/game/client/components/sounds.cpp @@ -1,12 +1,39 @@ /* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */ /* If you are missing that file, acquire a complete release at teeworlds.com. */ +#include <engine/engine.h> #include <engine/sound.h> #include <engine/shared/config.h> #include <game/generated/client_data.h> #include <game/client/gameclient.h> #include <game/client/components/camera.h> +#include <game/client/components/menus.h> #include "sounds.h" + +struct CUserData +{ + CGameClient *m_pGameClient; + bool m_Render; +} g_UserData; + +static int LoadSoundsThread(void *pUser) +{ + CUserData *pData = static_cast<CUserData *>(pUser); + + for(int s = 0; s < g_pData->m_NumSounds; s++) + { + for(int i = 0; i < g_pData->m_aSounds[s].m_NumSounds; i++) + { + int Id = pData->m_pGameClient->Sound()->LoadWV(g_pData->m_aSounds[s].m_aSounds[i].m_pFilename); + g_pData->m_aSounds[s].m_aSounds[i].m_Id = Id; + } + + if(pData->m_Render) + pData->m_pGameClient->m_pMenus->RenderLoading(); + } + + return 0; +} void CSounds::OnInit() { // setup sound channels @@ -18,6 +45,22 @@ void CSounds::OnInit() Sound()->SetListenerPos(0.0f, 0.0f); ClearQueue(); + + // load sounds + if(g_Config.m_ClThreadsoundloading) + { + g_UserData.m_pGameClient = m_pClient; + g_UserData.m_Render = false; + m_pClient->Engine()->AddJob(&m_SoundJob, LoadSoundsThread, &g_UserData); + m_WaitForSoundJob = true; + } + else + { + g_UserData.m_pGameClient = m_pClient; + g_UserData.m_Render = true; + LoadSoundsThread(&g_UserData); + m_WaitForSoundJob = false; + } } void CSounds::OnReset() @@ -28,6 +71,10 @@ void CSounds::OnReset() void CSounds::OnRender() { + // check for sound initialisation + if(m_WaitForSoundJob && m_SoundJob.Status() == CJob::STATE_DONE) + m_WaitForSoundJob = false; + // set listner pos Sound()->SetListenerPos(m_pClient->m_pCamera->m_Center.x, m_pClient->m_pCamera->m_Center.y); @@ -70,7 +117,7 @@ void CSounds::PlayAndRecord(int Chn, int SetId, float Vol, vec2 Pos) void CSounds::Play(int Chn, int SetId, float Vol, vec2 Pos) { - if(SetId < 0 || SetId >= g_pData->m_NumSounds) + if(m_WaitForSoundJob || SetId < 0 || SetId >= g_pData->m_NumSounds) return; SOUNDSET *pSet = &g_pData->m_aSounds[SetId]; @@ -85,10 +132,12 @@ void CSounds::Play(int Chn, int SetId, float Vol, vec2 Pos) } // 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, 0, Pos.x, Pos.y); - pSet->m_Last = id; + int Id; + do + { + Id = rand() % pSet->m_NumSounds; + } + while(Id == pSet->m_Last); + Sound()->PlayAt(Chn, pSet->m_aSounds[Id].m_Id, 0, Pos.x, Pos.y); + pSet->m_Last = Id; } diff --git a/src/game/client/components/sounds.h b/src/game/client/components/sounds.h index 62fee72a..0e782442 100644 --- a/src/game/client/components/sounds.h +++ b/src/game/client/components/sounds.h @@ -13,6 +13,8 @@ class CSounds : public CComponent int m_aQueue[QUEUE_SIZE]; int m_QueuePos; int64 m_QueueWaitTime; + class CJob m_SoundJob; + bool m_WaitForSoundJob; public: // sound channels diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp index b445803d..0aaf40b4 100644 --- a/src/game/client/gameclient.cpp +++ b/src/game/client/gameclient.cpp @@ -1,11 +1,12 @@ /* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */ /* If you are missing that file, acquire a complete release at teeworlds.com. */ +#include <engine/engine.h> #include <engine/graphics.h> #include <engine/textrender.h> -#include <engine/sound.h> #include <engine/demo.h> #include <engine/map.h> #include <engine/storage.h> +#include <engine/sound.h> #include <engine/serverbrowser.h> #include <engine/shared/demo.h> #include <engine/shared/config.h> @@ -80,33 +81,13 @@ static CMapLayers gs_MapLayersForeGround(CMapLayers::TYPE_FOREGROUND); CGameClient::CStack::CStack() { m_Num = 0; } void CGameClient::CStack::Add(class CComponent *pComponent) { m_paComponents[m_Num++] = pComponent; } -static int gs_LoadCurrent; -static int gs_LoadTotal; - -/*static void load_sounds_thread(void *do_render) -{ - // load sounds - for(int s = 0; s < data->num_sounds; s++) - { - if(do_render) - gameclient.menus->render_loading(load_current/(float)load_total); - for(int i = 0; i < data->sounds[s].num_sounds; i++) - { - int id = Sound()->LoadWV(data->sounds[s].sounds[i].filename); - data->sounds[s].sounds[i].id = id; - } - - if(do_render) - load_current++; - } -}*/ - const char *CGameClient::Version() { return GAME_VERSION; } const char *CGameClient::NetVersion() { return GAME_NETVERSION; } const char *CGameClient::GetItemName(int Type) { return m_NetObjHandler.GetObjName(Type); } void CGameClient::OnConsoleInit() { + m_pEngine = Kernel()->RequestInterface<IEngine>(); m_pClient = Kernel()->RequestInterface<IClient>(); m_pGraphics = Kernel()->RequestInterface<IGraphics>(); m_pTextRender = Kernel()->RequestInterface<ITextRender>(); @@ -227,15 +208,12 @@ void CGameClient::OnInit() // set the language g_Localization.Load(g_Config.m_ClLanguagefile, Storage(), Console()); - - // init all components - for(int i = 0; i < m_All.m_Num; i++) - m_All.m_paComponents[i]->OnInit(); - + + // TODO: this should be different // setup item sizes for(int i = 0; i < NUM_NETOBJTYPES; i++) Client()->SnapSetStaticsize(i, m_NetObjHandler.GetObjSize(i)); - + // load default font static CFont *pDefaultFont = 0; char aFilename[512]; @@ -248,46 +226,17 @@ void CGameClient::OnInit() } if(!pDefaultFont) Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "gameclient", "failed to load font. filename='fonts/DejaVuSans.ttf'"); - - g_Config.m_ClThreadsoundloading = 0; - - // setup load amount - gs_LoadTotal = g_pData->m_NumImages; - gs_LoadCurrent = 0; - if(!g_Config.m_ClThreadsoundloading) - gs_LoadTotal += g_pData->m_NumSounds; - // load textures + // init all components + for(int i = m_All.m_Num-1; i >= 0; --i) + m_All.m_paComponents[i]->OnInit(); + + // setup load amount// load textures for(int i = 0; i < g_pData->m_NumImages; i++) { - g_GameClient.m_pMenus->RenderLoading(gs_LoadCurrent/(float)gs_LoadTotal); g_pData->m_aImages[i].m_Id = Graphics()->LoadTexture(g_pData->m_aImages[i].m_pFilename, IStorage::TYPE_ALL, CImageInfo::FORMAT_AUTO, 0); - gs_LoadCurrent++; - } - - // TODO: Refactor: fix threaded loading of sounds again - // load sounds - { - bool DoRender = true; - for(int s = 0; s < g_pData->m_NumSounds; s++) - { - if(DoRender) - g_GameClient.m_pMenus->RenderLoading(gs_LoadCurrent/(float)gs_LoadTotal); - for(int i = 0; i < g_pData->m_aSounds[s].m_NumSounds; i++) - { - int Id = Sound()->LoadWV(g_pData->m_aSounds[s].m_aSounds[i].m_pFilename); - g_pData->m_aSounds[s].m_aSounds[i].m_Id = Id; - } - - if(DoRender) - gs_LoadCurrent++; - } + g_GameClient.m_pMenus->RenderLoading(); } - - /*if(config.cl_threadsoundloading) - thread_create(load_sounds_thread, 0); - else - load_sounds_thread((void*)1);*/ for(int i = 0; i < m_All.m_Num; i++) m_All.m_paComponents[i]->OnReset(); diff --git a/src/game/client/gameclient.h b/src/game/client/gameclient.h index 35deec7b..e6650d44 100644 --- a/src/game/client/gameclient.h +++ b/src/game/client/gameclient.h @@ -31,6 +31,7 @@ class CGameClient : public IGameClient CStack m_Input; CNetObjHandler m_NetObjHandler; + class IEngine *m_pEngine; class IInput *m_pInput; class IGraphics *m_pGraphics; class ITextRender *m_pTextRender; @@ -62,6 +63,7 @@ class CGameClient : public IGameClient public: IKernel *Kernel() { return IInterface::Kernel(); } + IEngine *Engine() const { return m_pEngine; } class IGraphics *Graphics() const { return m_pGraphics; } class IClient *Client() const { return m_pClient; } class CUI *UI() { return &m_UI; } diff --git a/src/game/variables.h b/src/game/variables.h index 0621f6af..de4699a0 100644 --- a/src/game/variables.h +++ b/src/game/variables.h @@ -15,7 +15,7 @@ MACRO_CONFIG_INT(ClAutoswitchWeapons, cl_autoswitch_weapons, 0, 0, 1, CFGFLAG_CL MACRO_CONFIG_INT(ClShowfps, cl_showfps, 0, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Show ingame FPS counter") MACRO_CONFIG_INT(ClAirjumpindicator, cl_airjumpindicator, 1, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "") -MACRO_CONFIG_INT(ClThreadsoundloading, cl_threadsoundloading, 0, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "") +MACRO_CONFIG_INT(ClThreadsoundloading, cl_threadsoundloading, 0, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Load sound files threaded") MACRO_CONFIG_INT(ClWarningTeambalance, cl_warning_teambalance, 1, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Warn about team balance") |