Skip to content

Commit

Permalink
Merge pull request #298 from BarthPaleologue/289-refactor-make-orbita…
Browse files Browse the repository at this point in the history
…lobjectmodel-celestialbodymodel-discriminated-unions

Refactor to discriminated unions: OrbitalObjectModel, OrbitalObject, MissionNode, MissionNodeSerialized
  • Loading branch information
BarthPaleologue authored Feb 8, 2025
2 parents b6e5884 + c61cb99 commit 39ff0e8
Show file tree
Hide file tree
Showing 115 changed files with 2,475 additions and 2,126 deletions.
7 changes: 1 addition & 6 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,7 @@ export default [
"import/no-cycle": "error",
"import/no-unresolved": "warn",

"@typescript-eslint/switch-exhaustiveness-check": [
"error",
{
considerDefaultExhaustiveForUnions: true
}
],
"@typescript-eslint/switch-exhaustiveness-check": "error",

"@typescript-eslint/no-floating-promises": "error",
"@typescript-eslint/no-inferrable-types": "warn",
Expand Down
1 change: 1 addition & 0 deletions src/locales/en-US/objectTypes.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"telluricMoon": "Telluric Moon",
"spaceStation": "Space Station",
"spaceElevator": "Space Elevator",
"custom": "Custom Object",
"spaceElevatorClimber": "Space Elevator Climber",
"anomaly": "Anomaly",
"landingPad": "Landing Pad"
Expand Down
1 change: 1 addition & 0 deletions src/locales/fr-FR/objectTypes.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"telluricMoon": "Lune Tellurique",
"spaceStation": "Station Spatiale",
"spaceElevator": "Ascenseur Spatial",
"custom": "Objet Personnalisé",
"spaceElevatorClimber": "Nacelle de l'Ascenseur Spatial",
"anomaly": "Anomalie",
"landingPad": "Plateforme d'Atterrissage"
Expand Down
38 changes: 10 additions & 28 deletions src/ts/alphaTestis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ import "../styles/index.scss";
import { Settings } from "./settings";
import { positionNearObjectBrightSide } from "./utils/positionNearObject";
import { CosmosJourneyer } from "./cosmosJourneyer";
import { newSeededGasPlanetModel } from "./planets/gasPlanet/gasPlanetModel";
import { newSeededGasPlanetModel } from "./planets/gasPlanet/gasPlanetModelGenerator";
import { SpaceShipControlsInputs } from "./spaceship/spaceShipControlsInputs";
import { newSeededStarModel } from "./stellarObjects/star/starModel";
import { newSeededStarModel } from "./stellarObjects/star/starModelGenerator";
import { StarSystemModel } from "./starSystem/starSystemModel";
import { StarSystemCoordinates } from "./utils/coordinates/universeCoordinates";
import { newSeededTelluricSatelliteModel } from "./planets/telluricPlanet/telluricSatelliteModel";
import { newSeededTelluricPlanetModel } from "./planets/telluricPlanet/telluricPlanetModel";
import { newSeededSpaceElevatorModel } from "./spacestation/spaceElevatorModel";
import { newSeededTelluricSatelliteModel } from "./planets/telluricPlanet/telluricSatelliteModelGenerator";
import { newSeededTelluricPlanetModel } from "./planets/telluricPlanet/telluricPlanetModelGenerator";
import { newSeededSpaceElevatorModel } from "./spacestation/spaceElevatorModelGenerator";
import { celsiusToKelvin, getOrbitRadiusFromPeriod } from "./utils/physics";
import { Tools } from "@babylonjs/core/Misc/tools";

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

const sunModel = newSeededStarModel(420, "Weierstrass", []);
sunModel.physics.blackBodyTemperature = 5778;
sunModel.blackBodyTemperature = 5778;

/*const secundaModel = new StarModel(-672446, sunModel);
secundaModel.orbit.semiMajorAxis = 30 * sunModel.radius;
Expand All @@ -63,10 +63,8 @@ terminaModel.orbit.period = 60 * 60;
const termina = StarSystemHelper.makeStar(starSystem, terminaModel);*/

const hecateModel = newSeededTelluricPlanetModel(253, "Hécate", [sunModel]);
hecateModel.physics.minTemperature = celsiusToKelvin(-40);
hecateModel.physics.maxTemperature = celsiusToKelvin(30);

hecateModel.physics.siderealDaySeconds = 6 * 60 * 60;
hecateModel.temperature.min = celsiusToKelvin(-40);
hecateModel.temperature.max = celsiusToKelvin(30);

hecateModel.orbit.semiMajorAxis = 21000 * hecateModel.radius;

Expand All @@ -84,28 +82,12 @@ const spaceStationModel = newSeededSpaceElevatorModel(
}*/

const moonModel = newSeededTelluricSatelliteModel(23, "Manaleth", [hecateModel]);
moonModel.physics.mass = 2;
moonModel.physics.siderealDaySeconds = 28 * 60 * 60;
moonModel.physics.minTemperature = celsiusToKelvin(-180);
moonModel.physics.maxTemperature = celsiusToKelvin(200);
moonModel.physics.waterAmount = 0.9;

moonModel.orbit.inclination = Tools.ToRadians(45);

moonModel.orbit.semiMajorAxis = getOrbitRadiusFromPeriod(
moonModel.physics.siderealDaySeconds,
hecateModel.physics.mass
);
moonModel.orbit.semiMajorAxis = getOrbitRadiusFromPeriod(moonModel.siderealDaySeconds, hecateModel.mass);

const aresModel = newSeededTelluricPlanetModel(0.3725, "Ares", [sunModel]);
if (aresModel.clouds !== null) aresModel.clouds.coverage = 1;
aresModel.physics.mass = 7;
aresModel.physics.siderealDaySeconds = (24 * 60 * 60) / 30;
aresModel.physics.minTemperature = celsiusToKelvin(-30);
aresModel.physics.maxTemperature = celsiusToKelvin(20);
aresModel.physics.pressure = Settings.EARTH_SEA_LEVEL_PRESSURE * 0.5;
aresModel.physics.waterAmount = 0.2;
aresModel.physics.oceanLevel = 0;
if (aresModel.atmosphere !== null) aresModel.atmosphere.pressure = Settings.EARTH_SEA_LEVEL_PRESSURE * 0.5;

aresModel.orbit.semiMajorAxis = 25100 * hecateModel.radius;

Expand Down
58 changes: 3 additions & 55 deletions src/ts/anomalies/julia/juliaSetModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,62 +15,10 @@
// 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 { normalRandom, randRange } from "extended-random";
import { clamp } from "../../utils/math";
import { Orbit } from "../../orbit/orbit";
import { OrbitalObjectPhysicsInfo } from "../../architecture/physicsInfo";
import { GenerationSteps } from "../../utils/generationSteps";
import { Color3 } from "@babylonjs/core/Maths/math.color";
import { AnomalyModel } from "../anomaly";
import { getRngFromSeed } from "../../utils/getRngFromSeed";
import { OrbitalObjectType } from "../../architecture/orbitalObject";
import { Tools } from "@babylonjs/core/Misc/tools";
import { CelestialBodyModelBase } from "../../architecture/orbitalObjectModelBase";
import { OrbitalObjectType } from "../../architecture/orbitalObjectType";

export type JuliaSetModel = AnomalyModel & {
readonly type: OrbitalObjectType.JULIA_SET;
export type JuliaSetModel = CelestialBodyModelBase<OrbitalObjectType.JULIA_SET> & {
readonly accentColor: Color3;
};

export function newSeededJuliaSetModel(seed: number, name: string): JuliaSetModel {
const rng = getRngFromSeed(seed);

const radius = 1000e3;

const accentColor = Color3.FromHSV(
360 * rng(GenerationSteps.ACCENT_COLOR),
rng(GenerationSteps.ACCENT_COLOR + 123) * 0.5,
0.8
);

// Todo: do not hardcode
const orbitRadius = rng(GenerationSteps.ORBIT) * 15e9;

const orbitalP = clamp(0.5, 3.0, normalRandom(1.0, 0.3, rng, GenerationSteps.ORBIT + 80));

const orbit: Orbit = {
semiMajorAxis: orbitRadius,
p: orbitalP,
inclination: Tools.ToRadians(normalRandom(90, 20, rng, GenerationSteps.ORBIT + 160)),
eccentricity: randRange(0.1, 0.9, rng, GenerationSteps.ORBIT + 240),
longitudeOfAscendingNode: randRange(0, 2 * Math.PI, rng, GenerationSteps.ORBIT + 320),
argumentOfPeriapsis: randRange(0, 2 * Math.PI, rng, GenerationSteps.ORBIT + 400),
initialMeanAnomaly: randRange(0, 2 * Math.PI, rng, GenerationSteps.ORBIT + 480)
};

const physicalProperties: OrbitalObjectPhysicsInfo = {
mass: 10,
siderealDaySeconds: 0,
axialTilt: normalRandom(0, 0.4, rng, GenerationSteps.AXIAL_TILT)
};

return {
seed,
name,
radius,
orbit,
physics: physicalProperties,
accentColor,
rings: null,
type: OrbitalObjectType.JULIA_SET
};
}
67 changes: 67 additions & 0 deletions src/ts/anomalies/julia/juliaSetModelGenerator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// 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 { normalRandom, randRange } from "extended-random";
import { clamp } from "../../utils/math";
import { OrbitalObjectType } from "../../architecture/orbitalObjectType";
import { Orbit } from "../../orbit/orbit";
import { GenerationSteps } from "../../utils/generationSteps";
import { getRngFromSeed } from "../../utils/getRngFromSeed";
import { JuliaSetModel } from "./juliaSetModel";
import { Color3 } from "@babylonjs/core/Maths/math.color";
import { Tools } from "@babylonjs/core/Misc/tools";

export function newSeededJuliaSetModel(seed: number, name: string): JuliaSetModel {
const rng = getRngFromSeed(seed);

const radius = 1000e3;

const accentColor = Color3.FromHSV(
360 * rng(GenerationSteps.ACCENT_COLOR),
rng(GenerationSteps.ACCENT_COLOR + 123) * 0.5,
0.8
);

// Todo: do not hardcode
const orbitRadius = rng(GenerationSteps.ORBIT) * 15e9;

const orbitalP = clamp(0.5, 3.0, normalRandom(1.0, 0.3, rng, GenerationSteps.ORBIT + 80));

const orbit: Orbit = {
semiMajorAxis: orbitRadius,
p: orbitalP,
inclination: Tools.ToRadians(normalRandom(90, 20, rng, GenerationSteps.ORBIT + 160)),
eccentricity: randRange(0.1, 0.9, rng, GenerationSteps.ORBIT + 240),
longitudeOfAscendingNode: randRange(0, 2 * Math.PI, rng, GenerationSteps.ORBIT + 320),
argumentOfPeriapsis: randRange(0, 2 * Math.PI, rng, GenerationSteps.ORBIT + 400),
initialMeanAnomaly: randRange(0, 2 * Math.PI, rng, GenerationSteps.ORBIT + 480)
};
const mass = 10;
const siderealDaySeconds = 0;
const axialTilt = normalRandom(0, 0.4, rng, GenerationSteps.AXIAL_TILT);

return {
type: OrbitalObjectType.JULIA_SET,
name,
radius,
orbit,
mass,
siderealDaySeconds,
axialTilt,
accentColor
};
}
2 changes: 1 addition & 1 deletion src/ts/anomalies/julia/juliaSetPostProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import juliaFragment from "../../../shaders/juliaSet.glsl";
import { UpdatablePostProcess } from "../../postProcesses/updatablePostProcess";
import { Effect } from "@babylonjs/core/Materials/effect";
import { StellarObject } from "../../architecture/stellarObject";
import { StellarObject } from "../../architecture/orbitalObject";
import { PostProcess } from "@babylonjs/core/PostProcesses/postProcess";
import { Camera } from "@babylonjs/core/Cameras/camera";
import { ObjectUniformNames, setObjectUniforms } from "../../postProcesses/uniforms/objectUniforms";
Expand Down
67 changes: 7 additions & 60 deletions src/ts/anomalies/mandelbox/mandelboxModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,14 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

import { Color3 } from "@babylonjs/core/Maths/math.color";
import { normalRandom, randRange } from "extended-random";
import { clamp } from "../../utils/math";
import { Orbit } from "../../orbit/orbit";
import { GenerationSteps } from "../../utils/generationSteps";
import { OrbitalObjectPhysicsInfo } from "../../architecture/physicsInfo";
import { AnomalyModel } from "../anomaly";
import { getRngFromSeed } from "../../utils/getRngFromSeed";
import { OrbitalObjectType } from "../../architecture/orbitalObject";
import { Tools } from "@babylonjs/core/Misc/tools";
import { OrbitalObjectType } from "../../architecture/orbitalObjectType";
import { CelestialBodyModelBase } from "../../architecture/orbitalObjectModelBase";

export type MandelboxModel = AnomalyModel & {
readonly type: OrbitalObjectType.MANDELBOX;
readonly accentColor: Color3;
export type MandelboxModel = CelestialBodyModelBase<OrbitalObjectType.MANDELBOX> & {
/**
* The albedo color of the mandelbox
*/
readonly color: Color3;

/**
* distance estimator parameter (range is [0-1])
Expand All @@ -40,51 +35,3 @@ export type MandelboxModel = AnomalyModel & {
*/
readonly spread: number;
};

export function newSeededMandelboxModel(seed: number, name: string): MandelboxModel {
const rng = getRngFromSeed(seed);

const radius = 200e3;

const mr2 = randRange(0.0, 1.0, rng, GenerationSteps.POWER);
const spread = randRange(1.0, 1.5, rng, GenerationSteps.POWER + 1);
const accentColor = Color3.FromHSV(
360 * rng(GenerationSteps.ACCENT_COLOR),
rng(GenerationSteps.ACCENT_COLOR + 123) * 0.5,
0.8
);

// Todo: do not hardcode
const orbitRadius = rng(GenerationSteps.ORBIT) * 15e9;

const orbitalP = clamp(0.5, 3.0, normalRandom(1.0, 0.3, rng, GenerationSteps.ORBIT + 80));

const orbit: Orbit = {
semiMajorAxis: orbitRadius,
p: orbitalP,
inclination: Tools.ToRadians(normalRandom(90, 20, rng, GenerationSteps.ORBIT + 160)),
eccentricity: randRange(0.1, 0.9, rng, GenerationSteps.ORBIT + 240),
longitudeOfAscendingNode: randRange(0, 2 * Math.PI, rng, GenerationSteps.ORBIT + 320),
argumentOfPeriapsis: randRange(0, 2 * Math.PI, rng, GenerationSteps.ORBIT + 400),
initialMeanAnomaly: randRange(0, 2 * Math.PI, rng, GenerationSteps.ORBIT + 480)
};

const physicalProperties: OrbitalObjectPhysicsInfo = {
mass: 10,
siderealDaySeconds: 0,
axialTilt: normalRandom(0, 0.4, rng, GenerationSteps.AXIAL_TILT)
};

return {
seed,
radius,
rings: null,
name,
type: OrbitalObjectType.MANDELBOX,
mr2,
spread,
accentColor,
orbit,
physics: physicalProperties
};
}
72 changes: 72 additions & 0 deletions src/ts/anomalies/mandelbox/mandelboxModelGenerator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// 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 { randRange, normalRandom } from "extended-random";
import { clamp } from "../../utils/math";
import { OrbitalObjectType } from "../../architecture/orbitalObjectType";
import { Orbit } from "../../orbit/orbit";
import { GenerationSteps } from "../../utils/generationSteps";
import { getRngFromSeed } from "../../utils/getRngFromSeed";
import { MandelboxModel } from "./mandelboxModel";
import { Color3 } from "@babylonjs/core/Maths/math.color";
import { Tools } from "@babylonjs/core/Misc/tools";

export function newSeededMandelboxModel(seed: number, name: string): MandelboxModel {
const rng = getRngFromSeed(seed);

const radius = 200e3;

const mr2 = randRange(0.0, 1.0, rng, GenerationSteps.POWER);
const spread = randRange(1.0, 1.5, rng, GenerationSteps.POWER + 1);
const accentColor = Color3.FromHSV(
360 * rng(GenerationSteps.ACCENT_COLOR),
rng(GenerationSteps.ACCENT_COLOR + 123) * 0.5,
0.8
);

// Todo: do not hardcode
const orbitRadius = rng(GenerationSteps.ORBIT) * 15e9;

const orbitalP = clamp(0.5, 3.0, normalRandom(1.0, 0.3, rng, GenerationSteps.ORBIT + 80));

const orbit: Orbit = {
semiMajorAxis: orbitRadius,
p: orbitalP,
inclination: Tools.ToRadians(normalRandom(90, 20, rng, GenerationSteps.ORBIT + 160)),
eccentricity: randRange(0.1, 0.9, rng, GenerationSteps.ORBIT + 240),
longitudeOfAscendingNode: randRange(0, 2 * Math.PI, rng, GenerationSteps.ORBIT + 320),
argumentOfPeriapsis: randRange(0, 2 * Math.PI, rng, GenerationSteps.ORBIT + 400),
initialMeanAnomaly: randRange(0, 2 * Math.PI, rng, GenerationSteps.ORBIT + 480)
};

const mass = 10;
const siderealDaySeconds = 0;
const axialTilt = normalRandom(0, 0.4, rng, GenerationSteps.AXIAL_TILT);

return {
radius,
mass,
siderealDaySeconds,
axialTilt,
name,
type: OrbitalObjectType.MANDELBOX,
mr2,
spread,
color: accentColor,
orbit
};
}
Loading

0 comments on commit 39ff0e8

Please sign in to comment.