diff options
author | cinap_lenrek <cinap_lenrek@centraldogma> | 2011-06-02 06:47:50 +0000 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@centraldogma> | 2011-06-02 06:47:50 +0000 |
commit | e4cba4c39a7311fcadc7170d9c7fcd2724928d2a (patch) | |
tree | 4a3b9a329692f9a88514671e18f25fb2f1aa0109 /sys | |
parent | bafa56df02a05521bacac29cdb817b971fd3a700 (diff) |
games/doom:
removed libthread dependency, its not needed
fix menu crash bug
introduce ev_char event type and use it for text
entering like savename and chat.
convert Kaltgr to KEY_RALT
fix skipped initialization when opening /dev/audio
fails. also dont try to write to fd -1
Diffstat (limited to 'sys')
-rw-r--r-- | sys/src/games/doom/d_event.h | 9 | ||||
-rw-r--r-- | sys/src/games/doom/d_main.c | 3 | ||||
-rw-r--r-- | sys/src/games/doom/doomdef.h | 1 | ||||
-rw-r--r-- | sys/src/games/doom/hu_stuff.c | 27 | ||||
-rw-r--r-- | sys/src/games/doom/i_main.c | 5 | ||||
-rw-r--r-- | sys/src/games/doom/i_sound.c | 7 | ||||
-rw-r--r-- | sys/src/games/doom/i_system.c | 4 | ||||
-rw-r--r-- | sys/src/games/doom/i_video.c | 68 | ||||
-rw-r--r-- | sys/src/games/doom/m_menu.c | 67 | ||||
-rw-r--r-- | sys/src/games/doom/st_stuff.c | 22 | ||||
-rw-r--r-- | sys/src/games/doom/v_video.c | 1 |
11 files changed, 124 insertions, 90 deletions
diff --git a/sys/src/games/doom/d_event.h b/sys/src/games/doom/d_event.h index 1a9717ae6..9aacc44fa 100644 --- a/sys/src/games/doom/d_event.h +++ b/sys/src/games/doom/d_event.h @@ -37,16 +37,17 @@ typedef enum ev_keydown, ev_keyup, ev_mouse, - ev_joystick + ev_joystick, + ev_char, } evtype_t; // Event structure. typedef struct { evtype_t type; - int data1; // raw keys / mouse/joystick buttons - int data2; // composed key down, mouse/joystick x move - int data3; // raw key down, mouse/joystick y move + int data1; // char / key / mouse/joystick buttons + int data2; // mouse/joystick x move + int data3; // mouse/joystick y move } event_t; diff --git a/sys/src/games/doom/d_main.c b/sys/src/games/doom/d_main.c index 22e249ccf..490b659bc 100644 --- a/sys/src/games/doom/d_main.c +++ b/sys/src/games/doom/d_main.c @@ -657,7 +657,8 @@ void FindResponseFile (void) handle = fopen (&myargv[i][1],"rb"); if (!handle) { - threadexitsall("No such response file!"); + fprint(2, "No such response file!\n"); + exits("open"); } printf("Found response file %s!\n",&myargv[i][1]); fseek (handle,0,SEEK_END); diff --git a/sys/src/games/doom/doomdef.h b/sys/src/games/doom/doomdef.h index ce024762f..b34992b10 100644 --- a/sys/src/games/doom/doomdef.h +++ b/sys/src/games/doom/doomdef.h @@ -26,7 +26,6 @@ #include <u.h> #include <libc.h> #include <stdio.h> -#include <thread.h> // // Global parameters/defines. diff --git a/sys/src/games/doom/hu_stuff.c b/sys/src/games/doom/hu_stuff.c index 55dea7b2e..6073c6e9f 100644 --- a/sys/src/games/doom/hu_stuff.c +++ b/sys/src/games/doom/hu_stuff.c @@ -507,7 +507,6 @@ boolean HU_Responder(event_t *ev) static char lastmessage[HU_MAXLINELENGTH+1]; char* macromessage; boolean eatkey = false; - static boolean shiftdown = false; static boolean altdown = false; int c; int i; @@ -527,20 +526,21 @@ boolean HU_Responder(event_t *ev) for (i=0 ; i<MAXPLAYERS ; i++) numplayers += playeringame[i]; - if (ev->data1 == KEY_RSHIFT) - { - shiftdown = ev->type == ev_keydown; - return false; - } - else if (ev->data1 == KEY_RALT || ev->data1 == KEY_LALT) - { + switch(ev->type){ + case ev_keydown: + case ev_keyup: + if (ev->data1 == KEY_RALT || ev->data1 == KEY_LALT) + { altdown = ev->type == ev_keydown; return false; + } + /* no break */ + case ev_char: + break; + default: + return false; } - if (ev->type != ev_keydown) - return false; - if (!chat_on) { if (ev->data1 == HU_MSGREFRESH) @@ -588,9 +588,7 @@ boolean HU_Responder(event_t *ev) } else { - c = ev->data2; - if(c == -1) - return false; + c = ev->data1; // send a macro if (altdown) @@ -598,7 +596,6 @@ boolean HU_Responder(event_t *ev) c = c - '0'; if (c < 0 || c > 9) return false; - // fprintf(stderr, "got here\n"); macromessage = chat_macros[c]; // kill last message with a '\n' diff --git a/sys/src/games/doom/i_main.c b/sys/src/games/doom/i_main.c index cce402a34..8538a1408 100644 --- a/sys/src/games/doom/i_main.c +++ b/sys/src/games/doom/i_main.c @@ -4,10 +4,9 @@ #include "m_argv.h" #include "d_main.h" -void threadmain(int argc, char **argv) +void main(int argc, char **argv) { myargc = argc; myargv = argv; - D_DoomMain (); - threadexitsall(nil); + D_DoomMain (); } diff --git a/sys/src/games/doom/i_sound.c b/sys/src/games/doom/i_sound.c index 9c227a90b..ec4142e77 100644 --- a/sys/src/games/doom/i_sound.c +++ b/sys/src/games/doom/i_sound.c @@ -132,10 +132,8 @@ void I_InitSound(void) int i; audio_fd = open("/dev/audio", ORDWR); - if(audio_fd < 0) { + if(audio_fd < 0) printf("WARN Failed to open /dev/audio, sound disabled\n"); - return; - } /* Initialize external data (all sounds) at start, keep static. */ for (i=1 ; i<NUMSFX ; i++) @@ -276,7 +274,8 @@ void I_UpdateSound(void) void I_SubmitSound(void) { - write(audio_fd, mixbuffer, MIXBUFFERSIZE); + if(audio_fd >= 0) + write(audio_fd, mixbuffer, MIXBUFFERSIZE); } void I_ShutdownSound(void) diff --git a/sys/src/games/doom/i_system.c b/sys/src/games/doom/i_system.c index 347d13d2f..7e8c8173b 100644 --- a/sys/src/games/doom/i_system.c +++ b/sys/src/games/doom/i_system.c @@ -45,7 +45,7 @@ void I_Quit (void) I_ShutdownMusic(); M_SaveDefaults (); I_ShutdownGraphics(); - threadexitsall(nil); + exits(nil); } byte* I_AllocLow (int length) @@ -108,7 +108,7 @@ void I_Error (char *error, ...) D_QuitNetGame (); I_ShutdownGraphics(); - threadexitsall("I_Error"); + exits("I_Error"); } int I_FileExists (char *filepath) diff --git a/sys/src/games/doom/i_video.c b/sys/src/games/doom/i_video.c index 34543bc96..4a715ef83 100644 --- a/sys/src/games/doom/i_video.c +++ b/sys/src/games/doom/i_video.c @@ -15,13 +15,18 @@ static int mouseactive; static Rectangle grabout; static Point center; -static void kbdproc(void*); -static void mouseproc(void*); +static void kbdproc(void); +static void mouseproc(void); static uchar cmap[3*256]; +static int kbdpid = -1; +static int mousepid = -1; + void I_InitGraphics(void) { + int pid; + if(initdraw(nil, nil, "doom") < 0) I_Error("I_InitGraphics failed"); @@ -30,14 +35,31 @@ void I_InitGraphics(void) center = addpt(screen->r.min, Pt(Dx(screen->r)/2, Dy(screen->r)/2)); grabout = insetrect(screen->r, Dx(screen->r)/8); - proccreate(kbdproc, nil, 8*1024); - proccreate(mouseproc, nil, 8*1024); + if((pid = rfork(RFPROC|RFMEM|RFFDG)) == 0){ + kbdproc(); + exits(nil); + } + kbdpid = pid; + + if((pid = rfork(RFPROC|RFMEM|RFFDG)) == 0){ + mouseproc(); + exits(nil); + } + mousepid = pid; screens[0] = (unsigned char*) malloc(SCREENWIDTH * SCREENHEIGHT); } void I_ShutdownGraphics(void) { + if(kbdpid != -1){ + postnote(PNPROC, kbdpid, "shutdown"); + kbdpid = -1; + } + if(mousepid != -1){ + postnote(PNPROC, mousepid, "shutdown"); + mousepid = -1; + } } void I_SetPalette(byte *palette) @@ -177,6 +199,8 @@ runetokey(Rune r) case Kctl: return KEY_RCTRL; case Kalt: + return KEY_LALT; + case Kaltgr: return KEY_RALT; case Kbs: @@ -197,22 +221,22 @@ runetokey(Rune r) case KF|11: case KF|12: return KEY_F1+(r-(KF|1)); + + default: + if(r < 0x80) + return r; } - if(r > 0x7f) - return 0; - return r; + return 0; } static void -kbdproc(void *) +kbdproc(void) { char buf[128], buf2[128], *s; int kfd, n; Rune r; event_t e; - threadsetname("kbdproc"); - if((kfd = open("/dev/kbd", OREAD)) < 0) sysfatal("can't open kbd: %r"); @@ -221,15 +245,27 @@ kbdproc(void *) while((n = read(kfd, buf, sizeof(buf))) > 0){ buf[n-1] = 0; + e.data1 = -1; + e.data2 = -1; + e.data3 = -1; + switch(buf[0]){ + case 'c': + chartorune(&r, buf+1); + if(r){ + e.data1 = r; + e.type = ev_char; + D_PostEvent(&e); + } + /* no break */ + default: + continue; case 'k': s = buf+1; while(*s){ s += chartorune(&r, s); if(utfrune(buf2+1, r) == nil){ if(e.data1 = runetokey(r)){ - e.data2 = *s == 0 ? e.data1 : -1; - e.data3 = -1; e.type = ev_keydown; D_PostEvent(&e); } @@ -242,15 +278,12 @@ kbdproc(void *) s += chartorune(&r, s); if(utfrune(buf+1, r) == nil){ if(e.data1 = runetokey(r)){ - e.data2 = e.data3 = -1; e.type = ev_keyup; D_PostEvent(&e); } } } break; - default: - continue; } strcpy(buf2, buf); } @@ -258,15 +291,13 @@ kbdproc(void *) } static void -mouseproc(void *) +mouseproc(void) { int fd, n, nerr; Mouse m, om; char buf[1+5*12]; event_t e; - threadsetname("mouseproc"); - if((fd = open("/dev/mouse", ORDWR)) < 0) sysfatal("can't open mouse: %r"); @@ -276,7 +307,6 @@ mouseproc(void *) for(;;){ n = read(fd, buf, sizeof buf); if(n != 1+4*12){ - yield(); /* if error is due to exiting, we'll exit here */ fprint(2, "mouse: bad count %d not 49: %r\n", n); if(n<0 || ++nerr>10) break; diff --git a/sys/src/games/doom/m_menu.c b/sys/src/games/doom/m_menu.c index e395a39c9..d923b9378 100644 --- a/sys/src/games/doom/m_menu.c +++ b/sys/src/games/doom/m_menu.c @@ -1086,9 +1086,9 @@ void M_QuitDOOM(int /*choice*/) // We pick index 0 which is language sensitive, // or one at random, between 1 and maximum number. if (language != english ) - sprintf(endstring,"%s\n\n"DOSY, endmsg[0] ); + snprintf(endstring, sizeof(endstring), "%s\n\n"DOSY, endmsg[0] ); else - sprintf(endstring,"%s\n\n"DOSY, endmsg[ (gametic%(NUM_QUITMESSAGES-2))+1 ]); + snprintf(endstring, sizeof(endstring), "%s\n\n"DOSY, endmsg[ (gametic%(NUM_QUITMESSAGES-2))+1 ]); M_StartMessage(endstring,M_QuitResponse,true); } @@ -1419,41 +1419,46 @@ boolean M_Responder (event_t* ev) } } else - if (ev->type == ev_keydown) + if (ev->type == ev_keydown || ev->type == ev_char) { - ch = ev->data2; + ch = ev->data1; } } if (ch == -1) return false; - // Save Game string input if (saveStringEnter) { switch(ch) { - case KEY_BACKSPACE: - if (saveCharIndex > 0) - { - saveCharIndex--; - savegamestrings[saveSlot][saveCharIndex] = 0; - } - break; - case KEY_ESCAPE: - saveStringEnter = 0; + if(ev->type != ev_keydown) + return false; + saveStringEnter = 0; strcpy(&savegamestrings[saveSlot][0],saveOldString); break; case KEY_ENTER: + if(ev->type != ev_keydown) + return false; saveStringEnter = 0; if (savegamestrings[saveSlot][0]) M_DoSave(saveSlot); break; default: + if(ev->type != ev_char) + return false; + if (ch == '\b'){ + if (saveCharIndex > 0) + { + saveCharIndex--; + savegamestrings[saveSlot][saveCharIndex] = 0; + } + break; + } ch = toupper(ch); if (ch != 32) if (ch-HU_FONTSTART < 0 || ch-HU_FONTSTART >= HU_FONTSIZE) @@ -1470,6 +1475,9 @@ boolean M_Responder (event_t* ev) } return true; } + + if(ev->type != ev_keydown) + return false; // Take care of any messages that need input if (messageToPrint) @@ -1483,7 +1491,7 @@ boolean M_Responder (event_t* ev) if (messageRoutine) messageRoutine(ch); - menuactive = false; + M_ClearMenus(); S_StartSound(NULL,sfx_swtchx); return true; } @@ -1493,8 +1501,7 @@ boolean M_Responder (event_t* ev) G_ScreenShot (); return true; } - - + // F-Keys if (!menuactive) switch(ch) @@ -1706,7 +1713,7 @@ void M_StartControlPanel (void) if (menuactive) return; - menuactive = 1; + menuactive = true; currentMenu = &MainDef; // JDC itemOn = currentMenu->lastOn; // JDC @@ -1721,15 +1728,15 @@ void M_StartControlPanel (void) // void M_Drawer (void) { - static short x; - static short y; - short i; - short max; + static int x; + static int y; + int i; + int n; + int max; char string[40]; int start; inhelpscreens = false; - // Horiz. & Vertically center string and print it. if (messageToPrint) @@ -1738,18 +1745,18 @@ void M_Drawer (void) y = 100 - M_StringHeight(messageString)/2; while(*(messageString+start)) { - for (i = 0;i < strlen(messageString+start);i++) + n = strlen(messageString+start); + for (i = 0;i < n;i++) if (*(messageString+start+i) == '\n') { - memset(string,0,40); - strncpy(string,messageString+start,i); + snprint(string, sizeof(string), "%.*s", i, messageString+start); start += i+1; break; } - if (i == strlen(messageString+start)) + if (i == n) { - strcpy(string,messageString+start); + snprint(string, sizeof(string), "%s", messageString+start); start += i; } @@ -1792,7 +1799,7 @@ void M_Drawer (void) // void M_ClearMenus (void) { - menuactive = 0; + menuactive = false; I_MouseEnable(1); // enable mouse grabbing // if (!netgame && usergame && paused) @@ -1831,7 +1838,7 @@ void M_Ticker (void) void M_Init (void) { currentMenu = &MainDef; - menuactive = 0; + menuactive = false; itemOn = currentMenu->lastOn; whichSkull = 0; skullAnimCounter = 10; diff --git a/sys/src/games/doom/st_stuff.c b/sys/src/games/doom/st_stuff.c index 3513af6c5..a7c857837 100644 --- a/sys/src/games/doom/st_stuff.c +++ b/sys/src/games/doom/st_stuff.c @@ -543,7 +543,7 @@ ST_Responder (event_t* ev) // if (gameskill != sk_nightmare) { // 'dqd' cheat for toggleable god mode - if (cht_CheckCheat(&cheat_god, ev->data2)) + if (cht_CheckCheat(&cheat_god, ev->data1)) { plyr->cheats ^= CF_GODMODE; if (plyr->cheats & CF_GODMODE) @@ -558,7 +558,7 @@ ST_Responder (event_t* ev) plyr->message = STSTR_DQDOFF; } // 'fa' cheat for killer fucking arsenal - else if (cht_CheckCheat(&cheat_ammonokey, ev->data2)) + else if (cht_CheckCheat(&cheat_ammonokey, ev->data1)) { plyr->armorpoints = 200; plyr->armortype = 2; @@ -572,7 +572,7 @@ ST_Responder (event_t* ev) plyr->message = STSTR_FAADDED; } // 'kfa' cheat for key full ammo - else if (cht_CheckCheat(&cheat_ammo, ev->data2)) + else if (cht_CheckCheat(&cheat_ammo, ev->data1)) { plyr->armorpoints = 200; plyr->armortype = 2; @@ -589,7 +589,7 @@ ST_Responder (event_t* ev) plyr->message = STSTR_KFAADDED; } // 'mus' cheat for changing music - else if (cht_CheckCheat(&cheat_mus, ev->data2)) + else if (cht_CheckCheat(&cheat_mus, ev->data1)) { char buf[3]; @@ -619,8 +619,8 @@ ST_Responder (event_t* ev) } // Simplified, accepting both "noclip" and "idspispopd". // no clipping mode cheat - else if ( cht_CheckCheat(&cheat_noclip, ev->data2) - || cht_CheckCheat(&cheat_commercial_noclip,ev->data2) ) + else if ( cht_CheckCheat(&cheat_noclip, ev->data1) + || cht_CheckCheat(&cheat_commercial_noclip,ev->data1) ) { plyr->cheats ^= CF_NOCLIP; @@ -632,7 +632,7 @@ ST_Responder (event_t* ev) // 'behold?' power-up cheats for (i=0;i<6;i++) { - if (cht_CheckCheat(&cheat_powerup[i], ev->data2)) + if (cht_CheckCheat(&cheat_powerup[i], ev->data1)) { if (!plyr->powers[i]) P_GivePower( plyr, i); @@ -646,19 +646,19 @@ ST_Responder (event_t* ev) } // 'behold' power-up menu - if (cht_CheckCheat(&cheat_powerup[6], ev->data2)) + if (cht_CheckCheat(&cheat_powerup[6], ev->data1)) { plyr->message = STSTR_BEHOLD; } // 'choppers' invulnerability & chainsaw - else if (cht_CheckCheat(&cheat_choppers, ev->data2)) + else if (cht_CheckCheat(&cheat_choppers, ev->data1)) { plyr->weaponowned[wp_chainsaw] = true; plyr->powers[pw_invulnerability] = true; plyr->message = STSTR_CHOPPERS; } // 'mypos' for player position - else if (cht_CheckCheat(&cheat_mypos, ev->data2)) + else if (cht_CheckCheat(&cheat_mypos, ev->data1)) { static char buf[ST_MSGWIDTH]; sprintf(buf, "ang=0x%x;x,y=(0x%x,0x%x)", @@ -670,7 +670,7 @@ ST_Responder (event_t* ev) } // 'clev' change-level cheat - if (cht_CheckCheat(&cheat_clev, ev->data2)) + if (cht_CheckCheat(&cheat_clev, ev->data1)) { char buf[3]; int epsd; diff --git a/sys/src/games/doom/v_video.c b/sys/src/games/doom/v_video.c index 9b30e6483..debdd6103 100644 --- a/sys/src/games/doom/v_video.c +++ b/sys/src/games/doom/v_video.c @@ -228,6 +228,7 @@ V_DrawPatch fprintf( stderr, "Patch at %d,%d exceeds LFB\n", x,y ); // No I_Error abort - what is up with TNT.WAD? fprintf( stderr, "V_DrawPatch: bad patch (ignored)\n"); +abort(); return; } #endif |