Beispiel #1
0
void SceneSaver::SaveScene(Scene *scene, const FilePath &fileName, Set<String> &errorLog)
{
    DVASSERT(0 == texturesForSave.size())
    
    String relativeFilename = fileName.GetRelativePathname(sceneUtils.dataSourceFolder);
    sceneUtils.workingFolder = fileName.GetDirectory().GetRelativePathname(sceneUtils.dataSourceFolder);
    
    FileSystem::Instance()->CreateDirectory(sceneUtils.dataFolder + sceneUtils.workingFolder, true);

    scene->Update(0.1f);

    FilePath oldPath = SceneValidator::Instance()->SetPathForChecking(sceneUtils.dataSourceFolder);
    SceneValidator::Instance()->ValidateScene(scene, errorLog);

    texturesForSave.clear();
    SceneDataManager::EnumerateTextures(scene, texturesForSave);

    CopyTextures(scene, errorLog);
	ReleaseTextures();

	Landscape *landscape = EditorScene::GetLandscape(scene);
    if (landscape)
    {
        sceneUtils.CopyFile(landscape->GetHeightmapPathname(), errorLog);
    }

	CopyReferencedObject(scene, errorLog);
	CopyEffects(scene, errorLog);
	CopyCustomColorTexture(scene, fileName.GetDirectory(), errorLog);

    //save scene to new place
    FilePath tempSceneName = sceneUtils.dataSourceFolder + relativeFilename;
    tempSceneName.ReplaceExtension(".saved.sc2");
    
    SceneFileV2 * outFile = new SceneFileV2();
    outFile->EnableSaveForGame(true);
    outFile->EnableDebugLog(false);
    
    outFile->SaveScene(tempSceneName, scene);
    SafeRelease(outFile);

    bool moved = FileSystem::Instance()->MoveFile(tempSceneName, sceneUtils.dataFolder + relativeFilename, true);
	if(!moved)
	{
		errorLog.insert(Format("Can't move file %s", fileName.GetAbsolutePathname().c_str()));
	}
    
    SceneValidator::Instance()->SetPathForChecking(oldPath);
}
AddSwitchEntityDialog::AddSwitchEntityDialog( QWidget* parent)
		:BaseAddEntityDialog(parent, QDialogButtonBox::Ok | QDialogButtonBox::Cancel)
{
	setAcceptDrops(true);
	setAttribute( Qt::WA_DeleteOnClose, true );
	FilePath defaultPath(ProjectManager::Instance()->CurProjectDataSourcePath());
	
	SceneEditor2 *scene = QtMainWindow::Instance()->GetCurrentScene();
	if(scene)
	{
		FilePath scenePath = scene->GetScenePath();
		if(scenePath.Exists())
		{
			defaultPath = scenePath.GetDirectory();
		}
	}
	
	SelectEntityPathWidget* firstWidget = new SelectEntityPathWidget(parent, defaultPath.GetAbsolutePathname(),"");
	SelectEntityPathWidget* secondWidget = new SelectEntityPathWidget(parent, defaultPath.GetAbsolutePathname(),"");
	SelectEntityPathWidget* thirdWidget = new SelectEntityPathWidget(parent, defaultPath.GetAbsolutePathname(),"");

	AddControlToUserContainer(firstWidget, "First Entity:");
	AddControlToUserContainer(secondWidget, "Second Entity:");
	AddControlToUserContainer(thirdWidget, "Third Entity:");

	pathWidgets.push_back(firstWidget);
	pathWidgets.push_back(secondWidget);
	pathWidgets.push_back(thirdWidget);

	propEditor->setVisible(false);
	propEditor->setMinimumHeight(0);
	propEditor->setMaximumSize(propEditor->maximumWidth(), 0);
}
void CubeMapTextureBrowser::OnCreateCubemapClicked()
{
	QString fileName = QtFileDialog::getSaveFileName(this,
													tr("Create Cubemap Texture"),
													ui->textRootPath->text(),
													tr("Tex File (*.tex)"));
	
	if(!fileName.isNull())
	{
		CubemapEditorDialog dlg(this);
		FilePath fp = fileName.toStdString();
		
		DAVA::FilePath rootPath = fp.GetDirectory();
		dlg.InitForCreating(fp, rootPath);
		dlg.exec();
		
		QString path = rootPath.GetAbsolutePathname().c_str();
		ui->textRootPath->setText(path);
		int currentRow = ui->listTextures->currentRow();
		ReloadTexturesFromUI(path);
		
		if(ui->listTextures->count() > 0 &&
		   currentRow < ui->listTextures->count())
		{
			RestoreListSelection(currentRow);
		}
	}	
}
Beispiel #4
0
bool Shader::LoadFromYaml(const FilePath & pathname)
{
//#if defined(__DAVAENGINE_ANDROID__) || defined (__DAVAENGINE_MACOS__)
//    relativeFileName = pathname;
//#endif //#if defined(__DAVAENGINE_ANDROID__) 

    uint64 shaderLoadTime = SystemTimer::Instance()->AbsoluteMS();
    
    YamlParser * parser = YamlParser::Create(pathname);
    if (!parser)
        return false;
    
    YamlNode * rootNode = parser->GetRootNode();
    if (!rootNode)
    {
        SafeRelease(rootNode);
        return false;
    }
    
    const YamlNode * vertexShaderNode = rootNode->Get("vertexShader");
    if (!vertexShaderNode)
    {
        SafeRelease(parser);
        return false;
    }

    const YamlNode * glslVertexNode = vertexShaderNode->Get("glsl");
    if (!glslVertexNode)
    {
        SafeRelease(parser);
        return false;
    }
    
    const YamlNode * fragmentShaderNode = rootNode->Get("fragmentShader");
    if (!fragmentShaderNode)
    {
        SafeRelease(parser);
        return false;
    }
    
    const YamlNode * glslFragmentNode = fragmentShaderNode->Get("glsl");
    if (!glslFragmentNode)
    {
        SafeRelease(parser);
        return false;
    }

    FilePath pathOnly(pathname.GetDirectory());
    vertexShaderPath = pathOnly + glslVertexNode->AsString();
    fragmentShaderPath = pathOnly + glslFragmentNode->AsString();
    SafeRelease(parser);

    Load(vertexShaderPath, fragmentShaderPath);
    
    shaderLoadTime = SystemTimer::Instance()->AbsoluteMS() - shaderLoadTime;
    
//    Logger::FrameworkDebug("shader loaded:%s load-time: %lld ms", pathname.c_str(), shaderLoadTime);
    return true;
}
Beispiel #5
0
String FilePath::AbsoluteToRelative(const FilePath &directoryPathname, const FilePath &absolutePathname)
{
    if(absolutePathname.IsEmpty())
        return String();

    DVASSERT(directoryPathname.IsDirectoryPathname());

    Vector<String> folders;
	Vector<String> fileFolders;

	if(directoryPathname.GetType() == PATH_IN_RESOURCES &&	absolutePathname.GetType() == PATH_IN_RESOURCES)
	{
		Split(directoryPathname.absolutePathname, "/", folders);
		Split(absolutePathname.GetDirectory().absolutePathname, "/", fileFolders);
	}
	else
	{
		Split(directoryPathname.GetAbsolutePathname(), "/", folders);
		Split(absolutePathname.GetDirectory().GetAbsolutePathname(), "/", fileFolders);
	}
    
    Vector<String>::size_type equalCount = 0;
    for(; equalCount < folders.size() && equalCount < fileFolders.size(); ++equalCount)
    {
        if(folders[equalCount] != fileFolders[equalCount])
        {
            break;
        }
    }
    
    String retPath = "";
    for(Vector<String>::size_type i = equalCount; i < folders.size(); ++i)
    {
        retPath += "../";
    }
    
    for(Vector<String>::size_type i = equalCount; i < fileFolders.size(); ++i)
    {
        retPath += fileFolders[i] + "/";
    }
    
    return (retPath + absolutePathname.GetFilename());
}
bool ImageSplitter::SplitImage(const FilePath &pathname, Set<String> &errorLog)
{
    Image *loadedImage = CreateTopLevelImage(pathname);
    if(!loadedImage)
    {
        errorLog.insert(String(Format("Can't load image %s", pathname.GetAbsolutePathname().c_str())));
        return false;
    }
    
    if(loadedImage->GetPixelFormat() != FORMAT_RGBA8888)
    {
        errorLog.insert(String(Format("Incorrect image format %s. Must be RGBA8888", Texture::GetPixelFormatString(loadedImage->GetPixelFormat()))));
        return false;
    }
    

    Image *red = Image::Create(loadedImage->width, loadedImage->height, FORMAT_A8);
    Image *green = Image::Create(loadedImage->width, loadedImage->height, FORMAT_A8);
    Image *blue = Image::Create(loadedImage->width, loadedImage->height, FORMAT_A8);
    Image *alpha = Image::Create(loadedImage->width, loadedImage->height, FORMAT_A8);

    int32 size = loadedImage->width * loadedImage->height;
    int32 pixelSize = Texture::GetPixelFormatSizeInBytes(FORMAT_RGBA8888);
    for(int32 i = 0; i < size; ++i)
    {
        int32 offset = i * pixelSize;
        red->data[i] = loadedImage->data[offset];
        green->data[i] = loadedImage->data[offset + 1];
        blue->data[i] = loadedImage->data[offset + 2];
        alpha->data[i] = loadedImage->data[offset + 3];
    }
    
    FilePath folder(pathname.GetDirectory());
    
    SaveImage(red, folder + "r.png");
    SaveImage(green, folder + "g.png");
    SaveImage(blue, folder + "b.png");
    SaveImage(alpha, folder + "a.png");


    ReleaseImages(red, green, blue, alpha);
    SafeRelease(loadedImage);
    return true;
}
void CubemapEditorDialog::LoadImageFromUserFile(float rotation, int face)
{
	FilePath projectPath = CubemapUtils::GetDialogSavedPath("Internal/CubemapLastFaceDir",
															ProjectManager::Instance()->CurProjectDataSourcePath().GetAbsolutePathname());
		
	QString fileName = QtFileDialog::getOpenFileName(this,
													tr("Open Cubemap Face Image"),
													QString::fromStdString(projectPath.GetAbsolutePathname()),
													tr("Image Files (*.png)"));
	
	if(!fileName.isNull())
	{
		String stdFilePath = fileName.toStdString();
		LoadImageTo(stdFilePath, face, false);
		
		projectPath = stdFilePath;
		SettingsManager::SetValue(Settings::Internal_CubemapLastFaceDir, VariantType(projectPath.GetDirectory()));
		
		if(AllFacesLoaded())
		{
			ui->legend->setVisible(false);
		}
	}
}
Beispiel #8
0
	rstream.Release();

	Console::GetDefault()->Out->WriteLine(String::Format("Success! Read back 0x%08x, \"%s\", and 0x%04x from file.", num, str.CString(), num2));

	// rstream and reader are both Released() when this returns thanks to AutoPointer.

	Console::GetDefault()->Out->WriteLine(" --- File Path Test --- ");
	Console::GetDefault()->Out->WriteLine("Creating FilePath, should be /test/lol/sup");
	FilePath path("lol");
	path = path.Combine("sup");
	path = path.RootPath("/test");
#if !BRICKS_ENV_WINDOWS
	BRICKS_FEATURE_ASSERT(path == "/test/lol/sup");
#endif
	Console::GetDefault()->Out->WriteLine(String::Format("Result: %s, filename is %s", path.CString(), path.GetFileName().CString()));
	Console::GetDefault()->Out->WriteLine(String::Format("Directory is: %s", path.GetDirectory().CString()));

	Console::GetDefault()->Out->WriteLine(" --- Directory Iteration Test --- ");
	Console::GetDefault()->Out->WriteLine("Listing contents of current directory...");
	AutoPointer<FileNode> node = autonew FilesystemNode("."); // current dir
#if BRICKS_CONFIG_CPP0X
	node->Iterate([](FileNode* subnode) -> bool {
		Console::GetDefault()->Out->WriteLine(String::Format("Subfile: %s", subnode->GetName().CString()));
		return true; // returning false is like break;ing out of the loop.
	});
#else
	foreach (FileNode* subnode, node) {
		Console::GetDefault()->Out->WriteLine(String::Format("Subfile: %s", subnode->GetName().CString()));
	}
#endif
}
FilePath LandscapeEditorCustomColors::GetScenePath()
{
	FilePath sceneFilePath = SceneDataManager::Instance()->SceneGetActive()->GetScenePathname();
	return FilePath(sceneFilePath.GetDirectory());
}
Beispiel #10
0
bool GraphicsFontDefinition::LoadFontDefinition(const FilePath & fontDefName)
{
    File * file = 0;

//    size_t pos = fontDefName.rfind("/");
//    String fileName = fontDefName.substr(pos + 1);
//    String pathName = fontDefName.substr(0, pos + 1) + LocalizationSystem::Instance()->GetCurrentLocale() + "/" + fileName;

    FilePath pathName = fontDefName.GetDirectory() + (LocalizationSystem::Instance()->GetCurrentLocale() + "/" + fontDefName.GetFilename());

    file = File::Create(pathName, File::READ|File::OPEN);

    if (!file)
    {
        file = File::Create(fontDefName, File::READ|File::OPEN);
        if (!file)
        {
            return false;
        }
    }

    char header[4];
    DVVERIFY(file->Read(header, 4) == 4);
    if ((header[0] != 'F') || (header[1] != 'D') || (header[2] != 'E') || (header[3] != 'F'))
    {
        SafeRelease(file);
        return false;
    }
    uint32 version = 0;
    DVVERIFY(file->Read(&version, 4) == 4);
    if (version != 1)
    {
        SafeRelease(file);
        return false;
    }

    DVVERIFY(file->Read(&fontAscent, 4) == 4);
    DVVERIFY(file->Read(&fontDescent, 4) == 4);
    DVVERIFY(file->Read(&fontLeading, 4) == 4);
    DVVERIFY(file->Read(&fontXHeight, 4) == 4);
    DVVERIFY(file->Read(&charLeftRightPadding, 4) == 4);
    DVVERIFY(file->Read(&charTopBottomPadding, 4) == 4);

    fontHeight = (uint32)(fontAscent + fontDescent + fontLeading + 0.5f);

    DVVERIFY(file->Read(&tableLenght, 4) == 4);
    characterTable = new char16[tableLenght];
    characterPreShift = new float32[tableLenght];
    characterWidthTable = new float32[tableLenght];
    kerningBaseShift = new float32[tableLenght];
    kerningTable = new KerningPair*[tableLenght];

    for (int32 t = 0; t < tableLenght; ++t)
    {
        // BORODA: THIS IS FIX BECAUSE CHAR16 isn't char16 on MacOS and iPhone
        unsigned short c = 0;
        DVVERIFY(file->Read(&c, 2) == 2);
        characterTable[t] = c;
        DVVERIFY(file->Read(&characterPreShift[t], 4) == 4);
        DVVERIFY(file->Read(&characterWidthTable[t], 4) == 4);
        //Logger::Debug("char: %c idx: %d",  characterTable[t], t);
    }

    DVVERIFY(file->Read(&defaultShiftValue, 4) == 4);

    for (int t = 0; t < tableLenght; ++t)
    {
        DVVERIFY(file->Read(&kerningBaseShift[t], 4) == 4);
        //Logger::Debug("base: %c baseshift:%f preshift:%f", characterTable[t], kerningBaseShift[t], characterPreShift[t]);
    }

    DVVERIFY(file->Read(&kerningPairCount, 4) == 4);
    for (int32 k = 0; k < tableLenght; ++k)
        kerningTable[k] = 0;

    for (int32 kp = 0; kp < kerningPairCount; ++kp)
    {
        unsigned short s1short;
        DVVERIFY(file->Read(&s1short, 2) == 2);
        unsigned short s2short;
        DVVERIFY(file->Read(&s2short, 2) == 2);
        float32 shift;
        DVVERIFY(file->Read(&shift, 4) == 4);

        KerningPair * p = new KerningPair();
        p->ch1Index = s1short;
        p->ch2Index = s2short;
        p->shift = shift;
        AddKerningPair(p);
        //file->Read(&kerningTable[s1][s2], 4, 1, fontFP);
    }

//	for (int32 t = 0; t < tableLenght; ++t)
//	{
//		//Logger::Debug("char check: %c idx: %d",  characterTable[t], t);
//	}


    SafeRelease(file);
    return true;
}