- streamlined font handling for scripts a bit.

- moved the two 'you raised the alarm' messages for Strife to the string table
This commit is contained in:
Christoph Oelckers 2017-02-05 13:14:22 +01:00
parent 5cfac78116
commit b570d0819b
14 changed files with 144 additions and 35 deletions

View file

@ -1752,11 +1752,10 @@ void C_MidPrintBold (FFont *font, const char *msg)
DEFINE_ACTION_FUNCTION(_Console, MidPrint) DEFINE_ACTION_FUNCTION(_Console, MidPrint)
{ {
PARAM_PROLOGUE; PARAM_PROLOGUE;
PARAM_STRING(font); PARAM_POINTER_NOT_NULL(fnt, FFont);
PARAM_STRING(text); PARAM_STRING(text);
PARAM_BOOL_DEF(bold); PARAM_BOOL_DEF(bold);
FFont *fnt = FFont::FindFont(font);
const char *txt = text[0] == '$'? GStrings(&text[1]) : text.GetChars(); const char *txt = text[0] == '$'? GStrings(&text[1]) : text.GetChars();
if (!bold) C_MidPrint(fnt, txt); if (!bold) C_MidPrint(fnt, txt);
else C_MidPrintBold(fnt, txt); else C_MidPrintBold(fnt, txt);

View file

@ -2467,6 +2467,9 @@ void D_DoomMain (void)
TexMan.Init(); TexMan.Init();
C_InitConback(); C_InitConback();
StartScreen->Progress();
V_InitFonts();
// [CW] Parse any TEAMINFO lumps. // [CW] Parse any TEAMINFO lumps.
if (!batchrun) Printf ("ParseTeamInfo: Load team definitions.\n"); if (!batchrun) Printf ("ParseTeamInfo: Load team definitions.\n");
TeamLibrary.ParseTeamInfo (); TeamLibrary.ParseTeamInfo ();

View file

@ -88,6 +88,7 @@ PColor *TypeColor;
PTextureID *TypeTextureID; PTextureID *TypeTextureID;
PSpriteID *TypeSpriteID; PSpriteID *TypeSpriteID;
PStatePointer *TypeState; PStatePointer *TypeState;
PPointer *TypeFont;
PStateLabel *TypeStateLabel; PStateLabel *TypeStateLabel;
PStruct *TypeVector2; PStruct *TypeVector2;
PStruct *TypeVector3; PStruct *TypeVector3;
@ -437,6 +438,7 @@ void PType::StaticInit()
TypeVoidPtr = NewPointer(TypeVoid, false); TypeVoidPtr = NewPointer(TypeVoid, false);
TypeColorStruct = NewStruct("@ColorStruct", nullptr); //This name is intentionally obfuscated so that it cannot be used explicitly. The point of this type is to gain access to the single channels of a color value. TypeColorStruct = NewStruct("@ColorStruct", nullptr); //This name is intentionally obfuscated so that it cannot be used explicitly. The point of this type is to gain access to the single channels of a color value.
TypeStringStruct = NewNativeStruct("Stringstruct", nullptr); TypeStringStruct = NewNativeStruct("Stringstruct", nullptr);
TypeFont = NewPointer(NewNativeStruct("Font", nullptr));
#ifdef __BIG_ENDIAN__ #ifdef __BIG_ENDIAN__
TypeColorStruct->AddField(NAME_a, TypeUInt8); TypeColorStruct->AddField(NAME_a, TypeUInt8);
TypeColorStruct->AddField(NAME_r, TypeUInt8); TypeColorStruct->AddField(NAME_r, TypeUInt8);

View file

@ -940,6 +940,7 @@ extern PStruct *TypeVector3;
extern PStruct *TypeColorStruct; extern PStruct *TypeColorStruct;
extern PStruct *TypeStringStruct; extern PStruct *TypeStringStruct;
extern PStatePointer *TypeState; extern PStatePointer *TypeState;
extern PPointer *TypeFont;
extern PStateLabel *TypeStateLabel; extern PStateLabel *TypeStateLabel;
extern PPointer *TypeNullPtr; extern PPointer *TypeNullPtr;
extern PPointer *TypeVoidPtr; extern PPointer *TypeVoidPtr;

View file

@ -337,8 +337,6 @@ void R_Init ()
{ {
atterm (R_Shutdown); atterm (R_Shutdown);
StartScreen->Progress();
V_InitFonts();
StartScreen->Progress(); StartScreen->Progress();
// Colormap init moved back to InitPalette() // Colormap init moved back to InitPalette()
//R_InitColormaps (); //R_InitColormaps ();

View file

@ -1420,6 +1420,76 @@ ExpEmit FxSoundCast::Emit(VMFunctionBuilder *build)
return to; return to;
} }
//==========================================================================
//
//
//
//==========================================================================
FxFontCast::FxFontCast(FxExpression *x)
: FxExpression(EFX_FontCast, x->ScriptPosition)
{
basex = x;
ValueType = TypeSound;
}
//==========================================================================
//
//
//
//==========================================================================
FxFontCast::~FxFontCast()
{
SAFE_DELETE(basex);
}
//==========================================================================
//
//
//
//==========================================================================
FxExpression *FxFontCast::Resolve(FCompileContext &ctx)
{
CHECKRESOLVED();
SAFE_RESOLVE(basex, ctx);
if (basex->ValueType == TypeFont)
{
FxExpression *x = basex;
basex = nullptr;
delete this;
return x;
}
// This intentionally does not convert non-constants.
// The sole reason for this cast is to allow passing both font pointers and string constants to printing functions and have the font names checked at compile time.
else if ((basex->ValueType == TypeString || basex->ValueType == TypeName) && basex->isConstant())
{
ExpVal constval = static_cast<FxConstant *>(basex)->GetValue();
FFont *font = V_GetFont(constval.GetString());
// Font must exist. Most internal functions working with fonts do not like null pointers.
// If checking is needed scripts will have to call Font.GetFont themselves.
if (font == nullptr)
{
ScriptPosition.Message(MSG_ERROR, "Unknown font '%s'", constval.GetString().GetChars());
delete this;
return nullptr;
}
FxExpression *x = new FxConstant(font, ScriptPosition);
delete this;
return x;
}
else
{
ScriptPosition.Message(MSG_ERROR, "Cannot convert to font");
delete this;
return nullptr;
}
}
//========================================================================== //==========================================================================
// //
// generic type cast operator // generic type cast operator
@ -1649,6 +1719,14 @@ FxExpression *FxTypeCast::Resolve(FCompileContext &ctx)
{ {
goto basereturn; goto basereturn;
} }
else if (ValueType == TypeFont)
{
FxExpression *x = new FxFontCast(basex);
x = x->Resolve(ctx);
basex = nullptr;
delete this;
return x;
}
// todo: pointers to class objects. // todo: pointers to class objects.
// All other types are only compatible to themselves and have already been handled above by the equality check. // All other types are only compatible to themselves and have already been handled above by the equality check.
// Anything that falls through here is not compatible and must print an error. // Anything that falls through here is not compatible and must print an error.

View file

@ -294,6 +294,7 @@ enum EFxType
EFX_StrLen, EFX_StrLen,
EFX_ColorLiteral, EFX_ColorLiteral,
EFX_GetDefaultByType, EFX_GetDefaultByType,
EFX_FontCast,
EFX_COUNT EFX_COUNT
}; };
@ -488,6 +489,13 @@ public:
isresolved = true; isresolved = true;
} }
FxConstant(FFont *state, const FScriptPosition &pos) : FxExpression(EFX_Constant, pos)
{
value.pointer = state;
ValueType = value.Type = TypeFont;
isresolved = true;
}
FxConstant(const FScriptPosition &pos) : FxExpression(EFX_Constant, pos) FxConstant(const FScriptPosition &pos) : FxExpression(EFX_Constant, pos)
{ {
value.pointer = nullptr; value.pointer = nullptr;
@ -664,6 +672,18 @@ public:
ExpEmit Emit(VMFunctionBuilder *build); ExpEmit Emit(VMFunctionBuilder *build);
}; };
class FxFontCast : public FxExpression
{
FxExpression *basex;
public:
FxFontCast(FxExpression *x);
~FxFontCast();
FxExpression *Resolve(FCompileContext&);
};
//========================================================================== //==========================================================================
// //
// FxTypeCast // FxTypeCast

View file

@ -2187,13 +2187,13 @@ template<> FSerializer &Serialize(FSerializer &arc, const char *key, FFont *&fon
{ {
if (arc.isWriting()) if (arc.isWriting())
{ {
const char *n = font->GetName(); FName n = font->GetName();
return arc.StringPtr(key, n); return arc(key, n);
} }
else else
{ {
const char *n; FName n;
arc.StringPtr(key, n); arc(key, n);
font = V_GetFont(n); font = V_GetFont(n);
if (font == nullptr) if (font == nullptr)
{ {

View file

@ -340,6 +340,14 @@ FFont *V_GetFont(const char *name)
return font; return font;
} }
DEFINE_ACTION_FUNCTION(FFont, GetFont)
{
PARAM_PROLOGUE;
PARAM_NAME(name);
ACTION_RETURN_POINTER(V_GetFont(name.GetChars()));
}
//========================================================================== //==========================================================================
// //
// FFont :: FFont // FFont :: FFont
@ -366,7 +374,7 @@ FFont::FFont (const char *name, const char *nametemplate, int first, int count,
LastChar = first + count - 1; LastChar = first + count - 1;
FontHeight = 0; FontHeight = 0;
GlobalKerning = false; GlobalKerning = false;
Name = copystring (name); FontName = name;
Next = FirstFont; Next = FirstFont;
FirstFont = this; FirstFont = this;
Cursor = '_'; Cursor = '_';
@ -478,11 +486,6 @@ FFont::~FFont ()
delete[] PatchRemap; delete[] PatchRemap;
PatchRemap = NULL; PatchRemap = NULL;
} }
if (Name)
{
delete[] Name;
Name = NULL;
}
FFont **prev = &FirstFont; FFont **prev = &FirstFont;
FFont *font = *prev; FFont *font = *prev;
@ -508,27 +511,26 @@ FFont::~FFont ()
// //
//========================================================================== //==========================================================================
FFont *FFont::FindFont (const char *name) FFont *FFont::FindFont (FName name)
{ {
if (name == NULL) if (name == NAME_None)
{ {
return NULL; return nullptr;
} }
FFont *font = FirstFont; FFont *font = FirstFont;
while (font != NULL) while (font != nullptr)
{ {
if (stricmp (font->Name, name) == 0) if (font->FontName == name) return font;
break;
font = font->Next; font = font->Next;
} }
return font; return nullptr;
} }
DEFINE_ACTION_FUNCTION(FFont, FindFont) DEFINE_ACTION_FUNCTION(FFont, FindFont)
{ {
PARAM_PROLOGUE; PARAM_PROLOGUE;
PARAM_STRING(name); PARAM_NAME(name);
ACTION_RETURN_POINTER(FFont::FindFont(name)); ACTION_RETURN_POINTER(FFont::FindFont(name));
} }
@ -935,7 +937,7 @@ FFont::FFont (int lump)
Lump = lump; Lump = lump;
Chars = NULL; Chars = NULL;
PatchRemap = NULL; PatchRemap = NULL;
Name = NULL; FontName = NAME_None;
Cursor = '_'; Cursor = '_';
} }
@ -951,7 +953,7 @@ FSingleLumpFont::FSingleLumpFont (const char *name, int lump) : FFont(lump)
{ {
assert(lump >= 0); assert(lump >= 0);
Name = copystring (name); FontName = name;
FMemLump data1 = Wads.ReadLump (lump); FMemLump data1 = Wads.ReadLump (lump);
const BYTE *data = (const BYTE *)data1.GetMem(); const BYTE *data = (const BYTE *)data1.GetMem();
@ -1189,7 +1191,7 @@ void FSingleLumpFont::LoadFON2 (int lump, const BYTE *data)
if (destSize < 0) if (destSize < 0)
{ {
i += FirstChar; i += FirstChar;
I_FatalError ("Overflow decompressing char %d (%c) of %s", i, i, Name); I_FatalError ("Overflow decompressing char %d (%c) of %s", i, i, FontName.GetChars());
} }
} }
@ -1491,7 +1493,7 @@ FSinglePicFont::FSinglePicFont(const char *picname) :
FTexture *pic = TexMan[picnum]; FTexture *pic = TexMan[picnum];
Name = copystring(picname); FontName = picname;
FontHeight = pic->GetScaledHeight(); FontHeight = pic->GetScaledHeight();
SpaceWidth = pic->GetScaledWidth(); SpaceWidth = pic->GetScaledWidth();
GlobalKerning = 0; GlobalKerning = 0;
@ -1903,7 +1905,7 @@ FSpecialFont::FSpecialFont (const char *name, int first, int count, FTexture **l
memcpy(this->notranslate, notranslate, 256*sizeof(bool)); memcpy(this->notranslate, notranslate, 256*sizeof(bool));
Name = copystring(name); FontName = name;
Chars = new CharData[count]; Chars = new CharData[count];
charlumps = new FTexture*[count]; charlumps = new FTexture*[count];
PatchRemap = new BYTE[256]; PatchRemap = new BYTE[256];

View file

@ -88,9 +88,9 @@ public:
int GetDefaultKerning () const { return GlobalKerning; } int GetDefaultKerning () const { return GlobalKerning; }
virtual void LoadTranslations(); virtual void LoadTranslations();
void Preload() const; void Preload() const;
const char *GetName() const { return Name; } FName GetName() const { return FontName; }
static FFont *FindFont (const char *fontname); static FFont *FindFont(FName fontname);
static void StaticPreloadFonts(); static void StaticPreloadFonts();
// Return width of string in pixels (unscaled) // Return width of string in pixels (unscaled)
@ -127,7 +127,7 @@ protected:
BYTE *PatchRemap; BYTE *PatchRemap;
int Lump; int Lump;
char *Name; FName FontName;
FFont *Next; FFont *Next;
static FFont *FirstFont; static FFont *FirstFont;

View file

@ -1417,6 +1417,9 @@ TXT_KILLED_ORACLE = "You've Killed The Oracle!";
TXT_KILLED_MACIL = "You Killed Macil!"; TXT_KILLED_MACIL = "You Killed Macil!";
TXT_KILLED_LOREMASTER = "You've Killed the Loremaster!"; TXT_KILLED_LOREMASTER = "You've Killed the Loremaster!";
TXT_YOUFOOL = "You Fool! You've set off the alarm.";
TXT_YOUREDEAD = "You're dead! You set off the alarm.";
// Strife pickup messages // Strife pickup messages
TXT_METALARMOR = "You picked up the Metal Armor."; TXT_METALARMOR = "You picked up the Metal Armor.";

View file

@ -70,13 +70,14 @@ struct Screen native
struct Font native struct Font native
{ {
native static Font FindFont(String name); native static Font FindFont(Name fontname);
native static Font GetFont(Name fontname);
} }
struct Console native struct Console native
{ {
native static void HideConsole(); native static void HideConsole();
native static void MidPrint(string fontname, string textlabel, bool bold = false); // always uses the stringtable. native static void MidPrint(Font fontname, string textlabel, bool bold = false);
} }
struct DamageTypeDefinition native struct DamageTypeDefinition native

View file

@ -9,7 +9,9 @@ extend class Object
deprecated static void C_MidPrint(string fontname, string textlabel, bool bold = false) // deprecated for 2.4.x deprecated static void C_MidPrint(string fontname, string textlabel, bool bold = false) // deprecated for 2.4.x
{ {
return Console.MidPrint(fontname, textlabel, bold); let f = Font.GetFont(fontname);
if (f == null) return;
return Console.MidPrint(f, textlabel, bold);
} }
} }

View file

@ -632,7 +632,7 @@ class RaiseAlarm : DummyStrifeItem
dropper.target.SoundAlert(dropper.target); dropper.target.SoundAlert(dropper.target);
if (dropper.target.CheckLocalView(consoleplayer)) if (dropper.target.CheckLocalView(consoleplayer))
{ {
A_Log("You Fool! You've set off the alarm."); Console.MidPrint(SmallFont, "$TXT_YOUFOOL");
} }
} }
Destroy (); Destroy ();
@ -672,7 +672,7 @@ class CloseDoor222 : DummyStrifeItem
{ {
if (dropper.target.CheckLocalView(consoleplayer)) if (dropper.target.CheckLocalView(consoleplayer))
{ {
A_Log("You're dead! You set off the alarm."); Console.MidPrint(SmallFont, "$TXT_YOUREDEAD");
} }
dropper.target.SoundAlert(dropper.target); dropper.target.SoundAlert(dropper.target);
} }