Change delta from float/sec to int/msec
This commit is contained in:
parent
fc4745f4d2
commit
6e2672e49a
8 changed files with 18 additions and 24 deletions
5
TODO
5
TODO
|
@ -28,11 +28,6 @@ Stuff to do before 0.5 release:
|
|||
* figure out what jscal does and if it can break stuff
|
||||
1) jscal uses the joystick interface, not the event interface
|
||||
|
||||
* different xbox controller use different endpoints for read/write, solution:
|
||||
1) make endpoints variables
|
||||
2) check if endpoints are available on start
|
||||
3) if not, then use different one, seems to be just 1 or 2
|
||||
|
||||
* implement basic rumble force feedback support
|
||||
- see ff-memless for effect emulation on rumble
|
||||
- handle FF status report
|
||||
|
|
|
@ -291,7 +291,7 @@ LinuxUinput::send(uint16_t type, uint16_t code, int32_t value)
|
|||
}
|
||||
|
||||
void
|
||||
LinuxUinput::update(float delta)
|
||||
LinuxUinput::update(int msec_delta)
|
||||
{
|
||||
if (ff_bit)
|
||||
{
|
||||
|
|
|
@ -66,7 +66,7 @@ public:
|
|||
|
||||
void send(uint16_t type, uint16_t code, int32_t value);
|
||||
|
||||
void update(float delta);
|
||||
void update(int msec_delta);
|
||||
|
||||
private:
|
||||
LinuxUinput (const LinuxUinput&);
|
||||
|
|
|
@ -160,7 +160,7 @@ AutoFireMapping::from_string(const std::string& str)
|
|||
{
|
||||
AutoFireMapping mapping;
|
||||
mapping.button = string2btn(str.substr(0, i));
|
||||
mapping.frequency = atoi(str.substr(i+1, str.size()-i).c_str())/1000.0f;
|
||||
mapping.frequency = boost::lexical_cast<int>(str.substr(i+1, str.size()-i).c_str());
|
||||
return mapping;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ struct AutoFireMapping {
|
|||
static AutoFireMapping from_string(const std::string&);
|
||||
|
||||
XboxButton button;
|
||||
float frequency;
|
||||
int frequency;
|
||||
};
|
||||
|
||||
struct RelativeAxisMapping {
|
||||
|
@ -70,14 +70,14 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
void update(float delta, XboxGenericMsg& msg)
|
||||
void update(int msec_delta, XboxGenericMsg& msg)
|
||||
{
|
||||
for(size_t i = 0; i < relative_axis_map.size(); ++i)
|
||||
{
|
||||
int value = get_axis(msg, relative_axis_map[i].axis);
|
||||
if (abs(value) > 4000 ) // FIXME: add proper deadzone handling
|
||||
{
|
||||
axis_state[i] += static_cast<int>(relative_axis_map[i].speed * delta * (value/32768.0f));
|
||||
axis_state[i] += ((relative_axis_map[i].speed * value) / 32768) * msec_delta / 1000;
|
||||
if (axis_state[i] < -32768)
|
||||
axis_state[i] = -32768;
|
||||
else if (axis_state[i] > 32767)
|
||||
|
@ -97,7 +97,7 @@ class AutoFireModifier
|
|||
{
|
||||
private:
|
||||
std::vector<AutoFireMapping> autofire_map;
|
||||
std::vector<float> button_timer;
|
||||
std::vector<int> button_timer;
|
||||
|
||||
public:
|
||||
AutoFireModifier(const std::vector<AutoFireMapping>& autofire_map)
|
||||
|
@ -109,13 +109,13 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
void update(float delta, XboxGenericMsg& msg)
|
||||
void update(int msec_delta, XboxGenericMsg& msg)
|
||||
{
|
||||
for(size_t i = 0; i < autofire_map.size(); ++i)
|
||||
{
|
||||
if (get_button(msg, autofire_map[i].button))
|
||||
{
|
||||
button_timer[i] += delta;
|
||||
button_timer[i] += msec_delta;
|
||||
|
||||
if (button_timer[i] > autofire_map[i].frequency)
|
||||
{
|
||||
|
|
|
@ -698,13 +698,12 @@ uInput::send(Xbox360GuitarMsg& msg)
|
|||
}
|
||||
|
||||
void
|
||||
uInput::update(float delta)
|
||||
uInput::update(int msec_delta)
|
||||
{
|
||||
// Relative Motion emulation for axis
|
||||
int msec = static_cast<int>(delta*1000);
|
||||
for(std::vector<RelAxisState>::iterator i = rel_axis.begin(); i != rel_axis.end(); ++i)
|
||||
{
|
||||
i->time += msec;
|
||||
i->time += msec_delta;
|
||||
|
||||
if (i->time >= i->next_time)
|
||||
{
|
||||
|
@ -717,7 +716,7 @@ uInput::update(float delta)
|
|||
// Relative Motion emulation for button
|
||||
for(std::vector<RelButtonState>::iterator i = rel_button.begin(); i != rel_button.end(); ++i)
|
||||
{
|
||||
i->time += msec;
|
||||
i->time += msec_delta;
|
||||
|
||||
if (i->time >= i->next_time)
|
||||
{
|
||||
|
@ -735,7 +734,7 @@ uInput::update(float delta)
|
|||
}
|
||||
|
||||
// Update forcefeedback
|
||||
get_joystick_uinput()->update(delta);
|
||||
get_joystick_uinput()->update(msec_delta);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -152,7 +152,7 @@ public:
|
|||
void send_button(int code, bool value);
|
||||
void send_axis(int code, int32_t value);
|
||||
|
||||
void update(float delta);
|
||||
void update(int msec_delta);
|
||||
|
||||
LinuxUinput* get_mouse_uinput() const;
|
||||
LinuxUinput* get_keyboard_uinput() const;
|
||||
|
|
|
@ -1120,7 +1120,7 @@ void controller_loop(GamepadType type, uInput* uinput, XboxGenericController* co
|
|||
|
||||
// Calc changes in time
|
||||
uint32_t this_time = get_time();
|
||||
float delta = (this_time - last_time)/1000.0f;
|
||||
int msec_delta = this_time - last_time;
|
||||
last_time = this_time;
|
||||
|
||||
// Apply modifier
|
||||
|
@ -1130,10 +1130,10 @@ void controller_loop(GamepadType type, uInput* uinput, XboxGenericController* co
|
|||
apply_square_axis(msg);
|
||||
|
||||
if (autofire_modifier.get())
|
||||
autofire_modifier->update(delta, msg);
|
||||
autofire_modifier->update(msec_delta, msg);
|
||||
|
||||
if (relative_axis_modifier.get())
|
||||
relative_axis_modifier->update(delta, msg);
|
||||
relative_axis_modifier->update(msec_delta, msg);
|
||||
|
||||
if (!opts.button_map.empty())
|
||||
apply_button_map(msg, opts.button_map);
|
||||
|
@ -1173,7 +1173,7 @@ void controller_loop(GamepadType type, uInput* uinput, XboxGenericController* co
|
|||
}
|
||||
}
|
||||
|
||||
uinput->update(delta);
|
||||
uinput->update(msec_delta);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue