Exemplo n.º 1
0
ComplementarityRestraint::GridObject *ComplementarityRestraint::get_grid_object(
    core::RigidBody rb, const kernel::ParticlesTemp &a, ObjectKey ok,
    double thickness, double value, double interior_thickness,
    double voxel) const {
  IMP_USAGE_CHECK(!a.empty(), "No particles passed for excluded volume");
  for (unsigned int i = 1; i < a.size(); ++i) {
    IMP_USAGE_CHECK(core::RigidMember(a[0]).get_rigid_body() ==
                        core::RigidMember(a[i]).get_rigid_body(),
                    "Not all particles are from the same rigid body.");
  }
  if (!rb->has_attribute(ok)) {
    IMP_LOG_TERSE("Creating grid for rigid body " << rb->get_name()
                                                  << std::endl);
    IMP::algebra::DenseGrid3D<float> grid =
        get_grid(a, thickness, value, interior_thickness, voxel);
    IMP_LOG_TERSE("Grid has size " << grid.get_number_of_voxels(0) << ", "
                                   << grid.get_number_of_voxels(1) << ", "
                                   << grid.get_number_of_voxels(2)
                                   << std::endl);
    base::Pointer<GridObject> n(new GridObject(
        GridPair(rb.get_reference_frame().get_transformation_to(), grid)));
    rb->add_cache_attribute(ok, n);
  }
  IMP_CHECK_OBJECT(rb->get_value(ok));
  IMP_INTERNAL_CHECK(dynamic_cast<GridObject *>(rb->get_value(ok)),
                     "The saved grid is not a grid.");
  return dynamic_cast<GridObject *>(rb->get_value(ok));
}
Exemplo n.º 2
0
void
Map::EnsureGridLoadedForPlayer(const Cell &cell, Player *player, bool add_player)
{
	EnsureGridCreated(GridPair(cell.GridX(), cell.GridY()));
	NGridType *grid = getNGrid(cell.GridX(), cell.GridY());

	assert(grid != NULL);
	if( !isGridObjectDataLoaded(cell.GridX(), cell.GridY()) )
	{
		if( player != NULL )
		{
			player->SendDelayResponse(MAX_GRID_LOAD_TIME);
			DEBUG_LOG("Player %s enter cell[%u,%u] triggers of loading grid[%u,%u] on map %u", player->GetName(), cell.CellX(), cell.CellY(), cell.GridX(), cell.GridY(), i_id);
		}
		else
		{
			DEBUG_LOG("Player nearby triggers of loading grid [%u,%u] on map %u", cell.GridX(), cell.GridY(), i_id);
		}

		ObjectGridLoader loader(*grid, this, cell);
		loader.LoadN();
		setGridObjectDataLoaded(true, cell.GridX(), cell.GridY());

		ResetGridExpiry(*getNGrid(cell.GridX(), cell.GridY()), 0.1f);
		grid->SetGridState(GRID_STATE_ACTIVE);

		if( add_player && player != NULL )
			(*grid)(cell.CellX(), cell.CellY()).AddWorldObject(player, player->GetAccountId());
	}
	else if( player && add_player )
		AddToGrid(player, grid, cell);
}
Exemplo n.º 3
0
void
Map::Remove(T *obj, bool remove)
{
	CellPair p = LeGACY::ComputeCellPair(obj->GetPositionX(), obj->GetPositionY());
	if(p.x_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP || p.y_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP)
	{
		sLog.outError("Map::Remove: Object " I64FMTD " have invalid coordinates X: %f Y:%f grid cell [%u:%u]", obj->GetGUID(), obj->GetPositionX(), obj->GetPositionY(), p.x_coord, p.y_coord);
		return;
	}

	Cell cell(p);
	if( !loaded(GridPair(cell.data.Part.grid_x, cell.data.Part.grid_y)) )
		return;

	DEBUG_LOG("Remove object " I64FMTD " from grid[%u,%u]", obj->GetGUID(), cell.data.Part.grid_x, cell.data.Part.grid_y);
	NGridType *grid = getNGrid(cell.GridX(), cell.GridY());
	assert( grid != NULL );

	RemoveFromGrid(obj,grid,cell);
	obj->RemoveFromWorld();

	UpdateObjectVisibility(obj,cell,p);

	if( remove )
	{
		DeleteFromWorld(obj);
	}
}
Exemplo n.º 4
0
void Map::MessageBroadcast(Player *player, WorldPacket *msg, bool to_self, bool own_team_only)
{
	//sLog.outDetail("Map::MessageBroadcast Player");
	CellPair p = LeGACY::ComputeCellPair(player->GetPositionX(), player->GetPositionY());

	if(p.x_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP || p.y_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP )
	{
		sLog.outError("Map::MessageBroadcast: Player '%s' (%u) have invalid coordinates X:%f Y:%f grid cell [%u:%u]", player->GetName(), player->GetAccountId(), player->GetPositionX(), player->GetPositionY(), p.x_coord, p.y_coord);
		return;
	}

	Cell cell(p);
	cell.data.Part.reserved = CENTER_DISTRICT;

	if( !loaded(GridPair(cell.data.Part.grid_x, cell.data.Part.grid_y)) ) {
		sLog.outDetail("Not loaded");
	//	return;
	}

	LeGACY::MessageDeliverer post_man(*player, msg, to_self, own_team_only);
	TypeContainerVisitor<LeGACY::MessageDeliverer, WorldTypeMapContainer > message(post_man);
	CellLock<ReadGuard> cell_lock(cell, p);
	cell_lock->Visit(cell_lock, message, *this);

}
Exemplo n.º 5
0
void
Map::Add(T *obj)
{
	CellPair p = LeGACY::ComputeCellPair(obj->GetPositionX(), obj->GetPositionY());

	assert(obj);

	if(p.x_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP || p.y_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP)
	{
		sLog.outError("Map::Add: Object " I64FMTD " have invalid coordinates X:%u Y:%u grid cell [%u,%u]", obj->GetGUID(), obj->GetPositionX(), obj->GetPositionY(), p.x_coord, p.y_coord);
		return;
	}

	Cell cell(p);
	EnsureGridCreated(GridPair(cell.GridX(), cell.GridY()));
	NGridType *grid = getNGrid(cell.GridX(), cell.GridY());
	assert( grid != NULL );

	AddToGrid(obj,grid,cell);
	obj->AddToWorld();

	DEBUG_LOG("Object %u enters grid[%u,%u]", GUID_LOPART(obj->GetGUID()), cell.GridX(), cell.GridY());

	UpdateObjectVisibility(obj,cell,p);

	AddNotifier(obj,cell,p);
}
Exemplo n.º 6
0
void Map::MessageBroadcast(WorldObject *obj, WorldPacket *msg)
{
//	sLog.outString("Map::MessageBroadcast WorldObject");
	CellPair p = LeGACY::ComputeCellPair(obj->GetPositionX(), obj->GetPositionY());

	if(p.x_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP || p.y_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP )
	{
		sLog.outError("Map::MessageBroadcast: Object " I64FMTD " have invalid coordinates X:%f Y:%f grid cell [%u,%u]", obj->GetGUID(), obj->GetPositionX(), obj->GetPositionY(), p.x_coord, p.y_coord);
		return;
	}

	Cell cell(p);
	cell.data.Part.reserved = CENTER_DISTRICT;
	cell.SetNoCreate();

	if( !loaded(GridPair(cell.data.Part.grid_x, cell.data.Part.grid_y)) )
		return;

	LeGACY::ObjectMessageDeliverer post_man(*obj, msg);
	TypeContainerVisitor<LeGACY::ObjectMessageDeliverer, WorldTypeMapContainer > message(post_man);
	CellLock<ReadGuard> cell_lock(cell, p);
	cell_lock->Visit(cell_lock, message, *this);

}