MCPcopy Create free account
hub / github.com/crownengine/crown / queue_request

Method queue_request

src/device/save_game.cpp:273–347  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

271 }
272
273 u32 queue_request(SaveGame::Request::Type type
274 , const char *filename
275 , const void *data
276 , u32 size
277 )
278 {
279 CE_ENSURE(type == SaveGame::Request::LOAD || data != NULL || size == 0);
280
281 for (u32 ii = 0; ii < countof(_requests); ++ii) {
282 SaveGame::Request &rr = _requests[ii];
283 if (rr.token == 0) {
284 rr.type = type;
285 rr.token = ++_next_token;
286 if (rr.token == 0)
287 rr.token = ++_next_token;
288 rr.done.store(true);
289 rr.error.store(SaveError::SUCCESS);
290 rr.progress.store(0.0f);
291 rr.basename[0] = '\0';
292 _allocator->deallocate(rr.data);
293 rr.data = NULL;
294 rr.size = 0;
295
296 if (filename == NULL
297 || !path::is_valid_basename(filename)
298 || strlen32(filename) >= sizeof(SaveGame::Request::basename)
299 ) {
300 loge(SAVE_GAME, "Invalid savegame filename: '%s'", filename ? filename : "<null>");
301 rr.progress.store(1.0f);
302 rr.error.store(SaveError::INVALID_FILENAME);
303 return rr.token;
304 }
305
306 strcpy(rr.basename, filename);
307
308 if (!_has_save_dir) {
309 rr.progress.store(1.0f);
310 rr.error.store(SaveError::SAVE_DIR_UNSET);
311 return rr.token;
312 }
313
314 if (type == SaveGame::Request::SAVE && data == NULL && size > 0) {
315 loge(SAVE_GAME, "Invalid savegame data");
316 rr.progress.store(1.0f);
317 rr.error.store(SaveError::UNKNOWN);
318 return rr.token;
319 }
320
321 if (size > 0) {
322 rr.data = _allocator->allocate(size);
323 memcpy(rr.data, data, size);
324 rr.size = size;
325 }
326
327 rr.done.store(false);
328
329 _mutex.lock();
330 const bool queued = _requests_queue.push(ii);

Callers 2

loadFunction · 0.80
saveFunction · 0.80

Calls 10

is_valid_basenameFunction · 0.85
strcpyFunction · 0.85
memcpyFunction · 0.85
signalMethod · 0.80
storeMethod · 0.45
deallocateMethod · 0.45
allocateMethod · 0.45
lockMethod · 0.45
pushMethod · 0.45
unlockMethod · 0.45

Tested by

no test coverage detected