Skip to content

Commit

Permalink
Added broadcaster example
Browse files Browse the repository at this point in the history
  • Loading branch information
Björn Ritzl committed Sep 16, 2016
1 parent 428b8bb commit 19ff2ab
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 1 deletion.
107 changes: 107 additions & 0 deletions examples/broadcast/broadcast.collection
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
name: "default"
scale_along_z: 0
embedded_instances {
id: "broadcaster"
data: "components {\n"
" id: \"script\"\n"
" component: \"/examples/broadcast/broadcaster.script\"\n"
" position {\n"
" x: 0.0\n"
" y: 0.0\n"
" z: 0.0\n"
" }\n"
" rotation {\n"
" x: 0.0\n"
" y: 0.0\n"
" z: 0.0\n"
" w: 1.0\n"
" }\n"
"}\n"
""
position {
x: 0.0
y: 0.0
z: 0.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale3 {
x: 1.0
y: 1.0
z: 1.0
}
}
embedded_instances {
id: "receiver1"
data: "components {\n"
" id: \"script\"\n"
" component: \"/examples/broadcast/receiver1.script\"\n"
" position {\n"
" x: 0.0\n"
" y: 0.0\n"
" z: 0.0\n"
" }\n"
" rotation {\n"
" x: 0.0\n"
" y: 0.0\n"
" z: 0.0\n"
" w: 1.0\n"
" }\n"
"}\n"
""
position {
x: 0.0
y: 0.0
z: 0.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale3 {
x: 1.0
y: 1.0
z: 1.0
}
}
embedded_instances {
id: "receiver2"
data: "components {\n"
" id: \"script\"\n"
" component: \"/examples/broadcast/receiver2.script\"\n"
" position {\n"
" x: 0.0\n"
" y: 0.0\n"
" z: 0.0\n"
" }\n"
" rotation {\n"
" x: 0.0\n"
" y: 0.0\n"
" z: 0.0\n"
" w: 1.0\n"
" }\n"
"}\n"
""
position {
x: 0.0
y: 0.0
z: 0.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale3 {
x: 1.0
y: 1.0
z: 1.0
}
}
16 changes: 16 additions & 0 deletions examples/broadcast/broadcaster.script
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
local broadcast = require "ludobits.m.broadcast"

function init(self)
msg.post(".", "acquire_input_focus")
end

function final(self)
msg.post(".", "release_input_focus")
end

function on_input(self, action_id, action)
if action.released then
local messages = { "foo", "bar", "boo" }
broadcast.send(messages[math.random(1, #messages)], { time = os.time() })
end
end
16 changes: 16 additions & 0 deletions examples/broadcast/receiver1.script
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
local broadcast = require "ludobits.m.broadcast"

function init(self)
broadcast.register("foo")
broadcast.register("bar")
end

function final(self)
broadcast.unregister("foo")
broadcast.unregister("bar")
end

function on_message(self, message_id, message, sender)
print("Received", message_id)
--pprint(message)
end
21 changes: 21 additions & 0 deletions examples/broadcast/receiver2.script
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
local broadcast = require "ludobits.m.broadcast"

local function receive_boo(message)
print("Received boo")
--pprint(message)
end

function init(self)
broadcast.register("foo")
broadcast.register("boo", receive_boo)
end

function final(self)
broadcast.unregister("foo")
broadcast.unregister("boo", receive_boo)
end

function on_message(self, message_id, message, sender)
print("Received", message_id)
--pprint(message)
end
2 changes: 1 addition & 1 deletion game.project
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title = Ludobits
version = 0.7.3

[bootstrap]
main_collection = /examples/dynamic/dynamic.collectionc
main_collection = /examples/broadcast/broadcast.collectionc
render = /ludobits/r/split_screen.renderc

[input]
Expand Down

0 comments on commit 19ff2ab

Please sign in to comment.