From 8bad5124338c5a9fd0f40d5a317f457626e81038 Mon Sep 17 00:00:00 2001 From: Thai Pangsakulyanont Date: Wed, 27 Jul 2011 00:29:22 +0700 Subject: [PATCH] Fix performance issue: remove the slow assertion code. GetDisplayedBeat and GetDisplayedSpeedPercent are called so many times in one frame so they need to be as fast as possible. --- Xcode/stepmania.xcodeproj/project.pbxproj | 5 +++-- src/TimingData.cpp | 24 ++++++----------------- 2 files changed, 9 insertions(+), 20 deletions(-) diff --git a/Xcode/stepmania.xcodeproj/project.pbxproj b/Xcode/stepmania.xcodeproj/project.pbxproj index 148b6bccb4..2b7410f7b0 100644 --- a/Xcode/stepmania.xcodeproj/project.pbxproj +++ b/Xcode/stepmania.xcodeproj/project.pbxproj @@ -1861,7 +1861,6 @@ 2B17AB7213980FDF001AE57D /* libpng-1.5.1-sm5.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libpng-1.5.1-sm5.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 2B17ABC013981521001AE57D /* libglew-sm5.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libglew-sm5.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 2B17ABE013981756001AE57D /* libpcre-sm5.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libpcre-sm5.a"; sourceTree = BUILT_PRODUCTS_DIR; }; - 2B23246213DE001D005FA074 /* sm-ssc.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; name = "sm-ssc.app"; path = "/Users/wolfman2000/Repositories/sm-ssc/sm-ssc.app"; sourceTree = ""; }; 2B30D6801315EA7E00044B68 /* MouseDevice.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MouseDevice.cpp; sourceTree = ""; }; 2B30D6811315EA7E00044B68 /* MouseDevice.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MouseDevice.h; sourceTree = ""; }; 2B43509313949F37006FA051 /* TimingSegments.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TimingSegments.h; path = ../src/TimingSegments.h; sourceTree = SOURCE_ROOT; }; @@ -3118,6 +3117,7 @@ AAFF55220549F43A00D02EE9 /* ComboGraph.h */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.h; name = ComboGraph.h; path = ../src/ComboGraph.h; sourceTree = ""; }; AAFF5541054E736D00D02EE9 /* Attack.cpp */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.cpp; name = Attack.cpp; path = ../src/Attack.cpp; sourceTree = ""; }; AAFF5542054E736D00D02EE9 /* Attack.h */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.h; name = Attack.h; path = ../src/Attack.h; sourceTree = ""; }; + B7055CE913DF263F00732AED /* sm-ssc.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "sm-ssc.app"; sourceTree = BUILT_PRODUCTS_DIR; }; B71A60BE139B41DB00183A27 /* InGameLoadingWindow.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = InGameLoadingWindow.cpp; path = ../src/InGameLoadingWindow.cpp; sourceTree = ""; }; B71A60BF139B41DB00183A27 /* InGameLoadingWindow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = InGameLoadingWindow.h; path = ../src/InGameLoadingWindow.h; sourceTree = ""; }; B75CE3B3137963350076A82D /* SongPosition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SongPosition.h; path = ../src/SongPosition.h; sourceTree = SOURCE_ROOT; }; @@ -3315,6 +3315,7 @@ 2B17ABC013981521001AE57D /* libglew-sm5.a */, 2B17ABE013981756001AE57D /* libpcre-sm5.a */, 2BD6E10C13D78B36008443DB /* libzlib-sm5.a */, + B7055CE913DF263F00732AED /* sm-ssc.app */, ); name = Products; sourceTree = ""; @@ -5909,7 +5910,7 @@ name = "stepmania-bare"; productInstallPath = "$(HOME)/Applications"; productName = "SDL App"; - productReference = 2B23246213DE001D005FA074 /* sm-ssc.app */; + productReference = B7055CE913DF263F00732AED /* sm-ssc.app */; productType = "com.apple.product-type.application"; }; AA7A2B930AE09B520054C5BA /* lua */ = { diff --git a/src/TimingData.cpp b/src/TimingData.cpp index 65df49d924..a7f0ca16ca 100644 --- a/src/TimingData.cpp +++ b/src/TimingData.cpp @@ -977,28 +977,16 @@ float TimingData::GetElapsedTimeFromBeatNoOffset( float fBeat ) const float TimingData::GetDisplayedBeat( float fBeat ) const { - const vector &scrolls = this->allTimingSegments[SEGMENT_SCROLL]; - vector::const_iterator it = scrolls.begin(), end = scrolls.end(); float fOutBeat = 0; - for( it = it + 1; it != end; it++ ) + unsigned i; + const vector &scrolls = this->allTimingSegments[SEGMENT_SCROLL]; + for( i=0; iGetBeat() <= (*it)->GetBeat()); - } - it = scrolls.begin(); - for( ; it != end; it++ ) - { - if( it+1 == end || fBeat <= (*(it+1))->GetBeat() ) - { - fOutBeat += ( fBeat - (*it)->GetBeat() ) * - static_cast(*it)->GetRatio(); + if( scrolls[i+1]->GetBeat() > fBeat ) break; - } - else - { - fOutBeat += ( (*(it+1))->GetBeat() - (*it)->GetBeat() ) * - static_cast(*it)->GetRatio(); - } + fOutBeat += (scrolls[i+1]->GetBeat() - scrolls[i]->GetBeat()) * static_cast(scrolls[i])->GetRatio(); } + fOutBeat += (fBeat - scrolls[i]->GetBeat()) * static_cast(scrolls[i])->GetRatio(); return fOutBeat; }