Implemented logger on cgame an UI module

Signed-off-by: Harry Young <hendrik.gerritzen@googlemail.com>
This commit is contained in:
Harry Young 2013-08-27 17:19:29 +02:00
parent 249f240b85
commit 5740527fcd
12 changed files with 225 additions and 0 deletions

View file

@ -2080,6 +2080,7 @@ Q3CGOBJ_ = \
$(B)/$(BASEGAME)/cgame/cg_screenfx.o \
$(B)/$(BASEGAME)/cgame/cg_scoreboard.o \
$(B)/$(BASEGAME)/cgame/cg_servercmds.o \
$(B)/$(BASEGAME)/cgame/cg_logger.o \
$(B)/$(BASEGAME)/cgame/cg_snapshot.o \
$(B)/$(BASEGAME)/cgame/cg_view.o \
$(B)/$(BASEGAME)/cgame/cg_weapons.o \
@ -2340,6 +2341,7 @@ Q3UIOBJ_ = \
$(B)/$(BASEGAME)/ui/ui_demo2.o \
$(B)/$(BASEGAME)/ui/ui_gameinfo.o \
$(B)/$(BASEGAME)/ui/ui_ingame.o \
$(B)/$(BASEGAME)/ui/ui_logger.o \
$(B)/$(BASEGAME)/ui/ui_menu.o \
$(B)/$(BASEGAME)/ui/ui_mfield.o \
$(B)/$(BASEGAME)/ui/ui_mods.o \

View file

@ -1627,6 +1627,9 @@ extern vmCvar_t rpg_forceFieldSet;
// grp cvars
extern vmCvar_t grp_berp;
// deuging
extern vmCvar_t cg_logLevel;
// lua
#ifdef CG_LUA
extern vmCvar_t cg_debugLua;

79
code/cgame/cg_logger.c Normal file
View file

@ -0,0 +1,79 @@
#include "cg_logger.h"
void QDECL CG_Logger (int level, char* fmt, ...) {
va_list argptr;
char text[1024];
if(level > cg_logLevel.integer) {
return;
}
va_start (argptr, fmt);
vsnprintf (text, sizeof(text), fmt, argptr);
va_end (argptr);
switch (level)
{
case LL_ERROR:
CG_Printf(S_COLOR_RED "[cgame][error] - %s", text);
break;
case LL_WARN:
CG_Printf(S_COLOR_YELLOW "[cgame][warn ] - %s", text);
break;
case LL_INFO:
CG_Printf("[cgame][info ] - %s", text);
break;
case LL_DEBUG:
CG_Printf("[cgame][debug] - %s", text);
break;
case LL_TRACE:
CG_Printf("[cgame][trace] - %s", text);
break;
case LL_ALWAYS:
default:
CG_Printf("[cgame] - %s", text);
break;
}
}
void QDECL _CG_LocLogger (const char* file, int line, int level, char* fmt, ...) {
va_list argptr;
char text[1024];
if(level > cg_logLevel.integer) {
return;
}
va_start (argptr, fmt);
vsnprintf (text, sizeof(text), fmt, argptr);
va_end (argptr);
switch (level)
{
case LL_ERROR:
CG_Printf(S_COLOR_RED "[cgame][error][%s:%d] - ", file, line);
CG_Printf(S_COLOR_RED "%s", text);
break;
case LL_WARN:
CG_Printf(S_COLOR_YELLOW "[cgame][warn ][%s:%d] - ", file, line);
CG_Printf(S_COLOR_YELLOW "%s", text);
break;
case LL_INFO:
CG_Printf("[cgame][info ][%s:%d] - ", file, line);
CG_Printf("%s", text);
break;
case LL_DEBUG:
CG_Printf("[cgame][debug][%s:%d] - ", file, line);
CG_Printf("%s", text);
break;
case LL_TRACE:
CG_Printf("[cgame][trace][%s:%d] - ", file, line);
CG_Printf("%s", text);
break;
case LL_ALWAYS:
default:
CG_Printf("[cgame] [%s:%d] - ", file, line);
CG_Printf("%s", text);
break;
}
}

19
code/cgame/cg_logger.h Normal file
View file

@ -0,0 +1,19 @@
#ifndef CG_LOGGER_H_
#define CG_LOGGER_H_
#include "cg_local.h"
enum {
LL_ALWAYS,
LL_ERROR,
LL_WARN,
LL_INFO,
LL_DEBUG,
LL_TRACE
};
#define CG_LocLogger(X,...) _CG_LocLogger(__FILE__, __LINE__, X, __VA_ARGS__)
void QDECL CG_Logger(int level, char* fmt, ...) __attribute__ ((format (printf, 2, 3)));
void QDECL _CG_LocLogger(const char* file, int line, int level, char* fmt, ...) __attribute__ ((format (printf, 4, 5)));
#endif /* CG_LOGGER_H_ */

View file

@ -190,6 +190,9 @@ vmCvar_t rpg_forceFieldSet;
// grp cvars
vmCvar_t grp_berp;
// debugging cvars
vmCvar_t cg_logLevel;
// lua
#ifdef CG_LUA
vmCvar_t cg_debugLua;
@ -322,6 +325,9 @@ static cvarTable_t cvarTable[] = {
// grp cvars
{ &grp_berp, "grp_berp", "0", CVAR_ARCHIVE | CVAR_LATCH },
// debugging cvars
{ &cg_logLevel, "cg_loglevel", "2", CVAR_ARCHIVE },
// lua
#ifdef CG_LUA
{ &cg_debugLua, "cg_debuglua", "0", CVAR_ARCHIVE | CVAR_LATCH },

View file

@ -463,6 +463,7 @@
<ClCompile Include="lua_cent.c" />
<ClCompile Include="lua_cfx.c" />
<ClCompile Include="lua_refent.c" />
<ClCompile Include="cg_logger.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\game\bg_local.h" />
@ -478,6 +479,7 @@
<ClInclude Include="..\game\surfaceflags.h" />
<ClInclude Include="list.h" />
<ClInclude Include="tr_types.h" />
<ClCompile Include="cg_logger.h" />
</ItemGroup>
<ItemGroup>
<None Include="cgame.def" />

View file

@ -481,6 +481,7 @@
</ClCompile>
<ClCompile Include="ui_transporter.c" />
<ClCompile Include="ui_turbolift.c" />
<ClCompile Include="ui_logger.c" />
<ClCompile Include="ui_video.c">
<Optimization Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Disabled</Optimization>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">WIN32;_DEBUG;_WINDOWS;_MBCS;_USRDLL;UI_EXPORTS</PreprocessorDefinitions>
@ -499,6 +500,7 @@
<ClInclude Include="..\cgame\tr_types.h" />
<ClInclude Include="ui_local.h" />
<ClInclude Include="ui_public.h" />
<ClInclude Include="ui_logger.h" />
</ItemGroup>
<ItemGroup>
<None Include="ui.def" />

View file

@ -152,6 +152,9 @@
<ClCompile Include="ui_sql.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ui_logger.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\game\bg_public.h">
@ -178,6 +181,9 @@
<ClInclude Include="ui_public.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ui_logger.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="ui.def">

View file

@ -1395,6 +1395,9 @@ extern vmCvar_t sv_securityCode;
extern vmCvar_t ui_handleWidescreen;
// debugging
extern vmCvar_t ui_logLevel;
#define GRAPHIC_SQUARE "menu/common/square.tga"
#define BUTTON_GRAPHIC_LONGRIGHT "menu/common/bar1.tga"

79
code/ui/ui_logger.c Normal file
View file

@ -0,0 +1,79 @@
#include "ui_logger.h"
void QDECL UI_Logger (int level, char* fmt, ...) {
va_list argptr;
char text[1024];
if(level > ui_logLevel.integer) {
return;
}
va_start (argptr, fmt);
vsnprintf (text, sizeof(text), fmt, argptr);
va_end (argptr);
switch (level)
{
case LL_ERROR:
Com_Printf(S_COLOR_RED "[ui][error] - %s", text);
break;
case LL_WARN:
Com_Printf(S_COLOR_YELLOW "[ui][warn ] - %s", text);
break;
case LL_INFO:
Com_Printf("[ui][info ] - %s", text);
break;
case LL_DEBUG:
Com_Printf("[ui][debug] - %s", text);
break;
case LL_TRACE:
Com_Printf("[ui][trace] - %s", text);
break;
case LL_ALWAYS:
default:
Com_Printf("[ui] - %s", text);
break;
}
}
void QDECL _UI_LocLogger (const char* file, int line, int level, char* fmt, ...) {
va_list argptr;
char text[1024];
if(level > ui_logLevel.integer) {
return;
}
va_start (argptr, fmt);
vsnprintf (text, sizeof(text), fmt, argptr);
va_end (argptr);
switch (level)
{
case LL_ERROR:
Com_Printf(S_COLOR_RED "[ui][error][%s:%d] - ", file, line);
Com_Printf(S_COLOR_RED "%s", text);
break;
case LL_WARN:
Com_Printf(S_COLOR_YELLOW "[ui][warn ][%s:%d] - ", file, line);
Com_Printf(S_COLOR_YELLOW "%s", text);
break;
case LL_INFO:
Com_Printf("[ui][info ][%s:%d] - ", file, line);
Com_Printf("%s", text);
break;
case LL_DEBUG:
Com_Printf("[ui][debug][%s:%d] - ", file, line);
Com_Printf("%s", text);
break;
case LL_TRACE:
Com_Printf("[ui][trace][%s:%d] - ", file, line);
Com_Printf("%s", text);
break;
case LL_ALWAYS:
default:
Com_Printf("[ui] [%s:%d] - ", file, line);
Com_Printf("%s", text);
break;
}
}

19
code/ui/ui_logger.h Normal file
View file

@ -0,0 +1,19 @@
#ifndef UI_LOGGER_H_
#define UI_LOGGER_H_
#include "UI_local.h"
enum {
LL_ALWAYS,
LL_ERROR,
LL_WARN,
LL_INFO,
LL_DEBUG,
LL_TRACE
};
#define UI_LocLogger(X,...) _UI_LocLogger(__FILE__, __LINE__, X, __VA_ARGS__)
void QDECL UI_Logger(int level, char* fmt, ...) __attribute__ ((format (printf, 2, 3)));
void QDECL _UI_LocLogger(const char* file, int line, int level, char* fmt, ...) __attribute__ ((format (printf, 4, 5)));
#endif /* UI_LOGGER_H_ */

View file

@ -274,6 +274,9 @@ vmCvar_t sv_securityCode;
//Widescreen support
vmCvar_t ui_handleWidescreen;
//debugging
vmCvar_t ui_logLevel;
static cvarTable_t cvarTable[] = {
{ &ui_ffa_fraglimit, "ui_ffa_fraglimit", "20", CVAR_ARCHIVE },
{ &ui_ffa_timelimit, "ui_ffa_timelimit", "0", CVAR_ARCHIVE },
@ -469,6 +472,8 @@ static cvarTable_t cvarTable[] = {
{ &sv_securityCode, "sv_securityCode", "4294967295", CVAR_ARCHIVE | CVAR_USERINFO | CVAR_ROM | CVAR_NORESTART },
{ &ui_handleWidescreen, "ui_handleWidescreen", "1", CVAR_ARCHIVE },
{ &ui_logLevel, "ui_loglevel", "1", CVAR_ARCHIVE },
};
static int32_t cvarTableSize = sizeof(cvarTable) / sizeof(cvarTable[0]);