Loading savegame sporadic MagicRound spam

Post here if you need help getting started with Daggerfall Unity or just want to clarify a potential bug. Questions about playing or modding classic Daggerfall should be posted to Community.
Post Reply
User avatar
Ralzar
Posts: 2211
Joined: Mon Oct 07, 2019 4:11 pm
Location: Norway

Loading savegame sporadic MagicRound spam

Post by Ralzar »

I've done quite a bit of testing on this. It seems to happen as far back as 0.10.13, which is the oldest version of DFU I had installed.

If I start the game, load a savgame, then load a diffrent savegame and then just keep choosing new savegames to load, after about 2-3 attempts I will hit a savegame that takes longer to load and during the loading it will cycle through an absurd amount of OnNewMagicRound. In Unity Editor the debug log shows between 2000 and 5000 rounds.

This is not very noticable most of the time because for it to have an effect you have to:

1: Have an effect applied to the character that uses OnNewMagicRound
2: Hit one of the loading where it happens.

Now, if it happened EVERY time you loaded I would just assume that is how it worked. But since it only happens sometimes, I am assuming there is something off here.

I've included the tiny mod I made. The zip contains both the .dfmod file and the script files.

RoundTester.PNG
RoundTester.PNG (88.11 KiB) Viewed 471 times
Attachments
RoundTester.zip
(7.28 KiB) Downloaded 52 times

User avatar
Ralzar
Posts: 2211
Joined: Mon Oct 07, 2019 4:11 pm
Location: Norway

Re: Loading savegame sporadic MagicRound spam

Post by Ralzar »

This is tested both in the Unity editor and in the Live Builds by the way. Same result. I included a DaggerfallUI.AddHUDText("Magic Round"); in the mod that runs each round so I could confirm it easily in live.

Edit: Something I forgot to test and did just now: When the bug happens, if you just load the exact same save again, the bug does not happen.
Might this be triggered by the switching of what part of the game world is loaded? You do not need to switch character for it to happen.

User avatar
JorisVanEijden
Posts: 114
Joined: Mon Aug 12, 2019 5:02 pm

Re: Loading savegame sporadic MagicRound spam

Post by JorisVanEijden »

It probably has to do with a time difference somewhere. Notice that it does 2880 rounds. That is exactly 48 hours worth of minutes.
Like it thinks that 2 days have passed resting or traveling and it needs to catch up?
Are the other amounts (you mention between 2000 and 5000) also exact multiples of 1440 (or 60)?

Edit: I took a look at the code.

This is what's happening:
- your current (fictitious) date is 04-05-2006 12:00
- DaggerfallWorkshop.Game.MagicAndEffects.EntityEffectBroker.lastGameMinute holds this date
- you load a new game
- DaggerfallWorkshop.Game.Serialization.SaveLoadManager.LoadGame() gets called
- It sets the current date to the one from the save game, let's say 01-02-2003 13:00
- a lot of stuff is loaded
- the LoadGame() method yields execution for a couple of frames.
- during these frames the Update() method of the EntityEffectBroker is called
- that compares it's own lastGameMinute (still on 04-05-2006 12:00) with the current world date (01-02-2003 13:00)
(This comparison uses unsigned integers which means that any negative numbers become huge positive numbers.)
At this point will make up the difference by running magicrounds up to 2880 times.
- after a few frames LoadGame() continues.
- it does some more loading and setting up of data and then raises the OnLoad event.
- the EntityEffectBroker receives this event and calls it's InitMagicRoundTimer() method which sets it's lastGameMinute to the current date.

I created a Pull Request to prevent the comparison while the game is loading: https://github.com/Interkarma/daggerfal ... /pull/1696

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

Re: Loading savegame sporadic MagicRound spam

Post by Hazelnut »

Nice. Glad to see my instinct was correct and it was not the save data at fault. :)
See my mod code for examples of how to change various aspects of DFU: https://github.com/ajrb/dfunity-mods

Post Reply