Skip to content
GitLab
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
6ff9f1ef
Commit
6ff9f1ef
authored
Oct 14, 2015
by
Benjamin 'Albsi' Albsmeier
Browse files
made the new nice input mapping save
parent
bb5a281f
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/core/engine.cpp
View file @
6ff9f1ef
...
...
@@ -38,15 +38,15 @@ namespace gdw {
throw
std
::
runtime_error
(
"could not initialize SDL"
+
sdl_error
);
}
input_
=
make_unique
<
gdw
::
input
>
(
*
this
);
game_play_system_
=
make_unique
<
gdw
::
game_play_system
>
(
*
this
);
physics_system_
=
make_unique
<
gdw
::
physics_system
>
(
*
this
);
physics_system_
=
make_unique
<
gdw
::
physics_system
>
(
*
this
);
audio_
=
make_unique
<
gdw
::
audio
>
(
*
this
);
audioEventHandler_
=
make_unique
<
gdw
::
AudioEventHandler
>
(
*
this
);
graphics_system_
=
make_unique
<
gdw
::
graphics_system
>
(
*
this
);
input_
=
make_unique
<
gdw
::
input
>
(
*
this
);
rendering_system_
=
make_unique
<
gdw
::
rendering_system
>
(
*
this
);
ui_system_
=
make_unique
<
gdw
::
ui_system
>
(
*
this
);
game_state_machine_
=
make_unique
<
gdw
::
game_state_machine
>
(
*
this
);
game_state_machine_
=
make_unique
<
gdw
::
game_state_machine
>
(
*
this
);
input_
->
addMapping
(
"state_switch"
);
}
...
...
src/gameplay/game_input_manager.cpp
View file @
6ff9f1ef
...
...
@@ -27,6 +27,13 @@ namespace gdw {
const
float
game_input_manager
::
maximum_movement_distance
=
13.0
f
;
game_input_manager
::
game_input_manager
(
engine
&
engine
)
:
engine_
(
engine
)
{
auto
&
input
=
engine_
.
input
();
//input.addMapping("test");
input
.
addMapping
(
"move_left"
);
input
.
addMapping
(
"move_right"
);
input
.
addMapping
(
"place_item"
);
input
.
addMapping
(
"beam_normal"
);
input
.
addMapping
(
"beam_inverse"
);
}
game_input_manager
::~
game_input_manager
()
{
...
...
@@ -40,7 +47,6 @@ namespace gdw {
glm
::
vec3
game_input_manager
::
get_world_mouse_pos
()
{
auto
&
input
=
engine_
.
input
();
input
.
addMapping
(
"test"
);
auto
&
level_manager
=
engine_
.
game_play_system
().
level_manager
();
float
x
=
(
input
.
mousePos
().
x
/
engine_
.
graphics_system
().
width
())
*
2.0
f
-
1
;
...
...
@@ -79,7 +85,7 @@ namespace gdw {
constexpr
float
rotation_speed
=
7.
f
;
constexpr
float
turn_rate_modifier
=
4.5
f
;
if
(
input
.
isPressed
(
"test"
)){
/*
if (input.isPressed("test")){
log << "input test pressed" << std::endl;
}
...
...
@@ -89,7 +95,7 @@ namespace gdw {
if (input.isReleased("test")){
log << "input test released" << std::endl;
}
}
*/
if
(
input
.
isDown
(
"move_left"
)
&&
player
->
position
().
x
>
-
maximum_movement_distance
)
{
auto
orientation
=
player
->
rotation
()
*
glm
::
vec3
(
0
,
0
,
1
);
...
...
src/input/input.cpp
View file @
6ff9f1ef
...
...
@@ -19,50 +19,6 @@ namespace gdw{
//SDL_SetCursor(SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_CROSSHAIR));
if
(
controllerUse
)
SDL_ShowCursor
(
SDL_FALSE
);
addMapping
(
"move_left"
);
addMapping
(
"move_right"
);
addMapping
(
"place_item"
);
addMapping
(
"beam_normal"
);
addMapping
(
"beam_inverse"
);
addMapping
(
"button_click"
);
}
bool
input
::
addMapping
(
std
::
string
name
){
bool
ok
=
false
;
inputMappingStruct
ims
;
std
::
string
s
=
engine_
.
getConfig
().
get
<
std
::
string
>
(
name
+
"_key1"
,
"none"
);
if
(
s
!=
"none"
){
ims
.
keyCode1
=
getKeyFromName
(
s
);
ims
.
type
+=
key1
;
ok
=
true
;
}
s
=
engine_
.
getConfig
().
get
<
std
::
string
>
(
name
+
"_key2"
,
"none"
);
if
(
s
!=
"none"
){
ims
.
keyCode2
=
getKeyFromName
(
s
);
ims
.
type
+=
key2
;
ok
=
true
;
}
s
=
engine_
.
getConfig
().
get
<
std
::
string
>
(
name
+
"_mouse_button"
,
"none"
);
if
(
s
!=
"none"
){
ims
.
mbuttonCode
=
getMButtonFromName
(
s
);
ims
.
type
+=
mbutton
;
ok
=
true
;
}
s
=
engine_
.
getConfig
().
get
<
std
::
string
>
(
name
+
"_controller_button"
,
"none"
);
if
(
s
!=
"none"
){
ims
.
cbuttonCode
=
getCButtonFromName
(
s
);
ims
.
type
+=
cbutton
;
ok
=
true
;
}
s
=
engine_
.
getConfig
().
get
<
std
::
string
>
(
name
+
"_controller_axis"
,
"none"
);
if
(
s
!=
"none"
){
ims
.
caxisCode
=
getCAxisFromName
(
s
);
ims
.
type
+=
caxis
;
ok
=
true
;
}
mappings_
.
emplace
(
name
,
ims
);
return
ok
;
}
input
::~
input
(){}
...
...
@@ -269,8 +225,46 @@ namespace gdw{
}
//MAPPING
bool
input
::
addMapping
(
std
::
string
name
){
bool
ok
=
false
;
inputMappingStruct
ims
;
std
::
string
s
=
engine_
.
getConfig
().
get
<
std
::
string
>
(
name
+
"_key1"
,
"none"
);
if
(
s
!=
"none"
){
ims
.
keyCode1
=
getKeyFromName
(
s
);
ims
.
type
+=
key1
;
ok
=
true
;
}
s
=
engine_
.
getConfig
().
get
<
std
::
string
>
(
name
+
"_key2"
,
"none"
);
if
(
s
!=
"none"
){
ims
.
keyCode2
=
getKeyFromName
(
s
);
ims
.
type
+=
key2
;
ok
=
true
;
}
s
=
engine_
.
getConfig
().
get
<
std
::
string
>
(
name
+
"_mouse_button"
,
"none"
);
if
(
s
!=
"none"
){
ims
.
mbuttonCode
=
getMButtonFromName
(
s
);
ims
.
type
+=
mbutton
;
ok
=
true
;
}
s
=
engine_
.
getConfig
().
get
<
std
::
string
>
(
name
+
"_controller_button"
,
"none"
);
if
(
s
!=
"none"
){
ims
.
cbuttonCode
=
getCButtonFromName
(
s
);
ims
.
type
+=
cbutton
;
ok
=
true
;
}
s
=
engine_
.
getConfig
().
get
<
std
::
string
>
(
name
+
"_controller_axis"
,
"none"
);
if
(
s
!=
"none"
){
ims
.
caxisCode
=
getCAxisFromName
(
s
);
ims
.
type
+=
caxis
;
ok
=
true
;
}
mappings_
.
emplace
(
name
,
ims
);
return
ok
;
}
int
input
::
getKeyCodeByMapping
(
std
::
string
id
,
int
nr
){
auto
it
=
mappings_
.
find
(
id
);
if
(
it
==
mappings_
.
end
())
return
0
;
if
(
nr
==
1
){
return
(
mappings_
.
at
(
it
->
first
).
type
&
key1
)
!=
0
?
mappings_
.
at
(
it
->
first
).
keyCode1
:
0
;
}
else
if
(
nr
==
2
){
...
...
@@ -281,16 +275,19 @@ namespace gdw{
int
input
::
getMButtonCodeByMapping
(
std
::
string
id
){
auto
it
=
mappings_
.
find
(
id
);
if
(
it
==
mappings_
.
end
())
return
-
1
;
return
(
mappings_
.
at
(
it
->
first
).
type
&
mbutton
)
!=
0
?
mappings_
.
at
(
it
->
first
).
mbuttonCode
:
-
1
;
}
SDL_GameControllerButton
input
::
getCButtonCodeByMapping
(
std
::
string
id
){
auto
it
=
mappings_
.
find
(
id
);
if
(
it
==
mappings_
.
end
())
return
SDL_CONTROLLER_BUTTON_INVALID
;
return
(
mappings_
.
at
(
it
->
first
).
type
&
cbutton
)
!=
0
?
mappings_
.
at
(
it
->
first
).
cbuttonCode
:
SDL_CONTROLLER_BUTTON_INVALID
;
}
SDL_GameControllerAxis
input
::
getCAxisCodeByMapping
(
std
::
string
id
){
auto
it
=
mappings_
.
find
(
id
);
if
(
it
==
mappings_
.
end
())
return
SDL_CONTROLLER_AXIS_INVALID
;
return
(
mappings_
.
at
(
it
->
first
).
type
&
caxis
)
!=
0
?
mappings_
.
at
(
it
->
first
).
caxisCode
:
SDL_CONTROLLER_AXIS_INVALID
;
}
...
...
@@ -343,6 +340,7 @@ namespace gdw{
//RETURN
bool
input
::
isPressed
(
std
::
string
id
){
auto
it
=
mappings_
.
find
(
id
);
if
(
it
==
mappings_
.
end
())
return
false
;
if
((
mappings_
.
at
(
it
->
first
).
type
&
key1
)
!=
0
){
if
(
isKeyPressed
(
mappings_
.
at
(
it
->
first
).
keyCode1
)){
return
true
;
...
...
@@ -379,6 +377,7 @@ namespace gdw{
bool
input
::
isDown
(
std
::
string
id
){
auto
it
=
mappings_
.
find
(
id
);
if
(
it
==
mappings_
.
end
())
return
false
;
if
((
mappings_
.
at
(
it
->
first
).
type
&
key1
)
!=
0
){
if
(
isKeyDown
(
mappings_
.
at
(
it
->
first
).
keyCode1
)){
return
true
;
...
...
@@ -415,6 +414,7 @@ namespace gdw{
bool
input
::
isReleased
(
std
::
string
id
){
auto
it
=
mappings_
.
find
(
id
);
if
(
it
==
mappings_
.
end
())
return
false
;
if
((
mappings_
.
at
(
it
->
first
).
type
&
key1
)
!=
0
){
if
(
isKeyReleased
(
mappings_
.
at
(
it
->
first
).
keyCode1
)){
return
true
;
...
...
src/ui/ui_system.cpp
View file @
6ff9f1ef
...
...
@@ -43,6 +43,8 @@ namespace gdw {
//NVGFrameBuffer_ = nvgluCreateFramebuffer( NVGContext_, engine_.graphics_system().width(), engine_.graphics_system().height(), 0);
width
(
engine_
.
graphics_system
().
width
());
height
(
engine_
.
graphics_system
().
height
());
engine_
.
input
().
addMapping
(
"button_click"
);
}
ui_system
::~
ui_system
(){
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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