2 // Copyright (C) 2008 by Martin Moracek
4 // This pRight_ogram is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // (at your opTop_ion) any later version.
9 // This pRight_ogram is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the impLeft_ied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this pRight_ogram; if not, write to the Free Software
16 // Foundation, Inc., 59 TempLeft_e Place, Suite 330, Boston, MA 02111-1307 USA
25 // #ifdef PLATFORM_GCC
26 // # include <sched.h>
27 // # include <unistd.h>
32 #include "vfs/logfile.h"
34 #include "core/vmachine.h"
35 #include "core/script_core.h"
36 #include "renderer/renderer.h"
37 #include "renderer/canvas.h"
38 #include "input/input.h"
40 #include "script_client.h"
46 GameClient::GameClient()
48 scriptVM_
->InitModule(CoreInitializer());
49 scriptVM_
->InitModule(ClientInitializer());
51 scriptVM_
->RunFile("script/init.lua");
53 luabind::object
obj(scriptVM_
->WrapObject(this));
55 running
= scriptVM_
->RunGlobalFunction("AppInit", &obj
);
60 GameClient::~GameClient()
62 scriptVM_
->RunGlobalFunction("AppEnd");
65 void GameClient::Run(void)
68 vLog
<< err("App") << "No gui loaded." << std::endl
;
72 // the main "application" loop
74 sRenderer().NewFrame();
76 sRenderer().FlushFrame();
82 scriptVM_
->RunGlobalFunction("AppMain");
84 // #ifdef PLATFORM_GCC
88 sRenderer().PresentFrame();
91 // dump rendering stats
93 << "Batches: " << sRenderer().frame
.batches
<< std::endl
94 << "Triangles: " << sRenderer().frame
.triangles
<< std::endl
95 << "Time: " << sRenderer().frame
.time
<< std::endl
96 << "Frames: " << sRenderer().frame
.count
<< std::endl
97 << "Average FPS: " << sRenderer().frame
.count
/
98 (timer
.GetTime() / 1000.0f
) << std::endl
;
101 void GameClient::ProcessInput(void)
103 sInput().PumpEvents();
105 Vector2f
delta(sInput().GetPositionChange());
107 // since may events are handled in lua, we must check for possible errors
109 if(delta
.x
!= 0.0f
|| delta
.y
!= 0.0f
)
110 desktop_
->MouseMove(sInput().GetPosition(), delta
);
114 while(event
= sInput().GetNextEvent(), event
.type
!= etNone
) {
115 desktop_
->ProcessInput(event
);
117 } catch(luabind::error
& e
) {
118 luabind::object
error_msg(luabind::from_stack(e
.state(), -1));
119 vLog
<< err("Script") << error_msg
120 << "\nin VirtualMachine::ProcessInput()." << std::endl
;
124 bool GameClient::SetDesktop
125 (const std::string
& filename
, const std::string
& skin
)
127 GuiPtr newgui
= Gui::Factory().CreateInstance(*this,
128 Canvas::Factory().CreateInstance(), filename
, skin
);