2006-08-20 12:55:46 +00:00
|
|
|
/*
|
|
|
|
** multipatchtexture.cpp
|
|
|
|
** Texture class for standard Doom multipatch textures
|
|
|
|
**
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
** Copyright 2004-2006 Randy Heit
|
|
|
|
** All rights reserved.
|
|
|
|
**
|
|
|
|
** Redistribution and use in source and binary forms, with or without
|
|
|
|
** modification, are permitted provided that the following conditions
|
|
|
|
** are met:
|
|
|
|
**
|
|
|
|
** 1. Redistributions of source code must retain the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer.
|
|
|
|
** 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer in the
|
|
|
|
** documentation and/or other materials provided with the distribution.
|
|
|
|
** 3. The name of the author may not be used to endorse or promote products
|
|
|
|
** derived from this software without specific prior written permission.
|
|
|
|
**
|
|
|
|
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
**
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
2008-04-12 15:31:18 +00:00
|
|
|
#include <ctype.h>
|
2006-08-20 12:55:46 +00:00
|
|
|
#include "doomtype.h"
|
|
|
|
#include "files.h"
|
|
|
|
#include "r_data.h"
|
|
|
|
#include "w_wad.h"
|
|
|
|
#include "i_system.h"
|
|
|
|
#include "gi.h"
|
Note: I have not tried compiling these recent changes under Linux. I wouldn't
be surprised if it doesn't work.
- Reorganized the network startup loops so now they are event driven. There is
a single function that gets called to drive it, and it uses callbacks to
perform the different stages of the synchronization. This lets me have a nice,
responsive abort button instead of the previous unannounced hit-escape-to-
abort behavior, and I think the rearranged code is slightly easier to
understand too.
- Increased the number of bytes for version info during D_ArbitrateNetStart(),
in preparation for the day when NETGAMEVERSION requires more than one byte.
- I noticed an issue with Vista RC1 and the new fatal error setup. Even after
releasing a DirectDraw or Direct3D interface, the DWM can still use the
last image drawn using them when it composites the window. It doesn't always
do it but it does often enough that it is a real problem. At this point, I
don't know if it's a problem with the release version of Vista or not.
After messing around, I discovered the problem was caused by ~Win32Video()
hiding the window and then having it immediately shown soon after. The DWM
kept an image of the window to do the transition effect with, and then when
it didn't get a chance to do the transition, it didn't properly forget about
its saved image and kept plastering it on top of everything else
underneath.
- Added a network synchronization panel to the window during netgame startup.
- Fixed: PClass::CreateDerivedClass() must initialize StateList to NULL.
Otherwise, classic DECORATE definitions generate a big, fat crash.
- Resurrected the R_Init progress bar, now as a standard Windows control.
- Removed the sound failure dialog. The FMOD setup already defaulted to no
sound if initialization failed, so this only applies when snd_output is set
to "alternate" which now also falls back to no sound. In addition, it wasn't
working right, and I didn't feel like fixing it for the probably 0% of users
it affected.
- Fixed: The edit control used for logging output added text in reverse order
on Win9x.
- Went back to the roots and made graphics initialization one of the last
things to happen during setup. Now the startup text is visible again. More
importantly, the main window is no longer created invisible, which seems
to cause trouble with it not always appearing in the taskbar. The fatal
error dialog is now also embedded in the main window instead of being a
separate modal dialog, so you can play with the log window to see any
problems that might be reported there.
Rather than completely restoring the original startup order, I tried to
keep things as close to the way they were with early graphics startup. In
particular, V_Init() now creates a dummy screen so that things that need
screen dimensions can get them. It gets replaced by the real screen later
in I_InitGraphics(). Will need to check this under Linux to make sure it
didn't cause any problems there.
- Removed the following stubs that just called functions in Video:
- I_StartModeIterator()
- I_NextMode()
- I_DisplayType()
I_FullscreenChanged() was also removed, and a new fullscreen parameter
was added to IVideo::StartModeIterator(), since that's all it controlled.
- Renamed I_InitHardware() back to I_InitGraphics(), since that's all it's
initialized post-1.22.
SVN r416 (trunk)
2006-12-19 04:09:10 +00:00
|
|
|
#include "st_start.h"
|
2008-04-12 15:31:18 +00:00
|
|
|
#include "sc_man.h"
|
|
|
|
#include "templates.h"
|
2008-04-15 22:17:30 +00:00
|
|
|
#include "r_translate.h"
|
|
|
|
#include "bitmap.h"
|
2008-09-14 23:54:38 +00:00
|
|
|
#include "colormatcher.h"
|
2008-09-15 14:11:05 +00:00
|
|
|
#include "v_palette.h"
|
2006-08-20 12:55:46 +00:00
|
|
|
|
|
|
|
// On the Alpha, accessing the shorts directly if they aren't aligned on a
|
|
|
|
// 4-byte boundary causes unaligned access warnings. Why it does this at
|
|
|
|
// all and only while initing the textures is beyond me.
|
|
|
|
|
|
|
|
#ifdef ALPHA
|
2006-09-14 00:02:31 +00:00
|
|
|
#define SAFESHORT(s) ((short)(((BYTE *)&(s))[0] + ((BYTE *)&(s))[1] * 256))
|
2006-08-20 12:55:46 +00:00
|
|
|
#else
|
|
|
|
#define SAFESHORT(s) LittleShort(s)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-06-01 20:43:02 +00:00
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Data structures for the TEXTUREx lumps
|
|
|
|
//
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
|
|
|
|
//
|
|
|
|
// Each texture is composed of one or more patches, with patches being lumps
|
|
|
|
// stored in the WAD. The lumps are referenced by number, and patched into
|
|
|
|
// the rectangular texture space using origin and possibly other attributes.
|
|
|
|
//
|
|
|
|
struct mappatch_t
|
|
|
|
{
|
|
|
|
SWORD originx;
|
|
|
|
SWORD originy;
|
|
|
|
SWORD patch;
|
|
|
|
SWORD stepdir;
|
|
|
|
SWORD colormap;
|
|
|
|
};
|
|
|
|
|
|
|
|
//
|
|
|
|
// A wall texture is a list of patches which are to be combined in a
|
|
|
|
// predefined order.
|
|
|
|
//
|
|
|
|
struct maptexture_t
|
|
|
|
{
|
|
|
|
BYTE name[8];
|
|
|
|
WORD Flags; // [RH] Was unused
|
|
|
|
BYTE ScaleX; // [RH] Scaling (8 is normal)
|
|
|
|
BYTE ScaleY; // [RH] Same as above
|
|
|
|
SWORD width;
|
|
|
|
SWORD height;
|
|
|
|
BYTE columndirectory[4]; // OBSOLETE
|
|
|
|
SWORD patchcount;
|
|
|
|
mappatch_t patches[1];
|
|
|
|
};
|
|
|
|
|
|
|
|
#define MAPTEXF_WORLDPANNING 0x8000
|
|
|
|
|
|
|
|
// Strife uses versions of the above structures that remove all unused fields
|
|
|
|
|
|
|
|
struct strifemappatch_t
|
|
|
|
{
|
|
|
|
SWORD originx;
|
|
|
|
SWORD originy;
|
|
|
|
SWORD patch;
|
|
|
|
};
|
|
|
|
|
|
|
|
//
|
|
|
|
// A wall texture is a list of patches which are to be combined in a
|
|
|
|
// predefined order.
|
|
|
|
//
|
|
|
|
struct strifemaptexture_t
|
|
|
|
{
|
|
|
|
BYTE name[8];
|
|
|
|
WORD Flags; // [RH] Was unused
|
|
|
|
BYTE ScaleX; // [RH] Scaling (8 is normal)
|
|
|
|
BYTE ScaleY; // [RH] Same as above
|
|
|
|
SWORD width;
|
|
|
|
SWORD height;
|
|
|
|
SWORD patchcount;
|
|
|
|
strifemappatch_t patches[1];
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// In-memory representation of a single PNAMES lump entry
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
struct FPatchLookup
|
|
|
|
{
|
|
|
|
char Name[9];
|
|
|
|
FTexture *Texture;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// A texture defined in a TEXTURE1 or TEXTURE2 lump
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
class FMultiPatchTexture : public FTexture
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
FMultiPatchTexture (const void *texdef, FPatchLookup *patchlookup, int maxpatchnum, bool strife, int deflump);
|
|
|
|
FMultiPatchTexture (FScanner &sc, int usetype);
|
|
|
|
~FMultiPatchTexture ();
|
|
|
|
|
|
|
|
const BYTE *GetColumn (unsigned int column, const Span **spans_out);
|
|
|
|
const BYTE *GetPixels ();
|
|
|
|
FTextureFormat GetFormat();
|
|
|
|
bool UseBasePalette() ;
|
|
|
|
void Unload ();
|
|
|
|
virtual void SetFrontSkyLayer ();
|
|
|
|
|
2009-08-10 18:30:25 +00:00
|
|
|
int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int w, int h, int rotate, FCopyInfo *inf = NULL);
|
2008-06-01 20:43:02 +00:00
|
|
|
int GetSourceLump() { return DefinitionLump; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
BYTE *Pixels;
|
|
|
|
Span **Spans;
|
|
|
|
int DefinitionLump;
|
|
|
|
|
|
|
|
struct TexPart
|
|
|
|
{
|
|
|
|
SWORD OriginX, OriginY;
|
|
|
|
BYTE Rotate;
|
|
|
|
BYTE op;
|
|
|
|
FRemapTable *Translation;
|
|
|
|
PalEntry Blend;
|
|
|
|
FTexture *Texture;
|
|
|
|
fixed_t Alpha;
|
|
|
|
|
|
|
|
TexPart();
|
|
|
|
};
|
|
|
|
|
|
|
|
int NumParts;
|
|
|
|
TexPart *Parts;
|
|
|
|
bool bRedirect:1;
|
|
|
|
bool bTranslucentPatches:1;
|
|
|
|
|
|
|
|
void MakeTexture ();
|
2008-08-14 19:08:38 +00:00
|
|
|
FTexture *GetRedirect(bool wantwarped);
|
2008-06-01 20:43:02 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void CheckForHacks ();
|
|
|
|
void ParsePatch(FScanner &sc, TexPart & part);
|
|
|
|
};
|
|
|
|
|
2008-01-27 09:38:37 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// FMultiPatchTexture :: FMultiPatchTexture
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2008-03-25 09:43:50 +00:00
|
|
|
FMultiPatchTexture::FMultiPatchTexture (const void *texdef, FPatchLookup *patchlookup, int maxpatchnum, bool strife, int deflumpnum)
|
2008-04-22 18:48:30 +00:00
|
|
|
: Pixels (0), Spans(0), Parts(0), bRedirect(false), bTranslucentPatches(false)
|
2006-08-20 12:55:46 +00:00
|
|
|
{
|
|
|
|
union
|
|
|
|
{
|
|
|
|
const maptexture_t *d;
|
|
|
|
const strifemaptexture_t *s;
|
|
|
|
}
|
|
|
|
mtexture;
|
|
|
|
|
|
|
|
union
|
|
|
|
{
|
|
|
|
const mappatch_t *d;
|
|
|
|
const strifemappatch_t *s;
|
|
|
|
}
|
|
|
|
mpatch;
|
|
|
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
mtexture.d = (const maptexture_t *)texdef;
|
|
|
|
|
|
|
|
if (strife)
|
|
|
|
{
|
|
|
|
NumParts = SAFESHORT(mtexture.s->patchcount);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NumParts = SAFESHORT(mtexture.d->patchcount);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NumParts <= 0)
|
|
|
|
{
|
|
|
|
I_FatalError ("Bad texture directory");
|
|
|
|
}
|
|
|
|
|
|
|
|
UseType = FTexture::TEX_Wall;
|
|
|
|
Parts = new TexPart[NumParts];
|
|
|
|
Width = SAFESHORT(mtexture.d->width);
|
|
|
|
Height = SAFESHORT(mtexture.d->height);
|
2006-09-14 00:02:31 +00:00
|
|
|
strncpy (Name, (const char *)mtexture.d->name, 8);
|
2006-08-20 12:55:46 +00:00
|
|
|
Name[8] = 0;
|
|
|
|
|
|
|
|
CalcBitSize ();
|
|
|
|
|
2007-04-29 12:07:27 +00:00
|
|
|
xScale = mtexture.d->ScaleX ? mtexture.d->ScaleX*(FRACUNIT/8) : FRACUNIT;
|
|
|
|
yScale = mtexture.d->ScaleY ? mtexture.d->ScaleY*(FRACUNIT/8) : FRACUNIT;
|
2006-08-20 12:55:46 +00:00
|
|
|
|
|
|
|
if (mtexture.d->Flags & MAPTEXF_WORLDPANNING)
|
|
|
|
{
|
|
|
|
bWorldPanning = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strife)
|
|
|
|
{
|
|
|
|
mpatch.s = &mtexture.s->patches[0];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mpatch.d = &mtexture.d->patches[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < NumParts; ++i)
|
|
|
|
{
|
|
|
|
if (unsigned(LittleShort(mpatch.d->patch)) >= unsigned(maxpatchnum))
|
|
|
|
{
|
|
|
|
I_FatalError ("Bad PNAMES and/or texture directory:\n\nPNAMES has %d entries, but\n%s wants to use entry %d.",
|
|
|
|
maxpatchnum, Name, LittleShort(mpatch.d->patch)+1);
|
|
|
|
}
|
|
|
|
Parts[i].OriginX = LittleShort(mpatch.d->originx);
|
|
|
|
Parts[i].OriginY = LittleShort(mpatch.d->originy);
|
|
|
|
Parts[i].Texture = patchlookup[LittleShort(mpatch.d->patch)].Texture;
|
|
|
|
if (Parts[i].Texture == NULL)
|
|
|
|
{
|
|
|
|
Printf ("Unknown patch %s in texture %s\n", patchlookup[LittleShort(mpatch.d->patch)].Name, Name);
|
|
|
|
NumParts--;
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
if (strife)
|
|
|
|
mpatch.s++;
|
|
|
|
else
|
|
|
|
mpatch.d++;
|
|
|
|
}
|
|
|
|
if (NumParts == 0)
|
|
|
|
{
|
|
|
|
Printf ("Texture %s is left without any patches\n", Name);
|
|
|
|
}
|
|
|
|
|
|
|
|
CheckForHacks ();
|
|
|
|
|
|
|
|
// If this texture is just a wrapper around a single patch, we can simply
|
|
|
|
// forward GetPixels() and GetColumn() calls to that patch.
|
|
|
|
if (NumParts == 1)
|
|
|
|
{
|
|
|
|
if (Parts->OriginX == 0 && Parts->OriginY == 0 &&
|
|
|
|
Parts->Texture->GetWidth() == Width &&
|
|
|
|
Parts->Texture->GetHeight() == Height)
|
|
|
|
{
|
|
|
|
bRedirect = true;
|
|
|
|
}
|
|
|
|
}
|
2008-03-25 09:43:50 +00:00
|
|
|
DefinitionLump = deflumpnum;
|
2006-08-20 12:55:46 +00:00
|
|
|
}
|
|
|
|
|
2008-01-27 09:38:37 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// FMultiPatchTexture :: ~FMultiPatchTexture
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2006-08-20 12:55:46 +00:00
|
|
|
FMultiPatchTexture::~FMultiPatchTexture ()
|
|
|
|
{
|
|
|
|
Unload ();
|
|
|
|
if (Parts != NULL)
|
|
|
|
{
|
2008-04-16 18:17:20 +00:00
|
|
|
for(int i=0; i<NumParts;i++)
|
|
|
|
{
|
|
|
|
if (Parts[i].Translation != NULL) delete Parts[i].Translation;
|
|
|
|
}
|
2006-08-20 12:55:46 +00:00
|
|
|
delete[] Parts;
|
|
|
|
Parts = NULL;
|
|
|
|
}
|
|
|
|
if (Spans != NULL)
|
|
|
|
{
|
|
|
|
FreeSpans (Spans);
|
|
|
|
Spans = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-27 09:38:37 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// FMultiPatchTexture :: SetFrontSkyLayer
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2006-08-20 12:55:46 +00:00
|
|
|
void FMultiPatchTexture::SetFrontSkyLayer ()
|
|
|
|
{
|
|
|
|
for (int i = 0; i < NumParts; ++i)
|
|
|
|
{
|
|
|
|
Parts[i].Texture->SetFrontSkyLayer ();
|
|
|
|
}
|
|
|
|
bNoRemap0 = true;
|
|
|
|
}
|
|
|
|
|
2008-01-27 09:38:37 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// FMultiPatchTexture :: Unload
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2006-08-20 12:55:46 +00:00
|
|
|
void FMultiPatchTexture::Unload ()
|
|
|
|
{
|
|
|
|
if (Pixels != NULL)
|
|
|
|
{
|
|
|
|
delete[] Pixels;
|
|
|
|
Pixels = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-27 09:38:37 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// FMultiPatchTexture :: GetPixels
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2006-08-20 12:55:46 +00:00
|
|
|
const BYTE *FMultiPatchTexture::GetPixels ()
|
|
|
|
{
|
|
|
|
if (bRedirect)
|
|
|
|
{
|
|
|
|
return Parts->Texture->GetPixels ();
|
|
|
|
}
|
|
|
|
if (Pixels == NULL)
|
|
|
|
{
|
|
|
|
MakeTexture ();
|
|
|
|
}
|
|
|
|
return Pixels;
|
|
|
|
}
|
|
|
|
|
2008-01-27 09:38:37 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// FMultiPatchTexture :: GetColumn
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2006-08-20 12:55:46 +00:00
|
|
|
const BYTE *FMultiPatchTexture::GetColumn (unsigned int column, const Span **spans_out)
|
|
|
|
{
|
|
|
|
if (bRedirect)
|
|
|
|
{
|
|
|
|
return Parts->Texture->GetColumn (column, spans_out);
|
|
|
|
}
|
|
|
|
if (Pixels == NULL)
|
|
|
|
{
|
|
|
|
MakeTexture ();
|
|
|
|
}
|
|
|
|
if ((unsigned)column >= (unsigned)Width)
|
|
|
|
{
|
|
|
|
if (WidthMask + 1 == Width)
|
|
|
|
{
|
|
|
|
column &= WidthMask;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
column %= Width;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (spans_out != NULL)
|
|
|
|
{
|
2008-04-14 12:10:45 +00:00
|
|
|
if (Spans == NULL)
|
|
|
|
{
|
|
|
|
Spans = CreateSpans (Pixels);
|
|
|
|
}
|
2006-08-20 12:55:46 +00:00
|
|
|
*spans_out = Spans[column];
|
|
|
|
}
|
|
|
|
return Pixels + column*Height;
|
|
|
|
}
|
|
|
|
|
2008-04-15 22:17:30 +00:00
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
2009-07-17 01:17:06 +00:00
|
|
|
// GetBlendMap
|
2008-04-15 22:17:30 +00:00
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2009-07-17 01:17:06 +00:00
|
|
|
BYTE *GetBlendMap(PalEntry blend, BYTE *blendwork)
|
2008-04-15 22:17:30 +00:00
|
|
|
{
|
|
|
|
|
2008-04-16 18:17:20 +00:00
|
|
|
switch (blend.a==0 ? blend.r : -1)
|
2008-04-15 22:17:30 +00:00
|
|
|
{
|
|
|
|
case BLEND_INVERSEMAP:
|
|
|
|
return InverseColormap;
|
|
|
|
|
|
|
|
case BLEND_GOLDMAP:
|
|
|
|
return GoldColormap;
|
|
|
|
|
|
|
|
case BLEND_REDMAP:
|
|
|
|
return RedColormap;
|
|
|
|
|
|
|
|
case BLEND_GREENMAP:
|
|
|
|
return GreenColormap;
|
|
|
|
|
|
|
|
case BLEND_ICEMAP:
|
|
|
|
return TranslationToTable(TRANSLATION(TRANSLATION_Standard, 7))->Remap;
|
|
|
|
|
|
|
|
default:
|
2008-04-16 18:17:20 +00:00
|
|
|
if (blend.r >= BLEND_DESATURATE1 && blend.r <= BLEND_DESATURATE31)
|
2008-04-15 22:17:30 +00:00
|
|
|
{
|
2008-12-07 12:11:59 +00:00
|
|
|
return DesaturateColormap[blend.r - BLEND_DESATURATE1];
|
2008-04-15 22:17:30 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
blendwork[0]=0;
|
|
|
|
if (blend.a == 255)
|
|
|
|
{
|
|
|
|
for(int i=1;i<256;i++)
|
|
|
|
{
|
|
|
|
int rr = (blend.r * GPalette.BaseColors[i].r) / 255;
|
|
|
|
int gg = (blend.g * GPalette.BaseColors[i].g) / 255;
|
|
|
|
int bb = (blend.b * GPalette.BaseColors[i].b) / 255;
|
|
|
|
|
|
|
|
blendwork[i] = ColorMatcher.Pick(rr, gg, bb);
|
|
|
|
}
|
|
|
|
return blendwork;
|
|
|
|
}
|
|
|
|
else if (blend.a != 0)
|
|
|
|
{
|
|
|
|
for(int i=1;i<256;i++)
|
|
|
|
{
|
|
|
|
int rr = (blend.r * blend.a + GPalette.BaseColors[i].r * (255-blend.a)) / 255;
|
|
|
|
int gg = (blend.g * blend.a + GPalette.BaseColors[i].g * (255-blend.a)) / 255;
|
|
|
|
int bb = (blend.b * blend.a + GPalette.BaseColors[i].b * (255-blend.a)) / 255;
|
|
|
|
|
|
|
|
blendwork[i] = ColorMatcher.Pick(rr, gg, bb);
|
|
|
|
}
|
|
|
|
return blendwork;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-01-27 09:38:37 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// FMultiPatchTexture :: MakeTexture
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2006-08-20 12:55:46 +00:00
|
|
|
void FMultiPatchTexture::MakeTexture ()
|
|
|
|
{
|
|
|
|
// Add a little extra space at the end if the texture's height is not
|
|
|
|
// a power of 2, in case somebody accidentally makes it repeat vertically.
|
|
|
|
int numpix = Width * Height + (1 << HeightBits) - Height;
|
2009-04-16 02:05:13 +00:00
|
|
|
BYTE blendwork[256];
|
2008-05-15 17:16:32 +00:00
|
|
|
bool hasTranslucent = false;
|
2006-08-20 12:55:46 +00:00
|
|
|
|
|
|
|
Pixels = new BYTE[numpix];
|
|
|
|
memset (Pixels, 0, numpix);
|
|
|
|
|
2008-05-15 17:16:32 +00:00
|
|
|
// This is not going to be easy for paletted output. Using the
|
|
|
|
// real time mixing tables gives results that just look bad and
|
|
|
|
// downconverting a true color image also has its problems so the only
|
|
|
|
// real choice is to do normal compositing with any translucent patch
|
|
|
|
// just masking the affected pixels, then do a full true color composition
|
|
|
|
// and merge these pixels in.
|
|
|
|
for (int i = 0; i < NumParts; ++i)
|
2008-04-22 18:48:30 +00:00
|
|
|
{
|
2009-04-16 02:02:56 +00:00
|
|
|
BYTE *trans = Parts[i].Translation ? Parts[i].Translation->Remap : NULL;
|
2008-05-15 17:16:32 +00:00
|
|
|
if (Parts[i].op != OP_COPY)
|
2008-04-22 18:48:30 +00:00
|
|
|
{
|
2008-05-15 17:16:32 +00:00
|
|
|
hasTranslucent = true;
|
|
|
|
}
|
2009-04-16 02:02:56 +00:00
|
|
|
else
|
2008-05-15 17:16:32 +00:00
|
|
|
{
|
2009-04-16 02:02:56 +00:00
|
|
|
if (Parts[i].Blend != 0)
|
|
|
|
{
|
|
|
|
trans = GetBlendMap(Parts[i].Blend, blendwork);
|
|
|
|
}
|
|
|
|
Parts[i].Texture->CopyToBlock (Pixels, Width, Height,
|
|
|
|
Parts[i].OriginX, Parts[i].OriginY, Parts[i].Rotate, trans);
|
2008-04-22 18:48:30 +00:00
|
|
|
}
|
|
|
|
}
|
2008-05-15 17:16:32 +00:00
|
|
|
|
|
|
|
if (hasTranslucent)
|
2006-08-20 12:55:46 +00:00
|
|
|
{
|
2008-04-22 18:48:30 +00:00
|
|
|
// In case there are translucent patches let's do the composition in
|
|
|
|
// True color to keep as much precision as possible before downconverting to the palette.
|
|
|
|
BYTE *buffer = new BYTE[Width * Height * 4];
|
2009-04-16 02:02:56 +00:00
|
|
|
memset(buffer, 0, Width * Height * 4);
|
2008-04-22 18:48:30 +00:00
|
|
|
FillBuffer(buffer, Width * 4, Height, TEX_RGB);
|
|
|
|
for(int y = 0; y < Height; y++)
|
2008-04-15 22:17:30 +00:00
|
|
|
{
|
2008-04-22 18:48:30 +00:00
|
|
|
BYTE *in = buffer + Width * y * 4;
|
|
|
|
BYTE *out = Pixels + y;
|
2008-05-15 17:16:32 +00:00
|
|
|
for (int x = 0; x < Width; x++)
|
2008-04-22 18:48:30 +00:00
|
|
|
{
|
2008-05-15 17:16:32 +00:00
|
|
|
if (*out == 0 && in[3] != 0)
|
|
|
|
{
|
|
|
|
*out = RGB32k[in[2]>>3][in[1]>>3][in[0]>>3];
|
|
|
|
}
|
2008-04-22 18:48:30 +00:00
|
|
|
out += Height;
|
|
|
|
in += 4;
|
|
|
|
}
|
2008-04-15 22:17:30 +00:00
|
|
|
}
|
2008-04-22 18:48:30 +00:00
|
|
|
delete [] buffer;
|
2006-08-20 12:55:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-14 18:51:05 +00:00
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// FMultipatchTexture::CopyTrueColorPixels
|
|
|
|
//
|
|
|
|
// Preserves the palettes of each individual patch
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
2009-08-10 18:30:25 +00:00
|
|
|
int FMultiPatchTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int w, int h, int rotate, FCopyInfo *inf)
|
2008-04-14 18:51:05 +00:00
|
|
|
{
|
|
|
|
int retv = -1;
|
2008-04-16 18:17:20 +00:00
|
|
|
FCopyInfo info;
|
2008-04-14 18:51:05 +00:00
|
|
|
|
2009-08-10 18:30:25 +00:00
|
|
|
if (w < 0 || w > Width) w = Width;
|
|
|
|
if (h < 0 || h > Height) h = Height;
|
|
|
|
|
2008-04-14 18:51:05 +00:00
|
|
|
for(int i=0;i<NumParts;i++)
|
|
|
|
{
|
2008-04-29 02:43:42 +00:00
|
|
|
int ret = -1;
|
2008-04-15 22:17:30 +00:00
|
|
|
|
2008-04-16 18:17:20 +00:00
|
|
|
if (!Parts[i].Texture->bComplex || inf == NULL)
|
2008-04-15 22:17:30 +00:00
|
|
|
{
|
2008-04-16 18:17:20 +00:00
|
|
|
memset (&info, 0, sizeof (info));
|
2008-04-22 18:48:30 +00:00
|
|
|
info.alpha = Parts[i].Alpha;
|
|
|
|
info.invalpha = FRACUNIT - info.alpha;
|
|
|
|
info.op = ECopyOp(Parts[i].op);
|
2008-04-15 22:17:30 +00:00
|
|
|
if (Parts[i].Translation != NULL)
|
|
|
|
{
|
|
|
|
// Using a translation forces downconversion to the base palette
|
2009-08-10 18:30:25 +00:00
|
|
|
ret = Parts[i].Texture->CopyTrueColorTranslated(bmp,
|
|
|
|
x+Parts[i].OriginX, y+Parts[i].OriginY,
|
|
|
|
w-Parts[i].OriginX, h-Parts[i].OriginY,
|
|
|
|
Parts[i].Rotate, Parts[i].Translation, &info);
|
2008-04-15 22:17:30 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-04-16 18:17:20 +00:00
|
|
|
PalEntry b = Parts[i].Blend;
|
|
|
|
if (b.a == 0 && b.r != BLEND_NONE)
|
2008-04-15 22:17:30 +00:00
|
|
|
{
|
2008-04-16 18:17:20 +00:00
|
|
|
info.blend = EBlend(b.r);
|
2008-04-15 22:17:30 +00:00
|
|
|
}
|
2008-04-16 18:17:20 +00:00
|
|
|
else if (b.a != 0)
|
|
|
|
{
|
|
|
|
if (b.a == 255)
|
|
|
|
{
|
|
|
|
info.blendcolor[0] = b.r * FRACUNIT / 255;
|
|
|
|
info.blendcolor[1] = b.g * FRACUNIT / 255;
|
|
|
|
info.blendcolor[2] = b.b * FRACUNIT / 255;
|
|
|
|
info.blend = BLEND_MODULATE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
info.blendcolor[3] = b.a * FRACUNIT / 255;
|
|
|
|
info.blendcolor[0] = b.r * (FRACUNIT-info.blendcolor[3]);
|
|
|
|
info.blendcolor[1] = b.g * (FRACUNIT-info.blendcolor[3]);
|
|
|
|
info.blendcolor[2] = b.b * (FRACUNIT-info.blendcolor[3]);
|
|
|
|
|
|
|
|
info.blend = BLEND_OVERLAY;
|
|
|
|
}
|
|
|
|
}
|
2009-08-10 18:30:25 +00:00
|
|
|
ret = Parts[i].Texture->CopyTrueColorPixels(bmp,
|
|
|
|
x+Parts[i].OriginX, y+Parts[i].OriginY,
|
|
|
|
w-Parts[i].OriginX, h-Parts[i].OriginY,
|
|
|
|
Parts[i].Rotate, &info);
|
2008-04-15 22:17:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// If the patch is a texture with some kind of processing involved
|
2008-04-16 18:17:20 +00:00
|
|
|
// and being drawn with additional processing
|
2008-04-15 22:17:30 +00:00
|
|
|
// the copying must be done in 2 steps: First create a complete image of the patch
|
|
|
|
// including all processing and then copy from that intermediate image to the destination
|
2008-04-16 18:17:20 +00:00
|
|
|
FBitmap bmp1;
|
|
|
|
if (bmp1.Create(Parts[i].Texture->GetWidth(), Parts[i].Texture->GetHeight()))
|
|
|
|
{
|
|
|
|
Parts[i].Texture->CopyTrueColorPixels(&bmp1, 0, 0);
|
2009-08-10 18:30:25 +00:00
|
|
|
bmp->CopyPixelDataRGB(
|
|
|
|
x+Parts[i].OriginX, y+Parts[i].OriginY, bmp1.GetPixels(),
|
|
|
|
MIN<int>(w-Parts[i].OriginX, bmp1.GetWidth()),
|
|
|
|
MIN<int>(h-Parts[i].OriginY, bmp1.GetHeight()),
|
|
|
|
4, bmp1.GetPitch()*4, Parts[i].Rotate, CF_BGRA, inf);
|
2008-04-16 18:17:20 +00:00
|
|
|
}
|
2008-04-15 22:17:30 +00:00
|
|
|
}
|
2008-04-14 18:51:05 +00:00
|
|
|
|
|
|
|
if (ret > retv) retv = ret;
|
|
|
|
}
|
|
|
|
return retv;
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// FMultiPatchTexture :: GetFormat
|
|
|
|
//
|
|
|
|
// only returns 'paletted' if all patches use the base palette.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
FTextureFormat FMultiPatchTexture::GetFormat()
|
|
|
|
{
|
2008-04-15 22:17:30 +00:00
|
|
|
if (bComplex) return TEX_RGB;
|
2008-04-14 18:51:05 +00:00
|
|
|
if (NumParts == 1) return Parts[0].Texture->GetFormat();
|
|
|
|
return UseBasePalette() ? TEX_Pal : TEX_RGB;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// FMultipatchTexture::UseBasePalette
|
|
|
|
//
|
|
|
|
// returns true if all patches in the texture use the unmodified base
|
|
|
|
// palette.
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
bool FMultiPatchTexture::UseBasePalette()
|
|
|
|
{
|
2008-04-15 22:17:30 +00:00
|
|
|
if (bComplex) return false;
|
2008-04-14 18:51:05 +00:00
|
|
|
for(int i=0;i<NumParts;i++)
|
|
|
|
{
|
|
|
|
if (!Parts[i].Texture->UseBasePalette()) return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-01-27 09:38:37 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// FMultiPatchTexture :: CheckForHacks
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2006-08-20 12:55:46 +00:00
|
|
|
void FMultiPatchTexture::CheckForHacks ()
|
|
|
|
{
|
|
|
|
if (NumParts <= 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Heretic sky textures are marked as only 128 pixels tall,
|
|
|
|
// even though they are really 200 pixels tall.
|
|
|
|
if (gameinfo.gametype == GAME_Heretic &&
|
|
|
|
Name[0] == 'S' &&
|
|
|
|
Name[1] == 'K' &&
|
|
|
|
Name[2] == 'Y' &&
|
|
|
|
Name[4] == 0 &&
|
|
|
|
Name[3] >= '1' &&
|
|
|
|
Name[3] <= '3' &&
|
|
|
|
Height == 128)
|
|
|
|
{
|
|
|
|
Height = 200;
|
|
|
|
HeightBits = 8;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The Doom E1 sky has its patch's y offset at -8 instead of 0.
|
|
|
|
if (gameinfo.gametype == GAME_Doom &&
|
|
|
|
!(gameinfo.flags & GI_MAPxx) &&
|
|
|
|
NumParts == 1 &&
|
|
|
|
Height == 128 &&
|
|
|
|
Parts->OriginY == -8 &&
|
|
|
|
Name[0] == 'S' &&
|
|
|
|
Name[1] == 'K' &&
|
|
|
|
Name[2] == 'Y' &&
|
|
|
|
Name[3] == '1' &&
|
|
|
|
Name[4] == 0)
|
|
|
|
{
|
|
|
|
Parts->OriginY = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// BIGDOOR7 in Doom also has patches at y offset -4 instead of 0.
|
|
|
|
if (gameinfo.gametype == GAME_Doom &&
|
|
|
|
!(gameinfo.flags & GI_MAPxx) &&
|
|
|
|
NumParts == 2 &&
|
|
|
|
Height == 128 &&
|
|
|
|
Parts[0].OriginY == -4 &&
|
|
|
|
Parts[1].OriginY == -4 &&
|
|
|
|
Name[0] == 'B' &&
|
|
|
|
Name[1] == 'I' &&
|
|
|
|
Name[2] == 'G' &&
|
|
|
|
Name[3] == 'D' &&
|
|
|
|
Name[4] == 'O' &&
|
|
|
|
Name[5] == 'O' &&
|
|
|
|
Name[6] == 'R' &&
|
|
|
|
Name[7] == '7')
|
|
|
|
{
|
|
|
|
Parts[0].OriginY = 0;
|
|
|
|
Parts[1].OriginY = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// [RH] Some wads (I forget which!) have single-patch textures 256
|
|
|
|
// pixels tall that have patch lengths recorded as 0. I can't think of
|
|
|
|
// any good reason for them to do this, and since I didn't make note
|
|
|
|
// of which wad made me hack in support for them, the hack is gone
|
|
|
|
// because I've added support for DeePsea's true tall patches.
|
|
|
|
//
|
|
|
|
// Okay, I found a wad with crap patches: Pleiades.wad's sky patches almost
|
|
|
|
// fit this description and are a big mess, but they're not single patch!
|
|
|
|
if (Height == 256)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
// All patches must be at the top of the texture for this fix
|
|
|
|
for (i = 0; i < NumParts; ++i)
|
|
|
|
{
|
2008-06-01 20:43:02 +00:00
|
|
|
if (Parts[i].OriginY != 0)
|
2006-08-20 12:55:46 +00:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == NumParts)
|
|
|
|
{
|
2008-06-01 20:43:02 +00:00
|
|
|
for (i = 0; i < NumParts; ++i)
|
2006-08-20 12:55:46 +00:00
|
|
|
{
|
2008-06-01 20:43:02 +00:00
|
|
|
Parts[i].Texture->HackHack(256);
|
2006-08-20 12:55:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-12 15:31:18 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// FMultiPatchTexture :: TexPart :: TexPart
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2008-08-14 19:08:38 +00:00
|
|
|
FTexture *FMultiPatchTexture::GetRedirect(bool wantwarped)
|
|
|
|
{
|
|
|
|
if (bRedirect) return Parts->Texture;
|
|
|
|
else return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// FMultiPatchTexture :: TexPart :: TexPart
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2008-04-12 15:31:18 +00:00
|
|
|
FMultiPatchTexture::TexPart::TexPart()
|
|
|
|
{
|
|
|
|
OriginX = OriginY = 0;
|
2008-04-14 18:51:05 +00:00
|
|
|
Rotate = 0;
|
2008-04-12 15:31:18 +00:00
|
|
|
Texture = NULL;
|
2008-04-15 22:17:30 +00:00
|
|
|
Translation = NULL;
|
|
|
|
Blend = 0;
|
2008-04-22 18:48:30 +00:00
|
|
|
Alpha = FRACUNIT;
|
|
|
|
op = OP_COPY;
|
2008-04-12 15:31:18 +00:00
|
|
|
}
|
|
|
|
|
2008-01-27 09:38:37 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// FTextureManager :: AddTexturesLump
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2008-03-25 09:43:50 +00:00
|
|
|
void FTextureManager::AddTexturesLump (const void *lumpdata, int lumpsize, int deflumpnum, int patcheslump, int firstdup, bool texture1)
|
2006-08-20 12:55:46 +00:00
|
|
|
{
|
|
|
|
FPatchLookup *patchlookup;
|
2008-06-15 18:36:26 +00:00
|
|
|
int i;
|
2006-08-20 12:55:46 +00:00
|
|
|
DWORD numpatches;
|
|
|
|
|
|
|
|
if (firstdup == 0)
|
|
|
|
{
|
|
|
|
firstdup = (int)Textures.Size();
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
FWadLump pnames = Wads.OpenLumpNum (patcheslump);
|
|
|
|
|
|
|
|
pnames >> numpatches;
|
|
|
|
|
|
|
|
// Check whether the amount of names reported is correct.
|
|
|
|
if (numpatches < 0)
|
|
|
|
{
|
|
|
|
Printf("Corrupt PNAMES lump found (negative amount of entries reported)");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check whether the amount of names reported is correct.
|
|
|
|
int lumplength = Wads.LumpLength(patcheslump);
|
|
|
|
if (numpatches > DWORD((lumplength-4)/8))
|
|
|
|
{
|
2006-09-14 00:02:31 +00:00
|
|
|
Printf("PNAMES lump is shorter than required (%u entries reported but only %d bytes (%d entries) long\n",
|
2006-08-20 12:55:46 +00:00
|
|
|
numpatches, lumplength, (lumplength-4)/8);
|
|
|
|
// Truncate but continue reading. Who knows how many such lumps exist?
|
|
|
|
numpatches = (lumplength-4)/8;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Catalog the patches these textures use so we know which
|
|
|
|
// textures they represent.
|
|
|
|
patchlookup = (FPatchLookup *)alloca (numpatches * sizeof(*patchlookup));
|
|
|
|
|
|
|
|
for (DWORD i = 0; i < numpatches; ++i)
|
|
|
|
{
|
|
|
|
pnames.Read (patchlookup[i].Name, 8);
|
|
|
|
patchlookup[i].Name[8] = 0;
|
|
|
|
|
2008-06-15 18:36:26 +00:00
|
|
|
FTextureID j = CheckForTexture (patchlookup[i].Name, FTexture::TEX_WallPatch);
|
|
|
|
if (j.isValid())
|
2006-08-20 12:55:46 +00:00
|
|
|
{
|
2008-06-15 18:36:26 +00:00
|
|
|
patchlookup[i].Texture = Textures[j.GetIndex()].Texture;
|
2006-08-20 12:55:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Shareware Doom has the same PNAMES lump as the registered
|
|
|
|
// Doom, so printing warnings for patches that don't really
|
|
|
|
// exist isn't such a good idea.
|
|
|
|
//Printf ("Patch %s not found.\n", patchlookup[i].Name);
|
|
|
|
patchlookup[i].Texture = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isStrife = false;
|
|
|
|
const DWORD *maptex, *directory;
|
|
|
|
DWORD maxoff;
|
|
|
|
int numtextures;
|
|
|
|
DWORD offset = 0; // Shut up, GCC!
|
|
|
|
|
|
|
|
maptex = (const DWORD *)lumpdata;
|
|
|
|
numtextures = LittleLong(*maptex);
|
|
|
|
maxoff = lumpsize;
|
|
|
|
|
|
|
|
if (maxoff < DWORD(numtextures+1)*4)
|
|
|
|
{
|
|
|
|
Printf ("Texture directory is too short");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Scan the texture lump to decide if it contains Doom or Strife textures
|
|
|
|
for (i = 0, directory = maptex+1; i < numtextures; ++i)
|
|
|
|
{
|
|
|
|
offset = LittleLong(directory[i]);
|
|
|
|
if (offset > maxoff)
|
|
|
|
{
|
|
|
|
Printf ("Bad texture directory");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
maptexture_t *tex = (maptexture_t *)((BYTE *)maptex + offset);
|
|
|
|
|
|
|
|
// There is bizzarely a Doom editing tool that writes to the
|
|
|
|
// first two elements of columndirectory, so I can't check those.
|
|
|
|
if (SAFESHORT(tex->patchcount) <= 0 ||
|
|
|
|
tex->columndirectory[2] != 0 ||
|
|
|
|
tex->columndirectory[3] != 0)
|
|
|
|
{
|
|
|
|
isStrife = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Textures defined earlier in the lump take precedence over those defined later,
|
|
|
|
// but later TEXTUREx lumps take precedence over earlier ones.
|
|
|
|
for (i = 1, directory = maptex; i <= numtextures; ++i)
|
|
|
|
{
|
|
|
|
if (i == 1 && texture1)
|
|
|
|
{
|
|
|
|
// The very first texture is just a dummy. Copy its dimensions to texture 0.
|
|
|
|
// It still needs to be created in case someone uses it by name.
|
|
|
|
offset = LittleLong(directory[1]);
|
|
|
|
const maptexture_t *tex = (const maptexture_t *)((const BYTE *)maptex + offset);
|
|
|
|
FDummyTexture *tex0 = static_cast<FDummyTexture *>(Textures[0].Texture);
|
|
|
|
tex0->SetSize (SAFESHORT(tex->width), SAFESHORT(tex->height));
|
|
|
|
}
|
|
|
|
|
|
|
|
offset = LittleLong(directory[i]);
|
|
|
|
if (offset > maxoff)
|
|
|
|
{
|
|
|
|
Printf ("Bad texture directory");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If this texture was defined already in this lump, skip it
|
|
|
|
// This could cause problems with animations that use the same name for intermediate
|
|
|
|
// textures. Should I be worried?
|
2008-06-15 18:36:26 +00:00
|
|
|
int j;
|
2006-08-20 12:55:46 +00:00
|
|
|
for (j = (int)Textures.Size() - 1; j >= firstdup; --j)
|
|
|
|
{
|
|
|
|
if (strnicmp (Textures[j].Texture->Name, (const char *)maptex + offset, 8) == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (j + 1 == firstdup)
|
|
|
|
{
|
2008-03-25 09:43:50 +00:00
|
|
|
FMultiPatchTexture *tex = new FMultiPatchTexture ((const BYTE *)maptex + offset, patchlookup, numpatches, isStrife, deflumpnum);
|
2006-08-20 12:55:46 +00:00
|
|
|
if (i == 1 && texture1)
|
|
|
|
{
|
2008-05-23 14:04:16 +00:00
|
|
|
tex->UseType = FTexture::TEX_FirstDefined;
|
2006-08-20 12:55:46 +00:00
|
|
|
}
|
|
|
|
TexMan.AddTexture (tex);
|
2007-03-06 01:33:18 +00:00
|
|
|
StartScreen->Progress();
|
2006-08-20 12:55:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-27 09:38:37 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// FTextureManager :: AddTexturesLumps
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2006-08-20 12:55:46 +00:00
|
|
|
void FTextureManager::AddTexturesLumps (int lump1, int lump2, int patcheslump)
|
|
|
|
{
|
|
|
|
int firstdup = (int)Textures.Size();
|
|
|
|
|
|
|
|
if (lump1 >= 0)
|
|
|
|
{
|
|
|
|
FMemLump texdir = Wads.ReadLump (lump1);
|
2008-03-25 09:43:50 +00:00
|
|
|
AddTexturesLump (texdir.GetMem(), Wads.LumpLength (lump1), lump1, patcheslump, firstdup, true);
|
2006-08-20 12:55:46 +00:00
|
|
|
}
|
|
|
|
if (lump2 >= 0)
|
|
|
|
{
|
|
|
|
FMemLump texdir = Wads.ReadLump (lump2);
|
2008-03-25 09:43:50 +00:00
|
|
|
AddTexturesLump (texdir.GetMem(), Wads.LumpLength (lump2), lump2, patcheslump, firstdup, false);
|
2006-08-20 12:55:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-12 15:31:18 +00:00
|
|
|
|
2008-09-21 22:25:23 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//==========================================================================
|
2008-04-15 22:17:30 +00:00
|
|
|
|
2008-04-12 15:31:18 +00:00
|
|
|
void FMultiPatchTexture::ParsePatch(FScanner &sc, TexPart & part)
|
|
|
|
{
|
|
|
|
FString patchname;
|
|
|
|
sc.MustGetString();
|
|
|
|
|
2008-06-15 18:36:26 +00:00
|
|
|
FTextureID texno = TexMan.CheckForTexture(sc.String, TEX_WallPatch);
|
2008-04-14 18:51:05 +00:00
|
|
|
int Mirror = 0;
|
2008-04-12 15:31:18 +00:00
|
|
|
|
2008-06-15 18:36:26 +00:00
|
|
|
if (!texno.isValid())
|
2008-04-12 15:31:18 +00:00
|
|
|
{
|
|
|
|
int lumpnum = Wads.CheckNumForFullName(sc.String);
|
|
|
|
if (lumpnum >= 0)
|
|
|
|
{
|
2008-11-30 12:49:27 +00:00
|
|
|
texno = TexMan.FindTextureByLumpNum(lumpnum);
|
|
|
|
if (texno.isValid ())
|
|
|
|
{
|
|
|
|
part.Texture = TexMan[texno];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
part.Texture = FTexture::CreateTexture("", lumpnum, TEX_WallPatch);
|
|
|
|
TexMan.AddTexture(part.Texture);
|
|
|
|
}
|
2008-04-12 15:31:18 +00:00
|
|
|
}
|
2008-04-16 18:17:20 +00:00
|
|
|
else if (strlen(sc.String) <= 8 && !strpbrk(sc.String, "./"))
|
|
|
|
{
|
|
|
|
int lumpnum = Wads.CheckNumForName(sc.String, ns_patches);
|
|
|
|
if (lumpnum >= 0)
|
|
|
|
{
|
|
|
|
part.Texture = FTexture::CreateTexture(lumpnum, TEX_WallPatch);
|
|
|
|
TexMan.AddTexture(part.Texture);
|
|
|
|
}
|
|
|
|
}
|
2008-04-12 15:31:18 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
part.Texture = TexMan[texno];
|
2008-04-16 18:17:20 +00:00
|
|
|
bComplex |= part.Texture->bComplex;
|
2008-04-12 15:31:18 +00:00
|
|
|
}
|
|
|
|
if (part.Texture == NULL)
|
|
|
|
{
|
|
|
|
Printf("Unknown patch '%s' in texture '%s'\n", sc.String, Name);
|
|
|
|
}
|
|
|
|
sc.MustGetStringName(",");
|
|
|
|
sc.MustGetNumber();
|
|
|
|
part.OriginX = sc.Number;
|
|
|
|
sc.MustGetStringName(",");
|
|
|
|
sc.MustGetNumber();
|
|
|
|
part.OriginY = sc.Number;
|
|
|
|
|
2008-04-14 18:51:05 +00:00
|
|
|
if (sc.CheckString("{"))
|
2008-04-12 15:31:18 +00:00
|
|
|
{
|
|
|
|
while (!sc.CheckString("}"))
|
|
|
|
{
|
|
|
|
sc.MustGetString();
|
|
|
|
if (sc.Compare("flipx"))
|
|
|
|
{
|
2008-04-14 18:51:05 +00:00
|
|
|
Mirror |= 1;
|
2008-04-12 15:31:18 +00:00
|
|
|
}
|
|
|
|
else if (sc.Compare("flipy"))
|
|
|
|
{
|
2008-04-14 18:51:05 +00:00
|
|
|
Mirror |= 2;
|
2008-04-12 15:31:18 +00:00
|
|
|
}
|
|
|
|
else if (sc.Compare("rotate"))
|
|
|
|
{
|
|
|
|
sc.MustGetNumber();
|
2008-06-30 23:30:06 +00:00
|
|
|
sc.Number = (((sc.Number + 90)%360)-90);
|
|
|
|
if (sc.Number != 0 && sc.Number !=90 && sc.Number != 180 && sc.Number != -90)
|
|
|
|
{
|
|
|
|
sc.ScriptError("Rotation must be a multiple of 90 degrees.");
|
2008-04-12 15:31:18 +00:00
|
|
|
}
|
2008-04-14 18:51:05 +00:00
|
|
|
part.Rotate = (sc.Number / 90) & 3;
|
2008-04-12 15:31:18 +00:00
|
|
|
}
|
2008-04-15 22:17:30 +00:00
|
|
|
else if (sc.Compare("Translation"))
|
|
|
|
{
|
|
|
|
bComplex = true;
|
|
|
|
if (part.Translation != NULL) delete part.Translation;
|
|
|
|
part.Translation = NULL;
|
|
|
|
part.Blend = 0;
|
|
|
|
static const char *maps[] = { "inverse", "gold", "red", "green", "ice", "desaturate", NULL };
|
2008-04-16 18:17:20 +00:00
|
|
|
sc.MustGetString();
|
2008-04-15 22:17:30 +00:00
|
|
|
int match = sc.MatchString(maps);
|
|
|
|
if (match >= 0)
|
|
|
|
{
|
|
|
|
part.Blend.r = 1 + match;
|
|
|
|
if (part.Blend.r == BLEND_DESATURATE1)
|
|
|
|
{
|
|
|
|
sc.MustGetStringName(",");
|
|
|
|
sc.MustGetNumber();
|
|
|
|
part.Blend.r += clamp(sc.Number-1, 0, 30);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-04-16 18:17:20 +00:00
|
|
|
sc.UnGet();
|
2008-04-15 22:17:30 +00:00
|
|
|
part.Translation = new FRemapTable;
|
|
|
|
part.Translation->MakeIdentity();
|
|
|
|
do
|
|
|
|
{
|
|
|
|
sc.MustGetString();
|
2008-09-21 22:25:23 +00:00
|
|
|
part.Translation->AddToTranslation(sc.String);
|
2008-04-15 22:17:30 +00:00
|
|
|
}
|
|
|
|
while (sc.CheckString(","));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else if (sc.Compare("Blend"))
|
|
|
|
{
|
|
|
|
bComplex = true;
|
|
|
|
if (part.Translation != NULL) delete part.Translation;
|
|
|
|
part.Translation = NULL;
|
|
|
|
part.Blend = 0;
|
|
|
|
|
|
|
|
if (!sc.CheckNumber())
|
|
|
|
{
|
2008-04-16 18:17:20 +00:00
|
|
|
sc.MustGetString();
|
2008-04-15 22:17:30 +00:00
|
|
|
part.Blend = V_GetColor(NULL, sc.String);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int r,g,b;
|
|
|
|
|
|
|
|
r = sc.Number;
|
|
|
|
sc.MustGetStringName(",");
|
|
|
|
sc.MustGetNumber();
|
2008-04-25 09:40:08 +00:00
|
|
|
g = sc.Number;
|
2008-04-15 22:17:30 +00:00
|
|
|
sc.MustGetStringName(",");
|
2008-04-25 09:40:08 +00:00
|
|
|
sc.MustGetNumber();
|
2008-04-15 22:17:30 +00:00
|
|
|
b = sc.Number;
|
2008-04-25 09:40:08 +00:00
|
|
|
sc.MustGetStringName(",");
|
2008-04-15 22:17:30 +00:00
|
|
|
part.Blend = MAKERGB(r, g, b);
|
|
|
|
}
|
|
|
|
if (sc.CheckString(","))
|
|
|
|
{
|
|
|
|
sc.MustGetFloat();
|
|
|
|
part.Blend.a = clamp<int>(int(sc.Float*255), 1, 254);
|
|
|
|
}
|
|
|
|
else part.Blend.a = 255;
|
|
|
|
}
|
2008-04-22 18:48:30 +00:00
|
|
|
else if (sc.Compare("alpha"))
|
|
|
|
{
|
|
|
|
sc.MustGetFloat();
|
|
|
|
part.Alpha = clamp(FLOAT2FIXED(sc.Float), 0, FRACUNIT);
|
|
|
|
// bComplex is not set because it is only needed when the style is not OP_COPY.
|
|
|
|
}
|
|
|
|
else if (sc.Compare("style"))
|
|
|
|
{
|
2008-05-15 17:16:32 +00:00
|
|
|
static const char *styles[] = {"copy", "translucent", "add", "subtract", "reversesubtract", "modulate", "copyalpha", NULL };
|
2008-04-22 18:48:30 +00:00
|
|
|
sc.MustGetString();
|
|
|
|
part.op = sc.MustMatchString(styles);
|
2008-04-29 02:43:42 +00:00
|
|
|
bComplex = (part.op != OP_COPY);
|
|
|
|
bTranslucentPatches = bComplex;
|
2008-04-22 18:48:30 +00:00
|
|
|
}
|
2008-04-12 15:31:18 +00:00
|
|
|
}
|
|
|
|
}
|
2008-04-14 18:51:05 +00:00
|
|
|
if (Mirror & 2)
|
|
|
|
{
|
|
|
|
part.Rotate = (part.Rotate + 2) & 3;
|
|
|
|
Mirror ^= 1;
|
|
|
|
}
|
|
|
|
if (Mirror & 1)
|
2008-04-13 14:27:58 +00:00
|
|
|
{
|
2008-04-14 18:51:05 +00:00
|
|
|
part.Rotate |= 4;
|
2008-04-13 14:27:58 +00:00
|
|
|
}
|
2008-04-12 15:31:18 +00:00
|
|
|
}
|
|
|
|
|
2008-09-21 22:25:23 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// Constructor for text based multipatch definitions
|
|
|
|
//
|
|
|
|
//==========================================================================
|
2008-04-12 15:31:18 +00:00
|
|
|
|
|
|
|
FMultiPatchTexture::FMultiPatchTexture (FScanner &sc, int usetype)
|
2008-04-22 18:48:30 +00:00
|
|
|
: Pixels (0), Spans(0), Parts(0), bRedirect(false), bTranslucentPatches(false)
|
2008-04-12 15:31:18 +00:00
|
|
|
{
|
|
|
|
TArray<TexPart> parts;
|
|
|
|
|
2008-04-13 11:40:53 +00:00
|
|
|
sc.SetCMode(true);
|
2008-04-12 15:31:18 +00:00
|
|
|
sc.MustGetString();
|
|
|
|
uppercopy(Name, sc.String);
|
2008-04-13 11:40:53 +00:00
|
|
|
Name[8] = 0;
|
2008-04-12 15:31:18 +00:00
|
|
|
sc.MustGetStringName(",");
|
|
|
|
sc.MustGetNumber();
|
|
|
|
Width = sc.Number;
|
|
|
|
sc.MustGetStringName(",");
|
|
|
|
sc.MustGetNumber();
|
|
|
|
Height = sc.Number;
|
2008-06-16 07:40:28 +00:00
|
|
|
UseType = usetype;
|
2009-05-24 07:58:57 +00:00
|
|
|
|
2008-04-12 15:31:18 +00:00
|
|
|
if (sc.CheckString("{"))
|
|
|
|
{
|
|
|
|
while (!sc.CheckString("}"))
|
|
|
|
{
|
|
|
|
sc.MustGetString();
|
|
|
|
if (sc.Compare("XScale"))
|
|
|
|
{
|
|
|
|
sc.MustGetFloat();
|
|
|
|
xScale = FLOAT2FIXED(sc.Float);
|
|
|
|
}
|
|
|
|
else if (sc.Compare("YScale"))
|
|
|
|
{
|
|
|
|
sc.MustGetFloat();
|
|
|
|
yScale = FLOAT2FIXED(sc.Float);
|
|
|
|
}
|
|
|
|
else if (sc.Compare("WorldPanning"))
|
|
|
|
{
|
|
|
|
bWorldPanning = true;
|
|
|
|
}
|
2008-04-13 11:40:53 +00:00
|
|
|
else if (sc.Compare("NullTexture"))
|
|
|
|
{
|
|
|
|
UseType = FTexture::TEX_Null;
|
|
|
|
}
|
2008-04-12 15:31:18 +00:00
|
|
|
else if (sc.Compare("NoDecals"))
|
|
|
|
{
|
|
|
|
bNoDecals = true;
|
|
|
|
}
|
|
|
|
else if (sc.Compare("Patch"))
|
|
|
|
{
|
|
|
|
TexPart part;
|
|
|
|
ParsePatch(sc, part);
|
2008-04-16 18:17:20 +00:00
|
|
|
if (part.Texture != NULL) parts.Push(part);
|
|
|
|
part.Texture = NULL;
|
|
|
|
part.Translation = NULL;
|
2008-04-12 15:31:18 +00:00
|
|
|
}
|
2008-06-16 07:40:28 +00:00
|
|
|
else if (sc.Compare("Offset"))
|
|
|
|
{
|
|
|
|
sc.MustGetNumber();
|
|
|
|
LeftOffset = sc.Number;
|
|
|
|
sc.MustGetStringName(",");
|
|
|
|
sc.MustGetNumber();
|
|
|
|
TopOffset = sc.Number;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sc.ScriptError("Unknown texture property '%s'", sc.String);
|
|
|
|
}
|
2008-04-12 15:31:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NumParts = parts.Size();
|
|
|
|
Parts = new TexPart[NumParts];
|
|
|
|
memcpy(Parts, &parts[0], NumParts * sizeof(*Parts));
|
|
|
|
|
2009-05-24 07:58:57 +00:00
|
|
|
//CalcBitSize ();
|
2008-04-12 15:31:18 +00:00
|
|
|
|
|
|
|
// If this texture is just a wrapper around a single patch, we can simply
|
|
|
|
// forward GetPixels() and GetColumn() calls to that patch.
|
|
|
|
if (NumParts == 1)
|
|
|
|
{
|
|
|
|
if (Parts->OriginX == 0 && Parts->OriginY == 0 &&
|
|
|
|
Parts->Texture->GetWidth() == Width &&
|
|
|
|
Parts->Texture->GetHeight() == Height &&
|
2008-07-20 08:34:24 +00:00
|
|
|
Parts->Rotate == 0 &&
|
|
|
|
!bComplex)
|
2008-04-12 15:31:18 +00:00
|
|
|
{
|
|
|
|
bRedirect = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-05-24 07:58:57 +00:00
|
|
|
|
|
|
|
if (Width <= 0 || Height <= 0)
|
|
|
|
{
|
|
|
|
UseType = FTexture::TEX_Null;
|
|
|
|
Printf("Texture %s has invalid dimensions (%d, %d)\n", Name, Width, Height);
|
|
|
|
Width = Height = 1;
|
|
|
|
}
|
|
|
|
CalcBitSize ();
|
|
|
|
|
|
|
|
|
2008-04-13 11:40:53 +00:00
|
|
|
sc.SetCMode(false);
|
2008-04-12 15:31:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void FTextureManager::ParseXTexture(FScanner &sc, int usetype)
|
|
|
|
{
|
|
|
|
FTexture *tex = new FMultiPatchTexture(sc, usetype);
|
|
|
|
TexMan.AddTexture (tex);
|
|
|
|
}
|