コード例 #1
0
ファイル: LiteObjectMgr.cpp プロジェクト: Arc0re/lithtech
void CLiteObjectMgr::AddObject(GameBaseLite *pObject)
{
	if (!pObject)
	{
		ASSERT(!"NULL lite object insertion encountered");
		return;
	}

	// Add it to the name map
	if (FindObjectByName(pObject->GetName()) != 0)
	{
		Warn("Duplicate lite object name %s encountered", pObject->GetName());
		if (IsObjectInList(m_aActiveObjects, pObject) ||
			IsObjectInList(m_aInactiveObjects, pObject))
		{
			ASSERT(!"Double-insertion encountered in lite object mgr");
			return;
		}
	}
	m_aNameMap[pObject->GetName()] = pObject;

	// Add it to the proper list
	if (pObject->IsActive())
		AddActiveObject(pObject);
	else
		AddInactiveObject(pObject);

	// Queue up an initial update
	m_aInitialUpdateObjects.push_back(pObject);

	// Your serialization IDs are dirty
	SetDirty(eDirty_SerializeIDs);
}
コード例 #2
0
//AddingMask
int AddStrModernMaskToList(DWORD maskID, char * szStr, char * objectName,  ModernMaskList * mmTemplateList, void * pObjectList)
{
    ModernMask mm={0};
    if (!szStr || !mmTemplateList) return -1;
    if (ParseToModernMask(&mm,szStr)) return -1;
    mm.ObjectID=(void*) FindObjectByName(objectName, OT_ANY, (SKINOBJECTSLIST*) pObjectList);
	mm.MaskID=maskID;
    return AddModernMaskToList(&mm,mmTemplateList);    
}
コード例 #3
0
ファイル: SceneUtil.cpp プロジェクト: 2asoft/xray
bool EScene::FindDuplicateName()
{
// find duplicate name
    SceneToolsMapPairIt _I = m_SceneTools.begin();
    SceneToolsMapPairIt _E = m_SceneTools.end();
    for (; _I!=_E; _I++){
        ESceneCustomOTool* mt = dynamic_cast<ESceneCustomOTool*>(_I->second);
        if (mt){
        	ObjectList& lst = mt->GetObjects(); 
            for(ObjectIt _F = lst.begin();_F!=lst.end();_F++)
                if (FindObjectByName((*_F)->Name, *_F)){
                    ELog.DlgMsg(mtError,"Duplicate object name already exists: '%s'",(*_F)->Name);
                    return true;
                }
        }
    }
    return false;
}
コード例 #4
0
ファイル: SceneIO.cpp プロジェクト: AntonioModer/xray-16
bool EScene::Load(LPCSTR map_name, bool bUndo)
{
    u32 version = 0;

	if (!map_name||(0==map_name[0])) return false;

    xr_string 		full_name;
    full_name 		= map_name;

	ELog.Msg( mtInformation, "EScene: loading '%s'", map_name);
    if (FS.exist(full_name.c_str()))
    {
        CTimer T; T.Start();
            
        // read main level
        IReader* F 	= FS.r_open(full_name.c_str()); VERIFY(F);
        // Version
        R_ASSERT	(F->r_chunk(CHUNK_VERSION, &version));
        if (version!=CURRENT_FILE_VERSION)
        {
            ELog.DlgMsg( mtError, "EScene: unsupported file version. Can't load Level.");
            UI->UpdateScene();
            FS.r_close(F);
            return false;
        }

        // Lev. ops.
        IReader* LOP = F->open_chunk(CHUNK_LEVELOP);
        if (LOP)
        {
	        m_LevelOp.Read	(*LOP);
        	LOP->close		();
        }else
        {
			ELog.DlgMsg		(mtError, "Skipping old version of level options.\nCheck level options after loading.");
	    }

        //
        if (F->find_chunk(CHUNK_CAMERA))
        {
        	Fvector hpb, pos;
	        F->r_fvector3	(hpb);
    	    F->r_fvector3	(pos);
            EDevice.m_Camera.Set(hpb,pos);
			EDevice.m_Camera.SetStyle(EDevice.m_Camera.GetStyle());
        }

	    if (F->find_chunk(CHUNK_TOOLS_GUID))
        {
		    F->r			(&m_GUID,sizeof(m_GUID));
        }

        if (F->find_chunk(CHUNK_LEVEL_TAG))
        {
            F->r_stringZ	(m_OwnerName);
            F->r			(&m_CreateTime,sizeof(m_CreateTime));
        }else
        {
            m_OwnerName		= "";
            m_CreateTime	= 0;
        }

        DWORD obj_cnt 		= 0;

        if (F->find_chunk(CHUNK_OBJECT_COUNT))
        	obj_cnt 		= F->r_u32();

        SPBItem* pb 		= UI->ProgressStart(obj_cnt,"Loading objects...");
        ReadObjectsStream	(*F,CHUNK_OBJECT_LIST,OnLoadAppendObject,pb);
        UI->ProgressEnd		(pb);

        SceneToolsMapPairIt _I = m_SceneTools.begin();
        SceneToolsMapPairIt _E = m_SceneTools.end();
        for (; _I!=_E; ++_I)
        {
            if (_I->second)
            {
			    IReader* chunk 		= F->open_chunk(CHUNK_TOOLS_DATA+_I->first);
            	if (chunk){
	                _I->second->LoadStream(*chunk);
    	            chunk->close	();
                }else{
                    if (!bUndo && _I->second->IsEnabled() && (_I->first!=OBJCLASS_DUMMY))
                    {
                        LoadLevelPart	(_I->second,LevelPartName(map_name,_I->first).c_str());
                    }
                }
            }
		}
        
        // snap list
        if (F->find_chunk(CHUNK_SNAPOBJECTS))
        {
        	shared_str 	buf;
            int cnt 	= F->r_u32();
            if (cnt)
            {
                for (int i=0; i<cnt; ++i)
                {
                    F->r_stringZ		(buf);
                    CCustomObject* 	O = FindObjectByName(buf.c_str(),OBJCLASS_SCENEOBJECT);
                    if (!O)
                    	ELog.Msg(mtError,"EScene: Can't find snap object '%s'.",buf.c_str());

                    else
                    m_ESO_SnapObjects.push_back(O);
                }
            }
            UpdateSnapList();
        }

        Msg("EScene: %d objects loaded, %3.2f sec", ObjCount(), T.GetElapsed_sec() );

    	UI->UpdateScene(true); 

		FS.r_close(F);

        SynchronizeObjects();

	    if (!bUndo)
        	m_RTFlags.set(flRT_Unsaved|flRT_Modified,FALSE);
        
		return true;
    }else
    {
    	ELog.Msg(mtError,"Can't find file: '%s'",map_name);
    }
	return false;
}
コード例 #5
0
ファイル: SceneIO.cpp プロジェクト: AntonioModer/xray-16
//----------------------------------------------------
bool EScene::LoadLTX(LPCSTR map_name, bool bUndo)
{
    DWORD version = 0;
	if (!map_name||(0==map_name[0])) return false;

    xr_string 		full_name;
    full_name 		= map_name;

	ELog.Msg( mtInformation, "EScene: loading '%s'", map_name);
    if (FS.exist(full_name.c_str()))
    {
        CTimer T; T.Start();

        // lock main level
		CInifile	ini(full_name.c_str());
        version 	= ini.r_u32("version","value");

        if (version!=CURRENT_FILE_VERSION)
        {
            ELog.DlgMsg( mtError, "EScene: unsupported file version. Can't load Level.");
            UI->UpdateScene();
            return false;
        }

        m_LevelOp.ReadLTX	(ini);

       	Fvector hpb, pos;
        pos					= ini.r_fvector3("camera","pos");
        hpb					= ini.r_fvector3("camera","hpb");
        EDevice.m_Camera.Set(hpb,pos);
        EDevice.m_Camera.SetStyle(EDevice.m_Camera.GetStyle());
		EDevice.m_Camera.SetStyle(EDevice.m_Camera.GetStyle());

        m_GUID.LoadLTX			(ini,"guid","guid");

		m_OwnerName				= ini.r_string("level_tag","owner");
        m_CreateTime			= ini.r_u32("level_tag","create_time");


        SceneToolsMapPairIt _I 	= m_SceneTools.begin();
        SceneToolsMapPairIt _E 	= m_SceneTools.end();
        for (; _I!=_E; ++_I)
        {
            if (_I->second)
            {
                {
                    if (!bUndo && _I->second->IsEnabled() && (_I->first!=OBJCLASS_DUMMY))
                    {
                        xr_string fn 		 = LevelPartName(map_name, _I->first).c_str();
                        LoadLevelPartLTX	(_I->second, fn.c_str());
                    }
                }
            }
		}

        if(ini.section_exist("snap_objects"))
        {
			CInifile::Sect& S 		= ini.r_section("snap_objects");
            CInifile::SectCIt Si 	= S.Data.begin();
            CInifile::SectCIt Se 	= S.Data.end();
            for(;Si!=Se; ++Si)
            {
                CCustomObject* 	O = FindObjectByName(Si->first.c_str(),OBJCLASS_SCENEOBJECT);
                if (!O)
                    ELog.Msg(mtError,"EScene: Can't find snap object '%s'.",Si->second.c_str());
                else
                	m_ESO_SnapObjects.push_back(O);
            }
            UpdateSnapList();
        }

        Msg("EScene: %d objects loaded, %3.2f sec", ObjCount(), T.GetElapsed_sec() );

    	UI->UpdateScene(true);

        SynchronizeObjects();

	    if (!bUndo)
        	m_RTFlags.set(flRT_Unsaved|flRT_Modified,FALSE);
        
		return true;
    }else
    {
    	ELog.Msg(mtError,"Can't find file: '%s'",map_name);
    }
	return false;
}
コード例 #6
0
ファイル: SceneIO.cpp プロジェクト: AntonioModer/xray-16
bool EScene::ReadObjectsStream(IReader& F, u32 chunk_id, TAppendObject on_append, SPBItem* pb)
{
	R_ASSERT			(on_append);
	bool bRes 			= true;
    IReader* OBJ 		= F.open_chunk(chunk_id);
    if (OBJ)
    {
        IReader* O   	= OBJ->open_chunk(0);
        for (int count=1; O; ++count)
        {
            CCustomObject* obj	=NULL;
            if (ReadObjectStream(*O, obj))
            {
                LPCSTR obj_name = obj->Name;
                CCustomObject* existing = FindObjectByName(obj_name,obj->ClassID);
                if(existing)
                {
                	if(g_frmConflictLoadObject->m_result!=2 && g_frmConflictLoadObject->m_result!=4 && g_frmConflictLoadObject->m_result!=6)
                    {
                        g_frmConflictLoadObject->m_existing_object 	= existing;
                        g_frmConflictLoadObject->m_new_object 		= obj;
                        g_frmConflictLoadObject->Prepare			();
                        g_frmConflictLoadObject->ShowModal			();
                    }
                    switch(g_frmConflictLoadObject->m_result)
                    {
                    	case 1: //Overwrite
                    	case 2: //Overwrite All
                        {
                           bool res = RemoveObject		(existing, true, true);
							if(!res)
                            	Msg("! RemoveObject [%s] failed", existing->Name);
                             else
                             	xr_delete(existing);
                        }break;
                    	case 3: //Insert new
                    	case 4: //Insert new All
                        {
                            string256 				buf;
    						GenObjectName			(obj->ClassID, buf, obj->Name);
    						obj->Name				= buf;
                        }break;
                    	case 0: //Cancel
                    	case 5: //Skip
                    	case 6: //Skip All
                        {
                        	xr_delete(obj);
                        }break;
                    }
                }
            	if (obj && !on_append(obj))
                	xr_delete(obj);}
            else
            	bRes = false;

            O->close	();
            O 			= OBJ->open_chunk(count);

            if (pb)
            pb->Inc();
        }
        OBJ->close();
    }
    return bRes;
}
コード例 #7
0
ファイル: SceneIO.cpp プロジェクト: AntonioModer/xray-16
bool EScene::ReadObjectsLTX(CInifile& ini,  LPCSTR sect_name_parent, LPCSTR sect_name_prefix, TAppendObject on_append, SPBItem* pb)
{
	string128			buff;
	R_ASSERT			(on_append);
	sprintf				(buff, "%s_count", sect_name_prefix);
    u32 count			= ini.r_u32(sect_name_parent, buff);
	bool bRes 			= true;

	for(u32 i=0; i<count; ++i)
    {
    	sprintf				(buff, "%s_%s_%d", sect_name_parent, sect_name_prefix, i);
        CCustomObject* obj	= NULL;

		if(ReadObjectLTX(ini, buff, obj))
        {
            LPCSTR obj_name = obj->Name;
            CCustomObject* existing = FindObjectByName(obj_name,obj->ClassID);
            if(existing)
            {

                if(g_frmConflictLoadObject->m_result!=2 && g_frmConflictLoadObject->m_result!=4 && g_frmConflictLoadObject->m_result!=6)
                {
                    g_frmConflictLoadObject->m_existing_object 	= existing;
                    g_frmConflictLoadObject->m_new_object 		= obj;
                    g_frmConflictLoadObject->Prepare			();
                    g_frmConflictLoadObject->ShowModal			();
                }
                switch(g_frmConflictLoadObject->m_result)
                {
                    case 1: //Overwrite
                    case 2: //Overwrite All
                    {
                       bool res = RemoveObject		(existing, true, true);
                        if(!res)
                            Msg("! RemoveObject [%s] failed", existing->Name);
                         else
                            xr_delete(existing);
                    }break;
                    case 3: //Insert new
                    case 4: //Insert new All
                    {
                        string256 				buf;
                        GenObjectName			(obj->ClassID, buf, obj->Name);
                        obj->Name				= buf;
                    }break;
                    case 0: //Cancel
                    case 5: //Skip
                    case 6: //Skip All
                    {
                        xr_delete(obj);
                    }break;
                } //switch
            } //if exist
            if (obj && !on_append(obj))
                xr_delete(obj);}
        
        else
        	bRes = false;

        if (pb)
			pb->Inc();
    }
    return bRes;
}