Firebase 滞后于数据更新 - 多人游戏

Firebase lagging with data updation - Multiplayer game

我使用 Firebase 作为多人开放世界游戏的后端数据库。 我需要高达 100 毫秒的写入速度来让所有播放器实时更新。 我的游戏图形在 LibGdx 引擎下保持流畅,但 Firebase 在写入显示对手玩家到他的延迟位置的数据时滞后。 我正在使用界面与核心 LibGdx 游戏 class 到 Android 功能进行通信(因为 LibGdx 中没有 Firebase)。

请建议我使用 Firebase 实现流畅的数据更新机制并实现流畅的多人游戏方法。 (包括LibGdx)

以下代码显示了我的 Firebase 代码段:

//For writing owners location update
taskMap.clear();
taskMap.put("x", Connect.carX);
taskMap.put("y", carY);
taskMap.put("angle", angle);
taskMap.put("rx", rx);
taskMap.put("ry", ry);
taskMap.put("fx", fx);
taskMap.put("fy", fy);
taskMap.put("wheelAngle", wheelAngle);
db.child("public").child(firebaseAuth.getUid()).updateChildren(taskMap);
taskMap.clear();
taskMap.put("damage", damage);
taskMap.put("gear", gear);
taskMap.put("fuel", fuel);
db.child(firebaseAuth.getUid()).updateChildren(taskMap);


//For reading opponent locations update
LibGdx.core.class.dummyCarUpdate(postSnapshot.getKey(),
Float.parseFloat(postSnapshot.child("x").getValue().toString()),
Float.parseFloat(postSnapshot.child("y").getValue().toString()),
Float.parseFloat(postSnapshot.child("angle").getValue().toString()),
Float.parseFloat(postSnapshot.child("rx").getValue().toString()),
Float.parseFloat(postSnapshot.child("ry").getValue().toString()),
Float.parseFloat(postSnapshot.child("fx").getValue().toString()),
Float.parseFloat(postSnapshot.child("fy").getValue().toString()),
Float.parseFloat(postSnapshot.child("wheelAngle").getValue().toString()));

您正在寻找的技术称为插值法。此技术允许您平滑连接到数据库的客户端上产生的移动。 Learn a bit about interpolation here

您将需要存储以前的数据以插入新数据。您还将决定状态之间的插值速度。