Skip to content

Commit

Permalink
fix(engine): More info between pack steps, retain same PackFile refer…
Browse files Browse the repository at this point in the history
…ence

::reload also had a double-message broadcast
(no one should have to manually reload anyways)
  • Loading branch information
Pazaz committed Nov 22, 2024
1 parent ef49eaa commit c44dddd
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 60 deletions.
8 changes: 8 additions & 0 deletions src/lostcity/engine/World.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,14 @@ class World {
this.broadcastMes(msg.error.replaceAll('data/src/scripts/', ''));
this.broadcastMes('Check the console for more information.');
}
} else if (msg.type === 'dev_progress') {
if (msg.broadcast) {
console.log(msg.broadcast);

this.broadcastMes(msg.broadcast);
} else if (msg.text) {
console.log(msg.text);
}
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ export default class ClientCheatHandler extends MessageHandler<ClientCheat> {
// developer commands
if (cmd === 'reload' && !Environment.STANDALONE_BUNDLE && !Environment.NODE_PRODUCTION) {
World.reload();

// todo: we're probably reloading twice now, just to get count?
const count = ScriptProvider.load('data/pack');
player.messageGame(`Reloaded ${count} scripts.`);
} else if (cmd === 'rebuild' && !Environment.STANDALONE_BUNDLE && !Environment.NODE_PRODUCTION) {
player.messageGame('Rebuilding scripts...');

Expand Down
2 changes: 1 addition & 1 deletion src/lostcity/pack/interface/PackShared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export function packInterface(server: boolean) {
comName = line.substring(1, line.length - 1);
comId = InterfacePack.getByName(`${ifName}:${comName}`);
if (comId === -1 || typeof component[comId] === 'undefined') {
throw new Error(`Missing component ID ${ifName}:${comName} in data/src/pack/interface.pack`);
throw new Error(`Missing component ID ${ifName}:${comName} in data/src/pack/interface.order`);
}

component[comId].root = ifName;
Expand Down
36 changes: 36 additions & 0 deletions src/lostcity/pack/packall.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import fs from 'fs';
import child_process from 'child_process';
import { parentPort } from 'worker_threads';

import { packServerInterface } from '#lostcity/pack/interface/PackServer.js';
import { packServerMap } from '#lostcity/pack/map/PackServer.js';
Expand All @@ -25,6 +26,13 @@ export async function packServer() {
throw new Error('The RuneScript compiler is missing and the build process cannot continue.');
}

if (parentPort) {
parentPort.postMessage({
type: 'dev_progress',
broadcast: 'Packing server cache (1/2)'
});
}

revalidatePack();
packConfigs();
packServerInterface();
Expand All @@ -34,16 +42,37 @@ export async function packServer() {

generateServerSymbols();

if (parentPort) {
parentPort.postMessage({
type: 'dev_progress',
text: 'Compiling server scripts'
});
}

try {
child_process.execSync(`"${Environment.BUILD_JAVA_PATH}" -jar RuneScriptCompiler.jar`, { stdio: 'inherit' });
} catch (err) {
throw new Error('Failed to compile scripts.');
}

if (parentPort) {
parentPort.postMessage({
type: 'dev_progress',
text: 'Packed server cache (1/2)'
});
}

fs.writeFileSync('data/pack/server/lastbuild.pack', '');
}

export async function packClient() {
if (parentPort) {
parentPort.postMessage({
type: 'dev_progress',
broadcast: 'Packing client cache (2/2)'
});
}

await packClientTitle();
packConfigs();
packClientInterface();
Expand All @@ -56,6 +85,13 @@ export async function packClient() {
packClientMap();
packClientMusic();

if (parentPort) {
parentPort.postMessage({
type: 'dev_progress',
text: 'Packed client cache (2/2)'
});
}

fs.writeFileSync('data/pack/client/crc', CrcBuffer.data);
fs.writeFileSync('data/pack/client/lastbuild.pack', '');
}
117 changes: 62 additions & 55 deletions src/lostcity/util/PackFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ type PackFileValidator = (packfile: PackFile, ...args: any[]) => void;

export class PackFile {
type: string;
validator: PackFileValidator | null = null;
validatorArgs: any[] = [];
pack: Map<number, string> = new Map();
names: Set<string> = new Set();
max: number = 0;
Expand All @@ -20,11 +22,16 @@ export class PackFile {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
constructor(type: string, validator: PackFileValidator | null = null, ...validatorArgs: any[]) {
this.type = type;
this.validator = validator;
this.validatorArgs = validatorArgs;
this.reload();
}

if (validator !== null) {
validator(this, ...validatorArgs);
reload() {
if (this.validator !== null) {
this.validator(this, ...this.validatorArgs);
} else {
this.load(`${Environment.BUILD_SRC_DIR}/pack/${type}.pack`);
this.load(`${Environment.BUILD_SRC_DIR}/pack/${this.type}.pack`);
}
}

Expand Down Expand Up @@ -254,60 +261,60 @@ function regenScriptPack(pack: PackFile) {
pack.save();
}

export let AnimPack = new PackFile('anim', validateFilesPack, `${Environment.BUILD_SRC_DIR}/models`, '.frame');
export let BasePack = new PackFile('base', validateFilesPack, `${Environment.BUILD_SRC_DIR}/models`, '.base');
export let CategoryPack = new PackFile('category', validateCategoryPack);
export let DbRowPack = new PackFile('dbrow', validateConfigPack, '.dbrow', true, false, false, true);
export let DbTablePack = new PackFile('dbtable', validateConfigPack, '.dbtable', true, false, false, true);
export let EnumPack = new PackFile('enum', validateConfigPack, '.enum', true, false, false, true);
export let FloPack = new PackFile('flo', validateConfigPack, '.flo');
export let HuntPack = new PackFile('hunt', validateConfigPack, '.hunt', true, false, false, true);
export let IdkPack = new PackFile('idk', validateConfigPack, '.idk');
export let InterfacePack = new PackFile('interface', validateInterfacePack);
export let InvPack = new PackFile('inv', validateConfigPack, '.inv', true);
export let LocPack = new PackFile('loc', validateConfigPack, '.loc');
export let MesAnimPack = new PackFile('mesanim', validateConfigPack, '.mesanim', true, false, false, true);
export let ModelPack = new PackFile('model', validateFilesPack, `${Environment.BUILD_SRC_DIR}/models`, '.ob2');
export let NpcPack = new PackFile('npc', validateConfigPack, '.npc');
export let ObjPack = new PackFile('obj', validateConfigPack, '.obj');
export let ParamPack = new PackFile('param', validateConfigPack, '.param', true, false, false, true);
export let ScriptPack = new PackFile('script', regenScriptPack);
export let SeqPack = new PackFile('seq', validateConfigPack, '.seq');
export let SoundPack = new PackFile('sound', validateFilesPack, `${Environment.BUILD_SRC_DIR}/sounds`, '.synth');
export let SpotAnimPack = new PackFile('spotanim', validateConfigPack, '.spotanim');
export let StructPack = new PackFile('struct', validateConfigPack, '.struct', true, false, false, true);
export let TexturePack = new PackFile('texture', validateImagePack, `${Environment.BUILD_SRC_DIR}/textures`, '.png');
export let VarpPack = new PackFile('varp', validateConfigPack, '.varp', true);
export let VarnPack = new PackFile('varn', validateConfigPack, '.varn', true, false, false, true);
export let VarsPack = new PackFile('vars', validateConfigPack, '.vars', true, false, false, true);
export const AnimPack = new PackFile('anim', validateFilesPack, `${Environment.BUILD_SRC_DIR}/models`, '.frame');
export const BasePack = new PackFile('base', validateFilesPack, `${Environment.BUILD_SRC_DIR}/models`, '.base');
export const CategoryPack = new PackFile('category', validateCategoryPack);
export const DbRowPack = new PackFile('dbrow', validateConfigPack, '.dbrow', true, false, false, true);
export const DbTablePack = new PackFile('dbtable', validateConfigPack, '.dbtable', true, false, false, true);
export const EnumPack = new PackFile('enum', validateConfigPack, '.enum', true, false, false, true);
export const FloPack = new PackFile('flo', validateConfigPack, '.flo');
export const HuntPack = new PackFile('hunt', validateConfigPack, '.hunt', true, false, false, true);
export const IdkPack = new PackFile('idk', validateConfigPack, '.idk');
export const InterfacePack = new PackFile('interface', validateInterfacePack);
export const InvPack = new PackFile('inv', validateConfigPack, '.inv', true);
export const LocPack = new PackFile('loc', validateConfigPack, '.loc');
export const MesAnimPack = new PackFile('mesanim', validateConfigPack, '.mesanim', true, false, false, true);
export const ModelPack = new PackFile('model', validateFilesPack, `${Environment.BUILD_SRC_DIR}/models`, '.ob2');
export const NpcPack = new PackFile('npc', validateConfigPack, '.npc');
export const ObjPack = new PackFile('obj', validateConfigPack, '.obj');
export const ParamPack = new PackFile('param', validateConfigPack, '.param', true, false, false, true);
export const ScriptPack = new PackFile('script', regenScriptPack);
export const SeqPack = new PackFile('seq', validateConfigPack, '.seq');
export const SoundPack = new PackFile('sound', validateFilesPack, `${Environment.BUILD_SRC_DIR}/sounds`, '.synth');
export const SpotAnimPack = new PackFile('spotanim', validateConfigPack, '.spotanim');
export const StructPack = new PackFile('struct', validateConfigPack, '.struct', true, false, false, true);
export const TexturePack = new PackFile('texture', validateImagePack, `${Environment.BUILD_SRC_DIR}/textures`, '.png');
export const VarpPack = new PackFile('varp', validateConfigPack, '.varp', true);
export const VarnPack = new PackFile('varn', validateConfigPack, '.varn', true, false, false, true);
export const VarsPack = new PackFile('vars', validateConfigPack, '.vars', true, false, false, true);

export function revalidatePack() {
AnimPack = new PackFile('anim', validateFilesPack, `${Environment.BUILD_SRC_DIR}/models`, '.frame');
BasePack = new PackFile('base', validateFilesPack, `${Environment.BUILD_SRC_DIR}/models`, '.base');
CategoryPack = new PackFile('category', validateCategoryPack);
DbRowPack = new PackFile('dbrow', validateConfigPack, '.dbrow', true, false, false, true);
DbTablePack = new PackFile('dbtable', validateConfigPack, '.dbtable', true, false, false, true);
EnumPack = new PackFile('enum', validateConfigPack, '.enum', true, false, false, true);
FloPack = new PackFile('flo', validateConfigPack, '.flo');
HuntPack = new PackFile('hunt', validateConfigPack, '.hunt', true, false, false, true);
IdkPack = new PackFile('idk', validateConfigPack, '.idk');
InterfacePack = new PackFile('interface', validateInterfacePack);
InvPack = new PackFile('inv', validateConfigPack, '.inv', true);
LocPack = new PackFile('loc', validateConfigPack, '.loc');
MesAnimPack = new PackFile('mesanim', validateConfigPack, '.mesanim', true, false, false, true);
ModelPack = new PackFile('model', validateFilesPack, `${Environment.BUILD_SRC_DIR}/models`, '.ob2');
NpcPack = new PackFile('npc', validateConfigPack, '.npc');
ObjPack = new PackFile('obj', validateConfigPack, '.obj');
ParamPack = new PackFile('param', validateConfigPack, '.param', true, false, false, true);
ScriptPack = new PackFile('script', regenScriptPack);
SeqPack = new PackFile('seq', validateConfigPack, '.seq');
SoundPack = new PackFile('sound', validateFilesPack, `${Environment.BUILD_SRC_DIR}/sounds`, '.synth');
SpotAnimPack = new PackFile('spotanim', validateConfigPack, '.spotanim');
StructPack = new PackFile('struct', validateConfigPack, '.struct', true, false, false, true);
TexturePack = new PackFile('texture', validateImagePack, `${Environment.BUILD_SRC_DIR}/textures`, '.png');
VarpPack = new PackFile('varp', validateConfigPack, '.varp', true);
VarnPack = new PackFile('varn', validateConfigPack, '.varn', true, false, false, true);
VarsPack = new PackFile('vars', validateConfigPack, '.vars', true, false, false, true);
AnimPack.reload();
BasePack.reload();
CategoryPack.reload();
DbRowPack.reload();
DbTablePack.reload();
EnumPack.reload();
FloPack.reload();
HuntPack.reload();
IdkPack.reload();
InterfacePack.reload();
InvPack.reload();
LocPack.reload();
MesAnimPack.reload();
ModelPack.reload();
NpcPack.reload();
ObjPack.reload();
ParamPack.reload();
ScriptPack.reload();
SeqPack.reload();
SoundPack.reload();
SpotAnimPack.reload();
StructPack.reload();
TexturePack.reload();
VarpPack.reload();
VarnPack.reload();
VarsPack.reload();
}

export function crawlConfigNames(ext: string, includeBrackets = false) {
Expand Down

0 comments on commit c44dddd

Please sign in to comment.