Ismoh / NoitaMP

WIP! Not working, atm! NoitaMP, Noita Multiplayer: First synchronous multiplayer mod for Noita!
GNU General Public License v3.0
115 stars 12 forks source link

Developer want to rework client and server modules/classes #48

Closed Ismoh closed 1 year ago

Ismoh commented 2 years ago

This is the successor issue to #27, which is more or less done and would be to huge to continue.

TBC

Ismoh commented 2 years ago

FYI: based on #27 branch

Ismoh commented 2 years ago

Use reliable, unsequnced and unreliable sendMode.

Reliable is default.

Reliable:

Unreliable

Other stuff:

  1. when client connects first time, ask for seed and check guid + change if there is any duplicate
  2. when seed received, cache seed and restart game. Start with cached seed. Clear cached seed. Connect, with seed or code in connection data send to server.
  3. When client connected the second time with seed in data, send mina, clientInfo, position and health
  4. Server then sends his and all clients minas, position and health.
  5. Server and clients start to continuos send position, health and 'needNuid' for clients
  6. When server received 'needNuid' send 'newNuid' to all clients

Enough for now!

Ismoh commented 2 years ago
Ismoh commented 2 years ago

Before doing any network stuff, extend logger with categories like GUID, NUID, ENTITY, NET, NOITA_COMPONENTS, etc. ✔️

Add log level per category in modSettings. ✔️

Log file be like: TL;DR

Ismoh commented 2 years ago

Change log of client server to use pprint.format to get a return instead of writing to io or console: https://github.com/jagt/pprint.lua#options ✔️

Ismoh commented 2 years ago

Remove all callbacks and rework them step by step, also schemas. ~When connecting dont send minä, sent seed and restart client, then auto connect and sent minä.~ No need for a restart anymore.

Ismoh commented 2 years ago

Use apto and exe filename for unique guid ✔️

Ismoh commented 2 years ago

Put networking update in one function and run this is WorldPreUpdate and OnPausePreUpdate. Does it make sense to run Networking update on pre normal and postUpdate?

Ismoh commented 2 years ago

Add saveSlot number into saveSlot cache. ✔️

Ismoh commented 2 years ago

When connecting the second time, clients save directory has to be empty, otherwise seed doesnt work: Try to remove the savefolders content with start /wait, because lfs isnt able to delete. I think because the directory is still in use. see below: https://stackoverflow.com/a/13258451/3493998 https://stackoverflow.com/a/9480476/3493998

Deprecated, because solved it without restarting. Thanks to Evaisa. ✔️

Ismoh commented 2 years ago

unknown-1

Ismoh commented 2 years ago

Fix unit test! 😡

Ismoh commented 2 years ago

For the future: Sync minäs arm leg and other stuff, but make it configurable, or better to say, when threshold is reached (lag ~60ms), then only sync necessary stuff like projectiles, enemies and position of minäs

Ismoh commented 2 years ago

Add version to playerInfo to detect version missmatch

Ismoh commented 2 years ago

Add exclude include for spawning entities. Player for example do need to be spawned, but a dump copy of it.

When server got needNuid, check if entity already was spawned (client guid + localEntityId).

I think I dont need messageIds, when entityIds + guid can be used.

Add reseting guid, when development build is used, otherwise guid will be the same. Do I want to add guid check for server/client? Yes...

Ismoh commented 2 years ago

When sock.lua creates a new client on server object, use NoitaMP client object, instead of sock.lua client object.

Ismoh commented 2 years ago

Override all send functions to set acknowledge. Copy&paste acknowledge of sock.lua#Client:send

Ismoh commented 2 years ago

I need to add a 'cache' list for detecting, if entities moved and needs to be synced: entities[entityId] = { health, pos, velo, etc } (round health, position, velo, etc otherwise this cache is obsolete) Then getFilteredEntities After that compare In addition: use callback function in getFilteredEntities to add additionalChecks like:

If client disconnects clear list. (client only sends minä and projectiles) If entity died, remove from list.

Double check if entityId for nuid changed in GlobalsUtils, when set or removed from cache.

Ismoh commented 2 years ago

Only owner is allowed to send entityData?

Ismoh commented 2 years ago

Load entities once per world update and pass the list as parameter.?

Ismoh commented 2 years ago
Ismoh commented 2 years ago

Screenshot_20220806_003046_com discord

Ismoh commented 2 years ago

Added tick rate and changed detection of changes, but clients fps still drop to ~29-55. I need to profile again!

Ismoh commented 2 years ago
Ismoh commented 2 years ago

Use coroutine as iterator for

Ismoh commented 2 years ago

config.lua:

modSettings {
radiusToDetectEntities.key = "noita-mp.radiusToDetectEntities",
radiusToDetectEntities.value = 250,
...
}
Ismoh commented 2 years ago

First check how long it takes to get a mod setting, by profiling ModSettingGet("foo.bar"):

local cpc = CustomProfiler.start("ModSettinGet")
local foo = ModSettingGet("bar.z")
CustomProfiler.stop("ModSettingGet", cpc)
Ismoh commented 2 years ago

First check how long it takes to get a mod setting, by profiling ModSettingGet("foo.bar"):

local cpc = CustomProfiler.start("ModSettinGet")
local foo = ModSettingGet("bar.z")
CustomProfiler.stop("ModSettingGet", cpc)

ModSettings execution is below 1ms! So this isn't the problem.

Ismoh commented 2 years ago

Use coroutine as iterator for

  • init network entities
  • sending network messages on specific tick rate (ms)
  • receive network messages on preUpdate
  • send network messages on postUpdate

Yield return iterator or index when execution time is greater equals 25ms (=40fps) Next frame continue on for loop

Ismoh commented 2 years ago

https://love2d.org/forums/viewtopic.php?t=79980

Ismoh commented 2 years ago

Profiler: Windows: https://stackoverflow.com/questions/6207573/how-to-append-output-to-the-end-of-a-text-file

Linux: https://stackoverflow.com/questions/17701989/how-do-i-append-text-to-a-file

Ismoh commented 2 years ago

Looks like I found the issue? I'll see, if this is the problem the next days: image It has to be EntityUtils.syncEntityData.for!

If you are curious, have a look on frame 4559 in report.html: reports.zip

Ismoh commented 2 years ago

Clear caches, when entering and exiting holy mountain!

yes, use BiomeMapGetName( x:number = camera_x, y:number = camera_y ) -> name

name = $biome_holymountain

Better to use this one?

DebugBiomeMapGetFilename( x:number = camera_x, y:number = camera_y ) -> string

Ismoh commented 2 years ago

If client and server have a distance of 3*radius do not sync entities only sync world changes.

Ismoh commented 2 years ago
Ismoh commented 2 years ago

Receive network messages in preworldupdate and send messages in postworldupdate?

Ismoh commented 2 years ago

image

Ismoh commented 1 year ago

Note: If entity has children, loop children and add nuid + send it two clients

ofoxsmith commented 1 year ago

Shouldn't this branch be merged into develop? The goals of this PR have been completed, so why hasn't it been merged?

ofoxsmith commented 1 year ago

As far as I can tell, most of the issues and PRs based off of this branch are seperate issues - not related to the client/server module rework.

Ismoh commented 1 year ago

It isn't merged, because other branches are based on this. But yes, it's time for it

ofoxsmith commented 1 year ago

Should we merge it after #89 is finished?

Ismoh commented 1 year ago

Yes. If there is stuff, not fully or correct synced, we can and should create follow up issues