Esempio n. 1
0
void Objects::update(ObjectIndex index, EntityIndex entity, ObjectLocation location, CursorStyle cursor, CursorStyle cursor2) {
	if (index >= kObjectMax)
		return;

	Object *object = &_objects[index];

	// Store original location
	ObjectLocation original_location = object->location;

	// Update entity
	object->entity = entity;
	object->location = location;

	if (cursor != kCursorKeepValue || cursor2 != kCursorKeepValue) {
		if (cursor != kCursorKeepValue)
			object->cursor = cursor;
		if (cursor2 != kCursorKeepValue)
			object->cursor2 = cursor2;

		getLogic()->updateCursor();
	}

	getFlags()->flag_3 = true;

	// Compartments
	if (original_location != location && (original_location == kObjectLocation2 || location == kObjectLocation2))
		if ((index >= kObjectCompartment1 && index <= kObjectCompartment8)
	     || (index >= kObjectCompartmentA && index <= kObjectCompartmentF)) {
		 	getScenes()->updateDoorsAndClock();
		}
}
Esempio n. 2
0
void Objects::update(ObjectIndex index, EntityIndex entity, ObjectLocation status, CursorStyle windowCursor, CursorStyle handleCursor) {
	if (index >= kObjectMax)
		return;

	Object *object = &_objects[index];

	// Store original location
	ObjectLocation original_status = object->status;

	// Update entity
	object->entity = entity;
	object->status = status;

	if (windowCursor != kCursorKeepValue || handleCursor != kCursorKeepValue) {
		if (windowCursor != kCursorKeepValue)
			object->windowCursor = windowCursor;
		if (handleCursor != kCursorKeepValue)
			object->handleCursor = handleCursor;

		getLogic()->updateCursor();
	}

	getFlags()->flag_3 = true;

	// Compartments
	if (original_status != status && (original_status == kObjectLocation2 || status == kObjectLocation2)) {
		if ((index >= kObjectCompartment1 && index <= kObjectCompartment8)
		   || (index >= kObjectCompartmentA && index <= kObjectCompartmentF)) {
			getScenes()->updateDoorsAndClock();
		}
	}
}
Esempio n. 3
0
//------------------------------------------------------------------------------
//! @brief   Export GPIO
//------------------------------------------------------------------------------
void GpioManager::exportPin( epicsUInt32 gpio ) {
  static std::string _exportFile = "/sys/class/gpio/export";

  // Each GPIO should only be handled by a single record
  // If GPIO is already exported by GpioManager throw an exception
  std::map< epicsUInt32, GPIO >::iterator it = _mgpio.find( gpio );
  if( it != _mgpio.end() ){
    if ( it->second.exported ) {
      std::stringstream errmsg;
      errmsg << ERR_BEGIN << "GpioManager::exportPin: Error: GPIO " << gpio << " already exported" << ERR_END;
      throw GpioManagerError( errmsg.str() );
    }
  }

  // Check if Pin was exported by another process
  std::stringstream gpioDir;
  gpioDir << _gpiobase << gpio << "/direction";
  if( access( gpioDir.str().c_str(), F_OK ) == 0 ) {
    GPIO nfo;
    nfo.exported = true;
    _mgpio.insert( std::make_pair( gpio, nfo ) );
    nfo.logic    = getLogic( gpio );
    nfo.dir      = getDirection( gpio );

    std::stringstream errmsg;
    errmsg << ERR_BEGIN << "GpioManager::exportPin: Warning: GPIO " << gpio << " already exported! Might be used by another process!" << ERR_END;
    throw GpioManagerWarning( errmsg.str() );
  }

  std::fstream exportFs( _exportFile.c_str(), std::fstream::out );

  if( !exportFs.is_open() || !exportFs.good() ) {
    std::stringstream errmsg;
    errmsg << ERR_BEGIN << "GpioManager::exportPin: Could not open export file: "
           << strerror( errno ) << ERR_END;
    throw GpioManagerError( errmsg.str() );
  }

  exportFs << gpio;
  exportFs.flush();
  if( exportFs.bad() ) {
    std::stringstream errmsg;
    errmsg << ERR_BEGIN << "GpioManager::exportPin: Could not export pin "
           << gpio << ": "
           << strerror( errno ) << ERR_END;
    throw GpioManagerError( errmsg.str() );
  }
  exportFs.close();

  GPIO nfo = { true, ACTIVE_HIGH, UNDIFIEND };
  _mgpio.insert( std::make_pair( gpio, nfo ) );
}
MSTrafficLightLogic*
MSTLLogicControl::TLSLogicVariants::getLogicInstantiatingOff(MSTLLogicControl& tlc,
        const std::string& programID) {
    if (myVariants.find(programID) == myVariants.end()) {
        if (programID == "off") {
            // build an off-tll if this switch indicates it
            if (!addLogic("off", new MSOffTrafficLightLogic(tlc, myCurrentProgram->getID()), true, true)) {
                // inform the user if this fails
                throw ProcessError("Could not build an off-state for tls '" + myCurrentProgram->getID() + "'.");
            }
        } else {
            // inform the user about a missing logic
            throw ProcessError("Can not switch tls '" + myCurrentProgram->getID() + "' to program '" + programID + "';\n The program is not known.");
        }
    }
    return getLogic(programID);
}
Esempio n. 5
0
void
MSTLLogicControl::TLSLogicVariants::setStateInstantiatingOnline(MSTLLogicControl& tlc,
        const std::string& state) {
    // build only once...
    MSTrafficLightLogic* logic = getLogic("online");
    if (logic == nullptr) {
        MSPhaseDefinition* phase = new MSPhaseDefinition(DELTA_T, state, -1);
        std::vector<MSPhaseDefinition*> phases;
        phases.push_back(phase);
        logic = new MSSimpleTrafficLightLogic(tlc, myCurrentProgram->getID(), "online", TLTYPE_STATIC, phases, 0,
                                              MSNet::getInstance()->getCurrentTimeStep() + DELTA_T,
                                              std::map<std::string, std::string>());
        addLogic("online", logic, true, true);
        MSNet::getInstance()->createTLWrapper(logic);
    } else {
        MSPhaseDefinition nphase(DELTA_T, state, -1);
        *(dynamic_cast<MSSimpleTrafficLightLogic*>(logic)->getPhases()[0]) = nphase;
        switchTo(tlc, "online");
    }
}
Esempio n. 6
0
// Start a game (or load an existing savegame)
void Menu::startGame() {
	// Clear savegame headers
	getSaveLoad()->clear();

	// Hide menu elements
	_clock->clear();
	_trainLine->clear();

	if (_lastIndex == _index) {
		setGlobalTimer(0);
		if (_index) {
			getSaveLoad()->loadGame(_gameId);
		} else {
			getLogic()->resetState();
			getEntities()->setup(true, kEntityPlayer);
		}
	} else {
		getSaveLoad()->loadGame(_gameId, _index);
	}
}
Esempio n. 7
0
//////////////////////////////////////////////////////////////////////////
// Setup
void Menu::setup() {

	// Clear drawing queue
	getScenes()->removeAndRedraw(&_frames[kOverlayAcorn], false);
	SAFE_DELETE(_seqAcorn);

	// Load Menu scene
	// + 1 = normal menu with open egg / clock
	// + 2 = shield menu, when no savegame exists (no game has been started)
	_isGameStarted = _lowerTime >= kTimeStartGame;
	getScenes()->loadScene((SceneIndex)(_isGameStarted ? _gameId * 5 + 1 : _gameId * 5 + 2));
	getFlags()->shouldRedraw = true;
	getLogic()->updateCursor();

	//////////////////////////////////////////////////////////////////////////
	// Load Acorn sequence
	_seqAcorn = loadSequence(getAcornSequenceName(_isGameStarted ? getNextGameId() : kGameBlue));

	//////////////////////////////////////////////////////////////////////////
	// Check if we loaded sequences before
	if (_seqTooltips && _seqTooltips->count() > 0)
		return;

	// Load all static data
	_seqTooltips = loadSequence("helpnewr.seq");
	_seqEggButtons = loadSequence("buttns.seq");
	_seqButtons = loadSequence("quit.seq");
	_seqCity1 = loadSequence("jlinetl.seq");
	_seqCity2 = loadSequence("jlinecen.seq");
	_seqCity3 = loadSequence("jlinebr.seq");
	_seqCredits = loadSequence("credits.seq");

	_frames[kOverlayTooltip] = new SequenceFrame(_seqTooltips);
	_frames[kOverlayEggButtons] = new SequenceFrame(_seqEggButtons);
	_frames[kOverlayButtons] = new SequenceFrame(_seqButtons);
	_frames[kOverlayAcorn] = new SequenceFrame(_seqAcorn);
	_frames[kOverlayCity1] = new SequenceFrame(_seqCity1);
	_frames[kOverlayCity2] = new SequenceFrame(_seqCity2);
	_frames[kOverlayCity3] = new SequenceFrame(_seqCity3);
	_frames[kOverlayCredits] = new SequenceFrame(_seqCredits);
}
int main(int argc,char* argv[])
{
    bool flag = true;
    while(inputLogicMap())
    {
        if(flag)
        {
            flag = false;
        }
        else
        {
            printf("\n");
        }
        getResultPosition();
        while(scanf("%s",logicAlpha),*logicAlpha!='*')
        {
            printf("%d\n",getLogic(resultX, resultY, NOTSURE));
        }
    }
    return 0;
}
Esempio n. 9
0
void Menu::setLogicEventHandlers() {
	SET_EVENT_HANDLERS(Logic, getLogic());
	clear();
	_isShowingMenu = false;
}
bool getLogic(int x, int y, Direction direction)
{
    #ifdef DEBUG
        printf("Position: x %d, y %d  Direction: %d\n",x,y,direction);
    #endif
    switch(logicMap[x][y])
    {
        case '?':
            if(logicMap[x][y-1] == '-')
            {
                return getLogic(x,y-1,LEFT);
            }
            else if(logicMap[x][y+1] == '-')
            {
                return getLogic(x,y+1,RIGHT);
            }
            else if(logicMap[x-1][y] == '|')
            {
                return getLogic(x-1,y,UP);
            }
            else
            {
                return getLogic(x+1,y,DOWN);
            }
            break;
        case '-':
            if(direction == LEFT)
            {
                return getLogic(x,y-1,LEFT);
            }
            else
            {
                return getLogic(x,y+1,RIGHT);
            }
            break;
        case '|':
            if(direction == UP)
            {
                return getLogic(x-1,y,UP);
            }
            else
            {
                return getLogic(x+1,y,DOWN);
            }
            break;
        case '+':
            if(direction == UP || direction == DOWN)
            {
                if(logicMap[x][y-1] == '-')
                {
                    return getLogic(x,y-1,LEFT);
                }
                else
                {
                    return getLogic(x,y+1,RIGHT);
                }
            }
            else
            {
                if(logicMap[x-1][y] == '|')
                {
                    return getLogic(x-1,y,UP);
                }
                else
                {
                    return getLogic(x+1,y,DOWN);
                }
            }
            break;
        case 'o':
            if((logicMap[x][y-1] == '-' || logicMap[x][y-1] == ')' || logicMap[x][y-1] == '>') && direction!=RIGHT)
            {
                return !getLogic(x,y-1,LEFT);
            }
            else if(logicMap[x][y+1] == '-' && direction!=LEFT)
            {
                return !getLogic(x,y+1,RIGHT);
            }
            else if(logicMap[x-1][y] == '|' && direction!=DOWN)
            {
                return !getLogic(x-1,y,UP);
            }
            else
            {
                return !getLogic(x+1,y,DOWN);
            }
            break;
        case ')':
            return getLogic(x-1,y-3,LEFT) && getLogic(x+1,y-3,LEFT);
        case '>':
            return getLogic(x-1,y-3,LEFT) || getLogic(x+1,y-3,LEFT);
        default:
            if(isAlpha(logicMap[x][y]))
            {
                return logicAlpha[logicMap[x][y] - 'A'] == '1';
            }
    }
}