HGE学习随笔之二

  

我也是看着写着,就当是自己记录自己的学习过程.

 今天看的是hge16/src/core/system.cpp

#include  " hge_impl.h "


#define  LOWORDINT(n) ((int)((signed short)(LOWORD(n))))
#define  HIWORDINT(n) ((int)((signed short)(HIWORD(n))))
//定义应该很容易就理解吧
const   char   * WINDOW_CLASS_NAME  =   " HGE__WNDCLASS " ;      //定义一个字符串常量.
LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
//这个就不用废话了

int             nRef = 0 ;
//记录接口对象创建个数
HGE_Impl
*     pHGE = 0 ;
//接口指针
BOOL APIENTRY DllMain(HANDLE, DWORD, LPVOID)  //这个不明白
{
    
return  TRUE;
}
HGE
*  CALL hgeCreate( int  ver)    //根据版本创建接口对象指针
{
 
if (ver == HGE_VERSION)  return  (HGE * )HGE_Impl::_Interface_Get();
 
else   return   0 ;
}
HGE_Impl
*  HGE_Impl::_Interface_Get()    //new一个HGE类对象,记录个数.
{
 
if ( ! pHGE) pHGE = new  HGE_Impl();
 nRef
++ ;
 
return  pHGE;
}
void  CALL HGE_Impl::Release()   //释放HGE类对象,当记录个数为0要执行system_shutdown和移除资源
{
 nRef
-- ;
 
if ( ! nRef)
 {
  
if (pHGE -> hwnd) pHGE -> System_Shutdown();
  Resource_RemoveAllPacks();
  delete pHGE;
  pHGE
= 0 ;
 }
}

 

bool  CALL HGE_Impl::System_Initiate()     //初始化, 创建窗口,调整尺寸
{
    OSVERSIONINFO    os_ver;        //
操作系统的信息
    SYSTEMTIME        tm;                    //系统时间    
    MEMORYSTATUS    mem_st;        // 内存状态
    WNDCLASS        winclass;            // 窗口类
     int                 width, height;

    System_Log(
" HGE Started.. " );         // log

    System_Log(
" HGE version: %X.%X " , HGE_VERSION >> 8 , HGE_VERSION  &   0xFF );
    GetLocalTime(
& tm);             // 得到时间
    System_Log( " Date: %02d.%02d.%d, %02d:%02d:%02d " , 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 " ,mem_st.dwTotalPhys / 1024L ,mem_st.dwAvailPhys / 1024L );
    
    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 ;
    }
    
    width
= nScreenWidth  +  GetSystemMetrics(SM_CXFIXEDFRAME) * 2 ;
    height
= nScreenHeight  +  GetSystemMetrics(SM_CYFIXEDFRAME) * 2   +  GetSystemMetrics(SM_CYCAPTION);

    rectW.left
= (GetSystemMetrics(SM_CXSCREEN) - width) / 2 ;
    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.left
= 0 ;
    rectFS.top
= 0 ;
    rectFS.right
= nScreenWidth;
    rectFS.bottom
= nScreenHeight;
    styleFS
= WS_POPUP | WS_VISIBLE;  // WS_POPUP

    
if (hwndParent)
    {
        rectW.left
= 0 ;
        rectW.top
= 0 ;
        rectW.right
= nScreenWidth;
        rectW.bottom
= nScreenHeight;
        styleW
= WS_CHILD | WS_VISIBLE; 
        bWindowed
= true ;
    }

    
if (bWindowed)
        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 ;
    }

    ShowWindow(hwnd, SW_SHOW);    
// 创建窗口以及显示窗口

    timeBeginPeriod(
1 );        
    Random_Seed();
    
if ( ! _GfxInit()) { System_Shutdown();  return   false ; }         // 初始化图形
     if ( ! _SoundInit()) { System_Shutdown();  return   false ; }         // 初始化声音

    System_Log(
" Init done. " );

    fTime
= 0.0f ;
    t0
= t0fps = timeGetTime();
    dt
= cfps = 0 ;
    nFPS
= 0 ;

    #ifdef DEMO    

    
bool             ( * func)();
    
bool             ( * rfunc)();
    HWND            hwndTmp;

    
if ( ~ pHGE -> nDMO  !=   ~ 0xFACE0FF //  Commercial version magic
    {
        Sleep(
200 );
        func
= ( bool ( * )())pHGE -> System_GetStateFunc(HGE_FRAMEFUNC);
        rfunc
= ( bool ( * )())pHGE -> System_GetStateFunc(HGE_RENDERFUNC);
        hwndTmp
= hwndParent; hwndParent = 0 ;
        pHGE
-> System_SetStateFunc(HGE_FRAMEFUNC, DFrame);
        pHGE
-> System_SetStateFunc(HGE_RENDERFUNC,  0 );
        DInit();
        pHGE
-> System_Start();
        DDone();
        hwndParent
= hwndTmp;
        pHGE
-> System_SetStateFunc(HGE_FRAMEFUNC, func);
        pHGE
-> System_SetStateFunc(HGE_RENDERFUNC, rfunc);
    }

    
#endif

    
return   true ;
}

 

 

void  CALL HGE_Impl::System_Shutdown()     //系统关闭
{
    System_Log(
" Finishing.. " );

    timeEndPeriod(
1 );
    _ClearQueue();        //清除队列
    _SoundDone();        //声音
    _GfxDone();             
//图像
    
if (hwnd)
    {
        
// ShowWindow(hwnd, SW_HIDE);
        
// SetWindowLong(hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_TOOLWINDOW);
        
// ShowWindow(hwnd, SW_SHOW);
        DestroyWindow(hwnd);
        hwnd
= 0 ;
    }
    
if (hInstance) UnregisterClass(WINDOW_CLASS_NAME, hInstance); //注销窗口类

    System_Log(
" The End. " );
}

这里只是先看system.cpp里的函数,有涉及到其他文件的函数先略过.

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值