Skip to content

Commit 3c623bc

Browse files
committed
preliminary resizing of AABBs of dynamic layers
1 parent f74f41c commit 3c623bc

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

examples/DrawMapWithDebug.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ it freely, subject to the following restrictions:
3535
int main()
3636
{
3737
sf::RenderWindow renderWindow(sf::VideoMode(800u, 600u), "TMX Loader");
38-
renderWindow.setVerticalSyncEnabled(true);
38+
//renderWindow.setVerticalSyncEnabled(true);
3939

4040
//create map loader and load map
4141
tmx::MapLoader ml("maps\\");
@@ -76,7 +76,7 @@ int main()
7676
{
7777
for(auto& o : l.objects)
7878
{
79-
o.Move(0.f, 1.f);
79+
o.Move(0.f, 60.f * frameClock.getElapsedTime().asSeconds());
8080
if(o.GetPosition().y > 600.f)
8181
{
8282
o.SetPosition(o.GetPosition().x, 0.f);

include/tmx/MapLayer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ namespace tmx
7676

7777
void draw(sf::RenderTarget& rt, sf::RenderStates states) const;
7878

79-
sf::FloatRect m_boundingBox;
79+
mutable sf::FloatRect m_boundingBox;
8080
void m_UpdateAABB(sf::Vector2f position, sf::Vector2f size);
8181
bool m_visible;
8282
};

src/MapLayer.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,43 @@ void LayerSet::Cull(const sf::FloatRect& bounds)
107107
//private
108108
void LayerSet::draw(sf::RenderTarget& rt, sf::RenderStates states) const
109109
{
110+
//std::vector<sf::Int32> dirtyPatches; //TODO prevent patches being duplicated
110111
for(const auto& q : m_dirtyQuads)
111112
{
112113
for(const auto& p : q->m_indices)
113114
{
114115
m_patches[q->m_patchIndex][p].position += q->m_movement;
115116
}
117+
//mark AABB as dirty if patch size has changed - TODO this doesn't shrink AABB :/
118+
//if(!m_boundingBox.contains(m_patches[q->m_patchIndex][0].position)
119+
// || !m_boundingBox.contains(m_patches[q->m_patchIndex][0].position))
120+
//{
121+
// //we only need to check first and 3rd - not all 4
122+
// dirtyPatches.push_back(q->m_patchIndex);
123+
//}
116124
}
117125
m_dirtyQuads.clear();
118126

127+
//for(auto p : dirtyPatches)
128+
//{
129+
// //update AABB
130+
// sf::Vector2f min, max;
131+
// const auto& verts = m_patches[p];
132+
// for(auto i = 0; i < verts.size(); i += 2) //only check extents
133+
// {
134+
// if(verts[i].position.x < min.x) min.x = verts[i].position.x;
135+
// else if(verts[i].position.x > max.x) max.x = verts[i].position.x;
136+
// if(verts[i].position.y < min.y) min.y = verts[i].position.y;
137+
// else if(verts[i].position.y > max.y) max.y = verts[i].position.y;
138+
// }
139+
140+
// //TODO this doesn't shrink the AABB!
141+
// if(m_boundingBox.left > min.x) m_boundingBox.left = min.x;
142+
// if(m_boundingBox.top > min.y) m_boundingBox.top = min.y;
143+
// if(std::fabs(m_boundingBox.left) + m_boundingBox.width < max.x) m_boundingBox.width = std::fabs(m_boundingBox.left) + max.x;
144+
// if(std::fabs(m_boundingBox.top) + m_boundingBox.height < max.y) m_boundingBox.width = std::fabs(m_boundingBox.top) + max.y;
145+
//}
146+
119147
if(!m_visible) return;
120148

121149
for(auto x = m_visiblePatchStart.x; x <= m_visiblePatchEnd.x; ++x)

0 commit comments

Comments
 (0)