diff --git a/.gitignore b/.gitignore index 2893ef0..8df98e6 100644 --- a/.gitignore +++ b/.gitignore @@ -26,4 +26,5 @@ target/ lib/ baseq2/ baseq2.rar -TODO.txt \ No newline at end of file +TODO.txt +qconsole.log \ No newline at end of file diff --git a/build.gradle b/build.gradle index b0269b9..cf1b553 100644 --- a/build.gradle +++ b/build.gradle @@ -1,3 +1,7 @@ +plugins { + id 'net.ltgt.apt' version '0.10' +} + apply plugin: 'java' apply plugin: 'application' apply plugin: 'idea' @@ -18,10 +22,18 @@ if (OperatingSystem.current().isWindows()) { } else if (OperatingSystem.current().isLinux()) { platform = 'linux' } +def slf4jVersion = '1.7.21' +def log4jVersion = '2.5' dependencies { compile (['org.lwjgl.lwjgl:lwjgl:' + lwjgl_ver], ['org.lwjgl.lwjgl:lwjgl_util:' + lwjgl_ver]) + compile group: 'org.slf4j', name: 'slf4j-api', version: slf4jVersion + compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: log4jVersion + compile group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: log4jVersion + + compileOnly 'org.projectlombok:lombok:1.16.20' + apt "org.projectlombok:lombok:1.16.20" } sourceSets { diff --git a/resources/log4j2.xml b/resources/log4j2.xml new file mode 100644 index 0000000..2692573 --- /dev/null +++ b/resources/log4j2.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/lwjake2/client/CL.java b/src/lwjake2/client/CL.java index ae5b27d..05e3285 100644 --- a/src/lwjake2/client/CL.java +++ b/src/lwjake2/client/CL.java @@ -18,6 +18,7 @@ package lwjake2.client; +import lombok.extern.slf4j.Slf4j; import lwjake2.Defines; import lwjake2.Globals; import lwjake2.game.Cmd; @@ -44,7 +45,6 @@ import lwjake2.sys.Sys; import lwjake2.sys.Timer; import lwjake2.util.Lib; import lwjake2.util.Math3D; -import lwjake2.util.Vargs; import java.io.IOException; import java.io.RandomAccessFile; @@ -54,8 +54,8 @@ import java.nio.ByteOrder; /** * CL */ +@Slf4j public final class CL { - static int precache_check; // for autodownload of precache items static int precache_spawncount; @@ -108,7 +108,7 @@ public final class CL { int len; if (!Globals.cls.demorecording) { - Com.Printf("Not recording a demo.\n"); + log.info("Not recording a demo."); return; } @@ -118,7 +118,7 @@ public final class CL { Globals.cls.demofile.close(); Globals.cls.demofile = null; Globals.cls.demorecording = false; - Com.Printf("Stopped demo.\n"); + log.info("Stopped demo."); } catch (IOException e) { } } @@ -142,17 +142,17 @@ public final class CL { entity_state_t ent; if (Cmd.Argc() != 2) { - Com.Printf("record \n"); + log.info("record "); return; } if (Globals.cls.demorecording) { - Com.Printf("Already recording.\n"); + log.info("Already recording."); return; } if (Globals.cls.state != Defines.ca_active) { - Com.Printf("You must be in a level to record.\n"); + log.info("You must be in a level to record."); return; } @@ -161,11 +161,11 @@ public final class CL { // name = FS.Gamedir() + "/demos/" + Cmd.Argv(1) + ".dm2"; - Com.Printf("recording to " + name + ".\n"); + log.info("recording to {}", name); FS.CreatePath(name); Globals.cls.demofile = new RandomAccessFile(name, "rw"); if (Globals.cls.demofile == null) { - Com.Printf("ERROR: couldn't open.\n"); + log.error("ERROR: couldn't open."); return; } Globals.cls.demorecording = true; @@ -246,7 +246,7 @@ public final class CL { public void run() { if (Globals.cls.state != Defines.ca_connected && Globals.cls.state != Defines.ca_active) { - Com.Printf("Can't \"" + Cmd.Argv(0) + "\", not connected\n"); + log.warn("Can't \"{}\", not connected", Cmd.Argv(0)); return; } @@ -294,7 +294,7 @@ public final class CL { String server; if (Cmd.Argc() != 2) { - Com.Printf("usage: connect \n"); + log.info("usage: connect "); return; } @@ -328,7 +328,7 @@ public final class CL { public void run() { if (Globals.rcon_client_password.string.length() == 0) { - Com.Printf("You must set 'rcon_password' before\nissuing an rcon command.\n"); + log.warn("You must set 'rcon_password' before\nissuing an rcon command."); return; } @@ -358,7 +358,7 @@ public final class CL { to = Globals.cls.netchan.remote_address; else { if (Globals.rcon_address.string.length() == 0) { - Com.Printf("You must either be connected,\nor set the 'rcon_address' cvar\nto issue rcon commands\n"); + log.warn("You must either be connected,\nor set the 'rcon_address' cvar\nto issue rcon commands"); return; } NET.StringToAdr(Globals.rcon_address.string, to); @@ -393,7 +393,7 @@ public final class CL { SCR.BeginLoadingPlaque(); Globals.cls.state = Defines.ca_connected; // not active anymore, but // not disconnected - Com.Printf("\nChanging map...\n"); + log.info("Changing map..."); } }; @@ -412,7 +412,7 @@ public final class CL { S.StopAllSounds(); if (Globals.cls.state == Defines.ca_connected) { - Com.Printf("reconnecting...\n"); + log.info("reconnecting..."); Globals.cls.state = Defines.ca_connected; MSG.WriteChar(Globals.cls.netchan.message, Defines.clc_stringcmd); @@ -428,7 +428,7 @@ public final class CL { Globals.cls.connect_time = -99999; // fire immediately Globals.cls.state = Defines.ca_connecting; - Com.Printf("reconnecting...\n"); + log.info("reconnecting..."); } } }; @@ -449,7 +449,7 @@ public final class CL { NET.Config(true); // allow remote // send a broadcast packet - Com.Printf("pinging broadcast...\n"); + log.info("pinging broadcast..."); noudp = Cvar.Get("noudp", "0", Defines.CVAR_NOSET); if (noudp.value == 0.0f) { @@ -478,9 +478,9 @@ public final class CL { if (adrstring == null || adrstring.length() == 0) continue; - Com.Printf("pinging " + adrstring + "...\n"); + log.info("pinging {} ...", adrstring); if (!NET.StringToAdr(adrstring, adr)) { - Com.Printf("Bad address: " + adrstring + "\n"); + log.warn("Bad address: {}", adrstring); continue; } if (adr.port == 0) @@ -504,9 +504,7 @@ public final class CL { for (i = 0; i < Defines.MAX_CLIENTS; i++) { if (Globals.cl.configstrings[Defines.CS_PLAYERSKINS + i] == null) continue; - Com.Printf("client " + i + ": " - + Globals.cl.configstrings[Defines.CS_PLAYERSKINS + i] - + "\n"); + log.info("client {}: {}", i, Globals.cl.configstrings[Defines.CS_PLAYERSKINS + i]); SCR.UpdateScreen(); Sys.SendKeyEvents(); // pump message loop CL_parse.ParseClientinfo(i); @@ -519,7 +517,7 @@ public final class CL { */ static Runnable Userinfo_f = new Runnable() { public void run() { - Com.Printf("User info settings:\n"); + log.info("User info settings:"); Info.Print(Cvar.Userinfo()); } }; @@ -615,7 +613,7 @@ public final class CL { int port; if (!NET.StringToAdr(Globals.cls.servername, adr)) { - Com.Printf("Bad server address\n"); + log.warn("Bad server address"); Globals.cls.connect_time = 0; return; } @@ -658,7 +656,7 @@ public final class CL { return; if (!NET.StringToAdr(Globals.cls.servername, adr)) { - Com.Printf("Bad server address\n"); + log.warn("Bad server address"); Globals.cls.state = Defines.ca_disconnected; return; } @@ -668,7 +666,7 @@ public final class CL { // for retransmit requests Globals.cls.connect_time = Globals.cls.realtime; - Com.Printf("Connecting to " + Globals.cls.servername + "...\n"); + log.info("Connecting to {}...", Globals.cls.servername); Netchan.OutOfBandPrint(Defines.NS_CLIENT, adr, "getchallenge\n"); } @@ -711,10 +709,11 @@ public final class CL { time = (int) (Timer.Milliseconds() - Globals.cl.timedemo_start); if (time > 0) - Com.Printf("%i frames, %3.1f seconds: %3.1f fps\n", - new Vargs(3).add(Globals.cl.timedemo_frames).add( - time / 1000.0).add( - Globals.cl.timedemo_frames * 1000.0 / time)); + log.info(String.format("%d frames, %3.1f seconds: %3.1f fps", + Globals.cl.timedemo_frames, + (time / 1000.0f), + (Globals.cl.timedemo_frames * 1000.0f / time) + )); } Math3D.VectorClear(Globals.cl.refdef.blend); @@ -757,7 +756,7 @@ public final class CL { s = MSG.ReadString(Globals.net_message); - Com.Printf(s + "\n"); + log.info(s); Menu.AddToServerList(Globals.net_from, s); } @@ -778,13 +777,13 @@ public final class CL { Cmd.TokenizeString(s.toCharArray(), false); c = Cmd.Argv(0); - - Com.Println(Globals.net_from.toString() + ": " + c); + + log.info("{}: {}", Globals.net_from.toString(), c); // server connection if (c.equals("client_connect")) { if (Globals.cls.state == Defines.ca_connected) { - Com.Printf("Dup connect received. Ignored.\n"); + log.info("Dup connect received. Ignored."); return; } Netchan.Setup(Defines.NS_CLIENT, Globals.cls.netchan, @@ -804,7 +803,7 @@ public final class CL { // remote command from gui front end if (c.equals("cmd")) { if (!NET.IsLocalAddress(Globals.net_from)) { - Com.Printf("Command packet from remote host. Ignored.\n"); + log.info("Command packet from remote host. Ignored."); return; } s = MSG.ReadString(Globals.net_message); @@ -816,7 +815,7 @@ public final class CL { if (c.equals("print")) { s = MSG.ReadString(Globals.net_message); if (s.length() > 0) - Com.Printf(s); + log.info(s); return; } @@ -840,7 +839,7 @@ public final class CL { return; } - Com.Printf("Unknown command.\n"); + log.warn("Unknown command."); } @@ -868,8 +867,7 @@ public final class CL { continue; // dump it if not connected if (Globals.net_message.cursize < 8) { - Com.Printf(NET.AdrToString(Globals.net_from) - + ": Runt packet\n"); + log.info("{}: Runt packet", NET.AdrToString(Globals.net_from)); continue; } @@ -894,7 +892,7 @@ public final class CL { && Globals.cls.realtime - Globals.cls.netchan.last_received > Globals.cl_timeout.value * 1000) { if (++Globals.cl.timeoutcount > 5) // timeoutcount saves debugger { - Com.Printf("\nServer connection timed out.\n"); + log.info("Server connection timed out."); Disconnect(); return; } @@ -1413,7 +1411,7 @@ public final class CL { path = FS.Gamedir() + "/config.cfg"; f = Lib.fopen(path, "rw"); if (f == null) { - Com.Printf("Couldn't write config.cfg.\n"); + log.warn("Couldn't write config.cfg."); return; } try { @@ -1572,7 +1570,7 @@ public final class CL { public static void Shutdown() { if (isdown) { - System.out.print("recursive shutdown\n"); + log.info("recursive shutdown"); return; } isdown = true; diff --git a/src/lwjake2/client/CL_parse.java b/src/lwjake2/client/CL_parse.java index 722ac43..05d2546 100644 --- a/src/lwjake2/client/CL_parse.java +++ b/src/lwjake2/client/CL_parse.java @@ -18,6 +18,7 @@ package lwjake2.client; +import lombok.extern.slf4j.Slf4j; import lwjake2.Defines; import lwjake2.Globals; import lwjake2.game.Cmd; @@ -40,8 +41,8 @@ import java.io.RandomAccessFile; /** * CL_parse */ +@Slf4j public class CL_parse { - //// cl_parse.c -- parse a message received from the server public static String svc_strings[] = { "svc_bad", "svc_muzzleflash", @@ -714,7 +715,15 @@ public class CL_parse { S.StartLocalSound("misc/talk.wav"); Globals.con.ormask = 128; } - Com.Printf(MSG.ReadString(Globals.net_message)); + //TODO потом уброать + String msg = MSG.ReadString(Globals.net_message); + while (msg.startsWith("\n")) { msg = msg.substring(1); } + while (msg.endsWith("\n")) { msg = msg.substring(0, msg.lastIndexOf("\n")); } + while (msg.endsWith("\r")) { msg = msg.substring(0, msg.lastIndexOf("\r")); } + msg = msg.trim(); + if (!msg.isEmpty()) { + log.info(msg); + } Globals.con.ormask = 0; break; diff --git a/src/lwjake2/client/Console.java b/src/lwjake2/client/Console.java index d2e6b3a..6defe61 100644 --- a/src/lwjake2/client/Console.java +++ b/src/lwjake2/client/Console.java @@ -18,6 +18,7 @@ package lwjake2.client; +import lombok.extern.slf4j.Slf4j; import lwjake2.Defines; import lwjake2.Globals; import lwjake2.game.Cmd; @@ -35,8 +36,8 @@ import java.util.Arrays; /** * Console */ +@Slf4j public final class Console extends Globals { - public static Runnable ToggleConsole_f = new Runnable() { public void run() { SCR.EndLoadingPlaque(); // get rid of loading plaque @@ -85,7 +86,8 @@ public final class Console extends Globals { String name; if (Cmd.Argc() != 2) { - Com.Printf("usage: condump \n"); + log.info("usage: condump "); + return; } @@ -93,11 +95,11 @@ public final class Console extends Globals { // Cmd_Argv(1)); name = FS.Gamedir() + "/" + Cmd.Argv(1) + ".txt"; - Com.Printf("Dumped console text to " + name + ".\n"); + log.info("Dumped console text to {}", name); FS.CreatePath(name); f = Lib.fopen(name, "rw"); if (f == null) { - Com.Printf("ERROR: couldn't open.\n"); + log.error("ERROR: couldn't open."); return; } @@ -147,7 +149,7 @@ public final class Console extends Globals { CheckResize(); - Com.Printf("Console initialized.\n"); + log.info("Console initialized."); // // register our commands diff --git a/src/lwjake2/client/Key.java b/src/lwjake2/client/Key.java index 377b57e..cf8a9fc 100644 --- a/src/lwjake2/client/Key.java +++ b/src/lwjake2/client/Key.java @@ -18,6 +18,7 @@ package lwjake2.client; +import lombok.extern.slf4j.Slf4j; import lwjake2.Defines; import lwjake2.Globals; import lwjake2.game.Cmd; @@ -33,6 +34,7 @@ import java.util.Vector; /** * Key */ +@Slf4j public class Key extends Globals { // // these are the key numbers that should be passed to Key_Event @@ -575,7 +577,7 @@ public class Key extends Globals { Cbuf.AddText("\n"); - Com.Printf(new String(Globals.key_lines[Globals.edit_line], 0, Lib.strlen(Globals.key_lines[Globals.edit_line])) + "\n"); + log.info(new String(Globals.key_lines[Globals.edit_line], 0, Lib.strlen(Globals.key_lines[Globals.edit_line]))); Globals.edit_line = (Globals.edit_line + 1) & 31; history_line = Globals.edit_line; @@ -664,11 +666,16 @@ public class Key extends Globals { } private static void printCompletions(String type, Vector compl) { - Com.Printf(type); + StringBuilder sb = new StringBuilder(compl.size()); for (int i = 0; i < compl.size(); i++) { - Com.Printf((String)compl.get(i) + " "); + sb.append(compl.get(i)).append(' '); } - Com.Printf("\n"); + //TODO потом убрать + while (type.startsWith("\n")) { type = type.substring(1); } + while (type.endsWith("\n")) { type = type.substring(0, type.lastIndexOf("\n")); } + while (type.endsWith("\r")) { type = type.substring(0, type.lastIndexOf("\r")); } + type = type.trim(); + log.info("{} {}", type, sb.toString()); } static void CompleteCommand() { diff --git a/src/lwjake2/client/SCR.java b/src/lwjake2/client/SCR.java index f6a6aac..74796e7 100644 --- a/src/lwjake2/client/SCR.java +++ b/src/lwjake2/client/SCR.java @@ -18,6 +18,7 @@ package lwjake2.client; +import lombok.extern.slf4j.Slf4j; import lwjake2.Defines; import lwjake2.Globals; import lwjake2.game.Cmd; @@ -41,8 +42,8 @@ import java.util.Arrays; /** * SCR */ +@Slf4j public final class SCR extends Globals { - // cl_scrn.c -- master for refresh, status bar, console, chat, notify, etc static String[][] sb_nums = { @@ -636,8 +637,7 @@ public final class SCR extends Globals { stop = Timer.Milliseconds(); time = (stop - start) / 1000.0f; - Com.Printf("%f seconds (%f fps)\n", new Vargs(2).add(time).add( - 128.0f / time)); + log.info(String.format("%f seconds (%f fps)", time, (128.0f / time))); } static void DirtyScreen() { @@ -1757,8 +1757,7 @@ public final class SCR extends Globals { return; if (frame > cl.cinematicframe + 1) { - Com.Println("Dropped frame: " + frame + " > " - + (cl.cinematicframe + 1)); + log.info("Dropped frame: {} > {}", frame, (cl.cinematicframe + 1)); cl.cinematictime = cls.realtime - cl.cinematicframe * 1000 / 14; } @@ -1825,7 +1824,7 @@ public final class SCR extends Globals { EndLoadingPlaque(); cls.state = ca_active; if (size == 0 || cin.pic == null) { - Com.Println(name + " not found."); + log.info("{} not found.", name); cl.cinematictime = 0; } return; diff --git a/src/lwjake2/client/V.java b/src/lwjake2/client/V.java index b330eb5..bfb085b 100644 --- a/src/lwjake2/client/V.java +++ b/src/lwjake2/client/V.java @@ -18,6 +18,7 @@ package lwjake2.client; +import lombok.extern.slf4j.Slf4j; import lwjake2.Globals; import lwjake2.game.Cmd; import lwjake2.game.cvar_t; @@ -25,7 +26,6 @@ import lwjake2.qcommon.Com; import lwjake2.qcommon.Cvar; import lwjake2.sys.Timer; import lwjake2.util.Math3D; -import lwjake2.util.Vargs; import java.io.IOException; import java.nio.FloatBuffer; @@ -33,8 +33,8 @@ import java.nio.FloatBuffer; /** * V */ +@Slf4j public final class V extends Globals { - static cvar_t cl_testblend; static cvar_t cl_testparticles; @@ -359,8 +359,7 @@ public final class V extends Globals { re.RenderFrame(cl.refdef); if (cl_stats.value != 0.0f) - Com.Printf("ent:%i lt:%i part:%i\n", new Vargs(3).add( - r_numentities).add(r_numdlights).add(r_numparticles)); + log.info("ent:{} lt:{} part:{}", r_numentities, r_numdlights, r_numparticles); if (log_stats.value != 0.0f && (log_stats_file != null)) try { log_stats_file.write(r_numentities + "," + r_numdlights + "," @@ -380,10 +379,11 @@ public final class V extends Globals { */ static Runnable Viewpos_f = new Runnable() { public void run() { - Com.Printf("(%i %i %i) : %i\n", new Vargs(4).add( - (int) cl.refdef.vieworg[0]).add((int) cl.refdef.vieworg[1]) - .add((int) cl.refdef.vieworg[2]).add( - (int) cl.refdef.viewangles[YAW])); + log.info("({} {} {}) : {}", + (int) cl.refdef.vieworg[0], + (int) cl.refdef.vieworg[1], + (int) cl.refdef.vieworg[2], + (int) cl.refdef.viewangles[YAW] } }; diff --git a/src/lwjake2/client/VID.java b/src/lwjake2/client/VID.java index 397c60b..576af04 100644 --- a/src/lwjake2/client/VID.java +++ b/src/lwjake2/client/VID.java @@ -18,6 +18,7 @@ package lwjake2.client; +import lombok.extern.slf4j.Slf4j; import lwjake2.Defines; import lwjake2.Globals; import lwjake2.game.Cmd; @@ -39,6 +40,7 @@ import java.awt.DisplayMode; * * @author cwei */ +@Slf4j public class VID extends Globals { // Main windowed and fullscreen graphics interface module. This module // is used for both the software and OpenGL rendering versions of the @@ -74,7 +76,11 @@ public class VID extends Globals { */ public static void Printf(int print_level, String fmt) { - Printf(print_level, fmt, null); + while (fmt.startsWith("\n")) { fmt = fmt.substring(1); } + while (fmt.endsWith("\n")) { fmt = fmt.substring(0, fmt.lastIndexOf("\n")); } + while (fmt.endsWith("\r")) { fmt = fmt.substring(0, fmt.lastIndexOf("\r")); } + fmt = fmt.trim(); + log.warn("{}", fmt); } public static void Printf(int print_level, String fmt, Vargs vargs) { @@ -173,7 +179,8 @@ public class VID extends Globals { FreeReflib(); } - Com.Printf( "------- Loading " + name + " -------\n"); + log.info("------- Loading {} -------", name); + boolean found = false; @@ -186,11 +193,11 @@ public class VID extends Globals { } if (!found) { - Com.Printf( "LoadLibrary(\"" + name +"\") failed\n"); + log.warn("LoadLibrary(\"{}\") failed", name); return false; } - Com.Printf( "LoadLibrary(\"" + name +"\")\n" ); + log.info("LoadLibrary(\"{}\")", name); Globals.re = Renderer.getDriver(name); if (Globals.re == null) @@ -216,7 +223,7 @@ public class VID extends Globals { /* Init KBD */ Globals.re.getKeyboardHandler().Init(); - Com.Printf( "------------------------------------\n"); + log.info("------------------------------------"); reflib_active = true; return true; } @@ -262,10 +269,10 @@ public class VID extends Globals { } if ( vid_ref.string.equals(Renderer.getDefaultName())) { renderer = vid_ref.string; - Com.Printf("Refresh failed\n"); + log.info("Refresh failed"); gl_mode = Cvar.Get( "gl_mode", "0", 0 ); if (gl_mode.value != 0.0f) { - Com.Printf("Trying mode 0\n"); + log.info("Trying mode 0"); Cvar.SetValue("gl_mode", 0); if ( !LoadRefresh( vid_ref.string ) ) Com.Error(Defines.ERR_FATAL, "Couldn't fall back to " + renderer +" refresh!"); diff --git a/src/lwjake2/game/Cmd.java b/src/lwjake2/game/Cmd.java index 141a5ff..ce5b7f1 100644 --- a/src/lwjake2/game/Cmd.java +++ b/src/lwjake2/game/Cmd.java @@ -18,6 +18,7 @@ package lwjake2.game; +import lombok.extern.slf4j.Slf4j; import lwjake2.Defines; import lwjake2.Globals; import lwjake2.game.monsters.M_Player; @@ -38,6 +39,7 @@ import java.util.Vector; /** * Cmd */ +@Slf4j public final class Cmd { static Runnable List_f = new Runnable() { public void run() { @@ -45,28 +47,28 @@ public final class Cmd { int i = 0; while (cmd != null) { - Com.Printf(cmd.name + '\n'); + log.info(cmd.name); i++; cmd = cmd.next; } - Com.Printf(i + " commands\n"); + log.info("{} commands", i); } }; static Runnable Exec_f = new Runnable() { public void run() { if (Cmd.Argc() != 2) { - Com.Printf("exec : run a script file\n"); + log.info("exec : execute a script file"); return; } byte[] f = null; f = FS.LoadFile(Cmd.Argv(1)); if (f == null) { - Com.Printf("couldn't exec " + Cmd.Argv(1) + "\n"); + log.info("couldn't exec {}", Cmd.Argv(1)); return; } - Com.Printf("execing " + Cmd.Argv(1) + "\n"); + log.info("execing {}", Cmd.Argv(1)); Cbuf.InsertText(new String(f)); @@ -76,10 +78,11 @@ public final class Cmd { static Runnable Echo_f = new Runnable() { public void run() { + StringBuilder sb = new StringBuilder(Cmd.Argc()); for (int i = 1; i < Cmd.Argc(); i++) { - Com.Printf(Cmd.Argv(i) + " "); + sb.append(Cmd.Argv(i)).append(' '); } - Com.Printf("'\n"); + log.info(sb.toString()); } }; @@ -87,16 +90,16 @@ public final class Cmd { public void run() { cmdalias_t a = null; if (Cmd.Argc() == 1) { - Com.Printf("Current alias commands:\n"); + log.info("Current alias commands:"); for (a = Globals.cmd_alias; a != null; a = a.next) { - Com.Printf(a.name + " : " + a.value); + log.info("{} : {}", a.name, a.value); } return; } String s = Cmd.Argv(1); if (s.length() > Defines.MAX_ALIAS_NAME) { - Com.Printf("Alias name is too long\n"); + log.warn("Alias name is too long"); return; } @@ -190,8 +193,7 @@ public final class Cmd { scan = text; if (len >= Defines.MAX_STRING_CHARS) { - Com.Printf("Line exceeded " + Defines.MAX_STRING_CHARS - + " chars, discarded.\n"); + log.info("Line exceeded {} chars, discarded.", Defines.MAX_STRING_CHARS); return null; } @@ -221,8 +223,7 @@ public final class Cmd { len += j; if (len >= Defines.MAX_STRING_CHARS) { - Com.Printf("Expanded line exceeded " + Defines.MAX_STRING_CHARS - + " chars, discarded.\n"); + log.warn("Expanded line exceeded {} chars, discarded.", Defines.MAX_STRING_CHARS); return null; } @@ -234,13 +235,13 @@ public final class Cmd { scan = expanded; i--; if (++count == 100) { - Com.Printf("Macro expansion loop, discarded.\n"); + log.info("Macro expansion loop, discarded."); return null; } } if (inquote) { - Com.Printf("Line has unmatched quote, discarded.\n"); + log.info("Line has unmatched quote, discarded."); return null; } @@ -308,17 +309,14 @@ public final class Cmd { //Com.DPrintf("Cmd_AddCommand: " + cmd_name + "\n"); // fail if the command is a variable name if ((Cvar.VariableString(cmd_name)).length() > 0) { - Com.Printf("Cmd_AddCommand: " + cmd_name - + " already defined as a var\n"); + log.warn("Cmd_AddCommand: {} already defined as a var", cmd_name); return; } // fail if the command already exists for (cmd = cmd_functions; cmd != null; cmd = cmd.next) { if (cmd_name.equals(cmd.name)) { - Com - .Printf("Cmd_AddCommand: " + cmd_name - + " already defined\n"); + log.warn("Cmd_AddCommand: {} already defined", cmd_name); return; } } @@ -342,7 +340,7 @@ public final class Cmd { while (true) { if (cmd == null) { - Com.Printf("Cmd_RemoveCommand: " + cmd_name + " not added\n"); + log.info("Cmd_RemoveCommand: {} not added", cmd_name); return; } if (0 == Lib.strcmp(cmd_name, cmd.name)) { @@ -420,7 +418,7 @@ public final class Cmd { if (cmd_argv[0].equalsIgnoreCase(a.name)) { if (++Globals.alias_count == ALIAS_LOOP_COUNT) { - Com.Printf("ALIAS_LOOP_COUNT\n"); + log.info("ALIAS_LOOP_COUNT"); return; } Cbuf.InsertText(a.value); @@ -1165,7 +1163,7 @@ public final class Cmd { cmd = Cmd.Argv(0); if (Globals.cls.state <= Defines.ca_connected || cmd.charAt(0) == '-' || cmd.charAt(0) == '+') { - Com.Printf("Unknown command \"" + cmd + "\"\n"); + log.warn("Unknown command \"{}\"", cmd); return; } diff --git a/src/lwjake2/game/GameBase.java b/src/lwjake2/game/GameBase.java index 8afae27..ad0e702 100644 --- a/src/lwjake2/game/GameBase.java +++ b/src/lwjake2/game/GameBase.java @@ -20,6 +20,7 @@ package lwjake2.game; +import lombok.extern.slf4j.Slf4j; import lwjake2.Defines; import lwjake2.client.M; import lwjake2.qcommon.Com; @@ -30,6 +31,7 @@ import lwjake2.util.Math3D; import java.util.StringTokenizer; +@Slf4j public class GameBase { public static cplane_t dummyplane = new cplane_t(); @@ -239,7 +241,7 @@ public class GameBase { edict_t choice[] = new edict_t[MAXCHOICES]; if (targetname == null) { - gi.dprintf("G_PickTarget called with null targetname\n"); + log.info("G_PickTarget called with null targetname"); return null; } @@ -252,7 +254,7 @@ public class GameBase { } if (num_choices == 0) { - gi.dprintf("G_PickTarget: target " + targetname + " not found\n"); + log.info("G_PickTarget: target {} not found", targetname); return null; } @@ -396,7 +398,7 @@ public class GameBase { }; public static void ShutdownGame() { - gi.dprintf("==== ShutdownGame ====\n"); + log.info("==== ShutdownGame ===="); } /** diff --git a/src/lwjake2/game/GameItems.java b/src/lwjake2/game/GameItems.java index 45727f4..b37087d 100644 --- a/src/lwjake2/game/GameItems.java +++ b/src/lwjake2/game/GameItems.java @@ -19,6 +19,7 @@ package lwjake2.game; +import lombok.extern.slf4j.Slf4j; import lwjake2.Defines; import lwjake2.qcommon.Com; import lwjake2.util.Lib; @@ -26,9 +27,8 @@ import lwjake2.util.Math3D; import java.util.StringTokenizer; - +@Slf4j public class GameItems { - public static gitem_armor_t jacketarmor_info = new gitem_armor_t(25, 50, .30f, .00f, Defines.ARMOR_JACKET); public static gitem_armor_t combatarmor_info = new gitem_armor_t(50, 100, @@ -815,7 +815,7 @@ public class GameItems { if (it.pickup_name.equalsIgnoreCase(pickup_name)) return it; } - Com.Println("Item not found:" + pickup_name); + log.info("Item not found:{}", pickup_name); return null; } diff --git a/src/lwjake2/game/GameSave.java b/src/lwjake2/game/GameSave.java index 375507b..117b69a 100644 --- a/src/lwjake2/game/GameSave.java +++ b/src/lwjake2/game/GameSave.java @@ -18,14 +18,15 @@ package lwjake2.game; +import lombok.extern.slf4j.Slf4j; import lwjake2.Defines; import lwjake2.Globals; import lwjake2.qcommon.Com; import lwjake2.util.Lib; import lwjake2.util.QuakeFile; +@Slf4j public class GameSave { - public static void CreateEdicts() { GameBase.g_edicts = new edict_t[GameBase.game.maxentities]; for (int i = 0; i < GameBase.game.maxentities; i++) @@ -114,7 +115,7 @@ public class GameSave { * a new game is started or a save game is loaded. */ public static void InitGame() { - GameBase.gi.dprintf("==== InitGame ====\n"); + log.info("==== InitGame ===="); // preload all classes to register the adapters for ( int n=0; n < preloadclasslist.length; n++) diff --git a/src/lwjake2/game/GameSpawn.java b/src/lwjake2/game/GameSpawn.java index 11019dd..2b5d0e6 100644 --- a/src/lwjake2/game/GameSpawn.java +++ b/src/lwjake2/game/GameSpawn.java @@ -18,6 +18,7 @@ package lwjake2.game; +import lombok.extern.slf4j.Slf4j; import lwjake2.Defines; import lwjake2.game.monsters.M_Actor; import lwjake2.game.monsters.M_Berserk; @@ -43,8 +44,8 @@ import lwjake2.game.monsters.M_Tank; import lwjake2.qcommon.Com; import lwjake2.util.Lib; +@Slf4j public class GameSpawn { - static EntThinkAdapter SP_item_health = new EntThinkAdapter() { public String getID(){ return "SP_item_health"; } public boolean think(edict_t ent) { @@ -352,7 +353,7 @@ public class GameSpawn { static void ED_ParseField(String key, String value, edict_t ent) { if (key.equals("nextmap")) - Com.Println("nextmap: " + value); + log.info("nextmap: {}", value); if (!GameBase.st.set(key, value)) if (!ent.setField(key, value)) GameBase.gi.dprintf("??? The key [" + key diff --git a/src/lwjake2/game/edict_t.java b/src/lwjake2/game/edict_t.java index 377cf08..7d450f7 100644 --- a/src/lwjake2/game/edict_t.java +++ b/src/lwjake2/game/edict_t.java @@ -18,6 +18,7 @@ package lwjake2.game; +import lombok.extern.slf4j.Slf4j; import lwjake2.Defines; import lwjake2.qcommon.Com; import lwjake2.util.Lib; @@ -25,8 +26,8 @@ import lwjake2.util.QuakeFile; import java.io.IOException; +@Slf4j public class edict_t { - /** Constructor. */ public edict_t(int i) { s.number = i; @@ -768,6 +769,6 @@ public class edict_t { // rst's checker :-) if (f.readInt() != 9876) - System.err.println("ent load check failed for num " + index); + log.error("ent load check failed for num {}", index); } } \ No newline at end of file diff --git a/src/lwjake2/game/gclient_t.java b/src/lwjake2/game/gclient_t.java index 71e11ad..004e48e 100644 --- a/src/lwjake2/game/gclient_t.java +++ b/src/lwjake2/game/gclient_t.java @@ -18,13 +18,13 @@ package lwjake2.game; +import lombok.extern.slf4j.Slf4j; import lwjake2.util.QuakeFile; import java.io.IOException; -public class gclient_t -{ - +@Slf4j +public class gclient_t { public gclient_t(int index) { this.index = index; @@ -303,7 +303,7 @@ public class gclient_t update_chase = f.readInt() != 0; if (f.readInt() != 8765) - System.err.println("game client load failed for num=" + index); + log.error("game client load failed for num={}", index); } /** Writes a game_client_t (a player) to a file. */ diff --git a/src/lwjake2/game/level_locals_t.java b/src/lwjake2/game/level_locals_t.java index 6bf11d2..d253f67 100644 --- a/src/lwjake2/game/level_locals_t.java +++ b/src/lwjake2/game/level_locals_t.java @@ -18,13 +18,13 @@ package lwjake2.game; +import lombok.extern.slf4j.Slf4j; import lwjake2.util.QuakeFile; import java.io.IOException; -public class level_locals_t -{ - +@Slf4j +public class level_locals_t { // this structure is cleared as each map is entered // it is read/written to the level.sav file for savegames // @@ -149,6 +149,6 @@ public class level_locals_t // rst's checker :-) if (f.readInt()!= 4711) - System.out.println("error in reading level_locals."); + log.error("error in reading level_locals."); } } diff --git a/src/lwjake2/game/player_state_t.java b/src/lwjake2/game/player_state_t.java index 679d1cd..82fd2e2 100644 --- a/src/lwjake2/game/player_state_t.java +++ b/src/lwjake2/game/player_state_t.java @@ -176,25 +176,26 @@ public class player_state_t { } /** Prints the player state. */ - public void dump() { - pmove.dump(); - - Lib.printv("viewangles", viewangles); - Lib.printv("viewoffset", viewoffset); - Lib.printv("kick_angles", kick_angles); - Lib.printv("gunangles", gunangles); - Lib.printv("gunoffset", gunoffset); - - Com.Println("gunindex: " + gunindex); - Com.Println("gunframe: " + gunframe); - - Lib.printv("blend", blend); - - Com.Println("fov: " + fov); - - Com.Println("rdflags: " + rdflags); - - for (int n= 0; n < Defines.MAX_STATS; n++) - System.out.println("stats[" + n + "]: " + stats[n]); - } +// метод не используется =( +// public void dump() { +// pmove.dump(); +// +// Lib.printv("viewangles", viewangles); +// Lib.printv("viewoffset", viewoffset); +// Lib.printv("kick_angles", kick_angles); +// Lib.printv("gunangles", gunangles); +// Lib.printv("gunoffset", gunoffset); +// +// Com.Println("gunindex: " + gunindex); +// Com.Println("gunframe: " + gunframe); +// +// Lib.printv("blend", blend); +// +// Com.Println("fov: " + fov); +// +// Com.Println("rdflags: " + rdflags); +// +// for (int n= 0; n < Defines.MAX_STATS; n++) +// System.out.println("stats[" + n + "]: " + stats[n]); +// } } diff --git a/src/lwjake2/game/pmove_state_t.java b/src/lwjake2/game/pmove_state_t.java index 7c47866..3ce2f26 100644 --- a/src/lwjake2/game/pmove_state_t.java +++ b/src/lwjake2/game/pmove_state_t.java @@ -18,12 +18,13 @@ package lwjake2.game; -import lwjake2.qcommon.Com; +import lombok.extern.slf4j.Slf4j; import lwjake2.util.Math3D; import java.io.IOException; import java.io.RandomAccessFile; +@Slf4j public class pmove_state_t { // this structure needs to be communicated bit-accurate // from the server to the client to guarantee that @@ -129,22 +130,22 @@ public class pmove_state_t { } public void dump() { - Com.Println("pm_type: " + pm_type); + log.info("pm_type: {}", pm_type); - Com.Println("origin[0]: " + origin[0]); - Com.Println("origin[1]: " + origin[0]); - Com.Println("origin[2]: " + origin[0]); + log.info("origin[0]: {}", origin[0]); + log.info("origin[1]: {}", origin[1]); + log.info("origin[2]: {}", origin[2]); - Com.Println("velocity[0]: " + velocity[0]); - Com.Println("velocity[1]: " + velocity[1]); - Com.Println("velocity[2]: " + velocity[2]); + log.info("velocity[0]: {}", velocity[0]); + log.info("velocity[1]: {}", velocity[1]); + log.info("velocity[2]: {}", velocity[2]); - Com.Println("pmflags: " + pm_flags); - Com.Println("pmtime: " + pm_time); - Com.Println("gravity: " + gravity); + log.info("pmflags: {}", pm_flags); + log.info("pmtime: {}", pm_time); + log.info("gravity: {}", gravity); - Com.Println("delta-angle[0]: " + delta_angles[0]); - Com.Println("delta-angle[1]: " + delta_angles[0]); - Com.Println("delta-angle[2]: " + delta_angles[0]); + log.info("delta-angle[0]: {}", delta_angles[0]); + log.info("delta-angle[1]: {}", delta_angles[1]); + log.info("delta-angle[2]: {}", delta_angles[2]); } } \ No newline at end of file diff --git a/src/lwjake2/logger/log4j2/QConsoleAppender.java b/src/lwjake2/logger/log4j2/QConsoleAppender.java new file mode 100644 index 0000000..aca5cee --- /dev/null +++ b/src/lwjake2/logger/log4j2/QConsoleAppender.java @@ -0,0 +1,47 @@ +/* + * DmitriyMX + * 2017-05-12 + */ +package lwjake2.logger.log4j2; + +import lwjake2.client.Console; +import org.apache.logging.log4j.core.Filter; +import org.apache.logging.log4j.core.Layout; +import org.apache.logging.log4j.core.LogEvent; +import org.apache.logging.log4j.core.appender.AbstractAppender; +import org.apache.logging.log4j.core.config.plugins.Plugin; +import org.apache.logging.log4j.core.config.plugins.PluginAttribute; +import org.apache.logging.log4j.core.config.plugins.PluginElement; +import org.apache.logging.log4j.core.config.plugins.PluginFactory; +import org.apache.logging.log4j.core.layout.PatternLayout; + +import java.io.Serializable; + +@Plugin(name = "QConsole", category = "Core", elementType = "appender", printObject = true) +public class QConsoleAppender extends AbstractAppender { + @PluginFactory + public static QConsoleAppender createAppender ( + @PluginAttribute("name") String name, + @PluginElement("Layout") Layout layout, + @PluginElement("Filter") final Filter filter + ) { + if (name == null) { + LOGGER.error("No name provided for QConsoleAppender"); + return null; + } + if (layout == null) { + layout = PatternLayout.createDefaultLayout(); + } + return new QConsoleAppender(name, filter, layout, true); + } + + protected QConsoleAppender(String name, Filter filter, Layout layout, boolean ignoreExceptions) { + super(name, filter, layout, ignoreExceptions); + } + + @Override + public void append(LogEvent event) { + String msg = new String(getLayout().toByteArray(event)); + Console.Print(msg+"\n"); + } +} diff --git a/src/lwjake2/qcommon/Cbuf.java b/src/lwjake2/qcommon/Cbuf.java index 3e57b92..54ddffd 100644 --- a/src/lwjake2/qcommon/Cbuf.java +++ b/src/lwjake2/qcommon/Cbuf.java @@ -18,6 +18,7 @@ package lwjake2.qcommon; +import lombok.extern.slf4j.Slf4j; import lwjake2.Defines; import lwjake2.Globals; import lwjake2.game.Cmd; @@ -26,8 +27,8 @@ import lwjake2.util.Lib; /** * Cbuf */ +@Slf4j public final class Cbuf { - private static final byte[] line = new byte[1024]; private static final byte[] tmp = new byte[8192]; @@ -135,7 +136,7 @@ public final class Cbuf { int l = text.length(); if (Globals.cmd_text.cursize + l >= Globals.cmd_text.maxsize) { - Com.Printf("Cbuf_AddText: overflow\n"); + log.warn("Cbuf_AddText: overflow"); return; } SZ.Write(Globals.cmd_text, Lib.stringToBytes(text), l); diff --git a/src/lwjake2/qcommon/Com.java b/src/lwjake2/qcommon/Com.java index f64ec52..9004c2a 100644 --- a/src/lwjake2/qcommon/Com.java +++ b/src/lwjake2/qcommon/Com.java @@ -18,27 +18,24 @@ package lwjake2.qcommon; +import lombok.extern.slf4j.Slf4j; import lwjake2.Defines; import lwjake2.Globals; import lwjake2.client.CL; -import lwjake2.client.Console; import lwjake2.game.Cmd; import lwjake2.server.SV_MAIN; import lwjake2.sys.Sys; import lwjake2.util.PrintfFormat; import lwjake2.util.Vargs; -import java.io.FileNotFoundException; import java.io.IOException; -import java.io.RandomAccessFile; /** * Com * */ -public final class Com -{ - +@Slf4j +public final class Com { static String debugContext = ""; static String _debugContext = ""; @@ -342,72 +339,17 @@ public final class Com public static void Printf(String fmt, Vargs vargs) { String msg= sprintf(_debugContext + fmt, vargs); - if (rd_target != 0) - { - if ((msg.length() + rd_buffer.length()) > (rd_buffersize - 1)) - { - rd_flusher.rd_flush(rd_target, rd_buffer); - rd_buffer.setLength(0); - } - rd_buffer.append(msg); - return; - } - - Console.Print(msg); // also echo to debugging console - Sys.ConsoleOutput(msg); - - // logfile - if (Globals.logfile_active != null && Globals.logfile_active.value != 0) - { - String name; - - if (Globals.logfile == null) - { - name= FS.Gamedir() + "/qconsole.log"; - if (Globals.logfile_active.value > 2) - try - { - Globals.logfile = new RandomAccessFile(name, "rw"); - Globals.logfile.seek(Globals.logfile.length()); - } - catch (Exception e) - { - // TODO: do quake2 error handling! - e.printStackTrace(); - } - else - try - { - Globals.logfile= new RandomAccessFile(name, "rw"); - } - catch (FileNotFoundException e1) - { - // TODO: do quake2 error handling! - e1.printStackTrace(); - } - } - if (Globals.logfile != null) - try - { - Globals.logfile.writeChars(msg); - } - catch (IOException e) - { - // TODO: do quake2 error handling! - e.printStackTrace(); - } - if (Globals.logfile_active.value > 1); // do nothing - // fflush (logfile); // force it to save every time + while (msg.startsWith("\n")) { msg = msg.substring(1); } + while (msg.endsWith("\n")) { msg = msg.substring(0, msg.lastIndexOf("\n")); } + while (msg.endsWith("\r")) { msg = msg.substring(0, msg.lastIndexOf("\r")); } + msg = msg.trim(); + if (!msg.isEmpty()) { + log.warn(msg); } } - public static void Println(String fmt) - { - Printf(_debugContext + fmt + "\n"); - } - public static String sprintf(String fmt, Vargs vargs) { String msg= ""; diff --git a/src/lwjake2/qcommon/FS.java b/src/lwjake2/qcommon/FS.java index a52dedb..5d1f15f 100644 --- a/src/lwjake2/qcommon/FS.java +++ b/src/lwjake2/qcommon/FS.java @@ -18,6 +18,7 @@ package lwjake2.qcommon; +import lombok.extern.slf4j.Slf4j; import lwjake2.Defines; import lwjake2.Globals; import lwjake2.game.Cmd; @@ -42,8 +43,8 @@ import java.util.List; * * @author cwei */ +@Slf4j public final class FS extends Globals { - /* * ================================================== * @@ -143,7 +144,7 @@ public final class FS extends Globals { if (index > 0) { File f = new File(path.substring(0, index)); if (!f.mkdirs() && !f.isDirectory()) { - Com.Printf("can't create path \"" + path + '"' + "\n"); + log.warn("can't create path \"{}\"", path); } } } @@ -581,8 +582,7 @@ public final class FS extends Globals { pack.numfiles = numpackfiles; pack.files = newfiles; - Com.Printf("Added packfile " + packfile + " (" + numpackfiles - + " files)\n"); + log.info("Added packfile {} ({} files)", packfile, numpackfiles); return pack; } @@ -684,7 +684,7 @@ public final class FS extends Globals { if (dir.indexOf("..") != -1 || dir.indexOf("/") != -1 || dir.indexOf("\\") != -1 || dir.indexOf(":") != -1) { - Com.Printf("Gamedir should be a single filename, not a path\n"); + log.warn("Gamedir should be a single filename, not a path"); return; } @@ -737,7 +737,7 @@ public final class FS extends Globals { filelink_t entry = null; if (Cmd.Argc() != 3) { - Com.Printf("USAGE: link \n"); + log.info("USAGE: link "); return; } @@ -805,8 +805,8 @@ public final class FS extends Globals { if (tmp != null) tmp.replaceAll("\\\\", "/"); - Com.Printf("Directory of " + findname + '\n'); - Com.Printf("----\n"); + log.info("Directory of {}", findname); + log.info("----"); dirnames = ListFiles(findname, 0, 0); @@ -814,15 +814,13 @@ public final class FS extends Globals { int index = 0; for (int i = 0; i < dirnames.length; i++) { if ((index = dirnames[i].lastIndexOf('/')) > 0) { - Com.Printf(dirnames[i].substring(index + 1, dirnames[i] - .length()) + '\n'); + log.info(dirnames[i].substring(index + 1, dirnames[i].length())); } else { - Com.Printf(dirnames[i] + '\n'); + log.info(dirnames[i]); } } } - Com.Printf("\n"); } } @@ -834,21 +832,20 @@ public final class FS extends Globals { searchpath_t s; filelink_t link; - Com.Printf("Current search path:\n"); + log.info("Current search path:"); for (s = fs_searchpaths; s != null; s = s.next) { if (s == fs_base_searchpaths) - Com.Printf("----------\n"); + log.info("----------"); if (s.pack != null) - Com.Printf(s.pack.filename + " (" + s.pack.numfiles - + " files)\n"); + log.info("{} ({} files)", s.pack.filename, s.pack.numfiles); else - Com.Printf(s.filename + '\n'); + log.info(s.filename); } - Com.Printf("\nLinks:\n"); + log.info("Links:"); for (Iterator it = fs_links.iterator(); it.hasNext();) { link = it.next(); - Com.Printf(link.from + " : " + link.to + '\n'); + log.info("{} : {}", link.from, link.to); } } diff --git a/src/lwjake2/qcommon/Qcommon.java b/src/lwjake2/qcommon/Qcommon.java index a359ffd..caa84e1 100644 --- a/src/lwjake2/qcommon/Qcommon.java +++ b/src/lwjake2/qcommon/Qcommon.java @@ -18,6 +18,7 @@ package lwjake2.qcommon; +import lombok.extern.slf4j.Slf4j; import lwjake2.Globals; import lwjake2.client.CL; import lwjake2.client.Key; @@ -36,8 +37,8 @@ import java.io.IOException; * Qcommon contains some basic routines for the game engine * namely initialization, shutdown and frame generation. */ +@Slf4j public final class Qcommon extends Globals { - public static final String BUILDSTRING = "Java " + System.getProperty("java.version");; public static final String CPUSTRING = System.getProperty("os.arch"); @@ -122,7 +123,7 @@ public final class Qcommon extends Globals { SCR.EndLoadingPlaque(); } - Com.Printf("====== Quake2 Initialized ======\n\n"); + log.info("====== Quake2 Initialized ======"); // save config when configuration is completed CL.WriteConfiguration(); @@ -184,9 +185,7 @@ public final class Qcommon extends Globals { } if (Globals.showtrace.value != 0.0f) { - Com.Printf("%4i traces %4i points\n", - new Vargs(2).add(Globals.c_traces) - .add(Globals.c_pointcontents)); + log.info(String.format("%4d traces %4d points", Globals.c_traces, Globals.c_pointcontents)); Globals.c_traces= 0; @@ -223,8 +222,7 @@ public final class Qcommon extends Globals { sv -= gm; cl -= rf; - Com.Printf("all:%3i sv:%3i gm:%3i cl:%3i rf:%3i\n", - new Vargs(5).add(all).add(sv).add(gm).add(cl).add(rf)); + log.info(String.format("all:%3d sv:%3d gm:%3d cl:%3d rf:%3d", all, sv, gm, cl, rf)); } } catch (IllegalStateException e) { diff --git a/src/lwjake2/render/lwjgl/LWJGLBase.java b/src/lwjake2/render/lwjgl/LWJGLBase.java index 3f384db..397d367 100644 --- a/src/lwjake2/render/lwjgl/LWJGLBase.java +++ b/src/lwjake2/render/lwjgl/LWJGLBase.java @@ -18,6 +18,7 @@ package lwjake2.render.lwjgl; +import lombok.extern.slf4j.Slf4j; import lwjake2.Defines; import lwjake2.client.VID; import lwjake2.client.viddef_t; @@ -37,6 +38,7 @@ import org.lwjgl.opengl.GL11; * * @author dsanders/cwei */ +@Slf4j public abstract class LWJGLBase { // IMPORTED FUNCTIONS protected DisplayMode oldDisplayMode; @@ -206,10 +208,8 @@ public abstract class LWJGLBase { Dimension newDim = new Dimension(); - VID.Printf(Defines.PRINT_ALL, "Initializing OpenGL display\n"); + log.info("Initializing OpenGL display"); - VID.Printf(Defines.PRINT_ALL, "...setting mode " + mode + ":"); - /* * fullscreen handling */ @@ -218,11 +218,11 @@ public abstract class LWJGLBase { } if (!VID.GetModeInfo(newDim, mode)) { - VID.Printf(Defines.PRINT_ALL, " invalid mode\n"); + log.warn("...setting mode {}: invalid mode", mode); return rserr_invalid_mode; } - VID.Printf(Defines.PRINT_ALL, " " + newDim.width + " " + newDim.height + '\n'); + log.info("...setting mode {}: {} {}", mode, newDim.width, newDim.height); // destroy the existing window GLimp_Shutdown(); @@ -253,7 +253,7 @@ public abstract class LWJGLBase { return rserr_invalid_fullscreen; } - VID.Printf(Defines.PRINT_ALL, "...setting fullscreen " + getModeString(displayMode) + '\n'); + log.info("...setting fullscreen {}", getModeString(displayMode)); } else diff --git a/src/lwjake2/render/lwjgl/Main.java b/src/lwjake2/render/lwjgl/Main.java index 22b34f4..1f38e97 100644 --- a/src/lwjake2/render/lwjgl/Main.java +++ b/src/lwjake2/render/lwjgl/Main.java @@ -18,6 +18,7 @@ package lwjake2.render.lwjgl; +import lombok.extern.slf4j.Slf4j; import lwjake2.Defines; import lwjake2.Globals; import lwjake2.client.VID; @@ -52,8 +53,8 @@ import org.lwjgl.opengl.GL13; * * @author cwei */ +@Slf4j public abstract class Main extends Base { - public static int[] d_8to24table = new int[256]; int c_visible_lightmaps; @@ -1036,19 +1037,19 @@ public abstract class Main extends Base { if (err == rserr_invalid_fullscreen) { Cvar.SetValue("vid_fullscreen", 0); vid_fullscreen.modified = false; - VID.Printf(Defines.PRINT_ALL, "ref_gl::R_SetMode() - fullscreen unavailable in this mode\n"); + log.warn("ref_gl::R_SetMode() - fullscreen unavailable in this mode"); if ((err = GLimp_SetMode(dim, (int) gl_mode.value, false)) == rserr_ok) return true; } else if (err == rserr_invalid_mode) { Cvar.SetValue("gl_mode", gl_state.prev_mode); gl_mode.modified = false; - VID.Printf(Defines.PRINT_ALL, "ref_gl::R_SetMode() - invalid mode\n"); + log.warn("ref_gl::R_SetMode() - invalid mode"); } // try setting it back to something safe if ((err = GLimp_SetMode(dim, gl_state.prev_mode, false)) != rserr_ok) { - VID.Printf(Defines.PRINT_ALL, "ref_gl::R_SetMode() - could not revert to safe mode\n"); + log.warn("ref_gl::R_SetMode() - could not revert to safe mode"); return false; } } @@ -1069,7 +1070,7 @@ public abstract class Main extends Base { r_turbsin[j] = Warp.SIN[j] * 0.5f; } - VID.Printf(Defines.PRINT_ALL, "ref_gl version: " + REF_VERSION + '\n'); + log.info("ref_gl version: {}", REF_VERSION); Draw_GetPalette(); @@ -1080,7 +1081,7 @@ public abstract class Main extends Base { // create the window and set up the context if (!R_SetMode()) { - VID.Printf(Defines.PRINT_ALL, "ref_gl::R_Init() - could not R_SetMode()\n"); + log.info("ref_gl::R_Init() - could not R_SetMode()"); return false; } return true; @@ -1096,13 +1097,13 @@ public abstract class Main extends Base { ** get our various GL strings */ gl_config.vendor_string = GL11.glGetString(GL11.GL_VENDOR); - VID.Printf(Defines.PRINT_ALL, "GL_VENDOR: " + gl_config.vendor_string + '\n'); + log.info("GL_VENDOR: {}", gl_config.vendor_string); gl_config.renderer_string = GL11.glGetString(GL11.GL_RENDERER); - VID.Printf(Defines.PRINT_ALL, "GL_RENDERER: " + gl_config.renderer_string + '\n'); + log.info("GL_RENDERER: {}", gl_config.renderer_string); gl_config.version_string = GL11.glGetString(GL11.GL_VERSION); - VID.Printf(Defines.PRINT_ALL, "GL_VERSION: " + gl_config.version_string + '\n'); + log.info("GL_VERSION: {}", gl_config.version_string); gl_config.extensions_string = GL11.glGetString(GL11.GL_EXTENSIONS); - VID.Printf(Defines.PRINT_ALL, "GL_EXTENSIONS: " + gl_config.extensions_string + '\n'); + log.info("GL_EXTENSIONS: {}", gl_config.extensions_string); gl_config.parseOpenGLVersion(); @@ -1136,7 +1137,7 @@ public abstract class Main extends Base { if (monolightmap.length() < 2 || monolightmap.charAt(1) != 'F') { if (gl_config.renderer == GL_RENDERER_PERMEDIA2) { Cvar.Set("gl_monolightmap", "A"); - VID.Printf(Defines.PRINT_ALL, "...using gl_monolightmap 'a'\n"); + log.info("...using gl_monolightmap 'a'"); } else if ((gl_config.renderer & GL_RENDERER_POWERVR) != 0) { Cvar.Set("gl_monolightmap", "0"); @@ -1171,16 +1172,16 @@ public abstract class Main extends Base { } if (gl_config.allow_cds) - VID.Printf(Defines.PRINT_ALL, "...allowing CDS\n"); + log.info("...allowing CDS"); else - VID.Printf(Defines.PRINT_ALL, "...disabling CDS\n"); + log.info("...disabling CDS"); /* ** grab extensions */ if (gl_config.extensions_string.indexOf("GL_EXT_compiled_vertex_array") >= 0 || gl_config.extensions_string.indexOf("GL_SGI_compiled_vertex_array") >= 0) { - VID.Printf(Defines.PRINT_ALL, "...enabling GL_EXT_compiled_vertex_array\n"); + log.info("...enabling GL_EXT_compiled_vertex_array"); // qglLockArraysEXT = ( void * ) qwglGetProcAddress( "glLockArraysEXT" ); if (gl_ext_compiled_vertex_array.value != 0.0f) qglLockArraysEXT = true; @@ -1190,16 +1191,16 @@ public abstract class Main extends Base { //qglUnlockArraysEXT = true; } else { - VID.Printf(Defines.PRINT_ALL, "...GL_EXT_compiled_vertex_array not found\n"); + log.info("...GL_EXT_compiled_vertex_array not found"); qglLockArraysEXT = false; } if (gl_config.extensions_string.indexOf("WGL_EXT_swap_control") >= 0) { qwglSwapIntervalEXT = true; - VID.Printf(Defines.PRINT_ALL, "...enabling WGL_EXT_swap_control\n"); + log.info("...enabling WGL_EXT_swap_control"); } else { qwglSwapIntervalEXT = false; - VID.Printf(Defines.PRINT_ALL, "...WGL_EXT_swap_control not found\n"); + log.info("...WGL_EXT_swap_control not found"); } if (gl_config.extensions_string.indexOf("GL_EXT_point_parameters") >= 0) { @@ -1207,14 +1208,14 @@ public abstract class Main extends Base { // qglPointParameterfEXT = ( void (APIENTRY *)( GLenum, GLfloat ) ) qwglGetProcAddress( "glPointParameterfEXT" ); qglPointParameterfEXT = true; // qglPointParameterfvEXT = ( void (APIENTRY *)( GLenum, const GLfloat * ) ) qwglGetProcAddress( "glPointParameterfvEXT" ); - VID.Printf(Defines.PRINT_ALL, "...using GL_EXT_point_parameters\n"); + log.info("...using GL_EXT_point_parameters"); } else { - VID.Printf(Defines.PRINT_ALL, "...ignoring GL_EXT_point_parameters\n"); + log.info("...ignoring GL_EXT_point_parameters"); } } else { - VID.Printf(Defines.PRINT_ALL, "...GL_EXT_point_parameters not found\n"); + log.info("...GL_EXT_point_parameters not found"); } // #ifdef __linux__ @@ -1241,26 +1242,26 @@ public abstract class Main extends Base { && gl_config.extensions_string.indexOf("GL_EXT_paletted_texture") >= 0 && gl_config.extensions_string.indexOf("GL_EXT_shared_texture_palette") >= 0) { if (gl_ext_palettedtexture.value != 0.0f) { - VID.Printf(Defines.PRINT_ALL, "...using GL_EXT_shared_texture_palette\n"); + log.info("...using GL_EXT_shared_texture_palette"); qglColorTableEXT = false; // true; TODO jogl bug } else { - VID.Printf(Defines.PRINT_ALL, "...ignoring GL_EXT_shared_texture_palette\n"); + log.info("...ignoring GL_EXT_shared_texture_palette"); qglColorTableEXT = false; } } else { - VID.Printf(Defines.PRINT_ALL, "...GL_EXT_shared_texture_palette not found\n"); + log.info("...GL_EXT_shared_texture_palette not found"); } if (gl_config.extensions_string.indexOf("GL_ARB_multitexture") >= 0) { - VID.Printf(Defines.PRINT_ALL, "...using GL_ARB_multitexture\n"); + log.info("...using GL_ARB_multitexture"); qglActiveTextureARB = true; GL_TEXTURE0 = ARBMultitexture.GL_TEXTURE0_ARB; GL_TEXTURE1 = ARBMultitexture.GL_TEXTURE1_ARB; } else { - VID.Printf(Defines.PRINT_ALL, "...GL_ARB_multitexture not found\n"); + log.info("...GL_ARB_multitexture not found"); } if (!(qglActiveTextureARB)) diff --git a/src/lwjake2/server/SV_CCMDS.java b/src/lwjake2/server/SV_CCMDS.java index e1f3dac..fbbb684 100644 --- a/src/lwjake2/server/SV_CCMDS.java +++ b/src/lwjake2/server/SV_CCMDS.java @@ -18,6 +18,7 @@ package lwjake2.server; +import lombok.extern.slf4j.Slf4j; import lwjake2.Defines; import lwjake2.Globals; import lwjake2.game.Cmd; @@ -47,8 +48,8 @@ import java.io.IOException; import java.io.RandomAccessFile; import java.util.Calendar; +@Slf4j public class SV_CCMDS { - /* =============================================================================== @@ -767,45 +768,46 @@ public class SV_CCMDS { Com.Printf("No server running.\n"); return; } - Com.Printf("map : " + SV_INIT.sv.name + "\n"); + log.info("map : {}", SV_INIT.sv.name); - Com.Printf("num score ping name lastmsg address qport \n"); - Com.Printf("--- ----- ---- --------------- ------- --------------------- ------\n"); + log.info("num score ping name lastmsg address qport "); + log.info("--- ----- ---- --------------- ------- --------------------- ------"); for (i = 0; i < SV_MAIN.maxclients.value; i++) { cl = SV_INIT.svs.clients[i]; if (0 == cl.state) continue; - Com.Printf("%3i ", new Vargs().add(i)); - Com.Printf("%5i ", new Vargs().add(cl.edict.client.ps.stats[Defines.STAT_FRAGS])); + StringBuilder sb = new StringBuilder(); + sb.append(String.format("%3d ", i)) + .append(String.format("%5d ", cl.edict.client.ps.stats[Defines.STAT_FRAGS])); if (cl.state == Defines.cs_connected) - Com.Printf("CNCT "); + sb.append("CNCT "); else if (cl.state == Defines.cs_zombie) - Com.Printf("ZMBI "); + sb.append("ZMBI "); else { ping = cl.ping < 9999 ? cl.ping : 9999; - Com.Printf("%4i ", new Vargs().add(ping)); + sb.append(String.format("%4d ", ping)); } - Com.Printf("%s", new Vargs().add(cl.name)); + sb.append(cl.name); l = 16 - cl.name.length(); for (j = 0; j < l; j++) - Com.Printf(" "); + sb.append(' '); - Com.Printf("%7i ", new Vargs().add(SV_INIT.svs.realtime - cl.lastmessage)); + sb.append(String.format("%7d ", (SV_INIT.svs.realtime - cl.lastmessage))); s = NET.AdrToString(cl.netchan.remote_address); - Com.Printf(s); + sb.append(s); l = 22 - s.length(); for (j = 0; j < l; j++) - Com.Printf(" "); + sb.append(' '); - Com.Printf("%5i", new Vargs().add(cl.netchan.qport)); + sb.append(String.format("%5d", cl.netchan.qport)); - Com.Printf("\n"); + log.info(sb.toString()); } - Com.Printf("\n"); + log.info(""); } /* ================== diff --git a/src/lwjake2/server/SV_INIT.java b/src/lwjake2/server/SV_INIT.java index d2f96b9..613109b 100644 --- a/src/lwjake2/server/SV_INIT.java +++ b/src/lwjake2/server/SV_INIT.java @@ -18,6 +18,7 @@ package lwjake2.server; +import lombok.extern.slf4j.Slf4j; import lwjake2.Defines; import lwjake2.Globals; import lwjake2.client.CL; @@ -42,8 +43,8 @@ import lwjake2.util.Math3D; import java.io.IOException; import java.io.RandomAccessFile; +@Slf4j public class SV_INIT { - /** * SV_FindIndex. */ @@ -185,7 +186,7 @@ public class SV_INIT { if (attractloop) Cvar.Set("paused", "0"); - Com.Printf("------- Server Initialization -------\n"); + log.info("------- Server Initialization -------"); Com.DPrintf("SpawnServer: " + server + "\n"); if (sv.demofile != null) @@ -320,7 +321,7 @@ public class SV_INIT { if (Cvar.VariableValue("coop") != 0 && Cvar.VariableValue("deathmatch") != 0) { - Com.Printf("Deathmatch and Coop both set, disabling Coop\n"); + log.info("Deathmatch and Coop both set, disabling Coop"); Cvar.FullSet("coop", "0", Defines.CVAR_SERVERINFO | Defines.CVAR_LATCH); } diff --git a/src/lwjake2/server/SV_MAIN.java b/src/lwjake2/server/SV_MAIN.java index c712666..69d1928 100644 --- a/src/lwjake2/server/SV_MAIN.java +++ b/src/lwjake2/server/SV_MAIN.java @@ -18,6 +18,7 @@ package lwjake2.server; +import lombok.extern.slf4j.Slf4j; import lwjake2.Defines; import lwjake2.Globals; import lwjake2.game.Cmd; @@ -39,9 +40,9 @@ import lwjake2.util.Lib; import java.io.IOException; +@Slf4j public class SV_MAIN { - - /** Address of group servers. */ + /** Address of group servers. */ public static netadr_t master_adr[] = new netadr_t[Defines.MAX_MASTERS]; diff --git a/src/lwjake2/sound/S.java b/src/lwjake2/sound/S.java index deac602..819766f 100644 --- a/src/lwjake2/sound/S.java +++ b/src/lwjake2/sound/S.java @@ -18,6 +18,7 @@ package lwjake2.sound; +import lombok.extern.slf4j.Slf4j; import lwjake2.Defines; import lwjake2.game.cvar_t; import lwjake2.qcommon.Com; @@ -29,8 +30,8 @@ import java.util.Vector; /** * S */ +@Slf4j public class S { - static Sound impl; static cvar_t s_impl; @@ -93,11 +94,11 @@ public class S { */ public static void Init() { - Com.Printf("\n------- sound initialization -------\n"); + log.info("------- sound initialization -------"); cvar_t cv = Cvar.Get("s_initsound", "1", 0); if (cv.value == 0.0f) { - Com.Printf("not initializing.\n"); + log.info("not initializing."); useDriver("dummy"); return; } @@ -119,7 +120,7 @@ public class S { useDriver("dummy"); } - Com.Printf("\n------- use sound driver \"" + impl.getName() + "\" -------\n"); + log.info("------- use sound driver \"{}\" -------", impl.getName()); StopAllSounds(); } diff --git a/src/lwjake2/sound/WaveLoader.java b/src/lwjake2/sound/WaveLoader.java index 00740a8..50e56ab 100644 --- a/src/lwjake2/sound/WaveLoader.java +++ b/src/lwjake2/sound/WaveLoader.java @@ -18,6 +18,7 @@ package lwjake2.sound; +import lombok.extern.slf4j.Slf4j; import lwjake2.Defines; import lwjake2.qcommon.Com; import lwjake2.qcommon.FS; @@ -25,8 +26,8 @@ import lwjake2.qcommon.FS; /** * SND_MEM */ +@Slf4j public class WaveLoader { - /** * The ResampleSfx can squeeze and stretch samples to a default sample rate. * Since Joal and lwjgl sound drivers support this, we don't need it and the samples @@ -227,7 +228,7 @@ public class WaveLoader { return; } if (iff_chunk_len > 1024*1024) { - Com.Println(" Warning: FindNextChunk: length is past the 1 meg sanity limit"); + log.warn("Warning: FindNextChunk: length is past the 1 meg sanity limit"); } data_p -= 8; last_chunk = data_p + 8 + ((iff_chunk_len + 1) & ~1); diff --git a/src/lwjake2/sound/lwjgl/LWJGLSoundImpl.java b/src/lwjake2/sound/lwjgl/LWJGLSoundImpl.java index bb1a5bd..473dec2 100644 --- a/src/lwjake2/sound/lwjgl/LWJGLSoundImpl.java +++ b/src/lwjake2/sound/lwjgl/LWJGLSoundImpl.java @@ -18,6 +18,7 @@ package lwjake2.sound.lwjgl; +import lombok.extern.slf4j.Slf4j; import lwjake2.Defines; import lwjake2.Globals; import lwjake2.game.Cmd; @@ -54,8 +55,8 @@ import org.lwjgl.openal.OpenALException; * * @author dsanders/cwei */ +@Slf4j public final class LWJGLSoundImpl implements Sound { - static { S.register(new LWJGLSoundImpl()); }; @@ -84,7 +85,7 @@ public final class LWJGLSoundImpl implements Sound { checkError(); initOpenALExtensions(); } catch (OpenALException e) { - Com.Printf(e.getMessage() + '\n'); + log.error(e.getMessage()); return false; } catch (Exception e) { Com.DPrintf(e.getMessage() + '\n'); @@ -95,7 +96,7 @@ public final class LWJGLSoundImpl implements Sound { s_volume = Cvar.Get("s_volume", "0.7", Defines.CVAR_ARCHIVE); AL10.alGenBuffers(buffers); int count = Channel.init(buffers); - Com.Printf("... using " + count + " channels\n"); + log.info("... using {} channels", count); AL10.alDistanceModel(AL10.AL_INVERSE_DISTANCE_CLAMPED); Cmd.AddCommand("play", new Runnable() { public void run() { @@ -120,10 +121,10 @@ public final class LWJGLSoundImpl implements Sound { num_sfx = 0; - Com.Printf("sound sampling rate: 44100Hz\n"); + log.info("sound sampling rate: 44100Hz"); StopAllSounds(); - Com.Printf("------------------------------------\n"); + log.info("------------------------------------"); return true; } @@ -140,7 +141,7 @@ public final class LWJGLSoundImpl implements Sound { String defaultSpecifier = ALC10.alcGetString(AL.getDevice(), ALC10.ALC_DEFAULT_DEVICE_SPECIFIER); - Com.Printf(os + " using " + ((deviceName == null) ? defaultSpecifier : deviceName) + '\n'); + log.info("{} using {}", os, ((deviceName == null) ? defaultSpecifier : deviceName)); // Check for an error. if (ALC10.alcGetError(AL.getDevice()) != ALC10.ALC_NO_ERROR) @@ -152,7 +153,7 @@ public final class LWJGLSoundImpl implements Sound { /** Initializes OpenAL EFX effects. */ private void initOpenALExtensions() { - Com.Printf("... using EFX effects:\n"); + log.info("... using EFX effects:"); underwaterFilter = new EFXFilterLowPass(); underwaterFilter.setGain(1.0f); underwaterFilter.setGainHF(0.0f); @@ -585,27 +586,26 @@ public final class LWJGLSoundImpl implements Sound { if (sc != null) { size = sc.length * sc.width * (sc.stereo + 1); total += size; - if (sc.loopstart >= 0) - Com.Printf("L"); - else - Com.Printf(" "); - Com.Printf("(%2db) %6i : %s\n", new Vargs(3).add(sc.width * 8).add(size).add(sfx.name)); + log.info(String.format("%s(%2db) %6d : %s", + (sc.loopstart >= 0 ? 'L' : ' '), + (sc.width * 8), size, sfx.name) + ); } else { if (sfx.name.charAt(0) == '*') - Com.Printf(" placeholder : " + sfx.name + "\n"); + log.info(" placeholder : {}", sfx.name); else - Com.Printf(" not loaded : " + sfx.name + "\n"); + log.info(" not loaded : {}", sfx.name); } } - Com.Printf("Total resident: " + total + "\n"); + log.info("Total resident: {}", total); } void SoundInfo_f() { - - Com.Printf("%5d stereo\n", new Vargs(1).add(1)); - Com.Printf("%5d samples\n", new Vargs(1).add(22050)); - Com.Printf("%5d samplebits\n", new Vargs(1).add(16)); - Com.Printf("%5d speed\n", new Vargs(1).add(44100)); + //TODO параметры тут не нужны, сплошная статика + log.info(String.format("%5d stereo", 1)); + log.info(String.format("%5d samples", 22050)); + log.info(String.format("%5d samplebits", 16)); + log.info(String.format("%5d speed", 44100)); } } diff --git a/src/lwjake2/sound/lwjgl/PlaySound.java b/src/lwjake2/sound/lwjgl/PlaySound.java index 14e681d..d1331c8 100644 --- a/src/lwjake2/sound/lwjgl/PlaySound.java +++ b/src/lwjake2/sound/lwjgl/PlaySound.java @@ -18,6 +18,7 @@ package lwjake2.sound.lwjgl; +import lombok.extern.slf4j.Slf4j; import lwjake2.Globals; import lwjake2.util.Math3D; @@ -26,8 +27,8 @@ import lwjake2.util.Math3D; * * @author cwei */ +@Slf4j public class PlaySound { - final static int MAX_PLAYSOUNDS = 128; // list with sentinel @@ -155,7 +156,7 @@ public class PlaySound { ps.beginTime = Globals.cl.time + (long)(timeoffset * 1000); PlaySound.add(ps); } else { - System.err.println("PlaySounds out of Limit"); + log.error("PlaySounds out of Limit"); } } } diff --git a/src/lwjake2/sys/NET.java b/src/lwjake2/sys/NET.java index 6b02b34..aaae6d2 100644 --- a/src/lwjake2/sys/NET.java +++ b/src/lwjake2/sys/NET.java @@ -18,6 +18,7 @@ package lwjake2.sys; +import lombok.extern.slf4j.Slf4j; import lwjake2.Defines; import lwjake2.Globals; import lwjake2.game.cvar_t; @@ -35,8 +36,8 @@ import java.net.SocketAddress; import java.nio.ByteBuffer; import java.nio.channels.DatagramChannel; +@Slf4j public final class NET { - private final static int MAX_LOOPBACK = 4; /** Local loopback adress. */ @@ -136,7 +137,7 @@ public final class NET { a.port = Lib.atoi(address[1]); return true; } catch (Exception e) { - Com.Println(e.getMessage()); + log.error(e.getMessage()); return false; } } @@ -227,7 +228,7 @@ public final class NET { int packetLength = receiveBuffer.position(); if (packetLength > net_message.maxsize) { - Com.Println("Oversize packet from " + AdrToString(net_from)); + log.info("Oversize packet from {}", AdrToString(net_from)); return false; } @@ -265,7 +266,7 @@ public final class NET { SocketAddress dstSocket = new InetSocketAddress(to.getInetAddress(), to.port); ip_channels[sock].send(ByteBuffer.wrap(data, 0, length), dstSocket); } catch (Exception e) { - Com.Println("NET_SendPacket ERROR: " + e + " to " + AdrToString(to)); + log.error(String.format("NET_SendPacket: %s to %s", e.getMessage(), AdrToString(to)), e); } } @@ -345,7 +346,7 @@ public final class NET { // the socket have to be broadcastable newsocket.setBroadcast(true); } catch (Exception e) { - Com.Println("Error: " + e.toString()); + log.error(String.format("Error: %s", e.getMessage()), e); newsocket = null; } return newsocket; diff --git a/src/lwjake2/sys/Sys.java b/src/lwjake2/sys/Sys.java index 62ccc1a..77cb5fd 100644 --- a/src/lwjake2/sys/Sys.java +++ b/src/lwjake2/sys/Sys.java @@ -18,6 +18,7 @@ package lwjake2.sys; +import lombok.extern.slf4j.Slf4j; import lwjake2.Defines; import lwjake2.Globals; import lwjake2.client.CL; @@ -31,8 +32,8 @@ import java.util.regex.PatternSyntaxException; /** * Sys */ +@Slf4j public final class Sys extends Defines { - public static void Error(String error) { CL.Shutdown(); @@ -226,11 +227,4 @@ public final class Sys extends Defines { return null; } - public static void ConsoleOutput(String msg) { - if (Globals.nostdout != null && Globals.nostdout.value != 0) - return; - - System.out.print(msg); - } - } \ No newline at end of file diff --git a/src/lwjake2/sys/Timer.java b/src/lwjake2/sys/Timer.java index b8825c8..59b3c39 100644 --- a/src/lwjake2/sys/Timer.java +++ b/src/lwjake2/sys/Timer.java @@ -18,11 +18,11 @@ package lwjake2.sys; +import lombok.extern.slf4j.Slf4j; import lwjake2.Globals; -import lwjake2.qcommon.Com; +@Slf4j public abstract class Timer { - abstract public long currentTimeMillis(); static Timer t; @@ -33,7 +33,7 @@ public abstract class Timer { } catch (Throwable e) { t = new StandardTimer(); } - Com.Println("using " + t.getClass().getName()); + log.info("using {}", t.getClass().getName()); } public static int Milliseconds() { diff --git a/src/lwjake2/util/Lib.java b/src/lwjake2/util/Lib.java index e99d287..5bba8b3 100644 --- a/src/lwjake2/util/Lib.java +++ b/src/lwjake2/util/Lib.java @@ -18,6 +18,7 @@ package lwjake2.util; +import lombok.extern.slf4j.Slf4j; import lwjake2.Globals; import lwjake2.qcommon.Com; import lwjake2.qcommon.FS; @@ -31,9 +32,8 @@ import java.nio.ByteOrder; import java.nio.FloatBuffer; import java.nio.IntBuffer; +@Slf4j public class Lib { - - /** Converts a vector to a string. */ public static String vtos(float[] v) { return (int) v[0] + " " + (int) v[1] + " " + (int) v[2]; @@ -197,7 +197,7 @@ public class Lib { /** Prints a vector to the quake console. */ public static void printv(String in, float arr[]) { for (int n = 0; n < arr.length; n++) { - Com.Println(in + "[" + n + "]: " + arr[n]); + log.info("{}[{}]: {}", in, n, arr[n]); } }