Skip to content

Commit

Permalink
orbitalkiller: some optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Borunov committed Jun 15, 2016
1 parent 09308c2 commit f136bf0
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 21 deletions.
Expand Up @@ -85,7 +85,10 @@ object OrbitDataUpdater {
yy:List[DVec],
orbit_color: ScageColor) = {
OrbitData(update_count, bs, body_radius, planet_state, planet, o, ccw, () => {
drawSlidingLines(yy.map(_ + planet_state.coord * scale), orbit_color)
openglLocalTransform {
openglMove(planet_state.coord * scale)
drawSlidingLines(yy, orbit_color)
}
if(InterfaceHolder.namesSwitcher.showNames) {
val new_o = o.withNewFocusPosition(planet_state.coord)
drawStringInOrbitPoint("P", 0, new_o, orbit_color)
Expand All @@ -103,7 +106,10 @@ object OrbitDataUpdater {
yy:List[DVec],
orbit_color: ScageColor) = {
OrbitData(update_count, bs, body_radius, planet_state, planet, o, ccw, () => {
drawSlidingLines(yy.map(_ + planet_state.coord * scale), orbit_color)
openglLocalTransform {
openglMove(planet_state.coord * scale)
drawSlidingLines(yy, orbit_color)
}
})
}

Expand All @@ -118,7 +124,10 @@ object OrbitDataUpdater {
orbit_color: ScageColor) = {
OrbitData(update_count, bs, body_radius, planet_state, planet, o, ccw, () => {
val new_o = o.withNewFocusPosition(planet_state.coord)
drawSlidingLines(yy.map(_ + planet_state.coord * scale), orbit_color)
openglLocalTransform {
openglMove(planet_state.coord * scale)
drawSlidingLines(yy, orbit_color)
}
if(InterfaceHolder.namesSwitcher.showNames) {
drawStringInOrbitPoint("P", 0, new_o, orbit_color)
}
Expand Down Expand Up @@ -174,13 +183,14 @@ object OrbitDataUpdater {
ccw:Boolean,
orbit_color: ScageColor) = {
OrbitData(update_count, bs, body_radius, planet_state, planet, o, ccw, () => {
val new_o = o.withNewFocusPosition(planet_state.coord)
val new_center = o.centerIfFocusPosition(planet_state.coord)
openglLocalTransform {
openglMove(new_o.center * scale)
openglRotateDeg(Vec(-1, 0).signedDeg(new_o.f2 - new_o.f))
drawEllipse(DVec.zero, new_o.a * scale, new_o.b * scale, orbit_color)
openglMove(new_center * scale)
if(o.f2 != o.f) openglRotateDeg(Vec(1, 0).signedDeg(o.f_minus_f2_n))
drawEllipse(DVec.zero, o.a * scale, o.b * scale, orbit_color)
}
if(InterfaceHolder.namesSwitcher.showNames) {
val new_o = o.withNewFocusPosition(planet_state.coord)
drawStringInOrbitPoint("P", 0, new_o, orbit_color)
drawStringInOrbitPoint("A", 180, new_o, orbit_color)
}
Expand All @@ -196,11 +206,11 @@ object OrbitDataUpdater {
ccw:Boolean,
orbit_color: ScageColor) = {
OrbitData(update_count, bs, body_radius, planet_state, planet, o, ccw, () => {
val new_o = o.withNewFocusPosition(planet_state.coord)
val new_center = o.centerIfFocusPosition(planet_state.coord)
openglLocalTransform {
openglMove(new_o.center * scale)
openglRotateDeg(Vec(-1, 0).signedDeg(o.f2 - o.f))
drawEllipse(DVec.zero, new_o.a * scale, new_o.b * scale, orbit_color)
openglMove(new_center * scale)
if(o.f2 != o.f) openglRotateDeg(Vec(1, 0).signedDeg(o.f_minus_f2_n))
drawEllipse(DVec.zero, o.a * scale, o.b * scale, orbit_color)
}
})
}
Expand All @@ -217,7 +227,7 @@ object OrbitDataUpdater {
val new_o = o.withNewFocusPosition(planet_state.coord)
openglLocalTransform {
openglMove(new_o.center * scale)
openglRotateDeg(Vec(-1, 0).signedDeg(new_o.f2 - new_o.f))
if(new_o.f2 != new_o.f) openglRotateDeg(Vec(-1, 0).signedDeg(new_o.f2 - new_o.f))
drawEllipse(DVec.zero, new_o.a * scale, new_o.b * scale, orbit_color)
}
if(InterfaceHolder.namesSwitcher.showNames) {
Expand Down
Expand Up @@ -1109,7 +1109,7 @@ abstract class PolygonShip(
}
}
}
def updateStateSinceDeactivation(time_msec:Long, some_system_state: mutable.Map[Int, MutableBodyState]): Unit = {
private def updateStateSinceDeactivation(time_msec:Long, some_system_state: mutable.Map[Int, MutableBodyState]): Unit = {
_orbit_data match {
case Some(or) =>
val time_since_deactivation_msec = time_msec - deactivate_moment_msec
Expand All @@ -1120,11 +1120,11 @@ abstract class PolygonShip(
or.orbit match {
case e:EllipseOrbit =>
val new_e = e.withNewFocusPosition(planet_coord)
val new_coord = new_e.orbitalPointAfterTime(deactivate_point_relative + planet_coord, time_since_deactivation_msec, or.ccw)
/*val new_coord = new_e.orbitalPointAfterTime(deactivate_point_relative + planet_coord, time_since_deactivation_msec, or.ccw)
if(new_coord.x.isNaN || new_coord.y.isNaN || new_coord == planet_coord) {
val x = new_e.orbitalPointAfterTime(deactivate_point_relative + planet_coord, time_since_deactivation_msec, or.ccw)
}
currentState.coord = new_coord
}*/
currentState.coord = new_e.orbitalPointAfterTime(deactivate_point_relative + planet_coord, time_since_deactivation_msec, or.ccw)
val (vt, vr) = new_e.orbitalVelocityInPoint(currentState.coord)
val r = if (or.ccw) (currentState.coord - planet_coord).n else -(currentState.coord - planet_coord).n
val t = r.perpendicular
Expand Down Expand Up @@ -1377,13 +1377,13 @@ abstract class PolygonShip(
// если это не корабль игрока, расстояние от данного корабля до корабля игрока больше 500 км,
// перигей орбиты выше верхней границы атмосферы (орбита стабильная) или мы стоим на земле,
// двигатели не включены
/*val deactivate_condition = thisOrActualProxyShipIndex != player_ship.thisOrActualProxyShipIndex &&
val deactivate_condition = thisOrActualProxyShipIndex != player_ship.thisOrActualProxyShipIndex &&
coord.dist2(OrbitalKiller.player_ship.coord) > 500l*1000l * 500l*1000l &&
_orbit_data.exists(or => {
or.is_landed || or.ellipseOrbit.exists(e => e.r_p > or.planet.radius + or.planet.air_free_altitude)
}) &&
engines.forall(!_.active)*/
val (deactivate_condition, reason) = deactivateCondition
engines.forall(!_.active)
//val (deactivate_condition, reason) = deactivateCondition
if (currentState.active) {
calculateShipState(time_msec)
if (deactivate_condition) {
Expand All @@ -1393,10 +1393,13 @@ abstract class PolygonShip(
println(s"deactivated $name")
}
} else {
if (!deactivate_condition) {
if(!deactivate_condition || (drawMapMode && ship_interface.exists(!_.isMinimized))) {
updateStateSinceDeactivation(time_msec, system_evolution.allBodyStates)
}
if (!deactivate_condition) {
currentState.active = true
println(s"activated $name, reason: $reason")
println(s"activated $name")
//println(s"activated $name, reason: $reason")
}
}
} else {
Expand Down
Expand Up @@ -1550,6 +1550,10 @@ package object orbitalkiller {
val new_center = (new_f2 - new_f).n * c + new_f
new EllipseOrbit(a, b, e, c, p, r_p, r_a, t, new_f, new_f2, new_center, mu)
}

def centerIfFocusPosition(new_f:DVec):DVec = {
(f2 - f).n * c + new_f
}
}

class HyperbolaOrbit(
Expand Down

0 comments on commit f136bf0

Please sign in to comment.