Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support controller analog triggers #600

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
80 changes: 40 additions & 40 deletions Descent3/Controls.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Descent 3
* Descent 3
* Copyright (C) 2024 Parallax Software
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -879,25 +879,25 @@ void DoControllerMovement(game_controls *controls) {
ct_packet ctl_pub, ctl_pdb, ctl_hlb, ctl_hrb, ctl_blb, ctl_brb;

// read controls
Controller->get_packet(ctfFORWARD_THRUSTAXIS, &ctl_z);
Controller->get_packet(ctfUP_THRUSTAXIS, &ctl_y);
Controller->get_packet(ctfRIGHT_THRUSTAXIS, &ctl_x);
Controller->get_packet(ctfPITCH_DOWNAXIS, &ctl_p);
Controller->get_packet(ctfBANK_RIGHTAXIS, &ctl_b);
Controller->get_packet(ctfHEADING_RIGHTAXIS, &ctl_h);
Controller->get_packet(ctfUP_BUTTON, &ctl_povu);
Controller->get_packet(ctfDOWN_BUTTON, &ctl_povd);
Controller->get_packet(ctfRIGHT_BUTTON, &ctl_povr);
Controller->get_packet(ctfLEFT_BUTTON, &ctl_povl);
Controller->get_packet(ctfFORWARD_BUTTON, &ctl_fb);
Controller->get_packet(ctfREVERSE_BUTTON, &ctl_rb);
Controller->get_packet(ctfAFTERBURN_BUTTON, &ctl_afterburn);
Controller->get_packet(ctfHEADING_LEFTBUTTON, &ctl_hlb);
Controller->get_packet(ctfHEADING_RIGHTBUTTON, &ctl_hrb);
Controller->get_packet(ctfPITCH_UPBUTTON, &ctl_pub);
Controller->get_packet(ctfPITCH_DOWNBUTTON, &ctl_pdb);
Controller->get_packet(ctfBANK_LEFTBUTTON, &ctl_blb);
Controller->get_packet(ctfBANK_RIGHTBUTTON, &ctl_brb);
Controller->get_packet(ctfFORWARD_THRUSTAXIS, &ctl_z, ctAnalog);
Controller->get_packet(ctfUP_THRUSTAXIS, &ctl_y, ctAnalog);
Controller->get_packet(ctfRIGHT_THRUSTAXIS, &ctl_x, ctAnalog);
Controller->get_packet(ctfPITCH_DOWNAXIS, &ctl_p, ctAnalog);
Controller->get_packet(ctfBANK_RIGHTAXIS, &ctl_b, ctAnalog);
Controller->get_packet(ctfHEADING_RIGHTAXIS, &ctl_h, ctAnalog);
Controller->get_packet(ctfUP_BUTTON, &ctl_povu, ctAnalog);
Controller->get_packet(ctfDOWN_BUTTON, &ctl_povd, ctAnalog);
Controller->get_packet(ctfRIGHT_BUTTON, &ctl_povr, ctAnalog);
Controller->get_packet(ctfLEFT_BUTTON, &ctl_povl, ctAnalog);
Controller->get_packet(ctfFORWARD_BUTTON, &ctl_fb, ctAnalog);
Controller->get_packet(ctfREVERSE_BUTTON, &ctl_rb, ctAnalog);
Controller->get_packet(ctfAFTERBURN_BUTTON, &ctl_afterburn, ctAnalog);
Controller->get_packet(ctfHEADING_LEFTBUTTON, &ctl_hlb, ctAnalog);
Controller->get_packet(ctfHEADING_RIGHTBUTTON, &ctl_hrb, ctAnalog);
Controller->get_packet(ctfPITCH_UPBUTTON, &ctl_pub, ctAnalog);
Controller->get_packet(ctfPITCH_DOWNBUTTON, &ctl_pdb, ctAnalog);
Controller->get_packet(ctfBANK_LEFTBUTTON, &ctl_blb, ctAnalog);
Controller->get_packet(ctfBANK_RIGHTBUTTON, &ctl_brb, ctAnalog);

// do x and y thrust
controls->sideways_thrust += ctl_x.value;
Expand Down Expand Up @@ -935,40 +935,40 @@ void DoControllerMovement(game_controls *controls) {
}

// do button heading
if (ctl_hlb.value)
controls->heading_thrust += (-1.0f);
if (ctl_hrb.value)
controls->heading_thrust += (1.0f);
if (ctl_hlb.value > 0.0f)
controls->heading_thrust += ctl_hlb.value;
if (ctl_hrb.value > 0.0f)
controls->heading_thrust -= ctl_hlb.value;
Copy link
Contributor

@pzychotic pzychotic Oct 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a copy-paste error? Shouldn't it be -= ctl_hrb.value?


// do button pitch
if (ctl_pub.value)
controls->pitch_thrust += (-1.0f);
if (ctl_pdb.value)
controls->pitch_thrust += (1.0f);
if (ctl_pub.value > 0.0f)
controls->pitch_thrust -= ctl_pub.value;
if (ctl_pdb.value > 0.0f)
controls->pitch_thrust += ctl_pdb.value;

// do forward thrust based off of button values.
controls->forward_thrust += ((ctl_fb.value - ctl_rb.value) / Frametime);

// do button banking
if (ctl_blb.value)
controls->bank_thrust += (1.0f);
if (ctl_brb.value)
controls->bank_thrust += (-1.0f);
if (ctl_blb.value > 0.0f)
controls->bank_thrust += ctl_blb.value;
if (ctl_brb.value > 0.0f)
controls->bank_thrust -= ctl_blb.value;
Copy link
Contributor

@pzychotic pzychotic Oct 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for -= ctl_brb.value?


// do button sliding. use control frametime to set sliding times per frame.
// note that vertical and sideways thrusts are dependent on what the keyboard controller
// set these values to. so we save our own slidetimes.
if (ctl_povu.value) {
controls->vertical_thrust += (1.0f);
if (ctl_povu.value > 0.0f) {
controls->vertical_thrust += ctl_povu.value;
}
if (ctl_povd.value) {
controls->vertical_thrust -= (1.0f);
if (ctl_povd.value > 0.0f) {
controls->vertical_thrust -= ctl_povd.value;
}
if (ctl_povr.value) {
controls->sideways_thrust += (1.0f);
if (ctl_povr.value > 0.0f) {
controls->sideways_thrust += ctl_povr.value;
}
if (ctl_povl.value) {
controls->sideways_thrust -= (1.0f);
if (ctl_povl.value > 0.0f) {
controls->sideways_thrust -= ctl_povl.value;
}
}

Expand Down
14 changes: 11 additions & 3 deletions Descent3/CtlCfgElem.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Descent 3
* Descent 3
* Copyright (C) 2024 Parallax Software
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -491,6 +491,7 @@ const char *cfg_binding_text(ct_type ctype, uint8_t ctrl, uint8_t binding) {
case ctPOV2:
case ctPOV3:
case ctPOV4:
case ctAnalogTrigger:
case ctMouseButton:
case ctButton:
case ctMouseAxis:
Expand All @@ -513,7 +514,7 @@ const char *cfg_binding_text(ct_type ctype, uint8_t ctrl, uint8_t binding) {
class cfg_element_ui : public newuiMessageBox {
uint8_t m_element; // element passed and returned.
uint8_t m_controller; // controller.
int8_t m_alpha; // used for fx.
int8_t m_alpha; // used for fx.
ct_type m_type;

public:
Expand Down Expand Up @@ -812,6 +813,7 @@ bool cfg_element::Configure(ct_type *new_elem_type, uint8_t *controller, uint8_t
case ctPOV2:
case ctPOV3:
case ctPOV4:
case ctAnalogTrigger:
case ctAxis:
case ctMouseAxis:
configure = true;
Expand Down Expand Up @@ -872,6 +874,7 @@ void cfg_element_ui::Create(const char *title, ct_type type, uint8_t controller,
case ctPOV2:
case ctPOV3:
case ctPOV4:
case ctAnalogTrigger:
sheet->AddText(TXT_CTLBINDHELP2_0);
sheet->AddText(TXT_CTLBINDHELP2_1);
break;
Expand Down Expand Up @@ -936,7 +939,8 @@ int cfg_element_ui::DoUI() {
case ctPOV:
case ctPOV2:
case ctPOV3:
case ctPOV4: {
case ctPOV4:
case ctAnalogTrigger: {
ct_config_data ccfgdata;
ct_type new_type;

Expand All @@ -960,6 +964,10 @@ int cfg_element_ui::DoUI() {
if (!GCV_VALID_RESULT(ccfgdata)) {
ccfgdata = Controller->get_controller_value(ctButton); // read hats before buttons
new_type = ctButton;
if (!GCV_VALID_RESULT(ccfgdata)) {
ccfgdata = Controller->get_controller_value(ctAnalogTrigger);
new_type = ctAnalogTrigger;
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions Descent3/CtlCfgElem.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ static inline void parse_config_data(tCfgDataParts *parts, ct_type type0, ct_typ
case ctPOV:
case ctPOV2:
case ctPOV3:
case ctAnalogTrigger:
case ctPOV4:
parts->bind_0 = CONTROLLER_CTL1_VALUE(CONTROLLER_VALUE(cfgdata));
break;
Expand All @@ -150,6 +151,7 @@ static inline void parse_config_data(tCfgDataParts *parts, ct_type type0, ct_typ
case ctPOV2:
case ctPOV3:
case ctPOV4:
case ctAnalogTrigger:
parts->bind_1 = CONTROLLER_CTL2_VALUE(CONTROLLER_VALUE(cfgdata));
break;
default:
Expand Down
1 change: 1 addition & 0 deletions Descent3/ctlconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1005,6 +1005,7 @@ void ctl_cfg_element_options_dialog(int16_t fnid) {
case ctPOV2:
case ctPOV3:
case ctPOV4:
case ctAnalogTrigger:
strcpy(str, TXT_CFGHELP_BTNS);
break;
default:
Expand Down
3 changes: 2 additions & 1 deletion ddio/controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ enum ct_type {
ctMouseButton,
ctPOV2,
ctPOV3,
ctPOV4 // auxillary POV values.
ctPOV4, // auxillary POV values.
ctAnalogTrigger
};

struct ct_function {
Expand Down
Loading
Loading