- Removed a few redundant calls to FTexture::GetWidth because all textures

are now fully initialized when being created.
- Added GZDoom's HI_START/HI_END namespace and HIRESTEX support.
- Added sprite scaling to the weapon drawing code


SVN r304 (trunk)
This commit is contained in:
Christoph Oelckers 2006-08-22 21:45:12 +00:00
parent 5c7eeed018
commit 66295cf9e9
7 changed files with 177 additions and 16 deletions

View file

@ -1,3 +1,9 @@
August 22, 2006 (Changes by Graf Zahl)
- Removed a few redundant calls to FTexture::GetWidth because all textures
are now fully initialized when being created.
- Added GZDoom's HI_START/HI_END namespace and HIRESTEX support.
- Added sprite scaling support to the weapon drawing code
August 21, 2006 (Changes by Graf Zahl) August 21, 2006 (Changes by Graf Zahl)
- Added support for PCX textures (1, 4, 8 and 24 bit variants.) - Added support for PCX textures (1, 4, 8 and 24 bit variants.)

View file

@ -1127,7 +1127,6 @@ void FDoomStatusBar::FDoomStatusBarTexture::DrawToBar (const char *name, int x,
pic = TexMan[name]; pic = TexMan[name];
if (pic != NULL) if (pic != NULL)
{ {
pic->GetWidth();
x -= pic->LeftOffset; x -= pic->LeftOffset;
pic->CopyToBlock (Pixels, Width, Height, x, y, colormap); pic->CopyToBlock (Pixels, Width, Height, x, y, colormap);
} }

View file

@ -792,6 +792,11 @@ static bool StuffBitmap (const DCanvas *canvas, FILE *file)
const int height = canvas->GetHeight(); const int height = canvas->GetHeight();
BYTE *from = canvas->GetBuffer(); BYTE *from = canvas->GetBuffer();
return M_SaveBitmap(from, width, height, pitch, file);
}
bool M_SaveBitmap(BYTE * from, int width, int height, int pitch, FILE *file)
{
Byte buffer[PNG_WRITE_SIZE]; Byte buffer[PNG_WRITE_SIZE];
Byte zero = 0; Byte zero = 0;
z_stream stream; z_stream stream;

View file

@ -53,6 +53,8 @@ bool M_AppendPNGText (FILE *file, const char *keyword, const char *text);
// Appends the IEND chunk to a PNG file. // Appends the IEND chunk to a PNG file.
bool M_FinishPNG (FILE *file); bool M_FinishPNG (FILE *file);
bool M_SaveBitmap(BYTE * from, int width, int height, int pitch, FILE *file);
// PNG Reading -------------------------------------------------------------- // PNG Reading --------------------------------------------------------------
class FileReader; class FileReader;

View file

@ -45,6 +45,7 @@
#include "c_dispatch.h" #include "c_dispatch.h"
#include "c_console.h" #include "c_console.h"
#include "r_data.h" #include "r_data.h"
#include "sc_man.h"
#include "v_palette.h" #include "v_palette.h"
#include "v_video.h" #include "v_video.h"
@ -290,6 +291,146 @@ void FTextureManager::AddGroup(const char * startlump, const char * endlump, int
} }
} }
//==========================================================================
//
// Adds all hires texture definitions.
//
//==========================================================================
void FTextureManager::AddHiresTextures ()
{
int firsttx = Wads.CheckNumForName ("HI_START");
int lasttx = Wads.CheckNumForName ("HI_END");
char name[9];
if (firsttx == -1 || lasttx == -1)
{
return;
}
name[8] = 0;
for (firsttx += 1; firsttx < lasttx; ++firsttx)
{
Wads.GetLumpName (name, firsttx);
if (Wads.CheckNumForName (name, ns_hires) == firsttx)
{
FTexture * newtex = FTexture::CreateTexture (firsttx, FTexture::TEX_Any);
int oldtexno = CheckForTexture(name, FTexture::TEX_Wall, TEXMAN_Overridable|TEXMAN_TryAny);
if (oldtexno<0)
{
// A texture with this name does not yet exist
newtex->UseType=FTexture::TEX_Override;
AddTexture(newtex);
}
else
{
FTexture * oldtex = Textures[oldtexno].Texture;
// Replace the entire texture and adjust the scaling and offset factors.
newtex->ScaleX = 8 * newtex->GetWidth() / oldtex->GetWidth();
newtex->ScaleY = 8 * newtex->GetHeight() / oldtex->GetHeight();
newtex->LeftOffset = Scale(oldtex->LeftOffset, newtex->ScaleX, 8);
newtex->TopOffset = Scale(oldtex->TopOffset, newtex->ScaleY, 8);
ReplaceTexture(oldtexno, newtex, true);
}
}
}
}
//==========================================================================
//
// Loads the HIRESTEX lumps
//
//==========================================================================
void FTextureManager::LoadHiresTex()
{
int remapLump, lastLump;
char src[9];
bool is32bit;
int width, height;
int type,mode;
lastLump = 0;
src[8] = '\0';
while ((remapLump = Wads.FindLump("HIRESTEX", &lastLump)) != -1)
{
SC_OpenLumpNum(remapLump, "HIRESTEX");
while (SC_GetString())
{
if (SC_Compare("remap")) // remap an existing texture
{
SC_MustGetString();
// allow selection by type
if (SC_Compare("wall")) type=FTexture::TEX_Wall, mode=FTextureManager::TEXMAN_Overridable;
else if (SC_Compare("flat")) type=FTexture::TEX_Flat, mode=FTextureManager::TEXMAN_Overridable;
else if (SC_Compare("sprite")) type=FTexture::TEX_Sprite, mode=0;
else type = FTexture::TEX_Any;
sc_String[8]=0;
int tex = TexMan.CheckForTexture(sc_String, type, mode);
SC_MustGetString();
int lumpnum = Wads.CheckNumForFullName(sc_String);
if (lumpnum < 0) lumpnum = Wads.CheckNumForName(sc_String, ns_graphics);
if (tex>0)
{
FTexture * oldtex = TexMan[tex];
FTexture * newtex = FTexture::CreateTexture (lumpnum, FTexture::TEX_Any);
// Replace the entire texture and adjust the scaling and offset factors.
newtex->ScaleX = 8 * newtex->GetWidth() / oldtex->GetWidth();
newtex->ScaleY = 8 * newtex->GetHeight() / oldtex->GetHeight();
newtex->LeftOffset = Scale(oldtex->LeftOffset, newtex->ScaleX, 8);
newtex->TopOffset = Scale(oldtex->TopOffset, newtex->ScaleY, 8);
ReplaceTexture(tex, newtex, true);
}
}
else if (SC_Compare("define")) // define a new "fake" texture
{
SC_GetString();
memcpy(src, sc_String, 8);
int lumpnum = Wads.CheckNumForFullName(sc_String);
if (lumpnum < 0) lumpnum = Wads.CheckNumForName(sc_String, ns_graphics);
SC_GetString();
is32bit = !!SC_Compare("force32bit");
if (!is32bit) SC_UnGet();
SC_GetNumber();
width = sc_Number;
SC_GetNumber();
height = sc_Number;
if (lumpnum>=0)
{
FTexture *newtex = FTexture::CreateTexture(lumpnum, FTexture::TEX_Override);
// Replace the entire texture and adjust the scaling and offset factors.
newtex->ScaleX = 8 * width / newtex->GetWidth();
newtex->ScaleY = 8 * height / newtex->GetHeight();
newtex->LeftOffset = Scale(newtex->LeftOffset, newtex->ScaleX, 8);
newtex->TopOffset = Scale(newtex->TopOffset, newtex->ScaleY, 8);
memcpy(newtex->Name, src, sizeof(newtex->Name));
int oldtex = TexMan.CheckForTexture(src, FTexture::TEX_Override);
if (oldtex>=0) TexMan.ReplaceTexture(oldtex, newtex, true);
else TexMan.AddTexture(newtex);
}
//else Printf("Unable to define hires texture '%s'\n", tex->Name);
}
}
SC_Close();
}
}
void FTextureManager::AddPatches (int lumpnum) void FTextureManager::AddPatches (int lumpnum)
{ {
@ -563,6 +704,8 @@ void R_InitData ()
TexMan.AddGroup("F_START", "F_END", ns_flats, FTexture::TEX_Flat); TexMan.AddGroup("F_START", "F_END", ns_flats, FTexture::TEX_Flat);
R_InitBuildTiles (); R_InitBuildTiles ();
TexMan.AddGroup("TX_START", "TX_END", ns_newtextures, FTexture::TEX_Override); TexMan.AddGroup("TX_START", "TX_END", ns_newtextures, FTexture::TEX_Override);
TexMan.AddHiresTextures ();
TexMan.LoadHiresTex ();
TexMan.DefaultTexture = TexMan.CheckForTexture ("-NOFLAT-", FTexture::TEX_Override, 0); TexMan.DefaultTexture = TexMan.CheckForTexture ("-NOFLAT-", FTexture::TEX_Override, 0);
R_InitColormaps (); R_InitColormaps ();

View file

@ -648,6 +648,12 @@ public:
int GetWidth () { return Width; } int GetWidth () { return Width; }
int GetHeight () { return Height; } int GetHeight () { return Height; }
int GetScaledWidth () { return DivScale3(Width, ScaleX); }
int GetScaledHeight () { return DivScale3(Height, ScaleY); }
int GetScaledLeftOffset () { return DivScale3(LeftOffset, ScaleX); }
int GetScaledTopOffset () { return DivScale3(TopOffset, ScaleY); }
virtual void SetFrontSkyLayer(); virtual void SetFrontSkyLayer();
void CopyToBlock (BYTE *dest, int dwidth, int dheight, int x, int y, const BYTE *translation=NULL); void CopyToBlock (BYTE *dest, int dwidth, int dheight, int x, int y, const BYTE *translation=NULL);
@ -734,6 +740,8 @@ public:
void AddGroup(const char * startlump, const char * endlump, int ns, int usetype); void AddGroup(const char * startlump, const char * endlump, int ns, int usetype);
void AddPatches (int lumpnum); void AddPatches (int lumpnum);
void AddTiles (void *tileFile); void AddTiles (void *tileFile);
void AddHiresTextures ();
void LoadHiresTex();
int CreateTexture (int lumpnum, int usetype=FTexture::TEX_Any); // Also calls AddTexture int CreateTexture (int lumpnum, int usetype=FTexture::TEX_Any); // Also calls AddTexture
int AddTexture (FTexture *texture); int AddTexture (FTexture *texture);

View file

@ -1175,7 +1175,6 @@ void R_ProjectSprite (AActor *thing, int fakeside)
int picnum; int picnum;
FTexture *tex; FTexture *tex;
int picwidth;
WORD flip; WORD flip;
@ -1299,9 +1298,6 @@ void R_ProjectSprite (AActor *thing, int fakeside)
return; return;
} }
// Getting the width now ensures that the texture's dimensions are loaded
picwidth = tex->GetWidth ();
// [RH] Added scaling // [RH] Added scaling
gzt = fz + (tex->TopOffset << (FRACBITS-6-3)) * (thing->yscale+1) * tex->ScaleX; gzt = fz + (tex->TopOffset << (FRACBITS-6-3)) * (thing->yscale+1) * tex->ScaleX;
gzb = fz + ((tex->TopOffset - tex->GetHeight()) << (FRACBITS-6-3)) * (thing->yscale+1) * tex->ScaleY; gzb = fz + ((tex->TopOffset - tex->GetHeight()) << (FRACBITS-6-3)) * (thing->yscale+1) * tex->ScaleY;
@ -1479,7 +1475,6 @@ void R_DrawPSprite (pspdef_t* psp, int pspnum, AActor *owner, fixed_t sx, fixed_
spritedef_t* sprdef; spritedef_t* sprdef;
spriteframe_t* sprframe; spriteframe_t* sprframe;
int picnum; int picnum;
int picwidth;
WORD flip; WORD flip;
FTexture* tex; FTexture* tex;
vissprite_t* vis; vissprite_t* vis;
@ -1506,19 +1501,18 @@ void R_DrawPSprite (pspdef_t* psp, int pspnum, AActor *owner, fixed_t sx, fixed_
if (tex->UseType == FTexture::TEX_Null) if (tex->UseType == FTexture::TEX_Null)
return; return;
picwidth = tex->GetWidth ();
// calculate edges of the shape // calculate edges of the shape
tx = sx-((320/2)<<FRACBITS); tx = sx-((320/2)<<FRACBITS);
tx -= tex->LeftOffset << FRACBITS; tx -= tex->GetScaledLeftOffset() << FRACBITS;
x1 = (centerxfrac + FixedMul (tx, pspritexscale)) >>FRACBITS; x1 = (centerxfrac + FixedMul (tx, pspritexscale)) >>FRACBITS;
// off the right side // off the right side
if (x1 > viewwidth) if (x1 > viewwidth)
return; return;
tx += tex->GetWidth() << FRACBITS; tx += tex->GetScaledWidth() << FRACBITS;
x2 = ((centerxfrac + FixedMul (tx, pspritexscale)) >>FRACBITS) - 1; x2 = ((centerxfrac + FixedMul (tx, pspritexscale)) >>FRACBITS) - 1;
// off the left side // off the left side
@ -1529,7 +1523,11 @@ void R_DrawPSprite (pspdef_t* psp, int pspnum, AActor *owner, fixed_t sx, fixed_
vis = &avis; vis = &avis;
vis->renderflags = owner->renderflags; vis->renderflags = owner->renderflags;
vis->floorclip = 0; vis->floorclip = 0;
vis->texturemid = (BASEYCENTER<<FRACBITS) - (sy - (tex->TopOffset << FRACBITS));
vis->texturemid = MulScale3((BASEYCENTER<<FRACBITS) - sy, tex->ScaleY) + (tex->TopOffset << FRACBITS);
if (camera->player && (RenderTarget != screen || if (camera->player && (RenderTarget != screen ||
realviewheight == RenderTarget->GetHeight() || realviewheight == RenderTarget->GetHeight() ||
(RenderTarget->GetWidth() > 320 && !st_scale))) (RenderTarget->GetWidth() > 320 && !st_scale)))
@ -1558,19 +1556,19 @@ void R_DrawPSprite (pspdef_t* psp, int pspnum, AActor *owner, fixed_t sx, fixed_
} }
vis->x1 = x1 < 0 ? 0 : x1; vis->x1 = x1 < 0 ? 0 : x1;
vis->x2 = x2 >= viewwidth ? viewwidth-1 : x2; vis->x2 = x2 >= viewwidth ? viewwidth-1 : x2;
vis->xscale = pspritexscale; vis->xscale = DivScale3(pspritexscale, tex->ScaleX);
vis->yscale = pspriteyscale; vis->yscale = DivScale3(pspriteyscale, tex->ScaleY);
vis->Translation = 0; // [RH] Use default colors vis->Translation = 0; // [RH] Use default colors
vis->pic = tex; vis->pic = tex;
if (flip) if (flip)
{ {
vis->xiscale = -pspritexiscale; vis->xiscale = -MulScale3(pspritexiscale, tex->ScaleX);
vis->startfrac = (tex->GetWidth() << FRACBITS) - 1; vis->startfrac = (tex->GetWidth() << FRACBITS) - 1;
} }
else else
{ {
vis->xiscale = pspritexiscale; vis->xiscale = MulScale3(pspritexiscale, tex->ScaleX);
vis->startfrac = 0; vis->startfrac = 0;
} }