X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fapp.cpp;h=7ddbbf189180d43dccd577a91e68a057ef1c8f0f;hb=e70967c971f77a4ac0f5c074e6eb94bdd0e2b7ab;hp=10a72b8e89e698f2abf52164df4bc91a6b164c96;hpb=1a7bbd64b1fef1f4e2f9303f820d6f3ce76cebf1;p=blank.git diff --git a/src/app.cpp b/src/app.cpp index 10a72b8..7ddbbf1 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -31,10 +31,6 @@ Application::Application() , place_id(1) { GLContext::EnableVSync(); - GLuint VertexArrayID; - glGenVertexArrays(1, &VertexArrayID); - glBindVertexArray(VertexArrayID); - world.Generate({ -4, -4, -4 }, { 5, 5, 5}); hud.Viewport(960, 600); @@ -44,6 +40,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(); @@ -118,7 +142,7 @@ void Application::Update(int dt) { glm::vec3 pos = Chunk::ToCoords(blkid); outline_visible = true; outline.Clear(); - chunk->BlockAt(blkid).type->FillOutlineModel(outline); + 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 { @@ -127,14 +151,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; @@ -147,7 +171,7 @@ void Application::Update(int dt) { mod_chunk = &world.Next(*chunk, normal); 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;