mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
added mapimages component
This commit is contained in:
parent
04eddacd65
commit
9c704c6a05
45
src/game/client/components/mapimages.cpp
Normal file
45
src/game/client/components/mapimages.cpp
Normal file
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
15
src/game/client/components/mapimages.hpp
Normal file
15
src/game/client/components/mapimages.hpp
Normal file
|
@ -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();
|
||||
};
|
||||
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -115,6 +115,7 @@ public:
|
|||
class EFFECTS *effects;
|
||||
class SOUNDS *sounds;
|
||||
class MOTD *motd;
|
||||
class MAPIMAGES *mapimages;
|
||||
};
|
||||
|
||||
extern GAMECLIENT gameclient;
|
||||
|
|
|
@ -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];
|
||||
}
|
|
@ -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);
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue