示例#1
0
/**
Return the node that is accessible and best fits the true value.
If there are no accessible coordinates, simply leave the node unchanged.
*/
void AStarGraph::findBestMatch(AStarNode& node, float* trueValue) {
	std::vector<AStarNode> validNodes;
	std::vector<float> distances; // index will correspond to validNodes

	if (!isAccessible(node)) {
		for (int a = -1; a <= 1; a++) {
			AStarNode tempNode;
			for (int b = -1; b <= 1; b++) {
				tempNode.x = node.x + a;
				tempNode.y = node.y + b;
			}
			if (isAccessible(tempNode)) { //add valid nodes to vector and keep track of distance to true location
				validNodes.push_back(tempNode);
				float distance = getDistance(tempNode, trueValue);
				distances.push_back(distance);
			}
		}
		if (validNodes.size() > 0) { 
			int smallest = 0;
			AStarNode newTemp;
			for (int i = 0; i < validNodes.size(); i++) {
				if (distances[i] < distances[smallest]) {
					smallest = i;
				}
			}
			newTemp = validNodes[smallest]; // change node to closest accessible node
			node.x = newTemp.x;
			node.y = newTemp.y;
		}
	}
}
示例#2
0
文件: access.c 项目: rbanderton/dmd
/********************************************************
 * Helper function for checkAccess()
 * Returns:
 *      false   is not accessible
 *      true    is accessible
 */
static bool isAccessible(
        Dsymbol *smember,
        Dsymbol *sfunc,
        AggregateDeclaration *dthis,
        AggregateDeclaration *cdscope)
{
    assert(dthis);

#if 0
    printf("isAccessible for %s.%s in function %s() in scope %s\n",
        dthis->toChars(), smember->toChars(),
        sfunc ? sfunc->toChars() : "NULL",
        cdscope ? cdscope->toChars() : "NULL");
#endif
    if (hasPrivateAccess(dthis, sfunc) ||
        isFriendOf(dthis, cdscope))
    {
        if (smember->toParent() == dthis)
            return true;

        if (ClassDeclaration *cdthis = dthis->isClassDeclaration())
        {
            for (size_t i = 0; i < cdthis->baseclasses->dim; i++)
            {
                BaseClass *b = (*cdthis->baseclasses)[i];
                Prot access = getAccess(b->base, smember);
                if (access.kind >= PROTprotected ||
                    isAccessible(smember, sfunc, b->base, cdscope))
                {
                    return true;
                }
            }
        }
    }
    else
    {
        if (smember->toParent() != dthis)
        {
            if (ClassDeclaration *cdthis = dthis->isClassDeclaration())
            {
                for (size_t i = 0; i < cdthis->baseclasses->dim; i++)
                {
                    BaseClass *b = (*cdthis->baseclasses)[i];
                    if (isAccessible(smember, sfunc, b->base, cdscope))
                        return true;
                }
            }
        }
    }
    return false;
}
示例#3
0
    //-----------------------------------------------------------------------
    String PixelUtil::getBNFExpressionOfPixelFormats(bool accessibleOnly)
    {
        // Collect format names sorted by length, it's required by BNF compiler
        // that similar tokens need longer ones comes first.
        typedef multimap<String::size_type, String>::type FormatNameMap;
        FormatNameMap formatNames;
        for (size_t i = 0; i < PF_COUNT; ++i)
        {
            PixelFormat pf = static_cast<PixelFormat>(i);
            if (!accessibleOnly || isAccessible(pf))
            {
                String formatName = getFormatName(pf);
                formatNames.insert(std::make_pair(formatName.length(), formatName));
            }
        }

        // Populate the BNF expression in reverse order
        String result;
        // Note: Stupid M$ VC7.1 can't dealing operator!= with FormatNameMap::const_reverse_iterator.
        for (FormatNameMap::reverse_iterator j = formatNames.rbegin(); j != formatNames.rend(); ++j)
        {
            if (!result.empty())
                result += " | ";
            result += "'" + j->second + "'";
        }

        return result;
    }
示例#4
0
static void printAgtReadMethodDecls(FILE *f, SmiModule *smiModule)
{
    SmiNode   *smiNode;
    int       cnt = 0;

    for (smiNode = smiGetFirstNode(smiModule, SMI_NODEKIND_ANY);
	 smiNode;
	 smiNode = smiGetNextNode(smiNode, SMI_NODEKIND_ANY)) {
	if (isGroup(smiNode) && isAccessible(smiNode)) {
	    cnt++;
	    if (cnt == 1) {
		fprintf(f,
			"/*\n"
			" * Forward declaration of read methods for groups of scalars and tables:\n"
			" */\n\n");
	    }
	    fprintf(f,
		    "static unsigned char *\nread_%s_stub(struct variable *,"
		    " oid *, size_t *, int, size_t *, WriteMethod **);\n",
		    smiNode->name);
	}
    }
    
    if (cnt) {
	fprintf(f, "\n");
    }
}
示例#5
0
static void printHeaderTypedefs(FILE *f, SmiModule *smiModule)
{
    SmiNode   *smiNode;
    int       cnt = 0;
    char      *cModuleName;
    char      *cSmiNodeName;
    
    for (smiNode = smiGetFirstNode(smiModule, SMI_NODEKIND_ANY);
	 smiNode;
	 smiNode = smiGetNextNode(smiNode, SMI_NODEKIND_ANY)) {
	if (isGroup(smiNode) && isAccessible(smiNode)) {
	    cnt++;
	    printHeaderTypedef(f, smiModule, smiNode);
	}
    }
    
    if (cnt) {
	fprintf(f, "\n");
    }

    if (cnt) {
	/*
	 * Should this go into the agent implementation module?
	 */
	cModuleName = translateLower(smiModule->name);
	fprintf(f, "typedef struct %s {\n", cModuleName);
	for (smiNode = smiGetFirstNode(smiModule, SMI_NODEKIND_ANY);
	     smiNode;
	     smiNode = smiGetNextNode(smiNode, SMI_NODEKIND_ANY)) {
	    if (isGroup(smiNode) && isAccessible(smiNode)) {
		cSmiNodeName = translate(smiNode->name);
		if (smiNode->nodekind == SMI_NODEKIND_ROW) {
		    fprintf(f, "    %s_t\t*%s;\n", cSmiNodeName, cSmiNodeName);
		} else {
		    fprintf(f, "    %s_t\t%s;\n", cSmiNodeName, cSmiNodeName);
		}
		xfree(cSmiNodeName);
	    }
	}
	fprintf(f, "} %s_t;\n\n", cModuleName);
	xfree(cModuleName);
    }
}
示例#6
0
	LineBasedFile::LineBasedFile(const String& filename, File::OpenMode open_mode, bool trim_whitespaces)
		: File(),
			line_number_(0),
			trim_whitespaces_(trim_whitespaces)
	{
		File::open(filename, open_mode);
		if (!isAccessible())
		{
			throw Exception::FileNotFound(__FILE__, __LINE__, filename);
		}
	}
示例#7
0
 void EditorTile::show()
 {
     if (!S(Game)->getInterface()->isMouseOver())
     {
         EditorMap* map = (EditorMap*) S(Game)->getMap();
         if (map->usingBrush())
         {
             float d = getBrushEffect();
             if (d > 0 && d <= 1)
                 showColored(engine::graphics::Color((1 - d) * 127 + 128, (1 - d) * 127 + 128, (1 - d) * 127 + 128));
             
             else
                 Tile::show();
         }
         else if (map->puttingBuilding())
         {
             engine::Vector2d pointerPosition = map->getPointerPosition();
             int x = pointerPosition.getRoundX();
             int y = pointerPosition.getRoundY();
             entity::BuildingModel* buildingModel = map->getBuildingModel();
             if (x - buildingModel->getSize() < (int)m_x && (int)m_x <= x && y - buildingModel->getSize() < (int)m_y && (int)m_y <= y)
             {
                 if (buildingModel->canBeBuilt(map, x, y))
                 {
                     showColored(engine::graphics::Color(128, 128, 128));
                 }
                 else
                 {
                     Tile* tile = map->getTile(x, y);
                     if (!isAccessible() || (tile != NULL && tile->getZ() != getZ()))
                         showColored(engine::graphics::Color(255, 0, 0));
                         
                     else
                         showColored(engine::graphics::Color(128, 128, 128));
                 }
             }
             else
                 Tile::show();
         }
         else if (map->puttingUnit())
         {
             m_color->use();
             
             MapObject::show();
             
             if (m_doodad != NULL)
                 m_doodad->show();
         }
         else
             Tile::show();
     }
     else
         Tile::show();
 }
示例#8
0
	void CellGrid::getAccessibleCoordinates(const ModelCoordinate& curpos, std::vector<ModelCoordinate>& coordinates) {
		coordinates.clear();
		for (int32_t x = curpos.x - 1; x <= curpos.x + 1; x++) {
			for (int32_t y = curpos.y - 1; y <= curpos.y + 1; y++) {
				ModelCoordinate pt(x, y);
				if (isAccessible(curpos, pt)) {
					coordinates.push_back(pt);
				}
			}
		}
	}
示例#9
0
	float HexGrid::getAdjacentCost(const ModelCoordinate& curpos, const ModelCoordinate& target) {
		assert(isAccessible(curpos, target));
		if (curpos == target) {
			return 0;
		} else if (curpos.y == target.y) {
			return m_xscale;
		} else {
			double a = VERTICAL_MULTIP * m_yscale;
			double b = HEX_TO_EDGE * m_xscale;
			return sqrt((a * a) + (b * b));
		}
	}
示例#10
0
bool IHttpDirectory::process(shared_ptr<HttpSession> session, const HttpPath &path)
{
	if(isActive() == false)
		return false;

	if(isAccessible(session) == false)
		return false;

	if(handle(session, path))
		return true;

	shared_ptr<IHttpDirectory> directory = getDirectory(path.getDirectory());
	if(directory != nullptr && directory->process(session, path.getTarget()))
		return true;

	return false;
}
示例#11
0
static void printMgrGetMethods(FILE *f, SmiModule *smiModule)
{
    SmiNode   *smiNode;
    int       cnt = 0;
    
    for (smiNode = smiGetFirstNode(smiModule, SMI_NODEKIND_ANY);
	 smiNode;
	 smiNode = smiGetNextNode(smiNode, SMI_NODEKIND_ANY)) {
	if (isGroup(smiNode) && isAccessible(smiNode)) {
	    cnt++;
	    printMgrGetMethod(f, smiModule, smiNode);
	}
    }
    
    if (cnt) {
	fprintf(f, "\n");
    }
}
示例#12
0
文件: dump-sql.c 项目: pan0007/libsmi
static void printCreateTables(SmiModule *smiModule)
{
    SmiNode   *smiNode;
    int       cnt = 0;
    
    for(smiNode = smiGetFirstNode(smiModule, SMI_NODEKIND_ANY);
	smiNode;
	smiNode = smiGetNextNode(smiNode, SMI_NODEKIND_ANY)) {
	if (isGroup(smiNode) && isAccessible(smiNode)) {
	    cnt++;
	    printCreateTable(smiNode);
	}
    }
    
    if (cnt) {
	printf("\n");
    }
}
示例#13
0
static void printAgtReadMethods(FILE *f, SmiModule *smiModule)
{
    SmiNode   *smiNode;
    int       cnt = 0;
    
    for (smiNode = smiGetFirstNode(smiModule, SMI_NODEKIND_ANY);
	 smiNode;
	 smiNode = smiGetNextNode(smiNode, SMI_NODEKIND_ANY)) {
	if (isGroup(smiNode) && isAccessible(smiNode)) {
	    cnt++;
	    if (cnt == 1) {
		fprintf(f,
			"/*\n"
			" * Read methods for groups of scalars and tables:\n"
			" */\n\n");
	    }
	    printAgtReadMethod(f, smiNode);
	}
    }
    
    if (cnt) {
	fprintf(f, "\n");
    }
}
示例#14
0
bool Field::ShouldCompile(void) const
{
    return isAccessible( );
}
示例#15
0
bool Global::ShouldCompile(void) const
{
    return isAccessible( );
}
示例#16
0
文件: access.c 项目: rbanderton/dmd
/*******************************
 * Do access check for member of this class, this class being the
 * type of the 'this' pointer used to access smember.
 * Returns true if the member is not accessible.
 */
bool checkAccess(AggregateDeclaration *ad, Loc loc, Scope *sc, Dsymbol *smember)
{
    FuncDeclaration *f = sc->func;
    AggregateDeclaration *cdscope = sc->getStructClassScope();

#if LOG
    printf("AggregateDeclaration::checkAccess() for %s.%s in function %s() in scope %s\n",
        ad->toChars(), smember->toChars(),
        f ? f->toChars() : NULL,
        cdscope ? cdscope->toChars() : NULL);
#endif

    Dsymbol *smemberparent = smember->toParent();
    if (!smemberparent || !smemberparent->isAggregateDeclaration())
    {
#if LOG
        printf("not an aggregate member\n");
#endif
        return false;                   // then it is accessible
    }

    // BUG: should enable this check
    //assert(smember->parent->isBaseOf(this, NULL));

    bool result;
    Prot access;
    if (smemberparent == ad)
    {
        Prot access2 = smember->prot();
        result = access2.kind >= PROTpublic ||
                hasPrivateAccess(ad, f) ||
                isFriendOf(ad, cdscope) ||
                (access2.kind == PROTpackage && hasPackageAccess(sc, ad)) ||
                ad->getAccessModule() == sc->module;
#if LOG
        printf("result1 = %d\n", result);
#endif
    }
    else if ((access = getAccess(ad, smember)).kind >= PROTpublic)
    {
        result = true;
#if LOG
        printf("result2 = %d\n", result);
#endif
    }
    else if (access.kind == PROTpackage && hasPackageAccess(sc, ad))
    {
        result = true;
#if LOG
        printf("result3 = %d\n", result);
#endif
    }
    else
    {
        result = isAccessible(smember, f, ad, cdscope);
#if LOG
        printf("result4 = %d\n", result);
#endif
    }
    if (!result)
    {
        ad->error(loc, "member %s is not accessible", smember->toChars());
        //printf("smember = %s %s, prot = %d, semanticRun = %d\n",
        //        smember->kind(), smember->toPrettyChars(), smember->prot(), smember->semanticRun);
        return true;
    }
    return false;
}
bool Constructor::ShouldCompile(void) const
{
    return isAccessible( );
}
bool Function::ShouldCompile(void) const
{
    return isAccessible( );
}
示例#19
0
bool Solid::StorageAccess::isAccessible() const
{
    Q_D(const StorageAccess);
    return_SOLID_CALL(Ifaces::StorageAccess *, d->backendObject(), false, isAccessible());
}
示例#20
0
bool Enum::ShouldCompile(void) const
{
    return isAccessible( );
}
示例#21
0
bool Class::ShouldCompile(void) const
{
    return isAccessible( ) && !isNativeType( m_qualifiedName );
}
bool CollisionCheckGridMapPlugin::isAccessible(const State& next, const State& /*current*/) const
{
  return isAccessible(next);
}