Browse Source

🐛 Fix console output on Windows and SDL1 targets

Fixes #921
pull/1166/head
Anders Jenbo 5 years ago
parent
commit
12658a0b3d
  1. 65
      Source/diablo.cpp
  2. 4
      Source/interfac.cpp
  3. 2
      Source/movie.cpp
  4. 35
      SourceS/console.h
  5. 1
      SourceS/file_util.h
  6. 4
      SourceS/miniwin/misc.h
  7. 11
      SourceS/sdl2_to_1_2_backports.h
  8. 4
      SourceX/miniwin/misc_msg.cpp

65
Source/diablo.cpp

@ -5,6 +5,7 @@
*/
#include "all.h"
#include "paths.h"
#include "console.h"
#include "../3rdParty/Storm/Source/storm.h"
#include "../DiabloUI/diabloui.h"
#include <config.h>
@ -92,36 +93,36 @@ BOOL was_snd_init = false;
static void print_help_and_exit()
{
printf("Options:\n");
printf(" %-20s %-30s\n", "-h, --help", "Print this message and exit");
printf(" %-20s %-30s\n", "--version", "Print the version and exit");
printf(" %-20s %-30s\n", "--data-dir", "Specify the folder of diabdat.mpq");
printf(" %-20s %-30s\n", "--save-dir", "Specify the folder of save files");
printf(" %-20s %-30s\n", "--config-dir", "Specify the location of diablo.ini");
printf(" %-20s %-30s\n", "-n", "Skip startup videos");
printf(" %-20s %-30s\n", "-f", "Display frames per second");
printf(" %-20s %-30s\n", "-x", "Run in windowed mode");
printf(" %-20s %-30s\n", "--spawn", "Force spawn mode even if diabdat.mpq is found");
printf("\nHellfire options:\n");
printf(" %-20s %-30s\n", "--diablo", "Force diablo mode even if hellfire.mpq is found");
printf(" %-20s %-30s\n", "--nestart", "Use alternate nest palette");
printInConsole("Options:\n");
printInConsole(" %-20s %-30s\n", "-h, --help", "Print this message and exit");
printInConsole(" %-20s %-30s\n", "--version", "Print the version and exit");
printInConsole(" %-20s %-30s\n", "--data-dir", "Specify the folder of diabdat.mpq");
printInConsole(" %-20s %-30s\n", "--save-dir", "Specify the folder of save files");
printInConsole(" %-20s %-30s\n", "--config-dir", "Specify the location of diablo.ini");
printInConsole(" %-20s %-30s\n", "-n", "Skip startup videos");
printInConsole(" %-20s %-30s\n", "-f", "Display frames per second");
printInConsole(" %-20s %-30s\n", "-x", "Run in windowed mode");
printInConsole(" %-20s %-30s\n", "--spawn", "Force spawn mode even if diabdat.mpq is found");
printInConsole("\nHellfire options:\n");
printInConsole(" %-20s %-30s\n", "--diablo", "Force diablo mode even if hellfire.mpq is found");
printInConsole(" %-20s %-30s\n", "--nestart", "Use alternate nest palette");
#ifdef _DEBUG
printf("\nDebug options:\n");
printf(" %-20s %-30s\n", "-d", "Increaased item drops");
printf(" %-20s %-30s\n", "-w", "Enable cheats");
printf(" %-20s %-30s\n", "-$", "Enable god mode");
printf(" %-20s %-30s\n", "-^", "Enable god mode and debug tools");
//printf(" %-20s %-30s\n", "-b", "Enable item drop log");
printf(" %-20s %-30s\n", "-v", "Highlight visibility");
printf(" %-20s %-30s\n", "-i", "Ignore network timeout");
//printf(" %-20s %-30s\n", "-j <##>", "Init trigger at level");
printf(" %-20s %-30s\n", "-l <##> <##>", "Start in level as type");
printf(" %-20s %-30s\n", "-m <##>", "Add debug monster, up to 10 allowed");
printf(" %-20s %-30s\n", "-q <#>", "Force a certain quest");
printf(" %-20s %-30s\n", "-r <##########>", "Set map seed");
printf(" %-20s %-30s\n", "-t <##>", "Set current quest level");
printInConsole("\nDebug options:\n");
printInConsole(" %-20s %-30s\n", "-d", "Increaased item drops");
printInConsole(" %-20s %-30s\n", "-w", "Enable cheats");
printInConsole(" %-20s %-30s\n", "-$", "Enable god mode");
printInConsole(" %-20s %-30s\n", "-^", "Enable god mode and debug tools");
//printInConsole(" %-20s %-30s\n", "-b", "Enable item drop log");
printInConsole(" %-20s %-30s\n", "-v", "Highlight visibility");
printInConsole(" %-20s %-30s\n", "-i", "Ignore network timeout");
//printInConsole(" %-20s %-30s\n", "-j <##>", "Init trigger at level");
printInConsole(" %-20s %-30s\n", "-l <##> <##>", "Start in level as type");
printInConsole(" %-20s %-30s\n", "-m <##>", "Add debug monster, up to 10 allowed");
printInConsole(" %-20s %-30s\n", "-q <#>", "Force a certain quest");
printInConsole(" %-20s %-30s\n", "-r <##########>", "Set map seed");
printInConsole(" %-20s %-30s\n", "-t <##>", "Set current quest level");
#endif
printf("\nReport bugs at https://github.com/diasurgical/devilutionX/\n");
printInConsole("\nReport bugs at https://github.com/diasurgical/devilutionX/\n");
diablo_quit(0);
}
@ -131,7 +132,7 @@ static void diablo_parse_flags(int argc, char **argv)
if (strcasecmp("-h", argv[i]) == 0 || strcasecmp("--help", argv[i]) == 0) {
print_help_and_exit();
} else if (strcasecmp("--version", argv[i]) == 0) {
printf("%s v%s\n", PROJECT_NAME, PROJECT_VERSION);
printInConsole("%s v%s\n", PROJECT_NAME, PROJECT_VERSION);
diablo_quit(0);
} else if (strcasecmp("--data-dir", argv[i]) == 0) {
SetBasePath(argv[++i]);
@ -195,7 +196,7 @@ static void diablo_parse_flags(int argc, char **argv)
debug_mode_key_w = TRUE;
#endif
} else {
printf("unrecognized option '%s'\n", argv[i]);
printInConsole("unrecognized option '%s'\n", argv[i]);
print_help_and_exit();
}
}
@ -309,14 +310,14 @@ static void run_game_loop(unsigned int uMsg)
nthread_ignore_mutex(FALSE);
while (gbRunGame) {
while (PeekMessage(&msg)) {
while (FetchMessage(&msg)) {
if (msg.message == DVL_WM_QUIT) {
gbRunGameResult = FALSE;
gbRunGame = FALSE;
break;
}
TranslateMessage(&msg);
DispatchMessage(&msg);
PushMessage(&msg);
}
if (!gbRunGame)
break;

4
Source/interfac.cpp

@ -265,10 +265,10 @@ void interface_msg_pump()
{
MSG Msg;
while (PeekMessage(&Msg)) {
while (FetchMessage(&Msg)) {
if (Msg.message != DVL_WM_QUIT) {
TranslateMessage(&Msg);
DispatchMessage(&Msg);
PushMessage(&Msg);
}
}
}

2
Source/movie.cpp

@ -31,7 +31,7 @@ void play_movie(const char *pszMovie, BOOL user_can_close)
SVidPlayBegin(pszMovie, 0, 0, 0, 0, loop_movie ? 0x100C0808 : 0x10280808, &video_stream);
MSG Msg;
while (video_stream && movie_playing) {
while (movie_playing && PeekMessage(&Msg)) {
while (movie_playing && FetchMessage(&Msg)) {
switch (Msg.message) {
case DVL_WM_KEYDOWN:
case DVL_WM_LBUTTONDOWN:

35
SourceS/console.h

@ -0,0 +1,35 @@
#pragma once
#if defined(_WIN64) || defined(_WIN32)
// Suppress definitions of `min` and `max` macros by <windows.h>:
#define NOMINMAX 1
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
namespace dvl {
void printInConsole(const char *fmt, ...)
{
static HANDLE stderrHandle = NULL;
if (stderrHandle == NULL) {
if (AttachConsole(ATTACH_PARENT_PROCESS)) {
stderrHandle = GetStdHandle(STD_ERROR_HANDLE);
}
}
if (stderrHandle == NULL)
return;
char message[256];
va_list ap;
va_start(ap, fmt);
vsprintf(message, fmt, ap);
va_end(ap);
WriteConsole(stderrHandle, message, strlen(message), NULL, NULL);
}
} // namespace dvl
#else
#define printInConsole printf
#endif

1
SourceS/file_util.h

@ -13,6 +13,7 @@
#if defined(_WIN64) || defined(_WIN32)
// Suppress definitions of `min` and `max` macros by <windows.h>:
#define NOMINMAX 1
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#endif

4
SourceS/miniwin/misc.h

@ -45,10 +45,10 @@ void FocusOnCharInfo();
SHORT GetAsyncKeyState(int vKey);
bool PeekMessage(LPMSG lpMsg);
bool FetchMessage(LPMSG lpMsg);
bool TranslateMessage(const MSG *lpMsg);
void DispatchMessage(const MSG *lpMsg);
void PushMessage(const MSG *lpMsg);
bool PostMessage(UINT Msg, WPARAM wParam, LPARAM lParam);
#ifndef TRUE

11
SourceS/sdl2_to_1_2_backports.h

@ -9,6 +9,7 @@
#include <math.h>
#include <cstddef>
#include "console.h"
#include "../SourceX/stubs.h"
#define WINDOW_ICON_NAME 0
@ -55,11 +56,13 @@
inline void SDL_Log(const char *fmt, ...)
{
char message[256];
va_list ap;
va_start(ap, fmt);
vprintf(fmt, ap);
vsprintf(message, fmt, ap);
va_end(ap);
puts("");
printInConsole("INFO: %s\n", message);
}
inline void SDL_StartTextInput()
@ -116,7 +119,7 @@ inline void SDL_GetWindowPosition(SDL_Window *window, int *x, int *y)
{
*x = window->clip_rect.x;
*y = window->clip_rect.x;
printf("SDL_GetWindowPosition %d %d", *x, *y);
SDL_Log("SDL_GetWindowPosition %d %d", *x, *y);
}
inline void SDL_SetWindowPosition(SDL_Window *window, int x, int y)
@ -128,7 +131,7 @@ inline void SDL_GetWindowSize(SDL_Window *window, int *w, int *h)
{
*w = window->clip_rect.w;
*h = window->clip_rect.h;
printf("SDL_GetWindowSize %d %d", *w, *h);
SDL_Log("SDL_GetWindowSize %d %d", *w, *h);
}
inline void SDL_ShowWindow(SDL_Window *window)

4
SourceX/miniwin/misc_msg.cpp

@ -301,7 +301,7 @@ bool BlurInventory()
return true;
}
bool PeekMessage(LPMSG lpMsg)
bool FetchMessage(LPMSG lpMsg)
{
#ifdef __SWITCH__
HandleDocking();
@ -714,7 +714,7 @@ SHORT GetAsyncKeyState(int vKey)
}
}
void DispatchMessage(const MSG *lpMsg)
void PushMessage(const MSG *lpMsg)
{
assert(CurrentProc);

Loading…
Cancel
Save