mirror of
https://github.com/sehugg/8bitworkshop.git
synced 2025-02-19 23:29:06 +00:00
ecs: default values work now
This commit is contained in:
parent
614fdf92f7
commit
a965bc83d1
@ -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,15 +1195,16 @@ 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// TODO: cull unused entity fields
|
// TODO: cull unused entity fields
|
||||||
allocateSegment(segment: DataSegment, alloc: boolean, type: 'init' | 'const' | undefined) {
|
allocateSegment(segment: DataSegment, alloc: boolean, type: 'init' | 'const' | undefined) {
|
||||||
let fields: FieldArray[] = Object.values(segment.fieldranges);
|
let fields: FieldArray[] = Object.values(segment.fieldranges);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user