Skip to content

Commit

Permalink
Improve type safety and names
Browse files Browse the repository at this point in the history
- separate TelluricPlanetModel from TelluricSatelliteModel
- better names for physical properties => physics info
- simplify CanHaveRings interface
  • Loading branch information
BarthPaleologue committed Oct 15, 2024
1 parent 2b7ec5c commit 1236e2f
Show file tree
Hide file tree
Showing 48 changed files with 408 additions and 327 deletions.
7 changes: 4 additions & 3 deletions src/ts/alphaTestis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { Settings } from "./settings";
import { positionNearObjectBrightSide } from "./utils/positionNearObject";
import { CosmosJourneyer } from "./cosmosJourneyer";
import { Vector3 } from "@babylonjs/core/Maths/math.vector";
import { newSeededTelluricPlanetModel } from "./planets/telluricPlanet/telluricPlanetModel";
import { newSeededGasPlanetModel } from "./planets/gasPlanet/gasPlanetModel";
import { SpaceShipControlsInputs } from "./spaceship/spaceShipControlsInputs";

Expand All @@ -30,6 +29,8 @@ import { newSeededSpaceStationModel } from "./spacestation/spacestationModel";
import { StarSystemModel } from "./starSystem/starSystemModel";
import { StarSystemCoordinates } from "./utils/coordinates/universeCoordinates";
import { CustomSystemRegistry } from "./starSystem/customSystemRegistry";
import { newSeededTelluricSatelliteModel } from "./planets/telluricPlanet/telluricSatelliteModel";
import { newSeededTelluricPlanetModel } from "./planets/telluricPlanet/telluricPlanetModel";

const engine = await CosmosJourneyer.CreateAsync();

Expand All @@ -51,7 +52,7 @@ const systemCoordinates: StarSystemCoordinates = {
};

const sunModel = newSeededStarModel(420, "Weierstrass", []);
sunModel.physics.temperature = 5778;
sunModel.physics.blackBodyTemperature = 5778;
sunModel.orbit.period = 60 * 60 * 24;

/*const secundaModel = new StarModel(-672446, sunModel);
Expand Down Expand Up @@ -79,7 +80,7 @@ const spaceStationModel = newSeededSpaceStationModel(0, [sunModel], systemCoordi
physicsViewer.showBody(landingpad.aggregate.body);
}*/

const moonModel = newSeededTelluricPlanetModel(23, "Manaleth", [hecateModel]);
const moonModel = newSeededTelluricSatelliteModel(23, "Manaleth", [hecateModel]);
moonModel.physics.mass = 2;
moonModel.physics.rotationPeriod = 7 * 60 * 60;
moonModel.physics.minTemperature = -180;
Expand Down
13 changes: 3 additions & 10 deletions src/ts/anomalies/julia/juliaSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ import { PostProcessType } from "../../postProcesses/postProcessTypes";
import { Axis } from "@babylonjs/core/Maths/math.axis";
import { TransformNode } from "@babylonjs/core/Meshes";
import { Scene } from "@babylonjs/core/scene";
import { RingsUniforms } from "../../rings/ringsUniform";
import { Vector3 } from "@babylonjs/core/Maths/math.vector";
import { Cullable } from "../../utils/cullable";
import { AsteroidField } from "../../asteroidFields/asteroidField";
import { CelestialBody } from "../../architecture/celestialBody";
import { orbitalObjectTypeToDisplay } from "../../utils/strings/orbitalObjectTypeToDisplay";

Expand All @@ -35,6 +33,9 @@ export class JuliaSet implements CelestialBody, Cullable {

readonly postProcesses: PostProcessType[] = [];

readonly ringsUniforms = null;
readonly asteroidField = null;

/**
* New Gas Planet
* @param model The model to create the planet from or a seed for the planet in [-1, 1]
Expand All @@ -58,14 +59,6 @@ export class JuliaSet implements CelestialBody, Cullable {
return this.getTransform().up;
}

getRingsUniforms(): RingsUniforms | null {
return null;
}

getAsteroidField(): AsteroidField | null {
return null;
}

getRadius(): number {
return this.model.radius;
}
Expand Down
4 changes: 2 additions & 2 deletions src/ts/anomalies/julia/juliaSetModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { normalRandom } from "extended-random";
import { clamp } from "../../utils/math";
import { getOrbitalPeriod, getPeriapsis, Orbit } from "../../orbit/orbit";
import { Vector3 } from "@babylonjs/core/Maths/math.vector";
import { OrbitalObjectPhysicalProperties } from "../../architecture/physicalProperties";
import { OrbitalObjectPhysicsInfo } from "../../architecture/physicsInfo";
import { CelestialBodyModel } from "../../architecture/celestialBody";
import { GenerationSteps } from "../../utils/generationSteps";
import { Color3 } from "@babylonjs/core/Maths/math.color";
Expand Down Expand Up @@ -54,7 +54,7 @@ export function newSeededJuliaSetModel(seed: number, name: string, parentBodies:
normalToPlane: Vector3.Up()
};

const physicalProperties: OrbitalObjectPhysicalProperties = {
const physicalProperties: OrbitalObjectPhysicsInfo = {
mass: 10,
rotationPeriod: 0,
axialTilt: normalRandom(0, 0.4, rng, GenerationSteps.AXIAL_TILT)
Expand Down
13 changes: 3 additions & 10 deletions src/ts/anomalies/mandelbulb/mandelbulb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ import { PostProcessType } from "../../postProcesses/postProcessTypes";
import { Axis } from "@babylonjs/core/Maths/math.axis";
import { TransformNode } from "@babylonjs/core/Meshes";
import { Scene } from "@babylonjs/core/scene";
import { RingsUniforms } from "../../rings/ringsUniform";
import { Vector3 } from "@babylonjs/core/Maths/math.vector";
import { Cullable } from "../../utils/cullable";
import { AsteroidField } from "../../asteroidFields/asteroidField";
import { CelestialBody } from "../../architecture/celestialBody";
import { orbitalObjectTypeToDisplay } from "../../utils/strings/orbitalObjectTypeToDisplay";

Expand All @@ -35,6 +33,9 @@ export class Mandelbulb implements CelestialBody, Cullable {

readonly postProcesses: PostProcessType[] = [];

readonly asteroidField = null;
readonly ringsUniforms = null;

/**
* New Gas Planet
* @param model The model to create the planet from or a seed for the planet in [-1, 1]
Expand All @@ -58,14 +59,6 @@ export class Mandelbulb implements CelestialBody, Cullable {
return this.getTransform().up;
}

getRingsUniforms(): RingsUniforms | null {
return null;
}

getAsteroidField(): AsteroidField | null {
return null;
}

getRadius(): number {
return this.model.radius;
}
Expand Down
4 changes: 2 additions & 2 deletions src/ts/anomalies/mandelbulb/mandelbulbModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { getOrbitalPeriod, getPeriapsis, Orbit } from "../../orbit/orbit";
import { Vector3 } from "@babylonjs/core/Maths/math.vector";
import { CelestialBodyModel } from "../../architecture/celestialBody";
import { GenerationSteps } from "../../utils/generationSteps";
import { OrbitalObjectPhysicalProperties } from "../../architecture/physicalProperties";
import { OrbitalObjectPhysicsInfo } from "../../architecture/physicsInfo";
import { AnomalyModel } from "../anomaly";

import { getRngFromSeed } from "../../utils/getRngFromSeed";
Expand Down Expand Up @@ -56,7 +56,7 @@ export function newSeededMandelbulbModel(seed: number, name: string, parentBodie
normalToPlane: Vector3.Up()
};

const physicalProperties: OrbitalObjectPhysicalProperties = {
const physicalProperties: OrbitalObjectPhysicsInfo = {
mass: 10,
rotationPeriod: 0,
axialTilt: normalRandom(0, 0.4, rng, GenerationSteps.AXIAL_TILT)
Expand Down
4 changes: 2 additions & 2 deletions src/ts/architecture/canHaveRings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ export interface CanHaveRings {
/**
* Returns the uniforms used to render the rings, or null if the object has no rings
*/
getRingsUniforms(): RingsUniforms | null;
readonly ringsUniforms: RingsUniforms | null;

/**
* Returns the asteroid belt of the object's ring, or null if the object has no rings
*/
getAsteroidField(): AsteroidField | null;
readonly asteroidField: AsteroidField | null;
}

export interface CanHaveRingsModel {
Expand Down
4 changes: 2 additions & 2 deletions src/ts/architecture/orbitalObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { Transformable } from "./transformable";
import { HasBoundingSphere } from "./hasBoundingSphere";
import { Quaternion, Vector3 } from "@babylonjs/core/Maths/math";
import { getRotationQuaternion, setRotationQuaternion, translate } from "../uberCore/transforms/basicTransform";
import { OrbitalObjectPhysicalProperties } from "./physicalProperties";
import { OrbitalObjectPhysicsInfo } from "./physicsInfo";
import { TypedObject } from "./typedObject";
import { getPointOnOrbit, Orbit } from "../orbit/orbit";

Expand Down Expand Up @@ -130,7 +130,7 @@ export type OrbitalObjectModel = {
/**
* Physical properties of the object
*/
readonly physics: OrbitalObjectPhysicalProperties;
readonly physics: OrbitalObjectPhysicsInfo;
};

export const enum OrbitalObjectType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

export type OrbitalObjectPhysicalProperties = {
export type OrbitalObjectPhysicsInfo = {
mass: number;
/**
* Time needed for the object to rotate on its axis in seconds
Expand All @@ -24,24 +24,24 @@ export type OrbitalObjectPhysicalProperties = {
axialTilt: number;
};

export type StellarObjectPhysicalProperties = OrbitalObjectPhysicalProperties & {
export type StellarObjectPhysicsInfo = OrbitalObjectPhysicsInfo & {
/**
* Black body temperature of the object in Kelvin
*/
temperature: number;
blackBodyTemperature: number;
};

export type BlackHolePhysicalProperties = StellarObjectPhysicalProperties & {
export type BlackHolePhysicsInfo = StellarObjectPhysicsInfo & {
accretionDiskRadius: number;
};

export type PlanetPhysicalProperties = OrbitalObjectPhysicalProperties & {
export type PlanetaryMassObjectPhysicsInfo = OrbitalObjectPhysicsInfo & {
minTemperature: number;
maxTemperature: number;
pressure: number;
};

export type TelluricPlanetPhysicalProperties = PlanetPhysicalProperties & {
export type TelluricPlanetaryMassObjectPhysicsInfo = PlanetaryMassObjectPhysicsInfo & {
waterAmount: number;
oceanLevel: number;
};
37 changes: 5 additions & 32 deletions src/ts/architecture/planet.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,10 @@
// This file is part of Cosmos Journeyer
//
// Copyright (C) 2024 Barthélemy Paléologue <barth.paleologue@cosmosjourneyer.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

import { CelestialBody, CelestialBodyModel } from "./celestialBody";
import { PlanetPhysicalProperties } from "./physicalProperties";
import { Transformable } from "./transformable";
import { PlanetaryMassObject, PlanetaryMassObjectModel } from "./planetaryMassObject";
import { OrbitalObjectType } from "./orbitalObject";

export interface Planet extends CelestialBody {
model: PlanetModel;

updateMaterial(stellarObjects: Transformable[], deltaSeconds: number): void;
export interface Planet extends PlanetaryMassObject {
readonly model: PlanetModel;
}

export type PlanetModel = CelestialBodyModel & {
readonly type: OrbitalObjectType.TELLURIC_PLANET | OrbitalObjectType.GAS_PLANET | OrbitalObjectType.TELLURIC_SATELLITE;

physics: PlanetPhysicalProperties;
export type PlanetModel = PlanetaryMassObjectModel & {
readonly type: OrbitalObjectType.TELLURIC_PLANET | OrbitalObjectType.GAS_PLANET;
};

export function hasAtmosphere(planetModel: PlanetModel): boolean {
return planetModel.physics.pressure > 0.05;
}
30 changes: 30 additions & 0 deletions src/ts/architecture/planetaryMassObject.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// This file is part of Cosmos Journeyer
//
// Copyright (C) 2024 Barthélemy Paléologue <barth.paleologue@cosmosjourneyer.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

import { CelestialBody, CelestialBodyModel } from "./celestialBody";
import { PlanetaryMassObjectPhysicsInfo } from "./physicsInfo";
import { Transformable } from "./transformable";

export interface PlanetaryMassObject extends CelestialBody {
readonly model: PlanetaryMassObjectModel;

updateMaterial(stellarObjects: Transformable[], deltaSeconds: number): void;
}

export type PlanetaryMassObjectModel = CelestialBodyModel & {
readonly physics: PlanetaryMassObjectPhysicsInfo;
};
4 changes: 2 additions & 2 deletions src/ts/architecture/stellarObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import { PointLight } from "@babylonjs/core/Lights/pointLight";
import { CelestialBody, CelestialBodyModel } from "./celestialBody";
import { StellarObjectPhysicalProperties } from "./physicalProperties";
import { StellarObjectPhysicsInfo } from "./physicsInfo";

export interface StellarObject extends CelestialBody {
model: StellarObjectModel;
Expand All @@ -26,5 +26,5 @@ export interface StellarObject extends CelestialBody {
}

export type StellarObjectModel = CelestialBodyModel & {
physics: StellarObjectPhysicalProperties;
physics: StellarObjectPhysicsInfo;
};
17 changes: 17 additions & 0 deletions src/ts/architecture/typedObject.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
// This file is part of Cosmos Journeyer
//
// Copyright (C) 2024 Barthélemy Paléologue <barth.paleologue@cosmosjourneyer.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

export interface TypedObject {
/**
* Returns the type name of the object. This is used as a short identifier in the UI Overlay of the object
Expand Down
2 changes: 1 addition & 1 deletion src/ts/blackHoleDemo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import { positionNearObjectBrightSide } from "./utils/positionNearObject";
import { CosmosJourneyer } from "./cosmosJourneyer";

import { newSeededBlackHoleModel } from "./stellarObjects/blackHole/blackHoleModel";
import { newSeededTelluricPlanetModel } from "./planets/telluricPlanet/telluricPlanetModel";
import { StarSystemModel } from "./starSystem/starSystemModel";
import { CustomSystemRegistry } from "./starSystem/customSystemRegistry";
import { newSeededTelluricPlanetModel } from "./planets/telluricPlanet/telluricPlanetModel";

const engine = await CosmosJourneyer.CreateAsync();

Expand Down
6 changes: 3 additions & 3 deletions src/ts/missions/generateSightSeeingMissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { newSightSeeingMission } from "./sightSeeingMission";
import { uniformRandBool } from "extended-random";
import { SystemObjectType } from "../utils/coordinates/universeCoordinates";
import { Player } from "../player/player";
import { hasLiquidWater, TelluricPlanetModel } from "../planets/telluricPlanet/telluricPlanetModel";
import { TelluricPlanetaryMassObjectModel } from "../planets/telluricPlanet/telluricPlanetaryMassObjectModel";
import { Mission, MissionType } from "./mission";
import { StarSystemModel, StarSystemModelUtils } from "../starSystem/starSystemModel";
import { getRngFromSeed } from "../utils/getRngFromSeed";
Expand Down Expand Up @@ -110,8 +110,8 @@ export function generateSightseeingMissions(spaceStationModel: SpaceStationModel
}

if (celestialBodyModel.type === OrbitalObjectType.TELLURIC_PLANET) {
const telluricPlanetModel = celestialBodyModel as TelluricPlanetModel;
if (!hasLiquidWater(telluricPlanetModel)) {
const telluricPlanetModel = celestialBodyModel as TelluricPlanetaryMassObjectModel;
if (telluricPlanetModel.physics.oceanLevel === 0) {
terminatorLandingMissions.push(
newSightSeeingMission(spaceStationModel, {
type: MissionType.SIGHT_SEEING_TERMINATOR_LANDING,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export class MissionAsteroidFieldNode implements MissionNode {
throw new Error(`Object with ID ${JSON.stringify(this.objectId)} is not a celestial body`);
}

const asteroidField = celestialBody.getAsteroidField();
const asteroidField = celestialBody.asteroidField;
if (asteroidField === null) {
throw new Error(`Object with ID ${JSON.stringify(this.objectId)} does not have an asteroid field`);
}
Expand Down
Loading

0 comments on commit 1236e2f

Please sign in to comment.