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
0394e315
Commit
0394e315
authored
2 years ago
by
Joseph Walton-Rivers
Browse files
Options
Downloads
Patches
Plain Diff
add neghbour calculation
parent
568cfa83
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
+33
-23
33 additions, 23 deletions
include/fggl/entity/gridworld/zone.hpp
with
33 additions
and
23 deletions
include/fggl/entity/gridworld/zone.hpp
+
33
−
23
View file @
0394e315
...
...
@@ -34,7 +34,6 @@ 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
;
...
...
@@ -98,6 +97,7 @@ namespace fggl::entity::grid {
template
<
uint32_t
width
,
uint32_t
height
>
struct
Area2D
{
public:
constexpr
static
std
::
array
<
math
::
vec2i
,
4
>
DIRECTIONS
{{
{
-
1
,
0
},
{
0
,
-
1
},
{
1
,
0
},
{
0
,
1
}
}};
inline
explicit
Area2D
(
TileSet
&
tiles
)
:
m_tiles
(
tiles
)
{
clear
();
}
...
...
@@ -155,33 +155,20 @@ namespace fggl::entity::grid {
return
canMove
(
pos
+
dir
)
&&
!
blocked
(
pos
,
dir
);
}
inline
bool
blocked
(
GridPos
pos
,
math
::
vec2i
dir
)
const
{
auto
targetPos
=
pos
;
if
(
dir
.
x
==
1
||
dir
.
y
==
1
)
{
targetPos
=
pos
+
dir
;
}
if
(
!
inBounds
(
targetPos
)
)
{
return
true
;
}
auto
&
wallObj
=
m_walls
.
get
(
targetPos
);
if
(
dir
.
y
!=
0
)
{
return
wallObj
.
north
!=
0
;
}
if
(
dir
.
x
!=
0
)
{
return
wallObj
.
west
!=
0
;
}
return
true
;
}
inline
bool
blocked
(
GridPos
pos
,
math
::
vec2i
dir
)
const
;
EntityManager
&
entities
()
{
return
m_entities
;
}
void
neighbours
(
math
::
vec2i
pos
,
std
::
vector
<
math
::
vec2i
>
&
neighbours
)
const
;
inline
void
neighbours
(
math
::
vec2i
pos
,
std
::
vector
<
math
::
vec2i
>
&
neighbours
)
const
{
for
(
auto
direction
:
DIRECTIONS
)
{
if
(
canMove
(
pos
,
direction
)
)
{
auto
result
=
pos
+
direction
;
neighbours
.
push_back
(
result
);
}
}
}
private
:
TileSet
&
m_tiles
;
Grid
<
uint32_t
,
width
,
height
>
m_floors
;
...
...
@@ -189,6 +176,29 @@ namespace fggl::entity::grid {
EntityManager
m_entities
;
};
template
<
uint32_t
width
,
uint32_t
height
>
bool
Area2D
<
width
,
height
>::
blocked
(
GridPos
pos
,
math
::
vec2i
dir
)
const
{
auto
targetPos
=
pos
;
if
(
dir
.
x
==
1
||
dir
.
y
==
1
)
{
targetPos
=
pos
+
dir
;
}
if
(
!
inBounds
(
targetPos
)
)
{
return
true
;
}
auto
&
wallObj
=
m_walls
.
get
(
targetPos
);
if
(
dir
.
y
!=
0
)
{
return
wallObj
.
north
!=
0
;
}
if
(
dir
.
x
!=
0
)
{
return
wallObj
.
west
!=
0
;
}
return
true
;
}
}
// namespace fggl::entity::gridworld
#endif //FGGL_ENTITY_GRIDWORLD_ZONE_HPP
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