#include "../graphics/Canvas.h"
#include "../graphics/Color.h"
+#include "../world/Entity.h"
#include "../world/World.h"
#include <chrono>
Application::Application(Canvas &c, World &w)
: canvas(c)
, world(w)
-, focus(Vector<float>(5, 5), 25)
+, focus(Vector<float>(250, 250), 25)
, cam(c.Size(), focus.Pos())
, last(SDL_GetTicks())
, running(false)
void Application::Loop(int delta) {
cout << "delta: " << delta << endl << endl;
+ auto enter = chrono::system_clock::now();
+
HandleEvents();
+ auto event = chrono::system_clock::now();
+ cout << " event: " << duration_cast<milliseconds>(event - enter).count() << endl;
+
if (delta == 0) {
SDL_Delay(1);
return;
}
+ auto update = event;
if (!paused) {
Update(delta);
+ update = chrono::system_clock::now();
+ cout << " update: " << duration_cast<milliseconds>(update - event).count() << endl;
}
+
Render();
+ auto render = chrono::system_clock::now();
+ cout << " render: " << duration_cast<milliseconds>(render - update).count() << endl;
+
canvas.Present();
}
void Application::Render() {
- auto enter = chrono::system_clock::now();
RenderBackground();
- auto background = chrono::system_clock::now();
- cout << " background: " << duration_cast<milliseconds>(background - enter).count() << endl;
RenderWorld();
- auto world = chrono::system_clock::now();
- cout << " world: " << duration_cast<milliseconds>(world - background).count() << endl;
RenderEntities();
- auto entities = chrono::system_clock::now();
- cout << " entities: " << duration_cast<milliseconds>(entities - world).count() << endl;
RenderUI();
- auto ui = chrono::system_clock::now();
- cout << " UI: " << duration_cast<milliseconds>(ui - entities).count() << endl;
}
void Application::RenderBackground() {
}
void Application::RenderEntities() {
+ constexpr Color entityColor(0x00, 0xFA, 0x00);
+ canvas.SetColor(entityColor);
+ for (const Entity &e : world.Entities()) {
+ canvas.Cross(cam.ToScreen(e.pos), 10);
+ }
}
void Application::RenderUI() {
constexpr Color focusColor(0xFA, 0xFA, 0x00);
constexpr Color forceColor(0xFA, 0x00, 0x00);
+ constexpr Color speedColor(0x00, 0xFA, 0x00);
canvas.SetColor(focusColor);
canvas.Cross(cam.ToScreen(focus.Pos()), 15);
- const Vector<float> force = world.ForceAt(focus.Pos(), 1);
- const Vector<int> screenFocus = cam.ToScreen(focus.Pos());
+ for (const Entity &e : world.Entities()) {
+ const Vector<int> screenPos = cam.ToScreen(e.pos);
+
+ canvas.SetColor(forceColor);
+ canvas.Arrow(screenPos, screenPos + Vector<int>(e.acc * e.mass * 10.0f));
- canvas.SetColor(forceColor);
- canvas.Arrow(screenFocus, screenFocus + Vector<int>(force * 10.0f));
- cout << "force on 1kg at " << focus.Pos() << ": " << force << endl;
+ canvas.SetColor(speedColor);
+ canvas.Arrow(screenPos, screenPos + Vector<int>(e.vel * 10.0f));
+
+ cout << "entity: pos " << e.pos << ", vel " << e.vel << ", acc " << e.acc << endl;
+ }
}
}