Page 1 of 2

[solved] Disabling the BlendLocationTerrainJob

Posted: Sun Sep 06, 2020 9:33 am
by monobelisk
Hi

In my mod Interesting Terrains, I'm implementing a custom terrain sampler. One of the terrain sampler's features is that it smooths locations based on different factors than the BlendLocationTerrainJob. It all works nicely, except that the BlendLocationTerrainJob displaces the already smoothed out locations after the terrain sampling is done.

Going through the code, the only condition I could find was MapPixelData.hasLocation, so I tried to set that to false during terrain sampling, then back to true using the OnPromoteTerrainData handler, but that completely breaks billboard and tilemap handling for locations (towns are littered with wilderness billboards and uses wilderness tilemapping).

Does anyone know if there's some other, more proper way to prevent the BlendLocationTerrainJob from happening?

Edit:

In fact, the only way I seem to be able to make it work as I want is to modify the DaggerfallTerrain.BeginMapPixelDataUpdate() method like so:

Code: Select all

if (MapData.hasLocation)
{
    // Set location tiles.
    TerrainHelper.SetLocationTiles(ref MapData);

    if (1 == 2)
    {
        // Schedule job to calc average & max heights.
        JobHandle calcAvgMaxHeightJobHandle = TerrainHelper.ScheduleCalcAvgMaxHeightJob(ref MapData, generateHeightmapSamplesJobHandle);
        JobHandle.ScheduleBatchedJobs();

        // Schedule job to blend and flatten location heights. (depends on SetLocationTiles being done first)
        blendLocationTerrainJobHandle = TerrainHelper.ScheduleBlendLocationTerrainJob(ref MapData, calcAvgMaxHeightJobHandle);
    }
    else
        blendLocationTerrainJobHandle = generateHeightmapSamplesJobHandle;
}
else
    blendLocationTerrainJobHandle = generateHeightmapSamplesJobHandle;
(where the "1 == 2" part, in this scenario, should obviously be replaced by a proper variable, such as a "blendLocations" flag in the TerrainSampler class, or something)

Re: Disabling the BlendLocationTerrainJob

Posted: Mon Sep 07, 2020 6:04 am
by BadLuckBurt
I think the code needs to be adjusted to allow for that to happen. HasLocation is also used to determine billboards as you have already seen. It either needs a separate property or a method needs an extra parameter.

I had the same problem with TransferLandToOcean,it extends the land pixels of the coastline making the world slightly bigger for nicer beaches. I disabled it with the help of Hazelnut but that code isnt live yet.

Re: Disabling the BlendLocationTerrainJob

Posted: Mon Sep 07, 2020 6:47 am
by monobelisk
BadLuckBurt wrote: Mon Sep 07, 2020 6:04 am I think the code needs to be adjusted to allow for that to happen. HasLocation is also used to determine billboards as you have already seen. It either needs a separate property or a method needs an extra parameter.

I had the same problem with TransferLandToOcean,it extends the land pixels of the coastline making the world slightly bigger for nicer beaches. I disabled it with the help of Hazelnut but that code isnt live yet.
Ah, I feared as much. Being completely new to this community, what's the proper way to suggest such changes to the base game?

Re: Disabling the BlendLocationTerrainJob

Posted: Mon Sep 07, 2020 6:56 am
by BadLuckBurt
Making a thread like this :) it might take some time for it to be implemented and figure out the best way but I dont see a problem with separating that bit of logic. Its a minor change with no chance breaking anything.

Re: Disabling the BlendLocationTerrainJob

Posted: Mon Sep 07, 2020 8:31 am
by monobelisk
BadLuckBurt wrote: Mon Sep 07, 2020 6:56 am Making a thread like this :) it might take some time for it to be implemented and figure out the best way but I dont see a problem with separating that bit of logic. Its a minor change with no chance breaking anything.
Well, that definitely sounds promising :D

And exactly, if it was to be implemented as a virtual property with a default value of true, or something, in the abstract TerrainSampler, the changes would only lead to different behavior if a subclass directly overrides it to false.

Really hope it'll make it through (of course), but in the mean time I suppose I'll just disable my own location blending logic.

Thanks for the help :)

Re: Disabling the BlendLocationTerrainJob

Posted: Mon Sep 07, 2020 12:19 pm
by Hazelnut
Yep I think this would be useful thing to do. I'll take a look at doing this when I have some time.

Re: Disabling the BlendLocationTerrainJob

Posted: Mon Sep 07, 2020 1:30 pm
by monobelisk
Hazelnut wrote: Mon Sep 07, 2020 12:19 pm Yep I think this would be useful thing to do. I'll take a look at doing this when I have some time.
That is amazing news! Thank you :D

Re: [solved] Disabling the BlendLocationTerrainJob

Posted: Mon Sep 14, 2020 8:52 pm
by Hazelnut
I have submitted this as PR#1935, would you grab it and check that it works for you and your sampler can successfully prepare terrain for locations please?

Re: [solved] Disabling the BlendLocationTerrainJob

Posted: Wed Sep 16, 2020 6:55 am
by monobelisk
Hazelnut wrote: Mon Sep 14, 2020 8:52 pm I have submitted this as PR#1935, would you grab it and check that it works for you and your sampler can successfully prepare terrain for locations please?
Thanks :D

I haven't been much active the last couple of days due to RL stuff, but I'll take a look today after work.

Re: [solved] Disabling the BlendLocationTerrainJob

Posted: Wed Sep 16, 2020 3:48 pm
by monobelisk
Unfortunately, I'm unable to confirm if it works, as I'm unable to get the latest DFUnity source code working. That is, it works fine until it tries to load Interesting Terrains, which causes the mod loader to throw a NullRef exception. Neither was I able to build the game and test it there (got stuck before showing the startup menu - something with localization related NullRefs. I'll see if I can get it sorted out tomorrow..