Sector::~Sector()
{
using namespace Scripting;
-
+
deactivate();
for(ScriptList::iterator i = scripts.begin();
}
sq_release(global_vm, §or_table);
sq_collectgarbage(global_vm);
-
+
update_game_objects();
assert(gameobjects_new.size() == 0);
return partsys;
} else if(name == "money") { // for compatibility with old maps
return new Jumpy(reader);
- }
+ }
try {
return create_object(name, reader);
} catch(std::exception& e) {
log_warning << e.what() << "" << std::endl;
}
-
+
return 0;
}
void
Sector::parse(const lisp::Lisp& sector)
-{
+{
lisp::ListIterator iter(§or);
while(iter.next()) {
const std::string& token = iter.item();
bkgd_top.red = static_cast<float> (r) / 255.0f;
bkgd_top.green = static_cast<float> (g) / 255.0f;
bkgd_top.blue = static_cast<float> (b) / 255.0f;
-
+
reader.get("bkgd_red_bottom", r);
reader.get("bkgd_green_bottom", g);
reader.get("bkgd_blue_bottom", b);
bkgd_bottom.red = static_cast<float> (r) / 255.0f;
bkgd_bottom.green = static_cast<float> (g) / 255.0f;
bkgd_bottom.blue = static_cast<float> (b) / 255.0f;
-
+
if(backgroundimage != "") {
Background* background = new Background();
background->set_image(
int width = 30, height = 15;
reader.get("width", width);
reader.get("height", height);
-
+
std::vector<unsigned int> tiles;
if(reader.get_vector("interactive-tm", tiles)
|| reader.get_vector("tilemap", tiles)) {
i = scripts.erase(i);
continue;
}
-
+
++i;
}
-
+
HSQOBJECT object = create_thread(global_vm);
scripts.push_back(object);
sp = *i;
break;
}
- }
+ }
if(!sp) {
log_warning << "Spawnpoint '" << spawnpoint << "' not found." << std::endl;
if(spawnpoint != "main") {
if(SQ_FAILED(sq_deleteslot(vm, -2, SQFalse)))
throw Scripting::SquirrelError(vm, "Couldn't unset sector in roottable");
sq_pop(vm, 1);
-
+
for(GameObjects::iterator i = gameobjects.begin();
i != gameobjects.end(); ++i) {
GameObject* object = *i;
-
+
try_unexpose(object);
}
GameObject* object = *i;
if(!object->is_valid())
continue;
-
+
object->update(elapsed_time);
}
-
+
/* Handle all possible collisions. */
handle_collisions();
update_game_objects();
for(std::vector<GameObject*>::iterator i = gameobjects.begin();
i != gameobjects.end(); /* nothing */) {
GameObject* object = *i;
-
+
if(object->is_valid()) {
++i;
continue;
}
before_object_remove(object);
-
+
object->unref();
i = gameobjects.erase(i);
}
GameObject* object = *i;
before_object_add(object);
-
+
gameobjects.push_back(object);
}
gameobjects_new.clear();
if(movingobject) {
moving_objects.push_back(movingobject);
}
-
+
TileMap* tilemap = dynamic_cast<TileMap*> (object);
if(tilemap && tilemap->is_solid()) solid_tilemaps.push_back(tilemap);
if(_current == this) {
try_expose(object);
}
-
+
return true;
}
}
sq_settop(vm, oldtop);
}
-}
+}
void
Sector::draw(DrawingContext& context)
for(GameObjects::iterator i = gameobjects.begin();
i != gameobjects.end(); ++i) {
- GameObject* object = *i;
+ GameObject* object = *i;
if(!object->is_valid())
continue;
}
/*-------------------------------------------------------------------------
- * Collision Detection
+ * Collision Detection
*-------------------------------------------------------------------------*/
static const float SHIFT_DELTA = 7.0f;
Sector::collision_object(MovingObject* object1, MovingObject* object2) const
{
using namespace collision;
-
+
const Rect& r1 = object1->dest;
const Rect& r2 = object2->dest;
if(moving_object->get_group() != COLGROUP_STATIC
|| !moving_object->is_valid())
continue;
-
+
check_collisions(constraints, movement, dest, moving_object->dest,
&object, moving_object);
}
}
-void
+void
Sector::collision_static_constrains(MovingObject& object)
{
using namespace collision;
}
if(constraints.has_constraints()) {
- if( constraints.hit.left || constraints.hit.right
- || constraints.hit.top || constraints.hit.bottom
+ if( constraints.hit.left || constraints.hit.right
+ || constraints.hit.top || constraints.hit.bottom
|| constraints.hit.crush )
object.collision_solid(constraints.hit);
- }
+ }
// an extra pass to make sure we're not crushed horizontally
constraints = Constraints();
h.top = true;
h.bottom = true;
h.crush = true;
- object.collision_solid(h);
+ object.collision_solid(h);
}
}
}
Sector::handle_collisions()
{
using namespace collision;
-
+
// calculate destination positions of the objects
for(MovingObjects::iterator i = moving_objects.begin();
i != moving_objects.end(); ++i) {
moving_object->collision(*moving_object_2, hit);
moving_object_2->collision(*moving_object, hit);
}
- }
+ }
}
// part3: COLGROUP_MOVING vs COLGROUP_MOVING
continue;
collision_object(moving_object, moving_object_2);
- }
+ }
}
// apply object movement
Sector::is_free_space(const Rect& rect) const
{
using namespace collision;
-
+
for(std::list<TileMap*>::const_iterator i = solid_tilemaps.begin(); i != solid_tilemaps.end(); i++) {
TileMap* solids = *i;
return height;
}
-void
+void
Sector::change_solid_tiles(uint32_t old_tile_id, uint32_t new_tile_id)
{
for(std::list<TileMap*>::const_iterator i = solid_tilemaps.begin(); i != solid_tilemaps.end(); i++) {