-
Notifications
You must be signed in to change notification settings - Fork 5
/
iengine.h
3076 lines (2856 loc) · 90.5 KB
/
iengine.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* @file iengine.h
* @brief The interface the game uses to access the engine.
*
* The file contains functions which comprise the API for writing games. This
* header file is not called by the game internally but should be included in
* the game code to expose functions to the game.
*/
#ifndef IENGINE_H_
#define IENGINE_H_
//forward object declarations (used in some functions below)
struct DecalSlot;
struct VSlot;
struct Texture;
struct editinfo;
class model;
struct undoblock;
struct vslotmap;
struct prefab;
// ragdoll
/**
* @brief Update a ragdoll's position and physics.
*
* If the dynent pointed to does not have a valid ragdoll object as a member,
* nothing happens.
* @param d a dynent pointer.
*/
extern void moveragdoll(dynent *d);
/**
* @brief Deletes the ragdoll associated with the passed dynent.
*
* The function does nothinf if the dynent does not point to a ragdoll object.
* Also, the function does nothing if the dynent is a ragdoll that is not
* present.
* @param d a dynent pointer.
*/
extern void cleanragdoll(dynent *d);
// glemu
namespace gle
{
/**
* @brief Sets the type of primitive to draw.
*
* @param mode one of the GL primitive types (e.g. GL_TRIANGLES, GL_TRIANGLE_STRIP, ..)
*/
extern void begin(GLenum mode);
/**
* @brief Sets up an immediate-like rendering context
*
* Does not use glBegin() or other legacy constructs.
*
* @param mode one of the GL primitive types (e.g. GL_TRIANGLES, GL_TRIANGLE_STRIP, ..)
* @param numverts the number of vertices to draw
*/
extern void begin(GLenum mode, int numverts);
/**
* @brief Adds three float values, packed in a vec, to the attribbuf.
*
* @param v the vec to add to the attribbuf
*/
extern void attrib(const vec &v);
/**
* @brief Adds two float values to the attribbuf.
*
* @param x the first value to add
* @param y the second value to add
*/
extern void attribf(float x, float y);
/**
* @brief Calls glVertexAttrib of the appropriate dimension.
*
* If the alpha value (w) is 0, glVertexAttrib3f is called, else glVertexAttrib4f.
* Sets the color of the attribute currently active.
*
* @param x the red channel (0..1)
* @param y the green channel (0..1)
* @param z the blue channel (0..1)
* @param w the alpha channel (0..1)
*/
extern void colorf(float x, float y, float z, float w = 0.0f);
/**
* @brief Calls glVertexAttrib4Nub to set the color of an attribute.
*
* @param x the red channel (0..255)
* @param y the green channel (0..255)
* @param z the blue channel (0..255)
* @param w the alpha channel (0..255)
*/
extern void colorub(uchar x, uchar y, uchar z, uchar w = 255);
/**
* @brief Sets texcoord0 with the given dimensionality and type.
*
* @param size the number of dimensions to use
* @param the GL format of the dimensions
*/
extern void deftexcoord0(int size = 2, int format = GL_FLOAT);
extern void defvertex(int size = 3, int format = GL_FLOAT);
extern int end();
}
/*==============================================================================*\
* Interface Functions & Values *
* *
* Input, Scripting, Sound, UI *
* *
* command.cpp *
* console.cpp *
* control.cpp *
* cubestd.cpp *
* input.cpp *
* menus.cpp *
* textedit.cpp *
* ui.cpp *
\*==============================================================================*/
// command
/* see command.h */
/**
* @brief Initializes core cubescript commands.
*
* `defvar`
*
* `defvarp`
*
* `deffvarp`
*
* `defsvar`
*
* `defsvarp`
*
* `getvarmin`
*
* `getfvarmin`
*
* `getfvarmax`
*
* `identexists`
*
* `getalias`
*
* `nodebug`
*
* `push`
*
* `alias`
*
* `resetvar`
*/
extern void initcscmds();
// console
/**
* @brief Prints a message to the ingame console.
*
* This function behaves the same way as printf() except it prints to the console
* instead.
*
* @param s the string to print
* @param ... the names of variables to substitute into the string, in order
*/
extern void conoutf(const char *s, ...) PRINTFARGS(1, 2);
/**
* @brief Prints a message to the ingame console, with a specific type flag.
*
* This function behaves the same way as printf() except it prints to the console
* instead. It uses a parameter `type` to indicate what type of console message
* to print. The console flags are defined in consts.h.
*
* @param type the flag to modify the console printout with
* @param s the string to print
* @param ... the names of variables to substitute into the string, in order
*/
extern void conoutf(int type, const char *s, ...) PRINTFARGS(2, 3);
extern int initing;
/**
* @brief Clears the console KeyM history hashtable.
*
* Empties the KeyM hashtable keyms, typicall used when shutting down the program.
*/
extern void clear_console();
/**
* @brief Initializes console cubescript commands.
*
* `fullconsole`
*
* `toggleconsole`
*
* `conskip`
*
* `miniconskip`
*
* `clearconsole`
*
* `keymap`
*
* `bind`
*
* `specbind`
*
* `editbind`
*
* `getbind`
*
* `getspecbind`
*
* `geteditbind`
*
* `searchbinds`
*
* `searchspecbinds`
*
* `searcheditbinds`
*
* `clearbinds`
*
* `clearspecbinds`
*
* `cleareditbinds`
*
* `clearallbinds`
*
* `inputcommand`
*
* `saycommand`
*
* `history`
*
* `onrelease`
*
* `complete`
*
* `listcomplete`
*/
extern void initconsolecmds();
// control
extern int curtime; /** current frame time */
extern int lastmillis; /** last time */
extern int elapsedtime; /** elapsed frame time */
extern int totalmillis; /** total elapsed time */
extern FILE *logfile; /** the file where the */
/**
* @brief Returns the logfile (Linux) or stdout (Windows)
*
* Log files are not supported on Windows, so this function returns stdout if
* on Windows.
*/
FILE *getlogfile();
/**
* @brief Prints a line to the log file.
*
* This function behaves the same way as printf(), except it prints to the
* output specified in `getlogfile()`.
*
* @param fmt The string to print
* @param ... the names of variables to substitute into the string, in order
*/
void logoutf(const char *fmt, ...);
/**
* @brief The dynamic entity representing the player.
*/
extern dynent *player;
extern bool inbetweenframes,
renderedframe;
/**
* @brief Initializes SDL functions necessary to run a game.
*
* Initializes SDL_INIT_TIMER, SDL_INIT_VIDEO, and SDL_INIT_AUDIO.
*/
extern bool initsdl();
/**
* @brief Immediately shuts down the game and prints error message(s)
*
* Shuts down SDL and closes the game immediately. Up to two error messages are
* printed in a SDL message box after exiting the game.
*
* @param s a series of C strings corresponding to error messages
*/
extern void fatal(const char *s, ...) PRINTFARGS(1, 2);
/**
* @brief Returns the number of milliseconds since the game started.
*
* Uses SDL to retrieve the amount of time since the game started.
*/
extern int getclockmillis();
extern int scr_w, scr_h;
extern int desktopw, desktoph;
/**
* @brief Returns the engine library's build date.
*
* Returns the value of __DATE__ macro at the time the engine was built; this
* value is in the format MMM DD YYYY (e.g. Jan 01 1970). The purpose of the
* function is to quickly disambiguate how old a (development) build of the engine
* is.
*
* @return a std::string corresponding to the engine's build date
*/
extern std::string enginebuilddate();
/**
* @brief Returns the engine library's name string
*
* Returns the version string for the engine library, which is a compiled-in
* constant inside the engine library. The purpose of the function is to quickly
* disambiguate different versions of the library.
*
* @return a std::string corresponding to the engine's name string
*/
extern std::string enginestr();
// cubestd
/**
* @brief Adds math commands to the cubescript interpreter
*
* `+` `+f`
* - returns the sum of the passed (int, float) parameters
*
* `*` `*f`
* - returns the product of the passed (int, float) parameters
*
* `-` `-f`
* - returns the first (int, float) minus the remaining parameters
* - if only one parameter is given, returns the unary negative of that value
*
* `=` `=f` `=s`
* - returns whether the (int, float, string) compares equal
*
* `!=` `!=f` `!=f`
* - returns whether the (int, float, string) compares not equal
* - equality for strings is determined by std::strncmp()
*
* `<` `<f` `<s`
* - returns whether the (int, float, string) parameters are ordered in strictly ascending order
* - order for strings is determined by std::strncmp()
*
* `>` `>f` `>s`
* - returns whether the (int, float, string) parameters are ordered in strictly descending order
* - order for strings is determined by std::strncmp()
*
* `<=` `<=f` `<=s`
* - returns whether the (int, float, string) parameters are ordered in non-descending order
* - order for strings is determined by std::strncmp()
*
* `>=` `>=f` `>=s`
* - returns whether the (int, float, string) parameters are ordered in non-ascending order
* - order for strings is determined by std::strncmp()
*
* `!` *tagval* val
* - returns whether the tagval passed evaluates to true (1)
* - all nonzero floats and int values return true
* - all nonnull strings return true
* - null strings, and 0.f/0 return false
*
* `&&` (variadic) *expression* arg1, *expression* arg2...
* - returns the logical AND of the collection of expressions passed
* - AND condition applies to only expressions actually existing (no implied false parameters)
* - if no parameters passed returns 1
* - if one parameter returns the truthiness of that expression
* - if multiple parameters passed returns 1 only if all expressions evaluate true
* - returns false for all other cases
*
* `||` (variadic) *expression* arg1, *expression* arg2...
* - returns the logical OR of the collection of expressions passed
* - OR condition returns 1 if any expression passed evaluates true
* - OR condition returns false if no parameters passed
*
* `div` `divf`
*
* `mod` `modf`
*
* `pow`
*
* `sin` *float* angle
* - returns the sine of the value passed
* - takes values denominated in degrees
*
* `cos` *float* angle
* - returns the cosine of the value passed
* - takes values denominated in degrees
*
* `tan` *float* angle
* - returns the tangent (sine divided by cosine) of the value passed
* - takes values denominated in degrees
*
* `asin` *float* ratio
* - returns the arcsine of the value passed
* - returns values denominated in degrees
*
* `acos` *float* ratio
* - returns the arccosine of the value passed
* - returns values denominated in degrees
*
* `atan` *float* ratio
* - returns the arctangent of the value passed
* - returns values denominated in degrees
*
* `atan2` *float* y *float* x
* - returns the two-parameter arctangent from the two values passed
* - equal to atan(arg1/arg2)
* - returns values denominated in degrees
* - uses Fortran (y,x) formalism
*
* `sqrt` *float* value
* - returns the square root of the value passed
*
* `loge` *float* value
* - returns log base e (Euler's number) of the value passed
*
* `log2` *float* value
* - returns log base 2 of the value passed
*
* `log10` *float* value
* - returns log base 10 of the value passed
*
* `exp` *float* value
* - returns e (Euler's number) to the power passed
*
* `min` `minf` (variadic) *(int, float)* arg1, *(int, float)* arg2...
* - returns the smallest of the list of (int, float) values passed
*
* `max` `maxf` (variadic) *(int, float)* arg1, *(int, float)* arg2...
* - returns the largest of the list of (int, float) values passed
*
* `bitscan` *int* value
* - returns the index of the least significant bit
* - this is one less than the GCC builtin_ffs
*
* `abs` `absf`
* - returns the absolute value of the (int, float) passed
*
* `floor`
*
* `ceil`
*
* `round`
*
* `cond` (variadic) *expression* arg1, *expression* arg2...
* - Evaluates a series of conditions to determine an expression to evaluate and return
* - Odd parameters are conditions and even parameters are consequent expressions to potentially evaluate
* - The first odd parameter (arg1, arg3, etc) to have an expression that evaluates to 1 will have its consequent parameter executed/returned
* - Execution stops with the first valid condition met
* - The final expression is evaluated and returned regardless of antecedent clauses, if no other expression evaluated
* - `cond` with one or zero parameters returns 0 regardless of parameter values
*
* `case`
*
* `casef`
*
* `cases`
*
* `rnd`
*
* `rndstr`
*
* `tohex` *int* value *int* digits
* - Returns a string containing the hexadecimal representation of the given value
* - Number of digits of output is at least `digits` (more if necessary to represent value)
* - Returned is a string beginning with "0x" followed by the hex representation
*
* `strcmp`
*/
extern void initmathcmds();
/**
* @brief Adds string commands to the cubescript interpreter
*
* `echo` *commandstr* expression
* - echoes the parameter passed directly to the console
*
* `error` *commandstr* expression
* - echos the parameter passed out as an error to the console
*
* `strstr` *string* haystack *string* needle
* - finds the first instance of *needle* in the *haystack* string passed, returns int index, wrapper around std::strstr()
*
* `strlen` *string*
* - returns the length of the string passed as an int
*
* `struni`
*
* `unistr`
*
* `strlower` converts the string to lowercase
*
* `strupper` converts the string to uppercase
*
* `strsplice` *string* str *string* vals *int* skip *int* count
* - replaces a substring between indices `skip` and `skip` + `count` with the passed `vals`
* - if the size of `vals` is larger than `count` + 1, the resulting string will be lengthened instead of values overwritten
*
* `strreplace` *string* str *string* oldval *string* newval *string* newval2
* - replaces every instance of `oldval` with `newval`
* - if `newval2` parameter exists, every other `oldval` will be `newval2` (starting with `newval`)
*
* `substr`
*
* `stripcolors` *string* str
* - strips any color formatting from the argument passed
*
* `appendword`
*
* `concat` (variadic) *string* param1, *string* param2...
* - concatenates the strings passed, without inserting spaces between arguments
*
* `concatword` (variadic) *string* param1, *string* param2...
* - concatenates the strings passed, adding a space between each argument
*
* `format` nicely formats the string passed
*/
extern void initstrcmds();
/**
* @brief Adds program control commands to the cubescript interpreter.
*
* `exec` *string* file *int* msg
*
* `escape` *string* str
*
* `unescape` *string* str
*
* `writecfg`
*
* `changedvars`
*
* `doargs`
*
* `if`
*
* `?`
*
* `pushif`
*
* `do`
*
* `append`
*
* `result` *tagval* v
* - Sets the passed tagval as a the command result.
* - If a string literal is passed, the command result is a tagval with that string as its stored value
* - Attempting to get a float/int from a string literal returns 0.0 and 0 respectively
*
* `listlen` *string* list
* - Returns the length of the `list` given
* - List length is not zero indexed, empty lists are the only length 0 list
*
* `at` *string* list *int* index
* - Returns the value at `index` position in `list`
* - List elements are zero-indexed
*
* `sublist`
* - Returns a `count` length subset of the `list` given
* - If no `count` is given then all elements from`skip` to the end of the list are returned
* - If no `skip` is given then all elements will be returned
* - Negative `skip` and `count` values are treated as zero
*
* `listcount` *ident* id *string* list *expression* condition
* - Counts the number of elements in the list that satisfy the given condition
* - `id` is set to the value of each list element before running the condition
* - empty list returns zero
*
* `listfind` *ident* id *string* list *expression* condition
* - Returns the index of the first element in `list` that satisfies the given condition
* - Returned indices are zero-indexed
* - `id` is set to the value of each list element before running the condition
* - If no element found, returns -1
* `listfind=`
*
* `loop` *ident* id *int* num *expression* body
* - Executes body `num` times with `id` set from 0 to `num`-1
* - `id` will become an int regardless of prior type
* - `id` retains its value set at the last loop iteration
*
* `loop+` *ident* id *int* offset *int* num *expression* body
* - Executes body `num` times with `id` set from `offset` to `offset`+`num`-1
* - `id` will become an int regardless of prior type
* - `id` retains its value set at hte last loop iteration
*
* `loop* *ident* id *int* step *int* num *expression* body
* - Executes body `num` times with `id` set from 0 to (`num`-1)*`step`
* - If `step` is zero, `id` is zero for all iterations (`num` iterations)
*
* `loop+*`*ident* id *int* step *int* num *expression* body
* - Executes body `num` times with `id` set from `offset` to (`offset`+`num`-1)*`step`
* - If `step` is zero, `id` is `offset` for all iterations (`num` iterations)
*
* `loopconcat` *ident* id *int* num *expression* body
* - Executes body `num` times with `id` set from 0 to `num`-1
* - Returns a list string containing the returns from the expression `body`
* - Returns values from the `body` expression are delimited by single spaces
* - `id` will become an int regardless of prior type
* - `id` retains its value set at hte last loop iteration
*
* `loopconcat+` *ident* id *int* offset *int* num *expression* body
* - Executes body `num` times with `id` set from `offset` to `offset`+`num`-1
* - Returns values from the `body` expression are delimited by single spaces
*
* `looplist`
*
* `looplist2`
*
* `looplist3`
*
* `listassoc=`
*
* `looplistconcat`
*
* `looplistconcatword`
*
* `prettylist` *string* list *string* conjunction
* - Returns the list formatted with appropriate grammar for an English sentence
* - If there are three or more list elements, or if no conjunction provided, returns a comma-delimited representation
* - If there is exactly two list elements, and a conjunction argument provided, returns list delimited only by conjunction
* - If there is only one list element, no delimiters or conjunctions will be added
* - If there is three or more elements and a conjunction, returns a comma-delimited list with the last element preceded by the conjunction
*
* `indexof` *string* list *string* elem
* - Returns the first index where `elem` is found within `list`
* - All comparisons are done by string equality
* - If nothing in `list` compares equal to `elem`, returns -1
*
* `listdel` *string* list *string* elems
* - Returns the `list` passed with all elements in `elems` removed from it
* - All comparisons done by string equality
*
* `listintersect` *string* list *string* elems
* - Returns the set intersection of `list` and `elems` (both space-delimited strings)
* - All elements both in `list` and `elems` are included in the return set
* - The return set is strictly a subset of both `list` and `elems`
* - The return set is ordered in the same order as `list`
* - Duplicate entries in `list` are preserved in the output set, if such a value is also in `elems`
* - Duplicate entries in `elems` are never preserved in the output set
*
* `listunion` *string* list *string* elems
* - Returns the set union of `list` and `elems` (both space-delimited strings)
* - All elements in `list` are in the return set
* - Elements in `elems` that are not in `list` are appended (up to one per unique entry)
* - Duplicate entries in `list` are preserved in the output set
* - Duplicate entries in `elems` are not preserved in the output set
*
* `loopfiles`
*
* `listsplice` *string* list *string* list2 *int* skip *int* count
* - Splices list2 into list1, optionally overwriting up to `count` elements with spliced-in list
* - List splicing begins after `skip` number of elements (starting from zero)
*
* `findfile`
*
* `sortlist` *string* list *ident* lesser *ident* greater *expression* comparison *expression* unique
* - Sorts the given list (space delimited string) given the provided idents and comparison expression
* - If a unique expression is provided, removes all but one value that compares equal for each unique list element
* - Comparison expression and unique expression take the `lesser` and `greater` parameters to evaluate
* - For example, `sortlist $list lesser greater [<s $lesser $greater] will sort in ascending order
* - An expression that asserts `$greater` < `$lesser` can be used to sort in reverse (descending) order
*
* `uniquelist` *string* list *ident* arg1 *ident* arg2 *expression* unique
* - Removes all redundent list elements that compare equal under the `unique` expression
* - Unique expression takes `arg1` and `arg2` and returns if they compare equal
* - For example `uniquelist $list a b [=s $a $b] will compare a list of strings for strcmp equality
*
* `getmillis`
*
* `sleep`
*
* `clearsleep`
*
*/
extern void initcontrolcmds();
// input
extern bool grabinput,
minimized; /**< Set to 1 if the window is minimized. */
extern bool interceptkey(int sym);
extern void inputgrab(bool on);
/**
* @brief Handles input from SDL.
*
* Executes the CubeScript commands associated with any SDL key operations queued.
*
* @param map the keymap to use: 0 for default, 1 for edit, 2 for spec
*/
extern void checkinput(int map = 0);
/**
* @brief Flushes all queued mouse events.
*
* For all SDL_MOUSEMOTION events currently queued in SDL's event queue, this
* function dumps them one by one while doing nothing. This is used to clear
* any mouse events which may happen while the game is starting up, to ensure
* the cursor spawns in the middle of the screen.
*/
extern void ignoremousemotion();
/**
* @brief Sets the key repeat mask for SDL.
*
* If on is true, sets keyrepeatmask to the OR of the existing mask and the passed mask;
* if on is false, sets keyrepeat mask to the AND of the existing mask and the inverse of the passed mask.
*
* The keyrepeat enum is defined in consts.h with the appropriate masks to pass.
*
* @param on the mode for the mask to be combined
* @param mask the bitmask to apply
*/
extern void keyrepeat(bool on, int mask = ~0);
// menus
extern int mainmenu; /**< toggles if the main menu is shown, bool-like int */
/**
* Initializes menus CubeScript commands.
*
* `applychanges`
*
* `pendingchanges`
*/
extern void initmenuscmds();
//textedit
/**
* @brief Initializes textedit cubescript commands.
*
* `textinit`
*
* `textlist`
*
* `textshow`
*
* `textfocus`
*
* `textprev`
*
* `textmode`
*
* `textsave`
*
* `textload`
*
* `textcopy`
*
* `textpaste`
*
* `textmark`
*
* `textselectall`
*
* `textclear`
*
* `textcurrentline`
*
* `textexec`
*/
extern void inittextcmds();
// UI
namespace UI
{
/**
* @brief Queries UI windows' cursor input ability.
*
* Returns whether the UI system is accepting cursor input; if any windows in
* the UI system accept cursor input, returns True.
*
* @return true if any UI window is accepting cursor input
* @return false if no windows exist that accept cursor input
*/
bool hascursor();
/**
* @brief Queries current UI cursor location.
*
* Returns to the parameters passed by reference the location of the UI cursor.
* This location ranges from 0 to 1.f in x and y, with 0,0 being the bottom
* left part of the screen, and 0.5 0.5 being the middle of the screen.
* The x and y parameters do not scale by aspect ratio, and 1,1 is always the
* top right corner of the screen
*
* @param x variable to assign x-coordinate of the cursor's location to
* @param y variable to assign y-coordinate of the cursor's location to
*/
void getcursorpos(float &x, float &y);
/**
* @brief Sets the cursor to the middle of the screen.
*
* Sets the location of the UI cursor to the middle of the screen; that is,
* the cursor's x and y values are both set to 0.5.
*/
void resetcursor();
/**
* @brief Moves the UI cursor by the amount perscribed.
*
* Moves the UI cursor by the amount described (positive or negative), scaled
* by the UI sensitivity variable. Values are capped in both dimensions between
* 0 and 1, thereby preventing the cursor from completely leaving the screen.
*
* @param dx amount to move the cursor in the x direction
* @param dy amount to move the cursor in the y direction
*/
bool movecursor(int dx, int dy);
/**
* @brief Creates a new UI World object, used globally for UI functionality.
*/
void setup();
/**
* @brief Updates cursor vis a vis the UI elements.
*/
void update();
/**
* @brief Deletes all of the open windows exposed and deletes the UI world object.
*/
void cleanup();
/**
* @brief Shows a UI window with the specified name.
*
* If the specified window does not exist or already is shown, no action is
* taken. Otherwise, displays the window specified.
*
* @param name the name of the UI to show
*
* @return true if the window was shown
* @return false if the window was hidden, or if no window exists
*/
bool showui(const char *name);
/**
* @brief Hides an open UI window with the specified name.
*
* If the specified window is not shown or does not exist, no action is taken,
* Otherwise, hides the open window specified
*
* @param name the name of the UI window to show
*
* @return true if the window was hidden
* @return false if the window was not previously shown or did not exist
*/
bool hideui(const char *name);
/**
* @brief Toggles the open/closed state of a window.
*
* If the speficied window is open, closes the window; if it is closed, opens
* it. If the window does not exist, does nothing.
*
* @param name the name of the window to toggle
*
* @return true if the window was shown
* @return false if the window was hidden, or if no window exists
*/
bool toggleui(const char *name);
/**
* @brief Opens or closes the specified UI.
*
* Opens the specified UI if `on` is `true` and closes it if `on` is false;
* calls either showui() or hideui().
*
* @param name the name of the window to hold
* @param on whether to open or close the specified UI window
*/
void holdui(const char *name, bool on);
/**
* @brief Gets the open/close status of a UI window.
*
* Returns whether the specified window is open or closed (displayed onscreen
* or hidden).
*
* @return true if the window is open
* @return false if the window does not exist or is closed
*/
bool uivisible(const char *name);
/**
* @brief Binds the UI commands to the command parser.
*
* Places into the CubeScript interpreter a series of UI commands, required
* before it is possible to use CubeScript to create UI elements.
*
* Commands defined:
*
* `showui`
*
* `hideui`
*
* `hidetopui`
*
* `hideallui`
*
* `toggleui`
*
* `holdui`
*
* `uivisiblecmd`
*
* `uiname`
*
* `uihover`
*
* `uihover?`
*
* `uihover+`
*
* `uihover+?`
*
* `uipress`
*
* `uipress?`
*
* `uipress+`
*
* `uipress+?`
*
* `uihold`
*
* `uihold?`
*
* `uihold+`
*
* `uihold+?`
*
* `uirelease`
*
* `uirelease?`
*
* `uirelease+`
*
* `uirelease+?`
*
* `uialthold`
*
* `uialthold?`
*
* `uialthold+`
*
* `uialthold+?`
*
* `uialtpress`
*
* `uialtpress?`
*
* `uialtpress+`
*
* `uialtpress+?`
*
* `uialtrelease`
*
* `uialtrelease?`
*
* `uialtrelease+`
*
* `uialtrelease+?`
*
* `uieschold`
*
* `uieschold?`