第二人生的源码分析(二十三)人物行走的键盘消息处理

前面介绍了怎么样显示人物角色,包括名称等等。那么人物角色是怎么样在里面行走的呢?第二人生是通过方向键来控制人物角色的走动,也就是说它是通过接收键盘的消息后不断地计算新的位置来实现移动。下面就是第二人生的消息处理函数代码:
#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 深圳

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

caimouse

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值