X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fapp%2FApplication.cpp;h=490e1675d8b83b25276bde6ddc219eaf59103b84;hb=HEAD;hp=d798b37c757f89b75aab6b41a524ed727caaa076;hpb=3694504331ca888f2cacbcb841a83c402d26934a;p=gworm.git diff --git a/src/app/Application.cpp b/src/app/Application.cpp index d798b37..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() { @@ -220,6 +195,7 @@ void Application::RenderUI() { canvas.Arrow(screenPos, screenPos + Vector(e.vel * 10.0f)); cout << "entity: pos " << e.pos << ", vel " << e.vel << ", acc " << e.acc << endl; + cout << " vel mag: " << Length(e.vel) << ", acc mag: " << Length(e.acc) << endl; } }