1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
require("preload")
local color = require("color")
local win = require("window")
local pp = am.postprocess({
clear_color = color.am_color.background,
depth_buffer = true,
--stencil_buffer = true,
width = win.width,
height = win.height,
})
local world = require("world")
world.node = pp
world.node:action(function()
if win:key_down("l") then
local log = require("log")
log.info("My network peerid is:" .. tostring(world.network.peer.id), {"net"})
if world.hub then
log.info("I'm the host, host peerid is:" .. tostring(world.hub.peer.id), {"net"})
end
log.info("Entities are:" .. tostring(world.level.entities), {"ecs"})
end
end)
--local stars = require("shaders.stars")
--pp:append(stars)
local shader_world = require("shaders.world")
--win.scene:append(shader_world.node)
win.scene:append(shader_world.node)
local ecs = require("ecs")
pp:append(ecs.node)
win.scene:append(pp)
local ui = require("ui")
local depth = am.depth_test("always")
depth:append(ui.node)
win.scene:append(depth)
-- Initialize world.network, world.network_mode, and world.hub
-- These will be set by the menu when user chooses Host or Join
world.network = nil
world.network_mode = nil
world.hub = nil
-- Network pump node - pumps net, world.hub, and world.network (client)
local net = require("net")
local net_node = am.group()
net_node:action(function()
net.pump()
if world.hub then
-- If we're hosting, pump the hub
world.hub:pump()
end
if world.network then
-- Pump the client (both host and regular clients have one)
world.network:pump()
end
end)
win.scene:append(net_node) -- Pumps the net state machine
task = require("task")
win.scene:append(task.node) -- Pumps async tasks
--input_menu = require("menu.input")
--input_menu.initialize()
--require("worldgen")
--require("world_test")
--require("net_test")
--require("ui_test")
--require("router_test")
--require("controller_test")
game = require("menu.game")
pp:append(game.node)
tutorial = require("menu.tutorial")
win.scene:append(tutorial.node)
require("menu.main").initialize()
require("log").listen(function(chunk)
--if chunk.tags.ui then
--return
--end
if not chunk.tags.net then
return
end
--if not chunk.tags.ecs then
--return
--end
--if not chunk.tags.graphic then
--return
--end
--if not (chunk.tags.net and chunk.tags.ecs and chunk.tags.client) then
--return
--end
--if not chunk.message:find("Want to create") then
--return
--end
data = {"[",chunk.level:upper(),"]"}
if chunk.tags.server then
table.insert(data,"[SERVER]")
elseif chunk.tags.client then
table.insert(data,"[CLIENT]")
end
table.insert(data, os.date())
table.insert(data," > ")
table.insert(data,chunk.message)
if chunk.level == "error" then
print(debug.traceback(table.concat(data)))
else
print(table.concat(data))
end
end)
pp.clear_color = require("color").am_color.background
--am.eval_js(require("js_bridge"))
--local a,b = pcall(am.eval_js, require("js_bridge"))
|