Exemple #1
0
int CLevel::addNewNpc(CString& pImage, CString& pCodeFile, float pX, float pY)
{
	CStringList codeData;
	CString code;
	char* dataFile = getDataFile(pCodeFile.text());
	if(!strlen(dataFile))
		return 0;
	if(!codeData.load(dataFile))
		return 0;
	for(int i = 0; i < codeData.count(); i++)
		code << codeData[i] << "\xa7";

	// Create the new NPC.  Do this before parsing the join commands.
	// The CNpc constructor will remove all comments.
	CString code2;
	CNpc* npc = new CNpc( pImage, code, pX, pY, this, false );

	// Now filter out the join commands.
	CStringList npcData;
	npcData.load( npc->clientCode.text(), "\xa7" );
	for ( int j = 0; j < npcData.count(); ++j )
		code2 << processNpcLine( npcData[j] ) << "\xa7";
	npc->clientCode = code2;

	// Now, add all the joined files to the code.
	if ( joinList.count() > 0 )
	{
		CString* file = 0;
		while ( (file = (CString*)joinList[0]) != 0 )
		{
			// Load the source file into memory.
			CString dataFile = getDataFile(file->text());
			if(dataFile.length())
			{
				// Append to the end of the script.
				CString retVal;
				retVal.load(dataFile.text());
				retVal.replaceAll("\r\n", "\xa7");
				retVal.replaceAll("\n", "\xa7");
				npc->clientCode << retVal << "\xa7";
			}
			delete (CString*)joinList[0];
			joinList.remove(0);
		}
	}
	joinList.clear();
	npcs.add(npc);

	for(int i = 0; i < players.count(); i++)
	{
		CPlayer* player = (CPlayer*)players[i];
		player->sendPacket(CPacket() << (char)SNPCPROPS << (int)npc->id <<
			npc->getPropertyList(0));
	}

	return npc->id;
}
Exemple #2
0
	TEST(FilterSobel, single) {

		K::ImageChannel img = K::ImageFactory::readPNG(getDataFile("lens_1.png"));

		K::ImageChannel out = K::CV::Sobel::apply(img);

		K::ImageFactory::writePNG("/tmp/sobel.png", out);


	}
Exemple #3
0
		Garden() {

			fileLeft = getDataFile("stereo1.jpg");		// left image
			fileRight = getDataFile("stereo2.jpg");		// right image
			imgLeft = ImageFactory::readJPEG(fileLeft);
			imgRight = ImageFactory::readJPEG(fileRight);

			MatchingSAD sad(imgLeft, imgRight, 15);
			Matching matcher;

			// image1				// image2 (left of image1)	// refine the approximate matching positions
			Point2i pl1(85,53);		Point2i pr1(29,57);			pr1 = matcher.refine(sad, pl1, pr1);
			Point2i pl2(264,34);	Point2i pr2(209,36);		pr2 = matcher.refine(sad, pl2, pr2);
			Point2i pl3(362,32);	Point2i pr3(306,32);		pr3 = matcher.refine(sad, pl3, pr3);

			Point2i pl4(213,155);	Point2i pr4(155,159);		pr4 = matcher.refine(sad, pl4, pr4);

			Point2i pl5(96,209);	Point2i pr5(36,210);		pr5 = matcher.refine(sad, pl5, pr5);
			Point2i pl6(330,212);	Point2i pr6(269,211);		pr6 = matcher.refine(sad, pl6, pr6);
			Point2i pl7(276,241);	Point2i pr7(216,242);		pr7 = matcher.refine(sad, pl7, pr7);

			Point2i pl8(385,332);	Point2i pr8(321,328);		pr8 = matcher.refine(sad, pl8, pr8);
			Point2i pl9(180,389);	Point2i pr9(114,388);		pr9 = matcher.refine(sad, pl9, pr9);
			Point2i pl10(136,500);	Point2i pr10(67,500);		pr10 = matcher.refine(sad, pl10, pr10);

			fm.addCorrespondence(pl1,	pr1);
			fm.addCorrespondence(pl2,	pr2);
			fm.addCorrespondence(pl3,	pr3);

			fm.addCorrespondence(pl4,	pr4);

			fm.addCorrespondence(pl5,	pr5);
			fm.addCorrespondence(pl6,	pr6);
			fm.addCorrespondence(pl7,	pr7);
			fm.addCorrespondence(pl8,	pr8);
//			fm.addCorrespondence(pl9,	pr9);
//			fm.addCorrespondence(pl10,	pr10);

			fm.estimate();

		}
Exemple #4
0
void CLevel::loadNpcs(CPacket& levelData)
{
	while(levelData.bytesLeft())
	{
		CPacket line;
		line << levelData.readLine();
		if(line.length() < 1 || line == "#")
			break;

		float x = line.readByte1();
		float y = line.readByte1();
		CString image = line.readString("#");
		CString code = line.readChars(line.bytesLeft());

		// Create the new NPC.  Do this before parsing the join commands.
		// The CNpc constructor will remove all comments.
		CString code2;
		CNpc* jnpc = new CNpc( image, code, x, y, this, true );

		// Now filter out the join commands.
		CStringList npcData;
		npcData.load( jnpc->clientCode.text(), "\xa7" );
		for ( int j = 0; j < npcData.count(); ++j )
			code2 << processNpcLine( npcData[j] ) << "\xa7";
		jnpc->clientCode = code2;

		// Now, add all the joined files to the code.
		if ( joinList.count() > 0 )
		{
			CString* file = 0;
			while ( (file = (CString*)joinList[0]) != 0 )
			{
				// Load the source file into memory.
				CString dataFile = getDataFile(file->text());
				if(dataFile.length())
				{
					// Append to the end of the script.
					CString retVal;
					retVal.load(dataFile.text());
					retVal.replaceAll("\r\n", "\xa7");
					retVal.replaceAll("\n", "\xa7");
					jnpc->clientCode << retVal << "\xa7";
				}
				delete (CString*)joinList[0];
				joinList.remove(0);
			}
		}
		joinList.clear();
		npcs.add( jnpc );
	}
}
Exemple #5
0
bool CLevel::loadGraal(CString& pFileName)
{
	CPacket levelData;
	CString version;
	char* dataFile = getDataFile(pFileName.text());
	if(!strlen(dataFile))
		return false;
	if(!levelData.load(dataFile))
		return false;
	fileName = pFileName;
	modTime = getFileModTime(dataFile);
	version = levelData.readChars(8);

	bool v0 = (version == "GR-V1.00");
	bool v1 = (version == "GR-V1.01");
	bool v2 = (version == "GR-V1.02");
	bool v3 = (version == "GR-V1.03");
	//printf("Loading map %s\n", pFileName.text());
	//printf("Loading tiles..\n");
	loadTiles(levelData, version);
	//printf("Loading links..\n");
	loadLinks(levelData);
	//printf("Loading baddies..\n");
	loadBaddies(levelData);
	if (v0 || v1 || v2 || v3)
	{
		//printf("Loading npcs..\n");
		loadNpcs(levelData);
	}
	if (v1 || v2 || v3)
	{
		//printf("Loading chests..\n");
		loadChests(levelData);
	}
	//printf("Loading signs..\n");
	loadSigns(levelData);

	//Find our map id
	for(int i = 0; i < CMap::mapList.count(); i++)
	{
		CMap* m = (CMap*)CMap::mapList[i];
		if((levelIndex = m->getLevelpos(pFileName)) >= 0)
		{
			map = m;
			break;
		}
	}

	return true;
}
Exemple #6
0
bool CLevel::loadZelda(CString& pFileName)
{
	CPacket levelData;
	CString version;
	char* dataFile = getDataFile(pFileName.text());
	if(!strlen(dataFile))
		return false;
	if(!levelData.load(dataFile))
		return false;
	fileName = pFileName;
	modTime = getFileModTime(dataFile);
	version = levelData.readChars(8);

	// Some clients will actually save .zelda levels as .graal.
	// If this is the case, parse it through the .graal loader.
	if (version.copy(0, 2) == "GR")
		return loadGraal(pFileName);

	bool v0 = (version == "unknown");
	bool v1 = (version == "unknown");
	bool v2 = (version == "unknown");
	bool v3 = (version == "Z3-V1.03");
	bool v4 = (version == "Z3-V1.04");

	// If we encountered an unknown version, ask the user to send it in so we can add support for it.
	if (!v3 && !v4)
	{
		errorOut("errorlog.txt", CString() << "Level " << fileName << " is of version " << version << ".  That version is unknown.  Please send us the level so we may add support for it.", true);
		return false;
	}

	loadTiles(levelData, version);
	loadLinks(levelData);
	loadBaddies(levelData);
	loadSigns(levelData);

	//Find our map id
	for(int i = 0; i < CMap::mapList.count(); i++)
	{
		CMap* m = (CMap*)CMap::mapList[i];
		if((levelIndex = m->getLevelpos(pFileName)) >= 0)
		{
			map = m;
			break;
		}
	}

	return true;
}
Exemple #7
0
void CLevel::loadLinks(CPacket& levelData)
{
	while(levelData.bytesLeft())
	{
		CBuffer line = levelData.readLine();
		if(line.length() <= 0 || line == "#")
			break;

		CString nextMap = line.readString(" ");
		if(!strlen(getDataFile(nextMap.text())))
			continue;
		int x = atoi(line.readString(" "));
		int y = atoi(line.readString(" "));
		int width = atoi(line.readString(" "));
		int height = atoi(line.readString(" "));
		CString warpX = line.readString(" ");
		CString warpY = line.readString(" ");
		links.add(new CLink(nextMap, x, y, width, height, warpX, warpY));
	}
}
Exemple #8
0
// This function is the main function to set up the structure from file
// The parameter is the path of the file
// The function a pointer to the new structure
FileContent* pushFileToStruct(char *filePath) {
	// Checking if the file path is empty, if null the program will be close by exit function
	if (filePath == NULL)
		exit(EXIT_FAILURE);

	FILE* file = NULL;

	file = fopen(filePath, "r");

	// Checking if the file is open, if the opening has failed we close the program
	if (file == NULL)
		exit(EXIT_FAILURE);

	FileContent* elem = NULL;
	int nbLine = 0, i = 0;

	elem = malloc(sizeof(FileContent));

	// Getting file info
	elem->fileInfo = getDataFile(filePath);

	// Transform Latest Modification Time to string
	elem->modifiedTime = getFTime(elem->fileInfo->st_mtime);

	// Getting line number from the file
	nbLine = getLineNumber(file);

	// Here, all the line of the file are put in char tab, one char tab for one line
	// The char** of the struct point to all the char tab (i.e the line)
	elem->elem = malloc(nbLine * sizeof(char*));
	for (i = 0; i < nbLine; i++)
	{
		elem->elem[i] = getLine(file);
	}
	elem->path = malloc((strlen(filePath) + 1)*sizeof(char));
	strcpy(elem->path, filePath);
	elem->nbLine = nbLine;
	fclose(file);

	return elem;
}
Exemple #9
0
  void CubeTileHandler::writeRaw(const RawCubeChunk &chunkToWrite) {
    BigInt startByte = getTileStartByte(chunkToWrite);
    bool success = false;

    QFile * dataFile = getDataFile();
    if(dataFile->seek(startByte)) {
      BigInt dataWritten = dataFile->write(chunkToWrite.getRawData());

      if(dataWritten == chunkToWrite.getByteCount()) {
        success = true;
      }
    }

    if(!success) {
      IString msg = "Writing to the file [" + dataFile->fileName() + "] "
          "failed with writing [" +
          QString::number(chunkToWrite.getByteCount()) +
          "] bytes at position [" + QString::number(startByte) + "]";
      throw IException(IException::Io, msg, _FILEINFO_);
    }
  }
Exemple #10
0
bool CLevel::loadGraal(CString& pFileName)
{
	CPacket levelData;
	CString version;
	char* dataFile = getDataFile(pFileName.text());
	if(!strlen(dataFile))
		return false;
	if(!levelData.load(dataFile))
		return false;
	fileName = pFileName;
	modTime = getFileModTime(dataFile);
	version = levelData.readChars(8);

	bool v0 = (version == "GR-V1.00");
	bool v1 = (version == "GR-V1.01");
	bool v2 = (version == "GR-V1.02");
	bool v3 = (version == "GR-V1.03");
	//printf("Loading map %s\n", pFileName.text());
	//printf("Loading tiles..\n");
	loadTiles(levelData, version);
	//printf("Loading links..\n");
	loadLinks(levelData);
	//printf("Loading baddies..\n");
	loadBaddies(levelData);
	if (v0 || v1 || v2 || v3)
	{
		//printf("Loading npcs..\n");
		loadNpcs(levelData);
	}
	if (v1 || v2 || v3)
	{
		//printf("Loading chests..\n");
		loadChests(levelData);
	}
	//printf("Loading signs..\n");
	loadSigns(levelData);
	return true;
}
Exemple #11
0
  void CubeTileHandler::readRaw(RawCubeChunk &chunkToFill) {
    BigInt startByte = getTileStartByte(chunkToFill);

    bool success = false;

    QFile * dataFile = getDataFile();
    if(dataFile->seek(startByte)) {
      QByteArray binaryData = dataFile->read(chunkToFill.getByteCount());

      if(binaryData.size() == chunkToFill.getByteCount()) {
        chunkToFill.setRawData(binaryData);
        success = true;
      }
    }

    if(!success) {
      IString msg = "Reading from the file [" + dataFile->fileName() + "] "
          "failed with reading [" +
          QString::number(chunkToFill.getByteCount()) +
          "] bytes at position [" + QString::number(startByte) + "]";
      throw IException(IException::Io, msg, _FILEINFO_);
    }
  }
Exemple #12
0
bool CLevel::loadNW(CString& pFileName)
{
	CStringList levelData;
	CString version;
	char* dataFile = getDataFile(pFileName.text());
	if(!strlen(dataFile))
		return false;

	if(!levelData.load(dataFile))
		return false;

	if(levelData.count() < 1)
		return false;

	version = levelData[0];
	modTime = getFileModTime(dataFile);
	fileName = pFileName;
	if(version == "GLEVNW01" || version == "GSERVL01")
	{
		for(int i = 1; i < levelData.count(); i ++)
		{
			CStringList words;
			words.load(levelData[i].text(), " ");
			if(words.count() <= 0)
				continue;
			if(words[0] == "BOARD")
			{
				if(words.count() <= 5)
					continue;

				int x = atoi(words[1].text());
				int y = atoi(words[2].text());
				int w = atoi(words[3].text());
				CString& data = words[5];
				if(x >= 0 && x <= 64 && y >= 0 && y <= 64 && w > 0 && x + w <= 64)
				{
					if(data.length() >= w*2)
					{
						for(int ii = x; ii < x + w; ii++)
						{
							char left = data.readChar();
							char top = data.readChar();
							short tile = base64.find(left) << 6;
							tile += base64.find(top);
							tiles[ii + y*64] = tile;
						}
					}
				}
			} else if(words[0] == "LINK")
			{
				if(words.count() <= 7)
					continue;
				if(strlen(getDataFile(words[1].text())))
				{
					links.add(new CLink(words[1], atoi(words[2].text()), atoi(words[3].text()),
						atoi(words[4].text()), atoi(words[5].text()), words[6], words[7]));
				}
			} else if(words[0] == "CHEST")
			{
				if(words.count() <= 4)
					continue;
				for(int ii = 0; ii < itemcount; ii++)
				{
					if(words[3] == itemNames[ii])
					{
						chests.add(new CChest(atoi(words[1].text()), atoi(words[2].text()),
							atoi(words[4].text()), ii));
						break;
					}
				}

			} else if(words[0] == "NPC")
			{
				if(words.count() <= 3)
					continue;
				CString image, code, code2;
				float x, y;
				if(words[1] != "-")
					image = words[1];

				x = (float)atof(words[2].text());
				y = (float)atof(words[3].text());
				for(i++; i < levelData.count() && levelData[i] != "NPCEND"; i++)
					code << levelData[i] << "\xa7";

				// Create the new NPC.  Do this before parsing the join commands.
				// The CNpc constructor will remove all comments.
				CNpc* jnpc = new CNpc( image, code, x, y, this, true );

				// Now filter out the join commands.
				CStringList npcData;
				npcData.load( jnpc->clientCode.text(), "\xa7" );
				for ( int j = 0; j < npcData.count(); ++j )
					code2 << processNpcLine( npcData[j] ) << "\xa7";
				jnpc->clientCode = code2;

				// Now, add all the joined files to the code.
				if ( joinList.count() > 0 )
				{
					CString* file = 0;
					while ( (file = (CString*)joinList[0]) != 0 )
					{
						// Load the source file into memory.
						CString dataFile = getDataFile(file->text());
						if(dataFile.length())
						{
							// Append to the end of the script.
							CString retVal;
							retVal.load(dataFile.text());
							retVal.replaceAll("\r\n", "\xa7");
							retVal.replaceAll("\n", "\xa7");
							jnpc->clientCode << retVal << "\xa7";
						}
						delete (CString*)joinList[0];
						joinList.remove(0);
					}
				}
				joinList.clear();

				npcs.add( jnpc );
			} else if(words[0] == "BADDY")
			{
				if(words.count() <= 3)
					continue;
				int x = atoi(words[1].text());
				int y = atoi(words[2].text());
				int type = atoi(words[3].text());

				CBaddy* baddy = new CBaddy(x, y, type);
				int baddyId = createBaddyId(baddy);
				baddy->id = baddyId;
				for(i++; i < levelData.count() && levelData[i] != "BADDYEND"; i++)
					baddy->verses.add(levelData[i].text());
				if(baddies.count() < 50)
					baddies.add(baddy);
				else delete baddy;
			} else if(words[0] == "SIGN")
			{
				if(words.count() <= 2)
					continue;

				CString sign;
				int x = atoi(words[1].text());
				int y = atoi(words[2].text());
				sign.writeChar(x+32);
				sign.writeChar(y+32);

				for (i++; i < levelData.count() && levelData[i] != "SIGNEND"; i++)
					sign << getSignCode(CString() << levelData[i] << "\n");
				signs.add(sign);
			} else if(words[0] == "REPLACENPC")
			{
				int npcId = atoi(words[1].text());
				CNpc* npc = (CNpc*)npcs[npcId];
				if(npc == NULL)
					continue;

				for(i++; i < levelData.count() && levelData[i] != "REPLACENPCEND"; i++)
					npc->setProps((CPacket&)levelData[i]);
			}
		}
	} else return false;

	return true;
}