Engine 0.0.6
Game engine in lua
Loading...
Searching...
No Matches
main.lua
Go to the documentation of this file.
1local zeebo_module = require('src/lib/engine/module')
2local engine_encoder = require('src/lib/engine/encoder')
3local engine_fps = require('src/lib/engine/fps')
4local engine_math = require('src/lib/engine/math')
5local engine_game = require('src/lib/engine/game')
6local engine_http = require('src/lib/engine/http')
7local engine_color = require('src/lib/object/color')
8local engine_keys = require('src/engine/core/ginga/keys')
9local engine_loop = require('src/engine/core/ginga/loop')
10local engine_draw = require('src/engine/core/ginga/draw')
11local engine_draw_fps = require('src/lib/draw/fps')
12local engine_draw_poly = require('src/lib/draw/poly')
13local library_csv = require('src/third_party/csv/rodrigodornelles')
14local library_json = require('src/third_party/json/rxi')
15local protocol_http_ginga = require('src/lib/protocol/http_ginga')
16local application = nil
17local game = require('src/lib/object/game')
18local std = require('src/lib/object/std')
19
20--! @short nclua:canvas
21--! @li <http://www.telemidia.puc-rio.br/~francisco/nclua/referencia/canvas.html>
23
24--! @short nclua:event
25--! @li <http://www.telemidia.puc-rio.br/~francisco/nclua/referencia/event.html>
26local event = event
27
28--! @short clear ENV
29--! @brief GINGA?
30_ENV = nil
31
32local function register_event_loop(listener)
33 event.register(listener('ginga'))
34end
35
36local function register_fixed_loop(listener)
37 local tick = nil
38 local loop = listener('loop')
39 local draw = listener('draw')
40
41 tick = function()
42 local delay = application.internal.fps_controler(event.uptime())
43 loop()
44 canvas:attrColor(0, 0, 0, 0)
46 draw()
47 canvas:flush()
48 event.timer(delay, tick)
49 end
50
51 event.timer(1, tick)
52end
53
54local function install(evt, gamefile)
55 if evt.class ~= 'ncl' or evt.action ~= 'start' then return end
56 local ginga = {
58 event=event
59 }
60 local polygons = {
61 repeats={true, true},
62 line=canvas.drawLine,
63 object=canvas
64 }
65 local config_fps = {
66 list={100, 60, 30, 20, 15, 10},
67 time={1, 10, 30, 40, 60, 90}
68 }
69
70 application = zeebo_module.loadgame(gamefile)
71 if not application then
72 error('game not loaded!')
73 end
74
75 game.width, game.height = canvas:attrSize()
76 game.fps_max = application.config and application.config.fps_max or 100
77 game.fps_show = application.config and application.config.fps_show or 0
78
80 :package('@fps', engine_fps, config_fps)
81 :package('@math', engine_math)
82 :package('@game', engine_game)
83 :package('@color', engine_color)
84 :package('@keys', engine_keys)
85 :package('@loop', engine_loop)
86 :package('@draw', engine_draw, ginga)
87 :package('@draw_fps', engine_draw_fps)
88 :package('@draw_poly', engine_draw_poly, polygons)
89 :package('load', zeebo_module.load)
92 :package('math', engine_math.clib)
93 :package('random', engine_math.clib_random)
95 :register(register_event_loop)
96 :register(register_fixed_loop)
97 :run()
98
99 application.callbacks.init(std, game)
100 event.unregister(install)
101end
102
103event.register(install)
104return install
local function require(std, game, application)
local function package(self, module_name, module, custom)
local function register(self, register_func)
local json
Definition rxi.lua:2
local function error(self, handler_func)
local function draw(std, game)
local function http(std, game)
local function run(args)
local library_csv
Definition main.lua:13
local function register_event_loop(listener)
local engine_loop
Definition main.lua:9
local engine_fps
Definition main.lua:3
local engine_draw_fps
Definition main.lua:11
local library_json
Definition main.lua:14
local application
Definition main.lua:16
local engine_game
Definition main.lua:5
local canvas
nclua:canvas
Definition main.lua:22
local game
Definition main.lua:17
local std
Definition main.lua:18
local engine_keys
Definition main.lua:8
local function register_fixed_loop(listener)
local engine_color
Definition main.lua:7
local engine_math
Definition main.lua:4
local engine_draw_poly
Definition main.lua:12
local engine_http
Definition main.lua:6
local zeebo_module
Definition main.lua:1
local function install(evt, gamefile)
local event
nclua:event
Definition main.lua:26
local engine_encoder
Definition main.lua:2
_ENV
clear ENV
Definition main.lua:30
local engine_draw
Definition main.lua:10
local protocol_http_ginga
Definition main.lua:15
local function line(x1, y1, x2, y2)
local function clear(c)
local function color(c)
local math
Definition draw.lua:1
local function loop(std, game, application, dt)
local function fps(self, show, x, y)