Small fix.
[urggr.git] / src / urggr.lua
blobd60035ab9bf38bf56d55e5ee77fea7d69db1f7fc
1 #!${LUA_INTERPRETER}
2 --[[
3 Urggr - An horizontal scrolling shoot'em up.
4 Copyright 2008 Antoine Chavasse <a.chavasse@gmail.com>
6 This file is part of Urggr.
8 Urggr is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License version 3
10 as published by the Free Software Foundation.
12 Urggr is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 --]]
21 package.path = package.path .. '${LUA_PACKAGE_PATH}'
23 Settings = {}
25 require 'qtcore'
26 require 'qtgui'
27 require 'qtopengl'
28 require 'fail'
29 require 'fail.math'
30 sg = require 'fail.scenegraph'
31 require 'fail.scenegraph.shapes'
32 require 'fail.bullet.collision'
33 require 'fail.game.keyboard'
34 require 'fail.gamestorage'
35 require 'fail.io'
36 require 'fail.fbffile'
37 require 'urggr'
39 qtapp = QApplication( 1 + select( '#', ... ), { arg[0], ...} )
40 qtapp.__gc = qtapp.delete
42 -- Serialization test. Create a cube with a material and save it to a file.
43 --[[local frame = sg.Frame()
44 local mat = sg.Material()
45 mat.Emission.value = fail.math.Vector4f( 0, 1, 1, 1 )
46 mat.Specular.value = fail.math.Vector4f( 0, 0, 0, 1 )
47 local renderable = sg.shapes.Cube( mat, frame )
49 fail.fbffile.Writer.Save( "lulz.fbf", renderable )]]
52 -- The current game scene (which can be the main menu, a game level, a mini game or basically anything occupying the rendering and UI)
53 -- will just provide a QGraphicsScene that we'll set as the current scene of the top level QGraphicsView. The actual fail engine action
54 -- shall be rendered with an overloaded drawBackground function, the QGraphicsItems should be used only for UI and hud elements.
55 -- The QGraphicsView used will always use a QGLWidget as its viewport.
57 -- Setup the main window, a QGraphicsView displaying our QGraphicsScene.
58 gv = QGraphicsView()
60 gv:setViewportUpdateMode( "FullViewportUpdate" )
61 gv:setCacheMode( {"CacheNone"} )
62 gv:setViewport( QGLWidget() )
64 -- Create the mainmenu. It'll set its own scene as the graphics view scene.
65 urggr.MainMenu( gv )
67 gv:show()
68 gv:resize(1024, 768);
70 -- TODO: separate the game logic updates and put them on a fixed time step.
71 -- Also change the input stuff to buffer the inputs and have them sent (and the
72 -- game event handler called) only when ticking the game updates (so the event handlers
73 -- can safely change the object states, which shouldn't be done in between game ticks)
75 -- It would be easier if it was possible to have qt process its events and render separately.
76 while( true ) do
77 qtapp.processEvents()
78 qtapp.sendPostedEvents()
79 end