Skip to content

Commit 2a56cb4

Browse files
committed
Drop broadcast block optimization
1 parent 83dd694 commit 2a56cb4

File tree

3 files changed

+6
-34
lines changed

3 files changed

+6
-34
lines changed

src/blocks/eventblocks.cpp

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -96,19 +96,8 @@ void EventBlocks::compileWhenStageClicked(Compiler *compiler)
9696

9797
void EventBlocks::compileBroadcast(Compiler *compiler)
9898
{
99-
auto input = compiler->input(BROADCAST_INPUT);
100-
101-
if (input->type() != Input::Type::ObscuredShadow) {
102-
std::vector<int> broadcasts = compiler->engine()->findBroadcasts(input->primaryValue()->value().toString());
103-
104-
for (int index : broadcasts) {
105-
compiler->addConstValue(index);
106-
compiler->addFunctionCall(&broadcastByIndex);
107-
}
108-
} else {
109-
compiler->addInput(input);
110-
compiler->addFunctionCall(&broadcast);
111-
}
99+
compiler->addInput(BROADCAST_INPUT);
100+
compiler->addFunctionCall(&broadcast);
112101
}
113102

114103
void EventBlocks::compileBroadcastAndWait(Compiler *compiler)
@@ -197,12 +186,6 @@ unsigned int EventBlocks::broadcast(VirtualMachine *vm)
197186
return 1;
198187
}
199188

200-
unsigned int EventBlocks::broadcastByIndex(VirtualMachine *vm)
201-
{
202-
vm->engine()->broadcast(vm->getInput(0, 1)->toLong(), vm);
203-
return 1;
204-
}
205-
206189
unsigned int EventBlocks::broadcastAndWait(VirtualMachine *vm)
207190
{
208191
std::vector<int> broadcasts = vm->engine()->findBroadcasts(vm->getInput(0, 1)->toString());

src/blocks/eventblocks.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ class EventBlocks : public IBlockSection
5656
static unsigned int whenTouchingObjectPredicate(VirtualMachine *vm);
5757

5858
static unsigned int broadcast(VirtualMachine *vm);
59-
static unsigned int broadcastByIndex(VirtualMachine *vm);
6059
static unsigned int broadcastAndWait(VirtualMachine *vm);
6160

6261
static unsigned int whenLoudnessGreaterThanPredicate(VirtualMachine *vm);

test/blocks/event_blocks_test.cpp

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -373,9 +373,7 @@ TEST_F(EventBlocksTest, Broadcast)
373373
notBlock->setCompileFunction(&OperatorBlocks::compileNot);
374374
addObscuredInput(block2, "BROADCAST_INPUT", EventBlocks::BROADCAST_INPUT, notBlock);
375375

376-
EXPECT_CALL(m_engineMock, findBroadcasts("test")).WillOnce(Return(std::vector<int>({ 0, 3 })));
377-
EXPECT_CALL(m_engineMock, functionIndex(&EventBlocks::broadcastByIndex)).Times(2).WillRepeatedly(Return(0));
378-
EXPECT_CALL(m_engineMock, functionIndex(&EventBlocks::broadcast)).WillOnce(Return(1));
376+
EXPECT_CALL(m_engineMock, functionIndex(&EventBlocks::broadcast)).Times(2).WillRepeatedly(Return(0));
379377

380378
compiler.init();
381379
compiler.setBlock(block1);
@@ -384,17 +382,16 @@ TEST_F(EventBlocksTest, Broadcast)
384382
EventBlocks::compileBroadcast(&compiler);
385383
compiler.end();
386384

387-
ASSERT_EQ(compiler.bytecode(), std::vector<unsigned int>({ vm::OP_START, vm::OP_CONST, 0, vm::OP_EXEC, 0, vm::OP_CONST, 1, vm::OP_EXEC, 0, vm::OP_NULL, vm::OP_NOT, vm::OP_EXEC, 1, vm::OP_HALT }));
388-
ASSERT_EQ(compiler.constValues(), std::vector<Value>({ 0, 3 }));
385+
ASSERT_EQ(compiler.bytecode(), std::vector<unsigned int>({ vm::OP_START, vm::OP_CONST, 0, vm::OP_EXEC, 0, vm::OP_NULL, vm::OP_NOT, vm::OP_EXEC, 0, vm::OP_HALT }));
386+
ASSERT_EQ(compiler.constValues(), std::vector<Value>({ "test" }));
389387
ASSERT_TRUE(compiler.variables().empty());
390388
ASSERT_TRUE(compiler.lists().empty());
391389
}
392390

393391
TEST_F(EventBlocksTest, BroadcastImpl)
394392
{
395393
static unsigned int bytecode1[] = { vm::OP_START, vm::OP_CONST, 0, vm::OP_EXEC, 0, vm::OP_HALT };
396-
static unsigned int bytecode2[] = { vm::OP_START, vm::OP_CONST, 1, vm::OP_EXEC, 1, vm::OP_HALT };
397-
static BlockFunc functions[] = { &EventBlocks::broadcast, &EventBlocks::broadcastByIndex };
394+
static BlockFunc functions[] = { &EventBlocks::broadcast };
398395
static Value constValues[] = { "test", 2 };
399396

400397
VirtualMachine vm(nullptr, &m_engineMock, nullptr);
@@ -409,13 +406,6 @@ TEST_F(EventBlocksTest, BroadcastImpl)
409406
vm.run();
410407

411408
ASSERT_EQ(vm.registerCount(), 0);
412-
413-
EXPECT_CALL(m_engineMock, broadcast(2, &vm)).Times(1);
414-
415-
vm.setBytecode(bytecode2);
416-
vm.run();
417-
418-
ASSERT_EQ(vm.registerCount(), 0);
419409
}
420410

421411
TEST_F(EventBlocksTest, BroadcastAndWait)

0 commit comments

Comments
 (0)