前面已经具备了设备层(DEVICE)显示层(SwapChain)现在就可以尝试测试显示的结果了:
添加个"SpliteDevice.h"的头文件,内容如下(注意这里也保证了语法的无关性和可读性):
很大一批程序员愿意使用gMyRenderDeviceAbstract这样的命名方式可能它根本就不想自己读懂它!
还比如#define abc(a,c){ a=c; }这种定义,程序员的智商就不能再低点嘛?这些在即使是NV的官方范例中也屡见不鲜!
一个类的名称描述应该是尽量贴近它所带来的结果。
struct SpliteDevice
{
Device device; //设备
SwapChain chain;//缓冲区
int sample,Startframe;//AA
float frameRate;//祯速率
InputState Input;//输入
void Create(Device dev,HWND hwnd,int sampleCount)
{
frameRate = 60;
sample = sampleCount;
device=dev;
chain.Create(dev,hwnd,sample);
Input.viewport=Viewport(chain.desc.Width,chain.desc.Height);//把窗口信息放在输入中便于其他下属类的访问Device.GetViewport()并不总是正确的是DX11的典型BUG
Input.hit.Zero();
LoadContent();
}
virtual void LoadContent(){}
virtual void UnLoadContent(){}
virtual void HandleInput(){}//抽象的空动作为它的下属类使用
virtual void Update(float gameTime){}
virtual void Resize(){ }
virtual void Draw(){}//绘画的抽象
void Dispose()
{
chain.Dispose();
UnLoadContent();
}
void Clear(Vector4 c) { chain.Clear(c); }
void Render()
{
DWORD tc = timeGetTime();
if ((tc - Startframe) > (1000 / frameRate))
{
Startframe = tc;
Update(1/frameRate);
Draw();
chain.Present();
}
}
//如果你真的是用游戏手柄或其他触摸设备输入的话也不必更改任何类的设定把InputState的类中增加个"Other。"的输入变量即可。
int HandleMsg(int uMsg,WPARAM wParam,LPARAM lParam)//记录所有的输入信息{
switch (uMsg)
{
case WM_CLOSE:
Dispose();
return 0;
case WM_KEYDOWN:
Input.mkeys[wParam] = true;
HandleInput();
return 0;
case WM_KEYUP:
Input.mkeys[wParam] = false;
HandleInput();
return 0;
// case WM_EXITSIZEMOVE:
case WM_SIZE:
if(wParam==SIZE_MAXIMIZED||wParam== SIZE_RESTORED)
{ chain.Resize();
Input.viewport=Viewport(chain.desc.Width,chain.desc.Height);
Resize();}
return 0;
case WM_MOUSEWHEEL:
case WM_LBUTTONUP:
case WM_MBUTTONUP:
case WM_RBUTTONUP:
case WM_LBUTTONDOWN:
case WM_MBUTTONDOWN:
case WM_RBUTTONDOWN:
case WM_MOUSEMOVE:
Input.state=uMsg;
int xPos =Input.X= (short)LOWORD(lParam);
int yPos =Input.Y= (short)HIWORD(lParam);
int nMouseButtonState = (short)LOWORD(wParam);
Input.LM = ((nMouseButtonState & MK_LBUTTON) != 0);
Input.RM = ((nMouseButtonState & MK_RBUTTON) != 0);
Input.MM = ((nMouseButtonState & MK_MBUTTON) != 0);
HandleInput();
if (uMsg == WM_MOUSEWHEEL)
{
int scroll =(short)HIWORD(wParam);
if (scroll != 0)
{
Input.WheelDelta = scroll/120;
HandleInput();
Input.WheelDelta =0;
}
scroll%=120;
}
Input.PX = xPos;Input.PY = yPos;
return 0;
break;
}
return 0;
}