7
std::vector<wSector_t *> AllDaySectors;
10
const int TagFor242 = 9999;
11
const int StartTag = 10000;
12
const int LightStartTag = 10000;
13
const int TransferStartTag = 15000;
14
const int StaticTag = 12000;
18
OutFile.open("output.wl", std::ios::out);
21
void LG_CloseOutFile()
26
void LC_Exit(int code)
31
void LG_ReadSectors(wFile_t *file, std::string mapname, std::vector<wSector_t *> §s)
33
const int SECTOR_SIZE = 26;
36
for (std::vector<wSector_t *>::iterator it = sects.begin(); it != sects.end(); ++it) {
38
sects.erase(sects.begin());
42
wEntry_t *sectors = Wad_FindEntry(file, "SECTORS",
43
Wad_FindEntry(file, mapname.c_str(), NULL, false), false);
45
uint8_t *sectLump = (uint8_t *)malloc(sectors->size * sizeof(uint8_t)); // SECTORS's data
46
fseek(file->file, sectors->offset, SEEK_SET);
47
fread((void*)sectLump, 1, sectors->size, file->file);
49
for (size_t i = 0; i < sectors->size; i += SECTOR_SIZE) { //
50
wSector_t *sector = new wSector_t;
51
sector->FloorHeight = read2bytes_mem((void *)(sectLump + i));
52
sector->CeilingHeight = read2bytes_mem((void *)(sectLump + i + 0x02));
53
memcpy((void *)(sector->FloorTexture), (void *)(sectLump + i + 0x04), 8);
54
memcpy((void *)(sector->CeilingTexture), (void *)(sectLump + i + 0x0C), 8);
55
sector->Light = read2bytes_mem((void *)(sectLump + i + 0x14));
56
sector->Tag = read2bytes_mem((void *)(sectLump + i + 0x18));
57
if (sector->Tag >= StartTag) {
58
sects.push_back(sector);
68
void LG_GenerateGeometry(std::vector<wSector_t *> daySects)
70
const int dayintics = 1024;
71
const int numsect = daySects.size();
72
const int daytonight[] = {240, 224, 208, 192, 176, 160, 144, 128, 112};
75
OutFile << "#\"standard.h\"" << std::endl;
76
OutFile << "#\"spawns.h\"" << std::endl;
80
OutFile << "Voodoo_Evening(tag)" << std::endl;
81
OutFile << "{" << std::endl;
82
// vBoxSize - horizontal size of box, multiple of 32, rounded upward
83
OutFile << "set(\"vBoxSize\", mul(add(div(" << numsect << ", 32), 1), 32))" << std::endl;
84
// number of voodoo dools
85
OutFile << "set(\"voodoos\", div(get(\"vBoxSize\"), 32))" << std::endl;
86
// first light to minimum neighbor
87
OutFile << "typeline(157,tag, step(-32, 0))" << std::endl;
88
// just lines to the end
89
OutFile << "for(2,get(\"voodoos\"),step(-32, 0))" << std::endl;
90
// one mappixel further
91
OutFile << "movestep(get(\"vBoxSize\"), -1)" << std::endl;
92
// transfer light to minimum neighbor
93
OutFile << "typeline(157,1099, step(-32, 0))" << std::endl;
94
// just lines to the end
95
OutFile << "for(2,get(\"voodoos\"),step(-32, 0))" << std::endl;
96
// one mappixel further
97
OutFile << "movestep(get(\"vBoxSize\"), -1)" << std::endl;
99
// determine current light level
100
OutFile << "{eq(tag, 1002) ? set(\"lightlevel\", 113) : \
101
{eq(tag, 1003) ? set(\"lightlevel\", 129) : \
102
{eq(tag, 1004) ? set(\"lightlevel\", 145) : \
103
{eq(tag, 1005) ? set(\"lightlevel\", 161) : \
104
{eq(tag, 1006) ? set(\"lightlevel\", 177) : \
105
{eq(tag, 1007) ? set(\"lightlevel\", 193) : \
106
{eq(tag, 1008) ? set(\"lightlevel\", 209) : \
107
{eq(tag, 1009) ? set(\"lightlevel\", 225) : \
108
{eq(tag, 1010) ? set(\"lightlevel\", 241) : set(\"lightlevel\", 0)}}}}}}}}}" << std::endl;
110
int counter = TransferStartTag;
111
for (int i = 0; i < daySects.size(); ++i) {
112
wSector_t &daysector = *daySects[i];
114
OutFile << "{lessthaneq(" << daysector.Light << ", get(\"lightlevel\")) ? \
115
movestep(-1, 0) : typeline(157," << counter++ << ", step(-1, 0))}" << std::endl;
117
OutFile << "{lessthaneq(" << daysector.Light << ", get(\"lightlevel\")) ? \
118
movestep(-1, 0) : typeline(157," << counter++ << ", step(-1, 0))}" << std::endl;*/
120
// just lines to the end
121
OutFile << "step(inv(sub(get(\"vBoxSize\"), " << numsect <<")), 0)" << std::endl;
124
OutFile << "movestep(get(\"vBoxSize\"), -1)" << std::endl;
125
// next light transfer
126
OutFile << "typeline(157, " << TagFor242 << ", step(-32, 0))" << std::endl;
127
// just lines to the end
128
OutFile << "for(2,get(\"voodoos\"),step(-32, 0))" << std::endl;
129
// one mappixel further
130
OutFile << "movestep(get(\"vBoxSize\"), 30)" << std::endl;
132
OutFile << "}" << std::endl;
135
// Voodoo morning controller
136
OutFile << "Voodoo_Morning(tag)" << std::endl;
137
OutFile << "{" << std::endl;
138
// vBoxSize - horizontal size of box, multiple of 32, rounded upward
139
OutFile << "set(\"vBoxSize\", mul(add(div(" << numsect << ", 32), 1), 32))" << std::endl;
140
// number of voodoo dools
141
OutFile << "set(\"voodoos\", div(get(\"vBoxSize\"), 32))" << std::endl;
142
OutFile << "typeline(80,tag, step(-32, 0))" << std::endl;
143
// just lines to the end
144
OutFile << "for(2,get(\"voodoos\"),step(-32, 0))" << std::endl;
145
// one mappixel further
146
OutFile << "movestep(get(\"vBoxSize\"), -1)" << std::endl;
147
// transfer light to minimum neighbor
148
OutFile << "typeline(80,1099, step(-32, 0))" << std::endl;
149
// just lines to the end
150
OutFile << "for(2,get(\"voodoos\"),step(-32, 0))" << std::endl;
151
// one mappixel further
152
OutFile << "movestep(get(\"vBoxSize\"), -1)" << std::endl;
154
// determine current light level
155
OutFile << "{eq(tag, 1003) ? set(\"lightlevel\", 127) : \
156
{eq(tag, 1004) ? set(\"lightlevel\", 143) : \
157
{eq(tag, 1005) ? set(\"lightlevel\", 159) : \
158
{eq(tag, 1006) ? set(\"lightlevel\", 175) : \
159
{eq(tag, 1007) ? set(\"lightlevel\", 191) : \
160
{eq(tag, 1008) ? set(\"lightlevel\", 207) : \
161
{eq(tag, 1009) ? set(\"lightlevel\", 223) : \
162
{eq(tag, 1010) ? set(\"lightlevel\", 239) : \
163
{eq(tag, 1011) ? set(\"lightlevel\", 254) : set(\"lightlevel\", 0)}}}}}}}}}" << std::endl;
165
counter = TransferStartTag;
166
for (int i = 0; i < daySects.size(); ++i) {
167
wSector_t &daysector = *daySects[i];
168
OutFile << "{lessthaneq(" << daysector.Light << ", get(\"lightlevel\")) ? \
169
movestep(-1, 0) : typeline(80," << counter++ << ", step(-1, 0))}" << std::endl;
171
// just lines to the end
172
OutFile << "step(inv(sub(get(\"vBoxSize\"), " << numsect <<")), 0)" << std::endl;
174
OutFile << "movestep(get(\"vBoxSize\"), -1)" << std::endl;
175
// next light transfer
176
OutFile << "typeline(80, " << TagFor242 << ", step(-32, 0))" << std::endl;
177
// just lines to the end
178
OutFile << "for(2,get(\"voodoos\"),step(-32, 0))" << std::endl;
179
// one mappixel further
180
OutFile << "movestep(get(\"vBoxSize\"), 30)" << std::endl;
182
OutFile << "}" << std::endl;
185
OutFile << "GenVoodooController" << std::endl;
186
OutFile << "{" << std::endl;
187
OutFile << "set(\"vBoxSize\", mul(add(div(" << daySects.size() << ", 32), 1), 32))" << std::endl;
188
OutFile << "set(\"voodoos\", div(get(\"vBoxSize\"), 32))" << std::endl;
189
OutFile << "movestep(0, " << dayintics <<")" << std::endl;
190
OutFile << "movestep(-16, -64)" << std::endl;
192
OutFile << "Voodoo_Morning(1011)" << std::endl;
193
OutFile << "Voodoo_Morning(1010)" << std::endl;
194
OutFile << "Voodoo_Morning(1009)" << std::endl;
195
OutFile << "Voodoo_Morning(1008)" << std::endl;
196
OutFile << "Voodoo_Morning(1007)" << std::endl;
197
OutFile << "Voodoo_Morning(1006)" << std::endl;
198
OutFile << "Voodoo_Morning(1005)" << std::endl;
199
OutFile << "Voodoo_Morning(1004)" << std::endl;
200
for (int i = 0; i < daySects.size(); ++i) {
201
wSector_t &daysector = *daySects[i];
202
OutFile << "typeline(157,"<<TransferStartTag+i <<", step(-1, 0))" << std::endl;
204
OutFile << "step(inv(sub(get(\"vBoxSize\"), " << numsect <<")), 0)" << std::endl;
205
OutFile << "movestep(get(\"vBoxSize\"), 10)" << std::endl;
208
OutFile << "typeline(157,1000, step(-1, 0))" << std::endl;
209
OutFile << "typeline(157,1001, step(-1, 0))" << std::endl;
210
OutFile << "typeline(157,1002, step(-1, 0))" << std::endl;
211
OutFile << "typeline(157,1003, step(-1, 0))" << std::endl;
212
OutFile << "typeline(157,1004, step(-1, 0))" << std::endl;
213
OutFile << "typeline(157,1005, step(-1, 0))" << std::endl;
214
OutFile << "typeline(157,1006, step(-1, 0))" << std::endl;
215
OutFile << "typeline(157,1007, step(-1, 0))" << std::endl;
216
OutFile << "typeline(157,1008, step(-1, 0))" << std::endl;
217
OutFile << "typeline(157,1009, step(-1, 0))" << std::endl;
218
OutFile << "typeline(157,1010, step(-1, 0))" << std::endl;
219
OutFile << "typeline(157,1011, step(-1, 0))" << std::endl;
220
OutFile << "typeline(157,1099, step(-1, 0))" << std::endl;
221
OutFile << "typeline(157,9999, step(-1, 0))" << std::endl;
222
OutFile << "movestep(inv(sub(get(\"vBoxSize\"), " << 14 <<")), 0)" << std::endl;
223
// one mappixel further
224
OutFile << "movestep(get(\"vBoxSize\"), 10)" << std::endl;
227
OutFile << "Voodoo_Evening(1003)" << std::endl;
228
OutFile << "Voodoo_Evening(1004)" << std::endl;
229
OutFile << "Voodoo_Evening(1005)" << std::endl;
230
OutFile << "Voodoo_Evening(1006)" << std::endl;
231
OutFile << "Voodoo_Evening(1007)" << std::endl;
232
OutFile << "Voodoo_Evening(1008)" << std::endl;
233
OutFile << "Voodoo_Evening(1009)" << std::endl;
234
OutFile << "Voodoo_Evening(1010)" << std::endl;
235
for (int i = 0; i < daySects.size(); ++i) {
236
wSector_t &daysector = *daySects[i];
237
OutFile << "typeline(81,"<<TransferStartTag+i <<", step(-1, 0))" << std::endl;
239
OutFile << "step(inv(sub(get(\"vBoxSize\"), " << numsect <<")), 0)" << std::endl;
240
OutFile << "movestep(get(\"vBoxSize\"), 10)" << std::endl;
242
OutFile << "typeline(81,1000, step(-1, 0))" << std::endl;
243
OutFile << "typeline(81,1001, step(-1, 0))" << std::endl;
244
OutFile << "typeline(81,1002, step(-1, 0))" << std::endl;
245
OutFile << "typeline(81,1003, step(-1, 0))" << std::endl;
246
OutFile << "typeline(81,1004, step(-1, 0))" << std::endl;
247
OutFile << "typeline(81,1005, step(-1, 0))" << std::endl;
248
OutFile << "typeline(81,1006, step(-1, 0))" << std::endl;
249
OutFile << "typeline(81,1007, step(-1, 0))" << std::endl;
250
OutFile << "typeline(81,1008, step(-1, 0))" << std::endl;
251
OutFile << "typeline(81,1009, step(-1, 0))" << std::endl;
252
OutFile << "typeline(81,1010, step(-1, 0))" << std::endl;
253
OutFile << "typeline(81,1011, step(-1, 0))" << std::endl;
254
OutFile << "movestep(inv(sub(get(\"vBoxSize\"), " << 12 <<")), 0)" << std::endl;
255
// one mappixel further
256
OutFile << "movestep(get(\"vBoxSize\"), 1)" << std::endl;
257
OutFile << "movestep(0, 64)" << std::endl;
261
OutFile << "movestep(0, inv(add(get(\"vBoxSize\"), 1)))" << std::endl;
263
OutFile << "typesector(0, 1012, " << std::endl;
264
OutFile << "step(add(get(\"vBoxSize\"), 2), 0)" << std::endl;
265
OutFile << "step(0, "<< dayintics <<")" << std::endl;
266
OutFile << "step(inv(add(get(\"vBoxSize\"), 2)), 0)" << std::endl;
267
OutFile << "step(0, inv("<< dayintics <<"))" << std::endl;
268
OutFile << "rightsector(0, 128, 255) )" << std::endl;
269
OutFile << "movestep(0, "<< dayintics <<")" << std::endl;
270
OutFile << "typeline(252,1012, step(0, -64))" << std::endl;
271
OutFile << "player1start" << std::endl;
272
OutFile << "movestep(17, 0)" << std::endl;
273
OutFile << "for(1,get(\"voodoos\"), thing movestep(32, 0))" << std::endl;
274
OutFile << "}" << std::endl;
280
const int MaxSects = 100;
281
counter = TransferStartTag;
282
for (std::vector<wSector_t *>::iterator it = daySects.begin(); it != daySects.end(); ++it) {
283
if (count % MaxSects == 0) {
284
if (OutFile.is_open()) {
285
OutFile << "}" << std::endl;
286
OutFile << "main {" << std::endl;
287
OutFile << "rotright" << std::endl;
288
OutFile << "GetLightManager"<<filecount << std::endl;
289
OutFile << "}" << std::endl;
294
std::string str("sector");
295
str.append(std::to_string(filecount));
297
OutFile.open(str, std::ios::out);
298
OutFile << "#\"standard.h\"" << std::endl;
299
OutFile << "#\"spawns.h\"" << std::endl;
300
OutFile << "GetLightManager" << filecount << std::endl;
301
OutFile << "{" << std::endl;
302
OutFile << "top(\"SKY1\")" << std::endl;
303
OutFile << "step(24, 0)" << std::endl;
304
OutFile << "step(0, " << 2*(MaxSects+50)+1 << ")" << std::endl;
305
OutFile << "step(-24, 0)" << std::endl;
306
OutFile << "step(0," << -(2*(MaxSects+50)+1) <<")" << std::endl;
307
OutFile << "typesector(0, 1099, rightsector(-10000, 10000, 255))" << std::endl;
311
wSector_t §or = **it;
312
OutFile << "step(-1, 0)" << std::endl;
313
OutFile << "typeline(213, " << sector.Tag << ", step(1, 1))" << std::endl;
314
OutFile << "step(0, -1)" << std::endl;
315
OutFile << "typesector(0, " << (sector.Tag >= StaticTag ? 6666 : counter) << ", leftsector(-10000, 10000, 255))" << std::endl;
316
OutFile << "movestep(-1, 0)" << std::endl;
317
OutFile << "typeline(271, " << sector.Tag << ", step(-1, 1))" << std::endl;
318
OutFile << "typeline(242, " << sector.Tag << ", step(1, 0))" << std::endl;
319
OutFile << "typeline(261, " << sector.Tag << ", step(1, 0))" << std::endl;
320
OutFile << "typeline(213, " << sector.Tag << ", step(-1, -1))" << std::endl;
321
OutFile << "floor(\"";
322
OutFile.write(sector.FloorTexture, std::min<int>(8, strlen(sector.FloorTexture)));
323
OutFile << "\")" << std::endl;
324
OutFile << "ceil(\"";
325
OutFile.write(sector.CeilingTexture, std::min<int>(8, strlen(sector.CeilingTexture)));
326
OutFile << "\")" << std::endl;
327
OutFile << "typesector(0," << (sector.Tag >= StaticTag ? 0 : TagFor242) << ", leftsector("
328
<< sector.FloorHeight + 1 << ", " << sector.FloorHeight + 1 << ", " << sector.Light<<"))" << std::endl;
329
OutFile << "movestep(1, 2)" << std::endl;
334
if (OutFile.is_open()) {
335
OutFile << "}" << std::endl;
336
OutFile << "main {" << std::endl;
337
OutFile << "rotright" << std::endl;
338
OutFile << "GetLightManager"<<filecount << std::endl;
339
OutFile << "}" << std::endl;
347
fprintf(stdout, "Usage: boomlightgen [OPTIONS] mapname daywad\n");
349
fprintf(stdout, " mapname\t Map to use\n");
350
fprintf(stdout, " daywad\t Wad used for day light\n");
353
int LG_Main(int argc, char **argv)
355
fprintf(stdout, "boomlightgen 0.1 by cybermind - a tool to generate realistic day/night cycle for Boom wads.\n");
361
std::string mapname(argv[1]);
362
std::string daywad(argv[2]);
363
wFile_t *daywadfile = Wad_Open(daywad.c_str());
368
LG_ReadSectors(daywadfile, mapname, AllDaySectors);
369
fprintf(stdout, "daysectors: %d\n", AllDaySectors.size());
371
LG_GenerateGeometry(AllDaySectors);
372
fprintf(stdout, "done\n");
376
int main(int argc, char **argv)
378
return LG_Main(argc, argv);
b'\\ No newline at end of file'