9 Application::Application()
14 , ctx(window.CreateContext())
20 , test_controller(MakeTestEntity(world))
22 GLContext::EnableVSync();
24 glClearColor(0.0, 0.0, 0.0, 1.0);
27 Entity &Application::MakeTestEntity(World &world) {
28 Entity &e = world.AddEntity();
29 e.Position({ 0.0f, 0.0f, 0.0f });
30 e.SetShape(world.BlockTypes()[1]->shape, { 1.0f, 1.0f, 0.0f });
31 e.AngularVelocity(glm::quat(glm::vec3{ 0.00001f, 0.000006f, 0.000013f }));
36 void Application::RunN(size_t n) {
37 Uint32 last = SDL_GetTicks();
38 for (size_t i = 0; i < n; ++i) {
39 Uint32 now = SDL_GetTicks();
40 int delta = now - last;
46 void Application::RunT(size_t t) {
47 Uint32 last = SDL_GetTicks();
48 Uint32 finish = last + t;
49 while (last < finish) {
50 Uint32 now = SDL_GetTicks();
51 int delta = now - last;
57 void Application::RunS(size_t n, size_t t) {
58 for (size_t i = 0; i < n; ++i) {
64 void Application::Run() {
66 Uint32 last = SDL_GetTicks();
69 Uint32 now = SDL_GetTicks();
70 int delta = now - last;
76 void Application::Loop(int dt) {
83 void Application::HandleEvents() {
85 while (SDL_PollEvent(&event)) {
89 interface.Handle(event.key);
91 case SDL_MOUSEBUTTONDOWN:
92 interface.Handle(event.button);
95 interface.Handle(event.motion);
98 interface.Handle(event.wheel);
103 case SDL_WINDOWEVENT:
104 switch (event.window.event) {
105 case SDL_WINDOWEVENT_FOCUS_GAINED:
108 case SDL_WINDOWEVENT_FOCUS_LOST:
109 window.ReleaseMouse();
111 case SDL_WINDOWEVENT_RESIZED:
112 cam.Viewport(event.window.data1, event.window.data2);
113 interface.Handle(event.window);
116 interface.Handle(event.window);
126 void Application::Update(int dt) {
127 interface.Update(dt);
128 test_controller.Update(dt);
132 void Application::Render() {
137 program.SetProjection(cam.Projection());
138 world.Render(program);
140 interface.Render(program);