Mon, 18 Mar 2013 12:15:23 +0200
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
0 | 1 | #include <vector> |
2 | ||
3 | #include "common.h" | |
4 | #include "io.h" | |
5 | #include "misc.h" | |
4
758302636564
improve opening, don't auto-load 55966.dat (:P)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
6 | #include "bbox.h" |
25
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
7 | #include "gui.h" |
0 | 8 | |
23
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
9 | vector<str> g_zaFileLoadPaths; |
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
10 | |
0 | 11 | // ============================================================================= |
25
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
12 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
0 | 13 | // ============================================================================= |
25
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
14 | OpenFile* findLoadedFile (str name) { |
23
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
15 | for (ulong i = 0; i < g_LoadedFiles.size(); i++) { |
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
16 | OpenFile* const file = g_LoadedFiles[i]; |
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
17 | if (file->zFileName == name) |
0 | 18 | return file; |
19 | } | |
20 | ||
23
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
21 | return nullptr; |
0 | 22 | } |
23 | ||
24 | // ============================================================================= | |
25
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
25 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
0 | 26 | // ============================================================================= |
25
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
27 | OpenFile* openDATFile (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
|
28 | 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
|
29 | |
0 | 30 | FILE* fp = fopen (path.chars (), "r"); |
31 | ||
32 | if (!fp) { | |
23
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
33 | for (ushort i = 0; i < g_zaFileLoadPaths.size(); ++i) { |
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
34 | str zFilePath = str::mkfmt ("%s/%s", g_zaFileLoadPaths[i].chars(), path.chars()); |
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
35 | fp = fopen (zFilePath.chars (), "r"); |
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
36 | |
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
37 | if (fp) |
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
38 | break; |
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
39 | } |
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
40 | } |
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
41 | |
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
42 | 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
|
43 | logf (LOG_Error, "Couldn't open %s: %s\n", path.chars (), strerror (errno)); |
23
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
44 | return nullptr; |
0 | 45 | } |
46 | ||
47 | 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
|
48 | 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
|
49 | |
7
098e3c4949c6
Set window title dynamically based on filename
Santeri Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
50 | load->zFileName = path; |
0 | 51 | |
52 | vector<str> lines; | |
53 | ||
54 | { | |
55 | char line[1024]; | |
56 | while (fgets (line, sizeof line, fp)) { | |
57 | // Trim the trailing newline | |
58 | str zLine = line; | |
59 | while (zLine[~zLine - 1] == '\n' || zLine[~zLine - 1] == '\r') | |
60 | zLine -= 1; | |
61 | ||
62 | lines.push_back (zLine); | |
63 | } | |
64 | } | |
65 | ||
66 | fclose (fp); | |
67 | ||
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
|
68 | for (ulong i = 0; i < lines.size(); ++i) { |
25
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
69 | LDObject* obj = parseLine (lines[i]); |
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
|
70 | 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
|
71 | |
25
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
72 | // Check for parse errors and warn abotu tthem |
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
|
73 | 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
|
74 | 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
|
75 | 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
|
76 | 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
|
77 | 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
|
78 | } |
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
|
79 | } |
0 | 80 | |
81 | 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
|
82 | |
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
|
83 | 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
|
84 | 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
|
85 | |
23
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
86 | return load; |
0 | 87 | } |
88 | ||
89 | // ============================================================================= | |
25
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
90 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
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
|
91 | // ============================================================================= |
25
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
92 | // Clear everything from the model |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
93 | void OpenFile::close () { |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
94 | for (ulong j = 0; j < objects.size(); ++j) |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
95 | delete objects[j]; |
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
|
96 | |
25
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
97 | delete this; |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
98 | } |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
99 | |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
100 | // ============================================================================= |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
101 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
102 | // ============================================================================= |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
103 | void closeAll () { |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
104 | if (!g_LoadedFiles.size()) |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
105 | return; |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
106 | |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
107 | // Remove all loaded files and the objects they contain |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
108 | for (ushort i = 0; i < g_LoadedFiles.size(); i++) { |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
109 | OpenFile* f = g_LoadedFiles[i]; |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
110 | f->close (); |
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
|
111 | } |
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 | |
25
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
113 | // Clear the array |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
114 | g_LoadedFiles.clear(); |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
115 | g_CurrentFile = NULL; |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
116 | |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
117 | g_qWindow->R->hardRefresh(); |
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
|
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 | |
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 | // ============================================================================= |
25
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
121 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
122 | // ============================================================================= |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
123 | void newFile () { |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
124 | // Create a new anonymous file and set it to our current |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
125 | closeAll (); |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
126 | |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
127 | OpenFile* f = new OpenFile; |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
128 | f->zFileName = ""; |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
129 | g_LoadedFiles.push_back (f); |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
130 | g_CurrentFile = f; |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
131 | |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
132 | g_BBox.calculate(); |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
133 | g_qWindow->buildObjList (); |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
134 | g_qWindow->R->hardRefresh(); |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
135 | } |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
136 | |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
137 | // ============================================================================= |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
138 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
139 | // ============================================================================= |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
140 | void openMainFile (str zPath) { |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
141 | closeAll (); |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
142 | |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
143 | OpenFile* pFile = openDATFile (zPath); |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
144 | g_CurrentFile = pFile; |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
145 | |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
146 | // Recalculate the bounding box |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
147 | g_BBox.calculate(); |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
148 | |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
149 | // Rebuild the object tree view now. |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
150 | g_qWindow->buildObjList (); |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
151 | g_qWindow->setTitle (); |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
152 | } |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
153 | |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
154 | // ============================================================================= |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
155 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
156 | // ============================================================================= |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
157 | void OpenFile::save (str zPath) { |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
158 | if (!~zPath) |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
159 | zPath = zFileName; |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
160 | |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
161 | FILE* fp = fopen (zPath, "w"); |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
162 | if (!fp) |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
163 | return; |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
164 | |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
165 | // Write all entries now |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
166 | for (ulong i = 0; i < objects.size(); ++i) { |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
167 | LDObject* obj = objects[i]; |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
168 | |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
169 | // LDraw requires lines to have DOS line endings |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
170 | str zLine = str::mkfmt ("%s\r\n",obj->getContents ().chars ()); |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
171 | |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
172 | fwrite (zLine.chars(), 1, ~zLine, fp); |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
173 | } |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
174 | |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
175 | fclose (fp); |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
176 | } |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
177 | |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
178 | // ============================================================================= |
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
179 | // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
0 | 180 | // ============================================================================= |
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
|
181 | #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
|
182 | 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
|
183 | 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
|
184 | |
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 | #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
|
186 | 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
|
187 | 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
|
188 | 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
|
189 | (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
|
190 | |
25
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
191 | LDObject* parseLine (str zLine) { |
0 | 192 | str zNoWhitespace = zLine; |
25
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
193 | stripWhitespace (zNoWhitespace); |
0 | 194 | if (!~zNoWhitespace) { |
195 | // Line was empty, or only consisted of whitespace | |
196 | return new LDEmpty; | |
197 | } | |
198 | ||
199 | vector<str> tokens = zLine / " "; | |
200 | ||
23
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
201 | // Rid leading all-whitespace tokens |
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
202 | while (tokens.size() && !(~tokens[0])) |
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
203 | tokens.erase (tokens.begin()); |
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
204 | |
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
|
205 | 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
|
206 | 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
|
207 | |
23
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
208 | char const c = tokens[0][0]; |
0 | 209 | switch (c - '0') { |
210 | case 0: | |
211 | { | |
212 | // Comment | |
213 | LDComment* obj = new LDComment; | |
17
5606eebd0b90
Allow addition of dummy lines..
Santeri Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
214 | obj->zText = zLine.substr (2, -1); |
0 | 215 | return obj; |
216 | } | |
217 | ||
218 | case 1: | |
219 | { | |
23
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
220 | // Subfile |
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
|
221 | 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
|
222 | 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
|
223 | |
23
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
224 | #ifndef WIN32 |
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
225 | tokens[14].replace ("\\", "/"); |
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
226 | #endif // WIN32 |
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
227 | |
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
228 | // Try open the file |
25
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
229 | OpenFile* pFile = findLoadedFile (tokens[14]); |
23
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
230 | if (!pFile) |
25
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
231 | pFile = openDATFile (tokens[14]); |
23
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
232 | |
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
233 | // If we cannot open the file, mark it an error |
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
234 | if (!pFile) |
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
235 | return new LDGibberish (zLine, "Could not open referred file"); |
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
236 | |
0 | 237 | LDSubfile* obj = new LDSubfile; |
238 | obj->dColor = atoi (tokens[1]); | |
25
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
239 | obj->vPosition = parseVertex (zLine, 2); // 2 - 4 |
0 | 240 | |
241 | for (short i = 0; i < 9; ++i) | |
242 | obj->faMatrix[i] = atof (tokens[i + 5]); // 5 - 13 | |
243 | ||
244 | obj->zFileName = tokens[14]; | |
23
69a91c1ff583
begin work on subfile caching
Santeri Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
245 | obj->pFile = pFile; |
0 | 246 | return obj; |
247 | } | |
248 | ||
249 | case 2: | |
250 | { | |
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
|
251 | 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
|
252 | 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
|
253 | |
0 | 254 | // Line |
255 | LDLine* obj = new LDLine; | |
25
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
256 | obj->dColor = getWordInt (zLine, 1); |
0 | 257 | for (short i = 0; i < 2; ++i) |
25
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
258 | obj->vaCoords[i] = parseVertex (zLine, 2 + (i * 3)); // 2 - 7 |
0 | 259 | return obj; |
260 | } | |
261 | ||
262 | case 3: | |
263 | { | |
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
|
264 | 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
|
265 | 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
|
266 | |
0 | 267 | // Triangle |
268 | LDTriangle* obj = new LDTriangle; | |
25
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
269 | obj->dColor = getWordInt (zLine, 1); |
0 | 270 | |
271 | for (short i = 0; i < 3; ++i) | |
25
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
272 | obj->vaCoords[i] = parseVertex (zLine, 2 + (i * 3)); // 2 - 10 |
0 | 273 | |
274 | return obj; | |
275 | } | |
276 | ||
277 | case 4: | |
278 | { | |
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
|
279 | 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
|
280 | 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
|
281 | |
0 | 282 | // Quadrilateral |
283 | LDQuad* obj = new LDQuad; | |
25
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
284 | obj->dColor = getWordInt (zLine, 1); |
0 | 285 | |
286 | for (short i = 0; i < 4; ++i) | |
25
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
287 | obj->vaCoords[i] = parseVertex (zLine, 2 + (i * 3)); // 2 - 13 |
0 | 288 | |
289 | return obj; | |
290 | } | |
291 | ||
292 | case 5: | |
293 | { | |
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
|
294 | 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
|
295 | 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
|
296 | |
0 | 297 | // Conditional line |
298 | LDCondLine* obj = new LDCondLine; | |
25
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
299 | obj->dColor = getWordInt (zLine, 1); |
0 | 300 | |
301 | for (short i = 0; i < 2; ++i) | |
25
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
302 | obj->vaCoords[i] = parseVertex (zLine, 2 + (i * 3)); // 2 - 7 |
0 | 303 | |
304 | for (short i = 0; i < 2; ++i) | |
25
c74bb88f537d
Deleted scanner.cpp (don't need it), merged model.cpp into io.cpp. Renamed LDForgeWindow to just ForgeWindow since I want the LD* prefix only be given to LDObject derivatives.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
305 | obj->vaControl[i] = parseVertex (zLine, 8 + (i * 3)); // 8 - 13 |
0 | 306 | return obj; |
307 | } | |
308 | ||
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
|
309 | 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
|
310 | return new LDGibberish (zLine, "Unknown line code number"); |
0 | 311 | } |
312 | } |