1 module demos.sandbox; 2 3 import bindbc.sdl; 4 5 import bubel.ecs.core; 6 7 import demos.simple; 8 import demos.snake; 9 import demos.space_invaders; 10 import demos.particles; 11 import demos.brick_breaker; 12 13 import game_core.rendering; 14 15 import app; 16 17 import ecs_utils.math.vector; 18 19 extern(C): 20 21 void sandboxStart() 22 { 23 simpleRegister(); 24 snakeRegister(); 25 spaceInvadersRegister(); 26 particlesRegister(); 27 brickBreakerRegister(); 28 29 simpleStart(); 30 snakeStart(); 31 spaceInvadersStart(); 32 particlesStart(); 33 brickBreakerStart(); 34 35 DrawSystem* draw_system = gEntityManager.getSystem!DrawSystem; 36 draw_system.default_data.size = vec2(16,16); 37 draw_system.default_data.coords = vec4(0,48,16,16)*demos.simple.px; 38 draw_system.default_data.material_id = 0; 39 draw_system.default_data.texture = particles_demo.texture; 40 draw_system.default_data.color = 0x80808080; 41 42 gEntityManager.getSystem(becsID!MouseAttractSystem).disable(); 43 gEntityManager.getSystem(becsID!(demos.simple.MoveSystem)).disable(); 44 45 } 46 47 void sandboxEnd() 48 { 49 simpleEnd(); 50 snakeEnd(); 51 spaceInvadersEnd(); 52 particlesEnd(); 53 } 54 /* 55 void sandboxEvent(SDL_Event* event) 56 { 57 }*/ 58 59 bool sandboxLoop() 60 { 61 launcher.render_position = (vec2(launcher.window_size.x,launcher.window_size.y)*launcher.scalling - vec2(400,300)) * 0.5; 62 63 gEntityManager.begin(); 64 65 float delta_time = launcher.delta_time; 66 if(delta_time > 2000)delta_time = 2000; 67 __gshared float time = 0; 68 69 /*if(launcher.getKeyState(SDL_SCANCODE_SPACE))time += delta_time * 3; 70 else */ 71 time += delta_time; 72 73 while(time > 200) 74 { 75 time -= 200; 76 77 gEntityManager.update("fixed"); 78 } 79 80 if(launcher.multithreading) 81 { 82 launcher.job_updater.begin(); 83 gEntityManager.updateMT(); 84 launcher.job_updater.call(); 85 } 86 else 87 { 88 gEntityManager.update(); 89 } 90 gEntityManager.end(); 91 92 return true; 93 } 94 95 DemoCallbacks getSanboxDemo() 96 { 97 DemoCallbacks demo; 98 demo.initialize = &sandboxStart; 99 demo.deinitialize = &sandboxEnd; 100 demo.loop = &sandboxLoop; 101 demo.tips = "This demo contains all components, systems and events from previous demos. They was not designed for that kind of coexisting. Some system collide with other making some weird things. 102 This gives biggest opportunities. You can add tower on top of snake, or lasers to paddle from BrickBreaker. This will be improved in next versions of ECS demo."; 103 return demo; 104 }