I have a problem with my MP current game where sometimes all clients get freezing when an object is built. i.e. every build object causes a 0.5 to 1 second freeze. For periods of time this will happen, then for no reason I can see it won't happen at all. Having talked to a couple of people it seems this doesn't happen for everyone even with massive bases, so I am concluding that it is probably related to a mod.
My suspicion is that on_entity_built event handlers that access global data that is large could cause this. I want to look into my different installed mods to find out which one is the culprit and try and optimize the access pattern for global data somehow.
So my questions:
Does my conclusion sound right (syncing global data every time an item is built causing freezing)?
What is the best way to do on_entity_built events to be MP efficient, assuming that is the issue?
MP efficient events.
Re: MP efficient events.
Factorio doesn't sync mod data runtime (it's determistic so they always run the same on every client). However, it could easily be a mod that was coded poorly and is halting the game while it runs the code in the mod.
You can press F4 and enable the "update times" option to see which mods are taking how much CPU time - then simply do stuff and watch which one is taking the most time.
You can press F4 and enable the "update times" option to see which mods are taking how much CPU time - then simply do stuff and watch which one is taking the most time.
If you want to get ahold of me I'm almost always on Discord.
-
- Fast Inserter
- Posts: 157
- Joined: Fri Jun 26, 2015 11:13 pm
Re: MP efficient events.
That's good to know. I guess before we use random() in the mod, we should make sure we save the seed in global to make sure that all clients get the same RNG outputs.Rseding91 wrote:Factorio doesn't sync mod data runtime (it's determistic so they always run the same on every client). However, it could easily be a mod that was coded poorly and is halting the game while it runs the code in the mod.
You can press F4 and enable the "update times" option to see which mods are taking how much CPU time - then simply do stuff and watch which one is taking the most time.
Re: MP efficient events.
Lua's random is attached to global map seed. If you can guarantee exact order of calls (same random calls on all clients) it will work correctly.johanwanderer wrote:That's good to know. I guess before we use random() in the mod, we should make sure we save the seed in global to make sure that all clients get the same RNG outputs.Rseding91 wrote:Factorio doesn't sync mod data runtime (it's determistic so they always run the same on every client). However, it could easily be a mod that was coded poorly and is halting the game while it runs the code in the mod.
You can press F4 and enable the "update times" option to see which mods are taking how much CPU time - then simply do stuff and watch which one is taking the most time.
-
- Fast Inserter
- Posts: 157
- Joined: Fri Jun 26, 2015 11:13 pm
Re: MP efficient events.
Great! I think that only left the player (via GUI events) as the sole source of randomness. Now this deviates from the thread's main point, but is there a way to synchronize some part of a mod's state for that reason? Scenario: mod creates a GUI that allows players to set persistent states. Would such a mod be confined to single-player only for now, or is there a way to package such "mod state" and sync it to the other players?orzelek wrote:Lua's random is attached to global map seed. If you can guarantee exact order of calls (same random calls on all clients) it will work correctly.
-
- Filter Inserter
- Posts: 952
- Joined: Sat May 23, 2015 12:10 pm
- Contact:
Re: MP efficient events.
Correct we if I'm wrong but doesn't the game automatically send all player click events to all clients?
-
- Fast Inserter
- Posts: 157
- Joined: Fri Jun 26, 2015 11:13 pm
Re: MP efficient events.
I will have to play with it more, but each player can have different GUI states (one have X GUI opened, one have Y, etc.) so a "click" may not mean the same to all player. Again, I will play with GUI syncs once the mod I'm working on is more matured. Right now I'm focusing on getting it working for single player.ratchetfreak wrote:Correct we if I'm wrong but doesn't the game automatically send all player click events to all clients?
-
- Filter Inserter
- Posts: 952
- Joined: Sat May 23, 2015 12:10 pm
- Contact:
Re: MP efficient events.
I meant that on_gui_click gets called on all clients with the relevant info (player index and gui element)johanwanderer wrote:I will have to play with it more, but each player can have different GUI states (one have X GUI opened, one have Y, etc.) so a "click" may not mean the same to all player. Again, I will play with GUI syncs once the mod I'm working on is more matured. Right now I'm focusing on getting it working for single player.ratchetfreak wrote:Correct we if I'm wrong but doesn't the game automatically send all player click events to all clients?
Re: MP efficient events.
Correct. When making a mod you don't need to worry about any of that stuff. The game engine handles firing events in the correct order regardless of which peer originally created the event. If it didn't work this way MP would never work even without modsratchetfreak wrote:I meant that on_gui_click gets called on all clients with the relevant info (player index and gui element)johanwanderer wrote:I will have to play with it more, but each player can have different GUI states (one have X GUI opened, one have Y, etc.) so a "click" may not mean the same to all player. Again, I will play with GUI syncs once the mod I'm working on is more matured. Right now I'm focusing on getting it working for single player.ratchetfreak wrote:Correct we if I'm wrong but doesn't the game automatically send all player click events to all clients?
The only part(s) left when making a mod is make sure your Lua local variables are either static or tied to the mods global variables (which are saved between save/load). Basically: save/load should not change any part of your mod's runtime data.
If you want to get ahold of me I'm almost always on Discord.