一个联网的开源格斗游戏demo - Websocket+UDP都支持啦 https://forum.cocos.org/t/topic/144489
Go to file
2022-11-02 10:57:37 +08:00
battle_srv Minor fix for "false == Room.BackendDynamicsEnabled". 2022-10-31 09:02:14 +08:00
charts Updated README. 2022-11-02 10:57:37 +08:00
collider_visualizer Updated test cases for frontend-backend-collision-reconciliation. 2022-10-22 13:38:10 +08:00
database/skeema-repo-root Initial commit. 2022-09-20 23:52:55 +08:00
dnmshared Updated test cases for frontend-backend-collision-reconciliation. 2022-10-22 13:38:10 +08:00
frontend Minor fix for "false == Room.BackendDynamicsEnabled". 2022-10-31 09:02:14 +08:00
nginx-templates Initial commit. 2022-09-20 23:52:55 +08:00
.gitattributes Initial commit. 2022-09-20 23:52:55 +08:00
.gitignore Initial commit. 2022-09-20 23:52:55 +08:00
ConcerningEdgeCases.md Minor fix on markdown file. 2022-09-30 23:32:26 +08:00
proto_gen_shortcut.sh Initial commit. 2022-09-20 23:52:55 +08:00
README.md Updated README. 2022-11-02 10:57:37 +08:00

Preface

This project is a demo for a websocket-based input synchronization method inspired by GGPO.

(how input delay roughly works)

input_delay_intro

(in game screenshot)

screenshot-1

Please checkout this demo video to see whether the source codes are doing what you expect for synchronization.

The video mainly shows the following features.

  • The backend receives inputs from frontend peers and by a GGPO-alike manner broadcasts back for synchronization.
  • The game is recovered for a player upon reconnection.
  • Both backend(Golang) and frontend(JavaScript) execute collision detection and handle collision contacts by the same algorithm. The backend dynamics can be toggled off by Room.BackendDynamicsEnabled, but when turned off the game couldn't support recovery upon reconnection.

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 incompatible)
  • 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.2 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.