Merge branch 'main' into cmake-options

This commit is contained in:
Jeod 2024-04-30 17:57:58 -04:00 committed by GitHub
commit 7607593958
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 126 additions and 45 deletions

View File

@ -67,7 +67,7 @@ jobs:
run: |
sudo apt update
sudo apt install -y --no-install-recommends \
ninja-build cmake g++ libgtest-dev libsdl1.2-dev libsdl-image1.2-dev libncurses-dev zlib1g-dev
ninja-build cmake g++ libgtest-dev libsdl1.2-dev libsdl-image1.2-dev libncurses-dev zlib1g-dev libspdlog-dev
- name: Configure CMake
env:

View File

@ -10,3 +10,6 @@ brew "ninja"
# zlib
brew "zlib"
# spdlog
brew "spdlog"

View File

@ -19,6 +19,8 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_CXX_EXTENSIONS OFF)
find_package(spdlog REQUIRED)
if(FORCE_COLORED_OUTPUT)
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.24)
set(CMAKE_COLOR_DIAGNOSTICS ON)

View File

@ -54,6 +54,8 @@
#include "osiris_dll.h"
#include "loki_utils.h"
#include "log.h"
#if defined(MACOSX)
#include <SDL.h>
#endif
@ -469,6 +471,15 @@ static void check_beta() {
int main(int argc, char *argv[]) {
__orig_pwd = getcwd(NULL, 0);
/* Setup the spdlog system */
InitLog();
#ifdef DEBUG
spdlog::set_level(spdlog::level::debug);
#else
spdlog::set_level(spdlog::level::info);
#endif
setbuf(stdout, NULL);
setbuf(stderr, NULL);
@ -564,6 +575,8 @@ int main(int argc, char *argv[]) {
#endif
D3_MAJORVER, D3_MINORVER, D3_BUILD, D3_GIT_HASH);
SPDLOG_INFO(game_version_buffer);
game_version += 2; // skip those first newlines for loki_initialize.
register_d3_args();

View File

@ -475,7 +475,6 @@ void loki_initialize(int argc, char **argv, char *desc) {
// printf("base path: %s\n", basepath);
// printf("pref path: %s\n", prefpath);
printf("%s\n", desc);
} /* loki_initialize */
/* end of loki_utils.c ... */

View File

@ -30,6 +30,7 @@
#include "init.h"
#include "dedicated_server.h"
#include "resource.h"
#include "log.h"
const char *English_strings[] = {"Descent 3 under Windows NT requires version 4.0 or greater of NT to run.",
"Descent 3 requires Windows 9x, NT 4.0 or greater to run.",
@ -594,6 +595,8 @@ int PASCAL HandledWinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR szCmdLine,
extern bool w32_mouseman_hack; // from winapp.cpp
extern bool joy_chpro_hack; // located in winjoy.cpp
InitLog();
strupr(szCmdLine);
GatherArgs(szCmdLine);

View File

@ -48,12 +48,21 @@ cmake --preset mac -D ENABLE_LOGGER=[ON|OFF]
cmake --build --preset mac --config [Debug|Release]
```
#### Building - Linux
#### Building - Linux (Ubuntu)
```sh
sudo dpkg --add-architecture i386
sudo apt update
sudo apt install -y --no-install-recommends ninja-build cmake g++ libsdl1.2-dev libsdl-image1.2-dev libncurses-dev libxext6:i386 zlib1g-dev
cmake --preset linux -D ENABLE_LOGGER=[ON|OFF]
sudo apt install -y --no-install-recommends ninja-build cmake g++ libsdl1.2-dev libsdl-image1.2-dev libncurses-dev libxext6:i386 zlib1g-dev spdlog-dev
cmake --preset linux -D LOGGER=[ON|OFF]
cmake --build --preset linux --config [Debug|Release]
```
#### Building - Linux (Fedora)
```sh
sudo dnf update --refresh
sudo dnf install -y ninja-build cmake gcc-c++ SDL-devel SDL_image-devel ncurses-devel libXext.x86_64 zlib-devel spdlog-devel
sudo dnf install -y libXext.i686
cmake --preset linux -D LOGGER=[ON|OFF]
cmake --build --preset linux --config [Debug|Release]
```

28
lib/log.h Normal file
View File

@ -0,0 +1,28 @@
/*
* Descent 3
* Copyright (C) 2024 Descent Developers
*
* 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 3 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.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "spdlog/spdlog.h"
#include "spdlog/sinks/stdout_sinks.h"
#ifndef LOG_H
#define LOG_H
// Initialize the logging system
void InitLog();
#endif // LOG_H

View File

@ -35,12 +35,13 @@
* $NoKeywords: $
*/
#ifndef _PSTRING_H_
#define _PSTRING_H_
#ifndef PSTRING_H
#define PSTRING_H
#include <cstring>
// CleanupStr
// this function strips all leading and trailing spaces, keeping internal spaces. this goes
// for tabs too.
int CleanupStr(char *dest, const char *src, int destlen);
// This function strips all leading and trailing spaces, keeping internal spaces. This goes for tabs too.
std::size_t CleanupStr(char *dest, const char *src, std::size_t destlen);
#endif

View File

@ -2,11 +2,11 @@ set(HEADERS)
set(CPPS
error.cpp
logfile.cpp
log.cpp
psglob.cpp
psrand.cpp
pstring.cpp)
add_library(misc STATIC ${HEADERS} ${CPPS})
target_link_libraries(misc
ddebug
)
target_link_libraries(misc spdlog::spdlog_header_only ddebug)

28
misc/log.cpp Normal file
View File

@ -0,0 +1,28 @@
/*
* Descent 3
* Copyright (C) 2024 Descent Developers
*
* 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 3 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.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "log.h"
void InitLog() {
// Set the logging pattern
spdlog::set_pattern("%T [%l] %s:%!:%# %v");
// Create and register a console logger
auto console = spdlog::stdout_logger_mt("console");
console->info("Logger initialized");
}

View File

@ -38,47 +38,41 @@
* $NoKeywords: $
*/
#include <string.h>
#include <cctype>
#include "pstring.h"
// CleanupStr
// this function strips all leading and trailing spaces, keeping internal spaces. this goes
// for tabs too.
int CleanupStr(char *dest, const char *src, int destlen) {
int i, j, err, begin = 0, end = 0, len;
// This function strips all leading and trailing spaces, keeping internal spaces. This goes for tabs too.
std::size_t CleanupStr(char *dest, const char *src, std::size_t destlen) {
if (destlen == 0)
return 0;
err = 0;
const char *end;
std::size_t out_size;
len = strlen(src);
for (i = 0; i < len; i++) {
char ch;
ch = src[i];
// Trim leading space
while (std::isspace((unsigned char)*src))
src++;
// mark beginning.
if ((ch > ' ' && ch > '\t') && err < 1) {
err = 1;
begin = i;
end = i;
} else if (ch == ' ' && err == 1) {
err = 2;
end = i;
} else if (ch > ' ' && err >= 1) {
end = i;
}
// All spaces?
if (*src == '\0') {
*dest = '\0';
return 1;
}
j = 0;
for (i = begin; i < (end + 1); i++) {
char ch;
ch = src[i];
if (j == destlen - 1)
break;
if (ch != '\"')
dest[j++] = ch;
}
// Trim trailing space
end = src + std::strlen(src) - 1;
while (end > src && std::isspace((unsigned char)*end))
end--;
end++;
dest[j] = 0;
// Set output size to minimum of trimmed string length and buffer size minus 1
out_size = (end - src) < destlen - 1 ? (end - src) : destlen - 1;
return 0;
// Copy trimmed string and add null terminator
std::memcpy(dest, src, out_size);
dest[out_size] = '\0';
return out_size;
}

View File

@ -1,6 +1,7 @@
{
"builtin-baseline": "000d1bda1ffa95a73e0b40334fa4103d6f4d3d48",
"dependencies": [
"spdlog",
"gtest",
"zlib"
]