本文整理汇总了C++中CGrid类的典型用法代码示例。如果您正苦于以下问题:C++ CGrid类的具体用法?C++ CGrid怎么用?C++ CGrid使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CGrid类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: FindMonsterGroupInRange
WORD CGrid::FindMonsterGroupInRange(DWORD* pFriendsList, CObject* pFinder,VECTOR3* pPos)
{
POS pos = m_NeighborGrid.GetFirstPos();
CGrid* pGrid;
WORD wStartEmptyNum = 0;
DWORD objectList[MAX_FIND_MONSTERNUM] = {0,};
WORD wFindNum = FindMonsterGroupInRange(pFinder, pPos, &objectList[0]);
for(WORD i=0; i<wFindNum; ++i)
{
pFriendsList[wStartEmptyNum] = objectList[i];
wStartEmptyNum++;
}
while( (pGrid = m_NeighborGrid.GetNextPos(pos) ) != NULL)
{
if(wStartEmptyNum >= MAX_FIND_MONSTERNUM)
return wStartEmptyNum;
ZeroMemory(objectList, sizeof(objectList));
wFindNum = pGrid->FindMonsterGroupInRange(pFinder, pPos, &objectList[0]);
for(WORD i=0; i<wFindNum; i++)
{
if(wStartEmptyNum >= MAX_FIND_MONSTERNUM)
return wStartEmptyNum;
pFriendsList[wStartEmptyNum] = objectList[i];
wStartEmptyNum++;
}
}
return wStartEmptyNum;
}
示例2:
void CMap::Draw( void )
{
CGrid* pEnd = m_pGrid + m_uWidth*m_uHeight;
for ( CGrid* pCur = m_pGrid; pCur!=pEnd; pCur++ )
{
pCur->Draw();
}
}
示例3: GetGridByPos
BOOL CGridManager::RemoveObjectFromGrid( CWorldObject *pWorldObject, FLOAT x, FLOAT z )
{
CGrid *pGrid = GetGridByPos(x, z);
if(pGrid == NULL)
{
return FALSE;
}
return pGrid->RemoveObject(pWorldObject);;
}
示例4: GetGridByIndex
//将对象从网格中删除
BOOL CGridManager::RemoveObjectFromGrid(CWorldObject *pWorldObject, INT32 nIndex)
{
CGrid *pGrid = GetGridByIndex(nIndex);
if(pGrid == NULL)
{
return FALSE;
}
return pGrid->RemoveObject(pWorldObject);;
}
示例5: AddGridToPackedDataWithoutOne
void CGrid::AddGridToPackedDataWithoutOne(DWORD dwID,CPackedData* pPackedData)
{
POS pos = m_NeighborGrid.GetFirstPos();
CGrid* pGrid;
AddObjectToPacket(dwID,pPackedData);
while( (pGrid = m_NeighborGrid.GetNextPos(pos)) != NULL)
{
pGrid->AddObjectToPacket(dwID,pPackedData);
}
}
示例6: AddGridToPackedData
void CGrid::AddGridToPackedData(CPackedData* pPackedData)
{
POS pos = m_NeighborGrid.GetFirstPos();
CGrid* pGrid;
AddObjectToPacket(0,pPackedData);
while( (pGrid = m_NeighborGrid.GetNextPos(pos)) != NULL)
{
pGrid->AddObjectToPacket(0,pPackedData);
}
}
示例7: ImportGrid
BOOL CDlgImportField::ImportGrid(int nGrid)
{
CGrid *pGrd = &(m_fldGrd[nGrid]);
CGrid grd;
GridInfo gi;
if(pGrd->IsEmpty()) {
gi = grd.GetInfoBrowse();
if( CheckGrid(gi) ) {
pGrd->Open( gi.strFilePath, gi.nType );
return TRUE;
}
}
else {
int ret = AfxMessageBox("Grid is not empty. Replace?", MB_ICONQUESTION | MB_YESNO);
if( ret == IDYES) {
gi = grd.GetInfoBrowse();
if( CheckGrid( gi) ) {
pGrd->Close();
pGrd->Open( gi.strFilePath, gi.nType );
return TRUE;
}
}
}
return FALSE;
}
示例8: SendRemoveObjectInfo
void CGrid::SendRemoveObjectInfo(CObject* pLeavedObject,CGrid* pCurGrid)
{
/////////////////////////////////////////////////////////////////////////
// 06. 04. 그리드 수정
// 이 함수는 삭제된 오브젝트가 소속된 그리드의 오브젝트들이
// 삭제된 오브젝트에게 연결된 Agent에 메세지를 보내는 부분인데
// 플레이어 이외의 오브젝트는 연결된 Agent가 없으므로 들어올 필요가 없다.
if(pLeavedObject->GetObjectKind() != eObjectKind_Player )
return;
/////////////////////////////////////////////////////////////////////////
POS pos = m_NeighborGrid.GetFirstPos();
CGrid* pGrid;
if(pCurGrid == NULL)
{
SendRemoveCharacterMsg(pLeavedObject);
// SendRemoveItemMsg(pLeavedObject);
while( (pGrid = m_NeighborGrid.GetNextPos(pos)) != NULL)
{
pGrid->SendRemoveCharacterMsg(pLeavedObject);
// pGrid->SendRemoveItemMsg(pLeavedObject);
}
}
else
{
if(!pCurGrid->IsNeighborGrid(this))
{
SendRemoveCharacterMsg(pLeavedObject);
// SendRemoveItemMsg(pLeavedObject);
}
while( (pGrid = m_NeighborGrid.GetNextPos(pos)) != NULL)
{
if(!pCurGrid->IsNeighborGrid(pGrid))
{
pGrid->SendRemoveCharacterMsg(pLeavedObject);
// pGrid->SendRemoveItemMsg(pLeavedObject);
}
}
}
}
示例9: GetNodeAttributeOrDefault
void CRABMedium::Init(TConfigurationNode& t_tree) {
try {
CMedium::Init(t_tree);
/* Check occlusions? */
GetNodeAttributeOrDefault(t_tree, "check_occlusions", m_bCheckOcclusions, m_bCheckOcclusions);
/* Get the positional index method */
std::string strPosIndexMethod("grid");
GetNodeAttributeOrDefault(t_tree, "index", strPosIndexMethod, strPosIndexMethod);
/* Get the arena center and size */
CVector3 cArenaCenter;
CVector3 cArenaSize;
TConfigurationNode& tArena = GetNode(CSimulator::GetInstance().GetConfigurationRoot(), "arena");
GetNodeAttribute(tArena, "size", cArenaSize);
GetNodeAttributeOrDefault(tArena, "center", cArenaCenter, cArenaCenter);
/* Create the positional index for embodied entities */
if(strPosIndexMethod == "grid") {
size_t punGridSize[3];
if(!NodeAttributeExists(t_tree, "grid_size")) {
punGridSize[0] = cArenaSize.GetX();
punGridSize[1] = cArenaSize.GetY();
punGridSize[2] = cArenaSize.GetZ();
}
else {
std::string strPosGridSize;
GetNodeAttribute(t_tree, "grid_size", strPosGridSize);
ParseValues<size_t>(strPosGridSize, 3, punGridSize, ',');
}
CGrid<CRABEquippedEntity>* pcGrid = new CGrid<CRABEquippedEntity>(
cArenaCenter - cArenaSize * 0.5f, cArenaCenter + cArenaSize * 0.5f,
punGridSize[0], punGridSize[1], punGridSize[2]);
m_pcRABEquippedEntityGridUpdateOperation = new CRABEquippedEntityGridEntityUpdater(*pcGrid);
pcGrid->SetUpdateEntityOperation(m_pcRABEquippedEntityGridUpdateOperation);
m_pcRABEquippedEntityIndex = pcGrid;
}
else {
THROW_ARGOSEXCEPTION("Unknown method \"" << strPosIndexMethod << "\" for the positional index.");
}
}
catch(CARGoSException& ex) {
THROW_ARGOSEXCEPTION_NESTED("Error in initialization of the range-and-bearing medium", ex);
}
}
示例10: OnBnClickedBrowseModel
void CDlgDefineModel::OnBnClickedBrowseModel()
{
CGrid grd;
grd.Open();
m_nX = grd.GetCols();
m_nY = grd.GetRows();
m_x0 = grd.GetX0();
m_y0 = grd.GetY0();
m_xCs = grd.GetXSize();
m_yCs = grd.GetYSize();
UpdateData(FALSE);
}
示例11: FindFirstMonsterInRange
CObject* CGrid::FindFirstMonsterInRange(CObject* pFinder,VECTOR3* pPos,float Range)
{
POS pos = m_NeighborGrid.GetFirstPos();
CGrid* pGrid;
CObject* pObject;
FindFirstMonsterInRange(pFinder,pPos,Range,&pObject);
if(pObject)
return pObject;
while( (pGrid = m_NeighborGrid.GetNextPos(pos) ) != NULL)
{
pGrid->FindFirstMonsterInRange(pFinder,pPos,Range,&pObject);
if(pObject)
return pObject;
}
return NULL;
}
示例12: FindPlayerRandom
CObject* CGrid::FindPlayerRandom()
{
POS pos = m_NeighborGrid.GetFirstPos();
CGrid* pGrid;
CObject* pObject[9];
CObject* temp;
WORD count = 0;
/// 우선 자기 그리드 내에서 플레이어를 고른다.
FindPlayerRandom( &temp );
if( temp )
{
pObject[count++] = temp;
}
/// 각 그리드에서 플레이어를 골라온다.
while( ( pGrid = m_NeighborGrid.GetNextPos( pos ) ) != NULL)
{
temp = NULL;
pGrid->FindPlayerRandom( &temp );
if( temp )
{
pObject[count++] = temp;
if(count == 9)
break;
}
}
/// 선택된 플레이어가 1인 이상일때
if(count > 0)
{
/// 리턴할 플레이어를 고른다
WORD select = WORD( rand() % count);
return pObject[select];
}
/// 선택된 플레이어가 없으면 NULL 리턴
return NULL;
}
示例13: sample
void CGrid::sample(CGrid &points,
void (*sample)(iterator starta, iterator enda,
iterator startb, iterator endb, double radius)) {
static int corner[8*3] = { 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1,
0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1 };
static int diagonals[14*2] = { 0, 0, //remove this line to avoid self intesextion
0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7,
2, 3, 1, 3, 1, 2,
1, 4, 2, 5, 3, 6 };
for(int z = 0; z < zside; z++) {
for(int y = 0; y < yside; y++) {
for(int x = 0; x < xside; x++) {
int origin = cell(x, y, z);
if(!isEmpty(origin) && !points.isEmpty(origin))
sample(startV(origin), endV(origin),
points.startV(origin), points.endV(origin), radius);
for(int d = 2; d < 28; d += 2) { //skipping self
int *cs = corner + 3*diagonals[d];
int *ce = corner + 3*diagonals[d+1];
if((x+cs[0] < xside) && (y+cs[1] < yside) && (z+cs[2] < zside) &&
(x+ce[0] < xside) && (y+ce[1] < yside) && (z+ce[2] < zside)) {
origin = cell(x+cs[0], y+cs[1], z+cs[2]);
int dest = cell(x+ce[0], y+ce[1], z+ce[2]);
if(!isEmpty(origin) && !points.isEmpty(dest)) // Locally
sample(startV(origin), endV(origin),
points.startV(dest), points.endV(dest), radius);
if(!isEmpty(dest) && !points.isEmpty(origin))
sample(startV(dest), endV(dest),
points.startV(origin), points.endV(origin), radius);
}
}
}
}
}
}
示例14: PrintGridCells
void PrintGridCells(CGrid<CLEDEntity>& g) {
for(SInt32 k = g.GetSizeK()-1; k >= 0; --k) {
for(SInt32 j = g.GetSizeJ()-1; j >= 0; --j) {
for(SInt32 i = 0; i < g.GetSizeI(); ++i) {
CGrid<CLEDEntity>::SCell& c = g.GetCellAt(i, j, k);
fprintf(stdout, "[ %d, %d, %d ] %u entities, timestamp = %u\n", i, j, k, c.Entities.size(), c.Timestamp);
if(!c.Entities.empty()) {
for(CSet<CLEDEntity*>::iterator it = c.Entities.begin();
it != c.Entities.end();
++it) {
fprintf(stdout, " %s\t%.3f\t%.3f\t%.3f\n",
(**it).GetId().c_str(),
(**it).GetPosition().GetX(),
(**it).GetPosition().GetY(),
(**it).GetPosition().GetZ());
}
}
}
}
}
fprintf(stdout, "\n");
}
示例15: FindMonsterInRange
CObject* CGrid::FindMonsterInRange(CObject* pFinder,VECTOR3* pPos,float Range)
{
POS pos = m_NeighborGrid.GetFirstPos();
CGrid* pGrid;
CObject* pObject;
CObject* pClosestObject;
float dist;
float mindist;
FindMonsterInRange(pFinder,pPos,Range,mindist,&pClosestObject);
while( (pGrid = m_NeighborGrid.GetNextPos(pos)) != NULL)
{
pGrid->FindMonsterInRange(pFinder,pPos,Range,dist,&pObject);
if(dist < mindist)
{
mindist = dist;
pClosestObject = pObject;
}
}
return pClosestObject;
}