[Super-tux-commit] supertux/src gameloop.cpp,1.168,1.169
Brought to you by:
wkendrick
From: Ricardo C. <rm...@us...> - 2004-09-12 16:11:58
|
Update of /cvsroot/super-tux/supertux/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8144/src Modified Files: gameloop.cpp Log Message: I guess this way is faster. Index: gameloop.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/gameloop.cpp,v retrieving revision 1.168 retrieving revision 1.169 diff -u -d -r1.168 -r1.169 --- gameloop.cpp 11 Sep 2004 14:48:07 -0000 1.168 +++ gameloop.cpp 12 Sep 2004 16:11:49 -0000 1.169 @@ -63,6 +63,19 @@ GameSession* GameSession::current_ = 0; +bool compare_last(std::string& haystack, std::string needle) +{ +int haystack_size = haystack.size(); +int needle_size = needle.size(); + +if(haystack_size < needle_size) + return false; + +if(haystack.compare(haystack_size-needle_size, needle_size, needle) == 0) + return true; +return false; +} + GameSession::GameSession(const std::string& levelname_, int mode, bool flip_level_) : level(0), currentsector(0), st_gl_mode(mode), end_sequence(NO_ENDSEQUENCE), levelname(levelname_), flip_level(flip_level_) @@ -456,34 +469,34 @@ if(!last_keys.empty()) { Player &tux = *currentsector->player; - if(last_keys.find("grow") != std::string::npos) + if(compare_last(last_keys, "grow")) { tux.grow(false); last_keys.clear(); } - if(last_keys.find("fire") != std::string::npos) + if(compare_last(last_keys, "fire")) { tux.grow(false); tux.got_power = tux.FIRE_POWER; last_keys.clear(); } - if(last_keys.find("ice") != std::string::npos) + if(compare_last(last_keys, "ice")) { tux.grow(false); tux.got_power = tux.ICE_POWER; last_keys.clear(); } - if(last_keys.find("lifeup") != std::string::npos) + if(compare_last(last_keys, "lifeup")) { player_status.lives++; last_keys.clear(); } - if(last_keys.find("lifedown") != std::string::npos) + if(compare_last(last_keys, "lifedown")) { player_status.lives--; last_keys.clear(); } - if(last_keys.find("invincible") != std::string::npos) + if(compare_last(last_keys, "invincible")) { // be invincle for the rest of the level tux.invincible_timer.start(time_left.get_left()); last_keys.clear(); |