Skip to content

Commit

Permalink
Merge pull request #285 from 0lvin/particles_size
Browse files Browse the repository at this point in the history
Fixes scale particles in soft render
  • Loading branch information
Yamagi committed Apr 17, 2018
2 parents c97204e + 189a34e commit d4b6e93
Show file tree
Hide file tree
Showing 11 changed files with 217 additions and 237 deletions.
9 changes: 8 additions & 1 deletion src/client/refresh/files/wal.c
Expand Up @@ -34,14 +34,21 @@ void
GetWalInfo(char *name, int *width, int *height)
{
miptex_t *mt;
int size;

ri.FS_LoadFile(name, (void **)&mt);
size = ri.FS_LoadFile(name, (void **)&mt);

if (!mt)
{
return;
}

if (size < sizeof(miptex_t))
{
ri.FS_FreeFile((void *)mt);
return;
}

*width = LittleLong(mt->width);
*height = LittleLong(mt->height);

Expand Down
29 changes: 22 additions & 7 deletions src/client/refresh/gl1/gl1_image.c
Expand Up @@ -1013,10 +1013,10 @@ R_LoadPic(char *name, byte *pic, int width, int realwidth,
}

static image_t *
LoadWal(char *origname)
LoadWal(char *origname, imagetype_t type)
{
miptex_t *mt;
int width, height, ofs;
int width, height, ofs, size;
image_t *image;
char name[256];

Expand All @@ -1028,19 +1028,34 @@ LoadWal(char *origname)
Q_strlcat(name, ".wal", sizeof(name));
}

ri.FS_LoadFile(name, (void **)&mt);
size = ri.FS_LoadFile(name, (void **)&mt);

if (!mt)
{
R_Printf(PRINT_ALL, "LoadWal: can't load %s\n", name);
return r_notexture;
}

if (size < sizeof(miptex_t))
{
R_Printf(PRINT_ALL, "LoadWal: can't load %s, small header\n", name);
ri.FS_FreeFile((void *)mt);
return r_notexture;
}

width = LittleLong(mt->width);
height = LittleLong(mt->height);
ofs = LittleLong(mt->offsets[0]);

image = R_LoadPic(name, (byte *)mt + ofs, width, 0, height, 0, it_wall, 8);
if ((ofs <= 0) || (width <= 0) || (height <= 0) ||
(((size - ofs) / height) < width))
{
R_Printf(PRINT_ALL, "LoadWal: can't load %s, small body\n", name);
ri.FS_FreeFile((void *)mt);
return r_notexture;
}

image = R_LoadPic(name, (byte *)mt + ofs, width, 0, height, 0, type, 8);

ri.FS_FreeFile((void *)mt);

Expand Down Expand Up @@ -1078,7 +1093,7 @@ R_FindImage(char *name, imagetype_t type)

/* Remove the extension */
memset(namewe, 0, 256);
memcpy(namewe, name, len - 4);
memcpy(namewe, name, len - (strlen(ext) + 1));

if (len < 5)
{
Expand Down Expand Up @@ -1175,7 +1190,7 @@ R_FindImage(char *name, imagetype_t type)
else
{
/* WAL if no TGA/PNG/JPEG available (exists always) */
image = LoadWal(namewe);
image = LoadWal(namewe, type);
}

if (!image)
Expand All @@ -1186,7 +1201,7 @@ R_FindImage(char *name, imagetype_t type)
}
else /* gl_retexture is not set */
{
image = LoadWal(name);
image = LoadWal(name, type);

if (!image)
{
Expand Down
29 changes: 22 additions & 7 deletions src/client/refresh/gl3/gl3_image.c
Expand Up @@ -550,10 +550,10 @@ GL3_LoadPic(char *name, byte *pic, int width, int realwidth,
}

static gl3image_t *
LoadWal(char *origname)
LoadWal(char *origname, imagetype_t type)
{
miptex_t *mt;
int width, height, ofs;
int width, height, ofs, size;
gl3image_t *image;
char name[256];

Expand All @@ -565,19 +565,34 @@ LoadWal(char *origname)
Q_strlcat(name, ".wal", sizeof(name));
}

ri.FS_LoadFile(name, (void **)&mt);
size = ri.FS_LoadFile(name, (void **)&mt);

if (!mt)
{
R_Printf(PRINT_ALL, "LoadWal: can't load %s\n", name);
return gl3_notexture;
}

if (size < sizeof(miptex_t))
{
R_Printf(PRINT_ALL, "LoadWal: can't load %s, small header\n", name);
ri.FS_FreeFile((void *)mt);
return gl3_notexture;
}

width = LittleLong(mt->width);
height = LittleLong(mt->height);
ofs = LittleLong(mt->offsets[0]);

image = GL3_LoadPic(name, (byte *)mt + ofs, width, 0, height, 0, it_wall, 8);
if ((ofs <= 0) || (width <= 0) || (height <= 0) ||
(((size - ofs) / height) < width))
{
R_Printf(PRINT_ALL, "LoadWal: can't load %s, small body\n", name);
ri.FS_FreeFile((void *)mt);
return gl3_notexture;
}

image = GL3_LoadPic(name, (byte *)mt + ofs, width, 0, height, 0, type, 8);

ri.FS_FreeFile((void *)mt);

Expand Down Expand Up @@ -615,7 +630,7 @@ GL3_FindImage(char *name, imagetype_t type)

/* Remove the extension */
memset(namewe, 0, 256);
memcpy(namewe, name, len - 4);
memcpy(namewe, name, len - (strlen(ext) + 1));

if (len < 5)
{
Expand Down Expand Up @@ -711,7 +726,7 @@ GL3_FindImage(char *name, imagetype_t type)
else
{
/* WAL if no TGA/PNG/JPEG available (exists always) */
image = LoadWal(namewe);
image = LoadWal(namewe, type);
}

if (!image)
Expand All @@ -722,7 +737,7 @@ GL3_FindImage(char *name, imagetype_t type)
}
else /* gl_retexture is not set */
{
image = LoadWal(name);
image = LoadWal(name, type);

if (!image)
{
Expand Down
3 changes: 1 addition & 2 deletions src/client/refresh/soft/header/local.h
Expand Up @@ -361,7 +361,6 @@ extern qboolean r_dowarp;

extern affinetridesc_t r_affinetridesc;

void R_DrawParticle(void);
void D_WarpScreen(void);
void R_PolysetUpdateTables(void);

Expand Down Expand Up @@ -390,7 +389,7 @@ surfcache_t *D_CacheSurface (msurface_t *surface, int miplevel);

extern int d_vrectx, d_vrecty, d_vrectright_particle, d_vrectbottom_particle;

extern int d_pix_min, d_pix_max, d_pix_shift;
extern int d_pix_min, d_pix_max, d_pix_mul;

extern pixel_t *d_viewbuffer;
extern zvalue_t *d_pzbuffer;
Expand Down
57 changes: 48 additions & 9 deletions src/client/refresh/soft/sw_image.c
Expand Up @@ -133,41 +133,80 @@ R_LoadPic (char *name, byte *pic, int width, int height, imagetype_t type)
return image;
}

static void
R_Restore_Mip(unsigned char* src, unsigned char *dst, int height, int width)
{
int x, y;
for (y=0; y<height; y++)
{
for (x=0; x<width; x++)
{
dst[x + y * width] = src[(x + y * width)*2];
}
}
}

/*
================
R_LoadWal
================
*/
static image_t *
R_LoadWal (char *name)
R_LoadWal (char *name, imagetype_t type)
{
miptex_t *mt;
int ofs;
int ofs;
image_t *image;
int size;
int size, file_size;

ri.FS_LoadFile (name, (void **)&mt);
file_size = ri.FS_LoadFile (name, (void **)&mt);
if (!mt)
{
R_Printf(PRINT_ALL, "R_LoadWal: can't load %s\n", name);
return r_notexture_mip;
}

if (file_size < sizeof(miptex_t))
{
R_Printf(PRINT_ALL, "R_LoadWal: can't load %s, small header\n", name);
ri.FS_FreeFile ((void *)mt);
return r_notexture_mip;
}

image = R_FindFreeImage ();
strcpy (image->name, name);
image->width = LittleLong (mt->width);
image->height = LittleLong (mt->height);
image->type = it_wall;
image->type = type;
image->registration_sequence = registration_sequence;
ofs = LittleLong (mt->offsets[0]);
size = image->width * image->height * (256+64+16+4)/256;

if ((ofs <= 0) || (image->width <= 0) || (image->height <= 0) ||
((file_size - ofs) / image->width < image->height))
{
R_Printf(PRINT_ALL, "LoadWal: can't load %s, small body\n", name);
ri.FS_FreeFile((void *)mt);
return r_notexture_mip;
}

size = image->width*image->height * (256+64+16+4)/256;
image->pixels[0] = malloc (size);
image->pixels[1] = image->pixels[0] + image->width*image->height;
image->pixels[2] = image->pixels[1] + image->width*image->height/4;
image->pixels[3] = image->pixels[2] + image->width*image->height/16;

ofs = LittleLong (mt->offsets[0]);
memcpy ( image->pixels[0], (byte *)mt + ofs, size);
if (size > (file_size - ofs))
{
memcpy ( image->pixels[0], (byte *)mt + ofs, file_size - ofs);
// looks to short restore everything from first image
R_Restore_Mip(image->pixels[0], image->pixels[1], image->height/2, image->width/2);
R_Restore_Mip(image->pixels[1], image->pixels[2], image->height/4, image->width/4);
R_Restore_Mip(image->pixels[2], image->pixels[3], image->height/8, image->width/8);
}
else
{
memcpy ( image->pixels[0], (byte *)mt + ofs, size);
}

ri.FS_FreeFile ((void *)mt);

Expand Down Expand Up @@ -228,7 +267,7 @@ image_t *R_FindImage (char *name, imagetype_t type)
}
else if (!strcmp(name+len-4, ".wal"))
{
image = R_LoadWal (name);
image = R_LoadWal (name, type);
}
else if (!strcmp(name+len-4, ".tga"))
return NULL; // ri.Sys_Error (ERR_DROP, "R_FindImage: can't load %s in software renderer", name);
Expand Down
2 changes: 2 additions & 0 deletions src/client/refresh/soft/sw_main.c
Expand Up @@ -122,6 +122,7 @@ cvar_t *sw_stipplealpha;
cvar_t *sw_surfcacheoverride;
cvar_t *sw_waterwarp;
static cvar_t *sw_overbrightbits;
cvar_t *sw_custom_particles;

cvar_t *r_drawworld;
static cvar_t *r_drawentities;
Expand Down Expand Up @@ -269,6 +270,7 @@ R_Register (void)
sw_surfcacheoverride = ri.Cvar_Get ("sw_surfcacheoverride", "0", 0);
sw_waterwarp = ri.Cvar_Get ("sw_waterwarp", "1", 0);
sw_overbrightbits = ri.Cvar_Get("sw_overbrightbits", "1.0", CVAR_ARCHIVE);
sw_custom_particles = ri.Cvar_Get("sw_custom_particles", "0", CVAR_ARCHIVE);
r_mode = ri.Cvar_Get( "r_mode", "0", CVAR_ARCHIVE );

r_lefthand = ri.Cvar_Get( "hand", "0", CVAR_USERINFO | CVAR_ARCHIVE );
Expand Down
9 changes: 5 additions & 4 deletions src/client/refresh/soft/sw_misc.c
Expand Up @@ -40,7 +40,7 @@ static int r_frustum_indexes[4*6];
static float basemip[NUM_MIPS-1] = {1.0, 0.5*0.8, 0.25*0.8};
int d_vrectx, d_vrecty, d_vrectright_particle, d_vrectbottom_particle;
float xcenter, ycenter;
int d_pix_min, d_pix_max, d_pix_shift;
int d_pix_min, d_pix_max, d_pix_mul;

/*
================
Expand All @@ -56,15 +56,16 @@ D_ViewChanged (void)

d_zwidth = vid.width;

d_pix_min = r_refdef.vrect.width / 320;
d_pix_min = r_refdef.vrect.height / 240;
if (d_pix_min < 1)
d_pix_min = 1;

d_pix_max = (int)((float)r_refdef.vrect.width / (320.0 / 4.0) + 0.5);
d_pix_shift = 8 - (int)((float)r_refdef.vrect.width / 320.0 + 0.5);
d_pix_max = (int)((float)r_refdef.vrect.height / (240.0 / 4.0) + 0.5);
if (d_pix_max < 1)
d_pix_max = 1;

d_pix_mul = (int)((float)r_refdef.vrect.height / 240.0 + 0.5);

d_vrectx = r_refdef.vrect.x;
d_vrecty = r_refdef.vrect.y;
d_vrectright_particle = r_refdef.vrectright - d_pix_max;
Expand Down

0 comments on commit d4b6e93

Please sign in to comment.