本文整理汇总了C++中Pos::set方法的典型用法代码示例。如果您正苦于以下问题:C++ Pos::set方法的具体用法?C++ Pos::set怎么用?C++ Pos::set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pos
的用法示例。
在下文中一共展示了Pos::set方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: onActorTurn_
bool GiantLocust::onActorTurn_() {
if(deadState == ActorDeadState::alive) {
if(awareOfPlayerCounter_ > 0) {
if(Rnd::percentile() < chanceToSpawnNew) {
bool blockers[MAP_W][MAP_H];
MapParse::parse(CellPred::BlocksActor(*this, true, eng), blockers);
Pos spawnPos;
for(int dx = -1; dx <= 1; dx++) {
for(int dy = -1; dy <= 1; dy++) {
spawnPos.set(pos + Pos(dx, dy));
if(blockers[spawnPos.x][spawnPos.y] == false) {
Actor* const actor =
eng.actorFactory->spawnActor(data_->id, spawnPos);
GiantLocust* const locust = dynamic_cast<GiantLocust*>(actor);
chanceToSpawnNew -= 2;
locust->chanceToSpawnNew = chanceToSpawnNew;
locust->awareOfPlayerCounter_ = awareOfPlayerCounter_;
eng.gameTime->actorDidAct();
return true;
}
}
}
}
}
}
return false;
}
示例2: addMatches
bool Matches::addMatches( char *s, int32_t slen, mf_t flags ) {
// . do not breach
// . happens a lot with a lot of link info text
if ( m_numMatchGroups >= MAX_MATCHGROUPS ) {
return true;
}
// get some new ptrs for this match group
Words *wp = &m_wordsArray [ m_numMatchGroups ];
Bits *bp = &m_bitsArray [ m_numMatchGroups ];
Pos *pb = &m_posArray [ m_numMatchGroups ];
// set the words class for this match group
if ( !wp->set( s, slen, true ) ) {
return false;
}
// bits vector
if ( ! bp->setForSummary ( wp ) ) {
return false;
}
// position vector
if ( ! pb->set ( wp ) ) {
return false;
}
// record the start
int32_t startNumMatches = m_numMatches;
// sometimes it returns true w/o incrementing this
int32_t n = m_numMatchGroups;
// . add all the Match classes from this match group
// . this increments m_numMatchGroups on success
bool status = addMatches( wp, NULL, NULL, bp, pb, flags );
// if this matchgroup had some, matches, then keep it
if ( m_numMatches > startNumMatches ) {
return status;
}
// otherwise, reset it, useless
wp->reset();
bp->reset();
pb->reset();
// do not decrement the counter if we never incremented it
if ( n == m_numMatchGroups ) {
return status;
}
// ok, remove it
m_numMatchGroups--;
return status;
}
示例3: generateSummary
static void generateSummary( Summary &summary, char *htmlInput, const char *queryStr, const char *urlStr ) {
Xml xml;
ASSERT_TRUE(xml.set(htmlInput, strlen(htmlInput), 0, CT_HTML));
Words words;
ASSERT_TRUE(words.set(&xml, true));
Bits bits;
ASSERT_TRUE(bits.set(&words));
Url url;
url.set(urlStr);
Sections sections;
ASSERT_TRUE(sections.set(&words, &bits, &url, "", CT_HTML));
Query query;
ASSERT_TRUE(query.set2(queryStr, langEnglish, true));
LinkInfo linkInfo;
memset ( &linkInfo , 0 , sizeof(LinkInfo) );
linkInfo.m_lisize = sizeof(LinkInfo);
Title title;
ASSERT_TRUE(title.setTitle(&xml, &words, 80, &query, &linkInfo, &url, NULL, 0, CT_HTML, langEnglish));
Pos pos;
ASSERT_TRUE(pos.set(&words));
Bits bitsForSummary;
ASSERT_TRUE(bitsForSummary.setForSummary(&words));
Phrases phrases;
ASSERT_TRUE(phrases.set(&words, &bits));
Matches matches;
matches.setQuery(&query);
ASSERT_TRUE(matches.set(&words, &phrases, §ions, &bitsForSummary, &pos, &xml, &title, &url, &linkInfo));
summary.setSummary(&xml, &words, §ions, &pos, &query, 180, 3, 3, 180, &url, &matches, title.getTitle(), title.getTitleLen());
}
示例4: setTitle
// returns false and sets g_errno on error
bool Title::setTitle ( Xml *xml, Words *words, int32_t maxTitleLen, Query *query,
LinkInfo *linkInfo, Url *firstUrl, const char *filteredRootTitleBuf, int32_t filteredRootTitleBufSize,
uint8_t contentType, uint8_t langId, int32_t niceness ) {
// make Msg20.cpp faster if it is just has
// Msg20Request::m_setForLinkInfo set to true, no need to extricate a title.
if ( maxTitleLen <= 0 ) {
return true;
}
m_niceness = niceness;
m_maxTitleLen = maxTitleLen;
// if this is too big the "first line" algo can be huge!!!
// and really slow everything way down with a huge title candidate
int32_t maxTitleWords = 128;
// assume no title
reset();
int32_t NW = words->getNumWords();
//
// now get all the candidates
//
// . allow up to 100 title CANDIDATES
// . "as" is the word # of the first word in the candidate
// . "bs" is the word # of the last word IN the candidate PLUS ONE
int32_t n = 0;
int32_t as[MAX_TIT_CANDIDATES];
int32_t bs[MAX_TIT_CANDIDATES];
float scores[MAX_TIT_CANDIDATES];
Words *cptrs[MAX_TIT_CANDIDATES];
int32_t types[MAX_TIT_CANDIDATES];
int32_t parent[MAX_TIT_CANDIDATES];
// record the scoring algos effects
float baseScore [MAX_TIT_CANDIDATES];
float noCapsBoost [MAX_TIT_CANDIDATES];
float qtermsBoost [MAX_TIT_CANDIDATES];
float inCommonCandBoost[MAX_TIT_CANDIDATES];
// reset these
for ( int32_t i = 0 ; i < MAX_TIT_CANDIDATES ; i++ ) {
// assume no parent
parent[i] = -1;
}
// xml and words class for each link info, rss item
Xml tx[MAX_TIT_CANDIDATES];
Words tw[MAX_TIT_CANDIDATES];
int32_t ti = 0;
// restrict how many link texts and rss blobs we check for titles
// because title recs like www.google.com have hundreds and can
// really slow things down to like 50ms for title generation
int32_t kcount = 0;
int32_t rcount = 0;
//int64_t x = gettimeofdayInMilliseconds();
// . get every link text
// . TODO: repeat for linkInfo2, the imported link text
for ( Inlink *k = NULL; linkInfo && (k = linkInfo->getNextInlink(k)) ; ) {
// breathe
QUICKPOLL(m_niceness);
// fast skip check for link text
if ( k->size_linkText >= 3 && ++kcount >= 20 ) continue;
// fast skip check for rss item
if ( k->size_rssItem > 10 && ++rcount >= 20 ) continue;
// set Url
Url u;
u.set( k->getUrl(), k->size_urlBuf );
// is it the same host as us?
bool sh = true;
// skip if not from same host and should be
if ( firstUrl->getHostLen() != u.getHostLen() ) {
sh = false;
}
// skip if not from same host and should be
if ( strncmp( firstUrl->getHost(), u.getHost(), u.getHostLen() ) ) {
sh = false;
}
// get the link text
if ( k->size_linkText >= 3 ) {
char *p = k->getLinkText();
int32_t plen = k->size_linkText - 1;
if ( ! verifyUtf8 ( p , plen ) ) {
log("title: set4 bad link text from url=%s", k->getUrl());
continue;
}
// now the words.
if ( !tw[ti].set( k->getLinkText(), k->size_linkText - 1, true, 0 ) ) {
//.........这里部分代码省略.........
示例5: main
int main () {
map<string,Archetype> factory;
TiXmlDocument doc("examples.xml");
if (!doc.LoadFile()) return 0;
TiXmlHandle hDoc(&doc);
TiXmlElement* pElem;
TiXmlHandle hRoot(0);
pElem=hDoc.FirstChildElement().Element();
if (!pElem) return 0;
string m_name=pElem->Value();
// save this for later
hRoot=TiXmlHandle(pElem);
int damagetypes = atoi(hRoot.Element()->Attribute("damagetypes"));
TiXmlElement* pArchetypeNode=hRoot.FirstChild( "archetype" ).Element();
for( pArchetypeNode; pArchetypeNode; pArchetypeNode=pArchetypeNode->NextSiblingElement())
{
Archetype currArch;
currArch.name = pArchetypeNode->Attribute("name");
currArch.duration = atoi(pArchetypeNode->Attribute("duration"));
string sizestr = pArchetypeNode->FirstChildElement("data")->Attribute("size");
// split size (eg. "70,60"), convert to vector of ints
// sort out +r1 later
vector<int> size;
string sizenumst;
stringstream stream(sizestr);
while( getline(stream, sizenumst, ',') ) {
istringstream intstream(sizenumst);
int foo;
intstream >> foo;
size.push_back(foo);
};
currArch.size[0] = size[0];
currArch.size[1] = size[1];
currArch.health = atoi(pArchetypeNode->FirstChildElement("data")->Attribute("health"));
currArch.pointvalue = atoi(pArchetypeNode->FirstChildElement("data")->Attribute("pointvalue"));
currArch.damagenumber = atoi(pArchetypeNode->FirstChildElement("data")->Attribute("damagenumber"));
for(int i= 0; i <= damagetypes; i++) {
currArch.damagedata.push_back(0);
}
TiXmlElement* pData=pArchetypeNode->FirstChildElement( "data" )->FirstChildElement("damage");
for( pData; pData; pData=pData->NextSiblingElement()) {
int ref = atoi(pData->Attribute("num"));
currArch.damagedata.at(atoi(pData->Attribute("num"))) = atoi(pData->Attribute("strength"));
}
// Iterating over meshes
TiXmlElement* pMesh=pArchetypeNode->FirstChildElement( "structure" )->FirstChildElement("mesh");
for( pMesh; pMesh; pMesh=pMesh->NextSiblingElement("mesh")) {
Mesh currMesh;
vector<int> pos = string_split_comma(pMesh->Attribute("pos"));
currMesh.pos.set(pos.at(0),pos.at(1),pos.at(2));
currMesh.file = pMesh->Attribute("file");
currMesh.texture = pMesh->Attribute("texture");
if (pMesh->Attribute("scale")) {
currMesh.scale = atof(pMesh->Attribute("scale"));
} else {
currMesh.scale = 1.0;
}
currArch.meshes.push_back(currMesh);
}
// Iterating over lights
TiXmlElement* pLight=pArchetypeNode->FirstChildElement( "structure" )->FirstChildElement("light");
for( pLight; pLight; pLight=pLight->NextSiblingElement("light")) {
Light currLight;
vector<int> pos = string_split_comma(pLight->Attribute("pos"));
currLight.pos.set(pos.at(0),pos.at(1),pos.at(2));
vector<int> color = string_split_comma(pLight->Attribute("colour"));
currLight.colour[0] = color.at(0);
currLight.colour[1] = color.at(1);
currLight.colour[2] = color.at(2);
currLight.range = atoi(pLight->Attribute("range"));
currArch.lights.push_back(currLight);
}
// Iterating over billboards
TiXmlElement* pBillb=pArchetypeNode->FirstChildElement( "structure" )->FirstChildElement("billboard");
for( pBillb; pBillb; pBillb=pBillb->NextSiblingElement("billboard")) {
Billboard currBillb;
//.........这里部分代码省略.........
示例6: calcNewLine
void LineCalc::calcNewLine(const Pos& origin, const Pos& target,
const bool SHOULD_STOP_AT_TARGET,
const int CHEB_TRAVEL_LIMIT,
const bool ALLOW_OUTSIDE_MAP,
vector<Pos>& lineRef) {
lineRef.resize(0);
if(target == origin) {
lineRef.push_back(origin);
return;
}
const double DELTA_X_DB = double(target.x - origin.x);
const double DELTA_Y_DB = double(target.y - origin.y);
const double HYPOT_DB =
sqrt((DELTA_X_DB * DELTA_X_DB) + (DELTA_Y_DB * DELTA_Y_DB));
const double X_INCR_DB = (DELTA_X_DB / HYPOT_DB);
const double Y_INCR_DB = (DELTA_Y_DB / HYPOT_DB);
double curX_db = double(origin.x) + 0.5;
double curY_db = double(origin.y) + 0.5;
Pos curPos = Pos(int(curX_db), int(curY_db));
const double STEP_SIZE_DB = 0.04;
for(double i = 0.0; i <= 9999.0; i += STEP_SIZE_DB) {
curX_db += X_INCR_DB * STEP_SIZE_DB;
curY_db += Y_INCR_DB * STEP_SIZE_DB;
curPos.set(floor(curX_db), floor(curY_db));
if(ALLOW_OUTSIDE_MAP == false) {
if(Utils::isPosInsideMap(curPos) == false) {
return;
}
}
bool isPosOkToAdd = false;
if(lineRef.empty()) {
isPosOkToAdd = true;
} else {
isPosOkToAdd = lineRef.back() != curPos;
}
if(isPosOkToAdd) {
lineRef.push_back(curPos);
}
//Check distance limits
if(SHOULD_STOP_AT_TARGET && (curPos == target)) {
return;
}
const int DISTANCE_TRAVELED =
Utils::chebyshevDist(
origin.x, origin.y, curPos.x, curPos.y);
if(DISTANCE_TRAVELED >= CHEB_TRAVEL_LIMIT) {
return;
}
}
}