- wicked sick size optimisation of map-tiles update packet

- fix ts-generator recursive value class unwrapping
- move kafka state dir
- try fixing kafka streams for tile generation (simplifying it, and fixing some nullability problems)
This commit is contained in:
Adam 2022-03-02 18:38:51 +01:00
parent c5d4ae8d63
commit b055397d25
14 changed files with 253 additions and 118 deletions

View file

@ -15,7 +15,7 @@ interface FactorioPrototypes extends KafkatorioPacket {
interface MapTilePrototype extends FactorioPrototype {
canBeMined: boolean;
collisionMasks: string[];
layer: int;
layer: uint;
mapColour: Colour;
name: string;
order: string;

View file

@ -59,3 +59,8 @@ interface EntityIdentifiers {
type: string;
unitNumber: uint | null;
}
interface MapTileDictionary {
protos: { [key: string]: string };
tilesXY: { [key: string]: { [key: string]: string } };
}

View file

@ -7,7 +7,7 @@ interface FactorioEventUpdateKey {
}
interface FactorioEventUpdate extends FactorioEventUpdateKey {
eventCounts: { [key: string]: int } | null;
eventCounts: { [key: string]: uint } | null;
updateType: FactorioEventUpdateType;
}
@ -30,7 +30,7 @@ interface PlayerUpdate extends FactorioEventUpdate, PlayerUpdateKey {
colour: Colour | null;
diedCause: EntityIdentifiers | null;
disconnectReason: string | null;
eventCounts: { [key: string]: int } | null;
eventCounts: { [key: string]: uint } | null;
forceIndex: uint | null;
index: uint;
isAdmin: boolean | null;
@ -57,12 +57,12 @@ interface EntityUpdateKey extends EntityIdentifiers, FactorioEventUpdateKey {
interface EntityUpdate extends FactorioEventUpdate, EntityIdentifiers, EntityUpdateKey {
chunkPosition: MapChunkPosition | null;
eventCounts: { [key: string]: int } | null;
graphicsVariation: number | null;
eventCounts: { [key: string]: uint } | null;
graphicsVariation: uint8 | null;
health: float | null;
isActive: boolean | null;
isRotatable: boolean | null;
lastUser: int | null;
lastUser: uint | null;
localisedDescription: string | null;
localisedName: string | null;
name: string;
@ -79,12 +79,12 @@ interface MapChunkUpdateKey extends FactorioEventUpdateKey {
interface MapChunkUpdate extends FactorioEventUpdate, MapChunkUpdateKey {
chunkPosition: MapChunkPosition;
eventCounts: { [key: string]: int } | null;
eventCounts: { [key: string]: uint } | null;
force: uint | null;
isDeleted: boolean | null;
player: uint | null;
robot: EntityIdentifiers | null;
surfaceIndex: uint;
tiles: MapTile[] | null;
tileDictionary: MapTileDictionary | null;
updateType: FactorioEventUpdateType;
}

View file

@ -20,7 +20,7 @@ export namespace EventDataCache {
log("Initialising global.DEFAULT_CACHE_DURATION_TICKS")
global.defaultCacheDurationTicks = {
"PLAYER": 60, // 1 second
"PLAYER": 15, // 0.25 seconds
"MAP_CHUNK": 60 * 30, // 30 seconds
"ENTITY": 60 * 2, // 2 seconds
"default": 60 * 5, // 5 seconds

View file

@ -8,6 +8,17 @@ import CacheData = EventDataCache.CacheData;
type MapChunkUpdater = (data: CacheData<"MAP_CHUNK">) => void
const mapProtoNameToKey: { [key: string]: string } = {}
let protoIndex: uint = 0
function getProtoKey(protoName: string): string {
if (mapProtoNameToKey[protoName] == undefined) {
mapProtoNameToKey[protoName] = `${protoIndex++}`
}
return mapProtoNameToKey[protoName]
}
function mapTilesUpdateDebounce(
surface: LuaSurface | undefined,
chunkPosition: ChunkPositionTable,
@ -27,24 +38,26 @@ function mapTilesUpdateDebounce(
updateType: "MAP_CHUNK",
},
data => {
if (data.tiles == undefined) {
data.tiles = []
data.tileDictionary ??= <MapTileDictionary>{
tilesXY: {},
protos: {},
}
for (const tile of tiles) {
data.tiles.push(
{
x: tile.position.x,
y: tile.position.y,
proto: tile.name,
}
)
for (let tile of tiles) {
const xString = `${tile.position.x}`
const yString = `${tile.position.y}`
const protoKey = getProtoKey(tile.name)
data.tileDictionary.protos[protoKey] = tile.name
data.tileDictionary.tilesXY[xString] ??= {}
data.tileDictionary.tilesXY[xString][yString] = protoKey
}
if (data.eventCounts == undefined) {
data.eventCounts = {}
}
data.eventCounts[eventName] = ((data.eventCounts ?? {}) [eventName] ?? 0) + 1
data.eventCounts ??= {}
data.eventCounts[eventName] ??= 0
data.eventCounts[eventName]++
if (updater != undefined) {
updater(data)