Skip to content

Commit 19ff2ab

Browse files
author
Björn Ritzl
committed
Added broadcaster example
1 parent 428b8bb commit 19ff2ab

File tree

5 files changed

+161
-1
lines changed

5 files changed

+161
-1
lines changed
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
name: "default"
2+
scale_along_z: 0
3+
embedded_instances {
4+
id: "broadcaster"
5+
data: "components {\n"
6+
" id: \"script\"\n"
7+
" component: \"/examples/broadcast/broadcaster.script\"\n"
8+
" position {\n"
9+
" x: 0.0\n"
10+
" y: 0.0\n"
11+
" z: 0.0\n"
12+
" }\n"
13+
" rotation {\n"
14+
" x: 0.0\n"
15+
" y: 0.0\n"
16+
" z: 0.0\n"
17+
" w: 1.0\n"
18+
" }\n"
19+
"}\n"
20+
""
21+
position {
22+
x: 0.0
23+
y: 0.0
24+
z: 0.0
25+
}
26+
rotation {
27+
x: 0.0
28+
y: 0.0
29+
z: 0.0
30+
w: 1.0
31+
}
32+
scale3 {
33+
x: 1.0
34+
y: 1.0
35+
z: 1.0
36+
}
37+
}
38+
embedded_instances {
39+
id: "receiver1"
40+
data: "components {\n"
41+
" id: \"script\"\n"
42+
" component: \"/examples/broadcast/receiver1.script\"\n"
43+
" position {\n"
44+
" x: 0.0\n"
45+
" y: 0.0\n"
46+
" z: 0.0\n"
47+
" }\n"
48+
" rotation {\n"
49+
" x: 0.0\n"
50+
" y: 0.0\n"
51+
" z: 0.0\n"
52+
" w: 1.0\n"
53+
" }\n"
54+
"}\n"
55+
""
56+
position {
57+
x: 0.0
58+
y: 0.0
59+
z: 0.0
60+
}
61+
rotation {
62+
x: 0.0
63+
y: 0.0
64+
z: 0.0
65+
w: 1.0
66+
}
67+
scale3 {
68+
x: 1.0
69+
y: 1.0
70+
z: 1.0
71+
}
72+
}
73+
embedded_instances {
74+
id: "receiver2"
75+
data: "components {\n"
76+
" id: \"script\"\n"
77+
" component: \"/examples/broadcast/receiver2.script\"\n"
78+
" position {\n"
79+
" x: 0.0\n"
80+
" y: 0.0\n"
81+
" z: 0.0\n"
82+
" }\n"
83+
" rotation {\n"
84+
" x: 0.0\n"
85+
" y: 0.0\n"
86+
" z: 0.0\n"
87+
" w: 1.0\n"
88+
" }\n"
89+
"}\n"
90+
""
91+
position {
92+
x: 0.0
93+
y: 0.0
94+
z: 0.0
95+
}
96+
rotation {
97+
x: 0.0
98+
y: 0.0
99+
z: 0.0
100+
w: 1.0
101+
}
102+
scale3 {
103+
x: 1.0
104+
y: 1.0
105+
z: 1.0
106+
}
107+
}

examples/broadcast/broadcaster.script

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
local broadcast = require "ludobits.m.broadcast"
2+
3+
function init(self)
4+
msg.post(".", "acquire_input_focus")
5+
end
6+
7+
function final(self)
8+
msg.post(".", "release_input_focus")
9+
end
10+
11+
function on_input(self, action_id, action)
12+
if action.released then
13+
local messages = { "foo", "bar", "boo" }
14+
broadcast.send(messages[math.random(1, #messages)], { time = os.time() })
15+
end
16+
end

examples/broadcast/receiver1.script

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
local broadcast = require "ludobits.m.broadcast"
2+
3+
function init(self)
4+
broadcast.register("foo")
5+
broadcast.register("bar")
6+
end
7+
8+
function final(self)
9+
broadcast.unregister("foo")
10+
broadcast.unregister("bar")
11+
end
12+
13+
function on_message(self, message_id, message, sender)
14+
print("Received", message_id)
15+
--pprint(message)
16+
end

examples/broadcast/receiver2.script

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
local broadcast = require "ludobits.m.broadcast"
2+
3+
local function receive_boo(message)
4+
print("Received boo")
5+
--pprint(message)
6+
end
7+
8+
function init(self)
9+
broadcast.register("foo")
10+
broadcast.register("boo", receive_boo)
11+
end
12+
13+
function final(self)
14+
broadcast.unregister("foo")
15+
broadcast.unregister("boo", receive_boo)
16+
end
17+
18+
function on_message(self, message_id, message, sender)
19+
print("Received", message_id)
20+
--pprint(message)
21+
end

game.project

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title = Ludobits
33
version = 0.7.3
44

55
[bootstrap]
6-
main_collection = /examples/dynamic/dynamic.collectionc
6+
main_collection = /examples/broadcast/broadcast.collectionc
77
render = /ludobits/r/split_screen.renderc
88

99
[input]

0 commit comments

Comments
 (0)