9 Application::Application(const Config &config)
12 , init_gl(config.doublebuf, config.multisampling)
14 , ctx(window.CreateContext())
20 , interface(config.interface, world)
21 , test_controller(MakeTestEntity(world))
24 GLContext::EnableVSync();
27 glClearColor(0.0, 0.0, 0.0, 1.0);
30 Entity &Application::MakeTestEntity(World &world) {
31 Entity &e = world.AddEntity();
32 e.Position({ 0.0f, 0.0f, 0.0f });
33 e.SetShape(world.BlockTypes()[1]->shape, { 1.0f, 1.0f, 0.0f });
34 e.AngularVelocity(glm::quat(glm::vec3{ 0.00001f, 0.000006f, 0.000013f }));
39 void Application::RunN(size_t n) {
40 Uint32 last = SDL_GetTicks();
41 for (size_t i = 0; i < n; ++i) {
42 Uint32 now = SDL_GetTicks();
43 int delta = now - last;
49 void Application::RunT(size_t t) {
50 Uint32 last = SDL_GetTicks();
51 Uint32 finish = last + t;
52 while (last < finish) {
53 Uint32 now = SDL_GetTicks();
54 int delta = now - last;
60 void Application::RunS(size_t n, size_t t) {
61 for (size_t i = 0; i < n; ++i) {
67 void Application::Run() {
69 Uint32 last = SDL_GetTicks();
72 Uint32 now = SDL_GetTicks();
73 int delta = now - last;
79 void Application::Loop(int dt) {
86 void Application::HandleEvents() {
88 while (SDL_PollEvent(&event)) {
92 interface.Handle(event.key);
94 case SDL_MOUSEBUTTONDOWN:
95 interface.Handle(event.button);
98 interface.Handle(event.motion);
101 interface.Handle(event.wheel);
106 case SDL_WINDOWEVENT:
107 switch (event.window.event) {
108 case SDL_WINDOWEVENT_FOCUS_GAINED:
111 case SDL_WINDOWEVENT_FOCUS_LOST:
112 window.ReleaseMouse();
114 case SDL_WINDOWEVENT_RESIZED:
115 cam.Viewport(event.window.data1, event.window.data2);
116 interface.Handle(event.window);
119 interface.Handle(event.window);
129 void Application::Update(int dt) {
130 interface.Update(dt);
131 test_controller.Update(dt);
135 void Application::Render() {
138 chunk_prog.SetProjection(cam.Projection());
139 entity_prog.SetProjection(cam.Projection());
141 world.Render(chunk_prog, entity_prog);
143 interface.Render(entity_prog);