nova::nstring CFilesPackage::GetFileExt(const nstring & name) const 
{
	stl<nstring, FileHeader>::map::const_iterator it;
	if(!mIsOpened)
		throw NOVA_EXP("CFilesPackage::GetFileExt: package not opened, open package file first!", BAD_OPERATION);

	if((it = mPackageMap.find(name)) != mPackageMap.end())
		return nstring((*it).second.ext);

	return nstring();
}
예제 #2
0
nstring CStringUtils::IntTo16xString(nInt32 num)
{
	char temp[30] = "\0";

	sprintf(temp, "%X", num);
	return nstring(temp);
	//return nstring(itoa(num, temp, 16));
}
예제 #3
0
void CRenderSystem::RegisterGlSubSystem(CGLSupport *glsup)
{
    if(glsup)
    {
        std::pair<nstring, CGLSupport*> _pair;
        _pair.first = glsup->GetName();
        _pair.second = glsup;

        stl<nstring, CGLSupport*>::map::iterator it;
        if((it = mGlSupports.find(glsup->GetName())) == mGlSupports.end())
            mGlSupports.insert(_pair);
        else
            throw NOVA_EXP(nstring("CRenderSystem::RegisterGlSubSystem - gl sub system ") + glsup->GetName() + " already registered..", BAD_OPERATION);

        LOG_MESSAGE(nstring("Render Sub System ") + glsup->GetName() + " successfully registered.");
    }
}
예제 #4
0
void CRenderSystem::UnregisterGlSubSystem(CGLSupport *glsup)
{
    stl<nstring, CGLSupport*>::map::iterator it;
    if((it = mGlSupports.find(glsup->GetName())) != mGlSupports.end())
    {
        mGlSupports.erase(it);
        LOG_MESSAGE(nstring("Render sub system ") + glsup->GetName() + " successfully unregistered.");
    }
}
예제 #5
0
//-----------------------------------------------------------------------------
// 設定除錯功能函式
void InitMemDbg(IN const nstring &szFilePath)
{
#ifdef _DEBUG
	// 寫入除錯旗標值
	_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);

	HANDLE hDumpFile = INVALID_HANDLE_VALUE;

	// 建立記憶體警告輸出到文件
	{
		hDumpFile = CreateFile(nstring(szFilePath + (szFilePath.empty() ? __T("") : __T("\\")) + __T("memoryleak_warning.log")).c_str(), 
							   GENERIC_WRITE, 
							   FILE_SHARE_WRITE | FILE_SHARE_READ, 
							   nullptr, 
							   CREATE_ALWAYS, 
							   FILE_ATTRIBUTE_NORMAL, 
							   nullptr);

		if(hDumpFile != INVALID_HANDLE_VALUE)
		{
			_CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE); // 設定將警告輸出到文件
			_CrtSetReportFile(_CRT_WARN, hDumpFile); // 設定輸出的文件Handle
		}//if
	}

	// 建立記憶體錯誤輸出到文件
	{
		hDumpFile = CreateFile(nstring(szFilePath + (szFilePath.empty() ? __T("") : __T("\\")) + __T("memoryleak_error.log")).c_str(), 
							   GENERIC_WRITE, 
							   FILE_SHARE_WRITE | FILE_SHARE_READ, 
							   nullptr, 
							   CREATE_ALWAYS, 
							   FILE_ATTRIBUTE_NORMAL, 
							   nullptr);

		if(hDumpFile == INVALID_HANDLE_VALUE)
		{
			_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE); // 設定將錯誤輸出到文件
			_CrtSetReportFile(_CRT_ERROR, hDumpFile); // 設定輸出的文件Handle
		}//if
	}
#endif
}
예제 #6
0
void CSDLWorkspace::SaveContents(nstring & file)
{
	if(!mReady)
		return;

	SDL_Surface * dib = NULL;
	Uint32 rmask, gmask, bmask, amask;

#if SDL_BYTEORDER == SDL_BIG_ENDIAN
    rmask = 0xff000000;
    gmask = 0x00ff0000;
    bmask = 0x0000ff00;
    amask = 0x000000ff;
#else
    rmask = 0x000000ff;
    gmask = 0x0000ff00;
    bmask = 0x00ff0000;
    amask = 0xff000000;
#endif

	if((dib = SDL_CreateRGBSurface(SDL_SWSURFACE, mMetrics.width, mMetrics.height, 
		mVideo->vfmt->BitsPerPixel, rmask, gmask, bmask, amask)) == NULL)
		throw NOVA_EXP((nstring("CSDLWorkspace::SaveContents - Couldn't allocate dib surface: ")+
			nstring(SDL_GetError())).c_str(), BAD_OPERATION);

	SDL_Rect dsrect, screct;
	SDL_GetClipRect(dib, &dsrect);
	screct.x =  screct.y = 0;
	screct.w = mMetrics.width;
	screct.h = mMetrics.height;

	SDL_BlitSurface(mScreen, &screct, dib, &dsrect);
	SDL_SaveBMP(dib, file.c_str());
	SDL_FreeSurface(dib);

	dib = NULL;
}
예제 #7
0
nova::stl<nstring>::vector CStringUtils::Split(const nstring & str, char delim)
{
	nstringstream stream(str);
	nova::stl<nstring>::vector temp;

	if(!stream.good())
		return temp;

	while(!stream.eof())
	{
		char buf[0xff];
		stream.getline(buf, 0xff, delim); 

		temp.push_back(nstring(buf));
	}

	return temp;
}
예제 #8
0
re_str_t
resetstr(re_str_t *oldstr, const u_char *addstr){
	u_char *p, *ostr = oldstr->data;
	size_t t =0, len = strlen(ostr);
	p = ostr + len;
	while(p--){
		if (*p == '.'){
			break;
		} else if (*p == '\0'){
			continue;
		}
		len--;
	}
	u_char newstr[len];
	p = newstr;
	while(++t < len){
		*p++ = *ostr++;
	}
	*p='\0';
	return (re_str_t)nstring(newstr, addstr, "\0");
}
/* for force loading form packages */
CResourcePtr CResourceManager::LoadResourceFromXml(const nstring &filename, const CFilesPackage &package)
{
	CResourcePtr res;
	nstring rname, rgroup;
	CResourceManager *manager = NULL;

	if(!package.IsOpened())
		return res;

	nova::CMemoryBuffer xmlfile = package.GetFile(filename);
	if(xmlfile.GetBegin() && ( package.GetFileExt(filename) == "xml"))
	{
		xmlDocPtr doc = NULL;
		doc = xmlParseMemory((char *)xmlfile.GetBegin(), xmlfile.GetBufferSize());

		if(doc == NULL)
			throw NOVA_EXP("CResourceManager::LoadResourceFromXml - Parse error of xml file from memory", BAD_OPERATION);

		xmlNodePtr cur = xmlDocGetRootElement(doc);
		if(cur == NULL)
		{
			xmlFreeDoc(doc);
			throw NOVA_EXP("CResourceManager::LoadResourceFromXml - Parse error xml root element.", BAD_OPERATION);
		}

		const xmlChar * caption = cur->name;
		if(xmlStrcmp(caption, (xmlChar *)"NovaResource"))
		{
			xmlFreeDoc(doc);
			throw NOVA_EXP("CResourceManager::LoadResourceFromXml - this xml file is not a nova resource file.", BAD_OPERATION);
		}

		cur = cur->children;
		xmlNodePtr dataNode = NULL;
		while(cur != NULL)
		{
			if(xmlIsBlankNode(cur))
			{
				cur = cur->next;
				continue;
			}

			if(!xmlStrcmp(cur->name, (xmlChar *)"ResourceHeader"))
			{
				cur = cur->children;
				continue;
			}

			if(!xmlStrcmp(cur->name, (xmlChar *) "ResourceName"))
				rname.append(reinterpret_cast<char *>(cur->children->content));
			if(!xmlStrcmp(cur->name, (xmlChar *) "ResourceGroup"))
				rgroup.append(reinterpret_cast<char *>(cur->children->content));

			if(!xmlStrcmp(cur->name, (xmlChar *) "ResourceData"))
			{
				xmlChar * managerName = xmlGetProp(cur, (xmlChar *) "ResourceFactory");
				dataNode = cur->children;

				if(!managerName)
				{
					xmlFreeDoc(doc);
					throw NOVA_EXP("CResourceManager::LoadResourceFromXml - \
						Resource manager is not set..", BAD_OPERATION);
				}

				manager = GetResourceFactory(nstring(reinterpret_cast<char *>(managerName)));
				if(!manager)
				{
					xmlFreeDoc(doc);
					throw NOVA_EXP(nstring("CResourceManager::LoadResourceFromXml - \
						Resource manager ") + reinterpret_cast<char *>(managerName)
						+ " is not found..", BAD_OPERATION);
				}
예제 #10
0
CRenderSystem::CRenderSystem() : mTargetsBuilded(0), mRootWindow(NULL),
    mConfigIsReady(false), mSupport(NULL), mScreenShotTarget(NULL), CBase("CRenderSystem")
{
    mPrivateConfigFile = nstring(DEFAULT_CONFIG_PATH);
    LOG_MESSAGE("OpenGL RenderSystem created...");
}
예제 #11
0
nInt32 CScene::LoadSceneForce(const nstring &pckFile, bool withResorces)
{
	xmlDocPtr doc = NULL;
	doc = xmlParseFile(pckFile.c_str());

	if(doc == NULL)
		throw NOVA_EXP("CScene::LoadSceneForce - Parse error of xml file from file", BAD_OPERATION);

	xmlNodePtr cur = xmlDocGetRootElement(doc);
	if(cur == NULL)
	{
		xmlFreeDoc(doc);
		throw NOVA_EXP("CScene::LoadSceneForce - Parse error xml root element.", BAD_OPERATION);
	}

	const xmlChar * caption = cur->name;
	if(xmlStrcmp(caption, (xmlChar *)"NovaScene"))
	{
		xmlFreeDoc(doc);
		throw NOVA_EXP("CScene::LoadSceneForce - this xml file is not a nova scene file.", BAD_OPERATION);
	}

	cur = cur->children;
	xmlNodePtr data = NULL;
	while(cur != NULL)
	{
		if(xmlIsBlankNode(cur))
		{
			cur = cur->next;
			continue;
		}

		if(withResorces)
		{
			if(!xmlStrcmp(cur->name, (xmlChar *)"SceneResources"))
			{
				data = cur->children;
				
				while(data != NULL)
				{
					if(xmlIsBlankNode(cur))
					{
						data = data->next;
						continue;
					}

					if(!xmlStrcmp(data->name, (xmlChar *) "ResourceFile"))
					{
						nova::CResourceManager::LoadResourceFromXml(reinterpret_cast<char *>(data->children->content));
					}

					data = data->next;
				}
			}
		}

		if(!xmlStrcmp(cur->name, (xmlChar *)"SceneContent"))
		{
			xmlChar * managerName = xmlGetProp(cur, (xmlChar *) "SceneManager");
			nova::CSmartPtr<CSceneManager> scenePtr = FindScene(reinterpret_cast<char *>(managerName));

			if(!scenePtr.IsNull())
			{
				scenePtr->DeSerializeSceneFromXml(cur->children);
				scenePtr->PrepareScene();
			}
			else
			{
				xmlFreeDoc(doc);
				throw NOVA_EXP(nstring("CScene::LoadSceneForce - can not find scene manager ") + reinterpret_cast<char *>(managerName), BAD_OPERATION);
			}
		}

		cur = cur->next;
	}

	xmlFreeDoc(doc);
	return 0;
}
예제 #12
0
void CSDLWorkspace::CreateRenderWindow(nova::WindowInitialTarget &init)
{
	LOG_MESSAGE("SDL(!): trying to create render window...");

	mMetrics.d_buff = init.d_buff;
	mMetrics.fullscreen = init.fullscreen;
	mMetrics.freq = init.freq;
	mMetrics.vsync = init.vsync;
	mMetrics.FSAA = init.FSAA;
	mMetrics.DepthBuffered = init.DepthBuffered;

	int color_depth = init.color_bits;
	int alpha_bits = (init.color_bits > 16)? 8 : 0;
	int color_bits = (init.color_bits > 16)? 24 : init.color_bits;

	mMetrics.color_bits = color_bits;

// Берем видео инфу для начала
	mVideo = const_cast<SDL_VideoInfo *>(SDL_GetVideoInfo());

    if(!mVideo)
		throw NOVA_EXP((nstring("CSDLWorkspace::CreateRenderWindow - Couldn't get video information: ")+
			nstring(SDL_GetError())).c_str(), BAD_OPERATION);

	nova::uint flags = SDL_OPENGL | SDL_HWSURFACE | SDL_ANYFORMAT;
	if(mMetrics.fullscreen > 0)
	{
		mFullScreen = true;
		flags |= SDL_FULLSCREEN;
	}

	if(mMetrics.color_bits > 16)
	{
		SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
		SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
		SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
	}

	if(alpha_bits > 0)
	{
		SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, alpha_bits);
	}

	SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
	SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);

	if(mMetrics.FSAA > 1)
	{
		SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
		SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, mMetrics.FSAA);
	}

	if(mMetrics.vsync)
		SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1);
	else
		SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 0);

	if(mMetrics.d_buff)
		SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
	else
		SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 0);


// Создаем окошко, ставим разрешение и видео мод
	if((mScreen = SDL_SetVideoMode(init.width, init.height, mVideo->vfmt->BitsPerPixel, flags)) == NULL)
		throw NOVA_EXP((nstring("CSDLWorkspace::CreateRenderWindow - Couldn't set video mode: ")+
			nstring(SDL_GetError())).c_str(), BAD_OPERATION);
	LOG_MESSAGE("SDL(!): Render window successfully created!");

	{
		char driver[100];
		nstring dr(SDL_VideoDriverName(driver, 100));
		dr = "SDL(!): current driver name: " + dr;
		LOG_MESSAGE(dr);
	}

	if (!mMetrics.fullscreen)
		SDL_WM_SetCaption(mName.c_str(), 0);

	//SDL_Rect rect;
	//SDL_GetClipRect(mScreen, &rect);

	if(mMetrics.FSAA > 1)
	{
		glEnable( GL_MULTISAMPLE_ARB ); 
	}

	mMetrics.xpos = 0;
	mMetrics.ypos = 0;
	mMetrics.width = init.width;
	mMetrics.height = init.height;

	mSupport->InitGLExtentions();
#ifdef WIN_BUILD
	mSupport->InitWGLExtensions();
#endif

	mReady = true;
}
void CFilesPackage::OpenPackage(CDataStream *pkgstream, bool write)
{
	if(mIsOpened)
		throw NOVA_EXP("CFilesPackage::OpenPackage: package already opened!", BAD_OPERATION);
	mPackageMap.clear();

	if(!pkgstream)
		throw NOVA_EXP("CFilesPackage::OpenPackage: bad input package stream!", BAD_OPERATION);
	mFile = pkgstream;

	if(!write)
	{
		mFile->Seek(0);
		TPackageHeader header;

		mFile->Read(&header, sizeof(TPackageHeader));

		if(header.m_signature != NPK_MAIN_SIGNATURE)
			throw NOVA_EXP("CFilesPackage::OpenPackage: package unknown main signature!", BAD_OPERATION);
		mVersion = header.version;

		if(mVersion == NPK_VERSION_1_0)
		{
			if(header.v_signature != NPK_SECOND_SIGNATURE(mVersion))
				throw NOVA_EXP("CFilesPackage::OpenPackage: package unknown version signature!", BAD_OPERATION);

			mPackageName.append(header.package_name);
			while(!mFile->Eof())
			{
				TFileHeader f_header;
				mFile->Read(&f_header, sizeof(TFileHeader));

				std::pair<nstring, TFileHeader> pf;
				pf.first = nstring(f_header.file_name);
				pf.second = f_header;
				mPackageMap.insert(pf);

				mFile->Skip(f_header.size);

				if(mFile->Eof())
					break;
			}

			mFile->Seek(0);
		}
		else
		{
			/////
			throw NOVA_EXP("CFilesPackage::OpenPackage: package unknown version!", BAD_OPERATION);
		}

		mIsOpened = true;
		mWritePackage = false;
	}
	else
	{
		memset(&mPackageHeader, 0, sizeof(TPackageHeader));
		mPackageHeader.m_signature = NPK_MAIN_SIGNATURE;
		mPackageHeader.version = NPK_VERSION_1_0;
		mPackageHeader.v_signature = NPK_SECOND_SIGNATURE(mPackageHeader.version);
		strcpy(mPackageHeader.package_name, mPackageName.c_str());
		mFile->Write(&mPackageHeader, sizeof(TPackageHeader));

		mIsOpened = true;
		mWritePackage = true;
	}
}
예제 #14
0
//-----------------------------------------------------------------------------
// 清除目前行
void ClearConsoleLine(IN short wPos)
{
    short wX, wY;

    if(GetConsoleMousePos(wX, wY) == false)
        return;

    SetConsoleMousePos(0, wY);
    printfex(FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE, nstring(79, __T(' ')));
    SetConsoleMousePos(wPos, wY);
}