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
Onuralp SEZER
Game Library
Commits
464dcba7
Commit
464dcba7
authored
2 years ago
by
Joseph Walton-Rivers
Browse files
Options
Downloads
Patches
Plain Diff
handle non-existant states more gracefully
parent
9b916e92
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
fggl/app.cpp
+4
-1
4 additions, 1 deletion
fggl/app.cpp
fggl/scenes/game.cpp
+1
-1
1 addition, 1 deletion
fggl/scenes/game.cpp
include/fggl/util/states.hpp
+6
-2
6 additions, 2 deletions
include/fggl/util/states.hpp
with
11 additions
and
4 deletions
fggl/app.cpp
+
4
−
1
View file @
464dcba7
...
...
@@ -46,7 +46,10 @@ namespace fggl {
while
(
m_running
)
{
// trigger a state change if expected
if
(
m_expectedScene
!=
m_states
.
activeID
()
)
{
m_states
.
change
(
m_expectedScene
);
auto
result
=
m_states
.
change
(
m_expectedScene
);
if
(
!
result
)
{
m_expectedScene
=
m_states
.
activeID
();
}
}
auto
&
state
=
m_states
.
active
();
...
...
This diff is collapsed.
Click to expand it.
fggl/scenes/game.cpp
+
1
−
1
View file @
464dcba7
...
...
@@ -43,7 +43,7 @@ namespace fggl::scenes {
}
void
Game
::
update
()
{
assert
(
m_world
);
assert
(
m_world
&&
"called game update, but there was no world - was activate called?"
);
if
(
m_input
!=
nullptr
)
{
bool
escapePressed
=
m_input
->
keyboard
.
pressed
(
glfwGetKeyScancode
(
GLFW_KEY_ESCAPE
));
...
...
This diff is collapsed.
Click to expand it.
include/fggl/util/states.hpp
+
6
−
2
View file @
464dcba7
...
...
@@ -48,12 +48,16 @@ namespace fggl::util {
return
(
T
*
)
(
m_states
[
name
].
get
());
}
void
change
(
const
Identifer
&
name
)
{
assertm
(
m_states
.
find
(
name
)
!=
m_states
.
end
(),
"state does not exist"
);
bool
change
(
const
Identifer
&
name
)
{
if
(
m_states
.
find
(
name
)
==
m_states
.
end
()
)
{
debug
::
error
(
"attempted to change to non-existent state {}, ignoring you."
,
name
);
return
false
;
}
active
().
deactivate
();
m_active
=
name
;
active
().
activate
();
return
true
;
}
StateType
&
active
()
const
{
...
...
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