diff options
Diffstat (limited to 'src/main.lua')
| -rw-r--r-- | src/main.lua | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/src/main.lua b/src/main.lua new file mode 100644 index 0000000..aebd83f --- /dev/null +++ b/src/main.lua @@ -0,0 +1,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")) |
