📄 mechwarrior.cpp
字号:
// Framework_SkyCamera.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include "MechWarrior.h"
#include "Game.h"
#define MAX_LOADSTRING 100
#define new VNEW
// Global Variables:
HINSTANCE hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name
HWND g_hWnd;
CGame *g_pGame;
// Forward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
/** 消除动态内存
*/
void Cleanup();
/** 逻辑帧,处理所有游戏逻辑
@param
fElapsedTime 连续两个时间戳的差值
*/
void LogicFrame(float fElapsedTime);
/** 渲染帧,处理所有渲染
@param
fElapsedTime 连续两个时间戳的差值
*/
void RenderFrame(float fElapsedTime , float FPS);
float FPS=0.0f;
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
MSG msg;
HACCEL hAccelTable;
// Initialize global strings
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_MECHWARRIOR, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);
// Perform application initialization:
if (!InitInstance(hInstance, nCmdShow))
{
return FALSE;
}
hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_MECHWARRIOR);
// Main message loop:
ZeroMemory( &msg, sizeof(msg) );
while( msg.message!=WM_QUIT )
{
if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
else
{
// 两个时间戳之间的差值
static float fPreTime = static_cast<float>(timeGetTime());
float fCurrentTime = static_cast<float>(timeGetTime());
float fElapsedTime = (fCurrentTime - fPreTime)*0.001f;
FPS=60/fElapsedTime;
LogicFrame(fElapsedTime);
RenderFrame(fElapsedTime,FPS);
fPreTime = fCurrentTime;
}
}
Cleanup();
return (int) msg.wParam;
}
// Registers the window class.
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_MECHWARRIOR);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
return RegisterClassEx(&wcex);
}
// Saves instance handle and creates main window
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
hInst = hInstance; // Store instance handle in our global variable
g_hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
0, 0, 800, 600, NULL, NULL, hInstance, NULL);
if (!g_hWnd)
{
return FALSE;
}
g_pGame = new CGame;
if( g_pGame->Init( hInstance, g_hWnd ) == false )
{
return FALSE;
}
ShowWindow(g_hWnd, nCmdShow);
UpdateWindow(g_hWnd);
return TRUE;
}
// Processes messages for the main window.
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
void Cleanup()
{
SAFE_DELETE(g_pGame);
}
void LogicFrame(float fElapsedTime)
{
g_pGame->Update(fElapsedTime);
}
void RenderFrame(float fElapsedTime,float FPS)
{
g_pGame->Render(fElapsedTime,FPS);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -