Blame view

emulateur/epsilon-nofrendo/ion/src/blackbox/events.cpp 1.02 KB
6663b6c9   adorian   projet complet av...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
  #include <ion/events.h>
  #include <stdio.h>
  #include <stdlib.h>
  #include "display.h"
  
  namespace Ion {
  namespace Events {
  
  static int sLogAfterNumberOfEvents = -1;
  static int sEventCount = 0;
  
  Event getEvent(int * timeout) {
    Ion::Events::Event event = Ion::Events::None;
    while (!(event.isDefined() && event.isKeyboardEvent())) {
      int c = getchar();
      if (c == EOF) {
        printf("Finished processing %d events\n", sEventCount);
        event = Ion::Events::Termination;
        break;
      }
      event = Ion::Events::Event(c);
    }
    if (sEventCount++ > sLogAfterNumberOfEvents && sLogAfterNumberOfEvents >= 0) {
      char filename[32];
      sprintf(filename, "event%d.png", sEventCount);
      Ion::Display::Blackbox::writeFrameBufferToFile(filename);
  #if DEBUG
      printf("Event %d is %s\n", sEventCount, event.name());
  #endif
    }
    return event;
  }
  
  namespace Blackbox {
  
  void dumpEventCount(int i) {
    printf("Current event index: %d\n", sEventCount);
  }
  
  void logAfter(int numberOfEvents) {
    sLogAfterNumberOfEvents = numberOfEvents;
  }
  
  }
  
  }
  }