Пример #1
0
void DECFile::load(Common::SeekableSubReadStreamEndian &dec, const Common::String &fileName) {
	dec.skip(2); // Unused

	int16 backdropCount = dec.readUint16();
	int16 layerCount    = dec.readUint16();

	// Sanity checks
	if (backdropCount > 1)
		warning("DECFile::load(): More than one backdrop (%d) in file \"%s\"",
		        backdropCount, fileName.c_str());
	if (layerCount < 1)
		warning("DECFile::load(): Less than one layer (%d) in file \"%s\"",
		        layerCount, fileName.c_str());

	// Load the backdrop
	if (backdropCount > 0) {
		loadBackdrop(dec);

		// We only support one backdrop, skip the rest
		dec.skip((backdropCount - 1) * (13 + (_hasPadding ? 1 : 0)));
	}

	// Load the layers
	_layers.reserve(MAX(0, layerCount - 1));
	for (int i = 0; i < layerCount - 1; i++)
		_layers.push_back(loadLayer(dec));

	// Load the backdrop parts
	if (backdropCount > 0)
		loadParts(dec);
}
Пример #2
0
void QgsAttributeTableModel::attributeDeleted( int idx )
{
  QgsDebugMsg( "entered." );
  loadAttributes();
  loadLayer();
  emit modelChanged();
}
Пример #3
0
void SoftmaxLayer::load(util::InputTarArchive& archive,
    const util::PropertyTree& properties)
{
    *_inputSize  = Dimension::fromString(properties["input-size"]);
    _precision   = matrix::Precision::fromString(properties["precision"]);

    loadLayer(archive, properties);
}
Пример #4
0
bool Cell::load(const std::string& filename)
{
    std::cout << "Attempting to load '" << filename << "'... (LEGACY)\n";
    
    //Load master layer (.map)
    if (!loadLayer(filename, 0, true)) return false;
    //Load all .maplayers
    for (int i = 1; i < NUM_LAYERS; ++i)
    {
        std::ostringstream layerFileName;
        layerFileName << filename << "layer" << i;
        if (!loadLayer(layerFileName.str(), i, false)) return false;
    }
    std::cout << "Successfully loaded '" << filename << "'\n";
    calculateDifficulty();
    return true;
}
Пример #5
0
void CTCDecoderLayer::load(util::InputTarArchive& archive, const util::PropertyTree& properties)
{
    _implementation->setInputSize(Dimension::fromString(properties["input-size"]));
    _implementation->setPrecision(*matrix::Precision::fromString(properties["precision"]));
    _implementation->setBeamSize(properties.get<size_t>("beam-size"));

    loadLayer(archive, properties);
}
Пример #6
0
bool GameLayer::init(){
    
    if ( !LayerColor::initWithColor(Color4B(255, 255, 255, 255)) )
    {
        return false;
    }
    

    
    visibleSize = Director::getInstance()->getVisibleSize();

    gun = Gun::create();
    gun->setScale(0.25);
    gun->setPosition(Vec2(120,visibleSize.height/2-180));
    addChild(gun,1);

    touchTest();    //触摸检测
    
    
    this->schedule(schedule_selector(GameLayer::checkCollision), 0.1);//启动检测碰撞的函数

    ////////////////////////////

    //文件解析
    str="Data.xml";
//    xmller.giveBirthTo(str);
    xmller.createwithxmlfile(str);
    
    //更换背景
    std::string a= xmller.getLevel01();
    int i = atoi(a.c_str());

    log("哇擦了%d",i);
    auto levelNumber = __String::createWithFormat("bg%d.png",i);
    log("%s",levelNumber->getCString());
    auto bg = Sprite::create(levelNumber->getCString());
    bg->setPosition(visibleSize/2);
    
    auto fade1 = FadeTo::create(2.0, 150);
    auto fade2 = FadeIn::create(2.0);
    auto seq = RepeatForever::create( Sequence::create(fade1,fade2,NULL));
    bg->runAction(seq);
    addChild(bg);
    
    loadLayer();    //加载场景
    addSprite();    //添加界面UI元素
    
    //拿到子弹数量,给全局变量
    auto bulletnm = xmller.getLevel03();
    int b = atoi(bulletnm.c_str());
    bulletNumber = b;

    butemp =0;
    return true;
}
Пример #7
0
QgsAttributeTableModel::QgsAttributeTableModel( QgsVectorLayer *theLayer, QObject *parent )
    : QAbstractTableModel( parent )
{
  mFeat.setFeatureId( std::numeric_limits<int>::min() );
  mLayer = theLayer;
  loadAttributes();

  connect( mLayer, SIGNAL( attributeValueChanged( int, int, const QVariant& ) ), this, SLOT( attributeValueChanged( int, int, const QVariant& ) ) );
  connect( mLayer, SIGNAL( featureAdded( int ) ), this, SLOT( featureAdded( int ) ) );
  connect( mLayer, SIGNAL( featureDeleted( int ) ), this, SLOT( featureDeleted( int ) ) );
  connect( mLayer, SIGNAL( attributeAdded( int ) ), this, SLOT( attributeAdded( int ) ) );
  connect( mLayer, SIGNAL( attributeDeleted( int ) ), this, SLOT( attributeDeleted( int ) ) );

  loadLayer();
}
Пример #8
0
int Map::load(std::string fname) {
	FileParser infile;
	maprow *cur_layer = NULL;

	clearEvents();
	clearLayers();
	clearQueues();

	// @CLASS Map|Description of maps/
	if (!infile.open(fname))
		return 0;

	this->filename = fname;

	while (infile.next()) {
		if (infile.new_section) {

			// for sections that are stored in collections, add a new object here
			if (infile.section == "enemy")
				enemies.push(Map_Enemy());
			else if (infile.section == "enemygroup")
				enemy_groups.push(Map_Group());
			else if (infile.section == "npc")
				npcs.push(Map_NPC());
			else if (infile.section == "event")
				events.push_back(Event());

		}
		if (infile.section == "header")
			loadHeader(infile);
		else if (infile.section == "layer")
			loadLayer(infile, &cur_layer);
		else if (infile.section == "enemy")
			loadEnemy(infile);
		else if (infile.section == "enemygroup")
			loadEnemyGroup(infile, &enemy_groups.back());
		else if (infile.section == "npc")
			loadNPC(infile);
		else if (infile.section == "event")
			EventManager::loadEvent(infile, &events.back());
	}

	infile.close();

	return 0;
}
Пример #9
0
ErrorCode LoadedMap::loadFile()
{
    Logger.logMessage(LOG_STATE, LOG_MAP, "LoadedMap::loadFile start\n");

    int ret = m_doc.LoadFile(m_filename.c_str());

    if(ret != 0)
    {
        return ERROR_OPENING_FILE;
    }

    XMLElement *root_map = m_doc.FirstChildElement(XML_MAP.c_str());
    assert(root_map);
    loadMap(root_map);

    XMLElement *child = root_map->FirstChildElement();
    assert(child);
    while(child != NULL)
    {
        if(child->Name() == XML_TILESET)
        {
            loadTileset(child);
        }
        else if(child->Name() == XML_LAYER)
        {
            loadLayer(child);
        }
        else if(child->Name() == XML_OBJECTGROUP)
        {
            loadObjectGroup(child);
        }
        child = child->NextSiblingElement();
    }

    Logger.logMessage(LOG_STATE, LOG_MAP, "LoadedMap::loadFile end\n");

    printMapInformation();
    return OK;
}
void QgsAttributeTableMemoryModel::layerDeleted()
{
  QgsDebugMsg( "entered." );
  loadLayer();
}
void QgsAttributeTableMemoryModel::featureAdded( QgsFeatureId fid )
{
  QgsDebugMsg( "entered." );
  Q_UNUSED( fid );
  loadLayer();
}
Пример #12
0
// An old map may be passed in to avoid reloading the images for the tilesets.
struct Map *loadMap(const char *path, SDL_Renderer *renderer, struct Map *reuse_images){
    // Load the 
    int size;
    struct Turbo_Value mapValue;
    struct Map *map = NULL;
    
    char *const data = BufferFile(path, &size);
    if(!data){
        fprintf(stderr, "Could not open map file %s\n", path);
        return NULL;
    }

    assert(path);

    Turbo_Parse(&mapValue, data, data + size);
    
    if(mapValue.type == TJ_Error){
        Turbo_WriteError(&mapValue, stderr, 0);
        goto ending;
    }

    if(mapValue.type != TJ_Object){
        fprintf(stderr, "Invalid map object\n");
        goto ending;
    }
    
    // Load the tilesets first.
    {
        unsigned i;
        const struct Turbo_Value *const tilesetArray = jsonFindObjectValue(&mapValue, "tilesets");
        if(!tilesetArray){
            fprintf(stderr, "Invalid map object: no tilesets\n");
            goto ending;
        }
        else if(tilesetArray->type == TJ_Error){
            Turbo_WriteError(&mapValue, stderr, 0);
            goto ending;
        }
        else if(tilesetArray->type != TJ_Array){
            fprintf(stderr, "Invalid tileset array\n");
            goto ending;
        }
        
        map = malloc(sizeof(struct Map));
        map->numTilesets = tilesetArray->length;
        map->tilesets = calloc(map->numTilesets, sizeof(struct Tileset));
        
        // Load all tilesets.
        for(i = 0; i < map->numTilesets; i++){
            if(!loadTileset(map->tilesets + i, renderer, tilesetArray->value.array + i, reuse_images)){
                // Free what we've loaded so far.
                unsigned e;
                for(e = 0; e != i; e++){
                    unsigned j;

                    // If we reused an existing image, don't touch it.
                    for(j = 0; j < reuse_images->numTilesets; j++){
                        if(reuse_images->tilesets[j].image == map->tilesets[e].image){
                            map->tilesets[e].image = NULL;
                            map->tilesets[e].imagePath[0] = '\0';
                            break;
                        }
                    }
                    destroyTileset(map->tilesets + e);
                }
                fprintf(stderr, "Error loading tileset %i\n", i);
                goto error_free_tilesets_only;
            }
        }

        // Change all reused surfaces to avoid any double-frees or use-after-frees.
        if(reuse_images){
            for(i = 0; i < map->numTilesets; i++){
                unsigned e;
                for(e = 0; e < reuse_images->numTilesets; e++){
                    if(reuse_images->tilesets[e].image == map->tilesets[i].image){
                        reuse_images->tilesets[e].image = NULL;
                        reuse_images->tilesets[e].imagePath[0] = '\0';
                    }
                }
            }
        }
    }

    // Load layers
    {
        const struct Turbo_Value *const layers = jsonFindObjectValue(&mapValue, "layers");
        if(!layers || layers->type != TJ_Array){
            // Huh. This is at least a warning.
            fprintf(stderr, "Warning: No layers in map.");
            map->numLayers = 0;
            map->layers = NULL;
        }
        else{
            unsigned i;
            map->numLayers = layers->length;
            map->layers = calloc(layers->length, sizeof(struct Layer));
            
            for(i = 0; i < map->numLayers; i++){
                if(!loadLayer(map->layers + i, layers->value.array + i)){
                    unsigned e;
                    for(e = 0; e < i; e++){
                        destroyLayer(map->layers + e);
                    }
                    free(map->layers);
                    goto error_free_tilesets;
                }
            }
        }
    }
    // All OK!
    goto ending;

error_free_tilesets:
    {
        unsigned i;
        for(i = 0; i < map->numTilesets; i++)
            destroyTileset(map->tilesets + i);
    }

error_free_tilesets_only:
    free(map->tilesets);

error_free_map:
    free(map);
    map = NULL;

ending:
    Turbo_FreeParse(&mapValue);
    FreeBufferFile(data, size);
    return map;
}
Пример #13
0
int Map::load(const std::string& fname) {
	FileParser infile;

	clearEvents();
	clearLayers();
	clearQueues();

	music_filename = "";

	// @CLASS Map|Description of maps/
	if (!infile.open(fname))
		return 0;

	this->filename = fname;

	while (infile.next()) {
		if (infile.new_section) {

			// for sections that are stored in collections, add a new object here
			if (infile.section == "enemy")
				enemy_groups.push(Map_Group());
			else if (infile.section == "npc")
				npcs.push(Map_NPC());
			else if (infile.section == "event")
				events.push_back(Event());

		}
		if (infile.section == "header")
			loadHeader(infile);
		else if (infile.section == "layer")
			loadLayer(infile);
		else if (infile.section == "enemy")
			loadEnemyGroup(infile, &enemy_groups.back());
		else if (infile.section == "npc")
			loadNPC(infile);
		else if (infile.section == "event")
			EventManager::loadEvent(infile, &events.back());
	}

	infile.close();

	// create a temporary EffectDef for immunity; will be used for map StatBlocks
	EffectDef immunity_effect;
	immunity_effect.id = "MAP_EVENT_IMMUNITY";
	immunity_effect.type = "immunity";

	// create StatBlocks for events that need powers
	for (unsigned i=0; i<events.size(); ++i) {
		Event_Component *ec_power = events[i].getComponent(EC_POWER);
		if (ec_power) {
			statblocks.push_back(StatBlock());
			StatBlock *statb = &statblocks.back();

			if (!statb) {
				logError("Map: Could not create StatBlock for Event.");
				continue;
			}

			// store the index of this StatBlock so that we can find it when the event is activated
			ec_power->y = static_cast<int>(statblocks.size())-1;

			statb->starting[STAT_ACCURACY] = 1000; // always hit the target

			Event_Component *ec_path = events[i].getComponent(EC_POWER_PATH);
			if (ec_path) {
				// source is power path start
				statb->pos.x = static_cast<float>(ec_path->x) + 0.5f;
				statb->pos.y = static_cast<float>(ec_path->y) + 0.5f;
			}
			else {
				// source is event location
				statb->pos.x = static_cast<float>(events[i].location.x) + 0.5f;
				statb->pos.y = static_cast<float>(events[i].location.y) + 0.5f;
			}

			Event_Component *ec_damage = events[i].getComponent(EC_POWER_DAMAGE);
			if (ec_damage) {
				statb->starting[STAT_DMG_MELEE_MIN] = statb->starting[STAT_DMG_RANGED_MIN] = statb->starting[STAT_DMG_MENT_MIN] = ec_damage->a;
				statb->starting[STAT_DMG_MELEE_MAX] = statb->starting[STAT_DMG_RANGED_MAX] = statb->starting[STAT_DMG_MENT_MAX] = ec_damage->b;
			}

			// this is used to store cooldown ticks for a map power
			// the power id, type, etc are not used
			statb->powers_ai.resize(1);

			// make this StatBlock immune to negative status effects
			// this is mostly to prevent a player with a damage return bonus from damaging this StatBlock
			statb->effects.addEffect(immunity_effect, 0, 0, false, -1, 0, SOURCE_TYPE_ENEMY);
		}
	}

	// ensure that our map contains a collison layer
	if (std::find(layernames.begin(), layernames.end(), "collision") == layernames.end()) {
		layernames.push_back("collision");
		layers.resize(layers.size()+1);
		layers.back().resize(w);
		for (size_t i=0; i<layers.back().size(); ++i) {
			layers.back()[i].resize(h, 0);
		}
		collision_layer = static_cast<int>(layers.size())-1;
	}

	return 0;
}
Пример #14
0
int Map::load(const std::string& fname) {
	FileParser infile;

	clearEvents();
	clearLayers();
	clearQueues();

	music_filename = "";

	collision_layer = -1;
	w = 1;
	h = 1;
	hero_pos_enabled = false;
	hero_pos.x = 0;
	hero_pos.y = 0;

	// @CLASS Map|Description of maps/
	if (!infile.open(fname))
		return 0;

	logInfo("Map: Loading map '%s'", fname.c_str());

	this->filename = fname;

	while (infile.next()) {
		if (infile.new_section) {

			// for sections that are stored in collections, add a new object here
			if (infile.section == "enemy")
				enemy_groups.push(Map_Group());
			else if (infile.section == "npc")
				npcs.push(Map_NPC());
			else if (infile.section == "event")
				events.push_back(Event());

		}
		if (infile.section == "header")
			loadHeader(infile);
		else if (infile.section == "layer")
			loadLayer(infile);
		else if (infile.section == "enemy")
			loadEnemyGroup(infile, &enemy_groups.back());
		else if (infile.section == "npc")
			loadNPC(infile);
		else if (infile.section == "event")
			EventManager::loadEvent(infile, &events.back());
	}

	infile.close();

	// create StatBlocks for events that need powers
	for (unsigned i=0; i<events.size(); ++i) {
		Event_Component *ec_power = events[i].getComponent(EC_POWER);
		if (ec_power) {
			// store the index of this StatBlock so that we can find it when the event is activated
			ec_power->y = addEventStatBlock(events[i]);
		}
	}

	// ensure that our map contains a collision layer
	if (std::find(layernames.begin(), layernames.end(), "collision") == layernames.end()) {
		layernames.push_back("collision");
		layers.resize(layers.size()+1);
		layers.back().resize(w);
		for (size_t i=0; i<layers.back().size(); ++i) {
			layers.back()[i].resize(h, 0);
		}
		collision_layer = static_cast<int>(layers.size())-1;
	}

	if (!hero_pos_enabled) {
		logError("Map: Hero spawn position (hero_pos) not defined in map header. Defaulting to (0,0).");
	}

	return 0;
}
QgsAttributeTableMemoryModel::QgsAttributeTableMemoryModel
( QgsVectorLayer *theLayer )
    : QgsAttributeTableModel( theLayer )
{
  loadLayer();
}
Пример #16
0
	bool Map::loadMap(const std::string &filename)
	{
	    std::string file = resourceManager->getDataPath(filename);
        logger->logDebug("Loading map " + file);

        TiXmlDocument doc(file.c_str());
        bool loaded = doc.LoadFile();
        if (!loaded)
        {
            logger->logError("Error loading map");
            return false;
        }

        TiXmlHandle hDoc(&doc);
        TiXmlElement *e;
        TiXmlHandle map = hDoc.FirstChild("map");

        if (!loadMapInfo(map.ToElement()))
        {
            return false;
        }

        int numTilesets = 0;

        while(1)
        {
            e = map.Child("tileset", numTilesets).ToElement();

            if (!loadTileset(e))
            {
                break;
            }
            ++numTilesets;
        }

        if (numTilesets == 0)
        {
            logger->logError("No tilesets found.");
            return false;
        }

        int numLayers = 0;
        while(1)
        {
            e = map.Child("layer", numLayers).ToElement();

            if (!loadLayer(e))
            {
                break;
            }
            ++numLayers;
        }
        if (numLayers == 0)
        {
            logger->logError("No layers found!");
            return false;
        }

        logger->logDebug("Finished loading map");

        mLoaded = true;

        return true;
    }