Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Jochen Bauer
spn-website
Commits
840dd18c
Commit
840dd18c
authored
May 06, 2018
by
Hubert Denkmair
Browse files
optimize food visibility
parent
37bf75b6
Changes
3
Hide whitespace changes
Inline
Side-by-side
visualization/static/visualization/FoodSprite.js
View file @
840dd18c
...
...
@@ -20,10 +20,11 @@ FoodSprite.prototype.SetData = function(decay_rate, food_id, pos_x, pos_y, value
this
.
y
=
pos_y
;
this
.
tint
=
this
.
GetRandomTint
();
this
.
visible
=
true
;
this
.
UpdateSize
();
this
.
request_garbage_collect
=
false
;
this
.
UpdateScale
();
};
FoodSprite
.
prototype
.
UpdateS
iz
e
=
function
()
FoodSprite
.
prototype
.
UpdateS
cal
e
=
function
()
{
let
size
=
Math
.
sqrt
(
this
.
food_value
)
/
this
.
textureRadius
;
this
.
scale
.
x
=
size
;
...
...
@@ -36,11 +37,12 @@ FoodSprite.prototype.Decay = function(cycles)
{
if
(
!
cycles
)
{
cycles
=
1
;
}
this
.
food_value
-=
cycles
*
this
.
decay_rate
;
this
.
UpdateS
iz
e
();
this
.
UpdateS
cal
e
();
}
if
(
this
.
food_value
<
=
0
.05
)
if
(
this
.
food_value
<
0
)
{
this
.
visible
=
false
;
this
.
request_garbage_collect
=
true
;
}
};
...
...
visualization/static/visualization/GameVisualization.js
View file @
840dd18c
...
...
@@ -133,16 +133,14 @@ GameVisualization.prototype.HandleTickMessage = function(frame_id)
{
let
item
=
this
.
foodItems
[
food_id
];
item
.
Decay
(
nth
);
if
(
!
item
.
visible
)
if
(
item
.
request_garbage_collect
)
{
delete
this
.
foodItems
[
food_id
];
this
.
foodItemPool
.
free
(
item
);
}
}
this
.
foodMap
.
CleanUp
();
this
.
foodMap
.
GarbageCollect
();
}
this
.
UpdateStagePosition
();
};
GameVisualization
.
prototype
.
HandleWorldUpdateMessage
=
function
(
data
)
...
...
@@ -256,24 +254,22 @@ GameVisualization.prototype.FollowDbId = function(db_id)
GameVisualization
.
prototype
.
UpdateStagePosition
=
function
()
{
if
(
this
.
ego_id
in
this
.
snakes
)
if
(
(
++
this
.
updateVisibilityCounter
<
25
)
||
(
!
this
.
foodMap
)
)
{
/*let egoSnake = this.snakes[this.ego_id];
let egoX = egoSnake.GetHeadX();
let egoY = egoSnake.GetHeadY();
let transX = (this.app.renderer.width/2) - egoX;
let transY = (this.app.renderer.height/2) - egoY;
this.app.stage.setTransform(transX, transY);
if (this.foodMap)
{
this.foodMap.Update(egoX, egoY, this.app.renderer.width, this.app.renderer.height);
} */
}
else
{
this
.
app
.
stage
.
setTransform
(
0
,
0
);
if
(
this
.
foodMap
)
{
this
.
foodMap
.
Update
(
this
.
world_size_x
/
2
,
this
.
world_size_y
/
2
,
this
.
world_size_x
,
this
.
world_size_y
);
}
return
;
}
this
.
updateVisibilityCounter
=
0
;
const
center
=
this
.
viewport
.
center
;
const
width
=
this
.
viewport
.
right
-
this
.
viewport
.
left
;
const
height
=
this
.
viewport
.
bottom
-
this
.
viewport
.
top
;
this
.
foodMap
.
Update
(
center
.
x
,
center
.
y
,
width
,
height
);
const
minimumVisibleFoodSize
=
0.5
/
this
.
viewport
.
scale
.
x
;
console
.
log
(
minimumVisibleFoodSize
);
this
.
foodMap
.
Iterate
(
function
(
foodSprite
)
{
foodSprite
.
visible
=
foodSprite
.
food_value
>
minimumVisibleFoodSize
;
});
};
visualization/static/visualization/ParticleGeoMap.js
View file @
840dd18c
...
...
@@ -26,41 +26,19 @@ ParticleGeoMap.prototype.AddSprite = function(sprite)
this
.
_geoMap
[
key
].
addChild
(
sprite
);
};
ParticleGeoMap
.
prototype
.
RemoveItem
=
function
(
item_id
)
{
if
(
!
(
item_id
in
this
.
_itemIdKeyMap
))
{
return
;
}
let
key
=
this
.
_itemIdKeyMap
[
item_id
];
delete
this
.
_itemIdKeyMap
[
key
];
let
container
=
this
.
_geoMap
[
key
];
for
(
let
i
in
container
.
children
)
{
let
child
=
container
.
children
[
i
];
if
(
child
.
item_id
==
item_id
)
{
container
.
removeChild
(
child
);
return
child
;
}
}
};
ParticleGeoMap
.
prototype
.
CleanUp
=
function
()
ParticleGeoMap
.
prototype
.
GarbageCollect
=
function
()
{
for
(
let
container
of
this
.
_geoMap
)
{
this
.
RemoveInvisibleFrom
Container
(
container
);
this
.
GarbageCollect
Container
(
container
);
}
};
ParticleGeoMap
.
prototype
.
RemoveInvisibleFrom
Container
=
function
(
container
)
ParticleGeoMap
.
prototype
.
GarbageCollect
Container
=
function
(
container
)
{
for
(
let
child
of
container
.
children
)
{
if
(
!
child
.
visible
)
if
(
child
.
request_garbage_collect
)
{
let
key
=
this
.
_itemIdKeyMap
[
child
.
item_id
];
delete
this
.
_itemIdKeyMap
[
key
];
...
...
@@ -81,18 +59,6 @@ ParticleGeoMap.prototype.Iterate = function(callback)
}
};
ParticleGeoMap
.
prototype
.
IterateRow
=
function
(
row
,
callback
,
context
)
{
for
(
let
i
=
row
*
this
.
_numTilesX
;
i
<
(
row
+
1
)
*
this
.
_numTilesX
;
i
++
)
{
let
container
=
this
.
_geoMap
[
i
];
for
(
let
i
in
container
.
children
)
{
callback
.
call
(
context
,
container
.
children
[
i
]);
}
}
};
ParticleGeoMap
.
prototype
.
Update
=
function
(
x
,
y
,
width
,
height
)
{
if
(
(
this
.
_last
.
x
==
x
)
&&
(
this
.
_last
.
y
==
y
)
&&
(
this
.
_last
.
width
==
width
)
&&
(
this
.
_last
.
height
==
height
)
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment