Changeset 67:108d123238c0
- Timestamp:
- 07/03/08 07:40:31
(6 months ago)
- Author:
- Diggory Hardy <diggory.hardy@gmail.com>
- branch:
- default
- Message:
Changes to work with tango r3700 (post 0.99.6).
Changes to logging.
Replaced many uses of PathView? with FilePath?.
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r64 |
r67 |
|
| 68 | 68 | FT_Int maj, min, patch; |
|---|
| 69 | 69 | FT_Library_Version (library, &maj, &min, &patch); |
|---|
| 70 | | if (maj != 2 || min != 3) { |
|---|
| 71 | | char[128] tmp; |
|---|
| 72 | | logger.warn (logger.format (tmp, "Using an untested FreeType version: {}.{}.{}", maj, min, patch)); |
|---|
| 73 | | } |
|---|
| | 70 | if (maj != 2 || min != 3) |
|---|
| | 71 | logger.warn ("Using an untested FreeType version: {}.{}.{}", maj, min, patch); |
|---|
| 74 | 72 | |
|---|
| 75 | 73 | // Set LCD filtering method if LCD rendering is enabled. |
|---|
| r63 |
r67 |
|
| 43 | 43 | GLenum err = glGetError(); |
|---|
| 44 | 44 | while (err != GL_NO_ERROR) { |
|---|
| 45 | | char[128] tmp; |
|---|
| 46 | | logger.error (logger.format (tmp, "GL error: {}", err)); |
|---|
| | 45 | logger.error ("GL error: {}", err); |
|---|
| 47 | 46 | err = glGetError(); |
|---|
| 48 | 47 | } |
|---|
| r63 |
r67 |
|
| 169 | 169 | |
|---|
| 170 | 170 | debug (MDE_CONFIG_DUMP) { |
|---|
| 171 | | char tmp[128] = void; |
|---|
| 172 | | logger.trace (logger.format (tmp, "Loaded {} config sections.", configs.length)); |
|---|
| | 171 | logger.trace ("Loaded {} config sections.", configs.length); |
|---|
| 173 | 172 | foreach (id, cfg; configs) { |
|---|
| 174 | 173 | logger.trace ("Section " ~ id ~ |
|---|
| r31 |
r67 |
|
| 38 | 38 | void openJoysticks () { |
|---|
| 39 | 39 | joysticks = new SDL_Joystick*[SDL_NumJoysticks ()]; |
|---|
| 40 | | char tmp[128] = void; |
|---|
| 41 | 40 | |
|---|
| 42 | 41 | for (int i = 0; i < joysticks.length; ++i) { |
|---|
| 43 | 42 | if ((joysticks[i] = SDL_JoystickOpen (i)) is null) { // null on failure |
|---|
| 44 | | logger.error (logger.format (tmp, "Unable to open joystick {} via SDL", i)); |
|---|
| | 43 | logger.error ("Unable to open joystick {} via SDL", i); |
|---|
| 45 | 44 | } |
|---|
| 46 | 45 | } |
|---|
| 47 | 46 | |
|---|
| 48 | | logger.info (logger.format (tmp, "Opened {} joysticks via SDL, succesfully unless preceding errors say otherwise.", joysticks.length)); |
|---|
| | 47 | logger.info ("Opened {} joysticks via SDL, succesfully unless preceding errors say otherwise.", joysticks.length); |
|---|
| 49 | 48 | } |
|---|
| 50 | 49 | |
|---|
| r64 |
r67 |
|
| 136 | 136 | */ |
|---|
| 137 | 137 | private const fileName = "options"; |
|---|
| 138 | | private const MT_LOAD_EXC = "Loading options aborted:"; |
|---|
| 139 | 138 | void load () { |
|---|
| 140 | 139 | // Check it exists (if not it should still be created on exit). |
|---|
| … | … | |
| 153 | 152 | reader.read; |
|---|
| 154 | 153 | } catch (MTException e) { |
|---|
| 155 | | logger.fatal (MT_LOAD_EXC); |
|---|
| | 154 | logger.fatal ("Loading options aborted:"); |
|---|
| 156 | 155 | logger.fatal (e.msg); |
|---|
| 157 | 156 | throw new optionsLoadException ("Mergetag exception (see above message)"); |
|---|
| … | … | |
| 177 | 176 | } catch (MTException e) { |
|---|
| 178 | 177 | // Log a message and continue, overwriting the file: |
|---|
| 179 | | logger.error (MT_LOAD_EXC); |
|---|
| | 178 | logger.error ("Loading options aborted:"); |
|---|
| 180 | 179 | logger.error (e.msg); |
|---|
| 181 | 180 | } |
|---|
| r47 |
r67 |
|
| 29 | 29 | |
|---|
| 30 | 30 | // tango imports |
|---|
| | 31 | import tango.io.FilePath; |
|---|
| 31 | 32 | import tango.io.UnicodeFile; |
|---|
| 32 | 33 | import Util = tango.text.Util; |
|---|
| 33 | 34 | import ConvInt = tango.text.convert.Integer; |
|---|
| 34 | | import tango.util.collection.model.View : View; |
|---|
| | 35 | //import tango.util.collection.model.View : View; |
|---|
| 35 | 36 | import tango.util.collection.HashSet : HashSet; |
|---|
| 36 | 37 | import tango.util.log.Log : Log, Logger; |
|---|
| … | … | |
| 54 | 55 | * |
|---|
| 55 | 56 | */ |
|---|
| 56 | | IReader makeReader (PathView path, DataSet ds = null, bool rdHeader = false) { |
|---|
| | 57 | IReader makeReader (FilePath path, DataSet ds = null, bool rdHeader = false) { |
|---|
| 57 | 58 | if (path.ext == "mtb") return new MTBReader (path, ds, rdHeader); |
|---|
| 58 | 59 | else if (path.ext == "mtt") return new MTTReader (path, ds, rdHeader); |
|---|
| … | … | |
| 64 | 65 | * Tries adding both ".mtt" and ".mtb" extensions, returning whichever exists (the most recently |
|---|
| 65 | 66 | * modified if both exist), or returns null if neither exist. */ |
|---|
| 66 | | PathView findFile (char[] path) { |
|---|
| | 67 | FilePath findFile (char[] path) { |
|---|
| 67 | 68 | if (path is null) return null; |
|---|
| 68 | 69 | |
|---|
| … | … | |
| 214 | 215 | } |
|---|
| 215 | 216 | /** ditto */ |
|---|
| 216 | | public this (PathView path, DataSet ds = null, bool rdHeader = false) { |
|---|
| | 217 | public this (FilePath path, DataSet ds = null, bool rdHeader = false) { |
|---|
| 217 | 218 | // Create a dataset or use an existing one |
|---|
| 218 | 219 | if (ds !is null) _dataset = ds; |
|---|
| r26 |
r67 |
|
| 91 | 91 | * MTFileFormatException if unable to determine writing format or use requested format. |
|---|
| 92 | 92 | */ |
|---|
| 93 | | IWriter makeWriter (char[] path, DataSet dataset = null, WriterMethod method = WriterMethod.FromExtension) { |
|---|
| | 93 | //FIXME: separate functions for separate functionality, like in Reader? |
|---|
| | 94 | IWriter makeWriter (char[] path, DataSet dataset = null, |
|---|
| | 95 | WriterMethod method = WriterMethod.FromExtension) { |
|---|
| 94 | 96 | if (method == WriterMethod.FromExtension) { |
|---|
| 95 | | PathView fpath = new FilePath (path); |
|---|
| 96 | | |
|---|
| 97 | | if (fpath.ext == "mtt") return new MTTWriter (fpath, dataset); |
|---|
| 98 | | else if (fpath.ext == "mtb") return new MTBWriter (fpath, dataset); |
|---|
| | 97 | if (path.length > 4 && path[$-4..$] == ".mtt") |
|---|
| | 98 | return new MTTWriter (path, dataset); |
|---|
| | 99 | else if (path.length > 4 && path[$-4..$] == ".mtb") |
|---|
| | 100 | return new MTBWriter (path, dataset); |
|---|
| 99 | 101 | else { |
|---|
| 100 | 102 | logger.error ("Unable to determine writing format: text or binary"); |
|---|
| … | … | |
| 144 | 146 | DataSet _dataset; |
|---|
| 145 | 147 | |
|---|
| 146 | | PathView _path; |
|---|
| | 148 | char[] _path; |
|---|
| 147 | 149 | //END DATA |
|---|
| 148 | 150 | |
|---|
| … | … | |
| 153 | 155 | * |
|---|
| 154 | 156 | * Params: |
|---|
| 155 | | * path = The name or FilePath of the file to open. |
|---|
| | 157 | * path = The name of the file to open. |
|---|
| 156 | 158 | * Standard extensions are .mtt and .mtb for text and binary files respectively. |
|---|
| 157 | 159 | * dataset_ = If null create a new DataSet, else use existing DataSet *dataset_ and merge read |
|---|
| … | … | |
| 159 | 161 | */ |
|---|
| 160 | 162 | public this (char[] path, DataSet ds = null) { |
|---|
| 161 | | this (new FilePath (path), ds); |
|---|
| 162 | | } |
|---|
| 163 | | /** ditto */ |
|---|
| 164 | | public this (PathView path, DataSet ds = null) { |
|---|
| 165 | 163 | _path = path; |
|---|
| 166 | 164 | _dataset = ds; |
|---|
| … | … | |
| 236 | 234 | class MTBWriter : IWriter { |
|---|
| 237 | 235 | public this (char[] path, DataSet ds = null) { |
|---|
| 238 | | this (new FilePath (path), ds); |
|---|
| 239 | | } |
|---|
| 240 | | public this (PathView path, DataSet ds = null) { |
|---|
| 241 | 236 | throw new MTNotImplementedException; |
|---|
| 242 | 237 | |
|---|
| r64 |
r67 |
|
| 38 | 38 | import TimeStamp = tango.text.convert.TimeStamp, tango.time.WallClock; // output date in log file |
|---|
| 39 | 39 | import tango.util.Arguments; |
|---|
| 40 | | import tango.util.log.Log : Log, Logger; |
|---|
| 41 | | import tango.util.log.ConsoleAppender : ConsoleAppender; |
|---|
| 42 | | |
|---|
| 43 | | //version = SwitchAppender; |
|---|
| 44 | | version (SwitchAppender) { // My own variation, currently just a test |
|---|
| 45 | | import tango.util.log.SwitchingFileAppender : SwitchingFileAppender; |
|---|
| 46 | | } else { |
|---|
| 47 | | import tango.util.log.RollingFileAppender : RollingFileAppender; |
|---|
| 48 | | } |
|---|
| | 40 | import tango.util.log.Log : Log, Logger, Level; |
|---|
| | 41 | import tango.util.log.AppendConsole; |
|---|
| | 42 | import tango.util.log.AppendFiles; |
|---|
| 49 | 43 | |
|---|
| 50 | 44 | // Derelict imports |
|---|
| … | … | |
| 63 | 57 | static this() |
|---|
| 64 | 58 | { |
|---|
| 65 | | Logger root = Log.getRootLogger(); |
|---|
| | 59 | Logger root = Log.root; |
|---|
| 66 | 60 | // Set the level here, but set it again once options have been loaded: |
|---|
| 67 | | debug root.setLevel(root.Level.Trace); |
|---|
| 68 | | else root.setLevel(root.Level.Info); |
|---|
| | 61 | debug root.level(Logger.Trace); |
|---|
| | 62 | else root.level(Logger.Info); |
|---|
| 69 | 63 | // Temporarily log to the console (until we've found paths and loaded options): |
|---|
| 70 | | root.addAppender(new ConsoleAppender); |
|---|
| | 64 | root.add(new AppendConsole); |
|---|
| 71 | 65 | } |
|---|
| 72 | 66 | static ~this() |
|---|
| … | … | |
| 168 | 162 | |
|---|
| 169 | 163 | // Where logging is done to is determined at compile-time, currently just via static ifs. |
|---|
| 170 | | root = Log.getRootLogger(); |
|---|
| 171 | | root.clearAppenders; // we may no longer want to log to the console |
|---|
| | 164 | root = Log.root; |
|---|
| | 165 | root.clear; // we may no longer want to log to the console |
|---|
| 172 | 166 | |
|---|
| 173 | 167 | // Now re-set the logging level, using the value from the config file: |
|---|
| 174 | | root.setLevel (cast(Log.Level) (miscOpts.logOptions & LOG.LEVEL), true); |
|---|
| | 168 | root.level (cast(Level) (miscOpts.logOptions & LOG.LEVEL), true); |
|---|
| 175 | 169 | |
|---|
| 176 | 170 | // Log to a file (first appender so root seperator messages don't show on console): |
|---|
| 177 | 171 | if (miscOpts.logOptions & LOG.ROLLFILE) { |
|---|
| 178 | | version (SwitchAppender) { |
|---|
| 179 | | root.addAppender (new SwitchingFileAppender (paths.logDir~"/log-.txt", 5)); |
|---|
| 180 | | } else { |
|---|
| 181 | 172 | // Use 2 log files with a maximum size of 1 MB: |
|---|
| 182 | | root.addAppender (new RollingFileAppender (paths.logDir~"/log-.txt", 2, 1024*1024)); |
|---|
| 183 | | root.info (""); // some kind of separation between runs |
|---|
| 184 | | root.info (""); |
|---|
| 185 | | } |
|---|
| | 173 | root.add (new AppendFiles (paths.logDir~"/log-.txt", 2, 1024*1024)); |
|---|
| | 174 | root.info (""); // some kind of separation between runs |
|---|
| | 175 | root.info (""); |
|---|
| 186 | 176 | } else if (!(miscOpts.logOptions & LOG.CONSOLE)) { |
|---|
| 187 | 177 | // make sure at least one logger is enabled |
|---|
| … | … | |
| 189 | 179 | } |
|---|
| 190 | 180 | if (miscOpts.logOptions & LOG.CONSOLE) { // Log to the console |
|---|
| 191 | | root.addAppender(new ConsoleAppender); |
|---|
| | 181 | root.add(new AppendConsole); |
|---|
| 192 | 182 | } |
|---|
| 193 | 183 | logger.info ("Starting mde [no version] on " ~ TimeStamp.toString(WallClock.now)); |
|---|
| … | … | |
| 195 | 185 | // Presumably it was only adding a file appender which failed; set up a new console |
|---|
| 196 | 186 | // logger and if that fails let the exception kill the program. |
|---|
| 197 | | root.clearAppenders; |
|---|
| 198 | | root.addAppender (new ConsoleAppender); |
|---|
| | 187 | root.clear; |
|---|
| | 188 | root.add (new AppendConsole); |
|---|
| 199 | 189 | logger.warn ("Exception while setting up the logger; logging to the console instead."); |
|---|
| 200 | 190 | } |
|---|
| r63 |
r67 |
|
| 27 | 27 | */ |
|---|
| 28 | 28 | /* Implementation note: |
|---|
| 29 | | * All paths are stored internally as strings, rather than as an instance of FilePath/PathView once |
|---|
| | 29 | * All paths are stored internally as strings, rather than as an instance of FilePath/FilePath once |
|---|
| 30 | 30 | * the FilePath has served its immediate purpose, since it's more convenient and creating new |
|---|
| 31 | 31 | * FilePaths for adjusted paths should be no slower than mutating existing ones. */ |
|---|
| … | … | |
| 72 | 72 | IReader makeMTReader (char[] file, PRIORITY readOrder, DataSet ds = null, bool rdHeader = false) |
|---|
| 73 | 73 | { |
|---|
| 74 | | PathView[] files = getFiles (file, readOrder); |
|---|
| | 74 | FilePath[] files = getFiles (file, readOrder); |
|---|
| 75 | 75 | if (files is null) |
|---|
| 76 | 76 | throw new MTFileIOException ("Unable to find the file: "~file~"[.mtt|mtb]"); |
|---|
| … | … | |
| 96 | 96 | char[] getFileName (char[] file, PRIORITY readOrder) |
|---|
| 97 | 97 | { |
|---|
| 98 | | PathView[] files = getFiles (file, readOrder); |
|---|
| | 98 | FilePath[] files = getFiles (file, readOrder); |
|---|
| 99 | 99 | if (files is null) |
|---|
| 100 | 100 | return "no file found"; |
|---|
| … | … | |
| 125 | 125 | |
|---|
| 126 | 126 | private: |
|---|
| 127 | | PathView[] getFiles (char[] filename, PRIORITY readOrder) |
|---|
| | 127 | FilePath[] getFiles (char[] filename, PRIORITY readOrder) |
|---|
| 128 | 128 | in { |
|---|
| 129 | 129 | assert (readOrder == PRIORITY.LOW_HIGH || |
|---|
| … | … | |
| 131 | 131 | readOrder == PRIORITY.HIGH_ONLY ); |
|---|
| 132 | 132 | } body { |
|---|
| 133 | | PathView[] ret; |
|---|
| | 133 | FilePath[] ret; |
|---|
| 134 | 134 | if (readOrder == PRIORITY.LOW_HIGH) { |
|---|
| 135 | 135 | for (size_t i = 0; i < pathsLen; ++i) { |
|---|
| 136 | | PathView file = findFile (paths[i]~filename); |
|---|
| | 136 | FilePath file = findFile (paths[i]~filename); |
|---|
| 137 | 137 | if (file !is null) |
|---|
| 138 | 138 | ret ~= file; |
|---|
| … | … | |
| 140 | 140 | } else { |
|---|
| 141 | 141 | for (int i = pathsLen - 1; i >= 0; --i) { |
|---|
| 142 | | PathView file = findFile (paths[i]~filename); |
|---|
| | 142 | FilePath file = findFile (paths[i]~filename); |
|---|
| 143 | 143 | if (file !is null) { |
|---|
| 144 | 144 | ret ~= file; |
|---|
| … | … | |
| 209 | 209 | // Base paths: |
|---|
| 210 | 210 | // Static data (must exist): |
|---|
| 211 | | PathView staticPath = |
|---|
| | 211 | FilePath staticPath = |
|---|
| 212 | 212 | findPath (false, "/usr/share/games/mde", "/usr/local/share/games/mde", "data"); |
|---|
| 213 | 213 | // Config (can just use defaults if necessary, so long as we can save afterwards): |
|---|
| 214 | | PathView userPath = findPath (true, HOME~"/.config/mde", HOME~"/.mde"); |
|---|
| | 214 | FilePath userPath = findPath (true, HOME~"/.config/mde", HOME~"/.mde"); |
|---|
| 215 | 215 | |
|---|
| 216 | 216 | // Static data paths: |
|---|
| … | … | |
| 237 | 237 | |
|---|
| 238 | 238 | // Base paths: |
|---|
| 239 | | PathView installPath = findPath (false, base); |
|---|
| 240 | | PathView staticPath = findPath (false, installPath.append("data").toString); |
|---|
| 241 | | PathView userPath = findPath (true, installPath.append("user").toString); // FIXME: see above |
|---|
| | 239 | FilePath installPath = findPath (false, base); |
|---|
| | 240 | FilePath staticPath = findPath (false, installPath.append("data").toString); |
|---|
| | 241 | FilePath userPath = findPath (true, installPath.append("user").toString); // FIXME: see above |
|---|
| 242 | 242 | |
|---|
| 243 | 243 | // Static data paths: |
|---|
| … | … | |
| 278 | 278 | * If none are valid and create is true, will try creating each in turn. |
|---|
| 279 | 279 | * If still none are valid, throws. */ |
|---|
| 280 | | PathView findPath (bool create, char[][] paths ...) { |
|---|
| | 280 | FilePath findPath (bool create, char[][] paths ...) { |
|---|
| 281 | 281 | FilePath[] fps; |
|---|
| 282 | 282 | fps.length = paths.length; |
|---|
| … | … | |
| 306 | 306 | class mdeReader : IReader |
|---|
| 307 | 307 | { |
|---|
| 308 | | private this (PathView[] files, DataSet ds, bool rdHeader) |
|---|
| | 308 | private this (FilePath[] files, DataSet ds, bool rdHeader) |
|---|
| 309 | 309 | in { |
|---|
| 310 | 310 | assert (files !is null, "mdeReader.this: files is null"); |
|---|
| r64 |
r67 |
|
| 94 | 94 | // Print a load of info: |
|---|
| 95 | 95 | logger.info ("Available video modes:"); |
|---|
| 96 | | char[128] tmp; |
|---|
| 97 | 96 | SDL_Rect** modes = SDL_ListModes (null, SDL_FULLSCREEN); |
|---|
| 98 | 97 | if (modes is null) logger.info ("None!"); |
|---|
| … | … | |
| 100 | 99 | else { |
|---|
| 101 | 100 | for (uint i = 0; modes[i] !is null; ++i) { |
|---|
| 102 | | logger.info (logger.format (tmp, "\t{}x{}", modes[i].w, modes[i].h)); |
|---|
| | 101 | logger.info ("\t{}x{}", modes[i].w, modes[i].h); |
|---|
| 103 | 102 | } |
|---|
| 104 | 103 | } |
|---|
| … | … | |
| 108 | 107 | logger.info ("Video info:"); |
|---|
| 109 | 108 | logger.info ("Hardware surface support: "~ (vi.flags & SDL_HWSURFACE ? "yes" : "no")); |
|---|
| 110 | | logger.info (logger.format (tmp, "Video memory: {}", vi.video_mem)); |
|---|
| | 109 | logger.info ("Video memory: {}", vi.video_mem); |
|---|
| 111 | 110 | |
|---|
| 112 | 111 | if (vi.vfmt !is null) { |
|---|
| 113 | 112 | logger.info ("Best video mode:"); |
|---|
| 114 | | logger.info (logger.format (tmp, "Bits per pixel: {}", vi.vfmt.BitsPerPixel)); |
|---|
| | 113 | logger.info ("Bits per pixel: {}", vi.vfmt.BitsPerPixel); |
|---|
| 115 | 114 | } |
|---|
| 116 | 115 | } |
|---|
| r47 |
r67 |
|
| 30 | 30 | |
|---|
| 31 | 31 | // Logger, used by mergetag: |
|---|
| 32 | | import tango.util.log.Log : Log, Logger; |
|---|
| 33 | | import tango.util.log.ConsoleAppender : ConsoleAppender; |
|---|
| 34 | | static this() { |
|---|
| 35 | | Logger root = Log.getRootLogger(); |
|---|
| 36 | | root.addAppender(new ConsoleAppender); |
|---|
| 37 | | } |
|---|
| | 32 | import tango.util.log.Config; |
|---|
| 38 | 33 | |
|---|
| 39 | 34 | int main (char[][] args) |
|---|