예제 #1
0
파일: cutscenes.cpp 프로젝트: 86400/scummvm
void Cutscenes::showSubtitles(uint windowIndex) {
	Screen &screen = *_vm->_screen;
	Sound &sound = *_vm->_sound;

	if (sound._soundOn || _vm->shouldQuit()) {
		// Sound is on, so subtitles aren't needed
		resetSubtitles(0, 0);
	} else {
		if (timeElapsed() > 1) {
			++_subtitleSize;
			const Common::String &line = _subtitles[_subtitleLineNum];
			Common::String lineStr(line.c_str(), line.c_str() + _subtitleSize);
			_subtitleLine = Common::String::format(SUBTITLE_LINE, lineStr.c_str());

			// If displayed a full line, then move to the next line
			if (_subtitleSize == line.size()) {
				_subtitleSize = 0;
				if (++_subtitleLineNum == _subtitles.size())
					_subtitleLineNum = 0;
			}
		}

		// Draw the box sprite
		if (!_boxSprites)
			// Not already loaded, so load it
			_boxSprites = new SpriteResource("box.vga");
		_boxSprites->draw(screen, 0, Common::Point(36, 189));

		// Write the subtitle line
		screen._windows[windowIndex].writeString(_subtitleLine);
	}

	screen.update();
}
bool ClassSpaceChecker::loadMapFile(const QString & mapPath) 
{
	QFile file(mapPath);
	if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
	{
		QMessageBox::warning(this, "", tr("Proguard Map file not found."));
		ui.lineEdit_MapFile->setFocus();
		return false;
	}

	while (!file.atEnd()) 
	{
		QByteArray line = file.readLine();
		QString lineStr(line);
		lineStr = lineStr.trimmed();

		if(lineStr.lastIndexOf(':') != lineStr.length() - 1) 
			continue;

		int pos = lineStr.indexOf("->");
		if(pos < 0)
			continue;

		QString key;
		QString value;

		key = lineStr.left(pos).trimmed();
		value = lineStr.mid(pos + 2).trimmed().remove(":");

		proguardMap_VK_.insert(value, key);
	}

	return true;
}
예제 #3
0
void Optimizer::loadFileToInstructions() {
	char* line;
	size_t len = 0;
	ssize_t read;
	while ((read = getline(&line, &len, optIn)) != -1) {
		std::string lineStr(line);
		Optimizer::instructions.push_back(new ILOC(lineStr));
	}
}
예제 #4
0
void NFAGenerator::getNFA(){

	if (languageFile==NULL)
	{
		cout << "File Not Opened" << endl;
		return;
	}

	string lineStr;
	char line[1000];
	while( fgets(line,1000,languageFile) != NULL ){
		line[1000];
		string lineStr(line);
		unsigned  pos = lineStr.find("\n");
		lineStr = lineStr.substr (0,pos);
		parseLine(lineStr);
		//cout<< lineStr;
	}

	combine();
	
}
예제 #5
0
void ImgToXml::convert(QString imgName, QString xmlFile) {
    QImage img(imgName);
    int width = img.width(), height = img.height(), nowColor;
    QVector<int> imgVec(width * height);
    int i, j;
    for (i = 0; i < height; i++) {
        for (j = 0; j < width; j++) {
            nowColor = img.pixel(j, i) - 4278190080;;
            if (nowColor < mSens) {
                imgVec [width * i + j] = 1;
            }
            else {
                imgVec [width * i + j] = 0;
            }
        }
    }
    QDomDocument picture ("Image");
    QDomElement image = picture.createElement("image");
    image.setAttribute("width", width);
    image.setAttribute("height", height);
    picture.appendChild(image);
    QString lineStr(width);
    for (i = 0; i < height; i++) {
        QDomElement line = picture.createElement("line");
        line.setAttribute("number", i + 1);
        for (j = 0; j < width; j++) {
            lineStr[j] = imgVec[i * width + j] + 48;
        }
        line.setAttribute("value", lineStr);
        image.appendChild(line);
    }
    QFile savePict(xmlFile);
    savePict.open(QIODevice::WriteOnly);
    QTextStream(&savePict) << picture.toString();
    savePict.close();
}
예제 #6
0
LWRESULT Cx_ConsoleMgr::RunConsole()
{
	LWRESULT res = 0;
	std::string lineStr("");
	std::cout << std::endl;
	Cx_Interface<Ix_LogMgr> iLogMgr(CLSID_LogMgr); 
    while(1)
    {	
		std::getline(std::cin, lineStr);           		
		if(!iLogMgr.IsNull()) 
		{ 
			iLogMgr->LogSwitch(false);   //
		}
	    while(1)
	    {
	    	COMMAND_LINE commandList;
	        std::cout << "TS> ";
	        std::getline(std::cin, lineStr);           		/*¶ÁÃüÁî*/
			if(lineStr.empty() || lineStr[0] == '\r' || lineStr[0] == '\n')
				continue;

			/////////////////
			std::string::size_type pos = lineStr.find(" ");
			if(lineStr.substr(0, pos) == "l")
			{
				lineStr = mLastCommand;
	    	}
			else
			{
				mLastCommand = lineStr;
			}

			//////////////////////////////////
			res = PraseCommandLine(lineStr, commandList, " ");
	        if(res != LWDP_OK)
	    	{
				std::cout << "Command Line Error" << std::endl;
				continue;
	    	}

	        res = CallBackCommand(commandList);          /*´¦ÀíÃüÁÌøµ½ÏàÓ¦º¯Êý*/
	        if(res != LWDP_OK)
	    	{
				if(CON::CONSOLE_BREAK== res)
				{
					break;
				}
				if(CON::CONSOLE_EXIT == res)
				{
					goto GOOD_BYE;
				}
	    	}
		}

		if(!iLogMgr.IsNull()) 
		{ 
			iLogMgr->LogSwitch(true);   //
		}
    }

GOOD_BYE:
	std::cout << "Bye!" << std::endl;
	
	return LWDP_OK;
}
예제 #7
0
/* Drive during race. */
static void
drive(int index, tCarElt* car, tSituation *s)
{

    total_tics[index]++;
   	char line[UDP_MSGLEN];

#ifdef __PRINT_RACE_RESULTS__
    bestLap[index]=car->_bestLapTime;
    damages[index]=car->_dammage;
    totalTime[index]=car->_timeBehindLeader;
#endif


#ifdef __DISABLE_RESTART__
    if (RESTARTING[index]==1)
    {

        clientAddressLength[index] = sizeof(clientAddress[index]);

        // Set line to all zeroes
        memset(line, 0x0, 101);
        if (recvfrom(listenSocket[index], line, 100, 0,
                     (struct sockaddr *) &clientAddress[index],
                     &clientAddressLength[index]) < 0)
        {
            std::cerr << "Error: problem in receiving from the listen socket";
            exit(1);
        }

  #ifdef __UDP_SERVER_VERBOSE__
        // show the client's IP address
        std::cout << "  from " << inet_ntoa(clientAddress[index].sin_addr);

        // show the client's port number.
        std::cout << ":" << ntohs(clientAddress[index].sin_port) << "\n";

        // Show the line
        std::cout << "  Received: " << line << "\n";
  #endif

        // compare received string with the ID
        if (strncmp(line,UDP_ID,3)==0)
        {
  #ifdef __UDP_SERVER_VERBOSE__
            std::cout << "IDENTIFIED" << std::endl;
  #endif
//            char line[UDP_MSGLEN];
            sprintf(line,"***identified***");
            // Sending the car state to the client
            if (sendto(listenSocket[index], line, strlen(line) + 1, 0,
                       (struct sockaddr *) &clientAddress[index],
                       sizeof(clientAddress[index])) < 0)
                std::cerr << "Error: cannot send identification message";
		RESTARTING[index]=0;
        }
    }
#endif

    // local variables for UDP
    struct timeval timeVal;
    fd_set readSet;

    // computing distance to middle
    float dist_to_middle = 2*car->_trkPos.toMiddle/(car->_trkPos.seg->width);
    // computing the car angle wrt the track axis
    float angle =  RtTrackSideTgAngleL(&(car->_trkPos)) - car->_yaw;
    NORM_PI_PI(angle); // normalize the angle between -PI and + PI

	//Update focus sensors' angle
	for (int i = 0; i < 5; ++i) {
		focusSens[index]->setSensor(i,(car->_focusCmd)+i-2,200);
	}

    // update the value of track sensors only as long as the car is inside the track
    float trackSensorOut[19];
	float focusSensorOut[5];//ML
    if (dist_to_middle<=1.0 && dist_to_middle >=-1.0 )
    {
        trackSens[index]->sensors_update();
		for (int i = 0; i < 19; ++i)
        {
            trackSensorOut[i] = trackSens[index]->getSensorOut(i);
            if (getNoisy())
            	trackSensorOut[i] *= normRand(1,__NOISE_STD__);
        }
		focusSens[index]->sensors_update();//ML
		if ((car->_focusCD <= car->_curLapTime + car->_curTime)//ML Only send focus sensor reading if cooldown is over
			&& (car->_focusCmd != 360))//ML Only send focus reading if requested by client
		{//ML
			for (int i = 0; i < 5; ++i)
			{
				focusSensorOut[i] = focusSens[index]->getSensorOut(i);
				if (getNoisy())
					focusSensorOut[i] *= normRand(1,__FOCUS_NOISE_STD__);
			}
			car->_focusCD = car->_curLapTime + car->_curTime + 1.0;//ML Add cooldown [seconds]
		}//ML
		else//ML
		{//ML
			for (int i = 0; i < 5; ++i)//ML
			    focusSensorOut[i] = -1;//ML During cooldown send invalid focus reading
		}//ML
    }
    else
    {
        for (int i = 0; i < 19; ++i)
        {
            trackSensorOut[i] = -1;
        }
		for (int i = 0; i < 5; ++i)
		{
			focusSensorOut[i] = -1;
		}
    }

    // update the value of opponent sensors
    float oppSensorOut[36];
    oppSens[index]->sensors_update(s);
    for (int i = 0; i < 36; ++i)
    {
        oppSensorOut[i] = oppSens[index]->getObstacleSensorOut(i);
        if (getNoisy())
        	oppSensorOut[i] *= normRand(1,__OPP_NOISE_STD__);
    }

    float wheelSpinVel[4];
    for (int i=0; i<4; ++i)
    {
        wheelSpinVel[i] = car->_wheelSpinVel(i);
    }

    if (prevDist[index]<0)
    {
	prevDist[index] = car->race.distFromStartLine;
    }
    float curDistRaced = car->race.distFromStartLine - prevDist[index];
    prevDist[index] = car->race.distFromStartLine;
    if (curDistRaced>100)
    {
	curDistRaced -= curTrack->length;
    }
    if (curDistRaced<-100)
    {
	curDistRaced += curTrack->length;
    }

    distRaced[index] += curDistRaced;





    float totdist = curTrack->length * (car->race.laps -1) + car->race.distFromStartLine;

//    std::cerr << "totraced: " << totdist << std::endl;

    /**********************************************************************
     ****************** Building state string *****************************
     **********************************************************************/

    string stateString;

    stateString =  SimpleParser::stringify("angle", angle);
    stateString += SimpleParser::stringify("curLapTime", float(car->_curLapTime));
    stateString += SimpleParser::stringify("damage",        ( getDamageLimit() ? car->_dammage : car->_fakeDammage ) );
    stateString += SimpleParser::stringify("distFromStart", car->race.distFromStartLine);
    stateString += SimpleParser::stringify("totalDistFromStart", totdist);
    stateString += SimpleParser::stringify("distRaced", distRaced[index]);
    stateString += SimpleParser::stringify("fuel", car->_fuel);
    stateString += SimpleParser::stringify("gear", car->_gear);
    stateString += SimpleParser::stringify("lastLapTime", float(car->_lastLapTime));
    stateString += SimpleParser::stringify("opponents", oppSensorOut, 36);
    stateString += SimpleParser::stringify("racePos", car->race.pos);
    stateString += SimpleParser::stringify("rpm", car->_enginerpm*10);
    stateString += SimpleParser::stringify("speedX", float(car->_speed_x  * 3.6));
    stateString += SimpleParser::stringify("speedY", float(car->_speed_y  * 3.6));
    stateString += SimpleParser::stringify("speedZ", float(car->_speed_z  * 3.6));
    stateString += SimpleParser::stringify("track", trackSensorOut, 19);
    stateString += SimpleParser::stringify("trackPos", dist_to_middle);
    stateString += SimpleParser::stringify("wheelSpinVel", wheelSpinVel, 4);
    stateString += SimpleParser::stringify("z", car->_pos_Z  - RtTrackHeightL(&(car->_trkPos)));
    stateString += SimpleParser::stringify("focus", focusSensorOut, 5);//ML

    //GIUSE - VISION HERE!
//    printf("size: %d\n",car->vision->imgsize);

    if( getVision() ){
//      std::cout << car->vision->imgsize << std::endl;
      stateString += SimpleParser::stringify("img", car->vision->img, car->vision->imgsize);
    }

//    for(int i=0; i < car->vision->imgsize; i++){
//      std::cout << (int)car->vision->img[i] << " ";
//    }

  // GIUSE - that's UGLY, can we stay coherent with either char* or string??
//    char line[UDP_MSGLEN];
//    memset(line, 0x0,UDP_MSGLEN ); //
//    sprintf(line,"%s",stateString.c_str());

if (RESTARTING[index]==0)
{
#ifdef __UDP_SERVER_VERBOSE__

    std::cout << "Sending: " << stateString.c_str() << std::endl;
    std::cout << "Sending: " << stateString.c_str() << std::endl;

#endif

#ifdef __STEP_LIMIT__

    if (total_tics[index]>__STEP_LIMIT__)
    {
	RESTARTING[index] = 1;
	car->RESTART=1;

	char fileName[200];
	sprintf(fileName,"%s.txt",trackName);
	printf("%s.txt\n",trackName);
	FILE *f = fopen (fileName,"a");

	printf("Dist_raced %lf\n",distRaced[index]);
	fprintf(f,"Dist_raced %lf\n",distRaced[index]);

	fclose(f);
	return;
    }
#endif


    // Sending the car state to the client
//    if (sendto(listenSocket[index], line, strlen(line) + 1, 0,
    if (sendto(listenSocket[index], stateString.c_str(), stateString.length() + 1, 0,
               (struct sockaddr *) &clientAddress[index],
               sizeof(clientAddress[index])) < 0)
        std::cerr << "Error: cannot send car state";


    // Set timeout for client answer
    FD_ZERO(&readSet);
    FD_SET(listenSocket[index], &readSet);
    timeVal.tv_sec = 0;
    timeVal.tv_usec = UDP_TIMEOUT;
    memset(line, 0x0,UDP_MSGLEN ); // GIUSE - BUG, THERE WAS A 1000 HARDCODED

    if (select(listenSocket[index]+1, &readSet, NULL, NULL, &timeVal))
    {
        // Read the client controller action
//        memset(line, 0x0,UDP_MSGLEN );  // Zero out the buffer. GIUSE - already done
        int numRead = recv(listenSocket[index], line, UDP_MSGLEN, 0);
        if (numRead < 0)
        {
            std::cerr << "Error, cannot get any response from the client!";
			CLOSE(listenSocket[index]);
            exit(1);
        }

#ifdef __UDP_SERVER_VERBOSE__
        std::cout << "Received: " << line << std::endl;
#endif

        std::string lineStr(line);
        CarControl carCtrl(lineStr);
        if (carCtrl.getMeta()==RACE_RESTART)
        {
         	RESTARTING[index] = 1;
#ifdef __DISABLE_RESTART__
//	        char line[UDP_MSGLEN];
          memset(line, 0x0,UDP_MSGLEN );
        	sprintf(line,"***restart***");
        	// Sending the car state to the client
        	if (sendto(listenSocket[index], line, strlen(line) + 1, 0,
                	   (struct sockaddr *) &clientAddress[index],
                   	sizeof(clientAddress[index])) < 0)
            	std::cerr << "Error: cannot send restart message";
#else
        car->RESTART=1;
#endif
        }

        // Set controls command and store them in variables
        oldAccel[index] = car->_accelCmd = carCtrl.getAccel();
        oldBrake[index] = car->_brakeCmd = carCtrl.getBrake();
        oldGear[index]  = car->_gearCmd  = carCtrl.getGear();
        oldSteer[index] = car->_steerCmd = carCtrl.getSteer();
        oldClutch[index] = car->_clutchCmd = carCtrl.getClutch();

		oldFocus[index] = car->_focusCmd = carCtrl.getFocus();//ML
    }
    else
    {
//#ifdef __UDP_SERVER_VERBOSE__
        std::cout << "Timeout for client answer\n";
//#endif

        // If no new controls are availables uses old ones...
        car->_accelCmd = oldAccel[index];
        car->_brakeCmd = oldBrake[index];
        car->_gearCmd  = oldGear[index];
        car->_steerCmd = oldSteer[index];
        car->_clutchCmd = oldClutch[index];

		car->_focusCmd = oldFocus[index];//ML
    }
}
else
{
        car->_accelCmd = oldAccel[index];
        car->_brakeCmd = oldBrake[index];
        car->_gearCmd  = oldGear[index];
        car->_steerCmd = oldSteer[index];
        car->_clutchCmd = oldClutch[index];

		car->_focusCmd = oldFocus[index];//ML
}
}
String JavaVMSingleton::computeClassPath(const zorba::StaticContext* aStaticContext)
{
  String cp;

  // get classpath from global Properties
  PropertiesGlobal * properties = Zorba::getInstance(NULL)->getPropertiesGlobal();
  std::string globalClassPath;
  properties->getJVMClassPath(globalClassPath);
  cp += globalClassPath;

  std::vector<String> lCPV;
  aStaticContext->getFullLibPath(lCPV);

  for (std::vector<String>::iterator lIter = lCPV.begin();
       lIter != lCPV.end(); ++lIter)
  {
    // verify it contains a jars dir
    String jarsDir( *lIter );
    fs::append( jarsDir, "jars" );

    if ( fs::get_type( jarsDir ) == fs::directory )
    {
      fs::iterator itemIter( jarsDir );

      while ( itemIter.next() )
      {
        String itemFile( jarsDir );
        fs::append( itemFile, itemIter->name );
        if ( fs::get_type( itemFile ) == fs::file )
        {
          std::string suffix = "-classpath.txt";
          size_t found;
          found = itemFile.rfind(suffix);
          if (found!=std::string::npos &&
              found + suffix.length() == itemFile.length() )
          {
            std::auto_ptr<std::istream> pathFile;
            pathFile.reset(new std::ifstream (itemFile.c_str ()));
            if (!pathFile->good() || pathFile->eof() )
            {
              std::cerr << "file {" << itemFile << "} not found or not readable." << std::endl;
              throw itemFile;
            }

            // read file
            char line[1024];
            while( !pathFile->eof() && !pathFile->bad() && !pathFile->fail())
            {
              pathFile->getline(line, sizeof(line));
              std::string lineStr(line);

              if ( lineStr.size() > 0 ) {
                cp += fs::path_separator;
                cp += fs::normalize_path( lineStr, jarsDir );
              }
            }
          }
        }
      }
    }
  }

  properties->setJVMClassPath(cp.str());

  return cp;
}