1 /** 2 Data structures used commonly throughout. 3 4 Copyright: 5 Copyright © 2020-2026, Inochi2D Project 6 7 License: 8 $(LINK2 https://github.com/Inochi2D/inochi2d/blob/main/LICENSE, BSD 2-clause License) 9 10 Authors: 11 Luna Nielsen 12 */ 13 module inochi2d.common; 14 import nulib.collections; 15 import nulib.string; 16 17 /** 18 Magic value meaning that the model has no thumbnail 19 */ 20 enum NO_THUMBNAIL = uint.max; 21 22 /** 23 Creates an Inochi2D version number. 24 */ 25 enum uint IN_MAKE_VERSION(ushort major, ubyte minor, ubyte patch) = 26 (cast(uint)major << 16) | 27 (cast(uint)minor << 8) | 28 (cast(uint)patch); 29 30 /** 31 IO Sink Interface for errors, warnings, etc. 32 */ 33 struct IOSink { 34 @nogc: 35 36 /** 37 Error sink to write errors to. 38 */ 39 extern (C) void function(const(char)* msg, const(char)* file, uint line) @nogc nothrow error; 40 41 /** 42 Warning sink to write warnings to. 43 */ 44 extern (C) void function(const(char)* msg, const(char)* file, uint line) @nogc nothrow warning; 45 46 /** 47 Info sink to write informational messages to. 48 */ 49 extern (C) void function(const(char)* msg, const(char)* file, uint line) @nogc nothrow info; 50 } 51 52 /** 53 Model loading state information. 54 */ 55 struct ModelState { 56 @nogc: 57 58 /** 59 IO Sink 60 */ 61 IOSink io; 62 63 /** 64 Is the puppet a 0.8 legacy puppet? 65 */ 66 bool doUpgrade08; 67 68 /** 69 Simple model upgrade context data 70 */ 71 HashTable!(string, float) upctx; 72 73 /** 74 Inochi2D Specification version. 75 */ 76 uint version_; 77 78 /** 79 Writes an error to the error sink. 80 81 Params: 82 msg = The message. 83 file = The file the error occured in. 84 line = The line of the file the error occured in. 85 */ 86 pragma(inline, true) 87 void error(nstring msg, const(char)* file = __MODULE__.ptr, uint line = __LINE__) { 88 if (io.error) 89 io.error(msg.ptr, file, line); 90 } 91 92 /** 93 Writes an error to the error sink. 94 95 Params: 96 msg = The message. 97 file = The file the error occured in. 98 line = The line of the file the error occured in. 99 */ 100 pragma(inline, true) 101 void error(const(char)* msg, const(char)* file = __MODULE__.ptr, uint line = __LINE__) { 102 if (io.error) 103 io.error(msg, file, line); 104 } 105 106 /** 107 Writes an warning to the warning sink. 108 109 Params: 110 msg = The message. 111 file = The file the warning occured in. 112 line = The line of the file the warning occured in. 113 */ 114 pragma(inline, true) 115 void warning(nstring msg, const(char)* file = __MODULE__.ptr, uint line = __LINE__) { 116 if (io.warning) 117 io.warning(msg.ptr, file, line); 118 } 119 120 /** 121 Writes an warning to the warning sink. 122 123 Params: 124 msg = The message. 125 file = The file the warning occured in. 126 line = The line of the file the warning occured in. 127 */ 128 pragma(inline, true) 129 void warning(const(char)* msg, const(char)* file = __MODULE__.ptr, uint line = __LINE__) { 130 if (io.warning) 131 io.warning(msg, file, line); 132 } 133 134 /** 135 Writes info to the info sink. 136 137 Params: 138 msg = The message. 139 file = The file the message was emitted from. 140 line = The line the message was emitted from. 141 */ 142 pragma(inline, true) 143 void info(nstring msg, const(char)* file = __MODULE__.ptr, uint line = __LINE__) { 144 if (io.info) 145 io.info(msg.ptr, file, line); 146 } 147 148 /** 149 Writes info to the info sink. 150 151 Params: 152 msg = The message. 153 file = The file the message was emitted from. 154 line = The line the message was emitted from. 155 */ 156 pragma(inline, true) 157 void info(const(char)* msg, const(char)* file = __MODULE__.ptr, uint line = __LINE__) { 158 if (io.info) 159 io.info(msg, file, line); 160 } 161 }