2019-12-08 11:28:51 +00:00
|
|
|
/*
|
|
|
|
** c_dispatch.cpp
|
|
|
|
** Functions for executing console commands and aliases
|
|
|
|
**
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
** Copyright 1998-2016 Randy Heit
|
|
|
|
** Copyright 2003-2019 Christoph Oelckers
|
|
|
|
** All rights reserved.
|
|
|
|
**
|
|
|
|
** Redistribution and use in source and binary forms, with or without
|
|
|
|
** modification, are permitted provided that the following conditions
|
|
|
|
** are met:
|
|
|
|
**
|
|
|
|
** 1. Redistributions of source code must retain the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer.
|
|
|
|
** 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer in the
|
|
|
|
** documentation and/or other materials provided with the distribution.
|
|
|
|
** 3. The name of the author may not be used to endorse or promote products
|
|
|
|
** derived from this software without specific prior written permission.
|
|
|
|
**
|
|
|
|
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
**
|
|
|
|
*/
|
2019-11-03 17:19:29 +00:00
|
|
|
|
|
|
|
#include "c_bind.h"
|
|
|
|
#include "d_event.h"
|
2019-11-09 22:58:26 +00:00
|
|
|
#include "c_console.h"
|
2019-11-03 17:19:29 +00:00
|
|
|
#include "d_gui.h"
|
2019-11-03 23:55:49 +00:00
|
|
|
#include "inputstate.h"
|
2019-11-21 21:31:46 +00:00
|
|
|
#include "menu.h"
|
2020-08-24 17:55:21 +00:00
|
|
|
#include "gamestate.h"
|
|
|
|
#include "gamecontrol.h"
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// AM_Responder
|
|
|
|
// Handle automap exclusive bindings.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
bool AM_Responder (event_t *ev, bool last)
|
|
|
|
{
|
|
|
|
if (ev->type == EV_KeyDown || ev->type == EV_KeyUp)
|
|
|
|
{
|
|
|
|
#if 0 // this feature does not exist yet.
|
|
|
|
if (automapFollow)
|
|
|
|
{
|
|
|
|
// check for am_pan* and ignore in follow mode
|
|
|
|
const char *defbind = AutomapBindings.GetBind(ev->data1);
|
|
|
|
if (defbind && !strnicmp(defbind, "+am_pan", 7)) return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
bool res = C_DoKey(ev, &AutomapBindings, nullptr);
|
|
|
|
if (res && ev->type == EV_KeyUp && !last)
|
|
|
|
{
|
|
|
|
// If this is a release event we also need to check if it released a button in the main Bindings
|
|
|
|
// so that that button does not get stuck.
|
|
|
|
const char *defbind = Bindings.GetBind(ev->data1);
|
|
|
|
return (!defbind || defbind[0] != '+'); // Let G_Responder handle button releases
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-11-03 17:19:29 +00:00
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// G_Responder
|
|
|
|
// Process the event for the game
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
bool G_Responder (event_t *ev)
|
|
|
|
{
|
2020-08-24 17:55:21 +00:00
|
|
|
if (gamestate == GS_LEVEL && automapMode == am_full && AM_Responder(ev, false)) return true;
|
|
|
|
|
2019-11-03 17:19:29 +00:00
|
|
|
switch (ev->type)
|
|
|
|
{
|
|
|
|
case EV_KeyDown:
|
2020-08-24 17:55:21 +00:00
|
|
|
if (C_DoKey (ev, &Bindings, &DoubleBindings))
|
2019-11-03 17:19:29 +00:00
|
|
|
return true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EV_KeyUp:
|
2020-08-24 17:55:21 +00:00
|
|
|
C_DoKey (ev, &Bindings, &DoubleBindings);
|
2019-11-03 17:19:29 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
// [RH] mouse buttons are sent as key up/down events
|
|
|
|
case EV_Mouse:
|
|
|
|
mousex = (int)(ev->x * mouse_sensitivity);
|
|
|
|
mousey = (int)(ev->y * mouse_sensitivity);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-08 11:28:51 +00:00
|
|
|
// [RH] If the view is active, give the automap a chance at
|
|
|
|
// the events *last* so that any bound keys get precedence.
|
2020-08-24 17:55:21 +00:00
|
|
|
if (gamestate == GS_LEVEL && automapMode == am_overlay)
|
|
|
|
return AM_Responder (ev, true);
|
2019-11-03 17:19:29 +00:00
|
|
|
|
|
|
|
return (ev->type == EV_KeyDown ||
|
|
|
|
ev->type == EV_Mouse);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// D_PostEvent
|
|
|
|
//
|
|
|
|
// Called by the I/O functions when input is detected.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
2019-11-09 21:22:51 +00:00
|
|
|
void sendKeyForBinding(int key);
|
2019-11-03 17:19:29 +00:00
|
|
|
|
|
|
|
void D_PostEvent (const event_t *ev)
|
|
|
|
{
|
|
|
|
// Do not post duplicate consecutive EV_DeviceChange events.
|
|
|
|
if (ev->type == EV_DeviceChange && events[eventhead].type == EV_DeviceChange)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2019-11-10 14:15:14 +00:00
|
|
|
|
2020-04-23 19:18:40 +00:00
|
|
|
if (ev->type == EV_Mouse && !System_WantGuiCapture())
|
2019-11-03 17:19:29 +00:00
|
|
|
{
|
2019-12-31 00:46:54 +00:00
|
|
|
inputState.MouseAddToPos(ev->x, -ev->y);
|
2019-11-10 14:15:14 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-11-09 21:22:51 +00:00
|
|
|
|
2019-11-03 23:55:49 +00:00
|
|
|
inputState.AddEvent(ev);
|
|
|
|
|
2019-11-10 14:15:14 +00:00
|
|
|
// Also add it to the event queue.
|
|
|
|
events[eventhead] = *ev;
|
2020-06-14 16:57:55 +00:00
|
|
|
eventhead = (eventhead+1)&(MAXEVENTS-1);
|
2019-11-03 17:19:29 +00:00
|
|
|
}
|
|
|
|
|