Exemple #1
0
void ParticleSystemProxy::simulateNoHeightmap()
{
    int timediff = int(GUIEngine::getLatestDt() * 1000.f);
    int active_count = getEmitter()->getMaxLifeTime() * getEmitter()->getMaxParticlesPerSecond() / 1000;
    core::matrix4 matrix = getAbsoluteTransformation();
    glUseProgram(ParticleShader::SimpleSimulationShader::Program);
    glEnable(GL_RASTERIZER_DISCARD);

    glUniform1i(ParticleShader::SimpleSimulationShader::uniform_dt, timediff);
    glUniform1i(ParticleShader::SimpleSimulationShader::uniform_level, active_count);
    glUniformMatrix4fv(ParticleShader::SimpleSimulationShader::uniform_sourcematrix, 1, GL_FALSE, matrix.pointer());
    glUniform1f(ParticleShader::SimpleSimulationShader::uniform_size_increase_factor, size_increase_factor);

    glBindVertexArray(current_simulation_vao);
    glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, tfb_buffers[1]);

    glBeginTransformFeedback(GL_POINTS);
    glDrawArrays(GL_POINTS, 0, count);
    glEndTransformFeedback();
    glBindVertexArray(0);

    glDisable(GL_RASTERIZER_DISCARD);
    std::swap(tfb_buffers[0], tfb_buffers[1]);
    std::swap(current_rendering_vao, non_current_rendering_vao);
    std::swap(current_simulation_vao, non_current_simulation_vao);
}
Exemple #2
0
void CodeGen::genFloatConst(GenTree* tree, RegSet::RegisterPreference* pref)
{
    assert(tree->gtOper == GT_CNS_DBL);
    var_types type       = tree->gtType;
    double    constValue = tree->gtDblCon.gtDconVal;
    size_t*   cv         = (size_t*)&constValue;

    regNumber dst = regSet.PickRegFloat(type, pref);

    if (type == TYP_FLOAT)
    {
        regNumber reg = regSet.rsPickReg();

        float f = forceCastToFloat(constValue);
        genSetRegToIcon(reg, *((int*)(&f)));
        getEmitter()->emitIns_R_R(INS_vmov_i2f, EA_4BYTE, dst, reg);
    }
    else
    {
        assert(type == TYP_DOUBLE);
        regNumber reg1 = regSet.rsPickReg();
        regNumber reg2 = regSet.rsGrabReg(RBM_ALLINT & ~genRegMask(reg1));

        genSetRegToIcon(reg1, cv[0]);
        regSet.rsLockReg(genRegMask(reg1));
        genSetRegToIcon(reg2, cv[1]);
        regSet.rsUnlockReg(genRegMask(reg1));

        getEmitter()->emitIns_R_R_R(INS_vmov_i2d, EA_8BYTE, dst, reg1, reg2);
    }
    genMarkTreeInReg(tree, dst);

    return;
}
//-----------------------------------------------------------------------
void PUDoPlacementParticleEventHandler::handle (PUParticleSystem3D* particleSystem, PUParticle3D* particle, float timeElapsed)
{
    if (!particle)
        return;

    if (!_found)
    {
        auto system = particleSystem;
        auto emitter = system->getEmitter(_forceEmitterName);
        //ParticleTechnique* technique = particleTechnique;
        //ParticleEmitter* emitter = particleTechnique->getEmitter(_forceEmitterName);
        if (!emitter)
        {
            // Search all techniques in this ParticleSystem for an emitter with the correct name
            PUParticleSystem3D* parentSystem = particleSystem->getParentParticleSystem();
            if (parentSystem){
                auto children = parentSystem->getChildren();
                for(auto iter : children)		
                {
                    PUParticleSystem3D *child  = dynamic_cast<PUParticleSystem3D *>(iter);
                    if (child){
                        system = child;
                        emitter = system->getEmitter(_forceEmitterName);
                        if (emitter)
                        {
                            break;
                        }
                    }
                }
            }
        }
        if (emitter)
        {
            _system = system;
            _emitter = emitter;
            if (_system)
            {
                _system->addListener(this);
            }
            _found = true;
        }
        else
        {
            return;
        }
    }

    // Emit 1 or more particles
    if (_system)
    {
        _baseParticle = particle;
        _system->forceEmission(_emitter, _numberOfParticles);
    }

    _baseParticle = 0;
}
Exemple #4
0
void ParticleSystemProxy::render() {
    if (!getEmitter() || !isGPUParticleType(getEmitter()->getType()))
    {
        CParticleSystemSceneNode::render();
        return;
    }
    if (!current_rendering_vao || !non_current_rendering_vao || !current_simulation_vao || !non_current_simulation_vao)
        generateVAOs();
    simulate();
    draw();
}
Exemple #5
0
void ParticleSystemProxy::simulateHeightmap()
{
	int timediff = int(GUIEngine::getLatestDt() * 1000.f);
	int active_count = getEmitter()->getMaxLifeTime() * getEmitter()->getMaxParticlesPerSecond() / 1000;
	core::matrix4 matrix = getAbsoluteTransformation();
	glUseProgram(HeightmapSimulationShader::Program);
	glEnable(GL_RASTERIZER_DISCARD);
	glEnableVertexAttribArray(HeightmapSimulationShader::attrib_position);
	glEnableVertexAttribArray(HeightmapSimulationShader::attrib_lifetime);
	glEnableVertexAttribArray(HeightmapSimulationShader::attrib_velocity);
	glEnableVertexAttribArray(HeightmapSimulationShader::attrib_size);
	glBindBuffer(GL_ARRAY_BUFFER, tfb_buffers[0]);
	glVertexAttribPointer(HeightmapSimulationShader::attrib_position, 3, GL_FLOAT, GL_FALSE, sizeof(ParticleData), (GLvoid*)0);
	glVertexAttribPointer(HeightmapSimulationShader::attrib_lifetime, 1, GL_FLOAT, GL_FALSE, sizeof(ParticleData), (GLvoid*)(3 * sizeof(float)));
	glVertexAttribPointer(HeightmapSimulationShader::attrib_velocity, 4, GL_FLOAT, GL_FALSE, sizeof(ParticleData), (GLvoid*)(4 * sizeof(float)));
	glVertexAttribPointer(HeightmapSimulationShader::attrib_size, 1, GL_FLOAT, GL_FALSE, sizeof(ParticleData), (GLvoid*)(7 * sizeof(float)));
	glEnableVertexAttribArray(HeightmapSimulationShader::attrib_initial_position);
	glEnableVertexAttribArray(HeightmapSimulationShader::attrib_initial_lifetime);
	glEnableVertexAttribArray(HeightmapSimulationShader::attrib_initial_velocity);
	glEnableVertexAttribArray(HeightmapSimulationShader::attrib_initial_size);
	glBindBuffer(GL_ARRAY_BUFFER, initial_values_buffer);
	glVertexAttribPointer(HeightmapSimulationShader::attrib_initial_position, 3, GL_FLOAT, GL_FALSE, sizeof(ParticleData), (GLvoid*)0);
	glVertexAttribPointer(HeightmapSimulationShader::attrib_initial_lifetime, 1, GL_FLOAT, GL_FALSE, sizeof(ParticleData), (GLvoid*)(3 * sizeof(float)));
	glVertexAttribPointer(HeightmapSimulationShader::attrib_initial_velocity, 4, GL_FLOAT, GL_FALSE, sizeof(ParticleData), (GLvoid*)(4 * sizeof(float)));
	glVertexAttribPointer(HeightmapSimulationShader::attrib_initial_size, 1, GL_FLOAT, GL_FALSE, sizeof(ParticleData), (GLvoid*)(7 * sizeof(float)));
	glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, tfb_buffers[1]);

	glUniform1i(HeightmapSimulationShader::uniform_dt, timediff);
	glUniform1i(HeightmapSimulationShader::uniform_level, active_count);
	glUniformMatrix4fv(HeightmapSimulationShader::uniform_sourcematrix, 1, GL_FALSE, matrix.pointer());
	glUniform1f(HeightmapSimulationShader::uniform_size_increase_factor, size_increase_factor);
	glActiveTexture(GL_TEXTURE2);
	glBindTexture(GL_TEXTURE_BUFFER, heightmaptexture);
	glUniform1i(HeightmapSimulationShader::uniform_heightmap, 2);
	glUniform1f(HeightmapSimulationShader::uniform_track_x, track_x);
	glUniform1f(HeightmapSimulationShader::uniform_track_z, track_z);
	glUniform1f(HeightmapSimulationShader::uniform_track_x_len, track_x_len);
	glUniform1f(HeightmapSimulationShader::uniform_track_z_len, track_z_len);

	glBeginTransformFeedback(GL_POINTS);
	glDrawArrays(GL_POINTS, 0, count);
	glEndTransformFeedback();
	glDisableVertexAttribArray(HeightmapSimulationShader::attrib_position);
	glDisableVertexAttribArray(HeightmapSimulationShader::attrib_lifetime);
	glDisableVertexAttribArray(HeightmapSimulationShader::attrib_velocity);
	glDisableVertexAttribArray(HeightmapSimulationShader::attrib_size);
	glDisableVertexAttribArray(HeightmapSimulationShader::attrib_initial_position);
	glDisableVertexAttribArray(HeightmapSimulationShader::attrib_initial_lifetime);
	glDisableVertexAttribArray(HeightmapSimulationShader::attrib_initial_velocity);
	glDisableVertexAttribArray(HeightmapSimulationShader::attrib_initial_size);
	glDisable(GL_RASTERIZER_DISCARD);
	std::swap(tfb_buffers[0], tfb_buffers[1]);
}
Exemple #6
0
void ParticleSystemProxy::render() {
	if (!getEmitter() || !isGPUParticleType(getEmitter()->getType()))
	{
		CParticleSystemSceneNode::render();
		return;
	}
	simulate();
	draw();
	// We need to force irrlicht to update its internal states
	irr::video::IVideoDriver * const drv = irr_driver->getVideoDriver();
	drv->setMaterial(fakemat);
	static_cast<irr::video::COpenGLDriver*>(drv)->setRenderStates3DMode();
}
Exemple #7
0
void                CodeGen::psiEndPrologScope(psiScope * scope)
{
    scope->scEndLoc.CaptureLocation(getEmitter());
    assert(scope->scEndLoc.Valid());

    // Remove from open-scope list
    scope->scPrev->scNext       = scope->scNext;
    if (scope->scNext)
    {
        scope->scNext->scPrev   = scope->scPrev;
    }
    else
    {
        psiOpenScopeLast        = scope->scPrev;
    }

    // Add to the finished scope list.
    // If the length is zero, it means that the prolog is empty. In that case,
    // CodeGen::genSetScopeInfo will report the liveness of all arguments
    // as spanning the first instruction in the method, so that they can
    // at least be inspected on entry to the method.
    if (scope->scStartLoc     != scope->scEndLoc ||
        scope->scStartLoc.IsOffsetZero())
    {
        psiScopeLast->scNext = scope;
        psiScopeLast         = scope;
        psiScopeCnt++;
    }
}
Exemple #8
0
CodeGen::siScope *          CodeGen::siNewScope( unsigned       LVnum,
                                                 unsigned       varNum)
{
    bool        tracked      = compiler->lvaTable[varNum].lvTracked;
    unsigned    varIndex     = compiler->lvaTable[varNum].lvVarIndex;

    if (tracked)
    {
        siEndTrackedScope(varIndex);
    }


    siScope * newScope       = (siScope*) compiler->compGetMem(sizeof(*newScope), CMK_SiScope);

    newScope->scStartLoc.CaptureLocation(getEmitter());
    assert(newScope->scStartLoc.Valid());

    newScope->scEndLoc.Init();

    newScope->scLVnum        = LVnum;
    newScope->scVarNum       = varNum;
    newScope->scNext         = NULL;
    newScope->scStackLevel   = genStackLevel;       // used only by stack vars

    siOpenScopeLast->scNext  = newScope;
    newScope->scPrev         = siOpenScopeLast;
    siOpenScopeLast          = newScope;

    if (tracked)
    {
        siLatestTrackedScopes[varIndex] = newScope;
    }

    return newScope;
}
void ParticleManager::addEmitter(const std::string& filename, const Point& position, int order) {
  auto emitter = getEmitter(filename);
  emitter->setPosition(position);
  emitter->setAutoRemoveOnFinish(true);

  getParent()->addChild(emitter, order);
}
void AdvancedSettings::onColorChanged (QString color)
{
    int emitter = getEmitter (QObject::sender());

    /* The color is empty, use the previous value */
    if (color.isEmpty())
        color = QVariant (getColor (emitter)).toString();

    /* Make sure that the color is formatted as a HEX color */
    if (!color.contains ("#"))
        color = "#" + color;

    /* We use CSS to change the color of the preview box */
    QString style = QString ("background-color: %1;").arg (color);

    /* Update the preview box that matches the line edit that was changed */
    switch (emitter) {
    case Base:
        ui.BaseEdit->setText (color);
        ui.BaseBox->setStyleSheet (style);
        break;
    case Highlight:
        ui.HighlightEdit->setText (color);
        ui.HighlightBox->setStyleSheet (style);
        break;
    case Background:
        ui.BackgroundEdit->setText (color);
        ui.BackgroundBox->setStyleSheet (style);
        break;
    case Foreground:
        ui.ForegroundEdit->setText (color);
        ui.ForegroundBox->setStyleSheet (style);
        break;
    }
}
void AdvancedSettings::onSelectorClicked()
{
    int emitter = getEmitter (QObject::sender());

    /* Configure the color dialog */
    QString color;
    QColorDialog dialog;
    dialog.setCurrentColor (getColor (emitter));
    dialog.setOption (QColorDialog::DontUseNativeDialog);

    /* Get new color */
    if (dialog.exec() == QColorDialog::Accepted)
        color = QVariant (dialog.currentColor()).toString();

    /* User clicked the 'Cancel' button in the color dialog */
    else
        return;

    /* Update the line edit that matches the button that called this function */
    switch (emitter) {
    case Base:
        ui.BaseEdit->setText (color);
        break;
    case Highlight:
        ui.HighlightEdit->setText (color);
        break;
    case Background:
        ui.BackgroundEdit->setText (color);
        break;
    case Foreground:
        ui.ForegroundEdit->setText (color);
        break;
    }
}
SSLSimTransceiver::SSLSimTransceiver(const ros::NodeHandle& n) :  nh(n)
{
  emitter=getEmitter("emitter");

  first_command_arrived = false;
  sub_command =
      nh.subscribe("team_command",1000,&SSLSimTransceiver::teamCommandCallback, this);
}
Exemple #13
0
// ----------------------------------------------------------------------------
void STKParticle::generate(std::vector<CPUParticle>* out)
{
    if (!getEmitter())
    {
        return;
    }

    Buffer->BoundingBox.reset(AbsoluteTransformation.getTranslation());
    int active_count = getEmitter()->getMaxLifeTime() *
        getEmitter()->getMaxParticlesPerSecond() / 1000;
    if (m_first_execution)
    {
        m_previous_frame_matrix = AbsoluteTransformation;
        for (int i = 0; i <
            (m_max_count > 5000 ? 5 : m_pre_generating ? 100 : 0); i++)
        {
            if (m_hm != NULL)
            {
                stimulateHeightMap((float)i, active_count, NULL);
            }
            else
            {
                stimulateNormal((float)i, active_count, NULL);
            }
        }
        m_first_execution = false;
    }

    float dt = GUIEngine::getLatestDt() * 1000.f;
    if (m_hm != NULL)
    {
        stimulateHeightMap(dt, active_count, out);
    }
    else
    {
        stimulateNormal(dt, active_count, out);
    }
    m_previous_frame_matrix = AbsoluteTransformation;

    core::matrix4 inv(AbsoluteTransformation, core::matrix4::EM4CONST_INVERSE);
    inv.transformBoxEx(Buffer->BoundingBox);

}   // generate
EvolverController::EvolverController() : Supervisor(),
logger(Logger::getInstance("EvolverController"))
{
    // setup shape encoding
    if (SHAPE_ENCODING == "CPPN")
    {
        genomeManager = new CppnGenomeManager();
    }
    else
    {
        // set genomeManager for other kind of genome
        logger.errorStream() << "Unknown Shape Encoding: " << SHAPE_ENCODING;
    }
    
    if (MIND_ENCODING == "RLPOWER") {
        mindGenomeManager = new MatrixGenomeManager();
    }
    else
    {
        logger.errorStream() << "Unknown Mind Encoding: " << MIND_ENCODING;
    }
    
    if(PARENT_SELECTION == "BESTTWO") {
        parentSelectionMechanism = new BestTwoParentSelection();
    } else if(PARENT_SELECTION == "BINARY_TOURNAMENT"){
        parentSelectionMechanism = new BinaryTournamentParentSelection();
    } else if (PARENT_SELECTION == "RANDOM") {
        parentSelectionMechanism = new RandomSelection();
    } else {
        logger.errorStream() << "Unknown Parent Selection Mechanism: " << PARENT_SELECTION;
    }
    
    if(MATING_SELECTION == "EVOLVER") {
        matingType = MATING_SELECTION_BY_EVOLVER;
    } else if(MATING_SELECTION == "ORGANISMS"){
        matingType = MATING_SELECTION_BY_ORGANISMS;
    } else {
        logger.errorStream() << "Unknown Mating Selection Mechanism: " << MATING_SELECTION;
    }
    
    if(DEATH_SELECTION == "EVOLVER") {
        deathType = DEATH_SELECTION_BY_EVOLVER;
    } else if(DEATH_SELECTION == "TIME_TO_LIVE"){
        deathType = DEATH_SELECTION_BY_TIME_TO_LIVE;
    } else {
        logger.errorStream() << "Unknown Death Selection Mechanism: " << DEATH_SELECTION;
    }
    
    emitter = getEmitter(EMITTER_NAME);
    emitter->setChannel(CLINIC_CHANNEL);
    receiver = getReceiver(RECEIVER_NAME);
    receiver->setChannel(EVOLVER_CHANNEL);
    
    builder = new Builder();
}
Exemple #15
0
// generate code for ckfinite tree/instruction
void CodeGen::genFloatCheckFinite(GenTree *tree, RegSet::RegisterPreference *pref)
{
    TempDsc  *      temp;
    int             offs;
            
    GenTreePtr op1 = tree->gtOp.gtOp1;

    // Offset of the DWord containing the exponent
    offs = (op1->gtType == TYP_FLOAT) ? 0 : sizeof(int);

    // get tree into a register
    genCodeForTreeFloat(op1, pref);

    regNumber reg = regSet.rsPickReg();

    int expMask;
    if (op1->gtType == TYP_FLOAT)
    {
        getEmitter()->emitIns_R_R(INS_vmov_f2i, EA_4BYTE, reg, op1->gtRegNum);
        expMask = 0x7F800000;
    }
    else // double
    {
        assert(op1->gtType == TYP_DOUBLE);
        getEmitter()->emitIns_R_R(INS_vmov_f2i, EA_4BYTE, reg, 
                                REG_NEXT(op1->gtRegNum)); // the high 32 bits of the double register
        expMask = 0x7FF00000;  
    }
    regTracker.rsTrackRegTrash(reg);

    // Check if the exponent is all ones
    inst_RV_IV(INS_and, reg, expMask, EA_4BYTE);
    inst_RV_IV(INS_cmp, reg, expMask, EA_4BYTE);

    // If exponent was all 1's, we need to throw ArithExcep
    emitJumpKind jmpEqual = genJumpKindForOper(GT_EQ, CK_SIGNED);
    genJumpToThrowHlpBlk(jmpEqual, SCK_ARITH_EXCPN);

    genCodeForTreeFloat_DONE(tree, op1->gtRegNum);
}
Exemple #16
0
void        CodeGen::siEndScope(siScope * scope)
{
    scope->scEndLoc.CaptureLocation(getEmitter());
    assert(scope->scEndLoc.Valid());

    siRemoveFromOpenScopeList(scope);

    LclVarDsc & lclVarDsc1  = compiler->lvaTable[scope->scVarNum];
    if (lclVarDsc1.lvTracked)
    {
        siLatestTrackedScopes[lclVarDsc1.lvVarIndex] = NULL;
    }
}
Exemple #17
0
void        CodeGen::siEndTrackedScope(unsigned varIndex)
{
    siScope * scope     = siLatestTrackedScopes[varIndex];
    if (!scope)
        return;

    scope->scEndLoc.CaptureLocation(getEmitter());
    assert(scope->scEndLoc.Valid());

    siRemoveFromOpenScopeList(scope);

    siLatestTrackedScopes[varIndex] = NULL;
}
void CodeGen::genHWIntrinsicJumpTableFallback(NamedIntrinsic            intrinsic,
                                              regNumber                 nonConstImmReg,
                                              regNumber                 baseReg,
                                              regNumber                 offsReg,
                                              HWIntrinsicSwitchCaseBody emitSwCase)
{
    assert(nonConstImmReg != REG_NA);
    emitter* emit = getEmitter();

    const unsigned maxByte = (unsigned)Compiler::immUpperBoundOfHWIntrinsic(intrinsic) + 1;
    assert(maxByte <= 256);
    BasicBlock* jmpTable[256];

    unsigned jmpTableBase = emit->emitBBTableDataGenBeg(maxByte, true);
    unsigned jmpTableOffs = 0;

    // Emit the jump table
    for (unsigned i = 0; i < maxByte; i++)
    {
        jmpTable[i] = genCreateTempLabel();
        emit->emitDataGenData(i, jmpTable[i]);
    }

    emit->emitDataGenEnd();

    // Compute and jump to the appropriate offset in the switch table
    emit->emitIns_R_C(INS_lea, emitTypeSize(TYP_I_IMPL), offsReg, compiler->eeFindJitDataOffs(jmpTableBase), 0);

    emit->emitIns_R_ARX(INS_mov, EA_4BYTE, offsReg, offsReg, nonConstImmReg, 4, 0);
    emit->emitIns_R_L(INS_lea, EA_PTR_DSP_RELOC, compiler->fgFirstBB, baseReg);
    emit->emitIns_R_R(INS_add, EA_PTRSIZE, offsReg, baseReg);
    emit->emitIns_R(INS_i_jmp, emitTypeSize(TYP_I_IMPL), offsReg);

    // Emit the switch table entries

    BasicBlock* switchTableBeg = genCreateTempLabel();
    BasicBlock* switchTableEnd = genCreateTempLabel();

    genDefineTempLabel(switchTableBeg);

    for (unsigned i = 0; i < maxByte; i++)
    {
        genDefineTempLabel(jmpTable[i]);
        emitSwCase(i);
        emit->emitIns_J(INS_jmp, switchTableEnd);
    }

    genDefineTempLabel(switchTableEnd);
}
Exemple #19
0
void Material::preview(Shape *shape) {
   SurfacePoint pt;
   pt.shape = shape;
   
   if (isEmitter()) {
      Emitter *emitter = getEmitter(pt);
      emitter->preview(shape);
      
      if (emitter != Material::s_nullEmitter)
         safeDelete(emitter);
   }
   
   BSDF *bsdf = getBSDF(pt);
   bsdf->preview(shape);
   
   safeDelete(bsdf);
}
Exemple #20
0
CodeGen::psiScope* CodeGen::psiNewPrologScope(unsigned LVnum, unsigned slotNum)
{
    psiScope* newScope = compiler->getAllocator(CMK_SiScope).allocate<psiScope>(1);

    newScope->scStartLoc.CaptureLocation(getEmitter());
    assert(newScope->scStartLoc.Valid());

    newScope->scEndLoc.Init();

    newScope->scLVnum   = LVnum;
    newScope->scSlotNum = slotNum;

    newScope->scNext         = nullptr;
    psiOpenScopeLast->scNext = newScope;
    newScope->scPrev         = psiOpenScopeLast;
    psiOpenScopeLast         = newScope;

    return newScope;
}
Exemple #21
0
CodeGen::psiScope* CodeGen::psiNewPrologScope(unsigned LVnum, unsigned slotNum)
{
    psiScope* newScope = (psiScope*)compiler->compGetMem(sizeof(*newScope), CMK_SiScope);

    newScope->scStartLoc.CaptureLocation(getEmitter());
    assert(newScope->scStartLoc.Valid());

    newScope->scEndLoc.Init();

    newScope->scLVnum   = LVnum;
    newScope->scSlotNum = slotNum;

    newScope->scNext         = nullptr;
    psiOpenScopeLast->scNext = newScope;
    newScope->scPrev         = psiOpenScopeLast;
    psiOpenScopeLast         = newScope;

    return newScope;
}
void CameraController::initialize() {
    std::cout << "Initializing robot: " << getName() << std::endl;
    emitter = getEmitter("Emitter");
    receiver = getReceiver("Receiver");
    
    TIME_STEP = getBasicTimeStep();
    
    type = parameters->get<int>("Robot." + getName() + ".Type");
    robotIndex = parameters->get<std::size_t>("Robot."+ getName() +".Index");
    
    // Battery is rated in joules here for easy conversion from the motor work
    // Battery specifications are usually in mAh (milliamp-hours).
    // To convert you need the nominal voltage.
    //
    // Reminder:
    // 1 Joule = 1 Newton Meter  ( kg * m^2 / s^2 )
    // 1 Watt-hour = 3600 Joules
    //
    // Roombot battery is 1200 mAh @ 12 V (taken from http://biorob.epfl.ch/roombots )
    // so 1200 mAh * 12 V / 1000 = 14.4 watt-hours (12V taken from https://fmcc.faulhaber.com/details/overview/PGR_3877_13818/PGR_13818_13813/en/ )
    // * 3600 = 51840 Joules
    batteryMax = ((1200 * 12) / 1000) * 3600;
    // Multiply by the number of modules to simulate power sharing
    batteryMax = batteryMax * parameters->get<int>("Robot.Modules_#");
    battery = batteryMax;
    
    // initialization for non-root module
    if (!isRoot()) {
        // set non-root module's emitter and receiver using the intex of the root
        emitter->setChannel(1);
        receiver->setChannel(2);
        receiver->enable(TIME_STEP);
        
        return;
    } else {
        // set root module's emitter and receiver as inverse of the ones for non-root modules
        // in order to make possible the communitation between master and slave
        emitter->setChannel(2);
        receiver->setChannel(1);
        receiver->enable(TIME_STEP);
    }
}
Exemple #23
0
void Material::initSurfacePoint(SurfacePoint &pt) {
   safeDelete(pt.bsdf);
   
   // TODO: abstract this out into SurfacePoint or Material
   if (pt.emitter != Material::s_nullEmitter)
      safeDelete(pt.emitter);
   if (pt.sensor != Material::s_nullSensor)
      safeDelete(pt.sensor);
   
   _initShadingNormal(pt);
   
   pt.bsdf    = getBSDF(pt);
   pt.emitter = getEmitter(pt);
   pt.sensor  = getSensor(pt);
   
   const SpectralSampleSet &ior = 
      getSpectralSampleSet("ior", IndexOfRefraction::AIR, pt);
   
   const unsigned index = Random::sampleInt(0, ior.getN());
   pt.ior2 = ior[index].value;
}
int CAdvThreadPool::startPoolMainFunction()
{
    systemThreadRunnableSign = true;
    bool isAdditionalThreadsQuantityChanged = false;

    int timeout;
    infoTimer.start();
    while(systemThreadRunnableSign)
    {
        QThread::msleep(10);

        //check repeated tasks
        std::unique_lock<std::mutex> locker(repeatTaskMutex);
        for(auto it = repeatedTaskArray.begin(); it != repeatedTaskArray.end(); it++)
        {
            timeout = it->qt_timer.elapsed();

            if(timeout >= it->timePeriod)
            {
                int threadId = -1;
                QString runType = it->run(int(CAdvThread::eRUN_MODES::RUN_TYPE), 0);
                adv_thread_ptr pThread;

                pThread = getFreeThread(threadId, runType.toInt());
                if(pThread == nullptr)
                {
                    emitter->sendSignal_NoThread();
                    continue;
                }
                pThread->appendRunnableTask(it->run, runType.toInt());
                it->qt_timer.start();
            }
        }


        //notification about suspicious behavior
        auto currentTime = std::chrono::high_resolution_clock::now();

        for (auto &it : threadsArray)
        {
            CAdvThread::eThreadType l_iThreadType = it->getThreadType();
            if(l_iThreadType == CAdvThread::eThreadType::THREAD_SHARED) //SHORT_TASK || REPEAT_TASK
            {
                if (!(it->isEmpty()))
                {
                    auto lastTimeOfTaskLaunch = it->getLastTimeOfTaskLaunch();
                    auto deltaTime = std::chrono::duration_cast<std::chrono::milliseconds>(currentTime - lastTimeOfTaskLaunch).count();
                    if((it->isReadyForSend_WarningAboutShortTaskFreeze) && deltaTime > 5000)//very suspicious
                    {
                        getEmitter()->addWarningToShell(QString("Maybe task '%1' was frozen (very suspicious)").arg(it->getWho()), eLogWarning::warning);
                        it->isReadyForSend_WarningAboutShortTaskFreeze = false;
                    }
                }
            }
        }

        //delete extra long threads which was stoped
        additionalThreadsMutex.lock();
        isAdditionalThreadsQuantityChanged = false;
        additionalThreadsArray.remove_if(
        [&isAdditionalThreadsQuantityChanged](adv_thread_ptr thr)
        {
            if(thr->isStoped())
            {
                qDebug() << "Remove thread from additionalThreadsArray";
                isAdditionalThreadsQuantityChanged = true;
                return true;
            }
            else
                return false;
        });
        additionalThreadsMutex.unlock();
        if(isAdditionalThreadsQuantityChanged)
        {
            int longTaskCounter = CAdvThreadPool::getInstance().getLongTaskQuantity();
            emitter->sendSignal_longTaskQuantity(longTaskCounter);
        }
    }
    return 0;
}
Exemple #25
0
void PacketStreamAdapter::emit(IPacket& packet)
{
    getEmitter().emit(packet);
}
Exemple #26
0
void CodeGen::genLoadFloat(GenTreePtr tree, regNumber reg)
{
    if (tree->IsRegVar())
    {
        // if it has been spilled, unspill it.%
        LclVarDsc * varDsc = &compiler->lvaTable[tree->gtLclVarCommon.gtLclNum];
        if (varDsc->lvSpilled)
        {
            UnspillFloat(varDsc);
        }

        inst_RV_RV(ins_FloatCopy(tree->TypeGet()), reg, tree->gtRegNum, tree->TypeGet());
    }
    else
    {
        bool unalignedLoad = false;
        switch (tree->OperGet())
        {
        case GT_IND:
        case GT_CLS_VAR:
            if  (tree->gtFlags & GTF_IND_UNALIGNED)
                unalignedLoad = true;
            break;
        case GT_LCL_FLD:
            // Check for a misalignment on a Floating Point field
            //
            if (varTypeIsFloating(tree->TypeGet()))
            {                
                if ((tree->gtLclFld.gtLclOffs % emitTypeSize(tree->TypeGet())) != 0)
                {
                    unalignedLoad = true;
                }
            }
            break;
        default:
            break;
        }

        if (unalignedLoad)
        {
            // Make the target addressable
            //
            regMaskTP   addrReg = genMakeAddressable(tree, 0, RegSet::KEEP_REG, true);
            regSet.rsLockUsedReg(addrReg);  // Must prevent regSet.rsGrabReg from choosing an addrReg

            var_types loadType = tree->TypeGet();
            assert(loadType == TYP_DOUBLE || loadType == TYP_FLOAT);

            // Unaligned Floating-Point Loads must be loaded into integer register(s)
            // and then moved over to the Floating-Point register
            regNumber  intRegLo    = regSet.rsGrabReg(RBM_ALLINT);
            regNumber  intRegHi    = REG_NA;
            regMaskTP  tmpLockMask = genRegMask(intRegLo);

            if (loadType == TYP_DOUBLE)
            {
                intRegHi     = regSet.rsGrabReg(RBM_ALLINT & ~genRegMask(intRegLo));
                tmpLockMask |= genRegMask(intRegHi);
            }
            
            regSet.rsLockReg(tmpLockMask);     // Temporarily lock the intRegs 
            tree->gtType = TYP_INT;     // Temporarily change the type to TYP_INT

            inst_RV_TT(ins_Load(TYP_INT), intRegLo, tree);
            regTracker.rsTrackRegTrash(intRegLo);

            if (loadType == TYP_DOUBLE)
            {
                inst_RV_TT(ins_Load(TYP_INT), intRegHi, tree, 4);
                regTracker.rsTrackRegTrash(intRegHi);
            }

            tree->gtType = loadType;    // Change the type back to the floating point type
            regSet.rsUnlockReg(tmpLockMask);   // Unlock the intRegs

            // move the integer register(s) over to the FP register
            //
            if  (loadType == TYP_DOUBLE)
                getEmitter()->emitIns_R_R_R(INS_vmov_i2d, EA_8BYTE, reg, intRegLo, intRegHi);
            else 
                getEmitter()->emitIns_R_R(INS_vmov_i2f, EA_4BYTE, reg, intRegLo);

            // Free up anything that was tied up by genMakeAddressable
            //
            regSet.rsUnlockUsedReg(addrReg);
            genDoneAddressable(tree, addrReg, RegSet::KEEP_REG);
        }
        else
        {
            inst_RV_TT(ins_FloatLoad(tree->TypeGet()), reg, tree);
        }
        if (((tree->OperGet() == GT_CLS_VAR) || (tree->OperGet() == GT_IND)) && 
            (tree->gtFlags & GTF_IND_VOLATILE))
        {
            // Emit a memory barrier instruction after the load 
            instGen_MemoryBarrier();
        }
    }
}
bool CC3PointParticle::hasSize()
{
	return getEmitter()->getMesh()->hasVertexPointSizes(); 
}
Exemple #28
0
Emitter *Material::getEmitter() {
   return getEmitter(s_nullSurfacePoint);
}
Exemple #29
0
void CodeGen::genFloatAssign(GenTree *tree)
{
    var_types   type       = tree->TypeGet();
    GenTreePtr  op1        = tree->gtGetOp1();
    GenTreePtr  op2        = tree->gtGetOp2();

    regMaskTP   needRegOp1 = RBM_ALLINT;
    regMaskTP   addrReg    = RBM_NONE;
    bool        volat      = false;        // Is this a volatile store
    bool        unaligned  = false;        // Is this an unaligned store
    regNumber   op2reg     = REG_NA;

#ifdef DEBUGGING_SUPPORT
    unsigned    lclVarNum  = compiler->lvaCount;
    unsigned    lclILoffs  = DUMMY_INIT(0);
#endif

    noway_assert(tree->OperGet() == GT_ASG);

    // Is the target a floating-point local variable?
    //  possibly even an enregistered floating-point local variable?
    //
    switch (op1->gtOper)
    {
        unsigned        varNum;
        LclVarDsc   *   varDsc;

    case GT_LCL_FLD:
        // Check for a misalignment on a Floating Point field
        //
        if (varTypeIsFloating(op1->TypeGet()))
        {                
            if ((op1->gtLclFld.gtLclOffs % emitTypeSize(op1->TypeGet())) != 0)
            {
                unaligned = true;
            }
        }
        break;

    case GT_LCL_VAR:
        varNum = op1->gtLclVarCommon.gtLclNum;
        noway_assert(varNum < compiler->lvaCount);
        varDsc = compiler->lvaTable + varNum;

 #ifdef DEBUGGING_SUPPORT
        // For non-debuggable code, every definition of a lcl-var has
        // to be checked to see if we need to open a new scope for it.
        // Remember the local var info to call siCheckVarScope
        // AFTER code generation of the assignment.
        //
        if (compiler->opts.compScopeInfo && !compiler->opts.compDbgCode && (compiler->info.compVarScopesCount > 0))
        {
            lclVarNum = varNum;
            lclILoffs = op1->gtLclVar.gtLclILoffs;
        }
 #endif

        // Dead Store assert (with min opts we may have dead stores)
        //
        noway_assert(!varDsc->lvTracked || compiler->opts.MinOpts() ||  !(op1->gtFlags & GTF_VAR_DEATH));

        // Does this variable live in a register?
        //
        if (genMarkLclVar(op1))
        {
             noway_assert(!compiler->opts.compDbgCode);   // We don't enregister any floats with debug codegen

            // Get hold of the target register
            //
            regNumber op1Reg = op1->gtRegVar.gtRegNum;

            // the variable being assigned should be dead in op2
            assert(!varDsc->lvTracked || !VarSetOps::IsMember(compiler, genUpdateLiveSetForward(op2), varDsc->lvVarIndex));

            // Setup register preferencing, so that we try to target the op1 enregistered variable
            //
            regMaskTP bestMask = genRegMask(op1Reg);
            if (type==TYP_DOUBLE)
            {
                assert((bestMask & RBM_DBL_REGS) != 0);
                bestMask |= genRegMask(REG_NEXT(op1Reg));
            }
            RegSet::RegisterPreference pref(RBM_ALLFLOAT, bestMask);

            // Evaluate op2 into a floating point register 
            //
            genCodeForTreeFloat(op2, &pref);
    
            noway_assert(op2->gtFlags & GTF_REG_VAL);

            // Make sure the value ends up in the right place ...
            // For example if op2 is a call that returns a result 
            // in REG_F0, we will need to do a move instruction here
            //
            if ((op2->gtRegNum != op1Reg) || (op2->TypeGet() != type))
            {
                regMaskTP spillRegs = regSet.rsMaskUsed & genRegMaskFloat(op1Reg, op1->TypeGet());
                if  (spillRegs != 0)
                    regSet.rsSpillRegs(spillRegs);

                assert(type == op1->TypeGet());

                inst_RV_RV(ins_FloatConv(type, op2->TypeGet()), op1Reg, op2->gtRegNum, type);
            }
            genUpdateLife(op1);
            goto DONE_ASG;
        }
        break;

    case GT_CLS_VAR:
    case GT_IND:
        // Check for a volatile/unaligned store
        //
        assert((op1->OperGet() == GT_CLS_VAR) || (op1->OperGet() == GT_IND));   // Required for GTF_IND_VOLATILE flag to be valid
        if (op1->gtFlags & GTF_IND_VOLATILE)
            volat = true;
        if (op1->gtFlags & GTF_IND_UNALIGNED)
            unaligned = true;
        break;

    default:
        break;
    }

    // Is the value being assigned an enregistered floating-point local variable?
    //
    switch (op2->gtOper)
    {
    case GT_LCL_VAR:

        if  (!genMarkLclVar(op2))
            break;

        __fallthrough;

    case GT_REG_VAR:

        // We must honor the order evalauation in case op1 reassigns our op2 register
        //
        if  (tree->gtFlags & GTF_REVERSE_OPS)
            break;

        // Is there an implicit conversion that we have to insert?
        // Handle this case with the normal cases below.
        //
        if (type != op2->TypeGet())
            break;

        // Make the target addressable
        //
        addrReg = genMakeAddressable(op1, needRegOp1, RegSet::KEEP_REG, true);

        noway_assert(op2->gtFlags & GTF_REG_VAL);
        noway_assert(op2->IsRegVar());
        
        op2reg = op2->gtRegVar.gtRegNum; 
        genUpdateLife(op2);

        goto CHK_VOLAT_UNALIGN;
    default:
        break;
    }

    // Is the op2 (RHS) more complex than op1 (LHS)?
    //
    if  (tree->gtFlags & GTF_REVERSE_OPS)
    {
        regMaskTP bestRegs = regSet.rsNarrowHint(RBM_ALLFLOAT, ~op1->gtRsvdRegs);
        RegSet::RegisterPreference pref(RBM_ALLFLOAT, bestRegs);

        // Generate op2 (RHS) into a floating point register
        //
        genCodeForTreeFloat(op2, &pref);
        regSet.SetUsedRegFloat(op2, true);

        // Make the target addressable
        //
        addrReg = genMakeAddressable(op1,
                                     needRegOp1,
                                     RegSet::KEEP_REG, true);

        genRecoverReg(op2, RBM_ALLFLOAT, RegSet::KEEP_REG);
        noway_assert(op2->gtFlags & GTF_REG_VAL);
        regSet.SetUsedRegFloat(op2, false);
    }
    else
    {
        needRegOp1 = regSet.rsNarrowHint(needRegOp1, ~op2->gtRsvdRegs);

        // Make the target addressable
        //
        addrReg = genMakeAddressable(op1,
                                     needRegOp1,
                                     RegSet::KEEP_REG, true);
        

        // Generate the RHS into any floating point register
        genCodeForTreeFloat(op2);

    }
    noway_assert(op2->gtFlags & GTF_REG_VAL);

    op2reg = op2->gtRegNum;

    // Is there an implicit conversion that we have to insert?
    //
    if (type != op2->TypeGet())
    {
        regMaskTP bestMask = genRegMask(op2reg);
        if (type==TYP_DOUBLE)
        {
            if (bestMask & RBM_DBL_REGS)
            {
                bestMask |= genRegMask(REG_NEXT(op2reg));
            }
            else
            {
                bestMask |= genRegMask(REG_PREV(op2reg));
            }
        }
        RegSet::RegisterPreference op2Pref(RBM_ALLFLOAT, bestMask);
        op2reg = regSet.PickRegFloat(type, &op2Pref);

        inst_RV_RV(ins_FloatConv(type, op2->TypeGet()), op2reg, op2->gtRegNum, type);
    }

    // Make sure the LHS is still addressable
    //
    addrReg = genKeepAddressable(op1, addrReg);

CHK_VOLAT_UNALIGN:
        
    regSet.rsLockUsedReg(addrReg);  // Must prevent unaligned regSet.rsGrabReg from choosing an addrReg
        
    if (volat)
    {
        // Emit a memory barrier instruction before the store
        instGen_MemoryBarrier();
    }
    if (unaligned)
    {
        var_types storeType = op1->TypeGet();
        assert(storeType == TYP_DOUBLE || storeType == TYP_FLOAT);

        // Unaligned Floating-Point Stores must be done using the integer register(s)
        regNumber  intRegLo    = regSet.rsGrabReg(RBM_ALLINT);
        regNumber  intRegHi    = REG_NA;
        regMaskTP  tmpLockMask = genRegMask(intRegLo);

        if (storeType == TYP_DOUBLE)
        {
            intRegHi     = regSet.rsGrabReg(RBM_ALLINT & ~genRegMask(intRegLo));
            tmpLockMask |= genRegMask(intRegHi);
        }

        // move the FP register over to the integer register(s)
        //
        if  (storeType == TYP_DOUBLE)
        {
            getEmitter()->emitIns_R_R_R(INS_vmov_d2i, EA_8BYTE, intRegLo, intRegHi, op2reg);
            regTracker.rsTrackRegTrash(intRegHi);
        }
        else 
        {
            getEmitter()->emitIns_R_R(INS_vmov_f2i, EA_4BYTE, intRegLo, op2reg);
        }
        regTracker.rsTrackRegTrash(intRegLo);

        regSet.rsLockReg(tmpLockMask);     // Temporarily lock the intRegs 
        op1->gtType = TYP_INT;      // Temporarily change the type to TYP_INT
        
        inst_TT_RV(ins_Store(TYP_INT), op1, intRegLo);

        if (storeType == TYP_DOUBLE)
        {
            inst_TT_RV(ins_Store(TYP_INT), op1, intRegHi, 4);
        }
        
        op1->gtType = storeType;    // Change the type back to the floating point type
        regSet.rsUnlockReg(tmpLockMask);   // Unlock the intRegs
    }
    else
    {
        // Move the value into the target
        //        
        inst_TT_RV(ins_Store(op1->TypeGet()), op1, op2reg);
    }

    // Free up anything that was tied up by the LHS
    //
    regSet.rsUnlockUsedReg(addrReg);
    genDoneAddressable(op1, addrReg, RegSet::KEEP_REG);

DONE_ASG:

    genUpdateLife(tree);

#ifdef DEBUGGING_SUPPORT
    /* For non-debuggable code, every definition of a lcl-var has
     * to be checked to see if we need to open a new scope for it.
     */
    if (lclVarNum < compiler->lvaCount)
        siCheckVarScope(lclVarNum, lclILoffs);
#endif
}
Exemple #30
0
//------------------------------------------------------------------------------
//       Class:  Emitter
//      Method:  createFocus
// Description:
//------------------------------------------------------------------------------
FocusPtr System::createFocus(EmitterID theEmitterID)
{
   return getEmitter(theEmitterID).createFocus();
}