Skip to content

Commit

Permalink
Implemented light sources for spacecraft thrusters
Browse files Browse the repository at this point in the history
- point light sources for spacecraft thrusters can be toggled in the graphics settings
- Editor: fixed and improved editing of thruster slots
- Editor: topParent added as parameter to isValid() and isRequired() property descriptor functions
  • Loading branch information
nkrisztian89 committed Nov 22, 2024
1 parent fa5dc63 commit 125a72f
Show file tree
Hide file tree
Showing 18 changed files with 204 additions and 31 deletions.
7 changes: 6 additions & 1 deletion src/config/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.5.5-dev:1224 (2024.11.21.)",
"version": "0.5.5-dev:1225 (2024.11.22.)",
"debugVersion": false,
"logVerbosity": 1,
"platform": "web",
Expand Down Expand Up @@ -420,6 +420,7 @@
"maxLevel": "veryLow"
},
"showMissilesInLaunchers": false,
"createLightSourcesForThrusters": false,
"particleAmount": {
"amount": "low"
},
Expand All @@ -445,6 +446,7 @@
"maxLevel": "medium"
},
"showMissilesInLaunchers": false,
"createLightSourcesForThrusters": false,
"particleAmount": {
"amount": "medium"
},
Expand Down Expand Up @@ -474,6 +476,7 @@
"maxLevel": "veryHigh"
},
"showMissilesInLaunchers": false,
"createLightSourcesForThrusters": false,
"particleAmount": {
"amount": "maximum"
},
Expand Down Expand Up @@ -503,6 +506,7 @@
"maxLevel": "veryHigh"
},
"showMissilesInLaunchers": true,
"createLightSourcesForThrusters": true,
"particleAmount": {
"amount": "maximum"
},
Expand Down Expand Up @@ -532,6 +536,7 @@
"maxLevel": "veryHigh"
},
"showMissilesInLaunchers": true,
"createLightSourcesForThrusters": true,
"particleAmount": {
"amount": "maximum"
},
Expand Down
1 change: 1 addition & 0 deletions src/config/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
]
},
"showMissilesInLaunchers": false,
"createLightSourcesForThrusters": false,
"particleAmount": {
"amount": "maximum",
"autoLimitByScreenSize": true,
Expand Down
1 change: 1 addition & 0 deletions src/config/strings/strings-hu.json
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,7 @@
"backgroundQuality": "Háttér részletessége:",
"modelDetails": "Modellek részletessége:",
"missilesInLaunchers": "Rakéták a vetőcsövekben:",
"thrusterLightSources": "Fényforrások a hajtóművekhez:",
"shaders": "Árnyalók részletessége:",
"shadows": "Árnyékok:",
"shadowQuality": "Árnyékok felbontása:",
Expand Down
1 change: 1 addition & 0 deletions src/config/strings/strings-it.json
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,7 @@
"backgroundQuality": "Dettagli dello sfondo:",
"modelDetails": "Dettagli del modello:",
"missilesInLaunchers": "Mostra i missili nei lanciamissili:",
"thrusterLightSources": "Fonti di luce per propulsori:",
"shaders": "Dettagli dello shader:",
"shadows": "Ombre:",
"shadowQuality": "Risoluzione delle ombre:",
Expand Down
1 change: 1 addition & 0 deletions src/config/strings/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,7 @@
"backgroundQuality": "Background details:",
"modelDetails": "Model details:",
"missilesInLaunchers": "Show missiles in launchers:",
"thrusterLightSources": "Light sources for thrusters:",
"shaders": "Shader details:",
"shadows": "Shadows:",
"shadowQuality": "Shadow resolution:",
Expand Down
24 changes: 16 additions & 8 deletions src/data/classes.json
Original file line number Diff line number Diff line change
Expand Up @@ -4168,16 +4168,20 @@
"size": 1.8
}, {
"position": [21.75, -5.4, 9.15],
"size": 1.8
"size": 1.8,
"lightFactor": 0.2
}, {
"position": [19.25, -5.4, 9.15],
"size": 1.8
"size": 1.8,
"lightFactor": 0.2
}, {
"position": [16.75, -5.4, 9.15],
"size": 1.8
"size": 1.8,
"lightFactor": 0.2
}, {
"position": [14.25, -5.4, 9.15],
"size": 1.8
"size": 1.8,
"lightFactor": 0.2
}]
}, {
"group": 4,
Expand All @@ -4190,16 +4194,20 @@
"size": 1.8
}, {
"position": [-21.75, -5.4, 9.15],
"size": 1.8
"size": 1.8,
"lightFactor": 0.2
}, {
"position": [-19.25, -5.4, 9.15],
"size": 1.8
"size": 1.8,
"lightFactor": 0.2
}, {
"position": [-16.75, -5.4, 9.15],
"size": 1.8
"size": 1.8,
"lightFactor": 0.2
}, {
"position": [-14.25, -5.4, 9.15],
"size": 1.8
"size": 1.8,
"lightFactor": 0.2
}]
}, {
"group": 5,
Expand Down
40 changes: 39 additions & 1 deletion src/js/armada/graphics.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2014-2021, 2023 Krisztián Nagy
* Copyright 2014-2021, 2023-2024 Krisztián Nagy
* @file Provides functionality to parse and load the graphics settings of Interstellar Armada from an external file as well as to save them
* to or load from HTML5 local storage and access derived settings.
* @author Krisztián Nagy [nkrisztian89@gmail.com]
Expand Down Expand Up @@ -725,6 +725,13 @@ define([
*/
MISSILES_IN_LAUNCHERS_LOCAL_STORAGE_ID = MODULE_LOCAL_STORAGE_PREFIX + "missilesInLaunchers",
// ............................................................................................
// Create light sources for thrusters
/**
* The key identifying the location where the creation of light sources for thrusters setting is stored in local storage.
* @type String
*/
THRUSTER_LIGHT_SOURCES_LOCAL_STORAGE_ID = MODULE_LOCAL_STORAGE_PREFIX + "thrusterLightSources",
// ............................................................................................
// Shader complexity
/**
* The key identifying the location where the shader complexity level setting is stored in local storage.
Expand Down Expand Up @@ -1174,6 +1181,11 @@ define([
* @type Boolean
*/
this._missilesInLaunchers = false;
/**
* Whether light sources should be created for each thruster on spacecrafts.
* @type Boolean
*/
this._thrusterLightSources = false;
/**
* The currently set and available texture qualities.
* @type TextureQuality
Expand Down Expand Up @@ -1484,6 +1496,8 @@ define([
this._limitSettingByScreenSize(dataJSON.levelOfDetail, this._lodLevel, this.getMaxLoadedLOD.bind(this), this.setLODLevel.bind(this), "level");
// whether to show loaded missiles in their launchers (during missions)
this.setMissilesInLaunchersVisible(types.getBooleanValue(dataJSON.showMissilesInLaunchers, {name: "settings.graphics.showMissilesInLaunchers"}), false);
// whether to create light sources for thrusters on spacecrafts
this.setLightSourcesForThrusters(types.getBooleanValue(dataJSON.createLightSourcesForThrusters, {name: "settings.graphics.createLightSourcesForThrusters"}), false);
// load the particle amount settings
this.setParticleAmount(dataJSON.particleAmount.amount, false);
// if the particle amount is limited by screen size, check the current size and apply the limit
Expand Down Expand Up @@ -1539,6 +1553,7 @@ define([
loadSetting(CUBEMAP_QUALITY_LOCAL_STORAGE_ID, {baseType: "enum", values: types.getEnumObjectForArray(this.getCubemapQualities())}, this.getCubemapQuality(), this.setCubemapQuality.bind(this));
loadSetting(MAX_LOD_LOCAL_STORAGE_ID, {baseType: "enum", values: types.getEnumObjectForArray(this.getLODLevels())}, this.getLODLevel(), this.setLODLevel.bind(this));
loadSetting(MISSILES_IN_LAUNCHERS_LOCAL_STORAGE_ID, "boolean", this.areMissilesInLaunchersVisible(), this.setMissilesInLaunchersVisible.bind(this));
loadSetting(THRUSTER_LIGHT_SOURCES_LOCAL_STORAGE_ID, "boolean", this.shouldCreateLightSourcesForThrusters(), this.setLightSourcesForThrusters.bind(this));
loadSetting(SHADER_COMPLEXITY_LOCAL_STORAGE_ID, {baseType: "enum", values: types.getEnumObjectForArray(this.getShaderComplexities())}, this.getShaderComplexity(), this.setShaderComplexity.bind(this));
loadSetting(SHADOW_MAPPING_LOCAL_STORAGE_ID, "boolean", this.isShadowMappingEnabled(), this.setShadowMapping.bind(this));
loadSetting(SHADOW_MAP_QUALITY_LOCAL_STORAGE_ID, {baseType: "enum", values: types.getEnumObjectForArray(this.getShadowMapQualities())}, this.getShadowMapQuality(), this.setShadowMapQuality.bind(this));
Expand Down Expand Up @@ -1789,6 +1804,27 @@ define([
GraphicsSettingsContext.prototype.areMissilesInLaunchersVisible = function () {
return this._missilesInLaunchers;
};
/**
* Sets whether light sources should be created for each thruster on spacecrafts.
* @param {Boolean} [value]
* @param {Boolean} [saveToLocalStorage=true]
*/
GraphicsSettingsContext.prototype.setLightSourcesForThrusters = function (value, saveToLocalStorage) {
if (saveToLocalStorage === undefined) {
saveToLocalStorage = true;
}
this._thrusterLightSources = value;
if (saveToLocalStorage) {
localStorage[THRUSTER_LIGHT_SOURCES_LOCAL_STORAGE_ID] = value.toString();
}
};
/**
* Returns whether light sources should be created for each thruster on spacecrafts.
* @returns {Boolean}
*/
GraphicsSettingsContext.prototype.shouldCreateLightSourcesForThrusters = function () {
return this._thrusterLightSources;
};
/**
* Returns the string identifying the current shader complexity level setting.
* @returns {String}
Expand Down Expand Up @@ -2568,6 +2604,8 @@ define([
getLODContext: _context.getLODContext.bind(_context),
setMissilesInLaunchersVisible: _context.setMissilesInLaunchersVisible.bind(_context),
areMissilesInLaunchersVisible: _context.areMissilesInLaunchersVisible.bind(_context),
setLightSourcesForThrusters: _context.setLightSourcesForThrusters.bind(_context),
shouldCreateLightSourcesForThrusters: _context.shouldCreateLightSourcesForThrusters.bind(_context),
getShaderComplexity: _context.getShaderComplexity.bind(_context),
setShaderComplexity: _context.setShaderComplexity.bind(_context),
getShaderComplexities: _context.getShaderComplexities.bind(_context),
Expand Down
9 changes: 8 additions & 1 deletion src/js/armada/logic/classes.js
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ define([
* @param {ThrusterSlot[]} thrusterSlots
*/
function _loadThrusterSlots(dataJSON, object, thrusterSlots) {
var i, j, groupIndex, uses, startPosition, translationVector, size, count, jsonObject;
var i, j, groupIndex, uses, startPosition, translationVector, size, count, lightFactor, jsonObject;
for (i = 0; i < dataJSON.thrusterSlots.length; i++) {
groupIndex = dataJSON.thrusterSlots[i].group;
uses = dataJSON.thrusterSlots[i].uses;
Expand All @@ -556,10 +556,12 @@ define([
translationVector = dataJSON.thrusterSlots[i].vector || _missingVector3(object, "thrusterSlot array vector");
size = dataJSON.thrusterSlots[i].size || _missingNumber(object, "thrusterSlot array size");
count = dataJSON.thrusterSlots[i].count;
lightFactor = dataJSON.thrusterSlots[i].lightFactor;
for (j = 0; j < count; j++) {
thrusterSlots.push(new ThrusterSlot({//eslint-disable-line no-use-before-define
position: vec.sum3(startPosition, vec.scaled3Aux(translationVector, j)),
size: size,
lightFactor: lightFactor,
groupIndex: groupIndex,
uses: uses
}));
Expand Down Expand Up @@ -3573,6 +3575,11 @@ define([
* @type Number
*/
this.group = dataJSON ? ((typeof dataJSON.groupIndex) === "number" ? dataJSON.groupIndex : _missingNumber(this, "groupIndex")) : 0;
/**
* The strength of the light source created for this thruster slot will be multiplied by this factor.
* @type Number
*/
this.lightFactor = dataJSON ? ((dataJSON.lightFactor !== undefined) ? dataJSON.lightFactor : 1.0) : 0;
}
// ##############################################################################
/**
Expand Down
8 changes: 7 additions & 1 deletion src/js/armada/logic/constants.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2014-2022 Krisztián Nagy
* Copyright 2014-2024 Krisztián Nagy
* @file Provides some constants to be used in other game logic modules
* @author Krisztián Nagy [nkrisztian89@gmail.com]
* @licence GNU GPLv3 <http://www.gnu.org/licenses/>
Expand Down Expand Up @@ -35,6 +35,11 @@ define(function () {
* @type Number
*/
BLINKER_LIGHT_PRIORITY = 4,
/**
* Lights sources for thrusters on spacecrafts will be added to their scenes with this priority
* @type Number
*/
THRUSTER_LIGHT_PRIORITY = 4,
/**
* Name of the pool for reusable Particle instances
* @type String
Expand Down Expand Up @@ -83,6 +88,7 @@ define(function () {
PROJECTILE_LIGHT_PRIORITY: PROJECTILE_LIGHT_PRIORITY,
MISSILE_LIGHT_PRIORITY: MISSILE_LIGHT_PRIORITY,
BLINKER_LIGHT_PRIORITY: BLINKER_LIGHT_PRIORITY,
THRUSTER_LIGHT_PRIORITY: THRUSTER_LIGHT_PRIORITY,
PARTICLE_POOL_NAME: PARTICLE_POOL_NAME,
PROJECTILE_POOL_NAME: PROJECTILE_POOL_NAME,
MISSILE_POOL_NAME: MISSILE_POOL_NAME,
Expand Down
34 changes: 30 additions & 4 deletions src/js/armada/logic/equipment.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ define([
* @type Number
*/
THRUSTER_SOUND_VOLUME_RAMP_DURATION = 0.020,
/**
* The intensity of point lights created for thrusters is always multiplied by this factor.
* @type Number
*/
THRUSTER_LIGHT_INTENSITY_FACTOR = 0.35,
/**
* When mapping potential targets to numerical values for ordering, the bearing angle of the target will be multiplied by this
* factor
Expand Down Expand Up @@ -1241,7 +1246,7 @@ define([
this._initVisualModel(wireframe, lod, shaderName, trail);
scene.addObject(this._visualModel, true);
for (i = 0; i < this._thrusters.length; i++) {
this._thrusters[i].addToScene(this._visualModel.getNode(), true);
this._thrusters[i].addToScene(this._visualModel.getNode(), true, false);
}
if (_dynamicLights && this._class.getLightColor()) {
if (!this._lightSource) {
Expand Down Expand Up @@ -3489,6 +3494,10 @@ define([
* @type Number
*/
this._maxMoveBurnLevel = this._propulsionClass.getMaxMoveBurnLevel();
/**
* @type PointLightSource
*/
this._lightSource = null;
}
/**
* @type PropulsionClass~ResourceParams
Expand All @@ -3503,8 +3512,12 @@ define([
* @param {Boolean} [replaceVisualModel=false] Whether to set the newly created
* renderable node as the visual model of the thruster even if one already
* existed before
* @param {Boolean} [addLightSource=true] Whether to add a point light source
* emitting with the same color as the burn particle at the position of the particle,
* with strength based on the thruster slot's size and lightFactor and the current
* burn rate
*/
Thruster.prototype.addToScene = function (parentNode, replaceVisualModel) {
Thruster.prototype.addToScene = function (parentNode, replaceVisualModel, addLightSource) {
var visualModel;
this._propulsionClass.acquireResources(Thruster.PROPULSION_RESOURCE_PARAMS);
resources.executeWhenReady(function () {
Expand All @@ -3518,6 +3531,14 @@ define([
this._propulsionClass.getThrusterBurnParticle().getInstancedShader());
visualModel.setRelativeSize(0);
parentNode.addSubnode(new sceneGraph.RenderableNode(visualModel, false, false, true));
if (_dynamicLights && (addLightSource !== false) && (this._slot.lightFactor > 0)) {
this._lightSource = new lights.PointLightSource(
this._propulsionClass.getThrusterBurnParticle().getColor(),
0,
this._slot.positionVector,
[parentNode.getRenderableObject()]);
parentNode.getScene().addPointLightSource(this._lightSource, constants.THRUSTER_LIGHT_PRIORITY);
}
if (!this._visualModel || replaceVisualModel) {
if (this._visualModel) {
this._visualModel.markAsReusable(true);
Expand All @@ -3540,6 +3561,9 @@ define([
this._slot.group,
Math.min(1.0, this._burnLevel / this._maxMoveBurnLevel));
}
if (this._lightSource) {
this._lightSource.setObjectIntensity(THRUSTER_LIGHT_INTENSITY_FACTOR * this._burnLevel * this._slot.size * this._slot.size * this._slot.lightFactor);
}
};
/**
* Sets the burn level of this thruster to zero.
Expand All @@ -3565,6 +3589,7 @@ define([
}
this._visualModel = null;
this._shipModel = null;
this._lightSource = null;
};
// #########################################################################
/**
Expand Down Expand Up @@ -3725,11 +3750,12 @@ define([
* Adds all necessary renderable objects under the passed parent node that
* can be used to render the propulsion system (and its thrusters).
* @param {RenderableNode} parentNode
* @param {Boolean} [addLightSources=true]
*/
Propulsion.prototype.addToScene = function (parentNode) {
Propulsion.prototype.addToScene = function (parentNode, addLightSources) {
var i;
for (i = 0; i < this._thrusters.length; i++) {
this._thrusters[i].addToScene(parentNode, false);
this._thrusters[i].addToScene(parentNode, false, addLightSources);
}
};
/**
Expand Down
1 change: 1 addition & 0 deletions src/js/armada/logic/missions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1788,6 +1788,7 @@ define([
weapons: true,
missilesInLaunchers: graphics.areMissilesInLaunchersVisible(),
thrusterParticles: !preview,
thrusterLightSources: !preview && graphics.shouldCreateLightSourcesForThrusters(),
projectileResources: !preview,
missileResources: !preview,
explosion: !preview,
Expand Down
3 changes: 2 additions & 1 deletion src/js/armada/logic/spacecraft.js
Original file line number Diff line number Diff line change
Expand Up @@ -1888,6 +1888,7 @@ define([
* loaded missiles behind the first one into the launch tubes (for displaying
* missile loadout in wireframe)
* @property {Boolean} thrusterParticles
* @property {Boolean} thrusterLightSources
* @property {Boolean} projectileResources
* @property {Boolean} missileResources
* @property {Boolean} explosion
Expand Down Expand Up @@ -2012,7 +2013,7 @@ define([
// add the thruster particles
if (addSupplements.thrusterParticles === true) {
if (this._propulsion) {
this._propulsion.addToScene(node);
this._propulsion.addToScene(node, addSupplements.thrusterLightSources);
}
}
// add projectile resources
Expand Down
Loading

0 comments on commit 125a72f

Please sign in to comment.