Repository navigation
Expand file tree
/
Copy pathcamera.zig
More file actions
2553 lines (2343 loc) · 134 KB
/
Copy pathcamera.zig
File metadata and controls
2553 lines (2343 loc) · 134 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
//! `C:\lancer\game\camera.cpp`: the views and where each puts the camera. `camera_set_view`
//! (`0x0045F1B0`) switches view, `camera_frame` (`0x0045FC90`) places the camera once a frame, and
//! `frame_controls` (`0x00414060`) picks views and steers the orbiting ones from the keyboard. The
//! game keeps the view (`Viewing`, `switchView`, `gameFrame`), and the camera shows it (`Camera`).
const std = @import("std");
const math = @import("../surrender/math.zig");
const srapi = @import("../surrender/surrenderlib/srapi.zig");
const input = @import("../input.zig");
const controls = @import("../input/controls.zig");
const Random = @import("../random.zig").Random;
const create = @import("create.zig");
const Order = @import("ai/orders.zig").Order;
const hud = @import("hud.zig");
const gameobj = @import("gameobj.zig");
const missiles = @import("missiles.zig");
const launch = @import("launch.zig");
const yamato_launch = @import("launch/yamato.zig");
const table = @import("table.zig");
const wgate = @import("wgate.zig");
const Vector = math.Vector;
/// The view table, which [`camera/views.zig`](camera/views.zig) transcribes.
pub const views = @import("camera/views.zig");
/// The director's shots, which the director's view shows.
pub const shots = @import("camera/shots.zig");
const director = @import("executor/director.zig");
const Matrix = math.Matrix;
test {
std.testing.refAllDecls(@This());
}
/// Where the camera is and which way it looks.
pub const Place = math.Place;
// --- Projection ---------------------------------------------------------------------------------
/// The factors every view but `View.launch_bay` projects with (`sr_set_projection`): the screen
/// spans 5/6 of a view unit either side of the middle across and 5/8 up and down, square on a 4:3
/// screen: about 80 degrees across and 64 down.
pub const factors = [2]f32{ 0.6, 0.8 };
/// `View.launch_bay` projects wider, about 110 degrees across, over the whole screen.
pub const wide_factors = [2]f32{ 0.35, 0.467 };
/// The tenth of a pixel `sr_set_projection` takes off the screen's size before it scales it
/// (`0x004DC420`, `srapi.Projection.init`), which `unstretched` takes off likewise so that its
/// pixels come out square.
const projection_trim: f32 = 0.1;
/// The cinematic views' bars: the viewport leaves out this much of the screen at the top and the
/// bottom once they have slid in (`camera_frame`, `0x004DC420`).
pub const letterbox: f32 = 0.1;
/// OpenReliant's factors for a screen of any shape: the game's down, and across whatever keeps
/// pixels square. **Improvement:** the game uses its factors on every screen, which stretches the
/// picture on any but a 4:3 one; OpenReliant shows more at the sides instead. On a 4:3 screen the
/// factors are the game's to within a thousandth of a percent.
pub fn unstretched(width: u32, height: u32, base: [2]f32) [2]f32 {
const w: f32 = @floatFromInt(width);
const h: f32 = @floatFromInt(height);
return .{ base[1] * (h - projection_trim) / (w - projection_trim), base[1] };
}
/// How far `factors` see up and down, in degrees: the screen spans 5/8 of a view unit either side
/// of the middle, which is about 64 degrees.
pub const original_field_of_view: f32 = 2 * std.math.radiansToDegrees(std.math.atan(0.5 / factors[1]));
/// The narrowest and the widest field of view the settings screen's FIELD OF VIEW offers, in
/// degrees up and down, the game's in the middle.
pub const least_field_of_view: f32 = 34;
pub const most_field_of_view: f32 = 94;
/// The factors that see `degrees` up and down, in the game's shape: `factors` at
/// `original_field_of_view`.
///
/// **Improvement:** the settings screen's FIELD OF VIEW sets how far the views the player flies in
/// see (`Camera.projection`). The game always projects them with `factors`.
pub fn factorsFor(degrees: f32) [2]f32 {
const down = 0.5 / @tan(std.math.degreesToRadians(degrees) / 2);
return .{ down * factors[0] / factors[1], down };
}
// --- Views --------------------------------------------------------------------------------------
/// A view, numbered as the game numbers them (`camera_view`, `0x00539A34`). The numbers not named
/// here are the game's cutaways: launches, landings, jumps, deaths and the like.
pub const View = enum(u8) {
/// From the cockpit, ahead; `CockpitMode` says which of three ways.
cockpit = 0,
cockpit_left = 1,
cockpit_right = 2,
cockpit_rear = 3,
/// Behind and above an object, lagging its turns.
chase = 4,
/// The spectator's view: the chase view under a number of its own, in which the player's
/// missile lock doesn't build. Once the player is out of a network game, the camera watches
/// the other players' ships in it, in turn (`camera_watch_next_player`, `0x004775D0`).
spectator = 0x1E,
/// The first of a launch's three cutaways (`launch_reliant_run`), from inside the carrier's
/// bay beside the ship, which projects wider than the rest (`wide_factors`) and tilts down
/// after the ship as it drops out.
launch_bay = 0x20,
/// The second: from far below the ship, looking up at it as it drops out.
launch_below = 0x21,
/// The third: from beside and below the carrier, which the view shows whole, looking at the
/// ship as it drops out.
launch_aside = 0x22,
/// The first of the two views the Reliant's landing picks from at random (`ailand`): from
/// beside the launch tube the ship lands in, within the carrier's hull, looking at the
/// player's ship as it comes in through the tube's upper door and sinks.
landing_tube = 0x23,
/// The second: from above the carrier, aside and behind the tube, watching the ship.
landing_aside = 0x26,
/// The player's Jump Out ([jumps](../../../docs/engine/jump.md)): from out along each of the
/// ship's axes where it began, watching it go.
jump_out = 0x27,
/// The first of three views the player's Jump In picks from at random: from close ahead of the
/// ship and above it, looking back at it as it flies in, pulling away a little and shaking as
/// hits shake the cockpit.
jump_in_close = 0x17,
/// The second: from far ahead, beyond where the ship arrives and below it, held, looking level
/// in the ship's frame at where it came in from.
jump_in_ahead = 0x18,
/// The third: from beside where the ship arrives and above it, watching it fly in.
jump_in_aside = 0x19,
/// Around the player's target, looking at it, steered from the keyboard.
target = 6,
/// Around the player's ship, likewise.
external = 0xC,
/// The director's: the mission's script's shots (`shots`), each flown along the mission's
/// curves or standing at a ship, locked, the ships each holds kept still. A ship keeps its
/// undamaged speed in it (`ai.cruiseSpeed`), the player's engine and afterburner are not heard
/// (`sound3d`), and CLOAK SHIP does nothing (`input.playerWeapons`).
director = 0xD,
/// Behind the camera's object, turning slowly with it and pulling away, as the player's ship is
/// destroyed.
pull_back = 8,
/// Behind a missile.
missile = 0x12,
/// Circling the pilot's pod as the pilot ejects: Eject Camera.
eject = 7,
/// Round the ship picking the pilot's pod up, a Nanny or the enemy's Antanov, closing in.
pickup = 0x1C,
/// From behind the pilot's pod, at the Sabre that shoots it down, pulling back as it bursts.
pod_shot = 0x1D,
/// From where the camera was, watching its object.
watch = 0x1A,
/// From where the camera was, watching where the player's ship burst
/// (`explode.Explosions.marker`).
watch_marker = 0x1B,
/// From a point the player flies past.
flyby = 0x24,
/// Watches the player's ship dock at a Nanny, from beside the Nanny.
nanny_dock = 0x2B,
/// Orbits beside the player while the warp tunnel opens, turned as the ship stood when it lined
/// up for the warp, or as the ship stands while it runs no Warp Out (`playerRunning`).
warp_prepare = 9,
/// Holds the preparation camera as the ship enters its warp.
warp_depart = 10,
/// Watches the ship emerge from its arrival tunnel.
warp_arrive = 11,
/// The first of the two views the Yamato's landing picks from at random (`ailand`): from low in
/// its landing bay, sliding along it as the landing goes on, turned level to face the ship
/// (`landingBay`).
landing_bay = 0x0E,
/// The second: from above the player's ship and behind it, looking down as it rises, then from
/// beside it, looking back at it as the view slides along it (`landingShip`).
landing_ship = 0x25,
/// The Yamato's launch: beside the ship, rising with time and following its position. Until the
/// ship is clear of the bay, and `yamato_look_delay` ticks after, it faces the way the ship
/// does. While the ship runs no Yamato launch, it always looks at the ship (`playerRunning`).
yamato_beside = 0x0F,
/// Far ahead of the ship, held still with a fixed pitch, looking back toward the bay.
yamato_ahead = 0x10,
/// Beside and ahead of the bay, held still and watching the ship fly out.
yamato_aside = 0x11,
_,
/// The view's record in the view table (`0x004F72A8`), or null for a number past it, which
/// `camera_set_view` stops the game for as an invalid camera type.
pub fn record(view: View) ?views.Record {
const n = @backingInt(view);
return if (n < views.records.len) views.records[n] else null;
}
/// Whether the bars slide in: for the cutaways from 7 to `0x27` and `0x2B`, but not the
/// external view.
pub fn letterboxed(view: View) bool {
return if (view.record()) |found| found.bars else false;
}
/// Whether the view is from the cockpit, so the object's own model is not drawn: views 0 to 3.
pub fn fromCockpit(view: View) bool {
return if (view.record()) |found| found.cockpit else false;
}
/// The language string that names the view, which `hud_draw` shows at the top of the screen
/// in every view but the one ahead from the cockpit.
pub fn name(view: View) ?u16 {
return if (view.record()) |found| found.name else null;
}
/// Whether the player's missile lock builds and its rings show while the last frame's view is
/// this one: the cockpit's views and the chase view, views 0 to 4 (`mission_frame`,
/// `0x004933D7`), but not the spectator's view.
pub fn showsLock(view: View) bool {
return switch (view) {
.cockpit, .cockpit_left, .cockpit_right, .cockpit_rear, .chase => true,
else => false,
};
}
/// How far the view turns from ahead, about the object's down axis, in degrees: the cockpit's
/// side and rear views, and no other (`camera_frame`'s table, `0x0045FC9B`).
pub fn cockpitTurn(view: View) f32 {
return switch (view) {
.cockpit_left => -90,
.cockpit_right => 90,
.cockpit_rear => 180,
else => 0,
};
}
};
/// Whether a view puts the camera in its ship's cockpit: one of the views from the cockpit, save
/// the view ahead in the chase mode.
pub fn inCockpit(view: View, mode: CockpitMode) bool {
return view.fromCockpit() and !(view == .cockpit and mode == .chase);
}
/// What the cockpit view shows (`cockpit_mode`, `0x00539A9C`). The cockpit key cycles it while
/// that view is up; the options set it at the start of a mission.
pub const CockpitMode = enum(u2) {
/// From the eye, with no cockpit drawn.
open = 0,
/// From the eye, with the cockpit's model over the view (hardware renderers only).
cockpit = 1,
/// The chase view instead.
chase = 2,
pub fn next(mode: CockpitMode) CockpitMode {
return switch (mode) {
.open => .cockpit,
.cockpit => .chase,
.chase => .open,
};
}
};
/// The options' cockpit setting (`cockpit_mode_setting`, `0x005D5A78`), which the game keeps in
/// its ini as `[Device] View`, 0 when the ini has none.
pub const CockpitSetting = enum(u32) {
cockpit = 0,
chase = 1,
none = 2,
_,
/// The cockpit mode a mission's launch ends in (`launch_reliant_run`, `0x0041B240`), as it switches
/// the camera from the launch's cutaway to view 0: the cockpit's model for 0, the chase view
/// for 1, and no cockpit for any other.
pub fn mode(setting: CockpitSetting) CockpitMode {
return switch (setting) {
.cockpit => .cockpit,
.chase => .chase,
else => .open,
};
}
};
/// The camera keys, in the order `frame_controls` reads them.
pub const camera_actions = [_]controls.Action{
.cockpit_camera, .left_view_camera, .right_view_camera, .rear_view_camera,
.flyby_camera, .target_camera, .external_camera, .missile_camera,
};
/// The view the joystick's hat switches to (`frame_controls`) for each of its four straight
/// directions, given in DirectInput's hundredths of a degree clockwise from forward: the cockpit's
/// front, right, rear or left view. Diagonals and the center select nothing.
pub fn hatView(pov: u32) ?View {
return switch (pov) {
0 => .cockpit,
9000 => .cockpit_right,
18000 => .cockpit_rear,
27000 => .cockpit_left,
else => null,
};
}
/// The view a camera key picks (`frame_controls`), or null for another action. The cockpit key
/// picks the cockpit view, and, pressed in it, cycles the cockpit mode.
pub fn keyView(action: controls.Action) ?View {
return switch (action) {
.cockpit_camera => .cockpit,
.left_view_camera => .cockpit_left,
.right_view_camera => .cockpit_right,
.rear_view_camera => .cockpit_rear,
.flyby_camera => .flyby,
.target_camera => .target,
.external_camera => .external,
.missile_camera => .missile,
else => null,
};
}
// --- The camera ---------------------------------------------------------------------------------
/// What a view reads of an object.
pub const Subject = struct {
position: Vector,
orientation: Matrix,
/// The model header's eye point.
eye: Vector = @splat(0),
/// `GameObject.radius`: its farthest vertex from its origin.
radius: f32 = 0,
motion: Chase.Motion = .{},
/// Whether it is exploding, which the pod-shot view waits for.
exploding: bool = false,
/// Where it stands and how it is turned.
pub fn place(subject: Subject) Place {
return .{ .position = subject.position, .orientation = subject.orientation };
}
/// What the camera follows of the object in `slot`: where its root's frame has it drawn, its
/// model's eye point and its size, and for the chase view its type, its throttle and its rates
/// of turn.
pub fn of(slot: *const create.Slot) Subject {
const live = &slot.object;
return .{
.position = slot.drawn.position,
.orientation = slot.drawn.orientation,
.eye = if (slot.type) |loaded| loaded.model.header.eye.vector() else @splat(0),
.radius = live.radius,
// The chase view sits farther back the more throttle the ship carries and swings
// against its rates of turn, so it lags a turn rather than riding rigidly behind the
// ship.
.motion = .{
.ship_type = live.type,
.throttle = live.throttle,
.afterburner = live.afterburner,
.pitch_rate = live.pitch_rate,
.yaw_rate = live.yaw_rate,
.roll_rate = live.roll_rate,
},
.exploding = live.flags.exploding,
};
}
};
/// What `Camera.frame` reads of the world.
pub const World = struct {
/// The object the view shows, `Camera.object`.
object: Subject,
/// The player's ship.
player: Subject,
/// The player's target, when it has one.
target: ?Subject = null,
/// Hundredths of a second since the last frame (`frame_duration`).
ticks: u32,
/// The mission's ticks this frame (`frame_start`), which the views that move with time go by,
/// from when the view was switched to.
now: u32 = 0,
/// How far past `now` the frame is drawn, as a share of a tick (`objects.pastTick`), which
/// those views go on by as well.
///
/// **Improvement:** with smooth motion the views that move with time move on every frame, as
/// the objects they watch do; the game moves them on a tick at a time, which a display's frames
/// fall between unevenly.
ahead: f32 = 0,
/// Where the player's ship burst, for `watch_marker`; null before it has.
marker: ?Vector = null,
/// The cockpit's model and what moves it, for view 0 outside the chase mode; null for an
/// object with no cockpit.
cockpit: ?Cockpit.Input = null,
/// The game's random numbers (`Random`), which the cockpit's jitter and the shake from hits
/// draw on.
random: ?*Random = null,
/// Whether the player's ship has begun to drop out of its carrier's bay, which the bay view
/// tilts down after (`launch.dropping`).
dropping: bool = false,
/// What the landing's views stand by, while the view's object lands (`ailand.seen`).
landing: ?Landing = null,
/// The game's world as the drawn frame sees it (`main.Drawn.world`), through which the
/// director's view flies along the mission's curves and the missile view finds its missile;
/// null where no game runs, as in a test.
game: ?gameobj.World = null,
/// What the game has the camera view (`input.Player.viewing`).
viewing: *const Viewing,
/// The game's shake from hits (`gameobj.World.shake`), as the last game frame left it.
shake: f32 = 0,
/// How long the view has been up at the frame, in ticks: since it was switched to, and on by as
/// much past the tick as the frame is drawn (`ahead`).
fn shown(world: World) f32 {
return @as(f32, @floatFromInt(world.now -| world.viewing.switched)) + world.ahead;
}
};
/// What the landing's views stand by, by the carrier the ship lands on (`ailand.seen`).
pub const Landing = union(enum) {
/// The Reliant's: the middle of its launch tube the ship lands in, which the landing keeps
/// (`ailand.State.tube`), and how the carrier is turned.
reliant: struct { tube: Vector, carrier: Matrix },
/// The Yamato's: where its landing bay stands, the bounds of the bay's hangar as it was drawn
/// last, and the tick the view from the bay slides from (`ailand.State.due`).
yamato: struct { bay: Place, hangar: [2]Vector, due: i32 },
/// OpenReliant's own, a hangar bay's (`ailand.State.gate_place`).
bay: Bay,
/// What a landing in a hangar bay's views stand by: where the launch point of the gate the
/// ship lands at stands and how it is turned, its Z axis the way the ship launches out, and
/// the mouth of the bay, where that way leaves the carrier's bounds.
pub const Bay = struct {
gate: Place,
mouth: Vector,
/// The bay's depth, from the launch point to the mouth.
pub fn depth(bay: Bay) f32 {
return math.distance(bay.gate.position, bay.mouth);
}
};
};
/// What the camera views, which the game keeps in `camera_set_view`'s globals: the view, the object
/// it shows, since when, and whether a script holds it, with the director's shots and the ships
/// they hold, the cockpit mode and the orbit the camera keys steer. The game goes by it as well as
/// the camera: the mission ends once the player's end has been watched long enough
/// (`main.missionOver`), and the ships' cruise speed, the cloak and the missile lock depend on the
/// view. The camera (`Camera`) shows what it says. A world that draws nothing keeps it just the
/// same (`input.Player.viewing`).
///
/// What the original's game work changes in the camera as it switches the view, OpenReliant's
/// game frames record here, and the camera, which drawing keeps, takes it up as it next frames
/// (`changes`, `Camera.notice`). The game keeps the camera's shake too (`gameobj.World.shake`).
pub const Viewing = struct {
view: View = .cockpit,
/// The object the view shows (`camera_object`, `0x00539A8C`).
object: ?u16 = null,
/// Set while a script holds the camera (`0x00539ACC`): the camera keys do nothing.
locked: bool = false,
/// `frame_start` when the view last changed (`0x00539AA4`).
switched: u32 = 0,
/// OpenReliant's: the watch view (`View.watch`) is one that lasts, as `--watch` sets it, rather
/// than the one the player's end switches to, so it doesn't end the mission
/// (`main.missionOver`). Any change of view clears it (`set`).
lasting: bool = false,
/// The view as the last game frame ended (`camera_view_last`, `0x00539A64`), which the missile
/// lock and the display go by.
last: View = .cockpit,
/// The missile the missile view follows (`camera_missile`, `0x00539A94`), and whether it has
/// ended (`0x00539A7C`), after which the view holds still for `missile_linger` ticks and goes
/// back to the cockpit (`gameFrame`).
missile: u8 = 0,
missile_gone: bool = false,
/// The director's shots waiting, the first on screen (`shots.Shots`), and what the director
/// keeps of that one (`director.Director`).
shots: shots.Shots = .{},
director: director.Director = .{},
/// The ships the director's shot on screen holds still (`camera_held_kind`, `0x00539A30`, and
/// `camera_held_index`, `0x00539A40`), and those the first shot waiting holds, as the view
/// takes it (`camera_shot_hold_kind`, `0x00539A5C`, and `camera_shot_hold_index`,
/// `0x00539938`).
held: ?shots.Held = null,
holding: ?shots.Held = null,
/// What the cockpit view shows, which the cockpit key cycles (`key`), and the options' setting
/// that a mission's start and the end of a launch put it back to (`cockpit_mode_setting`,
/// `0x005D5A78`).
cockpit_mode: CockpitMode = .open,
cockpit_setting: CockpitSetting = .cockpit,
/// Where the target and external views go round their object, which the arrow keys steer
/// (`frameControls`).
orbit: Orbit = .{},
/// Set while the joystick's hat is held (`0x0051CF8C`), so that the view returns to the front
/// when it is released.
hat_glancing: bool = false,
/// OpenReliant's: what the game changed of what the camera shows, which the camera takes up as
/// it next frames (`Camera.notice`).
changes: Changes = .{},
/// OpenReliant's: where the camera stood as the last frame was drawn (`Camera.place`), which
/// the driver hands the game as input, like what the player aims at (`hud.State.aim`). The
/// effects that depend on the camera go by it: the particles, fewer behind it, the flames
/// spread across the view, the sparks and the flak only near it, an Uber's bits thrown at it,
/// and the screen's flash near it. Null where nothing is drawn, which leaves them out.
seen_from: ?Place = null,
/// OpenReliant's: how many of the switches of view the drawing side asked for the game has
/// made (`Camera.requests`, `takeUp`).
requests_seen: u32 = 0,
/// What a switch of view goes by: the gates, whose worm the player's ship may be riding, and
/// the missiles in flight, which the missile view follows; null where there are none.
pub const Bounds = struct {
gates: ?*const wgate.Gates = null,
missiles: ?*const missiles.Missiles = null,
/// `world`'s.
pub fn of(world: gameobj.World) Bounds {
return .{ .gates = world.gates, .missiles = &world.objects.missiles };
}
};
/// The game's part of `camera_set_view`: the view's own part (`turn`), then, out of the
/// director's view, the ships its shot held go (`shots.Held.hold`), and into it, the shot's own
/// are held. The camera takes up the switch as it next frames (`Camera.cutTo`).
pub fn set(viewing: *Viewing, view: View, object: ?u16, lock: bool, force: bool, now: u32, by: Bounds) bool {
const cut = viewing.make(view, object, lock, force, now, by) orelse return false;
viewing.changes.add(.{ .cut = cut });
return true;
}
/// `set` without the change for the camera: returns the cut, or null where the switch is
/// refused.
fn make(viewing: *Viewing, view: View, object: ?u16, lock: bool, force: bool, now: u32, by: Bounds) ?Cut {
const leaving: ?shots.Held = if (viewing.view == .director) viewing.held else null;
const cut = viewing.turn(view, object, lock, force, now, by) orelse return null;
if (leaving) |held| held.hold(false);
if (view == .director) if (viewing.held) |held| held.hold(true);
return cut;
}
/// The view's own part of a switch (`set`): switches to `view` at tick `now`, `object` the one
/// it shows, `lock` keeping the camera keys off it. Refused while the player's ship rides the
/// worm between gates, forced or not (`wgate.ridingWorm`, `0x0045F1B0`), and while the camera
/// is locked, unless `force`. The missile view follows the next missile in flight, from the one
/// it last followed, that `object` launched; with none, it is refused. The target and external
/// views start their orbit again. It leaves the ships the director's shots hold as they are,
/// which is how the drawn frame's copy of the view takes a switch (`Camera.ask`). Returns the
/// cut for the camera, or null where the switch is refused.
pub fn turn(viewing: *Viewing, view: View, object: ?u16, lock: bool, force: bool, now: u32, by: Bounds) ?Cut {
if (wgate.ridingWorm(by.gates)) return null;
if (viewing.locked and !force) return null;
if (view == .missile) {
const records = by.missiles orelse return null;
viewing.missile = nextMissile(records, viewing.missile, object orelse return null) orelse return null;
viewing.missile_gone = false;
}
const cut: Cut = .{ .from = viewing.view, .from_object = viewing.object, .view = view, .object = object, .cockpit_mode = viewing.cockpit_mode };
viewing.view = view;
viewing.object = object;
viewing.locked = lock;
viewing.switched = now;
viewing.lasting = false;
if (view == .director) viewing.held = viewing.holding;
if (view == .target or view == .external) viewing.orbit = .{};
return cut;
}
/// OpenReliant's: makes the switches of view the drawing side asked for since the game last
/// took them up (`Camera.requests`), in the order they were asked, as `set` makes the game's
/// own. The game's view then ends up as it would have if drawing had switched it directly.
/// Where the camera cut to a switch as it was asked (`Request.cut_at_once`), `subtarget`
/// follows the switch here (`Camera.Subtarget.follow`), and the camera gets no change to take
/// up. Otherwise the camera takes the switch up as it next frames, as for the game's own.
pub fn takeUp(viewing: *Viewing, requests: *const Requests, by: Bounds, subtarget: ?Camera.Subtarget) void {
var asked = requests.since(viewing.requests_seen);
while (asked.next()) |request| {
const made = if (request.cut_at_once) made: {
const cut = viewing.make(request.view, request.object, request.lock, request.force, request.now, by) orelse break :made false;
if (subtarget) |sub| sub.follow(cut.view);
break :made true;
} else viewing.set(request.view, request.object, request.lock, request.force, request.now, by);
if (made and request.lasting) viewing.lasting = true;
}
viewing.requests_seen = requests.count;
}
/// Whether the view is in `object`'s cockpit, in the cockpit mode: `camera_set_view` then sets
/// the object's flag bit 0, so that it isn't drawn.
pub fn inside(viewing: *const Viewing, object: u16) bool {
return viewing.object == object and inCockpit(viewing.view, viewing.cockpit_mode);
}
/// A camera key (`frame_controls`): the cockpit key, in the cockpit view, cycles the cockpit
/// mode first, and into the chase mode, the chase starts from its start distance. Returns the
/// view to switch to, with the player's ship as its object for the views from it, or null for
/// another action.
pub fn key(viewing: *Viewing, action: controls.Action) ?View {
const view = keyView(action) orelse return null;
if (action == .cockpit_camera and viewing.view == .cockpit and !viewing.locked) {
viewing.cockpit_mode = viewing.cockpit_mode.next();
if (viewing.cockpit_mode == .chase) viewing.changes.add(.chase_mode);
}
return view;
}
/// The camera's part of `frame_controls` for a frame `ticks` hundredths of a second long: in
/// the target and external views, the arrow keys steer the orbit, with Shift up and down to
/// zoom. With `HatEnable`, holding the hat in a straight direction switches to the matching
/// cockpit view, and releasing it returns to the front view. Then each camera key that was
/// pressed selects its view (the last one in the game's order wins), which it returns, for the
/// caller to switch to with the player's ship as its object (`switchView`). The keys are read
/// in the game's order, since `key_pressed` clears latches.
///
/// `orbited` is the radius of the object the orbit goes round, null for none. The original's
/// camera keeps the orbit's distance in range as it places the camera each frame
/// (`Orbit.keep`); OpenReliant's camera places it without writing into the orbit, so the orbit
/// is kept in range here, as the frame before would have left it and as the frame after will
/// show it.
pub fn frameControls(viewing: *Viewing, devices: *input.Devices, ticks: u32, orbited: ?f32) ?View {
const keyboard = &devices.keyboard;
if (viewing.view == .target or viewing.view == .external) {
const scan = input.scan;
var keys: Orbit.Keys = .{};
if (keyboard.pressed(scan.left, .none, false)) {
keys.left = true;
} else if (keyboard.pressed(scan.right, .none, false)) {
keys.right = true;
}
if (keyboard.pressed(scan.up, .shift, false)) {
keys = .{ .left = keys.left, .right = keys.right, .up = true, .shift = true };
} else if (keyboard.pressed(scan.down, .shift, false)) {
keys = .{ .left = keys.left, .right = keys.right, .down = true, .shift = true };
} else if (keyboard.pressed(scan.up, .none, false)) {
keys.up = true;
} else if (keyboard.pressed(scan.down, .none, false)) {
keys.down = true;
}
if (orbited) |radius| viewing.orbit.keep(viewing.view, radius);
viewing.orbit.steer(keys, @floatFromInt(ticks));
if (orbited) |radius| viewing.orbit.keep(viewing.view, radius);
}
var chosen: ?View = null;
const glancing = viewing.hat_glancing;
viewing.hat_glancing = false;
if (devices.settings.hat_enabled and devices.joystick.hats != 0) {
if (hatView(devices.joystick.state.pov[0])) |view| {
chosen = view;
viewing.hat_glancing = true;
}
}
if (glancing and !viewing.hat_glancing) chosen = .cockpit;
for (camera_actions) |action| {
if (devices.active(action, true)) chosen = viewing.key(action);
}
return chosen;
}
};
/// OpenReliant's: a change the game makes to what the camera shows, which the camera takes up as
/// it next frames (`Camera.notice`), where the original's game work makes it to the camera at
/// once.
pub const Change = union(enum) {
/// A switch of view (`Viewing.set`), which the camera cuts to (`Camera.cutTo`).
cut: Cut,
/// The cockpit key put the cockpit view in the chase mode (`Viewing.key`): the chase starts
/// from its start distance.
chase_mode,
/// Where an ejection's view stands off from what it watches, as it is switched to
/// (`switchCutaway`, `Camera.placeCutaway`).
cutaway: struct { view: View, seen: Subject, pod: Subject },
/// Where a launch's view puts the camera (`switchLaunch`, `Camera.placeLaunch`).
launch: struct { view: View, seen: Subject, player: Subject, even_gate: bool },
/// Where one of the Yamato's exterior views puts the camera (`switchYamato`,
/// `Camera.placeYamato`).
yamato: struct { view: View, player: Subject },
/// Where a jump's view puts the camera (`switchJump`, `Camera.placeJump`).
jump: struct { view: View, seen: Subject, player: Subject },
};
/// A switch of view: from `from` of `from_object` to `view` of `object`, in the cockpit mode it
/// was made in.
pub const Cut = struct {
from: View,
from_object: ?u16,
view: View,
object: ?u16,
cockpit_mode: CockpitMode,
};
/// OpenReliant's: the latest changes the game made to what the camera shows (`Change`), which the
/// camera takes up as it frames (`Camera.notice`). More than a few come between two drawn frames
/// only where the game frames run with none drawn, as while `--skip-launch` passes over the
/// launch; the camera then takes up the latest.
pub const Changes = table.Latest(Change, 16);
/// OpenReliant's: a switch of view the drawing side asks the game for, as a mod's script and
/// `--watch` make them (`Camera.ask`), which the game makes before it next runs
/// (`Viewing.takeUp`).
pub const Request = struct {
view: View,
object: ?u16,
lock: bool = false,
force: bool = false,
/// The tick it is asked at (`main.Clock.viewTime`), which the game switches at too.
now: u32,
/// Whether the view lasts (`Viewing.lasting`), as `--watch` has it.
lasting: bool = false,
/// Whether the camera cuts to it as it is asked, as for a mod's script, which can read the view
/// back straight away. Otherwise, as for `--watch`, the camera cuts as it next frames, once the
/// game has made the switch.
cut_at_once: bool = true,
};
/// How many switches of view the drawing side can ask for before the game takes them up
/// (`Camera.ask`).
const most_requests = 16;
/// OpenReliant's: the latest switches of view the drawing side asked for (`Request`), which the
/// game takes up before it next runs (`Viewing.takeUp`).
pub const Requests = table.Latest(Request, most_requests);
/// Switches the world's view (`camera_set_view`, `Viewing.set`) at the mission's tick.
pub fn switchView(world: gameobj.World, view: View, object: ?u16, lock: bool, force: bool) bool {
return world.player.viewing.set(view, object, lock, force, world.clock.viewTime(), .of(world));
}
/// Makes the switches of view the drawing side asked the game for through `drawn`, the camera
/// (`Viewing.takeUp`), in `world`.
pub fn takeUp(world: gameobj.World, drawn: *const Camera) void {
world.player.viewing.takeUp(&drawn.requests, .of(world), drawn.subtarget);
}
/// Switches to one of the ejection's views, `view`, of `object`, locked and forced
/// (`switchView`), with what the camera stands off by taken from `seen`, the object, and `pod`, the
/// pilot's, as they stand now (`Camera.placeCutaway`).
pub fn switchCutaway(world: gameobj.World, view: View, object: u16, seen: Subject, pod: Subject) bool {
return switchPlacing(world, view, object, .{ .cutaway = .{ .view = view, .seen = seen, .pod = pod } });
}
/// Switches to one of a launch's views, `view`, of `object`, locked and forced (`switchView`),
/// placing the camera once where the view stands (`Camera.placeLaunch`).
pub fn switchLaunch(world: gameobj.World, view: View, object: u16, seen: Subject, player: Subject, even_gate: bool) bool {
return switchPlacing(world, view, object, .{ .launch = .{ .view = view, .seen = seen, .player = player, .even_gate = even_gate } });
}
/// Switches to one of the Yamato's exterior views, `view`, of `object`, locked and forced
/// (`switchView`), placing the camera once where the view stands (`Camera.placeYamato`).
pub fn switchYamato(world: gameobj.World, view: View, object: u16, player: Subject) bool {
return switchPlacing(world, view, object, .{ .yamato = .{ .view = view, .player = player } });
}
/// Switches to one of a jump's views, `view`, of `object`, locked and forced (`switchView`),
/// placing the camera once where the view stands (`Camera.placeJump`).
pub fn switchJump(world: gameobj.World, view: View, object: u16, seen: Subject, player: Subject) bool {
return switchPlacing(world, view, object, .{ .jump = .{ .view = view, .seen = seen, .player = player } });
}
/// Switches to `view` of `object`, locked and forced (`switchView`), and has the camera place
/// itself as `placing` says once it takes the switch up.
fn switchPlacing(world: gameobj.World, view: View, object: u16, placing: Change) bool {
if (!switchView(world, view, object, true, true)) return false;
world.player.viewing.changes.add(placing);
return true;
}
/// The camera: Surrender's camera frame, which `camera_frame` places as the game's view
/// (`Viewing`) says, and what the original keeps to place it, with the cockpit's model it moves in
/// view 0. Leaves out the views not named in `View`, and the shake from hits in any view but 0.
pub const Camera = struct {
place: Place = .{ .position = @splat(0), .orientation = math.identity },
/// How much of the screen each bar covers (`0x00539A38`), and how fast they move
/// (`0x00539A50`).
bars: f32 = 0,
bar_speed: f32 = 0,
/// Where the ejection's views stand off from what they watch, as they are switched to
/// (`0x00539A44`): the eject view's reach out to its object's right, the pickup's way to half
/// between the picking ship and the pod, and the pod shot's way from the pod to the Sabre.
cutaway: Vector = @splat(0),
chase: Chase = .{},
/// What is left of the game's shake from hits as the frame is drawn, a tick on
/// (`Cockpit.faded`), which the camera and the display shake by.
shake_left: f32 = 0,
/// The guns' kick on the cockpit's hands (`0x005636E0`): 1 as the player's guns fire
/// (`0x0047BE3A`), and a twentieth less each frame.
recoil: f32 = 0,
/// Where the cockpit's model stands this frame, in view 0 outside the chase mode; null in the
/// rest.
cockpit_place: ?Cockpit.Placed = null,
/// Set as the view switches, which resets the star streaks (`backdrop_reset_streaks`), so that
/// the frame drawn next draws none, even where the view switches back to what it was.
cut: bool = false,
/// The player's subtarget picked out in red, which a switch of view picks out or puts back
/// (`Subtarget.follow`), with the objects it is picked out of; null where there is no display.
subtarget: ?Subtarget = null,
/// OpenReliant's: how many of the game's changes to what it shows it has taken up
/// (`Viewing.changes`, `notice`).
seen: u32 = 0,
/// OpenReliant's: the switches of view the drawing side asked the game for (`ask`).
requests: Requests = .{},
pub const Subtarget = struct {
shown: *hud.subtarget.Subtarget,
all: *create.Objects,
/// The subtarget's part of a switch to `view`: its parts are picked out in view 0 and put
/// back in any other (`0x0045F42D`, `0x0045F397`).
pub fn follow(subtarget: Subtarget, view: View) void {
if (view == .cockpit) subtarget.shown.pick(subtarget.all) else subtarget.shown.clear(subtarget.all);
}
};
/// Bars grow this share of the screen a tick, times their speed (`camera_frame`, `0x004DC418`).
pub const bar_rate: f32 = 0.001;
/// Takes up the changes the game made to what the camera shows since it last did
/// (`Viewing.changes`), in the order the game made them, with the subtarget following each
/// switch of view. It does so as it frames, and the drawn frame has it do so before it copies
/// the objects, which a cut's subtarget changes.
pub fn notice(camera: *Camera, viewing: *const Viewing) void {
var changes = viewing.changes.since(camera.seen);
while (changes.next()) |change| switch (change) {
.cut => |cut| {
camera.cutTo(cut);
if (camera.subtarget) |sub| sub.follow(cut.view);
},
.chase_mode => camera.chase.distance = Chase.start_distance,
.cutaway => |placed| camera.placeCutaway(placed.view, placed.seen, placed.pod),
.launch => |placed| camera.placeLaunch(placed.view, placed.seen, placed.player, placed.even_gate),
.yamato => |placed| camera.placeYamato(placed.view, placed.player),
.jump => |placed| camera.placeJump(placed.view, placed.seen, placed.player),
};
camera.seen = viewing.changes.count;
}
/// OpenReliant's: a switch of view the drawing side makes, as `request` asks: `viewing`, the
/// drawn frame's copy of the view, switches at once (`Viewing.turn`), and the game makes the
/// same switch before it next runs (`requests`, `Viewing.takeUp`). Where the request says so,
/// the camera cuts to it at once too. Refused where the game would refuse it, and past
/// `most_requests` the game hasn't taken up yet. Returns whether it switched.
pub fn ask(camera: *Camera, viewing: *Viewing, request: Request, by: Viewing.Bounds) bool {
if (camera.requests.count -% viewing.requests_seen >= most_requests) return false;
const cut = viewing.turn(request.view, request.object, request.lock, request.force, request.now, by) orelse return false;
if (request.lasting) viewing.lasting = true;
if (request.cut_at_once) camera.cutTo(cut);
camera.requests.add(request);
return true;
}
/// The camera's part of a switch of view (`camera_set_view`, `Viewing.set`): it has the stars
/// draw no streaks next frame, and slides the bars in for a letterboxed view or takes them away
/// for another.
fn cutTo(camera: *Camera, cut: Cut) void {
const view = cut.view;
camera.cut = true;
if (view.letterboxed()) {
camera.bar_speed = 1;
} else {
camera.bars = 0;
camera.bar_speed = 0;
}
if (view == .chase and (cut.from != .chase or cut.from_object != cut.object)) {
camera.chase.distance = Chase.start_distance;
}
switch (view) {
.cockpit => if (cut.cockpit_mode == .chase) camera.chase.resetTurns(),
.chase, .spectator => camera.chase.resetTurns(),
else => {},
}
}
/// What the ejection's views stand off by from what they watch, as `view` is switched to
/// (`switchCutaway`), from `seen`, the object, and `pod`, the pilot's, as they stand now.
pub fn placeCutaway(camera: *Camera, view: View, seen: Subject, pod: Subject) void {
camera.cutaway = switch (view) {
.eject => math.xAxis(seen.orientation) * @as(Vector, @splat(eject_reach)),
.pickup => (pod.position - seen.position) * @as(Vector, @splat(pickup_share)),
.pod_shot => math.normalize(seen.position - pod.position),
else => camera.cutaway,
};
}
/// Where a launch's view, `view`, puts the camera once as it is switched to (`switchLaunch`):
/// the bay view beside `seen`, the object, on its left where `even_gate` and else on its right;
/// the view from below under `player`, the player's ship, looking up at it; and the view aside
/// beside and below the object. `frame` then turns it.
pub fn placeLaunch(camera: *Camera, view: View, seen: Subject, player: Subject, even_gate: bool) void {
switch (view) {
.launch_bay => {
const across: Vector = .{ if (even_gate) -bay_offset[0] else bay_offset[0], bay_offset[1], bay_offset[2] };
camera.place.position = seen.place().point(across);
},
// Looking at the player's ship (`camera_look_at_player`, `0x00461D00`).
.launch_below => camera.place = lookingAt(player.place().point(below_offset), player.position),
.launch_aside => camera.place.position = seen.place().point(aside_offset),
else => {},
}
}
/// Where the Yamato's exterior views put the camera as they are switched to (`switchYamato`,
/// `camera_set_view`, `0x0045F4B0` onward). The ahead view keeps its orientation; the aside
/// view keeps its position and follows the ship.
pub fn placeYamato(camera: *Camera, view: View, player: Subject) void {
switch (view) {
.yamato_beside => camera.place = yamatoBeside(player, 0),
.yamato_ahead => camera.place = .{
.position = player.place().point(yamato_ahead_offset),
.orientation = math.turned(math.turned(player.orientation, .x, yamato_ahead_pitch), .y, std.math.pi),
},
.yamato_aside => camera.place = lookingAt(player.place().point(yamato_aside_offset), player.position),
else => {},
}
}
/// Where a jump's view, `view`, puts the camera once as it is switched to (`switchJump`): Jump
/// Out's view `jump_out_reach` out from `seen`, the object, along each of its axes; the view
/// ahead `jump_ahead_offset` from it, looking at it level in the frame of `player`, the player's
/// ship; and the view aside `jump_aside_offset` from it. `frame` then moves it. The close view
/// needs no placing: `frame` places it from the player's ship every frame, as it does at the
/// switch.
pub fn placeJump(camera: *Camera, view: View, seen: Subject, player: Subject) void {
switch (view) {
.jump_out => camera.place.position = seen.place().point(@splat(jump_out_reach)),
.jump_in_ahead => camera.place = levelLookingAt(seen.place().point(jump_ahead_offset), seen.position, player.orientation),
.jump_in_aside => camera.place.position = seen.place().point(jump_aside_offset),
else => {},
}
}
/// Places the camera for a drawn frame (`camera_frame`), once it has taken up the game's
/// changes (`notice`): moves the bars, then puts the camera where the view says. Where the view
/// can't go on, it holds still until the game switches it back. The game frames do the rest of
/// `camera_frame`, the shake from hits on the controller among it (`gameFrame`).
///
/// **Improvement:** with smooth motion, the missile view keeps behind its missile where the
/// frame draws it, between the ticks, as the other views follow their objects; the game keeps
/// behind it where the last tick left it.
pub fn frame(camera: *Camera, world: World) void {
camera.notice(world.viewing);
const ticks: f32 = @floatFromInt(world.ticks);
// What the shake from hits jitters by this frame, before it dies away some more, which the
// game frames make it do (`main.gameFrames`).
const shake: f32 = if (world.shake > 0) @min(world.shake, Cockpit.shake_most) * Cockpit.shake_share else 0;
camera.shake_left = Cockpit.faded(world.shake);
camera.cockpit_place = null;
if (camera.bar_speed != 0) {
camera.bars += ticks * camera.bar_speed * bar_rate;
if (camera.bars >= 0) {
if (camera.bars > letterbox) {
camera.bars = letterbox;
camera.bar_speed = 0;
}
} else {
camera.bars = 0;
camera.bar_speed = 0;
}
}
switch (world.viewing.view) {
.cockpit => if (world.viewing.cockpit_mode == .chase) {
camera.place = camera.chase.frame(world.object.motion, world.object.position, world.object.orientation);
} else {
camera.place = cockpit(.cockpit, world.object.position, world.object.orientation, world.object.eye);
if (world.cockpit) |model| camera.cockpit_place = Cockpit.place(model, &camera.recoil, shake, world.random);
// The camera itself shakes with a hit, by what is left of it.
if (shake > 0) camera.place.orientation = math.product(
Cockpit.jitter(camera.shake_left * Cockpit.camera_shake, world.random),
camera.place.orientation,
);
},
.cockpit_left, .cockpit_right, .cockpit_rear => |side| {
camera.place = if (side == .cockpit_rear and world.object.motion.ship_type.base() == .kamov)
kamovRear(world.object.position, world.object.orientation)
else
cockpit(side, world.object.position, world.object.orientation, world.object.eye);
},
.chase, .spectator => if (world.object.motion.ship_type.hasStats()) {
camera.place = camera.chase.frame(world.object.motion, world.object.position, world.object.orientation);
},
.target => if (world.target) |target| {
camera.place = world.viewing.orbit.place(.target, target.position, target.radius);
},
.external => camera.place = world.viewing.orbit.place(.external, world.player.position, world.player.radius),
.flyby => camera.place = flyby(camera.place.position, world.player.position, world.player.orientation, world.player.radius),
.pull_back => camera.place = pullBack(world.object.position, world.object.orientation, world.shown()),
.eject => camera.place = ejected(camera.cutaway, world.object.position, world.shown()),
.pickup => camera.place = pickedUp(camera.cutaway, world.object.position, world.object.orientation, world.shown()),
.pod_shot => {
// Until the pod bursts, the view holds its time at nothing (`main.missionOver`).
const since = if (world.player.exploding) world.shown() else 0;
camera.place = podShot(camera.cutaway, world.player.position, world.object.position, since);
},
.launch_bay => {
// Until the ship drops, the view holds its time at nothing (`gameFrame`).
const since = if (world.dropping) world.shown() else 0;
camera.place.orientation = math.product(world.player.orientation, math.fromAngles(bay_pitch - since * bay_tilt, 0, 0));
},
// `camera_ease_to_player` (`0x00461C60`) eases the view's angles toward looking at the
// player's ship by a share, which every call gives as all the way: the look itself.
.launch_below => camera.place = lookingAt(camera.place.position, world.player.position),
.launch_aside => camera.place = lookingAt(camera.place.position, world.player.position),
.yamato_beside => {
camera.place = yamatoBeside(world.player, world.shown());
if (world.game) |game| if (playerRunning(game, .launch)) |slot| if (slot.state.launch.style == .yamato) {
const state = slot.state.launch;
const step = state.step.as(yamato_launch.Step);
if (!state.step.reached(yamato_launch.Step.clear) or
(step == .clear and state.due + yamato_look_delay >= game.clock.frame_start))
camera.place.orientation = world.player.orientation;
};
},
.yamato_ahead => {},
.yamato_aside => camera.place = lookingAt(camera.place.position, world.player.position),
// The Reliant's landing's views stand off the tube's middle each frame, turned as the
// carrier is, looking at the player's ship and at the view's object. A landing in a
// hangar bay uses the same two, standing off the gate's launch point and its doors.
.landing_tube => if (world.landing) |landing| switch (landing) {
.reliant => |tube| camera.place = lookingAt(tube.tube + math.transform(tube.carrier, landing_tube_offset), world.player.position),
.bay => |bay| camera.place = lookingAt(bay.gate.point(bay_tube_radii * @as(Vector, @splat(world.player.radius))), world.player.position),
.yamato => {},