X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fapp.cpp;h=0f1277535367ca060caffbcf018dd4a356630623;hb=a58c4558e7d4934f4d0ee621520acfe1c8258c93;hp=21eb85c309830eca5f332d6f5cdd719d1b8da04a;hpb=753be639d7d04f9f7415db9fc2721485c531f0a1;p=blank.git diff --git a/src/app.cpp b/src/app.cpp index 21eb85c..0f12775 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -19,6 +19,7 @@ Application::Application() , cam() , hud() , world() +, controller(world.Player()) , outline() , outline_visible(false) , outline_transform(1.0f) @@ -30,12 +31,6 @@ Application::Application() , place_id(1) { GLContext::EnableVSync(); - GLuint VertexArrayID; - glGenVertexArrays(1, &VertexArrayID); - glBindVertexArray(VertexArrayID); - - world.Generate(); - hud.Viewport(960, 600); hud.Display(*world.BlockTypes()[place_id]); @@ -43,6 +38,34 @@ Application::Application() } +void Application::RunN(size_t n) { + Uint32 last = SDL_GetTicks(); + for (size_t i = 0; i < n; ++i) { + Uint32 now = SDL_GetTicks(); + int delta = now - last; + Loop(delta); + last = now; + } +} + +void Application::RunT(size_t t) { + Uint32 last = SDL_GetTicks(); + Uint32 finish = last + t; + while (last < finish) { + Uint32 now = SDL_GetTicks(); + int delta = now - last; + Loop(delta); + last = now; + } +} + +void Application::RunS(size_t n, size_t t) { + for (size_t i = 0; i < n; ++i) { + Loop(t); + } +} + + void Application::Run() { running = true; Uint32 last = SDL_GetTicks(); @@ -68,7 +91,7 @@ void Application::HandleEvents() { switch (event.type) { case SDL_KEYDOWN: case SDL_KEYUP: - world.Controller().HandleKeyboard(event.key); + controller.HandleKeyboard(event.key); break; case SDL_MOUSEBUTTONDOWN: if (event.button.button == 1) { @@ -83,7 +106,7 @@ void Application::HandleEvents() { } break; case SDL_MOUSEMOTION: - world.Controller().HandleMouse(event.motion); + controller.HandleMouse(event.motion); break; case SDL_QUIT: running = false; @@ -105,9 +128,10 @@ void Application::HandleEvents() { } void Application::Update(int dt) { + controller.Update(dt); world.Update(dt); - Ray aim = world.Controller().Aim(); + Ray aim = controller.Aim(); Chunk *chunk; int blkid; float dist; @@ -116,8 +140,8 @@ void Application::Update(int dt) { glm::vec3 pos = Chunk::ToCoords(blkid); outline_visible = true; outline.Clear(); - chunk->BlockAt(blkid).type->FillOutlineModel(outline); - outline_transform = glm::translate(chunk->Transform(), pos); + chunk->Type(chunk->BlockAt(blkid)).FillOutlineModel(outline); + outline_transform = glm::translate(chunk->Transform(world.Player().ChunkCoords()), pos); outline_transform = glm::scale(outline_transform, glm::vec3(1.0001f)); } else { outline_visible = false; @@ -125,14 +149,14 @@ void Application::Update(int dt) { if (pick) { if (chunk) { - place_id = chunk->BlockAt(blkid).type->id; + place_id = chunk->BlockAt(blkid).type; hud.Display(*world.BlockTypes()[place_id]); } pick = false; } if (remove) { if (chunk) { - chunk->BlockAt(blkid).type = world.BlockTypes()[remove_id]; + chunk->BlockAt(blkid).type = remove_id; chunk->Invalidate(); } remove = false; @@ -143,9 +167,9 @@ void Application::Update(int dt) { glm::vec3 next_pos = Chunk::ToCoords(blkid) + normal; if (!Chunk::InBounds(next_pos)) { mod_chunk = &world.Next(*chunk, normal); - next_pos -= normal * Chunk::Extent(); + next_pos -= normal * glm::vec3(Chunk::Extent()); } - mod_chunk->BlockAt(next_pos).type = world.BlockTypes()[place_id]; + mod_chunk->BlockAt(next_pos).type = place_id; mod_chunk->Invalidate(); } place = false;