import {expect, test} from 'vitest'; import {RESOLUTION} from '@/constants.js' import Server from '@/net/server/server.js'; import Engine from './engine.js'; test('visibility-based updates', async () => { const engine = new Engine(Server); const ecs = engine.ecses[1]; // Create an entity. const entity = ecs.get(ecs.create({ Momentum: {x: 1, y: 0}, Position: {x: (RESOLUTION.x * 1.5) + 32 - 3, y: 20}, VisibleAabb: {}, })); // Connect an entity. await engine.connectPlayer(undefined); // Tick and get update. Should be a full update. engine.tick(1); expect(engine.updateFor(undefined)) .to.deep.equal({2: ecs.get(2).toJSON(), 3: {MainEntity: {}, ...ecs.get(3).toJSON()}}); // Tick and get update. Should be a partial update. engine.tick(1); expect(engine.updateFor(undefined)) .to.deep.equal({ 2: { Position: {x: (RESOLUTION.x * 1.5) + 32 - 1}, VisibleAabb: { x0: 1199, x1: 1263, }, }, }); // Tick and get update. Should remove the entity. engine.tick(1); expect(engine.updateFor(undefined)) .to.deep.equal({2: false}); // Aim back toward visible area and tick. Should be a full update for that entity. entity.Momentum.x = -1; engine.tick(1); expect(engine.updateFor(undefined)) .to.deep.equal({2: ecs.get(2).toJSON()}); });