Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
Game Library
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Game Development
Game Library
Commits
8b0537d6
Commit
8b0537d6
authored
3 years ago
by
Joseph Walton-Rivers
Browse files
Options
Downloads
Patches
Plain Diff
add controller name support
parent
5792db23
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#3040
failed
3 years ago
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
demo/main.cpp
+1
-1
1 addition, 1 deletion
demo/main.cpp
fggl/gfx/window.cpp
+2
-1
2 additions, 1 deletion
fggl/gfx/window.cpp
fggl/input/gamepad.hpp
+14
-0
14 additions, 0 deletions
fggl/input/gamepad.hpp
with
17 additions
and
2 deletions
demo/main.cpp
+
1
−
1
View file @
8b0537d6
...
...
@@ -292,7 +292,7 @@ int main(int argc, char* argv[]) {
auto
&
gamepads
=
inputs
->
gamepads
;
ImGui
::
Begin
(
"GamePad"
,
&
gamepadWindow
);
for
(
int
i
=
0
;
i
<
16
;
i
++
)
{
std
::
string
title
=
"G
ame
P
ad
"
+
std
::
to_string
(
i
);
std
::
string
title
=
g
ame
p
ad
s
.
name
(
i
);
bool
present
=
gamepads
.
present
(
i
);
if
(
ImGui
::
TreeNode
(
title
.
c_str
())
)
{
...
...
This diff is collapsed.
Click to expand it.
fggl/gfx/window.cpp
+
2
−
1
View file @
8b0537d6
...
...
@@ -49,12 +49,13 @@ static void fggl_input_keyboard(GLFWwindow* window, int key, int scancode, int a
}
static
void
fggl_update_joystick
(
fggl
::
input
::
GamepadInput
&
input
,
int
jid
)
{
//glfwGetJoystickName(jid);
bool
isGamepad
=
glfwJoystickIsGamepad
(
jid
);
if
(
isGamepad
)
{
if
(
!
input
.
present
(
jid
)
)
{
std
::
string
name
=
glfwGetJoystickName
(
jid
);
input
.
setActive
(
jid
,
true
);
input
.
name
(
jid
,
name
);
}
GLFWgamepadstate
state
;
...
...
This diff is collapsed.
Click to expand it.
fggl/input/gamepad.hpp
+
14
−
0
View file @
8b0537d6
...
...
@@ -108,6 +108,19 @@ namespace fggl::input {
return
m_active
[
id
];
}
inline
void
name
(
size_t
id
,
const
std
::
string
&
name
)
{
assert
(
id
<
MaxControllers
);
m_names
[
id
]
=
name
;
}
inline
std
::
string
name
(
size_t
id
)
const
{
std
::
string
name
=
m_names
[
id
].
empty
()
?
"gamepad "
+
std
::
to_string
(
id
)
:
m_names
[
id
];
if
(
!
present
(
id
)
)
{
return
name
+
" (disconnected)"
;
}
return
name
;
}
inline
float
axis
(
size_t
id
,
GamepadAxis
axis
)
const
{
if
(
!
present
(
id
)
)
{
return
0.0
f
;
...
...
@@ -166,6 +179,7 @@ namespace fggl::input {
private
:
std
::
bitset
<
MaxControllers
>
m_active
;
std
::
array
<
std
::
string
,
MaxControllers
>
m_names
;
std
::
array
<
GamepadState
,
MaxControllers
>
m_current
;
std
::
array
<
GamepadState
,
MaxControllers
>
m_previous
;
};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment