about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDominik Geyer <dominik.geyer@gmx.de>2008-09-04 18:54:37 +0000
committerDominik Geyer <dominik.geyer@gmx.de>2008-09-04 18:54:37 +0000
commita9211ffd64291fd22d3bfd6ba796eb2ebe041b6e (patch)
tree909b6a679f41603081ad016b2db895ba7b489352
parent4c2632b7b6ae03e9d54d4a2d72742b6865700143 (diff)
downloadzcatch-a9211ffd64291fd22d3bfd6ba796eb2ebe041b6e.tar.gz
zcatch-a9211ffd64291fd22d3bfd6ba796eb2ebe041b6e.zip
moved nameplate-code to new component nameplates; ticket #461
-rw-r--r--src/game/client/components/nameplates.cpp66
-rw-r--r--src/game/client/components/nameplates.hpp14
-rw-r--r--src/game/client/components/players.cpp23
-rw-r--r--src/game/client/gameclient.cpp3
4 files changed, 83 insertions, 23 deletions
diff --git a/src/game/client/components/nameplates.cpp b/src/game/client/components/nameplates.cpp
new file mode 100644
index 00000000..82a15487
--- /dev/null
+++ b/src/game/client/components/nameplates.cpp
@@ -0,0 +1,66 @@
+#include <engine/e_client_interface.h>
+#include <game/generated/g_protocol.hpp>
+#include <game/generated/gc_data.hpp>
+
+#include <game/client/gameclient.hpp>
+#include <game/client/animstate.hpp>
+#include "nameplates.hpp"
+
+void NAMEPLATES::render_nameplate(
+	const NETOBJ_CHARACTER *prev_char,
+	const NETOBJ_CHARACTER *player_char,
+	const NETOBJ_PLAYER_INFO *player_info
+	)
+{
+	float intratick = client_intratick();
+	
+	vec2 position = mix(vec2(prev_char->x, prev_char->y), vec2(player_char->x, player_char->y), intratick);
+	
+	// render name plate
+	if(!player_info->local)
+	{
+		//gfx_text_color
+		float a = 1;
+		if(config.cl_nameplates_always == 0)
+			a = clamp(1-powf(distance(gameclient.local_target_pos, position)/200.0f,16.0f), 0.0f, 1.0f);
+			
+		const char *name = gameclient.clients[player_info->cid].name;
+		float tw = gfx_text_width(0, 28.0f, name, -1);
+		gfx_text_color(1,1,1,a);
+		gfx_text(0, position.x-tw/2.0f, position.y-60, 28.0f, name, -1);
+		
+		if(config.debug) // render client id when in debug aswell
+		{
+			char buf[128];
+			str_format(buf, sizeof(buf),"%d", player_info->cid);
+			gfx_text(0, position.x, position.y-90, 28.0f, buf, -1);
+		}
+
+		gfx_text_color(1,1,1,1);
+	}
+}
+
+void NAMEPLATES::on_render()
+{
+	if (!config.cl_nameplates)
+		return;
+	
+	int num = snap_num_items(SNAP_CURRENT);
+	for(int i = 0; i < num; i++)
+	{
+		SNAP_ITEM item;
+		const void *data = snap_get_item(SNAP_CURRENT, i, &item);
+
+		if(item.type == NETOBJTYPE_CHARACTER)
+		{
+			const void *prev = snap_find_item(SNAP_PREV, item.type, item.id);
+			const void *info = snap_find_item(SNAP_CURRENT, NETOBJTYPE_PLAYER_INFO, item.id);
+
+			if(prev && info)
+				render_nameplate(
+					(const NETOBJ_CHARACTER *)prev,
+					(const NETOBJ_CHARACTER *)data,
+					(const NETOBJ_PLAYER_INFO *)info);
+		}
+	}
+}
diff --git a/src/game/client/components/nameplates.hpp b/src/game/client/components/nameplates.hpp
new file mode 100644
index 00000000..2695f5ac
--- /dev/null
+++ b/src/game/client/components/nameplates.hpp
@@ -0,0 +1,14 @@
+#include <game/client/component.hpp>
+
+class NAMEPLATES : public COMPONENT
+{
+	void render_nameplate(
+		const class NETOBJ_CHARACTER *prev_char,
+		const class NETOBJ_CHARACTER *player_char,
+		const class NETOBJ_PLAYER_INFO *player_info
+	);
+
+public:
+	virtual void on_render();
+};
+
diff --git a/src/game/client/components/players.cpp b/src/game/client/components/players.cpp
index 68cf032b..4e315f32 100644
--- a/src/game/client/components/players.cpp
+++ b/src/game/client/components/players.cpp
@@ -421,29 +421,6 @@ void PLAYERS::render_player(
 		gfx_quads_draw(position.x, position.y - 23 - 32*h, 64, 64*h);
 		gfx_quads_end();
 	}
-	
-	// render name plate
-	if(!info.local && config.cl_nameplates)
-	{
-		//gfx_text_color
-		float a = 1;
-		if(config.cl_nameplates_always == 0)
-			a = clamp(1-powf(distance(gameclient.local_target_pos, position)/200.0f,16.0f), 0.0f, 1.0f);
-			
-		const char *name = gameclient.clients[info.cid].name;
-		float tw = gfx_text_width(0, 28.0f, name, -1);
-		gfx_text_color(1,1,1,a);
-		gfx_text(0, position.x-tw/2.0f, position.y-60, 28.0f, name, -1);
-		
-		if(config.debug) // render client id when in debug aswell
-		{
-			char buf[128];
-			str_format(buf, sizeof(buf),"%d", info.cid);
-			gfx_text(0, position.x, position.y-90, 28.0f, buf, -1);
-		}
-
-		gfx_text_color(1,1,1,1);
-	}
 }
 
 void PLAYERS::on_render()
diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp
index 5efc9413..44d297b5 100644
--- a/src/game/client/gameclient.cpp
+++ b/src/game/client/gameclient.cpp
@@ -28,6 +28,7 @@
 #include "components/motd.hpp"
 #include "components/particles.hpp"
 #include "components/players.hpp"
+#include "components/nameplates.hpp"
 #include "components/scoreboard.hpp"
 #include "components/skins.hpp"
 #include "components/sounds.hpp"
@@ -56,6 +57,7 @@ static EMOTICON emoticon;
 static DAMAGEIND damageind;
 
 static PLAYERS players;
+static NAMEPLATES nameplates;
 static ITEMS items;
 static MAPIMAGES mapimages;
 
@@ -121,6 +123,7 @@ void GAMECLIENT::on_init()
 	all.add(&items);
 	all.add(&players);
 	all.add(&maplayers_foreground);
+	all.add(&nameplates);
 	all.add(&particles->render_general);
 	all.add(damageind);
 	all.add(&hud);