From 2fb736141667adaa2a883741719fa2ac6cff9956 Mon Sep 17 00:00:00 2001 From: Ingo Ruhnke Date: Sun, 18 Apr 2004 13:42:15 +0000 Subject: [PATCH] - added constructor to level - changed framerate handling to avoid large frame_ratio's SVN-Revision: 554 --- src/gameloop.cpp | 17 +++++++++++------ src/globals.cpp | 1 + src/globals.h | 1 + src/level.cpp | 15 ++++++++++++++- src/level.h | 7 +++++-- src/resources.cpp | 4 ++-- src/special.cpp | 3 +-- src/world.cpp | 8 ++++---- 8 files changed, 39 insertions(+), 17 deletions(-) diff --git a/src/gameloop.cpp b/src/gameloop.cpp index d0368f016..1f1131ad6 100644 --- a/src/gameloop.cpp +++ b/src/gameloop.cpp @@ -10,6 +10,7 @@ April 11, 2000 - March 15, 2004 */ +#include #include #include #include @@ -345,10 +346,7 @@ GameSession::action(double frame_ratio) if (exit_status == NONE) { - Player* tux = world->get_tux(); - // Update Tux and the World - tux->action(frame_ratio); world->action(frame_ratio); } } @@ -410,12 +408,11 @@ GameSession::run() draw(); + float overlap = 0.0f; while (exit_status == NONE) { /* Calculate the movement-factor */ double frame_ratio = ((double)(update_time-last_update_time))/((double)FRAME_RATE); - if(frame_ratio > 1.5) /* Quick hack to correct the unprecise CPU clocks a little bit. */ - frame_ratio = 1.5 + (frame_ratio - 1.5) * 0.85; if(!frame_timer.check()) { @@ -463,7 +460,15 @@ GameSession::run() // Handle actions: if(!game_pause && !show_menu) { - action(frame_ratio); + frame_ratio *= game_speed; + frame_ratio += overlap; + while (frame_ratio > 0) + { + action(1.0f); + frame_ratio -= 1.0f; + } + overlap = frame_ratio; + if (exit_status != NONE) return exit_status; } diff --git a/src/globals.cpp b/src/globals.cpp index cab93076d..b121bc2e6 100644 --- a/src/globals.cpp +++ b/src/globals.cpp @@ -32,6 +32,7 @@ bool use_joystick; bool use_fullscreen; bool debug_mode; bool show_fps; +float game_speed = 1.0f; int joystick_num = 0; char* level_startup_file = 0; diff --git a/src/globals.h b/src/globals.h index e205c5bf4..625abf3d9 100644 --- a/src/globals.h +++ b/src/globals.h @@ -49,6 +49,7 @@ extern bool launch_worldmap_mode; extern char* st_dir; extern char* st_save_dir; +extern float game_speed; extern SDL_Joystick * js; int wait_for_event(SDL_Event& event,unsigned int min_delay = 0, unsigned int max_delay = 0, bool empty_events = false); diff --git a/src/level.cpp b/src/level.cpp index d13f44974..970c7b0a2 100644 --- a/src/level.cpp +++ b/src/level.cpp @@ -190,6 +190,20 @@ void st_subset::free() levels = 0; } +Level::Level() +{ +} + +Level::Level(const std::string& subset, int level) +{ + load(subset, level); +} + +Level::Level(const std::string& filename) +{ + load(filename); +} + void Level::init_defaults() { @@ -659,7 +673,6 @@ Level::load_song() free(song_path); } - unsigned int Level::gettileid(float x, float y) { diff --git a/src/level.h b/src/level.h index e3efe0df7..3f4bf10bb 100644 --- a/src/level.h +++ b/src/level.h @@ -73,6 +73,10 @@ class Level std::vector badguy_data; public: + Level(); + Level(const std::string& subset, int level); + Level(const std::string& filename); + /** Will the Level structure with default values */ void init_defaults(); @@ -88,6 +92,7 @@ class Level int load(const std::string& filename); void load_gfx(); + void free_gfx(); void load_song(); void free_song(); @@ -103,8 +108,6 @@ class Level /** Return the id of the tile at position x/y */ unsigned int gettileid(float x, float y); - void free_gfx(); - void load_image(Surface** ptexture, std::string theme, const char * file, int use_alpha); }; diff --git a/src/resources.cpp b/src/resources.cpp index ed01dc6e4..9abc40176 100644 --- a/src/resources.cpp +++ b/src/resources.cpp @@ -145,11 +145,11 @@ void loadshared() ducktux_right = new Surface(datadir + - "/images/shared/ducktux-right.png", + "/images/shared/tux-duck-right.png", USE_ALPHA); ducktux_left = new Surface(datadir + - "/images/shared/ducktux-left.png", + "/images/shared/tux-duck-left.png", USE_ALPHA); skidtux_right = new Surface(datadir + diff --git a/src/special.cpp b/src/special.cpp index 25ffd17ad..78ae3637c 100644 --- a/src/special.cpp +++ b/src/special.cpp @@ -323,8 +323,7 @@ void load_special_gfx() img_growup = new Surface(datadir + "/images/shared/egg.png", USE_ALPHA); img_iceflower = new Surface(datadir + "/images/shared/iceflower.png", USE_ALPHA); - img_golden_herring = new Surface(datadir + - "/images/shared/star.png", USE_ALPHA); + img_golden_herring = new Surface(datadir + "/images/shared/star.png", USE_ALPHA); img_1up = new Surface(datadir + "/images/shared/1up.png", USE_ALPHA); diff --git a/src/world.cpp b/src/world.cpp index 1be985ed9..2617f532a 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -39,10 +39,9 @@ World::World(const std::string& filename) // world calls child functions current_ = this; - level = new Level; + level = new Level(filename); tux.init(); - level->load(filename); set_defaults(); get_level()->load_gfx(); @@ -57,10 +56,9 @@ World::World(const std::string& subset, int level_nr) // world calls child functions current_ = this; - level = new Level; + level = new Level(subset, level_nr); tux.init(); - level->load(subset, level_nr); set_defaults(); get_level()->load_gfx(); @@ -205,6 +203,8 @@ World::draw() void World::action(double frame_ratio) { + tux.action(frame_ratio); + /* Handle bouncy distros: */ for (unsigned int i = 0; i < bouncy_distros.size(); i++) bouncy_distros[i].action(frame_ratio); -- 2.11.0