blood color depending on skin fixed

This commit is contained in:
Magnus Auvinen 2008-03-17 01:41:11 +00:00
parent 412958bae3
commit 22360b5d79
9 changed files with 59 additions and 22 deletions

View file

@ -296,7 +296,7 @@ void process_events(int snaptype)
else if(item.type == NETEVENTTYPE_DEATH)
{
NETEVENT_DEATH *ev = (NETEVENT_DEATH *)data;
effect_playerdeath(vec2(ev->x, ev->y));
effect_playerdeath(vec2(ev->x, ev->y), ev->cid);
}
else if(item.type == NETEVENTTYPE_SOUND_WORLD)
{

View file

@ -147,7 +147,7 @@ void effect_explosion(vec2 pos);
void effect_air_jump(vec2 pos);
void effect_damage_indicator(vec2 pos, vec2 dir);
void effect_playerspawn(vec2 pos);
void effect_playerdeath(vec2 pos);
void effect_playerdeath(vec2 pos, int cid);
void effect_powerupshine(vec2 pos, vec2 size);
// particles

View file

@ -72,7 +72,7 @@ public:
void handle_event(INPUT_EVENT e)
{
if (!(e.ch >= 0 && e.ch < 32))
if (e.ch >= 32)
{
if (input_len < sizeof(input) - 1)
{

View file

@ -1,5 +1,6 @@
#include <engine/e_client_interface.h>
#include "gc_client.h"
#include "gc_skin.h"
#include "../generated/gc_data.h"
static bool add_50hz = false;
@ -123,8 +124,20 @@ void effect_playerspawn(vec2 pos)
}
}
void effect_playerdeath(vec2 pos)
void effect_playerdeath(vec2 pos, int cid)
{
vec3 blood_color(1.0f,1.0f,1.0f);
if(cid >= 0)
{
const skin *s = skin_get(client_datas[cid].skin_id);
if(s)
{
dbg_msg("", "good blood color!");
blood_color = s->blood_color;
}
}
for(int i = 0; i < 64; i++)
{
particle p;
@ -139,9 +152,9 @@ void effect_playerdeath(vec2 pos)
p.rotspeed = (frandom()-0.5f) * pi;
p.gravity = 800.0f;
p.friction = 0.8f;
p.color = mix(vec4(0.75f,0.2f,0.2f,0.75f), vec4(0.5f,0.1f,0.1f,0.75f), frandom());
vec3 c = blood_color * (0.75f + frandom()*0.25f);
p.color = vec4(c.r, c.g, c.b, 0.75f);
particle_add(PARTGROUP_GENERAL, &p);
}
}

View file

@ -1321,6 +1321,15 @@ static void menu2_render_settings_player(RECT main_view)
ui_hsplit_t(&icon, 5.0f, 0, &icon); // some margin from the top
render_tee(&state, &info, 0, vec2(1, 0), vec2(icon.x+icon.w/2, icon.y+icon.h/2));
if(config.debug)
{
gfx_texture_set(-1);
gfx_quads_begin();
gfx_setcolor(s->blood_color.r, s->blood_color.g, s->blood_color.b, 1.0f);
gfx_quads_drawTL(icon.x, icon.y, 12, 12);
gfx_quads_end();
}
ui_hsplit_t(&list, 50, &button, &list);
}
}

View file

@ -1,6 +1,7 @@
/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <engine/e_system.h>
#include <engine/e_client_interface.h>
#include "gc_skin.h"
@ -33,8 +34,28 @@ static void skinscan(const char *name, int is_dir, void *user)
skins[num_skins].org_texture = gfx_load_texture_raw(info.width, info.height, info.format, info.data, info.format);
// create colorless version
int body_size = 96; // body size
unsigned char *d = (unsigned char *)info.data;
int pitch = info.width*4;
// dig out blood color
{
int colors[3] = {0};
for(int y = 0; y < body_size; y++)
for(int x = 0; x < body_size; x++)
{
if(d[y*pitch+x*4+3] > 128)
{
colors[0] += d[y*pitch+x*4+0];
colors[1] += d[y*pitch+x*4+1];
colors[2] += d[y*pitch+x*4+2];
}
}
skins[num_skins].blood_color = normalize(vec3(colors[0], colors[1], colors[2]));
}
// create colorless version
int step = info.format == IMG_RGBA ? 4 : 3;
for(int i = 0; i < info.width*info.height; i++)
@ -44,20 +65,11 @@ static void skinscan(const char *name, int is_dir, void *user)
d[i*step+1] = v;
d[i*step+2] = v;
}
if(1)
{
int bs = 96; // body size
int pitch = info.width*4;
int freq[256] = {0};
for(int y = 0; y < bs; y++)
for(int x = 0; x < bs; x++)
{
if(d[y*pitch+x*4+3] > 128)
freq[d[y*pitch+x*4]]++;
}
int org_weight = 0;
int new_weight = 192;
for(int i = 1; i < 256; i++)
@ -68,8 +80,8 @@ static void skinscan(const char *name, int is_dir, void *user)
int inv_org_weight = 255-org_weight;
int inv_new_weight = 255-new_weight;
for(int y = 0; y < bs; y++)
for(int x = 0; x < bs; x++)
for(int y = 0; y < body_size; y++)
for(int x = 0; x < body_size; x++)
{
int v = d[y*pitch+x*4];
if(v <= org_weight)

View file

@ -8,6 +8,7 @@ typedef struct
int color_texture;
char name[31];
char term[1];
vec3 blood_color;
} skin;
vec4 skin_get_color(int v);

View file

@ -190,6 +190,7 @@ end
event death
any x, y
clientid cid
end
event air_jump

View file

@ -21,7 +21,7 @@ void create_damageind(vec2 p, float angle_mod, int amount);
void create_explosion(vec2 p, int owner, int weapon, bool bnodamage);
void create_smoke(vec2 p);
void create_playerspawn(vec2 p);
void create_death(vec2 p);
void create_death(vec2 p, int who);
void create_sound(vec2 pos, int sound, int mask=-1);
class player *intersect_player(vec2 pos0, vec2 pos1, vec2 &new_pos, class entity *notthis = 0);
class player *closest_player(vec2 pos, float radius, entity *notthis);
@ -1523,7 +1523,7 @@ void player::die(int killer, int weapon)
dead = true;
die_tick = server_tick();
clear_flag(FLAG_PHYSICS);
create_death(pos);
create_death(pos, client_id);
}
bool player::take_damage(vec2 force, int dmg, int from, int weapon)
@ -1907,7 +1907,7 @@ void create_playerspawn(vec2 p)
}
}
void create_death(vec2 p)
void create_death(vec2 p, int cid)
{
// create the event
NETEVENT_DEATH *ev = (NETEVENT_DEATH *)events.create(NETEVENTTYPE_DEATH, sizeof(NETEVENT_DEATH));
@ -1915,6 +1915,7 @@ void create_death(vec2 p)
{
ev->x = (int)p.x;
ev->y = (int)p.y;
ev->cid = cid;
}
}