Merge pull request #589 from Lgt2x/sdlcontroller

Merge WinController and lnxcontroller
This commit is contained in:
Azamat H. Hackimov 2024-09-18 21:58:02 +03:00 committed by GitHub
commit 3b49fb45c8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
20 changed files with 92 additions and 2192 deletions

View File

@ -416,7 +416,7 @@
#include "descent.h"
#include "log.h"
#include "weapon.h"
#include "Controller.h"
#include "controller.h"
#include "gamesequence.h"
#include "pilot.h"
#include "hud.h"
@ -446,7 +446,6 @@ struct tSensitivity {
// GLOBALS
char *Controller_ip = NULL; // IP of controller, if any.
gameController *Controller = NULL;
bool Control_poll_flag = false; // determines if system is polling controls now.
@ -571,7 +570,7 @@ void InitControls() {
Control_system_init = true;
Controller = CreateController(NUM_CONTROLLER_FUNCTIONS, Controller_needs, Controller_ip);
Controller = CreateController(NUM_CONTROLLER_FUNCTIONS, Controller_needs);
if (Controller == NULL)
Error(TXT_ERRUNINITCNT);
Controller->mask_controllers(false, false);
@ -631,7 +630,7 @@ void CloseControls() {
void RestoreDefaultControls() {
ResumeControls();
DestroyController(Controller);
Controller = CreateController(NUM_CONTROLLER_FUNCTIONS, Controller_needs, Controller_ip);
Controller = CreateController(NUM_CONTROLLER_FUNCTIONS, Controller_needs);
if (Controller == NULL)
Error(TXT_ERRUNINITCNT);
SuspendControls();

View File

@ -78,7 +78,7 @@
#define CTLCFGELEM_H
#include "newui.h"
#include "Controller.h"
#include "controller.h"
#include "controls.h"
#include "stringtable.h"

View File

@ -169,7 +169,7 @@
#define CONTROLS_H
#include "object.h"
#include "Controller.h"
#include "controller.h"
class gameController;
class pilot;
@ -239,9 +239,6 @@ struct game_controls {
bool rearview_down_state = false;
};
// This value should be set at initialization time. Use for remote controlling.
extern char *Controller_ip;
// Controller object.
extern gameController *Controller;

View File

@ -1433,8 +1433,7 @@ void InitIOSystems(bool editor) {
// do io init stuff
io_info.obj = Descent;
io_info.joy_emulation = (bool)((FindArg("-alternatejoy") == 0) && (FindArg("-directinput") == 0));
io_info.key_emulation = true; //(bool)(FindArg("-slowkey")!=0); WIN95: DirectInput is flaky for some keys.
INIT_MESSAGE(("Initializing DDIO systems."));
if (!ddio_Init(&io_info)) {
Error("I/O initialization failed.");
@ -1602,11 +1601,6 @@ void InitGraphics(bool editor) {
}
void InitGameSystems(bool editor) {
// initialize possible remote controller.
int adr = FindArg("-rjoy");
if (adr)
Controller_ip = &GameArgs[adr + 1][1];
// do other joint editor/game initialization.
SetInitMessageLength(TXT_INITCOLLATING, 0.4f);
TelComInit();
@ -2136,8 +2130,6 @@ void RestartD3() {
// startup io
io_info.obj = Descent;
io_info.key_emulation = true; //(bool)(FindArg("-slowkey")!=0);
io_info.joy_emulation = (bool)((FindArg("-alternatejoy") == 0) && (FindArg("-directinput") == 0));
if (!ddio_Init(&io_info)) {
Error("I/O initialization failed.");
}

View File

@ -89,7 +89,7 @@
#include "pstypes.h"
#include "controls.h"
#include "Controller.h"
#include "controller.h"
#include "cfile.h"
#include "weapon.h"
#include "config.h"

View File

@ -2,7 +2,10 @@ set(HEADERS
chrono_timer.h
ddio.h
ddio_common.h
ddio_lnx.h)
ddio_lnx.h
controller.h
sdlcontroller.h
)
set(CPPS
chrono_timer.cpp
ddio.cpp
@ -15,6 +18,7 @@ set(CPPS
lnxkey_null.cpp
lnxmouse.cpp
lnxkey_sdl.cpp
sdlcontroller.cpp
$<$<PLATFORM_ID:Darwin,Linux,OpenBSD>:
lnxfile.cpp
>

View File

@ -17,14 +17,14 @@
--- HISTORICAL COMMENTS FOLLOW ---
* $Logfile: /DescentIII/Main/lib/Controller.h $
* $Logfile: /DescentIII/Main/lib/controller.h $
* $Revision: 21 $
* $Date: 3/20/00 12:25p $
* $Author: Matt $
*
* Universal controller header
*
* $Log: /DescentIII/Main/lib/Controller.h $
* $Log: /DescentIII/Main/lib/controller.h $
*
* 21 3/20/00 12:25p Matt
* Merge of Duane's post-1.3 changes.
@ -92,7 +92,7 @@
* changed ct_need to ct_function
*
* 7 5/12/97 4:39 PM Jeremy
* #include of macController.h on Macintosh
* #include of maccontroller.h on Macintosh
*
* 6 5/12/97 1:21p Samir
* Added suspend and resume functions.
@ -262,13 +262,8 @@ public:
void toggle_controller_axis(int ctl, int axis, bool toggle){};
};
gameController *CreateController(int num_funcs, ct_function *funcs, char *remote_ip);
gameController *CreateController(int num_funcs, ct_function *funcs);
void DestroyController(gameController *ctl);
#if defined(DX_APP)
#include "win\WinController.h"
#else
#include "lnxcontroller.h"
#endif
#endif

View File

@ -119,7 +119,7 @@ bool ddio_Init(ddio_init_info *init_info) {
}
first_time = false;
DDIO_initialized = true;
joy_Init(init_info->joy_emulation);
joy_Init();
return res;
}
void ddio_Close() {

View File

@ -124,8 +124,6 @@
struct ddio_init_info {
oeApplication *obj; // App object used to initialize to IO system
bool key_emulation; // keyboard emulation
bool joy_emulation; // joystick emulation
};
// ----------------------------------------------------------------------------

View File

@ -17,7 +17,7 @@
--- HISTORICAL COMMENTS FOLLOW ---
* $Logfile: /DescentIII/Main/lnxcontroller/lnxcontroller.cpp $
* $Logfile: /DescentIII/Main/sdlcontroller/sdlcontroller.cpp $
* $Revision: 1.1.1.1 $
* $Date: 2003/08/26 03:58:14 $
* $Author: kevinb $
@ -44,12 +44,12 @@
#include <algorithm>
#include <cstring>
#include "Controller.h"
#include "controller.h"
#include "ddio.h"
#include "pserror.h"
#include "joystick.h"
#include "inffile.h"
#include "lnxcontroller.h"
#include "sdlcontroller.h"
#include "log.h"
// Sorry! This is needed for the semi-hacky mouselook support
@ -68,7 +68,7 @@ static float WinControllerTimer = 0.0f;
static int64_t g_last_frame_timer_ms = -1;
static float g_accum_frame_time = 0.0f;
lnxgameController::lnxgameController(int num_funcs, ct_function *funcs) : gameController(num_funcs, funcs) {
sdlgameController::sdlgameController(int num_funcs, ct_function *funcs) : gameController(num_funcs, funcs) {
enum_controllers();
for (int i = 0; i < num_funcs; i++)
@ -80,16 +80,16 @@ lnxgameController::lnxgameController(int num_funcs, ct_function *funcs) : gameCo
g_last_frame_timer_ms = -1;
g_accum_frame_time = 0.0f;
lnxgameController::flush();
sdlgameController::flush();
}
lnxgameController::~lnxgameController() {}
sdlgameController::~sdlgameController() {}
// these functions suspend or resume any controller reading. this is really only useful for
// preemptive controller polling, but they should be used to activate and deactivate controller
// reading.
void lnxgameController::suspend() { m_Suspended = 1; }
void lnxgameController::resume() {
void sdlgameController::suspend() { m_Suspended = 1; }
void sdlgameController::resume() {
m_Suspended = 0;
m_frame_timer_ms = -1;
m_frame_time = 1.0f;
@ -100,7 +100,7 @@ void lnxgameController::resume() {
// this functions polls the controllers if needed. some systems may not need to implement
// this function.
void lnxgameController::poll() {
void sdlgameController::poll() {
int64_t cur_frame_timer_ms;
if (m_Suspended)
@ -137,7 +137,7 @@ void lnxgameController::poll() {
// toggles use of deadzone for controllers. ctl can be 0 to ???
// dead zone is from 0.0 to 0.5
void lnxgameController::set_controller_deadzone(int ctl, float deadzone) {
void sdlgameController::set_controller_deadzone(int ctl, float deadzone) {
if (ctl < 0 || ctl >= (m_NumControls - 2)) {
return;
}
@ -163,7 +163,7 @@ char Ctltext_PovBindings[][16] = {"", "pov-U", "pov-R", "pov-D", "pov-L"};
#define NUM_BTNBINDSTRINGS (sizeof(Ctltext_BtnBindings) / sizeof(Ctltext_AxisBindings[0]))
// retrieves binding text for desired function, binding, etc.
const char *lnxgameController::get_binding_text(ct_type type, uint8_t ctrl, uint8_t bind) {
const char *sdlgameController::get_binding_text(ct_type type, uint8_t ctrl, uint8_t bind) {
static char binding_text[32];
const char *str;
@ -256,7 +256,7 @@ const char *lnxgameController::get_binding_text(ct_type type, uint8_t ctrl, uint
}
// flushes all controller information
void lnxgameController::flush() {
void sdlgameController::flush() {
bool old_mse = m_MouseActive, old_joy = m_JoyActive;
ddio_KeyFlush();
@ -268,7 +268,7 @@ void lnxgameController::flush() {
}
// returns the value of a requested controller type. make sure you flush the controller before polling.
ct_config_data lnxgameController::get_controller_value(ct_type type_req) {
ct_config_data sdlgameController::get_controller_value(ct_type type_req) {
// will return the current value of a requested control type.
ct_config_data val = MAKE_CONFIG_DATA(INVALID_CONTROLLER_INFO, NULL_BINDING);
int i, j;
@ -442,7 +442,7 @@ ct_config_data lnxgameController::get_controller_value(ct_type type_req) {
}
// sets the configuration of a function (type must be of an array == CTLBINDS_PER_FUNC)
void lnxgameController::set_controller_function(int id, const ct_type *type, ct_config_data value,
void sdlgameController::set_controller_function(int id, const ct_type *type, ct_config_data value,
const uint8_t *flags) {
ct_element elem;
@ -479,7 +479,7 @@ void lnxgameController::set_controller_function(int id, const ct_type *type, ct_
}
// returns information about a requested function (type must be of an array == CTLBINDS_PER_FUNC)
void lnxgameController::get_controller_function(int id, ct_type *type, ct_config_data *value, uint8_t *flags) {
void sdlgameController::get_controller_function(int id, ct_type *type, ct_config_data *value, uint8_t *flags) {
type[0] = m_ElementList[id].ctype[0];
type[1] = m_ElementList[id].ctype[1];
*value = makeword(CONTROLLER_CTL_INFO(m_ElementList[id].ctl[0], m_ElementList[id].ctl[1]),
@ -489,10 +489,10 @@ void lnxgameController::get_controller_function(int id, ct_type *type, ct_config
}
// temporarily enables or disables a function
void lnxgameController::enable_function(int id, bool enable) { m_ElementList[id].enabled = enable; }
void sdlgameController::enable_function(int id, bool enable) { m_ElementList[id].enabled = enable; }
// all systems need to implement this function. this returns information about the controller
bool lnxgameController::get_packet(int id, ct_packet *packet, ct_format alt_format) {
bool sdlgameController::get_packet(int id, ct_packet *packet, ct_format alt_format) {
float val = 0.0f;
int i;
@ -573,7 +573,7 @@ skip_packet_read:
}
// gets sensitivity of axis item
float lnxgameController::get_axis_sensitivity(ct_type axis_type, uint8_t axis) {
float sdlgameController::get_axis_sensitivity(ct_type axis_type, uint8_t axis) {
axis--;
ASSERT(axis < CT_NUM_AXES);
@ -592,7 +592,7 @@ float lnxgameController::get_axis_sensitivity(ct_type axis_type, uint8_t axis) {
}
// sets sensitivity of axis item
void lnxgameController::set_axis_sensitivity(ct_type axis_type, uint8_t axis, float val) {
void sdlgameController::set_axis_sensitivity(ct_type axis_type, uint8_t axis, float val) {
int i;
axis--;
@ -612,7 +612,7 @@ void lnxgameController::set_axis_sensitivity(ct_type axis_type, uint8_t axis, fl
}
// assigns an individual function
int lnxgameController::assign_function(ct_function *func) {
int sdlgameController::assign_function(ct_function *func) {
// for now this is a straight forward translation (that is, no mapping of needs to controller
// list to create elements.
ct_element elem;
@ -676,7 +676,7 @@ int lnxgameController::assign_function(ct_function *func) {
}
// get raw values for the controllers
int lnxgameController::get_mouse_raw_values(int *x, int *y) {
int sdlgameController::get_mouse_raw_values(int *x, int *y) {
if (m_Suspended)
return 0;
@ -686,7 +686,7 @@ int lnxgameController::get_mouse_raw_values(int *x, int *y) {
return m_MseState.btnmask;
}
unsigned lnxgameController::get_joy_raw_values(int *x, int *y) {
unsigned sdlgameController::get_joy_raw_values(int *x, int *y) {
unsigned btn = 0;
if (m_Suspended)
@ -707,8 +707,8 @@ unsigned lnxgameController::get_joy_raw_values(int *x, int *y) {
return 0;
}
gameController *CreateController(int num_funcs, ct_function *funcs, char *remote_ip) {
return new lnxgameController(num_funcs, funcs);
gameController *CreateController(int num_funcs, ct_function *funcs) {
return new sdlgameController(num_funcs, funcs);
}
void DestroyController(gameController *ctl) {
@ -716,7 +716,7 @@ void DestroyController(gameController *ctl) {
}
// activates or deactivates mouse and or controller
void lnxgameController::mask_controllers(bool joystick, bool mouse) {
void sdlgameController::mask_controllers(bool joystick, bool mouse) {
int i, j;
m_JoyActive = joystick;
@ -767,7 +767,7 @@ void lnxgameController::mask_controllers(bool joystick, bool mouse) {
// ---------------------------------------------------------------------------
// controller functions
void lnxgameController::extctl_getpos(int id) {
void sdlgameController::extctl_getpos(int id) {
tJoyPos ji;
float timer_val;
int i;
@ -830,7 +830,7 @@ void lnxgameController::extctl_getpos(int id) {
m_ExtCtlStates[id].buttons = ji.buttons;
}
void lnxgameController::mouse_geteval() {
void sdlgameController::mouse_geteval() {
int x, y, dx, dy; //,z;
unsigned btnmask;
@ -853,7 +853,7 @@ void lnxgameController::mouse_geteval() {
}
// enumerate all controllers on system
bool lnxgameController::enum_controllers() {
bool sdlgameController::enum_controllers() {
int num_devs = 0, dev;
int i;
@ -936,13 +936,13 @@ bool lnxgameController::enum_controllers() {
m_NumControls = num_devs;
lnxgameController::flush();
sdlgameController::flush();
return true;
}
// returns the controller with a pov hat
int8_t lnxgameController::get_pov_controller(uint8_t pov) {
int8_t sdlgameController::get_pov_controller(uint8_t pov) {
// start from controller 2 because 0, and 1 are reserved for keyboard and mouse
uint16_t pov_flag = CTF_POV << (pov);
@ -953,7 +953,7 @@ int8_t lnxgameController::get_pov_controller(uint8_t pov) {
return NULL_LNXCONTROLLER;
}
int8_t lnxgameController::get_button_controller(uint8_t btn) {
int8_t sdlgameController::get_button_controller(uint8_t btn) {
unsigned mask;
// buttons range from 1-CT_MAX_BUTTONS
@ -976,7 +976,7 @@ int8_t lnxgameController::get_button_controller(uint8_t btn) {
return NULL_LNXCONTROLLER;
}
int8_t lnxgameController::get_axis_controller(uint8_t axis) {
int8_t sdlgameController::get_axis_controller(uint8_t axis) {
// start from controller 2 because 0, and 1 are reserved for keyboard and mouse
if (axis == NULL_BINDING)
return NULL_LNXCONTROLLER;
@ -988,7 +988,7 @@ int8_t lnxgameController::get_axis_controller(uint8_t axis) {
return NULL_LNXCONTROLLER;
}
void lnxgameController::assign_element(int id, ct_element *elem) {
void sdlgameController::assign_element(int id, ct_element *elem) {
// assign element, check to see if valid.
int i;
@ -1038,7 +1038,7 @@ void lnxgameController::assign_element(int id, ct_element *elem) {
}
}
float lnxgameController::get_button_value(int8_t controller, ct_format format, uint8_t button) {
float sdlgameController::get_button_value(int8_t controller, ct_format format, uint8_t button) {
float val = 0.0f;
if (controller <= NULL_LNXCONTROLLER || controller >= CT_MAX_CONTROLLERS) {
@ -1111,8 +1111,8 @@ float lnxgameController::get_button_value(int8_t controller, ct_format format, u
}
// note controller is index into ControlList.
float lnxgameController::get_axis_value(int8_t controller, uint8_t axis, ct_format format, bool invert) {
struct lnxgameController::t_controller *ctldev;
float sdlgameController::get_axis_value(int8_t controller, uint8_t axis, ct_format format, bool invert) {
struct sdlgameController::t_controller *ctldev;
float val = 0.0f;
float normalizer, axisval = 0, nullzone; //, senszone;
@ -1278,7 +1278,7 @@ float lnxgameController::get_axis_value(int8_t controller, uint8_t axis, ct_form
}
// do some pov stuff
float lnxgameController::get_pov_value(int8_t controller, ct_format format, uint8_t pov_number, uint8_t pov) {
float sdlgameController::get_pov_value(int8_t controller, ct_format format, uint8_t pov_number, uint8_t pov) {
float val = 0.0f;
if (controller <= NULL_LNXCONTROLLER || controller >= CT_MAX_CONTROLLERS) {
@ -1345,7 +1345,7 @@ float lnxgameController::get_pov_value(int8_t controller, ct_format format, uint
}
// get keyboard info
float lnxgameController::get_key_value(int key, ct_format format) {
float sdlgameController::get_key_value(int key, ct_format format) {
float val = 0.0f;
ASSERT(key < DDIO_MAX_KEYS);
@ -1398,7 +1398,7 @@ int CTLLex(const char *command) {
}
// okay, now search for a '****.ctl' file in the current directory.
void lnxgameController::parse_ctl_file(int devnum, const char *ctlname) {
void sdlgameController::parse_ctl_file(int devnum, const char *ctlname) {
// parse each file until we find a name match, no name match, just return
ddio_DoForeachFile(
Base_directory, std::regex(".*\\.ctl"), [this, &devnum, &ctlname](const std::filesystem::path &path) {

View File

@ -19,7 +19,7 @@
#ifndef __LNXCONTROLLER_H_
#define __LNXCONTROLLER_H_
#include "Controller.h"
#include "controller.h"
#include "joystick.h"
#define NULL_LNXCONTROLLER ((int8_t)NULL_CONTROLLER)
@ -49,60 +49,60 @@ const int CTID_KEYBOARD = -1, // always -1 for keyboards
const int CTID_EXTCONTROL0 = 0;
class lnxgameController : public gameController {
class sdlgameController : public gameController {
public:
lnxgameController(int num_funcs, ct_function *funcs);
~lnxgameController();
sdlgameController(int num_funcs, ct_function *funcs);
~sdlgameController();
// these functions suspend or resume any controller reading. this is really only useful for
// preemptive controller polling, but they should be used to activate and deactivate controller
// reading.
virtual void suspend();
virtual void resume();
void suspend() override;
void resume() override;
// this functions polls the controllers if needed. some systems may not need to implement
// this function.
virtual void poll();
void poll();
// flushes all controller information
virtual void flush();
void flush() override;
// returns the value of a requested controller type. make sure you flush the controller before polling.
virtual ct_config_data get_controller_value(ct_type type_req);
ct_config_data get_controller_value(ct_type type_req) override;
// sets the configuration of a function (type must be of an array == CTLBINDS_PER_FUNC)
virtual void set_controller_function(int id, const ct_type *type, ct_config_data value, const uint8_t *flags);
void set_controller_function(int id, const ct_type *type, ct_config_data value, const uint8_t *flags) override;
// returns information about a requested function (type must be of an array == CTLBINDS_PER_FUNC)
virtual void get_controller_function(int id, ct_type *type, ct_config_data *value, uint8_t *flags);
void get_controller_function(int id, ct_type *type, ct_config_data *value, uint8_t *flags) override;
// temporarily enables or disables a function
virtual void enable_function(int id, bool enable);
void enable_function(int id, bool enable) override;
// all systems need to implement this function. this returns information about the controller
virtual bool get_packet(int id, ct_packet *packet, ct_format alt_format = ctNoFormat);
bool get_packet(int id, ct_packet *packet, ct_format alt_format = ctNoFormat) override;
// gets sensitivity of axis item
virtual float get_axis_sensitivity(ct_type axis_type, uint8_t axis);
float get_axis_sensitivity(ct_type axis_type, uint8_t axis) override;
// sets sensitivity of axis item
virtual void set_axis_sensitivity(ct_type axis_type, uint8_t axis, float val);
void set_axis_sensitivity(ct_type axis_type, uint8_t axis, float val) override;
// assigns an individual function
virtual int assign_function(ct_function *fn);
int assign_function(ct_function *fn) override;
// activates or deactivates mouse and or controller
virtual void mask_controllers(bool joystick, bool mouse);
void mask_controllers(bool joystick, bool mouse) override;
// get raw values for the controllers
virtual int get_mouse_raw_values(int *x, int *y);
virtual unsigned get_joy_raw_values(int *x, int *y);
int get_mouse_raw_values(int *x, int *y) override;
unsigned get_joy_raw_values(int *x, int *y) override;
// retrieves binding text for desired function, binding, etc.
virtual const char *get_binding_text(ct_type type, uint8_t ctrl, uint8_t bind);
const char *get_binding_text(ct_type type, uint8_t ctrl, uint8_t bind) override;
// toggles use of deadzone for controllers
void set_controller_deadzone(int ctl, float deadzone);
void set_controller_deadzone(int ctl, float deadzone) override;
private:
int m_NumControls = 0; // number of controllers available

View File

@ -83,11 +83,12 @@ static struct {
SDL_Joystick *handle;
tJoyInfo caps;
} Joysticks[MAX_JOYSTICKS];
void joy_Close();
static int joyGetNumDevs(void);
// closes a stick
// closes connection with controller.
static void joy_CloseStick(tJoystick joy);
// initializes a joystick
// if server_adr is valid, a link is opened to another machine with a controller.
static bool joy_InitStick(tJoystick joy, char *server_adr);
@ -96,27 +97,27 @@ static bool joy_InitStick(tJoystick joy, char *server_adr);
// functions
// joystick system initialization
bool joy_Init(bool remote) {
bool joy_Init() {
// reinitialize joystick if already initialized.
joy_Close();
if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) < 0) {
// FIXME: report an error?
LOG_ERROR << "Could not initialize Joystick";
return false;
}
// check if this OS supports joysticks
if (!joyGetNumDevs() && !remote) {
if (!joyGetNumDevs()) {
return false;
}
// rcg06182000 specific joystick support.
if (specificJoy >= 0) {
joy_InitStick((tJoystick)specificJoy, NULL);
joy_InitStick((tJoystick)specificJoy, nullptr);
} // if
else {
// initialize joystick list
for (int i = 0; i < MAX_JOYSTICKS; i++) {
joy_InitStick((tJoystick)i, NULL);
joy_InitStick((tJoystick)i, nullptr);
}
} // else
return true;
@ -133,8 +134,6 @@ void joy_Close() {
// initializes a joystick
// if server_adr is valid, a link is opened to another machine with a controller.
static bool joy_InitStick(tJoystick joy, char *server_adr) {
SDL_Joystick *stick;
// close down already open joystick.
joy_CloseStick(joy);
@ -142,12 +141,12 @@ static bool joy_InitStick(tJoystick joy, char *server_adr) {
if (server_adr) {
return false;
}
stick = SDL_JoystickOpen(joy);
SDL_Joystick *stick = SDL_JoystickOpen(joy);
Joysticks[joy].handle = stick;
if (stick) {
tJoyInfo caps;
memset(&caps, 0, (sizeof caps));
memset(&caps, 0, (sizeof(caps)));
strncpy(caps.name, SDL_JoystickNameForIndex(joy), sizeof(caps.name) - 1);
caps.num_btns = SDL_JoystickNumButtons(stick);
int axes = SDL_JoystickNumAxes(stick);
@ -205,12 +204,10 @@ static bool joy_InitStick(tJoystick joy, char *server_adr) {
return (Joysticks[joy].handle != NULL);
}
// closes a stick
// closes connection with controller.
// closes connection with controller.
static void joy_CloseStick(tJoystick joy) {
// CLOSE joystick here
SDL_JoystickClose(Joysticks[joy].handle);
Joysticks[joy].handle = 0;
Joysticks[joy].handle = nullptr;
}
// returns true if joystick valid
@ -279,7 +276,7 @@ void joy_GetPos(tJoystick joy, tJoyPos *pos) {
SDL_Joystick *stick;
int i;
memset(pos, 0, (sizeof *pos));
memset(pos, 0, (sizeof(*pos)));
// retrieve joystick info from the net, or locally.
stick = Joysticks[joy].handle;

View File

@ -670,10 +670,6 @@ void GameToEditor(bool set_viewer_from_player) {
SetWindowLong(theApp.main_frame->m_hWnd, GWL_STYLE, EditorWndStyle);
}
// this uses information defined above
io_info.key_emulation = true; //(bool)(FindArg("-slowkey")!=0);
io_info.joy_emulation = (bool)((FindArg("-alternatejoy") == 0) && (FindArg("-directinput") == 0));
ddio_Init(&io_info);
Cinematic_Init();
@ -871,8 +867,6 @@ void EditorToGame() {
// Initialize IO System for child window
io_info.obj = Descent;
io_info.key_emulation = true; //(bool)(FindArg("-slowkey")!=0);
io_info.joy_emulation = (bool)((FindArg("-alternatejoy") == 0) && (FindArg("-directinput") == 0));
ddio_Init(&io_info);
// Init force feedback

View File

@ -181,8 +181,6 @@ void InitIO(oeApplication *app) {
ddio_init_data.obj = app;
ddio_init_data.use_lo_res_time = true;
ddio_init_data.key_emulation = true;
ddio_init_data.joy_emulation = true;
ddio_Init(&ddio_init_data);
GetCurrentDirectory(sizeof(path), path);

View File

@ -138,7 +138,7 @@ struct tJoyPos {
};
// joystick system initialization
bool joy_Init(bool emulation);
bool joy_Init();
void joy_Close();
// retreive information about joystick.

View File

@ -1,304 +0,0 @@
/*
* Descent 3
* Copyright (C) 2024 Parallax Software
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
--- HISTORICAL COMMENTS FOLLOW ---
* $Logfile: /DescentIII/Main/Lib/Win/WinController.h $
* $Revision: 27 $
* $Date: 7/26/99 12:00p $
* $Author: Samir $
*
* Win32 controller header.
*
* $Log: /DescentIII/Main/Lib/Win/WinController.h $
*
* 27 7/26/99 12:00p Samir
* added code to read config files for different controllers.
*
* 26 7/20/99 4:53p Samir
* added ability to manually set the deadzone for a controller.
*
* 25 7/16/99 11:14a Samir
* multiple hat support and improved direct input support.
*
* 24 5/03/99 12:36p Samir
* poll mouse deltas and button masks not as often, to allow deltas to
* accumulate. also decreased normalizer for mouse axes'.
*
* 23 4/29/99 2:23a Samir
* moved binding text functions to wincontroller.cpp and new text for
* multiple joysticks.
*
* 22 4/26/99 4:31p Samir
* get_mouse_raw_values now returns screen coords, not deltas.
*
* 21 4/24/99 5:39p Samir
* mouse control now framerate independent.
*
* 20 4/16/99 2:02p Kevin
* Added mouselook support
*
* 19 2/16/99 11:59a Samir
* added proper constants for controller and binding null values.
*
* 18 12/18/98 6:00p Samir
* added enable_function.
*
* 17 10/24/98 2:18p Samir
* added mouse and joytick raw value retrieval functions.
*
* 16 10/21/98 10:36a Samir
* added code to turn on or off joystick or mouse.
*
* 15 10/18/98 7:29p Samir
* made assign_function public.
*
* 14 10/17/98 7:31p Samir
* added invertible axes
*
* 13 9/10/98 12:39p Samir
* added senstivity issures for controller.
*
* 12 6/29/98 6:47p Samir
* made suspended flag an int.
*
* 11 6/18/98 4:48p Samir
* added changes for multiple configs for joystick controls.
*
* 10 2/24/98 11:03a Samir
* Added flush function to controller system.
*
* 9 2/17/98 10:59a Samir
* Added invalid controller type.
*
* 8 2/16/98 3:04p Samir
* ctAxis instead of ctXAxis, ctYAxis, etc.
*
* 7 2/13/98 6:38p Samir
* Added get and set controller function.
*
* 6 12/05/97 12:49p Samir
* POV timing support
*
* 5 12/05/97 10:58a Samir
* Null zone for joysticks applied here.
*
* 4 12/03/97 7:35p Samir
* Newer joystick library support and some POV.
*
* 3 11/05/97 3:46p Samir
* Use C runtime calls for thread creattion.
*
* 2 10/29/97 4:44p Samir
* Added ctDownCount format.
*
* 7 5/12/97 1:20p Samir
* Preemptive thread for joystick buttons.
*
* 6 4/23/97 1:07p Samir
* Now we can poll for either positonal or evaluator data.
*
* 5 4/16/97 1:04p Samir
* For get packet, allow one to return an alternate format value if that
* function supports it.
*
* 4 4/16/97 12:27p Samir
* Added mouse support.
*
* 3 4/14/97 12:56p Samir
* Added information for button timings.
*
* 2 4/11/97 2:13p Samir
* Win32 controller interface works for keyboards and DirectInput devices
* through (not mouse yet).
*
* $NoKeywords: $
*/
#ifndef WINCONTROLLER_H
#define WINCONTROLLER_H
#include "Controller.h"
#include "joystick.h"
#define NULL_WINCONTROLLER ((int8_t)NULL_CONTROLLER)
const int CTF_POV = 64, // POV control
CTF_POV2 = 128, // POV 2
CTF_POV3 = 256, // POV 3
CTF_POV4 = 512; // POV 4
const unsigned CTF_X_AXIS = (1 << (CT_X_AXIS - 1)), // AXIS constants for ctAxis
CTF_Y_AXIS = (1 << (CT_Y_AXIS - 1)), CTF_Z_AXIS = (1 << (CT_Z_AXIS - 1)), CTF_R_AXIS = (1 << (CT_R_AXIS - 1)),
CTF_U_AXIS = (1 << (CT_U_AXIS - 1)), CTF_V_AXIS = (1 << (CT_V_AXIS - 1));
const unsigned CT_MAX_CONTROLLERS = 32, CT_MAX_ELEMENTS = 255, CT_MAX_EXTCTLS = 16, CT_MAX_BUTTONS = 32;
// rules for adding controllers
// any nonstandard special controllers should be added to the below list starting at
// CTID_MOUSE-1 (meaning a value of -3, -4 and so on)
const int CTID_KEYBOARD = -1, // always -1 for keyboards
CTID_MOUSE = -2, // always -2 for mice
CTID_INVALID = -3; // invalid controller
// External controls
// these are standard controllers handled through DDIO interface
// like joysticks, etc.
const int CTID_EXTCONTROL0 = 0;
class gameWinController : public gameController {
public:
// initialization of controller with needs
gameWinController(int num_funcs, ct_function *funcs, char *remote_adr = NULL);
virtual ~gameWinController();
virtual void suspend();
virtual void resume();
// this functions polls the controllers if needed. some systems may not need to implement
// this function.
virtual void poll();
// flushes all controller information
virtual void flush();
// returns the value of a requested controller type.
virtual ct_config_data get_controller_value(ct_type type_req);
// sets the configuration of a function
virtual void set_controller_function(int id, const ct_type *type, ct_config_data value, const uint8_t *flags);
// returns information about a requested function
virtual void get_controller_function(int id, ct_type *type, ct_config_data *value, uint8_t *flags);
// temporarily enables or disables a function
virtual void enable_function(int id, bool enable);
virtual bool get_packet(int id, ct_packet *packet, ct_format alt_format = ctNoFormat);
// gets sensitivity of axis item
virtual float get_axis_sensitivity(ct_type axis_type, uint8_t axis);
// sets sensitivity of axis item
virtual void set_axis_sensitivity(ct_type axis_type, uint8_t axis, float val);
// assigns an individual function
virtual int assign_function(ct_function *fn);
// activates or deactivates mouse and or controller
virtual void mask_controllers(bool joystick, bool mouse);
// retrieves binding text for desired function, binding, etc.
virtual const char *get_binding_text(ct_type type, uint8_t ctrl, uint8_t bind);
// get raw values for the controllers
virtual int get_mouse_raw_values(int *x, int *y);
virtual unsigned get_joy_raw_values(int *x, int *y);
// toggles use of deadzone for controllers. ctl can be 0 to ???
// dead zone is from 0.0 to 0.5
void set_controller_deadzone(int ctl, float deadzone);
private:
int m_NumControls = 0; // number of controllers available
int m_Suspended = 0; // is controller polling suspended?
bool m_JoyActive = false, m_MouseActive = false; // enables or disables mouse, joystick control
struct t_controller {
int id = 0;
uint16_t flags = 0;
uint16_t buttons = 0;
unsigned btnmask = 0;
float normalizer[CT_NUM_AXES]{};
float sens[CT_NUM_AXES]{};
float sensmod[CT_NUM_AXES]{};
float deadzone = 0;
} m_ControlList[CT_MAX_CONTROLLERS]; // the control list.
struct ct_element {
ct_format format{};
int8_t ctl[CTLBINDS_PER_FUNC]{};
uint8_t value[CTLBINDS_PER_FUNC]{};
ct_type ctype[CTLBINDS_PER_FUNC]{};
uint8_t flags[2]{};
bool enabled = false;
} m_ElementList[CT_MAX_ELEMENTS];
bool enum_controllers(char *remote_adr);
// sets up an elements information structure
void assign_element(int id, ct_element *elem);
// this returns an index into the control list.
int8_t get_axis_controller(uint8_t axis);
// returns controller with specified button
int8_t get_button_controller(uint8_t btn);
// returns the controller with a pov hat
int8_t get_pov_controller(uint8_t pov);
// note controller is index into ControlList.
float get_axis_value(int8_t controller, uint8_t axis, ct_format format, bool invert = false);
// get value of button in seconds, presses, etc.
float get_button_value(int8_t controller, ct_format format, uint8_t button);
// get value of pov (using JOYPOV values)
float get_pov_value(int8_t controller, ct_format format, uint8_t pov_number, uint8_t pov);
// get keyboard info
float get_key_value(int key, ct_format format);
// okay, now search for a '****.ctl' file in the current directory.
void parse_ctl_file(int devnum, const char *ctlname);
private:
struct t_msestate {
int m_deltaX = 0, m_deltaY = 0, m_deltaZ = 0;
int m_absX = 0, m_absY = 0;
uint32_t m_buttonMask = 0;
} m_MseState;
struct t_extctlstate {
int x = 0, y = 0, z = 0, r = 0, u = 0, v = 0;
int pov[JOYPOV_NUM]{};
int last_pov[JOYPOV_NUM]{};
float povstarts[JOYPOV_NUM][JOYPOV_DIR]{};
float povtimes[JOYPOV_NUM][JOYPOV_DIR]{};
uint8_t povpresses[JOYPOV_NUM][JOYPOV_DIR]{};
unsigned buttons = 0;
uint8_t btnpresses[CT_MAX_BUTTONS]{};
float btnstarts[CT_MAX_BUTTONS]{};
float btntimes[CT_MAX_BUTTONS]{};
} m_ExtCtlStates[CT_MAX_EXTCTLS];
// thread info.
int64_t m_frame_timer_ms = 0;
float m_frame_time = 0;
// note id is id value from controller in control list.
void extctl_getpos(int id);
void extctl_geteval(int id);
// this gets timings for mouse buttons
void mouse_geteval();
};
#endif

View File

@ -1,11 +1,9 @@
set(HEADERS
lnxapp.h
lnxcontroller.h
registry.h)
set(CPPS
lnxcon.cpp
lnxcon_raw.cpp
lnxcontroller.cpp
lnxapp.cpp
lnxcon_null.cpp
lnxdata.cpp

View File

@ -31,4 +31,5 @@ target_link_libraries(dmfc PUBLIC
grtext
misc
physics
ddio
)

View File

@ -1,7 +1,6 @@
set(CPPS
winapp.cpp
wincon.cpp
WinController.cpp
windata.cpp
)

File diff suppressed because it is too large Load Diff