Пример #1
0
// ---------------------------------------------------------
void ResourceTexture::Load(const Config & config)
{
	Resource::Load(config);

    format = (Format) config.GetInt("Format", unknown);
    has_mips   = config.GetBool("Mipmaps", false);
    linear     = config.GetBool("Linear", true);

    std::string extension;
    App->fs->SplitFilePath(exported_file.c_str(), nullptr, nullptr, &extension);

    compressed = _stricmp(extension.c_str(), "dds") == 0;
}
void ComponentParticleSystem::RandomValue::Load(const char* name, const Config& config)
{
    Config section = config.GetSection(name);
    random = section.GetBool("random", false); 

    if(random)
    {
        range[0] = section.GetFloat("init", 0.0f); 
        range[1] = section.GetFloat("end", 0.0f); 
    }
    else
    {
        range[0] = range[1] = section.GetFloat("value", 0.0f); 
    }
}
Пример #3
0
void ConfigTest::testConfig()
{
    ConfigApp* pApp = new ConfigApp;
    
    Config* pConf = new Config(_T("Config 001")); 
    pConf->AddBoolValue(_T("bool001"), false);
    pConf->AddBoolValue(_T("bool002"), true);
    pConf->AddBoolValue(_T("bool003"), false);

    pConf->AddStringValue(_T("string001"), _T("我是中国人"));
    pConf->AddStringValue(_T("string002"), _T("a"));
    pConf->AddStringValue(_T("string003"), _T("你好吧?"));

    pConf->AddDWORDValue(_T("dw001"), 2L);
    pConf->AddDWORDValue(_T("dw002"), 3L);
    pConf->AddDWORDValue(_T("dw003"), 23L);    
    pApp->AddConfig(pConf);


    pConf = new Config(_T("Config 002")); 
    pConf->AddBoolValue(_T("bool001"), false);
    pConf->AddBoolValue(_T("bool002"), true);
    pConf->AddBoolValue(_T("bool003"), false);

    pConf->AddStringValue(_T("string001"), _T(""));
    pConf->AddStringValue(_T("string002"), _T("a"));
    pConf->AddStringValue(_T("string003"), _T("b"));

    pConf->AddDWORDValue(_T("dw001"), 2L);
    pConf->AddDWORDValue(_T("dw002"), 3L);
    pConf->AddDWORDValue(_T("dw003"), 23L);  
    pApp->AddConfig(pConf);

    pApp->Save(_T("test.xml"));
    delete pApp;

    pApp = new ConfigApp;
    pApp->Load(_T("test.xml"));
    pConf = pApp->GetConfig(_T("Config 001"));
    CPPUNIT_ASSERT(pConf->GetBool(_T("bool001")) == false);
    CPPUNIT_ASSERT(pConf->GetBool(_T("bool003")) == false);
    pConf = pApp->GetConfig(_T("Config 002"));
    CPPUNIT_ASSERT(pConf->GetString(_T("string002")) == _T("a"));
    CPPUNIT_ASSERT(pConf->GetString(_T("string003")) == _T("b"));
    CPPUNIT_ASSERT(pConf->GetDoubleWorld(_T("dw002")) == 3L);
    delete pApp;
}
void ComponentParticleSystem::OnLoad(Config* config) 
{
	init.max_particles = config->GetUInt("Max particles", 100);
    init.loop = config->GetBool("Loop", false);

    init.duration = config->GetFloat("Duration", 0.0f);
    init.life.Load("Life", *config);
    init.speed.Load("Speed", *config);
    init.size.Load("Size", *config);
    init.rotation.Load("Rotation", *config);
    init.gravity.Load("Gravity", *config);
    init.color = config->GetFloat4("Color", float4::one);

	init.whole_speed = config->GetFloat("Whole speed", 1.0f);

    emitter.particles_per_second = config->GetUInt("Particles per second", 0);
    emitter.particles_per_distance = config->GetUInt("Particles per distance", 0);
    shape.type = (ShapeType)config->GetUInt("Shape type", (uint)Circle);
    if(shape.type == Circle)
    {
        shape.radius = config->GetFloat("Circle radius", 1.0f);
    }
    else if(shape.type == Cone)
    {
        shape.radius = config->GetFloat("Cone radius", 1.0f);
        shape.angle = config->GetFloat("Cone angle", 0.0f);
    }


    speed_over_time.init = config->GetFloat3("Speed init", float3::zero);
    speed_over_time.end = config->GetFloat3("Speed end", float3::zero);
    speed_over_time.bezier = config->GetFloat4("Speed bezier", float4(0.0f, 1.0f, 0.0f, 1.0f));

    size_over_time.init = config->GetFloat("Size init", 1.0f);
    size_over_time.end = config->GetFloat("Size end", 1.0f);
    size_over_time.bezier = config->GetFloat4("Size bezier", float4(0.0f, 1.0f, 0.0f, 1.0f));

    color_over_time.gradient.clearMarks();

    uint count = config->GetArrayCount("Color over time");
    for(uint i=0; i< count; ++i)
    {
        Config mark = config->GetArray("Color over time", i);
        
        bool alpha = mark.GetBool("alpha", false);
        float position = mark.GetFloat("position", 0.0f); 
        if(alpha)
        {
            float color = mark.GetFloat("color", 1.0f); 
            color_over_time.gradient.addAlphaMark(position, color);
        }
        else
        {
            float4 color = mark.GetFloat4("color", float4::one); 
            color_over_time.gradient.addMark(position, ImColor(color.x, color.y, color.z, 1.0f));
        }
    }

    if(color_over_time.gradient.getMarks().empty())
    {
        color_over_time.gradient.addMark(0.0f, ImColor(1.0f, 1.0f, 1.0f, 1.0f));
    }

    SetTexture(config->GetUID("Texture", 0));

    texture_info.x_tiles = config->GetInt("Sheet x", 1);
    texture_info.y_tiles = config->GetInt("Sheet y", 1);
    texture_info.random = config->GetBool("Sheet random", false);
    texture_info.frame_over_time.init = config->GetFloat("Sheet init", 0.0f);
    texture_info.frame_over_time.end = config->GetFloat("Sheet end", 0.0f);
    texture_info.frame_over_time.bezier = config->GetFloat4("Sheet bezier", float4(0.0f, 1.0f, 0.0f, 1.0f));
    blend_mode = (RenderBlendMode)config->GetInt("Blend mode", (int)AdditiveBlend);
    layer = config->GetFloat("Layer", 0.0f);
}
int TraceMain::RunTrace( int argc, char *argv[] )
{
    Stats *stats = new Stats( );
    Config *config = new Config( );
    GenericTraceReader *trace = NULL;
    TraceLine *tl = new TraceLine( );
    SimInterface *simInterface = new NullInterface( );
    NVMain *nvmain = new NVMain( );
    EventQueue *mainEventQueue = new EventQueue( );
    GlobalEventQueue *globalEventQueue = new GlobalEventQueue( );
    TagGenerator *tagGenerator = new TagGenerator( 1000 );
    bool IgnoreData = false;
    bool EventDriven = false;

    uint64_t simulateCycles;
    uint64_t currentCycle;
    
    if( argc < 4 )
    {
        std::cout << "Usage: nvmain CONFIG_FILE TRACE_FILE CYCLES [PARAM=value ...]" 
            << std::endl;
        return 1;
    }

    /* Print out the command line that was provided. */
    std::cout << "NVMain command line is:" << std::endl;
    for( int curArg = 0; curArg < argc; ++curArg )
    {
        std::cout << argv[curArg] << " ";
    }
    std::cout << std::endl << std::endl;

    config->Read( argv[1] );
    config->SetSimInterface( simInterface );
    SetEventQueue( mainEventQueue );
    SetGlobalEventQueue( globalEventQueue );
    SetStats( stats );
    SetTagGenerator( tagGenerator );
    std::ofstream statStream;

    /* Allow for overriding config parameter values for trace simulations from command line. */
    if( argc > 4 )
    {
        for( int curArg = 4; curArg < argc; ++curArg )
        {
            std::string clParam, clValue, clPair;
            
            clPair = argv[curArg];
            clParam = clPair.substr( 0, clPair.find_first_of("="));
            clValue = clPair.substr( clPair.find_first_of("=") + 1, std::string::npos );

            std::cout << "Overriding " << clParam << " with '" << clValue << "'" << std::endl;

            config->SetValue( clParam, clValue );
        }
    }

    if( config->KeyExists( "StatsFile" ) )
    {
        statStream.open( config->GetString( "StatsFile" ).c_str(), 
                         std::ofstream::out | std::ofstream::app );
    }

    if( config->KeyExists( "IgnoreData" ) && config->GetString( "IgnoreData" ) == "true" )
    {
        IgnoreData = true;
    }

    config->GetBool( "EventDriven", EventDriven );

    /*  Add any specified hooks */
    std::vector<std::string>& hookList = config->GetHooks( );

    for( size_t i = 0; i < hookList.size( ); i++ )
    {
        std::cout << "Creating hook " << hookList[i] << std::endl;

        NVMObject *hook = HookFactory::CreateHook( hookList[i] );
        
        if( hook != NULL )
        {
            AddHook( hook );
            hook->SetParent( this );
            hook->Init( config );
        }
        else
        {
            std::cout << "Warning: Could not create a hook named `" 
                << hookList[i] << "'." << std::endl;
        }
    }

    AddChild( nvmain );
    nvmain->SetParent( this );

    globalEventQueue->SetFrequency( config->GetEnergy( "CPUFreq" ) * 1000000.0 );
    globalEventQueue->AddSystem( nvmain, config );

    simInterface->SetConfig( config, true );
    nvmain->SetConfig( config, "defaultMemory", true );

    std::cout << "traceMain (" << (void*)(this) << ")" << std::endl;
    nvmain->PrintHierarchy( );

    if( config->KeyExists( "TraceReader" ) )
        trace = TraceReaderFactory::CreateNewTraceReader( 
                config->GetString( "TraceReader" ) );
    else
        trace = TraceReaderFactory::CreateNewTraceReader( "NVMainTrace" );

    trace->SetTraceFile( argv[2] );

    if( argc == 3 )
        simulateCycles = 0;
    else
        simulateCycles = atoi( argv[3] );

    std::cout << "*** Simulating " << simulateCycles << " input cycles. (";

    /*
     *  The trace cycle is assumed to be the rate that the CPU/LLC is issuing. 
     *  Scale the simulation cycles to be the number of *memory cycles* to run.
     */
    simulateCycles = (uint64_t)ceil( ((double)(config->GetValue( "CPUFreq" )) 
                    / (double)(config->GetValue( "CLK" ))) * simulateCycles ); 

    std::cout << simulateCycles << " memory cycles) ***" << std::endl;

    currentCycle = 0;
    while( currentCycle <= simulateCycles || simulateCycles == 0 )
    {
        if( !trace->GetNextAccess( tl ) )
        {
            /* Force all modules to drain requests. */
            bool draining = Drain( );

            std::cout << "Could not read next line from trace file!" 
                << std::endl;

            /* Wait for requests to drain. */
            while( outstandingRequests > 0 )
            {
                if( EventDriven )
                    globalEventQueue->Cycle( 1 );
                else 
                    GetChild( )->Cycle( 1 );
              
                currentCycle++;

                /* Retry drain each cycle if it failed. */
                if( !draining )
                    draining = Drain( );
            }

            break;
        }

        NVMainRequest *request = new NVMainRequest( );
        
        request->address = tl->GetAddress( );
        request->type = tl->GetOperation( );
        request->bulkCmd = CMD_NOP;
        request->threadId = tl->GetThreadId( );
        if( !IgnoreData ) request->data = tl->GetData( );
        if( !IgnoreData ) request->oldData = tl->GetOldData( );
        request->status = MEM_REQUEST_INCOMPLETE;
        request->owner = (NVMObject *)this;
        
        /* 
         * If you want to ignore the cycles used in the trace file, just set
         * the cycle to 0. 
         */
        if( config->KeyExists( "IgnoreTraceCycle" ) 
                && config->GetString( "IgnoreTraceCycle" ) == "true" )
            tl->SetLine( tl->GetAddress( ), tl->GetOperation( ), 0, 
                         tl->GetData( ), tl->GetOldData( ), tl->GetThreadId( ) );

        if( request->type != READ && request->type != WRITE )
            std::cout << "traceMain: Unknown Operation: " << request->type 
                << std::endl;

        /* 
         * If the next operation occurs after the requested number of cycles,
         * we can quit. 
         */
        if( tl->GetCycle( ) > simulateCycles && simulateCycles != 0 )
        {
            if( EventDriven )
            {
                globalEventQueue->Cycle( simulateCycles - currentCycle );
                currentCycle += simulateCycles - currentCycle;

                break;
            }

            /* Just ride it out 'til the end. */
            while( currentCycle < simulateCycles )
            {
                GetChild( )->Cycle( 1 );
              
                currentCycle++;
            }

            break;
        }
        else
        {
            /* 
             *  If the command is in the past, it can be issued. This would 
             *  occur since the trace was probably generated with an inaccurate 
             *  memory *  simulator, so the cycles may not match up. Otherwise, 
             *  we need to wait.
             */
            if( tl->GetCycle( ) > currentCycle )
            {
                if( EventDriven )
                {
                    globalEventQueue->Cycle( tl->GetCycle() - currentCycle );
                    currentCycle = globalEventQueue->GetCurrentCycle( );
                }
                else
                {
                    /* Wait until currentCycle is the trace operation's cycle. */
                    while( currentCycle < tl->GetCycle( ) )
                    {
                        if( currentCycle >= simulateCycles && simulateCycles != 0 )
                            break;

                        GetChild( )->Cycle( 1 );

                        currentCycle++;
                    }
                }

                if( currentCycle >= simulateCycles && simulateCycles != 0 )
                    break;
            }

            /* 
             *  Wait for the memory controller to accept the next command.. 
             *  the trace reader is "stalling" until then.
             */
            while( !GetChild( )->IsIssuable( request ) )
            {
                if( currentCycle >= simulateCycles && simulateCycles != 0 )
                    break;

                if( EventDriven )
                {
                    globalEventQueue->Cycle( 1 );
                    currentCycle = globalEventQueue->GetCurrentCycle( );
                }
                else 
                {
                    GetChild( )->Cycle( 1 );
                    currentCycle++;
                }
            }

            outstandingRequests++;
            GetChild( )->IssueCommand( request );

            if( currentCycle >= simulateCycles && simulateCycles != 0 )
                break;
        }
    }       

    GetChild( )->CalculateStats( );
    std::ostream& refStream = (statStream.is_open()) ? statStream : std::cout;
    stats->PrintAll( refStream );

    std::cout << "Exiting at cycle " << currentCycle << " because simCycles " 
        << simulateCycles << " reached." << std::endl; 
    if( outstandingRequests > 0 )
        std::cout << "Note: " << outstandingRequests << " requests still in-flight."
                  << std::endl;

    delete config;
    delete stats;

    return 0;
}