diff --git a/assets/opensb/interface/graphicsmenu/body.png.patch.lua b/assets/opensb/interface/graphicsmenu/body.png.patch.lua index 0c811cd..76ed0c4 100644 --- a/assets/opensb/interface/graphicsmenu/body.png.patch.lua +++ b/assets/opensb/interface/graphicsmenu/body.png.patch.lua @@ -1,6 +1,9 @@ function patch(image) -- Camera Pan Speed image:copyInto({119, 68}, image:process("?crop=19;68;117;87")) + local checkbox = image:process("?crop=19;26;117;35") -- Anti-Aliasing - image:copyInto({119, 26}, image:process("?crop=19;26;117;35")) + image:copyInto({119, 26}, checkbox) + -- Object Lighting + image:copyInto({19, 15}, checkbox) end \ No newline at end of file diff --git a/assets/opensb/interface/windowconfig/graphicsmenu.config.patch.lua b/assets/opensb/interface/windowconfig/graphicsmenu.config.patch.lua index 7e9081a..3f28954 100644 --- a/assets/opensb/interface/windowconfig/graphicsmenu.config.patch.lua +++ b/assets/opensb/interface/windowconfig/graphicsmenu.config.patch.lua @@ -28,6 +28,8 @@ function patch(config) -- Create anti-aliasing toggle shift(clone(layout, "multiTextureLabel", "antiAliasingLabel"), 98).value = "SUPER-SAMPLED AA" shift(clone(layout, "multiTextureCheckbox", "antiAliasingCheckbox"), 99) - +-- Create object lighting toggle + shift(clone(layout, "multiTextureLabel", "objectLightingLabel"), 0, -11).value = "NEW OBJECT LIGHTS" + shift(clone(layout, "multiTextureCheckbox", "objectLightingCheckbox"), 0, -11) return config end \ No newline at end of file diff --git a/assets/opensb/rendering/error.png b/assets/opensb/rendering/error.png new file mode 100644 index 0000000..b5bd3e7 Binary files /dev/null and b/assets/opensb/rendering/error.png differ diff --git a/assets/opensb/rendering/error_left.png b/assets/opensb/rendering/error_left.png new file mode 100644 index 0000000..2f4ec6f Binary files /dev/null and b/assets/opensb/rendering/error_left.png differ diff --git a/assets/opensb/rendering/error_right.png b/assets/opensb/rendering/error_right.png new file mode 100644 index 0000000..1fadd17 Binary files /dev/null and b/assets/opensb/rendering/error_right.png differ diff --git a/source/base/StarCellularLightArray.cpp b/source/base/StarCellularLightArray.cpp index 99490ce..49e0917 100644 --- a/source/base/StarCellularLightArray.cpp +++ b/source/base/StarCellularLightArray.cpp @@ -67,7 +67,7 @@ void CellularLightArray::calculatePointLighting(size_t xmin, auto newLight = ScalarLightTraits::subtract(light.value, attenuation); if (ScalarLightTraits::maxIntensity(newLight) > 0.0001f) { if (light.asSpread) - setLight(x, y, lvalue + newLight * 0.25f); + setLight(x, y, lvalue + newLight * 0.15f); else setLight(x, y, lvalue + newLight); } @@ -140,7 +140,7 @@ void CellularLightArray::calculatePointLighting(size_t xmin, auto newLight = ColoredLightTraits::subtract(light.value, attenuation); if (ColoredLightTraits::maxIntensity(newLight) > 0.0001f) { if (light.asSpread) - setLight(x, y, lvalue + newLight * 0.25f); + setLight(x, y, lvalue + newLight * 0.15f); else setLight(x, y, lvalue + newLight); } diff --git a/source/core/StarLua.cpp b/source/core/StarLua.cpp index 4499ebc..73955f2 100644 --- a/source/core/StarLua.cpp +++ b/source/core/StarLua.cpp @@ -461,6 +461,13 @@ ByteArray LuaEngine::compile(ByteArray const& contents, String const& name) { return compile(contents.ptr(), contents.size(), name.empty() ? nullptr : name.utf8Ptr()); } +lua_Debug const& LuaEngine::debugInfo(int level, const char* what) { + lua_Debug& debug = m_debugInfo = lua_Debug(); + lua_getstack(m_state, level, &debug); + lua_getinfo(m_state, what, &debug); + return debug; +} + LuaString LuaEngine::createString(String const& str) { lua_checkstack(m_state, 1); diff --git a/source/core/StarLua.hpp b/source/core/StarLua.hpp index 2fe275d..09e81e6 100644 --- a/source/core/StarLua.hpp +++ b/source/core/StarLua.hpp @@ -519,6 +519,9 @@ public: ByteArray compile(char const* contents, size_t size, char const* name = nullptr); ByteArray compile(String const& contents, String const& name = String()); ByteArray compile(ByteArray const& contents, String const& name = String()); + + // Returns the debug info of the state. + lua_Debug const& debugInfo(int level = 1, const char* what = "nSlu"); // Generic from/to lua conversion, calls template specialization of // LuaConverter for actual conversion. @@ -734,6 +737,7 @@ private: unsigned m_recursionLimit; int m_nullTerminated; HashMap, shared_ptr> m_profileEntries; + lua_Debug m_debugInfo; }; // Built in conversions diff --git a/source/frontend/StarGraphicsMenu.cpp b/source/frontend/StarGraphicsMenu.cpp index 0a87ef6..210b318 100644 --- a/source/frontend/StarGraphicsMenu.cpp +++ b/source/frontend/StarGraphicsMenu.cpp @@ -86,6 +86,12 @@ GraphicsMenu::GraphicsMenu() { Root::singleton().configuration()->set("monochromeLighting", checked); syncGui(); }); + reader.registerCallback("objectLightingCheckbox", [=](Widget*) { + bool checked = fetchChild("objectLightingCheckbox")->isChecked(); + m_localChanges.set("newObjectLighting", checked); + Root::singleton().configuration()->set("newObjectLighting", checked); + syncGui(); + }); auto assets = Root::singleton().assets(); @@ -140,7 +146,8 @@ StringList const GraphicsMenu::ConfigKeys = { "limitTextureAtlasSize", "useMultiTexturing", "antiAliasing", - "monochromeLighting" + "monochromeLighting", + "newObjectLighting" }; void GraphicsMenu::initConfig() { @@ -196,6 +203,7 @@ void GraphicsMenu::syncGui() { fetchChild("multiTextureCheckbox")->setChecked(m_localChanges.get("useMultiTexturing").optBool().value(true)); fetchChild("antiAliasingCheckbox")->setChecked(m_localChanges.get("antiAliasing").toBool()); fetchChild("monochromeCheckbox")->setChecked(m_localChanges.get("monochromeLighting").toBool()); + fetchChild("objectLightingCheckbox")->setChecked(m_localChanges.get("newObjectLighting").optBool().value(true)); } void GraphicsMenu::apply() { diff --git a/source/game/StarWorldClient.cpp b/source/game/StarWorldClient.cpp index 3b8f1a3..eaea2b2 100644 --- a/source/game/StarWorldClient.cpp +++ b/source/game/StarWorldClient.cpp @@ -489,7 +489,21 @@ void WorldClient::render(WorldRenderData& renderData, unsigned bufferTiles) { ClientRenderCallback renderCallback; - entity->render(&renderCallback); + try { entity->render(&renderCallback); } + catch (StarException const& e) { + if (entity->isMaster()) // this is YOUR problem!! + throw e; + else { // this is THEIR problem!! + Logger::error("WorldClient: Exception caught in {}::render ({}): {}", EntityTypeNames.getRight(entity->entityType()), entity->entityId(), e.what()); + auto toolUser = as(entity); + String image = toolUser ? strf("/rendering/error_{}.png", DirectionNames.getRight(toolUser->facingDirection())) : "/rendering/error.png"; + Color color = Color::rgbf(0.8f + (float)sin(m_currentTime * Constants::pi * 0.5) * 0.2f, 0.0f, 0.0f); + auto drawable = Drawable::makeImage(image, 1.0f / TilePixels, true, entity->position(), color); + drawable.fullbright = true; + renderCallback.addDrawable(std::move(drawable), RenderLayerMiddleParticle); + } + } + EntityDrawables ed; for (auto& p : renderCallback.drawables) { @@ -1110,7 +1124,13 @@ void WorldClient::update(float dt) { List toRemove; List clientPresenceEntities; m_entityMap->updateAllEntities([&](EntityPtr const& entity) { - entity->update(dt, m_currentStep); + try { entity->update(dt, m_currentStep); } + catch (StarException const& e) { + if (entity->isMaster()) // this is YOUR problem!! + throw e; + else // this is THEIR problem!! + Logger::error("WorldClient: Exception caught in {}::update ({}): {}", EntityTypeNames.getRight(entity->entityType()), entity->entityId(), e.what()); + } if (entity->shouldDestroy() && entity->entityMode() == EntityMode::Master) toRemove.append(entity->entityId()); @@ -1649,23 +1669,27 @@ void WorldClient::lightingCalc() { RectI lightRange = m_pendingLightRange; List lights = std::move(m_pendingLights); List> particleLights = std::move(m_pendingParticleLights); - m_lightingCalculator.setMonochrome(Root::singleton().configuration()->get("monochromeLighting").toBool()); + auto configuration = Root::singleton().configuration(); + bool monochrome = configuration->get("monochromeLighting").toBool(); + m_lightingCalculator.setMonochrome(monochrome); m_lightingCalculator.begin(lightRange); lightingTileGather(); prepLocker.unlock(); - - + bool useHybridPointLights = configuration->get("newObjectLighting").optBool().value(true); for (auto const& light : lights) { Vec2F position = m_geometry.nearestTo(Vec2F(m_lightingCalculator.calculationRegion().min()), light.position); if (light.type == LightType::Spread) m_lightingCalculator.addSpreadLight(position, light.color); else { if (light.type == LightType::PointAsSpread) { - // hybrid (used for auto-converted object lights) - 75% spread, 25% point (2nd is applied elsewhere) - m_lightingCalculator.addSpreadLight(position, light.color * 0.75f); - m_lightingCalculator.addPointLight(position, light.color, light.pointBeam, light.beamAngle, light.beamAmbience, true); + if (!useHybridPointLights) + m_lightingCalculator.addSpreadLight(position, light.color); + else { // hybrid (used for auto-converted object lights) - 85% spread, 15% point (2nd is applied elsewhere) + m_lightingCalculator.addSpreadLight(position, light.color * 0.85f); + m_lightingCalculator.addPointLight(position, light.color, light.pointBeam, light.beamAngle, light.beamAmbience, true); + } } else // fully additive point light m_lightingCalculator.addPointLight(position, light.color, light.pointBeam, light.beamAngle, light.beamAmbience); } diff --git a/source/rendering/StarFontTextureGroup.cpp b/source/rendering/StarFontTextureGroup.cpp index d5ad88d..e8f701a 100644 --- a/source/rendering/StarFontTextureGroup.cpp +++ b/source/rendering/StarFontTextureGroup.cpp @@ -56,7 +56,7 @@ const FontTextureGroup::GlyphTexture& FontTextureGroup::glyphTexture(String::Cha res.first->second.offset = (preSize - Vec2F(image.size())) / 2; } - catch (StarException&) { + catch (StarException const&) { image.forEachPixel([](unsigned x, unsigned y, Vec4B& pixel) { pixel = ((x + y) % 2 == 0) ? Vec4B(255, 0, 255, pixel[3]) : Vec4B(0, 0, 0, pixel[3]); });