Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
AIGT_ProceduralTerrain
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Buenen,F.W.M. (Felix)
AIGT_ProceduralTerrain
Commits
c264f2ba
Commit
c264f2ba
authored
4 years ago
by
Julian Thijssen
Browse files
Options
Downloads
Patches
Plain Diff
Abstract bounds-checking code
parent
00d66d3e
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
Assets/Scripts/CoastlineAgent.cs
+20
-27
20 additions, 27 deletions
Assets/Scripts/CoastlineAgent.cs
with
20 additions
and
27 deletions
Assets/Scripts/CoastlineAgent.cs
+
20
−
27
View file @
c264f2ba
...
...
@@ -81,8 +81,8 @@ public class CoastlineAgent
for
(
int
y
=
-
1
;
y
<=
1
;
y
++)
{
Vector2
currPos
=
new
Vector2
((
int
)
pos
.
x
+
x
,
(
int
)
pos
.
y
+
y
);
if
(
currPos
.
x
<
0
||
currPos
.
x
>=
coastlineGenerator
.
TerrainSize
)
continue
;
if
(
currPos
.
y
<
0
||
currPos
.
y
>=
coastlineGenerator
.
TerrainSize
)
continue
;
if
(
!
PositionInBounds
(
currPos
)
)
continue
;
int
currIndex
=
(
int
)(
currPos
.
x
+
currPos
.
y
*
coastlineGenerator
.
TerrainSize
);
if
(
coastlineGenerator
.
landBitField
[
currIndex
])
continue
;
...
...
@@ -102,16 +102,8 @@ public class CoastlineAgent
tokensRemaining
--;
return
true
;
}
//Debug.Log(assigned);
if
(
highestPos
.
x
<
0
||
highestPos
.
x
>=
coastlineGenerator
.
TerrainSize
)
{
Debug
.
Log
(
"whoops"
);
}
else
if
(
highestPos
.
y
<
0
||
highestPos
.
y
>=
coastlineGenerator
.
TerrainSize
)
{
Debug
.
Log
(
"whoops"
);
}
else
if
(
PositionInBounds
(
highestPos
))
{
coastlineGenerator
.
coastText
.
SetPixel
((
int
)
highestPos
.
x
,
(
int
)
highestPos
.
y
,
Color
.
grey
);
int
highestIndex
=
(
int
)
highestPos
.
x
+
(
int
)
highestPos
.
y
*
coastlineGenerator
.
TerrainSize
;
...
...
@@ -122,8 +114,8 @@ public class CoastlineAgent
if
(!
borderPart
.
Contains
(
highestPos
))
borderPart
.
Add
(
highestPos
);
coastlineGenerator
.
RemoveNonBoundaryPixels
(
highestPos
);
}
else
Debug
.
Log
(
"Whoops"
);
tokensRemaining
--;
return
true
;
}
...
...
@@ -138,6 +130,16 @@ public class CoastlineAgent
return
((
repulsor
-
pos
).
sqrMagnitude
*
1f
-
(
attractor
-
pos
).
sqrMagnitude
*
1f
)
+
3
*
mapDist
*
mapDist
;
}
private
bool
PositionInBounds
(
Vector2
pos
)
{
return
pos
.
x
>=
0
||
pos
.
y
>=
0
||
pos
.
x
<=
(
coastlineGenerator
.
TerrainSize
-
1
)
||
pos
.
y
<=
(
coastlineGenerator
.
TerrainSize
-
1
);
}
private
bool
PositionOnEdge
(
Vector2
pos
)
{
return
pos
.
x
==
0
||
pos
.
y
==
0
||
pos
.
x
==
(
coastlineGenerator
.
TerrainSize
-
1
)
||
pos
.
y
==
(
coastlineGenerator
.
TerrainSize
-
1
);
}
public
Vector2
GetRandomPosition
()
{
if
(
borderPart
.
Count
==
0
)
...
...
@@ -148,14 +150,7 @@ public class CoastlineAgent
int
randIndex
=
Random
.
Range
(
0
,
borderPart
.
Count
);
Vector2
pos
=
borderPart
[
randIndex
];
if
(
pos
.
x
==
0
||
pos
.
x
==
(
coastlineGenerator
.
TerrainSize
-
1
))
{
return
Vector2
.
zero
;
}
if
(
pos
.
y
==
0
||
pos
.
y
==
(
coastlineGenerator
.
TerrainSize
-
1
))
{
return
Vector2
.
zero
;
}
if
(
PositionOnEdge
(
pos
))
return
Vector2
.
zero
;
bool
inland
=
true
;
...
...
@@ -165,8 +160,7 @@ public class CoastlineAgent
{
if
(
x
==
0
&&
y
==
0
)
continue
;
if
((
pos
.
x
+
x
)
<
0
||
(
pos
.
x
+
x
)
>=
coastlineGenerator
.
TerrainSize
)
continue
;
if
((
pos
.
y
+
y
)
<
0
||
(
pos
.
y
+
y
)
>=
coastlineGenerator
.
TerrainSize
)
continue
;
if
(!
PositionInBounds
(
pos
+
new
Vector2
(
x
,
y
)))
continue
;
int
index
=
(
int
)((
pos
.
x
+
x
)
+
(
pos
.
y
+
y
)
*
coastlineGenerator
.
TerrainSize
);
if
(!
coastlineGenerator
.
landBitField
[
index
])
...
...
@@ -206,8 +200,7 @@ public class CoastlineAgent
{
Vector2
pos
=
new
Vector2
(-
1
,
-
1
);
if
(
startPos
.
x
==
0
||
startPos
.
x
==
(
coastlineGenerator
.
TerrainSize
-
1
))
return
pos
;
if
(
startPos
.
y
==
0
||
startPos
.
y
==
(
coastlineGenerator
.
TerrainSize
-
1
))
return
pos
;
if
(
PositionOnEdge
(
startPos
))
return
pos
;
Vector2
prevPos
=
pos
;
bool
foundCoastPoint
=
false
;
...
...
@@ -217,8 +210,8 @@ public class CoastlineAgent
do
{
Vector2Int
newPos
=
new
Vector2Int
((
int
)
(
oldPos
.
x
+
prefDirection
.
x
),
(
int
)
(
oldPos
.
y
+
prefDirection
.
y
));
if
(
newPos
.
x
<
0
||
newPos
.
x
>=
coastlineGenerator
.
TerrainSize
)
return
pos
;
if
(
newPos
.
y
<
0
||
newPos
.
y
>=
coastlineGenerator
.
TerrainSize
)
return
pos
;
if
(
!
PositionInBounds
(
pos
)
)
return
pos
;
int
idx
=
coastlineGenerator
.
TerrainSize
*
newPos
.
y
+
newPos
.
x
;
...
...
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