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
568cfa83
Commit
568cfa83
authored
2 years ago
by
Joseph Walton-Rivers
Browse files
Options
Downloads
Patches
Plain Diff
stronger bounds checks
parent
1cf8f72e
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
include/fggl/entity/gridworld/zone.hpp
+6
-1
6 additions, 1 deletion
include/fggl/entity/gridworld/zone.hpp
with
6 additions
and
1 deletion
include/fggl/entity/gridworld/zone.hpp
+
6
−
1
View file @
568cfa83
...
...
@@ -34,17 +34,22 @@ namespace fggl::entity::grid {
template
<
typename
T
,
uint32_t
width
,
uint32_t
height
>
struct
Grid
{
public:
constexpr
static
std
::
array
<
math
::
vec2i
,
4
>
DIRECTIONS
{{
{
-
1
,
0
},
{
0
,
-
1
},
{
1
,
0
},
{
0
,
1
}
}};
Grid
()
=
default
;
inline
T
&
get
(
GridPos
pos
)
{
assert
(
inBounds
(
pos
));
return
m_cells
[
getCellIndex
(
pos
)];
}
const
T
&
get
(
GridPos
pos
)
const
{
assert
(
inBounds
(
pos
));
return
m_cells
[
getCellIndex
(
pos
)];
}
inline
void
set
(
GridPos
pos
,
T
value
)
{
assert
(
inBounds
(
pos
));
m_cells
[
getCellIndex
(
pos
)]
=
value
;
}
...
...
@@ -57,7 +62,6 @@ namespace fggl::entity::grid {
constexpr
static
math
::
vec2i
size
=
math
::
vec2i
(
width
,
height
);
std
::
array
<
T
,
size
.
x
*
size
.
y
>
m_cells
;
inline
uint32_t
getCellIndex
(
GridPos
pos
)
const
{
assert
(
inBounds
(
pos
));
return
pos
.
y
*
size
.
x
+
pos
.
x
;
...
...
@@ -98,6 +102,7 @@ namespace fggl::entity::grid {
clear
();
}
[[
nodiscard
]]
inline
bool
inBounds
(
GridPos
pos
)
const
{
return
0
<=
pos
.
x
&&
pos
.
x
<=
width
&&
0
<=
pos
.
y
&&
pos
.
y
<=
height
;
...
...
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