Esempio n. 1
0
const DropPoolItem* DropPoolConfig::GenerateFixedSingle(uint id) const
{
	const DropPool* dropPool = Find(id);
	Log::AssertNotNullFormat(dropPool, "Cannot find drop pool id:{}", id);
	RETURN_NULL_IF_NULL(dropPool);
	return dropPool->GenerateFixedSingle();
}
Esempio n. 2
0
FileEntry* FileStorage::FindOrCreateFileEntry(const StringRef& path, DirectoryEntry* parent /*= nullptr*/)
{
	if (parent == nullptr)
	{
		parent = &mRootDir;
	}

	FileEntry* fileEntry = nullptr;
	if (Path::IsPath(path))
	{
		List<HeapString> paths;
		RETURN_NULL_IF_FALSE(Path::Split(path, paths));

		DirectoryEntry* dir = parent;
		for (uint i = 0; i < paths.Count() - 1; ++i)
		{
			dir = dir->FindOrCreateDirectoryEntry(paths[i]);
			RETURN_NULL_IF_NULL(dir);
		}

		fileEntry = dir->FindOrCreateFileEntry(paths.Last());
	}
	else
	{
		fileEntry = parent->FindOrCreateFileEntry(path);
	}

	return fileEntry;
}
Esempio n. 3
0
IEffect* EffectFactory::CreateFromFile( const FileIdRef& fileId ,ResourceShareType shareType /*= ResourceShareType::Share*/)
{
	IEffect* effect = nullptr;
	if (shareType != ResourceShareType::None)
	{
		effect = Find(fileId);
		RETURN_SELF_IF_NOT_NULL(effect);
	}
	

	switch(FileInfo::ExtractType(fileId.Name))
	{
	case FileType::pfx:
		effect=PFXEffect::CreateFromFile(fileId.Name);	//TODO:
		break;
	default:
		return nullptr;
	}

	RETURN_NULL_IF_NULL(effect);
	if (effect->Initialize())
	{
		Add(effect, shareType);
		return effect;
	}
	SAFE_DELETE(effect);
	return nullptr;
}
Esempio n. 4
0
const FileEntry* FileStorage::FindFile(const StringRef& path, const DirectoryEntry* parent/* = nullptr*/) const
{
	if (parent == nullptr)
	{
		parent = &mRootDir;
	}

	if (Path::IsPath(path))
	{
		List<HeapString> paths;
		RETURN_NULL_IF_FALSE(Path::Split(path, paths));

		const DirectoryEntry* dir = parent;
		for (uint i = 0; i < paths.Count() - 1; ++i)
		{
			dir = dir->FindDirectory(paths[i]);
			RETURN_NULL_IF_NULL(dir);
		}

		return dir->FindFile(paths.Last());
	}
	else
	{
		return parent->FindFile(path);
	}
}
Esempio n. 5
0
Sprite* NodeFactory::CreateSprite(const Share<ITexture>& texture, const Rect2F& textureRect /*= Rect2F::Zero*/)
{
	auto renderingObject = RenderingObjectFactory::Instance().CreateFromTexture(texture, textureRect);
	RETURN_NULL_IF_NULL(renderingObject);

	return CreateSprite(renderingObject);
}
Esempio n. 6
0
Share<IAudio> AudioFactory::CreateFromFile(const FileIdRef& fileId, ResourceShareType shareType /*= ResourceShareType::Share*/)
{
	Share<IAudio> buffer;
	if (shareType != ResourceShareType::None)
	{
		buffer = Find(fileId);
		RETURN_SELF_IF_NOT_NULL(buffer);
	}


	switch (FileInfo::ExtractType(fileId.Name))
	{
#ifdef MEDUSA_OGG
	case FileType::ogg:
		buffer = OggAudio::CreateFromFile(fileId);
		break;
#endif
	case FileType::wav:
		buffer = WavAudio::CreateFromFile(fileId);
		break;
	default:
		return nullptr;
		break;
	}

	RETURN_NULL_IF_NULL(buffer);
	Add(buffer, shareType);
	return buffer;
}
Esempio n. 7
0
const IStream* FileStorage::ReadFile(const StringRef& path, DirectoryEntry* parent /*= nullptr*/, FileDataType dataType /*= FileDataType::Binary*/)const
{
	const FileEntry* fileEntry = FindFile(path, parent);
	RETURN_NULL_IF_NULL(fileEntry);

	return ReadFileHelper(*fileEntry, dataType);
}
Esempio n. 8
0
const IStream* FileStorage::ReadFileHelper(const FileEntry& file, FileDataType dataType /*= FileDataType::Binary*/) const
{
	const IStream* resultStream = OnReadFile(file, dataType);
	RETURN_NULL_IF_NULL(resultStream);

	const CoderChain* coderChain = GetFileCoderChain(file);
	if (coderChain != nullptr)
	{
		if (IsWholeFileCoding())
		{
			MemoryStream* tempStream = new MemoryStream(file.OriginalSize(), false);
			coderChain->Decode(*resultStream, *tempStream);
			const auto data = tempStream->CurrentBuffer();
			SAFE_DELETE(tempStream);
			MemoryStream* outputStream = new MemoryStream(data);
			resultStream = outputStream;
		}
		else
		{
			resultStream = new BlockCodeReadStream(*resultStream, BlockSize(), *coderChain, file);
		}
	}

	return resultStream;
}
Esempio n. 9
0
SpineSkeleton* NodeFactory::CreateSkeleton(const FileIdRef& skeletonfileId, const FileIdRef& atlasFileId, bool isPreCalculated /*= false*/)
{
	SpineSkeletonModel* model = SkeletonModelFactory::Instance().CreateSpineFromJson(skeletonfileId, atlasFileId, isPreCalculated);
	RETURN_NULL_IF_NULL(model);
	SpineSkeleton* skeleton = new SpineSkeleton(StringRef::Empty, model);
	skeleton->Initialize();
	return skeleton;
}
Esempio n. 10
0
Share<const IStream> MemoryPackage::OnReadFile(const FileEntry& file, FileDataType dataType /*= FileDataType::Binary*/) const
{
	UN_USED(dataType);
	Share<MemoryStream> memoryStream = mMemoryStreamDict.GetOptional(&file, nullptr);
	RETURN_NULL_IF_NULL(memoryStream);
	memoryStream->Rewind();

	return memoryStream;
}
Esempio n. 11
0
ILabel* NodeFactory::CreateSingleLineBMPNumberLabel(const FontId& fontId, StringRef text, wchar_t firstChar /*= L'.'*/, Alignment alignment /*= Alignment::MiddleCenter*/, Size2F restrictSize /*= Size2F::Zero*/, bool isStatic /*= false*/)
{
	auto font = FontFactory::Instance().CreateFromSingleTexture(fontId, firstChar);
	RETURN_NULL_IF_NULL(font);
	FntLabel* label = new FntLabel(StringRef::Empty, font, alignment, restrictSize, true, isStatic);
	label->Initialize();
	label->SetString(text);
	return label;
}
Esempio n. 12
0
ILabel* NodeFactory::CreateSingleLineLabel(const FontId& fontId, WStringRef text, Alignment alignment/*=Alignment::LeftBottom*/, Size2F restrictSize/*=Size2F::Zero*/, bool isStatic/*=false*/)
{
	IFont* font = FontFactory::Instance().Create(fontId);
	RETURN_NULL_IF_NULL(font);
	FntLabel* label = new FntLabel(StringRef::Empty, font, alignment, restrictSize, false, isStatic);
	label->Initialize();
	label->SetString(text);
	return label;
}
Esempio n. 13
0
Share<MultipleLineFontModel> ModelFactory::CreateMultipleLineFontModel(const FontId& fontId,StringRef text,Alignment alignment/*=Alignment::LeftBottom*/,Size2U restrictSize/*=Size2U::Zero*/)
{
	auto font=FontFactory::Instance().Create(fontId);
	RETURN_NULL_IF_NULL(font);
	Share<MultipleLineFontModel> model=new MultipleLineFontModel(font,alignment,restrictSize);
	model->Initialize();
	model->SetText(text);
	return model;

}
Esempio n. 14
0
ScriptObject* ScriptModule::NewObject(StringRef className)
{
	asIObjectType* scriptObjectType = mScriptModule->GetObjectTypeByName(className.c_str());
	RETURN_NULL_IF_NULL(scriptObjectType);

	HeapString factoryName = className;
	factoryName += "@ ";
	factoryName += className;
	factoryName += "()";
	asIScriptFunction* factory = scriptObjectType->GetFactoryByDecl(factoryName.c_str());
	RETURN_NULL_IF_NULL(factory);

	asIScriptContext* context = ScriptEngine::Instance().GetScriptContext();
	context->Prepare(factory);
	context->Execute();
	asIScriptObject* scriptObject = *(asIScriptObject**)context->GetAddressOfReturnValue();

	return new ScriptObject(scriptObject);
}
Esempio n. 15
0
IMaterial* MaterialFactory::CreateSingleTexture(ITexture* texture, ResourceShareType shareType /*= ResourceShareType::Share*/)
{
	RETURN_NULL_IF_NULL(texture);
	IMaterial* result = Find(texture->GetFileId());
	RETURN_SELF_IF_NOT_NULL(result);
	IEffect* effect = EffectFactory::Instance().CreateSinglePassDefault(RenderPassNames::Texture);
	result = new IMaterial(texture, effect, GraphicsDrawMode::Triangles, texture->GetFileId());

	Add(result, shareType);
	return result;
}
Esempio n. 16
0
Sprite* NodeFactory::CreateSpriteFromAtlasRegion(StringRef regionName, const FileIdRef& atlasFileId, TextureAtlasFileFormat fileFormat /*= TextureAtlasFileFormat::Spine*/, uint atlasPageCount /*= 1*/)
{
	auto renderingObject = RenderingObjectFactory::Instance().CreateFromTextureAtlasRegion(regionName, atlasFileId, fileFormat, atlasPageCount);
	RETURN_NULL_IF_NULL(renderingObject);

	Sprite* sprite = new Sprite();
	sprite->SetRenderingObject(renderingObject);
	sprite->SetSize(renderingObject.Mesh()->Size());
	sprite->Initialize();
	return sprite;
}
Esempio n. 17
0
IMaterial* MaterialFactory::Create(const FileIdRef& fileId, const FileMapOrderItem& orderItem, StringRef samplerName /*= StringRef::Empty*/, ResourceShareType shareType /*= ResourceShareType::Share*/)
{
	IMaterial* result = Find(fileId);
	RETURN_SELF_IF_NOT_NULL(result);

	ITexture* texture = nullptr;
	texture = TextureFactory::Instance().CreateFromOrderItem(fileId, orderItem, samplerName);
	RETURN_NULL_IF_NULL(texture);

	return Create(fileId, texture, shareType);
}
Esempio n. 18
0
SkWStream* CreateJavaOutputStreamAdaptor(JNIEnv* env, jobject stream,
                                         jbyteArray storage) {
    static bool gInited;

    if (!gInited) {
        gOutputStream_Clazz = env->FindClass("java/io/OutputStream");
        RETURN_NULL_IF_NULL(gOutputStream_Clazz);
        gOutputStream_Clazz = (jclass)env->NewGlobalRef(gOutputStream_Clazz);

        gOutputStream_writeMethodID = env->GetMethodID(gOutputStream_Clazz,
                                                       "write", "([BII)V");
        RETURN_NULL_IF_NULL(gOutputStream_writeMethodID);
        gOutputStream_flushMethodID = env->GetMethodID(gOutputStream_Clazz,
                                                       "flush", "()V");
        RETURN_NULL_IF_NULL(gOutputStream_flushMethodID);

        gInited = true;
    }

    return new SkJavaOutputStream(env, stream, storage);
}
Esempio n. 19
0
Sprite* NodeFactory::CreateQuadSprite(const FileIdRef& textureName, const Rect2F& textureRect/*=Rect2F::Zero*/)
{
	auto renderingObject = RenderingObjectFactory::Instance().CreateFromTexture(textureName, textureRect);
	RETURN_NULL_IF_NULL(renderingObject);

	Sprite* sprite = new Sprite();
	sprite->SetRenderingObject(renderingObject);
	sprite->SetSize(renderingObject.Mesh()->Size());
	sprite->Initialize();

	return sprite;
}
Esempio n. 20
0
IShape* NodeFactory::CreateTriangle(float width, float height, const Color4F& color)
{
	ShapeTriangleMesh* mesh = MeshFactory::Instance().CreateShapeTriangleMesh(width, height, color);
	RETURN_NULL_IF_NULL(mesh);
	IMaterial* material = MaterialFactory::Instance().CreateShape(MEDUSA_PREFIX(Shape));
	IShape* sprite = new IShape();
	sprite->Initialize();
	sprite->SetSizeToContent(SizeToContent::Mesh);

	sprite->SetMesh(mesh);
	sprite->SetMaterial(material);
	return sprite;
}
Esempio n. 21
0
Sprite* NodeFactory::CreateSpriteFromAtlasRegion(TextureAtlasRegion* region)
{
	auto renderingObject = RenderingObjectFactory::Instance().CreateFromTextureAtlasRegion(region);
	RETURN_NULL_IF_NULL(renderingObject);

	Sprite* sprite = new Sprite();
	sprite->SetRenderingObject(renderingObject);
	sprite->SetSize(renderingObject.Mesh()->Size());
	sprite->Initialize();

	return sprite;

}
Esempio n. 22
0
IShape* NodeFactory::CreateTriangle(const Point3F& p1, const Point3F& p2, const Point3F& p3, const Color4F& color)
{
	auto mesh = MeshFactory::Instance().CreateShapeTriangleMesh(p1, p2, p3, color);
	RETURN_NULL_IF_NULL(mesh);
	auto material = MaterialFactory::Instance().CreateShape(MEDUSA_PREFIX(Shape));
	IShape* sprite = new IShape();
	sprite->Initialize();
	sprite->SetSizeToContent(SizeToContent::Mesh);

	sprite->SetMesh(mesh);
	sprite->SetMaterial(material);
	return sprite;

}
Esempio n. 23
0
LinesShape* NodeFactory::CreateLine(const Point3F& from, const Point3F& to, const Color4F& color)
{
	auto mesh = MeshFactory::Instance().CreateLineMesh(from, to, color);
	RETURN_NULL_IF_NULL(mesh);
	auto material = MaterialFactory::Instance().CreateShape(MEDUSA_PREFIX(Shape_Lines));
	material->SetDrawMode(GraphicsDrawMode::Lines);
	LinesShape* sprite = new LinesShape();
	sprite->Initialize();

	sprite->SetSize(Math::Abs(to.X - from.X), Math::Abs(to.Y - from.Y));
	sprite->SetMesh(mesh);
	sprite->SetMaterial(material);
	return sprite;
}
Esempio n. 24
0
IShape* NodeFactory::CreateCircle(float radius, float precision, const Color4F& color)
{
	ShapeGeneralMesh* mesh = MeshFactory::Instance().CreateShapeCircleMesh(radius, precision, color);
	RETURN_NULL_IF_NULL(mesh);
	IMaterial* material = MaterialFactory::Instance().CreateShape(MEDUSA_PREFIX(Shape_TrianglesFan));
	material->SetDrawMode(GraphicsDrawMode::TriangleFan);
	IShape* sprite = new IShape();
	sprite->Initialize();
	sprite->SetSizeToContent(SizeToContent::Mesh);
	sprite->SetMesh(mesh);
	sprite->SetMaterial(material);
	return sprite;
	
}
Esempio n. 25
0
NineGridSprite* NodeFactory::CreateNineGridSprite(const Size2F& targetSize, const FileIdRef& textureName, const ThicknessF& padding, const Rect2F& textureRect/*=Rect2F::Zero*/)
{
	auto renderingObject = RenderingObjectFactory::Instance().CreateNineGridTexture(targetSize, textureName,padding,textureRect);
	RETURN_NULL_IF_NULL(renderingObject);

	NineGridSprite* sprite = new NineGridSprite();
	sprite->EnableLayout(false);	//suppress duplicate arrange after size changed
	sprite->SetRenderingObject(renderingObject);
	sprite->SetSize(renderingObject.Mesh()->Size());
	sprite->Initialize();
	sprite->EnableLayout(true);
	return sprite;

}
Esempio n. 26
0
IEffect* EffectFactory::CreateSinglePass(const FileIdRef& fileId,IRenderPass* renderPass,ResourceShareType shareType /*= ResourceShareType::Share*/)
{
	IEffect* effect = nullptr;
	if (shareType != ResourceShareType::None)
	{
		effect = Find(fileId);
		RETURN_SELF_IF_NOT_NULL(effect);
	}

	effect= CreateEmpty(fileId,shareType);
	RETURN_NULL_IF_NULL(effect);

	effect->GetGroupByIndex(0)->GetTechniqueByIndex(0)->AddPass(renderPass);
	return effect;
}
Esempio n. 27
0
IShape* NodeFactory::CreateRect(const Size2F& rectSize, const Color4F& color)
{

	ShapeQuadMesh* mesh = MeshFactory::Instance().CreateShapeQuadMesh(rectSize, color);
	RETURN_NULL_IF_NULL(mesh);
	IMaterial* material = MaterialFactory::Instance().CreateShape(MEDUSA_PREFIX(Shape));
	IShape* sprite = new IShape();
	sprite->Initialize();
	sprite->SetSizeToContent(SizeToContent::Mesh);

	sprite->SetMesh(mesh);
	sprite->SetMaterial(material);
	sprite->SetSize(rectSize);
	return sprite;
}
Esempio n. 28
0
DirectoryEntry* FileStorage::FindDirectory(const StringRef& path, DirectoryEntry* parent /*= nullptr*/)
{
	if (parent == nullptr)
	{
		parent = &mRootDir;
	}
	List<HeapString> paths;
	RETURN_NULL_IF_FALSE(Path::Split(path, paths));
	for (const auto& str : paths)
	{
		parent = parent->FindDirectory(str);
		RETURN_NULL_IF_NULL(parent);
	}

	return parent;
}
Esempio n. 29
0
IShape* NodeFactory::CreateRectBorder(const Size2F& rectSize, const Color4F& color)
{
	auto mesh = MeshFactory::Instance().CreateShapeQuadMesh(rectSize, color);
	RETURN_NULL_IF_NULL(mesh);
	auto material = MaterialFactory::Instance().CreateShape(MEDUSA_PREFIX(Shape_WireFrame));
	material->SetDrawMode(GraphicsDrawMode::LineStrip);

	IShape* sprite = new IShape();
	sprite->Initialize();
	sprite->SetSizeToContent(SizeToContent::Mesh);

	sprite->SetMesh(mesh);
	sprite->SetMaterial(material);
	sprite->SetSize(rectSize);
	return sprite;
}
Esempio n. 30
0
IEffect* EffectFactory::CreateMultiplePasses( const FileIdRef& fileId,List<IRenderPass*>& renderPasses ,ResourceShareType shareType /*= ResourceShareType::Share*/)
{
	IEffect* effect = nullptr;
	if (shareType != ResourceShareType::None)
	{
		effect = Find(fileId);
		RETURN_SELF_IF_NOT_NULL(effect);
	}


	effect= CreateEmpty(fileId,shareType);
	RETURN_NULL_IF_NULL(effect);
	EffectTechnique* technique=effect->GetGroupByIndex(0)->GetTechniqueByIndex(0);
	FOR_EACH_COLLECTION(i,renderPasses)
	{
		technique->AddPass(*i);
	}