9 Application::Application(const Config &config)
12 , init_gl(config.doublebuf, config.multisampling)
14 , ctx(window.CreateContext())
19 , interface(config.interface, world)
20 , test_controller(MakeTestEntity(world))
23 GLContext::EnableVSync();
26 glClearColor(0.0, 0.0, 0.0, 1.0);
29 Entity &Application::MakeTestEntity(World &world) {
30 Entity &e = world.AddEntity();
31 e.Position({ 0.0f, 0.0f, 0.0f });
32 e.SetShape(world.BlockTypes()[1]->shape, { 1.0f, 1.0f, 0.0f });
33 e.AngularVelocity(glm::quat(glm::vec3{ 0.00001f, 0.000006f, 0.000013f }));
38 void Application::RunN(size_t n) {
39 Uint32 last = SDL_GetTicks();
40 for (size_t i = 0; i < n; ++i) {
41 Uint32 now = SDL_GetTicks();
42 int delta = now - last;
48 void Application::RunT(size_t t) {
49 Uint32 last = SDL_GetTicks();
50 Uint32 finish = last + t;
51 while (last < finish) {
52 Uint32 now = SDL_GetTicks();
53 int delta = now - last;
59 void Application::RunS(size_t n, size_t t) {
60 for (size_t i = 0; i < n; ++i) {
66 void Application::Run() {
68 Uint32 last = SDL_GetTicks();
71 Uint32 now = SDL_GetTicks();
72 int delta = now - last;
78 void Application::Loop(int dt) {
85 void Application::HandleEvents() {
87 while (SDL_PollEvent(&event)) {
91 interface.Handle(event.key);
93 case SDL_MOUSEBUTTONDOWN:
94 interface.Handle(event.button);
97 interface.Handle(event.motion);
100 interface.Handle(event.wheel);
105 case SDL_WINDOWEVENT:
106 switch (event.window.event) {
107 case SDL_WINDOWEVENT_FOCUS_GAINED:
110 case SDL_WINDOWEVENT_FOCUS_LOST:
111 window.ReleaseMouse();
113 case SDL_WINDOWEVENT_RESIZED:
114 cam.Viewport(event.window.data1, event.window.data2);
115 interface.Handle(event.window);
118 interface.Handle(event.window);
128 void Application::Update(int dt) {
129 interface.Update(dt);
130 test_controller.Update(dt);
134 void Application::Render() {
139 program.SetProjection(cam.Projection());
140 world.Render(program);
142 interface.Render(program);