root/trunk/lugre/lua/lugre.lua @ 727

Revision 727, 5.9 kB (checked in by ghoulsblade, 16 months ago)

unicode enable for chatinput, added Hook_Window_Resize

Line 
1-- some global timing variables (do not modifiy them!!!!)
2gMyFrameCounter = 0
3gSecondsSinceLastFrame = 0
4gMyTicks = 0
5gFrameStartTicks = 0
6-- -----------------------------
7
8-- some timing settings
9gFreeOldUnusedParticleSystemsTimeout = 10 * 1000
10gFreeOldUnusedParticleSystemsLimit = 100
11
12gLugreGoodFPS = 25
13gLugreGoodFrameTicks = 1000 / gLugreGoodFPS
14
15-- returns if there is time left in this frame using a good fps as reference.
16-- you can call this method to decide if you start
17function TimeLeftInFrame ()
18        return gLugreGoodFrameTicks - (Client_GetTicks() - gFrameStartTicks) > 0
19end
20
21function MyPOpenErrorTest () error("kapuuuuutt!") end
22function MyPOpen (...)
23        local success,errormsg_or_result = lugrepcall(io.popen,...)
24        --~ local success,errormsg_or_result = lugrepcall(MyPOpenErrorTest,...)
25        if (success) then return errormsg_or_result end
26        return nil,errormsg_or_result -- error
27end
28
29function lugre_detect_ogre_plugin_path () 
30        --~ print("lugre_detect_ogre_plugin_path:",gOgrePluginPath,WIN32)
31        if (gOgrePluginPath) then return gOgrePluginPath end -- override via config
32        if (WIN32) then return end -- autodetect(and popen) not possible on win, but libs are in working dir there
33        local cmd = "pkg-config --variable=plugindir OGRE"
34        local p,errtxt = MyPOpen(cmd)
35        if (not p) then 
36                print("lugre_detect_ogre_plugin_path failed:",errtxt)
37                print("please run the following manually:",cmd)
38                print("or if that fails :","locate Plugin_OctreeSceneManager.so")
39                print("if that fails too, try reinstalling ogre")
40                print("but if it works, add a line like the following to your data/config.lua :  gOgrePluginPath = \"/usr/local/lib/OGRE\"")
41                print("to get rid of this error")
42                os.exit(0)
43        end
44        local res = p and p:read() -- read line
45        if (p) then p:close() end
46        return res
47end
48
49function lugre_include_libs (basepath,lugrewidgetpath)
50        local libpath = basepath
51        lugrewidgetpath = lugrewidgetpath or ( basepath.."../widgets/" )
52               
53                -- test
54        dofile(libpath .. "lib.profile.lua")
55        dofile(libpath .. "lib.util.lua")
56        dofile(libpath .. "lib.listener.lua")
57        dofile(libpath .. "lib.contextmenu.lua")
58        dofile(libpath .. "lib.cursor.lua")
59        dofile(libpath .. "lib.tooltip.lua")
60        dofile(libpath .. "lib.sound.lua")
61        dofile(libpath .. "lib.box.lua")
62        dofile(libpath .. "lib.prism.lua")
63        dofile(libpath .. "lib.primitive.lua")
64        dofile(libpath .. "lib.voxel.lua")
65        dofile(libpath .. "lib.plugin.lua")
66        dofile(libpath .. "lib.cam.lua")
67        dofile(libpath .. "lib.beam.lua")
68        dofile(libpath .. "lib.material.lua")
69        dofile(libpath .. "lib.types.lua")
70        dofile(libpath .. "lib.time.lua")
71        dofile(libpath .. "lib.input.lua")
72        dofile(libpath .. "lib.netmessage.lua")
73        dofile(libpath .. "lib.broadcast.lua")
74        dofile(libpath .. "lib.glyphlist.lua")
75        dofile(libpath .. "lib.gui.lua")
76        dofile(libpath .. "lib.gui.spritepanel.lua")
77        dofile(libpath .. "lib.gui.font.lua")
78        dofile(libpath .. "lib.gui.widget.lua")
79        dofile(libpath .. "lib.gui.xml.lua")
80        dofile(libpath .. "lib.gui.layout.lua")
81        dofile(libpath .. "lib.gui.test.lua")
82        dofile(libpath .. "lib.guiutils.lua")
83        dofile(libpath .. "lib.guimaker.lua")
84        dofile(libpath .. "lib.fadelines.lua")
85        dofile(libpath .. "lib.edittext.lua")
86        dofile(libpath .. "lib.chatline.lua")
87        dofile(libpath .. "lib.plaingui.lua")
88        dofile(libpath .. "lib.movedialog.lua")
89        dofile(libpath .. "lib.preview.lua")
90        dofile(libpath .. "lib.http.lua")
91        dofile(libpath .. "lib.irc.lua")
92        dofile(libpath .. "lib.filebrowser.lua")
93        dofile(libpath .. "lib.thread.lua")
94        dofile(libpath .. "lib.ode.lua")
95        dofile(libpath .. "lib.texatlas.lua")
96        dofile(libpath .. "lib.atlasgroup.lua")
97        dofile(libpath .. "lib.job.lua")
98        dofile(libpath .. "lib.fifo.lua")
99        dofile(libpath .. "lib.config.lua")
100        dofile(libpath .. "lib.registry.lua")
101        dofile(libpath .. "lib.simplexml.lua")
102        --dofile(libpath .. "lib.xml.lua")
103        --dofile(libpath .. "lib.net.lua")
104        --dofile(libpath .. "lib.mousepick.lua")
105       
106        RegisterListener("lugre_error",function (...) print("lugre_error",...) end)
107       
108        LoadWidgetsBase(lugrewidgetpath)
109       
110        -- register pixel format constants, like PF_FLOAT16_R
111        if (OgrePixelFormatList) then
112                local mylist = OgrePixelFormatList()
113                for name,id in pairs(mylist) do _G[name] = id end
114        end
115       
116        RegisterIntervalStepper(100,function () 
117                local vw,vh = GetViewportSize()
118                if (vw and (gLugre_last_vw ~= vw or gLugre_last_vh ~= vh)) then 
119                        gLugre_last_vw = vw
120                        gLugre_last_vh = vh
121                        NotifyListener("Hook_Window_Resize",vw,vh)
122                end
123        end)
124end
125
126-- test if a name is following the convention for global variables and constants (e.g. giMyInt or gSomething or kBlub)
127-- g : globals
128-- k : constants
129-- c : classes
130function LugreIsGlobalVarName (name) return string.match(name,"^[gkc][iblsfv]*[A-Z]") ~= nil end
131
132function LugreActivateGlobalVarChecking ()
133        -- install metatable to enforce naming convention gUppercaseletter for global vars
134        setmetatable(_G,{
135                __newindex=function (t,k,v) 
136                        if ((type(v) ~= "function") and (not LugreIsGlobalVarName(k))) then 
137                                print("warning, illegal global var naming",k,v,_TRACEBACK()) 
138                        end 
139                        rawset(t, k, v)
140                        end
141                } )
142end
143
144-- call this in your mainloop
145function LugreStep ()
146        local curticks = Client_GetTicks()
147        collectgarbage("step")
148        gSecondsSinceLastFrame = (curticks - gMyTicks) / 1000.0
149        gMyFrameCounter = gMyFrameCounter + 1
150        gMyTicks = curticks
151        gFrameStartTicks = curticks
152
153        SoundStep()
154        gui.StepMoveDialog()
155
156        --UpdateFPS()
157        UpdateStats()
158        StepFadeLines()
159
160        job.step()
161
162        NotifyListener("LugreStep")
163
164        -- remove unused particle systems from cache from time to time
165        if not gNextFreeOldUnusedParticleSystems or gNextFreeOldUnusedParticleSystems < gMyTicks then
166                gNextFreeOldUnusedParticleSystems = gMyTicks + gFreeOldUnusedParticleSystemsTimeout
167                if (FreeOldUnusedParticleSystems) then FreeOldUnusedParticleSystems(gFreeOldUnusedParticleSystemsLimit) end
168        end
169end
170
171-- called after Main function ends to shutdown all lugre parts
172-- you should not call this manually!
173function LugreShutdown ()
174        print("shutting down lugre ...")
175        NotifyListener("LugreShutdown")
176end
Note: See TracBrowser for help on using the browser.