Skip to content

Commit

Permalink
More layer code simplification. (sky-map-team#432)
Browse files Browse the repository at this point in the history
Simplify and Kotlinize even more.  There's still more to do over time, but this should allow work on kotlinizing the renderer to begin and also make it at least possible to add new features.



* Mechanical transformation of the Java layers code to Kotlin.

* Clean up imports etc that were broken during the automatic conversion.

* Simplify AbstractLayer and kotlinize it a bit more.

* Changed to lateinit.

* Remove reduntant code. Reluctantly leave the generics and unsafe casts
as is since eliminating it does add more code, even if it makes it more
readable.

* Kotlinize some more.

* Remove a redundant method.

* Broke a lot of things...

* Fixed stuff I broke.

* There seems to be no need for the closures to be stored in a TreeSet.
The ordering isn't really used. And if that's the case then the Closure
doesn't need to be Comparable.

* Eliminate the UpdateClosure classes and replace with modern functional
stuff.

* Renamed "Source" to "Renderable" which better reflects what they are.

* Mechanical conversion of the renderables to Kotlin and the bare minimum
to get it to build again.

* Post-kotlin conversion cleanup.

* Eliminate another few unnecessary math functions.

* Renamed the source package.

* More renaming.

* Remove an unused method

* Rename a Kotlin-unfriendly variable.

* Upgrade Gradle version.

* Adds a placeholder image of Earth. We don't need it yet and will find a
better one later.
This image is from NASA and therefore in the public domain.

* Honey I shrunk the earth.

* Whoops I didn't mean to commit all that.
Might as well add in these two files: I renamed the Planet enum and its
associated rendered as they're not all planets.

* Revert "Whoops I didn't mean to commit all that."

This reverts commit e7a5b7a.

* Revert "Honey I shrunk the earth."

This reverts commit 2491623.

* Honey I shrunk the earth mk 2.

* Update the dd.

* Rename Planet to SolarSystemBody since it represents more than Planets.

* More renaming. The new "Earth" SolarSystem object is included in the
enum so that its orbital elements are available. However this
adds the wrinkle that we now need to remove it from the list of
objects to render.

* Bug fix.

* These are hardly new any more.

* Fix the bug with the planet orientation.
Not sure this code is right, but at least it's the same as before and
doesn't crash.
  • Loading branch information
jaydeetay authored Dec 18, 2021
1 parent 7d33da2 commit 106afd7
Show file tree
Hide file tree
Showing 76 changed files with 2,383 additions and 2,942 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
import com.google.android.stardroid.layers.HorizonLayer;
import com.google.android.stardroid.layers.LayerManager;
import com.google.android.stardroid.layers.MeteorShowerLayer;
import com.google.android.stardroid.layers.NewConstellationsLayer;
import com.google.android.stardroid.layers.NewMessierLayer;
import com.google.android.stardroid.layers.NewStarsLayer;
import com.google.android.stardroid.layers.PlanetsLayer;
import com.google.android.stardroid.layers.ConstellationsLayer;
import com.google.android.stardroid.layers.MessierLayer;
import com.google.android.stardroid.layers.StarsLayer;
import com.google.android.stardroid.layers.SolarSystemLayer;
import com.google.android.stardroid.layers.SkyGradientLayer;
import com.google.android.stardroid.util.Analytics;
import com.google.android.stardroid.util.AnalyticsInterface;
Expand Down Expand Up @@ -148,10 +148,10 @@ LayerManager provideLayerManager(
SharedPreferences preferences) {
Log.i(TAG, "Initializing LayerManager");
LayerManager layerManager = new LayerManager(preferences);
layerManager.addLayer(new NewStarsLayer(assetManager, resources));
layerManager.addLayer(new NewMessierLayer(assetManager, resources));
layerManager.addLayer(new NewConstellationsLayer(assetManager, resources));
layerManager.addLayer(new PlanetsLayer(model, resources, preferences));
layerManager.addLayer(new StarsLayer(assetManager, resources));
layerManager.addLayer(new MessierLayer(assetManager, resources));
layerManager.addLayer(new ConstellationsLayer(assetManager, resources));
layerManager.addLayer(new SolarSystemLayer(model, resources, preferences));
layerManager.addLayer(new MeteorShowerLayer(model, resources));
layerManager.addLayer(new GridLayer(resources, 24, 9));
layerManager.addLayer(new HorizonLayer(model, resources));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
import com.google.android.stardroid.math.Vector3;
import com.google.android.stardroid.renderer.RendererController;
import com.google.android.stardroid.renderer.SkyRenderer;
import com.google.android.stardroid.renderer.util.AbstractUpdateClosure;
import com.google.android.stardroid.search.SearchResult;
import com.google.android.stardroid.touch.DragRotateZoomGestureDetector;
import com.google.android.stardroid.touch.GestureInterpreter;
Expand Down Expand Up @@ -105,7 +104,7 @@ public DynamicStarMapComponent getComponent() {
*
* @author John Taylor
*/
private static final class RendererModelUpdateClosure extends AbstractUpdateClosure {
private static final class RendererModelUpdateClosure implements Runnable {
private RendererController rendererController;
private AstronomerModel model;
private boolean horizontalRotation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import com.google.android.stardroid.R;
import com.google.android.stardroid.activities.DynamicStarMapActivity;
import com.google.android.stardroid.control.AstronomerModel;
import com.google.android.stardroid.ephemeris.Planet;
import com.google.android.stardroid.ephemeris.SolarSystemBody;
import com.google.android.stardroid.space.CelestialObject;
import com.google.android.stardroid.space.Universe;
import com.google.android.stardroid.util.MiscUtil;
Expand Down Expand Up @@ -203,7 +203,7 @@ private void updateDisplay() {
private Universe universe = new Universe();

private void setToNextSunRiseOrSet(CelestialObject.RiseSetIndicator indicator) {
Calendar riseset = universe.solarSystemObjectFor(Planet.Sun).calcNextRiseSetTime(
Calendar riseset = universe.solarSystemObjectFor(SolarSystemBody.Sun).calcNextRiseSetTime(
calendar, model.getLocation(), indicator);
if (riseset == null) {
Toast.makeText(this.getContext(), R.string.sun_wont_set_message, Toast.LENGTH_SHORT).show();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ import android.util.Log
import com.google.android.stardroid.math.MathUtils.sin
import com.google.android.stardroid.math.MathUtils.cos
import com.google.android.stardroid.math.MathUtils.abs
import com.google.android.stardroid.math.MathUtils.atan
import com.google.android.stardroid.math.MathUtils.sqrt
import com.google.android.stardroid.math.MathUtils.tan
import com.google.android.stardroid.math.mod2pi
import com.google.android.stardroid.ephemeris.OrbitalElements
import com.google.android.stardroid.util.MiscUtil

/**
Expand Down Expand Up @@ -78,7 +76,7 @@ data class OrbitalElements(
} while (abs(e0 - e1) > EPSILON)

// convert eccentric anomaly to true anomaly
val v = 2f * atan(
val v = 2f * kotlin.math.atan(
sqrt((1 + e) / (1 - e))
* tan(0.5f * e0)
)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ import java.util.*

/**
* A data holder for some static data about solar system objects.
* These are usually planets.
*/
// Add Color, magnitude, etc.
enum class Planet
enum class SolarSystemBody
(
// Resource ID to use for a planet's image.
val imageResourceId: Int,
Expand All @@ -36,6 +37,8 @@ enum class Planet
) {
// The order here is the order in which they are drawn. To ensure that during
// conjunctions they display "naturally" order them in reverse distance from Earth.
// TODO(jontayler): do this more rigorously - the only times it could really matter are when
// Mercury and Venus ought to be behind the Sun.
Pluto(
R.drawable.pluto,
R.string.pluto,
Expand Down Expand Up @@ -77,7 +80,8 @@ enum class Planet
R.string.venus,
TimeConstants.MILLISECONDS_PER_HOUR
),
Moon(R.drawable.moon4, R.string.moon, TimeConstants.MILLISECONDS_PER_MINUTE);
Moon(R.drawable.moon4, R.string.moon, TimeConstants.MILLISECONDS_PER_MINUTE),
Earth(R.drawable.earth, R.string.earth, TimeConstants.MILLISECONDS_PER_HOUR);

// Taken from JPL's Planetary Positions page: http://ssd.jpl.nasa.gov/?planet_pos
// This gives us a good approximation for the years 1800 to 2050 AD.
Expand Down Expand Up @@ -105,7 +109,7 @@ enum class Planet
val o: Float = (76.67984255f - 0.27769418f * jc) * DEGREES_TO_RADIANS
OrbitalElements(a, e, i, o, w, l)
}
Sun -> {
Earth -> {
val a = 1.00000261f + 0.00000562f * jc
val e = 0.01671123f - 0.00004392f * jc
val i: Float = (-0.00001531f - 0.01294668f * jc) * DEGREES_TO_RADIANS
Expand Down Expand Up @@ -168,11 +172,11 @@ enum class Planet
val o: Float = (110.30393684f - 0.01183482f * jc) * DEGREES_TO_RADIANS
OrbitalElements(a, e, i, o, w, l)
}
else -> throw RuntimeException("Unknown Planet: $this")
else -> throw RuntimeException("Unknown orbital elements for Solar System Object: $this")
}
}

companion object {
private val TAG = MiscUtil.getTag(Planet::class.java)
private val TAG = MiscUtil.getTag(SolarSystemBody::class.java)
}
}
Loading

0 comments on commit 106afd7

Please sign in to comment.