new object lighting toggle, log non-master entity render/update exceptions

This commit is contained in:
Kae 2024-04-15 08:03:26 +10:00
parent ed8b22c472
commit 227e60ca4c
11 changed files with 62 additions and 14 deletions

View File

@ -1,6 +1,9 @@
function patch(image) function patch(image)
-- Camera Pan Speed -- Camera Pan Speed
image:copyInto({119, 68}, image:process("?crop=19;68;117;87")) image:copyInto({119, 68}, image:process("?crop=19;68;117;87"))
local checkbox = image:process("?crop=19;26;117;35")
-- Anti-Aliasing -- 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 end

View File

@ -28,6 +28,8 @@ function patch(config)
-- Create anti-aliasing toggle -- Create anti-aliasing toggle
shift(clone(layout, "multiTextureLabel", "antiAliasingLabel"), 98).value = "SUPER-SAMPLED AA" shift(clone(layout, "multiTextureLabel", "antiAliasingLabel"), 98).value = "SUPER-SAMPLED AA"
shift(clone(layout, "multiTextureCheckbox", "antiAliasingCheckbox"), 99) 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 return config
end end

Binary file not shown.

After

Width:  |  Height:  |  Size: 145 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 178 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 174 B

View File

@ -67,7 +67,7 @@ void CellularLightArray<ScalarLightTraits>::calculatePointLighting(size_t xmin,
auto newLight = ScalarLightTraits::subtract(light.value, attenuation); auto newLight = ScalarLightTraits::subtract(light.value, attenuation);
if (ScalarLightTraits::maxIntensity(newLight) > 0.0001f) { if (ScalarLightTraits::maxIntensity(newLight) > 0.0001f) {
if (light.asSpread) if (light.asSpread)
setLight(x, y, lvalue + newLight * 0.25f); setLight(x, y, lvalue + newLight * 0.15f);
else else
setLight(x, y, lvalue + newLight); setLight(x, y, lvalue + newLight);
} }
@ -140,7 +140,7 @@ void CellularLightArray<ColoredLightTraits>::calculatePointLighting(size_t xmin,
auto newLight = ColoredLightTraits::subtract(light.value, attenuation); auto newLight = ColoredLightTraits::subtract(light.value, attenuation);
if (ColoredLightTraits::maxIntensity(newLight) > 0.0001f) { if (ColoredLightTraits::maxIntensity(newLight) > 0.0001f) {
if (light.asSpread) if (light.asSpread)
setLight(x, y, lvalue + newLight * 0.25f); setLight(x, y, lvalue + newLight * 0.15f);
else else
setLight(x, y, lvalue + newLight); setLight(x, y, lvalue + newLight);
} }

View File

@ -461,6 +461,13 @@ ByteArray LuaEngine::compile(ByteArray const& contents, String const& name) {
return compile(contents.ptr(), contents.size(), name.empty() ? nullptr : name.utf8Ptr()); 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) { LuaString LuaEngine::createString(String const& str) {
lua_checkstack(m_state, 1); lua_checkstack(m_state, 1);

View File

@ -520,6 +520,9 @@ public:
ByteArray compile(String const& contents, String const& name = String()); ByteArray compile(String const& contents, String const& name = String());
ByteArray compile(ByteArray 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 // Generic from/to lua conversion, calls template specialization of
// LuaConverter for actual conversion. // LuaConverter for actual conversion.
template <typename T> template <typename T>
@ -734,6 +737,7 @@ private:
unsigned m_recursionLimit; unsigned m_recursionLimit;
int m_nullTerminated; int m_nullTerminated;
HashMap<tuple<String, unsigned>, shared_ptr<LuaProfileEntry>> m_profileEntries; HashMap<tuple<String, unsigned>, shared_ptr<LuaProfileEntry>> m_profileEntries;
lua_Debug m_debugInfo;
}; };
// Built in conversions // Built in conversions

View File

@ -86,6 +86,12 @@ GraphicsMenu::GraphicsMenu() {
Root::singleton().configuration()->set("monochromeLighting", checked); Root::singleton().configuration()->set("monochromeLighting", checked);
syncGui(); syncGui();
}); });
reader.registerCallback("objectLightingCheckbox", [=](Widget*) {
bool checked = fetchChild<ButtonWidget>("objectLightingCheckbox")->isChecked();
m_localChanges.set("newObjectLighting", checked);
Root::singleton().configuration()->set("newObjectLighting", checked);
syncGui();
});
auto assets = Root::singleton().assets(); auto assets = Root::singleton().assets();
@ -140,7 +146,8 @@ StringList const GraphicsMenu::ConfigKeys = {
"limitTextureAtlasSize", "limitTextureAtlasSize",
"useMultiTexturing", "useMultiTexturing",
"antiAliasing", "antiAliasing",
"monochromeLighting" "monochromeLighting",
"newObjectLighting"
}; };
void GraphicsMenu::initConfig() { void GraphicsMenu::initConfig() {
@ -196,6 +203,7 @@ void GraphicsMenu::syncGui() {
fetchChild<ButtonWidget>("multiTextureCheckbox")->setChecked(m_localChanges.get("useMultiTexturing").optBool().value(true)); fetchChild<ButtonWidget>("multiTextureCheckbox")->setChecked(m_localChanges.get("useMultiTexturing").optBool().value(true));
fetchChild<ButtonWidget>("antiAliasingCheckbox")->setChecked(m_localChanges.get("antiAliasing").toBool()); fetchChild<ButtonWidget>("antiAliasingCheckbox")->setChecked(m_localChanges.get("antiAliasing").toBool());
fetchChild<ButtonWidget>("monochromeCheckbox")->setChecked(m_localChanges.get("monochromeLighting").toBool()); fetchChild<ButtonWidget>("monochromeCheckbox")->setChecked(m_localChanges.get("monochromeLighting").toBool());
fetchChild<ButtonWidget>("objectLightingCheckbox")->setChecked(m_localChanges.get("newObjectLighting").optBool().value(true));
} }
void GraphicsMenu::apply() { void GraphicsMenu::apply() {

View File

@ -489,7 +489,21 @@ void WorldClient::render(WorldRenderData& renderData, unsigned bufferTiles) {
ClientRenderCallback renderCallback; 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<ToolUserEntity>(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; EntityDrawables ed;
for (auto& p : renderCallback.drawables) { for (auto& p : renderCallback.drawables) {
@ -1110,7 +1124,13 @@ void WorldClient::update(float dt) {
List<EntityId> toRemove; List<EntityId> toRemove;
List<EntityId> clientPresenceEntities; List<EntityId> clientPresenceEntities;
m_entityMap->updateAllEntities([&](EntityPtr const& entity) { 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) if (entity->shouldDestroy() && entity->entityMode() == EntityMode::Master)
toRemove.append(entity->entityId()); toRemove.append(entity->entityId());
@ -1649,23 +1669,27 @@ void WorldClient::lightingCalc() {
RectI lightRange = m_pendingLightRange; RectI lightRange = m_pendingLightRange;
List<LightSource> lights = std::move(m_pendingLights); List<LightSource> lights = std::move(m_pendingLights);
List<std::pair<Vec2F, Vec3F>> particleLights = std::move(m_pendingParticleLights); List<std::pair<Vec2F, Vec3F>> 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); m_lightingCalculator.begin(lightRange);
lightingTileGather(); lightingTileGather();
prepLocker.unlock(); prepLocker.unlock();
bool useHybridPointLights = configuration->get("newObjectLighting").optBool().value(true);
for (auto const& light : lights) { for (auto const& light : lights) {
Vec2F position = m_geometry.nearestTo(Vec2F(m_lightingCalculator.calculationRegion().min()), light.position); Vec2F position = m_geometry.nearestTo(Vec2F(m_lightingCalculator.calculationRegion().min()), light.position);
if (light.type == LightType::Spread) if (light.type == LightType::Spread)
m_lightingCalculator.addSpreadLight(position, light.color); m_lightingCalculator.addSpreadLight(position, light.color);
else { else {
if (light.type == LightType::PointAsSpread) { if (light.type == LightType::PointAsSpread) {
// hybrid (used for auto-converted object lights) - 75% spread, 25% point (2nd is applied elsewhere) if (!useHybridPointLights)
m_lightingCalculator.addSpreadLight(position, light.color * 0.75f); 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); m_lightingCalculator.addPointLight(position, light.color, light.pointBeam, light.beamAngle, light.beamAmbience, true);
}
} else // fully additive point light } else // fully additive point light
m_lightingCalculator.addPointLight(position, light.color, light.pointBeam, light.beamAngle, light.beamAmbience); m_lightingCalculator.addPointLight(position, light.color, light.pointBeam, light.beamAngle, light.beamAmbience);
} }

View File

@ -56,7 +56,7 @@ const FontTextureGroup::GlyphTexture& FontTextureGroup::glyphTexture(String::Cha
res.first->second.offset = (preSize - Vec2F(image.size())) / 2; res.first->second.offset = (preSize - Vec2F(image.size())) / 2;
} }
catch (StarException&) { catch (StarException const&) {
image.forEachPixel([](unsigned x, unsigned y, Vec4B& pixel) { 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]); pixel = ((x + y) % 2 == 0) ? Vec4B(255, 0, 255, pixel[3]) : Vec4B(0, 0, 0, pixel[3]);
}); });