mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-04 13:42:55 +01:00
add log level check so that --verbose option works
This commit is contained in:
@@ -49,6 +49,7 @@
|
||||
<ClCompile Include="..\src\audio\mixer.cpp" />
|
||||
<ClCompile Include="..\src\cmdline.c" />
|
||||
<ClCompile Include="..\src\config.c" />
|
||||
<ClCompile Include="..\src\diagnostic.c" />
|
||||
<ClCompile Include="..\src\drawing\drawing.c" />
|
||||
<ClCompile Include="..\src\drawing\line.c" />
|
||||
<ClCompile Include="..\src\drawing\rain.c" />
|
||||
@@ -163,6 +164,7 @@
|
||||
<ClInclude Include="..\src\common.h" />
|
||||
<ClInclude Include="..\src\config.h" />
|
||||
<ClInclude Include="..\src\cursors.h" />
|
||||
<ClInclude Include="..\src\diagnostic.h" />
|
||||
<ClInclude Include="..\src\drawing\drawing.h" />
|
||||
<ClInclude Include="..\src\editor.h" />
|
||||
<ClInclude Include="..\src\game.h" />
|
||||
|
||||
@@ -377,7 +377,6 @@
|
||||
<ClCompile Include="..\src\windows\shortcut_keys.c">
|
||||
<Filter>Source\Windows</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\lib\lodepng\lodepng.c" />
|
||||
<ClCompile Include="..\src\drawing\rain.c">
|
||||
<Filter>Source\Drawing</Filter>
|
||||
</ClCompile>
|
||||
@@ -449,6 +448,10 @@
|
||||
<ClCompile Include="..\src\world\footpath.c">
|
||||
<Filter>Source\World</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\lib\libspeex\resample.c;..\lib\lodepng\lodepng.c" />
|
||||
<ClCompile Include="..\src\diagnostic.c">
|
||||
<Filter>Source</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\src\management\award.h">
|
||||
@@ -655,5 +658,8 @@
|
||||
<ClInclude Include="..\src\world\footpath.h">
|
||||
<Filter>Source\World</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\src\diagnostic.h">
|
||||
<Filter>Source</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -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;
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#ifndef _COMMON_H_
|
||||
#define _COMMON_H_
|
||||
|
||||
#include "diagnostic.h"
|
||||
#include "rct2.h"
|
||||
|
||||
#endif
|
||||
81
src/diagnostic.c
Normal file
81
src/diagnostic.c
Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*****************************************************************************/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#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");
|
||||
}
|
||||
53
src/diagnostic.h
Normal file
53
src/diagnostic.h
Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*****************************************************************************/
|
||||
|
||||
#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
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user