[solved] Disabling the BlendLocationTerrainJob

Discuss modding questions and implementation details.
monobelisk
Posts: 33
Joined: Tue Aug 25, 2020 10:43 am

[solved] Disabling the BlendLocationTerrainJob

Post 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)
Last edited by monobelisk on Mon Sep 07, 2020 1:31 pm, edited 1 time in total.

User avatar
BadLuckBurt
Posts: 568
Joined: Sun Nov 05, 2017 8:30 pm

Re: Disabling the BlendLocationTerrainJob

Post 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.
Daggerfall Unity on UESP: https://en.uesp.net/w/index.php?title=T ... fall_Unity
Daggerfall Unity on Nexus Mods: https://www.nexusmods.com/daggerfallunity
My github repositories with mostly DFU related stuff: https://github.com/BadLuckBurt

monobelisk
Posts: 33
Joined: Tue Aug 25, 2020 10:43 am

Re: Disabling the BlendLocationTerrainJob

Post 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?

User avatar
BadLuckBurt
Posts: 568
Joined: Sun Nov 05, 2017 8:30 pm

Re: Disabling the BlendLocationTerrainJob

Post 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.
Daggerfall Unity on UESP: https://en.uesp.net/w/index.php?title=T ... fall_Unity
Daggerfall Unity on Nexus Mods: https://www.nexusmods.com/daggerfallunity
My github repositories with mostly DFU related stuff: https://github.com/BadLuckBurt

monobelisk
Posts: 33
Joined: Tue Aug 25, 2020 10:43 am

Re: Disabling the BlendLocationTerrainJob

Post 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 :)

User avatar
Hazelnut
Posts: 2384
Joined: Sat Aug 26, 2017 2:46 pm
Contact:

Re: Disabling the BlendLocationTerrainJob

Post 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.
See my mod code for examples of how to change various aspects of DFU: https://github.com/ajrb/dfunity-mods

monobelisk
Posts: 33
Joined: Tue Aug 25, 2020 10:43 am

Re: Disabling the BlendLocationTerrainJob

Post 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

User avatar
Hazelnut
Posts: 2384
Joined: Sat Aug 26, 2017 2:46 pm
Contact:

Re: [solved] Disabling the BlendLocationTerrainJob

Post 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?
See my mod code for examples of how to change various aspects of DFU: https://github.com/ajrb/dfunity-mods

monobelisk
Posts: 33
Joined: Tue Aug 25, 2020 10:43 am

Re: [solved] Disabling the BlendLocationTerrainJob

Post 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.

monobelisk
Posts: 33
Joined: Tue Aug 25, 2020 10:43 am

Re: [solved] Disabling the BlendLocationTerrainJob

Post 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..

Post Reply