Skip to content

Commit

Permalink
fixups1
Browse files Browse the repository at this point in the history
  • Loading branch information
ohlidalp committed Oct 16, 2022
1 parent fa32d50 commit 990ed2e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
7 changes: 5 additions & 2 deletions source/main/resources/tobj_fileformat/TObjFileFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ bool TObjEntry::IsActor() const
void TObjDocument::Load(Ogre::DataStreamPtr datastream, BitMask_t options)
{
// Tokenize
Document::Load(datastream, Document::OPTION_ALLOW_NAKED_STRINGS);
Document::Load(datastream, Document::OPTION_ALLOW_NAKED_STRINGS | Document::OPTION_ALLOW_SLASH_COMMENTS);

TObjReader reader(*this);
reader.Read();
Expand All @@ -64,11 +64,14 @@ void TObjReader::Read()
bool end_requested = false;
while (!this->EndOfFile())
{
m_cur_line_keyword = nullptr;
if (this->GetType() == TokenType::KEYWORD)
{
m_cur_line_keyword = this->GetArgKeyword();
}
else
{
m_cur_line_keyword = "";
}
end_requested = !this->ProcessCurrentLine();
this->SeekNextLine();
}
Expand Down
6 changes: 3 additions & 3 deletions source/main/utils/GenericFileFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ using namespace Ogre;

static void BeginToken(Document& doc, BitMask_t options, std::vector<char>& tok, RoR::TokenType& tok_type, bool& tok_number_dot, Ogre::DataStreamPtr datastream, size_t line_num, char c)
{
if (c == ';')
if (c == ';' || (c == '/' && (options & Document::OPTION_ALLOW_SLASH_COMMENTS)))
{
if (doc.tokens.size() == 0 || doc.tokens.back().type == TokenType::LINEBREAK)
tok_type = TokenType::COMMENT;
Expand Down Expand Up @@ -379,7 +379,7 @@ bool Reader::SeekNextLine()
this->MoveNext();

// Skip comments
while (!this->IsArgString() && !this->IsArgFloat() && !this->IsArgBool() && !this->GetArgKeyword())
while (!this->IsArgString() && !this->IsArgFloat() && !this->IsArgBool() && !this->IsArgKeyword())
{
this->MoveNext();
}
Expand All @@ -390,7 +390,7 @@ bool Reader::SeekNextLine()
size_t Reader::CountLineArgs()
{
size_t count = 0;
while (this->GetType(count) != TokenType::LINEBREAK)
while (!EndOfFile(count) && this->GetType(count) != TokenType::LINEBREAK)
count++;
return count;
}
Expand Down
11 changes: 6 additions & 5 deletions source/main/utils/GenericFileFormat.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ struct Token
struct Document
{
static const BitMask_t OPTION_ALLOW_NAKED_STRINGS = BITMASK(1); //!< Allow strings without quotes, for backwards compatibility.
static const BitMask_t OPTION_ALLOW_SLASH_COMMENTS = BITMASK(2); //!< Allow comments starting with `//`.

virtual ~Document() {};

Expand All @@ -84,17 +85,17 @@ struct Reader

TokenType GetType(size_t offset = 0) const { return !EndOfFile(offset) ? doc.tokens[token_pos].type : TokenType::NONE; }
const char* GetStringData(size_t offset = 0) const { return !EndOfFile(offset) ? (doc.string_pool.data() + (size_t)doc.tokens[token_pos + offset].data) : nullptr; }
float GetFloatData(size_t offset = 0) const { return !EndOfFile(offset) ? doc.tokens[token_pos].data : 0.f; }
float GetFloatData(size_t offset = 0) const { return !EndOfFile(offset) ? doc.tokens[token_pos + offset].data : 0.f; }

const char* GetArgString(size_t offset = 0) const { ROR_ASSERT(IsArgString(offset)); return GetStringData(offset); }
float GetArgFloat(size_t offset = 0) const { ROR_ASSERT(IsArgFloat(offset)); return GetFloatData(offset); }
bool GetArgBool(size_t offset = 0) const { ROR_ASSERT(IsArgBool(offset)); return GetFloatData(offset) == 1.f; }
const char* GetArgKeyword(size_t offset = 0) const { ROR_ASSERT(IsArgKeyword(offset)); return GetStringData(offset); }

bool IsArgString(size_t offset = 0) const { return GetType() == TokenType::STRING; };
bool IsArgFloat(size_t offset = 0) const { return GetType() == TokenType::NUMBER; };
bool IsArgBool(size_t offset = 0) const { return GetType() == TokenType::BOOL; };
bool IsArgKeyword(size_t offset = 0) const { return GetType() == TokenType::KEYWORD; };
bool IsArgString(size_t offset = 0) const { return GetType(offset) == TokenType::STRING; };
bool IsArgFloat(size_t offset = 0) const { return GetType(offset) == TokenType::NUMBER; };
bool IsArgBool(size_t offset = 0) const { return GetType(offset) == TokenType::BOOL; };
bool IsArgKeyword(size_t offset = 0) const { return GetType(offset) == TokenType::KEYWORD; };

};

Expand Down

0 comments on commit 990ed2e

Please sign in to comment.