diff --git a/CMakeLists.txt b/CMakeLists.txt index a8402f3d5..8e90061db 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,15 +14,21 @@ project( VERSION 0.1.0 ) +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED True) + string(TIMESTAMP BUILD_TIMESTAMP "%Y.%m.%d" UTC) add_compile_definitions(OBSIDIAN_TIMESTAMP="${BUILD_TIMESTAMP}") - if(CONSOLE_ONLY) - add_compile_definitions(CONSOLE_ONLY=1) + add_compile_definitions(CONSOLE_ONLY) +endif() +if(WIN32) + add_compile_definitions(WIN32_LEAN_AND_MEAN) + add_compile_definitions(UNICODE) + add_compile_definitions(_UNICODE) +elseif(NOT APPLE AND NOT CONSOLE_ONLY) + add_compile_definitions(USE_XFT) endif() - -set(CMAKE_CXX_STANDARD 17) -set(CMAKE_CXX_STANDARD_REQUIRED True) if(MSVC) # get the number of logical cores for parallel build cmake_host_system_information(RESULT LOGICAL_CORES QUERY NUMBER_OF_LOGICAL_CORES) diff --git a/source/bsp.cc b/source/bsp.cc index 98bb162a5..a4e34bba3 100644 --- a/source/bsp.cc +++ b/source/bsp.cc @@ -218,7 +218,7 @@ bool ValidateMapName(char *name) // Ok, convert to upper case for (char *s = name; *s; s++) { - *s = toupper(*s); + *s = ToUpperASCII(*s); } return true; diff --git a/source/bsp_wad.cc b/source/bsp_wad.cc index 03d8c397f..060819499 100644 --- a/source/bsp_wad.cc +++ b/source/bsp_wad.cc @@ -648,7 +648,7 @@ static bool IsDummyMarker(const char *name) if (strlen(name) < 3) return false; - if (!strchr("PSF", toupper(name[0]))) + if (!strchr("PSF", ToUpperASCII(name[0]))) return false; if (!isdigit(name[1])) diff --git a/source/csg_bsp.cc b/source/csg_bsp.cc index a4693741f..13f7df14c 100644 --- a/source/csg_bsp.cc +++ b/source/csg_bsp.cc @@ -28,10 +28,10 @@ #include "hdr_fltk.h" #endif #include "hdr_lua.h" -#include "headers.h" #include "lib_util.h" #include "m_lua.h" #include "main.h" +#include "sys_assert.h" #include "sys_macro.h" double QUANTIZE_GRID; diff --git a/source/csg_doom.cc b/source/csg_doom.cc index 4c2e977bc..bc16d93e6 100644 --- a/source/csg_doom.cc +++ b/source/csg_doom.cc @@ -29,9 +29,9 @@ #include "hdr_fltk.h" #include "hdr_ui.h" // ui_build.h #endif -#include "headers.h" #include "lib_util.h" #include "main.h" +#include "sys_assert.h" #include "sys_macro.h" // Properties @@ -841,8 +841,8 @@ template <> struct hash size_t operator()(const Doom::vertex_map_key_s &k) const { size_t h = 0; - h ^= std::hash()(k.x); - h ^= std::hash()(k.y); + h ^= IntHash(k.x); + h ^= IntHash(k.y); return h; } }; @@ -3168,7 +3168,6 @@ static void WriteFraggleScript() void FreeStuff() { - // This is erroring out right now std::for_each(vertices.begin(), vertices.end(), [](auto *i) { delete i; }); std::for_each(linedefs.begin(), linedefs.end(), [](auto *i) { delete i; }); std::for_each(sidedefs.begin(), sidedefs.end(), [](auto *i) { delete i; }); diff --git a/source/csg_main.cc b/source/csg_main.cc index a3c52f8cf..d4d28c0b9 100644 --- a/source/csg_main.cc +++ b/source/csg_main.cc @@ -28,10 +28,11 @@ #include "hdr_fltk.h" #endif #include "hdr_lua.h" -#include "headers.h" #include "lib_util.h" #include "m_lua.h" #include "main.h" +#include "sys_assert.h" +#include "sys_macro.h" #define EPSILON 0.001 diff --git a/source/csg_shade.cc b/source/csg_shade.cc index 99591b225..99aaecf94 100644 --- a/source/csg_shade.cc +++ b/source/csg_shade.cc @@ -28,10 +28,10 @@ #include "hdr_ui.h" #endif #include "hdr_lua.h" -#include "headers.h" #include "lib_argv.h" #include "lib_util.h" #include "main.h" +#include "sys_macro.h" /* diff --git a/source/csg_spots.cc b/source/csg_spots.cc index 0e43873ec..ae144c945 100644 --- a/source/csg_spots.cc +++ b/source/csg_spots.cc @@ -20,14 +20,11 @@ //---------------------------------------------------------------------- #include "hdr_lua.h" -#include "headers.h" #include "lib_argv.h" #include "lib_util.h" #include "main.h" - -#ifdef WIN32 -#include -#endif +#include "sys_assert.h" +#include "sys_macro.h" #define GRID_SIZE 20 @@ -311,7 +308,7 @@ static void remove_dud_cells() static bool test_mon_area(int x1, int y1, int x2, int y2, int want) { - if (x1 < 0 or x2 >= grid_W or y1 < 0 or y2 >= grid_H) + if (x1 < 0 || x2 >= grid_W || y1 < 0 || y2 >= grid_H) { return false; } diff --git a/source/dm_extra.cc b/source/dm_extra.cc index 73bcd21a5..336f1e796 100644 --- a/source/dm_extra.cc +++ b/source/dm_extra.cc @@ -26,7 +26,6 @@ #include "hdr_ui.h" #endif #include "hdr_lua.h" -#include "headers.h" #include "images.h" #include "lib_tga.h" #include "lib_util.h" @@ -35,6 +34,9 @@ #include "m_lua.h" #include "main.h" #include "physfs.h" +#include "sys_assert.h" +#include "sys_endian.h" +#include "sys_macro.h" #include "tx_forge.h" #include "tx_skies.h" @@ -656,7 +658,7 @@ int fsky_add_hills(lua_State *L) static int FontIndexForChar(char ch) { - ch = toupper(ch); + ch = ToUpperASCII(ch); if (ch == ' ') { diff --git a/source/dm_prefab.cc b/source/dm_prefab.cc index 2e6a4d690..72fd9e579 100644 --- a/source/dm_prefab.cc +++ b/source/dm_prefab.cc @@ -66,12 +66,13 @@ #include "hdr_ui.h" #endif #include "hdr_lua.h" -#include "headers.h" #include "lib_util.h" #include "lib_wad.h" #include "m_lua.h" #include "main.h" #include "physfs.h" +#include "sys_assert.h" +#include "sys_macro.h" // callbacks for AJ-Polygonator diff --git a/source/g_doom.cc b/source/g_doom.cc index 325a0c91f..be8f3b687 100644 --- a/source/g_doom.cc +++ b/source/g_doom.cc @@ -24,8 +24,6 @@ #include #include -#include "headers.h" - #ifndef CONSOLE_ONLY #include "hdr_fltk.h" #endif @@ -35,13 +33,13 @@ #include "lib_zip.h" #include "m_cookie.h" #include "m_lua.h" +#include "m_trans.h" #include "main.h" +#include "sys_assert.h" +#include "sys_endian.h" +#include "sys_macro.h" #include "sys_xoshiro.h" -#ifdef WIN32 -#include -#endif - #include "bsp.h" // SLUMP for Vanilla Doom @@ -445,7 +443,7 @@ static void WriteBehavior() /*raw_behavior_header_t behavior; std::string_view acs{"ACS"}; - std::copy(acs.data(), acs.data() + 4, behavior.marker); + memcpy(behavior.marker, acs.data(), 4); behavior.offset = LE_U32(8); behavior.func_num = 0; @@ -573,7 +571,7 @@ static void FreeLumps() { delete header_lump; header_lump = nullptr; - if (not UDMF_mode) + if (!UDMF_mode) { delete thing_lump; thing_lump = nullptr; @@ -601,7 +599,7 @@ void Doom::BeginLevel() FreeLumps(); header_lump = new qLump_c(); - if (not UDMF_mode) + if (!UDMF_mode) { thing_lump = new qLump_c(); vertex_lump = new qLump_c(); @@ -658,7 +656,7 @@ void Doom::EndLevel(std::string level_name) WriteLump("TEXTMAP", textmap_lump); } - if (not UDMF_mode) + if (!UDMF_mode) { WriteLump("THINGS", thing_lump); WriteLump("LINEDEFS", linedef_lump); @@ -737,7 +735,7 @@ void Doom::AddVertex(int x, int y) y += 32; } - if (not UDMF_mode) + if (!UDMF_mode) { raw_vertex_t vert; @@ -765,15 +763,15 @@ int Doom::v094_add_vertex(lua_State *L) void Doom::AddSector(int f_h, std::string f_tex, int c_h, std::string c_tex, int light, int special, int tag) { - if (not UDMF_mode) + if (!UDMF_mode) { raw_sector_t sec; sec.floor_h = LE_S16(f_h); sec.ceil_h = LE_S16(c_h); - std::copy(f_tex.data(), f_tex.data() + 8, sec.floor_tex); - std::copy(c_tex.data(), c_tex.data() + 8, sec.ceil_tex); + memcpy(sec.floor_tex, f_tex.data(), 8); + memcpy(sec.ceil_tex, c_tex.data(), 8); sec.light = LE_U16(light); sec.special = LE_U16(special); @@ -810,15 +808,15 @@ int Doom::v094_add_sector(lua_State *L) void Doom::AddSidedef(int sector, std::string l_tex, std::string m_tex, std::string u_tex, int x_offset, int y_offset) { - if (not UDMF_mode) + if (!UDMF_mode) { raw_sidedef_t side; side.sector = LE_S16(sector); - std::copy(l_tex.data(), l_tex.data() + 8, side.lower_tex); - std::copy(m_tex.data(), m_tex.data() + 8, side.mid_tex); - std::copy(u_tex.data(), u_tex.data() + 8, side.upper_tex); + memcpy(side.lower_tex, l_tex.data(), 8); + memcpy(side.mid_tex, m_tex.data(), 8); + memcpy(side.upper_tex, u_tex.data(), 8); side.x_offset = LE_S16(x_offset); side.y_offset = LE_S16(y_offset); @@ -854,7 +852,7 @@ void Doom::AddLinedef(int vert1, int vert2, int side1, int side2, int type, int { if (sub_format != SUBFMT_Hexen) { - if (not UDMF_mode) + if (!UDMF_mode) { raw_linedef_t line; @@ -926,7 +924,7 @@ void Doom::AddLinedef(int vert1, int vert2, int side1, int side2, int type, int } else // Hexen format { - if (not UDMF_mode) + if (!UDMF_mode) { raw_hexen_linedef_t line; @@ -946,7 +944,7 @@ void Doom::AddLinedef(int vert1, int vert2, int side1, int side2, int type, int if (args) { - std::copy(args, args + 5, line.args); + memcpy(line.args, args, 5); } linedef_lump->Append(&line, sizeof(line)); @@ -1109,7 +1107,7 @@ void Doom::AddThing(int x, int y, int h, int type, int angle, int options, int t if (sub_format != SUBFMT_Hexen) { - if (not UDMF_mode) + if (!UDMF_mode) { raw_thing_t thing; @@ -1186,7 +1184,7 @@ void Doom::AddThing(int x, int y, int h, int type, int angle, int options, int t } else // Hexen format { - if (not UDMF_mode) + if (!UDMF_mode) { raw_hexen_thing_t thing; @@ -1213,7 +1211,7 @@ void Doom::AddThing(int x, int y, int h, int type, int angle, int options, int t if (args) { - std::copy(args, args + 5, thing.args); + memcpy(thing.args, args, 5); } thing_lump->Append(&thing, sizeof(thing)); @@ -1315,7 +1313,7 @@ int Doom::v094_add_thing(lua_State *L) int Doom::NumVertexes() { - if (not UDMF_mode) + if (!UDMF_mode) { return vertex_lump->GetSize() / sizeof(raw_vertex_t); } @@ -1324,7 +1322,7 @@ int Doom::NumVertexes() int Doom::NumSectors() { - if (not UDMF_mode) + if (!UDMF_mode) { return sector_lump->GetSize() / sizeof(raw_sector_t); } @@ -1333,7 +1331,7 @@ int Doom::NumSectors() int Doom::NumSidedefs() { - if (not UDMF_mode) + if (!UDMF_mode) { return sidedef_lump->GetSize() / sizeof(raw_sidedef_t); } @@ -1342,7 +1340,7 @@ int Doom::NumSidedefs() int Doom::NumLinedefs() { - if (not UDMF_mode) + if (!UDMF_mode) { if (sub_format == SUBFMT_Hexen) { @@ -1356,7 +1354,7 @@ int Doom::NumLinedefs() int Doom::NumThings() { - if (not UDMF_mode) + if (!UDMF_mode) { if (sub_format == SUBFMT_Hexen) { @@ -1529,17 +1527,7 @@ bool Doom::game_interface_c::Start(const char *preset) if (map_format == FORMAT_UDMF) { UDMF_mode = true; -#ifdef __APPLE__ - setlocale(LC_NUMERIC, "C"); -#elif __unix__ -#ifndef __linux__ setlocale(LC_NUMERIC, "C"); -#else - std::setlocale(LC_NUMERIC, "C"); -#endif -#else - std::setlocale(LC_NUMERIC, "C"); -#endif } else { @@ -1563,17 +1551,7 @@ bool Doom::game_interface_c::Finish(bool build_ok) if (UDMF_mode) { -#ifdef __APPLE__ - setlocale(LC_NUMERIC, numeric_locale.c_str()); -#elif __unix__ -#ifndef __linux__ setlocale(LC_NUMERIC, numeric_locale.c_str()); -#else - std::setlocale(LC_NUMERIC, numeric_locale.c_str()); -#endif -#else - std::setlocale(LC_NUMERIC, numeric_locale.c_str()); -#endif } if (build_ok) diff --git a/source/g_wolf.cc b/source/g_wolf.cc index d05529b83..417ee40f1 100644 --- a/source/g_wolf.cc +++ b/source/g_wolf.cc @@ -23,10 +23,11 @@ #include "hdr_ui.h" #endif #include "hdr_lua.h" -#include "headers.h" #include "lib_util.h" #include "m_lua.h" +#include "m_trans.h" #include "main.h" +#include "sys_assert.h" #define TEMP_GAMEFILE "GAMEMAPS.TMP" #define TEMP_MAPTEMP "MAPTEMP.TMP" diff --git a/source/headers.h b/source/headers.h deleted file mode 100644 index ae0b4c4a5..000000000 --- a/source/headers.h +++ /dev/null @@ -1,79 +0,0 @@ -//------------------------------------------------------------------------ -// INCLUDES -//------------------------------------------------------------------------ -// -// OBSIDIAN Level Maker -// -// Copyright (C) 2021-2022 The OBSIDIAN Team -// Copyright (C) 2006-2017 Andrew Apted -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -//------------------------------------------------------------------------ - -#pragma once - -// we C++ -#ifdef NULL -#undef NULL -#endif -#define NULL nullptr - -/* OS specifics */ -#ifdef _WIN32 -#define WIN32_LEAN_AND_MEAN -#include -#else -#ifndef CONSOLE_ONLY -#ifndef __APPLE__ -#include -#define USE_XFT 1 -#endif -#endif -#endif - -/* C library */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -/* STL goodies */ - -#include -#include -#include -#include - -/* Our own system defs */ - -#include "sys_assert.h" -#include "sys_debug.h" -#include "sys_endian.h" -#include "sys_macro.h" - -/* Internationalization / Localization */ - -#define _(s) ob_gettext(s) -#define N_(s) (s) - -const char *ob_gettext(const char *s); - -//--- editor settings --- -// vi:ts=4:sw=4:noexpandtab diff --git a/source/images.h b/source/images.h index 6cccc8b33..3e80fefbc 100644 --- a/source/images.h +++ b/source/images.h @@ -2,8 +2,6 @@ #pragma once -#include "headers.h" - #ifndef WIN32 static const char *obsidian_icon[] = { "64 64 928 2", diff --git a/source/lib_argv.cc b/source/lib_argv.cc index 828699edd..6870bd1f9 100644 --- a/source/lib_argv.cc +++ b/source/lib_argv.cc @@ -21,14 +21,15 @@ #include "lib_argv.h" -#include "headers.h" -#include "lib_util.h" - #ifdef _WIN32 +#include #include #include #endif +#include "lib_util.h" +#include "sys_assert.h" + std::vector argv::list; std::unordered_set argv::short_flags; @@ -56,7 +57,7 @@ static void Parse_LongArg(std::string_view arg) static void Parse_ShortArgs(std::string_view arg) { - for (std::size_t i = 1; i < arg.size(); ++i) + for (size_t i = 1; i < arg.size(); ++i) { char ch = arg[i]; @@ -210,7 +211,7 @@ int argv::Find(const char shortName, const char *longName, int *numParams) const std::string &str = list[p]; - if (shortName && (shortName == tolower(str[1])) && str[2] == 0) + if (shortName && (shortName == ToLowerASCII(str[1])) && str[2] == 0) { break; } @@ -244,7 +245,7 @@ int argv::Find(const char shortName, const char *longName, int *numParams) bool argv::IsOption(const int index) { - return list.at(index)[0] == '-'; + return list[index][0] == '-'; } //--- editor settings --- diff --git a/source/lib_parse.cc b/source/lib_parse.cc index fdc9e4c89..8464da0a8 100644 --- a/source/lib_parse.cc +++ b/source/lib_parse.cc @@ -18,9 +18,11 @@ #include "lib_parse.h" -#include -#include -#include +#include +#include + +#include "lib_util.h" +#include "sys_assert.h" namespace ajparse { @@ -39,10 +41,10 @@ token_kind_e lexer_c::Next(std::string &s) if (ch == '"') return ParseString(s); - if (ch == '-' || ch == '+' || std::isdigit(ch)) + if (ch == '-' || ch == '+' || IsDigitASCII(ch)) return ParseNumber(s); - if (std::isalpha(ch) || ch == '_' || ch >= 128) + if (IsAlphaASCII(ch) || ch == '_' || ch >= 128) return ParseIdentifier(s); // anything else is a single-character symbol @@ -53,10 +55,10 @@ token_kind_e lexer_c::Next(std::string &s) bool lexer_c::Match(const char *s) { - assert(s); - assert(s[0]); + SYS_ASSERT(s); + SYS_ASSERT(s[0]); - bool is_keyword = std::isalnum(s[0]); + bool is_keyword = IsAlphanumericASCII(s[0]); SkipToNext(); @@ -72,9 +74,9 @@ bool lexer_c::Match(const char *s) // don't change a char when high-bit is set (for UTF-8) if (A < 128) - A = std::tolower(A); + A = ToLowerASCII(A); if (B < 128) - B = std::tolower(B); + B = ToLowerASCII(B); if (A != B) return false; @@ -87,7 +89,7 @@ bool lexer_c::Match(const char *s) { unsigned char ch = (unsigned char)data[pos]; - if (std::isalnum(ch) || ch >= 128) + if (IsAlphanumericASCII(ch) || ch >= 128) return false; } @@ -108,13 +110,13 @@ void lexer_c::Rewind() int LEX_Int(const std::string &s) { // strtol handles all the integer sequences of the UDMF spec - return (int)std::strtol(s.c_str(), NULL, 0); + return (int)strtol(s.c_str(), NULL, 0); } double LEX_Double(const std::string &s) { // strtod handles all the floating-point sequences of the UDMF spec - return std::strtod(s.c_str(), NULL); + return strtod(s.c_str(), NULL); } bool LEX_Boolean(const std::string &s) @@ -195,16 +197,16 @@ token_kind_e lexer_c::ParseIdentifier(std::string &s) // don't change a char when high-bit is set (for UTF-8) if (ch < 128) - ch = std::tolower(ch); + ch = ToLowerASCII(ch); - if (!(std::isalnum(ch) || ch == '_' || ch >= 128)) + if (!(IsAlphanumericASCII(ch) || ch == '_' || ch >= 128)) break; s.push_back((char)ch); pos++; } - assert(s.size() > 0); + SYS_ASSERT(s.size() > 0); return TOK_Ident; } @@ -214,7 +216,7 @@ token_kind_e lexer_c::ParseNumber(std::string &s) if (data[pos] == '-' || data[pos] == '+') { // no digits after the sign? - if (pos + 1 >= data.size() || !std::isdigit(data[pos + 1])) + if (pos + 1 >= data.size() || !IsDigitASCII(data[pos + 1])) { s.push_back(data[pos++]); return TOK_Symbol; @@ -231,7 +233,7 @@ token_kind_e lexer_c::ParseNumber(std::string &s) unsigned char ch = (unsigned char)data[pos]; // this is fairly lax, but adequate for our purposes - if (!(std::isalnum(ch) || ch == '+' || ch == '-' || ch == '.')) + if (!(IsAlphanumericASCII(ch) || ch == '+' || ch == '-' || ch == '.')) break; } @@ -328,14 +330,14 @@ void lexer_c::ParseEscape(std::string &s) *p++ = '0'; ch = (unsigned char)data[pos]; - if (std::isxdigit(ch)) + if (IsXDigitASCII(ch)) { *p++ = ch; pos++; } ch = (unsigned char)data[pos]; - if (std::isxdigit(ch)) + if (IsXDigitASCII(ch)) { *p++ = ch; pos++; @@ -343,7 +345,7 @@ void lexer_c::ParseEscape(std::string &s) *p = 0; - int val = (int)std::strtol(buffer, NULL, 0); + int val = (int)strtol(buffer, NULL, 0); s.push_back((char)val); return; } diff --git a/source/lib_tga.cc b/source/lib_tga.cc index 18e3b550e..d0f6d2c27 100644 --- a/source/lib_tga.cc +++ b/source/lib_tga.cc @@ -26,7 +26,6 @@ #include "lib_tga.h" -#include "headers.h" #include "m_addons.h" #include "main.h" diff --git a/source/lib_util.cc b/source/lib_util.cc index 119427efe..c072157f9 100644 --- a/source/lib_util.cc +++ b/source/lib_util.cc @@ -21,11 +21,6 @@ #include "lib_util.h" -#include - -#include "grapheme.h" -#include "headers.h" -#include "main.h" #ifndef _WIN32 #include #include @@ -36,6 +31,12 @@ #ifdef __MINGW32__ #include #endif +#include + +#include "grapheme.h" +#include "main.h" +#include "sys_assert.h" +#include "sys_macro.h" #ifdef _WIN32 // Windows API static inline bool IsDirectorySeparator(const char c) @@ -742,7 +743,7 @@ uint64_t StringHash64(const std::string &str) } for (size_t c = str.size() - 1; c > 0; c--) { - hash2 = (hash2 << 5) - hash2 + str.at(c); + hash2 = (hash2 << 5) - hash2 + str[c]; } } diff --git a/source/lib_wad.cc b/source/lib_wad.cc index 01f8b58d1..c3d7c9c3c 100644 --- a/source/lib_wad.cc +++ b/source/lib_wad.cc @@ -23,10 +23,11 @@ #include -#include "headers.h" #include "lib_util.h" #include "main.h" #include "physfs.h" +#include "sys_assert.h" +#include "sys_endian.h" // #define LogPrintf printf @@ -275,7 +276,7 @@ void WAD_NewLump(std::string name) memset(&wad_W_lump, 0, sizeof(wad_W_lump)); - std::copy(name.data(), name.data() + name.size(), wad_W_lump.name); + memcpy(wad_W_lump.name, name.data(), name.size()); wad_W_lump.start = wad_W_fp.tellp(); } diff --git a/source/lib_zip.cc b/source/lib_zip.cc index c9327703e..3153037f8 100644 --- a/source/lib_zip.cc +++ b/source/lib_zip.cc @@ -21,7 +21,6 @@ #include "lib_zip.h" -#include "headers.h" #include "lib_util.h" #include "miniz.h" diff --git a/source/m_about.cc b/source/m_about.cc index 53f6d8537..1b7bfd1bb 100644 --- a/source/m_about.cc +++ b/source/m_about.cc @@ -21,9 +21,10 @@ #include "hdr_fltk.h" #include "hdr_ui.h" -#include "headers.h" #include "lib_util.h" +#include "m_trans.h" #include "main.h" +#include "sys_assert.h" class UI_About : public Fl_Window { diff --git a/source/m_addons.cc b/source/m_addons.cc index 80f1705d1..7a783dbc5 100644 --- a/source/m_addons.cc +++ b/source/m_addons.cc @@ -21,8 +21,6 @@ #include "m_addons.h" -#include "headers.h" - #ifndef CONSOLE_ONLY #include "hdr_fltk.h" #include "hdr_ui.h" diff --git a/source/m_addons.h b/source/m_addons.h index 68acdcd6e..848247eac 100644 --- a/source/m_addons.h +++ b/source/m_addons.h @@ -22,8 +22,8 @@ #pragma once #include +#include -#include #include #include #include diff --git a/source/m_cookie.cc b/source/m_cookie.cc index e2858362d..3b6015884 100644 --- a/source/m_cookie.cc +++ b/source/m_cookie.cc @@ -28,11 +28,11 @@ #include "hdr_ui.h" #endif #include "hdr_lua.h" -#include "headers.h" #include "lib_argv.h" #include "lib_util.h" #include "m_lua.h" #include "main.h" +#include "sys_assert.h" enum struct cookie_context_e { @@ -85,7 +85,7 @@ static void Cookie_SetValue(std::string name, std::string value) { try { - next_rand_seed = std::stoull(value); + next_rand_seed = stoull(value); return; } catch (std::invalid_argument &e) @@ -124,7 +124,7 @@ static bool Cookie_ParseLine(std::string buf) return true; } - while (std::isspace(buf[0])) + while (IsSpaceASCII(buf[0])) { buf.erase(buf.begin()); } @@ -137,16 +137,16 @@ static bool Cookie_ParseLine(std::string buf) std::string::size_type pos = buf.find('='); - while (pos > 0 && std::isspace(buf[pos - 1])) + while (pos > 0 && IsSpaceASCII(buf[pos - 1])) { buf.erase(buf.begin() + (pos - 1)); pos--; } - while (pos + 1 < buf.size() && std::isspace(buf[pos + 1])) + while (pos + 1 < buf.size() && IsSpaceASCII(buf[pos + 1])) { buf.erase(buf.begin() + (pos + 1)); } - while (std::isspace(buf[buf.size() - 1])) + while (IsSpaceASCII(buf[buf.size() - 1])) { buf.erase(buf.end() - 1); } @@ -174,17 +174,7 @@ bool Cookie_Load(std::string filename) active_module.clear(); -#ifdef __APPLE__ setlocale(LC_NUMERIC, "C"); -#elif __unix__ -#ifndef __linux__ - setlocale(LC_NUMERIC, "C"); -#else - std::setlocale(LC_NUMERIC, "C"); -#endif -#else - std::setlocale(LC_NUMERIC, "C"); -#endif std::ifstream cookie_fp(filename, std::ios::in); if (!cookie_fp.is_open()) @@ -218,17 +208,7 @@ bool Cookie_Load(std::string filename) LogPrintf("DONE.\n\n"); } } -#ifdef __APPLE__ setlocale(LC_NUMERIC, numeric_locale.c_str()); -#elif __unix__ -#ifndef __linux__ - setlocale(LC_NUMERIC, numeric_locale.c_str()); -#else - std::setlocale(LC_NUMERIC, numeric_locale.c_str()); -#endif -#else - std::setlocale(LC_NUMERIC, numeric_locale.c_str()); -#endif return true; } @@ -260,17 +240,7 @@ bool Cookie_LoadString(std::string str, bool _keep_seed) bool Cookie_Save(std::string filename) { context = cookie_context_e::Save; -#ifdef __APPLE__ setlocale(LC_NUMERIC, "C"); -#elif __unix__ -#ifndef __linux__ - setlocale(LC_NUMERIC, "C"); -#else - std::setlocale(LC_NUMERIC, "C"); -#endif -#else - std::setlocale(LC_NUMERIC, "C"); -#endif std::ofstream cookie_fp(filename, std::ios::out); if (!cookie_fp.is_open()) @@ -306,17 +276,7 @@ bool Cookie_Save(std::string filename) } cookie_fp.close(); -#ifdef __APPLE__ setlocale(LC_NUMERIC, numeric_locale.c_str()); -#elif __unix__ -#ifndef __linux__ - setlocale(LC_NUMERIC, numeric_locale.c_str()); -#else - std::setlocale(LC_NUMERIC, numeric_locale.c_str()); -#endif -#else - std::setlocale(LC_NUMERIC, numeric_locale.c_str()); -#endif return true; } diff --git a/source/m_cookie.h b/source/m_cookie.h index 5651ed0fa..49ee841c3 100644 --- a/source/m_cookie.h +++ b/source/m_cookie.h @@ -21,7 +21,8 @@ #pragma once -#include +#include + #include bool Cookie_Load(std::string filename); diff --git a/source/m_dialog.cc b/source/m_dialog.cc index 74db7548a..c5fb924c6 100644 --- a/source/m_dialog.cc +++ b/source/m_dialog.cc @@ -25,16 +25,14 @@ #include #include -#ifdef WIN32 -#include -#endif - #include "hdr_fltk.h" #include "hdr_ui.h" -#include "headers.h" #include "lib_util.h" #include "m_lua.h" +#include "m_trans.h" #include "main.h" +#include "sys_assert.h" +#include "sys_macro.h" std::string last_directory; @@ -242,7 +240,7 @@ std::string DLG_OutputFilename(const char *ext, const char *preset) // uppercase the first word for (char *p = &kind_buf[0]; *p && *p != ' '; p++) { - *p = toupper(*p); + *p = ToUpperASCII(*p); } // save and restore the font height @@ -344,8 +342,8 @@ void DLG_EditSeed(void) { for (long unsigned int i = 0; i < word.size(); i++) { - char character = word.at(i); - if (!std::isdigit(character)) + char character = word[i]; + if (!IsDigitASCII(character)) { throw std::runtime_error( // clang-format off @@ -354,7 +352,7 @@ void DLG_EditSeed(void) } } did_specify_seed = true; - next_rand_seed = std::stoull(word); + next_rand_seed = stoull(word); return; } catch (std::invalid_argument &e) diff --git a/source/m_lua.cc b/source/m_lua.cc index 46f997bae..0c2dd94c9 100644 --- a/source/m_lua.cc +++ b/source/m_lua.cc @@ -20,24 +20,21 @@ //---------------------------------------------------------------------- #include -#ifdef WIN32 -#include -#endif #ifndef CONSOLE_ONLY #include "hdr_fltk.h" #include "hdr_ui.h" #endif #include "ff_main.h" -#include "headers.h" #include "lib_util.h" +#define LUA_IMPL +#include "m_lua.h" +#include "m_trans.h" #include "main.h" #include "physfs.h" +#include "sys_assert.h" #include "sys_xoshiro.h" -#define LUA_IMPL -#include "m_lua.h" - static lua_State *LUA_ST; static bool has_loaded = false; diff --git a/source/m_manage.cc b/source/m_manage.cc index 267138ebc..4975c692f 100644 --- a/source/m_manage.cc +++ b/source/m_manage.cc @@ -21,11 +21,12 @@ #include "hdr_fltk.h" #include "hdr_ui.h" -#include "headers.h" #include "lib_util.h" #include "m_cookie.h" #include "m_lua.h" +#include "m_trans.h" #include "main.h" +#include "sys_assert.h" // forward decls class UI_Manage_Config; diff --git a/source/m_options.cc b/source/m_options.cc index 8df736792..f6121a140 100644 --- a/source/m_options.cc +++ b/source/m_options.cc @@ -23,7 +23,6 @@ #include "hdr_fltk.h" #include "hdr_ui.h" #endif -#include "headers.h" #include "lib_argv.h" #include "lib_util.h" #include "m_addons.h" diff --git a/source/m_theme.cc b/source/m_theme.cc index 27ce8b8d7..958fc4213 100644 --- a/source/m_theme.cc +++ b/source/m_theme.cc @@ -21,13 +21,14 @@ #include "hdr_fltk.h" #include "hdr_ui.h" -#include "headers.h" #include "lib_argv.h" #include "lib_util.h" #include "m_addons.h" #include "m_cookie.h" #include "m_trans.h" #include "main.h" +#include "sys_assert.h" +#include "sys_macro.h" bool skip_color_picker = false; @@ -597,7 +598,7 @@ class UI_ThemeWin : public Fl_Window UI_ThemeWin *that = (UI_ThemeWin *)data; font_theme = that->opt_font_theme->value(); - font_style = font_menu_items.at(font_theme).second; + font_style = font_menu_items[font_theme].second; fl_font(font_style, FL_NORMAL_SIZE); fl_message_font(font_style, FL_NORMAL_SIZE); main_win->menu_bar->textfont(font_style); diff --git a/source/m_trans.cc b/source/m_trans.cc index ac6bdfee2..4d2f842a6 100644 --- a/source/m_trans.cc +++ b/source/m_trans.cc @@ -27,15 +27,16 @@ #include "m_trans.h" -#include "hdr_lua.h" -#include "headers.h" -#include "lib_util.h" -#include "main.h" - #ifndef WIN32 #include #endif +#include "hdr_lua.h" +#include "lib_util.h" +#include "main.h" +#include "sys_assert.h" +#include "sys_macro.h" + // // NOTE : // We assume that any string retrieved from our 'trans_store' @@ -1184,32 +1185,8 @@ void Trans_UnInit() //---------------------------------------------------------------------- -// debugging crud -std::string mucked_up_string(std::string_view s) -{ - std::string buffer; - buffer.resize(s.size()); - int p, q; - for (p = s.size() - 1, q = 0; p >= 0 && q < 250; p--, q++) - { - int ch = s[p]; - if (ch == '%') - { - ch = '#'; - } - ch = (isupper(ch) ? tolower(ch) : toupper(ch)); - buffer[q] = ch; - } - buffer[q] = 0; - return buffer; -} - const char *ob_gettext(const char *s) { -#if 0 // DEBUGGING CRUD - return mucked_up_string(s); -#endif - std::map::iterator IT; IT = trans_store.find(s); diff --git a/source/m_trans.h b/source/m_trans.h index 6a9ec5191..f69684c92 100644 --- a/source/m_trans.h +++ b/source/m_trans.h @@ -36,5 +36,10 @@ void Trans_UnInit(); std::string Trans_GetAvailCode(int idx); std::string Trans_GetAvailLanguage(int idx); +#define _(s) ob_gettext(s) +#define N_(s) (s) + +const char *ob_gettext(const char *s); + //--- editor settings --- // vi:ts=4:sw=4:noexpandtab diff --git a/source/main.cc b/source/main.cc index 18e53f5e9..9cfbaa521 100644 --- a/source/main.cc +++ b/source/main.cc @@ -27,7 +27,6 @@ #include "hdr_fltk.h" #include "hdr_ui.h" #endif -#include "headers.h" #include "lib_argv.h" #include "lib_util.h" #include "lib_zip.h" @@ -863,7 +862,7 @@ void Main::SetupFLTK() if (font_theme < num_fonts) { // In case the number of installed fonts is // reduced between launches - font_style = font_menu_items.at(font_theme).second; + font_style = font_menu_items[font_theme].second; } else { @@ -1463,17 +1462,7 @@ hardrestart:; debug_messages = true; } // Grab current numeric locale -#ifdef __APPLE__ - numeric_locale = setlocale(LC_NUMERIC, NULL); -#elif __unix__ -#ifndef __linux__ numeric_locale = setlocale(LC_NUMERIC, NULL); -#else - numeric_locale = std::setlocale(LC_NUMERIC, NULL); -#endif -#else - numeric_locale = std::setlocale(LC_NUMERIC, NULL); -#endif LogEnableDebug(debug_messages); diff --git a/source/main.h b/source/main.h index 8bbbc5cc7..1794ad6eb 100644 --- a/source/main.h +++ b/source/main.h @@ -21,11 +21,13 @@ #pragma once -#include +#include + #include #include #include #include + #ifndef CONSOLE_ONLY #include "hdr_fltk.h" #include "ui_window.h" @@ -214,7 +216,7 @@ template [[noreturn]] void FatalError(std::string_view msg, A #endif } - std::exit(9); + exit(9); } template void ProgStatus(std::string_view msg, Args &&...args) diff --git a/source/poly.cc b/source/poly.cc index da379a6f6..427d9a714 100644 --- a/source/poly.cc +++ b/source/poly.cc @@ -16,7 +16,7 @@ // //------------------------------------------------------------------------ -#include +#include #include "poly_local.h" #include "sys_macro.h" @@ -777,7 +777,7 @@ bool polygon_c::ContainsPoint(double x, double y) const return true; } -static constexpr std::size_t EDGE_BUFFER_SIZE = 32; +static constexpr size_t EDGE_BUFFER_SIZE = 32; void polygon_c::ClockwiseOrder() { diff --git a/source/poly.h b/source/poly.h index b2f5f0999..343befc5f 100644 --- a/source/poly.h +++ b/source/poly.h @@ -21,10 +21,11 @@ // functions provided by the application #include +#include -#include #include #include + void Appl_FatalError(const char *str, ...); void Appl_Printf(const char *str, ...); diff --git a/source/poly_map.cc b/source/poly_map.cc index 01f6a1908..4af0f9f0e 100644 --- a/source/poly_map.cc +++ b/source/poly_map.cc @@ -228,11 +228,11 @@ void ParseSectorField(sector_c *sector, const std::string &key, ajparse::token_k } else if (key == "texturefloor") { - std::copy(value.data(), value.data() + OBSIDIAN_MIN(8, value.size()), sector->floor_tex); + memcpy(sector->floor_tex, value.data(), OBSIDIAN_MIN(8, value.size())); } else if (key == "textureceiling") { - std::copy(value.data(), value.data() + OBSIDIAN_MIN(8, value.size()), sector->ceil_tex); + memcpy(sector->ceil_tex, value.data(), OBSIDIAN_MIN(8, value.size())); } else if (key == "lightlevel") { @@ -264,15 +264,15 @@ void ParseSidedefField(sidedef_c *side, const std::string &key, ajparse::token_k } else if (key == "texturetop") { - std::copy(value.data(), value.data() + OBSIDIAN_MIN(8, value.size()), side->upper_tex); + memcpy(side->upper_tex, value.data(), OBSIDIAN_MIN(8, value.size())); } else if (key == "texturebottom") { - std::copy(value.data(), value.data() + OBSIDIAN_MIN(8, value.size()), side->lower_tex); + memcpy(side->lower_tex, value.data(), OBSIDIAN_MIN(8, value.size())); } else if (key == "texturemiddle") { - std::copy(value.data(), value.data() + OBSIDIAN_MIN(8, value.size()), side->mid_tex); + memcpy(side->mid_tex, value.data(), OBSIDIAN_MIN(8, value.size())); } else if (key == "sector") { @@ -813,8 +813,8 @@ bool LoadSectors() sector->floor_h = LE_S16(raw->floorh); sector->ceil_h = LE_S16(raw->ceilh); - std::copy(raw->floor_tex, raw->floor_tex + 8, sector->floor_tex); - std::copy(raw->ceil_tex, raw->ceil_tex + 8, sector->ceil_tex); + memcpy(sector->floor_tex, raw->floor_tex, 8); + memcpy(sector->ceil_tex, raw->ceil_tex, 8); sector->light = LE_U16(raw->light); sector->special = LE_U16(raw->type); @@ -941,9 +941,9 @@ bool LoadSidedefs() side->x_offset = LE_S16(raw->x_offset); side->y_offset = LE_S16(raw->y_offset); - std::copy(raw->upper_tex, raw->upper_tex + 8, side->upper_tex); - std::copy(raw->mid_tex, raw->mid_tex + 8, side->mid_tex); - std::copy(raw->lower_tex, raw->lower_tex + 8, side->lower_tex); + memcpy(side->upper_tex, raw->upper_tex, 8); + memcpy(side->mid_tex, raw->mid_tex, 8); + memcpy(side->lower_tex, raw->lower_tex, 8); } return true; // OK diff --git a/source/poly_wad.h b/source/poly_wad.h index fd696b9e7..aeb11243f 100644 --- a/source/poly_wad.h +++ b/source/poly_wad.h @@ -18,8 +18,9 @@ #pragma once -#include -#include +#include +#include + #include // directory entry diff --git a/source/slump.cc b/source/slump.cc index 9aa21e778..82cbd156d 100644 --- a/source/slump.cc +++ b/source/slump.cc @@ -30,10 +30,9 @@ #include "slump.h" #include +#include #include -#include - #include "lib_util.h" #include "m_lua.h" #include "sys_macro.h" diff --git a/source/slump_dump.cc b/source/slump_dump.cc index b80896ab3..97f9ddb59 100644 --- a/source/slump_dump.cc +++ b/source/slump_dump.cc @@ -30,10 +30,9 @@ */ #include +#include #include -#include - #include "lib_util.h" #include "slump.h" diff --git a/source/sys_assert.cc b/source/sys_assert.cc index 50a01fc9b..850c11ba6 100644 --- a/source/sys_assert.cc +++ b/source/sys_assert.cc @@ -19,8 +19,8 @@ // //---------------------------------------------------------------------------- -#include "headers.h" #include "main.h" +#include "sys_macro.h" //---------------------------------------------------------------------------- diff --git a/source/sys_debug.cc b/source/sys_debug.cc index f550ca2ae..1154fa9c9 100644 --- a/source/sys_debug.cc +++ b/source/sys_debug.cc @@ -19,11 +19,11 @@ // //------------------------------------------------------------------------ -#include +#include + #include #include -#include "headers.h" #include "lib_util.h" #include "m_lua.h" #include "main.h" diff --git a/source/tx_forge.cc b/source/tx_forge.cc index e1c547d57..8cfe36bc1 100644 --- a/source/tx_forge.cc +++ b/source/tx_forge.cc @@ -34,9 +34,10 @@ #include "tx_forge.h" -#include "headers.h" #include "lib_util.h" #include "main.h" +#include "sys_assert.h" +#include "sys_macro.h" #include "sys_xoshiro.h" /* Definitions used to address real and imaginary parts in a two-dimensional diff --git a/source/tx_skies.cc b/source/tx_skies.cc index 65412081a..81e01fff9 100644 --- a/source/tx_skies.cc +++ b/source/tx_skies.cc @@ -21,10 +21,11 @@ #include "tx_skies.h" -#include "headers.h" #include "lib_util.h" #include "m_lua.h" #include "main.h" +#include "sys_assert.h" +#include "sys_macro.h" #include "sys_xoshiro.h" #include "tx_forge.h" diff --git a/source/ui_build.cc b/source/ui_build.cc index 0d31ea8b5..9e2dd754c 100644 --- a/source/ui_build.cc +++ b/source/ui_build.cc @@ -21,9 +21,10 @@ #include "hdr_fltk.h" #include "hdr_ui.h" -#include "headers.h" #include "lib_util.h" +#include "m_trans.h" #include "main.h" +#include "sys_assert.h" UI_Build::UI_Build(int X, int Y, int W, int H, const char *label) : Fl_Group(X, Y, W, H, label) { diff --git a/source/ui_game.cc b/source/ui_game.cc index 66fd5b170..e3be38710 100644 --- a/source/ui_game.cc +++ b/source/ui_game.cc @@ -24,9 +24,9 @@ #include "hdr_fltk.h" #include "hdr_lua.h" #include "hdr_ui.h" -#include "headers.h" #include "lib_util.h" #include "m_lua.h" +#include "m_trans.h" #include "main.h" #define ABORT_COLOR fl_color_cube(3, 1, 1) diff --git a/source/ui_game.h b/source/ui_game.h index f3f4fb645..82c7b88de 100644 --- a/source/ui_game.h +++ b/source/ui_game.h @@ -21,7 +21,7 @@ #pragma once -#include +#include #include "FL/Fl_Button.H" #include "FL/Fl_Group.H" diff --git a/source/ui_hyper.cc b/source/ui_hyper.cc index 7c6722300..87bbb3b72 100644 --- a/source/ui_hyper.cc +++ b/source/ui_hyper.cc @@ -27,7 +27,6 @@ #include "hdr_fltk.h" #include "hdr_ui.h" -#include "headers.h" #include "lib_util.h" #include "main.h" diff --git a/source/ui_map.cc b/source/ui_map.cc index 48c6757ff..0557f9b6c 100644 --- a/source/ui_map.cc +++ b/source/ui_map.cc @@ -24,9 +24,10 @@ #include "gif.h" #include "hdr_fltk.h" #include "hdr_ui.h" -#include "headers.h" #include "lib_util.h" #include "main.h" +#include "sys_assert.h" +#include "sys_macro.h" // The includes got too messy to make these part of the UI_MiniMap class - Dasho static GifWriter *gif_writer; diff --git a/source/ui_module.cc b/source/ui_module.cc index 507763815..d16753c7a 100644 --- a/source/ui_module.cc +++ b/source/ui_module.cc @@ -24,10 +24,12 @@ #include "hdr_fltk.h" #include "hdr_lua.h" #include "hdr_ui.h" -#include "headers.h" #include "lib_util.h" #include "m_lua.h" +#include "m_trans.h" #include "main.h" +#include "sys_assert.h" +#include "sys_macro.h" #include "sys_xoshiro.h" UI_Module::UI_Module(int X, int Y, int W, int H, std::string id, std::string label, std::string tip, int red, int green, @@ -337,17 +339,7 @@ void UI_Module::AddSliderOption(std::string opt, std::string label, std::string // Populate the preset_choices map oldpos = 0; pos = 0; -#ifdef __APPLE__ setlocale(LC_NUMERIC, "C"); -#elif __unix__ -#ifndef __linux__ - setlocale(LC_NUMERIC, "C"); -#else - std::setlocale(LC_NUMERIC, "C"); -#endif -#else - std::setlocale(LC_NUMERIC, "C"); -#endif while (pos != std::string::npos) { @@ -363,7 +355,7 @@ void UI_Module::AddSliderOption(std::string opt, std::string label, std::string double key; try { - key = std::stod(map_string.substr(0, temp_pos)); + key = stod(map_string.substr(0, temp_pos)); std::string value = map_string.substr(temp_pos + 1); rsl->preset_choices[key] = value; } @@ -388,17 +380,8 @@ void UI_Module::AddSliderOption(std::string opt, std::string label, std::string oldpos = pos + 1; } } -#ifdef __APPLE__ + setlocale(LC_NUMERIC, numeric_locale.c_str()); -#elif __unix__ -#ifndef __linux__ - setlocale(LC_NUMERIC, numeric_locale.c_str()); -#else - std::setlocale(LC_NUMERIC, numeric_locale.c_str()); -#endif -#else - std::setlocale(LC_NUMERIC, numeric_locale.c_str()); -#endif rsl->cb_data = new opt_change_callback_data_t; rsl->cb_data->mod = rsl; @@ -682,7 +665,7 @@ bool UI_Module::SetSliderOption(std::string option, std::string value) double double_value; try { - double_value = std::stod(value); + double_value = stod(value); if (limit_break) { rsl->mod_slider->value(double_value); @@ -1023,7 +1006,7 @@ void UI_Module::callback_ManualEntry(Fl_Widget *w, void *data) try { - new_value = std::stod(string_value); + new_value = stod(string_value); } catch (std::invalid_argument &e) { diff --git a/source/ui_widgets.cc b/source/ui_widgets.cc index 908014741..74255b58c 100644 --- a/source/ui_widgets.cc +++ b/source/ui_widgets.cc @@ -21,10 +21,11 @@ #include "hdr_fltk.h" #include "hdr_ui.h" -#include "headers.h" #include "lib_util.h" #include "m_lua.h" +#include "m_trans.h" #include "main.h" +#include "sys_assert.h" choice_data_c::choice_data_c(std::string _id, std::string _label) : enabled(false), mapped(-1), widget(NULL) { diff --git a/source/ui_window.cc b/source/ui_window.cc index 0a9461727..d82ec2107 100644 --- a/source/ui_window.cc +++ b/source/ui_window.cc @@ -19,14 +19,14 @@ // //------------------------------------------------------------------------ +#ifndef _WIN32 +#include +#endif + #include "hdr_fltk.h" #include "hdr_ui.h" -#include "headers.h" #include "main.h" - -#ifndef WIN32 -#include -#endif +#include "m_trans.h" #if (FL_MAJOR_VERSION != 1 || FL_MINOR_VERSION < 3) #error "Require FLTK version 1.3.0 or later"