仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 13957|回复: 35
打印 上一主题 下一主题

[学习教程] 魔神游戏客户端应用程序结构

[复制链接]

2

主题

3

帖子

81

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
81
跳转到指定楼层
楼主
发表于 2015-1-18 21:18:54 | 显示全部楼层 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
一.游戏状态逻辑
在游戏中分为如下几个阶段:
1.取服务器IP状态
2.登入状态
3.制作都名单
4.选择人物
5.创建人物
6. 主游戏
   其中登入状态负责获取用户输入的 帐号和密码登录服务器;
选择人物状态负责获取用户选择的角色进入游戏;
创建人物状态负责提供用户编辑角色形象的界面;
主游戏逻辑状态负责处理游戏逻辑。
二.游戏应用程序框架类CD3DApplication
  1.   class CD3DApplication
  2.      该类负责游戏逻辑控制,游戏场景更新,在MVC模式中,是属于控制单元。
  3. 主要数据结构如下
  4.     D3DPRESENT_PARAMETERS m_d3dpp;         // 游戏显示参数
  5.     HWND              m_hWnd;              // 游戏主窗口句柄
  6.     LPDIRECT3D9       m_pD3D;              // d3d对象
  7.     LPDIRECT3DDEVICE9 m_pd3dDevice;        // d3d 设备
  8.     D3DSURFACE_DESC   m_d3dsdBackBuffer;   // d3d 设备后缓冲信息
  9.     DWORD             m_dwWindowStyle;     // windows窗口类型
  10.     // Variables for timing
  11.     FLOAT             m_fTime;             // 游戏当前时间
  12.     FLOAT             m_fFPS;              // 游戏桢率
  13.     // Overridable variables for the app
  14.     TCHAR*            m_strWindowTitle;    // 窗口标题
  15. fullscreen<span style="font-family: 宋体; font-size: 10.5pt; text-indent: 15.75pt; background-color: rgb(255, 255, 255); line-height: 1.5;"> </span>
复制代码
三.游戏逻辑状态更新流程以及相关CD3DApplication类函数
  1.        1.INT CD3DApplication::Run()
  2.            a. 在该函数中首先负责处理windows消息
  3.     BOOL bGotMsg;
  4.     MSG  msg;
  5.     msg.message = WM_NULL;
  6.     PeekMessage( &msg, NULL, 0U, 0U, PM_NOREMOVE );
  7.     while( WM_QUIT != msg.message  )
  8.     {
  9.             bGotMsg = PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE );
  10.         if( bGotMsg )
  11.         {
  12.         
  13. //            if( 0 == TranslateAccelerator( m_hWnd, hAccel, &msg ) )
  14.             {
  15.                 TranslateMessage( &msg );
  16.                 DispatchMessage( &msg );
  17.             }
  18.         }
  19. b. 然后调用Render3DEnvironment()函数更新游戏画面。
  20. 2.Render3DEnvironment()
  21.   a. 首先测试d3d设备是否有效
  22.        if( FAILED( hr = m_pd3dDevice->TestCooperativeLevel() ) )
  23.     {
  24.         // If the device was lost, do not render until we get it back
  25.         if( D3DERR_DEVICELOST == hr )
  26.             return S_OK;
  27.         if( D3DERR_DEVICENOTRESET == hr )
  28.         {
  29.    
  30.             if( m_bWindowed )
  31.             {
  32.                 D3DAdapterInfo* pAdapterInfo = &m_Adapters[m_dwAdapter];
  33.                 m_pD3D->GetAdapterDisplayMode( m_dwAdapter, &pAdapterInfo->d3ddmDesktop );
  34.                 m_d3dpp.BackBufferFormat = pAdapterInfo->d3ddmDesktop.Format;
  35.      }
  36.   b. 得到游戏的全局时间
  37.              FLOAT fAppTime        = DXUtil_Timer( TIMER_GETAPPTIME );
  38.   c. 更新场景
  39.    if( m_bFrameMoving || m_bSingleStep )
  40.              {
  41.                  // Store the time for the app
  42.                  m_fTime        = fAppTime;
  43.                  m_fElapsedTime = fElapsedAppTime;
  44.                  // Frame move the scene
  45.                  if( FAILED( hr = FrameMove() ) )
  46.                      return hr;
  47.                  m_bSingleStep = FALSE;
  48. }
  49.   d. 渲染场景
  50. // Render the scene as normal
  51.     if ( !m_bPauseRendering )
  52.     {
  53.         if( FAILED( hr = Render() ) )
  54.             return hr;
  55.     }
  56.     // Keep track of the frame count
  57.     static FLOAT fLastTime = 0.0f;
  58.     static DWORD dwFrames  = 0L;
  59.     FLOAT fTime = DXUtil_Timer( TIMER_GETABSOLUTETIME );
  60. ++dwFrames;<span style="font-family: 新宋体; font-size: 9pt; line-height: 1.5; text-indent: 17.25pt; background-color: rgb(255, 255, 255);"> </span>
复制代码
其中更新场景需要用到游戏时间参数,通过游戏参数更新游戏逻辑。 并且在该步凑负责游戏状态的逻辑控制。 首先处理纹理更新; 游戏的输入更新;游戏界面模块更新以及游戏的状态更新。

游客,如果您要查看本帖隐藏内容请回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-5-6 01:28

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表