// Ryzom - MMORPG Framework
// Copyright (C) 2010 Winch Gate Property Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see .
#include "stdpch.h"
#include "primitive_cfg.h"
#include "nel/misc/config_file.h"
#include "nel/misc/path.h"
using namespace NLMISC;
using namespace std;
// std::vector CPrimitiveCfg::_AllPrimitives;
std::vector CPrimitiveCfg::_MapNames;
std::map > CPrimitiveCfg::_Maps;
std::map > CPrimitiveCfg::_ContinentFiles;
void CPrimitiveCfg::addPrimitive(std::vector &vectorlist, const std::string &str)
{
for (uint32 i=0;i >::iterator first(_ContinentFiles.begin()), last(_ContinentFiles.end());
for (; first != last; ++first)
if (find(first->second.begin(),first->second.end(), name) != first->second.end())
return first->first;
return std::string();
}
// dumb routine to simplify repetitive text parsing code
inline bool isWhiteSpace(char c)
{
return (c==' ' || c=='\t');
}
// -- stringToWordAndTail() --
// The following routine splits a text string into a keyword and a tail.
// A white space is used as separator between keyword and tail
// All leading and trailing ' ' and '\t' round keyword and tail characters are stripped
// If no keyword is found routine retuns false (keyword and tail retain previous content)
inline bool stringToWordAndTail(const std::string &input,std::string &word, std::string &tail)
{
uint i=0, j;
// skip white space
while (ij && isWhiteSpace(input[i-1]);) --i; // i points to character after end of tail text
// find start of tail text
do { ++j; } while(j CurrentMapNames;
set mapNames;
std::vector *_CurrentContinentFiles=NULL;
for (uint32 i=0;i=s.size())
// continue;
// // separate the first word (we need it to know what to do next)
// for (k=j;k=j) tail=s.substr(j,k-j+1);
// do something depending on the keyword found earlier
if (nlstricmp(keyword,"MAPEND")==0)
{
// remove the last map entry
CurrentMapNames.pop_back();
}
else if (nlstricmp(keyword,"CONTINENT")==0)
{
_CurrentContinentFiles=&_ContinentFiles[tail];
}
else if (nlstricmp(keyword,"MAP")==0)
{
// store the map name for use later
CurrentMapNames.push_back(tail);
mapNames.insert(tail);
_Maps.insert(make_pair(tail, vector()));
if (_CurrentContinentFiles)
addPrimitive(*_CurrentContinentFiles, tail); // bad but not too ..
}
else if (nlstricmp(keyword,"FILE")==0)
{
// if our file name is > 0 characters long then add it to the vector
// if (j<=k)
{
string filename = tail; //s.substr(j,k-j+1);
if (CFile::getExtension(filename).empty())
filename+=".primitive";
for (uint32 mapInd=0;mapInd 0 characters long then add it to the vector
// if (j<=k)
{
string includeName = tail; //s.substr(j,k-j+1);
if (_Maps.find(includeName)==_Maps.end())
{
nlwarning("PrimitiveCfg: Include %s failed, not defined.",includeName.c_str());
}
else
{
std::vector &vectorlist=_Maps[includeName];
for (uint32 primInd=0;primInd