diff --git a/src/client/cl_particles.c b/src/client/cl_particles.c index c2d4ecca..f2966ac6 100644 --- a/src/client/cl_particles.c +++ b/src/client/cl_particles.c @@ -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; diff --git a/src/client/cl_view.c b/src/client/cl_view.c index 2d3b7857..94c2dbc2 100644 --- a/src/client/cl_view.c +++ b/src/client/cl_view.c @@ -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; } } diff --git a/src/client/header/client.h b/src/client/header/client.h index adfbf219..2773cef0 100644 --- a/src/client/header/client.h +++ b/src/client/header/client.h @@ -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); diff --git a/src/client/refresh/files/models.c b/src/client/refresh/files/models.c index e5fe9243..00388de6 100644 --- a/src/client/refresh/files/models.c +++ b/src/client/refresh/files/models.c @@ -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", diff --git a/src/client/refresh/gl1/gl1_main.c b/src/client/refresh/gl1/gl1_main.c index f9576d45..9d84f31d 100644 --- a/src/client/refresh/gl1/gl1_main.c +++ b/src/client/refresh/gl1/gl1_main.c @@ -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); } } diff --git a/src/client/refresh/gl3/gl3_main.c b/src/client/refresh/gl3/gl3_main.c index 4acc34ee..867492cf 100644 --- a/src/client/refresh/gl3/gl3_main.c +++ b/src/client/refresh/gl3/gl3_main.c @@ -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); diff --git a/src/client/refresh/gl4/gl4_main.c b/src/client/refresh/gl4/gl4_main.c index 931ad990..cc8801bd 100644 --- a/src/client/refresh/gl4/gl4_main.c +++ b/src/client/refresh/gl4/gl4_main.c @@ -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; } diff --git a/src/client/refresh/soft/header/local.h b/src/client/refresh/soft/header/local.h index 38764fac..bf004f5d 100644 --- a/src/client/refresh/soft/header/local.h +++ b/src/client/refresh/soft/header/local.h @@ -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 ); diff --git a/src/client/refresh/soft/sw_image.c b/src/client/refresh/soft/sw_image.c index 796ca1f3..db28c63d 100644 --- a/src/client/refresh/soft/sw_image.c +++ b/src/client/refresh/soft/sw_image.c @@ -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) diff --git a/src/client/refresh/soft/sw_part.c b/src/client/refresh/soft/sw_part.c index 3f21ee92..5481f334 100644 --- a/src/client/refresh/soft/sw_part.c +++ b/src/client/refresh/soft/sw_part.c @@ -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; diff --git a/src/client/refresh/vk/vk_main.c b/src/client/refresh/vk/vk_main.c index 930e8609..ce35c45d 100644 --- a/src/client/refresh/vk/vk_main.c +++ b/src/client/refresh/vk/vk_main.c @@ -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); } } diff --git a/src/client/vid/header/ref.h b/src/client/vid/header/ref.h index e6a0ae97..94b0aa99 100644 --- a/src/client/vid/header/ref.h +++ b/src/client/vid/header/ref.h @@ -84,7 +84,7 @@ typedef struct { typedef struct { vec3_t origin; - int color; + unsigned color; float alpha; } particle_t; diff --git a/src/client/vid/image.c b/src/client/vid/image.c index e0712a80..c3447110 100644 --- a/src/client/vid/image.c +++ b/src/client/vid/image.c @@ -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