Skip to content

Commit

Permalink
Fix startup crash by being redirected to JPL Horizon's home page
Browse files Browse the repository at this point in the history
  • Loading branch information
DJBen committed Oct 12, 2018
1 parent b74841c commit 421cd9a
Show file tree
Hide file tree
Showing 73 changed files with 444 additions and 458 deletions.
6 changes: 3 additions & 3 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ github "DJBen/KelvinColor" "0.1.0"
github "DJBen/MathUtil" "0.4.0"
github "DJBen/SpaceTime" "0.3.1"
github "DJBen/StarryNight" "0.3.0"
github "SwiftyBeaver/SwiftyBeaver" "1.5.2"
github "SwiftyBeaver/SwiftyBeaver" "1.6.1"
github "Weebly/OrderedSet" "swift-3.2"
github "mhergon/RealmGeoQueries" "v1.3.1"
github "realm/realm-cocoa" "v3.3.2"
github "realm/realm-cocoa" "v3.11.0"
github "sharplet/Regex" "1.1.0"
github "stephencelis/SQLite.swift" "0.11.4"
github "stephencelis/SQLite.swift" "0.11.5"
github "xmartlabs/XLPagerTabStrip" "7.0.0"
21 changes: 10 additions & 11 deletions Graviton/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
// Copyright © 2016 Ben Lu. All rights reserved.
//

import UIKit
import Orbits
import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
func application(_: UIApplication, didFinishLaunchingWithOptions _: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
configureLogging()
RealmManager.default.migrateRealmIfNeeded()
UINavigationBar.configureNavigationBarStyles()
Expand Down Expand Up @@ -44,7 +43,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
return
}
let alertController = UIAlertController(title: "iOS SceneKit Bug", message: "There exists a bug on iOS 11.2 that causes transparent textures not to be rendered. As a result, some nodes will appear square-like. iOS 11.3 fixed this issue. Please update to latest system version whenever you can.", preferredStyle: .alert)
let openForumAction = UIAlertAction(title: "See Detail", style: .default) { (_) in
let openForumAction = UIAlertAction(title: "See Detail", style: .default) { _ in
UIApplication.shared.open(forumUrl, options: [:], completionHandler: nil)
}
alertController.addAction(openForumAction)
Expand All @@ -54,31 +53,31 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}
}

func applicationWillResignActive(_ application: UIApplication) {
func applicationWillResignActive(_: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}

func applicationDidEnterBackground(_ application: UIApplication) {
func applicationDidEnterBackground(_: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(_ application: UIApplication) {
func applicationWillEnterForeground(_: UIApplication) {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(_ application: UIApplication) {
func applicationDidBecomeActive(_: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

func applicationWillTerminate(_ application: UIApplication) {
func applicationWillTerminate(_: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
}

extension UINavigationController {
override open var childViewControllerForStatusBarStyle: UIViewController? {
return self.topViewController
open override var childViewControllerForStatusBarStyle: UIViewController? {
return topViewController
}
}
11 changes: 5 additions & 6 deletions Graviton/CelestialBody/Nodes/CelestialBodyNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,19 @@
// Copyright © 2017 Ben Lu. All rights reserved.
//

import UIKit
import SceneKit
import Orbits
import MathUtil
import Orbits
import SceneKit
import UIKit

class CelestialBodyNode: SCNNode {

init(naif: Naif) {
super.init()
geometry = naif.geometry
name = String(naif.rawValue)
}

required init?(coder aDecoder: NSCoder) {
required init?(coder _: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
Expand All @@ -36,7 +35,7 @@ private extension Naif {
switch self {
case .moon(.luna):
mat.diffuse.contents = #imageLiteral(resourceName: "moon_texture")
// mat.normal.contents = #imageLiteral(resourceName: "moon_normal")
// mat.normal.contents = #imageLiteral(resourceName: "moon_normal")
default:
fatalError("Unsupported celestial body")
}
Expand Down
15 changes: 8 additions & 7 deletions Graviton/CelestialBody/Scenes/CelestialBodyScene.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
// Copyright © 2017 Ben Lu. All rights reserved.
//

import UIKit
import SceneKit
import MathUtil
import Orbits
import SceneKit
import SpaceTime
import MathUtil
import UIKit

class CelestialBodyScene: SCNScene, CameraResponsive {
static let defaultFov: Double = 30
Expand Down Expand Up @@ -60,11 +60,12 @@ class CelestialBodyScene: SCNScene, CameraResponsive {
celestialNode.addChildNode(solarNode)
}

required init?(coder aDecoder: NSCoder) {
required init?(coder _: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

// MARK: - Observer Update

func updateObserverInfo(_ observerInfo: [Naif: CelestialBodyObserverInfo]) {
if let moonInfo = observerInfo[.moon(.luna)] {
solarNode.light!.intensity = 1500
Expand All @@ -75,10 +76,10 @@ class CelestialBodyScene: SCNScene, CameraResponsive {
)
let northPoleAxis = Vector3(equatorialCoordinate: eq)
precondition(northPoleAxis.length ~= 1, "North pole axis should be normalized")
let rotation = Quaternion.init(alignVector: Vector3(0, 1, 0), with: northPoleAxis)
let latRot = Quaternion.init(axisAngle: Vector4(0, 0, 1, -radians(degrees: moonInfo.obLon)))
let rotation = Quaternion(alignVector: Vector3(0, 1, 0), with: northPoleAxis)
let latRot = Quaternion(axisAngle: Vector4(0, 0, 1, -radians(degrees: moonInfo.obLon)))
celestialNode.orientation = SCNQuaternion(latRot * rotation)
celestialNode.pivot = SCNMatrix4(Matrix4.init(rotation: Vector4(1, 0, 0, Double.pi / 2)))
celestialNode.pivot = SCNMatrix4(Matrix4(rotation: Vector4(1, 0, 0, Double.pi / 2)))
let slXRot = -radians(degrees: moonInfo.slLat.value!)
let slYRot = radians(degrees: moonInfo.slLon.value!)
var slMat = Matrix4(rotation: Vector4(1, 0, 0, slXRot))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
// Copyright © 2017 Ben Lu. All rights reserved.
//

import UIKit
import SceneKit
import UIKit

class CelestialBodyViewController: SceneController {
private lazy var cbScene = CelestialBodyScene()
private var scnView: SCNView {
return self.view as! SCNView
return view as! SCNView
}

private var obsSubscriptionIdentifier: SubscriptionUUID!
Expand Down
10 changes: 5 additions & 5 deletions Graviton/Common/Geometries/Line.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
// Copyright © 2017 Ben Lu. All rights reserved.
//

import UIKit
import SceneKit
import MathUtil
import SceneKit
import UIKit

private struct LineMode {
enum Fill {
Expand All @@ -23,9 +23,9 @@ private struct LineMode {
let final: (Int) -> Int = closes ? { $0 } : { $0 - 1 }
switch fill {
case .solid:
return { index -> [CInt] in (0...final(index)).map { CInt($0 % index) } }
return { index -> [CInt] in (0 ... final(index)).map { CInt($0 % index) } }
case .dashed:
return { index -> [CInt] in (0...final(index)).map { CInt($0 % index) } }
return { index -> [CInt] in (0 ... final(index)).map { CInt($0 % index) } }
}
}
}
Expand All @@ -50,7 +50,7 @@ extension SCNGeometry {

static func dottedLine(vertices: [SCNVector3]) -> SCNGeometry {
func generateIndex(_ numberOfSegments: Int) -> [CInt] {
return (0...(numberOfSegments * 2)).map { CInt($0 % (numberOfSegments * 2)) }
return (0 ... (numberOfSegments * 2)).map { CInt($0 % (numberOfSegments * 2)) }
}
func extendVertices(_ vertices: [SCNVector3]) -> [SCNVector3] {
let diffs = vertices.enumerated().map { (index, vertex) -> SCNVector3 in
Expand Down
6 changes: 3 additions & 3 deletions Graviton/Common/Managers/CameraController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
// Copyright © 2017 Ben Lu. All rights reserved.
//

import UIKit
import SceneKit
import MathUtil
import SceneKit
import UIKit

class CameraController: NSObject {
struct Invert: OptionSet {
Expand Down Expand Up @@ -82,7 +82,7 @@ class CameraController: NSObject {
decelerateCamera(atTime: time)
}

func handleCameraRotation(atTime time: TimeInterval) {
func handleCameraRotation(atTime _: TimeInterval) {
guard let cameraNode = cameraNode, let oldRot = previousRotation else { return }
var rot: GLKQuaternion = GLKQuaternionMakeWithAngleAndAxis(oldRot.w, oldRot.x, oldRot.y, oldRot.z)
var rotZ: GLKQuaternion = GLKQuaternionMakeWithAngleAndAxis(Float(rotation), 0, 0, 1)
Expand Down
11 changes: 5 additions & 6 deletions Graviton/Common/Managers/CelestialBodyObserverInfoManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
// Copyright © 2017 Ben Lu. All rights reserved.
//

import UIKit
import CoreLocation
import Orbits
import SpaceTime
import CoreLocation
import UIKit

final class CelestialBodyObserverInfoManager: LocationSensitiveSubscriptionManager<[Naif: CelestialBodyObserverInfo]> {

static var globalMode: Horizons.FetchMode = .preferLocal

static let `default` = CelestialBodyObserverInfoManager()
Expand All @@ -21,19 +20,19 @@ final class CelestialBodyObserverInfoManager: LocationSensitiveSubscriptionManag
if isFetching { return }
isFetching = true
let site = ObserverSite(naif: .majorBody(.earth), location: LocationManager.default.content ?? CLLocation())
Horizons.shared.fetchCelestialBodyObserverInfo(preferredDate: requestedJd.date, observerSite: site, mode: mode ?? CelestialBodyObserverInfoManager.globalMode, update: { [weak self] (dict) in
Horizons.shared.fetchCelestialBodyObserverInfo(preferredDate: requestedJd.date, observerSite: site, mode: mode ?? CelestialBodyObserverInfoManager.globalMode, update: { [weak self] dict in
self?.content = dict
for (_, sub) in self!.subscriptions {
DispatchQueue.main.async {
sub.didLoad!(dict)
}
}
}, complete: { [weak self] (_, _) in
}, complete: { [weak self] _, _ in
self!.isFetching = false
})
}

override func update(subscription: LocationSensitiveSubscriptionManager<[Naif: CelestialBodyObserverInfo]>.Subscription, forJulianDay requestedJd: JulianDay) {
override func update(subscription _: LocationSensitiveSubscriptionManager<[Naif: CelestialBodyObserverInfo]>.Subscription, forJulianDay _: JulianDay) {
// no-op
}
}
10 changes: 5 additions & 5 deletions Graviton/Common/Managers/CityManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
// Copyright © 2017 Ben Lu. All rights reserved.
//

import UIKit
import SQLite
import CoreLocation
import SQLite
import UIKit

private let conn = try! Connection(Bundle.main.path(forResource: "cities", ofType: "sqlite3")!)
private let cities = Table("cities")
Expand Down Expand Up @@ -41,7 +41,7 @@ struct City: Equatable {
return try! conn.pluck(usStates.select(usStatesAbbrev).where(province == usStatesName))?.get(usStatesAbbrev)
}

static func ==(lhs: City, rhs: City) -> Bool {
static func == (lhs: City, rhs: City) -> Bool {
return lhs.name == rhs.name && lhs.province == rhs.province && lhs.country == rhs.country
}
}
Expand All @@ -53,7 +53,7 @@ class CityManager {
var currentlyLocatedCity: City? {
didSet {
if let city = currentlyLocatedCity {
let location = CLLocation.init(latitude: city.coordinate.latitude, longitude: city.coordinate.longitude)
let location = CLLocation(latitude: city.coordinate.latitude, longitude: city.coordinate.longitude)
LocationManager.default.locationOverride = location
} else {
LocationManager.default.locationOverride = nil
Expand All @@ -65,7 +65,7 @@ class CityManager {
let filterClause = substr == nil ? citiesPop >= minimumPopulation : citiesPop >= minimumPopulation && citiesName.like("%\(substr!)%")
let query = cities.select(citiesLat, citiesLng, citiesName, citiesCountry, citiesProvince, citiesIso2, citiesIso3).filter(filterClause).order(citiesName)
return try! conn.prepare(query).map { (row) -> City in
return City(coordinate: CLLocationCoordinate2D.init(latitude: try! row.get(citiesLat), longitude: try! row.get(citiesLng)), name: try! row.get(citiesName), country: try! row.get(citiesCountry), province: try! row.get(citiesProvince), iso2: try! row.get(citiesIso2), iso3: try! row.get(citiesIso3))
City(coordinate: CLLocationCoordinate2D(latitude: try! row.get(citiesLat), longitude: try! row.get(citiesLng)), name: try! row.get(citiesName), country: try! row.get(citiesCountry), province: try! row.get(citiesProvince), iso2: try! row.get(citiesIso2), iso3: try! row.get(citiesIso3))
}
}
}
5 changes: 2 additions & 3 deletions Graviton/Common/Managers/EphemerisManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
// Copyright © 2017 Ben Lu. All rights reserved.
//

import UIKit
import Orbits
import SpaceTime
import UIKit

final class EphemerisManager: SubscriptionManager<Ephemeris> {

static var globalMode: Horizons.FetchMode = .mixed

static let `default` = EphemerisManager()
Expand All @@ -38,7 +37,7 @@ final class EphemerisManager: SubscriptionManager<Ephemeris> {

override func subscribe(mode: SubscriptionManager<Ephemeris>.RefreshMode, didLoad: SubscriptionBlock?, didUpdate: SubscriptionBlock?) -> SubscriptionUUID {
let uuid = SubscriptionUUID()
subscriptions[uuid] = SubscriptionManager<Ephemeris>.Subscription(identifier: uuid, mode: mode, content: self.content?.copy() as? Ephemeris, didLoad: didLoad, didUpdate: didUpdate)
subscriptions[uuid] = SubscriptionManager<Ephemeris>.Subscription(identifier: uuid, mode: mode, content: content?.copy() as? Ephemeris, didLoad: didLoad, didUpdate: didUpdate)
if let eph = content {
didLoad?(eph)
}
Expand Down
2 changes: 1 addition & 1 deletion Graviton/Common/Managers/LiteSubscriptionManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class LiteSubscriptionManager<T>: NSObject {
}

func updateAllSubscribers(_ content: T) {
for (_, sub) in self.subscriptions {
for (_, sub) in subscriptions {
DispatchQueue.main.async {
sub.didUpdate?(content)
}
Expand Down
5 changes: 2 additions & 3 deletions Graviton/Common/Managers/LocationAndTimeManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
// Copyright © 2017 Ben Lu. All rights reserved.
//

import UIKit
import SpaceTime
import UIKit

class ObserverLocationTimeManager: NSObject {

static let `default` = ObserverLocationTimeManager()
var subId: SubscriptionUUID!
private(set) var observerInfo: ObserverLocationTime?
Expand All @@ -30,7 +29,7 @@ class ObserverLocationTimeManager: NSObject {

override init() {
super.init()
subId = LocationManager.default.subscribe(didUpdate: { [weak self] (location) in
subId = LocationManager.default.subscribe(didUpdate: { [weak self] location in
self?.observerInfo = ObserverLocationTime(location: location, timestamp: self!.julianDay ?? JulianDay.now)
})
}
Expand Down
Loading

0 comments on commit 421cd9a

Please sign in to comment.