예제 #1
0
bool ff::SaveData<ff::String>(ff::IDataWriter *pWriter, ff::StringRef data)
{
	DWORD nBytes = (DWORD)((data.length() + 1) * sizeof(wchar_t));

	assertRetVal(SaveData(pWriter, nBytes), false);

	return SaveBytes(pWriter, data.c_str(), nBytes);
}
예제 #2
0
파일: ClrHost.cpp 프로젝트: am11/ffcore
static ff::String GetClrVersion(ICLRMetaHost *metaHost, ff::StringRef versionOrAssembly)
{
	ff::String version;
	assertRetVal(versionOrAssembly.size(), version);

	if (!_wcsicmp(ff::GetPathExtension(versionOrAssembly).c_str(), L"dll"))
	{
		ff::String assembly = ff::GetExecutablePath();
		ff::StripPathTail(assembly);
		ff::AppendPathTail(assembly, versionOrAssembly);

		if (ff::FileExists(assembly))
		{
			wchar_t versionBuf[32];
			DWORD count = _countof(versionBuf);
			assertRetVal(SUCCEEDED(metaHost->GetVersionFromFile(assembly.c_str(), versionBuf, &count)), version);
			version = versionBuf;
		}
		else
		{
			assertSz(false, ff::String::format_new(L"Managed DLL doesn't exist: %s", assembly.c_str()).c_str());
		}
	}
	else if (versionOrAssembly[0] == 'v')
	{
		version = versionOrAssembly;
	}
	else
	{
		assertRetVal(false, version);
	}

	return version;
}
예제 #3
0
파일: DictPersist.cpp 프로젝트: am11/ffcore
void ff::DumpDict(ff::StringRef name, const Dict &dict, Log *log, bool chain, bool debugOnly)
{
	if (debugOnly && !GetThisModule().IsDebugBuild())
	{
		return;
	}

	Log extraLog;
	Log &realLog = log ? *log : extraLog;

	realLog.TraceF(L"+- Options for: %s --\r\n", name.c_str());

	Vector<String> names = dict.GetAllNames(chain, true, false);
	for (const String &key: names)
	{
		Value *value = dict.GetValue(key, chain);
		assert(value);

		String valueString;
		ValuePtr convertedValue;

		if (value->Convert(ff::Value::Type::String, &convertedValue))
		{
			valueString = convertedValue->AsString();
		}
		else if (value->Convert(ff::Value::Type::StringVector, &convertedValue))
		{
			Vector<String> &strs = convertedValue->AsStringVector();

			for (size_t i = 0; i < strs.Size(); i++)
			{
				valueString += String::format_new(L"\r\n|    [%lu]: %s", i, strs[i].c_str());
			}
		}
		else if (value->Convert(ff::Value::Type::Data, &convertedValue))
		{
			valueString.format(L"<data[%lu]>", convertedValue->AsData()->GetSize());
		}
		else
		{
			valueString = L"<data>";
		}

		realLog.TraceF(L"| %s: %s\r\n", key.c_str(), valueString.c_str());
	}

	realLog.Trace(L"+- Done --\r\n");
}
예제 #4
0
ff::ValuePtr SpritesTransformValue(ff::StringRef name, const ff::Dict &input)
{
	ff::String basePath = input.GetString(RES_BASE);

	bool optimize = input.GetBool(PROP_OPTIMIZE, true);
	size_t mips = input.GetSize(PROP_MIPS, 1);
	ff::String formatProp = input.GetString(PROP_FORMAT, ff::String(L"rgba32"));
	DXGI_FORMAT format = ff::ParseTextureFormat(formatProp);
	assertRetVal(format != DXGI_FORMAT_UNKNOWN, nullptr);

	ff::Dict spritesDict = input.GetDict(PROP_SPRITES);
	ff::Vector<ff::String> names = spritesDict.GetAllNames(true, true);
	ff::Map<ff::String, ff::ComPtr<ff::IGraphTexture>> textures;

	ff::ComPtr<IUnknown> catParent = ff::ProcessGlobals::Get()->GetModules().CreateParentForCategory(ff::GetCategoryGraphicsObject(), nullptr);
	ff::ComPtr<ff::IGraphDevice> graph;
	assertRetVal(graph.QueryFrom(catParent), nullptr);

	ff::ComPtr<ff::ISpriteList> origSprites;
	assertRetVal(ff::CreateSpriteList(graph, &origSprites), false);

	for (ff::StringRef name : names)
	{
		ff::Dict spriteDict = spritesDict.GetDict(name);

		ff::PointFloat pos;
		ff::PointFloat size;
		ff::RectFloat posRect = spriteDict.GetRectF(PROP_POS);
		if (!posRect.IsNull())
		{
			pos = posRect.TopLeft();
			size = posRect.Size();
		}
		else
		{
			pos = spriteDict.GetPointF(PROP_POS);
			size = spriteDict.GetPointF(PROP_SIZE);
		}

		ff::PointFloat offset = spriteDict.GetPointF(PROP_OFFSET, ff::PointFloat(size.x, 0));
		ff::String fileProp = spriteDict.GetString(PROP_FILE);
		ff::PointFloat handle = spriteDict.GetPointF(PROP_HANDLE);
		ff::PointFloat scale = spriteDict.GetPointF(PROP_SCALE, ff::PointFloat(1, 1));
		size_t repeat = spriteDict.GetSize(PROP_REPEAT, 1);

		if (size.x < 1 || size.y < 1)
		{
			std::wcerr << L"Sprite size too small: " << name << std::endl;
			return nullptr;
		}

		ff::String basePath = input.GetString(RES_BASE);
		ff::String fullFile = basePath;
		ff::AppendPathTail(fullFile, fileProp);

		ff::ComPtr<ff::IGraphTexture> texture;
		ff::BucketIter iter = textures.Get(fullFile);
		if (iter != ff::INVALID_ITER)
		{
			texture = textures.ValueAt(iter);
		}
		else
		{
			assertRetVal(ff::CreateGraphTexture(graph, fullFile,
				optimize ? DXGI_FORMAT_R8G8B8A8_UNORM : format,
				optimize ? 1 : mips, &texture), false);
			textures.SetKey(fullFile, texture);
		}

		for (size_t i = 0; i < repeat; i++)
		{
			ff::String spriteName = (repeat > 1)
				? ff::String::format_new(L"%s %d", name.c_str(), i)
				: name;
			ff::PointFloat topLeft(pos.x + offset.x * i, pos.y + offset.y * i);
			ff::RectFloat rect(topLeft, topLeft + size);

			assertRetVal(origSprites->Add(texture, spriteName, rect, handle, scale, ff::SpriteType::Unknown), false);
		}
	}

	ff::ComPtr<ff::ISpriteList> finalSprites;
	if (optimize)
	{
		assertRetVal(ff::OptimizeSprites(origSprites, format, mips, &finalSprites), false);
	}
	else
	{
		finalSprites = origSprites;
	}

	ff::ComPtr<ff::IResourceSave> resourceSave;
	assertRetVal(resourceSave.QueryFrom(finalSprites), nullptr);

	ff::Dict spritesSave;
	assertRetVal(resourceSave->SaveResource(spritesSave), nullptr);

	spritesSave = spritesSave.GetDict(PROP_DATA);
	assertRetVal(spritesSave.Size(), nullptr);

	ff::ValuePtr outputValue;
	assertRetVal(ff::Value::CreateDict(std::move(spritesSave), &outputValue), nullptr);

	return outputValue;
}