MCPcopy Create free account
hub / github.com/TheForceEngine/TheForceEngine / load

Function load

TheForceEngine/TFE_Asset/gameMessages.cpp:20–58  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18 static std::vector<char> s_buffer;
19
20 bool load()
21 {
22 if (s_loaded) { return true; }
23
24 if (TFE_AssetSystem::readAssetFromArchive(c_defaultGob, ARCHIVE_GOB, "TEXT.MSG", s_buffer))
25 {
26 TFE_Parser parser;
27 size_t len = s_buffer.size();
28 parser.init(s_buffer.data(), len);
29 parser.addCommentString("//");
30 parser.addCommentString("#");
31 parser.enableBlockComments();
32
33 size_t bufferPos = 0;
34 while (bufferPos < len)
35 {
36 const char* line = parser.readLine(bufferPos);
37 if (!line) { break; }
38
39 TokenList tokens;
40 parser.tokenizeLine(line, tokens);
41 if (tokens.size() < 3) { continue; }
42
43 // Skip until the first token is a number.
44 const char* idStr = tokens[0].c_str();
45 if (idStr[0] < '0' || idStr[0] > '9') { continue; }
46
47 // Finally read the line.
48 char* endPtr = nullptr;
49 u32 id = strtoul(idStr, &endPtr, 10);
50 u32 internal = strtoul(tokens[1].c_str(), &endPtr, 10);
51
52 // And then add the message.
53 s_msgMap[id] = tokens[2];
54 };
55 return true;
56 }
57 return false;
58 }
59
60 void unload()
61 {

Callers 1

getMessageFunction · 0.70

Calls 9

readAssetFromArchiveFunction · 0.85
dataMethod · 0.80
addCommentStringMethod · 0.80
enableBlockCommentsMethod · 0.80
readLineMethod · 0.80
tokenizeLineMethod · 0.80
c_strMethod · 0.80
sizeMethod · 0.45
initMethod · 0.45

Tested by

no test coverage detected