-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfteqcc_manual.txt
1912 lines (1574 loc) · 74 KB
/
fteqcc_manual.txt
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
====================
FTEQCC DOCUMENTATION
====================
Contents by David Walton and Marco Hladik.
Edited and compiled by Marco Hladik.
Last updated: 10th August 2018, 9:21 PM GMT
========
0. INDEX
========
1) Overview
1.1) Server-Side QuakeC (SSQC)
1.2) Client-Side QuakeC (CSQC)
1.3) Menu QuakeC (MenuQC)
2) Getting Started
3) Command-Line
4) Project Mangement
5) Other Pre-Processor
6) Control Statements
7) Basic Types
7.1) entity
7.2) float
7.3) string
7.4) int
7.5) vector
7.6) __variant
8) Complex Types
8.1) arrays
8.2) fields
8.3) functions
8.4) typedef
8.5) enum / enumflags / strongly typed enums
8.6) struct
8.7) union
8.8) class
8.9) pointer
8.10) Accessors
9) Type Modifiers
9.1) const / var
9.2) __unused / noref
9.3) __used
9.4) local
9.5) static / nonstatic
9.6) nosave
9.7) inline
9.8) strip / __ignore
9.9) shared
9.10) optional
9.11) __inout / __in / __out
9.12) __weak
9.13) __wrap
9.14) __accumulate
10) Operators
11) Intrinsics
12) Modelgen Commands
13) Compiler Flags
14) Engine Support
===========
1. Overview
===========
QuakeC is a language originally created by iD software for use in in the
video game Quake. Vanilla QuakeC is quite a limited language, however with qcc
improvements and engine extensions, its less annoying to write and also much
more capable as a programming language.
Today we're dealing with different types of modules. The original QuakeC only
supported the modification of game-code run on the server. It was not capable
of altering any client-side behaviour. Just send a selection of commands and
hope that the client interprets the stuff properly.
1.1) Server-Side QuakeC (SSQC)
==============================
This is the classic form of QuakeC, and is the module executed by the server
component. SSQC's reason to exist is so that it can deal with networking.
It is normally considered authoritive, which is a fancy way of saying that CSQC
isn't to be trusted (if only due to packetloss).
As such, the SSQC is normally expected to track the state of any entity that has
any impact on the outcome of a game.
In mods designed to run without CSQC, the SSQC generally does a lot more than
just that, however it is also potentially running on a computer on the other
side of the planet, so while you can write your entire game in just the SSQC
module, doing so means that you have no control over the user's actual screen,
and anything that is displayed can be quite laggy which may limit what you can
expect to achieve with SSQC alone.
There are two major variations of SSQC:
[1] NetQuake (NQ):
The original and more common type.
[2] QuakeWorld (QW):
Which was originally meant for deathmatch only.
It streamlines some things but in the process has a number of omissions that
break singleplayer quake (most qw mods lack any singleplayer/coop logic, with
no support for any monsters).
Thus most engines focus on NQ, even FTEQW!
SSQC tends to be very object orientated. There are comparatively few
non-constant globals as multiple pontential players/etc hinder the use of such
individual globals.
1.2) Client-Side QuakeC (CSQC)
==============================
This module runs clientside. Each client potentially has its own instance of
CSQC, and thus they'll all end up disagreeing about some part of the game
without the SSQC to provide authoritive information - remember this:
The SSQC knows best.
CSQC normally has full control over the client's screen (via builtins). It is
normally the CSQC that decides when and where to draw the various hud elements.
The CSQC also has control over the 3d view, and can not only decide where to
draw the 3d view, but it can also change the camera as well as directly control
the entities that are inserted into that view.
However, not every engine supports CSQC, and those that do might have it
disabled for whatever reason.
There are three variations of CSQC:
[1] FTE:
This was the first version of CSQC (if you ignore that CSQC was predated by
menuqc). It is also the one that supports the most extensions since.
[2] DP:
DP's CSQC implementation was an attempt to follow a poorly understood and
incomplete description of FTE's CSQC implementation. As a result, it does
many things in a sub-par way and refuses to improve upon any of it because
doing so might break one of the mods that use it.
Even so, you can still achieve some awesome stuff with it, it just tends to
be more limited than in FTE.
[3] Simple CSQC:
This variation of CSQC is a cut down version of CSQC. It is restricted from
various actions and is unable to query anything about the game beyond the
stats. Its sole purpose is to allow it to draw 2d elements including hud,
scoreboard, and menus. The crc of the csprogs.dat explcitly matches that
of the nq progs.dat, which allows client+server to reuse various builtins
etc, simplifying the implementation further, this also permits the entry
points to be provided by the progs.dat itself although this is more of a
convienience than anything else (it should still run in a seperate VM and
thus have no access to ssqc state).
As an improper subset, it is trivial to create a DP-compatible csprogs that
wraps the Simple CSQC entrypoints, allowing one csprogs to run seamlessly in
FTE+QSS+DP, and hopefully also other engines in the future.
CSQC tends to be more procedural than SSQC.
Generally there is only one player so that info can all be stored in globals
instead of entities (splitscreen may require arrays).
1.3) Menu QuakeC (MenuQC)
=========================
The mythical MenuQC module is responsible for drawing 2d menus.
It serves many of the CSQC's roles, except that it does not get purged on map
changes and is explicitly designed to remain running even when not connected
to a server.
Becase MenuQC was implemented in DP first combined with FTE's actual attempts
at compatibility, there is only a single standard for MenuQC. However, while
MenuQC is standard, both major supporters have their own extensions, but even
worse is that no two engines have the same names for the same cvar.
Indeed, cvar-hell is why it is generally not recommended for a mod to even try
to support more than one engine. Its much easier to just use the engine's menus
instead.
As such, MenuQC is generally used only for standalone total conversions.
==================
2. Getting Started
==================
The best way to get started is to find an existing qc-only mod (like
id1qc.zip), extract the qc source files somewhere like c:\quake\mymod\src\*.qc,
shift-right-click the extracted .src file and select open-with and find
fteqccgui.exe.
Then in fteqccgui press F7 to compile, then press F5 to run (you'll be prompted
to locate the exe you want to run as well as you quake directory.
In the engine you can then just load a map.
One common suggestion is to open weapons.qc, find the W_FireRocket function, and
to then change the velocity multiplier for really slow moving rockets, just to
see that you've made a change. There are many many other things you could do
instead, of course.
Your mod, your choice.
===============
3. Command-Line
===============
Many commandline arguments are best migrated to pragmas, or set via
fteqccgui's options menu.
[*] -src path
Specifies the directory to start looking in for source files. Mostly redundant.
[*] -srcfile foo.src
Specifies the .src file to start with.
[*] -o output.dat
Explicit output file name.
[*] -O3
Sets optimisations to max. Do not use in addons.
[*] -O2
Sets optimisations to high.
[*] -O0
Turns all optimisations off. You do NOT want this. Optimisations are required in
order to avoid wasting defs.
[*] -std=foo
Reconfigures compiler keywords+flags in order to attempt better compatibility
with the syntax of other QC compilers. There are absolutely no guarentees, nor
should there be much expectations...
[*] -Kfoo / -Kno-foo
Enables the named keyword.
Keywords that are not enabled are still usable with a double-underscore prefix,
so enabling/disabling them is more for compatibility.
[*] -Ffoo / -Fno-foo
Enables disables various compiler flags. There's a number of them, they're not
all useful either, and changing them mid-way through development will generally
result in new bugs in code that was working before. Consult fteqccgui's options
menu for a list.
[*] -Tfoo
Instructs fteqcc to target a specific instruction set and output format.
Common options are: standard, fte, h2, dp, qtest.
You may prefer to use '#pragma target foo' instead.
Using -Th2 also enables some additional keywords in order to act like hcc.
Other targets do not.
[*] -Dvariable[=value]
Defines the named preprocessor macro with the given value.
[*] -Isomepath
Registers an alternative include path, for included files that might otherwise
be considered missing.
[*] -Wall
Enables nearly all warnings.
[*] -Wextra
Enables more warnings than are useful. Many might be unfixable.
[*] -Werror
All warnings will be treated as errors.
[*] -Wno-mundane
Disables a number of warnings that you probably don't care too much about.
[*] -v
Verbose. Can be used multiple times to increase verbosity. Twice will include
autocvar output, which should simplify creation of your mod's default.cfg
[*] --version
Prints out the version of fteqcc and then quits.
[*] -stdout
Runs fteqccgui as if it were fteqcc (ie: compiles and quits without creating any
gui windows). Note that if you want to see the output on windows then you'll
need to pipe the output through some other program.
====================
4. Project Mangement
====================
All QuakeC starts with a single file - aka the .src.
This file comes in two forms.
1) Old style:
First token: treated as equivelent to #output "thetokenhere"
Other tokens: treated as equivelent to #include "thetokenhere"
Preprocessor may be used in this file only after the first token.
2) New style:
First token MUST have a leading #, and is typically #output "filename".
The rest of the code is treated as a .qc file in its own right, including
function defs etc.
Usually the code will be include a series of #includes in order to pull in
any .qc files you wish to compile.
[*] #merge
#merge "existing.dat" Attempts to imports an existing .dat into the compiler's
state. The imported state will lack any and all type information, so you will
need to re-prototype any variables that you use.
With the use of the __wrap keyword, you can rewrite the imported functions,
otherwise you can add additional symbols into the output.
Do NOT use the same filename for both #merge and #output.
[*] #copyright
Allows you to specify a copyright message. This will be embedded at the start of
the file, and will be displayed in a prompt if anyone tries to use fteqccgui's
decompiler on your mod.
You may wish to include the url of your source repo here.
[*] #include
Pulls in another source file, as if its contents had been embedded in the file
instead of the #include line.
[*] #includelist #endlist
Acts as an #include for each line between the #includelist and #endlist lines.
[*] #pragma includedir "path"
Specifies an alternative path from which to include other files. The path is
relative to the file containing the pragma (if not absolute).
[*] #datafile
Certain modes of operation cause FTEQCC to consider the output .dat files to be
zips (eg with the -Fembedsrc argument).
This argument explicitly includes the specified file within the resulting
.dat/zip.
[*] #pragma sourcefile
This pragma names an additional sourcefile to be compiled at the same time.
Thus if you have a progs.src that contains eg:
#pragma sourcefile "ssqc.src"
#pragma sourcefile "CSQC.src"
And then you compile that progs.src, fteqcc[gui] will attempt to compile all
three src files. This is strongly recommended for mods that involve a lot of
debugging of more than one module, and is the only way to get fteqccgui to track
the defs from multiple modules.
[*] #output / #pragma PROGS_DAT
Changes the .dat file that will be written from the current .src file.
[*] #message
Spits out a message to the compilers text output.
Does not otherwise affect anything.
[*] #pragma once
This file will be treated as 0-length if it is included again elsewhere.
[*] #error
Acts as a syntax error with user-defined text.
Useful to verify preprocessor state.
[*] #pragma noref STATE
If STATE is 1, then all following definitions will implicitly use the 'noref'
type modifier, which allows the qcc to silently strip them if they are not
actually referenced nor initialised.
This can be used to silence warnings from *extensions.qc files.
[*] #pragma defaultstatic STATE
Enables/disables the assumption that variables should be static. This can be
override on a per-variable basis with the static or nonstatic modifier.
In programming, it can often pay to 'box' things together, allowing you to
guarentee that only a specific part of your code can interact with something
and thereby reduce the number of outside things that will need to change when
refactoring code later on.
Note that static variables are considered to be invisible to the engine also,
which includes spawn functions and entry points, so use with caution.
[*] #pragma autoproto
If used, this must be used before any variables are defined. This causes fteqcc
to compile your code twice. The first time it will look only at definitions
while skipping over any function bodies allowing them to act as prototypes.
The second time it will compile the functions themselves.
Thus this ensures that any global that is declared later can freely be used in
any expressions or functions. Unfortunately this does not also apply to locals,
but this is usually much less of a concern.
[*] #pragma optimise [no-]foo
Enables or disables various specific optimisations without needing to deal with
commandlines etc, which can ensure other users alwways use the same
optimisation.
Note that if the argument is 'addon' then fteqcc will disable any optimisations
that might break addons/mutators. Otherwise accepts 0-3 as does the commandline.
[*] #pragam keyword enable|disable KEYWORD
Enables or disables parsing of a keyword. This can be used as a lazy wat to
avoid conflicts between eg fteqcc's break keyword and quake's break builtin.
Note that all keywords are still available using a double-underscore prefix,
eg '__break;' will always work. Many keywords default to disabled in order to
avoid common conflicts.
[*] #pragam flag enable|disable NAMEOFFLAG
Enables or disables some compiler flag (aka feature). These can affect how
various expressions are interpreted.
The exact list ought to be documented elsewhere.
[*] #pragam warning enable|disable|error|toggle WARNINGCODE
This controls the behaviour of the specified warning. If the warning is enabled
then it'll print as normal. If it is disabled, then the compiler will merely
mute the warning, everything else will still work the same. If the warning is
set to error, then any time that warning is encountered, the compiler will
consider it to be a soft error (aborting after 10 soft errors) and no output
will be generated.
The vanilla qcc silently accepted certain statements that are fundamentally
unsafe, and which many mods of the era used.
It is strongly recommended to make these into werrors instead, if you can.
Not all errors have a warning code to disable them, but those that do will
print their code every time one is encountered. Don't disable them simply
because you're lazy, as this solves nothing (if nothing else at least use
#warning to remind you to fix any spam later).
======================
5. Other Pre-Processor
======================
[*] #define foo bar
Defines a preprocessor constant/macro. Any time the compiler sees 'foo', it will
replace it with 'bar'.
If you have more than one token, it is strongly recommended to include brackets,
otherwise operator precedence can be confused between the code where the macro
is used and its contents (although this may even be desirable in rare
situations).
Multiple-line macros can be specified by a trailing backslash on the previous
line (there must be no whitespace between the backslash and the linebreak).
It is possible to embed preprocessor directives inside macros by using a
trailing backslash with the preprocessor starting on the next line.
However, this sort of vileness is STRONGLY DISCOURAGED, and will generate
warnings.
[*] #define foo(args) bar
Defines a preprocessor macro. This causes foo to act much like a function, with
any tokens matching an argument being replaced with the contents of that
argument, and otherwise acts as a constant.
Note that side effects (like pre/post increments or assignments) as arguments
can trigger multiple times if the argument is evaluated more than one in the
macro, or not at all if its not used.
Thus such side effects are not recommended.
Additionally, the macro should normally enclose each argument inside a
parenthasis in order to avoid operator precendence issues between caller
and macro.
Macros can contain braces or brackets, including unmatched ones, but this is
generally not recommended except possibly in BEGIN_* and END_* macros.
A single hash inside a macro body will 'stringify' the following token.
A double-hash will 'paste' the preceeding and trailing token together, removing
any whitespace, concatenating the two into a single token (which can be used to
generate names of variables/macros according to a base token.
[*] #append foo bar
Appends bar onto the end of the preprocessor macro.
This can be useful for list-like macros.
[*] #undef foo
Forgets the macro specified.
[*] #if EXPRESSION
The expression only supports numbers.
No variables are allowed, not even if they're defined with const.
The expession may contain && and || operators, and may include a special
'defined(x)' intrinsic that returns true if the name is in fact defined as a
macro (not a variable).
[*] #ifdef MACRONAME
Equivelent to #if defined(MACRONAME)
[*] #ifndef MACRONAME
Equivelent to #if !defined(MACRONAME)
[*] #elif EXPRESSION
Acts like #else #if expression but on a single line and without needing an
additional #endif
[*] #else
Parses the following text only if none of the expression in the preceeding #ifs
were false.
[*] #endif
Terminates a conditional preprocessor block.
=====================
6. Control Statements
=====================
[*] break;
Jumps outside of the current for/while/until/do loop, or switch statement.
[*] continue;
Jumps back to the start of the current loop.
[*] return
return; // for functions defined as returning void
return foo; // for functions with an actual return type.
return = foo; // for __accumulate functions that wish to execute accumulated
code instead of skipping it all.
__exit; // exit as if reaching the end of the function.
This is fantastic for confusing decompilers but otherwise should not be used.
The accumulate version above sets an implicit variable which is automatically
returned once control reaches the end of the function.
The other forms will leave the function there and then.
For compatibility reasons, fteqcc does not strictly enforce return types,
however this is bad practise and you really should fix any related warning
if you want to avoid unintended type punning.
[*] goto foo;
Jumps to another location of the current function. The location must be marked.
goto foo;
unreachablecode();
foo:
[*] { }
Blocks are a convienient way to group multiple statements.
Note that any control statement documented as taking either a block or a
statement does so interchangably (and many programming guides recommend that
blocks ALWAYS be used).
Note that blocks can be used outside of control statements too.
This allows for weird grouping or preprocessor workarounds.
[*] if (condition) statement;
The most simple conditional branch.
If the condition is considered true, then the code will be executed, otherwise
it will be skipped. If the expression is followed by an else satement then that
will be executed if the primary block was not.
Large 'else if' chains can be constructed, but you may find switch statements to
be more readable.
At this point, we have to ask ourselves what the nature of truth really is.
Not in a philosophical sense, but in a programmery sense.
QuakeC looks for truth in multiple ways, and all control statements use the same
basic form of truth, which depends upon types, but unitialised variables are
always FALSE (except field references, which are typically auto-initialised):
[*] int
False when 0, true when anything else.
[*] float
False when +0, true when anything else. Note that -0 is normally TRUE, but
some engines might treat this as false regardless, so don't expect things
to make sense. There's a compile-flag to treat if(-0) as FALSE, for a small
performance hit.
[*] strings
False when NULL, true when not NULL. Note that empty strings are not the
same as NULL.
[*] functions
Only the null function is false (assignments from __NULL__ or other null
functions can be used to reset a function reference to null).
Other functions (including SUB_Null) are considered true.
[*] vectors
By default, fteqcc compares all three components against +/-0.
Other QC compilers will typically test the _x component only.
[*] fields
Tests for null... Note that (typically) the modelindex field aliases the
null field, so would be considered false.
[*] entities
The world entity is equivelent to null, and thus false. All other entities
are considered true.
[*] pointers
__NULL__ is false, otherwise true.
[*] __variant
Danger... don't do this at home.
[*] arrays, structs, unions
These complex types cannot be evaluated for truth. You will need to evaluate
a specific index or member instead.
HexenC adds an inverted form of if statements:
if not(condition)
break;
Which is especially useful to test the return value of eg fgets, allowing you to
detect end-of-file conditions without breaking when encountering empty lines -
note that `if(!condition)` tests for empty instead of null, and is thus not
suitable in all cases.
[*] for (initial; condition; increment) statement;
Like in C. The initial terms are executed, then the loop will restart for as
long as the condition evaluates to true. The increment term is executed each
time the loop is restarted (including via continues) but not the initial time.
Multiple initial terms or increments can be achieved via use of the comma
operator, while the condition term must use the && or || operators.
Declarations are permitted inside the initial term, but have scope only within
the loop.
[*] while (condition) statement;
[*] do while
do {
statements();
} while( condition );
[*] __state
This is an alternative way to set .frame, .think, and .nextthink in a single
opcode.
__state [framenumber, functiontothink]; // quake style, accepts expressions,
however do not use pre-increment
nor post-increment as this is
potentially ambiguous - use
brackets if you need this.
__state [++ firstframe .. lastframe]; // hexen2 style, MUST use immediates
/ frame macros.
For the hexen2-style version, the animation automatically repeats
selecting(wrapping) the frame. The cycle_wrapped global will be set according to
whether the animation wrapped or not (starting from a frame outside of the range
does not count as a wrap).
[*] switch / case / default
switch (expression) {
case 0:
statements;
break;
case 1..5: // ranges are inclusive, so this includes 5 but not 5.001
statements;
break;
case 6: // falls through
case 7:
statements;
break;
default: // if none of the above cases matched (like 8 or .3)
statements;
break;
}
Switches allow a slightly cleaner alternative to massive if-else-if-else chains.
The case statements define various possible values, with the following code
being executed.
The 'default' statement defines a fallback location to execute from if none of
the cases matched the expression's value. Note that execution will continue
through any later cases, so be sure to use break statements to prevent undesired
fall-throughts.
Cases may be either a single value, or in the case of a numeric expression they
may be a range of values seperated by a double-dot (eg: case 0..1:foo;break;).
Cases are not required to be constants, but they must not be expressions (which
means fixed array indexes are acceptable, but not dynamic indexes).
[*] __thinktime
__thinktime ent : delay;
is equivelent to
ent.nextthink = time + delay;
When using -Th2 on the commandline, the double-underscores are not required.
[*] __until
__until(condition) {statements;}
A flipped version of while loops - the loop will repeat until the condition
becomes true. When using -Th2 on the commandline, the double-underscores are not
required.
[*] __loop
__loop { statements; }
Generally its better to use while(1){} or for(;;){} instead
When using -Th2 on the commandline, the double-underscores are not required.
==============
7. Basic Types
==============
7.1) entity
===========
Quake's objects. Each one has its own copy of each and every field.
Except for the world and players, the only difference between each entity is the
contents of its fields.
Note that collision and pvs state is tracked invisibly, and can be updated by
calling setorigin.
7.2) float
==========
These are standard IEEE single precision floats.
If you are attempting to store bit-values in a float then go no higher than 24
bits, failure to adhere to this can result in the lower bits getting forgotten
due to precision issues.
Float immediates can be specified as decimal (eg: 5.3), or as hex (eg: 0x554336
- note the bit limitation means you should stay with 6 hex digits).
Numbers with no decimal point are normally assumed to be floats, but if you wish
to be explicit then you can simply add a trailing point.
Additionally, character codes can be inserted as immediates using eg 'x' for the
ascii value of the x glyph.
A denormalised float is a very small float with its exponent part set to 0,
which is a special case of floats where the mantissa component has no implied
leading bit set to 1.
These thus have the same representation as an integer with up to 23 bits and can
thus be used to manipulate pointers/ents/strings in various hacky ways (as
popularised by qccx).
Not only are such hacks not recommended due to engine incompatibilties, but many
CPUs/binaries are explicitly configured to treat all denormalised floats as 0
for performance reasons and so their use isn't recommended even when not
exploiting an engine's QCVM, and any operation that implicitly requires
denormalised floats will generate warnings (which can be disabled).
7.3) string
===========
String immediates take the form of eg: "Hello World". Implicit concatenation
exists and can be used by simply placing two adjacent immediates.
To avoid issues with codepages and unicode conversions, strings should be kept
as ascii where possible, this can be achieved with string escapes instead of
pasting non-ascii values from an external tool.
[*] \\
Represents a single backslash character.
[*] \"
Represents a single double-quote character without closing the string.
[*] \'
Represents a single apostrophe character.
[*] \n
Represents a new-line character.
[*] \r
Represents a carrage-return character. This should only be used at the end
of console prints where you wish for the next line to replace the one you
just printed, and can be used for progress sprints without flooding the
console too much.
[*] \s
Denotes 'special' text. This is an easy way to write red text without
needing to resort to non-ascii source.
[*] \0 through \9
These represent 'golden' numbers.
[*] \x##
Represents a single byte with an explicit 8-bit hex value. If your engine is
configured to interpret text as utf-8 then this will often result in invalid
character encoding, if above 127.
[*] \u#
Represents a utf-8 encoded character. The # represents multiple hex nibbles.
In order to avoid confusion with trailing text, you may need to terminate
the string early and resume it again using string concatenation, but another
string escape works well too. This should only be used for mods that require
engines to interpret text as utf-8.
[*] \( \= \)
These three represent the open/center/close characters that are typically
used for quake's slider glyphs.
[*] \< \- \>
These three represent the start/middle/end characters of quake's line
seperator glyhs.
There are a few other escapes, but I cba to document them as I'd rather people
just used \x instead.
Additionally, FTEQCC supports raw strings.
These are specified as eg:
R"delim(Your String Here)delim".
Any and all text within the two brackets is your string - including any new line
characters exactly as they are in the file.
Any escapes are ignored, and will appear in the resulting string as-is
(you'll see the backslashes in-game).
The two 'delim' words in the example must match each other (but can be 0-length)
and are used as a way to allow close-bracket+double-quote pairs to exist inside
the raw string itself, including nested raw strings (so long as the delimiters
differ).
Note that file paths in quake should normally always use the more portable
forward-slash for path seperators, instead of the microsoft-only backslash
seperator.
Some engines support internationalisation. This is achieved by replacing all
strings defined as e.g. _("foo") according to the contents of a progs.LANG.po
file.
Mods that use this mechanism will likely also need to enable utf-8 support in
the engine, as well as use a unicode font.
Strings in the QCVM are nominally considered to be indexes from the start of
some string table defined by the progs.dat, however there are many special types
of string that are special or flawed.
[*] null string
The null string is the only string considered null. It is always empty.
[*] immediate string
This is any string immediate that came from inside the qc.
[*] permanent string
These are any string that came from parsing map entities.
[*] engine string
These strings point into engine memory, and their contents may change at any
time even when the string reference doesn't. This is why it can be so hard
to detect when the player's netname field changes - because the field itself
doesn't actually change.
[*] zoned/allocated strings
These strings are ones that were returned by the strzone builtin (part of
the FRIK_FILE extension). These are the ONLY strings that can be safely
strunzoned in all engines (some engines may silently ignore the null string
for convienience).
If your mod mixes permanent strings (or even immediate strings) with
allocated strings then you may find yourself with no way to decide whether
you need to call strunzone or not. It is recommended to just strzone in your
spawn functions etc, despite how ugly that is.
Note that allocated strings CANNOT safely be stored in globals in certain
engines, at least not if saved games are to load correctly without strunzone
crashing on the non-zoned strings loaded from the saved game.
[*] temporary string
Temp strings are messy and temporary by their very nature.
Their behaviour is highly engine-specific. Many engines rotate between 16
engine strings (or 1, in the case of vanilla quake), so after the 16th call
that returns a tempstring the older tempstrings get overwritten (you can
renew the string with strcat, but this is somewhat messy). Do not store them
inside globals or fields. Even temporarily storing a tempstring into a
global/field can result in warning messages when saving a game.
QS behaviour: Cycles between 16 tempstrings.
DP behaviour: Allocates more memory for tempstrings as needed.
Fails if strunzone is called on loaded saved games, spams if
tempstrings are still referenced when saving.
FTEQW behaviour: Does not distinguish between permanent strings, allocated
strings, nor temporary strings. All three have the exact
same behaviour - strzone is an alias for strcat (and
strunzone is a no-op), and tempstrings are collected only
once they are no longer referenced.
This avoids most savedgame issues.
7.4) int / integer
==================
Generally requires opcode extensions.
Note that unlike C, QC assumes numeric immediates to be floats.
Normally you should use a postfix of i to explicitly make it an int immediate,
but you can also enable a specific compiler flag to assume immediates as ints.
7.5) vector
===========
Vector immediates traditionally take the form of 'x y z', but using [x, y, z]
allows formulas and thus simpler argument passing.
Note that vector*vector yields a dot-product, while all other operations are
per-channel.
Normally vectors act a bit like unions and define both 'vec' and 'vec_[x|y|z]'
variables allowing for direct channel access, however the _x etc versions are
not always available (eg in arrays). The modern way to access individual
channels is with eg vec.x instead. Note that array indexing also works, so
vec[0] returns the _x component.
Dynamic indexes work also, but with the same performance hit as arrays so it is
generally best to avoid that if you can.
7.6) __variant
===============
This type represents an undefined type no larger than a vector, and should
normally be used only for function arguments or return value, but can also be
used for type punning.
================
8. Complex Types
================
8.1) arrays
===========
FTEQCC supports single-dimension arrays.
float foo[] = {1,2,3,4};
will thus define a float array and will infer its length as 4.
If you need to use an explicit length, or you do not wish to initialise the
array, then you must put the needed length inside the square brackets.
Note that arrays are 0-based, so an array defined as float foo[2]; can be
accessed as foo[0] or foo[1], but any other value (including foo[2]) is out of
bounds. Indexes will be rounded down.
foo.length can be read if you wish to know how long an array is (especially if
the length was inferred for some reason)
Dynamic indexes ARE supported in all cases, however they may come at a
significant performance loss if you do not have extended opcodes enabled, so it
is generally preferable to unroll small loops such that constant indexes can be
used.
Dynamic lengths are not supported at this time.
Arrays are also supported within structs, allowing for (clumsy)
multi-dimensional arrays.
8.2) fields
===========
Fields are defined by prefixing the field's type with a dot.
Every single entity will then have its own instance of the data, accessed via
eg: self.myfield
Fields are assumed to be constants, with any uninitialsed fields reserving space
in every single entity in order to hold the data. Fields defined as var or
initialised to the value of another field will NOT consume any space within
each entity.
.float foo; // const, allocates storage.
var .float bar = foo;
void() fnar =
{
self.foo = 42;
if (self.bar != 42)
dprintf("the impossible happened\n");
};
Note that field references are variables in their own right.
They can be defined as arrays, they can be passed to functions etc (eg the find
builtin depends upon it).
A word of warning though - field references will not appear in most saved game
formats. That's probably fine for deathmatch, but if you're using them for
singleplayer then be sure to initialise them (even if to the value of another).
8.3) functions
==============
In QuakeC, functions are both a function reference/variable, and typically a
function immediate/body, much like a string is both a string reference, and the
string data itself.
So function definitions are initialised in basically the same way as any other
variable, where the function-type syntax is basically just returntype(arglist),
eg:
returntype(arglist) name = functionbody;
functionbody can then be either some other function, or a function immediate.
As a special exception for C compatibility, the arglist parenthasis can follow
the function's name instead, and when the initialiser is an immediate, the
equals and trailing semi-colon tokens are optional.
Note that function immediates are what contain the bulk of code, and can only be
present within the context of a function type - meaning either in a function
initialisation or via a cast (creating an annonymous function - note that these
are not safe for saved games, so try to avoid their use in ssqc).
Because functions are really function references, you can define them as var,
and by doing so you can remap/wrap them at any point you wish. function types
can also be used freely within function arguments or anywhere else.
void() somename = {}; // QC-style function
void somename(void) {} // C-style
void() foo = [$newframe, nextfunc] {}; // QC state function ( function
// contains: self.frame = $newframe;
// self.think = nextfunc;
// self.nextthink = time+0.1; )
var void() dynreference; // uninitialised function reference, for
// dynamically switching functions.
var void() dynreference = somename; // initialised function references work
void(vector foo, float bar) func = {}; // function with two arguments.
void(float foo = 4) func = {}; // function that will be passed 4 for the
// first argument if it is omitted.
void(... foo) func = {
for(float f = 0; f < foo; f++)
bprint(va_arg(f, string));
}; // variable-args function that passes each arg to another.
void(optional float foo, ...) func = #0; // name-linked builtin where the
// first arg may be ommitted but
// must otherwise be a float, with
// up to 7 other args.
void(void) func = #0:foo; // unnumbered-but-named builtin.
void(float foo) func : 0; // hexenc builtin syntax
Note that QC can only tell how many arguments were passed using the
variable-argument argcount form. Any optional arguments that were omitted will
have undefined values. Any argumentsspecified after an optional argument must be
omitted if the prior arg is omitted but otherwise must be specified unless they
are optional themselves, or preinitialised.
Preinitialised non-optional arguments can be omitted, their preinitialised value
will be passed in this case. If the argument list is empty (ie: two adjacent
commas in the call), then the argument's default value will be passed
automatically regardless of whether the argument is considered optional.
Builtins can only accept up to 8 args. Non-builtins have a much higher limit.
Vectors count as 1 argument (and thus allow you to pack additional information).
Structs can be passed but will be counted as
ceil(sizeof(thestruct)/sizeof(vector)) arguments.
Named builtins can be used by some (but not all) engines to avoid numbering
conflicts. Typically these builtins must also be numbered as 0.
8.4) typedef
============
typedef type newname;
Typedefs allow the creation of an alias for types.
8.5) enum / enumflags / strongly typed enums
============================================
enum int
{
FIRST,
SECOND,
THIRD,
NINTH=8
};
Provides an easy way to define a set of constants.