编译文本配置文件从而得到可直接在游戏中使用的数据结构

来源:互联网 发布:弗莱彻级驱逐舰数据 编辑:程序博客网 时间:2024/06/08 04:01
编译的过程可以借助我们一直使用的编译器。

以对话框配置文件为例:


所需数据结构:

//type 宏定义 #define Dialog0#define Static1#define EditText2#define Button3#define CheckBox4#define RadioBotton5#define Image6#define non7struct control{int type;//类型 char text[16];//文本描述 int attr;//属性union{int rect[4];struct{int left;int bottom;int right;int top;};};};#define DIALOG_BEGIN(NumOfCtrl)\struct dialog{\controlm_dlg;\control m_ctrl[NumOfCtrl];\};\dialog _dlg = {#define DIALOG_END };

配置文件:

#include "readme.h"DIALOG_BEGIN(1){ Dialog,"对话框",0,0,0,10,10 },{ Dialog,"对话框",0,0,0,10,10 },DIALOG_END

编译好以后就可以从目标文件中将 .data 段提取出来,从而得到理想的资源文件。

在windows下目标文件格式为:coff

有时候数据段也需要进行重定位,即便这样也比自己来的轻松。