/
main.c
1571 lines (1273 loc) · 31.6 KB
/
main.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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <assert.h>
#include "SDL.h"
#include "oglfunc.h"
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <getopt.h>
#include "fixer.h"
#include "3dc.h"
#include "platform.h"
#include "inline.h"
#include "gamedef.h"
#include "gameplat.h"
#include "ffstdio.h"
#include "vision.h"
#include "comp_shp.h"
#include "avp_envinfo.h"
#include "stratdef.h"
#include "bh_types.h"
#include "avp_userprofile.h"
#include "pldnet.h"
#include "cdtrackselection.h"
#include "gammacontrol.h"
#include "opengl.h"
#include "avp_menus.h"
#include "avp_mp_config.h"
#include "npcsetup.h"
#include "cdplayer.h"
#include "hud.h"
#include "player.h"
#include "mempool.h"
#include "avpview.h"
#include "consbind.hpp"
#include "progress_bar.h"
#include "scrshot.hpp"
#include "version.h"
char LevelName[] = {"predbit6\0QuiteALongNameActually"}; /* the real way to load levels */
int DebouncedGotAnyKey;
unsigned char DebouncedKeyboardInput[MAX_NUMBER_OF_INPUT_KEYS];
int GotJoystick;
int GotMouse;
int JoystickEnabled;
int MouseVelX;
int MouseVelY;
extern int ScanDrawMode;
extern SCREENDESCRIPTORBLOCK ScreenDescriptorBlock;
extern unsigned char KeyboardInput[MAX_NUMBER_OF_INPUT_KEYS];
extern unsigned char GotAnyKey;
extern int NormalFrameTime;
SDL_Surface *surface;
SDL_Joystick *joy;
JOYINFOEX JoystickData;
JOYCAPS JoystickCaps;
/* defaults */
static int WantFullscreen = 1;
int WantSound = 1;
static int WantCDRom = 1;
static int WantJoystick = 1;
/* originally was "/usr/lib/libGL.so.1:/usr/lib/tls/libGL.so.1:/usr/X11R6/lib/libGL.so" */
static const char * opengl_library = NULL;
/* ** */
void DirectReadKeyboard()
{
}
void DirectReadMouse()
{
}
void ReadJoysticks()
{
int axes, balls, hats;
Uint8 hat;
JoystickData.dwXpos = 0;
JoystickData.dwYpos = 0;
JoystickData.dwRpos = 0;
JoystickData.dwUpos = 0;
JoystickData.dwVpos = 0;
JoystickData.dwPOV = (DWORD) -1;
if (joy == NULL || !GotJoystick) {
return;
}
SDL_JoystickUpdate();
axes = SDL_JoystickNumAxes(joy);
balls = SDL_JoystickNumBalls(joy);
hats = SDL_JoystickNumHats(joy);
if (axes > 0) {
JoystickData.dwXpos = SDL_JoystickGetAxis(joy, 0) + 32768;
}
if (axes > 1) {
JoystickData.dwYpos = SDL_JoystickGetAxis(joy, 1) + 32768;
}
if (hats > 0) {
hat = SDL_JoystickGetHat(joy, 0);
switch (hat) {
default:
case SDL_HAT_CENTERED:
JoystickData.dwPOV = (DWORD) -1;
break;
case SDL_HAT_UP:
JoystickData.dwPOV = 0;
break;
case SDL_HAT_RIGHT:
JoystickData.dwPOV = 9000;
break;
case SDL_HAT_DOWN:
JoystickData.dwPOV = 18000;
break;
case SDL_HAT_LEFT:
JoystickData.dwPOV = 27000;
break;
case SDL_HAT_RIGHTUP:
JoystickData.dwPOV = 4500;
break;
case SDL_HAT_RIGHTDOWN:
JoystickData.dwPOV = 13500;
break;
case SDL_HAT_LEFTUP:
JoystickData.dwPOV = 31500;
break;
case SDL_HAT_LEFTDOWN:
JoystickData.dwPOV = 22500;
break;
}
}
}
/* ** */
unsigned char *GetScreenShot24(int *width, int *height)
{
unsigned char *buf;
// Uint16 redtable[256], greentable[256], bluetable[256];
if (surface == NULL) {
return NULL;
}
buf = (unsigned char *)malloc(surface->w * surface->h * 3);
if (surface->flags & SDL_OPENGL) {
pglPixelStorei(GL_PACK_ALIGNMENT, 1);
pglPixelStorei(GL_UNPACK_ALIGNMENT, 1);
pglReadPixels(0, 0, surface->w, surface->h, GL_RGB, GL_UNSIGNED_BYTE, buf);
} else {
unsigned char *ptrd;
unsigned short int *ptrs;
int x, y;
if (SDL_MUSTLOCK(surface)) {
if (SDL_LockSurface(surface) < 0) {
free(buf);
return NULL; /* ... */
}
}
ptrd = buf;
for (y = 0; y < surface->h; y++) {
ptrs = (unsigned short *)(((unsigned char *)surface->pixels) + (surface->h-y-1)*surface->pitch);
for (x = 0; x < surface->w; x++) {
unsigned int c;
c = *ptrs;
ptrd[0] = (c & 0xF800)>>8;
ptrd[1] = (c & 0x07E0)>>3;
ptrd[2] = (c & 0x001F)<<3;
ptrs++;
ptrd += 3;
}
}
if (SDL_MUSTLOCK(surface)) {
SDL_UnlockSurface(surface);
}
}
*width = surface->w;
*height = surface->h;
#if 0
if (SDL_GetGammaRamp(redtable, greentable, bluetable) != -1) {
unsigned char *ptr;
int i;
ptr = buf;
for (i = 0; i < surface->w*surface->h; i++) {
ptr[i*3+0] = redtable[ptr[i*3+0]]>>8;
ptr[i*3+1] = greentable[ptr[i*3+1]]>>8;
ptr[i*3+2] = bluetable[ptr[i*3+2]]>>8;
ptr += 3;
}
}
#endif
return buf;
}
/* ** */
PROCESSORTYPES ReadProcessorType()
{
return PType_PentiumMMX;
}
/* ** */
typedef struct VideoModeStruct
{
int w;
int h;
int available;
} VideoModeStruct;
VideoModeStruct VideoModeList[] = {
{ 512, 384, 0 },
{ 640, 480, 0 },
{ 800, 600, 0 },
{ 1024, 768, 0 },
{ 1152, 864, 0 },
{ 1280, 960, 0, },
{ 1280, 1024, 0 },
{ 1600, 1200, 0 }
};
int CurrentVideoMode;
const int TotalVideoModes = sizeof(VideoModeList) / sizeof(VideoModeList[0]);
void LoadDeviceAndVideoModePreferences()
{
FILE *fp;
int mode;
fp = OpenGameFile("AvP_TempVideo.cfg", FILEMODE_READONLY, FILETYPE_CONFIG);
if (fp != NULL) {
if (fscanf(fp, "%d", &mode) == 1) {
fclose(fp);
if (mode >= 0 && mode < TotalVideoModes && VideoModeList[mode].available) {
CurrentVideoMode = mode;
return;
}
} else {
fclose(fp);
}
}
/* No, or invalid, mode found */
/* Try 640x480 first */
if (VideoModeList[1].available) {
CurrentVideoMode = 1;
} else {
int i;
for (i = 0; i < TotalVideoModes; i++) {
if (VideoModeList[i].available) {
CurrentVideoMode = i;
break;
}
}
}
}
void SaveDeviceAndVideoModePreferences()
{
FILE *fp;
fp = OpenGameFile("AvP_TempVideo.cfg", FILEMODE_WRITEONLY, FILETYPE_CONFIG);
if (fp != NULL) {
fprintf(fp, "%d\n", CurrentVideoMode);
fclose(fp);
}
}
void PreviousVideoMode2()
{
int cur = CurrentVideoMode;
do {
if (cur == 0)
cur = TotalVideoModes;
cur--;
if (cur == CurrentVideoMode)
return;
} while(!VideoModeList[cur].available);
CurrentVideoMode = cur;
}
void NextVideoMode2()
{
int cur = CurrentVideoMode;
do {
cur++;
if (cur == TotalVideoModes)
cur = 0;
if (cur == CurrentVideoMode)
return;
} while(!VideoModeList[cur].available);
CurrentVideoMode = cur;
}
char *GetVideoModeDescription2()
{
return "SDL";
}
char *GetVideoModeDescription3()
{
static char buf[64];
snprintf(buf, 64, "%dx%d", VideoModeList[CurrentVideoMode].w, VideoModeList[CurrentVideoMode].h);
return buf;
}
int InitSDL()
{
SDL_Rect **SDL_AvailableVideoModes;
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
fprintf(stderr, "SDL Init failed: %s\n", SDL_GetError());
exit(EXIT_FAILURE);
}
atexit(SDL_Quit);
SDL_AvailableVideoModes = SDL_ListModes(NULL, SDL_FULLSCREEN | SDL_OPENGL);
if (SDL_AvailableVideoModes == NULL)
return -1;
if (SDL_AvailableVideoModes != (SDL_Rect **)-1) {
int i, j, foundit;
foundit = 0;
for (i = 0; i < TotalVideoModes; i++) {
SDL_Rect **modes = SDL_AvailableVideoModes;
for (j = 0; modes[j]; j++) {
if (modes[j]->w >= VideoModeList[i].w &&
modes[j]->h >= VideoModeList[i].h) {
if (SDL_VideoModeOK(VideoModeList[i].w, VideoModeList[i].h, 16, SDL_FULLSCREEN | SDL_OPENGL)) {
/* assume SDL isn't lying to us */
VideoModeList[i].available = 1;
foundit = 1;
}
break;
}
}
}
if (foundit == 0)
return -1;
} else {
int i, foundit;
foundit = 0;
for (i = 0; i < TotalVideoModes; i++) {
if (SDL_VideoModeOK(VideoModeList[i].w, VideoModeList[i].h, 16, SDL_FULLSCREEN | SDL_OPENGL)) {
/* assume SDL isn't lying to us */
VideoModeList[i].available = 1;
foundit = 1;
}
}
if (foundit == 0)
return -1;
}
LoadDeviceAndVideoModePreferences();
if (WantJoystick) {
SDL_InitSubSystem(SDL_INIT_JOYSTICK);
if (SDL_NumJoysticks() > 0) {
/* TODO: make joystick number a configuration parameter */
joy = SDL_JoystickOpen(0);
if (joy) {
GotJoystick = 1;
}
JoystickCaps.wCaps = 0; /* no rudder... ? */
JoystickData.dwXpos = 0;
JoystickData.dwYpos = 0;
JoystickData.dwRpos = 0;
JoystickData.dwUpos = 0;
JoystickData.dwVpos = 0;
JoystickData.dwPOV = (DWORD) -1;
}
}
surface = NULL;
return 0;
}
/* ** */
static void load_opengl_library(const char *lib)
{
char tmppath[PATH_MAX];
size_t len, copylen;
if (lib == NULL) {
if (SDL_GL_LoadLibrary(NULL) == 0) {
/* success */
return;
}
fprintf( stderr, "ERROR: no opengl libraries given\n" );
exit( EXIT_FAILURE );
}
while (lib != NULL && *lib) {
len = strcspn(lib, ":");
copylen = min(len, PATH_MAX-1);
strncpy(tmppath, lib, copylen);
tmppath[copylen] = 0;
if (SDL_GL_LoadLibrary(tmppath) == 0) {
/* success */
return;
}
lib += len;
lib += strspn(lib, ":");
}
fprintf(stderr, "ERROR: unable to initialize opengl library: %s\n", SDL_GetError());
exit(EXIT_FAILURE);
}
int SetSoftVideoMode(int Width, int Height, int Depth)
{
SDL_GrabMode isgrab;
int flags;
load_ogl_functions(0);
/*
let sdl try loading the opengl library, to see if it is even available
this is definitely not enough, but it's a start...
*/
if (!surface || !(surface->flags & SDL_OPENGL)) {
load_opengl_library(opengl_library);
}
ScanDrawMode = ScanDrawD3DHardwareRGB;
GotMouse = 1;
flags = SDL_SWSURFACE|SDL_DOUBLEBUF;
if (surface != NULL) {
if (surface->flags & SDL_FULLSCREEN)
flags |= SDL_FULLSCREEN;
isgrab = SDL_WM_GrabInput(SDL_GRAB_QUERY);
SDL_FreeSurface(surface);
} else {
if (WantFullscreen)
flags |= SDL_FULLSCREEN;
isgrab = SDL_GRAB_OFF;
}
if ((surface = SDL_SetVideoMode(Width, Height, Depth, flags)) == NULL) {
fprintf(stderr, "(Software) SDL SetVideoMode failed: %s\n", SDL_GetError());
exit(EXIT_FAILURE);
}
SDL_WM_SetCaption("Aliens vs Predator", "Aliens vs Predator");
/* this is for supporting keyboard input processing with little hassle */
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
SDL_EnableUNICODE(1); /* toggle it to ON */
if (isgrab == SDL_GRAB_ON)
SDL_WM_GrabInput(SDL_GRAB_ON);
if ((surface->flags & SDL_FULLSCREEN) ||
(SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_ON))
SDL_ShowCursor(0);
ScreenDescriptorBlock.SDB_Width = Width;
ScreenDescriptorBlock.SDB_Height = Height;
ScreenDescriptorBlock.SDB_CentreX = Width/2;
ScreenDescriptorBlock.SDB_CentreY = Height/2;
ScreenDescriptorBlock.SDB_ProjX = Width/2;
ScreenDescriptorBlock.SDB_ProjY = Height/2;
ScreenDescriptorBlock.SDB_ClipLeft = 0;
ScreenDescriptorBlock.SDB_ClipRight = Width;
ScreenDescriptorBlock.SDB_ClipUp = 0;
ScreenDescriptorBlock.SDB_ClipDown = Height;
return 0;
}
int SetOGLVideoMode(int Width, int Height)
{
SDL_GrabMode isgrab;
int flags;
char *ext;
ScanDrawMode = ScanDrawD3DHardwareRGB;
GotMouse = 1;
load_ogl_functions(0);
flags = SDL_OPENGL;
if (surface != NULL) {
if (surface->flags & SDL_FULLSCREEN)
flags |= SDL_FULLSCREEN;
isgrab = SDL_WM_GrabInput(SDL_GRAB_QUERY);
SDL_FreeSurface(surface);
} else {
if (WantFullscreen) {
flags |= SDL_FULLSCREEN;
}
isgrab = SDL_GRAB_OFF;
}
load_opengl_library(opengl_library);
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
if ((surface = SDL_SetVideoMode(Width, Height, 0, flags)) == NULL) {
fprintf(stderr, "(OpenGL) SDL SetVideoMode failed: %s\n", SDL_GetError());
exit(EXIT_FAILURE);
}
load_ogl_functions(1);
SDL_WM_SetCaption("Aliens vs Predator", "Aliens vs Predator");
/* this is for supporting keyboard input processing with little hassle */
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
SDL_EnableUNICODE(1); /* toggle it to ON */
if (isgrab == SDL_GRAB_ON)
SDL_WM_GrabInput(SDL_GRAB_ON);
if ((surface->flags & SDL_FULLSCREEN) ||
(SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_ON))
SDL_ShowCursor(0);
pglViewport(0, 0, Width, Height);
pglMatrixMode(GL_PROJECTION);
pglLoadIdentity();
pglMatrixMode(GL_MODELVIEW);
pglLoadIdentity();
pglEnable(GL_BLEND);
pglBlendFunc(GL_SRC_ALPHA, GL_ONE);
pglEnable(GL_DEPTH_TEST);
pglDepthFunc(GL_LEQUAL);
pglDepthMask(GL_TRUE);
pglDepthRange(0.0, 1.0);
pglEnable(GL_TEXTURE_2D);
pglPolygonMode(GL_FRONT, GL_FILL);
pglPolygonMode(GL_BACK, GL_FILL);
pglDisable(GL_CULL_FACE);
pglClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
pglHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
ScreenDescriptorBlock.SDB_Width = Width;
ScreenDescriptorBlock.SDB_Height = Height;
ScreenDescriptorBlock.SDB_CentreX = Width/2;
ScreenDescriptorBlock.SDB_CentreY = Height/2;
ScreenDescriptorBlock.SDB_ProjX = Width/2;
ScreenDescriptorBlock.SDB_ProjY = Height/2;
ScreenDescriptorBlock.SDB_ClipLeft = 0;
ScreenDescriptorBlock.SDB_ClipRight = Width;
ScreenDescriptorBlock.SDB_ClipUp = 0;
ScreenDescriptorBlock.SDB_ClipDown = Height;
ext = (char *) pglGetString(GL_EXTENSIONS);
load_ogl_functions(1);
InitOpenGL();
return 0;
}
int InitialiseWindowsSystem(HANDLE hInstance, int nCmdShow, int WinInitMode)
{
return 0;
}
int ExitWindowsSystem()
{
if (joy) {
SDL_JoystickClose(joy);
}
load_ogl_functions(0);
if (surface) {
SDL_FreeSurface(surface);
}
surface = NULL;
return 0;
}
static int GotPrintScn, HavePrintScn;
static int KeySymToKey(int keysym)
{
switch(keysym) {
case SDLK_ESCAPE:
return KEY_ESCAPE;
case SDLK_0:
return KEY_0;
case SDLK_1:
return KEY_1;
case SDLK_2:
return KEY_2;
case SDLK_3:
return KEY_3;
case SDLK_4:
return KEY_4;
case SDLK_5:
return KEY_5;
case SDLK_6:
return KEY_6;
case SDLK_7:
return KEY_7;
case SDLK_8:
return KEY_8;
case SDLK_9:
return KEY_9;
case SDLK_a:
return KEY_A;
case SDLK_b:
return KEY_B;
case SDLK_c:
return KEY_C;
case SDLK_d:
return KEY_D;
case SDLK_e:
return KEY_E;
case SDLK_f:
return KEY_F;
case SDLK_g:
return KEY_G;
case SDLK_h:
return KEY_H;
case SDLK_i:
return KEY_I;
case SDLK_j:
return KEY_J;
case SDLK_k:
return KEY_K;
case SDLK_l:
return KEY_L;
case SDLK_m:
return KEY_M;
case SDLK_n:
return KEY_N;
case SDLK_o:
return KEY_O;
case SDLK_p:
return KEY_P;
case SDLK_q:
return KEY_Q;
case SDLK_r:
return KEY_R;
case SDLK_s:
return KEY_S;
case SDLK_t:
return KEY_T;
case SDLK_u:
return KEY_U;
case SDLK_v:
return KEY_V;
case SDLK_w:
return KEY_W;
case SDLK_x:
return KEY_X;
case SDLK_y:
return KEY_Y;
case SDLK_z:
return KEY_Z;
case SDLK_LEFT:
return KEY_LEFT;
case SDLK_RIGHT:
return KEY_RIGHT;
case SDLK_UP:
return KEY_UP;
case SDLK_DOWN:
return KEY_DOWN;
case SDLK_RETURN:
return KEY_CR;
case SDLK_TAB:
return KEY_TAB;
case SDLK_INSERT:
return KEY_INS;
case SDLK_DELETE:
return KEY_DEL;
case SDLK_END:
return KEY_END;
case SDLK_HOME:
return KEY_HOME;
case SDLK_PAGEUP:
return KEY_PAGEUP;
case SDLK_PAGEDOWN:
return KEY_PAGEDOWN;
case SDLK_BACKSPACE:
return KEY_BACKSPACE;
case SDLK_COMMA:
return KEY_COMMA;
case SDLK_PERIOD:
return KEY_FSTOP;
case SDLK_SPACE:
return KEY_SPACE;
case SDLK_LSHIFT:
return KEY_LEFTSHIFT;
case SDLK_RSHIFT:
return KEY_RIGHTSHIFT;
case SDLK_LALT:
return KEY_LEFTALT;
case SDLK_RALT:
return KEY_RIGHTALT;
case SDLK_LCTRL:
return KEY_LEFTCTRL;
case SDLK_RCTRL:
return KEY_RIGHTCTRL;
case SDLK_CAPSLOCK:
return KEY_CAPS;
case SDLK_NUMLOCK:
return KEY_NUMLOCK;
case SDLK_SCROLLOCK:
return KEY_SCROLLOK;
case SDLK_KP0:
return KEY_NUMPAD0;
case SDLK_KP1:
return KEY_NUMPAD1;
case SDLK_KP2:
return KEY_NUMPAD2;
case SDLK_KP3:
return KEY_NUMPAD3;
case SDLK_KP4:
return KEY_NUMPAD4;
case SDLK_KP5:
return KEY_NUMPAD5;
case SDLK_KP6:
return KEY_NUMPAD6;
case SDLK_KP7:
return KEY_NUMPAD7;
case SDLK_KP8:
return KEY_NUMPAD8;
case SDLK_KP9:
return KEY_NUMPAD9;
case SDLK_KP_MINUS:
return KEY_NUMPADSUB;
case SDLK_KP_PLUS:
return KEY_NUMPADADD;
case SDLK_KP_PERIOD:
return KEY_NUMPADDEL;
case SDLK_KP_ENTER:
return KEY_NUMPADENTER;
case SDLK_KP_DIVIDE:
return KEY_NUMPADDIVIDE;
case SDLK_KP_MULTIPLY:
return KEY_NUMPADMULTIPLY;
case SDLK_LEFTBRACKET:
return KEY_LBRACKET;
case SDLK_RIGHTBRACKET:
return KEY_RBRACKET;
case SDLK_SEMICOLON:
return KEY_SEMICOLON;
case SDLK_QUOTE:
return KEY_APOSTROPHE;
case SDLK_BACKQUOTE:
return KEY_GRAVE;
case SDLK_BACKSLASH:
return KEY_BACKSLASH;
case SDLK_SLASH:
return KEY_SLASH;
/* case SDLK_
return KEY_CAPITAL; */
case SDLK_MINUS:
return KEY_MINUS;
case SDLK_EQUALS:
return KEY_EQUALS;
case SDLK_LSUPER:
return KEY_LWIN;
case SDLK_RSUPER:
return KEY_RWIN;
/* case SDLK_
return KEY_APPS; */
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;
/* finish foreign keys */
default:
return -1;
}
}
static void handle_keypress(int key, int unicode, int press)
{
void RE_ENTRANT_QUEUE_WinProc_AddMessage_WM_CHAR(char Ch);
void RE_ENTRANT_QUEUE_WinProc_AddMessage_WM_KEYDOWN(int wParam);
if (key == -1)
return;
if (press) {
switch(key) {
case KEY_BACKSPACE:
RE_ENTRANT_QUEUE_WinProc_AddMessage_WM_KEYDOWN(VK_BACK);
break;
case KEY_END:
RE_ENTRANT_QUEUE_WinProc_AddMessage_WM_KEYDOWN(VK_END);
break;
case KEY_HOME:
RE_ENTRANT_QUEUE_WinProc_AddMessage_WM_KEYDOWN(VK_HOME);
break;
case KEY_LEFT:
RE_ENTRANT_QUEUE_WinProc_AddMessage_WM_KEYDOWN(VK_LEFT);
break;
case KEY_UP:
RE_ENTRANT_QUEUE_WinProc_AddMessage_WM_KEYDOWN(VK_UP);
break;
case KEY_RIGHT:
RE_ENTRANT_QUEUE_WinProc_AddMessage_WM_KEYDOWN(VK_RIGHT);
break;
case KEY_DOWN:
RE_ENTRANT_QUEUE_WinProc_AddMessage_WM_KEYDOWN(VK_DOWN);
break;
case KEY_INS:
RE_ENTRANT_QUEUE_WinProc_AddMessage_WM_KEYDOWN(VK_INSERT);
break;
case KEY_DEL:
RE_ENTRANT_QUEUE_WinProc_AddMessage_WM_KEYDOWN(VK_DELETE);
break;
case KEY_TAB:
RE_ENTRANT_QUEUE_WinProc_AddMessage_WM_KEYDOWN(VK_TAB);
break;
default:
if (unicode && !(unicode & 0xFF80)) {
RE_ENTRANT_QUEUE_WinProc_AddMessage_WM_CHAR(unicode);
KeyboardEntryQueue_Add(unicode);
}
break;
}
}
if (press && !KeyboardInput[key]) {
DebouncedKeyboardInput[key] = 1;
DebouncedGotAnyKey = 1;
}
if (press)
GotAnyKey = 1;
KeyboardInput[key] = press;
}
static void handle_buttonpress(int button, int press)
{
int key;
switch(button) {
case 4: /* mouse wheel up */
key = KEY_MOUSEWHEELUP;
break;
case 5: /* mouse wheel down */
key = KEY_MOUSEWHEELDOWN;
break;
default: /* other buttons are handled elsewhere */
return;
}
/* since this currently only handles wheel up/down */
if (press == 0)
return;
if (press && !KeyboardInput[key]) {
DebouncedKeyboardInput[key] = 1;
}
GotAnyKey = 1;
KeyboardInput[key] = press;
}
void CheckForWindowsMessages()
{
SDL_Event event;
int x, y, buttons, wantmouse;
GotAnyKey = 0;
DebouncedGotAnyKey = 0;
memset(DebouncedKeyboardInput, 0, sizeof(DebouncedKeyboardInput));
wantmouse = (surface->flags & SDL_FULLSCREEN) ||
(SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_ON);
KeyboardInput[KEY_MOUSEWHEELUP] = 0;
KeyboardInput[KEY_MOUSEWHEELDOWN] = 0;
if (SDL_PollEvent(&event)) {
do {
switch(event.type) {
case SDL_MOUSEBUTTONDOWN:
if (wantmouse)
handle_buttonpress(event.button.button, 1);
break;
case SDL_MOUSEBUTTONUP:
break;
case SDL_KEYDOWN:
if (event.key.keysym.sym == SDLK_PRINT) {
if (HavePrintScn == 0)
GotPrintScn = 1;
HavePrintScn = 1;
} else {
handle_keypress(KeySymToKey(event.key.keysym.sym), event.key.keysym.unicode, 1);
}
break;
case SDL_KEYUP:
if (event.key.keysym.sym == SDLK_PRINT) {
GotPrintScn = 0;
HavePrintScn = 0;
} else {
handle_keypress(KeySymToKey(event.key.keysym.sym), 0, 0);
}