Sat, 16 Mar 2013 03:12:31 +0200
oops, forgot the new dialog files out
0 | 1 | #include <vector> |
2 | ||
3 | #include "common.h" | |
4 | #include "io.h" | |
5 | #include "ldtypes.h" | |
6 | #include "misc.h" | |
4
758302636564
improve opening, don't auto-load 55966.dat (:P)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
7 | #include "gui.h" |
758302636564
improve opening, don't auto-load 55966.dat (:P)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
8 | #include "bbox.h" |
0 | 9 | |
10 | // ============================================================================= | |
11 | // IO_FindLoadedFile (str) | |
12 | // | |
13 | // Returns a pointer to the first found open file with the given name. | |
14 | // ============================================================================= | |
15 | OpenFile* IO_FindLoadedFile (str name) { | |
16 | OpenFile* file; | |
17 | ||
18 | for (uint i = 0; i < g_LoadedFiles.size(); i++) { | |
19 | file = g_LoadedFiles[i]; | |
7
098e3c4949c6
Set window title dynamically based on filename
Santeri Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
20 | if (!file->zFileName.icompare (name)) |
0 | 21 | return file; |
22 | } | |
23 | ||
24 | return NULL; | |
25 | } | |
26 | ||
27 | // ============================================================================= | |
4
758302636564
improve opening, don't auto-load 55966.dat (:P)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
28 | // IO_OpenLDrawFile (str) |
0 | 29 | // |
30 | // Opens the given file and parses the LDraw code within. | |
31 | // ============================================================================= | |
4
758302636564
improve opening, don't auto-load 55966.dat (:P)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
32 | OpenFile* IO_OpenLDrawFile (str path) { |
13
3955ff2a7d72
Added logf function to write to message log. Write warnings of unparsable files into the message log.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
33 | logf ("Opening %s...\n", path.chars()); |
3955ff2a7d72
Added logf function to write to message log. Write warnings of unparsable files into the message log.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
34 | |
0 | 35 | FILE* fp = fopen (path.chars (), "r"); |
36 | ||
37 | if (!fp) { | |
13
3955ff2a7d72
Added logf function to write to message log. Write warnings of unparsable files into the message log.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
38 | logf (LOG_Error, "Couldn't open %s: %s\n", path.chars (), strerror (errno)); |
0 | 39 | return NULL; |
40 | } | |
41 | ||
42 | OpenFile* load = new OpenFile; | |
13
3955ff2a7d72
Added logf function to write to message log. Write warnings of unparsable files into the message log.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
43 | ulong numWarnings = 0; |
3955ff2a7d72
Added logf function to write to message log. Write warnings of unparsable files into the message log.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
44 | |
7
098e3c4949c6
Set window title dynamically based on filename
Santeri Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
45 | load->zFileName = path; |
0 | 46 | |
47 | vector<str> lines; | |
48 | ||
49 | { | |
50 | char line[1024]; | |
51 | while (fgets (line, sizeof line, fp)) { | |
52 | // Trim the trailing newline | |
53 | str zLine = line; | |
54 | while (zLine[~zLine - 1] == '\n' || zLine[~zLine - 1] == '\r') | |
55 | zLine -= 1; | |
56 | ||
57 | lines.push_back (zLine); | |
58 | } | |
59 | } | |
60 | ||
61 | fclose (fp); | |
62 | ||
13
3955ff2a7d72
Added logf function to write to message log. Write warnings of unparsable files into the message log.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
63 | for (ulong i = 0; i < lines.size(); ++i) { |
3955ff2a7d72
Added logf function to write to message log. Write warnings of unparsable files into the message log.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
64 | LDObject* obj = ParseLine (lines[i]); |
3955ff2a7d72
Added logf function to write to message log. Write warnings of unparsable files into the message log.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
65 | load->objects.push_back (obj); |
3955ff2a7d72
Added logf function to write to message log. Write warnings of unparsable files into the message log.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
66 | |
3955ff2a7d72
Added logf function to write to message log. Write warnings of unparsable files into the message log.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
67 | // Check for warnings |
3955ff2a7d72
Added logf function to write to message log. Write warnings of unparsable files into the message log.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
68 | if (obj->getType() == OBJ_Gibberish) { |
3955ff2a7d72
Added logf function to write to message log. Write warnings of unparsable files into the message log.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
69 | logf (LOG_Warning, "Couldn't parse line #%lu: %s\n", |
3955ff2a7d72
Added logf function to write to message log. Write warnings of unparsable files into the message log.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
70 | i, static_cast<LDGibberish*> (obj)->zReason.chars()); |
3955ff2a7d72
Added logf function to write to message log. Write warnings of unparsable files into the message log.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
71 | logf (LOG_Warning, "- Line was: %s\n", lines[i].chars()); |
3955ff2a7d72
Added logf function to write to message log. Write warnings of unparsable files into the message log.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
72 | numWarnings++; |
3955ff2a7d72
Added logf function to write to message log. Write warnings of unparsable files into the message log.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
73 | } |
3955ff2a7d72
Added logf function to write to message log. Write warnings of unparsable files into the message log.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
74 | } |
0 | 75 | |
76 | g_LoadedFiles.push_back (load); | |
4
758302636564
improve opening, don't auto-load 55966.dat (:P)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
77 | g_CurrentFile = g_LoadedFiles[g_LoadedFiles.size() - 1]; |
758302636564
improve opening, don't auto-load 55966.dat (:P)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
78 | |
758302636564
improve opening, don't auto-load 55966.dat (:P)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
79 | // Recalculate the bounding box |
758302636564
improve opening, don't auto-load 55966.dat (:P)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
80 | g_BBox.calculate(); |
758302636564
improve opening, don't auto-load 55966.dat (:P)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
81 | |
758302636564
improve opening, don't auto-load 55966.dat (:P)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
82 | // Rebuild the object tree view now. |
758302636564
improve opening, don't auto-load 55966.dat (:P)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
83 | g_qWindow->buildObjList (); |
7
098e3c4949c6
Set window title dynamically based on filename
Santeri Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
84 | g_qWindow->setTitle (); |
4
758302636564
improve opening, don't auto-load 55966.dat (:P)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
85 | |
14
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
13
diff
changeset
|
86 | logf (LOG_Success, "File %s parsed successfully (%lu warning%s).\n", |
6d9d8efae2f8
this thing got its own reinterpret_cast now. :P Added SetContents action for altering an object by contents and reinterpreting it.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
13
diff
changeset
|
87 | path.chars(), numWarnings, PLURAL (numWarnings)); |
13
3955ff2a7d72
Added logf function to write to message log. Write warnings of unparsable files into the message log.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
88 | |
4
758302636564
improve opening, don't auto-load 55966.dat (:P)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
89 | return g_CurrentFile; |
0 | 90 | } |
91 | ||
92 | // ============================================================================= | |
12
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
93 | // isNumber (char*) |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
94 | // |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
95 | // Returns whether a given string represents a floating point number |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
96 | // TODO: Does LDraw support scientific notation? |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
97 | // ============================================================================= |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
98 | static bool isNumber (char* sToken) { |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
99 | char* sPointer = &sToken[0]; |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
100 | bool bGotDot = false; |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
101 | |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
102 | // Allow leading hyphen for negatives |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
103 | if (*sPointer == '-') |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
104 | sPointer++; |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
105 | |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
106 | while (*sPointer != '\0') { |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
107 | if (*sPointer == '.' && !bGotDot) { |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
108 | // Decimal point |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
109 | bGotDot = true; |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
110 | sPointer++; |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
111 | continue; |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
112 | } |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
113 | |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
114 | if (*sPointer >= '0' && *sPointer <= '9') { |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
115 | sPointer++; |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
116 | continue; // Digit |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
117 | } |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
118 | |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
119 | // If the above cases didn't catch this character, it was |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
120 | // illegal and this is therefore not a number. |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
121 | return false; |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
122 | } |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
123 | |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
124 | return true; |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
125 | } |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
126 | |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
127 | // ============================================================================= |
0 | 128 | // ParseLine (str) |
129 | // | |
130 | // Parses a string line containing an LDraw object and returns the object parsed. | |
131 | // ============================================================================= | |
12
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
132 | #define CHECK_TOKEN_COUNT(N) \ |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
133 | if (tokens.size() != N) \ |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
134 | return new LDGibberish (zLine, "Bad amount of tokens"); |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
135 | |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
136 | #define CHECK_TOKEN_NUMBERS(MIN,MAX) \ |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
137 | for (ushort i = MIN; i <= MAX; ++i) \ |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
138 | if (!isNumber (tokens[i])) \ |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
139 | return new LDGibberish (zLine, str::mkfmt ("Token #%u was `%s`, expected a number", \ |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
140 | (i + 1), tokens[i].chars())); |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
141 | |
0 | 142 | LDObject* ParseLine (str zLine) { |
143 | str zNoWhitespace = zLine; | |
144 | StripWhitespace (zNoWhitespace); | |
145 | if (!~zNoWhitespace) { | |
146 | // Line was empty, or only consisted of whitespace | |
147 | return new LDEmpty; | |
148 | } | |
149 | ||
150 | char c = zLine[0]; | |
151 | vector<str> tokens = zLine / " "; | |
152 | ||
11
323390a03294
Color gibberish red. Check for line code length for gibberish (must be 1 to be valid)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
7
diff
changeset
|
153 | if (~tokens[0] != 1) |
323390a03294
Color gibberish red. Check for line code length for gibberish (must be 1 to be valid)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
7
diff
changeset
|
154 | return new LDGibberish (zLine, "Illogical line code"); |
323390a03294
Color gibberish red. Check for line code length for gibberish (must be 1 to be valid)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
7
diff
changeset
|
155 | |
0 | 156 | switch (c - '0') { |
157 | case 0: | |
158 | { | |
159 | // Comment | |
160 | LDComment* obj = new LDComment; | |
161 | obj->zText = zLine.substr (1, -1); | |
162 | return obj; | |
163 | } | |
164 | ||
165 | case 1: | |
166 | { | |
12
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
167 | CHECK_TOKEN_COUNT (15) |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
168 | CHECK_TOKEN_NUMBERS (1, 13) |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
169 | |
0 | 170 | // Subfile |
171 | LDSubfile* obj = new LDSubfile; | |
172 | obj->dColor = atoi (tokens[1]); | |
173 | obj->vPosition = ParseVertex (zLine, 2); // 2 - 4 | |
174 | ||
175 | for (short i = 0; i < 9; ++i) | |
176 | obj->faMatrix[i] = atof (tokens[i + 5]); // 5 - 13 | |
177 | ||
178 | obj->zFileName = tokens[14]; | |
179 | return obj; | |
180 | } | |
181 | ||
182 | case 2: | |
183 | { | |
12
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
184 | CHECK_TOKEN_COUNT (8) |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
185 | CHECK_TOKEN_NUMBERS (1, 7) |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
186 | |
0 | 187 | // Line |
188 | LDLine* obj = new LDLine; | |
189 | obj->dColor = GetWordInt (zLine, 1); | |
190 | for (short i = 0; i < 2; ++i) | |
191 | obj->vaCoords[i] = ParseVertex (zLine, 2 + (i * 3)); // 2 - 7 | |
192 | return obj; | |
193 | } | |
194 | ||
195 | case 3: | |
196 | { | |
12
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
197 | CHECK_TOKEN_COUNT (11) |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
198 | CHECK_TOKEN_NUMBERS (1, 10) |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
199 | |
0 | 200 | // Triangle |
201 | LDTriangle* obj = new LDTriangle; | |
202 | obj->dColor = GetWordInt (zLine, 1); | |
203 | ||
204 | for (short i = 0; i < 3; ++i) | |
205 | obj->vaCoords[i] = ParseVertex (zLine, 2 + (i * 3)); // 2 - 10 | |
206 | ||
207 | return obj; | |
208 | } | |
209 | ||
210 | case 4: | |
211 | { | |
12
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
212 | CHECK_TOKEN_COUNT (14) |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
213 | CHECK_TOKEN_NUMBERS (1, 13) |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
214 | |
0 | 215 | // Quadrilateral |
216 | LDQuad* obj = new LDQuad; | |
217 | obj->dColor = GetWordInt (zLine, 1); | |
218 | ||
219 | for (short i = 0; i < 4; ++i) | |
220 | obj->vaCoords[i] = ParseVertex (zLine, 2 + (i * 3)); // 2 - 13 | |
221 | ||
222 | return obj; | |
223 | } | |
224 | ||
225 | case 5: | |
226 | { | |
12
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
227 | CHECK_TOKEN_COUNT (14) |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
228 | CHECK_TOKEN_NUMBERS (1, 13) |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
229 | |
0 | 230 | // Conditional line |
231 | LDCondLine* obj = new LDCondLine; | |
232 | obj->dColor = GetWordInt (zLine, 1); | |
233 | ||
234 | for (short i = 0; i < 2; ++i) | |
235 | obj->vaCoords[i] = ParseVertex (zLine, 2 + (i * 3)); // 2 - 7 | |
236 | ||
237 | for (short i = 0; i < 2; ++i) | |
238 | obj->vaControl[i] = ParseVertex (zLine, 8 + (i * 3)); // 8 - 13 | |
239 | return obj; | |
240 | } | |
241 | ||
12
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
242 | default: // Strange line we couldn't parse |
8f6de46a27e2
Check whether the numeric arguments of lines really are numeric, and treat lines that don't pass this check as gibberish
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
243 | return new LDGibberish (zLine, "Unknown line code number"); |
0 | 244 | } |
245 | } |