void scRedispList::AddColumn( scColumn* col, scXRect& xrect ) { Lock(); scColRedisplay* cell = FindCell( col ); if ( !cell ) { Unlock(); AddCell( col ); Lock(); cell = FindCell( col ); } col->ComputeInkExtents( ); cell->fWidth = col->Width(); cell->fDepth = col->Depth(); cell->fExRect = col->GetInkExtents(); cell->fAdditionalText = col->MoreText(); scXRect fRepaintRect( cell->fRepaintRect ); fRepaintRect.Union( xrect ); cell->fRepaintRect = fRepaintRect; cell->fHasRepaint = fRepaintRect.Valid(); Unlock(); }
void scRedispList::AddColumn( const scCOLRefData& colRefData ) { Lock(); scColRedisplay* cell = FindCell( colRefData.fCol ); if ( !cell ) { Unlock(); AddCell( colRefData.fCol ); Lock(); cell = FindCell( colRefData.fCol ); } colRefData.fCol->ComputeInkExtents( ); cell->fWidth = colRefData.fCol->Width(); cell->fDepth = colRefData.fCol->Depth(); cell->fExRect = colRefData.fCol->GetInkExtents(); cell->fAdditionalText = colRefData.fCol->MoreText( ); scXRect fRepaintRect( cell->fRepaintRect ); fRepaintRect.Union( colRefData.fLineDamage ); cell->fRepaintRect = fRepaintRect; cell->fHasRepaint = fRepaintRect.Valid(); scXRect fDamageRect( cell->fDamageRect ); fDamageRect.Union( colRefData.fLineDamage ); cell->fDamageRect = fDamageRect; cell->fHasDamage = fDamageRect.Valid(); Unlock(); }
int KBagManager::GetCount(int nBagID, int nPos) const { const KCellBag* pCell = FindCell(nBagID, nPos); ASSERT_RETURN(pCell, 0); return pCell->GetItemStackNumber(); }
bool TestCellChangeEnemy::DefaultBehavior() { auto PtrRigid = GetComponent<Rigidbody>(); auto Velo = PtrRigid->GetVelocity(); Velo *= 0.95f; PtrRigid->SetVelocity(Velo); auto MapPtr = m_CelMap.lock(); if (MapPtr) { auto PlayerPtr = GetStage()->GetSharedGameObject<Player>(L"Player"); auto PlayerPos = PlayerPtr->GetComponent<Transform>()->GetPosition(); CellIndex PlayerCell; if (MapPtr->FindCell(PlayerPos, PlayerCell)) { //プレイヤーがセルマップ上に入った。 return false; } else { //プレイヤーはマップ上にいない //マップをプレイヤーの周りに再設定 Vec3 CellmapStart; CellmapStart.x = float((int)(PlayerPos.x - 2.0f)); CellmapStart.z = float((int)(PlayerPos.z - 2.0f)); CellmapStart.y = 0.0f; MapPtr->RefleshCellMap(CellmapStart, 1.0f, 4, 4); auto GameStagePtr = dynamic_pointer_cast<GameStage>(GetStage()); GameStagePtr->SetCellMapCost(L"CellMap2"); } } return true; }
lifegrid::GridArray NextTurn(lifegrid::GridArray& grid, size_t stride, size_t total) { lifegrid::GridArray nextPage; size_t height = total / stride; for (int i = 0; i < total; ++i) { int y = static_cast<int>(i / stride); int x = i % stride; int num = NumNeighbors(grid, x, y, static_cast<int>(stride), static_cast<int>(height)); if (num == 3) { // Any dead cell with exactly three live neighbors becomes a live cell, as if by reproduction. nextPage[i] = true; } else if (num < 2) { // Any live cell with fewer than two live neighbors dies, as if caused by under population. nextPage[i] = false; } else if (num > 3) { // Any live cell with more than three live neighbors dies, as if by overpopulation. nextPage[i] = false; } else { // Any live cell with two or three live neighbors lives on to the next generation. nextPage[i] = FindCell(grid, x, y, static_cast<int>(stride), static_cast<int>(height)); } } return std::move(nextPage); }
void* establishConnection(void* arg) { //Мы работаем с конкретным соединением int incomeSd = *((int*)arg); int userID = FindCell(); MessageType *buf = (MessageType*) malloc (sizeof(MessageType)); int resultOfHandlingMessage = 1; while (resultOfHandlingMessage) { if (server_enabled) { getMessage(incomeSd, buf); resultOfHandlingMessage = HandleMessage(buf, incomeSd, userID); } else { char *str = "Server is turned off..."; MessageType m = composeMessage(text, strlen(str), str); sendMessage(incomeSd, &m); } } free(buf); return NULL; }
avtVector avtIVPVTKOffsetField::operator()( const double &t, const avtVector &p ) const { avtVector zeros(0, 0, 0); std::vector<avtVector> velocities(3); for ( size_t j = 0; j < 3; ++j ) { if (FindCell(t, p) != OK) { // ghost cells on the base mesh may be required to avoid this failure debug5 <<"avtIVPVTKOffsetField::operator() - UNABLE TO FIND CELL!" <<std::endl; return zeros; } avtVector displ = GetPositionCorrection( j ); avtVector pCorrected = p - displ; avtVector displ2 = displ; if (FindCell(t, pCorrected) != OK) { // the displacement seen from the base target position may be // a little different. displ2 = GetPositionCorrection( j ); } pCorrected = p - 0.5*(displ2 + displ); if (FindCell(t, pCorrected) != OK) { debug5 <<"avtIVPVTKOffsetField::operator() - UNABLE TO FIND CORRECTED CELL!" <<std::endl; return zeros; } // velocity for this staggering FindValue(velData, velocities[j]); } // compose the velocity, assuming each component is purely // aligned to each axis. How should this be generalized when // the velocites are not alog axes? avtVector vel( velocities[0].x, velocities[1].y, velocities[2].z ); return vel; }
void scRedispList::AddCell( scColumn* col ) { scAssert( !FindCell( col ) ); scColRedisplay colredisp( col, col->GetAPPName() ); AppendData( (ElementPtr)&colredisp ); }
double avtIVPVTKTimeVaryingField::ComputeScalarVariable(unsigned char index, const double& t, const avtVector &pt) const { vtkDataArray* data0 = sclData[0][index]; vtkDataArray* data1 = sclData[1][index]; // TODO. Not all of the scalar fields have the data from the second data set. // Do we want to limit our selfs, that you must have both data values? // Currently the color only has the one value. //if( data0 == NULL || data1 == NULL ) if( data0 == NULL ) return 0.0; if (FindCell(t, pt) != OK) return 0.0; double result = 0.0, tmp0, tmp1; if( !sclCellBased[index] ) { for( avtInterpolationWeights::const_iterator wi=lastWeights.begin(); wi!=lastWeights.end(); ++wi ) { data0->GetTuple( wi->i, &tmp0 ); // TODO. Look if we want this code. if( data1 ) { data1->GetTuple( wi->i, &tmp1 ); result += wi->w * ((t-t0)/(t1-t0)*tmp1 + (t1-t)/(t1-t0)*tmp0); } else { result += wi->w * tmp0; } } } else { data0->GetTuple( lastCell, &tmp0 ); // TODO. Look if we want this code. if( data1 ) { data1->GetTuple( lastCell, &tmp1 ); result = (t-t0)/(t1-t0)*tmp1 + (t1-t)/(t1-t0)*tmp0; } else { result = tmp0; } } return result; }
void scRedispList::SetImmediateRect( scColumn* col, const scImmediateRedisp& immedredisp ) { Lock(); scColRedisplay* cell = FindCell( col ); if ( !cell ) { Unlock(); AddCell( col ); Lock(); cell = FindCell( col ); } cell->fImmediateRedisplay = true; cell->fImmediateArea = immedredisp; Unlock(); }
int NumNeighbors(int x, int y) const { int num = FindCell(x - 1, y - 1) ? 1 : 0; num += FindCell(x - 1, y + 0) ? 1 : 0; num += FindCell(x - 1, y + 1) ? 1 : 0; num += FindCell(x + 0, y - 1) ? 1 : 0; num += FindCell(x + 0, y + 1) ? 1 : 0; num += FindCell(x + 1, y - 1) ? 1 : 0; num += FindCell(x + 1, y + 0) ? 1 : 0; num += FindCell(x + 1, y + 1) ? 1 : 0; return num; }
int NumNeighbors(lifegrid::GridArray& grid, int x, int y, int width, int height) { int num = FindCell(grid, x - 1, y - 1, width, height) ? 1 : 0; num += FindCell(grid, x - 1, y + 0, width, height) ? 1 : 0; num += FindCell(grid, x - 1, y + 1, width, height) ? 1 : 0; num += FindCell(grid, x + 0, y - 1, width, height) ? 1 : 0; num += FindCell(grid, x + 0, y + 1, width, height) ? 1 : 0; num += FindCell(grid, x + 1, y - 1, width, height) ? 1 : 0; num += FindCell(grid, x + 1, y + 0, width, height) ? 1 : 0; num += FindCell(grid, x + 1, y + 1, width, height) ? 1 : 0; return num; }
bool Symtab<ValueType>::Lookup(string key, ValueType & value) { int bucket; cellT *cp; bucket = Hash(key, NBuckets); cp = FindCell(buckets[bucket], key); if (cp == NULL) return (false); value = cp->value; return (true); }
bool KBagManager::UpdateCellLock(const SC_BagCellUpdateLock* pBCUL) { ASSERT_RETURN(pBCUL, false); KCellBag* pCell = FindCell(pBCUL->byteBagID, pBCUL->nPos); ASSERT_RETURN(pCell, false); pCell->SetLock(pBCUL->nLockType); // TODO: 通知UI return true; }
Grid NextTurn() { GridSet targets; GRID_SET_RESERVE(targets, m_cellMap.size() * 9); for (GridKey key : m_cellMap) { int y = key.first; int x = key.second; targets.insert(MakeKeySafe(x - 1, y - 1)); targets.insert(MakeKeySafe(x - 1, y + 0)); targets.insert(MakeKeySafe(x - 1, y + 1)); targets.insert(MakeKeySafe(x + 1, y - 1)); targets.insert(MakeKeySafe(x + 1, y + 0)); targets.insert(MakeKeySafe(x + 1, y + 1)); targets.insert(MakeKeySafe(x + 0, y - 1)); targets.insert(MakeKeySafe(x + 0, y + 0)); targets.insert(MakeKeySafe(x + 0, y + 1)); } Grid next(m_width, m_height); for (GridKey key : targets) { int y = key.first; int x = key.second; bool target = FindCell(x, y); int num = NumNeighbors(x, y); // Any live cell with fewer than two live neighbors dies, as if caused by underpopulation. // Any live cell with two or three live neighbors lives on to the next generation. // Any live cell with more than three live neighbors dies, as if by overpopulation. // Any dead cell with exactly three live neighbors becomes a live cell, as if by reproduction. if (!target) { // Any dead cell with exactly three live neighbors becomes a live cell, as if by reproduction. if (num == 3) { next.SetCell(x, y); } } else if (num == 2 || num == 3) { // Any live cell with fewer than two live neighbors dies, as if caused by under population. next.SetCell(x, y); } // Any live cell with more than three live neighbors dies, as if by overpopulation. ? } return std::move(next); }
bool Enemy::DefaultBehavior() { auto PtrRigid = GetComponent<Rigidbody>(); auto Velo = PtrRigid->GetVelocity(); Velo *= 0.95f; PtrRigid->SetVelocity(Velo); auto MapPtr = m_CelMap.lock(); if (MapPtr) { auto PlayerPtr = GetStage()->GetSharedGameObject<Player>(L"Player"); auto PlayerPos = PlayerPtr->GetComponent<Transform>()->GetPosition(); CellIndex PlayerCell; if (MapPtr->FindCell(PlayerPos, PlayerCell)) { return false; } } return true; }
void Symtab<ValueType>::Enter(string key, ValueType value) { int bucket; cellT *cp; bucket = Hash(key, NBuckets); cp = FindCell(buckets[bucket], key); if (cp == NULL) { cp = new cellT; cp->key = key; cp->link = buckets[bucket]; buckets[bucket] = cp; numEntries++; } cp->value = value; }
bool Enemy::SeekBehavior() { auto PlayerPtr = GetStage()->GetSharedGameObject<Player>(L"Player"); auto PlayerPos = PlayerPtr->GetComponent<Transform>()->GetPosition(); auto MyPos = GetComponent<Transform>()->GetPosition(); auto MapPtr = m_CelMap.lock(); if (MapPtr) { if (SearchPlayer()) { auto PtrSeek = GetBehavior<SeekSteering>(); if (m_NextCellIndex == 0) { auto PtrRigid = GetComponent<Rigidbody>(); auto Velo = PtrRigid->GetVelocity(); Velo *= 0.95f; PtrRigid->SetVelocity(Velo); PlayerPos.y = m_StartPosition.y; PtrSeek->Execute(PlayerPos); } else { if (length(MyPos - PlayerPos) <= 3.0f){ auto PtrRigid = GetComponent<Rigidbody>(); auto Velo = PtrRigid->GetVelocity(); Velo *= 0.95f; PtrRigid->SetVelocity(Velo); } AABB ret; MapPtr->FindAABB(m_CellPath[m_NextCellIndex], ret); auto Pos = ret.GetCenter(); Pos.y = m_StartPosition.y; PtrSeek->Execute(Pos); } return true; } else { auto PtrSeek = GetBehavior<SeekSteering>(); CellIndex PlayerCell; if (MapPtr->FindCell(PlayerPos, PlayerCell)) { AABB ret; MapPtr->FindAABB(PlayerCell, ret); auto Pos = ret.GetCenter(); Pos.y = m_StartPosition.y; PtrSeek->Execute(Pos); return true; } } } return false; }
avtIVPField::Result avtIVPVTKTimeVaryingField::operator()( const double &t, const avtVector &p, avtVector &vel ) const { Result res = FindCell(t, p); if (res != OK) return res; if (velCellBased) { double v0[3], v1[3]; double p0 = (t1-t)/dt; double p1 = (t-t0)/dt; velData[0]->GetTuple( lastCell, v0 ); velData[1]->GetTuple( lastCell, v1 ); vel.x = p1 * v1[0] + p0 * v0[0]; vel.y = p1 * v1[1] + p0 * v0[1]; vel.z = p1 * v1[2] + p0 * v0[2]; } else { double v0[3], v1[3]; double p0 = (t1-t)/dt; double p1 = (t-t0)/dt; for( avtInterpolationWeights::const_iterator wi=lastWeights.begin(); wi!=lastWeights.end(); ++wi ) { velData[0]->GetTuple( wi->i, v0 ); velData[1]->GetTuple( wi->i, v1 ); v0[0] = p1 * v1[0] + p0 * v0[0]; v0[1] = p1 * v1[1] + p0 * v0[1]; v0[2] = p1 * v1[2] + p0 * v0[2]; vel.x += wi->w * v0[0]; vel.y += wi->w * v0[1]; vel.z += wi->w * v0[2]; } } return OK; }
avtIVPField::Result avtIVPFlashField::operator()( const double &t, const avtVector &p, const avtVector &v, avtVector& retV ) const { if (FindCell(t, p) != OK) return OUTSIDE_SPATIAL; avtVector B, E; if (FindValue(B_vtkDataArray, B) && FindValue(E_vtkDataArray, E)) { retV = factor * (E + Cross(v, B) ); return OK; } else return OUTSIDE_SPATIAL; }
avtIVPField::Result avtIVPVTKTimeVaryingField::IsInside( const double& t, const avtVector &pt ) const { return FindCell( t, pt ); }
const KItem* KBagManager::GetItem( int nBagID, int nPos ) const { const KCellBag* pCell = FindCell(nBagID, nPos); if(NULL == pCell) return NULL; return &(pCell->GetItem()); }
DWORD KBagManager::GetItemID( int nBagID, int nPos ) const { const KCellBag* pCell = FindCell(nBagID, nPos); if(NULL == pCell) return 0; return pCell->GetItemID(); }
void UniformGrid::TagCells(Point3 p,float radius, int whichGrid) { float x = 0.0f, y = 0.0f; int minX,maxX; int minY,maxY; //XGrid if (whichGrid == 0) { x = p.y - radius; y = p.z - radius; } //YGrid else if (whichGrid == 1) { x = p.x - radius; y = p.z - radius; } //YGrid else if (whichGrid == 2) { x = p.x - radius; y = p.y - radius; } FindCell(x, y, whichGrid, minX, minY); //XGrid if (whichGrid == 0) { x = p.y + radius; y = p.z + radius; } //YGrid else if (whichGrid == 1) { x = p.x + radius; y = p.z + radius; } //YGrid else if (whichGrid == 2) { x = p.x + radius; y = p.y + radius; } FindCell(x, y, whichGrid, maxX, maxY); if (minX < 0) minX = 0; if (minY < 0) minY = 0; if (maxX >= width) maxX = width-1; if (maxY >= width) maxY = width-1; //fill out the bitarray for (int i = minY; i <= maxY; i++) { int index = i * width+minX; for (int j = minX; j <= maxX; j++) { Grid *g = NULL; if (whichGrid == 0) { g = xGrid[index]; } else if (whichGrid == 1) { g = yGrid[index]; } else if (whichGrid == 2) { g = zGrid[index]; } if (g) { for (int k = 0; k < g->index.Count(); k++) { int pointIndex = g->index[k]; hitList.Append(1,&pointIndex,1000); if (whichGrid == 0) xHitList.Set(pointIndex); else if (whichGrid == 1) yHitList.Set(pointIndex); else if (whichGrid == 2) zHitList.Set(pointIndex); } } index++; } } }
void UniformGrid::LoadPoints(Point3 *p, int count) { int dx,dy; bounds.Init(); pointBase.SetCount(count); for (int i = 0; i < count; i++) { pointBase[i] = p[i]; bounds += p[i]; } if (count == 1) bounds.EnlargeBy(0.5); //need to do some bounds check to check for bounds that are to small float expandBy = 0.0f; if (((bounds.pmax.x - bounds.pmin.x)/width) < 0.0001f) expandBy += 0.1f * width; if (((bounds.pmax.y - bounds.pmin.y)/width) < 0.0001f) expandBy += 0.1f * width; if (((bounds.pmax.z - bounds.pmin.z)/width) < 0.0001f) expandBy += 0.1f * width; bounds.EnlargeBy(expandBy); fXWidth = bounds.pmax.x - bounds.pmin.x; fYWidth = bounds.pmax.y - bounds.pmin.y; fZWidth = bounds.pmax.z - bounds.pmin.z; for (int i = 0; i < count; i++) { //do XGrid //find out which cell we are in int index; if (activeGrid == 0) { index = FindCell(p[i].y,p[i].z,0,dx,dy); if ((index < 0) || (index >= widthXwidth)) DebugPrint(_T("XGrid Error cell out of range %d\n"),i); else { //see if cell exists if (xGrid[index] == NULL) xGrid[index] = new Grid(); //add that vertex to the cell xGrid[index]->index.Append(1,&i); // xGrid[index]->hit=FALSE; } } //do yGrid //find out which cell we are in if (activeGrid == 1) { index = FindCell(p[i].x,p[i].z,1,dx,dy); if ((index < 0) || (index >= widthXwidth)) DebugPrint(_T("YGrid Error cell out of range %d\n"),i); else { //see if cell exists if (yGrid[index] == NULL) yGrid[index] = new Grid(); //add that vertex to the cell yGrid[index]->index.Append(1,&i); // yGrid[index]->hit=FALSE; } } //do ZGrid //find out which cell we are in if (activeGrid == 2) { index = FindCell(p[i].x,p[i].y,2,dx,dy); if ((index < 0) || (index >= widthXwidth)) DebugPrint(_T("ZGrid Error cell out of range %d\n"),i); else { //see if cell exists if (zGrid[index] == NULL) zGrid[index] = new Grid(); //add that vertex to the cell zGrid[index]->index.Append(1,&i); // zGrid[index]->hit=FALSE; } } } xHitList.SetSize(count); yHitList.SetSize(count); zHitList.SetSize(count); numberOfHits = 0; numberOfChecks = 0; largestCellCount = 0; whichLargestCell = -1; for (int i = 0; i < widthXwidth; i++) { Grid* g = NULL; if (activeGrid == 0) g = xGrid[i]; else if (activeGrid == 1) g = yGrid[i]; else if (activeGrid == 2) g = zGrid[i]; // it may be quite often NULL DbgAssert(g); if (g != NULL) { int ct = g->index.Count(); if ((ct > largestCellCount) || (whichLargestCell == -1)) { largestCellCount = ct; whichLargestCell = i; } } } }
void UniformGrid::LoadPoints(Point3 *p, float *radius, int count) { int dx,dy; bounds.Init(); pointBase.SetCount(count); radiusBase.SetCount(count); largestRadius = 0.0f; for (int i = 0; i < count; i++) { radiusBase[i] = radius[i]; if (radius[i] > largestRadius) largestRadius = radius[i]; pointBase[i] = p[i]; bounds += p[i]; } if (count == 1) bounds.EnlargeBy(0.5); //need to do some bounds check to check for bounds that are to small float expandBy = 0.0f; if (((bounds.pmax.x - bounds.pmin.x)/width) < 0.0001f) expandBy += 0.1f * width; if (((bounds.pmax.y - bounds.pmin.y)/width) < 0.0001f) expandBy += 0.1f * width; if (((bounds.pmax.z - bounds.pmin.z)/width) < 0.0001f) expandBy += 0.1f * width; bounds.EnlargeBy(expandBy); fXWidth = bounds.pmax.x - bounds.pmin.x; fYWidth = bounds.pmax.y - bounds.pmin.y; fZWidth = bounds.pmax.z - bounds.pmin.z; for (i = 0; i < count; i++) { //do XGrid //find out which cell we are in int index; index = FindCell(p[i].y,p[i].z,0,dx,dy); if ((index < 0) || (index >= widthXwidth)) DebugPrint("XGrid Error cell out of range %d\n",i); else { //see if cell exists if (xGrid[index] == NULL) xGrid[index] = new Grid(); //add that vertex to the cell xGrid[index]->index.Append(1,&i,10); xGrid[index]->hit=FALSE; } //do yGrid //find out which cell we are in index = FindCell(p[i].x,p[i].z,1,dx,dy); if ((index < 0) || (index >= widthXwidth)) DebugPrint("YGrid Error cell out of range %d\n",i); else { //see if cell exists if (yGrid[index] == NULL) yGrid[index] = new Grid(); //add that vertex to the cell yGrid[index]->index.Append(1,&i,10); yGrid[index]->hit=FALSE; } //do ZGrid //find out which cell we are in index = FindCell(p[i].x,p[i].y,2,dx,dy); if ((index < 0) || (index >= widthXwidth)) DebugPrint("ZGrid Error cell out of range %d\n",i); else { //see if cell exists if (zGrid[index] == NULL) zGrid[index] = new Grid(); //add that vertex to the cell zGrid[index]->index.Append(1,&i,10); zGrid[index]->hit=FALSE; } } xHitList.SetSize(count); yHitList.SetSize(count); zHitList.SetSize(count); }
bool KBagManager::IsEmpty(int nBagID, int nPos) const { const KCellBag* pCell = FindCell(nBagID, nPos); return pCell ? false : true; }