diff --git a/projects/openrct2.vcxproj b/projects/openrct2.vcxproj
index 36f12f5fdb..3ccf9c169c 100644
--- a/projects/openrct2.vcxproj
+++ b/projects/openrct2.vcxproj
@@ -49,6 +49,7 @@
+
@@ -163,6 +164,7 @@
+
diff --git a/projects/openrct2.vcxproj.filters b/projects/openrct2.vcxproj.filters
index 0c3c203548..006b5eb212 100644
--- a/projects/openrct2.vcxproj.filters
+++ b/projects/openrct2.vcxproj.filters
@@ -377,7 +377,6 @@
Source\Windows
-
Source\Drawing
@@ -449,6 +448,10 @@
Source\World
+
+
+ Source
+
@@ -655,5 +658,8 @@
Source\World
+
+ Source
+
\ No newline at end of file
diff --git a/src/cmdline.c b/src/cmdline.c
index 10c08c9eef..124b30a382 100644
--- a/src/cmdline.c
+++ b/src/cmdline.c
@@ -55,11 +55,12 @@ int cmdline_run(char *argv[], int argc)
argv--;
//
- int version = 0, width = 0, height = 0;
+ int version = 0, verbose = 0, width = 0, height = 0;
argparse_option_t options[] = {
OPT_HELP(),
OPT_BOOLEAN('v', "version", &version, "show version information and exit"),
+ OPT_BOOLEAN(0, "verbose", &verbose, "log verbose messages"),
OPT_END()
};
@@ -74,6 +75,9 @@ int cmdline_run(char *argv[], int argc)
return 0;
}
+ if (verbose)
+ _log_levels[DIAGNOSTIC_LEVEL_VERBOSE] = 1;
+
if (argc != 0) {
if (_stricmp(argv[0], "intro") == 0) {
gOpenRCT2StartupAction = STARTUP_ACTION_INTRO;
diff --git a/src/common.h b/src/common.h
index e2bdc76314..3fb41aac95 100644
--- a/src/common.h
+++ b/src/common.h
@@ -21,6 +21,7 @@
#ifndef _COMMON_H_
#define _COMMON_H_
+#include "diagnostic.h"
#include "rct2.h"
#endif
\ No newline at end of file
diff --git a/src/diagnostic.c b/src/diagnostic.c
new file mode 100644
index 0000000000..95c5661356
--- /dev/null
+++ b/src/diagnostic.c
@@ -0,0 +1,81 @@
+/*****************************************************************************
+* Copyright (c) 2014 Ted John, Duncan Frost
+* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
+*
+* This file is part of OpenRCT2.
+*
+* OpenRCT2 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 .
+*****************************************************************************/
+
+#include
+#include
+#include
+#include "diagnostic.h"
+
+int _log_levels[DIAGNOSTIC_LEVEL_COUNT] = { 1, 1, 1, 0 };
+int _log_location_enabled = 1;
+
+const char * _level_strings[] = {
+ "FATAL",
+ "ERROR",
+ "WARNING",
+ "VERBOSE"
+};
+
+void diagnostic_log(int diagnosticLevel, const char *format, ...)
+{
+ FILE *stream;
+ va_list args;
+
+ if (!_log_levels[diagnosticLevel])
+ return;
+
+ stream = stderr;
+
+ // Level
+ fprintf(stream, "%s: ", _level_strings[diagnosticLevel]);
+
+ // Message
+ va_start(args, format);
+ vfprintf(stream, format, args);
+ va_end(args);
+
+ // Line terminator
+ fprintf(stream, "\n");
+}
+
+void diagnostic_log_with_location(int diagnosticLevel, const char *file, const char *function, int line, const char *format, ...)
+{
+ FILE *stream;
+ va_list args;
+
+ if (!_log_levels[diagnosticLevel])
+ return;
+
+ stream = stderr;
+
+ // Level and source code information
+ if (_log_location_enabled)
+ fprintf(stream, "%s[%s:%d (%s)]: ", _level_strings[diagnosticLevel], file, line, function);
+ else
+ fprintf(stream, "%s: ", _level_strings[diagnosticLevel]);
+
+ // Message
+ va_start(args, format);
+ vfprintf(stream, format, args);
+ va_end(args);
+
+ // Line terminator
+ fprintf(stream, "\n");
+}
\ No newline at end of file
diff --git a/src/diagnostic.h b/src/diagnostic.h
new file mode 100644
index 0000000000..1237da073e
--- /dev/null
+++ b/src/diagnostic.h
@@ -0,0 +1,53 @@
+/*****************************************************************************
+* Copyright (c) 2014 Ted John, Duncan Frost
+* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
+*
+* This file is part of OpenRCT2.
+*
+* OpenRCT2 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 .
+*****************************************************************************/
+
+#ifndef _DIAGNOSTIC_H_
+#define _DIAGNOSTIC_H_
+
+enum {
+ DIAGNOSTIC_LEVEL_FATAL,
+ DIAGNOSTIC_LEVEL_ERROR,
+ DIAGNOSTIC_LEVEL_WARNING,
+ DIAGNOSTIC_LEVEL_VERBOSE,
+ DIAGNOSTIC_LEVEL_COUNT
+};
+
+extern int _log_levels[DIAGNOSTIC_LEVEL_COUNT];
+
+void diagnostic_log(int diagnosticLevel, const char *format, ...);
+void diagnostic_log_with_location(int diagnosticLevel, const char *file, const char *function, int line, const char *format, ...);
+
+#ifdef _MSC_VER
+#define diagnostic_log_macro(level, format, ...) diagnostic_log(level, __FILE__, __FUNCTION__, __LINE__, format, __VA_ARGS__)
+#else
+#define diagnostic_log_macro(level, format, ...) diagnostic_log(level, __FILE__, __func__, __LINE__, format, ## __VA_ARGS__)
+#endif
+
+#define log_fatal(format, ...) diagnostic_log_macro(DIAGNOSTIC_LEVEL_FATAL, format, __VA_ARGS__)
+#define log_error(format, ...) diagnostic_log_macro(DIAGNOSTIC_LEVEL_ERROR, format, __VA_ARGS__)
+#define log_warning(format, ...) diagnostic_log_macro(DIAGNOSTIC_LEVEL_WARNING, format, __VA_ARGS__)
+
+#ifdef _MSC_VER
+#define log_verbose(format, ...) diagnostic_log(DIAGNOSTIC_LEVEL_VERBOSE, format, __VA_ARGS__)
+#else
+#define log_verbose(format, ...) diagnostic_log(DIAGNOSTIC_LEVEL_VERBOSE, format, ## __VA_ARGS__)
+#endif
+
+#endif
\ No newline at end of file
diff --git a/src/drawing/sprite.c b/src/drawing/sprite.c
index ca8b68692e..0e28e76f7d 100644
--- a/src/drawing/sprite.c
+++ b/src/drawing/sprite.c
@@ -35,6 +35,8 @@ void *_g1Buffer = NULL;
*/
int gfx_load_g1()
{
+ log_verbose("loading g1 graphics");
+
FILE *file;
rct_g1_header header;
unsigned int i;
@@ -68,7 +70,7 @@ int gfx_load_g1()
}
// Unsuccessful
- RCT2_ERROR("Unable to load g1.dat");
+ log_fatal("Unable to load g1 graphics");
return 0;
}
diff --git a/src/rct2.c b/src/rct2.c
index 54333779c6..de77bbe566 100644
--- a/src/rct2.c
+++ b/src/rct2.c
@@ -73,6 +73,8 @@ void rct2_quit() {
void rct2_init()
{
+ log_verbose("initialising game");
+
RCT2_GLOBAL(RCT2_ADDRESS_SCENARIO_TICKS, int) = 0;
RCT2_GLOBAL(0x009AC310, char*) = RCT2_GLOBAL(RCT2_ADDRESS_CMDLINE, char*);
get_system_time();
diff --git a/src/scenario.c b/src/scenario.c
index 745f52e0dd..2af00426b1 100644
--- a/src/scenario.c
+++ b/src/scenario.c
@@ -82,6 +82,8 @@ int scenario_load_basic(const char *path, rct_s6_header *header, rct_s6_info *in
*/
int scenario_load(const char *path)
{
+ log_verbose("loading scenario, %s", path);
+
FILE *file;
int i, j;
rct_s6_header *s6Header = (rct_s6_header*)0x009E34E4;
@@ -93,6 +95,8 @@ int scenario_load(const char *path)
fclose(file);
RCT2_GLOBAL(0x009AC31B, uint8) = 255;
RCT2_GLOBAL(0x009AC31C, uint16) = STR_FILE_CONTAINS_INVALID_DATA;
+
+ log_error("failed to load scenario, invalid checksum");
return 0;
}