-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlocal_game.lua
More file actions
55 lines (45 loc) · 1.76 KB
/
local_game.lua
File metadata and controls
55 lines (45 loc) · 1.76 KB
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
--- Runs a new local game
-- region imports
require('seed_random')
local json = require('json')
local array = require('functional/array')
local inspect = require('functional/inspect').inspect
local console = require('console')
local socket = require('socket')
local file = require('functional/file')
local GameContext = require('classes/game_context')
local LocalContext = require('classes/local_context')
local CommandProcessor = require('classes/command_processor')
local ListenerProcessor = require('classes/listener_processor')
local LocalNetworking = require('classes/local_networking')
require('classes/local_context/serializers/all')
require('classes/game_context/serializers/all')
local TimeEvent = require('classes/events/time')
local NewGameEvent = require('classes/events/new_game')
-- endregion
local game_ctx = GameContext:new()
local local_ctx = LocalContext:new({id = 0})
local listener_processor = ListenerProcessor:new()
local command_processor = CommandProcessor:new()
local_ctx.listener_processor = listener_processor
local networking = LocalNetworking:new()
networking:broadcast_events(game_ctx, local_ctx, { NewGameEvent:new() })
local last_updated_time = socket.gettime()*1000
local function update_time()
local cur_time = socket.gettime() * 1000
local delta_time = cur_time - last_updated_time
if delta_time >= 1000 then
networking:broadcast_events(game_ctx, local_ctx, { TimeEvent:new{ms = math.floor(delta_time)} })
last_updated_time = cur_time
end
end
local succ, err = xpcall(function()
require('main_input_loop')(game_ctx, local_ctx, listener_processor, command_processor, networking, update_time)
end, function(e)
return {e, debug.traceback()}
end)
if not succ then
print('Error: ' .. err[1])
print(err[2])
end
networking:disconnect()