1 module isodi.raylib.tests; 2 3 import raylib; 4 import core.runtime; 5 6 import isodi.tests; 7 import isodi.raylib.camera; 8 import isodi.raylib.display; 9 10 11 @system: // This module is all system, no memory safety for us damned 12 13 14 version (unittest): 15 16 shared static this() { 17 18 // Redirect to our main 19 Runtime.extendedModuleUnitTester = { 20 21 UnitTestResult result = { 22 runMain: true 23 }; 24 25 return result; 26 27 }; 28 29 } 30 31 void main() { 32 33 // Restore original test runner 34 Runtime.extendedModuleUnitTester = null; 35 36 // Create the window 37 SetTraceLogLevel(TraceLogLevel.LOG_WARNING); 38 SetConfigFlags(ConfigFlags.FLAG_WINDOW_RESIZABLE); 39 InitWindow(1600, 900, "unittest"); 40 SetWindowMinSize(800, 600); 41 SetTargetFPS(60); 42 scope(exit) CloseWindow(); 43 44 // Set camera keybinds 45 // Too bad with() changes scope 46 const CameraKeybindings keybinds = { 47 48 zoomIn: KeyboardKey.KEY_EQUAL, 49 zoomOut: KeyboardKey.KEY_MINUS, 50 51 rotateLeft: KeyboardKey.KEY_Q, 52 rotateRight: KeyboardKey.KEY_E, 53 rotateUp: KeyboardKey.KEY_R, 54 rotateDown: KeyboardKey.KEY_F, 55 56 moveLeft: KeyboardKey.KEY_A, 57 moveRight: KeyboardKey.KEY_D, 58 moveDown: KeyboardKey.KEY_S, 59 moveUp: KeyboardKey.KEY_W, 60 moveBelow: KeyboardKey.KEY_PAGE_DOWN, 61 moveAbove: KeyboardKey.KEY_PAGE_UP, 62 63 }; 64 65 // Create a test runner 66 TestRunner runner; 67 runner.runTests(); 68 69 // Prepre the display for the next test 70 void prepare() { 71 72 // Add a camera 73 auto camAnchor = runner.display.addAnchor; 74 runner.display.camera.follow = camAnchor; 75 76 } 77 78 // Run the tests 79 loop: while (true) { 80 81 // Requested closing the window 82 if (WindowShouldClose) { 83 84 // Abort tests 85 runner.abortTests(); 86 break; 87 88 } 89 90 BeginDrawing(); 91 scope (exit) EndDrawing(); 92 93 import std.string : toStringz; 94 95 ClearBackground(Colors.WHITE); 96 97 with (TestRunner.Status) 98 final switch (runner.status) { 99 100 // Idle 101 case idle: 102 103 // Order next task 104 runner.nextTest(); 105 prepare(); 106 break; 107 108 // Paused 109 case paused: 110 111 // If pressing enter or space 112 if (IsKeyPressed(KeyboardKey.KEY_SPACE) || IsKeyPressed(KeyboardKey.KEY_ENTER)) { 113 114 // Continue to next task 115 runner.nextTest(); 116 prepare(); 117 118 } 119 120 break; 121 122 // Finished 123 case finished: 124 125 // Stop the program 126 break loop; 127 128 // Working, let it do its job 129 case working: break; 130 131 } 132 133 auto display = cast(RaylibDisplay) runner.display; 134 135 // Draw the frame 136 display.camera.updateCamera(keybinds); 137 display.draw(); 138 139 // Output status message 140 DrawText(runner.statusMessage.toStringz, 10, 10, 20, Colors.BLACK); 141 DrawFPS(10, GetScreenHeight - 20); 142 143 } 144 145 }