Exemplo n.º 1
0
/**
@todo This method does not properly create a new mesh map and should be
changed to use IFXCreateComponent.
*/
IFXAuthorMeshMap* CIFXAuthorMeshMap::Clone()
{
	U32 i;
	IFXRESULT result;
	IFXAuthorMeshMap* pClone = NULL;
	result = IFXCreateComponent(CID_IFXAuthorMeshMap, IID_IFXAuthorMeshMap, (void**)&pClone);
	if (IFXFAILURE(result))
		return NULL;

	for(i = 0; i < 6; i++)
		pClone->SetMapSize(i, GetMapSize(i));

	result = pClone->AllocateMaps();
	if (result != IFX_OK) 
	{
		pClone->Release();
		return NULL;
	}

	// copy map data.
	for(i = 0; i < 6; i++)
		memcpy(pClone->GetMap(i), GetMap(i), sizeof(U32)*GetMapSize(i));

	return pClone;
}
Exemplo n.º 2
0
/*--------------------------------------------------------------------------*
Name:           ProcessFile

Description:    Process file.

Arguments:      filename: file to process.

Returns:        None.
*---------------------------------------------------------------------------*/
void MapConverter::ProcessFile(const char *filename)
{
	// load file, set map size from height/width line
	// if map isn't too large, reformat the file content, add size and .txt to filename
	// and save the file

	LoadFile(filename);

	if (!is_loaded_)
		return;

	mapsize_ = GetMapSize();

	// catch exception in GetMapSize(), std::stoi()
	if (has_exception_)
		return;

	if (IsMapGoodSize())
	{
		ReformatMap();
		ChangeFileExt();
		SaveFile(filename_.c_str());
	}
	else
		printf("Map too large.\n");
}
Exemplo n.º 3
0
/** 
This map will be modified in place so that it performs both mappings
with a single map.
Before: inputMesh --> thisMap --> IntermediateMesh --> MapB --> resultMesh
After : inputMesh --> thisMap --> resultMesh
*/
IFXRESULT CIFXAuthorMeshMap::Concatenate(IFXAuthorMeshMap* pMapB)
{
	U32 i, j, stop, *mapA, *mapB;

	for(i = 0; i < 6; i++)
	{
		// a one to one or a many to one mapping can not have more entries on the ouput.
		IFXASSERT(pMapB->GetMapSize(i) <= GetMapSize(i));
		stop = GetMapSize(i);
		mapA = GetMap(i);
		mapB = pMapB->GetMap(i);
		for(j = 0; j<stop; j++)
		{
			if(mapA[j] != IFX_BAD_INDEX32)
				mapA[j] = mapB[ mapA[j] ];
		}
	}

	return IFX_OK;
}
Exemplo n.º 4
0
bool Map::LoadFromFile(std::string fileName)
{
	std::ifstream fs;
	fs.open(fileName.c_str(), std::ifstream::in);

	if (fs.fail())
		return false;

	int i = 0;
	while (!fs.eof())
	{
		std::string curLine;
		getline(fs, curLine);

		if (curLine == "" || curLine.find("//") != std::string::npos)
			continue;

		// Line #1
		if (i == 0) 
		{
			// The first line should be the file size.
			GetMapSize(curLine);
			InitArray(map_size_x, map_size_y);
			if (mapTiles == NULL)
			{
				std::cout << "Could not load map file: Error reading map size." << '\n';
				return false;
			}
			i++;
		}

		std::vector<std::string> parts = GetParts(curLine, ' ');

		if (parts[0] == "define")
		{
			ParseDefine(parts);
		}
		else if (parts[0] == "set")
		{
			ParseSet(parts);
		}
	}

	fs.close();

	return true;
}
Exemplo n.º 5
0
void TMaps::LoadNextMap() {
    MapStatus = MS_Loading;
    if (MapFiles.size() == 0) {
        throw UException("No maps found");
    }
    CurrentMap ++;
    if (CurrentMap >= MapFiles.size()) {
        CurrentMap = 0;
    }
    emit ClearObjects();
    emit ClearBorders();
    LoadConfig("maps/" + MapFiles[CurrentMap] + "/config.ini");
    LoadObjects("maps/" + MapFiles[CurrentMap] + "/objects.txt");
    LoadRespPoints("maps/" + MapFiles[CurrentMap] + "/points.txt");
    emit SpawnBorders(GetMapSize());
    MapStatus = MS_Ready;
    emit MapLoaded();
}
Exemplo n.º 6
0
void ManipulatorTerrain::Serialize( rapidxml::xml_document<>* doc, rapidxml::xml_node<>* XMLNode )
{
	String strWorldSize = Ogre::StringConverter::toString(GetWorldSize());
	String strTerrainSize = Ogre::StringConverter::toString(GetMapSize());

	float pixelError = ManipulatorSystem.GetScene()->GetTerrainOption()->getMaxPixelError();
	String strPixelError = Ogre::StringConverter::toString(pixelError);

	XMLNode->append_attribute(doc->allocate_attribute("worldSize", doc->allocate_string(strWorldSize.c_str())));
	XMLNode->append_attribute(doc->allocate_attribute("mapSize", doc->allocate_string(strTerrainSize.c_str())));
	XMLNode->append_attribute(doc->allocate_attribute("tuningMaxPixelError", doc->allocate_string(strPixelError.c_str())));

	//保存地形数据
	std::wstring fullPath(ManipulatorSystem.GenerateSceneFullPath());
	fullPath += L"terrain.dat";
	Ogre::DataStreamPtr stream = Ogre::Root::getSingleton().createFileStream(Utility::UnicodeToEngine(fullPath), 
		Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, true);

	Ogre::DataStreamPtr compressStream(new Ogre::DeflateStream(Utility::UnicodeToEngine(fullPath), stream));
	Ogre::StreamSerialiser ser(compressStream);

	ManipulatorSystem.GetScene()->GetTerrain()->save(ser);
}
Exemplo n.º 7
0
void Map::ResetAllToDark()
{
	for(int index=0; index<GetMapSize(); index++)
		m_cells[index].m_canBeSeen = false;
}
Exemplo n.º 8
0
void Map::ResetDiscoveredFlag()
{
	for(int index=0; index<GetMapSize(); index++)
		m_cells[index].m_discovered = false;
}
Exemplo n.º 9
0
void Map::ResetBeenSetToVisibleFlag()
{
	for(int index=0; index<GetMapSize(); index++)
		m_cells[index].m_beenSetToVisible = false;
}
Exemplo n.º 10
0
void Map::SetDebugMode(bool value)
{
	for(int index=0; index<GetMapSize(); index++)
		m_cells[index].m_debug = value;
}
Exemplo n.º 11
0
void ManipulatorTerrain::OnEdit( float dt )
{
	assert(m_curEditMode != eTerrainEditMode_None);

	//第0层不能编辑BlendMap,应该从第1层开始
	if(m_curEditMode == eTerrainEditMode_Splat && m_curEditLayer == 0)
		return;

	Ogre::Terrain* pTerrain = ManipulatorSystem.GetScene()->GetTerrain();

	const Vector3 brushPos = m_brush[m_curBrushIndex]->GetPosition();
	Vector3 tsPos;
	pTerrain->getTerrainPosition(brushPos, &tsPos);

	float brushSizeW, brushSizeH;
	m_brush[m_curBrushIndex]->GetDimension(brushSizeW, brushSizeH);
	float worldSize = GetWorldSize();
	brushSizeW /= worldSize;
	brushSizeH /= worldSize;

	int multiplier;
	Ogre::TerrainLayerBlendMap* layer = nullptr;
	if(m_curEditMode == eTerrainEditMode_Deform)
	{
		multiplier = pTerrain->getSize() - 1;
	}
	else
	{
		multiplier = pTerrain->getLayerBlendMapSize();
		layer = pTerrain->getLayerBlendMap(m_curEditLayer);
	}

	long startx = (long)((tsPos.x - brushSizeW / 2) * multiplier);
	long starty = (long)((tsPos.y - brushSizeH / 2) * multiplier);
	long endx = (long)((tsPos.x + brushSizeW / 2) * multiplier);
	long endy= (long)((tsPos.y + brushSizeH / 2) * multiplier);
	startx = max(startx, 0L);
	starty = max(starty, 0L);
	endx = min(endx, (long)multiplier);
	endy = min(endy, (long)multiplier);
	
	for (long y = starty; y <= endy; ++y)
	{
		for (long x = startx; x <= endx; ++x)
		{
			float tsXdist = (x / multiplier) - tsPos.x;
			float tsYdist = (y / multiplier)  - tsPos.y;

			if(m_curEditMode == eTerrainEditMode_Deform)
			{
				float* pData = pTerrain->getHeightData();
				pData[y*GetMapSize()+x] += 100.0f * dt;

			}
			else
			{
				float* pData = layer->getBlendPointer();
				size_t imgY = multiplier - y;
				float newValue = pData[imgY*multiplier+x] + dt;
				newValue = Ogre::Math::Clamp(newValue, 0.0f, 1.0f);
				pData[imgY*multiplier+x] = newValue;
			}
		}
	}
	
	
	if(m_curEditMode == eTerrainEditMode_Deform)
	{
		Ogre::Rect rect(startx, starty, endx, endy);
		pTerrain->dirtyRect(rect);
		pTerrain->update();
	}
	else
	{
		size_t imgStartY = multiplier - starty;
		size_t imgEndY = multiplier - endy;
		Ogre::Rect rect(startx, min(imgStartY,imgEndY), endx, max(imgStartY,imgEndY));

		layer->dirtyRect(rect);
		layer->update();
	}
}
Exemplo n.º 12
0
int main(int argc, char **argv)
{
	try
	{
		// skip program name
		argv++, argc--;

		ArgvInit(argc, (const char **)argv);
	 
		InitDebug(ArgvFind(0, "debug") >= 0);
		InitEndian();

		if (ArgvFind('?', NULL) >= 0 || ArgvFind('h', "help") >= 0)
		{
			ShowTitle();
			ShowInfo();
			exit(1);
		}

		InitFLTK();

		SetDefaults();
		SetupRandom();

		int W = 40;
		int H = 40;

		GetMapSize(&W, &H);

		PrintDebug("Map size %dx%d\n\n", W, H);

		the_world = new world_c(W, H);

		environ_build::CreateEnv();
		area_build::CreateAreas();
		island_build::CreateIslands();
		island_build::Cleanup();

  		stage_build::CreateStages();
		path_build::CreatePaths();
		room_build::CreateRooms();

		if (ArgvFind('g', "gui") >= 0)
		{
			guix_win = new Guix_MainWin(PROG_NAME);

			// run the GUI until the user quits
			while (! guix_win->want_quit)
				Fl::wait();
		}

		CreateWAD();
	}
	catch (const char * err)
	{
		DisplayError("%s", err);
	}
#if 1
	catch (assert_fail_c err)
	{
		DisplayError("Sorry, an internal error occurred:\n%s", err.GetMessage());
	}
	catch (...)
	{
		DisplayError("An unknown problem occurred (UI code)");
	}
#endif

	delete guix_win;

	TermDebug();

	return main_result;
}