游戏开发论坛

 找回密码
 立即注册
搜索
查看: 1231|回复: 0

请各位大哥帮我看看下面几个 HGE 问题(很难),谢谢!

[复制链接]

37

主题

67

帖子

73

积分

注册会员

Rank: 2

积分
73
发表于 2007-5-7 15:02:00 | 显示全部楼层 |阅读模式
#include "windows.h"
#include "include\hge.h"
#pragma  comment(lib,"lib\\vc\\hge.lib");         //库
#pragma  comment(lib,"lib\\vc\\hgehelp.lib");     //库


int i;

HGE *hge = 0;

// This function will be called by HGE once per frame.
// Put your game loop code here. In this example we
// just check whether ESC key has been pressed.
bool FrameFunc()
{
        // By returning "true" we tell HGE
        // to stop running the application.
        if (hge->Input_GetKeyState(HGEK_ESCAPE)) return true;

        // Continue execution
        return false;
}

LONG        g_lOldProc = NULL;       //全局变量

HRESULT MyWndProc( HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam )
{
        HDC hdc;
        PAINTSTRUCT ps;
        RECT rect;
        char temp[128];
        switch( nMsg )
        {
     case WM_CREATE:
               
                break;

         case        WM_RBUTTONDOWN:
                {
                        MessageBox( hWnd, "你在我身上点了右键,你想干嘛?", "测试", 0 );
                }
                break;
    case WM_TIMER:
                i++;
                if (i%2)
                {
                 hdc = GetDC(hWnd);
        // sprintf(temp,"x: %d , y: %d",50,50);
         //TextOut(hdc,100,100,1,1);
                // ReleaseDC(hWnd,hdc);
                }
                else
                {
          hdc = GetDC(hWnd);
                 // MessageBox(hWnd,0,0,0);
        // sprintf(temp,"x: %d , y: %d",60,60);
         //TextOut(hdc,100,100,"99","99");
                // ReleaseDC(hWnd,hdc);
                }
                 break ;
        //        在这里, 作你想做的事情~~~~~~
        }
        if( g_lOldProc != NULL )
                return CallWindowProc( (WNDPROC)g_lOldProc, hWnd, nMsg, wParam, lParam );        //        调用原来的窗口处理函数
        else
                return DefWindowProc( hWnd, nMsg, wParam, lParam );
}

int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
        // Here we use global pointer to HGE interface.
        // Instead you may use hgeCreate() every
        // time you need access to HGE. Just be sure to
        // have a corresponding hge->Release()
        // for each call to hgeCreate()
        hge = hgeCreate(HGE_VERSION);      //创建 HGE

        // Set our frame function
        hge->System_SetState(HGE_FRAMEFUNC, FrameFunc);  //回调函数 FrameFunc

        // Set the window title
        hge->System_SetState(HGE_TITLE, "HGE Tutorial 01 - Minimal HGE application");
       
        // Run in windowed mode
        // Default window size is 800x600
        hge->System_SetState(HGE_WINDOWED, true);

        // Don't use BASS for sound
        hge->System_SetState(HGE_USESOUND, false);

        // Tries to initiate HGE with the states set.
        // If something goes wrong, "false" is returned
        // and more specific description of what have
        // happened can be read with System_GetErrorMessage().

   
        i=0;
        if(hge->System_Initiate())
        {
                // Starts running FrameFunc().
                // Note that the execution "stops" here
                // until "true" is returned from FrameFunc().
                HWND hWnd = hge->System_GetState( HGE_HWND );                //        获得hge的窗口句柄

                if(hWnd != NULL )
                {
            SetTimer(hWnd,1,1000,NULL);
                        g_lOldProc = SetWindowLong( hWnd, GWL_WNDPROC, (LONG)MyWndProc );        //        设置窗口处理函数为你自己定义的, 并且保存原来的窗口处理函数
                }
                hge->System_Start();
        }
        else
        {       
                // If HGE initialization failed show error message
                MessageBox(NULL, hge->System_GetErrorMessage(), "Error", MB_OK | MB_ICONERROR | MB_APPLMODAL);
        }

        // Now ESC has been pressed or the user
        // has closed the window by other means.

        // Restore video mode and free
        // all allocated resources
        hge->System_Shutdown();

        // Release the HGE interface.
        // If there are no more references,
        // the HGE object will be deleted.
        hge->Release();

        return 0;
}


问题1:
g_lOldProc = SetWindowLong( hWnd, GWL_WNDPROC, (LONG)MyWndProc );
是不是说明 MyWndProc 就是回调函数?

那么 FrameFunc 也还是回调函数,是吗?

问题2:
hge->System_Shutdown();

执行 这句话后,
程序应该在 System_Shutdown 的 for 循环里转啊?

而在 System_Shutdown
只定义回调函数 FrameFunc
没有定义  MyWndProc ,那么 什么时候 会运行到 MyWndProc 呢?

问题3:
如果 FrameFunc 和  MyWndProc 都是回调函数
那么到底是运行哪个呢?
或者是先运行哪个呢?

问题4:
bool CALL HGE_Impl::System_Start()
{
        MSG                msg;
        POINT        pt;
        RECT        rc;

        if(!hwnd)
        {
                _PostError("System_Start: System_Initiate wasn't called");
                return false;
        }

        if(!procFrameFunc) {
                _PostError("System_Start: No frame function defined");
                return false;
        }

        bActive=true;

        for(;;)
        {
               
                if(!hwndParent)
                {
                        if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
                        {
                                if (msg.message == WM_QUIT)        break;
                                // TranslateMessage(&msg);
                                DispatchMessage(&msg);
                                continue;
                        }
                }

                GetCursorPos(&pt);
                GetClientRect(hwnd, &rc);
                MapWindowPoints(hwnd, NULL, (LPPOINT)&rc, 2);
                if(bCaptured || (PtInRect(&rc, pt) && WindowFromPoint(pt)==hwnd)) bMouseOver=true;
                else bMouseOver=false;

                if(bActive || bDontSuspend) {
                        do { dt=timeGetTime() - t0; } while(dt < 1);
                        if(dt >= nFixedDelta)
                        {
                                fDeltaTime=dt/1000.0f;
                                if(fDeltaTime > 0.2f)
                                {
                                        if(nFixedDelta) fDeltaTime=nFixedDelta/1000.0f;
                                        else fDeltaTime=0.01f;
                                }
                                fTime+=fDeltaTime;

                                t0=timeGetTime();
                                if(t0-t0fps < 1000) cfps++;
                                else {nFPS=cfps; cfps=0; t0fps=t0;}
                                if(procFrameFunc()) break;
                                if(procRenderFunc) procRenderFunc();
                                if(hwndParent) break;
                                _ClearQueue();
                                if(!bWindowed && nHGEFPS==HGEFPS_VSYNC) Sleep(1);
                        }
                        else { if(nFixedDelta && dt+3 < nFixedDelta) Sleep(1); }
                }
                else Sleep(1);
        }
        _ClearQueue();
        bActive=false;
        return true;
}

这里是 先运行  FrameFunc() 就运行 RenderFunc

现在是什么时候运行 RenderFunc 呢?

谢谢!
[em3] [em3] [em17] [em20] [em20] [em10] [em6] [em5]
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2026-1-26 13:08

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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