bodzio528 / FS22_CropRotation

mod for Farming Simulator 22
48 stars 15 forks source link

Large terrain support, savegame GRLE image resolutions #35

Open SnakeManPMC opened 1 year ago

SnakeManPMC commented 1 year ago

Back in feb / mar 2023 I tested CropRotation mod with large, huge, terrains, I cannot remember what was the issue, some fallow appearing out of nowhere or something (I didn't document it and cant remember anymore) so I removed the mod.

Now I was happy to see v2.5.0.1 mentioning about rewritten code so I had hope that perhaps as by-product that would fix whatever issue I had earlier this year.

Just finished testing v2.5.0.1 on elmcreek successfully and then on larger terrain, this was 10.2km x 10.2km Big Fields XXL 10km by Zoltanm. I noticed issue with "spotty" or "flaky" crop rotation previous harvest reporting in field info box, I walked across field diagonally and field info box switched from "fallow | fallow" to "fallow | CROPNAME" back and forth. At first I didn't even notice it as I was standing in the field on the "sweet spot", but walking across it definitely shows like strips of field with different crop rotation status.

That got me thinking and I went to savegame dir and sure enough there was three GRLE image files, those file sizes were 4kb, and 20kb, that sounds awfully low resolution, I did not convert them to PNG to see what resolution they are.

This situation reminds me of precision farming which has hardcoded soil GRLE image of 1024 x 1024 pixel resolution, which is just too small for large terrains and gives similar result in-game.

bodzio528, have you designed FS22_CropRotation mod for various terrain sizes, or is it only tested on elmcreek alike 2km x 2km size?

If you are willing to add support for various larger size terrains I am happy to do testing for you, I only play around with large terrains.

bodzio528 commented 9 months ago

Hi, due to lack of resources I test mod only od standard maps (base game and pDLCs). Sometimes popular ModHub maps on request - and not many of modhub maps are larger than standard ones.

In all places mod uses self.mission.terrainSize as reference value, so it should consider large terrains correctly out of the box in calculations.

The resolution is specified in CropRotation.xml file, sadly 1024 is set to default whenever not specified otherwise.

  <coverMap lockChannel="0" fallowChannel="1" harvestChannel="2"/>
  <yieldMap sizeX="1024" sizeY="1024" numChannels="6" />

Change sizeX/sizeY to desired value should do the trick:

  <coverMap sizeX="8192" sizeY="8192" lockChannel="0" fallowChannel="1" harvestChannel="2"/>
  <yieldMap sizeX="8192" sizeY="8192" numChannels="6" />

You'll need fresh savegame or delete cropRotation_XYZ.grle from savegame folder.

I've prepared small modification of package for you (see attached file). I've changed map resolution to 8k per side - this should improve resolution dramatically, but there is downside - periodic task, like fallow and regrow will take considerable amount of time. They are asynchronous, so the game will not freeze, but all this makes harvesting around midnight, when month or year changes, somewhat risky.

update new download FS22_CropRotation_8k.zip

SnakeManPMC commented 9 months ago

Thank you very much, I'll try to get this tested soon. I have some other projects going on currently so cant get it tested right away, but I'll let you know when my testing is complete.

I very much appreciate you writing that above change for this issue, thank you.

SnakeManPMC commented 9 months ago

Tried to launch FS22 with new version of crop rotation mod loaded, game start stalled at 95% loading with this in the error log:

Available mod: (Hash: 7c0b6b7dda4cf85e6d1bd12e6f9f5786) (Version: 2.5.0.2) FS22_CropRotation_8k

2023-12-08 20:13  [DEBUG] FS22_CropRotation_8k: loadItems() items file=data/maps/mapUS/items.xml
2023-12-08 20:13  [DEBUG] FS22_CropRotation_8k: loadItems() savegame dir=nil
2023-12-08 20:13  [DEBUG] FS22_CropRotation_8k: CropRotation:onNewSavegame(): start
2023-12-08 20:13  [DEBUG] FS22_CropRotation_8k:   isServer: true
2023-12-08 20:13  [DEBUG] FS22_CropRotation_8k:   isClient: true
2023-12-08 20:13  [DEBUG] FS22_CropRotation_8k:   isMultiplayer: false
2023-12-08 20:13  [DEBUG] FS22_CropRotation_8k:   isDedicatedServer: false
2023-12-08 20:13  [DEBUG] FS22_CropRotation_8k: CropRotation:randomInit()
2023-12-08 20:13 Error: Running LUA method 'update'.
C:/FS22.Mods/Crop_Rotation_Testing/FS22_CropRotation_8k/CropRotation.lua:465: attempt to call global 'string' (a table value)

As can be seen that is from elmcreek, same happens with my own large terrain. That elmcreek test was without any other mods loaded.

bodzio528 commented 9 months ago

Ah, my bad, programming at 2AM is stupid idea. Try this one instead:

FS22_CropRotation_8k.zip

SnakeManPMC commented 9 months ago

Downloaded your latest ZIP, then ran elmcreek, no other mods and this is what happens:

Available mod: (Hash: da2fd3c425cfa9de56085527c699a192) (Version: 2.5.0.2) FS22_CropRotation_8k

2023-12-08 21:40 Error: Failed to open xml file 'C:/FS22.Mods/Crop_Rotation_Testing/FS22_CropRotation_8k/data/crops.xml'.
2023-12-08 21:40  [DEBUG] FS22_CropRotation_8k: CropRotationData:loadFromXML() path: C:/FS22.Mods/Crop_Rotation_Testing/FS22_CropRotation_8k/data/crops.xml
2023-12-08 21:40  [DEBUG] FS22_CropRotation_8k: CropRotationData:parseCropsXml()
2023-12-08 21:40 Warning (script): Unknown entity id 0 for 'object' in method 'hasXMLProperty'.
2023-12-08 21:40 LUA call stack:
  =C:/FS22.Mods/Crop_Rotation_Testing/FS22_CropRotation_8k/CropRotationData.lua (83) : hasXMLProperty
  =C:/FS22.Mods/Crop_Rotation_Testing/FS22_CropRotation_8k/CropRotationData.lua (69) : parseCropsXml
  =C:/FS22.Mods/Crop_Rotation_Testing/FS22_CropRotation_8k/CropRotation.lua (143) : loadFromXML
  dataS/scripts/BaseMission.lua (537) : loadMap
  dataS/scripts/FSBaseMission.lua (1689) : loadMapFinished
  dataS/scripts/i3d/I3DManager.lua (175) : asyncCallbackFunction
2023-12-08 21:40  [ERROR] FS22_CropRotation_8k: CropRotationData:parseCropsXml(): loading XML element 'crops' failed: C:/FS22.Mods/Crop_Rotation_Testing/FS22_CropRotation_8k/data/crops.xml
2023-12-08 21:40  [DEBUG] FS22_CropRotation_8k: CropRotationData:postLoad(): list fruits in rotation ...
2023-12-08 21:40 Error: Running LUA method 'loadSharedI3DFileFinished'.
C:/FS22.Mods/Crop_Rotation_Testing/FS22_CropRotation_8k/CropRotationData.lua:193: attempt to call method 'warning' (a nil value)

And FS22 loading stalled at 60% point there.

bodzio528 commented 9 months ago

Ok, on elmcreek modified package will not work, apparently CR map must not be bigger than terrain itself. Looks like size=4096 is the hard limit for standard maps (density map resolution is 4096x4096).

Now we know.

I've prepared new one for you, try this: FS22_CropRotation.zip

But the main issue here is for some reason the crop rotation data is not found in file that should be part of archive. Let's try without mod renaming - it should not be a problem (I am using altered filename myself without issues myself), but from what I can see you have altered your mods folder location.

SnakeManPMC commented 9 months ago

Downloaded your latest version:

Available mod: (Hash: 20b32cefc39460539630576db10c06f8) (Version: 2.5.0.5) FS22_CropRotation

Ran it with my own PMC RedWhiteBlue 10km terrain which is as the name says 10.2 kilometers x 10.2 kilometers in size (elmcreek is two kilometers), and it runs fine, no errors and I see no issue described in this tickets first post anymore, when running through a large 30ha field diagonally the previous harvest and crop rotation percentage line stays stable.

I did not actually farm (seeding & harvesting) yet, just started a new savegame and purchased all the farmland, but so far it seems to work good.

Great job on the fix! :)

Do I understand correctly that the crop rotation image GRLE resolution is now 4096 x 4096 pixels? If so, does that work with smaller terrains as well like elmcreek?

Also, did you mean larger sizes than 4096 x 4096 are not possible? Just wondering that a huge terrains like 20km or 40km still might get the issue if crop rotation image resolution is only 4096, would need testing to confirm though.

bodzio528 commented 9 months ago

Hi, thanks for feedback.

Yes, this uploaded version has 4096x4096 GRLE map size. The 4096px is exact size of terrain GRLE for 2km map - it gives four pixels per square meter, and each pixel is divided into 4 sub-pixels (RGBA), so you can have implements with work width as small as 25cm.

Larger maps can be achivied in two ways: increase physical size without increassing terrain GRLE size (this causes increase in minimal working width eg. 50cm on 4x maps), or increase terrain GRLE to match physical size (but all functions that operate on terran will take more time to process).

In FS19 terrain size was fixed in game engine as far as I recall, thus maps bigger than 4x were not very popular (and game engine hacking was still required).

Exceceding 4096 resolution for CropRotation GRLE results in coordinates without corresponding terrain cells, unless terrain itself isn't increased (FS22 allows that). I have tested 8192x8192 GRLE on standard map, and while all functions work just fine, there is no benefit from increased resolution (3/4th of retrieved data is simply discarded). The downside is that the periodic task time to completion suffers (once a year, each field is checked for fallow condition, and once a month each field is checked for regrowing/sowing condition). For GRLE of 4096x4096 runtime is 10 seconds. For 8192x8192 the runtime is almost 40 seconds on my PC (i9 9900K), which is in yellow zone.

So, 4096 is safe value I'd went for modhub-style release to greater audience.

SnakeManPMC commented 9 months ago

Larger maps can be achivied in two ways: increase physical size without increassing terrain GRLE size (this causes increase in minimal working width eg. 50cm on 4x maps), or increase terrain GRLE to match physical size (but all functions that operate on terran will take more time to process).

Use Actual Size (terrains)

In FS19 terrain size was fixed in game engine as far as I recall, thus maps bigger than 4x were not very popular (and game engine hacking was still required).

Negative, not true. Please refer to heightmap, unitsPerPixel and HOWTO Create 45km Terrain

So, 4096 is safe value I'd went for modhub-style release to greater audience.

When I get some free time I'll try to get your latest upload version tested on one of the really large terrains, I'll let you know how it turns out.