Esempio n. 1
0
void Labirinth::setExits(int e)
// check exits already placed, than insert new exits up to desired number
{
  std::cout << "at present time there are " << exits << " exits in labirinth" << std::endl;
  int rand_x;
  int rand_y;
  int i;
  int result;
  i = 0;
  while (exits < e)
  {
    ++i;
    std::cout << "placing exit..." << std::endl;
    rand_x = (rand() + time(0)) % x_side;
    rand_y = (rand() + time(0)) % y_side; 
    result = readTile(rand_x, rand_y);
    std::cout << i << " , (" << rand_x << "," << rand_y << ") , " << result << std::endl;  
    if ( result == 0)
    {
      setExit(rand_x, rand_y);
      ++exits;
      std::cout << "placed exit number " << exits << " at (" << rand_x << "," << rand_y << ")" << std::endl;
    } 
    else
    {
      std::cout << "this is just a wall or exit... another tile will be used" << std::endl;
    }
  }
  std::cout << "at present time there are " << exits << " exits in labirinth" << std::endl;
}
Esempio n. 2
0
MainService::MainService(int argc, char* argv[])
{
		setServiceDescription("The daemon for monitoring and handling the g15 macro service");
		setServiceFlags(QtServiceBase::Default); //Stopped but not suspended

		thread_keys = new KeyThread();
		connect(thread_keys, SIGNAL(writeDbg(const QString)), this, SLOT(writeDbg(const QString)));
		connect(this, SIGNAL(sendExit()), thread_keys, SLOT(setExit()));

		thread_x = new XThread();
		connect(thread_x, SIGNAL(writeDbg(const QString)), this, SLOT(writeDbg(const QString)));
		connect(this, SIGNAL(sendExit()), thread_x, SLOT(setExit()));

		connect(thread_keys, SIGNAL(sendRecordingStatus(bool, int, int)), thread_x, SLOT(setRecordingStatus(bool, int, int)));
		connect(thread_keys, SIGNAL(playbackMacro(int, int)), thread_x, SLOT(playbackMacro(int, int)));
}
Esempio n. 3
0
void TeamMenu::onPressedCancel()
{
    if (mode_ == 0)
    {
        role_ = nullptr;
        result_ = -1;
        setExit(true);
    }
}
Esempio n. 4
0
void Talk::onPressedOK()
{
    if (current_line_ + height_ >= content_lines_.size())
    {
        setExit(true);
    }
    else
    {
        current_line_ += height_;
    }
    //e.type = BP_FIRSTEVENT;
}
Esempio n. 5
0
void System::waitForChange(bool error) {
  while (!isBack() && !isClosing()) {
    processEvents(0);
    if (error && _userScreenId == -1) {
      // back button presses while error displayed
      setExit(true);
      break;
    }
    if (_modifiedTime != getModifiedTime()) {
      break;
    }
    dev_delay(CHANGE_WAIT_SLEEP);
  }
}
Esempio n. 6
0
int ResPonseThread::start(void * param){    	
	int errCode = 0;
	setExit(false);
	do{
		pthread_attr_t attributes;
		errCode = pthread_attr_init(&attributes);
		CC_BREAK_IF(errCode!=0);
		errCode = pthread_attr_setdetachstate(&attributes, PTHREAD_CREATE_DETACHED);
		log("errCode : %d", errCode);
		if (errCode!=0) {
			pthread_attr_destroy(&attributes);
			break;
		}		
		errCode = pthread_create(&handle, &attributes,threadFunc,this);
		started = true; 
	}while (0);
	return errCode;
} 
Esempio n. 7
0
void Liquidmanager::prevScene()
{
	if (lockscene==FALSE)
	{
		m_pCurrentScene = m_pCurrentScene->getPrev();
	}
	else
	{
		m_pCurrentScene = m_pCurrentScene;
	}

	if(m_pCurrentScene == NULL)
		setExit();
	else
	{
		m_pCurrentScene->Init(textures);
		m_pCurrentScene->start();		
	}
}
bool SessionServer::writeSBuf(const char* buf, size_t len)
{
	size_t pos = 0;
	while(pos != len)
	{
		int rs = write(socket, buf + pos, len - pos);
		if(rs < 0)
		{
			setErr(ERR_SOCKET_EXCEPTION);
			return false;
		}
		if(rs == 0)
		{
			setExit();
			return false;
		}
		pos += rs;
	}
	return true;
}
bool SessionServer::validHeader()
{
	char tmp;
	int rs = read(socket, &tmp, 1);
	if(rs < 0)
	{
		setErr(ERR_SOCKET_EXCEPTION);
		return false;
	}
	if(rs == 0)
	{
		setExit();
		return false;
	}
	if(tmp != 'X')
	{
		setErr(ERR_VALIDATE_HEAD);
		return false;
	}
	return true;
}
Esempio n. 10
0
void System::setBack() {
  if (_userScreenId != -1) {
    // return (back) from user screen, (view source)
    _output->selectBackScreen(_userScreenId);
    _output->selectFrontScreen(_userScreenId);
    _userScreenId = -1;
  } else {
    // quit app when shell is active
    setExit(_mainBas);

    // follow history when available and not exiting
    if (!_mainBas) {
      // remove the current item
      strlib::String *old = _history.pop();
      if (old) {
        delete old;
      }
      if (_history.peek() != NULL) {
        _loadPath.clear();
        _loadPath.append(_history.peek());
      }
    }
  }
}
Esempio n. 11
0
void Manifold::Portal::setMutualExits(Manifold::Portal* exit) {
	setExit(exit);
	exit->setExit(this);
}
Esempio n. 12
0
void TMap::connectExitStub(int roomId, int dirType)
{
    TRoom * pR = mpRoomDB->getRoom( roomId );
    if( !pR )
        return;
    int areaId = pR->getAreaId();
    int minDistance = 999999;
    int minDistanceRoom=0, meanSquareDistance=0;
    if( !unitVectors.contains( dirType ) )
        return;
    QVector3D unitVector = unitVectors[dirType];
    int ux = unitVector.x(), uy = unitVector.y(), uz = unitVector.z();
    int rx = pR->x, ry = pR->y, rz = pR->z;
    int dx=0,dy=0,dz=0;
    TArea * pA = mpRoomDB->getArea(areaId);
    if( !pA )
        return;
    for( int i=0; i< pA->rooms.size(); i++ )
    {
        pR = mpRoomDB->getRoom( pA->rooms[i] );
        if( !pR )
            continue;
        if( pR->getId() == roomId )
            continue;
        if(uz)
        {
            dz = (int)pR->z-rz;
            if(!compSign(dz,uz) || !dz) continue;
        }
        else
        {
            //to avoid lower/upper floors from stealing stubs
            if((int)pR->z != rz) continue;
        }
        if(ux)
        {
            dx = (int)pR->x-rx;
            if (!compSign(dx,ux) || !dx) //we do !dx to make sure we have a component in the desired direction
                continue;
        }
        else
        {
            //to avoid rooms on same plane from stealing stubs
            if((int)pR->x != rx) continue;
        }
        if(uy)
        {
            dy = (int)pR->y-ry;
            //if the sign is the SAME here we keep it b/c we flip our y coordinate.
            if (compSign(dy,uy) || !dy)
                continue;
        }
        else
        {
            //to avoid rooms on same plane from stealing stubs
            if((int)pR->y != ry) continue;
        }
        meanSquareDistance=dx*dx+dy*dy+dz*dz;
        if(meanSquareDistance < minDistance)
        {
            minDistanceRoom=pR->getId();
            minDistance=meanSquareDistance;
        }
    }
    if(minDistanceRoom)
    {
        pR = mpRoomDB->getRoom(minDistanceRoom);
        if( !pR ) return;
        if(pR->exitStubs.contains(reverseDirections[dirType]))
        {
            setExit( roomId, minDistanceRoom, dirType);
            setExit( minDistanceRoom, roomId, reverseDirections[dirType]);
        }
    }
}
Esempio n. 13
0
void House::setExit(const Position& pos)
{
	setExit(map, pos);
}
Esempio n. 14
0
void TeamMenu::onPressedOK()
{
    if (mode_ == 0)
    {
        role_ = nullptr;
        for (auto h : heads_)
        {
            if (h->getState() == Press)
            {
                role_ = h->getRole();
            }
        }
        if (role_)
        {
            result_ = 0;
            setExit(true);
        }
    }
    if (mode_ == 1)
    {
        for (auto h : heads_)
        {
            if (h->getState() == Press)
            {
                if (h->getResult() == -1)
                {
                    h->setResult(0);
                }
                else
                {
                    h->setResult(-1);
                }
            }
        }
        if (button_all_.getState() == Press)
        {
            //如果已经全选,则是清除
            int all = -1;
            for (auto h : heads_)
            {
                if (h->getResult() != 0)
                {
                    all = 0;
                    break;
                }
            }
            for (auto h : heads_)
            {
                h->setResult(all);
            }
        }
        if (button_ok_.getState() == Press)
        {
            //没有人被选中,不能确定
            for (auto h : heads_)
            {
                if (h->getResult() == 0)
                {
                    setExit(true);
                }
            }
        }
    }
}
Esempio n. 15
0
// pass the key into the smallbasic keyboard handler
void Controller::handleKey(int key) {
  switch (key) {
  case MAK_FIRE:
  case MAK_5:
    return;
  case MAK_SOFTRIGHT:
  case MAK_BACK:
    if (_systemScreen) {
      // restore user screens
      _output->print("\033[ SR");
      _systemScreen = false;
    } else {
      // quit app when shell is active
      setExit(_mainBas);
    }
    return;
  case MAK_MENU:
    showMenu();
    return;
  }

  if (isRunning()) {
    switch (key) {
    case MAK_TAB:
      dev_pushkey(SB_KEY_TAB);
      break;
    case MAK_HOME:
      dev_pushkey(SB_KEY_KP_HOME);
      break;
    case MAK_END:
      dev_pushkey(SB_KEY_END);
      break;
    case MAK_INSERT:
      dev_pushkey(SB_KEY_INSERT);
      break;
    case MAK_KP_MULTIPLY:
      dev_pushkey(SB_KEY_KP_MUL);
      break;
    case MAK_KP_PLUS:
      dev_pushkey(SB_KEY_KP_PLUS);
      break;
    case MAK_KP_MINUS:
      dev_pushkey(SB_KEY_KP_MINUS);
      break;
    case MAK_SLASH:
      dev_pushkey(SB_KEY_KP_DIV);
      break;
    case MAK_PAGEUP:
      dev_pushkey(SB_KEY_PGUP);
      break;
    case MAK_PAGEDOWN:
      dev_pushkey(SB_KEY_PGDN);
      break;
    case MAK_UP:
      dev_pushkey(SB_KEY_UP);
      break;
    case MAK_DOWN:
      dev_pushkey(SB_KEY_DN);
      break;
    case MAK_LEFT:
      dev_pushkey(SB_KEY_LEFT);
      break;
    case MAK_RIGHT:
      dev_pushkey(SB_KEY_RIGHT);
      break;
    case MAK_CLEAR:
    case MAK_BACKSPACE:
    case MAK_DELETE:
      dev_pushkey(SB_KEY_BACKSPACE);
      break;
    default:
      dev_pushkey(key);
      break;
    }
  }
}
Esempio n. 16
0
// process events on the system event queue
MAEvent Controller::processEvents(int ms, int untilType) {
  MAEvent event;
  MAExtent screenSize;
  int loadPathSize = _loadPath.length();

  if (ms < 0 && untilType != -1) {
    // flush the display before pausing for target event
    if (isRunning()) {
      _output->flush(true);
    }
    maWait(ms);
    ms = EVENT_WAIT_NONE;
  }

  while (!isBreak() && maGetEvent(&event)) {
    switch (event.type) {
    case EVENT_TYPE_OPTIONS_BOX_BUTTON_CLICKED:
      if (_systemMenu) {
        handleMenu(event.optionsBoxButtonIndex);
        ms = EVENT_WAIT_NONE;
      } else if (isRunning()) {
        if (!_output->optionSelected(event.optionsBoxButtonIndex)) {
          dev_pushkey(event.optionsBoxButtonIndex);
        }
      }
      break;
    case EVENT_TYPE_SCREEN_CHANGED:
      screenSize = maGetScrSize();
      _output->resize(EXTENT_X(screenSize), EXTENT_Y(screenSize));
      os_graf_mx = _output->getWidth();
      os_graf_my = _output->getHeight();
      handleKey(SB_PKEY_SIZE_CHG);
      break;
    case EVENT_TYPE_POINTER_PRESSED:
      _touchX = _touchCurX = event.point.x;
      _touchY = _touchCurY = event.point.y;
      handleKey(SB_KEY_MK_PUSH);
      _output->pointerTouchEvent(event);
      break;
    case EVENT_TYPE_POINTER_DRAGGED:
      _touchCurX = event.point.x;
      _touchCurY = event.point.y;
      _output->pointerMoveEvent(event);
      break;
    case EVENT_TYPE_POINTER_RELEASED:
      _touchX = _touchY = _touchCurX = _touchCurY = -1;
      handleKey(SB_KEY_MK_RELEASE);
      _output->pointerReleaseEvent(event);
      break;
    case EVENT_TYPE_CLOSE:
      setExit(true);
      break;
    case EVENT_TYPE_KEY_PRESSED:
      handleKey(event.key);
      break;
    }
    if (untilType == EVENT_TYPE_EXIT_ANY ||
        untilType == event.type ||
        loadPathSize != _loadPath.length()) {
      // skip next maWait() - found target event or loadPath changed
      ms = EVENT_WAIT_NONE;
      break;
    }
  }

  if (ms != EVENT_WAIT_NONE) {
    maWait(ms);
  }
  return event;
}
Esempio n. 17
0
void Runtime::pollEvents(bool blocking) {
  if (isActive() && !isRestart()) {
    SDL_Event ev;
    SDL_Keymod mod;
    if (blocking ? SDL_WaitEvent(&ev) : SDL_PollEvent(&ev)) {
      MAEvent *maEvent = NULL;
      switch (ev.type) {
      case SDL_TEXTINPUT:
        // pre-transformed/composted text
        mod = SDL_GetModState();
        if (!mod || (mod & (KMOD_SHIFT|KMOD_CAPS))) {
          // ALT + CTRL keys handled in SDL_KEYDOWN
          for (int i = 0; ev.text.text[i] != 0; i++) {
            MAEvent *keyEvent = new MAEvent();
            keyEvent->type = EVENT_TYPE_KEY_PRESSED;
            keyEvent->key = ev.text.text[i];
            keyEvent->nativeKey = 0;
            pushEvent(keyEvent);
          }
        }
        break;
      case SDL_QUIT:
        setExit(true);
        break;
      case SDL_KEYDOWN:
        if (!isEditing() && ev.key.keysym.sym == SDLK_c
            && (ev.key.keysym.mod & KMOD_CTRL)) {
          setExit(true);
        } else if (ev.key.keysym.sym == SDLK_m && (ev.key.keysym.mod & KMOD_CTRL)) {
          showMenu();
        } else if (ev.key.keysym.sym == SDLK_b && (ev.key.keysym.mod & KMOD_CTRL)) {
          setBack();
        } else if (ev.key.keysym.sym == SDLK_BACKSPACE &&
                   get_focus_edit() == NULL &&
                   ((ev.key.keysym.mod & KMOD_CTRL) || !isRunning())) {
          setBack();
        } else if (!isEditing() && ev.key.keysym.sym == SDLK_PAGEUP &&
                   (ev.key.keysym.mod & KMOD_CTRL)) {
          _output->scroll(true, true);
        } else if (!isEditing() && ev.key.keysym.sym == SDLK_PAGEDOWN &&
                   (ev.key.keysym.mod & KMOD_CTRL)) {
          _output->scroll(false, true);
        } else if (!isEditing() && ev.key.keysym.sym == SDLK_UP &&
                   (ev.key.keysym.mod & KMOD_CTRL)) {
          _output->scroll(true, false);
        } else if (!isEditing() && ev.key.keysym.sym == SDLK_DOWN &&
                   (ev.key.keysym.mod & KMOD_CTRL)) {
          _output->scroll(false, false);
        } else if (ev.key.keysym.sym == SDLK_p && (ev.key.keysym.mod & KMOD_CTRL)) {
          ::screen_dump();
        } else {
          int lenMap = sizeof(keymap) / sizeof(keymap[0]);
          for (int i = 0; i < lenMap; i++) {
            if (ev.key.keysym.sym == keymap[i][0]) {
              maEvent = new MAEvent();
              maEvent->type = EVENT_TYPE_KEY_PRESSED;
              maEvent->key = keymap[i][1];
              maEvent->nativeKey = ev.key.keysym.mod;
              break;
            }
          }
          if (maEvent == NULL &&
              ((ev.key.keysym.sym >= SDLK_KP_1 && ev.key.keysym.sym <= SDLK_KP_9) ||
               ((ev.key.keysym.mod & KMOD_CTRL) &&
                ev.key.keysym.sym != SDLK_LSHIFT &&
                ev.key.keysym.sym != SDLK_RSHIFT &&
                ev.key.keysym.sym != SDLK_LCTRL &&
                ev.key.keysym.sym != SDLK_RCTRL) ||
               (ev.key.keysym.mod & KMOD_ALT))) {
            maEvent = new MAEvent();
            maEvent->type = EVENT_TYPE_KEY_PRESSED;
            maEvent->key = ev.key.keysym.sym;
            maEvent->nativeKey = ev.key.keysym.mod;
          }
        }
        break;
      case SDL_MOUSEBUTTONDOWN:
        if (ev.button.button == SDL_BUTTON_RIGHT) {
          _menuX = ev.motion.x;
          _menuY = ev.motion.y;
          showMenu();
        } else if (ev.motion.x != 0 && ev.motion.y != 0) {
          // avoid phantom down message when launching in windows
          maEvent = getMotionEvent(EVENT_TYPE_POINTER_PRESSED, &ev);
        }
        break;
      case SDL_MOUSEMOTION:
        maEvent = getMotionEvent(EVENT_TYPE_POINTER_DRAGGED, &ev);
        break;
      case SDL_MOUSEBUTTONUP:
        SDL_SetCursor(_cursorArrow);
        maEvent = getMotionEvent(EVENT_TYPE_POINTER_RELEASED, &ev);
        break;
      case SDL_WINDOWEVENT:
        switch (ev.window.event) {
        case SDL_WINDOWEVENT_FOCUS_GAINED:
          SDL_SetModState(KMOD_NONE);
          break;
        case SDL_WINDOWEVENT_RESIZED:
          onResize(ev.window.data1, ev.window.data2);
          break;
        case SDL_WINDOWEVENT_EXPOSED:
          _graphics->redraw();
          break;
        case SDL_WINDOWEVENT_LEAVE:
          _output->removeHover();
          break;
        }
        break;
      case SDL_DROPFILE:
        setLoadPath(ev.drop.file);
        setExit(false);
        SDL_free(ev.drop.file);
        break;
      case SDL_MOUSEWHEEL:
        if (!_output->scroll(ev.wheel.y == 1, false)) {
          maEvent = new MAEvent();
          maEvent->type = EVENT_TYPE_KEY_PRESSED;
          maEvent->key = ev.wheel.y == 1 ? SB_KEY_UP : SB_KEY_DN;
          maEvent->nativeKey = KMOD_CTRL;
        }
        break;
      }
      if (maEvent != NULL) {
        pushEvent(maEvent);
      }
    }
  }
}
Esempio n. 18
0
void Manifold::Portal::setMutualExits(Manifold::Portal* exit, Matrix3d rotation) {
	setExit(exit, rotation);
	exit->setExit(this, rotation.transpose());
}