From 7b31572d05443534d8b4eafa606fe7261f81b63e Mon Sep 17 00:00:00 2001 From: "Azamat H. Hackimov" Date: Sun, 28 Jul 2024 00:50:49 +0300 Subject: [PATCH] Isolate grtext submodule Isolate grtext from rest of the project, minor cleanups. --- grtext/CMakeLists.txt | 11 +++++-- grtext/grfont.cpp | 43 ++++++++++++++-------------- grtext/grtext.cpp | 27 +++++++---------- {lib => grtext}/grtext.h | 5 ++-- grtext/grtextlib.h | 3 +- grtext/textaux.cpp | 14 ++++----- netgames/anarchy/CMakeLists.txt | 1 - netgames/coop/CMakeLists.txt | 1 - netgames/ctf/CMakeLists.txt | 1 - netgames/dmfc/CMakeLists.txt | 3 +- netgames/entropy/CMakeLists.txt | 1 - netgames/hoard/CMakeLists.txt | 1 - netgames/hyperanarchy/CMakeLists.txt | 1 - netgames/monsterball/CMakeLists.txt | 1 - netgames/roboanarchy/CMakeLists.txt | 1 - netgames/tanarchy/CMakeLists.txt | 1 - ui/CMakeLists.txt | 1 + 17 files changed, 55 insertions(+), 61 deletions(-) rename {lib => grtext}/grtext.h (99%) diff --git a/grtext/CMakeLists.txt b/grtext/CMakeLists.txt index 30e606e4..1d29a9f0 100644 --- a/grtext/CMakeLists.txt +++ b/grtext/CMakeLists.txt @@ -1,12 +1,17 @@ -set(HEADERS grtextlib.h) set(CPPS grfont.cpp grtext.cpp - textaux.cpp) + textaux.cpp +) -add_library(grtext STATIC ${HEADERS} ${CPPS}) +add_library(grtext STATIC ${CPPS}) target_link_libraries(grtext PRIVATE ddio mem misc ) +target_include_directories(grtext PUBLIC + $ +) diff --git a/grtext/grfont.cpp b/grtext/grfont.cpp index a4ed9d5c..e425991f 100644 --- a/grtext/grfont.cpp +++ b/grtext/grfont.cpp @@ -107,18 +107,18 @@ * $NoKeywords: $ */ -#include "grtextlib.h" -#include "cfile.h" +#include +#include +#include +#include + #include "bitmap.h" +#include "cfile.h" +#include "ddio.h" +#include "grtextlib.h" +#include "mem.h" #include "pserror.h" #include "renderer.h" -#include "mem.h" -#include "ddio.h" - -#include -#include -#include -#include const int MAX_FONTS = 16, MAX_FONT_BITMAPS = 32; @@ -185,7 +185,7 @@ inline FONTFILE OPEN_FONT(const char *filename) { fp = (FONTFILE)cfopen(filename, "rb"); if (!fp) - return NULL; + return nullptr; file_id = READ_FONT_INT(fp); if (file_id != 0xfeedbaba) @@ -225,7 +225,7 @@ inline FONTFILE2 OPEN_FONT2(const char *filename) { fp = (FONTFILE2)fopen(filename, "wb"); if (!fp) - return NULL; + return nullptr; return fp; } @@ -333,9 +333,8 @@ int grfont_Load(const char *fname) { fnt.char_widths = (uint8_t *)mem_malloc(sizeof(uint8_t) * num_char); for (i = 0; i < num_char; i++) fnt.char_widths[i] = (uint8_t)READ_FONT_SHORT(ff); - // mprintf(0, "::proportional"); } else { - fnt.char_widths = NULL; + fnt.char_widths = nullptr; } // Read in kerning data @@ -351,7 +350,7 @@ int grfont_Load(const char *fname) { fnt.kern_data[i * 3 + 1] = 255; fnt.kern_data[i * 3 + 2] = 0; } else { - fnt.kern_data = NULL; + fnt.kern_data = nullptr; } // Read in pixel data. @@ -490,7 +489,7 @@ bool grfont_LoadTemplate(const char *fname, tFontTemplate *ft) { for (i = 0; i < num_char; i++) ft->ch_widths[i] = (uint8_t)READ_FONT_SHORT(ff); } else { - ft->ch_widths = NULL; + ft->ch_widths = nullptr; } if (ft_flags & FT_KERNED) { @@ -529,11 +528,11 @@ bool grfont_LoadTemplate(const char *fname, tFontTemplate *ft) { void grfont_FreeTemplate(tFontTemplate *ft) { if (ft->kern_data) { mem_free(ft->kern_data); - ft->kern_data = NULL; + ft->kern_data = nullptr; } if (ft->ch_widths) { mem_free(ft->ch_widths); - ft->ch_widths = NULL; + ft->ch_widths = nullptr; } } @@ -582,7 +581,7 @@ bool grfont_SetTemplate(const char *pathname, const tFontTemplate *ft) { for (i = 0; i < num_char; i++) fnt.char_widths[i] = (uint8_t)READ_FONT_SHORT(ffin); } else { - fnt.char_widths = NULL; + fnt.char_widths = nullptr; } // Read in kerning data @@ -598,7 +597,7 @@ bool grfont_SetTemplate(const char *pathname, const tFontTemplate *ft) { fnt.kern_data[i * 3 + 1] = 255; fnt.kern_data[i * 3 + 2] = 0; } else { - fnt.kern_data = NULL; + fnt.kern_data = nullptr; } // Read in pixel data. @@ -655,7 +654,7 @@ bool grfont_SetTemplate(const char *pathname, const tFontTemplate *ft) { // Write widths now if necessary.(FT_PROPORTIONAL) if (fnt.flags & FT_PROPORTIONAL) { - for (int i = 0; i < num_char; i++) + for (i = 0; i < num_char; i++) WRITE_FONT_SHORT(ffout, (int16_t)fnt.char_widths[i]); } @@ -698,7 +697,7 @@ bool grfont_SetKerning(int font, uint8_t *kern_data) { // reset kerning... if (oldft->font.kern_data) { mem_free(oldft->font.kern_data); - oldft->font.kern_data = NULL; + oldft->font.kern_data = nullptr; } if (kern_data) { @@ -1087,7 +1086,7 @@ uint16_t *grfont_GetRawCharacterData(int font, int ch, int *w, int *h, bool *mon } if ((ch < fnt->font.min_ascii) || (ch > fnt->font.max_ascii)) - return NULL; + return nullptr; ch = ch - fnt->font.min_ascii; *mono = !(fnt->font.flags & FT_COLOR); diff --git a/grtext/grtext.cpp b/grtext/grtext.cpp index bcc8de0d..acb49c25 100644 --- a/grtext/grtext.cpp +++ b/grtext/grtext.cpp @@ -148,16 +148,12 @@ #include #include +#include +#include #include "grtextlib.h" - -#include "renderer.h" #include "pserror.h" -#include "mem.h" - -#include -#include -#include +#include "renderer.h" #define CLIP_LEFT Grtext_left #define CLIP_TOP Grtext_top @@ -222,12 +218,12 @@ static bool grtext_FilterProfanity = false; void grtext_SetProfanityFilter(bool enabled) { grtext_FilterProfanity = enabled; } // Right now this just decrypts the bad words -void grtext_Init(void) { - for (int i = 0; i < NUM_BAD_WORDS; i++) { +void grtext_Init() { + for (auto & bad_word : bad_words) { int pos = 0; - while (bad_words[i][pos]) { - bad_words[i][pos] = bad_words[i][pos] ^ XORVAL; + while (bad_word[pos]) { + bad_word[pos] = bad_word[pos] ^ XORVAL; pos++; } } @@ -340,7 +336,6 @@ void grtext_SetFontScale(float scale) { void grtext_SetFancyColor(ddgr_color col1, ddgr_color col2, ddgr_color col3, ddgr_color col4) { struct { char op; - // ddgr_color col[4]; ddgr_color col; } cmd; @@ -478,10 +473,10 @@ void grtext_Puts(int x, int y, const char *str) { lowerstr[slen] = '\0'; - for (int i = 0; i < NUM_BAD_WORDS; i++) { - char *p = strstr(lowerstr, (char *)bad_words[i]); + for (auto & bad_word : bad_words) { + char *p = strstr(lowerstr, (char *)bad_word); while (p) { - int len = strlen((char *)bad_words[i]); + int len = strlen((char *)bad_word); char *realp = (char *)((int)(p - lowerstr) + &Grtext_buffer[Grtext_ptr]); for (int a = 0; a < len; a++) { ASSERT(p); @@ -489,7 +484,7 @@ void grtext_Puts(int x, int y, const char *str) { *p = *realp; realp++; } - p = strstr(lowerstr, (char *)bad_words[i]); + p = strstr(lowerstr, (char *)bad_word); }; } // DAJ mem_free(lowerstr); diff --git a/lib/grtext.h b/grtext/grtext.h similarity index 99% rename from lib/grtext.h rename to grtext/grtext.h index 03030016..350baf26 100644 --- a/lib/grtext.h +++ b/grtext/grtext.h @@ -108,7 +108,8 @@ #ifndef GRTEXT_H #define GRTEXT_H -#include "pstypes.h" +#include + #include "ddvid.h" #define GRTEXT_BUFLEN 16384 @@ -282,7 +283,7 @@ int grfont_GetTracking(int font); ///////////////////////////////////////////////////////////////////// // Init functions -- call before anything is rendered! -void grtext_Init(void); +void grtext_Init(); #ifndef RELEASE void grfont_Spew(int font, int x, int y); diff --git a/grtext/grtextlib.h b/grtext/grtextlib.h index c3d3a7c5..1d6c3346 100644 --- a/grtext/grtextlib.h +++ b/grtext/grtextlib.h @@ -38,8 +38,9 @@ #ifndef GRTEXTLIB_H #define GRTEXTLIB_H +#include + #include "grtext.h" -#include "pstypes.h" struct tCharBlt { uint16_t ch; diff --git a/grtext/textaux.cpp b/grtext/textaux.cpp index 8c41ae47..2305c4e8 100644 --- a/grtext/textaux.cpp +++ b/grtext/textaux.cpp @@ -49,10 +49,10 @@ * $NoKeywords: $ */ +#include +#include + #include "grtext.h" -#include -#include -#include // textaux_WordWrap // @@ -127,14 +127,14 @@ const char *textaux_CopyTextLine(const char *src, char *dest) { if (!src) { if (dest) dest[0] = '\0'; - return NULL; + return nullptr; } if (!dest) - return NULL; + return nullptr; // see if we are at the end of the src if (src[0] == '\0') { dest[0] = '\0'; - return NULL; + return nullptr; } int i; i = 0; @@ -145,7 +145,7 @@ const char *textaux_CopyTextLine(const char *src, char *dest) { // no more lines left after this strncpy(dest, src, i); dest[i] = '\0'; - return NULL; + return nullptr; } else { // we hit a newline char strncpy(dest, src, i); diff --git a/netgames/anarchy/CMakeLists.txt b/netgames/anarchy/CMakeLists.txt index 27662cee..7783b4ca 100644 --- a/netgames/anarchy/CMakeLists.txt +++ b/netgames/anarchy/CMakeLists.txt @@ -10,6 +10,5 @@ set_target_properties(${NETGAME_MODULE} PROPERTIES SUFFIX ".d3m") target_link_libraries(${NETGAME_MODULE} PRIVATE dmfc - misc ) install(TARGETS "${NETGAME_MODULE}" DESTINATION ${CMAKE_INSTALL_LIBDIR}/netgames) diff --git a/netgames/coop/CMakeLists.txt b/netgames/coop/CMakeLists.txt index a4f73fa8..41a39113 100644 --- a/netgames/coop/CMakeLists.txt +++ b/netgames/coop/CMakeLists.txt @@ -10,6 +10,5 @@ set_target_properties(${NETGAME_MODULE} PROPERTIES SUFFIX ".d3m") target_link_libraries(${NETGAME_MODULE} PRIVATE dmfc - misc ) install(TARGETS "${NETGAME_MODULE}" DESTINATION ${CMAKE_INSTALL_LIBDIR}/netgames) diff --git a/netgames/ctf/CMakeLists.txt b/netgames/ctf/CMakeLists.txt index 49b3c661..211cd7a7 100644 --- a/netgames/ctf/CMakeLists.txt +++ b/netgames/ctf/CMakeLists.txt @@ -10,6 +10,5 @@ set_target_properties(${NETGAME_MODULE} PROPERTIES SUFFIX ".d3m") target_link_libraries(${NETGAME_MODULE} PRIVATE dmfc - misc ) install(TARGETS "${NETGAME_MODULE}" DESTINATION ${CMAKE_INSTALL_LIBDIR}/netgames) diff --git a/netgames/dmfc/CMakeLists.txt b/netgames/dmfc/CMakeLists.txt index 58fe9939..8cd59ac6 100644 --- a/netgames/dmfc/CMakeLists.txt +++ b/netgames/dmfc/CMakeLists.txt @@ -27,6 +27,7 @@ set(CPPS add_definitions(-DOUTRAGE_VERSION) add_library(dmfc STATIC ${HEADERS} ${CPPS}) -target_link_libraries(dmfc PRIVATE +target_link_libraries(dmfc PUBLIC + grtext misc ) diff --git a/netgames/entropy/CMakeLists.txt b/netgames/entropy/CMakeLists.txt index 60509a94..ce4f7481 100644 --- a/netgames/entropy/CMakeLists.txt +++ b/netgames/entropy/CMakeLists.txt @@ -10,6 +10,5 @@ set_target_properties(${NETGAME_MODULE} PROPERTIES SUFFIX ".d3m") target_link_libraries(${NETGAME_MODULE} PRIVATE dmfc - misc ) install(TARGETS "${NETGAME_MODULE}" DESTINATION ${CMAKE_INSTALL_LIBDIR}/netgames) diff --git a/netgames/hoard/CMakeLists.txt b/netgames/hoard/CMakeLists.txt index a5938837..e5b5c779 100644 --- a/netgames/hoard/CMakeLists.txt +++ b/netgames/hoard/CMakeLists.txt @@ -10,6 +10,5 @@ set_target_properties(${NETGAME_MODULE} PROPERTIES SUFFIX ".d3m") target_link_libraries(${NETGAME_MODULE} PRIVATE dmfc - misc ) install(TARGETS "${NETGAME_MODULE}" DESTINATION ${CMAKE_INSTALL_LIBDIR}/netgames) diff --git a/netgames/hyperanarchy/CMakeLists.txt b/netgames/hyperanarchy/CMakeLists.txt index 4d773c19..4364cd7b 100644 --- a/netgames/hyperanarchy/CMakeLists.txt +++ b/netgames/hyperanarchy/CMakeLists.txt @@ -10,6 +10,5 @@ set_target_properties(${NETGAME_MODULE} PROPERTIES SUFFIX ".d3m") target_link_libraries(${NETGAME_MODULE} PRIVATE dmfc - misc ) install(TARGETS "${NETGAME_MODULE}" DESTINATION ${CMAKE_INSTALL_LIBDIR}/netgames) diff --git a/netgames/monsterball/CMakeLists.txt b/netgames/monsterball/CMakeLists.txt index 03781e0b..bfffff2d 100644 --- a/netgames/monsterball/CMakeLists.txt +++ b/netgames/monsterball/CMakeLists.txt @@ -10,6 +10,5 @@ set_target_properties(${NETGAME_MODULE} PROPERTIES SUFFIX ".d3m") target_link_libraries(${NETGAME_MODULE} PRIVATE dmfc - misc ) install(TARGETS "${NETGAME_MODULE}" DESTINATION ${CMAKE_INSTALL_LIBDIR}/netgames) diff --git a/netgames/roboanarchy/CMakeLists.txt b/netgames/roboanarchy/CMakeLists.txt index 5a543e72..aea13703 100644 --- a/netgames/roboanarchy/CMakeLists.txt +++ b/netgames/roboanarchy/CMakeLists.txt @@ -10,6 +10,5 @@ set_target_properties(${NETGAME_MODULE} PROPERTIES SUFFIX ".d3m") target_link_libraries(${NETGAME_MODULE} PRIVATE dmfc - misc ) install(TARGETS "${NETGAME_MODULE}" DESTINATION ${CMAKE_INSTALL_LIBDIR}/netgames) diff --git a/netgames/tanarchy/CMakeLists.txt b/netgames/tanarchy/CMakeLists.txt index 6b2e4af8..1d48e936 100644 --- a/netgames/tanarchy/CMakeLists.txt +++ b/netgames/tanarchy/CMakeLists.txt @@ -10,6 +10,5 @@ set_target_properties(${NETGAME_MODULE} PROPERTIES SUFFIX ".d3m") target_link_libraries(${NETGAME_MODULE} PRIVATE dmfc - misc ) install(TARGETS "${NETGAME_MODULE}" DESTINATION ${CMAKE_INSTALL_LIBDIR}/netgames) diff --git a/ui/CMakeLists.txt b/ui/CMakeLists.txt index 0a53f1d2..7b3cd299 100644 --- a/ui/CMakeLists.txt +++ b/ui/CMakeLists.txt @@ -19,6 +19,7 @@ set(CPPS add_library(ui STATIC ${CPPS}) target_link_libraries(ui PRIVATE ddio + grtext mem misc )