/
i_video.c
1742 lines (1381 loc) · 41 KB
/
i_video.c
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
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
// $Id:$
//
// Copyright (C) 1993-1996 by id Software, Inc.
//
// This source is available for distribution and/or modification
// only under the terms of the DOOM Source Code License as
// published by id Software. All rights reserved.
//
// The source is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
// for more details.
//
// $Log:$
//
// DESCRIPTION:
// DOOM graphics stuff for SDL library
//
//-----------------------------------------------------------------------------
static const char
rcsid[] = "$Id: i_x.c,v 1.6 1997/02/03 22:45:10 b1 Exp $";
#include <stdlib.h>
#include <pspdisplay.h>
#include <pspgu.h>
#include <pspkernel.h>
#include <pspctrl.h>
#include <pspgum.h>
#include "m_config.h"
#include "deh_str.h"
#include "w_wad.h"
#include "z_zone.h"
#include "i_swap.h"
#include "doomkeys.h"
#include "doomstat.h"
#include "i_system.h"
#include "v_video.h"
//#include "m_argv.h"
#include "d_main.h"
#include "doomdef.h"
#define BUF_WIDTH (512)
#define SCR_WIDTH (480)
#define SCR_HEIGHT (272)
#define PIXEL_SIZE (4) // change this if you change to another screenmode
#define FRAME_SIZE (BUF_WIDTH * SCR_HEIGHT * PIXEL_SIZE)
//#define ZBUF_SIZE (BUF_WIDTH * SCR_HEIGHT * 2) // zbuffer seems to be 16-bit?
static byte *disk_image = NULL;
//static byte *saved_background;
//static SceCtrlData ctl;
static SceCtrlData pad;
static SceCtrlData oldpad;
static unsigned int __attribute__((aligned(16))) list[262144];
// display has been set up?
boolean initialized = false;
unsigned int __attribute__((aligned(16))) colors[256];
unsigned char *ilineptr;
void *fbp0;
long SCREENMULT = SCREENWIDTH*SCREENHEIGHT;
// Fake mouse handling.
//boolean grabMouse;
extern boolean wipe;
extern boolean display_ticker;
extern int followplayer;
extern int next_weapon;
extern int frame_limit;
/*
// Lookup table for mapping ASCII characters to their equivalent when
// shift is pressed on an American layout keyboard:
static const char shiftxform[] =
{
0, 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, ' ', '!', '"', '#', '$', '%', '&',
'"', // shift-'
'(', ')', '*', '+',
'<', // shift-,
'_', // shift--
'>', // shift-.
'?', // shift-/
')', // shift-0
'!', // shift-1
'@', // shift-2
'#', // shift-3
'$', // shift-4
'%', // shift-5
'^', // shift-6
'&', // shift-7
'*', // shift-8
'(', // shift-9
':',
':', // shift-;
'<',
'+', // shift-=
'>', '?', '@',
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
'[', // shift-[
'!', // shift-backslash - OH MY GOD DOES WATCOM SUCK
']', // shift-]
'"', '_',
'\'', // shift-`
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
'{', '|', '}', '~', 127
};
#define LOADING_DISK_W 16
#define LOADING_DISK_H 16
// Non aspect ratio-corrected modes (direct multiples of 320x200)
static screen_mode_t *screen_modes[] = {
&mode_scale_1x,
&mode_scale_2x,
&mode_scale_3x,
&mode_scale_4x,
&mode_scale_5x,
};
// Aspect ratio corrected modes (4:3 ratio)
static screen_mode_t *screen_modes_corrected[] = {
// Vertically stretched modes (320x200 -> 320x240 and multiples)
&mode_stretch_1x,
&mode_stretch_2x,
&mode_stretch_3x,
&mode_stretch_4x,
&mode_stretch_5x,
// Horizontally squashed modes (320x200 -> 256x200 and multiples)
&mode_squash_1x,
&mode_squash_2x,
&mode_squash_3x,
&mode_squash_4x,
&mode_squash_5x,
};
// SDL video driver name
char *video_driver = "";
// Window position:
static char *window_position = "";
// SDL surface for the screen.
static SDL_Surface *screen;
// Window title
static char *window_title = "";
// Intermediate 8-bit buffer that we draw to instead of 'screen'.
// This is used when we are rendering in 32-bit screen mode.
// When in a real 8-bit screen mode, screenbuffer == screen.
static SDL_Surface *screenbuffer = NULL;
// palette
static SDL_Color palette[256];
static boolean palette_to_set;
// disable mouse?
static boolean nomouse = false;
int usemouse = 1;
// Bit mask of mouse button state.
static unsigned int mouse_button_state = 0;
// Disallow mouse and joystick movement to cause forward/backward
// motion. Specified with the '-novert' command line parameter.
// This is an int to allow saving to config file
int novert = 0;
// Save screenshots in PNG format.
int png_screenshots = 0;
// if true, I_VideoBuffer is screen->pixels
static boolean native_surface;
// Screen width and height, from configuration file.
int screen_width = SCREENWIDTH;
int screen_height = SCREENHEIGHT;
// Color depth.
int screen_bpp = 0;
// Automatically adjust video settings if the selected mode is
// not a valid video mode.
static int autoadjust_video_settings = 1;
// Run in full screen mode? (int type for config code)
int fullscreen = true;
// Aspect ratio correction mode
int aspect_ratio_correct = true;
// Time to wait for the screen to settle on startup before starting the
// game (ms)
static int startup_delay = 1000;
// Grab the mouse? (int type for config code)
static int grabmouse = true;
// The screen buffer; this is modified to draw things to the screen
byte *I_VideoBuffer = NULL;
// If true, game is running as a screensaver
boolean screensaver_mode = false;
// Flag indicating whether the screen is currently visible:
// when the screen isnt visible, don't render the screen
boolean screenvisible;
// If true, we display dots at the bottom of the screen to
// indicate FPS.
static boolean display_fps_dots;
// If this is true, the screen is rendered but not blitted to the
// video buffer.
static boolean noblit;
// Callback function to invoke to determine whether to grab the
// mouse pointer.
static grabmouse_callback_t grabmouse_callback = NULL;
// disk image data and background overwritten by the disk to be
// restored by EndRead
static boolean window_focused;
// Empty mouse cursor
static SDL_Cursor *cursors[2];
// The screen mode and scale functions being used
static screen_mode_t *screen_mode;
// Window resize state.
static boolean need_resize = false;
static unsigned int resize_w, resize_h;
static unsigned int last_resize_time;
// If true, keyboard mapping is ignored, like in Vanilla Doom.
// The sensible thing to do is to disable this if you have a non-US
// keyboard.
int vanilla_keyboard_mapping = true;
// Is the shift key currently down?
static int shiftdown = 0;
// Mouse acceleration
//
// This emulates some of the behavior of DOS mouse drivers by increasing
// the speed when the mouse is moved fast.
//
// The mouse input values are input directly to the game, but when
// the values exceed the value of mouse_threshold, they are multiplied
// by mouse_acceleration to increase the speed.
float mouse_acceleration = 2.0;
int mouse_threshold = 10;
// Gamma correction level to use
*/
// If true, we display dots at the bottom of the screen to
// indicate FPS.
struct Vertex
{
float u,v;
float x,y,z;
};
static unsigned long control_bef_ctl = 0;
#define KEY_1 0x02
/*
unsigned long key;
#define DO_KEY_EVENT(pspkey, gamekey) \
{ \
if (key & pspkey) \
{ \
kbevent.type = ev_keydown; \
kbevent.data1 = gamekey; \
D_PostEvent(&kbevent); \
} \
else \
{ \
kbevent.type = ev_keyup; \
kbevent.data1 = gamekey; \
D_PostEvent(&kbevent); \
} \
}
*/
extern int button_layout;
unsigned long Read_Key(void)
{
sceCtrlReadBufferPositive(&pad, 1);
if (pad.Buttons == control_bef_ctl)
{
return 0;
}
control_bef_ctl = pad.Buttons;
return control_bef_ctl;
}
boolean dont_move_forwards = false;
void CheckKey(int key, int gamekey)
{
event_t event;
if(pad.Buttons & key && !(oldpad.Buttons & key))
{
event.type = ev_keydown;
event.data1 = gamekey;
D_PostEvent(&event);
}
if(!(pad.Buttons & key) && oldpad.Buttons & key)
{
event.type = ev_keyup;
event.data1 = gamekey;
D_PostEvent(&event);
}
}
//
// I_StartFrame
//
void I_StartFrame (void)
{
static event_t event;
static event_t kbevent;
int xmickeys, ymickeys;
unsigned long key;
oldpad = pad;
sceCtrlPeekBufferPositive(&pad, 1);
// if(button_layout == 0) // FOR PS VITA
{
if(wipe == false) // FOR PSP: check for SCREEN WIPE and if so, DON'T...
{ // ...let ANY key filter through (prevent game hangup)
CheckKey(PSP_CTRL_UP, KEY_UPARROW);
CheckKey(PSP_CTRL_LEFT, KEY_LEFTARROW);
CheckKey(PSP_CTRL_RIGHT, KEY_RIGHTARROW);
CheckKey(PSP_CTRL_DOWN, KEY_DOWNARROW);
CheckKey(PSP_CTRL_TRIANGLE, KEY_TRIANGLE);
CheckKey(PSP_CTRL_CROSS, KEY_CROSS);
CheckKey(PSP_CTRL_SQUARE, KEY_SQUARE);
CheckKey(PSP_CTRL_CIRCLE, KEY_CIRCLE);
CheckKey(PSP_CTRL_SELECT, KEY_SELECT);
CheckKey(PSP_CTRL_START, KEY_START);
CheckKey(PSP_CTRL_LTRIGGER, KEY_LEFTTRIGGER);
CheckKey(PSP_CTRL_RTRIGGER, KEY_RIGHTTRIGGER);
xmickeys = ymickeys = 0;
if(pad.Lx < 40) xmickeys = -16;
if(pad.Lx > 216) xmickeys = 16;
if(pad.Lx < 2) xmickeys = -64;
if(pad.Lx > 253) xmickeys = 64;
if(pad.Ly < 40) ymickeys = -8;
if(pad.Ly > 216) ymickeys = 8;
if(pad.Ly < 2) ymickeys = -32;
if(pad.Ly > 253) ymickeys = 32;
if((xmickeys!=0)||(ymickeys!=0))
{
event.type=ev_mouse;
event.data1=0;
event.data2=xmickeys;
event.data3=-ymickeys;
D_PostEvent(&event);
}
}
}
/*
else if(button_layout == 1) // FOR PSP
{
if(wipe == false) // FOR PSP: check for SCREEN WIPE and if so, DON'T...
{ // ...let ANY key filter through (prevent game hangup)
CheckKey(PSP_CTRL_UP, KEY_UPARROW);
CheckKey(PSP_CTRL_LEFT, KEY_LEFTARROW);
CheckKey(PSP_CTRL_RIGHT, KEY_RIGHTARROW);
CheckKey(PSP_CTRL_DOWN, KEY_DOWNARROW);
CheckKey(PSP_CTRL_TRIANGLE, KEY_TRIANGLE);
CheckKey(PSP_CTRL_CROSS, KEY_CROSS);
CheckKey(PSP_CTRL_SQUARE, KEY_SQUARE);
CheckKey(PSP_CTRL_CIRCLE, KEY_CIRCLE);
CheckKey(PSP_CTRL_SELECT, KEY_SELECT);
CheckKey(PSP_CTRL_START, KEY_START);
CheckKey(PSP_CTRL_LTRIGGER, KEY_LEFTTRIGGER);
CheckKey(PSP_CTRL_RTRIGGER, KEY_RIGHTTRIGGER);
xmickeys = ymickeys = 0;
if(pad.Lx < 40) xmickeys = -16;
if(pad.Lx > 216) xmickeys = 16;
if(pad.Lx < 2) xmickeys = -64;
if(pad.Lx > 253) xmickeys = 64;
if(pad.Ly < 40) ymickeys = -8;
if(pad.Ly > 216) ymickeys = 8;
if(pad.Ly < 2) ymickeys = -32;
if(pad.Ly > 253) ymickeys = 32;
if((xmickeys!=0)||(ymickeys!=0))
{
event.type=ev_mouse;
event.data1=0;
event.data2=xmickeys;
event.data3=-ymickeys;
D_PostEvent(&event);
}
}
}
*/
/* // FOR PSP: WILL KEEP THIS...
if (gamestate == GS_LEVEL && (!menuactive || !automapactive)) // ...HERE (CHANGES WEAPON),...
{ // ...BUT ONLY CHANGES TO...
if(pad.Buttons != oldpad.Buttons) // ...NORMAL WEAPONS...
{ // ...(SWITCHES TO ALTERNATE...
oldpad = pad; // ...WEAPONS ONLY IF WE RUN...
if(pad.Buttons & PSP_CTRL_UP) // ...OUT OF AMMO FOR NORMAL...
{ // ...WEAPONS)
next_weapon = 1;
} // THEREFORE DEACTIVATED
}
}
*/
static player_t* plyrweap;
// BUGGY ??? IN A CERTAIN CASE, IT ACTIVATED AUTOMAP WHILE...
weapontype_t num; // ...IT SHOULDN'T. I MODIFIED THE CODE AFTERWARDS AND IT...
// ...DIDN'T HAPPEN AGAIN FOR ME, BUT IS IT REALLY GONE ???
key = Read_Key();
extern boolean gamekeydown[NUMKEYS];
extern int key_use;
if (gamestate == GS_LEVEL && !(menuactive || automapactive))
{
plyrweap = &players[consoleplayer];
num = plyrweap->readyweapon;
if(pad.Buttons != oldpad.Buttons)
{
oldpad = pad;
if (key & PSP_CTRL_UP && button_layout == 0)
{
while (1)
{
dont_move_forwards = true;
/*
// PSP-FIXME: DOESN'T WORK AS EXPECTED
// (SKIP CHANGING TO GUNS WITH NO AMMO)
if (plyrweap->ammo[weaponinfo[num].ammo] == 0)
{
num = plyrweap->pendingweapon;
}
else
*/
num++;
if (num > wp_supershotgun)
num = wp_fist;
if (plyrweap->weaponowned[num])
{
plyrweap->pendingweapon = num;
break;
}
}
kbevent.type = ev_keydown;
kbevent.data1 = KEY_1 + num;
D_PostEvent(&kbevent);
dont_move_forwards = false;
}
else if (key & PSP_CTRL_UP && button_layout == 1 && gamekeydown[key_use])
{
while (1)
{
dont_move_forwards = true;
/*
// PSP-FIXME: DOESN'T WORK AS EXPECTED
// (SKIP CHANGING TO GUNS WITH NO AMMO)
if (plyrweap->ammo[weaponinfo[num].ammo] == 0)
{
num = plyrweap->pendingweapon;
}
else
*/
num++;
if (num > wp_supershotgun)
num = wp_fist;
if (plyrweap->weaponowned[num])
{
plyrweap->pendingweapon = num;
break;
}
}
kbevent.type = ev_keydown;
kbevent.data1 = KEY_1 + num;
D_PostEvent(&kbevent);
dont_move_forwards = false;
}
}
/* // THE REST OF THE CODE IN THIS FUNCTION IS MOST LIKELY NOT NEEDED FOR PSP
else
{
kbevent.type = ev_keyup;
kbevent.data1 = KEY_1 + num;
D_PostEvent(&kbevent);
}
*/
// if (key & PSP_CTRL_DOWN)
// {
// while (1)
// {
// num--;
// if (num == -1)
// num = wp_supershotgun;
// if (plyrweap->weaponowned[num])
// {
// plyrweap->pendingweapon = num;
// break;
// }
// }
// kbevent.type = ev_keydown;
// kbevent.data1 = KEY_1 + num;
// D_PostEvent(&kbevent);
// }
}
}
/*
static void ApplyWindowResize(unsigned int w, unsigned int h);
static boolean MouseShouldBeGrabbed()
{
// never grab the mouse when in screensaver mode
if (screensaver_mode)
return false;
// if the window doesn't have focus, never grab it
if (!window_focused)
return false;
// always grab the mouse when full screen (dont want to
// see the mouse pointer)
if (fullscreen)
return true;
// Don't grab the mouse if mouse input is disabled
if (!usemouse || nomouse)
return false;
// if we specify not to grab the mouse, never grab
if (!grabmouse)
return false;
// Invoke the grabmouse callback function to determine whether
// the mouse should be grabbed
if (grabmouse_callback != NULL)
{
return grabmouse_callback();
}
else
{
return true;
}
}
void I_SetGrabMouseCallback(grabmouse_callback_t func)
{
grabmouse_callback = func;
}
// Update the value of window_focused when we get a focus event
//
// We try to make ourselves be well-behaved: the grab on the mouse
// is removed if we lose focus (such as a popup window appearing),
// and we dont move the mouse around if we aren't focused either.
static void UpdateFocus(void)
{
Uint8 state;
state = SDL_GetAppState();
// We should have input (keyboard) focus and be visible
// (not minimized)
window_focused = (state & SDL_APPINPUTFOCUS) && (state & SDL_APPACTIVE);
// Should the screen be grabbed?
screenvisible = (state & SDL_APPACTIVE) != 0;
}
// Show or hide the mouse cursor. We have to use different techniques
// depending on the OS.
static void SetShowCursor(boolean show)
{
// On Windows, using SDL_ShowCursor() adds lag to the mouse input,
// so work around this by setting an invisible cursor instead. On
// other systems, it isn't possible to change the cursor, so this
// hack has to be Windows-only. (Thanks to entryway for this)
#ifdef _WIN32
if (show)
{
SDL_SetCursor(cursors[1]);
}
else
{
SDL_SetCursor(cursors[0]);
}
#else
SDL_ShowCursor(show);
#endif
// When the cursor is hidden, grab the input.
if (!screensaver_mode)
{
SDL_WM_GrabInput(!show);
}
}
//
// Translates the SDL key
//
static int TranslateKey(SDL_keysym *sym)
{
switch(sym->sym)
{
case SDLK_LEFT: return KEY_LEFTARROW;
case SDLK_RIGHT: return KEY_RIGHTARROW;
case SDLK_DOWN: return KEY_DOWNARROW;
case SDLK_UP: return KEY_UPARROW;
case SDLK_ESCAPE: return KEY_ESCAPE;
case SDLK_RETURN: return KEY_ENTER;
case SDLK_TAB: return KEY_TAB;
case SDLK_F1: return KEY_F1;
case SDLK_F2: return KEY_F2;
case SDLK_F3: return KEY_F3;
case SDLK_F4: return KEY_F4;
case SDLK_F5: return KEY_F5;
case SDLK_F6: return KEY_F6;
case SDLK_F7: return KEY_F7;
case SDLK_F8: return KEY_F8;
case SDLK_F9: return KEY_F9;
case SDLK_F10: return KEY_F10;
case SDLK_F11: return KEY_F11;
case SDLK_F12: return KEY_F12;
case SDLK_PRINT: return KEY_PRTSCR;
case SDLK_BACKSPACE: return KEY_BACKSPACE;
case SDLK_DELETE: return KEY_DEL;
case SDLK_PAUSE: return KEY_PAUSE;
#if !SDL_VERSION_ATLEAST(1, 3, 0)
case SDLK_EQUALS: return KEY_EQUALS;
#endif
case SDLK_MINUS: return KEY_MINUS;
case SDLK_LSHIFT:
case SDLK_RSHIFT:
return KEY_RSHIFT;
case SDLK_LCTRL:
case SDLK_RCTRL:
return KEY_RCTRL;
case SDLK_LALT:
case SDLK_RALT:
#if !SDL_VERSION_ATLEAST(1, 3, 0)
case SDLK_LMETA:
case SDLK_RMETA:
#endif
return KEY_RALT;
case SDLK_CAPSLOCK: return KEY_CAPSLOCK;
case SDLK_SCROLLOCK: return KEY_SCRLCK;
case SDLK_NUMLOCK: return KEY_NUMLOCK;
case SDLK_KP0: return KEYP_0;
case SDLK_KP1: return KEYP_1;
case SDLK_KP2: return KEYP_2;
case SDLK_KP3: return KEYP_3;
case SDLK_KP4: return KEYP_4;
case SDLK_KP5: return KEYP_5;
case SDLK_KP6: return KEYP_6;
case SDLK_KP7: return KEYP_7;
case SDLK_KP8: return KEYP_8;
case SDLK_KP9: return KEYP_9;
case SDLK_KP_PERIOD: return KEYP_PERIOD;
case SDLK_KP_MULTIPLY: return KEYP_MULTIPLY;
case SDLK_KP_PLUS: return KEYP_PLUS;
case SDLK_KP_MINUS: return KEYP_MINUS;
case SDLK_KP_DIVIDE: return KEYP_DIVIDE;
case SDLK_KP_EQUALS: return KEYP_EQUALS;
case SDLK_KP_ENTER: return KEYP_ENTER;
case SDLK_HOME: return KEY_HOME;
case SDLK_INSERT: return KEY_INS;
case SDLK_END: return KEY_END;
case SDLK_PAGEUP: return KEY_PGUP;
case SDLK_PAGEDOWN: return KEY_PGDN;
#ifdef SDL_HAVE_APP_KEYS
case SDLK_APP1: return KEY_F1;
case SDLK_APP2: return KEY_F2;
case SDLK_APP3: return KEY_F3;
case SDLK_APP4: return KEY_F4;
case SDLK_APP5: return KEY_F5;
case SDLK_APP6: return KEY_F6;
#endif
default:
return tolower(sym->sym);
}
}
static void UpdateMouseButtonState(unsigned int button, boolean on)
{
event_t event;
if (button < SDL_BUTTON_LEFT || button > MAX_MOUSE_BUTTONS)
{
return;
}
// Note: button "0" is left, button "1" is right,
// button "2" is middle for Doom. This is different
// to how SDL sees things.
switch (button)
{
case SDL_BUTTON_LEFT:
button = 0;
break;
case SDL_BUTTON_RIGHT:
button = 1;
break;
case SDL_BUTTON_MIDDLE:
button = 2;
break;
default:
// SDL buttons are indexed from 1.
--button;
break;
}
// Turn bit representing this button on or off.
if (on)
{
mouse_button_state |= (1 << button);
}
else
{
mouse_button_state &= ~(1 << button);
}
// Post an event with the new button state.
event.type = ev_mouse;
event.data1 = mouse_button_state;
event.data2 = event.data3 = 0;
D_PostEvent(&event);
}
static int AccelerateMouse(int val)
{
if (val < 0)
return -AccelerateMouse(-val);
if (val > mouse_threshold)
{
return (int)((val - mouse_threshold) * mouse_acceleration + mouse_threshold);
}
else
{
return val;
}
}
// Get the equivalent ASCII (Unicode?) character for a keypress.
static int GetTypedChar(SDL_Event *event)
{
int key;
// If Vanilla keyboard mapping enabled, the keyboard
// scan code is used to give the character typed.
// This does not change depending on keyboard layout.
// If you have a German keyboard, pressing 'z' will
// give 'y', for example. It is desirable to be able
// to fix this so that people with non-standard
// keyboard mappings can type properly. If vanilla
// mode is disabled, use the properly translated
// version.
if (vanilla_keyboard_mapping)
{
key = TranslateKey(&event->key.keysym);
// Is shift held down? If so, perform a translation.
if (shiftdown > 0)
{
if (key >= 0 && key < arrlen(shiftxform))
{
key = shiftxform[key];
}
else
{
key = 0;
}
}
return key;
}
else
{
// Unicode value, from key layout.
return tolower(event->key.keysym.unicode);
}
}
static void UpdateShiftStatus(SDL_Event *event)
{
int change;
if (event->type == SDL_KEYDOWN)
{
change = 1;
}
else if (event->type == SDL_KEYUP)
{
change = -1;
}
else
{
return;
}
if (event->key.keysym.sym == SDLK_LSHIFT
|| event->key.keysym.sym == SDLK_RSHIFT)
{
shiftdown += change;
}
}
*/
void I_GetEvent(void)
{
/*
SDL_Event sdlevent;
event_t event;
// possibly not needed
SDL_PumpEvents();
// put event-grabbing stuff in here
while (SDL_PollEvent(&sdlevent))
{
// ignore mouse events when the window is not focused
if (!window_focused
&& (sdlevent.type == SDL_MOUSEMOTION
|| sdlevent.type == SDL_MOUSEBUTTONDOWN
|| sdlevent.type == SDL_MOUSEBUTTONUP))
{
continue;
}
if (screensaver_mode && sdlevent.type == SDL_QUIT)
{
I_Quit();
}
UpdateShiftStatus(&sdlevent);
// process event
switch (sdlevent.type)
{
case SDL_KEYDOWN:
// data1 has the key pressed, data2 has the character
// (shift-translated, etc)
event.type = ev_keydown;
event.data1 = TranslateKey(&sdlevent.key.keysym);
event.data2 = GetTypedChar(&sdlevent);
if (event.data1 != 0)
{
D_PostEvent(&event);
}
break;
case SDL_KEYUP:
event.type = ev_keyup;
event.data1 = TranslateKey(&sdlevent.key.keysym);
// data2 is just initialized to zero for ev_keyup.
// For ev_keydown it's the shifted Unicode character
// that was typed, but if something wants to detect