From: Matthias Braun Date: Wed, 11 Jan 2006 12:40:26 +0000 (+0000) Subject: some startup time debugging, changed skid dust particles back to old behaviour X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=70fdbd45026801f0f0f312278c69b383eaca9d3a;p=supertux.git some startup time debugging, changed skid dust particles back to old behaviour SVN-Revision: 2980 --- diff --git a/data/images/objects/particles/stomp.sprite b/data/images/objects/particles/stomp.sprite new file mode 100644 index 000000000..4f556d9f0 --- /dev/null +++ b/data/images/objects/particles/stomp.sprite @@ -0,0 +1,7 @@ +(supertux-sprite + (action + (x-offset 0) + (y-offset 0) + (images "stomp.png") + ) +) diff --git a/data/images/sprites.strf b/data/images/sprites.strf index e9a933de7..343b99f9f 100644 --- a/data/images/sprites.strf +++ b/data/images/sprites.strf @@ -1150,14 +1150,6 @@ (images "objects/bonus_block/empty.png")) ) - ; Stomp - (sprite (name "stomp") - (action - (x-offset 0) - (y-offset 0) - (images "objects/particles/stomp.png") - )) - (sprite (name "unstable_tile") (action (images "objects/unstable_tile/unstable_tile.png")) diff --git a/src/game_session.cpp b/src/game_session.cpp index 7baf7c5b7..c1531de18 100644 --- a/src/game_session.cpp +++ b/src/game_session.cpp @@ -449,38 +449,9 @@ GameSession::draw() void GameSession::draw_pause() { - int x = SCREEN_HEIGHT / 20; - for(int i = 0; i < x; ++i) { - context->draw_filled_rect( - Vector(i % 2 ? (pause_menu_frame * i)%SCREEN_WIDTH : - -((pause_menu_frame * i)%SCREEN_WIDTH) - ,(i*20+pause_menu_frame)%SCREEN_HEIGHT), - Vector(SCREEN_WIDTH,10), - Color(0.1, 0.1, 0.1, static_cast(rand() % 20 + 1) / 255.0), - LAYER_FOREGROUND1+1); - } - context->draw_filled_rect( Vector(0,0), Vector(SCREEN_WIDTH, SCREEN_HEIGHT), - Color( - static_cast(rand() % 50) / 255.0, - static_cast(rand() % 50) / 255.0, - static_cast(rand() % 50) / 255.0, - 0.5), LAYER_FOREGROUND1); -#if 0 - context->draw_text(blue_text, _("PAUSE - Press 'P' To Play"), - Vector(SCREEN_WIDTH/2, 230), CENTER_ALLIGN, LAYER_FOREGROUND1+2); - - const char* str1 = _("Playing: "); - const char* str2 = level->get_name().c_str(); - - context->draw_text(blue_text, str1, - Vector((SCREEN_WIDTH - (blue_text->get_text_width(str1) + white_text->get_text_width(str2)))/2, 340), - LEFT_ALLIGN, LAYER_FOREGROUND1+2); - context->draw_text(white_text, str2, - Vector(((SCREEN_WIDTH - (blue_text->get_text_width(str1) + white_text->get_text_width(str2)))/2)+blue_text->get_text_width(str1), 340), - LEFT_ALLIGN, LAYER_FOREGROUND1+2); -#endif + Color(.2, .2, .2, .5), LAYER_FOREGROUND1); } void diff --git a/src/gui/menu.cpp b/src/gui/menu.cpp index 94564e5d9..7b2868f55 100644 --- a/src/gui/menu.cpp +++ b/src/gui/menu.cpp @@ -213,10 +213,10 @@ Menu::Menu() active_item = -1; } -void Menu::set_pos(int x, int y, float rw, float rh) +void Menu::set_pos(float x, float y, float rw, float rh) { - pos_x = x + (int)((float)get_width() * rw); - pos_y = y + (int)((float)get_height() * rh); + pos_x = x + get_width() * rw; + pos_y = y + get_height() * rh; } /* Add an item to a menu */ @@ -503,8 +503,8 @@ Menu::draw_item(DrawingContext& context, int index) } Font* text_font = default_font; - int x_pos = pos_x; - int y_pos = pos_y + 24*index - menu_height/2 + 12 + effect_offset; + float x_pos = pos_x; + float y_pos = pos_y + 24*index - menu_height/2 + 12 + effect_offset; int shadow_size = 2; int text_width = int(text_font->get_text_width(pitem.text)); int input_width = int(text_font->get_text_width(pitem.input) + 10); @@ -535,8 +535,8 @@ Menu::draw_item(DrawingContext& context, int index) case MN_HL: { // TODO - int x = pos_x - menu_width/2; - int y = y_pos - 12 - effect_offset; + float x = pos_x - menu_width/2; + float y = y_pos - 12 - effect_offset; /* Draw a horizontal line with a little 3d effect */ context.draw_filled_rect(Vector(x, y + 6), Vector(menu_width, 4), @@ -557,9 +557,9 @@ Menu::draw_item(DrawingContext& context, int index) case MN_NUMFIELD: case MN_CONTROLFIELD: { - int width = text_width + input_width + 5; - int text_pos = SCREEN_WIDTH/2 - width/2; - int input_pos = text_pos + text_width + 10; + float width = text_width + input_width + 5; + float text_pos = SCREEN_WIDTH/2 - width/2; + float input_pos = text_pos + text_width + 10; context.draw_filled_rect( Vector(input_pos - 5, y_pos - 10), @@ -777,15 +777,16 @@ Menu::event(const SDL_Event& event) case SDL_MOUSEMOTION: { - int x = int(event.motion.x * float(SCREEN_WIDTH)/screen->w); - int y = int(event.motion.y * float(SCREEN_HEIGHT)/screen->h); + float x = event.motion.x * SCREEN_WIDTH/screen->w; + float y = event.motion.y * SCREEN_HEIGHT/screen->h; if(x > pos_x - get_width()/2 && x < pos_x + get_width()/2 && y > pos_y - get_height()/2 && y < pos_y + get_height()/2) { - int new_active_item = (y - (pos_y - get_height()/2)) / 24; + int new_active_item + = static_cast ((y - (pos_y - get_height()/2)) / 24); /* only change the mouse focus to a selectable item */ if ((items[new_active_item]->kind != MN_HL) diff --git a/src/gui/menu.hpp b/src/gui/menu.hpp index 88da10812..302a402cb 100644 --- a/src/gui/menu.hpp +++ b/src/gui/menu.hpp @@ -121,8 +121,8 @@ private: int hit_item; // position of the menu (ie. center of the menu, not top/left) - int pos_x; - int pos_y; + float pos_x; + float pos_y; /** input event for the menu (up, down, left, right, etc.) */ MenuAction menuaction; @@ -176,7 +176,7 @@ public: void set_active_item(int id); void draw(DrawingContext& context); - void set_pos(int x, int y, float rw = 0, float rh = 0); + void set_pos(float x, float y, float rw = 0, float rh = 0); void event(const SDL_Event& event); diff --git a/src/main.cpp b/src/main.cpp index 1b5653b94..3925f75a0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -425,21 +425,52 @@ void wait_for_event(float min_delay, float max_delay) } } +#ifdef DEBUG +static Uint32 last_timelog_ticks = 0; +static const char* last_timelog_component = 0; + +static inline void timelog(const char* component) +{ + Uint32 current_ticks = SDL_GetTicks(); + + if(last_timelog_component != 0) { + printf("Component '%s' finished after %f seconds\n", + last_timelog_component, (current_ticks - last_timelog_ticks) / 1000.0); + } + + last_timelog_ticks = current_ticks; + last_timelog_component = component; +} +#else +static inline void timelog(const char* ) +{ +} +#endif + int main(int argc, char** argv) { try { srand(time(0)); init_physfs(argv[0]); init_sdl(); + timelog("controller"); main_controller = new JoystickKeyboardController(); + timelog("config"); init_config(); + timelog("tinygettext"); init_tinygettext(); + timelog("commandline"); parse_commandline(argc, argv); + timelog("audio"); init_audio(); + timelog("video"); init_video(); + timelog("menu"); setup_menu(); + timelog("resources"); load_shared(); + timelog(0); if(config->start_level != "") { // we have a normal path specified at commandline not physfs paths. // So we simply mount that path here... diff --git a/src/main.hpp b/src/main.hpp index 3738c0039..8a65366dc 100644 --- a/src/main.hpp +++ b/src/main.hpp @@ -23,8 +23,8 @@ void init_video(); void wait_for_event(float min_delay, float max_delay); -static const int SCREEN_WIDTH = 800; -static const int SCREEN_HEIGHT = 600; +static const float SCREEN_WIDTH = 800; +static const float SCREEN_HEIGHT = 600; // global variables class JoystickKeyboardController; diff --git a/src/object/fireworks.cpp b/src/object/fireworks.cpp index 7047bf94b..112909728 100644 --- a/src/object/fireworks.cpp +++ b/src/object/fireworks.cpp @@ -23,7 +23,7 @@ #include "resources.hpp" #include "sector.hpp" #include "camera.hpp" -#include "gameobjs.hpp" +#include "particles.hpp" #include "main.hpp" #include "video/drawing_context.hpp" #include "audio/sound_manager.hpp" diff --git a/src/object/gameobjs.cpp b/src/object/gameobjs.cpp index 8bc045c2f..3ea669e47 100644 --- a/src/object/gameobjs.cpp +++ b/src/object/gameobjs.cpp @@ -153,6 +153,12 @@ SmokeCloud::SmokeCloud(const Vector& pos) : position(pos) { timer.start(.3); + sprite = sprite_manager->create("images/objects/particles/stomp.sprite"); +} + +SmokeCloud::~SmokeCloud() +{ + delete sprite; } void @@ -167,92 +173,6 @@ SmokeCloud::update(float elapsed_time) void SmokeCloud::draw(DrawingContext& context) { - img_smoke_cloud->draw(context, position, LAYER_OBJECTS+1); -} - -Particles::Particles(const Vector& epicenter, int min_angle, int max_angle, - const Vector& initial_velocity, const Vector& acceleration, int number, - Color color_, int size_, float life_time, int drawing_layer_) - : accel(acceleration), color(color_), size(size_), drawing_layer(drawing_layer_) -{ - if(life_time == 0) { - live_forever = true; - } else { - live_forever = false; - timer.start(life_time); - } - - // create particles - for(int p = 0; p < number; p++) - { - Particle* particle = new Particle; - particle->pos = epicenter; - - float angle = ((rand() % (max_angle-min_angle))+min_angle) - * (M_PI / 180); // convert to radius - particle->vel.x = /*fabs*/(sin(angle)) * initial_velocity.x; -// if(angle >= M_PI && angle < M_PI*2) -// particle->vel.x *= -1; // work around to fix signal - particle->vel.y = /*fabs*/(cos(angle)) * initial_velocity.y; -// if(angle >= M_PI_2 && angle < 3*M_PI_2) -// particle->vel.y *= -1; - - particles.push_back(particle); - } -} - -Particles::~Particles() -{ - // free particles - for(std::vector::iterator i = particles.begin(); - i < particles.end(); i++) - delete (*i); -} - -void -Particles::update(float elapsed_time) -{ - Vector camera = Sector::current()->camera->get_translation(); - - // update particles - for(std::vector::iterator i = particles.begin(); - i != particles.end(); ) { - (*i)->pos.x += (*i)->vel.x * elapsed_time; - (*i)->pos.y += (*i)->vel.y * elapsed_time; - - (*i)->vel.x += accel.x * elapsed_time; - (*i)->vel.y += accel.y * elapsed_time; - - if((*i)->pos.x < camera.x || (*i)->pos.x > SCREEN_WIDTH + camera.x || - (*i)->pos.y < camera.y || (*i)->pos.y > SCREEN_HEIGHT + camera.y) { - delete (*i); - i = particles.erase(i); - } else { - ++i; - } - } - - if((timer.check() && !live_forever) || particles.size() == 0) - remove_me(); -} - -void -Particles::draw(DrawingContext& context) -{ - // draw particles - for(std::vector::iterator i = particles.begin(); - i != particles.end(); i++) { - context.draw_filled_rect((*i)->pos, Vector(size,size), color,drawing_layer); - } -} - -void load_object_gfx() -{ - img_smoke_cloud = sprite_manager->create("stomp"); -} - -void free_object_gfx() -{ - delete img_smoke_cloud; + sprite->draw(context, position, LAYER_OBJECTS+1); } diff --git a/src/object/gameobjs.hpp b/src/object/gameobjs.hpp index 53e8b4827..18718e1ad 100644 --- a/src/object/gameobjs.hpp +++ b/src/object/gameobjs.hpp @@ -80,51 +80,21 @@ private: Timer timer; }; -extern Sprite *img_smoke_cloud; - class SmokeCloud : public GameObject { public: SmokeCloud(const Vector& pos); + ~SmokeCloud(); virtual void update(float elapsed_time); virtual void draw(DrawingContext& context); private: + Sprite* sprite; Timer timer; Vector position; }; -class Particles : public GameObject -{ -public: - Particles(const Vector& epicenter, int min_angle, int max_angle, - const Vector& initial_velocity, const Vector& acceleration, - int number, Color color, int size, float life_time, int drawing_layer); - ~Particles(); - - virtual void update(float elapsed_time); - virtual void draw(DrawingContext& context); - -private: - Vector accel; - Timer timer; - bool live_forever; - - Color color; - float size; - int drawing_layer; - - struct Particle { - Vector pos, vel; -// float angle; - }; - std::vector particles; -}; - -void load_object_gfx(); -void free_object_gfx(); - #endif /* Local Variables: */ diff --git a/src/object/particlesystem.cpp b/src/object/particlesystem.cpp index c9b484b28..de2282084 100644 --- a/src/object/particlesystem.cpp +++ b/src/object/particlesystem.cpp @@ -83,8 +83,8 @@ SnowParticleSystem::SnowParticleSystem() size_t snowflakecount = size_t(virtual_width/10.0); for(size_t i=0; ipos.x = rand() % int(virtual_width); - particle->pos.y = rand() % SCREEN_HEIGHT; + particle->pos.x = fmodf(rand(), virtual_width); + particle->pos.y = fmodf(rand(), SCREEN_HEIGHT); int snowsize = rand() % 3; particle->texture = snowimages[snowsize]; do { @@ -142,8 +142,8 @@ GhostParticleSystem::GhostParticleSystem() size_t ghostcount = 2; for(size_t i=0; ipos.x = rand() % int(virtual_width); - particle->pos.y = rand() % SCREEN_HEIGHT; + particle->pos.x = fmodf(rand(), virtual_width); + particle->pos.y = fmodf(rand(), SCREEN_HEIGHT); int size = rand() % 2; particle->texture = ghosts[size]; do { diff --git a/src/object/player.cpp b/src/object/player.cpp index 884059f73..1a8feb6f4 100644 --- a/src/object/player.cpp +++ b/src/object/player.cpp @@ -36,7 +36,7 @@ #include "game_session.hpp" #include "object/tilemap.hpp" #include "object/camera.hpp" -#include "object/gameobjs.hpp" +#include "object/particles.hpp" #include "object/portable.hpp" #include "object/bullet.hpp" #include "trigger/trigger_base.hpp" @@ -281,10 +281,9 @@ Player::handle_horizontal_input() // dust some particles Sector::current()->add_object( new Particles( - Vector(bbox.p1.x + (dir == RIGHT ? bbox.get_width() : 0), - bbox.p2.y), + Vector(dir == RIGHT ? bbox.p2.x : bbox.p1.x, bbox.p2.y), dir == RIGHT ? 270+20 : 90-40, dir == RIGHT ? 270+40 : 90-20, - Vector(280,-260), Vector(0,0.030), 3, Color(100,100,100), 3, .8, + Vector(280, -260), Vector(0, 300), 3, Color(.4, .4, .4), 3, .8, LAYER_OBJECTS+1)); ax *= 2.5; diff --git a/src/resources.cpp b/src/resources.cpp index e1ac72fba..e6583862e 100644 --- a/src/resources.cpp +++ b/src/resources.cpp @@ -113,9 +113,6 @@ void load_shared() ice_tux->arms = sprite_manager->create("big-tux-arms"); ice_tux->feet = sprite_manager->create("big-tux-feet"); - /* Objects */ - load_object_gfx(); - /* Tux life: */ tux_life = new Surface("images/creatures/tux_small/tux-life.png"); @@ -133,8 +130,6 @@ void unload_shared() delete white_small_text; delete white_big_text; - free_object_gfx(); - delete tux_life; delete small_tux; diff --git a/src/sprite/sprite_manager.cpp b/src/sprite/sprite_manager.cpp index aea403c1b..e0c6b5edb 100644 --- a/src/sprite/sprite_manager.cpp +++ b/src/sprite/sprite_manager.cpp @@ -32,7 +32,13 @@ SpriteManager::SpriteManager(const std::string& filename) { +#ifdef DEBUG + Uint32 ticks = SDL_GetTicks(); +#endif load_resfile(filename); +#ifdef DEBUG + printf("Loaded sprites in %f seconds\n", (SDL_GetTicks() - ticks) / 1000.0f); +#endif } SpriteManager::~SpriteManager() diff --git a/src/tile_manager.cpp b/src/tile_manager.cpp index 25c4997a9..c9db17fc1 100644 --- a/src/tile_manager.cpp +++ b/src/tile_manager.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include "video/drawing_context.hpp" #include "lisp/lisp.hpp" #include "lisp/parser.hpp" @@ -34,7 +35,13 @@ TileManager::TileManager(const std::string& filename) { +#ifdef DEBUG + Uint32 ticks = SDL_GetTicks(); +#endif load_tileset(filename); +#ifdef DEBUG + printf("Tiles loaded in %f seconds\n", (SDL_GetTicks() - ticks) / 1000.0); +#endif } TileManager::~TileManager() diff --git a/src/video/color.hpp b/src/video/color.hpp index 7cbbd7206..d48aa8b74 100644 --- a/src/video/color.hpp +++ b/src/video/color.hpp @@ -11,7 +11,11 @@ public: { } Color(float red, float green, float blue, float alpha = 1.0) : red(red), green(green), blue(blue), alpha(alpha) - { } + { +#ifdef DEBUG + check_color_ranges(); +#endif + } Color(const std::vector& vals) { red = vals[0]; @@ -21,6 +25,18 @@ public: alpha = vals[3]; else alpha = 1.0; +#ifdef DEBUG + check_color_ranges(); +#endif + } + + void check_color_ranges() + { + if(red < 0 || red > 1.0 || green < 0 || green > 1.0 + || blue < 0 || blue > 1.0 + || alpha < 0 || alpha > 1.0) + printf("Warning: color value out of range: %f %f %f %f\n", + red, green, blue, alpha); } float red, green, blue, alpha;