Teardown

Teardown

Structural Integrity Test
el Boydo 2 Jun, 2021 @ 1:54pm
Potential improvements
Hey, your mod is pretty awesome, i feel the following would really help, you said post a version but i don't consider it worth it given that you're focused on this and what you have done is incredible thus far, i really want to see it grow. so my suggestions are as follows :

start / init

maxDist = 200 function init() collapse_timer = 0.0 destroyedVoxels = GetInt("game.brokenvoxels") end

and for tick

function tick(dt) collapse_timer = collapse_timer - dt local destroyedTest = GetInt("game.brokenvoxels") if collapse_timer <= 0.0 and destroyedVoxels ~= destroyedTest then destroyedVoxels = destroyedTest collapse_timer = 1.0 QueryRequire("physical dynamic large") local list = QueryAabbShapes(Vec(-maxDist, -maxDist, -maxDist), Vec(maxDist, maxDist, maxDist))

Reasoning: a maps current max shadow volume is 400x400, meaning the max AABB box for all in game and most mod maps will be -200 x +200 for all dimensions, meaning you can reduce your aabb box search by a 5th (a massive jump in performance if i recall correctly). You can change this to a larger or smaller val too but I doubt you'd see a map larger than 400x400 in the majority of experiences. The 400x400 being due to AMD cards.


The addition of destroyedTest and destroyedVoxels is that the game has an inbuilt stat for destroyed voxels, if we don't break any voxels then why run the algorithm?

So in essence, your countdown will tick, but you won't actually test for collapses unless a voxel had been broken since the last time you tested for collapses, of course you may have an edge case but these are much rarer.

The end result is that instead of testing the algorithm constantly, you only do it when the game knows something is broken to test on.



Hopefully these small suggestions help you boost performance and make this fantastic mod into something everybody can have running.
< >
Showing 1-15 of 15 comments
Wadol  [developer] 2 Jun, 2021 @ 3:16pm 
This is really useful, thank you. I've pushed an update just now with this idea.
Where'd you find the game.brokenvoxels variable, by the way?
Miloski 2 Jun, 2021 @ 8:59pm 
smart talk
pigydog123 2 Jun, 2021 @ 9:31pm 
big smart :Goku:
el Boydo 4 Jun, 2021 @ 10:32am 
Originally posted by Wwadlol:
This is really useful, thank you. I've pushed an update just now with this idea.
Where'd you find the game.brokenvoxels variable, by the way?

I got it from the games challengeMayhem.lua function, as that game mode works based on how many destroyed voxels you have.


It's a pretty useful little trick to play with on a few things.
70UNIK 4 Jun, 2021 @ 2:27pm 
I don't know if it's possible, but can you have structural integrity for "overhanging structures" that are the result of damage, even when not moving? This is still present even with this mod. For example, destroying only 3/4 of the bottom of the house does not result in the upper section collapsing until all connections are destroyed.
FullMoonGlade 6 Jun, 2021 @ 5:28am 
sometimes driving large vehicles causes them to randomly fall apart like paper if they hit an object
Babombo 24 Jun, 2021 @ 4:45am 
hey
no clue if you are still here @Dev
but I made a small modification that leads to the object being destroyed once hitting the ground/ something else

it is far from perfect but imo looks much better when for example breaking Lee Chemical tower as it only gets destroyed when hitting the ground/ a building instead of breaking to bits the moment you cut it from the ground

code explanation:
I give the bodies that are broken (would be blown up in your original code) a tag that stores the velocity and once that velocity changes (decreases) below 0.1 of the max velocity, the breaking actually starts

the code is here:
function tick(dt) collapse_timer = collapse_timer - dt if collapse_timer <= 0.0 then collapse_timer = 0.3 --orig value 1.0 QueryRequire("physical dynamic large") local list = QueryAabbShapes(Vec(-1000, -1000, -1000), Vec(1000, 1000, 1000)) local testval = 0 for i=1, #list do local shape = list

local body = GetShapeBody(shape)



if body then
local mass = GetBodyMass(body)
local broken = IsBodyBroken(body)
local vector_vel = GetBodyVelocity(body)
local vector_len = VecLength(vector_vel)

local mass_modi = mass / 60000.0

local is_vehicle = GetBodyVehicle(body)


if is_vehicle == 0 then
if vector_len > 2 then
if mass > 500 and broken == true then
--evtl. lieber RIchtung statt Geschwindigkeit -> Richtungsaenderung
if not HasTag(body, "vela") then
SetTag(body, "vela", vector_len)
else
if tonumber(GetTagValue(body, "vela")) < vector_len then
SetTag(body, "vela", vector_len)
end
end
end
end
end

if HasTag(body, "vela") then
if vector_len < (tonumber(GetTagValue(body, "vela")) * 0.1) then

local bodyTransform = GetBodyTransform(body)

local mini, maxa = GetShapeBounds(shape)
local c = VecLerp(mini, maxa, math.random())

local cross = VecSub(mini, maxa)

local size_multi = mass / 5.0

MakeHole(c, size_multi, size_multi / 2.0, size_multi / 5.0)

-- DebugCross(cross)
-- DebugLine(bodyTransform.pos, cross, 1, 0, 0)

if GetBool("savegame.mod.dust") then
ParticleReset()
ParticleType("smoke")
ParticleColor(0.6, 0.55, 0.5)
ParticleDrag(0.15)
ParticleGravity(-.2)
for i = 50,1,-1
do
ParticleRadius(4.0)
local spread = math.floor(math.random() * (1000 - 1) + 1000) / 1000;
local v = VecScale(VecAdd(spread, rndVec(1.0)), 8)
v = VecAdd(v, VecScale(GetBodyVelocityAtPos(body, c)))
local l = rnd(10*0.5, 10*1.5)
SpawnParticle(c, v, l)
end
end
end
end
end
end
end
end[/code]
Last edited by Babombo; 24 Jun, 2021 @ 4:46am
Wadol  [developer] 24 Jun, 2021 @ 6:12am 
yup, im here. I'm pretty burnt out on maintaining this mod so, and this goes for anyone, feel free to upload your own versions! :steamthumbsup:
Babombo 24 Jun, 2021 @ 6:24am 
alrighty
SuperNova14 2 Jul, 2021 @ 4:30pm 
Originally posted by Terraria Smurf 1337 Hours:
alrighty
Do you plan to upload the mod with your code?
Like32Crabs 2 Jul, 2021 @ 10:32pm 
Originally posted by Terraria Smurf 1337 Hours:
alrighty
Yeah same response as the other guy, would love to see you upload a version of the mod with your code implemented because that is definitely a sticking point with the buildings.
Babombo 5 Jul, 2021 @ 12:30am 
i have some university deadlines to meet this week
once that is done I will come back to teardown modding and will most likely upload my modified code. I have some other ideas I want to implement first though
Havenkeeper 24 Jul, 2021 @ 5:00pm 
Originally posted by 70UNIK:
I don't know if it's possible, but can you have structural integrity for "overhanging structures" that are the result of damage, even when not moving? This is still present even with this mod. For example, destroying only 3/4 of the bottom of the house does not result in the upper section collapsing until all connections are destroyed.
Absolutely want this to happen, but i can see many custom maps collapsing instantly. You'd have to have code in place to make supports hold up a specific amount of weight/distance, and i'd imagine this being unbelievably difficult for a mod.
rickyjb [UK] 25 Jul, 2021 @ 3:53pm 
Originally posted by Terraria Smurf 1337 Hours:
i have some university deadlines to meet this week
once that is done I will come back to teardown modding and will most likely upload my modified code. I have some other ideas I want to implement first though

would be great to see what improvements you can make.
Babombo 26 Jul, 2021 @ 2:34pm 
i will work on it
i did so a little bit but I am not finished
and I am lacking motivation and time right now
sry
< >
Showing 1-15 of 15 comments
Per page: 1530 50