packet size improvements
- change structure resource packets - make more booleans default to false - use encode_string - massive decrease in packet size!!
This commit is contained in:
parent
523f6d5914
commit
085776d42b
14 changed files with 131 additions and 134 deletions
|
|
@ -40,8 +40,8 @@ export namespace KafkatorioPacketData {
|
|||
type: KafkatorioPacketData.Type.ConfigurationUpdate;
|
||||
factorioData: ConfigurationUpdateGameData;
|
||||
allMods: ConfigurationUpdateModData[];
|
||||
modStartupSettingsChange: boolean;
|
||||
migrationApplied: boolean;
|
||||
modStartupSettingsChange?: boolean;
|
||||
migrationApplied?: boolean;
|
||||
}
|
||||
|
||||
export interface ConsoleChatUpdate {
|
||||
|
|
@ -94,7 +94,8 @@ export namespace KafkatorioPacketData {
|
|||
type: KafkatorioPacketData.Type.MapChunkResourceUpdate;
|
||||
key: MapChunkResourceUpdateKey;
|
||||
events?: { [key: EventName]: Tick[] } | null;
|
||||
resourcesXY: FactorioEntityUpdateResourceDictionary;
|
||||
amounts?: FactorioEntityUpdateResourceAmountDictionary;
|
||||
initialAmounts?: FactorioEntityUpdateResourceAmountDictionary;
|
||||
}
|
||||
|
||||
export interface MapChunkTileUpdate {
|
||||
|
|
@ -132,7 +133,7 @@ export namespace KafkatorioPacketData {
|
|||
bannedReason?: string | null;
|
||||
kickedReason?: string | null;
|
||||
disconnectReason?: string | null;
|
||||
isRemoved?: boolean | null;
|
||||
isRemoved?: boolean;
|
||||
}
|
||||
|
||||
export interface Error {
|
||||
|
|
@ -171,7 +172,7 @@ export interface MapChunkEntityUpdateKey {
|
|||
chunkPosition: MapChunkPosition;
|
||||
}
|
||||
|
||||
export type FactorioEntityUpdateEntityDictionary = { [key: string]: { [key: string]: FactorioEntityUpdateEntity } };
|
||||
export type FactorioEntityUpdateEntityDictionary = { [key: string]: { [key: string]: FactorioEntityUpdateElementStandard } };
|
||||
|
||||
export interface MapChunkResourceUpdateKey {
|
||||
protoId: PrototypeId;
|
||||
|
|
@ -179,7 +180,7 @@ export interface MapChunkResourceUpdateKey {
|
|||
chunkPosition: MapChunkPosition;
|
||||
}
|
||||
|
||||
export type FactorioEntityUpdateResourceDictionary = { [key: string]: { [key: string]: FactorioEntityUpdateResource } };
|
||||
export type FactorioEntityUpdateResourceAmountDictionary = { [key: string]: { [key: string]: UInt } };
|
||||
|
||||
export interface MapChunkTileUpdateKey {
|
||||
chunkPosition: MapChunkPosition;
|
||||
|
|
@ -251,7 +252,7 @@ export namespace FactorioPrototype {
|
|||
layer: UInt;
|
||||
collisionMasks: string[];
|
||||
order: string;
|
||||
canBeMined: boolean;
|
||||
canBeMined?: boolean;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -274,7 +275,7 @@ export interface EntityItemGroup {
|
|||
}
|
||||
|
||||
export interface EntityMiningProperties {
|
||||
canBeMined: boolean;
|
||||
canBeMined?: boolean;
|
||||
products: MinedProduct[] | null;
|
||||
}
|
||||
|
||||
|
|
@ -293,21 +294,16 @@ export enum ChunkSize {
|
|||
|
||||
export type PrototypeKey = Int & { __PrototypeKey__: void };
|
||||
|
||||
export interface FactorioEntityUpdateEntity {
|
||||
export interface FactorioEntityUpdateElementStandard {
|
||||
status?: FactorioEntityStatus | null;
|
||||
unitNumber?: UnitNumber | null;
|
||||
graphicsVariation?: UByte | null;
|
||||
health?: Float | null;
|
||||
isActive?: boolean | null;
|
||||
isRotatable?: boolean | null;
|
||||
isActive?: boolean;
|
||||
isRotatable?: boolean;
|
||||
lastUser?: UInt | null;
|
||||
}
|
||||
|
||||
export interface FactorioEntityUpdateResource {
|
||||
amount: UInt;
|
||||
initialAmount?: UInt | null;
|
||||
}
|
||||
|
||||
export type MinedProduct =
|
||||
| MinedProduct.MinedProductFluid
|
||||
| MinedProduct.MinedProductItem;
|
||||
|
|
|
|||
|
|
@ -26,8 +26,10 @@ export class KafkatorioPacketEmitter {
|
|||
|
||||
/** Emit a serialised KafkatorioPacket */
|
||||
private static emitPacket<T extends KafkatorioPacket>(packet: T) {
|
||||
let data = game.table_to_json(packet)
|
||||
localised_print(`KafkatorioPacket: ${data}`)
|
||||
const data = game.table_to_json(packet)
|
||||
// print(`KafkatorioPacket::: ${data}`)
|
||||
const encoded = game.encode_string(data)
|
||||
print(`KafkatorioPacket encoded::: ${encoded}`)
|
||||
// rcon.print(`KafkatorioPacket: ${data}`)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import {
|
|||
EntityMiningProperties,
|
||||
EventName,
|
||||
FactorioEntityStatus,
|
||||
FactorioEntityUpdateResource,
|
||||
KafkatorioPacketData,
|
||||
MapBoundingBox,
|
||||
MapChunkPosition,
|
||||
|
|
@ -76,20 +75,6 @@ export namespace Converters {
|
|||
}
|
||||
|
||||
|
||||
export function convertResourceEntity(
|
||||
entity: LuaEntity
|
||||
): FactorioEntityUpdateResource | null {
|
||||
if (entity.type != "resource") {
|
||||
return null
|
||||
} else {
|
||||
return {
|
||||
amount: entity.amount,
|
||||
initialAmount: entity.initial_amount,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function convertEntityStatus(
|
||||
status: defines.entity_status | undefined
|
||||
): FactorioEntityStatus | null {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import {
|
||||
EventName,
|
||||
FactorioEntityUpdateEntity,
|
||||
FactorioEntityUpdateElementStandard,
|
||||
KafkatorioPacketData,
|
||||
MapChunkPosition,
|
||||
PrototypeId,
|
||||
|
|
@ -94,7 +94,7 @@ export class EntityUpdatesHandler {
|
|||
chunkPosition: Converters.mapPositionToChunkPosition(entity.position)
|
||||
}
|
||||
|
||||
const entityUpdate: FactorioEntityUpdateEntity = {
|
||||
const entityUpdate: FactorioEntityUpdateElementStandard = {
|
||||
unitNumber: entity.unit_number,
|
||||
graphicsVariation: entity.graphics_variation,
|
||||
health: entity.health,
|
||||
|
|
@ -140,7 +140,7 @@ export class EntityUpdatesHandler {
|
|||
|
||||
for (const [protoId, resourceEntities] of pairs(entitiesByProtoId)) {
|
||||
|
||||
// create an update for each prototype ID
|
||||
// create a MapChunkResourceUpdate for each prototype ID
|
||||
|
||||
const entityUpdateKey: KafkatorioPacketData.MapChunkResourceUpdate["key"] = {
|
||||
protoId: protoId,
|
||||
|
|
@ -158,18 +158,20 @@ export class EntityUpdatesHandler {
|
|||
data.events[eventName].push(eventTick)
|
||||
|
||||
for (const entity of resourceEntities) {
|
||||
const resourceUpdate = Converters.convertResourceEntity(entity)
|
||||
|
||||
if (resourceUpdate != null) {
|
||||
data.resourcesXY ??= {}
|
||||
data.resourcesXY[`${entity.position.x}`] ??= {}
|
||||
data.resourcesXY[`${entity.position.x}`][`${entity.position.y}`] = resourceUpdate
|
||||
data.amounts ??= {}
|
||||
data.amounts[`${entity.position.x}`] ??= {}
|
||||
data.amounts[`${entity.position.x}`][`${entity.position.y}`] = entity.amount
|
||||
|
||||
if (entity.initial_amount != null) {
|
||||
data.initialAmounts ??= {}
|
||||
data.initialAmounts[`${entity.position.x}`] ??= {}
|
||||
data.initialAmounts[`${entity.position.x}`][`${entity.position.y}`] = entity.initial_amount
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue