Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
GameDevWeek
Sommersemester 2015
Cpp
Deth Buff Arr
Commits
3ceea4db
Commit
3ceea4db
authored
Sep 27, 2015
by
Benjamin 'Albsi' Albsmeier
Browse files
fixed a typo
parent
80afd2cf
Changes
6
Hide whitespace changes
Inline
Side-by-side
include/input/input.hpp
View file @
3ceea4db
...
...
@@ -25,8 +25,8 @@ namespace gdw{
bool
active
=
false
;
};
//if you add here, add also a maping in makeMaping() in input.cpp
enum
class
inputMaping
{
//if you add here, add also a map
p
ing in makeMap
p
ing() in input.cpp
enum
class
inputMap
p
ing
{
state_switch
,
player_move_left
,
player_move_right
,
...
...
@@ -35,7 +35,7 @@ namespace gdw{
place_item
};
struct
inputMapingStruct
{
struct
inputMap
p
ingStruct
{
unsigned
int
type
=
0
;
bool
negativAxis
=
false
;
SDL_Keycode
keyCode1
=
0
;
...
...
@@ -52,14 +52,14 @@ namespace gdw{
static
float
constexpr
controllerAxisMax_
=
32767.
f
;
static
float
constexpr
controllerAxisDeadZone_
=
.3
f
;
/**inputMapingStruct.type for key*/
/**inputMap
p
ingStruct.type for key*/
static
unsigned
int
constexpr
key1
=
0x01
;
static
unsigned
int
constexpr
key2
=
0x02
;
/**inputMapingStruct.type for mouse button*/
/**inputMap
p
ingStruct.type for mouse button*/
static
unsigned
int
constexpr
mbutton
=
0x04
;
/**inputMapingStruct.type for controller button*/
/**inputMap
p
ingStruct.type for controller button*/
static
unsigned
int
constexpr
cbutton
=
0x08
;
/**inputMapingStruct.type for controller axis*/
/**inputMap
p
ingStruct.type for controller axis*/
static
unsigned
int
constexpr
caxis
=
0x10
;
public:
input
(
engine
&
engine
);
...
...
@@ -73,34 +73,39 @@ namespace gdw{
* should called once per game loop, at the end*/
void
reset
();
bool
isPressed
(
inputMaping
id
);
bool
isDown
(
inputMaping
id
);
bool
isReleased
(
inputMaping
id
);
/**Returns true every frame, as long as it is down - NOT FOR MULTI CONTROLLER*/
bool
isPressed
(
inputMapping
id
);
/**Returns true once it is pressed - NOT FOR MULTI CONTROLLER*/
bool
isDown
(
inputMapping
id
);
/**Returns true once it is released - NOT FOR MULTI CONTROLLER*/
bool
isReleased
(
inputMapping
id
);
/**Returns true every frame, as long as the key is down.*/
private:
int
isKeyDown
(
SDL_Keycode
key
)
noexcept
{
return
keyState_
[
SDL_GetScancodeFromKey
(
key
)];};
int
isKeyDown
(
inputMaping
key
)
noexcept
{
return
isKeyDown
(
getKeyCodeByMaping
(
key
,
1
))
||
isKeyDown
(
getKeyCodeByMaping
(
key
,
2
));};
int
isKeyDown
(
inputMap
p
ing
key
)
noexcept
{
return
isKeyDown
(
getKeyCodeByMap
p
ing
(
key
,
1
))
||
isKeyDown
(
getKeyCodeByMap
p
ing
(
key
,
2
));};
/**Returns true once the key is pressed*/
bool
isKeyPressed
(
SDL_Keycode
key
)
noexcept
{
return
keyMap_
[
key
]
==
1
;};
bool
isKeyPressed
(
inputMaping
key
)
noexcept
{
return
isKeyPressed
(
getKeyCodeByMaping
(
key
,
1
))
||
isKeyPressed
(
getKeyCodeByMaping
(
key
,
2
));};
bool
isKeyPressed
(
inputMap
p
ing
key
)
noexcept
{
return
isKeyPressed
(
getKeyCodeByMap
p
ing
(
key
,
1
))
||
isKeyPressed
(
getKeyCodeByMap
p
ing
(
key
,
2
));};
/**Returns true once the key is released*/
bool
isKeyReleased
(
SDL_Keycode
key
)
noexcept
{
return
keyReleasedMap_
[
key
]
&&
!
keyState_
[
SDL_GetScancodeFromKey
(
key
)];};
bool
isKeyReleased
(
inputMaping
key
)
noexcept
{
return
isKeyReleased
(
getKeyCodeByMaping
(
key
,
1
))
||
isKeyReleased
(
getKeyCodeByMaping
(
key
,
2
));};
bool
isKeyReleased
(
inputMap
p
ing
key
)
noexcept
{
return
isKeyReleased
(
getKeyCodeByMap
p
ing
(
key
,
1
))
||
isKeyReleased
(
getKeyCodeByMap
p
ing
(
key
,
2
));};
/**Returns true every frame, as long as the mouse button is down.*/
bool
isMouseButtonDown
(
int
button
)
noexcept
{
return
SDL_GetMouseState
(
NULL
,
NULL
)
&
SDL_BUTTON
(
button
);};
bool
isMouseButtonDown
(
inputMaping
button
);
bool
isMouseButtonDown
(
inputMap
p
ing
button
);
/**Returns true once the mouse button is pressed*/
bool
isMouseButtonPressed
(
int
button
)
noexcept
{
return
mouseMap_
[
button
]
==
1
;};
bool
isMouseButtonPressed
(
inputMaping
button
);
bool
isMouseButtonPressed
(
inputMap
p
ing
button
);
/**Returns true once the mouse button is released*/
bool
isMouseButtonReleased
(
int
button
)
noexcept
{
return
mouseReleasedMap_
[
button
];};
bool
isMouseButtonReleased
(
inputMaping
button
);
bool
isMouseButtonReleased
(
inputMap
p
ing
button
);
public:
/**Returns a glm::vec2 with the x and y motion of the mouse wheel
...
...
@@ -126,25 +131,25 @@ namespace gdw{
private:
bool
isControllerButtonDown
(
SDL_GameControllerButton
button
,
int
nr
=
0
);
public:
bool
isControllerButtonDown
(
inputMaping
button
,
int
nr
=
0
)
noexcept
{
return
isControllerButtonDown
(
getCButtonCodeByMaping
(
button
),
nr
);};
bool
isControllerButtonDown
(
inputMap
p
ing
button
,
int
nr
=
0
)
noexcept
{
return
isControllerButtonDown
(
getCButtonCodeByMap
p
ing
(
button
),
nr
);};
/**Returns true once the controller button is pressed*/
private:
bool
isControllerButtonPressed
(
SDL_GameControllerButton
button
,
int
nr
=
0
);
public:
bool
isControllerButtonPressed
(
inputMaping
button
,
int
nr
=
0
)
noexcept
{
return
isControllerButtonPressed
(
getCButtonCodeByMaping
(
button
),
nr
);};
bool
isControllerButtonPressed
(
inputMap
p
ing
button
,
int
nr
=
0
)
noexcept
{
return
isControllerButtonPressed
(
getCButtonCodeByMap
p
ing
(
button
),
nr
);};
/**Returns true once the controller button is released*/
private:
bool
isControllerButtonReleased
(
SDL_GameControllerButton
button
,
int
nr
=
0
);
public:
bool
isControllerButtonReleased
(
inputMaping
button
,
int
nr
=
0
)
noexcept
{
return
isControllerButtonReleased
(
getCButtonCodeByMaping
(
button
),
nr
);};
bool
isControllerButtonReleased
(
inputMap
p
ing
button
,
int
nr
=
0
)
noexcept
{
return
isControllerButtonReleased
(
getCButtonCodeByMap
p
ing
(
button
),
nr
);};
/**Returns the value of that axis as a float between -1 and 1*/
private:
float
controllerAxis
(
SDL_GameControllerAxis
axis
,
int
nr
=
0
);
public:
float
controllerAxis
(
inputMaping
axis
,
int
nr
=
0
)
noexcept
{
return
controllerAxis
(
getCAxisCodeByMaping
(
axis
),
nr
);};
float
controllerAxis
(
inputMap
p
ing
axis
,
int
nr
=
0
)
noexcept
{
return
controllerAxis
(
getCAxisCodeByMap
p
ing
(
axis
),
nr
);};
/**Returns number of aktiv controllers*/
int
controllerCount
()
noexcept
{
return
controllers_
.
size
();};
...
...
@@ -155,14 +160,14 @@ namespace gdw{
std
::
shared_ptr
<
const
asset
>
controllerDB_
;
std
::
unordered_map
<
int
,
controller
>
controllers_
;
std
::
map
<
gdw
::
inputMaping
,
gdw
::
inputMapingStruct
>
mapings_
;
void
makeMapings
();
bool
isMapingOk
(
inputMapingStruct
maping
,
std
::
string
name
);
std
::
map
<
gdw
::
inputMap
p
ing
,
gdw
::
inputMap
p
ingStruct
>
map
p
ings_
;
void
makeMap
p
ings
();
bool
isMap
p
ingOk
(
inputMap
p
ingStruct
map
p
ing
,
std
::
string
name
);
SDL_Keycode
getKeyCodeByMaping
(
inputMaping
id
,
int
nr
);
int
getMButtonCodeByMaping
(
inputMaping
id
);
SDL_GameControllerButton
getCButtonCodeByMaping
(
inputMaping
id
);
SDL_GameControllerAxis
getCAxisCodeByMaping
(
inputMaping
id
);
SDL_Keycode
getKeyCodeByMap
p
ing
(
inputMap
p
ing
id
,
int
nr
);
int
getMButtonCodeByMap
p
ing
(
inputMap
p
ing
id
);
SDL_GameControllerButton
getCButtonCodeByMap
p
ing
(
inputMap
p
ing
id
);
SDL_GameControllerAxis
getCAxisCodeByMap
p
ing
(
inputMap
p
ing
id
);
int
getMButtonFromName
(
std
::
string
name
);
SDL_Keycode
getKeyFromName
(
std
::
string
name
);
...
...
src/audio/AudioEventHandler.cpp
View file @
3ceea4db
...
...
@@ -43,12 +43,12 @@ namespace gdw {
}
void
AudioEventHandler
::
playStateUpdate
(
float
deltaTime
)
{
if
((
this
->
engine
.
input
().
isPressed
(
inputMaping
::
player_move_left
)
||
this
->
engine
.
input
().
isPressed
(
inputMaping
::
player_move_right
))
&&
!
this
->
playerMoving
)
{
if
((
this
->
engine
.
input
().
isPressed
(
inputMap
p
ing
::
player_move_left
)
||
this
->
engine
.
input
().
isPressed
(
inputMap
p
ing
::
player_move_right
))
&&
!
this
->
playerMoving
)
{
this
->
channels
[
"ship"
]
=
this
->
engine
.
audio
().
queue_sound
(
"engine"
,
-
1
);
this
->
engine
.
audio
().
sound_volume
(
40
,
this
->
channels
[
"ship"
]);
this
->
playerMoving
=
true
;
}
if
(
!
this
->
engine
.
input
().
isDown
(
inputMaping
::
player_move_left
)
&&
!
this
->
engine
.
input
().
isDown
(
inputMaping
::
player_move_right
)
&&
this
->
playerMoving
)
{
if
(
!
this
->
engine
.
input
().
isDown
(
inputMap
p
ing
::
player_move_left
)
&&
!
this
->
engine
.
input
().
isDown
(
inputMap
p
ing
::
player_move_right
)
&&
this
->
playerMoving
)
{
this
->
engine
.
audio
().
stop_sound
(
this
->
channels
[
"ship"
],
600
);
this
->
playerMoving
=
false
;
}
...
...
src/game_state_machine/menu_state.cpp
View file @
3ceea4db
...
...
@@ -21,7 +21,7 @@ void menu_state::on_enter() {
}
void
menu_state
::
update
(
float
dt
)
{
if
(
this
->
engine_
.
input
().
isPressed
(
inputMaping
::
state_switch
))
if
(
this
->
engine_
.
input
().
isPressed
(
inputMap
p
ing
::
state_switch
))
this
->
engine_
.
game_state_machine
().
change_state
<
play_state
>
();
}
...
...
src/game_state_machine/play_state.cpp
View file @
3ceea4db
...
...
@@ -58,7 +58,7 @@ void play_state::update(float dt) {
engine_
.
game_play_system
().
update
(
dt
);
this
->
engine_
.
audioEventHandler
().
playStateUpdate
(
dt
);
if
(
this
->
engine_
.
input
().
isPressed
(
inputMaping
::
state_switch
))
if
(
this
->
engine_
.
input
().
isPressed
(
inputMap
p
ing
::
state_switch
))
this
->
engine_
.
game_state_machine
().
change_state
<
menu_state
>
();
}
...
...
src/gameplay/game_input_manager.cpp
View file @
3ceea4db
...
...
@@ -76,7 +76,7 @@ namespace gdw {
constexpr
float
rotation_speed
=
7.
f
;
constexpr
float
turn_rate_modifier
=
4.5
f
;
if
(
input
.
isDown
(
inputMaping
::
player_move_left
)
&&
player
->
position
().
x
>
-
maximum_movement_distance
)
{
if
(
input
.
isDown
(
inputMap
p
ing
::
player_move_left
)
&&
player
->
position
().
x
>
-
maximum_movement_distance
)
{
auto
orientation
=
player
->
rotation
()
*
glm
::
vec3
(
0
,
0
,
1
);
auto
diff
=
std
::
abs
(
orientation
.
x
-
(
-
1.
f
))
+
std
::
abs
(
orientation
.
z
-
(
0.
f
));
auto
clamped
=
glm
::
clamp
(
diff
/
turn_rate_modifier
,
0.
f
,
1.
f
);
...
...
@@ -89,7 +89,7 @@ namespace gdw {
move
->
add_angular_force
(
glm
::
vec3
(
0.
f
,
-
rotation_speed
*
(
std
::
pow
(
diff
,
1.4
f
))
,
0.
f
));
}
if
(
engine_
.
input
().
isDown
(
inputMaping
::
player_move_right
)
&&
player
->
position
().
x
<
maximum_movement_distance
)
{
if
(
engine_
.
input
().
isDown
(
inputMap
p
ing
::
player_move_right
)
&&
player
->
position
().
x
<
maximum_movement_distance
)
{
auto
orientation
=
player
->
rotation
()
*
glm
::
vec3
(
0
,
0
,
1
);
auto
diff
=
std
::
abs
(
orientation
.
x
-
(
1.
f
))
+
std
::
abs
(
orientation
.
z
-
(
0.
f
));
auto
clamped
=
glm
::
clamp
(
diff
/
turn_rate_modifier
,
0.
f
,
1.
f
);
...
...
@@ -103,7 +103,7 @@ namespace gdw {
}
// SET ITEM WITH SPACE KEY
if
(
input
.
isDown
(
inputMaping
::
place_item
))
{
if
(
input
.
isDown
(
inputMap
p
ing
::
place_item
))
{
engine_
.
game_play_system
().
player_item_manager
().
place_item
(
get_world_mouse_pos
());
}
}
...
...
@@ -124,24 +124,24 @@ namespace gdw {
level_manager
.
set_weapon
(
weapon_type
::
portal_gun
);
}
if
(
input
.
isPressed
(
inputMaping
::
beam_normal
))
{
if
(
input
.
isPressed
(
inputMap
p
ing
::
beam_normal
))
{
engine_
.
audioEventHandler
().
trigger
(
AudioEventHandler
::
TRAKTORBEAM_REVERSE_ACTIVATED
);
}
if
(
input
.
isReleased
(
inputMaping
::
beam_normal
))
{
if
(
input
.
isReleased
(
inputMap
p
ing
::
beam_normal
))
{
engine_
.
audioEventHandler
().
trigger
(
AudioEventHandler
::
TRAKTORBEAM_REVERSE_DEACTIVATED
);
}
if
(
input
.
isPressed
(
inputMaping
::
beam_inverse
))
{
if
(
input
.
isPressed
(
inputMap
p
ing
::
beam_inverse
))
{
engine_
.
audioEventHandler
().
trigger
(
AudioEventHandler
::
TRAKTORBEAM_ACTIVATED
);
}
if
(
input
.
isReleased
(
inputMaping
::
beam_inverse
))
{
if
(
input
.
isReleased
(
inputMap
p
ing
::
beam_inverse
))
{
engine_
.
audioEventHandler
().
trigger
(
AudioEventHandler
::
TRAKTORBEAM_DEACTIVATED
);
}
//LEFT && RIGHT CLICK
switch
(
level_manager
.
weapon
())
{
case
weapon_type
::
tractor_beam
:
{
if
(
input
.
isDown
(
inputMaping
::
beam_normal
)
||
input
.
isDown
(
inputMaping
::
beam_inverse
))
{
if
(
input
.
isDown
(
inputMap
p
ing
::
beam_normal
)
||
input
.
isDown
(
inputMap
p
ing
::
beam_inverse
))
{
auto
intersection_point
=
get_world_mouse_pos
();
auto
cannon
=
level_manager
.
cannon
();
...
...
@@ -165,7 +165,7 @@ namespace gdw {
rot
*=
glm
::
quat
(
qw
,
qx
,
qy
,
qz
);
auto
ray_unnormalized
=
glm
::
vec3
(
1.
f
);
if
(
input
.
isDown
(
inputMaping
::
beam_normal
))
{
if
(
input
.
isDown
(
inputMap
p
ing
::
beam_normal
))
{
ray_unnormalized
=
r
.
source
-
r
.
destination
;
}
else
{
ray_unnormalized
=
r
.
destination
-
r
.
source
;
...
...
@@ -181,7 +181,7 @@ namespace gdw {
process_beam_collision
(
r
,
ray_unnormalized
,
beam_velocity
,
ray_length_
,
asteroid_hit
,
portal_type
,
remaining_length
);
if
(
input
.
isDown
(
inputMaping
::
beam_normal
))
{
if
(
input
.
isDown
(
inputMap
p
ing
::
beam_normal
))
{
auto
ray_length
=
(
std
::
abs
(
ray_length_
-
0.
f
)
<
0.001
f
)
?
glm
::
length
(
ray_unnormalized
)
:
ray_length_
;
render_ray
(
&
r
,
ray_length
,
std
::
max
((
beam_velocity
/
10.
f
)
/
2.
f
,
1.
f
),
glm
::
vec3
(
0
,
0
,
1
));
}
else
{
...
...
@@ -197,7 +197,7 @@ namespace gdw {
portal_type
=
-
1
;
ray_length_
=
remaining_length
;
process_beam_collision
(
r2
,
ray_unnormalized
,
beam_velocity
,
ray_length_
,
asteroid_hit
,
portal_type
,
remaining_length
);
if
(
input
.
isDown
(
inputMaping
::
beam_normal
))
{
if
(
input
.
isDown
(
inputMap
p
ing
::
beam_normal
))
{
render_ray
(
&
r2
,
remaining_length
,
std
::
max
((
beam_velocity
/
10.
f
)
/
2.
f
,
1.
f
),
glm
::
vec3
(
0
,
0
,
1
));
}
else
{
render_ray
(
&
r2
,
remaining_length
,
std
::
max
((
beam_velocity
/
10.
f
)
/
2.
f
,
1.
f
),
glm
::
vec3
(
1
,
0
,
0
));
...
...
@@ -212,7 +212,7 @@ namespace gdw {
portal_type
=
-
1
;
ray_length_
=
remaining_length
;
process_beam_collision
(
r2
,
ray_unnormalized
,
beam_velocity
,
ray_length_
,
asteroid_hit
,
portal_type
,
remaining_length
);
if
(
input
.
isDown
(
inputMaping
::
beam_normal
))
{
if
(
input
.
isDown
(
inputMap
p
ing
::
beam_normal
))
{
render_ray
(
&
r2
,
remaining_length
,
std
::
max
((
beam_velocity
/
10.
f
)
/
2.
f
,
1.
f
),
glm
::
vec3
(
0
,
0
,
1
));
}
else
{
render_ray
(
&
r2
,
remaining_length
,
std
::
max
((
beam_velocity
/
10.
f
)
/
2.
f
,
1.
f
),
glm
::
vec3
(
1
,
0
,
0
));
...
...
@@ -227,13 +227,13 @@ namespace gdw {
break
;
}
case
weapon_type
::
portal_gun
:
{
if
(
input
.
isDown
(
inputMaping
::
beam_normal
)
||
input
.
isDown
(
inputMaping
::
beam_inverse
))
{
if
(
input
.
isDown
(
inputMap
p
ing
::
beam_normal
)
||
input
.
isDown
(
inputMap
p
ing
::
beam_inverse
))
{
auto
intersection_point
=
get_world_mouse_pos
();
if
(
input
.
isDown
(
inputMaping
::
beam_normal
))
if
(
input
.
isDown
(
inputMap
p
ing
::
beam_normal
))
level_manager
.
create_blue_portal
(
intersection_point
);
if
(
input
.
isDown
(
inputMaping
::
beam_inverse
))
if
(
input
.
isDown
(
inputMap
p
ing
::
beam_inverse
))
level_manager
.
create_yellow_portal
(
intersection_point
);
}
break
;
...
...
src/input/input.cpp
View file @
3ceea4db
...
...
@@ -6,13 +6,13 @@
#include <util/config.hpp>
namespace
gdw
{
input
::
input
(
engine
&
engine
)
:
engine_
(
engine
),
mousePos_
(
0
,
0
),
mouseWheel_
(
0
,
0
),
controllers_
(),
mapings_
(){
input
::
input
(
engine
&
engine
)
:
engine_
(
engine
),
mousePos_
(
0
,
0
),
mouseWheel_
(
0
,
0
),
controllers_
(),
map
p
ings_
(){
keyState_
=
SDL_GetKeyboardState
(
NULL
);
controllerDB_
=
engine
.
asset_manager
().
load
(
engine
.
asset_manager
().
native_name
(
controllerDBPath_
));
makeMapings
();
makeMap
p
ings
();
}
/** if you add here, add also in enum inputMaping in input.hpp
/** if you add here, add also in enum inputMap
p
ing in input.hpp
*
* key names: http://wiki.libsdl.org/SDL_Keycode?highlight=%28%5CbCategoryEnum%5Cb%29%7C%28CategoryKeyboard%29
* getKeyFromName(std::string)
...
...
@@ -33,56 +33,56 @@ namespace gdw{
* DON'T MISS TO ADD THE RIGHT TYPES [ key1 | mbutton | cbutton | caxis]!
* CAXIS DON'T TRIGGER 'PRESSED' OR 'RELEASED' IT ONLY TRIGGERS 'DOWN'!
*/
void
input
::
makeMapings
(){
inputMapingStruct
state_switch_
;
void
input
::
makeMap
p
ings
(){
inputMap
p
ingStruct
state_switch_
;
state_switch_
.
type
=
key1
+
cbutton
;
state_switch_
.
keyCode1
=
getKeyFromName
(
engine_
.
getConfig
().
get
<
std
::
string
>
(
"state_switch_key"
,
"Escape"
));
state_switch_
.
cbuttonCode
=
getCButtonFromName
(
engine_
.
getConfig
().
get
<
std
::
string
>
(
"state_switch_cbutton"
,
"START"
));
isMapingOk
(
state_switch_
,
"state_switch"
);
mapings_
.
emplace
(
inputMaping
::
state_switch
,
state_switch_
);
isMap
p
ingOk
(
state_switch_
,
"state_switch"
);
map
p
ings_
.
emplace
(
inputMap
p
ing
::
state_switch
,
state_switch_
);
inputMapingStruct
player_move_left_
;
inputMap
p
ingStruct
player_move_left_
;
player_move_left_
.
type
=
key1
+
key2
+
cbutton
+
caxis
;
player_move_left_
.
keyCode1
=
getKeyFromName
(
engine_
.
getConfig
().
get
<
std
::
string
>
(
"player_move_left_key"
,
"A"
));
player_move_left_
.
keyCode2
=
getKeyFromName
(
engine_
.
getConfig
().
get
<
std
::
string
>
(
"player_move_left_key2"
,
"A"
));
player_move_left_
.
cbuttonCode
=
getCButtonFromName
(
engine_
.
getConfig
().
get
<
std
::
string
>
(
"player_move_left_cbutton"
,
"LEFT"
));
player_move_left_
.
caxisCode
=
getCAxisFromName
(
engine_
.
getConfig
().
get
<
std
::
string
>
(
"player_move_left_caxis"
,
"RIGHTX"
));
player_move_left_
.
negativAxis
=
true
;
isMapingOk
(
player_move_left_
,
"player_move_left"
);
mapings_
.
emplace
(
inputMaping
::
player_move_left
,
player_move_left_
);
isMap
p
ingOk
(
player_move_left_
,
"player_move_left"
);
map
p
ings_
.
emplace
(
inputMap
p
ing
::
player_move_left
,
player_move_left_
);
inputMapingStruct
player_move_right_
;
inputMap
p
ingStruct
player_move_right_
;
player_move_right_
.
type
=
key1
+
key2
+
cbutton
+
caxis
;
player_move_right_
.
keyCode1
=
getKeyFromName
(
engine_
.
getConfig
().
get
<
std
::
string
>
(
"player_move_right_key"
,
"D"
));
player_move_right_
.
keyCode2
=
getKeyFromName
(
engine_
.
getConfig
().
get
<
std
::
string
>
(
"player_move_right_key2"
,
"A"
));
player_move_right_
.
cbuttonCode
=
getCButtonFromName
(
engine_
.
getConfig
().
get
<
std
::
string
>
(
"player_move_right_cbutton"
,
"RIGHT"
));
player_move_right_
.
caxisCode
=
getCAxisFromName
(
engine_
.
getConfig
().
get
<
std
::
string
>
(
"player_move_right_caxis"
,
"RIGHTX"
));
isMapingOk
(
player_move_right_
,
"player_move_right"
);
mapings_
.
emplace
(
inputMaping
::
player_move_right
,
player_move_right_
);
isMap
p
ingOk
(
player_move_right_
,
"player_move_right"
);
map
p
ings_
.
emplace
(
inputMap
p
ing
::
player_move_right
,
player_move_right_
);
inputMapingStruct
place_item_
;
inputMap
p
ingStruct
place_item_
;
place_item_
.
type
=
key1
+
mbutton
+
cbutton
;
place_item_
.
keyCode1
=
getKeyFromName
(
engine_
.
getConfig
().
get
<
std
::
string
>
(
"place_item_key"
,
"Space"
));
place_item_
.
mbuttonCode
=
getMButtonFromName
(
engine_
.
getConfig
().
get
<
std
::
string
>
(
"place_item_mbutton"
,
"Middle"
));
place_item_
.
cbuttonCode
=
getCButtonFromName
(
engine_
.
getConfig
().
get
<
std
::
string
>
(
"place_item_cbutton"
,
"A"
));
isMapingOk
(
place_item_
,
"place_item"
);
mapings_
.
emplace
(
inputMaping
::
place_item
,
place_item_
);
isMap
p
ingOk
(
place_item_
,
"place_item"
);
map
p
ings_
.
emplace
(
inputMap
p
ing
::
place_item
,
place_item_
);
inputMapingStruct
beam_normal_
;
inputMap
p
ingStruct
beam_normal_
;
beam_normal_
.
type
=
key1
+
mbutton
+
caxis
;
beam_normal_
.
mbuttonCode
=
getMButtonFromName
(
engine_
.
getConfig
().
get
<
std
::
string
>
(
"beam_normal_mouse"
,
"Left"
));
beam_normal_
.
keyCode1
=
getKeyFromName
(
engine_
.
getConfig
().
get
<
std
::
string
>
(
"beam_normal_key"
,
"Q"
));
beam_normal_
.
caxisCode
=
getCAxisFromName
(
engine_
.
getConfig
().
get
<
std
::
string
>
(
"beam_normal_caxis"
,
"LEFTTRIGGER"
));
isMapingOk
(
beam_normal_
,
"beam_normal"
);
mapings_
.
emplace
(
inputMaping
::
beam_normal
,
beam_normal_
);
isMap
p
ingOk
(
beam_normal_
,
"beam_normal"
);
map
p
ings_
.
emplace
(
inputMap
p
ing
::
beam_normal
,
beam_normal_
);
inputMapingStruct
beam_inverse_
;
inputMap
p
ingStruct
beam_inverse_
;
beam_inverse_
.
type
=
key1
+
mbutton
+
caxis
;
beam_inverse_
.
mbuttonCode
=
getMButtonFromName
(
engine_
.
getConfig
().
get
<
std
::
string
>
(
"beam_inverse_mouse"
,
"Right"
));
beam_inverse_
.
keyCode1
=
getKeyFromName
(
engine_
.
getConfig
().
get
<
std
::
string
>
(
"beam_inverse_key"
,
"E"
));
beam_inverse_
.
caxisCode
=
getCAxisFromName
(
engine_
.
getConfig
().
get
<
std
::
string
>
(
"beam_inverse_caxis"
,
"RIGHTTRIGGER"
));
isMapingOk
(
beam_inverse_
,
"beam_inverse"
);
mapings_
.
emplace
(
inputMaping
::
beam_inverse
,
beam_inverse_
);
isMap
p
ingOk
(
beam_inverse_
,
"beam_inverse"
);
map
p
ings_
.
emplace
(
inputMap
p
ing
::
beam_inverse
,
beam_inverse_
);
}
input
::~
input
(){}
...
...
@@ -217,26 +217,26 @@ namespace gdw{
}
}
//MAPING
int
input
::
getKeyCodeByMaping
(
inputMaping
id
,
int
nr
){
//MAP
P
ING
int
input
::
getKeyCodeByMap
p
ing
(
inputMap
p
ing
id
,
int
nr
){
if
(
nr
==
1
){
return
(
mapings_
[
id
].
type
&
key1
)
!=
0
?
mapings_
[
id
].
keyCode1
:
0
;
return
(
map
p
ings_
[
id
].
type
&
key1
)
!=
0
?
map
p
ings_
[
id
].
keyCode1
:
0
;
}
else
if
(
nr
==
2
){
return
(
mapings_
[
id
].
type
&
key2
)
!=
0
?
mapings_
[
id
].
keyCode2
:
0
;
return
(
map
p
ings_
[
id
].
type
&
key2
)
!=
0
?
map
p
ings_
[
id
].
keyCode2
:
0
;
}
return
0
;
}
int
input
::
getMButtonCodeByMaping
(
inputMaping
id
){
return
(
mapings_
[
id
].
type
&
mbutton
)
!=
0
?
mapings_
[
id
].
mbuttonCode
:
-
1
;
int
input
::
getMButtonCodeByMap
p
ing
(
inputMap
p
ing
id
){
return
(
map
p
ings_
[
id
].
type
&
mbutton
)
!=
0
?
map
p
ings_
[
id
].
mbuttonCode
:
-
1
;
}
SDL_GameControllerButton
input
::
getCButtonCodeByMaping
(
inputMaping
id
){
return
(
mapings_
[
id
].
type
&
cbutton
)
!=
0
?
mapings_
[
id
].
cbuttonCode
:
SDL_CONTROLLER_BUTTON_INVALID
;
SDL_GameControllerButton
input
::
getCButtonCodeByMap
p
ing
(
inputMap
p
ing
id
){
return
(
map
p
ings_
[
id
].
type
&
cbutton
)
!=
0
?
map
p
ings_
[
id
].
cbuttonCode
:
SDL_CONTROLLER_BUTTON_INVALID
;
}
SDL_GameControllerAxis
input
::
getCAxisCodeByMaping
(
inputMaping
id
){
return
(
mapings_
[
id
].
type
&
caxis
)
!=
0
?
mapings_
[
id
].
caxisCode
:
SDL_CONTROLLER_AXIS_INVALID
;
SDL_GameControllerAxis
input
::
getCAxisCodeByMap
p
ing
(
inputMap
p
ing
id
){
return
(
map
p
ings_
[
id
].
type
&
caxis
)
!=
0
?
map
p
ings_
[
id
].
caxisCode
:
SDL_CONTROLLER_AXIS_INVALID
;
}
int
input
::
getMButtonFromName
(
std
::
string
name
){
...
...
@@ -277,63 +277,63 @@ namespace gdw{
}
//RETURN
bool
input
::
isPressed
(
inputMaping
id
){
if
((
mapings_
[
id
].
type
&
key1
)
!=
0
){
if
(
isKeyPressed
(
mapings_
[
id
].
keyCode1
)){
bool
input
::
isPressed
(
inputMap
p
ing
id
){
if
((
map
p
ings_
[
id
].
type
&
key1
)
!=
0
){
if
(
isKeyPressed
(
map
p
ings_
[
id
].
keyCode1
)){
return
true
;
}
}
if
((
mapings_
[
id
].
type
&
key2
)
!=
0
){
if
(
isKeyPressed
(
mapings_
[
id
].
keyCode2
)){
if
((
map
p
ings_
[
id
].
type
&
key2
)
!=
0
){
if
(
isKeyPressed
(
map
p
ings_
[
id
].
keyCode2
)){
return
true
;
}
}
if
((
mapings_
[
id
].
type
&
mbutton
)
!=
0
){
if
(
isMouseButtonPressed
(
mapings_
[
id
].
mbuttonCode
)){
if
((
map
p
ings_
[
id
].
type
&
mbutton
)
!=
0
){
if
(
isMouseButtonPressed
(
map
p
ings_
[
id
].
mbuttonCode
)){
return
true
;
}
}
if
((
mapings_
[
id
].
type
&
cbutton
)
!=
0
){
if
(
isControllerButtonPressed
(
mapings_
[
id
].
cbuttonCode
)){
if
((
map
p
ings_
[
id
].
type
&
cbutton
)
!=
0
){
if
(
isControllerButtonPressed
(
map
p
ings_
[
id
].
cbuttonCode
)){
return
true
;
}
}
/*if((mapings_[id].type & caxis) != 0){
if(controllerAxis(mapings_[id].caxisCode)){
/*if((map
p
ings_[id].type & caxis) != 0){
if(controllerAxis(map
p
ings_[id].caxisCode)){
return true;
}
}*/
return
false
;
}
bool
input
::
isDown
(
inputMaping
id
){
if
((
mapings_
[
id
].
type
&
key1
)
!=
0
){
if
(
isKeyDown
(
mapings_
[
id
].
keyCode1
)){
bool
input
::
isDown
(
inputMap
p
ing
id
){
if
((
map
p
ings_
[
id
].
type
&
key1
)
!=
0
){
if
(
isKeyDown
(
map
p
ings_
[
id
].
keyCode1
)){
return
true
;
}
}
if
((
mapings_
[
id
].
type
&
key2
)
!=
0
){
if
(
isKeyDown
(
mapings_
[
id
].
keyCode2
)){
if
((
map
p
ings_
[
id
].
type
&
key2
)
!=
0
){
if
(
isKeyDown
(
map
p
ings_
[
id
].
keyCode2
)){
return
true
;
}
}
if
((
mapings_
[
id
].
type
&
mbutton
)
!=
0
){
if
(
isMouseButtonDown
(
mapings_
[
id
].
mbuttonCode
)){
if
((
map
p
ings_
[
id
].
type
&
mbutton
)
!=
0
){
if
(
isMouseButtonDown
(
map
p
ings_
[
id
].
mbuttonCode
)){
return
true
;
}
}
if
((
mapings_
[
id
].
type
&
cbutton
)
!=
0
){
if
(
isControllerButtonDown
(
mapings_
[
id
].
cbuttonCode
)){
if
((
map
p
ings_
[
id
].
type
&
cbutton
)
!=
0
){
if
(
isControllerButtonDown
(
map
p
ings_
[
id
].
cbuttonCode
)){
return
true
;
}
}
if
((
mapings_
[
id
].
type
&
caxis
)
!=
0
){
if
(
!
mapings_
[
id
].
negativAxis
){
if
(
controllerAxis
(
mapings_
[
id
].
caxisCode
)
>
controllerAxisDeadZone_
){
if
((
map
p
ings_
[
id
].
type
&
caxis
)
!=
0
){
if
(
!
map
p
ings_
[
id
].
negativAxis
){
if
(
controllerAxis
(
map
p
ings_
[
id
].
caxisCode
)
>
controllerAxisDeadZone_
){
return
true
;
}
}
else
{
if
(
controllerAxis
(
mapings_
[
id
].
caxisCode
)
<
-
controllerAxisDeadZone_
){
if
(
controllerAxis
(
map
p
ings_
[
id
].
caxisCode
)
<
-
controllerAxisDeadZone_
){
return
true
;
}
}
...
...
@@ -341,47 +341,47 @@ namespace gdw{
return
false
;
}
bool
input
::
isReleased
(
inputMaping
id
){
if
((
mapings_
[
id
].
type
&
key1
)
!=
0
){
if
(
isKeyReleased
(
mapings_
[
id
].
keyCode1
)){
bool
input
::
isReleased
(
inputMap
p
ing
id
){
if
((
map
p
ings_
[
id
].
type
&
key1
)
!=
0
){
if
(
isKeyReleased
(
map
p
ings_
[
id
].
keyCode1
)){
return
true
;
}
}
if
((
mapings_
[
id
].
type
&
key2
)
!=
0
){
if
(
isKeyReleased
(
mapings_
[
id
].
keyCode2
)){
if
((
map
p
ings_
[
id
].
type
&
key2
)
!=
0
){
if
(
isKeyReleased
(
map
p
ings_
[
id
].
keyCode2
)){
return
true
;
}
}
if
((
mapings_
[
id
].
type
&
mbutton
)
!=
0
){
if
(
isMouseButtonReleased
(
mapings_
[
id
].
mbuttonCode
)){
if
((
map
p
ings_
[
id
].
type
&
mbutton
)
!=
0
){
if
(
isMouseButtonReleased
(
map
p
ings_
[
id
].
mbuttonCode
)){
return
true
;
}
}
if
((
mapings_
[
id
].
type
&
cbutton
)
!=
0
){
if
(
isControllerButtonReleased
(
mapings_
[
id
].
cbuttonCode
)){
if
((
map
p
ings_
[
id
].
type
&
cbutton
)
!=
0
){
if
(
isControllerButtonReleased
(
map
p
ings_
[
id
].
cbuttonCode
)){
return
true
;
}
}
/*if((mapings_[id].type & caxis) != 0){
if(controllerAxis(mapings_[id].caxisCode)){
/*if((map
p
ings_[id].type & caxis) != 0){
if(controllerAxis(map
p
ings_[id].caxisCode)){
return true;
}
}*/
return
false
;
}
bool
input
::
isMouseButtonDown
(
inputMaping
button
){
int
c
=
getMButtonCodeByMaping
(
button
);
bool
input
::
isMouseButtonDown
(
inputMap
p
ing
button
){
int
c
=
getMButtonCodeByMap
p
ing
(
button
);
return
c
!=
-
1
?
isMouseButtonDown
(
c
)
:
false
;
}
bool
input
::
isMouseButtonPressed
(
inputMaping
button
){
int
c
=
getMButtonCodeByMaping
(
button
);
bool
input
::
isMouseButtonPressed
(
inputMap
p
ing
button
){
int
c
=
getMButtonCodeByMap
p
ing
(
button
);
return
c
!=
-
1
?
isMouseButtonPressed
(
c
)
:
false
;
}
bool
input
::
isMouseButtonReleased
(
inputMaping
button
){
int
c
=
getMButtonCodeByMaping
(
button
);
bool
input
::
isMouseButtonReleased
(
inputMap
p
ing
button
){
int
c
=
getMButtonCodeByMap
p
ing
(
button
);
return
c
!=
-
1
?
isMouseButtonReleased
(
c
)
:
false
;
}
...
...
@@ -422,7 +422,7 @@ namespace gdw{
return
0.
f
;
}
bool
input
::
isMapingOk
(
inputMapingStruct
m
,
std
::
string
n
){
bool
input
::
isMap
p
ingOk
(
inputMap
p
ingStruct
m
,
std
::
string
n
){
bool
ok
=
true
;
if
((
m
.
type
&
key1
)
!=
0
&&
m
.
keyCode1
==
0
){
ok
=
false
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment