diff --git a/src/font.c b/src/font.c new file mode 100644 index 000000000..7207def62 --- /dev/null +++ b/src/font.c @@ -0,0 +1,76 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 1999-2018 by Sonic Team Junior. +// Copyright (C) 2019 by Kart Krew. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file font.c +/// \brief Font setup + +#include "doomdef.h" +#include "hu_stuff.h" +#include "font.h" + +font_t fontv[MAX_FONTS]; +int fontc; + +static void +FontCache (font_t *fnt) +{ + int i; + int c; + + c = fnt->start; + for (i = 0; i < fnt->size; ++i, ++c) + { + fnt->font[i] = HU_CachePatch( + "%s%.*d", + fnt->digits, + fnt->prefix, + c); + } +} + +void +Font_Load (void) +{ + int i; + for (i = 0; i < fontc; ++i) + { + FontCache(&fontv[i]); + } +} + +int +Font_DumbRegister (const font_t *sfnt) +{ + font_t *fnt; + + if (fontc == MAX_FONTS) + return -1; + + fnt = &fontv[fontc]; + + if (!( fnt->font = ZZ_Alloc(sfnt->size * sizeof (patch_t *)) )) + return -1; + + memcpy(fnt, sfnt, sizeof (font_t)); + + return fontc++; +} + +int +Font_Register (const font_t *sfnt) +{ + int d; + + d = Font_DumbRegister(sfnt); + + if (d >= 0) + FontCache(&fontv[d]); + + return d; +} diff --git a/src/font.h b/src/font.h new file mode 100644 index 000000000..c2ef5cf34 --- /dev/null +++ b/src/font.h @@ -0,0 +1,49 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 1999-2018 by Sonic Team Junior. +// Copyright (C) 2019 by Kart Krew. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file font.h +/// \brief Font setup + +#ifndef __FONT_H_ +#define __FONT_H__ + +#define MAX_FONTS 32 + +typedef struct font font_t; + +struct font +{ + patch_t **font; + + UINT8 start; + UINT8 size; + + char prefix[8];/* 7 used at most */ + unsigned digits : 2; +}; + +extern font_t fontv[MAX_FONTS]; +extern int fontc; + +/* +Reloads already registered fonts. +*/ +void Font_Load (void); + +/* +Registers and loads a new font. +*/ +int Font_Register (const font_t *); + +/* +Register a new font, but do not load it yet. +*/ +int Font_DumbRegister (const font_t *); + +#endif