changeset 67:108d123238c0

Changes to work with tango r3700 (post 0.99.6). Changes to logging. Replaced many uses of PathView with FilePath.
author Diggory Hardy <diggory.hardy@gmail.com>
date Thu, 03 Jul 2008 12:40:31 +0100
parents 891211f034f2
children 3a737e06dc50
files mde/font/font.d mde/gl/draw.d mde/input/Config.d mde/input/joystick.d mde/lookup/Options.d mde/mergetag/Reader.d mde/mergetag/Writer.d mde/setup/Init.d mde/setup/paths.d mde/setup/sdl.d util/mtcp.d
diffstat 11 files changed, 56 insertions(+), 82 deletions(-) [+]
line wrap: on
line diff
--- a/mde/font/font.d	Sun Jun 29 15:40:37 2008 +0100
+++ b/mde/font/font.d	Thu Jul 03 12:40:31 2008 +0100
@@ -67,10 +67,8 @@
             // Check version
             FT_Int maj, min, patch;
             FT_Library_Version (library, &maj, &min, &patch);
-            if (maj != 2 || min != 3) {
-                char[128] tmp;
-                logger.warn (logger.format (tmp, "Using an untested FreeType version: {}.{}.{}", maj, min, patch));
-            }
+            if (maj != 2 || min != 3)
+                logger.warn ("Using an untested FreeType version: {}.{}.{}", maj, min, patch);
             
             // Set LCD filtering method if LCD rendering is enabled.
             const RMF = FT_LOAD_TARGET_LCD | FT_LOAD_TARGET_LCD_V;
--- a/mde/gl/draw.d	Sun Jun 29 15:40:37 2008 +0100
+++ b/mde/gl/draw.d	Thu Jul 03 12:40:31 2008 +0100
@@ -42,8 +42,7 @@
     
     GLenum err = glGetError();
     while (err != GL_NO_ERROR) {
-        char[128] tmp;
-        logger.error (logger.format (tmp, "GL error: {}", err));
+        logger.error ("GL error: {}", err);
         err = glGetError();
     }
     
--- a/mde/input/Config.d	Sun Jun 29 15:40:37 2008 +0100
+++ b/mde/input/Config.d	Thu Jul 03 12:40:31 2008 +0100
@@ -168,8 +168,7 @@
         }
         
         debug (MDE_CONFIG_DUMP) {
-            char tmp[128] = void;
-            logger.trace (logger.format (tmp, "Loaded {} config sections.", configs.length));
+            logger.trace ("Loaded {} config sections.", configs.length);
             foreach (id, cfg; configs) {
                 logger.trace ("Section " ~ id ~
                 ":\n\tbutton:\t\t" ~ parseFrom!(uint[][][uint])(cfg.button) ~
--- a/mde/input/joystick.d	Sun Jun 29 15:40:37 2008 +0100
+++ b/mde/input/joystick.d	Thu Jul 03 12:40:31 2008 +0100
@@ -37,15 +37,14 @@
 */
 void openJoysticks () {
     joysticks = new SDL_Joystick*[SDL_NumJoysticks ()];
-    char tmp[128] = void;
     
     for (int i = 0; i < joysticks.length; ++i) {
         if ((joysticks[i] = SDL_JoystickOpen (i)) is null) {	// null on failure
-            logger.error (logger.format (tmp, "Unable to open joystick {} via SDL", i));
+            logger.error ("Unable to open joystick {} via SDL", i);
         }
     }
     
-    logger.info (logger.format (tmp, "Opened {} joysticks via SDL, succesfully unless preceding errors say otherwise.", joysticks.length));
+    logger.info ("Opened {} joysticks via SDL, succesfully unless preceding errors say otherwise.", joysticks.length);
 }
 
 /// Cleanup fct.
--- a/mde/lookup/Options.d	Sun Jun 29 15:40:37 2008 +0100
+++ b/mde/lookup/Options.d	Thu Jul 03 12:40:31 2008 +0100
@@ -135,7 +135,6 @@
          * If the file doesn't exist, no reading is attempted (options are left at default values).
     	*/
         private const fileName = "options";
-        private const MT_LOAD_EXC = "Loading options aborted:";
         void load () {
         // Check it exists (if not it should still be created on exit).
         // Don't bother checking it's not a folder, because it could still be a block or something.
@@ -152,7 +151,7 @@
                 };
                 reader.read;
             } catch (MTException e) {
-                logger.fatal (MT_LOAD_EXC);
+                logger.fatal ("Loading options aborted:");
                 logger.fatal (e.msg);
                 throw new optionsLoadException ("Mergetag exception (see above message)");
             }
@@ -176,7 +175,7 @@
             	// Presuming the former, this is not a problem.
             } catch (MTException e) {
             	// Log a message and continue, overwriting the file:
-                logger.error (MT_LOAD_EXC);
+                logger.error ("Loading options aborted:");
                 logger.error (e.msg);
             }
         
--- a/mde/mergetag/Reader.d	Sun Jun 29 15:40:37 2008 +0100
+++ b/mde/mergetag/Reader.d	Thu Jul 03 12:40:31 2008 +0100
@@ -28,10 +28,11 @@
 import tango.core.Exception;
 
 // tango imports
+import tango.io.FilePath;
 import tango.io.UnicodeFile;
 import Util = tango.text.Util;
 import ConvInt = tango.text.convert.Integer;
-import tango.util.collection.model.View : View;
+//import tango.util.collection.model.View : View;
 import tango.util.collection.HashSet : HashSet;
 import tango.util.log.Log : Log, Logger;
 
@@ -53,7 +54,7 @@
 *  )
 *
 */
-IReader makeReader (PathView path, DataSet ds = null, bool rdHeader = false) {
+IReader makeReader (FilePath path, DataSet ds = null, bool rdHeader = false) {
     if      (path.ext == "mtb") return new MTBReader (path, ds, rdHeader);
     else if (path.ext == "mtt") return new MTTReader (path, ds, rdHeader);
     else throw new MTFileIOException ("Invalid mergetag extension");
@@ -63,7 +64,7 @@
  *
  * Tries adding both ".mtt" and ".mtb" extensions, returning whichever exists (the most recently
  * modified if both exist), or returns null if neither exist. */
-PathView findFile (char[] path) {
+FilePath findFile (char[] path) {
     if (path is null) return null;
     
     FilePath tPath = new FilePath (path ~ ".mtt");
@@ -213,7 +214,7 @@
         this (new FilePath (path), ds, rdHeader);
     }
     /** ditto */
-    public this (PathView path, DataSet ds = null, bool rdHeader = false) {
+    public this (FilePath path, DataSet ds = null, bool rdHeader = false) {
         // Create a dataset or use an existing one
         if (ds !is null) _dataset = ds;
         else _dataset = new DataSet();
--- a/mde/mergetag/Writer.d	Sun Jun 29 15:40:37 2008 +0100
+++ b/mde/mergetag/Writer.d	Thu Jul 03 12:40:31 2008 +0100
@@ -90,12 +90,14 @@
  * Throws:
  *  MTFileFormatException if unable to determine writing format or use requested format.
  */
-IWriter makeWriter (char[] path, DataSet dataset = null, WriterMethod method = WriterMethod.FromExtension) {
+//FIXME: separate functions for separate functionality, like in Reader?
+IWriter makeWriter (char[] path, DataSet dataset = null,
+                    WriterMethod method = WriterMethod.FromExtension) {
     if (method == WriterMethod.FromExtension) {
-        PathView fpath = new FilePath (path);
-        
-        if (fpath.ext == "mtt") return new MTTWriter (fpath, dataset);
-        else if (fpath.ext == "mtb") return new MTBWriter (fpath, dataset);
+        if (path.length > 4 && path[$-4..$] == ".mtt")
+            return new MTTWriter (path, dataset);
+        else if (path.length > 4 && path[$-4..$] == ".mtb")
+            return new MTBWriter (path, dataset);
         else {
             logger.error ("Unable to determine writing format: text or binary");
             throw new MTFileFormatException;
@@ -143,7 +145,7 @@
     /* The container where data is written from. */
     DataSet _dataset;
     
-    PathView _path;
+    char[] _path;
 //END DATA
     
 //BEGIN CTOR / DTOR
@@ -152,16 +154,12 @@
     * The call doesn't actually execute any code so cannot fail (unless out of memory).
     *
     * Params:
-    * path = The name or FilePath of the file to open.
+    * path = The name of the file to open.
     *     Standard extensions are .mtt and .mtb for text and binary files respectively.
     * dataset_ = If null create a new DataSet, else use existing DataSet *dataset_ and merge read
     *     data into it.
     */
     public this (char[] path, DataSet ds = null) {
-        this (new FilePath (path), ds);
-    }
-    /** ditto */
-    public this (PathView path, DataSet ds = null) {
         _path = path;
         _dataset = ds;
     }
@@ -235,9 +233,6 @@
 */
 class MTBWriter : IWriter {
     public this (char[] path, DataSet ds = null) {
-        this (new FilePath (path), ds);
-    }
-    public this (PathView path, DataSet ds = null) {
         throw new MTNotImplementedException;
         
         /+_path = path;
--- a/mde/setup/Init.d	Sun Jun 29 15:40:37 2008 +0100
+++ b/mde/setup/Init.d	Thu Jul 03 12:40:31 2008 +0100
@@ -37,15 +37,9 @@
 import tango.io.Console;	// for printing command-line usage
 import TimeStamp = tango.text.convert.TimeStamp, tango.time.WallClock;	// output date in log file
 import tango.util.Arguments;
-import tango.util.log.Log : Log, Logger;
-import tango.util.log.ConsoleAppender : ConsoleAppender;
-
-//version = SwitchAppender;
-version (SwitchAppender) {  // My own variation, currently just a test
-    import tango.util.log.SwitchingFileAppender : SwitchingFileAppender;
-} else {
-    import tango.util.log.RollingFileAppender : RollingFileAppender;
-}
+import tango.util.log.Log : Log, Logger, Level;
+import tango.util.log.AppendConsole;
+import tango.util.log.AppendFiles;
 
 // Derelict imports
 import derelict.opengl.gl;
@@ -62,12 +56,12 @@
  */
 static this()
 {
-    Logger root = Log.getRootLogger();
+    Logger root = Log.root;
     // Set the level here, but set it again once options have been loaded:
-    debug root.setLevel(root.Level.Trace);
-    else root.setLevel(root.Level.Info);
+    debug root.level(Logger.Trace);
+    else  root.level(Logger.Info);
     // Temporarily log to the console (until we've found paths and loaded options):
-    root.addAppender(new ConsoleAppender);
+    root.add(new AppendConsole);
 }
 static ~this()
 {
@@ -167,35 +161,31 @@
             }
             
 	    // Where logging is done to is determined at compile-time, currently just via static ifs.
-            root = Log.getRootLogger();
-	    root.clearAppenders;	// we may no longer want to log to the console
+            root = Log.root;
+	    root.clear;			// we may no longer want to log to the console
 	    
             // Now re-set the logging level, using the value from the config file:
-            root.setLevel (cast(Log.Level) (miscOpts.logOptions & LOG.LEVEL), true);
+            root.level (cast(Level) (miscOpts.logOptions & LOG.LEVEL), true);
             
             // Log to a file (first appender so root seperator messages don't show on console):
             if (miscOpts.logOptions & LOG.ROLLFILE) {
-                version (SwitchAppender) {
-                    root.addAppender (new SwitchingFileAppender (paths.logDir~"/log-.txt", 5));
-                } else {
                 // Use 2 log files with a maximum size of 1 MB:
-                    root.addAppender (new RollingFileAppender (paths.logDir~"/log-.txt", 2, 1024*1024));
-                    root.info (""); // some kind of separation between runs
-                    root.info ("");
-                }
+                root.add (new AppendFiles (paths.logDir~"/log-.txt", 2, 1024*1024));
+                root.info (""); // some kind of separation between runs
+                root.info ("");
             } else if (!(miscOpts.logOptions & LOG.CONSOLE)) {
                 // make sure at least one logger is enabled
                 miscOpts.set!(int) ("logOptions", miscOpts.logOptions | LOG.CONSOLE);
             }
             if (miscOpts.logOptions & LOG.CONSOLE) {	// Log to the console
-                root.addAppender(new ConsoleAppender);
+                root.add(new AppendConsole);
             }
             logger.info ("Starting mde [no version] on " ~ TimeStamp.toString(WallClock.now));
         } catch (Exception e) {
             // Presumably it was only adding a file appender which failed; set up a new console
             // logger and if that fails let the exception kill the program.
-            root.clearAppenders;
-            root.addAppender (new ConsoleAppender);
+            root.clear;
+            root.add (new AppendConsole);
             logger.warn ("Exception while setting up the logger; logging to the console instead.");
         }
         
--- a/mde/setup/paths.d	Sun Jun 29 15:40:37 2008 +0100
+++ b/mde/setup/paths.d	Thu Jul 03 12:40:31 2008 +0100
@@ -26,7 +26,7 @@
 * Currently the paths are found as follows: (see codeDoc/paths.txt)
 */
 /* Implementation note:
-* All paths are stored internally as strings, rather than as an instance of FilePath/PathView once
+* All paths are stored internally as strings, rather than as an instance of FilePath/FilePath once
 * the FilePath has served its immediate purpose, since it's more convenient and creating new
 * FilePaths for adjusted paths should be no slower than mutating existing ones. */
 module mde.setup.paths;
@@ -71,7 +71,7 @@
     */
     IReader makeMTReader (char[] file, PRIORITY readOrder, DataSet ds = null, bool rdHeader = false)
     {
-        PathView[] files = getFiles (file, readOrder);
+        FilePath[] files = getFiles (file, readOrder);
         if (files is null)
             throw new MTFileIOException ("Unable to find the file: "~file~"[.mtt|mtb]");
         
@@ -95,7 +95,7 @@
       * matches are found), or "no file found". Intended for user output only. */
     char[] getFileName (char[] file, PRIORITY readOrder)
     {
-        PathView[] files = getFiles (file, readOrder);
+        FilePath[] files = getFiles (file, readOrder);
         if (files is null)
             return "no file found";
         
@@ -124,22 +124,22 @@
     }
     
 private:
-    PathView[] getFiles (char[] filename, PRIORITY readOrder)
+    FilePath[] getFiles (char[] filename, PRIORITY readOrder)
     in {
         assert (readOrder == PRIORITY.LOW_HIGH ||
                 readOrder == PRIORITY.HIGH_LOW ||
                 readOrder == PRIORITY.HIGH_ONLY );
     } body {
-        PathView[] ret;
+        FilePath[] ret;
         if (readOrder == PRIORITY.LOW_HIGH) {
             for (size_t i = 0; i < pathsLen; ++i) {
-                PathView file = findFile (paths[i]~filename);
+                FilePath file = findFile (paths[i]~filename);
                 if (file !is null)
                     ret ~= file;
             }
         } else {
             for (int i = pathsLen - 1; i >= 0; --i) {
-                PathView file = findFile (paths[i]~filename);
+                FilePath file = findFile (paths[i]~filename);
                 if (file !is null) {
                     ret ~= file;
                     if (readOrder == PRIORITY.HIGH_ONLY) break;
@@ -208,10 +208,10 @@
         
         // Base paths:
         // Static data (must exist):
-        PathView staticPath =
+        FilePath staticPath =
                 findPath (false, "/usr/share/games/mde", "/usr/local/share/games/mde", "data");
         // Config (can just use defaults if necessary, so long as we can save afterwards):
-        PathView userPath = findPath (true, HOME~"/.config/mde", HOME~"/.mde");
+        FilePath userPath = findPath (true, HOME~"/.config/mde", HOME~"/.mde");
         
         // Static data paths:
         dataDir.addPath (staticPath.toString);      // we know this is valid anyway
@@ -236,9 +236,9 @@
         //http://www.dsource.org/projects/tango/forums/topic/187
         
         // Base paths:
-        PathView installPath = findPath (false, base);
-        PathView staticPath = findPath (false, installPath.append("data").toString);
-        PathView userPath = findPath (true, installPath.append("user").toString);   // FIXME: see above
+        FilePath installPath = findPath (false, base);
+        FilePath staticPath = findPath (false, installPath.append("data").toString);
+        FilePath userPath = findPath (true, installPath.append("user").toString);   // FIXME: see above
         
         // Static data paths:
         dataDir.addPath (staticPath.toString);   // we know this is valid anyway
@@ -277,7 +277,7 @@
     /* Try each path in succession, returning the first to exist and be a folder.
      * If none are valid and create is true, will try creating each in turn.
      * If still none are valid, throws. */
-    PathView findPath (bool create, char[][] paths ...) {
+    FilePath findPath (bool create, char[][] paths ...) {
         FilePath[] fps;
         fps.length = paths.length;
         foreach (i,path; paths) {
@@ -305,7 +305,7 @@
      */
     class mdeReader : IReader
     {
-        private this (PathView[] files, DataSet ds, bool rdHeader)
+        private this (FilePath[] files, DataSet ds, bool rdHeader)
         in {
             assert (files !is null, "mdeReader.this: files is null");
         } body {
--- a/mde/setup/sdl.d	Sun Jun 29 15:40:37 2008 +0100
+++ b/mde/setup/sdl.d	Thu Jul 03 12:40:31 2008 +0100
@@ -93,13 +93,12 @@
         
         // Print a load of info:
         logger.info ("Available video modes:");
-        char[128] tmp;
         SDL_Rect** modes = SDL_ListModes (null, SDL_FULLSCREEN);
         if (modes is null) logger.info ("None!");
         else if (modes is cast(SDL_Rect**) -1) logger.info ("All modes are available");
         else {
             for (uint i = 0; modes[i] !is null; ++i) {
-                logger.info (logger.format (tmp, "\t{}x{}", modes[i].w, modes[i].h));
+                logger.info ("\t{}x{}", modes[i].w, modes[i].h);
             }
         }
     
@@ -107,11 +106,11 @@
         if (vi !is null) {
             logger.info ("Video info:");
             logger.info ("Hardware surface support: "~ (vi.flags & SDL_HWSURFACE ? "yes" : "no"));
-            logger.info (logger.format (tmp, "Video memory: {}", vi.video_mem));
+            logger.info ("Video memory: {}", vi.video_mem);
     
             if (vi.vfmt !is null) {
                 logger.info ("Best video mode:");
-                logger.info (logger.format (tmp, "Bits per pixel: {}", vi.vfmt.BitsPerPixel));
+                logger.info ("Bits per pixel: {}", vi.vfmt.BitsPerPixel);
             }
         }
         
--- a/util/mtcp.d	Sun Jun 29 15:40:37 2008 +0100
+++ b/util/mtcp.d	Thu Jul 03 12:40:31 2008 +0100
@@ -29,12 +29,7 @@
 import tango.io.FilePath;
 
 // Logger, used by mergetag:
-import tango.util.log.Log : Log, Logger;
-import tango.util.log.ConsoleAppender : ConsoleAppender;
-static this() {
-    Logger root = Log.getRootLogger();
-    root.addAppender(new ConsoleAppender);
-}
+import tango.util.log.Config;
 
 int main (char[][] args)
 {