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)) {
91 interface.HandlePress(event.key);
94 interface.HandleRelease(event.key);
96 case SDL_MOUSEBUTTONDOWN:
97 interface.HandlePress(event.button);
99 case SDL_MOUSEBUTTONUP:
100 interface.HandleRelease(event.button);
102 case SDL_MOUSEMOTION:
103 interface.Handle(event.motion);
106 interface.Handle(event.wheel);
111 case SDL_WINDOWEVENT:
112 switch (event.window.event) {
113 case SDL_WINDOWEVENT_FOCUS_GAINED:
116 case SDL_WINDOWEVENT_FOCUS_LOST:
117 window.ReleaseMouse();
119 case SDL_WINDOWEVENT_RESIZED:
120 cam.Viewport(event.window.data1, event.window.data2);
121 interface.Handle(event.window);
124 interface.Handle(event.window);
134 void Application::Update(int dt) {
135 interface.Update(dt);
136 test_controller.Update(dt);
140 void Application::Render() {
143 chunk_prog.SetProjection(cam.Projection());
144 entity_prog.SetProjection(cam.Projection());
146 world.Render(chunk_prog, entity_prog);
148 interface.Render(entity_prog);