MCPcopy Create free account
hub / github.com/Warzone2100/warzone2100 / snprint

Method snprint

lib/netplay/sync_debug.cpp:226–257  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

224 log.push_back('i');
225 }
226 int snprint(char* buf, size_t bufSize)
227 {
228 SyncDebugString const* stringPtr = strings.empty() ? nullptr : &strings[0]; // .empty() check, since &strings[0] is undefined if strings is empty(), even if it's likely to work, anyway.
229 SyncDebugValueChange const* valueChangePtr = valueChanges.empty() ? nullptr : &valueChanges[0];
230 SyncDebugIntList const* intListPtr = intLists.empty() ? nullptr : &intLists[0];
231 char const* charPtr = chars.empty() ? nullptr : &chars[0];
232 int const* intPtr = ints.empty() ? nullptr : &ints[0];
233
234 int printRes = 0;
235 int index = 0;
236 for (size_t n = 0; n < log.size() && (size_t)index < bufSize; ++n)
237 {
238 char type = log[n];
239 switch (type)
240 {
241 case 's':
242 printRes = stringPtr++->snprint(buf + index, bufSize - index, charPtr);
243 break;
244 case 'v':
245 printRes = valueChangePtr++->snprint(buf + index, bufSize - index);
246 break;
247 case 'i':
248 printRes = intListPtr++->snprint(buf + index, bufSize - index, intPtr);
249 break;
250 default:
251 abort();
252 break;
253 }
254 index += std::max<int>(printRes, 0);
255 }
256 return index;
257 }
258 uint32_t getGameTime() const
259 {
260 return time;

Callers 1

dumpLocalDebugSyncLogFunction · 0.45

Calls 2

emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected