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
This commit is contained in:
cinap_lenrek 2011-06-02 06:47:50 +00:00
parent bafa56df02
commit e4cba4c39a
11 changed files with 124 additions and 90 deletions

View file

@ -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;

View file

@ -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);

View file

@ -26,7 +26,6 @@
#include <u.h>
#include <libc.h>
#include <stdio.h>
#include <thread.h>
//
// Global parameters/defines.

View file

@ -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'

View file

@ -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 ();
}

View file

@ -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)

View file

@ -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)

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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