File confec.cpp changed (mode: 100644) (index a12c9ae..33863e4) |
... |
... |
void HitCallback( fworld::Entity *ent_a, fworld::Entity *ent_b, int damage ){ |
2520 |
2520 |
sleep_mode = false; |
sleep_mode = false; |
2521 |
2521 |
} |
} |
2522 |
2522 |
} |
} |
|
2523 |
|
// Blood. |
2523 |
2524 |
MakeGibs( |
MakeGibs( |
2524 |
2525 |
ent_b->x + 0.5, |
ent_b->x + 0.5, |
2525 |
2526 |
ent_b->y + 1.0 - ent_b->height * 0.75 / world.tileSize, |
ent_b->y + 1.0 - ent_b->height * 0.75 / world.tileSize, |
2526 |
2527 |
linalg::normalize( linalg::vec<double,3>( ent_b->x - ent_a->x, ent_b->y - ent_a->y, 0.0 ) ) * 10.0, |
linalg::normalize( linalg::vec<double,3>( ent_b->x - ent_a->x, ent_b->y - ent_a->y, 0.0 ) ) * 10.0, |
2527 |
2528 |
std::max( damage, 3 ) |
std::max( damage, 3 ) |
2528 |
2529 |
); |
); |
|
2530 |
|
// Controller rumble. |
|
2531 |
|
float intensity = std::fminf( std::max( damage, 3 ) / 50.0f, 1.0f ); |
|
2532 |
|
// Assuming conventional rumblers (motor with asymmetrical weight). |
|
2533 |
|
// The uppermost third of rumble voltage delivers the desired effect. |
|
2534 |
|
// ~150 ms is the minimum duration for rumblers to work. |
|
2535 |
|
fgl::hapticRumble( |
|
2536 |
|
lerp( 0.667, 1.0, intensity ), |
|
2537 |
|
std::max( (int)( intensity * 1000 ), 150 ) |
|
2538 |
|
); |
|
2539 |
|
// Sound. |
2529 |
2540 |
csPlaySound( "melee_hit", false ); |
csPlaySound( "melee_hit", false ); |
2530 |
2541 |
} |
} |
2531 |
2542 |
|
|
File include/fg2/fg2.h changed (mode: 100755) (index 4b35a45..a2f3ce4) |
... |
... |
bool touchStart = false; |
318 |
318 |
SDL_Window* window = nullptr; |
SDL_Window* window = nullptr; |
319 |
319 |
SDL_GLContext ctx = 0; |
SDL_GLContext ctx = 0; |
320 |
320 |
SDL_GameController* controller = nullptr; |
SDL_GameController* controller = nullptr; |
|
321 |
|
SDL_Haptic* haptic = nullptr; |
321 |
322 |
|
|
322 |
323 |
SDL_Rect textInputRect = {}; |
SDL_Rect textInputRect = {}; |
323 |
324 |
bool textInputEnabled = false; |
bool textInputEnabled = false; |
|
... |
... |
Display createDisplay( unsigned int width, unsigned int height, std::string titl |
1617 |
1618 |
|
|
1618 |
1619 |
Display disp = newDisplay; |
Display disp = newDisplay; |
1619 |
1620 |
|
|
1620 |
|
if( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER ) < 0 ){ |
|
|
1621 |
|
if( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER | SDL_INIT_HAPTIC ) < 0 ){ |
1621 |
1622 |
fprintf( stderr, "Failed to initialize SDL.\n" ); |
fprintf( stderr, "Failed to initialize SDL.\n" ); |
1622 |
1623 |
return disp; |
return disp; |
1623 |
1624 |
} |
} |
|
... |
... |
Display createDisplay( unsigned int width, unsigned int height, std::string titl |
1864 |
1865 |
if( SDL_IsGameController( i ) ){ |
if( SDL_IsGameController( i ) ){ |
1865 |
1866 |
controller = SDL_GameControllerOpen( i ); |
controller = SDL_GameControllerOpen( i ); |
1866 |
1867 |
if( controller ){ |
if( controller ){ |
|
1868 |
|
// Open the controller's haptic device. |
|
1869 |
|
haptic = SDL_HapticOpenFromJoystick( SDL_GameControllerGetJoystick( controller ) ); |
|
1870 |
|
// Verify rumble support. |
|
1871 |
|
if( SDL_HapticRumbleInit( haptic ) < 0 ){ |
|
1872 |
|
SDL_HapticClose( haptic ); |
|
1873 |
|
haptic = nullptr; |
|
1874 |
|
} |
1867 |
1875 |
break; |
break; |
1868 |
1876 |
}else{ |
}else{ |
1869 |
1877 |
fprintf( stderr, "Failed to open game controller %d: %s\n", i, SDL_GetError() ); |
fprintf( stderr, "Failed to open game controller %d: %s\n", i, SDL_GetError() ); |
|
... |
... |
void syncEvents(){ |
1996 |
2004 |
// Handle controller hotplugging. |
// Handle controller hotplugging. |
1997 |
2005 |
if( !controller || !SDL_GameControllerGetAttached( controller ) ){ |
if( !controller || !SDL_GameControllerGetAttached( controller ) ){ |
1998 |
2006 |
controller = nullptr; |
controller = nullptr; |
|
2007 |
|
if( haptic ){ |
|
2008 |
|
// Clean up haptic device. |
|
2009 |
|
SDL_HapticClose( haptic ); |
|
2010 |
|
haptic = nullptr; |
|
2011 |
|
} |
1999 |
2012 |
// Open the first available controller. |
// Open the first available controller. |
2000 |
2013 |
for( int i = 0; i < SDL_NumJoysticks(); i++ ){ |
for( int i = 0; i < SDL_NumJoysticks(); i++ ){ |
2001 |
2014 |
if( SDL_IsGameController( i ) ){ |
if( SDL_IsGameController( i ) ){ |
2002 |
2015 |
// Open the controller. |
// Open the controller. |
2003 |
2016 |
controller = SDL_GameControllerOpen( i ); |
controller = SDL_GameControllerOpen( i ); |
2004 |
|
if( controller ) break; |
|
|
2017 |
|
if( controller ){ |
|
2018 |
|
// Open the controller's haptic device. |
|
2019 |
|
haptic = SDL_HapticOpenFromJoystick( SDL_GameControllerGetJoystick( controller ) ); |
|
2020 |
|
// Verify rumble support. |
|
2021 |
|
if( SDL_HapticRumbleInit( haptic ) < 0 ){ |
|
2022 |
|
SDL_HapticClose( haptic ); |
|
2023 |
|
haptic = nullptr; |
|
2024 |
|
} |
|
2025 |
|
break; |
|
2026 |
|
} |
2005 |
2027 |
} |
} |
2006 |
2028 |
} |
} |
2007 |
2029 |
} |
} |
|
... |
... |
void trapMouse( bool trap ){ |
2269 |
2291 |
} |
} |
2270 |
2292 |
} |
} |
2271 |
2293 |
|
|
|
2294 |
|
void hapticRumble( float strength, unsigned int length ){ |
|
2295 |
|
if( haptic ) |
|
2296 |
|
SDL_HapticRumblePlay( haptic, strength, (Uint32)length ); |
|
2297 |
|
} |
|
2298 |
|
|
2272 |
2299 |
void end(){ |
void end(){ |
|
2300 |
|
if( haptic ){ |
|
2301 |
|
SDL_HapticClose( haptic ); |
|
2302 |
|
} |
2273 |
2303 |
if( controller ){ |
if( controller ){ |
2274 |
2304 |
SDL_GameControllerClose( controller ); |
SDL_GameControllerClose( controller ); |
2275 |
2305 |
} |
} |
File include/fg3/fg3.h changed (mode: 100644) (index 4eea18a..9a8e24e) |
... |
... |
bool touchStart = false; |
499 |
499 |
SDL_Window* window; |
SDL_Window* window; |
500 |
500 |
SDL_GLContext ctx; |
SDL_GLContext ctx; |
501 |
501 |
SDL_GameController* controller = nullptr; |
SDL_GameController* controller = nullptr; |
|
502 |
|
SDL_Haptic* haptic = nullptr; |
502 |
503 |
|
|
503 |
504 |
// TODO: SFML text input. |
// TODO: SFML text input. |
504 |
505 |
SDL_Rect textInputRect = {}; |
SDL_Rect textInputRect = {}; |
|
... |
... |
Display createDisplay( unsigned int width, unsigned int height, std::string titl |
1791 |
1792 |
Display disp = newDisplay; |
Display disp = newDisplay; |
1792 |
1793 |
|
|
1793 |
1794 |
# ifdef SDL_MAJOR_VERSION |
# ifdef SDL_MAJOR_VERSION |
1794 |
|
if( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER ) < 0 ){ |
|
|
1795 |
|
if( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER | SDL_INIT_HAPTIC ) < 0 ){ |
1795 |
1796 |
_ERROUT_ << "Failed to initialize SDL." << std::endl; |
_ERROUT_ << "Failed to initialize SDL." << std::endl; |
1796 |
1797 |
return disp; |
return disp; |
1797 |
1798 |
} |
} |
|
... |
... |
Display createDisplay( unsigned int width, unsigned int height, std::string titl |
1885 |
1886 |
if( SDL_IsGameController( i ) ){ |
if( SDL_IsGameController( i ) ){ |
1886 |
1887 |
controller = SDL_GameControllerOpen( i ); |
controller = SDL_GameControllerOpen( i ); |
1887 |
1888 |
if( controller ){ |
if( controller ){ |
|
1889 |
|
// Open the controller's haptic device. |
|
1890 |
|
haptic = SDL_HapticOpenFromJoystick( SDL_GameControllerGetJoystick( controller ) ); |
|
1891 |
|
// Verify rumble support. |
|
1892 |
|
if( SDL_HapticRumbleInit( haptic ) < 0 ){ |
|
1893 |
|
SDL_HapticClose( haptic ); |
|
1894 |
|
haptic = nullptr; |
|
1895 |
|
} |
1888 |
1896 |
break; |
break; |
1889 |
1897 |
}else{ |
}else{ |
1890 |
1898 |
_ERROUT_ << "Failed to open game controller " << i << ": " << SDL_GetError() << std::endl; |
_ERROUT_ << "Failed to open game controller " << i << ": " << SDL_GetError() << std::endl; |
|
... |
... |
void syncEvents(){ |
2166 |
2174 |
// Handle controller hotplugging. |
// Handle controller hotplugging. |
2167 |
2175 |
if( !controller || !SDL_GameControllerGetAttached( controller ) ){ |
if( !controller || !SDL_GameControllerGetAttached( controller ) ){ |
2168 |
2176 |
controller = nullptr; |
controller = nullptr; |
|
2177 |
|
if( haptic ){ |
|
2178 |
|
// Clean up haptic device. |
|
2179 |
|
SDL_HapticClose( haptic ); |
|
2180 |
|
haptic = nullptr; |
|
2181 |
|
} |
2169 |
2182 |
// Open the first available controller. |
// Open the first available controller. |
2170 |
2183 |
for( int i = 0; i < SDL_NumJoysticks(); i++ ){ |
for( int i = 0; i < SDL_NumJoysticks(); i++ ){ |
2171 |
2184 |
if( SDL_IsGameController( i ) ){ |
if( SDL_IsGameController( i ) ){ |
2172 |
2185 |
// Open the controller. |
// Open the controller. |
2173 |
2186 |
controller = SDL_GameControllerOpen( i ); |
controller = SDL_GameControllerOpen( i ); |
2174 |
|
if( controller ) break; |
|
|
2187 |
|
if( controller ){ |
|
2188 |
|
// Open the controller's haptic device. |
|
2189 |
|
haptic = SDL_HapticOpenFromJoystick( SDL_GameControllerGetJoystick( controller ) ); |
|
2190 |
|
// Verify rumble support. |
|
2191 |
|
if( SDL_HapticRumbleInit( haptic ) < 0 ){ |
|
2192 |
|
SDL_HapticClose( haptic ); |
|
2193 |
|
haptic = nullptr; |
|
2194 |
|
} |
|
2195 |
|
break; |
|
2196 |
|
} |
2175 |
2197 |
} |
} |
2176 |
2198 |
} |
} |
2177 |
2199 |
} |
} |
|
... |
... |
void trapMouse( bool trap ){ |
2382 |
2404 |
} |
} |
2383 |
2405 |
} |
} |
2384 |
2406 |
|
|
|
2407 |
|
void hapticRumble( float strength, unsigned int length ){ |
|
2408 |
|
if( haptic ) |
|
2409 |
|
SDL_HapticRumblePlay( haptic, strength, (Uint32)length ); |
|
2410 |
|
} |
|
2411 |
|
|
2385 |
2412 |
void end(){ |
void end(){ |
|
2413 |
|
if( haptic ){ |
|
2414 |
|
SDL_HapticClose( haptic ); |
|
2415 |
|
} |
2386 |
2416 |
if( controller ){ |
if( controller ){ |
2387 |
2417 |
SDL_GameControllerClose( controller ); |
SDL_GameControllerClose( controller ); |
2388 |
2418 |
} |
} |
|
... |
... |
void trapMouse( bool trap ){ |
2499 |
2529 |
mouseTrapped = trap; |
mouseTrapped = trap; |
2500 |
2530 |
} |
} |
2501 |
2531 |
|
|
|
2532 |
|
void hapticRumble( float strength, unsigned int length ){ |
|
2533 |
|
// TODO: SFML haptic rumble. |
|
2534 |
|
} |
|
2535 |
|
|
2502 |
2536 |
void end(){ |
void end(){ |
2503 |
2537 |
window.close(); |
window.close(); |
2504 |
2538 |
exit( 0 ); |
exit( 0 ); |