HGE学习随笔之一

 网页上提供了三个版本的HGE源码,既然是学习,那就从低版本开始吧.

下载解压后,很容易找到核心源码 hge16/src/core

根据文件名就很容易理解HGE的结构了

demo.cpp 明显是演示用的

graphics.cpp 图形显示.

ini.cpp 初始化

input.cpp  输入

random.cpp 随机数的生成

resource.cpp  资源

sound.cpp 声音

system.cpp 系统

timer.cpp 计时

一眼看上去就觉得结构很清晰.

这么多的.cpp,怎么才见到一个hge_impl.h呢?

原来这个头文件里这样写着 class HGE_Impl : public HGE,类里都是函数的声明.定义就都在上面的cpp里了.

上面的这个HGE类就是一个接口类,声明在hge16/include/hge.h中,里面写了所有的接口函数.

在core下还有两个文件夹,BASS和Zlib,前者是音效相关的,后者是个用来压缩和解压的库.

在 hge16/tutorials下提供了8个例子,在hge16/tutorials/precompiled下还提供了例子的可运行程序.

下面就是第一个例子:

 

/*
** Haaf's Game Engine 1.6
** Copyright (C) 2003-2006, Relish Games
** hge.relishgames.com
**
** hge_tut01 - Minimal HGE application
*/


#include 
"../../include/hge.h"

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;
}

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);

    
// Set our frame function
    hge->System_SetState(HGE_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().
    if(hge->System_Initiate())
    {
        
// Starts running FrameFunc().
        
// Note that the execution "stops" here
        
// until "true" is returned from FrameFunc().
        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;
}

 

从运行的结果看,这就是一个显示一个简单的logo,然后按Esc或者程序右上角的X就可以退出.

首先就是创建一个接口对象

hge = hgeCreate(HGE_VERSION);

下面就是开始设置参数,然后初始化,接着就可以start了.当程序收到退出命令以后释放所有的资源.

最后就是hge->Release()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值