- optionally allow passing a script position object to V_GetColor and subfunctions for better error output. Implemented this for all occurences where this info was available.

This commit is contained in:
Christoph Oelckers 2016-12-03 16:27:53 +01:00
parent 1fc90b1ba9
commit 21e3aba1c7
15 changed files with 51 additions and 54 deletions

View File

@ -15,6 +15,7 @@
#include "cmdlib.h"
#include "i_system.h"
#include "v_text.h"
#include "sc_man.h"
#include <sys/types.h>
#include <sys/stat.h>
@ -324,7 +325,7 @@ FString ExtractFileBase (const char *path, bool include_extension)
//
//==========================================================================
int ParseHex (const char *hex)
int ParseHex (const char *hex, FScriptPosition *sc)
{
const char *str;
int num;
@ -342,7 +343,8 @@ int ParseHex (const char *hex)
else if (*str >= 'A' && *str <= 'F')
num += 10 + *str-'A';
else {
Printf ("Bad hex number: %s\n",hex);
if (!sc) Printf ("Bad hex number: %s\n",hex);
else sc->Message(MSG_WARNING, "Bad hex number: %s", hex);
return 0;
}
str++;
@ -351,21 +353,6 @@ int ParseHex (const char *hex)
return num;
}
//==========================================================================
//
// ParseNum
//
//==========================================================================
int ParseNum (const char *str)
{
if (str[0] == '$')
return ParseHex (str+1);
if (str[0] == '0' && str[1] == 'x')
return ParseHex (str+2);
return atol (str);
}
//==========================================================================
//
// IsNum

View File

@ -33,8 +33,8 @@ void DefaultExtension (FString &path, const char *extension);
FString ExtractFilePath (const char *path);
FString ExtractFileBase (const char *path, bool keep_extension=false);
int ParseHex (const char *str);
int ParseNum (const char *str);
struct FScriptPosition;
int ParseHex(const char *str, FScriptPosition *sc = nullptr);
bool IsNum (const char *str); // [RH] added
char *copystring(const char *s);

View File

@ -193,10 +193,10 @@ void FIWadManager::ParseIWadInfo(const char *fn, const char *data, int datasize)
{
sc.MustGetStringName("=");
sc.MustGetString();
iwad->FgColor = V_GetColor(NULL, sc.String);
iwad->FgColor = V_GetColor(NULL, sc);
sc.MustGetStringName(",");
sc.MustGetString();
iwad->BkColor = V_GetColor(NULL, sc.String);
iwad->BkColor = V_GetColor(NULL, sc);
}
else if (sc.Compare("Load"))
{

View File

@ -1844,10 +1844,10 @@ static FString ParseGameInfo(TArray<FString> &pwads, const char *fn, const char
else if (!nextKey.CompareNoCase("STARTUPCOLORS"))
{
sc.MustGetString();
DoomStartupInfo.FgColor = V_GetColor(NULL, sc.String);
DoomStartupInfo.FgColor = V_GetColor(NULL, sc);
sc.MustGetStringName(",");
sc.MustGetString();
DoomStartupInfo.BkColor = V_GetColor(NULL, sc.String);
DoomStartupInfo.BkColor = V_GetColor(NULL, sc);
}
else if (!nextKey.CompareNoCase("STARTUPTYPE"))
{

View File

@ -532,7 +532,7 @@ void FDecalLib::ParseDecal (FScanner &sc)
sc.MustGetString ();
if (!sc.Compare("BloodDefault"))
{
newdecal.ShadeColor = V_GetColor (NULL, sc.String);
newdecal.ShadeColor = V_GetColor (NULL, sc);
}
else
{
@ -547,8 +547,8 @@ void FDecalLib::ParseDecal (FScanner &sc)
case DECAL_COLORS:
DWORD startcolor, endcolor;
sc.MustGetString (); startcolor = V_GetColor (NULL, sc.String);
sc.MustGetString (); endcolor = V_GetColor (NULL, sc.String);
sc.MustGetString (); startcolor = V_GetColor (NULL, sc);
sc.MustGetString (); endcolor = V_GetColor (NULL, sc);
newdecal.Translation = GenerateTranslation (startcolor, endcolor)->Index;
break;
@ -819,7 +819,7 @@ void FDecalLib::ParseColorchanger (FScanner &sc)
else if (sc.Compare ("Color"))
{
sc.MustGetString ();
goal = V_GetColor (NULL, sc.String);
goal = V_GetColor (NULL, sc);
}
else
{

View File

@ -860,14 +860,14 @@ DEFINE_MAP_OPTION(fade, true)
{
parse.ParseAssign();
parse.sc.MustGetString();
info->fadeto = V_GetColor(NULL, parse.sc.String);
info->fadeto = V_GetColor(NULL, parse.sc);
}
DEFINE_MAP_OPTION(outsidefog, true)
{
parse.ParseAssign();
parse.sc.MustGetString();
info->outsidefog = V_GetColor(NULL, parse.sc.String);
info->outsidefog = V_GetColor(NULL, parse.sc);
}
DEFINE_MAP_OPTION(titlepatch, true)

View File

@ -400,10 +400,10 @@ static void ParseListMenuBody(FScanner &sc, FListMenuDescriptor *desc)
int y = sc.Number;
sc.MustGetStringName(",");
sc.MustGetString();
PalEntry c1 = V_GetColor(NULL, sc.String);
PalEntry c1 = V_GetColor(NULL, sc);
sc.MustGetStringName(",");
sc.MustGetString();
PalEntry c2 = V_GetColor(NULL, sc.String);
PalEntry c2 = V_GetColor(NULL, sc);
if (sc.CheckString(","))
{
sc.MustGetNumber();

View File

@ -1256,7 +1256,7 @@ FxExpression *FxColorCast::Resolve(FCompileContext &ctx)
}
else
{
FxExpression *x = new FxConstant(V_GetColor(nullptr, constval.GetString()), ScriptPosition);
FxExpression *x = new FxConstant(V_GetColor(nullptr, constval.GetString(), &ScriptPosition), ScriptPosition);
delete this;
return x;
}

View File

@ -165,7 +165,7 @@ FxExpression *ParseParameter(FScanner &sc, PClassActor *cls, PType *type, bool c
}
else
{
int c = V_GetColor (NULL, sc.String);
int c = V_GetColor (NULL, sc);
// 0 needs to be the default so we have to mark the color.
v = MAKEARGB(1, RPART(c), GPART(c), BPART(c));
}

View File

@ -2305,8 +2305,7 @@ DEFINE_CLASS_PROPERTY_PREFIX(powerup, color, C_f, Inventory)
*pBlendColor = MakeSpecialColormap(65535);
return;
}
color = V_GetColor(NULL, name);
color = V_GetColor(NULL, name, &bag.ScriptPosition);
}
if (PROP_PARM_COUNT > 2)
{

View File

@ -182,7 +182,7 @@ void FTeam::ParseTeamDefinition (FScanner &Scan)
case TEAMINFO_PlayerColor:
Scan.MustGetString ();
Team.m_iPlayerColor = V_GetColor (NULL, Scan.String);
Team.m_iPlayerColor = V_GetColor (NULL, Scan);
break;
case TEAMINFO_TextColor:

View File

@ -1097,7 +1097,7 @@ void FMultiPatchTexture::ParsePatch(FScanner &sc, TexPart & part, TexInit &init)
if (!sc.CheckNumber())
{
sc.MustGetString();
part.Blend = V_GetColor(NULL, sc.String);
part.Blend = V_GetColor(NULL, sc);
}
else
{

View File

@ -2300,19 +2300,19 @@ void V_InitFontColors ()
else if (sc.Compare ("Flat:"))
{
sc.MustGetString();
logcolor = V_GetColor (NULL, sc.String);
logcolor = V_GetColor (NULL, sc);
}
else
{
// Get first color
c = V_GetColor (NULL, sc.String);
c = V_GetColor (NULL, sc);
tparm.Start[0] = RPART(c);
tparm.Start[1] = GPART(c);
tparm.Start[2] = BPART(c);
// Get second color
sc.MustGetString();
c = V_GetColor (NULL, sc.String);
c = V_GetColor (NULL, sc);
tparm.End[0] = RPART(c);
tparm.End[1] = GPART(c);
tparm.End[2] = BPART(c);

View File

@ -44,6 +44,7 @@
#include "i_video.h"
#include "v_video.h"
#include "v_text.h"
#include "sc_man.h"
#include "w_wad.h"
@ -437,7 +438,7 @@ void DCanvas::ReleaseScreenshotBuffer()
//
//==========================================================================
int V_GetColorFromString (const DWORD *palette, const char *cstr)
int V_GetColorFromString (const DWORD *palette, const char *cstr, FScriptPosition *sc)
{
int c[3], i, p;
char val[3];
@ -456,7 +457,7 @@ int V_GetColorFromString (const DWORD *palette, const char *cstr)
{
val[0] = cstr[1 + i*2];
val[1] = cstr[2 + i*2];
c[i] = ParseHex (val);
c[i] = ParseHex (val, sc);
}
}
else if (len == 4)
@ -465,7 +466,7 @@ int V_GetColorFromString (const DWORD *palette, const char *cstr)
for (i = 0; i < 3; ++i)
{
val[1] = val[0] = cstr[1 + i];
c[i] = ParseHex (val);
c[i] = ParseHex (val, sc);
}
}
else
@ -518,7 +519,7 @@ normal:
{
val[1] = val[0];
}
c[i] = ParseHex (val);
c[i] = ParseHex (val, sc);
}
}
}
@ -538,7 +539,7 @@ normal:
//
//==========================================================================
FString V_GetColorStringByName (const char *name)
FString V_GetColorStringByName (const char *name, FScriptPosition *sc)
{
FMemLump rgbNames;
char *rgbEnd;
@ -552,7 +553,8 @@ FString V_GetColorStringByName (const char *name)
rgblump = Wads.CheckNumForName ("X11R6RGB");
if (rgblump == -1)
{
Printf ("X11R6RGB lump not found\n");
if (!sc) Printf ("X11R6RGB lump not found\n");
else sc->Message(MSG_WARNING, "X11R6RGB lump not found");
return FString();
}
@ -614,7 +616,8 @@ FString V_GetColorStringByName (const char *name)
}
if (rgb < rgbEnd)
{
Printf ("X11R6RGB lump is corrupt\n");
if (!sc) Printf ("X11R6RGB lump is corrupt\n");
else sc->Message(MSG_WARNING, "X11R6RGB lump is corrupt");
}
return FString();
}
@ -627,22 +630,28 @@ FString V_GetColorStringByName (const char *name)
//
//==========================================================================
int V_GetColor (const DWORD *palette, const char *str)
int V_GetColor (const DWORD *palette, const char *str, FScriptPosition *sc)
{
FString string = V_GetColorStringByName (str);
FString string = V_GetColorStringByName (str, sc);
int res;
if (!string.IsEmpty())
{
res = V_GetColorFromString (palette, string);
res = V_GetColorFromString (palette, string, sc);
}
else
{
res = V_GetColorFromString (palette, str);
res = V_GetColorFromString (palette, str, sc);
}
return res;
}
int V_GetColor(const DWORD *palette, FScanner &sc)
{
FScriptPosition scc = sc;
return V_GetColor(palette, sc.String, &scc);
}
//==========================================================================
//
// BuildTransTable

View File

@ -497,15 +497,17 @@ void V_Shutdown ();
void V_MarkRect (int x, int y, int width, int height);
class FScanner;
// Returns the closest color to the one desired. String
// should be of the form "rr gg bb".
int V_GetColorFromString (const DWORD *palette, const char *colorstring);
int V_GetColorFromString (const DWORD *palette, const char *colorstring, FScriptPosition *sc = nullptr);
// Scans through the X11R6RGB lump for a matching color
// and returns a color string suitable for V_GetColorFromString.
FString V_GetColorStringByName (const char *name);
FString V_GetColorStringByName (const char *name, FScriptPosition *sc = nullptr);
// Tries to get color by name, then by string
int V_GetColor (const DWORD *palette, const char *str);
int V_GetColor (const DWORD *palette, const char *str, FScriptPosition *sc = nullptr);
int V_GetColor(const DWORD *palette, FScanner &sc);
void V_DrawFrame (int left, int top, int width, int height);
// If the view size is not full screen, draws a border around it.