slight intermediary optimization
This commit is contained in:
parent
c3756c4bd9
commit
26b7ed1310
3 changed files with 92 additions and 62 deletions
|
|
@ -104,14 +104,17 @@ pub const Activity = struct {
|
|||
|
||||
for (self.soundnode.wire_in.items, 0..) |wired_sn, i| {
|
||||
|
||||
if (wired_sn.active == 1) {
|
||||
const relayed_r_amp = wired_sn.fab.get_r_amp(current_tick);
|
||||
self.soundnode.fab.add_r_amp(relayed_r_amp);
|
||||
}
|
||||
_ = i;
|
||||
|
||||
}
|
||||
|
||||
for (self.soundnode.air_in.items, 0..) |aired_sn, i| {
|
||||
|
||||
if (aired_sn.active == 1) {
|
||||
const dist: f64 = self.soundnode.distance(aired_sn);
|
||||
|
||||
var b_sample_tick: u32 = 0;
|
||||
|
|
@ -135,7 +138,7 @@ pub const Activity = struct {
|
|||
self.soundnode.fab.add_r_amp(relayed_r_amp);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
_ = i;
|
||||
|
||||
}
|
||||
|
|
@ -439,14 +442,18 @@ pub const Activity = struct {
|
|||
|
||||
for (self.soundnode.wire_in.items, 0..) |wired_sn, i| {
|
||||
|
||||
if (wired_sn.active == 1) {
|
||||
const relayed_r_amp = wired_sn.fab.get_r_amp(current_tick);
|
||||
srcamp += relayed_r_amp;
|
||||
}
|
||||
_ = i;
|
||||
|
||||
}
|
||||
|
||||
for (self.soundnode.air_in.items, 0..) |aired_sn, i| {
|
||||
|
||||
if (aired_sn.active == 1) {
|
||||
|
||||
const dist: f64 = self.soundnode.distance(aired_sn);
|
||||
|
||||
var b_sample_tick: u32 = 0;
|
||||
|
|
@ -470,7 +477,7 @@ pub const Activity = struct {
|
|||
srcamp += relayed_r_amp;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
_ = i;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -175,6 +175,7 @@ pub fn main() !void {
|
|||
//print("Wired nodes at tick {d}\n", .{tick});
|
||||
|
||||
try trg.wire_in.append(src);
|
||||
try src.wire_targets.append(trg);
|
||||
},
|
||||
|
||||
2 => {
|
||||
|
|
@ -183,6 +184,7 @@ pub fn main() !void {
|
|||
|
||||
//print("Aired nodes at tick {d}\n", .{tick});
|
||||
try trg.air_in.append(src);
|
||||
try src.air_targets.append(trg);
|
||||
},
|
||||
|
||||
3 => {
|
||||
|
|
@ -204,6 +206,10 @@ pub fn main() !void {
|
|||
//print("Set activity {d} for node {d} s at tick {d}\n", .{opcode, src_node, tick});
|
||||
try src.activities.append(a);
|
||||
|
||||
if (src.activities.items.len == 1) {
|
||||
src.active = 1;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
}
|
||||
|
|
@ -218,6 +224,8 @@ pub fn main() !void {
|
|||
|
||||
for (soundnodes.items[2..], 0..) |soundnode, i| {
|
||||
|
||||
if (soundnode.active == 1) {
|
||||
|
||||
var toremove = ArrayList(usize).init(allocator);
|
||||
defer toremove.deinit();
|
||||
|
||||
|
|
@ -236,6 +244,11 @@ pub fn main() !void {
|
|||
j -= 1;
|
||||
const activity_ind = toremove.items[j];
|
||||
_ = soundnode.activities.swapRemove(activity_ind);
|
||||
if (soundnode.activities.items.len == 0) {
|
||||
soundnode.active = 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
soundnode.fab.increment_tick();
|
||||
|
|
|
|||
|
|
@ -26,6 +26,10 @@ pub const SoundNode = struct {
|
|||
|
||||
air_in: ArrayList(*SoundNode),
|
||||
wire_in: ArrayList(*SoundNode),
|
||||
|
||||
air_targets: ArrayList(*SoundNode),
|
||||
wire_targets: ArrayList(*SoundNode),
|
||||
|
||||
activities: ArrayList(*Activity),
|
||||
props: StringHashMap(f64),
|
||||
|
||||
|
|
@ -34,11 +38,14 @@ pub const SoundNode = struct {
|
|||
z: f32 = 0,
|
||||
|
||||
fab: FreqAmpBuffer,
|
||||
active: u8 = 1,
|
||||
|
||||
pub fn create(allocator: Allocator, name: []const u8) !*SoundNode {
|
||||
|
||||
const air_in = ArrayList(*SoundNode).init(allocator);
|
||||
const wire_in = ArrayList(*SoundNode).init(allocator);
|
||||
const air_targets = ArrayList(*SoundNode).init(allocator);
|
||||
const wire_targets = ArrayList(*SoundNode).init(allocator);
|
||||
const activities = ArrayList(*Activity).init(allocator);
|
||||
const fab = FreqAmpBuffer{};
|
||||
const props = StringHashMap(f64).init(allocator);
|
||||
|
|
@ -50,12 +57,15 @@ pub const SoundNode = struct {
|
|||
.name = name,
|
||||
.air_in = air_in,
|
||||
.wire_in = wire_in,
|
||||
.air_targets = air_targets,
|
||||
.wire_targets = wire_targets,
|
||||
.activities = activities,
|
||||
.fab = fab,
|
||||
.props = props,
|
||||
.x = 0,
|
||||
.y = 0,
|
||||
.z = 0,
|
||||
.active = 0,
|
||||
};
|
||||
|
||||
return sn;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue