Index: tests/gamecontroller/GameControllerTests.m ================================================================== --- tests/gamecontroller/GameControllerTests.m +++ tests/gamecontroller/GameControllerTests.m @@ -20,10 +20,11 @@ #include "config.h" #import "OFApplication.h" #import "OFArray.h" #import "OFColor.h" +#import "OFDate.h" #import "OFGameController.h" #import "OFNumber.h" #import "OFSet.h" #import "OFStdIOStream.h" #import "OFThread.h" @@ -58,19 +59,21 @@ # define yellow olive # define gray silver #endif @interface GameControllerTests: OFObject +{ + OFArray OF_GENERIC(OFGameController) *_controllers; + OFDate *_lastControllersUpdate; +} @end OF_APPLICATION_DELEGATE(GameControllerTests) @implementation GameControllerTests - (void)applicationDidFinishLaunching: (OFNotification *)notification { - OFArray *controllers; - #if defined(OF_WII) GXRModeObj *mode; void *nextFB; VIDEO_Init(); @@ -95,25 +98,27 @@ atexit(gfxExit); consoleInit(GFX_TOP, NULL); #endif - controllers = [OFGameController controllers]; - [OFStdOut clear]; for (;;) { void *pool = objc_autoreleasePoolPush(); -#ifdef OF_WII - /* Wii needs some time before controllers are found. */ - controllers = [OFGameController controllers]; -#endif + if (_lastControllersUpdate == nil || + -[_lastControllersUpdate timeIntervalSinceNow] > 1) { + [_controllers release]; + [_lastControllersUpdate release]; + + _controllers = [[OFGameController controllers] retain]; + _lastControllersUpdate = [[OFDate alloc] init]; + } [OFStdOut setCursorPosition: OFMakePoint(0, 0)]; - for (OFGameController *controller in controllers) { + for (OFGameController *controller in _controllers) { OFArray OF_GENERIC(OFGameControllerButton) *buttons = controller.buttons.allObjects.sortedArray; size_t i = 0; [OFStdOut setForegroundColor: [OFColor green]];