Skip to content

Commit

Permalink
Remove Universe.find
Browse files Browse the repository at this point in the history
  • Loading branch information
levinli303 committed Dec 18, 2024
1 parent f000fef commit c327def
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 35 deletions.
10 changes: 0 additions & 10 deletions Celestia/src/main/cpp/CelestiaUniverse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,6 @@ Java_space_celestia_celestia_Universe_c_1getStarBrowser(JNIEnv *env, jclass claz
return reinterpret_cast<jlong>(b);
}

extern "C"
JNIEXPORT jobject JNICALL
Java_space_celestia_celestia_Universe_c_1findObject(JNIEnv *env, jclass clazz, jlong pointer, jstring name) {
auto u = (Universe *)pointer;
const char *str = env->GetStringUTFChars(name, nullptr);
auto sel = u->find(str, {});
env->ReleaseStringUTFChars(name, str);
return selectionAsJavaSelection(env, sel);
}

using namespace std;

using json = nlohmann::json;
Expand Down
6 changes: 0 additions & 6 deletions Celestia/src/main/java/space/celestia/celestia/Universe.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,6 @@ public Map<String, BrowserItem> childrenForItem(@NonNull BrowserItem item) {
return null;
}

public @NonNull
Selection findObject(@NonNull String name) {
return c_findObject(pointer, name);
}

public void mark(@NonNull Selection selection, int marker) {
c_mark(pointer, selection, marker);
}
Expand All @@ -113,7 +108,6 @@ public void unmarkAll() {
private static native long c_getStarBrowser(long pointer, int kind, long observer);
private static native String c_getChildrenForStar(long ptr, long pointer);
private static native String c_getChildrenForBody(long ptr, long pointer);
private static native Selection c_findObject(long ptr, String name);

private static native void c_mark(long ptr, Selection selection, int marker);
private static native void c_unmark(long ptr, Selection selection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class BrowserFragment : Fragment(), BrowserRootFragment, NavigationBarView.OnIte
val universe = simulation.universe
return when (type) {
Type.SolarSystem -> {
universe.solBrowserRoot()!!
simulation.solBrowserRoot()!!
}
Type.Star -> {
universe.starBrowserRoot(simulation.activeObserver)
Expand Down Expand Up @@ -187,12 +187,11 @@ class BrowserFragment : Fragment(), BrowserRootFragment, NavigationBarView.OnIte
val simulation = appCore.simulation
val universe = simulation.universe
val observer = simulation.activeObserver
universe.createStaticBrowserItems(observer)
simulation.createStaticBrowserItems(observer)
universe.createDynamicBrowserItems(observer)
val solRoot = universe.solBrowserRoot()
if (solRoot != null) {
val solRoot = simulation.solBrowserRoot()
if (solRoot != null)
browserTabs.add(0, Tab(Tab.Type.SolarSystem))
}
}
tabs = browserTabs
rootItemsLoaded()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,31 @@ private var starRoot: BrowserItem? = null
private var dsoRoot: BrowserItem? = null
private var brightestStars: BrowserItem? = null

fun Universe.createStaticBrowserItems(observer: Observer) {
fun Simulation.createStaticBrowserItems(observer: Observer) {
if (solRoot == null)
solRoot = createSolBrowserRoot()
if (dsoRoot == null)
dsoRoot = createDSOBrowserRoot()
dsoRoot = universe.createDSOBrowserRoot()
if (brightestStars == null)
brightestStars = createStarBrowserRootItem(StarBrowser.KIND_BRIGHTEST, observer, CelestiaString("Brightest Stars (Absolute Magnitude)",""), true, null)
brightestStars = universe.createStarBrowserRootItem(StarBrowser.KIND_BRIGHTEST, observer, CelestiaString("Brightest Stars (Absolute Magnitude)",""), true, null)
}

fun Universe.createDynamicBrowserItems(observer: Observer) {
starRoot = createStarBrowserRoot(observer)
}

private fun Universe.createSolBrowserRoot(): BrowserItem? {
private fun Simulation.createSolBrowserRoot(): BrowserItem? {
val sol = findObject("Sol").star ?: return null
val universe = this.universe
val catalog = universe.starCatalog
return BrowserPredefinedItem(
starCatalog.getStarName(
catalog.getStarName(
sol
), CelestiaString("Solar System", "Tab for solar system in Star Browser"), sol, this, BrowserPredefinedItem.CategoryInfo("B2E44BE0-9DF7-FAB9-92D4-F8D323D31250", false)
), CelestiaString("Solar System", "Tab for solar system in Star Browser"), sol, universe, BrowserPredefinedItem.CategoryInfo("B2E44BE0-9DF7-FAB9-92D4-F8D323D31250", false)
)
}

fun Universe.solBrowserRoot(): BrowserItem? {
fun Simulation.solBrowserRoot(): BrowserItem? {
if (solRoot == null)
solRoot = createSolBrowserRoot()
return solRoot
Expand Down Expand Up @@ -180,11 +182,4 @@ class BrowserPredefinedItem: BrowserItem {
}
}

class BrowserPredefinedItem3(
name: String,
alternativeName: String?,
children: MutableList<KeyValuePair>
) : BrowserItem(name, alternativeName, children) {
}

class BrowserUIItem(val item: BrowserItem, val isLeaf: Boolean)

0 comments on commit c327def

Please sign in to comment.