77#include " TreeLoader3D.h"
88#include " space_world.h"
99#include " space_login.h"
10+ #include " space_avatarselect.h"
1011#include " cstdkbe/cstdkbe.hpp"
1112
1213#include " ../kbengine_dll/kbengine_dll.h"
@@ -23,9 +24,12 @@ namespace KBEngine{
2324
2425template <> OgreApplication* Ogre::Singleton<OgreApplication>::msSingleton = 0 ;
2526
26- Space* space = NULL ;
27+ Space* g_space = NULL ;
28+ boost::mutex g_spaceMutex;
29+
2730// -------------------------------------------------------------------------------------
28- OgreApplication::OgreApplication (void )
31+ OgreApplication::OgreApplication (void ):
32+ events_()
2933{
3034 kbe_registerEventHandle (this );
3135}
@@ -35,6 +39,7 @@ OgreApplication::~OgreApplication(void)
3539{
3640 kbe_deregisterEventHandle (this );
3741 mCameraMan = NULL ;
42+ SAFE_RELEASE (g_space);
3843}
3944
4045// -------------------------------------------------------------------------------------
@@ -77,9 +82,20 @@ bool OgreApplication::setup(void)
7782
7883 createFrameListener ();
7984
85+ changeSpace (new SpaceLogin (mRoot , mWindow , mInputManager , mTrayMgr ));
8086 return true ;
8187};
8288
89+ // -------------------------------------------------------------------------------------
90+ void OgreApplication::changeSpace (Space* space)
91+ {
92+ if (g_space)
93+ delete g_space;
94+
95+ g_space = space;
96+ space->setup ();
97+ }
98+
8399// -------------------------------------------------------------------------------------
84100void OgreApplication::setupResources (void )
85101{
@@ -91,18 +107,20 @@ bool OgreApplication::frameRenderingQueued(const Ogre::FrameEvent& evt)
91107{
92108 bool ret = BaseApplication::frameRenderingQueued (evt);
93109
94- kbe_update ();
110+ if (g_space == NULL )
111+ return false ;
95112
96- if (space == NULL )
113+ boost::mutex::scoped_lock lock (g_spaceMutex);
114+ std::vector<const KBEngine::EventData*>::iterator iter = events_.begin ();
115+ for (; iter != events_.end (); iter++)
97116 {
98- space = new SpaceLogin (mRoot , mWindow , mInputManager , mTrayMgr );
99- space->setup ();
100- }
101- else
102- {
103- space->frameRenderingQueued (evt);
117+ g_space->kbengine_onEvent ((*iter));
118+ delete (*iter);
104119 }
120+
121+ events_.clear ();
105122
123+ g_space->frameRenderingQueued (evt);
106124 return ret;
107125}
108126
@@ -111,9 +129,9 @@ bool OgreApplication::keyPressed( const OIS::KeyEvent &arg )
111129{
112130 if (mTrayMgr ->isDialogVisible ()) return true ; // don't process any more keys if dialog is up
113131
114- if (space )
132+ if (g_space )
115133 {
116- space ->keyPressed (arg);
134+ g_space ->keyPressed (arg);
117135 }
118136
119137 return BaseApplication::keyPressed ( arg );
@@ -122,15 +140,23 @@ bool OgreApplication::keyPressed( const OIS::KeyEvent &arg )
122140// -------------------------------------------------------------------------------------
123141void OgreApplication::buttonHit (OgreBites::Button* button)
124142{
125- if (space )
143+ if (g_space )
126144 {
127- space ->buttonHit (button);
145+ g_space ->buttonHit (button);
128146 }
129147}
130148
131149// -------------------------------------------------------------------------------------
132150void OgreApplication::kbengine_onEvent (const KBEngine::EventData* lpEventData)
133151{
152+ KBEngine::EventData* peventdata = KBEngine::newKBEngineEvent (lpEventData->id );
153+
154+ if (peventdata)
155+ {
156+ *peventdata = *lpEventData;
157+ boost::mutex::scoped_lock lock (g_spaceMutex);
158+ events_.push_back (peventdata);
159+ }
134160}
135161
136162// -------------------------------------------------------------------------------------
0 commit comments