MCPcopy Create free account
hub / github.com/OpenApoc/OpenApoc / processEvents

Method processEvents

framework/framework.cpp:418–501  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

416}
417
418void Framework::processEvents()
419{
420 if (p->ProgramStages.isEmpty())
421 {
422 p->quitProgram = true;
423 return;
424 }
425
426 // TODO: Consider threading the translation
427 translateSdlEvents();
428
429 while (p->eventQueue.size() > 0 && !p->ProgramStages.isEmpty())
430 {
431 up<Event> e;
432 {
433 std::lock_guard<std::mutex> l(p->eventQueueLock);
434 e = std::move(p->eventQueue.front());
435 p->eventQueue.pop_front();
436 }
437 if (!e)
438 {
439 LogError("Invalid event on queue");
440 continue;
441 }
442 this->cursor->eventOccured(e.get());
443 if (e->type() == EVENT_KEY_DOWN)
444 {
445 if (e->keyboard().KeyCode == SDLK_PRINTSCREEN)
446 {
447 int screenshotId = 0;
448 UString screenshotName;
449 do
450 {
451 screenshotName = format("screenshot%03d.png", screenshotId);
452 screenshotId++;
453 } while (fs::exists(fs::path(screenshotName)));
454 LogWarning("Writing screenshot to \"%s\"", screenshotName);
455 if (!p->defaultSurface->rendererPrivateData)
456 {
457 LogWarning("No renderer data on surface - nothing drawn yet?");
458 }
459 else
460 {
461 auto img = p->defaultSurface->rendererPrivateData->readBack();
462 if (!img)
463 {
464 LogWarning("No image returned");
465 }
466 else
467 {
468 this->threadPoolTaskEnqueue(
469 [img, screenshotName]
470 {
471 auto ret = fw().data->writeImage(screenshotName, img);
472 if (!ret)
473 {
474 LogWarning("Failed to write screenshot");
475 }

Callers

nothing calls this directly

Calls 12

threadPoolTaskEnqueueMethod · 0.95
formatFunction · 0.85
typeMethod · 0.80
currentMethod · 0.80
isEmptyMethod · 0.45
sizeMethod · 0.45
eventOccuredMethod · 0.45
getMethod · 0.45
readBackMethod · 0.45
writeImageMethod · 0.45
eventOccurredMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected