ShelloutAction::ShelloutAction(const ShelloutProcessing *sp, unsigned int attribID, POVMS_Object& opts): returnAction(ignore), returnNegate(false), isSet(false)
{
    if (opts.Exist(attribID))
    {
        POVMS_Object attr;

        opts.Get(attribID, attr);
        if (attr.Exist(kPOVAttrib_CommandString))
        {
            rawCommand = attr.GetString(kPOVAttrib_CommandString);
            if (sp->ExtractCommand(rawCommand, command, rawParameters))
            {
                int action = attr.TryGetInt(kPOVAttrib_ReturnAction, (int) ignore);
                switch (tolower(action))
                {
                case ignore:
                case skipOne:
                case skipAll:
                case quit:
                case abort:
                case fatal:
                    returnAction = (Action) tolower(action);
                    returnNegate = isupper(action);
                    isSet = true;
                    break;

                default:
                    break;
                }
            }
        }
    }
}
void ParserMessageHandler::DebugInfo(Console *console, POVMS_Object& obj, bool conout)
{
    if(conout == true)
    {
        // TODO FIXME HACK
        std::string str(obj.GetString(kPOVAttrib_EnglishText));
        console->Output(str);
    }
}
Exemple #3
0
void Scene::StartParser(POVMS_Object& parseOptions)
{
    size_t seed = 0; // TODO

    // A scene can only be parsed once
    if (parserControlThread == nullptr)
        parserControlThread = new std::thread(boost::bind(&Scene::ParserControlThread, this));
    else
        return;

    if (parseOptions.Exist(kPOVAttrib_Version))
    {
        sceneData->languageVersion = clip(int(parseOptions.GetFloat(kPOVAttrib_Version) * 100.0f + .5f), 100, 10000);
        sceneData->languageVersionSet = true;
    }

    sceneData->warningLevel = clip(parseOptions.TryGetInt(kPOVAttrib_WarningLevel, 9), 0, 9);

    sceneData->inputFile = parseOptions.TryGetUCS2String(kPOVAttrib_InputFile, "object.pov");
    sceneData->headerFile = parseOptions.TryGetUCS2String(kPOVAttrib_IncludeHeader, "");

    DBL outputWidth  = parseOptions.TryGetFloat(kPOVAttrib_Width, 160);
    DBL outputHeight = parseOptions.TryGetFloat(kPOVAttrib_Height, 120);
    sceneData->aspectRatio = outputWidth / outputHeight;

    sceneData->defaultFileType = parseOptions.TryGetInt(kPOVAttrib_OutputFileType, DEFAULT_OUTPUT_FORMAT); // TODO - should get DEFAULT_OUTPUT_FORMAT from the front-end
    sceneData->clocklessAnimation = parseOptions.TryGetBool(kPOVAttrib_ClocklessAnimation, false); // TODO - experimental code

    sceneData->splitUnions = parseOptions.TryGetBool(kPOVAttrib_SplitUnions, false);
    sceneData->removeBounds = parseOptions.TryGetBool(kPOVAttrib_RemoveBounds, true);
    sceneData->boundingMethod = clip<int>(parseOptions.TryGetInt(kPOVAttrib_BoundingMethod, 1), 1, 2);
    if(parseOptions.TryGetBool(kPOVAttrib_Bounding, true) == false)
        sceneData->boundingMethod = 0;

    sceneData->outputAlpha = parseOptions.TryGetBool(kPOVAttrib_OutputAlpha, false);
    if (!sceneData->outputAlpha)
        // if we're not outputting an alpha channel, precompose the scene background against a black "background behind the background"
        // (NB: Here, background color is still at its default of <0,0,0,0,1> = full transparency; we're changing that to opaque black.)
        sceneData->backgroundColour.Clear();

    // NB a value of '0' for any of the BSP parameters tells the BSP code to use its internal default
    sceneData->bspMaxDepth = parseOptions.TryGetInt(kPOVAttrib_BSP_MaxDepth, 0);
    sceneData->bspObjectIsectCost = clip<float>(parseOptions.TryGetFloat(kPOVAttrib_BSP_ISectCost, 0.0f), 0.0f, HUGE_VAL);
    sceneData->bspBaseAccessCost = clip<float>(parseOptions.TryGetFloat(kPOVAttrib_BSP_BaseAccessCost, 0.0f), 0.0f, HUGE_VAL);
    sceneData->bspChildAccessCost = clip<float>(parseOptions.TryGetFloat(kPOVAttrib_BSP_ChildAccessCost, 0.0f), 0.0f, HUGE_VAL);
    sceneData->bspMissChance = clip<float>(parseOptions.TryGetFloat(kPOVAttrib_BSP_MissChance, 0.0f), 0.0f, 1.0f - EPSILON);

    sceneData->realTimeRaytracing = parseOptions.TryGetBool(kPOVAttrib_RealTimeRaytracing, false);

    if(parseOptions.Exist(kPOVAttrib_Declare) == true)
    {
        POVMS_List ds;

        parseOptions.Get(kPOVAttrib_Declare, ds);
        for(int i = 1; i <= ds.GetListSize(); i++)
        {
            std::ostringstream sstr;
            POVMS_Attribute a;
            POVMS_Object d;

            ds.GetNth(i, d);
            d.Get(kPOVAttrib_Value, a);
            switch (a.Type())
            {
                case kPOVMSType_CString:
                    sstr << "\"" + d.TryGetString(kPOVAttrib_Value, "") + "\"";
                    break;

                case kPOVMSType_Float:
                    sstr << d.TryGetFloat(kPOVAttrib_Value, 0.0);
                    break;

                default:
                    // shouldn't happen unless we make a coding error
                    throw POV_EXCEPTION(kParamErr, "Invalid type passed in declare list");
            }

            sceneData->declaredVariables.insert(make_pair(d.GetString(kPOVAttrib_Identifier), sstr.str()));
        }
    }

    // do parsing
    sceneThreadData.push_back(dynamic_cast<TraceThreadData *>(parserTasks.AppendTask(new ParserTask(
        sceneData, pov_parser::ParserOptions(bool(parseOptions.Exist(kPOVAttrib_Clock)), parseOptions.TryGetFloat(kPOVAttrib_Clock, 0.0), seed)
        ))));

    // wait for parsing
    parserTasks.AppendSync();

    // do bounding - we always call this even if the bounding is turned off
    // because it also generates object statistics
    sceneThreadData.push_back(dynamic_cast<TraceThreadData *>(parserTasks.AppendTask(new BoundingTask(
        sceneData,
        clip<int>(parseOptions.TryGetInt(kPOVAttrib_BoundingThreshold, DEFAULT_AUTO_BOUNDINGTHRESHOLD),1,SIGNED16_MAX),
        seed
        ))));

    // wait for bounding
    parserTasks.AppendSync();

    // wait for bounding to finish
    parserTasks.AppendSync();

    // send statistics
    parserTasks.AppendFunction(boost::bind(&Scene::SendStatistics, this, _1));

    // send done message and compatibility data
    parserTasks.AppendFunction(boost::bind(&Scene::SendDoneMessage, this, _1));
}