Improve entity capturing

- Set velocity of VelocityComponent to zero
- Prevent some random explosions
- Make entity capture independent of screen capture
This commit is contained in:
David Vogel 2022-07-19 13:50:30 +02:00
parent 98f9c23064
commit 77bf19acf3
2 changed files with 81 additions and 19 deletions

View File

@ -42,10 +42,12 @@ local componentTypeNamesToDisable = {
"CharacterPlatformingComponent", "CharacterPlatformingComponent",
"WormComponent", "WormComponent",
"WormAIComponent", "WormAIComponent",
"DamageModelComponent", --"PhysicsBodyCollisionDamageComponent",
"PhysicsBodyCollisionDamageComponent", --"ExplodeOnDamageComponent",
"ExplodeOnDamageComponent", --"DamageModelComponent",
--"SpriteOffsetAnimatorComponent", --"SpriteOffsetAnimatorComponent",
--"MaterialInventoryComponent",
--"LuaComponent",
--"PhysicsBody2Component", -- Disabling will hide barrels and similar stuff, also triggers an assertion. --"PhysicsBody2Component", -- Disabling will hide barrels and similar stuff, also triggers an assertion.
--"PhysicsBodyComponent", --"PhysicsBodyComponent",
--"VelocityComponent", -- Disabling this component may cause a "...\component_updators\advancedfishai_system.cpp at line 107" exception. --"VelocityComponent", -- Disabling this component may cause a "...\component_updators\advancedfishai_system.cpp at line 107" exception.
@ -81,6 +83,7 @@ local function captureEntities(entityFile, x, y, radius)
local rootEntity = entity:GetRootEntity() local rootEntity = entity:GetRootEntity()
-- Make sure to only export entities when they are encountered the first time. -- Make sure to only export entities when they are encountered the first time.
if not rootEntity:HasTag("MapCaptured") then if not rootEntity:HasTag("MapCaptured") then
--print(rootEntity:GetFilename())
-- Some hacky way to generate valid JSON that doesn't break when the game crashes. -- Some hacky way to generate valid JSON that doesn't break when the game crashes.
-- Well, as long as it does not crash between write and flush. -- Well, as long as it does not crash between write and flush.
@ -109,6 +112,7 @@ local function captureEntities(entityFile, x, y, radius)
if component then if component then
component:SetValue("gravity_x", 0) component:SetValue("gravity_x", 0)
component:SetValue("gravity_y", 0) component:SetValue("gravity_y", 0)
component:SetValue("mVelocity", 0, 0)
end end
-- Modify the gravity of every CharacterPlatformingComponent, so mobs will not fall. -- Modify the gravity of every CharacterPlatformingComponent, so mobs will not fall.
@ -125,13 +129,41 @@ local function captureEntities(entityFile, x, y, radius)
end end
-- Disable the hover animation of cards. Disabling the "SpriteOffsetAnimatorComponent" does not help. -- Disable the hover animation of cards. Disabling the "SpriteOffsetAnimatorComponent" does not help.
--local components = rootEntity:GetComponents("SpriteOffsetAnimatorComponent") --[[local components = rootEntity:GetComponents("SpriteOffsetAnimatorComponent")
--for _, component in ipairs(components) do for _, component in ipairs(components) do
-- component:SetValue("x_speed", 0) component:SetValue("x_speed", 0)
-- component:SetValue("y_speed", 0) component:SetValue("y_speed", 0)
-- component:SetValue("x_amount", 0) component:SetValue("x_amount", 0)
-- component:SetValue("y_amount", 0) component:SetValue("y_amount", 0)
--end end]]
-- Try to prevent some stuff from exploding.
local component = rootEntity:GetFirstComponent("PhysicsBody2Component")
if component then
component:SetValue("kill_entity_if_body_destroyed", false)
component:SetValue("destroy_body_if_entity_destroyed", false)
component:SetValue("auto_clean", false)
end
-- Try to prevent some stuff from exploding.
local component = rootEntity:GetFirstComponent("DamageModelComponent")
if component then
component:SetValue("falling_damages", false)
end
-- Try to prevent some stuff from exploding.
local component = rootEntity:GetFirstComponent("ExplodeOnDamageComponent")
if component then
component:SetValue("explode_on_death_percent", 0)
print("What the hell?", component:ObjectGetValue("config_explosion", "damage"))
end
-- Try to prevent some stuff from exploding.
local component = rootEntity:GetFirstComponent("MaterialInventoryComponent")
if component then
component:SetValue("on_death_spill", false)
component:SetValue("kill_when_empty", false)
end
end end
end end
@ -140,6 +172,21 @@ local function captureEntities(entityFile, x, y, radius)
entityFile:flush() entityFile:flush()
end end
function DebugEntityCapture()
local entityFile = createOrOpenEntityCaptureFile()
-- Coroutine to capture all entities around the viewport every frame.
async_loop(function()
local x, y = GameGetCameraPos() -- Returns the virtual coordinates of the screen center.
-- Call the protected function and catch any errors.
local ok, err = pcall(captureEntities, entityFile, x, y, 5000)
if not ok then
print(string.format("Entity capture error: %s", err))
end
wait(0)
end)
end
--- Captures a screenshot at the given coordinates. --- Captures a screenshot at the given coordinates.
--- This will block until all chunks in the given area are loaded. --- This will block until all chunks in the given area are loaded.
--- ---
@ -147,8 +194,7 @@ end
--- @param y number -- Virtual y coordinate (World pixels) of the screen center. --- @param y number -- Virtual y coordinate (World pixels) of the screen center.
--- @param rx number -- Screen x coordinate of the top left corner of the screenshot rectangle. --- @param rx number -- Screen x coordinate of the top left corner of the screenshot rectangle.
--- @param ry number -- Screen y coordinate of the top left corner of the screenshot rectangle. --- @param ry number -- Screen y coordinate of the top left corner of the screenshot rectangle.
--- @param entityFile file* local function captureScreenshot(x, y, rx, ry)
local function captureScreenshot(x, y, rx, ry, entityFile)
local virtualWidth, virtualHeight = local virtualWidth, virtualHeight =
tonumber(MagicNumbersGetValue("VIRTUAL_RESOLUTION_X")), tonumber(MagicNumbersGetValue("VIRTUAL_RESOLUTION_X")),
tonumber(MagicNumbersGetValue("VIRTUAL_RESOLUTION_Y")) tonumber(MagicNumbersGetValue("VIRTUAL_RESOLUTION_Y"))
@ -173,12 +219,6 @@ local function captureScreenshot(x, y, rx, ry, entityFile)
wait(0) wait(0)
UiCaptureDelay = UiCaptureDelay + 1 UiCaptureDelay = UiCaptureDelay + 1
-- Capture all entities right after the camera frame was moved.
local ok, err = pcall(captureEntities, entityFile, x, y, 5000)
if not ok then
print(string.format("Entity capture error: %s", err))
end
until DoesWorldExistAt(xMin, yMin, xMax, yMax) -- Chunks will be drawn on the *next* frame. until DoesWorldExistAt(xMin, yMin, xMax, yMax) -- Chunks will be drawn on the *next* frame.
wait(0) -- Without this line empty chunks may still appear, also it's needed for the UI to disappear. wait(0) -- Without this line empty chunks may still appear, also it's needed for the UI to disappear.
@ -206,6 +246,17 @@ function startCapturingSpiral()
GameSetCameraFree(true) GameSetCameraFree(true)
-- Coroutine to capture all entities around the viewport every frame.
async_loop(function()
local x, y = GameGetCameraPos() -- Returns the virtual coordinates of the screen center.
-- Call the protected function and catch any errors.
local ok, err = pcall(captureEntities, entityFile, x, y, 5000)
if not ok then
print(string.format("Entity capture error: %s", err))
end
wait(0)
end)
-- Coroutine to calculate next coordinate, and trigger screenshots. -- Coroutine to calculate next coordinate, and trigger screenshots.
local i = 1 local i = 1
async_loop( async_loop(
@ -288,6 +339,17 @@ function startCapturingHilbert(area)
GameSetCameraFree(true) GameSetCameraFree(true)
-- Coroutine to capture all entities around the viewport every frame.
async_loop(function()
local x, y = GameGetCameraPos() -- Returns the virtual coordinates of the screen center.
-- Call the protected function and catch any errors.
local ok, err = pcall(captureEntities, entityFile, x, y, 5000)
if not ok then
print(string.format("Entity capture error: %s", err))
end
wait(0)
end)
-- Coroutine to calculate next coordinate, and trigger screenshots. -- Coroutine to calculate next coordinate, and trigger screenshots.
async( async(
function() function()