mirror of
https://codeberg.org/demostf/frontend.git
synced 2026-06-03 18:24:12 +02:00
render cart
This commit is contained in:
parent
c96f2e6b7b
commit
a4d835f0c6
9 changed files with 97 additions and 12 deletions
|
|
@ -1,5 +1,5 @@
|
|||
import {
|
||||
BuildingState,
|
||||
BuildingState, CartState,
|
||||
Event,
|
||||
Kill,
|
||||
ParsedDemo,
|
||||
|
|
@ -46,6 +46,7 @@ export class AsyncParser {
|
|||
cachedData.playerCount,
|
||||
cachedData.buildingCount,
|
||||
cachedData.projectileCount,
|
||||
cachedData.hasCart,
|
||||
cachedData.world,
|
||||
cachedData.header,
|
||||
cachedData.data,
|
||||
|
|
@ -93,6 +94,10 @@ export class AsyncParser {
|
|||
return projectiles;
|
||||
}
|
||||
|
||||
getCart(tick: number): CartState | null {
|
||||
return this.demo.getCart(tick);
|
||||
}
|
||||
|
||||
getKills(): Kill[] {
|
||||
return this.demo.kills
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ export async function parseDemo(bytes: Uint8Array, progressCallback: (progress:
|
|||
let playerCount = state.player_count;
|
||||
let buildingCount = state.building_count;
|
||||
let projectileCount = state.projectile_count;
|
||||
let hasCart = state.has_cart;
|
||||
let boundaries = state.boundaries;
|
||||
let interval_per_tick = state.interval_per_tick;
|
||||
let tickCount = state.tick_count;
|
||||
|
|
@ -76,6 +77,7 @@ export async function parseDemo(bytes: Uint8Array, progressCallback: (progress:
|
|||
playerCount,
|
||||
buildingCount,
|
||||
projectileCount,
|
||||
hasCart,
|
||||
{
|
||||
boundary_min: {
|
||||
x: boundaries.boundary_min.x,
|
||||
|
|
@ -191,6 +193,7 @@ export interface ProjectileState {
|
|||
angle: number,
|
||||
team: Team,
|
||||
projectileType: ProjectileType,
|
||||
critical: boolean,
|
||||
}
|
||||
|
||||
export interface Header {
|
||||
|
|
@ -206,6 +209,13 @@ export interface Kill {
|
|||
weapon: string,
|
||||
}
|
||||
|
||||
export interface CartState {
|
||||
position: {
|
||||
x: number,
|
||||
y: number
|
||||
},
|
||||
}
|
||||
|
||||
function unpack_f32(val: number, min: number, max: number): number {
|
||||
const ratio = val / (Math.pow(2, 16) - 1);
|
||||
return ratio * (max - min) + min;
|
||||
|
|
@ -220,6 +230,7 @@ export class ParsedDemo {
|
|||
public readonly playerCount: number;
|
||||
public readonly buildingCount: number;
|
||||
public readonly projectileCount: number;
|
||||
public readonly hasCart: boolean;
|
||||
public readonly world: WorldBoundaries;
|
||||
public readonly data: Uint8Array;
|
||||
public readonly header: Header;
|
||||
|
|
@ -232,6 +243,7 @@ export class ParsedDemo {
|
|||
playerCount: number,
|
||||
buildingCount: number,
|
||||
projectileCount: number,
|
||||
hasCart: boolean,
|
||||
world: WorldBoundaries,
|
||||
header: Header,
|
||||
data: Uint8Array,
|
||||
|
|
@ -243,6 +255,7 @@ export class ParsedDemo {
|
|||
this.playerCount = playerCount;
|
||||
this.buildingCount = buildingCount;
|
||||
this.projectileCount = projectileCount;
|
||||
this.hasCart = hasCart;
|
||||
this.world = world;
|
||||
this.header = header;
|
||||
this.data = data;
|
||||
|
|
@ -280,11 +293,24 @@ export class ParsedDemo {
|
|||
((projectileIndex * this.tickCount) + tick) * PROJECTILE_PACK_SIZE;
|
||||
return unpackProjectile(this.data, base, this.world);
|
||||
}
|
||||
|
||||
getCart(tick: number): CartState | null {
|
||||
if (this.hasCart) {
|
||||
const base = (this.playerCount * this.tickCount * PLAYER_PACK_SIZE) +
|
||||
(this.buildingCount * this.tickCount * BUILDING_PACK_SIZE) +
|
||||
(this.projectileCount * this.tickCount * PROJECTILE_PACK_SIZE) +
|
||||
(tick * CART_PACK_SIZE);
|
||||
return unpackCart(this.data, base, this.world);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const PLAYER_PACK_SIZE = 8;
|
||||
const BUILDING_PACK_SIZE = 7;
|
||||
const PROJECTILE_PACK_SIZE = 6;
|
||||
const CART_PACK_SIZE = 4;
|
||||
|
||||
function unpackPlayer(bytes: Uint8Array, base: number, world: WorldBoundaries, info: PlayerInfo): PlayerState {
|
||||
const x = unpack_f32(bytes[base] + (bytes[base + 1] << 8), world.boundary_min.x, world.boundary_max.x);
|
||||
|
|
@ -335,13 +361,24 @@ function unpackProjectile(bytes: Uint8Array, base: number, world: WorldBoundarie
|
|||
const team_type = bytes[base + 4];
|
||||
const team = (((team_type >> 4) & 1) === 0) ? Team.Blue : Team.Red;
|
||||
const projectileType = ((team_type >> 5) & 7) as ProjectileType;
|
||||
const angle = unpack_angle(bytes[base + 5]);
|
||||
const critical = bytes[base + 5] >> 7 == 1;
|
||||
const angle = unpack_angle(bytes[base + 5] >> 1);
|
||||
|
||||
return {
|
||||
position: {x, y},
|
||||
angle,
|
||||
team,
|
||||
projectileType,
|
||||
critical,
|
||||
}
|
||||
}
|
||||
|
||||
function unpackCart(bytes: Uint8Array, base: number, world: WorldBoundaries): CartState {
|
||||
const x = unpack_f32(bytes[base] + (bytes[base + 1] << 8), world.boundary_min.x, world.boundary_max.x);
|
||||
const y = unpack_f32(bytes[base + 2] + (bytes[base + 3] << 8), world.boundary_min.y, world.boundary_max.y);
|
||||
|
||||
return {
|
||||
position: {x, y},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue