示例#1
0
bool Animation::BeginLoad(Deserializer& source)
{
unsigned memoryUse = sizeof(Animation);

// Check ID
if (source.ReadFileID() != "UANI")
{
    LOGERROR(source.GetName() + " is not a valid animation file");
    return false;
}

// Read name and length
animationName_ = source.ReadString();
animationNameHash_ = animationName_;
length_ = source.ReadFloat();
tracks_.Clear();

unsigned tracks = source.ReadUInt();
memoryUse += tracks * sizeof(AnimationTrack);

// Read tracks
for (unsigned i = 0; i < tracks; ++i)
{
    AnimationTrack* newTrack = CreateTrack(source.ReadString());
    newTrack->channelMask_ = source.ReadUByte();

    unsigned keyFrames = source.ReadUInt();
    newTrack->keyFrames_.Resize(keyFrames);
    memoryUse += keyFrames * sizeof(AnimationKeyFrame);

    // Read keyframes of the track
    for (unsigned j = 0; j < keyFrames; ++j)
    {
        AnimationKeyFrame& newKeyFrame = newTrack->keyFrames_[j];
        newKeyFrame.time_ = source.ReadFloat();
        if (newTrack->channelMask_ & CHANNEL_POSITION)
            newKeyFrame.position_ = source.ReadVector3();
        if (newTrack->channelMask_ & CHANNEL_ROTATION)
            newKeyFrame.rotation_ = source.ReadQuaternion();
        if (newTrack->channelMask_ & CHANNEL_SCALE)
            newKeyFrame.scale_ = source.ReadVector3();
    }
}

// Optionally read triggers from an XML file
ResourceCache* cache = GetSubsystem<ResourceCache>();
String xmlName = ReplaceExtension(GetName(), ".xml");

SharedPtr<XMLFile> file(cache->GetTempResource<XMLFile>(xmlName, false));
if (file)
{
    XMLElement rootElem = file->GetRoot();
    XMLElement triggerElem = rootElem.GetChild("trigger");
    while (triggerElem)
    {
        if (triggerElem.HasAttribute("normalizedtime"))
            AddTrigger(triggerElem.GetFloat("normalizedtime"), true, triggerElem.GetVariant());
        else if (triggerElem.HasAttribute("time"))
            AddTrigger(triggerElem.GetFloat("time"), false, triggerElem.GetVariant());

        triggerElem = triggerElem.GetNext("trigger");
    }

    memoryUse += triggers_.Size() * sizeof(AnimationTriggerPoint);
}

SetMemoryUse(memoryUse);
return true;
}
示例#2
0
bool Entity::load_from(const char* file) {
    Deserializer des;
    return des.deserialize(file, *this);
}
示例#3
0
// loads the state of the rom settings
void BeamRiderSettings::loadState(Deserializer & ser) {
  m_reward = ser.getInt();
  m_score = ser.getInt();
  m_terminal = ser.getBool();
  m_lives = ser.getInt();
}
示例#4
0
文件: Sound.cpp 项目: acremean/urho3d
bool Sound::LoadWav(Deserializer& source)
{
    WavHeader header;
    
    // Try to open
    memset(&header, 0, sizeof header);
    source.Read(&header.riffText_, 4);
    header.totalLength_ = source.ReadUInt();
    source.Read(&header.waveText_, 4);
    
    if (memcmp("RIFF", header.riffText_, 4) || memcmp("WAVE", header.waveText_, 4))
    {
        LOGERROR("Could not read WAV data from " + source.GetName());
        return false;
    }
    
    // Search for the FORMAT chunk
    for (;;)
    {
        source.Read(&header.formatText_, 4);
        header.formatLength_ = source.ReadUInt();
        if (!memcmp("fmt ", &header.formatText_, 4))
            break;
        
        source.Seek(source.GetPosition() + header.formatLength_);
        if (!header.formatLength_ || source.GetPosition() >= source.GetSize())
        {
            LOGERROR("Could not read WAV data from " + source.GetName());
            return false;
        }
    }
    
    // Read the FORMAT chunk
    header.format_ = source.ReadUShort();
    header.channels_ = source.ReadUShort();
    header.frequency_ = source.ReadUInt();
    header.avgBytes_ = source.ReadUInt();
    header.blockAlign_ = source.ReadUShort();
    header.bits_ = source.ReadUShort();
    
    // Skip data if the format chunk was bigger than what we use
    source.Seek(source.GetPosition() + header.formatLength_ - 16);
    
    // Check for correct format
    if (header.format_ != 1)
    {
        LOGERROR("Could not read WAV data from " + source.GetName());
        return false;
    }
    
    // Search for the DATA chunk
    for (;;)
    {
        source.Read(&header.dataText_, 4);
        header.dataLength_ = source.ReadUInt();
        if (!memcmp("data", &header.dataText_, 4))
            break;
        
        source.Seek(source.GetPosition() + header.dataLength_);
        if (!header.dataLength_ || source.GetPosition() >= source.GetSize())
        {
            LOGERROR("Could not read WAV data from " + source.GetName());
            return false;
        }
    }
    
    // Allocate sound and load audio data
    unsigned length = header.dataLength_;
    SetSize(length);
    SetFormat(header.frequency_, header.bits_ == 16, header.channels_ == 2);
    source.Read(data_.Get(), length);
    
    // Convert 8-bit audio to signed
    if (!sixteenBit_)
    {
        for (unsigned i = 0; i < length; ++i)
            data_[i] -= 128;
    }
    
    return true;
}
示例#5
0
文件: Sound.cpp 项目: acremean/urho3d
bool Sound::LoadRaw(Deserializer& source)
{
    unsigned dataSize = source.GetSize();
    SetSize(dataSize);
    return source.Read(data_.Get(), dataSize) == dataSize;
}
示例#6
0
文件: QBert.cpp 项目: gandalfvn/EOH
// loads the state of the rom settings
void QBertSettings::loadState(Deserializer & ser) {
  m_reward = ser.getInt();
  m_score = ser.getInt();
  m_terminal = ser.getBool();
  m_last_lives = ser.getInt();
}
示例#7
0
bool ParticleEffect2D::BeginLoad(Deserializer& source)
{
    if (GetName().Empty())
        SetName(source.GetName());

    loadSpriteName_.Clear();

    XMLFile xmlFile(context_);
    if (!xmlFile.Load(source))
        return false;

    XMLElement rootElem = xmlFile.GetRoot("particleEmitterConfig");
    if (!rootElem)
        return false;

    String texture = rootElem.GetChild("texture").GetAttribute("name");
    loadSpriteName_ = GetParentPath(GetName()) + texture;
    // If async loading, request the sprite beforehand
    if (GetAsyncLoadState() == ASYNC_LOADING)
        GetSubsystem<ResourceCache>()->BackgroundLoadResource<Sprite2D>(loadSpriteName_, true, this);

    sourcePositionVariance_ = ReadVector2(rootElem, "sourcePositionVariance");

    speed_ = ReadFloat(rootElem, "speed");
    speedVariance_ = ReadFloat(rootElem, "speedVariance");

    particleLifeSpan_ = Max(0.01f, ReadFloat(rootElem, "particleLifeSpan"));
    particleLifespanVariance_ = ReadFloat(rootElem, "particleLifespanVariance");

    angle_ = ReadFloat(rootElem, "angle");
    angleVariance_ = ReadFloat(rootElem, "angleVariance");

    gravity_ = ReadVector2(rootElem, "gravity");

    radialAcceleration_ = ReadFloat(rootElem, "radialAcceleration");
    tangentialAcceleration_ = ReadFloat(rootElem, "tangentialAcceleration");

    radialAccelVariance_ = ReadFloat(rootElem, "radialAccelVariance");
    tangentialAccelVariance_ = ReadFloat(rootElem, "tangentialAccelVariance");

    startColor_ = ReadColor(rootElem, "startColor");
    startColorVariance_ = ReadColor(rootElem, "startColorVariance");

    finishColor_ = ReadColor(rootElem, "finishColor");
    finishColorVariance_ = ReadColor(rootElem, "finishColorVariance");

    maxParticles_ = ReadInt(rootElem, "maxParticles");

    startParticleSize_ = ReadFloat(rootElem, "startParticleSize");
    startParticleSizeVariance_ = ReadFloat(rootElem, "startParticleSizeVariance");

    finishParticleSize_ = ReadFloat(rootElem, "finishParticleSize");
    // Typo in pex file
    finishParticleSizeVariance_ = ReadFloat(rootElem, "FinishParticleSizeVariance");

    duration_ = M_INFINITY;
    if (rootElem.HasChild("duration"))
    {
        float duration = ReadFloat(rootElem, "duration");
        if (duration > 0.0f)
            duration_ = duration;
    }


    emitterType_ = (EmitterType2D)ReadInt(rootElem, "emitterType");

    maxRadius_ = ReadFloat(rootElem, "maxRadius");
    maxRadiusVariance_ = ReadFloat(rootElem, "maxRadiusVariance");
    minRadius_ = ReadFloat(rootElem, "minRadius");
    minRadiusVariance_ = ReadFloat(rootElem, "minRadiusVariance");

    rotatePerSecond_ = ReadFloat(rootElem, "rotatePerSecond");
    rotatePerSecondVariance_ = ReadFloat(rootElem, "rotatePerSecondVariance");

    int blendFuncSource = ReadInt(rootElem, "blendFuncSource");
    int blendFuncDestination = ReadInt(rootElem, "blendFuncDestination");
    blendMode_ = BLEND_ALPHA;
    for (int i = 0; i < MAX_BLENDMODES; ++i)
    {
        if (blendFuncSource == srcBlendFuncs[i] && blendFuncDestination == destBlendFuncs[i])
        {
            blendMode_ = (BlendMode)i;
            break;
        }
    }

    rotationStart_ = ReadFloat(rootElem, "rotationStart");
    rotationStartVariance_ = ReadFloat(rootElem, "rotationStartVariance");

    rotationEnd_ = ReadFloat(rootElem, "rotationEnd");
    rotationEndVariance_ = ReadFloat(rootElem, "rotationEndVariance");

    // Note: not accurate
    SetMemoryUse(source.GetSize());
    return true;
}
示例#8
0
void CompositeProperty::deserialize(Deserializer& d) {
    Property::deserialize(d);
    PropertyOwner::deserialize(d);
    d.deserialize("collapsed", collapsed_);
}
 CurveSegmentModel(Deserializer<Impl>& vis, QObject* parent) :
     IdentifiedObject<CurveSegmentModel>{vis, parent}
 {
     vis.writeTo(*this);
 }
// loads the state of the rom settings
void NBAGiveNGoSettings::loadState( Deserializer & des ) {
  m_reward = des.getInt();
  m_score = des.getInt();
  m_terminal = des.getBool();
}
示例#11
0
bool ScriptFile::AddScriptSection(asIScriptEngine* engine, Deserializer& source)
{
    ResourceCache* cache = GetSubsystem<ResourceCache>();
    
    unsigned dataSize = source.GetSize();
    SharedArrayPtr<char> buffer(new char[dataSize]);
    source.Read((void*)buffer.Get(), dataSize);
    
    // Pre-parse for includes
    // Adapted from Angelscript's scriptbuilder add-on
    Vector<String> includeFiles;
    unsigned pos = 0;
    while(pos < dataSize)
    {
        int len;
        asETokenClass t = engine->ParseToken(&buffer[pos], dataSize - pos, &len);
        if (t == asTC_COMMENT || t == asTC_WHITESPACE)
        {
            pos += len;
            continue;
        }
        // Is this a preprocessor directive?
        if (buffer[pos] == '#')
        {
            int start = pos++;
            asETokenClass t = engine->ParseToken(&buffer[pos], dataSize - pos, &len);
            if (t == asTC_IDENTIFIER)
            {
                String token(&buffer[pos], len);
                if (token == "include")
                {
                    pos += len;
                    t = engine->ParseToken(&buffer[pos], dataSize - pos, &len);
                    if (t == asTC_WHITESPACE)
                    {
                        pos += len;
                        t = engine->ParseToken(&buffer[pos], dataSize - pos, &len);
                    }
                    
                    if (t == asTC_VALUE && len > 2 && buffer[pos] == '"')
                    {
                        // Get the include file
                        String includeFile(&buffer[pos+1], len - 2);
                        pos += len;
                        
                        // If the file is not found as it is, add the path of current file but only if it is found there
                        if (!cache->Exists(includeFile))
                        {
                            String prefixedIncludeFile = GetPath(GetName()) + includeFile;
                            if (cache->Exists(prefixedIncludeFile))
                                includeFile = prefixedIncludeFile;
                        }
                        
                        String includeFileLower = includeFile.ToLower();
                        
                        // If not included yet, store it for later processing
                        if (!includeFiles_.Contains(includeFileLower))
                        {
                            includeFiles_.Insert(includeFileLower);
                            includeFiles.Push(includeFile);
                        }
                        
                        // Overwrite the include directive with space characters to avoid compiler error
                        memset(&buffer[start], ' ', pos - start);
                    }
                }
            }
        }
        // Don't search includes within statement blocks or between tokens in statements
        else
        {
            int len;
            // Skip until ; or { whichever comes first
            while (pos < dataSize && buffer[pos] != ';' && buffer[pos] != '{')
            {
                engine->ParseToken(&buffer[pos], 0, &len);
                pos += len;
            }
            // Skip entire statement block
            if (pos < dataSize && buffer[pos] == '{')
            {
                ++pos;
                // Find the end of the statement block
                int level = 1;
                while (level > 0 && pos < dataSize)
                {
                    asETokenClass t = engine->ParseToken(&buffer[pos], 0, &len);
                    if (t == asTC_KEYWORD)
                    {
                        if (buffer[pos] == '{')
                            ++level;
                        else if(buffer[pos] == '}')
                            --level;
                    }
                    pos += len;
                }
            }
            else
                ++pos;
        }
    }
    
    // Process includes first
    for (unsigned i = 0; i < includeFiles.Size(); ++i)
    {
        cache->StoreResourceDependency(this, includeFiles[i]);
        SharedPtr<File> file = cache->GetFile(includeFiles[i]);
        if (file)
        {
            if (!AddScriptSection(engine, *file))
                return false;
        }
        else
        {
            LOGERROR("Could not process all the include directives in " + GetName() + ": missing " + includeFiles[i]);
            return false;
        }
    }
    
    // Then add this section
    if (scriptModule_->AddScriptSection(source.GetName().CString(), (const char*)buffer.Get(), dataSize) < 0)
    {
        LOGERROR("Failed to add script section " + source.GetName());
        return false;
    }
    
    SetMemoryUse(GetMemoryUse() + dataSize);
    return true;
}
示例#12
0
void IntegrateGCommand::deserialize(Deserializer& deserializer, Serialization& serialization, Context& context)
{
	sensor = deserializer.deserialize();
	duration_s = deserializer.deserialize();
	deserializer.deserialize((uint8_t*)calibration_offset.values, sizeof(calibration_offset.values));
}
示例#13
0
    void ModelComponent::Deserialize(Deserializer &deserializer)
    {
        uint32_t whatChanged = 0;
        this->LockOnChanged();


        Serialization::ChunkHeader header;
        deserializer.Read(header);

        assert(header.id == Serialization::ChunkID_ModelComponent_Main);
        {
            size_t deserializerStart = deserializer.Tell();
            
            switch (header.version)
            {
            case 1:
                {
                    // Flags are first.
                    uint32_t newFlags;
                    deserializer.Read(newFlags);

                    if (newFlags != this->flags)
                    {
                        this->flags = newFlags;
                        whatChanged |= ChangeFlag_Flags;
                    }


                    // Next is a boolean indicating whether or not a model is defined here.
                    bool hasModel;
                    deserializer.Read(hasModel);

                    // We will only have additional data at this point if we have actually have a model defined.
                    if (hasModel)
                    {
                        auto oldModel = this->model;


                        String modelPath;
                        deserializer.ReadString(modelPath);

                        if (!modelPath.IsEmpty())
                        {
                            this->SetModel(modelPath.c_str());
                            
                            // If we failed to set the model (most likely due to the file not existing) we need to skip this chunk and return.
                            if (this->model == nullptr)
                            {
                                const size_t bytesReadSoFar = deserializer.Tell() - deserializerStart;
                                
                                deserializer.Seek(header.sizeInBytes - bytesReadSoFar);
                                return;
                            }
                        }
                        else
                        {
                            if (this->GetContext() != NULL) {
                                ModelDefinition nullDefinition(*this->GetContext());
                                this->SetModel(new Model(nullDefinition), true);
                            }
                        }


                        assert(this->model != nullptr);
                        {
                            this->model->Deserialize(deserializer);
                        }


                        if (this->model != oldModel)
                        {
                            whatChanged |= ChangeFlag_Model;
                        }
                    }


                    break;
                }

            default:
                {
                    if (this->GetContext() != NULL) {
                        this->GetContext()->Logf("Error deserializing ModelComponent. Main chunk has an unsupported version (%d).", header.version);
                    }

                    break;
                }
            }
        }


        this->UnlockOnChanged();
        if (whatChanged != 0)
        {
            this->OnChanged(whatChanged);
        }
    }
示例#14
0
bool SpriteSheet2D::Load(Deserializer& source)
{
    spriteMapping_.Clear();

    SharedPtr<XMLFile> xmlFile(new XMLFile(context_));
    if(!xmlFile->Load(source))
    {
        LOGERROR("Could not load sprite sheet");
        return false;
    }

    SetMemoryUse(source.GetSize());

    XMLElement rootElem = xmlFile->GetRoot();
    if (!rootElem)
    {
        LOGERROR("Invalid sprite sheet");
        return false;
    }

    if (rootElem.GetName() == "spritesheet")
    {
        ResourceCache* cache = GetSubsystem<ResourceCache>();
        texture_ = cache->GetResource<Texture2D>(rootElem.GetAttribute("texture"));
        if (!texture_)
        {
            LOGERROR("Cound not load texture");
            return false;
        }

        XMLElement spriteElem = rootElem.GetChild("sprite");
        while (spriteElem)
        {
            String name = spriteElem.GetAttribute("name");
            IntRect rectangle = spriteElem.GetIntRect("rectangle");
            
            Vector2 hotSpot(0.5f, 0.5f);
            if (spriteElem.HasAttribute("hotspot"))
                hotSpot = spriteElem.GetVector2("hotspot");

            DefineSprite(name, rectangle, hotSpot);

            spriteElem = spriteElem.GetNext("sprite");
        }
    }
    // Sparrow Starling texture atlas
    else if (rootElem.GetName() == "TextureAtlas")
    {    
        ResourceCache* cache = GetSubsystem<ResourceCache>();
        texture_ = cache->GetResource<Texture2D>(rootElem.GetAttribute("imagePath"));
        if (!texture_)
        {
            LOGERROR("Cound not load texture");
            return false;
        }

        XMLElement subTextureElem = rootElem.GetChild("SubTexture");
        while (subTextureElem)
        {
            String name = subTextureElem.GetAttribute("name");

            int x = subTextureElem.GetInt("x");
            int y = subTextureElem.GetInt("y");
            int width = subTextureElem.GetInt("width");
            int height = subTextureElem.GetInt("height");
            IntRect rectangle(x, y, x + width, y + height);

            Vector2 hotSpot(0.5f, 0.5f);
            if (subTextureElem.HasAttribute("frameWidth") && subTextureElem.HasAttribute("frameHeight"))
            {
                int frameX = subTextureElem.GetInt("frameX");
                int frameY = subTextureElem.GetInt("frameY");
                int frameWidth = subTextureElem.GetInt("frameWidth");
                int frameHeight = subTextureElem.GetInt("frameHeight");
                hotSpot.x_ = ((float)frameX + frameWidth / 2) / width;
                hotSpot.y_ = 1.0f - ((float)frameY + frameHeight / 2) / height;
            }

            DefineSprite(name, rectangle, hotSpot);

            subTextureElem = subTextureElem.GetNext("SubTexture");
        }
    }
    else
    {
        LOGERROR("Invalid sprite sheet file");
        return false;
    }

    return true;
}
示例#15
0
 SlotModel(Deserializer<Impl>& vis, QObject* parent) :
     IdentifiedObject{vis, parent}
 {
     initConnections();
     vis.writeTo(*this);
 }
void ImageEditorProperty::deserialize(Deserializer& d) {
    FileProperty::deserialize(d);
    d.deserialize("Dimension", dimensions_);
    d.deserialize("Labels", labels_, "Label");
}
示例#17
0
int main(int argc, char *argv[])
{
// For detecting memory leaks
#ifdef _MSVC
    _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
    _CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_DEBUG );
#endif

    //// Seed the random number generator
    //srand( (unsigned int)time( 0 ) );

    // Display license
    std::cout
        << "RayWatch - A simple cross-platform RayTracer."                  << std::endl
        << "Copyright (C) 2008"                                             << std::endl
        << "  Angelo Rohit Joseph Pulikotil,"                               << std::endl
        << "  Francis Xavier Joseph Pulikotil"                              << std::endl
        << "This program comes with ABSOLUTELY NO WARRANTY."                << std::endl
        << "This is free software, and you are welcome to redistribute it"  << std::endl
        << "under certain conditions; see <http://www.gnu.org/licenses/>."  << std::endl << std::endl;

    if( argc < 3 )
    {
        std::cout << "Insufficient arguments" << std::endl << std::endl;
        std::cout << "Syntax (to render a Scene file):" << std::endl << argv[0] << " <input scene filename> <output bitmap filename> [width] [height]" << std::endl << std::endl;
        std::cout << "Syntax (to generate a sample file): " << std::endl << argv[0] << " --gen:<sample name> <output scene filename>" << std::endl << std::endl;
        std::cout << "Currently supported samples are CornellBox, Example1, Example2" << std::endl;
        return -1;
    }

    // If we're supposed to generate a sample file
    if( Utility::String::CaseInsensitiveCompare( std::string( argv[1] ).substr(0, 6), "--gen:" ) == 0 )
    {
        const std::string sampleName = std::string( argv[1] ).substr( 6 );

        bool bResult = false;
        if( Utility::String::CaseInsensitiveCompare( sampleName, "CornellBox" ) == 0 )
        {
            bResult = Examples::CornellBox( argv[2] );
        }
        else if( Utility::String::CaseInsensitiveCompare( sampleName, "Example1" ) == 0 )
        {
            bResult = Examples::Example1( argv[2] );
        }
        else if( Utility::String::CaseInsensitiveCompare( sampleName, "Example2" ) == 0 )
        {
            bResult = Examples::Example2( argv[2] );
        }
        else  // We don't have this sample
            std::cout << "Error: Unknown sample name: " << sampleName << std::endl;

        if( !bResult )
            return -1;

        std::cout << "Sample '" << sampleName << "' written to file: " << argv[2] << std::endl;
        return 0;
    }

    // Get the required width
    int width = 500;
    if( argc > 3 )
    {
        if( !Utility::String::FromString(width, argv[3]) || (width < 1) )
        {
            std::cout << "Error: Invalid integer specified for width: " << argv[3] << std::endl;
            return -1;
        }
    }

    // Get the required height
    int height = 500;
    if( argc > 4 )
    {
        if( !Utility::String::FromString(height, argv[4]) || (height < 1) )
        {
            std::cout << "Error: Invalid integer specified for height: " << argv[4] << std::endl;
            return -1;
        }
    }

    // Create a Camera
    Camera camera;
    camera._position    .Set( 0, 0, 0 );
    camera._hFov        = 45 * (width / (float)height);
    camera._vFov        = 45;

    // Create an Image
    Image image;
    if( !image.Create( width, height ) )
    {
        std::cout << "Error: Failed to create Image of size " << width << "x" << height << std::endl;
        return -1;
    }

    // Open the input scene file
    std::fstream stream;
    stream.open( argv[1], std::ios_base::in );
    if( !stream.is_open() )
    {
        std::cout << "Error: Failed to open input scene file: " << argv[1] << std::endl;
        return -1;
    }

    // Create a Deserializer for the stream
    Deserializer d;
    if( !d.Open( stream ) )
    {
        std::cout << "Error: Failed to read file: " << argv[1] << std::endl;
        return -1;
    }

    // Load the scene from the stream
    Scene *pScene = d.Deserialize<Scene>( 0 );
    if( !pScene )
    {
        std::cout << "Error: Failed to load Scene from file: " << argv[1] << std::endl;
        return -1;
    }

    // Create a RayTracer and ray trace the scene
    RayTracer rayTracer;
    std::cout << "RayTracing";
    const bool bRTResult = rayTracer.Render( camera, *pScene, image );
    std::cout << "Done" << std::endl;

    // We're done with the scene, delete it
    SafeDeleteScalar( pScene );

    if( !bRTResult )
    {
        std::cout << "Error: Failed while RayTracing the Scene." << std::endl;
        return -1;
    }

    // Save the image to the required output file
    if( !image.Save( argv[2] ) )
    {
        std::cout << "Error: Failed while saving image to file: " << argv[2] << std::endl;
        return -1;
    }

    return 0;
}
void ImageLabel::deserialize(Deserializer& d) {
    d.deserialize("labelName", name_, SerializationTarget::Attribute);
    d.deserialize("topLeft", startPoint_);
    d.deserialize("size", rectSize_);
}
// loads the state of the rom settings
void AlienSettings::loadState(Deserializer & ser) {
  m_reward = ser.getInt();
  m_score = ser.getInt();
  m_terminal = ser.getBool();
}
示例#20
0
bool Animation2D::Load(Deserializer& source)
{
    frameEndTimes_.Clear();
    frameSprites_.Clear();

    SharedPtr<XMLFile> xmlFile(new XMLFile(context_));
    if(!xmlFile->Load(source))
    {
        LOGERROR("Could not load animation");
        return false;
    }

    SetMemoryUse(source.GetSize());

    XMLElement rootElem = xmlFile->GetRoot("animation");
    if (!rootElem)
    {
        LOGERROR("Invalid animation");
        return false;
    }

    ResourceCache* cache = GetSubsystem<ResourceCache>();

    XMLElement keyFrameElem = rootElem.GetChild("frame");
    if (!keyFrameElem)
    {
        LOGERROR("Could not found key frame");
        return false;
    }

    float endTime = 0.0f;

    while (keyFrameElem)
    {
        endTime += keyFrameElem.GetFloat("duration");
        frameEndTimes_.Push(endTime);

        SharedPtr<Sprite2D> sprite;
        Vector<String> names = keyFrameElem.GetAttribute("sprite").Split('@');
        if (names.Size() == 1)
            sprite = cache->GetResource<Sprite2D>(names[0]);
        else if (names.Size() == 2)
        {
            SpriteSheet2D* spriteSheet = cache->GetResource<SpriteSheet2D>(names[0]);
            if (!spriteSheet)
            {
                LOGERROR("Could not get sprite speet");
                return false;
            }

            sprite = spriteSheet->GetSprite(names[1]);
        }

        if (!sprite)
        {
            LOGERROR("Could not get sprite");
            return false;
        }

        frameSprites_.Push(sprite);
        keyFrameElem = keyFrameElem.GetNext("frame");
    }

    return true;
}