diff --git a/Makefile b/Makefile index fda3a04..38d8998 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC=g++ -CCFLAGS=-std=c++17 -DBMS_PARSER_VERBOSE=0 +CCFLAGS=-std=c++17 -O2 -DBMS_PARSER_VERBOSE=0 SRC_FILES = $(wildcard src/*.cpp) OBJ_PATH=obj BUILD_PATH=build diff --git a/src/Chart.h b/src/Chart.h index d280ec6..a74047c 100644 --- a/src/Chart.h +++ b/src/Chart.h @@ -32,7 +32,7 @@ namespace bms_parser std::wstring Folder; std::wstring Artist = L""; std::wstring SubArtist = L""; - double Bpm; + double Bpm = 0; std::wstring Genre = L""; std::wstring Title = L""; std::wstring SubTitle = L""; @@ -48,15 +48,15 @@ namespace bms_parser bool BgaPoorDefault = false; int Difficulty = 0; double PlayLevel = 3; - double MinBpm; - double MaxBpm; + double MinBpm = 0; + double MaxBpm = 0; int Player = 1; int KeyMode = 5; bool IsDP = false; - int TotalNotes; - int TotalLongNotes; - int TotalScratchNotes; - int TotalBackSpinNotes; + int TotalNotes = 0; + int TotalLongNotes = 0; + int TotalScratchNotes = 0; + int TotalBackSpinNotes = 0; int LnMode = 0; // 0: user decides, 1: LN, 2: CN, 3: HCN int GetKeyLaneCount() const { return KeyMode; } diff --git a/src/Parser.cpp b/src/Parser.cpp index 05810c3..5f120fe 100644 --- a/src/Parser.cpp +++ b/src/Parser.cpp @@ -102,7 +102,7 @@ namespace bms_parser int Parser::NoWav = -1; int Parser::MetronomeWav = -2; - bool Parser::MatchHeader(const std::wstring_view &str, const std::wstring_view &headerUpper) + inline bool Parser::MatchHeader(const std::wstring_view &str, const std::wstring_view &headerUpper) { auto size = headerUpper.length(); if (str.length() < size) @@ -598,12 +598,8 @@ namespace bms_parser break; case BpmChange: { - std::wstringstream ss; - ss << std::hex << val_view; - int bpm; - ss >> bpm; - // parse hex number - timeline->Bpm = bpm; + int bpm = ParseHex(val_view); + timeline->Bpm = static_cast(bpm); // std::cout << "BPM_CHANGE: " << timeline->Bpm << ", on measure " << i << std::endl; // Debug.Log($"BPM_CHANGE: {timeline.Bpm}, on measure {i}"); timeline->BpmChange = true; @@ -1112,7 +1108,7 @@ namespace bms_parser } } - int Parser::Gcd(int A, int B) + inline int Parser::Gcd(int A, int B) { while (true) { @@ -1131,7 +1127,7 @@ namespace bms_parser return Id >= 0 && Id < (UseBase62 ? 62*62 : 36*36); } - int Parser::ToWaveId(Chart *Chart, std::wstring_view Wav, bool metaOnly) + inline int Parser::ToWaveId(Chart *Chart, std::wstring_view Wav, bool metaOnly) { if (metaOnly) { @@ -1151,8 +1147,28 @@ namespace bms_parser return Chart->WavTable.find(decoded) != Chart->WavTable.end() ? decoded : NoWav; } - - int Parser::ParseInt(std::wstring_view Str, bool forceBase36) + inline int Parser::ParseHex(std::wstring_view Str) + { + auto result = 0; + for (auto i = 0; i < Str.length(); ++i) + { + auto c = Str[i]; + if (c >= '0' && c <= '9') + { + result = result * 16 + c - '0'; + } + else if (c >= 'A' && c <= 'F') + { + result = result * 16 + c - 'A' + 10; + } + else if (c >= 'a' && c <= 'f') + { + result = result * 16 + c - 'a' + 10; + } + } + return result; + } + inline int Parser::ParseInt(std::wstring_view Str, bool forceBase36) { if(forceBase36 || !UseBase62) { auto result = static_cast(std::wcstol(Str.data(), nullptr, 36)); diff --git a/src/Parser.h b/src/Parser.h index ec7d0e3..60fe158 100644 --- a/src/Parser.h +++ b/src/Parser.h @@ -46,11 +46,12 @@ namespace bms_parser int Lnobj = -1; int Lntype = 1; int Seed; - int ParseInt(std::wstring_view Str, bool forceBase32 = false); + inline int ParseHex(std::wstring_view Str); + inline int ParseInt(std::wstring_view Str, bool forceBase32 = false); void ParseHeader(Chart *Chart, std::wstring_view cmd, std::wstring_view Xx, const std::wstring &Value); - bool MatchHeader(const std::wstring_view &str, const std::wstring_view &headerUpper); - static int Gcd(int A, int B); + inline bool MatchHeader(const std::wstring_view &str, const std::wstring_view &headerUpper); + inline int Gcd(int A, int B); inline bool CheckResourceIdRange(int Id); - int ToWaveId(Chart *Chart, std::wstring_view Wav, bool metaOnly); + inline int ToWaveId(Chart *Chart, std::wstring_view Wav, bool metaOnly); }; }