加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
DataManager.cpp 6.71 KB
一键复制 编辑 原始数据 按行查看 历史
Shaker 提交于 2014-08-12 21:17 . *提交到Git@OSC
#include "StdAfx.h"
#include "GameMir.h"
#include ".\gamemir.h"
#define DIR_PRE "data\\"
CGameMir::CDataManager::CDataManager(void)
{
LoadDoorLink();
LoadMapTitle();
LoadMiniMap();
LoadBindItems();
}
CGameMir::CDataManager::~CDataManager(void)
{
}
bool CGameMir::CDataManager::GetMap(const std::string& name, sMap** map)
{
for(tMapList::iterator pos=m_Maps.begin();pos!=m_Maps.end();pos++)
{
if ( pos->mapname == name )
{
*map=&(*pos);
return true;
}
}
*map=NULL;
return false;
}
CGameMir::sMap* CGameMir::CDataManager::InsertMap(std::string name)
{
sMap* pmap;
if(GetMap(name,&pmap))
return pmap;
sMap map;
map.mapname=name;
m_Maps.push_back(map);
if(GetMap(name,&pmap))
return pmap;
return NULL;
}
void CGameMir::CDataManager::LoadDoorLink(void)
{
// doorlink.ini
CFile doorlink_ini((CGameMir::GetMainDir()+DIR_PRE"doorlink.ini").c_str(),CFile::typeBinary|CFile::modeRead|CFile::shareDenyWrite);
long flen=doorlink_ini.GetLength();
char*pBuf=new char[flen+1];
ZeroMemory(pBuf,flen+1);
doorlink_ini.Read(pBuf,flen);
pBuf[flen]=static_cast<char>(0);
std::wstring text;
LPWSTR UBuf=new WCHAR[flen+1];;
text=ToUnicode(pBuf,UBuf,flen);
delete[]pBuf;
delete[]UBuf;
std::vector<std::wstring> Lines;
const boost::wregex reSplit(L"\\s*\\n\\s*",boost::regbase::normal|boost::regbase::icase);
const boost::wregex reDoorLink(L"^(\\S+)\\s+(\\d+)\\s+(\\d+)\\s+(\\S+)\\s+(\\d+)\\s+(\\d+)(?:\\s+\\[>>(.+?)\\])?$",boost::regbase::normal|boost::regbase::icase);
const boost::wregex reDoorDist(L"^(.+?)\\s+(\\d+)\\s+(\\d+)\\s+\\1\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)$",boost::regbase::normal|boost::regbase::icase);
boost::regex_split(std::back_inserter(Lines),text,reSplit);
boost::wsmatch match;
int cnt1=0,cnt2=0;
char cBuf[STRING_BUFFER_LENGTH+1];
for(std::vector<std::wstring>::iterator pos=Lines.begin();pos!=Lines.end();pos++)
{
if (boost::regex_match( *pos, match, reDoorLink))
{
sDoorLink dlink;
dlink.source.mapname=ToAnsi(match.str(1).c_str(),cBuf,STRING_BUFFER_LENGTH);
dlink.source.pos.x=boost::lexical_cast<int>(match.str(2));
dlink.source.pos.y=boost::lexical_cast<int>(match.str(3));
dlink.dest.mapname=ToAnsi(match.str(4).c_str(),cBuf,STRING_BUFFER_LENGTH);
dlink.dest.pos.x=boost::lexical_cast<int>(match.str(5));
dlink.dest.pos.y=boost::lexical_cast<int>(match.str(6));
dlink.dlg_name=ToAnsi(match.str(7).c_str(),cBuf,STRING_BUFFER_LENGTH);
sMap* map=NULL;
map=InsertMap(dlink.dest.mapname);
if (map==NULL)
{
throw "氝樓華芞囮啖1";
}
map=InsertMap(dlink.source.mapname);
if (map==NULL)
{
throw "氝樓華芞囮啖2";
}
map->DoorLinks.push_back(dlink);
cnt1++;
}
else if (boost::regex_match( *pos, match, reDoorDist))
{
sDoorDist ddist;
ddist.mapname=ToAnsi(match.str(1).c_str(),cBuf,STRING_BUFFER_LENGTH);
ddist.pos1.x=boost::lexical_cast<int>(match.str(2));
ddist.pos1.y=boost::lexical_cast<int>(match.str(3));
ddist.pos2.x=boost::lexical_cast<int>(match.str(4));
ddist.pos2.y=boost::lexical_cast<int>(match.str(5));
ddist.dist=boost::lexical_cast<int>(match.str(6));
sMap* map=NULL;
map=InsertMap(ddist.mapname);
if (map==NULL)
{
throw "氝樓華芞囮啖";
}
map->DoorDists.push_back(ddist);
cnt2++;
}
}
}
void CGameMir::CDataManager::LoadMapTitle(void)
{
// mapinfo.txt
CFile mapinfo_txt((CGameMir::GetMainDir()+DIR_PRE"mapinfo.txt").c_str(),CFile::typeBinary|CFile::modeRead|CFile::shareDenyWrite);
long flen=mapinfo_txt.GetLength();
char*pBuf=new char[flen+1];
ZeroMemory(pBuf,flen+1);
mapinfo_txt.Read(pBuf,flen);
pBuf[flen]=static_cast<char>(0);
std::wstring text;
LPWSTR UBuf=new WCHAR[flen+1];;
text=ToUnicode(pBuf,UBuf,flen);
delete[]pBuf;
delete[]UBuf;
std::vector<std::wstring> Lines;
const boost::wregex reSplit(L"\\s*\\n\\s*",boost::regbase::normal|boost::regbase::icase);
const boost::wregex reMapTitle(L"^\\[(.+?)\\s+(.+?)\\s+.+$",boost::regbase::normal|boost::regbase::icase);
boost::regex_split(std::back_inserter(Lines),text,reSplit);
boost::wsmatch match;
char cBuf[STRING_BUFFER_LENGTH+1];
for(std::vector<std::wstring>::iterator pos=Lines.begin();pos!=Lines.end();++pos)
{
if (boost::regex_match( *pos, match, reMapTitle))
{
sMap* map=NULL;
map=InsertMap(ToAnsi(match.str(1).c_str(),cBuf,STRING_BUFFER_LENGTH));
if (map==NULL)
{
throw "氝樓華芞囮啖";
}
map->maptitle=ToAnsi(match.str(2).c_str(),cBuf,STRING_BUFFER_LENGTH);
}
}
}
void CGameMir::CDataManager::LoadMiniMap(void)
{
// MiniMap.txt
CFile minimap_txt((CGameMir::GetMainDir()+DIR_PRE"MiniMap.txt").c_str(),CFile::typeBinary|CFile::modeRead|CFile::shareDenyWrite);
long flen=minimap_txt.GetLength();
char*pBuf=new char[flen+1];
ZeroMemory(pBuf,flen+1);
minimap_txt.Read(pBuf,flen);
pBuf[flen]=static_cast<char>(0);
std::wstring text;
LPWSTR UBuf=new WCHAR[flen+1];;
text=ToUnicode(pBuf,UBuf,flen);
delete[]pBuf;
delete[]UBuf;
std::vector<std::wstring> Lines;
const boost::wregex reSplit(L"\\s*\\n\\s*",boost::regbase::normal|boost::regbase::icase);
const boost::wregex reMapTitle(L"^(\\S+)\\s+(\\d+)$",boost::regbase::normal|boost::regbase::icase);
boost::regex_split(std::back_inserter(Lines),text,reSplit);
boost::wsmatch match;
m_MiniMaps.clear();
char cBuf[STRING_BUFFER_LENGTH+1];
for(std::vector<std::wstring>::iterator pos=Lines.begin();pos!=Lines.end();pos++)
{
if (boost::regex_match( *pos, match, reMapTitle))
{
std::pair<std::string,WORD> item;
item.first=ToAnsi(match.str(1).c_str(),cBuf,STRING_BUFFER_LENGTH);
item.second=boost::lexical_cast<WORD>(match.str(2));
m_MiniMaps.insert(item);
}
}
}
void CGameMir::CDataManager::LoadBindItems(void)
{
// BindItems.txt
CFile BindItems_txt((CGameMir::GetMainDir()+DIR_PRE"BindItems.txt").c_str(),CFile::typeBinary|CFile::modeRead|CFile::shareDenyWrite);
long flen=BindItems_txt.GetLength();
char*pBuf=new char[flen+1];
ZeroMemory(pBuf,flen+1);
BindItems_txt.Read(pBuf,flen);
pBuf[flen]=static_cast<char>(0);
std::wstring text;
LPWSTR UBuf=new WCHAR[flen+1];;
text=ToUnicode(pBuf,UBuf,flen);
delete[]pBuf;
delete[]UBuf;
std::vector<std::wstring> Lines;
const boost::wregex reSplit(L"\\s*\\n\\s*",boost::regbase::normal|boost::regbase::icase);
const boost::wregex reBindItem(L"^(.+?)\\s+(.+)$",boost::regbase::normal|boost::regbase::icase);
boost::regex_split(std::back_inserter(Lines),text,reSplit);
boost::wsmatch match;
m_BandItems.clear();
char cBuf[STRING_BUFFER_LENGTH+1];
for(std::vector<std::wstring>::iterator pos=Lines.begin();pos!=Lines.end();pos++)
{
if (boost::regex_match( *pos, match, reBindItem))
{
std::pair<std::string,std::string> item;
item.first=ToAnsi(match.str(1).c_str(),cBuf,STRING_BUFFER_LENGTH);
item.second=ToAnsi(match.str(2).c_str(),cBuf,STRING_BUFFER_LENGTH);
m_BandItems.insert(item);
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化