一个联网的开源格斗游戏demo - Websocket+UDP都支持啦 https://forum.cocos.org/t/topic/144489
Go to file
2023-01-20 14:32:38 +08:00
battle_srv Enhanced turn-around performance. 2023-01-20 11:29:27 +08:00
charts Updated charts in README. 2023-01-15 17:43:02 +08:00
collider_visualizer A temp broken commit except for OfflineMap - refactoring jumping. 2022-12-31 23:28:09 +08:00
database/skeema-repo-root Initial commit. 2022-09-20 23:52:55 +08:00
dnmshared Drafted new character as NPC. 2023-01-08 20:34:29 +08:00
dragonBonesProjects Minor fix. 2022-12-10 18:12:20 +08:00
frontend Enhanced turn-around performance. 2023-01-20 11:29:27 +08:00
jsexport Enhanced turn-around performance. 2023-01-20 11:29:27 +08:00
nginx-templates Minor fix. 2023-01-18 18:03:54 +08:00
resolv_tailored A temp broken commit except for OfflineMap - refactoring jumping. 2022-12-31 23:28:09 +08:00
.gitattributes Initial commit. 2022-09-20 23:52:55 +08:00
.gitignore Added basic frontend-backend dynamics comparison logging. 2022-12-26 18:25:20 +08:00
ConcerningEdgeCases.md Made frontend landscape. 2023-01-17 23:35:23 +08:00
MULTIHIT_ROADMAP.md A temp broken commit except for OfflineMap - refactoring jumping. 2022-12-31 23:28:09 +08:00
proto_gen_shortcut.sh Temp broken commit, refactoring battle_srv to use jsexport. 2022-12-25 15:39:30 +08:00
README.md Updated README. 2023-01-20 14:32:38 +08:00

Preface

This project is a demo for a websocket-based rollback netcode inspired by GGPO. As lots of feedbacks ask for a discussion on using UDP instead, I tried to summarize my personal opinion about it in ConcerningEdgeCases -- not necessarily correct but that's indeed a question to face :)

The following video is recorded over INTERNET using an input delay of 4 frames and it feels SMOOTH when playing! Please also checkout these demo videos

to see how this demo carries out a full 60fps synchronization with the help of batched input upsync/downsync for satisfying network I/O performance.

gif_demo_1

gif_demo_2

All gifs are sped up to ~1.5x for file size reduction, kindly note that animations are resumed from a partial progress!

Notable Features

  • Backend dynamics toggle via Room.BackendDynamicsEnabled
  • Recovery upon reconnection (only if backend dynamics is ON)
  • Automatically correction for "slow ticker", especially "active slow ticker" which is well-known to be a headache for input synchronization
  • Frame data logging toggle for both frontend & backend, useful for debugging out of sync entities when developing new features

(how input delay roughly works)

input_delay_intro

(how rollback-and-chase in this project roughly works, kindly note that by the current implementation, each frontend only maintains a lastAllConfirmedInputFrameId for all the other peers, because the backend only downsyncs all-confirmed inputFrames, see markConfirmationIfApplicable for more information -- if a serverless peer-to-peer communication is seriously needed here, consider porting markConfirmationIfApplicable into frontend for maintaining lastAllConfirmedInputFrameId under chaotic reception order of inputFrames from peers)

server_clients rollback_and_chase_intro

(By use of GopherJs, the frontend codes for dynamics are now automatically generated) floating_point_accumulation_err

1. Building & running

1.1 Tools to install

Backend

Frontend

  • CocosCreator v2.2.1 (mandatory, ONLY AVAILABLE on Windows or OSX and should be exactly this version, DON'T use any other version because CocosCreator is well-known for new versions not being backward compatible)
  • protojs (optional, only for development)

1.2 Provisioning

Backend/Database

It's strongly recommended that skeema is used for provisioning the required schema in MySQL instance. When using skeema the steps are as follows.

### Mandatory after an initial clone
user@proj-root/database/skeema-repo-root> cp .skeema.template .skeema

### Mandatory
user@proj-root/database/skeema-repo-root> skeema push

On Windows 10/11, you can compile skeema from source and config the host to be 127.0.0.1 instead of localhost to use it, i.e. circumventing the pitfall for MySQL unix socket connection on Windows.

Backend/Golang

user@proj-root/battle_srv/configs> cp -r ./configs.template ./configs

Frontend

user@proj-root/frontend/assets/plugin_scripts> cp ./conf.js.template ./conf.js

1.3 Actual building & running

Backend

### The following command runs mysql-server in foreground, it's almost NEVER run in such a way, please find a proper way to run it for yourself
user@anywhere> mysqld

### The following command runs redis-server in foreground, it's OK to put it in background
user@anywhere> redis-server

### on Windows using TDM-GCC: mingw32-make run-test 
user@proj-root/battle_srv> make run-test

Frontend

The easy way is to try out 2 players with test accounts on a same machine.

  • Open CocosCreator v2.2.1 (mandatory, it serves the web content of the following steps)
  • Open one browser instance, visit http://localhost:7456?expectedRoomId=1, input addon the username box and click to request a captcha, this is a test account so a captcha would be returned by the backend and filled automatically (as shown in the figure below), then click and click to proceed to a matching scene.
  • Open another browser instance, visit http://localhost:7456?expectedRoomId=1, input bddon the username box and click to request a captcha, this is another test account so a captcha would be returned by the backend and filled automatically, then click and click to proceed, when matched a battle(but no competition rule yet) would start.
  • Try out the onscreen virtual joysticks to move the cars and see if their movements are in-sync. screenshot-2

2 Troubleshooting

2.1 Redis snapshot writing failure

ErrFatal        {"err": "MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk. Commands that may modify the data set are disabled. Please check Redis logs for details about the error."}

Just restart your redis-server process.

2.2 Why not show "PING value" on frontend display?

The most important reason for not showing "PING value" is simple: in most games the "PING value" is collected by a dedicated kernel thread which doesn't interfere the UI thread or the primary networking thread. As this demo primarily runs on browser by far, I don't have this capability easily.

Moreover, in practice I found that to spot sync anomalies, the following tools are much more useful than the "PING VALUE".