diff options
author | Simon Howard | 2010-08-31 19:26:32 +0000 |
---|---|---|
committer | Simon Howard | 2010-08-31 19:26:32 +0000 |
commit | 22fc405736dc4796958de221c07d52432f1b271b (patch) | |
tree | c05962aa5e839566ea40dd9b1f4ba3581954af8a /src/doom | |
parent | f391d85c96afa91a2302c58191ce8d401fdba2e2 (diff) | |
parent | 64918568eee62c73cbb87aa1bd68e191f19a4af3 (diff) | |
download | chocolate-doom-22fc405736dc4796958de221c07d52432f1b271b.tar.gz chocolate-doom-22fc405736dc4796958de221c07d52432f1b271b.tar.bz2 chocolate-doom-22fc405736dc4796958de221c07d52432f1b271b.zip |
Merge from trunk.
Subversion-branch: /branches/raven-branch
Subversion-revision: 1987
Diffstat (limited to 'src/doom')
-rw-r--r-- | src/doom/d_main.c | 6 | ||||
-rw-r--r-- | src/doom/g_game.c | 184 | ||||
-rw-r--r-- | src/doom/hu_stuff.c | 12 | ||||
-rw-r--r-- | src/doom/r_draw.c | 111 |
4 files changed, 233 insertions, 80 deletions
diff --git a/src/doom/d_main.c b/src/doom/d_main.c index 3fee8439..f3a4b037 100644 --- a/src/doom/d_main.c +++ b/src/doom/d_main.c @@ -358,6 +358,12 @@ void D_BindVariables(void) M_BindWeaponControls(); M_BindMapControls(); M_BindMenuControls(); + M_BindChatControls(MAXPLAYERS); + + key_multi_msgplayer[0] = HUSTR_KEYGREEN; + key_multi_msgplayer[1] = HUSTR_KEYINDIGO; + key_multi_msgplayer[2] = HUSTR_KEYBROWN; + key_multi_msgplayer[3] = HUSTR_KEYRED; #ifdef FEATURE_MULTIPLAYER NET_BindVariables(); diff --git a/src/doom/g_game.c b/src/doom/g_game.c index 9b569594..ad7155a0 100644 --- a/src/doom/g_game.c +++ b/src/doom/g_game.c @@ -176,14 +176,37 @@ static int *weapon_keys[] = { &key_weapon8 }; +// Set to -1 or +1 to switch to the previous or next weapon. + +static int next_weapon = 0; + +// Used for prev/next weapon keys. + +static const struct +{ + weapontype_t weapon; + weapontype_t weapon_num; +} weapon_order_table[] = { + { wp_fist, wp_fist }, + { wp_chainsaw, wp_fist }, + { wp_pistol, wp_pistol }, + { wp_shotgun, wp_shotgun }, + { wp_supershotgun, wp_shotgun }, + { wp_chaingun, wp_chaingun }, + { wp_missile, wp_missile }, + { wp_plasma, wp_plasma }, + { wp_bfg, wp_bfg } +}; + #define SLOWTURNTICS 6 #define NUMKEYS 256 +#define MAX_JOY_BUTTONS 20 static boolean gamekeydown[NUMKEYS]; static int turnheld; // for accelerative turning -static boolean mousearray[4]; +static boolean mousearray[MAX_MOUSE_BUTTONS + 1]; static boolean *mousebuttons = &mousearray[1]; // allow [-1] // mouse values are used once @@ -197,8 +220,6 @@ static int dclicktime2; static boolean dclickstate2; static int dclicks2; -#define MAX_JOY_BUTTONS 20 - // joystick values are repeated static int joyxmove; static int joyymove; @@ -337,7 +358,63 @@ int G_CmdChecksum (ticcmd_t* cmd) return sum; } - + +static boolean WeaponSelectable(weapontype_t weapon) +{ + // Can't select a weapon if we don't own it. + + if (!players[consoleplayer].weaponowned[weapon]) + { + return false; + } + + // Can't select the fist if we have the chainsaw, unless + // we also have the berserk pack. + + if (weapon == wp_fist + && players[consoleplayer].weaponowned[wp_chainsaw] + && !players[consoleplayer].powers[pw_strength]) + { + return false; + } + + return true; +} + +static int G_NextWeapon(int direction) +{ + weapontype_t weapon; + int i; + + // Find index in the table. + + if (players[consoleplayer].pendingweapon == wp_nochange) + { + weapon = players[consoleplayer].readyweapon; + } + else + { + weapon = players[consoleplayer].pendingweapon; + } + + for (i=0; i<arrlen(weapon_order_table); ++i) + { + if (weapon_order_table[i].weapon == weapon) + { + break; + } + } + + // Switch weapon. + + do + { + i += direction; + i = (i + arrlen(weapon_order_table)) % arrlen(weapon_order_table); + } while (!WeaponSelectable(weapon_order_table[i].weapon)); + + return weapon_order_table[i].weapon_num; +} // // G_BuildTiccmd @@ -465,20 +542,34 @@ void G_BuildTiccmd (ticcmd_t* cmd) dclicks = 0; } - // chainsaw overrides + // If the previous or next weapon button is pressed, the + // next_weapon variable is set to change weapons when + // we generate a ticcmd. Choose a new weapon. - for (i=0; i<arrlen(weapon_keys); ++i) + if (next_weapon != 0) { - int key = *weapon_keys[i]; + i = G_NextWeapon(next_weapon); + cmd->buttons |= BT_CHANGE; + cmd->buttons |= i << BT_WEAPONSHIFT; + next_weapon = 0; + } + else + { + // Check weapon keys. - if (gamekeydown[key]) + for (i=0; i<arrlen(weapon_keys); ++i) { - cmd->buttons |= BT_CHANGE; - cmd->buttons |= i<<BT_WEAPONSHIFT; - break; + int key = *weapon_keys[i]; + + if (gamekeydown[key]) + { + cmd->buttons |= BT_CHANGE; + cmd->buttons |= i<<BT_WEAPONSHIFT; + break; + } } } - + // mouse if (mousebuttons[mousebforward]) { @@ -657,7 +748,6 @@ void G_DoLoadLevel (void) players[consoleplayer].message = "Press escape to quit."; } } - static void SetJoyButtons(unsigned int buttons_mask) { @@ -665,10 +755,54 @@ static void SetJoyButtons(unsigned int buttons_mask) for (i=0; i<MAX_JOY_BUTTONS; ++i) { - joybuttons[i] = (buttons_mask & (1 << i)) != 0; + int button_on = (buttons_mask & (1 << i)) != 0; + + // Detect button press: + + if (!joybuttons[i] && button_on) + { + // Weapon cycling: + + if (i == joybprevweapon) + { + next_weapon = -1; + } + else if (i == joybnextweapon) + { + next_weapon = 1; + } + } + + joybuttons[i] = button_on; } } - + +static void SetMouseButtons(unsigned int buttons_mask) +{ + int i; + + for (i=0; i<MAX_MOUSE_BUTTONS; ++i) + { + unsigned int button_on = (buttons_mask & (1 << i)) != 0; + + // Detect button press: + + if (!mousebuttons[i] && button_on) + { + if (i == mousebprevweapon) + { + next_weapon = -1; + } + else if (i == mousebnextweapon) + { + next_weapon = 1; + } + } + + mousebuttons[i] = button_on; + } +} + // // G_Responder // Get info needed to make ticcmd_ts for the players. @@ -677,7 +811,7 @@ boolean G_Responder (event_t* ev) { // allow spy mode changes even during the demo if (gamestate == GS_LEVEL && ev->type == ev_keydown - && ev->data1 == KEY_F12 && (singledemo || !deathmatch) ) + && ev->data1 == key_spy && (singledemo || !deathmatch) ) { // spy mode do @@ -737,6 +871,18 @@ boolean G_Responder (event_t* ev) testcontrols_mousespeed = abs(ev->data2); } + // If the next/previous weapon keys are pressed, set the next_weapon + // variable to change weapons when the next ticcmd is generated. + + if (ev->type == ev_keydown && ev->data1 == key_prevweapon) + { + next_weapon = -1; + } + else if (ev->type == ev_keydown && ev->data1 == key_nextweapon) + { + next_weapon = 1; + } + switch (ev->type) { case ev_keydown: @@ -757,9 +903,7 @@ boolean G_Responder (event_t* ev) return false; // always let key up events filter down case ev_mouse: - mousebuttons[0] = ev->data1 & 1; - mousebuttons[1] = ev->data1 & 2; - mousebuttons[2] = ev->data1 & 4; + SetMouseButtons(ev->data1); mousex = ev->data2*(mouseSensitivity+5)/10; mousey = ev->data3*(mouseSensitivity+5)/10; return true; // eat events @@ -1784,7 +1928,7 @@ void G_WriteDemoTiccmd (ticcmd_t* cmd) { byte *demo_start; - if (gamekeydown['q']) // press q to end demo recording + if (gamekeydown[key_demo_quit]) // press q to end demo recording G_CheckDemoStatus (); demo_start = demo_p; diff --git a/src/doom/hu_stuff.c b/src/doom/hu_stuff.c index 3337f978..f9271b3d 100644 --- a/src/doom/hu_stuff.c +++ b/src/doom/hu_stuff.c @@ -529,14 +529,6 @@ boolean HU_Responder(event_t *ev) int i; int numplayers; - static char destination_keys[MAXPLAYERS] = - { - HUSTR_KEYGREEN, - HUSTR_KEYINDIGO, - HUSTR_KEYBROWN, - HUSTR_KEYRED - }; - static int num_nobrainers = 0; numplayers = 0; @@ -565,7 +557,7 @@ boolean HU_Responder(event_t *ev) message_counter = HU_MSGTIMEOUT; eatkey = true; } - else if (netgame && ev->data2 == HU_INPUTTOGGLE) + else if (netgame && ev->data2 == key_multi_msg) { eatkey = chat_on = true; HUlib_resetIText(&w_chat); @@ -575,7 +567,7 @@ boolean HU_Responder(event_t *ev) { for (i=0; i<MAXPLAYERS ; i++) { - if (ev->data2 == destination_keys[i]) + if (ev->data2 == key_multi_msgplayer[i]) { if (playeringame[i] && i!=consoleplayer) { diff --git a/src/doom/r_draw.c b/src/doom/r_draw.c index 1b6420d9..80362208 100644 --- a/src/doom/r_draw.c +++ b/src/doom/r_draw.c @@ -597,48 +597,54 @@ int dscount; // Draws the actual span. void R_DrawSpan (void) { - fixed_t xfrac; - fixed_t yfrac; - byte* dest; - int count; - int spot; - -#ifdef RANGECHECK + unsigned int position, step; + byte *dest; + int count; + int spot; + unsigned int xtemp, ytemp; + +#ifdef RANGECHECK if (ds_x2 < ds_x1 || ds_x1<0 - || ds_x2>=SCREENWIDTH + || ds_x2>=SCREENWIDTH || (unsigned)ds_y>SCREENHEIGHT) { I_Error( "R_DrawSpan: %i to %i at %i", ds_x1,ds_x2,ds_y); } -// dscount++; -#endif +// dscount++; +#endif + + // Pack position and step variables into a single 32-bit integer, + // with x in the top 16 bits and y in the bottom 16 bits. For + // each 16-bit part, the top 6 bits are the integer part and the + // bottom 10 bits are the fractional part of the pixel position. + + position = ((ds_xfrac << 10) & 0xffff0000) + | ((ds_yfrac >> 6) & 0x0000ffff); + step = ((ds_xstep << 10) & 0xffff0000) + | ((ds_ystep >> 6) & 0x0000ffff); - - xfrac = ds_xfrac; - yfrac = ds_yfrac; - dest = ylookup[ds_y] + columnofs[ds_x1]; // We do not check for zero spans here? - count = ds_x2 - ds_x1; + count = ds_x2 - ds_x1; - do + do { - // Current texture index in u,v. - spot = ((yfrac>>(16-6))&(63*64)) + ((xfrac>>16)&63); + // Calculate current texture index in u,v. + ytemp = (position >> 4) & 0x0fc0; + xtemp = (position >> 26); + spot = xtemp | ytemp; // Lookup pixel from flat texture tile, // re-index using light/colormap. *dest++ = ds_colormap[ds_source[spot]]; - // Next step in u,v. - xfrac += ds_xstep; - yfrac += ds_ystep; - - } while (count--); -} + position += step; + + } while (count--); +} @@ -718,49 +724,54 @@ void R_DrawSpan (void) // // Again.. // -void R_DrawSpanLow (void) -{ - fixed_t xfrac; - fixed_t yfrac; - byte* dest; - int count; - int spot; - -#ifdef RANGECHECK +void R_DrawSpanLow (void) +{ + unsigned int position, step; + unsigned int xtemp, ytemp; + byte *dest; + int count; + int spot; + +#ifdef RANGECHECK if (ds_x2 < ds_x1 || ds_x1<0 - || ds_x2>=SCREENWIDTH + || ds_x2>=SCREENWIDTH || (unsigned)ds_y>SCREENHEIGHT) { I_Error( "R_DrawSpan: %i to %i at %i", ds_x1,ds_x2,ds_y); } // dscount++; -#endif - - xfrac = ds_xfrac; - yfrac = ds_yfrac; - - count = (ds_x2 - ds_x1); +#endif + + position = ((ds_xfrac << 10) & 0xffff0000) + | ((ds_yfrac >> 6) & 0x0000ffff); + step = ((ds_xstep << 10) & 0xffff0000) + | ((ds_ystep >> 6) & 0x0000ffff); + + count = (ds_x2 - ds_x1); // Blocky mode, need to multiply by 2. ds_x1 <<= 1; ds_x2 <<= 1; - + dest = ylookup[ds_y] + columnofs[ds_x1]; - - do - { - spot = ((yfrac>>(16-6))&(63*64)) + ((xfrac>>16)&63); + + do + { + // Calculate current texture index in u,v. + ytemp = (position >> 4) & 0x0fc0; + xtemp = (position >> 26); + spot = xtemp | ytemp; + // Lowres/blocky mode does it twice, // while scale is adjusted appropriately. - *dest++ = ds_colormap[ds_source[spot]]; *dest++ = ds_colormap[ds_source[spot]]; - - xfrac += ds_xstep; - yfrac += ds_ystep; + *dest++ = ds_colormap[ds_source[spot]]; - } while (count--); + position += step; + + } while (count--); } // |