mirror of
https://github.com/genxium/DelayNoMore
synced 2025-10-17 12:36:46 +00:00
Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
2751569e0c | ||
|
d623916b3c | ||
|
efd070a11b | ||
|
d111de0a7a | ||
|
c2fa251e69 | ||
|
de16e8e8de | ||
|
365177a3af |
@@ -75,4 +75,18 @@ Instead of replacing all use of TCP by UDP, it's more reasonable to keep using T
|
||||
It's not a global consensus, but in practice many UDP communications are platform specific due to their paired asynchronous I/O choices, e.g. epoll in Linux and kqueue in BSD-ish. Of course there're many 3rd party higher level encapsulated tools for cross-platform use but that introduces extra debugging when things go wrong.
|
||||
|
||||
Therefore, the following plan doesn't assume use of any specific 3rd party encapsulation of UDP communication.
|
||||

|
||||

|
||||
|
||||
# Would using WebRTC for all frontends be a `UDP for all` solution?
|
||||
Theoretically yes.
|
||||
|
||||
## Plan to integrate WebRTC
|
||||
The actual integration of WebRTC to enable `browser v.s. native app w/ WebRTC` requires detailed planning :)
|
||||
|
||||
In my current implementation, there's only 1 backend process and it's responsible for all of the following things. The plan for integrating/migrating each item is written respectively.
|
||||
- TURN for UDP tunneling/relay
|
||||
- Some minor modification to [Room.PlayerSecondaryDownsyncSessionDict](https://github.com/genxium/DelayNoMore/blob/365177a3af6033f1cd629a4a4d59beb4557cc311/battle_srv/models/room.go#L126) should be enough to yield a WebRTC API friendly TURN. It's interesting that [though UDP based in transport layer, a WebRTC session is stateful and more similar to WebSocket in terms of API](https://developer.mozilla.org/en-US/docs/Web/API/WebRTC_API).
|
||||
- STUN for UDP holepunching
|
||||
- Some minor modification to [Player.UdpAddr](https://github.com/genxium/DelayNoMore/blob/365177a3af6033f1cd629a4a4d59beb4557cc311/battle_srv/models/player.go#L56) should be enough to yield a WebRTC API friendly STUN.
|
||||
- reconnection recovery
|
||||
- Not sure whether or not I should separate this feature from STUN and TURN, but if I were to do so, [both `Room.RenderFrameBuffer` and `Room.InputsBuffer`](https://github.com/genxium/DelayNoMore/blob/365177a3af6033f1cd629a4a4d59beb4557cc311/battle_srv/models/room.go) should be moved to a shared fast I/O storage (e.g. using Redis) to achieve the same level of `High Availability` in design as STUN and TURN.
|
||||
|
@@ -6,10 +6,14 @@ This project is a demo for a websocket-based rollback netcode inspired by [GGPO]
|
||||
|
||||

|
||||
|
||||
(battle between 2 celluar 4G users using Android phones, [original video here](https://pan.baidu.com/s/1RL-9M-cK8cFS_Q8afMTrJA?pwd=ryzv))
|
||||
|
||||

|
||||
|
||||
As lots of feedbacks ask for a discussion on using UDP instead, I tried to summarize my personal opinion about it in [ConcerningEdgeCases](./ConcerningEdgeCases.md) -- **since v0.9.25, the project is actually equipped with UDP capabilities as follows**.
|
||||
- When using the so called `native apps` on `Android` and `Windows` (I'm working casually hard to support `iOS` next), the frontends will try to use UDP hole-punching w/ the help of backend as a registry. If UDP hole-punching is working, the rollback is often less than `turn-around frames to recover` and thus not noticeable, being much better than using websocket alone. This video shows how the UDP holepunched p2p performs for [Phone-Wifi v.s. PC-Wifi (viewed by PC side)](https://pan.baidu.com/s/1K6704bJKlrSBTVqGcXhajA?pwd=l7ok).
|
||||
- If UDP hole-punching is not working, e.g. for Symmetric NAT like in 4G/5G cellular network, the frontends will use backend as a UDP tunnel (or relay, whatever you like to call it). This video shows how the UDP tunnel performs for [Phone-4G v.s. PC-Wifi (viewed by PC side)](https://pan.baidu.com/s/1IZVa5wVgAdeH6D-xsZYFUw?pwd=dgkj).
|
||||
- Browser vs `native app` is possible but in that case only websocket is used.
|
||||
- If UDP hole-punching is not working, e.g. for Symmetric NAT like in 4G/5G cellular network, the frontends will use backend as a UDP tunnel (or relay, whatever you like to call it). This video shows how the UDP tunnel performs for [Phone-4G v.s. PC-Wifi (merged view@v0.9.34, excellent synchronization)](https://pan.baidu.com/s/1yeIrN5TSf6_av_8-N3vdVg?pwd=7tzw).
|
||||
- Browser vs `native app` is possible but in that case only websocket is used. For WebRTC integration plan please see [ConcerningEdgeCases](./ConcerningEdgeCases.md). You might also be interested in visiting [netplayjs](https://github.com/rameshvarun/netplayjs) to see how others use WebRTC for browser game synchronization as well.
|
||||
|
||||
|
||||
# Notable Features
|
||||
|
@@ -168,7 +168,7 @@ func (pR *Room) updateScore() {
|
||||
pR.Score = calRoomScore(pR.EffectivePlayerCount, pR.Capacity, pR.State)
|
||||
}
|
||||
|
||||
func (pR *Room) AddPlayerIfPossible(pPlayerFromDbInit *Player, session *websocket.Conn, signalToCloseConnOfThisPlayer SignalToCloseConnCbType) bool {
|
||||
func (pR *Room) AddPlayerIfPossible(pPlayerFromDbInit *Player, speciesId int, session *websocket.Conn, signalToCloseConnOfThisPlayer SignalToCloseConnCbType) bool {
|
||||
playerId := pPlayerFromDbInit.Id
|
||||
// TODO: Any thread-safety concern for accessing "pR" here?
|
||||
if RoomBattleStateIns.IDLE != pR.State && RoomBattleStateIns.WAITING != pR.State {
|
||||
@@ -180,7 +180,7 @@ func (pR *Room) AddPlayerIfPossible(pPlayerFromDbInit *Player, session *websocke
|
||||
return false
|
||||
}
|
||||
|
||||
defer pR.onPlayerAdded(playerId)
|
||||
defer pR.onPlayerAdded(playerId, speciesId)
|
||||
|
||||
pPlayerFromDbInit.UdpAddr = nil
|
||||
pPlayerFromDbInit.BattleUdpTunnelAddr = nil
|
||||
@@ -416,15 +416,6 @@ func (pR *Room) StartBattle() {
|
||||
|
||||
pR.RenderFrameId = 0
|
||||
|
||||
for _, player := range pR.Players {
|
||||
speciesId := int(player.JoinIndex - 1) // FIXME: Hardcoded the values for now
|
||||
if player.JoinIndex == 1 {
|
||||
speciesId = 4096
|
||||
}
|
||||
chosenCh := battle.Characters[speciesId]
|
||||
pR.CharacterConfigsArr[player.JoinIndex-1] = chosenCh
|
||||
pR.SpeciesIdList[player.JoinIndex-1] = int32(speciesId)
|
||||
}
|
||||
Logger.Info("[StartBattle] ", zap.Any("roomId", pR.Id), zap.Any("roomState", pR.State), zap.Any("SpeciesIdList", pR.SpeciesIdList))
|
||||
|
||||
// Initialize the "collisionSys" as well as "RenderFrameBuffer"
|
||||
@@ -954,7 +945,7 @@ func (pR *Room) clearPlayerNetworkSession(playerId int32) {
|
||||
}
|
||||
}
|
||||
|
||||
func (pR *Room) onPlayerAdded(playerId int32) {
|
||||
func (pR *Room) onPlayerAdded(playerId int32, speciesId int) {
|
||||
pR.EffectivePlayerCount++
|
||||
|
||||
if 1 == pR.EffectivePlayerCount {
|
||||
@@ -966,8 +957,9 @@ func (pR *Room) onPlayerAdded(playerId int32) {
|
||||
pR.Players[playerId].JoinIndex = int32(index) + 1
|
||||
pR.JoinIndexBooleanArr[index] = true
|
||||
|
||||
speciesId := index // FIXME
|
||||
pR.SpeciesIdList[index] = int32(speciesId)
|
||||
chosenCh := battle.Characters[speciesId]
|
||||
pR.CharacterConfigsArr[index] = chosenCh
|
||||
pR.Players[playerId].Speed = chosenCh.Speed
|
||||
|
||||
// Lazily assign the initial position of "Player" for "RoomDownsyncFrame".
|
||||
|
@@ -50,7 +50,17 @@ func Serve(c *gin.Context) {
|
||||
|
||||
boundRoomId := 0
|
||||
expectedRoomId := 0
|
||||
speciesId := 0
|
||||
var err error
|
||||
if speciesIdStr, hasSpeciesId := c.GetQuery("speciesId"); hasSpeciesId {
|
||||
speciesId, err = strconv.Atoi(speciesIdStr)
|
||||
if err != nil {
|
||||
// TODO: Abort with specific message.
|
||||
c.AbortWithStatus(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if boundRoomIdStr, hasBoundRoomId := c.GetQuery("boundRoomId"); hasBoundRoomId {
|
||||
boundRoomId, err = strconv.Atoi(boundRoomIdStr)
|
||||
if err != nil {
|
||||
@@ -195,7 +205,7 @@ func Serve(c *gin.Context) {
|
||||
|
||||
if pRoom.ReAddPlayerIfPossible(pPlayer, conn, signalToCloseConnOfThisPlayer) {
|
||||
playerSuccessfullyAddedToRoom = true
|
||||
} else if pRoom.AddPlayerIfPossible(pPlayer, conn, signalToCloseConnOfThisPlayer) {
|
||||
} else if pRoom.AddPlayerIfPossible(pPlayer, speciesId, conn, signalToCloseConnOfThisPlayer) {
|
||||
playerSuccessfullyAddedToRoom = true
|
||||
} else {
|
||||
Logger.Warn("Failed to get:\n", zap.Any("roomId", pRoom.Id), zap.Any("playerId", playerId), zap.Any("forExpectedRoomId", expectedRoomId))
|
||||
@@ -219,7 +229,7 @@ func Serve(c *gin.Context) {
|
||||
} else {
|
||||
pRoom = tmpRoom
|
||||
Logger.Info("Successfully popped:\n", zap.Any("roomId", pRoom.Id), zap.Any("forPlayerId", playerId))
|
||||
res := pRoom.AddPlayerIfPossible(pPlayer, conn, signalToCloseConnOfThisPlayer)
|
||||
res := pRoom.AddPlayerIfPossible(pPlayer, speciesId, conn, signalToCloseConnOfThisPlayer)
|
||||
if !res {
|
||||
signalToCloseConnOfThisPlayer(Constants.RetCode.PlayerNotAddableToRoom, fmt.Sprintf("AddPlayerIfPossible returns false for roomId == %v, playerId == %v!", pRoom.Id, playerId))
|
||||
}
|
||||
|
BIN
charts/Phone4g_battle_spedup.gif
Normal file
BIN
charts/Phone4g_battle_spedup.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.4 MiB |
@@ -48,13 +48,13 @@
|
||||
}
|
||||
},
|
||||
{
|
||||
"frame": 0.45,
|
||||
"frame": 0.4,
|
||||
"value": {
|
||||
"__uuid__": "487b65c3-44e3-4b0e-9350-e0d1c952785b"
|
||||
}
|
||||
},
|
||||
{
|
||||
"frame": 0.5,
|
||||
"frame": 0.4166666666666667,
|
||||
"value": {
|
||||
"__uuid__": "9a5357ae-a160-4198-a6d5-cc9631fde754"
|
||||
}
|
||||
|
@@ -59,6 +59,12 @@
|
||||
"__uuid__": "0ecf4a0c-0f13-42fa-a214-b4826acd8556"
|
||||
}
|
||||
},
|
||||
{
|
||||
"frame": 0.3,
|
||||
"value": {
|
||||
"__uuid__": "cabf9cb6-99ca-426d-9a23-95cdec6f06b9"
|
||||
}
|
||||
},
|
||||
{
|
||||
"frame": 0.3333333333333333,
|
||||
"value": {
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -461,7 +461,7 @@
|
||||
"array": [
|
||||
0,
|
||||
0,
|
||||
216.50635094610968,
|
||||
210.59754059453806,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
|
@@ -547,7 +547,7 @@
|
||||
"array": [
|
||||
0,
|
||||
0,
|
||||
216.50635094610968,
|
||||
209.61049002258042,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
|
41
frontend/assets/scripts/CharacterSelectCell.js
Normal file
41
frontend/assets/scripts/CharacterSelectCell.js
Normal file
@@ -0,0 +1,41 @@
|
||||
cc.Class({
|
||||
extends: cc.Component,
|
||||
properties: {
|
||||
panelNode: {
|
||||
type: cc.Node,
|
||||
default: null
|
||||
},
|
||||
chosenFlag: {
|
||||
type: cc.Sprite,
|
||||
default: null
|
||||
},
|
||||
avatarNode: {
|
||||
type: cc.Button,
|
||||
default: null
|
||||
},
|
||||
animNode: {
|
||||
type: cc.Node,
|
||||
default: null
|
||||
},
|
||||
speciesId: {
|
||||
type: cc.Integer,
|
||||
default: 0
|
||||
},
|
||||
},
|
||||
|
||||
ctor() {},
|
||||
|
||||
setInteractable(enabled) {
|
||||
this.avatarNode.interactable = enabled;
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
const avatarNodeClickEventHandler = new cc.Component.EventHandler();
|
||||
avatarNodeClickEventHandler.target = this.panelNode;
|
||||
avatarNodeClickEventHandler.component = "GameRule";
|
||||
avatarNodeClickEventHandler.handler = "onSpeciesSelected";
|
||||
avatarNodeClickEventHandler.customEventData = this.speciesId;
|
||||
this.avatarNode.clickEvents.push(avatarNodeClickEventHandler);
|
||||
},
|
||||
});
|
||||
|
9
frontend/assets/scripts/CharacterSelectCell.js.meta
Normal file
9
frontend/assets/scripts/CharacterSelectCell.js.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.0.5",
|
||||
"uuid": "6dd2c047-fa5c-4080-8221-27fabfd275d6",
|
||||
"isPlugin": false,
|
||||
"loadPluginInWeb": true,
|
||||
"loadPluginInNative": true,
|
||||
"loadPluginInEditor": false,
|
||||
"subMetas": {}
|
||||
}
|
@@ -10,15 +10,32 @@ cc.Class({
|
||||
type: cc.Node,
|
||||
default: null
|
||||
},
|
||||
characterSelectCells: {
|
||||
type: cc.Node,
|
||||
default: []
|
||||
},
|
||||
chosenSpeciesId: {
|
||||
type: cc.Integer,
|
||||
default: 0
|
||||
},
|
||||
},
|
||||
|
||||
// LIFE-CYCLE CALLBACKS:
|
||||
onLoad() {
|
||||
const modeBtnClickEventHandler = new cc.Component.EventHandler();
|
||||
modeBtnClickEventHandler.target = this.mapNode;
|
||||
modeBtnClickEventHandler.component = "Map";
|
||||
modeBtnClickEventHandler.handler = "onGameRule1v1ModeClicked";
|
||||
this.modeButton.clickEvents.push(modeBtnClickEventHandler);
|
||||
}
|
||||
|
||||
onLoad() {},
|
||||
|
||||
onSpeciesSelected(evt, val) {
|
||||
for (let cell of this.characterSelectCells) {
|
||||
const comp = cell.getComponent("CharacterSelectCell");
|
||||
if (comp.speciesId != val) {
|
||||
comp.chosenFlag.node.active = false;
|
||||
} else {
|
||||
comp.chosenFlag.node.active = true;
|
||||
this.chosenSpeciesId = val;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
onModeButtonClicked(evt) {
|
||||
this.mapNode.getComponent("Map").onGameRule1v1ModeClicked(this.chosenSpeciesId);
|
||||
},
|
||||
});
|
||||
|
@@ -1230,9 +1230,10 @@ othersForcedDownsyncRenderFrame=${JSON.stringify(othersForcedDownsyncRenderFrame
|
||||
self.enableInputControls();
|
||||
},
|
||||
|
||||
onGameRule1v1ModeClicked(evt, cb) {
|
||||
onGameRule1v1ModeClicked(chosenSpeciesId) {
|
||||
const self = this;
|
||||
self.battleState = ALL_BATTLE_STATES.WAITING;
|
||||
window.chosenSpeciesId = chosenSpeciesId; // TODO: Find a better way to pass it into "self.initAfterWSConnected"!
|
||||
window.initPersistentSessionClient(self.initAfterWSConnected, null /* Deliberately NOT passing in any `expectedRoomId`. -- YFLu */ );
|
||||
self.hideGameRuleNode();
|
||||
},
|
||||
@@ -1306,7 +1307,7 @@ othersForcedDownsyncRenderFrame=${JSON.stringify(othersForcedDownsyncRenderFrame
|
||||
}
|
||||
for (let k in rdf.MeleeBullets) {
|
||||
const meleeBullet = rdf.MeleeBullets[k];
|
||||
const isExploding = (window.BULLET_STATE.Exploding == meleeBullet.BlState);
|
||||
const isExploding = (window.BULLET_STATE.Exploding == meleeBullet.BlState && meleeBullet.FramesInBlState < meleeBullet.Bullet.ExplosionFrames);
|
||||
if (isExploding) {
|
||||
let pqNode = self.cachedFireballs.popAny(meleeBullet.BattleAttr.BulletLocalId);
|
||||
let speciesName = `MeleeExplosion`;
|
||||
|
@@ -58,10 +58,21 @@ window.getBoundRoomCapacityFromPersistentStorage = function() {
|
||||
return (null == boundRoomCapacityStr ? null : parseInt(boundRoomCapacityStr));
|
||||
};
|
||||
|
||||
window.getChosenSpeciesIdFromPersistentStorage = function() {
|
||||
const boundRoomIdExpiresAt = parseInt(cc.sys.localStorage.getItem("boundRoomIdExpiresAt"));
|
||||
if (!boundRoomIdExpiresAt || Date.now() >= boundRoomIdExpiresAt) {
|
||||
window.clearBoundRoomIdInBothVolatileAndPersistentStorage();
|
||||
return null;
|
||||
}
|
||||
const chosenSpeciesIdStr = cc.sys.localStorage.getItem("chosenSpeciesId");
|
||||
return (null == chosenSpeciesIdStr ? 0 : parseInt(chosenSpeciesIdStr));
|
||||
};
|
||||
|
||||
window.clearBoundRoomIdInBothVolatileAndPersistentStorage = function() {
|
||||
window.boundRoomId = null;
|
||||
cc.sys.localStorage.removeItem("boundRoomId");
|
||||
cc.sys.localStorage.removeItem("boundRoomCapacity");
|
||||
cc.sys.localStorage.removeItem("chosenSpeciesId");
|
||||
cc.sys.localStorage.removeItem("boundRoomIdExpiresAt");
|
||||
};
|
||||
|
||||
@@ -84,6 +95,7 @@ window.handleHbRequirements = function(resp) {
|
||||
window.boundRoomCapacity = resp.bciFrame.boundRoomCapacity;
|
||||
cc.sys.localStorage.setItem('boundRoomId', window.boundRoomId);
|
||||
cc.sys.localStorage.setItem('boundRoomCapacity', window.boundRoomCapacity);
|
||||
cc.sys.localStorage.setItem('chosenSpeciesId', window.chosenSpeciesId);
|
||||
cc.sys.localStorage.setItem('boundRoomIdExpiresAt', Date.now() + 10 * 60 * 1000); // Temporarily hardcoded, for `boundRoomId` only.
|
||||
}
|
||||
console.log(`Handle hb requirements #3`);
|
||||
@@ -179,6 +191,13 @@ window.initPersistentSessionClient = function(onopenCb, expectedRoomId) {
|
||||
}
|
||||
}
|
||||
|
||||
if (null == window.chosenSpeciesId) {
|
||||
window.chosenSpeciesId = getChosenSpeciesIdFromPersistentStorage();
|
||||
}
|
||||
if (null != window.chosenSpeciesId) {
|
||||
urlToConnect = urlToConnect + "&speciesId=" + window.chosenSpeciesId;
|
||||
}
|
||||
|
||||
const clientSession = new WebSocket(urlToConnect);
|
||||
clientSession.binaryType = 'arraybuffer'; // Make 'event.data' of 'onmessage' an "ArrayBuffer" instead of a "Blob"
|
||||
|
||||
@@ -230,9 +249,9 @@ window.initPersistentSessionClient = function(onopenCb, expectedRoomId) {
|
||||
const peerAddrList = resp.rdf.peerUdpAddrList;
|
||||
console.log(`Got DOWNSYNC_MSG_ACT_PEER_UDP_ADDR peerAddrList=${JSON.stringify(peerAddrList)}; boundRoomCapacity=${window.boundRoomCapacity}`);
|
||||
for (let j = 0; j < 3; ++j) {
|
||||
setTimeout(()=> {
|
||||
DelayNoMore.UdpSession.upsertPeerUdpAddr(peerAddrList, window.boundRoomCapacity, window.mapIns.selfPlayerInfo.JoinIndex); // In C++ impl it actually broadcasts the peer-punching message to all known peers within "window.boundRoomCapacity"
|
||||
}, j*500);
|
||||
setTimeout(() => {
|
||||
DelayNoMore.UdpSession.upsertPeerUdpAddr(peerAddrList, window.boundRoomCapacity, window.mapIns.selfPlayerInfo.JoinIndex); // In C++ impl it actually broadcasts the peer-punching message to all known peers within "window.boundRoomCapacity"
|
||||
}, j * 500);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
File diff suppressed because one or more lines are too long
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"ver": "1.0.5",
|
||||
"uuid": "171e2c96-28b4-4225-bdcc-5e464f07d91a",
|
||||
"uuid": "eeaa56f4-bd6c-4208-bec4-6ab1aa39ca93",
|
||||
"isPlugin": true,
|
||||
"loadPluginInWeb": true,
|
||||
"loadPluginInNative": true,
|
||||
|
7
frontend/build-templates/.cocos-project.json
Normal file
7
frontend/build-templates/.cocos-project.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"engine_version": "2.2.1",
|
||||
"has_native": true,
|
||||
"project_type": "js",
|
||||
"projectName": "DelayNoMore",
|
||||
"packageName": "org.genxium.delaynomore"
|
||||
}
|
@@ -18,11 +18,11 @@
|
||||
"from": "cocos/scripting/js-bindings/manual/jsb_module_register.cpp",
|
||||
"to": "frameworks/runtime-src/Classes/jsb_module_register.cpp"
|
||||
}, {
|
||||
"from": "frameworks/runtime-src/Classes/send_ring_buff.hpp",
|
||||
"to": "frameworks/runtime-src/Classes/send_ring_buff.hpp"
|
||||
"from": "frameworks/runtime-src/Classes/ring_buff.hpp",
|
||||
"to": "frameworks/runtime-src/Classes/ring_buff.hpp"
|
||||
}, {
|
||||
"from": "frameworks/runtime-src/Classes/send_ring_buff.cpp",
|
||||
"to": "frameworks/runtime-src/Classes/send_ring_buff.cpp"
|
||||
"from": "frameworks/runtime-src/Classes/ring_buff.cpp",
|
||||
"to": "frameworks/runtime-src/Classes/ring_buff.cpp"
|
||||
}, {
|
||||
"from": "frameworks/runtime-src/Classes/udp_session.hpp",
|
||||
"to": "frameworks/runtime-src/Classes/udp_session.hpp"
|
||||
|
@@ -1,5 +1,5 @@
|
||||
#include <string.h>
|
||||
#include "send_ring_buff.hpp"
|
||||
#include "ring_buff.hpp"
|
||||
|
||||
// Sending
|
||||
void SendRingBuff::put(BYTEC* const newBytes, size_t newBytesLen, PeerAddr* pNewPeerAddr) {
|
||||
@@ -77,7 +77,7 @@ bool RecvRingBuff::pop(RecvWork* out) {
|
||||
if (0 >= oldCnt) {
|
||||
// "pop" could be accessed by either "GameThread/pollUdpRecvRingBuff" or "UvRecvThread/put", thus we should be proactively guard against concurrent popping while "1 == cnt"
|
||||
++cnt;
|
||||
return NULL;
|
||||
return false;
|
||||
}
|
||||
|
||||
// When concurrent "pop"s reach here, over-popping is definitely avoided.
|
||||
@@ -99,4 +99,4 @@ bool RecvRingBuff::pop(RecvWork* out) {
|
||||
++cnt;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,7 +1,7 @@
|
||||
#ifndef udp_session_hpp
|
||||
#define udp_session_hpp
|
||||
|
||||
#include "send_ring_buff.hpp"
|
||||
#include "ring_buff.hpp"
|
||||
|
||||
int const maxPeerCnt = 10;
|
||||
|
||||
|
@@ -15,7 +15,7 @@ LOCAL_SRC_FILES := hellojavascript/main.cpp \
|
||||
../../../Classes/jsb_module_register.cpp \
|
||||
../../../Classes/udp_session.cpp \
|
||||
../../../Classes/udp_session_bridge.cpp \
|
||||
../../../Classes/send_ring_buff.cpp
|
||||
../../../Classes/ring_buff.cpp
|
||||
|
||||
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../Classes
|
||||
|
||||
|
@@ -190,11 +190,11 @@ copy "$(ProjectDir)..\..\..\project.json" "$(OutDir)\" /Y</Command>
|
||||
<ClCompile Include="..\Classes\AppDelegate.cpp" />
|
||||
<ClCompile Include="..\Classes\udp_session.cpp" />
|
||||
<ClCompile Include="..\Classes\udp_session_bridge.cpp" />
|
||||
<ClCompile Include="..\Classes\send_ring_buff.cpp" />
|
||||
<ClCompile Include="..\Classes\ring_buff.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="main.h" />
|
||||
<ClInclude Include="..\Classes\send_ring_buff.hpp" />
|
||||
<ClInclude Include="..\Classes\ring_buff.hpp" />
|
||||
<ClInclude Include="..\Classes\udp_session.hpp" />
|
||||
<ClInclude Include="..\Classes\udp_session_bridge.hpp" />
|
||||
<ClInclude Include="..\Classes\AppDelegate.h" />
|
||||
|
@@ -22,7 +22,7 @@
|
||||
<ClCompile Include="..\Classes\jsb_module_register.cpp">
|
||||
<Filter>Classes</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\Classes\send_ring_buff.cpp">
|
||||
<ClCompile Include="..\Classes\ring_buff.cpp">
|
||||
<Filter>Classes</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\Classes\udp_session.cpp">
|
||||
@@ -40,7 +40,7 @@
|
||||
<Filter>win32</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="resource.h" />
|
||||
<ClInclude Include="..\Classes\send_ring_buff.hpp">
|
||||
<ClInclude Include="..\Classes\ring_buff.hpp">
|
||||
<Filter>Classes</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\Classes\udp_session.hpp">
|
||||
|
@@ -22,7 +22,7 @@ const (
|
||||
GRAVITY_X = int32(0)
|
||||
GRAVITY_Y = -int32(float64(0.5) * WORLD_TO_VIRTUAL_GRID_RATIO) // makes all "playerCollider.Y" a multiple of 0.5 in all cases
|
||||
|
||||
INPUT_DELAY_FRAMES = int32(6) // in the count of render frames
|
||||
INPUT_DELAY_FRAMES = int32(5) // in the count of render frames
|
||||
|
||||
/*
|
||||
[WARNING]
|
||||
@@ -716,7 +716,7 @@ func ApplyInputFrameDownsyncDynamicsOnSingleRenderFrame(inputsBuffer *RingBuffer
|
||||
} else if stoppingFromWalking {
|
||||
thatPlayerInNextFrame.FramesToRecover = chConfig.InertiaFramesToRecover
|
||||
} else {
|
||||
thatPlayerInNextFrame.FramesToRecover = (chConfig.InertiaFramesToRecover >> 1)
|
||||
thatPlayerInNextFrame.FramesToRecover = ((chConfig.InertiaFramesToRecover >> 1) + (chConfig.InertiaFramesToRecover >> 2))
|
||||
}
|
||||
} else {
|
||||
thatPlayerInNextFrame.CapturedByInertia = false
|
||||
@@ -757,8 +757,19 @@ func ApplyInputFrameDownsyncDynamicsOnSingleRenderFrame(inputsBuffer *RingBuffer
|
||||
if 0 >= thatPlayerInNextFrame.Hp && 0 == thatPlayerInNextFrame.FramesToRecover {
|
||||
// Revive from Dying
|
||||
newVx, newVy = currPlayerDownsync.RevivalVirtualGridX, currPlayerDownsync.RevivalVirtualGridY
|
||||
thatPlayerInNextFrame.CharacterState = ATK_CHARACTER_STATE_IDLE1
|
||||
thatPlayerInNextFrame.CharacterState = ATK_CHARACTER_STATE_GET_UP1
|
||||
thatPlayerInNextFrame.FramesInChState = ATK_CHARACTER_STATE_GET_UP1
|
||||
thatPlayerInNextFrame.FramesToRecover = chConfig.GetUpFramesToRecover
|
||||
thatPlayerInNextFrame.FramesInvinsible = chConfig.GetUpInvinsibleFrames
|
||||
thatPlayerInNextFrame.Hp = currPlayerDownsync.MaxHp
|
||||
// Hardcoded initial character orientation/facing
|
||||
if 0 == (thatPlayerInNextFrame.JoinIndex % 2) {
|
||||
thatPlayerInNextFrame.DirX = -2
|
||||
thatPlayerInNextFrame.DirY = 0
|
||||
} else {
|
||||
thatPlayerInNextFrame.DirX = +2
|
||||
thatPlayerInNextFrame.DirY = 0
|
||||
}
|
||||
}
|
||||
if jumpedOrNotList[i] {
|
||||
// We haven't proceeded with "OnWall" calculation for "thatPlayerInNextFrame", thus use "currPlayerDownsync.OnWall" for checking
|
||||
@@ -899,8 +910,12 @@ func ApplyInputFrameDownsyncDynamicsOnSingleRenderFrame(inputsBuffer *RingBuffer
|
||||
if collision := playerCollider.Check(0, 0); nil != collision {
|
||||
for _, obj := range collision.Objects {
|
||||
isBarrier, isAnotherPlayer, isBullet := false, false, false
|
||||
switch obj.Data.(type) {
|
||||
switch v := obj.Data.(type) {
|
||||
case *PlayerDownsync:
|
||||
if ATK_CHARACTER_STATE_DYING == v.CharacterState {
|
||||
// ignore collision with dying player
|
||||
continue
|
||||
}
|
||||
isAnotherPlayer = true
|
||||
case *MeleeBullet, *FireballBullet:
|
||||
isBullet = true
|
||||
@@ -912,6 +927,7 @@ func ApplyInputFrameDownsyncDynamicsOnSingleRenderFrame(inputsBuffer *RingBuffer
|
||||
// ignore bullets for this step
|
||||
continue
|
||||
}
|
||||
|
||||
bShape := obj.Shape.(*resolv.ConvexPolygon)
|
||||
overlapped, pushbackX, pushbackY, overlapResult := calcPushbacks(0, 0, playerShape, bShape)
|
||||
if !overlapped {
|
||||
@@ -1013,113 +1029,83 @@ func ApplyInputFrameDownsyncDynamicsOnSingleRenderFrame(inputsBuffer *RingBuffer
|
||||
collision := bulletCollider.Check(0, 0)
|
||||
bulletCollider.Space.Remove(bulletCollider) // Make sure that the bulletCollider is always removed for each renderFrame
|
||||
exploded := false
|
||||
if nil != collision {
|
||||
switch v := bulletCollider.Data.(type) {
|
||||
case *MeleeBullet:
|
||||
bulletShape := bulletCollider.Shape.(*resolv.ConvexPolygon)
|
||||
offender := currRenderFrame.PlayersArr[v.BattleAttr.OffenderJoinIndex-1]
|
||||
for _, obj := range collision.Objects {
|
||||
defenderShape := obj.Shape.(*resolv.ConvexPolygon)
|
||||
switch t := obj.Data.(type) {
|
||||
case *PlayerDownsync:
|
||||
if v.BattleAttr.OffenderJoinIndex == t.JoinIndex {
|
||||
continue
|
||||
}
|
||||
overlapped, _, _, _ := calcPushbacks(0, 0, bulletShape, defenderShape)
|
||||
if !overlapped {
|
||||
continue
|
||||
}
|
||||
exploded = true
|
||||
if _, existent := invinsibleSet[t.CharacterState]; existent {
|
||||
continue
|
||||
}
|
||||
if 0 < t.FramesInvinsible {
|
||||
continue
|
||||
}
|
||||
xfac := int32(1) // By now, straight Punch offset doesn't respect "y-axis"
|
||||
if 0 > offender.DirX {
|
||||
xfac = -xfac
|
||||
}
|
||||
atkedPlayerInNextFrame := nextRenderFramePlayers[t.JoinIndex-1]
|
||||
atkedPlayerInNextFrame.Hp -= v.Bullet.Damage
|
||||
if 0 >= atkedPlayerInNextFrame.Hp {
|
||||
// [WARNING] We don't have "dying in air" animation for now, and for better graphical recognition, play the same dying animation even in air
|
||||
atkedPlayerInNextFrame.Hp = 0
|
||||
atkedPlayerInNextFrame.CharacterState = ATK_CHARACTER_STATE_DYING
|
||||
atkedPlayerInNextFrame.FramesToRecover = DYING_FRAMES_TO_RECOVER
|
||||
} else {
|
||||
pushbackVelX, pushbackVelY := xfac*v.Bullet.PushbackVelX, v.Bullet.PushbackVelY
|
||||
atkedPlayerInNextFrame.VelX = pushbackVelX
|
||||
atkedPlayerInNextFrame.VelY = pushbackVelY
|
||||
if v.Bullet.BlowUp {
|
||||
atkedPlayerInNextFrame.CharacterState = ATK_CHARACTER_STATE_BLOWN_UP1
|
||||
} else {
|
||||
atkedPlayerInNextFrame.CharacterState = ATK_CHARACTER_STATE_ATKED1
|
||||
}
|
||||
oldFramesToRecover := nextRenderFramePlayers[t.JoinIndex-1].FramesToRecover
|
||||
if v.Bullet.HitStunFrames > oldFramesToRecover {
|
||||
atkedPlayerInNextFrame.FramesToRecover = v.Bullet.HitStunFrames
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
case *FireballBullet:
|
||||
bulletShape := bulletCollider.Shape.(*resolv.ConvexPolygon)
|
||||
offender := currRenderFrame.PlayersArr[v.BattleAttr.OffenderJoinIndex-1]
|
||||
for _, obj := range collision.Objects {
|
||||
defenderShape := obj.Shape.(*resolv.ConvexPolygon)
|
||||
switch t := obj.Data.(type) {
|
||||
case *PlayerDownsync:
|
||||
if v.BattleAttr.OffenderJoinIndex == t.JoinIndex {
|
||||
continue
|
||||
}
|
||||
overlapped, _, _, _ := calcPushbacks(0, 0, bulletShape, defenderShape)
|
||||
if !overlapped {
|
||||
continue
|
||||
}
|
||||
exploded = true
|
||||
if _, existent := invinsibleSet[t.CharacterState]; existent {
|
||||
continue
|
||||
}
|
||||
if 0 < t.FramesInvinsible {
|
||||
continue
|
||||
}
|
||||
xfac := int32(1) // By now, straight Punch offset doesn't respect "y-axis"
|
||||
if 0 > offender.DirX {
|
||||
xfac = -xfac
|
||||
}
|
||||
atkedPlayerInNextFrame := nextRenderFramePlayers[t.JoinIndex-1]
|
||||
atkedPlayerInNextFrame.Hp -= v.Bullet.Damage
|
||||
if 0 >= atkedPlayerInNextFrame.Hp {
|
||||
// [WARNING] We don't have "dying in air" animation for now, and for better graphical recognition, play the same dying animation even in air
|
||||
atkedPlayerInNextFrame.Hp = 0
|
||||
atkedPlayerInNextFrame.CharacterState = ATK_CHARACTER_STATE_DYING
|
||||
atkedPlayerInNextFrame.FramesToRecover = DYING_FRAMES_TO_RECOVER
|
||||
} else {
|
||||
pushbackVelX, pushbackVelY := xfac*v.Bullet.PushbackVelX, v.Bullet.PushbackVelY
|
||||
atkedPlayerInNextFrame.VelX = pushbackVelX
|
||||
atkedPlayerInNextFrame.VelY = pushbackVelY
|
||||
if v.Bullet.BlowUp {
|
||||
atkedPlayerInNextFrame.CharacterState = ATK_CHARACTER_STATE_BLOWN_UP1
|
||||
} else {
|
||||
atkedPlayerInNextFrame.CharacterState = ATK_CHARACTER_STATE_ATKED1
|
||||
}
|
||||
oldFramesToRecover := nextRenderFramePlayers[t.JoinIndex-1].FramesToRecover
|
||||
if v.Bullet.HitStunFrames > oldFramesToRecover {
|
||||
atkedPlayerInNextFrame.FramesToRecover = v.Bullet.HitStunFrames
|
||||
}
|
||||
}
|
||||
default:
|
||||
exploded = true
|
||||
explodedOnAnotherPlayer := false
|
||||
if nil == collision {
|
||||
continue
|
||||
}
|
||||
|
||||
var bulletStaticAttr *BulletConfig = nil
|
||||
var bulletBattleAttr *BulletBattleAttr = nil
|
||||
switch v := bulletCollider.Data.(type) {
|
||||
case *MeleeBullet:
|
||||
bulletStaticAttr = v.Bullet
|
||||
bulletBattleAttr = v.BattleAttr
|
||||
case *FireballBullet:
|
||||
bulletStaticAttr = v.Bullet
|
||||
bulletBattleAttr = v.BattleAttr
|
||||
}
|
||||
|
||||
bulletShape := bulletCollider.Shape.(*resolv.ConvexPolygon)
|
||||
offender := currRenderFrame.PlayersArr[bulletBattleAttr.OffenderJoinIndex-1]
|
||||
for _, obj := range collision.Objects {
|
||||
defenderShape := obj.Shape.(*resolv.ConvexPolygon)
|
||||
switch t := obj.Data.(type) {
|
||||
case *PlayerDownsync:
|
||||
if bulletBattleAttr.OffenderJoinIndex == t.JoinIndex {
|
||||
continue
|
||||
}
|
||||
overlapped, _, _, _ := calcPushbacks(0, 0, bulletShape, defenderShape)
|
||||
if !overlapped {
|
||||
continue
|
||||
}
|
||||
if _, existent := invinsibleSet[t.CharacterState]; existent {
|
||||
continue
|
||||
}
|
||||
if 0 < t.FramesInvinsible {
|
||||
continue
|
||||
}
|
||||
exploded = true
|
||||
explodedOnAnotherPlayer = true
|
||||
xfac := int32(1) // By now, straight Punch offset doesn't respect "y-axis"
|
||||
if 0 > offender.DirX {
|
||||
xfac = -xfac
|
||||
}
|
||||
atkedPlayerInNextFrame := nextRenderFramePlayers[t.JoinIndex-1]
|
||||
atkedPlayerInNextFrame.Hp -= bulletStaticAttr.Damage
|
||||
if 0 >= atkedPlayerInNextFrame.Hp {
|
||||
// [WARNING] We don't have "dying in air" animation for now, and for better graphical recognition, play the same dying animation even in air
|
||||
atkedPlayerInNextFrame.Hp = 0
|
||||
atkedPlayerInNextFrame.CharacterState = ATK_CHARACTER_STATE_DYING
|
||||
atkedPlayerInNextFrame.FramesToRecover = DYING_FRAMES_TO_RECOVER
|
||||
} else {
|
||||
pushbackVelX, pushbackVelY := xfac*bulletStaticAttr.PushbackVelX, bulletStaticAttr.PushbackVelY
|
||||
atkedPlayerInNextFrame.VelX = pushbackVelX
|
||||
atkedPlayerInNextFrame.VelY = pushbackVelY
|
||||
if bulletStaticAttr.BlowUp {
|
||||
atkedPlayerInNextFrame.CharacterState = ATK_CHARACTER_STATE_BLOWN_UP1
|
||||
} else {
|
||||
atkedPlayerInNextFrame.CharacterState = ATK_CHARACTER_STATE_ATKED1
|
||||
}
|
||||
oldFramesToRecover := nextRenderFramePlayers[t.JoinIndex-1].FramesToRecover
|
||||
if bulletStaticAttr.HitStunFrames > oldFramesToRecover {
|
||||
atkedPlayerInNextFrame.FramesToRecover = bulletStaticAttr.HitStunFrames
|
||||
}
|
||||
}
|
||||
default:
|
||||
exploded = true
|
||||
}
|
||||
}
|
||||
|
||||
if exploded {
|
||||
switch v := bulletCollider.Data.(type) {
|
||||
case *MeleeBullet:
|
||||
v.BlState = BULLET_EXPLODING
|
||||
v.FramesInBlState = 0
|
||||
if explodedOnAnotherPlayer {
|
||||
v.FramesInBlState = 0
|
||||
} else {
|
||||
// When hitting a barrier, don't play explosion anim
|
||||
v.FramesInBlState = v.Bullet.ExplosionFrames + 1
|
||||
}
|
||||
//fmt.Printf("melee exploded @currRenderFrame.Id=%d, bulletLocalId=%d, blState=%d\n", currRenderFrame.Id, v.BattleAttr.BulletLocalId, v.BlState)
|
||||
case *FireballBullet:
|
||||
v.BlState = BULLET_EXPLODING
|
||||
|
@@ -538,7 +538,7 @@ var skills = map[int]*Skill{
|
||||
HitboxSizeX: int32(float64(64) * WORLD_TO_VIRTUAL_GRID_RATIO),
|
||||
HitboxSizeY: int32(float64(48) * WORLD_TO_VIRTUAL_GRID_RATIO),
|
||||
BlowUp: false,
|
||||
ExplosionFrames: 10,
|
||||
ExplosionFrames: 30,
|
||||
SpeciesId: int32(1),
|
||||
},
|
||||
},
|
||||
@@ -781,10 +781,10 @@ var skills = map[int]*Skill{
|
||||
Hits: []interface{}{
|
||||
&MeleeBullet{
|
||||
Bullet: &BulletConfig{
|
||||
StartupFrames: int32(3),
|
||||
StartupFrames: int32(4),
|
||||
ActiveFrames: int32(20),
|
||||
HitStunFrames: int32(18),
|
||||
BlockStunFrames: int32(9),
|
||||
HitStunFrames: int32(9),
|
||||
BlockStunFrames: int32(5),
|
||||
Damage: int32(5),
|
||||
SelfLockVelX: NO_LOCK_VEL,
|
||||
SelfLockVelY: NO_LOCK_VEL,
|
||||
|
@@ -1,3 +1,5 @@
|
||||
# TODO: For websocket traffic, use a "consistent hash" on "expectedRoomId" and "boundRoomId"!
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
server_name tsrht.lokcol.com;
|
||||
|
Reference in New Issue
Block a user