Add --console, remove WINDOWS_CONSOLE=1

This commit is contained in:
Agent X 2023-12-24 10:26:44 -05:00
parent c7e996f53e
commit c27da0e382
5 changed files with 25 additions and 6 deletions

View file

@ -873,9 +873,6 @@ ifeq ($(WINDOWS_BUILD),1)
ifeq ($(CROSS),) ifeq ($(CROSS),)
LDFLAGS += -no-pie LDFLAGS += -no-pie
endif endif
ifeq ($(WINDOWS_CONSOLE),1)
LDFLAGS += -mconsole
endif
else ifeq ($(TARGET_RPI),1) else ifeq ($(TARGET_RPI),1)
LDFLAGS := $(OPT_FLAGS) -lm $(BACKEND_LDFLAGS) -no-pie LDFLAGS := $(OPT_FLAGS) -lm $(BACKEND_LDFLAGS) -no-pie
else ifeq ($(OSX_BUILD),1) else ifeq ($(OSX_BUILD),1)

View file

@ -57,6 +57,11 @@ bool parse_cli_opts(int argc, char* argv[]) {
else if (strcmp(argv[i], "--windowed") == 0) // Open game in windowed mode else if (strcmp(argv[i], "--windowed") == 0) // Open game in windowed mode
gCLIOpts.FullScreen = 2; gCLIOpts.FullScreen = 2;
#if defined(_WIN32) || defined(_WIN64)
else if (strcmp(argv[i], "--console") == 0) // Open game with console
gCLIOpts.Console = 1;
#endif
else if (strcmp(argv[i], "--server") == 0 && (i + 1) < argc) { // Host server else if (strcmp(argv[i], "--server") == 0 && (i + 1) < argc) { // Host server
gCLIOpts.Network = NT_SERVER; gCLIOpts.Network = NT_SERVER;
arg_uint("--server <port>", argv[++i], &gCLIOpts.NetworkPort); arg_uint("--server <port>", argv[++i], &gCLIOpts.NetworkPort);

View file

@ -16,6 +16,9 @@ enum NetworkType {
struct PCCLIOptions { struct PCCLIOptions {
unsigned int SkipIntro; unsigned int SkipIntro;
unsigned int FullScreen; unsigned int FullScreen;
#if defined(_WIN32) || defined(_WIN64)
unsigned int Console;
#endif
enum NetworkType Network; enum NetworkType Network;
char JoinIp[IP_MAX_LEN]; char JoinIp[IP_MAX_LEN];
unsigned int NetworkPort; unsigned int NetworkPort;

View file

@ -294,7 +294,7 @@ struct QueuedMods {
static struct QueuedMods *sQueuedEnableModsHead = NULL; static struct QueuedMods *sQueuedEnableModsHead = NULL;
void enable_queued_mods() { void enable_queued_mods(void) {
while (sQueuedEnableModsHead) { while (sQueuedEnableModsHead) {
struct QueuedMods *next = sQueuedEnableModsHead->next; struct QueuedMods *next = sQueuedEnableModsHead->next;
mods_enable(sQueuedEnableModsHead->path); mods_enable(sQueuedEnableModsHead->path);
@ -630,14 +630,14 @@ void configfile_load(void) {
void configfile_save(const char *filename) { void configfile_save(const char *filename) {
FILE *file; FILE *file;
printf("Saving configuration to '%s'\n", filename);
file = fopen(fs_get_write_path(filename), "w"); file = fopen(fs_get_write_path(filename), "w");
if (file == NULL) { if (file == NULL) {
// error // error
return; return;
} }
printf("Saving configuration to '%s'\n", filename);
for (unsigned int i = 0; i < ARRAY_LEN(options); i++) { for (unsigned int i = 0; i < ARRAY_LEN(options); i++) {
const struct ConfigOption *option = &options[i]; const struct ConfigOption *option = &options[i];

View file

@ -56,6 +56,10 @@
#include "pc/discord/discord.h" #include "pc/discord/discord.h"
#endif #endif
#if defined(_WIN32) || defined(_WIN64)
#include <windows.h>
#endif
bool gCoopCompatibility; bool gCoopCompatibility;
OSMesg D_80339BEC; OSMesg D_80339BEC;
@ -344,6 +348,16 @@ int main(int argc, char *argv[]) {
// Handle terminal arguments // Handle terminal arguments
if (!parse_cli_opts(argc, argv)) { return 0; } if (!parse_cli_opts(argc, argv)) { return 0; }
#if defined(_WIN32) || defined(_WIN64)
// Handle Windows console
if (gCLIOpts.Console && AllocConsole()) {
FILE* fDummy;
freopen_s(&fDummy, "CONOUT$", "w", stdout);
freopen_s(&fDummy, "CONOUT$", "w", stderr);
freopen_s(&fDummy, "CONIN$", "r", stdin);
}
#endif
// Create the window straight away // Create the window straight away
if (!gGfxInited) { if (!gGfxInited) {
gfx_init(&WAPI, &RAPI, TITLE); gfx_init(&WAPI, &RAPI, TITLE);