From: Ricardo Cruz Date: Mon, 28 Jun 2004 11:30:27 +0000 (+0000) Subject: A few changes to make the code ready for the new level editor. X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=4768775a296265eea1afae5cf971b1706fc049fd;p=supertux.git A few changes to make the code ready for the new level editor. Major changes: - Level's save() works. Still doesn't save the game properly. - added a set_drawing_effect() for DrawingContext. Will apply it to the following drawings. Works with pop/push_transform. SVN-Revision: 1514 --- diff --git a/src/level.cpp b/src/level.cpp index 3470547e7..a3d5a44d5 100644 --- a/src/level.cpp +++ b/src/level.cpp @@ -100,40 +100,27 @@ Level::load_old_format(LispReader& reader) void Level::save(const std::string& filename) { -#if 0 - LispReader* level = LispReader::load(filename, "supertux-level"); + ofstream file(filename.c_str(), ios::out); + LispWriter* writer = new LispWriter(file); - int version = 1; - level->read_int("version", version); - if(version == 1) { - load_old_format(*level); - return; - } + writer->write_comment("Level made using SuperTux's built-in Level Editor"); - for(lisp_object_t* cur = level->get_lisp(); !lisp_nil_p(cur); - cur = lisp_cdr(cur)) { - std::string token = lisp_symbol(lisp_car(lisp_car(cur))); - lisp_object_t* data = lisp_car(lisp_cdr(lisp_car(cur))); - LispReader reader(lisp_cdr(lisp_car(cur))); + writer->start_list("supertux-level"); - if(token == "name") { - name = lisp_string(data); - } else if(token == "author") { - author = lisp_string(data); - } else if(token == "time") { - time_left = lisp_integer(data); - } else if(token == "sector") { - Sector* sector = new Sector; - sector->parse(reader); - add_sector(sector); - } else { - std::cerr << "Unknown token '" << token << "' in level file.\n"; - continue; - } - } - - delete level; -#endif + int version = 2; + writer->write_int("version", version); + + writer->write_string("name", name); + writer->write_string("author", author); + writer->write_int("time", time_left); + + for(Sectors::iterator i = sectors.begin(); i != sectors.end(); ++i) + i->second->write(*writer); + + writer->end_list("supertux-level"); + + delete writer; + file.close(); } Level::~Level() diff --git a/src/mousecursor.cpp b/src/mousecursor.cpp index ee0a57d01..177f2f746 100644 --- a/src/mousecursor.cpp +++ b/src/mousecursor.cpp @@ -89,5 +89,5 @@ void MouseCursor::draw(DrawingContext& context) } context.draw_surface_part(cursor, Vector(w*cur_frame, h*cur_state), Vector(w, - h), Vector(x-mid_x, y-mid_y), LAYER_FOREGROUND1+100); + h), Vector(x-mid_x, y-mid_y), LAYER_GUI+100); } diff --git a/src/screen/drawing_context.cpp b/src/screen/drawing_context.cpp index 9a2227441..135d9a128 100644 --- a/src/screen/drawing_context.cpp +++ b/src/screen/drawing_context.cpp @@ -27,6 +27,7 @@ DrawingContext::DrawingContext() { +transform.draw_effect = NONE_EFFECT; } DrawingContext::~DrawingContext() @@ -46,6 +47,7 @@ DrawingContext::draw_surface(const Surface* surface, const Vector& position, request.request_data = const_cast (surface); request.pos = transform.apply(position); request.drawing_effect = drawing_effect; + request.drawing_effect = transform.draw_effect | drawing_effect; drawingrequests.push_back(request); } @@ -341,3 +343,8 @@ DrawingContext::pop_transform() transformstack.pop_back(); } +void +DrawingContext::set_drawing_effect(int effect) +{ + transform.draw_effect = effect; +} diff --git a/src/screen/drawing_context.h b/src/screen/drawing_context.h index 1c6241929..ceb9ea2bc 100644 --- a/src/screen/drawing_context.h +++ b/src/screen/drawing_context.h @@ -83,6 +83,9 @@ public: void push_transform(); void pop_transform(); + /** apply that effect in the next draws (effects are listed on surface.h) */ + void set_drawing_effect(int effect); + private: class Transform { @@ -93,6 +96,8 @@ private: { return v - translation; } + + int draw_effect; }; /// the transform stack diff --git a/src/sector.cpp b/src/sector.cpp index 163611803..5752860c2 100644 --- a/src/sector.cpp +++ b/src/sector.cpp @@ -332,6 +332,12 @@ Sector::action(float elapsed_time) /* Handle all possible collisions. */ collision_handler(); + update_game_objects(); +} + +void +Sector::update_game_objects() +{ /** cleanup marked objects */ for(std::vector::iterator i = gameobjects.begin(); i != gameobjects.end(); /* nothing */) { @@ -407,7 +413,6 @@ Sector::action(float elapsed_time) gameobjects.push_back(*i); } gameobjects_new.clear(); - } void diff --git a/src/sector.h b/src/sector.h index 4db528543..c8aa0b3b5 100644 --- a/src/sector.h +++ b/src/sector.h @@ -69,6 +69,8 @@ public: void activate(const std::string& spawnpoint = "main"); void action(float elapsed_time); + void update_game_objects(); + void draw(DrawingContext& context); /// adds a gameobject diff --git a/src/supertux.cpp b/src/supertux.cpp index 588639a20..7c46b7494 100644 --- a/src/supertux.cpp +++ b/src/supertux.cpp @@ -58,10 +58,14 @@ int main(int argc, char * argv[]) st_menu(); loadshared(); - if (launch_leveleditor_mode && level_startup_file) + if (launch_leveleditor_mode) { - // TODO - // leveleditor(level_startup_file); + LevelEditor leveleditor; + + if(level_startup_file) + leveleditor.run(level_startup_file); + else + leveleditor.run(); } else if (level_startup_file) { diff --git a/src/tile_manager.h b/src/tile_manager.h index a55fcb84d..a72777b13 100644 --- a/src/tile_manager.h +++ b/src/tile_manager.h @@ -61,6 +61,10 @@ class TileManager const Vector& pos, int layer); static std::set* tilegroups() { if(!instance_) { instance_ = new TileManager(); } return tilegroups_ ? tilegroups_ : tilegroups_ = new std::set; } + + unsigned int total_ids() + { return tiles.size(); } + Tile& get(unsigned int id) { if(id < tiles.size()) diff --git a/src/tilemap.h b/src/tilemap.h index 6f826421b..fa39f2a47 100644 --- a/src/tilemap.h +++ b/src/tilemap.h @@ -68,6 +68,9 @@ public: size_t get_height() const { return height; } + + int get_layer() const + { return layer; } bool is_solid() const { return solid; }