projects
/
supertux.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
First step towards multiple tilesets per tilemap. Code is very inefficient for now...
[supertux.git]
/
src
/
sector.cpp
diff --git
a/src/sector.cpp
b/src/sector.cpp
index
5ced57b
..
c340ddb
100644
(file)
--- a/
src/sector.cpp
+++ b/
src/sector.cpp
@@
-177,6
+177,9
@@
Sector::parse_object(const std::string& name, const lisp::Lisp& reader)
void
Sector::parse(const lisp::Lisp& sector)
{
void
Sector::parse(const lisp::Lisp& sector)
{
+
+ TileMap::loading_worldmap = false;
+
bool has_background = false;
lisp::ListIterator iter(§or);
while(iter.next()) {
bool has_background = false;
lisp::ListIterator iter(§or);
while(iter.next()) {
@@
-236,6
+239,9
@@
Sector::parse(const lisp::Lisp& sector)
void
Sector::parse_old_format(const lisp::Lisp& reader)
{
void
Sector::parse_old_format(const lisp::Lisp& reader)
{
+
+ TileMap::loading_worldmap = false;
+
name = "main";
reader.get("gravity", gravity);
name = "main";
reader.get("gravity", gravity);
@@
-889,11
+895,18
@@
void check_collisions(collision::Constraints* constraints,
if(!collision::intersects(r1, r2))
return;
if(!collision::intersects(r1, r2))
return;
+ MovingObject *moving_object = dynamic_cast<MovingObject*> (object);
+ CollisionHit dummy;
+ if(other != NULL && !other->collides(*object, dummy))
+ return;
+ if(moving_object != NULL && !moving_object->collides(*other, dummy))
+ return;
+
// calculate intersection
// calculate intersection
- float itop = r1.get_bottom() - r2.get_top();
+ float itop
= r1.get_bottom() - r2.get_top();
float ibottom = r2.get_bottom() - r1.get_top();
float ibottom = r2.get_bottom() - r1.get_top();
- float ileft = r1.get_right() - r2.get_left();
- float iright = r2.get_right() - r1.get_left();
+ float ileft
= r1.get_right() - r2.get_left();
+ float iright
= r2.get_right() - r1.get_left();
if(fabsf(movement.y) > fabsf(movement.x)) {
if(ileft < SHIFT_DELTA) {
if(fabsf(movement.y) > fabsf(movement.x)) {
if(ileft < SHIFT_DELTA) {
@@
-915,10
+928,10
@@
void check_collisions(collision::Constraints* constraints,
}
if(other != NULL) {
}
if(other != NULL) {
- CollisionHit dummy;
HitResponse response = other->collision(*object, dummy);
if(response == PASSTHROUGH)
return;
HitResponse response = other->collision(*object, dummy);
if(response == PASSTHROUGH)
return;
+
if(other->get_movement() != Vector(0, 0)) {
// TODO what todo when we collide with 2 moving objects?!?
constraints->ground_movement = other->get_movement();
if(other->get_movement() != Vector(0, 0)) {
// TODO what todo when we collide with 2 moving objects?!?
constraints->ground_movement = other->get_movement();
@@
-1072,12
+1085,19
@@
Sector::collision_object(MovingObject* object1, MovingObject* object2) const
Vector normal;
get_hit_normal(r1, r2, hit, normal);
Vector normal;
get_hit_normal(r1, r2, hit, normal);
+ if(!object1->collides(*object2, hit))
+ return;
+ std::swap(hit.left, hit.right);
+ std::swap(hit.top, hit.bottom);
+ if(!object2->collides(*object1, hit))
+ return;
+ std::swap(hit.left, hit.right);
+ std::swap(hit.top, hit.bottom);
+
HitResponse response1 = object1->collision(*object2, hit);
std::swap(hit.left, hit.right);
std::swap(hit.top, hit.bottom);
HitResponse response2 = object2->collision(*object1, hit);
HitResponse response1 = object1->collision(*object2, hit);
std::swap(hit.left, hit.right);
std::swap(hit.top, hit.bottom);
HitResponse response2 = object2->collision(*object1, hit);
- assert( response1 != SOLID && response1 != PASSTHROUGH );
- assert( response2 != SOLID && response2 != PASSTHROUGH );
if(response1 == CONTINUE && response2 == CONTINUE) {
normal *= (0.5 + DELTA);
object1->dest.move(-normal);
if(response1 == CONTINUE && response2 == CONTINUE) {
normal *= (0.5 + DELTA);
object1->dest.move(-normal);
@@
-1168,8
+1188,10
@@
Sector::collision_static_constrains(MovingObject& object)
if(constraints.right < infinity) {
float width = constraints.right - constraints.left;
if(width + SHIFT_DELTA < owidth) {
if(constraints.right < infinity) {
float width = constraints.right - constraints.left;
if(width + SHIFT_DELTA < owidth) {
+#if 0
printf("Object %p crushed horizontally... L:%f R:%f\n", &object,
constraints.left, constraints.right);
printf("Object %p crushed horizontally... L:%f R:%f\n", &object,
constraints.left, constraints.right);
+#endif
CollisionHit h;
h.left = true;
h.right = true;
CollisionHit h;
h.left = true;
h.right = true;
@@
-1198,7
+1220,9
@@
Sector::collision_static_constrains(MovingObject& object)
if(constraints.bottom < infinity) {
float height = constraints.bottom - constraints.top;
if(height + SHIFT_DELTA < oheight) {
if(constraints.bottom < infinity) {
float height = constraints.bottom - constraints.top;
if(height + SHIFT_DELTA < oheight) {
+#if 0
printf("Object %p crushed vertically...\n", &object);
printf("Object %p crushed vertically...\n", &object);
+#endif
CollisionHit h;
h.top = true;
h.bottom = true;
CollisionHit h;
h.top = true;
h.bottom = true;
@@
-1284,6
+1308,11
@@
Sector::handle_collisions()
CollisionHit hit;
get_hit_normal(moving_object->dest, moving_object_2->dest,
hit, normal);
CollisionHit hit;
get_hit_normal(moving_object->dest, moving_object_2->dest,
hit, normal);
+ if(!moving_object->collides(*moving_object_2, hit))
+ continue;
+ if(!moving_object_2->collides(*moving_object, hit))
+ continue;
+
moving_object->collision(*moving_object_2, hit);
moving_object_2->collision(*moving_object, hit);
}
moving_object->collision(*moving_object_2, hit);
moving_object_2->collision(*moving_object, hit);
}
@@
-1472,7
+1501,9
@@
Sector::inside(const Rect& rect) const
TileMap* solids = *i;
bool horizontally = ((rect.p2.x >= 0 + solids->get_x_offset()) && (rect.p1.x <= solids->get_width() * 32 + solids->get_x_offset()));
bool vertically = (rect.p1.y <= solids->get_height() * 32 + solids->get_y_offset());
TileMap* solids = *i;
bool horizontally = ((rect.p2.x >= 0 + solids->get_x_offset()) && (rect.p1.x <= solids->get_width() * 32 + solids->get_x_offset()));
bool vertically = (rect.p1.y <= solids->get_height() * 32 + solids->get_y_offset());
- if (horizontally && vertically) return true;
+
+ if (horizontally && vertically)
+ return true;
}
return false;
}
}
return false;
}
@@
-1481,10
+1512,14
@@
float
Sector::get_width() const
{
float width = 0;
Sector::get_width() const
{
float width = 0;
- for(std::list<TileMap*>::const_iterator i = solid_tilemaps.begin(); i != solid_tilemaps.end(); i++) {
+ for(std::list<TileMap*>::const_iterator i = solid_tilemaps.begin();
+ i != solid_tilemaps.end(); i++) {
TileMap* solids = *i;
TileMap* solids = *i;
- if ((solids->get_width() * 32 + solids->get_x_offset()) > width) width = (solids->get_width() * 32 + solids->get_x_offset());
+ if ((solids->get_width() * 32 + solids->get_x_offset()) > width) {
+ width = solids->get_width() * 32 + solids->get_x_offset();
+ }
}
}
+
return width;
}
return width;
}
@@
-1492,10
+1527,14
@@
float
Sector::get_height() const
{
float height = 0;
Sector::get_height() const
{
float height = 0;
- for(std::list<TileMap*>::const_iterator i = solid_tilemaps.begin(); i != solid_tilemaps.end(); i++) {
+ for(std::list<TileMap*>::const_iterator i = solid_tilemaps.begin();
+ i != solid_tilemaps.end(); i++) {
TileMap* solids = *i;
TileMap* solids = *i;
- if ((solids->get_height() * 32 + solids->get_y_offset()) > height) height = (solids->get_height() * 32 + solids->get_y_offset());
+ if ((solids->get_height() * 32 + solids->get_y_offset()) > height) {
+ height = solids->get_height() * 32 + solids->get_y_offset();
+ }
}
}
+
return height;
}
return height;
}