diff options
-rw-r--r-- | assets/opensb/interface.config.patch | 5 | ||||
-rw-r--r-- | assets/opensb/interface/chat/chat.config.patch | 2 | ||||
-rw-r--r-- | assets/opensb/interface/windowconfig/chatbubbles.config.patch | 3 | ||||
-rw-r--r-- | source/core/StarJsonExtra.cpp | 18 | ||||
-rw-r--r-- | source/core/StarJsonExtra.hpp | 3 | ||||
-rw-r--r-- | source/game/StarObject.cpp | 53 | ||||
-rw-r--r-- | source/game/StarObject.hpp | 2 | ||||
-rw-r--r-- | source/game/StarParallax.cpp | 26 | ||||
-rw-r--r-- | source/game/StarParallax.hpp | 7 | ||||
-rw-r--r-- | source/game/StarWorldClient.cpp | 27 | ||||
-rw-r--r-- | source/game/StarWorldParameters.cpp | 10 | ||||
-rw-r--r-- | source/game/StarWorldParameters.hpp | 2 | ||||
-rw-r--r-- | source/rendering/StarEnvironmentPainter.cpp | 18 | ||||
-rw-r--r-- | source/rendering/StarWorldPainter.cpp | 2 | ||||
-rw-r--r-- | source/rendering/StarWorldPainter.hpp | 2 |
15 files changed, 119 insertions, 61 deletions
diff --git a/assets/opensb/interface.config.patch b/assets/opensb/interface.config.patch index 1048500..eb33cb8 100644 --- a/assets/opensb/interface.config.patch +++ b/assets/opensb/interface.config.patch @@ -1,8 +1,9 @@ { "nametag" : { "showMasterNames" : true, - "fontDirectives" : "?border=2;444;4440", - "inspectOpacityRate" : 0.15 + "fontDirectives" : "?border=1;222;2220", + "inspectOpacityRate" : 0.15, + "movementThreshold" : 0.5 }, "font" : { "defaultDirectives" : "", diff --git a/assets/opensb/interface/chat/chat.config.patch b/assets/opensb/interface/chat/chat.config.patch index f8a8caa..11fd758 100644 --- a/assets/opensb/interface/chat/chat.config.patch +++ b/assets/opensb/interface/chat/chat.config.patch @@ -1,7 +1,7 @@ { "config" : { "font" : { - "directives" : "?border=1;333a;3330", + "directives" : "?border=1;111a;1110", "padding" : [1, 1] // Padding to prevent border clipping at the edges of the log canvas while keeping compat with mods that patch the canvas size }, "colors" : { diff --git a/assets/opensb/interface/windowconfig/chatbubbles.config.patch b/assets/opensb/interface/windowconfig/chatbubbles.config.patch new file mode 100644 index 0000000..5aed747 --- /dev/null +++ b/assets/opensb/interface/windowconfig/chatbubbles.config.patch @@ -0,0 +1,3 @@ +{ + "movementThreshold" : 0.5 +}
\ No newline at end of file diff --git a/source/core/StarJsonExtra.cpp b/source/core/StarJsonExtra.cpp index 7a660d1..aed4989 100644 --- a/source/core/StarJsonExtra.cpp +++ b/source/core/StarJsonExtra.cpp @@ -301,7 +301,7 @@ StringList jsonToStringList(Json const& v) { Json jsonFromStringList(List<String> const& v) { JsonArray result; - for (auto e : v) + for (auto& e : v) result.push_back(e); return result; } @@ -322,7 +322,7 @@ StringSet jsonToStringSet(Json const& v) { Json jsonFromStringSet(StringSet const& v) { JsonArray result; - for (auto e : v) + for (auto& e : v) result.push_back(e); return result; } @@ -369,6 +369,20 @@ List<Color> jsonToColorList(Json const& v) { return result; } +List<Directives> jsonToDirectivesList(Json const& v) { + List<Directives> result; + for (auto const& entry : v.iterateArray()) + result.append(move(entry.toString())); + return result; +} + +Json jsonFromDirectivesList(List<Directives> const& v) { + JsonArray result; + for (auto& e : v) + result.push_back(e.toString()); + return result; +} + Json weightedChoiceFromJson(Json const& source, Json const& default_) { if (source.isNull()) return default_; diff --git a/source/core/StarJsonExtra.hpp b/source/core/StarJsonExtra.hpp index 3bf5b9c..cfe7efb 100644 --- a/source/core/StarJsonExtra.hpp +++ b/source/core/StarJsonExtra.hpp @@ -6,6 +6,7 @@ #include "StarColor.hpp" #include "StarSet.hpp" #include "StarWeightedPool.hpp" +#include "StarDirectives.hpp" namespace Star { @@ -81,6 +82,8 @@ List<Vec2U> jsonToVec2UList(Json const& v); List<Vec2F> jsonToVec2FList(Json const& v); List<Vec4B> jsonToVec4BList(Json const& v); List<Color> jsonToColorList(Json const& v); +List<Directives> jsonToDirectivesList(Json const& v); +Json jsonFromDirectivesList(List<Directives> const& v); Json weightedChoiceFromJson(Json const& source, Json const& default_); diff --git a/source/game/StarObject.cpp b/source/game/StarObject.cpp index df3ecdf..43a8574 100644 --- a/source/game/StarObject.cpp +++ b/source/game/StarObject.cpp @@ -143,21 +143,23 @@ void Object::init(World* world, EntityId entityId, EntityMode mode) { m_orientationDrawablesCache.reset(); - if (isMaster()) { - auto colorName = configValue("color", "default").toString(); - auto colorEnd = colorName.find('?'); - if (colorEnd != NPos) { - setImageKey("color", colorName); - m_colorDirectives = colorName.substr(colorEnd); - } - else - m_colorDirectives = ""; + // This is stupid and we should only have to deal with the new directives parameter, but blah blah backwards compatibility. + auto colorName = configValue("color", "default").toString(); + auto colorEnd = colorName.find('?'); + if (colorEnd != NPos) { + m_colorDirectives = colorName.substr(colorEnd); + } + else + m_colorDirectives = ""; - m_directives = ""; - if (auto directives = configValue("")) { - if (directives.isType(Json::Type::String)) - m_directives.parse(directives.toString()); - } + m_directives = ""; + if (auto directives = configValue("")) { + if (directives.isType(Json::Type::String)) + m_directives.parse(directives.toString()); + } + + if (isMaster()) { + setImageKey("color", colorName); if (m_config->lightColors.contains(colorName)) m_lightSourceColor.set(m_config->lightColors.get(colorName)); @@ -562,7 +564,7 @@ List<Drawable> Object::cursorHintDrawables() const { if (m_direction.get() == Direction::Left) placementImage += "?flipx"; Drawable imageDrawable = Drawable::makeImage(AssetPath::relativeTo(m_config->path, placementImage), - 1.0 / TilePixels, false, jsonToVec2F(configValue("placementImagePosition")) / TilePixels); + 1.0 / TilePixels, false, jsonToVec2F(configValue("placementImagePosition", jsonFromVec2F(Vec2F()))) / TilePixels); return {imageDrawable}; } else { if (m_orientationIndex != NPos) { @@ -1217,11 +1219,26 @@ List<Drawable> Object::orientationDrawables(size_t orientationIndex) const { m_orientationDrawablesCache = make_pair(orientationIndex, List<Drawable>()); for (auto const& layer : orientation->imageLayers) { Drawable drawable = layer; + auto& imagePart = drawable.imagePart(); imagePart.image.directives.clear(); - imagePart.image = AssetPath::join(imagePart.image).replaceTags(m_imageKeys, true, "default"); - imagePart.image.directives = layer.imagePart().image.directives; - imagePart.addDirectives(m_colorDirectives).addDirectives(m_directives); + String imagePath = AssetPath::join(imagePart.image); + if (m_colorDirectives && m_imageKeys.contains("color")) { // We had to leave color untouched despite separating its directives for server-side compatibility reasons, temporarily substr it in the image key + String& color = m_imageKeys.find("color")->second; + String backup = move(color); + color = backup.substr(0, backup.find('?')); + imagePart.image = imagePath.replaceTags(m_imageKeys, true, "default"); + color = move(backup); + + imagePart.image.directives = layer.imagePart().image.directives; + imagePart.addDirectives(m_colorDirectives); + } + else { + imagePart.image = imagePath.replaceTags(m_imageKeys, true, "default"); + imagePart.image.directives = layer.imagePart().image.directives; + } + + imagePart.addDirectives(m_directives); if (orientation->flipImages) drawable.scale(Vec2F(-1, 1), drawable.boundBox(false).center() - drawable.position); diff --git a/source/game/StarObject.hpp b/source/game/StarObject.hpp index 3d5f302..eb039e8 100644 --- a/source/game/StarObject.hpp +++ b/source/game/StarObject.hpp @@ -232,7 +232,7 @@ private: size_t m_orientationIndex; NetElementSize m_orientationIndexNetState; NetElementHashMap<String, String> m_netImageKeys; - StringMap<String> m_imageKeys; + mutable StringMap<String> m_imageKeys; void resetEmissionTimers(); List<GameTimer> m_emissionTimers; diff --git a/source/game/StarParallax.cpp b/source/game/StarParallax.cpp index b676e24..a950086 100644 --- a/source/game/StarParallax.cpp +++ b/source/game/StarParallax.cpp @@ -39,8 +39,9 @@ ParallaxLayer::ParallaxLayer(Json const& store) : ParallaxLayer() { } Json ParallaxLayer::store() const { - return JsonObject{{"textures", jsonFromStringList(textures)}, - {"directives", directives}, + return JsonObject{ + {"textures", jsonFromStringList(textures)}, + {"directives", directives.toString()}, {"parallaxValue", jsonFromVec2F(parallaxValue)}, {"repeat", jsonFromVec2B(repeat)}, {"tileLimitTop", jsonFromMaybe(tileLimitTop)}, @@ -55,9 +56,18 @@ Json ParallaxLayer::store() const { {"fadePercent", fadePercent}}; } -void ParallaxLayer::addImageDirectives(String const& newDirectives) { - if (!newDirectives.empty()) - directives = String::joinWith("?", directives, newDirectives); +void ParallaxLayer::addImageDirectives(Directives const& newDirectives) { + if (newDirectives) { // TODO: Move to Directives += + if (directives) { + List<Directives::Entry> newEntries = *directives.entries; + for (auto const& entry : *newDirectives.entries) + newEntries.push_back(entry); + + directives = move(newEntries); + } + else + directives = newDirectives; + } } void ParallaxLayer::fadeToSkyColor(Color skyColor) { @@ -225,11 +235,11 @@ void Parallax::buildLayer(Json const& layerSettings, String const& kind) { layer.addImageDirectives(layerSettings.getString("directives", "")); if (isFoliage) - layer.addImageDirectives(strf("hueshift=%s", m_parallaxTreeVariant->foliageHueShift)); + layer.addImageDirectives(String(strf("hueshift=%s", m_parallaxTreeVariant->foliageHueShift))); else if (isStem) - layer.addImageDirectives(strf("hueshift=%s", m_parallaxTreeVariant->stemHueShift)); + layer.addImageDirectives(String(strf("hueshift=%s", m_parallaxTreeVariant->stemHueShift))); else if (!layerSettings.getBool("nohueshift", false)) - layer.addImageDirectives(strf("hueshift=%s", m_hueShift)); + layer.addImageDirectives(String(strf("hueshift=%s", m_hueShift))); layer.fadePercent = layerSettings.getFloat("fadePercent", 0); diff --git a/source/game/StarParallax.hpp b/source/game/StarParallax.hpp index d3e36eb..ca82564 100644 --- a/source/game/StarParallax.hpp +++ b/source/game/StarParallax.hpp @@ -4,6 +4,7 @@ #include "StarMaybe.hpp" #include "StarColor.hpp" #include "StarPlantDatabase.hpp" +#include "StarDirectives.hpp" namespace Star { @@ -16,11 +17,11 @@ struct ParallaxLayer { Json store() const; - void addImageDirectives(String const& newDirectives); + void addImageDirectives(Directives const& newDirectives); void fadeToSkyColor(Color skyColor); - StringList textures; - String directives; + List<String> textures; + Directives directives; float alpha; Vec2F parallaxValue; Vec2B repeat; diff --git a/source/game/StarWorldClient.cpp b/source/game/StarWorldClient.cpp index 91701e5..269bbca 100644 --- a/source/game/StarWorldClient.cpp +++ b/source/game/StarWorldClient.cpp @@ -356,10 +356,11 @@ void WorldClient::render(WorldRenderData& renderData, unsigned bufferTiles) { playerAimInteractive = entity->entityId(); } - Maybe<StringList> directives; - if (auto worldTemplate = m_worldTemplate) { - if(auto parameters = worldTemplate->worldParameters()) - directives = m_worldTemplate->worldParameters()->globalDirectives; + const List<Directives>* directives = nullptr; + if (auto& worldTemplate = m_worldTemplate) { + if (auto& parameters = worldTemplate->worldParameters()) + if (auto& globalDirectives = m_worldTemplate->worldParameters()->globalDirectives) + directives = &globalDirectives.get(); } m_entityMap->forAllEntities([&](EntityPtr const& entity) { if (m_startupHiddenEntities.contains(entity->entityId())) @@ -1263,10 +1264,11 @@ void WorldClient::handleDamageNotifications() { auto hitParticles = particlesFromDefinition(damageKind.effects.get(material).get(effectHitType).particles, damageNotification.position); - Maybe<StringList> directives; - if (auto worldTemplate = m_worldTemplate) { - if(auto parameters = worldTemplate->worldParameters()) - directives = m_worldTemplate->worldParameters()->globalDirectives; + const List<Directives>* directives = nullptr; + if (auto& worldTemplate = m_worldTemplate) { + if (auto& parameters = worldTemplate->worldParameters()) + if (auto& globalDirectives = m_worldTemplate->worldParameters()->globalDirectives) + directives = &globalDirectives.get(); } if (directives) { int directiveIndex = unsigned(damageNotification.targetEntityId) % directives->size(); @@ -1332,10 +1334,11 @@ void WorldClient::removeEntity(EntityId entityId, bool andDie) { ClientRenderCallback renderCallback; entity->destroy(&renderCallback); - Maybe<StringList> directives; - if (auto worldTemplate = m_worldTemplate) { - if(auto parameters = worldTemplate->worldParameters()) - directives = m_worldTemplate->worldParameters()->globalDirectives; + const List<Directives>* directives = nullptr; + if (auto& worldTemplate = m_worldTemplate) { + if (auto& parameters = worldTemplate->worldParameters()) + if (auto& globalDirectives = m_worldTemplate->worldParameters()->globalDirectives) + directives = &globalDirectives.get(); } if (directives) { int directiveIndex = unsigned(entity->entityId()) % directives->size(); diff --git a/source/game/StarWorldParameters.cpp b/source/game/StarWorldParameters.cpp index 83270a9..343e294 100644 --- a/source/game/StarWorldParameters.cpp +++ b/source/game/StarWorldParameters.cpp @@ -47,7 +47,7 @@ VisitableWorldParameters::VisitableWorldParameters(Json const& store) { weatherPool = jsonToWeightedPool<String>(store.getArray("weatherPool", JsonArray())); environmentStatusEffects = store.opt("environmentStatusEffects").apply(jsonToStringList).value(); overrideTech = store.opt("overrideTech").apply(jsonToStringList); - globalDirectives = store.opt("globalDirectives").apply(jsonToStringList); + globalDirectives = store.opt("globalDirectives").apply(jsonToDirectivesList); beamUpRule = BeamUpRuleNames.getLeft(store.getString("beamUpRule", "Surface")); disableDeathDrops = store.getBool("disableDeathDrops", false); terraformed = store.getBool("terraformed", false); @@ -65,7 +65,7 @@ Json VisitableWorldParameters::store() const { {"weatherPool", jsonFromWeightedPool<String>(weatherPool)}, {"environmentStatusEffects", jsonFromStringList(environmentStatusEffects)}, {"overrideTech", jsonFromMaybe(overrideTech.apply(&jsonFromStringList))}, - {"globalDirectives", jsonFromMaybe(globalDirectives.apply(&jsonFromStringList))}, + {"globalDirectives", jsonFromMaybe(globalDirectives.apply(&jsonFromDirectivesList))}, {"beamUpRule", BeamUpRuleNames.getRight(beamUpRule)}, {"disableDeathDrops", disableDeathDrops}, {"terraformed", terraformed}, @@ -606,7 +606,7 @@ TerrestrialWorldParametersPtr generateTerrestrialWorldParameters(String const& t parameters->airless = biomeDatabase->biomeIsAirless(primaryBiome); parameters->environmentStatusEffects = biomeDatabase->biomeStatusEffects(primaryBiome); parameters->overrideTech = config.opt("overrideTech").apply(jsonToStringList); - parameters->globalDirectives = config.opt("globalDirectives").apply(jsonToStringList); + parameters->globalDirectives = config.opt("globalDirectives").apply(jsonToDirectivesList); parameters->beamUpRule = BeamUpRuleNames.getLeft(config.getString("beamUpRule", "Surface")); parameters->disableDeathDrops = config.getBool("disableDeathDrops", false); parameters->worldEdgeForceRegions = WorldEdgeForceRegionTypeNames.getLeft(config.getString("worldEdgeForceRegions", "Top")); @@ -658,7 +658,7 @@ AsteroidsWorldParametersPtr generateAsteroidsWorldParameters(uint64_t seed) { parameters->gravity = staticRandomFloatRange(gravityRange[0], gravityRange[1], seed, "WorldGravity"); parameters->environmentStatusEffects = jsonToStringList(asteroidsConfig.getArray("environmentStatusEffects", JsonArray())); parameters->overrideTech = asteroidsConfig.opt("overrideTech").apply(jsonToStringList); - parameters->globalDirectives = asteroidsConfig.opt("globalDirectives").apply(jsonToStringList); + parameters->globalDirectives = asteroidsConfig.opt("globalDirectives").apply(jsonToDirectivesList); parameters->beamUpRule = BeamUpRuleNames.getLeft(asteroidsConfig.getString("beamUpRule", "Surface")); parameters->disableDeathDrops = asteroidsConfig.getBool("disableDeathDrops", false); parameters->worldEdgeForceRegions = WorldEdgeForceRegionTypeNames.getLeft(asteroidsConfig.getString("worldEdgeForceRegions", "TopAndBottom")); @@ -687,7 +687,7 @@ FloatingDungeonWorldParametersPtr generateFloatingDungeonWorldParameters(String parameters->airless = worldConfig.getBool("airless", false); parameters->environmentStatusEffects = jsonToStringList(worldConfig.getArray("environmentStatusEffects", JsonArray())); parameters->overrideTech = worldConfig.opt("overrideTech").apply(jsonToStringList); - parameters->globalDirectives = worldConfig.opt("globalDirectives").apply(jsonToStringList); + parameters->globalDirectives = worldConfig.opt("globalDirectives").apply(jsonToDirectivesList); if (auto weatherPoolConfig = worldConfig.optArray("weatherPool")) parameters->weatherPool = jsonToWeightedPool<String>(*weatherPoolConfig); parameters->beamUpRule = BeamUpRuleNames.getLeft(worldConfig.getString("beamUpRule", "Surface")); diff --git a/source/game/StarWorldParameters.hpp b/source/game/StarWorldParameters.hpp index 3f7c01d..46f4f9c 100644 --- a/source/game/StarWorldParameters.hpp +++ b/source/game/StarWorldParameters.hpp @@ -58,7 +58,7 @@ struct VisitableWorldParameters { WeatherPool weatherPool; StringList environmentStatusEffects; Maybe<StringList> overrideTech; - Maybe<StringList> globalDirectives; + Maybe<List<Directives>> globalDirectives; BeamUpRule beamUpRule; bool disableDeathDrops; bool terraformed; diff --git a/source/rendering/StarEnvironmentPainter.cpp b/source/rendering/StarEnvironmentPainter.cpp index a495eda..9d3e45a 100644 --- a/source/rendering/StarEnvironmentPainter.cpp +++ b/source/rendering/StarEnvironmentPainter.cpp @@ -80,10 +80,10 @@ void EnvironmentPainter::renderStars(float pixelRatio, Vec2F const& screenSize, RectF viewRect = RectF::withSize(Vec2F(), viewSize).padded(screenBuffer); - for (auto star : stars) { + for (auto& star : stars) { Vec2F screenPos = transform.transformVec2(star.first); if (viewRect.contains(screenPos)) { - size_t starFrame = (int)(sky.epochTime + star.second.second) % sky.starFrames; + size_t starFrame = (size_t)(sky.epochTime + star.second.second) % sky.starFrames; auto const& texture = m_starTextures[star.second.first * sky.starFrames + starFrame]; m_renderer->render(renderTexturedRect(texture, screenPos * pixelRatio - Vec2F(texture->size()) / 2, 1.0, color, 0.0f)); } @@ -224,7 +224,7 @@ void EnvironmentPainter::renderParallaxLayers( // Note: the "parallax space" referenced below is a grid where the scale of each cell is the size of the parallax image - for (auto layer : layers) { + for (auto& layer : layers) { if (layer.alpha == 0) continue; @@ -237,8 +237,10 @@ void EnvironmentPainter::renderParallaxLayers( Vec2F parallaxValue = layer.parallaxValue; Vec2B parallaxRepeat = layer.repeat; Vec2F parallaxOrigin = {0.0f, layer.verticalOrigin}; - Vec2F parallaxSize = - Vec2F(m_textureGroup->loadTexture(String::joinWith("?", layer.textures.first(), layer.directives))->size()); + + AssetPath first = layer.textures.first(); + first.directives += layer.directives; + Vec2F parallaxSize = Vec2F(m_textureGroup->loadTexture(first)->size()); Vec2F parallaxPixels = parallaxSize * camera.pixelRatio(); // texture offset in *screen pixel space* @@ -300,8 +302,10 @@ void EnvironmentPainter::renderParallaxLayers( if (tileLimitBottom != bottom && y < tileLimitBottom) anchorPoint[1] += fpart(tileLimitBottom) * parallaxPixels[1]; - for (String const& textureImage : layer.textures) { - if (auto texture = m_textureGroup->tryTexture(String::joinWith("?", textureImage, layer.directives))) { + for (auto const& textureImage : layer.textures) { + AssetPath withDirectives = textureImage; + withDirectives.directives += layer.directives; + if (auto texture = m_textureGroup->tryTexture(withDirectives)) { RectF drawRect = RectF::withSize(anchorPoint, subImage.size() * camera.pixelRatio()); m_renderer->render(RenderQuad{move(texture), {{drawRect.xMin(), drawRect.yMin()}, {subImage.xMin(), subImage.yMin()}, drawColor, lightMapMultiplier}, diff --git a/source/rendering/StarWorldPainter.cpp b/source/rendering/StarWorldPainter.cpp index 74812b9..4b2324d 100644 --- a/source/rendering/StarWorldPainter.cpp +++ b/source/rendering/StarWorldPainter.cpp @@ -203,6 +203,8 @@ void WorldPainter::renderParticles(WorldRenderData& renderData, Particle::Layer if (size > 0) { m_textPainter->setFontSize(size); m_textPainter->setFontColor(particle.color.toRgba()); + m_textPainter->setProcessingDirectives(""); + m_textPainter->setFont(""); m_textPainter->renderText(particle.string, {position, HorizontalAnchor::HMidAnchor, VerticalAnchor::VMidAnchor}); } } diff --git a/source/rendering/StarWorldPainter.hpp b/source/rendering/StarWorldPainter.hpp index 92bc45d..ab57e48 100644 --- a/source/rendering/StarWorldPainter.hpp +++ b/source/rendering/StarWorldPainter.hpp @@ -44,7 +44,7 @@ private: TilePainterPtr m_tilePainter; Json m_highlightConfig; - Map<EntityHighlightEffectType, pair<String, String>> m_highlightDirectives; + Map<EntityHighlightEffectType, pair<Directives, Directives>> m_highlightDirectives; Vec2F m_entityBarOffset; Vec2F m_entityBarSpacing; |