static Util::ReferenceCount<playerInfo> getPlayer(const Filesystem::AbsolutePath & file){
    Global::debug(1, PAINTOWN_DEBUG_CONTEXT) << "Checking " << file.path() << std::endl;
    if (Storage::instance().exists(file)){
        Global::debug(1, PAINTOWN_DEBUG_CONTEXT) << "Adding " << file.path() << std::endl;
        return Util::ReferenceCount<playerInfo>(new playerInfo(Util::ReferenceCount<Paintown::DisplayCharacter>(new Paintown::DisplayCharacter(file)), file));
    }
    throw LoadException(__FILE__, __LINE__, "File '" + file.path() + "' not found.");
}
Example #2
0
PackReader::PackReader(const Filesystem::AbsolutePath & filename):
filename(filename){
    ifstream stream;
    Global::debug(0) << "Reading pak file " << filename.path() << endl;
    stream.open(filename.path().c_str(), std::ios::in | std::ios::binary);
    Storage::LittleEndianReader reader(stream);
    uint32_t magic = reader.readByte4();
    if (magic != MAGIC){
        ostringstream error;
        error << filename.path() << " is not a packfile! " << std::hex << magic;
        throw PackError(__FILE__, __LINE__, error.str());
    } else {
        // cout << "Ok got a packfile" << endl;
    }
    uint32_t version = reader.readByte4();
    /* just assume we can read all versions for now */

    // cout << "Version is " << version << endl;
    reader.seekEnd(-4);
    uint32_t headerPosition = reader.readByte4();
    reader.seek(headerPosition);

    // cout << "Header at 0x" << std::hex << headerPosition << std::dec << endl;

    bool done = false;
    try{
        while (!done){
            uint32_t current = reader.position();
            uint32_t length = reader.readByte4();
            uint32_t start = reader.readByte4();
            uint32_t size = reader.readByte4();
            /* will read upto 80 bytes, but potentially fewer if a null byte
             * is reached.
             */
            string name = reader.readStringX(80);
            if (name.size() != 0){
                files[sanitizePath(name)] = File(start, size);
            }
            done = name.size() == 0;
            // cout << name << " at " << start << " size " << size << " length " << length << endl;
            // cout << " seek to " << (current + length) << endl;
            // reader.seek(current + length);
            done |= stream.eof();
        }
    } catch (const Storage::Eof & eof){
    }
    stream.close();

    handle.open(filename.path().c_str(), std::ios::in | std::ios::binary);
    Util::Thread::initializeLock(&readLock);
}
Example #3
0
static AstRef loadCached(const Filesystem::AbsolutePath & path){
    if (!Storage::instance().exists(path)){
        throw MugenException("Original file does not exist", __FILE__, __LINE__);
    }
    string converted = Storage::instance().cleanse(path).path();
    std::transform(converted.begin(), converted.end(), converted.begin(), replaceSlash);
    Filesystem::AbsolutePath fullPath = Storage::instance().userDirectory().join(Filesystem::RelativePath(MUGEN_CACHE)).join(Filesystem::RelativePath(converted));
    if (!newer(fullPath, path)){
        throw MugenException("File is old", __FILE__, __LINE__);
    }
    TokenReader reader;
    Global::debug(1, "mugen-parse-cache") << "Loading from cache " << fullPath.path() << endl;
    return PaintownUtil::ReferenceCount<Ast::AstParse>(new Ast::AstParse(reader.readTokenFromFile(fullPath.path().c_str())));
}
Example #4
0
Cat::Cat(const Filesystem::AbsolutePath & filename):
ObjectNonAttack( 0, 0 ),
state( IDLE1 ){

	path = filename;

	setMaxHealth( 1 );
	setHealth( 1 );
	
	TokenReader tr;
	try{
		Token * head;
		head = tr.readTokenFromFile(path.path());
		if ( *head != "cat" ){
			throw LoadException(__FILE__, __LINE__, "File does not begin with 'Cat'" );
		}

		while ( head->hasTokens() ){
			Token * next = head->readToken();
			if ( *next == "animation" ){
				Animation * animation = new Animation( next, 0 );
				animations[ animation->getName() ] = animation;
			}
		}
		if ( animations.size() == 0 ){
			throw LoadException(__FILE__, __LINE__, "No animation given" );
		}
        } catch (const TokenException & ex){
            // Global::debug(0) << "Could not read "<< filename.path() <<": "<< ex.getReason()<<endl;
            throw LoadException(__FILE__, __LINE__, ex, "Could not open file " + filename.path());
        }
	current_animation = animations[ "idle1" ];

	meow = Sound(Storage::instance().find(Filesystem::RelativePath("misc/cat/meow.wav")).path());
}
Example #5
0
static void saveParse(const Filesystem::AbsolutePath & path, const PaintownUtil::ReferenceCount<Ast::AstParse> & parse){
    ofstream out(path.path().c_str());
    Token * serial = parse->serialize();
    serial->toStringCompact(out);
    out << endl;
    out.close();
    delete serial;
}
Example #6
0
void Configuration::loadConfigurations(){
    data = new Token();
    *data << config_configuration;

    try{
        Filesystem::AbsolutePath file = Storage::instance().configFile();
        TokenReader tr;
        Token * head = tr.readTokenFromFile(file.path());

        if (*head != config_configuration){
            throw LoadException(__FILE__, __LINE__, string("Config file ") + Storage::instance().configFile().path() + " does not use the configuration format" );
        }

        /* Store the entire configuration tree */
        data = removeDuplicates(head->copy());
    } catch ( const LoadException & le ){
        Global::debug( 0 ) << "Notice: Could not load configuration file " << Storage::instance().configFile().path() << ": " << le.getTrace() << endl;
    } catch ( const TokenException & t ){
        Global::debug( 0 ) << "Notice: could not open configuration file '" << Storage::instance().configFile().path() << "': " << t.getTrace() << endl;
    }
}
Example #7
0
/* attempts to load from a file on disk. if the file doesn't exist then
 * parse it for real and save it to disk.
 */
Util::ReferenceCount<Ast::AstParse> Parser::loadFile(const Filesystem::AbsolutePath & path){
    try{
        return loadCached(path);
    } catch (const TokenException & fail){
        Global::debug(1, "mugen-parse-cache") << "Cache load warning: " << fail.getTrace() << endl;
    } catch (const MugenException & fail){
        Global::debug(1, "mugen-parse-cache") << "Cache load warning: " << fail.getTrace() << endl;
    } catch (const Filesystem::Exception & fail){
        Global::debug(1, "mugen-parse-cache") << "Cache load warning: " << fail.getTrace() << endl;
    }

    Global::debug(1, "mugen-parse-cache") << "Parsing " << path.path() << endl;
    Util::ReferenceCount<Ast::AstParse> out = doParse(path);
    try{
        saveCached(out, path);
    } catch (...){
        Global::debug(0) << "Failed to save cached file " << path.path() << endl;
        /* failed for some reason */
    }

    return out;
}
Example #8
0
Item::Item(const Filesystem::AbsolutePath & filename, const Util::ReferenceCount<Stimulation> & stimulation, const string & check):
ObjectNonAttack(0, 0),
// collide(0),
stimulation(stimulation){
    TokenReader tr;

    setMaxHealth(1);
    setHealth(1);

    try{
        Token * head;
        head = tr.readTokenFromFile(filename.path());

        if (*head != check){
            throw LoadException(__FILE__, __LINE__, "Item does not begin with 'item'" );
        }

        TokenView view = head->view();
        while (view.hasMore()){
            const Token * next = NULL;
            view >> next;
            if (*next == "frame"){
                animation = singleFrameAnimation(next);
                /*
                string file;
                next->view() >> file;
                picture.load(Storage::instance().find(Filesystem::RelativePath(file)).path());
                */
            } else if (*next == "anim" || *next == "animation"){
                animation = Util::ReferenceCount<Animation>(new Animation(next, NULL));
            } else if (*next == "sound"){
                string path;
                next->view() >> path;
                sound = Sound(Storage::instance().find(Filesystem::RelativePath(path)).path());
            } else if (*next == "float"){
                floating.enabled = true;
                double value = 0;
                if (next->match("_/height", value)){
                    floating.height = value;
                }
                if (next->match("_/amplitude", value)){
                    floating.amplitude = value;
                }
                if (next->match("_/period", value)){
                    if (value < 1){
                        value = 1;
                    }
                    floating.period = value;
                }
            }
        }
Example #9
0
Data::Data(const Filesystem::AbsolutePath & configFile):
motif(""),
difficulty(),
life(),
time(),
speed(),
team1vs2Life(),
teamLoseOnKO(),
gameType(),
defaultAttackLifeToPowerMultiplier(1),
defaultGetHitLifeToPowerMultiplier(1),
superTargetDefenceMultiplier(),
gameSpeed(),
drawShadows(),
afterImageMax(),
layeredSpriteMax(),
explodMax(),
sysExplodMax(),
helperMax(),
playerProjectileMax(),
firstRun(),
search(SelectDefAndAuto){
    
    Filesystem::AbsolutePath baseDir = configFile.getDirectory();
    const Filesystem::AbsolutePath ourDefFile = Mugen::Util::fixFileName(baseDir, configFile.getFilename().path());
    
    if (ourDefFile.isEmpty()){
        throw MugenException("Cannot locate definition file for: " + configFile.path(), __FILE__, __LINE__);
    }
    
    TimeDifference diff;
    diff.startTime();
    AstRef parsed(Util::parseDef(ourDefFile));
    diff.endTime();
    Global::debug(1) << "Parsed mugen file " + ourDefFile.path() + " in" + diff.printTime("") << endl;

    for (Ast::AstParse::section_iterator section_it = parsed->getSections()->begin(); section_it != parsed->getSections()->end(); section_it++){
        Ast::Section * section = *section_it;
	std::string head = section->getName();
        if (head == "Options"){
            class OptionWalk: public Ast::Walker{
            public:
                OptionWalk(Data & self):
                self(self){
                }
                Data & self;
                virtual void onAttributeSimple(const Ast::AttributeSimple & simple){
                    if (simple == "difficulty"){
                        simple.view() >> self.difficulty;
                    } else if (simple == "life"){
                        simple.view() >> self.life;
                    } else if (simple == "time"){
Example #10
0
static void saveCached(const Util::ReferenceCount<Ast::AstParse> & parse, const Filesystem::AbsolutePath & path){
    string converted = Storage::instance().cleanse(path).path();
    std::transform(converted.begin(), converted.end(), converted.begin(), replaceSlash);
    Filesystem::AbsolutePath cache = Storage::instance().userDirectory().join(Filesystem::RelativePath(MUGEN_CACHE));

    if (!System::isDirectory(cache.path())){
        /* like mkdir -p */
        System::makeAllDirectory(cache.path());
    }

    Filesystem::AbsolutePath fullPath = cache.join(Filesystem::RelativePath(converted));
    Global::debug(1, "mugen-parse-cache") << "Saving cache to " << fullPath.path() << endl;
    saveParse(fullPath, parse);
}