1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2025-01-13 06:29:57 +00:00

ecs: const values

This commit is contained in:
Steven Hugg 2022-01-27 13:48:45 -06:00
parent 47461b5a28
commit c022c16dc2

View File

@ -481,8 +481,17 @@ export class EntityScope {
// see if all entities have the same constant value // see if all entities have the same constant value
let constValues = new Set(); let constValues = new Set();
for (let e of entities) { for (let e of entities) {
let constVal = e.consts[fieldName]; let constVal = e.consts[mksymbol(component, fieldName)];
if (constVal) constValues.add(constVal); constValues.add(constVal); // constVal === undefined is allowed
}
// is it a constant?
if (constValues.size == 1) {
let value = constValues.values().next().value;
if (value !== undefined) {
if (bitofs == 0) return `#<${value}`;
if (bitofs == 8) return `#>${value}`;
// TODO: bitofs?
}
} }
// TODO: offset > 0? // TODO: offset > 0?
//let range = this.bss.getFieldRange(component, fieldName); //let range = this.bss.getFieldRange(component, fieldName);
@ -711,7 +720,7 @@ const TEMPLATE3_D = `
const TEMPLATE4_S = ` const TEMPLATE4_S = `
.macro %{@KernelSetup} ent,ofs .macro %{@KernelSetup} ent,ofs
lda #192 lda #192 ; TODO: numlines
sec sec
sbc ypos_ypos_b0+ent sbc ypos_ypos_b0+ent
sta %{$5}+ofs sta %{$5}+ofs
@ -748,7 +757,8 @@ const TEMPLATE4_S = `
// https://atariage.com/forums/topic/129683-advice-on-a-masking-kernel/ // https://atariage.com/forums/topic/129683-advice-on-a-masking-kernel/
// https://atariage.com/forums/topic/128147-having-trouble-with-2-free-floating-player-graphics/?tab=comments#comment-1547059 // https://atariage.com/forums/topic/128147-having-trouble-with-2-free-floating-player-graphics/?tab=comments#comment-1547059
const TEMPLATE4_K = ` const TEMPLATE4_K = `
ldy #192 ; lines in kernel lda %{<bgcolor}
ldy %{<lines}
@LVScan: @LVScan:
lda %{$4} ; height lda %{$4} ; height
dcp %{$5} dcp %{$5}
@ -978,6 +988,7 @@ function test() {
let scene = em.newScope("Scene", root); let scene = em.newScope("Scene", root);
let e_ekernel = root.newEntity({ components: [c_kernel] }); let e_ekernel = root.newEntity({ components: [c_kernel] });
root.setConstValue(e_ekernel, c_kernel, 'lines', 192); root.setConstValue(e_ekernel, c_kernel, 'lines', 192);
root.setConstValue(e_ekernel, c_kernel, 'bgcolor', 0x92);
let e_bitmap0 = root.newEntity({ components: [c_bitmap] }); let e_bitmap0 = root.newEntity({ components: [c_bitmap] });
// TODO: store array sizes? // TODO: store array sizes?