[Super-tux-commit] supertux/src gameloop.cpp,1.203,1.204 level.cpp,1.110,1.111 level.h,1.68,1.69 lev
Brought to you by:
wkendrick
Update of /cvsroot/super-tux/supertux/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31955/src Modified Files: gameloop.cpp level.cpp level.h leveleditor.cpp leveleditor.h misc.h resources.cpp sector.cpp sector.h supertux.cpp title.cpp Removed Files: background.cpp background.h camera.cpp camera.h gameobjs.cpp gameobjs.h particlesystem.cpp particlesystem.h player.cpp player.h tilemap.cpp tilemap.h Log Message: some cleanups memory leak fixes and moving of source files --- tilemap.cpp DELETED --- --- background.h DELETED --- Index: leveleditor.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/leveleditor.cpp,v retrieving revision 1.170 retrieving revision 1.171 diff -u -d -r1.170 -r1.171 --- leveleditor.cpp 23 Nov 2004 22:21:51 -0000 1.170 +++ leveleditor.cpp 26 Nov 2004 14:45:32 -0000 1.171 @@ -31,13 +31,13 @@ #include "leveleditor.h" #include "resources.h" #include "tile.h" -#include "tilemap.h" #include "tile_manager.h" #include "sector.h" -#include "background.h" #include "gameloop.h" -#include "gameobjs.h" -#include "camera.h" +#include "object/gameobjs.h" +#include "object/camera.h" +#include "object/tilemap.h" +#include "object/background.h" LevelEditor::LevelEditor() { @@ -288,7 +288,9 @@ level_subset->description = create_subset_menu->get_item_by_id(MN_ID_DESCRIPTION_SUBSET).input; //FIXME: generate better level filenames level_subset->add_level(subset_name+'/'+"new_level.stl"); - Level::create(level_subset->get_level_filename(0)); + Level* newlevel = new Level(); + newlevel->add_sector(create_sector("main", 25, 19)); + newlevel->save(level_subset->get_level_filename(0)); level_subset->save(); load_level(0); @@ -368,7 +370,9 @@ if(confirm_dialog(NULL, str)) { level_subset->add_level("new_level.stl"); - Level::create(level_subset->get_level_filename(level_nb + 1)); + Level* newlevel = new Level(); + newlevel->add_sector(create_sector("main", 25, 19)); + newlevel->save(level_subset->get_level_filename(level_nb + 1)); level_subset->save(); load_level(level_nb + 1); } @@ -780,7 +784,7 @@ { if(!confirm_dialog(NULL, _("No more sectors exist. Create another?"))) return; - sector_ = Sector::create("new_sector",25,19); + sector_ = create_sector("new_sector",25,19); level->add_sector(sector_); } @@ -1033,3 +1037,19 @@ show_grid = show_grid_t; mouse_cursor->set_state(MC_NORMAL); } + +Sector* +LevelEditor::create_sector(const std::string& name, size_t width, size_t height) +{ + Sector* sector = new Sector; + sector->set_name(name); + + sector->add_object(new TileMap(LAYER_BACKGROUNDTILES, false, width, height)); + sector->add_object(new TileMap(LAYER_TILES, true, width, height)); + sector->add_object(new TileMap(LAYER_FOREGROUNDTILES, false, width, height)); + sector->add_object(new Camera(sector)); + sector->update_game_objects(); + + return sector; +} + Index: misc.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/misc.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- misc.h 20 Nov 2004 22:14:38 -0000 1.3 +++ misc.h 26 Nov 2004 14:45:40 -0000 1.4 @@ -19,14 +19,14 @@ #define SUPERTUX_MISC_H #include "app/setup.h" -#include "resources.h" +#include "app/gettext.h" #include "gui/menu.h" #include "utils/configfile.h" -#include "player.h" #include "title.h" +#include "resources.h" #include "worldmap.h" #include "gameloop.h" -#include "app/gettext.h" +#include "object/player.h" class MyConfig : public Config { Index: gameloop.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/gameloop.cpp,v retrieving revision 1.203 retrieving revision 1.204 diff -u -d -r1.203 -r1.204 --- gameloop.cpp 26 Nov 2004 13:56:31 -0000 1.203 +++ gameloop.cpp 26 Nov 2004 14:45:32 -0000 1.204 @@ -47,19 +47,19 @@ #include "high_scores.h" #include "gui/menu.h" #include "sector.h" -#include "player.h" #include "level.h" #include "scene.h" #include "tile.h" -#include "particlesystem.h" +#include "object/particlesystem.h" +#include "object/background.h" +#include "object/tilemap.h" +#include "object/camera.h" +#include "object/player.h" #include "resources.h" -#include "background.h" -#include "tilemap.h" #include "app/gettext.h" #include "worldmap.h" #include "intro.h" #include "misc.h" -#include "camera.h" #include "statistics.h" #include "timer.h" #include "object/fireworks.h" Index: sector.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/sector.h,v retrieving revision 1.25 retrieving revision 1.26 diff -u -d -r1.25 -r1.26 --- sector.h 25 Nov 2004 00:49:34 -0000 1.25 +++ sector.h 26 Nov 2004 14:45:41 -0000 1.26 @@ -67,8 +67,6 @@ Sector(); ~Sector(); - /// create new sector - static Sector *create(const std::string& name, size_t width, size_t height); /// read sector from lisp file void parse(LispReader& reader); void parse_old_format(LispReader& reader); @@ -88,6 +86,8 @@ /// adds a gameobject void add_object(GameObject* object); + void set_name(const std::string& name) + { this->name = name; } const std::string& get_name() const { return name; } @@ -102,16 +102,10 @@ case (or not). */ void collision_handler(); - void add_score(const Vector& pos, int s); - bool add_bullet(const Vector& pos, float xm, Direction dir); bool add_smoke_cloud(const Vector& pos); void add_floating_text(const Vector& pos, const std::string& text); - /** Flip the all the sector vertically. The purpose of this is to let - player to play the same level in a different way :) */ - void do_vertical_flip(); - /** @evil@ but can#t always be avoided in current design... */ static Sector* current() { return _current; } --- gameobjs.cpp DELETED --- --- camera.cpp DELETED --- Index: title.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/title.cpp,v retrieving revision 1.133 retrieving revision 1.134 diff -u -d -r1.133 -r1.134 --- title.cpp 25 Nov 2004 19:48:36 -0000 1.133 +++ title.cpp 26 Nov 2004 14:45:41 -0000 1.134 @@ -52,14 +52,14 @@ #include "worldmap.h" #include "leveleditor.h" #include "scene.h" -#include "player.h" #include "tile.h" #include "sector.h" -#include "tilemap.h" +#include "object/tilemap.h" +#include "object/camera.h" +#include "object/player.h" #include "resources.h" #include "app/gettext.h" #include "misc.h" -#include "camera.h" static Surface* bkg_title; static Surface* logo; Index: resources.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/resources.cpp,v retrieving revision 1.58 retrieving revision 1.59 diff -u -d -r1.58 -r1.59 --- resources.cpp 25 Nov 2004 19:48:26 -0000 1.58 +++ resources.cpp 26 Nov 2004 14:45:41 -0000 1.59 @@ -25,9 +25,9 @@ #include "gui/menu.h" #include "gui/button.h" #include "scene.h" -#include "player.h" -#include "gameobjs.h" #include "resources.h" +#include "object/gameobjs.h" +#include "object/player.h" Surface* img_waves[3]; Surface* img_water; --- player.h DELETED --- Index: sector.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/sector.cpp,v retrieving revision 1.50 retrieving revision 1.51 diff -u -d -r1.50 -r1.51 --- sector.cpp 26 Nov 2004 13:56:31 -0000 1.50 +++ sector.cpp 26 Nov 2004 14:45:41 -0000 1.51 @@ -29,12 +29,12 @@ #include "app/globals.h" #include "sector.h" #include "utils/lispreader.h" -#include "gameobjs.h" -#include "camera.h" -#include "background.h" -#include "particlesystem.h" +#include "object/gameobjs.h" +#include "object/camera.h" +#include "object/background.h" +#include "object/particlesystem.h" +#include "object/tilemap.h" #include "tile.h" -#include "tilemap.h" #include "audio/sound_manager.h" #include "gameloop.h" #include "resources.h" @@ -69,13 +69,13 @@ song_title = "Mortimers_chipdisko.mod"; player = new Player(); add_object(player); - - printf("seccreated: %p.\n", this); } Sector::~Sector() { - printf("secdel: %p.\n", this); + update_game_objects(); + assert(gameobjects_new.size() == 0); + for(GameObjects::iterator i = gameobjects.begin(); i != gameobjects.end(); ++i) { delete *i; @@ -89,23 +89,6 @@ _current = 0; } -Sector *Sector::create(const std::string& name, size_t width, size_t height) -{ - Sector *sector = new Sector; - sector->name = name; - TileMap *background = new TileMap(LAYER_BACKGROUNDTILES, false, width, height); - TileMap *interactive = new TileMap(LAYER_TILES, true, width, height); - TileMap *foreground = new TileMap(LAYER_FOREGROUNDTILES, false, width, height); - sector->add_object(background); - sector->add_object(interactive); - sector->add_object(foreground); - sector->solids = interactive; - sector->camera = new Camera(sector); - sector->add_object(sector->camera); - sector->update_game_objects(); - return sector; -} - GameObject* Sector::parse_object(const std::string& name, LispReader& reader) { @@ -151,14 +134,6 @@ } else if(name == "nolok_01") { return new Nolok_01(reader); } -#if 0 - else if(badguykind_from_string(name) != BAD_INVALID) { - return new BadGuy(badguykind_from_string(name), reader); - } else if(name == "trampoline") { - return new Trampoline(reader); - } else if(name == "flying-platform") { - return new FlyingPlatform(reader); -#endif std::cerr << "Unknown object type '" << name << "'.\n"; return 0; @@ -197,6 +172,9 @@ } } + update_game_objects(); + fix_old_tiles(); + update_game_objects(); if(!camera) { std::cerr << "sector '" << name << "' does not contain a camera.\n"; camera = new Camera(this); @@ -237,11 +215,11 @@ bkgd_bottom.blue = b; if(backgroundimage != "") { - background = new Background; + Background* background = new Background; background->set_image(backgroundimage, bgspeed); add_object(background); } else { - background = new Background; + Background* background = new Background; background->set_gradient(bkgd_top, bkgd_bottom); add_object(background); } @@ -275,10 +253,7 @@ || reader.read_int_vector("tilemap", tiles)) { TileMap* tilemap = new TileMap(); tilemap->set(width, height, tiles, LAYER_TILES, true); - solids = tilemap; add_object(tilemap); - - fix_old_tiles(); } if(reader.read_int_vector("background-tm", tiles)) { @@ -338,8 +313,14 @@ } // add a camera - camera = new Camera(this); + Camera* camera = new Camera(this); add_object(camera); + + update_game_objects(); + fix_old_tiles(); + update_game_objects(); + if(solids == 0) + throw std::runtime_error("sector does not contain a solid tile layer."); } void @@ -411,41 +392,6 @@ } void -Sector::do_vertical_flip() -{ - // remove or fix later -#if 0 - for(GameObjects::iterator i = gameobjects_new.begin(); i != gameobjects_new.end(); ++i) - { - TileMap* tilemap = dynamic_cast<TileMap*> (*i); - if(tilemap) - { - tilemap->do_vertical_flip(); - } - - BadGuy* badguy = dynamic_cast<BadGuy*> (*i); - if(badguy) - badguy->start_position.y = solids->get_height()*32 - badguy->start_position.y - 32; - Trampoline* trampoline = dynamic_cast<Trampoline*> (*i); - if(trampoline) - trampoline->base.y = solids->get_height()*32 - trampoline->base.y - 32; - FlyingPlatform* flying_platform = dynamic_cast<FlyingPlatform*> (*i); - if(flying_platform) - flying_platform->base.y = solids->get_height()*32 - flying_platform->base.y - 32; - Door* door = dynamic_cast<Door*> (*i); - if(door) - door->set_area(door->get_area().x, solids->get_height()*32 - door->get_area().y - 32); - } - - for(SpawnPoints::iterator i = spawnpoints.begin(); i != spawnpoints.end(); - ++i) { - SpawnPoint* spawn = *i; - spawn->pos.y = solids->get_height()*32 - spawn->pos.y - 32; - } -#endif -} - -void Sector::add_object(GameObject* object) { // make sure the object isn't already in the list @@ -536,8 +482,7 @@ } /* Handle all possible collisions. */ - collision_handler(); - + collision_handler(); update_game_objects(); } @@ -573,7 +518,6 @@ if(tilemap && tilemap->is_solid()) { if(solids == 0) { solids = tilemap; - fix_old_tiles(); } else { std::cerr << "Another solid tilemaps added. Ignoring."; } @@ -774,14 +718,6 @@ } } -void -Sector::add_score(const Vector& pos, int s) -{ - global_stats.add_points(SCORE_STAT, s); - - add_object(new FloatingText(pos, s)); -} - bool Sector::add_bullet(const Vector& pos, float xm, Direction dir) { --- particlesystem.cpp DELETED --- --- gameobjs.h DELETED --- --- tilemap.h DELETED --- --- particlesystem.h DELETED --- --- camera.h DELETED --- Index: level.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/level.h,v retrieving revision 1.68 retrieving revision 1.69 diff -u -d -r1.68 -r1.69 --- level.h 25 Nov 2004 19:48:26 -0000 1.68 +++ level.h 26 Nov 2004 14:45:32 -0000 1.69 @@ -54,7 +54,6 @@ // loads a levelfile void load(const std::string& filename); void save(const std::string& filename); - static void create(const std::string& filename); EndSequenceType get_end_sequence_type() const { return end_sequence_type; } --- player.cpp DELETED --- Index: level.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/level.cpp,v retrieving revision 1.110 retrieving revision 1.111 diff -u -d -r1.110 -r1.111 --- level.cpp 26 Nov 2004 13:56:31 -0000 1.110 +++ level.cpp 26 Nov 2004 14:45:32 -0000 1.111 @@ -30,7 +30,6 @@ #include "app/globals.h" #include "app/setup.h" -#include "camera.h" #include "video/screen.h" #include "level.h" #include "math/physic.h" @@ -39,9 +38,10 @@ #include "tile.h" #include "utils/lispreader.h" #include "resources.h" -#include "gameobjs.h" #include "utils/lispwriter.h" -#include "tilemap.h" +#include "object/gameobjs.h" +#include "object/camera.h" +#include "object/tilemap.h" using namespace std; @@ -52,16 +52,6 @@ } void -Level::create(const std::string& filename) -{ - Level level; - const size_t width = 25; - const size_t height = 19; - level.add_sector(Sector::create("main", width, height)); - level.save(filename); -} - -void Level::load(const std::string& filepath) { LispReader* level = LispReader::load(filepath, "supertux-level"); @@ -167,8 +157,10 @@ void Level::do_vertical_flip() { +#if 0 for(Sectors::iterator i = sectors.begin(); i != sectors.end(); ++i) i->second->do_vertical_flip(); +#endif } void @@ -242,10 +234,7 @@ int total_coins = 0; for(Sectors::iterator i = sectors.begin(); i != sectors.end(); ++i) { TileMap* solids = i->second->solids; - if(!solids) { - std::cerr << "Sector '" << i->first << "' contains no solids!?!\n"; - continue; - } + assert(solids != 0); for(size_t x = 0; x < solids->get_width(); ++x) for(size_t y = 0; y < solids->get_height(); ++y) { const Tile* tile = solids->get_tile(x, y); --- background.cpp DELETED --- Index: supertux.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/supertux.cpp,v retrieving revision 1.33 retrieving revision 1.34 diff -u -d -r1.33 -r1.34 --- supertux.cpp 25 Nov 2004 01:12:13 -0000 1.33 +++ supertux.cpp 26 Nov 2004 14:45:41 -0000 1.34 @@ -39,7 +39,6 @@ #include "video/surface.h" #include "tile_manager.h" #include "app/gettext.h" -#include "player.h" #include "misc.h" #include "utils/configfile.h" Index: leveleditor.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/leveleditor.h,v retrieving revision 1.23 retrieving revision 1.24 diff -u -d -r1.23 -r1.24 --- leveleditor.h 23 Nov 2004 02:00:51 -0000 1.23 +++ leveleditor.h 26 Nov 2004 14:45:40 -0000 1.24 @@ -143,6 +143,9 @@ Vector selection_ini, selection_end; bool level_changed; + +private: + Sector* create_sector(const std::string& name, size_t width, size_t height); }; #endif |