/***************************************************************************************
** File: WorkLog
** Desc: record recent work
**
**
****************************************************************************************/
2006.8.30
预计最近会继续研究HGE引擎。HGE里的Resource manager技术,我觉得我一直想研究的"id式的文件管理"技术相似。----只需要改动数据文件,游戏程序不需要做任何修改,就可以把新的数据包当作新的游戏运行起来。翻译了篇大概的文章:
以下资料翻译自:[url]http://gpwiki.org/index.php/HGE:Tutorials:Resource_Manager[/url]
Resource Manager
The resource manager is a way of defining textures, sprites, sounds, and other items that your application makes use of. hgeresourceManager is an HGE helper class that automates creation of complex resource objects and their management in memory.
资源管理器是一种定义纹理,精灵,声音,以及其他被你的应用程序使用的资源的方法。
hgeResourceManager是HGE的扩展类,它使得创建各种复杂的资源以及管理各种资源自动化。
Resource Script files (资源脚本文件)
Resource script files are used with hgeResourceManager helper class to define complex resources. They are just plain text files containing resource definitions. A resource script file consists of commands separated by whitespace characters ('/t', '/n', '/r' or ' '). If a semicolon (';') is encountered, the rest of the line is treated as a comment and is not parsed. All the commands and names are case sensitive.
资源脚本文件和hgeResourceManager扩展类一起使用来定义复杂的资源。资源脚本文件是包含了资源定义的纯文本文件。一个资源脚本文件由被空格字符('/t', '/n', '/r' 或 ' ' )分开的命令组成。而分号(“;”)被用做注释,它后面的一行字符都将被认为是注释,而不被引擎解释。所有的命令以及名字都是大小写敏感的。
The command formate is:
命令格式为:
ResourceType ResourceName [ : BaseResourceName ]
{
Parameter1=Value1
Parameter2=Value2
...
ParameterN=ValueN
}
Example: specifying a texture
一个指定了纹理的例子:
Texture myTexture
{
file=picture1.png
}
For now, just create a blank text file named resource.res and place it in the same directory as the main.cpp file. Using the Resource Manager
现在创建一个名为resource.。res的空白文件,然后写入以上内容,并把这个文件放到与main.cpp相同目录下。使用资源管理器:
To use the resource manager, include the hgeresource.h file and declare myRes, which will be used when we need to access our resources:
要使用资源管理器,需要包含 hgeresource.h 文件,并定义myRes对象:
#include <hgeresource.h>
hgeResourceManager *myRes;
Inside WinMain(), but before the hge->System_Start() call, we initialize myRes with the name of the resource file we will be using.
在WinMain()函数里,在 hge->System_Start()前我们用刚才写的那个资源脚本文件初始化 myRes 对象。
myRes = new hgeResourceManager("resource.res");
程序退出时删除myRes对象即可。
我的总结:
例如要使用纹理,你可以这样定义:
Texture back
{
filename=back.jpg
}
把这个定义放到一个res文件里,例如:resource.res。然后在程序里可以这样使用这个纹理:
HTEXTURE backTx;
hgeResourceManager *resMgr = new hgeResourceManager( "resource.res" );
backTx = resMgr->GetTexture( “back” );
同理,要使用精灵,就可以这样做:
在res文件了里
Texture sheet
{
filename=sheet.png
}
Sprite playerSprite
{
texture=sheet
rect=0, 0, 64, 64
}
因为sprite 需要为其指定纹理,所以其参数texture=sheet,sheet是res文件中之前定义的纹理。
然后在程序里:
hgeSprite *sprite ;
hgeResourceManager *resMgr = new hgeResourceManager( “resource.res”);
sprite = resMgr->GetSprite( “playerSprite” );
然后就可以完全地使用sprite了。
2006.8.31
以下的语句居然是正确的:
char *p ;
p = "abcd";
p = "abcdef";
就因为这几句代码,让我丢大了脸。不过静下心来想想,其正确性也不是没理由的:
对于代码里的字符串,例如上面的"abcd","abcdef",编译器在编译时就会开辟内存来保存这些字符串----事实上它们是属于const string。你可以写个简单的程序,然后让编译器输出汇编代码看看。当程序运行时,p只是换了地址,当p= "abcd";时,p就指向内存中存放abcd的位置,这样当然正确。
2006.9.1
因为我把Feeding Frenzy也发布到了国外的网站上 ---感觉相比较而言,外国人给了我更多有用的意见。
今天收到一封外国人的邮件,从邮件内容来看,他的母语估计也不是英语。邮件内容如下:
“
Your source code will be very much appreciated. :) I'm very interested to compare hge and popcap code...
(Sorry for my weak english)
”
言下之意,他似乎有popcap公司出的Feeding Frenzy的代码,汗。
关于《游戏编程精粹3》的游戏调度器:
这一节的内容看了几次了,还是看不大明白。今天看着看着,有点累,于是靠在椅子上闭了下眼睛,结果我就那么睡着了。迷迷糊糊的,我又爬上床去睡觉,好象还关门关音响来着。在床上,一不小心又醒了,于是又爬下来。当时觉得这个世界太恍惚了,我都记不得自己是怎么爬上床的。
看了几次关于调度器的代码,不是很明白,但是大致可以了解个意思:游戏里会发生的事情,当做任务task来看待,然后依靠抽象类ITask来实现统一控制,调度器会根据其类型来在合适的时候调用其具体的Exectute方法。
事件类型似乎有三种:渲染事件,基于帧的事件,基于时间的事件。
感觉而言,这种实现机制有点象个操作系统。游戏里建立的各种任务就是一个应用程序,或者叫进程,然后OS会自动管理各种Process.
2006.9.2
早上起来,收到第二封外国人邮件:
“I would love to see the source, and I have been thinking about picking up and learning HGE myself. Unfortunately right now I can even look at your game, since you used RAR to compress it and many people like myself stuck at work cannot use RAR. Could you send me the source and also a ZIP'ped copy instead of the Rar'd version?
”
看起来,外国人真的软件正版意识要高很多!中国人真悲哀,满世界的盗版破解版注册机!
看他邮件服务器是MSN的,于是我加了他MSN,粗略地聊了几句,这是第一次在MSN上和外国人说话,之前在IRC上聊,但是聊的人都不是程序员:
“
Kevin Lynx 说:
Hello , I am the author of Feeding Frenzy.
qwst_cfelts 说:
Cool.. just bear with my occasional silence, i am at work on on the phone most of the time.
qwst_cfelts 说:
mainly, i was looking at picking up the HGE engine to experiment with, and wanted to see source code for a game done in this. Im not worried about the zip now, since I will be home in less than 2 hours
Kevin Lynx 说:
ok . and now I am uploading the game compressing with ZIP to the http://www.rapidshare.de/
qwst_cfelts 说:
IM Administrator:
This message has been blocked by the recipient due to risk.
Kevin Lynx 说:
...You mean you can read the source compressing with WinRAR ?
qwst_cfelts 说:
i can at home, yes
qwst_cfelts 说:
Since I am off work in 2 hours i will just look at it there. if you had emailed it earlier, a zip would have been easier
Kevin Lynx 说:
en . the source is only 87kb, and the game is much
Kevin Lynx 说:
bigger.8M.
qwst_cfelts 说:
I can download the game itself at home. the source would be nice to look at while I am here .. but it would have to be as a zip.. if you already have it as a rar, you can just email that and I will look at it when I get home
Kevin Lynx 说:
Hoho~a zip file is good and easy to compress .I will send it to you now.
qwst_cfelts 说:
ok . i appreciate it a lot.
qwst_cfelts 说:
how was HGE to use? easy to learn and all?
Kevin Lynx 说:
It doesnot matter.
Kevin Lynx 说:
Yes, as a SDK,it is very to learn
Kevin Lynx 说:
Here is the main page :http://hge.relishgames.com/
qwst_cfelts 说:
IM Administrator:
This message has been blocked by the recipient due to risk.
qwst_cfelt* 说:
**cellent. and thank you for the source. I got it and can open it fine here. Now time to dig in and see how hge looks and works.
Kevin Lynx 说:
Ha,that's good. And I must go to do something now . I think we can talk next time .See you .
qwst_cfelts 说:
have a good day
”
查看其档案,居然32岁了,头发留的跟Romero一样长,做计算机相关行业,住美国哪个州,离婚,一个儿子一个女儿。[em]e19[/em]
今天ACM测试,昨天下午我是第一次去上课,第二次去教室。开始我不是很自信,总觉得自己算法不强,结果一上午不小心就做出3道题---总共4道--其他人下午还要继续做,如果我中午能想出第一题,我下午也去。
哈哈,还是要自信点。
15:40
花了3个小时,终于把最后一道题给做出来了。用了链表,简单地模拟加法运算。挖哈哈哈,我是第一个做出来的呢。信心一下子增加不少啊。
这几天上ACM的老师恰好是我下学期C++的老师,我昨天下午就琢磨着怎么先跟他打好关系,下学期好容易逃课。然后我给他看了我最近做的Feeding Frenzy,再不小心把我在学校里做项目的事透露出来。哈哈,我走的时候他还特意问我名字呢。
今天表现也不错,这下子我更有理由逃课了。不过这个老师显然没上学期那个C语言老师开明,下午还特地给我说下学期的规矩。汗~~还好,后来我厚颜无耻地跟他拉了下关系,最终协议:下学期可以不去上课,可以不交作业,但是平时分他只给我一般的分数。----开始还让我到院长那去开假条,挖靠。
今天是个大胜利也!----除了鼠标坏了键盘不好使了打QUAKE有点恶心了~~~
2006.9.3
9月分计划:
1.游戏中的调度器,目前已经进入研究后期。
2.游戏中的GUI设计,打算做一套简单的库出来,目前正准备开始。
3.阅读HGE引擎代码,为10月分准备写的引擎做准备。
4.闲暇时间需要准备的事:a.ACM算法;b.设计模式;c.STL.