bool System_Initiate();
初始化所有硬件、软件的时候需要运行引擎并开启应用程序窗口。
bool CALL HGE_Impl::System_Initiate()
{
OSVERSIONINFO os_ver; //操作系统版本
SYSTEMTIME tm; //时间
MEMORYSTATUS mem_st; //内存分配情况
WNDCLASS winclass; //窗体
int width, height;
// Log system info
System_Log("HGE Started../n");
System_Log("HGE version: %X.%X", HGE_VERSION>>8, HGE_VERSION & 0xFF);
GetLocalTime(&tm); //获取当前时间
System_Log("Date: %02d.%02d.%d, %02d:%02d:%02d/n", tm.wDay, tm.wMonth, tm.wYear, tm.wHour, tm.wMinute, tm.wSecond);
System_Log("Application: %s",szWinTitle);
os_ver.dwOSVersionInfoSize=sizeof(os_ver); //初始化操作系统结构体
GetVersionEx(&os_ver); //获取当前操作系统版本
System_Log("OS: Windows %ld.%ld.%ld",os_ver.dwMajorVersion,os_ver.dwMinorVersion,os_ver.dwBuildNumber);
GlobalMemoryStatus(&mem_st); //获取当前内存使用情况
System_Log("Memory: %ldK total, %ldK free/n",mem_st.dwTotalPhys/1024L,mem_st.dwAvailPhys/1024L);
// 创建窗体 width=nScreenWidth + GetSystemMetrics(SM_CXFIXEDFRAME)*2; rectW.left=(GetSystemMetrics(SM_CXSCREEN)-width)/2; rectFS.left=0; if(hwndParent) if(bWindowed) ShowWindow(hwnd, SW_SHOW); // Init subsystems timeBeginPeriod(1); //多媒体时间,初始化时间间隔为1ms System_Log("Init done./n"); fTime=0.0f; // Show splash // Done return true;
// 注册窗体
winclass.style = CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
winclass.lpfnWndProc = WindowProc;
winclass.cbClsExtra = 0;
winclass.cbWndExtra = 0;
winclass.hInstance = hInstance;
winclass.hCursor = LoadCursor(NULL, IDC_ARROW);
winclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
winclass.lpszMenuName = NULL;
winclass.lpszClassName = WINDOW_CLASS_NAME;
if(szIcon) winclass.hIcon = LoadIcon(hInstance, szIcon);
else winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
if (!RegisterClass(&winclass)) {
_PostError("Can't register window class");
return false;
}
height=nScreenHeight + GetSystemMetrics(SM_CYFIXEDFRAME)*2 + GetSystemMetrics(SM_CYCAPTION);
rectW.top=(GetSystemMetrics(SM_CYSCREEN)-height)/2;
rectW.right=rectW.left+width;
rectW.bottom=rectW.top+height;
styleW=WS_POPUP|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX|WS_VISIBLE; //WS_OVERLAPPED | WS_SYSMENU | WS_MINIMIZEBOX;
rectFS.top=0;
rectFS.right=nScreenWidth;
rectFS.bottom=nScreenHeight;
styleFS=WS_POPUP|WS_VISIBLE; //WS_POPUP
{
rectW.left=0;
rectW.top=0;
rectW.right=nScreenWidth;
rectW.bottom=nScreenHeight;
styleW=WS_CHILD|WS_VISIBLE;
bWindowed=true;
}
hwnd = CreateWindowEx(0, WINDOW_CLASS_NAME, szWinTitle, styleW,
rectW.left, rectW.top, rectW.right-rectW.left, rectW.bottom-rectW.top,
hwndParent, NULL, hInstance, NULL);
else
hwnd = CreateWindowEx(WS_EX_TOPMOST, WINDOW_CLASS_NAME, szWinTitle, styleFS,
0, 0, 0, 0,
NULL, NULL, hInstance, NULL);
if (!hwnd)
{
_PostError("Can't create window");
return false;
}
Random_Seed(); //产生随机种子,默认为时间
_InitPowerStatus(); //更新当前电源属性
_InputInit(); //初始化键盘和鼠标值
if(!_GfxInit()) { System_Shutdown(); return false; } //初始化dx8
if(!_SoundInit()) { System_Shutdown(); return false; } //初始化多媒体库bass.dll
t0=t0fps=timeGetTime();
dt=cfps=0;
nFPS=0;
}