X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fsector.cpp;h=e155abd04b48c5c25bd403b8d66fe21e2f9aecdd;hb=ab9eab4c870195c2b60ce76b77044c35b31e8806;hp=20ed7fc0b77995db664ec208a93a9f3872e0dacc;hpb=8a627e73d824b5a14249cfe066dc2fdc643ce28d;p=supertux.git diff --git a/src/sector.cpp b/src/sector.cpp index 20ed7fc0b..e155abd04 100644 --- a/src/sector.cpp +++ b/src/sector.cpp @@ -56,6 +56,7 @@ #include "object/invisible_block.hpp" #include "object/bullet.hpp" #include "object/text_object.hpp" +#include "object/portable.hpp" #include "badguy/jumpy.hpp" #include "trigger/sequence_trigger.hpp" #include "player_status.hpp" @@ -69,8 +70,8 @@ bool Sector::show_collrects = false; bool Sector::draw_solids_only = false; Sector::Sector(Level* parent) - : level(parent), currentmusic(LEVEL_MUSIC), gravity(10), - player(0), camera(0) + : level(parent), currentmusic(LEVEL_MUSIC), + ambient_light( 1.0f, 1.0f, 1.0f, 1.0f ), gravity(10), player(0), camera(0) { add_object(new Player(player_status, "Tux")); add_object(new DisplayEffect("Effect")); @@ -185,6 +186,10 @@ Sector::parse(const lisp::Lisp& sector) spawnpoints.push_back(sp); } else if(token == "init-script") { iter.value()->get(init_script); + } else if(token == "ambient-light") { + std::vector vColor; + sector.get_vector( "ambient-light", vColor ); + ambient_light = Color( vColor ); } else { GameObject* object = parse_object(token, *(iter.lisp())); if(object) { @@ -341,7 +346,6 @@ Sector::parse_old_format(const lisp::Lisp& reader) void Sector::fix_old_tiles() { - // hack for now... for(std::list::iterator i = solid_tilemaps.begin(); i != solid_tilemaps.end(); i++) { TileMap* solids = *i; for(size_t x=0; x < solids->get_width(); ++x) { @@ -570,26 +574,6 @@ void Sector::update_game_objects() { /** cleanup marked objects */ - for(std::vector::iterator i = bullets.begin(); - i != bullets.end(); /* nothing */) { - Bullet* bullet = *i; - if(bullet->is_valid()) { - ++i; - continue; - } - - i = bullets.erase(i); - } - for(MovingObjects::iterator i = moving_objects.begin(); - i != moving_objects.end(); /* nothing */) { - MovingObject* moving_object = *i; - if(moving_object->is_valid()) { - ++i; - continue; - } - - i = moving_objects.erase(i); - } for(std::vector::iterator i = gameobjects.begin(); i != gameobjects.end(); /* nothing */) { GameObject* object = *i; @@ -622,19 +606,27 @@ bool Sector::before_object_add(GameObject* object) { Bullet* bullet = dynamic_cast (object); - if(bullet) + if(bullet != NULL) { bullets.push_back(bullet); + } MovingObject* movingobject = dynamic_cast (object); - if(movingobject) { + if(movingobject != NULL) { moving_objects.push_back(movingobject); } + Portable* portable = dynamic_cast (object); + if(portable != NULL) { + portables.push_back(portable); + } + TileMap* tilemap = dynamic_cast (object); - if(tilemap && tilemap->is_solid()) solid_tilemaps.push_back(tilemap); + if(tilemap != NULL && tilemap->is_solid()) { + solid_tilemaps.push_back(tilemap); + } Camera* camera = dynamic_cast (object); - if(camera) { + if(camera != NULL) { if(this->camera != 0) { log_warning << "Multiple cameras added. Ignoring" << std::endl; return false; @@ -643,7 +635,7 @@ Sector::before_object_add(GameObject* object) } Player* player = dynamic_cast (object); - if(player) { + if(player != NULL) { if(this->player != 0) { log_warning << "Multiple players added. Ignoring" << std::endl; return false; @@ -673,6 +665,20 @@ Sector::try_expose(GameObject* object) void Sector::before_object_remove(GameObject* object) { + Portable* portable = dynamic_cast (object); + if(portable != NULL) { + portables.erase(std::find(portables.begin(), portables.end(), portable)); + } + Bullet* bullet = dynamic_cast (object); + if(bullet != NULL) { + bullets.erase(std::find(bullets.begin(), bullets.end(), bullet)); + } + MovingObject* moving_object = dynamic_cast (object); + if(moving_object != NULL) { + moving_objects.erase( + std::find(moving_objects.begin(), moving_objects.end(), moving_object)); + } + if(_current == this) try_unexpose(object); } @@ -697,6 +703,7 @@ Sector::try_unexpose(GameObject* object) void Sector::draw(DrawingContext& context) { + context.set_ambient_color( ambient_light ); context.push_transform(); context.set_translation(camera->get_translation()); @@ -959,11 +966,14 @@ Sector::collision_static(collision::Constraints* constraints, i != moving_objects.end(); ++i) { MovingObject* moving_object = *i; if(moving_object->get_group() != COLGROUP_STATIC - || !moving_object->is_valid()) + && moving_object->get_group() != COLGROUP_MOVING_STATIC) + continue; + if(!moving_object->is_valid()) continue; - check_collisions(constraints, movement, dest, moving_object->dest, - &object, moving_object); + if(moving_object != &object) + check_collisions(constraints, movement, dest, moving_object->bbox, + &object, moving_object); } } @@ -1078,6 +1088,7 @@ Sector::handle_collisions() i != moving_objects.end(); ++i) { MovingObject* moving_object = *i; if((moving_object->get_group() != COLGROUP_MOVING + && moving_object->get_group() != COLGROUP_MOVING_STATIC && moving_object->get_group() != COLGROUP_MOVING_ONLY_STATIC) || !moving_object->is_valid()) continue; @@ -1091,6 +1102,7 @@ Sector::handle_collisions() i != moving_objects.end(); ++i) { MovingObject* moving_object = *i; if((moving_object->get_group() != COLGROUP_MOVING + && moving_object->get_group() != COLGROUP_MOVING_STATIC && moving_object->get_group() != COLGROUP_MOVING_ONLY_STATIC) || !moving_object->is_valid()) continue; @@ -1105,7 +1117,8 @@ Sector::handle_collisions() for(MovingObjects::iterator i = moving_objects.begin(); i != moving_objects.end(); ++i) { MovingObject* moving_object = *i; - if(moving_object->get_group() != COLGROUP_MOVING + if((moving_object->get_group() != COLGROUP_MOVING + && moving_object->get_group() != COLGROUP_MOVING_STATIC) || !moving_object->is_valid()) continue; @@ -1132,14 +1145,16 @@ Sector::handle_collisions() i != moving_objects.end(); ++i) { MovingObject* moving_object = *i; - if(moving_object->get_group() != COLGROUP_MOVING + if((moving_object->get_group() != COLGROUP_MOVING + && moving_object->get_group() != COLGROUP_MOVING_STATIC) || !moving_object->is_valid()) continue; for(MovingObjects::iterator i2 = i+1; i2 != moving_objects.end(); ++i2) { MovingObject* moving_object_2 = *i2; - if(moving_object_2->get_group() != COLGROUP_MOVING + if((moving_object_2->get_group() != COLGROUP_MOVING + && moving_object_2->get_group() != COLGROUP_MOVING_STATIC) || !moving_object_2->is_valid()) continue;