fix getfloat32

This commit is contained in:
sli97 2022-12-05 22:02:24 +08:00
parent eeaa7915de
commit 52539376b8
2 changed files with 13 additions and 11 deletions

View File

@ -1,5 +1,5 @@
import { ApiMsgEnum, InputTypeEnum } from "./Enum"; 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) => { const encodeActorMove = (proto: ApiMsgEnum, data: any, view: DataView, index: number) => {
view.setUint8(index++, data.type) view.setUint8(index++, data.type)
@ -103,11 +103,11 @@ export const binaryEncode = (proto: ApiMsgEnum, data: any): DataView => {
const decodeActorMove = (view: DataView, index: number) => { const decodeActorMove = (view: DataView, index: number) => {
const id = view.getUint8(index++) const id = view.getUint8(index++)
const directionX = view.getFloat32(index) const directionX = toFixed(view.getFloat32(index))
index += 4 index += 4
const directionY = view.getFloat32(index) const directionY = toFixed(view.getFloat32(index))
index += 4 index += 4
const dt = view.getFloat32(index) const dt = toFixed(view.getFloat32(index))
index += 4 index += 4
const msg = { const msg = {
name: ApiMsgEnum.MsgClientSync, name: ApiMsgEnum.MsgClientSync,
@ -127,13 +127,13 @@ const decodeActorMove = (view: DataView, index: number) => {
const decodeWeaponShoot = (view: DataView, index: number) => { const decodeWeaponShoot = (view: DataView, index: number) => {
const owner = view.getUint8(index++) const owner = view.getUint8(index++)
const positionX = view.getFloat32(index) const positionX = toFixed(view.getFloat32(index))
index += 4 index += 4
const positionY = view.getFloat32(index) const positionY = toFixed(view.getFloat32(index))
index += 4 index += 4
const directionX = view.getFloat32(index) const directionX = toFixed(view.getFloat32(index))
index += 4 index += 4
const directionY = view.getFloat32(index) const directionY = toFixed(view.getFloat32(index))
index += 4 index += 4
const msg = { const msg = {
name: ApiMsgEnum.MsgClientSync, name: ApiMsgEnum.MsgClientSync,
@ -155,7 +155,7 @@ const decodeWeaponShoot = (view: DataView, index: number) => {
} }
const decodeTimePast = (view: DataView, index: number) => { const decodeTimePast = (view: DataView, index: number) => {
const dt = view.getFloat32(index) const dt = toFixed(view.getFloat32(index))
index += 4 index += 4
const msg = { const msg = {
name: ApiMsgEnum.MsgClientSync, name: ApiMsgEnum.MsgClientSync,

View File

@ -1,4 +1,6 @@
const ab = new ArrayBuffer(10) const ab = new ArrayBuffer(10)
const view = new DataView(ab) const view = new DataView(ab)
view.setFloat32(0, 0.0023) view.setFloat32(0, 0.0012)
console.log(view);
console.log(view.getFloat32(0));