前面介绍了怎么样显示人物角色,包括名称等等。那么人物角色是怎么样在里面行走的呢?第二人生是通过方向键来控制人物角色的走动,也就是说它是通过接收键盘的消息后不断地计算新的位置来实现移动。下面就是第二人生的消息处理函数代码:
#001 bool LLAppViewer::mainLoop()
#002 {
#003 //-------------------------------------------
#004 // Run main loop until time to quit
#005 //-------------------------------------------
#006
#007 // Create IO Pump to use for HTTP Requests.
#008 gServicePump = new LLPumpIO(gAPRPoolp);
#009 LLHTTPClient::setPump(*gServicePump);
#010 LLCurl::setCAFile(gDirUtilp->getCAFile());
#011
#012 // initialize voice stuff here
#013 gLocalSpeakerMgr = new LLLocalSpeakerMgr();
#014 gActiveChannelSpeakerMgr = new LLActiveSpeakerMgr();
#015
#016 LLVoiceChannel::initClass();
#017 LLVoiceClient::init(gServicePump);
#018
#019 LLMemType mt1(LLMemType::MTYPE_MAIN);
#020 LLTimer frameTimer,idleTimer;
#021 LLTimer debugTime;
#022
#023 // Handle messages
#024 while (!LLApp::isExiting())
#025 {
#026 LLFastTimer::reset(); // Should be outside of any timer instances
#027 {
#028 LLFastTimer t(LLFastTimer::FTM_FRAME);
#029
#030 {
#031 LLFastTimer t2(LLFastTimer::FTM_MESSAGES);
#032 #if LL_WINDOWS
#033 if (!LLWinDebug::setupExceptionHandler())
#034 {
#035 llwarns << " Someone took over my exception handler (post messagehandling)!" << llendl;
#036 }
#037 #endif
#038
#039 gViewerWindow->mWindow->gatherInput();
#040 }
#041
#042 #if 1 && !RELEASE_FOR_DOWNLOAD
#043 // once per second debug info
#044 if (debugTime.getElapsedTimeF32() > 1.f)
#045 {
#046 debugTime.reset();
#047 }
#048 #endif
#049
#050 if (!LLApp::isExiting())
#051 {
#052 // Scan keyboard for movement keys. Command keys and typing
#053 // are handled by windows callbacks. Don't do this until we're
#054 // done initializing. JC
#055 if (gViewerWindow->mWindow->getVisible()
#056 && gViewerWindow->getActive()
#057 && !gViewerWindow->mWindow->getMinimized()
#058 && LLStartUp::getStartupState() == STATE_STARTED
#059 && !gViewerWindow->getShowProgress()
#060 && !gFocusMgr.focusLocked())
#061 {
#062 gKeyboard->scanKeyboard();
#063 LLViewerJoystick::scanJoystick();
#064 }
#065
……
#193
#194 // Save snapshot for next time, if we made it through initialization
#195 if (STATE_STARTED == LLStartUp::getStartupState())
#196 {
#197 saveFinalSnapshot();
#198 }
#199
#200 delete gServicePump;
#201
#202 llinfos << "Exiting main_loop" << llendflush;
#203
#204 return true;
#205 }
这里通过调用函数
gKeyboard->scanKeyboard()来处理键盘消息的,它实现每个键盘的消息处理,然后调用文件llviewerkeyboard.cpp的函数bind_keyboard_functions()绑定的函数来处理每个事件。比如向前走,就进行如下操作:
gViewerKeyboard.bindNamedFunction("move_forward", camera_move_forward);
当按下向前的按键时,就会调用函数camera_move_forward来处理这个事件,这样就可以调整摄像像的位置,就实现了人物的行走。
蔡军生
2008/3/12 QQ:9073204
深圳