From 600f0bc9f831b5832e6245e6987f20fe8564ec70 Mon Sep 17 00:00:00 2001 From: Tangent Date: Fri, 25 Oct 2019 20:46:06 -0700 Subject: [PATCH] theory --- src/generators/MapDisplay.moon | 34 ++++++++++++ src/main.moon | 9 +++- src/systems/{ => disabled}/MapDisplay.moon | 0 src/systems/disabled/MapDisplayManager.moon | 59 +++++++++++++++++++++ 4 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 src/generators/MapDisplay.moon rename src/systems/{ => disabled}/MapDisplay.moon (100%) create mode 100644 src/systems/disabled/MapDisplayManager.moon diff --git a/src/generators/MapDisplay.moon b/src/generators/MapDisplay.moon new file mode 100644 index 0000000..d05e2c3 --- /dev/null +++ b/src/generators/MapDisplay.moon @@ -0,0 +1,34 @@ +import graphics from love +import cos, sin from math + +w, h = graphics.getDimensions! + +tiny = require "tiny" +IDTracker = require "systems/IDTracker" + +MapDisplay = (system_id) -> + return tiny.sortedSystem { + compare: (a, b) => + if a.orbit and b.orbit + a.orbit.hierarchy <= b.orbit.hierarchy + else + true + filter: tiny.requireAny "orbit", tiny.requireAll("x", "y", system_id) + draw: (t) => + graphics.translate w / 2, h / 2 + for entity in *@entities + if orbit = entity.orbit + orbit = entity.orbit + -- orbital period + -- real: T = 2pi * sqrt(a^3 / G*M) + -- sim: T = 2pi * speed_parameter + entity.x = orbit.radius * cos(t / orbit.speed_parameter) + orbit.offset + entity.y = orbit.radius * sin(t / orbit.speed_parameter) + orbit.offset + if orbit.parent_id + parent = IDTracker[orbit.parent_id] + entity.x += parent.x + entity.y += parent.y + graphics.circle "fill", entity.x, entity.y, 5 -- TEMP radius + } + +return MapDisplay diff --git a/src/main.moon b/src/main.moon index 7e4dc6b..ce4b099 100644 --- a/src/main.moon +++ b/src/main.moon @@ -1,4 +1,5 @@ tiny = require "tiny" +MapDisplay = require "generators/MapDisplay" systems = {} for name in *love.filesystem.getDirectoryItems "systems" @@ -17,11 +18,14 @@ makeEntity = (tab) -> return tab world = tiny.world game, unpack systems +local map system = -> + system_id = "someuuidthing" sun = makeEntity { x: 0, y: 0 + [system_id]: true } planet = makeEntity { orbit: { @@ -31,8 +35,11 @@ system = -> offset: love.math.random! speed_parameter: 0.5 } + [system_id]: true } + map = MapDisplay system_id world\add sun, planet + world\add map system! @@ -40,7 +47,7 @@ love.update = (dt) -> world\update dt love.draw = -> - systems.MapDisplay\draw game.time + map\draw game.time love.keypressed = (key) -> if key == "escape" love.event.quit! diff --git a/src/systems/MapDisplay.moon b/src/systems/disabled/MapDisplay.moon similarity index 100% rename from src/systems/MapDisplay.moon rename to src/systems/disabled/MapDisplay.moon diff --git a/src/systems/disabled/MapDisplayManager.moon b/src/systems/disabled/MapDisplayManager.moon new file mode 100644 index 0000000..d7f82fc --- /dev/null +++ b/src/systems/disabled/MapDisplayManager.moon @@ -0,0 +1,59 @@ +import graphics from love +import cos, sin from math + +w, h = graphics.getDimensions! + +tiny = require "tiny" +IDTracker = require "systems/IDTracker" + + + +MapDisplayManager = tiny.system { + known: {} + filter: tiny.requireAll "system_id" + onAdd: (entity) => + unless @known[entity.system_id] + @known[entity.system_id] = true + makeDisplay entity.system_id + onRemove: (entity) => +} + + + +IDTracker = tiny.system { + filter: tiny.requireAll "id" + onAdd: (entity) => + @[entity.id] = entity + onRemove: (entity) => + @[entity.id] = nil +} +return MapDisplayManager + + + + +MapDisplay = tiny.sortedSystem { + compare: (a, b) => + if a.orbit and b.orbit + a.orbit.hierarchy <= b.orbit.hierarchy + else + true + filter: tiny.requireAny "orbit", tiny.requireAll("x", "y") + draw: (t) => + graphics.translate w / 2, h / 2 + for entity in *@entities + if orbit = entity.orbit + orbit = entity.orbit + -- orbital period + -- real: T = 2pi * sqrt(a^3 / G*M) + -- sim: T = 2pi * speed_parameter + entity.x = orbit.radius * cos(t / orbit.speed_parameter) + orbit.offset + entity.y = orbit.radius * sin(t / orbit.speed_parameter) + orbit.offset + if orbit.parent_id + parent = IDTracker[orbit.parent_id] + entity.x += parent.x + entity.y += parent.y + graphics.circle "fill", entity.x, entity.y, 5 -- TEMP radius +} + +return MapDisplay