Пример #1
0
void Instance::InsertMod(size_t index, const wxFileName &source)
{
	wxFileName dest(Path::Combine(GetInstModsDir().GetFullPath(), source.GetFullName()));
	if (!source.SameAs(dest))
	{
		wxCopyFile(source.GetFullPath(), dest.GetFullPath());
	}

	dest.MakeRelativeTo();
	SetNeedsRebuild();
	
	int oldIndex = Find(modList.begin(), modList.end(), [&dest] (Mod mod) -> bool
		{ return mod.GetFileName().SameAs(dest); });
	
	if (oldIndex != -1)
	{
		modList.erase(modList.begin() + oldIndex);
	}
	
	if (index >= modList.size())
		modList.push_back(Mod(dest));
	else
		modList.insert(modList.begin() + index, Mod(dest));
	
	SaveModList();
}
Пример #2
0
void Instance::LoadModList()
{
	if (GetModListFile().FileExists())
	{
		wxFileInputStream inputStream(GetModListFile().GetFullPath());
		wxStringList modListFile = ReadAllLines(inputStream);
		
		for (wxStringList::iterator iter = modListFile.begin(); iter != modListFile.end(); iter++)
		{
			// Normalize the path to the instMods dir.
			wxFileName modFile(*iter);
			modFile.Normalize(wxPATH_NORM_ALL, GetInstModsDir().GetFullPath());
			modFile.MakeRelativeTo();
			
			if (!Any(modList.begin(), modList.end(), [&modFile] (Mod mod) -> bool
				{ return mod.GetFileName().SameAs(wxFileName(modFile)); }))
			{
				//SetNeedsRebuild();
				modList.push_back(Mod(modFile));
			}
		}
	}
	
	for (size_t i = 0; i < modList.size(); i++)
	{
		if (!modList[i].GetFileName().FileExists())
		{
			SetNeedsRebuild();
			modList.erase(modList.begin() + i);
			i--;
		}
	}
	
	LoadModListFromDir(GetInstModsDir());
}
Пример #3
0
void Chunk::StopBatchUpdate()
{
	if (m_chunkChangedDuringBatchUpdate)
	{
		SetNeedsRebuild(true, true);
	}
}
Пример #4
0
void Instance::DeleteMod(size_t index)
{
	Mod *mod = &modList[index];
	if (wxRemoveFile(mod->GetFileName().GetFullPath()))
	{
		SetNeedsRebuild();
		modList.erase(modList.begin() + index);
		SaveModList();
	}
	else
	{
		wxLogError(_("Failed to delete mod."));
	}
}
Пример #5
0
void Instance::LoadModListFromDir(const wxFileName& dir, bool mlMod)
{
	ModList *list;
	
	if (mlMod)
		list = &mlModList;
	else
		list = &modList;
	
	wxDir modDir(dir.GetFullPath());
	
	if (!modDir.IsOpened())
	{
		wxLogError(_("Failed to open directory: ") + dir.GetFullPath());
		return;
	}
	
	wxString currentFile;
	if (modDir.GetFirst(&currentFile))
	{
		do
		{
			currentFile = Path::Combine(modDir.GetName(), currentFile);
			if (wxFileExists(currentFile) || mlMod)
			{
				Mod mod(currentFile);
				
				if (mlMod || !Any(list->begin(), list->end(), [&currentFile] (Mod mod) -> bool
					{ return mod.GetFileName().SameAs(wxFileName(currentFile)); }))
				{
					if (!mlMod)
						SetNeedsRebuild();

					list->push_back(mod);
				}
			}
			else if (wxDirExists(currentFile))
			{
				LoadModListFromDir(wxFileName(currentFile), mlMod);
			}
		} while (modDir.GetNext(&currentFile));
	}
}
Пример #6
0
void Chunk::Setup()
{
	ChunkStorageLoader* pChunkStorage = m_pChunkManager->GetChunkStorage(m_gridX, m_gridY, m_gridZ, false);

	for (int x = 0; x < CHUNK_SIZE; x++)
	{
		for (int z = 0; z < CHUNK_SIZE; z++)
		{
			float xPosition = m_position.x + x;
			float zPosition = m_position.z + z;

			float noise = octave_noise_2d(m_pVoxSettings->m_landscapeOctaves, m_pVoxSettings->m_landscapePersistence, m_pVoxSettings->m_landscapeScale, xPosition, zPosition);
			float noiseNormalized = ((noise + 1.0f) * 0.5f);

			float mountainNoise = octave_noise_2d(m_pVoxSettings->m_mountainOctaves, m_pVoxSettings->m_mountainPersistence, m_pVoxSettings->m_mountainScale, xPosition, zPosition);
			float mountainNoiseNormalise = (mountainNoise + 1.0f) * 0.5f;
			float mountainMultiplier = m_pVoxSettings->m_mountainMultiplier * mountainNoiseNormalise;

			float noiseHeight = noiseNormalized * CHUNK_SIZE;
			noiseHeight *= mountainMultiplier;

			if (m_gridY < 0)
			{
				noiseHeight = CHUNK_SIZE;
			}

			for (int y = 0; y < CHUNK_SIZE; y++)
			{
				float yPosition = m_position.y + y;

				if (pChunkStorage != NULL && pChunkStorage->m_blockSet[x][y][z] == true)
				{
					SetColour(x, y, z, pChunkStorage->m_colour[x][y][z]);
				}
				else
				{
					if (y + (m_gridY*CHUNK_SIZE) < noiseHeight)
					{
						float colorNoise = octave_noise_3d(4.0f, 0.3f, 0.005f, xPosition, yPosition, zPosition);
						float colorNoiseNormalized = ((colorNoise + 1.0f) * 0.5f);

						float red1 = 0.65f;
						float green1 = 0.80f;
						float blue1 = 0.00f;
						float red2 = 0.00f;
						float green2 = 0.46f;
						float blue2 = 0.16f;

						if (noise < -0.5f)
						{
							red1 = 0.10f;
							green1 = 0.25f;
							blue1 = 1.00f;
							red2 = 0.10f;
							green2 = 0.25f;
							blue2 = 1.00f;
						}
						else if (noise < -0.25f)
						{
							red1 = 0.94f;
							green1 = 0.74f;
							blue1 = 0.34f;
							red2 = 0.50f;
							green2 = 0.29f;
							blue2 = 0.20f;
						}
						else if (noise < 0.5f)
						{
							red1 = 0.65f;
							green1 = 0.80f;
							blue1 = 0.00f;
							red2 = 0.00f;
							green2 = 0.46f;
							blue2 = 0.16f;
						}
						else if (noise < 1.0f)
						{
							red1 = 0.85f;
							green1 = 0.85f;
							blue1 = 0.85f;
							red2 = 0.77f;
							green2 = 0.65f;
							blue2 = 0.80f;
						}

						float alpha = 1.0f;

						float r = red1 + ((red2 - red1) * colorNoiseNormalized);
						float g = green1 + ((green2 - green1) * colorNoiseNormalized);
						float b = blue1 + ((blue2 - blue1) * colorNoiseNormalized);

						SetColour(x, y, z, r, g, b, alpha);
					}
				}
			}

			// Tree generation
			if (m_gridY >= 0) // Only above ground
			{
				// Trees
				if ((GetRandomNumber(0, 1000) >= 1000))
				{
					if (noiseNormalized >= 0.5f)
					{
						vec3 treePos = vec3(xPosition, noiseHeight, zPosition);
						m_pChunkManager->ImportQubicleBinary("media/gamedata/terrain/plains/smalltree.qb", treePos, QubicleImportDirection_Normal);
					}
				}

				// Scenery
				if ((GetRandomNumber(0, 1000) >= 995))
				{
					if (noiseNormalized >= 0.5f)
					{
						vec3 pos = vec3(xPosition, noiseHeight, zPosition);
						//m_pSceneryManager->AddSceneryObject("flower", "media/gamedata/terrain/plains/flower1.qb", pos, vec3(0.0f, 0.0f, 0.0f), QubicleImportDirection_Normal, QubicleImportDirection_Normal, 0.08f, GetRandomNumber(0, 360, 2));
					}
				}
			}
		}
	}

	// Remove the chunk storage loader since we no longer need it
	if (pChunkStorage != NULL)
	{
		m_pChunkManager->RemoveChunkStorageLoader(pChunkStorage);
	}

	m_setup = true;

	SetNeedsRebuild(true, true);
}