Пример #1
0
bool TiXmlDocument::LoadFile( const char* filename, TiXmlEncoding encoding )
{
	// There was a really terrifying little bug here. The code:
	//		value = filename
	// in the STL case, cause the assignment method of the std::string to
	// be called. What is strange, is that the std::string had the same
	// address as it's c_str() method, and so bad things happen. Looks
	// like a bug in the Microsoft STL implementation.
	// See STL_STRING_BUG above.
	// Fixed with the StringToBuffer class.
	value = filename;

	// reading in binary mode so that tinyxml can normalize the EOL
	IFile* file = g_OpenFile( value.c_str () );

	if ( file )
	{
		bool result = LoadBuffer( (LPCSTR)file->GetBuffer(), file->Size(), encoding );
		file->Release();
		return result;
	}
	else
	{
		SetError( TIXML_ERROR_OPENING_FILE, 0, 0, TIXML_ENCODING_UNKNOWN );
		return false;
	}
}
Пример #2
0
////////////////////////////////////////////////////////////
/// Construit le shader à partir des 2 fichiers
/// <name>.vert
/// <name>.frag
///
/// \param shaderFile_ : fichier vertex shader : <name>.vertexshader
///
////////////////////////////////////////////////////////////
GLShader::GLShader(IFile *pFile_)
{
	std::string fragmentFile = pFile_->Filename();

	size_t pos = fragmentFile.find(IRenderer::Get().GetShaderFileExtension());

	if (pos != std::string::npos)
	{
		fragmentFile = fragmentFile.substr(0, pos) + ".frag";
		IFile *pFragFile = MediaManager::Instance().FindMedia(fragmentFile, false);

		if (pFragFile == nullptr)
		{
			throw CLoadingFailed(fragmentFile, "GLShader() : Can't find the fragment shader (maybe add a reference to the right directory ?)");
		}

		if (pFragFile->Exists() == false)
		{
			throw CLoadingFailed(fragmentFile, "GLShader() : The fragment shader doesn't exist");
		}

		m_ProgramID = LoadShaderFrombuffer(pFile_->GetBuffer(), pFragFile->GetBuffer());

		DELETE_AO pFragFile;
	}
	else
	{
		CA_ERROR("GLShader() : Can't find the character '%s' in the filename '%s' to get the fragment shader.", 
			IRenderer::Get().GetShaderFileExtension(), pFile_->Filename().c_str());
	}
}
Пример #3
0
BOOL KSkillManager::LoadSkillBinaryData(KMAP_SKILL_DATA& allBinarySkillData)
{
    BOOL                bResult         = false;
    BOOL                bRetCode        = false;
    IFile*              piFile          = NULL;
    BYTE*               pBuffer         = NULL;
    size_t              uBufferSize     = 0;
    uint64_t            uSkillKey       = 0;
    KSkillBinaryData*   pBinaryData     = NULL;
    KAnchor*            pAnchor         = NULL;
    KSkillSegmentInfo*  pSegmentInfo    = NULL;
    KSkillLogicInfo*    pLogicData      = NULL;
    unsigned int        uEnd            = 0;
    BYTE*               pBufferEnd      = NULL;

    piFile = g_OpenFile(SETTING_DIR"/SkillAction.skilllogic");
    KGLOG_PROCESS_ERROR(piFile);

    pBuffer = (BYTE*)piFile->GetBuffer();
    KGLOG_PROCESS_ERROR(pBuffer);

    uBufferSize = piFile->Size();
    KGLOG_PROCESS_ERROR(uBufferSize);

    bRetCode = g_DoBufferSkip(pBuffer, uBufferSize, sizeof(KSkillLogicFileHeader));
    KG_PROCESS_ERROR(bRetCode);

    while (uBufferSize)
    {
        bRetCode = g_ReadFromBufferTo(pBuffer, uBufferSize, uEnd);
        KGLOG_PROCESS_ERROR(bRetCode);

        pBufferEnd = pBuffer + uEnd;

        bRetCode = g_ReadFromBufferAs(pBuffer, uBufferSize, pLogicData);
        KGLOG_PROCESS_ERROR(bRetCode);

        uSkillKey = MAKE_INT64(pLogicData->skillID, pLogicData->skillStep);
        pBinaryData = &allBinarySkillData[uSkillKey];

        pBinaryData->dwID           = pLogicData->skillID;
        pBinaryData->dwStep         = pLogicData->skillStep;
        pBinaryData->nTotalFrame    = pLogicData->frameCount;

        bRetCode = LoadAnchors(pBuffer, uBufferSize, pBinaryData->Anchors);
        KGLOG_PROCESS_ERROR(bRetCode);

        bRetCode = LoadSegments(pBuffer, uBufferSize, pBinaryData->Segments);
        KGLOG_PROCESS_ERROR(bRetCode);

        KGLOG_PROCESS_ERROR(pBufferEnd == pBuffer);
    }

    bResult = true;
Exit0:
    KG_COM_RELEASE(piFile);
    return bResult;
}
Пример #4
0
void KLuaWrap::LoadJitOpt()
{
	IFile*	pFile = NULL;

	if ((pFile = g_OpenFile("\\script\\lib\\jit\\opt.lua")) == NULL)
	{
		lua_tinker::print_error(m_L, "\\script\\lib\\jit\\opt.lua is not exist!\n");
		return;
	}
	if (luaL_loadbuffer(m_L, (const char*)pFile->GetBuffer(), pFile->Size(), "load jit opt"))
	{
		lua_tinker::print_error(m_L, "%s", lua_tostring(m_L, -1));
		lua_pop(m_L, 1);
		return;
	}
	pFile->Release();

	if ((pFile = g_OpenFile("\\script\\lib\\jit\\opt_inline.lua")) == NULL)
	{
		lua_tinker::print_error(m_L, "\\script\\lib\\jit\\opt_inline.lua is not exist!\n");
		return;
	}
	if (luaL_loadbuffer(m_L, (const char*)pFile->GetBuffer(), pFile->Size(), "load jit opt_inline"))
	{
		lua_tinker::print_error(m_L, "%s", lua_tostring(m_L, -1));
		lua_pop(m_L, 1);
		return;
	}
	pFile->Release();

	lua_getglobal(m_L, "package");
	lua_getfield(m_L, -1, "preload");
	lua_insert(m_L, 1);
	lua_pop(m_L, 1);

	lua_setfield(m_L, 1, "jit.opt_inline");
	lua_setfield(m_L, 1, "jit.opt");

	lua_pop(m_L, 1);
}
Пример #5
0
int KSystemScriptTable::LuaLoadDataFromFile(Lua_State* L)
{
    int nRetCode = false;

    IFile *piFile = NULL;
    const char *pcszFile = NULL;
    const char *pcsBuff = NULL;
    size_t uBuffSize = 0;
    int nParamCount = 0;
    char szFilePath[MAX_PATH];

    KGLOG_PROCESS_ERROR(L);

    nRetCode = lua_gettop(L);
    KGLOG_PROCESS_ERROR(nRetCode == 1);

    pcszFile = lua_tostring(L, 1);
    KGLOG_PROCESS_ERROR(pcszFile);

    nRetCode = snprintf(
                   szFilePath,
                   sizeof(szFilePath),
                   "%s\\%s",
                   F_UI_USER_DATA_FOLDER,
                   pcszFile
               );
    KGLOG_PROCESS_ERROR(nRetCode > 0);
    szFilePath[sizeof(szFilePath) - 1] = '\0';
    FormatFilePath(szFilePath);

    nRetCode = KUiConfig::IsFilePathExist(szFilePath);
    KG_PROCESS_SUCCESS(!nRetCode);

    piFile = g_OpenFile(szFilePath, true);
    KGLOG_PROCESS_ERROR(piFile);

    uBuffSize = piFile->Size();
    KGLOG_PROCESS_ERROR(uBuffSize > 0);

    pcsBuff = (const char *)piFile->GetBuffer();
    KGLOG_PROCESS_ERROR(pcsBuff);

    lua_pushlstring(L, pcsBuff, uBuffSize);
    nParamCount++;

Exit1:
Exit0:
    SAFE_RELEASE(piFile);
    return nParamCount;
}
Пример #6
0
void ScriptComponent::Initialize()
{
    if (m_pFileName != nullptr)
    {
        IFile *pFile = MediaManager::Instance().FindMedia(m_pFileName, false);
        SetScriptFromBuffer(pFile->GetBuffer(), pFile->GetBufferLength());
        DELETE_AO pFile;

        //TODO crash
        //Game::Instance()->GetScriptEngine()->SetField(GetEntity(), "entity");

        //call function OnScriptInitialize()
        //Game::Instance()->GetScriptEngine()->CallFunction("OnScriptInitialize");
    }
}