Compare commits

..

1 Commits

Author SHA1 Message Date
Tangent
600f0bc9f8 theory 2019-10-25 20:46:06 -07:00
7 changed files with 107 additions and 66 deletions

View File

@ -13,13 +13,3 @@ NO Grabs all position and orbit components with a specific system.
- note: L4/L5 positions are stored as their own orbits
* id:
* x,y,system_id: position in a system
# Notes
- Model populations as their own entities.
- Minerals on a body can be mined.
- Minerals on a population have already been mined, and can be used.
- Consider splitting MapDisplay's version of bodies from the reality?
- Reason A: It will also need to store contacts, and should not always have all info
- Reason B: Orbital positions should only be updated by an orbital processor when needed
- Reason C: Reduce duplication by making the orbital processor the only thing that updates positions?

View File

@ -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

View File

@ -1,19 +0,0 @@
-- TODO defined globals need to be created somewhere else
export stefan_boltzmann_constant = 5.670374419e-8 -- W / (m^2 * K^4)
parameters = {
temperature: love.math.randomNormal 1000, 6000 -- [2000 to 10000] K
}
parameters.absolute_magnitude = 35.4631241560502 * math.exp(-0.000353006569939 * parameters.temperature) -- Mv
parameters.luminosity = 100 * math.exp -0.943865141164545 * (parameters.absolute_magnitude - 0.99^parameters.absolute_magnitude) -- L(sun)
-- TODO calculate B-V value ? Or color directly? Or spectrum?
-- TODO this needs to be multiplied by the star's surface area to get its total power emission
parameters.surface_power_emission = stefan_boltzmann_constant * parameters.temperature^4 -- W / m^2
-- NOTE then for measuring power input into a planet, find the surface area of
-- its orbital radius, divide total power by that, then multiply that by the
-- circular cross-section of that planet to get the total power being emitted
-- into that planet, which must equal its emission, allowing you to calculate
-- its surface temperature*
-- * if it had no atmosphere, or albedo

View File

@ -1,29 +0,0 @@
-- TODO defined globals need to be created somewhere else
export gravitational_constant = 6.6743e-11 -- m^3 / (kg * s^2)
export magic_pressure_constant = 1.1701572e-4 -- s^2 / m^2
parameters = {
surface_radius: love.math.randomNormal 1100, 5500 -- [1.1e3, 9.9e3 km]
solid_density: love.math.randomNormal 0.675, 5.2 -- [2.5, 7.9 g/cm^3]
}
parameters.solid_volume = 4/3 * math.pi * parameters.surface_radius^3 -- km^3
parameters.solid_mass = parameters.solid_density * parameters.solid_volume * 1e12 -- kg
parameters.surface_gravity = gravitational_constant * parameters.solid_mass / parameters.surface_radius^2 * 1e-6 -- m/s^2
parameters.atmosphere_reduction_rate = parameters.surface_gravity * magic_pressure_constant -- m^-1
parameters.atmosphere_halving_height = math.log(2) / parameters.atmosphere_reduction_rate -- m
-- volume containing the first half of the entire atmosphere is assumed to be
-- half of the volume of the entire atmosphere if it was at surface pressure
parameters.simulated_atmosphere_volume = (4/3 * math.pi * (parameters.surface_radius + parameters.atmosphere_halving_height / 1000)^3 - parameters.solid_volume) * 2 -- km^3
-- TODO better (based on distance from star / temperature from star)
parameters.surface_atmosphere_pressure = 101325 * math.max 0, love.math.randomNormal 0.125, 0.5 -- [0, 202650 kPa]
-- TODO verify this will generate in meters
parameters.minimum_orbital_height = math.log(1.4e-11 / parameters.surface_atmosphere_pressure) / parameters.atmosphere_reduction_rate -- m
parameters.atmosphere_volume = 4/3 * math.pi * (parameters.surface_radius + parameters.minimum_orbital_height / 1000)^3 - parameters.solid_volume -- km^3
-- TODO atmospheric composition?
-- TODO albedo
-- TODO surface_average_temperature (based on greenhouse gases or lack thereof, albedo, and base temperature from distance to star)
-- unused at this time?
parameters.surface_area = 4 * math.pi * parameters.surface_radius^2

View File

@ -1,4 +1,5 @@
tiny = require "tiny"
MapDisplay = require "generators/MapDisplay"
systems = {}
for name in *love.filesystem.getDirectoryItems "systems"
@ -17,14 +18,16 @@ makeEntity = (tab) ->
return tab
world = tiny.world game, unpack systems
local map
system = ->
system_id = "someuuidthing"
sun = makeEntity {
x: 0, y: 0
radius: 5
x: 0,
y: 0
[system_id]: true
}
planet = makeEntity {
radius: 1
orbit: {
hierarchy: 1
radius: 20
@ -32,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!
@ -41,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!

View File

@ -20,14 +20,14 @@ MapDisplay = tiny.sortedSystem {
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
-- 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, entity.radius
graphics.circle "fill", entity.x, entity.y, 5 -- TEMP radius
}
return MapDisplay

View File

@ -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