1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-06-17 19:29:44 +00:00

ecs: default values work now

This commit is contained in:
Steven Hugg 2022-02-24 14:02:18 -06:00
parent 614fdf92f7
commit a965bc83d1

View File

@ -1181,8 +1181,9 @@ export class EntityScope implements SourceLocated {
// constants and array pointers go into rodata // constants and array pointers go into rodata
let cfname = mksymbol(c, f.name); let cfname = mksymbol(c, f.name);
let ftype = this.fieldtypes[cfname]; let ftype = this.fieldtypes[cfname];
let segment = ftype == 'const' ? this.rodata : this.bss; let isConst = ftype == 'const';
if (v === undefined && ftype == 'const') let segment = isConst ? this.rodata : this.bss;
if (v === undefined && isConst)
throw new ECSError(`no value for const field ${cfname}`, e); throw new ECSError(`no value for const field ${cfname}`, e);
// determine range of indices for entities // determine range of indices for entities
let array = segment.fieldranges[cfname]; let array = segment.fieldranges[cfname];
@ -1194,11 +1195,12 @@ export class EntityScope implements SourceLocated {
throw new ECSError(`too many entities have field ${cfname}, limit is 256`); throw new ECSError(`too many entities have field ${cfname}, limit is 256`);
} }
// set default values for entity/field // set default values for entity/field
if (ftype == 'init') { if (!isConst) {
if (f.dtype == 'int' && f.defvalue !== undefined) { if (f.dtype == 'int' && f.defvalue !== undefined) {
let ecfname = mkscopesymbol(this, c, f.name); let ecfname = mkscopesymbol(this, c, f.name);
if (e.inits[ecfname] == null) if (e.inits[ecfname] == null) {
this.setInitValue(e, c, f, f.defvalue); this.setInitValue(e, c, f, f.defvalue);
}
} }
} }
} }