about summary refs log tree commit diff
path: root/src/game/client/components
diff options
context:
space:
mode:
authoroy <Tom_Adams@web.de>2011-02-27 17:56:03 +0100
committeroy <Tom_Adams@web.de>2011-02-27 17:56:03 +0100
commit0bc13c91ebcc6404fc67e079e5a9acad10176c98 (patch)
treec3b1e1cd155fc62fba0555a8d3549cccc6986db4 /src/game/client/components
parentd9ce7203871cea0046144bce175df5bf1d7fcc19 (diff)
downloadzcatch-0bc13c91ebcc6404fc67e079e5a9acad10176c98.tar.gz
zcatch-0bc13c91ebcc6404fc67e079e5a9acad10176c98.zip
made cl_threadsoundloading work again
Diffstat (limited to 'src/game/client/components')
-rw-r--r--src/game/client/components/chat.cpp1
-rw-r--r--src/game/client/components/effects.cpp2
-rw-r--r--src/game/client/components/menus.cpp9
-rw-r--r--src/game/client/components/menus.h6
-rw-r--r--src/game/client/components/players.cpp1
-rw-r--r--src/game/client/components/sounds.cpp63
-rw-r--r--src/game/client/components/sounds.h2
7 files changed, 75 insertions, 9 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