コード例 #1
0
bool SceneLoader::Load(SECore::Scene* scene, const TCHAR* filename)
{
	bool ret = false;
	Json::Value root;
	CHECK(scene);
	CHECK(LoadJsonFromFile(filename, root));

	if (root.isMember("Config"))
	{
		const Json::Value& configRoot = root["Config"];
		if (configRoot.isMember("ShowGizmo"))
			scene->GetConfig()->EnableGizmo(configRoot["ShowGizmo"].asBool());
		if (configRoot.isMember("AmbientColor"))
		{
			scene->GetConfig()->SetAmbientColor(Json2Color(configRoot["AmbientColor"]));
		}
	}

	CHECK(root.isMember("Entities"));
	CHECK(root["Entities"].isArray());

	size_t entityCount = root["Entities"].size();

	for (size_t i = 0; i < entityCount; ++i)
	{
		SECore::Scene::Entity* entity = scene->CreateEntity();
		const Json::Value& entityRoot = root["Entities"][i];

		if (entityRoot.isMember("Prefab"))
		{
			CString filename = MStr2WStr(entityRoot["Prefab"].asCString());
			Json::Value prefab;
			LoadJsonFromFile(filename, prefab);
			LoadEntity(scene->GetCore(), entity, prefab);
		}
		
		LoadEntity(scene->GetCore(), entity, entityRoot);
	}

	size_t lightCount = root["Lights"].size();
	for (size_t i = 0; i < lightCount; i++)
	{
		LoadLight(scene, root["Lights"][i]);
	}

	ret = true;
Exit0:
	return ret;
}
コード例 #2
0
ファイル: atticclient.cpp プロジェクト: danielsiders/libattic
int Client::Initialize() {
    int status = ret::A_OK;
    if(!status)
        status = LoadAppFromFile();
    if(!status)
        status = LoadEntity();
    // Optional
    if(!status)
        LoadPhraseToken();
    return status;
}
コード例 #3
0
void EntityFactory::LoadEntites(const std::string& aEntityRootPath, float aDifficultScale)
{
	myDifficultScale = aDifficultScale;
	XMLReader rootDocument;
	rootDocument.OpenDocument(aEntityRootPath);
	tinyxml2::XMLElement* rootElement = rootDocument.FindFirstChild("root");

	WATCH_FILE(aEntityRootPath, EntityFactory::ReloadEntity);

	for (tinyxml2::XMLElement* e = rootDocument.FindFirstChild(rootElement); e != nullptr;
		e = rootDocument.FindNextElement(e))
	{
		std::string entityPath = "";
		rootDocument.ForceReadAttribute(e, "src", entityPath);
		if (entityPath != "")
		{
			//#ifdef _DEBUG
			//			XMLReader entityReader;
			//			entityReader.OpenDocument(entityPath);
			//			tinyxml2::XMLElement* entityElement;
			//			tinyxml2::XMLElement* rootElement = entityReader.FindFirstChild("root");
			//			if (rootElement == nullptr)
			//			{
			//				entityElement = entityReader.FindFirstChild("Entity");
			//			}
			//			else
			//			{
			//				entityElement = entityReader.FindFirstChild(rootElement, "Entity");
			//			}
			//
			//			std::string entityName;
			//			entityReader.ForceReadAttribute(entityElement, "name", entityName);
			//			myEntityTags[entityName] = entityPath;
			//			entityReader.CloseDocument();
			//#else
			LoadEntity(entityPath, aDifficultScale);
			WATCH_FILE(entityPath, EntityFactory::ReloadEntity);
			//#endif
		}
	}

	rootDocument.CloseDocument();
}
コード例 #4
0
Area *XMLAreaLoader::LoadArea(tinyxml2::XMLElement *element, WorldGameState *world)
{
	int width = atoi(element->Attribute("width"));
	int height = atoi(element->Attribute("height"));
	Area *result = new Area(Vec2(width, height), world);
	
	// Get player start position/direction
	auto startPosElement = element->FirstChildElement("startPos");
	auto startDirElement = element->FirstChildElement("startDir");
	if (startPosElement && startDirElement)
	{
		Vec2 startPos = LoadVec2(startPosElement);
		DIR startDir = (DIR)atoi(startDirElement->GetText());
		result->SetStartPosAndDir(startPos, startDir);
	}
		

	tinyxml2::XMLElement *blockElement = element->FirstChildElement("Blocks")->FirstChildElement("Block");
	int iBlock = 0;
	while (blockElement != NULL)
	{
		if (iBlock >= width*height)
			throw std::exception();
		LoadBlock(result->GetBlock(iBlock % width, iBlock / width), blockElement);

		blockElement = blockElement->NextSiblingElement("Block");
		iBlock++;
	}

	tinyxml2::XMLElement *entityElement = element->FirstChildElement("Entities")->FirstChildElement("Entity");
	while (entityElement)
	{
		result->AddEntity(LoadEntity(entityElement));
		entityElement = entityElement->NextSiblingElement("Entity");
	}

	return result;
}
コード例 #5
0
ファイル: StartProcess.cpp プロジェクト: gthgame/gth
int GTH::InitStartProcess()
{
	int i, ret;


	
	LoadConfig( "select.cfg" );
	

	
    
	if(m_mapInfos[0].fogColor)
		g_timeSystem->SetFogEnable();
	else
		g_timeSystem->SetFogDisable();

	for( i = 0 ; i < m_numMapInfos ; i++ )
	{
		ret = LoadMap( m_mapInfos[ i ].mapName );
		if( !ret )	return false;
	}

	 
	g_move->SetWorldModel( m_worldBSPs[ m_currWorld ] );
	g_entityMng->SetWorldModel( m_worldBSPs[ m_currWorld ] );
	g_itemMng->SetWorldModel( m_worldBSPs[ m_currWorld ] );
	g_effectMng->SetWorldModel( m_worldBSPs[ m_currWorld ] );
	g_cursor->SetWorldModel( m_worldBSPs[ m_currWorld ] );
	 
	g_camera .SetWorldModel ( m_worldBSPs[ m_currWorld ] );
	
	ret = LoadMDLClasses( &m_mapInfos[0] );
	if( !ret )	return false;
	
	ret = LoadEntity( m_mapInfos[0].objectName );
	if( !ret )	return false;
	
	for( i = 0 ; i < m_numWorldBSPs ; i++ )
		m_worldBSPs[ i ]->Initialize( m_mapInfos[ 0 ].worldVisible );

	 

	g_entityMng->Initialize( m_mapInfos[ 0 ].modelVisible );

	 

	g_itemMng->Initialize( m_mapInfos[ 0 ].itemVisible );

	 

	g_effectMng->Initialize( m_mapInfos[ 0 ].itemVisible );
	
	g_cursor->Initialize();
	m_MDLMng->Initialize();
	
	g_camera.Reset();
	 


	m_frameFlag = 0;

	return( S_OK );
}