void ControllerMappingLoader::load(const std::string& filename) {
		VFS* vfs = VFS::instance();

		std::unique_ptr<RawData> data(vfs->open(filename));
		size_t datalen = data->getDataLength();
		std::unique_ptr<uint8_t[]> darray(new uint8_t[datalen]);
		data->readInto(darray.get(), datalen);
		SDL_RWops* rwops = SDL_RWFromConstMem(darray.get(), static_cast<int>(datalen));
		if (SDL_GameControllerAddMappingsFromRW(rwops, 0) == -1) {
			throw SDLException(std::string("Error when loading gamecontroller mappings: ") + SDL_GetError());
		}
		SDL_FreeRW(rwops);
	}
Beispiel #2
0
	void OggLoader::load(IResource* res) {
		VFS* vfs = VFS::instance();

		std::string filename = res->getName();

		RawData* rdptr = vfs->open(filename);
		dynamic_cast<SoundClip*>(res)->adobtDecoder(new SoundDecoderOgg(rdptr));
	}
Beispiel #3
0
	void ImageLoader::load(IResource* res) {
		VFS* vfs = VFS::instance();

		Image* img = dynamic_cast<Image*>(res);

		//Have to save the images x and y shift or it gets lost when it's
		//loaded again.
		int32_t xShiftSave = img->getXShift();
		int32_t yShiftSave = img->getYShift();

		if(!img->isSharedImage()) {
			const std::string& filename = img->getName();
			boost::scoped_ptr<RawData> data (vfs->open(filename));
			size_t datalen = data->getDataLength();
			boost::scoped_array<uint8_t> darray(new uint8_t[datalen]);
			data->readInto(darray.get(), datalen);
			SDL_RWops* rwops = SDL_RWFromConstMem(darray.get(), static_cast<int>(datalen));

			SDL_Surface* surface = IMG_Load_RW(rwops, false);

			if (!surface) {
				throw SDLException(std::string("Fatal Error when loading image into a SDL_Surface: ") + SDL_GetError());
			}

			RenderBackend* rb = RenderBackend::instance();
			// in case of SDL we don't need to convert the surface
			if (rb->getName() == "SDL") {
				img->setSurface(surface);
			// in case of OpenGL we need a 32bit surface
			} else {
				SDL_PixelFormat dst_format = rb->getPixelFormat();
				SDL_PixelFormat src_format = *surface->format;
				uint8_t dstbits = dst_format.BitsPerPixel;
				uint8_t srcbits = src_format.BitsPerPixel;

				if (srcbits != 32 || dst_format.Rmask != src_format.Rmask || dst_format.Gmask != src_format.Gmask ||
					dst_format.Bmask != src_format.Bmask || dst_format.Amask != src_format.Amask) {
					dst_format.BitsPerPixel = 32;
					SDL_Surface* conv = SDL_ConvertSurface(surface, &dst_format, 0);
					dst_format.BitsPerPixel = dstbits;

					if (!conv) {
						throw SDLException(std::string("Fatal Error when converting surface to the screen format: ") + SDL_GetError());
					}

					img->setSurface(conv);
					SDL_FreeSurface(surface);
				} else {
					img->setSurface(surface);
				}
			}

			SDL_FreeRW(rwops);
		}
		//restore saved x and y shifts
		img->setXShift(xShiftSave);
		img->setYShift(yShiftSave);
	}
Beispiel #4
0
void testVFS()
{
	VFS* vfs = LOTUS_NEW VFS;
	
	RawFileSystem* rfs = LOTUS_NEW RawFileSystem();
	vfs->addFileSystem(rfs);
	vfs->mount("C:\\github\\lotus\\Lotus", "sys", RAW_FS);
	
	StreamPtr fp = vfs->open("sys", "/test/test.h");


	LOTUS_DELETE vfs;
}
Beispiel #5
0
/*******************************************************************************
	概要	:	アプリケーションクラスの初期化
	説明	:
	Include	:	Appli.h
	引数	:	u4 u4_EIP
				u4 u4_ESP
				u4 u4_ESP0
				const char* CPc_AppliFP	アプリケーションのファイルパス
	戻り値	:	s4		エラー情報
*******************************************************************************/
s4		Appli::Init( u4 u4_EIP, u4 u4_ESP, u4 u4_ESP0, const char* CPc_AppliFP, SegmInfo* P_SegmInfoTable )
{
	s4		s4_Return;

	//ファイルパスコピー
	strncpy( MAc_FilePath, CPc_AppliFP, sizeof MAc_FilePath - 1 );

	//ファイルパス最適化
	if( G_VFS.OptimFP( MAc_FilePath ) < 0 )
		return ERROR_INVALID_FP;

	//ファイルパスからファイル名を取得
	char*	Pc_FileName;
	if( ( Pc_FileName = strrchr( MAc_FilePath, '/' ) ) == NULL )
		return ERROR_INVALID_FP;

	//タスク初期化
	TSS::Init();
	Mu4_EIP		= u4_EIP;
DP( "Mu4_EIP:%#x", Mu4_EIP );
	Mu4_ESP		= u4_ESP;
DP( "Mu4_ESP:%#x", Mu4_ESP );
	Mu4_ESP0	= u4_ESP0;
DP( "Mu4_ESP0:%#x", Mu4_ESP0 );
	M_SS0		= KERNEL_DS;
	M_Flag16.Init();		//フラグ初期化
	if( ( s4_Return = SetCaption( Pc_FileName + 1 ) ) < 0 )		//キャプション設定
		return s4_Return;
	SetAllottedTime();		//タスク持ち時間設定

	//TSSディスクリプタの作成
	SegmInfo	TSSInfo;		//TSSディスクリプタ作成用情報
	TSSInfo.u4_Base			= (u4)this;
	TSSInfo.u20b_Limit		= sizeof (Appli) - 1;
	TSSInfo.u5b_Type		= G_GDT.TYPE_TSS_32;
	TSSInfo.u2b_DPL			= G_GDT.DPL0;
	TSSInfo.u1b_Granularity	= G_GDT.GRA_BYTE;
	G_GDT.SetSegment( TSSInfo, &M_TSSSelector );		//TSSディスクリプタの作成

	//LDTセグメント・ディスクリプタの作成
	SegmInfo	LDTInfo;		//LDTディスクリプタ作成用情報
	LDTInfo.u4_Base			= (u4)&M_LDT;
	LDTInfo.u20b_Limit		= sizeof (LDT) - 1;
	LDTInfo.u5b_Type		= G_GDT.TYPE_LDT;
	LDTInfo.u2b_DPL			= G_GDT.DPL0;
	LDTInfo.u1b_Granularity	= G_GDT.GRA_BYTE;
	G_GDT.SetSegment( LDTInfo, &Mu2_LDT );		//LDTセグメント・ディスクリプタの作成

	//LDTのセットアップ、終了
	return SetupLDT( P_SegmInfoTable );
}