bool SpatialIndexManager::_AddObject(Object *newObject)
{
    uint32 finalBucket = getGrid()->AddObject(newObject);

    //DLOG(info) << "SpatialIndexManager::AddObject :: Object " << newObject->getId() << " added to bucket " <<  finalBucket;

    if(finalBucket == 0xffffffff)    {
        DLOG(info) << "SpatialIndexManager::AddObject :: Object " << newObject->getId() << " could not be added to the bucket because the bucket was invalid " <<  finalBucket;
        return false;
    }

	if(newObject->getType() == ObjType_Player)	{
		//enforce proper handling of players!!
		PlayerObject* player = static_cast<PlayerObject*>(newObject);
		_AddObject(player);
	}
   
	//get all Players in range and register as necessary

    ObjectListType playerList;
    getGrid()->GetPlayerViewingRangeCellContents(finalBucket, &playerList);

    for(ObjectListType::iterator i = playerList.begin(); i != playerList.end(); i++)    {
        PlayerObject* otherPlayer = static_cast<PlayerObject*>((*i));
        sendCreateObject(newObject,otherPlayer, false);

        if((newObject->getType() == ObjType_Creature) || (newObject->getType() == ObjType_NPC))	{
            gContainerManager->registerPlayerToContainer(newObject, otherPlayer);
        }
    }

    return true;
}
FloatLatchPropertyGeneralWidget::FloatLatchPropertyGeneralWidget(FloatLatch * comp, QWidget *parent, const char *name)
	:	ComponentPropertyGeneralWidget(comp, parent, name)
{
	
	QString tip;
	m_min = QMAX ( comp->getInputPack()->getNumberOfNotDeletableConnectors(),
	               comp->getOutputPack()->getNumberOfNotDeletableConnectors());

	
	m_channelsLabel = new QLabel(i18n("Channel count: "), getGrid(), "m_channelsLabel");
	CHECK_PTR(m_channelsLabel);
	
	m_channels = new QSpinBox(m_min, MAX_CHANNELS, 1, getGrid(), "m_channels");
	CHECK_PTR(m_channels);
	tip = i18n("Change count of channels here.");
	addToolTip(tip, m_channels, m_channelsLabel);
	addWhatsThis(tip, m_channels, m_channelsLabel);
	
	
	m_resetValueLabel = new QLabel(i18n("Reset value: "), getGrid(), "m_resetValueLabel");
	CHECK_PTR(m_resetValueLabel);
	
	m_resetValue = new KSimDoubleEdit(getGrid(), "m_resetValue");
	CHECK_PTR(m_resetValue);
	tip = i18n("Change the reset value of the component here.");
	addToolTip(tip, m_resetValue, m_resetValueLabel);
	addWhatsThis(tip, m_resetValue, m_resetValueLabel);
	
	
	// Setup value
	m_resetValue->setValue(comp->getResetValue());
	m_channels->setValue(comp->getInputPack()->getConnectorCount());
}
Exemple #3
0
Path MapManager::match(int gridId1, int gridId2) {
    if (gridId1 == gridId2 || gridId1 < 0 || gridId2 < 0) {
        return Path();
    }

    Grid* g1 = getGrid(gridId1);
    Grid* g2 = getGrid(gridId2);

    if (g1 == NULL || g2 == NULL) {
        return Path();
    }

    if (g1->imageId != g2->imageId) {
        return Path();
    }

    if (matchLine(gridId1, gridId2)) {
        m_path.push_back(gridId1);
        m_path.push_back(gridId2);
        CCLog("MapManager::matchLine done");
    } else if (matchTwoLine(gridId1, gridId2)) {
        CCLog("MapManager::matchTwoLine done");
    } else if (matchThreeLine(gridId1, gridId2)) {
        CCLog("MapManager::matchThreeLine done");
    }

    return m_path;
}
HippoGridInfo* HippoGridManager::getCurrentGrid() const
{
	HippoGridInfo* grid = getGrid(mCurrentGrid);
	if(!grid) 
	{
		grid = getGrid(mDefaultGrid);
	}
	return grid ? grid : &HippoGridInfo::FALLBACK_GRIDINFO;
}
Exemple #5
0
static int displayLight(gfluxstruct *gp)
{
    int polys = 0;
    double x,y;
    double z;
    double dx = 2.0/((double)_squares);
    double dy = 2.0/((double)_squares);

    glLoadIdentity();
    glRotatef(gp->anglex,1,0,0);
    glRotatef(gp->angley,0,1,0);
    glRotatef(gp->anglez,0,0,1);
    userRot(gp);
    glScalef(1,1,(GLfloat)_waveHeight);
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

    for(x=-1;x<0.9999;x+=dx) {
        glBegin(GL_QUAD_STRIP);
        for(y=-1;y<=1;y+=dy) {
            z = getGrid(gp, x,y,gp->time);
            genColour(z);
            glColor3fv(gp->colour);
            glNormal3f(
                getGrid(gp, x+dx,y,gp->time)-getGrid(gp, x-dx,y,gp->time),
                getGrid(gp, x,y+dy,gp->time)-getGrid(gp, x,y-dy,gp->time),
                1
            );
            glVertex3f(x,y,z);

            z = getGrid(gp, x+dx,y,gp->time);
            genColour(z);
            glColor3fv(gp->colour);
            glNormal3f(
                getGrid(gp, x+dx+dx,y,gp->time)-getGrid(gp, x,y,gp->time),
                getGrid(gp, x+dx,y+dy,gp->time)-getGrid(gp, x+dx,y-dy,gp->time),
                1
            );
            glVertex3f(x+dx,y,z);
            polys++;
        }
        glEnd();
    }

    if (! gp->button_down_p) {
      gp->time -= _speed;
      gp->anglex -= _rotationx;
      gp->angley -= _rotationy;
      gp->anglez -= _rotationz;
    }
    return polys;
}
Exemple #6
0
Scene *Resource::getScene(uint16 id) {
	int streamid = id;
	if (g_twin->getGameType() == GType_LBA2) {
		++streamid;
	}
	Scene *s = new Scene(_scene->createReadStreamForIndex(streamid));
	if (g_twin->getGameType() == GType_LBA) {
		s->setGrid(getGrid(id));
	} else if (!_scenes[id]._isIsland) {
		s->setGrid(getGrid(_scenes[id]._id));
	}
	s->setId(id);
	return s;
}
//==============================================================================================================
//
// get the Objects in range of the player ie everything in the Object Bucket
// NO players, NO creatures, NO regions
//
void SpatialIndexManager::getObjectsInRange(const Object* const object, ObjectSet* result_set, uint32 object_types, float range, bool cell_content) {
    ObjectList 	result_list;

    //see that we do not query more grids than necessary
    uint32_t CustomRange = range / (MAPWIDTH/GRIDWIDTH);

    if(CustomRange > VIEWRANGE) {
        CustomRange = VIEWRANGE;
    }

    if(CustomRange < 2)	{
        CustomRange = 2;
    }

    glm::vec3 position = object->getWorldPosition();
    getGrid()->GetCustomRangeCellContents(getGrid()->getCellId(position.x, position.z), CustomRange, &result_list, Bucket_Objects);

    std::for_each(result_list.begin(), result_list.end(), [object, position, result_set, object_types, range, cell_content] (Object* range_object) {
        if (range_object == object) {
            return;
        }

        ObjectType type = range_object->getType();

        if ((range_object->getType() & object_types) == static_cast<uint32_t>(type)) {
            if (glm::distance(object->getWorldPosition(), range_object->getWorldPosition()) <= range) {
                result_set->insert(range_object);
            }
        }

        // if its a building, add objects of our types it contains if wished
        if(type == ObjType_Building && cell_content) {
            ObjectList cells = static_cast<BuildingObject*>(range_object)->getAllCellChilds();

            std::for_each(cells.begin(), cells.end(), [=] (Object* cell) {
                ObjectType type = cell->getType();

                if ((type & object_types) == static_cast<uint32_t>(type)) {
                    TangibleObject* tangible = static_cast<TangibleObject*>(cell);

                    glm::vec3 tangible_position = tangible->getWorldPosition();

                    if (glm::distance(tangible_position, position) <= range) {
                        result_set->insert(tangible);
                    }
                }
            });
        }
    });
}
Exemple #8
0
static int displayWire(gfluxstruct *gp)
{
    int polys = 0;
    double x,y;
    double z;
    double dx1 = 2.0/((double)(_squares*_resolution)) - 0.00001;
    double dy1 = 2.0/((double)(_squares*_resolution)) - 0.00001;
    double dx2 = 2.0/((double)_squares) - 0.00001;
    double dy2 = 2.0/((double)_squares) - 0.00001;

    glLoadIdentity();
    glRotatef(gp->anglex,1,0,0);
    glRotatef(gp->angley,0,1,0);
    glRotatef(gp->anglez,0,0,1);
    userRot(gp);
    glScalef(1,1,(GLfloat)_waveHeight);
    glClear(GL_COLOR_BUFFER_BIT);

    for(x=-1;x<=1;x+=dx2) {
        glBegin(GL_LINE_STRIP);
        for(y=-1;y<=1;y+=dy1) {
            z = getGrid(gp, x,y,gp->time);
            genColour(z);
            glColor3fv(gp->colour);
            glVertex3f(x,y,z);
            polys++;
        }
        glEnd();
    }
    for(y=-1;y<=1;y+=dy2) {
        glBegin(GL_LINE_STRIP);
        for(x=-1;x<=1;x+=dx1) {
            z = getGrid(gp, x,y,gp->time);
            genColour(z);
            glColor3fv(gp->colour);
            glVertex3f(x,y,z);
            polys++;
        }
        glEnd();
    }

    if (! gp->button_down_p) {
      gp->time -= _speed;
      gp->anglex -= _rotationx;
      gp->angley -= _rotationy;
      gp->anglez -= _rotationz;
    }
    return polys;
}
Exemple #9
0
PUBLIC void table(EdiGrid *grid, cchar *optionString)
{
    if (grid == 0) {
        grid = getGrid();
    }
    espTable(getConn(), grid, optionString);
}
void HippoGridManager::setCurrentGrid(const std::string& grid)
{
	HippoGridInfo* prevGrid = getGrid(mCurrentGrid);
	GridIterator it = mGridInfo.find(grid);
	if (it != mGridInfo.end()) 
	{
		mCurrentGrid = grid;
	} 
	else if (!mGridInfo.empty()) 
	{
		llwarns << "Unknown grid '" << grid << "'. Setting to default grid." << llendl;
	    mCurrentGrid = mDefaultGrid;
	}
	if(mCurrentGridChangeSignal)
		(*mCurrentGridChangeSignal)(getGrid(mCurrentGrid),prevGrid);
}
Exemple #11
0
bool MapDraw::isVisible(short x, short y)
{
  int distFromCenter = 
    getGrid()->distanceBetween(x, y, getCenterX(), getCenterY());

  if (distFromCenter < (GRID_SIZE - 2 ))
    return true;
  else
    return false;
/*
// Come on Owen, you have their X / Y.

  // out of array bounds.
  if ((x<0) || (y < 0) || (y>=DEPTH) || (x>=WIDTH))
    return false;

  float pos = positionY( y );
  if (fabs(pos) > (GRID_SIZE-2))
    return false;

  pos = positionX( x );
  if (fabs(pos) > (GRID_SIZE-2))
    return false;
  return true;
*/
}
Exemple #12
0
Grid* Universe::getSouthGrid(unsigned int x, unsigned int y, unsigned int z) {
	int zWest = (z == 0 ? -1 : z - 1);

	if (zWest == -1)
		return NULL;
	else
		return getGrid(x, y, zWest);
}
Exemple #13
0
Grid* Universe::getDownGrid(unsigned int x, unsigned int y, unsigned int z) {
	int yWest = (y == 0 ? -1 : y - 1);

	if (yWest == -1)
		return NULL;
	else
		return getGrid(x, yWest, z);
}
bool HelloWorld::canInput(CCTouch* pTouch) {
    Grid* pGrid = getGrid(pTouch);
    if(pGrid) {
        return !pGrid->IsStatic();
    }
    
    return false;
}
Exemple #15
0
Grid* Universe::getNorthGrid(unsigned int x, unsigned int y, unsigned int z) {
	int zEast = (z == CONFIG::gridNumberZ - 1 ? -1 : z + 1);

	if (zEast == -1)
		return NULL;
	else
		return getGrid(x, y, zEast);
}
Exemple #16
0
Grid* Universe::getUpGrid(unsigned int x, unsigned int y, unsigned int z) {
	int yEast = (y == CONFIG::gridNumberY - 1 ? -1 : y + 1);

	if (yEast == -1)
		return NULL;
	else
		return getGrid(x, yEast, z);
}
Exemple #17
0
Grid* Universe::getWestGrid(unsigned int x, unsigned int y, unsigned int z) {
	int xWest = (x == 0 ? -1 : x - 1);

	if (xWest == -1)
		return NULL;
	else
		return getGrid(xWest, y, z);
}
Exemple #18
0
Grid* Universe::getEastGrid(unsigned int x, unsigned int y, unsigned int z) {
	int xEast = (x == CONFIG::gridNumberX - 1 ? -1 : x + 1);

	if (xEast == -1)
		return NULL;
	else
		return getGrid(xEast, y, z);
}
void PoissonDiskSampling::objectsPosition(WorldMap* map) {
	float minDistance = DISTANCE;

	std::vector <sf::Vector2f*> activePoints;
	//contenner in witch we are putting ceils with points.
	Grid grid;


	float cellSize = minDistance / SQRT2;
	grid.resize((mapWidth / cellSize), std::vector<bool>((mapHeight / cellSize), false));

	sf::Vector2f* firstPoint = randPoint();
	sf::Vector2i baseGrid;
	baseGrid = getGrid(firstPoint, cellSize);
	activePoints.push_back(firstPoint);

	positions[baseGrid.x][baseGrid.y].push_back(firstPoint);
	grid[baseGrid.x][baseGrid.y] = true;
	while (!activePoints.empty()) {

		sf::Vector2f* basePoint = (*activePoints.begin());
		baseGrid = getGrid(basePoint, cellSize);
		int z = KMAX;
		for (int i = 0; i < z; ++i) {

			sf::Vector2f* neighbour = randNeighbour(basePoint, minDistance);
			sf::Vector2i neighbourGrid = getGrid(neighbour, cellSize);

			if (neighbour->x>0 && neighbour->y > 0 && neighbour->x < mapWidth && neighbour->y < mapHeight) {
				if (map->getMap(neighbour->x, neighbour->y, 0)>127) {
					// if ok add to active, grid and objectsPosition
					if (checkNeighbour(neighbour, minDistance, grid, positions)) {
						activePoints.push_back(neighbour);
						grid[neighbourGrid.x][neighbourGrid.y] = true;
						positions[neighbourGrid.x][neighbourGrid.y].push_back(neighbour);
						ilosc++;
					}
				}
			}
		}

		// delete previous random from active
		activePoints.erase(activePoints.begin());
	}
}
Exemple #20
0
void GridCommand::writeProperties(QXmlStreamWriter* writer)
{
    AbstractCommand::writeProperties(writer);

    writer->writeTextElement("grid", QString::number(getGrid()));
    writer->writeTextElement("transitionDuration", QString::number(getTransitionDuration()));
    writer->writeTextElement("tween", getTween());
    writer->writeTextElement("defer", (getDefer() == true) ? "true" : "false");
}
HippoGridInfo *HippoGridManager::getCurrentGrid() const
{
	HippoGridInfo *grid = getGrid(mCurrentGrid);
	if (grid) {
		return grid;
	} else {
		return &HippoGridInfo::FALLBACK_GRIDINFO;
	}
}
/**
	Function that calculates the column in which an obstacle (i.e. grid indices
	corresponding to a value greater than 50 (obstacle) or equal to -1 (unknown))

	@param	x	float
	@param	y	float
	@return	row	int
*/
int Pathplanner::getXObstacleInPath()
{
    // ROS_INFO("%i, %i", indices[0], indices[1]);

    float currentX = this->currentPose.pose.position.x;
    float currentY = this->currentPose.pose.position.y;
    float currentZ = this->currentPose.pose.orientation.z;
    //float currentAngle = 2 * acos(currentZ) * (180/3.14);

    std::vector<int> indices = getGrid(currentX, currentY);

    ROS_INFO("X: %f, Y: %f", currentX, currentY);

    int column = indices[1];
    int row = indices[0];

    poseUpdated = false;

    if(this->sweepingRight)
    {
        for(; column < this->gridLength - 1; ++column)
        {
            int row = (indices[0] - 1 < 0) ? 0 : indices[0] - 10;
            int endI = (indices[0] + 1 >= this->gridLength) ? this->gridLength - 1 : indices[0] + 1;

            for(; row < endI; row++)
            {
                if(occupancyGrid[row][column] == 100) // || occupancyGrid[row][column] == -1)
                {
                    ROS_INFO("Obst Column: %i", column);
                    ROS_INFO("Current indices: %i, %i", row, column);
                    return column;
                }
            }
        }
    }
    else
    {
        for(; column >= 1; --column)
        {
            int row = (indices[0] - 1 < 0) ? 0 : indices[0] - 1;
            int endI = (indices[0] + 1 >= this->gridLength) ? this->gridLength - 1 : indices[0] + 1;

            for(; row < endI; row++)
            {
                if(occupancyGrid[row][column] == 100) //|| occupancyGrid[row][column] == -1)
                {
                    ROS_INFO("Obst Column: %i", column);
                    ROS_INFO("Current indices: %i, %i", row, column);
                    return column;
                }
            }
        }
    }

    //ROS_INFO("sweeping right? %i, obstacle column: %i, indices[0]: %i, indices[1]: %i", this->sweepingRight, column, indices[0], indices[1]);
}
//====================================================================================================================
//
// send to all players in chatrange
void SpatialIndexManager::sendToChatRange(Object* container, std::function<void (PlayerObject* const player)> callback) {
    //get the Objects and unregister as necessary
    ObjectListType player_list;
    getGrid()->GetChatRangeCellContents(container->getGridBucket(), &player_list);

    std::for_each(player_list.begin(), player_list.end(), [callback] (Object* object) {
        callback(static_cast<PlayerObject*>(object));
    });
}
bool LLGridManager::isSystemGrid(const std::string& grid)
{
	std::string grid_name = getGrid(grid);

	return (   !grid_name.empty()
			&& mGridList.has(grid)
			&& mGridList[grid].has(GRID_IS_SYSTEM_GRID_VALUE)
			&& mGridList[grid][GRID_IS_SYSTEM_GRID_VALUE].asBoolean()
			);
}
Exemple #25
0
int main()
{

	unsigned int  grid[20][20]  ; 
	getGrid(file, grid);
	
	std::cout << getMaxProduct(grid);
	std::cin.get();

}
bool SpatialIndexManager::_AddObject(PlayerObject *player)
{

    uint32 finalBucket = getGrid()->AddObject(player);

    DLOG(info) << "SpatialIndexManager::AddObject :: Player " << player->getId() << " added to bucket " <<  finalBucket;

    //any errors ?
    if(finalBucket == 0xffffffff)    {
        DLOG(info) << "SpatialIndexManager::AddObject :: Player " << player->getId() << " could not be added to the bucket because the bucket was invalid " <<  finalBucket;
        return false;
    }

    //now create it for everyone around and around for it

    ObjectListType playerList;
    getGrid()->GetViewingRangeCellContents(finalBucket, &playerList,(Bucket_Creatures|Bucket_Objects|Bucket_Players));

    for(ObjectListType::iterator i = playerList.begin(); i != playerList.end(); i++)    {
        //we just added ourselves to the grid - dont send a create to ourselves
        if(((*i)->getId() == player->getId()))		{
            continue;
        }

        //the object needs to be created no matter what
        sendCreateObject((*i), player, false);

        if(((*i)->getType() == ObjType_Creature) || ((*i)->getType() == ObjType_NPC))	{
            gContainerManager->registerPlayerToContainer((*i), player);
            continue;
        }

        if((*i)->getType() == ObjType_Player) 		{
			//create us for the other player
            PlayerObject* otherPlayer = static_cast<PlayerObject*>(*i);
            sendCreateObject(player, otherPlayer, false);

            gContainerManager->registerPlayerToContainer(otherPlayer, player);
            continue;
        }
    }
    return true;
}
void SpatialIndexManager::UpdateObject(Object *updateObject)
{

    uint32 oldBucket = updateObject->getGridBucket();
    uint32 newBucket = getGrid()->getCellId(updateObject->getWorldPosition().x, updateObject->getWorldPosition().z);

    // now process the spatial index update
    if(newBucket != oldBucket)	{
        DLOG(info) << "ContainerManager::UpdateObject :: " << updateObject->getId() <<"normal movement from bucket" << oldBucket << " to bucket" << newBucket;
        
        // test how much we moved if only one grid proceed normally
        if((newBucket == (oldBucket +1)) || (newBucket == (oldBucket -1)) ||
           (newBucket == (oldBucket + GRIDWIDTH)) || (newBucket == (oldBucket - GRIDWIDTH))	 ||
           (newBucket == (oldBucket + GRIDWIDTH +1)) || (newBucket == (oldBucket + GRIDWIDTH -1)) ||
           (newBucket == (oldBucket - GRIDWIDTH +1)) || (newBucket == (oldBucket - GRIDWIDTH -1)))	{
            // sets the new gridcell, updates subcells
            getGrid()->UpdateObject(updateObject);

            // remove us from the row we left
            _UpdateBackCells(updateObject,oldBucket);

            // create us for the row in which direction we moved
            _UpdateFrontCells(updateObject,oldBucket);
        } else {
            // we teleported destroy all and create everything new
            DLOG(info) << "ContainerManager::UpdateObject :: " << updateObject->getId() <<"teleportation from bucket" << oldBucket << " to bucket" << newBucket;

            // remove us from everything
            RemoveObjectFromWorld(updateObject);

            // sets the new gridcell, updates subcells
            getGrid()->AddObject(updateObject);

            // and add us freshly to the world
            _AddObject(updateObject);
        }
    }
    
    // Make sure to update any regions the object may be entering or leaving.
    getGrid()->updateRegions(updateObject);
}
Exemple #28
0
bool MapManager::matchLine(int gridId1, int gridId2) {
    //判断一条连线上是否能消除
    m_path.clear();

    Grid* g1 = getGrid(gridId1);
    Grid* g2 = getGrid(gridId2);

    if (g1 == NULL || g2 == NULL) {
        return false;
    }

    if (g1->row == g2->row) {
        return isRowEmpty(g1->row, g1->col, g2->col);
    }

    if (g1->col == g2->col) {
        return isColEmpty(g1->col, g1->row, g2->row);
    }

    return false;
}
Exemple #29
0
void gridToGrid(phys::Collision* c, phys::RigidBody *a, phys::RigidBody *b)
{
    auto gridA = reinterpret_cast<GridShape*>(a->getShape());
    auto gridB = reinterpret_cast<GridShape*>(b->getShape());

    bool polyA;

    if (gridA->getGrid()->getWrapX() && gridB->getGrid()->getWrapX())
    {
        return;
    }
    else if (gridA->getGrid()->getWrapX())
    {
        polyA = false;
    }
    else if (gridB->getGrid()->getWrapX())
    {
        polyA = true;
    }

    if (polyA)
    {
        a->setShape(&gridA->getGrid()->mPolyShape); // Use B's polygon shape
        gridToPolygon(c, b, a);
        a->setShape(gridA); // Put B's grid shape back
    }
    else
    {
        b->setShape(&gridB->getGrid()->mPolyShape); // Use B's polygon shape
        gridToPolygon(c, a, b);
        b->setShape(gridB); // Put B's grid shape back
    }
}
std::string LLGridManager::getLoginPage(const std::string& grid)
{
	std::string grid_login_page;
	std::string grid_name = getGrid(grid);
	if (!grid_name.empty())
	{
		grid_login_page = mGridList[grid_name][GRID_LOGIN_PAGE_VALUE].asString();
	}
	else
	{
		LL_WARNS("GridManager")<<"invalid grid '"<<grid<<"'"<<LL_ENDL;
	}
	return grid_login_page;
}