From 4f1dfc455771a79e5cf16626db7787668314a41c Mon Sep 17 00:00:00 2001 From: Gabor Bata Date: Thu, 5 Oct 2023 14:15:49 +0200 Subject: [PATCH] Use logger instead of println --- src/automap/Map.java | 2 +- src/awt/DoomWindowController.java | 6 +- src/defines/DoomVersion.java | 7 +- src/doom/CVarManager.java | 14 +- src/doom/ConfigManager.java | 13 +- src/doom/DoomMain.java | 155 +++++++----------- src/doom/wbplayerstruct_t.java | 8 +- src/doom/wbstartstruct_t.java | 7 +- src/f/EndLevel.java | 6 +- src/i/DoomSystem.java | 27 ++- src/i/system.java | 10 +- src/m/DelegateRandom.java | 9 +- src/m/Menu.java | 9 +- src/m/MenuMisc.java | 17 +- src/mochadoom/Engine.java | 5 +- src/mochadoom/Loggers.java | 12 ++ src/n/BasicNetworkInterface.java | 15 +- src/p/AbstractLevelLoader.java | 33 ++-- src/p/ActionFunctions.java | 4 +- src/p/Actions/ActionsSlideDoors.java | 4 +- src/p/BoomLevelLoader.java | 62 +++---- src/p/LevelLoader.java | 22 +-- src/p/mobj_t.java | 7 +- src/p/plat_t.java | 8 +- src/pooling/ObjectPool.java | 11 +- src/pooling/ObjectQueuePool.java | 6 +- src/rr/RendererState.java | 100 +++++------ src/rr/SimpleTextureManager.java | 38 +++-- src/rr/SpriteManager.java | 12 +- src/rr/UnifiedRenderer.java | 9 +- src/rr/VisSprites.java | 7 +- src/rr/Visplanes.java | 9 +- src/rr/drawfuns/R_DrawColumnBoom.java | 20 ++- src/rr/parallel/AbstractParallelRenderer.java | 9 +- src/rr/parallel/MaskedWorker.java | 11 +- src/rr/parallel/ParallelRenderer.java | 9 +- src/rr/parallel/ParallelRenderer2.java | 12 +- src/rr/parallel/ParallelThings.java | 9 +- src/rr/parallel/ParallelThings2.java | 7 +- src/rr/parallel/RenderMaskedExecutor.java | 6 +- src/rr/parallel/RenderSegExecutor.java | 7 +- src/rr/parallel/RenderWallExecutor.java | 6 +- src/rr/parallel/VisplaneWorker.java | 7 +- src/rr/parallel/VisplaneWorker2.java | 7 +- src/rr/sector_t.java | 6 +- src/s/AbstractDoomAudio.java | 13 +- src/s/AbstractSoundDriver.java | 10 +- src/s/ClassicDoomSoundDriver.java | 39 +++-- src/s/ClipSFXModule.java | 21 ++- src/s/DSP.java | 2 +- src/s/DavidMusicModule.java | 14 +- src/s/DavidSFXModule.java | 38 +++-- src/s/DoomIO.java | 10 +- src/s/DoomToWave.java | 17 +- src/s/FinnwMusicModule.java | 9 +- src/s/ISoundDriver.java | 6 +- src/s/QMusToMid.java | 62 +++---- src/s/SpeakerDoomSoundDriver.java | 7 +- src/s/SuperDoomSoundDriver.java | 43 ++--- src/s/VolumeScalingReceiver.java | 6 +- src/savegame/VanillaDSG.java | 10 +- src/timing/NanoTicker.java | 7 +- src/utils/C2JUtils.java | 46 ++---- src/utils/OrderedExecutor.java | 6 +- src/utils/ResourceIO.java | 9 +- src/v/graphics/Columns.java | 5 +- src/v/graphics/Patches.java | 4 +- src/v/renderers/BufferedRenderer16.java | 6 +- src/v/renderers/BufferedRenderer32.java | 6 +- src/w/DoomIO.java | 7 +- src/w/IWadLoader.java | 10 +- src/w/JadDecompress.java | 8 +- src/w/WadLoader.java | 44 ++--- 73 files changed, 708 insertions(+), 527 deletions(-) diff --git a/src/automap/Map.java b/src/automap/Map.java index c091ed24..02e3de59 100644 --- a/src/automap/Map.java +++ b/src/automap/Map.java @@ -783,7 +783,7 @@ public final void initVariables() { // find player to center on initially if (!DOOM.playeringame[pnum = DOOM.consoleplayer]) { for (pnum = 0; pnum < MAXPLAYERS; pnum++) { - System.out.println(pnum); + //System.out.println(pnum); if (DOOM.playeringame[pnum]) { break; } diff --git a/src/awt/DoomWindowController.java b/src/awt/DoomWindowController.java index eb5618b5..8298d8e8 100644 --- a/src/awt/DoomWindowController.java +++ b/src/awt/DoomWindowController.java @@ -26,6 +26,7 @@ import java.util.function.Consumer; import java.util.function.Supplier; import java.util.logging.Level; +import java.util.logging.Logger; import m.Settings; import mochadoom.Engine; import mochadoom.Loggers; @@ -36,6 +37,7 @@ * That sort of things. */ public class DoomWindowController, H extends Enum & EventBase> implements FullscreenOptions { + private static final Logger LOGGER = Loggers.getLogger(DoomWindow.class.getName()); private static final long ALL_EVENTS_MASK = 0xFFFF_FFFF_FFFF_FFFFL; @@ -82,7 +84,7 @@ private void sizeInit() { updateSize(); } } catch (Exception e) { - Loggers.getLogger(DoomWindow.class.getName()).log(Level.SEVERE, + LOGGER.log(Level.SEVERE, String.format("Error creating DOOM AWT frame. Exiting. Reason: %s", e.getMessage()), e); throw e; } @@ -97,7 +99,7 @@ public EventObserver getObserver() { } public boolean switchFullscreen() { - Loggers.getLogger(DoomFrame.class.getName()).log(Level.WARNING, "FULLSCREEN SWITHED"); + LOGGER.log(Level.INFO, "FULLSCREEN SWITHED"); // remove the frame from view doomFrame.dispose(); doomFrame = new DoomFrame<>(dimension, component, doomFrame.imageSupplier); diff --git a/src/defines/DoomVersion.java b/src/defines/DoomVersion.java index e1268e6c..1fc4d286 100644 --- a/src/defines/DoomVersion.java +++ b/src/defines/DoomVersion.java @@ -18,6 +18,7 @@ import doom.DoomMain; import java.util.logging.Level; +import java.util.logging.Logger; import mochadoom.Loggers; import utils.C2JUtils; import static utils.C2JUtils.testReadAccess; @@ -42,6 +43,8 @@ private DoomVersion(String wadFileName) { this.wadFileName = wadFileName; } + private static final Logger LOGGER = Loggers.getLogger(DoomVersion.class.getName()); + /** * Try all versions in given doomwaddir * @@ -56,7 +59,7 @@ public static String tryAllWads(final DoomMain DOOM, final String doomwadd // C'est ridicule! // Let's handle languages in config files, okay? DOOM.language = Language_t.french; - System.out.println("French version\n"); + //System.out.println("French version\n"); } return vFullPath; @@ -85,7 +88,7 @@ public static GameMode tryOnlyOne(String iwad, String doomwaddir) { } } catch (IllegalArgumentException ex) { - Loggers.getLogger(DoomVersion.class.getName()).log(Level.WARNING, iwad, ex); + LOGGER.log(Level.WARNING, iwad, ex); } // It's either invalid or we can't read it. diff --git a/src/doom/CVarManager.java b/src/doom/CVarManager.java index 1a08288b..b140b03f 100644 --- a/src/doom/CVarManager.java +++ b/src/doom/CVarManager.java @@ -25,6 +25,7 @@ import java.util.Optional; import java.util.function.Consumer; import java.util.logging.Level; +import java.util.logging.Logger; import mochadoom.Loggers; import utils.ResourceIO; @@ -38,11 +39,14 @@ * @author Good Sign */ public class CVarManager { + private static final Logger LOGGER = Loggers.getLogger(CVarManager.class.getName()); + private final EnumMap cVarMap = new EnumMap<>(CommandVariable.class); public CVarManager(final List commandList) { - System.out.println(processAllArgs(commandList) + " command-line variables"); + LOGGER.log(Level.INFO, + String.format("%d command-line variables", processAllArgs(commandList))); } /** @@ -156,9 +160,9 @@ public boolean override(final CommandVariable cv, final T value, final int p private void readResponseFile(final String filename) { final ResponseReader r = new ResponseReader(); if (new ResourceIO(filename).readLines(r)) { - System.out.println(String.format("Found response file %s, read %d command line variables", filename, r.cVarCount)); + LOGGER.log(Level.INFO,String.format("Found response file %s, read %d command line variables", filename, r.cVarCount)); } else { - System.out.println(String.format("No such response file %s!", filename)); + LOGGER.log(Level.WARNING,String.format("No such response file %s!", filename)); System.exit(1); } } @@ -251,7 +255,7 @@ private Object formatArgValue(final Class format, final String arg) { try { return Integer.parseInt(arg); } catch (NumberFormatException ex) { - Loggers.getLogger(CommandVariable.class.getName()).log(Level.WARNING, null, ex); + LOGGER.log(Level.WARNING, "formatArgValue failure", ex); return null; } } else if (format == String.class) { @@ -265,7 +269,7 @@ private Object formatArgValue(final Class format, final String arg) { | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { - Loggers.getLogger(CommandVariable.class.getName()).log(Level.SEVERE, null, ex); + LOGGER.log(Level.SEVERE, "formatArgValue failure", ex); return null; } } diff --git a/src/doom/ConfigManager.java b/src/doom/ConfigManager.java index c1bf4047..9897b676 100644 --- a/src/doom/ConfigManager.java +++ b/src/doom/ConfigManager.java @@ -24,9 +24,12 @@ import java.util.List; import java.util.Objects; import java.util.Optional; +import java.util.logging.Level; +import java.util.logging.Logger; import java.util.regex.Pattern; import m.Settings; import static m.Settings.SETTINGS_MAP; +import mochadoom.Loggers; import utils.ParseString; import utils.QuoteType; import utils.ResourceIO; @@ -38,6 +41,8 @@ */ public class ConfigManager { + private static final Logger LOGGER = Loggers.getLogger(ConfigManager.class.getName()); + private static final Pattern SPLITTER = Pattern.compile("[ \t\n\r\f]+"); private final List configFiles = ConfigBase.getFiles(); @@ -224,7 +229,7 @@ private void LoadDefaults() { configMap.put(setting, setting.defaultValue); }); - System.out.print("M_LoadDefaults: Load system defaults.\n"); + LOGGER.log(Level.INFO, "M_LoadDefaults: Load system defaults."); this.configFiles.forEach(file -> { final Optional maybeRIO = file.firstValidPathIO(); @@ -240,7 +245,7 @@ private void LoadDefaults() { } private boolean readFoundConfig(Files file, ResourceIO rio) { - System.out.print(String.format("M_LoadDefaults: Using config %s.\n", rio.getFileame())); + LOGGER.log(Level.INFO, String.format("M_LoadDefaults: Using config %s.", rio.getFileame())); if (rio.readLines(line -> { final String[] split = SPLITTER.split(line, 2); if (split.length < 2) { @@ -256,7 +261,7 @@ private boolean readFoundConfig(Files file, ResourceIO rio) { .orElse(split[1]); if (update(setting, value) == UpdateStatus.INVALID) { - System.err.printf("WARNING: invalid config value for: %s in %s \n", name, rio.getFileame()); + LOGGER.log(Level.WARNING, String.format("WARNING: invalid config value for: %s in %s", name, rio.getFileame())); } else { setting.rebase(file); } @@ -267,7 +272,7 @@ private boolean readFoundConfig(Files file, ResourceIO rio) { } // Something went bad, but this won't destroy successfully read values, though. - System.err.printf("Can't read the settings file %s\n", rio.getFileame()); + LOGGER.log(Level.SEVERE, String.format("Can't read the settings file %s", rio.getFileame())); return false; } diff --git a/src/doom/DoomMain.java b/src/doom/DoomMain.java index 39fa7645..5f0474ab 100644 --- a/src/doom/DoomMain.java +++ b/src/doom/DoomMain.java @@ -143,6 +143,8 @@ import java.io.OutputStreamWriter; import java.util.Arrays; import java.util.Objects; +import java.util.logging.Level; +import java.util.logging.Logger; import java.util.stream.Collectors; import m.DelegateRandom; import m.IDoomMenu; @@ -152,6 +154,7 @@ import static m.fixed_t.FRACBITS; import static m.fixed_t.MAPFRACUNIT; import mochadoom.Engine; +import mochadoom.Loggers; import n.DoomSystemNetworking; import n.DummyNetworkDriver; import p.AbstractLevelLoader; @@ -225,6 +228,8 @@ }) public class DoomMain extends DoomStatus implements IDoomGameNetworking, IDoomGame, IDoom { + private static final Logger LOGGER = Loggers.getLogger(DoomMain.class.getName()); + public static final String RCSID = "$Id: DoomMain.java,v 1.109 2012/11/06 16:04:58 velktron Exp $"; // @@ -510,12 +515,11 @@ public void DoomLoop() throws IOException { { if (cVarManager.bool(CommandVariable.DEBUGFILE)) { String filename = "debug" + consoleplayer + ".txt"; - System.out.println("debug output to: " + filename); + LOGGER.log(Level.INFO, String.format("Debug output to: %s", filename)); try { debugfile = new OutputStreamWriter(new FileOutputStream(filename)); } catch (FileNotFoundException e) { - System.err.println("Couldn't open debugfile. Now, that sucks some putrid shit out of John Romero's asshole!"); - e.printStackTrace(); + LOGGER.log(Level.SEVERE, "Couldn't open debugfile.", e); } } } @@ -739,7 +743,7 @@ public final String IdentifyVersion() { // First, check for -iwad parameter. // If valid, then it trumps all others. if (cVarManager.present(CommandVariable.IWAD)) { - System.out.println("-iwad specified. Will be used with priority\n"); + LOGGER.log(Level.INFO, "-iwad specified. Will be used with priority"); // It might be quoted. final String test = C2JUtils.unquoteIfQuoted(cVarManager.get(CommandVariable.IWAD, String.class, 0).get(), '"'); final String separator = System.getProperty("file.separator"); @@ -759,7 +763,7 @@ public final String IdentifyVersion() { doomwaddir = System.getenv("DOOMWADDIR"); if (doomwaddir != null) { - System.out.println("DOOMWADDIR found. Will be used with priority\n"); + LOGGER.log(Level.INFO, "DOOMWADDIR found. Will be used with priority"); } // None found, using current. @@ -776,7 +780,7 @@ public final String IdentifyVersion() { final String wadFullPath = DoomVersion.tryAllWads(this, doomwaddir); if (wadFullPath == null) { - System.out.println("Game mode indeterminate.\n"); + LOGGER.log(Level.INFO, "Game mode indeterminate."); setGameMode(GameMode.indetermined); // We don't abort. Let's see what the PWAD contains. //exit(1); @@ -816,7 +820,7 @@ protected final void CheckForPWADSInShareware() { // Oh yes I can. if (isShareware()) { - System.out.println("\nYou cannot -file with the shareware version. Register!"); + LOGGER.log(Level.WARNING, "You cannot -file with the shareware version. Register!"); } // Check for fake IWAD with right name, @@ -824,7 +828,7 @@ protected final void CheckForPWADSInShareware() { if (isRegistered()) { for (i = 0; i < 23; i++) { if (wadLoader.CheckNumForName(name[i].toUpperCase()) < 0) { - doomSystem.Error("\nThis is not the registered version: " + name[i]); + doomSystem.Error("This is not the registered version: " + name[i]); } } } @@ -868,99 +872,73 @@ protected boolean CheckForLumps(String[] name, WadLoader W) { return true; } - /** - * - */ protected final void GenerateTitle() { switch (getGameMode()) { case retail: - title.append(" "); title.append("The Ultimate DOOM Startup v"); title.append(VERSION / 100); title.append("."); title.append(VERSION % 100); - title.append(" "); break; case shareware: - title.append(" "); title.append("DOOM Shareware Startup v"); title.append(VERSION / 100); title.append("."); title.append(VERSION % 100); - title.append(" "); break; case registered: - title.append(" "); title.append("DOOM Registered Startup v"); title.append(VERSION / 100); title.append("."); title.append(VERSION % 100); - title.append(" "); break; case commercial: - title.append(" "); title.append("DOOM 2: Hell on Earth v"); title.append(VERSION / 100); title.append("."); title.append(VERSION % 100); - title.append(" "); - break; case pack_plut: - title.append(" "); title.append("DOOM 2: Plutonia Experiment v"); title.append(VERSION / 100); title.append("."); title.append(VERSION % 100); - title.append(" "); break; case pack_tnt: - title.append(" "); title.append("DOOM 2: TNT - Evilution v"); title.append(VERSION / 100); title.append("."); title.append(VERSION % 100); - title.append(" "); break; case pack_xbla: - title.append(" "); title.append("DOOM 2: No Rest for the Living v"); title.append(VERSION / 100); title.append("."); title.append(VERSION % 100); - title.append(" "); break; case freedm: - title.append(" "); - title.append("FreeDM v"); + title.append("FreeDM v"); title.append(VERSION / 100); title.append("."); title.append(VERSION % 100); - title.append(" "); break; case freedoom1: - title.append(" "); - title.append("FreeDoom: Phase 1 v"); + title.append("FreeDoom: Phase 1 v"); title.append(VERSION / 100); title.append("."); title.append(VERSION % 100); - title.append(" "); break; case freedoom2: - title.append(" "); - title.append("FreeDoom: Phase 2 v"); + title.append("FreeDoom: Phase 2 v"); title.append(VERSION / 100); title.append("."); title.append(VERSION % 100); - title.append(" "); break; default: - title.append(" "); title.append("Public DOOM - v"); title.append(VERSION / 100); title.append("."); title.append(VERSION % 100); - title.append(" "); break; } } @@ -1053,12 +1031,10 @@ private void BuildTiccmd(ticcmd_t cmd) { } if (gamekeydown[key_up]) { - //System.err.print("up\n"); forward += forwardmove[speed]; } if (gamekeydown[key_down]) { - //System.err.print("down\n"); forward -= forwardmove[speed]; } @@ -1078,17 +1054,14 @@ private void BuildTiccmd(ticcmd_t cmd) { // Look up/down/center keys if (gamekeydown[key_lookup]) { - System.err.print("Look up\n"); look = lspeed; } if (gamekeydown[key_lookdown]) { - System.err.print("Look down\n"); look = -lspeed; } if (gamekeydown[key_lookcenter]) { - System.err.print("Center look\n"); look = TOCENTER; } @@ -2515,8 +2488,8 @@ public void DoPlayDemo() { final int version; if (fail || ((version = demobuffer.getVersion() & 0xFF) & ~JAVARANDOM_MASK) != VERSION) { - System.err.println("Demo is from a different game version!\n"); - System.err.println("Version code read: " + demobuffer.getVersion()); + LOGGER.log(Level.WARNING, String.format("Demo is from a different game version, version code read: %d", + demobuffer.getVersion())); gameaction = ga_nothing; return; } @@ -2700,7 +2673,7 @@ public DoomMain() throws IOException { // Random number generator, but we can have others too. this.random = new DelegateRandom(); - System.out.print(String.format("M_Random: Using %s.\n", random.getClass().getSimpleName())); + LOGGER.log(Level.INFO, String.format("M_Random: Using %s.", random.getClass().getSimpleName())); // Sound can be left until later, in Start this.wadLoader = new WadLoader(this.doomSystem); // The wadloader is a "weak" status holder. @@ -2728,8 +2701,8 @@ public DoomMain() throws IOException { this.finale = selectFinale(); readCVars(); - System.out.printf("W_Init: Init WAD files: [%s]\n", - Arrays.stream(wadfiles).filter(Objects::nonNull).collect(Collectors.joining(", "))); + LOGGER.log(Level.INFO, String.format("W_Init: Init WAD files: [%s]", + Arrays.stream(wadfiles).filter(Objects::nonNull).collect(Collectors.joining(", ")))); try { wadLoader.InitMultipleFiles(wadfiles); } catch (Exception e1) { @@ -2742,13 +2715,13 @@ public DoomMain() throws IOException { .setVideoScale(vs).setBppMode(bppMode).setWadLoader(wadLoader) .build(); - System.out.print("V_Init: allocate screens.\n"); + LOGGER.log(Level.INFO, "V_Init: allocate screens."); // Disk access visualizer this.diskDrawer = new DiskDrawer(this, DiskDrawer.STDISK); // init subsystems - System.out.print("AM_Init: Init Automap colors - \n"); + LOGGER.log(Level.INFO, "AM_Init: Init Automap colors"); this.autoMap = new automap.Map<>(this); this.wiper = graphicSystem.createWiper(random); @@ -2761,26 +2734,25 @@ public DoomMain() throws IOException { printGameInfo(); - System.out.print("Tables.InitTables: Init trigonometric LUTs.\n"); + LOGGER.log(Level.INFO, "Tables.InitTables: Init trigonometric LUTs."); Tables.InitTables(); - System.out.print("M_Init: Init miscellaneous info.\n"); + LOGGER.log(Level.INFO, "M_Init: Init miscellaneous info."); menu.Init(); - System.out.print("R_Init: Init DOOM refresh daemon - "); + LOGGER.log(Level.INFO, "R_Init: Init DOOM refresh daemon"); sceneRenderer.Init(); - System.out.print("\nP_Init: Init Playloop state.\n"); + LOGGER.log(Level.INFO, "P_Init: Init Playloop state."); actions.Init(); - System.out.print("I_Init: Setting up machine state.\n"); + LOGGER.log(Level.INFO, "I_Init: Setting up machine state."); doomSystem.Init(); - System.out.print("D_CheckNetGame: Checking network game status.\n"); + LOGGER.log(Level.INFO, "D_CheckNetGame: Checking network game status."); CheckNetGame(); - System.out.print("S_Init: Setting up sound.\n"); - + LOGGER.log(Level.INFO, "S_Init: Setting up sound."); // Sound "drivers" before the game sound controller. this.music = IMusic.chooseModule(cVarManager); this.soundDriver = ISoundDriver.chooseModule(this, cVarManager); @@ -2789,14 +2761,14 @@ public DoomMain() throws IOException { music.InitMusic(); doomSound.Init(snd_SfxVolume * 8, snd_MusicVolume * 8); - System.out.print("HU_Init: Setting up heads up display.\n"); + LOGGER.log(Level.INFO, "HU_Init: Setting up heads up display."); headsUp.Init(); - System.out.print("ST_Init: Init status bar.\n"); + LOGGER.log(Level.INFO, "ST_Init: Init status bar."); statusBar.Init(); if (statcopy != null) { - System.out.print("External statistics registered.\n"); + LOGGER.log(Level.INFO, "External statistics registered."); } // NOW it's safe to init the disk reader. @@ -2842,7 +2814,7 @@ public void setupLoop() throws IOException { cVarManager.with(CommandVariable.STATCOPY, 0, (String s) -> { // TODO: this should be chained to a logger statcopy = s; - System.out.print("External statistics registered.\n"); + LOGGER.log(Level.INFO, "External statistics registered."); }); // start the apropriate game based on parms @@ -2897,9 +2869,7 @@ private void printGameInfo() { switch (getGameMode()) { case shareware: case indetermined: - System.out.print("===========================================================================\n"); - System.out.print(" Shareware!\n"); - System.out.print("===========================================================================\n"); + LOGGER.log(Level.INFO, "Game info: Shareware!"); break; case registered: case retail: @@ -2907,19 +2877,14 @@ private void printGameInfo() { case pack_tnt: case pack_plut: case pack_xbla: - System.out.print("===========================================================================\n"); - System.out.print(" Commercial product - do not distribute!\n"); - System.out.print(" Please report software piracy to the SPA: 1-800-388-PIR8\n"); - System.out.print("===========================================================================\n"); + LOGGER.log(Level.INFO, "Game info: Commercial product - do not distribute!"); + LOGGER.log(Level.INFO, "Game note: Please report software piracy to the SPA: 1-800-388-PIR8"); break; case freedoom1: case freedoom2: case freedm: - System.out.print("===========================================================================\n"); - System.out.print(" Copyright © 2001-2017 Contributors to the Freedoom project.\n"); - System.out.print(" All rights reserved.\n"); - System.out.print(" See: https://github.com/freedoom/freedoom/blob/master/COPYING.adoc\n"); - System.out.print("===========================================================================\n"); + LOGGER.log(Level.INFO, "Game info: Copyright (c) 2001-2017 Contributors to the Freedoom project. All rights reserved."); + LOGGER.log(Level.INFO, "Game note: See https://github.com/freedoom/freedoom/blob/master/COPYING.adoc"); break; default: // Ouch. @@ -2962,19 +2927,19 @@ private void readCVars() { GenerateTitle(); // Print ticker info. It has already been set at Init() though. if (cVarManager.bool(CommandVariable.MILLIS)) { - System.out.println("ITicker: Using millisecond accuracy timer."); + LOGGER.log(Level.INFO, "ITicker: Using millisecond accuracy timer."); } else if (cVarManager.bool(CommandVariable.FASTTIC)) { - System.out.println("ITicker: Using fastest possible timer."); + LOGGER.log(Level.INFO, "ITicker: Using fastest possible timer."); } else { - System.out.println("ITicker: Using nanosecond accuracy timer."); + LOGGER.log(Level.INFO, "ITicker: Using nanosecond accuracy timer."); } - System.out.println(title.toString()); + LOGGER.log(Level.INFO, title.toString()); if (devparm) { - System.out.println(D_DEVSTR); + LOGGER.log(Level.INFO, D_DEVSTR); } // Running from CDROM? if (cVarManager.bool(CommandVariable.CDROM)) { - System.out.println(D_CDROM); + LOGGER.log(Level.INFO, D_CDROM); //System.get("c:\\doomdata",0); //System.out.println (Settings.basedefault+"c:/doomdata/default.cfg"); } @@ -2990,7 +2955,7 @@ private void readCVars() { if (scale > 400) { scale = 400; } - System.out.println("turbo scale: " + scale); + LOGGER.log(Level.INFO, String.format("turbo scale: %d", scale)); forwardmove[0] = forwardmove[0] * scale / 100; forwardmove[1] = forwardmove[1] * scale / 100; sidemove[0] = sidemove[0] * scale / 100; @@ -3050,7 +3015,7 @@ private void readCVars() { normaldemo = true; loaddemo = cVarManager.get(CommandVariable.PLAYDEMO, String.class, 0).get(); } else if (cVarManager.present(CommandVariable.FASTDEMO)) { - System.out.println("Fastdemo mode. Boundless clock!"); + LOGGER.log(Level.INFO, "Fastdemo mode. Boundless clock!"); fastdemo = true; loaddemo = cVarManager.get(CommandVariable.FASTDEMO, String.class, 0).get(); } else if (cVarManager.present(CommandVariable.TIMEDEMO)) { @@ -3062,7 +3027,7 @@ private void readCVars() { if (loaddemo != null) { loaddemo = C2JUtils.unquoteIfQuoted(loaddemo, '"'); AddFile(loaddemo + ".lmp"); - System.out.printf("Playing demo %s.lmp.\n", loaddemo); + LOGGER.log(Level.INFO, String.format("Playing demo %s.lmp.", loaddemo)); autostart = true; } @@ -3081,9 +3046,9 @@ private void readCVars() { .isPresent(); if (!novert) { - System.out.println("-novert ENABLED (default)"); + LOGGER.log(Level.INFO, "-novert ENABLED (default)"); } else { - System.out.println("-novert DISABLED. Hope you know what you're doing..."); + LOGGER.log(Level.INFO, "-novert DISABLED. Hope you know what you're doing..."); } } @@ -3101,15 +3066,11 @@ private void readCVars() { if (cVarManager.present(CommandVariable.TIMER) && deathmatch) { // Good Sign (2017/03/31) How this should work? final int time = cVarManager.get(CommandVariable.TIMER, Integer.class, 0).get(); - System.out.print("Levels will end after " + time + " minute"); - if (time > 1) { - System.out.print("s"); - } - System.out.print(".\n"); + LOGGER.log(Level.INFO, String.format("Levels will end after %d minute(s)", time)); } // OK, and exactly how is this enforced? if (cVarManager.bool(CommandVariable.AVG) && deathmatch) { - System.out.print("Austin Virtual Gaming: Levels will end after 20 minutes\n"); + LOGGER.log(Level.INFO, "Austin Virtual Gaming: Levels will end after 20 minutes"); } // MAES 31/5/2011: added support for +map variation. @@ -3634,7 +3595,7 @@ public void ArbitrateNetStart() throws IOException { memset(gotinfo, false, gotinfo.length); if (doomcom.consoleplayer != 0) { // listen for setup info from key player - System.out.println("listening for network start info...\n"); + LOGGER.log(Level.INFO, "listening for network start info..."); while (true) { CheckAbort(); if (!HGetPacket()) { @@ -3663,7 +3624,7 @@ public void ArbitrateNetStart() throws IOException { } } else { // key player, send the setup info - System.out.println("sending network start info...\n"); + LOGGER.log(Level.INFO, "sending network start info..."); do { CheckAbort(); for (i = 0; i < doomcom.numnodes; i++) { @@ -3735,8 +3696,8 @@ private void CheckNetGame() throws IOException { ArbitrateNetStart(); } - System.out.printf("startskill %s deathmatch: %s startmap: %d startepisode: %d\n", - startskill.toString(), Boolean.toString(deathmatch), startmap, startepisode); + LOGGER.log(Level.INFO, String.format("D_CheckNetGame: startskill %s deathmatch: %s startmap: %d startepisode: %d", + startskill.toString(), Boolean.toString(deathmatch), startmap, startepisode)); // read values out of doomcom ticdup = doomcom.ticdup; @@ -3754,7 +3715,7 @@ private void CheckNetGame() throws IOException { nodeingame[i] = true; } - System.out.printf("player %d of %d (%d nodes)\n", (consoleplayer + 1), doomcom.numplayers, doomcom.numnodes); + LOGGER.log(Level.INFO, String.format("D_CheckNetGame: player %d of %d (%d nodes)", (consoleplayer + 1), doomcom.numplayers, doomcom.numnodes)); } /** @@ -3870,13 +3831,13 @@ public void TryRunTics() throws IOException { } else { if (nettics[0] <= nettics[nodeforplayer[i]]) { gametime--; - System.out.print("-"); + //System.out.print("-"); } frameskip[frameon & 3] = oldnettics > nettics[nodeforplayer[i]]; oldnettics = nettics[0]; if (frameskip[0] && frameskip[1] && frameskip[2] && frameskip[3]) { skiptics = 1; - System.out.print("+"); + //System.out.print("+"); } } } // demoplayback diff --git a/src/doom/wbplayerstruct_t.java b/src/doom/wbplayerstruct_t.java index fb7de333..58a2555a 100644 --- a/src/doom/wbplayerstruct_t.java +++ b/src/doom/wbplayerstruct_t.java @@ -1,10 +1,16 @@ package doom; // + +import java.util.logging.Level; +import java.util.logging.Logger; +import mochadoom.Loggers; + // INTERMISSION // Structure passed e.g. to WI_Start(wb) // public class wbplayerstruct_t implements Cloneable { + private static final Logger LOGGER = Loggers.getLogger(wbplayerstruct_t.class.getName()); public wbplayerstruct_t() { frags = new int[4]; @@ -25,7 +31,7 @@ public wbplayerstruct_t clone() { try { r = (wbplayerstruct_t) super.clone(); } catch (CloneNotSupportedException e) { - e.printStackTrace(); + LOGGER.log(Level.SEVERE, "wbplayerstruct_t: clone failure", e); } /*r.in=this.in; r.skills=this.skills; diff --git a/src/doom/wbstartstruct_t.java b/src/doom/wbstartstruct_t.java index 43c79a63..7b09f1f2 100644 --- a/src/doom/wbstartstruct_t.java +++ b/src/doom/wbstartstruct_t.java @@ -1,9 +1,13 @@ package doom; import static data.Limits.MAXPLAYERS; +import java.util.logging.Level; +import java.util.logging.Logger; +import mochadoom.Loggers; import static utils.GenericCopy.malloc; public class wbstartstruct_t implements Cloneable { + private static final Logger LOGGER = Loggers.getLogger(wbstartstruct_t.class.getName()); public wbstartstruct_t() { plyr = malloc(wbplayerstruct_t::new, wbplayerstruct_t[]::new, MAXPLAYERS); @@ -36,8 +40,7 @@ public wbstartstruct_t clone() { try { cl = (wbstartstruct_t) super.clone(); } catch (CloneNotSupportedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + LOGGER.log(Level.SEVERE, "wbstartstruct_t: clone failure", e); } /*cl.epsd=this.epsd; cl.didsecret=this.didsecret; diff --git a/src/f/EndLevel.java b/src/f/EndLevel.java index 33b1321f..2e9bf488 100644 --- a/src/f/EndLevel.java +++ b/src/f/EndLevel.java @@ -150,6 +150,9 @@ import doom.player_t; import doom.wbplayerstruct_t; import doom.wbstartstruct_t; +import java.util.logging.Level; +import java.util.logging.Logger; +import mochadoom.Loggers; import rr.patch_t; import static v.DoomGraphicSystem.V_NOSCALESTART; import static v.DoomGraphicSystem.V_SAFESCALE; @@ -163,6 +166,7 @@ * */ public class EndLevel extends AbstractEndLevel { + private static final Logger LOGGER = Loggers.getLogger(EndLevel.class.getName()); ////////////////// STATUS /////////////////// private final DoomMain DOOM; @@ -439,7 +443,7 @@ protected void drawEL() { DOOM.graphicSystem.DrawPatchScaled(FG, c[i], DOOM.vs, lnodes[wbs.epsd][n].x, lnodes[wbs.epsd][n].y); } else { // DEBUG - System.out.println("Could not place patch on level " + n + 1); + LOGGER.log(Level.FINE, String.format("Could not place patch on level %d", n + 1)); } } diff --git a/src/i/DoomSystem.java b/src/i/DoomSystem.java index df54d8da..2dd4b5ac 100644 --- a/src/i/DoomSystem.java +++ b/src/i/DoomSystem.java @@ -109,13 +109,16 @@ import doom.DoomMain; import doom.ticcmd_t; import java.io.IOException; +import java.util.logging.Level; +import java.util.logging.Logger; +import mochadoom.Loggers; public class DoomSystem implements IDoomSystem { + private static final Logger LOGGER = Loggers.getLogger(DoomSystem.class.getName()); + public static void MiscError(String error, Object... args) { - System.err.print("Error: "); - System.err.print(error); - System.err.print("\n"); + LOGGER.log(Level.SEVERE, String.format("Error: %s", error)); } static int mb_used = 6; @@ -159,8 +162,7 @@ public void Quit() { try { DM.QuitNetGame(); } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + LOGGER.log(Level.SEVERE, "Error: Quit() / DM.QuitNetGame()", e); } //DM.debugEnd(); /** @@ -187,8 +189,7 @@ public void WaitVBL(int count) { try { Thread.sleep(count * 1000 / 70); } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + LOGGER.log(Level.SEVERE, "Error: WaitVBL / Thread.sleep()", e); } } @@ -218,12 +219,9 @@ public void AllocLow(int length) { // @Override public void Error(String error, Object... args) { + LOGGER.log(Level.SEVERE, String.format("Error: " + error, args)); - System.err.print("Error: "); - System.err.printf(error, args); - System.err.print("\n"); //va_end (argptr); - //fflush( stderr ); // Shutdown. Here might be other errors. if (DM.demorecording) { @@ -233,8 +231,7 @@ public void Error(String error, Object... args) { try { DM.QuitNetGame(); } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + LOGGER.log(Level.SEVERE, "Error: Error() / DM.QuitNetGame()", e); } // DM.VI.ShutdownGraphics(); @@ -247,9 +244,7 @@ public void Error(String error) { // Message first. //va_start (argptr,error); - System.err.print("Error: "); - System.err.printf(error); - System.err.print("\n"); + LOGGER.log(Level.SEVERE, String.format("Error: %s", error)); //va_end (argptr); //fflush( stderr ); diff --git a/src/i/system.java b/src/i/system.java index 1f06dc25..98d2e113 100644 --- a/src/i/system.java +++ b/src/i/system.java @@ -38,8 +38,14 @@ //----------------------------------------------------------------------------- package i; +import java.util.logging.Level; +import java.util.logging.Logger; +import mochadoom.Loggers; + public class system { + private static final Logger LOGGER = Loggers.getLogger(system.class.getName()); + /* #include #include @@ -175,9 +181,7 @@ public static void Error(String error, Object... args) { // Message first. //va_start (argptr,error); - System.err.print("Error: "); - System.err.printf(error, args); - System.err.print("\n"); + LOGGER.log(Level.SEVERE, String.format("Error: " + error, args)); //va_end (argptr); //fflush( stderr ); diff --git a/src/m/DelegateRandom.java b/src/m/DelegateRandom.java index 29ff0b9a..734a085c 100644 --- a/src/m/DelegateRandom.java +++ b/src/m/DelegateRandom.java @@ -22,6 +22,9 @@ import static doom.SourceCode.M_Random.M_ClearRandom; import static doom.SourceCode.M_Random.M_Random; import static doom.SourceCode.M_Random.P_Random; +import java.util.logging.Level; +import java.util.logging.Logger; +import mochadoom.Loggers; import p.ActiveStates; import utils.C2JUtils; @@ -42,6 +45,8 @@ */ public class DelegateRandom implements IRandom { + private static final Logger LOGGER = Loggers.getLogger(DelegateRandom.class.getName()); + private IRandom random; private IRandom altRandom; @@ -62,11 +67,11 @@ private void switchRandom(boolean which) { if (arandom != null && ((!which && arandom instanceof DoomRandom) || (which && arandom instanceof JavaRandom))) { this.altRandom = random; this.random = arandom; - System.out.print(String.format("M_Random: Switching to %s\n", random.getClass().getSimpleName())); + LOGGER.log(Level.INFO, String.format("M_Random: Switching to %s\n", random.getClass().getSimpleName())); } else { this.altRandom = random; this.random = which ? new JavaRandom() : new DoomRandom(); - System.out.print(String.format("M_Random: Switching to %s (new instance)\n", random.getClass().getSimpleName())); + LOGGER.log(Level.INFO, String.format("M_Random: Switching to %s (new instance)\n", random.getClass().getSimpleName())); } //random.ClearRandom(); } diff --git a/src/m/Menu.java b/src/m/Menu.java index f81583f3..f54bb269 100644 --- a/src/m/Menu.java +++ b/src/m/Menu.java @@ -47,6 +47,9 @@ import java.io.DataInputStream; import java.io.FileInputStream; import java.io.IOException; +import java.util.logging.Level; +import java.util.logging.Logger; +import mochadoom.Loggers; import rr.patch_t; import timing.DelegateTicker; import utils.C2JUtils; @@ -54,6 +57,7 @@ import w.DoomIO; public class Menu extends AbstractDoomMenu { + private static final Logger LOGGER = Loggers.getLogger(Menu.class.getName()); ////////////////// CONSTRUCTOR //////////////// public Menu(DoomMain DOOM) { @@ -1163,7 +1167,7 @@ && StringWidth(savegamestrings[saveSlot]) < (SAVESTRINGSIZE - 2) * 8) { } } else if (sc == SC_F5 && DOOM.ticker instanceof DelegateTicker) { // Toggle ticker ((DelegateTicker) DOOM.ticker).changeTicker(); - System.err.println("Warning! Ticker changed; time reset"); + LOGGER.log(Level.WARNING,"Warning! Ticker changed; time reset"); DOOM.doomSound.StartSound(null, sfxenum_t.sfx_radio); return true; } @@ -1762,8 +1766,7 @@ public void invoke(int choice) { // Yet another hack... if (!DOOM.isRetail() && (choice > 2)) { - System.err - .print("M_Episode: 4th episode requires UltimateDOOM\n"); + LOGGER.log(Level.WARNING,"M_Episode: 4th episode requires UltimateDOOM"); choice = 0; } diff --git a/src/m/MenuMisc.java b/src/m/MenuMisc.java index 5e6a5c01..236cb662 100644 --- a/src/m/MenuMisc.java +++ b/src/m/MenuMisc.java @@ -16,7 +16,10 @@ import java.io.OutputStream; import java.nio.ByteBuffer; import java.util.Arrays; +import java.util.logging.Level; +import java.util.logging.Logger; import javax.imageio.ImageIO; +import mochadoom.Loggers; import w.IWritableDoomObject; // Emacs style mode select -*- C++ -*- @@ -45,6 +48,8 @@ //----------------------------------------------------------------------------- public abstract class MenuMisc { + private static final Logger LOGGER = Loggers.getLogger(MenuMisc.class.getName()); + public static final String rcsid = "$Id: MenuMisc.java,v 1.29 2012/09/24 17:16:22 velktron Exp $"; // @@ -188,16 +193,14 @@ public static int ReadFile(String name, byte[] buffer) { f = new DataOutputStream(new FileOutputStream(filename)); } catch (FileNotFoundException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + LOGGER.log(Level.SEVERE, "WritePCXfile: not found", e); } try { //f.setLength(0); pcx.write(f); } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + LOGGER.log(Level.SEVERE, "WritePCXfile: I/O error", e); } } @@ -214,7 +217,7 @@ public static void WritePNGfile(String imagename, short[] linear, int width, int try { ImageIO.write(buf, "PNG", new File(imagename)); } catch (IOException e) { - e.printStackTrace(); + LOGGER.log(Level.SEVERE, "WritePNGfile: I/O error", e); } } @@ -226,7 +229,7 @@ public static void WritePNGfile(String imagename, int[] linear, int width, int h try { ImageIO.write(buf, "PNG", new File(imagename)); } catch (IOException e) { - e.printStackTrace(); + LOGGER.log(Level.SEVERE, "WritePNGfile: I/O error", e); } } @@ -238,7 +241,7 @@ public static void WritePNGfile(String imagename, byte[] linear, int width, int try { ImageIO.write(buf, "PNG", new File(imagename)); } catch (IOException e) { - e.printStackTrace(); + LOGGER.log(Level.SEVERE, "WritePNGfile: I/O error", e); } } } diff --git a/src/mochadoom/Engine.java b/src/mochadoom/Engine.java index db848d33..ee785a21 100644 --- a/src/mochadoom/Engine.java +++ b/src/mochadoom/Engine.java @@ -37,6 +37,7 @@ import java.util.logging.Logger; public class Engine { + private static final Logger LOGGER = Logger.getLogger(Engine.class.getName()); private static volatile Engine instance; @@ -62,7 +63,7 @@ public static void main(final String[] argv) throws IOException { try { local.DOOM.setupLoop(); } catch (Exception e) { - e.printStackTrace(); + LOGGER.log(Level.SEVERE, "DOOM.setupLoop failure", e); System.exit(1); } } @@ -157,7 +158,7 @@ public static Engine getEngine() { try { Engine.instance = local = new Engine(); } catch (IOException ex) { - Logger.getLogger(Engine.class.getName()).log(Level.SEVERE, null, ex); + LOGGER.log(Level.SEVERE, "Engine I/O error", ex); throw new Error("This launch is DOOMed"); } } diff --git a/src/mochadoom/Loggers.java b/src/mochadoom/Loggers.java index 6f7f2f90..14877dff 100644 --- a/src/mochadoom/Loggers.java +++ b/src/mochadoom/Loggers.java @@ -21,6 +21,10 @@ import awt.EventBase.ActionMode; import awt.EventBase.ActionStateHolder; import awt.EventBase.RelationType; +import doom.CVarManager; +import doom.ConfigManager; +import doom.DoomMain; +import i.DoomSystem; import java.awt.AWTEvent; import java.io.OutputStream; import java.util.Arrays; @@ -44,6 +48,10 @@ */ public class Loggers { + static { + System.setProperty("java.util.logging.SimpleFormatter.format", "[%1$tF %1$tT] [%4$-7s] [%3$-20s] %5$s %n"); + } + private static final Level DEFAULT_LEVEL = Level.WARNING; private static final Map PARENT_LOGGERS_MAP = Stream.of( @@ -59,6 +67,10 @@ public class Loggers { INDIVIDUAL_CLASS_LOGGERS.put(ActiveStates.class.getName(), PARENT_LOGGERS_MAP.get(Level.FINER)); INDIVIDUAL_CLASS_LOGGERS.put(DoomWindow.class.getName(), PARENT_LOGGERS_MAP.get(Level.FINE)); INDIVIDUAL_CLASS_LOGGERS.put(Patches.class.getName(), PARENT_LOGGERS_MAP.get(Level.INFO)); + INDIVIDUAL_CLASS_LOGGERS.put(ConfigManager.class.getName(), PARENT_LOGGERS_MAP.get(Level.INFO)); + INDIVIDUAL_CLASS_LOGGERS.put(DoomMain.class.getName(), PARENT_LOGGERS_MAP.get(Level.INFO)); + INDIVIDUAL_CLASS_LOGGERS.put(DoomSystem.class.getName(), PARENT_LOGGERS_MAP.get(Level.INFO)); + INDIVIDUAL_CLASS_LOGGERS.put(CVarManager.class.getName(), PARENT_LOGGERS_MAP.get(Level.INFO)); } public static Logger getLogger(final String className) { diff --git a/src/n/BasicNetworkInterface.java b/src/n/BasicNetworkInterface.java index a6fbea8d..c6da7e96 100644 --- a/src/n/BasicNetworkInterface.java +++ b/src/n/BasicNetworkInterface.java @@ -16,6 +16,9 @@ import java.net.SocketException; import java.net.SocketTimeoutException; import java.net.UnknownHostException; +import java.util.logging.Level; +import java.util.logging.Logger; +import mochadoom.Loggers; import w.DoomBuffer; // Emacs style mode select -*- C++ -*- @@ -62,6 +65,8 @@ // //----------------------------------------------------------------------------- public class BasicNetworkInterface implements DoomSystemNetworking { + static final Logger LOGGER = Loggers.getLogger(BasicNetworkInterface.class.getName()); + protected DoomMain DOOM; @@ -183,7 +188,6 @@ public void invoke() { sendPacket.setSocketAddress(sendsocket.getRemoteSocketAddress()); sendSocketPacket(sendsocket, sendPacket); } catch (Exception e) { - e.printStackTrace(); DOOM.doomSystem.Error("SendPacket error: %s", e.getMessage()); } @@ -240,7 +244,7 @@ public void invoke() { sb.append(" 0x"); sb.append(DoomBuffer.getBEInt(recvData.retransmitfrom, recvData.starttic, recvData.player, recvData.numtics)); sb.append("numtics: ").append(recvData.numtics); - System.out.println(sb.toString()); + LOGGER.log(Level.FINE, sb.toString()); first = false; } } @@ -325,7 +329,7 @@ public void InitNetwork() { DOOM.cVarManager.with(CommandVariable.PORT, 0, (Integer port) -> { DOOMPORT = port; - System.out.println("using alternate port " + DOOMPORT); + LOGGER.log(Level.INFO, String.format("using alternate port %d", DOOMPORT)); }); // parse network game options, @@ -364,7 +368,7 @@ public void InitNetwork() { sendaddress[doomcom.numnodes] = ds; } catch (SocketException | UnknownHostException e) { - e.printStackTrace(); + LOGGER.log(Level.SEVERE, "InitNetwork: failure", e); } doomcom.numnodes++; @@ -380,8 +384,7 @@ public void InitNetwork() { insocket.setSoTimeout(1); insocket.bind(new InetSocketAddress(RECVPORT)); } catch (SocketException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); + LOGGER.log(Level.SEVERE, "InitNetwork: failure", e1); } } diff --git a/src/p/AbstractLevelLoader.java b/src/p/AbstractLevelLoader.java index 6a5593ff..4940ae8c 100644 --- a/src/p/AbstractLevelLoader.java +++ b/src/p/AbstractLevelLoader.java @@ -14,10 +14,13 @@ import doom.SourceCode.R_Main; import static doom.SourceCode.R_Main.R_PointInSubsector; import doom.SourceCode.fixed_t; +import java.util.logging.Level; +import java.util.logging.Logger; import m.BBox; import m.Settings; import static m.fixed_t.FRACBITS; import mochadoom.Engine; +import mochadoom.Loggers; import static p.mobj_t.MF_NOBLOCKMAP; import static p.mobj_t.MF_NOSECTOR; import rr.line_t; @@ -41,6 +44,7 @@ * @author velktron */ public abstract class AbstractLevelLoader implements ILevelLoader { + private static final Logger LOGGER = Loggers.getLogger(AbstractLevelLoader.class.getName()); // ///////////////// Status objects /////////////////// final DoomMain DOOM; @@ -554,8 +558,8 @@ protected final void CreateBlockMap() { long b = System.nanoTime(); - System.err.printf("Blockmap generated in %f sec\n", (b - a) / 1e9); - System.err.printf("Time spend in AddBlockLine : %f sec\n", total / 1e9); + LOGGER.log(Level.WARNING, String.format("Blockmap generated in %f sec", (b - a) / 1e9)); + LOGGER.log(Level.WARNING, String.format("Time spend in AddBlockLine : %f sec", total / 1e9)); } // jff 10/6/98 @@ -581,7 +585,7 @@ protected boolean VerifyBlockMap(int count) { // check that block offset is in bounds if (blockoffset >= p_maxoffs) { - System.err.printf("P_VerifyBlockMap: block offset overflow\n"); + LOGGER.log(Level.WARNING, String.format("P_VerifyBlockMap: block offset overflow")); return false; } @@ -589,7 +593,7 @@ protected boolean VerifyBlockMap(int count) { // check that list offset is in bounds if (offset < 4 || offset >= count) { - System.err.printf("P_VerifyBlockMap: list offset overflow\n"); + LOGGER.log(Level.WARNING, String.format("P_VerifyBlockMap: list offset overflow")); return false; } @@ -599,7 +603,7 @@ protected boolean VerifyBlockMap(int count) { for (tmplist = p_list;; tmplist++) { // we have overflowed the lump? if (tmplist >= p_maxoffs) { - System.err.printf("P_VerifyBlockMap: open blocklist\n"); + LOGGER.log(Level.WARNING, String.format("P_VerifyBlockMap: open blocklist")); return false; } if (blockmaplump[tmplist] == -1) // found -1 @@ -611,7 +615,7 @@ protected boolean VerifyBlockMap(int count) { // scan the list for out-of-range linedef indicies in list for (tmplist = p_list; blockmaplump[tmplist] != -1; tmplist++) { if (blockmaplump[tmplist] < 0 || blockmaplump[tmplist] >= numlines) { - System.err.printf("P_VerifyBlockMap: index >= numlines\n"); + LOGGER.log(Level.WARNING, String.format("P_VerifyBlockMap: index >= numlines")); return false; } } @@ -699,8 +703,7 @@ protected void pokeIntoReject(int x, int y) { // next time. rejectmatrix[bytenum] |= POKE_REJECT[bitnum]; - System.out.println(rejectDensity()); - + rejectDensity(); } protected void retrieveFromReject(int x, int y, boolean value) { @@ -726,7 +729,7 @@ protected void retrieveFromReject(int x, int y, boolean value) { // next time. rejectmatrix[bytenum] |= POKE_REJECT[bitnum]; - System.out.println(rejectDensity()); + rejectDensity(); } @@ -791,8 +794,8 @@ protected final int[] getMapBoundingBox(boolean playable) { } } - System.err.printf("Map bounding %d %d %d %d\n", minx >> FRACBITS, - miny >> FRACBITS, maxx >> FRACBITS, maxy >> FRACBITS); + LOGGER.log(Level.WARNING, String.format("Map bounding %d %d %d %d\n", minx >> FRACBITS, + miny >> FRACBITS, maxx >> FRACBITS, maxy >> FRACBITS)); // Blow up bounding to the closest 128-sized block, adding 8 units as // padding. @@ -802,8 +805,8 @@ protected final int[] getMapBoundingBox(boolean playable) { int bckx = ((BLOCKMAPPADDING + maxx) - orgx); int bcky = ((BLOCKMAPPADDING + maxy) - orgy); - System.err.printf("%d %d %d %d\n", orgx >> FRACBITS, orgy >> FRACBITS, - 1 + (bckx >> MAPBLOCKSHIFT), 1 + (bcky >> MAPBLOCKSHIFT)); + LOGGER.log(Level.WARNING, String.format("%d %d %d %d", orgx >> FRACBITS, orgy >> FRACBITS, + 1 + (bckx >> MAPBLOCKSHIFT), 1 + (bcky >> MAPBLOCKSHIFT))); return new int[]{orgx, orgy, bckx, bcky}; } @@ -839,8 +842,8 @@ protected void LoadReject(int lumpnum) { // all-zeroes one, // or whatever you happened to read anyway. if (tmpreject.length < rejectmatrix.length) { - System.err.printf("BROKEN REJECT MAP! Length %d expected %d\n", - tmpreject.length, rejectmatrix.length); + LOGGER.log(Level.WARNING, String.format("BROKEN REJECT MAP! Length %d expected %d\n", + tmpreject.length, rejectmatrix.length)); } // Maes: purely academic. Most maps are well above 0.68 diff --git a/src/p/ActionFunctions.java b/src/p/ActionFunctions.java index fc408ba6..acc9a7a4 100644 --- a/src/p/ActionFunctions.java +++ b/src/p/ActionFunctions.java @@ -26,6 +26,7 @@ import i.IDoomSystem; import java.util.logging.Level; import java.util.logging.Logger; +import mochadoom.Loggers; import p.Actions.ActionsAttacks; import p.Actions.ActionsEnemies; import p.Actions.ActionsThinkers; @@ -41,6 +42,7 @@ public class ActionFunctions extends UnifiedGameMap implements ActionsThinkers, ActionsEnemies, ActionsAttacks, Ai, Attacks, Thinkers, Weapons { + private static final Logger LOGGER = Loggers.getLogger(ActionFunctions.class.getName()); private final SharedContext traitsSharedContext; @@ -53,7 +55,7 @@ private SharedContext buildContext() { try { return TraitFactory.build(this, ACTION_KEY_CHAIN); } catch (IllegalArgumentException | IllegalAccessException ex) { - Logger.getLogger(ActionFunctions.class.getName()).log(Level.SEVERE, null, ex); + LOGGER.log(Level.SEVERE, "buildContext failure", ex); throw new RuntimeException(ex); } } diff --git a/src/p/Actions/ActionsSlideDoors.java b/src/p/Actions/ActionsSlideDoors.java index ea5f7666..7ce0cd9e 100644 --- a/src/p/Actions/ActionsSlideDoors.java +++ b/src/p/Actions/ActionsSlideDoors.java @@ -2,6 +2,7 @@ import doom.thinker_t; import java.util.logging.Level; +import java.util.logging.Logger; import mochadoom.Loggers; import p.AbstractLevelLoader; import static p.ActiveStates.T_SlidingDoor; @@ -19,6 +20,7 @@ import utils.TraitFactory.ContextKey; public interface ActionsSlideDoors extends ActionTrait { + static final Logger LOGGER = Loggers.getLogger(ActionsSlideDoors.class.getName()); ContextKey KEY_SLIDEDOORS = ACTION_KEY_CHAIN.newKey(ActionsSlideDoors.class, SlideDoors::new); @@ -186,7 +188,7 @@ default void EV_SlidingDoor(line_t line, mobj_t thing) { return; } - Loggers.getLogger(ActionsSlideDoors.class.getName()).log(Level.WARNING, "EV_SlidingDoor"); + LOGGER.log(Level.WARNING, "EV_SlidingDoor"); // Make sure door isn't already being animated sec = line.frontsector; diff --git a/src/p/BoomLevelLoader.java b/src/p/BoomLevelLoader.java index 73a7b01b..7e29e5b6 100644 --- a/src/p/BoomLevelLoader.java +++ b/src/p/BoomLevelLoader.java @@ -37,6 +37,8 @@ import java.nio.ByteOrder; import java.util.Arrays; import java.util.function.IntFunction; +import java.util.logging.Level; +import java.util.logging.Logger; import m.BBox; import static m.BBox.BOXBOTTOM; import static m.BBox.BOXLEFT; @@ -45,6 +47,7 @@ import m.fixed_t; import static m.fixed_t.FRACBITS; import static m.fixed_t.FRACUNIT; +import mochadoom.Loggers; import rr.RendererState; import rr.line_t; import static rr.line_t.ML_TWOSIDED; @@ -93,6 +96,8 @@ */ public class BoomLevelLoader extends AbstractLevelLoader { + private static final Logger LOGGER = Loggers.getLogger(BoomLevelLoader.class.getName()); + public BoomLevelLoader(DoomMain DM) { super(DM); // TODO Auto-generated constructor stub @@ -237,7 +242,7 @@ private boolean P_CheckForDeePBSPv4Nodes(int lumpnum, int gl_lumpnum) { byte[] compare = Arrays.copyOfRange(data, 0, 7); if (Arrays.equals(compare, DeepBSPNodesV4.DeepBSPHeader)) { - System.out.println("P_CheckForDeePBSPv4Nodes: DeePBSP v4 Extended nodes are detected"); + LOGGER.log(Level.INFO, "P_CheckForDeePBSPv4Nodes: DeePBSP v4 Extended nodes are detected"); result = true; } @@ -261,7 +266,7 @@ private boolean P_CheckForZDoomUncompressedNodes(int lumpnum, int gl_lumpnum) { wrapper = ByteBuffer.wrap(data).getInt(); if (wrapper == XNOD) { - System.out.println("P_CheckForZDoomUncompressedNodes: ZDoom uncompressed normal nodes are detected"); + LOGGER.log(Level.INFO, "P_CheckForZDoomUncompressedNodes: ZDoom uncompressed normal nodes are detected"); result = true; } @@ -289,7 +294,7 @@ public void P_GetNodesVersion(int lumpnum, int gl_lumpnum) { ver = 3; } else { nodesVersion = gNd2; - System.out.println("P_GetNodesVersion: found version 2 nodes"); + LOGGER.log(Level.INFO, "P_GetNodesVersion: found version 2 nodes"); } } if (wrapper == gNd4) { @@ -300,12 +305,12 @@ public void P_GetNodesVersion(int lumpnum, int gl_lumpnum) { } // e6y: unknown gl nodes will be ignored if (nodesVersion == 0 && ver != -1) { - System.out.printf("P_GetNodesVersion: found version %d nodes\n", ver); - System.out.printf("P_GetNodesVersion: version %d nodes not supported\n", ver); + LOGGER.log(Level.INFO, String.format("P_GetNodesVersion: found version %d nodes", ver)); + LOGGER.log(Level.INFO, String.format("P_GetNodesVersion: version %d nodes not supported", ver)); } } else { nodesVersion = 0; - System.out.println("P_GetNodesVersion: using normal BSP nodes"); + LOGGER.log(Level.INFO, "P_GetNodesVersion: using normal BSP nodes"); if (P_CheckForZDoomNodes(lumpnum, gl_lumpnum)) { DOOM.doomSystem.Error("P_GetNodesVersion: ZDoom nodes not supported yet"); } @@ -514,7 +519,7 @@ private void P_LoadSegs(int lump) { // e6y: fix wrong side index if (side != 0 && side != 1) { - System.err.printf("P_LoadSegs: seg %d contains wrong side index %d. Replaced with 1.\n", i, side); + LOGGER.log(Level.WARNING, String.format("P_LoadSegs: seg %d contains wrong side index %d. Replaced with 1.", i, side)); side = 1; } @@ -537,7 +542,7 @@ private void P_LoadSegs(int lump) { li.frontsector = sides[ldef.sidenum[side]].sector; } else { li.frontsector = null; - System.err.printf("P_LoadSegs: front of seg %i has no sidedef\n", i); + LOGGER.log(Level.INFO, String.format("P_LoadSegs: front of seg %i has no sidedef", i)); } if (flags(ldef.flags, ML_TWOSIDED) && ldef.sidenum[side ^ 1] != NO_INDEX) { @@ -561,10 +566,10 @@ private void P_LoadSegs(int lump) { } if (v1 >= numvertexes) { - System.err.printf(str, i, v1); + LOGGER.log(Level.WARNING, String.format(str, i, v1)); } if (v2 >= numvertexes) { - System.err.printf(str, i, v2); + LOGGER.log(Level.WARNING, String.format(str, i, v2)); } if (li.sidedef == sides[li.linedef.sidenum[0]]) { @@ -638,7 +643,7 @@ private void P_LoadSegs_V4(int lump) { // e6y: fix wrong side index if (side != 0 && side != 1) { - System.err.printf("P_LoadSegs_V4: seg %d contains wrong side index %d. Replaced with 1.\n", i, side); + LOGGER.log(Level.WARNING, String.format("P_LoadSegs_V4: seg %d contains wrong side index %d. Replaced with 1.", i, side)); side = 1; } @@ -661,7 +666,7 @@ linedef, i, unsigned(ldef.sidenum[side]) li.frontsector = sides[ldef.sidenum[side]].sector; } else { li.frontsector = null; - System.err.printf("P_LoadSegs_V4: front of seg %i has no sidedef\n", i); + LOGGER.log(Level.WARNING, String.format("P_LoadSegs_V4: front of seg %i has no sidedef", i)); } if (flags(ldef.flags, ML_TWOSIDED) @@ -686,10 +691,10 @@ linedef, i, unsigned(ldef.sidenum[side]) } if (v1 >= numvertexes) { - System.err.printf(str, i, v1); + LOGGER.log(Level.WARNING, String.format(str, i, v1)); } if (v2 >= numvertexes) { - System.err.printf(str, i, v2); + LOGGER.log(Level.WARNING, String.format(str, i, v2)); } if (li.sidedef == sides[li.linedef.sidenum[0]]) { @@ -870,8 +875,7 @@ private void P_LoadNodes(int lump) { if ((data == null) || (numnodes == 0)) { // allow trivial maps if (numsubsectors == 1) { - System.out - .print("P_LoadNodes: trivial map (no nodes, one subsector)\n"); + LOGGER.log(Level.INFO, "P_LoadNodes: trivial map (no nodes, one subsector)"); } else { DOOM.doomSystem.Error("P_LoadNodes: no nodes in level"); } @@ -899,7 +903,7 @@ private void P_LoadNodes(int lump) { // haleyjd 11/06/10: check for invalid subsector reference if (no.children[j] >= numsubsectors) { - System.err.printf("P_LoadNodes: BSP tree references invalid subsector %d.\n", no.children[j]); + LOGGER.log(Level.WARNING, String.format("P_LoadNodes: BSP tree references invalid subsector %d.", no.children[j])); no.children[j] = 0; } @@ -930,7 +934,7 @@ private void P_LoadNodes_V4(int lump) { if ((data == null) || (numnodes == 0)) { // allow trivial maps if (numsubsectors == 1) { - System.out.print("P_LoadNodes_V4: trivial map (no nodes, one subsector)\n"); + LOGGER.log(Level.INFO, "P_LoadNodes_V4: trivial map (no nodes, one subsector)\n"); } else { DOOM.doomSystem.Error("P_LoadNodes_V4: no nodes in level"); } @@ -991,7 +995,7 @@ i, unsigned(linedef) // e6y: fix wrong side index if (side != 0 && side != 1) { - System.err.printf("P_LoadZSegs: seg %d contains wrong side index %d. Replaced with 1.\n", i, side); + LOGGER.log(Level.WARNING, String.format("P_LoadZSegs: seg %d contains wrong side index %d. Replaced with 1.", i, side)); side = 1; } @@ -1014,7 +1018,7 @@ linedef, i, unsigned(ldef.sidenum[side]) li.frontsector = sides[ldef.sidenum[side]].sector; } else { li.frontsector = null; - System.err.printf("P_LoadZSegs: front of seg %i has no sidedef\n", i); + LOGGER.log(Level.WARNING, String.format("P_LoadZSegs: front of seg %i has no sidedef", i)); } if (flags(ldef.flags, ML_TWOSIDED) && (ldef.sidenum[side ^ 1] != NO_INDEX)) { @@ -1376,9 +1380,9 @@ private void P_LoadLineDefs(int lump) { for (int j = 0; j < 2; j++) { if (ld.sidenum[j] != NO_INDEX && ld.sidenum[j] >= numsides) { ld.sidenum[j] = NO_INDEX; - System.err.printf( - "P_LoadLineDefs: linedef %d has out-of-range sidedef number\n", - numlines - i - 1 + LOGGER.log(Level.WARNING, String.format( + "P_LoadLineDefs: linedef %d has out-of-range sidedef number", + numlines - i - 1) ); } } @@ -1388,7 +1392,7 @@ private void P_LoadLineDefs(int lump) { ld.sidenum[0] = 0; // Substitute dummy sidedef for missing // right side // cph - print a warning about the bug - System.err.printf("P_LoadLineDefs: linedef %d missing first sidedef\n", numlines - i - 1); + LOGGER.log(Level.WARNING, String.format("P_LoadLineDefs: linedef %d missing first sidedef\n", numlines - i - 1)); } if ((ld.sidenum[1] == NO_INDEX) && flags(ld.flags, ML_TWOSIDED)) { @@ -1411,9 +1415,9 @@ private void P_LoadLineDefs(int lump) { // TODO ehhh? // ld.r_flags = RF_IGNORE_COMPAT; // cph - print a warning about the bug - System.err.printf( + LOGGER.log(Level.WARNING, String.format( "P_LoadLineDefs: linedef %d has two-sided flag set, but no second sidedef\n", - numlines - i - 1 + numlines - i - 1) ); } } @@ -1486,7 +1490,7 @@ private void P_LoadSideDefs2(int lump) { */ char sector_num = (char) msd.sector; if (sector_num >= numsectors) { - System.err.printf("P_LoadSideDefs2: sidedef %i has out-of-range sector num %u\n", i, sector_num); + LOGGER.log(Level.WARNING, String.format("P_LoadSideDefs2: sidedef %i has out-of-range sector num %u\n", i, sector_num)); sector_num = 0; } sd.sector = sec = sectors[sector_num]; @@ -1603,8 +1607,8 @@ private void P_LoadBlockMap(int lump) throws IOException { // haleyjd 03/04/10: check for blockmap problems // http://www.doomworld.com/idgames/index.php?id=12935 if (!VerifyBlockMap(count)) { - System.err.printf("P_LoadBlockMap: erroneous BLOCKMAP lump may cause crashes.\n"); - System.err.printf("P_LoadBlockMap: use \"-blockmap\" command line switch for rebuilding\n"); + LOGGER.log(Level.WARNING, String.format("P_LoadBlockMap: erroneous BLOCKMAP lump may cause crashes.")); + LOGGER.log(Level.WARNING, String.format("P_LoadBlockMap: use \"-blockmap\" command line switch for rebuilding")); } } diff --git a/src/p/LevelLoader.java b/src/p/LevelLoader.java index 94f59901..64f1e017 100644 --- a/src/p/LevelLoader.java +++ b/src/p/LevelLoader.java @@ -20,6 +20,8 @@ import doom.DoomMain; import java.io.IOException; import java.nio.ByteOrder; +import java.util.logging.Level; +import java.util.logging.Logger; import m.BBox; import static m.BBox.BOXBOTTOM; import static m.BBox.BOXLEFT; @@ -27,6 +29,7 @@ import static m.BBox.BOXTOP; import static m.fixed_t.FRACBITS; import static m.fixed_t.FixedDiv; +import mochadoom.Loggers; import rr.line_t; import static rr.line_t.ML_TWOSIDED; import rr.node_t; @@ -63,6 +66,7 @@ // //----------------------------------------------------------------------------- public class LevelLoader extends AbstractLevelLoader { + private static final Logger LOGGER = Loggers.getLogger(LevelLoader.class.getName()); public static final String rcsid = "$Id: LevelLoader.java,v 1.44 2012/09/24 17:16:23 velktron Exp $"; @@ -243,10 +247,9 @@ public void LoadNodes(int lump) throws IOException { // haleyjd 11/06/10: check for invalid subsector reference if (no.children[j] >= numsubsectors) { - System.err - .printf( - "P_LoadNodes: BSP tree references invalid subsector %d.\n", - no.children[j]); + LOGGER.log(Level.WARNING, String.format( + "P_LoadNodes: BSP tree references invalid subsector %d.", + no.children[j])); no.children[j] = 0; } @@ -501,10 +504,8 @@ public void LoadBlockMap(int lump) throws IOException { // haleyjd 03/04/10: check for blockmap problems // http://www.doomworld.com/idgames/index.php?id=12935 if (!VerifyBlockMap(count)) { - System.err - .printf("P_LoadBlockMap: erroneous BLOCKMAP lump may cause crashes.\n"); - System.err - .printf("P_LoadBlockMap: use \"-blockmap\" command line switch for rebuilding\n"); + LOGGER.log(Level.WARNING, "P_LoadBlockMap: erroneous BLOCKMAP lump may cause crashes.\n"); + LOGGER.log(Level.WARNING, "P_LoadBlockMap: use \"-blockmap\" command line switch for rebuilding\n"); } } @@ -718,7 +719,7 @@ public void GroupLines() { DOOM.leveltime = 0; if (!DOOM.wadLoader.verifyLumpName(lumpnum + ML_BLOCKMAP, LABELS[ML_BLOCKMAP])) { - System.err.println("Blockmap missing!"); + LOGGER.log(Level.WARNING, "Blockmap missing!"); } // note: most of this ordering is important @@ -772,8 +773,7 @@ public void GroupLines() { } } catch (Exception e) { - System.err.println("Error while loading level"); - e.printStackTrace(); + LOGGER.log(Level.SEVERE, "Error while loading level", e); } } diff --git a/src/p/mobj_t.java b/src/p/mobj_t.java index d16313c0..72748634 100644 --- a/src/p/mobj_t.java +++ b/src/p/mobj_t.java @@ -21,6 +21,9 @@ import java.io.IOException; import java.nio.ByteBuffer; import java.nio.ByteOrder; +import java.util.logging.Level; +import java.util.logging.Logger; +import mochadoom.Loggers; import p.ActiveStates.MobjConsumer; import static p.MapUtils.AproxDistance; import rr.subsector_t; @@ -86,6 +89,7 @@ */ public class mobj_t extends thinker_t implements ISoundOrigin, Interceptable, IWritableDoomObject, IPackableDoomObject, IReadableDoomObject { + private static final Logger LOGGER = Loggers.getLogger(mobj_t.class.getName()); public final ActionFunctions A; @@ -427,8 +431,7 @@ public void clear() { try { this.unpack(mobj_t.fastclear); } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + LOGGER.log(Level.SEVERE, "clear failure", e); } } diff --git a/src/p/plat_t.java b/src/p/plat_t.java index 9b03bc56..c0dcdffb 100644 --- a/src/p/plat_t.java +++ b/src/p/plat_t.java @@ -41,8 +41,8 @@ public void read(DataInputStream f) throws IOException { count = DoomIO.readLEInt(f); status = plat_e.values()[DoomIO.readLEInt(f)]; oldstatus = plat_e.values()[DoomIO.readLEInt(f)]; - System.out.println(status); - System.out.println(oldstatus); + //System.out.println(status); + //System.out.println(oldstatus); crush = DoomIO.readIntBoolean(f); tag = DoomIO.readLEInt(f); type = plattype_e.values()[DoomIO.readLEInt(f)]; @@ -59,8 +59,8 @@ public void pack(ByteBuffer b) throws IOException { b.putInt(count); //36 b.putInt(status.ordinal()); //40 b.putInt(oldstatus.ordinal()); //44 - System.out.println(status); - System.out.println(oldstatus); + //System.out.println(status); + //System.out.println(oldstatus); b.putInt(crush ? 1 : 0); // 48 b.putInt(tag); // 52 b.putInt(type.ordinal()); // 56 diff --git a/src/pooling/ObjectPool.java b/src/pooling/ObjectPool.java index 520e48b1..8a1338d7 100644 --- a/src/pooling/ObjectPool.java +++ b/src/pooling/ObjectPool.java @@ -2,6 +2,9 @@ import java.util.Enumeration; import java.util.Hashtable; +import java.util.logging.Level; +import java.util.logging.Logger; +import mochadoom.Loggers; import p.mobj_t; /** A convenient object pooling class. Currently used for AudioChunks, but @@ -10,6 +13,8 @@ * */ public abstract class ObjectPool { + private static final Logger LOGGER = Loggers.getLogger(ObjectPool.class.getName()); + private static final boolean D = false; @@ -37,7 +42,7 @@ public synchronized K checkOut() { // object has expired if (t instanceof mobj_t) { if (D) { - System.out.printf("Object %s expired\n", t.toString()); + LOGGER.log(Level.FINE, String.format("Object %s expired", t.toString())); } } unlocked.remove(t); @@ -49,7 +54,7 @@ public synchronized K checkOut() { locked.put(t, Long.valueOf(now)); if (D) { if (t instanceof mobj_t) { - System.out.printf("Object %s reused\n", t.toString()); + LOGGER.log(Level.FINE, String.format("Object %s reused", t.toString())); } } return t; @@ -71,7 +76,7 @@ public synchronized K checkOut() { public synchronized void checkIn(K t) { if (D) { if (t instanceof mobj_t) { - System.out.printf("Object %s returned to the pool\n", t.toString()); + LOGGER.log(Level.FINE, String.format("Object %s returned to the pool", t.toString())); } } locked.remove(t); diff --git a/src/pooling/ObjectQueuePool.java b/src/pooling/ObjectQueuePool.java index dbc4e2dc..83bf1b21 100644 --- a/src/pooling/ObjectQueuePool.java +++ b/src/pooling/ObjectQueuePool.java @@ -1,6 +1,9 @@ package pooling; import java.util.Stack; +import java.util.logging.Level; +import java.util.logging.Logger; +import mochadoom.Loggers; import p.mobj_t; /** A convenient object pooling class, derived from the stock ObjectPool. @@ -10,6 +13,7 @@ * */ public abstract class ObjectQueuePool { + private static final Logger LOGGER = Loggers.getLogger(ObjectQueuePool.class.getName()); private static final boolean D = false; @@ -43,7 +47,7 @@ public K checkOut() { public void checkIn(K t) { if (D) { if (t instanceof mobj_t) { - System.out.printf("Object %s returned to the pool\n", t.toString()); + LOGGER.log(Level.FINE, String.format("Object %s returned to the pool", t.toString())); } } locked.push(t); diff --git a/src/rr/RendererState.java b/src/rr/RendererState.java index e2a15d8c..1b634763 100644 --- a/src/rr/RendererState.java +++ b/src/rr/RendererState.java @@ -36,6 +36,8 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; import static m.BBox.BOXBOTTOM; import static m.BBox.BOXLEFT; import static m.BBox.BOXRIGHT; @@ -48,6 +50,7 @@ import static m.fixed_t.FixedDiv; import static m.fixed_t.FixedMul; import mochadoom.Engine; +import mochadoom.Loggers; import static p.ActiveStates.P_MobjThinker; import p.mobj_t; import rr.drawfuns.ColFuncs; @@ -84,6 +87,8 @@ */ public abstract class RendererState implements SceneRenderer, ILimitResettable { + private static final Logger LOGGER = Loggers.getLogger(RendererState.class.getName()); + protected static final boolean DEBUG = false; protected static final boolean DEBUG2 = false; @@ -513,7 +518,7 @@ public void ClearClipSegs() { */ private void AddLine(seg_t line) { if (DEBUG) { - System.out.println("Entered AddLine for " + line); + LOGGER.log(Level.FINE, String.format("Entered AddLine for %s", String.valueOf(line))); } int x1; int x2; @@ -589,11 +594,11 @@ private void AddLine(seg_t line) { // Single sided line? if (backsector == null) { if (DEBUG) { - System.out.println("Entering ClipSolidWallSegment SS with params " + x1 + " " + (x2 - 1)); + LOGGER.log(Level.FINE, String.format("Entering ClipSolidWallSegment SS with params %d %d", x1, (x2 - 1))); } ClipSolidWallSegment(x1, x2 - 1); // to clipsolid if (DEBUG) { - System.out.println("Exiting ClipSolidWallSegment"); + LOGGER.log(Level.FINE, "Exiting ClipSolidWallSegment"); } return; } @@ -602,7 +607,7 @@ private void AddLine(seg_t line) { if (backsector.ceilingheight <= frontsector.floorheight || backsector.floorheight >= frontsector.ceilingheight) { if (DEBUG) { - System.out.println("Entering ClipSolidWallSegment Closed door with params " + x1 + " " + (x2 - 1)); + LOGGER.log(Level.FINE, String.format("Entering ClipSolidWallSegment Closed door with params %d %d", x1, (x2 - 1))); } ClipSolidWallSegment(x1, x2 - 1); // to clipsolid @@ -613,7 +618,7 @@ private void AddLine(seg_t line) { if (backsector.ceilingheight != frontsector.ceilingheight || backsector.floorheight != frontsector.floorheight) { if (DEBUG) { - System.out.println("Entering ClipSolidWallSegment window with params " + x1 + " " + (x2 - 1)); + LOGGER.log(Level.FINE, String.format("Entering ClipSolidWallSegment window with params %d %d", x1, (x2 - 1))); } ClipPassWallSegment(x1, x2 - 1); // to clippass return; @@ -638,7 +643,7 @@ private void AddLine(seg_t line) { // Fucking GOTOs.... ClipPassWallSegment(x1, x2 - 1); // to clippass if (DEBUG) { - System.out.println("Exiting AddLine for " + line); + LOGGER.log(Level.FINE, String.format("Exiting AddLine for %s", String.valueOf(line))); } } @@ -794,7 +799,7 @@ public boolean CheckBBox(int[] bspcoord) { */ private void Subsector(int num) { if (DEBUG) { - System.out.println("\t\tSubSector " + num + " to render"); + LOGGER.log(Level.FINE, String.format("SubSector %d to render", num)); } int count; int line; // pointer into a list of segs instead of seg_t @@ -812,14 +817,14 @@ private void Subsector(int num) { frontsector = sub.sector; if (DEBUG) { - System.out.println("Frontsector to render :" + frontsector); + LOGGER.log(Level.FINE, String.format("Frontsector to render: %s", String.valueOf(frontsector))); } count = sub.numlines; // line = LL.segs[sub.firstline]; line = sub.firstline; if (DEBUG) { - System.out.println("Trying to find an existing FLOOR visplane..."); + LOGGER.log(Level.FINE, "Trying to find an existing FLOOR visplane..."); } if (frontsector.floorheight < view.z) { vp_vars.floorplane @@ -847,14 +852,14 @@ private void Subsector(int num) { VIS.AddSprites(frontsector); if (DEBUG) { - System.out.println("Enter Addline for SubSector " + num + " count " + count); + LOGGER.log(Level.FINE, String.format("Enter Addline for SubSector %d count %d", num, count)); } while (count-- > 0) { AddLine(DOOM.levelLoader.segs[line]); line++; } if (DEBUG) { - System.out.println("Exit Addline for SubSector " + num); + LOGGER.log(Level.FINE, String.format("Exit Addline for SubSector %d", num)); } } @@ -864,7 +869,7 @@ private void Subsector(int num) { */ public void RenderBSPNode(int bspnum) { if (DEBUG) { - System.out.println("Processing BSP Node " + bspnum); + LOGGER.log(Level.FINE, String.format("Processing BSP Node %d", bspnum)); } node_t bsp; @@ -874,7 +879,7 @@ public void RenderBSPNode(int bspnum) { // SubSector. if (C2JUtils.flags(bspnum, NF_SUBSECTOR)) { if (DEBUG) { - System.out.println("Subsector found."); + LOGGER.log(Level.FINE, "Subsector found."); } if (bspnum == -1) { Subsector(0); @@ -889,26 +894,26 @@ public void RenderBSPNode(int bspnum) { // Decide which side the view point is on. side = bsp.PointOnSide(view.x, view.y); if (DEBUG) { - System.out.println("\tView side: " + side); + LOGGER.log(Level.FINE, String.format("View side: %d", side)); } // Recursively divide front space. if (DEBUG) { - System.out.println("\tEnter Front space of " + bspnum); + LOGGER.log(Level.FINE, String.format("Enter Front space of %d", bspnum)); } RenderBSPNode(bsp.children[side]); if (DEBUG) { - System.out.println("\tReturn Front space of " + bspnum); + LOGGER.log(Level.FINE, String.format("Return Front space of %d", bspnum)); } // Possibly divide back space. if (CheckBBox(bsp.bbox[side ^ 1].bbox)) { if (DEBUG) { - System.out.println("\tEnter Back space of " + bspnum); + LOGGER.log(Level.FINE, String.format("Enter Back space of %d", bspnum)); } RenderBSPNode(bsp.children[side ^ 1]); if (DEBUG) { - System.out.println("\tReturn Back space of " + bspnum); + LOGGER.log(Level.FINE, String.format("Return Back space of %d", bspnum)); } } } @@ -1029,7 +1034,7 @@ public void sync() { public void StoreWallRange(int start, int stop) { if (DEBUG2) { - System.out.println("\t\t\t\tStorewallrange called between " + start + " and " + stop); + LOGGER.log(Level.FINER, String.format("Storewallrange called between %d and %d", start, stop)); } int hyp; // fixed_t @@ -1544,7 +1549,7 @@ protected void RenderSegLoop() { dcvars.dc_source = TexMan.GetCachedColumn(toptexture, texturecolumn); dcvars.dc_source_ofs = 0; if (dcvars.dc_colormap == null) { - System.out.println("Two-sided"); + LOGGER.log(Level.FINE, "Two-sided"); } CompleteColumn(); ceilingclip[rw_x] = (short) mid; @@ -1756,7 +1761,7 @@ protected class Planes extends PlaneDrawer { @Override public void DrawPlanes() { if (DEBUG) { - System.out.println(" >>>>>>>>>>>>>>>>>>>>> DrawPlanes: " + vp_vars.lastvisplane); + LOGGER.log(Level.FINE, String.format("DrawPlanes: %d", vp_vars.lastvisplane)); } visplane_t pln; // visplane_t int light; @@ -1771,7 +1776,7 @@ public void DrawPlanes() { for (int pl = 0; pl < vp_vars.lastvisplane; pl++) { pln = vp_vars.visplanes[pl]; if (DEBUG2) { - System.out.println(pln); + LOGGER.log(Level.FINER, String.valueOf(pln)); } if (pln.minx > pln.maxx) { @@ -2447,32 +2452,33 @@ public void Init() { // DON'T FORGET ABOUT MEEEEEE!!!11!!! this.screen = this.DOOM.graphicSystem.getScreen(FG); - System.out.print("\nR_InitData"); + LOGGER.log(Level.INFO, "R_InitData"); InitData(); // InitPointToAngle (); - System.out.print("\nR_InitPointToAngle"); + LOGGER.log(Level.INFO, "R_InitPointToAngle"); // ds.DM.viewwidth / ds.viewheight / detailLevel are set by the defaults - System.out.print("\nR_InitTables"); + LOGGER.log(Level.INFO, "R_InitTables"); InitTables(); SetViewSize(DOOM.menu.getScreenBlocks(), DOOM.menu.getDetailLevel()); - System.out.print("\nR_InitPlanes"); + LOGGER.log(Level.INFO, "R_InitPlanes"); MyPlanes.InitPlanes(); - System.out.print("\nR_InitLightTables"); + LOGGER.log(Level.INFO, "R_InitLightTables"); InitLightTables(); - System.out.print("\nR_InitSkyMap: " + TexMan.InitSkyMap()); + int initSkyMap = TexMan.InitSkyMap(); + LOGGER.log(Level.INFO, String.format("R_InitSkyMap: %d", initSkyMap)); - System.out.print("\nR_InitTranslationsTables"); + LOGGER.log(Level.INFO, "R_InitTranslationsTables"); InitTranslationTables(); - System.out.print("\nR_InitTranMap: "); + LOGGER.log(Level.INFO, "R_InitTranMap"); R_InitTranMap(0); - System.out.print("\nR_InitDrawingFunctions: "); + LOGGER.log(Level.INFO, "R_InitDrawingFunctions"); R_InitDrawingFunctions(); framecount = 0; @@ -2647,19 +2653,21 @@ protected void R_InitTranMap(int progress) { // it. If OK, this trumps even those specified in lumps. DOOM.cVarManager.with(CommandVariable.TRANMAP, 0, (String tranmap) -> { if (C2JUtils.testReadAccess(tranmap)) { - System.out.printf("Translucency map file %s specified in -tranmap arg. Attempting to use...\n", tranmap); + LOGGER.log(Level.INFO, + String.format("Translucency map file %s specified in -tranmap arg. Attempting to use...", tranmap)); main_tranmap = new byte[256 * 256]; // killough 4/11/98 int result = MenuMisc.ReadFile(tranmap, main_tranmap); if (result > 0) { return; } - System.out.print("...failure.\n"); + + LOGGER.log(Level.SEVERE, "R_InitTranMap: translucency map failure"); } }); // Next, if a tranlucency filter map lump is present, use it if (lump != -1) { // Set a pointer to the translucency filter maps. - System.out.print("Translucency map found in lump. Attempting to use..."); + LOGGER.log(Level.INFO, "Translucency map found in lump. Attempting to use..."); // main_tranmap=new byte[256*256]; // killough 4/11/98 main_tranmap = DOOM.wadLoader.CacheLumpNumAsRawBytes(lump, Defines.PU_STATIC); // killough // 4/11/98 @@ -2667,12 +2675,12 @@ protected void R_InitTranMap(int progress) { if (main_tranmap.length >= 0x10000) { return; } - System.out.print("...failure.\n"); // Not good, try something else. + LOGGER.log(Level.SEVERE, "R_InitTranMap: tranlucency filter map failure"); // Not good, try something else. } // A default map file already exists. Try to read it. if (C2JUtils.testReadAccess("tranmap.dat")) { - System.out.print("Translucency map found in default tranmap.dat file. Attempting to use..."); + LOGGER.log(Level.INFO, "Translucency map found in default tranmap.dat file. Attempting to use..."); main_tranmap = new byte[256 * 256]; // killough 4/11/98 int result = MenuMisc.ReadFile("tranmap.dat", main_tranmap); if (result > 0) { @@ -2683,7 +2691,7 @@ protected void R_InitTranMap(int progress) { // Nothing to do, so we must synthesize it from scratch. And, boy, is it // slooow. { // Compose a default transparent filter map based on PLAYPAL. - System.out.print("Computing translucency map from scratch...that's gonna be SLOW..."); + LOGGER.log(Level.INFO, "Computing translucency map from scratch...that's gonna be SLOW..."); byte[] playpal = DOOM.wadLoader.CacheLumpNameAsRawBytes("PLAYPAL", Defines.PU_STATIC); main_tranmap = new byte[256 * 256]; // killough 4/11/98 int[] basepal = new int[3 * 256]; @@ -2726,15 +2734,15 @@ protected void R_InitTranMap(int progress) { main_tranmap[(b << 8) | a] = main_tranmap[(a << 8) | b]; } } - System.out.print("...done\n"); + LOGGER.log(Level.INFO, "R_InitTranMap: done"); if (MenuMisc.WriteFile("tranmap.dat", main_tranmap, main_tranmap.length)) { - System.out.print("TRANMAP.DAT saved to disk for your convenience! Next time will be faster.\n"); + LOGGER.log(Level.INFO, "TRANMAP.DAT saved to disk for your convenience! Next time will be faster."); } } long b = System.nanoTime(); - System.out.printf("Tranmap %d\n", (b - ta) / 1000000); + LOGGER.log(Level.INFO, String.format("Tranmap %d", (b - ta) / 1000000)); } /** @@ -2819,21 +2827,21 @@ protected int findMin(float[] a) { */ public void InitData() { try { - System.out.print("\nInit Texture and Flat Manager"); + LOGGER.log(Level.INFO, "Init Texture and Flat Manager"); TexMan = this.DOOM.textureManager; - System.out.print("\nInitTextures"); + LOGGER.log(Level.INFO, "InitTextures"); TexMan.InitTextures(); - System.out.print("\nInitFlats"); + LOGGER.log(Level.INFO, "InitFlats"); TexMan.InitFlats(); - System.out.print("\nInitSprites"); + LOGGER.log(Level.INFO, "InitSprites"); DOOM.spriteManager.InitSpriteLumps(); MyThings.cacheSpriteManager(DOOM.spriteManager); VIS.cacheSpriteManager(DOOM.spriteManager); - System.out.print("\nInitColormaps\t\t"); + LOGGER.log(Level.INFO, "InitColormaps"); InitColormaps(); } catch (IOException e) { - e.printStackTrace(); + LOGGER.log(Level.SEVERE, "Error: InitData failure", e); } } diff --git a/src/rr/SimpleTextureManager.java b/src/rr/SimpleTextureManager.java index 960efa66..fadc8f1e 100644 --- a/src/rr/SimpleTextureManager.java +++ b/src/rr/SimpleTextureManager.java @@ -16,8 +16,11 @@ import java.util.Enumeration; import java.util.HashMap; import java.util.Hashtable; +import java.util.logging.Level; +import java.util.logging.Logger; import static m.fixed_t.FRACBITS; import static m.fixed_t.FRACUNIT; +import mochadoom.Loggers; import p.AbstractLevelLoader; import w.DoomBuffer; import w.IWadLoader; @@ -34,6 +37,8 @@ */ public class SimpleTextureManager implements TextureManager { + private static final Logger LOGGER = Loggers.getLogger(SimpleTextureManager.class.getName()); + IWadLoader W; IDoomSystem I; AbstractLevelLoader LL; @@ -209,14 +214,8 @@ public void InitTextures() throws IOException { totalwidth = 0; - // Really complex printing shit... - System.out.print("["); + LOGGER.log(Level.INFO, String.format("Textures: %d", numtextures)); for (int i = 0; i < numtextures; i++, directory++) { - - if ((i & 63) == 0) { - System.out.print('.'); - } - if (i == _numtextures[TEXTURE1]) { // Start looking in second texture file. texset = TEXTURE2; @@ -270,7 +269,6 @@ public void InitTextures() throws IOException { totalwidth += texture.width; } - System.out.print("]"); // Precalculate whatever possible. for (int i = 0; i < numtextures; i++) { @@ -444,9 +442,9 @@ public void GenerateLookup(int texnum) throws IOException { for (x = 0; x < texture.width; x++) { // Can only occur if a column isn't covered by a patch at all, not even a transparent one. if (patchcount[x] == 0) { - // TODO: somehow handle this. - System.err.print(realpatch.width); - System.err.print("R_GenerateLookup: column without a patch (" + texture.name + ")\n"); + // TODO: somehow handle this. + LOGGER.log(Level.WARNING, String.format("R_GenerateLookup: column without a patch (%s), width: %d", + texture.name, realpatch.width)); //return; } // I_Error ("R_GenerateLookup: column without a patch"); @@ -1242,9 +1240,11 @@ public column_t GetSmpColumn(int tex, int col, int id) { // Problem. Composite texture requested as if it was masked // but it doesn't yet exist. Create it. if (getMaskedComposite(tex) == null) { - System.err.printf("Forced generation of composite %s\n", CheckTextureNameForNum(tex), smp_composite[id], col, ofs); + LOGGER.log(Level.WARNING, String.format("Forced generation of composite %s", + CheckTextureNameForNum(tex), smp_composite[id], col, ofs)); GenerateMaskedComposite(tex); - System.err.printf("Composite patch %s %d\n", getMaskedComposite(tex).name, getMaskedComposite(tex).columns.length); + LOGGER.log(Level.WARNING, String.format("Composite patch %s %d", + getMaskedComposite(tex).name, getMaskedComposite(tex).columns.length)); } // Last resort. @@ -1311,9 +1311,11 @@ public byte[] GetColumn(int tex, int col) { // Problem. Composite texture requested as if it was masked // but it doesn't yet exist. Create it. if (getMaskedComposite(tex) == null) { - System.err.printf("Forced generation of composite %s\n", CheckTextureNameForNum(tex), composite, col, ofs); + LOGGER.log(Level.WARNING, + String.format("Forced generation of composite %s", CheckTextureNameForNum(tex), composite, col, ofs)); GenerateMaskedComposite(tex); - System.err.printf("Composite patch %s %d\n", getMaskedComposite(tex).name, getMaskedComposite(tex).columns.length); + LOGGER.log(Level.WARNING, + String.format("Composite patch %s %d", getMaskedComposite(tex).name, getMaskedComposite(tex).columns.length)); } // Last resort. @@ -1375,9 +1377,11 @@ public column_t GetColumnStruct(int tex, int col) { // Problem. Composite texture requested as if it was masked // but it doesn't yet exist. Create it. if (getMaskedComposite(tex) == null) { - System.err.printf("Forced generation of composite %s\n", CheckTextureNameForNum(tex), composite, col, ofs); + LOGGER.log(Level.WARNING, + String.format("Forced generation of composite %s", CheckTextureNameForNum(tex), composite, col, ofs)); GenerateMaskedComposite(tex); - System.err.printf("Composite patch %s %d\n", getMaskedComposite(tex).name, getMaskedComposite(tex).columns.length); + LOGGER.log(Level.WARNING, + String.format("Composite patch %s %d", getMaskedComposite(tex).name, getMaskedComposite(tex).columns.length)); } // Last resort. diff --git a/src/rr/SpriteManager.java b/src/rr/SpriteManager.java index 969643db..09ca9964 100644 --- a/src/rr/SpriteManager.java +++ b/src/rr/SpriteManager.java @@ -5,7 +5,10 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; import static m.fixed_t.FRACBITS; +import mochadoom.Loggers; import static utils.C2JUtils.memset; import static utils.GenericCopy.malloc; import w.lumpinfo_t; @@ -21,6 +24,8 @@ */ public class SpriteManager implements ISpriteManager { + private static final Logger LOGGER = Loggers.getLogger(SpriteManager.class.getName()); + /** There seems to be an arbitrary limit of 29 distinct frames per THING */ public static final int MAX_SPRITE_FRAMES = 29; @@ -231,19 +236,14 @@ public void InitSpriteLumps() { spriteoffset = new int[numspritelumps]; spritetopoffset = new int[numspritelumps]; - System.out.print("["); + LOGGER.log(Level.INFO, String.format("Sprite lumps: %d", numspritelumps)); for (i = 0; i < numspritelumps; i++) { - if ((i & 63) == 0) { - System.out.print("."); - } - patch = DOOM.wadLoader.CacheLumpNum(firstspritelump + i, PU_CACHE, patch_t.class); spritewidth[i] = patch.width << FRACBITS; spriteoffset[i] = patch.leftoffset << FRACBITS; spritetopoffset[i] = patch.topoffset << FRACBITS; } - System.out.print("]"); } /** diff --git a/src/rr/UnifiedRenderer.java b/src/rr/UnifiedRenderer.java index 6018dbc5..73c529d8 100644 --- a/src/rr/UnifiedRenderer.java +++ b/src/rr/UnifiedRenderer.java @@ -2,6 +2,9 @@ import doom.DoomMain; import java.io.IOException; +import java.util.logging.Level; +import java.util.logging.Logger; +import mochadoom.Loggers; import rr.drawfuns.R_DrawColumnBoom; import rr.drawfuns.R_DrawColumnBoomLow; import rr.drawfuns.R_DrawColumnBoomOpt; @@ -15,6 +18,8 @@ import rr.drawfuns.R_DrawTranslatedColumnLow; public abstract class UnifiedRenderer extends RendererState { + private static final Logger LOGGER = Loggers.getLogger(UnifiedRenderer.class.getName()); + public UnifiedRenderer(DoomMain DOOM) { super(DOOM); @@ -73,7 +78,7 @@ public HiColor(DoomMain DOOM) { @Override protected void InitColormaps() throws IOException { colormaps.colormaps = DOOM.graphicSystem.getColorMap(); - System.out.println("COLORS15 Colormaps: " + colormaps.colormaps.length); + LOGGER.log(Level.FINE, String.format("COLORS15 Colormaps: %d", colormaps.colormaps.length)); // MAES: blurry effect is hardcoded to this colormap. BLURRY_MAP = DOOM.graphicSystem.getBlurryTable(); @@ -214,7 +219,7 @@ public TrueColor(DoomMain DOOM) { */ protected void InitColormaps() throws IOException { colormaps.colormaps = DOOM.graphicSystem.getColorMap(); - System.out.println("COLORS32 Colormaps: " + colormaps.colormaps.length); + LOGGER.log(Level.FINE, String.format("COLORS32 Colormaps: %d", colormaps.colormaps.length)); // MAES: blurry effect is hardcoded to this colormap. BLURRY_MAP = DOOM.graphicSystem.getBlurryTable(); diff --git a/src/rr/VisSprites.java b/src/rr/VisSprites.java index be6d35da..2e394dca 100644 --- a/src/rr/VisSprites.java +++ b/src/rr/VisSprites.java @@ -6,10 +6,13 @@ import static data.Tables.ANG45; import static data.Tables.BITS32; import java.util.Arrays; +import java.util.logging.Level; +import java.util.logging.Logger; import static m.fixed_t.FRACBITS; import static m.fixed_t.FRACUNIT; import static m.fixed_t.FixedDiv; import static m.fixed_t.FixedMul; +import mochadoom.Loggers; import p.mobj_t; import static p.mobj_t.MF_SHADOW; import static rr.SceneRenderer.MINZ; @@ -25,6 +28,8 @@ */ public final class VisSprites implements IVisSpriteManagement { + private static final Logger LOGGER = Loggers.getLogger(VisSprites.class.getName()); + private final static boolean DEBUG = false; @@ -56,7 +61,7 @@ public VisSprites(RendererState rendererState) { @Override public void AddSprites(sector_t sec) { if (DEBUG) { - System.out.println("AddSprites"); + LOGGER.log(Level.FINER, "AddSprites"); } mobj_t thing; int lightnum; diff --git a/src/rr/Visplanes.java b/src/rr/Visplanes.java index 5e4d4776..aa49a7b9 100644 --- a/src/rr/Visplanes.java +++ b/src/rr/Visplanes.java @@ -6,7 +6,10 @@ import static data.Tables.finecosine; import static data.Tables.finesine; import java.util.Arrays; +import java.util.logging.Level; +import java.util.logging.Logger; import static m.fixed_t.FixedDiv; +import mochadoom.Loggers; import utils.C2JUtils; import v.scale.VideoScale; @@ -15,6 +18,7 @@ * visplane data among parallel renderers, without duplicating them. */ public class Visplanes { + private static final Logger LOGGER = Loggers.getLogger(Visplanes.class.getName()); private static final boolean DEBUG2 = false; @@ -208,8 +212,7 @@ public void ClearPlanes() { public int CheckPlane(int index, int start, int stop) { if (DEBUG2) { - System.out.println("Checkplane " + index + " between " + start - + " and " + stop); + LOGGER.log(Level.FINER, String.format("Checkplane %d between %d and %d", index, start, stop)); } // Interval ? @@ -223,7 +226,7 @@ public int CheckPlane(int index, int start, int stop) { visplane_t pl = visplanes[index]; if (DEBUG2) { - System.out.println("Checking out plane " + pl); + LOGGER.log(Level.FINER,String.format("Checking out plane %s", String.valueOf(pl))); } int x; diff --git a/src/rr/drawfuns/R_DrawColumnBoom.java b/src/rr/drawfuns/R_DrawColumnBoom.java index 52ad257c..16538289 100644 --- a/src/rr/drawfuns/R_DrawColumnBoom.java +++ b/src/rr/drawfuns/R_DrawColumnBoom.java @@ -1,7 +1,10 @@ package rr.drawfuns; import i.IDoomSystem; +import java.util.logging.Level; +import java.util.logging.Logger; import static m.fixed_t.FRACBITS; +import mochadoom.Loggers; /** * Adapted from Killough's Boom code. There are optimized as well as low-detail @@ -11,6 +14,8 @@ */ public abstract class R_DrawColumnBoom extends DoomColumnFunction { + private static final Logger LOGGER = Loggers.getLogger(R_DrawColumnBoom.class.getName()); + public R_DrawColumnBoom(int SCREENWIDTH, int SCREENHEIGHT, int[] ylookup, int[] columnofs, ColVars dcvars, V screen, IDoomSystem I) { @@ -123,8 +128,9 @@ public void invoke() { = colormap[0x00FF & source[dc_source_ofs + ((frac >> FRACBITS) & heightmask)]]; } catch (Exception e) { - System.err.printf("%s %s %x %x %x\n", colormap, - source, dc_source_ofs, frac, heightmask); + LOGGER.log(Level.WARNING, + String.format("%s %s %x %x %x", colormap, + source, dc_source_ofs, frac, heightmask)); } dest += SCREENWIDTH; frac += fracstep; @@ -241,8 +247,9 @@ public void invoke() { = colormap[0x00FF & source[dc_source_ofs + ((frac >> FRACBITS) & heightmask)]]; } catch (Exception e) { - System.err.printf("%s %s %x %x %x\n", colormap, - source, dc_source_ofs, frac, heightmask); + LOGGER.log(Level.WARNING, + String.format("%s %s %x %x %x\n", colormap, + source, dc_source_ofs, frac, heightmask)); } dest += SCREENWIDTH; frac += fracstep; @@ -359,8 +366,9 @@ public void invoke() { = colormap[0x00FF & source[dc_source_ofs + ((frac >> FRACBITS) & heightmask)]]; } catch (Exception e) { - System.err.printf("%s %s %x %x %x\n", colormap, - source, dc_source_ofs, frac, heightmask); + LOGGER.log(Level.WARNING, + String.format("%s %s %x %x %x\n", colormap, + source, dc_source_ofs, frac, heightmask)); } dest += SCREENWIDTH; frac += fracstep; diff --git a/src/rr/parallel/AbstractParallelRenderer.java b/src/rr/parallel/AbstractParallelRenderer.java index ee51cd66..b1ed408f 100644 --- a/src/rr/parallel/AbstractParallelRenderer.java +++ b/src/rr/parallel/AbstractParallelRenderer.java @@ -8,8 +8,11 @@ import java.util.concurrent.CyclicBarrier; import java.util.concurrent.Executor; import java.util.concurrent.Executors; +import java.util.logging.Level; +import java.util.logging.Logger; import static m.fixed_t.FRACBITS; import static m.fixed_t.FixedMul; +import mochadoom.Loggers; import rr.PlaneDrawer; import rr.RendererState; import rr.SceneRenderer; @@ -22,6 +25,7 @@ * @author velktron */ public abstract class AbstractParallelRenderer extends RendererState implements RWI.Init { + private static final Logger LOGGER = Loggers.getLogger(AbstractParallelRenderer.class.getName()); public AbstractParallelRenderer(DoomMain DM, int wallthread, int floorthreads, int nummaskedthreads) { super(DM); @@ -177,8 +181,7 @@ public void sync() { try { drawsegsbarrier.await(); } catch (InterruptedException | BrokenBarrierException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + LOGGER.log(Level.SEVERE, "sync failure", e); } // TODO Auto-generated catch block } @@ -446,7 +449,7 @@ void ResizeRSIBuffer() { RSIExec[i].updateRSI(RSI); } - System.out.println("RWI Buffer resized. Actual capacity " + RSI.length); + LOGGER.log(Level.INFO, String.format("RWI Buffer resized. Actual capacity %d", RSI.length)); } } diff --git a/src/rr/parallel/MaskedWorker.java b/src/rr/parallel/MaskedWorker.java index 4d6524e9..b33f3e6f 100644 --- a/src/rr/parallel/MaskedWorker.java +++ b/src/rr/parallel/MaskedWorker.java @@ -5,9 +5,12 @@ import static data.Defines.pw_invisibility; import java.util.concurrent.BrokenBarrierException; import java.util.concurrent.CyclicBarrier; +import java.util.logging.Level; +import java.util.logging.Logger; import static m.fixed_t.FRACBITS; import static m.fixed_t.FRACUNIT; import static m.fixed_t.FixedMul; +import mochadoom.Loggers; import static p.mobj_t.MF_TRANSLATION; import p.pspdef_t; import rr.AbstractThings; @@ -42,7 +45,8 @@ * @param */ public abstract class MaskedWorker extends AbstractThings implements Runnable, IDetailAware { - + private static final Logger LOGGER = Loggers.getLogger(MaskedWorker.class.getName()); + private final static boolean DEBUG = false; private final static boolean RANGECHECK = false; @@ -202,7 +206,7 @@ protected final void DrawVisSprite(vissprite_t vis) { column = patch.columns[texturecolumn]; if (column == null) { - System.err.printf("Null column for texturecolumn %d\n", texturecolumn, x1, x2); + LOGGER.log(Level.WARNING, String.format("Null column for texturecolumn %d", texturecolumn, x1, x2)); } else { DrawMaskedColumn(column); } @@ -495,8 +499,7 @@ public void run() { try { barrier.await(); } catch (InterruptedException | BrokenBarrierException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + LOGGER.log(Level.SEVERE, "MaskedWorker run failure", e); } // TODO Auto-generated catch block } diff --git a/src/rr/parallel/ParallelRenderer.java b/src/rr/parallel/ParallelRenderer.java index d8748825..185ddc56 100644 --- a/src/rr/parallel/ParallelRenderer.java +++ b/src/rr/parallel/ParallelRenderer.java @@ -3,6 +3,9 @@ import doom.DoomMain; import doom.player_t; import java.io.IOException; +import java.util.logging.Level; +import java.util.logging.Logger; +import mochadoom.Loggers; import rr.SimpleThings; import rr.drawfuns.ColVars; import rr.drawfuns.R_DrawColumnBoom; @@ -31,6 +34,8 @@ * @author admin */ public abstract class ParallelRenderer extends AbstractParallelRenderer { + private static final Logger LOGGER = Loggers.getLogger(ParallelRenderer.class.getName()); + public ParallelRenderer(DoomMain DM, int wallthread, int floorthreads, int nummaskedthreads) { @@ -306,7 +311,7 @@ protected void InitMaskedWorkers() { protected void InitColormaps() throws IOException { colormaps.colormaps = DOOM.graphicSystem.getColorMap(); - System.out.println("COLORS15 Colormaps: " + colormaps.colormaps.length); + LOGGER.log(Level.FINE,String.format("COLORS15 Colormaps: %d", colormaps.colormaps.length)); // MAES: blurry effect is hardcoded to this colormap. // Pointless, since we don't use indexes. Instead, a half-brite @@ -420,7 +425,7 @@ protected void InitColormaps() throws IOException { colormaps.colormaps = DOOM.graphicSystem.getColorMap(); - System.out.println("COLORS15 Colormaps: " + colormaps.colormaps.length); + LOGGER.log(Level.FINE, String.format("COLORS15 Colormaps: %d", colormaps.colormaps.length)); // MAES: blurry effect is hardcoded to this colormap. // Pointless, since we don't use indexes. Instead, a half-brite diff --git a/src/rr/parallel/ParallelRenderer2.java b/src/rr/parallel/ParallelRenderer2.java index 965b5bb3..43670f7f 100644 --- a/src/rr/parallel/ParallelRenderer2.java +++ b/src/rr/parallel/ParallelRenderer2.java @@ -7,6 +7,9 @@ import java.util.concurrent.BrokenBarrierException; import java.util.concurrent.CyclicBarrier; import java.util.concurrent.Executors; +import java.util.logging.Level; +import java.util.logging.Logger; +import mochadoom.Loggers; import rr.drawfuns.R_DrawColumnBoom; import rr.drawfuns.R_DrawColumnBoomLow; import rr.drawfuns.R_DrawColumnBoomOpt; @@ -29,11 +32,12 @@ * */ public abstract class ParallelRenderer2 extends AbstractParallelRenderer { + private static final Logger LOGGER = Loggers.getLogger(ParallelRenderer2.class.getName()); @SuppressWarnings("unchecked") public ParallelRenderer2(DoomMain DOOM, int wallthread, int floorthreads, int nummaskedthreads) { super(DOOM, wallthread, floorthreads, nummaskedthreads); - System.out.println("Parallel Renderer 2 (Seg-based)"); + LOGGER.log(Level.FINE, "Parallel Renderer 2 (Seg-based)"); this.MySegs = new ParallelSegs2<>(this); this.MyPlanes = new ParallelPlanes<>(DOOM, this); @@ -126,7 +130,7 @@ public void RenderPlayerView(player_t player) { try { visplanebarrier.await(); } catch (InterruptedException | BrokenBarrierException e) { - e.printStackTrace(); + LOGGER.log(Level.SEVERE, "RenderPlayerView failure", e); } // Check for new console commands. @@ -323,7 +327,7 @@ protected void InitMaskedWorkers() { @Override protected void InitColormaps() throws IOException { colormaps.colormaps = DOOM.graphicSystem.getColorMap(); - System.out.println("COLORS15 Colormaps: " + colormaps.colormaps.length); + LOGGER.log(Level.FINE, String.format("COLORS15 Colormaps: %d", colormaps.colormaps.length)); // MAES: blurry effect is hardcoded to this colormap. // Pointless, since we don't use indexes. Instead, a half-brite @@ -424,7 +428,7 @@ protected void InitMaskedWorkers() { @Override protected void InitColormaps() throws IOException { colormaps.colormaps = DOOM.graphicSystem.getColorMap(); - System.out.println("COLORS15 Colormaps: " + colormaps.colormaps.length); + LOGGER.log(Level.FINE, String.format("COLORS15 Colormaps: %d", colormaps.colormaps.length)); // MAES: blurry effect is hardcoded to this colormap. // Pointless, since we don't use indexes. Instead, a half-brite diff --git a/src/rr/parallel/ParallelThings.java b/src/rr/parallel/ParallelThings.java index 59b3d26e..362a15fe 100644 --- a/src/rr/parallel/ParallelThings.java +++ b/src/rr/parallel/ParallelThings.java @@ -4,6 +4,9 @@ import java.util.concurrent.BrokenBarrierException; import java.util.concurrent.CyclicBarrier; import java.util.concurrent.Executor; +import java.util.logging.Level; +import java.util.logging.Logger; +import mochadoom.Loggers; import rr.AbstractThings; import rr.IDetailAware; import rr.SceneRenderer; @@ -36,6 +39,8 @@ * @author velktron */ public abstract class ParallelThings extends AbstractThings { + private static final Logger LOGGER = Loggers.getLogger(ParallelThings.class.getName()); + // stuff to get from container /** Render Masked Instuction subsystem. Essentially, a way to split sprite work @@ -75,7 +80,7 @@ public void DrawMasked() { maskedbarrier.await(); } catch (InterruptedException | BrokenBarrierException e) { // TODO Auto-generated catch block - e.printStackTrace(); + LOGGER.log(Level.SEVERE, "ParallelThings DrawMasked failure", e); } // TODO Auto-generated catch block @@ -130,7 +135,7 @@ protected void ResizeRMIBuffer() { RMIExec[i].updateRMI(RMI); } - System.err.println("RMI Buffer resized. Actual capacity " + RMI.length); + LOGGER.log(Level.FINE, String.format("RMI Buffer resized. Actual capacity %d", RMI.length)); } protected abstract void InitRMISubsystem(int[] columnofs, int[] ylookup, V screen, CyclicBarrier maskedbarrier, BlurryTable BLURRY_MAP, List detailaware); diff --git a/src/rr/parallel/ParallelThings2.java b/src/rr/parallel/ParallelThings2.java index e55b1498..07b10b53 100644 --- a/src/rr/parallel/ParallelThings2.java +++ b/src/rr/parallel/ParallelThings2.java @@ -3,6 +3,9 @@ import java.util.concurrent.BrokenBarrierException; import java.util.concurrent.CyclicBarrier; import java.util.concurrent.Executor; +import java.util.logging.Level; +import java.util.logging.Logger; +import mochadoom.Loggers; import rr.IMaskedDrawer; import rr.ISpriteManager; import rr.IVisSpriteManagement; @@ -28,6 +31,7 @@ * */ public final class ParallelThings2 implements IMaskedDrawer { + private static final Logger LOGGER = Loggers.getLogger(ParallelThings2.class.getName()); MaskedWorker[] maskedworkers; CyclicBarrier maskedbarrier; @@ -52,8 +56,7 @@ public void DrawMasked() { try { maskedbarrier.await(); } catch (InterruptedException | BrokenBarrierException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + LOGGER.log(Level.SEVERE, "ParallelThings2 DrawMasked failure", e); } // TODO Auto-generated catch block diff --git a/src/rr/parallel/RenderMaskedExecutor.java b/src/rr/parallel/RenderMaskedExecutor.java index 718916f0..c988bc7a 100644 --- a/src/rr/parallel/RenderMaskedExecutor.java +++ b/src/rr/parallel/RenderMaskedExecutor.java @@ -3,6 +3,9 @@ import i.IDoomSystem; import java.util.concurrent.BrokenBarrierException; import java.util.concurrent.CyclicBarrier; +import java.util.logging.Level; +import java.util.logging.Logger; +import mochadoom.Loggers; import rr.IDetailAware; import rr.drawfuns.ColVars; import rr.drawfuns.DcFlags; @@ -23,6 +26,7 @@ */ public abstract class RenderMaskedExecutor implements Runnable, IDetailAware { + private static final Logger LOGGER = Loggers.getLogger(RenderMaskedExecutor.class.getName()); protected CyclicBarrier barrier; @@ -97,7 +101,7 @@ public void run() { try { barrier.await(); } catch (InterruptedException | BrokenBarrierException e) { - e.printStackTrace(); + LOGGER.log(Level.SEVERE, "RenderMaskedExecutor run failure", e); } } diff --git a/src/rr/parallel/RenderSegExecutor.java b/src/rr/parallel/RenderSegExecutor.java index 37d69306..f676df78 100644 --- a/src/rr/parallel/RenderSegExecutor.java +++ b/src/rr/parallel/RenderSegExecutor.java @@ -5,8 +5,11 @@ import doom.DoomMain; import java.util.concurrent.BrokenBarrierException; import java.util.concurrent.CyclicBarrier; +import java.util.logging.Level; +import java.util.logging.Logger; import static m.fixed_t.FRACBITS; import static m.fixed_t.FixedMul; +import mochadoom.Loggers; import rr.IDetailAware; import rr.TextureManager; import rr.drawfuns.ColVars; @@ -41,6 +44,7 @@ * */ public abstract class RenderSegExecutor implements Runnable, IDetailAware { + private static final Logger LOGGER = Loggers.getLogger(RenderSegExecutor.class.getName()); // This needs to be set by the partitioner. protected int rw_start, rw_end, rsiend; @@ -320,8 +324,7 @@ public void run() { try { barrier.await(); } catch (InterruptedException | BrokenBarrierException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + LOGGER.log(Level.SEVERE, "RenderSegExecutor run failure", e); } // TODO Auto-generated catch block diff --git a/src/rr/parallel/RenderWallExecutor.java b/src/rr/parallel/RenderWallExecutor.java index 705ea7bb..1a785c65 100644 --- a/src/rr/parallel/RenderWallExecutor.java +++ b/src/rr/parallel/RenderWallExecutor.java @@ -2,6 +2,9 @@ import java.util.concurrent.BrokenBarrierException; import java.util.concurrent.CyclicBarrier; +import java.util.logging.Level; +import java.util.logging.Logger; +import mochadoom.Loggers; import rr.IDetailAware; import rr.drawfuns.ColVars; import rr.drawfuns.DoomColumnFunction; @@ -16,6 +19,7 @@ */ public class RenderWallExecutor implements Runnable, IDetailAware { + private static final Logger LOGGER = Loggers.getLogger(RenderWallExecutor.class.getName()); protected CyclicBarrier barrier; @@ -60,7 +64,7 @@ public void run() { try { barrier.await(); } catch (InterruptedException | BrokenBarrierException e) { - e.printStackTrace(); + LOGGER.log(Level.SEVERE, "RenderWallExecutor run failure", e); } } diff --git a/src/rr/parallel/VisplaneWorker.java b/src/rr/parallel/VisplaneWorker.java index 48ba2d65..8dae9345 100644 --- a/src/rr/parallel/VisplaneWorker.java +++ b/src/rr/parallel/VisplaneWorker.java @@ -5,7 +5,10 @@ import doom.DoomMain; import java.util.concurrent.BrokenBarrierException; import java.util.concurrent.CyclicBarrier; +import java.util.logging.Level; +import java.util.logging.Logger; import static m.fixed_t.FRACBITS; +import mochadoom.Loggers; import rr.IDetailAware; import rr.PlaneDrawer; import rr.SceneRenderer; @@ -30,6 +33,7 @@ * */ public abstract class VisplaneWorker extends PlaneDrawer implements Runnable, IDetailAware { + private static final Logger LOGGER = Loggers.getLogger(VisplaneWorker.class.getName()); // Private to each thread. protected final int id; @@ -174,8 +178,7 @@ public void run() { try { barrier.await(); } catch (InterruptedException | BrokenBarrierException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + LOGGER.log(Level.SEVERE, "VisplaneWorker run failure", e); } // TODO Auto-generated catch block diff --git a/src/rr/parallel/VisplaneWorker2.java b/src/rr/parallel/VisplaneWorker2.java index 58fec526..96e6a837 100644 --- a/src/rr/parallel/VisplaneWorker2.java +++ b/src/rr/parallel/VisplaneWorker2.java @@ -5,7 +5,10 @@ import doom.DoomMain; import java.util.concurrent.BrokenBarrierException; import java.util.concurrent.CyclicBarrier; +import java.util.logging.Level; +import java.util.logging.Logger; import static m.fixed_t.FRACBITS; +import mochadoom.Loggers; import rr.IDetailAware; import rr.PlaneDrawer; import rr.SceneRenderer; @@ -31,6 +34,7 @@ * TODO: fix crashes */ public abstract class VisplaneWorker2 extends PlaneDrawer implements Runnable, IDetailAware { + private static final Logger LOGGER = Loggers.getLogger(VisplaneWorker2.class.getName()); protected final int id; protected final int NUMFLOORTHREADS; @@ -217,8 +221,7 @@ public void run() { try { barrier.await(); } catch (InterruptedException | BrokenBarrierException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + LOGGER.log(Level.SEVERE, "VisplaneWorker2 run failure", e); } // TODO Auto-generated catch block } diff --git a/src/rr/sector_t.java b/src/rr/sector_t.java index c2e94b38..d51cadb8 100644 --- a/src/rr/sector_t.java +++ b/src/rr/sector_t.java @@ -10,6 +10,7 @@ import java.io.IOException; import java.nio.ByteBuffer; import java.util.logging.Level; +import java.util.logging.Logger; import m.IRandom; import static m.fixed_t.FRACBITS; import static m.fixed_t.FRACUNIT; @@ -30,6 +31,7 @@ * @author Maes */ public class sector_t implements IReadableDoomObject, IPackableDoomObject, Resettable { + private static final Logger LOGGER = Loggers.getLogger(sector_t.class.getName()); public ThinkerList TL; @@ -192,8 +194,8 @@ public int FindNextHighestFloor(int currentheight) { // Check for overflow. Exit. if (h >= MAX_ADJOINING_SECTORS) { - Loggers.getLogger(sector_t.class.getName()).log(Level.WARNING, - "Sector with more than 20 adjoining sectors\n"); + LOGGER.log(Level.WARNING, + "Sector with more than 20 adjoining sectors"); break; } } diff --git a/src/s/AbstractDoomAudio.java b/src/s/AbstractDoomAudio.java index 381beb45..c65782f2 100644 --- a/src/s/AbstractDoomAudio.java +++ b/src/s/AbstractDoomAudio.java @@ -11,8 +11,11 @@ import data.sounds.musicenum_t; import data.sounds.sfxenum_t; import doom.DoomMain; +import java.util.logging.Level; +import java.util.logging.Logger; import static m.fixed_t.FRACBITS; import static m.fixed_t.FixedMul; +import mochadoom.Loggers; import p.mobj_t; /** Some stuff that is not implementation dependant @@ -26,6 +29,8 @@ * */ public class AbstractDoomAudio implements IDoomSound { + private static final Logger LOGGER = Loggers.getLogger(AbstractDoomAudio.class.getName()); + protected final DoomMain DS; protected final IMusic IMUS; protected final ISoundDriver ISND; @@ -83,7 +88,7 @@ public void Init(int sfxVolume, int musicVolume) { int i; - System.err.printf("S_Init: default sfx volume %d\n", sfxVolume); + LOGGER.log(Level.INFO, String.format("S_Init: default sfx volume %d", sfxVolume)); this.snd_SfxVolume = sfxVolume; this.snd_MusicVolume = musicVolume; @@ -191,8 +196,6 @@ public void Start() { // sfx_id, S_sfx[sfx_id].name , origin.type.toString(),origin.hashCode()); // check for bogus sound # if (sfx_id < 1 || sfx_id > NUMSFX) { - Exception e = new Exception(); - e.printStackTrace(); DS.doomSystem.Error("Bad sfx #: %d", sfx_id); } @@ -319,8 +322,8 @@ public void Start() { priority); if (D) { - System.err.printf("Handle %d for channel %d for sound %s vol %d sep %d\n", channels[cnum].handle, - cnum, sfx.name, volume, sep); + LOGGER.log(Level.FINE, String.format("Handle %d for channel %d for sound %s vol %d sep %d\n", channels[cnum].handle, + cnum, sfx.name, volume, sep)); } } diff --git a/src/s/AbstractSoundDriver.java b/src/s/AbstractSoundDriver.java index 0e27fb42..5937f9bf 100644 --- a/src/s/AbstractSoundDriver.java +++ b/src/s/AbstractSoundDriver.java @@ -4,6 +4,9 @@ import data.sounds; import static data.sounds.S_sfx; import doom.DoomMain; +import java.util.logging.Level; +import java.util.logging.Logger; +import mochadoom.Loggers; /** * Functionality and fields that are common among the various "sound drivers" @@ -13,6 +16,8 @@ */ public abstract class AbstractSoundDriver implements ISoundDriver { + private static final Logger LOGGER = Loggers.getLogger(AbstractSoundDriver.class.getName()); + protected final static boolean D = false; // debug protected final DoomMain DM; @@ -172,7 +177,8 @@ protected byte[] getsfx(String sfxname, int[] len, int index) { DM.wadLoader.UnlockLumpNum(sfxlump); if (D) { - System.out.printf("SFX %d name %s size %d speed %d padded to %d\n", index, S_sfx[index].name, dmx.datasize, dmx.speed, paddedsize); + LOGGER.log(Level.FINE, + String.format("SFX %d name %s size %d speed %d padded to %d", index, S_sfx[index].name, dmx.datasize, dmx.speed, paddedsize)); } // Preserve padded length. len[index] = paddedsize; @@ -304,7 +310,7 @@ public final int GetSfxLumpNum(sfxinfo_t sfx) { try { lump = DM.wadLoader.GetNumForName(namebuf); } catch (Exception e) { - e.printStackTrace(); + LOGGER.log(Level.SEVERE, "GetSfxLumpNum failure", e); return -1; } diff --git a/src/s/ClassicDoomSoundDriver.java b/src/s/ClassicDoomSoundDriver.java index dbcc73fc..a2518bef 100644 --- a/src/s/ClassicDoomSoundDriver.java +++ b/src/s/ClassicDoomSoundDriver.java @@ -6,10 +6,13 @@ import java.util.HashMap; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.Semaphore; +import java.util.logging.Level; +import java.util.logging.Logger; import javax.sound.sampled.AudioFormat; import javax.sound.sampled.AudioSystem; import javax.sound.sampled.DataLine; import javax.sound.sampled.SourceDataLine; +import mochadoom.Loggers; import pooling.AudioChunkPool; /** @@ -28,6 +31,8 @@ */ public class ClassicDoomSoundDriver extends AbstractSoundDriver { + private static final Logger LOGGER = Loggers.getLogger(ClassicDoomSoundDriver.class.getName()); + protected final Semaphore produce; protected final Semaphore consume; @@ -186,11 +191,10 @@ public void UpdateSound() { if (channel_pointer >= channelsend[chan]) { // Reset pointer for a channel. if (D) { - System.err - .printf( - "Channel %d handle %d pointer %d thus done, stopping\n", - chan, this.channelhandles[chan], - channel_pointer); + LOGGER.log(Level.INFO, String.format( + "Channel %d handle %d pointer %d thus done, stopping", + chan, this.channelhandles[chan], + channel_pointer)); } channels[chan] = null; channel_pointer = 0; @@ -278,7 +282,7 @@ public void SetChannels(int numChannels) { public boolean InitSound() { // Secure and configure sound device first. - System.out.println("I_InitSound: "); + LOGGER.log(Level.INFO, "I_InitSound"); // We only need a single data line. // PCM, signed, 16-bit, stereo, 22025 KHz, 2048 bytes per "frame", @@ -292,16 +296,15 @@ public boolean InitSound() { line = (SourceDataLine) AudioSystem.getSourceDataLine(format); line.open(format, AUDIOLINE_BUFFER); } catch (Exception e) { - e.printStackTrace(); - System.err.print("Could not play signed 16 data\n"); + LOGGER.log(Level.SEVERE, "Could not play signed 16 data", e); return false; } if (line != null) { - System.err.print(" configured audio device\n"); + LOGGER.log(Level.INFO, "configured audio device"); line.start(); } else { - System.err.print(" could not configure audio device\n"); + LOGGER.log(Level.SEVERE, "could not configure audio device"); return false; } @@ -316,17 +319,17 @@ public boolean InitSound() { SOUNDTHREAD.start(); // Initialize external data (all sounds) at start, keep static. - System.err.print("I_InitSound: "); + LOGGER.log(Level.INFO, "I_InitSound"); super.initSound8(); - System.err.print(" pre-cached all sound data\n"); + LOGGER.log(Level.INFO, "pre-cached all sound data"); // Now initialize mixbuffer with zero. initMixBuffer(); // Finished initialization. - System.err.print("I_InitSound: sound module ready\n"); + LOGGER.log(Level.INFO, "I_InitSound: sound module ready"); return true; } @@ -458,12 +461,12 @@ protected int addsfx(int sfxid, int volume, int step, int seperation) { channelids[slot] = sfxid; if (D) { - System.err.println(channelStatus()); + LOGGER.log(Level.FINE, String.valueOf(channelStatus())); } if (D) { - System.err.printf( - "Playing sfxid %d handle %d length %d vol %d on channel %d\n", - sfxid, rc, S_sfx[sfxid].data.length, volume, slot); + LOGGER.log(Level.FINE, String.format( + "Playing sfxid %d handle %d length %d vol %d on channel %d", + sfxid, rc, S_sfx[sfxid].data.length, volume, slot)); } // You tell me. @@ -537,7 +540,7 @@ public void run() { // System.err.println("Got a permit"); } catch (InterruptedException e) { // Well, ouch. - e.printStackTrace(); + LOGGER.log(Level.SEVERE, "MixServer run failure", e); } int chunks = 0; diff --git a/src/s/ClipSFXModule.java b/src/s/ClipSFXModule.java index fa7e1a0f..e800e93e 100644 --- a/src/s/ClipSFXModule.java +++ b/src/s/ClipSFXModule.java @@ -5,12 +5,15 @@ import doom.DoomMain; import java.util.Collection; import java.util.HashMap; +import java.util.logging.Level; +import java.util.logging.Logger; import javax.sound.sampled.AudioSystem; import javax.sound.sampled.Clip; import javax.sound.sampled.DataLine; import javax.sound.sampled.FloatControl; import javax.sound.sampled.FloatControl.Type; import javax.sound.sampled.LineUnavailableException; +import mochadoom.Loggers; /** Experimental Clip based driver. It does work, but it has no * tangible advantages over the Audioline or Classic one. If the @@ -33,6 +36,8 @@ */ public class ClipSFXModule extends AbstractSoundDriver { + private static final Logger LOGGER = Loggers.getLogger(ClipSFXModule.class.getName()); + HashMap cachedSounds = new HashMap<>(); // Either it's null (no clip is playing) or non-null (some clip is playing). @@ -68,16 +73,16 @@ private float[] computeLinear2DB() { @Override public boolean InitSound() { // Secure and configure sound device first. - System.err.println("I_InitSound: "); + LOGGER.log(Level.INFO, "I_InitSound"); // We don't actually do this here (will happen only when we // create the first audio clip). // Initialize external data (all sounds) at start, keep static. initSound16(); - System.err.print(" pre-cached all sound data\n"); + LOGGER.log(Level.INFO, "pre-cached all sound data"); // Finished initialization. - System.err.print("I_InitSound: sound module ready\n"); + LOGGER.log(Level.INFO, "I_InitSound: sound module ready"); return true; } @@ -225,14 +230,12 @@ private final void getClipForChannel(int c, int sfxid) { try { clip = (Clip) AudioSystem.getLine(info); } catch (LineUnavailableException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + LOGGER.log(Level.SEVERE, "Line unavailable", e); } try { clip.open(DoomSound.DEFAULT_SAMPLES_FORMAT, S_sfx[sfxid].data, 0, S_sfx[sfxid].data.length); } catch (LineUnavailableException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + LOGGER.log(Level.SEVERE, "Line unavailable", e); } if (!exists) { @@ -339,10 +342,10 @@ protected int addsfx(int sfxid, int volume, int pitch, int seperation) { //channels[slot].setPitch(pitch); if (D) { - System.err.println(channelStatus()); + LOGGER.log(Level.FINE, channelStatus()); } if (D) { - System.err.printf("Playing %d vol %d on channel %d\n", rc, volume, slot); + LOGGER.log(Level.FINE, String.format("Playing %d vol %d on channel %d\n", rc, volume, slot)); } // Well...play it. diff --git a/src/s/DSP.java b/src/s/DSP.java index 0e1e3d76..e28a10d2 100644 --- a/src/s/DSP.java +++ b/src/s/DSP.java @@ -106,7 +106,7 @@ public static double[] wsfiltgen(int nt, double fc, double fsr, double bw, doubl public static void main(String[] argv) { double[] fir = wsfiltgen(128, 11025 / 2.0, 22050, 22050 * 3.0 / 4, 0.5); - System.out.println(fir); + //System.out.println(fir); } diff --git a/src/s/DavidMusicModule.java b/src/s/DavidMusicModule.java index 96dc019e..cfebc5f8 100644 --- a/src/s/DavidMusicModule.java +++ b/src/s/DavidMusicModule.java @@ -1,6 +1,8 @@ package s; import java.io.ByteArrayInputStream; +import java.util.logging.Level; +import java.util.logging.Logger; import javax.sound.midi.InvalidMidiDataException; import javax.sound.midi.MidiDevice; import javax.sound.midi.MidiSystem; @@ -11,6 +13,7 @@ import javax.sound.midi.ShortMessage; import javax.sound.midi.SysexMessage; import javax.sound.midi.Transmitter; +import mochadoom.Loggers; /** Concern separated from David Martel's MIDI & MUS player * for Mocha Doom. Greatly improved upon by finnw, perfecting volume changes @@ -23,6 +26,8 @@ */ public class DavidMusicModule implements IMusic { + private static final Logger LOGGER = Loggers.getLogger(DavidMusicModule.class.getName()); + public static final int CHANGE_VOLUME = 7; public static final int CHANGE_VOLUME_FINE = 9; @@ -67,7 +72,7 @@ public void InitMusic() { transmitter = sequencer.getTransmitter(); transmitter.setReceiver(receiver); } catch (MidiUnavailableException e) { - e.printStackTrace(); + LOGGER.log(Level.SEVERE, "InitMusic: midi unavilable", e); } } @@ -99,8 +104,7 @@ public void ShutdownMusic() { @Override public void SetMusicVolume(int volume) { - - System.out.println("Midi volume set to " + volume); + LOGGER.log(Level.INFO, String.format("Midi volume set to %d", volume)); receiver.setGlobalVolume(volume / 127f); } @@ -115,7 +119,7 @@ public void PauseSong(int handle) { @Override public void ResumeSong(int handle) { if (songloaded) { - System.out.println("Resuming song"); + LOGGER.log(Level.FINE, "Resuming song"); sequencer.start(); } @@ -139,7 +143,7 @@ public int RegisterSong(byte[] data) { sequencer.setSequence(sequence); // Create a sequencer for the sequence songloaded = true; } catch (Exception e) { - e.printStackTrace(); + LOGGER.log(Level.SEVERE, "RegisterSong failure", e); return -1; } // In good old C style, we return 0 upon success? diff --git a/src/s/DavidSFXModule.java b/src/s/DavidSFXModule.java index 04f1f993..caf3c733 100644 --- a/src/s/DavidSFXModule.java +++ b/src/s/DavidSFXModule.java @@ -5,12 +5,15 @@ import doom.DoomMain; import java.util.ArrayList; import java.util.concurrent.Semaphore; +import java.util.logging.Level; +import java.util.logging.Logger; import javax.sound.sampled.AudioSystem; import javax.sound.sampled.DataLine; import javax.sound.sampled.FloatControl; import javax.sound.sampled.FloatControl.Type; import javax.sound.sampled.LineUnavailableException; import javax.sound.sampled.SourceDataLine; +import mochadoom.Loggers; /** David Martel's sound driver for Mocha Doom. Excellent work! * @@ -33,6 +36,8 @@ */ public class DavidSFXModule extends AbstractSoundDriver { + private static final Logger LOGGER = Loggers.getLogger(DavidSFXModule.class.getName()); + ArrayList cachedSounds = new ArrayList<>(); public final float[] linear2db; @@ -69,7 +74,7 @@ private float[] computeLinear2DB() { @Override public boolean InitSound() { // Secure and configure sound device first. - System.err.println("I_InitSound: "); + LOGGER.log(Level.INFO, "I_InitSound"); // Initialize external data (all sounds) at start, keep static. initSound16(); @@ -81,9 +86,9 @@ public boolean InitSound() { cachedSounds.add(tmp); } - System.err.print(" pre-cached all sound data\n"); + LOGGER.log(Level.INFO, "pre-cached all sound data"); // Finished initialization. - System.err.print("I_InitSound: sound module ready\n"); + LOGGER.log(Level.INFO, "I_InitSound: sound module ready"); return true; @@ -123,7 +128,7 @@ public void ShutdownSound() { this.soundThread[i].join(); } catch (InterruptedException e) { // TODO Auto-generated catch block - e.printStackTrace(); + LOGGER.log(Level.SEVERE, "ShutDownSound failure", e); } } // Done. @@ -162,8 +167,7 @@ private final void createDataLineForChannel(int c, int sfxid) { channels[c].auline = (SourceDataLine) AudioSystem.getLine(info); channels[c].auline.open(tmp.format); } catch (LineUnavailableException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + LOGGER.log(Level.INFO, "create data line for channel failure", e); } boolean errors = false; // Add individual volume control. @@ -171,13 +175,13 @@ private final void createDataLineForChannel(int c, int sfxid) { channels[c].vc = (FloatControl) channels[c].auline .getControl(Type.MASTER_GAIN); } else { - System.err.print("MASTER_GAIN, "); + LOGGER.log(Level.FINE, "MASTER_GAIN"); errors = true; if (channels[c].auline.isControlSupported(Type.VOLUME)) { channels[c].vc = (FloatControl) channels[c].auline .getControl(Type.VOLUME); } else { - System.err.print("VOLUME, "); + LOGGER.log(Level.FINE, "VOLUME"); } } @@ -187,7 +191,7 @@ private final void createDataLineForChannel(int c, int sfxid) { .getControl(Type.SAMPLE_RATE); } else { errors = true; - System.err.print("SAMPLE_RATE, "); + LOGGER.log(Level.FINE, "SAMPLE_RATE"); } // Add individual pan control @@ -195,18 +199,18 @@ private final void createDataLineForChannel(int c, int sfxid) { channels[c].bc = (FloatControl) channels[c].auline .getControl(FloatControl.Type.BALANCE); } else { - System.err.print("BALANCE, "); + LOGGER.log(Level.FINE, "BALANCE"); errors = true; if (channels[c].auline.isControlSupported(Type.PAN)) { channels[c].bc = (FloatControl) channels[c].auline .getControl(FloatControl.Type.PAN); } else { - System.err.print("PANNING "); + LOGGER.log(Level.FINE, "PANNING"); } } if (errors) { - System.err.printf("for channel %d NOT supported!\n", c); + LOGGER.log(Level.SEVERE, String.format("for channel %d NOT supported!", c)); } channels[c].auline.start(); @@ -369,10 +373,10 @@ protected int addsfx(int sfxid, int volume, int pitch, int seperation) { channels[slot].setPitch(pitch); if (D) { - System.err.println(channelStatus()); + LOGGER.log(Level.FINE, channelStatus()); } if (D) { - System.err.printf("Playing %d vol %d on channel %d\n", rc, volume, slot); + LOGGER.log(Level.FINE, String.format("Playing %d vol %d on channel %d", rc, volume, slot)); } // You tell me. return rc; @@ -463,7 +467,7 @@ public SoundWorker(int id) { public void addSound(byte[] ds, int handle) { if (D) { - System.out.printf("Added handle %d to channel %d\n", handle, id); + LOGGER.log(Level.INFO, String.format("Added handle %d to channel %d", handle, id)); } this.handle = handle; this.currentSound = ds; @@ -512,7 +516,7 @@ public void setPitch(int pitch) { } public void run() { - System.err.printf("Sound thread %d started\n", id); + LOGGER.log(Level.INFO, String.format("Sound thread %d started", id)); while (!terminate) { currentSoundSync = currentSound; if (currentSoundSync != null) { @@ -520,7 +524,7 @@ public void run() { try { auline.write(currentSoundSync, 0, currentSoundSync.length); } catch (Exception e) { - e.printStackTrace(); + LOGGER.log(Level.SEVERE, "SoundWorker run failure", e); return; } finally { // The previous steps are actually VERY fast. diff --git a/src/s/DoomIO.java b/src/s/DoomIO.java index c1848baa..9f9365a1 100644 --- a/src/s/DoomIO.java +++ b/src/s/DoomIO.java @@ -7,8 +7,12 @@ import java.lang.reflect.Array; import java.lang.reflect.Field; import java.lang.reflect.Method; +import java.util.logging.Level; +import java.util.logging.Logger; +import mochadoom.Loggers; public class DoomIO { + private static final Logger LOGGER = Loggers.getLogger(DoomIO.class.getName()); InputStream is; OutputStream os; @@ -213,8 +217,7 @@ public static void linkBA(Object obj, Object fieldName, Object stream, int size) ((OutputStream) stream).write(bytes); } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); + LOGGER.log(Level.SEVERE, "linkBA output failure", e); } } @@ -229,8 +232,7 @@ public static void linkBA(Object obj, Object fieldName, Object stream, int size) } } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); + LOGGER.log(Level.SEVERE, "linkBA input failure", e); } } diff --git a/src/s/DoomToWave.java b/src/s/DoomToWave.java index 1a0b92f1..07fcd372 100644 --- a/src/s/DoomToWave.java +++ b/src/s/DoomToWave.java @@ -6,9 +6,14 @@ import java.io.OutputStream; import java.nio.ByteBuffer; import java.nio.ByteOrder; +import java.util.logging.Level; +import java.util.logging.Logger; +import mochadoom.Loggers; import utils.C2JUtils; public class DoomToWave { + private static final Logger LOGGER = Loggers.getLogger(DoomToWave.class.getName()); + static int MEMORYCACHE = 0x8000; @@ -105,15 +110,15 @@ public void SNDsaveSound(InputStream is, OutputStream os) throws IOException { int speed = DoomIO.freadint(is, 2);//peek_u16_le (buffer + 2); int datasize = DoomIO.freadint(is, 4);//peek_i32_le (buffer + 4); if (type != 3) { - System.out.println("Sound: weird type " + type + ". Extracting anyway."); + LOGGER.log(Level.FINE, String.format("Sound: weird type %d. Extracting anyway.", type)); } int headsize = 2 + 2 + 4; /*- headsize*/ int phys_size = is.available(); if (datasize > phys_size) { - System.out.println("Sound %s: declared sample size %lu greater than lump size %lu ;"/*, + LOGGER.log(Level.INFO, "Sound: declared sample size greater than lump size"/*, lump_name (name), (unsigned long) datasize, (unsigned long) phys_size*/); - System.out.println("Sound %s: truncating to lump size."/*, lump_name (name)*/); + LOGGER.log(Level.INFO, "Sound: truncating to lump size."/*, lump_name (name)*/); datasize = phys_size; } /* Sometimes the size of sound lump is greater than the declared sound size. */ else if (datasize < phys_size) { @@ -140,15 +145,15 @@ public byte[] DMX2Wave(byte[] DMXSound) throws IOException { int speed = 0x0000FFFF & is.getShort();//peek_u16_le (buffer + 2); int datasize = is.getInt();//peek_i32_le (buffer + 4); if (type != 3) { - System.out.println("Sound: weird type " + type + ". Extracting anyway."); + LOGGER.log(Level.INFO, String.format("Sound: weird type %d. Extracting anyway.", type)); } int headsize = 2 + 2 + 4; /*- headsize*/ int phys_size = is.remaining(); if (datasize > phys_size) { - System.out.println("Sound %s: declared sample size %lu greater than lump size %lu ;"/*, + LOGGER.log(Level.INFO, "Sound: declared sample size greater than lump size"/*, lump_name (name), (unsigned long) datasize, (unsigned long) phys_size*/); - System.out.println("Sound %s: truncating to lump size."/*, lump_name (name)*/); + LOGGER.log(Level.INFO, "Sound: truncating to lump size."/*, lump_name (name)*/); datasize = phys_size; } /* Sometimes the size of sound lump is greater than the declared sound size. */ else if (datasize < phys_size) { diff --git a/src/s/FinnwMusicModule.java b/src/s/FinnwMusicModule.java index 1591e912..8eade358 100644 --- a/src/s/FinnwMusicModule.java +++ b/src/s/FinnwMusicModule.java @@ -20,6 +20,8 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; +import java.util.logging.Level; +import java.util.logging.Logger; import javax.sound.midi.InvalidMidiDataException; import javax.sound.midi.MidiDevice; import javax.sound.midi.MidiEvent; @@ -32,6 +34,7 @@ import javax.sound.midi.SysexMessage; import javax.sound.midi.Track; import javax.sound.midi.Transmitter; +import mochadoom.Loggers; /** A music driver that bypasses Sequences and sends events from a MUS lump * directly to a MIDI device. @@ -51,6 +54,8 @@ * */ public class FinnwMusicModule implements IMusic { + private static final Logger LOGGER = Loggers.getLogger(FinnwMusicModule.class.getName()); + public FinnwMusicModule() { this.lock = new ReentrantLock(); @@ -73,7 +78,7 @@ public void InitMusic() { genMidiEG.sendTo(receiver); sleepUninterruptibly(100, TimeUnit.MILLISECONDS); } catch (MidiUnavailableException ex) { - System.err.println(ex); + LOGGER.log(Level.WARNING, "InitMusic: midi unavailable", ex); receiver = null; } exec = Executors.newSingleThreadScheduledExecutor(new ThreadFactoryImpl()); @@ -736,7 +741,7 @@ void scheduleIfRequired(Receiver receiver, } catch (RejectedExecutionException ex) { // This is normal when shutting down } catch (Exception ex) { - System.err.println(ex); + LOGGER.log(Level.WARNING, "schedule failure", ex); } } } diff --git a/src/s/ISoundDriver.java b/src/s/ISoundDriver.java index 360a4b3a..5d34a8b9 100644 --- a/src/s/ISoundDriver.java +++ b/src/s/ISoundDriver.java @@ -5,6 +5,9 @@ import doom.CVarManager; import doom.CommandVariable; import doom.DoomMain; +import java.util.logging.Level; +import java.util.logging.Logger; +import mochadoom.Loggers; //Emacs style mode select -*- C++ -*- //----------------------------------------------------------------------------- @@ -30,6 +33,7 @@ // //----------------------------------------------------------------------------- public interface ISoundDriver { + static final Logger LOGGER = Loggers.getLogger(ISoundDriver.class.getName()); public static final int VOLUME_STEPS = 128; public static final int PANNING_STEPS = 256; @@ -93,7 +97,7 @@ public static ISoundDriver chooseModule(DoomMain DM, CVarManager CVM) { } // Check for sound init failure and revert to dummy if (!driver.InitSound()) { - System.err.println("S_InitSound: failed. Reverting to dummy...\n"); + LOGGER.log(Level.WARNING, "S_InitSound: failed. Reverting to dummy..."); return new DummySFX(); } return driver; diff --git a/src/s/QMusToMid.java b/src/s/QMusToMid.java index 7c402e42..b53249d5 100644 --- a/src/s/QMusToMid.java +++ b/src/s/QMusToMid.java @@ -8,8 +8,12 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.util.logging.Level; +import java.util.logging.Logger; +import mochadoom.Loggers; public class QMusToMid { + private static final Logger LOGGER = Loggers.getLogger(QMusToMid.class.getName()); public static final int NOTMUSFILE = 1; /* Not a MUS file */ @@ -93,8 +97,7 @@ void TWriteByte(int MIDItrack, byte byte_, Track track[]) { if (pos < TRACKBUFFERSIZE) { track[MIDItrack].data[(int) pos] = byte_; } else { - System.out.println("ERROR : Track buffer full.\n" - + "Increase the track buffer size (option -size).\n"); + LOGGER.log(Level.SEVERE, "ERROR: Track buffer full. Increase the track buffer size (option -size)."); System.exit(1); } track[MIDItrack].current++; @@ -156,7 +159,7 @@ int ReadMUSheader(MUSheader MUSh, InputStream file) { return 0; } catch (Exception e) { - e.printStackTrace(); + LOGGER.log(Level.WARNING, "Could not read MUS header", e); return COMUSFILE; } } @@ -171,7 +174,7 @@ int WriteMIDheader(int ntrks, int division, Object file) { DoomIO.fwrite2(DoomIO.toByteArray(ntrks), 2, file); DoomIO.fwrite2(DoomIO.toByteArray(division), 2, file); } catch (IOException e) { - e.printStackTrace(); + LOGGER.log(Level.WARNING, "Could not write MID header", e); } return 0; @@ -221,7 +224,7 @@ void WriteTrack(int tracknum, Object file, Track[] track) { DoomIO.fwrite(track[tracknum].data, (int) track[tracknum].current, 1, file); DoomIO.fwrite(TRACKMAGIC2, 4, 1, file); } catch (Exception e) { - e.printStackTrace(); + LOGGER.log(Level.WARNING, "Could not write track", e); } } @@ -238,7 +241,7 @@ void WriteFirstTrack(Object file) { DoomIO.fwrite(TRACKMAGIC6, 4, 1, file); } catch (Exception e) { - e.printStackTrace(); + LOGGER.log(Level.WARNING, "Could not write first track", e); } } @@ -319,7 +322,7 @@ int qmus2mid(InputStream mus, Object mid, boolean nodisplay, return MUSFILECOR ; }*/ if (!nodisplay) { - System.out.println(mus + " (" + mus.available() + " bytes) contains " + MUSh.channels + " melodic channel" + (MUSh.channels >= 2 ? "s" : "") + "\n"); + LOGGER.log(Level.FINE, String.format("stream (%d bytes) contains %d melodic channel(s)", mus.available(), MUSh.channels)); } if (MUSh.channels > 15) /* <=> MUSchannels+drums > 16 */ { @@ -337,12 +340,12 @@ int qmus2mid(InputStream mus, Object mid, boolean nodisplay, if (BufferSize != 0) { TRACKBUFFERSIZE = ((long) BufferSize) << 10; if (!nodisplay) { - System.out.println("Track buffer size set to " + BufferSize + " KB.\n"); + LOGGER.log(Level.FINE, String.format("Track buffer size set to %d KB.", BufferSize)); } } if (!nodisplay) { - System.out.println("Converting..."); + LOGGER.log(Level.FINE,"Converting..."); } event = getc(mus); et = event_type(event); @@ -463,16 +466,15 @@ int qmus2mid(InputStream mus, Object mid, boolean nodisplay, } } if (!nodisplay) { - System.out.println("done !\n"); + LOGGER.log(Level.FINE,"done!"); } if (ouch != 0) { - System.out.println("WARNING : There are bytes missing at the end of " + mus + ".\n " - + "The end of the MIDI file might not fit the original one.\n"); + LOGGER.log(Level.WARNING,"WARNING: There are bytes missing at the end of stream. The end of the MIDI file might not fit the original one."); } if (division == 0) { division = 89; } else if (!nodisplay) { - System.out.println("Ticks per quarter note set to " + division + ".\n"); + LOGGER.log(Level.FINE,String.format("Ticks per quarter note set to %d", division)); } if (!nodisplay) { if (division != 89) { @@ -485,13 +487,13 @@ int qmus2mid(InputStream mus, Object mid, boolean nodisplay, min = time / 60; sec = (char) (time - min * 60); if (division != 89) { - System.out.println(" MID file"); + LOGGER.log(Level.FINE,"MID file"); } else { - System.out.println("Playing time: " + min + "min " + sec + "sec"); + LOGGER.log(Level.FINE, String.format("Playing time: %dmin %dsec", min, sec)); } } if (!nodisplay) { - System.out.println("Writing..."); + LOGGER.log(Level.FINE,"Writing..."); } WriteMIDheader(TrackCnt + 1, division, mid); WriteFirstTrack(mid); @@ -499,13 +501,12 @@ int qmus2mid(InputStream mus, Object mid, boolean nodisplay, WriteTrack(i, mid, track); } if (!nodisplay) { - System.out.println("done !\n"); + LOGGER.log(Level.FINE,"done !"); } - if (!nodisplay && (!nocomp)) { - System.out.println("Compression : %u%%.\n"/*, - (100 * n) / (n+ (long) ftell( mid ))*/); - } - + //if (!nodisplay && (!nocomp)) { + // System.out.println("Compression : %u%%.\n"/*, + // (100 * n) / (n+ (long) ftell( mid ))*/); + //} return 0; } @@ -581,28 +582,27 @@ int convert(InputStream mus, Object mid, boolean nodisplay, int div, int error = qmus2mid(mus, mid, nodisplay, div, size, nocomp); if (error != 0) { - System.out.println("ERROR : "); switch (error) { case NOTMUSFILE: - System.out.println("%s is not a MUS file.\n"/*, mus*/); + LOGGER.log(Level.SEVERE,"ERROR: stream is not a MUS file."/*, mus*/); break; case COMUSFILE: - System.out.println("Can't open %s for read.\n"/*, mus*/); + LOGGER.log(Level.SEVERE,"ERROR: Can't open stream for read."/*, mus*/); break; case COTMPFILE: - System.out.println("Can't open temp file.\n"); + LOGGER.log(Level.SEVERE,"ERROR: Can't open temp file."); break; case CWMIDFILE: - System.out.println("Can't write %s (?).\n"/*, mid */); + LOGGER.log(Level.SEVERE,"ERROR: Can't write stream (?)."/*, mid */); break; case MUSFILECOR: - System.out.println("%s is corrupted.\n"/*, mus*/); + LOGGER.log(Level.SEVERE,"ERROR: stream is corrupted."/*, mus*/); break; case TOOMCHAN: - System.out.println("%s contains more than 16 channels.\n"/*, mus*/); + LOGGER.log(Level.SEVERE,"ERROR: stream contains more than 16 channels."/*, mus*/); break; case MEMALLOC: - System.out.println("Not enough memory.\n"); + LOGGER.log(Level.SEVERE,"ERROR: Not enough memory."); break; default: break; @@ -611,7 +611,7 @@ int convert(InputStream mus, Object mid, boolean nodisplay, int div, } if (!nodisplay) { - System.out.println(mus + " converted successfully.\n"); + LOGGER.log(Level.FINE,"stream converted successfully."); /*if( (file = fopen( mid, "rb" )) != NULL ) { //stat( mid, &file_data ) ; diff --git a/src/s/SpeakerDoomSoundDriver.java b/src/s/SpeakerDoomSoundDriver.java index 243c3889..cd26ced4 100644 --- a/src/s/SpeakerDoomSoundDriver.java +++ b/src/s/SpeakerDoomSoundDriver.java @@ -1,6 +1,9 @@ package s; import doom.DoomMain; +import java.util.logging.Level; +import java.util.logging.Logger; +import mochadoom.Loggers; /** A variation of the Classic Sound Driver, decoding the DP-lumps * instead of the DS. A better way would be to build-in an @@ -10,6 +13,8 @@ * */ public class SpeakerDoomSoundDriver extends ClassicDoomSoundDriver { + private static final Logger LOGGER = Loggers.getLogger(SpeakerDoomSoundDriver.class.getName()); + public SpeakerDoomSoundDriver(DoomMain DM, int numChannels) { super(DM, numChannels); @@ -79,7 +84,7 @@ protected byte[] getsfx(String sfxname, DM.wadLoader.UnlockLumpNum(sfxlump); if (D) { - System.out.printf("SFX %d size %d padded to %d\n", index, size, paddedsize); + LOGGER.log(Level.FINE, String.format("SFX %d size %d padded to %d", index, size, paddedsize)); } // Preserve padded length. len[index] = paddedsize; diff --git a/src/s/SuperDoomSoundDriver.java b/src/s/SuperDoomSoundDriver.java index 0de050e6..db94889d 100644 --- a/src/s/SuperDoomSoundDriver.java +++ b/src/s/SuperDoomSoundDriver.java @@ -8,10 +8,13 @@ import java.util.TimerTask; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.Semaphore; +import java.util.logging.Level; +import java.util.logging.Logger; import javax.sound.sampled.AudioFormat; import javax.sound.sampled.AudioSystem; import javax.sound.sampled.DataLine; import javax.sound.sampled.SourceDataLine; +import mochadoom.Loggers; import pooling.AudioChunkPool; /** @@ -37,6 +40,8 @@ */ public class SuperDoomSoundDriver extends AbstractSoundDriver { + private static final Logger LOGGER = Loggers.getLogger(SuperDoomSoundDriver.class.getName()); + protected final Semaphore produce; protected final Semaphore consume; @@ -128,7 +133,7 @@ public void SetChannels(int numChannels) { public boolean InitSound() { // Secure and configure sound device first. - System.err.print("I_InitSound: "); + LOGGER.log(Level.INFO, "I_InitSound"); // We only need a single data line. // PCM, signed, 16-bit, stereo, 22025 KHz, 2048 bytes per "frame", @@ -142,16 +147,15 @@ public boolean InitSound() { line = (SourceDataLine) AudioSystem.getSourceDataLine(format); line.open(format, AUDIOLINE_BUFFER); } catch (Exception e) { - e.printStackTrace(); - System.err.print("Could not play signed 16 data\n"); + LOGGER.log(Level.SEVERE, "Could not play signed 16 data", e); return false; } if (line != null) { - System.err.print("configured audio device\n"); + LOGGER.log(Level.INFO, "configured audio device"); line.start(); } else { - System.err.print("could not configure audio device\n"); + LOGGER.log(Level.SEVERE, "could not configure audio device"); return false; } @@ -165,14 +169,14 @@ public boolean InitSound() { MIXTHREAD.start(); // Initialize external data (all sounds) at start, keep static. - System.err.print("I_InitSound: "); + LOGGER.log(Level.INFO, "I_InitSound"); super.initSound8(); - System.err.print("pre-cached all sound data\n"); + LOGGER.log(Level.INFO, "pre-cached all sound data"); // Finished initialization. - System.err.print("I_InitSound: sound module ready\n"); + LOGGER.log(Level.INFO, "I_InitSound: sound module ready"); return true; @@ -307,12 +311,12 @@ protected int addsfx(int sfxid, int volume, int step, int seperation) { channelids[slot] = sfxid; if (D) { - System.err.println(channelStatus()); + LOGGER.log(Level.FINE, String.valueOf(channelStatus())); } if (D) { - System.err.printf( - "Playing sfxid %d handle %d length %d vol %d on channel %d\n", - sfxid, rc, S_sfx[sfxid].data.length, volume, slot); + LOGGER.log(Level.FINE, String.format( + "Playing sfxid %d handle %d length %d vol %d on channel %d", + sfxid, rc, S_sfx[sfxid].data.length, volume, slot)); } MIXSRV.submitMixMessage(m); @@ -353,9 +357,9 @@ public void ShutdownSound() { } catch (InterruptedException e) { // Well, I don't care. } - System.err.printf("3\n"); + //System.err.printf("3\n"); line.close(); - System.err.printf("4\n"); + //System.err.printf("4\n"); } @@ -391,7 +395,7 @@ public void run() { //System.err.print("...got it\n"); } catch (InterruptedException e) { // Well, ouch. - e.printStackTrace(); + LOGGER.log(Level.SEVERE, "PlaybackServer run failure", e); } int chunks = 0; @@ -631,11 +635,10 @@ public void run() { if (channel_pointer >= channelsend[chan]) { // Reset pointer for a channel. if (D) { - System.err - .printf( - "Channel %d handle %d pointer %d thus done, stopping\n", - chan, channelhandles[chan], - channel_pointer); + LOGGER.log(Level.FINE, String.format( + "Channel %d handle %d pointer %d thus done, stopping", + chan, channelhandles[chan], + channel_pointer)); } channels[chan] = null; diff --git a/src/s/VolumeScalingReceiver.java b/src/s/VolumeScalingReceiver.java index 89382b8e..7d1e8c95 100644 --- a/src/s/VolumeScalingReceiver.java +++ b/src/s/VolumeScalingReceiver.java @@ -7,6 +7,8 @@ import java.util.Iterator; import java.util.List; import java.util.Locale; +import java.util.logging.Level; +import java.util.logging.Logger; import javax.sound.midi.InvalidMidiDataException; import javax.sound.midi.MidiDevice; import javax.sound.midi.MidiMessage; @@ -16,6 +18,7 @@ import javax.sound.midi.Sequencer; import javax.sound.midi.ShortMessage; import javax.sound.midi.Synthesizer; +import mochadoom.Loggers; /** A {@link Receiver} that scales channel volumes. * @@ -27,6 +30,7 @@ * */ public class VolumeScalingReceiver implements Receiver { + private static final Logger LOGGER = Loggers.getLogger(VolumeScalingReceiver.class.getName()); /** Guess which is the "best" available synthesizer & create a * VolumeScalingReceiver that forwards to it. @@ -172,7 +176,7 @@ private void sendVolumeChange(int chan, int newVolScaled, long timeStamp) { message.setMessage(0xb0 | (chan & 15), 7, newVolScaled); synthReceiver.send(message, timeStamp); } catch (InvalidMidiDataException ex) { - System.err.println(ex); + LOGGER.log(Level.SEVERE, "sendVolumeChange failure", ex); } } diff --git a/src/savegame/VanillaDSG.java b/src/savegame/VanillaDSG.java index 56c23ec3..ba640d61 100644 --- a/src/savegame/VanillaDSG.java +++ b/src/savegame/VanillaDSG.java @@ -24,6 +24,7 @@ import java.util.HashMap; import java.util.List; import java.util.logging.Level; +import java.util.logging.Logger; import m.Settings; import mochadoom.Engine; import mochadoom.Loggers; @@ -51,6 +52,7 @@ import utils.C2JUtils; public class VanillaDSG implements IDoomSaveGame { + private static final Logger LOGGER = Loggers.getLogger(VanillaDSG.class.getName()); VanillaDSGHeader header; final DoomMain DOOM; @@ -85,7 +87,7 @@ public boolean doLoad(DataInputStream f) { try { this.f = f; maxsize = f.available(); - System.out.println("Max size " + maxsize); + LOGGER.log(Level.FINE, String.format("Max size %d", maxsize)); this.header = new VanillaDSGHeader(); header.read(f); UnArchivePlayers(); @@ -95,7 +97,7 @@ public boolean doLoad(DataInputStream f) { byte terminator = f.readByte(); return terminator == 0x1D; } catch (IOException e) { - Loggers.getLogger(VanillaDSG.class.getName()).log(Level.WARNING, e, () + LOGGER.log(Level.WARNING, e, () -> String.format("Error while loading savegame! Cause: %s", e.getMessage())); return false; // Needed to shut up compiler. } @@ -517,7 +519,7 @@ protected void reconstructPointers() { } if (player == 0) { - Loggers.getLogger(VanillaDSG.class.getName()).log(Level.WARNING, + LOGGER.log(Level.WARNING, "Player not found, cannot reconstruct pointers!"); return; } @@ -866,7 +868,7 @@ public boolean doSave(DataOutputStream f) { // TODO: the rest... f.write(0x1D); } catch (IOException e) { - Loggers.getLogger(VanillaDSG.class.getName()).log(Level.WARNING, e, () + LOGGER.log(Level.WARNING, e, () -> String.format("Error while saving savegame! Cause: %s", e.getMessage())); return false; // Needed to shut up compiler. } diff --git a/src/timing/NanoTicker.java b/src/timing/NanoTicker.java index 2a5a717d..52767cdf 100644 --- a/src/timing/NanoTicker.java +++ b/src/timing/NanoTicker.java @@ -1,9 +1,14 @@ package timing; import static data.Defines.TICRATE; +import java.util.logging.Level; +import java.util.logging.Logger; +import mochadoom.Loggers; public class NanoTicker implements ITicker { + private static final Logger LOGGER = Loggers.getLogger(NanoTicker.class.getName()); + /** * I_GetTime @@ -23,7 +28,7 @@ public int GetTime() { } newtics = (int) (((tp - basetime) * TICRATE) / 1000000000);// + tp.tv_usec*TICRATE/1000000; if (newtics < oldtics) { - System.err.printf("Timer discrepancies detected : %d", (++discrepancies)); + LOGGER.log(Level.WARNING, String.format("Timer discrepancies detected : %d", (++discrepancies))); return oldtics; } return (oldtics = newtics); diff --git a/src/utils/C2JUtils.java b/src/utils/C2JUtils.java index 0851c085..91bbf4ae 100644 --- a/src/utils/C2JUtils.java +++ b/src/utils/C2JUtils.java @@ -12,6 +12,9 @@ import java.net.MalformedURLException; import java.net.URL; import java.util.Arrays; +import java.util.logging.Level; +import java.util.logging.Logger; +import mochadoom.Loggers; import p.Resettable; import w.InputStreamSugar; @@ -23,6 +26,8 @@ */ public final class C2JUtils { + private static final Logger LOGGER = Loggers.getLogger(C2JUtils.class.getName()); + public static char[] strcpy(char[] s1, final char[] s2) { System.arraycopy(s2, 0, s1, 0, Math.min(s1.length, s2.length)); return s1; @@ -170,9 +175,7 @@ public static void initArrayOfObjects(T[] os, Class c) { os[i] = c.getDeclaredConstructor().newInstance(); } } catch (IllegalAccessException | InstantiationException | NoSuchMethodException | InvocationTargetException e) { - e.printStackTrace(); - System.err.println("Failure to allocate " + os.length - + " objects of class" + c.getName() + "!"); + LOGGER.log(Level.SEVERE, String.format("Failure to allocate %d objects of class %s", os.length, c.getName()), e); System.exit(-1); } } @@ -195,10 +198,7 @@ public static void initArrayOfObjects(T[] os) { os[i] = c.getDeclaredConstructor().newInstance(); } } catch (IllegalAccessException | InstantiationException | NoSuchMethodException | InvocationTargetException e) { - e.printStackTrace(); - System.err.println("Failure to allocate " + os.length - + " objects of class " + c.getName() + "!"); - + LOGGER.log(Level.SEVERE, String.format("Failure to allocate %d objects of class %s", os.length, c.getName()), e); System.exit(-1); } } @@ -232,8 +232,7 @@ public static T[] createArrayOfObjects(Class c, int num) { os[i] = c.getDeclaredConstructor().newInstance(); } } catch (IllegalAccessException | InstantiationException | NoSuchMethodException | InvocationTargetException e) { - e.printStackTrace(); - System.err.println("Failure to instantiate " + os.length + " objects of class " + c.getName() + "!"); + LOGGER.log(Level.SEVERE, String.format("Failure to instantiate %d objects of class %s", os.length, c.getName()), e); System.exit(-1); } @@ -266,9 +265,7 @@ public static T[] createArrayOfObjects(T instance, int num) { os[i] = c.getDeclaredConstructor().newInstance(); } } catch (IllegalAccessException | InstantiationException | NoSuchMethodException | InvocationTargetException e) { - e.printStackTrace(); - System.err.println("Failure to instantiate " + os.length - + " objects of class " + c.getName() + "!"); + LOGGER.log(Level.SEVERE, String.format("Failure to instantiate %d objects of class %s", os.length, c.getName()), e); System.exit(-1); } @@ -294,10 +291,7 @@ public static void initArrayOfObjects(T[] os, int startpos, int endpos) { os[i] = c.getDeclaredConstructor().newInstance(); } } catch (IllegalAccessException | InstantiationException | NoSuchMethodException | InvocationTargetException e) { - e.printStackTrace(); - System.err.println("Failure to allocate " + os.length - + " objects of class " + c.getName() + "!"); - + LOGGER.log(Level.SEVERE, String.format("Failure to allocate %d objects of class %s", os.length, c.getName()), e); System.exit(-1); } } @@ -696,12 +690,12 @@ public static String extractFileBase(String path, int limit, boolean whole) { return path.substring(src, src + len); } - /** Maes: File intead of "inthandle" */ + /** Maes: File instead of "inthandle" */ public static long filelength(File handle) { try { return handle.length(); } catch (Exception e) { - System.err.println("Error fstating"); + LOGGER.log(Level.SEVERE, "Error fstating", e); return -1; } @@ -718,7 +712,7 @@ public static T[] resize(T[] oldarray, int newsize) { cls = (T) oldarray.getClass().getComponentType().getDeclaredConstructor().newInstance(); return resize(cls, oldarray, newsize); } catch (IllegalAccessException | InstantiationException | NoSuchMethodException | InvocationTargetException e) { - System.err.println("Cannot autodetect type in resizeArray.\n"); + LOGGER.log(Level.SEVERE, "Cannot autodetect type in resizeArray.", e); return null; } } @@ -743,7 +737,7 @@ public static T[] resize(T instance, T[] oldarray, int newsize) { // Init the null portions as well C2JUtils.initArrayOfObjects(tmp, oldarray.length, tmp.length); - System.out.printf("Old array of type %s resized. New capacity: %d\n", instance.getClass(), newsize); + LOGGER.log(Level.INFO, String.format("Old array of type %s resized. New capacity: %d", instance.getClass(), newsize)); return tmp; } @@ -760,8 +754,8 @@ public static T[] resizeNoAutoInit(T[] oldarray, int newsize) { // For non-autoinit types, this is enough. T[] tmp = Arrays.copyOf(oldarray, newsize); - System.out.printf("Old array of type %s resized without auto-init. New capacity: %d\n", - tmp.getClass().getComponentType(), newsize); + LOGGER.log(Level.INFO, String.format("Old array of type %s resized without auto-init. New capacity: %d", + tmp.getClass().getComponentType(), newsize)); return tmp; } @@ -773,9 +767,7 @@ public static T[] getNewArray(T instance, int size) { try { return (T[]) Array.newInstance(c, size); } catch (NegativeArraySizeException e) { - e.printStackTrace(); - System.err.println("Failure to allocate " + size - + " objects of class " + c.getName() + "!"); + LOGGER.log(Level.SEVERE, String.format("Failure to allocate %d objects of class %s", size, c.getName()), e); System.exit(-1); } @@ -793,9 +785,7 @@ public final static T[] getNewArray(Class c, int size) { try { return (T[]) Array.newInstance(c, size); } catch (NegativeArraySizeException e) { - e.printStackTrace(); - System.err.println("Failure to allocate " + size - + " objects of class " + c.getName() + "!"); + LOGGER.log(Level.SEVERE, String.format("Failure to allocate %d objects of class %s", size, c.getName()), e); System.exit(-1); } diff --git a/src/utils/OrderedExecutor.java b/src/utils/OrderedExecutor.java index dad0b96d..7fab624c 100644 --- a/src/utils/OrderedExecutor.java +++ b/src/utils/OrderedExecutor.java @@ -7,6 +7,9 @@ import java.util.concurrent.Executor; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; +import java.util.logging.Level; +import java.util.logging.Logger; +import mochadoom.Loggers; /** * An executor that make sure tasks submitted with the same key @@ -24,6 +27,7 @@ * * @param type of keys. */ public class OrderedExecutor { + private static final Logger LOGGER = Loggers.getLogger(OrderedExecutor.class.getName()); private final Executor executor; private final Map tasks; @@ -95,7 +99,7 @@ public void run() { try { runnable.run(); } catch (Exception ex) { - ex.printStackTrace(); + LOGGER.log(Level.SEVERE, "OrderedExecutor run failure", ex); } // Check to see if there are queued task, if yes, submit for execution. lock.lock(); diff --git a/src/utils/ResourceIO.java b/src/utils/ResourceIO.java index c43e37ff..3da32c8f 100644 --- a/src/utils/ResourceIO.java +++ b/src/utils/ResourceIO.java @@ -27,6 +27,9 @@ import java.nio.file.Path; import java.util.function.Consumer; import java.util.function.Supplier; +import java.util.logging.Level; +import java.util.logging.Logger; +import mochadoom.Loggers; /** * Resource IO to automate read/write on configuration/resources @@ -34,6 +37,8 @@ * @author Good Sign */ public class ResourceIO { + private static final Logger LOGGER = Loggers.getLogger(ResourceIO.class.getName()); + private final Path file; private final Charset charset = Charset.forName("US-ASCII"); @@ -64,7 +69,7 @@ public boolean readLines(final Consumer lineConsumer) { return true; } catch (IOException x) { - System.err.format("IOException: %s%n", x); + LOGGER.log(Level.WARNING, "ResourceIO read failure", x); return false; } } @@ -82,7 +87,7 @@ public boolean writeLines(final Supplier lineSupplier, final OpenOption. return true; } catch (IOException x) { - System.err.format("IOException: %s%n", x); + LOGGER.log(Level.WARNING, "ResourceIO write failure", x); return false; } } diff --git a/src/v/graphics/Columns.java b/src/v/graphics/Columns.java index b54a5ff0..ddaf3195 100644 --- a/src/v/graphics/Columns.java +++ b/src/v/graphics/Columns.java @@ -20,6 +20,7 @@ import java.util.concurrent.ForkJoinPool; import java.util.function.IntConsumer; import java.util.logging.Level; +import java.util.logging.Logger; import java.util.stream.IntStream; import m.Settings; import mochadoom.Engine; @@ -35,7 +36,7 @@ * @author Good Sign */ public interface Columns> extends Blocks { - + static final Logger LOGGER = Loggers.getLogger(Columns.class.getName()); /** * We have to draw columns to the screen, not rows and is ineffective performance-wise because * System.arraycopy only speeds a lot row copying, where it only have to be called once @@ -94,7 +95,7 @@ default void DrawPatchColumns(V screen, patch_t patch, int x, int y, int dupx, i if (U.COLUMN_THREADS > 0) try { U.pool.submit(() -> IntStream.range(0, patch.width).parallel().forEach(task)).get(); } catch (InterruptedException | ExecutionException ex) { - Loggers.getLogger(Columns.class.getName()).log(Level.SEVERE, null, ex); + LOGGER.log(Level.SEVERE, null, ex); } else { for (int i = 0; i < patch.width; ++i) { task.accept(i); diff --git a/src/v/graphics/Patches.java b/src/v/graphics/Patches.java index dacb31a2..52b7e1be 100644 --- a/src/v/graphics/Patches.java +++ b/src/v/graphics/Patches.java @@ -17,6 +17,7 @@ package v.graphics; import java.util.logging.Level; +import java.util.logging.Logger; import mochadoom.Loggers; import rr.patch_t; import utils.C2JUtils; @@ -55,6 +56,7 @@ * Unless overriden by flags, starting x and y are automatically scaled (implied V_SCALESTART) */ public interface Patches> extends Columns { + static final Logger LOGGER = Loggers.getLogger(Patches.class.getName()); /** * V_DrawPatch @@ -125,7 +127,7 @@ default void DrawPatchCenteredScaled(E screen, patch_t patch, VideoScale vs, int * - Good Sign 2017/04/22 */ default void printDebugPatchInfo(patch_t patch, int x, int y, final boolean predevide, final boolean scaleOffset, final boolean scaleStart, int dupx, int dupy) { - Loggers.getLogger(Patches.class.getName()).log(Level.INFO, () -> String.format( + LOGGER.log(Level.INFO, () -> String.format( "V_DrawPatch: bad patch (ignored)\n" + "Patch %s at %d, %d exceeds LFB\n" + "\tpredevide: %s\n" diff --git a/src/v/renderers/BufferedRenderer16.java b/src/v/renderers/BufferedRenderer16.java index 617cd5c8..ff20693b 100644 --- a/src/v/renderers/BufferedRenderer16.java +++ b/src/v/renderers/BufferedRenderer16.java @@ -23,6 +23,7 @@ import java.awt.image.VolatileImage; import java.util.concurrent.BrokenBarrierException; import java.util.logging.Level; +import java.util.logging.Logger; import mochadoom.Loggers; import v.tables.BlurryTable; import v.tables.ColorTint; @@ -40,6 +41,7 @@ * - Good Sign 2017/04/12 */ class BufferedRenderer16 extends SoftwareParallelVideoRenderer { + private static final Logger LOGGER = Loggers.getLogger(BufferedRenderer16.class.getName()); protected final short[] raster; @@ -124,7 +126,7 @@ void doWriteScreen() { try { updateBarrier.await(); } catch (InterruptedException | BrokenBarrierException e) { - Loggers.getLogger(BufferedRenderer32.class.getName()).log(Level.SEVERE, e, null); + LOGGER.log(Level.SEVERE, e, null); } } @@ -185,7 +187,7 @@ public void run() { try { updateBarrier.await(); } catch (InterruptedException | BrokenBarrierException e) { - Loggers.getLogger(BufferedRenderer32.class.getName()).log(Level.WARNING, e, null); + LOGGER.log(Level.WARNING, e, null); } } } diff --git a/src/v/renderers/BufferedRenderer32.java b/src/v/renderers/BufferedRenderer32.java index 21343b29..40c8d504 100644 --- a/src/v/renderers/BufferedRenderer32.java +++ b/src/v/renderers/BufferedRenderer32.java @@ -26,6 +26,7 @@ import java.awt.image.VolatileImage; import java.util.concurrent.BrokenBarrierException; import java.util.logging.Level; +import java.util.logging.Logger; import mochadoom.Loggers; import v.tables.BlurryTable; import v.tables.ColorTint; @@ -42,6 +43,7 @@ * - Good Sign 2017/04/12 */ class BufferedRenderer32 extends SoftwareParallelVideoRenderer { + private static final Logger LOGGER = Loggers.getLogger(BufferedRenderer32.class.getName()); protected final int[] raster; @@ -122,7 +124,7 @@ void doWriteScreen() { try { updateBarrier.await(); } catch (InterruptedException | BrokenBarrierException e) { - Loggers.getLogger(BufferedRenderer32.class.getName()).log(Level.SEVERE, e, null); + LOGGER.log(Level.SEVERE, e, null); } final Graphics2D g = screen.createGraphics(); @@ -189,7 +191,7 @@ public void run() { try { updateBarrier.await(); } catch (InterruptedException | BrokenBarrierException e) { - Loggers.getLogger(BufferedRenderer32.class.getName()).log(Level.WARNING, e, null); + LOGGER.log(Level.WARNING, e, null); } } } diff --git a/src/w/DoomIO.java b/src/w/DoomIO.java index 1e759629..4021ad57 100644 --- a/src/w/DoomIO.java +++ b/src/w/DoomIO.java @@ -28,7 +28,10 @@ of the License, or (at your option) any later version. import java.nio.ByteOrder; import java.nio.charset.Charset; import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; import m.Swap; +import mochadoom.Loggers; /** * An extension of RandomAccessFile, which handles readString/WriteString specially @@ -47,6 +50,8 @@ of the License, or (at your option) any later version. * */ public class DoomIO { + private static final Logger LOGGER = Loggers.getLogger(DoomIO.class.getName()); + private DoomIO() { @@ -205,7 +210,7 @@ public static void writeString(DataOutputStream dos, String s) { dos.writeBytes(s); } } catch (Exception e) { - System.err.println("writeString " + s + " to DoomFile failed!"); + LOGGER.log(Level.WARNING, String.format("writeString %s to DoomFile failed!", s)); } } diff --git a/src/w/IWadLoader.java b/src/w/IWadLoader.java index a85e473e..b72604f7 100644 --- a/src/w/IWadLoader.java +++ b/src/w/IWadLoader.java @@ -13,6 +13,8 @@ import java.io.IOException; import java.nio.ByteBuffer; import java.util.function.IntFunction; +import java.util.logging.Level; +import java.util.logging.Logger; import rr.patch_t; import utils.GenericCopy.ArraySupplier; import v.graphics.Lights; @@ -22,6 +24,8 @@ public interface IWadLoader { + static final Logger LOGGER = Logger.getLogger(IWadLoader.class.getName()); + /** * W_Reload Flushes any of the reloadable lumps in memory and reloads the * directory. @@ -314,8 +318,7 @@ default byte[] LoadPlaypal() { playpal.length, minLength)); } - System.out.print("VI_Init: set palettes.\n"); - System.out.println("Palette: " + playpal.length / PAL_NUM_STRIDES + " colors"); + LOGGER.log(Level.FINE, String.format("VI_Init: set palettes: %d colors", playpal.length / PAL_NUM_STRIDES)); InjectLumpNum(pallump, new DoomBuffer(ByteBuffer.wrap(playpal))); return playpal; @@ -340,8 +343,7 @@ default byte[][] LoadColormap() { colormap.length, minLength)); } - System.out.print("VI_Init: set colormaps.\n"); - System.out.println("Colormaps: " + colormap.length); + LOGGER.log(Level.FINE, String.format("VI_Init: set colormaps: %d", colormap.length)); final byte[] tmp = new byte[length]; ReadLump(lump, tmp); diff --git a/src/w/JadDecompress.java b/src/w/JadDecompress.java index 0ed2c397..b7635a77 100644 --- a/src/w/JadDecompress.java +++ b/src/w/JadDecompress.java @@ -1,6 +1,12 @@ package w; +import java.util.logging.Level; +import java.util.logging.Logger; +import mochadoom.Loggers; + public class JadDecompress { + private static final Logger LOGGER = Loggers.getLogger(JadDecompress.class.getName()); + public final static int WINDOW_SIZE = 4096; @@ -52,7 +58,7 @@ public static void decode(byte[] input, byte[] output) { } - System.out.printf("Expanded %d to %d\n", input_ptr, output_ptr); + LOGGER.log(Level.INFO, String.format("Expanded %d to %d", input_ptr, output_ptr)); } } diff --git a/src/w/WadLoader.java b/src/w/WadLoader.java index a3437d88..4f864940 100644 --- a/src/w/WadLoader.java +++ b/src/w/WadLoader.java @@ -40,6 +40,7 @@ import java.util.List; import java.util.function.IntFunction; import java.util.logging.Level; +import java.util.logging.Logger; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; import mochadoom.Loggers; @@ -50,6 +51,8 @@ public class WadLoader implements IWadLoader { + private static final Logger LOGGER = Loggers.getLogger(WadLoader.class.getName()); + protected IDoomSystem I; ///// CONSTRUCTOR @@ -405,12 +408,12 @@ public void InitMultipleFiles(String[] filenames) throws Exception { } else { this.AddFile(s, null, type); } - Loggers.getLogger(WadLoader.class.getName()).log(Level.INFO, + LOGGER.log(Level.INFO, String.format("Added %s (zipped: %s network: %s)", s, C2JUtils.flags(type, InputStreamSugar.ZIP_FILE), C2JUtils.flags(type, InputStreamSugar.NETWORK_FILE))); } else { - Loggers.getLogger(WadLoader.class.getName()).log(Level.SEVERE, + LOGGER.log(Level.SEVERE, String.format("Couldn't open resource %s", s)); } } @@ -597,12 +600,7 @@ public int GetNumForName(String name) { i = CheckNumForName(name.toUpperCase()); if (i == -1) { - Exception e = new Exception(); - e.printStackTrace(); - System.err.println("Error: " + name + " not found"); - System.err.println("Hash: " - + Long.toHexString(name8.getLongHash(name))); - I.Error("W_GetNumForName: %s not found!", name); + I.Error("W_GetNumForName: %s not found! hash: %s", name, Long.toHexString(name8.getLongHash(name))); } return i; @@ -674,8 +672,7 @@ public final void ReadLump(int lump, byte[] buf, int offset) { // FIXME: reloadable files can only be that. Files. handle = InputStreamSugar.createInputStreamFromURI(this.reloadname, null, 0); } catch (Exception e) { - e.printStackTrace(); - I.Error("W_ReadLump: couldn't open %s", reloadname); + I.Error("W_ReadLump: couldn't open %s, due to: %s", reloadname, e.getMessage()); } } else { handle = l.handle; @@ -697,8 +694,8 @@ public final void ReadLump(int lump, byte[] buf, int offset) { // Well, that's a no-brainer. //l.wadfile.knownpos=l.position+c; if (c < l.size) { - System.err.printf("W_ReadLump: only read %d of %d on lump %d %d\n", c, l.size, - lump, l.position); + LOGGER.log(Level.SEVERE, String.format("W_ReadLump: only read %d of %d on lump %d %d", c, l.size, + lump, l.position)); } if (l.handle == null) { @@ -711,9 +708,7 @@ public final void ReadLump(int lump, byte[] buf, int offset) { // ??? I_EndRead (); } catch (Exception e) { - e.printStackTrace(); - I.Error("W_ReadLump: could not read lump " + lump); - e.printStackTrace(); + I.Error("W_ReadLump: could not read lump %d, due to: %s", lump, e.getMessage()); } } @@ -773,9 +768,8 @@ public T CacheLumpNum(int lump, int tag, Class what) { Track((CacheableDoomObject) thebuffer, lump); } } catch (Exception e) { - System.err.println("Could not auto-instantiate lump " - + lump + " of class " + what); - e.printStackTrace(); + LOGGER.log(Level.SEVERE, + String.format("Could not auto-instantiate lump %d of class %s", lump, String.valueOf(what)), e); } } else { @@ -850,9 +844,8 @@ public void CacheLumpNumIntoArray(int lump, int tag, Object[] array, } // lumpcache[lump]=array; } catch (Exception e) { - System.err.println("Could not auto-unpack lump " + lump - + " into an array of objects of class " + what); - e.printStackTrace(); + LOGGER.log(Level.SEVERE, String.format("Could not auto-unpack lump %d into an array of objects of class %s", + lump, String.valueOf(what)), e); } } @@ -902,7 +895,7 @@ public T[] CacheLumpNumIntoArray(int lump, int n thebuffer.rewind(); lumpcache[lump].unpack(thebuffer); } catch (IOException e) { - Loggers.getLogger(WadLoader.class.getName()).log(Level.WARNING, String.format( + LOGGER.log(Level.WARNING, String.format( "Could not auto-unpack lump %s into an array of objects of class %s", lump, what ), e); } @@ -1171,7 +1164,7 @@ public lumpinfo_t GetLumpInfo(int i) { @Override public void CloseAllHandles() { - ArrayList d = new ArrayList<>(); + List d = new ArrayList<>(); for (int i = 0; i < this.lumpinfo.length; i++) { if (!d.contains(lumpinfo[i].handle)) { @@ -1179,7 +1172,7 @@ public void CloseAllHandles() { } } - int count = 0; + int count = 1; for (InputStream e : d) { try { @@ -1187,8 +1180,7 @@ public void CloseAllHandles() { //System.err.printf("%s file handle closed",e.toString()); count++; } catch (IOException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); + LOGGER.log(Level.SEVERE, String.format("Could not close file handle (%d/%d)", count, d.size()), e1); } }