Skip to content

Commit

Permalink
Improvements
Browse files Browse the repository at this point in the history
* allow background events for joysticks when using window events
* add perf instrumentation for ginput_periodic_task in ginput_test
  • Loading branch information
matlo committed Jan 27, 2020
1 parent 39dcc46 commit d8f150b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/sdl/sdlinput.c
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,9 @@ static int sdlinput_mkb_init(const GPOLL_INTERFACE * poll_interface __attribute_
if (SDL_GetHint(SDL_HINT_TIMER_RESOLUTION) == NULL) {
SDL_SetHint(SDL_HINT_TIMER_RESOLUTION, "0");
}
if (SDL_GetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS) == NULL) {
SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1");
}
if (SDL_Init(0) < 0) {
PRINT_ERROR_SDL("SDL_Init");
return -1;
Expand Down
36 changes: 34 additions & 2 deletions test/ginput_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,21 @@
#include <gimxcommon/test/input.c>
#include <gimxcommon/test/timer.c>

#include <gimxcommon/include/gperf.h>

#define SAMPLETYPE \
struct { \
gtime now; \
gtime delta; \
}

#define NBSAMPLES 2500 // 10s with a period of 4ms

#define SAMPLEPRINT(SAMPLE) \
printf("now = "GTIME_FS" delta = "GTIME_FS"\n", SAMPLE.now, SAMPLE.delta)

static GPERF_INST(ginput_test, SAMPLETYPE, NBSAMPLES);

#define PERIOD 10000//microseconds

int mkb_select() {
Expand Down Expand Up @@ -60,14 +75,15 @@ static unsigned int periods = 0;
static int quiet = 0;
static int debug = 0;
static int prio = 0;
static int perf = 0;

/*
* Reads command-line arguments.
*/
static int read_args(int argc, char* argv[]) {

int opt;
while ((opt = getopt(argc, argv, "dn:pq")) != -1) {
while ((opt = getopt(argc, argv, "dn:pqs")) != -1) {
switch (opt) {
case 'd':
debug = 1;
Expand All @@ -81,6 +97,9 @@ static int read_args(int argc, char* argv[]) {
case 'q':
quiet = 1;
break;
case 's':
perf = 1;
break;
default: /* '?' */
usage();
break;
Expand Down Expand Up @@ -138,12 +157,20 @@ int main(int argc __attribute__((unused)), char* argv[] __attribute__((unused)))
exit(-1);
}

while(!is_done())
while(!is_done() && gperf_ginput_test.count != NBSAMPLES)
{
gpoll();

if (perf) {
GPERF_START(ginput_test);
}

ginput_periodic_task();

if (perf) {
GPERF_END(ginput_test);
}

//do something periodically

if (periods > 0) {
Expand All @@ -167,5 +194,10 @@ int main(int argc __attribute__((unused)), char* argv[] __attribute__((unused)))

printf("Exiting\n");

if (perf) {
GPERF_SAMPLE_PRINT(ginput_test, SAMPLEPRINT);
GPERF_LOG(ginput_test);
}

return 0;
}

0 comments on commit d8f150b

Please sign in to comment.