X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fapp%2FApplication.cpp;h=490e1675d8b83b25276bde6ddc219eaf59103b84;hb=HEAD;hp=b7983aa0fcc56323e9bc07629cdcf53409c249c5;hpb=e4732374394610bdd3deafd2138cbea267a670e0;p=gworm.git diff --git a/src/app/Application.cpp b/src/app/Application.cpp index b7983aa..490e167 100644 --- a/src/app/Application.cpp +++ b/src/app/Application.cpp @@ -16,6 +16,7 @@ namespace gworm { Application::Application(Canvas &c, World &w) : canvas(c) , world(w) +, worldTex(canvas.CreateStaticTexture(world.Size())) , focus(Vector(250, 250), 25) , cam(c.Size(), focus.Pos()) , last(SDL_GetTicks()) @@ -158,39 +159,13 @@ void Application::RenderBackground() { } void Application::RenderWorld() { - Vector begin(0, 0); - Vector end(world.Size()); - Vector topLeft = cam.ToScreen(Vector(begin)); - Vector bottomRight = cam.ToScreen(Vector(end)); - Vector clip(canvas.Size()); - - if (begin.x > clip.x || begin.y > clip.y || end.x < 0 || end.y < 0) { - return; + if (world.ColorDirty()) { + worldTex.SetColors(world.GetColors()); + world.CleanColor(); } - if (topLeft.x < 0) { - begin.x -= topLeft.x; - topLeft.x = 0; - } - if (topLeft.y < 0) { - begin.y -= topLeft.y; - topLeft.y = 0; - } - if (bottomRight.x > clip.x) { - end.x -= bottomRight.x - clip.x; - bottomRight.x = clip.x; - } - if (bottomRight.y > clip.y) { - end.y -= bottomRight.y - clip.y; - bottomRight.y = clip.y; - } - - for (Vector pos(begin), cur(topLeft); pos.y < end.y; ++pos.y, ++cur.y) { - for (pos.x = begin.x, cur.x = topLeft.x; pos.x < end.x; ++pos.x, ++cur.x) { - canvas.SetColor(world.ColorAt(pos)); - canvas.Dot(cur); - } - } + const Vector pos = cam.ToScreen(Vector(0, 0)); + canvas.Copy(worldTex, pos); } void Application::RenderEntities() {