以前在codeproject上看到過(guò)一篇關(guān)于內(nèi)存池的文章(http://www.codeproject.com/KB/cpp/MemoryPool.aspx)
下載下來(lái)試了試,感覺(jué)有點(diǎn)問(wèn)題
想給引擎加入內(nèi)存池,考慮到當(dāng)前業(yè)余時(shí)間在看Loki
就索性使用其SmallObject了
對(duì)于內(nèi)存池當(dāng)然要求之一那就是速度
其次對(duì)我來(lái)說(shuō)我比較關(guān)系以下的這類(lèi)問(wèn)題
一句話(huà)概括就是
Base* ptr = new SubClass;
索性我就根據(jù)Loki庫(kù)和Boost的Object_Pool
設(shè)計(jì)了如下的引擎內(nèi)存池(當(dāng)然問(wèn)題還很多以后慢慢修改)
#ifdef LOKI_EXT_LIB
#include <GEngine/Loki/Loki.hpp>
#else
#error 需要包含Loki庫(kù)
#endif
namespace core
{
////////////////////////////////////////////////////////////
/// 定義蓋莫引擎2.1.2內(nèi)存池對(duì)象
////////////////////////////////////////////////////////////
struct MemoryPool
{
public:
////////////////////////////////////////////////////////
/// 獲取,釋放指定大小的內(nèi)存
////////////////////////////////////////////////////////
template<class T>
static T* Malloc(size_t size)
{
return (T*)MEMORY_POOL.Allocate(size,false);
}
template<class T>
static void Free(T* ptr,size_t size)
{
MEMORY_POOL.Deallocate(ptr,size);
}
////////////////////////////////////////////////////////
/// 構(gòu)造無(wú)參數(shù)的對(duì)象類(lèi)型并返回指針
////////////////////////////////////////////////////////
template<class T>
static T* Construct()
{
void* ptr = MEMORY_POOL.Allocate(OBJECT_SIZE(T),false);
if(ptr == NULL)
return NULL;
new(ptr)T();
return (T*)ptr;
}
////////////////////////////////////////////////////////
/// 構(gòu)造帶有1個(gè)參數(shù)的對(duì)象類(lèi)型并返回指針
////////////////////////////////////////////////////////
template<class T,class P1>
static T* Construct(const P1 &p1)
{
void* ptr = MEMORY_POOL.Allocate(OBJECT_SIZE(T),false);
if(ptr == NULL)
return NULL;
new(ptr)T(p1);
return (T*)ptr;
}
////////////////////////////////////////////////////////
/// 構(gòu)造帶有2個(gè)參數(shù)的對(duì)象類(lèi)型并返回指針
////////////////////////////////////////////////////////
template<class T,class P1,class P2>
static T* Construct(const P1 &p1,const P2 &p2)
{
void* ptr = MEMORY_POOL.Allocate(OBJECT_SIZE(T),false);
if(ptr == NULL)
return NULL;
new(ptr)T(p1,p2);
return (T*)ptr;
}
////////////////////////////////////////////////////////
/// 構(gòu)造帶有3個(gè)參數(shù)的對(duì)象類(lèi)型并返回指針
////////////////////////////////////////////////////////
template<class T,class P1,class P2,class P3>
static T* Construct(const P1 &p1,const P2 &p2,const P3 &p3)
{
void* ptr = MEMORY_POOL.Allocate(OBJECT_SIZE(T),false);
if(ptr == NULL)
return NULL;
new(ptr)T(p1,p2,p3);
return (T*)ptr;
}
////////////////////////////////////////////////////////
/// 構(gòu)造帶有4個(gè)參數(shù)的對(duì)象類(lèi)型并返回指針
////////////////////////////////////////////////////////
template<class T,class P1,class P2,class P3,class P4>
static T* Construct(const P1 &p1,const P2 &p2,const P3 &p3,const P4 &p4)
{
void* ptr = MEMORY_POOL.Allocate(OBJECT_SIZE(T),false);
if(ptr == NULL)
return NULL;
new(ptr)T(p1,p2,p3,p4);
return (T*)ptr;
}
////////////////////////////////////////////////////////
/// 構(gòu)造帶有5個(gè)參數(shù)的對(duì)象類(lèi)型并返回指針
////////////////////////////////////////////////////////
template<class T,class P1,class P2,class P3,class P4,class P5>
static T* Construct(const P1 &p1,const P2 &p2,const P3 &p3,const P4 &p4,const P5 &p5)
{
void* ptr = MEMORY_POOL.Allocate(OBJECT_SIZE(T),false);
if(ptr == NULL)
return NULL;
new(ptr)T(p1,p2,p3,p4,p5);
return (T*)ptr;
}
////////////////////////////////////////////////////////
/// 給定對(duì)象的析構(gòu)(size為對(duì)象大小)
////////////////////////////////////////////////////////
template<class T>
static void Destruct(T* ptr, size_t size)
{
if(ptr == NULL || size <= 0)
return;
ptr->~T();
MEMORY_POOL.Deallocate(ptr,size);
}
////////////////////////////////////////////////////////
/// 獲取可分配的最大對(duì)象大小
////////////////////////////////////////////////////////
static int GetMaxObjSize()
{
return MEMORY_POOL.GetMaxObjectSize();
}
////////////////////////////////////////////////////////
/// 獲取字節(jié)對(duì)齊字節(jié)數(shù)
////////////////////////////////////////////////////////
static int GetAlignment()
{
return MEMORY_POOL.GetAlignment();
}
};
靜態(tài)的Malloc和Free是分配和釋放原生態(tài)的內(nèi)存
而Construct,Destruct則是構(gòu)造和析構(gòu)對(duì)象形式的內(nèi)存
這里提供了6個(gè)版本的Construct函數(shù)
分別對(duì)應(yīng)0-5個(gè)構(gòu)造函數(shù)參數(shù)
記得以前遇到的一個(gè)問(wèn)題
那就是假如有一個(gè)對(duì)象 她沒(méi)有默認(rèn)構(gòu)造函數(shù)(只有帶參數(shù)構(gòu)造函數(shù))
如果現(xiàn)在需要分配N(xiāo)個(gè)她該如何操作?
那就是placement new 了
發(fā)布最新版本的蓋莫游戲引擎2.1.1
首先說(shuō)明當(dāng)前內(nèi)置demo列表:
1.字體測(cè)試 +
2.圖形測(cè)試 +
3.粒子測(cè)試-噴泉測(cè)試 +
4.音頻測(cè)試 +
5.輸入輸出測(cè)試 +
6.引擎框架 +
7.3d音效測(cè)試 +
8.視頻播放 +
9.BoingBall +
10.粒子火焰測(cè)試 +
11.立方體繪制測(cè)試 +
12.隧道進(jìn)度仿真 +
13.天空盒測(cè)試 +
14.天空面測(cè)試 +
15.天空頂測(cè)試 +
16.地形測(cè)試 +
17.物理測(cè)試1 +
18.物理測(cè)試2 +
19.物理測(cè)試1 +
20.物理測(cè)試2 +
21.md2模型測(cè)試 +
22.3ds模型測(cè)試 +
23.線程渲染 +
24.光源測(cè)試 +
25.立方體紋理 +
26.球面紋理 +
27.多線程資源載入 +
.....
下面是下次修改要點(diǎn)
2.1.2版本計(jì)劃加入或更新功能
1.音頻引擎(內(nèi)置蓋莫音頻引擎1.2.8版本)
1.支持audio capture
2.支持midi音樂(lè)格式
2.
文件系統(tǒng) 1.對(duì)7z壓縮格式的支持
2.支持
xml配置文件
3.插件系統(tǒng)
1.引入插件系統(tǒng)
4.GLSL
1.對(duì)GLSL的支持
5.渲染引擎
1.對(duì)各類(lèi)廣告牌的支持
2.支持水面渲染
3.支持動(dòng)態(tài)天空
4.支持lod地形
5.支持md3模型
6.支持環(huán)境映射
7.加入渲染到紋理
8.加入體積霧
9.支持深度紋理
10.支持壓縮紋理
11.支持屏幕圖形捕獲
12.支持投影紋理
6.內(nèi)存池
1.初步使用內(nèi)存池(考慮Loki)
7.數(shù)學(xué)庫(kù)
1.完善數(shù)學(xué)庫(kù)并作全面的優(yōu)化處理
8.多線程
1.加入引擎專(zhuān)用多線程計(jì)算器(用于求值計(jì)算)
9.框架
1.修改InitDevice函數(shù)減少參數(shù)個(gè)數(shù)
9.其它
1.加入
GEngine水印
2.支持設(shè)置,加載游標(biāo)圖形(內(nèi)置3種常見(jiàn)游標(biāo)形狀圖標(biāo))
3.加入一個(gè)新3D仿真程序
4.others
下面是蓋莫QQ群列表:
蓋莫QQ群列表
1.蓋莫3群 超級(jí)群-高端技術(shù):81836528
2.蓋莫0群 引擎討論:20997748
3.蓋莫玩家交流群:23376710
4.蓋莫新人集中營(yíng):49749954
5.蓋莫
游戲開(kāi)發(fā)群:58970936
6.其他蓋莫非技術(shù)群列表:...
再者是當(dāng)前版本編譯
當(dāng)前編譯版本為win32下的gcc版本
可使用codeblock,devc++設(shè)計(jì)游戲
下面是當(dāng)前功能
蓋莫游戲引擎2.1.1功能描述
1.音頻引擎:內(nèi)置蓋莫音頻引擎1.1.2版本
支持wav,mp3,
ogg3種音頻格式,
基于流式多線程音頻播放
真3d音效
支持低通,次級(jí)音效(本模塊可獨(dú)立出售)
2.視頻系統(tǒng):支持mp4,mpg等視頻格式(可替換為vlc模塊)
3.圖形處理:
支持bmp,jpg,png,gif等28種圖形格式的載入,切割,翻轉(zhuǎn),旋轉(zhuǎn)等常見(jiàn)操作
4.文件系統(tǒng):
簡(jiǎn)便易用-支持zip,pk3等幾種壓縮格式(可加入對(duì)7z的解壓支持)
5.3d模型支持
靜態(tài)模型:3ds,ase(做為仿真之用)
動(dòng)態(tài)模型:md2
6.天空:支持天空盒,天空面,天空頂3種渲染模式
7.地形:支持地形紋理細(xì)節(jié)渲染
8.支持鏡頭光功能
9.支持從腳本載入材質(zhì),霧,光配置(當(dāng)前為lua腳本)
10.支持動(dòng)態(tài)光照,霧,材質(zhì)渲染
11.內(nèi)置數(shù)學(xué)庫(kù)包含矩陣,四元數(shù),歐拉角等基本數(shù)據(jù)結(jié)構(gòu)
12.支持
truetype字體
13.支持多線程渲染
14.內(nèi)置快速的三角函數(shù)求值和數(shù)學(xué)隨機(jī)數(shù)
15.內(nèi)置Lua/LuapLua腳本引擎
16.基于ode物理引擎
17.支持對(duì)簡(jiǎn)單的幾何對(duì)象渲染
18.支持日志文件
19.支持輸入輸出系統(tǒng)
20.支持3d坐標(biāo)查詢(xún)
21.支持2d紋理,球面紋理和立方體紋理
22.支持2d動(dòng)畫(huà)
23.支持多重紋理
24.支持粒子系統(tǒng)(可基于腳本配置)
25.支持多線程資源載入
26.另外還有一個(gè)游戲demo(資料在這里:http://www.gaimo.net/viewthread.php?tid=2705&extra=page%3D1)
關(guān)于蓋莫音頻引擎更新記錄:
蓋莫音頻引擎更新概要
1.2版本-支持midi格式--支持audio capture
1.3版本-支持ape格式 --支持從內(nèi)存中播放音頻 提供ptf文檔
1.4版本-無(wú)需安裝
openal 即可使用支持更多音效
1.5版本-支持vc,c#,python語(yǔ)言,支持linux操作系統(tǒng)
1.6版本-
當(dāng)前蓋莫音頻引擎為1.1.6版本
蓋莫音頻引擎可免費(fèi)使用于非商業(yè)用途
使用于商業(yè)用途只需少許許可費(fèi)即可(為了繼續(xù)開(kāi)發(fā))!
如果程序不能運(yùn)行
則需要安裝openal
蓋莫游戲引擎2.1.1使用的第三方庫(kù)列表
1.視頻庫(kù)ffmpeg
2.線程庫(kù)zthread
3.插槽sigc++/sigslot
4.gl擴(kuò)展glew
5.lua封裝luaplus
6.物理引擎ode
下載在這里
1.csdn
http://download.csdn.net/source/2257934
http://download.csdn.net/source/2257248
http://download.csdn.net/source/2257104
2.pudn 下載本sdk free!
http://www.pudn.com/downloads243/sourcecode/game/detail1132418.html
從csdn站點(diǎn)下載需要merge下載文件!
關(guān)于蓋莫軟件技術(shù)工作室
關(guān)于成都蓋莫軟件技術(shù)工作室
成都蓋莫軟件技術(shù)工作室成立于2010年1月份
主要從事游戲引擎設(shè)計(jì)和3d仿真業(yè)務(wù)
如果有任何疑問(wèn)和建議請(qǐng)致函:ccsdu2010@gmail.com
這是使用蓋莫游戲引擎2.1.1設(shè)計(jì)的射擊類(lèi)小游戲
題材源于SpaceInvader Game.
當(dāng)前僅設(shè)計(jì)了一個(gè)關(guān)卡
以后每發(fā)布一次游戲引擎
本游戲會(huì)升級(jí)一個(gè)版本
本游戲提供源碼
使用devc++,codeblock可編譯之
截圖1:

截圖2:

截圖3:

截圖4:

關(guān)于代碼的下載
在這里:
當(dāng)前提供2個(gè)下載站點(diǎn):
SpaceInvader.
http://www.pudn.com/downloads243/sourcecode/game/detail1132305.html
http://download.csdn.net/source/2257020
摘要: 以前大致看過(guò)模板元編程但是并沒(méi)有深入進(jìn)去現(xiàn)在就拿比較小的Loki庫(kù)研究了本文主要涉及的是其頭文件TypeMapIP.h1.根據(jù)給定常量生成對(duì)等枚舉變量
////////////////////////////////////////////////////////////////////////////////// class template Int2Type//...
閱讀全文
摘要: 接上文下面看看TypeList的類(lèi)型刪除功能相關(guān)源碼為:
/**/////////////////////////////////////////////////////////////////////////////////// class template Erase// Erases the first occurenc...
閱讀全文
接上篇
本文主要涉及rapidxml讀文件的操作
基本的步驟為
首先獲取xml文件數(shù)據(jù)
然后分析數(shù)據(jù)
獲取節(jié)點(diǎn)
獲取屬性
獲取名字
獲取值
...
代碼如下:
#include <iostream>
#include <rapidxml/rapidxml.hpp>
#include <rapidxml/rapidxml_utils.hpp>
#include <rapidxml/rapidxml_print.hpp>
using namespace rapidxml;

int main()


{
file<> fdoc("config.xml");
std::cout<<fdoc.data()<<std::endl;
xml_document<> doc;
doc.parse<0>(fdoc.data());

std::cout<<doc.name()<<std::endl;
//! 獲取根節(jié)點(diǎn)
xml_node<>* root = doc.first_node();
std::cout<<root->name()<<std::endl;

//! 獲取根節(jié)點(diǎn)第一個(gè)節(jié)點(diǎn)
xml_node<>* node1 = root->first_node();
std::cout<<node1->name()<<std::endl;

xml_node<>* node11 = node1->first_node();
std::cout<<node11->name()<<std::endl;
std::cout<<node11->value()<<std::endl;
//! 修改之后再次保存
xml_node<>* size = root->first_node("size");
size->append_node(doc.allocate_node(node_element,"w","0"));
size->append_node(doc.allocate_node(node_element,"h","0"));

std::string text;
rapidxml::print(std::back_inserter(text),doc,0);
std::cout<<text<<std::endl;
std::ofstream out("config.xml");
out << doc;

system("PAUSE");
return EXIT_SUCCESS;
}


生成的xml為:
<?xml version='1.0' encoding='utf-8' ?>
<config>
<color>
<red>0.1</red>
<green>0.1</green>
<blue>0.1</blue>
<alpha>1.0</alpha>
</color>
<size>
<x>640</x>
<y>480</y>
</size>
<mode fullscreen="false">screen mode</mode>
</config>

需要說(shuō)明的是rapidxml明顯有一個(gè)bug
那就是append_node(doc.allocate_node(node_element,"h","0"));的時(shí)候并不考慮該對(duì)象是否存在!
經(jīng)過(guò)這2篇 基本上就可以使用xml了
當(dāng)然這里并沒(méi)有涉及異常處理
蓋莫游戲引擎1.x版本是采用libxml操作xml文件的
這個(gè)庫(kù)弄得太復(fù)雜了
現(xiàn)在計(jì)劃從2.1.2開(kāi)始使用rapidxml操作xml
首先上一個(gè)簡(jiǎn)單的xml寫(xiě)文件
如下:
#include <iostream>
#include <rapidxml/rapidxml.hpp>
#include <rapidxml/rapidxml_utils.hpp>
#include <rapidxml/rapidxml_print.hpp>
using namespace rapidxml;
int main()
{
xml_document<> doc;
xml_node<>* rot = doc.allocate_node(rapidxml::node_pi,doc.allocate_string("xml version='1.0' encoding='utf-8'"));
doc.append_node(rot);
xml_node<>* node = doc.allocate_node(node_element,"config","information");
xml_node<>* color = doc.allocate_node(node_element,"color",NULL);
doc.append_node(node);
node->append_node(color);
color->append_node(doc.allocate_node(node_element,"red","0.1"));
color->append_node(doc.allocate_node(node_element,"green","0.1"));
color->append_node(doc.allocate_node(node_element,"blue","0.1"));
color->append_node(doc.allocate_node(node_element,"alpha","1.0"));
xml_node<>* size = doc.allocate_node(node_element,"size",NULL);
size->append_node(doc.allocate_node(node_element,"x","640"));
size->append_node(doc.allocate_node(node_element,"y","480"));
node->append_node(size);
xml_node<>* mode = doc.allocate_node(rapidxml::node_element,"mode","screen mode");
mode->append_attribute(doc.allocate_attribute("fullscreen","false"));
node->append_node(mode);
std::string text;
rapidxml::print(std::back_inserter(text), doc, 0);
std::cout<<text<<std::endl;
std::ofstream out("config.xml");
out << doc;
system("PAUSE");
return EXIT_SUCCESS;
}
生成的xml文件為:
<?xml version='1.0' encoding='utf-8' ?>
<config>
<color>
<red>0.1</red>
<green>0.1</green>
<blue>0.1</blue>
<alpha>1.0</alpha>
</color>
<size>
<x>640</x>
<y>480</y>
</size>
<mode fullscreen="false">screen mode</mode>
</config>

說(shuō)實(shí)話(huà) 感覺(jué)這個(gè)比較不錯(cuò)
希望更多的人使用它!

這是ode物理引擎中的關(guān)節(jié)類(lèi)型和圖例
對(duì)于關(guān)節(jié)類(lèi)型上圖是很直觀的了
1.球窩關(guān)節(jié)(Ball Socket)

2.合頁(yè)關(guān)節(jié)(Hinge)

3.插銷(xiāo)關(guān)節(jié)(Slider)

4.萬(wàn)向輪關(guān)節(jié)(Univeersal)

5.Hinge2關(guān)節(jié)

6.PR關(guān)節(jié)

PR關(guān)節(jié)即A prismatic and rotoide joint
是插銷(xiāo)關(guān)節(jié)和荷葉關(guān)節(jié)的組合形式
7.PU關(guān)節(jié)
PU關(guān)節(jié)即A prismatic-Universal joint (JointPU)
他是插銷(xiāo)關(guān)節(jié)和萬(wàn)向輪關(guān)節(jié)的組合形式

8.Piston joint 關(guān)節(jié)
Piston joint 關(guān)節(jié)類(lèi)似于插銷(xiāo)關(guān)節(jié)但是她可以繞軸轉(zhuǎn)動(dòng)

9.接觸面關(guān)節(jié)
物理受重力落體過(guò)程中就需要使用到接觸面關(guān)節(jié)


10.A Motor關(guān)節(jié)
該關(guān)節(jié)可以控制對(duì)象之間的相對(duì)角速度
11.另外還有LMotor關(guān)節(jié),plane-2d 關(guān)節(jié)
下面是關(guān)機(jī)的生成函數(shù)列表,其銷(xiāo)毀函數(shù)是相同的
dJointID dJointCreateBall (dWorldID, dJointGroupID);
dJointID dJointCreateHinge (dWorldID, dJointGroupID);
dJointID dJointCreateSlider (dWorldID, dJointGroupID);
dJointID dJointCreateContact (dWorldID, dJointGroupID, const dContact *);
dJointID dJointCreateUniversal (dWorldID, dJointGroupID);
dJointID dJointCreateHinge2 (dWorldID, dJointGroupID);
dJointID dJointCreatePR (dWorldID, dJointGroupID);
dJointID dJointCreatePU (dWorldID, dJointGroupID);
dJointID dJointCreatePiston (dWorldID, dJointGroupID);
dJointID dJointCreateFixed (dWorldID, dJointGroupID);
dJointID dJointCreateAMotor (dWorldID, dJointGroupID);
dJointID dJointCreateLMotor (dWorldID, dJointGroupID);
dJointID dJointCreatePlane2d (dWorldID, dJointGroupID);
參考文獻(xiàn):http://opende.sourceforge.net/wiki/index.php/Manual_%28Joint_Types_and_Functions%29
關(guān)于ode物理引擎的時(shí)候可參考o(jì)de庫(kù)自帶demo
當(dāng)然也可以參考蓋莫游戲引擎sdk上面附有3個(gè)基于ode的物理模擬
這是使用蓋莫游戲引擎(2.1.1)設(shè)計(jì)的天空頂小例
天空頂比較類(lèi)似天空面
具體代碼和圖片如下:
#include <GEngine/Gaimo.hpp>
using namespace std;
using namespace core;
int Main()
{
//! 初始化引擎設(shè)備并得到設(shè)備指針
RefPtr<Device> device = InitDevice("天空頂測(cè)試");
//! 得到引擎場(chǎng)景指針
RefPtr<SceneManager> scenemanager = device->GetSceneManager();
//! 得到引擎資源指針
RefPtr<ResourceManager> resourcemanager = device->GetResourceManager();
//! 獲取圖形管理器指針
RefPtr<ImageManager> imagemanager = resourcemanager->GetImageManager();
//! 得到視頻驅(qū)動(dòng)器指針
RefPtr<VideoDriver> videodriver = device->GetVideoDriver();
//! 得到天空?qǐng)D形和紋理
RefPtr<Image> image = imagemanager->CreateObject("sky","..\\image\\sky\\top.jpg");
RefPtr<Texture> texture = resourcemanager->GetTextureManager()->CreateTexture("sky",image);
//! 得到天空盒指針
SkyDomeDesc desc;
desc.texture = texture;
RefPtr<Renderable> sky = scenemanager->CreateSkyDome(desc);
//! 獲取攝像機(jī)指針
RefPtr<Camera> camera = scenemanager->GetCameraManager()->CreateCamera("camera",
Vector3f(),
Vector3f(100,60,0));
camera->SetViewPort(Recti(0,0,640,480));
camera->SetPerspective(45.0f,640.0f/480.0f,0.1f,600.0f);
//! 獲取霧指針
RefPtr<Fog> fog = resourcemanager->GetFog("..\\script//fog.lua","fog");
fog->Render();
BEGIN_LOOP(device)
videodriver->SetClearBuffer(ENGINE_CLEAR_COLOR | ENGINE_CLEAR_DEPTH);
camera->Render();
sky->Render();
END_LOOP(device)
return 0;
}
摘要: Loki中的TypeList這塊是Loki中比較基礎(chǔ)的部分其主要涉及類(lèi)型鏈表(TypeList)相關(guān)功能有1.模板化得類(lèi)型鏈表-最打提供18個(gè)類(lèi)型參數(shù)2.獲取類(lèi)型鏈表的長(zhǎng)度3.獲取給定索引位置的參數(shù)類(lèi)型4.當(dāng)索引越界時(shí)獲取設(shè)定的參數(shù)類(lèi)型5.類(lèi)型鏈表的類(lèi)型增加和剔除6.其他下面是makeTypeList的代碼
1 &...
閱讀全文