Comments (10)
from hashlink.
I tried both directx and SDL they do the same thing
from hashlink.
I guess it's not related to Heaps then as you should at least get some feedback from SDL ?
from hashlink.
Yeah it should that's why I think it's hashlink or the communication with libsdl.
It could be because of how the controllers are being mapped and used. There is a list of mappings in GameController
It does look a little like anything that's not on that list might be ignored but I don't know the full context of it.
from hashlink.
from hashlink.
Oh I see SDL has gamepad and joysticks split into two different things. With different events for each of them ie. SDL_GameController* and SDL_Joystick*
from hashlink.
In Heaps the Pad object uses only the GameController not the Joystick part so that's why the wait callback is never triggered for a joystick like device because it's not a gamepad in SDL. So now the question is how do I get access to the joystick instead of a gamepad in Heaps? Seems that there is no support in Heaps for joystick then at least not that I can see. It would require the equivalent to hxd.Pad but one that would use sdl.Joystick instead of sdl.GameController.
from hashlink.
I should be able to mimic what Pad does for GameController and try to do something similar for Joystick. But I guess that's out of topic for a hashlink issue then. I'll still let you know if I find out something. It's just kinda hashlink adjacent because it's visible only when using SDL not when using something else like the web environment etc.
from hashlink.
A very hacked up test for the theory... this works for opengl it's a copy of the hxd.Pad object from Heaps.
It doesn't help for directx that still has some other issue and I didn't research how it handles joysticks if it's similar to SDL or no.
package tools;
class Joystick {
public var index : Int = -1;
public var connected(default, null) = true;
public var values : Array<Float> = [];
public var buttons : Array<Bool> = [];
public var prevValues : Array<Float> = [];
public var xAxis(get,never) : Float;
public var yAxis(get,never) : Float;
public var rxAxis(get,never) : Float;
public var ryAxis(get,never) : Float;
public var axisDeadZone : Float = 0.1;
#if hl
public static var ANALOG_BUTTON_THRESHOLDS = { press: 0.3, release: 0.25 };
#end
#if hlsdl
public var d : sdl.Joystick;
#end
var rawXAxis : Float = 0.;
var rawYAxis : Float = 0.;
var rawRXAxis : Float = 0.;
var rawRYAxis : Float = 0.;
var prevButtons : Array<Bool> = [];
static var sticks : Map<Int, Joystick> = new Map();
static var waitPad : Joystick -> Void;
static var initDone = false;
function get_xAxis() {
if( rawXAxis*rawXAxis + rawYAxis*rawYAxis < axisDeadZone*axisDeadZone ) return 0.;
return rawXAxis;
}
function get_yAxis() {
if( rawXAxis*rawXAxis + rawYAxis*rawYAxis < axisDeadZone*axisDeadZone ) return 0.;
return rawYAxis;
}
function get_rxAxis() {
if( rawRXAxis*rawRXAxis + rawRYAxis*rawRYAxis < axisDeadZone*axisDeadZone ) return 0.;
return rawRXAxis;
}
function get_ryAxis() {
if( rawRXAxis*rawRXAxis + rawRYAxis*rawRYAxis < axisDeadZone*axisDeadZone ) return 0.;
return rawRYAxis;
}
function new() {
}
public function isDown( button : Int ) {
return buttons[button];
}
public function isPressed( button : Int ) {
return buttons[button] && !prevButtons[button];
}
public function isReleased( button : Int ) {
return !buttons[button] && prevButtons[button];
}
public dynamic function onDisconnect(){
}
inline function _setAxis( axisId : Int, value : Int ){
var v = value / 0x7FFF;
_detectAnalogButton(axisId, v);
// Invert Y axis
if( axisId == 1 || axisId == 3 )
values[ axisId ] = -v;
else
values[ axisId ] = v;
if( axisId == 0 )
rawXAxis = v;
else if( axisId == 1 )
rawYAxis = v;
else if( axisId == 2 )
rawRXAxis = v;
else if( axisId == 3 )
rawRYAxis = v;
}
#if hl
inline function _setButton( btnId : Int, down : Bool ){
buttons[ btnId ] = down;
values[ btnId ] = down ? 1 : 0;
}
function _detectAnalogButton(index: Int, v: Float) {
if(v > ANALOG_BUTTON_THRESHOLDS.press && v > values[index]) {
buttons[ index ] = true;
}
if(v < ANALOG_BUTTON_THRESHOLDS.release && v < values[index]) {
buttons[ index ] = false;
}
}
#end
static function initPad( index ){
var sp = new sdl.Joystick( index );
if( @:privateAccess sp.ptr == null )
return;
var j = new Joystick();
j.index = sp.id;
j.d = sp;
var prev = sticks.get( j.index );
if (prev != null) {
sticks.remove( j.index );
prev.d.close();
prev.connected = false;
prev.onDisconnect();
}
sticks.set( j.index, j );
for( axis in 0...6 )
j._setAxis( axis, sp.getAxis(axis) );
for( button in 0...15 )
j._setButton( button + 6, sp.getButton(button) );
waitPad( j );
}
static function syncPads(){
for( p in sticks ) {
for( i in 0...p.buttons.length ) {
p.prevButtons[i] = p.buttons[i];
p._setButton( i, p.d.getButton(i) );
}
for( i in 0...p.values.length ) {
p.prevValues[i] = p.values[i];
p._setAxis( i, p.d.getAxis(i) );
}
}
}
public static function wait( onPad : Joystick -> Void ) {
#if js
if( !js.Browser.supported )
return;
#end
waitPad = onPad;
#if hlsdl
if( !initDone ) {
initDone = true;
var c = @:privateAccess sdl.Joystick.joyCount();
for( idx in 0...c )
initPad( idx );
haxe.MainLoop.add(syncPads);
}
#elseif (hldx || usesys)
if( !initDone ){
initDone = true;
sdl.Joystick.init();
haxe.MainLoop.add(syncPads);
}
#elseif js
if( !initDone ) {
initDone = true;
js.Browser.window.addEventListener("gamepadconnected", function(p) {
var pad = new hxd.Pad();
pad.d = p.gamepad;
pad.config = pickConfig(pad.d.id);
pad.index = pad.d.index;
pads.set(pad.d.index, pad);
waitPad(pad);
});
js.Browser.window.addEventListener("gamepaddisconnected", function(p) {
var pad = pads.get(p.gamepad.index);
if( pad == null ) return;
pads.remove(p.gamepad.index);
pad.connected = false;
pad.onDisconnect();
});
#if !manual_sync_pad
haxe.MainLoop.add(syncPads);
#end
}
#end
}
}
from hashlink.
The conclusion here is that it would need to be implemented in Heaps at least for Opengl for DirectX more research would be needed. Feel free to close this issue or plan accordingly whatever you feel like I'm just keeping this here for whoever might need it.
from hashlink.
Related Issues (20)
- Get live objects from a specific type
- JIT ERROR 0 mixing hl.UI8 and Float HOT 2
- Explicit constant Float to Int type conversion HOT 1
- --debug is faster to run than non debug. HOT 2
- HL thread hangs when using trace() and semaphores HOT 2
- Can't run any .hl file on Mac M1 - Segmentation Fault HOT 2
- Unexpected value conversion when using an abstract class with type param
- Any way to get hl.Bytes from an hl.NativeArray? HOT 1
- Single and hl.F32 function args for callMethod stack issue HOT 1
- With SDL backend on Windows, adding an element to a SpriteBatch can cause a large lag spike HOT 2
- src/module.c(567) : FATAL ERROR : Failed to load function sdl@gl_polygon_offset HOT 3
- Macbook M1 Support HOT 2
- JIT/VM calls incorrect method HOT 3
- Unable to build C output on Windows gcc HOT 4
- Hashlink access violation/segfault, when abstract is used as inerface HOT 11
- Warnings when compiling mysql module (implicit declaration of function `gethostbyname_r`) HOT 3
- `profile.c` caused build regression HOT 1
- Arguments misbehaving on nightly HOT 1
- Unexpected implicit cast to Int, from `abstract(Null<Int>)` HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hashlink.