Ejemplo n.º 1
0
QStringList GlobalConfig::fetch(const QString &baseURL)
{
    m_baseURL = baseURL;
    if(!m_baseURL.endsWith('/'))
      m_baseURL += '/';

    QStringList configFiles;
    QUrl url(m_baseURL + "config.txt");

    if (url.scheme() == "file")
    {
        QFileInfo cfr(url.toLocalFile());
        if (cfr.exists())
        {
            configFiles << cfr.absoluteFilePath();
        }
        else
        {
            qCritical() << "local config file does not exist" <<  cfr.absoluteFilePath();    
        }
        return configFiles;
    }
    // remote config file
    else if (url.scheme() == "http" || url.scheme() == "ftp")
    {
        QFileInfo cfr(Settings::instance().downloadDir()+"/config-remote.txt");
        qDebug() << "Check if a copy of the remote config file is available at" << cfr.absoluteFilePath() << (cfr.exists() ? "... found" : "... not found");
        if (cfr.exists())
        {
            configFiles << cfr.absoluteFilePath();
        }
        else
        {
            QFileInfo cfi(Settings::instance().downloadDir()+"/config.txt");
            bool ret = Downloader::instance()->fetch(url,cfi.absoluteFilePath());
            qDebug() << "download remote config file from" <<  url << "to" << cfi.absoluteFilePath() << "..." << (ret ? "okay" : "failure") ;
            if (ret)
                configFiles << cfi.absoluteFilePath();
            else 
                return configFiles;
        }

        QFileInfo fi(Settings::instance().downloadDir()+"/config-local.txt");
        qDebug() << "Check if a local config file is available at" << fi.absoluteFilePath() << (fi.exists() ? "... found" : "... not found");
        if (fi.exists())
            configFiles << fi.absoluteFilePath();

    }
    qDebug() << "using config file(s)" << configFiles;
    
    return configFiles;
}
Ejemplo n.º 2
0
const LLMatrix4 &LLViewerCamera::getModelview() const
{
	LLMatrix4 cfr(OGL_TO_CFR_ROTATION);
	getMatrixToLocal(mModelviewMatrix);
	mModelviewMatrix *= cfr;
	return mModelviewMatrix;
}
Ejemplo n.º 3
0
//m_objectType
bool CGameData::LoadAssetFile(std::string filename){
  CLog *pLog = CLog::Instance();
  
  //read assets.dat file
  CFileReader cfr(filename);
  if(cfr.IsValid() == false)
    return false; //file is invalid or contains no usable data

  //validate asset data and add to appropriate vectors
  std::string parameter;
  std::string assetType;
  GAME_OBJECT_TYPE got;

  for(int i = 0; i < cfr.GetNumberOfLines(); ++i){

    if(cfr.GetNumberOfTermsFromLine(i) > 1){
      assetType = cfr.GetTerm(cfr.GetLineFromFile(i), 1);
      
      //ignore these asset types
      if(assetType == "graphicfile" || assetType == "sprite" || assetType == "mesh" || assetType == "soundfile"){
        //do nothing..ignore these assets
      }
    
      //this should be a game object type
      else{
        if(cfr.GetNumberOfTermsFromLine(i) == 6){ // need 6 parameters to be valid
          got.name = cfr.GetTerm(cfr.GetLineFromFile(i), 1);
          parameter = cfr.GetTerm(cfr.GetLineFromFile(i), 2);
          got.objectID = atoi(parameter.c_str());
          parameter = cfr.GetTerm(cfr.GetLineFromFile(i), 3);
          got.spriteID = atoi(parameter.c_str());
          parameter = cfr.GetTerm(cfr.GetLineFromFile(i), 4);
          got.badSpriteID = atoi(parameter.c_str());
          parameter = cfr.GetTerm(cfr.GetLineFromFile(i), 5);
          got.layer = atoi(parameter.c_str());
          parameter = cfr.GetTerm(cfr.GetLineFromFile(i), 6);
          got.radius = atof(parameter.c_str());
          //pLog->Log("Object added",got.name, got.objectID);
          m_objectType.push_back(got);
        }        
      }
    }
  }
  
  //log results of load
//  pLog->Log("Number of game object types",  m_objectType.size());

  return true;
}
bool CAudioManager::LoadAssetFile(std::string filename){
  CLog *pLog = CLog::Instance();

  //read assets.dat file
  CFileReader cfr(filename);
  if(cfr.IsValid() == false)
    return false; //file is invalid or contains no usable data

  //validate asset data and add to appropriate vectors
  std::string parameter;
  std::string assetType;
  SOUND_FILE_DATA     tempSound;

  for(int i = 0; i < cfr.GetNumberOfLines(); ++i){

    //process only lines with 2 or more terms
    if(cfr.GetNumberOfTermsFromLine(i) > 1){
      assetType = cfr.GetTerm(cfr.GetLineFromFile(i), 1);
     
      if(assetType == "soundfile" && cfr.GetNumberOfTermsFromLine(i) == 4){
        parameter = cfr.GetTerm(cfr.GetLineFromFile(i), 2);//sound ID
        tempSound.soundID = atoi(parameter.c_str());
        parameter = cfr.GetTerm(cfr.GetLineFromFile(i), 3);//filename
        tempSound.filename = parameter;
        parameter = cfr.GetTerm(cfr.GetLineFromFile(i), 4);//description
        tempSound.description = parameter;
        m_assetSoundData.push_back(tempSound);
        pLog->Log("****** soundfile added *******");
        pLog->Log("soundID", tempSound.soundID);
        pLog->Log("filename", tempSound.filename);
        pLog->Log("description", tempSound.description);        
      }
    }
  }

  //load sound information
  for(int i = 0; i < m_assetSoundData.size(); ++i){
    LoadSample(m_assetSoundData[i].soundID,
               "assets\\sounds\\" + m_assetSoundData[i].filename);
    pLog->Log("Loaded into memory", m_assetSoundData[i].filename);
  }

  return true;
}
Ejemplo n.º 5
0
void LLDrawPoolAvatar::renderAvatars(LLVOAvatar* single_avatar, S32 pass)
{
	if (pass == -1)
	{
		for (S32 i = 1; i < getNumPasses(); i++)
		{ //skip foot shadows
			prerender();
			beginRenderPass(i);
			renderAvatars(single_avatar, i);
			endRenderPass(i);
		}

		return;
	}

	if (mDrawFace.empty() && !single_avatar)
	{
		return;
	}

	LLVOAvatar *avatarp;

	if (single_avatar)
	{
		avatarp = single_avatar;
	}
	else
	{
		const LLFace *facep = mDrawFace[0];
		if (!facep->getDrawable())
		{
			return;
		}
		avatarp = (LLVOAvatar *)facep->getDrawable()->getVObj().get();
	}

    if (avatarp->isDead() || avatarp->mDrawable.isNull())
	{
		return;
	}

	if (!single_avatar && !avatarp->isFullyLoaded())
	{
		if (pass == 0 && (!gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_PARTICLES) || LLViewerPartSim::getMaxPartCount() <= 0))
		{
			// debug code to draw a sphere in place of avatar
			gGL.getTexUnit(0)->bind(LLViewerFetchedTexture::sWhiteImagep);
			gGL.setColorMask(true, true);
			LLVector3 pos = avatarp->getPositionAgent();
			gGL.color4f(1.0f, 1.0f, 1.0f, 0.7f);

			gGL.pushMatrix();
			gGL.translatef((F32)(pos.mV[VX]), (F32)(pos.mV[VY]), (F32)(pos.mV[VZ]));
			gGL.scalef(0.15f, 0.15f, 0.3f);

			gSphere.renderGGL();

			gGL.popMatrix();
			gGL.setColorMask(true, false);
		}
		// don't render please
		return;
	}

	BOOL impostor = avatarp->isImpostor() && !single_avatar;

	if (impostor && pass != 0)
	{ //don't draw anything but the impostor for impostored avatars
		return;
	}
	
	if (pass == 0 && !impostor && LLPipeline::sUnderWaterRender)
	{ //don't draw foot shadows under water
		return;
	}

	if (pass == 0)
	{
		if (!LLPipeline::sReflectionRender)
		{
			LLVOAvatar::sNumVisibleAvatars++;
		}

		if (impostor)
		{
			if (LLPipeline::sRenderDeferred && !LLPipeline::sReflectionRender &&
				avatarp->mImpostor.isComplete()) 
			{
				if (normal_channel > -1)
				{
					avatarp->mImpostor.bindTexture(2, normal_channel);
				}
				if (specular_channel > -1)
				{
					avatarp->mImpostor.bindTexture(1, specular_channel);
				}
			}
			avatarp->renderImpostor(LLColor4U(255,255,255,255), sDiffuseChannel);
		}
		return;
	}

	if (single_avatar && avatarp->mSpecialRenderMode >= 1) // 1=anim preview, 2=image preview,  3=morph view
	{
		gPipeline.enableLightsAvatarEdit(LLColor4(.5f, .5f, .5f, 1.f));
	}
	
	if (pass == 1)
	{
		// render rigid meshes (eyeballs) first
		avatarp->renderRigid();
		return;
	}
	
	if (pass == 3)
	{
		if (is_deferred_render)
		{
			renderDeferredRiggedSimple(avatarp);
		}
		else
		{
			renderRiggedSimple(avatarp);
		}
		return;
	}

	if (pass == 4)
	{
		if (is_deferred_render)
		{
			renderDeferredRiggedBump(avatarp);
		}
		else
		{
			renderRiggedFullbright(avatarp);
		}

		return;
	}

	if (pass == 5)
	{
		renderRiggedShinySimple(avatarp);
		return;
	}

	if (pass == 6)
	{
		renderRiggedFullbrightShiny(avatarp);
		return;
	}

	if (pass >= 7 && pass < 9)
	{
		LLGLEnable blend(GL_BLEND);

		gGL.setColorMask(true, true);
		gGL.blendFunc(LLRender::BF_SOURCE_ALPHA,
					  LLRender::BF_ONE_MINUS_SOURCE_ALPHA,
					  LLRender::BF_ZERO,
					  LLRender::BF_ONE_MINUS_SOURCE_ALPHA);

		if (pass == 7)
		{
			renderRiggedAlpha(avatarp);
			return;
		}

		if (pass == 8)
		{
			renderRiggedFullbrightAlpha(avatarp);
			return;
		}
	}

	if (pass == 9)
	{
		LLGLEnable blend(GL_BLEND);
		LLGLDisable test(GL_ALPHA_TEST);
		gGL.flush();

		LLGLEnable polyOffset(GL_POLYGON_OFFSET_FILL);
		glPolygonOffset(-1.0f, -1.0f);
		gGL.setSceneBlendType(LLRender::BT_ADD);

		LLGLDepthTest depth(GL_TRUE, GL_FALSE);
		gGL.setColorMask(false, true);

		renderRiggedGlow(avatarp);
		gGL.setColorMask(true, false);
		gGL.setSceneBlendType(LLRender::BT_ALPHA);
		return;
	}

	if (sShaderLevel > 0)
	{
		gAvatarMatrixParam = sVertexProgram->mUniform[LLViewerShaderMgr::AVATAR_MATRIX];
	}
    
	if (sShaderLevel >= SHADER_LEVEL_CLOTH)
	{
		LLMatrix4 rot_mat;
		LLViewerCamera::getInstance()->getMatrixToLocal(rot_mat);
		LLMatrix4 cfr(OGL_TO_CFR_ROTATION);
		rot_mat *= cfr;
		
		LLVector4 wind;
		wind.setVec(avatarp->mWindVec);
		wind.mV[VW] = 0;
		wind = wind * rot_mat;
		wind.mV[VW] = avatarp->mWindVec.mV[VW];

		sVertexProgram->vertexAttrib4fv(LLViewerShaderMgr::AVATAR_WIND, wind.mV);
		F32 phase = -1.f * (avatarp->mRipplePhase);

		F32 freq = 7.f + (noise1(avatarp->mRipplePhase) * 2.f);
		LLVector4 sin_params(freq, freq, freq, phase);
		sVertexProgram->vertexAttrib4fv(LLViewerShaderMgr::AVATAR_SINWAVE, sin_params.mV);

		LLVector4 gravity(0.f, 0.f, -CLOTHING_GRAVITY_EFFECT, 0.f);
		gravity = gravity * rot_mat;
		sVertexProgram->vertexAttrib4fv(LLViewerShaderMgr::AVATAR_GRAVITY, gravity.mV);
	}

	if (!single_avatar || avatarp == single_avatar)
	{
		avatarp->renderSkinned(AVATAR_RENDER_PASS_SINGLE);
	}
}
Ejemplo n.º 6
0
void LLDrawPoolAvatar::renderAvatars(LLVOAvatar* single_avatar, S32 pass)
{
	LLFastTimer t(FTM_RENDER_AVATARS);

	if (pass == -1)
	{
		for (S32 i = 1; i < getNumPasses(); i++)
		{ //skip foot shadows
			prerender();
			beginRenderPass(i);
			renderAvatars(single_avatar, i);
			endRenderPass(i);
		}

		return;
	}

	if (mDrawFace.empty() && !single_avatar)
	{
		return;
	}

	LLVOAvatar *avatarp;

	if (single_avatar)
	{
		avatarp = single_avatar;
	}
	else
	{
		const LLFace *facep = mDrawFace[0];
		if (!facep->getDrawable())
		{
			return;
		}
		avatarp = (LLVOAvatar *)facep->getDrawable()->getVObj().get();
	}

    if (avatarp->isDead() || avatarp->mDrawable.isNull())
	{
		return;
	}

	if (!single_avatar && !avatarp->isFullyLoaded() )
	{
		if (pass==0 && (!gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_PARTICLES) || LLViewerPartSim::getMaxPartCount() <= 0))
		{
			// debug code to draw a sphere in place of avatar
			gGL.getTexUnit(0)->bind(LLViewerFetchedTexture::sWhiteImagep);
			gGL.setColorMask(true, true);
			LLVector3 pos = avatarp->getPositionAgent();
			gGL.color4f(1.0f, 1.0f, 1.0f, 0.7f);
			
			gGL.pushMatrix();	 
			gGL.translatef((F32)(pos.mV[VX]),	 
						   (F32)(pos.mV[VY]),	 
							(F32)(pos.mV[VZ]));	 
			 gGL.scalef(0.15f, 0.15f, 0.3f);

			 gSphere.renderGGL();

			 gGL.popMatrix();
			 gGL.setColorMask(true, false);
		}
		// don't render please
		return;
	}

	BOOL impostor = avatarp->isImpostor() && !single_avatar;

	if (impostor && pass != 0)
	{ //don't draw anything but the impostor for impostored avatars
		return;
	}
	
	if (pass == 0 && !impostor && LLPipeline::sUnderWaterRender)
	{ //don't draw foot shadows under water
		return;
	}

	if (pass == 0)
	{
		if (!LLPipeline::sReflectionRender)
		{
			LLVOAvatar::sNumVisibleAvatars++;
		}

		if (impostor)
		{
			if (LLPipeline::sRenderDeferred && !LLPipeline::sReflectionRender && avatarp->mImpostor.isComplete()) 
			{
				if (normal_channel > -1)
				{
					avatarp->mImpostor.bindTexture(2, normal_channel);
				}
				if (specular_channel > -1)
				{
					avatarp->mImpostor.bindTexture(1, specular_channel);
				}
			}
			avatarp->renderImpostor(LLColor4U(255,255,255,255), sDiffuseChannel);
		}
		//else if (gPipeline.hasRenderDebugFeatureMask(LLPipeline::RENDER_DEBUG_FEATURE_FOOT_SHADOWS) && !LLPipeline::sRenderDeferred)
		//{
		//	avatarp->renderFootShadows();	
		//}
		return;
	}

	llassert(LLPipeline::sImpostorRender || !avatarp->isVisuallyMuted());

	/*if (single_avatar && avatarp->mSpecialRenderMode >= 1) // 1=anim preview, 2=image preview,  3=morph view
	{
		gPipeline.enableLightsAvatarEdit(LLColor4(.5f, .5f, .5f, 1.f));
	}*/
	
	if (pass == 1)
	{
		// render rigid meshes (eyeballs) first
		avatarp->renderRigid();
		return;
	}

	if (pass == 3)
	{
		if (is_deferred_render)
		{
			renderDeferredRiggedSimple(avatarp);
		}
		else
		{
			renderRiggedSimple(avatarp);
			if (LLPipeline::sRenderDeferred)
			{ //render "simple" materials
				renderRigged(avatarp, RIGGED_MATERIAL);
				renderRigged(avatarp, RIGGED_MATERIAL_ALPHA_MASK);
				renderRigged(avatarp, RIGGED_MATERIAL_ALPHA_EMISSIVE);
				renderRigged(avatarp, RIGGED_NORMMAP);
				renderRigged(avatarp, RIGGED_NORMMAP_MASK);
				renderRigged(avatarp, RIGGED_NORMMAP_EMISSIVE);	
				renderRigged(avatarp, RIGGED_SPECMAP);
				renderRigged(avatarp, RIGGED_SPECMAP_MASK);
				renderRigged(avatarp, RIGGED_SPECMAP_EMISSIVE);
				renderRigged(avatarp, RIGGED_NORMSPEC);
				renderRigged(avatarp, RIGGED_NORMSPEC_MASK);
				renderRigged(avatarp, RIGGED_NORMSPEC_EMISSIVE);
			}
		}
		return;
	}

	if (pass == 4)
	{
		if (is_deferred_render)
		{
			renderDeferredRiggedBump(avatarp);
		}
		else
		{
			renderRiggedFullbright(avatarp);
		}

		return;
	}

	if (is_deferred_render && pass >= 5 && pass <= 21)
	{
		S32 p = pass-5;
		if (p != 1 &&
			p != 5 &&
			p != 9 &&
			p != 13)
		{
			renderDeferredRiggedMaterial(avatarp, p);
		}
		return;
	}
	if (pass == 5)
	{
		renderRiggedShinySimple(avatarp);
		return;
	}

	if (pass == 6)
	{
		renderRiggedFullbrightShiny(avatarp);
		return;
	}

	if (pass >= 7 && pass < 13)
	{
		if (pass == 7)
		{
			renderRiggedAlpha(avatarp);
			if (LLPipeline::sRenderDeferred && !is_post_deferred_render)
			{ //render transparent materials under water
				LLGLEnable blend(GL_BLEND);
				gGL.setColorMask(true, true);
				gGL.blendFunc(LLRender::BF_SOURCE_ALPHA,
								LLRender::BF_ONE_MINUS_SOURCE_ALPHA,
								LLRender::BF_ZERO,
								LLRender::BF_ONE_MINUS_SOURCE_ALPHA);
				renderRigged(avatarp, RIGGED_MATERIAL_ALPHA);
				renderRigged(avatarp, RIGGED_SPECMAP_BLEND);
				renderRigged(avatarp, RIGGED_NORMMAP_BLEND);
				renderRigged(avatarp, RIGGED_NORMSPEC_BLEND);
				gGL.setSceneBlendType(LLRender::BT_ALPHA);
				gGL.setColorMask(true, false);
			}
			return;
		}

		if (pass == 8)
		{
			renderRiggedFullbrightAlpha(avatarp);
			return;
		}
		if (LLPipeline::sRenderDeferred && is_post_deferred_render)
		{
			S32 p = 0;
			switch (pass)
			{
			case 9: p = 1; break;
			case 10: p = 5; break;
			case 11: p = 9; break;
			case 12: p = 13; break;
			}
			{
				LLGLEnable blend(GL_BLEND);
				renderDeferredRiggedMaterial(avatarp, p);
			}
			return;
		}
		else if (pass == 9)
		{
			renderRiggedGlow(avatarp);
			return;
		}
	}

	if (pass == 13)
	{
		renderRiggedGlow(avatarp);

		return;
	}
	
	if ((sShaderLevel >= SHADER_LEVEL_CLOTH))
	{
		LLMatrix4 rot_mat;
		LLViewerCamera::getInstance()->getMatrixToLocal(rot_mat);
		LLMatrix4 cfr(OGL_TO_CFR_ROTATION.getF32ptr());
		rot_mat *= cfr;
		
		LLVector4 wind;
		wind.setVec(avatarp->mWindVec);
		wind.mV[VW] = 0;
		wind = wind * rot_mat;
		wind.mV[VW] = avatarp->mWindVec.mV[VW];

		sVertexProgram->uniform4fv(LLViewerShaderMgr::AVATAR_WIND, 1, wind.mV);
		F32 phase = -1.f * (avatarp->mRipplePhase);

		F32 freq = 7.f + (noise1(avatarp->mRipplePhase) * 2.f);
		LLVector4 sin_params(freq, freq, freq, phase);
		sVertexProgram->uniform4fv(LLViewerShaderMgr::AVATAR_SINWAVE, 1, sin_params.mV);

		LLVector4 gravity(0.f, 0.f, -CLOTHING_GRAVITY_EFFECT, 0.f);
		gravity = gravity * rot_mat;
		sVertexProgram->uniform4fv(LLViewerShaderMgr::AVATAR_GRAVITY, 1, gravity.mV);
	}

	if( !single_avatar || (avatarp == single_avatar) )
	{
		avatarp->renderSkinned(AVATAR_RENDER_PASS_SINGLE);
	}
}
Ejemplo n.º 7
0
bool GlobalConfig::isRemoteConfigAvailable()
{
    QFileInfo cfr(Settings::instance().downloadDir()+"/config-remote.txt");
    return cfr.exists();
}
Ejemplo n.º 8
0
BOOL QToolAlign::findSelectedManipulator(S32 x, S32 y)
{
	mHighlightedAxis = -1;
	mHighlightedDirection = 0;

	LLMatrix4 transform;
	if (LLSelectMgr::getInstance()->getSelection()->getSelectType() == SELECT_TYPE_HUD)
	{
		LLVector4 translation(mBBox.getCenterAgent());
		transform.initRotTrans(mBBox.getRotation(), translation);
		LLMatrix4 cfr(OGL_TO_CFR_ROTATION);
		transform *= cfr;
		LLMatrix4 window_scale;
		F32 zoom_level = 2.f * gAgentCamera.mHUDCurZoom;
		window_scale.initAll(LLVector3(zoom_level / LLViewerCamera::getInstance()->getAspect(), zoom_level, 0.f),
							 LLQuaternion::DEFAULT,
							 LLVector3::zero);
		transform *= window_scale;
	}
	else
	{
		transform.initAll(LLVector3(1.f, 1.f, 1.f), mBBox.getRotation(), mBBox.getCenterAgent());

		LLMatrix4 projection_matrix = LLViewerCamera::getInstance()->getProjection();
		LLMatrix4 model_matrix = LLViewerCamera::getInstance()->getModelview();

		transform *= model_matrix;
		transform *= projection_matrix;
	}


	LLRect world_view_rect = gViewerWindow->getWorldViewRectScaled();
	F32 half_width = (F32)world_view_rect.getWidth() / 2.f;
	F32 half_height = (F32)world_view_rect.getHeight() / 2.f;
	LLVector2 manip2d;
	LLVector2 mousePos((F32)x - half_width, (F32)y - half_height);
	LLVector2 delta;

	LLVector3 bbox_scale = mBBox.getMaxLocal() - mBBox.getMinLocal();
	
	for (S32 axis = VX; axis <= VZ; axis++)
	{
		for (F32 direction = -1.0; direction <= 1.0; direction += 2.0)
		{
			LLVector3 axis_vector = LLVector3(0,0,0);
			axis_vector.mV[axis] = direction * bbox_scale.mV[axis] / 2.0;
			
			LLVector4 manipulator_center = 	LLVector4(axis_vector);

			LLVector4 screen_center = manipulator_center * transform;
			screen_center /= screen_center.mV[VW];

			manip2d.setVec(screen_center.mV[VX] * half_width, screen_center.mV[VY] * half_height);

			delta = manip2d - mousePos;

			if (delta.magVecSquared() < MANIPULATOR_SELECT_SIZE * MANIPULATOR_SELECT_SIZE)
			{
				mHighlightedAxis = axis;
				mHighlightedDirection = direction;
				return TRUE;
			}

		}
	}

	return FALSE;
}
Ejemplo n.º 9
0
void CGameData::LoadGameLevelBU(std::string filename){
  CLog *pLog = CLog::Instance();
  
  //read assets.dat file
  CFileReader cfr(filename);
  if(cfr.IsValid() == false)
    return; //file is invalid or contains no usable data

  //validate asset data and add to appropriate vectors
  GAME_OBJECT temp;
  std::string value;
  std::string asset;
  m_level.clear();

  for(int i = 0; i < cfr.GetNumberOfLines(); ++i){
    asset = cfr.GetTerm(cfr.GetLineFromFile(i),1);
    if(asset == "mesh")
      temp.asset = C_MESH;        //mesh
    else if(asset == "splatter")
      temp.asset = C_SPLATTER;    //splatter
    else if(asset == "sprite")
      temp.asset = C_SPRITE;      //sprite
    else if(asset == "player")
      temp.asset = C_PLAYER;      //player
    else if(asset == "worldlimits")
      temp.asset = C_WORLD;       //world
    
    //mesh or splatter
    if (temp.asset == C_MESH || temp.asset == C_SPLATTER){
      value = cfr.GetTerm(cfr.GetLineFromFile(i),2);
      temp.meshID = atoi(value.c_str());
      value = cfr.GetTerm(cfr.GetLineFromFile(i),3);
      temp.meshBadID = atoi(value.c_str());
      value = cfr.GetTerm(cfr.GetLineFromFile(i),4);
      temp.x = atof(value.c_str());
      value = cfr.GetTerm(cfr.GetLineFromFile(i),5);
      temp.y = atof(value.c_str());
      value = cfr.GetTerm(cfr.GetLineFromFile(i),6);
      temp.z = atof(value.c_str());
      value = cfr.GetTerm(cfr.GetLineFromFile(i),7);
      temp.rx = atof(value.c_str());
      value = cfr.GetTerm(cfr.GetLineFromFile(i),8);
      temp.ry = atof(value.c_str());
      value = cfr.GetTerm(cfr.GetLineFromFile(i),9);
      temp.rz = atof(value.c_str());
      temp.alive = true;
      m_level.push_back(temp);
    }

    else if(temp.asset == C_SPRITE){
      value = cfr.GetTerm(cfr.GetLineFromFile(i),2);
      temp.spriteID = atoi(value.c_str());
      value = cfr.GetTerm(cfr.GetLineFromFile(i),3);
      temp.spriteBadID = atoi(value.c_str());
      value = cfr.GetTerm(cfr.GetLineFromFile(i),4);
      temp.left = atoi(value.c_str());
      value = cfr.GetTerm(cfr.GetLineFromFile(i),5);
      temp.top = atoi(value.c_str());
      temp.totalTime = 0.0;
      temp.frameCount = 0;      
      temp.alive = true;
      m_level.push_back(temp);
    }

    else if(temp.asset == C_PLAYER){
      //value = cfr.GetTerm(cfr.GetLineFromFile(i),2);
      //temp.spriteID = atoi(value.c_str());
      value = cfr.GetTerm(cfr.GetLineFromFile(i),3);
      m_playerX = atoi(value.c_str());
      value = cfr.GetTerm(cfr.GetLineFromFile(i),4);
      m_playerY = atoi(value.c_str());
      //temp.alive = true;
      //m_level.push_back(temp);
    }

    else if(temp.asset == C_WORLD){
      //pLog->Log("World found");
      value = cfr.GetTerm(cfr.GetLineFromFile(i),2);
      m_world_left = atof(value.c_str());
      value = cfr.GetTerm(cfr.GetLineFromFile(i),3);
      m_world_top = atof(value.c_str());
      value = cfr.GetTerm(cfr.GetLineFromFile(i),4);
      m_world_right = atof(value.c_str());
      value = cfr.GetTerm(cfr.GetLineFromFile(i),5);
      m_world_bottom = atof(value.c_str());

    }

  }
//pLog->Log("world top", m_world_top);
}
Ejemplo n.º 10
0
void CGameData::LoadGameLevel(std::string filename, CGraphics &con){
  CLog *pLog = CLog::Instance();
  
  //read assets.dat file
  CFileReader cfr(filename);
  if(cfr.IsValid() == false)
    return; //file is invalid or contains no usable data

  //validate asset data and add to appropriate vectors
  GAME_OBJECT temp;
  GRAPHIC_IMAGE gi;
  GAME_OBJECT go;
  GAME_OBJECT_TYPE got;
  std::string value;
  std::string asset;
  m_level.clear();
  unsigned long size = 0;
  CGrandma tempMa;
  //CElf elf;
  //CLandscape land;
  //CCharacter character;
  srand((unsigned)time(NULL));

  for(int i = 0; i < cfr.GetNumberOfLines(); ++i){
    asset = cfr.GetTerm(cfr.GetLineFromFile(i),1);

    if(asset == "sprite")
      temp.asset = C_SPRITE;      //sprite
    else if(asset == "player")
      temp.asset = C_PLAYER;      //player
    else if(asset == "worldlimits")
      temp.asset = C_WORLD;       //world
    else if(asset == "tree1")
      temp.asset = C_TREE1; 
    else if(asset == "tree2")
      temp.asset = C_TREE2; 
    else if(asset == "tree3")
      temp.asset = C_TREE3; 
    
    //mesh or splatter
    //if (temp.asset == C_MESH || temp.asset == C_SPLATTER){
    if(asset == "mesh" || asset == "splatter"){
      if(asset == "mesh")
        temp.asset = C_MESH;        //mesh
      else if(asset == "splatter")
        temp.asset = C_SPLATTER;    //splatter      

      value = cfr.GetTerm(cfr.GetLineFromFile(i),2);
      temp.meshID = atoi(value.c_str());
      value = cfr.GetTerm(cfr.GetLineFromFile(i),3);
      temp.meshBadID = atoi(value.c_str());
      value = cfr.GetTerm(cfr.GetLineFromFile(i),4);
      temp.x = atof(value.c_str());
      value = cfr.GetTerm(cfr.GetLineFromFile(i),5);
      temp.y = atof(value.c_str());
      value = cfr.GetTerm(cfr.GetLineFromFile(i),6);
      temp.z = atof(value.c_str());
      value = cfr.GetTerm(cfr.GetLineFromFile(i),7);
      temp.rx = atof(value.c_str());
      value = cfr.GetTerm(cfr.GetLineFromFile(i),8);
      temp.ry = atof(value.c_str());
      value = cfr.GetTerm(cfr.GetLineFromFile(i),9);
      temp.rz = atof(value.c_str());
      temp.alive = true;
      m_level.push_back(temp);
    }

    //game time
    else if(asset == "time"){
      value = cfr.GetTerm(cfr.GetLineFromFile(i),2);
      m_player.m_time = atoi(value.c_str());
    }

    else if(asset == "player"){// temp.asset == C_PLAYER){
      value = cfr.GetTerm(cfr.GetLineFromFile(i),2);
      if(value == "position"){
        value = cfr.GetTerm(cfr.GetLineFromFile(i),3);
        m_playerX = atoi(value.c_str());
        m_player.go.pos.x = atoi(value.c_str());
        value = cfr.GetTerm(cfr.GetLineFromFile(i),4);
        m_playerY = atoi(value.c_str());
        m_player.go.pos.y = atoi(value.c_str());
      }
    }

    else if(asset == "grandma"){
      //m_grandma.push_back(new CGrandma);

      //look for match between level object name and game object types
      go.spriteID = -1;
      for(int j = 0; j < m_objectType.size(); ++j){
        //pLog->Log("Object", m_objectType[j].name, m_objectType[j].spriteID);

        if(m_objectType[j].name == "grandma"){

          //load game object data from file
          value = cfr.GetTerm(cfr.GetLineFromFile(i),2);
          go.pos.x = atoi(value.c_str());
          value = cfr.GetTerm(cfr.GetLineFromFile(i),3);
          go.pos.y = atoi(value.c_str());
          value = cfr.GetTerm(cfr.GetLineFromFile(i),4);
          go.mode = atoi(value.c_str());

          //load game object data from assets and sprite data
          go.spriteID = m_objectType[j].spriteID;
          go.spriteBadID = m_objectType[j].badSpriteID;
          go.objectID = m_objectType[j].objectID;
          //if(go.objectID > 15){
          //  pLog->Log("Loaded", go.objectID, go.pos.x, go.pos.y);
          //}
          go.radius = m_objectType[j].radius;
          go.layer = m_objectType[j].layer;
          gi = con.GetSprite(go.spriteID);
          go.totalTime = (double)( rand() % 1000)/1000;
          go.width = gi.width;
          go.height = gi.height;
          go.maxFrames = gi.maxFrames; //1=static, >1 is an animation
          go.updateInterval = gi.updateInterval; //how often to change frames
          go.alive = true;
          go.dying = false;
          go.angle = 0;
          if(go.maxFrames > 1)
            go.frameCount = rand() % go.maxFrames;
          else
            go.frameCount = 0;  //sets initial animation frame
          tempMa.go = go;
          m_grandma.push_back(tempMa);// [m_grandma.size() - 1].go = go;

          //pLog->Log("object added", m_pObject[m_pObject.size() - 1]->go.objectID);
          break;
        }
      }
    }
/*
    else if(asset == "ogre"){
      //m_ogregrandma.push_back(new CGrandma);

      //look for match between level object name and game object types
      go.spriteID = -1;
      for(int j = 0; j < m_objectType.size(); ++j){
        //pLog->Log("Object", m_objectType[j].name, m_objectType[j].spriteID);

        if(m_objectType[j].name == "ogre"){

          //load game object data from file
          value = cfr.GetTerm(cfr.GetLineFromFile(i),2);
          go.pos.x = atoi(value.c_str());
          value = cfr.GetTerm(cfr.GetLineFromFile(i),3);
          go.pos.y = atoi(value.c_str());
          //value = cfr.GetTerm(cfr.GetLineFromFile(i),4);
          //go.mode = atoi(value.c_str());

          //load game object data from assets and sprite data
          go.spriteID = m_objectType[j].spriteID;
          go.spriteBadID = m_objectType[j].badSpriteID;
          go.objectID = m_objectType[j].objectID;
          //if(go.objectID > 15){
          //  pLog->Log("Loaded", go.objectID, go.pos.x, go.pos.y);
          //}
          go.radius = m_objectType[j].radius;
          go.layer = m_objectType[j].layer;
          gi = con.GetSprite(go.spriteID);
          go.totalTime = (double)( rand() % 1000)/1000;
          go.width = gi.width;
          go.height = gi.height;
          go.maxFrames = gi.maxFrames; //1=static, >1 is an animation
          go.updateInterval = gi.updateInterval; //how often to change frames
          go.alive = true;
          go.dying = false;
          go.angle = 0;
          if(go.maxFrames > 1)
            go.frameCount = rand() % go.maxFrames;
          else
            go.frameCount = 0;  //sets initial animation frame
          //m_ogre.go = go;
          //m_grandma[m_grandma.size() - 1].go = go;

          //pLog->Log("object added", m_pObject[m_pObject.size() - 1]->go.objectID);
          break;
        }
      }
    }
*/
    else if(asset == "elf"){
      m_pObject.push_back(new CElf);

      //look for match between level object name and game object types
      go.spriteID = -1;
      for(int j = 0; j < m_objectType.size(); ++j){
        //pLog->Log("Object", m_objectType[j].name, m_objectType[j].spriteID);

        if(m_objectType[j].name == "elf"){

          //load game object data from file
          value = cfr.GetTerm(cfr.GetLineFromFile(i),2);
          go.pos.x = atoi(value.c_str());
          value = cfr.GetTerm(cfr.GetLineFromFile(i),3);
          go.pos.y = atoi(value.c_str());
          value = cfr.GetTerm(cfr.GetLineFromFile(i),4);
          go.speed = atof(value.c_str());

          //load game object data from assets and sprite data
          go.spriteID = m_objectType[j].spriteID;
          go.spriteBadID = m_objectType[j].badSpriteID;
          go.objectID = m_objectType[j].objectID;
          //if(go.objectID > 15){
          //  pLog->Log("Loaded", go.objectID, go.pos.x, go.pos.y);
          //}
          go.radius = m_objectType[j].radius;
          go.layer = m_objectType[j].layer;
          gi = con.GetSprite(go.spriteID);
          go.totalTime = (double)( rand() % 1000)/1000;
          go.width = gi.width;
          go.height = gi.height;
          go.maxFrames = gi.maxFrames; //1=static, >1 is an animation
          go.updateInterval = gi.updateInterval; //how often to change frames
          go.alive = true;
          go.dying = false;
          go.angle = 0;
          if(go.maxFrames > 1)
            go.frameCount = rand() % go.maxFrames;
          else
            go.frameCount = 0;  //sets initial animation frame
          m_pObject[m_pObject.size() - 1]->go = go;

          //pLog->Log("object added", m_pObject[m_pObject.size() - 1]->go.objectID);
          break;
        }
      }
    }

    else if(asset == "fairy"){
      m_pObject.push_back(new CFairy);

      //look for match between level object name and game object types
      go.spriteID = -1;
      for(int j = 0; j < m_objectType.size(); ++j){
        //pLog->Log("Object", m_objectType[j].name, m_objectType[j].spriteID);

        if(m_objectType[j].name == "fairy"){

          //load game object data from file
          value = cfr.GetTerm(cfr.GetLineFromFile(i),2);
          go.pos.x = atoi(value.c_str());
          value = cfr.GetTerm(cfr.GetLineFromFile(i),3);
          go.pos.y = atoi(value.c_str());
          value = cfr.GetTerm(cfr.GetLineFromFile(i),4);
          go.speed = atof(value.c_str());

          //load game object data from assets and sprite data
          go.spriteID = m_objectType[j].spriteID;
          go.spriteBadID = m_objectType[j].badSpriteID;
          go.objectID = m_objectType[j].objectID;
          //if(go.objectID > 15){
          //  pLog->Log("Loaded", go.objectID, go.pos.x, go.pos.y);
          //}
          go.radius = m_objectType[j].radius;
          go.layer = m_objectType[j].layer;
          gi = con.GetSprite(go.spriteID);
          go.totalTime = (double)( rand() % 1000)/1000;
          go.width = gi.width;
          go.height = gi.height;
          go.maxFrames = gi.maxFrames; //1=static, >1 is an animation
          go.updateInterval = gi.updateInterval; //how often to change frames
          go.alive = true;
          go.angle = 0;
          if(go.maxFrames > 1)
            go.frameCount = rand() % go.maxFrames;
          else
            go.frameCount = 0;  //sets initial animation frame
          m_pObject[m_pObject.size() - 1]->go = go;

          //pLog->Log("object added", m_pObject[m_pObject.size() - 1]->go.objectID);
          break;
        }
      }
    }

    else if(asset == "witch"){
      m_pObject.push_back(new CWitch);

      //look for match between level object name and game object types
      go.spriteID = -1;
      for(int j = 0; j < m_objectType.size(); ++j){
        //pLog->Log("Object", m_objectType[j].name, m_objectType[j].spriteID);

        if(m_objectType[j].name == "witch"){

          //load game object data from file
          value = cfr.GetTerm(cfr.GetLineFromFile(i),2);
          go.pos.x = atoi(value.c_str());
          value = cfr.GetTerm(cfr.GetLineFromFile(i),3);
          go.pos.y = atoi(value.c_str());
          value = cfr.GetTerm(cfr.GetLineFromFile(i),4);
          go.speed = atof(value.c_str());

          //load game object data from assets and sprite data
          go.spriteID = m_objectType[j].spriteID;
          go.spriteBadID = m_objectType[j].badSpriteID;
          go.objectID = m_objectType[j].objectID;
          //if(go.objectID > 15){
          //  pLog->Log("Loaded", go.objectID, go.pos.x, go.pos.y);
          //}
          go.radius = m_objectType[j].radius;
          go.layer = m_objectType[j].layer;
          gi = con.GetSprite(go.spriteID);
          go.totalTime = (double)( rand() % 1000)/1000;
          go.width = gi.width;
          go.height = gi.height;
          go.maxFrames = gi.maxFrames; //1=static, >1 is an animation
          go.updateInterval = gi.updateInterval; //how often to change frames
          go.alive = true;
          go.angle = 0;
          if(go.maxFrames > 1)
            go.frameCount = rand() % go.maxFrames;
          else
            go.frameCount = 0;  //sets initial animation frame

          m_pObject[m_pObject.size() - 1]->go = go;

          //pLog->Log("object added", m_pObject[m_pObject.size() - 1]->go.objectID);
          break;
        }
      }
    }

    else if(asset == "worldlimits"){ //temp.asset == C_WORLD){
      value = cfr.GetTerm(cfr.GetLineFromFile(i),2);
      m_world_left = atof(value.c_str());
      value = cfr.GetTerm(cfr.GetLineFromFile(i),3);
      m_world_top = atof(value.c_str());
      value = cfr.GetTerm(cfr.GetLineFromFile(i),4);
      m_world_right = atof(value.c_str());
      value = cfr.GetTerm(cfr.GetLineFromFile(i),5);
      m_world_bottom = atof(value.c_str());
    }

    //generic objects
    else if(cfr.GetNumberOfTermsFromLine(i) == 3){
      m_pObject.push_back(new CGeneric);
      go.pos.x = 0;
      go.pos.y = 0;
      go.pos.z = 0;

      //read name of game object
      value = cfr.GetTerm(cfr.GetLineFromFile(i),1);

      //look for match between level object name and game object types
      go.spriteID = -1;
      for(int j = 0; j < m_objectType.size(); ++j){
        if(m_objectType[j].name == value){
          
          //load game object data from file
          value = cfr.GetTerm(cfr.GetLineFromFile(i),2);
          go.pos.x = atoi(value.c_str());
          value = cfr.GetTerm(cfr.GetLineFromFile(i),3);
          go.pos.y = atoi(value.c_str());

          //load game object data from assets and sprite data
          go.spriteID = m_objectType[j].spriteID;
          go.spriteBadID = m_objectType[j].badSpriteID;
          go.objectID = m_objectType[j].objectID;
          go.radius = m_objectType[j].radius;
          go.layer = m_objectType[j].layer;
          gi = con.GetSprite(go.spriteID);
          go.totalTime = (double)( rand() % 1000)/1000;
          go.width = gi.width;
          go.height = gi.height;
          go.maxFrames = gi.maxFrames; //1=static, >1 is an animation
          go.updateInterval = gi.updateInterval; //how often to change frames
          go.alive = true;
          go.dying = false;
          go.angle = 0;
          if(go.maxFrames > 1)
            go.frameCount = rand() % go.maxFrames;
          else
            go.frameCount = 0;  //sets initial animation frame

          m_pObject[m_pObject.size() - 1]->go = go;
          //pLog->Log("object added", m_pObject[m_pObject.size() - 1]->go.objectID);
          break;
        }
      }
    }
  }
}
Ejemplo n.º 11
0
bool NucleicAcidTools::symm_match( clipper::MiniMol& molwrk, const clipper::MiniMol& molref )
{
  clipper::Spacegroup spg1 = clipper::Spacegroup(clipper::Spacegroup::P1);
  clipper::Spacegroup spgr = molwrk.spacegroup();
  clipper::Cell       cell = molwrk.cell();

  // calculate extent of model
  clipper::Atom_list atomr = molref.atom_list();
  clipper::Range<clipper::ftype> urange, vrange, wrange;
  clipper::Coord_frac cfr( 0.0, 0.0, 0.0 );
  for ( int i = 0; i < atomr.size(); i++ ) {
    clipper::Coord_frac cf = atomr[i].coord_orth().coord_frac( cell );
    cfr += cf;
    urange.include( cf.u() );
    vrange.include( cf.v() );
    wrange.include( cf.w() );
  }
  clipper::Coord_frac cf0( urange.min(), vrange.min(), wrange.min() );
  clipper::Coord_frac cf1( urange.max(), vrange.max(), wrange.max() );
  cfr = (1.0/double(atomr.size())) * cfr;

  // calculate mask using wrk cell and ref atoms
  clipper::Resolution reso( 5.0 );
  clipper::Grid_sampling grid( spg1, cell, reso );
  clipper::Grid_range    grng( grid,  cf0,  cf1 );
  grng.add_border(4);
  clipper::NXmap<float> nxmap( cell, grid, grng ), nxflt( cell, grid, grng );
  clipper::EDcalc_mask<float> maskcalc( 2.0 );
  nxmap = 0.0;
  maskcalc( nxmap, atomr );
  MapFilterFn_g5 fn;
  clipper::MapFilter_fft<float>
    fltr( fn, 1.0, clipper::MapFilter_fft<float>::Relative );
  fltr( nxflt, nxmap );

  // now score each chain, symmetry and offset in turn
  for ( int c = 0; c < molwrk.size(); c++ ) {
    double              bestscr = 0.0;
    int                 bestsym = 0;
    clipper::Coord_frac bestoff( 0.0, 0.0, 0.0 );
    const clipper::Coord_frac cfh( 0.5, 0.5, 0.5 );
    for ( int sym = 0; sym < spgr.num_symops(); sym++ ) {
      clipper::Atom_list atomw = molwrk[c].atom_list();
      clipper::RTop_orth rtop = spgr.symop(sym).rtop_orth( cell );
      clipper::Coord_orth cow( 0.0, 0.0, 0.0 );
      for ( int a = 0; a < atomw.size(); a++ ) {
	atomw[a].transform( rtop );
	cow += atomw[a].coord_orth();
      }
      if ( atomw.size() > 0 ) cow = (1.0/double(atomw.size())) * cow;
      clipper::Coord_frac cfw = cow.coord_frac( cell );
      clipper::Coord_frac cfwt = cfw.lattice_copy_near( cfr - cfh );
      clipper::Coord_frac off0 = cfwt - cfw;

      // try offsets
      for ( double du = 0.0; du <= 1.01; du += 1.0 )
	for ( double dv = 0.0; dv < 1.01; dv += 1.0 )
	  for ( double dw = 0.0; dw < 1.01; dw += 1.0 ) {
	    clipper::Coord_frac off( rint( off0.u() ) + du,
				     rint( off0.v() ) + dv,
				     rint( off0.w() ) + dw );
	    clipper::Coord_orth ofo = off.coord_orth( cell );
	    double scr = 0.0;
	    for ( int a = 0; a < atomw.size(); a++ ) {
	      clipper::Coord_orth coa = atomw[a].coord_orth() + ofo;
	      clipper::Coord_grid cga = nxflt.coord_map( coa ).coord_grid();
	      if ( nxflt.in_map( cga ) ) scr += nxflt.get_data( cga );
	    }
	    if ( scr > bestscr ) {
	      bestscr = scr;
	      bestsym = sym;
	      bestoff = off;
	    }
	  }
    }
    // now transform using the best operator
    clipper::Coord_orth cot = bestoff.coord_orth( cell );
    clipper::RTop_orth rtop = spgr.symop(bestsym).rtop_orth( cell );
    rtop = clipper::RTop_orth( rtop.rot(), rtop.trn()+cot );
    molwrk[c].transform( rtop );
  }

  return true;
}