Commit 41116634 authored by Alexey Hohlov's avatar Alexey Hohlov
Browse files

Убраны ненужные проверки на наличие в списке элементов.

parent 4d8de8f7
......@@ -45,55 +45,49 @@ void CMap::step_objects()
int32_t i, j;
int32_t cx, cy;
if (!particles.empty()) {
particles.remove_if( [](IObject2D* p) {
p->process();
return p->destroyed();
} );
}
particles.remove_if( [](IObject2D* p) {
p->process();
return p->destroyed();
} );
for (i = 0; i < cells_x; i++) {
for (j = 0; j < cells_y; j++) {
if (!cells[i][j].statics.empty()) {
cells[i][j].statics.remove_if( [](IObjectStatic* s) {
s->step();
return s->destroyed();
} );
}
cells[i][j].statics.remove_if( [](IObjectStatic* s) {
s->step();
return s->destroyed();
} );
}
}
if (!dynamics.empty()) {
for (IObjectDynamic* body : dynamics) {
body->process();
body->step();
for (IObjectDynamic* coll_body : dynamics) {
if (coll_body != body) {
if (DistanceBetweenPoints(body->pos(), coll_body->pos()) <= 256) {
if (body->checkCollide(coll_body)) {
body->collide(coll_body);
}
for (IObjectDynamic* body : dynamics) {
body->process();
body->step();
for (IObjectDynamic* coll_body : dynamics) {
if (coll_body != body) {
if (DistanceBetweenPoints(body->pos(), coll_body->pos()) <= 256) {
if (body->checkCollide(coll_body)) {
body->collide(coll_body);
}
}
}
}
cx = int32_t(body->pos().x + 64) / 128;
cy = int32_t(body->pos().y + 64) / 128;
cx = int32_t(body->pos().x + 64) / 128;
cy = int32_t(body->pos().y + 64) / 128;
for (i = max(0, cx - 1); i < min(cx + 2, (int32_t)cells_x); i++) {
for (j = max(0, cy - 1); j < min(cy + 2, (int32_t)cells_y); j++) {
for (IObjectStatic* coll_body_s : cells[i][j].statics) {
if (body->checkCollide(coll_body_s)) {
body->collide(coll_body_s);
}
for (i = max(0, cx - 1); i < min(cx + 2, (int32_t)cells_x); i++) {
for (j = max(0, cy - 1); j < min(cy + 2, (int32_t)cells_y); j++) {
for (IObjectStatic* coll_body_s : cells[i][j].statics) {
if (body->checkCollide(coll_body_s)) {
body->collide(coll_body_s);
}
}
}
}
dynamics.remove_if( [](IObjectDynamic* b) { return b->destroyed(); } );
}
dynamics.remove_if( [](IObjectDynamic* b) { return b->destroyed(); } );
}
void CMap::loadmap(string name)
......@@ -248,27 +242,22 @@ void CMap::DrawObjects()
i < min(int(ViewPos.x / 128 + ViewSize.w / 256) + 2, (int)cells_x); i++)
{
for (j = max(0, int(ViewPos.y / 128) - 4); j < min(int(ViewPos.y / 128) + 6, (int)cells_y); j++) {
if (!cells[i][j].statics.empty()) {
for (IObjectStatic* obj : cells[i][j].statics) {
if (!obj->draw()) {
render.draw(obj->sprite, obj->pos(), obj->size(), obj->angle());
}
for (IObjectStatic* obj : cells[i][j].statics) {
if (!obj->draw()) {
render.draw(obj->sprite, obj->pos(), obj->size(), obj->angle());
}
}
}
}
if (!dynamics.empty()) {
for (IObjectDynamic* obj : dynamics) {
if ((obj->pos().x - ViewSize.w / 2 - 128 <= ViewPos.x)
&& (obj->pos().x + ViewSize.w / 2 + 128 >= ViewPos.x)
&& (obj->pos().y - ViewSize.h / 2 - 128 <= ViewPos.y)
&& (obj->pos().y + ViewSize.h/2 + 128 >= ViewPos.y))
{
if (!obj->draw()) {
render.draw(obj->sprite, obj->pos(), obj->size(), obj->angle());
}
for (IObjectDynamic* obj : dynamics) {
if ((obj->pos().x - ViewSize.w / 2 - 128 <= ViewPos.x)
&& (obj->pos().x + ViewSize.w / 2 + 128 >= ViewPos.x)
&& (obj->pos().y - ViewSize.h / 2 - 128 <= ViewPos.y)
&& (obj->pos().y + ViewSize.h/2 + 128 >= ViewPos.y))
{
if (!obj->draw()) {
render.draw(obj->sprite, obj->pos(), obj->size(), obj->angle());
}
}
}
......@@ -445,12 +434,10 @@ CMap::~CMap()
for (i = 0; i < cells_x; i++) {
for (j = 0; j < cells_y; j++) {
if (!cells[i][j].statics.empty()) {
for (IObjectStatic* s : cells[i][j].statics) {
delete s;
}
cells[i][j].statics.clear();
for (IObjectStatic* s : cells[i][j].statics) {
delete s;
}
cells[i][j].statics.clear();
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment