/
p_dmu.cpp
2464 lines (2144 loc) · 65.8 KB
/
p_dmu.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/** @file p_dmu.cpp Doomsday Map Update API
*
* @todo Throw a game-terminating exception if an illegal value is given
* to a public API function.
*
* @authors Copyright © 2006-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2006-2013 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA</small>
*/
#define DENG_NO_API_MACROS_MAP
#include <cstring>
#include "de_base.h"
#include "de_play.h"
#include "de_audio.h"
#include <de/LegacyCore>
#include <de/memoryzone.h>
#include "Materials"
#include "api_map.h"
// Converting a public void* pointer to an internal de::MapElement.
#define IN_ELEM(p) reinterpret_cast<de::MapElement *>(p)
#define IN_ELEM_CONST(p) reinterpret_cast<de::MapElement const *>(p)
using namespace de;
/**
* Additional data for all dummy elements.
*/
struct DummyData
{
void *extraData; /// Pointer to user data.
DummyData() : extraData(0) {}
virtual ~DummyData() {} // polymorphic
};
class DummyVertex : public Vertex, public DummyData {};
class DummySideDef : public SideDef, public DummyData {};
class DummySector : public Sector, public DummyData {};
class DummyLineDef : public LineDef, public DummyData
{
public:
DummyLineDef(DummyVertex &v1, DummyVertex &v2) : LineDef(v1, v2) {}
};
typedef QSet<de::MapElement *> Dummies;
static Dummies dummies;
static DummyVertex dummyVertex; // The one dummy vertex.
char const *DMU_Str(uint prop)
{
static char propStr[40];
struct prop_s {
uint prop;
char const *str;
} props[] =
{
{ DMU_NONE, "(invalid)" },
{ DMU_VERTEX, "DMU_VERTEX" },
{ DMU_HEDGE, "DMU_HEDGE" },
{ DMU_LINEDEF, "DMU_LINEDEF" },
{ DMU_SIDEDEF, "DMU_SIDEDEF" },
{ DMU_BSPNODE, "DMU_BSPNODE" },
{ DMU_BSPLEAF, "DMU_BSPLEAF" },
{ DMU_SECTOR, "DMU_SECTOR" },
{ DMU_PLANE, "DMU_PLANE" },
{ DMU_MATERIAL, "DMU_MATERIAL" },
{ DMU_LINEDEF_BY_TAG, "DMU_LINEDEF_BY_TAG" },
{ DMU_SECTOR_BY_TAG, "DMU_SECTOR_BY_TAG" },
{ DMU_LINEDEF_BY_ACT_TAG, "DMU_LINEDEF_BY_ACT_TAG" },
{ DMU_SECTOR_BY_ACT_TAG, "DMU_SECTOR_BY_ACT_TAG" },
{ DMU_X, "DMU_X" },
{ DMU_Y, "DMU_Y" },
{ DMU_XY, "DMU_XY" },
{ DMU_TANGENT_X, "DMU_TANGENT_X" },
{ DMU_TANGENT_Y, "DMU_TANGENT_Y" },
{ DMU_TANGENT_Z, "DMU_TANGENT_Z" },
{ DMU_TANGENT_XYZ, "DMU_TANGENT_XYZ" },
{ DMU_BITANGENT_X, "DMU_BITANGENT_X" },
{ DMU_BITANGENT_Y, "DMU_BITANGENT_Y" },
{ DMU_BITANGENT_Z, "DMU_BITANGENT_Z" },
{ DMU_BITANGENT_XYZ, "DMU_BITANGENT_XYZ" },
{ DMU_NORMAL_X, "DMU_NORMAL_X" },
{ DMU_NORMAL_Y, "DMU_NORMAL_Y" },
{ DMU_NORMAL_Z, "DMU_NORMAL_Z" },
{ DMU_NORMAL_XYZ, "DMU_NORMAL_XYZ" },
{ DMU_VERTEX0, "DMU_VERTEX0" },
{ DMU_VERTEX1, "DMU_VERTEX1" },
{ DMU_FRONT_SECTOR, "DMU_FRONT_SECTOR" },
{ DMU_BACK_SECTOR, "DMU_BACK_SECTOR" },
{ DMU_SIDEDEF0, "DMU_SIDEDEF0" },
{ DMU_SIDEDEF1, "DMU_SIDEDEF1" },
{ DMU_FLAGS, "DMU_FLAGS" },
{ DMU_DX, "DMU_DX" },
{ DMU_DY, "DMU_DY" },
{ DMU_DXY, "DMU_DXY" },
{ DMU_LENGTH, "DMU_LENGTH" },
{ DMU_SLOPETYPE, "DMU_SLOPETYPE" },
{ DMU_ANGLE, "DMU_ANGLE" },
{ DMU_OFFSET, "DMU_OFFSET" },
{ DMU_OFFSET_X, "DMU_OFFSET_X" },
{ DMU_OFFSET_Y, "DMU_OFFSET_Y" },
{ DMU_OFFSET_XY, "DMU_OFFSET_XY" },
{ DMU_BLENDMODE, "DMU_BLENDMODE" },
{ DMU_VALID_COUNT, "DMU_VALID_COUNT" },
{ DMU_LINEDEF_COUNT, "DMU_LINEDEF_COUNT" },
{ DMU_COLOR, "DMU_COLOR" },
{ DMU_COLOR_RED, "DMU_COLOR_RED" },
{ DMU_COLOR_GREEN, "DMU_COLOR_GREEN" },
{ DMU_COLOR_BLUE, "DMU_COLOR_BLUE" },
{ DMU_ALPHA, "DMU_ALPHA" },
{ DMU_LIGHT_LEVEL, "DMU_LIGHT_LEVEL" },
{ DMT_MOBJS, "DMT_MOBJS" },
{ DMU_BOUNDING_BOX, "DMU_BOUNDING_BOX" },
{ DMU_BASE, "DMU_BASE" },
{ DMU_WIDTH, "DMU_WIDTH" },
{ DMU_HEIGHT, "DMU_HEIGHT" },
{ DMU_TARGET_HEIGHT, "DMU_TARGET_HEIGHT" },
{ DMU_HEDGE_COUNT, "DMU_HEDGE_COUNT" },
{ DMU_SPEED, "DMU_SPEED" },
{ DMU_FLOOR_PLANE, "DMU_FLOOR_PLANE" },
{ DMU_CEILING_PLANE, "DMU_CEILING_PLANE" },
{ 0, NULL }
};
for(uint i = 0; props[i].str; ++i)
{
if(props[i].prop == prop)
return props[i].str;
}
dd_snprintf(propStr, 40, "(unnamed %i)", prop);
return propStr;
}
#undef DMU_GetType
int DMU_GetType(void const *ptr)
{
if(!ptr) return DMU_NONE;
de::MapElement const *elem = IN_ELEM_CONST(ptr);
// Make sure it's valid.
switch(elem->type())
{
case DMU_VERTEX:
case DMU_HEDGE:
case DMU_LINEDEF:
case DMU_SIDEDEF:
case DMU_BSPLEAF:
case DMU_SECTOR:
case DMU_PLANE:
case DMU_BSPNODE:
case DMU_SURFACE:
case DMU_MATERIAL:
return elem->type();
default: break; // Unknown.
}
return DMU_NONE;
}
/**
* Initializes a setargs struct.
*
* @param type Type of the map data object.
* @param args Ptr to setargs struct to be initialized.
* @param prop Property of the map data object.
*/
static void initArgs(setargs_t *args, int type, uint prop)
{
DENG_ASSERT(args && VALID_DMU_ELEMENT_TYPE_ID(type));
std::memset(args, 0, sizeof(*args));
args->type = type;
args->prop = prop & ~DMU_FLAG_MASK;
args->modifiers = prop & DMU_FLAG_MASK;
}
void P_InitMapUpdate()
{
// TODO: free existing/old dummies here?
dummies.clear();
}
#undef P_AllocDummy
void *P_AllocDummy(int type, void *extraData)
{
switch(type)
{
case DMU_SIDEDEF: {
DummySideDef *ds = new DummySideDef;
dummies.insert(ds);
ds->extraData = extraData;
return ds; }
case DMU_LINEDEF: {
DummyLineDef *dl = new DummyLineDef(dummyVertex, dummyVertex);
dummies.insert(dl);
dl->extraData = extraData;
return dl; }
case DMU_SECTOR: {
DummySector *ds = new DummySector;
dummies.insert(ds);
ds->extraData = extraData;
return ds; }
default: {
/// @throw Throw exception.
QByteArray msg = String("P_AllocDummy: Dummies of type %1 not supported.").arg(DMU_Str(type)).toUtf8();
LegacyCore_FatalError(msg.constData());
break; }
}
return 0; // Unreachable.
}
#undef P_IsDummy
boolean P_IsDummy(void const *dummy)
{
return P_DummyType(dummy) != DMU_NONE;
}
#undef P_FreeDummy
void P_FreeDummy(void *dummy)
{
de::MapElement *elem = IN_ELEM(dummy);
int type = P_DummyType(dummy);
if(type == DMU_NONE)
{
/// @todo Throw exception.
LegacyCore_FatalError("P_FreeDummy: Dummy is of unknown type.");
}
DENG2_ASSERT(dummies.contains(elem));
dummies.remove(elem);
delete elem;
}
/**
* Determines the type of a dummy object.
*/
int P_DummyType(void const *dummy)
{
de::MapElement const *elem = IN_ELEM_CONST(dummy);
if(!dynamic_cast<DummyData const *>(elem))
{
// Not a dummy.
return DMU_NONE;
}
DENG2_ASSERT(dummies.contains(const_cast<de::MapElement *>(elem)));
return elem->type();
}
#undef P_DummyExtraData
void *P_DummyExtraData(void *dummy)
{
if(P_IsDummy(dummy))
{
de::MapElement *elem = IN_ELEM(dummy);
return elem->castTo<DummyData>()->extraData;
}
return 0;
}
#undef P_ToIndex
uint P_ToIndex(void const *ptr)
{
if(!ptr) return 0;
if(P_IsDummy(ptr)) return 0;
de::MapElement const *elem = IN_ELEM_CONST(ptr);
switch(elem->type())
{
case DMU_VERTEX:
return theMap->vertexIndex(elem->castTo<Vertex>());
case DMU_HEDGE:
return theMap->hedgeIndex(elem->castTo<HEdge>());
case DMU_LINEDEF:
return theMap->lineIndex(elem->castTo<LineDef>());
case DMU_SIDEDEF:
return theMap->sideDefIndex(elem->castTo<SideDef>());
case DMU_BSPLEAF:
return theMap->bspLeafIndex(elem->castTo<BspLeaf>());
case DMU_SECTOR:
return theMap->sectorIndex(elem->castTo<Sector>());
case DMU_BSPNODE:
return theMap->bspNodeIndex(elem->castTo<BspNode>());
case DMU_PLANE:
return elem->castTo<Plane>()->inSectorIndex();
case DMU_MATERIAL:
return elem->castTo<Material>()->manifest().id();
default:
/// @todo Throw exception.
DENG2_ASSERT(false); // Unknown/non-indexable DMU type.
return 0;
}
}
#undef P_ToPtr
void *P_ToPtr(int type, uint index)
{
switch(type)
{
case DMU_VERTEX:
return theMap->vertexes().at(index);
case DMU_HEDGE:
return theMap->hedges().at(index);
case DMU_LINEDEF:
return theMap->lines().at(index);
case DMU_SIDEDEF:
return theMap->sideDefs().at(index);
case DMU_SECTOR:
return theMap->sectors().at(index);
case DMU_PLANE: {
/// @todo Throw exception.
QByteArray msg = String("P_ToPtr: Cannot convert %1 to a ptr (sector is unknown).").arg(DMU_Str(type)).toUtf8();
LegacyCore_FatalError(msg.constData());
return 0; /* Unreachable. */ }
case DMU_BSPLEAF:
return theMap->bspLeafs().at(index);
case DMU_BSPNODE:
return theMap->bspNodes().at(index);
case DMU_MATERIAL:
if(index == 0) return 0;
return &App_Materials().toManifest(index).material();
default: {
/// @todo Throw exception.
QByteArray msg = String("P_ToPtr: unknown type %1.").arg(DMU_Str(type)).toUtf8();
LegacyCore_FatalError(msg.constData());
return 0; /* Unreachable. */ }
}
}
#undef P_Iteratep
int P_Iteratep(void *elPtr, uint prop, void *context, int (*callback) (void *p, void *ctx))
{
de::MapElement *elem = IN_ELEM(elPtr);
switch(elem->type())
{
case DMU_SECTOR:
switch(prop)
{
case DMU_LINEDEF:
foreach(LineDef *line, elem->castTo<Sector>()->lines())
{
int result = callback(line, context);
if(result) return result;
}
return false; // Continue iteration
case DMU_PLANE:
foreach(Plane *plane, elem->castTo<Sector>()->planes())
{
int result = callback(plane, context);
if(result) return result;
}
return false; // Continue iteration
case DMU_BSPLEAF:
foreach(BspLeaf *bspLeaf, elem->castTo<Sector>()->bspLeafs())
{
int result = callback(bspLeaf, context);
if(result) return result;
}
return false; // Continue iteration.
default:
throw Error("P_Iteratep", QString("Property %1 unknown/not vector").arg(DMU_Str(prop)));
}
case DMU_BSPLEAF:
switch(prop)
{
case DMU_HEDGE:
if(HEdge *base = elem->castTo<BspLeaf>()->firstHEdge())
{
HEdge *hedge = base;
do
{
int result = callback(hedge, context);
if(result) return result;
} while((hedge = &hedge->next()) != base);
}
return false; // Continue iteration.
default:
throw Error("P_Iteratep", QString("Property %1 unknown/not vector").arg(DMU_Str(prop)));
}
default:
throw Error("P_Iteratep", QString("Type %1 unknown").arg(DMU_Str(elem->type())));
}
return false;
}
/**
* Call a callback function on a selection of map data objects. The
* selected objects will be specified by 'type' and 'index'.
* @param context Is passed to the callback function.
*
* @return @c true if all the calls to the callback function
* return @c true.
* @c false is returned when the callback function
* returns @c false; in this case, the iteration is
* aborted immediately when the callback function
* returns @c false.
*/
#undef P_Callback
int P_Callback(int type, uint index, void *context, int (*callback)(void *p, void *ctx))
{
switch(type)
{
case DMU_VERTEX:
if(index < theMap->vertexCount())
return callback(theMap->vertexes().at(index), context);
break;
case DMU_HEDGE:
if(index < theMap->hedgeCount())
return callback(theMap->hedges().at(index), context);
break;
case DMU_LINEDEF:
if(index < theMap->lineCount())
return callback(theMap->lines().at(index), context);
break;
case DMU_SIDEDEF:
if(index < theMap->sideDefCount())
return callback(theMap->sideDefs().at(index), context);
break;
case DMU_BSPNODE:
if(index < theMap->bspNodeCount())
return callback(theMap->bspNodes().at(index), context);
break;
case DMU_BSPLEAF:
if(index < theMap->bspLeafCount())
return callback(theMap->bspLeafs().at(index), context);
break;
case DMU_SECTOR:
if(index < theMap->sectorCount())
return callback(theMap->sectors().at(index), context);
break;
case DMU_PLANE: {
/// @todo Throw exception.
QByteArray msg = String("P_Callback: %1 cannot be referenced by id alone (sector is unknown).").arg(DMU_Str(type)).toUtf8();
LegacyCore_FatalError(msg.constData());
return 0; /* Unreachable */ }
case DMU_MATERIAL:
if(index != 0)
return callback(&App_Materials().toManifest(materialid_t(index)).material(), context);
break;
case DMU_LINEDEF_BY_TAG:
case DMU_SECTOR_BY_TAG:
case DMU_LINEDEF_BY_ACT_TAG:
case DMU_SECTOR_BY_ACT_TAG: {
/// @todo Throw exception.
QByteArray msg = String("P_Callback: Type %1 not implemented yet.").arg(DMU_Str(type)).toUtf8();
LegacyCore_FatalError(msg.constData());
return 0; /* Unreachable */ }
default: {
/// @todo Throw exception.
QByteArray msg = String("P_Callback: Type %1 unknown (index %2).").arg(DMU_Str(type)).arg(index).toUtf8();
LegacyCore_FatalError(msg.constData());
return 0; /* Unreachable */ }
}
// Successfully completed.
return true;
}
/**
* Another version of callback iteration. The set of selected objects is
* determined by 'type' and 'ptr'. Otherwise works like P_Callback.
*/
#undef P_Callbackp
int P_Callbackp(int type, void *elPtr, void *context, int (*callback)(void *p, void *ctx))
{
de::MapElement *elem = IN_ELEM(elPtr);
LOG_AS("P_Callbackp");
switch(type)
{
case DMU_VERTEX:
case DMU_HEDGE:
case DMU_LINEDEF:
case DMU_SIDEDEF:
case DMU_BSPNODE:
case DMU_BSPLEAF:
case DMU_SECTOR:
case DMU_PLANE:
case DMU_MATERIAL:
// Only do the callback if the type is the same as the object's.
if(type == elem->type())
{
return callback(elem, context);
}
#if _DEBUG
else
{
LOG_DEBUG("Type mismatch %s != %s\n") << DMU_Str(type) << DMU_Str(elem->type());
DENG2_ASSERT(false);
}
#endif
break;
default: {
/// @todo Throw exception.
QByteArray msg = String("P_Callbackp: Type %1 unknown.").arg(DMU_Str(elem->type())).toUtf8();
LegacyCore_FatalError(msg.constData());
return 0; /* Unreachable */ }
}
return true;
}
void DMU_SetValue(valuetype_t valueType, void *dst, setargs_t const *args,
uint index)
{
if(valueType == DDVT_FIXED)
{
fixed_t *d = (fixed_t *)dst;
switch(args->valueType)
{
case DDVT_BYTE:
*d = (args->byteValues[index] << FRACBITS);
break;
case DDVT_INT:
*d = (args->intValues[index] << FRACBITS);
break;
case DDVT_FIXED:
*d = args->fixedValues[index];
break;
case DDVT_FLOAT:
*d = FLT2FIX(args->floatValues[index]);
break;
case DDVT_DOUBLE:
*d = FLT2FIX(args->doubleValues[index]);
break;
default: {
/// @todo Throw exception.
QByteArray msg = String("SetValue: DDVT_FIXED incompatible with value type %1.").arg(value_Str(args->valueType)).toUtf8();
LegacyCore_FatalError(msg.constData());
}
}
}
else if(valueType == DDVT_FLOAT)
{
float *d = (float *)dst;
switch(args->valueType)
{
case DDVT_BYTE:
*d = args->byteValues[index];
break;
case DDVT_INT:
*d = args->intValues[index];
break;
case DDVT_FIXED:
*d = FIX2FLT(args->fixedValues[index]);
break;
case DDVT_FLOAT:
*d = args->floatValues[index];
break;
case DDVT_DOUBLE:
*d = (float)args->doubleValues[index];
break;
default: {
/// @todo Throw exception.
QByteArray msg = String("SetValue: DDVT_FLOAT incompatible with value type %1.").arg(value_Str(args->valueType)).toUtf8();
LegacyCore_FatalError(msg.constData());
}
}
}
else if(valueType == DDVT_DOUBLE)
{
double *d = (double *)dst;
switch(args->valueType)
{
case DDVT_BYTE:
*d = args->byteValues[index];
break;
case DDVT_INT:
*d = args->intValues[index];
break;
case DDVT_FIXED:
*d = FIX2FLT(args->fixedValues[index]);
break;
case DDVT_FLOAT:
*d = args->floatValues[index];
break;
case DDVT_DOUBLE:
*d = args->doubleValues[index];
break;
default: {
/// @todo Throw exception.
QByteArray msg = String("SetValue: DDVT_DOUBLE incompatible with value type %1.").arg(value_Str(args->valueType)).toUtf8();
LegacyCore_FatalError(msg.constData());
}
}
}
else if(valueType == DDVT_BOOL)
{
boolean *d = (boolean *)dst;
switch(args->valueType)
{
case DDVT_BOOL:
*d = args->booleanValues[index];
break;
default: {
/// @todo Throw exception.
QByteArray msg = String("SetValue: DDVT_BOOL incompatible with value type %1.").arg(value_Str(args->valueType)).toUtf8();
LegacyCore_FatalError(msg.constData());
}
}
}
else if(valueType == DDVT_BYTE)
{
byte *d = (byte *)dst;
switch(args->valueType)
{
case DDVT_BOOL:
*d = args->booleanValues[index];
break;
case DDVT_BYTE:
*d = args->byteValues[index];
break;
case DDVT_INT:
*d = args->intValues[index];
break;
case DDVT_FLOAT:
*d = (byte) args->floatValues[index];
break;
case DDVT_DOUBLE:
*d = (byte) args->doubleValues[index];
break;
default: {
/// @todo Throw exception.
QByteArray msg = String("SetValue: DDVT_BYTE incompatible with value type %1.").arg(value_Str(args->valueType)).toUtf8();
LegacyCore_FatalError(msg.constData());
}
}
}
else if(valueType == DDVT_INT)
{
int *d = (int *)dst;
switch(args->valueType)
{
case DDVT_BOOL:
*d = args->booleanValues[index];
break;
case DDVT_BYTE:
*d = args->byteValues[index];
break;
case DDVT_INT:
*d = args->intValues[index];
break;
case DDVT_FLOAT:
*d = args->floatValues[index];
break;
case DDVT_DOUBLE:
*d = args->doubleValues[index];
break;
case DDVT_FIXED:
*d = (args->fixedValues[index] >> FRACBITS);
break;
default: {
/// @todo Throw exception.
QByteArray msg = String("SetValue: DDVT_INT incompatible with value type %1.").arg(value_Str(args->valueType)).toUtf8();
LegacyCore_FatalError(msg.constData());
}
}
}
else if(valueType == DDVT_SHORT)
{
short *d = (short *)dst;
switch(args->valueType)
{
case DDVT_BOOL:
*d = args->booleanValues[index];
break;
case DDVT_BYTE:
*d = args->byteValues[index];
break;
case DDVT_INT:
*d = args->intValues[index];
break;
case DDVT_FLOAT:
*d = args->floatValues[index];
break;
case DDVT_DOUBLE:
*d = args->doubleValues[index];
break;
case DDVT_FIXED:
*d = (args->fixedValues[index] >> FRACBITS);
break;
default: {
/// @todo Throw exception.
QByteArray msg = String("SetValue: DDVT_SHORT incompatible with value type %1.").arg(value_Str(args->valueType)).toUtf8();
LegacyCore_FatalError(msg.constData());
}
}
}
else if(valueType == DDVT_ANGLE)
{
angle_t *d = (angle_t *)dst;
switch(args->valueType)
{
case DDVT_ANGLE:
*d = args->angleValues[index];
break;
default: {
/// @todo Throw exception.
QByteArray msg = String("SetValue: DDVT_ANGLE incompatible with value type %1.").arg(value_Str(args->valueType)).toUtf8();
LegacyCore_FatalError(msg.constData());
}
}
}
else if(valueType == DDVT_BLENDMODE)
{
blendmode_t *d = (blendmode_t *)dst;
switch(args->valueType)
{
case DDVT_INT:
if(args->intValues[index] > DDNUM_BLENDMODES || args->intValues[index] < 0)
{
QByteArray msg = String("SetValue: %1 is not a valid value for DDVT_BLENDMODE.").arg(args->intValues[index]).toUtf8();
LegacyCore_FatalError(msg.constData());
}
*d = blendmode_t(args->intValues[index]);
break;
default: {
/// @todo Throw exception.
QByteArray msg = String("SetValue: DDVT_BLENDMODE incompatible with value type %1.").arg(value_Str(args->valueType)).toUtf8();
LegacyCore_FatalError(msg.constData());
}
}
}
else if(valueType == DDVT_PTR)
{
void **d = (void **)dst;
switch(args->valueType)
{
case DDVT_PTR:
*d = args->ptrValues[index];
break;
default: {
/// @todo Throw exception.
QByteArray msg = String("SetValue: DDVT_PTR incompatible with value type %1.").arg(value_Str(args->valueType)).toUtf8();
LegacyCore_FatalError(msg.constData());
}
}
}
else
{
/// @todo Throw exception.
QByteArray msg = String("SetValue: unknown value type %1.").arg(valueType).toUtf8();
LegacyCore_FatalError(msg.constData());
}
}
/**
* Only those properties that are writable by outside parties (such as games)
* are included here. Attempting to set a non-writable property causes a
* fatal error.
*
* When a property changes, the relevant subsystems are notified of the change
* so that they can update their state accordingly.
*/
static int setProperty(void *ptr, void *context)
{
de::MapElement *elem = IN_ELEM(ptr);
setargs_t *args = (setargs_t *) context;
Sector *updateSector1 = NULL, *updateSector2 = NULL;
Plane *updatePlane = NULL;
LineDef *updateLinedef = NULL;
SideDef *updateSidedef = NULL;
Surface *updateSurface = NULL;
// BspLeaf *updateBspLeaf = NULL;
/**
* @par Algorithm
* When setting a property, reference resolution is done hierarchically so
* that we can update all owner's of the objects being manipulated should
* the DMU object's Set routine suggest that a change occured (which other
* DMU objects may wish/need to respond to).
* <ol>
* <li> Collect references to all current owners of the object.
* <li> Pass the change delta on to the object.
* <li> Object responds: @c true = update owners, ELSE @c false.
* <li> If num collected references > 0: recurse, Object = owners[n]
* </ol>
*/
// Dereference where necessary. Note the order, these cascade.
if(args->type == DMU_BSPLEAF)
{
if(args->modifiers & DMU_FLOOR_OF_SECTOR)
{
elem = elem->castTo<BspLeaf>()->sectorPtr();
args->type = DMU_SECTOR;
}
else if(args->modifiers & DMU_CEILING_OF_SECTOR)
{
elem = elem->castTo<BspLeaf>()->sectorPtr();
args->type = DMU_SECTOR;
}
}
if(args->type == DMU_SECTOR)
{
updateSector1 = elem->castTo<Sector>();
if(args->modifiers & DMU_FLOOR_OF_SECTOR)
{
elem = &elem->castTo<Sector>()->floor();
args->type = DMU_PLANE;
}
else if(args->modifiers & DMU_CEILING_OF_SECTOR)
{
elem = &elem->castTo<Sector>()->ceiling();
args->type = DMU_PLANE;
}
}
if(args->type == DMU_LINEDEF)
{
updateLinedef = elem->castTo<LineDef>();
if(args->modifiers & DMU_SIDEDEF0_OF_LINE)
{
elem = &elem->castTo<LineDef>()->frontSideDef();
args->type = DMU_SIDEDEF;
}
else if(args->modifiers & DMU_SIDEDEF1_OF_LINE)
{
elem = &elem->castTo<LineDef>()->backSideDef();
args->type = DMU_SIDEDEF;
}
}
if(args->type == DMU_SIDEDEF)
{
updateSidedef = elem->castTo<SideDef>();
if(args->modifiers & DMU_TOP_OF_SIDEDEF)
{
elem = &updateSidedef->top();
args->type = DMU_SURFACE;
}
else if(args->modifiers & DMU_MIDDLE_OF_SIDEDEF)
{
elem = &updateSidedef->middle();
args->type = DMU_SURFACE;
}
else if(args->modifiers & DMU_BOTTOM_OF_SIDEDEF)
{
elem = &updateSidedef->bottom();
args->type = DMU_SURFACE;
}
}
if(args->type == DMU_PLANE)
{
updatePlane = elem->castTo<Plane>();
switch(args->prop)
{
case DMU_MATERIAL:
case DMU_OFFSET_X:
case DMU_OFFSET_Y:
case DMU_OFFSET_XY:
case DMU_TANGENT_X:
case DMU_TANGENT_Y:
case DMU_TANGENT_Z:
case DMU_TANGENT_XYZ:
case DMU_BITANGENT_X:
case DMU_BITANGENT_Y:
case DMU_BITANGENT_Z:
case DMU_BITANGENT_XYZ:
case DMU_NORMAL_X:
case DMU_NORMAL_Y:
case DMU_NORMAL_Z:
case DMU_NORMAL_XYZ:
case DMU_COLOR:
case DMU_COLOR_RED:
case DMU_COLOR_GREEN:
case DMU_COLOR_BLUE:
case DMU_ALPHA:
case DMU_BLENDMODE:
case DMU_FLAGS:
elem = &elem->castTo<Plane>()->surface();
args->type = DMU_SURFACE;
break;
default:
break;
}
}
if(args->type == DMU_SURFACE)
{
updateSurface = elem->castTo<Surface>();
/*
// Resolve implicit references to properties of the surface's material.
switch(args->prop)
{
case UNKNOWN1:
obj = &((Surface*) obj)->material;
args->type = DMU_MATERIAL;
break;
default:
break;
}*/
}
switch(args->type)
{
case DMU_SURFACE:
elem->castTo<Surface>()->setProperty(*args);
break;
case DMU_PLANE:
elem->castTo<Plane>()->setProperty(*args);
break;
case DMU_VERTEX:
elem->castTo<Vertex>()->setProperty(*args);
break;
case DMU_HEDGE: