Repository navigation
Expand file tree
/
Copy pathhs_runtime.c
More file actions
3568 lines (3146 loc) · 94.8 KB
/
Copy pathhs_runtime.c
File metadata and controls
3568 lines (3146 loc) · 94.8 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
/*
HS_RUNTIME.C
symbols in this file:
000B9850 0030:
_hs_syntax_nth (0000)
000B9880 0050:
_hs_inspect_boolean (0000)
000B98D0 0050:
_hs_inspect_real (0000)
000B9920 0050:
_hs_inspect_short_integer (0000)
000B9970 0050:
_hs_inspect_long_integer (0000)
000B99C0 0050:
_hs_inspect_string (0000)
000B9A10 0090:
_hs_inspect_enum (0000)
000B9AA0 0100:
_hs_runtime_initialize (0000)
000B9BA0 0080:
_hs_runtime_dispose_from_old_map (0000)
000B9C20 0010:
_hs_runtime_dispose (0000)
000B9C30 00b0:
_expression_get_function_name (0000)
000B9CE0 00f0:
_hs_thread_new (0000)
000B9DD0 0050:
_hs_thread_delete (0000)
000B9E20 0080:
_hs_thread_format (0000)
000B9EA0 0080:
_hs_stack_push (0000)
000B9F20 0020:
_hs_stack_pop (0000)
000B9F40 0150:
_hs_stack_allocate (0000)
000BA090 00b0:
_hs_wake (0000)
000BA140 0060:
_hs_find_thread_by_script (0000)
000BA1A0 0080:
_hs_find_thread_by_name (0000)
000BA220 0020:
_hs_long_to_boolean (0000)
000BA240 0020:
_hs_short_to_boolean (0000)
000BA260 0020:
_hs_string_to_boolean (0000)
000BA280 0010:
_hs_data_to_void (0000)
000BA290 0020:
_hs_short_to_real (0000)
000BA2B0 0010:
_hs_long_to_real (0000)
000BA2C0 0020:
_hs_enum_to_real (0000)
000BA2E0 0020:
_hs_real_to_short (0000)
000BA300 0010:
_hs_real_to_long (0000)
000BA310 0010:
_hs_long_to_short (0000)
000BA320 0040:
_hs_object_name_to_object_list (0000)
000BA360 0030:
_hs_object_to_object_list (0000)
000BA390 0080:
_hs_object_type_can_cast (0000)
000BA410 0100:
_hs_can_cast (0000)
000BA510 00c0:
_hs_cast (0000)
000BA5D0 0580:
_hs_global_reconcile_read (0000)
000BAB50 0190:
_hs_global_reconcile_write (0000)
000BACE0 0040:
_script_error (0000)
000BAD20 0020:
_hs_runtime_get_executing_thread_name (0000)
000BAD40 0020:
_hs_wake_by_name (0000)
000BAD60 0180:
_render_debug_scripting (0000)
000BAEE0 0440:
_render_debug_trigger_volumes (0000)
000BB320 0120:
_hs_return (0000)
000BB440 0040:
_hs_global_evaluate (0000)
000BB480 00f0:
_hs_evaluate_wake (0000)
000BB570 0170:
_hs_evaluate (0000)
000BB6E0 0060:
_hs_script_evaluate (0000)
000BB740 01c0:
_hs_arguments_evaluate (0000)
000BB900 0030:
_hs_macro_function_evaluate (0000)
000BB930 00d0:
_hs_evaluate_begin (0000)
000BBA00 0210:
_hs_evaluate_begin_random (0000)
000BBC10 0190:
_hs_evaluate_if (0000)
000BBDA0 0140:
_hs_evaluate_set (0000)
000BBEE0 0130:
_hs_evaluate_logical (0000)
000BC010 0180:
_hs_evaluate_arithmetic (0000)
000BC190 00e0:
_hs_evaluate_equality (0000)
000BC270 0210:
_hs_evaluate_inequality (0000)
000BC480 01c0:
_hs_evaluate_sleep (0000)
000BC640 0200:
_hs_evaluate_sleep_until (0000)
000BC840 0100:
_hs_evaluate_inspect (0000)
000BC940 0120:
_hs_evaluate_object_cast_up (0000)
000BCA60 0180:
_hs_evaluate_debug_string (0000)
000BCBE0 02f0:
_hs_thread_main (0000)
000BCED0 02d0:
_hs_runtime_initialize_for_new_map (0000)
000BD1A0 00b0:
_hs_runtime_update (0000)
000BD250 00c0:
_hs_runtime_evaluate (0000)
0026E880 0017:
??_C@_0BH@JDOAAMFH@type?$DN?$DN_hs_type_boolean?$AA@ (0000)
0026E898 0030:
??_C@_0DA@OFBKMPEO@c?3?2halo?2source?2hs?2hs_library_int@ (0000)
0026E8C8 0003:
??_C@_02NJPGOMH@?$CFf?$AA@ (0000)
0026E8CC 0014:
??_C@_0BE@OILODGFF@type?$DN?$DN_hs_type_real?$AA@ (0000)
0026E8E0 001d:
??_C@_0BN@EMEJADII@type?$DN?$DN_hs_type_short_integer?$AA@ (0000)
0026E900 0004:
??_C@_03JALODAI@?$CFld?$AA@ (0000)
0026E904 001c:
??_C@_0BM@KMJMLGIL@type?$DN?$DN_hs_type_long_integer?$AA@ (0000)
0026E920 0016:
??_C@_0BG@BOOAAIJG@type?$DN?$DN_hs_type_string?$AA@ (0000)
0026E938 0033:
??_C@_0DD@LFJLKEGO@enum_value?$DO?$DN0?5?$CG?$CG?5enum_value?$DMenum@ (0000)
0026E96C 0016:
??_C@_0BG@BHHILIEN@HS_TYPE_IS_ENUM?$CItype?$CJ?$AA@ (0000)
0026E984 0025:
??_C@_0CF@LGMLOJMN@couldn?8t?5allocate?5scripting?5glob@ (0000)
0026E9AC 000c:
??_C@_0M@IAKOKLGB@index?$CB?$DNNONE?$AA@ (0000)
0026E9B8 0024:
??_C@_0CE@JAGJENNE@raise?5MAXIMUM_NUMBER_OF_HS_GLOBA@ (0000)
0026E9DC 001f:
??_C@_0BP@HNAHKNME@c?3?2halo?2SOURCE?2hs?2hs_runtime?4c?$AA@ (0000)
0026E9FC 000b:
??_C@_0L@KLMNBLNA@hs?5globals?$AA@ (0000)
0026EA08 000a:
??_C@_09NFPDIMGO@hs?5thread?$AA@ (0000)
0026EA14 0010:
??_C@_0BA@DMAAAIAF@?$CIend?5of?5script?$CJ?$AA@ (0000)
0026EA24 0033:
??_C@_0DD@EECLOJLE@type?$CB?$DN_hs_thread_type_script?5?$HM?$HM?5@ (0000)
0026EA58 002a:
??_C@_0CK@PILPJPBD@type?$DO?$DN0?5?$CG?$CG?5type?$DMNUMBER_OF_HS_THR@ (0000)
0026EA84 003a:
??_C@_0DK@IFFNCFDC@hs_thread_get?$CIthread_index?$CJ?9?$DOtyp@ (0000)
0026EAC0 0014:
??_C@_0BE@FDONEJOD@?$FLglobal?5initialize?$FN?$AA@ (0000)
0026EAD4 0012:
??_C@_0BC@DIMBPFCM@?$FLconsole?5command?$FN?$AA@ (0000)
0026EAE8 003a:
??_C@_0DK@FJONKAAK@a?5problem?5occurred?5while?5executi@ (0000)
0026EB24 0010:
??_C@_0BA@OPEHPPEI@stack?5overflow?4?$AA@ (0000)
0026EB34 003f:
??_C@_0DP@HONBOJOM@?$CIbyte?5?$CK?$CJ?5?$CInew_frame?$CL1?$CJ?$DMthread?9?$DOs@ (0000)
0026EB78 0046:
??_C@_0EG@GLGLNCNE@frame?9?$DOdata?$CLframe?9?$DOsize?$CLsize?$DM?$DNth@ (0000)
0026EBC0 002f:
??_C@_0CP@LGELPKKM@attempt?5to?5allocate?5zero?5space?5f@ (0000)
0026EBF0 0011:
??_C@_0BB@IJDFEIOE@corrupted?5stack?4?$AA@ (0000)
0026EC04 0015:
??_C@_0BF@NOEAJPHF@valid_thread?$CIthread?$CJ?$AA@ (0000)
0026EC1C 003a:
??_C@_0DK@CIPMAIGO@desired_type?$DO?$DN0?5?$CG?$CG?5desired_type?$DM@ (0000)
0026EC58 0038:
??_C@_0DI@FBLLEJHE@actual_type?$DO?$DN0?5?$CG?$CG?5actual_type?$DMNU@ (0000)
0026EC90 001c:
??_C@_0BM@LDIPEIGF@hs_type_valid?$CIdesired_type?$CJ?$AA@ (0000)
0026ECAC 003b:
??_C@_0DL@KFHDEBEB@actual_type?$DN?$DN_hs_passthrough?5?$HM?$HM?5@ (0000)
0026ECE8 000e:
??_C@_0O@OAGBFBKC@bad?5typecast?4?$AA@ (0000)
0026ECF8 0027:
??_C@_0CH@CMGFPKPO@hs_can_cast?$CIactual_type?0?5desired@ (0000)
0026ED20 002b:
??_C@_0CL@BFAIEDCL@script?5?$CFs?5needs?5to?5be?5recompiled@ (0000)
0026ED4C 0011:
??_C@_0BB@OIKAMJPF@no?5reason?5given?4?$AA@ (0000)
0026ED60 000a:
??_C@_09DJENBFJK@?$FLunknown?$FN?$AA@ (0000)
0026ED6C 0003:
??_C@_02BGAGALCL@?$HMt?$AA@ (0000)
0026ED70 0028:
??_C@_0CI@KMEEEBHP@?$HMn?$HMn?$HMnscript?5name?$HMtsleep?5time?$HMtf@ (0000)
0026ED98 0028:
??_C@_0CI@PIIEBFIK@script_name_node?9?$DOtype?$DN?$DN_hs_type@ (0000)
0026EDC0 0042:
??_C@_0EC@EIHIFDEJ@TEST_FLAG?$CIscript_name_node?9?$DOflag@ (0000)
0026EE04 0018:
??_C@_0BI@DEHGHNBF@?$CKexpression_index?$DN?$DNNONE?$AA@ (0000)
0026EE1C 001e:
??_C@_0BO@IEBGLNDF@unexpected?5actual?5parameters?4?$AA@ (0000)
0026EE40 004b:
??_C@_0EL@EPENHJGN@hs_syntax_get?$CI?$CKexpression_index?$CJ@ (0000)
0026EE8C 0017:
??_C@_0BH@JHPKLPNE@corrupted?5syntax?5tree?4?$AA@ (0000)
0026EEA4 0018:
??_C@_0BI@JEAIILKP@?$CKexpression_index?$CB?$DNNONE?$AA@ (0000)
0026EEBC 0023:
??_C@_0CD@LMIAMJPE@function_index?$DN?$DN_hs_function_beg@ (0000)
0026EEE0 001a:
??_C@_0BK@ICIEGLDA@?$CKargument_count?$DMLONG_BITS?$AA@ (0000)
0026EEFC 002a:
??_C@_0CK@HFFDNMBO@function_index?$DN?$DN_hs_function_beg@ (0000)
0026EF28 0052:
??_C@_0FC@PECKPIAM@parameter_types?$FL0?$FN?$DN?$DN_hs_type_sho@ (0000)
0026EF7C 0028:
??_C@_0CI@EGAEHKHM@attempt?5to?5convert?5object?5?$CFs?5to?5@ (0000)
0026EFA4 0013:
??_C@_0BD@HGOCLPEG@function?9?$DOevaluate?$AA@ (0000)
0026EFB8 0023:
??_C@_0CD@JFOOFKBP@found?5a?5static?5script?5at?5topleve@ (0000)
0026EFE0 004f:
??_C@_0EP@ECAJPAK@script?9?$DOscript_type?$CB?$DN_hs_script_@ (0000)
0026F030 001b:
??_C@_0BL@LKLEHFKI@ran?5out?5of?5script?5threads?4?$AA@ (0000)
0026F04C 002c:
??_C@_0CM@EIHAGODH@a?5global?5initialization?5attempte@ (0000)
0026F078 0020:
??_C@_0CA@COEBOOJE@internal_thread?9?$DOsleep_until?$DN?$DN0?$AA@ (0000)
0026F098 0036:
??_C@_0DG@NJPPFAFA@there?5are?5not?5enough?5threads?5to?5@ (0000)
002E2370 264c:
_hs_type_inspectors (0000)
_typecasting_procedures (00c8)
004535AC 0008:
_hs_runtime_globals (0000)
*/
/* ---------- headers */
#include "cseries/cseries.h"
#include "ai/ai_debug_scripting.h"
#include "ai/ai_script.h"
#include "hs/hs.h"
#include "hs/hs_library_internal.h"
/* Empty reconstructed header removed; no declarations to include. */
#include "hs/object_lists.h"
#include "hs/hs_scenario_definitions.h"
#include "math/real_math.h"
#include "memory/data.h"
#include "objects/objects.h"
#include "objects/object_types.h"
#include "physics/collisions.h"
#include "render/render.h"
#include "render/render_debug.h"
#include "scenario/scenario.h"
#include "scenario/scenario_definitions.h"
#include "saved games/game_state.h"
#include "text/draw_string.h"
#include "cseries/errors.h"
#include "interface/terminal.h"
#include "main/console.h"
#include "game/game.h"
#include "mcc_scripts.h" /* port: port/linux/game/mcc_scripts.h */
/* ---------- constants */
enum
{
_hs_thread_type_script = 0,
_hs_thread_type_global_initialize,
_hs_thread_type_console_command,
NUMBER_OF_HS_THREAD_TYPES,
};
enum
{
_hs_syntax_node_primitive_bit = 0,
_hs_syntax_node_script_bit,
_hs_syntax_node_global_bit,
};
enum
{
MAXIMUM_HS_DEBUG_STRING_ARGUMENTS = 32
};
enum
{
HS_THREAD_STACK_SIZE = 0x200
};
/* port: the size of the text an inspector writes (hs_evaluate_inspect) */
enum
{
HS_INSPECT_BUFFER_SIZE = 1024
};
enum
{
_hs_thread_in_function_call_bit = 0,
_hs_thread_sleeping_bit,
/* port: the thread's stack overflowed (hs_stack_overflow); hs_thread_main
ends it */
_hs_thread_stack_overflow_bit,
_hs_global_external_bit = 15,
};
/* ---------- macros */
#define hs_thread_get(thread_index) \
((struct hs_thread_datum *)datum_get(hs_thread_data, (thread_index)))
#define hs_syntax_get(expression_index) \
((struct hs_syntax_node *)datum_get(hs_syntax_data, (expression_index)))
/* port: MCC selects its own checked stack end; native limits are unchanged. */
/* a thread is valid when it lies inside the thread data array and its stack pointer and
the fill mark of its topmost frame lie inside its own inline stack buffer */
#define valid_thread(thread) \
((byte *)(thread)>=(byte *)hs_thread_data->data && \
(byte *)(thread)<(byte *)hs_thread_data->data+hs_thread_data->count*hs_thread_data->size && \
(byte *)(thread)->stack>=(thread)->stack_data && \
(byte *)(thread)->stack<mcc_hs_stack_end(thread) && \
(thread)->stack->data+(thread)->stack->size<=mcc_hs_stack_end(thread))
#define HS_GLOBAL_DESIGNATOR_IS_EXTERNAL(designator) \
TEST_FLAG((designator), _hs_global_external_bit)
#define HS_GLOBAL_DESIGNATOR_TO_INDEX(designator) \
((designator)&0x7fff)
/* every runtime failure is reported through the executing script's name */
#define match_hs_assert(file, line, thread_index, expr, reason) \
match_vassert(file, line, expr, csprintf(temporary, \
"a problem occurred while executing the script %s: %s (%s)", \
hs_thread_format(thread_index), reason, #expr))
/* the four ordered comparisons of hs_evaluate_inequality, expanded once per operand
representation; each expansion reports its own case's location */
#define HS_EVALUATE_INEQUALITY(first, second, line) \
value0 = (first); \
value1 = (second); \
switch (function_index) \
{ \
case _hs_function_gt: \
comparison = value0>value1; \
break; \
case _hs_function_lt: \
comparison = value0<value1; \
break; \
case _hs_function_gte: \
comparison = value0>=value1; \
break; \
case _hs_function_lte: \
comparison = value0<=value1; \
break; \
default: \
comparison = FALSE; \
match_vassert("c:\\halo\\source\\hs\\hs_library_internal_runtime.h", line, FALSE, NULL); \
break; \
}
typedef long (*hs_typecasting_procedure)(long value);
typedef void (*hs_debug_string_procedure)(
long name_count,
char const **names);
typedef void (*hs_inspection_procedure)(
short type,
long value,
char *buffer);
/* ---------- structures */
struct hs_runtime_globals
{
boolean initialized;
short executing_thread_index;
};
struct hs_stack_frame
{
struct hs_stack_frame *previous;
long expression_index;
void *result;
short size;
byte data[2];
};
struct hs_global_datum
{
short identifier;
short unused;
long value;
};
struct hs_thread_datum
{
short identifier;
byte type;
byte flags;
long script_index;
long sleep_until;
long previous_sleep_until;
struct hs_stack_frame *stack;
long result;
byte stack_data[0x200];
};
typedef char hs_thread_datum_size_assert[
sizeof(struct hs_thread_datum) == 0x218 ? 1 : -1];
/* ---------- prototypes */
static void hs_inspect_boolean(
short type,
long value,
char *buffer);
static void hs_inspect_real(
short type,
long value,
char *buffer);
static void hs_inspect_short_integer(
short type,
long value,
char *buffer);
static void hs_inspect_long_integer(
short type,
long value,
char *buffer);
static void hs_inspect_string(
short type,
long value,
char *buffer);
static void hs_inspect_enum(
short type,
long value,
char *buffer);
static long hs_long_to_boolean(
long n);
static long hs_short_to_boolean(
long s);
static long hs_string_to_boolean(
long n);
static long hs_data_to_void(
long n);
static long hs_short_to_real(
long s);
static long hs_long_to_real(
long l);
static long hs_enum_to_real(
long e);
static long hs_real_to_short(
long r);
static long hs_real_to_long(
long r);
static long hs_long_to_short(
long l);
static long hs_object_name_to_object_list(
long object_name_index);
static long hs_object_to_object_list(
long object_index);
static boolean hs_object_type_can_cast(
short actual_type,
short desired_type);
/* port: an object, unit or list a value names that no longer exists */
static long hs_value_still_exists(
short type,
long value);
static char const *hs_thread_format(
long thread_index);
static void hs_stack_pop(
long thread_index);
static void hs_wake(
long thread_index);
static long hs_find_thread_by_script(
short script_index);
static long hs_find_thread_by_name(
char const *name);
static long hs_syntax_nth(
long expression_index,
short n);
static void hs_thread_delete(
long thread_index);
static long hs_thread_new(
short type,
long script_index);
static boolean hs_stack_push(
long thread_index);
static void hs_stack_overflow(
long thread_index);
static void hs_syntax_error(
long thread_index);
static void *hs_stack_allocate(
long thread_index,
long size);
static void hs_evaluate(
long thread_index,
long expression_index,
long *destination);
static long hs_global_evaluate(
short global_designator);
static long *hs_arguments_evaluate(
long thread_index,
short formal_parameter_count,
short const *formal_parameters,
boolean initialize);
static boolean script_error(
long thread_index,
char const *reason,
char const *expression);
/* port: a type's default value (hs_scenario_functions_check) */
static long hs_type_default_value(
short type);
static void hs_script_evaluate(
short script_index,
long thread_index,
boolean initialize);
static void hs_thread_main(
long thread_index);
static void hs_global_reconcile_read(
word global_designator);
static void hs_global_reconcile_write(
word global_designator);
/* ---------- globals */
struct data_array *hs_global_data;
struct data_array *hs_thread_data;
extern struct data_array *hs_syntax_data;
extern short const hs_external_global_count;
extern long const hs_function_table_count;
extern short const hs_type_sizes[NUMBER_OF_HS_TYPES];
boolean debug_scripting;
unsigned long hs_debug_data[BIT_VECTOR_SIZE_IN_LONGS(MAXIMUM_TRIGGER_VOLUMES_PER_SCENARIO)];
typedef char verify_hs_debug_data_size[sizeof(hs_debug_data) == 0x20 ? 1 : -1];
static hs_inspection_procedure hs_type_inspectors[NUMBER_OF_HS_TYPES] =
{
NULL,
NULL,
NULL,
NULL,
NULL,
hs_inspect_boolean,
hs_inspect_real,
hs_inspect_short_integer,
hs_inspect_long_integer,
hs_inspect_string,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
hs_inspect_enum,
hs_inspect_enum,
hs_inspect_enum,
hs_inspect_enum,
hs_inspect_enum,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
};
hs_typecasting_procedure typecasting_procedures[NUMBER_OF_HS_TYPES][NUMBER_OF_HS_TYPES] =
{
{ NULL }, /* unparsed */
{ NULL }, /* special_form */
{ NULL }, /* function_name */
{ NULL }, /* passthrough */
{ /* void */
NULL, NULL, NULL, NULL,
NULL,
hs_data_to_void, hs_data_to_void, hs_data_to_void, hs_data_to_void,
hs_data_to_void, hs_data_to_void, hs_data_to_void, hs_data_to_void,
hs_data_to_void, hs_data_to_void, hs_data_to_void, hs_data_to_void,
hs_data_to_void, hs_data_to_void, hs_data_to_void, hs_data_to_void,
hs_data_to_void, hs_data_to_void, hs_data_to_void, hs_data_to_void,
hs_data_to_void, hs_data_to_void, hs_data_to_void, hs_data_to_void,
hs_data_to_void, hs_data_to_void, hs_data_to_void, hs_data_to_void,
hs_data_to_void, hs_data_to_void, hs_data_to_void, hs_data_to_void,
hs_data_to_void, hs_data_to_void, hs_data_to_void, hs_data_to_void,
hs_data_to_void, hs_data_to_void, hs_data_to_void, hs_data_to_void,
hs_data_to_void, hs_data_to_void, hs_data_to_void, hs_data_to_void,
},
{ /* boolean */
NULL, NULL, NULL, NULL,
NULL, NULL,
hs_long_to_boolean,
hs_short_to_boolean,
hs_long_to_boolean,
hs_string_to_boolean,
},
{ /* real */
NULL, NULL, NULL, NULL,
NULL, NULL, NULL,
hs_short_to_real,
hs_long_to_real,
NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL,
NULL,
hs_enum_to_real, hs_enum_to_real, hs_enum_to_real, hs_enum_to_real,
},
{ /* short_integer */
NULL, NULL, NULL, NULL,
NULL, NULL,
hs_real_to_short,
NULL,
hs_long_to_short,
},
{ /* long_integer */
NULL, NULL, NULL, NULL,
NULL, NULL,
hs_real_to_long,
NULL,
hs_long_to_short,
},
{ NULL }, /* string */
{ NULL }, /* script */
{ NULL }, /* trigger_volume */
{ NULL }, /* cutscene_flag */
{ NULL }, /* cutscene_camera_point */
{ NULL }, /* cutscene_title */
{ NULL }, /* cutscene_recording */
{ NULL }, /* device_group */
{ NULL }, /* ai */
{ NULL }, /* ai_command_list */
{ NULL }, /* starting_profile */
{ NULL }, /* conversation */
{ NULL }, /* navpoint */
{ NULL }, /* hud_message */
{ /* object_list */
NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL,
object_list_from_ai_reference,
NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL,
NULL,
hs_object_to_object_list, hs_object_to_object_list, hs_object_to_object_list, hs_object_to_object_list,
hs_object_to_object_list,
hs_object_name_to_object_list, hs_object_name_to_object_list, hs_object_name_to_object_list, hs_object_name_to_object_list,
hs_object_name_to_object_list, hs_object_name_to_object_list,
},
};
static struct hs_runtime_globals hs_runtime_globals;
/* per-type fallbacks used when an external global has no backing address */
extern boolean const _hs_type_boolean_default;
extern real const _hs_type_real_default;
extern short const _hs_type_short_integer_default;
extern long const _hs_type_long_integer_default;
extern char const *_hs_type_string_default;
extern short const _hs_type_script_default;
extern short const _hs_type_trigger_volume_default;
extern short const _hs_type_cutscene_flag_default;
extern short const _hs_type_cutscene_camera_point_default;
extern short const _hs_type_cutscene_title_default;
extern short const _hs_type_cutscene_recording_default;
extern short const _hs_type_device_group_default;
extern long const _hs_type_ai_default;
extern short const _hs_type_ai_command_list_default;
extern short const _hs_type_starting_profile_default;
extern short const _hs_type_conversation_default;
extern short const _hs_type_navpoint_default;
extern short const _hs_type_hud_message_default;
extern long const _hs_type_object_list_default;
extern long const _hs_type_sound_default;
extern long const _hs_type_effect_default;
extern long const _hs_type_damage_default;
extern long const _hs_type_looping_sound_default;
extern long const _hs_type_animation_graph_default;
extern long const _hs_type_actor_variant_default;
extern long const _hs_type_damage_effect_default;
extern long const _hs_type_object_definition_default;
extern short const _hs_type_enum_game_difficulty_default;
extern short const _hs_type_enum_team_default;
extern short const _hs_type_enum_ai_default_state_default;
extern short const _hs_type_enum_actor_type_default;
extern short const _hs_type_enum_hud_corner_default;
extern long const _hs_type_object_default;
extern long const _hs_type_unit_default;
extern long const _hs_type_vehicle_default;
extern long const _hs_type_weapon_default;
extern long const _hs_type_device_default;
extern long const _hs_type_scenery_default;
extern short const _hs_type_object_name_default;
boolean debug_trigger_volumes;
/* ---------- public code */
#include "mcc_script_threads.inl" /* port: MCC-only bounded thread storage. */
#include "mcc_script_runtime.inl" /* port: port/linux/game/mcc_script_runtime.inl */
#include "hs_console_state.inl" /* port: port/linux/game/hs_console_state.inl */
void hs_runtime_initialize(
void)
{
short global_index;
long index;
hs_thread_data = game_state_data_new("hs thread", 0x100, 0x218);
hs_global_data = game_state_data_new("hs globals", 0x400, 8);
hs_console_state_initialize(); /* port: shares the threads' saved lifetime. */
if (hs_thread_data && hs_global_data)
{
match_vassert("c:\\halo\\SOURCE\\hs\\hs_runtime.c", 0xa9,
hs_external_global_count*2<0x400,
"raise MAXIMUM_NUMBER_OF_HS_GLOBALS.");
data_make_valid(hs_global_data);
for (global_index = 0;
global_index<hs_external_global_count;
global_index++)
{
index = datum_new_at_index(hs_global_data,
DATUM_INDEX_NEW(global_index, 0xaced));
match_assert("c:\\halo\\SOURCE\\hs\\hs_runtime.c", 0xb1, index!=NONE);
}
}
else
{
error(_error_immediate, "couldn't allocate scripting globals.");
}
return;
}
void hs_runtime_initialize_for_new_map(
void)
{
long internal_thread_index;
/* port: select the MCC-owned array only after its cache was accepted. */
mcc_hs_threads_activate();
hs_console_state_reset(); /* port: text and snapshots belong to this map. */
data_make_valid(hs_thread_data);
hs_runtime_globals.initialized = TRUE;
hs_runtime_globals.executing_thread_index = NONE;
internal_thread_index = hs_thread_new(_hs_thread_type_global_initialize, NONE);
if (global_scenario_index!=NONE)
{
struct scenario *scenario = global_scenario_get();
struct hs_thread_datum *internal_thread = hs_thread_get(internal_thread_index);
struct hs_global_datum *global_datum;
long global_datum_index;
short global_index;
short script_index;
for (global_index = 0;
global_index<scenario->hs_globals.count;
global_index++)
{
struct hs_global *global = TAG_BLOCK_GET_ELEMENT(
&global_scenario_get()->hs_globals,
global_index,
struct hs_global);
if (HS_GLOBAL_DESIGNATOR_IS_EXTERNAL((word)global_index))
global_datum_index = HS_GLOBAL_DESIGNATOR_TO_INDEX(global_index);
else
global_datum_index = HS_GLOBAL_DESIGNATOR_TO_INDEX(global_index)+
hs_external_global_count;
datum_new_at_index(hs_global_data,
DATUM_INDEX_NEW(global_datum_index, 0xaced));
if (HS_GLOBAL_DESIGNATOR_IS_EXTERNAL((word)global_index))
global_datum_index = HS_GLOBAL_DESIGNATOR_TO_INDEX(global_index);
else
global_datum_index = HS_GLOBAL_DESIGNATOR_TO_INDEX(global_index)+
hs_external_global_count;
global_datum = datum_get(hs_global_data, global_datum_index);
internal_thread->script_index = NONE;
internal_thread->stack->size = 0;
/* port: an initializer that calls a function a map's scripts
may not isn't evaluated: the global starts at its type's
default (hs_scenario_functions_check) */
if (hs_scenario_global_initializer_disabled(global_index))
{
global_datum->value = hs_type_default_value(global->type);
}
else
{
hs_evaluate(
internal_thread_index,
global->initialization_expression_index,
&global_datum->value);
}
if (TEST_FLAG(internal_thread->flags, _hs_thread_in_function_call_bit))
{
hs_thread_main(internal_thread_index);
if (global->type==_hs_type_object_list)
object_list_add_reference(hs_global_evaluate(global_index));
match_hs_assert("c:\\halo\\SOURCE\\hs\\hs_runtime.c", 0xe7, internal_thread_index,
internal_thread->sleep_until==0,
"a global initialization attempted to sleep.");
}
hs_global_reconcile_write(global_index);
}
hs_thread_delete(internal_thread_index);
for (script_index = 0;
script_index<scenario->hs_scripts.count;
script_index++)
{
struct hs_script *script = TAG_BLOCK_GET_ELEMENT(
&scenario->hs_scripts,
script_index,
struct hs_script);
/* port: none for a script that calls a function a map's
scripts may not (hs_scenario_functions_check) */
if (script->script_type!=_hs_script_static &&
script->script_type!=_hs_script_stub &&
!hs_scenario_script_disabled(script_index))
{
if (hs_thread_new(_hs_thread_type_script, script_index)==NONE)
error(_error_immediate, "ran out of script threads.");
}
}
}
csmemset(hs_debug_data, 0,
BIT_VECTOR_SIZE_IN_BYTES(MAXIMUM_TRIGGER_VOLUMES_PER_SCENARIO));
return;
}
void hs_runtime_dispose(
void)
{
data_make_invalid(hs_global_data);
return;
}
void hs_runtime_dispose_from_old_map(
void)
{
short global_index;
data_make_invalid(hs_thread_data);
for (global_index = hs_external_global_count;
global_index<hs_global_data->count;
global_index++)
{
if (datum_try_and_get(hs_global_data, global_index))
datum_delete(hs_global_data, global_index);
}
hs_runtime_globals.initialized = FALSE;
hs_console_state_reset(); /* port: release the old map's console ownership. */
return;
}
static char const *expression_get_function_name(
long thread_index,
long expression_index)
{
long next_expression_index;
struct hs_syntax_node *syntax_node = hs_syntax_get(expression_index);
struct hs_thread_datum *thread = hs_thread_get(thread_index);
while (TRUE)
{
if (TEST_FLAG(syntax_node->flags, _hs_syntax_node_script_bit))
break;
if (syntax_node->index != 0 ||
expression_index != thread->stack->expression_index)
{
/* port: an index past the table (a damaged map's) names none */
{
struct hs_function_definition *mcc_function = mcc_script_function(syntax_node->index);
if (mcc_function)
return mcc_function->name;
}
if ((word)syntax_node->index>=hs_function_table_count)
return "(corrupt function)";
return hs_function_get((word)syntax_node->index)->name;
}
next_expression_index = *(long *)thread->stack->data;
if (next_expression_index == NONE)
return "(end of script)";
expression_index = next_expression_index;
syntax_node = hs_syntax_get(expression_index);
thread = hs_thread_get(thread_index);
}
/* port: as for a function's */
if (syntax_node->index<0 ||
syntax_node->index>=global_scenario_get()->hs_scripts.count)
{
return "(corrupt script)";
}
return TAG_BLOCK_GET_ELEMENT(
&global_scenario_get()->hs_scripts,
syntax_node->index,
struct hs_script)->name;
}
boolean hs_runtime_waiting_on_call(
void)
{
struct hs_stack_frame *frame;
struct hs_syntax_node *caller;
if (hs_runtime_globals.executing_thread_index == NONE)
return FALSE;
frame = hs_thread_get(hs_runtime_globals.executing_thread_index)->stack;
if (!frame || !frame->previous)
return FALSE;
caller = hs_syntax_get(frame->previous->expression_index);
return !TEST_FLAG(caller->flags, _hs_syntax_node_script_bit) && caller->function_index == _hs_function_sleep_until;
}
/* port: a global initializer is not a console command, even when it calls
a static script. The owning thread, not its current stack frame, decides. */
boolean hs_runtime_port_executing_console_command(
void)
{
return hs_runtime_globals.initialized &&
hs_runtime_globals.executing_thread_index != NONE &&
hs_thread_get(hs_runtime_globals.executing_thread_index)->type == _hs_thread_type_console_command;
}
/* port: the map's riding call counts only from a startup script (vehicle_riding.c) */
short hs_runtime_port_executing_script_type(
void)
{
struct hs_thread_datum *thread;
struct hs_script *script;
if (!hs_runtime_globals.initialized || hs_runtime_globals.executing_thread_index==NONE)
return NONE;
thread = hs_thread_get(hs_runtime_globals.executing_thread_index);
if (thread->type!=_hs_thread_type_script)