client: use rgb color in particle_t

This commit is contained in:
Denis Pauk 2024-06-23 13:18:13 +03:00
parent bcda8cccaf
commit 3121849500
13 changed files with 68 additions and 22 deletions

View file

@ -35,7 +35,7 @@ CL_ClearParticles(void)
{
if (cl_numparticles == 0)
return;
int i;
free_particles = &particles[0];
@ -175,7 +175,6 @@ CL_AddParticles(void)
float alpha;
float time, time2;
vec3_t org;
int color;
cparticle_t *active, *tail;
active = NULL;
@ -183,6 +182,8 @@ CL_AddParticles(void)
for (p = active_particles; p; p = next)
{
unsigned color;
next = p->next;
if (p->alphavel != INSTANT_PARTICLE)
@ -222,7 +223,7 @@ CL_AddParticles(void)
alpha = 1;
}
color = p->color;
color = VID_PaletteColor(p->color);
time2 = time * time;
org[0] = p->org[0] + p->vel[0] * time + p->accel[0] * time2;

View file

@ -159,7 +159,8 @@ V_TestParticles(void)
cl.v_right[j] * r + cl.v_up[j] * u;
}
p->color = 8;
/* grey */
p->color = 0xFF7B7B7B;
p->alpha = cl_testparticles->value;
}
}

View file

@ -513,6 +513,7 @@ void VID_ImageDecode(const char *filename, byte **pic, byte **palette,
int *width, int *height, int *bytesPerPixel);
void VID_GetPalette(byte **colormap, unsigned *d_8to24table);
void VID_GetPalette24to8(const byte *d_8to24table, byte** d_16to8table);
unsigned VID_PaletteColor(byte color);
void CL_RegisterTEntSounds (void);
void CL_RegisterTEntModels (void);

View file

@ -2670,7 +2670,7 @@ Mod_LoadModel_SDEF_Text(const char *mod_name, char *curr_buff, readfile_t read_f
}
}
base_size = read_file(base_model, &base);
base_size = read_file(base_model, (void **)&base);
if (base_size <= 0)
{
R_Printf(PRINT_DEVELOPER, "%s: %s No base model for %s\n",
@ -2709,7 +2709,7 @@ Mod_LoadModel_SDEF_Text(const char *mod_name, char *curr_buff, readfile_t read_f
{
int anim_size, j;
anim_size = read_file(animations[i], &anim[animation_num]);
anim_size = read_file(animations[i], (void **)&anim[animation_num]);
if (anim_size <= 0)
{
R_Printf(PRINT_DEVELOPER, "%s: %s empty animation %s\n",

View file

@ -418,8 +418,7 @@ R_DrawEntitiesOnList(void)
}
static void
R_DrawParticles2(int num_particles, const particle_t particles[],
const unsigned *colortable)
R_DrawParticles2(int num_particles, const particle_t particles[])
{
const particle_t *p;
int i;
@ -461,7 +460,7 @@ R_DrawParticles2(int num_particles, const particle_t particles[],
scale = 1 + scale * 0.004;
}
*(unsigned *) color = colortable [ p->color ];
*(unsigned *) color = p->color;
for (j=0; j<3; j++) // Copy the color for each point
{
@ -551,7 +550,7 @@ R_DrawParticles(void)
for ( i = 0, p = r_newrefdef.particles; i < r_newrefdef.num_particles; i++, p++ )
{
*(int *) color = d_8to24table [ p->color & 0xFF ];
*(int *) color = p->color;
clr[index_clr++] = color[0]/255.0f;
clr[index_clr++] = color[1]/255.0f;
clr[index_clr++] = color[2]/255.0f;
@ -583,7 +582,7 @@ R_DrawParticles(void)
else
{
R_DrawParticles2(r_newrefdef.num_particles,
r_newrefdef.particles, d_8to24table);
r_newrefdef.particles);
}
}

View file

@ -1034,7 +1034,7 @@ GL3_DrawParticles(void)
for ( i = 0, p = gl3_newrefdef.particles; i < numParticles; i++, p++ )
{
*(int *) color = d_8to24table [ p->color & 0xFF ];
*(int *) color = p->color;
part_vtx* cur = &buf[i];
vec3_t offset; // between viewOrg and particle position
VectorSubtract(viewOrg, p->origin, offset);

View file

@ -1009,7 +1009,7 @@ GL4_DrawParticles(void)
for ( i = 0, p = gl4_newrefdef.particles; i < numParticles; i++, p++ )
{
*(int *) color = d_8to24table [ p->color & 0xFF ];
*(int *) color = p->color;
part_vtx* cur = &buf[i];
vec3_t offset; // between viewOrg and particle position
VectorSubtract(viewOrg, p->origin, offset);
@ -1018,7 +1018,10 @@ GL4_DrawParticles(void)
cur->size = pointSize;
cur->dist = VectorLength(offset);
for(int j=0; j<3; ++j) cur->color[j] = color[j]*(1.0f/255.0f);
for(int j=0; j<3; ++j)
{
cur->color[j] = color[j]*(1.0f / 255.0f);
}
cur->color[3] = p->alpha;
}

View file

@ -567,9 +567,10 @@ image_t *R_LoadPic(const char *name, const byte *pic, int width, int realwidth,
size_t data_size, imagetype_t type, int bits);
byte *Get_BestImageSize(const image_t *image, int *req_width, int *req_height);
void R_FreeUnusedImages(void);
qboolean R_ImageHasFreeSpace(void);
qboolean R_ImageHasFreeSpace(void);
pixel_t R_ApplyLight(pixel_t pix, const light3_t light);
void R_Convert32To8bit(const unsigned char* pic_in, pixel_t* pic_out, size_t size, qboolean transparent);
int R_ConvertRGBColor(unsigned color);
void R_InitSkyBox(model_t *loadmodel);
void R_IMFlatShadedQuad( const vec3_t a, const vec3_t b, const vec3_t c, const vec3_t d, int color, float alpha );

View file

@ -217,6 +217,22 @@ Get_BestImageSize(const image_t *image, int *req_width, int *req_height)
static byte *d_16to8table = NULL; // 16 to 8 bit conversion table
int
R_ConvertRGBColor(unsigned color)
{
YQ2_ALIGNAS_TYPE(unsigned) byte rgbcolor[4];
unsigned int r, g, b, c;
*(int *)rgbcolor = color;
r = ( rgbcolor[0] >> 3 ) & 31;
g = ( rgbcolor[1] >> 2 ) & 63;
b = ( rgbcolor[2] >> 3 ) & 31;
c = r | ( g << 5 ) | ( b << 11 );
return d_16to8table[c & 0xFFFF];
}
void
R_Convert32To8bit(const unsigned char* pic_in, pixel_t* pic_out, size_t size,
qboolean transparent)

View file

@ -48,7 +48,7 @@ R_DrawParticle(particle_t *pparticle, int level)
float zi;
byte *pdest;
zvalue_t *pz;
int color = pparticle->color;
int color = R_ConvertRGBColor(pparticle->color);
int i, pix, count, u, v;
zvalue_t izi;
int custom_particle = (int)sw_custom_particles->value;

View file

@ -409,7 +409,7 @@ R_DrawEntitiesOnList(void)
}
static void
Vk_DrawParticles(int num_particles, const particle_t particles[], const unsigned *colortable)
Vk_DrawParticles(int num_particles, const particle_t particles[])
{
typedef struct {
float x,y,z,r,g,b,a,u,v;
@ -418,11 +418,12 @@ Vk_DrawParticles(int num_particles, const particle_t particles[], const unsigned
const particle_t *p;
int i;
vec3_t up, right;
YQ2_ALIGNAS_TYPE(unsigned) byte color[4];
pvertex* currentvertex;
if (!num_particles)
{
return;
}
VectorScale(vup, 1.5, up);
VectorScale(vright, 1.5, right);
@ -437,6 +438,7 @@ Vk_DrawParticles(int num_particles, const particle_t particles[], const unsigned
currentvertex = visibleParticles;
for (p = particles, i = 0; i < num_particles; i++, p++)
{
YQ2_ALIGNAS_TYPE(unsigned) byte color[4];
float scale;
// hack a scale up to keep particles from disapearing
@ -453,7 +455,7 @@ Vk_DrawParticles(int num_particles, const particle_t particles[], const unsigned
scale = 1 + scale * 0.004;
}
*(int *)color = colortable[p->color];
*(int *)color = p->color;
float r = color[0] / 255.f;
float g = color[1] / 255.f;
@ -562,7 +564,7 @@ R_DrawParticles(void)
for (i = 0, p = r_newrefdef.particles; i < r_newrefdef.num_particles; i++, p++)
{
*(int *)color = d_8to24table[p->color];
*(int *)color = p->color;
float r = color[0] / 255.f;
float g = color[1] / 255.f;
@ -593,7 +595,7 @@ R_DrawParticles(void)
}
else
{
Vk_DrawParticles(r_newrefdef.num_particles, r_newrefdef.particles, d_8to24table);
Vk_DrawParticles(r_newrefdef.num_particles, r_newrefdef.particles);
}
}

View file

@ -84,7 +84,7 @@ typedef struct {
typedef struct {
vec3_t origin;
int color;
unsigned color;
float alpha;
} particle_t;

View file

@ -492,10 +492,32 @@ VID_GetPalette(byte **colormap, unsigned *d_8to24table)
memcpy(d_8to24table, d_8to24table_cache, sizeof(d_8to24table_cache));
}
/*
* Get rgb color from palette
*/
unsigned
VID_PaletteColor(byte color)
{
if (!colormap_cache)
{
LoadPalette(&colormap_cache, d_8to24table_cache);
}
return d_8to24table_cache[color & 0xFF];
}
void
VID_ImageInit(void)
{
int i;
colormap_cache = NULL;
for (i = 0; i < 256; i++)
{
/* fake grey colors */
d_8to24table_cache[i] = (255U<<24) + (i << 16) + (i << 8) + (i << 0);
}
}
void