-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtr_types.pas
More file actions
1687 lines (1475 loc) · 59.3 KB
/
tr_types.pas
File metadata and controls
1687 lines (1475 loc) · 59.3 KB
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
unit tr_types;
{$ifdef fpc}
{$mode delphi}{$H+}
{$packrecords 1}
{$endif}
// TRosettaStone1 http://www.tnlc.com/eep/tr/TRosettaStone.html
// TRosettaStone3 https://opentomb.earvillage.net/OpenTomb/doc/trosettastone.html
interface
const
FILEVERSION_TR1 = $0000020;
const
MATIDX_MUD = 0; // Mud
MATIDX_SNOW = 1; // Snow (TR3 and TR5 only)
MATIDX_SAND = 2; // Sand
MATIDX_GRAVEL = 3; // Gravel
MATIDX_ICE = 4; // Ice (TR3 and TR5 only)
MATIDX_WATER = 5; // Water (unused, as water footstep is only activated in water rooms)
MATIDX_STONE = 6; // Stone (unused, as it is default footstep sound)
MATIDX_WOOD = 7; // Wood
MATIDX_METAL = 8; // Metal
MATIDX_MARBLE = 9; // Marble (TR4 only)
MATIDX_GRASS = 10; // Grass (same sound effect as sand)
MATIDX_CONCRETE = 11; // Concrete (same sound effect as stone, hence unused)
MATIDX_OLDWOOD = 12; // Old wood (same sound effect as wood)
MATIDX_OLDMETAL = 13; // Old metal (same sound effect as metal)
// LightType is somewhat similar to D3D light type, but there are some differences.
// used in tr4_room_light
LIGHTTYPE_SUN = 0;
LIGHTTYPE_LIGHT = 1;
LIGHTTYPE_SPOT = 2;
LIGHTTYPE_SHADOW = 3;
LIGHTTYPE_FOGBULB = 5;
type
uint8 = Byte;
int8 = ShortInt;
uint16 = Word;
int16 = SmallInt;
uint32 = Longword;
int32 = Integer;
pint16 = ^int16;
pint32 = ^int32;
float = single;
tr_colour3 = packed record
r : uint8; { the red component. }
g : uint8; { the green component. }
b : uint8; { the blue component. }
end;
{/ RGBA colour using uint8. For palette etc. }
tr_colour4 = record
case byte of
0:(
r : uint8; { the red component. }
g : uint8; { the green component. }
b : uint8; { the blue component. }
a : uint8; { the alpha component. }
);
1:(clr: tr_colour3; alpha: uint8 )
end;
tr2_colour = tr_colour4;
tr2_colour_s = tr2_colour;
tr2_colour_t = tr2_colour_s;
{/ RGBA colour using float. For single colours. }
tr5_colour = record
r : float; { the red component. }
g : float; { the green component. }
b : float; { the blue component. }
a : float; { the alpha component. }
end;
tr5_colour_s = tr5_colour;
tr5_colour_t = tr5_colour_s;
{ Vertex structure - this is how vertices are specified, using relative coordinates.
They are generally formed into lists, such that other entities (such as quads or triangles)
can refer to them by simply using their index in the list. }
tr1_vertex = record
x : int16;
y : int16;
z : int16;
end;
ptr1_vertex = ^tr1_vertex;
tr2_vertex = tr1_vertex;
tr1_vertexarray = array [word] of tr1_vertex;
ptr1_vertexarray = ^tr1_vertexarray;
{ A vertex with x, y and z coordinates. }
tr5_vertex = record
x : float;
y : float;
z : float;
end;
tr5_vertex_s = tr5_vertex;
tr5_vertex_t = tr5_vertex_s;
tr1_face4 = packed record
Verticies : array [0..3] of uint16;
Texture : uint16;
end;
ptr1_face4 = ^tr1_face4;
tr1_face4array = array [Word] of tr1_face4;
ptr1_face4array = ^tr1_face4array;
tr2_face4 = tr1_face4;
tr1_face3 = packed record
Verticies : array [0..2] of uint16;
Texture : uint16;
end;
ptr1_face3 = ^tr1_face3;
tr1_face3array = array [Word] of tr1_face3;
ptr1_face3array = ^tr1_face3array;
tr2_face3 = tr1_face3;
{ Definition for a triangle. }
tr4_face3 = record
vertices : array[0..2] of uint16; { index into the appropriate list of vertices. }
texture : uint16; { object-texture index or colour index.
* If the triangle is textured, then this is an index into the object-texture list.
* If it's not textured, then the low 8 bit contain the index into the 256 colour palette
* and from TR2 on the high 8 bit contain the index into the 16 bit palette.
}
lighting : uint16; { transparency flag & strength of the hilight (TR4-TR5).
* bit0 if set, then alpha channel = intensity (see attribute in tr2_object_texture).<br>
* bit1-7 is the strength of the hilight.
}
end;
tr4_face3_s = tr4_face3;
tr4_face3_t = tr4_face3_s;
{ Definition for a rectangle. }
tr4_face4 = record
vertices : array[0..3] of uint16; { index into the appropriate list of vertices. }
texture : uint16; { object-texture index or colour index.
* If the rectangle is textured, then this is an index into the object-texture list.
* If it's not textured, then the low 8 bit contain the index into the 256 colour palette
* and from TR2 on the high 8 bit contain the index into the 16 bit palette.
}
lighting : uint16; { transparency flag & strength of the hilight (TR4-TR5).
*
* In TR4, objects can exhibit some kind of light reflection when seen from some particular angles.
* - bit0 if set, then alpha channel = intensity (see attribute in tr2_object_texture).
* - bit1-7 is the strength of the hilight.
}
end;
tr4_face4_s = tr4_face4;
tr4_face4_t = tr4_face4_s;
{* 8-bit texture.
*
* Each pixel is an index into the colour palette.
}
tr_textile8 = record
case byte of
0: (pixels : array[0..255] of array[0..255] of uint8);
0: (raw : array[0..256*256-1] of uint8);
end;
tr_textile8_s = tr_textile8;
tr_textile8_t = tr_textile8;
tr1_textile = tr_textile8;
{* 16-bit texture.
*
* Each pixel is a colour with the following format.<br>
* - 1-bit transparency (0 ::= transparent, 1 ::= opaque) (0x8000)
* - 5-bit red channel (0x7c00)
* - 5-bit green channel (0x03e0)
* - 5-bit blue channel (0x001f)
}
tr2_textile16 = record
Tile : array [0..256*256-1] of uint16;
//pixels : array[0..255] of array[0..255] of uint16;
end;
tr2_textile16_s = tr2_textile16;
tr2_textile16_t = tr2_textile16_s;
{* 32-bit texture.
*
* Each pixel is an ABGR value.
}
tr4_textile32 = record
//pixels : array[0..255] of array[0..255] of uint32;
Tile : array [0..256*256-1] of uint32;
end;
tr4_textile32_s = tr4_textile32;
tr4_textile32_t = tr4_textile32_s;
{* Room Info *}
tr1_room_info = record // 16 bytes
x : int32; // X-offset of room (world coordinates)
z : int32; // Z-offset of room (world coordinates)
yBottom : int32; // (actually largest value, but indicates lowest point in room)
yTop : int32; // (actually smallest value, but indicates highest point in room)
end;
ptr1_room_info = ^tr1_room_info;
tr2_room_info = tr1_room_info;
ptr2_room_info = ^tr2_room_info;
tr5_room_info = record // 16 bytes
x : int32; // X-offset of room (world coordinates)
y : int32; // Y-offset of room (world coordinates)
z : int32; // Z-offset of room (world coordinates)
yBottom : int32; // (actually largest value, but indicates lowest point in room)
yTop : int32; // (actually smallest value, but indicates highest point in room)
end;
ptr5_room_info = ^tr5_room_info;
{* Room portal. }
tr1_room_portal = record
adjoining_room : uint16; {* which room this portal leads to. }
normal : tr1_vertex; {* which way the portal faces.
* the normal points away from the adjacent room.
* to be seen through, it must point toward the viewpoint.
}
vertices : array[0..3] of tr1_vertex; {* the corners of this portal.
* the right-hand rule applies with respect to the normal.
* if the right-hand-rule is not followed, the portal will
* contain visual artifacts instead of a viewport to
* AdjoiningRoom.
}
end;
ptr1_room_portal = tr1_room_portal;
tr1_room_door = tr1_room_portal;
tr5_room_portal = record
adjoining_room : uint16; { which room this portal leads to. }
normal : tr5_vertex_t; {* which way the portal faces.
* the normal points away from the adjacent room.
* to be seen through, it must point toward the viewpoint.
}
vertices : array[0..3] of tr5_vertex; {* the corners of this portal.
* the right-hand rule applies with respect to the normal.
* if the right-hand-rule is not followed, the portal will
* contain visual artifacts instead of a viewport to
* AdjoiningRoom.
}
end;
// aliases
tr5_room_portal_s = tr5_room_portal;
tr5_room_portal_t = tr5_room_portal_s;
{* Room sector. }
tr_room_sector = record
fd_index : uint16; { Index into FloorData[] }
box_index : uint16; { Index into Boxes[]/Zones[] (-1 if none) }
room_below : uint8; { The number of the room below this one (-1 or 255 if none) }
floor : int8; { Absolute height of floor (multiply by 256 for world coordinates) }
room_above : uint8; { The number of the room above this one (-1 or 255 if none) }
ceiling : int8; { Absolute height of ceiling (multiply by 256 for world coordinates) }
end;
tr_room_sector_s = tr_room_sector;
tr_room_sector_t = tr_room_sector_s;
tr1_room_sector = tr_room_sector;
{* Room light. }
tr1_room_light = packed record // 18 bytes
x : int32; // X-position of light, in world coordinates
y : int32; // Y-position of light, in world coordinates
z : int32; // Z-position of light, in world coordinates
Intensity1 : uint16; // Light intensity
Fade1 : uint32; // Falloff value 1
end;
tr2_room_light = record // 24 bytes [TR1: 18 bytes]
x : int32; // X-position of light, in world coordinates
y : int32; // Y-position of light, in world coordinates
z : int32; // Z-position of light, in world coordinates
Intensity1 : uint16; // Light intensity
Intensity2 : uint16; // Almost always equal to Intensity1 [absent from TR1 data files]
Fade1 : uint32; // Falloff value 1
Fade2 : uint32; // Falloff value 2 [absent from TR1 data files]
end;
tr3_room_light = record
x,y,z : int32; // Position of light, in world coordinates
color : tr_colour4; // Colour of the light
intensity : uint32;
fade : uint32; // Falloff value
end;
tr4_room_light = record // 46 bytes
x, y, z : int32; // Position of light, in world coordinates
Colour : tr_colour3; // Colour of the light
LightType : uint8;
Unknown : uint8; // Always 0xFF?
Intensity : uint8;
In_ : float; // Also called hotspot in TRLE manual
Out_ : float; // Also called falloff in TRLE manual
Length : float;
CutOff : float;
dx, dy, dz: float; // Direction - used only by sun and spot lights
end;
tr5_room_light = record
pos : tr5_vertex; { world coords }
color : tr_colour3; { three bytes rgb values }
separtor : uint32;
In_ : float; // Also called hotspot in TRLE manual
Out_ : float; // Also called falloff in TRLE manual
RadIn : float;
RadOut : float;
Range : float;
dir : tr5_vertex; { direction }
pos2 : tr5_vertex; { world coords }
dir2 : tr5_vertex; { direction }
light_type : uint8; { same as D3D (i.e. 2 is for spotlight) }
Filler : array [0..2] of uint8;
end;
tr5_room_light_s = tr5_room_light;
tr5_room_light_t = tr5_room_light_s;
{* Room sprite. }
tr_room_sprite = record
vertex : int16; { offset into vertex list }
texture : int16; { offset into sprite texture list }
end;
tr_room_sprite_s = tr_room_sprite;
tr_room_sprite_t = tr_room_sprite_s;
tr1_room_sprite = tr_room_sprite;
tr2_room_sprite = tr1_room_sprite;
{* Room layer (TR5).
}
{ number of vertices in this layer (4 bytes) }
{ number of rectangles in this layer (2 bytes) }
{ number of triangles in this layer (2 bytes) }
{ The following 6 floats (4 bytes each) define the bounding box for the layer }
tr5_room_layer_s = record
num_vertices : uint16;
unknown_l1 : uint16;
unknown_l2 : uint16;
num_rectangles : uint16;
num_triangles : uint16;
unknown_l3 : uint16;
unknown_l4 : uint16;
bounding_box_x1 : single;
bounding_box_y1 : single;
bounding_box_z1 : single;
bounding_box_x2 : single;
bounding_box_y2 : single;
bounding_box_z2 : single;
unknown_l6a : int16;
unknown_l6b : int16;
unknown_l7a : int16;
unknown_l7b : int16;
unknown_l8a : int16;
unknown_l8b : int16;
end;
tr5_room_layer_t = tr5_room_layer_s;
{* Room vertex.
}
{ where this vertex lies (relative to tr2_room_info::x/z) }
{ A set of flags for special rendering effects [absent from TR1 data files] }
{ 0x8000 something to do with water surface }
{ 0x4000 under water lighting modulation and }
{ movement if viewed from above water surface }
{ 0x2000 water/quicksand surface movement }
{ 0x0010 "normal" }
{ Almost always equal to Lighting1 [absent from TR1 data files] }
{ TR5 --> }
{ vertex color ARGB format (4 bytes) }
tr5_room_vertex_s = record
vertex : tr5_vertex_t;
lighting1 : int16;
attributes : uint16;
lighting2 : int16;
normal : tr5_vertex_t;
colour : tr5_colour_t;
end;
tr5_room_vertex_t = tr5_room_vertex_s;
{* Room staticmesh.
}
{ world coords }
{ high two bits (0xC000) indicate steps of }
{ 90 degrees (e.g. (Rotation >> 14) * 90) }
{ Constant lighting; -1 means use mesh lighting }
{ Like Intensity 1, and almost always the same value [absent from TR1 data files] }
{ which StaticMesh item to draw }
{ extracted from intensity }
tr2_room_staticmesh_s = record
pos : tr5_vertex_t;
rotation : single;
intensity1 : int16;
intensity2 : int16;
object_id : uint16;
tint : tr5_colour_t;
end;
tr2_room_staticmesh_t = tr2_room_staticmesh_s;
{* Room.
}
{/< offset of room (world coordinates). }
{/< indicates lowest point in room. }
{/< indicates highest point in room. }
{ number of layers (pieces) this room (4 bytes) }
{ [NumStaticMeshes]list of static meshes }
{ number of vertices in the following list }
{ [NumVertices] list of vertices (relative coordinates) }
{ number of textured rectangles }
{ [NumRectangles] list of textured rectangles }
{ number of textured triangles }
{ [NumTriangles] list of textured triangles }
{ number of sprites }
{ [NumSprites] list of sprites }
{ number of visibility portals to other rooms }
{ [NumPortals] list of visibility portals }
{ "width" of sector list }
{ "height" of sector list }
{ [NumXsectors * NumZsectors] list of sectors }
{ in this room }
{ This and the next one only affect externally-lit objects }
{ Almost always the same value as AmbientIntensity1 [absent from TR1 data files] }
{ (present only in TR2: 0 is normal, 1 is flickering(?), 2 and 3 are uncertain) }
{ number of point lights in this room }
{ [NumLights] list of point lights }
{ number of static meshes }
{ [NumStaticMeshes]list of static meshes }
{ number of the room that this room can alternate }
{ number of group which is used to switch alternate rooms }
{ with (e.g. empty/filled with water is implemented as an empty room that alternates with a full room) }
{ Flag bits: }
{ 0x0001 - room is filled with water, }
{ 0x0020 - Lara's ponytail gets blown by the wind; }
{ TR1 has only the water flag and the extra unknown flag 0x0100. }
{ TR3 most likely has flags for "is raining", "is snowing", "water is cold", and "is }
{ filled by quicksand", among others. }
{ Water scheme is used with various room options, for example, R and M room flags in TRLE. }
{ Also, it specifies lighting scheme, when 0x4000 vertex attribute is set. }
{ Reverb info is used in TR3-5 and contains index that specifies reverb type. }
{ 0 - Outside, 1 - Small room, 2 - Medium room, 3 - Large room, 4 - Pipe. }
{ Present in TR4 and TR5 only }
{ TR5 only: }
tr5_room_s = record
offset : tr5_vertex_t;
y_bottom : single;
y_top : single;
num_layers : uint32;
layers : ^tr5_room_layer_t;
num_vertices : uint32;
vertices : ^tr5_room_vertex_t;
num_rectangles : uint32;
rectangles : ^tr4_face4_t;
num_triangles : uint32;
triangles : ^tr4_face3_t;
num_sprites : uint32;
sprites : ^tr_room_sprite_t;
num_portals : uint16;
portals : ^tr5_room_portal_t;
num_zsectors : uint16;
num_xsectors : uint16;
sector_list : ^tr_room_sector_t;
intensity1 : int16;
intensity2 : int16;
light_mode : int16;
num_lights : uint16;
lights : ^tr5_room_light_t;
num_static_meshes : uint16;
static_meshes : ^tr2_room_staticmesh_t;
alternate_room : int16;
alternate_group : int8;
flags : uint16;
water_scheme : uint8;
reverb_info : uint8;
light_colour : tr5_colour_t;
room_x : single;
room_z : single;
room_y_bottom : single;
room_y_top : single;
unknown_r1 : uint32;
unknown_r2 : uint32;
unknown_r3 : uint32;
unknown_r4a : uint16;
unknown_r4b : uint16;
unknown_r5 : uint32;
unknown_r6 : uint32;
end;
tr5_room_t = tr5_room_s;
{* Mesh.
}
{ This is usually close to the mesh's centroid, and appears to be the center of a sphere used for collision testing. }
{ This appears to be the radius of that aforementioned collisional sphere. }
{ number of vertices in this mesh }
{[NumVertices]; // list of vertices (relative coordinates) }
{ If positive, number of normals in this mesh. }
{ If negative, number of vertex lighting elements (* (-1)) }
{ Engine internal for above }
{[NumNormals]; // list of normals (if NumNormals is positive) }
{[-NumNormals]; // list of light values (if NumNormals is negative) }
{ number of textured rectangles in this mesh }
{[NumTexturedRectangles]; // list of textured rectangles }
{ number of textured triangles in this mesh }
{[NumTexturedTriangles]; // list of textured triangles }
{ the rest is not present in TR4 }
{ number of coloured rectangles in this mesh }
{[NumColouredRectangles]; // list of coloured rectangles }
{ number of coloured triangles in this mesh }
{[NumColouredTriangles]; // list of coloured triangles }
tr4_mesh_s = record
centre : tr5_vertex_t;
collision_size : int32;
num_vertices : int16;
vertices_count : uint32;
vertices : ^tr5_vertex_t;
num_normals : int16;
num_lights : int16;
normals : ^tr5_vertex_t;
lights : ^int16;
num_textured_rectangles : int16;
textured_rectangles : ^tr4_face4_t;
num_textured_triangles : int16;
textured_triangles : ^tr4_face3_t;
num_coloured_rectangles : int16;
coloured_rectangles : ^tr4_face4_t;
num_coloured_triangles : int16;
coloured_triangles : ^tr4_face3_t;
end;
tr4_mesh_t = tr4_mesh_s;
{* Staticmesh. }
tr_staticmesh = record { 32 bytes }
object_id : uint32; { Object Identifier (matched in Items[]) }
mesh : uint16; { mesh (offset into MeshPointers[]) }
visibility_box : array[0..1] of tr5_vertex; { Meaning uncertain; it is usually 2, and is 3 for objects Lara can travel through, }
collision_box : array[0..1] of tr5_vertex;
flags : uint16; { like TR2's skeletons and underwater vegetation }
end;
tr_staticmesh_s = tr_staticmesh;
tr_staticmesh_t = tr_staticmesh_s;
{* MeshTree.
*
* MeshTree[] is actually groups of four bit32s. The first one is a
* "flags" word;
* bit 1 (0x0002) indicates "put the parent mesh on the mesh stack";
* bit 0 (0x0001) indicates "take the top mesh off of the mesh stack and use as the parent mesh"
* when set, otherwise "use the previous mesh are the parent mesh".
* When both are present, the bit-0 operation is always done before the bit-1 operation; in effect, read the stack but do not change it.
* The next three bit32s are X, Y, Z offsets of the mesh's origin from the parent mesh's origin.
}
tr5_meshtree = record { 4 bytes }
flags : uint32;
offset : tr5_vertex_t;
end;
tr5_meshtree_s = tr5_meshtree;
tr5_meshtree_t = tr5_meshtree_s;
{* Frame.
*
* Frames indicates how composite meshes are positioned and rotated.
* They work in conjunction with Animations[] and Bone2[].
*
* A given frame has the following format:
* short BB1x, BB1y, BB1z // bounding box (low)
* short BB2x, BB2y, BB2z // bounding box (high)
* short OffsetX, OffsetY, OffsetZ // starting offset for this moveable
* (TR1 ONLY: short NumValues // number of angle sets to follow)
* (TR2/3: NumValues is implicitly NumMeshes (from moveable))
*
* What follows next is a list of angle sets. In TR2/3, an angle set can
* specify either one or three axes of rotation. If either of the high two
* bits (0xc000) of the first angle unsigned short are set, it's one axis:
* only one unsigned short,
* low 10 bits (0x03ff),
* scale is 0x100 == 90 degrees;
* the high two bits are interpreted as follows:
* 0x4000 == X only, 0x8000 == Y only,
* 0xC000 == Z only.
*
* If neither of the high bits are set, it's a three-axis rotation. The next
* 10 bits (0x3ff0) are the X rotation, the next 10 (including the following
* unsigned short) (0x000f, 0xfc00) are the Y rotation,
* the next 10 (0x03ff) are the Z rotation, same scale as
* before (0x100 == 90 degrees).
*
* Rotations are performed in Y, X, Z order.
* TR1 ONLY: All angle sets are two words and interpreted like the two-word
* sets in TR2/3, EXCEPT that the word order is reversed.
*
}
{typedef struct tr_frame_s
tr5_vertex_t bbox_low;
tr5_vertex_t bbox_high;
tr5_vertex_t offset;
tr5_vertex_array_t rotations;
int32 byte_offset;
tr_frame_t;
typedef prtl::array < tr_frame_t > tr_frame_array_t; }
{* Moveable.
}
tr_moveable_s = record { 18 bytes }
object_id : uint32; { Item Identifier (matched in Items[]) }
num_meshes : uint16; { number of meshes in this object }
starting_mesh : uint16; { stating mesh (offset into MeshPointers[]) }
mesh_tree_index : uint32; { offset into MeshTree[] }
frame_offset : uint32; { byte offset into Frames[] (divide by 2 for Frames[i]) }
frame_index : uint32;
animation_index : uint16; { offset into Animations[] }
end;
tr_moveable_t = tr_moveable_s;
{* Item.
}
{ 24 bytes [TR1: 22 bytes] }
{ Object Identifier (matched in Moveables[], or SpriteSequences[], as appropriate) }
{ which room contains this item }
{ world coords }
{ ((0xc000 >> 14) * 90) degrees }
{ (constant lighting; -1 means use mesh lighting) }
{ Like Intensity1, and almost always with the same value. [absent from TR1 data files] }
{ Object code bit - used for altering entity behaviour. Only in TR4-5. }
{ 0x0100 indicates "initially invisible", 0x3e00 is Activation Mask }
{ 0x3e00 indicates "open" or "activated"; these can be XORed with }
{ related FloorData::FDlist fields (e.g. for switches) }
tr2_item_s = record
object_id : int16;
room : int16;
pos : tr5_vertex_t;
rotation : single;
intensity1 : int16;
intensity2 : int16;
ocb : int16;
flags : uint16;
end;
tr2_item_t = tr2_item_s;
{* Sprite texture. }
tr_sprite_texture = packed record
tile : uint16;
x0 : int16;
y0 : int16;
x1 : int16;
y1 : int16;
left_side : int16;
top_side : int16;
right_side : int16;
bottom_side : int16;
end;
tr_sprite_texture_s = tr_sprite_texture;
tr_sprite_texture_t = tr_sprite_texture_s;
tr1_sprite_texture = packed record { 16 bytes }
tile : uint16;
x : int8;
y : int8;
width : int16; // actually (Width * 256) + 255
height : int16; // actually (Height * 256) + 255
left_side : int16;
top_side : int16;
right_side : int16;
bottom_side : int16;
end;
{* Sprite sequence. }
tr_sprite_sequence = record { 8 bytes }
object_id : int32; { Item identifier (matched in Items[]) }
length : int16; { negative of "how many sprites are in this sequence" }
offset : int16; { where (in sprite texture list) this sequence starts }
end;
tr_sprite_sequence_s = tr_sprite_sequence;
tr_sprite_sequence_t = tr_sprite_sequence_s;
tr1_sprite_sequence = tr_sprite_sequence;
{* Animation.
*
* This describes each individual animation; these may be looped by specifying
* the next animation to be itself. In TR2 and TR3, one must be careful when
* parsing frames using the FrameSize value as the size of each frame, since
* an animation's frame range may extend into the next animation's frame range,
* and that may have a different FrameSize value.
}
tr_animation = record { 32 bytes TR1/2/3 40 bytes TR4 }
frame_offset : uint32; { byte offset into Frames[] (divide by 2 for Frames[i]) }
frame_rate : uint8; { Engine ticks per frame }
frame_size : uint8; { number of int16's in Frames[] used by this animation }
state_id : uint16; { new in TR4 --> }
speed : single; { lateral speed and acceleration. }
accel : single;
speed_lateral : single;
accel_lateral : single;
frame_start : uint16; { first frame in this animation }
frame_end : uint16; { last frame in this animation (numframes = (End - Start) + 1) }
next_animation : uint16;
next_frame : uint16;
num_state_changes : uint16;
state_change_offset : uint16; { offset into StateChanges[] }
num_anim_commands : uint16; { How many of them to use. }
anim_command : uint16; { offset into AnimCommand[] }
end;
tr1_animation = packed record { 32 bytes TR1/2/3 40 bytes TR4 }
frame_offset : uint32; { byte offset into Frames[] (divide by 2 for Frames[i]) }
frame_rate : uint8; { Engine ticks per frame }
frame_size : uint8; { number of int16's in Frames[] used by this animation }
state_id : uint16;
unk : array [0..7] of uint8;
frame_start : uint16; { first frame in this animation }
frame_end : uint16; { last frame in this animation (numframes = (End - Start) + 1) }
next_animation : uint16;
next_frame : uint16;
num_state_changes : uint16;
state_change_offset : uint16; { offset into StateChanges[] }
num_anim_commands : uint16; { How many of them to use. }
anim_command : uint16; { offset into AnimCommand[] }
end;
tr2_animation = tr1_animation;
tr_animation_s = tr_animation;
tr_animation_t = tr_animation_s;
{* State Change.
*
* Each one contains the state to change to and which animation dispatches
* to use; there may be more than one, with each separate one covering a different
* range of frames.
}
tr_state_change = record { 6 bytes }
state_id : uint16;
num_anim_dispatches : uint16; { number of ranges (seems to always be 1..5) }
anim_dispatch : uint16; { Offset into AnimDispatches[] }
end;
tr_state_change_s = tr_state_change;
tr_state_change_t = tr_state_change_s;
{* Animation Dispatch.
*
* This specifies the next animation and frame to use; these are associated
* with some range of frames. This makes possible such specificity as one
* animation for left foot forward and another animation for right foot forward.
}
tr_anim_dispatch = record { 8 bytes }
low : int16; { Lowest frame that uses this range }
high : int16; { Highest frame (+1?) that uses this range }
next_animation : int16; { Animation to dispatch to }
next_frame : int16; { Frame offset to dispatch to }
end;
tr_anim_dispatch_s = tr_anim_dispatch;
tr_anim_dispatch_t = tr_anim_dispatch_s;
tr_anim_command = int16;
{* Animation Command.
*
* These are various commands associated with each animation; they are
* called "Bone1" in some documentation. They are varying numbers of int16's
* packed into an array; the first of each set is the opcode, which determines
* how operand int16's follow it. Some of them refer to the whole animation
* (jump and grab points, etc.), while others of them are associated with
* specific frames (sound, bubbles, etc.).
}
{typedef struct // 2 bytes }
{ int16 value; }
{ tr_anim_command_t; }
{* Box. }
tr_box = packed record { 8 bytes [TR1: 20 bytes] In TR1, the first four are int32's instead of uint8's, and are not scaled. }
zmin : uint32; { sectors (* 1024 units) }
zmax : uint32;
xmin : uint32;
xmax : uint32;
true_floor : int16; { Y value (no scaling) }
overlap_index : int16; { index into Overlaps[]. The high bit is sometimes set; this }
{ occurs in front of swinging doors and the like. }
end;
tr_box_s = tr_box;
tr_box_t = tr_box_s;
tr1_box = tr_box;
{* SoundSource.
*
* This structure contains the details of continuous-sound sources. Although
* a SoundSource object has a position, it has no room membership; the sound
* seems to propagate omnidirectionally for about 10 horizontal-grid sizes
* without regard for the presence of walls.
}
tr_sound_source = packed record
x : int32; { absolute X position of sound source (world coordinates) }
y : int32; { absolute Y position of sound source (world coordinates) }
z : int32; { absolute Z position of sound source (world coordinates) }
sound_id : uint16; { internal sound index }
flags : uint16; { 0x40, 0x80, or 0xc0 }
end;
tr_sound_source_s = tr_sound_source;
tr_sound_source_t = tr_sound_source_s;
tr1_sound_source = tr_sound_source;
{* SoundDetails.
*
* SoundDetails (also called SampleInfos in native TR sources) are properties
* for each sound index from SoundMap. It contains all crucial information
* that is needed to play certain sample, except offset to raw wave buffer,
* which is unnecessary, as it is managed internally by DirectSound.
}
{ 8 bytes }
{ Index into SampleIndices -- NOT USED IN TR4-5!!! }
{ Global sample value }
{ Sound range }
{ Chance to play }
{ Pitch shift }
{ Bits 0-1: Looped flag, bits 2-5: num samples, bits 6-7: UNUSED }
{ Bit 4: UNKNOWN, bit 5: Randomize pitch, bit 6: randomize volume }
{ All other bits in flags_2 are unused. }
tr_sound_details_s = record
sample : uint16;
volume : uint16;
sound_range : uint16;
chance : uint16;
pitch : int16;
num_samples_and_flags_1 : uint8;
flags_2 : uint8;
end;
tr_sound_details_t = tr_sound_details_s;
{* Object Texture Vertex.
*
* It specifies a vertex location in textile coordinates.
* The Xpixel and Ypixel are the actual coordinates of the vertex's pixel.
* The Xcoordinate and Ycoordinate values depend on where the other vertices
* are in the object texture. And if the object texture is used to specify
* a triangle, then the fourth vertex's values will all be zero.
}
{ 4 bytes }
{ 1 if Xpixel is the low value, -1 if Xpixel is the high value in the object texture }
{ 1 if Ypixel is the low value, -1 if Ypixel is the high value in the object texture }
tr4_object_texture_vert_s = record
xcoordinate : int8;
xpixel : uint8;
ycoordinate : int8;
ypixel : uint8;
end;
tr4_object_texture_vert_t = tr4_object_texture_vert_s;
{* Object Texture.
*
* These, thee contents of ObjectTextures[], are used for specifying texture
* mapping for the world geometry and for mesh objects.
}
{ 38 bytes TR4 - 20 in TR1/2/3 }
{ 0 means that a texture is all-opaque, and that transparency }
{ information is ignored. }
{ 1 means that transparency information is used. In 8-bit colour, }
{ index 0 is the transparent colour, while in 16-bit colour, the }
{ top bit (0x8000) is the alpha channel (1 = opaque, 0 = transparent). }
{ 2 (only in TR3) means that the opacity (alpha) is equal to the intensity; }
{ the brighter the colour, the more opaque it is. The intensity is probably calculated }
{ as the maximum of the individual color values. }
{ index into textile list }
{ TR4 }
{ the four corners of the texture }
{ TR4 }
{ TR4 }
{ TR4 }
{ TR4 }
tr4_object_texture_s = record
transparency_flags : uint16;
tile_and_flag : uint16;
flags : uint16;
vertices : array[0..3] of tr4_object_texture_vert_t;
unknown1 : uint32;
unknown2 : uint32;
x_size : uint32;
y_size : uint32;
end;
tr4_object_texture_t = tr4_object_texture_s;
{* Animated Textures.
}
{int16 num_texture_ids; // Actually, this is the number of texture ID's - 1. }
{[NumTextureIDs + 1]; // offsets into ObjectTextures[], in animation order. }
tr_animated_textures_s = record
texture_ids_count : int16;
texture_ids : ^int16;
end;
tr_animated_textures_t = tr_animated_textures_s;
{[NumAnimatedTextures]; }
{* Camera.
}
{ correlates to Boxes[]? Zones[]? }
tr_camera = record
x : int32;
y : int32;
z : int32;
room : int16;
unknown1 : uint16;
end;
tr_camera_s = tr_camera;
tr_camera_t = tr_camera_s;
tr1_camera = tr_camera;
{* Extra Camera.
}
tr4_flyby_camera_s = record
pos_x : int32;
pos_y : int32;
pos_z : int32;
target_x : int32;
target_y : int32;
target_z : int32;
sequence : uint8;
index : uint8;
fov : uint16;
roll : uint16;
timer : uint16;
speed : uint16;
flags : uint16;
room_id : int32;
end;
tr4_flyby_camera_t = tr4_flyby_camera_s;
{* AI Object.
}
{ the objectID from the AI object (AI_FOLLOW is 402) }
{ The trigger flags (button 1-5, first button has value 2) }
tr4_ai_object_s = record
object_id : uint16;
room : uint16;
x : int32;
y : int32;
z : int32;
ocb : uint16;
flags : uint16;
angle : int32;
end;
tr4_ai_object_t = tr4_ai_object_s;
{* Cinematic Frame. }
tr_cinematic_frame = packed record
targetx : int16; {Camera look at position }
targety : int16;
targetz : int16;
posx : int16; {Camera position }
posy : int16;
posz : int16;
fov : int16;
roll : int16;
end;
tr_cinematic_frame_s = tr_cinematic_frame;
tr_cinematic_frame_t = tr_cinematic_frame_s;
tr1_cinematic_frame = tr_cinematic_frame;
{* Lightmap. }
tr_lightmap_s = record
map : array[0..(32*256)-1] of uint8;
end;
tr_lightmap_t = tr_lightmap_s;
{* Palette. }
tr2_palette = record
colour : array[0..255] of tr2_colour_t;
end;
tr2_palette_s = tr2_palette;
tr2_palette_t = tr2_palette_s;