diff --git a/apps/server/src/Common/Binary.ts b/apps/server/src/Common/Binary.ts index 696a255..054b1f0 100644 --- a/apps/server/src/Common/Binary.ts +++ b/apps/server/src/Common/Binary.ts @@ -1,5 +1,5 @@ import { ApiMsgEnum, InputTypeEnum } from "./Enum"; -import { strdecode, strencode } from "./Utils"; +import { strdecode, strencode, toFixed } from "./Utils"; const encodeActorMove = (proto: ApiMsgEnum, data: any, view: DataView, index: number) => { view.setUint8(index++, data.type) @@ -103,11 +103,11 @@ export const binaryEncode = (proto: ApiMsgEnum, data: any): DataView => { const decodeActorMove = (view: DataView, index: number) => { const id = view.getUint8(index++) - const directionX = view.getFloat32(index) + const directionX = toFixed(view.getFloat32(index)) index += 4 - const directionY = view.getFloat32(index) + const directionY = toFixed(view.getFloat32(index)) index += 4 - const dt = view.getFloat32(index) + const dt = toFixed(view.getFloat32(index)) index += 4 const msg = { name: ApiMsgEnum.MsgClientSync, @@ -127,13 +127,13 @@ const decodeActorMove = (view: DataView, index: number) => { const decodeWeaponShoot = (view: DataView, index: number) => { const owner = view.getUint8(index++) - const positionX = view.getFloat32(index) + const positionX = toFixed(view.getFloat32(index)) index += 4 - const positionY = view.getFloat32(index) + const positionY = toFixed(view.getFloat32(index)) index += 4 - const directionX = view.getFloat32(index) + const directionX = toFixed(view.getFloat32(index)) index += 4 - const directionY = view.getFloat32(index) + const directionY = toFixed(view.getFloat32(index)) index += 4 const msg = { name: ApiMsgEnum.MsgClientSync, @@ -155,7 +155,7 @@ const decodeWeaponShoot = (view: DataView, index: number) => { } const decodeTimePast = (view: DataView, index: number) => { - const dt = view.getFloat32(index) + const dt = toFixed(view.getFloat32(index)) index += 4 const msg = { name: ApiMsgEnum.MsgClientSync, diff --git a/test.js b/test.js index 37ae539..5333ce5 100644 --- a/test.js +++ b/test.js @@ -1,4 +1,6 @@ const ab = new ArrayBuffer(10) const view = new DataView(ab) -view.setFloat32(0, 0.0023) -console.log(view); \ No newline at end of file +view.setFloat32(0, 0.0012) + + +console.log(view.getFloat32(0)); \ No newline at end of file