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
bb8aa771
Commit
bb8aa771
authored
Sep 21, 2015
by
Benjamin 'Albsi' Albsmeier
Browse files
input is not working - but no errors
parent
f746f63a
Changes
6
Hide whitespace changes
Inline
Side-by-side
include/core/engine.hpp
View file @
bb8aa771
...
...
@@ -8,6 +8,7 @@
namespace
gdw
{
class
audio
;
class
graphics_system
;
class
input
;
class
rendering_system
;
}
...
...
@@ -19,6 +20,7 @@ namespace gdw {
gdw
::
config_manager
config_manager_
;
std
::
unique_ptr
<
gdw
::
audio
>
audio_
;
std
::
unique_ptr
<
gdw
::
graphics_system
>
graphics_system_
;
std
::
unique_ptr
<
gdw
::
input
>
input_
;
std
::
unique_ptr
<
gdw
::
rendering_system
>
rendering_system_
;
// needs to be the last one that will be destroyed
...
...
@@ -61,6 +63,10 @@ namespace gdw {
return
*
graphics_system_
;
}
gdw
::
input
&
input
()
noexcept
{
return
*
input_
;
}
gdw
::
rendering_system
&
rendering_system
()
noexcept
{
return
*
rendering_system_
;
}
...
...
include/input/.gitkeep
deleted
100644 → 0
View file @
f746f63a
include/input/input.hpp
0 → 100644
View file @
bb8aa771
#include
<map>
#include
<SDL.h>
#include
<glm/glm.hpp>
#ifndef __INPUT_HPP__
#define __INPUT_HPP__
namespace
gdw
{
class
engine
;
class
input
{
public:
input
(
engine
&
engine
);
~
input
();
void
update
(
const
SDL_Event
&
event
);
bool
isKeyDown
(
SDL_Keycode
key
);
bool
isKeyPressed
(
SDL_Keycode
key
);
bool
isKeyReleased
(
SDL_Keycode
key
);
bool
isMouseButtonDown
(
int
button
);
bool
isMouseButtonPressed
(
int
button
);
bool
isMouseButtonReleased
(
int
button
);
glm
::
vec2
mouseWheel
()
noexcept
{
return
mousePos_
;};
int
mouseWheelX
()
noexcept
{
return
mouseWheel_
.
x
;};
int
mouseWheelY
()
noexcept
{
return
mouseWheel_
.
y
;};
glm
::
vec2
mousePos
()
noexcept
{
return
mousePos_
;};
int
mousePosX
()
noexcept
{
return
mousePos_
.
x
;};
int
mousePosY
()
noexcept
{
return
mousePos_
.
y
;};
private:
const
Uint8
*
keyState_
;
glm
::
vec2
mousePos_
;
glm
::
vec2
mouseWheel_
;
std
::
map
<
int
,
int
>
mouseMap_
;
std
::
map
<
int
,
int
>
mouseReleasedMap_
;
std
::
map
<
SDL_Keycode
,
int
>
keyMap_
;
std
::
map
<
SDL_Keycode
,
int
>
keyReleasedMap_
;
};
}
#endif
src/core/engine.cpp
View file @
bb8aa771
...
...
@@ -9,11 +9,14 @@
#include
<ecs/component.hpp>
#include
<ecs/entity.hpp>
#include
<graphics/graphics_system.hpp>
#include
<input/input.hpp>
#include
<rendering/rendering_system.hpp>
#include
<util/config.hpp>
#include
<util/logger.hpp>
#include
<util/make_unique.hpp>
#include
<iostream>
namespace
gdw
{
engine
::
engine
()
:
quit_
(
false
),
config_manager_
(
*
this
),
entity_manager_
(
*
this
)
{
...
...
@@ -26,6 +29,7 @@ namespace gdw {
}
audio_
=
make_unique
<
gdw
::
audio
>
(
*
this
);
graphics_system_
=
make_unique
<
gdw
::
graphics_system
>
(
*
this
);
input_
=
make_unique
<
gdw
::
input
>
(
*
this
);
rendering_system_
=
make_unique
<
gdw
::
rendering_system
>
(
*
this
);
}
...
...
@@ -57,6 +61,11 @@ namespace gdw {
current_time
=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
duration
<
float
>>
(
duration
).
count
();
delta_time
=
current_time
-
last_time
;
input_
->
update
(
event
);
if
(
input_
->
isKeyDown
(
SDLK_f
))
quit_
=
true
;
update
(
delta_time
);
entity_manager_
.
clean_up
();
}
...
...
src/input/.gitkeep
deleted
100644 → 0
View file @
f746f63a
src/input/input.cpp
0 → 100644
View file @
bb8aa771
#include
"input/input.hpp"
#include
<iostream>
namespace
gdw
{
input
::
input
(
engine
&
engine
)
:
/*engine_(engine),*/
mousePos_
(
0
,
0
),
mouseWheel_
(
0
,
0
){
keyState_
=
SDL_GetKeyboardState
(
0
);
}
input
::~
input
(){}
void
input
::
update
(
const
SDL_Event
&
event
){
keyReleasedMap_
.
clear
();
mouseReleasedMap_
.
clear
();
if
(
event
.
type
==
SDL_MOUSEMOTION
){
mousePos_
.
x
=
event
.
motion
.
x
;
mousePos_
.
y
=
event
.
motion
.
y
;
}
if
(
event
.
type
==
SDL_MOUSEWHEEL
){
mouseWheel_
.
x
=
event
.
wheel
.
x
;
mouseWheel_
.
y
=
event
.
wheel
.
y
;
}
if
(
event
.
type
==
SDL_MOUSEBUTTONDOWN
){
if
(
mouseMap_
[
event
.
button
.
button
]){
++
mouseMap_
[
event
.
button
.
button
];
}
else
{
mouseMap_
[
event
.
button
.
button
]
=
1
;
}
}
if
(
event
.
type
==
SDL_MOUSEBUTTONUP
){
mouseMap_
[
event
.
button
.
button
]
=
0
;
mouseReleasedMap_
[
event
.
button
.
button
]
=
1
;
}
if
(
event
.
type
==
SDL_KEYDOWN
){
if
(
keyMap_
[
event
.
key
.
keysym
.
sym
]){
++
keyMap_
[
event
.
key
.
keysym
.
sym
];
}
else
{
keyMap_
[
event
.
key
.
keysym
.
sym
]
=
1
;
}
}
if
(
event
.
type
==
SDL_KEYUP
){
keyMap_
[
event
.
key
.
keysym
.
sym
]
=
0
;
}
}
bool
input
::
isKeyDown
(
SDL_Keycode
key
){
std
::
cout
<<
"kd:"
<<
keyMap_
[
key
]
<<
std
::
endl
;
return
keyMap_
[
key
];
}
bool
input
::
isKeyPressed
(
SDL_Keycode
key
){
return
keyMap_
[
key
]
==
1
;
}
bool
input
::
isKeyReleased
(
SDL_Keycode
key
){
return
keyReleasedMap_
[
key
];
}
bool
input
::
isMouseButtonDown
(
int
button
){
return
mouseMap_
[
button
];
}
bool
input
::
isMouseButtonPressed
(
int
button
){
return
mouseMap_
[
button
]
==
1
;
}
bool
input
::
isMouseButtonReleased
(
int
button
){
return
mouseReleasedMap_
[
button
];
}
}
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