1 /*
2  * This file is part of the Colobot: Gold Edition source code
3  * Copyright (C) 2001-2020, Daniel Roux, EPSITEC SA & TerranovaTeam
4  * http://epsitec.ch; http://colobot.info; http://github.com/colobot
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see http://gnu.org/licenses
18  */
19 
20 /**
21  * \file common/event.h
22  * \brief Event types, structs and event queue
23  */
24 
25 #pragma once
26 
27 #include "common/key.h"
28 #include "common/make_unique.h"
29 
30 #include "common/thread/sdl_mutex_wrapper.h"
31 
32 #include "math/point.h"
33 #include "math/vector.h"
34 
35 #include <memory>
36 
37 /**
38   \enum EventType
39   \brief Type of event message
40  */
41 enum EventType
42 {
43 
44 // TODO: document the meaning of each value
45 
46     //! Invalid event / no event
47     EVENT_NULL              = 0,
48 
49     // System events (originating in CApplication)
50 
51     //! Event sent on system quit request
52     EVENT_SYS_QUIT          = 1,
53 
54     //! Frame update event
55     EVENT_FRAME             = 2,
56 
57     //! Event sent after pressing a mouse button
58     EVENT_MOUSE_BUTTON_DOWN = 3,
59     //! Event sent after releasing a mouse button
60     EVENT_MOUSE_BUTTON_UP   = 4,
61     //! Event sent after moving mouse wheel up or down
62     EVENT_MOUSE_WHEEL       = 5,
63     //! Event sent after moving the mouse
64     EVENT_MOUSE_MOVE        = 7,
65     //! Event sent when mouse enters the window
66     EVENT_MOUSE_ENTER       = 8,
67     //! Event sent when mouse leaves the window
68     EVENT_MOUSE_LEAVE       = 9,
69 
70     //! Event sent after pressing a key
71     EVENT_KEY_DOWN          = 10,
72     //! Event sent after releasing a key
73     EVENT_KEY_UP            = 11,
74     //! Event sent when user inputs some character
75     EVENT_TEXT_INPUT        = 12,
76 
77     //! Event sent after moving joystick axes
78     EVENT_JOY_AXIS          = 13,
79     //! Event sent after pressing a joystick button
80     EVENT_JOY_BUTTON_DOWN   = 14,
81     //! Event sent after releasing a joystick button
82     EVENT_JOY_BUTTON_UP     = 15,
83 
84     //! Event sent when the app winddow gains focus
85     EVENT_FOCUS_GAINED      = 16,
86     //! Event sent when the app winddow loses focus
87     EVENT_FOCUS_LOST        = 17,
88 
89     //!< Maximum value of system events
90     EVENT_SYS_MAX,
91 
92 
93     /* Events sent/received in game and user interface */
94 
95     //! Event sent on user quit request
96     EVENT_QUIT              = 20,
97     EVENT_UPDINTERFACE      = 21,
98     //! Event sent on resolution change
99     EVENT_RESOLUTION_CHANGED = 22,
100     //! Event sent when textures have to be reloaded
101     EVENT_RELOAD_TEXTURES   = 23,
102     EVENT_WIN               = 30,
103     EVENT_LOST              = 31,
104 
105     //! CEdit focus
106     EVENT_FOCUS             = 35,
107 
108     EVENT_BUTTON_OK         = 40,
109     EVENT_BUTTON_CANCEL     = 41,
110     EVENT_BUTTON_NEXT       = 42,
111     EVENT_BUTTON_PREV       = 43,
112 
113     EVENT_BUTTON0           = 50,
114     EVENT_BUTTON1           = 51,
115     EVENT_BUTTON2           = 52,
116     EVENT_BUTTON3           = 53,
117     EVENT_BUTTON4           = 54,
118     EVENT_BUTTON5           = 55,
119     EVENT_BUTTON6           = 56,
120     EVENT_BUTTON7           = 57,
121     EVENT_BUTTON8           = 58,
122     EVENT_BUTTON9           = 59,
123     EVENT_BUTTON10          = 60,
124     EVENT_BUTTON11          = 61,
125     EVENT_BUTTON12          = 62,
126     EVENT_BUTTON13          = 63,
127     EVENT_BUTTON14          = 64,
128     EVENT_BUTTON15          = 65,
129     EVENT_BUTTON16          = 66,
130     EVENT_BUTTON17          = 67,
131     EVENT_BUTTON18          = 68,
132     EVENT_BUTTON19          = 69,
133 
134     EVENT_EDIT0             = 70,
135     EVENT_EDIT1             = 71,
136     EVENT_EDIT2             = 72,
137     EVENT_EDIT3             = 73,
138     EVENT_EDIT4             = 74,
139     EVENT_EDIT5             = 75,
140     EVENT_EDIT6             = 76,
141     EVENT_EDIT7             = 77,
142     EVENT_EDIT8             = 78,
143     EVENT_EDIT9             = 79,
144 
145     EVENT_WINDOW0           = 80,   //!< object interface (CObjectInterface + CAuto classes)
146     EVENT_WINDOW1           = 81,   //!< CMainMap
147     EVENT_WINDOW2           = 82,   //!< CDisplayText
148     EVENT_WINDOW3           = 83,   //!< CStudio
149     EVENT_WINDOW4           = 84,   //!< CDisplayInfo
150     EVENT_WINDOW5           = 85,   //!< all menu windows
151     EVENT_WINDOW6           = 86,   //!< code battle interface
152     EVENT_WINDOW7           = 87,   //!< debug interface
153     EVENT_WINDOW8           = 88,   //!< (unused)
154     EVENT_WINDOW9           = 89,   //!< CMainDialog and CStudio file selector
155 
156     EVENT_LABEL0            = 90,
157     EVENT_LABEL1            = 91,
158     EVENT_LABEL2            = 92,
159     EVENT_LABEL3            = 93,
160     EVENT_LABEL4            = 94,
161     EVENT_LABEL5            = 95,
162     EVENT_LABEL6            = 96,
163     EVENT_LABEL7            = 97,
164     EVENT_LABEL8            = 98,
165     EVENT_LABEL9            = 99,
166     EVENT_LABEL10           = 100,
167     EVENT_LABEL11           = 101,
168     EVENT_LABEL12           = 102,
169     EVENT_LABEL13           = 103,
170     EVENT_LABEL14           = 104,
171     EVENT_LABEL15           = 105,
172     EVENT_LABEL16           = 106,
173     EVENT_LABEL17           = 107,
174     EVENT_LABEL18           = 108,
175     EVENT_LABEL19           = 109, // cursor position overlay
176 
177     EVENT_LIST0             = 110,
178     EVENT_LIST1             = 111,
179     EVENT_LIST2             = 112, // list of resolutions
180     EVENT_LIST3             = 113,
181     EVENT_LIST4             = 114,
182     EVENT_LIST5             = 115,
183     EVENT_LIST6             = 116,
184     EVENT_LIST7             = 117,
185     EVENT_LIST8             = 118,
186     EVENT_LIST9             = 119,
187 
188     EVENT_LOADING           = 120,
189 
190     EVENT_LABEL_CODE_BATTLE = 121,
191 
192     EVENT_SCOREBOARD        = 130,
193     EVENT_SCOREBOARD_MAX    = 169,
194 
195     EVENT_TOOLTIP           = 200,
196 
197     EVENT_DIALOG_OK         = 300,
198     EVENT_DIALOG_CANCEL     = 301,
199     EVENT_DIALOG_LABEL      = 302,
200     EVENT_DIALOG_LABEL1     = 303,
201     EVENT_DIALOG_LABEL2     = 304,
202     EVENT_DIALOG_LABEL3     = 305,
203     EVENT_DIALOG_LIST       = 306,
204     EVENT_DIALOG_EDIT       = 307,
205     EVENT_DIALOG_EDIT2      = 308,
206     EVENT_DIALOG_CHECK1     = 309,
207     EVENT_DIALOG_CHECK2     = 310,
208     EVENT_DIALOG_GROUP1     = 320,
209     EVENT_DIALOG_NEWDIR     = 330,
210     EVENT_DIALOG_ACTION     = 348,
211     EVENT_DIALOG_STOP       = 349,
212 
213     EVENT_INTERFACE_TRAINER = 400,
214     EVENT_INTERFACE_DEFI    = 401,
215     EVENT_INTERFACE_MISSION = 402,
216     EVENT_INTERFACE_FREE    = 403,
217     EVENT_INTERFACE_CODE_BATTLES = 404,
218     EVENT_INTERFACE_NAME    = 405,
219     EVENT_INTERFACE_SETUP   = 406,
220     EVENT_INTERFACE_QUIT    = 407,
221     EVENT_INTERFACE_BACK    = 408,
222     EVENT_INTERFACE_AGAIN   = 409,
223     EVENT_INTERFACE_WRITE   = 410,
224     EVENT_INTERFACE_READ    = 411,
225     EVENT_INTERFACE_ABORT   = 412,
226     EVENT_INTERFACE_USER    = 413,
227     EVENT_INTERFACE_SATCOM  = 414,
228     EVENT_INTERFACE_PLUS    = 415,
229     EVENT_INTERFACE_MODS    = 416,
230 
231     EVENT_INTERFACE_CHAP    = 420,
232     EVENT_INTERFACE_LIST    = 421,
233     EVENT_INTERFACE_RESUME  = 422,
234     EVENT_INTERFACE_PLAY    = 423,
235 
236     EVENT_INTERFACE_SETUPd  = 430,
237     EVENT_INTERFACE_SETUPg  = 431,
238     EVENT_INTERFACE_SETUPp  = 432,
239     EVENT_INTERFACE_SETUPc  = 433,
240     EVENT_INTERFACE_SETUPs  = 434,
241 
242     EVENT_INTERFACE_DEVICE  = 440,
243     EVENT_INTERFACE_RESOL   = 441,
244     EVENT_INTERFACE_FULL    = 442,
245     EVENT_INTERFACE_APPLY   = 443,
246 
247     EVENT_INTERFACE_SHADOW_SPOTS = 451,
248     EVENT_INTERFACE_DIRTY   = 452,
249     EVENT_INTERFACE_LIGHT   = 457,
250     EVENT_INTERFACE_PARTI   = 458,
251     EVENT_INTERFACE_CLIP    = 459,
252     EVENT_INTERFACE_PAUSE_BLUR = 460,
253     EVENT_INTERFACE_RAIN    = 462,
254     EVENT_INTERFACE_GLINT   = 463,
255     EVENT_INTERFACE_TOOLTIP = 464,
256     EVENT_INTERFACE_MOVIES  = 465,
257     EVENT_INTERFACE_SCROLL  = 467,
258     EVENT_INTERFACE_INVERTX = 468,
259     EVENT_INTERFACE_INVERTY = 469,
260     EVENT_INTERFACE_EFFECT  = 470,
261     EVENT_INTERFACE_BGPAUSE = 471,
262     EVENT_INTERFACE_BGMUTE  = 472,
263     EVENT_INTERFACE_FOG     = 474,
264     EVENT_INTERFACE_EDITMODE= 476,
265     EVENT_INTERFACE_EDITVALUE= 477,
266     EVENT_INTERFACE_SOLUCE4 = 478,
267     EVENT_INTERFACE_BLOOD   = 479,
268     EVENT_INTERFACE_AUTOSAVE_ENABLE = 780,
269     EVENT_INTERFACE_AUTOSAVE_INTERVAL = 781,
270     EVENT_INTERFACE_AUTOSAVE_SLOTS = 782,
271     EVENT_INTERFACE_TEXTURE_FILTER = 783,
272     EVENT_INTERFACE_TEXTURE_MIPMAP = 784,
273     EVENT_INTERFACE_TEXTURE_ANISOTROPY = 785,
274     EVENT_INTERFACE_MSAA = 786,
275     EVENT_INTERFACE_SHADOW_MAPPING = 787,
276     EVENT_INTERFACE_SHADOW_MAPPING_QUALITY = 788,
277     EVENT_INTERFACE_SHADOW_MAPPING_BUFFER = 789,
278     EVENT_INTERFACE_LANGUAGE = 790,
279     EVENT_INTERFACE_VSYNC = 791,
280 
281     EVENT_INTERFACE_KINFO1  = 500,
282     EVENT_INTERFACE_KINFO2  = 501,
283     EVENT_INTERFACE_KGROUP  = 502,
284     EVENT_INTERFACE_KSCROLL = 503,
285     EVENT_INTERFACE_KDEF    = 504,
286     // Reserved space for keybindings
287     // This is not the nicest solution, but it'll have to work like that until we move to CEGUI
288     EVENT_INTERFACE_KEY     = 505,
289     EVENT_INTERFACE_KEY_END = 539,
290 
291     EVENT_INTERFACE_MIN     = 540,
292     EVENT_INTERFACE_NORM    = 541,
293     EVENT_INTERFACE_MAX     = 542,
294 
295     EVENT_INTERFACE_VOLSOUND= 550,
296     EVENT_INTERFACE_VOLMUSIC= 551,
297     EVENT_INTERFACE_SILENT  = 552,
298     EVENT_INTERFACE_NOISY   = 553,
299 
300     EVENT_INTERFACE_JOYSTICK= 560,
301     EVENT_INTERFACE_SOLUCE  = 561,
302     EVENT_INTERFACE_JOYSTICK_DEADZONE = 562,
303     EVENT_INTERFACE_JOYSTICK_X = 563,
304     EVENT_INTERFACE_JOYSTICK_Y = 564,
305     EVENT_INTERFACE_JOYSTICK_Z = 565,
306     EVENT_INTERFACE_JOYSTICK_CAM_X = 566,
307     EVENT_INTERFACE_JOYSTICK_CAM_Y = 567,
308     EVENT_INTERFACE_JOYSTICK_CAM_Z = 568,
309     EVENT_INTERFACE_JOYSTICK_X_INVERT = 569,
310     EVENT_INTERFACE_JOYSTICK_Y_INVERT = 570,
311     EVENT_INTERFACE_JOYSTICK_Z_INVERT = 571,
312     EVENT_INTERFACE_JOYSTICK_CAM_X_INVERT = 572,
313     EVENT_INTERFACE_JOYSTICK_CAM_Y_INVERT = 573,
314     EVENT_INTERFACE_JOYSTICK_CAM_Z_INVERT = 574,
315 
316     EVENT_INTERFACE_PLUS_TRAINER  = 575,
317     EVENT_INTERFACE_PLUS_RESEARCH = 576,
318     EVENT_INTERFACE_PLUS_EXPLORER = 577,
319 
320     EVENT_INTERFACE_MOD_LIST = 580,
321     EVENT_INTERFACE_WORKSHOP = 581,
322     EVENT_INTERFACE_MODS_DIR = 582,
323     EVENT_INTERFACE_MOD_ENABLE_OR_DISABLE = 583,
324     EVENT_INTERFACE_MODS_APPLY = 584,
325     EVENT_INTERFACE_MOD_SUMMARY = 585,
326     EVENT_INTERFACE_MOD_DETAILS = 586,
327     EVENT_INTERFACE_MOD_MOVE_UP = 587,
328     EVENT_INTERFACE_MOD_MOVE_DOWN = 888,
329     EVENT_INTERFACE_MODS_REFRESH = 589,
330 
331     EVENT_INTERFACE_GLINTl  = 590,
332     EVENT_INTERFACE_GLINTr  = 591,
333     EVENT_INTERFACE_GLINTu  = 592,
334     EVENT_INTERFACE_GLINTb  = 593,
335 
336     EVENT_INTERFACE_NEDIT   = 595,
337     EVENT_INTERFACE_NLIST   = 596,
338     EVENT_INTERFACE_NOK     = 597,
339     EVENT_INTERFACE_NDELETE = 598,
340     EVENT_INTERFACE_NLABEL  = 599,
341 
342     EVENT_INTERFACE_IOWRITE = 600,
343     EVENT_INTERFACE_IOREAD  = 601,
344     EVENT_INTERFACE_IOLIST  = 602,
345     EVENT_INTERFACE_IONAME  = 603,
346     EVENT_INTERFACE_IOLABEL = 604,
347     EVENT_INTERFACE_IOIMAGE = 605,
348     EVENT_INTERFACE_IODELETE= 606,
349 
350     EVENT_INTERFACE_PERSO   = 620,
351     EVENT_INTERFACE_POK     = 621,
352     EVENT_INTERFACE_PCANCEL = 622,
353     EVENT_INTERFACE_PDEF    = 623,
354     EVENT_INTERFACE_PHEAD   = 624,
355     EVENT_INTERFACE_PBODY   = 625,
356     EVENT_INTERFACE_PLROT   = 626,
357     EVENT_INTERFACE_PRROT   = 627,
358     EVENT_INTERFACE_PC0a    = 640,
359     EVENT_INTERFACE_PC1a    = 641,
360     EVENT_INTERFACE_PC2a    = 642,
361     EVENT_INTERFACE_PC3a    = 643,
362     EVENT_INTERFACE_PC4a    = 644,
363     EVENT_INTERFACE_PC5a    = 645,
364     EVENT_INTERFACE_PC6a    = 646,
365     EVENT_INTERFACE_PC7a    = 647,
366     EVENT_INTERFACE_PC8a    = 648,
367     EVENT_INTERFACE_PC9a    = 649,
368     EVENT_INTERFACE_PCRa    = 650,
369     EVENT_INTERFACE_PCGa    = 651,
370     EVENT_INTERFACE_PCBa    = 652,
371     EVENT_INTERFACE_PC0b    = 660,
372     EVENT_INTERFACE_PC1b    = 661,
373     EVENT_INTERFACE_PC2b    = 662,
374     EVENT_INTERFACE_PC3b    = 663,
375     EVENT_INTERFACE_PC4b    = 664,
376     EVENT_INTERFACE_PC5b    = 665,
377     EVENT_INTERFACE_PC6b    = 666,
378     EVENT_INTERFACE_PC7b    = 667,
379     EVENT_INTERFACE_PC8b    = 668,
380     EVENT_INTERFACE_PC9b    = 669,
381     EVENT_INTERFACE_PCRb    = 670,
382     EVENT_INTERFACE_PCGb    = 671,
383     EVENT_INTERFACE_PCBb    = 672,
384     EVENT_INTERFACE_PFACE1  = 680,
385     EVENT_INTERFACE_PFACE2  = 681,
386     EVENT_INTERFACE_PFACE3  = 682,
387     EVENT_INTERFACE_PFACE4  = 683,
388     EVENT_INTERFACE_PGLASS0 = 690,
389     EVENT_INTERFACE_PGLASS1 = 691,
390     EVENT_INTERFACE_PGLASS2 = 692,
391     EVENT_INTERFACE_PGLASS3 = 693,
392     EVENT_INTERFACE_PGLASS4 = 694,
393     EVENT_INTERFACE_PGLASS5 = 695,
394     EVENT_INTERFACE_PGLASS6 = 696,
395     EVENT_INTERFACE_PGLASS7 = 697,
396     EVENT_INTERFACE_PGLASS8 = 698,
397     EVENT_INTERFACE_PGLASS9 = 699,
398 
399     EVENT_DT_GROUP0         = 700,
400     EVENT_DT_GROUP1         = 701,
401     EVENT_DT_GROUP2         = 702,
402     EVENT_DT_GROUP3         = 703,
403     EVENT_DT_GROUP4         = 704,
404     EVENT_DT_LABEL0         = 710,
405     EVENT_DT_LABEL1         = 711,
406     EVENT_DT_LABEL2         = 712,
407     EVENT_DT_LABEL3         = 713,
408     EVENT_DT_LABEL4         = 714,
409     EVENT_DT_VISIT0         = 720,
410     EVENT_DT_VISIT1         = 721,
411     EVENT_DT_VISIT2         = 722,
412     EVENT_DT_VISIT3         = 723,
413     EVENT_DT_VISIT4         = 724,
414     EVENT_DT_END            = 725,
415 
416     EVENT_CMD               = 800,
417     EVENT_SPEED             = 801,
418 
419     EVENT_DBG_STATS         = 850,
420     EVENT_DBG_SPAWN_OBJ     = 851,
421     EVENT_DBG_TELEPORT      = 852,
422     EVENT_DBG_LIGHTNING     = 853,
423     EVENT_DBG_RESOURCES     = 854,
424     EVENT_DBG_GOTO          = 855,
425     EVENT_DBG_CRASHSPHERES  = 856,
426     EVENT_DBG_LIGHTS        = 857,
427     EVENT_DBG_LIGHTS_DUMP   = 858,
428 
429     EVENT_SPAWN_CANCEL      = 860,
430     EVENT_SPAWN_ME          = 861,
431     EVENT_SPAWN_WHEELEDGRABBER = 862,
432     EVENT_SPAWN_WHEELEDSHOOTER = 863,
433     EVENT_SPAWN_PHAZERSHOOTER  = 864,
434     EVENT_SPAWN_BOTFACTORY  = 865,
435     EVENT_SPAWN_CONVERTER   = 866,
436     EVENT_SPAWN_DERRICK     = 867,
437     EVENT_SPAWN_POWERSTATION= 868,
438     EVENT_SPAWN_TITANIUM    = 869,
439     EVENT_SPAWN_TITANIUMORE = 870,
440     EVENT_SPAWN_URANIUMORE  = 871,
441     EVENT_SPAWN_POWERCELL   = 872,
442     EVENT_SPAWN_NUCLEARCELL = 873,
443 
444     EVENT_HYPER_PREV        = 900,
445     EVENT_HYPER_NEXT        = 901,
446     EVENT_HYPER_HOME        = 902,
447     EVENT_HYPER_COPY        = 903,
448     EVENT_HYPER_SIZE1       = 904,
449     EVENT_HYPER_SIZE2       = 905,
450     EVENT_HYPER_SIZE3       = 906,
451     EVENT_HYPER_SIZE4       = 907,
452     EVENT_HYPER_SIZE5       = 908,
453 
454     EVENT_SATCOM_HUSTON     = 920,
455     EVENT_SATCOM_SAT        = 921,
456     EVENT_SATCOM_LOADING    = 922,
457     EVENT_SATCOM_OBJECT     = 923,
458     EVENT_SATCOM_PROG       = 924,
459     EVENT_SATCOM_SOLUCE     = 925,
460 
461     EVENT_OBJECT_DESELECT   = 1000,
462     EVENT_OBJECT_LEFT       = 1001,
463     EVENT_OBJECT_RIGHT      = 1002,
464     EVENT_OBJECT_UP         = 1003,
465     EVENT_OBJECT_DOWN       = 1004,
466     EVENT_OBJECT_GASUP      = 1005,
467     EVENT_OBJECT_GASDOWN    = 1006,
468     EVENT_OBJECT_HTAKE      = 1020,
469     EVENT_OBJECT_MTAKE      = 1021,
470     EVENT_OBJECT_MFRONT     = 1022,
471     EVENT_OBJECT_MBACK      = 1023,
472     EVENT_OBJECT_MPOWER     = 1024,
473     EVENT_OBJECT_BHELP      = 1040,
474     EVENT_OBJECT_BTAKEOFF   = 1041,
475     EVENT_OBJECT_BDESTROY   = 1042,
476     EVENT_OBJECT_BDERRICK   = 1050,
477     EVENT_OBJECT_BSTATION   = 1051,
478     EVENT_OBJECT_BFACTORY   = 1052,
479     EVENT_OBJECT_BCONVERT   = 1053,
480     EVENT_OBJECT_BTOWER     = 1054,
481     EVENT_OBJECT_BREPAIR    = 1055,
482     EVENT_OBJECT_BRESEARCH  = 1056,
483     EVENT_OBJECT_BRADAR     = 1057,
484     EVENT_OBJECT_BENERGY    = 1058,
485     EVENT_OBJECT_BLABO      = 1059,
486     EVENT_OBJECT_BNUCLEAR   = 1060,
487     EVENT_OBJECT_BPARA      = 1061,
488     EVENT_OBJECT_BINFO      = 1062,
489     EVENT_OBJECT_BSAFE      = 1063,
490     EVENT_OBJECT_GFLAT      = 1070,
491     EVENT_OBJECT_FCREATE    = 1071,
492     EVENT_OBJECT_FDELETE    = 1072,
493     EVENT_OBJECT_FCOLORb    = 1073,
494     EVENT_OBJECT_FCOLORr    = 1074,
495     EVENT_OBJECT_FCOLORg    = 1075,
496     EVENT_OBJECT_FCOLORy    = 1076,
497     EVENT_OBJECT_FCOLORv    = 1077,
498     EVENT_OBJECT_FACTORYwa  = 1080,
499     EVENT_OBJECT_FACTORYta  = 1081,
500     EVENT_OBJECT_FACTORYfa  = 1082,
501     EVENT_OBJECT_FACTORYia  = 1083,
502     EVENT_OBJECT_FACTORYwc  = 1084,
503     EVENT_OBJECT_FACTORYtc  = 1085,
504     EVENT_OBJECT_FACTORYfc  = 1086,
505     EVENT_OBJECT_FACTORYic  = 1087,
506     EVENT_OBJECT_FACTORYwi  = 1088,
507     EVENT_OBJECT_FACTORYti  = 1089,
508     EVENT_OBJECT_FACTORYfi  = 1090,
509     EVENT_OBJECT_FACTORYii  = 1091,
510     EVENT_OBJECT_FACTORYws  = 1092,
511     EVENT_OBJECT_FACTORYts  = 1093,
512     EVENT_OBJECT_FACTORYfs  = 1094,
513     EVENT_OBJECT_FACTORYis  = 1095,
514     EVENT_OBJECT_FACTORYrt  = 1096,
515     EVENT_OBJECT_FACTORYrc  = 1097,
516     EVENT_OBJECT_FACTORYrr  = 1098,
517     EVENT_OBJECT_FACTORYrs  = 1099,
518     EVENT_OBJECT_FACTORYsa  = 1100,
519     EVENT_OBJECT_FACTORYwb  = 1101,
520     EVENT_OBJECT_FACTORYtb  = 1102,
521     EVENT_OBJECT_FACTORYfb  = 1103,
522     EVENT_OBJECT_FACTORYib  = 1104,
523     EVENT_OBJECT_FACTORYtg  = 1105,
524     EVENT_OBJECT_SEARCH     = 1200,
525     EVENT_OBJECT_TERRAFORM  = 1201,
526     EVENT_OBJECT_FIRE       = 1202,
527     EVENT_OBJECT_FIREANT    = 1203,
528     EVENT_OBJECT_SPIDEREXPLO= 1204,
529     EVENT_OBJECT_RECOVER    = 1220,
530     EVENT_OBJECT_BEGSHIELD  = 1221,
531     EVENT_OBJECT_ENDSHIELD  = 1222,
532     EVENT_OBJECT_RTANK      = 1223,
533     EVENT_OBJECT_RFLY       = 1224,
534     EVENT_OBJECT_RTHUMP     = 1225,
535     EVENT_OBJECT_RCANON     = 1226,
536     EVENT_OBJECT_RTOWER     = 1227,
537     EVENT_OBJECT_RPHAZER    = 1228,
538     EVENT_OBJECT_RSHIELD    = 1229,
539     EVENT_OBJECT_RATOMIC    = 1230,
540     EVENT_OBJECT_RiPAW      = 1231,
541     EVENT_OBJECT_RiGUN      = 1232,
542     EVENT_OBJECT_RESET      = 1233,
543     EVENT_OBJECT_DIMSHIELD  = 1234,
544     EVENT_OBJECT_TARGET     = 1235,
545     EVENT_OBJECT_DELSEARCH  = 1236, // delete mark on ground
546     EVENT_OBJECT_PROGLIST   = 1310,
547     EVENT_OBJECT_PROGRUN    = 1311,
548     EVENT_OBJECT_PROGEDIT   = 1312,
549     EVENT_OBJECT_PROGSTART  = 1313,
550     EVENT_OBJECT_PROGSTOP   = 1314,
551     EVENT_OBJECT_PROGADD    = 1315,
552     EVENT_OBJECT_PROGREMOVE = 1316,
553     EVENT_OBJECT_PROGCLONE  = 1317,
554     EVENT_OBJECT_PROGMOVEUP = 1318,
555     EVENT_OBJECT_PROGMOVEDOWN = 1319,
556     EVENT_OBJECT_INFOOK     = 1340,
557     EVENT_OBJECT_DELETE     = 1350,
558     EVENT_OBJECT_GENERGY    = 1360,
559     EVENT_OBJECT_GSHIELD    = 1361,
560     EVENT_OBJECT_GRANGE     = 1362,
561     EVENT_OBJECT_MAP        = 1364,
562     EVENT_OBJECT_MAPZOOM    = 1365,
563     EVENT_OBJECT_GPROGRESS  = 1366,
564     EVENT_OBJECT_GRADAR     = 1367,
565     EVENT_OBJECT_GINFO      = 1368,
566     EVENT_OBJECT_TYPE       = 1369,
567     EVENT_OBJECT_CROSSHAIR  = 1370,
568     EVENT_OBJECT_CORNERul   = 1371,
569     EVENT_OBJECT_CORNERur   = 1372,
570     EVENT_OBJECT_CORNERdl   = 1373,
571     EVENT_OBJECT_CORNERdr   = 1374,
572     EVENT_OBJECT_MAPi       = 1375,
573     EVENT_OBJECT_MAPg       = 1376,
574     EVENT_OBJECT_CAMERA     = 1400,
575     EVENT_OBJECT_HELP       = 1401,
576     EVENT_OBJECT_SOLUCE     = 1402,
577     EVENT_OBJECT_CAMERAleft = 1403,
578     EVENT_OBJECT_CAMERAright= 1404,
579     EVENT_OBJECT_CAMERAnear = 1405,
580     EVENT_OBJECT_CAMERAaway = 1406,
581     EVENT_OBJECT_SHORTCUT_MODE = 1500,
582     EVENT_OBJECT_SHORTCUT   = 1501,
583     EVENT_OBJECT_SHORTCUT_MAX = 1549,
584     EVENT_OBJECT_MOVIELOCK  = 1550,
585     EVENT_OBJECT_EDITLOCK   = 1551,
586     EVENT_OBJECT_SAVING     = 1552,
587     EVENT_OBJECT_LIMIT      = 1560,
588 
589     EVENT_OBJECT_PEN0       = 1570,
590     EVENT_OBJECT_PEN1       = 1571,
591     EVENT_OBJECT_PEN2       = 1572,
592     EVENT_OBJECT_PEN3       = 1573,
593     EVENT_OBJECT_PEN4       = 1574,
594     EVENT_OBJECT_PEN5       = 1575,
595     EVENT_OBJECT_PEN6       = 1576,
596     EVENT_OBJECT_PEN7       = 1577,
597     EVENT_OBJECT_PEN8       = 1578,
598     EVENT_OBJECT_REC        = 1580,
599     EVENT_OBJECT_STOP       = 1581,
600 
601     EVENT_STUDIO_OK         = 2000,
602     EVENT_STUDIO_CANCEL     = 2001,
603     EVENT_STUDIO_EDIT       = 2002,
604     EVENT_STUDIO_LIST       = 2003,
605     EVENT_STUDIO_CLONE      = 2004,
606     EVENT_STUDIO_NEW        = 2010,
607     EVENT_STUDIO_OPEN       = 2011,
608     EVENT_STUDIO_SAVE       = 2012,
609     EVENT_STUDIO_UNDO       = 2013,
610     EVENT_STUDIO_CUT        = 2014,
611     EVENT_STUDIO_COPY       = 2015,
612     EVENT_STUDIO_PASTE      = 2016,
613     EVENT_STUDIO_SIZE       = 2017,
614     EVENT_STUDIO_TOOL       = 2018,
615     EVENT_STUDIO_HELP       = 2019,
616     EVENT_STUDIO_COMPILE    = 2050,
617     EVENT_STUDIO_RUN        = 2051,
618     EVENT_STUDIO_REALTIME   = 2052,
619     EVENT_STUDIO_STEP       = 2053,
620 
621     EVENT_WRITE_SCENE_FINISHED = 2100, //!< indicates end of writing scene (writing screenshot image)
622 
623     EVENT_CODE_BATTLE_START = 2200, //!< button that starts the code battle
624     EVENT_CODE_BATTLE_SPECTATOR = 2201, //!< button that controls the code battle spectator camera
625 
626     EVENT_OBJECT_RBUILDER       = 2300,
627     EVENT_OBJECT_BUILD          = 2301,
628     EVENT_OBJECT_RTARGET        = 2302,
629 
630     //! Buttons that switch viewpoints
631     EVENT_VIEWPOINT0 = 3000,
632     EVENT_VIEWPOINT1 = 3001,
633     EVENT_VIEWPOINT2 = 3002,
634     EVENT_VIEWPOINT3 = 3003,
635     EVENT_VIEWPOINT4 = 3004,
636     EVENT_VIEWPOINT5 = 3005,
637     EVENT_VIEWPOINT6 = 3006,
638     EVENT_VIEWPOINT7 = 3007,
639     EVENT_VIEWPOINT8 = 3008,
640     EVENT_VIEWPOINT9 = 3009,
641     //! Maximum value of standard events
642     EVENT_STD_MAX,
643 
644     EVENT_USER              = 10000,
645     EVENT_FORCE_LONG        = 0x7fffffff
646 };
647 
648 /**
649  * \struct EventData
650  * \brief Base class for additional event data
651  */
652 struct EventData
653 {
~EventDataEventData654     virtual ~EventData()
655     {}
656 
657     virtual std::unique_ptr<EventData> Clone() const = 0;
658 };
659 
660 /**
661  * \struct KeyEventData
662  * \brief Additional data for keyboard event
663  */
664 struct KeyEventData : public EventData
665 {
CloneKeyEventData666     std::unique_ptr<EventData> Clone() const override
667     {
668         return MakeUnique<KeyEventData>(*this);
669     }
670 
671     //! If true, the key is a virtual code generated by certain key modifiers or joystick buttons
672     bool virt = false;
673     //! Key symbol: KEY(...) macro value or virtual key VIRTUAL_... (from common/key.h)
674     unsigned int key = 0;
675     //! Input binding slot for this key
676     InputSlot slot = INPUT_SLOT_MAX;
677 };
678 
679 /**
680  * \struct TextInputData
681  * \brief Additional data for text input event
682  */
683  struct TextInputData : public EventData
684  {
CloneTextInputData685     std::unique_ptr<EventData> Clone() const override
686     {
687         return MakeUnique<TextInputData>(*this);
688     }
689 
690     //! Text entered by the user (usually one character, UTF-8 encoded)
691     std::string text = "";
692  };
693 
694 /**
695  * \enum MouseButton
696  * \brief Mouse button
697  *
698  * Values are a bitmask to have a state bitmask
699  */
700 enum MouseButton
701 {
702     MOUSE_BUTTON_LEFT   = (1<<1),
703     MOUSE_BUTTON_MIDDLE = (1<<2),
704     MOUSE_BUTTON_RIGHT  = (1<<3),
705     //! There may be additional mouse buttons >= this value
706     MOUSE_BUTTON_OTHER  = (1<<4)
707 };
708 
709 /**
710  * \struct MouseButtonEventData
711  * \brief Additional data mouse button event
712  */
713 struct MouseButtonEventData : public EventData
714 {
CloneMouseButtonEventData715     std::unique_ptr<EventData> Clone() const override
716     {
717         return MakeUnique<MouseButtonEventData>(*this);
718     }
719 
720     //! The mouse button
721     MouseButton button = MOUSE_BUTTON_LEFT;
722 };
723 
724 /**
725  * \struct MouseWheelEventData
726  * \brief Additional data for mouse wheel event.
727  */
728 struct MouseWheelEventData : public EventData
729 {
CloneMouseWheelEventData730     std::unique_ptr<EventData> Clone() const override
731     {
732         return MakeUnique<MouseWheelEventData>(*this);
733     }
734 
735     //! Amount scrolled vertically, positive value is away from the user
736     signed int y = 0;
737     //! Amount scrolled horizontally (if the mouse supports it), positive value is to the right
738     signed int x = 0;
739 };
740 
741 /**
742  * \struct JoyAxisEventData
743  * \brief Additional data for joystick axis event
744  */
745 struct JoyAxisEventData : public EventData
746 {
CloneJoyAxisEventData747     std::unique_ptr<EventData> Clone() const override
748     {
749         return MakeUnique<JoyAxisEventData>(*this);
750     }
751 
752     //! The joystick axis index
753     unsigned char axis = 0;
754     //! The axis value (range: -32768 to 32767)
755     int value = 0;
756 };
757 
758 /**
759  * \struct JoyButtonEventData
760  * \brief Additional data for joystick button event
761  */
762 struct JoyButtonEventData : public EventData
763 {
CloneJoyButtonEventData764     std::unique_ptr<EventData> Clone() const override
765     {
766         return MakeUnique<JoyButtonEventData>(*this);
767     }
768 
769     //! The joystick button index
770     unsigned char button = 0;
771 };
772 
773 /**
774  * \struct Event
775  * \brief Event sent by system, interface or game
776  *
777  * Event is described by its type (EventType) and anonymous union that
778  * contains additional data about the event.
779  * Different members of the union are filled with different event types.
780  * With some events, nothing is filled (it's zeroed out).
781  * The union contains roughly the same information as SDL_Event struct
782  * but packaged to independent structs and fields.
783  **/
784 struct Event
785 {
786     explicit Event(EventType type = EVENT_NULL)
typeEvent787      : type(type),
788        rTime(0.0f),
789        kmodState(0),
790        mouseButtonsState(0),
791        customParam(0)
792     {}
793 
794     Event(const Event&) = delete;
795     Event& operator=(const Event&) = delete;
796 
797     // Workaround for MSVC2013
EventEvent798     Event(Event&& other)
799         : type(std::move(other.type)),
800           rTime(std::move(other.rTime)),
801           motionInput(std::move(other.motionInput)),
802           cameraInput(std::move(other.cameraInput)),
803           kmodState(std::move(other.kmodState)),
804           mousePos(std::move(other.mousePos)),
805           mouseButtonsState(std::move(other.mouseButtonsState)),
806           customParam(std::move(other.customParam)),
807           data(std::move(other.data))
808     {}
809 
810     Event& operator=(Event&& other)
811     {
812         type = std::move(other.type);
813         rTime = std::move(other.rTime);
814         motionInput = std::move(other.motionInput);
815         cameraInput = std::move(other.cameraInput);
816         kmodState = std::move(other.kmodState);
817         mousePos = std::move(other.mousePos);
818         mouseButtonsState = std::move(other.mouseButtonsState);
819         customParam = std::move(other.customParam);
820         data = std::move(other.data);
821         return *this;
822     }
823 
824     //! Convenience function for getting appropriate EventData subclass
825     template<typename EventDataSubclass>
GetDataEvent826     EventDataSubclass* GetData()
827     {
828         return static_cast<EventDataSubclass*>(data.get());
829     }
830 
831     //! Convenience function for getting appropriate EventData subclass
832     template<typename EventDataSubclass>
GetDataEvent833     const EventDataSubclass* GetData() const
834     {
835         return static_cast<EventDataSubclass*>(data.get());
836     }
837 
838     //! Returns a clone of this event
CloneEvent839     Event Clone() const
840     {
841         Event clone;
842 
843         clone.type = type;
844         clone.rTime = rTime;
845         clone.motionInput = motionInput;
846         clone.cameraInput = cameraInput;
847         clone.kmodState = kmodState;
848         clone.mousePos = mousePos;
849         clone.mouseButtonsState = mouseButtonsState;
850         clone.customParam = customParam;
851 
852         if (data != nullptr)
853         {
854             clone.data = data->Clone();
855         }
856 
857         return clone;
858     }
859 
860     //! Type of event
861     EventType type;
862 
863     //! Relative time since last EVENT_FRAME
864     //! Scope: only EVENT_FRAME events
865     // TODO: gradually replace the usage of this with new CApplication's time functions
866     float        rTime;
867 
868     //! Motion vector set by keyboard or joystick (managed by CInput)
869     //! Scope: all system events
870     Math::Vector motionInput;
871 
872     //! Motion vector set by numeric keyboard (managed by CInput)
873     //! Scope: all system events
874     Math::Vector cameraInput;
875 
876     //! Current state of keyboard modifier keys: bitmask made of KEY_MOD(...) macro values (from common/key.h)
877     //! Scope: all system events
878     unsigned int kmodState;
879 
880     //! Current position of mouse cursor in interface coords
881     //! Scope: all system events
882     Math::Point  mousePos;
883 
884     //! Current state of mouse buttons: bitmask of MouseButton enum values
885     //! Scope: all system events
886     unsigned int mouseButtonsState;
887 
888     //! Custom parameter that may be set for some events
889     //! Scope: some interface events
890     long         customParam;
891 
892     //! Additional data for some events
893     std::unique_ptr<EventData> data;
894 };
895 
896 
897 //! Returns an unique event type (above the standard IDs)
898 EventType GetUniqueEventType();
899 
900 //! Initializes static array with event type strings
901 void InitializeEventTypeTexts();
902 
903 //! Parses event type to string
904 std::string ParseEventType(EventType eventType);
905 
906 /**
907  * \class CEventQueue
908  * \brief Global event queue
909  *
910  * Provides an interface to a global FIFO queue with events (both system- and user-generated).
911  * The queue has a fixed maximum size but it should not be a problem.
912  *
913  * This class is thread-safe
914  */
915 class CEventQueue
916 {
917 public:
918     //! Constant maximum size of queue
919     static const int MAX_EVENT_QUEUE = 100;
920 
921 public:
922     //! Object's constructor
923     CEventQueue();
924     //! Object's destructor
925     ~CEventQueue();
926 
927     //! Checks if queue is empty
928     bool IsEmpty();
929     //! Adds an event to the queue
930     bool AddEvent(Event&& event);
931     //! Removes and returns an event from queue front; if queue is empty, returns event of type EVENT_NULL
932     Event GetEvent();
933 
934 protected:
935     CSDLMutexWrapper m_mutex;
936     Event        m_fifo[MAX_EVENT_QUEUE];
937     int          m_head;
938     int          m_tail;
939     int          m_total;
940 };
941