|
@@ -28,21 +28,16 @@ void Dimension::tickEntities()
|
|
|
{
|
|
|
for( auto entity : *entities )
|
|
|
{
|
|
|
- if( zChunk( Punkt( (int)entity->getPosition().x, (int)entity->getPosition().y ) ) )
|
|
|
+ if( !entity->isRemoved() && zChunk( Punkt( (int)entity->getPosition().x, (int)entity->getPosition().y ) ) )
|
|
|
entity->prepareTick( this );
|
|
|
}
|
|
|
int index = 0;
|
|
|
- Array<int> removed;
|
|
|
for( auto entity : *entities )
|
|
|
{
|
|
|
- if( zChunk( Punkt( (int)entity->getPosition().x, (int)entity->getPosition().y ) ) )
|
|
|
+ if( !entity->isRemoved() && zChunk( Punkt( (int)entity->getPosition().x, (int)entity->getPosition().y ) ) )
|
|
|
entity->tick( this );
|
|
|
- if( entity->isRemoved() )
|
|
|
- removed.add( index, 0 );
|
|
|
index++;
|
|
|
}
|
|
|
- for( int i : removed )
|
|
|
- entities->remove( i );
|
|
|
}
|
|
|
|
|
|
void Dimension::getAddrOf( Punkt cPos, char* addr ) const
|
|
@@ -269,8 +264,43 @@ Entity* Dimension::zEntity( int id )
|
|
|
{
|
|
|
for( auto entity : *entities )
|
|
|
{
|
|
|
- if( entity->getId() == id )
|
|
|
+ if( !entity->isRemoved() && entity->getId() == id )
|
|
|
return entity;
|
|
|
}
|
|
|
return 0;
|
|
|
+}
|
|
|
+
|
|
|
+Entity* Dimension::zNearestEntity( Framework::Vec3<float> pos, std::function<bool( Entity* )> filter )
|
|
|
+{
|
|
|
+ Entity* result = 0;
|
|
|
+ float sqDist = 0;
|
|
|
+ for( auto entity : *entities )
|
|
|
+ {
|
|
|
+ if( !entity->isRemoved() && filter( entity ) )
|
|
|
+ {
|
|
|
+ float d = pos.abstandSq( entity->getPosition() );
|
|
|
+ if( !result || d < sqDist )
|
|
|
+ {
|
|
|
+ result = entity;
|
|
|
+ sqDist = d;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
+void Dimension::removeEntity( int id )
|
|
|
+{
|
|
|
+ Entity* result = 0;
|
|
|
+ float sqDist = 0;
|
|
|
+ int index = 0;
|
|
|
+ for( auto entity : *entities )
|
|
|
+ {
|
|
|
+ if( entity->getId() == id )
|
|
|
+ {
|
|
|
+ entities->remove( index );
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ index++;
|
|
|
+ }
|
|
|
}
|