about summary refs log tree commit diff
path: root/src/game
diff options
context:
space:
mode:
authorMagnus Auvinen <magnus.auvinen@gmail.com>2008-09-01 05:54:00 +0000
committerMagnus Auvinen <magnus.auvinen@gmail.com>2008-09-01 05:54:00 +0000
commit9c704c6a0510e9c5f8af8e9c1f810e9688345111 (patch)
treedc8e7598702963ca4d4ff260824c031ed4e66ce3 /src/game
parent04eddacd65fd3da680e3d896368cb766b377e6e2 (diff)
downloadzcatch-9c704c6a0510e9c5f8af8e9c1f810e9688345111.tar.gz
zcatch-9c704c6a0510e9c5f8af8e9c1f810e9688345111.zip
added mapimages component
Diffstat (limited to 'src/game')
-rw-r--r--src/game/client/components/mapimages.cpp45
-rw-r--r--src/game/client/components/mapimages.hpp15
-rw-r--r--src/game/client/components/maplayers.cpp11
-rw-r--r--src/game/client/components/menus.cpp2
-rw-r--r--src/game/client/gameclient.cpp7
-rw-r--r--src/game/client/gameclient.hpp1
-rw-r--r--src/game/client/gc_map_image.cpp136
-rw-r--r--src/game/client/gc_map_image.hpp10
-rw-r--r--src/game/client/gc_render.hpp2
9 files changed, 68 insertions, 161 deletions
diff --git a/src/game/client/components/mapimages.cpp b/src/game/client/components/mapimages.cpp
new file mode 100644
index 00000000..d13524cd
--- /dev/null
+++ b/src/game/client/components/mapimages.cpp
@@ -0,0 +1,45 @@
+#include <game/client/component.hpp>
+#include <game/mapitems.hpp>
+
+#include "mapimages.hpp"
+
+MAPIMAGES::MAPIMAGES()
+{
+	count = 0;
+}
+
+void MAPIMAGES::on_reset()
+{
+	// unload all textures
+	for(int i = 0; i < count; i++)
+	{
+		gfx_unload_texture(textures[i]);
+		textures[i] = -1;
+	}
+	count = 0;
+
+	int start;
+	map_get_type(MAPITEMTYPE_IMAGE, &start, &count);
+	
+	// load new textures
+	for(int i = 0; i < count; i++)
+	{
+		textures[i] = 0;
+		
+		MAPITEM_IMAGE *img = (MAPITEM_IMAGE *)map_get_item(start+i, 0, 0);
+		if(img->external)
+		{
+			char buf[256];
+			char *name = (char *)map_get_data(img->image_name);
+			str_format(buf, sizeof(buf), "data/mapres/%s.png", name);
+			textures[i] = gfx_load_texture(buf, IMG_AUTO, 0);
+		}
+		else
+		{
+			void *data = map_get_data(img->image_data);
+			textures[i] = gfx_load_texture_raw(img->width, img->height, IMG_RGBA, data, IMG_RGBA, 0);
+			map_unload_data(img->image_data);
+		}
+	}
+}
+
diff --git a/src/game/client/components/mapimages.hpp b/src/game/client/components/mapimages.hpp
new file mode 100644
index 00000000..e1e0063d
--- /dev/null
+++ b/src/game/client/components/mapimages.hpp
@@ -0,0 +1,15 @@
+#include <game/client/component.hpp>
+
+class MAPIMAGES : public COMPONENT
+{	
+	int textures[64];
+	int count;
+public:
+	MAPIMAGES();
+	
+	int get(int index) const { return textures[index]; }
+	int num() const { return count; }
+	
+	virtual void on_reset();
+};
+
diff --git a/src/game/client/components/maplayers.cpp b/src/game/client/components/maplayers.cpp
index 1c72a200..e1518036 100644
--- a/src/game/client/components/maplayers.cpp
+++ b/src/game/client/components/maplayers.cpp
@@ -1,15 +1,10 @@
-
-extern "C" {
-	#include <engine/e_config.h>
-}
-
 #include <game/layers.hpp>
 #include <game/client/gameclient.hpp>
 #include <game/client/component.hpp>
 #include <game/client/gc_render.hpp>
-#include <game/client/gc_map_image.hpp>
 
 #include <game/client/components/camera.hpp>
+#include <game/client/components/mapimages.hpp>
 
 #include "maplayers.hpp"
 
@@ -125,7 +120,7 @@ void MAPLAYERS::on_render()
 					if(tmap->image == -1)
 						gfx_texture_set(-1);
 					else
-						gfx_texture_set(img_get(tmap->image));
+						gfx_texture_set(gameclient.mapimages->get(tmap->image));
 						
 					TILE *tiles = (TILE *)map_get_data(tmap->data);
 					gfx_blend_none();
@@ -139,7 +134,7 @@ void MAPLAYERS::on_render()
 					if(qlayer->image == -1)
 						gfx_texture_set(-1);
 					else
-						gfx_texture_set(img_get(qlayer->image));
+						gfx_texture_set(gameclient.mapimages->get(qlayer->image));
 
 					QUAD *quads = (QUAD *)map_get_data_swapped(qlayer->data);
 					
diff --git a/src/game/client/components/menus.cpp b/src/game/client/components/menus.cpp
index 6d0cbf38..70fdc767 100644
--- a/src/game/client/components/menus.cpp
+++ b/src/game/client/components/menus.cpp
@@ -530,8 +530,6 @@ int MENUS::render_menubar(RECT r)
 			if (ui_do_button(&favorites_button, "Favorites", active_page==PAGE_FAVORITES, &button, ui_draw_menu_tab_button, 0))
 				new_page  = PAGE_FAVORITES;
 		}
-
-
 	}
 	else
 	{
diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp
index 977b7863..6403873a 100644
--- a/src/game/client/gameclient.cpp
+++ b/src/game/client/gameclient.cpp
@@ -5,11 +5,9 @@
 
 #include <game/layers.hpp>
 #include "gc_render.hpp"
-#include "gc_map_image.hpp"
 
 #include "gameclient.hpp"
 
-
 #include "components/binds.hpp"
 #include "components/broadcast.hpp"
 #include "components/camera.hpp"
@@ -24,6 +22,7 @@
 #include "components/hud.hpp"
 #include "components/items.hpp"
 #include "components/killmessages.hpp"
+#include "components/mapimages.hpp"
 #include "components/maplayers.hpp"
 #include "components/menus.hpp"
 #include "components/motd.hpp"
@@ -58,6 +57,7 @@ static DAMAGEIND damageind;
 
 static PLAYERS players;
 static ITEMS items;
+static MAPIMAGES mapimages;
 
 static MAPLAYERS maplayers_background(MAPLAYERS::TYPE_BACKGROUND);
 static MAPLAYERS maplayers_foreground(MAPLAYERS::TYPE_FOREGROUND);
@@ -102,9 +102,11 @@ void GAMECLIENT::on_init()
 	sounds = &::sounds;
 	motd = &::motd;
 	damageind = &::damageind;
+	mapimages = &::mapimages;
 	
 	// make a list of all the systems, make sure to add them in the corrent render order
 	all.add(skins);
+	all.add(mapimages);
 	all.add(effects); // doesn't render anything, just updates effects
 	all.add(particles);
 	all.add(binds);
@@ -233,7 +235,6 @@ void GAMECLIENT::on_connected()
 {
 	layers_init();
 	col_init();
-	img_init();
 	render_tilemap_generate_skip();
 		
 	on_reset();	
diff --git a/src/game/client/gameclient.hpp b/src/game/client/gameclient.hpp
index 5aa37afc..8e3284bf 100644
--- a/src/game/client/gameclient.hpp
+++ b/src/game/client/gameclient.hpp
@@ -115,6 +115,7 @@ public:
 	class EFFECTS *effects;
 	class SOUNDS *sounds;
 	class MOTD *motd;
+	class MAPIMAGES *mapimages;
 };
 
 extern GAMECLIENT gameclient;
diff --git a/src/game/client/gc_map_image.cpp b/src/game/client/gc_map_image.cpp
deleted file mode 100644
index ca16674a..00000000
--- a/src/game/client/gc_map_image.cpp
+++ /dev/null
@@ -1,136 +0,0 @@
-/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */
-#include <base/system.h>
-
-#include <stdio.h>
-#include <engine/e_client_interface.h>
-#include <game/mapitems.hpp>
-#include "gc_map_image.hpp"
-
-static int map_textures[64] = {0};
-static int count = 0;
-/*
-static void calc_mipmaps(void *data_in, unsigned width, unsigned height, void *data_out)
-{
-	unsigned char *src = (unsigned char*)data_in;
-	unsigned char *dst = (unsigned char*)data_out;
-	unsigned mip_w = width;
-	unsigned mip_h = height;
-	unsigned prev_w;
-	unsigned prev_h;
-
-	// Highest level - no mod
-	for(unsigned x = 0; x < mip_w; x++)
-	{
-		for(unsigned y = 0; y < mip_h; y++)
-		{
-			unsigned i = (y * mip_w + x)<<2;
-			for(unsigned j = 0; j < 4; j++)
-				dst[i+j] = src[i+j];
-		}
-	}
-
-	src = dst;
-	dst += mip_w * mip_h * 4;
-	prev_w = mip_w;
-	prev_h = mip_h;
-	mip_w = mip_w>>1;
-	mip_h = mip_h>>1;
-
-	while(mip_w > 0 && mip_h > 0)
-	{
-		for(unsigned x = 0; x < mip_w; x++)
-		{
-			for(unsigned y = 0; y < mip_h; y++)
-			{
-				unsigned i = (y * mip_w + x)<<2;
-
-				unsigned r = 0;
-				unsigned g = 0;
-				unsigned b = 0;
-				unsigned a = 0;
-
-
-				r += src[(((y<<1) * prev_w + (x<<1))<<2)];
-				g += src[(((y<<1) * prev_w + (x<<1))<<2)+1];
-				b += src[(((y<<1) * prev_w + (x<<1))<<2)+2];
-				a += src[(((y<<1) * prev_w + (x<<1))<<2)+3];
-
-				r += src[(((y<<1) * prev_w + ((x+1)<<1))<<2)];
-				g += src[(((y<<1) * prev_w + ((x+1)<<1))<<2)+1];
-				b += src[(((y<<1) * prev_w + ((x+1)<<1))<<2)+2];
-				a += src[(((y<<1) * prev_w + ((x+1)<<1))<<2)+3];
-
-				r += src[((((y+1)<<1) * prev_w + (x<<1))<<2)];
-				g += src[((((y+1)<<1) * prev_w + (x<<1))<<2)+1];
-				b += src[((((y+1)<<1) * prev_w + (x<<1))<<2)+2];
-				a += src[((((y+1)<<1) * prev_w + (x<<1))<<2)+3];
-
-				r += src[((((y+1)<<1) * prev_w + ((x+1)<<1))<<2)];
-				g += src[((((y+1)<<1) * prev_w + ((x+1)<<1))<<2)+1];
-				b += src[((((y+1)<<1) * prev_w + ((x+1)<<1))<<2)+2];
-				a += src[((((y+1)<<1) * prev_w + ((x+1)<<1))<<2)+3];
-
-				dst[i]   = r>>2;
-				dst[i+1] = g>>2;
-				dst[i+2] = b>>2;
-				dst[i+3] = a>>2;
-			}
-		}
-
-		src = dst;
-		dst = dst + mip_w*mip_h*4;
-		prev_w = mip_w;
-		prev_h = mip_h;
-		mip_w = mip_w>>1;
-		mip_h = mip_h>>1;
-	}
-}
-extern int DEBUGTEST_MAPIMAGE;
-*/
-
-
-int img_init()
-{
-	int start, count;
-	map_get_type(MAPITEMTYPE_IMAGE, &start, &count);
-	dbg_msg("image", "start=%d count=%d", start, count);
-	for(int i = 0; i < 64; i++)
-	{
-		if(map_textures[i])
-		{
-			gfx_unload_texture(map_textures[i]);
-			map_textures[i] = -1;
-		}
-	}
-
-	//void *data_res = (void*)mem_alloc(1024*1024*4*2, 16);
-	for(int i = 0; i < count; i++)
-	{
-		MAPITEM_IMAGE *img = (MAPITEM_IMAGE *)map_get_item(start+i, 0, 0);
-		if(img->external)
-		{
-			char buf[256];
-			char *name = (char *)map_get_data(img->image_name);
-			str_format(buf, sizeof(buf), "data/mapres/%s.png", name);
-			map_textures[i] = gfx_load_texture(buf, IMG_AUTO, 0);
-		}
-		else
-		{
-			void *data = map_get_data(img->image_data);
-			map_textures[i] = gfx_load_texture_raw(img->width, img->height, IMG_RGBA, data, IMG_RGBA, 0);
-			map_unload_data(img->image_data);
-		}
-	}
-
-	return count;
-}
-
-int img_num()
-{
-	return count;
-}
-
-int img_get(int index)
-{
-	return map_textures[index];
-}
diff --git a/src/game/client/gc_map_image.hpp b/src/game/client/gc_map_image.hpp
deleted file mode 100644
index d73f43d3..00000000
--- a/src/game/client/gc_map_image.hpp
+++ /dev/null
@@ -1,10 +0,0 @@
-/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */
-
-// loads images from the map to textures
-int img_init();
-
-// returns the number of images in the map
-int img_num();
-
-// fetches the texture id for the image
-int img_get(int index);
diff --git a/src/game/client/gc_render.hpp b/src/game/client/gc_render.hpp
index 280f0532..917641c8 100644
--- a/src/game/client/gc_render.hpp
+++ b/src/game/client/gc_render.hpp
@@ -50,8 +50,6 @@ void draw_round_rect_ext(float x, float y, float w, float h, float r, int corner
 void ui_draw_rect(const RECT *r, vec4 color, int corners, float rounding);
 
 // larger rendering methods
-void render_loading(float percent);
-
 void render_tilemap_generate_skip();
 
 // object render methods (gc_render_obj.cpp)