Ejemplo n.º 1
0
TargetDecoder::TargetDecoder(const ghoul::Dictionary& dictionary) :_type("TARGET")
{
    _names.resize(dictionary.size());
    for (int i = 0; i < _names.size(); ++i) {
        std::string readMe;
        dictionary.getValue(std::to_string(i + 1), readMe);
        _names[i] = readMe;
    }
}
Ejemplo n.º 2
0
void ScriptScheduler::loadScripts(const ghoul::Dictionary& dictionary) {
    // Check if all of the scheduled scripts are formed correctly
    documentation::testSpecificationAndThrow(
        Documentation(),
        dictionary,
        "ScriptScheduler"
    );
    
    // Create all the scheduled script first
    std::vector<ScheduledScript> scheduledScripts;
    for (size_t i = 1; i <= dictionary.size(); ++i) {
        const ghoul::Dictionary& timedScriptDict = dictionary.value<ghoul::Dictionary>(
            std::to_string(i)
        );
        scheduledScripts.emplace_back(timedScriptDict);
    }

    // Sort scripts by time; use a stable_sort as the user might have had an intention
    // specifying multiple scripts for the same time in a specific order
    std::stable_sort(
        scheduledScripts.begin(),
        scheduledScripts.end(),
        [](const ScheduledScript& lhs, const ScheduledScript& rhs) {
            return lhs.time < rhs.time;
        }
    );
    
    // Move the scheduled scripts into their SOA alignment
    // For the forward scripts, this is the forwards direction
    // For the backward scripts, we insert them in the opposite order so that we can still
    // return forward iterators to them in the progressTo method
    for (ScheduledScript& script : scheduledScripts) {
        _timings.push_back(script.time);

        _forwardScripts.push_back(std::move(script.forwardScript));

        _backwardScripts.insert(
            _backwardScripts.begin(),
            std::move(script.backwardScript)
        );
    }

    // Ensure _currentIndex and _currentTime is accurate after new scripts was added
    double lastTime = _currentTime;
    rewind();
    progressTo(lastTime);
    
    ghoul_assert(
        (_timings.size() == _forwardScripts.size()) &&
        (_timings.size() == _backwardScripts.size()),
        "The SOA data structure has been mistreated and has different number of values"
    );
}
Ejemplo n.º 3
0
    TileProviderManager::TileProviderManager(
        const ghoul::Dictionary& textureCategoriesDictionary,
        const ghoul::Dictionary& textureInitDictionary){
        // Create all the categories of tile providers
        for (size_t i = 0; i < textureCategoriesDictionary.size(); i++) {
            ghoul::Dictionary texturesDict = textureCategoriesDictionary.value<ghoul::Dictionary>(
                LayeredTextures::TEXTURE_CATEGORY_NAMES[i]);

            ghoul_assert(texturesDict.size() <=
                LayeredTextures::MAX_NUM_TEXTURES_PER_CATEGORY,
                "Too many textures! Number of textures per category must be less than or equal to "
                << LayeredTextures::MAX_NUM_TEXTURES_PER_CATEGORY);

            TileProviderInitData initData;

            if (i == LayeredTextures::ColorTextures ||
                i == LayeredTextures::NightTextures ||
                i == LayeredTextures::WaterMasks    ||
                i == LayeredTextures::GrayScaleOverlays) {
                initData.minimumPixelSize = textureInitDictionary.value<double>("ColorTextureMinimumSize");
            }
            else if (i == LayeredTextures::Overlays) {
                initData.minimumPixelSize = textureInitDictionary.value<double>("OverlayMinimumSize");
            }
            else if (i == LayeredTextures::HeightMaps) {
                initData.minimumPixelSize = textureInitDictionary.value<double>("HeightMapMinimumSize");
            }
            else {
                initData.minimumPixelSize = 512;
            }

            initData.threads = 1;
            initData.cacheSize = 5000;
            initData.framesUntilRequestQueueFlush = 60;
            // Only preprocess height maps.
            initData.preprocessTiles = i == LayeredTextures::HeightMaps;

            initTexures(
                _layerCategories[i].tileProviders,
                texturesDict,
                initData);

            // init level blending to be true
            _layerCategories[i].levelBlendingEnabled = true;
        }
    }
Ejemplo n.º 4
0
    void TileProviderManager::initTexures(std::vector<NamedTileProvider>& dest,
        const ghoul::Dictionary& texturesDict, const TileProviderInitData& initData)
    {
        // Create TileProviders for all textures within this category
        for (size_t i = 0; i < texturesDict.size(); i++) {
            std::string name, path;
            
            std::string dictKey = std::to_string(i + 1);
            ghoul::Dictionary texDict = texturesDict.value<ghoul::Dictionary>(dictKey);
            texDict.getValue("Name", name);
            texDict.getValue("FilePath", path);

            std::string type = "LRUCaching"; // if type is unspecified
            texDict.getValue("Type", type);

            TileProvider* tileProvider;
            auto tileProviderFactory = FactoryManager::ref().factory<TileProvider>();
            try {
                tileProvider = tileProviderFactory->create(type, texDict);
            }
            catch (const ghoul::RuntimeError& e) {
                LERROR(e.what());
                continue;
            }

            // Something else went wrong and no exception was thrown
            if (tileProvider == nullptr) {
                LERROR("Unable to create TileProvider '" << name << "' of type '"
                    << type << "'");
                continue;
            }

            bool enabled = false; // defaults to false if unspecified
            texDict.getValue("Enabled", enabled);

            dest.push_back({ name, std::shared_ptr<TileProvider>(tileProvider), enabled });
        }
    }